Sega Mega Drive/Palettes and CRAM

From Sega Retro

The Sega Mega Drive stores four palettes of 16 colours, totalling 64 ($40) colours, in 128 ($80) bytes of CRAM. The CRAM is a separate area of memory on the VDP from VRAM. Each colour consists of two bytes which contain 9-bit RBG values. This gives the Mega Drive a total of 512 colours to choose from for its 64 colour palette.

In practice only 61 colours are visible because four are used for transparency, although one of those is visible as the background colour. It is possible to display more than 61 colours by changing the CRAM mid-frame, or by using shadow and highlight mode.

Format

7
6
5
4
3
2
1
0

0
0
0
0
B
0
7
6
5
4
3
2
1
0

G
0
R
0
  • B, G, R: 3-bit values each for blue, green and red.

A simpler way of expressing this is as a word value with the format $0BGR. The 2nd, 3rd and 4th nybbles contain the brightness levels for blue, green and red respectively. Possible values are 0, 2, 4, 6, 8, $A, $C and $E.

3-bit value Nybble value Brightness (0-255)
000 0 0 ($00)
001 2 52 ($34)
010 4 87 ($57)
011 6 116 ($74)
100 8 144 ($90)
101 A 172 ($AC)
110 C 206 ($CE)
111 E 255 ($FF)

CRAM mid-frame changes