System Variable KSTATE


Notes AddressName Contents

N8 23552 KSTATE Used in reading the keyboard.

23552 5C00 (IY-$3A) KSTATE-0
23553 5C01 (IY-$39) KSTATE-1
23554 5C02 (IY-$38) KSTATE-2
23555 5C03 (IY-$37) KSTATE-3
23556 5C04 (IY-$36) KSTATE-4
23557 5C05 (IY-$35) KSTATE-5
23558 5C06 (IY-$34) KSTATE-6
23559 5C07 (IY-$33) KSTATE-7

Notes: There are two 4-byte keyboard maps at the start of the System Variables Area. These are identical in layout and marked as free for use by having the first location hold 255 as is done during initialisation.

The interrupt routine, when it detects a valid key press, or no key, considers both maps and if it finds that a key is not free, then the second location is decremented and if the result has reached zero from it's initial value of five, the set is marked free.

So, if the keyboard is not touched for a tenth of a second, both sets will be free.

If no key was pressed then no further action is taken.

Otherwise the two sets are examined the second one always before the first.
If it finds that the first location holds 255 then the raw key value, uppercase letter, is placed in the first location.
The second location is then set to hold 5 and acts as an interrupt counter mentioned above.
It will take five interrupts before this location can be considered when a different key is pressed.
The third location is set to the system variable REPDEL, default value 35, and this is the delay in interrupts before the same key will repeat.
After the first repeat, this third location is loaded from system variable REPPER, default value 5, for the delay for all subsequent repeats.

After initialising the delay value, the raw key is then decoded and the value placed in the fourth location and also in the system variable LAST K.

A new key has been accepted in one interrupt.

This works fine especially if you want to print, for example, a row of asterisks.

10 REM ***********************

as the system finds that the 'B' key is being held down and after waiting for the number of interrupts held in the third location, the repeated key can be picked up from the fourth location. Once started you don't even have to keep your finger on [Symbol Shift] just 'B'.

However when the first keypress was decoded as a keyword, the repeat key can never be a keyword, so 'NEXT n' may give 'NEXT NEXT'. Spectrum users soon become used to this and it is not regarded as a problem. It is usually encountered when they have held the key down for too long and NEXT NEXT is just as easy to delete as NEXT n.

Back   Homepage