# Validation: every oracle, its tier, and the plan ## Oracle tiers The family's rule (z80-python `docs/validation.md`, sm83-python): rank an oracle by **where its expected values came from**; a lower tier detects, the highest tier that covers a claim decides it. | Tier | Meaning here | | --- | --- | | **hardware-captured** | expected values recorded from a real S-SMP. *None exists for the SPC700*: no per-instruction or per-cycle capture has been published | | **hardware-verified** | a self-checking ROM whose author ran it on a SNES and states it passes there (PeterLemon: "I only test with a real SNES using a SD2SNES"; expected screens in the repo) | | **hardware-run, author's expectations** | a self-checking ROM whose expected values the author wrote by hand and whose history shows hardware runs, without a per-test statement (gilyon's spctest: its sibling cputest commit "Disable (dp,X) E=1 test that fails on real SNES") | | **research documentation** | anomie's docs (with per-cycle notes on what blargg verified on hardware), fullsnes: from hardware experiments, not all traceable to a published test | | **die-traced** | *none*: no S-SMP die shot, netlist or decap study was found (searched 2026-10-21) | | **emulator-derived** | values produced by an emulator: SingleStepTests spc700 (JSMoo, from higan's timings; MIT), ares (ISC, read), MAME (run; `cpu/spc700` BSD-3 read), and bsnes, Mesen2, snes_spc as closed boxes only. Detectors only | The consequence: the **bus schedule** (which cycle reads, writes or idles, and where) has no oracle above research documentation, and on the points where anomie is unsure (C4, C6, C7) the only specific source is emulator-derived. Instruction **results** have two hardware-run suites (gilyon, PeterLemon) on top of the emulators. ## The oracles ### SingleStepTests `spc700` — emulator-derived, the volume detector - Pin: `SingleStepTests/spc700` @ `67d15f492b27` (2024-05-10), MIT, 7 MB, `v1/00.json` .. `v1/ff.json`; no README. - **256 files × 1,000 cases**. Each case: initial and final `pc a x y sp psw`, sparse RAM, and `cycles`: one `[address, data, kind]` per SPC700 cycle, kind `read`, `write` or `wait`, opcode fetch first. `wait` cycles have address and data `null`; dummy reads are `read` with data `null` (C9). - Provenance: generated by JSMoo (`raddad772/jsmoo` @ `359d18e6ea8a`, `misc/code_generation/spc700_test_generator.js`): "the timings are taken from Higan, which claims 100% compatability ... we do not simulate extra hardware registers here, clock dividers, timers". So: emulator-derived, byuu's microcode as re-expressed by JSMoo; the generator writes `SLEEP` and `STOP` as three dummy-read/internal pairs (C5). - Measured here (2026-10-21, `python -I scripts/sst_survey.py`, 7 s): - **cycle counts agree with anomie's table on 254/256 opcodes, every case, both paths of all 28 conditionals**; the exceptions are SLEEP/STOP (anomie `?`, corpus 7); - 228 opcodes have a single kind sequence over all 1,000 cases; the 28 conditionals have exactly two; - cycle kinds over all cases: 803,000 reads with data, 64,000 dummy reads (data `null`), 120,000 writes, 195,940 internal; no internal cycle has an address; - initial PSW has P set in 127,929 of 256,000 cases, so direct page `$01xx` is exercised throughout; - read-before-write (U1) holds on every case: `8F C4 C5 C6 C7 D4 D5 D7` 1,000/1,000; `AF` 0/1,000; `FA` 6/1,000 (only where source = destination); `DA` reads the low byte only; - **DIV** final A, Y, V equal anomie's 9-step algorithm on 1,000/1,000; **DAA/DAS** final A, C equal anomie's rule on 2,000/2,000; - fullsnes' internal-cycle wait counts fit within the corpus' internal and dummy-read cycles for 255 opcodes; `PCALL` is the exception (fullsnes 3, corpus 2; C3, C6). - Use: rung 1, all 256 files; compare registers, RAM, and every cycle's kind and address; data on non-null entries; `EF`/`FF` registers only. ### gilyon `snes-tests` spctest — hardware-run, author's expectations - Pin: `gilyon/snes-tests` @ `5ecdf555da92` (2025-06-10), MIT; built ROMs from the v1.4 release zip (SHA-256 `c3a39e15…`). - **1,368 tests** (`tests.txt` holds Test 0000 to Test 0557, numbered in hexadecimal: $558 tests; earlier revisions of this page said 558): every opcode except SLEEP and STOP, every addressing mode, with P = 0 and P = 1, flag edge cases; expected values written by hand in `spctest/make_tests.py` and listed in `tests.txt`. Does *not* test cycle counts, dummy reads, timers or the DSP (its README). - The ROM is an S-CPU program that uploads three raw SPC700 programs (`spc_tests0..2`, at `$0300`) and reports through the ports; `scripts/build_referees.py spctest` cuts them out of `spctest.sfc` (file offsets `$0A79`, `$8000`, `$10000`, each starting `8F 00 F4 8F 00 F1`). **They run without a SNES**: the program waits for `$F5 = 1`, reads the starting test number from `$F6/$F7`, runs, and writes `$F4 = 1` on success or `$F4 = 2` then `3` with the failing test's results in `$F5`-`$F7` (`spc_common.inc`). A harness answers those port reads; that is rung 2. - Measured here: anomie's DIV and DAA/DAS rules reproduce all 7 DIV, 9 DAA and 7 DAS expectations; MAME 0.285 runs the ROM to "Success" at test $0557, the last (mame-oracle.md). - Tier caveat: no per-test hardware statement. Where it agrees with the emulators and anomie it confirms; where it disagreed it would need a hardware run. ### PeterLemon `CPUTest/SPC700` — hardware-verified - Pin: `PeterLemon/SNES` @ `350b394e86ec` (2022-09-19), no licence stated, sparse `/CPUTest/SPC700/` and `/SPC700/`. - 7 programs (ADC, AND, DEC, EOR, INC, ORA, SBC), 162 sub-tests over the addressing modes, each reporting `$0n` (pass) or `$8n` (fail) on `$F4` and playing a pass/fail sample; a `.png` of the expected screen per program; each exists as `.sfc` (with the S-CPU side) and as a standalone `.spc`. The README: "I only test with a real SNES using a SD2SNES Cartridge". - Needs timer 0 (`SPCWaitSHIFTMS` waits on the 8 kHz timer) and DSP writes (to start the sample), so the harness needs a timer and a DSP-port sink. - Measured here: MAME 0.285 passes all 162 (mame-oracle.md). ### anomie's SPC700 documents — research documentation - Pins (mirror `naffnuff/SnesEmulator` @ `b8205a74da10`, because romhacking.net answers 403 to scripted downloads): *SPC700 Doc* rev 1162 (2009-07-19, SHA-256 `c5c71f72…`), *SPC700 Cycle Doc* rev 1126 (2007-04-21, `6c6825c4…`), *SNES Timing Doc* (`a26b6a88…`). - The opcode table (`scripts/anomie_opcodes.py` → `tests/anomie_opcodes.json`, 256 entries), the DIV algorithm, the DAA/DAS rule, the register descriptions, the IPL ROM bytes (which match MAME's `spc700.rom` CRC and SHA-1 exactly), and per-group cycle tables whose notes say which cycles "blargg verified" on hardware and which are guesses. ### fullsnes — research documentation - Pin: `https://problemkaputt.de/fullsnes.txt` as served 2026-10-21 (`d79dbec9…`, live document: the URL serves the newest text). - Sections "SNES APU SPC700 CPU Overview / Load/Store / ALU / Jump/Control / I/O Ports": flags, the store read rule, H for ADDW/SUBW, the TEST and CONTROL bits, reset state, "no interrupt sources", and the per-opcode "Waitstates on Internal Cycles" table (C3). ### blargg's 2010 SNES test ROMs — hardware research, no pass criteria - Pin: `blargg_2010-03-14.zip` from SNES Central article 1115 (SHA-256 `a1fc4278…`), no licence stated. - `test_timer_speed*`, `test_timer_stop*`, `test_speed`, `speed_2_freezes2`, `test_ram_disable_ipl`, `timer_at_power_reset`, and `exec_io_tests` (`1-test_exec_from_io`, `2-test_single_instr`, `3-test_write_disable`, `4-test_ram_disable`); `notes.txt` holds TEST speed and timer measurements that match byuu's wait-state model (ares `sfc/smp/timing.cpp`). Undocumented: SNES Central "can only guess what many tests do". No expected results are published, so they detect only by comparison with a reference emulator. Relevant to U10, C2, C3 and B2-B3 (the board). ### Emulator sources — emulator-derived detectors | Source | Pin | What it is | | --- | --- | --- | | ares | `ares-emulator/ares` @ `9408cb43d494` (2026-10-06), ISC, sparse `component/processor/spc700`, `sfc/smp` | byuu's per-cycle SPC700 and S-SMP, read and cited (NOTICE); the same microcode SingleStepTests' generator cites; the TEST wait-state model; DIV closed form | | MAME 0.285 | `mamedev/mame` @ `f379cd060ac3` (tag `mame0285`), sparse `cpu/spc700` (BSD-3-Clause, read) | instruction-level; run as a closed box for its S-SMP (`machine/s_smp`, `sound/s_dsp`: LGPL-2.1+, never opened); [mame-oracle.md](mame-oracle.md) | | bsnes, Mesen2, snes_spc (libgme) | pins kept for lineage, `"fetch": false` | GPL-3.0 / GPL-3.0 / LGPL-2.1: closed boxes only, never opened. Wave 2 (2026-11-19) withdrew what earlier text said about their source (provenance.md) | ### .spc files — a board-free harness for real code An `.spc` file is a snapshot of the whole sound unit (SPC700 registers, 64 KiB RAM, the 128 DSP registers, the 64 bytes under the IPL ROM; header "SNES-SPC700 Sound File Data v0.30", layout as the SPC file format document gives it: registers at $25-$2B, RAM at $100, DSP registers at $10100, the IPL-area bytes at $101C0). Loading one into the core plus a small S-SMP model (timers, ports reading 0 or a script, DSP register file without audio) runs a game's real sound driver with no S-CPU and no SNES board. Sources: PeterLemon's homebrew `.spc` files (pinned above); game rips from snesmusic.org / Zophar's Domain (**never fetched by the scripts, never committed**); `.spc` dumps any SNES emulator can write from the player's own ROMs (`NO_INTRO_DIR`; never commit). With the DSP model off they test the CPU and timers only; a DSP-sample comparison belongs to snes-python. ### Not available - No Sony SPC700 manual with an opcode table and timings is public. - No hardware-captured per-cycle corpus; no die study, netlist or HDL traced from an S-SMP die was found. FPGA SNES cores were not examined here; if one claims a die tracing, it belongs in the die-traced tier after checking. ## Results (2026-10-30, CPython 3.14 and PyPy 7.3.20 / 3.11) | Rung | Tier | Result | | --- | --- | --- | | 0 | research documentation | table equals `tests/anomie_opcodes.json` on all 256; every opcode's and path's (kind, address) schedule, from a template written from timing.md, on 300 random states; cycle counts, lengths, flags touched; readability | | 1 | emulator-derived | **256 files x 1,000 = 256,000 cases, no disagreement**: registers, PSW, RAM, every cycle's kind and address, data where non-null; `EF`/`FF` registers only. CPython 37 s, PyPy 40 s | | 2 | hardware-run, author's expectations | **1,368/1,368**, 3 programs, test numbers 0 to $557 in order with no gap, 184,246 cycles, 51,549 instructions. CPython 0.05 s, PyPy under 1 s. A DAA with its adjustments removed fails the gate | | 3 | hardware-verified | **162/162, no `$8n`**, 7 programs, raw from `$0200` (172,460,628 cycles) and again from the `.spc` snapshots (169,869,393 cycles). CPython 130 s, PyPy 9 s for both forms. An ADC that flips C fails the gate | | 4 | emulator-derived | **6 traces, 45,428,492 instructions, no divergence**: registers and cycle deltas after every instruction; 12,360,645 I/O reads answered from MAME's log, 908,925 I/O writes compared with it | Rung 3's two forms: `CPUTest/SPC700/ADC/SPC700ADC.spc` is the raw program the `.sfc` uploads to `$0200`, despite the extension; the top-level `SPC700ADC.spc` is a true snapshot taken just after sub-test 1, at its `$F4` store, so its run computes sub-tests 2 onward and only re-reports the first. The raw programs are the 162; the snapshots are a second path through the `.spc` loader. Rung 4's traces (`scripts/mame_trace.py ROM --io --seconds 30`, spctest 25 s, attract mode, no input), from the IPL ROM's entry, with RAM starting at zero and the IPL ROM from `reference/build/iplrom.bin`: | Trace | Driver | Instructions | Opcodes | I/O reads | I/O writes | | --- | --- | --- | --- | --- | --- | | gilyon spctest | test ROM | 5,807,100 | 254 | 2,759,549 | 80,419 | | Super Mario World | N-SPC | 7,939,388 | 117 | 1,140,440 | 140,681 | | Chrono Trigger | Square | 7,598,257 | 131 | 1,466,114 | 246,933 | | Donkey Kong Country | Rare | 8,812,716 | 56 | 3,665,912 | 99,759 | | Final Fantasy III | Square | 7,377,608 | 122 | 2,121,796 | 214,951 | | Street Fighter II | Capcom | 7,893,423 | 112 | 1,206,834 | 126,182 | The core made 875,888 reads of `$F0`-`$FF` that MAME's instruction-level core does not (store destinations, U1). One detector hit, explained: MAME's `SUBOP_ADC` macro expands its second argument twice, so `OP_ADCM` reads an ADC's memory destination twice; DKC's `ADC $F2,#$04` logged `R R W`. anomie groups 10, 18, 19 ("Verified by blargg") and SingleStepTests have one read, so the core stays, and the replay drops the repeat (89 times, all in DKC; research documentation over an emulator). No `.spc` rips were run: a snapshot has no MAME trace to compare with. ## The plan, in oracle-tier order Each rung is cheaper than the next and earns one claim. Do not reorder. | Rung | Gate | Tier | Claim earned | | --- | --- | --- | --- | | 0 | Generated opcode table == `tests/anomie_opcodes.json` (mnemonic, bytes, cycles, flags affected); per opcode and path, the core's (kind, address) sequence == [timing.md](timing.md)'s group row on random states; cycle count == anomie on every opcode; readability test | research documentation | the schedule anomie and fullsnes describe, where they are specific | | 1 | SingleStepTests spc700: 256 files × 1,000, registers, PSW, RAM, every cycle's kind and address, data where non-null (C9); `EF`/`FF` registers only (C5). Record each disagreement with anomie in a test comment (C4, C6, C7) | emulator-derived (detector, high volume) | agreement with higan's microcode everywhere | | 2 | gilyon spctest in `spc700_python.harness`: the three cut programs from `$0300`, the harness playing the S-CPU side of the port protocol; all 1,368 pass; CPython and PyPy, wall time recorded | hardware-run, author's expectations | every opcode's result and flags on hand-chosen edge cases, P = 0 and 1 | | 3 | PeterLemon `CPUTest/SPC700/*.spc` in the harness with timer 0 and a DSP-register sink: all 162 sub-tests write `$0n`, none `$8n` | hardware-verified | ADC/AND/DEC/EOR/INC/ORA/SBC across addressing modes, as a real SNES computes them | | 4 | MAME replay ([mame-oracle.md](mame-oracle.md) "Use") on spctest and on commercial drivers: per-instruction registers and cycle deltas, port/timer reads fed from MAME's log; `.spc` snapshots as a second source of real driver code | emulator-derived | long real-code agreement; every divergence explained by a higher tier | | 5 | Second per-cycle emulator: a small ares harness (ISC; or Mesen2 strictly as a closed box, through its trace logger, with no hook that needs its source) that dumps per-cycle bus activity for SingleStepTests' initial states, diffed against the core; expected differences limited to C4 | emulator-derived, independent of SST's generator | the bus schedule confirmed by two cores that do not share code | | 6 | Through snes-python: blargg's 2010 timer/speed/exec-from-I/O ROMs compared with ares' output (or a closed-box run), TEST wait states, timer reads during stores (U1, B2) | hardware research | the parts only a board exercises | Rung 5 has not been run: it is a follow-up session (handoff-brief.md). Rung 6 is the board's acceptance, not this repository's; failures it traces to the core come back here as issues or PRs with a failing core-level test.