home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Examples / DriverKit / QVision / QVision_reloc.tproj / QVisionDAC.m < prev    next >
Text File  |  1996-03-26  |  5KB  |  192 lines

  1. /* Copyright (c) 1993-1996 by NeXT Software, Inc. as an unpublished work.
  2.  * All rights reserved.
  3.  *
  4.  * QVisionDAC.m -- DAC support for the QVision.
  5.  *
  6.  * History
  7.  * Thu Sep 15 16:13:45 PDT 1994, James C. Lee
  8.  *   Added AT&T 20C505 DAC support
  9.  * Author:  Derek B Clegg    30 June 1993
  10.  * Based on work by Joe Pasqua.
  11.  */
  12. #import <driverkit/generalFuncs.h>
  13. #import <driverkit/i386/ioPorts.h>
  14. #import <bsd/dev/ev_types.h>
  15. #import "QVision.h"
  16.  
  17. /* The `ProgramDAC' category of `QVision'. */
  18.  
  19. @implementation QVision (ProgramDAC)
  20.  
  21. // also check for AT&T 20C505 DAC; it's BT485 compatible
  22. static DACtype checkForBrooktreeDAC(void)
  23. {
  24.     DACtype dac;
  25.  
  26.     /* Unlock the extended graphics registers. */
  27.     outw(VGA_GRFX_INDEX, 0x050f);
  28.  
  29.     /* Unlock some more extended registers. */
  30.     outb(VGA_GRFX_INDEX, 0x10);
  31.     outb(VGA_GRFX_DATA, 0x08);
  32.  
  33.     /* Read the status register. */
  34.     switch (inb(DAC_EXT_REG) & 0xF0) {
  35.     case 0x40:
  36.     dac = Bt484;
  37.     break;
  38.     case 0x80:
  39.     dac = Bt485;
  40.     break;
  41.     case 0x20:
  42.     dac = Bt485A;
  43.     break;
  44.     case 0xd0:
  45.     dac = ATT20C505;
  46.     break;
  47.     default:
  48.     dac = UnknownDAC;
  49.     break;
  50.     }
  51.     return dac;
  52. }
  53.  
  54. - determineDACType
  55. {
  56.     dac = checkForBrooktreeDAC();
  57.     return self;
  58. }
  59.  
  60. /* Default gamma precompensation table for color displays.
  61.  * Gamma 2.2 LUT for P22 phosphor displays (Hitachi, NEC, generic VGA) */
  62.  
  63. static const unsigned char gamma16[] = {
  64.       0,  74, 102, 123, 140, 155, 168, 180,
  65.     192, 202, 212, 221, 230, 239, 247, 255
  66. };
  67.  
  68. static const unsigned char gamma8[] = {
  69.       0,  15,  22,  27,  31,  35,  39,  42,  45,  47,  50,  52,
  70.      55,  57,  59,  61,  63,  65,  67,  69,  71,  73,  74,  76,
  71.      78,  79,  81,  82,  84,  85,  87,  88,  90,  91,  93,  94,
  72.      95,  97,  98,  99, 100, 102, 103, 104, 105, 107, 108, 109,
  73.     110, 111, 112, 114, 115, 116, 117, 118, 119, 120, 121, 122,
  74.     123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
  75.     135, 136, 137, 138, 139, 140, 141, 141, 142, 143, 144, 145,
  76.     146, 147, 148, 148, 149, 150, 151, 152, 153, 153, 154, 155, 
  77.     156, 157, 158, 158, 159, 160, 161, 162, 162, 163, 164, 165,
  78.     165, 166, 167, 168, 168, 169, 170, 171, 171, 172, 173, 174,
  79.     174, 175, 176, 177, 177, 178, 179, 179, 180, 181, 182, 182,
  80.     183, 184, 184, 185, 186, 186, 187, 188, 188, 189, 190, 190, 
  81.     191, 192, 192, 193, 194, 194, 195, 196, 196, 197, 198, 198,
  82.     199, 200, 200, 201, 201, 202, 203, 203, 204, 205, 205, 206, 
  83.     206, 207, 208, 208, 209, 210, 210, 211, 211, 212, 213, 213,
  84.     214, 214, 215, 216, 216, 217, 217, 218, 218, 219, 220, 220, 
  85.     221, 221, 222, 222, 223, 224, 224, 225, 225, 226, 226, 227,
  86.     228, 228, 229, 229, 230, 230, 231, 231, 232, 233, 233, 234, 
  87.     234, 235, 235, 236, 236, 237, 237, 238, 238, 239, 240, 240,
  88.     241, 241, 242, 242, 243, 243, 244, 244, 245, 245, 246, 246, 
  89.     247, 247, 248, 248, 249, 249, 250, 250, 251, 251, 252, 252,
  90.     253, 253, 254, 255, 
  91. };
  92.  
  93. static void
  94. SetGammaValue(unsigned int r, unsigned int g, unsigned int b, int level)
  95. {
  96.     outb(PALETTE_DATA, EV_SCALE_BRIGHTNESS(level, r));
  97.     outb(PALETTE_DATA, EV_SCALE_BRIGHTNESS(level, g));
  98.     outb(PALETTE_DATA, EV_SCALE_BRIGHTNESS(level, b));
  99. }
  100.  
  101. - setGammaTable
  102. {
  103.     unsigned int i, j, g;
  104.     const IODisplayInfo *displayInfo;
  105.  
  106.     displayInfo = [self displayInfo];
  107.  
  108.     outb(PALETTE_WRITE, 0x00);
  109.  
  110.     if (redTransferTable != 0) {
  111.     for (i = 0; i < transferTableCount; i++) {
  112.         for (j = 0; j < 256/transferTableCount; j++) {
  113.         SetGammaValue(redTransferTable[i], greenTransferTable[i],
  114.                   blueTransferTable[i], brightnessLevel);
  115.         }
  116.     }
  117.     } else {
  118.     switch (displayInfo->bitsPerPixel) {
  119.     case IO_24BitsPerPixel:
  120.     case IO_8BitsPerPixel:
  121.         for (g = 0; g < 256; g++) {
  122.         SetGammaValue(gamma8[g], gamma8[g], gamma8[g],
  123.                   brightnessLevel);
  124.         }
  125.         break;
  126.     case IO_15BitsPerPixel:
  127.         for (i = 0; i < 32; i++) {
  128.         for (j = 0; j < 8; j++) {
  129.             SetGammaValue(gamma16[i/2], gamma16[i/2], gamma16[i/2],
  130.                   brightnessLevel);
  131.         }
  132.         }
  133.         break;
  134.     default:
  135.         break;
  136.     }
  137.     }
  138.     return self;
  139. }
  140.  
  141. - resetDAC
  142. {
  143.     const QVisionMode *mode;
  144.  
  145.     mode = [self displayInfo]->parameters;
  146.  
  147.     if (dac == Bt485 || dac == Bt485A || dac == ATT20C505) {
  148.     /* Brooktree 485 or 485A only! */
  149.     outb(DAC_CMD_0, 0x80);        /* Enable the DAC_EXT_REG. */
  150.     outb(PALETTE_WRITE, 0x01);    /* Make 13C6 be the DAC_EXT_REG. */
  151.     outb(DAC_EXT_REG, 0x00);    /* Turn off clock doubling. */
  152.     outb(PALETTE_WRITE, 0x00);    /* Restore 13C6. */
  153.     }
  154.  
  155.     /* Restore DAC command registers 0, 1, & 2 to their initial VGA values. */
  156.     outb(DAC_CMD_0, 0x40);
  157.     outb(DAC_CMD_1, 0x00);
  158.     outb(DAC_CMD_2, 0x20);
  159.  
  160.     return self;
  161. }
  162.  
  163. - programDAC
  164. {
  165.     const QVisionMode *mode;
  166.  
  167.     mode = [self displayInfo]->parameters;
  168.  
  169.     /* Load DAC Command regs. */
  170.     outb(DAC_CMD_0, 0x02);        /* 8-bit DAC. */
  171.     outb(DAC_CMD_1, mode->dacCmd1);    /* Set the bits per pixel. */
  172.     outb(DAC_CMD_2, 0x20);        /* Allow advanced modes. */
  173.     
  174.     if (mode->needsPixelDoubling &&
  175.         (dac == Bt485 || dac == Bt485A || dac == ATT20C505))
  176.     {
  177.     /* Brooktree 485 or 485A, or AT&T 20C505 only! */
  178.     outb(DAC_CMD_0, 0x82);        /* Enable the DAC_EXT_REG. */
  179.     outb(PALETTE_WRITE, 0x01);    /* Make 13C6 be the DAC_EXT_REG. */
  180.     outb(DAC_EXT_REG, 0x08);    /* Turn on clock doubling. */
  181.     }
  182.  
  183.     /* Set overscan color (black) */
  184.     outb(CO_COLOR_WRITE, 0x00);
  185.     outb(CO_COLOR_DATA, 0x00);        /* Red component. */
  186.     outb(CO_COLOR_DATA, 0x00);        /* Green component. */
  187.     outb(CO_COLOR_DATA, 0x00);        /* Blue component. */
  188.  
  189.     return self;
  190. }
  191. @end
  192.