mirror of
https://github.com/pret/pmd-sky.git
synced 2026-09-28 05:07:58 -05:00
f47593d94ec5ca5d7f88d87e55363eb6bc6b1aa2
sub_0203D538 (0x0203D538, 1666 instructions in US and EU, 1640 in JP) is the mission-reward state machine: a 77-case dense switch over MISSION_REWARD_STRUCT_MAIN_PTR->field_0x0 driving money, egg, item, rank-up and recruit rewards through dialogue boxes and menus. It is function 13 of 89 in asm/main_0203CAF0.s, so extract_function.py splits rather than merges: the 76 functions after it move to asm/main_0203EFD4.s, the function lands in src/main_0203D538.c with include/main_0203D538.h, and main.lsf lists both new objects where it listed one. src/overlay_24_init.c declared sub_0203D538 itself, with a live call site in a switch. That extern is removed and the file now includes the new header. Case order is source order and is not ascending - two contiguous runs are swapped (32,33,34 before 30,31; and 52..57 before 45..51), read off the jump table. Every case ends `break` with a single `return 0` after the switch, because the target's exit block itself materialises the value: a `return 0` per case makes MWCC materialise r0 at each of 77 sites and, worse, de-predicates the short blocks above them. case 76 keeps its `return 1`, which is how the target jumps past that shared `mov r0, #0`. The nine function-scope locals are declared buffer-first then the five struct item in reverse case order, because MWCC gives the first-declared local the highest stack address and the target wants the buffer at sp+0x22. That ordering costs no instructions, so it shows up only as a wrong offset at every stack access - not as a length difference. struct unk_020AFE74 is a placeholder for the 0x3C0-byte state struct, with field_0x<off> members and two u8 filler ranges this function never touches; it cannot be honestly typed from one caller. The 19 callees with no declaration anywhere are declared extern in the .c with prototypes read off their own asm, and two of them - sub_02046C78 and sub_02046D20 - take no arguments, contradicting src/main_020663C8.c. Region handling: 35 message ids carry a uniform +0x21D4 under JAPAN via one file-scope offset macro; one id at 0x2CC shifts by +0x2D20 instead and needs its own ifdef; StrncpySimple becomes the two-argument StrcpySimple; and JAPAN omits case 74's item fetch, its name formatting and its early-exit guard, which is what removes a struct item local and takes the frame from 0x11C to 0x114. EUROPE is byte-identical to NORTH_AMERICA - there is no EUROPE directive anywhere in this function. Authored by Claude (Opus 5) under human direction. Confirmed by matching builds of all three regions: build/pmdsky.us/pmdsky.us.nds: OK, build/pmdsky.eu/pmdsky.eu.nds: OK, build/pmdsky.jp/pmdsky.jp.nds: OK. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Pokémon Mystery Dungeon: Explorers of Sky
This is a WIP disassembly of Pokémon Mystery Dungeon: Explorers of Sky. For instructions on how to set up the repository, please read INSTALL.md. For information on how to contribute changes, see CONTRIBUTING.md.
This repository builds the following ROMs:
- pmdsky.us.nds
sha1: 5fa96ca8d8dd6405d6cd2bad73ed68bc73a9d152 - pmdsky.eu.nds
sha1: c838a5adf1ed32d2da8454976e5b1a1aa189c139 - pmdsky.jp.nds
sha1: 7785138dd343b6f2d0f2c9cadc26b4aa927161d7
For contacts and other pret projects, see pret.github.io.
Description
Languages
Assembly
66.3%
C
18%
C++
7.1%
Boogie
4.3%
sed
1.5%
Other
2.8%