So then the code I posted becomes this:
Code: Select all
ldx #8
polling_loop:
asl controller_state
lda reg_ctrl_port1
and #$89
beq next
inc controller_state
next:
dex
bne polling_loop
Moderator: Moderators
Code: Select all
ldx #8
polling_loop:
asl controller_state
lda reg_ctrl_port1
and #$89
beq next
inc controller_state
next:
dex
bne polling_loop
The AND #$03 clears all bits but the lowest 2, which means that the possible values for the result are:unregistered wrote:How does CMP #$01 detect whether a button is pressed rehgardless of the bit?
Ooh, i get it now. C stands for the carry flag, Z is zero flag, and N stands for the non-zero flag. Now I need to read tokumaru's reply again.Bregalad wrote:The "magic" is that CMP #$01 is basically equivalent to C <- Z and CMP #$80 is basically equivalent to C <- N
You can quite often make your code smaller/faster using those two tricks.
Not quite, it stands for the Negative flag.unregistered wrote: and N stands for the non-zero flag
I think you're being a little harsh there. I didn't say that was a complete example. That's just the reading loop. And I didn't use a Read Modify Write instruction on a register. The only instruction that touches a register is LDA.Bregalad wrote:And qbradq don't post some nonsense code like that. There is no way any of it will ever work. You need to write 1->0 to $4016, and read it 8 times, there is no way arround that.
DON'T EVER use RMW instructions on registers.
The only faster thing you can do is do it in an unrolled loop.
I forgot about that when I suggested something like that for a faster controller reading routine, didn't think about it, but yeah don't use them, like me. And that code is pretty dumb truthfully. And using X to store the value 1 then 0 to 4016 is used by stuff and isn't widely used, I wish that was noted somewhere, instead of just using A and losing a whole 1 byte, heh. Just kidding, but it seems worth the gain when you're strapped for ROM. Although there's probably many more ways to go around with this stuff, in the mean time lets post them all and figure out another topic to blow up! lolBregalad wrote: DON'T EVER use RMW instructions on registers.
Thanks!tokumaru wrote:The AND #$03 clears all bits but the lowest 2, which means that the possible values for the result are:unregistered wrote:How does CMP #$01 detect whether a button is pressed rehgardless of the bit?
%00000000 (decimal 0) (no button pressed on either controller)
%00000001 (decimal 1) (pressed on controller 1, not pressed on controller 3)
%00000010 (decimal 2) (not pressed on controller 1, pressed on controller 3)
%00000011 (decimal 3) (pressed on both controller)
The CMP instruction is a subtraction, if the result of the subtraction is positive the carry will be set. Since we're subtracting 1, the only way the result will be negative is when the value is 0, i.e. no button is pressed on either controller. In the other 3 cases the carry will be set, accurately reflecting the fact that the button is pressed on at least one of the controllers..
Forget it, I just was in a very bad mood the other day because of a stupid physics exam.I think you're being a little harsh there. I didn't say that was a complete example. That's just the reading loop. And I didn't use a Read Modify Write instruction on a register. The only instruction that touches a register is LDA.
When background tiles use color 0, no matter the palette, the background color is displayed (color 0 of the first background palette). For sprites, the transparent color is always color 0. You can't even set an actual color for it when writing the palette, there is no internal memory to hold that information. Actually, if you try to set those colors, they'll be written to the corresponding places in the background palette, overwriting whatever you wrote there previously.dsv101 wrote:Me and Cooshinator came up with a question, how do you set a backgroud color and key out a color in sprites? I found a tutorial for putting tiles in the background, but i figured you should be able to set a background color.