# The MAME recipe (run 2026-11-26, MAME 0.285) MAME is a closed box here: run, never read (its source is GPL-2.0+ as a whole; the SNK files say BSD-3-Clause on their licence lines, but the brief keeps all of it closed). Tier 5: a detector. ## Devices (`mame -listxml`) Every `snk.cpp` set: `maincpu`, `sub`, `audiocpu` (Zilog Z80), `screen`, `gfxdecode`, `palette`, `speaker`, `generic_latch_8` (the sound command), and its sound chips (`ym1`, `ym2`: YM3526, YM3812 or Y8950; `ay1`, `ay2`; `snkwave`). Clocks in [boards.md](boards.md). ## The commands, as run ```sh python -I scripts/mame_trace.py --map --set ikari # also tnk3 athena victroad psychos gwar python -I scripts/mame_trace.py --frames 3 --set ikari --watch C700,1 python -I scripts/mame_trace.py --frames 3 --set ikari --cpu sub python -I scripts/mame_trace.py --snap 20 --set ikari ``` | Run | Wall time | Result | | --- | --- | --- | | `--map`, six sets | under 1 s each | 55 map entries for ikari over three CPUs; the maps in [boards.md](boards.md) | | main Z80, 3 frames | under 1 s | 27,906 instructions in 199,967 cycles (7.17 cycles each; the boot's RAM clear and the $C700 poll) | | sub Z80, 3 frames | under 1 s | 7,993 trace lines; the NMI handler at $0066 at line 9 | | untraced, 20 s | about 1 s (3,416 % speed) | the Ikari Warriors title screen at frame 1200 | What the script passes: `-rompath $MAME_ROMPATH -homepath -cfg_directory /cfg -nvram_directory /nvram -video none -sound none -nothrottle -noreadconfig -skip_gameinfo -log -seconds_to_run N -autoboot_script run.lua`, and when tracing `-debug -debugger none`; the process runs under `nice taskset -c 24-31`. The Lua script dumps `device.spaces[...].map.entries` (start, end, mirror, read and write handler types, share name) for each CPU, or sets `debugger.visible_cpu` and issues `trace Z.trace,,noloop` and optional `wpset` watchpoints, then a frame notifier saves a snapshot and exits. ## Traps met - **A `{logerror ...}` action on a Z80 `trace` printed stale values**: `pc` and `totalcycles` repeated for runs of lines, changing once per scheduler timeslice (about 670 cycles). The bare trace file (one disassembled instruction per line) is exact; the script keeps that as `trace.log` and does not use an action. Watchpoint actions printed `pc` 0 on their first hit for the same reason; read their addresses and data, not their `pc`. - `ldir` appears once per iteration in the trace. - MAME warns "1.1d NOT FOUND (NO GOOD DUMP KNOWN)" and "1.2d" for ikari (the undumped rotary PROMs) and runs anyway. - The map dump shows MAME's model, with no timing: it cannot answer how the shared RAM is arbitrated (U2). ## Output `reference/mame/-/` (git-ignored): `trace.log`, `run.log` (MAME's log and watchpoint lines), `stdout.txt` (the map dump), `snap//0000.png`.