|  | Routines | 
| Prev: 6337 | Up: Map | Next: 651E | 
| 
Used by the routine at 6337.
 | ||||
| 63DA | LD A,($6DBE) | Pick up the guard's return delay counter. | ||
| 63DD | AND A | Has this guard been thrown out of the park? | ||
| 63DE | RET NZ | Return if so. | ||
| 63DF | LD HL,($7C6B) | Pick up Horace's current location. | ||
| 63E2 | RR H | Now H=0, 1 or 2, indicating which third of the screen the top row of Horace's sprite is in. | ||
| 63E4 | RR H | |||
| 63E6 | RR H | |||
| 63E8 | LD B,$05 | Move bits 5-7 of L down to bits 0-2, and bits 0-2 of H into bits 3-5 of L. | ||
| 63EA | RR H | |||
| 63EC | RR L | |||
| 63EE | DJNZ $63EA | |||
| 63F0 | LD A,L | Now A=Horace's screen y-coordinate (0-22). | ||
| 63F1 | AND $1F | |||
| 63F3 | LD HL,($7C6B) | Pick up Horace's current location. | ||
| 63F6 | LD H,A | H=Horace's screen y-coordinate (0-22). | ||
| 63F7 | LD A,L | Now L=Horace's screen x-coordinate (0-30). | ||
| 63F8 | AND $1F | |||
| 63FA | LD L,A | |||
| 63FB | LD ($7C7A),HL | Save Horace's screen x- and y-coordinates temporarily. | ||
| 63FE | LD HL,($6DB8) | Compute the guard's screen x- and y-coordinates. | ||
| 6401 | RR H | |||
| 6403 | RR H | |||
| 6405 | RR H | |||
| 6407 | LD B,$05 | |||
| 6409 | RR H | |||
| 640B | RR L | |||
| 640D | DJNZ $6409 | |||
| 640F | LD A,L | |||
| 6410 | AND $1F | |||
| 6412 | LD HL,($6DB8) | |||
| 6415 | LD H,A | |||
| 6416 | LD A,L | |||
| 6417 | AND $1F | |||
| 6419 | LD L,A | |||
| 641A | LD ($6DB0),HL | Save the guard's screen x- and y-coordinates temporarily. | ||
| 641D | LD B,$04 | Initialise B (the direction indicator) for the loop that follows. | ||
| 
Four passes are made through the following loop, one for each direction the guard might go: left, down, right, or up.
 | ||||
