Prev: BDDE Up: Map Next: BF0D
BDF8: Read Controls
Used by the routine at HandlePlayerLegs.
Reads the keyboard or the joystick, according to the control method that was chosen in the menu, and writes what is wanted to ControlsPressed as a set of bits:
Bit Meaning
00 Turn left
01 Turn right
02 Walk forward
03 Jump
04 Pick up or drop an object
06 Fire
With the keyboard, any of several keys do each action. With a joystick, up walks forward, down jumps and fire fires, and a long list of the keys of the keyboard picks up or drops an object.
CAPS SHIFT and SPACE are left alone by this routine, as they pause the game (see PauseGame).
Output
C The controls, also written to ControlsPressed
Find the control method: 00 is the keyboard, 01 is a Kempston joystick, 02 is a cursor joystick and 03 is an Interface II joystick.
ReadControls BDF8 LD A,($A709) Fetch the control method.
BDFB RRCA Shift the method down to bits 0 and 1...
BDFC AND %00000011 ...and keep only those bits.
BDFE JP Z,ReadControls_Keyboard Jump to ReadControls_Keyboard to read the keyboard if the method is 00.
BE01 DEC A Jump to ReadControls_Kempston to read a Kempston joystick if the method is 01.
BE02 JR Z,ReadControls_Kempston
BE04 DEC A Jump to ReadControls_Cursor to read a cursor joystick if the method is 02.
BE05 JR Z,ReadControls_Cursor
Read an Interface II joystick, which can be either of the two ports of the interface: they are the keys 1 to 5 (left, right, down, up, fire) and the keys 6, 7, 8, 9 and 0 (left, right, down, up, fire).
BE07 LD A,$F7 Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
Port Number Bit
0 1 2 3 4
F7 1 2 3 4 5
BE09 CALL ReadKeyboardPort
BE0C PUSH BC Stash BC on the stack.
BE0D LD B,$05 Set a counter in B of five keys.
ReadControls_Reverse BE0F RRA Reverse the order of the five bits, so that they line up with the keys of the second port.
BE10 RL C
BE12 DJNZ ReadControls_Reverse
BE14 LD A,C Move the reversed keys to A.
BE15 POP BC Restore BC from the stack.
BE16 LD C,A Move the reversed keys to C.
BE17 LD A,$EF Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
Port Number Bit
0 1 2 3 4
EF 0 9 8 7 6
BE19 CALL ReadKeyboardPort
BE1C OR C Add the keys from the first port to those of the second.
BE1D LD C,$00 Start with no controls.
BE1F BIT 0,A Set the bit for fire if fire is pressed.
BE21 JR Z,ReadControls_Interface2Up
BE23 SET 6,C
ReadControls_Interface2Up BE25 BIT 1,A Set the bit for walking forward if up is pressed.
BE27 JR Z,ReadControls_Interface2Down
BE29 SET 2,C
ReadControls_Interface2Down BE2B BIT 2,A Set the bit for jumping if down is pressed.
BE2D JR Z,ReadControls_Interface2Right
BE2F SET 3,C
ReadControls_Interface2Right BE31 BIT 3,A Set the bit for turning right if right is pressed.
BE33 JR Z,ReadControls_Interface2Left
BE35 SET 1,C
ReadControls_Interface2Left BE37 BIT 4,A Set the bit for turning left if left is pressed.
BE39 JR Z,ReadControls_Interface2Keys
BE3B SET 0,C
ReadControls_Interface2Keys BE3D JP ReadControls_Keys Jump to ReadControls_Keys to check the keys for picking up and dropping.
Read a Kempston joystick, whose bits are right, left, down, up and fire.
ReadControls_Kempston BE40 IN A,($1F) Read the joystick.
BE42 LD C,$00 Start with no controls.
BE44 BIT 0,A Set the bit for turning right if right is pressed.
BE46 JR Z,ReadControls_KempstonLeft
BE48 SET 1,C
ReadControls_KempstonLeft BE4A BIT 1,A Set the bit for turning left if left is pressed.
BE4C JR Z,ReadControls_KempstonDown
BE4E SET 0,C
ReadControls_KempstonDown BE50 BIT 2,A Set the bit for jumping if down is pressed.
BE52 JR Z,ReadControls_KempstonUp
BE54 SET 3,C
ReadControls_KempstonUp BE56 BIT 3,A Set the bit for walking forward if up is pressed.
BE58 JR Z,ReadControls_KempstonFire
BE5A SET 2,C
ReadControls_KempstonFire BE5C BIT 4,A Set the bit for fire if fire is pressed.
BE5E JR Z,ReadControls_KempstonKeys
BE60 SET 6,C
ReadControls_KempstonKeys BE62 JP ReadControls_Keys Jump to ReadControls_Keys to check the keys for picking up and dropping.
Read a cursor joystick, which is the keys 5 (left), 6 (down), 7 (up), 8 (right) and 0 (fire).
ReadControls_Cursor BE65 LD C,$00 Start with no controls.
BE67 LD A,$F7 Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
Port Number Bit
0 1 2 3 4
F7 1 2 3 4 5
BE69 CALL ReadKeyboardPort
BE6C BIT 4,A Set the bit for turning left if the key 5 is pressed.
BE6E JR Z,ReadControls_CursorFire
BE70 SET 0,C
ReadControls_CursorFire BE72 LD A,$EF Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
Port Number Bit
0 1 2 3 4
EF 0 9 8 7 6
BE74 CALL ReadKeyboardPort
BE77 BIT 0,A Set the bit for fire if the key 0 is pressed.
BE79 JR Z,ReadControls_CursorUp
BE7B SET 6,C
ReadControls_CursorUp BE7D BIT 3,A Set the bit for walking forward if the key 7 is pressed.
BE7F JR Z,ReadControls_CursorRight
BE81 SET 2,C
ReadControls_CursorRight BE83 BIT 2,A Set the bit for turning right if the key 8 is pressed.
BE85 JR Z,ReadControls_CursorDown
BE87 SET 1,C
ReadControls_CursorDown BE89 BIT 4,A Set the bit for jumping if the key 6 is pressed.
BE8B JR Z,ReadControls_Keys
BE8D SET 3,C
BE8F JR ReadControls_Keys Jump to ReadControls_Keys to check the keys for picking up and dropping.
Read the keyboard. The keys that turn left are Z, C, M and B and those that turn right are X, V, SYMBOL SHIFT and N.
ReadControls_Keyboard BE91 LD A,$FE Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
Port Number Bit
0 1 2 3 4
FE CAPS SHIFT Z X C V
BE93 CALL ReadKeyboardPort
BE96 RRCA Shift the keys down by one, which drops CAPS SHIFT and leaves Z and C for turning left, and X and V for turning right.
BE97 LD C,A Stash them in C.
BE98 AND %00000011 Keep the keys Z and X.
BE9A SRL C Shift the keys C and V down to the same place.
BE9C SRL C
BE9E OR C Combine them with the keys Z and X.
BE9F AND %00000011 Keep the two bits for turning left and turning right.
BEA1 LD C,A Set the turning bits of the controls.
BEA2 LD A,$7F Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
Port Number Bit
0 1 2 3 4
7F SPACE SYMBOL SHIFT M N B
BEA4 CALL ReadKeyboardPort
BEA7 BIT 1,A Set the bit for turning right if SYMBOL SHIFT is pressed.
BEA9 JR Z,ReadControls_KeyboardM
BEAB SET 1,C
ReadControls_KeyboardM BEAD BIT 2,A Set the bit for turning left if M is pressed.
BEAF JR Z,ReadControls_KeyboardN
BEB1 SET 0,C
ReadControls_KeyboardN BEB3 BIT 3,A Set the bit for turning right if N is pressed.
BEB5 JR Z,ReadControls_KeyboardB
BEB7 SET 1,C
ReadControls_KeyboardB BEB9 BIT 4,A Set the bit for turning left if B is pressed.
BEBB JR Z,ReadControls_KeyboardWalk
BEBD SET 0,C
ReadControls_KeyboardWalk BEBF LD A,$BD Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
Port Number Bit
0 1 2 3 4
BD A or ENTER S or L D or K F or J G or H
BEC1 CALL ReadKeyboardPort
BEC4 JR Z,ReadControls_KeyboardJumpKeys Set the bit for walking forward if any of those keys is pressed.
BEC6 SET 2,C
ReadControls_KeyboardJumpKeys BEC8 LD A,$DF Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
Port Number Bit
0 1 2 3 4
DF P O I U Y
BECA CALL ReadKeyboardPort
BECD LD B,A Stash the keys in B, which is not used.
BECE AND %00001010 Keep the keys O and U.
BED0 JR NZ,ReadControls_KeyboardJump Jump to ReadControls_KeyboardJump if either of them is pressed.
BED2 LD A,$FB Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
Port Number Bit
0 1 2 3 4
FB Q W E R T
BED4 CALL ReadKeyboardPort
BED7 LD E,A Stash the keys in E, which is not used.
BED8 AND %00010101 Keep the keys Q, E and T.
BEDA JR Z,ReadControls_KeyboardAction Jump to ReadControls_KeyboardAction if none of them is pressed.
ReadControls_KeyboardJump BEDC SET 3,C Set the bit for jumping, as one of the keys Q, E, T, O and U is pressed.
ReadControls_KeyboardAction BEDE LD A,$E7 Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
Port Number Bit
0 1 2 3 4
E7 1 or 0 2 or 9 3 or 8 4 or 7 5 or 6
BEE0 CALL ReadKeyboardPort
BEE3 JR Z,ReadControls_KeyboardFire Jump to ReadControls_KeyboardFire if none of the number keys is pressed.
BEE5 SET 4,C Set the bit for picking up and dropping, as a number key is pressed.
ReadControls_KeyboardFire BEE7 LD A,$DF Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
Port Number Bit
0 1 2 3 4
DF P O I U Y
BEE9 CALL ReadKeyboardPort
BEEC AND %00010101 Keep the keys P, I and Y.
BEEE JR NZ,ReadControls_KeyboardSetFire Jump to ReadControls_KeyboardSetFire if one of them is pressed.
BEF0 LD A,$FB Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
Port Number Bit
0 1 2 3 4
FB Q W E R T
BEF2 CALL ReadKeyboardPort
BEF5 AND %00001010 Keep the keys W and R.
BEF7 JR Z,ReadControls_Done Jump to ReadControls_Done if neither is pressed.
ReadControls_KeyboardSetFire BEF9 SET 6,C Set the bit for fire, as one of the keys P, I, Y, W and R is pressed.
BEFB JR ReadControls_Done Jump to ReadControls_Done to finish.
With a joystick, the keys of the keyboard other than CAPS SHIFT and SPACE are used to pick up and drop an object.
ReadControls_Keys BEFD LD A,$7E Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
Port Number Bit
0 1 2 3 4
7E CAPS SHIFT or SPACE Z or SYMBOL SHIFT X or M C or N V or B
BEFF CALL ReadKeyboardPort
BF02 AND %00011110 Keep the keys other than CAPS SHIFT and SPACE.
BF04 JR Z,ReadControls_Done Jump to ReadControls_Done if none of them is pressed.
BF06 SET 4,C Set the bit for picking up and dropping.
ReadControls_Done BF08 LD A,C Copy the controls to A.
BF09 LD ($A737),A Write them to ControlsPressed.
BF0C RET Return.
View the equivalent code in;
Prev: BDDE Up: Map Next: BF0D