Commit Graph

21 Commits

Author SHA1 Message Date
Test User
eb284575b3 Func_* labeling: 23 functions (list primitives, credits scroll, OW meet-cutscenes)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 20:14:07 -04:00
Test User
86516e3fa5 Func_* labeling: 54 functions (SFX engine, damage-HUD anim, ContinueOW, Aaron steps)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 20:08:27 -04:00
Test User
2c99d4ac17 Func_* labeling: 27 functions (cup RNG, scroll math, sprite-anim, debug viewer, SFX)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 20:01:49 -04:00
Test User
7898c470e3 Func_* labeling: 51 functions (OW script tail: Ronald scenes, GR-island map, platforms)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 19:56:22 -04:00
Test User
88393e2d14 Func_* labeling: 88 functions (appearance-checks + ow_script coord handlers) - OW table seams complete
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 19:49:12 -04:00
Test User
750557449b Func_* labeling: 108 npc_script handlers (fort trainers, chests, lobbies) - seam complete
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 19:43:11 -04:00
Test User
dc972883e9 Func_* labeling: 57 npc_script handlers (club lobbies + strongholds) via parallel subagents
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 19:39:00 -04:00
Test User
e9da34733f Func_* labeling: 79 npc_script handlers (7 Clubs + Mason Lab) via parallel subagents
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 19:33:15 -04:00
Test User
6a6842e19b Func_* labeling: 23 functions via parallel subagents (OW dispatch/frame helpers, duel)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 19:22:33 -04:00
Test User
e15cc16bf1 Func_* labeling: 24 functions via parallel subagents (OW suspend/resume, printer, mailbox)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 19:17:26 -04:00
Test User
7468d6ab3c Func_* labeling: 21 functions via parallel subagents (OW screen/object/map)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 19:12:47 -04:00
Test User
1f690b7b46 Func_* labeling: 20 functions via parallel subagents (duel/OW/scripts)
8 subagents analyzed 20 functions; verified and applied:

Duel effect/damage: ApplyStrikesBackOrPoisonFluid (tcg1
  HandleStrikesBack_AgainstDamagingAttack), SubtractHPAndPrintReceivedDamage,
  ApplyMirrorShellDamageModifiers, LoadAttackerCardNameLevelToTxRam2
Overworld fade/anim: StartOverworldFadeIn, StartOverworldFadeOut,
  UpdateOverworldPaletteCycle, ApplyCreditsFadeConfig,
  ExecutePlayerInteractScript, LoadAndQueueOWMapTilemap,
  WriteTileAndAttrToBGMap0AtCoord
Features: MasonChallengeMachineAfterDuel, GRChallengeMachineAfterDuel,
  DrawColorChangeScreen (tcg1 HandleColorChangeScreen.DrawScreen),
  DisplayDeckDiagnosisAdvice, SelectDeckToCheck, WalkPlayerAlongTCGIslandPath,
  ReceiveCardIntoCollection, GiveDeckToPlayer, HandleImakuniAfterDuel

make compare: poketcg2.gbc OK (symbol-only, byte-identical).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 19:05:37 -04:00
Test User
44af303607 Func_* labeling: name 554 OW map-script handlers by their OWMODE slot
ExecuteOWModeScript walks each map's <Map>_MapScripts table of
`dbw OWMODE_<MODE>, <handler>` entries -- tcg2's variable-length
generalization of tcg1's fixed 8-slot MapScripts table. Like tcg1, the
handlers are named per map+slot.

tools/name_mapscripts.py generates <Map>_<OWMODEAction> names mechanically
(16 OWMODE modes -> CamelCase actions) for every Func_* handler that is
map-specific and collision-free, then applies them. 554 handlers across
116 map tables named in one pass (e.g. GrCastleEntrance_LoadNPCs,
FightingFortMaze22_StepEvent, IshiharasHouse_MusicPreload). Func_2c4db was
a duplicate in-table entry, named manually (LightningClub_MusicPreload).

This clears ~48% of the remaining Func_* placeholders.

make compare: poketcg2.gbc OK (symbol-only, byte-identical).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 18:59:38 -04:00
Test User
281cb387ea Func_* labeling: 14 functions via parallel subagents (+ OWMODE map-scripts)
8 subagents analyzed ~15 functions in parallel; verified and applied:

