Sherlock: annotated disassembly

Routines

Prev: D7E1 Up: Map Next: D87D
D7FA: Player's turn: turn the sentence into a command (RUN at $993C)
Addresses named in the title: 993C.
Part of the player's own script (see 993C): parses the sentence at 9FF2 into a verb and objects (B191) and copies them into the plan registers (9FD6-9FD8), where the script's DO picks them up. With ALL ($A01C, kept in D6B8 between turns) the sentence is kept so that the next turn takes the next thing; otherwise its node is freed, with any BUT nodes after it. If the sentence does not parse, an ALL that has run out of things fails quietly (DC15, with $A033 = $FF); anything else sets D7E0 so that the rest of the line is thrown away (D7E1).
This record is one step of the loop in the player's own plan script at 9921: DO LOOK once, then read a line (D6BF), split it into words (D715), check there is a word (D769), parse a sentence (D77E), check there is a sentence (D7D9), turn it into a command (D7FA) and DO it. When you wear the china man's disguise the same script runs for him; the counts below include both.
How it works:
1. Carry the ALL flag over from the last turn and take the sentence at 9FF2.
2. Parse it into a verb and objects (B191). If that fails, set the failure flag and finish.
3. Put the verb and objects in the plan registers (9FD6, 9FD7), and note where the ALL search got to.
4. If ALL is still going keep the sentence; otherwise unhook and free its node.
Input
$9FF2 The sentence
Output
$9FD6 The verb
$9FD7 The objects
F Z if the sentence could not be made into a command
D7FA DEFB $00,$00 Action record header: flags $00; byte 1 $00
D7FC XOR A Clear A to zero (and the carry flag)
D7FD LD A,($D6B8) Read "A flag of the player's script step, and spare..." (D6B8) into A - Carry the ALL flag over from the last turn
D800 LD ($A01C),A Store A in $A01C in "Game variables"
D803 LD IY,($9FF2) Read 9FF2 in "Game variables" into IY - IY = the sentence; where the ALL search had got to (D6BB -> $B17E)
D807 LD HL,($D6BB) Read D6BB in "A flag of the player's script step, and..." into HL
D80A LD ($B17E),HL Store HL in $B17E in "Parser variables"
D80D CALL $B191 Parse it into a verb and objects (B191)
D810 LD A,$01 Load A with $01 - (failures now count: $A00B = 1)
D812 LD ($A00B),A Store A in $A00B in "Game variables"
D815 JP Z,$D85B If the zero flag is set, jump on to D85B
D818 LD A,($A01C) Read $A01C in "Game variables" into A - Parsed: keep the ALL flag for next turn
D81B LD ($D6B8),A Store A in "A flag of the player's script step, and spare..." (D6B8)
D81E LD A,$01 Load A with $01 - The next letter printed is a capital ($A026)
D820 LD ($A026),A Store A in $A026 in "Game variables"
D823 LD A,($A033) Read $A033 in "Game variables" into A - The verb and objects into the plan registers
D826 LD ($9FD6),A Store A in the plan's verb (9FD6)
D829 LD HL,($A034) Read $A034 in "Game variables" into HL
D82C LD ($9FD7),HL Store HL in the plan's direct object (9FD7)
D82F LD HL,($B17E) Read $B17E in "Parser variables" into HL - Note where the ALL search got to
D832 LD ($D6BB),HL Store HL in D6BB in "A flag of the player's script step, and..."
D835 LD A,($D6B8) Read "A flag of the player's script step, and spare..." (D6B8) into A - ALL still going: keep the sentence
D838 AND A Test A for zero (this leaves A as it was and clears carry)
D839 JR NZ,$D858 If A is not zero, skip ahead to D858
D83B LD IX,($9FF2) Read 9FF2 in "Game variables" into IX - Otherwise unhook and free its node...
D83F LD L,(IX-$02) Read byte -2 of the record at IX into L
D842 LD H,(IX-$01) Read byte -1 of the record at IX into H
D845 LD ($9FF2),HL Store HL in 9FF2 in "Game variables"
D848 CALL $A1C7 Call the routine "Free node IX back to the heap" (A1C7)
D84B LD A,L Copy L into A
D84C OR H Set in A the bits that are set in H
D84D JR Z,$D858 If the result is zero, skip ahead to D858
D84F PUSH HL Save HL on the stack - ...and any nodes after it marked with bit 6 (BUT)
D850 POP IX Restore IX from the stack
D852 BIT 6,(IX+$01) Test bit 6 of byte +1 of the record at IX
D856 JR NZ,$D83F If bit 6 of byte +1 of the record at IX is set, go back to D83F
D858 OR $01 Make A non-zero, which clears the zero flag, and hand that back to the caller - Succeed
D85A RET Return to the caller
D85B XOR A Clear A to zero (and the carry flag) - Did not parse: the ALL is over
D85C LD ($D6B8),A Store A in "A flag of the player's script step, and spare..." (D6B8)
D85F LD A,($A01C) Read $A01C in "Game variables" into A - It was an ALL: no verb ($A033 = $FF), drop the sentence and fail quietly
D862 AND A Test A for zero (this leaves A as it was and clears carry)
D863 JR Z,$D870 If A is zero, skip ahead to D870
D865 LD A,$FF Load A with $FF
D867 LD ($A033),A Store A in $A033 in "Game variables"
D86A CALL $D835 Call D835 (inside "Player's turn: turn the sentence into a...")
D86D JP $DC15 Jump on to the routine "Fail: A = 0, HL = 0, Z set" (DC15)
D870 LD A,$01 Load A with $01 - Otherwise drop the rest of the line (D7E0) and end the word list there
D872 LD ($D7E0),A Store A in "A flag for D7E1" (D7E0)
D875 PUSH HL Save HL on the stack
D876 LD HL,($D6BD) Read D6BD in "A flag of the player's script step, and..." into HL
D879 LD (HL),$C0 Store $C0 at the address HL points to
D87B POP HL Restore HL from the stack
D87C RET Return to the caller
Prev: D7E1 Up: Map Next: D87D