Prev: A5C6 Up: Map Next: A60A
A5DB: Match Phrase Tokens
Used by the routines at A8F9 and A90D.
Matches phrase patterns with multiple variations against user input tokens.
Input
HL A pointer to phrase token data
Output
F The Z flag is set if the input matches any pattern
MatchPhraseTokens A5DB EX DE,HL Switch the phrase token pointer to DE.
A5DC JR MatchPhraseTokens_Start Jump to MatchPhraseTokens_Start.
Skip the separator.
MatchPhraseTokens_Loop A5DE 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 A5DF LD HL,$A13C HL=UserInput_Token_2.
A5E2 JR CompareTokens Jump to CompareTokens.
The tokens matched so advance both pointers.
MatchTokens_Loop A5E4 INC HL Increment the input token pointer by one.
A5E5 INC DE Increment the pattern token pointer by one.
Keep looping if the tokens match.
CompareTokens A5E6 LD A,(DE) Jump to MatchTokens_Loop if the pattern token and the input token are the same.
A5E7 CP (HL)
A5E8 JR Z,MatchTokens_Loop
The tokens are different, but is it just that we are at the end of the pattern?
A5EA CP $FE Jump to CheckSeparator unless this is the terminator character (FE).
A5EC JR NZ,CheckSeparator
Yes! The input tokens all matched against the phrase pattern tokens.
A5EE LD A,(HL) Return with Z flag result.
A5EF CP $FF
A5F1 RET
The tokens are different, but is this a separator character?
CheckSeparator A5F2 CP $FD Jump to MatchPhraseTokens_Next if this is not the separator (FD).
A5F4 JR NZ,MatchPhraseTokens_Next
A5F6 LD A,(HL) Jump to MatchPhraseTokens_Loop if the input tokens are not complete.
A5F7 CP $FF
A5F9 JR NZ,MatchPhraseTokens_Loop
A5FB RET Return.
The current variant doesn't match, so skip to the next one.
MatchPhraseTokens_Next A5FC INC DE Increment the phrase token pointer by one.
A5FD LD A,(DE) Jump to MatchPhraseTokens_Return if the terminator has been reached (FE).
A5FE CP $FE
A600 JR Z,MatchPhraseTokens_Return
A602 CP $FD Jump to MatchPhraseTokens_Next if this is not the separator (FD).
A604 JR NZ,MatchPhraseTokens_Next
A606 JR MatchPhraseTokens_Loop Jump to MatchPhraseTokens_Loop.
The input doesn't match any patterns.
MatchPhraseTokens_Return A608 OR A Clear the Z flag.
A609 RET Return.
View the equivalent code in;
Prev: A5C6 Up: Map Next: A60A