mirror of
https://github.com/pret/pmd-sky.git
synced 2026-09-27 12:47:39 -05:00
Decompile OverlayIsLoaded (0x02003ED0) from asm/main_02003DB8.s. It maps an overlay group id to whether that group is currently loaded, via a jump table over ids 0-0x24: group 0 is always loaded, and the other ranges check one of the three LOADED_OVERLAY_GROUP_0 slots, gated on the parent slot holding the expected group. Out-of-range ids fail an assert through Debug_FatalError with a prog_pos_info record for overlay.c line 177. That record is the reason this commit also moves data. The function copies _02092558[2] to the stack to pass its address, and the copy's two loads only schedule in the target's order when the compiler can see the array's initializers -- an extern declaration of the same array compiles to the loads transposed. So the five-record array moves into the C file as a const definition. The values are the ones decoded from the data: five entries sharing the overlay.c filename with lines 887, 534, 177, 269 and 626. The array's neighbours cannot move with it. The two strings that follow it in retail cannot be produced by this compiler in place: mwccarm 2.0/sp2p2 emits anonymous string literals into writable .data sections, which the link places in the far data region, and it has no -str readonly (only [no]reuse and [no]pool); a named const u8 string does land in .rodata but is emitted before the array regardless of definition order. The strings therefore stay as assembly, in a new asm/main_rodata_02092580.s holding exactly overlay.c and check group error. asm/main_rodata_020908D4.s is accordingly split: it now ends just before _02092558, and the remainder from _020925A0 onward becomes asm/main_rodata_020925A0.s. Both new rodata files include the original main_rodata_020908D4.inc, which other rodata files also include as a shared declaration header and which is left untouched. main.lsf orders the pieces src/main_02003ED0.o, asm/main_rodata_02092580.o, asm/main_rodata_020925A0.o, so the linker lays out the array, the strings and the remaining data at their retail addresses; the extraction also splits the text file, with the trailing functions moving verbatim into asm/main_020040AC.s. No new names are introduced: OverlayIsLoaded, struct prog_pos_info, Debug_FatalError, LOADED_OVERLAY_GROUP_0 and the three data placeholders all already exist in the tree. No comments are added to any pmd-sky file. Authored by Claude (Opus 4.8) under human direction. Confirmed by a matching build: build/pmdsky.us/pmdsky.us.nds: OK. Intermediate layouts were verified by binary-diffing the built main.sbin against a clean build, which is what located each divergence exactly. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
10 lines
146 B
C
10 lines
146 B
C
#ifndef PMDSKY_MAIN_02003ED0_H
|
|
#define PMDSKY_MAIN_02003ED0_H
|
|
|
|
#include "util.h"
|
|
#include "debug.h"
|
|
|
|
bool8 OverlayIsLoaded(s32 group_id);
|
|
|
|
#endif
|