NES palette

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

Post Reply
Muhammad_R4
Posts: 66
Joined: Sat Jun 25, 2016 5:33 am

NES palette

Post by Muhammad_R4 »

Hello NES developers :D

I have a question related to NES palette colours

https://www.google.com.eg/search?hl=ar& ... i6nFo8M%3A

I know that each colour is of 6 bits ( 2 bits -> red , 2 bits -> green and 2 bits-> blue)

I want to write a software concerning the pattern tables, attributes ...etc , my question is how the 24 bits of the color codes (the rgb we use ) are mapped to only 6 bits ?

I mean if I have the 6 bits of the NES colours , how to know their 24 bit-equivalent colour ? what operations to do ?

Thank's in advance
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: NES palette

Post by rainwarrior »

Muhammad_R4 wrote:I know that each colour is of 6 bits ( 2 bits -> red , 2 bits -> green and 2 bits-> blue)
The NES colours are not made of RGB components. It's more like 2 bits for intensity, and 4 bits for hue.
Muhammad_R4 wrote:I mean if I have the 6 bits of the NES colours , how to know their 24 bit-equivalent colour ? what operations to do ?
Most emulators just use a palette table to map the NES colours to RGB colours for the output system.

Here's an example generator to make that kind of palette: http://bisqwit.iki.fi/utils/nespalette.php

More accurate emulation will try to simulate the effects of NTSC signal generation, which are a lot more complicated than just mapping to a single RGB colour.

Example: http://slack.net/~ant/libs/ntsc.html
Muhammad_R4
Posts: 66
Joined: Sat Jun 25, 2016 5:33 am

Re: NES palette

Post by Muhammad_R4 »

Most emulators just use a palette table to map the NES colours to RGB colours for the output system.
that's good, now how they map the 2 and the 4 bits to an RGB 24 bit color code ?
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: NES palette

Post by Dwedit »

They don't map to RGB color codes at all.
They generate a square wave of NTSC signal that goes up and down between a high and low voltage level, and the phase of the wave determines the hue.
There's an article for this on the Nesdev Wiki, which has more information than you ever wanted to know about how NTSC TVs work.

A couple of random illustrations from the wiki:

Code: Select all

 1.0               +--+
 0.9               |  |
 0.8               |  |
 0.7            +--+  | +-+ +-+
 0.6            |     | | | | |
 0.5            |     | | | | |
 0.4         +--+     | | | | |
 0.3      +--+        | | | | |
 0.2      |           | | | | |
 0.1      |           | | | | |
 0.0 . +--+ . . . . . +-+ +-+ + . .
-0.1 --+
     0D 0F 2D 00 10 30   11
Image

So if you want to do all the complicated calculations of converting to the YIQ color space, then to YUV, then finally getting RGB out of that, that's fine. Or you could build of someone else's work. Nintendulator has a very nice NES palette.
If you want to generate NTSC composite video directly, you can make the same square wave patterns that the NES does.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: NES palette

Post by tokumaru »

Muhammad_R4 wrote:I know that each colour is of 6 bits ( 2 bits -> red , 2 bits -> green and 2 bits-> blue)
That's actually the Master System palette.

The NES palette is notoriously hard to convert to RGB, because there are a lot of steps in between, and the final result never pleases everyone, because each person had a different TV that rendered the colors differently, so they have different memories of what the NES palette looks like.

Other consoles also suffered from all the processing that happened to the colors until they reached people's eyes, but since many of them used RGB internally, it's hard to argue with that...
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: NES palette

Post by tepples »

I took the liberty of running Bisqwit's tool to make something that looks fairly realistic.

Image
Default parameters were used, except saturation at 1.2 and gamma at 2.0


The RGB PPUs (2C03, 2C04, and 2C05) have three 3-bit DACs and an internal lookup table from 6-bit palette values to 3-bit-per-channel RGB. These are also ripped, and they can be used without modification if you want a Genesis game's palette to match that of a PlayChoice, Famicom Titler, or the "garish" mode of the NESRGB.
Post Reply