1 /*- 2 * Copyright (c) 1995 S�ren Schmidt 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer 10 * in this position and unchanged. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software withough specific prior written permission 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * $Id$ 29 */ 30 31 /* vm things */ 32 #define ISMAPPED(pa, width) \ 33 (((pa) <= (u_long)0x1000 - (width)) \ 34 || ((pa) >= 0xa0000 && (pa) <= 0x100000 - (width))) 35 #define pa_to_va(pa) (KERNBASE + (pa)) /* works if ISMAPPED(pa...) */ 36 37 /* printable chars */ 38 #define PRINTABLE(ch) (ch>0x1B || (ch>0x0d && ch<0x1b) || ch<0x07) 39 40 /* status flags */ 41 #define LOCK_KEY_MASK 0x0000F 42 #define LED_MASK 0x00007 43 #define UNKNOWN_MODE 0x00010 44 #define KBD_RAW_MODE 0x00020 45 #define SWITCH_WAIT_REL 0x00040 46 #define SWITCH_WAIT_ACQ 0x00080 47 #define BUFFER_SAVED 0x00100 48 #define CURSOR_ENABLED 0x00200 49 #define CURSOR_SHOWN 0x00400 50 #define MOUSE_ENABLED 0x00800 51 #define UPDATE_MOUSE 0x01000 52 #define UPDATE_SCREEN 0x02000 53 54 /* configuration flags */ 55 #define VISUAL_BELL 0x00001 56 #define BLINK_CURSOR 0x00002 57 #define CHAR_CURSOR 0x00004 58 59 /* video hardware memory addresses */ 60 #define VIDEOMEM 0x000A0000 61 62 /* misc defines */ 63 #define FALSE 0 64 #define TRUE 1 65 #define MAX_ESC_PAR 5 66 #define LOAD 1 67 #define SAVE 0 68 #define COL 80 69 #define ROW 25 70 #define BELL_DURATION 5 71 #define BELL_PITCH 800 72 #define TIMER_FREQ 1193182 /* should be in isa.h */ 73 #define CONSOLE_BUFSIZE 1024 74 #define PCBURST 128 75 #define FONT_8 0x001 76 #define FONT_14 0x002 77 #define FONT_16 0x004 78 #define HISTORY_SIZE 100*80 79 80 /* defines related to hardware addresses */ 81 #define MONO_BASE 0x3B4 /* crt controller base mono */ 82 #define COLOR_BASE 0x3D4 /* crt controller base color */ 83 #define MISC 0x3C2 /* misc output register */ 84 #define ATC IO_VGA+0x00 /* attribute controller */ 85 #define TSIDX IO_VGA+0x04 /* timing sequencer idx */ 86 #define TSREG IO_VGA+0x05 /* timing sequencer data */ 87 #define PIXMASK IO_VGA+0x06 /* pixel write mask */ 88 #define PALRADR IO_VGA+0x07 /* palette read address */ 89 #define PALWADR IO_VGA+0x08 /* palette write address */ 90 #define PALDATA IO_VGA+0x09 /* palette data register */ 91 #define GDCIDX IO_VGA+0x0E /* graph data controller idx */ 92 #define GDCREG IO_VGA+0x0F /* graph data controller data */ 93 94 /* special characters */ 95 #define cntlc 0x03 96 #define cntld 0x04 97 #define bs 0x08 98 #define lf 0x0a 99 #define cr 0x0d 100 #define del 0x7f 101 102 typedef struct term_stat { 103 int esc; /* processing escape sequence */ 104 int num_param; /* # of parameters to ESC */ 105 int last_param; /* last parameter # */ 106 int param[MAX_ESC_PAR]; /* contains ESC parameters */ 107 int cur_attr; /* current attributes */ 108 int std_attr; /* normal attributes */ 109 int rev_attr; /* reverse attributes */ 110 } term_stat; 111 112 typedef struct scr_stat { 113 u_short *scr_buf; /* buffer when off screen */ 114 int xpos; /* current X position */ 115 int ypos; /* current Y position */ 116 int xsize; /* X size */ 117 int ysize; /* Y size */ 118 term_stat term; /* terminal emulation stuff */ 119 int status; /* status (bitfield) */ 120 u_short *cursor_pos; /* cursor buffer position */ 121 u_short cursor_saveunder; /* saved chars under cursor */ 122 char cursor_start; /* cursor start line # */ 123 char cursor_end; /* cursor end line # */ 124 u_short *mouse_pos; /* mouse buffer position */ 125 u_short *mouse_oldpos; /* mouse old buffer position */ 126 u_short mouse_saveunder[4]; /* saved chars under mouse */ 127 short mouse_xpos; /* mouse x coordinate */ 128 short mouse_ypos; /* mouse y coordinate */ 129 u_char mouse_cursor[128]; /* mouse cursor bitmap store */ 130 u_short bell_duration; 131 u_short bell_pitch; 132 u_char border; /* border color */ 133 u_char mode; /* mode */ 134 u_char font; /* font on this screen */ 135 pid_t pid; /* pid of controlling proc */ 136 struct proc *proc; /* proc* of controlling proc */ 137 struct vt_mode smode; /* switch mode */ 138 u_short *history; /* circular history buffer */ 139 u_short *history_head; /* current head position */ 140 u_short *history_pos; /* position shown on screen */ 141 u_short *history_save; /* save area index */ 142 int history_size; /* size of history buffer */ 143 #if NAPM > 0 144 struct apmhook r_hook; /* reconfiguration support */ 145 #endif 146 } scr_stat; 147 148 typedef struct default_attr { 149 int std_attr; /* normal attributes */ 150 int rev_attr; /* reverse attributes */ 151 } default_attr; 152 153 /* function prototypes */ 154 int scprobe(struct isa_device *dev); 155 int scattach(struct isa_device *dev); 156 int scopen(dev_t dev, int flag, int mode, struct proc *p); 157 int scclose(dev_t dev, int flag, int mode, struct proc *p); 158 int scread(dev_t dev, struct uio *uio, int flag); 159 int scwrite(dev_t dev, struct uio *uio, int flag); 160 int scparam(struct tty *tp, struct termios *t); 161 int scioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p); 162 void scxint(dev_t dev); 163 void scstart(struct tty *tp); 164 void pccnprobe(struct consdev *cp); 165 void pccninit(struct consdev *cp); 166 void pccnputc(dev_t dev, char c); 167 int pccngetc(dev_t dev); 168 int pccncheckc(dev_t dev); 169 void scintr(int unit); 170 int pcmmap(dev_t dev, int offset, int nprot); 171 static void scinit(void); 172 static u_int scgetc(int noblock); 173 static struct tty *get_tty_ptr(dev_t dev); 174 static scr_stat *get_scr_stat(dev_t dev); 175 static scr_stat *alloc_scp(); 176 static void init_scp(scr_stat *scp); 177 static int get_scr_num(); 178 static void scrn_timer(); 179 static void clear_screen(scr_stat *scp); 180 static int switch_scr(scr_stat *scp, u_int next_scr); 181 static void exchange_scr(void); 182 static inline void move_crsr(scr_stat *scp, int x, int y); 183 static void scan_esc(scr_stat *scp, u_char c); 184 static inline void draw_cursor(scr_stat *scp, int show); 185 static void ansi_put(scr_stat *scp, u_char *buf, int len); 186 static u_char *get_fstr(u_int c, u_int *len); 187 static void update_leds(int which); 188 static void history_to_screen(scr_stat *scp); 189 static int history_up_line(scr_stat *scp); 190 static int history_down_line(scr_stat *scp); 191 static void kbd_wait(void); 192 static void kbd_cmd(u_char command); 193 static void set_mode(scr_stat *scp); 194 void set_border(int color); 195 static void set_vgaregs(char *modetable); 196 static void set_font_mode(); 197 static void set_normal_mode(); 198 static void copy_font(int operation, int font_type, char* font_image); 199 static void draw_mouse_image(scr_stat *scp); 200 static void save_palette(void); 201 void load_palette(void); 202 static void do_bell(scr_stat *scp, int pitch, int duration); 203 static void blink_screen(scr_stat *scp); 204