| Routines

65D4: Check whether a character is beside a chair

Used by the routines at 6697, 7974 and F3FC. The value returned in A is as follows:
A | Meaning
--- | ---
0x00 | Character is facing left and standing beside a chair
0x03 | Character must walk to the next chair to the left
0x04 | Character must walk to the rightmost chair
0xFF | Character is not in a classroom
Input
H | Character number (0xB7-0xD2)
65D4 | LD L,$02 | Point HL at byte 0x02 of the character's buffer
65D6 | LD A,(HL) | A=character's y-coordinate
65D7 | LD DE,$D332 | The table at D332 contains the x-coordinates of the left ends of the classrooms
65DA | LD B,$03 | There are three sets of chairs on the top floor
65DC | CP B | Is the character on the top floor?
65DD | JR Z,$65E6 | Jump if so
65DF | DEC B | B=2 (two sets of chairs on the middle floor)
65E0 | CP $0A | Is the character on the middle floor?
65E2 | JR NZ,$65F5 | Jump if not
65E4 | LD E,$35 | DE=D335
65E6 | DEC L |
65E7 | LD A,(HL) | A=character's x-coordinate
65E8 | EX DE,HL | HL=D332 if the character is on the top floor, D335 if he's on the middle floor
65E9 | CP (HL) | Is the character to the left of this classroom?
65EA | JR C,$65F1 | Jump if so
65EC | INC H | Point HL at the x-coordinate of the right end of the classroom (in the table at D432)
65ED | CP (HL) | Is the character in this classroom?
65EE | JR C,$65F8 | Jump if so
65F0 | DEC H |
65F1 | INC L |
65F2 | DJNZ $65E9 |
65F4 | EX DE,HL |
65F5 | LD A,$FF | Signal: the character is not in a classroom
65F7 | RET |
The character is in a classroom. But is he beside a chair?
65F8 | INC H | Point HL at the x-coordinate of the leftmost seat in the classroom (in the table at D532)
65F9 | CP (HL) | Is the character to the right of the leftmost chair?
65FA | JR NC,$6600 | Jump if so
65FC | LD A,$04 | Signal: the character must walk to the rightmost chair
65FE | EX DE,HL |
65FF | RET |
6600 | INC H | Point HL at the x-coordinate of the rightmost seat in the classroom (in the table at D632)
6601 | CP (HL) | Is the character to the left of the rightmost chair?
6602 | JR C,$6608 | Jump if so
6604 | LD A,$03 | Signal: the character must walk to the next chair to the left
6606 | EX DE,HL |
6607 | RET |
The character is between the leftmost and rightmost chairs in the classroom.
6608 | DEC E | E=0
6609 | LD A,(DE) | A=character's animatory state
660A | INC E | E=1
660B | RLCA |
660C | JR C,$65FC | Jump if the character is facing right
660E | LD A,(DE) | A=character's x-coordinate
660F | XOR (HL) | The chairs in a classroom have either all odd or all even x-coordinates; is the character standing beside one?
6610 | RRCA
6611 | JR NC,$6604 | Jump if not
6613 | EX DE,HL |
6614 | XOR A | Signal: the character is facing left and standing beside a chair
6615 | RET |
The contents of the classroom/chairs location tables are as follows:
Room | Chairs
--- | ---
0 | 23 | 11 | 22 | Blue Room
40 | 63 | 50 | 61 | Yellow Room
159 | 180 | 168 | 179 | Top-floor room in the girls' skool
30 | 54 | 40 | 53 | Science Lab
159 | 179 | 167 | 178 | Middle-floor room in the girls' skool