# MAME as a detector for the TMS9900 (tier 5, closed box) MAME 0.285 (the installed `mame` binary; any 0.285 build) runs the TI-99/4A with its own TMS9900. It is a **detector**: it finds places where an instruction stream differs, it never decides which side is right. Its source is not opened for this work: MAME's `src/devices/cpu/tms9900/*` say `license:BSD-3-Clause` (Michael Zapf; the disassembler Raphael Nabet), but its TI-99 drivers and buses (`src/mame/ti/ti99_4x.cpp`, `src/devices/bus/ti99/**`, `src/devices/machine/tmc0430.cpp`) say `license:LGPL-2.1+` (Michael Zapf). Those lines were read on 2026-11-26 by fetching only the first 400 bytes of each file at tag `mame0285` (validation.md summarises all 62 by group); no source was kept. ## The recipe, as run on 2026-11-26 ```sh # a shell with MAME_ROMPATH set (the family's profile-env file sets it) python -I scripts/mame_trace.py --machine ti99_4a --start 0 --frames 2 \ --out tests/mame_traces/boot.trace # 5,762 instructions, 0.033376 s python -I scripts/mame_trace.py --machine ti99_4a --start 120 --frames 60 \ --out tests/mame_traces/title-1s.trace # 161,014 instructions, 1.001289 s python -I scripts/survey_trace.py tests/mame_traces/title-1s.trace ``` Each run is one MAME process, under `nice`, with `-video none -sound none -nothrottle -noreadconfig -skip_gameinfo -debug -debugger none -autoboot_script tests/mame_traces/trace.lua`; MAME's cwd is `tests/mame_traces/` (git-ignored), so error.log, cfg/ and nvram/ stay there. The Lua script turns the debugger's `trace` command on at frame `--start` and off `--frames` later, with an action `{tracelog "WP=%04X ST=%04X ",WP,ST}`. A line looks like ``` WP=83E0 ST=0000 0024: li R13,>9800 ``` where WP and ST are the values **before** the instruction runs (the first line, the reset vector's first instruction, shows ST = 0000; the next shows the flags LI set). The summary is in `tests/detectors/mame-trace-survey-2026-11-26.txt`. ## MAME's symbols for its tms9900 device `PC`, `WP`, `ST` and `R0`..`R15` (the workspace registers, read through memory). They were used in the action above and accepted. MAME's `ti99_4a` romset supplies the console ROM and GROMs from `$MAME_ROMPATH` (SHA-1s in ../ti99-python's census). ## What the traces show (OBSERVED) - From reset the CPU's first instruction is at 0024 with WP = 83E0: the console ROM's reset vector points into the scratchpad for its workspace (the GPL interpreter's workspace is 83E0 throughout). - In one second at the title screen every one of the 161,014 instructions ran from the console ROM (140 distinct PCs: the GPL interpreter's inner loop and the keyboard scan, LDCR/STCR on the 9901), so the instruction stream there is 16-bit-bus code reading GROM and VDP through the multiplexer. - 161,014 instructions in 3,003,867 CPU clocks = 18.66 clocks per instruction in MAME's model. ## What MAME can and cannot decide - Can detect: a different instruction stream, register value or flag after an instruction, a different interrupt point (by comparing PCs at interrupt entry), from reset or after a cartridge loads (`--cart`, MAME's `-cart` with an RPK from its software list). - Cannot decide: any cycle count, the position of wait states, the read-before-write cycles, undefined opcodes, or the C1-C5 timing disagreements (docs/timing-and-bus.md); MAME's timing model is unread and its agreement with hardware is unknown. - Its `trace` output is per instruction, not per bus cycle: a cycle-level comparison needs a memory-tap script (Lua `install_read_tap`/`install_write_tap` on the program space, held in a global), not done in Phase 0.