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

  1. /* Copyright (c) 1993-1996 by NeXT Software, Inc. as an unpublished work.
  2.  * All rights reserved.
  3.  *
  4.  * vgaModes.c -- VGA Mode support for the QVision.
  5.  *
  6.  */
  7.  
  8. #import <driverkit/i386/ioPorts.h>
  9. #import "vgaModes.h"
  10.  
  11. static const VGAMode VGAMode_3 = {
  12.     0x67, 0x00,
  13.     { 0x01, 0x00, 0x03, 0x00, 0x02 },
  14.     {                    
  15.     0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f, 0x00, 0x4f,
  16.     0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x9c, 0x8e, 0x8f, 0x28,
  17.     0x1f, 0x96, 0xb9, 0xa3, 0xff,
  18.     },
  19.     {
  20.     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39,
  21.     0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x0c, 0x00, 0x0f, 0x08,
  22.     },
  23.     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0e, 0x00, 0xff },
  24. };
  25.  
  26. static const VGAMode VGAMode_12 = {
  27.     0xE3, 0x00,
  28.     { 0x03, 0x01, 0x0f, 0x00, 0x06 },
  29.     {
  30.     0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0x0b, 0x3e, 0x00, 0x40,
  31.     0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0xea, 0x8c, 0xdf, 0x28,
  32.     0x00, 0xe7, 0x04, 0xe3, 0xff,
  33.     },
  34.     {
  35.     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07, 0x38, 0x39,
  36.     0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x01, 0x00, 0x0f, 0x00,
  37.     },
  38.     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0f, 0xff },
  39. };
  40.  
  41. int
  42. VGASetMode(unsigned int mode)
  43. {
  44.     switch (mode) {
  45.     case 0x03:
  46.     VGASetModeData(&VGAMode_3);
  47.     break;
  48.     case 0x12:
  49.     VGASetModeData(&VGAMode_12);
  50.     break;
  51.     default:
  52.     return -1;
  53.     }
  54.     return 0;
  55. }
  56.  
  57. int
  58. VGASetModeData(const VGAMode *modeData)
  59. {
  60.     int k;
  61.     
  62.     /* NOTE: The attribute registers are a little weird. For most registers,
  63.      * there is a separate index and data port. The attribute register set
  64.      * has just one port that gets used for both. You write an index to the
  65.      * port, then use the same port for data. The VGA automatically toggles
  66.      * the sense of the port (between index and data) with an internal
  67.      * flip-flop.  You set the state of the flip-flop by doing an inb() on
  68.      * the input status 1 port.
  69.      *
  70.      * The other weird thing is that the attribute index register also
  71.      * contains a palette access bit. This bit determines whether the
  72.      * CPU or the VGA has control of the palette. While the CPU owns the
  73.      * palette, the display is effectively off.
  74.      */
  75.  
  76.     /* Turn the video off while we are doing this.... */
  77.  
  78.     inb(VGA_INPUT_STATUS_1);    /* Set the attribute flip-flop to "index". */
  79.     outb(VGA_ATTR_INDEX, 0x00);    /* Gives palette to CPU, turning off video. */
  80.     
  81.     /* Set the misc. output register. */
  82.     outb(VGA_MISC_OUTPUT, modeData->miscOutput);
  83.     
  84.     /* Set the feature control register */
  85.     outb(VGA_FEATURE_CTRL, modeData->featureCtrl);
  86.  
  87.     /* Load the sequencer registers. */
  88.     for (k = 0; k < VGA_SEQ_COUNT; k++) {
  89.     outb(VGA_SEQ_INDEX, k);
  90.     outb(VGA_SEQ_DATA, modeData->seqx[k]);
  91.     }
  92.     outb(VGA_SEQ_INDEX, 0x00);
  93.     outb(VGA_SEQ_DATA, 0x03);    /* Low order two bits are reset bits. */
  94.     
  95.     /* Load the CRTC registers.  CRTC registers 0-7 are locked by a bit
  96.      * in register 0x11. We need to unlock these registers before we can
  97.      * start setting them. */
  98.     outb(VGA_CRTC_INDEX, 0x11);
  99.     outb(VGA_CRTC_DATA, 0x00);        /* Unlocks registers 0-7. */
  100.     for (k = 0; k < VGA_CRTC_COUNT; k++) {
  101.     outb(VGA_CRTC_INDEX, k);
  102.     outb(VGA_CRTC_DATA, modeData->crtc[k]);
  103.     }
  104.  
  105.     /* Load the attribute registers. */
  106.     inb(VGA_INPUT_STATUS_1);    /* Set the attribute flip-flop to "index" */
  107.     for (k = 0; k < VGA_ATTR_COUNT; k++) {
  108.     outb(VGA_ATTR_INDEX, k);
  109.     outb(VGA_ATTR_DATA, modeData->attr[k]);
  110.     }
  111.  
  112.     /* Load graphics registers. */
  113.     for (k = 0; k < VGA_GRFX_COUNT; k++) {
  114.     outb(VGA_GRFX_INDEX, k);
  115.     outb(VGA_GRFX_DATA, modeData->grfx[k]);
  116.     }    
  117.  
  118.     /* Re-enable video. */
  119.     inb(VGA_INPUT_STATUS_1);    /* Set the attribute flip-flop to "index" */
  120.     outb(VGA_ATTR_INDEX, 0x20);    /* Give the palette back to the VGA */
  121.     
  122.     return 0;
  123. }
  124.