# The MAME recipe (MAME 0.285, headless, as run here) MAME is a **tier-5 detector** ([validation.md](validation.md)): it finds where this board differs and never decides who is right. Everything on this page was run on this machine with `/usr/games/mame` 0.285; `scripts/mame_trace.py` encodes it. ## Commands ```sh python -I scripts/mame_trace.py puzzledp --symbols # register symbols, 1.4 s python -I scripts/mame_trace.py puzzledp --seconds 1 # 68000 trace: 44 s wall, 82.5 MB, 1,474,250 lines python -I scripts/mame_trace.py puzzledp --cpu audiocpu --seconds 1 # Z80 trace: 14 s wall, 23 MB, 464,566 lines python -I scripts/mame_trace.py puzzledp --no-trace --seconds 20 # snapshot only: 3 s wall python -I scripts/mame_trace.py puzzledp --bios unibios40 --no-trace --seconds 20 python -I scripts/mame_trace.py kof2003 --no-trace --seconds 25 # an encrypted set (PVC, CMC50, PCM2): 7.6 s wall # AES: needs an aes.zip; a symlink to the curated neogeo.zip (which holds the AES ROMs) is enough mkdir -p tests/runs/rompath && ln -s "$CURATED_ROMS/neogeo/neogeo.zip" tests/runs/rompath/aes.zip python -I scripts/mame_trace.py puzzledp --driver aes --no-trace --seconds 20 \ --rompath "$PWD/tests/runs/rompath;$CURATED_ROMS" # 3.4 s wall, title screen ``` Each run writes a fresh git-ignored `tests/mame_traces/-[-n]/` with `command.txt`, `stdout.txt`, `error.log` (the trace), `snap//0000.png` and MAME's `cfg/`, `nvram/`. The command the script builds (MVS): ```text mame puzzledp -rompath "$CURATED_ROMS/mame;$CURATED_ROMS/neogeo" -homepath -cfg_directory /cfg -nvram_directory /nvram -snapshot_directory /snap -video none -sound none -nothrottle -noreadconfig -skip_gameinfo -seconds_to_run N -debug -debugger none -log -autoboot_script /run.lua ``` with `run.lua`: ```lua local dbg = manager.machine.debugger dbg.visible_cpu = manager.machine.devices[':maincpu'] -- or ':audiocpu' dbg:command('trace cpu.trace,:maincpu,noloop,{logerror "M %06X %04X %X %X %X %X %d %d %d %d\\n",pc,sr,d0,d1,a0,sp,totalcycles,beamy,beamx,frame}') dbg:command('go') ``` For `--driver aes` the script adds `aes -cart ` and `-hashpath /usr/share/games/mame/hash`. ## What was measured - Devices of `neogeo` (`mame -listdevices neogeo`): `maincpu` 68000 at 12 MHz, `audiocpu` Z80 at 4 MHz, `ymsnd` YM2610 at 8 MHz, `screen` at 6 MHz (384 x 264 total, 320 x 224 visible, hbend 28, vbend 16), `spritegen`, `systemlatch` (74HC259), `upd4990a`, `watchdog`, `saveram`, `memcard`, `soundlatch`, `soundlatch2`, `audionmi`, `cslot1-6`, `ctrl1-2`, `edge`. - Register symbols: `:maincpu` has `A0-A6 D0-D7 SP USP PC SR IR CURPC CURFLAGS` (**no `A7`**); `:audiocpu` has `A AF AF2 B BC BC2 C D DE DE2 E F H HL HL2 L I R IM IFF1 IFF2 IX IY SP PC WZ HALT`. - 68000, first line `M C00404 2700 0 0 0 10F300 34 240 17 0`: the default system ROM (`euro`, `sp-s2.sp1`) starts at `$C00404`, SSP `$10F300`, after **34** clocks, on line 240 (MAME starts the frame at the vblank line), `beamx` 17 = `totalcycles / 2` (pixel clock = 68000 clock / 2). After one emulated second the system ROM is still in its RAM tests (`$C13180`, `D0 = $AAAA`, `A0` in `$D0xxxx`, backup RAM). - Z80, first line `Z 0000 0040 ... 0 240 0 0`: starts at `$0000` at clock 0. One unmapped write is logged: port `$01C0` at PC `$0104` (C11). - Snapshots: `puzzledp` (MVS, 20 s) at its attract screen; `puzzledp` on `aes` (20 s) at its title screen with "CREDITS 04" on both sides (no coin slots: the home mode shows credits); `kof2003` (25 s) at its attract sequence with "INSERT COIN", so MAME's PVC/CMC50/PCM2 path works from the local MAME set. ## Traps 1. Trace symbols resolve against the **visible** CPU: a Z80 trace issued without setting `dbg.visible_cpu` to `:audiocpu` is dropped silently (0 lines). 2. `logerror` takes at most 14 values after the format. 3. `grep` needs `-a` on `error.log`. 4. `-seconds_to_run` takes integers. 5. `mame aes` needs an `aes` set; none exists locally. The curated `roms-retrobat/neogeo/neogeo.zip` (38 members) holds `neo-epo.bin`, `neo-po.bin` and `neodebug.rom`; `roms-retrobat/mame/neogeo.zip` (34 members) does not. A symlink named `aes.zip` in an ignored directory solves it without copying. 6. With `-noreadconfig`, `mame.ini`'s `hashpath` is dropped; a console driver's `-cart` then fails with "Unable to load image" until `-hashpath` is given. The cartridge is then found in a `neogeo/` directory under a rompath entry (hence `$CURATED_ROMS` in the AES rompath). 7. An ALSA warning on stderr is harmless. 8. Lua `device.debug:bpset` segfaults (family note); the `bpset` debugger command works. ## What MAME can and cannot decide here It can flag: instruction-stream divergence (lockstep on PC, SR, registers and `totalcycles`), the frame and line on which an IRQ is taken, pictures. It **cannot** decide: wait states (MAME inserts only the memory card's two [neogeo.cpp 1074, 1086] and lists ROM waits as a to-do [32]), the interrupt-acknowledge length (C6), the reset-instruction behaviour (C2), the AES clock (C1: MAME runs `aes` at the MVS's 24 MHz figures), the vector-swap mirror at `$C00000` (C10), raster effects "off by a couple of lines" (its own to-do list [neogeo.cpp 26-27]). ## Not tried `-bios japan`, a multi-slot machine (`ng_mv4f`), Lua register taps on the LSPC, a trace through the eye-catcher (it ends before 20 s), and the diagnostics BIOS (`tests/test_roms/`, pinned) as a system ROM.