![]() |
Routines |
| Prev: 45623 | Up: Map | Next: 45924 |
|
Used by the routine at Handler_UserInput.
Turn the finished command into word tokens.
|
||||||||||
| UserInput_Enter | 45646 | LD (HL),A | Write 13 to the command buffer at the current position for use as a termination character. | |||||||
|
Force a newline to be "printed" to the screen.
|
||||||||||
| 45647 | CALL SwitchNormalScreenOutput | Call SwitchNormalScreenOutput. | ||||||||
| 45650 | CALL PrintCharacter | Call PrintCharacter to print the character. | ||||||||
|
Initialise the word token buffer. This buffer will store up to 10 vocabulary tokens (one per word in the command). Each token is the index of the word in the vocabulary table.
|
||||||||||
| 45653 | LD HL,44846 | Point HL at UserInput_FirstToken. | ||||||||
| 45656 | LD A,255 | Use the the terminator key code. | ||||||||
| 45658 | LD B,10 | Set a counter in B for the size of the word token buffer (10 bytes). | ||||||||
|
Fill the word token buffer with 255 (the terminator value) to mark all slots as empty.
|
||||||||||
| EmptyWordTokenBuffer_Loop | 45660 | LD (HL),A | Mark every word slot empty. | |||||||
| 45661 | INC HL | |||||||||
| 45662 | DJNZ EmptyWordTokenBuffer_Loop | |||||||||
| 45664 | LD HL,44796 | Point HL at CommandBuffer. | ||||||||
| 45667 | LD C,10 | Allow ten words in the command. | ||||||||
|
Clear the four-letter buffer to spaces so a short word cannot match the previous one's tail.
|
||||||||||
| Parser_MatchInputWord | 45669 | LD DE,44857 | DE=FourLetterBuffer. | |||||||
| 45672 | LD B,4 | Set a counter in B for the 4 letters. | ||||||||
| 45674 | LD A,32 | A=32. | ||||||||
| ClearWordBuffer_Loop | 45676 | LD (DE),A | Write a space character (32) to the buffer. | |||||||
| 45677 | INC DE | Move to the next letter. | ||||||||
| 45678 | DJNZ ClearWordBuffer_Loop | Decrease the counter by one and loop back to ClearWordBuffer_Loop until the counter is zero. | ||||||||
| 45680 | XOR A | Finish when every word slot is full. | ||||||||
| 45681 | OR C | |||||||||
| 45682 | JP Z,HandlerUnknownWord | |||||||||
| 45685 | LD A,(HL) | Read the next character of the command. | ||||||||
| 45686 | CP 13 | Finish the command at ENTER. | ||||||||
| 45688 | JP Z,HandlerUnknownWord | |||||||||
| 45691 | LD B,4 | Copy the next word into the four-byte scratch. | ||||||||
| 45693 | LD DE,44857 | |||||||||
| UserInput_Enter_0 | 45696 | LD A,(HL) | Read the next character of this word. | |||||||
| 45697 | CP 13 | End the word at ENTER. | ||||||||
| 45699 | JR Z,UserInput_Enter_3 | |||||||||
| 45701 | CP 32 | End the word at a space. | ||||||||
| 45703 | JR Z,UserInput_Enter_2 | |||||||||
| 45705 | CP 44 | End the word at a comma. | ||||||||
| 45707 | JR Z,UserInput_Enter_2 | |||||||||
| 45709 | LD (DE),A | Store that character in the word scratch. | ||||||||
| 45710 | INC HL | Advance through the command and the word scratch. | ||||||||
| 45711 | INC DE | |||||||||
| 45712 | DJNZ UserInput_Enter_0 | Copy up to four letters of this word into the word scratch. | ||||||||
| UserInput_Enter_1 | 45714 | LD A,(HL) | Read the character past a word that did not fit. | |||||||
| 45715 | CP 13 | Stop skipping once ENTER is reached. | ||||||||
| 45717 | JR Z,UserInput_Enter_3 | |||||||||
| 45719 | CP 32 | Stop skipping at a space. | ||||||||
| 45721 | JR Z,UserInput_Enter_2 | |||||||||
| 45723 | CP 44 | Stop skipping at a comma. | ||||||||
| 45725 | JR Z,UserInput_Enter_2 | |||||||||
| 45727 | INC HL | Skip the rest of a word that does not fit the scratch. | ||||||||
| 45728 | JR UserInput_Enter_1 | Keep skipping to the end of a long word. | ||||||||
| UserInput_Enter_2 | 45730 | INC HL | Step past the space or comma between words. | |||||||
| 45731 | LD A,(HL) | Read the character after that space or comma. | ||||||||
| 45732 | CP 32 | Skip spaces between words. | ||||||||
| 45734 | JR Z,UserInput_Enter_2 | |||||||||
| 45736 | CP 44 | Skip commas between words. | ||||||||
| 45738 | JR Z,UserInput_Enter_2 | |||||||||
|
Preserve the command pointer, word buffer and token counter while comparing.
|
||||||||||
| UserInput_Enter_3 | 45740 | PUSH HL | Stash HL, DE and BC on the stack. | |||||||
| 45741 | PUSH DE | |||||||||
| 45742 | PUSH BC | |||||||||
| 45743 | LD HL,44884 | Compare the scratch word with "THE ". | ||||||||
| 45746 | LD DE,44857 | |||||||||
| 45749 | LD B,4 | |||||||||
| CompareWord_Loop | 45751 | LD A,(DE) | Jump to UserInput_Enter_4 if the characters don't match (the word is not "The"). | |||||||
| 45752 | CP (HL) | |||||||||
| 45753 | JR NZ,UserInput_Enter_4 | |||||||||
| 45755 | INC DE | Compare the next letter of "THE". | ||||||||
| 45756 | INC HL | |||||||||
| 45757 | DJNZ CompareWord_Loop | Decrease the letter counter by one and loop back to CompareWord_Loop until the counter is zero. | ||||||||
|
Restore the registers saved before the "THE" comparison.
|
||||||||||
| UserInput_Enter_4 | 45759 | POP BC | Restore BC, DE and HL from the stack. | |||||||
| 45760 | POP DE | |||||||||
| 45761 | POP HL | |||||||||
| 45762 | JR Z,Parser_MatchInputWord | Jump to Parser_MatchInputWord if the words matched (this was "The", so skip it and process the next word). | ||||||||
| 45764 | DEC C | Use up one of the ten word slots for this word. | ||||||||
| 45765 | LD (44869),HL | Write HL to the word scratch. | ||||||||
| 45768 | LD (44871),DE | Write DE to the word pointer. | ||||||||
| 45772 | LD (44873),BC | Write BC to *TempStore_WordCount. | ||||||||
|
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.
|
||||||||||
| 45776 | LD HL,(44752) | HL=*Pointer_Vocabulary. | ||||||||
| 45779 | LD C,0 | Set the token number in C to 0. | ||||||||
| VocabularyLookup_Loop | 45781 | LD A,(HL) | Jump to ProcessUnrecognisedWords if the word is the 255 terminator. | |||||||
| 45782 | CP 255 | |||||||||
| 45784 | JR Z,ProcessUnrecognisedWords | |||||||||
| CompareVocabularyWord | 45786 | LD DE,44857 | DE=FourLetterBuffer. | |||||||
| 45789 | LD B,4 | Set a counter in B for the 4 letters. | ||||||||
| CompareVocabularyWord_Loop | 45791 | LD A,(DE) | Jump to VocabularyWordNoMatch if this letter does not match. | |||||||
| 45792 | CP (HL) | |||||||||
| 45793 | JR NZ,VocabularyWordNoMatch | |||||||||
| 45795 | INC DE | Move to the next letter of the four-letter buffer. | ||||||||
| 45796 | INC HL | Move to the next vocabulary letter. | ||||||||
| 45797 | DJNZ CompareVocabularyWord_Loop | Decrease the letter counter by one and loop back to CompareVocabularyWord_Loop until the counter is zero. | ||||||||
|
The word matched. Calculate which token-buffer slot to use and store the vocabulary index as the token.
|
||||||||||
| 45799 | LD HL,44873 | Work out which token slot this word fills. | ||||||||
| 45802 | LD A,9 | |||||||||
| 45804 | SUB (HL) | |||||||||
| 45805 | LD D,0 | |||||||||
| 45807 | LD E,A | Copy the slot index into E. | ||||||||
| 45808 | LD HL,44846 | Calculate the address of the token buffer slot: HL=UserInput_FirstToken+DE. | ||||||||
| 45811 | ADD HL,DE | |||||||||
| 45812 | LD (HL),C | Store the vocabulary index (C) in the token buffer slot. | ||||||||
| 45813 | LD HL,(44869) | Put back the command buffer position from the word scratch. | ||||||||
| 45816 | LD DE,(44871) | Put back the word buffer position from the word pointer. | ||||||||
| 45820 | LD BC,(44873) | Put back the word counter from *TempStore_WordCount. | ||||||||
| 45824 | JP Parser_MatchInputWord | Jump to Parser_MatchInputWord. | ||||||||
|
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.
|
||||||||||
| VocabularyWordNoMatch | 45827 | LD E,B | Turn the remaining letter count into a 16-bit offset in DE. | |||||||
| 45828 | LD D,0 | |||||||||
| 45830 | ADD HL,DE | Move HL past the unmatched letters. | ||||||||
| 45831 | LD A,(HL) | Fetch the next vocabulary byte into A. | ||||||||
| 45832 | CP 44 | Jump to VocabularyNextEntry if this byte is not a comma (44). | ||||||||
| 45834 | JR NZ,VocabularyNextEntry | |||||||||
| 45836 | INC HL | Move past the comma. | ||||||||
| 45837 | JR CompareVocabularyWord | Jump to CompareVocabularyWord to try matching the synonym. | ||||||||
| VocabularyNextEntry | 45839 | INC C | Advance the token number for the next vocabulary entry. | |||||||
| 45840 | JR VocabularyLookup_Loop | Jump to VocabularyLookup_Loop. | ||||||||
|
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 | 45842 | LD HL,(44869) | Load the pointer for the word scratch into HL. | |||||||
| 45845 | LD DE,(44871) | Restore the word pointer. | ||||||||
| 45849 | LD BC,(44873) | Restore the word count. | ||||||||
| 45853 | LD A,10 | Count the words still to check. | ||||||||
| 45855 | SUB C | |||||||||
| 45856 | LD C,A | |||||||||
| 45857 | LD HL,44796 | Point HL at CommandBuffer. | ||||||||
| ProcessUnrecognisedWords_Loop | 45860 | DEC C | Count off one recognised word; the unrecognised word is reached when the count runs out. | |||||||
| 45861 | JR Z,PrintUnrecognisedWord | Jump to PrintUnrecognisedWord if C is equal to 10 (no unrecognised words found). | ||||||||
| FindUnrecognisedWord_Loop | 45863 | LD A,(HL) | Read the character from *HL and store it in A. | |||||||
| 45864 | CP 32 | Jump to SkipDelimiters_Loop2 if the character is an ASCII "SPACE" (32). | ||||||||
| 45866 | JR Z,SkipDelimiters_Loop2 | |||||||||
| 45868 | CP 44 | Jump to SkipDelimiters_Loop2 if the character is an ASCII comma (44). | ||||||||
| 45870 | JR Z,SkipDelimiters_Loop2 | |||||||||
| 45872 | INC HL | Move to the next character in the command buffer. | ||||||||
| 45873 | JR FindUnrecognisedWord_Loop | Keep reading this unrecognised word. | ||||||||
| SkipDelimiters_Loop2 | 45875 | INC HL | Move to the next character in the command buffer. | |||||||
| 45876 | LD A,(HL) | Read the character from *HL and store it in A. | ||||||||
| 45877 | CP 32 | Jump to SkipDelimiters_Loop2 if the character is an ASCII "SPACE" (32). | ||||||||
| 45879 | JR Z,SkipDelimiters_Loop2 | |||||||||
| 45881 | CP 44 | Jump to SkipDelimiters_Loop2 if the character is an ASCII comma (44). | ||||||||
| 45883 | JR Z,SkipDelimiters_Loop2 | |||||||||
| 45885 | JR ProcessUnrecognisedWords_Loop | Look for the next unrecognised word. | ||||||||
|
Print the unrecognised word(s) in quotes.
|
||||||||||
| PrintUnrecognisedWord | 45887 | PUSH HL | Remember where the unrecognised word starts. | |||||||
| 45888 | LD HL,44909 | Print "I don't know the word:-" and start a new line. | ||||||||
| 45891 | CALL PrintStringAndNewline | |||||||||
| 45894 | POP HL | Restore the start of the unrecognised word from the stack. | ||||||||
| 45895 | LD A,34 | Open a quote around the unrecognised word. | ||||||||
| 45897 | CALL PrintCharacter | Call PrintCharacter to print the character. | ||||||||
| PrintUnrecognisedWord_Loop | 45900 | LD A,(HL) | Read the character from *HL and store it in A. | |||||||
| 45901 | CP 33 | Jump to PrintUnrecognisedWord_End if this character is less than 33 (a control character, indicating end of word). | ||||||||
| 45903 | JR C,PrintUnrecognisedWord_End | |||||||||
| 45905 | INC HL | Move to the next character in the command buffer. | ||||||||
| 45906 | CALL PrintCharacter | Call PrintCharacter to print the character. | ||||||||
| 45909 | JR PrintUnrecognisedWord_Loop | Print the next character of the unrecognised word. | ||||||||
| PrintUnrecognisedWord_End | 45911 | LD A,34 | Close the quote around the unrecognised word. | |||||||
| 45913 | CALL PrintCharacter | Call PrintCharacter to print the character. | ||||||||
| 45916 | LD HL,45323 | Print "." and start a new line. | ||||||||
| 45919 | CALL PrintStringAndNewline | |||||||||
| 45922 | JR HandlerUnknownWord_0 | Read another command. | ||||||||
|
View the equivalent code in;
|
||||||||||
| Prev: 45623 | Up: Map | Next: 45924 |