![]() |
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_FirstToken. | ||
| 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_FirstToken. | ||
| 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!".
|
||||
| Response_NotUnderstood | 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 | Stash HL, DE and BC on the stack. | |
| 42257 | PUSH DE | |||
| 42258 | PUSH BC | |||
| 42259 | LD HL,(42051) | HL=*Pointer_CommandWord. | ||
| 42262 | LD DE,41285 | DE=FourLetterBuffer. | ||
| 42265 | LD BC,4 | Set BC to 0004 letters at most. | ||
| 42268 | LD A,(42053) | Jump to CopyWordToBuffer if *CommandWordLength is at least 4. | ||
| 42271 | CP C | |||
| 42272 | JR NC,CopyWordToBuffer | |||
| 42274 | LD C,A | Copy the actual length into C. | ||
| CopyWordToBuffer | 42275 | LDIR | Copy those letters into FourLetterBuffer. | |
|
Restore the registers saved at the start of TokeniseWord.
|
||||
| 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 | Stash the command-buffer pointer on the stack. | ||
| 42281 | LD HL,40402 | Point the search at "THE" in Table_Vocabulary_The. | ||
| 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. | ||
|
Search the main vocabulary for this word.
|
||||
| 42299 | CALL Handler_MatchItem | Call Handler_MatchItem. | ||
| 42302 | JR C,StoreTokenAndContinue | Jump to StoreTokenAndContinue if the word matched. | ||
|
The word is not in the vocabulary.
Print "Try another command.".
|
||||
| 42304 | LD HL,2 | HL=Messaging_TryAnotherCommand. | ||
| 42307 | CALL PrintCompressedStringAndNewline | Call PrintCompressedStringAndNewline. | ||
| 42310 | JP Handler_UserInput | Jump to Handler_UserInput. | ||
|
Store the token and stop after 10 tokens.
|
||||
| StoreTokenAndContinue | 42313 | LD (IX+0),A | Write the token to the current token slot at UserInput_FirstToken. | |
| 42316 | INC IX | Move to the next token slot. | ||
| 42318 | DEC C | Decrease the token counter by one. | ||
| 42319 | JR Z,CheckVerbToken | Jump to CheckVerbToken if all token slots are filled. | ||
|
Clear the four-letter buffer to spaces so a short word cannot match the previous one's tail.
|
||||
| EmptyFourLetterBuffer | 42321 | PUSH HL | Stash HL and BC on the stack. | |
| 42322 | PUSH BC | |||
| 42323 | LD HL,41285 | HL=FourLetterBuffer. | ||
| 42326 | LD B,4 | Set a counter in B for the 4 letters. | ||
| EmptyFourLetterBuffer_Loop | 42328 | LD (HL),32 | Write a space character (32) to the buffer. | |
| 42330 | INC HL | Move to the next letter. | ||
| 42331 | DJNZ EmptyFourLetterBuffer_Loop | Decrease the counter by one and loop back to EmptyFourLetterBuffer_Loop until the counter is zero. | ||
| 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 | Stash DE on the stack. | ||
| 42336 | JR FindWordStart | Jump to FindWordStart. | ||
| SkipDelimiter | 42338 | INC HL | Move to the next character. | |
| FindWordStart | 42339 | LD A,(HL) | Fetch the character at *HL into A. | |
| 42340 | CP 13 | Jump to EndWordParsing if the character is ENTER (13). | ||
| 42342 | JR Z,EndWordParsing | |||
| 42344 | CALL IsDelimiter | Call IsDelimiter. | ||
| 42347 | JR Z,SkipDelimiter | Jump to SkipDelimiter if the character is a delimiter. | ||
|
Remember where this word starts and how long it is, then tokenise it.
|
||||
| 42349 | LD (42051),HL | Store the starting address of this word in *Pointer_CommandWord. | ||
| 42352 | LD DE,0 | Initialise DE to 0000 to count the letters. | ||
| MeasureWord | 42355 | INC HL | Move to the next character. | |
| 42356 | INC DE | Increment the letter counter by one. | ||
| 42357 | LD A,(HL) | Fetch the character at *HL into A. | ||
| 42358 | CP 13 | Jump to MeasureWord_Store if the character is ENTER (13). | ||
| 42360 | JR Z,MeasureWord_Store | |||
| 42362 | CALL IsDelimiter | Call IsDelimiter. | ||
| 42365 | JR NZ,MeasureWord | Jump to MeasureWord if the character was not a delimiter. | ||
| MeasureWord_Store | 42367 | LD (42053),DE | Store the length at CommandWordLength. | |
| 42371 | SCF | Set the carry flag to show a word was found. | ||
|
Tokenise the word that was just measured.
|
||||
| EndWordParsing | 42372 | POP DE | Restore DE from the stack. | |
| 42373 | JP C,TokeniseWord | Jump to TokeniseWord if another word was found. | ||
|
Check whether any token was stored; if not, the command was not understood.
|
||||
| CheckVerbToken | 42376 | LD A,(41275) | Jump to Response_NotUnderstood if *UserInput_FirstToken holds the terminator byte (255). | |
| 42379 | CP 255 | |||
| 42381 | JP Z,Response_NotUnderstood | |||
| 42384 | RET | Return. | ||
|
View the equivalent code in;
|
||||
| Prev: 42105 | Up: Map | Next: 42385 |