| Routines

F4CC: Make ALBERT keep an eye out for ERIC during lessons

The address of this continual subcommand routine is placed into bytes 0x17 and 0x18 of ALBERT's buffer by command list 0x4C. Makes ALBERT raise his arm and alert MR WACKER if ERIC enters the 'danger zone' (within 6 spaces to the left of ALBERT). Also makes ALBERT lower his arm if ERIC leaves the danger zone.
Input
H | 0xCD (ALBERT)
F4CC | LD L,$00 | Point HL at byte 0x00 of ALBERT's buffer
F4CE | LD A,(HL) | A=ALBERT's animatory state
F4CF | OR $FA | Is ALBERT midstride or lying on his back?
F4D1 | RET PO | Return if so
F4D2 | LD DE,($D201) | Collect ERIC's coordinates in DE
F4D6 | LD A,D | A=ERIC's y-coordinate
F4D7 | CP $0E | Is ERIC above the level of the stage?
F4D9 | JR C,$F4EA | Jump if so
F4DB | LD A,E | A=ERIC's x-coordinate
F4DC | CP $60 | Is ERIC inside the boys' skool?
F4DE | JR C,$F4EA | Jump if so
F4E0 | LD L,$01 | Point HL at byte 0x01 of ALBERT's buffer
F4E2 | CP (HL) | Is ERIC to the left of ALBERT?
F4E3 | JR NC,$F4EA | Jump if not
F4E5 | ADD A,$06 | Is ERIC within 6 spaces to the left of ALBERT?
F4E7 | CP (HL)
F4E8 | JR NC,$F4F7 | Jump if so
ERIC's not in the danger zone. Make ALBERT lower his arm if he has it raised.
F4EA | LD L,$00 | Point HL at byte 0x00 of ALBERT's buffer
F4EC | LD A,(HL) | A=ALBERT's animatory state
F4ED | CP $7F | 0x7F: Is ALBERT facing left with his arm up?
F4EF | RET NZ | Return if not
F4F0 | POP BC | Drop the return address (6357) from the stack
F4F1 | POP BC | Drop the character buffer reference used by the routine at 62D0
F4F2 | LD A,$78 | 0x78: ALBERT facing left, standing, with his arm down
F4F4 | JP $F3F4 | Update ALBERT's animatory state and SRB
ERIC is in the danger zone near ALBERT.
F4F7 | DEC L | L=0x00
F4F8 | POP BC | Drop the return address (6357) from the stack
F4F9 | POP BC | Drop the character buffer reference used by the routine at 62D0
F4FA | BIT 7,(HL) | Is ALBERT facing right?
F4FC | JP NZ,$6430 | Turn ALBERT round if so
F4FF | LD A,$7F | 0x7F: ALBERT facing left with his arm up
F501 | CP (HL) | Is ALBERT already holding ERIC back?
F502 | RET Z | Return if so
F503 | CALL $F3F4 | Make ALBERT put his arm up and update the SRB
F506 | LD HL,$7F80 | 7F80 holds various game status flags
F509 | BIT 1,(HL) | Is MR WACKER already looking for ERIC in order to expel him?
F50B | JR NZ,$F51E | Jump if so
F50D | BIT 2,(HL) | Is MR WACKER already looking for the truant ERIC?
F50F | JR NZ,$F51E | Jump if so
F511 | SET 2,(HL) | Signal: MR WACKER is looking for the truant ERIC
F513 | LD HL,$C81B | Place the address of the command list at F52E into bytes 0x1B and 0x1C of MR WACKER's buffer; this command list contains a single entry: the address of the routine at 7D36
F516 | LD (HL),$2E
F518 | INC L
F519 | LD (HL),$F5
F51B | INC L | Set bit 0 of byte 0x1D of MR WACKER's buffer, triggering a command list restart (at F52E)
F51C | SET 0,(HL)
F51E | LD H,$CD | 0xCD=ALBERT
F520 | CALL $7400 | Determine the coordinates at which to print ALBERT's exclamation
F523 | CALL $6A8C | Save the area of the screen that will be overwritten by the message box
F526 | LD BC,$6232 | B=0x62 (MR WACKER^HE'S ESCAPING), C=0x32 (INK 2: PAPER 6)
F529 | LD A,$02 | The border colour will be red
F52B | JP $7473 | Make ALBERT sound the alarm