Page 1 of 1

256-colours on Pmode using a VGA driver?

Posted: Sat Feb 16, 2008 3:33 pm
by t6q4
Hello,
I was wondering that since in real mode you can use

Code: Select all

mov ax, 0x0013
int 0x10
in real mode to go to 256-colour mode, how can you do this in Pmode? And also, I have just stumbled onto this, so could someone help explain the 256-colour pallete, please.

Thanks.

Posted: Sat Feb 16, 2008 4:16 pm
by Masterkiller
In Pmode you must use VGA registers to do that.
You can read more about it here: http://www.osdever.net/FreeVGA/vga/vga.htm#register

Posted: Mon Feb 18, 2008 3:54 am
by jal
Masterkiller wrote:In Pmode you must use VGA registers to do that.
You can read more about it here: http://www.osdever.net/FreeVGA/vga/vga.htm#register
Note, however, that this is not trivial, as you'll have to set all registers by yourself. Possible, but tricky, and not guaranteed to work on all cards.


JAL

Re: 256-colours on Pmode using a VGA driver?

Posted: Mon Feb 18, 2008 4:00 am
by jal
t6q4 wrote:And also, I have just stumbled onto this, so could someone help explain the 256-colour pallete, please.
In 256 colour mode, each byte in video memory refers to one pixel. A byte can have a value of 0-255, so there's a maximum of 256 different colours on the screen (without trickery). A value of 0-255 doesn't directly specify a colour. Instead, it refers to a programmable table inside the VGA hardware that has 256 entries (for each of the values 0-255), and for each entry a Red, Green and Blue value specifying the colour. On the VGA, the RGB values are 6-bit, which means that each R, G and B component is specified as a value between 0 and 63 (0 meaning least intensity and 63 meaning maximum intensity for that component). This makes for a total number of 262144 (256K) possible colours (but as said, you can only show 256 at a time). The palette is programmable through the DAC registers (see link Masterkiller specified).


JAL

Posted: Mon Feb 18, 2008 9:58 am
by zaleschiemilgabriel
I haven't tried it myself, but I think you can also use the VESA VBE protected mode function the same way to set mode 13h. Have a look-see here:
http://www.vesa.org/public/VBE/vbe3.pdf
To save you some trouble, VESA says (in that document) that video card manufacturers are not required to support old video modes through the new VBE interface, but they recommend it to keep compatibility with older applications. There's also Appendix 5 of that pdf, that you can use as a guide to getting the video mode that you need the "new" way.
As a side note, my video card supports video mode 300x200x8bpp with a VESA VBE mode (one above 100h) and a framebuffer, which is basically the same thing as mode 13h. I haven't tried setting video mode 13h with VESA VBE.
In older documentation you might find "VESA VBE" as "SVGA"...
If you're writing an operating system, you'll end up using VBE anyway. If you use direct register programming, you should be aware that your code will not be compatible with all video cards.
P.S.: I'm waiting for the "smart" replies to this one... :twisted:

Re: 256-colours on Pmode using a VGA driver?

Posted: Mon Feb 18, 2008 11:56 am
by Combuster
t6q4 wrote:Hello,
I was wondering that since in real mode you can use

Code: Select all

mov ax, 0x0013
int 0x10
in real mode to go to 256-colour mode, how can you do this in Pmode? And also, I have just stumbled onto this, so could someone help explain the 256-colour pallete, please.

Thanks.
There are several ways to set a graphics mode:

1. drop from protected mode, call the interrupt, then go back to protected mode and enjoy
2. add v8086 functionality to your os, have it call int 0x10 from there and enjoy. A shame if you happen to run in 64-bit mode
3. write a generic driver that accesses the VGA front-end via its registers. While it works in most cases, some non-VGA cards can screw up big time.
4. write a driver specific for your card. Enjoy everything and hardware acceleration, but leave your friends in the cold.

Overall most people go for #2 because it allows SVGA modes as well, #3 is good second choice since it works in the most cases. Regarding register-level programming, my shameless plug: VGA Hardware

Regarding the palette, Its basically a substitution table wiuth 256 indices. The color of the pixel goes in, a color signal comes out. The VGA has 18 bits of accuracy here. You can change entries in that table.

I see FreeVGA has already been linked, you might want to read that as well even though its rather obfuscated. You may also want to google for "graphics programming black book" which is a longer, but easier read. (and it comes with sourcecode). You can also look up the VGA test suite in my OS's source if you want a more complete driver.

p.s. VESA-modes are not necessarily VGA-compatible, including low-resolution 8-bit modes.

Posted: Mon Feb 18, 2008 1:26 pm
by t6q4
Thanks for all the helpful replies. I guess I have quite a few options. I'm not planning to go to long mode yet, so I'll try making v8086 functionality.

Regards,
t6q4