home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / SVGALIB / SVGALIB1.TAR / svgalib / src / vgaregs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-28  |  4.9 KB  |  179 lines

  1.  
  2. #include "timing.h"
  3. #include "vgaregs.h"
  4.  
  5.  
  6. /*
  7.  * Setup VGA registers for SVGA mode timing. Adapted from XFree86,
  8.  * vga256/vga/vgaHW.c vgaHWInit().
  9.  *
  10.  * Note that VGA registers are set up in a way that is common for
  11.  * SVGA modes. This is not particularly useful for standard VGA
  12.  * modes, since VGA does not have a clean packed-pixel mode.
  13.  */
  14.  
  15. void setup_VGA_registers( unsigned char *moderegs, ModeTiming *modetiming,
  16. ModeInfo *modeinfo ) {
  17.     int i;
  18. /* Sync Polarities */
  19.     if ((modetiming->flags & (PHSYNC | NHSYNC)) &&
  20.     (modetiming->flags & (PVSYNC | NVSYNC))) {
  21.         /*
  22.          * If both horizontal and vertical polarity are specified,
  23.          * set them as specified.
  24.          */
  25.         moderegs[VGA_MISCOUTPUT] = 0x23;
  26.         if (modetiming->flags & NHSYNC)
  27.             moderegs[VGA_MISCOUTPUT] |= 0x40;
  28.         if (modetiming->flags & NVSYNC)
  29.             moderegs[VGA_MISCOUTPUT] |= 0x80;
  30.     }
  31.     else {
  32.         /*
  33.          * Otherwise, calculate the polarities according to
  34.          * monitor standards.
  35.          */
  36.         if (modetiming->VDisplay < 400)
  37.             moderegs[VGA_MISCOUTPUT] = 0xA3;
  38.         else if (modetiming->VDisplay < 480)
  39.             moderegs[VGA_MISCOUTPUT] = 0x63;
  40.         else if (modetiming->VDisplay < 768)
  41.             moderegs[VGA_MISCOUTPUT] = 0xE3;
  42.         else
  43.             moderegs[VGA_MISCOUTPUT] = 0x23;
  44.     }
  45.  
  46. /* Sequencer */
  47.     moderegs[VGA_SR0] = 0x00;
  48.     if (modeinfo->bitsPerPixel == 4)
  49.         moderegs[VGA_SR0] = 0x02;
  50.     moderegs[VGA_SR1] = 0x01;
  51.     moderegs[VGA_SR2] = 0x0F;    /* Bitplanes. */
  52.     moderegs[VGA_SR3] = 0x00;
  53.     moderegs[VGA_SR4] = 0x0E;
  54.     if (modeinfo->bitsPerPixel == 4)
  55.         moderegs[VGA_SR4] = 0x06;
  56.  
  57. /* CRTC Timing */
  58.     moderegs[VGA_CR0] = (modetiming->CrtcHTotal / 8) - 5;
  59.     moderegs[VGA_CR1] = (modetiming->CrtcHDisplay / 8) - 1;
  60.     moderegs[VGA_CR2] = (modetiming->CrtcHSyncStart / 8) - 1;
  61.     moderegs[VGA_CR3] = ((modetiming->CrtcHSyncEnd / 8) & 0x1F) | 0x80;
  62.     moderegs[VGA_CR4] = (modetiming->CrtcHSyncStart / 8);
  63.     moderegs[VGA_CR5] = (((modetiming->CrtcHSyncEnd / 8) & 0x20) << 2)
  64.         | ((modetiming->CrtcHSyncEnd / 8) & 0x1F);
  65.     moderegs[VGA_CR6] = (modetiming->CrtcVTotal - 2) & 0xFF;
  66.     moderegs[VGA_CR7] = (((modetiming->CrtcVTotal - 2) & 0x100) >> 8)
  67.         | (((modetiming->CrtcVDisplay - 1) & 0x100) >> 7)
  68.         | ((modetiming->CrtcVSyncStart & 0x100) >> 6)
  69.         | (((modetiming->CrtcVSyncStart) & 0x100) >> 5)
  70.         | 0x10
  71.         | (((modetiming->CrtcVTotal - 2) & 0x200) >> 4)
  72.         | (((modetiming->CrtcVDisplay - 1) & 0x200) >> 3)
  73.         | ((modetiming->CrtcVSyncStart & 0x200) >> 2);
  74.     moderegs[VGA_CR8] = 0x00;
  75.     moderegs[VGA_CR9] = ((modetiming->CrtcVSyncStart & 0x200) >> 4) | 0x40;
  76.     if (modetiming->flags & DOUBLESCAN)
  77.         moderegs[VGA_CR9] |= 0x80;
  78.     moderegs[VGA_CRA] = 0x00;
  79.     moderegs[VGA_CRB] = 0x00;
  80.     moderegs[VGA_CRC] = 0x00;
  81.     moderegs[VGA_CRD] = 0x00;
  82.     moderegs[VGA_CRE] = 0x00;
  83.     moderegs[VGA_CRF] = 0x00;
  84.     moderegs[VGA_CR10] = modetiming->CrtcVSyncStart & 0xFF;
  85.     moderegs[VGA_CR11] = (modetiming->CrtcVSyncEnd & 0x0F) | 0x20;
  86.     moderegs[VGA_CR12] = (modetiming->CrtcVDisplay - 1) & 0xFF;
  87.     moderegs[VGA_CR13] = modeinfo->lineWidth >> 4;    /* Just a guess. */
  88.     moderegs[VGA_CR14] = 0x00;
  89.     moderegs[VGA_CR15] = modetiming->CrtcVSyncStart & 0xFF;
  90.     moderegs[VGA_CR16] = (modetiming->CrtcVSyncStart + 1) & 0xFF;
  91.     moderegs[VGA_CR17] = 0xC3;
  92.     if (modeinfo->bitsPerPixel == 4)
  93.         moderegs[VGA_CR17] = 0xE3;
  94.     moderegs[VGA_CR18] = 0xFF;
  95.  
  96. /* Graphics Controller */
  97.     moderegs[VGA_GR0] = 0x00;
  98.     moderegs[VGA_GR1] = 0x00;
  99.     moderegs[VGA_GR2] = 0x00;
  100.     moderegs[VGA_GR3] = 0x00;
  101.     moderegs[VGA_GR4] = 0x00;
  102.     moderegs[VGA_GR5] = 0x40;
  103.     if (modeinfo->bitsPerPixel == 4)
  104.         moderegs[VGA_GR5] = 0x02;
  105.     moderegs[VGA_GR6] = 0x05;
  106.     moderegs[VGA_GR7] = 0x0F;
  107.     moderegs[VGA_GR8] = 0xFF;
  108.  
  109. /* Attribute Controller */
  110.     for (i = 0; i < 16; i++)
  111.         moderegs[VGA_AR0 + i] = i;
  112.     moderegs[VGA_AR10] = 0x41;
  113.     if (modeinfo->bitsPerPixel == 4)
  114.         moderegs[VGA_AR10] = 0x01;    /* was 0x81 */
  115.     /* Attribute register 0x11 is the overscan color. */
  116.     moderegs[VGA_AR12] = 0x0F;
  117.     moderegs[VGA_AR13] = 0x00;
  118.     moderegs[VGA_AR14] = 0x00;
  119. }
  120.  
  121.  
  122. #include "libvga.h"    /* For controller port addresses. */
  123.  
  124. /*
  125.  * These are simple functions to write a value to a VGA Graphics
  126.  * Controller, CRTC Controller or Sequencer register.
  127.  * The idea is that drivers call these as a function call, making the
  128.  * code smaller and inserting small delays between I/O accesses when
  129.  * doing mode switches.
  130.  */
  131.  
  132. void outGR( int index, unsigned char val ) {
  133.     int v;
  134.     v = ((int)val << 8) + index;
  135.     outw(GRA_I, v);
  136. }
  137.  
  138. void outbGR( int index, unsigned char val ) {
  139.     outb(GRA_I, index);
  140.     outb(GRA_D, val);
  141. }
  142.  
  143. void outCR( int index, unsigned char val ) {
  144.     int v;
  145.     v = ((int)val << 8) + index;
  146.     outw(CRT_IC, v);
  147. }
  148.  
  149. void outbCR( int index, unsigned char val ) {
  150.     outb(CRT_IC, index);
  151.     outb(CRT_D, val);
  152. }
  153.  
  154. void outSR( int index, unsigned char val ) {
  155.     int v;
  156.     v = ((int)val << 8) + index;
  157.     outw(SEQ_I, v);
  158. }
  159.  
  160. void outbSR( int index, unsigned char val ) {
  161.     outb(SEQ_I, index);
  162.     outb(SEQ_D, val);
  163. }
  164.  
  165. unsigned char inGR( int index ) {
  166.     outb(GRA_I, index);
  167.     return inb(GRA_D);
  168. }
  169.  
  170. unsigned char inCR( int index ) {
  171.     outb(CRT_IC, index);
  172.     return inb(CRT_DC);
  173. }
  174.  
  175. unsigned char inSR( int index ) {
  176.     outb(SEQ_I, index);
  177.     return inb(SEQ_D);
  178. }
  179.