From de35dfc8a843d7b56b587dae2cf643f9aec60e13 Mon Sep 17 00:00:00 2001 From: Mr-Wiseguy Date: Fri, 15 Mar 2024 01:15:33 -0400 Subject: [PATCH] Rename cmake project, embed data for custom code directly into executable instead of a separate file --- CMakeLists.txt | 35 +++++++++++++++++++++-------------- launch.vs.json | 4 ++-- src/recomp/recomp.cpp | 21 +++------------------ 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a09ca6e..a1a60b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.20) -project(MMRecomp) +project(Zelda64Recompiled) set(CMAKE_C_STANDARD 17) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -66,6 +66,7 @@ target_include_directories(PatchesLib PRIVATE target_sources(PatchesLib PRIVATE ${CMAKE_SOURCE_DIR}/RecompiledPatches/patches.c + ${CMAKE_SOURCE_DIR}/RecompiledPatches/patches_bin.c ) set_source_files_properties(${CMAKE_SOURCE_DIR}/RecompiledPatches/patches.c PROPERTIES COMPILE_FLAGS -fno-strict-aliasing) @@ -77,6 +78,12 @@ add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/patches/patches.elf BYPRODUCTS ${CMAKE_SOURCE_DIR}/patches/patches.bin} ) +# Generate patches_bin.c from patches.bin +add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/RecompiledPatches/patches_bin.c + COMMAND file_to_c ${CMAKE_SOURCE_DIR}/patches/patches.bin mm_patches_bin ${CMAKE_SOURCE_DIR}/RecompiledPatches/patches_bin.c ${CMAKE_SOURCE_DIR}/RecompiledPatches/patches_bin.h + DEPENDS ${CMAKE_SOURCE_DIR}/patches/patches.elf ${CMAKE_SOURCE_DIR}/patches/patches.bin +) + # Recompile patches elf into patches.c add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/RecompiledPatches/patches.c @@ -89,7 +96,7 @@ add_custom_command(OUTPUT ) # Main executable -add_executable(MMRecomp) +add_executable(Zelda64Recompiled) set (SOURCES ${CMAKE_SOURCE_DIR}/ultramodern/audio.cpp @@ -153,7 +160,7 @@ set (SOURCES ${CMAKE_SOURCE_DIR}/lib/RmlUi/Backends/RmlUi_Platform_SDL.cpp ) -target_include_directories(MMRecomp PRIVATE +target_include_directories(Zelda64Recompiled PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/lib/concurrentqueue ${CMAKE_SOURCE_DIR}/lib/GamepadMotionHelpers @@ -170,7 +177,7 @@ target_include_directories(MMRecomp PRIVATE ${CMAKE_BINARY_DIR}/shaders ) -target_compile_options(MMRecomp PRIVATE +target_compile_options(Zelda64Recompiled PRIVATE -march=nehalem -fno-strict-aliasing -fms-extensions @@ -185,23 +192,23 @@ if (WIN32) URL_HASH MD5=d8173db078e54040c666f411c5a6afff ) FetchContent_MakeAvailable(sdl2) - target_include_directories(MMRecomp PRIVATE + target_include_directories(Zelda64Recompiled PRIVATE ${sdl2_SOURCE_DIR}/include ) - target_link_directories(MMRecomp PRIVATE + target_link_directories(Zelda64Recompiled PRIVATE ${sdl2_SOURCE_DIR}/lib/x64 ) # Copy SDL2 and dxc DLLs to output folder as post build step - add_custom_command(TARGET MMRecomp POST_BUILD + add_custom_command(TARGET Zelda64Recompiled POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${sdl2_SOURCE_DIR}/lib/x64/SDL2.dll" "${CMAKE_SOURCE_DIR}/lib/RT64-HLE/src/contrib/dxc/bin/x64/dxil.dll" "${CMAKE_SOURCE_DIR}/lib/RT64-HLE/src/contrib/dxc/bin/x64/dxcompiler.dll" - $) + $) endif() -target_link_libraries(MMRecomp PRIVATE +target_link_libraries(Zelda64Recompiled PRIVATE PatchesLib RecompiledFuncs SDL2 @@ -230,14 +237,14 @@ else() set (DXC "LD_LIBRARY_PATH=${PROJECT_SOURCE_DIR}/lib/RT64-HLE/src/src/contrib/dxc/lib/x64" "${PROJECT_SOURCE_DIR}/src/contrib/dxc/bin/x64/dxc") endif() -build_vertex_shader(MMRecomp "shaders/InterfaceVS.hlsl" "shaders/InterfaceVS.hlsl") -build_pixel_shader (MMRecomp "shaders/InterfacePS.hlsl" "shaders/InterfacePS.hlsl") +build_vertex_shader(Zelda64Recompiled "shaders/InterfaceVS.hlsl" "shaders/InterfaceVS.hlsl") +build_pixel_shader (Zelda64Recompiled "shaders/InterfacePS.hlsl" "shaders/InterfacePS.hlsl") -target_sources(MMRecomp PRIVATE ${SOURCES}) +target_sources(Zelda64Recompiled PRIVATE ${SOURCES}) -set_property(TARGET MMRecomp PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}") +set_property(TARGET Zelda64Recompiled PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}") -add_custom_command(TARGET MMRecomp POST_BUILD +add_custom_command(TARGET Zelda64Recompiled POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/${RT64_DLL} ${CMAKE_SOURCE_DIR} diff --git a/launch.vs.json b/launch.vs.json index 6a03e49..bdc4cdc 100644 --- a/launch.vs.json +++ b/launch.vs.json @@ -5,8 +5,8 @@ { "type": "default", "project": "CMakeLists.txt", - "projectTarget": "MMRecomp.exe", - "name": "MMRecomp.exe", + "projectTarget": "Zelda64Recompiled.exe", + "name": "Zelda64Recompiled.exe", "currentDir": "${workspaceRoot}" } ] diff --git a/src/recomp/recomp.cpp b/src/recomp/recomp.cpp index fc75098..df40c86 100644 --- a/src/recomp/recomp.cpp +++ b/src/recomp/recomp.cpp @@ -15,6 +15,7 @@ #include "recomp_config.h" #include "xxHash/xxh3.h" #include "../ultramodern/ultramodern.hpp" +#include "../../RecompiledPatches/patches_bin.h" #ifdef _WIN32 #define EXPORT __declspec(dllexport) @@ -310,24 +311,8 @@ extern "C" void load_overlays(uint32_t rom, int32_t ram_addr, uint32_t size); extern "C" void unload_overlays(int32_t ram_addr, uint32_t size); void read_patch_data(uint8_t* rdram, gpr patch_data_address) { - const char patches_data_file_path[] = "patches/patches.bin"; - std::ifstream patches_data_file{ patches_data_file_path, std::ios::binary }; - - if (!patches_data_file) { - fprintf(stderr, "Failed to open patches data file: %s\n", patches_data_file_path); - exit(EXIT_FAILURE); - } - - patches_data_file.seekg(0, std::ios::end); - size_t patches_data_size = patches_data_file.tellg(); - patches_data_file.seekg(0, std::ios::beg); - - std::unique_ptr patches_data = std::make_unique(patches_data_size); - - patches_data_file.read(reinterpret_cast(patches_data.get()), patches_data_size); - - for (size_t i = 0; i < patches_data_size; i++) { - MEM_B(i, patch_data_address) = patches_data[i]; + for (size_t i = 0; i < sizeof(mm_patches_bin); i++) { + MEM_B(i, patch_data_address) = mm_patches_bin[i]; } }