OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 1:13 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Setting VGA color palette dosn't give the right colors
PostPosted: Thu Jul 28, 2022 9:03 am 
Offline
Member
Member

Joined: Tue Jun 07, 2022 11:23 am
Posts: 78
Location: France
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:
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:
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

_________________
https://github.com/cheyao/Achieve-Core


Top
 Profile  
 
 Post subject: Re: Setting VGA color palette dosn't give the right colors
PostPosted: Thu Jul 28, 2022 10:33 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
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!)


Top
 Profile  
 
 Post subject: Re: Setting VGA color palette dosn't give the right colors
PostPosted: Thu Jul 28, 2022 1:14 pm 
Offline
Member
Member

Joined: Tue Jun 07, 2022 11:23 am
Posts: 78
Location: France
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 :(

_________________
https://github.com/cheyao/Achieve-Core


Top
 Profile  
 
 Post subject: Re: Setting VGA color palette dosn't give the right colors
PostPosted: Thu Jul 28, 2022 1:43 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
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:
    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.


Top
 Profile  
 
 Post subject: Re: Setting VGA color palette dosn't give the right colors
PostPosted: Fri Jul 29, 2022 1:10 am 
Offline
Member
Member

Joined: Tue Jun 07, 2022 11:23 am
Posts: 78
Location: France
Ok!! Thanks for your reply!

_________________
https://github.com/cheyao/Achieve-Core


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 58 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group