Prev: 49001 Up: Map Next: 49112
49011: Handler: User Input
Used by the routines at Handler_UnknownWord and GameLoop.
Read a line of text, then turn it into vocabulary tokens.
Reset the cursor to the top of the text window.
Handler_UserInput 49011 CALL SetDefaultScreenPosition Call SetDefaultScreenPosition to park the cursor at the top of the text.
Clear the command buffer.
49014 LD HL,47876 Start at the command buffer (InputBuffer).
49017 LD A,32 Prepare a space (32) and a counter of 50 bytes.
49019 LD B,50
UserInput_Clear 49021 LD (HL),A Write spaces through the whole command buffer.
49022 INC HL
49023 DJNZ UserInput_Clear
Print the ">" prompt.
49025 CALL PrintInputPrompt Call PrintInputPrompt.
Collect keypresses.
49028 LD HL,47876 Start again at the beginning of the command.
Wait for the next key.
UserInput_Loop 49031 CALL GetUserInput Call GetUserInput.
DELETE rubs out a character. ENTER finishes the line. Any other control key is ignored.
49034 CP 12 Jump to UserInput_Delete if DELETE was pressed.
49036 JR Z,UserInput_Delete
49038 CP 13 Jump to UserInput_Enter if ENTER was pressed.
49040 JR Z,UserInput_Enter
49042 CP 32 Jump back to UserInput_Loop when the key is below SPACE.
49044 JR C,UserInput_Loop
Is the command buffer full?
49046 EX DE,HL Jump back to UserInput_Loop once the pointer has reached the sentinel at 47925.
49047 LD HL,47925
49050 AND A
49051 SBC HL,DE
49053 EX DE,HL
49054 JR Z,UserInput_Loop
The key is valid, so store it and print it.
49056 LD (HL),A Write the key into the command buffer.
49057 CALL SwitchToNormalScreenOutput Call SwitchToNormalScreenOutput to select the screen channel.
49060 CALL PrintCharacter Call PrintCharacter to echo the key.
49063 INC HL Advance to the next space in the buffer.
49064 JR UserInput_Loop Jump back to UserInput_Loop for the next key.
The player pressed DELETE.
UserInput_Delete 49066 EX DE,HL Jump back to UserInput_Loop when the buffer is still empty.
49067 LD HL,47876
49070 AND A
49071 SBC HL,DE
49073 EX DE,HL
49074 JR Z,UserInput_Loop
Rub the previous character off the screen.
49076 PUSH HL Keep the buffer pointer safe.
49077 LD HL,47960 Print " ".
49080 CALL PrintString
49083 POP HL Restore the buffer pointer from the stack.
49084 DEC HL Step back one character and blank it.
49085 LD (HL),32
49087 JR UserInput_Loop Jump back to UserInput_Loop for the next key.
The player pressed ENTER, so close the command and clear the tokens.
UserInput_Enter 49089 LD (HL),A Store ENTER as the end of the command.
49090 CALL SwitchToNormalScreenOutput Call SwitchToNormalScreenOutput to select the screen channel.
49093 CALL PrintCharacter Call PrintCharacter to echo ENTER.
49096 LD HL,47926 Start at the token buffer (47926) and prepare the empty marker 255.
49099 LD A,255
49101 LD B,10
UserInput_ClearTokens 49103 LD (HL),A Write 255 into each of the 10 token slots.
49104 INC HL
49105 DJNZ UserInput_ClearTokens
49107 LD HL,47876 Start at the command and allow 10 words, then fall into the parser.
49110 LD C,10
Prev: 49001 Up: Map Next: 49112