Until 1986 a ZX Spectrum could only beep. When the Spectrum 128 reached British shops in early 1986, Sinclair User went straight to the sound: “Yes, for the first time in history Sinclair has finally produced a machine which sounds good.” The reason was a chip that Amstrad owners already knew. “The chip is identical to the one used in Amstrad machines,” the magazine noted, “and produces three channels of sound through the TV speaker.”
That chip was General Instrument’s AY-3-8912. It sets up a sound and keeps playing it without the processor’s help. On the 48K Spectrum the Z80 had to toggle the speaker bit itself for every cycle of every note. On the 128 a program writes a few registers and the note plays on its own while the game runs.
One design, three packages
General Instrument sold its programmable sound generator (PSG) in three packages and described all three in one data sheet. The main difference is how many general-purpose I/O ports survive:
| Part | I/O ports | Pins |
|---|---|---|
| AY-3-8910 | A and B | 40 |
| AY-3-8912 | A only | 28 |
| AY-3-8913 | none | 24 |
The sound hardware is the same in all three. The 28-pin package also drops one of the two extra chip-select inputs: the 8912 keeps A8 and loses A9. General Instrument provided these so that several PSGs could share one bus. Yamaha later made a pin-compatible part, the YM2149, whose envelope has 32 steps where General Instrument’s has 16.
General Instrument’s data manual for the AY-3-8910 and AY-3-8912 is dated February 1979, and it is the earliest dated document for either chip in public sources. By that September the chip was on sale to hobbyists: a mail-order advertisement in BYTE offered the 40-pin AY-3-8910 as a “NEW! G.I. COMPUTER SOUND CHIP” for $14.95.
What the chip does
Sixteen registers control everything, and every one of them can be read back as well as written:
| Registers (decimal) | Job |
|---|---|
| R0–R5 | Tone period for channels A, B and C: a fine byte and a coarse 4-bit nibble each, making a 12-bit period |
| R6 | Noise period, 5 bits |
| R7 | Mixer: tone and noise enables for each channel, and the direction of the I/O ports |
| R8–R10 | Volume for channels A, B and C: 4 bits of level, plus a bit that hands the channel to the envelope |
| R11–R12 | Envelope period, 16 bits (R11 fine, R12 coarse) |
| R13 | Envelope shape |
| R14–R15 | I/O port data (R15 has no pins to drive on the 8912) |
Tone. Each channel produces a square wave. The chip divides its input clock by 16 and then by the 12-bit period, so a larger period gives a lower note. On the Spectrum 128 the clock is 1.7734 MHz, which makes the base unit about 110.8 kHz. A period of 252 gives very nearly 440 Hz, the A above middle C. Amstrad’s manual gives the range as “27Hz to 110 KHz”.
Noise. One noise generator, whose pitch is set by a 5-bit period, can be mixed into any of the three channels. As the Spectrum 128’s manual put it, “any of the channels can produce either a musical tone or noise, so you can mix sound effects in with your music”.
The mixer. Register 7 is back to front. A 0 bit switches a channel’s tone or noise on. The top two bits set whether the I/O ports read or write.
Volume. Each channel has 16 volume levels on a logarithmic scale, because, as General Instrument put it, the chip is producing sound “for the highly imperfect amplitude detection mechanism of the human ear”.
Envelopes. Set the envelope bit in a channel’s volume register and the level follows a pattern instead of staying fixed. The pattern comes from four bits in R13, called Continue, Attack, Alternate and Hold. That allows sixteen codes. When Continue is 0 the envelope runs once and falls silent whatever the other bits say, so several codes duplicate each other and there are eight distinct shapes: single decays and attacks, repeating saws and triangles, and ramps that stop at full volume. One envelope serves all three channels. A tune that wanted a different fade on each voice had to change the volume registers itself, many times a second.
On the Spectrum 128, +2 and +3
The Spectrum 128 reached the chip through two I/O ports. Write a register number to port $FFFD (65533). Then write the value to $BFFD (49149), or read it back from $FFFD. Once a register is selected it stays selected, so repeated writes need no fresh address. The booklet that came with the 128 did not give the ports. Sinclair User complained that it said nothing about “the appropriate code instructions … for the new sound chip”. Amstrad’s manual for the +2 later gave the ports, the clock and a full register list.
BASIC reached the chip through a new command. PLAY a$,b$,c$ takes up to three strings of note letters, one per channel. The 128’s introduction manual promised “sophisticated music with up to three notes at once”, and its first examples include a set of sound effects.
The chip’s one I/O port did a second job. It drives the 128’s RS232 and MIDI socket and the keypad connector. The Spectrum 128 could send MIDI to a synthesiser while PLAY was running, and over MIDI it could play up to eight notes at once instead of three.
Two traps wait for a programmer reading the original documents:
- General Instrument numbers its registers in octal. Its “Amplitude Control R10–R12” means decimal R8–R10, and its “Envelope Generator Control R13–R15” means decimal R11–R13. Read as decimal, the numbers seem to collide with the I/O ports.
- Amstrad’s +2 manual swaps the envelope period labels. It calls R11 “coarse” and R12 “fine”. The data sheet has them the other way round, with R11 as the fine byte and R12 as the coarse one.
On other machines
- Amstrad CPC. The CPC464 uses an AY-3-8912, reached through two ports of its 8255 interface chip rather than directly. Amstrad’s firmware guide gives its clock as “exactly 1.00 MHz”, so the same period value plays a different note on a CPC than on a Spectrum 128.
- MSX. The MSX standard specifies a sound chip “GI AY-3-8910 Compatible” with a clock of 1.7897725 MHz, half the CPU clock.
- Atari ST. The ST uses Yamaha’s YM2149, in the same family.
A music driver written for one of these machines needs new port routines and a new table of periods for the other machine’s clock. The registers themselves do not change.
Before the 128
Sinclair did not build the chip into a Spectrum until the 128, but add-on makers used it in sound boxes for the 48K. In March 1985 Sinclair User reviewed DK’tronics’ Sound Generator at £29.95, “based around the ever popular AY-3-8912 chip”, with its own amplifier and speaker. The reviewer’s objection was about software, not the chip: “the problem has always been lack of support from software writers.” The 128 gave programmers a Sinclair machine with the chip already built in, and by February 1986 Sinclair User was calling it “the evergreen AY-3-8912”.
Sources
- General Instrument, AY-3-8910/8912/8913 Programmable Sound Generator data sheet (undated), pp. 5-18 to 5-22: the three packages and their ports; the A8 and A9 inputs; the register array, all sixteen registers readable; tone and noise dividers; the mixer and I/O enable register; amplitude control and the envelope shape bits; octal register numbers; logarithmic D/A conversion.
- Yamaha, YM2149 SSG data sheet: pin compatibility with the AY-3-8910; the 5-bit envelope generator; the envelope shape table (Table 4).
- General Instrument, AY-3-8910/8912 Programmable Sound Generator Data Manual (February 1979): the date of the two parts. https://archive.org/details/rearc_atari-st-e-tt-toolkit-b1-73-ay-3-8910-8912-psg-data-manual-1979-02
- BYTE, September 1979, p. 247: mail-order advertisement for the AY-3-8910 at $14.95.
- Sinclair User issue 36, March 1985, p. 25: review of the DK’tronics Sound Generator.
- Sinclair User issue 47, February 1986, p. 106: John Lambert’s first look at the Spectrum 128 (“the evergreen AY-3-8912”).
- Sinclair User issue 48, March 1986, pp. 6–7: the Spectrum 128 arrives in the UK; the sound chip and the missing programming information.
- ZX Spectrum 128 Introduction (Sinclair Research), pp. 9–10 and 14: the PLAY command, three channels, tone or noise on any channel, and MIDI output with up to eight notes.
- Sinclair ZX Spectrum +2 manual (Amstrad), Part 29, pp. 166–167: ports $FFFD and $BFFD, the 1.7734 MHz clock, the register list, the active-low mixer and the RS232, MIDI and keypad ports.
- ZX Spectrum +3 Service Manual (Amstrad): technical specification and parts list (IC11, AY-3-8912A).
- CPC464 Firmware (AMSOFT, 1984), appendix 12: the AY-3-8912, its connection through the 8255 and its 1.00 MHz clock.
- MSX Technical Data Book (ASCII Corporation, 1984), section 1.3: the sound chip specification and clock.
- Atari ST Internals (Abacus Software, 1986), section 1.6: the YM-2149 sound generator.