Palettes: Difference between revisions

From SNESdev Wiki
Jump to navigationJump to search
(official reference for CG-RAM)
m (→‎CGRAM access: CGDATA is 2122)
 
(4 intermediate revisions by 2 users not shown)
Line 6: Line 6:


# Write a byte to [[PPU registers#CGADD|CGADD]] ($2121) to select one of the 256 entries in CGRAM.
# Write a byte to [[PPU registers#CGADD|CGADD]] ($2121) to select one of the 256 entries in CGRAM.
# Write two bytes to [[PPU registers#CGDATA|CGDATA]] ($2121) to set the 15-bit RGB color for that entry. (Low byte first.)
# Write two bytes to [[PPU registers#CGDATA|CGDATA]] ($2122) to set the 15-bit RGB color for that entry. (Low byte first.)


     CGDATA ($2122)
     CGDATA ($2122)
Line 15: Line 15:
   ||| ||||  |||+-++++- Red component  
   ||| ||||  |||+-++++- Red component  
   ||| ||++---+++------- Green component
   ||| ||++---+++------- Green component
   +++-++-------------- Blue component
   +++-++--------------- Blue component


After two writes to CGDATA, CGADD will automatically be incremented to the next entry.
After two writes to CGDATA, CGADD will automatically be incremented to the next entry.
Line 23: Line 23:
== Assignment ==
== 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.
* 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.
* [[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.
* [[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).
* [[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).
Line 35: Line 35:


== References ==
== References ==
:* [[SNES Development Manual]] - Book I A-17 CG-RAM
* [[SNES Development Manual]] - Book I A-17 CG-RAM
 
[[Category:Graphics]]

Latest revision as of 07:28, 11 October 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 ($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.

See Also

References