# MAME 0.285 as a detector: the recipe that was run MAME 0.285 (`/usr/games/mame`; source pinned at tag `mame0285`, `f379cd06`, sparse in `reference/src/mame`) is a **detector** for this board, never a judge ([validation.md](validation.md)). Everything here was run on 2026-11-11 with the machine under heavy load (load average near 59); `scripts/mame_trace.py` encodes it. ## Drivers, devices, ROM sets `mame -listxml coleco`: `maincpu` Z80 @ 3,579,545 Hz, `tms9928a`, `sn76489a` @ 3,579,545 Hz, `cartslot`, `exp` (one option: `sgm`, "Opcode Super Game Module"), two software lists (`coleco`, `coleco_homebrew`), screen 342 x 262 at 5,369,317 Hz pixel clock, visible 280 x 216, 59.922738 Hz. Clones `colecop` (PAL, TMS9929A) and `onyx`; relatives `czz50`, `dina`, `prsarcde`, `bit90`, `adam`. **The driver needs the BIOS**: `coleco.zip` holds `313_10031-4005_73108a.u2` (SHA-1 `45bedc4c...`), `colecop.zip` holds `r72114a_8317.u2`. `--rompath` defaults to `$MAME_ROMPATH` (a local copy of MAME's non-merged sets), read in place. What the driver models that matters for timing (`coleco.cpp` l.566-582): **one extra clock on every M1 cycle** (`z80_set_m1_cycles(4+1)`) and **the SN76489A's READY on the Z80's WAIT line**. Its spinner pulse widths are marked "TODO: measure duration" (11 microseconds for `/INT`, 500 for bit 7). Its TMS9928A is line-based with no CPU access windows and no status-read race. ## The recipe ```sh python -I scripts/mame_trace.py coleco --seconds 2 # the BIOS alone python -I scripts/mame_trace.py coleco "tests/runs/carts/Zaxxon (USA, Europe).col" --seconds 5 --no-trace python -I scripts/mame_trace.py colecop CART.zip --seconds 3 python -I scripts/mame_trace.py coleco CART.rom --exp sgm # not run here: no SGM image in the library ``` which runs, in a new `tests/mame_traces/-/` (it refuses to reuse a directory): ```sh mame coleco [-cart ] -rompath "" -homepath -snapshot_directory snap \ -video none -sound none -nothrottle -noreadconfig -skip_gameinfo -log -seconds_to_run \ -debug -debugger none -autoboot_script /trace.lua ``` with ```lua local dbg = manager.machine.debugger dbg.visible_cpu = manager.machine.devices[":maincpu"] dbg:command('trace z80.trace,,noloop,{logerror "%X %X %X %X %X %X %X %X %X %X %X %d %d %d\\n",pc,af,bc,de,hl,ix,iy,sp,af2,i,r,totalcycles,beamy,beamx}') dbg:command('wpiset 0,100,w,1,{logerror "IW %X %X %d\\n",wpaddr&0xff,wpdata,totalcycles; g}') dbg:command('wpiset 0,100,r,1,{logerror "IR %X %X %d\\n",wpaddr&0xff,wpdata,totalcycles; g}') dbg:command("go") ``` `error.log` (in the run directory) then holds one line per instruction **before** it executes: `PC AF BC DE HL IX IY SP AF' I R totalcycles beamy beamx` (hex, the last three decimal), and `IW port data totalcycles` / `IR port data totalcycles` for every I/O access. The Z80's debugger symbols are those of `z80.cpp`'s `state_add` (l.724-752): `PC SP AF BC DE HL IX IY AF2 BC2 DE2 HL2 WZ R I IM IFF1 IFF2 HALT`. ## What it produced **The BIOS with no cartridge, 2 emulated seconds**: 945,993 instructions, 17,821 I/O writes, 1 I/O read, 25.5 s of wall time, a 54 MB `error.log` (and a 15 MB `z80.trace` MAME writes beside it). ``` Soft reset 0 40 0 0 0 FFFF FFFF 0 0 0 0 0 244 0 3 40 0 0 0 FFFF FFFF 73B9 0 0 1 11 244 16 6E 40 0 0 0 FFFF FFFF 73B9 0 0 2 22 244 33 71 40 0 0 FFFF FFFF FFFF 73B9 0 0 3 39 244 58 72 FF40 0 0 FFFF FFFF FFFF 73B9 0 0 4 44 244 66 74 FF82 0 0 FFFF FFFF FFFF 73B9 0 0 5 52 244 78 81 FF82 0 0 FFFF FFFF FFFF 73B9 0 0 6 63 244 94 1FD6 FF82 0 0 FFFF FFFF FFFF 73B7 0 0 7 81 244 121 23B FF82 0 0 FFFF FFFF FFFF 73B7 0 0 8 92 244 138 23D 9F82 0 0 FFFF FFFF FFFF 73B7 0 0 9 100 244 150 23F 9F82 0 0 FFFF FFFF FFFF 73B7 0 0 A 140 244 210 IW FF 9F 100 IW FF BF 148 IW FF DF 196 IW FF FF 244 IW C0 FF 341 IW BF 0 1793 IW BF 40 1818 IW BE 0 1835 ``` Read off it: - `LD SP,$73B9` 11 clocks, `JP $006E` 11, `LD HL,($8000)` 17, `LD A,L` 5, `CP $55` 8, `JP NZ` 11, `CALL` 18, `LD A,n` 8: **each is the Z80's documented count plus one per M1 cycle**. - **`OUT ($FF),A` takes 40 clocks** (from 100 to 140): 11, plus 1, plus 28 of READY wait. The watchpoint's `totalcycles` is the instruction's start, not the write's own clock. - The BIOS's first acts: four sound writes `9F BF DF FF` (all channels off), `$C0` (joystick segment), then VDP address `$0000` for writing and 16K of zeros to `$BE` at 47 clocks a byte. - The frame starts at `beamy` 244 at reset; `beamx` advances 1.5 per CPU clock (the pixel clock). - Port writes in 2 s: 17,680 to `$BE`, 136 to `$BF`, 4 to `$FF`, 1 to `$C0`; the one read is `IR BF 80` at clock 771,902: the status register with F set. No instruction at `$0066` in these two seconds: the BIOS leaves the NMI disabled on its no-cartridge screen. - The run ends at clock 7,168,314, snapshot: the rainbow COLECOVISION logo over "TURN GAME OFF BEFORE INSERTING CARTRIDGE OR EXPANSION MODULE. (C) 1982 COLECO". **Untraced, 5 emulated seconds each** (about 1 s of wall time): Zaxxon shows "COLECOVISION PRESENTS SEGA'S ZAXXON (C) 1982 COLECO"; the Final Test Cartridge shows "ROM CHECKSUM D483 / ROM GOOD / RAM TEST RAM GOOD". Gearcoleco shows the same two screens at 300 frames ([validation.md](validation.md)). MAME's snapshot is 280 x 216 (the 256 x 192 picture with 12 pixels of border on each side); Gearcoleco's frame is 256 x 192. ## Traps 1. **Cost**: tracing took 12.7 s of wall time per emulated second on the loaded machine, and 27 MB of log per second. Keep traces to a few seconds; untraced runs are about 5x real time. 2. **`error.log` lands in the working directory**, not under `-homepath`, and an old one is appended to: the script makes a new directory per run and refuses an existing one. 3. **A `logerror` action logs nothing with more than 14 values** (sms-python's finding; not re-tested here), so `BC'`, `DE'`, `HL'`, `IFF1/2` and `IM` are left out. A shadow-register difference shows one `EXX` later. 4. **`wpiset` with `wpaddr`**: the Z80 puts a 16-bit address on the bus for I/O; the script masks it to 8 bits. The clock logged is the start of the instruction that made the access. 5. **`-seconds_to_run` takes integers.** 6. `grep` on `error.log` needs `-a`. 7. Lua `device.debug:bpset` segfaults (the `bpset` debugger command is fine); Lua taps must be held in globals (family knowledge, not re-tested here). ## What MAME cannot tell us - anything about CPU access windows or lost VDP writes (it serves every access at once); - the status-read race (it has none); - real spinner pulse widths (its own to-do); - the Activision, MegaCart and Super Game Cartridge boards beyond what its authors needed (`sgc.cpp`: "what gradius needs"); - which of the SN76489A's undocumented behaviours are right: its header claims verification against chips for the noise, and gives no method.