Prev: 49155 Up: Map Next: 49217
49162: Handler: User Input
Used by the routines at UserInput_Enter and GameLoop.
Reset the screen position to defaults.
Handler_UserInput 49162 CALL SetDefaultScreenPosition Call SetDefaultScreenPosition.
Clear down the command buffer which will hold the users input.
49165 LD HL,48436 HL=CommandBuffer.
49168 LD A,32 Store the ASCII code for "SPACE" (" ") into A.
49170 LD B,50 Set a counter in B for the size of the command buffer (50 bytes).
Write "SPACE" 50 times wiping the entire command buffer.
EmptyCommandBuffer_Loop 49172 LD (HL),A Write A to *HL.
49173 INC HL Increment HL by one.
49174 DJNZ EmptyCommandBuffer_Loop Decrease the command buffer counter by one and loop back to EmptyCommandBuffer_Loop until the whole buffer is cleared.
Now print the prompt icon ">".
49176 CALL PrintInputPrompt Call PrintInputPrompt.
Initialise the command buffer.
49179 LD HL,48436 HL=CommandBuffer.
This entry point is used by the routine at UserInput_Delete.
Collect the users keypress.
UserInput_Loop 49182 CALL GetUserInput Call GetUserInput.
Check the two valid control keys "DELETE" and "ENTER".
49185 CP 12 Jump to UserInput_Delete if "DELETE" was pressed.
49187 JR Z,UserInput_Delete
49189 CP 13 Jump to UserInput_Enter if "ENTER" was pressed.
49191 JR Z,UserInput_Enter
49193 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_Loop.
49195 JR C,UserInput_Loop
Test if the current position in the command buffer is at the end (48485) of the buffer. For example:
Position Output
48436 49
48443 42
48450 35
48457 28
48464 21
48471 14
48478 7
48485 0
49197 EX DE,HL Jump back to UserInput_Loop if the input has reached the end of the command buffer (so don't process it).
49198 LD HL,48485
49201 AND A
49202 SBC HL,DE
49204 EX DE,HL
49205 JR Z,UserInput_Loop
The keypress is valid, so process it and print it to the screen.
49207 LD (HL),A Write the keypress into the command buffer at the current position.
49208 CALL SwitchNormalScreenOutput Call SwitchNormalScreenOutput.
49211 CALL PrintCharacter Call PrintCharacter.
49214 INC HL Increment the pointer to the command buffer by one.
49215 JR UserInput_Loop Jump back to UserInput_Loop.
Prev: 49155 Up: Map Next: 49217