home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name scchgdev -- Switch to color or monochrome adapter
- *
- * Synopsis ercode = scchgdev(device);
- *
- * int ercode Returned error code:
- * 1 if device absent or if it must first
- * be reset with SCNEWDEV or SCRESET;
- * 0 if ok.
- * int device The device to select (MONO or COLOR).
- *
- * Description SCCHGDEV selects a video adapter for future I/O without
- * resetting it. This includes testing for the presence of
- * the proper device, setting the BIOS equipment word,
- * restoring the BIOS video state variables, and setting
- * the global variables b_device and b_curpage to restore
- * the saved current page on the new device.
- *
- * If the requested device is not the current device, then
- * information from the b_adap_state table is used to
- * restore the BIOS video state information. (BSCREEN.H
- * defines b_adap_state.) This information is only
- * available if the BIOS state variables for the requested
- * device have been previously stored by SCCHGDEV,
- * SCNEWDEV, or SCRESET. This implies that
- *
- * (a) The device which is current when the program is
- * started can be selected at any time by SCCHGDEV,
- * SCNEWDEV, or SCRESET;
- * (b) The other device (if present) must first be
- * reset at least once by SCRESET or SCNEWDEV before
- * it is selected by SCCHGDEV. Otherwise SCCHGDEV
- * will report an error.
- *
- * Returns ercode Returned error code:
- * 1 if device absent or if it must first
- * be reset with SCNEWDEV or SCRESET;
- * 0 if ok.
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1986
- *
- **/
-
- #include <bquery.h>
- #include <bscreen.h>
-
- extern int b_vidcpy(int,int); /* Internal (see SCNEWDEV.C). */
-
- #define FROM_BIOS 0 /* Direction flags for copying */
- #define TO_BIOS 1 /* BIOS video state variables. */
-
- #define VIDEO_FIELD 0x0030 /* The bits to be modified in */
- /* the BIOS equipment word. */
- #define MONO_FLAG 0x0030
- #define COLOR_80 0x0020
- #define COLOR_40 0x0010
-
- int scchgdev(device)
- int device;
- {
- int old_mode,old_columns,old_act_page; /* Previous state */
- int old_dev;
- int ax,bx,cx,dx,flags;
- /* Address of BIOS equipment */
- static ADS equip_word_ads = {0x0010,0x0040}; /* word. */
-
- #define our_word ax /* Our copy of equipment word. */
- ADS our_ads; /* Address of our_word. */
- int old_flag,new_flag; /* Old and new values of video */
- /* device bit field. */
-
- if (device != MONO && device != COLOR)
- return 1; /* Unknown device. */
-
- /* Note current state of BIOS. */
-
- old_dev = scmode(&old_mode,&old_columns,&old_act_page);
-
- if (device == old_dev)
- return 0; /* Nothing to do. */
-
- /* Record current BIOS variables in case we ever need to change */
- /* back to the old device. */
-
- if (b_vidcpy(FROM_BIOS,old_dev))
- return 1;
-
- if (!b_adap_state[device].known) /* Abort if we've never */
- return 1; /* recorded the BIOS state */
- /* variables for new device. */
-
- scequip(); /* Sense which hardware is */
- /* present. */
-
- switch (device)
- {
- case COLOR:
- if ( b_cga != COLOR && b_pcmodel != IBM_JR
- && b_ega != COLOR && b_pgc != COLOR)
- return 1; /* Color/Graphics Adapter */
- /* functions are not available. */
- new_flag = COLOR_80;
- break;
- case MONO:
- if (b_mdpa != MONO && b_ega != MONO)
- return 1; /* Monochrome Adapter functions */
- /* are not available. */
- new_flag = MONO_FLAG;
- break;
- }
-
- b_device = device;
-
- /* The BIOS keeps track of the color vs. monochrome distinction */
- /* by two bits in the equipment word, so we must poke those bits */
- /* to signal the change in device. */
-
- bios(17,&ax,&bx,&cx,&dx,&flags); /* Retrieve equipment word. */
-
- old_flag = (our_word & VIDEO_FIELD);
- if (new_flag != old_flag /* There is a change. */
- && (old_flag != COLOR_40 || new_flag != COLOR_80))
- /* (Skip the change if 40-col */
- /* mode is set and we're */
- /* setting color.) */
- {
- our_word = (our_word & ~VIDEO_FIELD) | new_flag;
-
- /* Install modified equipment */
- /* word. */
- utabsptr((char *) &our_word,&our_ads);
- utslmove(&our_ads,&equip_word_ads,1); /* Lower byte only */
- }
-
- /* Restore BIOS variables which were in effect when we last quit */
- /* this device. */
-
- b_vidcpy(TO_BIOS,b_device);
-
- scpage(b_adap_state[device].curpage);
-
- return 0;
- }