Adding BASIC Function Keys

16K Cassette or Disk

by Stephen Prokopchuk

One day while typing out a long program, I realized how often one types the same BASIC key words over and over again. If these words could be printed out by pressing a single key, I reasoned, much time could be saved.

The resulting program will define CTRL 4-0 and SHIFT+CTRL 4-0 as Function Keys. It does so via the seldom-used POKEY keyboard interrupt vector VKEYBD at memory location 520-521 ($208-$209 hex). Whenever a key is pressed, the computer stops whatever it is doing and jumps to the keyboard scan routine normally located at 65470 ($FFBE hex). This interrupt has been moved to our program, Function Keys, which checks to see if any of these keys has been pressed.

How to use it.

Two programs are presented here, one in BASIC and one in assembly language. The assembly language program is for more advanced users and does not have to be typed into the computer.

After running the BASIC program for Function Keys, your computer will give brief instructions and show the default setting (see Table 1) for function key #1 (LOAD), asking for your setting. If you wish this key to have the default assignment, simply push RETURN.

If you wish to assign your own phrase to that key, type the phrase and then press RETURN. Keep in mind that the length of the phrase must not exceed seven letters. The computer will prompt you in this fashion for all of the keys capable of function assignments.

Table 1.

Command  Function
CTRL-4 ... LOAD "
CTRL-5 ... SAVE "
CTRL-6 ... LIST
CTRL-7 ... RUN
CTRL-8 ... POKE
CTRL-9 ... PEEK(
CTRL-0 ... DATA
SHIFT+CTRL-4 ... PLOT
SHIFT+CTRL-5 ... DR. (DRAWTO)
SHIFT+CTRL-6 ... LOC. (LOCATE)
SHIFT+CTRL-7 ... POS. (POSITION)
SHIFT+CTRL-8 ... COLOR(
SHIFT+CTRL-9 ... SE. (SETCOLOR)
SHIFT+CTRL-0 ... GR. (GRAPHICS)

When BASIC displays READY, your Function Keys are all defined. Try pressing CTRL-4 to CTRL-0 or SHIFT-CTRL-4 to 0 and see the words you have defined appear on the screen.

Keep in mind that pressing SYSTEM RESET will disable the Function Keys. To re-enable them, type: PRINT USR(1536)

Also, press RESET before re-running the BASIC program, otherwise Function Keys will print FUNCTION ALREADY IMPLEMENTED.

Go to it!

This program is only a small example of what could be done using the keyboard interrupt. The keypad could be reconfigured in hundreds of ways, including moving the cursor control keys, or even setting it up in a Dvorak layout. Have fun-experiment!

BASIC Listing

CHECKSUM DATA

Assembly language listing