Sherlock: annotated disassembly

Routines

Prev: DA34 Up: Map Next: DAC6
DA7D: Compare the typed word against one dictionary candidate
On a match, also follows a synonym chain (a bit in the next word's own flag byte marks 'this is the last synonym in the group'; otherwise a 16-bit offset follows, pointing at another word to also accept as equivalent).
Input
$5C0B The typed word
$5C42 The candidate word
Output
The best match so far updated ($DC14)
DA7D PUSH HL Save HL on the stack
DA7E PUSH DE Save DE on the stack
DA7F LD A,($DC13) Read "The number reader's working bytes" (DC13) into A - Already matched every typed letter with an earlier word: skip this one
DA82 LD B,A Copy A into B
DA83 LD A,($DC14) Read $DC14 in "The number reader's working bytes" into A
DA86 CP B Compare A with B
DA87 JR NC,$DAA5 If A is B or more, skip ahead to DAA5
DA89 LD B,$01 Load B with $01 - Count the letters of the typed word ($5C0B) that agree with this word ($5C42)
DA8B LD DE,$5C0B Point DE at the tape header workspace ($5C0B)
DA8E LD HL,$5C42 Point HL at the BASIC workspace ($5C42)
DA91 LD A,(DE) Read the byte DE points at into A
DA92 AND A Test A for zero (this leaves A as it was and clears carry)
DA93 JR Z,$DA9D If A is zero, skip ahead to DA9D
DA95 CP (HL) Compare A with the byte HL points at
DA96 JR NZ,$DA9D If A differs from the byte HL points at, skip ahead to DA9D
DA98 INC HL Step HL on to the next byte
DA99 INC DE Step DE on to the next byte
DA9A INC B Add one to B
DA9B JR $DA91 Go back to DA91
DA9D LD A,($DC14) Read $DC14 in "The number reader's working bytes" into A - As good as the best so far? Then this word becomes the best ($DC14)
DAA0 CP B Compare A with B
DAA1 JR Z,$DAA9 If A equals B, skip ahead to DAA9
DAA3 JR C,$DAA9 If A is below B, skip ahead to DAA9
DAA5 POP DE Restore DE from the stack
DAA6 POP HL Restore HL from the stack
DAA7 XOR A Set A to zero, which sets the zero flag for the caller
DAA8 RET Return to the caller
DAA9 LD A,B Copy B into A
DAAA LD ($DC14),A Store A in $DC14 in "The number reader's working bytes"
DAAD POP HL Restore HL from the stack - A record whose count byte has bit 7 set holds the offset of another record in its next two bytes: follow such links
DAAE PUSH HL Save HL on the stack
DAAF INC HL Step HL on to the next byte
DAB0 BIT 7,(HL) Test bit 7 of the byte HL points at
DAB2 DEC HL Step HL back one byte
DAB3 JR Z,$DAC1 If bit 7 of the byte HL points at is clear, skip ahead to DAC1
DAB5 INC HL Step HL on to the next byte
DAB6 INC HL Step HL on to the next byte
DAB7 LD E,(HL) Read the byte HL points at into E
DAB8 INC HL Step HL on to the next byte
DAB9 LD D,(HL) Read the byte HL points at into D
DABA LD HL,$5DBF Point HL at $5DBF
DABD ADD HL,DE Add DE to HL
DABE EX (SP),HL Swap HL with the word on top of the stack
DABF JR $DAAD Go back to DAAD
DAC1 POP DE Restore DE from the stack - NZ: more words to try
DAC2 POP HL Restore HL from the stack
DAC3 OR $01 Make A non-zero, which clears the zero flag, and hand that back to the caller
DAC5 RET Return to the caller
Prev: DA34 Up: Map Next: DAC6