⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vgahw.c

📁 基于组件方式开发操作系统的OSKIT源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
    {      /*			        * save the colorlookuptable        */      outb(0x3C7,0x01);      for (i=3; i<768; i++)      {	save->DAC[i] = inb(0x3C9); 	DACDelay;      }    }  }#endif /* NEED_SAVED_CMAP */  for (i=0; i<25; i++) { outb(vgaIOBase + 4,i);			 save->CRTC[i] = inb(vgaIOBase + 5); }  for (i=0; i<21; i++) {    tmp = inb(vgaIOBase + 0x0A);    outb(0x3C0,i);    save->Attribute[i] = inb(0x3C1);  }  for (i=0; i<9;  i++) { outb(0x3CE,i); save->Graphics[i]  = inb(0x3CF); }  for (i=0; i<5;  i++) { outb(0x3C4,i); save->Sequencer[i]   = inb(0x3C5); }#endif /* !defined(PC98_NEC480) && !defined(PC98_EGC) */  vgaSaveScreen(NULL, FALSE);  #if !defined(PC98_NEC480) && !defined(PC98_EGC)  /* XXXX Still not sure if this is needed.  It isn't done in the Restore */  outb(0x3C2, save->MiscOutReg | 0x01);		/* shift to colour emulation */  /* Since forced to colour mode, must use 0x3Dx instead of (vgaIOBase + x) */#if defined(SAVE_TEXT) || defined(SAVE_FONT1) || defined(SAVE_FONT2)  /*   * get the character sets, and text screen if required   */  if (((save->Attribute[0x10] & 0x01) == 0) && (size >= 0)) {#ifdef SAVE_FONT1    if (save->FontInfo1 == NULL) {      save->FontInfo1 = (pointer)xalloc(FONT_AMOUNT);      /*       * Here we switch temporary to 16 color-plane-mode, to simply       * copy the font-info       *       * BUGALLERT: The vga's segment-select register MUST be set appropriate !       */      tmp = inb(0x3D0 + 0x0A); /* reset flip-flop */      outb(0x3C0,0x30); outb(0x3C0, 0x01); /* graphics mode */      outw(0x3C4, 0x0402);    /* write to plane 2 */      outw(0x3C4, 0x0604);    /* enable plane graphics */      outw(0x3CE, 0x0204);    /* read plane 2 */      outw(0x3CE, 0x0005);    /* write mode 0, read mode 0 */      outw(0x3CE, 0x0506);    /* set graphics */      slowbcopy_frombus(vgaBase, save->FontInfo1, FONT_AMOUNT);    }#endif /* SAVE_FONT1 */#ifdef SAVE_FONT2    if (save->FontInfo2 == NULL) {      save->FontInfo2 = (pointer)xalloc(FONT_AMOUNT);      tmp = inb(0x3D0 + 0x0A); /* reset flip-flop */      outb(0x3C0,0x30); outb(0x3C0, 0x01); /* graphics mode */      outw(0x3C4, 0x0802);    /* write to plane 3 */      outw(0x3C4, 0x0604);    /* enable plane graphics */      outw(0x3CE, 0x0304);    /* read plane 3 */      outw(0x3CE, 0x0005);    /* write mode 0, read mode 0 */      outw(0x3CE, 0x0506);    /* set graphics */      slowbcopy_frombus(vgaBase, save->FontInfo2, FONT_AMOUNT);    }#endif /* SAVE_FONT2 */#ifdef SAVE_TEXT    if (save->TextInfo == NULL) {      save->TextInfo = (pointer)xalloc(2 * TEXT_AMOUNT);      tmp = inb(0x3D0 + 0x0A); /* reset flip-flop */      outb(0x3C0,0x30); outb(0x3C0, 0x01); /* graphics mode */      /*       * This is a quick hack to save the text screen for system that don't       * restore it automatically.       */      outw(0x3C4, 0x0102);    /* write to plane 0 */      outw(0x3C4, 0x0604);    /* enable plane graphics */      outw(0x3CE, 0x0004);    /* read plane 0 */      outw(0x3CE, 0x0005);    /* write mode 0, read mode 0 */      outw(0x3CE, 0x0506);    /* set graphics */      slowbcopy_frombus(vgaBase, save->TextInfo, TEXT_AMOUNT);      outw(0x3C4, 0x0202);    /* write to plane 1 */      outw(0x3C4, 0x0604);    /* enable plane graphics */      outw(0x3CE, 0x0104);    /* read plane 1 */      outw(0x3CE, 0x0005);    /* write mode 0, read mode 0 */      outw(0x3CE, 0x0506);    /* set graphics */      slowbcopy_frombus(vgaBase, (char *)save->TextInfo + TEXT_AMOUNT, TEXT_AMOUNT);    }#endif /* SAVE_TEXT */  }#endif /* defined(SAVE_TEXT) || defined(SAVE_FONT1) || defined(SAVE_FONT2) */  outb(0x3C2, save->MiscOutReg);		/* back to original setting */#endif /* !defined(PC98_NEC480) && !defined(PC98_EGC) */    vgaSaveScreen(NULL, TRUE);#if !defined(PC98_NEC480) && !defined(PC98_EGC)  /* Turn on PAS bit */  tmp = inb(vgaIOBase + 0x0A);  outb(0x3C0, 0x20);#endif /* !defined(PC98_NEC480) && !defined(PC98_EGC) */    return ((void *) save);}/* * vgaHWInit -- *      Handle the initialization, etc. of a screen. *      Return FALSE on failure. */BoolvgaHWInit(mode, size)     DisplayModePtr      mode;     int             size;{  unsigned int       i;  /*   * If we're using an external clock program, the first thing we do is   * call it.  If it fails for any reason, we abort the mode switch and   * hope that it hasn't screwed up the old clock setting.   */  if (vga256InfoRec.clockprog)  {    if (setExternClock(mode->Clock))      currentGraphicsClock = mode->Clock;    else      return(FALSE);  }  if (vgaNewVideoState == NULL) {    if (size < sizeof(vgaHWRec))      size = sizeof(vgaHWRec);    vgaNewVideoState = (void *)xcalloc(1,size);    /*     * initialize default colormap for monochrome     */    for (i=0; i<3;   i++) new->DAC[i] = 0x00;    for (i=3; i<768; i++) new->DAC[i] = 0x3F;#ifdef MONOVGA    i = BLACK_VALUE * 3;    new->DAC[i++] = vga256InfoRec.blackColour.red;    new->DAC[i++] = vga256InfoRec.blackColour.green;    new->DAC[i] = vga256InfoRec.blackColour.blue;    i = WHITE_VALUE * 3;    new->DAC[i++] = vga256InfoRec.whiteColour.red;    new->DAC[i++] = vga256InfoRec.whiteColour.green;    new->DAC[i] = vga256InfoRec.whiteColour.blue;    i = OVERSCAN_VALUE * 3;    new->DAC[i++] = 0x00;    new->DAC[i++] = 0x00;    new->DAC[i] = 0x00;#endif#ifndef MONOVGA    /* Initialise overscan register */    new->Attribute[17] = 0xFF;#endif  }  /*   * Get NoClock.  Set it to -1 if using an external clock setting program   */  if (vga256InfoRec.clockprog)    new->NoClock = -1;  else    new->NoClock = mode->Clock;  /*   * compute correct Hsync & Vsync polarity    */  if ((mode->Flags & (V_PHSYNC | V_NHSYNC))      && (mode->Flags & (V_PVSYNC | V_NVSYNC)))      {	new->MiscOutReg = 0x23;	if (mode->Flags & V_NHSYNC) new->MiscOutReg |= 0x40;	if (mode->Flags & V_NVSYNC) new->MiscOutReg |= 0x80;      }      else      {	int VDisplay = mode->VDisplay;	if (mode->Flags & V_DBLSCAN)	  VDisplay *= 2;	if      (VDisplay < 400)		new->MiscOutReg = 0xA3;		/* +hsync -vsync */	else if (VDisplay < 480)		new->MiscOutReg = 0x63;		/* -hsync +vsync */	else if (VDisplay < 768)		new->MiscOutReg = 0xE3;		/* -hsync -vsync */	else		new->MiscOutReg = 0x23;		/* +hsync +vsync */      }  if (!vga256InfoRec.clockprog)    new->MiscOutReg |= (new->NoClock & 0x03) << 2;    /*   * Time Sequencer   */#ifdef XF86VGA16  new->Sequencer[0] = 0x02;#else  new->Sequencer[0] = 0x00;#endif  if (mode->Flags & V_CLKDIV2)     new->Sequencer[1] = 0x09;  else    new->Sequencer[1] = 0x01;#ifdef MONOVGA  new->Sequencer[2] = 1 << BIT_PLANE;#else  new->Sequencer[2] = 0x0F;#endif  new->Sequencer[3] = 0x00;                             /* Font select */#if defined(MONOVGA) || defined(XF86VGA16)  new->Sequencer[4] = 0x06;                             /* Misc */#else  new->Sequencer[4] = 0x0E;                             /* Misc */#endif  if (!mode->CrtcVAdjusted && (mode->Flags & V_INTERLACE) &&      vgaInterlaceType == VGA_DIVIDE_VERT) {    mode->CrtcVDisplay >>= 1;    mode->CrtcVSyncStart >>= 1;    mode->CrtcVSyncEnd >>= 1;    mode->CrtcVTotal >>= 1;    mode->CrtcVAdjusted = TRUE;  }  /*   * CRTC Controller   */  new->CRTC[0]  = (mode->CrtcHTotal >> 3) - 5;  new->CRTC[1]  = (mode->CrtcHDisplay >> 3) - 1;  new->CRTC[2]  = (mode->CrtcHSyncStart >> 3) -1;  new->CRTC[3]  = ((mode->CrtcHSyncEnd >> 3) & 0x1F) | 0x80;  i = (((mode->CrtcHSkew << 2) + 0x10) & ~0x1F);  if (i < 0x80)    new->CRTC[3] |= i;  new->CRTC[4]  = (mode->CrtcHSyncStart >> 3);  new->CRTC[5]  = (((mode->CrtcHSyncEnd >> 3) & 0x20 ) << 2 )    | (((mode->CrtcHSyncEnd >> 3)) & 0x1F);  new->CRTC[6]  = (mode->CrtcVTotal - 2) & 0xFF;  new->CRTC[7]  = (((mode->CrtcVTotal -2) & 0x100) >> 8 )    | (((mode->CrtcVDisplay -1) & 0x100) >> 7 )      | ((mode->CrtcVSyncStart & 0x100) >> 6 )	| (((mode->CrtcVSyncStart) & 0x100) >> 5 )	  | 0x10	    | (((mode->CrtcVTotal -2) & 0x200)   >> 4 )	      | (((mode->CrtcVDisplay -1) & 0x200) >> 3 )		| ((mode->CrtcVSyncStart & 0x200) >> 2 );  new->CRTC[8]  = 0x00;  new->CRTC[9]  = ((mode->CrtcVSyncStart & 0x200) >>4) | 0x40;  if (mode->Flags & V_DBLSCAN)    new->CRTC[9] |= 0x80;  new->CRTC[10] = 0x00;  new->CRTC[11] = 0x00;  new->CRTC[12] = 0x00;  new->CRTC[13] = 0x00;  new->CRTC[14] = 0x00;  new->CRTC[15] = 0x00;  new->CRTC[16] = mode->CrtcVSyncStart & 0xFF;  new->CRTC[17] = (mode->CrtcVSyncEnd & 0x0F) | 0x20;  new->CRTC[18] = (mode->CrtcVDisplay -1) & 0xFF;  new->CRTC[19] = vga256InfoRec.displayWidth >> 4;  /* just a guess */  new->CRTC[20] = 0x00;  new->CRTC[21] = mode->CrtcVSyncStart & 0xFF;   new->CRTC[22] = (mode->CrtcVSyncEnd + 1) & 0xFF;#if defined(MONOVGA) || defined(XF86VGA16)  new->CRTC[23] = 0xE3;#else  new->CRTC[23] = 0xC3;#endif  new->CRTC[24] = 0xFF;  /*   * Graphics Display Controller   */  new->Graphics[0] = 0x00;  new->Graphics[1] = 0x00;  new->Graphics[2] = 0x00;  new->Graphics[3] = 0x00;#ifdef MONOVGA  new->Graphics[4] = BIT_PLANE;  new->Graphics[5] = 0x00;#else  new->Graphics[4] = 0x00;#ifdef XF86VGA16  new->Graphics[5] = 0x02;#else  new->Graphics[5] = 0x40;#endif#endif  new->Graphics[6] = 0x05;   /* only map 64k VGA memory !!!! */  new->Graphics[7] = 0x0F;  new->Graphics[8] = 0xFF;  #ifdef MONOVGA  /* Initialise the Mono map according to which bit-plane gets written to */  for (i=0; i<16; i++)    if (i & (1<<BIT_PLANE))      new->Attribute[i] = WHITE_VALUE;    else      new->Attribute[i] = BLACK_VALUE;  new->Attribute[16] = 0x01;  /* -VGA2- */ /* wrong for the ET4000 */  new->Attribute[17] = OVERSCAN_VALUE;  /* -VGA2- */#else  new->Attribute[0]  = 0x00; /* standard colormap translation */  new->Attribute[1]  = 0x01;  new->Attribute[2]  = 0x02;  new->Attribute[3]  = 0x03;  new->Attribute[4]  = 0x04;  new->Attribute[5]  = 0x05;  new->Attribute[6]  = 0x06;  new->Attribute[7]  = 0x07;  new->Attribute[8]  = 0x08;  new->Attribute[9]  = 0x09;  new->Attribute[10] = 0x0A;  new->Attribute[11] = 0x0B;  new->Attribute[12] = 0x0C;  new->Attribute[13] = 0x0D;  new->Attribute[14] = 0x0E;  new->Attribute[15] = 0x0F;#ifdef XF86VGA16  new->Attribute[16] = 0x81; /* wrong for the ET4000 */  new->Attribute[17] = 0x00; /* GJA -- overscan. */#else  new->Attribute[16] = 0x41; /* wrong for the ET4000 */#endif  /*   * Attribute[17] is the overscan, and is initalised above only at startup   * time, and not when mode switching.   */#endif  new->Attribute[18] = 0x0F;  new->Attribute[19] = 0x00;  new->Attribute[20] = 0x00;#ifdef PC98_EGC  outb (0x7c, 0x00);  /* set to 16color mode */  outb(0x6a, 0x01);  /* set EGC enable */  outb(0x7c, 0xc0); /* GRCG enable, RMW mode */  outb(0x6a, 0x07);  outb(0x6a, 0x05);  outb(0x6a, 0x06);     for (i = 0; i < 4 ; i++)     {             outb (0x7e,0xff);     }       /* set up VGA registers */     outw (EGC_READ, 0x0000) ;     outw (EGC_MASK, 0xffff) ;     outw (EGC_READ ,0x40ff) ;     outw (EGC_ADD, 0x0000) ;     outw (EGC_LENGTH, 0x000f) ;#endif /* PC98_EGC */  return(TRUE);}/* * vgaGetClocks -- *      get the dot-clocks via a BIG BAD hack ... */voidvgaGetClocks(int num,#if NeedNestedPrototypes     Bool (*ClockFunc)(int))#else     Bool (*ClockFunc)())#endif{  xf86GetClocks(num, ClockFunc, vgaProtect, vgaSaveScreen,		(vgaIOBase + 0x0A), 0x08, 1, 28322, &vga256InfoRec);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -