# MAME as a detector: the headless recipe, as run MAME 0.285 (`/usr/games/mame`), driver `jaguar`. Tier 5: a **detector**, never a judge. Its own flags for the console: preliminary, unemulated protection, imperfect graphics and sound; of the 102 entries in its `jaguar` software list, 89 are marked "no" and 11 "partial" (`-listxml`, 2026-11-11). It is still useful: it runs the **real boot ROM** and boots *Tempest 2000* to its title screen through it, its 68000 is cycle-counted, and its `-log` records every Tom and Jerry register write by the 68000. Encoded in `scripts/mame_trace.py`. Every run gets a fresh, git-ignored directory `tests/mame_traces//` (the script refuses to overwrite one). ## Commands that ran ```sh python3 -I scripts/mame_trace.py --seconds 2 # 68000, no cart: 57 s wall, 2.1 M lines python3 -I scripts/mame_trace.py --cpu gpu --seconds 2 --name X # GPU, no cart: 34,840 instructions python3 -I scripts/mame_trace.py --cart "" --no-trace --seconds 12 # snapshot only python3 -I scripts/mame_trace.py --cpu gpu --cart "" \ --frames 200,202 --seconds 4 --name t2k-gpu-frames-200-202 # 2026-11-12 python3 -I scripts/mame_trace.py --cpu dsp --cart "" \ --frames 200,201 --seconds 4 --name t2k-dsp-frames-200-201 # 2026-11-12 ``` The MAME command line the script builds (cwd = the run directory): ```sh mame jaguar -rompath "$MAME_ROMPATH" \ -homepath -snapshot_directory snap -video none -sound none -nothrottle -noreadconfig \ -skip_gameinfo -seconds_to_run [-cart ] \ -debug -debugger none -log -autoboot_script /trace.lua ``` The Lua script, whole-run form: ```lua local dbg = manager.machine.debugger dbg.visible_cpu = manager.machine.devices[':gpu'] -- or ':maincpu', ':dsp' dbg:command('trace cpu.trace,:gpu,noloop,{logerror "G %X %X ...\\n",pc,flags,r0,...,totalcycles}') dbg:command('go') ``` Frame-window form (`--frames A,B`): the same, but the `trace` command is issued from a frame notifier when the frame counter reaches A and `trace off,:` at B; the notifier is held in a global (`frame_tap = emu.add_machine_frame_notifier(...)`) or Lua collects it. **Tested 2026-11-12**: frame notifiers fire under `-video none`; frames 200-202 of *Tempest 2000* start at GPU `totalcycles` 88,581,332 (3.33 s). Trace line formats: `M PC SR D0 D1 A0 A1 A7 totalcycles beamy beamx frame` for the 68000; `G|D PC FLAGS R0 R1 R2 R3 R28 R29 R30 R31 totalcycles` for the GPU and DSP. ## What the runs showed | Run | Result | | --- | --- | | no cart, 68000, 2 s | the boot sequence of [memory-map.md](memory-map.md): MEMCON1 `$1861`, MEMCON2 `$35CC`, the NTSC time base, ROM copied to RAM, DSP program loaded, `G_CTRL` written at 68000 clock 15,286,586 (about 1.15 s); red screen, 68000 at `$50B8` | | no cart, GPU, 2 s | 34,840 instructions, all in `F03xxx`, from `F032EC`: the cartridge check reading `800000` | | *Tempest 2000*, snapshot, 12 s | title screen, through the real boot ROM; snapshot 713 pixels wide (642 for the boot screen: `PWIDTH` changes the width) | | *Tempest 2000*, GPU, frames 200-202 | 290,535 instructions in two frames, all from `F03xxx` (GPU local RAM); about 145,000 per frame | | *Tempest 2000*, DSP, frame 200 | 306,894 instructions in one frame, all from `F1Bxxx` (DSP local RAM); about 18 M per second at 60 Hz | The last two are **workload numbers for the cost estimate** ([start-here.md](start-here.md)): in this game the DSP executes more instructions than the 68000 and GPU together. MAME's JRISC is not cycle-timed (one count per instruction, +3 for a taken jump, divide instant: jrisc-python's reading of `cpu/jaguar/jaguar.cpp`), so its counts are instructions, not clocks. ## Traps 1. **The trace action's symbols resolve against the visible CPU.** For `gpu`/`dsp` set `dbg.visible_cpu` first, or `logerror` prints nothing while `cpu.trace` still fills. 2. JRISC register symbols: `PC`, `FLAGS`, `R0`-`R31` (current bank only), `totalcycles`; `IMASK` is not in `FLAGS` (jrisc-python's note). 3. `-log` also records every Tom and Jerry register write made **by the 68000** (`TOM write register @ F00028 = 06C1`), not those made by the GPU or DSP. 4. The GPU starts only at about 1.15 s: a 1 s run shows no GPU lines. 5. Size: a 68000 trace is about 67 MB per emulated second, written twice (`error.log` and `cpu.trace`); a busy DSP about 2.7 M lines per second. Use `--frames`. The GPU window of two frames above was 19.7 MB of `error.log`, the DSP frame 16.6 MB. 6. Under `-debug -debugger none` MAME ignores SIGTERM (jrisc-python's finding): stop a runaway with SIGKILL, and cap runs with `-seconds_to_run`. 7. Snapshot width varies with `PWIDTH` (642 and 713 seen); compare pictures as line-buffer values where possible, not as PNGs. 8. MAME copies the first `$400` bytes of the boot ROM into RAM at reset instead of modelling the ROM mirror that lasts until MEMCON1 is written ("do not increase, or Doom breaks", `machine_reset`), and pokes `$FFFFFFFF` into shared RAM at `$804` for *Battle Sphere* (`machine_start`, "depends on what shared RAM contains at power on and what's the actual blitter status when going idle"). Lockstep comparisons must expect differences there. 9. MAME's vector for every 68000 interrupt is `$40` only on **level 2** (`cpu_space_map`); its other levels autovector. Only level 2 is used by the console. 10. One MAME process at a time on this machine; each run above took under a minute of wall time. ## What MAME can and cannot decide Can **detect**: instruction-level divergence of the 68000 (lockstep from reset through the boot ROM), register-write sequences of the boot ROM and of games (from `-log`), whether a game reaches a given screen, where a GPU/DSP program runs and roughly how much. Cannot **decide**: anything about bus contention, blitter or Object Processor timing, the JRISC pipeline, the CRY tables (its green table has 4 transcription errors, [video.md](video.md)), or the lock ([memory-map.md](memory-map.md)).