Setting VGA color palette dosn't give the right colors

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Cyao
Member
Member
Posts: 78
Joined: Tue Jun 07, 2022 11:23 am
Libera.chat IRC: Cyao
Location: France
Contact:

Setting VGA color palette dosn't give the right colors

Post by Cyao »

I was trying to make some art on the 0x13 screen, and set up some basic colors, but the colors wasn't the right one that I wanted, Is this some qemu bug or me doing it wrong?

I set up the color using this:

Code: Select all

void init_screen() {
    outb(PALETTE_MASK, 0xFF);
    outb(PALETTE_WRITE, 0);

    outb(PALETTE_DATA, 0xFF);
    outb(PALETTE_DATA, 0xFF);
    outb(PALETTE_DATA, 0xFF);

    outb(PALETTE_DATA, 0x00);
    outb(PALETTE_DATA, 0x00);
    outb(PALETTE_DATA, 0x00);

    outb(PALETTE_DATA, 0xB3);
    outb(PALETTE_DATA, 0x32);
    outb(PALETTE_DATA, 0x27);
}
Draw function:

Code: Select all

void draw_mario(bool left) {
    char * address = (char *) (VIDEO_ADDRESS + item.x + item.y * SC_WIDTH); // This isn't wrong
    memset(address + 3, RED, 5); // RED = 2
    UNUSED(left);
}
Output:
Image
Wanted color:
Image
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Setting VGA color palette dosn't give the right colors

Post by Octocontrabass »

The VGA RAMDAC supports only 6 bits per channel; it ignores the upper two bits. You're writing #B33227 but the RAMDAC interprets that value as (approximately) #CFCB9E.

Some RAMDACs can be switched to 8 bits per channel, but it's not part of standard VGA so the method to switch will depend on the display adapter. (On really old SVGA cards, it also depends on which RAMDAC chip is installed in the RAMDAC socket. Yes, you could swap your RAMDAC to get an upgrade!)
Cyao
Member
Member
Posts: 78
Joined: Tue Jun 07, 2022 11:23 am
Libera.chat IRC: Cyao
Location: France
Contact:

Re: Setting VGA color palette dosn't give the right colors

Post by Cyao »

Octocontrabass wrote:The VGA RAMDAC supports only 6 bits per channel; it ignores the upper two bits. You're writing #B33227 but the RAMDAC interprets that value as (approximately) #CFCB9E.

Some RAMDACs can be switched to 8 bits per channel, but it's not part of standard VGA so the method to switch will depend on the display adapter. (On really old SVGA cards, it also depends on which RAMDAC chip is installed in the RAMDAC socket. Yes, you could swap your RAMDAC to get an upgrade!)
Is there some good way to make the screen 8 bit with the standard stuff? Maybe is there something other then the VGA? I would like to have more colors :(
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Setting VGA color palette dosn't give the right colors

Post by Octocontrabass »

The screen is still 8 bits per pixel. You can still show 256 colors simultaneously. The only limitation is that there are only 6 bits per channel, so you need to use numbers that fit in 6 bits when you set the palette in the RAMDAC. Like this:

Code: Select all

    outb(PALETTE_DATA, 0xB3 >> 2);
    outb(PALETTE_DATA, 0x32 >> 2);
    outb(PALETTE_DATA, 0x27 >> 2);
There is a VBE function to set the RAMDAC to 8 bits per channel, but I don't know if it's commonly supported. If you're using VBE anyway, you might as well use it to set up a 32bpp linear framebuffer and forget about palettes.
Cyao
Member
Member
Posts: 78
Joined: Tue Jun 07, 2022 11:23 am
Libera.chat IRC: Cyao
Location: France
Contact:

Re: Setting VGA color palette dosn't give the right colors

Post by Cyao »

Ok!! Thanks for your reply!
Post Reply