Organ Grinder (New Owners Column, Lesson 14)
- Type
- Sound
- Category
- Keyboard organ and BASIC sound tutorial
- Author
- David Plotkin
- Published in
- Antic, May 1987 (Vol. 6, No. 1), "New Owners Column" Lesson 14
- Year
- 1987
- Language
- Atari BASIC
- Requirements
- Any Atari 8-bit, 16K RAM, Atari BASIC
About the program
Antic's New Owners Column taught Atari BASIC to beginners from the March 1986 issue onwards. David Plotkin finished the series in May 1987 with Lesson 14, on sound, and Antic announced that a new series on animated graphics and game design would follow. The lesson explains the SOUND voice, pitch, distortion, volume statement and the eight POKEY registers at 53760–53767 that you can POKE directly. Its first listing puts the ideas together as a small organ. The middle row of the keyboard plays a ten-note scale, and each note lights up on a drawn piano keyboard.
The companion listing, a menu of sound effects, has its own entry: Sound Menu.
Typing it in
It's plain text apart from two places. The inverse word {inv}SELECT{/inv}/{inv}START{/inv} in lines 270–280 is typed with the Atari (inverse) key before and after. In line 60, the title alternates normal and inverse pairs of letters: An{inv}Ti{/inv}C p{inv}Re{/inv}Se{inv}Nt{/inv}S. Type the lower-case letters with CAPS off. Each of the four kinds of character (upper, lower, inverse upper, inverse lower) shows in a different colour in GRAPHICS 1. Every line is commented, as you'd expect in a beginners' series, and you can leave the REMs out.
How to use it
- A title slides in letter by letter, then the colours cycle until you press a key.
- Press SELECT to pick a tempo from 1 to 5 (this sets how long each note lasts), then press START.
- Play with A S D F G H J K L ;. These play B, C, D, E, F, G, A, B, C and D, as labelled under the keys. A dot marks the key you're playing. ESC quits.
How it works
- The sliding title (lines 90–170) reads 13 character codes from DATA and slides each one along row 8 from the left with
PLOT. In GRAPHICS 1 theCOLORvalue is the character to plot. Each letter stops one column short of the one before, so the DATA spells the words backwards. Once all 13 have arrived, they read ORGAN GRINDER in four colours, because the codes mix upper case, lower case and inverse. - Colour cycling (line 210) rotates the four colour registers 708–711 with PEEK and POKE, so the letters seem to flash.
- Console keys. Location 53279 (CONSOL) reads 5 when SELECT is pressed and 6 for START.
- The keyboard. Line 600 waits until location 764 shows a key. That location holds the keyboard's internal code, not ATASCII. The KEYTABLE array (line 80) lists the codes for the ten keys (63 = A, 62 = S … 2 = ;), and line 630 finds the key in it. The matching pitch from line 590 is played with distortion 10, a pure tone. Note that the scale is only approximately in tune, as POKEY's 8-bit pitch values always are.
- Drawing letters in GRAPHICS 7. Lines 450–540 draw A, S, D, F … with
PLOTandDRAWTO, which is one way to put text on a graphics-only screen.
The article describes the organ as keeping track of free voices and letting you play several notes at once. The version on the Antic disk, printed here, uses only voice 0 and plays one note at a time.
Variations to try
- Change the pitches in line 590 using the note table in any Atari BASIC manual, for example to start the scale on C.
- Give the notes a decay. Replace the fixed delay in line 670 with a loop that steps the volume down, such as
FOR V=10 TO 0 STEP -1:SOUND 0,NTES(NT),10,V:FOR W=1 TO TEMPO*2:NEXT W:NEXT V. - Try distortion 12 instead of 10 in line 650 for a buzzier organ.
Listing
10 REM THE NEW OWNER'S COLUMN #14
20 REM BY DAVID PLOTKIN
30 REM (c) 1987, ANTIC PUBLISHING
40 GRAPHICS (1+16):REM FULL TITLE SCREEN
50 SETCOLOR 4,3,2:REM RED BACKGROUND
60 POSITION 3,5:PRINT #6;"An{inv}Ti{/inv}C p{inv}Re{/inv}Se{inv}Nt{/inv}S";
70 DIM KEYTABLE(10):RESTORE 80:FOR X=1 TO 10:READ Y:KEYTABLE(X)=Y:NEXT X
80 DATA 63,62,58,56,61,57,1,5,0,2
90 FOR LP=1 TO 13:READ DT:COLOR DT:REM GET DATA FOR THE LETTERS
100 FOR LP1=2 TO 17-LP:PLOT LP1,8:REM SLIDE THE LETTERS ONTO THE SCREEN
110 FOR WAIT=1 TO 5:NEXT WAIT:REM A SHORT DELAY LOOP
120 NEXT LP1
130 COLOR 32:FOR LP1=16-LP TO 2 STEP -1:PLOT LP1,8:REM PRINT SPACES
140 FOR WAIT=1 TO 10:NEXT WAIT:REM A SHORT DELAY LOOP
150 NEXT LP1
160 NEXT LP
170 DATA 82,101,196,238,73,114,199,32,238,65,103,210,239
180 POSITION 3,16:? #6;"PRESS ANY KEY";:POSITION 4,17:? #6;"TO CONTINUE";
190 POKE 764,255:REM CLEAR THE KEYBOARD BUFFER. THIS IS USEFUL WHEN YOU WANT TO READ A KEY.
200 IF PEEK(764)<>255 THEN POKE 764,255:GOTO 240:REM A KEY HAS BEEN PRESSED. DOESN'T MATTER WHICH ONE...
210 HOLD=PEEK(708):POKE 708,PEEK(709):POKE 709,PEEK(710):POKE 710,PEEK(711):POKE 711,HOLD
220 REM ABOVE, WE USE THE PEEK/POKE METHOD TO ROTATE THE COLORS IN THE COLOR REGISTERS
230 FOR WAIT=1 TO 10:NEXT WAIT:GOTO 200
240 DIM ANSWER$(10)
250 GRAPHICS 2+16:REM LARGE LETTERS
260 REM GET THE TEMPO
270 POSITION 1,2:? #6;"PRESS {inv}SELECT{/inv}":POSITION 1,3:? #6;"TO SELECT TEMPO"
280 POSITION 1,4:? #6;"PRESS {inv}START{/inv}":POSITION 1,5:? #6;"WHEN YOU ARE"
290 POSITION 1,6:? #6;"READY TO PLAY":TEMPO=1
300 POSITION 1,8:? #6;"tempo ";TEMPO:CONSOLE=53279:REM LOCATION TO READ THE SELECT/START/OPTION BUTTONS
310 IF PEEK(CONSOLE)=5 THEN TEMPO=TEMPO+1:IF TEMPO=6 THEN TEMPO=1:REM THE SELECT BUTTON WAS PRESSED
320 POSITION 7,8:? #6;TEMPO
330 IF PEEK(CONSOLE)=6 THEN 350:REM THE START BUTTON WAS PRESSED
340 FOR WAIT=1 TO 30:NEXT WAIT:GOTO 310
350 GRAPHICS 7:REM HI-RES. 4-COLOR GRAPHICS MODE
360 REM SET-UP THE KEYBOARD ON THE SCREEN.
370 SETCOLOR 4,6,2:REM PURPLE BACKGROUND
380 SETCOLOR 0,5,4:SETCOLOR 1,0,8:SETCOLOR 2,6,2:REM SET THE COLORS YOU WANT
390 COLOR 1:FOR X=20 TO 130 STEP 12:PLOT X,40:DRAWTO X+10,40:DRAWTO X+10,77:DRAWTO X,77
400 DRAWTO X,40:NEXT X:REM DRAW THE OUTLINE OF EACH KEY IN COLOR 1
410 COLOR 2:FOR X=20 TO 130 STEP 12:FOR Y=40 TO 75
420 PLOT X+1,Y+1:DRAWTO X+9,Y+1
430 NEXT Y:NEXT X:REM FILL IN THE KEYS IN COLOR 2
440 REM DRAW THE LETTERS
450 COLOR 2:PLOT 23,35:DRAWTO 23,30:DRAWTO 27,30:DRAWTO 27,35:PLOT 23,32:DRAWTO 27,32:REM THE LETTER "A"
460 PLOT 35,35:DRAWTO 39,35:DRAWTO 39,32:DRAWTO 35,32:DRAWTO 35,30:DRAWTO 39,30:REM THE LETTER "S"
470 PLOT 47,35:DRAWTO 47,30:DRAWTO 50,30:PLOT 51,31:DRAWTO 51,34:PLOT 50,35:DRAWTO 47,35:REM THE LETTER "D"
480 PLOT 59,35:DRAWTO 59,30:DRAWTO 63,30:PLOT 59,33:DRAWTO 62,33:REM THE LETTER "F"
490 PLOT 73,33:DRAWTO 75,33:DRAWTO 75,35:DRAWTO 71,35:DRAWTO 71,30:DRAWTO 75,30:REM THE LETTER "G"
500 PLOT 83,35:DRAWTO 83,30:PLOT 87,30:DRAWTO 87,35:PLOT 83,33:DRAWTO 87,33:REM THE LETTER "H"
510 PLOT 95,33:DRAWTO 95,35:DRAWTO 99,35:DRAWTO 99,30:REM THE LETTER "J"
520 PLOT 107,35:DRAWTO 107,30:PLOT 107,33:DRAWTO 111,30:PLOT 107,33:DRAWTO 111,35:REM THE LETTER "K"
530 PLOT 123,35:DRAWTO 119,35:DRAWTO 119,30:REM THE LETTER "L"
540 PLOT 134,31:PLOT 134,32:PLOT 134,34:PLOT 133,35:REM THE LETTER ";"
550 REM THE ABOVE IS ONE WAY TO PUT LETTERS ON A GRAPHICS SCREEN.
560 POKE 752,1:? " B C D E F G A B C D"
570 REM INITIALIZE OUR SOUND ROUTINES
580 DIM NTES(10):RESTORE 590:FOR X=1 TO 10:READ NTE:NTES(X)=NTE:NEXT X
590 DATA 128,121,108,96,91,81,72,64,60,53
600 KEY=PEEK(764):IF KEY=255 THEN 600
610 IF KEY=28 THEN 690
620 POKE 764,255:NTI=1
630 IF KEY=KEYTABLE(NTI) THEN NT=NTI:GOTO 650
640 NTI=NTI+1:ON ((NTI<11)+1) GOTO 680,630
650 SOUND 0,NTES(NTI),10,10
660 COLOR 1:PLOT 13+NTI*12,60
670 FOR COUNT=1 TO TEMPO*10:NEXT COUNT:SOUND 0,0,0,0:COLOR 2:PLOT 13+NT*12,60
680 GOTO 600
690 SOUND 0,0,0,0:GRAPHICS 0
700 END
Download
The original program from the Antic disk, to LOAD or ENTER instead of typing it: NEWOWN14.BAS.
Credits
- Program listing: Organ Grinder (New Owners Column, Lesson 14) — program listing (Antic, May 1987 (Vol. 6, No. 1), "New Owners Column" Lesson 14) — David Plotkin
- Picture: The organ keyboard, drawn with PLOT and DRAWTO in GRAPHICS 7. — David Plotkin (program); screenshot by the site
- Antic, May 1987 - Vol. 6 No. 1 — article: New Owner's Column #14 by David Plotkin — David Plotkin, 1987
- Antic Software Archive — May 1987 - Vol. 6 No. 1 disk: NEWOWN14.BAS — AtariMagazines.com (Kevin Savetz), 1987
