# MAME as a detector: the recipe as run MAME 0.285 (`mame -version`: "0.285 (unknown)"), a binary release, run headless. Tier 5: it finds differences, it decides nothing. Every PC-98 machine in it is marked **preliminary** except `pc9801rs` (`-listxml`). One MAME process at a time, short runs, `nice` and `taskset -c 24-31`. ## The recipe `scripts/mame_run.py` writes a Lua autoboot script into `reference/mame//` and runs: ``` mame -rompath "$MAME_ROMPATH" -video none -sound none -nothrottle -noreadconfig \ -skip_gameinfo -snapshot_directory snap -autoboot_script tap.lua -log ``` The Lua installs a read tap and a write tap over the main CPU's whole I/O space (`manager.machine.devices[":maincpu"].spaces["io"]`, 0000h-FFFFh), logs each access as `time CURPC dir offset data mask`, and after N frames saves a snapshot and exits. Two gotchas met: - **Byte lanes:** the 8086/V30/286 I/O space is 16 bits wide in MAME; a tap reports the even address and a lane mask. An access to an odd port alone has mask `FF00`. The script folds that back into the odd port number (the first run's counts showed only even ports until it did). - **Register names:** `CURPC` is the generic linear PC and works for the i86, NEC and i286 cores alike; per-core segment names differ (`CS`/`IP` on the i86, `PS`/`PC` style names on the NEC core), so the script does not use them. - The taps and the frame notifier are held in Lua globals (else they are collected). ## The runs (2026-11-26; no disk inserted) | Machine | Frames | Emulated time | Accesses logged | Wall time | Result | | --- | --- | --- | --- | --- | --- | | pc9801vm | 600 | 10.63 s | 239,063 | 2.3 s | black screen at 10.6 s | | pc9801vm | 1800 | 31.91 s | 252,979 | ~6 s (574 % speed) | **N88-BASIC(86) "How many files(0-15)?"** with the function-key bar | | pc9801 | 1800 | 31.90 s | 224,410 | ~4 s (720 %) | the same prompt | | pc9801vx | 1800 | 31.91 s | 202,937 | ~8 s (415 %) | the same prompt (286 mode, MAME's default) | The VM's I/O traffic is front-loaded: 74,103 accesses in the first emulated second, ~65-70 k in seconds 2 and 3, a few thousand a second to second 11, then almost none (BASIC waiting for a key: the keyboard is read through its interrupt). Snapshots are in `reference/mame//snap/` (git-ignored). ### Port access counts, pc9801vm, 32 s (selected) | Port | Device | Reads | Writes | Reading | | --- | --- | --- | --- | --- | | 00h / 02h | master PIC | 0 / 4 | 607 / 12 | 606 EOIs (20h) and one ICW1 (11h) on 00h | | 08h / 0Ah | slave PIC | 603 / 7 | 1,207 / 9 | | | 01h-0Fh odd, 11h-1Bh odd, 21h-27h odd | DMA and banks | a few | a few | the BIOS initialising the 8237A | | 31h, 33h, 35h, 37h | system 8255 | 5, 24, 0, 0 | 0, 0, 0, 13 | DIP switches and control | | 42h / 43h | printer 8255 port B (system type) / keyboard 8251 status | 3,401 / 10,240 | 0 / 12 | | | 60h / 62h | text GDC | 22,930 / 0 | 44 / 16 | status polling dominates | | 64h | VSYNC interrupt trigger | | 2 | | | 68h, 6Ah, 6Ch | mode flip-flops, border | | 27, 7, 1 | | | 70h-77h | line counter controls and 8253 (odd) | | | 8253 command writes on 77h: 15 | | 7Ch, 7Eh | GRCG | | 9, 4 | | | **90h** / 92h / 94h | **1 MB FDC** status / data / control | **145,040** / 4,315 / 1,536 | 0 / 5,593 / 195 | the boot's disk probe: the dominant traffic | | A0h / A2h | graphics GDC | 26,051 / 0 | 47 / 19 | | | A1h, A3h, A5h, A9h | character generator | A9h: 6,144 | 384, 384, 12,288, 6,144 | 384 codes set, 32 line selections per code (12,288 = 384 x 32), 6,144 pattern reads and 6,144 writes (384 x 16): the BIOS moving glyph lines, HYPOTHESIS: initialising the user-defined characters | | A8h-AEh | palette | | 20 each | | | BEh | dual-mode FD control | 5,316 | 97 | | | 188h, 18Ah | OPN on the -26K | | 1, 1 | one register write: the BIOS probing the board | ### What differs on the original (pc9801, 32 s) - **55h: 186,986 reads**, 51h: 2, 53h: 9 writes, 57h: 40 writes: the BIOS polls the **320 KB drive subsystem's handshake** and gets nowhere: MAME's `pc9801` fits the Z80 and uPD765 of that subsystem but **no drive ROM** (`-listxml`), so the path is inert in MAME ([fdc.md](fdc.md)). - 90h: 5,009 reads, no BEh (no dual-mode interface), no GRCG writes (7Ch, 7Eh absent: the original has no GRCG, consistent with U6), no character-generator writes (A1h-A9h absent: no user-defined characters on the original, as UND says). ### What the VX adds (32 s) F0h (3 writes) and F2h (2 writes): CPU reset/select and A20; 439h, 43Dh, 4A0h, 7FDDh/7FDFh: later-model registers; 7Eh: 44 GRCG tile writes; 3,072 writes to A5h. ## What MAME can and cannot decide here It can show which ports a BIOS touches, in what order and how often, the SYNC parameters the BIOS writes to each GDC (the next run to make: log the parameter bytes after each SYNC command), and a reference picture of the N88-BASIC(86) screen. It cannot judge timing (its CPU clocks are rounded: 5.000 and 10.000 MHz against 4.9152 and 9.8304: machines.md), the 320 KB path (inert), the kanji ROM on the original and VX (bad dumps, borrowed images), or anything its "preliminary" status leaves open.