Changing DAC palette in text mode

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
Athenos
Posts: 3
Joined: Tue Jan 20, 2009 11:14 pm

Changing DAC palette in text mode

Post by Athenos »

Hi!

I have begun the process of building my own hobby OS. I seem to have hit an annoying problem however, I cannot change several of the DAC palette colours - in particular 6 and 8-15.

I have tried accomplishing this in C with my own code, then in C with code I found in a web based tutorial .... and even in assembler

Code: Select all

mov al,0                     ;Colour to change
mov dx, 0x03C8          
out dx, al                    ;Tell DAC which colour to write to
mov al, 63                  
inc dx
out dx, al                    ;Set to white
out dx, al
out dx, al
(Not particuarly well written but I wrote it really quickly to test this wasnt a problem with my C code).

My OS uses Grub as its bootloader, and I am attempting to simulate this in qemu.
Any help with what could possibly be causing this would be greatly appreciated.
User avatar
gzaloprgm
Member
Member
Posts: 141
Joined: Sun Sep 23, 2007 4:53 pm
Location: Buenos Aires, Argentina
Contact:

Re: Changing DAC palette in text mode

Post by gzaloprgm »

I used

Code: Select all

void VgaSetColor(unsigned char color, unsigned char red, unsigned char green, unsigned char blue){
	outportb(0x3C8, color);
	outportb(0x3C9, red);
	outportb(0x3C9, green);
	outportb(0x3C9, blue);
}
and it worked ok. Try adding -std-vga at the end of qemu arguments.

Cheers,
Gonzalo
Visit https://gzalo.com : my web site with electronic circuits, articles, schematics, pcb, calculators, and other things related to electronics.
Athenos
Posts: 3
Joined: Tue Jan 20, 2009 11:14 pm

Re: Changing DAC palette in text mode

Post by Athenos »

Unfortunately adding that tag to qemu has made no difference. I have also tried the emulator in bochs, but I keep getting this same problem :(.

I have disabled every piece of code in my kernel, except for the graphics init function (which I have also disabled most of the extra stuff from)

Here is a cutdown version of scrn_init and scrn_dac_w

Code: Select all

 void scrn_init(void)
{
    //Assign video memory loc
    textmemptr = (unsigned short *)0xB8000; 
    //Write black (or at least almost black) to every colour
    unsigned char i =0;
    for (i=0;i<16;i++)
    {
    	Write_DAC_C_Palette(i,2,2,2);
    }
    //Write every text to screen in every colour
    for (i=0;i<16;i++)
    {
	settextcolor(i,0x00);
	printf("Colour: %d\n\0", i);
    }
}

//Writes a colour to the DAC
//In: uchar colour - the index of the colour to write
//     uchar r - red value (0-63)
//     uchar g - green value (0-63)
//     uchar b - blue value (0-63)
void scrn_dac_w(uchar colour, uchar r, uchar g,uchar b)
{
  outportb(0x03C8,colour);          //1st color to input!
  outportb(0x03C9,r);
  outportb(0x03C9,g);
  outportb(0x03C9,b);
}
Which gives the image below - I was trying to set every Colour to black (I have tried other colours too)

Image
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Changing DAC palette in text mode

Post by jal »

Note that when changing one of the 16-colours of the VGA, you have a two-step process: the VGA first maps indexes 0-15 to one of the 265 palette registers, and then uses one of the 265 RGB values to display the actual colour. You problem simply means that index 0-15 of the palette registers are not mapped to attributes 0-15 of the 16-colour mode. Remember that on the EGA, you had a similar thing with mapping attributes 0-15 to one of the 64 EGA colours.

Please check the VGA documentation that can be abundantly found everywhere for further details (sorry, I'm in a hurry right now).


JAL
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Changing DAC palette in text mode

Post by Combuster »

IMO Michael Abrash is better at explaining that stuff than some creepy VGA doc:
http://www.byte.com/abrash/chapters/gpbb33.pdf

(and IMO, vgadoc is better at enumerating registers than pointing out the usefulness)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Athenos
Posts: 3
Joined: Tue Jan 20, 2009 11:14 pm

Re: Changing DAC palette in text mode

Post by Athenos »

Thanks heaps for your help :),

I've been able to modify the code now so that it maps all of the text mode registers to ones I want to use.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Changing DAC palette in text mode

Post by jal »

Combuster wrote:IMO Michael Abrash is better at explaining that stuff than some creepy VGA doc:
http://www.byte.com/abrash/chapters/gpbb33.pdf

(and IMO, vgadoc is better at enumerating registers than pointing out the usefulness)
I didn't mean a specific doc, just general VGA programming info found everywhere. Abrash is good.


JAL
Post Reply