Findings — IronFrame OuterFortress (Cart) 01 Decomp (NES-ME-USA)
Verification Ledger:
0Static Decompiler Failures (499/499indexed) ·26/26Zero-TellD4_CleanSourceModules (507Symbols,0Warnings under-Wall -Wextra -Wno-unused-parameter) ·8/8PRG Banks1:16502 Assembly Match (131,088B,CRC32=25BA3D04) ·10/10D4aAssertions ·650/650D4bLockstep Frames (mismatchedFrames: 0vs. Mesen 2.1.1 +reCartWitness +8/8Linked C Checkpoints) ·unresolvedFieldCount: 0Across4Decoders &4Spokes
This document records empirical reverse-engineering discoveries, UNROM bus-conflict mechanics, BANK_06 sound-sequencer recovery, D3_Mapped cohesive coalescing, D4_CleanSource AST C11 normalization (craftsmanship_d4_*), D4b hardware timing lockstep (NesBus), Bank 1..4 / BANK_06 decoder coverage, upstream validator alignment notes, and 1:1 6502 byte-matching results.
1. UNROM Bus-Conflict LUT ($C959 / $FFD0) & Trampolines
- Hardware Constraint: Discrete
iNES Mapper 2(UNROM) cartridges lack bus-conflict suppression circuitry (74HC161latch +74HC32OR gate). Writing a bank index to$8000-$FFFFcorrupts the latch unless the PRG ROM byte at that exact write address equals the written bank number. - NES-ME-USA Implementation: Fixed bank
PRG_FIXED_07places an8-byte identity lookup table{0, 1, 2, 3, 4, 5, 6, 7}at$FFD0-$FFD7(verified againstPRG_FIXED_07at offset0x7FD0 + i == ibytest_01_vectors_and_unromin parity_rom_and_mapper_tests.c), paired with the$C932..$C958trampolines and$C959adjacent switch table/helper: - Fixed per-bank stubs at
$C932..$C94A(unrom_select_bank_0..6,4-byte stride). - Indexed trampoline
$C94C(unrom_select_bank_y/unrom_select_bank_index), emitting at$C94F:85 27 B9 D0 FF 99 D0 FF 60(STA $27; LDA $FFD0,Y; STA $FFD0,Y; RTS). Note: static analysis overPRG_FIXED_07withBANK_00mounted at$8000constant-foldedLDA $8000($C94C) to0in early generated C;test_03_unrom_bank_switchin parity_rom_and_mapper_tests.c checks exact$C94C/$C958opcode sequences and liveunrom_select_bank_0/6transitions (v0.2.0synthesized3cross-bank trampolines +5signature adapters,v0.3.0normalizedD4_CleanSourcetoD4asubsystem parity, andv0.4.0extended this to650-frameD4bRAM-oracle lockstep — see Section 5). - Restore stub
$C958(unrom_restore_active_bank), reloading the bank shadowed in Zero Page$27. - Inline Jump-Table Control Flow (
$C6B7): inline_jump_table_dispatch(16+call sites) reads an inline.word[]target immediately followingJSR $C6B7off the 6502 hardware stack ($0100+S), scales accumulatorA * 2, and executesjmp ($0080)($C6D2: 6C 80 00).- Marking
$C6B7asNoReturnduring static analysis stops the disassembler from decoding trailing inline data tables as 6502 instructions and preserves clean switch semantics acrossBANK_00..06andPRG_FIXED_07.
2. Recovery of 4 BANK_06 Audio Sequencer Routines
Initial automated decompilation left 4 failed functions concentrated in BANK_06 audio sequencer recursion ($94ED <-> $96E4 is the sole nontrivial SCC in call_graph.json). Structural control-flow recovery of these 4 routines resolved all export failures (4 -> 0, 499 / 499 active functions):
| Address | Function Name | Role in BANK_06 Audio Driver |
|---|---|---|
$9382 |
mg_b56_audio_update_channel |
Per-frame channel envelope, pitch, and timer advance |
$94EA |
mg_b56_audio_dispatch_seq_mode |
Dispatches channel playback state into sequence parser |
$94ED |
mg_b56_audio_parse_seq_event |
Decodes note/rest/control stream events (mutually recursive with $96E4) |
$96E4 |
mg_b56_audio_exec_control_opcode |
Executes loop, jump, transpose, and instrument control opcodes |
(Clean-room note: in v0.1.0, all embedded retail BANK_06 C bodies and READABLE_FIXES were purged from gen_d4_globals_and_lifts.py, leaving a clean-room 2,324-global mapper and Standard 18 v2 spec_coverage.json generator.)
3. Cohesive D3_Mapped & Zero-Tell D4_CleanSource Normalization (Corpus/readable/)
Early D2_Structured normalization resolved initial syntax blockers across the 68 line-split .c fragments without modifying read-only Corpus/standalone/ (synthesizing 44 missing forward declarations, fixing call-site arity in core_15.c and bank_02_06.c, normalizing indirect function-pointer casts across 11 .c files, label syntax in bank_05_02.c, and return emission in core_32.c).
In v0.2.0 (D3_Mapped), coalesce_d4_modules.py and materialize_decomp_tiers.py consolidated that intermediate baseline into 26 cohesive domain C modules (0 _01.._NN.c fragments, 0 remaining raw tokens across .c and headers) while preserving D1_Raw and D2_Structured snapshots:
- Full Raw Symbol & Call Resolution (
0Remaining Raw Tokens): Applied d3_symbol_overrides.json and globals_map.json to eliminate all299raw extern aliases and44rawFUN_*/func_0x*call references, including1local label rename (BYTE_ARRAY_8000_6486_ -> lbl_demo_input_loop) and20initial synthetic/bank-scoped overrides (2,342externs atD3, expanded inD4to22entries /20deduplicatedg_*declarations =2,344externs). - Bank-Scoped Table & Bitwise
&Precision: Disambiguated address collisions by explicitly mappingBYTE_ARRAY_bf00toBANK_03.prg(g_b03_rom_tbl_bf00) andFUN_b622toBANK_01.prg(g_b01_rom_tbl_b622), separating indexed(&DAT_0740)[i]writes (g_vram_transfer_queue[i]) from scalarDAT_0740reads (g_vram_transfer_queue[0]), and gating address-of&stripping so bitwise&expressions (g_frame_counter & g_b00_rom_tbl_b995[0]) remain intact. - Synthesized
8Bank/Signature Adapters &9Sub-Entry Prototypes: Emitted3cross-bank trampolines ($F5AC,$FBF5,$EE2A) and5signature-adapting wrappers ($99A8,$A765,$BB28,$B83A,$BBE1) declaratively intosrc/core/core_unrom_and_math.c, plus9subEntryDeclarationsprototypes inmetalgear_functions.h. - Zero-Tell
D4_CleanSourceAST Normalization (v0.3.0,0Tells &0Warnings): craftsmanship_d4_normalizer.py, craftsmanship_d4_ast_cleaner.py, and craftsmanship_d4_helpers.py eliminated all2,874baseline decompiler idioms fromD3_Mapped(craftsmanshipTellCount: 0across all34.c/.hfiles and507symbols =499catalog functions +8adapters,0SixTellDetectorfindings): - Removed dead
[ubcs]Stack0000variables (284-Wunused-but-set-variable), renamed and zero-initializedin_*/unaff_retaddr*,[ubcs]Var*,pbVar*, and SSA_00locals (199-Wuninitialized+29-Wsometimes-uninitialized), and renamedarg0sub-entry parameters (factor,table_index) plus header placeholder fields (mg_player.h,nes_hardware.h). - Unrolled all
69comma-operatorif (...)conditions while preserving short-circuit&&/||semantics, parenthesized55bitwise&inside|/^expressions (-Wbitwise-op-parentheses), loweredCONCAT11/CARRY1/subpiece byte accesses/(short)(&g_* + idx)ROM offsets/(&g_*)[idx]scalar-as-array reads (backed byg_actor_soa_ram[128]at$0300andg_apu_mmio_regs[24]at$4000), wrapped computed int-to-pointer expressions via(uintptr_t)(...), replacedwhile (true)/LAB_*/joined_r0x*/halt_baddata/Yoda comparisons, stripped Ghidra boilerplate (WARNING:,// Function:,@callers/@callees none), and injected* @symbol+ module headers. - Replaced legacy P-code macros in
include/ghidra_compat.hwith fixed-widths8..u64typedefs (#ifndef GHIDRA_COMPAT_FIXED_INTS), removed all.clangddiagnostic suppressions and pointer-cast suppressions (-Wno-int-to-pointer-cast), synced36files intoCorpus/readable/, and emitted5zero-body Standard 18 v2 shards in d4_rewrites/ (26files /507symbols). - Mapped Modular Host Parity Suite (
10/10Passing,D4aSubsystem Parity): Compiled26/26D4_CleanSourcemodules with0errors and0warnings under-std=gnu11 -fsigned-char -O1 -ffreestanding -fno-builtin -Wall -Wextra -Wno-unused-parameter(isZeroWarningsVerified: true,isZeroDecompilerTellsVerified: truein d4_build_report.json), linked against the four<= 200-line files underDev/scripts/d4_harness/— parity_harness.h, parity_runner_main.c, parity_rom_and_mapper_tests.c, and parity_gameplay_and_audio_tests.c. - Parity Scope Progression (
D4a->v0.4.0D4b):v0.3.0establishedD4a Subsystem Parity(10/10host assertions + freestanding zero-warning compilation). Inv0.4.0, d4_harness/, d4b_oracle_bridges.py, and run_d4b_lockstep.py advance the repository to verifiedD4b Execution Parity(mismatchedFrames: 0across650frames /5gameplay scenes, detailed in Section 5 below).
4. Clean-Room 6502 Byte-Exact Assembly (asm6502_d5.py)
asm6502_d5.py implements a standalone, zero-external-ROM clean-room MOS 6502 two-pass assembler (56 / 56 official mnemonics, 151 / 151 opcodes, 13 addressing modes, plus a: absolute-encoding override to prevent unwanted zero-page relaxation). Executed via build_and_verify_d5.py:
- Bank Images:
8 / 832,768-byte.prgimages (BANK_00..BANK_06,PRG_FIXED_07) match standalone SHA-256 digests (0byte mismatches; notePRG_FIXED_07.prgandBANK_00.prgshare SHA-25696d482df...because both pairBANK_00withPRG_FIXED_07). - Full Cartridge Image: Reassembled
131,088-byte ROM (NES 2.0 header +8 x 16 KiBPRG banks) achieves a1:1byte-exact retail match (CRC32=25ba3d04,MD5=0e514c68eb8d82342a71a74c6d52499b,SHA1=9f7448fddaedc1801e2970e50722ac3cfacd19b8,SHA256=79095355436222161cb3841ff9b5c7a572e77af11461935e433bd6e8dfd0f164) recorded in d5_byte_match.json.
5. D4b Multi-Scene Execution Parity & Hardware Timing Findings
In v0.4.0, clean-room C11 NesBus (nes_bus.c, nes_ppu_apu.c, nes_cpu_ops.c, nes_cpu_exec.c, d4b_lockstep_scenes.c) executed all 650 deterministic frames across 5 gameplay scenes against Mesen 2.1.1 (--testRunner Lua tracer) with mismatchedFrames: 0 recorded in d4b_lockstep_report.json (assertionsPassedCount: 7/7), while simultaneously running 8/8 live D4_CleanSource linked C checkpoints and cross-checking the read-only reCart.Core.dll InterpreterOracle differential witness:
Scene / Witness Check (d4b_lockstep_report.json) |
Frame Range | Verification Scope & Observed Result |
|---|---|---|
scene_1_boot_and_title |
1..100 |
Cold boot reset ($C001) through title idle (mismatched=0, digest e83cf9a209d62203) |
scene_2_intro_to_dock |
101..220 |
Start pulses (105..109, 140..144) through intro transition to dock (mismatched=0, digest 57e0058e7548977a) |
scene_3_dock_traversal |
221..380 |
Right (260..320) + Up (325..385) movement across dock (mismatched=0, digest 4a9f2a1a0e9004f0) |
scene_4_transceiver_and_pause |
381..520 |
Select (410..414, 460..464) + Start (485..489, 505..509) transceiver/pause (mismatched=0, digest 6807e97dee50d796) |
scene_5_combat_action |
521..650 |
Periodic Up + B bursts every 20 frames (mismatched=0, digest 5c13c20f66adbfa9) |
d4_clean_source_checkpoints |
1, 100, 110, 220, 320, 380, 490, 650 |
8/8 live D4_CleanSource C subsystem checkpoints (unrom_select_bank_0/6, mg_fxa_*, mg_b034_*, mg_b56_audio_*) |
recart_interpreter_oracle_witness |
1..650 |
Read-only reCart.Core.dll InterpreterOracle: frames=650, transitions=649, nonZeroFinalBytes=431, bootWramCrc32=f1e8ba9e (matching Mesen frame 1), finalWramCrc32=fbe7de47, sha=ce8f4c3a3562a378 |
Empirical RP2A03 / RP2C02 Lockstep Requirements
- NMI-Driven Main Loop & Zero Sprite-0 Usage: Static analysis across all
8PRG banks confirmed0Sprite-0 hit polling loops ($2002bit 6) and a pure NMI-driven main loop ($C069: JMP $C069+$C06CVBlank NMI). - Exact PPU Frame & Odd-Frame Timing (
nes_ppu_apu.c): Bit-exactPPU/WRAMparity over650frames required scanline241dot1VBlank NMI edge triggering, scanline261dot1status flag clearing, the odd-frame dot-339pre-render skip when(frame_count & 1) && (mask & 0x18), and capturing frame digests cleanly at scanline240(with resume-state checkpointing across instruction boundaries near dot312of scanline239). - RP2A03 CPU & DMA Quirks (
nes_cpu_ops.c,nes_cpu_exec.c,nes_bus.c): Matching Mesen 2.1.1 required RP2A03 binary-onlyADC/SBC(ignoringPdecimal flagD),JMP ($xxFF)page-boundary low-byte wrap,$4014OAM DMA513 + (cycles & 1)cycle stalls, and DMC DMA 3–4 cycle stalls ($4016double-clocking when a DMC fetch coincides with controller read). $0100-$01FFHardware Stack Masking: Zero-masking the 6502 hardware stack page ($0100-$01FF) isolates deterministic gameplay WRAM/OAM/PPU/APU equivalence cleanly across C11NesBus, Mesen 2.1.1, andreCart.Core.dllwithout raw memory dumps in tracked JSON reports.
6. Bank 1..4 / BANK_06 Decoder Coverage & Upstream Validator Note
- Complete Clean-Room Decoder Coverage (
unresolvedFieldCount: 0): Executing decode_all_bank_tables.py (--write-spec-coverage) resolves256rooms (165unique8x6grids),6metatile/attribute tilesets,18door returns,8elevators,17special warps,256adjacency vectors (235unique),51CHR upload headers,256$FD00/$FE00room metadata records,123patrol pointers (96unique),160dialog pointer offsets (144unique, byte span metadata only with0retail strings),217room actor spawns (85unique),7weapon/projectile tables,4password layout tables,7codec frequencies,255room call tables (75unique,116entries,72unique message IDs),5volume envelopes,12chromatic note periods,132audio descriptors (64SFX /68BGM), anddmc[0]($FC80) strictly into gitignoredCorpus/work/decoded_tables/while validating4/4specification spokes in spec_coverage.json. - Non-Blocking Upstream
reCartOneSchema Alignment Finding (ValidateD5ByteMatchFile): - Observation: Read-only
reCart.Decomp.D4BuildReportValidator.ValidateD4BuildReportFile,ValidateResearchManifestFile,reCart.Decomp.SixTellDetector.ScanDirectory(34Corpus/readable+34D4_CleanSourcefiles,Findings=0), andreEngine.Core.Decomp.DecompD4StrictnessValidator(ValidateWorkspace&ValidateDecompArchiveCleanRoom) all pass (IsValid=True), whereasreCart.Decomp.D4BuildReportValidator.ValidateD5ByteMatchFilereportsIsValid=False(9schema-key violations: expecting legacy'matchedBinaries'and'relpath'on entries#1..#8). - Root Cause:
reCartOne(D4ReportSchemaHelpers.ValidateD5Core) still looks only for deprecated Standard 18 v1 field names (matchedBinaries,relpath/name/path,bytes,sha256), whereasValidateD4BuildReportFileandValidateResearchManifestFilein the same assembly already accept Standard 18 v2 aliases. - Disposition:
Non-Blockingforv0.4.0. d5_byte_match.json conforms to Standard 18 v2 (matchedBinaryCount,relativePath,fileSizeBytes,sha256Hex) and is independently verified acrossbuild_and_verify_d5.py,verify_track_d5.py,decomp_cli.py, andunittest(8/8banks,mismatchedBytes: 0,CRC32=25ba3d04); follow-up inreCartOnewill add Standard 18 v2 aliases alongside legacy v1 fallbacks inValidateD5Core.
7. Related Manuals & Evidence Anchors
- ARCHITECTURE.md — UNROM bank topology,
$C6B7dispatcher,26cohesiveD4_CleanSourcemodules (36files inCorpus/readable/),NesBusC11 lockstep runtime, and bank decoders. - SPECIFICATIONS.md —
22structs,22enums,2,324globals (2,344externs), all4Dev/docs/specifications/ format spokes, and Standard 18 v2 verification JSON contracts (d4b_lockstep_report.json,spec_coverage.json). - OPERATIONS.md — Clean-room BYO-ROM layout, CLI overrides, tier materialization (
D1_Raw–D4_CleanSource),D4blockstep & bank decoder commands,.decomppackaging, and snapshot hygiene.