Prev: 45315 Up: Map Next: 45475
45340: Read Keyboard
Used by the routine at ReadControls.
Reads the keyboard. The keys C, M and B turn right, and X, V and N turn left. Any of A, S, D, F, G, Enter, L, K, J and H moves forward. The keys O, U, Q, E and T fire the second weapon, and P, I, Y, W and R fire the first one. Z, Symbol Shift and all of the number keys use the action key.
Output
A The controls
C The controls
ReadKeyboard 45340 LD A,254 Read from the keyboard;
Port Number Bit
0 1 2 3 4
254 SHIFT Z X C V
45342 CALL ReadKeys
45345 PUSH BC Save BC.
45346 RRCA Move the keys Z, X, C and V into the lowest bits...
45347 AND 14 ...and keep X, C and V.
45349 LD C,A Keep the keys X, C and V.
45350 AND 3 Keep X, which turns left...
45352 SRL C ...and move C and V down by two bits.
45354 SRL C Shift C into the right-turn bit and V into the left-turn bit.
45356 OR C Combine them, so that C turns right and X or V turn left...
45357 AND 3 ...and keep just the bits for turning.
45359 LD C,A
45360 LD A,127 Read from the keyboard;
Port Number Bit
0 1 2 3 4
127 SPACE SYMBOL SHIFT M N B
45362 CALL ReadKeys
45365 RRA Move the keys Symbol Shift, M, N and B into the lowest bits...
45366 AND 14 ...and keep M, N and B.
45368 LD B,A Keep the keys M, N and B.
45369 RR B Rotate the keys round, so that N turns left and M turns right...
45371 RLA Shift the next key in.
45372 RR B Rotate the keys that are left.
45374 RLA Shift the next key in.
45375 AND 3 ...keep just the bits for turning and combine them with the others.
45377 OR C
45378 LD C,A Keep the turning bits.
45379 RR B Do the same for the last of the keys, so that B turns right...
45381 RLA Shift the last key in.
45382 RR B Rotate the keys that are left.
45384 RLA Shift the last key in.
45385 AND 3 ...keep just the bits for turning and combine them with the others.
45387 OR C
45388 POP BC Restore BC.
45389 LD C,A Keep the bits for turning.
45390 LD A,189 Read from the keyboard;
Port Number Bit
0 1 2 3 4
189 A / ENTER S / L D / K F / J G / H
45392 CALL ReadKeys
45395 AND 31 Jump if none of them is pressed.
45397 JR Z,ReadKeyboard_ReadPToY
45399 SET 2,C Set the bit for moving forward.
ReadKeyboard_ReadPToY 45401 LD A,223 Read from the keyboard;
Port Number Bit
0 1 2 3 4
223 P O I U Y
45403 CALL ReadKeys
45406 LD B,A Keep the keys P to Y.
45407 AND 10 Jump if neither O nor U is pressed.
45409 JR Z,ReadKeyboard_CheckPIY
45411 SET 3,C Set the bit for firing the second weapon.
ReadKeyboard_CheckPIY 45413 LD A,B Fetch the keys again.
45414 AND 21 Jump if none of P, I and Y is pressed.
45416 JR Z,ReadKeyboard_ReadQToT
45418 SET 4,C Set the bit for firing the first weapon.
ReadKeyboard_ReadQToT 45420 LD A,251 Read from the keyboard;
Port Number Bit
0 1 2 3 4
251 Q W E R T
45422 CALL ReadKeys
45425 LD B,A Keep the keys Q to T.
45426 AND 21 Jump if none of Q, E and T is pressed.
45428 JR Z,ReadKeyboard_CheckQET
45430 SET 3,C Set the bit for firing the second weapon.
ReadKeyboard_CheckQET 45432 LD A,B Fetch the keys again.
45433 AND 10 Jump if neither W nor R is pressed.
45435 JR Z,ReadKeyboard_Controls
45437 SET 4,C Set the bit for firing the first weapon.
ReadKeyboard_Controls 45439 LD A,(38437) Fetch the controls that have not been used yet...
45442 OR C ...and add the new ones.
45443 LD C,A Keep the controls.
45444 RES 6,C Clear the bit for the action key.
45446 LD A,126 Read from the keyboard;
Port Number Bit
0 1 2 3 4
126 SHIFT / SPACE Z / SYM X / M C / N V / B
45448 CALL ReadKeys
45451 AND 2 Jump if neither Z nor Symbol Shift is pressed.
45453 JR Z,ReadKeyboard_ReadNumbers
45455 SET 6,C Set the bit for the action key.
ReadKeyboard_ReadNumbers 45457 LD A,231 Read from the keyboard;
Port Number Bit
0 1 2 3 4
231 1 / 0 2 / 9 3 / 8 4 / 7 5 / 6
45459 CALL ReadKeys
45462 AND 31 Jump if none of the number keys is pressed.
45464 JR Z,ReadKeyboard_Store
45466 SET 6,C Set the bit for the action key.
ReadKeyboard_Store 45468 LD A,C Fetch the controls...
45469 LD (38437),A ...and store them.
45472 POP BC Restore BC.
45473 LD C,A Return the controls in C as well.
45474 RET Return.
Prev: 45315 Up: Map Next: 45475