X68000

Programming the ZX Spectrum Beeper

by admin on Mai.19, 2009, under Music Creation, Programming

The ZX Spectrum from 1982, although well known for its AY-3-8912 Multichannel Tunes, also features a build-in Beeper. The Beeper was actually the only sound source until the ZX Spectrum 128 was released 3 years later.

Emulation

You can skip this part if you have a real ZX Spectrum.

The ZX Spectrum is pretty well Emulated and you can choose from lots of Emulators. The ones I found didnt require any additional files like a bios, so this part is very easy and you should get an Emulator running soon. I’ve used EmuZWin for the most part, which has a useful option that shows you the ZX Keyboard which you will need later on.

BASIC Intro / how to Input BEEP

At first, launch the ZX and press Enter. This will bring you to the BASIC Interpreter, with a blinking Cursor that shows a “K”. Very minimalistic somehow.

zx1

Welcome to the Basic Interpreter

There are several Modes for entering commands into the Interpreter now. The Command that controls the Beeper is called BEEP.

Unfortunately you cannot just write down your commands, because at the moment we’re inside the “K” (Keywords) Mode. There are also other modes, like “G” (Graphics) or “E” (Extended). Pressing the B Key will input the BORDER Command, which is not really what we are looking for. All the Keys on the ZX Keyboard will enter different BASIC Commands.

The BEEP Command we are looking for can be written inside the “E” Mode, which you can reach by pressing both Shift Keys together (Right Shift + STRG in EmuZWin). Since BEEP is above the Z Letter on the keyboard, you have to go inside the E mode, then press Shift together with “Z” to write BEEP. If you are using EmuZWin, you can have a look at the ZX Keyboard by pressing Alt+K, this will probably make some more sense then. ;) Its easy once you get it.

The “BEEP” Command

As said before, the BEEP Command is what controls the ZX Beeper, its pretty easy to use:

BEEP duration, pitch

Example: BEEP 2, 0 (this will output a C for 2 seconds)

The Duration is entered in Seconds. 1 = 1 Second, .5 = a half Second, and so on.

As for the Pitch, you have to imagine a Keyboard and count the keys, like this:

ZX Pitch

The Values for the Pitch. 0 = C, 1 = C#, 2 = D and so on..

The 0 is actually a C4 (or C3?). The next Octave goes on from this with values like 12, 13, 14.. and if you want to go deeper you can enter Values like -1, -2, etc. Its easy when you have a table like the one above. You can also enter values like 1.5, which would set the pitch halfway between C# and D.

In the end, we might come up with a song like this:

ZX Spectrum Basic

This is actually from Final Fantasy

GO TO makes it loop, of course.

That’s it!


Leave a Reply

x68000.de

yay

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...