Skip to main content
GameDev.net gamedev.net
🔒 Locked

Programming the VGA card without using interrupts

Started by Nacho Oct 27, 2006 at 9:39 PM 12 replies 6.1k views
Original Post
Nacho
Nacho
Hi! I´ve to add some kind of capability to minix OS for my operating systems class and I´d like to evaluate the feasibility of doing a VGA graphics driver with support for the basic primitives such as putpixel, drawline, fillrect and bitblt. Since minix works in protected mode, mode x and mode 13h are not an option. I´ve been googling for hours and the following three links are the best I have found: http://www.brackeen.com/home/vga/basics.html http://www.osdever.net/FreeVGA/vga/vga.htm http://www.csee.umbc.edu/~motteler/teaching/courses/operating_systems/os97a/proj4/proj4.html Unfortunately, the first one uses a BIOS call so I cannot use it. The second link has lots of information on the VGA registers but no examples showing how to make them work together. The third example is from an operating systems course from another university that proposes a similar project to the one I´d like to make. The author suggests looking for simple drivers written for DOS but I haven´t been able to find anything useful. Can you guys give me a hint? Thanks in advance! --Ignacio
hplus0603
hplus0603
The problem is that the VGA cards don't have a common register set -- they only have a common BIOS. You have to set up a mode where you can call the BIOS, if you want to set the card in graphics mode.

I also believe that you can call the BIOS using a real mode emulator in protected mode, if you pay careful attention to what's going on.

It's either that, or disassembling the graphics driver for your card of choice to try to figure out how it works (you won't get register specs out of the IHVs).
enum Bool { True, False, FileNotFound };
Nacho
Nacho
Thanks for you reply hplus0603. How can I set a mode where I can call the video´s card BIOS? I´m also interested in that real mode emulator, can you suggest me a link?

As a side question: How does Linux, being a protected mode OS, manages to provide a graphical interface such as X? How does it communicate with the video card? Or does it have a driver for each kind of video card model?

Thanks again for your input.

--Ignacio
joanusdmentia
joanusdmentia
All graphics cards today should support the VESA BIOS Extensions. These provide both a real-mode and protected-mode interface to call (at least, I'd expect all modern cards to provide the protected-mode interface, I'm not 100% sure though). Worst case scenario you can thunk back to real mode to use the real-mode interface, which while slow for setting up the video modes and switching between banks, will make no difference to accessing the video memory itself (and you can avoid switching banks by setting up a linear buffer).
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The nly verdict is vengeance; a vendett o
Nacho
Nacho
Quote:
Original post by joanusdmentia
All graphics cards today should support the VESA BIOS Extensions.


Do you have more information about this? I´ve googled the term and found a 96 page PDF that explains how to do it (something related to copying a piece of code from the BIOS) but provides no examples. I´ve also found this: VESA Bios Extension assembler & C functions but I´m not quite sure if it´s useful at all since it uses interrupts, too.
Mastaba
Mastaba
I have a vague memory of the VESA BIOS Extensions supporting a real mode interrupt function that returned the protected mode addresses to directly call into the bios (or rather a copy of it) when in protected mode.
JasonBlochowiak
JasonBlochowiak
Quote:
Original post by hplus0603
The problem is that the VGA cards don't have a common register set -- they only have a common BIOS. You have to set up a mode where you can call the BIOS, if you want to set the card in graphics mode.

I also believe that you can call the BIOS using a real mode emulator in protected mode, if you pay careful attention to what's going on.

It's either that, or disassembling the graphics driver for your card of choice to try to figure out how it works (you won't get register specs out of the IHVs).


Um, the VGA cards do have a common register set.

SVGA cards, on the other hand, don't - but, quite a few of them were well (-ish) documented.

If you're only going for mode 13 or mode X style framebuffer access, you should be able to do it purely by register access.

At first blush, this does look pretty good, but you're right in that it doesn't tie everything together.

In describing mode X, this at least lists a ton of register settings.

Back in the day, we used "Richard F. Ferraro's Programmer's Guide to the EGA, VGA, and Super VGA Cards" at id. I can't remember if it had a full register dump for how to setup mode 13, but if anything is likely to, that's it. My copy is somewhere in my basement, or I'd look it up for you. :)
Rockoon1
Rockoon1
I second that book recommendation. Ferraro's books are the best source out there short of individual specifications for specific cards. Back in the day, it was THE bible for graphics programming.
joanusdmentia
joanusdmentia
Quote:
Original post by Ignacio Liverotti
Do you have more information about this? I´ve googled the term and found a 96 page PDF that explains how to do it (something related to copying a piece of code from the BIOS) but provides no examples. I´ve also found this: VESA Bios Extension assembler & C functions but I´m not quite sure if it´s useful at all since it uses interrupts, too.


