# The parallel and serial units Source: the Information Manual chapters 5 (serial I/O) and 6 (parallel I/O), appendix D, tier 2. What the QSound program sets is from the annotated disassembly in jtdsp16 (tier 4) and MAME traces (tier 5); where it matters, checked against Loïc Petit's traced CPS-2 A-board schematic (tier 3). These units are part of the core: they are on the die and every DSP16A has them. What is connected to their pins is the board's ([qsound.md](qsound.md)). ## Parallel I/O (PIO, chapter 6) **Pins**: PDB15-PDB00 (bidirectional data), PSEL (output: 0 for `pdx0`, 1 for `pdx1`), PIDS (input strobe, active low), PODS (output strobe, active low). `pdx0` and `pdx1` are **one physical register**; the name only sets PSEL for the transaction (6-1). In both modes the trailing (rising) edge of PIDS is the sampling point (6-6). **`pioc`** (6-2, D-3): | Bits | Field | | | --- | --- | --- | | 15 | IBF status (read-only copy of bit 4) | | | 14-13 | STROBE | PIDS/PODS width 1T, 2T, 3T, 4T (T = one machine cycle) | | 12 | PODS | 1: output (active mode); 0: input (passive) | | 11 | PIDS | 1: output (active mode); 0: input (passive) | | 10 | S/C | status/control mode: PDB15-8 input only (6-8) | | 9-5 | interrupt enables | IBF, OBE, PIDS, PODS, INT | | 4-0 | status (read-only) | IBF, OBE, PIDS, PODS, INT | Reset: `pioc = 0x0008` (OBE status set, everything else clear; 6-4). - **Active mode** (the DSP drives the strobes): a write of `pdxN` drives PDB and pulses PODS; a read of `pdxN` **returns the input register as it stands and starts a PIDS strobe that refills it** (the latent read, 6-5): N values need N + 1 reads. With a strobe wider than 1T, two PIO instructions may not be adjacent (one, two or three other instructions between them for 2T, 3T, 4T; 6-7). The QSound service routine puts two `nop`s between its `pdx0` reads. - **Passive mode** (an external device drives the strobes): PIDS written by the host sets the PIDS status bit and loads the input register; PODS read by the host puts the output register on PDB and sets the PODS status bit. Reading or writing `pdxN` clears the corresponding status bit. - **Interrupt shadowing**: with PIDS active, the input register is saved at an interrupt and restored at `ireturn` (6-9, U7). - **Enable latency**: a `pioc` write's new enables apply from the instruction after next (6-4). The program relies on it (timing.md). QSound: `pioc = 0x3800` (2T strobes, PIDS and PODS active, INT disabled) and `0x3820` (the same with INT enabled) only. ## Serial I/O (SIO, chapter 5) **Pins** (table 5-2): DI, ICK, ILD, IBF (input side); DO, OCK, OLD, OSE (output side); SADD, SYNC, DOEN (multiprocessor). DO and SADD are driven only while DOEN is low; SYNC must be tied low when unused. **Registers**: `sdx` (read: input buffer; write: output buffer; two registers under one name), `sioc`, `srta`, `tdms` (the last three write-only). `sioc` (5-4, D-4), cleared by reset: | Bit | Field | | | --- | --- | --- | | 9 | LD | active ILD/OLD derived from 0: ICK / 16; 1: OCK / 16 | | 8-7 | CLK | active clock = CKI / 4, / 12, / 16, / 20 | | 6 | MSB | 1: MSB first | | 5 | OLD | 1: OLD is an output (active) | | 4 | ILD | 1: ILD is an output | | 3 | OCK | 1: OCK is an output | | 2 | ICK | 1: ICK is an output | | 1 | OLEN | 1: 8-bit output words | | 0 | ILEN | 1: 8-bit input words | `srta` (5-13, D-5): bits 15-8 receive address, 7-0 transmit address; **unaltered by reset**. `tdms` (D-6): bit 9 SYNCSP, 8 MODE (multiprocessor), 7-1 transmit slot, 0 SYNC output; reset to zero. Output sequence (5-1 to 5-3, 5-6): writing `sdx` fills the output buffer and clears OBE; on the falling edge of OLD the buffer moves to the shift register (OBE set, OSE low two clocks later); DO changes on rising OCK; when the shift register empties OSE rises; if nothing was loaded, zeros go out and OSE stays high. **SADD sends the 8-bit transmit address from `srta`, active low, alongside DO**, in or out of multiprocessor mode; with LD = 1 it is in step with DO, which is how SADD serves as a second serial output (5-3). QSound: `sioc = 0x02E8` (LD from OCK; CKI / 12 = 5 MHz; MSB first; OLD and OCK active outputs; ILD and ICK inputs; 16-bit words) and `srta = 0x00FF` (transmit address all ones, so SADD is low for the first eight bit times of every word: jotego's logic-analyser captures show exactly that, tier 1). The input side is unused (DI, ICK, ILD unconnected on the A-board). `tdms` is never written (it stays zero: multiprocessor mode off). ## What the core must model, and how finely - PIO: the strobes as **events** reported to the host (direction, PSEL, the word, the strobe width), with the latent-read input register, status bits and enables. The QSound glue reacts to PODS (latch the sample address) and PIDS (drive the next latched byte pair), so an event per strobe is enough. - SIO output: the output buffer, shift register, OBE/OSE and the **word as an event at the OLD edge** with PSEL as it stands, SADD's address bits and the bit count. Sub-word, per-bit stepping is not needed for QSound; offer a bit level callback only if a later board needs it. - SIO input, multiprocessor mode (`tdms`, SYNC, receive-address matching), S/C mode: implement from the manual as directed-test-only features or raise on use; nothing in the family uses them. **Recommendation: implement output and the registers fully, input passively (IBF on an `sdx_in` call from the host), and raise `NotImplementedError` for multiprocessor mode**, listed in `undocumented-behavior.md` when the build session decides.