Commodore 128 Programmer's Reference Manual page 103

Hide thumbs Also See for 128:
Table of Contents

Advertisement

n
ONE STEP BEYOND SIMPLE BASIC
93
n
j |
BUFFER ROUTINE
jj
The C128 keyboard buffer can hold and dispense up to ten characters from the
• )
keyboard. This is useful in a word processing program where it is possible at certain
moments to type faster than the software can actually process. The characters that
p
haven't been displayed yet are temporarily stored in the keyboard buffer. The computer
/
can hold the next instruction in the buffer for use when the program is ready. This buffer
allows a maximum of ten characters in queue. To see the buffer in action, enter the
^
command SLEEP 5 and immediately press ten different letter keys. After five seconds,
I J
all ten characters are displayed on the screen.
( l
Here is a buffer routine that allows you to put items in the keyboard buffer
from within a program so they are dispensed automatically as the computer is able to act
fl
upon them.
! !
In line 10, memory location 208 (198 in C64 mode) is filled with a number
between 0 and 10—the number of keyboard characters in the keyboard buffer. In line
p
20, memory locations 842 through 851 (631-640 in C64 mode) are filled with any ten
i j
characters you want placed there. In this example, seven characters are in the buffer,
each a carriage RETURN character. CHR$(13) is the character string code for the
carriage return character.
j
Line 40 places the text 4<?CHR$(156)" on the screen, but does not execute the
'
instruction. Line 50 displays the word "LIST" on the screen. Neither command is
executed until the program ends. In the C128, the keyboard buffer automatically empties
p
when a program ends. In this case, the characters in the buffer (carriage return) are
I j
emptied and act as though you are pressing the RETURN key manually. When this occurs
on a line where the commands from lines 40 and 50 are displayed, they are executed
as though you typed them in direct mode and pressed the RETURN key yourself. When
this program ends, the character color is changed to purple and the program is LISTED
to the screen. This technique is handy in restarting programs (with RUN or GOTO).
The next section gives a practical example of using the buffer routine.
10
POKE 208,7:REM SPECIFY # OF CHARS
IN BUFFER
20
FOR 1=842 TO 849:POKE I,13:NEXT:REM PLACE CHARS IN BUFFER
30
SLEEP
2
:REM DELAY
40
SCNCLR: PRINT: PRINT: PRINT: PRINT: PRINT: PRINT .-PRINT"? CHR$(156)"
50 PRINT:PRINT:PRINT:PRINT"LIST":REM PLACE LIST ON SCREEN
60
PRINT CHR$(19):PRINT:PRINT:REM GO HOME AND CURSOR DOWN TWICE
70 REM WHEN PROGRAM ENDS,
BUFFER EMPTIES AND EXECUTES
7 RETURNS.
80 REM THIS CHANGES CHAR COLOR TO PURPLE AND LISTS THE PROGRAM AUTOMATICALLY
90 REM AS
IF YOU PRESSED THE RETURN KEY MANUALLY
Program 3-2. Buffer Return
LOADING ROUTINE
The buffer can be used in automatic loader routines. Many programs often involve the
loading of several machine code routines as well as a BASIC program. The results of
the following loader are similar to many found on commercial software packages.

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents