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

  1. /**
  2. *
  3. * Name        SCSETVID - Set the state of the video adapter.
  4. *
  5. * Synopsis    error = scsetvid(pstate);
  6. *
  7. *        int error        Returned error code.
  8. *        ADAP_STATE *pstate  Structure containing the video
  9. *                    state.
  10. *
  11. * Description    This function uses the values contained in state
  12. *        to set the state of the video adapter. The information
  13. *        used to set the state includes which adapter will be
  14. *        made current, the mode of the adapter, the active
  15. *        (displayed) page, the number of rows and columns on
  16. *        the screen, and the size of the cursor.  Note that
  17. *        it may be necessary to call scnewdev() to set the
  18. *        current video adapter and/or mode; if this is the case,
  19. *        all display pages on the requested adapter will be
  20. *        cleared.
  21. *
  22. * Returns    int error   -1 if there was an error (i.e., if the
  23. *                requested mode is invalid), 0 if no errors
  24. *                occur.
  25. *
  26. * Version    6.00 (C)Copyright Blaise Computing Inc.  1989
  27. *
  28. **/
  29. #include <bscreens.h>
  30.  
  31. int scsetvid(pstate)
  32. const ADAP_STATE *pstate;
  33. {
  34.     int      current_adapter, requested_adapter;
  35.     int      current_mode;
  36.     int      current_act_page;
  37.     int      current_rows, current_columns;
  38.     int      current_curs_off;
  39.     CUR_TYPE current_curs_size;
  40.     int row, column;
  41.  
  42.     current_adapter = scmode(¤t_mode, ¤t_columns,
  43.                  ¤t_act_page);
  44.  
  45.     requested_adapter = ((pstate->mode == 7) || (pstate->mode == 15))
  46.             ? SC_MONO : SC_COLOR;
  47.  
  48.     /* First, check to see if we need to switch adapters.  If so, try */
  49.     /* to switch without calling scnewdev().  Having switched, call   */
  50.     /* scmode() again to record the state of the new device.          */
  51.  
  52.     if (current_adapter != requested_adapter)
  53.     {
  54.     if (scchgdev(requested_adapter) != 0)
  55.         if (scnewdev(pstate->mode, pstate->rows) != pstate->mode)
  56.         return(-1);
  57.     current_adapter = scmode(¤t_mode, ¤t_columns,
  58.                  ¤t_act_page);
  59.     }
  60.  
  61.     current_rows = scrows();
  62.     current_curs_off = sccurst(&row, &column, ¤t_curs_size.high,
  63.                    ¤t_curs_size.low);
  64.  
  65.     /* Check to see whether we need to call scnewdev() to switch      */
  66.     /* modes or rows.                              */
  67.  
  68.     if ((current_mode != pstate->mode) ||
  69.     (current_rows != pstate->rows) ||
  70.     (current_columns != pstate->columns))
  71.     {
  72.     if (scnewdev(pstate->mode, pstate->rows) != pstate->mode)
  73.         return(-1);
  74.     }
  75.  
  76.     /* Now restore the active (displayed) page and the current page   */
  77.     /* for this device.                           */
  78.  
  79.     if (scapage(pstate->act_page) != pstate->act_page)
  80.     return(-1);
  81.     if (scpage(pstate->cur_page) != pstate->cur_page)
  82.     return(-1);
  83.  
  84.     /* Finally, check to see if we need to fix the cursor.          */
  85.  
  86.     if ((current_curs_off != pstate->curs_off) ||
  87.     (current_curs_size.high != pstate->curs_size.high) ||
  88.     (current_curs_size.low != pstate->curs_size.low))
  89.     {
  90.     if (scpgcur(pstate->curs_off, pstate->curs_size.high,
  91.             pstate->curs_size.low, CUR_NO_ADJUST) !=
  92.         pstate->curs_off)
  93.     {
  94.         return(-1);
  95.     }
  96.     }
  97.  
  98.     return(0);
  99. }
  100.