Sherlock: annotated disassembly

Routines

Prev: B866 Up: Map Next: B90E
B86A: Hand quoted words to the person spoken to (SAY TO / TALK TO)
Called by the TALK TO body (DDAE) with A = 1 if the person has a plan script (an actor, CC0E) and 0 if not. Takes the next quoted sentence off the list at 9FEC. For an actor, B8AA puts it on the order/remark list (9FEE) as an 8-byte node: +0 the person, +1 0, +5/+6 the words, +7 = $A024 (2 for a statement); the person deals with it on its next turn (B936). For anyone else the words are just used up.
How it works:
1. Take the next quoted sentence from the list at 9FEC and unlink it.
2. If the person has a plan script (A = 1), parse the words as a sentence of their own (B8AA) and put them on the order and remark list at 9FEE as an 8-byte node.
3. Otherwise skip the words to the end of the line and mark it with a $90 token.
Input
A 1 if the person spoken to has a plan script; 0 if not
Output
The quoted sentence handed over or used up
B86A PUSH AF Save AF on the stack
B86B LD IX,$9FEE Point IX at orders and remarks (9FEE) - Take the next quoted sentence off its list (9FEC, A0F7); none: done
B86F CALL $A0F7 Call the routine "Move IX to the next node of a list" (A0F7)
B872 JR Z,$B8A8 If the zero flag is set, jump on to B8A8
B874 LD C,(IX+$00) Read the first byte of the record at IX into C - Remember where its words are (B868) and unlink it
B877 LD B,(IX+$01) Read byte +1 of the record at IX into B
B87A LD ($B868),BC Store BC in B868 in "Speech hand-over variables"
B87E LD L,(IX-$02) Read byte -2 of the record at IX into L
B881 LD H,(IX-$01) Read byte -1 of the record at IX into H
B884 LD ($9FEC),HL Store HL in quoted speech waiting to (9FEC)
B887 CALL $A1C7 Call the routine "Free node IX back to the heap" (A1C7)
B88A POP AF Restore AF from the stack - A person with a plan script (A = 1): parse it and hand it over (B8AA)
B88B PUSH AF Save AF on the stack
B88C AND A Test A for zero (this leaves A as it was and clears carry)
B88D JR Z,$B894 If A is zero, skip ahead to B894
B88F CALL $B8AA Call B8AA (inside "Hand quoted words to the person spoken to...")
B892 JR Z,$B8A8 If the zero flag is set, skip ahead to B8A8
B894 LD BC,($B868) Read B868 in "Speech hand-over variables" into BC - Otherwise just use the words up, to the end of the line ($C0),
B898 LD ($A02B),BC Store BC in $A02B in "Game variables"
B89C CALL $AE7F Call the routine "Read the next token of the typed line" (AE7F)
B89F CP $C0 Compare A with $C0
B8A1 JR NZ,$B89C If A differs from $C0, go back to B89C
B8A3 LD HL,($A029) Read $A029 in "Game variables" into HL - and mark the end with a $90 token
B8A6 LD (HL),$90 Store $90 at the address HL points to
B8A8 POP AF Restore AF from the stack
B8A9 RET Return to the caller
B8AA LD HL,($B868) Read B868 in "Speech hand-over variables" into HL - Parse the words as a sentence of their own
B8AD LD ($A02B),HL Store HL in $A02B in "Game variables"
B8B0 XOR A Clear A to zero (and the carry flag)
B8B1 LD ($A024),A Store A in $A024 in "Game variables"
B8B4 LD HL,($9FF0) Read words the player has (9FF0) into HL - with an empty sentence list (the player's own is kept on the stack)
B8B7 PUSH HL Save HL on the stack
B8B8 LD HL,$0000 Load HL with $0000
B8BB LD ($9FF0),HL Store HL in words the player has (9FF0)
B8BE CALL $AAB2 Call the routine "Parse the next sentence from the word list" (AAB2) - Parse (AAB2); A = 2 counts as parsed; anything else is nonsense
B8C1 JR Z,$B8C7 If the zero flag is set, skip ahead to B8C7
B8C3 CP $02 Compare A with $02
B8C5 JR NZ,$B904 If A differs from $02, jump on to B904
B8C7 LD HL,($A02B) Read $A02B in "Game variables" into HL - Go on until the end of the quotation, then mark it with $90
B8CA LD A,(HL) Read the byte HL points at into A
B8CB AND $F0 Keep only bits 4, 5, 6, 7 of A (mask $F0)
B8CD CP $C0 Compare A with $C0
B8CF JR NZ,$B8BE If A differs from $C0, go back to B8BE
B8D1 LD (HL),$90 Store $90 at the address HL points to
B8D3 LD A,$08 Load A with $08 - An 8-byte node on the order/remark list 9FEE (A11C)
B8D5 CALL $A11C Call the routine "Allocate A + 3 bytes from the free list, cleared" (A11C)
B8D8 LD HL,($9FEE) Read orders and remarks (9FEE) into HL
B8DB LD ($9FEE),IX Store IX in orders and remarks (9FEE)
B8DF LD (IX-$02),L Store L in byte -2 of the record at IX
B8E2 LD (IX-$01),H Store H in byte -1 of the record at IX
B8E5 LD HL,($9FF0) Read words the player has (9FF0) into HL - +5/+6: the parsed words
B8E8 LD (IX+$05),L Store L in byte +5 of the record at IX
B8EB LD (IX+$06),H Store H in byte +6 of the record at IX
B8EE POP HL Restore HL from the stack
B8EF LD ($9FF0),HL Store HL in words the player has (9FF0)
B8F2 XOR A Clear A to zero (and the carry flag) - +1 = 0, +0 = the person spoken to
B8F3 LD (IX+$01),A Store A in byte +1 of the record at IX
B8F6 LD A,($A034) Read $A034 in "Game variables" into A
B8F9 LD (IX+$00),A Store A in the first byte of the record at IX
B8FC LD A,($A024) Read $A024 in "Game variables" into A - +7 = the mode: 2 for a statement
B8FF LD (IX+$07),A Store A in byte +7 of the record at IX
B902 XOR A Set A to zero, which sets the zero flag for the caller
B903 RET Return to the caller
B904 PUSH AF Save AF on the stack - Nonsense: free the words (D87D) and put the player's list back
B905 CALL $D87D Call the routine "Free the current sentence's word list (9FF0)" (D87D)
B908 POP AF Restore AF from the stack
B909 POP HL Restore HL from the stack
B90A LD ($9FF0),HL Store HL in words the player has (9FF0)
B90D RET Return to the caller
Prev: B866 Up: Map Next: B90E