198
The zeropage address 198 ($C6, official name NDX) is used by the Kernal system to hold the number of keyboard entries waiting in the ten-character keyboard buffer (see address 631-640).
Examples[edit | edit source]
Here are examples that demonstrates the keyboard buffer and the contents of 198.
1000 POKE 198,0: WAIT 198,1: GET K$
This line will clear prior key presses, then wait for a key to be pressed before reading it. Useful to stop buffered keystrokes triggering an unexpected prompt.
FOR N=0 TO 1000: PRINT CHR$(19);PEEK(198): NEXT N
Note: chr$(19) is the control character for "home"; it ensures the reported count is always printed at the upper left-hand corner of the screen.
This loop will go on for about eight seconds, whilst reporting the number of characters waiting in the keyboard buffer in the corner of the screen. As it runs, try typing something on the keyboard, and notice how the number of chars rises by one for each keystroke, and when the loop comes to an end, whatever you type is "spat out" right underneath the "ready." prompt.
If you type a lot, you'll see that this "counter" won't go beyond 10, which is the default maximum of chars (see address 649): Try the loop again, this time typing the alphabet to beyond the letter J (tenth in the row) – at the end of the loop, only the first ten entries (A thru J) are "released" from the keyboard buffer.
Here is another example, demonstrating a useful application of writing to address 198: Putting a zero byte in this address "fools" the system to think that no entries were made at all.
FOR N=0 TO 1000: NEXT: POKE 198,0
This loop takes a tad over a second to complete: If you make a few keystrokes in that second, your entries will not appear underneath the "ready." prompt, because the POKE at the end of the command line "cancels" your entries.
This is useful in situations where the computer "thinks" long and hard (several seconds where, from the user's perspective, apparently "nothing" happens), and then asks the user an important question. If the surprised user tried to type something during the apparent "pause", these entries may inadvertantly be accepted as the answer to the question. To avoid this as a programmer, one should put a zero byte in address 198 inbetween displaying the question on screen, and awaiting answers in the form of keyboard entries acquired through the standard buffer system.