# MAME as a detector: the headless recipe (run) MAME 0.285 (`/usr/games/mame`) is tier 5: it finds differences, it does not decide them ([validation.md](validation.md)). This recipe was run on 2026-11-11 (pnickj, both CPUs) and again on 2026-11-12 (ffight, main CPU) and works as written. ## Commands ```sh python -I scripts/mame_trace.py pnickj --cpu main --seconds 3 --trace-frames 2 python -I scripts/mame_trace.py pnickj --cpu audio --seconds 3 --trace-frames 2 python -I scripts/mame_trace.py ffight --cpu main --seconds 3 --trace-frames 1 ``` Each writes `tests/mame_traces/-/` (git-ignored) and refuses an existing directory (move an old one into `trash/`). ROMs are read in place from `MAME/ROMs (non-merged)`. Wall time about 2-3 s each (ffight: 180 frames at 1,466% speed). The script runs: ``` mame -rompath -homepath -snapshot_directory snap -nvram_directory nvram -cfg_directory cfg -video none -sound none -nothrottle -noreadconfig -skip_gameinfo -debug -debugger none -log -seconds_to_run -autoboot_script /trace.lua ``` The Lua script makes the traced CPU visible and issues, for the main CPU: ``` trace cpu.trace,:maincpu,noloop,{logerror "M %06X %04X %08X ... %d %d %d\n",curpc,sr,d0,d1,d7,a0,a1,sp,totalcycles,beamy,beamx} wpset 800100,80,w,1,{logerror "W %06X %X %04X %d %d %d\n",wpaddr,wpsize,wpdata,totalcycles,beamy,beamx; g} wpset 800100,80,r,1,{... "R ..."} # CPS-A/CPS-B reads wpset 800180,10,w,1,{... "S ..."} # sound latches wpset 800000,20,r,1,{... "I ..."} # inputs and DIPs ``` and for the audio CPU a `Z` trace (`pc af bc de hl ix iy sp totalcycles`) plus `YW`/`YR` watchpoints on `F000-F00F`. Tracing stops after `--trace-frames` frames (a frame notifier); the watchpoints run for the whole run; at the last frame it saves `snap//final.png`, writes `facts.txt` (device tags, screen, register symbols) and exits. ## What it measured - Devices: `:maincpu` m68000 (10 MHz ffight, 12 MHz pnickj), `:audiocpu` z80 3.579545 MHz, `:2151`, `:oki`, `:soundlatch`, `:soundlatch2`, `:screen` 384 x 224 at 59.637405 Hz (8 MHz, 512 x 262). - 68000 debugger symbols: `A0-A6 D0-D7 PC CURPC SP USP SR IR CURFLAGS`: **no `A7`, use `SP`**. Z80: `A AF AF2 B BC BC2 C D DE DE2 E F H HL HL2 I IFF1 IFF2 IM IX IY L PC R SP WZ HALT CURPC CURFLAGS`. - pnickj (CPS_B_21_DEF): 60,068 instructions in 2 frames; writes layer control at `800166` (`12CE`) and palette control at `800170` (`003F`), the default offsets `26` and `30`; reads the write-only CPS-A registers `80010C-800116` at boot (Q13). Z80: 16,046 instructions; first write `F006 = 01`. - ffight (CPS_B_04): 39,965 instructions in 1 frame; reads the CPS-B ID at `800160` (offset `20`) once, value `0004`, as MAME's row says; writes layer control at `80016E` (`12CE`), palette control `80016A`, priority masks `800166 800170 800168 800172`, video control `800122 = 000E`, palette base `80010A = 9140`. These are the "G" evidence of [cps-b.md](cps-b.md). ## Traps (all hit here) 1. **One CPU per run.** A second `trace` with `logerror` for the other CPU logged nothing: the debugger parses a trace's expression against the visible CPU, so set `dbg.visible_cpu` first and trace one CPU per run. 2. Lua `install_write_tap` never fired, and `emu.print_error` does not reach `error.log`: use debugger `wpset` with `logerror` actions. 3. `wpsize` printed with `%X` gives `10` for a word access and `8` for a byte access (observed); decode accordingly. 4. An unknown symbol in a trace expression drops the whole command silently. 5. Lua `device.debug:bpset` segfaults (family note); the `bpset` command is fine. 6. Lua taps and notifiers must be held in globals (`frame_sub = ...`) or they are collected. ## What it cannot show Wait states, bus requests, per-line tilemap fetches, the sprite tile limit, the ID read counter and the CHECK lock-out: MAME models none of them (Q1-Q4, Q6, Q9). A lockstep against this trace must compare **instruction streams and register/I/O values**, not cycle counts: the board's 68000 will be slower than MAME's by design. Compare pictures at the palette index.