Hello again, this time I'm having trouble with controller reading.
I'm using a loop in a sub-routine to copy the controller data into a variable, buttons1, which should copy each keypress into its own bit. I didn't write this, it came from the Nerdy Nights tutorials, and is a bit confusing and doesn't seem to work as said in the tutorial. Here's the code for the sub-routine:
And the code I'm using to check for a button press:
The bits in the buttons1 variable are supposed to read:
A, B, Sel, Start, Up, Down, Left, Right
This almost works.. but it doesn't seem to read the right button?
Where I have the bit set to 1, it works when I press Right. The 7th bit does nothing at all, and all the other bits just seem to be different button presses than they should be. Could anyone please explain why it's not working?
Edit: Yeah solved. Stupid mistake, I just forgot to put # in front of the byte used to check the controller inputs.. I feel dumb now
I'm using a loop in a sub-routine to copy the controller data into a variable, buttons1, which should copy each keypress into its own bit. I didn't write this, it came from the Nerdy Nights tutorials, and is a bit confusing and doesn't seem to work as said in the tutorial. Here's the code for the sub-routine:
Code:
ReadController1:
LDA #$01
STA $4016
LDA #$00
STA $4016
LDX #$08
ReadController1Loop:
LDA $4016
LSR A ; bit0 -> Carry
ROL buttons1 ; bit0 <- Carry
DEX
BNE ReadController1Loop
RTS
LDA #$01
STA $4016
LDA #$00
STA $4016
LDX #$08
ReadController1Loop:
LDA $4016
LSR A ; bit0 -> Carry
ROL buttons1 ; bit0 <- Carry
DEX
BNE ReadController1Loop
RTS
And the code I'm using to check for a button press:
Code:
MovePaddleUp1:
LDA buttons1
AND #%00001000 ; solved, forgot the #
BEQ MovePaddleUpDone1
LDA buttons1
AND #%00001000 ; solved, forgot the #
BEQ MovePaddleUpDone1
The bits in the buttons1 variable are supposed to read:
A, B, Sel, Start, Up, Down, Left, Right
This almost works.. but it doesn't seem to read the right button?
Where I have the bit set to 1, it works when I press Right. The 7th bit does nothing at all, and all the other bits just seem to be different button presses than they should be. Could anyone please explain why it's not working?
Edit: Yeah solved. Stupid mistake, I just forgot to put # in front of the byte used to check the controller inputs.. I feel dumb now