![]() |
Routines |
Prev: 44283 | Up: Map | Next: 44598 |
Used by the routine at GameLoop.
Handles keyboard input, tokenises commands and validates the vocabulary.
|
||||
Reset the screen position to defaults.
|
||||
Handler_UserInput | 44338 | CALL SetDefaultScreenPosition | Call SetDefaultScreenPosition. | |
44341 | CALL PrintInputPrompt | Call PrintInputPrompt. | ||
Initialise the command buffer.
|
||||
44344 | LD HL,42994 | HL=CommandBuffer. | ||
44347 | LD B,0 | Initialise a letter counter in B. | ||
44349 | JR UserInput_Next | Jump to UserInput_Next. | ||
Main input loop - process each keypress.
|
||||
UserInput_Loop | 44351 | INC HL | Move to the next byte of the command buffer. | |
44352 | INC B | Increment the letter counter by one. | ||
UserInput_Next | 44353 | CALL Print_Cursor | Call Print_Cursor. | |
44356 | CALL GetUserInput | Call GetUserInput. | ||
44359 | CP 12 | Jump to ValidateUserInput if "DELETE" was not pressed. | ||
44361 | JR NZ,ValidateUserInput | |||
The user pressed "DELETE".
|
||||
44363 | XOR A | Jump back to UserInput_Next if there hasn't been any input yet (nothing to delete). | ||
44364 | OR B | |||
44365 | JR Z,UserInput_Next | |||
There is input which can be deleted, so action a delete!
|
||||
44367 | 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.
|
||||
44368 | LD HL,44230 | HL=Messaging_SpaceBackspaceBackspaceSpaceBackspace. | ||
44371 | CALL PrintString | Call PrintString. | ||
Adjust the command buffer position and letter counter.
|
||||
44374 | EX DE,HL | Restore the command buffer pointer from DE. | ||
44375 | DEC HL | Decrease the command buffer pointer by one. | ||
44376 | DEC B | Decrease the letter counter by one. | ||
44377 | JR UserInput_Next | Jump to UserInput_Next. | ||
Check which key the user pressed:
|
||||
ValidateUserInput | 44379 | LD C,A | Jump to UserInput_WriteKeypress if "ENTER" was pressed. | |
44380 | CP 13 | |||
44382 | JR Z,UserInput_WriteKeypress | |||
44384 | 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. | ||
44386 | JR C,UserInput_Next | |||
44388 | CP 128 | If the keypress was higher than 128 it's also not valid input so jump back to UserInput_Next. | ||
44390 | JR NC,UserInput_Next | |||
Is the command buffer full?
|
||||
44392 | LD A,B | Jump to UserInput_Next if the letter counter is 49 (so the buffer is full). | ||
44393 | CP 49 | |||
44395 | JR Z,UserInput_Next | |||
Writes the keypress into the command buffer and print it to the screen.
|
||||
UserInput_WriteKeypress | 44397 | LD A,C | Write the user input key to *HL. | |
44398 | LD (HL),A | |||
44399 | CALL Print_UserInputToScreen | Call Print_UserInputToScreen. | ||
Did the user press "ENTER"?
|
||||
44402 | LD A,C | Jump to UserInput_Loop if "ENTER" was not pressed. | ||
44403 | CP 13 | |||
44405 | JR NZ,UserInput_Loop | |||
The player pressed "ENTER" so begin to process the user input.
Clear down the user input tokens.
|
||||
44407 | LD HL,43044 | HL=UserInput_Token_1. | ||
44410 | LD B,10 | Set a counter in B for all 10 user input tokens. | ||
EmptyUserInputTokens_Loop | 44412 | LD (HL),255 | Write a termination byte (255) to *HL. | |
44414 | INC HL | Increment HL by one. | ||
44415 | 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.
|
||||
44417 | LD HL,42994 | HL=CommandBuffer. | ||
44420 | LD IX,43044 | IX=UserInput_Token_1. | ||
44424 | LD C,10 | Set a counter in C for the 10 user input tokens. | ||
44426 | JR EmptyFourLetterBuffer | Jump to EmptyFourLetterBuffer. | ||
What's been entered isn't parsable.
Print "I don't understand.".
|
||||
Response_NotUnderstood | 44428 | LD HL,43087 | HL=Messaging_IDontUnderstand. | |
44431 | CALL PrintStringAndNewline | Call PrintStringAndNewline. | ||
44434 | JP Handler_UserInput | Jump to Handler_UserInput. | ||
Process found word into user input token.
|
||||
ProcessFoundWord | 44437 | PUSH HL | Stash the command buffer pointer, DE and user input tokens counter on the stack. | |
44438 | PUSH DE | |||
44439 | PUSH BC | |||
44440 | LD HL,(44226) | HL=*TempStore_CommandBufferPointer. | ||
44443 | LD DE,43055 | DE=FourLetterBuffer. | ||
Ensure that the length is not more than 4.
|
||||
44446 | LD BC,4 | BC=0004. | ||
44449 | LD A,(44228) | Jump to CopyWordToBuffer if *TempStore_CommandBufferCount is greater than or equal to 4. | ||
44452 | CP C | |||
44453 | JR NC,CopyWordToBuffer | |||
The length is less than 4 so no need to copy 4 bytes.
|
||||
44455 | LD C,A | Copy the actual length of the word into C. | ||
Copy the word (up to 4 characters in length) into the four letter buffer.
|
||||
CopyWordToBuffer | 44456 | LDIR | Copy the "up-to-4" letters from the command buffer into the four-letter buffer. | |
44458 | POP BC | Restore the user input token counter, DE and command buffer pointer from the stack. | ||
44459 | POP DE | |||
44460 | POP HL | |||
44461 | PUSH HL | Stash the command buffer pointer back on the stack. | ||
Stash the vocabulary pointer for a separate check...
|
||||
44462 | LD HL,(42950) | Stash *Pointer_Vocabulary on the stack. | ||
44465 | PUSH HL | |||
Ignore any usage of "THE" - this is a very good idea! If the player enters: "EXAMINE THE SKULL", this ensures it's evaluated in the exact same way as "EXAMINE SKULL" (or really, "EXAM SKUL").
|
||||
44466 | LD HL,42599 | Write Table_Vocabulary_The to *Pointer_Vocabulary. | ||
44469 | LD (42950),HL | |||
44472 | CALL Handler_MatchItem | Call Handler_MatchItem. | ||
Do nothing with with this match - just restore the vocabulary pointer from the stack.
|
||||
44475 | POP HL | Restore *Pointer_Vocabulary from the stack and write it back to *Pointer_Vocabulary. | ||
44476 | LD (42950),HL | |||
44479 | POP HL | Restore HL from the stack. | ||
44480 | JR C,EmptyFourLetterBuffer | Jump to EmptyFourLetterBuffer if "THE" was successfully found. | ||
44482 | CALL Handler_MatchItem | Call Handler_MatchItem. | ||
44485 | JR C,StoreTokenAndContinue | Jump to StoreTokenAndContinue if an item was successfully found. | ||
Nothing matched ... Inform the player.
Print "I don't know the word:-".
|
||||
44487 | LD HL,43107 | HL=Messaging_IDontKnowTheWord. | ||
44490 | CALL PrintStringAndNewline | Call PrintStringAndNewline. | ||
Print a double quote character: "
" ".
|
||||
44493 | LD A,34 | Call PrintCharacter to print a double quote character (ASCII 34). | ||
44495 | CALL PrintCharacter | |||
44498 | LD HL,(44228) | HL=*TempStore_CommandBufferCount. | ||
44501 | LD DE,(44226) | HL+=*TempStore_CommandBufferPointer. | ||
44505 | ADD HL,DE | |||
44506 | LD (HL),255 | Write 255 to *HL. | ||
44508 | EX DE,HL | Exchange the DE and HL registers. | ||
44509 | CALL PrintString | Call PrintString. | ||
Print a double quote character: "
" ".
|
||||
44512 | LD A,34 | Call PrintCharacter to print another double quote character (ASCII 34). | ||
44514 | CALL PrintCharacter | |||
Print ".".
|
||||
44517 | LD HL,43541 | HL=Messaging_FullStop. | ||
44520 | CALL PrintStringAndNewline | Call PrintStringAndNewline. | ||
44523 | JP Handler_UserInput | Jump to Handler_UserInput. | ||
The word in the four-letter buffer was matched!
Store the found token and check if we can continue parsing.
|
||||
StoreTokenAndContinue | 44526 | LD (IX+0),A | Write the token to the current token slot. | |
44529 | INC IX | Move to the next token slot. | ||
44531 | DEC C | Decrease the token counter by one. | ||
44532 | JR Z,CheckVerbToken | Jump to CheckVerbToken if all token slots are filled. | ||
Token matching only uses four letters of every word so a buffer is used for processing.
Start by clearing the buffer.
|
||||
EmptyFourLetterBuffer | 44534 | PUSH HL | Stash the command buffer pointer and user input tokens counter on the stack. | |
44535 | PUSH BC | |||
44536 | LD HL,43055 | Load FourLetterBuffer into HL. | ||
44539 | LD B,4 | Set a counter in B for the 4 letters in the buffer. | ||
EmptyFourLetterBuffer_Loop | 44541 | LD (HL),32 | Write ASCII "SPACE" (32) to *HL. | |
44543 | INC HL | Increment HL by one. | ||
44544 | DJNZ EmptyFourLetterBuffer_Loop | Decrease the letter buffer counter by one and loop back to EmptyFourLetterBuffer_Loop until all four letters have been cleared. | ||
44546 | POP BC | Restore the user input tokens counter and command buffer pointer from the stack. | ||
44547 | POP HL | |||
44548 | PUSH DE | Stash DE on the stack. | ||
44549 | JR FindWordStart | Jump to FindWordStart. | ||
Skip delimiter characters to find the next word.
|
||||
SkipDelimiters | 44551 | INC HL | Move to the next byte of the command buffer. | |
FindWordStart | 44552 | LD A,(HL) | Fetch a character from the command buffer. | |
44553 | CP 13 | Jump to EndWordParsing if the character is "ENTER" (ASCII 13). | ||
44555 | JR Z,EndWordParsing | |||
44557 | CALL IsDelimiter | Call IsDelimiter. | ||
44560 | JR Z,SkipDelimiters | Jump to SkipDelimiters if the character is a delimiter. | ||
The character is not a delimiter.
|
||||
44562 | LD (44226),HL | Store the starting address of this new word in *TempStore_CommandBufferPointer. | ||
44565 | LD DE,0 | Initialise DE to 0000 to count the number of letters in the word. | ||
Just keep looping and moving across the command buffer until we hit a delimiter or an "ENTER" character.
|
||||
CountWordLength | 44568 | INC HL | Move to the next byte of the command buffer. | |
44569 | INC DE | Increment the letter counter by one. | ||
44570 | LD A,(HL) | Fetch a character from the command buffer. | ||
44571 | CP 13 | Jump to StoreWordLength if the character is "ENTER" (ASCII 13). | ||
44573 | JR Z,StoreWordLength | |||
44575 | CALL IsDelimiter | Call IsDelimiter. | ||
44578 | JR NZ,CountWordLength | Jump to CountWordLength if the character was not a delimiter. | ||
This is the end of the word, so store the word length.
|
||||
StoreWordLength | 44580 | LD (44228),DE | Write the letter counter to *TempStore_CommandBufferCount. | |
44584 | SCF | Set the carry flag to indicate that a word was successfully found. | ||
EndWordParsing | 44585 | POP DE | Restore DE from the stack. | |
44586 | JP C,ProcessFoundWord | Jump to ProcessFoundWord if a word was found. | ||
Check to see if any of the user input tokens have been populated, and if not, print "I don't understand.".
|
||||
CheckVerbToken | 44589 | LD A,(43044) | Jump to Response_NotUnderstood if *UserInput_Token_1 hold the terminator byte (255). | |
44592 | CP 255 | |||
44594 | JP Z,Response_NotUnderstood | |||
44597 | RET | Return. | ||
View the equivalent code in The Jewels Of Babylon.
|
Prev: 44283 | Up: Map | Next: 44598 |