Routines
 Prev: F0FD Up: Map Next: F24C
F100: Make a teacher conduct a class
Used by command lists 0x16, 0x18, 0x3A, 0x3C and 0x3E to make a teacher conduct a class (after having walked to the edge of the blackboard).
Input
H Teacher's character number (0xC9-0xCC)
F100 LD A,(\$7FE0) 7FE0 holds the current lesson descriptor
F103 AND \$F0 Keep only the teacher-identifying bits and shift them into bits 0-3
F105 RLCA
F106 RLCA
F107 RLCA
F108 RLCA
F109 ADD A,\$C7 Now A=character number of the teacher taking ERIC's class (0xC9-0xCB)
F10B CP H Is this teacher conducting ERIC's class?
F10C JR Z,\$F140 Jump if so
This teacher is not conducting ERIC's class, so he has it easy: wipe the board, write on the board (maybe), tell the class what to do, and pace up and down.
F10E LD BC,\$680F Redirect control to the routine at 680F (wipe board) and return to F114 (below) when done
F111 CALL \$639F
F114 LD L,\$01 Point HL at byte 0x01 of the teacher's buffer
F116 LD A,(HL) A=teacher's x-coordinate
F117 ADD A,\$03 A=x-coordinate of the middle of the blackboard
F119 LD L,\$0B Place this in byte 0x0B ready for the routine at 63ED
F11B LD (HL),A
F11C LD BC,\$63ED Redirect control to the routine at 63ED (walk to a location) and return to F122 (below) when done
F11F CALL \$639F
F122 CALL \$6291 A=random number
F125 LD BC,\$6880 Routine at 6880: write on board
F128 CP \$A0 Should the teacher write on the board?
F12A CALL NC,\$639F If so, redirect control to the routine at 6880 and return to F12D (below) when done
F12D CALL \$F05D Tell the class what to do
F130 LD L,\$01 Point HL at byte 0x01 of the teacher's buffer
F132 LD A,(HL) A=teacher's x-coordinate
F133 XOR \$03 Now A=x-coordinate of the location 3 paces behind the teacher
F135 LD L,\$0B Place this in byte 0x0B of the teacher's buffer, ready for the routine at 63ED
F137 LD (HL),A
F138 LD BC,\$63ED Redirect control to the routine at 63ED (walk to a location) and return to F13E (below) when done
F13B CALL \$639F
F13E JR \$F130 Make the teacher pace up (or down) again
The teacher is taking ERIC's class. This is a far more difficult task.
F140 LD A,(\$7F80) Set bit 6 at 7F80, indicating that ERIC should be in class now
F143 SET 6,A
F145 LD (\$7F80),A
F148 CALL \$F048 Are ERIC and EINSTEIN both in class?
F14B JR Z,\$F175 Jump if so
ERIC is not in class, but EINSTEIN is. EINSTEIN must therefore grass.
F14D LD BC,\$F017 Routine at F017: make EINSTEIN talk
F150 LD E,\$12 0x12: Please Sir...ERIC is not here
F152 CALL \$639F Make EINSTEIN grass on ERIC, and return to F155 (below) when done
F155 LD C,\$D0 0xD0=EINSTEIN
F157 CALL \$F02F Give lines to EINSTEIN (maybe)
F15A CALL \$7D15 Set the zero flag if ERIC is in class
F15D LD A,(\$7F80) 7F80 holds various game status flags
F160 JR Z,\$F16A Jump if ERIC is in class
F162 SET 7,A Set bit 7 at 7F80: the teacher's next absence reprimand should be 'STAY TILL I DISMISS YOU'
F164 LD (\$7F80),A
F167 JP \$F0D0 Go and find ERIC
ERIC is in class now, having shown up while EINSTEIN was grassing on him for being absent.
F16A RLCA Push bit 7 of 7F80 into the carry flag
F16B LD B,\$14 0x14: STAY TILL I DISMISS YOU
F16D LD A,\$D2 0xD2=ERIC
F16F JR C,\$F172 Jump if the teacher's already had to chase or give lines to ERIC for being late or leaving early
F171 DEC B B=0x13: DON'T BE LATE AGAIN
F172 CALL \$F040 Give ERIC lines
F175 LD A,(\$7F80) Set bits 6 (ERIC should be in class) and 7 (the teacher's next absence reprimand should be 'STAY TILL I DISMISS YOU') at 7F80
F178 OR \$C0
F17A LD (\$7F80),A
F17D CALL \$F048 Is ERIC in class?
F180 JR NZ,\$F14D Jump if not
Now is EINSTEIN's chance to grass on ERIC for hitting him.
F182 CALL \$6291 A=random number
F185 CP \$DC Should EINSTEIN tell tales?
F187 JR C,\$F19C Jump if not
F189 LD E,\$57 0x57: Please Sir...ERIC hit me
F18B LD BC,\$F017 Redirect control to the routine at F017 (make EINSTEIN talk) and return to F191 (below) when done
F18E CALL \$639F
F191 LD BC,\$61D2 B=0x61: DON'T HIT YOUR MATES; C=0xD2 (ERIC)
F194 CALL \$F02F Give EINSTEIN or ERIC lines
F197 CALL \$F048 Is ERIC in class?
F19A JR NZ,\$F14D Jump if not
Now is EINSTEIN's opportunity to grass on someone for writing on the blackboard. However, the opportunity is wasted, because the CALL to 6755 (at F19C below) returns a valid blackboard ID only if the character is standing within four spaces of the left edge of the blackboard, which is not the case when the teacher is waiting for EINSTEIN to grass (teachers stand at the right edge of the blackboard for that, more than four spaces away). This is a bug.
F19C CALL \$6755 Collect information about the blackboard
F19F INC B The intent here is to point BC at the second byte of the blackboard's buffer, which holds the character number of the person who last wrote on it; instead, BC points at 7F04 if the teacher is on the top floor, or 7F03 if he's on the middle floor
F1A0 LD C,B
F1A1 LD B,\$7F
F1A3 LD A,(BC) Now A is supposed to hold the character number of the person who last wrote on the board; instead it holds the contents of 7F03 or 7F04 (bytes 0x03 and 0x04 of the SRB), which will never be 0xCE or 0xD2
F1A4 CP \$D2 Did ERIC write on the board?
F1A6 JR Z,\$F1B7 Jump if so (this jump is never made)
F1A8 CP \$CE Or did BOY WANDER?
F1AA JR NZ,\$F1CB Jump if not (this jump is always made)
F1AC CALL \$6291 A=random number
F1AF CP \$C3 Should EINSTEIN blame BOY WANDER for writing on the board?
F1B1 LD A,\$CE 0xCE=BOY WANDER
F1B3 JR C,\$F1B7 Jump if so
F1B5 LD A,\$D2 Blame ERIC instead
F1B7 LD (\$7F90),A Place the character number of the scapegoat into 7F90
F1BA LD BC,\$F017 Routine at F017: make EINSTEIN talk
F1BD LD E,\$58 0x58: Please Sir...[0x07] wrote on the board
F1BF CALL \$639F Redirect control to the routine at F017 and return to F1C2 (below) when done
F1C2 LD A,(\$7F90) A=0xCE (BOY WANDER) or 0xD2 (ERIC)
F1C5 LD C,A Copy the scapegoat's character number to C
F1C6 LD B,\$56 0x56: DON'T TOUCH BLACKBOARDS
F1C8 CALL \$F02F Give lines to EINSTEIN, ERIC or BOY WANDER
The next section of code makes the teacher wipe the board. Note that the teacher may already have wiped the board at this point, and therefore will not be standing at the right edge of the board (the correct location to begin wiping); this is a bug.
F1CB LD BC,\$680F Redirect control to the routine at 680F (wipe board) and return to F1D1 (below) when done
F1CE CALL \$639F
F1D1 LD L,\$01 Point HL at byte 0x01 of the teacher's buffer
F1D3 LD A,(HL) A=teacher's x-coordinate
F1D4 ADD A,\$03 A=x-coordinate of the middle of the blackboard
F1D6 LD L,\$0B Place this in byte 0x0B of the teacher's buffer, ready for the routine at 63ED
F1D8 LD (HL),A
F1D9 LD BC,\$63ED Redirect control to the routine at 63ED (walk to location) and return to F1DF (below) when done
F1DC CALL \$639F
The teacher has wiped the board, and is ready to start the class.
F1DF CALL \$F048 Is ERIC in class?
F1E2 JP NZ,\$F14D Jump if not
F1E5 CALL \$6291 A=random number
F1E8 LD BC,\$6880 Routine at 6880: write on board
F1EB CP \$B8 Should the teacher write on the board?
F1ED CALL NC,\$639F Redirect control to 6880 if so, and return to F1F0 (below) when done
F1F0 CALL \$F048 Is ERIC in class?
F1F3 JR NZ,\$F1E2 Jump if not
F1F5 CALL \$6291 A=random number
F1F8 CP \$E8 Should this be a questions-and-answers lesson?
F1FA JR C,\$F214 Jump if so
This is not going to be a questions-and-answers lesson.
F1FC CALL \$F05D Tell the class what to do
F1FF CALL \$F048 Is ERIC in class?
F202 JR NZ,\$F1E2 Jump if not
F204 LD L,\$01 Point HL at byte 0x01 of the teacher's buffer
F206 LD A,(HL) A=teacher's x-coordinate
F207 XOR \$03 Now A=x-coordinate of location three paces behind the teacher
F209 LD L,\$0B Place this in byte 0x0B of the teacher's buffer ready for the routine at 63ED
F20B LD (HL),A
F20C LD BC,\$63ED Redirect control to the routine at 63ED (walk to location) and return to F212 (below) when done
F20F CALL \$639F
F212 JR \$F1FF Check whether ERIC's in class, then pace up (or down) again
This is going to be a questions-and-answers lesson. Pick a question-answer word pair, and decide which word will be in the question, and which in the answer.
F214 CALL \$6291 A=random number
F217 AND \$87 Keep only bits 0-2 (the word pair identifier) and bit 7 (indicates which word will be in the question)
F219 PUSH AF Save bit 7 for now
F21A LD C,A
F21B LD DE,\$7F8C Point DE at the first byte of message 0x0A
F21E LD A,H Set A=0xA0 (if the teacher is MR WITHIT), 0xB0 (MR ROCKITT), or 0xC0 (MR CREAK)
F21F SUB D
F224 OR C Now A holds the message number of a random mountain, animal or king
F225 LD (DE),A Place this into 7F8C (message 0x0A)
F226 ADD A,\$08 Set A to the message number of the corresponding country, habitat or date
F228 LD E,\$8E Place this into 7F8E (the first byte of message 0x0B)
F22A LD (DE),A
F22B POP AF Restore the random bit 7 to A
F22C RLCA Push it into the carry flag
F22D SBC A,A Set A to 0x49 or 0x4B (MR WITHIT), 0x4D or 0x4F (MR ROCKITT), 0x51 or 0x53 (MR CREAK); this is the message number for EINSTEIN's reply