# Start here: the uPD7725 and uPD96050 as a core author needs them The SNES's DSP-1, DSP-1A, DSP-1B, DSP-2, DSP-3 and DSP-4 are NEC **uPD77C25** signal processors (the CMOS uPD7725; "uPD7725" below) with Nintendo's mask programs: 2,048 x 24-bit instruction ROM, 1,024 x 16-bit data ROM, 256 x 16-bit data RAM. Seta's ST010 and ST011 are the **uPD96050** (`D96050CW-012`/`-013`), a uPD77C25 with 16,384 instruction words, 2,048 data ROM words, 2,048 words of battery-backed data RAM, a deeper stack, a wider program counter and three extra jump codes. **NEC published no documentation for the uPD96050**: byuu asked and NEC "refused to provide any"; its differences were reverse-engineered (byuu, *snes coprocessors: future has arrived*, 2012). Every uPD96050-only statement here is therefore research or emulator tier. This repository builds the DSP alone: its registers, ALU, multiplier, instruction decode, stack, flags, and the host (parallel) port as the chip's pins present it. The board (`snes-python`, milestone 5) owns the cartridge address decode, the clock relation to the master clock, the BYOR program loading and battery saves. [The boundary](handoff-brief.md#the-core-boundary) and the [open decisions](handoff-brief.md#open-decisions-for-aubrey) are in the brief. Sources and their short names (all pinned in `scripts/pinned_*.json`; tiers in [validation.md](validation.md)): - **DS**: NEC Data Sheet *uPD77C25, 77P25*, document U12675EJ7V0DS00 (7th edition, 1997; text PDF, printed page numbers), `reference/docs/upd77c25-datasheet-U12675EJ7V0DS00.pdf`. - **DB**: the uPD77C25/77P25 data sheet inside NEC's *1992 DSP and Speech Processor Products* data book (bitsavers scan; PDF pages 94-128 = printed pages 1-35), `reference/docs/nec-1992-dsp-speech-databook.pdf`. An older edition with text the 1997 one dropped (the ALU-NOP rule, U1/C3) and timing diagrams. - **fullsnes**: Martin Korth's `fullsnes.txt`, "SNES Cart DSP-n/ST010/ST011" (lines 8771-9310 of the pinned version, `reference/docs/fullsnes.txt`). - **ares** `ares/component/processor/upd96050/` + `ares/sfc/coprocessor/necdsp/` (ISC, NOTICE) and **MAME** `src/devices/cpu/upd7725/` + `bus/snes/upd.cpp` (BSD-3-Clause), at the pinned revisions (`scripts/pinned_repos.json`): byuu's model in readable, citable form. **ares and MAME are one lineage** (MAME's file: "Original by byuu in the public domain"; bsnes, the same core under GPL-3, is a closed box). **Mesen2** † is a separate rewrite. The rule is [docs/provenance.md](provenance.md): GPL and non-commercial sources are closed boxes only. **Sources marked †** (2026-11-19): Mesen2 (GPL-3), snes9x and bsnes's HLE code were read from source under the old rule (before 2026-11-19). They are closed boxes from now on: their source is not opened again, and no default rests on them. byuu's model is cited through ares (ISC, NOTICE) and MAME's `upd7725.cpp` (BSD-3-Clause), at the pinned revisions; bsnes (GPL-3) is a closed box. - **the programs**: MAME's device sets `sns_dsp1leg` ... `sns_seta11leg` (BYOR, read in place; [validation.md](validation.md) "The programs"), surveyed by `scripts/survey_programs.py`. ## Registers (DS section 2; fullsnes "Registers") | Register | uPD7725 | uPD96050 | Notes | | --- | --- | --- | --- | | PC | 11 bits | 14 bits | program counter, in instruction words | | stack | 4 x 11 bits | 8 x 14 bits | LIFO for CALL and interrupt; RT pops (C5: emulators differ) | | RP | 10 bits | 11 bits | data ROM pointer; `RPDEC` in OP/RT | | DP | 8 bits | 11 bits | data RAM pointer: DPL = bits 3-0, DPH = bits 7-4 | | K, L | 16 | 16 | multiplier inputs, signed | | M, N | 16 | 16 | multiplier outputs (read-only, as ALU P inputs) | | A, B | 16 | 16 | accumulators AccA, AccB | | FLAGA, FLAGB | 6 each | | S1 S0 C Z OV1 OV0 (bit 5 to bit 0, as MAME and ares pack them) | | TR, TRB | 16 | 16 | temporaries; SRC 0 ("NON") reads TRB (DS SRC note 1) | | SR | 16 | 16 | status; host reads bits 15-8 | | DR | 16 | 16 | the parallel data register (host port) | | SI, SO | 16 | 16 | serial in/out: not wired on the SNES; SO is a jump register on the ST011 (JMPSO, C4) | | RO | 16 | 16 | data ROM output (ROM[RP]) | | data ROM | 1,024 x 16 | 2,048 x 16 | | | data RAM | 256 x 16 | 2,048 x 16 | uPD96050 RAM is battery-backed and host-addressable (below) | The **multiplier** (DS (9)-(10); DB p.6) multiplies K and L (signed 16 x 16) in every instruction cycle; at the end of the instruction M holds the sign and the upper 15 bits of the 31-bit product and N the lower 15 bits shifted left once (N bit 0 = 0). Every emulator computes `p = K * L; M = p >> 15; N = p << 1` (16-bit truncation) after each instruction, so an instruction that loads K or L makes the new product visible to the next instruction, which is the DS's timing ("Multiply output set" one T-phase after "Multiply input set", DS p.26). `-8000h * -8000h` is "unknown" (fullsnes; U3). **SGN** (SRC 7) is `8000h` when SA1 = 0 and `7FFFh` when SA1 = 1 (DS (16)), i.e. `0x8000 - SA1`. It reads flag A's S1 whatever the instruction's ASL bit selects (DB p.6: "not affected by arithmetic operations on accumulator B"). ## Flags (DS (14), the flag table DS p.25; DB Table 6; fullsnes "ALU Opcode") Each accumulator has its own six flags; an ALU op updates only the flags of the accumulator its ASL bit selects. **SBB, ADC and SHL1 read the carry of the other accumulator** (DS flag table: "Nonselected FLAG ... C: Affects the result of operation" for SBB, ADC, SHL1; fullsnes "OtherCy"). | Flag | Meaning (DS) | | --- | --- | | S0 | bit 15 of the result | | Z | result = 0 | | C | carry or borrow of SUB/ADD/SBB/ADC/DEC/INC; bit 0 shifted out by SHR1, bit 15 by SHL1; 0 for OR/AND/XOR/CMP/SHL2/SHL4/XCHG | | OV0 | signed overflow of this operation | | OV1 | "set to 1 if an overflow has occurred the odd number of times as a result of the 3 operations executed" (SUB ADD SBB ADC DEC INC); 0 after the logic ops and shifts | | S1 | "the direction in which the overflow (positive or negative) has, if any, occurred"; undefined (X) after the logic ops and shifts | The S1 and OV1 update rules are **C2**: the DS states intent, fullsnes a toggle rule, the emulators byuu's formula; the core must pick one. ## Status register (DS (17); fullsnes "Status Register (SR)") | Bit | Name | Who changes it | | --- | --- | --- | | 15 | RQM | set when the DSP moves to or from DR (`MOV @DR,x`, `MOV x,DR`; **not** `DRNF`, SRC 9); cleared when the host completes a DR access | | 14-13 | USF1-0 | program; the host reads them (DSP-3 uses USF1 as a direction flag, fullsnes) | | 12 | DRS | the host's half-transfer state in 16-bit mode | | 11 | DMA | program (DRQ is not connected on SNES carts, fullsnes) | | 10 | DRC | program: 0 = 16-bit DR, 1 = 8-bit | | 9, 8 | SOC, SIC | program: serial word lengths | | 7 | EI | program; cleared on interrupt entry (C7) | | 6-2 | 0 | | | 1-0 | P1-0 | program; drive the P1/P0 pins (U17) | A program write (`LD`/`MOV @SR`) changes everything but RQM, DRS and bits 6-2: every emulator keeps `SR & 0x907C` (ares `instructions.cpp` l.230; MAME `upd7725.cpp` l.557; Mesen2 †), and the DS says RQM and DRS "can only be affected by parallel data moves" (DB p.7). The seven programs write SR with `0000`, `0001`, `0400`, `1130`, `2400`, `4400`, `A400`, `C400` (survey). ## The instruction formats (DS section 3; DB Figures 4-6; fullsnes "Opcode Encoding") Every instruction is one 24-bit word, executed in one instruction cycle. ``` 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0 RT P-SEL ALU (4) ASL DPL DPHM (4) RPDCR SRC (4) DST (4) OP (RT=0) / RT (RT=1) 1 0 BRCH (9) NA (11) BANK(2) JP 1 1 ID (16) - - DST (4) LD ``` - **OP** (`00`): an ALU operation on AccA or AccB (ASL) with P chosen by P-SEL (`RAM` = RAM[DP], `IDB` = the value SRC puts on the internal bus, `M`, `N`); a move SRC -> DST on the internal data bus; DPL (`DPNOP`, `DPINC`, `DPDEC`, `DPCLR`: the low nibble only, no carry into DPH); DPHM (XOR DP bits 7-4 with the field: `M0`-`MF`); RPDCR (`RPDEC`). - **RT** (`01`): the same as OP, then pop the stack into PC ("If a return is specified as part of an OP instruction, it is executed last", DB p.9). - **JP** (`10`): BRCH selects JMP/CALL or a condition on one flag, DPL, the serial acknowledges or RQM; NA is the target. On the uPD96050 bits 1-0 are NA bits 12-11 (fullsnes; "Reserved" on the uPD7725) and PC bit 13 is kept by every conditional jump, set by `HJMP`/`HCALL` (`101h`/`141h`) and cleared by `JMP`/`CALL` (fullsnes; ares `instructions.cpp` l.161, l.210-214). `JMPSO` (`000h`) jumps to SO. fullsnes says `000h`, `101h`, `141h` exist on the uPD96050 only (C8). - **LD** (`11`): `DST <- ID` (16-bit immediate). Bits 5-4 are reserved. SRC and DST (DS p.21-22; full table in [timing.md](timing.md#field-tables)): SRC `TRB A B TR DP RP RO SGN DR DRNF SR SIM SIL K L MEM`; DST `NON A B TR DP RP DR SR SOL SOM K KLR KLM L TRB MEM`. `@KLR` loads K from the bus and L from RO (ROM[RP]); `@KLM` loads L from the bus and K from RAM at `DP | 40h` (DS DST note 4: "RAM (DP7, '1', DP5 ... DP0)"). The 16 ALU codes are `NOP OR AND XOR SUB ADD SBB ADC DEC INC CMP SHR1 SHL1 SHL2 SHL4 XCHG`; CMP is one's complement, SHR1 is arithmetic, SHL1 shifts the other accumulator's carry in, SHL2/SHL4 shift ones in, XCHG swaps bytes (DS p.19; fullsnes). The 42 BRCH codes are listed in [timing.md](timing.md#field-tables). The condition codes are 9 bits with the low bit selecting the sense; `JDPL0`, `JDPLN0`, `JDPLF`, `JDPLNF` test DP bits 3-0. ### Order inside one instruction (DB p.9; DS p.16 and p.26) "Multiplication automatically begins first. Also, data moves from source to destination before other elements of the instruction. Data being moved on the internal data bus (IDB) is available for use in ALU operations (if P-select field of the instruction specifies IDB). However, if the accumulator specified in the ASL field is also specified as the destination of the data move, the ALU operation becomes a NOP, as the data move supersedes the ALU operation. Pointer modifications occur at the end of the instruction cycle after their values have been used for data moves. ... If a return is specified as part of an OP instruction, it is executed last" (DB p.9). The DS adds that the new DP and RP "become valid from the next instruction". What the emulators do (ares `execOP`, `instructions.cpp` l.15-149: byuu's model, which MAME carries too): read SRC onto IDB; compute the ALU from P and the selected accumulator and store result and flags; perform the move (so an `@A`/`@B` destination overwrites the ALU's result: C3); then, unless DST was DP, apply DPL and DPHM, and unless DST was RP, apply RPDEC (U2); RT then pops. The multiplier runs after the whole instruction from the new K and L. ## The host interface as the SNES sees it (DS (17), (19), (20); fullsnes "RQM"; ares `memory.cpp`) The chip has an 8-bit bus with /CS, /RD, /WR and A0: **A0 = 0 selects DR, A0 = 1 selects SR** (DS (20)). On the SNES the cartridge wires A0 to an address line: A14 on LoROM DSP boards (DR at `$8000-$BFFF`, SR at `$C000-$FFFF` of banks `$30-$3F` or `$20-$3F`), A12 on HiROM boards (DR `$6000-$6FFF`, SR `$7000-$7FFF` of banks `$00-$1F`), A0 on the ST010/ST011 (DR `$60:0000`, SR `$60:0001`) (fullsnes "DSP Mapping"; MAME `upd.cpp` `chip_read`; Mesen2 †). That decode is the board's. - **SR read**: the host gets SR bits 15-8 (RQM, USF1, USF0, DRS, DMA, DRC, SOC, SIC). Reading has no side effect. **SR is read-only**: a host write with A0 = 1 is "Inhibit" (DS table (20)); every emulator ignores it. - **DR, 16-bit mode (DRC = 0)**: the host transfers the low byte first, then the high byte. The first access sets DRS = 1; the second clears DRS and **clears RQM**. Reads and writes behave alike (ares `readDR`/`writeDR`, `memory.cpp` l.8-42; MAME `data_r`/`data_w`; Mesen2 †; DS (17)(g)). - **DR, 8-bit mode (DRC = 1)**: each access transfers DR bits 7-0 and clears RQM; DRS does not move. - **The DSP's side**: `MOV @DR, x` (or `LD @DR`) writes all 16 bits and sets RQM; `MOV x, DR` reads all 16 bits and sets RQM; `MOV x, DRNF` reads without setting it. The programs wait with `JRQM $` (a jump to itself while RQM = 1): the host's access clears RQM and the loop falls through. **79 % of the DSP-1's instructions in a half-second of Pilotwings were that loop** (timing.md). - **When the DSP sees a host access**: "The RQM flag is recognized as '0' from this instruction" one instruction after the access completes (DS "Normal Operation" timing charts, p.36; DB p.19-20). The emulators let the next instruction see it; MAME's stamps say the same (mame-oracle.md). Timing, not results: U19, C13. - **16-bit host accesses from the 65C816** (`LDA $3F8000` with M = 0) read `$8000` then `$8001`, which both have A0 = 0 on a LoROM board: low byte then high byte of DR, the natural order. Pilotwings polls SR with 16-bit reads of `$3F:C000` (measured: 1.19 M reads of `$3FC000` and 1.16 M of `$3FC001` in 60 s, `scripts/mame_dsp_trace.py --host-only`). - **ST010/ST011 data RAM** is also on the SNES bus, at `$68-$6F:0000-$0FFF`, byte-addressed: even addresses are the low byte of a 16-bit word, odd the high byte (fullsnes; MAME `dataram_r/w`; Mesen2 †). The ST010's game talks to it almost only through that RAM (fullsnes: a command at `$0020`, bit 7 of `$0021` as busy; measured: 1.0 M host reads and 341 k writes in bank `$68` in 20 s of Exhaust Heat II, one access to `$60`). The core must expose the RAM as words to the board; the byte split is the board's. ## Reset, power-on and interrupt (DS (24), (25); DB p.6; fullsnes "Reset", "Interrupts") **Reset** (RST high) sets PC = 0, FLAGA = FLAGB = 0, SR = 0, the DMA and serial request outputs and SI/SO ACK = 0, and **RP = 3FFh**; "The other registers and contents of DATA RAM are not changed" (DS (25); fullsnes agrees on RP). The emulators disagree (C6). After power-on the DS requires a reset and says nothing of the other registers' values (U18). **Interrupt**: on a rising edge of INT with EI = 1 the chip calls `100h`, pushing PC; "The EI bit of the status register automatically resets to 0" (DB p.6; the DS timing chart p.40 shows EI falling and a `NOP` before the instruction at `100h`). fullsnes says EI is not cleared (C7). **No SNES cartridge drives INT** as far as any source shows: ares and Mesen2 † have no interrupt input, and MAME's SNES glue never sets the line. ## Program and data ROM images (DS "uPD77P25 PROM interface" p.27; fullsnes "ROM-Images") The uPD77P25 PROM is programmed as bytes: each instruction word is **three bytes, big-endian, plus one dummy byte** (`FFh`), words `000h-7FFh` at byte addresses `0000h-1FFFh`, then the data ROM as big-endian 16-bit words at `2000h-27FFh` (DS p.27 "Memory Map of uPD77P25 On-Chip PROM"; DB Figures 13-14). That 10 KB layout is fullsnes' "Oldest Files" and exactly MAME's device sets (`get_prg`: `CPU[addr*4] << 24 | CPU[addr*4+1] << 16 | CPU[addr*4+2] << 8`); the ST010/ST011 sets extend it to `10000h` program bytes plus `1000h` data bytes (68 KB). ares (`load.cpp` l.393-399, l.430-436) and Mesen2 † load the "Newer" format instead: separate `*.program.rom` (3 bytes per word, little-endian) and `*.data.rom` (little-endian 16-bit) files. fullsnes' detection rule: every original program has `JRQM $` (`97C00xh`) in its first four words; the survey confirms it for all seven. A loader that accepts all three formats and hands the core lists of integers is the board's (or a small helper here: an open decision). | Program | Chip | Words used | SHA-1 (MAME's) | Notes (survey) | | --- | --- | ---: | --- | --- | | DSP-1 / 1A | uPD7725 | 1,266 | `0a03ccb1` | `sns_dsp1leg`, `sns_dsp1leg_hi` (same file) | | DSP-1B | uPD7725 | 1,267 | `3a218b0e` | the bug-fixed DSP-1 | | DSP-2 | uPD7725 | 1,747 | `06dd9fcb` | Dungeon Master | | DSP-3 | uPD7725 | 1,541 | `1b133741` | SD Gundam GX | | DSP-4 | uPD7725 | 1,742 | `76fd25f7` | Top Gear 3000; starts `LD $FFFF,@DR` | | ST010 | uPD96050 | 533 | `cc1984e9` | Exhaust Heat II / F1 ROC II | | ST011 | uPD96050 | 16,364 | `1375b8c1` | Hayazashi Nidan Morita Shougi; 1,250 HJMP/HCALL/JMPSO | ## What the core owns, and what it does not Owned: every register above, the instruction decode and execution, the multiplier, both flag sets, the stack, data RAM, the data ROM and program ROM contents it is given, the host port's DR/SR state machine (RQM, DRS, the 8/16-bit modes), reset, and, if Aubrey wants it, the INT input. Its unit of time is one instruction (= one input clock). Not owned: the cartridge address decode and A0 wiring, the clock rate and its relation to the 21.477 MHz master clock, synchronising the DSP with the 65C816 before each host access, the BYOR loading of program images, the ST010/ST011 battery save, and anything about the S-CPU's wait states for the DSP's addresses. All the board's ([handoff-brief.md](handoff-brief.md#the-core-boundary)). ## The embedding contract (proposed; the build session may refine) ```python dsp = UPD7725(program, data_rom, model=UPD96050_MODEL) # lists of ints; default the uPD7725 # (names: handoff-brief decision 2) dsp.reset() # DS reset: PC, flags, SR = 0; RP = 3FFh dsp.step() # one instruction == one input clock; returns 1 dsp.run(n) # n instructions (a loop over step; no skipping) dsp.read_sr() -> int # host: SR bits 15-8, no side effect dsp.read_dr() -> int # host: one byte, advances DRS/RQM dsp.write_dr(value) # host: one byte, advances DRS/RQM dsp.ram # data RAM words (ST010/ST011 host access, saves) dsp.p0, dsp.p1 # SR bits 1-0 (the output pins), readable ``` - The DSP has no external memory bus: its three memories are inside the chip, so there are no bus callbacks. The only interface is the host port, which the board calls **after** catching the DSP up to the access's time. - Plain integers in the hot path, no generators, so `upd7725-rust` and a `-fast` fork can transcribe it.