Architecture — IronFrame OuterFortress (Cart) 01 Decomp (NES-ME-USA)
Platform: 8-bit Cart (
NES / RP2A03, MOS6502) · Mapper:iNES Mapper 2(UNROM) · Title ID:NES-ME-USA
IronFrame-OuterFortress-Cart-01-Decomp houses the clean-room decompilation schemas, hardware-level system specification, self-contained BYO-ROM tooling, .decomp package exporter, cohesive D3_Mapped C coalescer, zero-tell D4_CleanSource AST normalizer, multi-tier snapshot builder, and 1:1 byte-exact 6502 reassembly scripts for NES-ME-USA (131,088 bytes, NES 2.0). Source media remains clean-room separated inside the gitignored Corpus/standalone/ directory (pinned in Standard 18 v2 standalone_integrity.json as 1 requiredRomChecksums BYO-ROM entry plus 17 deterministic extracted/ entries), while tracked schemas, verification scripts, modular C parity harness (d4_harness/), offline tests (tests/), and manuals live under Dev/.
1. Cartridge & UNROM Bank Topology (iNES Mapper 2)
| Segment / Window | CPU Address Range | Size | Mapping Behavior | Contents / Role |
|---|---|---|---|---|
| NES 2.0 Header | (file offset 0x0000..0x000F) |
16 B |
Static ROM header | 4E45531A 08 00 21 08 20 00 00 07 00 00 00 01 |
| Switchable PRG Window | $8000-$BFFF |
16,384 B (7 banks) |
Mapped via UNROM $8000-$FFFF latch (BANK_00..BANK_06) |
Gameplay, maps, transceiver dialogs, sound sequencer |
Fixed PRG Bank (PRG_FIXED_07) |
$C000-$FFFF |
16,384 B |
Permanently mapped to final 16 KiB PRG bank (bank 7) |
Reset/NMI/IRQ vectors, PPU/APU drivers, UNROM trampolines, core loop |
CHR Memory (CHR-RAM) |
PPU $0000-$1FFF |
8,192 B RAM |
0 CHR-ROM banks (CHR-RAM dynamically populated from PRG) |
Tiles/patterns streamed by PRG_FIXED_07 and switchable banks |
CPU Work RAM (WRAM / ZP) |
$0000-$07FF |
2,048 B |
Internal 2 KiB SRAM + 256-B page mirrors |
Zero Page, 0x0100 stack, 0x0200 OAM, 0x0300 Actor/Audio SoA |
32 KiB
.prgExtraction Convention: Each linked.prgbank image underCorpus/standalone/extracted/is32,768bytes ($8000-$FFFF), pairing a switchable bank (BANK_00..BANK_06) with fixedPRG_FIXED_07.PRG_FIXED_07.prgpairsBANK_00withPRG_FIXED_07, giving it the exact same SHA-256 (96d482df...) asBANK_00.prgin d5_byte_match.json.
Hardware Entry Vectors (PRG_FIXED_07, $FFFA-$FFFF)
VEC_NMI($C06C): VBlank PPU/OAM/scroll commit and per-frame tick entry.VEC_RESET($C001): Cold-boot hardware init, WRAM clear, and main loop handoff.VEC_IRQ($C0B7): Interrupt vector stub in fixed bank7.
2. Core Control-Flow & Bank-Switching Primitives
2.1 Inline Jump-Table Dispatch ($C6B7)
- Routine:
inline_jump_table_dispatchat$C6B7(16+call sites). - Mechanism: Pulls the caller's return address from the 6502 hardware stack (
$0100+S), scales accumulatorAby2to index an inline.word[]target table stored immediately after theJSR $C6B7, writes the resolved target into Zero Page pointer$0080, and transfers control viajmp ($0080)($C6D2:6C 80 00). - Decompiler Boundary: Marked
NoReturnduring static analysis so callers terminate cleanly afterJSR $C6B7rather than attempting to decode inline pointer tables as instructions.
2.2 UNROM Bank-Switch Trampolines ($C932..$C958) & Bus-Conflict LUT
Discrete UNROM hardware requires the value written to ROM latch space ($8000-$FFFF) to equal the byte stored in ROM at the write address to avoid bus contention:
$C932..$C94A(unrom_select_bank_0..unrom_select_bank_6): Fixed4-byte spaced bank-select entry points inPRG_FIXED_07.$C94C(unrom_select_bank_y/unrom_select_bank_index): Stores active bank index in Zero Page$27, then executes85 27 B9 D0 FF 99 D0 FF 60(STA $27; LDA $FFD0,Y; STA $FFD0,Y; RTSstarting at$C94F) through the$FFD0-$FFD7identity table{0..7}.$C958(unrom_restore_active_bank): Restores the active bank shadowed in Zero Page$27, adjacent to the$C959bank-switch helper/LUT region.
3. Domain & Translation-Unit Topology (499 / 499 Functions, 26 Cohesive Modules)
In v0.4.0 (D4_CleanSource / D4b Execution Parity), coalesce_d4_modules.py and craftsmanship_d4_normalizer.py (backed by craftsmanship_d4_ast_cleaner.py and craftsmanship_d4_helpers.py) organize and normalize all 507 symbols (499 catalog functions from 68 historical D2_Structured fragments + 8 synthesized adapters) into 26 cohesive, warning-free, zero-tell C11 modules (10 src/core/ + 16 overlays/BANK_00..06.prg/, 34 .c/.h files total) governed by d3_module_map.json and d3_symbol_overrides.json. The D4_CleanSource tree resolves all 2,344 extern declarations in include/metalgear_globals.h (2,324 catalog globals + 20 deduplicated synthetic/bank-scoped overrides including g_actor_soa_ram[128] and g_apu_mmio_regs[24]), ships a clean fixed-width include/ghidra_compat.h (s8..u64 only, zero P-code macros), configures zero-suppression .clangd and compile_commands.json (-Wall -Wextra -Wno-unused-parameter targeting msp430-unknown-none-elf), syncs 36 files into Corpus/readable/, exports 5 zero-body Standard 18 v2 shards under Dev/schemas/d4_rewrites/, and pairs with 3 lifted hardware assembly modules (551 lines) under Corpus/work/lifted_asm/, while run_d4b_lockstep.py and d4_harness/ certify 650-frame / 5-scene WRAM/OAM/PPU/APU execution lockstep (mismatchedFrames: 0):
| Domain | Bank Image | Code Bytes | Cohesive D4 Modules |
D2 Slices |
Functions | Bank Globals | Domain Globals |
|---|---|---|---|---|---|---|---|
core |
PRG_FIXED_07 ($C000-$FFFF) |
12,832 |
10 |
33 |
246 |
1,246 (resident) |
1,113 |
bank_00 |
BANK_00 ($8000-$BFFF) |
2,618 |
2 |
5 |
34 |
310 |
310 |
bank_01 |
BANK_01 ($8000-$BFFF) |
715 |
1 |
1 |
2 |
25 |
30 |
bank_02 |
BANK_02 ($8000-$BFFF) |
4,100 |
3 |
12 |
87 |
259 |
274 |
bank_03 |
BANK_03 ($8000-$BFFF) |
2,471 |
3 |
5 |
41 |
100 |
134 |
bank_04 |
BANK_04 ($8000-$BFFF) |
2,046 |
3 |
4 |
32 |
148 |
160 |
bank_05 |
BANK_05 ($8000-$BFFF) |
2,252 |
2 |
4 |
24 |
79 |
82 |
bank_06 |
BANK_06 ($8000-$BFFF) |
2,123 |
2 |
4 |
33 |
157 |
221 |
| Total | 8 PRG Banks (131,072 B) |
29,157 |
26 |
68 |
499 |
2,324 |
2,324 |
3.1 Cohesive D4_CleanSource Module Partition (26 Modules) & 8 Synthesized Adapters
Module (Corpus/readable/ & Corpus/tiers/D4_CleanSource/) |
Domain | Funcs | Primary Scope |
|---|---|---|---|
src/core/core_vectors_boot_and_input.c |
core |
15 |
Hardware reset/NMI/IRQ vectors, RAM init, joypad polling, pause/timer helpers |
src/core/core_game_state_and_cutscenes.c |
core |
48 |
Top-level game mode state machine, submodes, cutscene stepping, BGM selection |
src/core/core_unrom_and_math.c |
core |
19 (+8) |
UNROM bank trampolines, inline jump dispatch, math/PPU text helpers, 8 synthesized D3 adapters |
src/core/core_ppu_and_vram.c |
core |
21 |
PPU nametable streaming, room/tileset CHR loading, VRAM queue writers |
src/core/core_oam_and_metasprites.c |
core |
7 |
OAM shadow sprite builder, grid/column metasprite emitters, attribute helpers |
src/core/core_gameplay_loop_and_rooms.c |
core |
28 |
Gameplay frame tick, attract-mode demo loop, room decompression, bank-call wrappers |
src/core/core_actor_ai.c |
core |
34 |
Enemy patrol scripts, line-of-sight/chase pathfinding, alert states, actor projectiles |
src/core/core_player_and_doors.c |
core |
40 |
Player movement, collision probes, guard vision/alert, damage handling, door/elevator triggers |
src/core/core_weapons_and_bosses.c |
core |
26 |
Player weapons, mines, projectile collisions, boss damage/spawning, room gimmick dispatch |
src/core/core_objectives_and_items.c |
core |
8 |
Hostage rescue tracking, item pickups, supply refills, pause/ending bank dispatchers |
overlays/BANK_00.prg/bank00_hud_and_guards.c |
bank_00 |
8 |
Alert reinforcement guard spawning and HUD status-bar equipment/ammo queue updates |
overlays/BANK_00.prg/bank00_hazards_and_countdown.c |
bank_00 |
26 |
Screen shake, laser/pit/bridge/explosion hazards, hazard zones, self-destruct countdown |
overlays/BANK_01.prg/bank01_ppu_streams.c |
bank_01 |
2 |
Bank-1 PPU nametable stream batch uploader and zero-page scratch helper |
overlays/BANK_02.prg/bank02_intro_menus_and_cutscenes.c |
bank_02 |
17 |
Intro/title sequence packets, VRAM menu rows, cursor input handling, cutscene scroll |
overlays/BANK_02.prg/bank02_boss_movement_and_minions.c |
bank_02 |
33 |
Boss state dispatchers, alignment checks, bounded movement, minion/twin-actor updates |
overlays/BANK_02.prg/bank02_boss_patterns_and_turrets.c |
bank_02 |
37 |
Polar-orbit boss mechanics, bomb/barrage/quad-shot patterns, twin-turret tracking |
overlays/BANK_03.prg/bank03_actors_and_fade.c |
bank_03 |
6 |
Bank-3 palette fades, actor behavior state machine, proximity hits, animation timers |
overlays/BANK_03.prg/bank03_password_system.c |
bank_03 |
25 |
Password grid UI, cursor input, 24-character encode/decode, 5-bit checksum validation |
overlays/BANK_03.prg/bank03_ppu_boxes_and_vram.c |
bank_03 |
10 |
Direct PPU bordered dialog/menu box drawing, room radio triggers, VRAM queue flusher |
overlays/BANK_04.prg/bank04_room_spawns_and_warps.c |
bank_04 |
10 |
Room actor spawning, directional warps, special transitions, ending ascent cutscene |
overlays/BANK_04.prg/bank04_homing_actors.c |
bank_04 |
8 |
Binoculars room peek, homing patrol projectiles, bank-4 actor proximity triggers |
overlays/BANK_04.prg/bank04_dialog_system.c |
bank_04 |
14 |
Codec/dialog window framing, typewriter text streaming, row clearing, close restoration |
overlays/BANK_05.prg/bank05_transceiver_ui.c |
bank_05 |
11 |
Transceiver frequency HUD, incoming call matching, dialog streaming, frame rendering |
overlays/BANK_05.prg/bank05_ending_sequence.c |
bank_05 |
13 |
Ending explosion animation, transceiver epilogue calls, frequency sweep, palette fadeout |
overlays/BANK_06.prg/bank06_audio_engine.c |
bank_06 |
14 |
APU register writers, pause-mute synchronization, DMC DAC ramp, envelopes, vibrato |
overlays/BANK_06.prg/bank06_audio_sequencer.c |
bank_06 |
19 |
BGM/SFX sequence bytecode parser, pitch decoding, control opcodes, track triggers |
- Synthesized
D3Adapters (8insrc/core/core_unrom_and_math.c) &9Sub-Entry Prototypes: d3_symbol_overrides.json declaratively specifies3cross-bank trampolines (switch_bank6_play_sound_and_restore_bank2at$F5AC,switch_bank6_and_queue_ppu_streamat$FBF5,trampoline_bank4_resolve_room_transitionat$EE2A) and5signature-adapting wrappers (audio_play_sound_or_bgmat$99A8,mg_b034_try_spawn_alert_guard_defaultat$A765,mg_b034_upload_bank00_ppu_stream_bb3a_retat$BB28,mg_b034_bank03_dispatch_actor_defaultat$B83A,mg_b034_bank04_dispatch_actor_defaultat$BBE1), alongside9subEntryDeclarationsprototypes ($C68B,$C7F9,$C804,$C885,$CA2C,$D59C,$2020,$4420,$8043) emitted ininclude/metalgear_functions.h. - Call Graph & Curated Anchors: call_graph.json orders all
499functions into bottom-up waves0..9(max_wave=9) with1nontrivial strongly connected component (BANK_06.prg@000094ed <-> BANK_06.prg@000096e4, audio sequencer recursion) and0failed functions (4 -> 0afterBANK_06recovery). anchor_functions.json tracks39curated entry/system anchors across5export shards. - Lifted Hardware Assembly (
551lines):Corpus/work/lifted_asm/isolates low-level 6502 hardware glue acrossppu_joypad_io.s(149lines),unrom_trampoline.s(218lines), andvectors_and_nmi.s(184lines).
3.2 Clean-Room NesBus Runtime (Dev/scripts/d4_harness/), Oracle Bridges & Bank Decoders
In v0.4.0, host execution verification expands from D4a subsystem checks (10/10) to D4b cycle-synced frame lockstep (650 frames across 5 deterministic gameplay scenes) plus clean-room Bank 1..4 and BANK_06 binary decoders:
Component (Dev/scripts/) |
Lines / SLOC | Responsibility & Key Symbols |
|---|---|---|
| nes_bus.h | 103 lines |
Declares NesCpuState, NesPpuState, NesApuState, NesBus (wram[2048], oam[256], chr_ram[8192], nt_ram[2048], palette[32], prg_banks[8][16384], prg_bank, mirroring, joy1 shift/strobe, open bus), nes_bus_load_ines, nes_bus_reset, nes_bus_read/write, nes_ppu_read/write, nes_apu_read/write, nes_cpu_step, nes_cpu_nmi, nes_bus_step_frame, d4b_crc32, and d4b_run_lockstep_cli. |
| nes_bus.c | 158 lines |
Implements iNES/NES 2.0 loader, $0000-$1FFF mirrored 2 KiB WRAM, $4014 OAM DMA (513 + (cycles & 1) stall cycles), $4016/$4017 strobe/shift controller input, $8000-$FFFF UNROM Mapper 2 bus-conflict latch ((val & prg_read_raw(bus, addr)) & 7), and IEEE 802.3 d4b_crc32. |
| nes_ppu_apu.c | 242 lines |
Implements RP2C02 PPU $2000-$2007 (scanline 241 dot 1 VBlank NMI edge, scanline 261 flag clear, odd-frame dot-339 skip, $2002 clear-on-read, w-latch scroll/VRAM addr, 1-byte read buffer, palette $3F10/$14/$18/$1C mirrors, H/V nametable mirroring), RP2A03 APU/DMC latches + 3–4 cycle DMA stalls, and nes_bus_step_frame. |
| nes_cpu_ops.c & nes_cpu_exec.c | 172 / 232 lines |
Clean-room 56-mnemonic / 151-opcode RP2A03 6502 decoder (nes_cpu_decode_op, nes_cpu_alu omitting BCD decimal mode, nes_cpu_rmw, nes_cpu_branch_cond, nes_cpu_reg_op) and cycle-accurate execution/stack/interrupt engine (JMP ($xxFF) page wrap, nes_cpu_step, nes_cpu_nmi). |
| d4b_lockstep_scenes.c | 181 lines |
Drives 5 deterministic gameplay scenes (1..100, 101..220, 221..380, 381..520, 521..650), hashes masked WRAM ($0100-$01FF zeroed), OAM (256 B), PPU (4-B regs + 32-B palette), and APU (24-B regs), and executes 8 live D4_CleanSource C checkpoints (cp_1_boot_unrom_bank0..cp_8_combat_dmc_ramp). |
| parity_harness.h, parity_runner_main.c, parity_rom_and_mapper_tests.c, parity_gameplay_and_audio_tests.c | 25 / 65 / 142 / 176 lines |
Preserves <extracted_prg_dir> 10/10 D4a subsystem parity CLI and adds --lockstep <rom.nes> <out.json> dispatching d4b_run_lockstep_cli. |
| d4b_oracle_bridges.py & run_d4b_lockstep.py | 241 / 169 SLOC |
Locates Mesen 2.1.1 (--mesen-exe / MESEN_EXE / %LOCALAPPDATA%\Programs\Mesen2\Mesen.exe -> --testRunner Lua tracer) and read-only reCart.Core.dll (--recart-dir / RECART_DIR -> ephemeral net8.0 C# top-level host instantiating CartMachineFactory.CreateFromRomBytes(..., CartExecutionTierMode.InterpreterOracle)), verifying mismatchedFrames == 0 into digest-only d4b_lockstep_report.json. |
| decode_rooms_and_metatiles.py, decode_guards_and_weapons.py, decode_codec_and_audio.py, decode_all_bank_tables.py | 168 / 183 / 180 / 210 SLOC |
Extracts room, metatile, adjacency, CHR, patrol, dialog-offset (metadata-only), spawn, weapon, password, codec, and BANK_06 audio tables strictly into --out-dir (Corpus/work/decoded_tables/) and writes Standard 18 v2 spec_coverage.json (--write-spec-coverage, unresolvedFieldCount: 0). |
| d4b_validation_helpers.py | 191 SLOC |
Enforces Standard 18 v2 key schemas, zero raw RAM dumps (_scan_digest_only), zero trademark/PII leaks, and 4/4 specification spoke checks for verify_track_d5.py. |
4. Research Directory Contract & Related Documentation
- Read-Only Media Isolation & Multi-Tier Snapshots: Local
Corpus/holds read-onlystandalone/(pinned in standalone_integrity.json v2 as1BYO-ROM entry +17extracted/entries totaling3,717,065B), preservedtiers/{D1_Raw, D2_Structured, D3_Mapped, D4_CleanSource}snapshots (D1_Raw:8bank trees /555files;D2_Structured:68line-split.cslices /80files;D3_Mapped:26cohesive.cmodules /38files with0raw tokens;D4_CleanSource:26zero-tell C11 modules /36files with0tells and strict-Wall -Wextra -Wno-unused-parameterconfigs),readable/(synced toD4_CleanSource,36files), andwork/(includingwork/decoded_tables/from the4table decoders)—strictly gitignored and excluded from source and.decomparchives. - Clean-Room Tooling (
Dev/scripts/&Dev/schemas/): Organized into shared path/hash helpers (nes_cli_common.py), 6502 CFG/UNROM unpacker (nes_6502_cfg.py,nes_unrom_unpack.py),D3schemas (d3_module_map.json,d3_symbol_overrides.json),D4zero-body rewrite shards (d4_rewrites/*.json,5shards covering507symbols), cohesive coalescer (coalesce_d4_modules.py), AST C11 normalizer (craftsmanship_d4_helpers.py,craftsmanship_d4_ast_cleaner.py,craftsmanship_d4_normalizer.py), tier materializer (materialize_decomp_tiers.py), 6502 assembler (asm6502_d5.py,build_and_verify_d5.py), D4a/D4b parity & oracle harness (build_and_verify_d4.py,run_d4b_lockstep.py,d4b_oracle_bridges.py,10-filed4_harness/), Bank1..4&BANK_06table decoders (decode_rooms_and_metatiles.py,decode_guards_and_weapons.py,decode_codec_and_audio.py,decode_all_bank_tables.py), schema/verifier CLIs (gen_d4_globals_and_lifts.py,reexport_stage3.py,d4b_validation_helpers.py,verify_track_d5.py),.decomp/release packagers (export_decomp_bundle.py,package_release.py), and5offlineunittestmodules (25cases +tests/synthetic_d4_fixtures.py). - Next Manuals & Specification Spokes: SPECIFICATIONS.md | Symbol & Bank Spoke | Rooms, Metatiles & CHR Spoke | Guards, Weapons & Password Spoke | Codec &
BANK_06Audio Spoke | FINDINGS.md | OPERATIONS.md - Stage Notes: Stage 0 | Stage 1 | Stage 2 | Stage 3 | Stage 4