| Routines

7D3E: Make any nearby teacher give ERIC lines if necessary (2)

Continues from 7D20. On entry, A contains a location identifier for ERIC:
ID | Region
--- | ---
0 | None of the places below (ERIC is never allowed here)
1 | Playground
2 | Various places in the boys' skool outside classrooms
3 | Assembly hall
4 | Dining hall
5 | Revision Library, just outside the Yellow Room door
6 | Science Lab
7 | Blue Room
8 | Yellow Room
Input
A | Location identifier for ERIC (0-8)
7D3E | AND A | Is ERIC in a forbidden zone?
7D3F | JP Z,$7DE8 | Jump with A=0 (0x00+0x3E=0x3E: YOU ARE NOT ALLOWED HERE) if so
ERIC's not in a forbidden zone. Check whether he's standing on a plant, or riding the bike in the boys' skool.
7D42 | LD B,A | B=ERIC's location identifier (1-8)
7D43 | LD L,$FB | HL=7FFB (ERIC's status flags)
7D45 | BIT 1,(HL) | Is ERIC on the bike, on a plant, or falling?
7D47 | JR Z,$7D5B | Jump if not
ERIC is on the bike, on a plant, or falling.
7D49 | LD L,$ED | HL=7FED (ERIC's other status flags)
7D4B | LD A,(HL) | Pick these up in A
7D4C | AND $83 | Check bits 0, 1 and 7
7D4E | JR Z,$7D5B | Jump if ERIC's falling
7D50 | AND $02 | A=0x02 (0x02+0x3E=0x40: GET OFF THE PLANTS) if ERIC's standing on a plant or plant pot
7D52 | JP NZ,$7DE8 | Jump if ERIC is (a) standing on a plant or plant pot, or (b) riding or standing on the saddle of the bike inside the boys' skool
7D55 | DEC B | B=0 now if ERIC's in the playground
7D56 | LD A,$03 | 0x03+0x3E=0x41: DON'T RIDE BIKES IN HERE
7D58 | JR NZ,$7D52 | Jump if ERIC's riding the bike in the boys' skool
7D5A | INC B | B=ERIC's location identifier (1-8)
Now to check whether ERIC's in the room or area he's supposed to be in this period.
7D5B | LD L,$E0 | HL=7FE0 (lesson descriptor)
7D5D | LD A,(HL) | Pick this up in A
7D5E | AND $0F | Keep only the 'room' bits (bits 0-3)
7D60 | LD C,A | Copy the room bits to C
Now the value in C indicates where this lesson takes place:
C | Lesson/location
--- | ---
2 | Playtime
3 | Assembly
4 | Dinner
5 | Revision Library
6 | Science Lab
7 | Blue Room
8 | Yellow Room
7D61 | LD L,$80 | HL=7F80 (various game status flags)
7D63 | BIT 6,(HL) | Should ERIC be in class, assembly or the dinner hall by now?
7D65 | JR NZ,$7DA7 | Jump if so
7D67 | LD L,$E4 | Pick up the MSB of the lesson clock
7D69 | LD A,(HL)
7D6A | CP $0C | Should ERIC by now have left the classroom he was in last period?
7D6C | JR C,$7D86 | Jump if so
It's too soon to be telling ERIC to GET ALONG NOW. Check whether he's sitting on the floor anywhere outside the assembly hall.
7D6E | LD L,$FB | HL=7FFB (ERIC's status flags)
7D70 | BIT 2,(HL) | Is ERIC sitting or lying down?
7D72 | RET Z | Return if not
7D73 | LD A,($D200) | A=ERIC's animatory state
7D76 | CP $04 | 0x04: Is ERIC sitting in a chair?
7D78 | RET Z | Return if so
7D79 | CP $85 | 0x85: ERIC sitting on the floor facing right
7D7B | LD A,$04 | 0x04+0x3E=0x42: GET OFF THE FLOOR
7D7D | JP NZ,$7DE8 | Give lines if ERIC's sitting on the floor facing left, or lying down
7D80 | LD A,B | A=ERIC's location identifier (1-8)
7D81 | CP $03 | ERIC is sitting on the floor facing right; is he in the assembly hall?
7D83 | JR NZ,$7D7B | Give lines if not
7D85 | RET |
By now, ERIC should have left the classroom he was in last period.
7D86 | LD A,$05 | Location IDs 6-8 correspond to the boys' skool classrooms
7D88 | CP B | Is ERIC in the Blue Room, Yellow Room or Science Lab?
7D89 | JR C,$7DA7 | Jump if so
7D8B | LD A,$02 | Is it PLAYTIME?
7D8D | CP C
7D8E | JR Z,$7D9E | Jump if so
7D90 | DEC A | A=1
7D91 | CP B | B=1 if ERIC's in the playground
7D92 | LD A,$05 | 0x05+0x3E=0x43: GET BACK TO SCHOOL
7D94 | JR Z,$7DE8 | Give lines if ERIC is in the playground
7D96 | LD A,C | Is it ASSEMBLY?
7D97 | CP $03
7D99 | JR NZ,$7D9E | Jump if not
7D9B | CP B | Is ERIC in the assembly hall?
7D9C | JR Z,$7DB6 | Jump if so
7D9E | LD L,$FB | HL=7FFB (ERIC's status flags)
7DA0 | BIT 2,(HL) | Is ERIC sitting or lying down?
7DA2 | RET Z | Return if not
7DA3 | LD A,$04 | 0x04+0x3E=0x42: GET OFF THE FLOOR
7DA5 | JR $7DE8 | Give lines
ERIC should be in class, assembly or the dinner hall by now.
7DA7 | LD A,B | A=ERIC's location identifier (1-8)
7DA8 | CP C | Compare that with where he should be
7DA9 | LD A,$06 | 0x06+0x3E=0x44: GET ALONG NOW
7DAB | JR NZ,$7DE8 | Give lines if ERIC's not where he should be
7DAD | DEC A | A=5
7DAE | CP C | C > 5 if this lesson is in a classroom
7DAF | JR C,$7DD1 | Jump if this lesson is in a classroom
7DB1 | LD A,C | Is it ASSEMBLY?
7DB2 | CP $03
7DB4 | JR NZ,$7D9E | Jump if not
7DB6 | LD L,$80 | HL=7F80 (various game status flags)
7DB8 | BIT 7,(HL) | Bit 7 is set if ERIC should be sitting down now
7DBA | LD A,($D200) | A=ERIC's animatory state
7DBD | JR NZ,$7DC4 | Jump if ERIC should be sitting facing the stage now
7DBF | CP $85 | 0x85: Is ERIC sitting on the floor facing right?
7DC1 | JR NZ,$7D9E | Jump if not
7DC3 | RET |
It's assembly, ERIC is in the assembly hall, and he should be sitting down facing the stage now. Check whether he is.
7DC4 | CP $85 | 0x85: Is ERIC sitting on the floor facing right?
7DC6 | RET Z | Return if so
7DC7 | LD L,$FB | HL=7FFB (ERIC's status flags)
7DC9 | LD A,$07 | 0x07+0x3E=0x45: SIT FACING THE STAGE
7DCB | BIT 2,(HL) | Is ERIC sitting (facing left) or lying down?
7DCD | JR Z,$7DE8 | Tell ERIC to sit facing the stage if not (this is a bug)
7DCF | JR $7DE4 | Otherwise tell ERIC to sit down
This lesson takes place in a classroom, and ERIC is present. Check whether ERIC is sitting in a chair.
7DD1 | LD A,($D200) | A=ERIC's animatory state
7DD4 | CP $04 | 0x04: Is ERIC sitting in a chair?
7DD6 | RET Z | Return if so
7DD7 | LD L,$FB | HL=7FFB (ERIC's status flags)
7DD9 | BIT 2,(HL) | Bit 2 is set if ERIC's sitting or lying on the floor
7DDB | LD A,$04 | 0x04+0x3E=0x42: GET OFF THE FLOOR
7DDD | JR NZ,$7DE8 | Give lines if ERIC's sitting or lying on the floor
7DDF | LD L,$80 | HL=7F80 (various game status flags)
7DE1 | BIT 7,(HL) | Should ERIC be seated by now (bit 7 is set by F100)?
7DE3 | RET Z | Return if not
7DE4 | LD A,$08 | 0x08+0x3E=0x46: NOW SIT DOWN
7DE6 | NOP |
7DE7 | NOP |
At this point, A holds the lines reprimand ID.
7DE8 | AND A | Is ERIC in a forbidden zone?
7DE9 | JR NZ,$7E16 | Jump if not
ERIC is somewhere he's never allowed to be.
7DEB | LD L,$80 | HL=7F80 (various game status flags)
7DED | BIT 5,(HL) | Is MISS TAKE chasing ERIC?
7DEF | JR NZ,$7E15 | Jump if so
7DF1 | LD A,($7FE0) | A=lesson descriptor
7DF4 | CP $02 | Is it PLAYTIME?
7DF6 | JR Z,$7E15 | Jump if so
7DF8 | LD A,E | A=ERIC's x-coordinate
7DF9 | CP $A0 | Is ERIC in the girls' skool?
7DFB | JR C,$7E15 | Jump if not
So it's not playtime, ERIC is in the girls' skool, and MISS TAKE is not (yet) chasing him out. Should she start?
7DFD | LD HL,$CC02 | Point HL at byte 0x02 of MISS TAKE's buffer
7E00 | LD A,(HL) | A=MISS TAKE's y-coordinate
7E01 | CP D | Are ERIC and MISS TAKE on the same floor?
7E02 | JR NZ,$7E13 | Jump if not
7E04 | LD L,$1D | Set bit 0 of byte 0x1D of MISS TAKE's character buffer, triggering a restart of her command list (set to 7E73 below)
7E06 | SET 0,(HL)
7E08 | DEC L | Place the address of the command list at 7E73 into bytes 0x1B and 0x1C of MISS TAKE's buffer; this command list contains a single routine address: 7E75
7E09 | LD (HL),$7E
7E0B | DEC L
7E0C | LD (HL),$73
7E0E | LD HL,$7F80 | 7F80 holds various game status flags
7E11 | SET 5,(HL) | Signal: MISS TAKE is chasing ERIC
7E13 | LD H,$7F | Point HL at the game status buffer page
7E15 | XOR A | 0x00+0x3E=0x3E: YOU ARE NOT ALLOWED HERE
Check how long it's been since ERIC last got lines.
7E16 | LD L,$F7 | HL=7FF7 (MSB of the lines-giving delay counter)
7E18 | DEC (HL) | Reset the zero flag if it's too soon for the teacher who gave ERIC lines last time to give him lines again
7E19 | INC (HL)
This entry point is used by the routine at F862 with the zero flag set (meaning any teacher may give ERIC lines) and A holding a lines reprimand ID.
7E1A | PUSH AF | Save the lines reprimand ID and the zero flag
7E1B | NOP |
7E1C | NOP |
7E1D | JR Z,$7E28 | Jump if any teacher (including the one who gave him lines last time) can give ERIC lines now
It's too soon for the teacher who gave ERIC lines last time to give him lines again. Remove that teacher from lines-giving range temporarily.
7E1F | LD L,$F5 | Collect from 7FF5 into H the character number of the teacher who last gave ERIC lines
7E21 | LD H,(HL)
7E22 | LD L,$01 | A=this teacher's x-coordinate
7E24 | LD A,(HL)
7E25 | LD (HL),$E0 | Set this teacher's x-coordinate to 224 temporarily to take him out of lines-giving range
7E27 | LD L,A | Save the teacher's real x-coordinate in L
Now to find out which teacher (if any) should give ERIC lines.
7E28 | PUSH HL |
7E29 | CALL $6D62 | Find the first adult within lines-giving range of ERIC
7E2C | POP HL |
7E2D | LD D,A | D=character number of this adult, or 0 if there are none in range
7E2E | POP AF |
7E2F | LD B,A | B=lines reprimand ID
7E30 | JR Z,$7E36 | Jump unless we need to restore the x-coordinate of the teacher who last gave ERIC lines
7E32 | LD A,L | Restore the x-coordinate of the teacher who last gave ERIC lines
7E33 | LD L,$01
7E35 | LD (HL),A
7E36 | LD A,D | A=character number of the adult who can see ERIC, or 0 if there are no adults in range
7E37 | CP $CD | Is it ALBERT (and therefore none of the teachers)?
7E39 | RET Z | Return if so (ALBERT doesn't give lines)
7E3A | AND A | Can any adult character see ERIC?
7E3B | RET Z | Return if not
A teacher is within lines-giving range.
7E3C | LD HL,$7F80 | 7F80 holds various game status flags
7E3F | BIT 1,(HL) | Is MR WACKER chasing ERIC to expel him?
7E41 | RET NZ | Return if so
7E42 | LD L,$F5 | Store the character number of the lines-giver at 7FF5
7E44 | LD (HL),A
7E45 | LD L,$F7 | Reset the MSB of the lines-giving delay counter at 7FF7 to 0x0A
7E47 | LD (HL),$0A
7E49 | LD A,B | A=lines reprimand ID
7E4A | CP $06 | 0x06+0x3E=0x44: GET ALONG NOW
7E4C | JR NZ,$7E69 | Jump unless ERIC is late for class, dinner or assembly
ERIC is late for class, dinner or assembly. The appropriate lines reprimand depends on who saw him: his teacher for this period, or some other teacher.
7E4E | LD A,($7FE0) | Collect the lesson descriptor from 7FE0
7E51 | AND $F0 | Keep only the bits relating to ERIC's teacher and shift them into bits 0-3
7E53 | RLCA
7E54 | RLCA
7E55 | RLCA
7E56 | RLCA
7E57 | ADD A,$C7 | Now A=character number of ERIC's teacher (0xC8-0xCB)
7E59 | CP D | Was it that teacher who saw ERIC?
7E5A | JR NZ,$7E69 | Jump if not
ERIC's teacher for this period is the lines-giver. His lines reprimand alternates between 'COME ALONG YOU MONSTER' and 'DON'T KEEP ME WAITING'.
7E5C | LD L,$80 | HL=7F80 (various game status flags)
7E5E | LD A,$10 | Set bit 4 in A
7E60 | LD B,$09 | 0x09+0x3E=0x47: COME ALONG YOU MONSTER
7E62 | XOR (HL) | Flip bit 4 in 7F80, toggling between 0x47 and 0x48
7E63 | LD (HL),A
7E64 | BIT 4,(HL) | Should ERIC's teacher say 'COME ALONG YOU MONSTER' this time (bit 4 set)?
7E66 | JR NZ,$7E69 | Jump if so
7E68 | INC B | 0x0A+0x3E=0x48: DON'T KEEP ME WAITING
At this point D holds the character number of the teacher who is going to give ERIC lines, and B holds the lines reprimand ID.
7E69 | EX DE,HL | Now H=character number of the lines-giver
7E6A | LD A,B | B=lines reprimand ID
7E6B | ADD A,$3E
7E6D | LD B,A
7E6E | LD A,$D2 | 0xD2=ERIC (the lines recipient)
7E70 | JP $7414 | Make the teacher give lines to ERIC