The palette is used in 8-bit color depth (as used in mode13 for instance).
The palette is a buffer that contains definitions for 256 colors
(color = Red, Green, Blue).
The video buffer contains a Color Index for each pixel on the screen.
The color that would be displayed on the monitor is color number
'Color Index' from the palette.
That means that if a pixel's color index is 74, and color no. 74 in the
palette is RGB(63, 0, 0) (=Red) then that pixel will be red.
Each value in the palette (Red, Green or blue) should
be in the range of 0-63.
That means you have 64^3 = 262144 possible colors to display
(but remember - only 256 colors in the same time).
Playing with the palette you can make some cool effects
such as 'Fade In'/'Fade Out'.
You can set or retrieve each color from the palette pretty easily.
To set a color in the palette do:
void setpal(unsigned char col,
unsigned char r,
unsigned char g,
unsigned char b)
// We send to port 0x3C8 the index of the color in the
// palette we want to change
outportb(0x3C9, r); // Send Red Value to port 0x3C9
outportb(0x3C9, g); // Send Green Value to port 0x3C9
outportb(0x3C9, b); // Send Blue Value to port 0x3C9
// The retrieve a color from the palette do:
void getpal(unsigned char col,
unsigned char *red,
unsigned char *green,
unsigned char *blue)
// Send to port 0x3C7 the index of the color in the
// palette we want to retrieve
*red = inportb(0x3C9); // Retrieve Red Value from port 0x3C9
*green = inportb(0x3C9); // Retrieve Green Value from port 0x3C9
*blue = inportb(0x3C9); // Retrieve Blue Value from port 0x3C9
Note: Palette may be found in other modes that use 8 bits per pixel
DJGPP - palette.c
Turbo C - palette.cpp