# Timing: the 32-step sample The S-DSP makes one stereo sample every 32 S-SMP clocks, and everything it does is pinned to one of those 32 **steps**. A register write lands before or after the step that reads it, and that is observable. The schedule below is anomie's sample loop ("SOUND GENERATION"), checked against his per-register "accessed during ... cycles" lists, against fullsnes "SNES APU Low Level Timings" (the same chart; fullsnes numbers its slots one higher, T1 = step 0), and against the order of operations in ares's `DSP::main()` (ISC; the step list only, cited with ares's notice in `NOTICE`). The spc_dsp6 test names that check a step on a console are given per row. This replaces the earlier schedule, which had been extracted from a GPL/LGPL implementation's source; nothing here comes from it. ## The schedule Voice operations are anomie's S1-S9. "Vn:Sk" is voice n's operation Sk. | Step | Voice operations | Global (anomie) | spc_dsp6 Timing tests | | --- | --- | --- | --- | | 0 | V0:S5 V1:S2 | T0/T1 (every 4 samples) and T2 timer ticks | `V4-5 vvol`, `V2 pitchl`, `V2 adsr0.*`, `V2 dir.*` | | 1 | V0:S6 V1:S3 | | `V3 pitchh`, `V3 BRR.*`, `V3 adsr1.*`, `V3 gain.*`, `V3 flg.80` | | 2 | V0:S7 V1:S4 V3:S1 | | `V7 endx *`, `V1 srcn.*` | | 3 | V0:S8 V1:S5 V2:S2 | | `V8 outx` | | 4 | V0:S9 V1:S6 V2:S3 | | `V9 envx` | | 5 | V1:S7 V2:S4 V4:S1 | | | | 6 | V1:S8 V2:S5 V3:S2 | | | | 7 | V1:S9 V2:S6 V3:S3 | | | | 8 | V2:S7 V3:S4 V5:S1 | | | | 9 | V2:S8 V3:S5 V4:S2 | | | | 10 | V2:S9 V3:S6 V4:S3 | | | | 11 | V3:S7 V4:S4 V6:S1 | | | | 12 | V3:S8 V4:S5 V5:S2 | | | | 13 | V3:S9 V4:S6 V5:S3 | | | | 14 | V4:S7 V5:S4 V7:S1 | | | | 15 | V4:S8 V5:S5 V6:S2 | | | | 16 | V4:S9 V5:S6 V6:S3 | T2 timer tick | | | 17 | V0:S1 V5:S7 V6:S4 | | | | 18 | V5:S8 V6:S5 V7:S2 | | | | 19 | V5:S9 V6:S6 V7:S3 | | | | 20 | V1:S1 V6:S7 V7:S4 | | | | 21 | V0:S2 V6:S8 V7:S5 | | | | 22 | V0:S3a V6:S9 V7:S6 | echo pointer from ESA and the offset; left echo read; FFC0 | `22-23 echo read`, `22-25 fir` | | 23 | V7:S7 | right echo read; FFC1, FFC2 | | | 24 | V7:S8 | FFC3-FFC5 | | | 25 | V0:S3b V7:S9 | FFC6, FFC7 | | | 26 | | MVOLL, EVOLL, left output; EFB | `26 efb` | | 27 | | MVOLR, EVOLR, right output; PMON | `27 pmon` | | 28 | | NON, EON, DIR; FLG.5 for the left write | `28 dir`, `28 eon`, `28 non`, `28-29 flg.20` | | 29 | | counter; left echo write; EDL if the offset is 0; ESA; FLG.5 for the right write; internal KON cleared (every other sample) | `29 edl`, `29 esa`, `29 kon cleared`, `29-30 echo write` | | 30 | V0:S3c | right echo write; offset advanced; FLG.0-4 and noise; KOFF and internal KON loaded (every other sample) | `30 flg.1F`, `30 koff`, `30 kon` | | 31 | V0:S4 V2:S1 | | | The per-voice steps, from anomie's register lists: | Op | V0 | V1 | V2 | V3 | V4 | V5 | V6 | V7 | | --- | --- | --- | --- | --- | --- | --- | --- | --- | | S1 (SRCN) | 17 | 20 | 31 | 2 | 5 | 8 | 11 | 14 | | S2 (pointer, PITCHL, ADSR1) | 21 | 0 | 3 | 6 | 9 | 12 | 15 | 18 | | S3a (PITCHH, PMON) | 22 | 1 | 4 | 7 | 10 | 13 | 16 | 19 | | S3b (header, first byte) | 25 | 1 | 4 | 7 | 10 | 13 | 16 | 19 | | S3c (envelope, KON/KOFF, FLG.7, ADSR2/GAIN) | 30 | 1 | 4 | 7 | 10 | 13 | 16 | 19 | | S4 (decode, pitch, VOLL) | 31 | 2 | 5 | 8 | 11 | 14 | 17 | 20 | | S5 (VOLR, ENDX prepared) | 0 | 3 | 6 | 9 | 12 | 15 | 18 | 21 | | S6 (OUTX prepared) | 1 | 4 | 7 | 10 | 13 | 16 | 19 | 22 | | S7 (ENDX written, ENVX prepared) | 2 | 5 | 8 | 11 | 14 | 17 | 20 | 23 | | S8 (OUTX written) | 3 | 6 | 9 | 12 | 15 | 18 | 21 | 24 | | S9 (ENVX written) | 4 | 7 | 10 | 13 | 16 | 19 | 22 | 25 | **Agreement.** Every row above is in anomie's loop and in his register lists; fullsnes's chart has the same accesses (one slot later in its numbering). ares's `DSP::main()` runs the same operations on every step. **Order inside a step** (tagged in the code): - Steps 2, 5, 8, 11, 14, 17: the S1 of one voice and the S4/S7 of others share no state; any order gives the same result. - Step 30: anomie lists V0:S3c, the echo write and the KOFF/KON/noise loads without an order. The module runs the global part first (the poll, the noise update), then V0:S3c, then the echo write: ares's order, and OBSERVED to agree with the referee (voice 0 acts on a poll in the step it is made; voice 0 noise uses the updated noise). - Step 29: the counter update comes before the step-30 consumers either way (C4 is not observable). ## Latch points - **Loaded once per sample** (a write takes effect at the next load): PMON (27), NON, EON, DIR (28), ESA (29, used at the next 22), EDL (29, only at offset 0), FLG.5 (28 and 29), FLG.0-4 (30), KOFF and internal KON (30, every other sample). MVOL, EVOL, EFB and the FIR coefficients are read at their steps. - **Read at use, per voice**: SRCN (S1), PITCHL and ADSR1 (S2), PITCHH (S3a), ADSR2/GAIN and FLG.7 (S3c), VOLL (S4), VOLR (S5). ## ARAM traffic Per sample, per voice: the directory entry at S2, the header and one data byte at S3b, the second data byte at S4 when a group is decoded; the echo reads at 22-23 and writes at 29-30 (anomie). fullsnes's signal chart shows the DSP's RAM strobes going low "even when no new BRR/DIR data is needed", consistent with anomie's note that "the S-DSP may perform some of the 'if necessary' operations unconditionally". The module reads only what it uses; the difference is not observable by the S-SMP. ## The S-SMP's access versus the DSP step (C14) No document orders the S-SMP's bus access against the DSP step of the same clock. The module's convention: in each S-SMP cycle the board first runs the DSP step(s) of that cycle, then performs the S-SMP's access, so a `$F3` store in the cycle that runs step *c* is seen from step *c* + 1 on. OBSERVED: with spc700-python's per-cycle callbacks and this order, the referee's register file matches after every sample on all synthetic cases, including `latch-sweep` and `kon-timing`, which write at every one of the 32 phases; the opposite order disagrees with it (validation.md). spc_dsp6's `Timing/*` tests, through the board, are the hardware-verified judge. ## KON, KOFF and the 64-step poll The poll runs every other sample (anomie: steps 29 and 30 "performed every other sample"). Which samples poll, relative to the S-SMP timers, is anomie's "30 & 94 or 62 & 126 cycles after the SPC700 timer T0 and T1 tick ... On power on, 62 & 126 seems to be chosen more frequently" (U22). The module exposes the flag (`every_other`) for the board to set; `reset()` pairs it with even counter values (TEST ROM: spc_dsp6 `Misc/brr addr wrap-around`; U22). Voice 0 acts on the poll at step 30 of the same sample; voices 1-7 at their S3c in the next sample. ## The register-write override window ENDX (S5 prepares, S7 writes), OUTX (S6/S8) and ENVX (S7/S9): "a write by the SMP to this register up to 2 cycles earlier will overwrite the DSP's updated value" (anomie). The pending ENVX and OUTX values are one latch each for all voices: a write to any voice's ENVX lands in the voice whose ENVX is pending (OBSERVED, C16).