Twelve contiguous functions from the head of asm/overlay_11_02308D1C.s,
merged into src/overlay_11_02307334.c so the .s splits rather than the
source file:
ov11_02308D1C ov11_02308D48 ov11_02308DD8 ov11_02308EB4
ov11_02308EDC ov11_02308F14 ov11_02308F4C ov11_02308FD0
ov11_02308FEC ov11_0230901C ov11_02309040 ov11_02309084
Ten are callees of ov11_02307334; ov11_02308D1C and ov11_02308D48 are the
head neighbours that had to clear first for the run to reach a file
boundary. The remainder of the file becomes asm/overlay_11_023090DC.s,
which keeps the OV11_02309084_OFFSET definition its 24 users need.
include/overlay_11_02307334.h gains struct unk_02309DAC, struct
unk_02308F4C and the twelve prototypes; nine superseded void*-typed
forward declarations in src/overlay_11_02307334.c are removed.
Two file-local types in src/overlay_11_02307334.c change. struct
unk_02324D90 is added, its second member region-split (JP 0xF0 against
0x110 elsewhere). struct unk_02324D8C's u8 field_0x104[0x134] splits into
u8 field_0x104[0x32] plus char field_0x136[0x102] -- same size, same
layout, naming the offset ov11_02308DD8 writes through. Neither type
appears outside this file.
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>
Each was verified at score 0 against its NORTH_AMERICA, EUROPE and JAPAN targets
before landing, with the address walk closing exactly in each region, and by a
matching US build after.
overlay_29_0231E9F0.c InitMoveWrapper, MoveIsNotPhysical, CategoryIsNotPhysical
overlay_29_022E45B8.c ov29_022E45CC, ov29_022E45D0
overlay_29_022F0590.c UnfreezeAnim
overlay_29_02311010.c TickNoSlipCap
dungeon_logic_6.c ov29_022EFB84
main_02062A58.c sub_02062AD0
main_0200224C.c AddFixedPoint64
main_0202A66C.c CreateParentMenuFromStringIds
All eleven merge into an adjacent source file; no assembly file is split. Two of
them were bought cheaply: InitMoveWrapper is four instructions and clearing it
puts MoveIsNotPhysical and CategoryIsNotPhysical at the file head, and
ov29_022E45CC is a single instruction standing in front of ov29_022E45D0.
TickNoSlipCap needed a repair the compiler could not report. extract_function.py
placed its generated placeholder immediately after a pre-existing `#ifdef EUROPE`
in overlay_29_02311010.c, so the definition existed only in EU builds: every
object compiled and the failure appeared at the link step as
`Undefined : "TickNoSlipCap"`, referenced from ActivateEndOfTurnEffects in the
same object. Moving it out of the block then exposed two of its own declarations
that had been invisible while the region never compiled it. main.lsf confirms the
merge target itself was right -- asm/overlay_29_0230F9A4.o is immediately followed
by src/overlay_29_02311010.o, and the function sat at the tail of the former.
build-tools/check_landed_guards.py now reports any definition at conditional
depth > 0; it is clean across every function landed so far.
Twelve call-site declarations are replaced by an include of the owning header.
CreateParentMenuFromStringIds had THREE mutually contradictory ones --
(void*, u32, void*, void*), (u32*, u32, struct struct_2*, u32*), and the matching
signature -- which could coexist only while the function had no header. Its body
indexes the fourth argument as struct unk_0202A5CC throughout, so the two call
sites are cast rather than the parameter weakened to void*, which would only move
the casts inside.
Authored by Claude (Opus 5) under human direction. Confirmed by a matching
build: build/pmdsky.us/pmdsky.us.nds: OK.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Each was verified at score 0 against its NORTH_AMERICA, EUROPE and JAPAN targets
before landing, with the address walk closing exactly in each region, and by a
matching US build after.
main_0200224C.c sub_02002228, ClampedLn
main_020114F8.c ApplyGummiBoostsToTeamMember
main_0200F798.c RemoveItemNoHoleCheck
main_02062A58.c CanMonsterBeUsedForMission
main_0205D11C.c CountAndPopulateValidMissionTableMonsters
overlay_10_022BCC60.c ov10_022BCDF4
overlay_29_022E4338.c PlayEffectAnimationEntityStandard
overlay_29_022EAC7C.c MusicTableIdxToMusicId
overlay_29_022ECDC0.c ov29_022ECD84
overlay_29_022F0590.c ov29_022F0534
overlay_29_0230A9DC.c AftermathCheck
dungeon_logic_6.c ov29_022EFB20
Every one sat at the head or tail of its .s, so all thirteen merge into an
adjacent source file and no assembly file is split. sub_02002228 is one
instruction and was taken only because it is the single function standing between
ClampedLn and the end of its file.
Ten call-site declarations are replaced by an include of the owning header,
including three unprototyped `extern int ov29_...();` forms in
src/overlay_29_02308FBC.c that became hard conflicts the moment these functions
had real headers to contradict.
Three implicit-conversion errors were fixed by correcting a declaration rather
than by adding a cast, which is the better repair when the declaration is ours:
RANDOM_MUSIC_ID_TABLE had no C declaration anywhere, so the u16 in the first
draft was a guess. It is declared `enum music_id[30][4]` here; -enum min sizes
that enum (max 999) to two bytes, so the layout is unchanged and the cast is
unnecessary.
GetBaseForm and IsMonsterMissionAllowed had no declaration either, and the
invented `enum monster_id` parameters created the conversions. They take s16
here, matching the tree's own FemaleToMaleForm(s16) and
HasMonsterBeenAttackedInDungeons(s16) for the same ids.
One cast is kept deliberately: MUSIC_ID_TABLE entries carry a 0x8000 flag bit
that the source tests and masks off, so an entry is not a valid music_id
enumerator and typing that table as the enum would be false.
Two generated headers are made self-contained -- overlay_29_022EAC7C.h named
enum music_id and main_0200224C.h named struct fixed_point_64 without including
anything, so each prototype built its own scoped tag and the definition read as a
redeclaration with a different type.
Authored by Claude (Opus 5) under human direction. Confirmed by a matching
build: build/pmdsky.us/pmdsky.us.nds: OK.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Each function was verified at score 0 against its NORTH_AMERICA, EUROPE and
JAPAN targets before landing, with the address walk closing exactly in each
region, and by a matching US build after.
main_020517D4.c GetRankUpEntry
main_02001188.c MemAlloc
main_0203088C.c CloseAdvancedTextBox
main_020114F8.c ApplyGummiBoostsToGroundMonster
main_0205283C.c GetExp
overlay_29_02305C04.c EndNegativeStatusConditionWrapper
overlay_29_02338350.c NearbyAllyIqSkillIsEnabled
overlay_29_022E9FC0.c AdvanceFrame
overlay_29_022E99F0.c TickStatusTurnCounter
overlay_29_0234B4BC.c LogMessageByIdWithPopup
overlay_29_0234B340.c LogMessageByIdWithPopupCheckUserTarget
All eleven sat at the head or tail of their .s, so every one merges into the
adjacent source file and no assembly file is split.
Forty call-site declarations of these functions are replaced by an include of
the owning header. Two of them disagreed with the real signature, and one had to
be fixed for the tree to compile at all:
MemAlloc was declared six different ways. src/overlay_24_end.c spelled it
`void* MemAlloc(s32, s32);` -- signed -- and that file already
includes main_02001188.h, so the contradiction became a hard
compile error the moment MemAlloc had a header to contradict.
It had been harmless only because the function had none.
AdvanceFrame was declared `void AdvanceFrame(u8);` in two overlay_31 files
against the real u32. Byte-neutral in practice, since every call
site passes the literal 0x62, but wrong.
struct unk_020517F4 was defined file-locally in src/main_0203D538.c. It now has
one definition, in include/main_020517D4.h, and both local copies are gone --
otherwise including that header where GetRankUpEntry is called would collide.
Two generated headers are made self-contained. extract_function.py emits a
header that names types it does not include, and since the .c includes it first,
the prototype builds its own scoped tag: include/main_020114F8.h declaring
`struct ground_monster *` before common.h defines it made the definition read as
a redeclaration with a different type.
Authored by Claude (Opus 5) under human direction. Confirmed by a matching
build: build/pmdsky.us/pmdsky.us.nds: OK.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Every function was verified at score 0 against its NORTH_AMERICA, EUROPE and
JAPAN targets before landing, with the target's address walk closing exactly in
each region, and by a matching US build after landing.
overlay_29_0233E43C.c GenerateRoomImperfections, CreateHallway
overlay_29_022E3F20.c UpdateStatusIconFlags, PlayQuestionMarkEffect,
PlayExclamationPointEffect__022E47D4,
PlayExclamationPointEffect__022E4880, ov29_022E3E74
dungeon_util_2.c PopulateActiveMonsterPtrs, GetTeamMemberIndex,
GetMonsterOrTrapName, SubstitutePlaceholderStringTags
overlay_29_022EC7E8.c IsFloorOver (new file)
overlay_29_02345A3C.c SpawnDroppedItemWrapper (new file)
overlay_29_023061A8.c EndBurnClassStatus (new file)
overlay_29_02306728.c EndCurseClassStatus (new file)
overlay_29_02336F4C.c UpdateTrapsVisibility (new file)
Eleven were landed at a file boundary by first decompiling the functions between
them and the nearest end of their .s, so they merge into the adjacent source file
instead of splitting it. The other five sit too far from either end to make that
worthwhile and split their .s as usual.
CreateHallway closes a provisional declaration: CreateGridCellConnections had
declared it from the call site as (s32 arg1 .. s32 arg7), and that guessed
prototype is now replaced by the real one in the same header.
Eighteen pre-existing declarations of these functions, written from call sites in
other translation units, are replaced by an include of the owning header. Three
of them disagreed with the real signature, and no build could have caught any of
them because two declarations of one function never meet in a single translation
unit:
IsFloorOver declared `extern s32` in two files; it returns bool8.
SpawnDroppedItem declared `void`; SpawnDroppedItemWrapper returns its
value. Corrected in src/dungeon_projectile_throw.c.
SetPreprocessorArgsStringToName
declared with `u8 pos` / `u8 param_4`. Every existing
call site passes literal constants, where the narrowing
is invisible; SubstitutePlaceholderStringTags passes
variables, and the narrow form emits two `and rX,#0xff`
rows the target does not have. Widened to s32/u32.
GetMonsterOrTrapName is landed with three parameters rather than two. Both score
0 -- an ignored third argument costs the callee nothing, so the callee's bytes
cannot distinguish them -- but src/overlay_31_02382820.c has always called it
with three, which is evidence about the caller that the callee cannot supply.
pret/pmd-red was used as a structural reference where it has an equivalent
function. It supplied the shape and never the spelling: it is a different game
built by a different compiler. IsFloorOver is the clearest case -- translating
its nested form literally scored 1525, and flattening to four independent early
returns scored 0.
Authored by Claude (Opus 5) under human direction. Confirmed by a matching
build: build/pmdsky.us/pmdsky.us.nds: OK.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Re-land eight already-matching functions in more idiomatic C. Every one was
verified at score 0 in each region it has a target for BEFORE landing, and by
a matching US build AFTER landing, one function at a time.
CreateGridCellConnections 320 -> 278 eight (u32) index casts removed
GenerateExtraHallways 170 -> 161 terrain_flags & 3 -> GetTerrainType
ActivateEndOfTurnEffects 538 -> 533 MAX_HP_LIMIT for the 999 literals
ApplyDamageAndEffects 316 -> 314
CalcDamage 635 -> 631 one volatile local dropped
ApplyDamage 807 -> 818
ov11_022ED69C 242 -> 240 const void * -> typed pointers
ov11_02307334 733 -> 735 three redundant (u8 *) casts dropped
The CreateGridCellConnections index casts had been recorded as load-bearing.
They are not. MWCC keys common-subexpression elimination on the address
expression INCLUDING integer conversion nodes, so an `int` alias of an `s32`
index splits the use-set exactly as a cast does, while a same-type copy is
erased by copy propagation. An identity (s32) cast is byte-identical to the
(u32) one, and casting every site is byte-identical to casting none, which is
what shows the lever is the split rather than the cast.
overlay_29_0233C9E8.c gains #include "dungeon.h" and "dungeon_util_static.h"
for TERRAIN_TYPE_*, DUNGEON_MAX_SIZE_* and GetTerrainType. All three were
already in the tree; no name is introduced here.
Three candidate rephrasings were rejected on measurement and are not included:
one scored 1195 in EUROPE against a landed baseline of 10, one carried an
artificial `damage_data++; damage_data--;` pair, and one did not match at all.
Authored by Claude (Opus 5) under human direction. Confirmed by a matching
build after each individual change: build/pmdsky.us/pmdsky.us.nds: OK.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
573 instructions in overlay_29, the immediate neighbour of
GenerateExtraHallways. No region preprocessor directives -- all three regions
assemble identical text, so one source serves US/EU/JP.
asm/overlay_29_0233CF84.s is split: the function becomes the new pair
src/overlay_29_0233E43C.c + include/overlay_29_0233E43C.h, and the remainder
becomes asm/overlay_29_0233ED34.s. main.lsf gains two objects.
The header adds a provisional prototype for CreateHallway, which had no C
declaration anywhere in the tree. Its arity of 7 is read off its own prologue
(ten pushed registers, no sub sp, and reads at [sp,#0x28]/[sp,#0x2c]/[sp,#0x30]);
the parameter types are the loosest that fit and the names are positional
placeholders.
struct unk_0233C9E8 and FLOOR_GENERATION_STATUS come from
include/overlay_29_0233C9E8.h, landed by the previous function; the grid's
450/30 strides and 450/30 = 15 confirm the (*)[15] shape independently here.
Authored by Claude (Opus 5) under human direction. Confirmed by a matching
build: build/pmdsky.us/pmdsky.us.nds: OK.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
356 instructions in overlay_29. No region preprocessor directives -- all three
regions assemble identical text, so one source serves US/EU/JP.
asm/overlay_29_0233AE84.s is split: the function becomes the new pair
src/overlay_29_0233C9E8.c + include/overlay_29_0233C9E8.h, and the remainder
becomes asm/overlay_29_0233CF84.s. main.lsf gains two objects.
The header carries two placeholder types the function needs and the tree did
not have: struct unk_0233C9E8, the 30-byte dungeon grid cell (no such struct
existed, and the grid is a stack local in every caller, so it has no global to
key a name on), and struct unk_0237CFBC for FLOOR_GENERATION_STATUS, which had
no C declaration anywhere. That symbol's asm reserves .space 0x4 but this
function reads byte +6, so the declaration is sized to what is used.
Authored by Claude (Opus 4.8) under human direction. Confirmed by a matching
build: build/pmdsky.us/pmdsky.us.nds: OK.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
864 instructions, a 19-step pipeline with five jump tables. No region
preprocessor directives -- all three regions assemble identical text, so one
source serves US/EU/JP.
asm/main_0205D1F4.s is split: GenerateMission merges into src/main_0205D11C.c
and the remainder becomes asm/main_0205DFAC.s. main.lsf swaps the object in
place. include/main_0205D11C.h gains struct unk_0205DFAC (the 6-byte record),
struct unk_0205D224 (the 0x22-byte template) and the prototype;
CheckItemForMissionType's second parameter is corrected to
union mission_subtype *.
Authored by Claude (Opus 4.8) under human direction. Confirmed by a matching
build: build/pmdsky.us/pmdsky.us.nds: OK.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ov11_02307334 (0x02307334, 1624 instructions in all three regions) is the
TM/HM use flow: a 42-case dense switch over *ov11_02324D8C, driving the bag
inventory menu, the TM info and confirmation dialogues, the gummi/IQ path and
the move-forget flow through menus, text boxes and scroll boxes. It is
function 145 of 215 in asm/overlay_11_022FE5F8.s, so extract_function.py
splits rather than merges: the 70 functions after it move to
asm/overlay_11_02308D1C.s, the function lands in src/overlay_11_02307334.c
with include/overlay_11_02307334.h, and main.lsf lists both new objects where
it listed one.
Unlike the last three functions on this branch there is no stale extern to
reconcile. The symbol has exactly one caller, ov11_02304B4C, in the same
object and still in asm; it has no external linkage today, appears in no
function-pointer table, and a scan of all 512 .s files for the little-endian
encoding of its address finds nothing.
Three declarations elsewhere in the tree are wrong and this function is the
first caller that makes them matter. RemoveItemNoHoleCheck takes an item
index, not a struct item *: asm/main_0200F390.s does mov r1,#6 / smulbb r1,
r0, r1, and SMULBB multiplies the low halfwords, so the argument is a signed
16-bit value scaled by sizeof(struct item). Its only other caller passes
GetFirstUnequippedItemOfType, which likewise returns an index rather than a
pointer, so the two errors cancelled and the pair matched by accident.
ov10_022BCDA8 is declared void but its body ends in sub_02033064, which
returns s32, and both of this function's call sites consume the result. All
three are -W error blockers here, and the matching build confirms the fixes
are byte-neutral.
Case emission order is source order and is not ascending: 0, 2, 1, 3, 17..25,
33, 34, 31, 32, 35..40, 26..30, 41, then 4..16 last. Every case breaks to a
single trailing return 0; case 16 returns 1, and case 15 falls through into
it. The eight function-scope locals are declared in descending stack-address
order because MWCC gives the first-declared local the highest address, which
tiles the frame exactly to 0x5A0.
The 43-instruction block shared by cases 32 and 34 is written out twice
rather than factored into a helper - MWCC 2.0 does not tail-merge blocks of
that size, and the target has both copies. Several shapes that read as
redundant are load-bearing and reproduce the target: case 4's v1 != 8 &&
v1 == 4, the dead field_0x0 = 0x1a in case 38 and field_0x24e = v6->id in
case 1 that the following if/else overwrites in both arms, the guard
if (field_0x8 == -2) ov11_02308EDC() in case 12 that the callee performs
again itself, and case 21's two search loops being written differently.
struct unk_02324D8C is a placeholder for the 0x330-byte state struct
MemAlloc'd by ov11_02307244, with field_0x<off> members, three identified
sub-object types where the arithmetic closes, and u8 filler elsewhere. The
0x14-byte object at 0x238 has to be a real nested struct: the target holds
base + 0x238 in a callee-saved register across two calls, while flat fields
make MWCC round the base to #0x200 and re-offset per use. The 49 callees with
no declaration anywhere are declared extern in the .c with prototypes read
off their own asm; every name is established by a literal bl in the target,
but the argument types are inference.
Region handling: three file-scope offset macros under JAPAN cover the id
families at +0x2D20 (16 sites), +0x1458 and +0x1567, and the two genuine
three-way forks - the StringFromId base in case 1 and the
CreateScrollBoxSingle base in case 10 - are written out per region as
src/get_category_string.c and src/overlay_25_init.c already do. The asm's
four #ifdef JAPAN code forks need no #if here: each exists only because
exactly one of the two constants is an ARM rotated-8-bit immediate, so
writing id + OFFSET and letting MWCC choose mov versus a pool word
reproduces all four. EUROPE differs from NORTH_AMERICA in two constants and
nothing else.
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>
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>
ApplyItemEffect (0x0231B68C, 1310 instructions in US, 1312 in EU) is the
thrown/eaten item dispatcher: an item-catcher preamble, the sticky-item
block, and then one switch (item->id) over a 183-entry jump table with 85
distinct case bodies, a shared tail that walks
APPLES_AND_BERRIES_ITEM_IDS, and EnemyEvolution. It is the last of ten
functions in asm/overlay_29_0231B33C.s and the next object in main.lsf is
src/overlay_29_0231CBC8.o, so extract_function.py merges rather than
splits and main.lsf is unchanged.
src/dungeon_projectile_throw.c declared ApplyItemEffect itself, with a
live call site. That extern is removed and the file now includes the new
header instead. It is a landed, already-matching object and parameters 1-3
are exactly where a wrong spelling would surface, so its rebuild in all
three regions is a check on the signature rather than tidying.
case ITEM_NOTHING is written explicitly above default even though the jump
table sends id 0 there. The dispatch is cmp r0,#0 / addge pc,pc,r0,lsl #2
with no rebase, and a survey of all 786 such dispatches in asm/ shows
MWCC's table spans the minimum to maximum LABELLED case: 104 of the 105
rebased tables have a real case at index 0, rebases occur for offsets as
small as 3, yet 40 tables have 3-7 leading default entries un-rebased and
82 have trailing default entries, which padding cannot explain. Leading
and trailing default entries are therefore explicit case labels sharing
default's body.
The category-5/10 test that skips the switch is an if/else whose else arm
is the entire switch; both arms fall into the shared tail. Case emission
order is source order and is not ascending (8 before 7, 77 before 74, 136
before 113, 182 before 104, default last).
The 41 callees that are still asm are declared extern in the .c with
prototypes read off their own asm, as the sibling files do, and so are the
28 rodata data symbols - const, with ov10_022C4864 as s32 where the other
25 scalars are s16, which is what makes its load a 32-bit ldr. Two
prototypes deliberately differ from pmdsky-debug: ApplyKeyEffect takes one
parameter, not two, and CalcDamageFixedNoCategory's fifth parameter points
at a one-byte object, not a struct damage_data.
Region handling: seven message ids are file-scope defines at US - 0x2C1
under JAPAN, and one EU-only call to ov29_022FB920 sits inside an
ifdef EUROPE with its prototype. The JP fork of the
exclusive_item_effect_flags offset needs nothing - the header already
models the 4-byte JP struct monster shrink.
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>
ActivateEndOfTurnEffects (0x0230FC24, 1235 instructions in US) is the
per-turn status tick: the warp-scarf counter, the leader's belly and
hunger messages, weather damage, Shed Skin and Hydration, the burn, poison,
bad-poison, constriction, wrap, ingrain, curse and leech-seed damage
countdowns, perish song and bide. It is the last of five functions in
asm/overlay_29_0230F9A4.s and the next object in main.lsf is
src/overlay_29_02311010.o, so extract_function.py merges rather than
splits and main.lsf is unchanged.
struct monster declared 0xAC as u8 bide_move_id plus u8 field_0xad. Retail
accesses it with ldrh/strh and stores 0x165 = MOVE_BIDE_UNLEASH, which
does not fit in a byte; enum move_id runs to 558, so -enum min sizes it to
two bytes - the width struct move's own enum move_id id at 0x2 already
has. The field becomes enum move_id and absorbs field_0xad. The struct
size and every later offset are unchanged, no other source reads either
member, and InitMove already takes enum move_id so no cast is needed. This
deviates from pmdsky-debug's u8; the reasoning note linked from the PR has
the evidence.
The 29 callees that are still asm are declared extern in the .c with
prototypes read off their own asm, as the sibling files do, and so are the
24 data symbols - const on the read-only rodata ones, which is what places
their loads correctly.
Region handling: the sound-effect guard in the hunger block is a genuine
three-way fork, EU calling ov29_022E34A8_EU where JP omits the
end_floor_no_death_check_flag test that US performs, and nine message ids
are file-scope defines at US - 0x2C0 under JAPAN. The JP struct and
dungeon offset shifts are absorbed by the headers with no directive.
Locals are generic and declared at function scope. That is not cosmetic:
the allocator's unit is the coalesced web, and the function-scope
declaration list is the only thing that orders it, so the declaration
order is what reproduces retail's register assignment.
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>
sub_02050EBC, SubFixedPoint, sub_02050F78, sub_02050FF8 and
BinToDecFixedPoint are the last five functions in asm/main_020504BC.s and
all operate on struct fixed_point (106 instructions). The next object in
main.lsf is src/number_util.o, which already holds their sibling
CeilFixedPoint, so extract_function.py merges rather than splits and
main.lsf is unchanged. They are landed in reverse address order so each
prepends above the last, leaving number_util.c in ascending address order
with CeilFixedPoint last.
sub_02050EBC and sub_02050F78 keep their sub_<addr> names - this is
decompilation, not identification.
A 4-byte struct fixed_point is passed and returned by value in r0, packed
as integer | fractional << 16. The stmdb sp!, {r0, r1, r2, r3} at entry is
MWCC giving the argument registers stack homes so a by-value struct
parameter can be addressed, and writing to the parameter reuses that home,
which is why SubFixedPoint and sub_02050EBC modify their first argument
and return it. The caller-side sub rX, sp, #4 idiom around these calls is
compiler-generated, not a source construct: src/dungeon_ai_movement.c
already emits it from a plain CeilFixedPoint(pokemon_info->belly).
None of the five blocks carries a region directive, so one source serves
all three regions.
Authored by Claude (Opus 5) under human direction. Confirmed by a matching
build: build/pmdsky.us/pmdsky.us.nds: OK.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
CalcDamage, CalcTypeBasedDamageEffects, ApplyDamage, ApplyDamageAndEffects
and ov11_022ED69C had locals named after what the decompiler inferred them
to mean. A local's meaning is not something the matching build can check,
so every such name is replaced by a type-derived generic one numbered in
declaration order: fixed-point temporaries fp1.., monster pointers mon1..,
scalar values v1.., bool8 flags f1.., pointers p1.. / ent1.. / item1.. /
ls1.., arrays arr / buf. Names that were already generic (i, j, k, n,
result) or are simply the type's own name (diag, weather, tile, member,
entry, spec) are unchanged, and so are all parameters, whose names upstream
syncs from pmdsky-debug. Declaration order is untouched; only identifiers
change, so no object changes.
Authored by Claude (Fable 5.1) under human direction. Confirmed by matching
builds of all three regions after the rename: 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 Fable 5.1 <noreply@anthropic.com>
CalcDamage (0x0230BBAC, 1290 instructions) is the damage formula: stat
stages, item/ability/IQ-skill modifiers, the fixed-point base formula,
CalcTypeBasedDamageEffects, critical hits, Reflect/Light Screen and the
final multipliers, with its diagnostics in DUNGEON_PTR->last_damage_calc.
It is the first of 26 functions in asm/overlay_29_0230BBAC.s and a rodata
object precedes that object in main.lsf, so extract_function.py splits
rather than merges: the function lands in src/overlay_29_0230BBAC.c with
include/overlay_29_0230BBAC.h, the other 25 move to
asm/overlay_29_0230D088.{s,inc}, and main.lsf lists both objects where it
listed one.
struct damage_calc_diag modelled move_category as a 1-byte enum plus
field_0x5/0x6/0x7 padding (3fc6d8bd). Retail writes that field with a
4-byte str (0x0230BDC8) and reads the eight modifier bytes at 0x30..0x37
unsigned (ldrb at 24 sites), so move_category becomes s32 - the struct
stays 0x54 bytes - and the modifiers become u8 (they were s8). No other
source in the tree reads these members. Both deviate from pmdsky-debug's
declarations; the reasoning note linked from the PR has the evidence.
Region handling follows the neighbouring files: six
DefenderAbilityIsActive__0230A940 calls take three arguments under JAPAN,
and message ids C53/C54/C55/C57/C58 and DC1 are file-scope defines at
US - 0x2C1 under JAPAN. One difference is real source: the defense-side
apparent_id 0x211/0x218 checks compare the attacker's apparent_id under
JAPAN (the JP-only ldrsh r1, [r6, #4]). EU is identical to US.
The 17 callees that are still asm are declared extern in the .c with
prototypes read off their own asm, as the sibling files do. The spelling
of the ability-multiply block (an s32 calc[2] local, two temps and three
volatile s32 * pointers) is match-derived, each element removing one
measured compiler obstacle; the reasoning note explains it.
Authored by Claude (Fable 5.1) 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,
each also passing main.sha1, filesystem.sha1 and arm7.sha1.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
CalcTypeBasedDamageEffects (0x0230AD04, 676 instructions) applies every
type-, ability-, weather- and status-based multiplier to a damage
calculation. It merges into src/type_effectiveness.c, which already held
its callee GetTypeMatchup, so asm/overlay_29_0230AD04.{s,inc} are removed
and main.lsf loses that object with no new object added.
struct damage_calc_diag modelled move_type as a 1-byte enum plus explicit
field_0x1/0x2/0x3 padding, but gave move_category no such padding, so
every member from move_indiv_type_matchups (0x8) to attacker_level (0x16)
compiled below the offset its own comment states. Downstream alignment
before damage_calc re-absorbed the drift, so the struct still totalled
0x54 and no build caught it; the two existing users in the tree both sit
past the re-convergence point. asm/overlay_29_022E0378.s writes 0x188 and
asm/overlay_29_022E335C.s reads 0x184/0x188 with word accesses, so both
fields are four bytes in retail. Adding field_0x5/0x6/0x7 is byte-neutral
for the existing tree.
include/type_effectiveness.h gains overlay_29_02308FBC.h, which defines
the struct unk_02308FE0 its new declaration names.
Region handling follows the neighbouring files: six
DefenderAbilityIsActive__0230A940 calls take three arguments under JAPAN
and four elsewhere, and five message ids are file-scope defines at
US - 0x2C1 under JAPAN. EU is identical to US - the original asm block
carries no EUROPE directive at all.
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,
each also passing main.sha1 and filesystem.sha1.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ApplyDamageAndEffects (617 instructions, overlay 29 at 0x0230863C) lands in
src/overlay_29_02308FBC.c beside ApplyDamage, with all three regions matching.
JAPAN differs in eleven places: ten DefenderAbilityIsActive__0230A940 calls
drop their fourth argument (the header already declares both forms), and the
counter-damage message id is US - 0x2C1, added as MESSAGE_C3F alongside the
existing per-region defines. EUROPE is byte-identical to US.
ApplyDamage's sixth parameter changes from enum damage_source_non_move to
s16. The caller loads it with ldrsh and passes it in a register; the enum is
all-positive so -enum min makes it unsigned 2-byte, which emits ldrh there.
s16 scores 0 on both functions and all three ROMs still match, so this is a
correction to the type rather than a change in behaviour.
New in this commit: struct unk_023535DC for the exclusive-item effect table at
ov29_023535DC (16-byte stride: effect id, argument, handler), and externs for
the ten ov10_022C* activation-chance globals and six overlay callees.
Three constructs are colouring devices rather than recovered source and should
be read as stand-ins: a (u32) cast on the final return, a (s16) cast on the
counter-attack loop's damage-source argument, and *(u8 *)effect as the effect
loop's condition. Each is plain C, and each is load-bearing for the match.
Authored by Claude (Opus 5 and Fable 5) under human direction. Confirmed by
matching builds of all three ROMs: build/pmdsky.us/pmdsky.us.nds: OK,
build/pmdsky.eu/pmdsky.eu.nds: OK, build/pmdsky.jp/pmdsky.jp.nds: OK -- each
also passing main.sha1, so the ARM9 binaries match and not only the packaged
ROMs.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Follow-up to ff65ac0e, which decompiled the US branch only. One source now
matches all three regions:
build/pmdsky.us/pmdsky.us.nds: OK
build/pmdsky.eu/pmdsky.eu.nds: OK
build/pmdsky.jp/pmdsky.jp.nds: OK
JAPAN, five source differences:
- DefenderAbilityIsActive__0230A940 takes three arguments, not four, at six
call sites. include/overlay_29_0230A994.h already declares this, so the JP
build failed to compile rather than to match.
- every message id is US - 0x2C1. Kept as region-conditional #defines at file
scope, following src/dungeon_ai.c.
- no UpdateStatusIconFlags call before the HP check.
- no end_floor_no_death_check_flag guard on the revival-item path.
- in the reviver-seed block, no ov29_022FBD24; instead ov29_02307DC0 after the
curse handling.
EUROPE, one behavioural difference: the last arm of the defeat-message ladder
records a flag instead of logging, and the message is emitted later at three
points - the reviver-seed path, the revival-item path, and their else. The two
revival paths log from a different table.
That table is four bytes that exist only in the EUROPE branch of
asm/overlay_29_rodata_02352A6C.s, immediately after ov29_02353218 and carrying
no symbol; the extractor could only render both as raw addresses (0x02353E44 and
0x02353E40). This commit labels it. The label and .global add no bytes, and the
EU checksum is what confirms both references resolve where intended - had either
been wrong, pmdsky.eu.nds would not match.
The name ov29_02353E44 is keyed to the symbol's EUROPE address, which breaks the
file's convention of naming by US address. There is no US address to use: the
data does not exist in that build.
One change was needed for the EU register allocation and is byte-neutral for the
other two builds: `dmon` is now assigned after the wild-enemy test rather than
before it, with that test reading through defender->info. Introducing the
variable later flips which web the allocator colours first and unwinds a
whole-function rotation of three callee-saved registers.
Authored by Claude (Opus 5) under human direction. Confirmed by matching builds
of all three regions.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ApplyDamage (overlay 29, 0x02308FE0). asm/overlay_29_02308FE0.s and its .inc
are removed and the object drops out of main.lsf; the function merges into
src/overlay_29_02308FBC.c alongside EntityIsValid__02308FBC.
Types added: struct unk_02308FE0 (the damage-data argument, in the function's
header), struct unk_023528A4 and struct unk_022C593C (element types for
TYPE_DAMAGE_NEGATING_EXCLUSIVE_ITEM_EFFECTS and ov10_022C593C, local to the .c).
Field types corrected, each required by the match:
struct monster::bide_damage_tally u32 -> s32 (clamped with strgt)
struct monster::field_0x168 / field_0x169 -> s16 field_0x168 (read ldrsh)
struct dungeon_generation_info::music_table_idx u16 -> s16 (read ldrsh)
TalkToSecretBazaarNpcStandard, ov29_022F0618, TalkToSecretBazaarNpcWithYesNoMenu
and the TalkToSecretBazaarNpc extern take a message id in their first parameter,
not a struct entity *. Every caller loads a small constant into r0 - 0xC6B from
ApplyDamage, 0xF32/0xF4A/0xF4B/0xF4C in asm/overlay_29_02344178.s. The three
tree functions are one-line forwarders, so their parameter types were
unconstrained; ApplyDamage is the first C caller.
Two things a reviewer should weigh. DUNGEON_PTR is declared scalar here
(extern struct dungeon *DUNGEON_PTR;) rather than the *DUNGEON_PTR[] idiom the
other files use - the array form lets MWCC CSE the load and costs three
instructions. And one read is qualified volatile
(*(volatile u8 *)&dmon->curse_class_status.curse) to reproduce a reload retail
performs with no intervening call; it is standard C and the ROM matches, but it
is a stand-in rather than recovered source, and a struct curse_class_status *
local gets to within one instruction without it.
Only the US branch is decompiled; the original block carries 50 preprocessor
directives including two wholesale #ifdef EUROPE duplications.
Authored by Claude (Opus 5) under human direction. Confirmed by a matching
build: build/pmdsky.us/pmdsky.us.nds: OK (main.sha1 passes, so the ARM9 binary
matches and not only the packaged ROM).
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Decompiles ov11_022ED69C (410 instructions) out of
asm/overlay_11_022ECD24.s. The function was first in that file, so the
remainder splits to asm/overlay_11_022EDD14.s and main.lsf gains
src/overlay_11_022ED69C.o ahead of it.
include/ground_bg.h:
- MapRender 0x1C -> 0x54, adding unk1C/unk24/unk2C (two pointers each)
and a 0x20 filler. This consumes GroundBg::fillerForNow2[112]
exactly: 0x210 + 2*0x54 == 0x2B8, so no offset after it moves, and
ground_bg.c only ever uses mapRender[0].
- GroundBg::unk1FC: four unreferenced u8 -> one s32.
- BmaHeader::numLayers/hasDataLayer/hasCollision: u16 -> s16. Retail
reads these with ldrsh; the u16 declaration emitted ldrh and produced
three wrong bytes in OVY_11.sbin. This function is their only reader
in the tree -- every other use is a strh, identical either way -- so
no other object changes.
- RGB_Array, the UnkStruct_2324CBC family, the three palette helpers,
ov11_02320C18 and ov11_02320BF4/BE8 move here from src/ground_bg.c,
which now includes them rather than redeclaring them.
asm/overlay_11_022ECD24_data.s has its .include repointed at the .inc
that survived the split; extract_function.py deletes the old one without
knowing about sibling objects in the same address range.
ov11_022EE9B0 and ov11_022EE8CC are still asm and are declared
provisionally in include/overlay_11_022ED69C.h from their call sites.
Authored by Claude (Opus 5) under human direction. Confirmed by a
matching build: build/pmdsky.us/pmdsky.us.nds: OK.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>