# The MAME oracle: logging what a CPS-1 program says to its MSM6295 MAME 0.285 (`/usr/games/mame`) is a detector (tier 5). This recipe logs every access the sound Z80 of a CPS-1 board makes to the chip, with its time in chip clocks, so a later rung can replay the writes into the core and into MAME's own device and compare what comes out. It was run on 2026-11-11 and again on 2026-11-12 with the same result. ## The command python3 -I scripts/mame_oki_tap.py ffight --seconds 40 which runs, from `reference/mame-run/ffight/` (ignored): mame ffight -rompath "$MAME_ROMPATH" \ -homepath . -cfg_directory cfg -nvram_directory nvram -snapshot_directory snap \ -video none -sound none -nothrottle -noreadconfig -skip_gameinfo \ -seconds_to_run 40 -autoboot_script ../../../scripts/mame_oki_tap.lua 40 emulated seconds in about 3.8 s of wall time. No `-debug` is needed: the taps are Lua memory taps, not debugger traces. One MAME process; nothing else runs. ## The Lua tap (`scripts/mame_oki_tap.lua`) CPS-1 maps the chip in the sound Z80's program space (`cps1.cpp` lines 657-659): `$F002` read status / write command, `$F006` write bit 0 = pin 7. The script installs a write tap on `$F002-$F006` and a read tap on `$F002`, and writes one line per access to `oki-tap.log`: # clock kind value 12032 P 1 15092 W 78 85483 R F0 The clock is `machine.time:as_ticks(1000000)`: the chip's 1 MHz clock on CPS-1 (16 MHz / 4 / 4). Kinds: `W` command byte, `R` status byte as MAME's device answered it, `P` pin 7 written. To get sound out of the attract mode the script inserts a coin at frame 240, presses start at 360 and button 1 for 12 frames of every 60 from frame 480. Notes for MAME 0.285's Lua: `space:install_write_tap(lo, hi, name, fn)` with `fn(offset, data, mask)`; `emu.add_machine_frame_notifier`; the input fields are `:IN0` "Coin 1", "1 Player Start", `:IN1` "P1 Button 1". The taps, the notifiers and the file handle are held in globals, or MAME's Lua collects them. ## What the run showed (Final Fight, 40 s) 50712 accesses: P 1, W 49, R 50662 pin 7 writes: [(12032, 1)] play commands: 15, second byte after 4-13 clocks channel masks: {8: 4, 1: 9, 2: 2} (one channel bit each time) attenuations: {0: 4, 3: 11} phrases: [54, 55, 66, 67, 69] stop commands: 78 x3, 40 x2, 08 x10, 10 x3, 20 x1 status reads: F0 37602, F1 852, F2 696, F3 468, F8 9888, FA 984, FB 172 - At power-on the Z80 sets pin 7 high, then writes `78` (stop all four). - The two bytes of a play are 4 to 13 µs apart: inside the '94 data sheet's >= 500 ns, outside the 1987 sheet's 7,500 ns (C3). - The shortest gap from one command to the next was 82 clocks (stop to stop); play to play 161 clocks, stop to a play 274 clocks: all inside the data sheet's 75 tCYC and "more than one sample" (132 clocks at pin 7 high). - The driver never sets two channel bits, never plays phrase 0, never plays on a channel whose BUSY bit the last status read showed set (all 15 plays checked). - The Z80 polls the status about four times every 3 ms; bits 7-4 always read 1 (MAME's convention). A 30-second run of `sf2` wrote only pin 7 and six `78` stops (the attract mode is silent and the script's inputs did not start a game there). ## What it is for - The write streams (with times) are the input of the whole-chip rung: replay them into the core and into MAME's device, compare the four channels' values sample by sample. - The status reads record what MAME answered, which is MAME's model of BUSY, not the chip's (U8). A program whose control flow depends on BUSY may take a different path on hardware; the replay must therefore feed writes, not re-run the program, when comparing with MAME. - The tap is CPS-1 specific (addresses, clock). Other boards need their own addresses; the pattern is the same.