Palettes

The SNES has a palette of 256 colors, stored as 256 15-bit words in CGRAM.

A SNES color entry gives an RGB color with 5-bit precision in each component.

CGRAM access

 * 1) Write a byte to CGADD ($2121) to select one of the 256 entries in CGRAM.
 * 2) Write two bytes to CGDATA ($2122) to set the 15-bit RGB color for that entry. (Low byte first.)

CGDATA ($2122) 15 bit  8   7  bit  0 .BBB BBGG  GGGR RRRR ||| ||||  |||| ||||   ||| ||||   |||+-++++- Red component ||| ||++---+++--- Green component +++-++--- Blue component

After two writes to CGDATA, CGADD will automatically be incremented to the next entry.

Entries can also be read back through CGDATAREAD ($213B). Note that because the high bit is unused, it returns an unreliable value that should be ignored.

Assignment

 * CGRAM entry 0 is always used as the backdrop color, beneath all the background layers and sprites, or where all other rendering is disabled or windowed.
 * 2bpp tiles use groups of 4 from CGRAM. The first of 4 will be unseen, as a tile pixel of 0 is always transparent, but the remaining 3 will be used to color the visible tile.
 * 4bpp tiles use groups of 16. Again the first entry is always transparent and unseen. Backgrounds use the first 8 groups of 16 (0-127) and sprites use the last 8 groups (128-255).
 * 8bpp tiles can use the entire contents of CGRAM, except entry 0 which is always transparent. This also includes mode 7 tiles.
 * Direct color tiles do not use the CGRAM palette at all, instead specifying an 8-bit color directly with their bits.