2068 Keyboard Notes

See all articles from Sinc-Link v3 n3
Author(s): Cameron Hayne
Publication: Sinc-Link
Pub Details: Sinc-Link v3 n3 (Volume 3, Issue 3)
Date: May/June 1985
Pages: 7

Testing For Keys Pressed:

The BASIC function INKEY$ returns a string with the value of the key pressed, if the “5” key is being pressed then INKEY$=”5″. If no key is being pressed INKEY$=”” (the empty string). Thus INKEY$ can be used to test for keyboard input. There are limitations to this use, if the lower case “e” is being pushed then INKEY$=”e” but if the upper case “E” is being pressed then INKEY$=”E”, so these two cases will have to be tested for separately. (The 2068 does distinguish between strings “e” and “E” but not between variables e and E.) Also, if ENTER is being pressed, or if more than one key (aside from a shift key) is being pressed, then INKEY$ will return an empty string as if no keys were being pressed

An alternative method is to use the BASIC function IN. For example, IN 63486 would return a value of 15 if the “5” ey were being pressed. So we can use IN to test for a certain key being pressed just as we might use INKEY$, eg. IF IN 63486=15 THEN ….. The use of IN overcomes the limitations mentioned above on the use of INKEY$. If the key with the letter “E” on it is being pressed then IN 64510 will equal 27 whether it is upper or lower case. If both the “5” and “4” keys are pressed togeather then IN 63486 will equal 7. In all the abve examples the value returned would be 31 if no keys in the same half row were being pressed.

How do you know what number to use with IN and what number it will result in? Well, you can just look in the table below. I found out by experimenting. (Now that I have a copy of The Intermediate/Advanced Guide, I find that the information is on page 101.)

Try INPUTing values of x between zero and 255 with the following:

10 INPUT x
20 PRINT AT 0,0; IN(254+x*256)
30 GOTO 20

BREAK in and RUN to try a new value

You will find that if x=0 all the half rows are activated so that they respond to a keypress. Non-zero values for x de-activate half rows according to the binary form of x. The table below shows the values of x to use so that only the single half row indicated is activated. Also shown is the number to be subtracted from 31 to find the value given by the IN function when that key is pressed. Foe example, IN 49150 will equal 31-1=30 when ENTER is pressed. 31-2=29 when “L” is pressed, 31-1-2=28 when both ENTER and “L” are pressed, etc. If no key in that half row is pressed then IN 49150=31.

A technical note: It is only the first five bits of the value returned by the IN function that are relevant to the keyboard. In the 2068 it seems that the other three bits are always zero, except during tape loading, hence the 31. However, on the Spectrum these oter bits are not necessarily zero – so beware!!!

The same method can be used in machine code to provide a means of reading the keyboard which is often faster and simpler than using the ROM routine K-SCAN. (Which Stan Piotrowski explained in newsletter Vol 2, #6) Use the instructions:

LD A, x
IN A, (254)
CP test

where x is the value appropriate to the half row the key is in, and test is the value obtained by subtracting the key value from 31. The zero flag will be set (ie. Z=1) if the key is being pressed, otherwise it will be reset.

Keyboard half rows with x values and key values
Keyboard half rows with x values and key values
  x       254 + x * 256          x
 ---     ---------------        ---
 247      63486 | 61438         239
 251      64510 | 57342         223
 253      65022 | 49150         191
 254      65278 | 32766         127

        KEYBOARD VALUE TABLE