Prev: 44536 Up: Map Next: 44630
44567: 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 44567 LD A,(36565) Fetch the control method from GameOptions.
44570 AND %00000011 Keep only the control method bits (bits 0 and 1).
44572 JR Z,ReadControls_Keyboard Jump to ReadControls_Keyboard if the keyboard is being used.
44574 CP 2 Jump to Read_Cursor_Keys if the cursor keys are being used.
44576 JP Z,Read_Cursor_Keys
44579 CP 3 Jump to Read_Interface_II_Joystick if the Interface II joystick is being used.
44581 JP Z,Read_Interface_II_Joystick
Read the Kempston joystick.
44584 IN A,(31) Read the Kempston joystick.
44586 CPL Flip the bits, so that a reset bit is a direction or fire which is used.
44587 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 44588 LD A,254 Read from the keyboard;
Port Number Bit
0 1 2 3 4
254 CAPS SHIFT Z X C V
44590 OUT (253),A
44592 IN A,(254)
44594 CPL Flip the bits so that a pressed key gives a set bit.
44595 AND %00011111 Keep only the five keys.
44597 SET 5,B Set bit 5 of the controls.
44599 JR Z,ReadControls_Fetch_State Jump to ReadControls_Fetch_State if none of those keys is pressed.
44601 RES 5,B Reset bit 5 of the controls.
ReadControls_Fetch_State 44603 LD A,B Fetch the state of the controls.
44604 RET Return.
Read the keyboard controls.
ReadControls_Keyboard 44605 LD A,251 Read from the keyboard;
Port Number Bit
0 1 2 3 4
251 Q W E R T
44607 OUT (253),A
44609 IN A,(254)
44611 LD C,A Stash the state of the keys in C.
44612 RRA Move bit 1 (W) into bit 0.
44613 AND %00000001 Keep only that bit (right).
44615 LD B,A Store it in B.
44616 LD A,C Fetch the state of the keys.
44617 RLA Move bit 0 (Q) into bit 1.
44618 AND %00000010 Keep only that bit (left).
44620 OR B Combine it with right.
44621 LD B,A Store the result in B.
44622 LD A,C Fetch the state of the keys.
44623 AND %00011100 Keep only bits 2 to 4 (E, R and T: down, up and fire).
44625 OR B Combine them with right and left.
44626 LD B,A Store the result in B.
44627 JP ReadControls_Bottom_Row Jump to ReadControls_Bottom_Row to read the bottom row of the keyboard.
View the equivalent code in;
Prev: 44536 Up: Map Next: 44630