Skip to content

Apple II 8. Keyboard

StewBC edited this page Feb 16, 2020 · 1 revision

Reading the keyboard in assembly language is quite easy. You have already seen it in spkr.asm but, it may look something like this if you wanted to know which key was pressed:

    # Get the definitions for KBDSTRB and KBD
    .include "apple2.inc"

    sta KBDSTRB     ; clear the keyboard strobe bit (bit 7 in KBD)
:
    lda KBD         ; get a key
    bpl :-          ; loop till bit 7 is set, meaning there's a new key
    sta KBDSTRB     ; clear the keyboard strobe bit (i.e. "consume"; this last key)
    ; Bits 0-6 now contain the key code for the key pressed, and bit 7
    ; is 1, indicating a key was pressed.  Depending on your needs
    ; this can now be processed further (normalized) - such as working
    ; with upper/lower case, etc.
Clone this wiki locally