Page 1 of 1
Changing DAC palette in text mode
Posted: Tue Jan 20, 2009 11:30 pm
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.
Re: Changing DAC palette in text mode
Posted: Wed Jan 21, 2009 1:21 am
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
Re: Changing DAC palette in text mode
Posted: Wed Jan 21, 2009 3:33 am
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)
Re: Changing DAC palette in text mode
Posted: Wed Jan 21, 2009 4:23 am
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
Re: Changing DAC palette in text mode
Posted: Wed Jan 21, 2009 5:35 am
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)
Re: Changing DAC palette in text mode
Posted: Wed Jan 21, 2009 5:48 am
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.
Re: Changing DAC palette in text mode
Posted: Wed Jan 21, 2009 9:52 am
by jal
I didn't mean a specific doc, just general VGA programming info found everywhere. Abrash is good.
JAL