| Routines

63749: Check whether a character is in the correct spot to enter a building

Used by the routine at 60812. The character in question is standing outside the entrance to a shop or other building, and his destination is somewhere inside. This routine returns with the zero flag set if the character is standing in the correct spot (and facing the right way) to enter the building or knock on the door; otherwise it returns with the zero flag reset, and the carry flag reset if the character should move left, or set if he should move right in order to reach the correct spot.
Input
D | x-coordinate of the right edge of the doorway
H | Character number (215-230)
63749 | LD L,1 | Point HL at byte 1 of the character's buffer
63751 | LD A,D | A=x-coordinate of the right edge of the doorway
63752 | CP (HL) | Compare this with the character's x-coordinate
63753 | JR NZ,63763 | Jump unless they match
63755 | AND A | Is the character's x-coordinate 0 (meaning he is standing at the doorway of the shop at the far left of town)?
63756 | JR Z,63767 | Jump if so
63758 | DEC L | L=0
63759 | BIT 7,(HL) | Set the zero flag if the character is facing left
63761 | INC HL | Point HL at byte 1 of the character's buffer
63762 | RET | Return with the zero flag set if the character is facing left (he can enter or knock now); otherwise return with the zero flag reset and the carry flag reset (he should turn round first)
The character is not standing at the right edge of the doorway. Is he standing at the left edge?
63763 | DEC A | A=D-1 (x-coordinate of the left edge of the doorway)
63764 | CP (HL) | Compare this with the character's x-coordinate
63765 | CCF | Set the carry flag if the character's x-coordinate is less than D
63766 | RET NZ | Return with the zero flag reset (and the carry flag reset if the character's x-coordinate is at least D, set if it's less than D-1) if the character is not standing at the left edge of the doorway
The character is either standing at the doorway of the shop at the far left of town (at x-coordinate 0), or standing at the left edge of some other doorway.
63767 | DEC L | L=0
63768 | LD A,(HL) | A=character's animatory state
63769 | INC L | L=1
63770 | RLCA | Set the zero flag if the character is facing right; otherwise reset the zero flag and set the carry flag (the character should turn round first)
63771 | CCF
63772 | SBC A,A
63773 | RET |