Prev: 43791 Up: Map Next: 44096
43919: Read Controls
Used by the routine at ControlPlayer.
Reads the controls of the current player, using the control method which is selected in Player1ControlMethod (0 for the keyboard, 1 for a Kempston joystick, 2 for a Cursor joystick, otherwise an Interface II joystick). The result has one bit for each control: bit 0 is right, bit 1 is left, bit 2 is down, bit 3 is up and bit 4 is fire.
Output
C The controls which are being used
ReadControls 43919 LD A,(24827) Fetch the control method of the current player.
43922 AND A Test it.
43923 JP Z,ReadControls_Keyboard Jump to ReadControls_Keyboard if it is the keyboard.
43926 DEC A Decrease it by one.
43927 JR Z,ReadControls_Kempston Jump to ReadControls_Kempston if it is a Kempston joystick.
43929 DEC A Decrease it by one.
43930 JR Z,ReadControls_Cursor Jump to ReadControls_Cursor if it is a Cursor joystick.
43932 LD A,239 Read from the keyboard;
Port Number Bit
0 1 2 3 4
239 0 9 8 7 6
43934 IN A,(254)
43936 LD B,255 Start with all of the bits set.
43938 RRA Move the bit for "0" into the carry flag.
43939 RL B Move it into B.
43941 RRA Move the bit for "9" into the carry flag.
43942 RL B Move it into B.
43944 RRA Move the bit for "8" into the carry flag.
43945 RL B Move it into B.
43947 RRA Move the bit for "7" into the carry flag...
43948 RRA ...and then the bit for "6".
43949 RL B Move it into B.
43951 RLA Rotate the bit for "7" back into the carry flag...
43952 RL B ...and move it into B.
43954 LD A,B Fetch the result.
43955 CPL Invert the bits, so that a set bit is a control being used.
43956 LD C,A Store it in C.
43957 RET Return.
ReadControls_Kempston 43958 IN A,(31) Read the Kempston joystick.
43960 AND %00011111 Keep the five bits.
43962 LD C,A Store them in C.
43963 RET Return.
ReadControls_Cursor 43964 LD A,239 Read from the keyboard;
Port Number Bit
0 1 2 3 4
239 0 9 8 7 6
43966 IN A,(254)
43968 OR %11100000 Set the unused bits.
43970 LD B,A Keep the bits in B.
43971 AND %00001000 Keep the bit for "7", up.
43973 LD C,A Store it in C.
43974 LD A,B Fetch the bits.
43975 RRCA Rotate bit 2, for "8" (right), into bit 0...
43976 RRCA ...and bit 4, for "6" (down), into bit 2.
43977 LD B,A Keep the bits in B.
43978 AND %00000101 Keep the bits for right and down.
43980 OR C Add the bit for up.
43981 LD C,A Store them in C.
43982 LD A,B Fetch the bits.
43983 RRA Rotate the bit for "0" (fire)...
43984 RRA ...into bit 4.
43985 AND %00010000 Keep the bit for fire.
43987 OR C Add the other bits.
43988 LD C,A Store them in C.
43989 LD A,247 Read from the keyboard;
Port Number Bit
0 1 2 3 4
247 1 2 3 4 5
43991 IN A,(254)
43993 RRA Rotate the bit for "5" (left)...
43994 RRA ...into...
43995 RRA ...bit 1.
43996 AND %00000010 Keep the bit for left.
43998 OR C Add the other bits.
43999 CPL Invert the bits, so that a set bit is a control being used.
44000 LD C,A Store them in C.
44001 RET Return.
ReadControls_Keyboard 44002 LD C,0 Clear the controls.
44004 LD A,254 Read from the keyboard;
Port Number Bit
0 1 2 3 4
254 CAPS SHIFT Z X C V
44006 CALL ReadKeyboard
44009 AND %00010100 Keep the bits for "X" and "V".
44011 JR NZ,ReadControls_Right Jump to ReadControls_Right if either of them is being pressed.
44013 LD A,127 Read from the keyboard;
Port Number Bit
0 1 2 3 4
127 SPACE SYMBOL SHIFT M N B
44015 CALL ReadKeyboard
44018 AND %00001010 Keep the bits for "SYMBOL SHIFT" and "N".
44020 JR Z,ReadControls_TestLeft Jump to ReadControls_TestLeft if neither of them is being pressed.
ReadControls_Right 44022 SET 0,C Set bit 0, right.
ReadControls_TestLeft 44024 LD A,254 Read from the keyboard;
Port Number Bit
0 1 2 3 4
254 CAPS SHIFT Z X C V
44026 CALL ReadKeyboard
44029 AND %00001010 Keep the bits for "Z" and "C".
44031 JR NZ,ReadControls_Left Jump to ReadControls_Left if either of them is being pressed.
44033 LD A,127 Read from the keyboard;
Port Number Bit
0 1 2 3 4
127 SPACE SYMBOL SHIFT M N B
44035 CALL ReadKeyboard
44038 AND %00010100 Keep the bits for "M" and "B".
44040 JR Z,ReadControls_TestUp Jump to ReadControls_TestUp if neither of them is being pressed.
ReadControls_Left 44042 SET 1,C Set bit 1, left.
ReadControls_TestUp 44044 LD A,253 Read from the keyboard;
Port Number Bit
0 1 2 3 4
253 A S D F G
44046 CALL ReadKeyboard
44049 JR NZ,ReadControls_Up Jump to ReadControls_Up if any of the keys is being pressed.
44051 LD A,191 Read from the keyboard;
Port Number Bit
0 1 2 3 4
191 ENTER L K J H
44053 CALL ReadKeyboard
44056 JR Z,ReadControls_TestDown Jump to ReadControls_TestDown if none of the keys is being pressed.
ReadControls_Up 44058 SET 3,C Set bit 3, up.
ReadControls_TestDown 44060 LD A,251 Read from the keyboard;
Port Number Bit
0 1 2 3 4
251 Q W E R T
44062 CALL ReadKeyboard
44065 LD E,A Keep the bits in E.
44066 LD A,223 Read from the keyboard;
Port Number Bit
0 1 2 3 4
223 P O I U Y
44068 CALL ReadKeyboard
44071 LD D,A Keep the bits in D.
44072 LD A,E Fetch the bits for "Q", "W", "E", "R" and "T".
44073 AND %00010101 Keep the bits for "Q", "E" and "T".
44075 LD L,A Store them in L.
44076 LD A,D Fetch the bits for "P", "O", "I", "U" and "Y".
44077 AND %00001010 Keep the bits for "O" and "U".
44079 OR L Combine them with the bits for "Q", "E" and "T".
44080 JR Z,ReadControls_TestFire Jump to ReadControls_TestFire if none of them is being pressed.
44082 SET 2,C Set bit 2, down.
ReadControls_TestFire 44084 LD A,E Fetch the bits for "Q", "W", "E", "R" and "T".
44085 AND %00001010 Keep the bits for "W" and "R".
44087 LD L,A Store them in L.
44088 LD A,D Fetch the bits for "P", "O", "I", "U" and "Y".
44089 AND %00010101 Keep the bits for "P", "I" and "Y".
44091 OR L Combine them with the bits for "W" and "R".
44092 RET Z Return if none of them is being pressed.
44093 SET 4,C Set bit 4, fire.
44095 RET Return.
Prev: 43791 Up: Map Next: 44096