Prev: 54598 Up: Map Next: 54876
54647: Redefine keyboard controls
Used by the routine at 26745.
54647 CALL 54598 Print current control keys to screen
54650 CALL 54575 If key-press was enqueued then load A with index of last key pressed, otherwise wait for key-press and load A with index
54653 CP 13 If key pressed was 13 (ENTER)...
54655 RET Z ...then return
54656 LD (54576),A Set enqueued key index to index of key pressed
54659 LD B,5 Load B with 5 (as there are five controls)
54661 LD HL,54894 Point HL at start of list of current keyboard control characters
54664 LD (HL),0 Set current keyboard control character to zero
54666 INC HL Advance to next keyboard control character
54667 DJNZ 54664 Decrease B (remaining number of keyboard control characters to clear) and loop back to 54664 if not zero
54669 LD BC,1280 Load B with 5 and C with zero
54672 LD HL,54894 Point HL at start of list of current keyboard control characters
54675 PUSH BC Store BC (B = remaining number of controls to define, C = number of controls defined)
54676 PUSH HL Store HL (current position in list of keyboard control characters)
54677 LD A,C Load number of controls defined (0, 1, 2, 3 or 4) into A
54678 AND 6 Reset all but bits 1 and 2 (to give 0, 2 or 4)
54680 ADD A,6 Add 6 (to give 6, 8 or 10, the y-coordinates in characters of displayed keyboard controls)...
54682 LD B,A ...and load into B
54683 LD A,C Load A with number of controls defined (0, 1, 2, 3 or 4)
54684 AND 1 Reset all but bit 0 (to give 0 or 1)
54686 PUSH AF Store AF (A = bit 0 of number of controls defined)
54687 ADD A,A Double A (to give 0 or 2)...
54688 LD C,A ...and load into C
54689 POP AF Restore AF (A = bit 0 of number of controls defined)
54690 PUSH AF Store AF (A = bit 0 of number of controls defined)
54691 ADD A,C Add C to A (to give 0 or 3)
54692 ADD A,A Multiply A by four...
54693 ADD A,A ...to give 0 or 12...
54694 LD C,A ...and load into C
54695 POP AF Restore AF (A = bit 0 of number of controls defined)
54696 ADD A,C Add value in C to A (to give 0 or 13)
54697 ADD A,5 Add 5 (to give 5 or 18, the x-coordinates in characters of displayed keyboard controls)...
54699 LD C,A ...and load into C
54700 PUSH BC Store BC (coordinates in characters of current control being defined)
54701 CALL 54148 Load HL with attribute file address for coordinates (C, B)...
54704 LD A,(HL) ...and set the FLASH flag for this address...
54705 OR 128 ...
54707 LD (HL),A ...
54708 POP BC Restore BC (coordinates in characters of current control being defined)
54709 PUSH BC Store BC (coordinates in characters of current control being defined)
54710 CALL 54132 Move virtual cursor (bitmap) to display file address for coordinates x=C, y=B and load address into HL
54713 CALL 54575 If key-press was enqueued then load A with index of last key pressed, otherwise wait for key-press and load A with index
54716 CP 32 If key pressed was SPACE...
54718 JP Z,54744 ...then skip ahead to 54744
54721 CP 48 If index of key pressed is less than 48 (i.e. below "0")...
54723 JP M,54708 ...then jump back to 54708 (i.e. wait for next key press and try again)
54726 CP 91 If index of key pressed is 91 or higher (i.e. above "Z")...
54728 JP P,54708 ...then jump back to 54708 (i.e. wait for next key press and try again)
54731 CP 58 If index of key pressed is less than 58 (i.e. "9" or below)...
54733 JP M,54744 ...then skip ahead to 54744
54736 CP 65 If index of key pressed is 65 or higher (i.e. "A" or above)...
54738 JP P,54744 ...then skip ahead to 54744
54741 JP 54708 Jump back to 54708 (i.e. wait for next key press and try again)
54744 CALL 54876 Set zero flag if key pressed is already assigned to a control, otherwise reset
54747 JP Z,54708 If key pressed is already assigned then jump back to 54708 (i.e. wait for next key press and try again)
54750 LD (23398),A Store pressed key index at 23398
54753 CP 32 If key was not SPACE...
54755 JR NZ,54759 ...then skip ahead to 54759
54757 LD A,127 Load A with 127 (index in character set of "SP" UDG at 65516)
54759 CALL 54097 Print text character in A and advance bitmap virtual text cursor
54762 POP BC Restore BC (coordinates in characters of current control being defined)
54763 CALL 54148 Load HL with attribute file address for coordinates (C, B)...
54766 LD A,(HL) ...and reset the FLASH flag for this address...
54767 AND 127 ...
54769 LD (HL),A ...
54770 POP HL Restore HL (current position in list of keyboard control characters)
54771 LD A,(23398) Load A with index of previously defined key...
54774 LD (HL),A ...and store in list of keyboard control characters
54775 INC HL Advance HL to next entry in list of keyboard control characters
54776 POP BC Restore BC (B = remaining number of controls to define, C = number of controls defined)
54777 INC C Increase C (number of controls defined)
54778 DJNZ 54675 Decrease B (remaining number of controls to define) and loop back to 54675 if not zero
54780 LD B,5 Load B with 5 (as each keyboard half-row holds five keys)
54782 LD HL,54953 Store address of operand of instruction at 54953 (MSB of "input address" for keyboard half-row reading for LEFT)...
54785 LD (23398),HL ...at 23398
54788 LD HL,54894 Point HL at start of list of current keyboard control characters
54791 PUSH BC Store BC (B = remaining number of control keys to check)
54792 PUSH HL Store HL (pointer to current position in list of current keyboard control characters)
54793 LD IX,54902 Point IX at lists of characters on each keyboard half-row
54797 LD A,(HL) Load A with current keyboard control character index
54798 LD C,0 Set C (index in list of half-rows) to zero
54800 CP (IX+0) If current keyboard control character index is the same as the current character in keyboard half-row groups...
54803 JR Z,54810 ...then skip ahead to 54810
54805 INC C Increase C (index in list of half-rows)
54806 INC IX Advance to next entry in list of half-rows
54808 JR 54800 Loop back to 54800
54810 LD A,C Load A with index of current control key in list of half-rows
At this point we know the index of the current key in the list of half-rows. We now need to identify which half row it belongs to.
54811 LD B,0 Set B (keyboard half-row index) to zero
54813 SUB 5 If index of key in current half-row is less than 5 (i.e. key is in the current half-row)...
54815 JP M,54821 ...then skip ahead to 54821
54818 INC B Increase B (keyboard half-row index)
54819 JR 54813 Loop back to 54813
The MSB in the "input address" for the various keyboard half-rows obeys the progression (254, 253, 251, 247, 239, 223, 191, 127).
54821 LD A,B Load A with index of keyboard half-row containing current key
54822 PUSH BC Store BC (B = index of keyboard half-row, C = index of key in list of half-rows)
54823 INC B Increase B
54824 LD HL,128 Load HL with 128
54827 ADD HL,HL Double value in HL
54828 DJNZ 54827 Decrease B (index of keyboard half-row) and loop back to 54827 if not zero
HL now contains the value (128 × 2n) where n is the (1-based) index of the relevant half-row. H contains (2m, where m is the (zero-based) index of the relevant half-row.
54830 LD A,255 Load A with 255
54832 SUB H Subtract H (2m) to give MSB of input address for relevant half-row
54833 LD HL,(23398) Load HL with address of operand of instruction to modify (54953)...
54836 LD (HL),A ...and set operand to value in A
Next we need to modify the second part of the opcode for the instruction that checks the set bit in A to determine which key in the half-row was pressed. The range of opcode values are:
Opcode Value Instruction
71 BIT 0,A
79 BIT 1,A
87 BIT 2,A
95 BIT 3,A
103 BIT 4,A
54837 INC HL Advance HL by four bytes to operand of instruction at 54956...
54838 INC HL ...
54839 INC HL ...
54840 INC HL ...
54841 LD (23398),HL ...and store at 23398
54844 POP BC Restore BC (B = index of keyboard half-row, C = index of key in list of half-rows)
54845 LD A,B Load B with five times index of keyboard half-row (value currently in B)...
54846 ADD A,A ...
54847 ADD A,A ...
54848 ADD A,B ...
54849 LD B,A ... (B is now 0, 5, 10, 15, 20, 25, 30 or 35)
54850 LD A,C Load A with index of key in list of half-rows...
54851 SUB B ...and subtract B (5 times index of half-row) to give index of key within current half-row
54852 ADD A,A Multiply this index by 8 (opcode interval between successive BIT n,A and BIT n+1,A instructions)...
54853 ADD A,A ...
54854 ADD A,A ...
54855 ADD A,71 ...and add 71 (opcode for BIT 0,A)
54857 LD HL,(23398) Load HL with address of operand / opcode for BIT n,A instruction...
54860 LD (HL),A ...and set "n" accordingly
54861 LD BC,5 Advance HL by five bytes to operand of next LD B,x instruction (i.e. MSB of "input address" for next control)...
54864 ADD HL,BC ...
54865 LD (23398),HL ...and store at 23398
54868 POP HL Restore HL (pointer to current position in list of current keyboard control characters, PUSHed at 54792)
54869 INC HL Advance HL to next keyboard control character
54870 POP BC Store BC (B = remaining number of control keys to check, PUSHed at 54791)
54871 DJNZ 54791 Decrease B (remaining number of control keys to check) and loop back to 54791 for next control key if not zero
54873 JP 55138 Display "PRESS FIRE TO CONTINUE" window and wait for fire to be pressed and return
Prev: 54598 Up: Map Next: 54876