Mozart

Date: 1983
Type: Program
Platform(s): TS 2068

This program plays Mozart’s Piano Sonata in C Major, K. 545, using the BEEP command to generate pitched notes on the built-in speaker. Duration variables X (half), Y (quarter), Z (eighth), and A (sixteenth) are derived from a single base value of 0.5, allowing easy tempo scaling. The melody and accompaniment data are stored in DATA statements from line 2030 onward, with transposition achieved arithmetically by adding or subtracting integer offsets to note numbers at playback time rather than storing separate datasets. Several subroutines handle repeating melodic patterns and arpeggios, and RESTORE with specific line numbers allows non-sequential DATA reading for different sections of the piece.


Program Structure

The program is divided into three clearly labelled regions. Lines 1–490 contain subroutines; lines 500–1610 form the main playback sequence; and lines 2000–2310 hold all musical DATA. A RESTORE : GO TO 500 at line 10 ensures the DATA pointer is reset before the main program begins.

LinesRole
50–60Read and play a three-note group (triplet figure)
70–90Play 16 notes at duration z (sixteenth-note run)
100–140Play 8 notes at duration y plus a cadential tail, then PAUSE
150–160Read and play a five-note group with mixed durations
170–190Play 12 notes at duration z
200–230Play a leading note then 12 notes transposed down 12 semitones
240–250Three-note group like line 50–60 but shifted up 5 semitones
500–1610Main sequence: exposition, development, recapitulation
2030–2310DATA blocks for all melodic material
9000–9998Save utility with OUT 244,1 device selection

Duration Variables

All note lengths derive from a single assignment at line 530:

  • X = 0.5 — half note (minim)
  • Y = X/2 = 0.25 — quarter note (crotchet)
  • Z = X/4 = 0.125 — eighth note (quaver)
  • A = X/8 = 0.0625 — sixteenth note (semiquaver)

Compound durations such as X+Y (dotted half), A+Z (dotted sixteenth), and 2*X (whole note) are computed inline at each BEEP call, keeping the code concise and making tempo adjustment trivial — only the value of X need be changed.

Transposition Technique

Rather than duplicating DATA for passages that repeat at a different pitch, the program applies arithmetic offsets at playback time. For example, subroutine 200 subtracts 12 from every data value (BEEP z,b-12), dropping the passage an octave. Lines 960–1010 use offsets of -5 and -17 against the same dataset at line 2190. The recapitulation (lines 1050 onwards) reuses the exposition DATA from line 2030 but shifts notes up by 5 throughout, calling the variant subroutine at line 240 and applying +5 inline. This is an efficient form of data compression well suited to the limited memory of the target machine.

Non-Sequential DATA Access

Multiple RESTORE <line> statements (lines 730, 880, 910, 950, 990, 1020, 1050, 1220, 1240, 1320, 1360, 1400, 1440, 1480, 1540, 1580) allow the program to jump back to specific DATA blocks rather than consuming them linearly. This enables the same DATA to be read multiple times for repeated sections and allows different subroutines to share a dataset, each reading a different number of values or applying a different pitch offset.

Variable Naming Anomaly

The duration variables are initialised as lowercase (x, y, z, a) at line 530 but are referenced as both lowercase and uppercase throughout the rest of the program (e.g. BEEP x,19 at line 580 and BEEP X,19 at line 580 of the recapitulation). In Sinclair BASIC, variable names are case-sensitive for string and array variables but numeric variable names are single letters and are case-insensitive internally; lowercase and uppercase single-letter numeric variables refer to the same storage location, so this inconsistency is harmless in practice.

Notable Idioms and Techniques

  • PAUSE 25 (approximately half a second) is inserted at phrase boundaries to create musical rests and articulation, since BEEP with a very short duration is not a reliable silence.
  • The inner loop pattern FOR m=1 TO 14: READ b: BEEP z,b: NEXT m within an outer FOR n=1 TO 5 reads 15 values per iteration (1 before the inner loop, 14 inside), efficiently unrolling scale-run passages.
  • Subroutine 70 always reads exactly 16 values; subroutine 170 reads 12. Callers use RESTORE beforehand to position the DATA pointer correctly, making subroutine reuse dependent on external state rather than parameters.
  • Line 770 reads 13 variables (B through P, skipping N and O to avoid confusion with the loop counter and the digit zero) in a single READ statement, then issues 13 BEEPs with individually specified durations for a complex rhythmic figure.
  • Negative note values appear in DATA (e.g. -1, -3, -17), which are valid BEEP pitch arguments representing notes below middle C.

Content

Appears On

Capital Area Timex Sinclair User Group’s Library Tape.

Related Products

Related Articles

Related Content

Image Gallery

Mozart