| 641F | DEC B | B=3 (left), 2 (down), 1 (right) or 0 (up). | ||
| 6420 | LD HL,($6DB8) | Pick up the guard's current location. | ||
| 6423 | LD C,$00 | Initialise C to 0; this is the direction probability parameter. | ||
| 6425 | PUSH BC | Save the direction indicator briefly. | ||
| 6426 | LD A,B | Copy the direction indicator to A. | ||
| 6427 | CALL $6CC2 | Check the tiles next to the guard in that direction. | ||
| 642A | POP BC | Restore the direction indicator to B. | ||
| 642B | CP $02 | Is there a wall or the maze exit or entrance in that direction? | ||
| 642D | JP NC,$64C3 | Jump if so with C=0: that direction is blocked. | ||
| 6430 | LD C,$19 | C=25; this value determines the base probability that the guard will turn 90 degrees in the direction indicated by B when his path is blocked. | ||
| 6432 | LD A,($6DBA) | Pick up the guard's animation frame. | ||
| 6435 | CP B | Is it equal to the current value of the direction indicator? | ||
| 6436 | JR NZ,$643E | Jump if not. | ||
| 6438 | LD A,$28 | C=65; this value ensures that the guard will keep moving in the same direction if he can. | ||
| 643A | ADD A,C | |||
| 643B | LD C,A | |||
| 643C | JR $645B | |||
| 643E | ADD A,$02 | Add 2 to the guard's current animation frame; this has the effect of toggling his direction between up/down and left/right. | ||
| 6440 | AND $03 | |||
| 6442 | CP B | Is it equal to the current value of the direction indicator now? | ||
| 6443 | JR NZ,$644B | Jump if not. | ||
| 6445 | LD A,$F6 | C=15; this value determines the probability that the guard will turn round 180 degrees when his path is blocked. | ||
| 6447 | ADD A,C | |||
| 6448 | LD C,A | |||
| 6449 | JR $645B | |||
| 644B | LD HL,($5C78) | Increment the two least significant bytes of the system variable FRAMES, and copy the value to HL. | ||
| 644E | INC HL | |||
| 644F | LD ($5C78),HL | |||
| 6452 | LD A,H | Use this value to generate a pseudo-random number between 0 and 31. | ||
| 6453 | AND $0F | |||
| 6455 | LD H,A | |||
| 6456 | LD A,(HL) | |||
| 6457 | AND $1F | |||
| 6459 | ADD A,C | Add this to C, giving a number between 25 and 56; the higher this value, the more likely the guard will turn 90 degrees in the direction indicated by B when his path is blocked. | ||
| 645A | LD C,A | |||
| 645B | LD A,B | Copy the direction indicator to A. | ||
| 645C | CP $03 | Set the zero flag if we're considering 'left' at the moment. | ||
| 645E | LD A,($7C64) | Pick up the value of the redundant variable at 7C64. | ||
| 6461 | JR NZ,$6467 | Jump if we're considering 'right', 'up' or 'down' at the moment. | ||
| 6463 | DEC A | Decrement the redundant variable at 7C64. | ||
| 6464 | LD ($7C64),A | |||
| 6467 | AND A | This instruction is redundant. | ||
| 6468 | LD A,B | Copy the direction indicator to A. | ||
| 6469 | CP $00 | Are we considering 'up' at the moment? | ||
| 646B | JR NZ,$6473 | Jump if not. | ||
| 646D | LD A,($7C62) | Reset the redundant variable at 7C64 to the value of the game speed parameter. | ||
| 6470 | LD ($7C64),A | |||
| 6473 | LD A,B | Copy the direction indicator to A. | ||
| 6474 | CP $00 | Are we considering 'up' at the moment? | ||
| 6476 | JR NZ,$6484 | Jump if not. | ||
| 6478 | LD HL,($6DB0) | Pick up the guard's screen x- and y-coordinates. | ||
| 647B | LD A,H | A=guard's screen y-coordinate. | ||
| 647C | LD HL,($7C7A) | Pick up Horace's screen x- and y-coordinates. | ||
| 647F | SUB H | Is Horace's y-coordinate greater than the guard's? | ||
| 6480 | JR C,$64C3 | Jump if so. | ||
| 6482 | JR $64AE | Otherwise jump to increase the probability that the guard will move up (towards Horace). | ||
| 6484 | CP $01 | Are we considering 'right' at the moment? | ||
| 6486 | JR NZ,$6494 | Jump if not. | ||
| 6488 | LD HL,($7C7A) | Pick up Horace's screen x- and y-coordinates. | ||
| 648B | LD A,L | A=Horace's screen x-coordinate. | ||
| 648C | LD HL,($6DB0) | Pick up the guard's screen x- and y-coordinates. | ||
| 648F | SUB L | Is the guard's x-coordinate greater than Horace's? | ||
| 6490 | JR C,$64C3 | Jump if so. | ||
| 6492 | JR $64AE | Otherwise jump to increase the probability that the guard will move right (towards Horace). | ||
| 6494 | CP $02 | Are we considering 'down' at the moment? | ||
| 6496 | JR NZ,$64A4 | Jump if not. | ||
| 6498 | LD HL,($7C7A) | Pick up Horace's screen x- and y-coordinates. | ||
| 649B | LD A,H | A=Horace's screen y-coordinate. | ||
| 649C | LD HL,($6DB0) | Pick up the guard's screen x- and y-coordinates. | ||
| 649F | SUB H | Is the guard's y-coordinate greater than Horace's? | ||
| 64A0 | JR C,$64C3 | Jump if so. | ||
| 64A2 | JR $64AE | Otherwise jump to increase the probability that the guard will move down (towards Horace). | ||
| 64A4 | LD HL,($6DB0) | Pick up the guard's screen x- and y-coordinates. | ||
| 64A7 | LD A,L | A=guard's screen x-coordinate. | ||
| 64A8 | LD HL,($7C7A) | Pick up Horace's screen x- and y-coordinates. | ||
| 64AB | SUB L | Is Horace's x-coordinate greater than the guard's? | ||
| 64AC | JR C,$64C3 | Jump if so. | ||
| 64AE | AND A | This instruction is redundant. | ||
| 64AF | ADD A,$0A | Add 10 to A; the higher the value A holds now, the more likely the guard will move in the direction indicated by B (towards Horace). | ||
| 64B1 | PUSH AF | Save this probability modifier briefly. | ||
| 64B2 | PUSH HL | Save HL (unnecessarily). | ||
| 64B3 | LD HL,($6DAE) | Pick up the guard panic timer. | ||
| 64B6 | LD A,H | Set the zero flag unless the guards are panicking. | ||
| 64B7 | OR L | |||
| 64B8 | POP HL | Restore HL. | ||
| 64B9 | JR Z,$64C0 | Jump unless the guards are panicking. | ||
| 64BB | POP AF | Restore the probability modifier to A. | ||
| 64BC | NEG | Negate A, making it less likely that the guard will move in the direction indicated by B (towards Horace). | ||
| 64BE | JR $64C1 | |||
| 64C0 | POP AF | Restore the probability modifier to A. | ||
| 64C1 | ADD A,C | Now C holds the probability parameter for the direction indicated by B. | ||
| 64C2 | LD C,A | |||
| 64C3 | PUSH BC | Save the direction indicator briefly. | ||
| 64C4 | LD HL,$6DB2 | Point HL at one of the four slots at 6DB2. | ||
| 64C7 | LD C,B | |||
| 64C8 | LD B,$00 | |||
| 64CA | ADD HL,BC | |||
| 64CB | POP BC | Restore the direction indicator to B. | ||
| 64CC | LD A,C | Save the direction probability parameter in the appropriate slot. | ||
| 64CD | LD (HL),A | |||
| 64CE | INC B | Have we considered every direction yet? | ||
| 64CF | DEC B | |||
| 64D0 | JP NZ,$641F | Jump back if not. | ||
| 
Having computed a direction probability parameter for each of the four slots at 6DB2, we now use those values to determine the guard's next animation frame (and therefore direction of travel).
 | ||||
