home *** CD-ROM | disk | FTP | other *** search
/ Graphics Programming Black Book (Special Edition) / BlackBook.bin / disk1 / source / chapterg / lg-1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-18  |  3.8 KB  |  73 lines

  1. /* Looks for a Sierra Hicolor DAC; if one is present, puts the VGA into the 
  2. specified Hicolor (32K color) mode. Relies on the Tseng Labs ET4000 BIOS and 
  3. hardware; probably will not work on adapters built around other VGA chips. 
  4. Returns 1 for success, 0 for failure; failure can result from no Hicolor DAC, 
  5. too little display memory, or lack of an ET4000.
  6.  
  7. Tested with Borland C++ 4.02 in small model by Jim Mischel 12/16/94. */
  8.  
  9. #include <dos.h>
  10. #define DAC_MASK  0x3C6 /* DAC pixel mask reg address, also Sierra
  11.                            command reg address when enabled */
  12. #define DAC_WADDR 0x3C8  /* DAC write address reg address */
  13.  
  14. /* Mode selections: 0x2D=640x350; 0x2E=640x480; 0x2F=640x400; 0x30=800x600 */
  15. int SetHCMode(int Mode) {
  16.    int i, Temp1, Temp2, Temp3;
  17.    union REGS regset;
  18.  
  19.    /* See if a Sierra SC1148X Hicolor DAC is present, by trying to
  20.    program and then read back the DAC's command register. (Shouldn't be 
  21.    necessary when using the BIOS Get DAC Type function, but the BIOS function 
  22.    locks up some computers, so it's safer to check the hardware first) */
  23.    inp(DAC_WADDR); /* reset the Sierra command reg enable sequence */
  24.    for (i=0; i<4; i++) inp(DAC_MASK); /* enable command reg access */
  25.    outp(DAC_MASK, 0x00); /* set command reg (if present) to 0x00, and
  26.                             reset command reg enable sequence */
  27.    outp(DAC_MASK, 0xFF); /* command reg access no longer enabled;
  28.                             set pixel mask register to 0xFF */
  29.    for (i=0; i<4; i++) inp(DAC_MASK); /* enable command reg access */
  30.    /* If this is a Hicolor DAC, we should read back the 0 in the
  31.       command reg; otherwise we get the 0xFF in the pixel mask reg */
  32.    i = inp(DAC_MASK); inp(DAC_WADDR); /* reset enable sequence */
  33.    if (i == 0xFF) return(0);
  34.  
  35.    /* Check for a Tseng Labs ET4000 by poking unique regs, (assumes
  36.       VGA configured for color, w/CRTC addressing at 3D4/5) */
  37.    outp(0x3BF, 3); outp(0x3D8, 0xA0);  /* unlock extended registers */
  38.    /* Try toggling AC R16 bit 4 and seeing if it takes */
  39.    inp(0x3DA); outp(0x3C0, 0x16 | 0x20);
  40.    outp(0x3C0, ((Temp1 = inp(0x3C1)) | 0x10)); Temp2 = inp(0x3C1);
  41.    outp(0x3C0, 0x16 | 0x20); outp(0x3C0, (inp(0x3C1) & ~0x10));
  42.    Temp3 = inp(0x3C1); outp(0x3C0, 0x16 | 0x20);
  43.    outp(0x3C0, Temp1);  /* restore original AC R16 setting */
  44.    /* See if the bit toggled; if so, it's an ET3000 or ET4000 */
  45.    if ((Temp3 & 0x10) || !(Temp2 & 0x10)) return(0);
  46.    outp(0x3D4, 0x33); Temp1 = inp(0x3D5); /* get CRTC R33 setting */
  47.    outp(0x3D5, 0x0A); Temp2 = inp(0x3D5); /* try writing to CRTC */
  48.    outp(0x3D5, 0x05); Temp3 = inp(0x3D5); /*  R33 */
  49.    outp(0x3D5, Temp1);  /* restore original CRTC R33 setting */
  50.    /* If the register was writable, it's an ET4000 */
  51.    if ((Temp3 != 0x05) || (Temp2 != 0x0A)) return(0);
  52.  
  53.    /* See if a Sierra SC1148X Hicolor DAC is present by querying the
  54.       (presumably) ET4000-compatible BIOS. Not really necessary after
  55.       the hardware check above, but generally more useful; in the
  56.       future it will return information about other high-color DACs */
  57.    regset.x.ax = 0x10F1;   /* Get DAC Type BIOS function # */
  58.    int86(0x10, ®set, ®set); /* ask BIOS for the DAC type */
  59.    if (regset.x.ax != 0x0010) return(0); /* function not supported */
  60.    switch (regset.h.bl) {
  61.       case 0:  return(0);  /* normal DAC (non-Hicolor) */
  62.       case 1:  break;      /* Sierra SC1148X 15-bpp Hicolor DAC */
  63.       default: return(0);  /* other high-color DAC */
  64.    }
  65.  
  66.    /* Set Hicolor mode */
  67.    regset.x.ax = 0x10F0;   /* Set High-Color Mode BIOS function # */
  68.    regset.h.bl = Mode;     /* desired resolution */
  69.    int86(0x10, ®set, ®set); /* have BIOS enable Hicolor mode */
  70.    return (regset.x.ax == 0x0010); /* 1 for success, 0 for failure */
  71. }
  72.  
  73.