Skip navigation
NintendoAge
Welcome, Guest! Please Login or Join
Loading...

Nerdy Nights week 4 Color Palettes, Sprites, second app

Feb 25, 2011 at 7:24:43 AM
removed04092017 (0)
This user has been banned -- click for more information.
< Bowser >
Posts: 7316 - Joined: 12/04/2010
Other
Profile
You need to point the PPU to the sprite RAM. Without looking I want to say:

LDA $2002
LDA #$3F
STA $2003
LDA #$00 
STA $2003

That will point it to the PPU's pallet ram. Then you upload a new pallet, or you can do something like storing $3F10 and then only change the pallets you need. Go to $3020 to upload both palettes at the same time.


Edited: 07/25/2011 at 12:49 AM by removed04092017

Feb 25, 2011 at 8:39:13 AM
Mario's Right Nut (352)
avatar
(Cunt Punch) < Bowser >
Posts: 6634 - Joined: 11/21/2008
Texas
Profile
3GenGames, you've confused me. The sprite palettes are in bits 0and1, not as you've specified above. Also. Couple other things I can't xo on my phone.

-------------------------

This is my shiny thing, and if you try to take it off me, I may have to eat you.

Check out my dev blog.


Feb 25, 2011 at 9:27:44 AM
albailey (55)
avatar
(Al Bailey) < Lolo Lord >
Posts: 1523 - Joined: 04/10/2007
Ontario
Profile
Do this to change the palette for sprites:
LDA $2002 ; this resets the toggle
LDA #$3F
STA $2006
LDA #$10
STA $2006

LDX #$00
: LDA myPaletteTable,x
STA $2007
inx
cpx #$10 ; $10 hex == 16 decimal
bne :-

This gets you pointing at $3F10 which is the first of the sprite palette.
It then copies 16 bytes to the sprite palette.

This assumes you are set to increment PPU by 1.

Refer to this page: http://wiki.nesdev.com/w/index.ph... and the entry that says: VRAM address increment per CPU read/write of PPUDATA



As for your question about sprite 0.
It appears that you are using mem page 2 for sprites.
That means $0200-02FF will represent all 64 possible sprites you can have on the screen.
$0200-$0203  are for sprite 0
$0204-$0207  are for sprite 1
etc..

If you want to create or move a different sprite, do so for the memory that corresponds to that sprite.
Al


Al

-------------------------

My Gameboy collection  97% complete.          My N64 collection   88% complete



 My Gamecube collection  99% complete        My NES collection   97% complete



Edited: 02/25/2011 at 09:29 AM by albailey

Feb 25, 2011 at 10:56:44 AM
KHAN Games (89)
avatar
(Kevin Hanley) < Master Higgins >
Posts: 8124 - Joined: 06/21/2007
Florida
Profile
Yes, if you want to move NOT sprite 0, you skip $0200-$0203 and just move $0204 and $0207 for sprite 1.

To change the color of the sprite, you need to first of all edit the palettes that you have. There are four different palette sections for sprites. Something like this is in your document if you're using nerdy nights.

$xx,$00,$00,$00, $xx,$00,$00,$00, $xx,$00,$00,$00, $xx,$00,$00,$00 ;sprites
$xx,$00,$00,$00, $xx,$00,$00,$00, $xx,$00,$00,$00, $xx,$00,$00,$00 ;background

The first 16 bytes are the color palette for sprites. You need to write #$00 to $0202 to use the first section, #$01 to $0202 to use the second palette, #$02 to $0203 to use the third, and #$03 to use the fourth.

Of course you're going to need to change all of the values in the palette area to something other than $00 to get colors you want.

