Prev: 65FA Up: Map Next: 6669
6604: Handler: User Input
Used by the routines at Handler_UnknownWord, GameLoop and ActionRead.
Read a line of text, then turn it into vocabulary tokens.
Reset the cursor to the default text position.
Handler_UserInput 6604 CALL SetDefaultScreenPosition Call SetDefaultScreenPosition.
Clear the command buffer.
6607 LD HL,$625F Blank CommandBuffer with 32 spaces.
660A LD A,$20
660C LD B,$32
Handler_UserInput_Loop1 660E LD (HL),A Write spaces through the command buffer.
660F INC HL
6610 DJNZ Handler_UserInput_Loop1
Print the ">" prompt.
6612 CALL PrintInputPrompt Call PrintInputPrompt.
Collect keypresses into the command buffer.
6615 LD HL,$625F Start at the beginning of CommandBuffer.
Wait for the next key.
Handler_UserInput_Loop2 6618 CALL GetUserInput Call GetUserInput.
DELETE rubs out a character. ENTER finishes the line. Any other control key is ignored.
661B CP $0C Jump to Handler_UserInput_Step1 if DELETE was pressed.
661D JR Z,Handler_UserInput_Step1
661F CP $0D Jump to Handler_UserInput_Step2 if ENTER was pressed.
6621 JR Z,Handler_UserInput_Step2
6623 CP $20 Jump back to Handler_UserInput_Loop2 when the key is below SPACE.
6625 JR C,Handler_UserInput_Loop2
Is the command buffer full?
6627 EX DE,HL Jump back to Handler_UserInput_Loop2 once the pointer has reached the end of CommandBuffer.
6628 LD HL,$6290
662B AND A
662C SBC HL,DE
662E EX DE,HL
662F JR Z,Handler_UserInput_Loop2
The key is valid, so store it and print it.
6631 LD (HL),A Write the key into the buffer and echo it.
6632 CALL SwitchToNormalScreenOutput
6635 CALL PrintCharacter
6638 INC HL
6639 JR Handler_UserInput_Loop2
The player pressed DELETE.
Handler_UserInput_Step1 663B EX DE,HL Jump back to Handler_UserInput_Loop2 when the buffer is still empty.
663C LD HL,$625F
663F AND A
6640 SBC HL,DE
6642 EX DE,HL
6643 JR Z,Handler_UserInput_Loop2
Rub the previous character off the screen.
Print " ".
6645 PUSH HL Print " " and blank the previous character.
6646 LD HL,$62E3
6649 CALL PrintString
664C POP HL
664D DEC HL
664E LD (HL),$20
6650 JR Handler_UserInput_Loop2
The player pressed ENTER, so close the command and clear the tokens.
Handler_UserInput_Step2 6652 LD (HL),A Store ENTER as the terminator and echo the newline.
6653 CALL SwitchToNormalScreenOutput
6656 CALL PrintCharacter
Initialise the word token buffer. Up to 0A vocabulary tokens are stored at UserInput_FirstToken; FF marks an empty slot.
6659 LD HL,$6291 Point at UserInput_FirstToken and prepare the empty marker (FF).
665C LD A,$FF
665E LD B,$0A
Handler_UserInput_Loop3 6660 LD (HL),A Write FF into each of the 0A token slots.
6661 INC HL
6662 DJNZ Handler_UserInput_Loop3
6664 LD HL,$625F Start at the command and allow 0A words, then fall into Parser_MatchInputWord.
6667 LD C,$0A
Prev: 65FA Up: Map Next: 6669