OW/engine: LoadOWObjectStates, SetOWObjectSpriteAnimMovement,
  LoadOWMapTilemapNoDimensions, LoadFirstSpriteAnimFrame
Duel/UI:   PlayDuelistIntroScene, LoadNPCDuelConfiguration,
  PrintTextNoDelay_ZeroAttributes

Key discovery: ExecuteOWModeScript dispatches a per-map <Map>_MapScripts
table of `dbw OWMODE_*, handler` entries, so each map's lifecycle handlers
are nameable as <Map>_<OWMODEAction>. Did two full map tables:
  RockClubEntrance_{MusicPreload,MusicPostload,StepEvent,WarpFadeInPreload}
  RockClub_{MusicPreload,StepEvent,LoadNPCs}

Deferred Func_235e (low-confidence text-LRU helper).

make compare: poketcg2.gbc OK (symbol-only, byte-identical).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 18:43:56 -04:00
Test User
c07a2e8d5c Func_* labeling: 11 engine functions analyzed in parallel by subagents
Fanned the analysis out to 7 subagents (each read the body + checked tcg1,
returned a structured name proposal); verified and applied centrally:

  Func_1059f  -> BackupOverworldStateToWRAM3
  Func_105de  -> RestoreOverworldStateFromWRAM3
  Func_10ea7  -> PushOWObjectsAndExtraByteToBank3
  Func_10ed3  -> PullOWObjectsAndExtraByteFromBank3
  Func_10d40  -> InitOverworldObjectState
  Func_10f32  -> SaveOWObjectStates
  Func_12c0b7 -> LoadOWMapTilemap
  Func_12c1c1 -> DecompressPermissionMap   (tcg1 name match)
  Func_10b9c  -> ReloadSpriteAnimTilesets
  Func_1dfb9  -> ClearDuelAnimationState
  Func_189d   -> CheckAndDisplayDefenderTransparency  (the deferred one,
                 resolved via a deep dive into wEffectFunctionsFeedback)

make compare: poketcg2.gbc OK (symbol-only, byte-identical).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 18:37:12 -04:00
Test User
1420d0c840 Func_* labeling: HandleAfterDamageEffects + DrawCurrentPlayAreaPrizeCards
Func_17fb -> HandleAfterDamageEffects  (tcg1 name; the AFTER_DAMAGE effect ->
               status conditions -> last-turn damage -> knockouts cascade run
               by PlayAttackAnimation_DealAttackDamage)
  Func_83b3 -> DrawCurrentPlayAreaPrizeCards  (player/opp prize-card draw for
               TurnDuelistTakePrizes; tcg1 Func_82b6)

Deferred Func_189d (tcg2-specific wEffectFunctionsFeedback) and Func_2c4b
(ambiguous text helper) rather than guess.

make compare: poketcg2.gbc OK (symbol-only, byte-identical).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 18:31:09 -04:00
Test User
46764adb75 Func_* labeling: palette-fade quad, screen-anim runner, BG-palette trio
Next duel/engine batch (8), from the dynamic graph + static callees:

  Func_1c735 -> FadeBGPalsToTarget            (FadeColorToTarget over wTargetBGPalettes)
  Func_1c767 -> FadeOBPalsToTarget
  Func_1c799 -> UpdatePaletteFadeToWhiteOrBlack
  Func_1c7b6 -> UpdatePaletteFadeToTarget      (FadePalettes dispatches to these two)
  Func_1e088 -> UpdateScreenAnimations         (active screen-anim fn or anim queue)
  Func_6c12  -> LoadDuelScreenBGPalettes       (Pals_6f0d8 -> BG pals 2-4)
  Func_6c15  -> LoadDuelBGPalettesFromHL        (shared copy core)
  Func_6c1d  -> LoadCardPictureBGPalettes      (Pals_6f0f0; the card-pic palettes)

The 6c12/6c1d pair resolves the TODO left during the duel-gfx work.

