Sherlock: annotated disassembly

Routines

Prev: A360 Up: Map Next: A419
A37D: Print the rest of a narrated command: verb words, objects, numbers
Part of A2E4. From the verb pattern (A2B1/A2BD) and the parse flags ($A01D/$A01E) prints the verb's words (A880), then the direct object - as a number or money (A419) when it is one ($FE), as ME when it is the actor, or by name (A745) - then any preposition and the indirect object the same way, and a full stop.
How it works:
1. Look up the remembered command's verb record and flags (A2B1, A2BD, C493, C4B2).
2. Print the verb's words: the pair at +6 of the record, then the pair at +0 (A880).
3. If the verb takes a direct object (flags bit 3): print any word that goes before it, then the object itself - a number or sum of money (A419) if it is one, ME if it is the actor, or its name (A745).
4. If there is an indirect object and the flags allow one: print its preposition, then the object the same three ways.
5. End with a full stop. The result is a sentence such as 'You pay 2/6 to Watson.'
Input
$A35D The remembered command: verb, direct object, indirect object
A37D XOR A Clear A to zero (and the carry flag) - No article flag; the remembered command's verb...
A37E LD ($A028),A Store A in $A028 in "Game variables"
A381 LD A,($A35D) Read "A remembered command: verb, direct object,..." (A35D) into A
A384 CALL $A2B1 Call the routine "HL = verb A's record in the verb table" (A2B1) - ...gives its record in the verb table (A2B1) and its flags (A2BD, $A01D/$A01E)
A387 PUSH HL Save HL on the stack
A388 POP IX Restore IX from the stack
A38A PUSH HL Save HL on the stack
A38B CALL $A2BD Call the routine "Gather a verb record's flag nibbles into $A01D and..." (A2BD)
A38E CALL $C493 Call the routine "Set the direct object's requirement from the parsed..." (C493) - (C493, C4B2: also from the record)
A391 CALL $C4B2 Call the routine "Set the indirect object's requirement from the parsed..." (C4B2)
A394 POP HL Restore HL from the stack
A395 LD A,($A01D) Read $A01D in "Game variables" into A
A398 LD C,A Copy A into C
A399 PUSH HL Save HL on the stack - Print the verb's words: the pair at +6, then the pair at +0 (A880)
A39A LD DE,$0006 Load DE with $0006, the amount that is added next
A39D ADD HL,DE Add DE to HL
A39E CALL $A880 Call the routine "Print the dictionary word that HL refers to" (A880)
A3A1 POP HL Restore HL from the stack
A3A2 CALL $A880 Call the routine "Print the dictionary word that HL refers to" (A880)
A3A5 BIT 3,C Test bit 3 of C - Flags bit 3: the verb takes a direct object
A3A7 JR Z,$A3E2 If bit 3 of C is clear, jump on to A3E2
A3A9 BIT 5,C Test bit 5 of C - A word before it (bit 5), and one more if $A01E bit 7 is set
A3AB CALL NZ,$A880 If bit 5 of C is set, call the routine "Print the dictionary word that HL refers to" (A880)
A3AE LD A,($A01E) Read $A01E in "Game variables" into A
A3B1 BIT 7,A Test bit 7 of A
A3B3 CALL NZ,$A880 If bit 7 of A is set, call the routine "Print the dictionary word that HL refers to" (A880)
A3B6 LD A,($A35E) Read A35E in "A remembered command: verb, direct object,..." into A - A number or a sum of money ($FE): print it (A419)
A3B9 CP $FE Compare A with $FE
A3BB JR NZ,$A3C7 If A differs from $FE, skip ahead to A3C7
A3BD PUSH HL Save HL on the stack
A3BE LD HL,($A02F) Read $A02F in "Game variables" into HL
A3C1 CALL $A419 Call the routine "Print an amount of money" (A419)
A3C4 POP HL Restore HL from the stack
A3C5 JR $A3E2 Skip ahead to A3E2
A3C7 PUSH HL Save HL on the stack - The actor itself: ME ($055B)
A3C8 LD HL,$A036 Point HL at $A036 in "Game variables"
A3CB CP (HL) Compare A with the byte at $A036 in "Game variables"
A3CC JR NZ,$A3D6 If A differs from the byte at $A036 in "Game variables", skip ahead to A3D6
A3CE LD DE,$055B Load DE with $055B
A3D1 CALL $A887 Call A887 (inside "Print the dictionary word that HL refers to")
A3D4 JR $A3E1 Skip ahead to A3E1
A3D6 LD A,($A00F) Read $A00F in "Game variables" into A - Otherwise its name: a room for requirement codes below 5, else a thing (A745)
A3D9 CP $05 Compare A with $05
A3DB LD A,($A35E) Read A35E in "A remembered command: verb, direct object,..." into A
A3DE CALL $A745 Call the routine "Name room or thing A" (A745)
A3E1 POP HL Restore HL from the stack
A3E2 LD A,($A35F) Read A35F in "A remembered command: verb, direct object,..." into A - An indirect object, if there is one and the flags (bit 2) allow it
A3E5 CP $FF Compare A with $FF
A3E7 JR Z,$A414 If A equals $FF, jump on to A414
A3E9 BIT 2,C Test bit 2 of C
A3EB JR Z,$A414 If bit 2 of C is clear, jump on to A414
A3ED BIT 5,C Test bit 5 of C - Its preposition: the words not printed before
A3EF CALL Z,$A880 If bit 5 of C is clear, call the routine "Print the dictionary word that HL refers to" (A880)
A3F2 LD A,($A01E) Read $A01E in "Game variables" into A
A3F5 BIT 7,A Test bit 7 of A
A3F7 CALL Z,$A880 If bit 7 of A is clear, call the routine "Print the dictionary word that HL refers to" (A880)
A3FA LD A,($A35F) Read A35F in "A remembered command: verb, direct object,..." into A - A number or money (A419), or a name (A745)
A3FD CP $FE Compare A with $FE
A3FF JR NZ,$A409 If A differs from $FE, skip ahead to A409
A401 LD HL,($A031) Read $A031 in "Game variables" into HL
A404 CALL $A419 Call the routine "Print an amount of money" (A419)
A407 JR $A414 Skip ahead to A414
A409 LD A,($A010) Read $A010 in "Game variables" into A
A40C CP $05 Compare A with $05
A40E LD A,($A35F) Read A35F in "A remembered command: verb, direct object,..." into A
A411 CALL $A745 Call the routine "Name room or thing A" (A745)
This entry point is used by the routines at BB67, D113, D526, D60B and D68C.
A414 LD A,$2E Load A with $2E - And a full stop
A416 JP $A9B7 Jump on to the routine "Print character A, a word at a time (word wrap)" (A9B7)
Prev: A360 Up: Map Next: A419