home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name SCSETVID - Set the state of the video adapter.
- *
- * Synopsis error = scsetvid(pstate);
- *
- * int error Returned error code.
- * ADAP_STATE *pstate Structure containing the video
- * state.
- *
- * Description This function uses the values contained in state
- * to set the state of the video adapter. The information
- * used to set the state includes which adapter will be
- * made current, the mode of the adapter, the active
- * (displayed) page, the number of rows and columns on
- * the screen, and the size of the cursor. Note that
- * it may be necessary to call scnewdev() to set the
- * current video adapter and/or mode; if this is the case,
- * all display pages on the requested adapter will be
- * cleared.
- *
- * Returns int error -1 if there was an error (i.e., if the
- * requested mode is invalid), 0 if no errors
- * occur.
- *
- * Version 6.00 (C)Copyright Blaise Computing Inc. 1989
- *
- **/
- #include <bscreens.h>
-
- int scsetvid(pstate)
- const ADAP_STATE *pstate;
- {
- int current_adapter, requested_adapter;
- int current_mode;
- int current_act_page;
- int current_rows, current_columns;
- int current_curs_off;
- CUR_TYPE current_curs_size;
- int row, column;
-
- current_adapter = scmode(¤t_mode, ¤t_columns,
- ¤t_act_page);
-
- requested_adapter = ((pstate->mode == 7) || (pstate->mode == 15))
- ? SC_MONO : SC_COLOR;
-
- /* First, check to see if we need to switch adapters. If so, try */
- /* to switch without calling scnewdev(). Having switched, call */
- /* scmode() again to record the state of the new device. */
-
- if (current_adapter != requested_adapter)
- {
- if (scchgdev(requested_adapter) != 0)
- if (scnewdev(pstate->mode, pstate->rows) != pstate->mode)
- return(-1);
- current_adapter = scmode(¤t_mode, ¤t_columns,
- ¤t_act_page);
- }
-
- current_rows = scrows();
- current_curs_off = sccurst(&row, &column, ¤t_curs_size.high,
- ¤t_curs_size.low);
-
- /* Check to see whether we need to call scnewdev() to switch */
- /* modes or rows. */
-
- if ((current_mode != pstate->mode) ||
- (current_rows != pstate->rows) ||
- (current_columns != pstate->columns))
- {
- if (scnewdev(pstate->mode, pstate->rows) != pstate->mode)
- return(-1);
- }
-
- /* Now restore the active (displayed) page and the current page */
- /* for this device. */
-
- if (scapage(pstate->act_page) != pstate->act_page)
- return(-1);
- if (scpage(pstate->cur_page) != pstate->cur_page)
- return(-1);
-
- /* Finally, check to see if we need to fix the cursor. */
-
- if ((current_curs_off != pstate->curs_off) ||
- (current_curs_size.high != pstate->curs_size.high) ||
- (current_curs_size.low != pstate->curs_size.low))
- {
- if (scpgcur(pstate->curs_off, pstate->curs_size.high,
- pstate->curs_size.low, CUR_NO_ADJUST) !=
- pstate->curs_off)
- {
- return(-1);
- }
- }
-
- return(0);
- }