Prev: 77A6 Up: Map Next: 78A8
77AC: Make any nearby teacher give ERIC lines if necessary
Used by the routine at 6AD9. 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.
77AC LD HL,$7FF2 Check (and decrement) the lines-giving delay counter at 7FF2, and proceed only if it was <0x4B (the counter starts off at 0 for a new game, and is set to 0x96 by this routine after ERIC has been given lines)
77AF LD A,(HL)
77B0 AND A
77B1 JR Z,$77B7
77B3 DEC (HL)
77B4 CP $4B
77B6 RET NC
77B7 LD BC,($AC61) Collect ERIC's coordinates in BC
77BB LD L,$FB HL=7FFB (ERIC's status flags)
77BD BIT 2,(HL) Is ERIC jumping?
77BF JR Z,$77D0 Jump if not
77C1 LD A,C A=ERIC's y-coordinate
77C2 LD C,$9B This is the y-coordinate of the top floor
77C4 CP $9C Is ERIC on the top floor?
77C6 JR C,$77D0 Jump if so
77C8 LD C,$A2 This is the y-coordinate of the middle floor
77CA CP $A3 Is ERIC on the middle floor?
77CC JR C,$77D0 Jump if so
77CE LD C,$A9 This is the y-coordinate of the bottom floor
77D0 LD A,C A=ERIC's y-coordinate (adjusted if he's jumping)
77D1 LD DE,$7790 Point HL at the skool region data table for the top floor at 7790
77D4 EX DE,HL
77D5 CP $9B Is ERIC on the top floor?
77D7 JR Z,$77F0 Jump if so
77D9 LD L,$9C HL=779C (skool region data table for the middle floor)
77DB CP $A2 Is ERIC on the middle floor?
77DD JR Z,$77F0 Jump if so
77DF LD L,$A6 HL=77A6 (skool region data table for the bottom floor)
77E1 CP $A9 Is ERIC on the bottom floor?
77E3 JR Z,$77F0 Jump if so
ERIC is on a staircase. Is he sitting on the stairs?
77E5 EX DE,HL HL=7FFB (ERIC's status flags)
77E6 BIT 7,(HL) Reset the zero flag if ERIC is sitting
77E8 LD A,$07 This value is ignored
77EA JR Z,$77F8 Jump unless ERIC is sitting on the stairs
77EC LD A,$00 Lines reprimand 0x00: DON'T SIT ON THE STAIRS
77EE JR $7838 Make any nearby teacher give lines
At this point, HL holds the base address of a data table describing the regions in the skool (7790 for the top floor, 779C for the middle floor, or 77A6 for the bottom floor).
77F0 LD A,B B=ERIC's x-coordinate
77F1 CP (HL) Compare it with the x-coordinate from the region table
77F2 INC HL
77F3 INC HL
77F4 JR NC,$77F1 Jump back until we've determined where ERIC is
77F6 DEC HL Point DE at the ID byte of the region table entry
77F7 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
77F8 LD A,(DE) A=ID of the region ERIC's in (7 if he's on a staircase)
77F9 AND A Set the zero flag if ERIC's in a forbidden zone
77FA LD A,$01 Lines reprimand 0x01: THE ROOM IS PRIVATE
77FC JR Z,$7838 Jump if ERIC's in the head's study or the staff room
77FE LD A,(DE) A=ID of the region ERIC's in
77FF LD L,$C8 HL=7FC8 (lesson status flags)
7801 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
7803 JR Z,$782B
7805 LD A,($7FF4) 7FF4 holds the current lesson descriptor
7808 AND $07 Keep only the 'room' bits (0-2)
780A EX DE,HL
780B CP (HL) Compare this with ERIC's region ID
780C EX DE,HL
780D LD A,$02 Lines reprimand 0x02: GET TO WHERE YOU SHOULD BE
780F JR NZ,$7838 Jump if ERIC is not where he should be
7811 LD A,(HL) Pick up the lesson status flags from 7FC8
7812 RLCA Set the carry flag if ERIC's lesson has started with ERIC present
7813 RLCA
7814 LD A,($AC60) A=ERIC's animatory state
7817 JR NC,$7822 Jump if ERIC's lesson has not started
7819 AND $0F ERIC's lesson has started; is ERIC sitting in a chair?
781B CP $05
781D RET Z Return if so
781E LD A,$03 Lines reprimand 0x03: NOW FIND A SEAT
7820 JR $7838 Make any nearby teacher give lines
ERIC's lesson has not started yet.
7822 AND $07 Is ERIC standing, or midstride, or sitting on a chair?
7824 CP $06
7826 RET C Return if so
7827 LD A,$04 Lines reprimand 0x04: GET OFF THE FLOOR
7829 JR $7838 Make any nearby teacher give lines
Bit 7 of 7FC8 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.
782B CP $05 Is ERIC in a room?
782D JR NC,$7814 Jump if not
782F LD A,($7FF8) Pick up the MSB of the lesson clock in A
7832 CP $13 Should ERIC have left the room he was in last period?
7834 JR NC,$7814 Jump if not
7836 JR $7805 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
7838 LD D,A D=0, 1, 2, 3 or 4
7839 LD L,$F2 HL=7FF2: lines-giving delay counter (0x00-0x49)
783B LD A,(HL) Is it too soon for the same teacher to give ERIC lines twice in a row?
783C AND A
783D JR Z,$7846 Jump if not
783F INC HL Otherwise, collect from 7FF3 into H the character number of the teacher who last gave ERIC lines
7840 LD H,(HL)
7841 LD L,$62 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
7843 LD E,(HL)
7844 LD (HL),$FF
7846 PUSH DE
7847 PUSH AF
7848 LD D,C DE=ERIC's coordinates
7849 LD E,B
784A LD HL,$AC60 Point HL at ERIC's character buffer
784D CALL $6E96 Get the floor closest to ERIC (0x9B, 0xA2 or 0xA9) in D
7850 CALL $6E3F Can ERIC be seen by a teacher?
7853 JR C,$7860 Jump if so
7855 POP AF
7856 POP DE
7857 RET Z Return unless we need to restore the x-coordinate of the last teacher who gave ERIC lines
7858 LD A,($7FF3) Restore the x-coordinate of the teacher who was temporarily placed out of lines-giving range
785B LD H,A
785C LD L,$62
785E LD (HL),E
785F RET
Time to dish out some lines to ERIC.
7860 POP AF
7861 POP DE
7862 JR Z,$786B Jump unless we need to restore the x-coordinate of the last teacher who gave ERIC lines
7864 LD A,($7FF3) Restore the x-coordinate of the teacher who was temporarily placed out of lines-giving range
7867 LD H,A
7868 LD L,$62
786A LD (HL),E
786B LD B,D B=0, 1, 2, 3 or 4 (lines reprimand ID)
786C EXX H=character number of the teacher who saw ERIC
786D PUSH HL
786E EXX
786F POP HL
7870 LD L,$96 Reset the lines-giving delay counter at 7FF2 to 0x96, and set 7FF3 to the character number of the teacher who saw ERIC
7872 LD ($7FF2),HL
7875 LD L,$62 DE=coordinates of the teacher who saw ERIC
7877 LD E,(HL)
7878 DEC L
7879 LD D,(HL)
787A LD A,B B=0, 1, 2, 3 or 4 (lines reprimand ID)
787B CP $02 Was ERIC spotted somewhere other than where he should be?
787D JR NZ,$78A3 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.
787F LD A,($7FF4) Pick up the current lesson descriptor from 7FF4
7882 AND $F0 Keep only the teacher bits (4-7)
7884 RRCA A=character number of ERIC's teacher for this period
7885 RRCA
7886 RRCA
7887 RRCA
7888 ADD A,$A3
788A CP H Was it ERIC's teacher who saw him?
788B JR NZ,$78A3 Jump if not (with B=0x02: GET TO WHERE YOU SHOULD BE)
The truant ERIC has been spotted by his teacher for this period.
788D LD B,$05 Lines reprimand 0x05: COME ALONG WITH ME BOY
788F LD A,($7FC8) Bits 4 and 5 of 7FC8 hold the flags that determine ERIC's teacher's next lines reprimand
7892 BIT 5,A Set the zero flag if ERIC's teacher hasn't said 'COME ALONG WITH ME BOY' yet
7894 SET 5,A Indicate that he has said this now
7896 JR Z,$78A0 Jump if ERIC's teacher has spotted him for the first time
7898 XOR $10 Flip bit 4
789A INC B B=0x06: HURRY UP YOU HORROR
789B BIT 4,A Should ERIC's teacher say this next?
789D JR Z,$78A0 Jump if so
789F INC B B=0x07: DON'T TRY MY PATIENCE BOY
78A0 LD ($7FC8),A Update the truancy lines reprimand flags in 7FC8
Now B holds the appropriate lines reprimand ID. Finally, give lines to ERIC.
78A3 LD A,$AC 0xAC=ERIC
78A5 JP $7700 Give lines to ERIC
Prev: 77A6 Up: Map Next: 78A8