# The MAME recipe (run 2026-11-26, MAME 0.285) MAME is a closed box here, tier 5, a detector. Its Plus/4 files carry `license:BSD-3-Clause` (checked through raw.githubusercontent.com at tag `mame0285`, the first 300 bytes of each file only): `mame/commodore/plus4.cpp`, `sound/mos7360.cpp/.h`, `cpu/m6502/m7501.cpp/.h`, `cpu/m6502/m6502.cpp`, `machine/mos6529.cpp`, `machine/mos6551.cpp`, `machine/6525tpi.cpp`, `machine/64h156.cpp`, `machine/6522via.cpp`, `bus/plus4/{c1551,exp,std,sid,user}.cpp`, `bus/cbmiec/c1541.cpp`, `lib/formats/cbm_tap.cpp`. The brief keeps MAME closed regardless of those lines: nothing was read beyond them and nothing was fetched (open decision 8). Its software lists `hash/plus4_cart.xml`, `plus4_cass.xml`, `plus4_flop.xml` are CC0-1.0 (their headers, read in the installed copies). ## Devices (`mame -listdevices plus4`) `u2` MOS Technology 7501 @ 894.88 kHz (PAL `plus4p`: 886.72 kHz); `u1` MOS 7360 TED @ 3.57 MHz (PAL 3.54 MHz); `u3` MOS 6551 ACIA; `u5`, `u27` MOS 6529; `u19` 82S100-series PLA; `exp` Plus/4 expansion port (options `c1551`, `sid`); `tape` with a `c1531`; IEC slots 4, 8-11 with a **1541 on device 8 by default**; `user` port (`diag264`, `rs232`); `joy1`, `joy2`; `mainirq` input merger. `c16`/`c116` lack `u3` and `u5`. With `-exp c1551`: a 6510T @ 2.00 MHz, two 6525 TPIs, a PLA and a 64H156 @ 16 MHz. All five drivers report a raster screen of 336 x 216 at "50.000000" Hz, the NTSC ones included (`mame -listxml`). ## Commands ```sh python -I scripts/mame_trace.py --snap 5 # untraced, PNG after 5 s (0.7 s wall) python -I scripts/mame_trace.py --snap 5 --driver c16p python -I scripts/mame_trace.py --frames 150 # 7501 traced, 3 s (15 s wall, 22 MB log) ``` The script passes `-rompath $MAME_ROMPATH -homepath -video none -sound none -nothrottle -noreadconfig -skip_gameinfo -log -iec8 "" -seconds_to_run N -autoboot_script run.lua`, plus `-debug -debugger none` when tracing. The Lua sets `debugger.visible_cpu` to `:u2`, issues `trace S.trace,:u2,noloop,{logerror "S %X %X %X %X %X %X %d\n",pc,a,x,y,p,sp,totalcycles}` and `wpset` write watchpoints on $0000 (2 bytes), $FF00 (64) and $FD00 (64); a frame notifier saves a snapshot and exits. One MAME process at a time, under `nice`, on CPUs 24-31. ## Results | Run | Result | | --- | --- | | `--snap 5` (plus4) | "COMMODORE BASIC V3.5 60671 BYTES FREE / 3-PLUS-1 ON KEY F1 / READY." 336 x 216 PNG | | `--snap 5` plus4p, c16p, c116 | boot to READY; C16: "12277 BYTES FREE" | | `--frames 150` (plus4) | **801,584 instructions in 2,684,654 CPU cycles** (3.35 cycles an instruction); first instruction at $FFF6 at cycle 8 (the reset vector's target); 1,387 watched writes | Watched writes, first ones (OBSERVED, detector): `$FF3E` (ROM on) at cycle 8; `$FD20 <- $09, $89` at 31 and 37 (unexplained, U10); the port `$0000 <- $0F`, `$0001 <- $08` at 343, 348; `$FD10 <- $FF` at 353; the TED block `$FF11..$FF19` at 416-830; `$FD30 <- $7F` then `$FF08 <- $7F` (the keyboard scan) from cycle 997; RAM test done by cycle 94,950 (`$FF3F` then `$FF3E`, timer and raster set-up, bank probing `$FF3E/$FF3F` pairs). ## Traps met 1. **MAME's screen rate.** Every Plus/4-family driver reports 50.000 Hz, NTSC too, so "frames" in MAME are not TED frames. Count CPU instructions or cycles, never MAME frames. 2. **MAME's cycle counter runs at the single-clock rate.** 2,684,654 cycles in 3.000 s of its screen = 894,885 a second, exactly 14,318,180 / 16. Whether MAME models the double clock some other way is not visible from outside; its `totalcycles` cannot be used to judge the single/double-clock timing (ted.md). Use it for the instruction stream and the order of register writes only. 3. The default 1541 on device 8 runs a second 6502 unless removed: `-iec8 ""` removes it (tested: the boot is unaffected). 4. `listroms plus4` includes the default drive's ROMs and third-party KERNAL/DOS options (JiffyDOS and others); the census names them. 5. `-seconds_to_run` takes whole seconds; the Lua frame notifier stops the run.