Question

I am learning old DOS programming, specifically controlling VGA directly. I am also doing this to relearn and get better at C.

Anyway I have written a small program that loads a PCX file and displays it. The one I am using is of a cacodemon from DooM, with the original DooM palette. The pixel data seems to be correct, as well as the RGB values for the palette (I did a printf of all 256 rgb triplets and they matched the editor I am using). However when I display the palette, there is obvious differences and the image's color is distorted.

Original image and palette:

http://i.imgur.com/7lM5R.png

My output (the numbers are palette values, and are correct):

http://i.imgur.com/MJTUE.png

Here is the palette load code

void setPalette(unsigned char * newPalette)
{
    int x, y = 0;
    //SET PALETTE MEMORY
    for (x = 0; x <= 255; x++)
    {
        outp(PALETTE_MASK, 0xFF); //Can access whole palette
        outp(PALETTE_REGISTER_WR, x); //Set index
        outp(PALETTE_DATA,newPalette[y]); //Write R value
        outp(PALETTE_DATA,newPalette[y+1]); //Write G value
        outp(PALETTE_DATA,newPalette[y+2]); //Write B value

        printf("%d, %d, %d\n", newPalette[y], newPalette[y+1], newPalette[y+2]);

        y += 3;


        //getch();
   }
}
Was it helpful?

Solution

I figured it out. Because VGA stores only 64 levels of R,G, & B, you need to shift each value twice right.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top