Elementary Piano draws a piano keyboard on the screen and lets you play it. The white keys are the QWERTYUIOP row and the black keys are the number keys above them (2, 3, 5, 6, 7, 9, 0). Press A, S or D to choose the lower, middle or upper octave. Each note is played on channel A of the TS2068’s AY sound chip with an envelope, so it sounds struck and fades.
This is the type-in from the LISTing newsletter of September 1984, “Elementary Piano”, by Nazir A. Pashtoon. The article explains the program line by line, and the copy here matches it.
Program Analysis
Program Structure
- Lines 10–300 draw the keyboard point by point with PLOT and label the keys and octave choices.
- Lines 600–640 fill the array
b()so that it is indexed by the character code of each key, holding the pitch values from page 187 of the TS2068 manual (DATA 1000–1400). - Lines 650–770 poll INKEY$; 800–880 play a middle or upper note, 900–980 a lower one, where the coarse-tune register is also needed.
Notable Techniques
DIM b(256)used as a lookup table indexed byCODE INKEY$+1needs no search for the key pressed.- The flags
Fandztell the octaves apart and set the coarse-tune register for pitches below 164 in the low octave.
Potential Issues
- Drawing the keyboard with single PLOT statements takes about two minutes.
- Each note holds the program for two seconds (
PAUSE 120), so fast playing isn’t possible.
This copy comes from a Larken disk, the TTSUC library disk “Music and Sound”. It was converted for tape (the disk command was removed from the save line) and tested in ZEsarUX.
Source Code
1 REM "ELEM-PIANO" ; 3 octaves
5 INK 0: PAPER 7: BORDER 7: CLS : POKE 23658,0
10 FOR x=3 TO 252
20 PLOT x,10: PLOT x,100: NEXT x
30 FOR x=3 TO 260 STEP 25
40 FOR y=10 TO 100
50 PLOT x,y
60 NEXT y: NEXT x
65 LET n=0
70 FOR x=28 TO 228 STEP 25
80 LET n=n+1
90 IF n=3 OR n=7 THEN GO TO 130
100 FOR y=40 TO 100 STEP 1
105 FOR e=1 TO 12
110 PLOT x-6+e,y
115 NEXT e
120 NEXT y
130 NEXT x
140 FOR x=0 TO 9
150 LET k$="QWERTYUIOP"
160 PRINT AT 19,x*3+2;k$(x+1)
170 NEXT x
190 LET k$="2356790"
200 PRINT AT 14,3; BRIGHT 1; INVERSE 1;k$(1);AT 14,6;k$(2);AT 14,13;k$(3);AT 14,16;k$(4);AT 14,19;k$(5);AT 14,25;k$(6);AT 14,28;k$(7): INVERSE 0: BRIGHT 0
300 PRINT AT 3,1;"For lower octave press";AT 3,27; BRIGHT 1;"A"; BRIGHT 0;AT 5,1;"For middle octave press"; BRIGHT 1;AT 5,28;"S"; BRIGHT 0;AT 7,1;"For higher octave press"; BRIGHT 1;AT 7,29;"D"; BRIGHT 0
500 REM MUSIC MAKER
510 RESTORE 1200
520 LET F=0
600 DIM b(256)
610 LET k$="q2w3er5t6y7ui9o0p"
620 FOR l=1 TO 17
630 READ b(CODE k$(l)+1)
640 NEXT l
650 LET k=CODE INKEY$+1
660 IF INKEY$="a" OR INKEY$="A" THEN RESTORE 1000: LET F=1: GO TO 620
670 IF INKEY$="s" OR INKEY$="S" THEN RESTORE 1200: LET F=0: GO TO 620
680 IF INKEY$="d" OR INKEY$="D" THEN RESTORE 1400: LET F=0: GO TO 620
760 IF b(k) AND F=1 THEN GO TO 900
765 IF b(k) THEN GO TO 800
770 GO TO 650
800 REM
850 SOUND 0,b(k);1,0;8,31;11,16;12,55;13,8;7,56
860 PAUSE 120
870 SOUND 8,0;7,63
880 GO TO 650
900 LET z=0
910 IF b(k)<164 THEN LET z=1
950 SOUND 0,b(k);1,z;8,31;11,16;12,55;13,8;7,56
960 PAUSE 120
970 SOUND 8,0;7,63
980 GO TO 650
1000 DATA 162,138,116,95,75,57,39,23,7,248,234,221,209,197,186,175,165
1200 DATA 209,197,186,175,165,156,147,139,131,124,117,110,104,98,93,87,82
1400 DATA 104,98,93,87,82,78,73,69,65,62,58,55,52,49,46,43,41
9998 SAVE "piano.B3" LINE 1Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

