BASIC music loading program for the ZX81
So far in this series we've discussed machine code programming of the ZX81, and output ports for feeding synthesisers. This means we can feed out numbers representing notes to up to seven synthesisers, giving polyphonic music. In this, the last article on this subject (for a while at least) we shall describe a program for entering the coded notes into the machine. The machine code routine given last month expects to find its data in array A$, and Table 1 lists a program for entering numbers into the array. This program is the result of much alteration and "honing" — which explains the eccentric line numbering system — and this process is still continuing; there is plenty of scope for alteration and customising to suit personal requirements.
The REM statement in line 1 is the machine code routine itself, and is included only to give some idea of what this will look like; don't try to enter it from the keyboard, because it won't work. Instead, enter a REM statement with 180 characters in it (I usually use full stops) and then use the "machine code monitor" discussed in December; this is subsequently erased, leaving only line 1 of course, and the rest of the program can be entered as usual.
Line 9990 enables the program to be stored on cassette in "LOAD" and "RUN" fashion (actually LOAD and GOTO in this case) which saves the embarrassment caused if you try to start the program with RUN; this erases all the music data, of course. If you do stop the program when it contains data you want to keep, always restart using GOTO 100 to avoid bad language and broken computers.
When the program is first run, it will start off by asking you the number of voices (synthesisers) you want to use, the number of notes, and the name of the piece. The number of notes is not necessarily the same as the number of "blobs" in the music; this variable should more accurately be called "events". For instance, if a quaver is the shortest note in the piece, and the music is in 4/4 time, there will be 8 quavers per bar. For reasons which will be explained, you would probably want 16 events per bar, and a 100 bar piece would require 1600 events. You will need a 16K RAM pack to fit the program in, and with this amount of memory there is room for over 12800 events; using the maximum of seven voices, this allows 1825 events per voice, which should be sufficient for most uses.
Once the initial conditions are established, the program moves on to the "title page" which repeats the information you've just fed in, and also presents a list of choices of what to do next; this also happens when the program is loaded from tape.
The choices are selected by entering the appropriate letter. P, T and S should be self explanatory; C enables you to start again from scratch, and E (or indeed any character other than P, T, C or S) is for writing or altering the music. The letter E by itself will start at event 1; if you want to start halfway through, enter E250 (for instance) to start at event 250.
Once you are in edit mode, these letters still have the same effect, so you can skip about by entering E followed by a number for example; and there is also a further "menu" to aid the music entry. If the entry is a number (detected by lines 2115 to 2135) this is taken as a note to be entered; the note code system will vary according to the synthesiser in use, and this was covered in January.
V followed by a number allows you to choose which voice to enter; e g. V2 selects voice 2. A letter V at the top of the display points to the voice in use.
New line allows you to skip on to the next event without entering any data.
R enters a rest.
J repeats the previous entry.
K repeats the previous event, but on all voices at once; for sustaining a chord, for instance.
B repeats a whole block of several events. This is also useful for moving the data around — so that you can insert new material, for instance.
F (for fine) signals the end of the piece.
D (for da capo) also signifies the end, but makes the piece repeat until BREAK is pressed.
Figure 1 is an extract from a piece by yours truly, written so that it uses the maximum of seven voices. The shortest note is a quaver, so you might expect the extract to need 8 events per bar, 16 altogether. In fact, in some places notes are repeated, but not "tied"; a musician playing these would automatically insert a small rest between them, even though one is not written. The computer has to be told about these rests explicitly, and so we allow 32 events to give room for the rests.
Table 2 shows how the piece would appear programmed in "linear" code — for feeding D to A converters for instance — and Table 3 gives the same thing in Wasp code; hopefully these examples will clarify any minor points I haven't explained.
As you will see, a certain amount of effort (not to say tedium) is involved in entering a lengthy piece of music; this is the price you pay for such a good value system. How much would a 12 000 note sequencer cost from a commercial manufacturer, if such a machine were available? For the sake of a day's work slaving over a hot TV set, my ZX81 can play nearly any music I choose, as many times as I like, and much better than I ever could! (My chess computer keeps beating me too.)
Feature by Peter Maydew
mu:zines is the result of thousands of hours of effort, and will require many thousands more going forward to reach our goals of getting all this content online.
If you value this resource, you can support this project - it really helps!