| Routines

30636: Make any nearby teacher give ERIC lines if necessary

Used by the routine at 27353. Checks whether ERIC is somewhere he shouldn't be, or sitting or standing when or where he shouldn't be, or lying down, and makes any nearby teacher give lines accordingly.
30636 | LD HL,32754 | Check (and decrement) the lines-giving delay counter at 32754, and proceed only if it was <75 (the counter starts off at 0 for a new game, and is set to 150 by this routine after ERIC has been given lines)
30639 | LD A,(HL)
30640 | AND A
30641 | JR Z,30647
30643 | DEC (HL)
30644 | CP 75
30646 | RET NC
30647 | LD BC,(44129) | Collect ERIC's coordinates in BC
30651 | LD L,251 | HL=32763 (ERIC's status flags)
30653 | BIT 2,(HL) | Is ERIC jumping?
30655 | JR Z,30672 | Jump if not
30657 | LD A,C | A=ERIC's y-coordinate
30658 | LD C,155 | This is the y-coordinate of the top floor
30660 | CP 156 | Is ERIC on the top floor?
30662 | JR C,30672 | Jump if so
30664 | LD C,162 | This is the y-coordinate of the middle floor
30666 | CP 163 | Is ERIC on the middle floor?
30668 | JR C,30672 | Jump if so
30670 | LD C,169 | This is the y-coordinate of the bottom floor
30672 | LD A,C | A=ERIC's y-coordinate (adjusted if he's jumping)
30673 | LD DE,30608 | Point HL at the skool region data table for the top floor at 30608
30676 | EX DE,HL
30677 | CP 155 | Is ERIC on the top floor?
30679 | JR Z,30704 | Jump if so
30681 | LD L,156 | HL=30620 (skool region data table for the middle floor)
30683 | CP 162 | Is ERIC on the middle floor?
30685 | JR Z,30704 | Jump if so
30687 | LD L,166 | HL=30630 (skool region data table for the bottom floor)
30689 | CP 169 | Is ERIC on the bottom floor?
30691 | JR Z,30704 | Jump if so
ERIC is on a staircase. Is he sitting on the stairs?
30693 | EX DE,HL | HL=32763 (ERIC's status flags)
30694 | BIT 7,(HL) | Reset the zero flag if ERIC is sitting
30696 | LD A,7 | This value is ignored
30698 | JR Z,30712 | Jump unless ERIC is sitting on the stairs
30700 | LD A,0 | Lines reprimand 0: DON'T SIT ON THE STAIRS
30702 | JR 30776 | Make any nearby teacher give lines
At this point, HL holds the base address of a data table describing the regions in the skool (30608 for the top floor, 30620 for the middle floor, or 30630 for the bottom floor).
30704 | LD A,B | B=ERIC's x-coordinate
30705 | CP (HL) | Compare it with the x-coordinate from the region table
30706 | INC HL |
30707 | INC HL |
30708 | JR NC,30705 | Jump back until we've determined where ERIC is
30710 | DEC HL | Point DE at the ID byte of the region table entry
30711 | EX DE,HL
The ID bytes in the region tables have the following meanings:
ID | Meaning
--- | ---
0 | ERIC should never be here (head's study or staff room)
1 | Reading Room
2 | Map Room
3 | White Room
4 | Exam Room
5 | Revision Library
6 | Dinner hall
7 | None of the above
30712 | LD A,(DE) | A=ID of the region ERIC's in (7 if he's on a staircase)
30713 | AND A | Set the zero flag if ERIC's in a forbidden zone
30714 | LD A,1 | Lines reprimand 1: THE ROOM IS PRIVATE
30716 | JR Z,30776 | Jump if ERIC's in the head's study or the staff room
30718 | LD A,(DE) | A=ID of the region ERIC's in
30719 | LD L,200 | HL=32712 (lesson status flags)
30721 | BIT 7,(HL) | Jump if EINSTEIN has not had a chance to grass on ERIC for being absent yet, or dinner has not started yet, or this is PLAYTIME or REVISION LIBRARY
30723 | JR Z,30763
30725 | LD A,(32756) | 32756 holds the current lesson descriptor
30728 | AND 7 | Keep only the 'room' bits (0-2)
30730 | EX DE,HL |
30731 | CP (HL) | Compare this with ERIC's region ID
30732 | EX DE,HL |
30733 | LD A,2 | Lines reprimand 2: GET TO WHERE YOU SHOULD BE
30735 | JR NZ,30776 | Jump if ERIC is not where he should be
30737 | LD A,(HL) | Pick up the lesson status flags from 32712
30738 | RLCA | Set the carry flag if ERIC's lesson has started with ERIC present
30739 | RLCA
30740 | LD A,(44128) | A=ERIC's animatory state
30743 | JR NC,30754 | Jump if ERIC's lesson has not started
30745 | AND 15 | ERIC's lesson has started; is ERIC sitting in a chair?
30747 | CP 5
30749 | RET Z | Return if so
30750 | LD A,3 | Lines reprimand 3: NOW FIND A SEAT
30752 | JR 30776 | Make any nearby teacher give lines
ERIC's lesson has not started yet.
30754 | AND 7 | Is ERIC standing, or midstride, or sitting on a chair?
30756 | CP 6
30758 | RET C | Return if so
30759 | LD A,4 | Lines reprimand 4: GET OFF THE FLOOR
30761 | JR 30776 | Make any nearby teacher give lines
Bit 7 of 32712 is reset, which means EINSTEIN has not yet had a chance to grass on ERIC for being absent at the start of the lesson, or dinner has not started yet, or this is PLAYTIME or REVISION LIBRARY.
30763 | CP 5 | Is ERIC in a room?
30765 | JR NC,30740 | Jump if not
30767 | LD A,(32760) | Pick up the MSB of the lesson clock in A
30770 | CP 19 | Should ERIC have left the room he was in last period?
30772 | JR NC,30740 | Jump if not
30774 | JR 30725 | Otherwise check ERIC's location
ERIC is not where he should be, or is not sitting down when he should be, or is sitting on the floor or on the stairs. In short, he should be given lines by any adult witness. At this point A holds one of the following values:
A | Meaning
--- | ---
0 | ERIC is sitting on the stairs
1 | ERIC is in the head's study or the staff room
2 | ERIC is not in the room he should be in
3 | ERIC is not sitting down when he should be
4 | ERIC is sitting on the floor
30776 | LD D,A | D=0, 1, 2, 3 or 4
30777 | LD L,242 | HL=32754: lines-giving delay counter (0-73)
30779 | LD A,(HL) | Is it too soon for the same teacher to give ERIC lines twice in a row?
30780 | AND A
30781 | JR Z,30790 | Jump if not
30783 | INC HL | Otherwise, collect from 32755 into H the character number of the teacher who last gave ERIC lines
30784 | LD H,(HL)
30785 | LD L,98 | Store this teacher's x-coordinate in E, and set his x-coordinate to 255 temporarily, so he's out of range and will not be regarded as a lines-giving candidate
30787 | LD E,(HL)
30788 | LD (HL),255
30790 | PUSH DE |
30791 | PUSH AF |
30792 | LD D,C | DE=ERIC's coordinates
30793 | LD E,B
30794 | LD HL,44128 | Point HL at ERIC's character buffer
30797 | CALL 28310 | Get the floor closest to ERIC (155, 162 or 169) in D
30800 | CALL 28223 | Can ERIC be seen by a teacher?
30803 | JR C,30816 | Jump if so
30805 | POP AF |
30806 | POP DE |
30807 | RET Z | Return unless we need to restore the x-coordinate of the last teacher who gave ERIC lines
30808 | LD A,(32755) | Restore the x-coordinate of the teacher who was temporarily placed out of lines-giving range
30811 | LD H,A
30812 | LD L,98
30814 | LD (HL),E
30815 | RET |
Time to dish out some lines to ERIC.
30816 | POP AF |
30817 | POP DE |
30818 | JR Z,30827 | Jump unless we need to restore the x-coordinate of the last teacher who gave ERIC lines
30820 | LD A,(32755) | Restore the x-coordinate of the teacher who was temporarily placed out of lines-giving range
30823 | LD H,A
30824 | LD L,98
30826 | LD (HL),E
30827 | LD B,D | B=0, 1, 2, 3 or 4 (lines reprimand ID)
30828 | EXX | H=character number of the teacher who saw ERIC
30829 | PUSH HL
30830 | EXX
30831 | POP HL
30832 | LD L,150 | Reset the lines-giving delay counter at 32754 to 150, and set 32755 to the character number of the teacher who saw ERIC
30834 | LD (32754),HL
30837 | LD L,98 | DE=coordinates of the teacher who saw ERIC
30839 | LD E,(HL)
30840 | DEC L
30841 | LD D,(HL)
30842 | LD A,B | B=0, 1, 2, 3 or 4 (lines reprimand ID)
30843 | CP 2 | Was ERIC spotted somewhere other than where he should be?
30845 | JR NZ,30883 | Jump if not
ERIC was spotted somewhere other than where he should be. The appropriate lines reprimand depends on who saw him: his teacher for this period, or another teacher.
30847 | LD A,(32756) | Pick up the current lesson descriptor from 32756
30850 | AND 240 | Keep only the teacher bits (4-7)
30852 | RRCA | A=character number of ERIC's teacher for this period
30853 | RRCA
30854 | RRCA
30855 | RRCA
30856 | ADD A,163
30858 | CP H | Was it ERIC's teacher who saw him?
30859 | JR NZ,30883 | Jump if not (with B=2: GET TO WHERE YOU SHOULD BE)
The truant ERIC has been spotted by his teacher for this period.
30861 | LD B,5 | Lines reprimand 5: COME ALONG WITH ME BOY
30863 | LD A,(32712) | Bits 4 and 5 of 32712 hold the flags that determine ERIC's teacher's next lines reprimand
30866 | BIT 5,A | Set the zero flag if ERIC's teacher hasn't said 'COME ALONG WITH ME BOY' yet
30868 | SET 5,A | Indicate that he has said this now
30870 | JR Z,30880 | Jump if ERIC's teacher has spotted him for the first time
30872 | XOR 16 | Flip bit 4
30874 | INC B | B=6: HURRY UP YOU HORROR
30875 | BIT 4,A | Should ERIC's teacher say this next?
30877 | JR Z,30880 | Jump if so
30879 | INC B | B=7: DON'T TRY MY PATIENCE BOY
30880 | LD (32712),A | Update the truancy lines reprimand flags in 32712
Now B holds the appropriate lines reprimand ID. Finally, give lines to ERIC.
30883 | LD A,172 | 172=ERIC
30885 | JP 30464 | Give lines to ERIC