mirror of
https://github.com/N64Recomp/N64Recomp.git
synced 2026-05-15 07:29:46 -05:00
Adds [[input.decompressed_section]] toml block + Yay0/PERS-SZP wrapper
decoders + an in-memory section synthesis pass. Required for games
like Pokemon Stadium where Stadium's CPU-side decompressor materializes
fragment bytes at runtime and the static recompiler can't see them in
the ELF/ROM-direct path.
User-facing config:
[[input.decompressed_section]]
name = "fragment78"
vram = 0x8FF00000
rom_wrapper = 0x9E93F0
wrapper_format = "pers_szp_yay0"
Pipeline:
1. compression/{yay0,pers_szp}.{h,cpp} decode the wrapper.
2. decompressed.cpp parses the FRAGMENT-format header (relocOffset,
sizeInRam) + Stadium-format reloc table, translates it to
N64Recomp::Reloc entries (R_MIPS_32/26/HI16/LO16) with paired
HI16/LO16 immediate computation, and synthesizes a Section
handed to the existing recompilation pipeline. Stores
decompressed bytes into context.rom at synthetic_rom =
0xFE000000 | rom_wrapper to keep them out of real-ROM addr space.
3. Two functions per fragment: the +0x00 entry trampoline (J + nop)
and the +0x20 implementation (runs to first jr ra in body).
4. After all decompressed sections are added, retargets each
R_MIPS_32 reloc to whichever existing section's vram range
contains its target address (cross-section pointer support).
Adds [output] collision_policy:
"error" (default) — abort the build if two emitted symbols collide
on name; print both colliders + how to opt in.
"suffix" — auto-disambiguate by appending __rom_<rom_addr>
to colliding symbols. Suffix only appears where
collisions exist.
Validated end-to-end on Stadium's fragment78 (wrapper at ROM 0x9E93F0,
decomp_size=0x25340, 319 relocs). Recompiled func_8FF00020 dispatches
to runtime_addr+0x24DC0 correctly; Stadium boots past the prior
crash point, no regression on the N64 logo + PIKA jingle.
Future work: pattern form ([[input.decompressed_section_pattern]]) for
slots like vram 0x8FF00000 where Stadium streams 279 different
fragments at the same link addr. Validation script
(tools/_validate_dynfrag.py in the consumer repo) confirms 268 distinct
content-hashes, 23MB total payload — feasible as engine work.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
212 lines
8.5 KiB
CMake
212 lines
8.5 KiB
CMake
cmake_minimum_required(VERSION 3.20)
|
|
set(CMAKE_C_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD 20)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
# set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
|
|
|
# Rabbitizer
|
|
project(rabbitizer)
|
|
add_library(rabbitizer STATIC)
|
|
|
|
target_sources(rabbitizer PRIVATE
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/cplusplus/src/analysis/LoPairingInfo.cpp"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/cplusplus/src/analysis/RegistersTracker.cpp"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/cplusplus/src/instructions/InstrId.cpp"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/cplusplus/src/instructions/InstrIdType.cpp"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/cplusplus/src/instructions/InstructionBase.cpp"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/cplusplus/src/instructions/InstructionCpu.cpp"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/cplusplus/src/instructions/InstructionR3000GTE.cpp"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/cplusplus/src/instructions/InstructionR5900.cpp"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/cplusplus/src/instructions/InstructionRsp.cpp"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/analysis/RabbitizerLoPairingInfo.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/analysis/RabbitizerRegistersTracker.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/analysis/RabbitizerTrackedRegisterState.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/common/RabbitizerConfig.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/common/RabbitizerVersion.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/common/Utils.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/instructions/RabbitizerInstrCategory.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/instructions/RabbitizerInstrDescriptor.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/instructions/RabbitizerInstrId.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/instructions/RabbitizerInstrIdType.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/instructions/RabbitizerInstrSuffix.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/instructions/RabbitizerInstructionCpu/RabbitizerInstructionCpu_OperandType.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/instructions/RabbitizerInstructionR3000GTE/RabbitizerInstructionR3000GTE.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/instructions/RabbitizerInstructionR3000GTE/RabbitizerInstructionR3000GTE_OperandType.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/instructions/RabbitizerInstructionR3000GTE/RabbitizerInstructionR3000GTE_ProcessUniqueId.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/instructions/RabbitizerInstructionR5900/RabbitizerInstructionR5900.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/instructions/RabbitizerInstructionR5900/RabbitizerInstructionR5900_OperandType.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/instructions/RabbitizerInstructionR5900/RabbitizerInstructionR5900_ProcessUniqueId.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/instructions/RabbitizerInstructionRsp/RabbitizerInstructionRsp.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/instructions/RabbitizerInstructionRsp/RabbitizerInstructionRsp_OperandType.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/instructions/RabbitizerInstructionRsp/RabbitizerInstructionRsp_ProcessUniqueId.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/instructions/RabbitizerInstruction/RabbitizerInstruction.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/instructions/RabbitizerInstruction/RabbitizerInstruction_Disassemble.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/instructions/RabbitizerInstruction/RabbitizerInstruction_Examination.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/instructions/RabbitizerInstruction/RabbitizerInstruction_Operand.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/instructions/RabbitizerInstruction/RabbitizerInstruction_ProcessUniqueId.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/instructions/RabbitizerRegister.c"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/src/instructions/RabbitizerRegisterDescriptor.c")
|
|
|
|
target_include_directories(rabbitizer PUBLIC
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/include"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/cplusplus/include")
|
|
|
|
target_include_directories(rabbitizer PRIVATE
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/rabbitizer/tables")
|
|
|
|
# fmtlib
|
|
add_subdirectory(lib/fmt)
|
|
|
|
# tomlplusplus
|
|
set(TOML_ENABLE_FORMATTERS OFF)
|
|
add_subdirectory(lib/tomlplusplus)
|
|
|
|
# Hardcoded symbol lists (separate library to not force a dependency on N64Recomp)
|
|
project(SymbolLists)
|
|
add_library(SymbolLists)
|
|
|
|
target_sources(SymbolLists PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/symbol_lists.cpp
|
|
)
|
|
|
|
target_include_directories(SymbolLists PUBLIC
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include"
|
|
)
|
|
|
|
# N64 recompiler core library
|
|
project(N64Recomp)
|
|
add_library(N64Recomp)
|
|
|
|
target_sources(N64Recomp PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/analysis.cpp
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/operations.cpp
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/cgenerator.cpp
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/recompilation.cpp
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/mod_symbols.cpp
|
|
)
|
|
|
|
target_include_directories(N64Recomp PUBLIC
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include"
|
|
)
|
|
|
|
target_link_libraries(N64Recomp SymbolLists fmt rabbitizer tomlplusplus::tomlplusplus)
|
|
|
|
# N64 recompiler elf parsing
|
|
project(N64RecompElf)
|
|
add_library(N64RecompElf)
|
|
|
|
target_sources(N64RecompElf PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/elf.cpp
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/mdebug.cpp
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/symbol_lists.cpp
|
|
)
|
|
|
|
target_include_directories(N64RecompElf PUBLIC
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include"
|
|
)
|
|
|
|
target_include_directories(N64RecompElf PRIVATE
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/lib/ELFIO"
|
|
)
|
|
|
|
target_link_libraries(N64RecompElf fmt)
|
|
|
|
# N64 recompiler executable
|
|
project(N64RecompCLI)
|
|
add_executable(N64RecompCLI)
|
|
|
|
target_sources(N64RecompCLI PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/config.cpp
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/decompressed.cpp
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/compression/yay0.cpp
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/compression/pers_szp.cpp
|
|
)
|
|
|
|
target_include_directories(N64RecompCLI PRIVATE
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/include"
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/src"
|
|
)
|
|
|
|
target_link_libraries(N64RecompCLI fmt rabbitizer tomlplusplus::tomlplusplus N64Recomp N64RecompElf)
|
|
set_target_properties(N64RecompCLI PROPERTIES OUTPUT_NAME N64Recomp)
|
|
|
|
# RSP recompiler
|
|
project(RSPRecomp)
|
|
add_executable(RSPRecomp)
|
|
|
|
target_include_directories(RSPRecomp PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
|
|
|
target_link_libraries(RSPRecomp fmt rabbitizer tomlplusplus::tomlplusplus)
|
|
|
|
target_sources(RSPRecomp PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/RSPRecomp/src/rsp_recomp.cpp)
|
|
|
|
# Mod tool
|
|
project(RecompModTool)
|
|
add_executable(RecompModTool)
|
|
|
|
target_sources(RecompModTool PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/config.cpp
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/mod_symbols.cpp
|
|
${CMAKE_CURRENT_SOURCE_DIR}/RecompModTool/main.cpp
|
|
)
|
|
|
|
target_include_directories(RecompModTool PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/lib/ELFIO
|
|
)
|
|
|
|
target_link_libraries(RecompModTool fmt tomlplusplus::tomlplusplus N64RecompElf)
|
|
|
|
# Offline mod recompiler
|
|
project(OfflineModRecomp)
|
|
add_executable(OfflineModRecomp)
|
|
|
|
target_sources(OfflineModRecomp PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/config.cpp
|
|
${CMAKE_CURRENT_SOURCE_DIR}/OfflineModRecomp/main.cpp
|
|
)
|
|
|
|
target_link_libraries(OfflineModRecomp fmt rabbitizer tomlplusplus::tomlplusplus N64Recomp)
|
|
|
|
# Mod combiner
|
|
project(RecompModMerger)
|
|
add_executable(RecompModMerger)
|
|
|
|
target_sources(RecompModMerger PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/config.cpp
|
|
${CMAKE_CURRENT_SOURCE_DIR}/RecompModMerger/main.cpp
|
|
)
|
|
|
|
target_link_libraries(RecompModMerger N64Recomp)
|
|
|
|
# Live recompiler
|
|
project(LiveRecomp)
|
|
add_library(LiveRecomp)
|
|
|
|
target_sources(LiveRecomp PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/LiveRecomp/live_generator.cpp
|
|
${CMAKE_CURRENT_SOURCE_DIR}/lib/sljit/sljit_src/sljitLir.c
|
|
)
|
|
|
|
target_include_directories(LiveRecomp PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/lib/sljit/sljit_src
|
|
)
|
|
|
|
target_link_libraries(LiveRecomp N64Recomp)
|
|
|
|
# Live recompiler test
|
|
project(LiveRecompTest)
|
|
add_executable(LiveRecompTest)
|
|
|
|
target_sources(LiveRecompTest PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/LiveRecomp/live_recompiler_test.cpp
|
|
)
|
|
|
|
target_include_directories(LiveRecompTest PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/lib/sljit/sljit_src
|
|
)
|
|
|
|
target_link_libraries(LiveRecompTest LiveRecomp)
|