Classic Computer Magazine Archive COMPUTE! ISSUE 46 / MARCH 1984 / PAGE 165

Big Buffer For Atari

Jeff Brenner

Add a keyboard buffer to your Atari so you can type in characters while a program is running or listing, and even during a SAVE. See the "Automatic Proofreader" article on page 60 before typing these programs.

This article will show you how to add an extremely powerful feature to your Atari computer—a keyboard buffer. A keyboard buffer is a reserved area of computer memory used to temporarily store keypresses while the keyboard is inactive. When the keyboard is ready for input, any stored keypresses will be printed out onto the screen.

Look at this simple program:

10 GOTO 10

When you run this program, the computer will be put into an infinite loop. If you type in characters while this program is running, the computer will ignore your input.

With a keyboard buffer, you still see nothing when you run the program and type characters. But as soon as you stop the program by pressing the BREAK key, all of the characters that you typed in previously will be printed out.

Most higher-priced computers, such as the IBM Personal Computer, have intricate keyboard buffers controlled by a separate microprocessor. Some lower-priced computers, such as the Commodore 64 and VIC-20, have simple ten-character buffers built into the operating system.

A 100-Character Buffer

Atari computers do not have a buffer, but "Keyboard Buffer" will give your Atari a 100-character buffer.

Here's how Keyboard Buffer works. Each time a key is pressed, the program will check whether the computer is busy or not. If the computer is not prepared for an input, the number representing that keypress will be stored in the buffer (on Page 6, so it won't interfere with BASIC). As soon as the computer is ready to accept input, the characters stored in the buffer will be displayed.

Program 1 is a BASIC program which loads a machine language program into memory. The program is designed to be a subroutine for any BASIC program requiring keyboard input. After you enter this program, LIST it to tape or disk so you can ENTER it later and merge it with your program.

If you press SYSTEM RESET while using the buffer program, it will be necessary to restart the program by typing:

A = USR(1536)

Program 1: Keyboard Buffer

OC 30000 REM KEYBOARD BUFFER
BD 30010 DATA 104, 173, 8, 2, 141, 96, 6, 173,
         9, 2, 141, 97, 6, 169, 0, 141, 14, 21
         2, 120, 169, 52, 141, 8, 2
ON 30020 DATA 169, 6, 141, 9, 2, 169, 98, 141,
         36, 2, 169, 6, 141, 37, 2, 169, 192,
         141, 14, 212, 169, 0, 133, 204
JN 30030 DATA 133, 205, 88, 96, 173, 9, 210,
         201, 159, 240, 36, 152.72, 173, 252,
         2, 201, 255, 240, 19, 164, 204, 192,
         100
MN 30040 DATA 240, 9, 230, 204, 200, 173, 9,
         210, 153, 14 3, 6, 104, 168, 104, 64,
         165, 204, 197, 205.208, 231, 104, 1
         68, 76
NB 30050 DATA 95, 6, 173, 252, 2, 201, 255, 2
         08, 35, 165, 204, 197, 205, 240, 23,
         230, 205, 164, 204, 192, 120, 176, 1
         5, 164
GE 30060 DATA 205, 192, 120, 176, 9, 185, 14
         3, 6, 141, 252, 2, 76, 98, 228, 169, 0,
         133, 204, 133, 205, 76, 98, 228
LL 30070 T = 0
GM 30080 IF PEEK (521) = 6 THEN GOTO 3015
         0
NF 30090 FOR I = 1 TO 143
PG 30100 READ N:T = T + N
OA 30110 POKE 1535 + I, N
HO 30120 NEXT I
FJ 30130 IF T <>18309 THEN PRINT "CHECK
          DATA STATEMENTS":STOP JA 30140 A = USR(1536)
NJ 30150 RETURN

After you type in Program 1, LIST it to cassette or disk. If you wish to test your work, do not type NEW. Add the lines from Program 2 and RUN.

Program 2: Buffer Test

JA 10 REM KEYBOARD BUFFER TEST
NF 20 GOSUB 30000
DG 30 DIM NAME$ (30)
OP 40 PRINT "WHAT IS YOUR NAME?";
DL 50 FOR I = 1 TO 500
AP 60 A = RND(0) * 255
HP 70 SOUND 1, A, 10, 8
PA 80 NEXT I
DO 90 INPUT NAME $
00 100 PRINT "YOUR NAME IS "; NAME$
GJ 110 END

A Test With Background Music

If you get an error or a CHECK DATA STATEMENTS message, you have made an error in typing Program 1. Check all the DATA statements carefully.

When everything is correct, the computer will print WHAT IS YOUR NAME? and start playing tones. Even though the music is busy playing, type in your name and press RETURN. After the music is over, your name will be printed out and entered automatically.

This is only one example of an application for Keyboard Buffer. If you would like to use Keyboard Buffer while doing your own programming in BASIC, change line 30150 to:

30150 END

Then RUN the program. When the READY prompt appears, type NEW. Keyboard Buffer will be operational and you can begin programming.

A keyboard buffer can surely improve the quality of any program requiring user input. Since you can enter characters even while the computer is in a lengthy loop, you save time. After using Keyboard Buffer, you will begin to see the advantage of having a constantly monitored keyboard.