Prev: D022 Up: Map Next: D077
D03E: 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 D03E LD A,$F7 Read from the keyboard;
Port Number Bit
0 1 2 3 4
F7 1 2 3 4 5
D040 CALL ReadKeyboardPort
D043 PUSH BC Stash BC on the stack.
D044 LD B,$05 Set the number of keys to 05.
Reverse the order of the five keys into C.
ReadInterface2Joystick_Reverse D046 RRA Rotate A right.
D047 RL C Rotate C left.
D049 DJNZ ReadInterface2Joystick_Reverse Jump to ReadInterface2Joystick_Reverse until B is zero.
Take the reversed keys and restore BC.
D04B LD A,C Copy C to A.
D04C POP BC Restore BC from the stack.
D04D LD C,A Copy it to C.
Merge the keys 6 to 0.
D04E LD A,$EF Read from the keyboard;
Port Number Bit
0 1 2 3 4
EF 0 9 8 7 6
D050 CALL ReadKeyboardPort
D053 OR C Combine the keys of the two joysticks.
D054 LD C,$00 Set the controls to none.
D056 BIT 0,A Set the jump control if the fire key is pressed.
D058 JR Z,ReadInterface2Joystick_TestUp
D05A SET 3,C
ReadInterface2Joystick_TestUp D05C BIT 1,A Set the walk control if the up key is pressed.
D05E JR Z,ReadInterface2Joystick_TestDown
D060 SET 2,C
ReadInterface2Joystick_TestDown D062 BIT 2,A Set the pick up control if the down key is pressed.
D064 JR Z,ReadInterface2Joystick_TestRight
D066 SET 4,C
ReadInterface2Joystick_TestRight D068 BIT 3,A Set the right control if the right key is pressed.
D06A JR Z,ReadInterface2Joystick_TestLeft
D06C SET 1,C
ReadInterface2Joystick_TestLeft D06E BIT 4,A Set the left control if the left key is pressed.
D070 JR Z,ReadInterface2Joystick_Done
D072 SET 0,C
ReadInterface2Joystick_Done D074 JP ReadControls_Finish Jump to ReadControls_Finish.
View the equivalent code in;
Prev: D022 Up: Map Next: D077