| Routines

6496: Guide a character to a location on the same floor

Used by the routine at 63BE when the character under consideration is on the same floor as his destination.
Input
DE | Character's coordinates
H | Character number (0x98-0xA9)
L | 0x65
6496 | INC L | Point HL at the destination x-coordinate
6497 | LD A,E | A=character's current x-coordinate
6498 | CP (HL) | Is the character at the destination?
6499 | JR NZ,$64A5 | Jump if not
649B | LD L,$60 | Byte 0x60 holds the character's animatory state
649D | BIT 0,(HL) | Is the character midstride?
649F | JP Z,$62A8 | Move to the next command in the command list if not
64A2 | JP $641B | Otherwise finish the stride
The character hasn't reached his destination yet. Figure out his next move.
64A5 | LD A,D | A=character's y-coordinate
64A6 | CP $A9 | Set the zero flag if the character is on the bottom floor
64A8 | LD A,(HL) | A=destination x-coordinate
64A9 | JP Z,$641B | Jump if the character is on the bottom floor
The character is on the middle floor or the top floor. But which side of the wall?
64AC | LD A,D | A=character's y-coordinate
64AD | CP $9B | Set the zero flag if the character is on the top floor
64AF | LD A,$39 | This is the x-coordinate of the wall between the Map and Reading Rooms
64B1 | JR Z,$64B5 | Jump if the character is on the top floor
64B3 | LD A,$26 | This is the x-coordinate of the wall between the White and Exam Rooms
64B5 | CP E | Is the character to the left of the wall?
64B6 | JR NC,$64C0 | Jump if so
The character is on the right side of the wall.
64B8 | CP (HL) | Compare the wall's x-coordinate (in A) with the destination x-coordinate
64B9 | LD A,(HL) | A=destination x-coordinate
64BA | JP C,$641B | Jump if the character doesn't need to go down the stairs
64BD | JP $63F6 | Send the character to the top of the staircase
The character is on the left side of the wall.
64C0 | CP (HL) | Compare the wall's x-coordinate (in A) with the destination x-coordinate
64C1 | LD A,(HL) | A=destination x-coordinate
64C2 | JP NC,$641B | Jump if the character doesn't need to go down the stairs
64C5 | LD A,$0C | This is the x-coordinate of the tops of the staircases at the left of the skool
64C7 | JP $63F8 | Send the character to the top of the staircase