mirror of
https://github.com/pret/pmd-sky.git
synced 2026-08-20 01:25:24 -05:00
Decomp OverlayIsLoaded; migrate its prog_pos_info array to C
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>
This commit is contained in:
@@ -1,126 +1,18 @@
|
||||
#pragma once
|
||||
.public Card_TerminateForPulledOut
|
||||
.public Debug_Print0
|
||||
.public OS_SleepThread
|
||||
.public OS_WaitIrq
|
||||
.public _02092540
|
||||
.public _02092558
|
||||
.public _0209258C
|
||||
.public _020925A0
|
||||
.public _020925B4
|
||||
.public _020925C8
|
||||
.public _020925F8
|
||||
.public _02092670
|
||||
.public _020926C0
|
||||
.public _0209277C
|
||||
.public _0209278C
|
||||
.public _02092798
|
||||
.public _020927B8
|
||||
.public _020927BC
|
||||
.public _020927E4
|
||||
.public _020927EC
|
||||
.public _020927FC
|
||||
.public _02092844
|
||||
.public _020AEF7C
|
||||
.public _020AF050
|
||||
.public _020AF078
|
||||
.public _020AF23C
|
||||
.public _020AF240
|
||||
.public _020AF264
|
||||
.public _020AF288
|
||||
.public _020AF2AC
|
||||
.public _020AF2B8
|
||||
.public _020AF2C4
|
||||
.public _020AF344
|
||||
.public _020AF354
|
||||
.public _020AF360
|
||||
.public _020AF368
|
||||
.public _022A3248
|
||||
.public _022A3538
|
||||
.public _022A353C
|
||||
.public _022A3554
|
||||
.public _022A35E8
|
||||
.public _022A3614
|
||||
.public _022A3620
|
||||
.public _022A362C
|
||||
.public _022A3644
|
||||
.public _022A3658
|
||||
.public _022A3670
|
||||
.public _fadd
|
||||
.public _fflt
|
||||
.public _fmul
|
||||
.public _s32_div_f
|
||||
.public abs
|
||||
.public Card_IsPulledOut
|
||||
.public Card_TerminateForPulledOut
|
||||
.public CardPullOutWithStatus
|
||||
.public DC_FlushAll
|
||||
.public Debug_FatalError
|
||||
.public Debug_Print
|
||||
.public Debug_Print0
|
||||
.public FS_CloseFile
|
||||
.public FS_InitFile
|
||||
.public FS_LoadOverlayImage
|
||||
.public FS_LoadOverlayInfo
|
||||
.public FS_OpenFile
|
||||
.public FS_ReadFile
|
||||
.public FS_SeekFile
|
||||
.public FS_StartOverlay
|
||||
.public FS_UnloadOverlay
|
||||
.public GetDsFirmwareUserSettings
|
||||
.public GX_BeginLoadBGExtPltt
|
||||
.public GX_BeginLoadOBJExtPltt
|
||||
.public GX_EndLoadBGExtPltt
|
||||
.public GX_EndLoadOBJExtPltt
|
||||
.public GXS_BeginLoadBGExtPltt
|
||||
.public GXS_EndLoadBGExtPltt
|
||||
.public IC_InvalidateAll
|
||||
.public LOADED_OVERLAY_GROUP_0
|
||||
.public MATH_CalcCRC32
|
||||
.public MATHi_CRC32InitTable
|
||||
.public MemAlloc
|
||||
.public MemFree
|
||||
.public MemLocateSet
|
||||
.public MI_DmaCopy16Async
|
||||
.public MI_DmaCopy32Async
|
||||
.public MI_DmaSend16Async
|
||||
.public MI_DmaSend32Async
|
||||
.public MI_IsDmaBusy
|
||||
.public OS_SleepThread
|
||||
.public OS_WaitIrq
|
||||
.public RandInt
|
||||
.public Rtc_GetDateTime
|
||||
.public Rtc_Init
|
||||
.public sprintf
|
||||
.public sqrtf
|
||||
.public strcat
|
||||
.public strcmp
|
||||
.public strcpy
|
||||
.public strlen
|
||||
.public strncpy
|
||||
.public sub_02002368
|
||||
.public sub_020023A8
|
||||
.public sub_02002448
|
||||
.public sub_02002580
|
||||
.public sub_020025F8
|
||||
.public sub_020027F8
|
||||
.public sub_02002824
|
||||
.public sub_020029B8
|
||||
.public sub_02002A9C
|
||||
.public sub_02002B38
|
||||
.public sub_02002B50
|
||||
.public sub_02002B7C
|
||||
.public sub_02002C40
|
||||
.public sub_02002CAC
|
||||
.public sub_02002CB4
|
||||
.public sub_02002E10
|
||||
.public sub_02002E98
|
||||
.public sub_0200302C
|
||||
.public sub_020030FC
|
||||
.public sub_020031C0
|
||||
.public sub_0200844C
|
||||
.public sub_0200846C
|
||||
.public sub_020081C8
|
||||
.public sub_020081F0
|
||||
.public sub_0200B76C
|
||||
.public sub_020184A8
|
||||
.public TOUCHSCREEN_STATUS
|
||||
.public TP_GetUserInfo
|
||||
.public TP_Init
|
||||
.public TP_RequestSamplingAsync
|
||||
.public TP_SetCalibrateParam
|
||||
.public TP_WaitCalibratedResult
|
||||
|
||||
112
asm/include/main_020040AC.inc
Normal file
112
asm/include/main_020040AC.inc
Normal file
@@ -0,0 +1,112 @@
|
||||
#pragma once
|
||||
.public CardPullOutWithStatus
|
||||
.public Card_IsPulledOut
|
||||
.public DC_FlushAll
|
||||
.public Debug_FatalError
|
||||
.public Debug_Print
|
||||
.public Debug_Print0
|
||||
.public FS_CloseFile
|
||||
.public FS_InitFile
|
||||
.public FS_OpenFile
|
||||
.public FS_ReadFile
|
||||
.public FS_SeekFile
|
||||
.public FS_UnloadOverlay
|
||||
.public GXS_BeginLoadBGExtPltt
|
||||
.public GXS_EndLoadBGExtPltt
|
||||
.public GX_BeginLoadBGExtPltt
|
||||
.public GX_BeginLoadOBJExtPltt
|
||||
.public GX_EndLoadBGExtPltt
|
||||
.public GX_EndLoadOBJExtPltt
|
||||
.public GetDsFirmwareUserSettings
|
||||
.public FS_LoadOverlayInfo
|
||||
.public IC_InvalidateAll
|
||||
.public FS_StartOverlay
|
||||
.public LOADED_OVERLAY_GROUP_0
|
||||
.public FS_LoadOverlayImage
|
||||
.public MI_DmaCopy16Async
|
||||
.public MI_DmaCopy32Async
|
||||
.public MI_DmaSend16Async
|
||||
.public MI_DmaSend32Async
|
||||
.public MI_IsDmaBusy
|
||||
.public MATH_CalcCRC32
|
||||
.public MATHi_CRC32InitTable
|
||||
.public MemAlloc
|
||||
.public MemFree
|
||||
.public MemLocateSet
|
||||
.public RandInt
|
||||
.public Rtc_GetDateTime
|
||||
.public Rtc_Init
|
||||
.public TOUCHSCREEN_STATUS
|
||||
.public TP_GetUserInfo
|
||||
.public TP_Init
|
||||
.public TP_RequestSamplingAsync
|
||||
.public TP_SetCalibrateParam
|
||||
.public TP_WaitCalibratedResult
|
||||
.public _02092558
|
||||
.public _020925A0
|
||||
.public _020925B4
|
||||
.public _020925C8
|
||||
.public _020925F8
|
||||
.public _02092670
|
||||
.public _020926C0
|
||||
.public _0209277C
|
||||
.public _0209278C
|
||||
.public _02092798
|
||||
.public _020927B8
|
||||
.public _020927BC
|
||||
.public _020927E4
|
||||
.public _020927EC
|
||||
.public _020927FC
|
||||
.public _02092844
|
||||
.public _020AF23C
|
||||
.public _020AF240
|
||||
.public _020AF264
|
||||
.public _020AF288
|
||||
.public _020AF2AC
|
||||
.public _020AF2B8
|
||||
.public _020AF2C4
|
||||
.public _020AF344
|
||||
.public _020AF354
|
||||
.public _020AF360
|
||||
.public _020AF368
|
||||
.public _022A3248
|
||||
.public _022A3538
|
||||
.public _022A353C
|
||||
.public _022A3554
|
||||
.public _022A35E8
|
||||
.public _022A3614
|
||||
.public _022A3620
|
||||
.public _022A362C
|
||||
.public _022A3644
|
||||
.public _022A3658
|
||||
.public _022A3670
|
||||
.public _fadd
|
||||
.public _fflt
|
||||
.public _fmul
|
||||
.public _s32_div_f
|
||||
.public abs
|
||||
.public sprintf
|
||||
.public sqrtf
|
||||
.public strcat
|
||||
.public strcmp
|
||||
.public strcpy
|
||||
.public strlen
|
||||
.public strncpy
|
||||
.public sub_02002368
|
||||
.public sub_020023A8
|
||||
.public sub_02002580
|
||||
.public sub_020027F8
|
||||
.public sub_02002A9C
|
||||
.public sub_02002B38
|
||||
.public sub_02002B50
|
||||
.public sub_02002B7C
|
||||
.public sub_02002C40
|
||||
.public sub_02002CAC
|
||||
.public sub_02002CB4
|
||||
.public sub_02002E10
|
||||
.public sub_02002E98
|
||||
.public sub_0200302C
|
||||
.public sub_020030FC
|
||||
.public sub_020031C0
|
||||
.public sub_0200844C
|
||||
.public sub_0200846C
|
||||
5132
asm/main_02003DB8.s
5132
asm/main_02003DB8.s
File diff suppressed because it is too large
Load Diff
5002
asm/main_020040AC.s
Normal file
5002
asm/main_020040AC.s
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
12
asm/main_rodata_02092580.s
Normal file
12
asm/main_rodata_02092580.s
Normal file
@@ -0,0 +1,12 @@
|
||||
.include "asm/macros.inc"
|
||||
.include "main_rodata_020908D4.inc"
|
||||
|
||||
.rodata
|
||||
.global _02092580
|
||||
_02092580:
|
||||
.byte 0x6F, 0x76, 0x65, 0x72
|
||||
.byte 0x6C, 0x61, 0x79, 0x2E, 0x63, 0x00, 0x00, 0x00
|
||||
.global _0209258C
|
||||
_0209258C:
|
||||
.byte 0x63, 0x68, 0x65, 0x63, 0x6B, 0x20, 0x67, 0x72
|
||||
.byte 0x6F, 0x75, 0x70, 0x20, 0x65, 0x72, 0x72, 0x6F, 0x72, 0x00, 0x00, 0x00
|
||||
7534
asm/main_rodata_020925A0.s
Normal file
7534
asm/main_rodata_020925A0.s
Normal file
File diff suppressed because it is too large
Load Diff
9
include/main_02003ED0.h
Normal file
9
include/main_02003ED0.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef PMDSKY_MAIN_02003ED0_H
|
||||
#define PMDSKY_MAIN_02003ED0_H
|
||||
|
||||
#include "util.h"
|
||||
#include "debug.h"
|
||||
|
||||
bool8 OverlayIsLoaded(s32 group_id);
|
||||
|
||||
#endif
|
||||
4
main.lsf
4
main.lsf
@@ -31,6 +31,10 @@ Static main
|
||||
Object asm/main_020038D8.o
|
||||
Object src/main_02003D2C.o
|
||||
Object asm/main_02003DB8.o
|
||||
Object src/main_02003ED0.o
|
||||
Object asm/main_rodata_02092580.o
|
||||
Object asm/main_rodata_020925A0.o
|
||||
Object asm/main_020040AC.o
|
||||
Object src/main_02008210.o
|
||||
Object asm/main_02008240.o
|
||||
Object src/main_02008254.o
|
||||
|
||||
84
src/main_02003ED0.c
Normal file
84
src/main_02003ED0.c
Normal file
@@ -0,0 +1,84 @@
|
||||
#include "main_02003ED0.h"
|
||||
|
||||
extern const u8 _02092580[];
|
||||
|
||||
const struct prog_pos_info _02092558[] = {
|
||||
{(u8*)_02092580, 887},
|
||||
{(u8*)_02092580, 534},
|
||||
{(u8*)_02092580, 177},
|
||||
{(u8*)_02092580, 269},
|
||||
{(u8*)_02092580, 626},
|
||||
};
|
||||
|
||||
extern u8 _0209258C;
|
||||
extern s32 LOADED_OVERLAY_GROUP_0[3];
|
||||
|
||||
bool8 OverlayIsLoaded(s32 group_id)
|
||||
{
|
||||
struct prog_pos_info ppi;
|
||||
|
||||
switch (group_id) {
|
||||
case 0:
|
||||
return 1;
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
return LOADED_OVERLAY_GROUP_0[2] == group_id;
|
||||
case 4:
|
||||
case 5:
|
||||
if (LOADED_OVERLAY_GROUP_0[2] != 1) {
|
||||
return 0;
|
||||
}
|
||||
return LOADED_OVERLAY_GROUP_0[1] == group_id;
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
if (LOADED_OVERLAY_GROUP_0[1] != 4) {
|
||||
return 0;
|
||||
}
|
||||
return LOADED_OVERLAY_GROUP_0[0] == group_id;
|
||||
case 13:
|
||||
case 14:
|
||||
case 15:
|
||||
if (LOADED_OVERLAY_GROUP_0[2] != 2) {
|
||||
return 0;
|
||||
}
|
||||
return LOADED_OVERLAY_GROUP_0[1] == group_id;
|
||||
case 16:
|
||||
case 17:
|
||||
case 18:
|
||||
case 19:
|
||||
case 20:
|
||||
case 21:
|
||||
case 22:
|
||||
case 23:
|
||||
case 24:
|
||||
case 25:
|
||||
case 26:
|
||||
case 27:
|
||||
case 28:
|
||||
case 29:
|
||||
case 30:
|
||||
case 31:
|
||||
case 32:
|
||||
if (LOADED_OVERLAY_GROUP_0[1] != 0xd) {
|
||||
return 0;
|
||||
}
|
||||
return LOADED_OVERLAY_GROUP_0[0] == group_id;
|
||||
case 33:
|
||||
case 34:
|
||||
case 35:
|
||||
case 36:
|
||||
if (LOADED_OVERLAY_GROUP_0[1] != 0xe) {
|
||||
return 0;
|
||||
}
|
||||
return LOADED_OVERLAY_GROUP_0[0] == group_id;
|
||||
default:
|
||||
ppi = _02092558[2];
|
||||
Debug_FatalError(&ppi, &_0209258C);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user