One will also likely want to know how long one has held a button. The simplest way is to have a counter running when the input doesn't change, that resets when it does. Something like...
Code:
LDA previousButtons
CMP currentButtons
BEQ holding
LDA #0
STA heldFrames
BEQ holdingNext ;always triggers
holding:
INC heldFrames
holdingNext:
;whatever comes next
The problems with this simplest approach are that it rolls over at a little over 4 seconds (5 in PAL) and that any change in buttons resets it; thus, holding B while moving in various directions doesn't get saved. Sometimes this is desired, sometimes not.
A way around this is to store the intermediate result of (previousButtons XOR currentButtons) somewhere, which makes it easy to use an AND to mask out individual bits that have changed to implement multiple counters.
Code:
;need 8 bytes allocated for buttonHeldCounters...per controller
;this assumes only one controller.
LDA previousButtons
EOR currentButtons ;back when you were calculating for pressedButtons
STA changedButtons
AND currentButtons ;gets you pressedButtons
STA pressedButtons
LDA #1
LDX #0
LDY #0
holdCounterLoop:
BIT changedButtons ;AND without destroying which bit A is on
BEQ resetCounter
INC buttonHeldCounters, X
BNE holdCounterIter ;next button...unless it overflowed,
DEC buttonHeldCounter, X ;in which case, put it back at #$FF
BNE holdCounterIter ;This is always taken.
resetCounter:
STY buttonHeldCounter, X ;that is, store zero
holdCounterIter:
INX
ASL A
BCC holdCounterLoop ;when carry gets set, our test-bit has left the byte.
;and now the counters have been updated