Metadata-Version: 2.5 Name: spc700-python Version: 0.1.0.dev0 Summary: Readable, pure-Python Sony SPC700 (SNES S-SMP CPU) cycle-exact core reference implementation Author: alewman License: MIT License Copyright (c) 2026 alewman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. License-File: LICENSE Classifier: Development Status :: 3 - Alpha Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Topic :: Software Development :: Libraries Classifier: Topic :: System :: Emulators Requires-Python: >=3.11 Provides-Extra: dev Requires-Dist: pytest>=8; extra == 'dev' Requires-Dist: ruff==0.16.8; extra == 'dev' Description-Content-Type: text/markdown # 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-10-30): core built, rungs 0-4 of [docs/validation.md](docs/validation.md) recorded there; rung 5 (a second per-cycle emulator) is a later session, rung 6 is the board's.** 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, and the SPC700/S-SMP sources of bsnes, ares, Mesen2, blargg's snes_spc (in libgme) and MAME 0.285. ```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, `/usr/games/mame` 0.285. 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.