# MAME as a detector (closed box, tier 5) MAME 0.285 (`mame`, the system build). Its DS machine is `nds` ("DS", flagged not working), source `nintendo/nds.cpp`. Devices (`mame -listdevices nds`): `arm7` "ARM7 (little) @ 33.51 MHz", `arm9` "ARM946ES @ 67.02 MHz", two address-map banks for the WRAM. **No media**: MAME's nds has no cartridge slot (`mame -listmedia nds`: none), so it can run only the BIOS and firmware boot. ROM set `nds.zip` (in `$MAME_ROMPATH`): `biosnds9.rom` (4,096 bytes, SHA-1 bfaac75f...), `biosnds7.rom` (16,384, 24f67bde...), `firmware.bin` and two more firmware images (nds-python docs/census.md). **Closed box**: the source is never opened. Only the `// license:` lines were read (the first 120 bytes of each file, raw.githubusercontent.com at tag `mame0285`, 2026-11-26): `src/devices/cpu/arm7/arm7.cpp`, `arm7ops.cpp`, `arm7core.h`, `src/mame/nintendo/nds.cpp` and `nds.h` all say **BSD-3-Clause**. As for psx-python's BSD-3 files, whether they may be read is an Open decision; until Aubrey says otherwise they stay closed. ## The recipe (run 2026-11-26) ```sh export MAME_ROMPATH="" # holds nds.zip python -I scripts/mame_trace.py --state # STATE :arm9 AR13 AR14 AR16 CPSR CURFLAGS CURPC FR10 ... GENPC IR13 ... LOGTLB PC R0 ... R15 SR13 ... UR16 python -I scripts/mame_trace.py --cpu arm9 --frames 1 --regs CPSR,R13 --out tests/mame_traces/boot-arm9.trace # TIME 0.016667 s # arm9: 372403 instructions traced to tests/mame_traces/boot-arm9.trace python -I scripts/mame_trace.py --cpu arm7 --frames 1 --regs CPSR,R13 --out tests/mame_traces/boot-arm7.trace # TIME 0.016667 s # arm7: 186206 instructions traced to tests/mame_traces/boot-arm7.trace ``` The script writes `tests/mame_traces/trace.lua` and runs, in `tests/mame_traces/` (git-ignored): ``` nice mame nds -rompath "$MAME_ROMPATH" -video none -sound none -nothrottle -noreadconfig \ -skip_gameinfo -debug -debugger none -autoboot_script trace.lua -seconds_to_run 5 ``` The Lua sets `dbg.visible_cpu` to the device, issues `trace ,,noloop,{tracelog "CPSR=%08X R13=%08X ",CPSR,R13}`, `go`, and after `--frames` frames (counted with `emu.add_machine_frame_notifier`, held in a global) `trace off` and exits. First lines: ``` CPSR=000000D3 R13=00000000 FFFF0000: B 0xFFFF0110 (ARM9, reset at the high vectors) CPSR=000000D3 R13=00000000 00000000: B 0x00000020 (ARM7, reset at 0) ``` ### Quirks found (OBSERVED, 2026-11-26) - `trace file,:arm9,noloop,{tracelog ...}` traces the ARM9's instructions but **drops the action** (no register prefix); the same form for `:arm7`, MAME's default visible CPU, keeps it. Making the device visible first and leaving the CPU field empty works for both. Two traces in one run therefore need care; the script traces one CPU per run. - `noloop` does not fold the BIOS's two-instruction delay loop (`SUB R0,#1; BGT`): the first probe, 60 frames of both CPUs, wrote 475 MB for the ARM9 and was stopped (moved aside to `trash/`). One frame is 372,403 ARM9 lines (9.9 MB). - The ARM9 has **no CP15 state symbols** (no control register, TCM or PU values to trace); CP15 writes are visible only as MCR lines with the source register. `LOGTLB` (an MMU leftover) is listed. - In MAME's run, the ARM9 BIOS's first CP15 writes are: control 00002078h, invalidate I-cache, invalidate D-cache, drain write buffer, DTCM region 0080000Ah (base 00800000h, size code 5), then control 00012078h (DTCM on). That is the BIOS's behaviour as MAME runs it; it says nothing about MAME's CP15 model. (`--regs R0,R4` trace.) ## What MAME can and cannot decide - It **can** find differences in instruction results over the BIOS and firmware boot: register values, branches taken, ARM/Thumb switches (the ARM9 BIOS's 20th instruction is a BLX into a Thumb delay loop, so v5 interworking is exercised from the start). - It **cannot judge timing.** OBSERVED: in one frame (1/60 s by MAME's clock, which is not the DS's 59.83 Hz refresh) MAME ran 372,403 ARM9 instructions (67.02 MHz / 22.34 M = 3.00 core cycles each) and 186,206 ARM7 instructions (33.51 MHz / 11.17 M = 3.00 each): a flat 3 cycles per instruction on both CPUs, whatever the memory, while DDI 0165B and GBATEK give 1 to 20+ cycles by instruction and region (timing.md). MAME's counts are a model, not a measurement. - It cannot test cartridges (no slot), the caches or the TCMs' timing, or anything the BIOS does not reach. Its value is a rung-2 lockstep over the boot: the build compares register writes instruction by instruction and stops at the first divergence that a timing difference explains (an IPC or interrupt seen at a different instruction).