# MAME 0.285 as an emulator-derived detector for the SPC700 MAME's `spc700` device (`src/devices/cpu/spc700/spc700.cpp`, an instruction-level core whose header credits "Anonymous, TRAC, Brad Martin, anomie, Blargg") runs inside the `snes` driver as the S-SMP (`:soundcpu`; the S-SMP device, `machine/s_smp.cpp`, is LGPL-2.1+ and a closed box). The CPU file is BSD-3-Clause (R. Belmont, Karl Stenerud) and may be read. It is **emulator-derived**: use it to find where a core first disagrees on real code, then settle the disagreement with a higher tier ([validation.md](validation.md)). It counts whole instructions, not bus cycles, and its S-SMP ignores the TEST register (a statement first made from reading the LGPL device under the old rule; closed box from now on, never a default), so it says nothing about dummy reads, cycle order or wait states. Everything on this page was run on 2026-10-21 on this machine, MAME 0.285 (`mame` on the path, or `MAME`). `scripts/mame_trace.py` is the recipe as a script. ## The IPL ROM, without a download `mame -listroms snes` requires one file, `spc700.rom` (64 bytes, CRC 44bb3a40, SHA-1 97e35255...), the S-SMP's boot ROM. It is not installed here and nothing downloads it: anomie's pinned SPC700 doc prints the 64 bytes ("IPL BOOT ROM"), and those bytes have **exactly MAME's CRC-32 and SHA-1** (checked). The script writes them into its gitignored run directory as `roms/snes/spc700.rom` and refuses to run if the check fails. The file is Sony/Nintendo's code: never committed, never copied out of `reference/` or `tests/mame_traces/`. ## The recipe Write `trace.lua` in a fresh working directory: ```lua local dbg = manager.machine.debugger dbg.visible_cpu = manager.machine.devices[":soundcpu"] dbg:command('trace spc.trace,:soundcpu,noloop,{logerror "%X %X %X %X %X %X %X %d\n",pc,b@pc,a,x,y,s,p,totalcycles}') dbg:command("go") ``` and run, from that directory, with the IPL ROM at `roms/snes/spc700.rom` and the cartridge copied in as `cart.sfc`: ```text mame snes -rompath roms -cart cart.sfc -homepath "$PWD" \ -video none -sound none -nothrottle -noreadconfig -skip_gameinfo \ -debug -debugger none -log -seconds_to_run 20 -autoboot_script "$PWD/trace.lua" ``` `error.log` lands in the working directory. After a byte-order mark and cartridge-slot lines, it holds one line per S-SMP instruction before it executes: `PC opcode A X Y SP PSW totalcycles`, all hex but the last. `scripts/mame_trace.py ROM.sfc --ports` replaces the trace with a watchpoint that logs only the S-SMP's writes to `$F4` (`wpset f4,1,w,1,{...}`), which is where PeterLemon's tests report each sub-test and where the IPL echoes its upload counter. ## Facts about the trace - Device `:soundcpu`, "Nintendo/Sony S-SMP @ 2.04 MHz". State symbols: `PC S P A X Y` plus `GENPC CURPC GENFLAGS`; **no YA**. `b@pc` reads the opcode through the visible CPU's program space. - `totalcycles` counts the **2.048 MHz** S-SMP input clock, 2 per SPC700 cycle: in the IPL, `MOV X,#$EF` advances it by 4, `MOV (X),A` by 8, `DEC X` by 4, a taken `BNE` by 8 (anomie: 2, 4, 2, 4 cycles). - MAME starts the S-SMP at `$FFC0` with A = X = Y = SP = PSW = 0 (its `device_reset` clears S and every flag), not ares' SP = $EF, PSW = $02 (U12). - The family's trace traps hold: keep `logerror` actions to at most 14 values (8 used); `-debugger none` is required; Lua notifier subscriptions must be held in globals or they stop firing. - Speed here: a 20-emulated-second traced run of `spctest` took 41 s wall and wrote 4.67 million instruction lines (139 MB of `error.log`, plus an 88 MB disassembly in `spc.trace`). ## How MAME 0.285 scores | ROM | What | MAME 0.285 | Tier of the ROM | | --- | --- | --- | --- | | gilyon `spctest.sfc` (v1.4) | 1,368 tests, every opcode but SLEEP/STOP, every addressing mode, P = 0 and 1 | **"Running tests... Success", test number 0557** (hexadecimal: the last, the 1,368th) | hardware-run test, author's expectations (validation.md) | | PeterLemon `SPC700ADC/AND/DEC/EOR/INC/ORA/SBC.sfc` | 162 sub-tests reporting `$0n` pass / `$8n` fail on `$F4` | **all 162 pass** (ADC 1-$1A, AND 1-$1C, DEC 1-$E, EOR 1-$1A, INC 1-$E, ORA 1-$1C, SBC 1-$1A; no `$8n` write) | hardware-verified (author runs on SNES via SD2SNES; expected screens in the repo) | Cycle audit (`scripts/mame_trace.py`, after the `spctest` run): MAME's per-instruction cycle delta equals anomie's `Cyc` column on **all 4,671,187 measurable instructions** (254 distinct opcodes executed; taken/not-taken decided from the next PC). So MAME, anomie's table and SingleStepTests agree on every instruction length that real code exercised. ## Use 1. **Rung 4 replay** ([validation.md](validation.md)): real sound drivers read `$F4`-`$F7` (S-CPU mailboxes), `$FD`-`$FF` (timers) and `$F3` (DSP), whose values come from the board. `scripts/mame_trace.py ROM --io` adds read and write watchpoints on `$F0`-`$FF` (`R addr data cycles`, `W addr data cycles` between instruction lines) and `spc700_python.replay` feeds the logged reads to the core in order, compares the writes, `PC A X Y SP PSW` per instruction and the `totalcycles` deltas รท 2. Volume: 30 emulated seconds is 7-9 M instruction lines, 1-4 M I/O lines, 210-240 MB of `error.log`, about 3 minutes of PyPy. Results are in [validation.md](validation.md). U1's read-before-write makes a store to `$F4`-`$FF` also a read, which MAME's instruction-level core does not make: the replay answers those from RAM and counts them. And MAME's `SUBOP_ADC` macro evaluates its second argument twice, so memory-destination ADCs log two reads; the replay drops the repeat. 2. The first divergence is a lead, not a verdict: look it up in [undocumented-behavior.md](undocumented-behavior.md), then ask a higher tier. 3. Commercial ROMs are the player's own, found through `NO_INTRO_DIR` (never commit, never copy into the repository). Any of them gives long real-driver traces (N-SPC and other drivers) once the replay above exists.