| Routines

F55F: Make MR WACKER find and expel ERIC

The address of this routine is found in the command list at F530, the address of which is placed into bytes 0x1B and 0x1C of MR WACKER's buffer by the routine at F532.
Input
H | 0xC8 (MR WACKER)
F55F | LD L,$1D | Set bit 7 of byte 0x1D of MR WACKER's buffer, making him run
F561 | SET 7,(HL)
F563 | LD A,$FF | Set the MSB of the lesson clock at 7FE3 to 0xFF (this lesson will not end until ERIC's expelled)
F565 | LD ($7FE4),A
F568 | CALL $6558 | Move MR WACKER one step closer to ERIC (if he's not yet close enough)
F56B | LD HL,$C800 | Point HL at byte 0x00 of MR WACKER's buffer
F56E | BIT 0,(HL) | Is MR WACKER now midstride?
F570 | RET NZ | Return if so
F571 | INC L | L=0x01
F572 | LD DE,($D201) | E=ERIC's x-coordinate, D=ERIC's y-coordinate
F576 | LD A,(HL) | A=MR WACKER's x-coordinate
F577 | SUB E | Is MR WACKER within 3 x-coordinates of ERIC?
F578 | ADD A,$03
F57A | CP $07
F57C | RET NC | Return if not
F57D | INC L | L=0x02
F57E | LD A,(HL) | A=MR WACKER's y-coordinate
F57F | SUB D | Is MR WACKER within 3 y-coordinates of ERIC?
F580 | ADD A,$03
F582 | CP $07
F584 | RET NC | Return if not
MR WACKER has found ERIC.
F585 | LD HL,$7FFB | 7FFB holds ERIC's status flags
F588 | LD (HL),$40 | Set bit 6: MR WACKER is expelling ERIC (who is now paralysed)
F58A | LD L,$ED | HL=7FED (ERIC's other status flags)
F58C | BIT 5,(HL) | Bit 5 is set if ERIC jumped out of the top-floor window
F58E | LD H,$C8 | 0xC8=MR WACKER
F590 | LD E,$63 | Message 0x63: YOU HAVE 10000 LINES...
F592 | JR Z,$F595 | Jump if ERIC didn't jump out of the top-floor window (i.e. he has 10000 lines)
F594 | INC E | E=0x64: YOU ARE NOT A BIRD...
F595 | LD BC,$6A08 | Redirect control to the routine at 6A08 (make character speak) and return to F59B (below) when done
F598 | CALL $639F
F59B | LD DE,($7FE5) | Collect the score from 7FE5 into DE
F59F | LD HL,($7FE9) | Collect the current hi-score from 7FE9 into HL
F5A2 | AND A | Clear the carry flag ready for subtraction
F5A3 | SBC HL,DE | Do we have a new hi-score?
F5A5 | JR NC,$F5AB | Jump if not
F5A7 | LD ($7FE9),DE | Insert the new hi-score
F5AB | LD HL,$0000 | Reset the score (at 7FE5) and the lines total (at 7FE7) to 0
F5AE | LD ($7FE5),HL
F5B1 | LD ($7FE7),HL
F5B4 | JP $F6D5 | Enter demo mode