| Routines

6618: Check whether a chair is occupied

Used by the routine at 663F. Returns with the zero flag set if the chair beside the character looking for a seat is already occupied by one of the potential occupants being checked.
Input
B | Number of potential occupants to check
C | Animatory state mask (0x87 or 0x8F)
D | Number of the first potential occupant to check
H | Number of the character looking for a seat (0xB7-0xD1)
L | 0x01
6618 | CALL $6621 | Are any of the first B potential occupants sitting here?
661B | RET Z | Return if so
661C | LD BC,$028F | B=0x02 (BOY WANDER and ANGELFACE), C=0x8F
661F | LD D,$CE | 0xCE=BOY WANDER
This entry point also is used by the routine at 663F.
6621 | LD E,$01 |
6623 | LD A,(DE) | A=x-coordinate of the potential occupant
6624 | CP (HL) | Compare with that of the character looking for a seat
6625 | JR NZ,$663B | Jump ahead to consider the next potential occupant if they don't match
6627 | INC E | E=0x02
6628 | INC L | L=0x02
6629 | LD A,(DE) | A=y-coordinate of the potential occupant
662A | DEC E | E=0x01
662B | CP (HL) | Compare with the y-coordinate of the character looking for a seat
662C | DEC HL | L=0x01
662D | JR NZ,$663B | Jump if the potential occupant is not in the same location as the character looking for a seat
662F | DEC E | E=0x00
6630 | LD A,(DE) | A=potential occupant's animatory state
6631 | AND C | Discard the character-identifying bits and keep only the 'direction' bit and 'action' bits (C=10001111 for BOY WANDER, ANGELFACE or ERIC, and 10000111 for anybody else)
6632 | CP $04 | Is the potential occupant sitting in the chair here?
6634 | JR NZ,$663B | Jump if not
6636 | LD E,$12 | Is there an uninterruptible subcommand routine address in bytes 0x11 and 0x12 of the potential occupant's buffer?
6638 | LD A,(DE)
6639 | AND A
663A | RET Z | Return if not
663B | INC D | Next potential occupant to test
663C | DJNZ $6621 | Jump back until done
663E | RET |