HeadlinesBriefing favicon HeadlinesBriefing.com

ZX Spectrum Sound: Beeper & AY-3-8910

Hacker News •
×

The ZX Spectrum offers two primary sound capabilities: a 1-bit beeper and the General Instrument AY-3-8910 synthesizer chip. The beeper, present on all models, functions similarly to the Apple II or PC speaker, with sound produced by toggling a specific I/O port bit. BASIC's `BEEP` command utilizes a ROM routine at $03B5 for timing, which takes delay and duration codes to generate tones. Formulas are provided for calculating these codes based on frequency (f Hz) and duration (t seconds): HL = 437500/f – 30.125 for frequency, and DE = f×t for duration. A sample program demonstrates playing a C-major scale using these calculations and the beeper routine.

Alternatively, direct control of the beeper is possible by managing a counter and toggling I/O port $FE. This method requires careful attention to timing and preserving other port functions, such as border color. While capable of fine-grained frequency control, the direct beeper method can be complex and prone to timing inconsistencies, leading to an unpleasant sound quality. The AY-3-8910 chip, found in 128K models and available as a peripheral, offers more advanced sound synthesis capabilities, akin to the Atari ST, though without a built-in BIOS interface for it.