Prev: E241 Up: Map Next: E289
E250: Read Interface 2 Joystick
Reads the controls from the Interface 2 joysticks, which are the keys 1 to 5 for the first joystick and 6 to 0 for the second joystick. The joysticks use the keys left, right, down, up and fire in that order, so the keys of the first joystick are reversed to put them in the same order as the keys of the second joystick.
Output
C The controls
Reverse the keys 1 to 5.
ReadInterface2Joystick E250 LD A,$F7 Read from the keyboard;
Port Number Bit
0 1 2 3 4
F7 1 2 3 4 5
E252 CALL ReadKeyboardPort
Save the registers, and count five keys.
E255 PUSH BC Stash BC on the stack.
E256 LD B,$05 Set B to 05.
ReadInterface2Joystick_Reverse E258 RRA Rotate A right.
E259 RL C Rotate C left.
E25B DJNZ ReadInterface2Joystick_Reverse Jump to ReadInterface2Joystick_Reverse until B is zero.
Get the registers back, and keep the reversed keys.
E25D LD A,C Copy C to A.
E25E POP BC Restore BC from the stack.
E25F LD C,A Copy it to C.
Merge the keys 6 to 0.
E260 LD A,$EF Read from the keyboard;
Port Number Bit
0 1 2 3 4
EF 0 9 8 7 6
E262 CALL ReadKeyboardPort
E265 OR C Combine them with the keys 1 to 5, so that the joysticks are the same.
Set the controls from the keys.
E266 LD C,$00 Start with none of the controls.
E268 BIT 0,A Set the control for fire if the key for fire is pressed.
E26A JR Z,ReadInterface2Joystick_Forward
E26C SET 3,C
ReadInterface2Joystick_Forward E26E BIT 1,A Set the control for forward if the key for up is pressed.
E270 JR Z,ReadInterface2Joystick_Down
E272 SET 2,C
ReadInterface2Joystick_Down E274 BIT 2,A Set the control for down if the key for down is pressed.
E276 JR Z,ReadInterface2Joystick_Right
E278 SET 4,C
ReadInterface2Joystick_Right E27A BIT 3,A Set the control for right if the key for right is pressed.
E27C JR Z,ReadInterface2Joystick_Left
E27E SET 1,C
ReadInterface2Joystick_Left E280 BIT 4,A Set the control for left if the key for left is pressed.
E282 JR Z,ReadInterface2Joystick_ViewKey
E284 SET 0,C
ReadInterface2Joystick_ViewKey E286 JP ReadViewKey Jump to ReadViewKey to read the key for turning the view.
View the equivalent code in;
Prev: E241 Up: Map Next: E289