# MAME 0.285 as an emulator-tier detector for the CP1610 MAME runs the CP1610 in two drivers: `intv` (the Intellivision and its relatives `intv2`, `intvsrs`, `intvecs`, `intvoice`, `intvkbd`) and `unichamp` (the Unisonic Champion 2711, the only other machine with this CPU in MAME; checked with `mame -listxml`, `reference/mame-cp1610-machines.txt`). Its CPU device `src/devices/cpu/cp1610/cp1610.cpp` is **tier 5**: a detector for where a core first disagrees on real programs, never the judge ([validation.md](validation.md)). It counts cycles per instruction and has no bus phases and no bus request inside the CPU. Everything here was run on this machine on 2026-11-11 with MAME 0.285 at `/usr/games/mame`; the counts were re-read from the kept logs on 2026-11-12. `scripts/mame_trace.py` is the recipe as a script. ## The recipe ```sh python3 scripts/mame_trace.py --symbols # list the CPU's state symbols and stop python3 scripts/mame_trace.py --frames 180 \ --cart "$NO_INTRO_DIR/Mattel - Intellivision/Astrosmash (USA, Europe).zip" python3 scripts/mame_trace.py --machine unichamp --frames 120 ``` The script writes `trace.lua` into `tests/mame_traces//` (gitignored) and runs there: ```text mame -rompath "$MAME_ROMPATH" \ -homepath . -cfg_directory ./cfg -nvram_directory ./nvram \ -video none -sound none -nothrottle -noreadconfig -skip_gameinfo \ -debug -debugger none -log -autoboot_script trace.lua [-cart GAME] ``` The Lua script sets `dbg.visible_cpu` to `:maincpu`, starts ```text trace trace.txt,,noloop,{logerror "%04X %04X %04X %04X %04X %04X %04X %04X %04X %02X %d\n",curpc,r0,r1,r2,r3,r4,r5,r6,r7,curflags,totalcycles} ``` and stops MAME after N frames from a frame notifier held in a **global** (a local one is garbage-collected and stops firing). Outputs: - `error.log`: a `Soft reset` line (after a UTF-8 byte-order mark), then one line per instruction **before it executes**: `PC R0..R7 FLAGS CYCLES`. - `trace.txt`: MAME's disassembly per instruction, and a line `(interrupted at XXXX, IRQ 1)` where an interrupt was taken. ROMs are read in place with `-rompath`; `-cart` takes the No-Intro zip (one `.int` inside) directly. Nothing is copied or committed. ## Facts - Device tag `:maincpu`, "GI CP1610"; clock 894,886 for `intv` (MAME calls the microcycle rate the clock: 3.579545 MHz / 4), 232,260 for `unichamp`. - State symbols: `r0`-`r7`, `curpc`, `curflags`, `totalcycles`. The flags are `curflags` with **S = $80, Z = $40, OV = $20, C = $10**. The source names the entry "GENFLAGS", but `genflags` in the action logs nothing; use `curflags`. There is **no symbol for the interrupt enable or D**. - **SDBD is never its own line**: MAME's disassembler and its execution treat SDBD and the next instruction as one (`1610dasm.cpp` prints `SDBD ????` only for a following word it does not combine); the merged step's cycle delta is 14 (4 + 10). - Running `intv` with no cartridge runs the EXEC into RAM: not useful. - **Astrosmash (USA, Europe), 180 frames**: 343,189 instructions, 177 interrupts (each `(interrupted at ..., IRQ 1)` followed by `1004: PSHR R0`, the EXEC's handler at the vector $1004), 428 distinct PCs in `error.log`, 2,688,237 cycles (14,934.6 a frame, the frame is 14,934), about 6 s wall. - **unichamp, 120 frames**: 127,848 instructions, 63,308 of them BEXT, no interrupts. The only corpus here that exercises BEXT and EBCI. - Cycle deltas per mnemonic from the Astrosmash trace equal the manuals' table except **SETC (6, manuals 4)** and **`SARC r,2` (6, manuals 8)** (C3); the interrupt adds 9 (C2). - `mame -verifyroms`: `intv`, `intv2`, `intvsrs`, `intvecs`, `intvoice`, `intvkbd` good; `unichamp` "best available" (its GIC character ROM is a bad dump; the CPU's program ROM is good). ## What MAME does that the core must not copy The known-difference list (each a mask in rungs 2 and 3, each with its row in [undocumented-behavior.md](undocumented-behavior.md)): SETC 6 and `SARC r,2` 6 (C3); NEGR of 0 leaves C clear (C6); SDBD with R6 decrements twice (C9); SDBD + direct decoded as indirect through R0 (C10); SDBD + MVO illegal (C11); MVO@ with the pointer as source writes the old value (C12); a jump with II = 11 is not taken (C13); HLT is a 4-cycle no-op (C8); an opcode word with bits 15-10 set advances the PC and costs nothing (U1); no reset cycles (C1); no BUSRQ in the CPU (the STIC driver stalls it from outside), so no grant rule at all. ## Use in the rungs - Rung 2: a separate Lua driver (to write) that sets registers and memory, single-steps and logs; the same command line with `-debug`. - Rung 3: replay of `error.log` lines against the core in a minimal host with `timing="doc"`. ## Rule slips on the first run (2026-11-11) The first trace was started while other agents' MAME processes were running (the rule "one MAME at a time" was read as per agent); a wait loop on `pgrep mame` was stopped because theirs did not end. No run since.