Sherlock: annotated disassembly

Routines

Prev: B0EE Up: Map Next: B16D
B0FD: Handlers for THATS, HE, IT and THEY
Pronouns: HE sets bit 7 and IT/THEY bit 6 of the current parse record's +$19 (used only when Watson or Lestrade weigh a statement: BD7E then takes the statement's subject from $9FF6, the last person a statement named, for HE, or from $9FFC, the last thing, for IT/THEY); the first-word versions (B135, B151) also mark the sentence as a statement to a character ($A024 = 2). THATS (B0FD) rearranges the parse record's object slots.
So pronouns are for statements, not commands.
Input
E Parse flags (bit 3: a clause has finished)
IY The sentence node
Output
E Bits 0 to 2, 6 and 7 set
IY The node that took the pronoun's words
B0FD LD BC,$0008 Load BC with $0008 - THATS: E bit 3 clear - the noun phrase before it belongs to the last node
B100 BIT 3,E Test bit 3 of E
B102 JR NZ,$B107 If bit 3 of E is set, skip ahead to B107
B104 CALL $AEC6 (step back to it, AEC6)
B107 PUSH IY Save IY on the stack - HL = that node's first group (+8)
B109 POP HL Restore HL from the stack
B10A ADD HL,BC Add BC to HL
B10B PUSH DE Save DE on the stack
B10C PUSH HL Save HL on the stack
B10D BIT 3,E Test bit 3 of E - Then move on to the next node, and set E bit 3
B10F JR NZ,$B118 If bit 3 of E is set, skip ahead to B118
B111 SET 3,E Set bit 3 of E
B113 CALL $AEA9 Call the routine "IY = the next node in the list (Z at the end)" (AEA9)
B116 JR $B11F Skip ahead to B11F
B118 LD HL,$A012 Point HL at A012 in "Game variables" - E bit 3 set: count a sentence and start a new node (AE6A)
B11B INC (HL) Add one to the byte at A012 in "Game variables"
B11C CALL $AE6A Call the routine "Add a new node to the end of the sentence list" (AE6A)
B11F PUSH IY Save IY on the stack - Copy the first group into the new node's third group (+24)
B121 POP HL Restore HL from the stack
B122 LD BC,$0018 Load BC with $0018, the amount that is added next
B125 ADD HL,BC Add BC to HL
B126 POP DE Restore DE from the stack
B127 EX DE,HL Swap DE and HL
B128 LD BC,$0006 Load BC with $0006
B12B LDIR Copy BC bytes from where HL points to where DE points, counting up
B12D POP DE Restore DE from the stack
B12E LD A,E Copy E into A - Back to the parser with E bits 0-2, 6 and 7 set
B12F OR $C7 Set bits 0, 1, 2, 6, 7 of A (mask $C7)
B131 LD E,A Copy A into E
B132 JP $AAD1 Go back to AAD1
B135 CALL $AFE1 Call the routine "Handler guards: only at the start of a sentence (not..." (AFE1) - HE as the first word: a statement ($A024 = 2)
B138 LD A,$02 Load A with $02
B13A LD ($A024),A Store A in $A024 in "Game variables"
B13D JR $B14B Skip ahead to B14B
B13F BIT 3,E Test bit 3 of E - HE later on: after a finished clause (E bit 3), a new node
B141 JR Z,$B14B If bit 3 of E is clear, skip ahead to B14B
B143 PUSH DE Save DE on the stack
B144 CALL $AEA9 Call the routine "IY = the next node in the list (Z at the end)" (AEA9)
B147 CALL $AE6A Call the routine "Add a new node to the end of the sentence list" (AE6A)
B14A POP DE Restore DE from the stack
B14B SET 7,(IY+$19) Set bit 7 of byte +25 of the record at IY - Mark the node: HE (+25 bit 7)
B14F JR $B12E Go back to B12E
B151 CALL $AFE1 Call the routine "Handler guards: only at the start of a sentence (not..." (AFE1) - IT or THEY as the first word: a statement
B154 LD A,$02 Load A with $02
B156 LD ($A024),A Store A in $A024 in "Game variables"
B159 JR $B167 Skip ahead to B167
B15B BIT 3,E Test bit 3 of E - Later on: a new node after a finished clause
B15D JR Z,$B167 If bit 3 of E is clear, skip ahead to B167
B15F PUSH DE Save DE on the stack
B160 CALL $AEA9 Call the routine "IY = the next node in the list (Z at the end)" (AEA9)
B163 CALL $AE6A Call the routine "Add a new node to the end of the sentence list" (AE6A)
B166 POP DE Restore DE from the stack
B167 SET 6,(IY+$19) Set bit 6 of byte +25 of the record at IY - Mark the node: IT or THEY (+25 bit 6)
B16B JR $B12E Go back to B12E
Prev: B0EE Up: Map Next: B16D