Game Programming with DGJPP
Graphics by Lord Azathoth

The Vesa BIOS extension 2.0
Are you bored by the pixels of the 320x200 VGA mode? Do you want a higher resolution? What do you think about 640x480? Or 800x600? Or higher? No problem: use the Vesa BIOS extension 2.0!

Introduction to the VBE functions
The VBE is made for semplify the life to the programmator that want to use an high resolution with a lot of colors. Whit the functions of the Vesa BIOS extension we can access directly to the video memory in the same way of the VGA mode 13h: with a simple pointer! But now I want to introduce few things about using these functions......
The BIOS have limited the number of video modes from 0 to 13h, and the OEMs have defined extended video modes from 14h to 7Fh. The values in the range form 80h to 0FFh are reserved by BIOS for determing if the video memory must cleared or not. Due to the 7 bits mode numbers, the VBE use a 14 bits mode numbers:

   D0-D8     =    Mode number
                  If D8 == 0, this is not a VESA defined mode
                  If D8 == 1, this is a VESA defined mode
   D9-D13    =    Reserved by VESA for future expansion (= 0)
   D14       =    Linear/Flat Frame Buffer Select
                  If D14 == 0, Use VGA Frame Buffer
                  If D14 == 1, Use Linear/Flat Frame Buffer
   D15       =    Preserve Display Memory Select
                  If D15 == 0, Clear display memory
                  If D14 == 1, Preserve display memory
The functions of the VBE returns the status in the register AX, formatted as follow:

          AL ==     4Fh: Function is supported
          AL !=     4Fh: Function is not supported
          AH ==     00h: Function call successful
          AH ==     01h: Function call failed
          AH ==     02h: Software supports this function, but the hardware
                         does not
          AH ==     03h: Function call invalid in current video mode
Thus we must treat a nonzero value in the register AH as an error.
I've introduced enough, but if someone want more details, mail me.

Read The VBE Controller Information
Trough the function 00h we can receive all the informations about the controller. These informations are stored in a 512 bytes buffer, formatted as follow:

struct VBEINFO {
   char  vbesignature[4];   // VBE Signature
   WORD  vbeversion;        // VBE Version
   DWORD oemstringptr;      // Pointer to OEM String
   BYTE  capabilities[4];   // Capabilities of graphics cont.
   DWORD videomodeptr;      // Pointer to Video Mode List
   WORD  totalmemory;       // number of 64Kb memory blocks
   WORD  oemsoftwarerev;    // VBE implementation Software revision
   DWORD oemvendornameptr;  // Pointer to Vendor Name String
   DWORD oemproductnameptr; // Pointer to Product Name String
   DWORD oemproductrevptr;  // Pointer to Product Revision String
   char  reserved[222];     // Reserved for VBE implementation scratch area
   char  oemdata[256];      // Data Area for OEM Strings
};
The function call format is:

     Input:    AX   = 4F00h  Return VBE Controller Information
            ES:DI   =        Pointer to buffer in which to place
                             VbeInfoBlock structure
                             (VbeSignature should be set to 'VBE2' when
                             function is called to indicate VBE 2.0
                             information is desired and the information
                             block is 512 bytes in size.)

     Output:   AX   =         VBE Return Status  
I've wrote a simple demo program for reading all the informations about the controller. See it!!!!!!!

Read VBE Mode Information
The VBE 2.0 provide a function for retrieving informations about a video mode. Isn't necessary to be in the video mode that interest to use this function. The function call format is: 01h:

     Input:    AX   = 4F01h   Return VBE mode information
               CX   =         Mode number
            ES:DI   =         Pointer to ModeInfoBlock structure

     Output:   AX   =         VBE Return Status
This function return a detailed 256 bytes record, formatted as follow:

struct MODEINFO {
   // Mandatory information for all VBE revision
   WORD  modeattributes;     // Mode attributes
   BYTE  winaattributes;     // Window A attributes
   BYTE  winbattributes;     // Window B attributes
   WORD  wingranularity;     // Window granularity
   WORD  winsize;    	     // Window size
   WORD  winasegment;        // Window A start segment
   WORD  winbsegment;        // Window B start segment
   DWORD winfuncptr;         // pointer to window function
   WORD  bytesperscanline;   // Bytes per scan line

   // Mandatory information for VBE 1.2 and above
   WORD  xresolution;         // Horizontal resolution in pixel or chars
   WORD  yresolution;         // Vertical resolution in pixel or chars
   BYTE  xcharsize;           // Character cell width in pixel
   BYTE  ycharsize;           // Character cell height in pixel
   BYTE  numberofplanes;      // Number of memory planes
   BYTE  bitsperpixel;        // Bits per pixel
   BYTE  numberofbanks;       // Number of banks
   BYTE  memorymodel;         // Memory model type
   BYTE  banksize;            // Bank size in KB
   BYTE  numberofimagepages;  // Number of images
   BYTE  reserved1;           // Reserved for page function