Source Code

    1 REM                                  MOZART's Piano Sonata            in C Major  K 545              *  C-Y Choy   1983  *    
   10 RESTORE : GO TO 500
   20 REM ***********************
   30 REM      SUBROUTINES
   40 REM ***********************
   50 READ b,c,d
   60 BEEP 2*x,b: BEEP x,c: BEEP x,d: RETURN 
   70 FOR m=1 TO 16
   80 READ b: BEEP z,b
   90 NEXT m: RETURN 
  100 FOR n=1 TO 8
  110 READ b: BEEP y,b
  120 NEXT n
  130 BEEP x,14: BEEP x,19: BEEP x,7: PAUSE 25
  140 RETURN 
  150 READ b,c,d,e,f
  160 BEEP 2*x,b: BEEP z,c: BEEP y+z,d: BEEP z,e: BEEP y+z,f: RETURN 
  170 FOR n=1 TO 12
  180 READ b: BEEP z,b
  190 NEXT n: RETURN 
  200 BEEP x,19
  210 FOR n=1 TO 12
  220 READ b: BEEP z,b-12
  230 NEXT n: RETURN 
  240 READ b,c,d
  250 BEEP 2*x,b+5: BEEP x,c+5: BEEP x,d+5: RETURN 
  500 REM ***********************
  510 REM       MAIN PROGRAM
  520 REM **********************
  530 LET X=1/2: LET Y=X/2: LET Z=X/4: LET A=X/8
  540 GO SUB 50
  550 READ B,C,D,E
  560 BEEP X+Y,B: BEEP Z,C: BEEP Z,D: BEEP X,E: PAUSE 25
  570 GO SUB 50
  580 BEEP X,19
  590 FOR N=1 TO 3
  600 BEEP A,19: BEEP A,17: NEXT N
  610 BEEP A,16: BEEP A,17: BEEP X,16: PAUSE 25
  620 FOR N=1 TO 5
  630 READ B: BEEP Y,B
  640 FOR M=1 TO 14
  650 READ B: BEEP Z,B: NEXT M: NEXT N
  660 GO SUB 70
  670 GO SUB 100
  680 FOR N=1 TO 2
  690 FOR M=1 TO 4
  700 IF N=1 THEN BEEP Z,1: BEEP Z,2: GO TO 720
  710 BEEP Z,0: BEEP Z,2
  720 NEXT M: NEXT N
  730 RESTORE 2120
  740 FOR N=1 TO 2
  750 RESTORE 2120
  760 READ B,C,D,E,F,G,H,I,J,K,L,M,P
  770 BEEP Y,B: BEEP Y,C: BEEP X+Y,D: BEEP Z,E: BEEP Z,F: BEEP Y,G: BEEP Y,H: BEEP A,I: BEEP A,J: BEEP A,K: BEEP A+Z,L: BEEP Z,M: BEEP X,P: PAUSE 50
  780 NEXT N
  790 FOR N=1 TO 4
  800 GO SUB 70: NEXT N
  810 GO SUB 150
  820 BEEP Z,20: BEEP X+Z,21: BEEP A,23: BEEP A,21: BEEP A,20: BEEP A,21: BEEP Y,24: BEEP Y,21: BEEP Y,24: BEEP Y,21
  830 BEEP Y,23: BEEP Y,19: BEEP 2*X,26: BEEP Z,24: BEEP Z,23: BEEP Z,21: BEEP Z,19
  840 FOR N=1 TO 15
  850 BEEP A,23: BEEP A,21: NEXT N
  860 BEEP Z,19: BEEP Z,21: BEEP X,19
  870 GO SUB 170
  880 RESTORE 2180: GO SUB 200
  890 BEEP X,7: BEEP X,23: BEEP X,19: PAUSE 25
  900 BEEP X,7: GO SUB 170
  910 RESTORE 2190: GO SUB 200
  920 FOR N=1 TO 2
  930 GO SUB 70: NEXT N
  940 BEEP X,17
  950 RESTORE 2190
  960 FOR N=1 TO 12
  970 READ B: BEEP Z,B-5: NEXT N
  980 BEEP X,14
  990 RESTORE 2190
 1000 FOR N=1 TO 12
 1010 READ B: BEEP Z,B-17: NEXT N
 1020 RESTORE 2220
 1030 FOR N=1 TO 7
 1040 GO SUB 70: NEXT N
 1050 RESTORE 2030: GO SUB 240
 1060 READ B,C,D,E
 1070 BEEP X+Y,B+5: BEEP Z,C+5: BEEP Z,D+5: BEEP X,E+5: PAUSE 25
 1080 GO SUB 240
 1090 BEEP X,24
 1100 FOR N=1 TO 3
 1110 BEEP A,24: BEEP A,22: NEXT N
 1120 BEEP x,21: BEEP A,22: BEEP X,21: PAUSE 25
 1130 FOR N=1 TO 4
 1140 READ B: BEEP Y,B+5
 1150 FOR M=1 TO 14
 1160 READ B: BEEP Z,B+5
 1170 NEXT M: NEXT N
 1180 BEEP 2*X,21: PAUSE 25: BEEP X,21
 1190 BEEP 2*X,19: PAUSE 25: BEEP X,19
 1200 BEEP 2*X,17: PAUSE 25: BEEP X,17
 1210 BEEP 2*X,16: PAUSE 25: BEEP X,16
 1220 RESTORE 2300
 1230 GO SUB 70
 1240 RESTORE 2100
 1250 GO SUB 70: GO SUB 100
 1260 FOR N=1 TO 2
 1270 FOR M=1 TO 4
 1280 IF N=2 THEN BEEP Z,5: BEEP Z,7: GO TO 1300
 1290 BEEP Z,6: BEEP Z,7
 1300 NEXT M: NEXT N
 1310 FOR N=1 TO 2
 1320 RESTORE 2120
 1330 READ B,C,D,E,F,G,H,I,J,K,L,M,P
 1340 BEEP Y,B-7: BEEP Y,C-7: BEEP X+Y,D-7: BEEP Z,E-7: BEEP Z,F-7: BEEP Y,G-7: BEEP Y,H-7: BEEP A,I-7: BEEP A,J-7: BEEP A,K-7: BEEP A+Z,L-7: BEEP Z,M-7: BEEP X,P-7: PAUSE 50
 1350 NEXT N
 1360 FOR N=1 TO 2
 1370 FOR M=1 TO 16
 1380 READ B: BEEP Z,B-7
 1390 NEXT M: NEXT N
 1400 FOR N=1 TO 2
 1410 FOR M=1 TO 16
 1420 READ B: BEEP Z,B+5
 1430 NEXT M: NEXT N
 1440 RESTORE 2290
 1450 GO SUB 150
 1460 BEEP 2*X,21: BEEP Z,20: BEEP Y+Z,21: BEEP Z,20: BEEP Y+Z,21
 1470 BEEP Y,19
 1480 RESTORE 2310
 1490 FOR N=1 TO 14
 1500 READ B: BEEP Z,B: NEXT N
 1510 FOR N=1 TO 15
 1520 BEEP A,16: BEEP A,14: NEXT N
 1530 BEEP Z,12: BEEP Z,14: BEEP X,12
 1540 RESTORE 2180
 1550 FOR N=1 TO 12
 1560 READ B: BEEP Z,B-7: NEXT N
 1570 BEEP X,12
 1580 RESTORE 2180
 1590 FOR N=1 TO 12
 1600 READ B: BEEP Z,B-19: NEXT N
 1610 BEEP X,0: BEEP X,16: BEEP X+X,12: PAUSE 50
 2000 REM ***********************
 2010 REM          DATA
 2020 REM ***********************
 2030 DATA 12,16,19,11,12,14,12
 2040 DATA 21,19,24
 2050 DATA 9,11,12,14,16,17,19,21,19,17,16,14,12,11,9
 2060 DATA 7,9,11,12,14,16,17,19,17,16,14,12,11,9,7
 2070 DATA 5,7,9,11,12,14,16,17,16,14,12,11,9,7,5
 2080 DATA 4,5,7,9,11,12,14,16,14,12,11,9,7,5,4
 2090 DATA 2,4,5,7,9,11,13,14,9,11,13,14,16,17,19
 2100 DATA 21,23,24,23,21,19,17,16,17,19,21,19,17,16,14,12
 2110 DATA 11,19,16,12,14,19,16,12
 2120 DATA 26,23,19,21,23,21,19,21,19,21,19,18,18
 2130 DATA 26,-1,2,7,11,26,23,19,16,0,4,7,12,16,19,16
 2140 DATA 24,-3,0,6,9,24,21,18,14,-1,2,6,11,14,18,14
 2150 DATA 23,-5,-1,4,7,23,19,16,12,-3,0,4,9,12,16,12
 2160 DATA 21,-6,-3,2,6,21,18,14,11,-5,-1,2,7,19,14,11
 2170 DATA 9,11,12,15,16
 2180 DATA 19,14,19,23,26,23,19,23,24,21,18,21
 2190 DATA 19,14,19,22,26,22,19,22,24,21,18,21
 2200 DATA 7,-17,-15,-14,-12,-10,-8,-6,-5,19,22,21,19,17,16,14
 2210 DATA 13,-15,-13,-11,-10,-8,-6,-4,-3,25,28,26,25,22,21,19
 2220 DATA -7,2,4,5,7,9,11,13,14,2,5,4,2,0,-1,-3
 2230 DATA -4,11,12,14,16,18,20,21,23,-4,-1,-3,-4,-7,-8,-10
 2240 DATA -12,21,28,26,24,23,21,19,17,2,9,7,5,4,2,0
 2250 DATA -1,19,26,24,23,21,19,17,16,0,7,5,4,2,0,-1
 2260 DATA -3,17,24,23,21,19,17,16,14,-1,5,4,2,0,-1,-3
 2270 DATA -4,16,23,21,20,17,16,14,12,-3,0,-1,-3,-5,-7,-8
 2280 DATA -10,10,14,12,10,9,7,5,4,5,7,9,10,12,14,16
 2290 DATA 14,13,14,13,14
 2300 DATA 14,2,4,5,7,9,11,13,14,9,11,13,14,16,17,19
 2310 DATA 21,23,24,26,28,26,24,23,21,19,17,16,14,12
 8999 STOP 
 9000 OUT 244,1
 9020 LET save=9000
 9997 STOP 
 9998 SAVE "MOZART" LINE 1

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

People

No people associated with this content.

Scroll to Top