![]()  | 
Routines | 
| Prev: AE6B | Up: Map | Next: AEAF | 
| 
 
Used by the routine at ActionRouting.
 
Matches phrase patterns with multiple variations against user input tokens.
 
 
  | 
||||||||||||
| MatchPhraseTokens | AE80 | EX DE,HL | Switch the phrase token pointer to DE. | |||||||||
| AE81 | JR MatchPhraseTokens_Start | Jump to MatchPhraseTokens_Start. | ||||||||||
| 
 
Skip the separator.
 
 | 
||||||||||||
| MatchPhraseTokens_Loop | AE83 | 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 | AE84 | LD HL,$A825 | HL=UserInput_Token_2. | |||||||||
| AE87 | JR CompareTokens | Jump to CompareTokens. | ||||||||||
| 
 
The tokens matched so advance both pointers.
 
 | 
||||||||||||
| MatchTokens_Loop | AE89 | INC HL | Increment the input token pointer by one. | |||||||||
| AE8A | INC DE | Increment the pattern token pointer by one. | ||||||||||
| 
 
Keep looping if the tokens match.
 
 | 
||||||||||||
| CompareTokens | AE8B | LD A,(DE) | Jump to MatchTokens_Loop if the pattern token and the input token are the same. | |||||||||
| AE8C | CP (HL) | |||||||||||
| AE8D | JR Z,MatchTokens_Loop | |||||||||||
| 
 
The tokens are different, but is it just that we are at the end of the pattern?
 
 | 
||||||||||||
| AE8F | CP $FE | Jump to CheckSeparator unless this is the terminator character (FE). | ||||||||||
| AE91 | JR NZ,CheckSeparator | |||||||||||
| 
 
Yes! The input tokens all matched against the phrase pattern tokens.
 
 | 
||||||||||||
| AE93 | LD A,(HL) | Return with Z flag result. | ||||||||||
| AE94 | CP $FF | |||||||||||
| AE96 | RET | |||||||||||
| 
 
The tokens are different, but is this a separator character?
 
 | 
||||||||||||
| CheckSeparator | AE97 | CP $FD | Jump to MatchPhraseTokens_Next if this is not the separator (FD). | |||||||||
| AE99 | JR NZ,MatchPhraseTokens_Next | |||||||||||
| AE9B | LD A,(HL) | Jump to MatchPhraseTokens_Loop if the input tokens are not complete. | ||||||||||
| AE9C | CP $FF | |||||||||||
| AE9E | JR NZ,MatchPhraseTokens_Loop | |||||||||||
| AEA0 | RET | Return. | ||||||||||
| 
 
The current variant doesn't match, so skip to the next one.
 
 | 
||||||||||||
| MatchPhraseTokens_Next | AEA1 | INC DE | Increment the phrase token pointer by one. | |||||||||
| AEA2 | LD A,(DE) | Jump to MatchPhraseTokens_Return if the terminator has been reached (FE). | ||||||||||
| AEA3 | CP $FE | |||||||||||
| AEA5 | JR Z,MatchPhraseTokens_Return | |||||||||||
| AEA7 | CP $FD | Jump to MatchPhraseTokens_Next if this is not the separator (FD). | ||||||||||
| AEA9 | JR NZ,MatchPhraseTokens_Next | |||||||||||
| AEAB | JR MatchPhraseTokens_Loop | Jump to MatchPhraseTokens_Loop. | ||||||||||
| 
 
The input doesn't match any patterns.
 
 | 
||||||||||||
| MatchPhraseTokens_Return | AEAD | OR A | Clear the Z flag. | |||||||||
| AEAE | RET | Return. | ||||||||||
| 
 
View the equivalent code in The Jewels Of Babylon.
 
 | 
||||||||||||
| Prev: AE6B | Up: Map | Next: AEAF |