| Routines

31854: Make a teacher perform dinner duty (1)

Used by command list 184. Makes the teacher on dinner duty pace up and down the dinner hall, checking whether ERIC is present. If ERIC is absent, the teacher is sent to find him, after which the command list is restarted.
Input
H | 163 (MR WACKER) or 165 (MR WITHIT)
31854 | LD DE,32712 | Set bit 7 at 32712, indicating that dinner has started (and so ERIC should be in the dinner hall)
31857 | EX DE,HL
31858 | SET 7,(HL)
31860 | EX DE,HL
This entry point is used on subsequent calls when the teacher on dinner duty has reached the right end of the dinner hall.
31861 | CALL 31188 | Set the zero flag if ERIC is where he should be
31864 | LD DE,38689 | D=151 (LSB of 31895), E=33 (x-coordinate of the left end of the teacher's dinner duty orbit)
This entry point is used by the routine at 31895 with D=117 (LSB of the entry point at 31861, above) and E=62 (x-coordinate of the right end of the teacher's dinner duty orbit), and also by the routine at 62208 with the zero flag reset.
31867 | LD L,105 |
31869 | JR Z,31879 | Jump if ERIC is where he should be
31871 | LD (HL),160 | Place the address of the interruptible subcommand routine at 31648 into bytes 105 and 106 of the character's buffer
31873 | INC L
31874 | LD (HL),123
31876 | JP 31648 | And jump to that routine now
ERIC is where he should be, so there's no need to chase him.
31879 | LD (HL),60 | Place the address of the interruptible subcommand routine at 25404 into bytes 105 and 106 of the teacher's buffer
31881 | INC L
31882 | LD (HL),99
31884 | INC L | Place 33 or 62 into byte 107 of the teacher's buffer (to make him go to that x-coordinate next)
31885 | LD (HL),E
31886 | INC L | Place 0 into byte 108 of the teacher's buffer, giving him more than enough time to reach the other end of the dinner hall without interruption
31887 | LD (HL),0
31889 | LD L,99 | Replace the address of this primary command routine in bytes 99 and 100 of the teacher's buffer with that of 31895 or 31861
31891 | LD (HL),D
31892 | JP 25404 | Proceed to the other end of the dinner hall