Prev: 7A2A Up: Map Next: 7AD7
7A32: Prepare a question and answer
Used by the routine at F400. Prepares a question message and stores its address in bytes 0x6B and 0x6C of the teacher's buffer; also prepares the answer message and stores its address in bytes 0x6B and 0x6C of EINSTEIN's buffer. Places the address of the interruptible subcommand routine at 7986 (make character speak) into bytes 0x69 and 0x6A of the teacher's buffer before returning.
Input
H Teacher's character number (0xA3-0xA6)
7A32 PUSH HL Save the teacher's character number
7A33 LD A,H A=teacher's character number
7A34 CP $A3 Is it MR WACKER?
7A36 JR NZ,$7A92 Jump if not
MR WACKER is conducting this lesson, so we have to prepare a multiplication question and answer. First, generate two random numbers and store the ASCII codes of their digits in the question message.
7A38 LD HL,$F008 HL=F008: the '12' in 'WHAT IS 12 x 34?'
7A3B LD B,$02 There are two numbers to generate
7A3D LD C,A Store the second (the multiplier) in C on pass 2
7A3E CALL $61A1 Collect a random number between 32 and 99 in A
7A41 AND $7F
7A43 CP $64
7A45 JR NC,$7A3E
7A47 CP $20
7A49 JR C,$7A3E
7A4B PUSH AF Store this number temporarily
7A4C LD (HL),$2F Insert the ASCII codes for the digits of the number into the 'WHAT IS 12 x 34?' message
7A4E INC (HL)
7A4F SUB $0A
7A51 JR NC,$7A4E
7A53 ADD A,$3A
7A55 INC L
7A56 LD (HL),A
7A57 POP AF Restore the number to A
7A58 LD L,$0D HL=F00D: the '34' in 'WHAT IS 12 x 34?'
7A5A DJNZ $7A3D Jump back to insert the multiplier into the message
Now multiply the two numbers, and store the ASCII codes of the digits of the product in the answer message.
7A5C LD DE,$0000 HL=0 (ready for multiplication), and DE=F017 (the '1234' in EINSTEIN's response message)
7A5F LD L,$17
7A61 EX DE,HL
7A62 ADD HL,BC HL=the product of the two numbers
7A63 DEC A
7A64 JR NZ,$7A62
7A66 LD BC,$FC18 Calculate the 1000s digit and store its ASCII code in the appropriate spot
7A69 INC A
7A6A ADD HL,BC
7A6B JR C,$7A69
7A6D SBC HL,BC
7A6F ADD A,$2F
7A71 LD (DE),A
7A72 LD BC,$FF9C Calculate the 100s digit and store its ASCII code in the appropriate spot
7A75 LD A,$2F
7A77 INC A
7A78 ADD HL,BC
7A79 JR C,$7A77
7A7B SBC HL,BC
7A7D INC E
7A7E LD (DE),A
7A7F LD A,L Calculate the 10s digit and store its ASCII code in the appropriate spot
7A80 EX DE,HL
7A81 INC L
7A82 LD (HL),$2F
7A84 INC (HL)
7A85 SUB $0A
7A87 JR NC,$7A84
7A89 ADD A,$3A Store the ASCII code of the units digit in the appropriate spot
7A8B INC L
7A8C LD (HL),A
7A8D LD HL,$7A18 This is the base address of the data table used for MR WACKER's questions and answers
7A90 JR $7AC0
Some teacher other than MR WACKER is conducting this lesson.
7A92 SUB $A4 A=0 (MR ROCKITT), 1 (MR WITHIT), or 2 (MR CREAK)
7A94 CALL $F923 Make MR CREAK ask the birth year question if appropriate
7A97 LD B,$80
7A99 JR Z,$7AA6 Jump if we're dealing with MR ROCKITT
7A9B LD B,$AA
7A9D LD L,$22 HL=7A22
7A9F DEC A Are we dealing with MR WITHIT?
7AA0 JR Z,$7AA6 Jump if so
7AA2 LD L,$2A HL=7A2A
7AA4 LD B,$D4
Now HL points at one of the data tables at 7A1A (MR ROCKITT), 7A22 (MR WITHIT) and 7A2A (MR CREAK). Each data table contains eight LSBs: four LSBs for each type of question. The LSBs correspond to (1) the identifier slot in the teacher's question; (2) the identifier slot in EINSTEIN's answer; (3) the base address of EINSTEIN's answer; and (4) the base address of the teacher's question.
7AA6 CALL $61A1 Get a random number between 0x00 and 0x29 in A
7AA9 CP $2A
7AAB JR NC,$7AA6
7AAD ADD A,B A=0x80-0xA9 (MR ROCKITT), 0xAA-0xD3 (MR WITHIT), or 0xD4-0xFD (MR CREAK)
7AAE BIT 0,A There are two types of question the teacher can ask; here we decide which one
7AB0 JR Z,$7AB6
7AB2 INC L Move forward four spaces in the data table to the LSBs for the second type of question
7AB3 INC L
7AB4 INC L
7AB5 INC L
7AB6 LD D,$F0 Insert the random identifier into the teacher's question
7AB8 LD E,(HL)
7AB9 LD (DE),A
7ABA INC L Insert the corresponding random identifier into EINSTEIN's answer
7ABB LD E,(HL)
7ABC XOR $01
7ABE LD (DE),A
7ABF INC L
7AC0 LD E,(HL) Store the address of the answer message in bytes 0x6B and 0x6C of EINSTEIN's buffer
7AC1 LD D,$F0
7AC3 LD ($A96B),DE
7AC7 INC L
7AC8 LD E,(HL) DE=address of the question message
This entry point is used by the routine at F923.
7AC9 POP HL Restore the teacher's character number to H
7ACA LD L,$6B Store the address of the question message in bytes 0x6B and 0x6C of the teacher's buffer
7ACC LD (HL),E
7ACD INC L
7ACE LD (HL),D
7ACF LD L,$6A Place the address of the interruptible subcommand routine at 7986 (make character speak) into bytes 0x69 and 0x6A of the teacher's buffer
7AD1 LD (HL),$79
7AD3 DEC L
7AD4 LD (HL),$86
7AD6 RET
Prev: 7A2A Up: Map Next: 7AD7