# Sound: an AY-3-8910 in the ASIC ## What the sources say - **KH** ("Audio", tier 3): "appears to be an AY-3-8910, down to the register and bit mappings, and log output. ... I tested all the registers, noise, envelope, and volume/mixer bits. It's as stock as can be. It's not the Yamaha clone with the 32 step envelope, I checked this." Three outputs: channel A (4000/4001, ...) left, channel B (4002/4003) right, channel C (4004/4005) both. "The clock going to the dividers is 4.433MHz / 32": divider 0000h gives 69.265 kHz, 0FFFh gives 16.914 Hz. - **MAME** `-listxml gamate` (tier 5): "AY-3-8910A PSG" at 1,108,250 Hz. - **CC65** `gamate.h` (PeT's notes, tier 3 toolchain view): `AUDIO_BASE 0x4000`, registers 0-13 described in PeT's own words (12-bit periods, a noise period, a mixer, volumes, an envelope period and shape), with channel 1 (registers 0/1) on the **right** and channel 2 on the **left**, and a "17 bit" noise LFSR guess. ## The arithmetic (consistent) An AY-3-8910 with input clock `C` makes a tone of `C / (16 x TP)` (a period of 0 acts as 1: ay8910-python's machine). KH's 69.265 kHz at period 0 gives `C = 69,265 x 16 = 1.108 MHz`, which is 4.433 MHz / 4 = the CPU clock / 2, and MAME's 1,108,250 Hz. KH's "/32" is the divider stage's clock (C / 8 = 138.5 kHz) before the output toggle halves it again; his two frequencies check: 4,433,000 / 64 / 4095 = 16.91 Hz. DOC, consistent across all three. ## Registers The AY's sixteen registers appear directly at **4000 + n** (KH's "4000/4001, etc", CC65's register numbers from `AUDIO_BASE`): no address latch is visible to the CPU, and **reads return open bus** (KH, memory map). So the CPU never reads back the AY, and its I/O ports (registers 14-15) are unreachable or absent (U11). Mirroring inside 4000-43FF: U3. ## Contradiction C5: which channel is left KH (bench) says A left, B right; CC65 (PeT) says registers 0/1 right, 2/3 left. KH wins (decision 2); both are recorded. Channel C goes to both sides in both sources. ## Reuse: ay8910-python (`../ay8910-python`, pin `76cace3`) - **Row:** `AY8910` ("AY-3-8910") already exists; KH's tests (16-step envelope, stock noise and mixer) match it and rule out `YM2149`. MAME's "AY-3-8910A" is the same die revision family; nothing in the sources distinguishes an "A" behaviour. - **Socket needed:** the board calls `write_register(n, value)` for a CPU write to 4000+n (no latch phase is visible) and `tick()` once per **two** CPU cycles (the AY's input clock is phi2 / 2). Which CPU cycle of the pair the AY advances on is U12. Nothing reads the chip. The board mixes A to left, B to right, C to both (the core's `levels()` gives the three DAC codes). - **Cartridge audio in:** cart pin 38 feeds the left channel before the volume control (KH); no known cartridge uses it. A socket hook only (U13). - No change to ay8910-python is needed. By the chip rule, nothing new is extracted. ## Unknowns U11 registers 14-15 and the I/O ports; U12 the AY tick's phase against phi2; U13 the cartridge audio input; U14 the analogue mix (levels, the volume control, headphone vs speaker): host side.