The first color in each of the 16 4-byte sections (designated here with x's) is the transparent color. Usually these all need to be the same, but I think basically whatever you have the first value set at, it will automatically make the other 7 first-bytes that same value. So don't be surprised if you try to change that color and nothing happens.

-------------------------

gauauu: look, we all paid $10K at some point in our lives for the privilege of hanging out with Kevin



Edited: 02/25/2011 at 10:59 AM by KHAN Games

Feb 25, 2011 at 3:36:59 PM
removed04092017 (0)
This user has been banned -- click for more information.
< Bowser >
Posts: 7316 - Joined: 12/04/2010
Other
Profile
Originally posted by: Mario's Right Nut

3GenGames, you've confused me. The sprite palettes are in bits 0and1, not as you've specified above. Also. Couple other things I can't xo on my phone.


Sorry. I am touching on changing the palette since I thought he just asked that, but I guess he wants to assign the sprite a different palette. Since he is confused about the palette assigning, I'll try to help with that now:


Bits number 0 and 1 assign the color palette inside the attributes byte of sprite RAM in the 3rd register for sprite RAM.

#%00000000=Palette 0;
#%00000001=Palette 1;
#%00000010=Palette 2;
#%00000011=Palette 3;


Those values will change what palette the sprite uses. if you want any other attributes set, just set the bits you want (ORA instruction):

  76543210
||| ||
||| ++- Color Palette of sprite. Choose which set of 4 from the 16 colors to use
|||
||+------ Priority (0: in front of background; 1: behind background)
|+------- Flip sprite horizontally
+-------- Flip sprite vertically

Edit: fixed text width to fixed-width. Sorry for the mix up.


Edited: 02/25/2011 at 04:39 PM by removed04092017

Jul 24, 2011 at 8:40:42 PM
toshi5o3 (64)
avatar
(Sergio E.) < Meka Chicken >
Posts: 807 - Joined: 03/14/2011
California
Profile
Finally had a chance to get back on track with the lessons! Went back a bit to refresh what I had studied, but so far so good. Lesson 4 is in the bag! It's really cool to be able to change the colors on the back of Mario's head/hat. Cheers!


-------------------------
"A Winner is You" -- Real audio on a cart? Full length NES album? Now you're listening with power. Play it on your AVS (or toaster): RetroUSB.com

Aug 3, 2011 at 3:36:36 PM
Laserbeak43 (0)
avatar
(Malik Martin) < Cherub >
Posts: 4 - Joined: 05/22/2008
Maryland
Profile
Originally posted by: bunnyboy

$0D is a bad color and should not be used.



was that a joke?

Aug 3, 2011 at 3:38:05 PM
removed04092017 (0)
This user has been banned -- click for more information.
< Bowser >
Posts: 7316 - Joined: 12/04/2010
Other
Profile
Originally posted by: Laserbeak43

Originally posted by: bunnyboy

$0D is a bad color and should not be used.



was that a joke?


Nope. On digitally run TV's, it will likely roll the screen. Don't use it. Use 0F.

Aug 3, 2011 at 4:58:46 PM
NESHomebrew (21)
avatar
(Brad Bateman - Strange Brew Games) < King Solomon >
Posts: 4264 - Joined: 04/28/2008
Saskatchewan
Profile
Originally posted by: 3GenGames

Originally posted by: Laserbeak43

Originally posted by: bunnyboy

$0D is a bad color and should not be used.



was that a joke?


Nope. On digitally run TV's, it will likely roll the screen. Don't use it. Use 0F.
Quoted from nesdev wiki "Note that a value of $0D should not be used (brightness=0, hue=13), as this results in a "blacker than black" color that causes stability problems on some televisions. "

Aug 3, 2011 at 5:04:53 PM
removed04092017 (0)
This user has been banned -- click for more information.
< Bowser >
Posts: 7316 - Joined: 12/04/2010
Other
Profile
That'd be it.

Sep 3, 2011 at 8:24:08 PM
derekb (0)

(d b) < Cherub >
Posts: 12 - Joined: 08/24/2011
Texas
Profile
I'm having a trouble doing palette cycling and was wondering if anyone could help, when I change a palette color my entire background winds up pushing itself down for some reason, my lil code snip is

[code]
lda $2002
lda #$3F
sta $2006
lda #$00
sta $2006
lda #$0F
sta $2007
RTS
[/code]

before:



after code runs:



(the boxes on top are just reference points to see whats happened)

if anyone has an idea off top of their head of what would cause this please lmk

Sep 3, 2011 at 8:37:45 PM
removed04092017 (0)
This user has been banned -- click for more information.
< Bowser >
Posts: 7316 - Joined: 12/04/2010
Other
Profile
Are you only doing it in vblank? That could be because of the $2006 writes during rendering aren't the same as pointing it so memory, it affects the internal registers for such things as scroll and stuff. And also, you're only changing palette 0 there, so that'll only affect the background color 0, making it 0F, which is the right color black. For best help, post all of your code and we can point all the stuff out.


Edited: 09/03/2011 at 09:01 PM by removed04092017

Sep 3, 2011 at 8:58:06 PM
thefox (0)
avatar
(Kalle Immonen) < Meka Chicken >
Posts: 533 - Joined: 07/08/2008
Finland
Profile
Originally posted by: derekb

I'm having a trouble doing palette cycling and was wondering if anyone could help, when I change a palette color my entire background winds up pushing itself down for some reason, my lil code snip is 

Always at the end of vblank, after all PPU updates (but still in vblank) remember to set the scroll using $2005 *and* $2000.

Something like this should be enough if you just want to scroll to the upper left corner (of course you can change the $2000 flags depending on your needs):

lda #%10001000
sta $2000
lda #0
sta $2005
sta $2005


-------------------------
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: kkfos.aspekt.fi

Sep 4, 2011 at 8:36:56 PM
derekb (0)

(d b) < Cherub >
Posts: 12 - Joined: 08/24/2011
Texas
Profile
3GenGames: I'm gonna change more palette values, I just condensed my code down to easily show the problem

thefox thanks I'll try that out

Sep 4, 2011 at 8:40:59 PM
removed04092017 (0)
This user has been banned -- click for more information.
< Bowser >
Posts: 7316 - Joined: 12/04/2010
Other
Profile
If you want me to help, I'm online all the time, just send me a PM and I'll work with you to fix it.

Feb 14, 2012 at 1:44:27 AM
glenn101 (0)
avatar
(Glenn Kirilov) < Tourian Tourist >
Posts: 37 - Joined: 02/11/2012
Victoria
Profile
Just curious, where in the PPU memory are these 64 sprites stored which you transferred via DMA, where is sprite memory located?
I thought it would be somewhere between $0000 and $2000 but the mario.chr data is stored there correct?

Feb 14, 2012 at 1:52:52 AM
bunnyboy (81)
avatar
(Funktastic B) < Master Higgins >
Posts: 7704 - Joined: 02/28/2007
California
Profile
Sprites are in their own RAM, internal to the PPU chip. Writing them with DMA is the only reliable way to access it.

Feb 14, 2012 at 2:15:51 AM
glenn101 (0)
avatar
(Glenn Kirilov) < Tourian Tourist >
Posts: 37 - Joined: 02/11/2012
Victoria
Profile
Ok then, thanks for the quick reply bunnyboy!

Feb 15, 2012 at 4:46:43 AM
glenn101 (0)
avatar
(Glenn Kirilov) < Tourian Tourist >
Posts: 37 - Joined: 02/11/2012
Victoria
Profile
*Edit*
This should only be posted in the week 5 tutorial section, remove this post. I accidently posted here first, wasn't paying attention as to which week I was posting under.

Is this an acceptable way to make sprites move slower than 1 pixel per Vblank:

; Just before JMP Forever I cleared the X register.
ReadA:
LDA $4016 ; player 1 - A
AND #%00000001 ; only look at bit 0
BEQ ReadADone ; branch to ReadADone if button is NOT pressed (0)
; add instructions here to do something when button IS pressed (1)
INX ; if a press is registered for 3 Vblanks then translate the sprite.
CPX #$03
BNE ReadADone
LDX #$00 ; Once it has been moved reset the Vblank counter.
LDA $0203 ; load sprite X position
CLC ; make sure the carry flag is clear
ADC #$01 ; A = A + 3 (changed to 3)
STA $0203 ; save sprite X position (sprite moves 1 unit right).
ReadADone: ; handling this button is done

I've tried it and it works, just wondering if it's the right way to go about it.



Edited: 02/15/2012 at 04:58 AM by glenn101

Feb 18, 2012 at 2:25:06 AM
glenn101 (0)
avatar
(Glenn Kirilov) < Tourian Tourist >
Posts: 37 - Joined: 02/11/2012
Victoria
Profile
Hmm, I can get mario to move as a whole, but I get an additional sprite moving along at the top of the screen, it appears to be a duplicate of the first sprite. Any idea why this would happen? Here is my code to shift mario across:


     LDX $00
ReadA:
     LDA $4016 ; player 1 - A
     AND #%00000001 ; only look at bit 0
     BEQ ReadADone ; branch to ReadADone if button is NOT pressed (0)
; add instructions here to do something when button IS pressed (1)
SpriteUpdateA
     LDA $0203,x ; load sprite X position with offset
     CLC ; make sure the carry flag is clear
     ADC #$01 ; A = A + 1
     STA $0203,x ; save sprite X position (sprite moves 1 unit right).
     INX
     INX
     INX
     INX
     CPX $10 ; When x=16 done all sprites.
     BNE SpriteUpdateA
ReadADone: ; handling this button is done

I do the exact same for moving left but I subtract of course But the algorithm is the same.

*Edit*
I fixed it! ah damn syntax, I didn't put a '#" before $! But I'm still curious as to why another mario sprite would appear?


Edited: 02/18/2012 at 02:33 AM by glenn101

Feb 18, 2012 at 11:01:06 PM
muffins (0)
avatar
(I am Error.) < Tourian Tourist >
Posts: 44 - Joined: 01/31/2012
Maine
Profile
It's hard to say but effectively what that code would be doing is loading a number representing each sprite's x-coordinate, adding the value stored at memory address $0001, then storing that value in the sprite's x-coordinate.

-------------------------


Feb 19, 2012 at 3:33:29 AM
glenn101 (0)
avatar
(Glenn Kirilov) < Tourian Tourist >
Posts: 37 - Joined: 02/11/2012
Victoria
Profile
Yeah that's exactly what I thought, it is quite strange how the y-coordinate is effected by comparing the value stored at memory address $10 and not the value #$10. Especially because I am not doing anything with the addresses which hold the y-coordinates. I think it might actually have to do with how I wrote the address (even though that wasn't intended), normally they are written as a 4 digit hex value, I think that's the key, it's incorrect syntax.

