home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / SCMODE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  3.1 KB  |  110 lines

  1. /**
  2. *
  3. * Name        scmode -- Return the screen video mode
  4. *
  5. * Synopsis    adapter = scmode(pmode,pcolumns,papage);
  6. *
  7. *        int adapter      Returned adapter status.
  8. *                  1 is returned for the Color/Graphics
  9. *                   Adapter (or if another adapter is
  10. *                   emulating the CGA),
  11. *                  or 0 for the Monochrome Adapter (or if
  12. *                   another adapter is emulating
  13. *                   the Monochrome Adapter).
  14. *        int *pmode      Returned screen mode.
  15. *        int *pcolumns      Returned number of columns on screen.
  16. *        int *papage      Returned active page.
  17. *
  18. * Description    SCMODE returns the current video setting of the screen
  19. *        display.  The functional value indicates which adapter
  20. *        is used.  The integer pointers are used to store values
  21. *        describing the screen.
  22. *
  23. *        See the list of possible modes in SCNEWDEV.C.
  24. *
  25. *        This function also sets the global variables b_device,
  26. *        b_vga, and b_mcga (declared in BSCREENS.H) to SC_COLOR
  27. *        (1) or SC_MONO (0) depending on which device is in use.
  28. *
  29. * Returns    adapter       Adapter used
  30. *        b_device      Adapter used
  31. *        b_vga          b_device (if VGA is current device)
  32. *        b_mcga          b_device (if MCGA is current device)
  33. *        *pmode          Screen mode
  34. *        *pcolumns      Number of columns on screen
  35. *        *papage       Active display page
  36. *
  37. * Version    6.00 (C)Copyright Blaise Computing Inc.  1983,1987,1989
  38. *
  39. **/
  40.  
  41. #include <dos.h>
  42.  
  43. #include <bscreens.h>
  44.  
  45. int b_device = SC_DONT_KNOW;       /* Current adapter:    SC_DONT_KNOW, */
  46.                    /*    SC_MONO, or SC_COLOR          */
  47.  
  48. #define  VIDEO_FIELD  0x0030          /* The bits to be examined in   */
  49.                       /* the BIOS equipment flag.     */
  50. #define  MONO_FLAG    0x0030
  51. #define  COLOR_80     0x0020
  52. #define  COLOR_40     0x0010
  53.  
  54. int scmode(pmode,pcolumns,papage)
  55. int *pmode,*pcolumns,*papage;
  56. {
  57.     union REGS inregs,outregs;          /* Registers for BIOS calls     */
  58.  
  59.     inregs.h.ah = 15;
  60.     int86(SC_BIOS_INT,&inregs,&outregs);
  61.     *pmode    = (outregs.h.al & 0x7f); /* Discard bit 7 (sign bit)    */
  62.     *pcolumns =  outregs.h.ah;           /*   of mode.              */
  63.     *papage   =  outregs.h.bh;
  64.  
  65.     int86(17,&inregs,&outregs);       /* Equipment setting determines */
  66.                       /* which adapter is used.       */
  67.  
  68.     switch (outregs.x.ax & VIDEO_FIELD)
  69.     {
  70.     case MONO_FLAG:
  71.         b_device = SC_MONO;
  72.         break;
  73.     case COLOR_80:
  74.     case COLOR_40:
  75.     default:              /* Impossible bit settings.     */
  76.         b_device = SC_COLOR;
  77.         break;
  78.     }
  79.  
  80.                       /* Check VGA/MCGA state.          */
  81.     inregs.x.ax = 0x1a00;
  82.     int86(SC_BIOS_INT,&inregs,&outregs);
  83.     if (outregs.h.al == 0x1a)
  84.     {                      /* Function 0x1a is supported.  */
  85.     switch (outregs.h.bl)          /* Handle active device.          */
  86.     {
  87.         case 0x07:
  88.         case 0x08:    b_vga  = b_device;   break;
  89.  
  90.         case 0x0b:
  91.         case 0x0c:    b_mcga = b_device;   break;
  92.     }
  93.     switch (outregs.h.bh)          /* Handle alternate device.     */
  94.     {
  95.         case 0x07:
  96.         case 0x08:
  97.         b_vga  = (b_device == SC_MONO ? SC_COLOR : SC_MONO);
  98.         break;
  99.  
  100.         case 0x0b:
  101.         case 0x0c:
  102.         if (b_device == SC_MONO)
  103.             b_mcga = SC_COLOR;
  104.         break;
  105.     }
  106.     }
  107.  
  108.     return b_device;
  109. }
  110.