delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/23/15:45:29

From: hackeroc3 AT aol DOT com (HackerOC3)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Palette Register
Date: 23 Jan 1998 20:34:23 GMT
Lines: 111
Message-ID: <19980123203401.PAA03724@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
Organization: AOL http://www.aol.com
References: <6a3o3i$1lc AT alpha DOT delta DOT edu>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp


>Could someone help me out and make a simple example program using these the
>functions Get_Palette_Register and Set_Palette_Register.  It'll help me out
>alot. Thanks in advance.

Do this:

void Set_Palette_Register(int index, RGB_color_ptr color)
{

    /* Tell the VGA card we're going to update a palette register. */

    outportb(PALETTE_MASK,0xff);

    /* Tell the VGA card which register we'll be updating. */

    outportb(PALETTE_REGISTER_WR, index);

    /* Now update the RGB triple.  Note: the same port is used each time. */

    outportb(PALETTE_DATA,color->red);
    outportb(PALETTE_DATA,color->green);
    outportb(PALETTE_DATA,color->blue);

    return;
}

/* This function gets the data out of a color look-up register and places
 * the data into color
 */
void Get_Palette_Register(int index, RGB_color_ptr color)
{

    /* Set the palette mask register. */

    outportb(PALETTE_MASK,0xff);

    /* Tell the VGA card which register we'll be reading. */

    outportb(PALETTE_REGISTER_RD, index);

    /* Now extract the data. */

    color->red     = inportb(PALETTE_DATA);
    color->green   = inportb(PALETTE_DATA);
    color->blue    = inportb(PALETTE_DATA);

    return;
}

Defines:

#define PALETTE_MASK            0x3C6
#define PALETTE_REGISTER_RD     0x3C7
#define PALETTE_REGISTER_WR     0x3C8
#define PALETTE_DATA            0x3C9

typedef struct RGB_color_typ
{
    unsigned char red;        //useful for palette
    unsigned char green;
    unsigned char blue;
} RGB_color, *RGB_color_ptr;


And this function uses the above functions:

void Create_Cool_Palette(void)
{
    RGB_color color;
    int index;

    for (index=0; index < 64; index++)
    {
	/* These are the grays: */
	color.red = index;
	color.green = index;
	color.blue = index;
	Set_Palette_Register(index, (RGB_color_ptr)&color);

	/* These are the reds: */
	color.red = index;
	color.green = 0;
	color.blue = 0;
	Set_Palette_Register(index + 64, (RGB_color_ptr)&color);

	/* These are the greens: */
	color.red = 0;
	color.green = index;
	color.blue = 0;
	Set_Palette_Register(index+128, (RGB_color_ptr)&color);

	/* These are the blues: */
	color.red = 0;
	color.green = 0;
	color.blue = index;
	Set_Palette_Register(index+192, (RGB_color_ptr)&color);
    }
    /* make color 0 black */

    color.red = 0;
    color.green = 0;
    color.blue = 0;
    Set_Palette_Register(0, (RGB_color_ptr)&color);

    return;
}



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019