# MAME 0.285 as a closed-box detector (tier 5) MAME is run as a binary; its source is not opened (this batch's brief holds MAME's drivers closed, although `v30mz.cpp` carries a BSD-3-Clause `license:` line: open decision 4). One MAME process of ours at a time, short runs, `nice`, CPUs 24-31. ## Machines and devices `mame -listdevices wswan`: `maincpu NEC V30MZ @ 3.07 MHz`, `vdp Bandai WonderSwan VDP`, `custom WonderSwan Custom Sound`, `cartslot @ 384 kHz`. `wscolor` and `pockchv2` are clones. `wswan` boots with no cartridge; `wscolor` refuses to start without one ("Images must be mounted for the following devices: cartridge"). ## Register symbols From a Lua listing of `manager.machine.devices[":maincpu"].state` (2026-11-26): `AW BW CW DW SP BP IX IY PS SS DS0 DS1 PSW IP PFP CURPC CURFLAGS GENPC V`, NEC names throughout; `totalcycles` is the debugger's running clock count. ## Recipe 1: the boot ROM from reset (run) ```sh # with MAME_ROMPATH set (the family's profile) python -I scripts/mame_trace.py --machine wswan --frames 1 ``` Result, 2026-11-26: `FRAMES 1 TIME 0.013250`, **7,148 instructions** in `reference/mame/trace.log`, `totalcycles` 0 to 40,703 (one frame is 159 x 256 = 40,704 clocks, WSDEV "Timing"). First lines: ``` ... PS=FFFF ... PSW=F002 T=0 FFFF0: br 0FF00h:0h ... PS=FF00 ... PSW=F002 T=7 FF000: di ... PS=FF00 ... PSW=F002 T=11 FF001: mov aw,0h ``` The reset state (CS FFFFh, IP 0, FLAGS F002h) equals WSDEV's console power-on table. The per-instruction charges this trace implies are in timing.md (C1: taken conditional branches cost 10-11 in MAME, 4 in the PUM). One `rep` in the boot ROM runs 24,579 clocks (a RAM clear). ## Recipe 2: FluBBa's WSCpuTest (run) ```sh python -I scripts/fetch_references.py # fetches reference/tests/WSCpuTest-v0.7.1.zip unzip -o reference/tests/WSCpuTest-v0.7.1.zip WSCpuTest.wsc -d reference/tests/WSCpuTest-v0.7.1 python -I scripts/mame_trace.py --machine wscolor \ --cart reference/tests/WSCpuTest-v0.7.1/WSCpuTest.wsc --no-trace --snap --frames 2400 --press-a 300 ``` `--press-a` holds button A (`:BUTTONS` / `Button A`) for 6 frames to start "Test All". Result, 2026-11-26, 31.8 s emulated: the snapshot (`reference/mame/snap/wscolor/0000.png`) shows SUB and CMP bytes Ok, then **"NEG bytes ... Input: 0x00 ... Expected Result: Value 0x0000 Flags 0xf246; Tested Result: Value 0x0000 Flags 0xfa56"**: MAME sets OF and AF on NEG 0. MAME is therefore not a judge of flags (flags-and-undocumented.md). Two traps met: MAME given the release **zip** (README, source and ROM inside) on `wswan` loaded nothing usable and died with "REPNC is not supported by v30mz" at 0FFFF1h; on `wscolor` it showed a white screen. Extract the `.wsc` first. ## Using a trace in lockstep Compare instruction addresses and registers; compare flags only for instructions whose flag rules WSCPU covers and MAME passes; compare clocks only as a detector (C1). The board's recipe (wonderswan-python docs/mame-oracle.md) adds an I/O-write log.