# MAME as a detector (closed box, tier 5) MAME 0.285 (`/usr/games/mame`). Its PlayStation 2 machine is **`ps2`** (source `sony/ps2sony.cpp`), status *preliminary* for emulation and save states (`mame -listxml ps2`). It declares `maincpu` "Emotion Engine Core (little)" at 294,912,000 Hz, `vu0` and `vu1` at 294,912,000 Hz, `vu1:vif` (VIF1), `gs:gif` and `dmac` at 147,456,000 Hz, and the IOP side (`iop`, `iop_dma`, `iop_spu`) at **33,868,800 Hz** (OBSERVED; contrast the 36.864 MHz that Sony's SPU2 manual and ps2tek give for PS2 mode: ps2-python C2). It has 63 BIOS sets (SCPH-10000 v5.0 01/17/00 T, the default, to the late slims), all present in `$MAME_ROMPATH/ps2.zip` (ps2-python docs/census.md). The arcade machines `sys246`, `sys256` (namco/namcops2.cpp, a "MIPS R5000" stand-in at 294 MHz), `kpython` and `kpython2` (konami) reuse the same devices. **Licence lines.** Read for these files only (the first line, through the GitHub API at tag `mame0285`, 2026-11-26): `cpu/mips/mips3.cpp` (which holds MAME's R5900), `cpu/mips/ ps2vu.cpp`, `cpu/mips/ps2vif1.cpp`, `cpu/mips/mips1.cpp` (the IOP), `sony/ps2sony.cpp`, `video/ps2gs.cpp`, `video/ps2gif.cpp`, `machine/ps2{dma,intc,sif,timer,mc,pad}.cpp`, `machine/iop{cdvd,dma,intc,sio2,timer}.cpp`, `sound/iopspu.cpp`, `namco/namcops2.cpp`: all say **BSD-3-Clause**. They stay closed, as r3000a-python's decision 3 keeps MAME's psx files closed: MAME is one tree written beside GPL files, its PS2 support is preliminary, and the documents above are better witnesses (decision E9). ## The recipe (run 2026-11-26) ```sh export MAME_ROMPATH="" # holds ps2.zip python -I scripts/mame_trace.py --list-state # prints each CPU's symbols python -I scripts/mame_trace.py --bios scph10000_t --cpu maincpu --start 0 --frames 2 \ --regs SR,Cause --out tests/mame_traces/ee-boot.trace # WINDOW 0.033333 s # 8601780 lines traced (2 min 6 s wall, one process, CPUs 24-31, nice) python -I scripts/mame_trace.py --bios scph10000_t --cpu iop --start 0 --frames 2 \ --regs SR,Cause --out tests/mame_traces/iop-boot.trace # WINDOW 0.033333 s # 564480 lines traced (7 s wall) ``` The script writes `tests/mame_traces/trace.lua` and runs, in `tests/mame_traces/` (git-ignored): ``` nice mame ps2 -bios scph10000_t -rompath "$MAME_ROMPATH" -video none -sound none \ -nothrottle -noreadconfig -skip_gameinfo -debug -debugger none \ -autoboot_script trace.lua -seconds_to_run 5 ``` The Lua issues `trace ,,noloop,{tracelog "SR=%X Cause=%X ",SR,Cause}` before `go` (start 0) and `trace off` after the frames, counting with `emu.add_machine_frame_notifier` (held in a global). The EE trace's first lines (BFC00000h, BEV set: SR = 00400004h): ``` SR=400004 Cause=0 BFC00000: mfc0 $k0,PRId SR=400004 Cause=0 BFC00008: slti $at,$k0,0x59 SR=400004 Cause=0 BFC0000C: bnez $at,0xbfc00024 SR=400004 Cause=0 BFC00014: lui $k0,0xbfc0 SR=400004 Cause=0 BFC00018: ori $k0,$k0,0x0800 SR=400004 Cause=0 BFC0001C: jr $k0 SR=400004 Cause=0 BFC00800: lui $k0,0x0007 SR=400004 Cause=0 BFC00804: ori $k0,$k0,0x3003 SR=400004 Cause=0 BFC00808: mtc0 $k0,Config ``` The IOP's trace starts at the same address with the same instructions and takes the branch (`BFC00024`, then `BFC02000`): one ROM, two CPUs, told apart by PRId (ps2tek "BIOS Boot Process" says PRId >= 59h runs the EE code, tier 3; the traces agree, OBSERVED). **What the window shows.** Of the EE's 8,601,780 instructions, the first ~5,050 are boot code (TLB writes, SYNCs, Config, Status); then the BIOS sits in a five-instruction delay loop on COP0.Count (`mfc0 $v0,Count; subu; sltu; nop; bnez`, at 9FC42548h) for the rest of the two frames. So MAME charges about 258 M instructions per emulated second here, 0.875 per EE cycle (OBSERVED; MAME's own timing, not the hardware's). The IOP ran 564,480 instructions in the same window, 16.9 M/s, which is MAME's IOP clock of 33.8688 MHz at about 2 cycles per instruction (OBSERVED). The first 20,000 EE lines are kept as `tests/mame_traces/ee-boot-head.trace`; the full trace is compressed beside it (both git-ignored). ## MAME's state symbols (from `cpu.state`, `--list-state`, 2026-11-26) - `maincpu`: `PC`, `CURPC`, `SR`, `Cause`, `EPC`, `BadVAddr`, `Count`, `Compare`, `Index`, `Random`, `EntryHi`, `EntryLo0`, `EntryLo1`, `PageMask`, `Wired`, `LLAddr`, `HI`, `LO`, `CCR31`, `FPR0-31` (with `FPS`/`FPD` views), the GPRs by ABI name (`zero at v0 ... ra`) and their **upper 64 bits as `h`** (`a0h`...). Not exposed: HI1/LO1, SA, the cache tags, the TLB entries' contents. A lockstep against MAME can therefore compare all 128 GPR bits but not the second HI/LO pair. - `vu0`: `VF00x..VF31w`, `VI00-VI15`, `ACC[xyzw]`, `I`, `Q`, `R`, `MF`, `SF`, `CF`, `CMSAR0`, `CMSAR1`, `FBRST`, `VPU_STAT`, `TPC`; `vu1` the same plus `P`. - `iop`: `R0-R31`, `HI`, `LO`, `SR`, `Cause`, `EPC`, `BadVAddr`, `PC`. ## What MAME can and cannot decide here - **Can** detect: decode and disassembly differences on the BIOS's boot path; register results for MIPS III instructions on that path; the PRId dispatch. - **Cannot** decide anything: it is tier 5 and preliminary; it does not boot to the browser, so no game code and almost no MMI, FPU or VU code is reachable (one line of the whole 8.6 M-line window matched an MMI or EE-specific multiply mnemonic). Its timing is not the hardware's. - The better tier-5 detector for the core is Play! (BSD-2-Clause, readable) once built in a tool repository, and PCSX2 (GPL-3.0) built and run from emu-tools-gpl if ever needed; neither is fetched into this repository.