Prev: 6F30 Up: Map Next: 6FBA
6F47: Look a typed word up in the dictionary
Used by the routine at TOKENISE.
Copies the word from the input line, turning each letter into its 5-bit code with AND $1F -- which works because 'A' is $41 and the codes were chosen to be the low five bits of the ASCII -- and stops at the first character below $40, so punctuation and spaces end a word without being tested for.
Then the index: the first letter doubled and added to WORD_INDEX gives the bucket's offset, and that added to WORD_INDEX again gives the first entry. From there each call unpacks one candidate -- the tokeniser comes back in at TRY_ENTRY for the next -- and the bucket is over when an entry's initial letter stops matching the one typed, which is its only end marker.
MATCH_WORD 6F47 LD DE,TYPED_LETTERS Copy the typed word as 5-bit codes to TYPED_LETTERS, up to the first character below $40
6F4A LD B,$00
MATCH_WORD_0 6F4C LD A,(HL)
6F4D CP $40
6F4F JR C,MATCH_WORD_1
6F51 AND $1F
6F53 LD (DE),A
6F54 INC DE
6F55 INC HL
6F56 INC B
6F57 JR MATCH_WORD_0
MATCH_WORD_1 6F59 LD A,B Keep its length
6F5A LD (TYPED_LENGTH),A
6F5D PUSH HL IX = the first word in the dictionary under its initial letter
6F5E LD HL,(TYPED_LETTERS)
6F61 LD H,$00
6F63 LD DE,WORD_INDEX
6F66 ADD HL,HL
6F67 ADD HL,DE
6F68 LD E,(HL)
6F69 INC HL
6F6A LD D,(HL)
6F6B LD IX,WORD_INDEX
6F6F ADD IX,DE
6F71 POP HL
This entry point is used by the routine at TOKENISE.
TRY_ENTRY 6F72 LD (DICTIONARY_ENTRY),IX Remember which entry is being tried
This entry point is used by the routine at TOKENISE.
TRY_SAME_ENTRY 6F76 LD A,(IX+$00) Has the bucket run out? Its initial letter no longer matches
6F79 AND $1F
6F7B LD B,A
6F7C LD A,(TYPED_LETTERS)
6F7F CP B
6F80 RET NZ
6F81 PUSH HL
6F82 LD HL,ENTRY_LETTERS Unpack this entry's letters to ENTRY_LETTERS, by PRINT_WORD's rule for where a word ends
6F85 LD BC,$0000
MATCH_WORD_2 6F88 LD A,(IX+$00)
6F8B AND $1F
6F8D JR Z,MATCH_WORD_3
6F8F LD (HL),A
6F90 INC HL
6F91 INC B
MATCH_WORD_3 6F92 INC IX
6F94 INC C
6F95 BIT 7,(IX-$01)
6F99 JR Z,MATCH_WORD_2
6F9B LD A,C
6F9C CP $02
6F9E JR Z,MATCH_WORD_2
6FA0 CP $03
6FA2 JR NZ,MATCH_WORD_4
6FA4 BIT 7,(IX-$02)
6FA8 JR NZ,MATCH_WORD_2
MATCH_WORD_4 6FAA POP HL Keep the entry's length
6FAB LD A,B
6FAC LD (ENTRY_LENGTH),A
6FAF BIT 6,(IX-$01) A synonym: step over its two-byte link to the next entry
6FB3 RET Z
6FB4 INC IX
6FB6 INC IX
6FB8 XOR A
6FB9 RET
A linear scan, not a binary search -- which is the other half of why the list only has to be grouped by initial letter and can be loosely ordered within a group, as BLOW before BLOOD and HELP before HEART are.
Prev: 6F30 Up: Map Next: 6FBA