Prev: 50015 Up: Map Next: 50094
50047: Match Phrase Tokens
Input
HL A pointer to phrase token data
Output
F The Z flag is set if the input matches any pattern
MatchPhraseTokens 50047 EX DE,HL Switch the phrase token pointer to DE.
50048 JR MatchPhraseTokens_Start Jump to MatchPhraseTokens_Start.
Skip the separator.
MatchPhraseTokens_Loop 50050 INC DE Increment the phrase token pointer by one.
Fetch the second user input token (not the first, as the first token is the verb and the second token onwards gives the context).
For example; "GET" (verb) "KEG OF GUNPOWDER" (direct object).
MatchPhraseTokens_Start 50051 LD HL,48487 HL=UserInput_Token_2.
50054 JR CompareTokens Jump to CompareTokens.
The tokens matched so advance both pointers.
MatchTokens_Loop 50056 INC HL Increment the input token pointer by one.
50057 INC DE Increment the pattern token pointer by one.
Keep looping if the tokens match.
CompareTokens 50058 LD A,(DE) Jump to MatchTokens_Loop if the pattern token and the input token are the same.
50059 CP (HL)
50060 JR Z,MatchTokens_Loop
The tokens are different, but is it just that we are at the end of the pattern?
50062 CP 254 Jump to CheckSeparator unless this is the terminator character (254).
50064 JR NZ,CheckSeparator
Yes! The input tokens all matched against the phrase pattern tokens.
50066 LD A,(HL) Return with Z flag result.
50067 CP 255
50069 RET
The tokens are different, but is this a separator character?
CheckSeparator 50070 CP 253 Jump to MatchPhraseTokens_Next if this is not the separator (253).
50072 JR NZ,MatchPhraseTokens_Next
50074 LD A,(HL) Jump to MatchPhraseTokens_Loop if the input tokens are not complete.
50075 CP 255
50077 JR NZ,MatchPhraseTokens_Loop
50079 RET Return.
The current variant doesn't match, so skip to the next one.
MatchPhraseTokens_Next 50080 INC DE Increment the phrase token pointer by one.
50081 LD A,(DE) Jump to MatchPhraseTokens_Return if the terminator has been reached (254).
50082 CP 254
50084 JR Z,MatchPhraseTokens_Return
50086 CP 253 Jump to MatchPhraseTokens_Next if this is not the separator (253).
50088 JR NZ,MatchPhraseTokens_Next
50090 JR MatchPhraseTokens_Loop Jump to MatchPhraseTokens_Loop.
The input doesn't match any patterns.
MatchPhraseTokens_Return 50092 OR A Clear the Z flag.
50093 RET Return.
Prev: 50015 Up: Map Next: 50094