The first _wip project to get a real disassembly. 4,165 instructions /
8,444 code bytes (25.8%), 24,324 data bytes, 0 unclassified -- every byte
of the 32 KB PRG is now classified as code or data.
The split needed three stages, all recorded in prg.s's header:
* nesdis.py --undocumented --auto-seed at base $8000 gave 3,272
instructions / 6,555 bytes. The undocumented opcodes matter here: the
trace stops dead at the first one it cannot decode.
* Four hand-seeded entries ($C08B, $DC1E, $E0D5, $E134). Each is a
branch target from decoded code that sat inside an untraced data run,
so the tracer never reached it.
* A merged four-session Mesen Code Data Logger capture (kept as
xevious_mesen.cdl) promoted 1,902 bytes from data to code and
demoted 22 the trace had called code.
Two tool bugs fell out and are fixed here:
* nesdis.py emitted the undocumented single-byte NOPs ($1A/$3A/$5A/
$7A/$DA/$FA) as `nop`, which ca65 assembles as the *official* $EA --
the rebuild stopped being byte-identical at $DF82. The check now
keys on the opcode byte, not just the addressing mode. All three
`make regen` pipelines (MUSCLE, Pyramid, Urban Champion) are
unaffected and still reproduce prg.s byte for byte.
* cdl_reclass.py left the original data-block header in place when the
CDL split that block, so the file ended up with two region headers
describing overlapping spans (20 of them here). The header is now
dropped with the block it describes; the promoted projects that use
the tool are byte-for-byte unchanged.
The project README has the power-on flow analysis. The most interesting
find is at $FC45: the reset path compares RAM $0100-$0107 against the
ASCII string "Kei Cros", and the copyright text at $FF1E reads
"MAIN: KEI CROSS. SOUND: UHOHOY OHNOGI." The OAM is at $0700, not
$0200 -- the NMI handler does LDA #$07 / STA $4014.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add explicit `make wip` / `make wipclean` targets for the _wip tier
The root Makefile's all / clean / <MAPPER> targets deliberately name only
the promoted mapper folders, so nothing in them reaches into _wip/. Give
the pre-promotion tier its own opt-in targets instead of the manual
`for d in _wip/*/*/; do make -C "$d"; done` loop:
make wip # build + verify every _wip/<MAPPER>/<Project>/
make wipclean # clean the build artifacts in that tier
Both the Makefile and the four documents that describe the tier (README,
TODO, WIP, AGENTS) are updated together, so the tree stays consistent.
The same commit records Xevious (U) reaching Pass 2 in those documents:
all 487 labels named, every branch and call symbolic, zero Label_XXXX and
zero raw $XXXX operands left.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Update the _wip/ tier documentation; fix the make wip target and the mirroring bug
The WIP tier's four documents (WIP.md, README.md, TODO.md, AGENTS.md) had
drifted away from the tree. Every number in them was re-derived from the
ROMs and the folder layout rather than carried forward.
Counts and structure
- The tier holds 854 projects across 29 mapper folders, not "856 across
30". Xevious (U) and Zanac (U) were promoted on 2026-10-20 and their
_wip/ folders were left behind as residue -- "git mv" moves only the
tracked files, so the old folder survived with its build artifacts and a
stale README. Both are removed now; the promotion procedure documents
the step so it does not recur.
- _wip/MAPPER8/ holds a copy of the already-promoted Mermaids of
Atlantis (U) and is excluded from every count and table.
- Pass 0 skeletons: 852 (was 855). Xevious (U) left the tier, so the
two projects with a real disassembly are Golf (JU) and Volleyball (U).
- PRG sizes 2 / 150 / 42 / 522 / 127 / 10 / 1; 226 projects with no CHR;
38 keep the CPU-address linker layout; 37 are mapper 0.
- Every inventory row was re-checked against its ROM: PRG/CHR size,
mirroring, all three vectors, and the battery / four-screen / footer
notes. 854 of 854 rows now match.
Fixes
- The root Makefile used $(WIP) but never defined it, so "make wip" and
"make wipclean" expanded to "for m in /*/" -- they walked the
filesystem root instead of the tier. "WIP := _wip" is now defined, and
"make wip" builds and verifies the whole tier: 855 of 855 passed, 0
failures.
- make_skeleton.py masked header byte 6 with 0x03, so the battery bit
(bit 1) leaked into the mirroring value and 56 battery-backed ROMs'
READMEs claimed "Four-screen" while their own "Four-screen VRAM" row
said "no". The mask is now 0x01 and the 56 READMEs are corrected.
- Golf (JU)'s README still described the pre-flatten copilot/ folder and
the old PRG-only compare; it now describes the whole-ROM build.
- Pyramid (U)'s audit comments are canonical again, so Golf (JU) is the
only project in the tree still on the pre-canonical spelling.
New in WIP.md
- Byte 7's lower nybble is non-zero on 58 of the ROMs -- 55 carry the
literal "DiskDude!" watermark, two "DisNi0330", one "byKH+KEN". Only
the upper nybble carries mapper bits, so the noise is harmless.
- The twelve ROMs that set the four-screen bit, split by whether their
board actually supports four-screen VRAM.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Promote Volleyball (U) from _wip/NROM/ to NROM/
Volleyball (U) reached Pass 3 before promotion, so this is a promotion of a
finished disassembly rather than a Pass 0 skeleton.
The disassembly
- 11,395 instructions / 23,926 code bytes (73.0 % of the PRG image),
8,842 data bytes, 0 unclassified.
- The split needed the game-state dispatch table at $85E1 declared to the
tracer (--table 85E1:11) -- without it only 66 % of the image traced --
plus a Mesen Code Data Logger capture taken while a random-input bot
played the attract demo, which promoted 1,757 bytes from data to code.
- Pass 2 named all 1,989 labels: 730 read out of the code by hand, 1,221
internal branch targets derived mechanically. Zero Label_XXXX, zero raw
$XXXX call or branch operands, zero SubC residue.
- Pass 3 named the zero page, the $0500 ball structure and all 37 data
blocks. apply_symbols.py --report: 0 pending substitutions, 0
multi-alias residue. align_audit_comments.py: no column drift.
- cdl_check.py cross-checks the finished prg.s against the capture: 0
CDL-code bytes not covered by an instruction, 0 CDL-data bytes that
start one.
- 29 neutral ZpXX zero-page slots remain, each with its reason recorded
in locals.inc, as the promotion rules allow.
The promotion
- git mv "_wip/NROM/Volleyball (U)" "NROM/Volleyball (U)". Mapper 0, so
it lands in NROM/. The whole-ROM build was already in place, so there
was no build surgery; the project builds byte-identically at its new
home and the old folder is gone (git mv moves the untracked build
artifacts too, so no residue was left behind).
- Root README.md: new inventory row 39 and a per-project detail section,
plus the WIP-tier counts. The detail sections for Xevious (U) and
Zanac (U) were numbered one too high against the inventory rows and
are now aligned; a leftover editing note in the same place is gone.
- WIP.md: the Volleyball row leaves the inventory, and the tier is now
853 projects across 29 mapper folders (36 in _wip/NROM/), 852 of them
Pass 0 skeletons. Golf (JU) is the only project left in the tier with
a real disassembly.
- TODO.md and AGENTS.md: the same counts, and the promoted tier is now
40 projects (39 under NROM/).
Verified: make wip builds and verifies the whole tier (854 of 854 passed,
0 failures) and make builds the promoted tier (39 of 39 passed).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Rename NROM/Pyramid (U) to NROM/Pyramid (U) (Sachen)
The promoted inventory row had read "Pyramid (U) (Sachen)" since the
project was promoted on 2026-10-20, but the folder was named "Pyramid (U)" --
so the row pointed at a folder that did not exist. The folder now matches
the row, and the project's own README title, its ROM file name
("Pyramid (U) (Sachen).nes") and the parenthetical convention the rest of
the promoted tier already uses (Popeye (JU) (PRG 0/1), Raid on Bungeling
Bay (U) [a2], Pac-Man (Tengen) (U)).
What changed inside the project
- The Makefile's regen target passes --project "Pyramid (U) (Sachen)", so
the tracer writes the matching header line. prg.s and locals.inc were
updated to that header line and nothing else -- the disassembly is
byte-identical to before.
- make regen still reproduces prg.s and locals.inc byte for byte.
- The project's README's build-verification line now names the new folder.
References updated: the root README.md (inventory prose, the row-33 detail
section, the build-status table, and the notable-observations bullet),
TODO.md (the promoted-projects table and the Pyramid notes) and AGENTS.md
(the recently-promoted list and the unlicensed-titles quirk).
Verified: make builds the promoted tier (39 of 39 passed) and the project
rebuilds byte-identically at its new path.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Rebuild Mermaids of Atlantis (U): bank-aware Pass 1, Pass 2/3 names
The promoted project did not build: a Pass 2 rename had been applied
half-way, leaving eight undefined symbols and two jumps that pointed at
the wrong routine, while the root README already claimed the project was
byte identical. The _wip copy still built, because it held the un-renamed
Pass 1 source.
The disassembly is now derived from the ROM itself, with the Mesen Code
Data Logger as the oracle for the code/data split:
* _tools/banked_dis.py traces every MMC3 bank separately, each with the CPU
window it is visible at, seeded from a CDL capture so the code a static
trace cannot reach is disassembled too. The CDL is the authority: a
decode the CPU never fetched is dropped, and so is the fall-through
behind a call whose target never returns (the game's dispatchers have
their jump table right behind the call).
* One segment per bank (PRG0..PRG7) with its own .org, so the assembler
knows the CPU address of every label while the linker still writes the
bytes to the bank's file offset. A flat segment cannot do both: a call
would encode the file offset instead of the CPU address.
* Pass 2 names every label - 494 routines, no Label_XXXX and no raw
$XXXX branch or jump operand left. Pass 3 applies 13 semantic zero-page
aliases and writes the routine headers.
* 8,075 bytes of code (12.3% of the 64 KB PRG), up from 200 bytes.
The banking turned out to be unusual and is documented: the fixed bank is
the fourth 8 KB bank (file $6000-$7FFF), not the last one, and the image
carries the reset stub and the vector table twice. The live NMI vector
is $808F - the frame handler - while the copy at the end of the image
names $8189, which is a BRK in the first half. The game's text table
lives at CPU $F1D6, which is the fixed window, and that is what settles
the question.
Also: the leftover _wip/MAPPER8 folder is removed, as it is for every
other promotion.
The project builds byte identical:
Byte-identical ROM verified.
Add CHANGELOG.md: the pass history of every project
A project goes through four milestones - Pass 1 (the code/data split),
Pass 2 (the labels replaced by names), Pass 3 (the semantic naming) and
Promotion (the move into the top-level mapper folder) - and the history
of those milestones was scattered over the commit log, the project
READMEs and the root README.
CHANGELOG.md gathers it: one section per project with a row for each
milestone, the date, and a sentence saying what the milestone produced.
The numbers are the ones the project README and the root README already
carry - instruction count, code coverage, named labels, semantic
zero-page aliases, named data tables - so a reader can see at a glance
which projects are done and which are not. Golf (JU), the only project
still in _wip/ with a real disassembly, is listed with its open
milestones, and the other 852 _wip/ projects are covered as a tier.
The requirement is now part of the workflow contract: PROMPTS.md gains a
"Pass 3: Changelog entry" section and a ninth checklist item, and
AGENTS.md points at the file. A milestone and its changelog row go in
the same commit, so the changelog and the source never disagree.
Balloon Fight (JU): repair the audit trail and complete the routine headers
The per-instruction audit trail was stale by two bytes from
ResetInitializationData ($C085) onward. 5,944 of the 6,007 comments named
the wrong CPU address and PRG offset, because the three-byte .byte "HAL"
signature at $C082-$C084 had been counted as one byte when the trail was
first generated - the routine headers and the linker labels were right all
along, so the source and its own headers disagreed with each other. The
trail was rebuilt from the ca65 -l listing with
_tools/repair_audit_comments.py, and every rewritten comment was re-checked
against prg.bin. The comments were also moved into the canonical column-35
field: they had sat two spaces after the mnemonic, with no column discipline
at all, unlike every other promoted project.
All 63 routine headers now carry a ; Clobbers: block, so the headers carry
the full template AGENTS.md describes. The blocks are derived, not written by
hand. The new _tools/derive_clobbers.py takes the opcode from the audit
comment's byte list, so the addressing mode is exact and a data directive is
never mistaken for an instruction; it resolves the operand through
locals.inc and symbols.inc to name what is written; it follows the real
control flow, so a jsr to another named entry is a call (the callee's
clobbers count) while a branch or a fall-through is not; and it models
register preservation, so NmiHandler reports *no register* - it saves and
restores A, X and Y around the frame - and FlushPpuCommandPreserved reports
only A, because X and Y come back unchanged.
Two tools changed. derive_clobbers.py is new. align_audit_comments.py had
an off-by-one: it tested the indented code length against 31 instead of
against 35, so code texts of 28-31 characters were never padded into the
column.
The change is comments only. The code text of all 8,538 lines is unchanged,
make still prints "Byte-identical ROM verified.", the 6,007 audit comments
still re-check against prg.bin, all 63 routine headers agree with the
instructions they describe, and every label agrees with reconstructed.lbl.
ReflectObjectYVelocity and UpdateSpecialObjectSystem moved out of locals.inc
and became labels in prg.s at their real addresses.
CHANGELOG.md becomes the repository's running log: a Pending list of the
changes to be put in the next commit, a History of the commits already made,
and the per-project milestone index at the end. The next commit's message is
written from the Pending entries, so the two cannot drift apart. PROMPTS.md
and AGENTS.md describe the new shape. WIP.md drops the _wip/MAPPER8/ note:
the folder held a copy of Mermaids of Atlantis (U) that had already been
promoted.
World Class Track Meet (U): Pass 1, the code/data split
Pass 1 is done. The split is 8,400 instructions / 18,028 code bytes (55.0 %)
of the 32 KB PRG, with 884 routine entries, 55 data blocks and 102 zero-page
aliases. The PRG is CNROM (mapper 3) and maps whole at $8000-$FFFF, so the
linker moved the PRG segment from a .nes file offset to $8000 and the build
still compares byte identical.
Four dispatch tables had to be seeded by hand. The event table at $F796 (5
entries) is read at $F780 and jumped to through `jmp ($001F)`. The three
push-pointer tables - $BFC4 (16 entries), $BFE4 (2) and $E5F2 (7) - push a
handler address and `rts` into it, and the 6502's `rts` adds one to the
address it pops, so each table stores the entry address minus one; the seeds
are the table values plus one. The tracer runs with --undocumented: the code
uses undocumented NMOS opcodes as ordinary code (ANC $37 at $BFF8, and the
RRA/RLA/SLO and NOP forms elsewhere). Seeding the tables takes the coverage
from 27.8 % to 55.0 %.
$C0BE-$C0C5 is forced back to data: the IRQ vector $C0C0 points into the
middle of the `jmp $C047` at $C0BE, and the game never executes CLI, so the
vector is dead. `make pass1` regenerates prg.s and locals.inc from prg.bin
and reproduces the committed prg.s byte for byte.
The project README records the split, the four dispatch tables, the dead IRQ
vector, the wrong CHR size field in the header, and what is still data. The
milestone index in CHANGELOG.md gains the project; WIP.md, README.md and
AGENTS.md follow the tier counts and the layout.
nesdis.py gains a --mapping-note option, so the header's "PRG mapped at" line
can describe a board that is not NROM - CNROM's whole 32 KB at $8000-$FFFF is
not "mirrored to the upper half".
Replaces runs of $00 and $FF with .res <run>, <byte>
Golf (JU) and World Class Track Meet (U): Pass 2/3 complete, promoted from _wip/
- World Class Track Meet (U) - Pass 2 complete: all 884 Label_<addr>
definitions replaced (651 semantic routine names + 233 Sub_<addr>), all 731
raw $XXXX jsr/jmp call operands resolved to symbolic labels, all branch
targets given role-based names; routinemap.tsv added; make stays
byte-identical.
- World Class Track Meet (U) - Pass 3 complete: 24 semantic zero-page
aliases applied via apply_symbols.py (0 residue), 78 neutral ZpXX slots
documented with reasons in locals.inc, all hardware-register operands use
symbols.inc names, project README rewritten with Pass 2/Pass 3 sections and
data-table inventory; promoted out of _wip/CNROM/.
- World Class Track Meet (U) - project README documents the five event-table
entries at $F796 and marks the olympics mode as not yet proven.
- Golf (JU) - audit comments converted from pre-canonical (; C000: A9 00)
to the canonical ; CPU:$C000 PRG:0000 A9 00 form at column 35; 4,156
comments re-aligned, comment/whitespace only, whole-ROM build stays
byte-identical.
- Golf (JU) - 339 internal branch-target Label_ labels given role-based names
via _tools/derive_branch_names.py; 0 raw $XXXX branch/jump operands remain.
- Golf (JU) - 275 zero-page operands substituted with locals.inc aliases via
apply_symbols.py; 0 residue; promoted out of _wip/NROM/.
- Xevious (U) - runs of $FF padding replaced with .res <count>, $FF in prg.s;
whole-ROM build stays byte-identical.
- Both projects promoted via git mv; leftover _wip/ folders removed; root
README.md inventory rows added; WIP.md rows removed.
World Class Track Meet (U): apply zero-page symbol substitutions
Run apply_symbols.py to substitute ZpXX zero-page operands with
semantic locals.inc aliases (SlotState, GameMode, etc.) at proven
sites; 0 residue, whole-ROM build stays byte-identical.
Xevious (U): re-split Pass 1 from the Mesen CDL and decode the data tables
- Xevious (U) - Pass 1 re-split from the Mesen CDL (xevious_mesen.cdl) with
_tools/cdl_reclass.py: 1,158 bytes data->code, 48 code->data, 42 labels
emitted and 3 branch targets labelled; code 11,321->12,455 bytes
(34.5%->38.0%), instructions 5,513->6,002. The 45 recovered entry points
are named Sub_XXXX, so no Label_XXXX remains; six CDL-silent raw call
operands are documented as residue.
- Xevious (U) - the 4,448-byte block at $A74B-$B8AA is split into six proven
tables: VramWritePtrTable (15 pointers), VramWriteData, DataStreamPtrTable
(16), ObjTilePtrTable (99), ObjTileData and DataStreamData. The $D833
pointer table is corrected to base $D833 (4 entries; the old ObjCodePtrTable
at $D834 was one byte late). $F957-$FAF5 is split into ObjSpeedTable,
ObjSpeedTable2, SpriteLayoutPtrTable (19) and SpriteLayoutData;
$FEE6-$FF1C into PaletteData and OamAttrTable. $F5D8 is decoded as
TextTileData (font tile indices: PLAYER, GAME OVER, READY, SOLVALOU, LEFT,
PAUSE); $F53C becomes AttrAddrTable, $F89E HandlerPtrTable and $EF3B
SpriteLayoutData2. Project README rewritten with the corrected stats, a
32-entry table inventory and the Pass 1 residue.
- _tools/cdl_reclass.py - preserve the data label(s) between a data-block
header and its first .byte row when the block stays data; the $DF78 split
dropped Data_DF78 and the rebuild failed with an undefined symbol.
- _tools/resolve_raw_branches.py - handle negative relative offsets
(beq *-$0B); the pattern only matched *+$NN and *$NN.
Docs: refresh the tier counts to 41 promoted / 851 _wip, add the WCTM row
- Docs - tier counts refreshed to the post-promotion state across AGENTS.md,
root README.md, WIP.md, TODO.md and CHANGELOG.md: 41 promoted projects
(38 under NROM/, plus CNROM/World Class Track Meet (U), UNROM/Zanac (U) and
MAPPER8/Mermaids of Atlantis (U)) and 851 _wip/ projects, every one of them
a Pass 0 skeleton. The stale "39/40 promoted", "853 _wip", "Golf (JU) is
still in _wip/" and "Golf is the last pre-canonical project" statements are
corrected.
- Root README.md - the promoted inventory gained the missing World Class Track
Meet (U) row (row 41, mapper 3, 32 KB PRG / 32 KB CHR), and the "All 38 are
mapper 0 / 16 KB PRG" sentence is replaced with the actual split (36 of the
41 rows are mapper 0 / 16 KB; Xevious and Volleyball are 32 KB, World Class
Track Meet is mapper 3, Zanac mapper 2 and Mermaids mapper 8).
Balloon Fight (JU) — Game Flow from Power-On
This document describes the execution flow of the disassembled Balloon Fight (JU) PRG bank (16 KB, mapped at CPU $C000–$FFFF), starting from power-on. It is based entirely on copilot/prg.s in the repository. The rebuild is verified byte-identical to the original prg.bin.
1. Reset Vector — CPU $FFFC → $C000
Reset ($C000–$C07E)
On power-on or reset, the 6502 jumps to $C000. The reset routine performs cold-start hardware initialization:
| Step | Code | Purpose |
|---|---|---|
| 1 | lda #$00 / sta PPUCTRL |
Disable NMI and PPU rendering |
| 2 | lda #$00 / sta PPUMASK |
Disable screen output |
| 3–6 | Poll $2002 twice |
Wait for two full VBlank periods (PPU warm-up) |
| 7 | sei / cld |
Disable interrupts, clear decimal mode |
| 8 | ldx #$FF / txs |
Initialize stack pointer |
| 9–13 | Clear Zero Page | Zero all of RAM $00–$FF |
| 14–21 | Warm-start signature check | Compare RAM $07FA–$07FC against "HAL" ($C082–$C084). If valid, skip full memory clear |
| 22–31 | Initialize memory | Clear zero page + stack page ($0700–$07FF via SortedRecordTable, x = 0), set SpawnPixelPosition = $32, run block-init loop (jsr InitializeOrQueueObject 50 times), jsr SortOrInitializeRecords |
| 32–44 | Copy initialization data | Copy 15 bytes from $C085 to $0629 (initial game state table) |
| 45–51 | Clear local variables | Zero the five-byte CurrentRecord at $03–$07 |
| 52–56 | Copy saved signature | Re-store "HAL" to $07FA–$07FC |
| 57 | jmp MainInitialization |
Transfer control to $F1D4 |
Warm-start signature: "HAL" stored at $C082; RAM copy at $07FA. This lets the game resume state after a soft reset without re-initializing everything.
2. Main Initialization
MainInitialization is at $F1D4 (forward-referenced in locals.inc). It sets up the first round, initializes object pools, and enters the main loop. Its body lives in the upper bank region (not fully shown in the decoded $C000–$C07E range).
3. Interrupt Vectors — CPU $FFFA–$FFFF
Located at the end of the bank (PRG offset $3FFA):
| Vector | Address | Handler |
|---|---|---|
| NMI | $C094 | NmiHandler |
| RESET | $C000 | Reset |
| IRQ | $C0F7 | IrqHandler (self-loop jmp IrqHandler — unused) |
4. NMI / Frame Heartbeat — NmiHandler ($C094)
The NMI fires once per frame and drives the frame pacing. It:
- Preserves registers (A, X, Y on stack)
- OAM DMA: writes
$00toOAMADDR, then$02toOAMDMA(DMA from $0200–$02FF) - PPU command buffer flush: compares read/write offsets at $52/$53; if data pending, calls
FlushPpuCommandPreserved($C17C) - Transfer sources:
jsr UpdatePpuTransferSources($D60D) - Build OAM:
jsr BuildFrameOam($D798) - Frame counter:
inc FrameCounter($19) - Scroll/rendering setup: sets the
PPUADDR/PPUSCROLLregisters, conditionally waits for VBlank if rendering disabled (pollingPPUSTATUS), writesPPUCTRL - Audio:
jsr UpdateAudioFrame($FFF7 bank call →Sound_F758) - Sets
NmiCompletedFlag($02 = $01) - Restores registers,
rti
The main game loop runs during VBlank and waits for this flag.
5. Main Game Loop — $C209
After initialization, control reaches the per-frame loop at $C209:
UpdateGameplayObjects ($E691) ; update all 20 gameplay-object slots
UpdateSpecialObjectSystem ($C6F9) ; every other frame (frame counter / 2)
[round spawner / HUD / spawning logic]
[object physics & collision]
[particle system]
[OAM sorting / sprite setup]
WaitForFrame ($F465) ; wait for NMI-completed flag
jmp back to $C209
Key flow details:
- Scroll handling ($C227): if
PpuScrollX($17) is non-zero, togglesPpuControlBasebit 0 (screen scroll page flip), decrements scroll X. - Carrier/rescue sequence ($C233): updates carrier position ($0488), target player, sound requests.
- Effect object pool (8 slots, $055D–$0584): updates timers, respawns offscreen.
- Gameplay object pool (20 slots, $0530–$055C): movement, position integration.
- Round spawner ($C790): on frame boundaries, counts down
RoundSpawnDelay, finds free slots, spawns round objects from tables ($C88F–$C8B5), plays spawn sound. - HUD updates ($C831): when spawn delay reaches 1, writes round HUD digits to PPU buffer.
- Sprite sorting:
SortOrInitializeRecords($C579) maintains a sorted table of up to 50 five-byte records ($0700–$07F9) for OAM priority.
6. Subsystems
6.1 PPU Command Buffer ($C12D–$C1C4)
A buffered PPU update system. Commands are staged at $0300 with format:
- Byte 0: PPU address high | $20
- Byte 1: PPU address low
- Byte 2: length (number of data bytes following)
Routines:
AppendBytesToPpuBuffer($C131) — appends raw bytesAppendLengthPrefixedPpuData($C139) — appends with length prefixBuildPpuCommand($C154, formerlySub_C154) — formats address+length commandFlushPpuCommandPreserved($C17C, formerlySub_C17C) — drains buffer to $2006/$2007, preserving X/Y- Special handling for palette writes ($3Fxx range)
6.2 Round Spawning ($C77A–$C88A)
ChooseRoundSpawnIndex($C77A): picks a random spawn index belowRoundSpawnRandomLimit, rejecting zeroUpdateRoundSpawner($C790): timer-driven spawning; initializes object position, velocity (from tables at $C89F–$C8B1), flip flags, aux state; incrementsSpawnSelector; requests spawn sound ($F0 bit $04)UpdateRoundHud/ConfigureRoundPresentation($C831–$C88A): writes round number / HUD tiles to PPU buffer
Spawn tables ($C88F–$C8B5): flip X/Y, X/Y offsets, parameter, velocity Y, position hi, velocity X — six entry types.
6.3 Gameplay Objects ($C8B7–$C9DC)
UpdateRoundObjectSpritesAndPhysics ($C8B7) updates slots 1 and 0:
- Builds 3-sprite OAM per object from tile tables ($C9DD–$CA33)
- Integrates fixed-point position ($C9B6)
- Bounds testing (
TestGameplayObjectAgainstBounds, $CA67) against rectangular regions - Velocity reflection on collision (
BounceGameplayObjectX/Y, $CA4F/$CA37) - Object removal when offscreen
6.4 Bonus Objects ($CB74–$CCCA)
UpdateBonusObjectSystem($CB74): per-frame phase/timer advance for the single active bonus slotTestBonusObjectPlayerOverlap($CBB2): rectangle overlap vs both players; applies horizontal/vertical impulses, collision soundTestBonusObjectCollection($CC3A): phase-3 collection; starts bonus timerTriggerBonusObjectEffect($CCBF): increments effect counter, callsApplyBonusEffect($E983)DrawBonusObjectHud($CCCB): 3-row HUD tile display from phase tables ($CD26–$D046)
6.5 Carrier / Rescue Sequence ($C5C3–$C715)
UpdateCarrierSequence($C6F9): advances carrier target X while idle; finds eligible player; starts sequenceFindEligiblePlayerForCarrier($C614): scans player slots 7→0, finds one at lower screen boundary ($B4+) matching carrier target XBeginCarrierTargetSequence($C6C4): captures player position/state, resets timerUpdateCarrierArrivalSequence($C658): moves carrier down, checks contact, transitions player to hit/rescue state, sound requestUpdateCarrierObjectDisplay($C5C3): builds 8-sprite carrier metasprite, updates target player position relative to carrier- Tables:
NormalDisplayModeTable($C5B7),AlternateDisplayModeTable($C5BB),CarrierAnimationSequenceTable($C6B8)
6.6 Particle System ($CD4A–$CEAD)
InitializeParticleSlots($CD4A): 10 slots, offscreen Y ($F0)SpawnTimedParticle($CD5A): random timer, finds free slot, assigns position/velocity fromParticleInitialVelocityTable($CEAE)UpdateParticleSystem($CDAA): integrates signed motion, applies scroll delta, retires offscreen particlesDrawParticleSprites($CE2F): 3-sprite OAM per particle with animation/attribute masking
6.7 Sound Driver ($FFF7 region, bank-switched)
UpdateAudioFramejumps toSound_F758in another bank- Sound sequence pointer table at $3BCA (32 entries)
- Encoded sequence data $3BCA–$3FF1 (note/duration bytes with $02/$FF/$8x control codes)
- APU channel init at $F7xx region (
InitializeApuChannelState,SilencePulseChannels) - Sound request flags: $F0 (flags 0), $F1 (flags 1), $F2 (flags 2), $F3 (flags 3)
7. Memory Map (Key Zero Page / RAM)
| Address | Name | Use |
|---|---|---|
| $00 | PpuControlShadow |
$2000 mirror |
| $01 | PpuMaskShadow |
$2001 mirror |
| $02 | NmiCompletedFlag |
VBlank sync flag |
| $12–$13 | RecordIndex / ReverseRecordIndex |
Sorted-record insertion (see reuse note below) |
| $14–$15 | SpawnParameter / SpawnPixelPosition |
Spawn args |
| $16 | RenderingDisabledFlag |
Rendering state |
| $17 | PpuScrollX |
Scroll X |
| $18 | PpuControlBase |
Base PPU control |
| $19 | FrameCounter |
Frame tick |
| $1B | RandomState |
PRNG state |
| $1D–$1E | RecordPtrLo/Hi |
Record table pointer |
| $23–$24 | SpawnCommandPointerLo/Hi |
Command stream pointer |
| $25–$26 | DispatchPointerLo/Hi |
Spawn dispatch indirect jump |
| $52–$53 | Ppu buffer read/write offsets | Command buffer |
| $54–$56 | Ppu command address/length | Pending PPU command |
| $7F | PlayerLifecycleState |
Per-player lifecycle |
| $88 | PlayerSlotState |
Per-player active state |
| $91 | PlayerPosX / Player0PosX |
Player X |
| $99 | CarrierTargetX |
Carrier target |
| $9A | PlayerPosY / Player0PosY |
Player Y |
| $A2 | CarrierPosY |
Carrier Y |
| $BD | PlayerCollisionDisable |
Collision immunity |
| $F0–$F3 | Sound request flags 0–3 | Audio requests |
| $0300–$03FF | PPU command buffer | Staged PPU updates |
| $0489–$048D | Carrier sequence state | Active, mode, target, drop, timer |
| $0490–$0530 | Gameplay object pool (20 slots) | State, pos, velocity |
| $055D–$0584 | Effect object pool (8 slots) | State, pos |
| $0558–$05CE | Particle / sequence state | 10-slot particle pool |
| $05D1–$060E | Bonus object state | Timer, phase, pos, HUD |
| $0700–$07F9 | Sorted record table | 50 × 5-byte OAM sort records |
| $07FA–$07FC | Warm-start signature | "HAL" |
Alias reuse. Several zero-page addresses serve more than one subsystem, so locals.inc
defines several names per address; prg.s uses whichever fits the routine reading it:
| Address | Names used in prg.s |
|---|---|
| $12 | RecordIndex (sort), Temp12 (generic scratch), CollisionDeltaX, MotionDeltaLo |
| $13 | ReverseRecordIndex (sort), CollisionDeltaY, MotionDeltaHi |
| $23–$26 | SpawnCommandPointerLo/Hi + DispatchPointerLo/Hi, BoundsLeftPtrLo/Hi + BoundsRightPtrLo/Hi (stage-collision bounds) |
| $27–$2A | BoundsTopPtrLo/Hi + BoundsBottomPtrLo/Hi (stage-collision bounds) |
| $3E | SequencePlayerIndex (bonus accumulation) / CurrentObjectIndex (object loops) |
| $57–$5A | PpuCommandData0/1/2 (PPU command buffer) / HudCommandTile0; RoundHudCommandAddressHi/Lo + RoundHudCommandLength + RoundHudTile in DrawRoundStatusPanel |
| $55D/$567/$57B | EffectObjectState / EffectObjectPosX / EffectObjectPosY (spawn effects) vs ParticleState / ParticlePosX / ParticlePosY (particles) |
8. Object Pools
| Pool | Slots | State array | Purpose |
|---|---|---|---|
| Gameplay objects | 20 ($00–$13) | $0530 | Round enemies/objects, movement & physics |
| Effect objects | 8 ($00–$07) | $055D | Short-lived spawn effects |
| Particles | 10 ($00–$09) | $055D | Visual particles (shared state array, different offset interpretation) |
Slot state convention: negative ($FF) = inactive/free, zero or positive = active.
9. Summary of Execution Flow
Power On / Reset
│
▼
Reset ($C000) ────► hardware init, clear RAM, validate "HAL" signature
│
▼
jmp MainInitialization ($F1D4)
│
▼
[first-round setup, object pool init]
│
▼
Main Loop ($C209) ──────────────────────────────────────────────┐
│ │
├─ UpdateGameplayObjects ($E691) │
├─ UpdateSpecialObjectSystem ($C6F9) [alt frames] │
├─ Carrier sequence ($C6F9 family) │
├─ Round spawner ($C790) + HUD ($C831) │
├─ Object physics & collision ($C8B7, $CA67) │
├─ Bonus object system ($CB74) │
├─ Particle system ($CDAA) │
├─ OAM sort ($C579) │
├─ WaitForFrame ($F465) ◄──────── waits for NMI flag ──────┘
│
▼ (loop back to $C209)
NMI ($C094) [once per frame]
├─ OAM DMA ($4014)
├─ Flush PPU command buffer ($C17C)
├─ Update transfer sources ($D60D)
├─ Build frame OAM ($D798)
├─ Frame counter++, scroll setup
├─ UpdateAudioFrame ($FFF7 → Sound_F758)
└─ Set NmiCompletedFlag, rti
10. Naming and Residue
Pass 2 (2026-10-19) replaced every address-derived definition with a semantic name —
Sub_Cxxx for the routines that had no behavioural name yet, <Routine>_Block[_n] for
internal branch targets — so prg.s now contains zero Label_ definitions. The 77
Sound_Fxxx entry points keep their addresses as names in the banked audio region.
Pass 3 applies the two symbol tables to the instruction stream:
symbols.inc— the NES hardware constants (PPUCTRL…APUFRAMECNT). All 125 numeric register operands are now symbolic.locals.inc— zero-page/RAM names plus forward-reference aliases for routine addresses (AbsoluteDifference= $F08E,MainInitialization= $F1D4, …). All but 16 numeric operands are now symbolic.
Placeholder names renamed during the same work:
Sub_C154→BuildPpuCommandSub_C17C→FlushPpuCommandPreservedSub_C40C→SpawnRandomObjectSpawnCommandStreamData_C4AD→RoundSpawnCommandStream(format documented)
Residue. $13 carries three aliases (ReverseRecordIndex, CollisionDeltaY,
MotionDeltaHi), none of which fits the 16 sites where it is used as an ordinary
high-byte scratch beside Temp12 — in LoadStageObjectData, ReadPpuStreamByte,
CreateBonusResultSprites, RenderObjectSprites_Load, ResolveObjectCollisionPair
and SwapObjectIndexes. Those operands are deliberately left numeric rather than given
a speculative name; a neutral $13 companion to Temp12 would close them.
Build verification: make in copilot/ produces reconstructed.nes, compared whole-ROM
against rom.nes (byte-identical).
11. Audit Trail (comment format)
Every instruction and data line in prg.s carries the canonical repo audit comment —
; CPU:$XXXX PRG:XXXX AA BB — giving the CPU address, the PRG offset and the exact
emitted bytes. That comment is the byte-identity trail, so its contents and its
column both matter.
What was wrong (fixed 2026-10-21).
- The addresses were stale by two bytes. The comment trail had been generated when
the warm-start signature was still a single byte, so from
ResetInitializationData($C085) onward every comment claimed a CPU address and PRG offset two bytes below the truth —NmiHandlerread$C092instead of$C094,AllocateEffectObjectread$C469instead of$C46B, and so on. The.byte "HAL"string at $C082–$C084 is three bytes, not one. 5,944 of the 6,007 comments were affected; the routine headers (; PRG offsets:/; CPU range:) and the linker labels were right all along, so the two disagreed with each other. - The comments were not in the canonical column. They sat two spaces after the
mnemonic instead of in the column-35 field that
nesdis.pyemits (f" {text:<31}; CPU:…"), so the file had no column discipline at all.
What was done. _tools/repair_audit_comments.py rebuilt the trail from the ca65 -l
listing (the linker is ground truth for each source line's offset and byte span) and
validated every rewritten comment against prg.bin; _tools/align_audit_comments.py
then restored the column. Both steps are whitespace-and-comment only — the code text of
all 8,544 lines is unchanged, so the rebuild stays byte-identical.
A bug in _tools/align_audit_comments.py was fixed at the same time: it tested the
indented code length against 31 rather than against 35, so code texts of 28–31
characters (83 + 36 + 51 lines here) were never padded into the column.
Verification.
make→Byte-identical ROM verified.- All 6,007 audit comments re-checked against
prg.bin: every byte list matches the ROM at the offset it names, and everyCPUfield equals$C000 + PRG. - All 63 routine headers re-checked against the instruction comments they describe:
every
; PRG offsets:range and; PRG offset:entry point agrees. - Every label in the source agrees with the linker label file (
reconstructed.lbl). python3 _tools/verify_pass1.py "Balloon Fight (JU)"→canonical, verdictOK.
12. Routine Headers — the Clobbers: Section
The header template AGENTS.md describes is global + local description, parameters,
returns, clobbers. The first four were already here; the fifth was missing from 61 of
the 63 routine headers (only AllocateEffectObject and AllocateGameplayObject had
one, and both were incomplete). All 63 now carry a ; Clobbers: block, so every header
in the file is complete.
Nothing was guessed. _tools/derive_clobbers.py derives the block from the source:
- the opcode comes from the audit comment's byte list, so the addressing mode is
exact (
sta $0400,xis ABSX,sta Zp00is ZP) and a data directive is never mistaken for an instruction; - the operand is resolved through
locals.inc,symbols.incand the labels inprg.s, so a clobber can be named — and where several names share one address (Temp12andRecordIndexare both $12) the first name inlocals.incis used; - the control flow comes from the instructions. A unit is a named entry point in
the source; the code a unit reaches — the shared tails it branches into, the block it
falls through into — is its own, while a
jsr/jmpto another unit is a call, so the callee's clobbers count but its code is not merged in; - register preservation is modelled: a small abstract interpreter carries the value
of A, X, Y and of each processor flag through the unit, so a routine that saves a
register on the stack and puts it back is not reported as clobbering it. That is why
FlushPpuCommandPreservedreports only A, and whyNmiHandler— which saves and restores A, X and Y around the frame — reports no register at all; - a call into code the project has not decoded (a forward reference in
locals.incthat lands in the undecoded upper bank) can damage anything, so it is reported as a clobber of every register and every flag.
The flags are named individually — the N, Z, C and V flags — because that is what the
instructions actually set.
Results worth noting.
| Routine | Clobbers | Why |
|---|---|---|
NmiHandler |
no register, the N, Z, C and V flags | saves and restores A, X and Y around the frame |
FlushPpuCommandPreserved |
A, the N, Z and C flags | the name is the contract: X and Y come back unchanged |
IrqHandler |
nothing | a one-instruction self-loop |
TriggerBonusObjectEffect |
A, the N, Z, C and V flags | moves Y into X and puts the old X back into X; A is left holding the old X |
AllocateEffectObject |
A and X, the N and Z flags | the hand-written "A and X." was right about the registers and silent about the rest |
Verification. Comment-only change: the code text of all 8,538 lines is unchanged,
make still prints Byte-identical ROM verified., the 6,007 audit comments still
re-check against prg.bin, and the tool is idempotent — running it twice leaves the
file byte-identical.