2

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.

circl
  • 121
  • 8

1 Answers1

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$
Cactus
  • 27,075
  • 9
  • 69
  • 149
some
  • 48,070
  • 14
  • 77
  • 93