# MAME 0.285 as a detector for the Lynx MAME's `lynx` driver is an **instruction-flow detector**: it can answer "did the 65SC02 execute the same instructions with the same registers" and "did the program write the same values to the same registers in the same order". It cannot answer any question about time. Verified on 2026-11-11 with the installed MAME 0.285 (`/usr/games/mame`) on `Zaku (World) (Unl)`. MAME is a **closed box** here (restart rules): only `hash/lynx.xml` (CC0-1.0) is read. On 2026-11-14 every statement below that had come from reading the driver's source was struck or re-sourced to what running MAME shows ([provenance.md](provenance.md)). ## The boot ROM `mame -listroms lynx` wants `lynx.bin` (CRC `e1ffecb6`, bios `default`) or `lynxa.bin` (CRC `0d973c9d`, bios `a`), both 512 bytes, both flagged BAD_DUMP because they were saved from a running machine and the byte under MAPCTL cannot be read. `lynxa.bin` is the image everyone else calls `lynxboot.img` (SHA-1 `e4ed47fae31693e016b081c6bda48da5b70d7ccb`). Both are in `lynx.zip` under `$MAME_ROMPATH`; the script passes that directory as `-rompath` and `-bios a`. Nothing is copied. ## The recipe `scripts/mame_trace.py CART [--seconds N] [--no-trace] [--bios default|a] [--snap] [--out DIR]` It extracts a one-member zip into the run directory (default `tests/mame_traces//`, ignored) and runs, from there: ```sh mame lynx -rompath "$MAME_ROMPATH" -bios a -cart GAME.lnx -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\n",pc,a,x,y,p,sp,totalcycles} ``` plus write watchpoints on SUZYBUSEN/SPRGO/SPRSYS (`$FC90-92`), SDONEACK/CPUSLEEP/DISPCTL/PBKUP (`$FD90-93`), INTRST/INTSET (`$FD80-81`), MAPCTL (`$FFF9`) and the timer 0 and 2 registers, each logging `W address data totalcycles`, and a frame notifier writing the machine time in 250 ns units to `frames.txt`. Output: `error.log`, `frames.txt`, `summary.txt`. Devices (`mame -listdevices lynx`, observed): `:maincpu` (G65SC02 at 4 MHz), `:screen`, `:custom` sound, `:cartslot`, `:quickload`. Mikey and Suzy are not listed as devices and have no debugger symbols. ## Measured | Run | Result | | --- | --- | | Zaku (World) (Unl), 2 s, traced | 2,290,284 instructions; CPU cycles 8 to 8,013,595; 120 screen frames; 55 s wall at load 40 (about 0.04x real time traced) | | Frame period | 66,780 CPU cycles every frame = 16.695 ms (the default Timer 0/2 setting; MAME's screen is fixed at it) | | First instructions | `FF80` at cycle 8 with P = `$36`; MAPCTL written with 3 at cycle 42 (Suzy and Mikey spaces replaced by RAM) | The trace's first line is the reset vector target `$FF80`; the boot ROM runs from there, so a lockstep starts at the same place on our board with the same ROM image. ## Traps 1. `error.log` lands in the working directory. Its first lines are MAME's own messages (a UTF-8 BOM, the screen warning, the cart line, "Soft reset"); instruction lines are the ones with exactly 7 fields. 2. The trace stamp is the cycle count when the instruction is about to run, with MAME's prefetch: the first instruction is stamped 8. 3. `totalcycles` is in **CPU cycles of 250 ns**, uniform. Convert nothing to ticks: there is no correspondence finer than "about 4 or 5 ticks each". 4. P reads with bits 4 and 5 set (`$36`, `$34`): compare under mask `$CF`. SP includes the page (`1FD`). 5. *Struck*: how MAME's cart loader treats header bytes and `.lyx` sizes was read from its source. To use MAME on a cart, give it a `.lnx` whose header says what our loader resolved, and treat block-size handling as unknown until observed. 6. The trace format keeps under 14 values (7 used). 7. Lua notifier subscriptions must be held in globals. 8. A BLL `.o` (`-quik`) path is not set up; the earlier note on it came from the source and was struck. Not run. 9. Loading by software-list name (`mame lynx apb`) needs the software ROMs in MAME's layout under a `-rompath`; not set up here, not run. 10. The ALSA "seq_hw open failed" message is harmless. ## What MAME's Lynx cannot judge (why it is flow-only) Observed from outside only (the earlier ten-point list was read from the driver's source and its TODO, and was struck on 2026-11-14): 1. Its trace counts **uniform 250 ns CPU cycles** (`totalcycles`, 16 MHz / 4): no 4- or 5-tick distinction is visible, so nothing about time can be compared. 2. `-listdevices` shows one `G65SC02` and one machine, `lynx`: no Lynx II row (so the bit instructions of `Lynx2Cell` cannot be compared). 3. Its frame period on Zaku is 66,780 CPU cycles (the default timer setting). Whether it follows a game's own timer setting is to be observed. Everything else about it (sprites, UART, math, EEPROM, sound) is to be found by running it, recorded as OBSERVED with the revision, and never fixed toward. ## What it is good for - Milestone 1's lockstep: PC, A, X, Y, P (mask `$CF`), S instruction by instruction through the boot ROM and into a game, until the first time-dependent branch (a timer read, a vertical-blank wait). The divergence point is expected and is itself information: it shows where time first matters. - The order and values of register writes (the watch list) for a boot. - The software list as data ([cartridge.md](cartridge.md)).