New Project

A place where you can keep others updated about your NES-related projects through screenshots, videos or information in general.

Moderator: Moderators

User avatar
qbradq
Posts: 972
Joined: Wed Oct 15, 2008 11:50 am

Post by qbradq »

Oh, wow, thanks for the info TheFox :D

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
Or should the AND mask be different?
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

unregistered wrote:How does CMP #$01 detect whether a button is pressed rehgardless of the bit?
The AND #$03 clears all bits but the lowest 2, which means that the possible values for the result are:

%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..
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

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.
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. :)
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Post by Bregalad »

unregistered wrote: and N stands for the non-zero flag
Not quite, it stands for the Negative flag.

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.
Useless, lumbering half-wits don't scare us.
User avatar
qbradq
Posts: 972
Joined: Wed Oct 15, 2008 11:50 am

Post by qbradq »

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 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.
3gengames
Formerly 65024U
Posts: 2284
Joined: Sat Mar 27, 2010 12:57 pm

Post by 3gengames »

Bregalad wrote: DON'T EVER use RMW instructions on registers.
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! :D :wink: lol
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Post by unregistered »

tokumaru wrote:
unregistered wrote:How does CMP #$01 detect whether a button is pressed rehgardless of the bit?
The AND #$03 clears all bits but the lowest 2, which means that the possible values for the result are:

%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..
Thanks! :D
dsv101
Posts: 36
Joined: Fri Jun 17, 2011 5:16 am
Location: United States
Contact:

Post by dsv101 »

Update Post:

I have a new member involved. His s/n is Cooshinator.

We have to go through a concept conversation and stuff, but the game may end up not being a space shooter, or it may. Who knows?

Anyway, our jobs are as follows

Me: Programmer

Cooshinator: GFX and Music

Time to restart, pay attention to every detail, and try that controller read loop and stuff you guys recommend highly :)
~Yeah, I Said That
User avatar
Bregalad
Posts: 8056
Joined: Fri Nov 12, 2004 2:49 pm
Location: Divonne-les-bains, France

Post by Bregalad »

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.
Forget it, I just was in a very bad mood the other day because of a stupid physics exam.

For some reason I thought controller_state was some hardware resister but of course it's not. That's what I like to use plain register adress so that you can immediately see it's a register and avoid the confusion (and I'm dumb too). Also if you really inist on using a label instead of using $4016, it's a good idea to make the label all in caps which is commonly used for constants.

So yeah if you replace the and #$89 by and #$03 I think this will actually work. Although I'm not sure it's faster to tepples' solution (which happens to also be my solution). So yeah the AND mask should be different.
Useless, lumbering half-wits don't scare us.
User avatar
qbradq
Posts: 972
Joined: Wed Oct 15, 2008 11:50 am

Post by qbradq »

Honestly I didn't read pages 2 and 3 (and most of 4) so I probably shouldn't have said anything anyway. My actual controller reading routine is much different that this as well, but it only handles data on D0 ($4016 READ bit 0).

I made up the register name of the fly because I couldn't be bothered to look up the address :D
dsv101
Posts: 36
Joined: Fri Jun 17, 2011 5:16 am
Location: United States
Contact:

Post by dsv101 »

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.
~Yeah, I Said That
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

The background color is always color 0. Which paint program or tile editor are you using to create your sprite cels?
dsv101
Posts: 36
Joined: Fri Jun 17, 2011 5:16 am
Location: United States
Contact:

Post by dsv101 »

yychr of course :)
~Yeah, I Said That
dsv101
Posts: 36
Joined: Fri Jun 17, 2011 5:16 am
Location: United States
Contact:

Post by dsv101 »

also, it seems as if the first color of the palette is always keyed out, is this true?
~Yeah, I Said That
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

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.
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.

Also, note that even though there is physical memory to hold a different color 0 for each background palette, the one that always gets displayed is the one in the first palette. The others are never displayed during normal rendering.
Post Reply