Prev: 00654 Up: Map Next: 00798
00703: THE 'KEYBOARD' SUBROUTINE
Used by the routine at MASK_INT.
This subroutine is called on every occasion that a maskable interrupt occurs. In normal operation this will happen once every 20 ms. The purpose of this subroutine is to scan the keyboard and decode the key value. The code produced will, if the 'repeat' status allows it, be passed to the system variable LAST-K. When a code is put into this system variable bit 5 of FLAGS is set to show that a 'new' key has been pressed.
KEYBOARD 00703 CALL KEY_SCAN Fetch a key value in the DE register pair but return immediately if the zero flag is reset.
00706 RET NZ
A double system of 'KSTATE system variables' (KSTATE0-KSTATE3 and KSTATE4-KSTATE7) is used from now on.
The two sets allow for the detection of a new key being pressed (using one set) whilst still within the 'repeat period' of the previous key to have been pressed (details in the other set).
A set will only become free to handle a new key if the key is held down for about 1/10th. of a second, i.e. five calls to KEYBOARD.
00707 LD HL,23552 Start with KSTATE0.
K_ST_LOOP 00710 BIT 7,(HL) Jump forward if a 'set is free', i.e. KSTATE0/4 holds 255.
00712 JR NZ,K_CH_SET
00714 INC HL However if the set is not free decrease its '5 call counter' and when it reaches zero signal the set as free.
00715 DEC (HL)
00716 DEC HL
00717 JR NZ,K_CH_SET
00719 LD (HL),255
After considering the first set change the pointer and consider the second set.
K_CH_SET 00721 LD A,L Fetch the low byte of the address and jump back if the second set (KSTATE4) has still to be considered.
00722 LD HL,23556
00725 CP L
00726 JR NZ,K_ST_LOOP
Return now if the key value indicates 'no-key' or a shift key only.
00728 CALL K_TEST Make the necessary tests and return if needed. Also change the key value to a 'main code'.
00731 RET NC
A key stroke that is being repeated (held down) is now separated from a new key stroke.
00732 LD HL,23552 Look first at KSTATE0.
00735 CP (HL) Jump forward if the codes match - indicating a repeat.
00736 JR Z,K_REPEAT
00738 EX DE,HL Save the address of KSTATE0.
00739 LD HL,23556 Now look at KSTATE4.
00742 CP (HL) Jump forward if the codes match - indicating a repeat.
00743 JR Z,K_REPEAT
But a new key will not be accepted unless one of the sets of KSTATE system variables is 'free'.
00745 BIT 7,(HL) Consider the second set.
00747 JR NZ,K_NEW Jump forward if 'free'.
00749 EX DE,HL Now consider the first set.
00750 BIT 7,(HL) Continue if the set is 'free' but exit if not.
00752 RET Z
The new key is to be accepted. But before the system variable LAST-K can be filled, the KSTATE system variables, of the set being used, have to be initialised to handle any repeats and the key's code has to be decoded.
K_NEW 00753 LD E,A The code is passed to the E register and to KSTATE0/4.
00754 LD (HL),A
00755 INC HL The '5 call counter' for this set is reset to '5'.
00756 LD (HL),5
00758 INC HL The third system variable of the set holds the REPDEL value (normally 0.7 secs.).
00759 LD A,(23561)
00762 LD (HL),A
00763 INC HL Point to KSTATE3/7.
The decoding of a 'main code' depends upon the present state of MODE, bit 3 of FLAGS and the 'shift byte'.
00764 LD C,(IY+7) Fetch MODE.
00767 LD D,(IY+1) Fetch FLAGS.
00770 PUSH HL Save the pointer whilst the 'main code' is decoded.
00771 CALL K_DECODE
00774 POP HL
00775 LD (HL),A The final code value is saved in KSTATE3/7, from where it is collected in case of a repeat.
The next three instructions are common to the handling of both 'new keys' and 'repeat keys'.
K_END 00776 LD (23560),A Enter the final code value into LAST-K and signal 'a new key' by setting bit 5 of FLAGS.
00779 SET 5,(IY+1)
00783 RET Finally return.
A key will 'repeat' on the first occasion after the delay period (REPDEL - normally 0.7s) and on subsequent occasions after the delay period (REPPER - normally 0.1s).
K_REPEAT 00784 INC HL Point to the '5 call counter' of the set being used and reset it to 5.
00785 LD (HL),5
00787 INC HL Point to the third system variable - the REPDEL/REPPER value - and decrement it.
00788 DEC (HL)
00789 RET NZ Exit from the KEYBOARD subroutine if the delay period has not passed.
00790 LD A,(23562) However once it has passed the delay period for the next repeat is to be REPPER.
00793 LD (HL),A
00794 INC HL The repeat has been accepted so the final code value is fetched from KSTATE3/7 and passed to K_END.
00795 LD A,(HL)
00796 JR K_END
Prev: 00654 Up: Map Next: 00798