home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 4.ddi / C / SCCHGDEV.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  4.7 KB  |  145 lines

  1. /**
  2. *
  3. * Name        scchgdev -- Switch to color or monochrome adapter
  4. *
  5. * Synopsis    ercode = scchgdev(device);
  6. *
  7. *        int ercode      Returned error code:
  8. *                  1 if device absent or if it must first
  9. *                    be reset with SCNEWDEV or SCRESET;
  10. *                  0 if ok.
  11. *        int device      The device to select (MONO or COLOR).
  12. *
  13. * Description    SCCHGDEV selects a video adapter for future I/O without
  14. *        resetting it.  This includes testing for the presence of
  15. *        the proper device, setting the BIOS equipment word,
  16. *        restoring the BIOS video state variables, and setting
  17. *        the global variables b_device and b_curpage to restore
  18. *        the saved current page on the new device.
  19. *
  20. *        If the requested device is not the current device, then
  21. *        information from the b_adap_state table is used to
  22. *        restore the BIOS video state information.  (BSCREEN.H
  23. *        defines b_adap_state.)    This information is only
  24. *        available if the BIOS state variables for the requested
  25. *        device have been previously stored by SCCHGDEV,
  26. *        SCNEWDEV, or SCRESET.  This implies that
  27. *
  28. *            (a) The device which is current when the program is
  29. *            started can be selected at any time by SCCHGDEV,
  30. *            SCNEWDEV, or SCRESET;
  31. *            (b) The other device (if present) must first be
  32. *            reset at least once by SCRESET or SCNEWDEV before
  33. *            it is selected by SCCHGDEV.  Otherwise SCCHGDEV
  34. *            will report an error.
  35. *
  36. * Returns    ercode          Returned error code:
  37. *                  1 if device absent or if it must first
  38. *                    be reset with SCNEWDEV or SCRESET;
  39. *                  0 if ok.
  40. *
  41. * Version    3.0 (C)Copyright Blaise Computing Inc.    1986
  42. *
  43. **/
  44.  
  45. #include <bquery.h>
  46. #include <bscreen.h>
  47.  
  48. extern int b_vidcpy(int,int);          /* Internal (see SCNEWDEV.C).   */
  49.  
  50. #define  FROM_BIOS    0          /* Direction flags for copying  */
  51. #define  TO_BIOS    1          /* BIOS video state variables.  */
  52.  
  53. #define  VIDEO_FIELD  0x0030          /* The bits to be modified in   */
  54.                       /* the BIOS equipment word.     */
  55. #define  MONO_FLAG    0x0030
  56. #define  COLOR_80     0x0020
  57. #define  COLOR_40     0x0010
  58.  
  59. int scchgdev(device)
  60. int device;
  61. {
  62.     int old_mode,old_columns,old_act_page;  /* Previous state          */
  63.     int old_dev;
  64.     int ax,bx,cx,dx,flags;
  65.                       /* Address of BIOS equipment    */
  66.     static ADS    equip_word_ads = {0x0010,0x0040};    /* word.      */
  67.  
  68. #define our_word    ax              /* Our copy of equipment word.  */
  69.     ADS  our_ads;              /* Address of our_word.          */
  70.     int  old_flag,new_flag;          /* Old and new values of video  */
  71.                       /* device bit field.          */
  72.  
  73.     if (device != MONO && device != COLOR)
  74.     return 1;              /* Unknown device.          */
  75.  
  76.     /* Note current state of BIOS.                      */
  77.  
  78.     old_dev = scmode(&old_mode,&old_columns,&old_act_page);
  79.  
  80.     if (device == old_dev)
  81.     return 0;              /* Nothing to do.           */
  82.  
  83.     /* Record current BIOS variables in case we ever need to change   */
  84.     /* back to the old device.                          */
  85.  
  86.     if (b_vidcpy(FROM_BIOS,old_dev))
  87.     return 1;
  88.  
  89.     if (!b_adap_state[device].known)  /* Abort if we've never         */
  90.     return 1;              /* recorded the BIOS state      */
  91.                       /* variables for new device.    */
  92.  
  93.     scequip();                  /* Sense which hardware is      */
  94.                       /* present.              */
  95.  
  96.     switch (device)
  97.     {
  98.     case COLOR:
  99.         if (   b_cga != COLOR && b_pcmodel != IBM_JR
  100.         && b_ega != COLOR && b_pgc     != COLOR)
  101.         return 1;          /* Color/Graphics Adapter       */
  102.                       /* functions are not available. */
  103.         new_flag = COLOR_80;
  104.         break;
  105.     case MONO:
  106.         if (b_mdpa != MONO && b_ega != MONO)
  107.         return 1;          /* Monochrome Adapter functions */
  108.                       /* are not available.          */
  109.         new_flag = MONO_FLAG;
  110.         break;
  111.     }
  112.  
  113.     b_device = device;
  114.  
  115.     /* The BIOS keeps track of the color vs. monochrome distinction   */
  116.     /* by two bits in the equipment word, so we must poke those bits  */
  117.     /* to signal the change in device.                      */
  118.  
  119.     bios(17,&ax,&bx,&cx,&dx,&flags);  /* Retrieve equipment word.     */
  120.  
  121.     old_flag = (our_word & VIDEO_FIELD);
  122.     if (new_flag != old_flag          /* There is a change.          */
  123.         && (old_flag != COLOR_40 || new_flag != COLOR_80))
  124.                       /* (Skip the change if 40-col   */
  125.                       /*   mode is set and we're      */
  126.                       /*   setting color.)          */
  127.     {
  128.     our_word = (our_word & ~VIDEO_FIELD) | new_flag;
  129.  
  130.                       /* Install modified equipment   */
  131.                       /* word.                  */
  132.     utabsptr((char *) &our_word,&our_ads);
  133.     utslmove(&our_ads,&equip_word_ads,1);       /* Lower byte only */
  134.     }
  135.  
  136.     /* Restore BIOS variables which were in effect when we last quit  */
  137.     /* this device.                              */
  138.  
  139.     b_vidcpy(TO_BIOS,b_device);
  140.  
  141.     scpage(b_adap_state[device].curpage);
  142.  
  143.     return 0;
  144. }
  145.