Prev: 6B96 Up: Map Next: 6BE5
6B97: Check whether a chair is occupied and unseat any occupant
Used by the routine at 6B7D. Returns with the carry flag reset if the chair next to the character looking for a seat is not occupied by any of the potential occupants being checked. Otherwise knocks the occupant out of the chair and returns with the carry flag set.
Input
B Number of potential occupants to check (11, 3, or 1)
D Number of the first potential occupant to check (0x98, 0xA7, or 0xAC)
H Number of the character looking for a seat (0x98-0xA9)
6B97 LD L,$62 Byte 0x62 of a character's buffer holds his x-coordinate
6B99 LD E,L
6B9A LD A,(DE) A=x-coordinate of the potential dethronee
6B9B CP (HL) Do the x-coordinates match?
6B9C JR NZ,$6BAC Jump ahead to consider the next character if not
6B9E DEC E E=L=0x61 (which byte holds the character's y-coordinate)
6B9F DEC L
6BA0 LD A,(DE) A=y-coordinate of the potential dethronee
6BA1 CP (HL) Do the y-coordinates match?
6BA2 JR NZ,$6BAC Jump ahead to consider the next character if not
6BA4 DEC E E=0x60
6BA5 LD A,(DE) A=animatory state of the potential dethronee
6BA6 AND $0F
6BA8 CP $05 Is this character sitting in the chair?
6BAA JR Z,$6BB1 Dethrone him if so
6BAC INC D Next character to check
6BAD DJNZ $6B97 Jump back until all potential dethronees have been checked
6BAF AND A Return with the carry flag reset to indicate that no one was knocked out of the chair
6BB0 RET
6BB1 LD A,D A=number of the character sitting in the chair
6BB2 CP $AC Is ERIC sitting here?
6BB4 JR NZ,$6BD1 Jump if not
6BB6 LD DE,$7FFB 7FFB holds ERIC's status flags
6BB9 EX DE,HL
6BBA SET 4,(HL) Signal: ERIC has been knocked out of his chair
6BBC EX DE,HL
This entry point is used by the routine at 6B7D to make the chair-seeking character sit down after having found a vacant seat.
6BBD LD L,$70 Remove the uninterruptible subcommand routine address from bytes 0x6F and 0x70 of the buffer of the character who is going to sit down
6BBF LD (HL),$00
6BC1 LD L,$60 A=this character's current animatory state
6BC3 LD A,(HL)
6BC4 AND $F8 Set A to the animatory state of this character sitting in a chair
6BC6 ADD A,$05
6BC8 INC L Pick up the character's coordinates in DE
6BC9 LD D,(HL)
6BCA INC L
6BCB LD E,(HL)
6BCC CALL $61B0 Update the character's animatory state and update the SRB
6BCF SCF Return with the carry flag set to indicate that a character was pushed out of his chair
6BD0 RET
Someone is sitting in the chair, but it isn't ERIC.
6BD1 LD E,$70 Is there an uninterruptible subcommand routine address in bytes 0x6F and 0x70 of the seated character's buffer?
6BD3 LD A,(DE)
6BD4 AND A
6BD5 JR Z,$6BDD Jump if not
The current occupant of the chair must be in the process of being dethroned by someone else at the moment (i.e. bytes 0x6F and 0x70 of his buffer hold the address of the uninterruptible subcommand routine at 6C55). In that case, the chair-seeking character will give way to the dethroner and look for another chair.
6BD7 LD L,$60 A=current animatory state of the character who wants to sit down
6BD9 LD A,(HL)
6BDA INC A Put this character midstride; this has the effect of making him walk to the next chair
6BDB JR $6BC8
The current occupant of the chair can be dethroned. Make it so.
6BDD EX DE,HL
6BDE LD (HL),$6C Place the address of the uninterruptible subcommand routine at 6C55 into bytes 0x6F and 0x70 of the seated character's buffer
6BE0 DEC L
6BE1 LD (HL),$55
6BE3 JR $6BBC
Prev: 6B96 Up: Map Next: 6BE5