home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 328_02 / wgetmon.c < prev    next >
C/C++ Source or Header  |  1991-04-02  |  3KB  |  186 lines

  1. /* wdetect_monitor ()
  2.  *     Detect the type of monitor,
  3.  *        store the info in wmonitor
  4.  *              store amount of EGA ram in wegasize  ( 0 for <256, 1=256k);
  5.  *
  6.  *
  7.  */
  8. #include  "wscreen.h"
  9. #include  "wsys.h"
  10.  
  11.  
  12. #include <dos.h>
  13.  
  14.  
  15. /* return  codes from interrupt 0x10, function 0x1A subfunction 0
  16.  *    BL = active monitor, BH = inactive mon.
  17.  */
  18. #define FOUND_UNRECOGNIZABLE  0xFF
  19. #define FOUND_NO_MONITOR    0
  20. #define FOUND_MDA            1
  21. #define FOUND_CGA            2
  22. #define FOUND_reserved_1    3
  23. #define FOUND_EGA            4
  24. #define FOUND_EGA_mono        5
  25. #define FOUND_Profess        6
  26. #define FOUND_VGA_mono        7
  27. #define FOUND_VGA             8
  28. #define FOUND_reserved_2    9
  29. #define FOUND_MCGA_1        0x0A
  30. #define FOUND_MCGA_2        0x0B
  31. #define FOUND_MCGA_3        0x0C
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. void      wgetmon (void)
  39.     {
  40.  
  41.  
  42.     PSEUDOREGS
  43.  
  44.  
  45.     unsigned char adapter;
  46.     int trials;
  47.     int active;
  48.     unsigned char egaram;
  49.     unsigned char egadata;
  50.  
  51.  
  52.     /* ROM BIOS equipment list - second word */
  53.     adapter = *( (unsigned char far *) 0x00000411L) & 0x30;
  54.  
  55.     if (adapter == 0x01)    /* 40 column monitor */
  56.         {
  57.         perror ("Unsupported monitor");
  58.         wmonitor = 'X';
  59.         exit (99);
  60.         }
  61.     /* adapter = 2 for 80x25 text color, adapter = 3 for 80x25 mono */
  62.  
  63.  
  64.     egadata = *( (unsigned char far *)0x00000487L );
  65.  
  66.  
  67.     /* attempt to read video info
  68.      * USE A VGA only call.( although some newer BIOS return values
  69.      *        even if they're hercules or EGA. )
  70.      */
  71.     _BX = 0;
  72.     _AH = 0x1A;    /* get video info subservice for PS/2, 386, newer AT. */
  73.     _AL = 0;    /* 0=get, 1 = set */
  74.  
  75.     INTERRUPT (0x10);
  76.  
  77.     active   = _BL;
  78.     /* the inactive monitor ID is in  _BH, if you should ever switch */
  79.     active &= 0x0f;    /* take low order half */
  80.  
  81.     if ( active == 0  || active == 0x0f )
  82.         {
  83.         /* BIOS did not recognize the call - could be an old EGA or CGA or H.
  84.          */
  85.         if ( egadata & 0x80 )        /* it's an EGA */    
  86.             {
  87.             active = FOUND_EGA;
  88.             }
  89.         else
  90.         /* not VGA, and not EGA,... */
  91.         if ( adapter == 2 )
  92.             {
  93.             /* not EGA, VGA, but is color... */
  94.             active = FOUND_CGA;    
  95.             }
  96.         else 
  97.         /* not a color monitor ... */
  98.         active = FOUND_MDA;    
  99.         
  100.         }
  101.         
  102.         
  103.         
  104.     
  105.     
  106.     
  107.     switch (active)
  108.         {
  109.     case (FOUND_VGA):
  110.     case (FOUND_VGA_mono):
  111.         wmonitor = 'V';
  112.         break;
  113.  
  114.     case (FOUND_EGA):
  115.         wmonitor = 'E';
  116.  
  117.         egaram= egadata & 0x60 ;
  118.  
  119.         if (egaram == 0x60)
  120.             {
  121.             wega256 = 1;    /* 256 k avail on-board */
  122.             }
  123.         else
  124.         if (egaram == 00)
  125.             {
  126.             /* only 64k on this pathetic board --
  127.              * no hi-res graphics 
  128.              */
  129.             wmonitor = 'C';    /* disables graphics modes */
  130.             }
  131.         else
  132.             {
  133.             wega256 = 0;    /* less than 256 k */
  134.             }
  135.  
  136.  
  137.         break;
  138.     case (FOUND_MDA):
  139.         wmonitor = 'M';
  140.  
  141.         /* in text mode, BIOS thinks hercules is an MDA
  142.          */
  143.  
  144.  
  145.         /* if the vertical retrace bit ever goes hi,
  146.          * this is a hercules card. MGA keeps this low always.
  147.          */
  148.         trials = 10000;
  149.         while ( --trials )        /* NOTE loop contains break statement */
  150.             {
  151.             if ( inp(0x3BA)  & 0x80 )
  152.                 {
  153.                 wmonitor = 'H';
  154.                 break;                /* BREAK from while loop */
  155.                 }
  156.             }
  157.  
  158.  
  159.         break;        /* break from switch */
  160.         
  161.     case (FOUND_CGA):
  162.     case (FOUND_MCGA_1):
  163.     case (FOUND_MCGA_2):
  164.     case (FOUND_MCGA_3):
  165.         wmonitor = 'C';
  166.         break;
  167.  
  168.     case (FOUND_reserved_1):
  169.     case (FOUND_reserved_2):
  170.     case (FOUND_Profess):
  171.         perror ("Unsupported monitor");
  172.         wmonitor = 'X';
  173.         exit(99);
  174.  
  175.  
  176.         }    /* end switch */
  177.  
  178.     return;
  179.  
  180.  
  181.  
  182.     /* wgetmon */
  183.     }
  184.  
  185.  
  186.