| Routines

31648: Make a teacher find the truant ERIC

Used by the routine at 31854, which also places the address of this interruptible subcommand routine into bytes 105 and 106 of the teacher's buffer when ERIC is absent during dinner or class. It makes the teacher run after and stalk ERIC until he goes to wherever he should be (the dinner hall or the classroom).
Input
H | Teacher's character number (163-166)
31648 | CALL 31229 | Get ERIC's coordinates in DE
31651 | CALL 32234 | Make this teacher walk fast
31654 | CALL 31452 | Determine which way the teacher needs to go to find ERIC
31657 | AND A | Are ERIC and this teacher in the same location?
31658 | JR Z,31664 | Jump if so
31660 | CP 3 | Is this teacher going up or down a staircase?
31662 | JR C,31695 | Jump if so
31664 | LD L,122 | If this teacher's command list has been marked for a restart (by the routine at 26342), terminate this interruptible subcommand and restart now
31666 | BIT 0,(HL)
31668 | JP NZ,25252
31671 | LD B,A |
31672 | CALL 31188 | Check whether ERIC is where he should be
31675 | LD A,B |
31676 | JR NZ,31695 | Jump if ERIC is not where he should be
ERIC is back where he should be, so it's time for the teacher to resume his classroom duties.
31678 | LD L,117 | Pick up in DE the address the teacher has reached in his command list
31680 | LD E,(HL)
31681 | INC L
31682 | LD D,(HL)
31683 | LD B,2 | 190 is the LSB of the address of the routine at 25534; point DE at the second-from-last occurrence of this routine address in the teacher's command list (which will take him to the side of the blackboard where he waits for EINSTEIN to grass, or back to the dinner hall)
31685 | DEC DE
31686 | LD A,(DE)
31687 | CP 190
31689 | JR NZ,31685
31691 | DJNZ 31685
31693 | JR 31638 | Restart the teacher's command list from this point
ERIC is not where he should be, or the teacher is on a staircase.
31695 | AND A | Are ERIC and the teacher in exactly the same location?
31696 | JR NZ,31711 | Jump if not
31698 | LD A,(23672) | 23672=LSB of FRAMES system variable
31701 | AND A | This LSB will be 0 once every 5.12 seconds
31702 | RET NZ | Return if it's not zero now
31703 | CALL 25108 | Update the SRB for the teacher's current animatory state
31706 | XOR 128 | Make the teacher turn round
31708 | JP 25008 | Update the teacher's animatory state and update the SRB
This entry point is used by the routine at 63374 with H holding the number of a character looking for ERIC (which will be little boy no. 10 or a teacher), and A holding 1, 2, 3 or 4 (indicating the character's next move).
31711 | CP 3 | Set the carry flag if the chaser is on a staircase
31713 | LD BC,0 | DE will hold the appropriate x- and y-coordinate increments for the chaser's next move (to the midstride position), and BC will hold the appropriate x- and y-coordinate increments for the chaser's move after that (from the midstride position); initialise these increments to 0
31716 | LD DE,0
31719 | LD L,96 | Byte 96 of the buffer holds the animatory state of ERIC's chaser
31721 | JR C,31768 | Jump if the chaser is currently going up or down stairs
31723 | JR NZ,31732 | Jump if the chaser must go right (A=4)
31725 | BIT 7,(HL) | Is the chaser facing right?
31727 | JR NZ,31703 | Turn him round if so
31729 | DEC C | C=-1
31730 | JR 31781 |
31732 | BIT 7,(HL) | Is the chaser facing left?
31734 | JR Z,31703 | Turn him round if so
31736 | INC C | C=1
31737 | JR 31781 |