# MAME as a detector (tier 5) MAME 0.285 at `/usr/games/mame`, driver `n64` ("Nintendo 64 (NTSC)"), run as a closed box: its source is never opened (GPL-2.0+/BSD-3 mix). Devices (`mame -listdevices n64`): `maincpu` "NEC VR4300 (big) @ 93.75 MHz", `rsp` "Nintendo & SGI Reality Signal Processor RSP @ 62.50 MHz", `rcp`, `dac1`, `dac2`, `screen`. The romset `n64.zip` (read in place from `MAME_ROMPATH`) holds `pifntsc.bin` (2048 bytes, SHA-1 `9174eadc...`: Nintendo's PIF boot ROM, as MAME dumps it, 64 bytes longer than No-Intro's 1984-byte PIF images), and two 128-byte tables `normpnt.rom`, `normslp.rom` (RDP tables). Nothing from it is copied. ## The recipe that ran (2026-11-25) ```sh MAME_ROMPATH=... python -I scripts/mame_trace.py reference/src/krom-n64/CPUTest/CPU/ADD/CPUADD.N64 --frames 60 ``` The script writes a Lua autoboot script that sets a breakpoint at the cartridge's entry point (header word 0x08; `bpset 80001000,1,{trace ...;go}`) so that the trace **starts after IPL1-IPL3**, then traces `:maincpu` with `noloop` and an action `logerror "T pc at v0 ... ra hi lo totalcycles"`, and exits after N frames. Command line: `-video none -sound none -nothrottle -noreadconfig -skip_gameinfo -debug -debugger none -log -autoboot_script trace.lua -seconds_to_run 5`, under `nice` with a file-size limit. Result (MEASURED on this run): 1,374,700 trace lines in about 30 s wall time before the 400 MB cap stopped it; the first traced instruction is at 0x80001004 with the IPL3's handover state in the registers (for example `s6` = 0x3F, the CIC-6102 seed; `s4` = 1, the TV type; `sp` = 0xA4001FF0). **MAME's `totalcycles` advances by exactly one per instruction** (1,000,000 lines = 1,000,000 cycles), and the entry is reached at cycle 58,189,543 (about 0.62 s of emulated time after reset, MAME's figure, not hardware's). ## Traps (each met tonight) 1. **Register symbols are the ABI names** (`at v0 v1 a0..a3 t0..t9 s0..s7 k0 k1 gp sp fp ra`, `HI`, `LO`, `PC`, CP0 names such as `Status`, `Count`, FPU `FPR0`...); `r1`-style names do not exist and a trace action naming them prints nothing, silently. Listed with `manager.machine.devices[":maincpu"].state`. The RSP's symbols are `R0`-`R31`, `V0`-`V31`, `PC`, `SR`. 2. **Breakpoint addresses are 32-bit** (`80001000`); a sign-extended 64-bit address never hits, and the run exits early with an empty trace. 3. **Tracing from reset traces Nintendo's PIF ROM and IPL3.** The first run did that (409,804 disassembly lines into `T.trace`); it was moved unread into the ignored `trash/`. The default now starts at the entry point; `--from-reset` exists for boot studies and its output must never be committed or read as a source. 4. **The RSP trace showed only 20 instructions** over 4 emulated seconds of krom's RSPCPUADD (with and without `-nodrc`); the PC sat at 0x18. Not resolved: either the test starts the RSP in a way MAME's trace does not follow, or MAME's RSP tracing needs another option. The RSP's referee is therefore not MAME until this is understood (rsp-python Phase 0). 5. Test ROMs built with the old toolchains carry Nintendo's 6102 IPL3 (218 of the fetched ROMs: IPL3 CRC-32 `90bb6cb5`); libdragon builds carry its open IPL3. Both are only run. ## What it decides Register values after each instruction of real code, from a machine that boots: a detector for rungs 1-3 (results). Never timing (one cycle per instruction), never caches (MAME's mips3 core does not model the VR4300's caches as far as its output shows: to be measured with N64-Cache-Emulation-Tests run in MAME, U14).