Prev: 57921 Up: Map Next: 57993
57936: 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 57936 LD A,247 Read from the keyboard;
Port Number Bit
0 1 2 3 4
247 1 2 3 4 5
57938 CALL ReadKeyboardPort
Save the registers, and count five keys.
57941 PUSH BC Stash BC on the stack.
57942 LD B,5 Set B to 5.
ReadInterface2Joystick_Reverse 57944 RRA Rotate A right.
57945 RL C Rotate C left.
57947 DJNZ ReadInterface2Joystick_Reverse Jump to ReadInterface2Joystick_Reverse until B is zero.
Get the registers back, and keep the reversed keys.
57949 LD A,C Copy C to A.
57950 POP BC Restore BC from the stack.
57951 LD C,A Copy it to C.
Merge the keys 6 to 0.
57952 LD A,239 Read from the keyboard;
Port Number Bit
0 1 2 3 4
239 0 9 8 7 6
57954 CALL ReadKeyboardPort
57957 OR C Combine them with the keys 1 to 5, so that the joysticks are the same.
Set the controls from the keys.
57958 LD C,0 Start with none of the controls.
57960 BIT 0,A Set the control for fire if the key for fire is pressed.
57962 JR Z,ReadInterface2Joystick_Forward
57964 SET 3,C
ReadInterface2Joystick_Forward 57966 BIT 1,A Set the control for forward if the key for up is pressed.
57968 JR Z,ReadInterface2Joystick_Down
57970 SET 2,C
ReadInterface2Joystick_Down 57972 BIT 2,A Set the control for down if the key for down is pressed.
57974 JR Z,ReadInterface2Joystick_Right
57976 SET 4,C
ReadInterface2Joystick_Right 57978 BIT 3,A Set the control for right if the key for right is pressed.
57980 JR Z,ReadInterface2Joystick_Left
57982 SET 1,C
ReadInterface2Joystick_Left 57984 BIT 4,A Set the control for left if the key for left is pressed.
57986 JR Z,ReadInterface2Joystick_ViewKey
57988 SET 0,C
ReadInterface2Joystick_ViewKey 57990 JP ReadViewKey Jump to ReadViewKey to read the key for turning the view.
View the equivalent code in;
Prev: 57921 Up: Map Next: 57993