# Sound: the Z80, the T6W28 and the DACs Sources: **M** = Ivan Mackintosh, "NGPC Sound Tutorial" (2001, a homebrew author's driver guide), **JT** = Judge's ngpctech.txt, **ares** = ares `6e67c8b` (ISC, readable, tier 5: OBSERVED), **MAME** = MAME 0.285 run as a closed box (our write log, see [mame-oracle.md](mame-oracle.md)). No Toshiba T6W28 data sheet and no recording of a real NGP's sound was found. ## The sound subsystem - A **Z80 at 3.072 MHz** (MAME device list; ares runs it at system frequency / 2) with **4 KiB of RAM shared** with the main CPU: Z80 0000-0FFF = main CPU 7000-7FFF (JT, M). ares stalls the Z80 while the main CPU's memory address register is inside 7000-7FFF (apu/memory.cpp): an arbitration model with no source (U5). - Z80 memory map (ares apu/memory.cpp): 0000-0FFF shared RAM; **4000 write = T6W28 right port, 4001 write = left port**; 8000 read/write = the communication byte (the main CPU writes it at its SFR 0xBC); C000 write = raise the main CPU's interrupt 5. `OUT (FF),A` acknowledges the Z80's IRQ (ares apu/memory.cpp `out`; JT saw the driver write an increasing number to port FF at each NMI). - Main CPU side (ares cpu/io.cpp; JT): **0xB8**: 0x55 selects the PSG, 0xAA the DACs; **0xB9**: 0x55 starts the Z80, 0xAA stops (resets) it; **0xBA**: any write raises the Z80's NMI; **0xBC**: the communication byte. JT describes the same pair as a word: writing AAAA to 0xB8 "disable[s] the Z80", 5555 turns it back on; a word write covers B8 and B9, so the two accounts agree. MAME's log of the NGPC BIOS shows `B8 AA, B9 AA, B8 55, B9 AA, B8 AA, B9 AA, BC 00` within its first instructions. - The Z80's maskable interrupt comes from the main CPU's timer 3 output (ares cpu/timers.cpp: `if(latch) apu.irq.line = 1`): a channel from the main CPU domain. - **DACs**: two 8-bit DACs, left and right (MAME: two "8-Bit R-2R DAC" devices; ares writeLeftDAC/writeRightDAC from the main CPU's I/O window). In ares the output is either the PSG or the DACs, chosen at 0xB8. ## The T6W28 against the SN76489 What the T6W28 shares with the SN76489 (M: the command format is the SN76489's, bit 7 latch, bits 6-4 channel and type, bits 3-0 data; second byte for the high 6 bits of a 10-bit period): | Point | SN76489 family (sn76489-python variants) | T6W28 | Source | | --- | --- | --- | --- | | Write ports | one | **two**: left (Z80 4001) and right (4000); each latches its own channel/type | ares t6w28.cpp; M names 4000 "REG_CH4" (noise) and 4001 "REG_CH123" (tones) | | Attenuation | one 4-bit per channel | **one 4-bit per channel per side**: a volume byte on the left port sets the left level, on the right port the right level | ares; Furnace's T6W28 page (GPL project's docs, facts only) calls it soft panning | | Stereo | Game Gear: an on/off mask per channel and side | true per-side levels (no mask register) | ares | | Tone periods | written through the one port | written **through the left port only**; right-port tone writes are ignored except channel 2's | ares | | Noise period source | rate 3 = tone 2's period | rate 3 = **the noise's own 10-bit period**, written as "tone 2 frequency" on the **right** port: independent of tone 2 | ares; Furnace's page says the same | | Noise register | Sega: 16 stages, taps 0 and 3; TI: 15 stages | ares: 15-bit LFSR, reset to 0x4000, white-noise feedback bit 0 XOR bit 2 | ares (OBSERVED only: U6) | | Noise control write | resets the LFSR | resets the LFSR (ares), on the right port | ares | | Clock divide | /16 per tone half-period count (sn76489-python spec) | ares steps the T6W28 at 6.144 MHz / 32 = 192 kHz, which is the chip's 3.072 MHz / 16 | ares psg.cpp | | Output mix | per variant | ares: 4 channels summed per side through a 15-step volume table, a 20 Hz high-pass | ares (host filter, not specification) | ares's `writePitch` hook fires on tone 1 period writes only to feed its debugger; no hardware meaning. ### Variant or in-board? sn76489-python's `PSGVariant` is a frozen record of data (register length, taps, tone 0 rule, a stereo-mask flag) over one chip class with one `write(byte)`. The T6W28 needs **structure** the record does not have: two latches, two attenuation sets, a port-dependent decode, and a noise period register. Options: (a) a `T6W28` subclass or sibling class in sn76489-python sharing the tone and noise counters; (b) a T6W28 class inside this board. The chip rule says a non-CPU chip used by one machine stays in its board; the T6W28 is used only by the NGP. **Recommendation: (b), in-board**, written as a pin-shaped class over sn76489-python's documented counter rules, and lifted into sn76489-python only if a second family board needs it (open decision 3). ## Z80 core needs (z80-python v0.4.0, read only) z80-python takes its buses as callables and offers `request_non_maskable_interrupt()`, `request_maskable_interrupt(vector_byte)` and `request_reset()`; it is instruction-level with documented cycle totals, no wait states or bus arbitration. The board needs: NMI from 0xBA writes, IRQ from timer 3 (the driver's IM mode is the game's choice), reset and stop from 0xB9, and shared-RAM accesses that charge the arbitration U5 decides, which z80-python cannot express as waits today: a request to raise on z80-python only if U5 is settled toward cycle-level stalls.