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
- *
- * 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 BSCREEN.H, except for b_pcmodel, which is
- * declared in BQUERY.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 and SCROWS to obtain video information which
- * might be altered under software control (such as video
- * mode or number of columns or lines). Use SCNEWDEV or
- * SCCHGDEV to switch to a given video adapter.
- *
- * Results 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
- * (Also sets various global variables in BSCREEN.H)
- *
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1986
- *
- * Version 3.02 March 24, 1987
- * Removed a strong typing warning (no change in object
- * code).
- *
- **/
-
- #include <bscreen.h>
- #include <bquery.h>
-
- #if LAT300
- #include <dos.h>
- #endif
- #if MSC300
- #include <conio.h>
- #endif
-
- int b_know_hw = 0; /* Flag stating whether we have yet */
- /* run EQINIT: 0 if no, 1 if yes */
-
- int b_mdpa = DONT_KNOW; /* Monochrome Display & Printer Adapter */
- /* DONT_KNOW, ABSENT, or MONO */
-
- int b_cga = DONT_KNOW; /* Color/Graphics Monitor Adapter */
- /* DONT_KNOW, ABSENT, or COLOR */
-
- int b_ega = DONT_KNOW; /* Enhanced Graphics Adapter */
- /* DONT_KNOW, ABSENT, MONO or COLOR */
-
- int b_pgc = DONT_KNOW; /* Professional Graphics Controller */
- /* DONT_KNOW, ABSENT, COLOR or 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 int adap_present(int); /* Internal function */
- static int pgc_present(void); /* Internal function */
- static int pgc_emulating(void); /* Internal function */
-
- char scequip()
- {
- int ax,bx,cx,dx,flags; /* Registers for BIOS call */
- unsigned color_or_mono,mem;
- int pgc_mode;
-
- if (b_know_hw)
- return b_pcmodel; /* No need to do this work again */
-
- if (qymodel() == IBM_JR) /* Fetch & save model code. */
- { /* This is a PCjr */
- b_mdpa = ABSENT;
- b_cga = ABSENT;
- b_ega = ABSENT;
- b_pgc = ABSENT;
- }
- else if (b_pcmodel == IBM_CV)
- { /* IBM PC Convertible acts like */
- b_mdpa = MONO; /* both MDPA & CGA. */
- b_cga = COLOR;
- b_ega = ABSENT;
- b_pgc = ABSENT;
- }
- else
- { /* Neither PCjr nor Convertible */
-
- /* First 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. */
-
- ax = utbyword(18,0);
- bx = (int) 0xff10;
- cx = 0x000f;
- bios(16,&ax,&bx,&cx,&dx,&flags);
- color_or_mono = uthibyte(bx);
- mem = utlobyte(bx);
- b_sw_ega = utlobyte(cx);
-
- if (b_sw_ega >= 12 || color_or_mono > 1 || mem > 3)
- b_ega = ABSENT; /* Invalid value(s) found */
- else
- { /* EGA is present */
- b_ega = (color_or_mono ? MONO : COLOR);
- b_mem_ega = 64 * (mem + 1);
- }
-
- /* If the EGA is present, the color_or_mono flag says whether */
- /* it is emulating the MDPA or the CGA; if so, then the emulated */
- /* board cannot itself be present, but the other might be. */
-
- if (b_ega == MONO
- || !adap_present(0)) /* Sense mono adapter */
- b_mdpa = ABSENT;
- else
- b_mdpa = MONO;
-
- /* Further, if we sense a color adapter, then exactly one of the */
- /* following conditions must be true: EGA is in color mode */
- /* (detected above from color_or_mono flag); PGC is emulating the */
- /* CGA; or a genuine CGA is present. */
-
- pgc_mode = DONT_KNOW;
- if (b_ega == COLOR
- || (!adap_present(1)) /* Sense color adapter */
- || (pgc_mode = pgc_emulating()) == COLOR)
- b_cga = ABSENT;
- else
- b_cga = COLOR;
-
- /* If the PGC is present but not emulating the CGA, then it must */
- /* be in its high-function graphics mode. */
-
- if (pgc_mode == COLOR)
- b_pgc = COLOR;
- else
- b_pgc = (pgc_present() ? HIFUNC : ABSENT);
- }
-
- b_know_hw = 1;
- return b_pcmodel;
- }
-
- /**
- *
- * 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.
- *
- * 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 save_cursor,crtc_there;
- unsigned int port; /* Address of the CRT controller chip */
-
- port = (adapter ? 0x03d4 : 0x03b4);
-
- outp(port++,0xf); /* Set cursor register */
-
- save_cursor = inp(port); /* Save previous contents */
-
- outp(port,0x5a); /* Set to column 90 */
- crtc_there = (inp(port) == 0x5a); /* Read the value back again */
-
- outp(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()
- {
- static ADS pgc_ads = {0x03db,0xc600};
- char save,dummy;
- ADS save_ads,dummy_ads;
-
- utabsptr(&save,&save_ads);
- utslmove(&pgc_ads,&save_ads,1); /* Save previous contents */
-
- dummy = 0x5a;
- utabsptr(&dummy,&dummy_ads);
- utslmove(&dummy_ads,&pgc_ads,1); /* Store dummy value */
- utslmove(&pgc_ads,&dummy_ads,1); /* Read it back again */
-
- utslmove(&save_ads,&pgc_ads,1); /* Restore previous contents */
- return (dummy == 0x5a);
- }
-
- /**
- *
- * Name pgc_emulating -- Test for whether IBM Professional
- * Graphics Controller is emulating the IBM Color/Graphics
- * Adapter
- *
- * Synopsis emulating = pgc_emulating();
- * int emulating COLOR if PGC emulating the CGA,
- * 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 COLOR if PGC emulating the CGA,
- * HIFUNC if not.
- *
- **/
-
- static int pgc_emulating()
- {
- static ADS pgc_ads = {0x03d4,0xc600};
- char save,dummy;
- ADS save_ads,dummy_ads;
-
- utabsptr(&save,&save_ads);
- utslmove(&pgc_ads,&save_ads,1); /* Save previous contents */
-
- dummy = 0x28;
- utabsptr(&dummy,&dummy_ads);
- utslmove(&dummy_ads,&pgc_ads,1); /* Store dummy value */
- dummy = (char) inp(0x3d4); /* Read it back again */
- utslmove(&save_ads,&pgc_ads,1); /* Restore previous contents */
-
- return (dummy == 0x28) ? COLOR : HIFUNC;
- }