home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT12 / CVIDEO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-28  |  5.1 KB  |  171 lines

  1.  
  2. /***************************************************************
  3. *                                                              *
  4. *   Determining the type of video adapter used                 *
  5. *                                                              *
  6. *   Author: A.I.Sopin,  Voronezh, 1992                         *
  7. *                                                              *
  8. *   The adapter type is returned as character string           *
  9. *   char VTYPE [4] and can have the following values:          *
  10. *                                                              *
  11. *   "MDA", "CGA", "EGA", "MCGA" or "VGA"                       *
  12. *                                                              *
  13. ****************************************************************/
  14.  
  15. #include <dos.h>
  16.  
  17. int EGACGA ();
  18.  
  19. int MCGAVGA ();
  20.  
  21. void  CVIDEO (char *VTYPE)
  22.  
  23. {
  24.  
  25. union  REGS  regs;
  26.  
  27. char  AL, BL;
  28.  
  29.       regs.x.ax = 0x1a00;        /*  get current mode                     */
  30.  
  31.       int86 (0x10, ®s, ®s);
  32.  
  33.       AL = regs.h.al;
  34.  
  35.       BL = regs.h.bl;
  36.  
  37. /*-------------------------------------------------------------------------*/
  38.  
  39. /*  Check for adapters other than MCGA or VGA                              */
  40.  
  41.     strcpy (VTYPE, "MDA ");
  42.  
  43.     if (AL != 0x1a)              /*  not VGA  or  not MCGA ?               */
  44.       {
  45.  
  46. /*  Check for adapters MDA, CGA, EGA                                       */
  47.  
  48.        if (EGACGA () == 0)  return;
  49.  
  50.         if (EGACGA () == 1)
  51.           {
  52.             strcpy (VTYPE, "CGA ");  return;
  53.           }
  54.  
  55.         if (EGACGA () == 3)
  56.           {
  57.             strcpy (VTYPE, "EGA ");  return;
  58.           }
  59.       }
  60.  
  61. /*-------------------------------------------------------------------------*/
  62.  
  63. /*  Check for adapters MDA, VGA or MCGA                                    */
  64.  
  65.     else      /* AL == 0x1a                                                */
  66.  
  67.       {
  68.          if (BL < 2)  return;               /*  MDA                        */
  69.  
  70.          if (BL == 2)                       /*  CGA                        */ 
  71.           {
  72.             strcpy (VTYPE, "CGA ");  return;
  73.           }
  74.  
  75.          if (BL <= 5)
  76.            {
  77.             if (EGACGA () == 0)  return;    /*  MDA                        */
  78.  
  79.             if (EGACGA () == 1)             /*  CGA                        */
  80.               {
  81.                 strcpy (VTYPE, "CGA ");  return;
  82.               }
  83.  
  84.             if (EGACGA () == 3)            /*  EGA                         */ 
  85.               {
  86.                 strcpy (VTYPE, "EGA ");  return;
  87.               }
  88.            }
  89.  
  90.          else
  91.            {
  92.  
  93.             if (MCGAVGA (BL) == 2)         /*  MCGA                        */
  94.               {
  95.                 strcpy (VTYPE, "MCGA");  return;
  96.               }
  97.  
  98.             if (MCGAVGA (BL) == 4)        /*  VGA                          */
  99.               {
  100.                 strcpy (VTYPE, "VGA ");  return;
  101.               }
  102.            }
  103.  
  104.       }
  105.  
  106. }  /*  End  CVIDEO  */
  107.  
  108. /***************************************************************
  109. *                                                              *
  110. *   Determining whether adapters MCGA or VGA installed         *
  111. *                                                              *
  112. *   Returned value:                                            *
  113. *                                                              *
  114. *   2  - adapter is MCGA                                       *
  115. *                                                              *
  116. *   4  - adapter is VGA                                        *
  117. *                                                              *
  118. ****************************************************************/
  119.  
  120. int  MCGAVGA (char  BL)
  121.  
  122. {
  123.      if (BL >  8)    return (2);
  124.  
  125.      else   return (4);
  126. }
  127.  
  128. /***************************************************************
  129. *                                                              *
  130. *   Determining whether adapters EGA or CGA installed          *
  131. *                                                              *
  132. *   Returned value:                                            *
  133. *                                                              *
  134. *   0  - adapter is MDA                                        *
  135. *                                                              *
  136. *   1  - adapter is CGA                                        *
  137. *                                                              *
  138. *   3  - adapter is EGA                                        *
  139. *                                                              *
  140. ****************************************************************/
  141.  
  142. int  EGACGA (void)
  143.  
  144. {
  145.  
  146. union  REGS  regs;
  147.  
  148. int  AL;
  149.  
  150.       regs.h.ah = 0x12;
  151.  
  152.       regs.h.bl = 0x10;
  153.  
  154.       regs.x.cx = 0;
  155.  
  156.       int86 (0x10, ®s, ®s);
  157.  
  158.       if (regs.x.cx != 0)  return (3);
  159.  
  160.       else
  161.           {
  162.               int86 (0x11, ®s, ®s);
  163.  
  164.               AL = regs.h.al & 0x30;
  165.  
  166.               if (AL == 0x30)  return (0);    /*  MDA  */
  167.  
  168.               else   return (1);
  169.           }
  170.  
  171. }