# Handoff: build the S-DSP inside snes-python Rewritten 2026-11-19 for the restart (`docs/restart.md`). The earlier brief told the builder to read blargg's snes_spc `SPC_DSP.cpp` (LGPL-2.1) and write "a readable transcription of its behaviour"; that route is closed. This brief replaces it. ## Context Chips are cores, boards compose cores; a chip used by one board stays in the board behind a pin-shaped interface and an import-boundary test (Aubrey, 2026-10-21). The S-DSP has no consumer outside the SNES family, so it is `snes_python/dsp/`. Siblings: `spc700-python` (the S-SMP's CPU, used as is), `65816-python`, and the board. Binding rules (restart.md, the family charter): - **Sources.** Write from anomie's S-DSP document (r1160 and r1212-jwdonal), fullsnes ("SNES APU ..." chapters), the SNESdev wiki ("S-DSP registers", "DSP envelopes", "BRR samples"), blargg's `notes.txt` and the names of his hardware-verified spc_dsp6 tests, and ares (ISC, notice kept) for separate formulas only (the Gaussian table generator; ares `sfc/dsp` is "a rewrite of blargg's SPC_DSP", so its code structure is not taken). ares `sfc/smp` may be used as ISC code with its notice for the S-SMP side. - **Never read** snes_spc (any file but `readme.txt` and `snes_spc.txt`), bsnes, higan, Mesen2, MesenCE, snes9x, game-music-emu, MAME's `sound/s_dsp.cpp`, or the archived first build. Code fragments attributed to such programs inside documents stay unused (anomie's Mednafen counter). - **snes_spc is a closed box.** It is built unmodified from the pinned archive and driven through its documented C API by `spc_dump.cpp`, all inside the GPL tool snes-spc (`$EMU_TOOLS_GPL/tools/snes-spc/build.sh` builds `build/spc_dump`; this repository fetches and keeps none of it since 2026-11-24); its outputs are tagged OBSERVED. Compiler diagnostics from building it quote its source and are not shown. - **Rung checks compare outputs**, never a step table extracted from LGPL source, never "blargg's names" in docstrings: docstrings name anomie's operations (S1-S9) and the document section. - **Evidence tags** on every rule: DOC (section), TEST ROM, OBSERVED (model and pin), HYPOTHESIS. SPDX header on every file (`MIT`, or `MIT AND ISC` where an ares formula is taken). - **A difference from the referee is written down, not fixed**, unless a document says the module is wrong. Where the documents are silent or ambiguous, the reading that agrees with the referee may be taken, tagged OBSERVED. - Python floor 3.11 (PyPy); reference code is correct, not fast; `python -I` for scripts that read `reference/`; `nice` and `PYPY_GC_NURSERY=1M` for long runs. ### Read, in this order 1. [README.md](README.md), [start-here.md](start-here.md), [timing.md](timing.md), [undocumented-behavior.md](undocumented-behavior.md), [interface.md](interface.md), [validation.md](validation.md). 2. `reference/dsp/docs/anomie-s-dsp-r1212-jwdonal.txt` whole; fullsnes "SNES APU DSP ..." and "SNES APU Low Level Timings"; the three wiki pages. 3. `spc700-python/docs/handoff-brief.md`, "The bus contract". Then: `python -I scripts/dsp_fetch_references.py`, `"$EMU_TOOLS_GPL/tools/snes-spc/build.sh"` and `python -I scripts/dsp_build_referees.py` (which checks the build), `python -I scripts/dsp_make_spc.py reference/dsp/spc/synthetic`, `python -I scripts/dsp_run_referee.py`: the output hashes must equal validation.md's table. ## Decisions already made (Aubrey, 2026-10-21; restated) - In the board, import boundary enforced. - A per-step model: one step per S-SMP clock, the 32-step schedule of timing.md. - ARAM is one 64 KiB `bytearray` shared with the S-SMP. - The power-on register table is a constructor argument. Its default is all zeros (HYPOTHESIS: no document gives a table; anomie and fullsnes say power-on values are chip-dependent garbage), not snes_spc's table. - `$F2`/`$F3` decoding is the S-SMP side's (`smp.py`); 32 kHz stereo out. - Game `.spc` files are fetched per run into `reference/dsp/spc/games/` and never committed. - Hardware capture is deferred. ## The rungs 0. **Tables.** The Gaussian table from ares's formula equals the values printed by anomie and fullsnes; its SHA-256 is asserted. Counter rates and offsets as anomie and fullsnes give them. The import-boundary test. 1. **Units from document statements.** BRR shift and filter cases, the clamp-then-clip glitches fullsnes lists, the interpolation overflow example fullsnes gives, envelope modes and the four update steps, the noise generator's period, register mirrors, ENDX clearing, the KON sequence's five empty samples. 2. **Synthetic `.spc` cases against the referee, value-exact.** `scripts/dsp_make_spc.py` writes small S-SMP programs that drive the DSP at chosen phases. They run on spc700-python + `smp.py` + `dsp/` (the referee no longer gives write logs, so there is no DSP-only replay) and are compared sample by sample with `spc_dump`'s output, and register file by register file with its per-sample snapshots (`scripts/dsp_compare.py`). Differences are listed in validation.md. 3. **Game `.spc` files against the referee.** The same comparison over tracks from many sound drivers. A `.spc` holds no internal DSP or timer state, so the start-up convention is part of what is compared (C18); report first-difference positions and counts. 4. **A conformance kit** (manifest in, trace out) for a later Rust module: when needed. 5. **Through the board.** blargg's `spc_dsp6.sfc` (111 tests, hardware-verified) needs the S-CPU to upload its test code: it runs when the board runs ROMs. gilyon's spctest likewise. These are the judges for C3, C14 and the OBSERVED items. 6. **Hardware capture**, if ever available. ## Tooling `python -I scripts/dsp_compare.py [SPC ...]` (rung 2/3 comparison); `scripts/dsp_gauss_formula.py` (the table); `scripts/dsp_run_referee.py` (referee hashes).