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;
- * 0 if ok.
- * int device The device to select (SC_MONO or
- * SC_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 state of 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. (BSCREENS.H
- * declares b_adap_state.) This information is available
- * only if the BIOS state variables for the requested
- * device have been previously stored by SCCHGDEV or
- * SCNEWDEV. This implies that
- *
- * (a) The device that is current when the program is
- * started can be selected at any time by SCCHGDEV
- * or SCNEWDEV.
- * (b) The other device (if present) must first be
- * reset at least once by 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;
- * 0 if ok.
- * b_device Adapter used (SC_COLOR or SC_MONO).
- *
- * Version 6.00 (C)Copyright Blaise Computing Inc. 1986-1989
- *
- **/
-
- #include <dos.h>
-
- #include <bscreens.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
-
- /* Address of BIOS equipment word. */
- #define EQUIP_WORD_LOC (uttofar(0x0040,0x0010,unsigned int))
-
- int scchgdev(device)
- int device;
- {
- int old_mode,old_columns,old_act_page; /* Previous state */
- int old_dev;
- union REGS regs;
-
- #define our_word (regs.x.ax) /* Our copy of equipment word. */
-
- int old_flag,new_flag; /* Old and new values of video */
- /* device bit field. */
-
- if (device != SC_MONO && device != SC_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 SC_COLOR:
- if ( b_cga != SC_COLOR && b_pcmodel != IBM_JR
- && b_ega != SC_COLOR && b_pgc != SC_COLOR
- && b_vga == SC_ABSENT && b_mcga == SC_ABSENT)
- return 1; /* Color/Graphics Adapter */
- /* functions are not available. */
- new_flag = COLOR_80;
- break;
- case SC_MONO:
- if ( b_mdpa != SC_MONO
- && b_ega != SC_MONO
- && b_vga == SC_ABSENT)
- return 1; /* Monochrome Adapter functions */
- /* are not available. */
- new_flag = MONO_FLAG;
- break;
- }
-
- b_device = device;
-
- /* If we are switching VGA from color to monochrome or vice */
- /* versa, note the change in our global variables. */
-
- if ( device != b_mdpa && device != b_cga && device != b_ega
- && device != b_pgc)
- {
- if (b_vga == old_dev)
- b_vga = 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. */
-
- int86(17,®s,®s); /* 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.) */
- {
- /* Install modified equipment */
- /* word. */
- utpokeb(EQUIP_WORD_LOC,
- (unsigned char) ((our_word & ~VIDEO_FIELD) | new_flag));
- }
-
- /* Restore BIOS variables that were in effect when we last quit */
- /* this device. */
-
- b_vidcpy(TO_BIOS,b_device);
-
- scpage(b_adap_state[device].curpage); /* Restore current page. */
-
- return 0;
- }