That link looks like what you'll want (I only glanced at it quickly, but it looks like it's for running in protected mode). You'll always need to use a couple of software interrupt calls in real-mode, the only other option is to program the card's registers directly and unless you only plan on ever using a single very old VGA card you'll have a hard time finding the information and will have to write a new driver for each type of card. There will be an interrupt call that returns a protected-mode (physical) address as Mastaba mentioned, after you switch to protected-mode you call this address (after mapping into your logical address-space) instead of the software interrupt.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The nly verdict is vengeance; a vendett o
JasonBlochowiak
JasonBlochowiak
Quote:
Original post by joanusdmentia
... the only other option is to program the card's registers directly and unless you only plan on ever using a single very old VGA card you'll have a hard time finding the information and will have to write a new driver for each type of card.


As I already mentioned in this thread, that statement is incorrect for VGA cards. It's slightly more correct for SVGA cards, but even then they all functioned similarly.
joanusdmentia
joanusdmentia
Quote:
Original post by JasonBlochowiak
Quote:
Original post by joanusdmentia
... the only other option is to program the card's registers directly and unless you only plan on ever using a single very old VGA card you'll have a hard time finding the information and will have to write a new driver for each type of card.


As I already mentioned in this thread, that statement is incorrect for VGA cards. It's slightly more correct for SVGA cards, but even then they all functioned similarly.


I was assuming the OP was referring to a driver that supported 256 colours, not a genuine VGA graphics card. Good luck to him actually finding a genuine VGA card and an old enough system to use it, unless he already has one lying around.

Of course if he really is talking about a VGA card then he doesn't want to use the VESA BIOS Extensions.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The nly verdict is vengeance; a vendett o
kvp
kvp
Quote:
Original post by joanusdmentia
Quote:
Original post by JasonBlochowiak
Quote:
Original post by joanusdmentia
... the only other option is to program the card's registers directly and unless you only plan on ever using a single very old VGA card you'll have a hard time finding the information and will have to write a new driver for each type of card.


As I already mentioned in this thread, that statement is incorrect for VGA cards. It's slightly more correct for SVGA cards, but even then they all functioned similarly.


I was assuming the OP was referring to a driver that supported 256 colours, not a genuine VGA graphics card. Good luck to him actually finding a genuine VGA card and an old enough system to use it, unless he already has one lying around.

Of course if he really is talking about a VGA card then he doesn't want to use the VESA BIOS Extensions.


Any modern svga compatible card support the old vga register set and can be programmed like a vga card. The limits are 640x480x16 and 320x200x256. Both modes are selectable by directly programming the legacy vga registers from protected mode. No bios is necessary for this.

The svga standard is an interface standard, and one has to use the svga bios, either through the real or the protected mode interface. Most svga compatible cards support their full resolution range in svga mode. Once the mode is set up, the os can use the framebuffer through memory mapping, like a simple array of bytes.

For hobby os use, I would suggest learning how to switch to 320x200x256 mode (also called mcga). In this mode 1 pixel is one byte and the video ram can be found at 0xa0000 physical and is 64Kb long. This is very much how the svga linear framebuffer works, but doesn't need svga bios calls to work.

For 640x480x16 mode, the video ram is at the same place but acts as a 640x480x1 black and white image and the os has to switch between the 4 planes (rgbi) by setting vga i/o registers and pack pixels (8 pixels into 1 byte) to get it working.

For more info, I suggest Ralph Brown's Interrupt List and Port List...
Nacho
Nacho
Thanks for all your replies! We finally managed to set the video card in mode 13h by only writing to the registers.

@ Jason Blochowiak: Thanks for the link. I had already visited it but it was very useful nonetheless. Just like you mentioned, we´re aiming our project at VGA cards since they are the lowest common denominator. I´ve seen references to Ferraro´s book everywhere but there´s no chance for me to actually grab a copy of it since early 90´s computer books are hard to find here in Argentina. In any case, our biggest concern was to set the video card in a graphical mode and manage to plot a few pixels and, fortunately, we solved it. Now we´re in the fun phase, which is designing a simplified version of opengl for minix.

@ joanusdmentia: Thanks for all your help during this thread. Our project aims to work on every single PC out there (with a VGA card at the very least :P ). Although useful for getting into higher resolutions, the VESA BIOS extensions won´t serve our purposes since not every video card out there supports it.

@ kvp: Quote: "Any modern svga compatible card support the old vga register set and can be programmed like a vga card." That´s right. I´ve read some parts of Abrash´s black book and that´s one of the things I remembered about it so that´s why we aimed our project at VGA cards. We´re using the exact same mode you said and had to set the the memory range from 0xA0000 to AFA00 as a data segment so that minix could grant us access to it.

--Nacho

PRS102076
PRS102076
I wrote some code a while back and figured the settings needed for the bulk of the VGA modes, and also the code needed to fool around with loading fonts
in text mode. I got 320*200/240/350/400/480 and 360*200/240/350/400/480 for 256 color modes as well as 640/720 16 color equivalents.
As for SVGA cards and later, if you are at all interested, you will have to get an NDA from ATI, NVidia and alike, which is like trying to get blood out of a stone, unless you can get an Asiliant or Silicon motion based card, where the info is freely available. XGI may be more receptive.

Ferraro's Programmer's Guide to the ega, VGA and SVGA can be acquired from here:

http://www.amazon.co.uk/Programmers-Guide-EGA-Super-Cards/dp/0201624907/sr=11-1/qid=1162829135/ref=sr_11_1/202-5847756-4281449

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.