|
This months column is about detecting the VESA compatible video card and displaying its capabilities.
#include <stdio.h>
typedef struct {
char signature[4]; // 'VESA'
short version; // VESA version
char far *oem; // Name of the card
long capabilities;
unsigned far *videomodes; //pointer to available videomodes
short totalmemory;
char reserved[236];
} vesaInfo;
typedef struct {
unsigned short mode;
unsigned char wina;
unsigned char winb;
unsigned short granularity; //granularity and winsize are used
unsigned short winsize; //to calculate the banksift value
unsigned short winasegment;
unsigned short winbsegment;
void (far *bankSwitch)(void); //pointer to bankSwitch routine
unsigned short bytesperline;
unsigned short width; //width and
unsigned short height; //height of the videomode
unsigned char charwidth;
unsigned char charheight;
unsigned char bitplanes;
unsigned char bitsperpixel; //if this is 8 then it's 256 colors
unsigned char banks;
unsigned char memorymodel;
unsigned char banksize;
unsigned char imagepages;
unsigned char reserved1;
unsigned char redmasksize;
unsigned char redfieldposition;
unsigned char greenmasksize;
unsigned char greenfieldposition;
unsigned char bluemasksize;
unsigned char bluefieldposition;
unsigned char rsvdmasksize;
unsigned char rsvdfieldposition;
unsigned char directcolormode;
unsigned char reserved2[216];
} modeInfo;
int getVesaInfo(vesaInfo far *vesainfo) {
_asm {
mov ax,04F00h //ax = 0x4f00
les di,[vesainfo] //es:di -> vesainfo
int 10h //call interrupt and get vesainfo
cmp ax,4Fh //if ax is 0x4f then vesa is detected
jz done
}
return(0); //if not, return 0 (no vesa card)
done:
return(1); //successful, return 1
}
int getVesaModeInfo(int mode, modeInfo far *modeinfo) {
_asm {
mov ax,4F01h
mov cx,[mode]
les di,[modeinfo]
int 10h
}
//return 1 if succesful, else 0
return (modeinfo->mode & 1);
}
//detect VESA and print info about the available modes
void main(void) {
vesaInfo vesainfo;
modeInfo modeinfo;
unsigned far *mode;
int i;
if(!getVesaInfo(&vesainfo))
printf("No VESA VBE detected...\n");
else {
//print VESA version of the card
printf("\nVESA VBE version %d.%d (", vesainfo.version >> 8, vesainfo.version & 0xF);
for(i=0; vesainfo.oem[i] !=0; i++) putchar(vesainfo.oem[i]);
printf(") detected\n\n");
printf("Available VESA video modes:\n");
printf("mode\twidth\theight\tcolors\n");
printf("----------------------------\n");
//loop through all available videomodes
for(mode = vesainfo.videomodes; *mode != 0xFFFF; mode++)
//get info about a mode and print some of the info
if(getVesaModeInfo(*mode,&modeinfo))
printf("%.3Xh\t %.4d\t %.4d\t %.8li\n",*mode, modeinfo.width, \
modeinfo.height, (long) 1 << modeinfo.bitsperpixel );
}
}
Thanks to Abe Racadabra for the just of this code.
¥
|