# MAME as a detector for the board (closed box, tier 5) MAME 0.285, machines `cdimono1` (Mono-I PAL), `cdimono2`, `cdi910`, `cdi490a`, `cdibios`, `gpi1200` (`philips/cdi.cpp`). Every CD-i file's `license:` line says **BSD-3-Clause** (read through the GitHub API at tag `mame0285`, `3bd358f`, first lines only, 2026-11-26): `philips/cdi.cpp`, `cdi.h`, `cdicdic.cpp/.h`, `cdislavehle.cpp/.h`, `mcd212.cpp/.h`, `devices/machine/scc68070.cpp/.h` (Ryan Holtz), `devices/cpu/m68000/scc68070.cpp/.h` (Karl Stenerud), `devices/cpu/m6805/m68hc05.cpp` (Vas Crabb), `m6805.cpp` (Aaron Giles, Vas Crabb), `devices/machine/timekpr.cpp` (Aaron Giles, smf). As with the PlayStation board, they stay **closed** (run, never read) until Aubrey decides otherwise (decision 6). Note that the CDi_MiSTer author writes that MAME's CD-i code "is heavily inspired by shared code snippets from cdiemu", a closed-source program: the lineage of those BSD files is not established, another reason to keep them closed. Device tree (OBSERVED, `-listxml cdimono1`): `maincpu` Philips SCC68070 at 30,000,000 Hz (the crystal; the CPU runs at half); `mcd212` "MCD212 VDSC"; `cdic` "CD-i CDIC"; `slave_hle` "CD-i Mono-I Slave HLE" (no slave CPU); `mk48t08` timekeeper; two DMA-driven DACs; screen 768 x 560 at 50 Hz, pixel clock 28,416,000 Hz; a 192 x 22 LCD (the front display). `cdimono2` and `cdi910` instead list two MC68HC05C8 CPUs (`servo`, `slave`) at 4,000,000 Hz and no CDIC device. ## The recipe (run 2026-11-26) ```sh export MAME_ROMPATH="" python -I scripts/mame_run.py --frames 2000 --trace-at 100 --trace-frames 50 # ACCESSES 20821 reads 1637 writes 2000 frames (fresh NVRAM) # TRACE_START 2.000000000 / TRACE_END 3.000000000 # trace: 446 listed + 426353 collapsed = 426799 instructions over 50 frames ``` `scripts/mame_run.py` writes `tests/mame_traces/run.lua` and runs, in that directory, ``` nice mame cdimono1 [-debug -debugger none] -bios mcdi200 -rompath "$MAME_ROMPATH" \ -video none -sound none -nothrottle -noreadconfig -skip_gameinfo \ -snapshot_directory snap -nvram_directory nvram -cfg_directory cfg \ -autoboot_script run.lua -seconds_to_run N ``` The Lua installs read and write taps on `:maincpu`'s program space over `300000-3FFFFF` and `4FFFE0-4FFFFF` (taps and the frame notifier held in globals), counts accesses per 256-byte block (`blocks.txt`), logs the first writes (`io.log`: time, address, data, mask), runs the debugger's `trace` command between two frames, and takes a snapshot at the end. A whole run takes 3-5 s of wall time. Emulation runs tonight: 12 (plus `-listxml` queries), one process at a time, CPUs 24-31. **Determinism:** MAME saves the timekeeper NVRAM in `tests/mame_traces/nvram/` at exit, and the next boot takes a different path (fresh: 20,821 reads, 1,637 writes in 2,000 frames; with the saved NVRAM: 23,537 and 1,907, the same in two runs). Move `nvram/` aside into `trash/` to repeat a first boot. The specification will take its NVRAM image and clock epoch from the host for the same reason (slave-and-input.md). ## What the runs showed (OBSERVED, MAME's model, `cdi200.rom`, no disc) - **Boot to the player shell** (PHILIPS / Compact Disc Interactive, PLAY CD-I, INFO, SETTINGS, DIM, MEMORY, OPEN, with the pointer): on screen at frame 1,100 (22 s), not yet at frame 600 (12 s, a blank screen with the LCD showing dashes). The boot is about **15-20 emulated seconds** in MAME's timing (screenshots in `tests/mame_traces/snap/`, git-ignored: they show Philips artwork). - The access census of the first boot (fresh NVRAM), blocks with any access: CDIC `301400` (R 18, W 2), `303C00` (W 1), `303Fxx` (R 2, W 3); slave `310000` (R 21, W 56-98); `318000` (W 2, `0000` mask `FF00`: an unidentified write-only latch, U19); NVRAM `320000-3202FF` (R 5,018, W 1,512; `3204FF` is reached when a saved NVRAM is present) and `323Fxx` (the clock registers); MCD212 registers `4FFFE0-4FFFFF` (16 writes, 15,742 reads: the CPU polls CSR1R/CSR2R). - The first writes, 0.0822 s after reset: CDIC `301400/301402` = 0, the slave handshake (`310000` <- `86`, `89`; `310006` <- `80 60 73 50 81 6F 7F 00`; `310004` <- `F2`; `310002` <- `09 21 40 24 0F 21 39 00`), then the MCD212's CSR1W (`4FFFF0` <- `0001`), DCR/VSR/DCP writes, display enabled at 0.101-0.120 s (`4FFFF2` <- `4000`, `C000`). At 8.45 s the CDIC is programmed (IVEC `303FFC` <- `2480`, `303C00` <- `0024`, DBUF `303FFE` <- `8000`) and at 8.53 s the clock's control register (`323FF0` <- `40`, `00`). - **Instruction counts per emulated second** (debugger trace; MAME collapses repeating loops into "(loops for N instructions)", which the script adds back): 2-3 s, the ROM module scan (`cmpi.w #$4afc,(A2)+` / `bne` / `cmpa.l` / `bcs`): **426,799**; 6-7 s: 118,998; 10-11 s: 189,363; 30-31 s at the shell: **27,107** (the CPU mostly in `STOP`, waiting for the next interrupt). The trace's first record is "interrupted at 0040A0EE, IRQ 6" with the vector `$F8` (the on-chip timer: scc68070.md). The module scan's rate is a question for the specification, not a verdict: the data sheet's totals for that four-instruction loop are 18 + 13 + 7 + 13 = 51 clocks, i.e. about 1.18 M instructions/s at 15 MHz with no wait states; MAME's 0.43 M/s implies about 35 clocks per instruction, which ROM DTACK delays (Table 3-2: up to 11-12 CLK a ROM access when CSR1W is at its reset value) could explain (U20). ## What MAME can and cannot decide Can: find differences in the I/O streams (order and values), the boot's control flow, interrupt sources, the shell's picture, NVRAM layout; and run long. Cannot: judge timing (its 68070 cycle model and DRAM slot waits are its own), the slave (high-level on Mono-I), DMA timing (high-level DMA, per CDi_MiSTer), ADPCM rounding, or exact pixels. Every MAME disagreement is a question, never a verdict.