| Routines

31996: Make a teacher tell the kids to go to a certain page in their books

Used by the routines at 32048 and 62208. Makes the teacher tell the kids to turn to or answer the questions on a randomly chosen page of their books.
Input
H | Teacher's character number (163-166)
31996 | LD DE,62063 | BC=62050 (TURN TO PAGE 123 OF YOUR BOOKS...); DE=62063 (the '123' in this message)
31999 | LD C,98
32001 | LD B,D
32002 | CALL 24993 | A=random number
32005 | RLCA | This jump (which decides between the message at 62050 and the message at 62109) is performed half the time
32006 | JR C,32012
32008 | LD E,186 | BC=62109 (ANSWER THE QUESTIONS ON PAGE 123 OF YOUR LOVELY TEXTBOOK); DE=62138 (the '123' in this message)
32010 | LD C,157
32012 | SCF | A=128-255 (random page number to insert into the message)
32013 | RRA
32014 | NOP |
32015 | EX DE,HL | Point HL at the slot for the 100s digit of the page number in the message
32016 | LD (HL),47 | Compute and insert the ASCII code for the 100s digit of the page number
32018 | INC (HL)
32019 | SUB 100
32021 | JR NC,32018
32023 | INC L | Point HL at the slot for the 10s digit of the page number
32024 | ADD A,100 | Compensate for the trial subtraction of 100 above
32026 | LD (HL),47 | Compute and insert the ASCII code for the 10s digit of the page number
32028 | INC (HL)
32029 | SUB 10
32031 | JR NC,32028
32033 | INC L | Point HL at the slot for the units digit of the page number
32034 | ADD A,58 | Compensate for the trial subtraction of ten above, and add an extra 48 (the ASCII code for '0')
32036 | LD (HL),A | Insert the ASCII code for the units digit of the page number
32037 | EX DE,HL | Restore the teacher's character number to H
This entry point is used by the routines at 32048, 32132, 62208, 63456, 63488 and 63990.
32038 | LD L,108 | Place the address of the message into bytes 107 and 108 of the character's buffer
32040 | LD (HL),B
32041 | DEC L
32042 | LD (HL),C
32043 | LD BC,31110 | Place the address of the interruptible subcommand routine at 31110 (make character speak) into bytes 105 and 106 of the character's buffer and jump to it
32046 | JR 31985