# The DSP16A as a core author needs it Source for everything here unless a line says otherwise: the AT&T *WE DSP16 and DSP16A Digital Signal Processors Information Manual*, January 1989 (tier 2; `reference/docs/WE_DSP-16_DSP_Information_Manual_Jan89.pdf`; page numbers are the manual's own, such as 2-10). "MAME" is `dsp16.cpp` at MAME 0.285 (tier 5, a detector). Unknowns are `U1..`, contradictions `C1..`, both in [undocumented-behavior.md](undocumented-behavior.md). ## What the part is A 16-bit fixed-point DSP from AT&T Microelectronics (the DSP16A advance data sheet is dated 1988, the manual January 1989; the DL-1425 is marked "(C) 92"): Harvard layout, mask ROM for program and constants, RAM for data, one multiplier, one 36-bit ALU, two accumulators, a serial port, a parallel port, five interrupt sources, and a 15-instruction cache that repeats a block without fetching. All instructions are one 16-bit word except the long immediate load (two). There is no stack: one return register, one interrupt return register. | | DSP16 | DSP16A | | --- | --- | --- | | Instruction cycle | 55 or 75 ns | 25 or 33 ns | | Program ROM | 2,048 words | 4,096 words | | RAM | 512 words | 2,048 words | | YAAU registers (r0-r3, j, k, rb, re) | 9 bits | 16 bits | | EXM low | internal ROM only | internal ROM at 0x0000-0x0FFF, external 0x1000-0xFFFF | | EXM high | all 64K external | all 64K external | | Longest modulo buffer | 512 words | 2,048 words | (1-1, 1-2, 2-2, 2-6, 7-7, 7-13.) Pins, source code and object code are the same. The QSound chip needs the DSP16A column on every row: 2K words of RAM, internal ROM and external reads together. **Neither part has a timer or a power-down mode.** Both words are absent from the manual and the data sheet (searched). They arrive with the later DSP1610 family, which is out of scope ([below](#the-later-family)). The clock: CKI is the input clock, the instruction (machine) cycle is two CKI periods (`T = 2 x tCKIHCKIH`, 2-16, 6-7). QSound: 60 MHz in, 30 MHz machine cycles, 33.3 ns: the slower of the DSP16A's two speed grades. ## The three units ### XAAU: the ROM address unit (2-4) | Register | Width | Meaning | | --- | --- | --- | | `pc` | 16 | program counter; not readable or writable as a register | | `pt` | 16 | table pointer: `x = *pt++` or `*pt++i`; `goto pt`, `call pt` | | `pr` | 16 | return address of the one `call` in flight | | `pi` | 16 | shadow of `pc`; frozen while an interrupt is in service | | `i` | 12, signed | increment for `*pt++i`; reads sign-extended to 16 | - **The adder is 12 bits.** Incrementing `pc` or `pt` changes the low 12 bits only: the address space is sixteen 4K pages. `pt = 4095; x = *pt++` leaves `pt = 0` (4-6). `goto JA`/`call JA` replace the low 12 bits of `pc`. Only `goto pt`, `call pt`, `return`, `ireturn` and an interrupt change the page. - **`pi` shadows `pc`**: every change of `pc` is copied to `pi`, except while an interrupt is in service, when `pi` holds the return address. `ireturn` is `goto pi`. A write to `pi` outside an interrupt does not change it (and resets the random generator, U3); inside one it changes the return address. ### YAAU: the RAM address unit (2-6) `r0`-`r3` point into RAM; `j` and `k` are signed increments; `rb` and `re` bound a modulo buffer. All eight are 16 bits on the DSP16A, 9 on the DSP16; unsigned ones read zero-extended, `j` and `k` sign-extended (3-17). Postmodification, by the low two bits of the Y field: `*rN` (none), `*rN++` (+1), `*rN--` (-1), `*rN++j`. Compound (Z) addressing uses the pointer twice, read then write: `zp` (0 then +1), `pz` (+1 then 0), `m2` (-1 then +2), `jk` (+j then +k). **Modulo ("virtual shift") addressing**: when `re` is not zero and a pointer equals `re` **before** a +1 postincrement, the pointer becomes `rb` instead. Only the +1 case (4-5); in compound addressing the check is made in the read step for `pz` and in the write step for `zp` (3-4). `re` is zero after reset. Whether `++j` with `j = 1` also wraps is not stated (U8). RAM is 2,048 words on the DSP16A while the pointers are 16 bits: what an address above 0x07FF reads or writes is not documented (U9). ### DAU: the data unit (2-6 to 2-12) | Register | Width | Notes | | --- | --- | --- | | `x` | 16, signed | multiplier input; loaded from ROM, RAM or a register move | | `y` | 32 | `y` in assembly is the high half (the other multiplier input), `yl` the low half | | `p` | 32 | product `x * y[31:16]`, signed | | `a0`, `a1` | 36 | 32 bits and 4 guard bits (35-32); binary point taken to sit right of bit 16 | | `c0`, `c1`, `c2` | 8, signed | counters; `c0`, `c1` tested by conditions, `c2` a holding register | | `auc` | 7 | arithmetic control | | `psw` | 16 | flags and the guard bits | `auc` (2-10, D-1; **not affected by reset**): | Bits | Field | Meaning | | --- | --- | --- | | 6 | CLR | 1: loading `y` does **not** clear `yl` | | 5 | CLR | 1: loading `a1` does not clear `a1l` | | 4 | CLR | 1: loading `a0` does not clear `a0l` | | 3 | SAT | 1: `a1` is **not** saturated when read out | | 2 | SAT | 1: `a0` is not saturated when read out | | 1-0 | ALIGN | 00: `p` as is; 01: `p >> 2`; 10: `p << 2`; 11: reserved | All six control bits are "disable when 1": a cleared `auc` clears low halves and saturates. `psw` (2-9, D-2): | Bits | Field | | --- | --- | | 15 | LMI: bit 35 of the last ALU result | | 14 | LEQ: the last result was zero (all 36 bits) | | 13 | LLV: the result did not fit in 36 bits | | 12 | LMV: bits 35-31 of the result were not all alike (does not fit in 32) | | 11-10 | reserved | | 9 | `a1[V]`: "accumulator 1 overflow" (U1) | | 8-5 | `a1[35:32]`, readable and writable | | 4 | `a0[V]` (U1) | | 3-0 | `a0[35:32]`, readable and writable | **Flags are set only by multiply/ALU function statements (F1) and special functions (F2)**, never by a transfer or a data move (3-4). `aD = y` as an F1 or F2 sets them; `a0 = y` as a data move does not, and costs two cycles instead of one: the assembler picks special function, then multiply/ALU, then short immediate, then data move (4-3, 4-4). **The multiplier**: `p = x * y[31:16]`, 16 x 16 signed to 32 bits, when the F1 statement says so. In `aD = aS + p p = x * y` the old `p` is used and the new product is formed in the same cycle (3-6). **Alignment** applies where `p` enters the ALU, not to `p` itself (2-10, 2-11): `p` sign-extended to 36 bits; with ALIGN 10 shifted left two (bits 1-0 of the operand are zero, the sign extension shrinks to two guard bits); with ALIGN 01 shifted right two (the two low bits of `p` are lost). The manual's sentence on ALIGN 10 is ambiguous for a plain `aD = p` (C3). **Loading an accumulator's high half** (`aT = Y`, `aT = R`, `Z : aT`) writes bits 31-16, copies bit 31 into the guard bits, and clears the low half unless the CLR bit says otherwise. Loading the low half touches nothing else. **Reading an accumulator** (`Y = aT`, `Y = aTl`, `R = aS`, `Z : aT`): when saturation is enabled and the 36-bit value does not fit in 32 bits, the value read is `0x7FFFFFFF` or `0x80000000` by bit 35, and the half asked for is taken from that (2-8). The accumulator itself is not changed. Whether `y = aT` (the transfer into `y`) saturates is not stated (U5). **The ALU** works on 36 bits; `y` and `p` are sign-extended to 36 (2-7). The logical operations are described as 32-bit (3-2) but the result is a 36-bit accumulator: what the guard bits become after `&`, `|`, `^` is U6. ## Memory spaces - **Program (X) space**, 64K words: instructions, long immediates, and data read with `x = *pt++`. DSP16A with EXM low: 0x0000-0x0FFF internal ROM, the rest external (address on AB15-AB0, data on RB15-RB0, **no read strobe**: 7-13). QSound reads its sample ROM this way, at addresses with bit 15 set. - **Data (Y) space**: the on-chip RAM, through `r0`-`r3` only. - There is **no direct addressing**: an absolute RAM address is a pointer load (short or long immediate) and an indirect access. ## Reset (7-14, 6-4, 5-4, 2-6) RSTB low 3-states the outputs; on its rising edge execution starts at **address 0**. Documented state after reset: | | | | --- | --- | | `pc` | 0 | | `re` | 0 (modulo off); MAME also clears `rb` | | `pioc` | 0x0008: all interrupts masked, passive, strobe width T, OBE set | | `sioc`, `tdms` | 0 (5-4, 5-12) | | `srta` | **not affected** (5-12) | | `auc` | **not affected** | | everything else | not stated (U10): `a0`, `a1`, `y`, `p`, `x`, `r0`-`r3`, `j`, `k`, `pt`, `pr`, `i`, `c0`-`c2`, `psw`, RAM, the cache. The QSound program clears all 2K of RAM itself at 0x0288 | ## Interrupts (2-15 to 2-17, 4-7 to 4-11, 6-3, 6-4) Five sources, one vector. Status and enable bits live in `pioc`: | Source | Status bit | Enable bit | Set by | Cleared by | | --- | --- | --- | --- | --- | | IBF | 4 (and 15) | 9 | serial input buffer filled | reading `sdx` | | OBE | 3 | 8 | serial output buffer moved to the shift register | writing `sdx` | | PIDS | 2 | 7 | an external device wrote the parallel port (passive mode) | reading `pdx0`/`pdx1` | | PODS | 1 | 6 | an external device read the parallel port (passive mode) | writing `pdx0`/`pdx1` | | INT | 0 | 5 | the INT pin, **only if enabled** | IACK ending (`ireturn`) | - An interrupt is taken **between instructions, before an interruptible one**: "a `goto 1` is jammed into the instruction register" (2-15). `pi` keeps the address of the instruction that did not run; IACK is asserted; `pi` stops shadowing. **Not interruptible**: every branch (`goto`, `call`, `return`, `ireturn`, the conditional qualifier with its branch, `icall`), and anything executing in the cache, `do`/`redo` included (4-11). Latency is therefore bounded by the longest cache loop: up to 127 x 15 instructions. - **No nesting**: IACK masks INT; nothing saves `pi`. A status bit left set retriggers after `ireturn` (2-17). - `icall` is the same sequence to **address 2**, three cycles, never conditional. The development system uses it for breakpoints. Placing `icall` at address 0 turns `pi` into a free register (4-6). - `ireturn` copies `pi` to `pc`, ends IACK, and clears the INT status bit. - **One instruction of latency on the enable bits**: after `pioc = ...` the old enables still apply to the next instruction (6-4). - INT must be held for 4 CKI periods to be seen (2-16). Whether it is latched or sampled is not said; MAME samples the level before each interruptible instruction (U11). - Nothing saves `psw`, the accumulators, `pr` or the cache: a service routine that uses `do` destroys a cache the main program may `redo` (not stated in the manual; follows from its description; U12). The serial and parallel units, where four of the five sources come from, are in [peripherals.md](peripherals.md). ## The cache (2-3, 3-18, 3-19) `do K { NI instructions }` (NI 1-15, K 2-127) runs the block K times; `redo K` runs the block already in the cache K times. Fifteen words. What may sit in it: multiply/ALU, special function, data moves and short immediates; **not** control instructions and not the two-word immediate. Timing rules are in [timing.md](timing.md). Details the manual leaves out (K below 2, a `do` whose block contains a forbidden instruction, the cache after an interrupt, `redo` before any `do`) are U13. ## The random bit (3-5, 4-5) Conditions `heads` and `tails` test a bit from "a 10-state pseudorandom sequence generator", advanced on each test and reset by any write to `pi`. The polynomial is not given (U3). MAME does not implement it (it stops the machine). The QSound program does not use it (checked: scripts/program_census.py and the annotated disassembly). ## The later family Out of scope and **not verified in this Phase 0** (no DSP1610 data sheet was fetched; listed so nobody assumes they exist here): the DSP1610/1616/1617/1618 and their descendants keep this instruction set and add a bit-manipulation unit with alternate accumulators, vectored and maskable interrupts with their own registers, a timer, power-down control, more I/O and JTAG. MAME 0.285 has no device for any of them (`-listxml`: only `dsp16a`, inside `qsound`). If a family board ever needs one, it is a subclass or a sibling, decided then. ## What the core owns and what it does not Owns: the three units, the cache, the interrupt logic, the internal ROM and RAM, the serial and parallel units up to their pins. Does not own: anything on the other side of the pins (the QSound latch, sample ROM, DAC: [qsound.md](qsound.md)). The proposed contract is in [handoff-brief.md](handoff-brief.md).