How to make Arduino sing like ZX Spectrum. Part 1: history

Maxilect
8 min readDec 2, 2020

ZX Spectrum 128 and its numerous clones had a built-in sound generator AY-3–8912, thanks to which a lot of musicians managed to write a huge amount of music for this computer.

In two parts of this article, spiced with a pinch of nostalgia, we will recall the main sound production methods on the XZ Spectrum 128. We designate the characteristics of the AY-3–8912 “music coprocessor,” list the most famous music editors, disassemble the music module from the popular game Dizzy IV and recreate it on Arduino. We invite all lovers of computer music, DIY, and those interested in why we put the phrase “musical coprocessor” in quotes.

Screenshot of the start screen of Dizzy IV

I remember the first computer — the ZX Spectrum “Companion” clone. My brother and I were trying to connect it to the TV. As I understand it now, the computer only had a low-frequency video output, which we tried to connect to the high-frequency input of a black and white TV. Surprisingly, somehow the video signal made its way through all these local oscillators to see the characters’ vague outlines (recognizable only if you know what was written there). Our possibilities were limited to writing (almost blindly) the simplest programs in BASIC and downloading games from a tape recorder that was not playable due to the low-quality connection to the screen.

One of the games that attracted attention was “Legend of the Amazon” (or “Amazons,” as we called them then). At the start, there was great music played through a 1-bit speaker. Music could be played “blindly” and listened to endlessly. We tortured the cassette to barely start the game when we finally connected the Companion to the TV’s low-frequency input, and everything became visible. Alas, I didn’t have any other memories of the game — the gameplay was mediocre (or I didn’t understand anything).

Having learned to solder and gathered more information about the ZX Spectrum, I was able to connect a “magic” music coprocessor to our long-suffering “Companion.” It was YAMAHA YM2149F, the analog of AY-3–8912, installed in the original ZX Spectrum 128. It should be noted that the name “music coprocessor” is incorrect because the chip does not execute any code. It is a state machine. In the chip documentation, the term “programmable sound generator” is suggested, so in the future, in the article, I will refer to the chip as a sound generator.

The experiment ended with both success and disappointment. On the one hand, the sound generator worked. On the other hand, it turned out that in many games, the 48K memory was filled to the end, and no memory was left for music. It was customary to place music modules in additional memory pages in those days present in the 128-kilobyte Spectrum. Still, it was absent in our 48-kilobyte “Companion” the sound generator in most cases remained an extra ballast. However, in the ZX Review magazine, from which I took the connection diagram, there was a note on how to check the generator: the music module from the Dizzy IV game was loaded into memory separately from the game, and it could be started. The picture above is a screenshot of the game’s start screen.

This is how the add-on module was loaded:

CLEAR 30000
LOAD “” CODE
RANDOMIZE USR 49152
RANDOMIZE USR 49180

From time to time, I had loaded this module and listened to that beautiful starting music (now you can listen to it here; it is the starting music and the melody inside the game).

AY-3–8912 sound generator

The AY-3–8912 sound generator by General Instrument, which was installed in the ZX Spectrum 128, as well as its analogs, was a fairly popular way to add musical capabilities to computers of that time. This family of chips was installed on such computers as Amstrad CPC and Japanese MSX.

The AY-3–8912 had three channels for generating square wave (tone) signals; one noise generator; an envelope generator for amplitude modulation of tone and noise signals; signal mixer for mixing tone, noise, and envelope signals; volume control module and digital-to-analog converter.

There were three analog channels at the generator’s output, called A, B, and C. In the original Spectrum, the signals were combined into one, and a mono signal was obtained. However, the channels could be connected in pairs and receive a stereo signal. I often came across the union A + C -> left channel, B + C -> right channel, i.e. Channel C was sent to both the left and right outputs, being the central channel. Until the time of this writing, such a connection seemed to be canonical. But it turned out that channel B was often made central, and sometimes in the software, it was possible to find the setting, which channel was considered middle.

It’s worth mentioning, that there were several modifications to the chip. Here are the most common ones:

  • AY-3–8910 — it was produced in a DIP 40 package and additionally had two eight-bit I/O ports;
  • AY-3–8912 — manufactured in DIP 28 package and also had only one eight-bit I/O port;
  • YAMAHA YM2149F — fully compatible with AY-3–8910 but had some additional features.

