| Routines

6E9B: Check for walls and closed doors in front of ERIC

Used by the routines at 6F14 and 6F2C. Impedes ERIC's progress if he's confronted by an immovable object, or opens the Science Lab storeroom door (if ERIC has the key and is trying to go right at the relevant location). Also sends ERIC down the first step of the staircase leading down to the assembly hall stage, or begins his descent off the assembly hall stage (if ERIC is trying to go left at the relevant location).
Input
D | ERIC's y-coordinate
E | x-coordinate of the spot in front of ERIC
6E9B | LD A,E | A=x-coordinate of the spot in front of ERIC
6E9C | CP $BF | Is ERIC facing the far right wall of the girls' skool?
6E9E | RET NC | Return if so (ERIC can't walk through walls)
6E9F | LD HL,$7FF4 | 7FF4 holds the doors flags
6EA2 | LD A,D | A=ERIC's y-coordinate
6EA3 | CP $03 | Is ERIC on the top floor?
6EA5 | JR NZ,$6ECB | Jump if not
ERIC is on the top floor.
6EA7 | LD A,E | A=x-coordinate of the spot in front of ERIC
6EA8 | CP $9F | Is ERIC facing the far wall of the top-floor room in the girls' skool?
6EAA | RET Z | Return if so
6EAB | CP $5C | Is ERIC facing the window on the top floor of the boys' skool?
6EAD | RET Z | Return if so
6EAE | CP $48 | Is ERIC facing the head's left study door?
6EB0 | JR NZ,$6EB5 | Jump if not
6EB2 | BIT 0,(HL) | Is the head's left study door closed?
6EB4 | RET Z | Return if so
6EB5 | CP $53 | Is ERIC facing the head's right study door?
6EB7 | JR NZ,$6EBC | Jump if not
6EB9 | BIT 1,(HL) | Is the head's right study door closed?
6EBB | RET Z | Return if so
ERIC's path is not blocked, so let him move forward.
6EBC | LD A,($D200) | A=ERIC's animatory state
6EBF | LD C,E | Copy the coordinates of the spot in front of ERIC (his post-midstride coordinates) from DE to BC
6EC0 | LD B,D
6EC1 | BIT 7,A | Is ERIC facing right?
6EC3 | JR NZ,$6EC7 | Jump if so
6EC5 | INC E |
6EC6 | INC E |
6EC7 | DEC E | Set E to ERIC's current x-coordinate (which will also be his midstride x-coordinate)
6EC8 | JP $6DD2 | Put ERIC midstride
ERIC's not on the top floor. Is he on the middle floor?
6ECB | CP $0A | Is ERIC on the middle floor?
6ECD | JR NZ,$6EED | Jump if not
ERIC is on the middle floor.
6ECF | LD A,E | A=x-coordinate of the spot in front of ERIC
6ED0 | CP $9F | Is ERIC facing the far wall of the middle-floor classroom in the girls' skool?
6ED2 | RET Z | Return if so
6ED3 | CP $5E | Is ERIC facing the window on the middle floor of the boys' skool?
6ED5 | RET Z | Return if so
6ED6 | CP $3F | Is ERIC facing the far wall of the Science Lab storeroom?
6ED8 | RET Z | Return if so
6ED9 | CP $54 | Is ERIC about to descend the stairs from the middle floor to the stage?
6EDB | JR NZ,$6EE1 | Jump if not
6EDD | INC E | E=85 (ERIC's current x-coordinate)
6EDE | JP $6FBE | Start moving ERIC down a stair
6EE1 | CP $36 | Is ERIC facing the Science Lab storeroom door?
6EE3 | JR NZ,$6EBC | Jump if not
6EE5 | BIT 2,(HL) | Is the Science Lab storeroom door closed?
6EE7 | JP Z,$73F1 | Jump if so (and open it if ERIC has the key)
6EEA | RET Z | Return if the door/gate is (still) closed
6EEB | JR $6EBC | Otherwise move ERIC forward
ERIC's not on the top floor or the middle floor. Is he on the bottom floor?
6EED | CP $11 | Is ERIC on the bottom floor?
6EEF | LD A,E | A=x-coordinate of the spot in front of ERIC
6EF0 | JR NZ,$6F05 | Jump if not
ERIC is on the bottom floor.
6EF2 | CALL $7166 | Let ERIC go no further if ALBERT's in his way
6EF5 | LD A,E | A=x-coordinate of the spot in front of ERIC
6EF6 | CP $5E | Is ERIC facing the boys' skool door?
6EF8 | JR NZ,$6EFD | Jump if not
6EFA | BIT 3,(HL) | Is the boys' skool door closed?
6EFC | RET Z | Return if so
6EFD | CP $85 | Is ERIC facing the skool gate?
6EFF | JR NZ,$6EBC | Jump if not
6F01 | BIT 4,(HL) | Is the skool gate closed?
6F03 | JR $6EEA | Jump back and return if so, or move ERIC forward if not
ERIC is on the assembly hall stage.
6F05 | CP $52 | Is ERIC about to ascend the stairs from the stage to the middle floor?
6F07 | JR NZ,$6F0D | Jump if not
6F09 | DEC E | E=81 (ERIC's current x-coordinate)
6F0A | JP $6F62 | Start moving ERIC up a stair
6F0D | CP $4C | Is ERIC about to jump off the stage?
6F0F | JP Z,$6E91 | Jump if so to deal with ERIC's descent to the floor
6F12 | JR $6EBC | Otherwise move ERIC forward