| 64D3 | XOR A | Compute in C the index of the slot that holds the largest number (0, 1, 2 or 3). | ||
| 64D4 | LD HL,$6DB6 | |||
| 64D7 | LD B,$04 | |||
| 64D9 | DEC B | |||
| 64DA | DEC HL | |||
| 64DB | CP (HL) | |||
| 64DC | JR NC,$64E0 | |||
| 64DE | LD A,(HL) | |||
| 64DF | LD C,B | |||
| 64E0 | INC B | |||
| 64E1 | DEC B | |||
| 64E2 | JR NZ,$64D9 | |||
| 64E4 | LD A,C | Update the guard's animation frame to this index value. | ||
| 64E5 | LD ($6DBA),A | |||
| 64E8 | LD A,($6DBA) | Pick up the guard's animation frame. | ||
| 64EB | LD HL,($6DB8) | Pick up the guard's current location. | ||
| 64EE | CALL $6CC2 | Check the tiles in front of the guard. | ||
| 64F1 | CP $00 | Is there anything in front of the guard? | ||
| 64F3 | JR Z,$650A | Jump if not. | ||
| 64F5 | CP $01 | Is the guard facing a tunnel entrance? | ||
| 64F7 | JR NZ,$6517 | Jump if not. (This jump is never made.) | ||
| 
The guard is about to enter a tunnel.
 | ||||
| 64F9 | LD BC,($6FCF) | Pick up the the tunnel offset. | ||
| 64FD | LD A,($6DBA) | Pick up the guard's animation frame. | ||
| 6500 | AND A | Is it 0 (going up)? | ||
| 6501 | JR Z,$6507 | Jump if so. | ||
| 6503 | SBC HL,BC | Subtract the tunnel offset from the guard's current location. | ||
| 6505 | JR $6508 | |||
| 6507 | ADD HL,BC | Add the tunnel offset to the guard's current location. | ||
| 6508 | JR $6513 | |||
| 650A | LD HL,($6DB8) | Pick up the guard's current location. | ||
| 650D | LD A,($6DBA) | Pick up the guard's animation frame. | ||
| 6510 | CALL $6D17 | Compute the guard's new location. | ||
| 6513 | LD ($6DBC),HL | Update the guard's location. | ||
| 6516 | RET | |||
| 
The guard has been left facing a wall or the maze entrance or exit (so he cannot move). This never happens, so the following code is never executed.
 | ||||
| 6517 | LD HL,($6DB8) | Pick up the guard's current location. | ||
| 651A | LD ($6DBC),HL | Set the guard's new location. | ||
| 651D | RET | |||
| Prev: 6337 | Up: Map | Next: 651E |