![]() |
Routines |
| Prev: BF69 | Up: Map | Next: BFD8 |
|
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 | BF73 | CALL SetDefaultScreenPosition | Call SetDefaultScreenPosition to park the cursor at the top of the text. | |
|
Clear the command buffer.
|
||||
| BF76 | LD HL,$BB04 | Start at the command buffer (InputBuffer). | ||
| BF79 | LD A,$20 | Prepare a space (20) and a counter of 32 bytes. | ||
| BF7B | LD B,$32 | |||
| UserInput_Clear | BF7D | LD (HL),A | Write spaces through the whole command buffer. | |
| BF7E | INC HL | |||
| BF7F | DJNZ UserInput_Clear | |||
|
Print the ">" prompt.
|
||||
| BF81 | CALL PrintInputPrompt | Call PrintInputPrompt. | ||
|
Collect keypresses.
|
||||
| BF84 | LD HL,$BB04 | Start again at the beginning of the command. | ||
|
Wait for the next key.
|
||||
| UserInput_Loop | BF87 | CALL GetUserInput | Call GetUserInput. | |
|
DELETE rubs out a character. ENTER finishes the line. Any other control key is ignored.
|
||||
| BF8A | CP $0C | Jump to UserInput_Delete if DELETE was pressed. | ||
| BF8C | JR Z,UserInput_Delete | |||
| BF8E | CP $0D | Jump to UserInput_Enter if ENTER was pressed. | ||
| BF90 | JR Z,UserInput_Enter | |||
| BF92 | CP $20 | Jump back to UserInput_Loop when the key is below SPACE. | ||
| BF94 | JR C,UserInput_Loop | |||
|
Is the command buffer full?
|
||||
| BF96 | EX DE,HL | Jump back to UserInput_Loop once the pointer has reached the sentinel at BB35. | ||
| BF97 | LD HL,$BB35 | |||
| BF9A | AND A | |||
| BF9B | SBC HL,DE | |||
| BF9D | EX DE,HL | |||
| BF9E | JR Z,UserInput_Loop | |||
|
The key is valid, so store it and print it.
|
||||
| BFA0 | LD (HL),A | Write the key into the command buffer. | ||
| BFA1 | CALL SwitchToNormalScreenOutput | Call SwitchToNormalScreenOutput to select the screen channel. | ||
| BFA4 | CALL PrintCharacter | Call PrintCharacter to echo the key. | ||
| BFA7 | INC HL | Advance to the next space in the buffer. | ||
| BFA8 | JR UserInput_Loop | Jump back to UserInput_Loop for the next key. | ||
|
The player pressed DELETE.
|
||||
| UserInput_Delete | BFAA | EX DE,HL | Jump back to UserInput_Loop when the buffer is still empty. | |
| BFAB | LD HL,$BB04 | |||
| BFAE | AND A | |||
| BFAF | SBC HL,DE | |||
| BFB1 | EX DE,HL | |||
| BFB2 | JR Z,UserInput_Loop | |||
|
Rub the previous character off the screen.
|
||||
| BFB4 | PUSH HL | Keep the buffer pointer safe. | ||
| BFB5 | LD HL,$BB58 | Print " ". | ||
| BFB8 | CALL PrintString | |||
| BFBB | POP HL | Restore the buffer pointer from the stack. | ||
| BFBC | DEC HL | Step back one character and blank it. | ||
| BFBD | LD (HL),$20 | |||
| BFBF | 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 | BFC1 | LD (HL),A | Store ENTER as the end of the command. | |
| BFC2 | CALL SwitchToNormalScreenOutput | Call SwitchToNormalScreenOutput to select the screen channel. | ||
| BFC5 | CALL PrintCharacter | Call PrintCharacter to echo ENTER. | ||
| BFC8 | LD HL,$BB36 | Start at the token buffer (BB36) and prepare the empty marker FF. | ||
| BFCB | LD A,$FF | |||
| BFCD | LD B,$0A | |||
| UserInput_ClearTokens | BFCF | LD (HL),A | Write FF into each of the 0A token slots. | |
| BFD0 | INC HL | |||
| BFD1 | DJNZ UserInput_ClearTokens | |||
| BFD3 | LD HL,$BB04 | Start at the command and allow 0A words, then fall into the parser. | ||
| BFD6 | LD C,$0A | |||
|
View the equivalent code in;
|
||||
| Prev: BF69 | Up: Map | Next: BFD8 |