make compare: poketcg2.gbc OK (symbol-only, byte-identical).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 18:26:13 -04:00
Test User
c299256899 Func_* labeling: name 6 duel/engine functions via the dynamic call graph
Used cg.txt (a duel play-through's deduped dynamic graph) + static callees
+ tcg1 as a semantic reference to name a confident batch:

  Func_6fa5   -> TakePrizesForKnockedOutPokemon  (CountKnockedOutPokemon + TurnDuelistTakePrizes)
  Func_6986   -> TriggerPlayedEnergyCardEffect    (played card's PKMN_POWER_TRIGGER effect)
  Func_1bb4   -> RedrawDuelSceneAndPrintFailedEffect (HandleConfusionDamageToSelf)
  Func_12c36a -> AdvanceToNextSpriteAnimFrame      (inc frame index + GetFramesetData)
  Func_fc094  -> ExecuteNextSFXCommand             (tcg1 exact match)
  Func_fc094_2-> ExecuteNextSFX2Command            (bank-$7f SFX2 copy)

make compare: poketcg2.gbc OK (symbol-only, byte-identical).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 18:21:12 -04:00
Test User
cdb9264a7d Func_* labeling: add dynamic call-graph tooling
Static analysis can't see indirect dispatch (jump tables, `jp hl`), which
reaches most of the ~974 unreferenced Func_*. Add a runtime call graph:

- SameBoy (tools/sameboy_trace) patched to accumulate a DEDUPLICATED set of
  (caller -> callee) edges for every taken CALL/RST/`jp hl`, gated by
  SAMEBOY_CALLGRAPH=<file>. The output is bounded by distinct edges, not a
  growing per-call log; dumped on clean exit / SIGTERM. (Patch lives in the
  separate sameboy checkout's SDL/main.c; binary installed in tools/.)
- tools/callgraph.py --dyn <dump>: resolves bank:pc edges to func->func via
  poketcg2.sym and flags dynamic-only callers/callees (<-* / ->*) -- the
  indirect edges the static graph misses.

Validated: a short boot/title run already surfaces real indirect dispatch,
e.g. FadePalettes -> Func_1c799/Func_1c7b6 (bank-specific fade handlers).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 18:07:17 -04:00
Test User
51edd23b09 Func_* labeling: name the overworld/animation frame-function cluster
Phase 1 pilot on bank 04's xref-referenced cluster. Named the two
per-frame "frame functions" and their Set/Unset stack wrappers, using
tcg2's existing FrameFunc_* / Set..FrameFunc / Unset..FrameFunc
convention and confirming each by callers + named callees:

  Func_3a39  -> FrameFunc_Overworld          (UpdateOWScroll + sprite anims + FadePalettes)
  Func_1109f -> SetOverworldFrameFunc         (pushes it; OverworldLoop / CreditsCmd_InitOW)
  Func_110a8 -> UnsetOverworldFrameFunc        (pops it; CreditsCmd_DeinitOW ...)
  Func_3a81  -> FrameFunc_AnimationQueue      (gated on wActiveScreenAnim)
  Func_110b9 -> SetAnimationQueueFrameFunc     (ResetAnimationQueue)
  Func_110c2 -> UnsetAnimationQueueFrameFunc   (FinishQueuedAnimations)

make compare: poketcg2.gbc OK (symbol-only, byte-identical).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 17:48:27 -04:00
Test User
2058080637 Func_* labeling: Phase 0 tooling + ledger
Stand up the infrastructure for naming the 1,209 Func_* placeholders:

- tools/match_tcg1.py: fingerprints function bodies (opcode stream with
  16-bit address operands masked) and proposes byte-identical tcg1 names.
- tools/callgraph.py: caller/callee graph; surfaces named callees that
  describe a Func_, and lists a bank's Func_* by reference count.
- FUNC_LABELS.md: ledger + methodology + the measured reality.

Key finding that reshapes the plan: tcg1 byte-porting only resolves ~10
functions (the byte-identical engine code is already named in tcg2; the
unnamed Func_* are mostly tcg2-specific sequel code). Static xref is the
real lever (~225 funcs self-describe via named callees); the other ~974
are fallthrough/indirect/dead and need per-function analysis + tracing.

First validated rename via the loop: Func_8f10 ->
InitBoosterPacksAndDeckCounterSaveData (tcg1 exact match, adapted to
tcg2's SRAM symbols).

make compare: poketcg2.gbc OK (byte-identical).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 17:42:42 -04:00