Prev: A467 Up: Map Next: A4B0
A479: 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; FF ends the table.
Output
A The token number of the matched word
F Carry set when a match was found
Handler_MatchItem A479 PUSH HL Stash HL, DE, BC and IX on the stack.
A47A PUSH DE
A47B PUSH BC
A47C 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.
A47E LD HL,$B0ED HL=Table_Vocabulary.
A481 LD C,$00 Set the token number in C to 00.
A483 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 A485 LD E,B Turn the remaining letter count into a 16-bit offset in DE.
A486 LD D,$00
A488 ADD HL,DE Move HL past the unmatched letters.
A489 LD A,(HL) Fetch the next vocabulary byte into A.
A48A CP $2C Is this byte a comma (2C)?
A48C JR Z,MatchItem_SkipComma Jump to MatchItem_SkipComma if it is, so the token number stays the same.
A48E INC C Otherwise advance the token number for the next vocabulary entry.
A48F JR MatchItem_Word Jump to MatchItem_Word.
MatchItem_SkipComma A491 INC HL Move past the comma.
Test this vocabulary word against the four-letter buffer.
MatchItem_Word A492 LD A,(HL) Jump to MatchItem_Return if the word is the FF terminator.
A493 CP $FF
A495 JR Z,MatchItem_Return
Compare the four-letter buffer at FourLetterBuffer with this word.
A497 LD IX,$A145 IX=FourLetterBuffer.
A49B LD B,$04 Set a counter in B for the 04 letters.
MatchItem_Letter A49D LD A,(IX+$00) Jump to MatchItem_NextWord if this letter does not match.
A4A0 CP (HL)
A4A1 JR NZ,MatchItem_NextWord
A4A3 INC HL Move to the next vocabulary letter.
A4A4 INC IX Move to the next letter of the four-letter buffer.
A4A6 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.
A4A8 LD A,C Copy the matched token number into A.
A4A9 SCF Set the carry flag to show the word was found.
Hand back the registers saved at the start of the search.
MatchItem_Return A4AA POP IX Restore IX, BC, DE and HL from the stack.
A4AC POP BC
A4AD POP DE
A4AE POP HL
A4AF RET Return.
View the equivalent code in;
Prev: A467 Up: Map Next: A4B0