| Routines

29160: Make a teacher wipe a blackboard (2)

Continues from 29148.
Input
A | Blackboard identifier (236, 238 or 240)
DE | Coordinates of the top-left corner of the blackboard
H | Teacher's character number (163-166)
29160 | LD L,105 | Replace the address of the interruptible subcommand routine at 29148 in bytes 105 and 106 of the teacher's buffer with 29175 (below)
29162 | LD (HL),247
29164 | LD L,107 | Wiping a blackboard requires 32 distinct actions (in 8 groups of 4: two paces forward, arm up, arm down)
29166 | LD (HL),32
29168 | INC L | Store the x-coordinate of the rightmost column of the blackboard (which will be wiped first) in byte 108 of the teacher's buffer
29169 | LD A,E
29170 | ADD A,7
29172 | LD (HL),A
29173 | INC L | Store the y-coordinate of the top row of the blackboard in byte 109 of the teacher's buffer
29174 | LD (HL),D
After the initial call to this routine, each subsequent call enters here.
29175 | LD L,107 | Decrement the number of board-wiping actions remaining
29177 | DEC (HL)
29178 | BIT 7,(HL) | Has the teacher finished wiping the board?
29180 | JR NZ,29264 | Jump if so
29182 | CALL 25108 | Update the SRB for the teacher's current location
29185 | LD L,107 | Is the teacher midstride or is his arm raised?
29187 | BIT 0,(HL)
29189 | JR Z,29248 | Jump if so
29191 | BIT 1,(HL) | Is the teacher ready to raise his arm (and wipe)?
29193 | JR Z,29199 | Jump if so
29195 | INC A | A=animatory state of the teacher midstride
29196 | JP 25008 | Update the teacher's animatory state and update the SRB
The teacher is ready to raise his arm and wipe a column of the board.
29199 | ADD A,5 | A=animatory state of the teacher with his arm raised
29201 | CP 72 | Are we actually dealing with a teacher?
29203 | JR NC,29207 | Jump if so
29205 | ADD A,8 | If ANGELFACE or BOY WANDER were wiping the board, A would now hold the animatory state of the boy with his arm raised
29207 | CALL 25008 | Update the teacher's animatory state and update the SRB
29210 | LD L,108 | E=x-coordinate of the blackboard column to wipe
29212 | LD E,(HL)
29213 | DEC (HL) | Decrement the blackboard column x-coordinate
29214 | INC L | D=y-coordinate of the top row of the blackboard column to wipe
29215 | LD D,(HL)
29216 | CALL 28807 | Update the SRB for the upper and lower character squares of the blackboard column that will be wiped
29219 | INC D
29220 | CALL 28807
29223 | LD A,(DE) | L=skool UDG reference for the lower character square of the blackboard column
29224 | LD L,A
29225 | ADD A,8 | E=skool UDG reference for the upper character square of the blackboard column
29227 | LD E,A
29228 | LD H,128 | Point HL at the base address of the UDG data for the lower character square of the blackboard column, and DE at the base address of the UDG data for the upper character square of the blackboard column
29230 | CP 233
29232 | JR NC,29236
29234 | LD H,136
29236 | LD D,H
29237 | LD B,8 | There are 8 bytes in a UDG
29239 | LD A,255 | All bits set means clean (no chalk)
29241 | LD (HL),A | Wipe the blackboard column clean by altering the skool UDG data directly
29242 | LD (DE),A
29243 | INC H
29244 | INC D
29245 | DJNZ 29241
29247 | RET |
The teacher is midstride or his arm is raised.
29248 | AND 248 | A=base animatory state of the teacher
29250 | CP 72 | Are we actually dealing with a teacher?
29252 | JR NC,29256 | Jump if so
29254 | AND 240 | If ANGELFACE or BOY WANDER were wiping the board, A would now hold the base animatory state of the boy
29256 | BIT 1,(HL) | Is the teacher's arm raised?
29258 | JR Z,29261 | Jump if so
29260 | DEC E | The teacher was midstride, so move him forward to the next blackboard column
29261 | JP 25008 | Update the teacher's animatory state and location and update the SRB
The teacher has finished wiping the board.
29264 | CALL 28968 | A=identifier of the blackboard the teacher is next to
29267 | LD L,A | HL=32748 (Reading Room blackboard), 32750 (White Room blackboard), or 32752 (Exam Room blackboard)
29268 | LD H,127
29270 | LD (HL),1 | The first clean pixel column is now column no. 1
29272 | INC L | Signal: no one has written on this blackboard
29273 | LD (HL),0
29275 | JP 25252 | Terminate this interruptible subcommand