# spc700-python A readable, pure-Python **Sony SPC700** CPU core: the 8-bit processor inside the SNES's **S-SMP** sound chip, which runs the sound driver and feeds the S-DSP. "S-SMP" is the whole Sony die (SPC700 core, 64-byte IPL ROM, three timers, four CPU I/O ports, the TEST/CONTROL registers and the DSP address and data ports); this repository is only the CPU. The board, [snes-python](../snes-python), owns everything else, including the S-DSP, which lives inside snes-python rather than in a repository of its own. **Status (2026-11-19): core built, rungs 0-4 of [docs/validation.md](docs/validation.md) recorded there; rung 5 (a second per-cycle emulator: ares, or Mesen2 strictly as a closed box) is a later session, rung 6 is the board's. Provenance rewrite (Wave 2) done: docs only, no code behaviour changed ([docs/provenance.md](docs/provenance.md)); 1,774 tests pass.** All 256 opcodes, one bus callback per SPC700 cycle in chip order, dummy reads and internal cycles included: on the S-SMP a dummy read of `$FD`-`$FF` clears a timer counter, and internal cycles take their own wait states when the TEST register slows the bus. No dependencies, CPython and PyPy (Python 3.11+). Correct, not fast. Local git only for now. ```python from spc700_python import SPC700 memory = bytearray(0x10000) cpu = SPC700(memory.__getitem__, memory.__setitem__) # idle() is optional cycles = cpu.step() # SPC700 cycles == bus callbacks made ``` The host advances its devices inside `read_byte`, `write_byte` and `idle`, never by adding `step()`'s return value on top. Inside a callback it may read `cpu.psw`, `cpu.opcode`, `cpu.cycle` (0 = the fetch), `cpu.stopped` and, for tooling, `cpu.dummy`. The contract is in [docs/handoff-brief.md](docs/handoff-brief.md); the facts behind every handler in [`docs/`](docs/README.md), each with its source and tier. Tooling, at the family's bar: `CPUState`, `disasm`, `DebugSession` (breakpoints, and bus watchpoints that see dummy reads and internal cycles), JSONL traces ([docs/trace-schema.md](docs/trace-schema.md)), a command debugger, and: ```sh python -m spc700_python FILE.spc # a snapshot, or a raw program: python -m spc700_python PROGRAM.bin --org 0x200 --max-cycles 5000000 --trace out.jsonl python -m spc700_python PROGRAM.bin --debug ``` running in `spc700_python.harness`, a host that is not a SNES, and printing the `$F4` port log. ## What is fetched Nothing third-party is committed. `scripts/fetch_references.py` rebuilds `reference/` from `scripts/pinned_files.json` (6 files pinned by SHA-256: anomie's SPC700, SPC700 cycle and timing documents, fullsnes, gilyon's snes-tests release, blargg's 2010 SNES test ROMs) and `scripts/pinned_repos.json` (9 repositories at full commit SHAs, sparse where large): SingleStepTests spc700 and its JSMoo generator, gilyon's snes-tests, PeterLemon's SNES tests, ares (ISC) and MAME 0.285's BSD-3 `cpu/spc700`. bsnes, Mesen2 and blargg's snes_spc (libgme) are GPL/LGPL: their pins are kept for lineage with `"fetch": false` and they are closed boxes only (Wave 2, docs/provenance.md). ```sh python scripts/fetch_references.py # everything missing (~70 MB) python scripts/fetch_references.py --verify # check what is present python -I scripts/build_referees.py # spctest programs, IPL ROM python -I scripts/anomie_opcodes.py # tests/anomie_opcodes.json python -I scripts/sst_survey.py # the numbers in docs/validation.md python -I scripts/mame_trace.py ROM.sfc # MAME 0.285 S-SMP trace + audit ``` They need `git`, `curl` and, for the MAME recipe, MAME 0.285 (`mame` on the path, or `MAME`). No sudo. Anything that reads `reference/` runs with `python -I`. ## Scripts | Script | What | | --- | --- | | `scripts/fetch_references.py` | the pinned documents, test ROMs and source trees | | `scripts/build_referees.py` | cuts the three raw SPC700 test programs out of gilyon's `spctest.sfc`; writes the IPL ROM from anomie's doc after checking MAME's CRC | | `scripts/anomie_opcodes.py` | anomie's opcode table (mnemonic, bytes, cycles, flags) as JSON | | `scripts/sst_survey.py` | measures SingleStepTests spc700 against anomie's table and the documented quirks | | `scripts/gen_opcode_table.py` | `src/spc700_python/_opcodes.py` from anomie's table | | `scripts/mame_trace.py` | MAME 0.285 per-instruction S-SMP trace of a SNES ROM, its cycle audit, the S-SMP's `$F4` port writes, or (`--io`) the log the rung 4 replay needs ([docs/mame-oracle.md](docs/mame-oracle.md)) | ## Licence MIT (see `LICENSE`), for what is in this repository. The fetched material keeps its own terms, recorded per entry in the pin lists. The ares ISC notice and the other permissive notices are in [NOTICE](NOTICE).