Prev: 8B81 Up: Map Next: 8BFB
8B93: Get Key
Used by the routine at Input_WaitForAKey.
Reads a newly pressed key. Returns 00 if there isn't one.
GetKey 8B93 PUSH HL Save HL, IX and BC and call Pause to pause.
8B94 PUSH IX
8B96 PUSH BC
8B97 CALL Pause
8B9A LD ($8B89),BC Write 0000 to 8B89.
8B9E LD HL,$8B8B Point HL at 8B8B.
8BA1 LD IX,$8B81 Point IX at KeyboardRowMasks.
8BA5 LD BC,$FEFE Read the keyboard from port FEFE.
GetKey_Loop 8BA8 IN A,(C) Read from the keyboard port.
8BAA AND %00011111 Keep the selected bits.
8BAC OR (IX+$00) OR against what IX is pointing to.
8BAF PUSH AF Save the row and complement it.
8BB0 CPL
8BB1 AND (HL) Keep the keys that are pressed now but were up in the previous scan at HL. The second CPL leaves the flags alone.
8BB2 CPL
8BB3 JR Z,GetKey_StoreTheRow Jump to GetKey_StoreTheRow if no key in this half-row has been newly pressed.
8BB5 LD ($8B89),BC Store BC at 8B89.
8BB9 LD ($8B89),A Store the result at 8B89.
GetKey_StoreTheRow 8BBC POP AF Store the result, then step HL on.
8BBD LD (HL),A
8BBE INC HL
8BBF INC IX Step IX to the next byte of KeyboardRowMasks.
8BC1 RLC B Rotate the next bit of B into carry.
8BC3 JR C,GetKey_Loop Jump back to GetKey_Loop until all eight half-rows have been read.
8BC5 LD BC,($8B89) Bring BC back from 8B89.
No newly pressed key was stored.
8BC9 LD A,B If BC is 0000, return 00 through GetKey_Return.
8BCA OR C
8BCB JR Z,GetKey_Return
8BCD LD A,$FB Start the key index at FB (that is -5).
GetKey_CountTheRows 8BCF ADD A,$05 Add 05 for each keyboard row passed.
8BD1 RRC B Shift the next row bit of B into the carry flag.
8BD3 JR C,GetKey_CountTheRows If there is any carry, jump to GetKey_CountTheRows.
8BD5 DEC A Step back one so the next loop starts in the same place.
GetKey_CountTheKeys 8BD6 INC A Count one more key along the row.
8BD7 RRC C Shift the next key bit of C into the carry flag.
8BD9 JR C,GetKey_CountTheKeys If there is any carry, jump to GetKey_CountTheKeys.
8BDB LD C,A Copy the key code into C.
8BDC LD B,$00 Start the character count at zero.
8BDE LD HL,$8BFB Point HL at the unshifted keyboard map at KeyboardMapUnshifted.
8BE1 LD A,$FE Read from the keyboard port.
Port Number Bit
0 1 2 3 4
FE SHIFT Z X C V
8BE3 IN A,($FE)
8BE5 AND %00000001 Keep only bit 0 (SHIFT).
8BE7 JR Z,GetKey_UseTheShiftedMap If it is zero, jump to GetKey_UseTheShiftedMap.
8BE9 LD A,$7F Read from the keyboard port.
Port Number Bit
0 1 2 3 4
7F SPACE SYMBOL SHIFT M N B
8BEB IN A,($FE)
8BED AND %00000010 Keep only bit 1 (SYMBOL SHIFT).
8BEF JR NZ,GetKey_GetByte If it is not zero, jump to GetKey_GetByte.
GetKey_UseTheShiftedMap 8BF1 LD HL,$8C23 Point HL at the shifted keyboard map at KeyboardMapShifted.
GetKey_GetByte 8BF4 ADD HL,BC Add the key code in BC to the keyboard map pointer.
8BF5 LD A,(HL) Read the character for this key from the keyboard map.
GetKey_Return 8BF6 POP BC Restore BC, IX and HL from the stack.
8BF7 POP IX
8BF9 POP HL
8BFA RET Return.
Prev: 8B81 Up: Map Next: 8BFB