Vesa or Mastercard ?

VESA BIOS EXTENSION 2.0
Basic Trainer
by dlt, May 1998


INTRODUCTION

This trainer/tutorial is aimed at getting you started with VBE2; that is, setting up an appropriate graphics mode, drawing to the screen, and some other basic functions that you will probably need. If you are interested in anything more advanced or in-depth, I suggest you get the VBE2 spec:

ftp://ftp.scitechsoft.com/devel/docs/vbe20-11.exe

What might also be helpful is the DPMI spec; 0.9 will do as well as 1.0.

ftp://x2ftp.oulu.fi/pub/msdos/programming/specs/dpmispec.arj (0.9)
or
ftp://x2ftp.oulu.fi/pub/msdos/programming/specs/dpmi100.zip (1.0)

As you will discover while reading this document, I use DJGPP, and I like it a lot :-) Many thanks to DJ Delorie & co. Point yourself to:

http://www.delorie.com/


REQUIREMENTS
1. A compiler which produces protected mode source. This is not the same as a protected mode compiler; Turbo Pascal 7 users may as well stop reading this now, and go get DJGPP.

2. A very basic understanding of the differences between protected mode and real mode.

3. Reading lessons help, as my science teacher is wont to say...


SETTING UP A VIDEO MODE

This is probably the first thing you will want to do. But before you can set up a video mode using VBE2, you need to establish that VBE2 functions are in fact installed on your system. For this you need a data structure.

  VBE_INFO_STRUC 
     VBE_Signature      DWORD 
     Version            WORD 
     OEM_String         DWORD 
     Capabilities       DWORD 
     VideoModeList      DWORD 
     TotalMemory        WORD 
     OEMSoftwareRev     WORD 
     OEMVendorName      DWORD 
     OEMProductName     DWORD 
     OEMProductRev      DWORD 
     Reserved           222 bytes 
     OEM_Data           256 bytes 
  VBE_INFO_STRUC ENDS 

A couple of these may need explaining:

OEM_* are seg:off pointers to null-terminated strings.

VideoModeList points to an array of words representing the VBE2 display modes supported by the video card. This list is terminated by a 0xffff.

TotalMemory is in 64k chunks, so you need to multiply by 65536 to get the number of bytes of video memory actually available.

Version is a binary-coded decimal. In other words, the most significant byte contains the major version number (the number before the decimal point) and the least significant byte contains the minor version number.

Capabilities is a set of flags indicating what the video card can do. You probably won't need to look at this.

You'll need to set this structure up in whatever form is appropriate to your compiler. Note that for many C compilers, an int is 4 bytes big, in other words a signed dword. You need to use the type short to store words. Also beware of #pragma pack() and __PACKED__ conventions (look these up in your compiler's documentation).

Now that you have the structure, you need to do three things:

If all of this works okay, then VBE2 functions are installed.

To set up a particular screen mode is relatively easy. Again, you call real- mode interrupt 0x10, with AX = 0x4f02, and BX = the video mode you want. To get back to text mode, do the same thing with BX = 3 (this is exactly the same as a normal BIOS "set video mode" call).


LINEAR FRAME BUFFERS

This is probably the reason you wanted to use VBE2 in the first place, right? For those who are in the dark, having a linear frame buffer is a neat little protected mode gimmick whereby you can access all of the video card's memory directly. Yup, that's right, no messing around with write-planes and small windows into video memory... you get to play with the whole lot at once. You needn't worry about the mechanics of how this works. Just pretend that the video card's memory has been tacked onto the end of the "normal" memory in your system. All you really have to do is find out the address where it begins. This is unfortunately a less-than-simple process.


PANNING, PALETTES, PAGE FLIPPING

The good news is that you've got past the hard bit. The rest is fairly trivial. Here are a few other things you might want to do with VBE2:

ANY QUESTIONS?

You can contact me via


APPENDIX: CALLING REAL-MODE INTERRUPTS

Generally:

Tran's PMODE:
As I recall, he used int 33h with the interrupt number pushed onto the stack. So, set up the registers as if you were in real mode, push the interrupt number as an immediate, and call interrupt 33h.

DJGPP (and similarly for some other Cs):

Borland Pascal 7.0:

And that should be enough to get you started.