![]() |
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 | Increment HL by one. | ||
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. | ||
Handler_UserInput_1 | 42256 | PUSH HL | ||
42257 | PUSH DE | |||
42258 | PUSH BC | |||
42259 | LD HL,(42051) | |||
42262 | LD DE,41285 | |||
42265 | LD BC,4 | |||
42268 | LD A,(42053) | |||
42271 | CP C | |||
42272 | JR NC,Handler_UserInput_2 | |||
42274 | LD C,A | |||
Handler_UserInput_2 | 42275 | LDIR | ||
42277 | POP BC | |||
42278 | POP DE | |||
42279 | POP HL | |||
42280 | PUSH HL | |||
42281 | LD HL,40402 | |||
42284 | LD (42111),HL | |||
42287 | CALL Handler_MatchItem | |||
42290 | LD HL,45293 | |||
42293 | LD (42111),HL | |||
42296 | POP HL | |||
42297 | JR C,EmptyFourLetterBuffer | |||
42299 | CALL Handler_MatchItem | |||
42302 | JR C,StoreTokenAndContinue | |||
42304 | LD HL,2 | |||
42307 | CALL PrintCompressedStringAndNewline | |||
42310 | JP Handler_UserInput | |||
StoreTokenAndContinue | 42313 | LD (IX+0),A | ||
42316 | INC IX | |||
42318 | DEC C | |||
42319 | JR Z,Handler_UserInput_9 | |||
EmptyFourLetterBuffer | 42321 | PUSH HL | ||
42322 | PUSH BC | |||
42323 | LD HL,41285 | |||
42326 | LD B,4 | |||
Handler_UserInput_3 | 42328 | LD (HL),32 | ||
42330 | INC HL | |||
42331 | DJNZ Handler_UserInput_3 | |||
42333 | POP BC | |||
42334 | POP HL | |||
42335 | PUSH DE | |||
42336 | JR Handler_UserInput_5 | |||
Handler_UserInput_4 | 42338 | INC HL | ||
Handler_UserInput_5 | 42339 | LD A,(HL) | ||
42340 | CP 13 | |||
42342 | JR Z,Handler_UserInput_8 | |||
42344 | CALL IsDelimiter | |||
42347 | JR Z,Handler_UserInput_4 | |||
42349 | LD (42051),HL | |||
42352 | LD DE,0 | |||
Handler_UserInput_6 | 42355 | INC HL | ||
42356 | INC DE | |||
42357 | LD A,(HL) | |||
42358 | CP 13 | |||
42360 | JR Z,Handler_UserInput_7 | |||
42362 | CALL IsDelimiter | |||
42365 | JR NZ,Handler_UserInput_6 | |||
Handler_UserInput_7 | 42367 | LD (42053),DE | ||
42371 | SCF | |||
Handler_UserInput_8 | 42372 | POP DE | ||
42373 | JP C,Handler_UserInput_1 | |||
Handler_UserInput_9 | 42376 | LD A,(41275) | ||
42379 | CP 255 | |||
42381 | JP Z,Handler_UserInput_0 | |||
42384 | RET | |||
View the equivalent code in;
|
Prev: 42105 | Up: Map | Next: 42385 |