Using the AY-3–8910 I/O ports, it was possible to connect the computer, for example, to a printer with a parallel interface. But as far as I know, no one did that for clones of the Spectrum.

Music editors for Spectrum

Any Spectrum, even without a sound generator, could play sounds using a 1-bit output channel. The signal was output to a built-in miniature loudspeaker, as in the original Spectrum, and in the clones, piezo-tweeters or other sound reproducing devices were sometimes used instead. Interestingly, in the original Spectrum, only one output of the ULA microcircuit was responsible for input/output from the tape recorder and reproducing sounds. The built-in BASIC supported the BEEP command, which took two parameters — the offset in semitones relative to the “C” note of the first octave and the sound duration in seconds (you can use it in beats). Armed with DATA and FOR operators, it was possible to play any monophonic melody.

The most famous beeper editor is “Wham! The Music Box” or simply “Wham!”. I think the reference to the musical pop duo “Wham” with George Michael was not accidental. There were rumors that the editor was delivered with several demo tracks, one of which was the song “Careless Whisper”. But I did not find any confirmation of this fact.

George Michael version
1-bit vesrion in Wham!

“Wham!” allowed to simultaneously reproduce two voices or sound effects, which was a rarity for a beeper at that time.

It is worth mentioning here, although not an editor, but the game Manic Miner. In 1983 (just a year after the appearance of the ZX Spectrum) on the start screen, there was an attempt to play two sounds simultaneously. During the game, music was played, which required a lot of processor time. But after writing this article, my world will never be the same. I discovered that the author of the game Matthew Smith says in one of the interviews: he used a TRS-80 computer to write the game, connected to the Spectrum via an expansion port. What a scam! (joke)

Game sounds

Before the sound generator, my brother and I also experimented with creating polyphonic music. The Z80 was too slow to generate a multi-voice signal on the fly, but if generated in advance and placed in RAM, it could output data to the audio port at a sufficient speed. I didn’t know what PWM was then …

Our approach allowed us to reproduce a large number of sounds, each with a different volume. The problem was that when the signal was generated in the RAM, the sound was interrupted. As a result, the sounds emitted by our beeper resembled playing a bad balalaika, so this idea was not further developed. A quick search on Youtube shows that much more could be squeezed out of the Spectrum beeper, and enthusiasts are still having so much fun.

There was a version of Wham! for a 128-kilobyte spectrum with AY-3–8912, but the ideas that worked in the previous version became a severe limitation in the current one — it was impossible to play a long note. Also, the notation was not the most suitable for 8-bit music.

A massive breakthrough for computer music lovers was the Polish tracker editor Sound Tracker for the XZ Spectrum (note that this is not the first tracker editor in general, it is the first only for the Spectrum).

According to the number of channels in the sound generator, it was a transition from traditional music notation to letter notation in 3 columns.

Another well-known music editor was ASC Sound Master (ASM) by A. Sendetsky. Unfortunately, the author of this editor is no longer with us (proof). I remember this editor as very cool because the author was not too lazy but developed his file system to save musical compositions. I remember there was a song called “Boom,” which I liked. I listened to it endlessly, then not knowing that it was the music from the same name’s French film.

A rare demo did without music at that time. The best examples (like Insult or Satisfaction) can still be Googled. One of the most mature editors was Pro Tracker, which appeared quite late — in 1995. Quite a lot of music was written with his help.

Indeed everyone familiar with games on the Spectrum has their favorite musical memories. At one time, I was impressed by the bootloader from floppy disks called ZYX. This program was launched very first, showed the catalog of programs on the disk, and allowed you to download one. There were a huge variety of these downloaders with different popular music of the time. I especially liked Jean Michel Jarre.

Surprisingly, demos are still being developed. For AY-3–8912, there is even a completely modern music editor, “Vortex Tracker”, which allows you to write 8-bit music under Windows.

This concludes my historical excursion. In the second part of the article, we will disassemble the Dizzy IV music module and write firmware for the Arduino that will repeat the music from this game, emulating the music processor and using the Dizzy IV music module.

To be continued…

Article author: Anton Dmitrievsky, Maxilect.

PS. Subscribe to our social networks: Twitter, Telegram, FB to learn about our publications and Maxilect news.

--

--

Maxilect

We are building IT-solutions for the Adtech and Fintech industries. Our clients are SMBs across the Globe (including USA, EU, Australia).