# The MAME recipe (run 2026-11-26, MAME 0.285) MAME is a closed box here: run, never read (brief: its Sega files' licences are checked by their `license:` lines only, [sources.md](sources.md)). It is a tier-5 detector. One MAME process at a time, a few emulated seconds per run, `nice` and `taskset -c 24-31`. ## Devices (`mame -listdevices`) | Machine | Board | Devices and clocks MAME declares | | --- | --- | --- | | `shinobi` | 16A | `maincpu` MC68000 @ 10.00 MHz; `soundcpu` Z80 @ 4.00 MHz; `upd7751` NEC uPD7751 @ 6.00 MHz with `upd7751_8243` Intel 8243; `ymsnd` YM2151 @ 4.00 MHz; `dac` 8-bit R-2R; `i8255` PPI; `soundlatch`; `watchdog`; `sprites` "Sega System 16A Sprites"; `segaic16vid` | | `altbeast` | 16B | MC68000 @ 10.00 MHz; `mapper` "Sega 315-5195 Memory Mapper" @ 10.00 MHz; `mcu` Intel 8751 @ 8.00 MHz; Z80 @ 5.00 MHz; `ym2151` @ 4.00 MHz; `upd` uPD7759 @ 640 kHz; `netlist` (the analog stage); `screen` @ 6.29 MHz; `sprites` "Sega System 16B Sprites" | | `shdancer` | 18 | MC68000 @ 10 MHz; 315-5195 mapper; `io` Sega 315-5296 @ 16 MHz; Z80 @ 8 MHz; `ym1`, `ym2` YM3438 @ 8 MHz; `rfsnd` RF5C68 @ 10 MHz; `gen_vdp` 315-5313 @ 15 MHz with its PSG @ 1 MHz | | `outrun` | Out Run | two MC68000 @ 10 MHz (`maincpu`, `subcpu`); 315-5195; Z80 @ 4 MHz; YM2151; `pcm` Sega PCM @ 4 MHz; `segaic16road`; ADC0804; i8255 | ## The commands ```sh python -I scripts/mame_trace.py shinobi --snap 20 # untraced, PNG at frame 1200 python -I scripts/mame_trace.py shinobi --frames 3 # the 68000, 3 frames python -I scripts/mame_trace.py goldnaxe --frames 3 --cpu mcu # the 8751 python -I scripts/mame_trace.py goldnaxe --frames 3 --cpu sound # the Z80 python -I scripts/mame_trace.py goldnaxe --frames 40 --watch 0,1000000 # every 68000 write ``` 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 Lua script sets `manager.machine.debugger.visible_cpu`, issues `trace S.trace,,noloop,{logerror "S %X ... %d\n",,totalcycles}` and, with `--watch`, `wpset ,,w,1,{logerror "W %X %X %X %d\n",wpaddr,wpsize,wpdata,totalcycles; g}`; a frame notifier saves a snapshot and exits. Register symbols that worked: 68000 `pc,sr,d0,a7`; Z80 `pc,af,sp`; 8751 `pc,acc,sp`. ## What came out (OBSERVED in MAME; a detector's numbers, not hardware's) | Run | Wall | Result | | --- | ---: | --- | | `shinobi --snap 20` | 1.7 s | 1200 frames at 1554% speed; the attract screen with the SHINOBI logo and SEGA 1987 | | `shinobi --frames 3` (68000) | 1.2 s | 42,574 instructions in 499,994 cycles: 11.7 cycles an instruction; first PCs 0x402, 0x410, 0x418 (SR 0x2700) | | `shinobi --frames 3 --watch ffc000,4000 --watch c40000,4000` | | 8,372 writes; the 68000 programs the 8255 at reset: C40007 = C0 (control), C40003 = 00 (port B), C40005 = 07 (port C, the value CMP16 says every game writes) | | `goldnaxe --frames 3` (68000) | 1.5 s | **38 instructions**, then nothing: the 68000 is held (CM18: the 8751 can halt the 68000, presumably while it checksums the ROM; CMP16 describes Body Slam's MCU doing exactly that) | | `goldnaxe --frames 3 --cpu mcu` | 1.8 s | 25,786 8751 instructions in 33,301 machine cycles (8 MHz / 12 = 666,667 machine cycles a second, so 11,100 a frame) | | `goldnaxe --frames 3 --cpu sound` | 1.5 s | 20,831 Z80 instructions in 249,763 cycles at 5 MHz: 12.0 cycles an instruction | | `goldnaxe --frames 60` (68000) | 14.5 s | 674,946 instructions, 8,247,667 cycles at frame 60 (the first frames held by the MCU); 12.2 cycles an instruction; MAME's mapper logs "Unknown memory_mapper_w to address 00/01" about 480 times | | `goldnaxe --frames 40 --watch 0,1000000` | | 116,339 68000 writes, **none** to a 315-5195 register window (FE00xx, FF00xx, C000xx); text RAM at 0x100000-0x10FFFF, sprites near 0x500000, I/O at C40001/C43007. Read with the MCU's halt: in this set the memory map seems to be set up by the 8751 (HYPOTHESIS; MAME's model, unopened) | | `goldnaxe1 --frames 3` and `goldnaxe1d --frames 3` | | 43,030 instructions each; the two traces (PC, SR, D0, A7, totalcycles) are **byte-identical**: MAME's FD1094 set and its decrypted set are the same machine to its 68000 | ## Traps met - Non-merged sets: the zip name is the machine name; no parent zip is needed. - `-cfg_directory`/`-nvram_directory` inside the run directory keep MAME from writing its NVRAM (high scores, the 8751's state) into a shared place between runs. - The 16B sets log "[:upd] ROM region ':upd' not found" (slave-mode uPD7759: no ROM on the chip side; CMSND) and the netlist solver lines: noise. - A watchpoint range is in the 68000's 24-bit space; `0,1000000` watches everything (a 40-frame run made 116 k lines; keep it short). - `S.trace` (the debugger's disassembly) is deleted after a run; `run.log` has the state. ## Output `reference/mame/-/` and `reference/mame/-snap/` (git-ignored): `run.log`, `stdout.txt`, `run.lua`, `snap//*.png`.