; Assumes 8_bit mem, 16-Bit index
; key	= 16-bit memory location to store joypad data
;
;##########################
; get a joy pad response  #
;##########################
_Joy .macro (key)
 php
 rep #$10
 sep #$20
 pha
 phy
 phx

Test_joy:
 lda $4210
 and #$80
 bne Test_joy

joypad:
 lda $4212 
 and #$01  
 bne joypad

 rep #$20
 lda $4218		; load the WORD joy value
 sta key		; holds the button status

 sep #$20
 plx
 ply
 pla
 plp 
.endm