Routines
 Prev: 64D7 Up: Map Next: 6554
64F3: Determine the next move of a character following another character
Used by the routines at 6558 and F413. Returns with one of the following values in bits 0-2 of A depending on the relative locations of the follower and his target:
A Meaning
0 Follower is at the same coordinates as the target
1 Follower should go (or continue going) upstairs
2 Follower should go (or continue going) downstairs
3 Follower should go left
4 Follower should go right
In addition, bit 3 of A will be set if the follower is facing a closed door, and C will hold the identifier of the closed door (see 7040).
Input
DE Target character's coordinates
H Follower's character number (0xC8-0xCC, 0xD2)
64F3 PUSH DE Save the target coordinates temporarily
64F4 CALL \$6E52 Is the follower on a staircase?
64F7 JR NC,\$6504 Jump if not
The follower is on a staircase. At this point, A=0x00 if the staircase goes up and to the left, 0x80 (bit 7 set) if it goes up and to the right.
64F9 LD L,\$00 Point HL at byte 0x00 of the character's buffer
64FB XOR (HL) Compare the staircase's direction with the follower's
64FC RLCA Set the carry flag if the character is descending the staircase
64FD LD A,\$01 A=1 if the follower is ascending the staircase, 2 if descending
6501 POP DE Restore the target coordinates to DE
6502 SCF Signal: follower is on a staircase (this is ignored by both callers)
6503 RET
The follower is not on a staircase.
6504 CALL \$63D2 Get the region identifier for the follower's current location
6507 LD L,A Copy this to L
6508 POP DE Restore the target coordinates to DE
6509 CALL \$63D2 Get the region identifier for the target coordinates
650C CP L Compare the current and target regions
650D LD D,L D=region ID for the follower's current location
650E LD L,\$01 Point HL at byte 0x01 of the follower's buffer
6510 JR NZ,\$6535 Jump if the follower is not in the same region as his target
6512 LD A,E A=target x-coordinate
6513 SUB (HL) Is the follower in exactly the same location as his target?
6514 RET Z Return if so (with the carry flag reset)
The follower is in the same region as his target, but still has some walking to do. At this point the carry flag is set if the follower is to the right of his target, and reset if he's to the left.
6515 SBC A,A A=3 if the follower must go left, 4 if right to reach the target
6518 PUSH AF Save this value briefly
6519 LD L,\$00 Point HL at byte 0x00 of the follower's buffer
651B RRCA Set bit 7 of A if the follower is facing the right way to reach his target
651C XOR (HL)
651D RLCA Push bit 7 of A into the carry flag
651E JR C,\$6523 Jump if the follower is facing the right way to reach his target
6520 POP AF A=3 (go left) or 4 (go right)
6521 AND A Clear the carry flag (the follower is not on a staircase)
6522 RET
The follower is in the same region as his target, and is facing the right way to reach him. But are there any doors in the way?
6523 CALL \$705F Check for closed doors in front of the follower
6526 JR NC,\$6520 Jump if there are none
6528 LD A,H A=follower's character number
6529 CP \$D2 Is this ERIC (in demo mode)?
652B JR NZ,\$6531 Jump if not
652D POP AF A=3 (go left) or 4 (go right)
652E XOR \$07 3 (go left) becomes 4 (go right) and vice versa for ERIC
6530 RET Return with the carry flag reset and C holding the door identifier
6531 POP AF A=3 (go left) or 4 (go right)
6534 RET Return with the carry flag reset and C holding the door identifier
The follower is not in the same region as his target. This means at least one visit to a staircase first.
6535 SUB \$81 A=identifier of the top or bottom of the staircase (see 6464)
6537 LD E,A
6538 LD A,(DE)
6539 LD D,A A=x-coordinate of the top or bottom of the staircase the follower will have to go to first in order to reach his target
653A LD E,\$44
653C LD A,(DE)
653D CP (HL) Is the follower standing at this staircase already?
653E JR NZ,\$6513 Jump if not
The follower is at the top or bottom of the first staircase he must negotiate in order to reach his target. Is he facing the right way to begin his ascent or descent?
6540 INC E Point DE at the staircase direction indicator
6541 DEC L Point HL at byte 0x00 of the character's buffer
6542 LD A,(DE) A=0x00 if the follower must face left to negotiate the stairs, 0x80 (bit 7 set) if right
6543 XOR (HL) Set the carry flag if the follower is facing the wrong way
6544 RLCA
6545 JR NC,\$654E Jump if the follower is facing the right way to negotiate the stairs
6547 LD A,(HL) A=follower's animatory state
6548 RLCA A=3 if the follower's facing right, 4 if facing left
6549 SBC A,A