; This is the code I've been using, I think I stole it from one of SnoBro's programs, I hope he doesn't mind. :)
lda joy1
sta joy1old
ldy #$01 ;
sty $4016 ; reset strobe
dey
sty $4016 ; clear strobe
sty joy1 ; clears joystick data
ldy #$08 ; do all 8 buttons
read_buttons:
lda $4016 ; load button status
and #$01 ; only keep lowest bit
lsr a ; transfer to carry flag
rol joy1
dey
bne read_buttons
;(change the lda $4016 to $4017 for player 2)
a_button = 128
b_button = 64
select_button = 32
start_button = 16
up_button = 8
down_button = 4
left_button = 2
right_button = 1
; And a macro I made to use with CA65.. Uses the button and branch labels (if not pressed) as parameters.
; And what I forgot to mention is that $4016 is the strobe for both joysticks. $4017 is different for writing.
;---------------------------------------------------------
; Check Controller
; (macro: controller button,branch,(optional)branch
;---------------------------------------------------------
.macro controller button,not_pressed,button_held
.ifblank button_held
lda joy1
and #button
beq not_pressed
.endif
.ifnblank button_held
lda joy1
and #button
beq not_pressed
and joy1old
bne button_held
.endif
.endmacro
;---------------------------------------------------------