Feb 19, 2012 at 3:42:14 AM
KHAN Games (89)
avatar
(Kevin Hanley) < Master Higgins >
Posts: 8124 - Joined: 06/21/2007
Florida
Profile
Can I see your entire code? Paste it at pastebin.com, please.

-------------------------

gauauu: look, we all paid $10K at some point in our lives for the privilege of hanging out with Kevin


Aug 8, 2012 at 7:50:56 PM
SomewhatEvil (16)

< Crack Trooper >
Posts: 151 - Joined: 08/08/2012
Washington
Profile
I was having some issues with the palette, so I tried to run the provided code for this section as a sanity check. Unfortunately I don't think I'm getting the expected results.

When I run sprites.nes in FCEUX I get this:
http://i.imgur.com/R0VYK.png...

Here is the debug PPU viewer:
http://i.imgur.com/hO3ln.png...

Anyone know why the provided code may not be running as expected? It looks to me like some of the color palette isn't loading properly. The patterns table also looks a bit weird, but it may just be that this is the first patterns table I've looked at since I'm following along with the series.

Aug 8, 2012 at 8:16:16 PM
NESHomebrew (21)
avatar
(Brad Bateman - Strange Brew Games) < King Solomon >
Posts: 4264 - Joined: 04/28/2008
Saskatchewan
Profile
Looks like it is running as expected. You need to change your palette entries if you want it the colors YOU want. The colors are from the chart in the first post.