diff --git a/build.sh b/build.sh index c0ea70dffc..5b2625aa69 100755 --- a/build.sh +++ b/build.sh @@ -21,10 +21,7 @@ export MESON_RSP_THRESHOLD=16387 if [ "$target" = test ]; then "${MESON:-meson}" test -C build "$@" elif [ "$target" = rom ]; then - "${MESON:-meson}" compile -C build "pokeplatinum.us.nds" + "${MESON:-meson}" compile -C build "pokeplatinum.us.nds" "debug.nef" else "${MESON:-meson}" compile -C build "$target" "$@" fi - -# remap incorrect source paths due to Wine build process -python3 fixup_elf2.py diff --git a/meson.build b/meson.build index bde780a575..fb2d02080e 100644 --- a/meson.build +++ b/meson.build @@ -228,6 +228,22 @@ pokeplatinum_nds = custom_target('pokeplatinum.us.nds', build_by_default: true ) +############################################################ +### NEF FIXER ### +############################################################ +nef_fixer = custom_target('debug.nef', + output: [ + 'debug.nef' + ], + input: [ + main + ], + command : [ + nef_fixer_py, '@INPUT@', '@OUTPUT@' + ], + build_by_default: true +) + ############################################################ ### TESTS ### diff --git a/src/game_overlay.c b/src/game_overlay.c index 7152857045..b37d2d3e31 100644 --- a/src/game_overlay.c +++ b/src/game_overlay.c @@ -59,9 +59,14 @@ void LoadOverlayGDB(const FSOverlayID overlayID) GF_ASSERT(FS_LoadOverlayInfo(&overlayInfo, MI_PROCESSOR_ARM9, overlayID) == TRUE); // 2. add entry to _ovly_table + // note that this is a little hacky. the VMA is correct but the LMA is not exposed by the OverlayManager + // and the size field is not correct compared to what's stored in the NEF. + // the standard overlay manager in GDB bases comparisons on VMA and LMA, so it's not viable here. + // requires a custom GDB build which uses section name and which can override section size. + // see _ovly_table[overlayID].vma = overlayInfo.header.ram_address; _ovly_table[overlayID].lma = 0; - _ovly_table[overlayID].size = overlayInfo.header.ram_size; + _ovly_table[overlayID].size = overlayInfo.header.ram_size; _ovly_table[overlayID].mapped = 1; _ovly_debug_event(); } diff --git a/tools/scripts/meson.build b/tools/scripts/meson.build index 5c20a881d9..86826b06f1 100644 --- a/tools/scripts/meson.build +++ b/tools/scripts/meson.build @@ -10,3 +10,4 @@ make_species_tables_py = find_program('make_species_tables.py', native: true) make_tutorable_moves_py = find_program('make_tutorable_moves.py', native: true) make_pokedex_data_py = find_program('make_pokedex_data.py', native: true) make_pokedex_message_banks_py = find_program('make_pokedex_message_banks.py', native: true) +nef_fixer_py = find_program('nef_fixer.py', native: true) \ No newline at end of file diff --git a/fixup_elf2.py b/tools/scripts/nef_fixer.py similarity index 69% rename from fixup_elf2.py rename to tools/scripts/nef_fixer.py index 792b22b247..713856c1ae 100644 --- a/fixup_elf2.py +++ b/tools/scripts/nef_fixer.py @@ -1,15 +1,24 @@ +#!/usr/bin/env python3 import subprocess import os +import shutil +import sys try: - os.remove("build/sources.txt") + os.remove("sources.txt") except: pass -print("Retrieving source file list via debugedit") -subprocess.run(["debugedit", "-l", "build/sources.txt", "build/main.nef"]) +source = sys.argv[1] +dest = sys.argv[2] -with open("build/sources.txt") as f: +print(f"Copying {source} to {dest}") +shutil.copyfile(source, dest) + +print("Retrieving source file list via debugedit") +subprocess.run(["debugedit", "-l", "sources.txt", dest]) + +with open("sources.txt") as f: content = f.read() all_sources = content.split('\0') @@ -29,4 +38,4 @@ print(f"Identified {len(source_paths)} unique source directories from source fil for source in source_paths: remapped = source.replace("\\", "/")[2:] print(f"Remapping source path from {source} to {remapped} using debugedit.") - subprocess.run(["debugedit", "-b", source, "-d", remapped, "build/main.nef"]) \ No newline at end of file + subprocess.run(["debugedit", "-b", source, "-d", remapped, dest]) \ No newline at end of file