home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Examples / DriverKit / QVision / QVision_reloc.tproj / QVisionDAC.m < prev    next >
Encoding:
Text File  |  1993-07-20  |  5.1 KB  |  184 lines

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