![]() |
Routines |
| Prev: 42105 | Up: Map | Next: 42385 |
|
Used by the routine at GameStart.
Handles keyboard input, tokenises commands and validates the vocabulary.
|
||||
|
Reset the screen position to defaults.
|
||||
| Handler_UserInput | 42160 | CALL PrintPrompt | Call PrintPrompt. | |
| 42163 | LD HL,41225 | HL=CommandBuffer. | ||
|
Initialise the command buffer.
|
||||
| 42166 | LD B,0 | Initialise a letter counter in B. | ||
| 42168 | JR UserInput_Next | Jump to UserInput_Next. | ||
|
Main input loop - process each keypress.
|
||||
| UserInput_Loop | 42170 | INC HL | Move to the next byte of the command buffer. | |
| 42171 | INC B | Increment the letter counter by one. | ||
| UserInput_Next | 42172 | CALL Print_Cursor | Call Print_Cursor. | |
| 42175 | CALL GetUserInput | Call GetUserInput. | ||
| 42178 | CP 12 | Jump to ValidateUserInput if "DELETE" was not pressed. | ||
| 42180 | JR NZ,ValidateUserInput | |||
|
The user pressed "DELETE".
|
||||
| 42182 | XOR A | Jump back to UserInput_Next if there hasn't been any input yet (nothing to delete). | ||
| 42183 | OR B | |||
| 42184 | JR Z,UserInput_Next | |||
|
There is input which can be deleted, so action a delete!
|
||||
| 42186 | EX DE,HL | Temporarily stash the command buffer pointer in DE. | ||
|
Print "SPACE BACKSPACE BACKSPACE SPACE BACKSPACE" to move the current print position on the screen to the previous character, and to delete the character present using a space.
|
||||
| 42187 | LD HL,42055 | HL=Messaging_SpaceBackspaceBackspaceSpaceBackspace. | ||
| 42190 | CALL PrintString | Call PrintString. | ||
|
Adjust the command buffer position and letter counter.
|
||||
| 42193 | EX DE,HL | Restore the command buffer pointer from DE. | ||
| 42194 | DEC HL | Decrease the command buffer pointer by one. | ||
| 42195 | DEC B | Decrease the letter counter by one. | ||
| 42196 | JR UserInput_Next | Jump to UserInput_Next. | ||
|
Check which key the user pressed:
|
||||
| ValidateUserInput | 42198 | LD C,A | Jump to UserInput_WriteKeypress if "ENTER" was pressed. | |
| 42199 | CP 13 | |||
| 42201 | JR Z,UserInput_WriteKeypress | |||
| 42203 | CP 32 | If the keypress was any other control key (the value being under 32 ASCII "SPACE"), it's not valid input so jump back to UserInput_Next. | ||
| 42205 | JR C,UserInput_Next | |||
| 42207 | CP 128 | If the keypress was higher than 128 it's also not valid input so jump back to UserInput_Next. | ||
| 42209 | JR NC,UserInput_Next | |||
|
Is the command buffer full?
|
||||
| 42211 | LD A,B | Jump to UserInput_Next if the letter counter is 49 (so the buffer is full). | ||
| 42212 | CP 49 | |||
| 42214 | JR Z,UserInput_Next | |||
|
Writes the keypress into the command buffer and print it to the screen.
|
||||
| UserInput_WriteKeypress | 42216 | LD A,C | Write the user input key to *HL. | |
| 42217 | LD (HL),A | |||
| 42218 | CALL Print_UserInputToScreen | Call Print_UserInputToScreen. | ||
|
Did the user press "ENTER"?
|
||||
| 42221 | LD A,C | Jump to UserInput_Loop if "ENTER" was not pressed. | ||
| 42222 | CP 13 | |||
| 42224 | JR NZ,UserInput_Loop | |||
|
The player pressed "ENTER" so begin to process the user input.
Clear down the user input tokens.
|
||||
| 42226 | LD HL,41275 | HL=UserInput_Token_1. | ||
| 42229 | LD B,10 | Set a counter in B for all 10 user input tokens. | ||
| EmptyUserInputTokens_Loop | 42231 | LD (HL),255 | Write a termination byte (255) to *HL. | |
| 42233 | INC HL | Move HL on to the next user input token. | ||
| 42234 | DJNZ EmptyUserInputTokens_Loop | Decrease the user input tokens counter by one and loop back to EmptyUserInputTokens_Loop until all the tokens have been set to termination bytes (255). | ||
|
Set up pointers for the command buffer, the user input tokens and the count of the number of user input tokens.
|
||||
| 42236 | LD HL,41225 | HL=CommandBuffer. | ||
| 42239 | LD IX,41275 | IX=UserInput_Token_1. | ||
| 42243 | LD C,10 | Set a counter in C for the 10 user input tokens. | ||
| 42245 | JR EmptyFourLetterBuffer | Jump to EmptyFourLetterBuffer. | ||
|
Print "Give me a command!".
|
||||
| Handler_UserInput_0 | 42247 | LD HL,1 | HL=Messaging_GiveMeACommand. | |
| 42250 | CALL PrintCompressedStringAndNewline | Call PrintCompressedStringAndNewline. | ||
| 42253 | JP Handler_UserInput | Jump to Handler_UserInput. | ||
|
Copy up to four letters of the current word into FourLetterBuffer.
|
||||
| TokeniseWord | 42256 | PUSH HL | The command scan waits. | |
| 42257 | PUSH DE | |||
| 42258 | PUSH BC | |||
| 42259 | LD HL,(42051) | The word starts at the address in Pointer_CommandWord, and lands in FourLetterBuffer. | ||
| 42262 | LD DE,41285 | |||
| 42265 | LD BC,4 | Four letters is the most a word contributes. | ||
| 42268 | LD A,(42053) | A shorter word copies only as many letters as CommandWordLength holds. | ||
| 42271 | CP C | |||
| 42272 | JR NC,Handler_UserInput_1 | |||
| 42274 | LD C,A | |||
| Handler_UserInput_1 | 42275 | LDIR | Copy those letters into FourLetterBuffer. | |
| 42277 | POP BC | Restore BC, DE and HL from the stack. | ||
| 42278 | POP DE | |||
| 42279 | POP HL | |||
|
Ignore a leading "THE" from Table_Vocabulary_The, then search the main vocabulary at Table_Vocabulary.
|
||||
| 42280 | PUSH HL | Point the search at "THE" in Table_Vocabulary_The. | ||
| 42281 | LD HL,40402 | |||
| 42284 | LD (42111),HL | |||
| 42287 | CALL Handler_MatchItem | Call Handler_MatchItem. | ||
| 42290 | LD HL,45293 | The next search uses the main vocabulary at Table_Vocabulary. | ||
| 42293 | LD (42111),HL | |||
| 42296 | POP HL | Restore the command-buffer pointer from the stack. | ||
| 42297 | JR C,EmptyFourLetterBuffer | Jump to EmptyFourLetterBuffer if "THE" was matched. | ||
|
The word is in the vocabulary.
|
||||
| 42299 | CALL Handler_MatchItem | Jump to StoreTokenAndContinue if the word matched. | ||
| 42302 | JR C,StoreTokenAndContinue | |||
|
The word is not in the vocabulary.
|
||||
| 42304 | LD HL,2 | Print "Try another command." and read the command again. | ||
| 42307 | CALL PrintCompressedStringAndNewline | |||
| 42310 | JP Handler_UserInput | |||
|
Store the token and stop after 10 tokens.
|
||||
| StoreTokenAndContinue | 42313 | LD (IX+0),A | The token buffer at UserInput_Token_1 holds the words understood so far. | |
| 42316 | INC IX | |||
| 42318 | DEC C | |||
| 42319 | JR Z,Handler_UserInput_5 | |||
|
Clear the four-letter buffer to spaces before the next word.
|
||||
| EmptyFourLetterBuffer | 42321 | PUSH HL | Clear the four-letter buffer to spaces so a short word cannot match the previous one's tail. | |
| 42322 | PUSH BC | |||
| 42323 | LD HL,41285 | |||
| 42326 | LD B,4 | |||
| Handler_UserInput_2 | 42328 | LD (HL),32 | ||
| 42330 | INC HL | |||
| 42331 | DJNZ Handler_UserInput_2 | |||
| 42333 | POP BC | Restore BC and HL from the stack. | ||
| 42334 | POP HL | |||
|
Find the next word. ENTER finishes the command, and IsDelimiter marks a gap between words.
|
||||
| 42335 | PUSH DE | Start at this character. | ||
| 42336 | JR Handler_UserInput_3 | |||
| SkipDelimiter | 42338 | INC HL | The next character. | |
| Handler_UserInput_3 | 42339 | LD A,(HL) | ENTER finishes the command. | |
| 42340 | CP 13 | |||
| 42342 | JR Z,Handler_UserInput_4 | |||
| 42344 | CALL IsDelimiter | Call IsDelimiter. | ||
| 42347 | JR Z,SkipDelimiter | Skip the gap and keep looking. | ||
|
Remember where this word starts and how long it is, then tokenise it.
|
||||
| 42349 | LD (42051),HL | Remember where this word starts. | ||
| 42352 | LD DE,0 | |||
| MeasureWord | 42355 | INC HL | Count this letter. | |
| 42356 | INC DE | |||
| 42357 | LD A,(HL) | ENTER ends the word. | ||
| 42358 | CP 13 | |||
| 42360 | JR Z,MeasureWord_Store | |||
| 42362 | CALL IsDelimiter | Call IsDelimiter. | ||
| 42365 | JR NZ,MeasureWord | A gap has not been reached yet. | ||
| MeasureWord_Store | 42367 | LD (42053),DE | Store the length at CommandWordLength. | |
| 42371 | SCF | The word is ready to tokenise. | ||
|
Tokenise the word that was just measured.
|
||||
| Handler_UserInput_4 | 42372 | POP DE | Restore the command-scan pointer from the stack. | |
| 42373 | JP C,TokeniseWord | Jump to TokeniseWord if another word was found. | ||
|
Nothing was understood.
|
||||
| Handler_UserInput_5 | 42376 | LD A,(41275) | Jump to Handler_UserInput_0 if no token was stored. | |
| 42379 | CP 255 | |||
| 42381 | JP Z,Handler_UserInput_0 | |||
| 42384 | RET | Return. | ||
|
View the equivalent code in;
|
||||
| Prev: 42105 | Up: Map | Next: 42385 |