Prev: B115 Up: Map Next: B234
B16F: Read Input Device
Used by the routine at ReadControls.
Reads the device that was chosen on the title screen: the keyboard (00), a Kempston joystick (01), a Cursor joystick (02) or a Sinclair Interface 2 joystick (03). The result is in the same layout for all of them. The keyboard has no joystick, so the keys of the middle two rows are all for up, the top row is for fire, the number keys are for the extra key, and the keys of the bottom row alternate between right and left.
Output
C Controls: bit 0 is right, bit 1 left, bit 3 up, bit 4 fire and bit 5 the extra key
ReadInputDevice B16F LD A,($F603) The control device.
B172 AND A Jump to ReadInputDevice_Keyboard if A is zero.
B173 JP Z,ReadInputDevice_Keyboard
B176 CP $01 Jump to ReadInputDevice_Kempston if A is 01.
B178 JR Z,ReadInputDevice_Kempston
B17A CP $02 Jump to ReadInputDevice_Cursor if A is 02.
B17C JR Z,ReadInputDevice_Cursor
B17E JR ReadInputDevice_Interface2 Jump to ReadInputDevice_Interface2.
ReadInputDevice_Kempston B180 IN A,($1F) Read port 1F.
B182 AND %00011111 Keep the bits of A that are set in 1F.
B184 LD C,A C=A.
B185 JP ReadInputDevice_Joystick Jump to ReadInputDevice_Joystick.
ReadInputDevice_Interface2 B188 LD A,$EF A=EF.
B18A OUT ($FD),A Send A to port FD.
B18C IN A,($FE) Read port FE.
B18E LD B,$FF B=FF.
B190 RRA Rotate A right.
B191 RL B Rotate B left through the carry.
B193 RRA Rotate A right.
B194 RL B Rotate B left through the carry.
B196 RRA Rotate A right.
B197 RL B Rotate B left through the carry.
B199 RRA Rotate A right.
B19A RRA Rotate A right.
B19B RL B Rotate B left through the carry.
B19D RLA Rotate A left.
B19E RL B Rotate B left through the carry.
B1A0 LD A,B A=B.
B1A1 CPL Invert A.
B1A2 LD C,A C=A.
B1A3 JP ReadInputDevice_Joystick Jump to ReadInputDevice_Joystick.
ReadInputDevice_Cursor B1A6 LD A,$EF A=EF.
B1A8 OUT ($FD),A Send A to port FD.
B1AA IN A,($FE) Read port FE.
B1AC OR %11100000 Set the bits of A that are set in E0.
B1AE LD B,A B=A.
B1AF AND %00001000 Keep the bits of A that are set in 08.
B1B1 LD C,A C=A.
B1B2 LD A,B A=B.
B1B3 RRCA Rotate A right.
B1B4 RRCA Rotate A right.
B1B5 LD B,A B=A.
B1B6 AND %00000101 Keep the bits of A that are set in 05.
B1B8 OR C Set the bits of A that are set in C.
B1B9 LD C,A C=A.
B1BA LD A,B A=B.
B1BB RRA Rotate A right.
B1BC RRA Rotate A right.
B1BD AND %00010000 Keep the bits of A that are set in 10.
B1BF OR C Set the bits of A that are set in C.
B1C0 LD C,A C=A.
B1C1 LD A,$F7 A=F7.
B1C3 OUT ($FD),A Send A to port FD.
B1C5 IN A,($FE) Read port FE.
B1C7 RRA Rotate A right.
B1C8 RRA Rotate A right.
B1C9 RRA Rotate A right.
B1CA AND %00000010 Keep the bits of A that are set in 02.
B1CC OR C Set the bits of A that are set in C.
B1CD CPL Invert A.
B1CE LD C,A C=A.
B1CF JP ReadInputDevice_Joystick Jump to ReadInputDevice_Joystick.
ReadInputDevice_Keyboard B1D2 XOR A Clear A.
B1D3 LD C,A C=A.
B1D4 LD A,$FE A=FE.
B1D6 OUT ($FD),A Send A to port FD.
B1D8 IN A,($FE) Read port FE.
B1DA AND %00010100 Keep the bits of A that are set in 14.
B1DC LD B,A B=A.
B1DD LD A,$7F A=7F.
B1DF OUT ($FD),A Send A to port FD.
B1E1 IN A,($FE) Read port FE.
B1E3 AND %00001010 Keep the bits of A that are set in 0A.
B1E5 OR B Set the bits of A that are set in B.
B1E6 XOR %00011110 Flip the bits of A that are set in 1E.
B1E8 JR Z,ReadInputDevice_Left Jump to ReadInputDevice_Left if the zero flag is set.
B1EA LD A,C A=C.
B1EB OR %00000001 Set the bits of A that are set in 01.
B1ED LD C,A C=A.
B1EE JR ReadInputDevice_Up Jump to ReadInputDevice_Up.
ReadInputDevice_Left B1F0 LD A,$FE A=FE.
B1F2 OUT ($FD),A Send A to port FD.
B1F4 IN A,($FE) Read port FE.
B1F6 AND %00001010 Keep the bits of A that are set in 0A.
B1F8 LD B,A B=A.
B1F9 LD A,$7F A=7F.
B1FB OUT ($FD),A Send A to port FD.
B1FD IN A,($FE) Read port FE.
B1FF AND %00010100 Keep the bits of A that are set in 14.
B201 OR B Set the bits of A that are set in B.
B202 XOR %00011110 Flip the bits of A that are set in 1E.
B204 JR Z,ReadInputDevice_Up Jump to ReadInputDevice_Up if the zero flag is set.
B206 SET 1,C Set bit 1 of C.
ReadInputDevice_Up B208 LD A,$BD A=BD.
B20A CALL ReadKeyboardPort Call ReadKeyboardPort.
B20D JR Z,ReadInputDevice_Fire Jump to ReadInputDevice_Fire if the zero flag is set.
B20F SET 3,C Set bit 3 of C.
ReadInputDevice_Fire B211 LD A,$DB A=DB.
B213 CALL ReadKeyboardPort Call ReadKeyboardPort.
B216 JR Z,ReadInputDevice_Extra Jump to ReadInputDevice_Extra if the zero flag is set.
B218 SET 4,C Set bit 4 of C.
ReadInputDevice_Extra B21A LD A,$E7 A=E7.
B21C LD B,$00 Clear B.
ReadInputDevice_Test B21E CALL ReadKeyboardPort Call ReadKeyboardPort.
B221 OR B Set the bits of A that are set in B.
B222 RET Z Return if the zero flag is set.
B223 SET 5,C Set bit 5 of C.
B225 RET Return.
ReadInputDevice_Joystick B226 RES 5,C Reset bit 5 of C.
B228 LD A,$7E A=7E.
B22A CALL ReadKeyboardPort Call ReadKeyboardPort.
B22D AND %00011110 Keep the bits of A that are set in 1E.
B22F LD B,A B=A.
B230 LD A,$99 A=99.
B232 JR ReadInputDevice_Test Jump to ReadInputDevice_Test.
Prev: B115 Up: Map Next: B234