Prev: D0E3 Up: Map Next: D12B
D0F2: Read Interface 2 Joystick
Reads an Interface 2 joystick. The first joystick is 1 to 5 (left, right, down, up, fire) and the second is 6 to 0. The first row is reversed and the two are combined, so either can be used.
Output
C The controls
Read 1 to 5.
ReadInterface2Joystick D0F2 LD A,$F7 Read from the keyboard;
Port Number Bit
0 1 2 3 4
F7 1 2 3 4 5
D0F4 CALL ReadKeyboardPort
D0F7 PUSH BC Stash BC on the stack.
D0F8 LD B,$05 Set a count of 05.
Reverse the five keys into C.
ReadInterface2Joystick_Reverse D0FA RRA Reverse the five keys into C.
D0FB RL C
D0FD DJNZ ReadInterface2Joystick_Reverse
D0FF LD A,C Keep the reversed keys, and restore BC.
D100 POP BC
D101 LD C,A
Read 6 to 0, and combine the two joysticks.
D102 LD A,$EF Read from the keyboard;
Port Number Bit
0 1 2 3 4
EF 0 9 8 7 6
D104 CALL ReadKeyboardPort
D107 OR C Combine them with the reversed keys.
D108 LD C,$00 Clear the controls.
Set bit 3 if fire is pressed.
D10A BIT 0,A Set bit 3 if fire is pressed.
D10C JR Z,ReadInterface2Joystick_TestUp
D10E SET 3,C
Set bit 2 if up is pressed.
ReadInterface2Joystick_TestUp D110 BIT 1,A Set bit 2 if up is pressed.
D112 JR Z,ReadInterface2Joystick_TestDown
D114 SET 2,C
Set bit 4 if down is pressed.
ReadInterface2Joystick_TestDown D116 BIT 2,A Set bit 4 if down is pressed.
D118 JR Z,ReadInterface2Joystick_TestRight
D11A SET 4,C
Set bit 1 if right is pressed.
ReadInterface2Joystick_TestRight D11C BIT 3,A Set bit 1 if right is pressed.
D11E JR Z,ReadInterface2Joystick_TestLeft
D120 SET 1,C
Set bit 0 if left is pressed.
ReadInterface2Joystick_TestLeft D122 BIT 4,A Set bit 0 if left is pressed.
D124 JR Z,ReadInterface2Joystick_Finish
D126 SET 0,C
ReadInterface2Joystick_Finish D128 JP ReadControls_Rotate Jump to ReadControls_Rotate.
View the equivalent code in;
Prev: D0E3 Up: Map Next: D12B