Prev: 53282 Up: Map Next: 53367
53310: 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 53310 LD A,247 Read from the keyboard;
Port Number Bit
0 1 2 3 4
247 1 2 3 4 5
53312 CALL ReadKeyboardPort
53315 PUSH BC Stash BC on the stack.
53316 LD B,5 Set the number of keys to 5.
Reverse the order of the five keys into C.
ReadInterface2Joystick_Reverse 53318 RRA Rotate A right.
53319 RL C Rotate C left.
53321 DJNZ ReadInterface2Joystick_Reverse Jump to ReadInterface2Joystick_Reverse until B is zero.
Take the reversed keys and restore BC.
53323 LD A,C Copy C to A.
53324 POP BC Restore BC from the stack.
53325 LD C,A Copy it to C.
Merge the keys 6 to 0.
53326 LD A,239 Read from the keyboard;
Port Number Bit
0 1 2 3 4
239 0 9 8 7 6
53328 CALL ReadKeyboardPort
53331 OR C Combine the keys of the two joysticks.
53332 LD C,0 Set the controls to none.
53334 BIT 0,A Set the jump control if the fire key is pressed.
53336 JR Z,ReadInterface2Joystick_TestUp
53338 SET 3,C
ReadInterface2Joystick_TestUp 53340 BIT 1,A Set the walk control if the up key is pressed.
53342 JR Z,ReadInterface2Joystick_TestDown
53344 SET 2,C
ReadInterface2Joystick_TestDown 53346 BIT 2,A Set the pick up control if the down key is pressed.
53348 JR Z,ReadInterface2Joystick_TestRight
53350 SET 4,C
ReadInterface2Joystick_TestRight 53352 BIT 3,A Set the right control if the right key is pressed.
53354 JR Z,ReadInterface2Joystick_TestLeft
53356 SET 1,C
ReadInterface2Joystick_TestLeft 53358 BIT 4,A Set the left control if the left key is pressed.
53360 JR Z,ReadInterface2Joystick_Done
53362 SET 0,C
ReadInterface2Joystick_Done 53364 JP ReadControls_Finish Jump to ReadControls_Finish.
View the equivalent code in;
Prev: 53282 Up: Map Next: 53367