| Routines

680F: Make a teacher wipe a blackboard

The address of this interruptible subcommand routine is placed into bytes 0x09 and 0x0A of the teacher's buffer by the routine at F100.
Input
H | Teacher's character number (0xC9-0xCC)
680F | CALL $6FF2 | Collect information about the board
6812 | LD L,$0B | 32 distinct actions are needed to wipe the board; store this counter in byte 0x0B of the teacher's buffer
6814 | LD (HL),$20
6816 | INC L | L=0x0C
6817 | LD A,E | A=x-coordinate of the left edge of the board
6818 | ADD A,$07 | A=x-coordinate of the right edge of the board
681A | LD (HL),A | Store this in byte 0x0C of the teacher's buffer
681B | INC L | Place the y-coordinate of the top line of the board into byte 0x0D of the teacher's buffer
681C | LD (HL),D
681D | INC L | And the board identifier (LSB of 7F54, 7F5A, 7F60, 7F66 or 7F6C) into byte 0x0E
681E | LD (HL),B
681F | LD L,$09 | Change the routine address in bytes 0x09 and 0x0A of the teacher's buffer to 6823 (below)
6821 | LD (HL),$23
6823 | LD L,$0B | Byte 0x0B holds the board-wiping action counter
6825 | DEC (HL) | Decrement the counter
6826 | JP P,$6836 | Jump if the board has not yet been fully wiped
The teacher has finished wiping the board. Mark the board as clean, and move the teacher on to his next task.
6829 | LD L,$0E | Collect the board identifier in L
682B | LD L,(HL)
682C | LD H,$7F | HL now points to the board's buffer
682E | LD (HL),$00 | Signal that the board has been wiped by zeroing the first two bytes of the blackboard's buffer
6830 | INC L
6831 | LD (HL),$00
6833 | JP $6390 | Now the job's been done, terminate this interruptible subcommand
The board's not clean yet. Work out what the teacher has to do next: wipe, or move down the board to the next spot.
6836 | CALL $61B4 | Update the SRB for the teacher's current animatory state and location
6839 | AND $78 | A=teacher's base animatory state
683B | LD L,$0B | Point HL at the board-wiping action counter
683D | BIT 0,(HL) | Is the teacher midstride or wiping (arm up)?
683F | JR Z,$6876 | Jump if so
6841 | BIT 1,(HL) | Are we ready for a wipe action?
6843 | JR Z,$6849 | Jump if so
6845 | INC A | A=animatory state of the teacher midstride
6846 | JP $6130 | Update the teacher's animatory state and update the SRB
The teacher's next action will be a wipe, so raise his arm.
6849 | ADD A,$07 | A=animatory state of the teacher with his arm up
684B | CALL $6130 | Update the teacher's animatory state and update the SRB
684E | LD L,$0C | Collect the x-coordinate of the part of the board to be wiped into E
6850 | LD E,(HL)
6851 | DEC (HL) | Decrease this x-coordinate ready for the next wipe
6852 | INC L | Collect the y-coordinate of the top line of the blackboard into D
6853 | LD D,(HL)
6854 | CALL $670C | Update the SRB for the top line of the blackboard
6857 | INC D | D=y-coordinate of the bottom line of the blackboard
6858 | CALL $670C | Update the SRB for the bottom line of the blackboard
685B | LD A,D | Prepare H for picking up skool UDG base address LSBs later
685C | ADD A,$A0
685E | LD H,A
685F | LD D,$B5 | Pick up the Q value (0x00<=Q<=0x8F) for the lower blackboard tile being wiped from page 0xB5 in L
6861 | LD A,(DE)
6862 | LD L,A
6863 | LD A,(HL) | Collect the LSB of the base address of the skool UDG for this blackboard tile in L
6864 | LD L,A
6865 | SUB $08 | Set E to the LSB of the base address of the skool UDG for the upper blackboard tile
6867 | LD E,A
6868 | LD H,$80 | The base page for all blackboard tile UDGs is 0x80
686A | LD D,H
686B | LD B,$08 | 8 lines per character square
686D | LD A,$FF | 0xFF=blank blackboard byte
686F | LD (HL),A | Clear a pixel line in the skool UDG for the lower blackboard tile
6870 | LD (DE),A | Clear a pixel line in the skool UDG for the upper blackboard tile
6871 | INC H | Next pixel row of the lower blackboard tile UDG
6872 | INC D | Next pixel row of the upper blackboard tile UDG
6873 | DJNZ $686F | Jump back until the two blackboard tile UDGs have been cleared
6875 | RET |
The teacher is either wiping or midstride while on his way to the next spot along the board. At this point, A holds the teacher's base animatory state.
6876 | BIT 1,(HL) | Is the teacher wiping?
6878 | JR Z,$687B | Jump if so
687A | DEC E | The teacher is midstride, so now move him one space to the left
687B | JP $6130 | Update the teacher's animatory state and location and update the SRB