2 * Copyright (c) 1999 Hellmuth Michaelis
4 * Copyright (c) 1992, 1995 Hellmuth Michaelis and Joerg Wunsch.
6 * Copyright (c) 1992, 1993 Brian Dunford-Shore and Scott Turner.
8 * Copyright (C) 1992, 1993 Soeren Schmidt.
10 * All rights reserved.
12 * For the sake of compatibility, portions of this code regarding the
13 * X server interface are taken from Soeren Schmidt's syscons driver.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. All advertising materials mentioning features or use of this software
24 * must display the following acknowledgement:
25 * This product includes software developed by Hellmuth Michaelis,
26 * Brian Dunford-Shore, Joerg Wunsch, Scott Turner and Soeren Schmidt.
27 * 4. The name authors may not be used to endorse or promote products
28 * derived from this software without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
31 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
33 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
34 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
35 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
39 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 /*---------------------------------------------------------------------------*
44 * pcvt_sup.c VT220 Driver Support Routines
45 * ---------------------------------------------
47 * Last Edit-Date: [Thu Dec 30 17:01:03 1999]
49 * $FreeBSD: src/sys/i386/isa/pcvt/pcvt_sup.c,v 1.16 1999/12/30 16:17:10 hm Exp $
51 *---------------------------------------------------------------------------*/
56 #include <i386/isa/pcvt/pcvt_hdr.h> /* global include */
58 #include <sys/resource.h>
60 static void vid_cursor ( struct cursorshape *data );
61 static void vgasetfontattr ( struct vgafontattr *data );
62 static void vgagetfontattr ( struct vgafontattr *data );
63 static void vgaloadchar ( struct vgaloadchar *data );
64 static void vid_getscreen ( struct screeninfo *data, Dev_t dev );
65 static void vid_setscreen ( struct screeninfo *data, Dev_t dev );
66 static void setchargen ( void );
67 static void setchargen3 ( void );
68 static void resetchargen ( void );
69 static void vgareadpel ( struct vgapel *data, Dev_t dev );
70 static void vgawritepel ( struct vgapel *data, Dev_t dev );
71 static void vgapcvtid ( struct pcvtid *data );
72 static void vgapcvtinfo ( struct pcvtinfo *data );
75 static unsigned char * compute_charset_base ( unsigned fontset );
78 static struct callout_handle async_update_ch =
79 CALLOUT_HANDLE_INITIALIZER(&async_update_ch);
82 static void scrnsv_timedout ( void *arg );
83 static struct callout_handle scrnsv_timeout_ch =
84 CALLOUT_HANDLE_INITIALIZER(&scrnsv_timeout_ch);
85 static u_short *savedscreen = (u_short *)0; /* ptr to screen contents */
86 static size_t scrnsv_size = (size_t)-1; /* size of saved image */
89 static unsigned scrnsv_timeout = 0; /* initially off */
90 static void pcvt_set_scrnsv_tmo ( int timeout );/* else declared global */
94 static u_short *scrnsv_current = (u_short *)0; /* attention char ptr */
95 static struct callout_handle scrnsv_blink_ch =
96 CALLOUT_HANDLE_INITIALIZER(&scrnsv_blink_ch);
97 static void scrnsv_blink ( void * );
98 static u_short getrand ( void );
99 #endif /* PCVT_PRETTYSCRNS */
101 #endif /* PCVT_SCREENSAVER */
104 /*---------------------------------------------------------------------------*
106 *---------------------------------------------------------------------------*/
108 vgaioctl(Dev_t dev, int cmd, caddr_t data, int flag)
110 if(minor(dev) >= PCVT_NSCREENS)
114 * Some of the commands are not applicable if the vt in question, or the
115 * current vt is in graphics mode (i.e., the X server acts on it); they
116 * will cause an EAGAIN (resource temporarily unavailable) to be returned.
120 #if PCVT_USL_VT_COMPAT
121 #define is_dev_grafx vs[minor(dev)].vt_status & VT_GRAFX
122 #define is_current_grafx vsp->vt_status & VT_GRAFX
123 #else /* old X interface */
124 #define is_dev_grafx pcvt_xmode
125 #define is_current_grafx pcvt_xmode
126 #endif /* PCVT_USL_VT_COMPAT */
128 #define is_dev_grafx 0 /* not applicable */
129 #define is_current_grafx 0
137 vid_cursor((struct cursorshape *)data);
141 if((adaptor_type != VGA_ADAPTOR) &&
142 (adaptor_type != EGA_ADAPTOR))
146 vgaloadchar((struct vgaloadchar *)data);
150 if((adaptor_type != VGA_ADAPTOR) &&
151 (adaptor_type != EGA_ADAPTOR))
156 #endif /* PCVT_SCREENSAVER */
158 vgasetfontattr((struct vgafontattr *)data);
162 if((adaptor_type != VGA_ADAPTOR) &&
163 (adaptor_type != EGA_ADAPTOR))
165 vgagetfontattr((struct vgafontattr *)data);
170 #if defined XSERVER && !PCVT_USL_VT_COMPAT
171 /* avoid screen switch if using old X mode */
174 #endif /* XSERVER && !PCVT_USL_VT_COMPAT */
178 #endif /* PCVT_SCREENSAVER */
180 vid_setscreen((struct screeninfo *)data, dev);
184 vid_getscreen((struct screeninfo *)data, dev);
188 if(adaptor_type != VGA_ADAPTOR)
192 vgareadpel((struct vgapel *)data, dev);
196 if(adaptor_type != VGA_ADAPTOR)
200 vgawritepel((struct vgapel *)data, dev);
207 pcvt_set_scrnsv_tmo(*(int *)data);
210 #endif /* PCVT_SCREENSAVER */
213 vgapcvtid((struct pcvtid *)data);
217 vgapcvtinfo((struct pcvtinfo *)data);
223 if(*(int *)data == 80)
224 (void)vt_col(&vs[minor(dev)], SCR_COL80);
225 else if(*(int *)data == 132)
227 if(vt_col(&vs[minor(dev)], SCR_COL132) == 0)
228 return EINVAL; /* not a VGA */
236 reallocate_scrollbuffer(vsp, *(u_short *)data);
241 /* do nothing here */
250 #undef is_current_grafx
253 /*---------------------------------------------------------------------------*
254 * video ioctl - return driver id
255 *---------------------------------------------------------------------------*/
257 vgapcvtid(struct pcvtid *data)
259 snprintf(data->name, sizeof(data->name), "%s", PCVTIDNAME);
260 data->rmajor = PCVTIDMAJOR;
261 data->rminor = PCVTIDMINOR;
264 /*---------------------------------------------------------------------------*
265 * video ioctl - return driver compile time options data
266 *---------------------------------------------------------------------------*/
268 vgapcvtinfo(struct pcvtinfo *data)
271 data->opsys = CONF_NETBSD;
272 data->opsysrel = PCVT_NETBSD;
274 data->opsys = CONF_FREEBSD;
275 data->opsysrel = PCVT_FREEBSD;
277 data->opsys = CONF_UNKNOWNOPSYS;
281 data->nscreens = PCVT_NSCREENS;
282 data->scanset = PCVT_SCANSET;
283 data->updatefast= PCVT_UPDATEFAST;
284 data->updateslow= PCVT_UPDATESLOW;
285 data->sysbeepf = PCVT_SYSBEEPF;
287 #if PCVT_NETBSD || PCVT_FREEBSD >= 200
288 data->pcburst = PCVT_PCBURST;
294 data->kbd_fifo_sz = PCVT_KBD_FIFO_SZ;
296 data->kbd_fifo_sz = 0;
299 data->compile_opts = (0
310 #if PCVT_CTRL_ALT_DEL
334 #if PCVT_BACKUP_FONTS
337 #if PCVT_SW0CNOUTP /* was FORCE8BIT */
355 #if PCVT_USL_VT_COMPAT
358 #if PCVT_PORTIO_DELAY
361 #if PCVT_INHIBIT_NUMLOCK
362 | CONF_INHIBIT_NUMLOCK
370 #if PCVT_NOFASTSCROLL
373 #if PCVT_SLOW_INTERRUPT
374 | CONF_SLOW_INTERRUPT
376 #if PCVT_NO_LED_UPDATE
382 /*---------------------------------------------------------------------------*
383 * video ioctl - set cursor appearence
384 *---------------------------------------------------------------------------*/
386 vid_cursor(struct cursorshape *data)
394 /* for which virtual screen, -1 for current */
395 screen = data->screen_no;
397 if(screen == -1) /* current ? */
398 screen = current_video_screen;
399 else if(screen > totalscreens - 1)
400 screen = totalscreens - 1;
404 if(adaptor_type == VGA_ADAPTOR || adaptor_type == EGA_ADAPTOR)
406 character_set = vs[screen].vga_charset;
407 character_set = (character_set < 0) ? 0 :
408 ((character_set < totalfonts) ?
412 line_height = vgacs[character_set].char_scanlines & 0x1F;
414 else if(adaptor_type == MDA_ADAPTOR)
420 line_height = 8; /* CGA */
423 start = (data->start < 0) ? 0 :
424 ((data->start > line_height) ? line_height : data->start);
426 if((vga_family == VGA_F_TRI) && (start == 0))
429 end = (data->end < 0) ? 0 :
430 ((data->end > line_height) ? line_height : data->end);
432 vs[screen].cursor_start = start;
433 vs[screen].cursor_end = end;
435 if(screen == current_video_screen)
437 outb(addr_6845,CRTC_CURSTART); /* cursor start reg */
438 outb(addr_6845+1, start);
439 outb(addr_6845,CRTC_CUREND); /* cursor end reg */
440 outb(addr_6845+1, end);
444 /*---------------------------------------------------------------------------*
445 * ega/vga ioctl - set font attributes
446 *---------------------------------------------------------------------------*/
448 vgasetfontattr(struct vgafontattr *data)
451 int vga_character_set;
452 int lines_per_character;
456 vga_character_set = data->character_set;
457 vga_character_set = (vga_character_set < 0) ? 0 :
458 ((vga_character_set < totalfonts) ?
459 vga_character_set : totalfonts-1);
461 vgacs[vga_character_set].loaded = data->font_loaded;
463 /* Limit Characters to 32 scanlines doubled */
464 vgacs[vga_character_set].char_scanlines =
465 (data->character_scanlines & 0x1F)
466 | 0x40; /* always set bit 9 of line cmp reg */
468 if(adaptor_type == EGA_ADAPTOR)
469 /* ...and screen height to scan 350 lines */
470 vgacs[vga_character_set].scr_scanlines =
471 (data->screen_scanlines > 0x5d) ?
472 0x5d : data->screen_scanlines;
474 /* ...and screen height to scan 480 lines */
475 vgacs[vga_character_set].scr_scanlines =
476 (data->screen_scanlines > 0xdF) ?
477 0xdF : data->screen_scanlines;
479 lines_per_character =
480 (int)(0x1F & vgacs[vga_character_set].char_scanlines)+1;
482 totscanlines = 0x101 + (int)vgacs[vga_character_set].scr_scanlines;
484 size = data->screen_size;
486 if(adaptor_type == EGA_ADAPTOR)
490 case SIZ_25ROWS: /* This case is always OK */
494 if(totscanlines/lines_per_character >= 35)
502 if(totscanlines/lines_per_character >= 43)
504 else if(totscanlines/lines_per_character >= 35)
515 case SIZ_25ROWS: /* This case is always OK */
519 if(totscanlines/lines_per_character >= 28)
526 if(totscanlines/lines_per_character >= 40)
528 else if(totscanlines/lines_per_character >= 28)
536 if(totscanlines/lines_per_character >= 50)
538 else if(totscanlines/lines_per_character >= 40)
540 else if(totscanlines/lines_per_character >= 28)
548 vgacs[vga_character_set].screen_size = size;
550 for (i = 0;i < PCVT_NSCREENS;i++)
552 if(vga_character_set == vs[i].vga_charset)
553 set_charset(&(vs[i]),vga_character_set);
556 #if !PCVT_USL_VT_COMPAT
557 vgapage(current_video_screen);
559 switch_screen(current_video_screen, 0, 0);
560 #endif /* !PCVT_USL_VT_COMPAT */
564 /*---------------------------------------------------------------------------*
565 * ega/vga ioctl - get font attributes
566 *---------------------------------------------------------------------------*/
568 vgagetfontattr(struct vgafontattr *data)
570 int vga_character_set;
572 vga_character_set = data->character_set;
573 vga_character_set = (vga_character_set < 0) ? 0 :
574 ((vga_character_set < (int)totalfonts) ?
576 (int)(totalfonts-1));
578 data->character_set = (int)vga_character_set;
580 data->font_loaded = (int)vgacs[vga_character_set].loaded;
582 data->character_scanlines =
583 (int)vgacs[vga_character_set].char_scanlines
584 & 0x1f; /* do not display the overflow bits */
586 data->screen_scanlines = (int)vgacs[vga_character_set].scr_scanlines;
588 data->screen_size = (int)vgacs[vga_character_set].screen_size;
591 /*---------------------------------------------------------------------------*
592 * ega/vga ioctl - load a character shape into character set
593 *---------------------------------------------------------------------------*/
595 vgaloadchar(struct vgaloadchar *data)
597 int vga_character_set;
599 int lines_per_character;
601 vga_character_set = data->character_set;
602 vga_character_set = (vga_character_set < 0) ? 0 :
603 ((vga_character_set < (int)totalfonts) ?
604 vga_character_set : (int)(totalfonts-1));
606 character = (data->character < 0) ? 0 :
607 ((data->character > 255) ? 255 : data->character);
609 lines_per_character = (int)data->character_scanlines;
610 lines_per_character = (lines_per_character < 0) ? 0 :
611 ((lines_per_character > 32) ? 32 : lines_per_character);
613 loadchar(vga_character_set,character,lines_per_character,
617 /*---------------------------------------------------------------------------*
618 * video ioctl - get screen information
619 *---------------------------------------------------------------------------*/
621 vid_getscreen(struct screeninfo *data, Dev_t dev)
623 int device = minor(dev);
624 data->adaptor_type = adaptor_type; /* video adapter installed */
625 data->monitor_type = color; /* monitor type installed */
626 data->totalfonts = totalfonts; /* no of downloadble fonts */
627 data->totalscreens = totalscreens; /* no of virtual screens */
628 data->screen_no = device; /* this screen number */
629 data->current_screen = current_video_screen; /* displayed screen no */
631 data->screen_size = vgacs[(vs[device].vga_charset)].screen_size;
632 /* pure VT mode or HP/VT mode */
633 data->pure_vt_mode = vs[device].vt_pure_mode;
634 data->vga_family = vga_family; /* manufacturer, family */
635 data->vga_type = vga_type; /* detected chipset type */
636 data->vga_132 = can_do_132col; /* 132 column support */
637 data->force_24lines = vs[device].force24; /* force 24 lines */
640 /*---------------------------------------------------------------------------*
641 * video ioctl - set screen information
642 *---------------------------------------------------------------------------*/
644 vid_setscreen(struct screeninfo *data, Dev_t dev)
648 if(data->current_screen == -1)
654 if(data->current_screen >= PCVT_NSCREENS)
656 screen = data->current_screen;
661 #if defined XSERVER && PCVT_USL_VT_COMPAT
663 int x = spltty(), waitfor = screen + 1;
664 /* if the vt is yet to be released by a process, wait here */
665 if(vs[screen].vt_status & VT_WAIT_REL)
666 (void)usl_vt_ioctl(dev, VT_WAITACTIVE,
667 (caddr_t)&waitfor, 0, 0);
670 /* make sure the switch really happened */
671 if(screen != current_video_screen)
672 return; /* XXX should say "EAGAIN" here */
673 #endif /* defined XSERVER && PCVT_USL_VT_COMPAT */
675 if((data->screen_size != -1) || (data->force_24lines != -1))
677 if(data->screen_size == -1)
679 vgacs[(vs[screen].vga_charset)].screen_size;
681 if(data->force_24lines != -1)
683 vs[screen].force24 = data->force_24lines;
685 if(vs[screen].force24)
687 swritefkl(2,(u_char *)"FORCE24 ENABLE *",
692 swritefkl(2,(u_char *)"FORCE24 ENABLE ",
697 if((data->screen_size == SIZ_25ROWS) ||
698 (data->screen_size == SIZ_28ROWS) ||
699 (data->screen_size == SIZ_35ROWS) ||
700 (data->screen_size == SIZ_40ROWS) ||
701 (data->screen_size == SIZ_43ROWS) ||
702 (data->screen_size == SIZ_50ROWS))
704 if(data->screen_no == -1)
705 set_screen_size(vsp, data->screen_size);
707 set_screen_size(&vs[minor(dev)],
712 if(data->pure_vt_mode != -1)
714 if((data->pure_vt_mode == M_HPVT) ||
715 (data->pure_vt_mode == M_PUREVT))
717 if(data->screen_no == -1)
718 set_emulation_mode(vsp, data->pure_vt_mode);
720 set_emulation_mode(&vs[minor(dev)],
726 /*---------------------------------------------------------------------------*
727 * set screen size/resolution for a virtual screen
728 *---------------------------------------------------------------------------*/
730 set_screen_size(struct video_state *svsp, int size)
734 for(i = 0; i < totalfonts; i++)
736 if(vgacs[i].screen_size == size)
738 set_charset(svsp, i);
739 clr_parms(svsp); /* escape parameter init */
740 svsp->state = STATE_INIT; /* initial state */
741 svsp->scrr_beg = 0; /* start of scrolling region */
742 svsp->sc_flag = 0; /* invalidate saved cursor
744 svsp->transparent = 0; /* disable control code
747 /* Update tty to reflect screen size */
751 svsp->vs_tty->t_winsize.ws_col = svsp->maxcol;
752 svsp->vs_tty->t_winsize.ws_xpixel =
753 (svsp->maxcol == 80)? 720: 1056;
754 svsp->vs_tty->t_winsize.ws_ypixel = 400;
755 svsp->vs_tty->t_winsize.ws_row =
758 /* screen_rows already calculated in set_charset() */
759 if(svsp->vt_pure_mode == M_HPVT && svsp->labels_on)
761 if(svsp->which_fkl == SYS_FKL)
763 else if(svsp->which_fkl == USR_FKL)
768 svsp->scrr_len = svsp->screen_rows;
769 svsp->scrr_end = svsp->scrr_len - 1;
772 if (svsp->vs_tty && svsp->vs_tty->t_pgrp)
773 pgsignal(svsp->vs_tty->t_pgrp, SIGWINCH, 1);
774 #endif /* PCVT_SIGWINCH */
776 reallocate_scrollbuffer(svsp, svsp->scrollback_pages);
782 /*---------------------------------------------------------------------------*
783 * resize the scrollback buffer to the specified number of "pages"
784 *---------------------------------------------------------------------------*/
786 reallocate_scrollbuffer(struct video_state *svsp, int pages)
798 if((stmp = (u_short *)malloc(svsp->maxcol * svsp->screen_rows *
799 pages * CHR, M_DEVBUF, M_NOWAIT)) == NULL)
802 printf("pcvt: reallocate_scrollbuffer, malloc failed\n");
806 svsp->max_off = svsp->screen_rows * pages - 1;
810 bcopy(svsp->Scrollback, stmp,
811 (min(pages, svsp->scrollback_pages)) *
812 svsp->screen_rows * svsp->maxcol * CHR);
813 free(svsp->Scrollback, M_DEVBUF);
814 svsp->Scrollback = stmp;
818 svsp->scr_offset = 0;
820 svsp->Scrollback = stmp;
822 bcopy(svsp->Crtat, svsp->Scrollback,
823 svsp->screen_rows * svsp->maxcol * CHR);
825 svsp->scr_offset = svsp->row;
828 svsp->scrollback_pages = pages;
833 /*---------------------------------------------------------------------------*
834 * VGA ioctl - read DAC palette entry
835 *---------------------------------------------------------------------------*/
837 vgareadpel(struct vgapel *data, Dev_t dev)
839 register unsigned vpage = minor(dev);
840 register unsigned idx = data->idx;
843 return; /* no such entry */
845 /* do not read VGA palette directly, use saved values */
846 data->r = vs[vpage].palette[idx].r;
847 data->g = vs[vpage].palette[idx].g;
848 data->b = vs[vpage].palette[idx].b;
851 /*---------------------------------------------------------------------------*
852 * VGA ioctl - write DAC palette entry
853 *---------------------------------------------------------------------------*/
855 vgawritepel(struct vgapel *data, Dev_t dev)
857 register unsigned vpage = minor(dev);
858 register unsigned idx = data->idx;
861 return; /* no such entry */
863 /* first, update saved values for this video screen */
864 vs[vpage].palette[idx].r = data->r;
865 vs[vpage].palette[idx].g = data->g;
866 vs[vpage].palette[idx].b = data->b;
868 /* if this happens on active screen, update VGA DAC, too */
869 if(vpage == current_video_screen)
870 vgapaletteio(idx, &vs[vpage].palette[idx], 1);
873 /*---------------------------------------------------------------------------*
874 * VGA physical IO - read/write one palette entry
875 *---------------------------------------------------------------------------*/
877 vgapaletteio(unsigned idx, struct rgb *val, int writeit)
882 #endif /* PCVT_PALFLICKER */
886 outb(VGA_DAC + 2, idx);
890 #endif /* PCVT_WAITRETRACE */
892 outb(VGA_DAC + 3, val->r & VGA_PMSK);
896 #endif /* PCVT_WAITRETRACE */
898 outb(VGA_DAC + 3, val->g & VGA_PMSK);
902 #endif /* PCVT_WAITRETRACE */
904 outb(VGA_DAC + 3, val->b & VGA_PMSK);
908 outb(VGA_DAC + 1, idx);
912 #endif /* PCVT_WAITRETRACE */
914 val->r = inb(VGA_DAC + 3) & VGA_PMSK;
918 #endif /* PCVT_WAITRETRACE */
920 val->g = inb(VGA_DAC + 3) & VGA_PMSK;
924 #endif /* PCVT_WAITRETRACE */
926 val->b = inb(VGA_DAC + 3) & VGA_PMSK;
931 #endif /* PCVT_PALFLICKER */
935 /*---------------------------------------------------------------------------*
937 * update asynchronous: cursor, cursor pos displ, sys load, keyb scan
940 * UPDATE_START = do update; requeue
941 * UPDATE_STOP = suspend updates
942 * UPDATE_KERN = do update for kernel printfs
944 *---------------------------------------------------------------------------*/
946 async_update(void *arg)
948 static int lastpos = 0;
949 static int counter = PCVT_UPDATESLOW;
952 /* need a method to suspend the updates */
954 if(arg == UPDATE_STOP)
956 untimeout(async_update, UPDATE_START, async_update_ch);
961 /* first check if update is possible */
963 if(chargen_access /* does no-one load characters? */
964 #ifdef XSERVER /* is vt0 not in graphics mode? */
965 #if !PCVT_USL_VT_COMPAT
966 || pcvt_xmode /* XXX necessary ????? */
967 #endif /* PCVT_USL_VT_COMPAT */
971 goto async_update_exit; /* do not update anything */
975 if(reset_screen_saver && (counter == PCVT_UPDATESLOW))
977 pcvt_scrnsv_reset(); /* yes, do it */
978 reset_screen_saver = 0; /* re-init */
980 else if(scrnsv_active) /* is the screen not blanked? */
982 goto async_update_exit; /* do not update anything */
984 #endif /* PCVT_SCREENSAVER */
986 /*-------------------------------------------------------------------*/
987 /* this takes place on EVERY virtual screen (if not in X mode etc...)*/
988 /*-------------------------------------------------------------------*/
990 if ( cursor_pos_valid &&
991 (lastpos != (vsp->Crtat + vsp->cur_offset - Crtat)))
993 lastpos = vsp->Crtat + vsp->cur_offset - Crtat;
994 outb(addr_6845, CRTC_CURSORH); /* high register */
995 outb(addr_6845+1, ((lastpos) >> 8));
996 outb(addr_6845, CRTC_CURSORL); /* low register */
997 outb(addr_6845+1, (lastpos));
1000 if (arg == UPDATE_KERN) /* Magic arg: for kernel printfs */
1003 if(--counter) /* below is possible update */
1004 goto async_update_exit; /* just now and then ..... */
1005 counter = PCVT_UPDATESLOW; /* caution, see screensaver above !! */
1007 /*-------------------------------------------------------------------*/
1008 /* this takes place ONLY on screen 0 if in HP mode, labels on, !X */
1009 /*-------------------------------------------------------------------*/
1011 /* additional processing for HP necessary ? */
1013 if((vs[0].vt_pure_mode == M_HPVT) && (vs[0].labels_on))
1015 static volatile u_char buffer[] =
1016 "System Load: 1min: 0.00 5min: 0.00 15min: 0.00";
1017 register int tmp, i;
1019 extern u_char rawkeybuf[80];
1023 for(i = 0; i < 80; i++)
1025 *((vs[0].Crtat+((vs[0].screen_rows+2)
1026 * vs[0].maxcol))+i) =
1027 user_attr | rawkeybuf[i];
1032 #endif /* PCVT_SHOWKEYS */
1034 /* display load averages in last line (taken from tty.c) */
1036 #ifdef NEW_AVERUNNABLE
1037 tmp = (averunnable.ldavg[0] * 100 + FSCALE / 2)
1040 tmp = (averunnable[0] * 100 + FSCALE / 2) >> FSHIFT;
1044 ((((tmp/100)/10) == 0) ?
1046 ((tmp/100)/10) + '0');
1047 buffer[i++] = ((tmp/100)%10) + '0';
1049 buffer[i++] = ((tmp%100)/10) + '0';
1050 buffer[i++] = ((tmp%100)%10) + '0';
1052 #ifdef NEW_AVERUNNABLE
1053 tmp = (averunnable.ldavg[1] * 100 + FSCALE / 2)
1056 tmp = (averunnable[1] * 100 + FSCALE / 2) >> FSHIFT;
1058 buffer[i++] = ((((tmp/100)/10) == 0) ?
1060 ((tmp/100)/10) + '0');
1061 buffer[i++] = ((tmp/100)%10) + '0';
1063 buffer[i++] = ((tmp%100)/10) + '0';
1064 buffer[i++] = ((tmp%100)%10) + '0';
1066 #ifdef NEW_AVERUNNABLE
1067 tmp = (averunnable.ldavg[2] * 100 + FSCALE / 2)
1070 tmp = (averunnable[2] * 100 + FSCALE / 2) >> FSHIFT;
1072 buffer[i++] = ((((tmp/100)/10) == 0) ?
1074 ((tmp/100)/10) + '0');
1075 buffer[i++] = ((tmp/100)%10) + '0';
1077 buffer[i++] = ((tmp%100)/10) + '0';
1078 buffer[i++] = ((tmp%100)%10) + '0';
1081 for(i = 0; buffer[i]; i++)
1084 ((vs[0].screen_rows + 2) * vs[0].maxcol)
1086 ) = user_attr | buffer[i];
1093 ((vs[0].screen_rows + 2) * vs[0].maxcol)
1095 ) = user_attr | ' ';
1099 #endif /* PCVT_SHOWKEYS */
1102 /*-------------------------------------------------------------------*/
1103 /* this takes place on EVERY screen which is in HP mode, labels on,!X*/
1104 /*-------------------------------------------------------------------*/
1106 if((vsp->vt_pure_mode == M_HPVT) && (vsp->labels_on))
1108 register int col = vsp->col+1;
1109 register u_short *p = vsp->Crtat +
1110 (vsp->screen_rows * vsp->maxcol);
1112 /* update column display between labels */
1114 if(vsp->maxcol == SCR_COL132)
1116 p += (SCR_COL132 - SCR_COL80)/2;
1120 *(p + LABEL_COLU) = user_attr | '1';
1125 *(p + LABEL_COLU) = user_attr | '0';
1128 *(p + LABEL_COLH) = user_attr | ((col/10) + '0');
1129 *(p + LABEL_COLL) = user_attr | ((col%10) + '0');
1131 /* update row display between labels */
1133 *(p + LABEL_ROWH) = (user_attr | (((vsp->row+1)/10) + '0'));
1134 *(p + LABEL_ROWL) = (user_attr | (((vsp->row+1)%10) + '0'));
1139 if(arg == UPDATE_START)
1141 async_update_ch = timeout(async_update, UPDATE_START,
1146 /*---------------------------------------------------------------------------*
1147 * set character set for virtual screen
1148 *---------------------------------------------------------------------------*/
1150 set_charset(struct video_state *svsp, int curvgacs)
1152 static int sizetab[] = { 25, 28, 35, 40, 43, 50 };
1153 int oldsize, oldrows, newsize, newrows;
1155 if((curvgacs < 0) || (curvgacs > (NVGAFONTS-1)))
1158 svsp->vga_charset = curvgacs;
1160 select_vga_charset(curvgacs);
1162 oldsize = svsp->screen_rowsize;
1163 oldrows = svsp->screen_rows;
1164 newsize = sizetab[(vgacs[curvgacs].screen_size)];
1166 if (svsp->vt_pure_mode == M_HPVT)
1168 if (newrows == 25 && svsp->force24)
1170 if (newrows < oldrows) {
1171 int nscroll = svsp->row + 1 - newrows;
1173 if (svsp->row >= oldrows) /* Sanity check */
1174 nscroll = oldrows - newrows;
1177 bcopy (svsp->Crtat + nscroll * svsp->maxcol,
1179 newrows * svsp->maxcol * CHR);
1180 svsp->row -= nscroll;
1181 svsp->cur_offset -= nscroll * svsp->maxcol;
1183 if (newrows < newsize)
1184 fillw(user_attr | ' ',
1185 svsp->Crtat + newrows * svsp->maxcol,
1186 (newsize - newrows) * svsp->maxcol);
1187 } else if (oldrows < newsize)
1188 fillw(user_attr | ' ',
1189 svsp->Crtat + oldrows * svsp->maxcol,
1190 (newsize - oldrows) * svsp->maxcol);
1192 svsp->screen_rowsize = newsize;
1193 svsp->screen_rows = newrows;
1195 /* Clip scrolling region */
1196 if(svsp->scrr_end > svsp->screen_rows - 1)
1197 svsp->scrr_end = svsp->screen_rows - 1;
1198 svsp->scrr_len = svsp->scrr_end - svsp->scrr_beg + 1;
1200 /* Clip cursor pos */
1202 if(svsp->cur_offset > (svsp->scrr_len * svsp->maxcol))
1203 svsp->cur_offset = (svsp->scrr_len * svsp->maxcol) + svsp->col;
1206 /*---------------------------------------------------------------------------*
1207 * select a vga character set
1208 *---------------------------------------------------------------------------*/
1210 select_vga_charset(int vga_charset)
1217 static u_char cmaptaba[] =
1218 {0x00, 0x01, 0x02, 0x03, 0x10, 0x11, 0x12, 0x13};
1220 static u_char cmaptabb[] =
1221 {0x00, 0x04, 0x08, 0x0c, 0x20, 0x24, 0x28, 0x2c};
1223 if((adaptor_type != EGA_ADAPTOR) && (adaptor_type != VGA_ADAPTOR))
1226 if((vga_charset < 0) || (vga_charset >= totalfonts))
1229 if(!vgacs[vga_charset].loaded)
1232 /*--------------------------------------------------------------
1233 find the the first and second charset of a given resolution.
1234 the first is used for lower 256 and the second (if any) is
1235 used for the upper 256 entries of a complete 512 entry ega/
1237 --------------------------------------------------------------*/
1239 for(first = 0; first < totalfonts; first++)
1241 if(!vgacs[first].loaded)
1243 if(vgacs[first].screen_size != vgacs[vga_charset].screen_size)
1245 if(vgacs[first].char_scanlines !=
1246 vgacs[vga_charset].char_scanlines)
1248 if(vgacs[first].scr_scanlines !=
1249 vgacs[vga_charset].scr_scanlines)
1258 for(second = first+1; second < totalfonts; second++)
1260 if(!vgacs[second].loaded)
1262 if(vgacs[second].screen_size != vgacs[vga_charset].screen_size)
1264 if(vgacs[second].char_scanlines !=
1265 vgacs[vga_charset].char_scanlines)
1267 if(vgacs[second].scr_scanlines !=
1268 vgacs[vga_charset].scr_scanlines)
1274 cmap = cmaptaba[first];
1277 cmap |= cmaptabb[second];
1278 vgacs[first].secondloaded = second;
1282 vgacs[first].secondloaded = 0; /*cs 0 can never become a 2nd!*/
1287 cmap = (vga_charset & 0x07);
1291 outb(TS_INDEX, TS_FONTSEL); /* character map select register */
1292 outb(TS_DATA, cmap); /* new char map */
1294 outb(addr_6845, CRTC_MAXROW); /* max scan line reg */
1296 vgacs[first].char_scanlines); /* scanlines/char */
1298 outb(addr_6845, CRTC_VDE); /* vert display enable end */
1300 vgacs[first].scr_scanlines); /* low byte of scr scanlines */
1302 if((color == 0) && (adaptor_type == VGA_ADAPTOR))
1304 outb(addr_6845, CRTC_ULOC); /* underline location reg */
1305 outb(addr_6845+1, (vgacs[first].char_scanlines & 0x1F));
1309 /*---------------------------------------------------------------------------*
1310 * switch vga-card to load a character set
1311 *---------------------------------------------------------------------------*/
1315 chargen_access = 1; /* flag we are accessing the chargen ram */
1317 /* program sequencer to access character generator */
1319 outb(TS_INDEX, TS_SYNCRESET);
1320 outb(TS_DATA, 0x01); /* synchronous reset */
1322 outb(TS_INDEX, TS_WRPLMASK);
1323 outb(TS_DATA, 0x04); /* write to map 2 */
1325 outb(TS_INDEX, TS_MEMMODE);
1326 outb(TS_DATA, 0x07); /* sequential addressing */
1328 outb(TS_INDEX, TS_SYNCRESET);
1329 outb(TS_DATA, 0x03); /* clear synchronous reset */
1331 /* program graphics controller to access character generator */
1333 outb(GDC_INDEX, GDC_RDPLANESEL);
1334 outb(GDC_DATA, 0x02); /* select map 2 for cpu reads */
1336 outb(GDC_INDEX, GDC_MODE);
1337 outb(GDC_DATA, 0x00); /* disable odd-even addressing */
1339 outb(GDC_INDEX, GDC_MISC);
1340 outb(GDC_DATA, 0x00); /* map starts at 0xA000 */
1343 /*---------------------------------------------------------------------------*
1344 * switch vga-card to load a character set to plane 3
1345 *---------------------------------------------------------------------------*/
1349 chargen_access = 1; /* flag we are accessing the chargen ram */
1351 /* program sequencer to access character generator */
1353 outb(TS_INDEX, TS_SYNCRESET);
1354 outb(TS_DATA, 0x01); /* synchronous reset */
1356 outb(TS_INDEX, TS_WRPLMASK);
1357 outb(TS_DATA, 0x08); /* write to map 3 */
1359 outb(TS_INDEX, TS_MEMMODE);
1360 outb(TS_DATA, 0x07); /* sequential addressing */
1362 outb(TS_INDEX, TS_SYNCRESET);
1363 outb(TS_DATA, 0x03); /* clear synchronous reset */
1365 /* program graphics controller to access character generator */
1367 outb(GDC_INDEX, GDC_RDPLANESEL);
1368 outb(GDC_DATA, 0x03); /* select map 3 for cpu reads */
1370 outb(GDC_INDEX, GDC_MODE);
1371 outb(GDC_DATA, 0x00); /* disable odd-even addressing */
1373 outb(GDC_INDEX, GDC_MISC);
1374 outb(GDC_DATA, 0x00); /* map starts at 0xA000 */
1377 /*---------------------------------------------------------------------------*
1378 * switch back vga-card to normal operation
1379 *---------------------------------------------------------------------------*/
1383 /* program sequencer to access video ram */
1385 outb(TS_INDEX, TS_SYNCRESET);
1386 outb(TS_DATA, 0x01); /* synchronous reset */
1388 outb(TS_INDEX, TS_WRPLMASK);
1389 outb(TS_DATA, 0x03); /* write to map 0 & 1 */
1391 outb(TS_INDEX, TS_MEMMODE);
1392 outb(TS_DATA, 0x03); /* odd-even addressing */
1394 outb(TS_INDEX, TS_SYNCRESET);
1395 outb(TS_DATA, 0x03); /* clear synchronous reset */
1397 /* program graphics controller to access character generator */
1399 outb(GDC_INDEX, GDC_RDPLANESEL);
1400 outb(GDC_DATA, 0x00); /* select map 0 for cpu reads */
1402 outb(GDC_INDEX, GDC_MODE);
1403 outb(GDC_DATA, 0x10); /* enable odd-even addressing */
1405 outb(GDC_INDEX, GDC_MISC);
1407 outb(GDC_DATA, 0x0e); /* map starts at 0xb800 */
1409 outb(GDC_DATA, 0x0a); /* map starts at 0xb000 */
1411 chargen_access = 0; /* flag we are NOT accessing the chargen ram */
1414 #if PCVT_WAITRETRACE
1415 /*---------------------------------------------------------------------------*
1416 * wait for being in a retrace time window
1417 * NOTE: this is __VERY__ bad programming practice in this environment !!
1418 *---------------------------------------------------------------------------*/
1425 while(!(inb(GN_INPSTAT1C) & 0x01))
1430 while(!(inb(GN_INPSTAT1M) & 0x01))
1435 #endif /* PCVT_WAITRETRACE */
1437 /*---------------------------------------------------------------------------*
1438 * switch screen off (VGA only)
1439 *---------------------------------------------------------------------------*/
1441 vga_screen_off(void)
1445 outb(TS_INDEX, TS_SYNCRESET);
1446 outb(TS_DATA, 0x01); /* synchronous reset */
1448 outb(TS_INDEX, TS_MODE); /* clocking mode reg */
1449 old = inb(TS_DATA); /* get current value */
1451 outb(TS_INDEX, TS_MODE); /* clocking mode reg */
1452 outb(TS_DATA, (old | 0x20)); /* screen off bit on */
1454 outb(TS_INDEX, TS_SYNCRESET);
1455 outb(TS_DATA, 0x03); /* clear synchronous reset */
1458 /*---------------------------------------------------------------------------*
1459 * switch screen back on (VGA only)
1460 *---------------------------------------------------------------------------*/
1466 outb(TS_INDEX, TS_SYNCRESET);
1467 outb(TS_DATA, 0x01); /* synchronous reset */
1469 outb(TS_INDEX, TS_MODE); /* clocking mode reg */
1470 old = inb(TS_DATA); /* get current value */
1472 outb(TS_INDEX, TS_MODE); /* clocking mode reg */
1473 outb(TS_DATA, (old & ~0x20)); /* screen off bit off */
1475 outb(TS_INDEX, TS_SYNCRESET);
1476 outb(TS_DATA, 0x03); /* clear synchronous reset */
1479 /*---------------------------------------------------------------------------*
1480 * compute character set base address (in kernel map)
1481 *---------------------------------------------------------------------------*/
1482 static unsigned char *
1483 compute_charset_base(unsigned fontset)
1485 unsigned char *d = (unsigned char *)Crtat;
1487 static int charset_offset[8] = { 0x0000, 0x4000, 0x8000, 0xC000,
1488 0x2000, 0x6000, 0xA000, 0xE000 };
1490 static int charsetw_offset[8] = { 0x0000, 0x2000, 0x4000, 0x6000,
1491 0x8000, 0xA000, 0xC000, 0xE000 };
1493 switch(adaptor_type)
1496 fontset = (fontset > 3) ? 3 : fontset;
1500 fontset = (fontset > 7) ? 7 : fontset;
1508 d -= (0xB8000 - 0xA0000); /* Point to 0xA0000 */
1510 d -= (0xB0000 - 0xA0000); /* Point to 0xA0000 */
1513 d += charsetw_offset[fontset]; /* Load into Character set n */
1515 d += charset_offset[fontset]; /* Load into Character set n */
1520 /*---------------------------------------------------------------------------*
1521 * load a char into ega/vga character generator ram
1522 *---------------------------------------------------------------------------*/
1524 loadchar(int fontset, int character, int char_scanlines, u_char *char_table)
1528 #if PCVT_BACKUP_FONTS
1530 #endif /* PCVT_BACKUP_FONTS */
1534 if((d = compute_charset_base(fontset)) == 0)
1537 d += (character * 32); /* 32 bytes per character */
1540 (fontset == 1||fontset == 3||fontset == 5||fontset == 7))
1541 setchargen3(); /* access chargen ram */
1543 setchargen(); /* access chargen ram */
1545 for(j = k = 0; j < char_scanlines; j++) /* x bit high characters */
1551 for(; j < 32; j++) /* Up to 32 bytes per character image*/
1557 resetchargen(); /* access video ram */
1559 #if PCVT_BACKUP_FONTS
1560 if(saved_charsets[fontset] == 0)
1561 saved_charsets[fontset] =
1562 (u_char *)malloc(32 * 256, M_DEVBUF, M_WAITOK);
1564 if((bak = saved_charsets[fontset]))
1566 /* make a backup copy of this char */
1567 bak += (character * 32);
1569 bcopy(char_table, bak, char_scanlines);
1573 panic("pcvt loadchar: no backup buffer");
1574 #endif /* DIAGNOSTIC */
1576 #endif /* PCVT_BACKUP_FONTS */
1580 /*---------------------------------------------------------------------------*
1581 * save/restore character set n to addr b
1582 *---------------------------------------------------------------------------*/
1583 #if !PCVT_BACKUP_FONTS
1586 vga_move_charset(unsigned n, unsigned char *b, int save_it)
1588 unsigned char *d = compute_charset_base(n);
1592 panic("vga_move_charset: wrong adaptor");
1595 if(vsp->wd132col && (n == 1||n == 3||n == 5||n == 7))
1605 /* PLEASE, leave the following alone using bcopyb, as several */
1606 /* chipsets have problems if their memory is accessed with 32 */
1607 /* or 16 bits wide, don't change this to using bcopy for speed! */
1610 bcopyb(d, b, 256 /* chars */ * 32 /* bytes per char */);
1612 bcopyb(b, d, 256 /* chars */ * 32 /* bytes per char */);
1617 #else /* PCVT_BACKUP_FONTS */
1619 /* since there are always backed up copies, we do not save anything here */
1620 /* parameter "b" is totally ignored */
1623 vga_move_charset(unsigned n, unsigned char *b, int save_it)
1625 unsigned char *d = compute_charset_base(n);
1630 if(saved_charsets[n] == 0)
1632 panic("pcvt: restoring unbuffered charset");
1639 panic("vga_move_charset: wrong adaptor");
1642 if(vsp->wd132col && (n == 1||n == 3||n == 5||n == 7))
1652 /* PLEASE, leave the following alone using bcopyb, as several */
1653 /* chipsets have problems if their memory is accessed with 32 */
1654 /* or 16 bits wide, don't change this to using bcopy for speed! */
1656 bcopyb(saved_charsets[n], d,
1657 256 /* chars */ * 32 /* bytes per char */);
1662 #endif /* PCVT_BACKUP_FONTS */
1665 #if !PCVT_USL_VT_COMPAT
1666 /*---------------------------------------------------------------------------*
1667 * switch to virtual screen n (0 ... PCVT_NSCREENS-1)
1668 *---------------------------------------------------------------------------*/
1675 #endif /* !PCVT_KBD_FIFO */
1677 int cols = vsp->maxcol; /* get current col val */
1679 if(n < 0 || n >= totalscreens)
1683 x = spltty(); /* protect us */
1684 #endif /* !PCVT_KBD_FIFO */
1686 /* video board memory -> kernel memory */
1688 bcopy(vsp->Crtat, vsp->Memory, vsp->screen_rows * vsp->maxcol * CHR);
1690 vsp->Crtat = vsp->Memory; /* operate in memory now */
1692 /* update global screen pointers/variables */
1694 current_video_screen = n; /* current screen no */
1696 #if !PCVT_NETBSD && !(PCVT_FREEBSD > 110 && PCVT_FREEBSD < 200)
1697 pcconsp = &pccons[n]; /* current tty */
1698 #elif PCVT_FREEBSD > 110 && PCVT_FREEBSD < 200
1699 pcconsp = pccons[n]; /* current tty */
1701 pcconsp = pc_tty[n]; /* current tty */
1704 vsp = &vs[n]; /* current video state ptr */
1706 /* kernel memory -> video board memory */
1708 bcopy(vsp->Crtat, Crtat, vsp->screen_rows * vsp->maxcol * CHR);
1710 vsp->Crtat = Crtat; /* operate on screen now */
1712 outb(addr_6845, CRTC_STARTADRH);
1713 outb(addr_6845+1, 0);
1714 outb(addr_6845, CRTC_STARTADRL);
1715 outb(addr_6845+1, 0);
1719 #endif /* !PCVT_KBD_FIFO */
1721 select_vga_charset(vsp->vga_charset);
1723 if(vsp->maxcol != cols)
1724 vga_col(vsp, vsp->maxcol); /* select 80/132 columns */
1726 outb(addr_6845, CRTC_CURSORH); /* select high register */
1727 outb(addr_6845+1, vsp->cur_offset >> 8);
1728 outb(addr_6845, CRTC_CURSORL); /* select low register */
1729 outb(addr_6845+1, vsp->cur_offset);
1733 outb(addr_6845, CRTC_CURSTART); /* select high register */
1734 outb(addr_6845+1, vsp->cursor_start);
1735 outb(addr_6845, CRTC_CUREND); /* select low register */
1736 outb(addr_6845+1, vsp->cursor_end);
1743 if(adaptor_type == VGA_ADAPTOR)
1747 /* switch VGA DAC palette entries */
1749 for(i = 0; i < NVGAPEL; i++)
1750 vgapaletteio(i, &vsp->palette[i], 1);
1753 update_led(); /* update led's */
1755 update_hp(vsp); /* update fkey labels, if present */
1757 #endif /* !PCVT_USL_VT_COMPAT */
1759 /*---------------------------------------------------------------------------*
1760 * test if it is a vga
1761 *---------------------------------------------------------------------------*/
1766 u_char old, new, check;
1768 outb(addr_6845,CRTC_CURSTART); /* cursor start reg */
1769 old = inb(addr_6845+1); /* get current value */
1771 new = old | CURSOR_ON_BIT; /* set cursor on by setting bit 5 on */
1773 outb(addr_6845,CRTC_CURSTART); /* cursor start reg */
1774 outb(addr_6845+1,new); /* cursor should be on now */
1776 outb(addr_6845,CRTC_CURSTART); /* cursor start reg */
1777 check = inb(addr_6845+1); /* get current value */
1781 outb(addr_6845,CRTC_CURSTART); /* cursor start reg */
1782 outb(addr_6845+1,old); /* failsafe */
1783 return(0); /* must be ega */
1786 new = old & ~CURSOR_ON_BIT; /* turn cursor off by clearing bit 5 */
1788 outb(addr_6845,CRTC_CURSTART); /* cursor start reg */
1789 outb(addr_6845+1,new); /* cursor should be off now */
1791 outb(addr_6845,CRTC_CURSTART); /* cursor start reg */
1792 check = inb(addr_6845+1); /* get current value */
1796 outb(addr_6845,CRTC_CURSTART); /* cursor start reg */
1797 outb(addr_6845+1,old); /* failsafe */
1798 return(0); /* must be ega */
1801 outb(addr_6845,CRTC_CURSTART); /* cursor start reg */
1802 outb(addr_6845+1,old); /* failsafe */
1804 return(1); /* vga */
1807 /*---------------------------------------------------------------------------*
1808 * convert upper/lower sixel font array to vga font array
1809 *---------------------------------------------------------------------------*/
1811 sixel_vga(struct sixels *sixelp, u_char *vgachar)
1815 register u_char mask;
1817 for(j = 0; j < 16; j++)
1821 for(j = 0; j < 6; j++)
1823 for(i = 0, shift = 7; i < 8; i++, shift--)
1824 vgachar[j] |= ((((sixelp->upper[i]) & mask) >> j)
1830 for(j = 0; j < 4; j++)
1832 for(i = 0, shift = 7; i < 8; i++, shift--)
1833 vgachar[j+6] |= ((((sixelp->lower[i]) & mask) >>j)
1839 /*---------------------------------------------------------------------------*
1840 * Expand 8x10 EGA/VGA characters to 8x16 EGA/VGA characters
1841 *---------------------------------------------------------------------------*/
1843 vga10_vga16(u_char *invga, u_char *outvga)
1848 * Keep the top and bottom scanlines the same and double every scan
1852 outvga[0] = invga[0];
1853 outvga[1] = invga[1];
1854 outvga[14] = invga[8];
1855 outvga[15] = invga[9];
1857 for(i = j = 2;i < 8 && j < 14;i++,j += 2)
1859 outvga[j] = invga[i];
1860 outvga[j+1] = invga[i];
1864 /*---------------------------------------------------------------------------*
1865 * Expand 8x10 EGA/VGA characters to 8x14 EGA/VGA characters
1866 *---------------------------------------------------------------------------*/
1868 vga10_vga14(u_char *invga, u_char *outvga)
1873 * Double the top two and bottom two scanlines and copy everything
1877 outvga[0] = invga[0];
1878 outvga[1] = invga[0];
1879 outvga[2] = invga[1];
1880 outvga[3] = invga[1];
1881 outvga[10] = invga[8];
1882 outvga[11] = invga[8];
1883 outvga[12] = invga[9];
1884 outvga[13] = invga[9];
1886 for(i = 2;i < 8;i++)
1887 outvga[i+2] = invga[i];
1890 /*---------------------------------------------------------------------------*
1891 * Expand 8x10 EGA/VGA characters to 8x10 EGA/VGA characters
1892 *---------------------------------------------------------------------------*/
1894 vga10_vga10(u_char *invga, u_char *outvga)
1898 for(i = 0;i < 10;i++)
1899 outvga[i] = invga[i];
1902 /*---------------------------------------------------------------------------*
1903 * Contract 8x10 EGA/VGA characters to 8x8 EGA/VGA characters
1904 *---------------------------------------------------------------------------*/
1906 vga10_vga8(u_char *invga, u_char *outvga)
1908 /* Skip scanlines 3 and 7 */
1910 outvga[0] = invga[0];
1911 outvga[1] = invga[1];
1912 outvga[2] = invga[2];
1913 outvga[3] = invga[4];
1914 outvga[4] = invga[5];
1915 outvga[5] = invga[6];
1916 outvga[6] = invga[8];
1917 outvga[7] = invga[9];
1920 /*---------------------------------------------------------------------------*
1921 * force a vga card to behave like an ega for debugging
1922 *---------------------------------------------------------------------------*/
1927 unsigned char vgareg;
1929 if(adaptor_type == VGA_ADAPTOR)
1931 adaptor_type = EGA_ADAPTOR;
1933 vgareg = inb(GN_MISCOUTR); /* Miscellaneous Output Register */
1934 vgareg |= 128; /* Set 350 scanline mode */
1936 outb(GN_MISCOUTW,vgareg);
1939 #endif /* FORCE_EGA */
1941 /*---------------------------------------------------------------------------*
1942 * disconnect attribute bit 3 from generating intensity
1943 * (and use it for a second character set !)
1944 *---------------------------------------------------------------------------*/
1946 set_2ndcharset(void)
1948 if(color) /* prepare to access index register! */
1953 /* select color plane enable reg, caution: set ATC access bit ! */
1955 outb(ATC_INDEX, (ATC_COLPLEN | ATC_ACCESS));
1956 outb(ATC_DATAW, 0x07); /* disable plane 3 */
1959 #if PCVT_SCREENSAVER
1960 #if PCVT_PRETTYSCRNS
1962 /*---------------------------------------------------------------------------*
1963 * produce some kinda random number, had a look into the system library...
1964 *---------------------------------------------------------------------------*/
1969 extern struct timeval time; /* time-of-day register */
1971 static unsigned long seed = 1;
1972 register u_short res = (u_short)seed;
1973 seed = seed * 1103515245L + time_second;
1977 /*---------------------------------------------------------------------------*
1978 * produce "nice" screensaving ....
1979 *---------------------------------------------------------------------------*/
1981 scrnsv_blink(void * arg)
1983 static struct rgb blink_rgb[8] =
1985 {63, 63, 63}, /* white */
1986 {0, 63, 42}, /* pale green */
1987 {63, 63, 0}, /* yellow */
1988 {63, 21, 63}, /* violet */
1989 {42, 63, 0}, /* yellow-green */
1990 {63, 42, 0}, /* amber */
1991 {63, 42, 42}, /* rose */
1992 {21, 42, 42} /* cyan */
1994 register u_short r = getrand();
1995 unsigned pos = (r % (scrnsv_size / 2));
1997 *scrnsv_current = /* (0 << 8) + */ ' ';
1998 scrnsv_current = vsp->Crtat + pos;
1999 *scrnsv_current = (7 /* LIGHTGRAY */ << 8) + '*';
2000 if(adaptor_type == VGA_ADAPTOR)
2001 vgapaletteio(7 /* LIGHTGRAY */, &blink_rgb[(r >> 4) & 7], 1);
2002 scrnsv_blink_ch = timeout(scrnsv_blink, NULL, hz);
2005 #endif /* PCVT_PRETTYSCRNS */
2007 /*---------------------------------------------------------------------------*
2009 *---------------------------------------------------------------------------*/
2012 pcvt_set_scrnsv_tmo(int timeout)
2015 pcvt_set_scrnsv_tmo(int timeout)
2016 #endif /* XSERVER */
2021 untimeout(scrnsv_timedout, NULL, scrnsv_timeout_ch);
2023 scrnsv_timeout = timeout;
2024 pcvt_scrnsv_reset(); /* sanity */
2026 if(timeout == 0 && savedscreen)
2028 /* release buffer when screen saver turned off */
2029 free(savedscreen, M_TEMP);
2030 savedscreen = (u_short *)0;
2034 /*---------------------------------------------------------------------------*
2036 *---------------------------------------------------------------------------*/
2038 scrnsv_timedout(void *arg)
2040 /* this function is called by timeout() */
2041 /* raise priority to avoid conflicts with kbd intr */
2045 * due to some undefined problems with video adaptor RAM
2046 * access timing, the following has been splitted into
2047 * two pieces called subsequently with a time difference
2051 if(++scrnsv_active == 1)
2055 * first, allocate a buffer
2056 * do only if none allocated yet or another size required
2057 * this reduces malloc() overhead by avoiding successive
2058 * calls to malloc() and free() if they would have requested
2061 * XXX This is inherited from old days where no buffering
2062 * happened at all. Meanwhile we should use the standard
2063 * screen buffer instead. Any volunteers? :-) [At least,
2064 * this code proved to work...]
2067 s = sizeof(u_short) * vsp->screen_rowsize * vsp->maxcol;
2069 if(savedscreen == (u_short *)0 || s != scrnsv_size)
2071 /* really need to allocate */
2073 free(savedscreen, M_TEMP);
2076 (u_short *)malloc(s, M_TEMP, M_NOWAIT))
2080 * didn't get the buffer memory,
2081 * turn off screen saver
2083 scrnsv_timeout = scrnsv_active = 0;
2088 /* save current screen */
2089 bcopy(vsp->Crtat, savedscreen, scrnsv_size);
2091 /* on VGA's, make sure palette is set to blank screen */
2092 if(adaptor_type == VGA_ADAPTOR)
2094 struct rgb black = {0, 0, 0};
2095 vgapaletteio(0 /* BLACK */, &black, 1);
2097 /* prepare for next time... */
2098 scrnsv_timeout_ch = timeout(scrnsv_timedout, NULL, hz / 10);
2102 /* second call, now blank the screen */
2103 /* fill screen with blanks */
2104 fillw(/* (BLACK<<8) + */ ' ', vsp->Crtat, scrnsv_size / 2);
2106 #if PCVT_PRETTYSCRNS
2107 scrnsv_current = vsp->Crtat;
2108 scrnsv_blink_ch = timeout(scrnsv_blink, NULL, hz);
2109 #endif /* PCVT_PRETTYSCRNS */
2111 sw_cursor(0); /* cursor off on mda/cga */
2116 /*---------------------------------------------------------------------------*
2117 * interface to screensaver "subsystem"
2118 *---------------------------------------------------------------------------*/
2120 pcvt_scrnsv_reset(void)
2123 * to save lotta time with superfluous timeout()/untimeout() calls
2124 * when having massive output operations, we remember the last
2125 * second of kernel timer we've rescheduled scrnsv_timedout()
2127 static long last_schedule = 0L;
2128 register int x = splhigh();
2131 if((scrnsv_active == 1 || scrnsv_timeout) &&
2132 last_schedule != time_second)
2134 last_schedule = time_second;
2136 untimeout(scrnsv_timedout, NULL, scrnsv_timeout_ch);
2141 #if PCVT_PRETTYSCRNS
2142 if(scrnsv_active > 1)
2143 untimeout(scrnsv_blink, NULL, scrnsv_blink_ch);
2144 #endif /* PCVT_PRETTYSCRNS */
2146 bcopy(savedscreen, vsp->Crtat, scrnsv_size);
2147 if(adaptor_type == VGA_ADAPTOR)
2149 /* back up VGA palette info */
2150 vgapaletteio(0 /* BLACK */, &vsp->palette[0], 1);
2152 #if PCVT_PRETTYSCRNS
2153 vgapaletteio(7 /* LIGHTGRAY */, &vsp->palette[7], 1);
2154 #endif /* PCVT_PRETTYSCRNS */
2160 sw_cursor(1); /* cursor on */
2165 /* mark next timeout */
2166 scrnsv_timeout_ch = timeout(scrnsv_timedout, NULL,
2167 scrnsv_timeout * hz);
2172 #endif /* PCVT_SCREENSAVER */
2174 /*---------------------------------------------------------------------------*
2175 * switch cursor on/off
2176 *---------------------------------------------------------------------------*/
2178 sw_cursor(int onoff)
2180 if(adaptor_type == EGA_ADAPTOR)
2185 start = vsp->cursor_start;
2186 end = vsp->cursor_end;
2190 int cs = vs[current_video_screen].vga_charset;
2192 cs = (cs < 0) ? 0 : ((cs < totalfonts) ?
2195 start = (vgacs[cs].char_scanlines & 0x1F) + 1;
2198 outb(addr_6845,CRTC_CURSTART); /* cursor start reg */
2199 outb(addr_6845+1, start);
2200 outb(addr_6845,CRTC_CUREND); /* cursor end reg */
2201 outb(addr_6845+1, end);
2203 else /* mda, cga, vga */
2205 outb(addr_6845,CRTC_CURSTART); /* cursor start reg */
2207 outb(addr_6845+1, vsp->cursor_start);
2209 outb(addr_6845+1, CURSOR_ON_BIT);
2213 /*---------------------------------------------------------------------------*
2214 * cold init support, if a mono monitor is attached to a
2215 * vga or ega, it comes up with a mda emulation. switch
2216 * board to generic ega/vga mode in this case.
2217 *---------------------------------------------------------------------------*/
2222 * program sequencer to access
2226 /* synchronous reset */
2227 outb(TS_INDEX, TS_SYNCRESET);
2228 outb(TS_DATA, 0x01);
2230 /* write to map 0 & 1 */
2231 outb(TS_INDEX, TS_WRPLMASK);
2232 outb(TS_DATA, 0x03);
2234 /* odd-even addressing */
2235 outb(TS_INDEX, TS_MEMMODE);
2236 outb(TS_DATA, 0x03);
2238 /* clear synchronous reset */
2239 outb(TS_INDEX, TS_SYNCRESET);
2240 outb(TS_DATA, 0x03);
2243 * program graphics controller
2244 * to access character
2248 /* select map 0 for cpu reads */
2249 outb(GDC_INDEX, GDC_RDPLANESEL);
2250 outb(GDC_DATA, 0x00);
2252 /* enable odd-even addressing */
2253 outb(GDC_INDEX, GDC_MODE);
2254 outb(GDC_DATA, 0x10);
2256 /* map starts at 0xb000 */
2257 outb(GDC_INDEX, GDC_MISC);
2258 outb(GDC_DATA, 0x0a);
2261 #endif /* NVT > 0 */
2263 /* ------------------------- E O F ------------------------------------------*/