Now that my memory issues are seemingly under control, let's take a look at my modifications to the parser. Normally, in these types of graphical adventures the player enters two words in the form of
VERB OBJECT. My interface limits the number of verb choices and allows the player to enter a verb with a single keystroke.
In Applesoft you can prompt for user input in two ways. First there is
INPUT A$ which will display a question mark on the screen and await user input followed by a RETURN. That user response then fills the variable A$. Similarly there is
GET A$ which also displays a question mark but
GET will only accept a single keypress as user input. My main problem with both of these is an aesthetic one: that darn question mark.
The solution is to write your own input routine leveraging machine code routines via
POKEs. To do this, first I simulate a cursor by placing a flashing underscore character at the bottom of the screen.
101 VTAB 24 : HTAB 1 : CALL -868 : PRINT ":"; : FLASH : PRINT "_"; : NORMAL : GOSUB 55
A lot is going on in this line. The
HTAB commands position the screen cursor at line 24 and character 1.
CALL -868 is a special machine code call that clears that single line of text. Now that we have an empty line we type a colon and then a flashing underscore. The result looks like this:
This looks like a user input prompt, but at this point it does nothing. The magic happens at the subroutine which is GOSUB'd at the end of that line.
55 KEY = PEEK (49152) : IF KEY < 128 THEN 55 56 IF KEY > 224 AND KEY < 251 THEN KEY = KEY - 32 : REM UPPERCASE 57 POKE 49168,0 : BUZZ = PEEK (49200) : RETURN
In line 55 we are creating a variable KEY and assigning to it the contents of memory location 49,152 to it ($C000 for you hex-heads). Turns out location 49,152 will read the keyboard and return the ASCII value of the currently pressed key. If that value is a character then we break out of the loop and go to line 56.
Line 56 insures that, if the ASCII value of the key denotes a lowercase key, it is converted to uppercase by shifting the ASCII value.
POKE 49168,0 clears the keyboard buffer so that the PEEK in 55 will work next time around and not just register the same value. Finally, that
BUZZ = PEEK (49200) bit triggers a speaker click so that the player's keystroke has and audible sound.
When we return to the main game loop we now have a variable KEY which contains an ASCII value of the key pressed. I can then branch the program based on this value. I can also test if it's a RETURN keypress and then toggle text display. Later in my program I can concatenate keypresses into a single string value by returning to that subroutine again and again until a return press is detected. That's how I collect the OBJECT half of the VERB OBJECT pair.