Post by limitzer0 on Feb 15, 2020 14:02:44 GMT -5
I plan on using all of the buttons on controller 1 to do the same thing. I initially used Read_Btns and just checked register A was not 0. I went to go back and use Vec_Btn_State but do not really see a reason to. Looking into it further it looks like I can save a few cycles by removing the LF1EA loop in Read_Btns. After the return from Read_Btns_2 I just look for register A being >00 and <=08 to count as a button push. Does anyone see anything wrong with this method? It seems simple and it all works fine but I've gotten little sleep and can't think straight at this point. Let me know if you all think there is a reason not to do it this way.
Read_Btns_2: LDX #Vec_Button_1_1 ;Point to button flags
LDA -3,X ;Save previous state
STA -2,X
LDA #$0E ;Sound chip register 0E to port A
STA <VIA_port_a
LDD #$1901 ;sound BDIR on, BC1 on, mux off
STA <VIA_port_b
NOP ;pause
STB <VIA_port_b ;sound BDIR off, BC1 off, mux off
CLR <VIA_DDR_a ;DDR A to input
LDD #$0901 ;sound BDIR off, BC1 on, mux off
STA <VIA_port_b
NOP ;pause
LDA <VIA_port_a ;Read buttons
COMA ;Convert to active high
STA -3,X ;Save buttons
STB <VIA_port_b ;sound BDIR off, BC1 off, mux off
LDB #$FF
STB <VIA_DDR_a ;DDR A to output
COMA ;Check for transitions
ORA -2,X
COMA
STA -1,X ;Store transition result
; PSHS A ;Save result for return value
; LDB #$01 ;Initialize bit position
;LF1EA2 TFR B,A ;Mask out bit
; ANDA ,S
; STA ,X+ ;Store masked bit
; ASLB ;Go back for next bit
; BNE LF1EA2
; PULS A,PC ;Get back transition bits and return
RTS