struggling with understanding pallets

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
User avatar
Kitty_Space_Program
Posts: 29
Joined: Mon Sep 21, 2020 7:42 am

struggling with understanding pallets

Post by Kitty_Space_Program » Mon Oct 05, 2020 7:31 am

I'm trying to set certain sprites to be certain colors by editing the palette data, so to try and figure out which pallets were being sent where i went through and edited every single number in pallets data one at a time to a random number, and the only color that changed was the background. then I copied and pasted in a color palette I found online and again it only changed the background
here's my pallets data if that helps:
(there are indentions, nesdev forum just doesn't include them for some reason)

pallete:
.db $30,$30,$30,$30
.db $30,$30,$30,$30
.db $30,$30,$30,$30
.db $30,$30,$30,$30 ;background palette data

.db $13,$3f,$03,$0F
.db $30,$17,$34,$0F
.db $1C,$15,$14,$0F
.db $02,$38,$3C,$10 ;sprite palette data

In my sprites, 11 as the last two bits make the sprite black and white and 10 makes it green and purple if that helps with anything

User avatar
za909
Posts: 216
Joined: Fri Jan 24, 2014 9:05 am
Location: Hungary

Re: struggling with understanding pallets

Post by za909 » Mon Oct 05, 2020 8:29 am

For the background palettes, the first entry (at PPU addresses $3F00, $3F04, $3F08, $3F0C) in each palette actually refers to the so-called backdrop color, which is shared by the background palettes. This is not what's causing your weird colors, but it is something to remember in the future. This matters when you set a sprite to be hidden behind the background. It will technically be displayed "in front of" the backdrop pixels, but behind the other colors in the palette.

For the sprite palettes, the first entry (at PPU addresses $3F10, $3F14, $3F18, $3F1C) in each palette are mirrors of the above mentioned backdrop color, so your sprite palettes are overwriting this right now. You can either not upload anything to the first color of the sprite palettes, or make sure that you write the same value as for the first color in your background palettes ($30 in this case). The first sprite color is of no real consequence, because sprites can only use transparency + three colors.

User avatar
nesrocks
Posts: 474
Joined: Thu Aug 13, 2015 4:40 pm
Location: Rio de Janeiro - Brazil
Contact:

Re: struggling with understanding pallets

Post by nesrocks » Mon Oct 05, 2020 9:39 am

Are you increasing the address as you write? Sound like you're writing all bytes to the same byte address.
https://twitter.com/bitinkstudios <- Follow me on twitter! Thanks!

User avatar
Kitty_Space_Program
Posts: 29
Joined: Mon Sep 21, 2020 7:42 am

Re: struggling with understanding pallets

Post by Kitty_Space_Program » Mon Oct 05, 2020 9:59 am

nesrocks wrote:
Mon Oct 05, 2020 9:39 am
Are you increasing the address as you write? Sound like you're writing all bytes to the same byte address.
yeah, I believe I am.
this is the code I'm using to do that.
loadpallete:
lda pallete, x
sta $2007
inx
cpx #$0F
bne loadpallete
za909 wrote:
Mon Oct 05, 2020 8:29 am
For the background palettes, the first entry (at PPU addresses $3F00, $3F04, $3F08, $3F0C) in each palette actually refers to the so-called backdrop color, which is shared by the background palettes. This is not what's causing your weird colors, but it is something to remember in the future. This matters when you set a sprite to be hidden behind the background. It will technically be displayed "in front of" the backdrop pixels, but behind the other colors in the palette.

For the sprite palettes, the first entry (at PPU addresses $3F10, $3F14, $3F18, $3F1C) in each palette are mirrors of the above mentioned backdrop color, so your sprite palettes are overwriting this right now. You can either not upload anything to the first color of the sprite palettes, or make sure that you write the same value as for the first color in your background palettes ($30 in this case). The first sprite color is of no real consequence, because sprites can only use transparency + three colors.

ok thank you. Is there an objective never changing value for every color? On the wiki there seems to be many different values for colors here: https://wiki.nesdev.com/w/index.php/PPU_palettes

User avatar
Quietust
Posts: 1633
Joined: Sun Sep 19, 2004 10:59 pm
Contact:

Re: struggling with understanding pallets

Post by Quietust » Mon Oct 05, 2020 10:31 am

Kitty_Space_Program wrote:
Mon Oct 05, 2020 9:59 am
this is the code I'm using to do that.
loadpallete:
lda pallete, x
sta $2007
inx
cpx #$0F
bne loadpallete
I see 2 problems in that code, both in the same place: it's only writing 15 bytes of data. If you want to just update half of the palette (i.e. sprites or background), then you need to do cpx #$10, and if you want to update the entire palette, then you need to do cpx #$20.

Also, if the last value you wrote to $2000 had bit 0x04 set, then each write would increment the address by 32 (instead of 1), causing it to repeatedly update the first entry.
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.

User avatar
Kitty_Space_Program
Posts: 29
Joined: Mon Sep 21, 2020 7:42 am

Re: struggling with understanding pallets

Post by Kitty_Space_Program » Tue Oct 06, 2020 6:49 am

Quietust wrote:
Mon Oct 05, 2020 10:31 am
I see 2 problems in that code, both in the same place: it's only writing 15 bytes of data. If you want to just update half of the palette (i.e. sprites or background), then you need to do cpx #$10, and if you want to update the entire palette, then you need to do cpx #$20.

Also, if the last value you wrote to $2000 had bit 0x04 set, then each write would increment the address by 32 (instead of 1), causing it to repeatedly update the first entry.
cool thank you! it seems to have worked

Post Reply