Prev: 42087 Up: Map Next: 42160
42105: Handler: Match Vocabulary Word
Used by the routine at Handler_UserInput.
Match the four letters at FourLetterBuffer against the vocabulary. On success return the word's token number in A with the carry flag set; on failure return with the carry flag clear. A comma separates synonyms of the same token; 255 ends the table.
Output
A The token number of the matched word
F Carry set when a match was found
Handler_MatchItem 42105 PUSH HL Stash HL, DE, BC and IX on the stack.
42106 PUSH DE
42107 PUSH BC
42108 PUSH IX
Search the vocabulary from the address written into this instruction, which starts as Table_Vocabulary. Handler_UserInput rewrites that address to try "THE" first.
42110 LD HL,45293 HL=Table_Vocabulary.
42113 LD C,0 Set the token number in C to 0.
42115 JR MatchItem_Word Jump to MatchItem_Word.
This vocabulary word did not match. Step past the remaining letters. A comma keeps the same token for a synonym; anything else advances the token number for the next entry.
MatchItem_NextWord 42117 LD E,B Turn the remaining letter count into a 16-bit offset in DE.
42118 LD D,0
42120 ADD HL,DE Move HL past the unmatched letters.
42121 LD A,(HL) Fetch the next vocabulary byte into A.
42122 CP 44 Is this byte a comma (44)?
42124 JR Z,MatchItem_SkipComma Jump to MatchItem_SkipComma if it is, so the token number stays the same.
42126 INC C Otherwise advance the token number for the next vocabulary entry.
42127 JR MatchItem_Word Jump to MatchItem_Word.
MatchItem_SkipComma 42129 INC HL Move past the comma.
Test this vocabulary word against the four-letter buffer.
MatchItem_Word 42130 LD A,(HL) Jump to MatchItem_Return if the word is the 255 terminator.
42131 CP 255
42133 JR Z,MatchItem_Return
Compare the four-letter buffer at FourLetterBuffer with this word.
42135 LD IX,41285 IX=FourLetterBuffer.
42139 LD B,4 Set a counter in B for the 4 letters.
MatchItem_Letter 42141 LD A,(IX+0) Jump to MatchItem_NextWord if this letter does not match.
42144 CP (HL)
42145 JR NZ,MatchItem_NextWord
42147 INC HL Move to the next vocabulary letter.
42148 INC IX Move to the next letter of the four-letter buffer.
42150 DJNZ MatchItem_Letter Decrease the letter counter by one and loop back to MatchItem_Letter until the counter is zero.
The word matched, so return its token with the carry set.
42152 LD A,C Copy the matched token number into A.
42153 SCF Set the carry flag to show the word was found.
Hand back the registers saved at the start of the search.
MatchItem_Return 42154 POP IX Restore IX, BC, DE and HL from the stack.
42156 POP BC
42157 POP DE
42158 POP HL
42159 RET Return.
View the equivalent code in;
Prev: 42087 Up: Map Next: 42160