Sega Mega Drive/Palettes and CRAM

From Sega Retro

512 available colours.

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

Normally a game would transfer new data to the CRAM between two frames, during the VBlank period, and any in-game changes to the palette are buffered in RAM before the transfer. The contents of CRAM can also be changed mid-frame, in order to display a new set of colours on the lower part of the screen. One example of this is in water-based levels of Sonic the Hedgehog games, where a new palette is loaded partway down the screen to show the change between over- and underwater areas. To modify the CRAM at a specific scanline, new data is loaded during a horizontal interrupt.

CRAM dots

A drawback of CRAM mid-frame changes is that data sent to the CRAM interferes with the screen drawing process, which results in rogue pixels appearing on the screen for every word sent to the CRAM. This bug is known as "CRAM dots".

Each dot is a single pixel with the same colour value as the word being written to CRAM, which appears at the current position of the electron beam on the screen. While CRAM dots are generally an unwanted visual artifact, it is possible to use them to draw graphics directly to the screen without using sprites or planes.[1] It is also possible to hide CRAM dots in the "overscan" area to the left and right of the screen, which is hidden by most TVs (Sonic the Hedgehog 3 does this).

CRAM dots can also appear even when palettes are written between frames during VBlank, in the top and bottom overscan areas. These areas are usually hidden.

Background colour

The background colour is a single colour selected from the palette which is displayed as the screen border, and also where there are no opaque pixels displayed from any plane or sprite. The background colour is controlled by VDP register $07. By choosing a transparent colour as the background colour, the number of visible colours can be extended from 60 to 61.

Below is an example of Sonic the Hedgehog using a transparent colour (dark blue) for the borders and in the background water.

Sonic1 title with borders.png

Low color mode

In Mega Drive mode, if the M4 (Master System) bit in VDP register $00 is cleared, color RAM entries will be interpreted differently.

In this "low color mode", only three bits of a palette entry are used in the following way:

15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0

0
0
0
0
0
0
B
0
0
0
G
0
0
0
R
0

As such, all palettes appear quite dark and there are only 8 possible colours to choose from. Below is an example of Sonic the Hedgehog using low color mode (taken in Gens/GS, unconfirmed on real hardware).

Sonic1 title low colour.png

Note that this is most likely a bug, since on Master System, the M4 bit controls whether or not SMS or TMS video modes are used. On Mega Drive, TMS video modes don't function, so the colors are to 0, but it seems they only handled two bits per color, not all three.

References