Prev: F8AE Up: Map Next: F91E
F905: Check whether a character is in the correct spot to enter a building
Used by the routine at ED8C. 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 (0xD7-0xE6)
F905 LD L,$01 Point HL at byte 0x01 of the character's buffer
F907 LD A,D A=x-coordinate of the right edge of the doorway
F908 CP (HL) Compare this with the character's x-coordinate
F909 JR NZ,$F913 Jump unless they match
F90B 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)?
F90C JR Z,$F917 Jump if so
F90E DEC L L=0x00
F90F BIT 7,(HL) Set the zero flag if the character is facing left
F911 INC HL Point HL at byte 0x01 of the character's buffer
F912 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?
F913 DEC A A=D-1 (x-coordinate of the left edge of the doorway)
F914 CP (HL) Compare this with the character's x-coordinate
F915 CCF Set the carry flag if the character's x-coordinate is less than D
F916 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.
F917 DEC L L=0x00
F918 LD A,(HL) A=character's animatory state
F919 INC L L=0x01
F91A 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)
F91B CCF
F91C SBC A,A
F91D RET
Prev: F8AE Up: Map Next: F91E