📄 pcvt_sup.c
字号:
outb(addr_6845, CRTC_STARTADRL); outb(addr_6845+1, 0);#if !PCVT_KBD_FIFO splx(x);#endif /* !PCVT_KBD_FIFO */ select_vga_charset(vsp->vga_charset); if(vsp->maxcol != cols) vga_col(vsp, vsp->maxcol); /* select 80/132 columns */ outb(addr_6845, CRTC_CURSORH); /* select high register */ outb(addr_6845+1, vsp->cur_offset >> 8); outb(addr_6845, CRTC_CURSORL); /* select low register */ outb(addr_6845+1, vsp->cur_offset); if(vsp->cursor_on) { outb(addr_6845, CRTC_CURSTART); /* select high register */ outb(addr_6845+1, vsp->cursor_start); outb(addr_6845, CRTC_CUREND); /* select low register */ outb(addr_6845+1, vsp->cursor_end); } else { sw_cursor(0); } if(adaptor_type == VGA_ADAPTOR) { unsigned i; /* switch VGA DAC palette entries */ for(i = 0; i < NVGAPEL; i++) vgapaletteio(i, &vsp->palette[i], 1); } update_led(); /* update led's */ update_hp(vsp); /* update fkey labels, if present */}#endif /* !PCVT_USL_VT_COMPAT *//*---------------------------------------------------------------------------* * test if it is a vga *---------------------------------------------------------------------------*/intvga_test(void){ u_char old, new, check; outb(addr_6845,CRTC_CURSTART); /* cursor start reg */ old = inb(addr_6845+1); /* get current value */ new = old | CURSOR_ON_BIT; /* set cursor on by setting bit 5 on */ outb(addr_6845,CRTC_CURSTART); /* cursor start reg */ outb(addr_6845+1,new); /* cursor should be on now */ outb(addr_6845,CRTC_CURSTART); /* cursor start reg */ check = inb(addr_6845+1); /* get current value */ if(check != new) { outb(addr_6845,CRTC_CURSTART); /* cursor start reg */ outb(addr_6845+1,old); /* failsafe */ return(0); /* must be ega */ } new = old & ~CURSOR_ON_BIT; /* turn cursor off by clearing bit 5 */ outb(addr_6845,CRTC_CURSTART); /* cursor start reg */ outb(addr_6845+1,new); /* cursor should be off now */ outb(addr_6845,CRTC_CURSTART); /* cursor start reg */ check = inb(addr_6845+1); /* get current value */ if(check != new) { outb(addr_6845,CRTC_CURSTART); /* cursor start reg */ outb(addr_6845+1,old); /* failsafe */ return(0); /* must be ega */ } outb(addr_6845,CRTC_CURSTART); /* cursor start reg */ outb(addr_6845+1,old); /* failsafe */ return(1); /* vga */}/*---------------------------------------------------------------------------* * convert upper/lower sixel font array to vga font array *---------------------------------------------------------------------------*/voidsixel_vga(struct sixels *sixelp, u_char *vgachar){ register int i, j; register int shift; register u_char mask; for(j = 0; j < 16; j++) vgachar[j] = 0; mask = 0x01; for(j = 0; j < 6; j++) { for(i = 0, shift = 7; i < 8; i++, shift--) vgachar[j] |= ((((sixelp->upper[i]) & mask) >> j) << shift); mask <<= 1; } mask = 0x01; for(j = 0; j < 4; j++) { for(i = 0, shift = 7; i < 8; i++, shift--) vgachar[j+6] |= ((((sixelp->lower[i]) & mask) >>j) << shift); mask <<= 1; }}/*---------------------------------------------------------------------------* * Expand 8x10 EGA/VGA characters to 8x16 EGA/VGA characters *---------------------------------------------------------------------------*/voidvga10_vga16(u_char *invga, u_char *outvga){ register int i,j; /* * Keep the top and bottom scanlines the same and double every scan * line in between. */ outvga[0] = invga[0]; outvga[1] = invga[1]; outvga[14] = invga[8]; outvga[15] = invga[9]; for(i = j = 2;i < 8 && j < 14;i++,j += 2) { outvga[j] = invga[i]; outvga[j+1] = invga[i]; }}/*---------------------------------------------------------------------------* * Expand 8x10 EGA/VGA characters to 8x14 EGA/VGA characters *---------------------------------------------------------------------------*/voidvga10_vga14(u_char *invga, u_char *outvga){ register int i; /* * Double the top two and bottom two scanlines and copy everything * in between. */ outvga[0] = invga[0]; outvga[1] = invga[0]; outvga[2] = invga[1]; outvga[3] = invga[1]; outvga[10] = invga[8]; outvga[11] = invga[8]; outvga[12] = invga[9]; outvga[13] = invga[9]; for(i = 2;i < 8;i++) outvga[i+2] = invga[i];}/*---------------------------------------------------------------------------* * Expand 8x10 EGA/VGA characters to 8x10 EGA/VGA characters *---------------------------------------------------------------------------*/voidvga10_vga10(u_char *invga, u_char *outvga){ register int i; for(i = 0;i < 10;i++) outvga[i] = invga[i];}/*---------------------------------------------------------------------------* * Contract 8x10 EGA/VGA characters to 8x8 EGA/VGA characters *---------------------------------------------------------------------------*/voidvga10_vga8(u_char *invga, u_char *outvga){ /* Skip scanlines 3 and 7 */ outvga[0] = invga[0]; outvga[1] = invga[1]; outvga[2] = invga[2]; outvga[3] = invga[4]; outvga[4] = invga[5]; outvga[5] = invga[6]; outvga[6] = invga[8]; outvga[7] = invga[9];}/*---------------------------------------------------------------------------* * force a vga card to behave like an ega for debugging *---------------------------------------------------------------------------*/#if FORCE_EGAvoidforce_ega(void){ unsigned char vgareg; if(adaptor_type == VGA_ADAPTOR) { adaptor_type = EGA_ADAPTOR; totalfonts = 4; vgareg = inb(GN_MISCOUTR); /* Miscellaneous Output Register */ vgareg |= 128; /* Set 350 scanline mode */ vgareg &= ~64; outb(GN_MISCOUTW,vgareg); }}#endif /* FORCE_EGA *//*---------------------------------------------------------------------------* * disconnect attribute bit 3 from generating intensity * (and use it for a second character set !) *---------------------------------------------------------------------------*/voidset_2ndcharset(void){ if(color) /* prepare to access index register! */ inb(GN_INPSTAT1C); else inb(GN_INPSTAT1M); /* select color plane enable reg, caution: set ATC access bit ! */ outb(ATC_INDEX, (ATC_COLPLEN | ATC_ACCESS)); outb(ATC_DATAW, 0x07); /* disable plane 3 */}#if PCVT_SCREENSAVER#if PCVT_PRETTYSCRNS/*---------------------------------------------------------------------------* * produce some kinda random number, had a look into the system library... *---------------------------------------------------------------------------*/static u_shortgetrand(void){#if !PCVT_FREEBSD extern struct timeval time; /* time-of-day register */#endif static unsigned long seed = 1; register u_short res = (u_short)seed; seed = seed * 1103515245L + time.tv_sec; return res;}/*---------------------------------------------------------------------------* * produce "nice" screensaving .... *---------------------------------------------------------------------------*/static voidscrnsv_blink(void * arg){ static struct rgb blink_rgb[8] = { {63, 63, 63}, /* white */ {0, 63, 42}, /* pale green */ {63, 63, 0}, /* yellow */ {63, 21, 63}, /* violet */ {42, 63, 0}, /* yellow-green */ {63, 42, 0}, /* amber */ {63, 42, 42}, /* rose */ {21, 42, 42} /* cyan */ }; register u_short r = getrand(); unsigned pos = (r % (scrnsv_size / 2)); *scrnsv_current = /* (0 << 8) + */ ' '; scrnsv_current = vsp->Crtat + pos; *scrnsv_current = (7 /* LIGHTGRAY */ << 8) + '*'; if(adaptor_type == VGA_ADAPTOR) vgapaletteio(7 /* LIGHTGRAY */, &blink_rgb[(r >> 4) & 7], 1); timeout(scrnsv_blink, NULL, hz);}#endif /* PCVT_PRETTYSCRNS *//*---------------------------------------------------------------------------* * set timeout time *---------------------------------------------------------------------------*/#ifndef XSERVERstatic voidpcvt_set_scrnsv_tmo(int timeout)#elsevoidpcvt_set_scrnsv_tmo(int timeout)#endif /* XSERVER */{ int x = splhigh(); if(scrnsv_timeout) untimeout(scrnsv_timedout, NULL); scrnsv_timeout = timeout; pcvt_scrnsv_reset(); /* sanity */ splx(x); if(timeout == 0 && savedscreen) { /* release buffer when screen saver turned off */ free(savedscreen, M_TEMP); savedscreen = (u_short *)0; }}/*---------------------------------------------------------------------------* * we were timed out *---------------------------------------------------------------------------*/static voidscrnsv_timedout(void *arg){ /* this function is called by timeout() */ /* raise priority to avoid conflicts with kbd intr */ int x = spltty(); /* * due to some undefined problems with video adaptor RAM * access timing, the following has been splitted into * two pieces called subsequently with a time difference * of 100 millisec */ if(++scrnsv_active == 1) { register size_t s; /* * first, allocate a buffer * do only if none allocated yet or another size required * this reduces malloc() overhead by avoiding successive * calls to malloc() and free() if they would have requested * the same buffer * * XXX This is inherited from old days where no buffering * happened at all. Meanwhile we should use the standard * screen buffer instead. Any volunteers? :-) [At least, * this code proved to work...] */ s = sizeof(u_short) * vsp->screen_rowsize * vsp->maxcol; if(savedscreen == (u_short *)0 || s != scrnsv_size) { /* really need to allocate */ if(savedscreen) free(savedscreen, M_TEMP); scrnsv_size = s; if((savedscreen = (u_short *)malloc(s, M_TEMP, M_NOWAIT)) == (u_short *)0) { /* * didn't get the buffer memory, * turn off screen saver */ scrnsv_timeout = scrnsv_active = 0; splx(x); return; } } /* save current screen */ bcopy(vsp->Crtat, savedscreen, scrnsv_size); /* on VGA's, make sure palette is set to blank screen */ if(adaptor_type == VGA_ADAPTOR) { struct rgb black = {0, 0, 0}; vgapaletteio(0 /* BLACK */, &black, 1); } /* prepare for next time... */ timeout(scrnsv_timedout, NULL, hz / 10); } else { /* second call, now blank the screen */ /* fill screen with blanks */ fillw(/* (BLACK<<8) + */ ' ', vsp->Crtat, scrnsv_size / 2);#if PCVT_PRETTYSCRNS scrnsv_current = vsp->Crtat; timeout(scrnsv_blink, NULL, hz);#endif /* PCVT_PRETTYSCRNS */ sw_cursor(0); /* cursor off on mda/cga */ } splx(x);}/*---------------------------------------------------------------------------* * interface to screensaver "subsystem" *---------------------------------------------------------------------------*/voidpcvt_scrnsv_reset(void){ /* * to save lotta time with superfluous timeout()/untimeout() calls * when having massive output operations, we remember the last * second of kernel timer we've rescheduled scrnsv_timedout() */ static long last_schedule = 0L; register int x = splhigh(); int reschedule = 0; if((scrnsv_active == 1 || scrnsv_timeout) && last_schedule != time.tv_sec) { last_schedule = time.tv_sec; reschedule = 1; untimeout(scrnsv_timedout, NULL); } if(scrnsv_active) {#if PCVT_PRETTYSCRNS if(scrnsv_active > 1) untimeout(scrnsv_blink, NULL);#endif /* PCVT_PRETTYSCRNS */ bcopy(savedscreen, vsp->Crtat, scrnsv_size); if(adaptor_type == VGA_ADAPTOR) { /* back up VGA palette info */ vgapaletteio(0 /* BLACK */, &vsp->palette[0], 1);#if PCVT_PRETTYSCRNS vgapaletteio(7 /* LIGHTGRAY */, &vsp->palette[7], 1);#endif /* PCVT_PRETTYSCRNS */ } scrnsv_active = 0; if(vsp->cursor_on) sw_cursor(1); /* cursor on */ } if(reschedule) { /* mark next timeout */ timeout(scrnsv_timedout, NULL, scrnsv_timeout * hz); } splx(x);}#endif /* PCVT_SCREENSAVER *//*---------------------------------------------------------------------------* * switch cursor on/off *---------------------------------------------------------------------------*/voidsw_cursor(int onoff){ if(adaptor_type == EGA_ADAPTOR) { int start, end; if(onoff) { start = vsp->cursor_start; end = vsp->cursor_end; } else { int cs = vs[current_video_screen].vga_charset; cs = (cs < 0) ? 0 : ((cs < totalfonts) ? cs : totalfonts-1); start = (vgacs[cs].char_scanlines & 0x1F) + 1; end = 0; } outb(addr_6845,CRTC_CURSTART); /* cursor start reg */ outb(addr_6845+1, start); outb(addr_6845,CRTC_CUREND); /* cursor end reg */ outb(addr_6845+1, end); } else /* mda, cga, vga */ { outb(addr_6845,CRTC_CURSTART); /* cursor start reg */ if(onoff) outb(addr_6845+1, vsp->cursor_start); else outb(addr_6845+1, CURSOR_ON_BIT); }}/*---------------------------------------------------------------------------* * cold init support, if a mono monitor is attached to a * vga or ega, it comes up with a mda emulation. switch * board to generic ega/vga mode in this case. *---------------------------------------------------------------------------*/voidmda2egaorvga(void){ /* * program sequencer to access * video ram */ /* synchronous reset */ outb(TS_INDEX, TS_SYNCRESET); outb(TS_DATA, 0x01); /* write to map 0 & 1 */ outb(TS_INDEX, TS_WRPLMASK); outb(TS_DATA, 0x03); /* odd-even addressing */ outb(TS_INDEX, TS_MEMMODE); outb(TS_DATA, 0x03); /* clear synchronous reset */ outb(TS_INDEX, TS_SYNCRESET); outb(TS_DATA, 0x03); /* * program graphics controller * to access character * generator */ /* select map 0 for cpu reads */ outb(GDC_INDEX, GDC_RDPLANESEL); outb(GDC_DATA, 0x00); /* enable odd-even addressing */ outb(GDC_INDEX, GDC_MODE); outb(GDC_DATA, 0x10); /* map starts at 0xb000 */ outb(GDC_INDEX, GDC_MISC); outb(GDC_DATA, 0x0a);}#endif /* NVT > 0 *//* ------------------------- E O F ------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -