I have found a few BASIC and KERNAL functions and memory addresses related to getting a key press/line, but how can I simply wait for a key press, and get its code? I want to pause execution, and resume once a key is pressed. I do not want them to be queued up during execution.
Asked
Active
Viewed 435 times
1 Answers
3
The principle is to use a non-blocking call, and keep calling it until you get a key.
In assembler you can use the KERNAL function GETIN
at $FFE4
WAIT_KEY
jsr $FFE4 ; Calling KERNAL GETIN
beq WAIT_KEY ; If Z, no key was pressed, so try again.
; The key is in A
In BASIC you can use GET
10 GET A$:IF A$="" GOTO 10:REM WAIT FOR KEY
20 PRINT A$
Above I used spaces to make it more readable, but spaces are not necessary (they use memory and take time to process. It could be written as:
10 GETA$:IFA$=""GOTO10
20 PRINTA$
-
I'll try this! Thanks! – circl May 20 '21 at 18:05
-
It appears to! I was expecting it to be more complicated requiring you to mess with the jiffy clock. – circl May 25 '21 at 08:34
-
Ah I didn't understand that you had to put GET in a loop for it to wait the key, this makes sense now. – Lucas van Dongen Mar 28 '23 at 13:39