Sherlock: annotated disassembly

Routines

Prev: AA71 Up: Map Next: AB91
AAB2: Parse the next sentence from the word list
Called for the player's typed line ($D78F, part of the player's script step D77E) and for the words of a remark ($B8BF). Sorts tokens into the parse record (IY) - the verb and its particles (AB91), objects (AC24) - and dispatches on punctuation: a full stop finishes the sentence (AD57), a comma starts another object or sentence (ACCC), a special word (class $90) goes to AFB3. NZ if it does not make sense (AF67).
How it works:
1. Clear the sentence count and start with every kind of word allowed (E = $FF).
2. Decide the sentence's mode ($A024). If a line of sentences is still being worked through it is an ordinary command (mode 1). Otherwise try to read a noun phrase first (AC24): a sentence that opens with one and has no preposition is a statement such as MRS JONES KILLED TRICIA FENDER (mode 2, subject kept in the parse node); anything else is a command (mode 1) and reading starts again from the beginning.
3. Read the verb and its particles (AB91). Carry means the words make no sense.
4. A special word (token class $90) goes to AFB3. A comma ($A0) starts another sentence (ACCC).
5. Read the objects: each noun phrase (AC24) is filed in the parse node (ACA6), and this repeats as long as noun phrases follow.
6. A full stop ($B0) completes the sentence (AD57). In a statement, any other word must be a relation word (ABF3), which ends the subject and carries on with the object.
7. Anything else makes no sense: return NZ (AF67).
Input
IY The parse node for the sentence
Output
F NZ if the sentence makes no sense (A = 2 for a stray full stop)
AAB2 XOR A Clear A to zero (and the carry flag) - A01A and the sentence count A012 start at 0
AAB3 LD ($A01A),A Store A in A01A in "Game variables"
AAB6 LD ($A012),A Store A in A012 in "Game variables"
AAB9 LD E,$FF Load E with $FF - E: flags for what may come next; D: the token class last read
AABB LD D,$C0 Load D with $C0
This entry point is used by the routine at AD57.
AABD LD A,E Copy E into A
AABE OR $C7 Set bits 0, 1, 2, 6, 7 of A (mask $C7)
AAC0 LD E,A Copy A into E
AAC1 CALL $AE6A A new parse node for this sentence (AE6A)
This entry point is used by the routine at AFFA.
AAC4 LD A,($A01B) Read $A01B in "Game variables" into A - Sentences still waiting from the same line: an ordinary command (mode 1)
AAC7 AND A Test A for zero (this leaves A as it was and clears carry)
AAC8 JR Z,$AAD1 If A is zero, skip ahead to AAD1
AACA LD A,$01 Load A with $01
AACC LD ($A024),A Store A in $A024 in "Game variables"
AACF RES 3,E Clear bit 3 of E
This entry point is used by the routine at B0FD.
AAD1 PUSH DE Save DE on the stack
AAD2 LD A,($A024) Read $A024 in "Game variables" into A - Mode ($A024) not settled: does the sentence open with a noun phrase (AC24)?
AAD5 AND A Test A for zero (this leaves A as it was and clears carry)
AAD6 JR NZ,$AB11 If A is not zero, jump on to AB11
AAD8 LD ($AAA7),A Store A in $AAA7
AADB LD HL,($A02B) Read $A02B in "Game variables" into HL
AADE PUSH HL Save HL on the stack
AADF CALL $AC24 Call the routine "Read a noun phrase into the pattern at $AAA8" (AC24)
AAE2 JR NZ,$AB08 If the zero flag is clear, skip ahead to AB08
AAE4 LD A,($AAA7) Read $AAA7 into A
AAE7 AND A Test A for zero (this leaves A as it was and clears carry)
AAE8 JR NZ,$AB08 If A is not zero, skip ahead to AB08
AAEA LD A,$02 Load A with $02 - Yes, with no preposition: a statement such as 'MRS JONES KILLED TRICIA FENDER' (mode 2); its subject goes to the node at +$18
AAEC LD ($A024),A Store A in $A024 in "Game variables"
AAEF POP HL Restore HL from the stack
AAF0 PUSH IY Save IY on the stack
AAF2 POP HL Restore HL from the stack
AAF3 LD DE,$0018 Load DE with $0018, the amount that is added next
AAF6 ADD HL,DE Add DE to HL
AAF7 LD DE,$AAAC Point DE at $AAAC
AAFA EX DE,HL Swap DE and HL
AAFB LD BC,$0006 Load BC with $0006
AAFE LDIR Copy BC bytes from where HL points to where DE points, counting up
AB00 LD HL,($A029) Read $A029 in "Game variables" into HL
AB03 LD ($A02B),HL Store HL in $A02B in "Game variables"
AB06 JR $AB11 Skip ahead to AB11
AB08 LD A,$01 Load A with $01 - No: an ordinary command (mode 1) - go back to the start of the sentence
AB0A LD ($A024),A Store A in $A024 in "Game variables"
AB0D POP HL Restore HL from the stack
AB0E LD ($A02B),HL Store HL in $A02B in "Game variables"
AB11 POP DE Restore DE from the stack
AB12 XOR A Clear A to zero (and the carry flag)
AB13 LD ($AAA7),A Store A in $AAA7
AB16 CALL $AB91 Call the routine "Read a sentence's verb words into the node at IY" (AB91) - The verb and its particles (AB91); carry: nonsense
AB19 JR C,$AB8E If the carry flag is set, jump on to AB8E
AB1B JR Z,$AB47 If the zero flag is set, jump on to AB47
AB1D CP $90 Compare A with $90 - A special word ($90): handled at AFB3
AB1F JP Z,$AFB3 If A equals $90, jump on to the routine "Is word BC a special word? Then run its handler" (AFB3)
AB22 CP $A0 Compare A with $A0 - A comma ($A0): another sentence (ACCC)
AB24 JP Z,$ACCC If A equals $A0, jump on to the routine "Note where this sentence started, so it can be..." (ACCC)
AB27 BIT 3,E Test bit 3 of E
AB29 JR Z,$AB4C If bit 3 of E is clear, skip ahead to AB4C
AB2B LD A,($A012) Read A012 in "Game variables" into A - No verb at the very start of a line, just a full stop: return NZ with A = 2
AB2E AND A Test A for zero (this leaves A as it was and clears carry)
AB2F JR NZ,$AB8E If A is not zero, jump on to AB8E
AB31 LD A,($A01B) Read $A01B in "Game variables" into A
AB34 AND A Test A for zero (this leaves A as it was and clears carry)
AB35 JR NZ,$AB4C If A is not zero, skip ahead to AB4C
AB37 LD A,($A02D) Read $A02D in "Game variables" into A
AB3A CP $C0 Compare A with $C0
AB3C JR NZ,$AB8E If A differs from $C0, jump on to AB8E
AB3E LD A,$B0 Load A with $B0
AB40 CP D Compare A with D
AB41 JR NZ,$AB8E If A differs from D, jump on to AB8E
AB43 LD A,$02 Load A with $02
AB45 AND A Clear the carry flag for the caller (A is unchanged)
AB46 RET Return to the caller
AB47 BIT 3,E Test bit 3 of E - No verb and no more allowed: on to ACFB
AB49 JP Z,$ACFB If bit 3 of E is clear, jump on to the routine "After a sentence: copy the objects on, or rewind..." (ACFB)
This entry point is used by the routine at ACFB.
AB4C LD HL,($A029) Read $A029 in "Game variables" into HL - Objects: read a noun phrase (AC24) and file it in the node (ACA6), as long as they come
AB4F LD ($A02B),HL Store HL in $A02B in "Game variables"
This entry point is used by the routine at B01C.
AB52 CALL $AC24 Call the routine "Read a noun phrase into the pattern at $AAA8" (AC24)
AB55 JR C,$AB8E If the carry flag is set, jump on to AB8E
AB57 JR NZ,$AB60 If the zero flag is clear, skip ahead to AB60
AB59 CALL $ACA6 Call the routine "Copy the noun-phrase pattern into the node: first or..." (ACA6)
AB5C JR Z,$AB8E If the zero flag is set, jump on to AB8E
AB5E JR $AB4C Go back to AB4C
AB60 CP $B0 Compare A with $B0 - A full stop ($B0): the sentence is complete (AD57)
AB62 JP Z,$AD57 If A equals $B0, jump on to the routine "Count the sentence, then on to the next or finish" (AD57)
AB65 CP $A0 Compare A with $A0
AB67 JP Z,$ACCC If A equals $A0, jump on to the routine "Note where this sentence started, so it can be..." (ACCC)
AB6A CP $90 Compare A with $90
AB6C JP Z,$AFB3 If A equals $90, jump on to the routine "Is word BC a special word? Then run its handler" (AFB3)
AB6F LD HL,($A029) Read $A029 in "Game variables" into HL - Anything else is only allowed in a statement: a relation word (ABF3) starts the next part
AB72 LD ($A02B),HL Store HL in $A02B in "Game variables"
AB75 LD A,($A024) Read $A024 in "Game variables" into A
AB78 CP $02 Compare A with $02
AB7A JR NZ,$AB8E If A differs from $02, skip ahead to AB8E
AB7C CALL $ABF3 Call ABF3 (inside "Read a sentence's verb words into the node...")
AB7F JR C,$AB8E If the carry flag is set, skip ahead to AB8E
AB81 JR NZ,$AB8E If the zero flag is clear, skip ahead to AB8E
AB83 LD HL,($A029) Read $A029 in "Game variables" into HL
AB86 LD ($A02B),HL Store HL in $A02B in "Game variables"
AB89 LD D,$A0 Load D with $A0
AB8B JP $ACCC Jump on to the routine "Note where this sentence started, so it can be..." (ACCC)
AB8E JP $AF67 It makes no sense (AF67)
Prev: AA71 Up: Map Next: AB91