Prev: 6229 Up: Map Next: 6337
624F: Read the keyboard and update Horace's sprite accordingly
Called from the main loop at 6229.
624F LD A,($7C79) Pick up the tunnel timer.
6252 AND A Is Horace in a tunnel at the moment?
6253 RET NZ Return if so.
6254 LD A,$FF Initialise the direction keypress to 'no key'.
6256 LD ($7C6F),A
6259 LD A,($6B0B) Pick up the game mode indicator.
625C AND A Is it demo mode?
625D JR NZ,$62C4 Jump if not.
625F LD A,$00 Read the keyboard.
6261 IN A,($FE)
6263 AND $1F Is a key being pressed?
6265 CP $1F
6267 JR Z,$626D Jump if not.
6269 POP HL Drop the return address from the stack.
626A JP $67E9 Cycle the screen colours briefly and return to the title screen.
It's demo mode. Time to figure out where to move Horace next.
626D LD B,$04 Initialise B (the direction indicator) for the loop that follows.
626F DEC B B=3 (left), 2 (down), 1 (right) or 0 (up).
6270 LD HL,($7C6B) Pick up Horace's current location.
6273 LD C,$00 Initialise C to 0; this is the direction probability parameter.
6275 PUSH BC Save the direction indicator briefly.
6276 LD A,B Copy the direction indicator to A.
6277 CALL $6CC2 Check the tiles next to Horace in that direction.
627A POP BC Restore the direction indicator to B.
627B CP $02 Is there a wall or the maze exit or entrance in that direction?
627D JP NC,$629F Jump if so with C=0: that direction is blocked.
6280 CALL $6B12 Set C to a pseudo-random number between 25 and 56; the higher this value, the more likely Horace will turn 90 degrees in the direction indicated by B when his path is blocked.
6283 AND $1F
6285 ADD A,$19
6287 LD C,A
6288 LD A,($7C70) Pick up Horace's animation frame.
628B CP B Is it equal to the current value of the direction indicator?
628C JR NZ,$6294 Jump if not.
628E LD A,$28 Now C holds a pseudo-random number between 65 and 96; this value ensures that Horace will keep moving in the same direction if he can.
6290 ADD A,C
6291 LD C,A
6292 JR $629F
6294 ADD A,$02 Add 2 to Horace's animation frame; this has the effect of toggling his direction between up/down and left/right.
6296 AND $03
6298 CP B Is it equal to the current value of the direction indicator now?
6299 JR NZ,$629F Jump if not.
629B LD A,$F6 Now C holds a pseudo-random number between 15 and 46; the higher this value, the more likely Horace will turn round 180 degrees when his path is blocked.
629D ADD A,C
629E LD C,A
629F PUSH BC Save the direction indicator briefly.
62A0 LD HL,$6DB2 Point HL at one of the four slots at 6DB2.
62A3 LD C,B
62A4 LD B,$00
62A6 ADD HL,BC
62A7 POP BC Restore the direction indicator to B.
62A8 LD A,C Save the direction probability parameter in the appropriate slot.
62A9 LD (HL),A
62AA INC B Have we considered every direction yet?
62AB DEC B
62AC JR NZ,$626F Jump back if not.
Having computed a direction probability parameter for each of the four slots at 6DB2, we now use those parameters to determine Horace's next animation frame (and therefore direction of travel).
62AE XOR A Compute in C the index of the slot that holds the largest number (0, 1, 2 or 3).
62AF LD HL,$6DB6
62B2 LD B,$04
62B4 DEC B
62B5 DEC HL
62B6 CP (HL)
62B7 JR NC,$62BB
62B9 LD A,(HL)
62BA LD C,B
62BB INC B
62BC DEC B
62BD JR NZ,$62B4
62BF LD A,C Update Horace's animation frame to this index value.
62C0 LD ($7C70),A
62C3 RET
A game is in progress.
62C4 LD A,$FB Read keys Q-W-E-R-T.
62C6 IN A,($FE)
62C8 AND $01 Is 'Q' (up) being pressed?
62CA JR Z,$62D4 Jump if so.
62CC LD A,$F7 Read keys 1-2-3-4-5.
62CE IN A,($FE)
62D0 AND $08 Is '4' (up) being pressed?
62D2 JR NZ,$62DB Jump if not.
62D4 LD A,$00 Signal: 'up' key pressed.
62D6 LD ($7C6F),A
62D9 JR $631E
62DB LD A,$FE Read keys SHIFT-Z-X-C-V.
62DD IN A,($FE)
62DF AND $02 Is 'Z' (down) being pressed?
62E1 JR Z,$62EB Jump if so.
62E3 LD A,$F7 Read keys 1-2-3-4-5.
62E5 IN A,($FE) Is '3' (down) being pressed?
62E7 AND $04 Jump if not.
62E9 JR NZ,$62F2
62EB LD A,$02 Signal: 'down' key pressed.
62ED LD ($7C6F),A
62F0 JR $631E
62F2 LD A,$DF Read keys Y-U-I-O-P.
62F4 IN A,($FE)
62F6 BIT 0,A Is 'P' (right) being pressed?
62F8 JR Z,$6302 Jump if so.
62FA LD A,$F7 Read keys 1-2-3-4-5.
62FC IN A,($FE)
62FE AND $02 Is '2' (right) being pressed?
6300 JR NZ,$6309 Jump if not.
6302 LD A,$01 Signal: 'right' key pressed.
6304 LD ($7C6F),A
6307 JR $631E
6309 LD A,$DF Read keys Y-U-I-O-P.
630B IN A,($FE)
630D BIT 2,A Is 'I' (left) being pressed?
630F JR Z,$6319 Jump if so.
6311 LD A,$F7 Read keys 1-2-3-4-5.
6313 IN A,($FE)
6315 AND $01 Is '1' (left) being pressed?
6317 JR NZ,$632D Jump if not.
6319 LD A,$03 Signal: 'left' key pressed.
631B LD ($7C6F),A
631E LD HL,($7C6B) Pick up Horace's current location.
6321 CALL $6CC2 Check the tiles in front of Horace.
6324 CP $03 Is Horace facing a wall?
6326 JR NZ,$632D Jump if not.
6328 LD A,$FF Signal: no key pressed (Horace will not respond to the keypress).
632A LD ($7C6F),A
632D LD A,($7C6F) Pick up the direction keypress indicator.
6330 CP $FF Was a direction key pressed?
6332 RET Z Return if not.
6333 LD ($7C70),A Otherwise update Horace's animation frame accordingly.
6336 RET
Prev: 6229 Up: Map Next: 6337