# MAME 0.285 as a detector for the 2600 MAME's `a2600` driver is a **CPU-level detector only**. Its TIA is a catch-up line renderer with fitted tables, not a colour-clock model (list below), so it can answer "did the 6507 execute the same instructions with the same registers and cycle counts" and nothing finer. Stella is the board-level detector ([validation.md](validation.md)). Verified on 2026-10-21 with the installed MAME 0.285 (`/usr/games/mame`) on Combat, Pitfall!, Adventure, Asteroids, River Raid, Pitfall II (DPC), Decathlon (FE), Montezuma's Revenge (E0) and Kaboom! (paddles). Sources read: `src/mame/atari/tia.cpp`, `src/mame/atari/a2600.cpp`, `src/devices/machine/mos6530.cpp`, `src/devices/bus/vcs/*` at tag `mame0285`, each of which starts `// license:BSD-3-Clause` (headers re-checked on 2026-11-14 under the restart rules; MAME's GPL files, such as the TIA sound in `src/devices/sound/tiasound.cpp`, are never opened). The BSD-3 notice is in NOTICE. ## The recipe `scripts/mame_trace.py {a2600|a2600p} CART [--seconds N] [--no-trace] [--slot a26_xx] [--left pad|joy|keypad|wheel|trakball|…] [--right …] [--out DIR]` It extracts a No-Intro zip's single member into the run directory (default `tests/mame_traces/-/`, ignored) and runs, from that directory: ```sh mame a2600 [-cartslot a26_f8] [-joyport1 pad] -cart GAME.a26 -homepath . \ -snapshot_directory snap -video none -sound none -nothrottle -noreadconfig \ -skip_gameinfo -debug -debugger none -log -seconds_to_run N \ -autoboot_script trace.lua ``` The Lua turns on a per-instruction trace into `logerror`: ``` trace cpu.trace,,noloop,{logerror "%X %X %X %X %X %X %d %X %X\n",pc,a,x,y,p,sp,totalcycles,b@284,b@285} ``` plus watchpoints on $00–$7F (TIA), $280–$29F (RIOT) and $1FE0–$1FFF (hotspots), each logging `R/W address data totalcycles`, and a frame notifier that reads the TIA's `frame_cycles` save item. Output: `error.log`, `frames.txt`, `summary.txt`. Devices: `:maincpu` (M6507, 1,193,191 Hz), `:tia_video` (picture), `:tia` (sound, at the crystal / 114 = 31,399 Hz), `:riot` (MOS6532), `:cartslot:<type>`, `:joyport1`, `:joyport2`, `:screen`. The TIA and RIOT have **no debugger state symbols**; their save items are readable from Lua (TIA `frame_cycles`, `prev_x`, `prev_y`, `HMOVE_started`; RIOT `m_timershift`, `m_timerstate`, `m_irq_timer`). ## Measured | Cartridge | Instructions (2 s) | CPU cycles per frame | | --- | ---: | --- | | Combat (USA, Europe) | 777,410 | 19,988 (263 lines) on all 119 frames | | Pitfall! | 975,324 | 19,912 (262 lines) | | Adventure | 796,673 | 19,912 | | Adventure (Europe), `a2600p` | | 23,712 (312 lines) | | Asteroids | | 20,140 (265 lines; one frame 20,124) | | River Raid, Pitfall II, Decathlon, Montezuma's Revenge, Kaboom! | | 19,912 where measured | Tracing runs at 0.25–0.7× real time; `--no-trace` does 1 s in 1.5 s. The Lua `frame_cycles` deltas equal the deltas between VSYNC writes. Combat's 263-line frame is the game's own choice (frames are whatever the program makes them). **WSYNC is not RDY in MAME.** `WSYNC_w` burns the remaining cycles with `adjust_icount(cycles % 76 - 76)` (tia.cpp:976-984), so the stall shows as a jump in `totalcycles`: ``` 15C0 0 60 0 34 1FD 46 FF 0 STA WSYNC W 2 0 46 15C2 ... 78 (32 cycles later) ``` The instruction after a WSYNC is always stamped ≡ 2 (mod 76) (trap 2: an opcode fetch at line cycle 1). A write landing exactly on cycle ≡ 0 (mod 76) stalls nothing. Whether that matches Stella to the cycle is for milestone 1's lockstep to say. Reading INTIM (`b@284`) and TIMINT (`b@285`) in the trace has no side effects: the debugger sets `side_effects_disabled` (mos6530.cpp:510-548), and Pitfall!'s register stream is byte-identical with and without those fields. **The beam position** is not the debugger's `beamx`/`beamy` (those belong to MAME's free-running screen and ignore VSYNC). Compute it from the TIA's own anchor: x = 3·((tc − frame_cycles) mod 76) − 68, y = (tc − frame_cycles) div 76 (tia.cpp:637-646); `frame_cycles` re-anchors to a whole line at VSYNC (tia.cpp:987-1008). ## Traps 1. `error.log` lands in the working directory; the register trace is in the logerror output, and `cpu.trace` holds only the disassembly. 2. The trace stamp is the opcode-fetch cycle + 1 (MAME's 6502 prefetches): the first instruction after reset is stamped 8, not 7. Watchpoint lines carry the instruction's start stamp, not the bus cycle's. 3. Watchpoints fire on opcode and operand fetches too, including the next opcode's prefetch. 4. Only the address ranges named are watched: TIA mirrors above $7F and at $100+ are missed unless added. 5. PC is the program's 16-bit view ($Fxxx, $Dxxx…): mask with $1FFF before comparing with a 13-bit board. 6. A loose `-cart` file is typed by MAME's own heuristic (`identify_cart_type`, vcs_slot.cpp:684-760; Super Chip by `detect_super_chip`); the software list's slot feature applies only when loading by softlist name. `-cartslot a26_xx` (`--slot`) overrides. 7. P shows bits 4 and 5 set (compare under mask $CF); SP includes the $1xx page. 8. Lua notifier subscriptions must be held in globals, or garbage collection silently ends them. 9. `logerror` drops anything past 14 values; the trace line uses 9. 10. Lua run from the autoboot script before the first frame sees pre-reset state (PC = 0): read state from a frame notifier. 11. The ALSA "seq_hw open failed" message is harmless. 12. Supercharger images (8,448 / 16,896 / 25,344 / 33,792 bytes) and the 8,195-byte WDSW are refused as cartridges (vcs_slot.cpp:208-224). 13. **Power-on state**: X = $80 and Z set (P = $36), A = Y = 0, S = $FD after reset; RIOT RAM zeroed; the timer at 255 with a 1024-cycle interval, its first decrement read off the trace at cycle 1023. The board's `machine.PowerOn` defaults are these, labelled as MAME-matched. 14. **Line phase**: the instruction after a WSYNC is fetched in cycle 1 mod 76 of MAME's count. The board's TIA releases RDY so that the read resumes in the line's first cycle (timing.md, settled on the die), so the board powers on two cycles' worth of steps before a line start, on the cycle grid (`PowerOn.hclock = 224`), which lines the two counts up. 15. **The timer slips** (undocumented-behavior.md C21, C22): timer writes act at the instruction's stamp, and within the first second the timer loses a further cycle against MAME's own CPU. `scripts/lockstep_mame.py` replays MAME's logged INTIM/TIMINT reads instead of comparing them; Stella is the timer's detector. 16. **RSYNC** is a no-op in MAME; the lockstep drops RSYNC writes before they reach the board's TIA. ## The board in lockstep (milestone 1, 2026-10-22) `scripts/lockstep_mame.py ROM error.log` steps the board beside a trace and compares PC, A, X, Y, P (under $CF), S and the cycle count before every instruction, replaying collision and timer reads from the log (traps 15, 16 and milestone 1's TIA drawing nothing). Results are in [validation.md](validation.md) "Certification record". ## What MAME's 2600 gets wrong (why it is CPU-only) Read from the source at `mame0285`; the file has almost no TODOs, so these are from the code itself. 1. **No beam counter and no colour-clock model**: a catch-up line renderer driven by CPU total cycles (tia.cpp:637-646, `update_bitmap` from 697) with per-register fudge tables (tia.cpp:1846-1890); playfield writes rounded with `(x+1)&~3` (tia.cpp:1901). Resolution is three colour clocks. 2. Line origin is CPU cycle 0 mod 76; VSYNC re-anchors to a whole line (tia.cpp:1003). 3. WSYNC is an icount burn, not RDY (tia.cpp:976-984). **RSYNC is a no-op** (tia.cpp:1317-1320). 4. **HMOVE by fitted windows**: writes at x in [−5, 97) ignored (tia.cpp:1221-1228), skip/clamp formulas (1238-1270), a cycle-75 special case (1296-1302), patches for HMxx/RESxx during an active HMOVE (1035-1190, 1502-1522); no motion clock, no ripple counters. 5. Undriven bits of TIA reads guessed from the opcode stream (tia.cpp:1783-1792, a2600.cpp:411-447, "a quick hack"). 6. Paddles as a linear `input*76` threshold (tia.cpp:1766-1777), not the capacitor's curve. 7. Reset clears only CXM0P among the collision latches (tia.cpp:2133). 8. Sound is a separate Fries-style stream (tia.cpp:1981), not clocked with the CPU. 9. a2600.cpp: NTSC crystal 3.579575 MHz (189) where the POP unit uses 3.579545 (211); RIOT mapped at $280–$29F mirrored $0D00 only, so the $2A0–$2FF mirrors are missing (268); RIOT RAM zeroed at start (476); no SECAM driver. 10. Harmony/Melody is a stub (harmony_melody.cpp:95-147): irrelevant here. Bankswitch hotspots are read taps guarded by `side_effects_disabled()` (rom.cpp:119-187): dummy reads switch banks, debugger reads do not. That is right, and makes MAME useful for hotspot questions. MAME's slot types: `a26_2k_4k f4 f6 f8 f8sw fa fe 3e 3f e0 e7 ua cv dc fv jvp cm ss dpc 4in1 8in1 32in1 x07 harmony`.