When I first got my Commodore 64 in 1983, one of the things I did with it was to program it to play music, in particular Bach organ works. The Commodore 64 had a 3-voice synthesizer built into it (called the SID chip) which was capable of four different timbres: white noise, triangle, sawtooth, and pulse with an adjustable pulse rate. It also has an attack, decay, sustain, and release envelope.
The only problem was that the SID chip required using the PEEK and POKE statements to program it; there were no predefined sound commands in Commodore 64 BASIC. To help alleviate that problem, Mike Steed of Compute! magazine published a utility called SYSound in the September 1984 issue. The utility was so named as it was invoked using the SYS command, which is used to invoke a machine language program. The syntax of the command is:
SYS 49152,Vx,F(x),Wyx,Ax,Dx,Sx,Rx
Where:
The SID chip was initialized with the following command:
SYS 49152,C,Lx
Where:
The frequency of each note was read off of a chart published in the appendix of the Commodore 64 Programmer's Reference Guide. Here's a small portion, encompassing middle C for one octave:
Note | Frequency |
---|---|
C-4 | 4291 |
C#-4 | 4547 |
D-4 | 4817 |
D#-4 | 5103 |
E-4 | 5407 |
F-4 | 5728 |
F#-4 | 6069 |
G-4 | 6430 |
G#-4 | 6812 |
A-4 | 7217 |
A#-4 | 7647 |
B-4 | 8101 |
As an example, consider the opening measures of Bach's Toccata and Fugue in D Minor, BWV 565:
This is the portion of the BASIC program using SYSound to produce the above music:
10 Z=5 20 PRINT "{SC}":PRINT"(BL}" 30 POKE 53280,0:POKE 53281,0 40 PRINT SPC(ll)"{CD){CD){CD){CD){CD}(CD){CD}TOCCATA IN D MINOR" 50 PRINT:PRINT SPC(16)"BWV 565" 60 PRINT:PRINT SPC(8)"BY JOHANN SEBASTIAN BACH" 100 S=49152:SYS S,C,L15:T=TIME 110 READ D:IF D=O THEN 230 120 READ Nl,N2,N3 130 SYS S,V1,F(Nl),WP2048,Al,D2,SlO,RlO 140 SYS S,V2,F(N2),WP2048,Al,D2,SlO,RlO 150 SYS S,V3,F(N3),WP2048,Al,D2,SlO,RlO 160 T=T+(Z+2)*D 170 IF T>TIME GOTO 170 180 GOTO 110 200 REM MEASURE 1 201 DATA 1,14435,7217,0,1,13625,6812,0,8,14435,7217,0,3,1,1,1 202 DATA 1,12860,6430,0,1,11457,5728,0,1,10814,5407,0,1,9634,4817,0 203 DATA 2,9094,4547,0,8,9634,4817,0,6,1,1,1,1,7217,3608,0 204 DATA 1,6812,3406,0,8,7217,3608,0,3,1,1,1,2,5407,2703,0 205 DATA 2,5728,2864,0,2,4547,2273,0,8,4817,2408,0 206 REM MEASURE 2 207 DATA 6,1,1,1,1,3608,1804,0,1,3406,1703,0,8,3608,1804,0 208 DATA 3,1,1,1,1,3215,1607,0,1,2864,1432,0,1,2703,1351,0 209 DATA 1,2408,1204,0,2,2273,1136,0,8,2408,1204,0,8,1204,1,1 210 DATA 4,0,2273,0,4,0,0,2703,4,0,0,3215,4,0,0,3823 211 DATA 4,0,0,4547,16,0,0,5407 212 REM MEASURE 3 213 DATA 16,0,0,3215,6,0,0,2703,16,0,0,3034,1,1,1,1,0
Imagine an entire BASIC program consisting mostly of endless DATA statements with note timing values and frequencies. Often took weeks just to put together one program.
Here's all the music I did on the Commodore 64, in MP3 format: