# The interface: the S-DSP and the S-SMP side inside snes-python The S-DSP is an in-board package, `snes_python/dsp/` (Aubrey, 2026-10-21), behind a pin-shaped interface, with a test (`tests/dsp/test_import_boundary.py`) that it imports only the standard library and itself. The S-SMP side, `snes_python/smp.py`, wraps spc700-python and owns the I/O page, the timers, the IPL overlay and the DSP's clock. Plain integers, no generators in the hot path, so a Rust transcription can follow it. ## The S-DSP's pins ```python from snes_python.dsp import SDSP aram = bytearray(0x10000) # shared with the S-SMP dsp = SDSP(aram, registers=None) # registers: 128 power-on bytes (default zeros, HYPOTHESIS: C11) dsp.write(register, value) # an S-SMP store to $F3 with $F2 < $80 value = dsp.read(register) # an S-SMP load from $F3 ($F2 & $7F) dsp.step() # one S-SMP clock: runs step dsp.phase, then phase += 1 mod 32 dsp.phase # 0-31, settable (C12) dsp.every_other # the poll flag, settable (U22) dsp.ram_writable # set by the S-SMP side from TEST bit 1: gates echo writes samples = dsp.take_samples() # [(left, right), ...] signed 16-bit, one per 32 steps dsp.reset() # /RESET: FLG acts as $E0, ENDX 0, counter 0, noise $4000 dsp.load_registers(regs, pending_kon=True) # an .spc snapshot's 128 registers (C18) ``` | Pin | Behaviour | | --- | --- | | ARAM | The DSP reads directory entries, BRR bytes and echo samples and writes echo samples at the steps of [timing.md](timing.md), 16-bit wrap on every address. It sees plain RAM: the IPL overlay is on the S-SMP's read path (C6). | | `$F3` write | Into the register file now. KON also sets the internal KON; FLG the internal FLG; ENDX clears every bit; ENVX and OUTX also replace the pending latch (U15, C16). | | `$F3` read | The register file's byte; no side effects. | | clock | `step()`, once per S-SMP clock (1.024 MHz). The module knows no rate (C13). | | output | `take_samples()`: the samples since the last call, after MVOL/EVOL and mute, as the DAC receives them. | Readable internal state (not part of the contract): `dsp.voices[n]` (envelope, state, position, BRR address and offset, ring), the counter, the echo offset, the noise value. ## The S-SMP side (`snes_python.smp`) ```python from snes_python.smp import SMP, load_ipl from snes_python.spc_file import read_spc smp = SMP(ipl=load_ipl()) # IPL: bytes, or load_ipl(path) / $SNES_IPL; None = no ROM smp.cpu_write_port(n, value) # the S-CPU stores to $2140+n (n = 0-3) value = smp.cpu_read_port(n) # the S-CPU loads from $2140+n smp.run(clocks) # whole SPC700 instructions until >= clocks S-SMP clocks passed smp.step() # one instruction; returns its cycles smp.clock # S-SMP clocks since power-on smp.dsp.take_samples() # the 32 kHz output smp.reset() # /RESET smp.skip_ipl(entry) # no IPL: start at entry with the IPL's hand-off registers smp.load_spc(read_spc(path)) # an .spc snapshot smp.run_samples(count) # run until count samples exist; returns exactly count ``` **Clocking from the S-CPU side.** The board owns time. One S-SMP clock is 24 oscillator clocks (24.576 MHz nominal); the S-CPU runs from 21.477 MHz. The board keeps the two in step by calling `smp.run(n)` (or `step()`) with the S-SMP clocks due since the last call, and by doing so before every `cpu_read_port` / `cpu_write_port`, so the port values are those of the right moment. The S-SMP may overrun `run`'s target by up to one instruction (at most 12 clocks); the board carries the overrun forward (`smp.clock` is the truth). Inside each SPC700 cycle (`read_byte`, `write_byte`, `idle` callbacks) the S-SMP side first clocks the DSP and the timers through the cycle (1 clock normally; 2, 5 or 10 with TEST wait states, ares's model), then performs the access (C14). | Address | Read | Write | Source | | --- | --- | --- | --- | | `$F0` TEST | 0 | timers enable/disable, RAM write enable, RAM disable, wait states; ignored while P is set | fullsnes "00F0h - TEST"; ares io.cpp (P flag, read value) | | `$F1` CONTROL | 0 | timer enables (0 -> 1 clears the divider and TnOUT), port latch resets (bits 4, 5), IPL ROM (bit 7) | fullsnes "00F1h"; ares io.cpp | | `$F2` | the address | the address | fullsnes | | `$F3` | DSP register `$F2 & $7F` | DSP register if `$F2 < $80` | fullsnes, anomie | | `$F4-$F7` | the S-CPU's last store | to the S-CPU | fullsnes "00F4h-00F7h" | | `$F8-$F9` | the last store | stored (pins unconnected) | fullsnes "AUXIO" | | `$FA-$FC` | 0 | timer dividers (0 = 256) | fullsnes; ares | | `$FD-$FF` | TnOUT, then 0 | ignored | fullsnes | Every I/O write also goes to RAM (fullsnes: "writes are also passed to RAM"), unless TEST disables RAM writes. Timers: T0/T1 at 8 kHz, T2 at 64 kHz (fullsnes), their stage-1 ticks on DSP step 0 (T0, T1 every 4 samples) and steps 0 and 16 (T2) (anomie "SOUND GENERATION"). Power-on: TEST `$0A`, CONTROL `$B0` (fullsnes). The IPL ROM is bring-your-own, never committed; with none, reads at `$FFC0-$FFFF` return RAM. ## What the S-CPU side does not see The four ports are the only link (fullsnes: "no additional communication methods (like IRQs)"). fullsnes notes that an S-CPU read during an S-SMP write to the same port sees the OR of old and new values; not modelled (HYPOTHESIS: needs sub-cycle timing). ## Stability Inside the board the interface may change with a recorded reason. What must stay true: the import boundary and the ordering rule (C14), both tested.