# QSound: the Z80 interface and the DSP behind it **Decided by Aubrey (relayed 2026-11-11): QSound is the real DSP program, `dl-1425.bin`, run on the family's `dsp16-python` core (low level).** A high-level model is not a goal of this board; at most a later speed option, accepted only if proven sample-equal to the low-level path. The DSP core is being specified in parallel at `../dsp16-python` (read, not touched; its Phase 0 was unfinished when read on 2026-11-12). ## The parts - **DL-1425** = an AT&T WE DSP16A (die marking WEDSP16A-M14) with Capcom's program in mask ROM; decapped (siliconpr0n), 0 % reversed as a custom (`cps2-reverse` `DLs/README.md`). MAME's LLE notes: the die shows 12 kilowords of internal ROM, not the documented 4; the program uses `0000-0FFF` internal and external space from `8000` (`qsound.cpp` header). - A TDA1543 dual 16-bit I2S DAC and a TC9185P electronic volume (not emulated by MAME). - **The program dump**: `dl-1425.bin`, 24,576 bytes, CRC `d6cf5ef5`, SHA-1 `555f50fe5cdf127619da7d854c03f4a244a0c501`. MAME loads its first `0x2000` bytes word-swapped as 4 Ki words and ignores the rest (`ROM_IGNORE(0x4000)`). Present locally in **every** non-merged CPS-2 zip, in `MAME/ROMs (bios-devices)/qsound_hle.zip` and `ROMs (non-merged)/qsound.zip` (census, [census.md](census.md)). It is the only file every set shares; CPS-2 has no BIOS. ## The Z80 side (what the board implements) Z80 addresses (MAME `qsound_sub_map`, shared with CPS-1.5 boards): | Address | Access | Meaning | | --- | --- | --- | | `D000` | write | command data, high byte | | `D001` | write | command data, low byte | | `D002` | write | command **address** (DSP internal RAM word `00-FF`); this write raises the DSP's INT | | `D003` | write | Z80 ROM bank for `8000-BFFF` (bits 0-3; not a QSound register) | | `D007` | read | bit 7 = 1: the DSP has taken the last command (ready); MAME returns `80` or `00` | **Measured** (`scripts/mame_trace.py spf2t --no-trace --z80 --seconds 2`, `z80.trace` lines 29,830-29,870): the Z80 driver at `00B7-00C6` polls `D007` until bit 7 is set (`rlca` / `jr nc`), writes the low byte to `D001`, the high byte to `D000`, then the address to `D002`, and repeats for the next pair of a table. So the Z80 **busy-waits on the DSP** for every command. MAME's description of the glue (`qsound.cpp` header, Vas Crabb): the host may address only the first 256 words of DSP RAM; writing the address asserts INT; the ready bit is "assumed" to reflect INT (low while asserted); on the interrupt the DSP program reads `pdx0` three times (address, data, and a third read for the DSP16's latent PIO reads); the program accepts one command per sample interval. MAME's known command words (sample bank, per-channel offset/rate/period/loop/end/volume, pan `0x80+ch`, reverb, delays `0xDE-0xE1`, `0xE2` "write non-zero to set delays", output volumes `0xE4-0xE7`) are documented by the firmware, not by the board: the board passes words through. ## The DSP side (what `dsp16-python` plus a QSound glue must do) From MAME's LLE `qsound.cpp` (BSD-3, tier 5; the only description of the glue apart from jtcps15's GPL HDL, tier 4, which the dsp16 Phase 0 read and which is not fetched since 2026-11-24): - Clock: the device runs at **60 MHz**; the DSP16A's machine cycle is two clocks, **30 MHz**. "Sample pairs are loaded every 1,248 machine cycles, giving a sample rate of 24.03846 kHz (60 MHz / 2 / 1248)". jtcps2's README gives "3746 ticks" of 90 MHz (24,019.2 Hz) for its own clocking; the dsp16 brief (its C1, landed 2026-11-12) finds that by the manual's rules and MAME's own DSP core the program's loop is **1,245** machine cycles (24,096.39 Hz), not the 1,248 every HLE uses (C6 here). Running the real program settles it for this board. - Sample ROM: the DSP writes a sample offset to PDX0, then reads external ROM at `bank | 0x8000`; **the bank applies to the next read** (a dummy read sets the first bank), giving the odd "bank on the previous channel" command layout. Only 8-bit ROMs are fitted: MAME's header says "I'm assuming byte smearing, but it may be zero-padded", while its `dsp_sample_r` says "on CPS2, bit 0-7 of external ROM data is tied to ground" and returns `byte << 8` (C7: the code wins over the header in MAME itself; no board trace read here). - Output: 16-bit samples shifted out on the SIO port at 5 MHz, left and right in alternate frames with an empty frame between; channel taken from PSEL at the start of a word (MAME: "FIXME ... how does the logic derive WS"). The DSP also writes `pdx1` every sample (alternating zero and non-zero; perhaps the volume chip). - The 68000's digital volume (`804030`, 40 steps in MAME) sets output gain; the TC9185P is not modelled anywhere. **The QSound sample ROM region** is up to 8 MiB per set (4 or 8 MiB in the 40 parents); the 93646E QSound ROM extension board exists (`cps2-reverse` `93646E`, traced 100 %). ## Where the QSound device lives Users in the family: cps1-python (the CPS-1.5 Q-Sound games: MAME's `dino`, `punisher`, `slammast`, `mbombrd`, `wof` families use the same `qsound_sub_map`) and cps2-python. The DSP16A is a CPU and gets its own core (`dsp16-python`, being specified). The QSound **glue** (the Z80 register file, INT/ready handshake, sample-ROM bank latch, SIO de-serialiser, 60 MHz clocking) is a non-CPU device with two family consumers, so by the chip rule it qualifies for its own repository. The dsp16 Phase 0's leaning is **`qsound-python` pinning `dsp16-python`**, with the device contract documented in the dsp16 repo. This board agrees (open decision 3 in the brief): cps2-python then owns only the Z80 address decode and the volume register. ## Speed, frankly The DSP program executes about **24 million instructions per second** (about 1,000 per sample, 30 million machine cycles; dsp16 Phase 0 estimate from a MAME trace). The dsp16 Phase 0 estimates a readable pure-Python interpreter at 0.4-0.8 M instructions/s on CPython (2-3 % of real time) and 8-20 M/s on PyPy (0.3-0.8 x real time), nothing measured. MAME itself ran the low-level device at about 4 % of real time with its debugger on in that trace. Put together with the 68000 (16 MHz less wait states, about twice the Mega Drive's 7.67 MHz: megadrive-python reaches about 20 frames a second on PyPy, a third of real time) and the 8 MHz Z80, **a whole CPS-2 board with low-level QSound will run at very roughly 1/10 to 1/30 of real time on PyPy and about 1/100 or worse on CPython**: an estimate, to be measured at the QSound milestone. That is acceptable for a reference board ("correct, not fast"); the playable path is the family's `*-rust-fast` line. Coupling matters as much as raw speed: because the Z80 polls `D007` before every command, the DSP cannot be run in large batches ahead of or behind the Z80 without changing when the Z80 sees "ready". The board must advance the DSP at least to the Z80's time whenever the Z80 reads `D007` or writes `D002` (a catch-up scheduler, as megadrive-python does for its Z80). Running the DSP in another process would need exactly that synchronisation; it is a later speed option, not a design for the reference board.