Palettes conflict with simple background.

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
Posts: 31
Joined: Fri Jan 08, 2021 8:36 am

Palettes conflict with simple background.

Post by ludoVIC » Wed Jan 27, 2021 3:15 am

While experimenting with the basic Nerdy Nights tutorials, I stumbled into an issue concerning Palettes and simple full color backgrounds ($2001).
I wrote a short minimal example in the attached code, where the task should be straightforward:

1. start the program: set the background to red
2. load some Palettes (they will be ignored)
3. at each frame, set the background to blue

The operation (2) is done in the section "LoadPalettes".
Now, if I comment that part, the code works as expected, otherwise I just get a constant black screen.
I really don't understand the reason for that, especially because I don't see the connection between $2001 and the palettes.

Any help would be very appreciated.
Thanks in advance!
(16 KiB) Downloaded 16 times
(1010 Bytes) Downloaded 17 times

User avatar
Posts: 1684
Joined: Sun Sep 19, 2004 10:59 pm

Re: Palettes conflict with simple background.

Post by Quietust » Wed Jan 27, 2021 5:30 am

The top bits of $2001 don't actually set the background color; instead, they apply something we've called "color emphasis" which merely tints the entire screen with a particular color.

On the NTSC/PAL PPUs this is done by darkening the other color channels (i.e. red emphasis will reduce the green and blue levels, and setting all 3 would dim the screen by about 25%), while on the RGB (arcade) PPUs this is done by forcing the specified channels to maximum intensity (i.e. red emphasis would turn black to red and turn green to yellow, and setting all 3 would turn the entire screen white).
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.

User avatar
Posts: 11991
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Palettes conflict with simple background.

Post by tokumaru » Wed Jan 27, 2021 7:54 am

Since you don't have any graphics in yet, the only color you're gonna see is color 0, the background color (unless you point the VRAM address at specific palette entries, in which case the PPU will render that instead of the background color - this is a little quirk of the NES). This is the color you write to PPU address $3F00.

Looking at your code, you'd think that'd be color $31, seeing as that's the first color in your palette, but the NES palette has some weird mirroring going on: there's no physical memory for the first color of each sprite palette ($3F10, $3F14, $3F18 and $3F1C), they're actually mirrors of the corresponding colors in the background palettes ($3F00, $3F04, $3F08 and $3F0C). This means that you're overwriting the $31 with the $0F you have in the first sprite palette, and $0F is black.

Since the color emphasis bits in $2001 work by darkening specific color components, like Quietust said, they don't have any noticeable effect on black, which is already completely dark.

Posts: 31
Joined: Fri Jan 08, 2021 8:36 am

Re: Palettes conflict with simple background.

Post by ludoVIC » Thu Jan 28, 2021 9:36 am

Fantastic. I tried modifying the code by loading another background palette, and it works.
I set a light blue palette, then wrote $%00100000 to $2001 (intensify red) and got a sort of violet background.

My misunderstood came from the NN tutorials, but now that I look better, he actually says "intensify" and not "set".
Therefore, my mistake.
And of course, thank you very much for the kind and complete explanation!

Post Reply