Routines

26068: Check if character is beside a chair


Used by routines at 26263, 31092 and 62460

H Character number (183-210)

The value returned in A is as follows:
0 Character is facing left and standing beside a chair
3 Character must walk to the next chair to the left
4 Character must walk to the rightmost chair
255 Character is not even in a classroom

26068 2E02 LD L,2
26070 7E LD A,(HL) A=character's y-coordinate
26071 1132D3 LD DE,54066 DE points to the classroom/chairs location table (see below)
26074 0603 LD B,3 Three sets of chairs on the top floor
26076 B8 CP B Is the character on the top floor?
26077 2807 JR Z,26086 Jump if so
26079 05 DEC B B=2 (two sets of chairs on the middle floor)
26080 FE0A CP 10 Is the character on the middle floor?
26082 2011 JR NZ,26101 Jump if not
26084 1E35 LD E,53 DE=54069
26086 2D DEC L
26087 7E LD A,(HL) A=character's x-coordinate
26088 EB EX DE,HL
26089 BE CP (HL) Is the character to the left of this classroom?
26090 3805 JR C,26097 Jump if so
26092 24 INC H
26093 BE CP (HL) Is the character in this classroom?
26094 3808 JR C,26104 Jump if so
26096 25 DEC H
26097 2C INC L
26098 10F5 DJNZ 26089
26100 EB EX DE,HL
26101 3EFF LD A,255 Signal: character is not even in a classroom
26103 C9 RET

The character is in a classroom. But is he beside a chair?
26104 24 INC H
26105 BE CP (HL) Is the character to the right of the leftmost chair?
26106 3004 JR NC,26112 Jump if so
26108 3E04 LD A,4 Signal: character must walk to the rightmost chair
26110 EB EX DE,HL
26111 C9 RET
26112 24 INC H
26113 BE CP (HL) Is the character to the left of the rightmost chair?
26114 3804 JR C,26120 Jump if so
26116 3E03 LD A,3 Signal: character must walk to the next chair to the left
26118 EB EX DE,HL
26119 C9 RET

The character is between the leftmost and rightmost chairs in the classroom.
26120 1D DEC E E=0
26121 1A LD A,(DE) A=character's animatory state
26122 1C INC E
26123 07 RLCA
26124 38EE JR C,26108 Jump if the character is facing right
26126 1A LD A,(DE) A=character's x-coordinate
26127 AE XOR (HL) The chairs in a classroom have either all odd or all even x-coordinates. Is the character standing beside one?
26128 0F RRCA
26129 30F1 JR NC,26116 Jump if not
26131 EB EX DE,HL
26132 AF XOR A Signal: character is beside a chair
26133 C9 RET

The contents of the classroom/chairs location table are as follows:
Room Chairs
D=211 D=212 D=213 D=214 Room
E=50 0 23 11 22 Blue room
E=51 40 63 50 61 Yellow room
E=52 159 180 168 179 Top-floor room in girls' skool
E=53 30 54 40 53 Science lab
E=54 159 179 167 178 Middle-floor room in girls' skool