diff --git a/.gitignore b/.gitignore index e8ef78d..e65ec5a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,7 @@ .DS_Store *.dSYM /.vs/ -/packages/ /saves/ -*.o -/sm -/build/ +/build*/ /sm.smc -SDL2.dll -/sm.exe -/glsl-shaders/ \ No newline at end of file +/glsl-shaders/ diff --git a/BUILDING.md b/BUILDING.md index e40b009..0c07992 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -1,55 +1,41 @@ # Requirements - * A Super Metroid rom (Make sure to rename it to `sm.smc`) + * cmake (and also ninja, for better compiling speed) + * A Super Metroid rom (Make sure to rename it to `sm.smc`) which **must be in + the same folder as `sm`/`sm.exe`** * libsdl2-dev * Super Metroid repo `git clone --recursive https://github.com/snesrev/sm` For Linux/MacOS you must install these for your desired OS: - * Ubuntu/Debian: `sudo apt install libsdl2-dev` - * Fedora Linux: `sudo dnf in sdl2-devel` - * Arch Linux: `sudo pacman -S sdl2` - * macOS: `brew install sdl2` + * Ubuntu/Debian: `sudo apt install libsdl2-dev cmake ninja-build` + * Fedora Linux: `sudo dnf in sdl2-devel cmake ninja-build` + * Arch Linux: `sudo pacman -S sdl2 cmake ninja` + * macOS: `brew install sdl2 cmake ninja` # Windows ## Building with MSYS2 - -Dependencies and requirements: - - * The `libsdl2-dev` library - * [MSYS2](https://www.msys2.org) +First, install [MSYS2](https://www.msys2.org/). After following the instructions, +install the following packages. Note: *Make sure you're using MINGW64 and you're in `sm` folder in the terminal.* -1. Install MSYS2 on your machine. -2. Place the copy of your rom in the main directory. -3. Install the necessary dependencies by inputting this command in the terminal. - -```sh -pacman -S mingw-w64-x86_64-SDL2 && pacman -S make && pacman -S mingw-w64-x86_64-gcc -``` -4. Type `sdl2-config --cflags`, it should output: -```sh --IC:/msys64/mingw64/include/SDL2 -Dmain=SDL_main -``` -5. After that type `sdl2-config --libs`, should output: ```sh --LC:/msys64/mingw64/lib -lmingw32 -mwindows -lSDL2main -lSDL2 +pacman -S mingw-w64-x86_64-{gcc,cmake,SDL2,ninja} ``` -After you've done installing everything, cd to `sm` folder. Type `make` -In order to speed up the compilation, type `make -j16` - ## Building with Visual Studio Dependencies and requirements: * The `libsdl2-dev` library, which is automatically installed with NuGet. * [Visual Studio Community 2022](https://visualstudio.microsoft.com) -Download VS installer. On installer prompt, make sure you're on "Workloads" and check `Desktop Development with C++` this will install the necessary deps for compilation. +Download VS installer. On installer prompt, make sure you're on "Workloads" +and check **both** `Desktop Development with C++` **and** `C++ CMake Tools for Windows`. +This will install the necessary deps for compilation. -1. Open `sm.sln` solution. -2. Change the build target from `Debug` to `Release` -3. Build the solution. +Visual Studio should automatically detect the CMake project and let you configure and build it. If not, +follow the [general instructions](https://learn.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio?view=msvc-170) +from Microsoft. ## Building with Tiny C Compiler @@ -64,34 +50,34 @@ Download VS installer. On installer prompt, make sure you're on "Workloads" and CD to your SM root folder and open the terminal and type: ```sh -make +cmake -B build && cmake --build build --parallel ``` -For more advanced usage: -```sh -make -j$(nproc) # run on all core -make clean all # clear gen+obj and rebuild -CC=clang make # specify compiler -``` +The resulting binary will be `build/sm`. # Nintendo Switch -Dependencies and requirements: +## Getting Dependencies - * The `switch-sdl2` library +You will need: * [DevKitPro](https://github.com/devkitPro/installer) * [Atmosphere](https://github.com/Atmosphere-NX/Atmosphere) -1. Make sure you've installed Atmosphere on your Switch. -2. Please download the DevKitPro version of MSYS2 through their installer, as the default MSYS2 causes issues with windows compiling. -3. Now that you've installed DevKitPro, open up the location you've installed DevKitPro to, then find `mingw64.exe` inside `msys2` located in `devkitPro` folder. -4. Type `pacman -S git switch-dev switch-sdl2 switch-tools` in the terminal to install the `switch-sdl2` library. -5. CD to `switch` folder by typing `cd src/platfrom/switch` in the terminal on the `sm` root folder. -6. type `make` to compile the Switch Port. -7. Transfer the `.ini`, `nro`, `ncap` and your rom file to the Switch. +First, follow the [installation instructions on devkitPro's website](https://devkitpro.org/wiki/Getting_Started). -**OPTIONAL STEP** +Second, once you have pacman set up and synced, do: +```shell +pacman -S switch-dev switch-tools switch-sdl2 +``` -```sh -make -j$(nproc) # To build using all cores +## Building +In the top level directory, you can use the cmake preset for running a build for the switch: +```shell +cmake --preset nintendo-switch +cmake --build build-switch --parallel ``` + +## Getting SM on to your Switch +First, make sure you've installed [Atmosphere](https://github.com/Atmosphere-NX/Atmosphere) on your Switch. +Next, go into the `build-switch` directory and copy `sm.ini`, `sm.nro`, and `sm.ncap` and the sm rom +file to your Switch. \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..595b04a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,60 @@ +cmake_minimum_required(VERSION 3.22 FATAL_ERROR) + +project(sm + VERSION 0.0.1 + DESCRIPTION "Super Metroid PC Port" + HOMEPAGE_URL "https://github.com/snesrev/sm" + LANGUAGES C) + +if (CMAKE_BINARY_DIR EQUAL CMAKE_SOURCE_DIR) + message(WARNING "You are compiling in the source tree, you probably don't want to do that. Use -B to set the build directory") +endif() + +include(GNUInstallDirs) + +# For installation later +set(ini_name "${PROJECT_SOURCE_DIR}/sm.ini") + +# Dependencies +# ------------ +# SDL +if (WIN32 OR NINTENDO_SWITCH) + # Force static on Windows and Switch, just because it's easier + find_package(SDL2 REQUIRED COMPONENTS SDL2-static) +else() + find_package(SDL2 REQUIRED COMPONENTS SDL2) +endif() + +# OpenGL +# TODO: This should likely be removed +add_library(gl STATIC "third_party/gl_core/gl_core_3_1.c") +target_include_directories(gl PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") + +# Main Executable +# --------------- +add_executable(sm) +add_subdirectory(src) +target_link_libraries(sm PRIVATE m SDL2::SDL2 gl) +target_compile_definitions(sm PRIVATE SYSTEM_VOLUME_MIXER_AVAILABLE=0) + +# Nintendo Switch extra setup +if (NINTENDO_SWITCH) + enable_language(CXX) + nx_generate_nacp(sm.nacp + NAME "Super Metroid" + AUTHOR "snesrev & Lywx" + VERSION "${PROJECT_VERSION}") + + nx_create_nro(sm + NACP sm.nacp + ICON "${PROJECT_SOURCE_DIR}/src/platform/switch/icon.jpg") + + set(ini_name "${PROJECT_SOURCE_DIR}/src/platform/switch/sm.ini") +endif() + +# Installation +# ------------ +install(TARGETS sm RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + +# TODO: should be in some config dir +install(FILES "${ini_name}" DESTINATION "${CMAKE_INSTALL_BINDIR}") \ No newline at end of file diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..97da501 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,20 @@ +{ + "version": 3, + "cmakeMinimumRequired": { + "major": 3, + "minor": 21, + "patch": 0 + }, + "configurePresets": [ + { + "name": "nintendo-switch", + "binaryDir": "${sourceDir}/build-switch", + "toolchainFile": "$env{DEVKITPRO}/cmake/Switch.cmake", + "condition": { + "type": "notEquals", + "lhs": "$env{DEVKITPRO}", + "rhs": "" + } + } + ] +} \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index 1fcc86b..0000000 --- a/Makefile +++ /dev/null @@ -1,33 +0,0 @@ -TARGET_EXEC:=sm - -SRCS:=$(wildcard src/*.c src/snes/*.c) third_party/gl_core/gl_core_3_1.c -OBJS:=$(SRCS:%.c=%.o) - -PYTHON:=/usr/bin/env python3 -CFLAGS:=$(if $(CFLAGS),$(CFLAGS),-O2 -fno-strict-aliasing -Werror ) -CFLAGS:=${CFLAGS} $(shell sdl2-config --cflags) -DSYSTEM_VOLUME_MIXER_AVAILABLE=0 -I. - -ifeq (${OS},Windows_NT) - WINDRES:=windres -# RES:=sm.res - SDLFLAGS:=-Wl,-Bstatic $(shell sdl2-config --static-libs) -else - SDLFLAGS:=$(shell sdl2-config --libs) -lm -endif - -.PHONY: all clean clean_obj - -all: $(TARGET_EXEC) -$(TARGET_EXEC): $(OBJS) $(RES) - $(CC) $^ -o $@ $(LDFLAGS) $(SDLFLAGS) - -%.o : %.c - $(CC) -c $(CFLAGS) $< -o $@ - -#$(RES): src/platform/win32/sm.rc -# @echo "Generating Windows resources" -# @$(WINDRES) $< -O coff -o $@ - -clean: clean_obj -clean_obj: - @$(RM) $(OBJS) $(TARGET_EXEC) diff --git a/sm.sln b/sm.sln deleted file mode 100644 index 82a190e..0000000 --- a/sm.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.3.32825.248 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sm", "src/sm.vcxproj", "{1F8AB1B4-DAFB-4D6E-BF1E-F802FF5A52EE}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {1F8AB1B4-DAFB-4D6E-BF1E-F802FF5A52EE}.Debug|x64.ActiveCfg = Debug|x64 - {1F8AB1B4-DAFB-4D6E-BF1E-F802FF5A52EE}.Debug|x64.Build.0 = Debug|x64 - {1F8AB1B4-DAFB-4D6E-BF1E-F802FF5A52EE}.Debug|x86.ActiveCfg = Debug|Win32 - {1F8AB1B4-DAFB-4D6E-BF1E-F802FF5A52EE}.Debug|x86.Build.0 = Debug|Win32 - {1F8AB1B4-DAFB-4D6E-BF1E-F802FF5A52EE}.Release|x64.ActiveCfg = Release|x64 - {1F8AB1B4-DAFB-4D6E-BF1E-F802FF5A52EE}.Release|x64.Build.0 = Release|x64 - {1F8AB1B4-DAFB-4D6E-BF1E-F802FF5A52EE}.Release|x86.ActiveCfg = Release|Win32 - {1F8AB1B4-DAFB-4D6E-BF1E-F802FF5A52EE}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {8F47385F-600A-41BA-AEF8-C47A2C0D15E6} - EndGlobalSection -EndGlobal diff --git a/src/.gitignore b/src/.gitignore deleted file mode 100644 index cbc684b..0000000 --- a/src/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/sm.vcxproj.user diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..954f971 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,98 @@ +target_sources(sm PRIVATE + "config.c" + "config.h" + "enemy_types.h" + "features.h" + "funcs.h" + "glsl_shader.c" + "glsl_shader.h" + "ida_types.h" + "main.c" + "opengl.c" + "sm_80.c" + "sm_81.c" + "sm_82.c" + "sm_84.c" + "sm_85.c" + "sm_86.c" + "sm_87.c" + "sm_88.c" + "sm_89.c" + "sm_8b.c" + "sm_8d.c" + "sm_8f.c" + "sm_90.c" + "sm_91.c" + "sm_92.c" + "sm_93.c" + "sm_94.c" + "sm_9b.c" + "sm_a0.c" + "sm_a2.c" + "sm_a3.c" + "sm_a4.c" + "sm_a5.c" + "sm_a6.c" + "sm_a7.c" + "sm_a8.c" + "sm_a9.c" + "sm_aa.c" + "sm_ad.c" + "sm_b2.c" + "sm_b3.c" + "sm_b4.c" + "sm_cpu_infra.c" + "sm_cpu_infra.h" + "sm_rtl.c" + "sm_rtl.h" + "spc_player.c" + "spc_player.h" + "spc_variables.h" + "tracing.c" + "tracing.h" + "types.h" + "util.c" + "util.h" + "variables_extra.h" + "variables.h" + + "snes/apu.c" + "snes/apu.h" + "snes/cart.c" + "snes/cart.h" + "snes/cpu.c" + "snes/cpu.h" + "snes/dma.c" + "snes/dma.h" + "snes/dsp.c" + "snes/dsp.h" + "snes/dsp_regs.h" + "snes/input.c" + "snes/input.h" + "snes/ppu.c" + "snes/ppu.h" + "snes/saveload.h" + "snes/snes.c" + "snes/snes.h" + "snes/snes_other.c" + "snes/spc.c" + "snes/spc.h" +) + +if (WIN32) + enable_language(RC) + target_sources(sm PRIVATE + "platform/win32/resource.h" + "platform/win32/sm.rc" + "platform/win32/volume_control.c" + "platform/win32/volume_control.h" + ) +endif() + +if (NINTENDO_SWITCH) + target_include_directories(sm PRIVATE "platform/switch/src") + target_sources(sm PRIVATE + "platform/switch/src/switch_impl.c" + "platform/switch/src/switch_impl.h" + ) +endif() \ No newline at end of file diff --git a/src/packages.config b/src/packages.config deleted file mode 100644 index 7ede8af..0000000 --- a/src/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/sm.vcxproj b/src/sm.vcxproj deleted file mode 100644 index c7355e7..0000000 --- a/src/sm.vcxproj +++ /dev/null @@ -1,276 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 17.0 - {1F8AB1B4-DAFB-4D6E-BF1E-F802FF5A52EE} - Win32Proj - 10.0 - - - - Application - true - v143 - - - Application - false - v143 - - - Application - true - v143 - - - Application - false - v143 - - - - - - - - - - - - - - - - - - - - - true - $(SolutionDir)build\bin-$(Platform)-$(Configuration)\ - $(SolutionDir)build\obj-$(Platform)-$(Configuration)\ - - - true - $(SolutionDir)build\bin-$(Platform)-$(Configuration)\ - $(SolutionDir)build\obj-$(Platform)-$(Configuration)\ - - - $(SolutionDir)build\bin-$(Platform)-$(Configuration)\ - $(SolutionDir)build\obj-$(Platform)-$(Configuration)\ - - - $(SolutionDir)build\bin-$(Platform)-$(Configuration)\ - $(SolutionDir)build\obj-$(Platform)-$(Configuration)\ - - - - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS - MultiThreadedDebugDLL - Level3 - ProgramDatabase - Disabled - $(SolutionDir) - Default - 4996 - stdc11 - - - MachineX86 - true - Console - $(CoreLibraryDependencies);%(AdditionalDependencies) - - - - - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS - MultiThreadedDLL - Level3 - ProgramDatabase - $(SolutionDir) - 4996 - stdc11 - - - MachineX86 - true - Console - true - true - $(CoreLibraryDependencies);%(AdditionalDependencies) - - - - - $(SolutionDir) - Level3 - ;_CRT_SECURE_NO_WARNINGS - Default - 4996 - stdc11 - true - - - $(CoreLibraryDependencies);%(AdditionalDependencies) - - - - - $(SolutionDir) - Level3 - ;_CRT_SECURE_NO_WARNINGS - 4996 - stdc11 - - - $(CoreLibraryDependencies);%(AdditionalDependencies) - - - - - - - - - - - - - - - - - - - - stdc17 - stdc17 - stdc17 - stdc17 - - - - - - - - - - - - - - - - - - - - - - - - - - - Disabled - Disabled - - - MinSpace - MinSpace - - - Disabled - Disabled - - - Disabled - Disabled - - - Disabled - Disabled - - - MinSpace - MinSpace - - - Disabled - Disabled - - - - - MinSpace - MinSpace - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - \ No newline at end of file diff --git a/src/sm.vcxproj.filters b/src/sm.vcxproj.filters deleted file mode 100644 index 08f7da9..0000000 --- a/src/sm.vcxproj.filters +++ /dev/null @@ -1,270 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav - - - {e1763dbc-4fb3-417f-ad1a-8436411c3b7a} - - - {2b72ed96-9194-4c2c-b1e5-15445f0a9550} - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Snes - - - Snes - - - Snes - - - Snes - - - Snes - - - Snes - - - Snes - - - Snes - - - Snes - - - Snes - - - Snes - - - Shader - - - Shader - - - Shader - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Snes - - - Snes - - - Snes - - - Snes - - - Snes - - - Snes - - - Snes - - - Snes - - - Snes - - - Snes - - - Snes - - - Snes - - - Shader - - - Shader - - - - - - \ No newline at end of file diff --git a/third_party/.gitignore b/third_party/.gitignore deleted file mode 100644 index 1fbecd9..0000000 --- a/third_party/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/tcc/ -/SDL2-2.24.1/ -/gl_core/*.o \ No newline at end of file diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt new file mode 100644 index 0000000..ea8f19b --- /dev/null +++ b/third_party/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(sm PRIVATE + "gl_core/gl_core_3_1.c" +) \ No newline at end of file