   // Direct Color fields (required for direct/6 and YUV/7 memory models)
   BYTE  redmasksize;         // Size of direct color red mask in bits
   BYTE  redfieldposition;    // Bit position of lsb of red bask
   BYTE  greenmasksize;       // Size of direct color green mask in bits
   BYTE  greenfieldposition;  // Bit position of lsb of green bask
   BYTE  bluemasksize;        // Size of direct color blue mask in bits
   BYTE  bluefieldposition;   // Bit position of lsb of blue bask
   BYTE  rsvdmasksize;        // Size of direct color reserved mask in bits
   BYTE  rsvdfieldposition;   // Bit position of lsb of reserved bask
   BYTE  directcolormodeinfo; // Direct color mode attributes

   // Mandatory information for VBE 2.0 and above
   DWORD physbaseptr;         // Physical address for flat frame buffer
   DWORD offscreenmemoffset;  // Pointer to start of off screen memory
   WORD  offscreenmemsize;    // Amount of off screen memory in 1Kb units
   char  reserved2[206];      // Remainder of ModeInfoBlock
};
See the demo program for the source code.

Set VBE Video Mode
Ok, now we can retrieve informations about the controllers and the video modes. But about setting the desidered video mode? I want to see the high resolution of my SVGA! Well, another VBE function:

     Input:    AX   = 4F02h     Set VBE Mode
               BX   =           Desired Mode to set
                    D0-D8  =    Mode number
                    D9-D13 =    Reserved (must be 0)
                    D14    = 0  Use windowed frame buffer model
                           = 1  Use linear/flat frame buffer model
                    D15    = 0  Clear display memory
                           = 1  Don't clear display memory

     Output:   AX   =           VBE Return Status
There are a list of the standard VESA video modes:
mode numberresolution and color depthtypesupporting flat memory model
0x100640x400x8graphicsyes
0x101640x480x8graphicsyes
0x102800x600x4graphicsno
0x103800x600x8graphicsyes
0x1051024x768x8graphicsyes
0x1071280x1024x8graphicsyes
0x10880x60textno
0x109132x132textno
0x10B132x50textno
0x10C132x60textno
0x110640x480x16graphicsyes
0x112640x480x32graphicsyes
0x113800x600x16graphicsyes
0x115800x600x32graphicsyes
0x1161024x768x16graphicsyes
0x1181024x768x32graphicsyes
0x1191280x1024x16graphicsyes
0x11B1280x1024x32graphicsyes
0x11C1600x1200x8graphicsyes
0x11D1600x1200x16graphicsyes
And see demo program for view these video modes....

Return VBE Video Mode
And if you want to know the current VBE video mode, use the function 03h:

     Input:    AX   = 4F03h   Return current VBE Mode

     Output:   AX   =         VBE Return Status
               BX   =         Current VBE mode
                    D0-D13 =  Mode number
                    D14  = 0  Windowed frame buffer model
                         = 1  Linear/flat frame buffer model
                    D15  = 0  Memory cleared at last mode set
                         = 1  Memory not cleared at last mode set
Simply, isn't true?

Return to the text mode
And for return in the normal text mode 03h? We can use the BIOS set video mode function 00h:

#define TEXT_MODE 0x03

void setmode(short mode)
{
	union REGS regs;

	regs.h.ah = 0x00;	  // Procedure 0x00: Set Video Mode
	regs.h.al = TEXT_MODE;	  
	int86(0x10,&regs,&regs)	  // Call the BIOS
}


Put the first pixel
When we use the flat memory model of the VBE 2.0, the video memory structure in similar to the VGA memory structure. The only difference is that we must multiply the 'y' by 640 instead of 320. For obtain the video memory address we must use the function __dpmi_physical_address_mapping() to mapping the address obtained via the function Return VBE mode informations (physbaseptr) and add the __djgpp_conventional_base value for access to the video memory:

   struct MODEINFO modeinfo;
   __dpmi_meminfo meminfo;

   if(get_mode_info(0x4101, &modeinfo)) return(VBE_INVALID_MODE);
   if(!(modeinfo.modeattributes&0x80)) return(VBE_LINEAR);
   meminfo.size=(unsigned long)(modeinfo.xresolution*modeinfo.yresolution);
   meminfo.address=modeinfo.physbaseptr;
   if(__dpmi_physical_address_mapping(&meminfo)) return(VBE_MAPPING);

   __djgpp_nearptr_enable();
   vbememory=(char *)(meminfo.address + __djgpp_conventional_base);
See the simple demo program for the source code!



[main] [prec] [next] [email]

Site Made and Maintained by The Dark Angel <DarkAngel@tin.it>
My ICQ Number is 2063026
You Visited This Page times


This page hosted by Geocities Icon Get your own Free Home Page