# Sound Hardware Galaxian predates programmable sound chips on most boards of its era — there is **no AY-3-8910, no SN76489, no sample ROM**. All sound comes from a discrete circuit built from four 555 timer ICs, entirely driven by the same Z80 that runs the game, writing to a handful of latched registers. ## Register map (recap from [memory-map.md](memory-map.md)) | Write address | Meaning | |---|---| | `0x6004` | Select 1 MΩ resistor for the background-drone 555 timer (at board position 9R) | | `0x6005` | Select 470 kΩ resistor for the same timer | | `0x6006` | Select 220 kΩ resistor for the same timer | | `0x6007` | Select 100 kΩ resistor for the same timer | | `0x6800` | FS1 — enable tone generator 555 timer at 8R | | `0x6801` | FS2 — enable tone generator 555 timer at 8S | | `0x6802` | FS3 — enable tone generator 555 timer at 8T | | `0x6803` | HIT trigger (percussive/noise-like burst — alien or player destroyed) | | `0x6805` | FIRE trigger (short blip — player shot launched) | | `0x6806` / `0x6807` | VOL1 / VOL2 — coarse volume control | | `0x7800` | Pitch latch (feeds a chip at board position 9J) | ## What this sounds like in practice - A continuous background **drone/oscillator** whose warble rate is set by which of the four `0x6004`-`0x6007` resistor values are currently selected — classically used to make the warble speed up as gameplay intensifies (e.g. as aliens dive), rather than playing a fixed note. Each warble cycle is a *descending* pitch glide that snaps back up: the modulation source is a sawtooth ramp, not a symmetric wobble. - Three additional 555-driven **tone generators** (FS1/FS2/FS3), enabled independently — layered together these produce the game's various alien-movement/dive tones. There's no requirement to model them as three literally-separate oscillators in a recreation; the audible effect is close enough with one or two representative tones. - A dedicated **HIT** trigger — a loud noise burst for destroying an alien or losing a life, with a long rumbling decay tail. - A dedicated **FIRE** trigger — the player's shot: a rising, raspy swoop that sweeps up roughly an octave-plus and sizzles at its ceiling while the missile flies. - Coarse **volume** control (2 bits), not fine-grained. ## Practical emulation model The implementation follows the circuit's signal graph without attempting a transistor-level simulation: - `0x6004`-`0x6007` form a persistent four-bit resistor DAC (1 MΩ/470 kΩ/220 kΩ/100 kΩ against a 15 kΩ bias to 4.4 V and 330 kΩ to ground). Its voltage sets the charge current of a constant-current 555 (100 kΩ/1 µF), whose capacitor ramp — a rising sawtooth between the 555 thresholds, from about 5.7 Hz (latch 0) down to 0.8 Hz (latch 15) — is scaled by an op-amp stage into the control voltage (~1.31-3.69 V) shared by all three tone generators. - FS1-FS3 gate three independently tuned 555 pulse trains driven by that shared control voltage. Rising control voltage lengthens a 555's charge phase, so each LFO cycle glides every tone *down* its logarithmic curve and snaps back up — the signature descending warble. Their ranges are 121-239 Hz, 165-334 Hz, and 231-488 Hz, and the duty cycle widens from about 22% to 61% across the sweep (built-in pulse-width motion). The three outputs mix through equal 10 kΩ branches with a 0.1 µF node capacitor — a one-pole lowpass at roughly 478 Hz that mellows the drone the way the real board does. - The pitch latch preloads a 1.536 MHz divider. Counter bits 0, 2, and 3 are mixed as square waves with conductance-proportional weights (bit 0 through 33 kΩ, bit 2 through 22 kΩ always); `VOL1` switches a 10 kΩ branch onto bit 2 and `VOL2` a 15 kΩ branch onto bit 3, rather than acting as a scalar two-bit volume. - The board's noise line is a 17-bit XNOR-feedback LFSR sampled at the 2V line (7,920 Hz). The all-ones register value is that feedback's lockup state, so the register must never be seeded with it; the implementation resets it to zero. - FIRE follows the board's 555 VCO chain. Latching FIRE discharges the 2.2 kΩ/47 µF control-voltage store (~103 ms), which raises the 555's frequency from roughly 2.4-2.8 kHz toward its ~6.5 kHz ceiling, while the sampled noise line keeps frequency-modulating the control pin through a 10 kΩ/2.2 kΩ divider — that FM is the shot's raspy sizzle. The output stage charges instantly through a diode and decays through 100 kΩ/1 µF (~100 ms) after release while the pitch slides back down. The final mixer couples this branch through a 0.01 µF series capacitor, thinning the pulse train; near the sweep ceiling the 555's high pulse is shorter than one 48 kHz sample, so synthesis integrates each sample's high-window coverage rather than point-sampling the square. - HIT wires the sampled noise line as the *switch* of the shaped store, with the 4 V HIT latch (through a diode) as its charge source: while the latch is high, the roughly 168 Hz resonant bandpass receives full-amplitude noise, and after release the stored level decays through 172 kΩ/2.2 µF (~378 ms) so the explosion keeps rumbling. Feeding the bandpass the noise waveform itself — never a rectified envelope, which is DC that a bandpass rejects — is what makes the explosion loudly audible. Its mixer gain stays well above an individual tone channel, reflecting the final mixer's lowest-impedance HIT branch. Pygame receives four-frame PCM chunks from a bounded software FIFO. Playback starts only after both the playing and queued chunks are ready, maintaining one full chunk of scheduling margin. Every emulated catch-up frame advances synthesis, but audio never blocks or controls game time. If the sink falls far behind, stale complete frames are discarded rather than slowing the board. Audio initialization remains non-fatal. The mixer format is verified after initialization as **48 kHz, signed 16-bit, stereo**. The pure synthesizer remains mono, but the adapter duplicates every PCM sample into equal left and right values because the real Windows audio path did not audibly present pygame's mono mode. Pygame's default is commonly 44.1 kHz stereo; feeding an unexpanded mono buffer into that format makes each adjacent pair of samples one stereo frame, nearly halves playback duration, raises apparent pitch, creates regular FIFO gaps, and can skip short effects entirely. The adapter therefore reopens incompatible formats and performs explicit mono-to-stereo expansion. ## Deterministic synthesis boundary The implementation uses a pure PCM16 approximation before touching pygame. At 48 kHz, the exact $2{,}000/33$ Hz board frame rate produces exactly 792 samples per frame, avoiding accumulated fractional-frame drift. Immutable state carries the CPU-visible pitch, background/tone/volume latches, oscillator position, and active fire/hit envelopes, divider state, filter state, and oscillator phases. A frame consumes decoded semantic writes and returns updated state plus one fixed-size PCM buffer. This retains deterministic, ROM-free tests while deliberately leaving exact component tolerances and intra-frame write timing out of scope.