Prev: 65FA Up: Map Next: 6669
6604: Handler: User Input
Used by the routines at Handler_UnknownWord, GameLoop and ActionRead.
Handles keyboard input, tokenises commands and validates the vocabulary.
Prepare a blank command line.
Handler_UserInput 6604 CALL SetDefaultScreenPosition Call SetDefaultScreenPosition to park the cursor at the default position.
6607 LD HL,$625F Blank the command buffer 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
Ask for a command.
6612 CALL PrintInputPrompt Call PrintInputPrompt to print the prompt.
6615 LD HL,$625F The next character is stored at the start of the command.
Read the next key.
Handler_UserInput_Loop2 6618 CALL GetUserInput Call GetUserInput to wait for a keypress.
661B CP $0C Jump to Handler_UserInput_Step1 when DELETE (0C) was pressed.
661D JR Z,Handler_UserInput_Step1
661F CP $0D Jump to Handler_UserInput_Step2 when ENTER (0D) was pressed.
6621 JR Z,Handler_UserInput_Step2
6623 CP $20 Jump back to Handler_UserInput_Loop2 when the key is a control character.
6625 JR C,Handler_UserInput_Loop2
6627 EX DE,HL Jump back to Handler_UserInput_Loop2 when the command buffer is full.
6628 LD HL,$6290
662B AND A
662C SBC HL,DE
662E EX DE,HL
662F JR Z,Handler_UserInput_Loop2
6631 LD (HL),A Store the character in the command buffer and print 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 there is nothing to delete.
663C LD HL,$625F
663F AND A
6640 SBC HL,DE
6642 EX DE,HL
6643 JR Z,Handler_UserInput_Loop2
6645 PUSH HL Print   and rub out the last 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.
Handler_UserInput_Step2 6652 LD (HL),A Store the terminator and echo the newline.
6653 CALL SwitchToNormalScreenOutput
6656 CALL PrintCharacter
6659 LD HL,$6291 Point at the word tokens and prepare the empty marker (FF).
665C LD A,$FF
665E LD B,$0A
Handler_UserInput_Loop3 6660 LD (HL),A Mark every word token as empty.
6661 INC HL
6662 DJNZ Handler_UserInput_Loop3
6664 LD HL,$625F Up to 0A words of the command are accepted.
6667 LD C,$0A
Prev: 65FA Up: Map Next: 6669