# Timing: one instruction per clock, and the clock is the cartridge's The uPD7725 has no variable timing: **every instruction takes one instruction cycle, and one instruction cycle is one period of the CLK input** ("All instructions execute in one instruction cycle"; "the 77C25 executes an instruction in one external clock cycle (versus two cycles of the same 8.192-MHz clock for 77C20A)", DB p.1-2; DS p.1: "122 ns" at 8.192 MHz). There are no wait states, no memory bus, no multi-cycle instructions, and the multiplier finishes inside the cycle. The core's unit of time is therefore the instruction, and the only timing questions are the clock rate (the board's), the order of the parts inside one instruction (the core's, results only), and when the DSP sees the host's accesses (the board's scheduling plus U19). Short names as in [start-here.md](start-here.md). ## The clocks (fullsnes "External Oscillators (in Cartridges)", line 22768) The DSP is clocked by **its own oscillator on the cartridge**, not by the SNES master clock, so its relation to the 65C816 is a ratio of two crystals that drift independently (as the S-SMP's is: snes-python U8). | Chip | fullsnes (oscillator) | ares default | Mesen2 † | MAME 0.285 | | --- | --- | --- | --- | --- | | DSP-1..4 (uPD7725) | **7.600 MHz** "[M]7600A", used without divider | 7,600,000 (ares `load.cpp` l.383-387 `loaduPD7725`; the game database's oscillator when present) | 7,600,000 | **8,000,000** (`upd.cpp` `UPD7725(config, m_upd7725, 8000000)`) | | ST010 (uPD96050) | 22.000 MHz "[M]22000C", **internally 11.000 MHz** | 11,000,000 | 11,000,000 | **10,000,000** | | ST011 (uPD96050) | **15.000 MHz** "15.00X", used without divider | 11,000,000 unless the database names 15 MHz | **22,000,000** | 15,000,000 | Each is one instruction per clock in every emulator (ares `NECDSP::main`, `necdsp.cpp` l.20-26: one `exec()`, one `Thread::step(1)`; MAME `execute_run`: one `m_icount` per instruction; Mesen2 † likewise). The disagreements are C10. ### Against the 21.477 MHz master clock (NTSC: 236.25 MHz / 11) | | per master clock | per 8-clock S-CPU cycle | per scanline (1,364) | per frame (357,368) | per second | | --- | ---: | ---: | ---: | ---: | ---: | | DSPn at 7.6 MHz | 0.353862 (exactly 1672/4725) | 2.831 | 482.67 | 126,459 | 7,600,000 | | DSPn at MAME's 8 MHz | 0.372487 | 2.980 | 508.07 | 133,115 | 8,000,000 | | ST010 at 11 MHz | 0.512169 | 4.097 | 698.60 | 183,033 | 11,000,000 | | ST011 at 15 MHz | 0.698413 | 5.587 | 952.63 | 249,590 | 15,000,000 | Measured on MAME: 30 frames of Pilotwings executed 3,993,445 DSP instructions, 133,115 per frame, which is MAME's 8 MHz exactly. **What this asks of the board**: keep the DSP as a second clock domain with an exact fraction of the master clock (snes-python already does this for the APU), and before every host access run the DSP up to the access's time (ares `cpu.synchronize(*this)` at the top of `NECDSP::read`/`write`, necdsp `memory.cpp` l.1-17; Mesen2 † likewise). A pure-Python core at real time would need 7.6 M instructions per second; the reference board is expected to run below real time (the family rule: reference boards are correct, not fast). ## Inside one instruction (DB p.9; DS section 4, p.26) The DS divides CLK into two phases, T1 and T2: "Data is read from and written to RAM and registers and is read from the data ROM at T1. ALU performs an operation in T1 and T2 and the output result is latched to an Acc in one T2. The input data to the multiplier is set in one at T1. At the same time, a multiplication is performed and its result is output at the next T1" (DS p.26). The observable order, which is all the core needs: 1. the multiplier's product of the K and L set by the **previous** instruction is in M and N; 2. SRC drives the internal bus (IDB); 3. the ALU reads P (RAM[DP], IDB, M or N) and the selected accumulator and latches the result (unless the move's destination is that accumulator: C3); 4. the move writes DST (and `@KLR`/`@KLM` their second register); 5. DP and RP change (DPL, DPHM, RPDEC; suppressed when DST is DP or RP: U2); 6. RT pops the return address; 7. K x L of the values now in K and L becomes next instruction's M and N. No part of this is visible outside the chip except through DR, SR, the P0/P1 pins and, on the uPD96050, the data RAM, so a core that executes these steps in this order, once per `step()`, is exact for timing. ## The host port's timing (DS p.36-37 and the AC tables; DB p.15-20) - A host read or write is recognised at a CLK edge: RD/WR must rise at least tSRWC = 50 ns before the CLK edge ("Setup and hold requirement for asynchronous signal only guarantees recognition at next CLK", DB p.17). - After the access that clears RQM, "The RQM flag is recognized as '0' from this instruction": the chart puts that instruction one instruction cycle after the one during which RQM falls (DS p.36, "Normal Operation-1 8 bit Mode" and "-2 16 bit Mode"; DB p.19-20, read at 180 dpi). So the hardware shows **one instruction of latency** between the host's access and the program's `JRQM`/`JNRQM` seeing it (U19). The emulators show none beyond their scheduling: the access lands between two instructions and the next one sees it. - MAME's stamps say the same thing: over all 49,315 host accesses in 30 frames of Pilotwings, an access stamped `N` fell after the instruction stamped `N` and was first seen by instruction `N + 1` (mame-oracle.md). - RD/WR pulse 120 ns minimum, recovery 100 ns (77C25). The S-CPU's 8-clock (373 ns) and 6-clock (279 ns) cycles satisfy both. ## Reset and interrupt timing (DS p.40, AC table "Interrupt Reset Timing") - RST: minimum pulse 2 tCYC for a system reset, 3 tCYC to "enter power saving state" (77C25). The chart shows NOPs while RST is high and the instruction at `0H` in the first cycle after it falls. - INT: pulse at least 3 tCYC, recovery 2 tCYC. The chart: a NOP, then the instruction at `100H`; EI falls with the NOP; "EI bit can be set to '1' from this instruction" one instruction after `LDI @SR`. MAME executes the NOP and then an extra `LCALL 100h` as its own instruction cycle before `100h` (one slot more than the chart, C7). Unused on the SNES. ## Field tables **ALU** (bits 19-16): `0 NOP`, `1 OR`, `2 AND`, `3 XOR`, `4 SUB`, `5 ADD`, `6 SBB` (Acc - P - other C), `7 ADC` (Acc + P + other C), `8 DEC`, `9 INC`, `A CMP` (one's complement), `B SHR1` (arithmetic, C = bit 0), `C SHL1` (shift in the other accumulator's C, C = bit 15), `D SHL2` (shift in `11`), `E SHL4` (shift in `1111`), `F XCHG` (swap bytes) (DS p.19, flag effects p.25). **P-SELECT** (bits 21-20): `0 RAM` (RAM[DP]), `1 IDB`, `2 M`, `3 N`. **DPL** (bits 14-13): `0 DPNOP`, `1 DPINC`, `2 DPDEC`, `3 DPCLR` (DP bits 3-0, no carry). **DPHM** (bits 12-9): DP bits 7-4 XOR the field. **RPDCR** (bit 8): RP - 1. **SRC** (bits 7-4): `0 TRB` ("NON": TRB is output anyway, DS SRC note 1), `1 A`, `2 B`, `3 TR`, `4 DP`, `5 RP`, `6 RO` (ROM[RP]), `7 SGN`, `8 DR` (sets RQM), `9 DRNF` (no RQM), `A SR`, `B SIM` (SI, first bit in at the MSB), `C SIL` (first bit in at the LSB), `D K`, `E L`, `F MEM` (RAM[DP]). **DST** (bits 3-0): `0 @NON`, `1 @A`, `2 @B`, `3 @TR`, `4 @DP`, `5 @RP`, `6 @DR` (sets RQM), `7 @SR` (mask `907Ch` kept), `8 @SOL` (serial out LSB first), `9 @SOM` (MSB first), `A @K`, `B @KLR` (K = IDB, L = RO), `C @KLM` (L = IDB, K = RAM[DP | 40h]), `D @L`, `E @TRB`, `F @MEM`. **BRCH** (bits 21-13, JP; target = NA, plus PC bit 13 and BANK bits on the uPD96050): `000 JMPSO` (PC = SO; uPD96050 per fullsnes), `100 JMP`, `101 HJMP` (uPD96050), `140 CALL`, `141 HCALL` (uPD96050); conditional (jump if the condition holds): `080 JNCA`, `082 JCA`, `084 JNCB`, `086 JCB`, `088 JNZA`, `08A JZA`, `08C JNZB`, `08E JZB`, `090 JNOVA0`, `092 JOVA0`, `094 JNOVB0`, `096 JOVB0`, `098 JNOVA1`, `09A JOVA1`, `09C JNOVB1`, `09E JOVB1`, `0A0 JNSA0`, `0A2 JSA0`, `0A4 JNSB0`, `0A6 JSB0`, `0A8 JNSA1`, `0AA JSA1`, `0AC JNSB1`, `0AE JSB1`, `0B0 JDPL0`, `0B1 JDPLN0`, `0B2 JDPLF`, `0B3 JDPLNF`, `0B4 JNSIAK`, `0B6 JSIAK`, `0B8 JNSOAK`, `0BA JSOAK`, `0BC JNRQM`, `0BE JRQM` (DS p.23-24; fullsnes "BRCH Opcode"). Any other BRCH value does nothing in every emulator (falls through to PC + 1); no program uses one (survey). ## What the programs use (`scripts/survey_programs.py`, static, every word) | | DSP-1 | DSP-1B | DSP-2 | DSP-3 | DSP-4 | ST010 | ST011 | | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | | words used | 1,266 | 1,267 | 1,747 | 1,541 | 1,742 | 533 | 16,364 | | OP / RT / JP / LD | 792/37/273/164 | 791/37/273/166 | 1064/28/456/199 | 862/23/348/308 | 884/49/555/254 | 325/3/79/126 | 7170/349/3705/5140 | | `JRQM` | 85 | 85 | 222 | 61 | 157 | 1 | 14 | | SGN read | 2 | 2 | 0 | 0 | 0 | 0 | 0 | | ADC/SBB/SHL1 (other carry) | 22 | 22 | 44 | 32 | 26 | 7 | 17 | | P = RAM with DST = @MEM (prohibited) | 9 (1 reads P) | 9 (1) | 36 (0) | 33 (0) | 33 (6) | 4 (0) | 94 (0) | | @KLR/@KLM with SRC = K/L (prohibited) | 2 | 2 | 0 | 0 | 0 | 0 | 0 | | ALU with DST = its own accumulator (C3) | 0 | 0 | 0 | 0 | 2 | 0 | 0 | | HJMP / HCALL / JMPSO | - | - | - | - | - | 0 | 227 / 1,000 / 23 | | @SOL (serial out) | 0 | 0 | 0 | 0 | 0 | 0 | 79 | | uPD7725 JP with BANK bits set | 0 | 0 | 0 | 0 | 0 | - | - | | JSIAK/JSOAK/JNSIAK/JNSOAK, JxSx1, JxOVx1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | INT-related (EI set by `LD @SR`) | 0 | 0 | 0 | 0 | 0 | 0 | 0 | So: **no program uses the serial port as a port, the interrupt, the OV1/S1 jumps or the serial-acknowledge jumps**; S1 matters only through the DSP-1's two SGN reads; the "prohibited" combinations are used, and each needs a defined behaviour (U13). ## Measured on MAME 0.285 (2026-11-05; `scripts/mame_dsp_trace.py`) | Run | Emulated | Wall | Result | | --- | ---: | ---: | --- | | Pilotwings (USA), host accesses only | 3,600 frames | 49 s | DSP idle until 29.6 s, then 18.7 k writes and 200 k reads per second (16-bit SR polls of `$3F:C000/1`, DR at `$3F:8000/1`) | | Pilotwings, trace frames 1,800-1,829 | 30 frames | 106 s | 3,993,445 instructions, 3,149,574 (79 %) in collapsed wait loops; 140,362 R, 5,861 W from power-on; 904 of 1,266 program words executed (71 %), including both @KLR/@KLM-from-K/L words, the binary P=RAM/@MEM word, one SGN read, 8 ADC/SBB sites | | Super Mario Kart (USA), host only | 1,200 frames | 16 s | `hirom_dsp1leg`; 231 k R, 3.5 k W | | Dungeon Master (USA) | 1,200 | 12 s | `lorom_dsp2leg`; 6 W (needs input to reach the DSP-2's work) | | SD Gundam GX (Japan) | 1,200 | 13 s | `lorom_dsp3leg`; 105 k R, 31 k W | | Top Gear 3000 (USA) | 1,200 | 13 s | `lorom_dsp4leg`; 514 R, 0 W in attract mode | | Exhaust Heat II (Japan) | 1,200 | 17 s | `lorom_st10leg`; 1.0 M R, 341 k W, all but 2 in the data RAM (bank `$68`) | | Hayazashi Nidan Morita Shougi (Japan) | 1,200 | 17 s | `lorom_st11leg`; no access in 20 s headless | | F1 ROC (USA) | | 2 s | **no DSP**: chipset byte `$02`; the ST010 game is Exhaust Heat II / F1 ROC II | A traced emulated second costs about 53 s of one core (MAME evaluates the trace action per instruction, ~150 k instructions per wall second); host-only runs go at about full speed.