EvidenceChain answer
How does the ZX Spectrum generate sound with its 1-bit beeper and AY-3-8910 chip, and how do these compare for machine-c
2
The ZX Spectrum made sound in two very different ways, and each one demanded a very different approach from machine-code musicians [1][50].
Two sound systems, one little computer
- The original 48K Spectrum produced sound through a small piezoelectric buzzer, driven from BASIC by the BEEP command. It was considered "pitiful," which is why the 128K series added a dedicated AY-3-8912 chip [1][42][50]. The AY-3-8910 family also appeared in later ZX Spectrum home computers [9], including the 128/+2/+3 models [10], the Timex T/S 2068 [71], and the Amstrad-made Spectrum+2 128K [72].
- The original beeper is a single channel that can generate ten octaves [31][58]. The 128K models added three-channel audio through the AY-3-8912 [37][38][63][64].
- One odd detail: the 128K Spectrum has no internal speaker at all, so its sound only comes out of a television speaker [40][66].
- A modern Spectrum Next keeps both paths alive: three AY chips feed the HDMI or ear socket, while an optional internal speaker reproduces the original 48K beeper path [55]. When the beeper volume is set to "Int," it roughly matches the original Spectrum for classic 16/48K beeper games, and AY/DAC sound does not play through that internal speaker in this mode [56]. AY volume through this setup is fairly low but usable in a quiet room [57].
How the 1-bit beeper makes sound
- The beeper is literally one bit: sound is made by toggling a single bit on and off [32][59]. In machine code, the target is bit 4 of port &FE, toggled rapidly [2][43].
- From BASIC, BEEP plays a note of a given pitch and duration, but the processor is occupied exclusively until the sound finishes, which limits anything else happening at the same time [33][34][60].
- Accurate notes in machine code usually lock up the processor too, but clever programming let people play sound effects without stalling gameplay and stretched the one channel into two or three channels of music [3][44].
- The beeper was pushed far beyond a simple "beep": programmers found workarounds so it could emit multiple pitches [35][61], later software allowed two-channel playback [36][62], and musicians such as David Whittaker and Tim Follin created multichannel game music [41]. Games managed music during gameplay (Manic Miner is claimed as a first) and even two channels with percussion [54]. Some routines even simulated three-channel sound with "actual instruments" [67][68].
- Machine-code technique: a practical guide starts with the ROM's BEEPER routine for precise tones, then builds a custom oscillator with cycle-exact timing. The video circuitry can force the CPU to wait while fetching pixel and color data, so code may need to be relocated to dodge these wait states; the demo program plays a C-major scale [51][52][53].
How the AY chip makes sound
- The AY-3-8910 is a three-voice programmable sound generator designed by General Instrument in 1978 [7]. It has three channels, covers almost the whole 88-key piano range, and adds a shared envelope generator plus a noise channel [8][27]. The AY-3-8912 used in the Spectrum also provides three channels [45].
- Programmers reach the chip through registers. The AY has sixteen 8-bit registers on an 8-bit bus, register selection uses the lower four bits (normally with the top four bits at "0000"), and each read or write takes two cycles [11][13]. Because Z80 systems do not implement this bus natively, the Spectrum had to recreate it with glue logic or an adapter [12].
- On the Spectrum itself, the two control ports are &FFFD (select or read a register) and &BFFD (write to the selected register) [4][46].
- The register layout: R0-R5 are fine and coarse pitch for channels A, B, and C; R6 is noise pitch (5 bits); R7 is the mixer; R8-RA are the three volumes (4 bits); RB/RC set envelope duration; RD sets envelope shape (4 bits); and RE is the I/O port [47].
- Each channel's pitch is a 12-bit value split between fine and coarse registers, with the top nibble of the coarse register ignored [6][48]. Channel A uses R0/R1, channel B R2/R3, and channel C R4/R5 [15]. The value acts as a frequency divider from 1 to 4095, with zero treated as 1, and with a 4 MHz input clock the lowest directly definable note is about 30.6 Hz, roughly B0 [16][23][24].
- Mixer register R7 routes tone and/or noise to each channel; all six enable bits are inverted, so a 0 enables the output and a 1 disables it [5][18][49]. R6 creates noise by dividing the input clock by 16 and then by the 5-bit value in R6 [17].
- Volume registers R10-R12 hold a level from 0 to 15, and bit 4 switches the channel to the shared envelope generator. R13/R14 set the envelope period, and R15 sets the envelope shape [19][20][21].
- The shared envelope is one of the AY's weak points, so many programmers wrote software envelope controllers instead. A well-known trick runs the hardware envelope at rates above 20 Hz to produce sawtooth- or triangle-like bass [22].
- If one AY is not enough, multiple chips can share the same bus, as in TurboSound for the ZX Spectrum, using the upper address bits as a chip select [14].
- On 128K machines, BASIC exposes the chip and MIDI out through the PLAY command [39][65].
What that meant for machine-code music
- For the beeper, music code is a timing fight: a single bit must be toggled continuously [2][32], and the video hardware's wait states make cycle counting delicate [52]. The reward is that coders got genuinely musical results anyway, with multiple simulated channels [3][36][41][44][54].
- For the AY, music code is mostly register writing: set the pitch dividers, mixer, volume, envelope, and noise, then let the hardware generate the tone [4][16][19][47]. The chip itself supplies three channels and a noise/envelope section [8][45]. In the early days, at least one programmer hand-assembled AY test code before an assembler existed [30], and a later AY synthesizer project included a premade interface module for the ZX Spectrum, marked as untested [25][26].
- Both sound options have limits. The AY is still three square waves with a modest hardware envelope [29], and the beeper has no hardware polyphony at all, only software trickery [3][32][54]. A 4 MHz Z80 AY synth was estimated to manage about 250 "ticks" per second at most, with 120 or even 60 ticks per second recommended [28].
- One broader comparison noted that the Spectrum's sound was more limited than the Commodore 64's, but the Spectrum was considered better for programming. On the C64, the sound synthesizer was not even reachable from BASIC and needed cartridges or machine code [69][70][73].
Discussion
Comments
Sign in to join the discussion
Comments are open to registered users so replies and notifications stay tied to a real account.
No comments yet. Be the first to add a useful angle.