| Routines

31768: Move a character looking for ERIC to the midstride position

Continues from 31648. Moves the character looking for ERIC to the midstride position in the appropriate direction.
Input
A | 1 if the character's going upstairs, 2 if going down
BC | 0
DE | 0
H | Number of the character looking for ERIC (161, 163-166)
L | 96
The main entry point is used when the character is on a staircase.
31768 | INC B | B=1
31769 | DEC A | Is the chaser going downstairs?
31770 | JR NZ,31774 | Jump if so
31772 | DEC B | B=0
31773 | DEC D | D=-1
31774 | INC C | C=1
31775 | BIT 7,(HL) | Is the chaser facing right?
31777 | JR NZ,31781 | Jump if so
31779 | DEC C | C=-1
31780 | DEC C
This entry point is used by the routine at 31648 when the character looking for ERIC is not on a staircase; in this case B=D=E=0, and C=-1 if the chaser is to ERIC's left, or 1 if he is to ERIC's right.
31781 | LD L,107 | C=-1 if the chaser is to ERIC's left, or 1 if to his right; B=1 if the chaser is going downstairs, 0 otherwise; place these values into bytes 107 and 108 of the chaser's buffer
31783 | LD (HL),C
31784 | INC L
31785 | LD (HL),B
31786 | LD L,105 | Change the interruptible subcommand routine address in bytes 105 and 106 of the chaser's buffer from 31648 to 31739
31788 | LD (HL),251
31790 | PUSH DE | Save the x- and y-coordinate increments for the chaser's next move
31791 | CALL 25108 | Update the SRB for the chaser's current location
31794 | INC A | A=chaser's next animatory state (midstride)
31795 | LD L,A | Store this in L briefly
31796 | POP BC | Get the appropriate y- and x-coordinate increments for the chaser's move to the midstride position in BC
31797 | LD A,B | Get the chaser's new y-coordinate in D (which is the same as his current y-coordinate unless he's going up a staircase)
31798 | ADD A,D
31799 | LD D,A
31800 | LD A,C | Get the chaser's new x-coordinate in E (which is the same as his current x-coordinate, because C is always 0)
31801 | ADD A,E
31802 | LD E,A
31803 | LD A,L | Restore the chaser's new animatory state to A
31804 | JP 25008 | Update the chaser's animatory state and location and update the SRB