Sherlock: annotated disassembly

Routines

Prev: BCC9 Up: Map Next: BDC2
BD51: Find the statement $BA19-$BA1B in the case table
Addresses named in the title: $BA19, BA1B.
Z with IX = the statement if found (BD69 compares subject, relation and object in that order). BD4B searches Watson's own list at 9A7D the same way.
How it works:
1. Start at the first record of the case table (9965), or - from BD4B - at Watson's own list (9A7D).
2. A first byte of $FF ends the table: return NZ.
3. Compare the record with the statement being looked for: its relation ($BA1A) with byte +1, then its subject ($BA19) with +0, then its object (BA1B) with +2. All three must match.
4. On a match return Z with IX at the record; otherwise step to the next record (BE5A), skipping any evidence records that belong to this one, and repeat.
Input
$BA19 The statement's subject
$BA1A Its relation
$BA1B Its object
Output
F Z if found, NZ if not
IX The record, if found
BD51 LD IX,$9965 The case table (9965)
This entry point is used by the routine at BCC9.
BD55 LD A,(IX+$00) Read the first byte of the record at IX into A - First byte $FF ends the table
BD58 CP $FF Compare A with $FF
BD5A JR Z,$BD66 If A equals $FF, skip ahead to BD66
BD5C CALL $BD69 Does this record match the statement (BD69)?
BD5F JR Z,$BD68 Yes: Z, IX = the record
BD61 CALL $BE5A Call the routine "Step IX over one case record (4 bytes, or 6 with a..." (BE5A) - Step to the next record (BE5A)
BD64 JR $BD55 Go back to BD55
BD66 OR $01 Make A non-zero, which clears the zero flag, and hand that back to the caller - End of table: NZ
BD68 RET Return to the caller
BD69 LD A,($BA1A) Read $BA1A in "Variables used by the code at BA20-BF58" into A - Compare the relation ($BA1A) with +1...
BD6C CP (IX+$01) Compare A with byte +1 of the record at IX
BD6F RET NZ If A differs from byte +1 of the record at IX, return
BD70 LD A,($BA19) Read $BA19 in "Variables used by the code at BA20-BF58" into A - ...then the subject ($BA19) with +0...
BD73 CP (IX+$00) Compare A with the first byte of the record at IX
BD76 RET NZ If A differs from the first byte of the record at IX, return
BD77 LD A,($BA1B) Read BA1B in "Variables used by the code at BA20-BF58" into A - ...then the object (BA1B) with +2; Z if all three agree
BD7A CP (IX+$02) Compare A with byte +2 of the record at IX
BD7D RET Return to the caller
This entry point is used by the routines at BA67 and BB67.
BD7E PUSH IY Save IY on the stack - The statement's subject: the node's words at +$18...
BD80 POP HL Restore HL from the stack
BD81 LD DE,$0018 Load DE with $0018, the amount that is added next
BD84 ADD HL,DE Add DE to HL
BD85 BIT 7,(IY+$19) Test bit 7 of byte +25 of the record at IY - ...or for HE the last person named ($9FF6)...
BD89 JR Z,$BD8E If bit 7 of byte +25 of the record at IY is clear, skip ahead to BD8E
BD8B LD HL,$9FF6 Point HL at $9FF6 in "Game variables"
BD8E BIT 6,(IY+$19) Test bit 6 of byte +25 of the record at IY - ...or for IT/THEY the last thing ($9FFC)
BD92 JR Z,$BD97 If bit 6 of byte +25 of the record at IY is clear, skip ahead to BD97
BD94 LD HL,$9FFC Point HL at $9FFC in "Game variables"
BD97 LD DE,$B172 Point DE at $B172 in "Parser variables" - into the first object slot; the words at +8 into the second
BD9A LD BC,$0006 Load BC with $0006
BD9D LDIR Copy BC bytes from where HL points to where DE points, counting up
BD9F PUSH IY Save IY on the stack
BDA1 POP HL Restore HL from the stack
BDA2 LD DE,$0008 Load DE with $0008, the amount that is added next
BDA5 ADD HL,DE Add DE to HL
BDA6 LD DE,$B178 Point DE at $B178 in "Parser variables"
BDA9 LD BC,$0006 Load BC with $0006
BDAC LDIR Copy BC bytes from where HL points to where DE points, counting up
BDAE LD L,(IY+$00) Read the first byte of the record at IY into L - $BA17 = the verb word; then make the statement (BDC2)
BDB1 LD A,(IY+$01) Read byte +1 of the record at IY into A
BDB4 AND $0F Keep only bits 0, 1, 2, 3 of A (mask $0F)
BDB6 LD H,A Copy A into H
BDB7 LD ($BA17),HL Store HL in $BA17 in "Variables used by the code at BA20-BF58"
BDBA PUSH IY Save IY on the stack
BDBC CALL $BDC2 Call the routine "Turn the player's remark into a statement" (BDC2)
BDBF POP IY Restore IY from the stack
BDC1 RET Return to the caller
Prev: BCC9 Up: Map Next: BDC2