Simple way to *wait* for a key press, and get its martrix or PETSCII code?

718 views Asked by At

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.

1

There are 1 answers

3
some On BEST ANSWER

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$