# Sound: a Z80 and two SN76489A PSGs ## The parts - **Sound CPU**: a Z80 at 4 MHz (2.5 MHz on Star Jacker and Up'n Down) (MAME, OBSERVED). - **Two PSGs**: MAME fits two **SN76489A** on every machine, at 2 + 4 MHz on 84 of 92 sets ([census.md](census.md)). The task brief called them SN76496s; MAME's device name says SN76489A (C1). The difference matters little to the core (both are TI's discrete divide-by-16 part with READY; sn76489-python's `SN76489AN` row), but which chip each board carries wants a board photo or document (system16.com, the usual source, is set aside). - **The command latch**: MAME's `soundlatch` (an 8-bit latch) between the main and sound CPUs. ## What the closed box shows (OBSERVED, `wboyu`, 60 frames) | Item | Seen | | --- | --- | | RAM | writes at 0x8000-0x87FF; stack at 0x87FE | | PSG writes | 0xA000-0xA3FF and 0xC000-0xC3FF, 1,302 writes each (one address range per PSG: HYPOTHESIS) | | I/O ports | none used | | interrupts | 237 entries at 0x0038 in 60 frames, 16,382-17,409 cycles apart (about four a frame: a timer near 4 MHz / 16,384 = 244 Hz, MAME's `soundirq` device; its source on the board is U8) | | NMI | one entry at 0x0066, in a run where the main CPU wrote port 0x18 once: the sound command arrives by NMI (HYPOTHESIS, consistent with both) | | rate | 376,097 instructions in 3,993,595 cycles: 10.6 cycles an instruction | MAME's `sn_ready` input merger joins both PSGs' READY outputs ("any low"), so in its model the sound Z80 waits while a PSG absorbs a write (sn76489-python `docs/spec.md` ยง3.8: about 32 input clocks with READY low on the discrete chip, documented by TI). A write to the 2 MHz PSG would then stall the 4 MHz Z80 for about 64 of its cycles (arithmetic from the 32-clock figure; U4 for the wiring). ## What the board needs from the cores - **sn76489-python** (`1379eff`): its `SN76489AN` variant, twice, at the board's clocks. The core already documents READY's 32 clocks and leaves the stall to the board. - **z80-python**: the sound Z80 needs a way for the board to stretch a memory write by wait states (READY to /WAIT). z80-python's README lists `WAIT` among what it does not claim; the board can add cycles after the write returns if the core lets a write callback report extra T-states, or else the core needs a small wait-state hook. To raise on z80-python (open decision 6). sms-python's SC-3000 has the same wiring (sn76489-python's spec cites it), so this is not new to the family. - NMI and INT lines, as every z80-python board uses. ## Unknowns U4 (the latch's read address, READY wiring), U8 (the timer interrupt's source and its exact period: 16,384 cycles with some intervals 1,024 cycles longer in MAME's run), and whether the two PSG clocks differ on real boards as MAME says.