read: ldx #01h loop2: ldy #09h sty 4016h dey sty 4016h loop: lda 4016h,x lsr a rol buttons,x dey bne loop lda buttons,x pha eor oldbuts,x and buttons,x sta pressed,x pla sta oldbuts,x dex bpl loop2 rts RAM variables: ;first byte is controller 1, second byte is controller 2. buttons: .dsb 2 ;reserve 2 bytes for current state of the buttons oldbuts: .dsb 2 ;reserve 2 bytes for old state of the buttons pressed: .dsb 2 ;reserve 2 bytes for which buttons were just pressed