This program plays an arrangement of Chopin’s Prelude using the AY-3-8912 sound chip via the SOUND statement. Each musical event is encoded as an 8-value DATA record (AF, AC, BF, BC, CF, CC, F, V) representing the frequency and amplitude registers for channels A, B, and C, a BEEP pitch value, and a note duration divisor. A sentinel value of -1 in the AF field triggers a 16-value register-load block for the AY chip’s tone, noise, and mixer registers, while F=99 signals a pure PAUSE rest instead of a BEEP. The program offers looped playback, one-shot playback, and a tempo adjustment facility by varying the TT multiplier applied to the base duration R read from the opening DATA record.
Program Structure
The program divides into four functional regions:
- Initialisation (lines 10–20): Sets colours, reads the title string
N$and base tempo ratioRfrom line 3000, and resets the tempo multiplierTTand loop flagZ$. - Display and playback engine (lines 30–130): Prints the “NOW PLAYING” banner, then enters the main DATA-driven loop that reads and dispatches each musical event.
- Post-play menu (lines 140–290): After an
ON ERR/RESETcatches the end-of-data condition, the user may loop continuously, choose a different tempo, or stop. - Data block (lines 3000–3100): Roughly 800 comma-separated values encoding the entire Prelude arrangement, preceded by a header record at line 3000.
Sound Architecture
The playback loop at line 80 reads eight values per iteration: AF, AC, BF, BC, CF, CC, F, V. These map as follows:
| Variable | Meaning |
|---|---|
AF | Channel A frequency (AY register pair, low byte); −1 signals a 16-register block follows |
AC | Channel A amplitude / register value |
BF | Channel B frequency low byte |
BC | Channel B amplitude |
CF | Channel C frequency low byte |
CC | Channel C amplitude |
F | BEEP semitone offset, or 99 for a rest (PAUSE only) |
V | Note value divisor (e.g. 4 = quarter note) |
When AF < 0 (i.e. −1), execution falls through to line 110 and a PAUSE is issued; this sentinel marks chords where only the AY chip sustains sound without a new BEEP pitch. When F = 99, line 110 again uses PAUSE instead of BEEP, producing a silent rest of the correct duration.
Line 70 issues SOUND 7,56;8,15;9,15;10,15 once per play-through to configure the AY mixer and noise registers globally before the loop begins. Line 130 restores them to silence with SOUND 7,63 at the end.
Use of ON ERR and RESET
The ON ERR keyword is used at line 80 to intercept the “Out of DATA” error that naturally occurs when the DATA block is exhausted. This is a common idiom in 2068 music programs as a clean way to detect end-of-score without counting records. Line 130 cancels the error trap with ON ERR RESET before resetting the AY chip.
Tempo Control
The note duration formula is T/V, where T = R * TT. R is the scaling constant read from the DATA header (0.2 for this piece) and TT starts at 10, giving T = 2.0. The user-adjustable tempo path (lines 220–290) replaces TT via INPUT; larger values slow the piece, smaller values speed it up. The explanatory text correctly states the original tempo is 10.
Key BASIC Idioms
RESTORE 3010at line 140 rewinds the DATA pointer to the first musical record (skipping the header at 3000), allowing seamless repeat play.- The centred title display at line 40 uses
AT 10,(31-LEN N$)/2— a standard Spectrum-family centring formula. PAUSE 0followed byINKEY$at line 180 is the standard efficient keypress-wait idiom.- The loop flag
Z$is set to"1"implicitly only by the continuous-play branch at line 190; line 140 checks it to skip the menu and go directly back to playback.
Content
Image Gallery
Source Code
1 REM program 31 p. 109 of "30 Music Programs for Timex Sinclair 2068" by Jefimenko
2 REM Example of Sound function
10 BORDER 4: PAPER 6: CLS : READ N$,R
15 LET TT=10: LET Z$=""
20 LET TT=10: LET Z$=""
30 PRINT PAPER 5;"***********NOW PLAYING**********"
40 PRINT AT 10,(31-LEN N$)/2;N$
50 PRINT PAPER 5;AT 21,0;"***********NOW PLAYING**********"
60 PRINT PAPER 3; INK 7;AT 20,0;"TO STOP PRESS""SHIFT"" + ""BREAK"""
70 LET T=R*TT: SOUND 7,56;8,15;9,15;10,15
80 READ AF,AC,BF,BC,CF,CC,F,V: ON ERR GO TO 130: IF AF<0 THEN GO TO 100
90 SOUND 0,AF;1,AC;2,BF;3,BC;4,CF;5,CC
100 IF F<>99 THEN GO TO 120
110 PAUSE T/V*60: GO TO 80
120 BEEP T/V,F: GO TO 80
130 ON ERR RESET : SOUND 7,63
140 RESTORE 3010: IF Z$="1" THEN GO TO 70
150 CLS : PRINT AT 7,0;"PRESS ""1"" TO PLAY CONTINUOUSLY."
160 PRINT '"PRESS ""2""TO PLAY DIFFERENTLY"
170 PRINT '"PRESS ""S""TO STOP"
180 PAUSE 0: LET Z$=INKEY$
190 IF Z$="1" THEN CLS : GO TO 30
200 IF Z$="2" THEN GO TO 220
210 STOP
220 CLS : PRINT AT 4,0;"YOU CAN PLAY THIS COMPOSITION"
230 PRINT "AT A DIFFERENT TEMPO. THE"
240 PRINT "ORIGINAL TEMPO IS 10. INPUT 10"
250 PRINT "TO RETAIN THE ORIGINAL TEMPO."
260 PRINT "INPUT A LARGER NUMBER FOR A"
270 PRINT "SLOWER TEMPO. INPUT A SMALLER"
280 PRINT "NUMBER FOR A FASTER TEMPO."
290 INPUT TT: CLS : GO TO 30
380 SAVE "PRELUDE" LINE 10
3000 DATA "PRELUDE BY CHOPIN",.2
3010 DATA 0,0,0,0,0,0,4,4,47,5,47,5,47,5,13,5.33,-1,0,0,0,0,0,14,16,7,1,116,1,151,2,11,4,7,1,116,1,151,2,11,4,7,1,116,1,151,2,11,4,7,1,116,1,115,2,11,1,0,0,0,0,0,0,18,4,209,0,226,3,226,3,15,5.22,-1,0,0,0,0,0,16,16,197,0,75,1,241,1,21,4
3020 DATA 197,1,75,1,241,1,21,4,197,0,75,1,241,1,21,2,0,0,0,0,0,0,13,4,138,1,47,5,47,5,10,5.33,-1,0,0,0,0,0,11,16,39,1,186,1,151,2,14,4,39,1,186,1,151,2,14,4,39,1,186,1,151,2,14,2,116,1,0,0,0,0,8,4,116,1,196,7,196,7,8,5.33
3030 DATA -1,0,0,0,0,0,9,16,138,1,241,1,151,2,13,4,138,1,241,1,151,2,13,4,138,1,241,1,151,2,13,2,0,0,0,0,0,0,4,4,47,5,47,5,47,5,13,5.33,-1,0,0,0,0,0,14,16,7,1,116,1,151,2,11,4,7,1,116,1,151,2,11,4,7,1,116,1,151,2,11,2
3040 DATA 0,0,0,0,0,0,18,4,209,0,226,3,226,3,15,5.33,-1,0,0,0,0,0,16,16,124,0,75,1,241,1,25,4,124,0,75,1,241,1,25,4,117,0,138,1,79,2,25,2,248,0,0,0,0,0,13,4,234,0,235,6,235,6,13,5.33,-1,0,0,0,0,0,14,16,221,0,116,1,79,2,18,4
3050 DATA 248,0,186,1,79,2,18,4,7,1,186,1,151,2,18,2,116,1,0,0,0,0,8,4,116,1,196,7,196,7,11,5.33,-1,0,0,0,0,0,9,16,197,0,241,1,151,2,21,4,197,0,75,1,241,1,21,4,197,0,75,1,241,1,21,2,0,0,0,0,0,0,99,4,0,0,0,0,0,0,4,4
3060 DATA 47,5,47,5,47,5,13,5.33,-1,0,0,0,0,0,14,16,7,1,116,1,151,2,11,4,7,1,116,1,151,2,11,4,7,1,116,1,151,2,11,2,0,0,0,0,0,0,18,4,209,0,226,3,226,3,15,5.33,-1,0,0,0,0,0,16,16,197,0,75,1,241,1,21,4,197,0,75,1,241,1,21,4
3070 DATA 197,0,75,1,241,1,21,2,0,0,0,0,0,0,13,4,138,1,47,5,47,5,10,5.33,-1,0,0,0,0,0,11,16,39,1,186,1,151,2,14,4,39,1,186,1,151,2,14,4,39,1,186,1,151,2,14,2,116,1,0,0,0,0,8,4,116,1,196,7,196,7,8,5.33,-1,0,0,0,0,0,9,16
3080 DATA 138,1,124,1,151,2,13,4,138,1,241,1,151,2,13,4,138,1,241,1,151,2,13,2,0,0,0,0,0,0,4,4,47,5,47,5,47,5,13,5.33,-1,0,0,0,0,0,14,16,7,1,116,1,151,2,11,4,7,1,116,1,151,2,11,4,7,1,116,1,151,2,11,2,0,0,0,0,0,0,18,4
3090 DATA 209,0,226,3,226,3,15,5.33,-1,0,0,0,0,0,16,16,124,0,75,1,241,1,25,4,124,0,75,1,241,1,25,4,117,0,138,1,79,2,25,2,248,0,0,0,0,0,13,4,234,0,235,6,235,6,13,5.33,-1,0,0,0,0,0,14,16,221,0,116,1,79,2,18,4,248,0,186,1,79,2,18,4
3100 DATA 7,1,186,1,151,2,18,2,116,1,0,0,0,0,8,4,116,1,196,7,196,7,11,5.33,-1,0,0,0,0,0,9,16,197,0,241,1,151,2,21,4,197,0,75,1,241,1,21,2,0,0,0,0,0,0,99,4
9997 STOP
9998 SAVE "CHOPIN" LINE 10
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.