Palettes: Difference between revisions
From SNESdev Wiki
Jump to navigationJump to search
Rainwarrior (talk | contribs) m (→References: maybe no pre-emptive indent) |
Rainwarrior (talk | contribs) m (→CGRAM access: CGDATA is 2122) |
||
(3 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]] ($ | # 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 | * 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 36: | Line 36: | ||
== 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
- Write a byte to CGADD ($2121) to select one of the 256 entries in CGRAM.
- 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
- SNES Development Manual - Book I A-17 CG-RAM