I stole this from someone, and it works pretty universally and has all the controller info you'll need...ever. It is pretty close to what you're using. After that, I'd just do:
LDA joypad1_pressed
AND #%00001000 ;assuming that I have right bits
STA bitchinvarible
LDA joypad1_pressed
AND #%00000100
STA lamevariable
And set the variables to whatever you want them to be.
; read_joypad will capture the current button state and store it in joypad1.
; Off-to-on transitions will be stored in joypad1_pressed
strobe_controllers:
lda joypad1
sta joypad1_old ;save last frame's joypad button states
lda joypad2
sta joypad2_old ;save last frame's joypad button states
lda #$01
sta $4016
lda #$00
sta $4016
ldx #$08
.loop:
lda $4016
lsr a
rol joypad1 ;A, B, select, start, up, down, left, right
dex
bne .loop
lda joypad1_old ;what was pressed last frame. EOR to flip all the bits to find ...
eor #$FF ;what was not pressed last frame
and joypad1 ;what is pressed this frame
sta joypad1_pressed ;stores off-to-on transitions
ldx #$08
.loop2:
lda $4017
lsr a
rol joypad2 ;A, B, select, start, up, down, left, right
dex
bne .loop2
lda joypad2_old ;what was pressed last frame. EOR to flip all the bits to find ...
eor #$FF ;what was not pressed last frame
and joypad2 ;what is pressed this frame
sta joypad2_pressed ;stores off-to-on transitions
rts