# MAME as an oracle: the recipe that ran MAME 0.285 (`/usr/games/mame`; source pinned at `mamedev/mame` @ `f379cd06`, the commit the `mame0285` tag points to) emulates both processors in `src/devices/cpu/jaguar/jaguar.cpp` (Aaron Giles, BSD-3-Clause) as devices `jaguargpu` and `jaguardsp`, used by the console driver `jaguar` and by the CoJag arcade boards in `src/mame/atari/jaguar.cpp`. **Emulator tier**: it detects differences in the order of execution and in register results; it cannot judge timing (one count per instruction, +3 for a taken jump, DIV instant, no pipeline, no scoreboard, interrupt entry instant; [timing.md](timing.md)). ## The command `scripts/mame_trace.py` builds it, runs it in a fresh directory under `tests/mame_traces/-/` (gitignored) and leaves `error.log`: ```sh python -I scripts/mame_trace.py jaguar --cpu gpu --seconds 2 python -I scripts/mame_trace.py jaguar --cpu dsp --seconds 4 --max-mb 16 \ --cart "$NO_INTRO_DIR/Atari - Atari Jaguar (J64)/Tempest 2000 (World).zip" python -I scripts/mame_trace.py fishfren --cpu gpu --seconds 3 --max-mb 16 ``` Underneath (cwd = the output directory): ```sh mame jaguar -rompath "$MAME_ROMPATH;$MAME_CHDS" \ -video none -sound none -nothrottle -noreadconfig -skip_gameinfo \ -debug -debugger none -log -autoboot_script trace.lua -seconds_to_run N [-cart FILE] ``` with `trace.lua`: ```lua local dbg = manager.machine.debugger dbg.visible_cpu = manager.machine.devices[":gpu"] -- or ":dsp" dbg:command('trace cpu.trace,,noloop,{logerror "%X %X\\n",curpc,flags}') dbg:command("go") local frames = 0 stop_sub = emu.add_machine_frame_notifier(function() -- held in a global, or it is collected frames = frames + 1 if frames == 120 then manager.machine:exit() end end) ``` `error.log` gets one line per instruction, before it executes: `PC FLAGS` (add `--registers` for R0-R31; **untested**). `cpu.trace` gets MAME's own disassembly of the same instructions. ## Runs (2026-11-11 and 2026-11-12) | Run | Result | | --- | --- | | `jaguar --cpu gpu --seconds 2`, no cartridge | 34,840 instructions, 1.7 s wall, all in `F03xxx`. The GPU starts at `F032EC` (`movei $f03314,r29; movei $800000,r0; ...`), the boot ROM's cartridge check reading `800000`; with no cartridge the check fails (the board's notes: red screen at 2 s) | | `jaguar --cpu dsp --seconds 4 --max-mb 16`, Tempest 2000 (World) | 1,406,913 instructions before the 16 MB cap, all in `F1Bxxx`; the DSP starts at `F1B000: movei $f1b030,r0 / jump (r0) / nop`; it never idles | | `fishfren --cpu gpu --seconds 3 --max-mb 16` (CoJag, R3041 at 20 MHz, GPU/DSP at 26 MHz; no CHD needed) | exit 0 after 5.8 s; 54 GPU instructions: the same 27-instruction setup at `F03508`-`F03554` run twice (`move pc,r21`, `moveta` into the other bank, `movei $fff02100,r21`, `load (r21),r22; bset $e,r22; store r22,(r21); nop; nop` i.e. REGPAGE set with **two NOPs after the FLAGS store**, the bugs sheet's rule, C1). Nothing more in 3 s (the game waits on hardware MAME's run did not give it) | ## Traps - **The trace action's symbols resolve against the visible CPU**: set `dbg.visible_cpu` to `:gpu`/`:dsp` first, or `logerror` prints nothing while `cpu.trace` still fills (found by the board's Phase 0). - **Delay slots are logged with the jump's address.** In `error.log`, `curpc` for the instruction in a delay slot is the jump's PC (MAME executes the slot inside the jump handler); `cpu.trace` shows the slot's real address. Seen in both traces: GPU `F0332A jr nz` is followed by a second `F0332A` line where `cpu.trace` has `F0332C: rorq $8,r13`; DSP `F1B006 jump` twice where `cpu.trace` has `F1B008: nop`. A replay must pair the two files, or treat a repeated PC after a jump as the slot. - **FLAGS is MAME's `m_flags`**: Z C N in bits 0-2 and the enables and REGPAGE as last written; **IMASK is held separately (`m_imask`) and is not in it**; the latches are not in it either. - Register symbols: `PC`, `FLAGS`, `R0`-`R31` (current bank only), `totalcycles`. - A DSP that never idles logs about 2.7 million lines per emulated second, and MAME under the debugger runs far below real time: cap by size (`--max-mb`). MAME under `-debug -debugger none` was seen ignoring SIGTERM on 2026-11-11 (two runs at once for three minutes, both killed with SIGKILL); the script now sends SIGTERM, waits 5 s, then SIGKILL. **One MAME at a time.** - The GPU does not start until the 68000 sets GO (about 1.15 s on the console boot), so a 1 s run shows nothing. - `-log` also records Tom/Jerry register writes by the main CPU (`TOM write register @ F00002 = 35DD`), which interleave with the trace lines; filter on lines starting with `F0`/`F1`. ## What it is good for here - Rung 3 (replay): the boot ROM's GPU program (34,840 instructions with no cartridge, deterministic) and a game's DSP loop give an order-of-execution record a core can follow instruction by instruction, comparing PC and flags (and registers with `--registers`) after each. Differences are leads, decided by the netlist where it speaks. - It cannot judge: anything about ticks, stalls, interrupt entry timing, the bugs (B1, B2, B5, B7, B13 never happen in MAME), carry after logic and multiply (C4), or the DSP's undefined opcode. ## Other places MAME is used - `mame -listxml jaguar` / `fishfren`: clocks (26,590,906 Hz console, 26 MHz CoJag), CPU tags. CoJag sets present locally: area51 family, maxforce family, vcircle, fishfren, freezeat and its revisions; fishfren and freezeat need no CHD ([census.md](census.md)).