Prev: ADF8 Up: Map Next: AE56
AE17: Read Controls
Reads the controls that were chosen on the game selection screen (see GameOptions). A bit is reset when its control is used: bit 0 is right, bit 1 is left, bit 2 is down, bit 3 is up and bit 4 is fire. The keyboard uses W, Q, E, R and T.
Bit 5 is reset when a key from the bottom row of the keyboard (CAPS SHIFT, Z, X, C or V) is pressed, whichever control method is in use.
The cursor keys and the Interface II joystick are read by Read_Cursor_Keys and Read_Interface_II_Joystick. The Kempston joystick is read directly.
Output
A The state of the controls
B The state of the controls
Pick the routine for the control method.
ReadControls AE17 LD A,($8ED5) Fetch the control method from GameOptions.
AE1A AND %00000011 Keep only the control method bits (bits 0 and 1).
AE1C JR Z,ReadControls_Keyboard Jump to ReadControls_Keyboard if the keyboard is being used.
AE1E CP $02 Jump to Read_Cursor_Keys if the cursor keys are being used.
AE20 JP Z,Read_Cursor_Keys
AE23 CP $03 Jump to Read_Interface_II_Joystick if the Interface II joystick is being used.
AE25 JP Z,Read_Interface_II_Joystick
Read the Kempston joystick.
AE28 IN A,($1F) Read the Kempston joystick.
AE2A CPL Flip the bits, so that a reset bit is a direction or fire which is used.
AE2B LD B,A Store the state of the controls in B.
This entry point is used by the routines at Read_Cursor_Keys and Read_Interface_II_Joystick.
Read the bottom row of the keyboard, which sets bit 5 whichever control method is being used.
ReadControls_Bottom_Row AE2C LD A,$FE Read from the keyboard;
Port Number Bit
0 1 2 3 4
FE CAPS SHIFT Z X C V
AE2E OUT ($FD),A
AE30 IN A,($FE)
AE32 CPL Flip the bits so that a pressed key gives a set bit.
AE33 AND %00011111 Keep only the five keys.
AE35 SET 5,B Set bit 5 of the controls.
AE37 JR Z,ReadControls_Fetch_State Jump to ReadControls_Fetch_State if none of those keys is pressed.
AE39 RES 5,B Reset bit 5 of the controls.
ReadControls_Fetch_State AE3B LD A,B Fetch the state of the controls.
AE3C RET Return.
Read the keyboard controls.
ReadControls_Keyboard AE3D LD A,$FB Read from the keyboard;
Port Number Bit
0 1 2 3 4
FB Q W E R T
AE3F OUT ($FD),A
AE41 IN A,($FE)
AE43 LD C,A Stash the state of the keys in C.
AE44 RRA Move bit 1 (W) into bit 0.
AE45 AND %00000001 Keep only that bit (right).
AE47 LD B,A Store it in B.
AE48 LD A,C Fetch the state of the keys.
AE49 RLA Move bit 0 (Q) into bit 1.
AE4A AND %00000010 Keep only that bit (left).
AE4C OR B Combine it with right.
AE4D LD B,A Store the result in B.
AE4E LD A,C Fetch the state of the keys.
AE4F AND %00011100 Keep only bits 2 to 4 (E, R and T: down, up and fire).
AE51 OR B Combine them with right and left.
AE52 LD B,A Store the result in B.
AE53 JP ReadControls_Bottom_Row Jump to ReadControls_Bottom_Row to read the bottom row of the keyboard.
View the equivalent code in;
Prev: ADF8 Up: Map Next: AE56