![]() |
Routines |
| Prev: B237 | Up: Map | Next: B364 |
|
Used by the routine at HandlerUserInput.
Turn the finished command into word tokens.
|
||||||||||
| HandlerUserPressedENTER | B24E | LD (HL),A | Write 0D to the command buffer at the current position for use as a termination character. | |||||||
|
Force a newline to be "printed" to the screen.
|
||||||||||
| B24F | CALL SwitchToNormalScreenOutput | Call SwitchToNormalScreenOutput. | ||||||||
| B252 | CALL PrintCharacter | Call PrintCharacter to print the character. | ||||||||
|
Initialise the word token buffer. This buffer will store up to 0A vocabulary tokens (one per word in the command). Each token is the index of the word in the vocabulary table.
|
||||||||||
| B255 | LD HL,$AF2E | Point HL at the first word token. | ||||||||
| B258 | LD A,$FF | Use the the terminator key code. | ||||||||
| B25A | LD B,$0A | Set a counter in B for the size of the word token buffer (0A bytes). | ||||||||
|
Fill the word token buffer with FF (the terminator value) to mark all slots as empty.
|
||||||||||
| EmptyWordTokenBuffer_Loop | B25C | LD (HL),A | Mark every word slot empty. | |||||||
| B25D | INC HL | |||||||||
| B25E | DJNZ EmptyWordTokenBuffer_Loop | |||||||||
| B260 | LD HL,$AEFC | Point HL at the command buffer. | ||||||||
| B263 | LD C,$0A | Allow ten words in the command. | ||||||||
| Parser_MatchInputWord | B265 | LD DE,$AF39 | Blank the four-byte word scratch with spaces. | |||||||
| B268 | LD B,$04 | |||||||||
| B26A | LD A,$20 | |||||||||
| HandlerUserPressedENTER_0 | B26C | LD (DE),A | Fill the word scratch with spaces. | |||||||
| B26D | INC DE | |||||||||
| B26E | DJNZ HandlerUserPressedENTER_0 | |||||||||
| B270 | XOR A | Finish when every word slot is full. | ||||||||
| B271 | OR C | |||||||||
| B272 | JP Z,HandlerUnknownWord | |||||||||
| B275 | LD A,(HL) | Read the next character of the command. | ||||||||
| B276 | CP $0D | Finish the command at ENTER. | ||||||||
| B278 | JP Z,HandlerUnknownWord | |||||||||
| B27B | LD B,$04 | Copy the next word into the four-byte scratch. | ||||||||
| B27D | LD DE,$AF39 | |||||||||
| HandlerUserPressedENTER_1 | B280 | LD A,(HL) | Read the next character of this word. | |||||||
| B281 | CP $0D | End the word at ENTER. | ||||||||
| B283 | JR Z,HandlerUserPressedENTER_4 | |||||||||
| B285 | CP $20 | End the word at a space. | ||||||||
| B287 | JR Z,HandlerUserPressedENTER_3 | |||||||||
| B289 | CP $2C | End the word at a comma. | ||||||||
| B28B | JR Z,HandlerUserPressedENTER_3 | |||||||||
| B28D | LD (DE),A | Store that character in the word scratch. | ||||||||
| B28E | INC HL | Advance through the command and the word scratch. | ||||||||
| B28F | INC DE | |||||||||
| B290 | DJNZ HandlerUserPressedENTER_1 | Copy up to four letters of this word into the word scratch. | ||||||||
| HandlerUserPressedENTER_2 | B292 | LD A,(HL) | Read the character past a word that did not fit. | |||||||
| B293 | CP $0D | Stop skipping once ENTER is reached. | ||||||||
| B295 | JR Z,HandlerUserPressedENTER_4 | |||||||||
| B297 | CP $20 | Stop skipping at a space. | ||||||||
| B299 | JR Z,HandlerUserPressedENTER_3 | |||||||||
| B29B | CP $2C | Stop skipping at a comma. | ||||||||
| B29D | JR Z,HandlerUserPressedENTER_3 | |||||||||
| B29F | INC HL | Skip the rest of a word that does not fit the scratch. | ||||||||
| B2A0 | JR HandlerUserPressedENTER_2 | Keep skipping to the end of a long word. | ||||||||
| HandlerUserPressedENTER_3 | B2A2 | INC HL | Step past the space or comma between words. | |||||||
| B2A3 | LD A,(HL) | Read the character after that space or comma. | ||||||||
| B2A4 | CP $20 | Skip spaces between words. | ||||||||
| B2A6 | JR Z,HandlerUserPressedENTER_3 | |||||||||
| B2A8 | CP $2C | Skip commas between words. | ||||||||
| B2AA | JR Z,HandlerUserPressedENTER_3 | |||||||||
| HandlerUserPressedENTER_4 | B2AC | PUSH HL | Remember the command, the scratch and the word count. | |||||||
| B2AD | PUSH DE | |||||||||
| B2AE | PUSH BC | |||||||||
| B2AF | LD HL,$AF54 | Compare the scratch word with "THE ". | ||||||||
| B2B2 | LD DE,$AF39 | |||||||||
| B2B5 | LD B,$04 | |||||||||
| CompareWord_Loop | B2B7 | LD A,(DE) | Jump to HandlerUserPressedENTER_5 if the characters don't match (the word is not "The"). | |||||||
| B2B8 | CP (HL) | |||||||||
| B2B9 | JR NZ,HandlerUserPressedENTER_5 | |||||||||
| B2BB | INC DE | Compare the next letter of "THE". | ||||||||
| B2BC | INC HL | |||||||||
| B2BD | DJNZ CompareWord_Loop | Keep going until all four letters have been compared. | ||||||||
| HandlerUserPressedENTER_5 | B2BF | POP BC | Restore BC, DE, HL from the stack. | |||||||
| B2C0 | POP DE | |||||||||
| B2C1 | POP HL | |||||||||
| B2C2 | JR Z,Parser_MatchInputWord | Jump to Parser_MatchInputWord if the words matched (this was "The", so skip it and process the next word). | ||||||||
| B2C4 | DEC C | Use up one of the ten word slots for this word. | ||||||||
| B2C5 | LD ($AF45),HL | Write HL to the word scratch. | ||||||||
| B2C8 | LD ($AF47),DE | Write DE to the word pointer. | ||||||||
| B2CC | LD ($AF49),BC | Write BC to *Workspace_Tail. | ||||||||
|
Look up the word in the vocabulary table. The vocabulary contains all recognised verbs, nouns, and other words the game understands. Each entry can have synonyms separated by commas.
|
||||||||||
| B2D0 | LD HL,($AED0) | Load the pointer for the vocabulary pointer into HL. | ||||||||
| B2D3 | LD C,$00 | Select the north exit. | ||||||||
| VocabularyLookup_Loop | B2D5 | LD A,(HL) | Jump to ProcessUnrecognisedWords if *HL is equal to FF (end of vocabulary table). | |||||||
| B2D6 | CP $FF | |||||||||
| B2D8 | JR Z,ProcessUnrecognisedWords | |||||||||
| CompareVocabularyWord | B2DA | LD DE,$AF39 | Compare this vocabulary word with the scratch word. | |||||||
| B2DD | LD B,$04 | |||||||||
| CompareVocabularyWord_Loop | B2DF | LD A,(DE) | Jump to VocabularyWordNoMatch if the characters don't match (this vocabulary entry doesn't match the word). | |||||||
| B2E0 | CP (HL) | |||||||||
| B2E1 | JR NZ,VocabularyWordNoMatch | |||||||||
| B2E3 | INC DE | Move to the next character in the extracted word. | ||||||||
| B2E4 | INC HL | Move to the next character in the vocabulary entry. | ||||||||
| B2E5 | DJNZ CompareVocabularyWord_Loop | Decrease counter by one and loop back to CompareVocabularyWord_Loop until all 04 characters have been compared. | ||||||||
|
Word matched in vocabulary! Calculate which slot in the token buffer to use (based on how many words have been processed so far) and store the vocabulary index as the token.
|
||||||||||
| B2E7 | LD HL,$AF49 | Work out which token slot this word fills. | ||||||||
| B2EA | LD A,$09 | |||||||||
| B2EC | SUB (HL) | |||||||||
| B2ED | LD D,$00 | |||||||||
| B2EF | LD E,A | Use the filled slot as an offset into the token buffer. | ||||||||
| B2F0 | LD HL,$AF2E | Calculate the address of the token buffer slot: HL=the first word token+DE. | ||||||||
| B2F3 | ADD HL,DE | |||||||||
| B2F4 | LD (HL),C | Store the vocabulary index (C) in the token buffer slot. | ||||||||
| B2F5 | LD HL,($AF45) | Put back the command buffer position from the word scratch. | ||||||||
| B2F8 | LD DE,($AF47) | Put back the word buffer position from the word pointer. | ||||||||
| B2FC | LD BC,($AF49) | Put back the word counter from *Workspace_Tail. | ||||||||
| B300 | JP Parser_MatchInputWord | Take the next word. | ||||||||
|
Word didn't match this vocabulary entry. Check if there's a synonym (indicated by a comma). If found, try matching against the synonym instead.
|
||||||||||
| VocabularyWordNoMatch | B303 | LD E,B | Step past the vocabulary word that did not match. | |||||||
| B304 | LD D,$00 | |||||||||
| B306 | ADD HL,DE | |||||||||
| B307 | LD A,(HL) | Read the character at this position and store it in A. | ||||||||
| B308 | CP $2C | Jump to VocabularyNextEntry if this character is not a comma (2C, meaning no synonym exists). | ||||||||
| B30A | JR NZ,VocabularyNextEntry | |||||||||
| B30C | INC HL | Move past the comma to the synonym. | ||||||||
| B30D | JR CompareVocabularyWord | Jump to CompareVocabularyWord to try matching the synonym. | ||||||||
| VocabularyNextEntry | B30F | INC C | Advance to the next vocabulary word. | |||||||
| B310 | JR VocabularyLookup_Loop | Jump to VocabularyLookup_Loop to check the next vocabulary entry. | ||||||||
|
All recognised words have been tokenised. Now check if there are any unrecognised words remaining in the input. If so, display an error message to the player showing which word(s) weren't understood.
|
||||||||||
| ProcessUnrecognisedWords | B312 | LD HL,($AF45) | Load the pointer for the word scratch into HL. | |||||||
| B315 | LD DE,($AF47) | Restore the word pointer. | ||||||||
| B319 | LD BC,($AF49) | Restore the word count. | ||||||||
| B31D | LD A,$0A | Count the words still to check. | ||||||||
| B31F | SUB C | |||||||||
| B320 | LD C,A | |||||||||
| B321 | LD HL,$AEFC | Point HL at the command buffer. | ||||||||
| ProcessUnrecognisedWords_Loop | B324 | DEC C | Count off one recognised word; the unrecognised word is reached when the count runs out. | |||||||
| B325 | JR Z,PrintUnrecognisedWord | Jump to PrintUnrecognisedWord if C is equal to 0A (no unrecognised words found). | ||||||||
| FindUnrecognisedWord_Loop | B327 | LD A,(HL) | Read the character from *HL and store it in A. | |||||||
| B328 | CP $20 | Jump to SkipDelimiters_Loop2 if the character is an ASCII "SPACE" (20). | ||||||||
| B32A | JR Z,SkipDelimiters_Loop2 | |||||||||
| B32C | CP $2C | Jump to SkipDelimiters_Loop2 if the character is an ASCII comma (2C). | ||||||||
| B32E | JR Z,SkipDelimiters_Loop2 | |||||||||
| B330 | INC HL | Move to the next character in the command buffer. | ||||||||
| B331 | JR FindUnrecognisedWord_Loop | Keep reading this unrecognised word. | ||||||||
| SkipDelimiters_Loop2 | B333 | INC HL | Move to the next character in the command buffer. | |||||||
| B334 | LD A,(HL) | Read the character from *HL and store it in A. | ||||||||
| B335 | CP $20 | Jump to SkipDelimiters_Loop2 if the character is an ASCII "SPACE" (20). | ||||||||
| B337 | JR Z,SkipDelimiters_Loop2 | |||||||||
| B339 | CP $2C | Jump to SkipDelimiters_Loop2 if the character is an ASCII comma (2C). | ||||||||
| B33B | JR Z,SkipDelimiters_Loop2 | |||||||||
| B33D | JR ProcessUnrecognisedWords_Loop | Look for the next unrecognised word. | ||||||||
|
Print the unrecognised word(s) in quotes.
|
||||||||||
| PrintUnrecognisedWord | B33F | PUSH HL | Remember where the unrecognised word starts. | |||||||
| B340 | LD HL,$AF6D | Print "I don't know the word:-" and start a new line. | ||||||||
| B343 | CALL PrintStringAndANewline | |||||||||
| B346 | POP HL | Restore the start of the unrecognised word from the stack. | ||||||||
| B347 | LD A,$22 | Open a quote around the unrecognised word. | ||||||||
| B349 | CALL PrintCharacter | Call PrintCharacter to print the character. | ||||||||
| PrintUnrecognisedWord_Loop | B34C | LD A,(HL) | Read the character from *HL and store it in A. | |||||||
| B34D | CP $21 | Jump to PrintUnrecognisedWord_End if this character is less than 21 (a control character, indicating end of word). | ||||||||
| B34F | JR C,PrintUnrecognisedWord_End | |||||||||
| B351 | INC HL | Move to the next character in the command buffer. | ||||||||
| B352 | CALL PrintCharacter | Call PrintCharacter to print the character. | ||||||||
| B355 | JR PrintUnrecognisedWord_Loop | Print the next character of the unrecognised word. | ||||||||
| PrintUnrecognisedWord_End | B357 | LD A,$22 | Close the quote around the unrecognised word. | |||||||
| B359 | CALL PrintCharacter | Call PrintCharacter to print the character. | ||||||||
| B35C | LD HL,$B10B | Print "." and start a new line. | ||||||||
| B35F | CALL PrintStringAndANewline | |||||||||
| B362 | JR HandlerUnknownWord_0 | Read another command. | ||||||||
|
View the equivalent code in;
|
||||||||||
| Prev: B237 | Up: Map | Next: B364 |