# MAME 0.285 as a detector MAME is tier 5: it finds differences and decides nothing. It is run as a **closed box**: the released binary (`mame` on PATH, or `$MAME`), never its source ([restart.md](restart.md), rule 1). Its source is not pinned or fetched. ## Why it is run inside a driver Its POKEY cannot be run on its own without building MAME's source against a stand-in, which would mean opening that source. So the device is asked questions where it lives: inside the `a5200` driver, through a probe cartridge. ## Recipe (run once, 2026-11-11, 4 s of wall time) MAME_ROMPATH=DIR python -I scripts/mame_pokey.py - Driver `a5200` (POKEY at `$E800-$E80F`, "Atari C012294 POKEY @ 1.78 MHz" in `-listdevices`). The BIOS is read in place from `a5200.zip` in `$MAME_ROMPATH`; it is never copied. - The script writes a 32K probe cartridge from a byte list (its own 6502 code; `$BFFD` = `$FF` makes the BIOS jump through `$BFFE` at once). - Flags: `-video none -sound none -nothrottle -noreadconfig -skip_gameinfo -debug -debugger none -log -seconds_to_run 2 -autoboot_script probe.lua`. The Lua sets two watchpoints (`wpset e800,10,w` and `,r`) that `logerror` the address, the data and `totalcycles`; `error.log` appears in the working directory, not under `-homepath`. - Output: `tests/mame_traces/pokey-probe/` (ignored): `error.log`, `summary.txt`. ## What it answered | Probe | MAME | Hardware / VHDL | | --- | --- | --- | | RANDOM after SKCTL = 3, 17-bit, reads at +4, +8, ... +32 | `FF FF FF 0F 00 00 F0 1F` | VHDL: `1F 01 00 E0 ...`; hardware `$1F` at +4 (9-bit) | | IRQST bit 0 after STIMER, AUDF1 = 1 | first low at +11 | +9 | | the same, AUDF1 = 5 | first low at +11 | +13 | | the same, AUDF1 = 0 | low already at +4, high +6 to +10, low from +11 | +8 | ## Traps 1. **Cycle offsets are not meaningful.** A read k cycles after a write did not behave like a device k clocks later: the identical "+11" for two different periods shows it (U13). Why is not known and is not investigated (that would need the source). Use MAME for what a register sequence does over thousands of cycles (which interrupts, which values, which sound), never for a latency. 2. ANTIC steals CPU cycles even with the display off, and MAME's ANTIC is not cycle-exact about which; the probe writes WSYNC before each measurement. 3. The first measurement of a series inherits the previous timer state (the AUDF1 = 0 row above): discard it. 4. A logerror action drops values past 14; `b@` reads in debugger expressions have no side effects (from the sibling boards). 5. MAME's audio samples are not a reference for the chip's output curve: nothing permitted establishes what its output stage models. 6. Arcade drivers clock the same device at 1.25 and 1.5 MHz (`-listdevices missile`, `centiped`); quad-POKEY boards are four `pokey` devices. ## Later use Rung 8 can record long register logs from real programs with this recipe through the sibling boards' own trace scripts and replay them into the core; MAME's own output is then compared only as a detector, per trap 1.