# MAME as a detector: the recipe that was run MAME 0.285 (`mame -version`: "0.285 (unknown)"), run as a closed box. Its PC files are BSD-3-Clause by their `license:` lines (checked 2026-11-26 at tag `mame0285` by reading only the first line of each: `pc/ibmpc.cpp`, `pc/ibmpcjr.cpp`, `pc/tandy1t.cpp`, `machine/genpc.cpp`, `cpu/i86/i86.cpp`, `machine/am9517a.cpp`, `machine/pit8253.cpp`, `machine/pic8259.cpp`, `machine/i8255.cpp`, `machine/upd765.cpp`, `video/mc6845.cpp`, `bus/isa/{cga,mda,ega,fdc}.cpp`, `bus/pc_kbd/{pc83,pcxt83,keyboards}.cpp`, `sound/sn76496.cpp`, `cpu/mcs48/mcs48.cpp`); nothing of their bodies was fetched or read. MAME's own status for `ibm5150`: `driver status="imperfect"`, graphics imperfect, save states unsupported (`-listxml`). Tier 5: a detector, never a judge. Its i86 core is not cycle-exact on the bus (no claim either way was checked; treat every MAME timing as unproven). ## The recipe `scripts/mame_run.py` runs the machine headless with Lua read and write taps on the 8088's I/O space (ports 000h-3FFh), logs emulated time, CS:IP, direction, port and data, takes a screenshot after N frames and prints access counts per port. Output lands in git-ignored `tests/mame_traces/-/`. ```text MAME_ROMPATH=... python3 -I scripts/mame_run.py --frames 3000 --no-hdc ``` That is `mame ibm5150 -bios rev3 -ramsize 640K -isa4 "" -video none -sound none -nothrottle -noreadconfig -skip_gameinfo -autoboot_script tap.lua`. `-isa4 ""` removes the hard-disk controller MAME fits by default (its BIOS otherwise polls ports 320h-322h forever). ## Runs on 2026-11-26 (one MAME process at a time, `nice`, CPUs 24-31) | Run | Emulated | Wall | Accesses logged | Result | | --- | ---: | ---: | ---: | --- | | rev3, 64 KB, HDC fitted, 600 frames | 10.03 s | 7.3 s | 229,247 | POST error "201" (RAM size vs switches), then the HDC BIOS polling 320h-322h (moved to `trash/`) | | rev3, 640 KB, no HDC, 1,200 frames | 20.05 s | 2.6 s | 1,036 | still in the memory test (moved to `trash/`) | | **rev3, 640 KB, no HDC, 3,000 frames** | **50.08 s** | **8.1 s** | **269,750** | **ROM BASIC "Version C1.10", "62940 Bytes free"** on the screenshot | From the third run (OBSERVED, closed box): - Chip programming in order: `A0h<-00` (NMI off), `83h<-00`, `3D8h<-00`, `3B8h<-01`, `63h<-99h` (PPI), `61h<-FCh`, then at 0.0567 s DMA command `08h<-04`, PIT `43h<-54h`, `41h<-00` and latch reads (the BIOS's timer-1 test), `41h<-12h` (refresh count 18), DMA `0Dh` master clear, `0Bh<-58h` (ch0 read, autoinit), `08h<-00`, `0Ah<-00` (unmask ch0), modes `41h/42h/43h`. - PIC: `20h<-13h`, `21h<-08h`, `21h<-09h` at 2.736 s. PIT ch0: `43h<-36h`, `40h<-00`, `40h<-00` at 3.248 s. Timer EOIs every 0.0549242-0.0549265 s (65536 / 1.19318 MHz = 54.925 ms). - CGA: the BIOS writes the 80x25 6845 row `71 50 5A 0A 1F 06 19 1C 02 07 06 07 00 00 00 00`, mode `29h`, colour `30h`; 5,094 reads of 3DAh (retrace waits). - Floppy: first DOR write at 39.13 s, 262,430 reads of 3F4h (polling for RQM) until 49.28 s. - Port totals: 20h 188 writes, 21h 17, 40h-43h 29 writes and 14 reads, 60h-63h 22 writes and 188 reads, 3D4/3D5 744 each, 3F5 95 writes and 32 reads. ## What MAME can and cannot decide here It can show the BIOS's programming order and values (they are the BIOS's, MAME only carries them out), the boot timeline to within its CPU timing, and a picture to compare. It cannot decide bus timing (refresh cost, wait states, CGA snow: not examined in MAME, and a detector could not judge them anyway), PIT edge cases, or the keyboard (its default 5150 keyboard is a Keytronic 3270 model with an 8051; IBM's 5150 keyboard ROM is undumped). Those go to the tier-1 sources in [validation.md](validation.md).