| Routines

F5CE: Guide a character across a floor to his destination

The address of this interruptible subcommand routine is placed into bytes 0x0E and 0x0F of a character's buffer by the routine at F600. It guides the character left or right across the floor of a building to his final destination.
Input
H | Character number (0xD7-0xE5)
F5CE | LD BC,$F4E6 | Point BC at the routine at F4E6
This entry point is used by the unused routine at F5F6 (with BC=F5A0) and by the routine at F5FB (with BC=F5EE: RET).
F5D1 | LD L,$00 | Point HL at byte 0x00 of the character's buffer
F5D3 | BIT 0,(HL) | Is the character midstride?
F5D5 | JP NZ,$EC5A | If so, move the character from the midstride position and update the SRB
F5D8 | LD L,$03 | Has this character's command list been marked for a restart?
F5DA | BIT 4,(HL)
F5DC | JP NZ,$F284 | Terminate this subcommand if so (this jump is never made because bit 4 of byte 0x03 is unused)
F5DF | LD L,$01 | Collect the character's x-coordinate from byte 0x01 of his buffer
F5E1 | LD A,(HL)
F5E2 | LD L,$10 | Compare this with the character's intermediate or final destination x-coordinate
F5E4 | CP (HL)
F5E5 | JP Z,$F284 | Terminate this subcommand if they match
F5E8 | PUSH AF | Save the carry flag
F5E9 | LD DE,$F5EF | Push the address of the instruction at F5EF (below) onto the stack
F5EC | PUSH DE
F5ED | PUSH BC | Make an indirect jump to the routine whose address is in BC, and then return to F5EF (below)
F5EE | RET
F5EF | POP AF | Restore the carry flag
F5F0 | JP C,$EBAE | Make the character move right if he's to the left of his intermediate or final destination
F5F3 | JP $EBBB | Otherwise make the character move left