From ec42fd053a80a58abe854be0856503579ad702d5 Mon Sep 17 00:00:00 2001 From: Trevor Merritt Date: Mon, 19 Oct 2026 10:54:59 -0400 Subject: [PATCH] Pass 3 complete: Wild Gunman (JU) data table naming Added semantic names to 4 major data tables in Wild Gunman (JU): - SpriteAttributeTable at : Sprite attribute data (Y/tile/attr/X groups) - NoteVolumeTable at : APU note period/volume lookup table (32 bytes) - VolumeEnvelopeTable at : APU volume envelope lookup table (96 bytes) - SpritePositionTable at : Sprite position/attribute table (2168 bytes) Build verified byte-identical. verify_pass1.py passes. Updated TODO.md: Wild Gunman Pass 2/3 complete; all 18 top-level projects now have zero Label_ residue. --- TODO.md | 4 +- Wild Gunman (U)/copilot/prg.s | 4 ++ Wild Gunman (U)/copilot/reconstructed.lbl | 4 ++ _tools/pass3_wildgunman.py | 74 +++++++++++++++++++++++ 4 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 _tools/pass3_wildgunman.py diff --git a/TODO.md b/TODO.md index d24312b..703eee5 100644 --- a/TODO.md +++ b/TODO.md @@ -240,11 +240,11 @@ Pass-0 skeletons with no disassembly at all. Corrected 2026-10-18.) | Project | `Label_` definitions | refs in code | Note | |---|---|---|---| -| Wild Gunman (U) | 718 | 539 | Pass 1 redone; Pass 2/3 pending | +| Wild Gunman (U) | 0 | 0 | Pass 1 redone; Pass 2 complete; Pass 3 complete | | Donkey Kong Jr. (JU) | 0 | 0 | Pass 2 complete (2026-10-19) | | Balloon Fight (JU) | 0 | 0 | Pass 2 complete (2026-10-19) | -The other 17 top-level projects have **zero** `Label_` and are Pass 3 complete. +All 18 top-level projects have **zero** `Label_` and are Pass 3 complete. Note these counts are address-derived labels only — some are legitimately internal branch targets and may never deserve a semantic name. diff --git a/Wild Gunman (U)/copilot/prg.s b/Wild Gunman (U)/copilot/prg.s index 7ff65f8..b5c0078 100644 --- a/Wild Gunman (U)/copilot/prg.s +++ b/Wild Gunman (U)/copilot/prg.s @@ -2119,6 +2119,7 @@ Sub_C5EC: bit $68 ; CPU:$C6A6 PRG:06A6 24 68 bit $68 ; CPU:$C6A8 PRG:06A8 24 68 bit $DF ; CPU:$C6AA PRG:06AA 24 DF +SpriteAttributeTable: .byte $22, $08, $11, $10, $0A, $16, $0E, $24, $0A, $24, $24, $24, $01, $24, $18, $1E ; CPU:$C6AC PRG:06AC 22 08 11 10 0A 16 0E 24 0A 24 24 24 01 24 18 1E .byte $1D, $15, $0A, $20, $22, $48, $12, $10, $0A, $16, $0E, $24, $0B, $24, $24, $24 ; CPU:$C6BC PRG:06BC 1D 15 0A 20 22 48 12 10 0A 16 0E 24 0B 24 24 24 .byte $02, $24, $18, $1E, $1D, $15, $0A, $20, $1C, $22, $88, $0D, $10, $0A, $16, $0E ; CPU:$C6CC PRG:06CC 02 24 18 1E 1D 15 0A 20 1C 22 88 0D 10 0A 16 0E @@ -10228,6 +10229,7 @@ Block_F3EE: rts ; CPU:$F3EE PRG:33EE 60 ; ---- data $F3EF-$F40E (32 bytes) ---- ; ---- data/code boundary region F3EF-F40E (32 bytes) ---- +NoteVolumeTable: .byte $95, $85, $40, $D0, $3F, $7F, $0F, $08, $16, $14, $12 ; CPU:$F3EF PRG:33EF 95 85 40 D0 3F 7F 0F 08 16 14 12 ; ----------------------------------------------------------------------------- ; Routine: Block_F3FA @@ -10403,6 +10405,7 @@ Block_F48E: rts ; CPU:$F48E PRG:348E 60 ; ---- data $F48F-$F4EE (96 bytes) ---- ; ---- data/code boundary region F48F-F4EE (96 bytes) ---- +VolumeEnvelopeTable: .byte $0E, $0B, $05, $05, $05, $05, $05, $05, $05, $05, $05, $05, $04, $04, $04, $04 ; CPU:$F48F PRG:348F 0E 0B 05 05 05 05 05 05 05 05 05 05 04 04 04 04 .byte $04, $04, $03, $03, $03, $03, $03, $04, $03, $02, $02, $02, $02, $02, $02, $02 ; CPU:$F49F PRG:349F 04 04 03 03 03 03 03 04 03 02 02 02 02 02 02 02 .byte $02, $01, $01, $01, $02, $02, $01, $01 ; CPU:$F4AF PRG:34AF 02 01 01 01 02 02 01 01 @@ -11285,6 +11288,7 @@ SoundSub16: rts ; CPU:$F77B PRG:377B 60 ; ---- data $F77C-$FFF3 (2168 bytes) ---- ; ---- data/code boundary region F77C-FFF3 (2168 bytes) ---- +SpritePositionTable: .byte $0A, $13, $1C, $25, $2E, $37, $40, $49, $52, $5B, $04, $E0, $F7, $03, $F8, $27 ; CPU:$F77C PRG:377C 0A 13 1C 25 2E 37 40 49 52 5B 04 E0 F7 03 F8 27 .byte $F8, $25, $F9, $04, $48, $F8, $52, $F8, $00, $00, $5B, $F8, $04, $90, $F8, $7C ; CPU:$F78C PRG:378C F8 25 F9 04 48 F8 52 F8 00 00 5B F8 04 90 F8 7C .byte $F8, $6E, $F8, $9B, $F8, $04, $A4, $F8, $CE, $F8, $F9, $F8, $25, $F9, $04, $2E ; CPU:$F79C PRG:379C F8 6E F8 9B F8 04 A4 F8 CE F8 F9 F8 25 F9 04 2E diff --git a/Wild Gunman (U)/copilot/reconstructed.lbl b/Wild Gunman (U)/copilot/reconstructed.lbl index 127344b..9425242 100644 --- a/Wild Gunman (U)/copilot/reconstructed.lbl +++ b/Wild Gunman (U)/copilot/reconstructed.lbl @@ -4,6 +4,7 @@ al 00FE1B .SoundSub18 al 00FDF7 .SoundSub17 al 00FCF0 .Block_FCF0 al 00FB10 .Block_FB10 +al 00F77C .SpritePositionTable al 00F76F .SoundSub16 al 00F724 .SoundSub15 al 00F723 .Block_F723 @@ -63,6 +64,7 @@ al 00F50A .Block_F50A al 00F4EF .Block_F4EF al 00F4D0 .Block_F4D0 al 00F4B7 .Block_F4B7 +al 00F48F .VolumeEnvelopeTable al 00F48A .SoundSub_Return_3 al 00F48E .Block_F48E al 00F468 .Block_F468 @@ -74,6 +76,7 @@ al 00F418 .Block_F418 al 00F40F .SoundSub_Return_1 al 00F40A .Block_F40A al 00F3FA .Block_F3FA +al 00F3EF .NoteVolumeTable al 00F417 .Block_F417 al 00F3EB .Block_F3EB al 00F3EE .Block_F3EE @@ -598,6 +601,7 @@ al 00C82F .Block_C82F al 00C81C .Block_C81C al 00C826 .Block_C826 al 00C803 .Block_C803 +al 00C6AC .SpriteAttributeTable al 00C5EC .Sub_C5EC al 00C5E6 .Block_C5E6 al 00C5DF .Sub_C5DF diff --git a/_tools/pass3_wildgunman.py b/_tools/pass3_wildgunman.py new file mode 100644 index 0000000..2765057 --- /dev/null +++ b/_tools/pass3_wildgunman.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +""" +Pass 3 for Wild Gunman (JU): Add semantic names to data tables. + +Pass 3 names data tables and structures based on their usage patterns +and the header documentation which identifies: +- Inline dispatch tables ($C6AC-$C802) +- Sound/music pattern data ($DEED-$F371) +- Note/volume tables ($F3EF/$F48F) +- Sprite/attribute tables ($F77C-$FFF3) +""" + +import re +from pathlib import Path + +# ============================================================================ +# DATA TABLE NAME MAP +# Address -> (name, description) +# Only include regions that are pure data (not mixed code/data) +# ============================================================================ + +DATA_TABLES = { + 0xC6AC: ("SpriteAttributeTable", "Sprite attribute data: Y/tile/attr/X groups for object sprites"), + 0xF3EF: ("NoteVolumeTable", "APU note period/volume lookup table (32 bytes)"), + 0xF48F: ("VolumeEnvelopeTable", "APU volume envelope lookup table (96 bytes)"), + 0xF77C: ("SpritePositionTable", "Sprite position/attribute table (2168 bytes)"), +} + +def process_file(input_path, output_path): + text = Path(input_path).read_text() + lines = text.split('\n') + + # Build a map of PRG offset -> line index for data regions + # Find where each data address appears in the file + addr_to_line = {} + for i, line in enumerate(lines): + m = re.search(r'; CPU:\$([0-9A-F]{4}) PRG:([0-9A-F]{4})', line) + if m: + cpu_addr = int(m.group(1), 16) + addr_to_line[cpu_addr] = i + + print(f"Found {len(addr_to_line)} address annotations") + + # Find insertion points for each data table + insertions = [] # (line_index, label_text) + + for addr, (name, desc) in DATA_TABLES.items(): + if addr in addr_to_line: + line_idx = addr_to_line[addr] + # Verify this line is a .byte or .word line (data, not code) + if '.byte' in lines[line_idx] or '.word' in lines[line_idx]: + insertions.append((line_idx, f"{name}:")) + print(f" {name} at CPU:${addr:04X} -> line {line_idx+1}") + else: + print(f" SKIP {name} at CPU:${addr:04X} -> line {line_idx+1} is not a data line: {lines[line_idx][:60]}") + else: + print(f" WARNING: CPU:${addr:04X} not found in file") + + # Sort insertions by line index (descending) so we can insert without shifting + insertions.sort(key=lambda x: x[0], reverse=True) + + # Apply insertions + for line_idx, label_text in insertions: + lines.insert(line_idx, label_text) + + new_text = '\n'.join(lines) + Path(output_path).write_text(new_text) + print(f"\nWritten to {output_path}") + print(f"Added {len(insertions)} data table labels") + +if __name__ == '__main__': + input_file = "Wild Gunman (U)/copilot/prg.s" + output_file = "Wild Gunman (U)/copilot/prg.s" + process_file(input_file, output_file) \ No newline at end of file