← BC23 Player control state Map BCAD → Wait until no key is pressed
BC25: Read the player's controls into the control bitfield
Rebuilds the control bitfield from scratch on each call.
The control bitfield it builds, whose bits 0–1 and 5–7 are always 0:
Bit When set
2 Down/back held
3 Up/forward held
4 Fire held
The control bitfield's two motion bits are forward and back along the bat's fixed edge.
Per-device reads, by input device value:
Device code Device Fire Up (bit 3) Down (bit 2)
0 Keyboard Space P L
1 Kempston port bit 4 port bit 3 port bit 2
2 Cursor key 0 key 7 key 6
3 Sinclair key 0 key 9 key 8
read_ctrl BC25 LD HL,controls Point HL at the control bitfield.
BC28 XOR A
BC29 LD (HL),A Zero it; every control bit is rebuilt from scratch each call.
BC2A LD A,(input_device) Read the selected input device.
BC2D OR A
BC2E JP Z,read_ctrl_keyboard
BC31 CP $01 Kempston joystick
BC33 JR Z,read_ctrl_kempston
BC35 CP $02 Cursor keys
BC37 JP Z,read_ctrl_cursor
BC3A LD BC,KBD_ROW_6_0 Sinclair joystick, the fall-through – read the 6/7/8/9/0 keyboard half-row.
BC3D IN A,(C)
Each scheme tests its inputs and sets the output bit for each one. The field is zeroed at entry, so nothing is cleared mid-read. A pressed key on the keyboard and the two key-set joysticks reads as 0. The Kempston port reads a pressed input as 1.
BC3F AND $1F Keep the five key bits.
BC41 BIT 0,A Key 0 (fire) up?
BC43 JR NZ,read_ctrl_sinclair_up
BC45 SET 4,(HL) Fire held
read_ctrl_sinclair_up BC47 BIT 1,A Key 9 (up) up?
BC49 JR NZ,read_ctrl_sinclair_down
BC4B SET 3,(HL) Up held
BC4D RET
read_ctrl_sinclair_down BC4E BIT 2,A Key 8 (down) up?
BC50 RET NZ
BC51 SET 2,(HL) Down held
BC53 RET
read_ctrl_kempston BC54 IN A,($1F) Kempston: read the joystick port.
BC56 AND $1C Keep only the fire/up/down bits.
BC58 BIT 4,A Fire pressed?
BC5A JR Z,read_ctrl_kempston_up
BC5C SET 4,(HL) Fire held
read_ctrl_kempston_up BC5E BIT 3,A Up pressed?
BC60 JR Z,read_ctrl_kempston_down
BC62 SET 3,(HL) Up held
BC64 RET
read_ctrl_kempston_down BC65 BIT 2,A Down pressed?
BC67 RET Z
BC68 SET 2,(HL) Down held
BC6A RET
read_ctrl_cursor BC6B LD BC,KBD_ROW_6_0 Cursor keys: read the 6/7/8/9/0 keyboard half-row.
BC6E IN A,(C)
BC70 AND $1F
BC72 BIT 0,A Key 0 (fire) up?
BC74 JR NZ,read_ctrl_cursor_up
BC76 SET 4,(HL) Fire held
read_ctrl_cursor_up BC78 BIT 3,A Key 7 (up) up?
BC7A JR NZ,read_ctrl_cursor_down
BC7C SET 3,(HL) Up held
BC7E RET
read_ctrl_cursor_down BC7F BIT 4,A Key 6 (down) up?
BC81 RET NZ
BC82 SET 2,(HL) Down held
BC84 RET
read_ctrl_keyboard BC85 LD BC,KBD_ROW_B_SPACE Keyboard: read Space for fire, on the B/N/M/SymShift/Space half-row.
BC88 IN A,(C)
BC8A AND $1F
BC8C BIT 0,A
BC8E JR NZ,read_ctrl_keyboard_up
BC90 SET 4,(HL) Fire held
read_ctrl_keyboard_up BC92 LD BC,KBD_ROW_Y_P Read P for up, on the Y/U/I/O/P half-row.
BC95 IN A,(C)
BC97 AND $1F
BC99 BIT 0,A
BC9B JR NZ,read_ctrl_keyboard_down
BC9D SET 3,(HL) Up held
BC9F RET
read_ctrl_keyboard_down BCA0 LD BC,KBD_ROW_H_ENTER Read L for down, on the H/J/K/L/Enter half-row.
BCA3 IN A,(C)
BCA5 AND $1F
BCA7 BIT 1,A
BCA9 RET NZ
BCAA SET 2,(HL) Down held
BCAC RET
← BC23 Player control state Map BCAD → Wait until no key is pressed
Fork me on GitHub