home *** CD-ROM | disk | FTP | other *** search
/ Graphics 16,000 / graphics-16000.iso / msdos / viewers / disp160 / vesainfo.c < prev    next >
Text File  |  1992-08-12  |  7KB  |  239 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3.  
  4. /*
  5.  * VESA BIOS extended function number and return code
  6.  */
  7. #define VESA_FUNC    0x4f00
  8. #define VESA_SUCCESS    0x004f
  9.  
  10. /*
  11.  * VESA BIOS sub-function numbers
  12.  */
  13. #define VESA_VGA_INFO    0
  14. #define VESA_MODE_INFO  1
  15. #define VESA_SET_MODE    2
  16. #define VESA_GET_MODE    3
  17. #define VESA_VGA_STATE  4
  18. #define VESA_PAGE_CTL    5
  19.  
  20. #define ushort  unsigned short
  21.  
  22. /*
  23.  * The VGA info structure
  24.  */
  25. typedef struct {
  26.     char       VESASignature[4];    /* should be "VESA" */
  27.     short      VESAVersion;        /* VESA version number */
  28.     char  far *OEMStringPtr;        /* Pointer to OEM string */
  29.     long       Capabilities;        /* capabilities of the video env */
  30.     short far *VideoModePtr;        /* ptr to supported Super VGA modes */
  31. } VgaInfoBlock;
  32.  
  33. /*
  34.  * The mode info structure
  35.  */
  36. typedef struct {
  37.     short      ModeAttributes;        /* mode attributes */
  38.     char       WinAAttributes;        /* Window A attributes */
  39.     char       WinBAttributes;        /* Window B attributes */
  40.     short      WinGranularity;        /* window granularity */
  41.     short      WinSize;            /* window size */
  42.     ushort     WinASegment;        /* Window A start segment */
  43.     ushort     WinBSegment;        /* Window B start segment */
  44.     void far   (*WinFuncPtr)();        /* pointer to window function */
  45.     short      BytesPerScanLine;    /* bytes per scan line */
  46.     /* extended information */
  47.     /* optional information */
  48.     short      XResolution;        /* horizontal resolution */
  49.     short      YResolution;        /* vertical resolution */
  50.     char       XCharSize;        /* character cell width */
  51.     char       YCharSize;        /* character cell height */
  52.     char       NumberOfPlanes;        /* number of memory planes */
  53.     char       BitsPerPixel;        /* bits per pixel */
  54.     char       NumberOfBanks;        /* number of banks */
  55.     char       MemoryModel;        /* memory model type */
  56.     char       BankSize;        /* bank size in K */
  57. } ModeInfoBlock;
  58.  
  59. /*
  60.  * MODE attribute bits
  61.  */
  62. #define MODE_SUPPORTED  1        /* Mode supported in hardware */
  63. #define MODE_EXTINFO    2        /* Extended information available */
  64. #define MODE_SUPBIOS    4        /* Outp functions supported by BIOS */
  65. #define MODE_ISCOLOR    8        /* Monochrome/color mode */
  66. #define MODE_ISGRAPHICS 16        /* Mode type (0: text, 1:graphics) */
  67.  
  68. /*
  69.  * Window attribute bits
  70.  */
  71. #define WIN_SUPPORTED    1        /* Window supported */
  72. #define WIN_READABLE    2        /* Window readable */
  73. #define WIN_WRITABLE    4        /* Window writable */
  74.  
  75. /*
  76.  * MemoryModel values
  77.  */
  78. #define MODEL_TEXT    0        /* 00h = Text mode */
  79. #define MODEL_CGA    1        /* 01h = CGA graphics */
  80. #define MODEL_HERC    2        /* 02h = Hercules graphics */
  81. #define MODEL_4PLANE    3        /* 03h = 4-plane planar */
  82. #define MODEL_PACKED    4        /* 04h = Packed pixel */
  83. #define MODEL_256_NC    5        /* 05h = Non-chain 4, 256 color */
  84. /* 06h-0Fh = Reserved, to be defined by VESA */
  85. /* 10h-FFh = To be defined by OEM         */
  86.  
  87.  
  88. int getinfo(VgaInfoBlock *vgainfo)
  89. {
  90.     _ES = FP_SEG(vgainfo);
  91.     _DI = FP_OFF(vgainfo);
  92.     _AX = VESA_FUNC + VESA_VGA_INFO;
  93.     geninterrupt(0x10);
  94.     if(_AX != VESA_SUCCESS) return(0);
  95.     if(vgainfo->VESASignature[0] != 'V') return(0);
  96.     if(vgainfo->VESASignature[1] != 'E') return(0);
  97.     if(vgainfo->VESASignature[2] != 'S') return(0);
  98.     if(vgainfo->VESASignature[3] != 'A') return(0);
  99.     return(1);
  100. }
  101.  
  102. int getmodeinfo(int mode,ModeInfoBlock *modeinfo)
  103. {
  104.     _ES = FP_SEG(modeinfo);
  105.     _DI = FP_OFF(modeinfo);
  106.     _CX = mode;
  107.     _AX = VESA_FUNC + VESA_MODE_INFO;
  108.     geninterrupt(0x10);
  109.     if(_AX != VESA_SUCCESS) return(0);
  110.     return(modeinfo->ModeAttributes & MODE_SUPPORTED);
  111. }
  112.  
  113.  
  114. void printinfo(VgaInfoBlock *vgainfo)
  115. {
  116.     char  far *sp = vgainfo->OEMStringPtr;
  117.     short far *mp = vgainfo->VideoModePtr;
  118.  
  119.     printf("VESASignature: \"%c%c%c%c\"\n",
  120.         vgainfo->VESASignature[0],
  121.         vgainfo->VESASignature[1],
  122.         vgainfo->VESASignature[2],
  123.         vgainfo->VESASignature[3]
  124.     );
  125.     printf("VESAVersion:\t%d\n",vgainfo->VESAVersion);
  126.     printf("OEMStringPtr:\t\"");
  127.     while(*sp != '\0') putchar(*sp++);
  128.     printf("\"\nCapabilities:\t%ld\n",vgainfo->Capabilities);
  129.     printf("VideoModePtr:\t%Fp\n",mp);
  130.     printf("Video Modes:\t");
  131.     while(*mp != (-1)) printf("0x%x ",*mp++);
  132.     printf("\n\n");
  133. }
  134.  
  135. #define DEFBIT(bit)    { bit, #bit }
  136. typedef struct {
  137.     int  bit;
  138.     char *name;
  139. } bitdef;
  140.  
  141. bitdef modeattrbits[] = {
  142.     DEFBIT(MODE_SUPPORTED),
  143.     DEFBIT(MODE_EXTINFO),
  144.     DEFBIT(MODE_SUPBIOS),
  145.     DEFBIT(MODE_ISCOLOR),
  146.     DEFBIT(MODE_ISGRAPHICS),
  147.     { 0 }
  148. };
  149.  
  150. bitdef winattrbits[] = {
  151.     DEFBIT(WIN_SUPPORTED),
  152.     DEFBIT(WIN_READABLE),
  153.     DEFBIT(WIN_WRITABLE),
  154.     { 0 }
  155. };
  156.  
  157. bitdef memorymodels[] = {
  158.     DEFBIT(MODEL_TEXT),
  159.     DEFBIT(MODEL_CGA),
  160.     DEFBIT(MODEL_HERC),
  161.     DEFBIT(MODEL_4PLANE),
  162.     DEFBIT(MODEL_PACKED),
  163.     DEFBIT(MODEL_256_NC),
  164.     { 0 }
  165. };
  166.  
  167. void printbits(int value,bitdef *def)
  168. {
  169.     int prev = 0;
  170.  
  171.     while(def->bit != 0) {
  172.         if(value & def->bit) {
  173.         if(prev) printf(" | ");
  174.         printf(def->name);
  175.         prev = 1;
  176.         }
  177.         def++;
  178.     }
  179.     if(!prev) printf("0");
  180.     printf("\n");
  181. }
  182.  
  183. char *getmodelname(int model)
  184. {
  185.     static char temp[50];
  186.  
  187.     if(model < 0) return(sprintf(temp,"Invalid model [%d]",model),temp);
  188.     if(model <= MODEL_256_NC) return(memorymodels[model].name);
  189.     if(model <= 15) return(sprintf(temp,"VESA model [%0x2x]",model),temp);
  190.     return(sprintf(temp,"OEM model [%0x2x]",model),temp);
  191. }
  192.  
  193. void printmodeinfo(int mode,ModeInfoBlock *modeinfo)
  194. {
  195.     printf("Mode 0x%x is supported\n",mode);
  196.     printf("  ModeAttributes:\t");
  197.     printbits(modeinfo->ModeAttributes,modeattrbits);
  198.     printf("  WinAAttributes:\t");
  199.     printbits(modeinfo->WinAAttributes,winattrbits);
  200.     printf("  WinBAttributes:\t");
  201.     printbits(modeinfo->WinBAttributes,winattrbits);
  202.     printf("  WinGranularity:\t%d\n",modeinfo->WinGranularity);
  203.     printf("  WinSize:\t\t%d\n",modeinfo->WinSize);
  204.     printf("  WinASegment:\t\t0x%04x\n",modeinfo->WinASegment);
  205.     printf("  WinBSegment:\t\t0x%04x\n",modeinfo->WinBSegment);
  206.     printf("  WinFuncPtr:\t\t\%Fp\n",modeinfo->WinFuncPtr);
  207.     printf("  BytesPerScanLine:\t%d\n",modeinfo->BytesPerScanLine);
  208.     if(!(modeinfo->ModeAttributes & MODE_EXTINFO)) return;
  209.     printf("  XResolution:\t\t%d\n",modeinfo->XResolution);
  210.     printf("  YResolution:\t\t%d\n",modeinfo->YResolution);
  211.     printf("  XCharSize:\t\t%d\n",modeinfo->XCharSize);
  212.     printf("  YCharSize:\t\t%d\n",modeinfo->YCharSize);
  213.     printf("  NumberOfPlanes:\t%d\n",modeinfo->NumberOfPlanes);
  214.     printf("  BitsPerPixel:\t\t%d\n",modeinfo->BitsPerPixel);
  215.     printf("  NumberOfBanks:\t%d\n",modeinfo->NumberOfBanks);
  216.     printf("  MemoryModel:\t\t%d (%s)\n",modeinfo->MemoryModel,getmodelname(modeinfo->MemoryModel));
  217.     printf("  BankSize:\t\t%d\n",modeinfo->BankSize);
  218. }
  219.  
  220. void main(void)
  221. {
  222.     VgaInfoBlock  vgainfo;
  223.     ModeInfoBlock modeinfo;
  224.     short far *modeptr;
  225.     int mode;
  226.  
  227.     if(getinfo(&vgainfo)) {
  228.         printinfo(&vgainfo);
  229.         modeptr = vgainfo.VideoModePtr;
  230.         while((mode = *modeptr++) != (-1)) {
  231.         if(getmodeinfo(mode,&modeinfo)) printmodeinfo(mode,&modeinfo);
  232.         else printf("Mode 0x%x IS NOT SUPPORTED!\n",mode);
  233.         }
  234.     }
  235.     else printf("VESA BIOS extensions not found\n");
  236.     exit(0);
  237. }
  238.  
  239.