home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name scequip -- Obtain video hardware environment & settings
- *
- * Synopsis model = scequip();
- *
- * char model IBM Model code:
- * IBM_PC (0xff) if IBM PC
- * IBM_XT (0xfe) if IBM PC-XT
- * or Portable PC
- * IBM_JR (0xfd) if IBM PCjr
- * IBM_AT (0xfc) if IBM PC-AT
- * IBM_CV (0xf9) if IBM PC Convertible
- * IBM_30 (0xfa) if IBM PS/2 model 30
- * IBM_50 (0xfc) if IBM PS/2 models 50 or 60
- * IBM_80 (0xf8) if IBM PS/2 model 80
- *
- * Description This function obtains information about the video
- * adapters installed on this machine and their options.
- * All of the results are available in global variables
- * declared in BSCREENS.H, except for b_pcmodel, which is
- * declared in BUTIL.H.
- *
- * This function should need to be called only once during
- * the execution of a program. (If it is called again, it
- * will examine the b_know_hw flag and skip most of its
- * operations to save time.)
- *
- * Use SCMODE to obtain video information that might be
- * altered under software control (such as video mode or
- * number of columns). Use SCNEWDEV to switch to a given
- * video adapter.
- *
- * Results model IBM Model code:
- * b_pcmodel IBM_PC (0xff) if IBM PC
- * IBM_XT (0xfe) if IBM PC-XT
- * or Portable PC
- * IBM_JR (0xfd) if IBM PCjr
- * IBM_AT (0xfc) if IBM PC-AT
- * IBM_CV (0xf9) if IBM PC Convertible
- * (Also sets various global variables in BSCREENS.H)
- *
- * Version 6.00 (C)Copyright Blaise Computing Inc. 1986-1989
- *
- **/
-
- #include <conio.h>
- #include <dos.h>
-
- #include <bscreens.h>
-
- int b_know_hw = 0; /* Flag stating whether we have yet */
- /* run SCEQUIP: 0 if no, 1 if yes */
-
- int b_mdpa = SC_DONT_KNOW;/* Monochrome Display & Printer Adapter */
- /* SC_DONT_KNOW, SC_ABSENT, or SC_MONO */
- /* (SC_MONO if Hercules graphics adapter.)*/
- /* */
- int b_cga = SC_DONT_KNOW; /* Color/Graphics Monitor Adapter */
- /* SC_DONT_KNOW, SC_ABSENT, or SC_COLOR */
- /* */
- int b_ega = SC_DONT_KNOW; /* Enhanced Graphics Adapter: SC_DONT_KNOW, */
- /* SC_ABSENT, SC_MONO or SC_COLOR */
- /* */
- int b_mcga = SC_DONT_KNOW;/* Multicolor Graphics Array: SC_DONT_KNOW, */
- /* SC_ABSENT, or SC_COLOR */
- /* */
- int b_vga = SC_DONT_KNOW; /* Video Graphics Array: SC_DONT_KNOW, */
- /* SC_ABSENT, SC_MONO or SC_COLOR */
- /* */
- int b_herc = SC_DONT_KNOW;/* Hercules monochrome graphics adapter */
- /* SC_DONT_KNOW, SC_ABSENT, or SC_MONO */
- /* */
- int b_pgc = SC_DONT_KNOW; /* Professional Graphics Controller: */
- /* SC_DONT_KNOW, SC_ABSENT, SC_COLOR, or */
- /* SC_HIFUNC */
-
- int b_mem_ega = 0; /* Amount of memory installed on EGA in */
- /* 1024-byte units: 64, 128, 192, 256 */
-
- unsigned b_sw_ega = 0x0ffff; /* Switch settings on EGA */
- /* Low-order bit set means SW1 off, etc.*/
- /* (Bit value 1 implies that */
- /* corresponding switch is off.) */
-
- static volatile int waiter; /* Variable to assign to to wait for */
- /* CGA and PGC to stabilize when using */
- /* fast processors. */
-
- #define PGC_SEG 0xc600 /* Segment of memory-mapped PGC ports. */
- /* PGC port for presence test. */
- #define PGC_PRES_BYTE (uttofar(PGC_SEG,0x03db,unsigned char))
- #define PGC_INDEX 0x03d4 /* Offset of PGC/CGA index port */
- #define PGC_IND_BYTE (uttofar(PGC_SEG,PGC_INDEX,unsigned char))
-
- #define WAIT \
- { \
- waiter = 0; \
- waiter += 1; \
- }
-
- static void note_adapter(unsigned char,int); /* Internal function */
- static int adap_present(int); /* Internal function */
- static int pgc_present(void); /* Internal function */
- static int pgc_emulating(void); /* Internal function */
- static int herc(void); /* Internal function */
-
- /* Internal variables containing interim knowledge of adapter */
- /* state and modes. */
-
- #define _DONT_KNOW (-1)
- #define _ABSENT 0
- #define _ACTIVE 1
- #define _ALTERNATE 2
- #define _PRESENT 3
-
- static int pgc_state = _DONT_KNOW;
- static int vga_state;
-
-
- char scequip()
- {
- union REGS inregs,outregs; /* Registers for BIOS calls */
- unsigned color_or_mono,mem;
- int pgc_emul_tested;
- int mode,columns,act_page;
-
- if (b_know_hw)
- {
- scmode(&mode,&columns,&act_page); /* Check VGA state. */
- return b_pcmodel; /* No need to do this work again */
- }
-
- if (utmodel() == IBM_JR) /* Fetch & save model code. */
- { /* This is a PCjr */
- b_mdpa = SC_ABSENT;
- b_cga = SC_ABSENT;
- b_ega = SC_ABSENT;
- b_pgc = SC_ABSENT;
- b_vga = SC_ABSENT;
- b_mcga = SC_ABSENT;
- b_herc = SC_ABSENT;
- }
- else if (b_pcmodel == IBM_CV)
- { /* IBM PC Convertible acts like */
- b_mdpa = SC_MONO; /* both MDPA & CGA. */
- b_cga = SC_COLOR;
- b_ega = SC_ABSENT;
- b_pgc = SC_ABSENT;
- b_vga = SC_ABSENT;
- b_mcga = SC_ABSENT;
- b_herc = SC_ABSENT;
- }
- else
- { /* Neither PCjr nor Convertible */
-
- /* First test for VGA or MCGA: attempt BIOS video function 0x1a. */
-
- inregs.x.ax = 0x1a00;
- int86(16,&inregs,&outregs);
- if (outregs.h.al == 0x1a)
- {
- b_mdpa = SC_ABSENT; /* Flag these devices as absent; */
- b_cga = SC_ABSENT; /* note_adapter will change the */
- b_ega = SC_ABSENT; /* value for devices actually found. */
- b_mcga = SC_ABSENT;
- b_vga = SC_ABSENT;
- b_pgc = SC_ABSENT;
- b_mcga = SC_ABSENT;
- vga_state = _ABSENT;
-
- /* Record the active adapter. */
- note_adapter(outregs.h.bl,_ACTIVE);
- /* Record the other adapter. */
- note_adapter(outregs.h.bh,_ALTERNATE);
-
- if (vga_state == _ABSENT)
- b_vga = SC_ABSENT;
- else
- { /* Use current mode to learn */
- /* whether VGA is monochrome or */
- /* color. */
- inregs.h.ah = 0x0f;
- int86(16,&inregs,&outregs);
- if (outregs.h.al == 7 || outregs.h.al == 15)
- /* Active adapter is SC_MONO. */
- b_vga = (vga_state == _ACTIVE ? SC_MONO : SC_COLOR);
- else
- /* Active device is SC_COLOR. */
- b_vga = (vga_state == _ACTIVE ? SC_COLOR : SC_MONO);
- }
- }
- else
- {
- b_mcga =
- b_vga = SC_ABSENT;
- }
-
- /* Next test for the presence of an EGA: attempt BIOS video */
- /* function 18, subfunction BL=0x10 ("Return EGA Information"). */
- /* If any information returned is invalid, then the EGA must be */
- /* absent. */
-
- if (b_ega != SC_ABSENT)
- {
- inregs.h.ah = 18;
- inregs.x.bx = 0xff10;
- inregs.x.cx = 0x000f;
- int86(16,&inregs,&outregs);
- color_or_mono = outregs.h.bh;
- mem = outregs.h.bl;
- b_sw_ega = outregs.h.cl;
-
- if (b_sw_ega >= 12 || color_or_mono > 1 || mem > 3)
- b_ega = SC_ABSENT; /* Invalid value(s) found */
- else
- { /* EGA is present */
- b_ega = (color_or_mono ? SC_MONO : SC_COLOR);
- b_mem_ega = 64 * (mem + 1);
- }
- }
-
- /* If the EGA, VGA, or MCGA is emulating the MDPA or the CGA, */
- /* then the emulated board cannot itself be present, but the */
- /* other might be. */
-
- if (b_mdpa == SC_DONT_KNOW)
- if (b_ega==SC_MONO || b_vga==SC_MONO || b_mcga==SC_MONO
- || !adap_present(0)) /* Sense monochrome adapter */
- b_mdpa = SC_ABSENT;
- else
- b_mdpa = SC_MONO;
-
- /* Further, if we sense a color adapter, then exactly one of the */
- /* following conditions must be true: EGA, VGA, or MCGA is in */
- /* color mode; PGC is emulating the CGA; or a genuine CGA is */
- /* present. */
-
- pgc_emul_tested = 0;
- if (b_cga == SC_DONT_KNOW)
- {
- if (b_ega==SC_COLOR || b_vga==SC_COLOR || b_mcga==SC_COLOR)
- b_cga = SC_ABSENT;
- else if (adap_present(1)) /* Sense color adapter */
- {
- if (pgc_emulating() == SC_COLOR)
- {
- b_pgc = SC_COLOR;
- b_cga = SC_ABSENT;
- }
- else
- b_cga = SC_COLOR;
- pgc_emul_tested = 1;
- }
- else
- b_cga = SC_ABSENT;
- }
-
- /* If the PGC is present but not emulating the CGA, then it must */
- /* be in its high-function graphics mode. */
-
- if (b_pgc == SC_DONT_KNOW)
- {
- if (pgc_present())
- b_pgc = (pgc_emul_tested ? SC_HIFUNC : pgc_emulating());
- else
- b_pgc = SC_ABSENT;
- }
-
- }
-
- if (b_mdpa == SC_MONO && herc()) /* Hercules adapter may be */
- b_herc = SC_MONO; /* emulating monochrome. */
- else
- b_herc = SC_ABSENT;
-
- b_know_hw = 1;
-
- return b_pcmodel;
- }
-
- /**
- *
- * Name note_adapter -- Record installed adapters based on BIOS
- * display combination code from video
- * function 0x1a
- *
- * Synopsis note_adapter(code,active_flag);
- *
- * unsigned char code Display code from BIOS video
- * function 0x1a.
- * int active_flag _ACTIVE or _ALTERNATE indicating
- * whether we are dealing with the
- * active or alternate adapter.
- *
- * Description This function extracts adapter presence information from
- * a display combination code from BIOS function 0x1a.
- *
- * Result b_mdpa, b_cga, b_ega, vga_state, b_mcga, or pgc_state
- * (Depending on which adapter is
- * indicated by the code).
- *
- **/
-
- static void note_adapter(code,active_flag)
- unsigned char code;
- int active_flag;
- {
- switch (code)
- {
- case 0x01: b_mdpa = SC_MONO; break;
- case 0x02: b_cga = SC_COLOR; break;
- case 0x04: b_ega = SC_COLOR; break;
- case 0x05: b_ega = SC_MONO; break;
- case 0x06: pgc_state = _PRESENT; break;
-
- case 0x07:
- case 0x08: vga_state = active_flag; break;
-
- case 0x0b:
- case 0x0c: b_mcga = SC_COLOR; break;
- }
- }
-
- /**
- *
- * Name adap_present -- Test for Monochrome or Color/Graphics
- * Adapter or emulator
- *
- * Synopsis present = adap_present(adapter);
- * int present 1 if present or being emulated,
- * 0 if not.
- * int adapter 0 if testing for Monochrome Adapter,
- * 1 if Color/Graphics Adapter
- *
- * Description This function tests for the presence of the IBM
- * Monochrome Display and Printer Adapter or the IBM
- * Color/Graphics Adapter or other device (such as the EGA
- * or PGC) that may be emulating them.
- *
- * We do an assignment between the UTINP and UTOUTP calls
- * so that the device has time to properly stabilize
- * when using slow devices with fast processors.
- *
- * Method Write a bogus value into the cursor position register of
- * the CRT controller chip, then read it back again. If
- * the same value is found in the register, then the CRTC
- * must be present; if the value is different, then it must
- * be absent.
- *
- * Result present 1 if present or being emulated,
- * 0 if not.
- *
- **/
-
- static int adap_present(adapter)
- int adapter;
- {
- int crtc_there;
- char save_cursor;
- unsigned int port; /* Address of the CRT controller chip */
-
- port = (adapter ? 0x03d4 : 0x03b4);
-
- utoutp(port++,0xf); /* Set cursor register */
- WAIT
- /* Save previous contents */
- save_cursor = (unsigned char) utinp(port);
-
- utoutp(port,0x5a); /* Set to column 90 */
- WAIT
- crtc_there = (utinp(port) == 0x5a); /* Read the value back again */
- WAIT
- utoutp(port,save_cursor); /* Restore previous contents */
- return crtc_there;
- }
-
- /**
- *
- * Name pgc_present -- Test for IBM Professional Graphics
- * Controller
- *
- * Synopsis present = pgc_present();
- * int present 1 if present, 0 if not.
- *
- * Description This function tests for the presence of the IBM
- * Professional Graphics Controller.
- *
- * Method Write a bogus value into the supposed PGC, then read it
- * back again. If the same value is found, then the PGC
- * must be present; if the value is different, then it must
- * be absent.
- *
- * Result present 1 if present, 0 if not.
- *
- **/
-
- static int pgc_present()
- {
- int result;
- char save,dummy;
-
- switch (pgc_state)
- {
- case _ABSENT:
- result = 0;
- break;
- case _PRESENT:
- result = 1;
- break;
-
- case _DONT_KNOW:
- save = utpeekb(PGC_PRES_BYTE); /* Save previous contents */
- WAIT
- utpokeb(PGC_PRES_BYTE,0x5a); /* Store dummy value */
- WAIT
- dummy = utpeekb(PGC_PRES_BYTE); /* Read it back again */
- WAIT
- utpokeb(PGC_PRES_BYTE,save); /* Restore previous contents */
- result = (dummy == 0x5a);
- break;
- }
- return result;
- }
-
- /**
- *
- * Name pgc_emulating -- Test for whether IBM Professional
- * Graphics Controller is emulating the IBM
- * Color/Graphics Adapter
- *
- * Synopsis emulating = pgc_emulating();
- * int emulating SC_COLOR if PGC emulating the CGA,
- * SC_HIFUNC if not.
- *
- * Description This function tests for whether the IBM Professional
- * Graphics Controller is emulating the IBM Color/Graphics
- * Adapter.
- *
- * Method Write a bogus value into the PGC through a memory
- * address, then read it back again through an input port.
- * If the same value is found, then the PGC must be present
- * and in CGA emulation mode; if the value is different,
- * then (if the PGC is indeed present) it must be in
- * high-function graphics mode.
- *
- * Result present SC_COLOR if PGC emulating the CGA,
- * SC_HIFUNC if not.
- *
- **/
-
- static int pgc_emulating()
- {
- char save,dummy;
-
- save = utpeekb(PGC_IND_BYTE); /* Save previous contents */
- WAIT
- utpokeb(PGC_IND_BYTE,0x28); /* Store dummy value */
- WAIT
- dummy = (char) utinp(PGC_INDEX); /* Read it back again */
- WAIT
- utpokeb(PGC_IND_BYTE,save); /* Restore previous contents */
-
- return (dummy == 0x28) ? SC_COLOR : SC_HIFUNC;
- }
-
- /**
- *
- * Name herc -- Sense presence of Hercules monochrome graphics
- * adapter.
- *
- * Synopsis present = herc();
- *
- * int present Zero if Hercules adapter absent,
- * nonzero if present.
- *
- * Description This function reports whether the Hercules monochrome
- * graphics adapter is present.
- *
- * Result present Zero if Hercules adapter absent,
- * nonzero if present.
- *
- **/
-
- static int herc()
- {
- unsigned char save;
- unsigned int i;
- int result;
-
- result = 0;
- save = (unsigned char) (utinp(0x3ba) & 0x80);
- for (i = 0; i < (unsigned int) 32768L; i++)
- if (save != (unsigned char) (utinp(0x3ba) & 0x80))
- {
- result = 1;
- break;
- }
-
- return result;
- }