# The MAME recipe (run 2026-11-26, MAME 0.285) MAME is a closed box here. Its CPC driver (`src/mame/amstrad/amstrad.cpp`, `amstrad_m.cpp`, `amstrad.h`) is **GPL-2.0+** by its `license:` lines (read through raw.githubusercontent.com byte ranges 0-160 at tag `mame0285`, nothing else of the files fetched): only the installed binary is run. The devices it uses are BSD-3-Clause by their lines (`video/mc6845.cpp` Wilbert Pol, Nigel Barnes; `machine/i8255.cpp` Curt Coder; `machine/upd765.cpp` Olivier Galibert; `bus/cpc/cpcexp.cpp` Barry Rodewald; `imagedev/cassette.cpp`; `formats/tzx_cas.cpp`) but are not fetched either: MAME's devices model generic chips, not the CPC's types. Tier 5: a detector of I/O order and values; **not** a judge of timing (cpu-core.md) or of CRTC types (crtc-6845.md). ## Devices (`mame -listdevices `) | Driver | CPU | Video | Others | | --- | --- | --- | --- | | `cpc464` | Zilog Z80 @ 4.00 MHz | "Hitachi HD6845S CRTC @ 1.00 MHz", screen @ 16.00 MHz | AY-3-8912A PSG @ 1.00 MHz, Intel 8255 PPI, cassette, expansion port @ 4.00 MHz, Centronics | | `cpc6128` | as above | as above | plus "NEC uPD765A FDC @ 4.00 MHz", floppy list | | `cpc6128p` | as above | "AMS40489 ASIC (CRTC) @ 1.00 MHz" | "Amstrad AMS40489 PPI", cartridge slot (`gx4000` list), uPD765A | MAME fixes the CRTC part per driver (HD6845S on the 464/6128); it offers no CRTC-type choice in its device list, so types 1 and 2 are not available as a detector. ## The commands ```sh MAME_ROMPATH=... python -I scripts/mame_trace.py --driver cpc6128 --seconds 3 MAME_ROMPATH=... python -I scripts/mame_trace.py --driver cpc464 --seconds 2 --trace 0.04 python -I scripts/mame_summary.py reference/mame/cpc6128 ``` `mame_trace.py` runs `nice taskset -c 24-31 mame -rompath $MAME_ROMPATH -homepath -snapshot_directory /snap -video none -sound none -nothrottle -noreadconfig -skip_gameinfo -log -seconds_to_run N -autoboot_script run.lua`, plus `-debug -debugger none` with `--trace`. The Lua installs a write tap and a read tap on the Z80's `io` space at script start (held in globals) that write `O|I port value seconds` lines to `io.log`; with `--trace` it issues `trace T.trace,:maincpu,noloop,{logerror "T %X %d\n",pc,totalcycles}` and turns it off after the given emulated seconds; a frame notifier stops the run by emulated time (`manager.machine.time`), saves a snapshot and exits. Output stays in the git-ignored `reference/mame//`. ## Runs made (2 MAME processes in all, one at a time; each under 1 s of wall time) 1. `cpc6128`, 3 emulated seconds: 6,504 I/O accesses. The snapshot shows "Amstrad 128K Microcomputer (v3) / ©1985 Amstrad Consumer Electronics plc and Locomotive Software Ltd. / BASIC 1.1 / Ready". 2. `cpc464`, 2 emulated seconds with a 0.04-second trace: 4,033 I/O accesses, 14,580 trace lines. ## What the runs showed (OBSERVED) - **Boot order** (both models): `F782 <- 82` (PPI: A out, B in, C out) at 16 µs; `F4xx <- 00`, `F6xx <- 00`; the Gate Array `7Fxx <- 89` (RMR: upper ROM off, mode 1) and `C0` (bank code 0, on the 6128 too where it reaches the PAL); then the CRTC from **R15 down to R0** between 67 and 337 µs, at 18-µs intervals, with R0 = 63, R1 = 40, R2 = 46, R3 = &8E, R4 = 38, R5 = 0, R6 = 25, R7 = 30, R8 = 0, R9 = 7, R12/R13 = &3000, R14/R15 = &C000: ap12 D's PAL column and ACCC 4.1's note (starts 64 µs after the first instruction, R15 first). Then `DFxx <- 00` (upper ROM 0) at 365 µs and, on the 6128, `FA7E <- 00` (motors off) at 387 µs. - **AY access** through the PPI: register number on port A, port C `C0` then `00`; data on port A, port C `80` then `00`; the keyboard scan selects AY register 14, sets the PPI to `92` (port A input), then writes port C `40`+row (BDIR/BC1 = read, keyboard row) and reads port A, row by row (108 such scans of row 0 in the 6128's 3 s; every read FF with no key down). - **RMR values** seen: `81`, `85`, `89` (bit 4 never set by the firmware in 3 s). - **Gate Array traffic**: 2,516 writes on the 6128 in 3 s, mostly the RMR (1,937: the firmware toggles the ROM enables) and the palette (289 pen selects, 289 colours: the firmware's per-frame ink refresh, KT `garray`'s note). - **FDC** (6128): 3 status reads, 3 data writes, 2 motor writes in 3 s with no disc. - **Timing** (464 trace): instruction lengths in MAME's `totalcycles` are not aligned to 4 T-states for 30 % of instructions (cpu-core.md). MAME's timing is not used. ## Traps met - The frame notifier fires at host-frame rate under `-video none`: stop by emulated time. - `-seconds_to_run` takes whole seconds; the script adds 5 and stops from Lua. - MAME prints an ALSA sequencer permission error under `-sound none`; harmless.