# The MAME recipe (run 2026-11-26, MAME 0.285) MAME is a closed box here, tier 5, a detector. Its PET files carry `license:BSD-3-Clause` (checked tonight through raw.githubusercontent.com at tag `mame0285` (tag object `3bd358f`), **the first 300 bytes of each file only**): `mame/commodore/pet.cpp`, `cbm2.cpp`, `cbm_snqk.cpp`; `devices/bus/ieee488/{ieee488,c2031,c2040,c2040fdc,c8050, c8050fdc,c8280}.cpp`; `devices/machine/{6522via,6821pia,mos6526,6525tpi,mos6551,pla}.cpp`; `devices/video/mc6845.cpp`; `devices/bus/pet/{exp,superpet,user,cass,c2n,64k,hsg}.cpp`; `devices/bus/cbm2/exp.cpp`; `devices/cpu/m6502/m6502.cpp`, `cpu/m6809/m6809.cpp`; `devices/sound/mos6581.cpp`; `lib/formats/{d80_dsk,d82_dsk,c3040_dsk,c4040_dsk,cbm_tap}.cpp`. (`mame/commodore/pet.h` does not exist at that tag: 404.) The brief keeps MAME closed regardless: nothing beyond those header lines was read, nothing fetched (open decision 10). ## Devices (`mame -listdevices`) - `pet2001`, `pet2001n`, `pet4032`: `f3` MOS 6502 @ 1 MHz; `a5` MOS 6522 VIA; `b8`, `g8` 6821 PIA (MAME models the 6520 as its 6821); no CRTC; screen "@ 4.00 MHz"; IEEE slots 4, 8-15 with **a 4040 on device 8 by default** (`un1` 6502, `uh3` 6504, `uc1`/`ue1` 6532, `uk3` 6530, `um3` 6522, "2040 FDC" @ 16 MHz); two datasette ports; user port; quickload. - `pet4032f`: adds `ub13` Motorola MC6845 @ 1 MHz, a speaker ("Filtered DAC"). - `cbm8032`, `pet8032`, `superpet`: `ub13` Synertek SY6545-1 @ 1 MHz, speaker, an **8050** on device 8 by default; `superpet` adds `exp:superpet:u4` MC6809E @ 1 MHz. - `cbm8296`: adds `ue5`, `ue6` 82S100 PLAs and an 8250. - `cbm610`, `p500`: see cbm-ii.md. - Screens (`-listxml`): CRTC-less drivers 320 x 200 at **62.5 Hz**, 4 MHz pixel clock (a legacy fixed frame); `pet4032f` 400 x 333 at 8 MHz, 60.06 Hz; `pet8032` 800 x 333 at 16 MHz, 60.06 Hz; `cbm8296` 944 x 339, 49.9975 Hz. ## Commands ```sh python -I scripts/mame_trace.py --snap 4 --driver pet2001 # untraced, PNG after 4 s python -I scripts/mame_trace.py --snap 4 --driver pet2001n python -I scripts/mame_trace.py --snap 4 --driver pet4032 python -I scripts/mame_trace.py --snap 4 --driver cbm8032 python -I scripts/mame_trace.py --frames 120 --driver pet2001n # 6502 traced (8 s wall, 17 MB log) python -I scripts/mame_trace.py --frames 120 --driver cbm8032 ``` The script passes `-rompath $MAME_ROMPATH -homepath -video none -sound none -nothrottle -noreadconfig -skip_gameinfo -log -ieee8 "" -seconds_to_run N -autoboot_script run.lua` (plus `-debug -debugger none` when tracing), under `nice` and `taskset -c 24-31`. `-ieee8 ""` detaches the default drive (it worked: no drive CPU in the runs). The Lua sets `debugger.visible_cpu` to `:f3`, sends the disassembly trace to `/dev/null` with a `logerror` action that writes `S pc a x y p sp totalcycles` into `error.log`, sets write watchpoints on $E810 (4), $E820 (4), $E840 (16) and $E880 (2), and a frame notifier saves a snapshot and exits. One MAME process at a time. ## Results | Run | Result | | --- | --- | | `--snap 4 --driver pet2001` | "### COMMODORE BASIC ### / 3071 BYTES FREE / READY." (BASIC 1, 4K), 320 x 200 | | `--snap 4 --driver pet2001n` | "*** COMMODORE BASIC *** / 7167 BYTES FREE" (BASIC 2, 8K) | | `--snap 4 --driver pet4032` | "*** COMMODORE BASIC 4.0 *** / 31743 BYTES FREE" (32K), 320 x 200 | | `--snap 4 --driver cbm8032` | "*** commodore basic 4.0 *** / 31743 bytes free / ready." in lower case, 815 x 391 PNG | | `--frames 120 --driver pet2001n` | **628,616 instructions in 1,919,997 cycles** (3.05 per instruction); first instruction at $FCD1 (the reset target) at cycle 8; 2,427 I/O writes | | `--frames 120 --driver cbm8032` | **713,437 instructions in 2,293,028 cycles** (3.21); first instruction at $FD16; 36 CRTC writes (R17 down to R0, the 901474-04 values: video.md); PIA1 CRB re-armed every 19,992 cycles | From the `pet2001n` watchpoints (OBSERVED): cycle 22 VIA IER=$7F; from cycle 1,036 PIA1 PA=$0F, VIA ORB=$1E, DDRB=$1E, PIA2 ORB=$FF, VIA T1 high $FF, PIA1 CRB=$3D, PIA2 CRA/CRB=$3C, PIA1 CRA=$3C, VIA PCR=$0C; then at every interrupt (every 16,666-16,667 cycles, the first after 15,758) PIA1 CRB=$3D and the keyboard scan stepping PIA1 PA from $F0 to $F9, each step written twice in one cycle-count (the read-modify-write's dummy write, io.md). ## Traps met - **MAME's frames are not the PET's frames.** The CRTC-less drivers run a 62.5 Hz legacy screen (16,000 cycles) while the KERNAL's interrupt comes every 16,666 cycles; on CRTC drivers the frame follows the CRTC (19,992 cycles with the 50 Hz editor in `cbm8032`). Count by CPU cycles. - `cbm8032` uses the 50 Hz editor 901474-04, `pet8032` the 60 Hz 901474-03: pick the row by the editor, not the name. - The default drive on device 8 runs two more CPUs in every run unless `-ieee8 ""`. - Snapshots land in `snap//0000.png`. - ALSA prints a sequencer permission error on this machine with `-sound none`: harmless.