This is a sidebar page

It provides more detailed information but you don't need to read it to follow the tutorial. You might want to come back to it later.

Palette

The palette defines which colours we can use. There are actually two palettes - one for the background, and one for the sprites. (The sprite palette can be used by the background too.) Each palette contains 16 entries. Here's the palette window in Meka:

The first sixteen colours are the background palette, the second sixteen are the sprite palette.

Each pixel of each tile is represented by four bits, giving a number between 0 and 15. This number is used to select which colour to use. It's a lot like "Paint By Number":

Each palette entry is one of the 64 possible colours on the Master System:

To pick a colour, you must choose a number between 0 and 3 for each of the red, green and blue colour channels. Then combine them in a byte:

Bit: 7 6 5 4 3 2 1 0
% Unused Blue Green Red

So, for example, if there was a little blue, no green and a lot of red, the colour would be %00010011. Here are all of the colours:

Colour SMS colour index RGB HTML
Hex Dec Binary Red Green Blue
$00 0 %00000000 0 0 0 #000000
$01 1 %00000001 85 0 0 #550000
$02 2 %00000010 170 0 0 #aa0000
$03 3 %00000011 255 0 0 #ff0000
$04 4 %00000100 0 85 0 #005500
$05 5 %00000101 85 85 0 #555500
$06 6 %00000110 170 85 0 #aa5500
$07 7 %00000111 255 85 0 #ff5500
$08 8 %00001000 0 170 0 #00aa00
$09 9 %00001001 85 170 0 #55aa00
$0a 10 %00001010 170 170 0 #aaaa00
$0b 11 %00001011 255 170 0 #ffaa00
$0c 12 %00001100 0 255 0 #00ff00
$0d 13 %00001101 85 255 0 #55ff00
$0e 14 %00001110 170 255 0 #aaff00
$0f 15 %00001111 255 255 0 #ffff00
$10 16 %00010000 0 0 85 #000055
$11 17 %00010001 85 0 85 #550055
$12 18 %00010010 170 0 85 #aa0055
$13 19 %00010011 255 0 85 #ff0055
$14 20 %00010100 0 85 85 #005555
$15 21 %00010101 85 85 85 #555555
$16 22 %00010110 170 85 85 #aa5555
$17 23 %00010111 255 85 85 #ff5555
$18 24 %00011000 0 170 85 #00aa55
$19 25 %00011001 85 170 85 #55aa55
$1a 26 %00011010 170 170 85 #aaaa55
$1b 27 %00011011 255 170 85 #ffaa55
$1c 28 %00011100 0 255 85 #00ff55
$1d 29 %00011101 85 255 85 #55ff55
$1e 30 %00011110 170 255 85 #aaff55
$1f 31 %00011111 255 255 85 #ffff55
$20 32 %00100000 0 0 170 #0000aa
$21 33 %00100001 85 0 170 #5500aa
$22 34 %00100010 170 0 170 #aa00aa
$23 35 %00100011 255 0 170 #ff00aa
$24 36 %00100100 0 85 170 #0055aa
$25 37 %00100101 85 85 170 #5555aa
$26 38 %00100110 170 85 170 #aa55aa
$27 39 %00100111 255 85 170 #ff55aa
$28 40 %00101000 0 170 170 #00aaaa
$29 41 %00101001 85 170 170 #55aaaa
$2a 42 %00101010 170 170 170 #aaaaaa
$2b 43 %00101011 255 170 170 #ffaaaa
$2c 44 %00101100 0 255 170 #00ffaa
$2d 45 %00101101 85 255 170 #55ffaa
$2e 46 %00101110 170 255 170 #aaffaa
$2f 47 %00101111 255 255 170 #ffffaa
$30 48 %00110000 0 0 255 #0000ff
$31 49 %00110001 85 0 255 #5500ff
$32 50 %00110010 170 0 255 #aa00ff
$33 51 %00110011 255 0 255 #ff00ff
$34 52 %00110100 0 85 255 #0055ff
$35 53 %00110101 85 85 255 #5555ff
$36 54 %00110110 170 85 255 #aa55ff
$37 55 %00110111 255 85 255 #ff55ff
$38 56 %00111000 0 170 255 #00aaff
$39 57 %00111001 85 170 255 #55aaff
$3a 58 %00111010 170 170 255 #aaaaff
$3b 59 %00111011 255 170 255 #ffaaff
$3c 60 %00111100 0 255 255 #00ffff
$3d 61 %00111101 85 255 255 #55ffff
$3e 62 %00111110 170 255 255 #aaffff
$3f 63 %00111111 255 255 255 #ffffff

So there are 64 possible colours on the Master System, but you have to select 16 of them (for each palette) - you can't use more without using special tricks.

Writing to the palette

To write to the palette, set the address using the VDP control port, with the two high bits set (i.e. address ORed with $c000). If you set an address higher than 32, the address wraps.

Transparency

Palette index 0 is special. For sprites, it is always transparent - the colour you choose is never used (for sprites, it can be used for other things). For background tiles, it is drawn but when the tile is set to be drawn in front of sprites (see Tilemap), it is drawn behind sprites while the other palette entries are drawn in front, so it again has a sort of transparency.

Game Gear differences

The Game Gear palette is exactly the same as the Master System, except:

  • Each colour channel has four bits, not two, giving 212 = 4096 possible colours.
  • Each palette entry then takes up two bytes
    • So there are 64 bytes of colour RAM instead of 32
    • Each entry takes up two consecutive bytes, in the format:
Byte: 1 0
Bit: 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
% Unused Blue Green Red

< Setting up the graphics | Lesson 1 | Tiles >