Palettes: Difference between revisions

From SNESdev Wiki
Jump to navigationJump to search
(palettes)
 
m (→‎Assignment: fix links to Tiles)
Line 25: Line 25:
* CGRAM entry 0 is always used as the background color, beneath all the [[background]] layers and [[sprites]], or where all other rendering is disabled or windowed.
* CGRAM entry 0 is always used as the background color, beneath all the [[background]] layers and [[sprites]], or where all other rendering is disabled or windowed.
* [[Tiles#2bpp|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.
* [[Tiles#2bpp|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.
* [[Tile#4bpp|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).
* [[Tiles#4bpp|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).
* [[Tile#8bpp|8bpp]] tiles can use the entire contents of CGRAM, except entry 0 which is always transparent. This also includes [[mode 7]] tiles.
* [[Tiles#8bpp|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.
* [[Direct color]] tiles do not use the CGRAM palette at all, instead specifying an 8-bit color directly with their bits.



Revision as of 22:12, 29 May 2022

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 ($2121) 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 background 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.

See Also