# MAME 0.285 as a detector for the 5200 MAME is an emulator (tier 5): it finds differences, it does not settle them. For this machine it is a **CPU-order detector**: good for "which instruction ran when, and which registers did it touch", weak for ANTIC timing and known to be wrong on several titles. ## What MAME models (read in Phase 0 from sources no longer fetched) Historical record. This section was written in Phase 0 (2026-11-11) from MAME's GPL-2.0+ driver and ANTIC files, before the family charter made GPL emulators closed boxes only. It informs no board code (the board follows [AHRM], [IJOR] and Acid5200), and from wave 2 (2026-11-13) on MAME is described by running it: what the board relies on here is re-observed in closed-box runs (the frame marks below; the VBI-against-DLI placement in undocumented-behavior.md C15, measured from MAME's own trace). MAME's driver and ANTIC/GTIA files are GPL-2.0+ and their source is no longer fetched (Aubrey, 2026-11-24; https://github.com/mamedev/mame tag `mame0285`, `f379cd060ac3b2bd567ebbd0957aed059d6895ff`). What the Phase 0 reading said is kept below only as HYPOTHESIS (for review), except where a run observed it: - Machines `a5200` (BIOS `co19156.u8`) and `a5200a` (`co19156a.a8`), as `-listxml` and the ROM loader report (OBSERVED). CPU: plain 6502 at 1,789,790 Hz; map RAM $0000-$3FFF, cartridge $4000-$BFFF, GTIA $C000-$CFFF, ANTIC $D400-$D4FF, POKEY $E800-$EFFF, ROM $F000-$FFFF with the 2K image at $F800 and $FF below it (HYPOTHESIS: read from the GPL driver; the debugger's memory view can re-observe it). Save states unsupported (OBSERVED). - ANTIC as a **per-scan-line** renderer: the CPU loses a line's DMA cycles in one piece rather than at the cycles where DMA falls; WSYNC waits for a line timer; the DLI comes a fixed 7 cycles after a fixed point (HYPOTHESIS: read from the GPL ANTIC file in Phase 0; the VBI placement in C15 is the re-observed part). So cycle positions inside a line are not the hardware's, while cycles per line and per frame are (the frame marks below, measured). - The floating bus is not modelled (HYPOTHESIS: from the driver's to-do list, read in Phase 0). - Its software list marks 9 of 112 items unsupported and 4 partial, among them commercial titles (Galaxian, Quest for Quintana Roo, RealSports Soccer) and Atari's diagnostics (PAM 2.0 "crashes on Atari copyright screen"; PAM 2.3 "[ANTIC] test returns soft error 34 01"). `totalcycles` in the debugger counts machine time (stolen cycles included): frame marks come 29,866-29,871 cycles apart (measured), i.e. 262 x 114. ## The recipe (run on 2026-11-11) `scripts/mame_trace.py` wraps it: ```sh python scripts/mame_trace.py a5200 "$NO_INTRO_DIR/Atari - Atari 5200/Pac-Man (USA).zip" --seconds 8 python scripts/mame_trace.py a5200 CART --no-trace --seconds 11 --snapshot 600 ``` which runs, in a fresh directory under `tests/mame_traces/` (ignored): ```sh mame a5200 -rompath "$MAME_ROMPATH" \ -cart "Pac-Man (USA).a52" -hashpath "${MAME_HASHPATH:-/usr/share/games/mame/hash}" \ -homepath DIR -snapshot_directory snap -video none -sound none -nothrottle \ -noreadconfig -skip_gameinfo -debug -debugger none -log \ -seconds_to_run 8 -autoboot_script DIR/trace.lua ``` `trace.lua` sets a `trace` with a `logerror` action per instruction (`PC A X Y P SP totalcycles VCOUNT`), write watchpoints on GTIA, ANTIC and POKEY, read watchpoints on GTIA and POKEY, and a frame notifier that logs a mark. Measured, Pac-Man (USA), `a5200`, 8 emulated seconds: 127 s wall on this loaded machine, 3,743,215 instructions, 480 frames, 30,052 WSYNC writes, first cartridge instruction $8386 at cycle 7,706,528 (instruction 1,651,425). `error.log` is about 80 MB for 8 s: keep runs short. ## Traps 1. **The hash path.** `-noreadconfig` discards the system `mame.ini`, and with it `hashpath`. MAME then cannot find `a5200.hsi`, maps every loose 16K image as one chip, and two-chip cartridges (Pac-Man) run into garbage and show a black screen. Always pass `-hashpath`. The first trace recorded in this phase was wrong for this reason. 2. A loose cartridge file is typed by its size and by `a5200.hsi` (CRC-32), not by the software list; the list applies only to software-list items loaded by name from a software ROM set, which is not present here. For a 16K image the hash file does not know, MAME says one chip. 3. The BIOS is found by `-rompath` (`$MAME_ROMPATH`); a merged set holds both revisions in `a5200.zip` (`co19156.u8` and `a5200a/co19156a.a8`), a non-merged one has `a5200a.zip` for revision A. Read in place. 4. `error.log` is written to the working directory, not under `-homepath`; the script runs MAME with the output directory as working directory. 5. P in the trace is MAME's internal P with bits 4 and 5 set: mask with $CF. SP is printed with its page ($1FF). 6. An indexed store logs a read before its write at the same address (the 6502's dummy read). That is correct behaviour, not a duplicate. 7. A Lua device object has no `totalcycles`; the frame mark is written with `manager.machine:logerror` and appears as `[luaengine] F`, taking its cycle from the next instruction line. The first line of `error.log` starts with a byte-order mark. 8. `-video none` still renders: a frame-notifier snapshot gives a correct PNG (checked: the BIOS logo at frame 150). MAME writes one more PNG at exit. 9. A `logerror` action silently drops lines with more than 14 values (found on other boards); 8 are used. 10. The first cartridge instruction comes 4.3 emulated seconds in for a cartridge with the logo; 2-3 second traces show only the BIOS. 11. Controller input is not scripted here. MAME exposes the sticks as analog ports `:analog_0`-`:analog_7` and the keypads as `:keypad.0`-`.3`; a lockstep past a title screen needs a Lua input script (not written). ## How to use it in the milestones - Milestone 1: instruction-order lockstep from reset through the BIOS to the first N instructions of the cartridge, comparing PC, A, X, Y, P & $CF, S. Cycle numbers are compared per frame (29,868) and not per instruction, because MAME moves stolen cycles within the line. A divergence in order that traces back to the position of a stolen cycle or an NMI within a line is expected and is not evidence against the board: it goes to Acid5200 and [AHRM]. - Later milestones: frame snapshots only, and only as a second opinion next to Atari800.