# QSound: what the boards need around the DSP16A Written for `cps1-python` (the CPS-1.5 QSound games), `cps2-python` and any later ZN-1/ZN-2 board. **Decided by Aubrey: QSound is the real DL-1425 program run on this DSP16A core**, low-level; that is the boards' reference sound path. This document says what sits around the core: the host port, the program's register file, sample ROM addressing, and the output. Where the device itself lives (a module here, a `qsound-python` repo, or the boards) is an open decision in [handoff-brief.md](handoff-brief.md). Sources and tiers: MAME 0.285 `qsound.cpp` (the low-level device, Vas Crabb, tier 5) and `qsoundhle.cpp` (tier 5); Loïc "WydD" Petit's traced CPS-2 board schematics in jtdsp16's `doc/` (`93646A.pdf` A-board, `93646B.pdf` B-board, KiCad, 2019, CC-BY; tier 3, traced from real boards); jotego's JTCPS1.5 sound glue (GPL HDL, read under the old rule, not fetched since 2026-11-24: HYPOTHESIS) and logic-analyser screenshots (tier 1 for what the screenshots show); superctr's register description gist (tier 3, pinned in `scripts/pinned_files.json`); jotego's annotated disassembly `doc/qsound_dl-1425.asm` (tier 4). Not copied: cited. ## The parts `DL-1425` ("CAPCOM-Q1 QSound Processor, DSP-16A (C) 92 AT&T", PLCC84; the die is marked WEDSP16A-M14 per MAME): a mask-programmed DSP16A. Around it on the CPS-2 A-board (sheet 16): a 60 MHz oscillator into CKI; EXM tied low (internal ROM, external space above 0x0FFF); SYNC and DOEN tied low; DI, ICK, ILD, IBF, OLD, OSE unconnected; a TDA1543 dual 16-bit I2S DAC; a TC9185P electronic volume control driven by the cabinet's volume buttons (sheet 17), not by the DSP. ## The program image `dl-1425.bin`, read in place from MAME's device set `ROMs (bios-devices)/qsound.zip` (the same file is in `qsound_hle.zip` and in the non-merged and merged trees): 24,576 bytes, SHA-1 `555f50fe5cdf127619da7d854c03f4a244a0c501`, SHA-256 `524a25bcd153be24594d37c0dbd334fe4f384f77da73c2058dc60fc1f581cf18`, CRC `d6cf5ef5`; little-endian 16-bit words. 12,288 words of which only the first 4,096 are addressable (C6): load words 0x0000-0x0FFF; 0x1000-0x2FFF are zero. Word 0 is `0x0288` (`goto 0x0288`); the last non-zero word is 0x0FCF; code runs to about 0x0D52, then filter coefficient tables (0x0D53-0x0FCF). Provenance: MAME commit `08d07f5917` (2017-04-26, "update ROM ... from recent decap [Lord Nightmare, Siliconpr0n, superctr, Quench]") replaced an earlier 8 KB `qsound.bin` (CRC `059c847d`) marked `BAD_DUMP`. No write-up of the read-out method was found; the die photographs at siliconpr0n refuse scripted clients. ## The host port (Z80 side) The same on CPS-1.5, CPS-2 and ZN (MAME `cps1.cpp` `qsound_sub_map`, `cps2.cpp` uses it, `zn.cpp` `qsound_map`): | Z80 address | Access | Meaning | | --- | --- | --- | | 0xD000 | write | data, high byte | | 0xD001 | write | data, low byte | | 0xD002 | write | register address; **asserts the DSP's INT** and clears "ready" | | 0xD003 | write | Z80 ROM bank (board, not QSound) | | 0xD007 | read | bit 7: ready (1 when the DSP has taken the address) | Hardware (schematic sheet 19, tier 3): three 74LS374 latches hold data-high, data-low and the address byte; when the DSP strobes PIDS, glue logic (sheet 16: two 74F74 and 74F32 gates around INT, IACK and PIDS) puts the address latch on PDB7-0 with PDB15-8 driven to zero by a 74LS245 with grounded inputs, or the data latches on PDB15-0. DSP-READY to the host is `not (INT or IACK)`. The protocol as the program runs it (interrupt routine at 0x0001-0x000B): INT is enabled for one instruction per sample. The DSP takes the interrupt, sets `c0 = 1`, reads `pdx0` three times with two `nop`s between (the latent read): the first read returns stale data and strobes PIDS, which makes the glue put the **address** on the bus and drop INT; the second returns the address and strobes again for the **data**; the third returns the data. It stores the data at RAM address `address` (so only RAM 0x00-0xFF is reachable: the address latch is 8 bits) and returns. **At most one command per sample period.** The host must wait for ready between commands. MAME notes it does not believe the data word is double-buffered in hardware (U16); a host that writes before the DSP has read the data would corrupt the command. MAME models INT as asserted until the address read; the core samples INT before interruptible instructions (U11). The Z80's own interrupt is 250 Hz on CPS-2 and ZN (MAME, "measured"): a board fact, recorded for the consumers. ## The register file (the program's RAM 0x00-0xFF) Summarised from superctr's gist (tier 3), MAME's header (tier 5) and the HLE (tier 5); the program, run on the core, is the judge of every line (rung 4). | RAM address | Meaning | | --- | --- | | `n*8 + 0` (n = 0-15) | sample bank (bits 23-16 of the sample address); **bit 15 must be set**; applies to the **next** voice (register 0x78 is voice 0's bank: C2) | | `n*8 + 1` | sample address (current position, 16 bits) | | `n*8 + 2` | rate, 4.12 fixed point: 0x1000 = one ROM byte per output sample | | `n*8 + 3` | phase (fraction of the position); 0x8000 at key-on | | `n*8 + 4` | loop length (subtracted from the position at the end) | | `n*8 + 5` | end address | | `n*8 + 6` | volume (negative inverts phase) | | 0x80-0x8F | pan of voices 0-15: -16..16 plus 0x120 (QSound table) or 0x150 (linear) | | 0x90-0x92 | pan of ADPCM voices 0-2 (also their mute) | | 0x93 | echo feedback | | 0xBA-0xC9 | echo send of voices 0-15 | | 0xCA, 0xCE, 0xD2 | ADPCM voice 0-2 start | | 0xCB, 0xCF, 0xD3 | ADPCM end | | 0xCC, 0xD0, 0xD4 | ADPCM bank | | 0xCD, 0xD1, 0xD5 | ADPCM volume (latched at key-on) | | 0xD6-0xD8 | ADPCM key-on (non-zero) | | 0xD9 | echo length (end pointer; 0x055A-0x0FFF stereo mode) | | 0xDA-0xDD | filter table addresses in program ROM for wet L, dry L, wet R, dry R: 0x0D53, 0x0DB2 (default L), 0x0E11 (default R), 0x0E70, 0x0ECF, 0x0F2E (silence), 0x0F73, 0x0FA0 (no filter), 0x0FA4 | | 0xDE-0xE1 | component delays; 0xE2 non-zero applies them | | 0xE3 | **next state: an address in the program**: 0x0288 reset to stereo mode, 0x061A reset to quad mode (never used by Capcom), 0x0039 / 0x004F refresh the filters, 0x000C / 0x000F test tones (sawtooth), 0x0000 soft reset | | 0xE4-0xE7 | component volumes (default 0x3FFF) | The 0xE3 entry means the host can send the program to six addresses; rung 4 should exercise each. ## Sample ROM addressing The program reads sample ROM through the external program space: it writes the 16-bit offset to `pdx0` (or `pdx1`), then reads `x = *pt++` with `pt` = `0x8000 | bank`. On the board (sheets 16 and 19): - every `pdx` write pulses PODS, which clocks the parallel bus into two 74LS374 latches: **sample address bits 15-0**; - the DSP's AB7-AB0 are clocked into another 74LS374 by a signal derived from CKO (the DSP's clock output): **sample address bits 22-16**, taken from whatever AB showed on the previous clock. AB holds the last external address between accesses (U19). Hence the **one-read latency** of the bank: the read at `0x8000 | bank_n` fetches with the bank latched from the **previous** external read, which is why the bank register belongs to the next voice (C2) and why the program makes a dummy read first; - ROM data arrives on RB15-RB8; **RB7-RB0 are tied to ground on CPS-2** (U15: not traced for CPS-1.5 or ZN); the samples are 8-bit signed in the high byte. The B-board's QSound ROMs are 27C322s wired straight (`93646B.pdf` sheet 9). The A-board latch appears to permute AB bits into A16-A22 (C10): a question for `cps2-python`. MAME's LLE models this as: `pdx` write sets the offset (and PSEL into bit 15 of its bank variable); a read at external address `a` returns the byte at `(bank << 16) | offset` and then sets `bank = a & 0x7FFF`. Region sizes in MAME 0.285: 4 MB (278 machines), 8 MB (87), 2 MB (18), 3 MB (1), none (4). **For the core**: an external read is a callback `read_external(address) -> word` at the cycle it happens; the core also exposes the AB value it holds, so a board can model the CKO latch literally, or (simpler, equivalent for this program) remember the previous external address itself. ## The output path `sioc = 0x02E8`, `srta = 0x00FF`: 16-bit words, MSB first, OCK = 5 MHz, the load derived from OCK; SADD low for the first 8 bit times of every word. Board wiring (sheet 16, C4): DO re-latched on inverted OCK is the DAC's DATA, OCK its bit clock, and **WS = PSEL latched on the falling edge of SADD**. The program writes `pdx1 = 0` (PSEL = 1) before the right word and leaves PSEL = 0 (after `pdx0` writes) for the left: left word written to `sdx` at 0x059C, right at 0x05D7, 337 cycles apart, once per 1,245-cycle loop (24,096.39 Hz; C1). The TDA1543 takes two's complement 16-bit samples; MAME's LLE emits the recovered words as they are. **For the board**: take the 16-bit word and PSEL at the moment the core's serial unit starts shifting it (the OLD edge), put it in the left or right slot, and emit a stereo frame each time the right word arrives. The board resamples to its mixer rate; the volume chip (TC9185P) and the CPS-2's digital volume (`0x804030` in MAME, `set_output_gain(level / 39)`) are board features after the DAC. ## Who uses it (census, MAME 0.285 `-listxml`) 388 machines use QSound, all through `qsound_hle` in MAME (no game driver can select the low-level device; only `vgmplay` instantiates it): `capcom/cps2.cpp` 322 (40 parents), `sony/zn.cpp` 47 (14 parents), `capcom/cps1.cpp` 19 (6 parents: dino, punisher, wof, slammast, mbombrd, wofch). All 388 sets are in the local non-merged MAME set; 112 in a frontend's MAME folder, 54 in its FBNeo folder (romsets through `MAME_ROMPATH`). The only BIOS-like file the DSP needs is `dl-1425.bin`, and it is present. No other machine in MAME 0.285 uses a DSP16 or DSP16A. ## Speed, frankly The program executes about 1,003 instructions and 1,245 machine cycles per output sample: **24.1 million instructions per emulated second**, plus one host-port event per command and two serial words per sample. A readable pure-Python interpreter in the family's style runs roughly 0.4-0.8 million such instructions per second on CPython (0.02-0.03 of real time: about 40-60 seconds of compute per second of sound) and perhaps 8-20 million on PyPy (0.3-0.8 of real time). These are estimates from the family's other cores, not measurements. MAME itself ran the LLE at about 4 percent of real time in the traced run (debugger on, machine loaded). The reference path is still the low- level one; speed is the `-rust`/`-fast` forks' job. (A high-level QSound would be a few hundred multiply-adds per sample; per Aubrey's decision it is at most a later speed option, and only once proven sample-equal to the low-level core.)