| Routines

76BC: Deal with a character who is at the entrance to a building

Used by the routine at EBBB. On entry, the bit set in A indicates the direction in which the character is going to move next:
Bit | Direction
--- | ---
7 | Left
6 | Right
5 | Up and to the left
4 | Up and to the right
3 | Down and to the left
2 | Down and to the right
Also on entry, the zero flag is set if the character is indoors. If the character is Sam, we also check whether he's entering a house other than no. 19 without a key.
Input
A | Direction indicator (0x80, 0x40, 0x20, 0x10, 0x08 or 0x04)
B | Third byte of the character's location descriptor (see EB13)
H | Character number (0xD7-0xE6)
L | 4
76BC | JR NZ,$76C2 | Jump unless the character is indoors
76BE | AND B | Is the character going to leave the building?
76BF | RET NZ | Return if not
76C0 | INC (HL) | Set the character's z-coordinate to 2
76C1 | RET |
76C2 | AND B | Is the character going to enter the building?
76C3 | JR Z,$76C0 | Jump if not
76C5 | LD A,H | A=character number
76C6 | CP $E6 | Is this Sam?
76C8 | RET NZ | Return if not
76C9 | BIT 0,B | Does the entrance have a door?
76CB | RET Z | Return if not
76CC | CALL $F293 | Point HL at the status flags for the door that Sam is standing next to (see 7FF0)
76CF | LD A,L | A=LSB of the address of the door status flags (0xF0-0xF9)
76D0 | CP $F5 | Is Sam standing in the doorway of no. 19?
76D2 | JR Z,$76D7 | Jump if so
76D4 | LD A,(HL) | Pick up the door status flags for the doorway Sam is standing in
76D5 | AND $F8 | Set the zero flag if the door requires no key to unlock it
76D7 | LD H,$E6 | 0xE6=Sam
76D9 | RET Z | Return if the door requires no key to unlock it
76DA | JP $7A39 | Check whether Sam has entered a house through the front door without a key