Skip to content

v0.3.0 — 1:1 ROM Differential Verification Engine & Fygar Flap Timing

Choose a tag to compare

@Suspence00 Suspence00 released this 13 Oct 12:22
· 8 commits to main since this release

v0.3.0 — 1:1 ROM Differential Verification Engine & Fygar Flap Timing

A major milestone release introducing automated mathematical differential verification against original 1982 Namco arcade ROM bytes and MAME hardware microcode, alongside gameplay timing fixes uncovered by the new verification harness.


Highlights

1. Automated 1:1 ROM Differential Verification Harness

Rather than relying on subjective gameplay inspection, this release adds a reference verification system that executes original 1982 arcade ROM bytes in lockstep with the hand-decompiled Rust routines:

  • Reference Z80 Interpreter (src/z80_ref.rs): Ground-truth CPU emulator running original ROM machine code with precise Z80 flag calculation (SZ53P, DAA, 16-bit ALU, IX/IY index math, CB/ED/DD/FD opcode tables).
  • Step-by-Step State Verifier (src/verify.rs & src/bin/verify_decomp.rs): Compares post-execution CPU and shared RAM states across each routine.
    • Dead-Stack Window Filtering: Eliminates false alarms from return address residue left below SP in stack memory.
    • Onward Liveness Analysis: When scratch registers (A, F, HL) differ at function exit, simulates 20,000 onward instructions from both states to prove whether the divergence propagates into memory/branches (REG-PROPAGATES) or is benign scratch state (REG-BENIGN).
  • MAME Reference Alignment (tools/mame/): Lua tracing harness verifying Namco 51XX and 53XX custom I/O MCU commands, fire button edge detection, and bus timings against real chip microcode.

2. Bug Fix: Fygar Fire Breath Flap Animation (decomp_update_fygar_fire_2aa4)

Differential verification uncovered a real state divergence (STATE) during monster AI processing:

  • Symptom: At frame 1,119, RAM $857C (wing color) and $98A4..$98A9 (fire sprite positions) diverged between Rust and the reference ROM.
  • Root Cause: In decomp_update_fygar_fire_2aa4, the countdown timer was checked against 5 | 8 | 12 (FlapOrange) and 7 | 10 (FlapRed). In original Z80 ROM (cpu0_main.asm lines 6183–6219), the timer decrements every 2 frames: odd intervals 5 | 9 | 13 are FlapOrange ($0C) and 7 | 11 are FlapRed ($02). Even values caused frames 9, 11, and 13 to fall through to FireStep::None, skipping sprite clearances and desyncing wing colors.
  • Resolution: All 3 clearance branches now strictly follow the ROM cadence.

Verification Benchmarks

Metric Result
Total Frames Run 2,000
CPU Steps Verified 119,999,998 (~120M)
Real State Divergences (STATE) 0
Register Propagations (REG-PROPAGATES) 0
Benign Dead Scratch Registers (REG-BENIGN) 25 (proven dead over 20,000 onward steps)
Standard Unit Tests (cargo test) Passed
Headless Verification (--headless-test) Passed

Reproducing Verification

To verify the decompiled Rust routines against your own extracted ROM set:

cargo run --release --bin verify_decomp -- --frames 2000 --script tools/mame/inputscript.txt

Full Changelog: v0.2.1...v0.3.0

Full Changelog: v0.2.1...v0.3.0

Full Changelog: v0.2.1...v0.3.0