Sherlock: annotated disassembly

Routines

Prev: DA32 Up: Map Next: DA7D
DA34: Look up this word's first letter in the dictionary index
Takes the current word's first character directly from the input buffer, masks it to 5 bits (giving 1-26 for any letter without needing a separate packing step - 'A' is $41, whose low 5 bits are 1; 'Z' is $5A, whose low 5 bits are 26), and uses that to index a 26-entry table at 5D80 of 16-bit offsets, relative to a second base at $5DBF, to find the first candidate word stored under that letter.
How it works:
1. The first letter (A = 1 to Z = 26) indexes the table of offsets at 5D80.
2. DE is where that letter's words start in the dictionary. The next letter that has words marks where they end (DA32).
3. Return Z if there are no words under the letter.
Input
HL The word
Output
DE The first dictionary record for the letter
$DA32 Where its words end
F Z if there are none
DA34 LD A,(HL) Read the byte HL points at into A - The first letter (A = 1 ... Z = 26) indexes the table of offsets at 5D80
DA35 INC HL Step HL on to the next byte
DA36 AND $1F Keep only bits 0, 1, 2, 3, 4 of A (mask $1F)
DA38 RLCA Rotate A left one place (bit 7 goes to carry and bit 0)
DA39 LD E,A Copy A into E
DA3A LD D,$00 Load D with $00
DA3C PUSH HL Save HL on the stack
DA3D POP IX Restore IX from the stack
DA3F LD HL,$5D80 Point HL at "Dictionary index: where each letter's words start" (5D80)
DA42 ADD HL,DE Add DE to HL
DA43 LD E,(HL) Read the byte HL points at into E - DE = where this letter's words start in the dictionary
DA44 INC HL Step HL on to the next byte
DA45 LD D,(HL) Read the byte HL points at into D
DA46 INC HL Step HL on to the next byte
DA47 PUSH DE Save DE on the stack
DA48 LD E,(HL) Read the byte HL points at into E - The next letter that has words marks where they end (DA32)
DA49 INC HL Step HL on to the next byte
DA4A LD D,(HL) Read the byte HL points at into D
DA4B INC HL Step HL on to the next byte
DA4C LD A,D Copy D into A
DA4D OR E Set in A the bits that are set in E
DA4E JR Z,$DA48 If the result is zero, go back to DA48
DA50 LD HL,$5DBF Point HL at $5DBF
DA53 ADD HL,DE Add DE to HL
DA54 LD ($DA32),HL Store HL in "The tokenizer's word pointer" (DA32)
DA57 POP DE Restore DE from the stack
DA58 LD A,D Copy D into A - No words under this letter: Z
DA59 OR E Set in A the bits that are set in E
DA5A RET Z If the result is zero, return
DA5B LD HL,$5DBF Point HL at $5DBF
DA5E ADD HL,DE Add DE to HL
DA5F LD DE,$5C0B Point DE at the tape header workspace ($5C0B) - Copy the typed word to $5C0B in lower case, as the dictionary spells
DA62 LD B,$01 Load B with $01
DA64 LD A,(IX+$00) Read the first byte of the record at IX into A
DA67 CP $40 Compare A with $40
DA69 JR C,$DA74 If A is below $40, skip ahead to DA74
DA6B OR $20 Set bit 5 of A
DA6D LD (DE),A Store A at the address DE points to
DA6E INC DE Step DE on to the next byte
DA6F INC IX Step IX on to the next byte
DA71 INC B Add one to B
DA72 JR $DA64 Go back to DA64
DA74 XOR A Clear A to zero (and the carry flag) - End it with 0; DC13 = its length + 1
DA75 LD (DE),A Store A at the address DE points to
DA76 LD A,B Copy B into A
DA77 LD ($DC13),A Store A in "The number reader's working bytes" (DC13)
DA7A OR $01 Make A non-zero, which clears the zero flag, and hand that back to the caller
DA7C RET Return to the caller
Prev: DA32 Up: Map Next: DA7D