Sherlock: annotated disassembly

Routines

Prev: B5B6 Up: Map Next: B6AE
B5D3: Ask the player which object, or what
Self-modifying: B62F loads $28 (the opcode of JR Z) and B633 $20 (JR NZ); B635 writes it over the jumps at B649 and B658, which decide whether the words in the saved verb pattern ($B18E, +2/+3 and +4/+5, with +7 bit 7 and bit 5 of the first word as flags) are included.
Input
$B16D, $B16E Flags telling which slots hold words
Output
A question printed ($A59F); the player's own words are the message parameters
B5D3 LD A,($B16E) Read $B16E in "Parser variables" into A - Indirect-object slot holds words (bit 0 of $B16E)?
B5D6 BIT 0,A Test bit 0 of A
B5D8 JR Z,$B610 No: the 'THE ... WHAT ?' form at B610
B5DA LD A,($B183) Read $B183 in "Parser variables" into A - Yes: A = the slot's count byte ($B183), HL = the slot ($B178)
B5DD LD HL,$B178 Point HL at $B178 in "Parser variables"
B5E0 JR $B5EF Join the 'WHICH' question
B5E2 LD A,($B16D) Read "Parser variables" (B16D) into A - (Entry for the direct object) same test on B16D
B5E5 BIT 0,A Test bit 0 of A
B5E7 JR Z,$B5FC If bit 0 of A is clear, skip ahead to B5FC
B5E9 LD A,($B182) Read $B182 in "Parser variables" into A - A = its count byte ($B182), HL = $B172
B5EC LD HL,$B172 Point HL at $B172 in "Parser variables"
B5EF CALL $B83C Push the slot's three words as message parameters (B83C)
B5F2 CALL $B5B6 Move on to the next sentence of the typed line (B5B6)
B5F5 LD HL,$6888 Point HL at the message "WHICH ‹word› ?" (6888) - Print 'WHICH ... ?' (6888)
B5F8 CALL $A59F Call the routine "Print the message at HL" (A59F)
B5FB RET Return to the caller
B5FC CALL $B633 Direct object with no words: push the verb's words (B633)
B5FF LD HL,($B186) Read $B186 in "Parser variables" into HL - ...and the saved ($B186) word
B602 PUSH HL Save HL on the stack
B603 LD A,($B182) Read $B182 in "Parser variables" into A
B606 CALL $B5B6 Next sentence
B609 LD HL,$6880 Point HL at the message "‹word› WHAT ?" (6880) - Print '<word> WHAT ?' (6880)
B60C CALL $A59F Call the routine "Print the message at HL" (A59F)
B60F RET Return to the caller
B610 CALL $B62F Call B62F (inside "Ask the player which object, or what") - Neither slot: the full question: verb words (B62F)...
B613 LD HL,$0000 Load HL with $0000
B616 PUSH HL Save HL on the stack
B617 LD HL,$B172 Point HL at $B172 in "Parser variables" - ...the direct object's words ($B172)...
B61A PUSH HL Save HL on the stack
B61B CALL $B633 Call B633 (inside "Ask the player which object, or what") - ...and (B633) the verb again
B61E LD HL,($B186) Read $B186 in "Parser variables" into HL
B621 PUSH HL Save HL on the stack
B622 LD A,($B183) Read $B183 in "Parser variables" into A
B625 CALL $B5B6 Next sentence
B628 LD HL,$687C Point HL at the message "‹word› THE ‹word› WHAT ?" (687C) - Print '<word> THE <word> WHAT ?' (687C)
B62B CALL $A59F Call the routine "Print the message at HL" (A59F)
B62E RET Return to the caller
This entry point is used by the routines at B6AE and B6DA.
B62F LD A,$28 Load A with $28 - JR Z opcode...
B631 JR $B635 Skip ahead to B635
This entry point is used by the routine at B6DA.
B633 LD A,$20 JR NZ opcode...
B635 LD ($B649),A Store A in B649 in "Ask the player which object, or what" - ...written into the jumps below (self-modifying)
B638 LD ($B658),A Store A in B658 in "Ask the player which object, or what"
B63B LD IX,($B18E) Read $B18E in "Parser variables" into IX
B63F LD L,(IX+$04) Read byte +4 of the record at IX into L
B642 LD H,(IX+$05) Read byte +5 of the record at IX into H
B645 BIT 7,(IX+$07) Test bit 7 of byte +7 of the record at IX
B649 JR NZ,$B64E If bit 7 of byte +7 of the record at IX is set, skip ahead to B64E - Modified by B635
B64B LD HL,$0000 Load HL with $0000
B64E EX (SP),HL Swap HL with the word on top of the stack
B64F PUSH HL Save HL on the stack
B650 LD L,(IX+$02) Read byte +2 of the record at IX into L
B653 LD H,(IX+$03) Read byte +3 of the record at IX into H
B656 BIT 5,H Test bit 5 of H
B658 JR NZ,$B65D If bit 5 of H is set, skip ahead to B65D - Modified by B635
B65A LD HL,$0000 Load HL with $0000
B65D EX (SP),HL Swap HL with the word on top of the stack
B65E JP (HL) Jump to the address in HL
B65F LD A,($A00F) Read $A00F in "Game variables" into A - (Entry B65F) requirement code 5 or 6 (a number) wants...
B662 CP $05 Compare A with $05
B664 JR Z,$B671 If A equals $05, skip ahead to B671
B666 CP $06 Compare A with $06
B668 JR Z,$B671 If A equals $06, skip ahead to B671
B66A LD A,($B173) Read $B173 in "Parser variables" into A - ...or the first word of the direct-object slot has bit 7 set
B66D BIT 7,A Test bit 7 of A
B66F JR Z,$B678 If bit 7 of A is clear, skip ahead to B678
This entry point is used by the routine at B6AE.
B671 LD HL,$6855 Point HL at the message "DON'T BE SILLY." (6855) - Print 6855 ('DON'T BE SILLY.')
B674 CALL $A59F Call the routine "Print the message at HL" (A59F)
B677 RET Return to the caller
B678 LD HL,$B16D Point HL at "Parser variables" (B16D) - Otherwise: direct-object slot holds words?
B67B BIT 0,(HL) Test bit 0 of the byte at "Parser variables" (B16D)
B67D LD HL,$B172 Point HL at $B172 in "Parser variables"
B680 CALL NZ,$B6DA Yes: count them (B6DA)
B683 CALL $B633 Call B633 (inside "Ask the player which object, or what") - Push the verb's words (B633)
B686 LD A,($B16D) Read "Parser variables" (B16D) into A
B689 LD HL,$B172 Point HL at $B172 in "Parser variables"
This entry point is used by the routine at B6AE.
B68C LD DE,($B186) Read $B186 in "Parser variables" into DE - Push the saved word ($B186)
B690 PUSH DE Save DE on the stack
B691 BIT 0,A Test bit 0 of A - Slot has words (bit 0)?
B693 JR Z,$B69D If bit 0 of A is clear, skip ahead to B69D
B695 CALL $B83C Call the routine "Push the three words at HL as message parameters" (B83C) - Yes: push them (B83C) and use the message at $05B3
B698 LD HL,$05B3 Load HL with $05B3
B69B JR $B6A6 Skip ahead to B6A6
B69D LD HL,$0000 Load HL with $0000 - No: three zero parameters and the message at $05DB
B6A0 PUSH HL Save HL on the stack
B6A1 PUSH HL Save HL on the stack
B6A2 PUSH HL Save HL on the stack
B6A3 LD HL,$05DB Load HL with $05DB
B6A6 PUSH HL Save HL on the stack
B6A7 LD HL,$6894 Point HL at the message "I SEE ‹word› THAT YOU CAN ‹word›" (6894) - Print 6894 with those parameters
B6AA CALL $A59F Call the routine "Print the message at HL" (A59F)
B6AD RET Return to the caller
Prev: B5B6 Up: Map Next: B6AE