# The MAME recipe (headless, run here) MAME 0.285 at `/usr/games/mame` is a **tier-5 detector**: it finds differences, it does not judge them ([validation.md](validation.md)). Everything below was run on this machine on 2026-11-11 and 2026-11-12; the script is `scripts/mame_trace.py`, outputs go to the git-ignored `tests/mame_traces//`. Sets are read in place from `$MAME_ROMPATH`. ## Commands that worked ```sh python -I scripts/mame_trace.py spf2t --seconds 2 # 68000 trace python -I scripts/mame_trace.py spf2t --no-trace --z80 --seconds 2 # Z80 trace python -I scripts/mame_trace.py spf2tu --no-trace --dump 0x100000 --seconds 1 # opcode/data images python -I scripts/phoenix_pair.py spf2td spf2tu # compare with a Phoenix set ``` The script builds a Lua file and runs, in the output directory: ```sh mame spf2t -rompath "" -homepath . -cfg_directory cfg -nvram_directory nvram \ -snapshot_directory snap -video none -sound none -nothrottle -noreadconfig -skip_gameinfo \ -debug -debugger none -log -seconds_to_run 2 -autoboot_script trace.lua ``` Measured costs on the loaded machine (load average 40-70): 68000 trace of `spf2t`, 2 emulated seconds = 2,144,181 instructions, 119 frames, about 80 s wall, a 130 MB `error.log`. Z80 trace, 2 s = 874,738 lines, 18-35 s wall, 32 MB. Dump only (`--no-trace`), 1 s: under 2 s wall. One MAME process at a time. ## What MAME exposes - Device tags: `:maincpu` (m68000; spaces `program`, `opcodes`, `cpu_space`), `:audiocpu` (z80; `program`, `io`), `:qsound`, `:eeprom`, `:scantimer`, `:screen` (the script writes `devices.txt` with every device's spaces and register symbols). - 68000 symbols: `D0-D7 A0-A6 SP USP SR PC CURPC IR`. Z80: `PC SP AF BC DE HL IX IY AF2 BC2 DE2 HL2 I R IM IFF1 IFF2 HALT WZ` and the 8-bit halves. - **The decrypted opcode space.** The 68000 has a separate `opcodes` address space (`decrypted_opcodes_map`, `000000-3FFFFF`), fed by every program-function-code access ([encryption.md](encryption.md)). In debugger expressions `ow@addr` (or `3w@addr`) reads it; `w@addr` reads the program space (the ROM as dumped, which is what a data read sees). `dasm` disassembles the decrypted words. `saveo file,addr,len` saves from the opcodes space; `save file,addr,len` from the program space. From Lua: `manager.machine.devices[":maincpu"].spaces["opcodes"]`. - The `cps2 decrypt key0,key1,lower,upper` line in `error.log` (the driver's `logerror`) gives the key halves and the byte range for the set being run. - The trace line the script logs per 68000 instruction: `C curpc sr ow@curpc w@curpc d0 d1 a0 sp totalcycles beamy beamx frame`: the opcode as fetched and the same address as data, side by side. ## Traps 1. On MAME's 68000, `pc` in a trace action is already past the first word: use `curpc`. 2. Debugger errors appear only in the debugger console: the script writes `dbg.consolelog` to `console.txt`; read it after every new command. 3. **A trace action is evaluated with the symbols of the CPU that is visible while the machine runs**, not of the traced CPU. With `:maincpu` visible, a Z80 action naming `hl` silently does nothing; switching `dbg.visible_cpu` to `:audiocpu` only while issuing the command is not enough (measured 2026-11-12). So: **one CPU's action trace per run**; the script refuses `--z80` without `--no-trace`. With `:audiocpu` visible, `af`, `bc`, `de` resolve as registers, not as hex numbers. 4. `save`/`saveo` take three arguments; a fourth is parsed as `addr:tag` and fails. 5. `logerror` lines go to `error.log` in the current directory; `tracelog` lines go into the trace file, in front of MAME's own disassembly of the instruction. 6. Lua taps and notifiers must be held in globals or they are collected; Lua `device.debug:bpset` segfaults (the `bpset` command works). 7. The Z80 is held in reset until the 68000 writes `804040` bit 3: 15 Z80 instructions in the first emulated second of `spf2t`. Ask for 2-3 seconds. ## What MAME's CPS-2 is (so differences are read correctly) - **QSound is the HLE device by default** (`-listxml`: `device_ref` `qsound_hle`, 60 MHz). The DSP program runs only in a MAME built with `QSOUND_LLE` defined (`sound/qsound.h`); no command-line switch selects it. The dsp16-python Phase 0 drove the LLE device through `vgmplay` instead (`../dsp16-python/docs/phase0-status.md`). **So MAME's CPS-2 audio is not a reference for the low-level path**; for QSound the detector is the dsp16/qsound repos' LLE recipe. - **The 68000 is slowed by `set_clock_scale(0.7375)`** (11.8 MHz) instead of wait states; no bus stealing; the watchdog is not emulated; the encrypted range is deciphered one word past its end. Instruction counts per frame therefore differ from a board that models wait states: lockstep against MAME compares *sequences* (PC, registers, bus writes), not cycle positions, until the wait-state model is decided. - Objects are drawn once per frame from a copy latched at vblank; raster effects are drawn by partial updates at the raster IRQ. ## FinalBurn Neo https://github.com/finalburnneo/FBNeo @ `c3e8c4df` (non-commercial licence: closed box only), a second detector; its source is not fetched (Aubrey, 2026-11-24). Its QSound is the same superctr HLE as MAME's (per the dsp16 Phase 0, HYPOTHESIS). **Not built and not run here**; a shipped build would be run; its video lineage is partly separate from MAME's and would be the second opinion on object priority when M3 starts.