home *** CD-ROM | disk | FTP | other *** search
/ PC Gamer 9 / 1995-08_Disc_9.iso / vesa / tecmar / vesatest.c next >
C/C++ Source or Header  |  1990-09-24  |  7KB  |  300 lines

  1. /*
  2.  * This is a sample program to query a video adapters capabilities
  3.  * conforming to Vesa Super VGA BIOS Extension Standard #VS891001
  4.  *
  5.  * This program is compiled under Microsoft C version 5.0 (or equivalent).
  6.  * Any memory model may be used.
  7.  * (Note the "%Fs" format to display the (far) OEM string)
  8.  *
  9.  * The command used to compile this is:
  10.  *        cl /AS /Os /Gs /G0 /Zp vesatest.c
  11.  *
  12.  * Program written by Mark D. Niemiec of Tecmar Inc.
  13.  * This program is in the public domain.
  14.  */
  15. #include <stdio.h>
  16.  
  17. typedef unsigned char uchar;
  18. typedef unsigned int uint;
  19.  
  20. #define    lobyte(n)    ((n) & 0xFF)
  21. #define    hibyte(n)    ((n) >> 8 & 0xFF)
  22.  
  23.  
  24.  
  25. /*
  26.  * VGA BIOS extension functions
  27.  */
  28. #define    SUPERVGA        0x4F
  29.  
  30. #define    GetSuperVGAInfo        0x00
  31. #define    GetModeInfo        0x01
  32.  
  33.  
  34.  
  35. /*
  36.  * VGA information block returned by GetSuperVGAInfo call
  37.  */
  38. struct VgaInfoBlock {
  39.     char    VESASignature[4];    /* 0: 4 signature bytes:  must be 'VESA' */
  40.     uint    VESAVersion;        /* 4: VESA version number */
  41.     char    far *OEMStringPtr;    /* 6: Pointer to OEM string */
  42.     long    Capabilities;        /* 10: Capabilities of the video environment */
  43.     int    far *VideoModePtr;    /* 14: list of supported Super VGA modes */
  44.     char    VIBfiller[256-18];    /* 18: fill to 256 bytes */
  45. };
  46.  
  47. struct VgaInfoBlock far vib;
  48. /* NOTE: Since 'vib' is a static variable, it is pre-initialized to zero */
  49.  
  50.  
  51.  
  52. /*
  53.  * Mode information returned by GetModeInfo call
  54.  */
  55. struct ModeInfoBlock {
  56.     uint    ModeAttributes;        /* 0: mode attributes */
  57.     uchar    WinAAttributes;        /* 2: Window A attributes */
  58.     uchar    WinBAttributes;        /* 3: Window B attributes */
  59.     uint    WinGranularity;        /* 4: Window granularity */
  60.     uint    WinSize;        /* 6: Window size */
  61.     uint    WinASegment;        /* 8: Window A start segment */
  62.     uint    WinBSegment;        /* 10: Window B start segment */
  63.     uint    WinFuncPtr[2];        /* 12: (far) pointer to window function */
  64.     uint    BytesPerScanLine;    /* 14: bytes per scan line */
  65.  
  66.     uint    XResolution;        /* 16: horizontal resolution */
  67.     uint    YResolution;        /* 18: vertical resolution */
  68.     uchar    XCharSize;        /* 19: character cell width */
  69.     uchar    YCharSize;        /* 20: character cell height */
  70.     uchar    NumberOfPlanes;        /* 21: number of memory planes */
  71.     uchar    BitsPerPixel;        /* 22: bits per pixel */
  72.     uchar    NumberOfBanks;        /* 23: number of banks */
  73.     uchar    MemoryModel;        /* 24: memory model type */
  74.     uchar    BankSize;        /* 25: bank size in KB */
  75.  
  76.     char    MIBfiller[256-26];    /* 26: fill to 256 bytes */
  77. };
  78.  
  79. struct ModeInfoBlock far mib;
  80. /* NOTE: Since 'mib' is a static variable, it is pre-initialized to zero */
  81.  
  82.  
  83.  
  84. /*
  85.  * Known memory models
  86.  */
  87. uchar *models[] = {
  88.     "Text",                /* 0 = text */
  89.     "CGA",                /* 1 = CGA graphics */
  90.     "Herc",                /* 2 = Hercules graphics */
  91.     "EGA",                /* 3 = EGA/VGA planar graphics */
  92.     "VGA",                /* 4 = VGA packed-pixel graphics */
  93.     "256"                /* 5 = non-chain-4 256 color */
  94. };                    /* 6-F = VESA TBD; 10-FF = OEM */
  95.  
  96.  
  97.  
  98. /*
  99.  * Column headings
  100.  */
  101. char headings[] = "\n\
  102. Mode Attr Window  WindowA WindowB Mapping  Bytes Resolution Char BPP Banks Type\n\
  103.           Grn Siz Seg att Seg att Function /line            Cell   Planes\n\n";
  104.  
  105.  
  106.  
  107. /*
  108.  * Main procedure
  109.  */
  110. void
  111. main(int argc, char **argv)
  112. {
  113.     extern void queryvesa(void);
  114.  
  115.     queryvesa();
  116.     exit(0);
  117. }
  118.  
  119.  
  120.  
  121. /*
  122.  * Inquire about VESA information
  123.  */
  124. void
  125. queryvesa(void)
  126. {
  127.     extern void vesainfo(void);
  128.     extern int same(char far *, char *, int);
  129.     int status;
  130.  
  131.     status = int10(SUPERVGA<<8|GetSuperVGAInfo, 0, 0, 0, &vib);
  132.  
  133.     if(lobyte(status) != SUPERVGA) {
  134.         printf("VGA BIOS extensions not installed\n");
  135.     } else if(hibyte(status) != 0) {
  136.         printf("Get Super VGA Information call returned error %d\n",
  137.           hibyte(status));
  138.     } else if(!same(vib.VESASignature,"VESA",4)) {
  139.         printf("VESA signature was expected, '%4.4s' was found\n",
  140.           vib.VESASignature);
  141.     } else {
  142.         vesainfo();
  143.     }
  144. }
  145.  
  146.  
  147.  
  148. /*
  149.  * See if two strings (one far and one normal) are equal
  150.  */
  151. int
  152. same(char far *p, char *q, int n)
  153. {
  154.     while(--n >= 0) {
  155.         if(*p++ != *q++)
  156.             return(0);
  157.     }
  158.     return(1);
  159. }
  160.  
  161.  
  162.  
  163. /*
  164.  * Display VESA information
  165.  */
  166. void
  167. vesainfo(void)
  168. {
  169.     extern void querymode(int);
  170.     int far *modes;
  171.  
  172.     printf("Super VGA BIOS extension version %d.%02d is installed\n",
  173.       hibyte(vib.VESAVersion),
  174.       lobyte(vib.VESAVersion));
  175.     printf(
  176.       vib.OEMStringPtr==NULL ?
  177.         "No OEM String is present" : "OEM string is '%Fs'\n",
  178.       vib.OEMStringPtr);
  179.     printf("Device capabilities are %lX\n",
  180.       vib.Capabilities);
  181.  
  182.     printf(headings);
  183.  
  184.     for(modes=vib.VideoModePtr; *modes!=-1; )
  185.         querymode(*modes++);
  186. }
  187.  
  188.  
  189.  
  190. /*
  191.  * Inquire about mode information
  192.  */
  193. void
  194. querymode(int mode)
  195. {
  196.     extern void dispmode(void), dispextmode(void);
  197.     int status;
  198.  
  199.     printf("%04X", mode);
  200.     status = int10(SUPERVGA<<8|GetModeInfo, 0, mode, 0,
  201.       (struct ModeInfoBlock far *)&mib);
  202.  
  203.     if(lobyte(status) != SUPERVGA) {
  204.         printf(": Get Mode Information call is not available\n");
  205.     } else if(hibyte(status) != 0) {
  206.         printf(": Get Mode Information call returned error %d\n",
  207.           hibyte(status));
  208.     } else {
  209.         dispmode();
  210.         if(mib.ModeAttributes & 0x02)
  211.             dispextmode();
  212.     }
  213.  
  214.     printf("\n");
  215. }
  216.  
  217.  
  218.  
  219. /*
  220.  * Display mandatory mode information
  221.  */
  222. void
  223. dispmode(void)
  224. {
  225.     printf(" %s%s%s%s",
  226.       mib.ModeAttributes&0x01 ? "I" : " ",        /* initializable */
  227.       mib.ModeAttributes&0x04 ? "B" : " ",        /* BIOS fns. */
  228.       mib.ModeAttributes&0x08 ? "C" : "M",        /* color/mono */
  229.       mib.ModeAttributes&0x10 ? "G" : "T");        /* graphics/text */
  230.     printf("%4d%4d",
  231.       mib.WinGranularity,                /* window granularity */
  232.       mib.WinSize);                    /* window size */
  233.     printf(
  234.       mib.WinAAttributes&0x01 ? " %04X %s%s" : "        ",
  235.       mib.WinASegment,                /* window A segment */
  236.       mib.WinAAttributes&0x02 ? "R" : " ",        /* window A readable */
  237.       mib.WinAAttributes&0x04 ? "W" : " ");        /* window A writable */
  238.     printf(
  239.       mib.WinBAttributes&0x01 ? " %04X %s%s" : "        ",
  240.       mib.WinBSegment,                /* window B segment */
  241.       mib.WinBAttributes&0x02 ? "R" : " ",        /* window B readable */
  242.       mib.WinBAttributes&0x04 ? "W" : " ");        /* window B writable */
  243.     printf(" %04X:%04X",
  244.       mib.WinFuncPtr[1], mib.WinFuncPtr[0]);    /* mapping function */
  245.     printf("%5d",
  246.       mib.BytesPerScanLine);            /* bytes/scan line */
  247. }
  248.  
  249.  
  250.  
  251. /*
  252.  * Display extended mode information
  253.  */
  254. void
  255. dispextmode(void)
  256. {
  257.     printf("%5dx%-4d",
  258.       mib.XResolution,                /* screen width */
  259.       mib.YResolution);                /* screen height */
  260.     printf("%3dx%-2d",
  261.       mib.XCharSize,                /* character width */
  262.       mib.YCharSize);                /* character height */
  263.     printf("%2d",
  264.       mib.BitsPerPixel);                /* bits/pixel */
  265.     printf("%2d",
  266.       mib.NumberOfPlanes);                /* number of planes */
  267.     printf(
  268.       mib.BankSize!=0 ? "%2dx%-3d" : "%2d    ",
  269.       mib.NumberOfBanks,                /* number of banks */
  270.       mib.BankSize);                /* bank size */
  271.  
  272.     if(mib.MemoryModel < 6)
  273.         printf(" %s", models[mib.MemoryModel]);    /* model type */
  274.     else
  275.         printf(" %02X", mib.MemoryModel);    /* model number */
  276. }
  277.  
  278.  
  279.  
  280. /*
  281.  * Call video BIOS
  282.  * (Note:  es and di may be passed separately, or together via a far pointer)
  283.  */
  284. #include <dos.h>
  285.  
  286. int10(int ax, int bx, int cx, int dx, int di, int es)
  287. {
  288.     union REGS r;
  289.     struct SREGS s;
  290.  
  291.     r.x.ax = ax;
  292.     r.x.bx = bx;
  293.     r.x.cx = cx;
  294.     r.x.dx = dx;
  295.     r.x.di = di;
  296.     s.es = es;
  297.     int86x(0x10, &r, &r, &s);
  298.     return(r.x.ax);
  299. }
  300.