vidconsole.c (40775) | vidconsole.c (42002) |
---|---|
1/* 2 * Copyright (c) 1998 Michael Smith (msmith@freebsd.org) 3 * Copyright (c) 1997 Kazutaka YOKOTA (yokota@zodiac.mech.utsunomiya-u.ac.jp) 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * From Id: probe_keyboard.c,v 1.13 1997/06/09 05:10:55 bde Exp 28 * | 1/* 2 * Copyright (c) 1998 Michael Smith (msmith@freebsd.org) 3 * Copyright (c) 1997 Kazutaka YOKOTA (yokota@zodiac.mech.utsunomiya-u.ac.jp) 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * From Id: probe_keyboard.c,v 1.13 1997/06/09 05:10:55 bde Exp 28 * |
29 * $Id: vidconsole.c,v 1.7 1998/10/28 19:24:15 msmith Exp $ | 29 * $Id: vidconsole.c,v 1.8 1998/10/31 02:53:12 msmith Exp $ |
30 */ 31 32#include <stand.h> 33#include <bootstrap.h> 34#include <btxv86.h> 35#include <machine/psl.h> 36#include "libi386.h" 37 --- 5 unchanged lines hidden (view full) --- 43static void vidc_probe(struct console *cp); 44static int vidc_init(int arg); 45static void vidc_putchar(int c); 46static int vidc_getchar(void); 47static int vidc_ischar(void); 48 49static int vidc_started; 50 | 30 */ 31 32#include <stand.h> 33#include <bootstrap.h> 34#include <btxv86.h> 35#include <machine/psl.h> 36#include "libi386.h" 37 --- 5 unchanged lines hidden (view full) --- 43static void vidc_probe(struct console *cp); 44static int vidc_init(int arg); 45static void vidc_putchar(int c); 46static int vidc_getchar(void); 47static int vidc_ischar(void); 48 49static int vidc_started; 50 |
51#ifdef TERM_EMU 52void end_term(); 53void bail_out(int c); 54void vidc_term_emu(int c); 55void get_pos(void); 56void curs_move(int x, int y); 57void write_char(int c, int fg, int bg); 58void scroll_up(int rows, int fg, int bg); 59void AB(void); 60void AF(void); 61void CD(void); 62void CM(void); 63void HO(void); 64void ME(void); 65 66static int args[2],argc,br; 67static int fg,bg,dig; 68static int fg_c,bg_c,curx,cury; 69static int esc; 70#endif 71 72 |
|
51struct console vidconsole = { 52 "vidconsole", 53 "internal video/keyboard", 54 0, 55 vidc_probe, 56 vidc_init, 57 vidc_putchar, 58 vidc_getchar, --- 20 unchanged lines hidden (view full) --- 79static int 80vidc_init(int arg) 81{ 82 int i; 83 84 if (vidc_started && arg == 0) 85 return; 86 vidc_started = 1; | 73struct console vidconsole = { 74 "vidconsole", 75 "internal video/keyboard", 76 0, 77 vidc_probe, 78 vidc_init, 79 vidc_putchar, 80 vidc_getchar, --- 20 unchanged lines hidden (view full) --- 101static int 102vidc_init(int arg) 103{ 104 int i; 105 106 if (vidc_started && arg == 0) 107 return; 108 vidc_started = 1; |
109#ifdef TERM_EMU 110 /* Init terminal emulator */ 111 end_term(); 112 get_pos(); 113 curs_move(curx,cury); 114 fg_c=7; 115 bg_c=0; 116#endif |
|
87 for(i = 0; i < 10 && vidc_ischar(); i++) 88 (void)vidc_getchar(); 89 return(0); /* XXX reinit? */ 90} 91 92static void | 117 for(i = 0; i < 10 && vidc_ischar(); i++) 118 (void)vidc_getchar(); 119 return(0); /* XXX reinit? */ 120} 121 122static void |
93vidc_putchar(int c) | 123vidc_rawputchar(int c) |
94{ 95 int i; 96 | 124{ 125 int i; 126 |
97 if (c == '\t') { | 127 if(c == '\t') |
98 /* lame tab expansion */ 99 for (i = 0; i < 8; i++) | 128 /* lame tab expansion */ 129 for (i = 0; i < 8; i++) |
100 vidc_putchar(' '); 101 } else { | 130 vidc_rawputchar(' '); 131 else { 132#ifndef TERM_EMU |
102 v86.ctl = 0; | 133 v86.ctl = 0; |
134 v86.addr = 0x10; 135 v86.eax = 0xe00 | c; 136 v86.ebx = 0x7; 137 v86int(); 138#else 139 /* Emulate AH=0eh (teletype output) */ 140 switch(c) { 141 case '\r': 142 curx=0; 143 curs_move(curx,cury); 144 return; 145 case '\n': 146 cury++; 147 if(cury>24) { 148 scroll_up(1,fg_c,bg_c); 149 cury--; 150 } else { 151 curs_move(curx,cury); 152 } 153 return; 154 case '\b': 155 if(curx>0) { 156 curx--; 157 curs_move(curx,cury); 158 write_char(' ',fg_c,bg_c); 159 return; 160 } 161 return; 162 default: 163 write_char(c,fg_c,bg_c); 164 curx++; 165 if(curx>79) { 166 curx=0; 167 cury++; 168 } 169 if(cury>24) { 170 curx=0; 171 scroll_up(1,fg_c,bg_c); 172 cury--; 173 } 174 } 175 curs_move(curx,cury); 176#endif 177 } 178} 179 180#ifdef TERM_EMU 181 182/* Get cursor position on the screen. Result is in edx. Sets 183 * curx and cury appropriately. 184 */ 185void 186get_pos(void) 187{ 188 v86.ctl = 0; 189 v86.addr = 0x10; 190 v86.eax = 0x0300; 191 v86.ebx = 0x0; 192 v86int(); 193 curx=v86.edx & 0x00ff; 194 cury=(v86.edx & 0xff00)>>8; 195} 196 197/* Move cursor to x rows and y cols (0-based). */ 198void 199curs_move(int x, int y) 200{ 201 v86.ctl = 0; 202 v86.addr = 0x10; 203 v86.eax = 0x0200; 204 v86.ebx = 0x0; 205 v86.edx = ((0x00ff & y)<<8)+(0x00ff & x); 206 v86int(); 207 curx=x; 208 cury=y; 209 /* If there is ctrl char at this position, cursor would be invisible. 210 * Make it a space instead. 211 */ 212 v86.ctl=0; 213 v86.addr = 0x10; 214 v86.eax = 0x0800; 215 v86.ebx= 0x0; 216 v86int(); 217#define isvisible(c) (((c)>32) && ((c)<255)) 218 if(!isvisible(v86.eax & 0x00ff)) { 219 write_char(' ',fg_c,bg_c); 220 } 221} 222 223/* Scroll up the whole window by a number of rows. If rows==0, 224 * clear the window. fg and bg are attributes for the new lines 225 * inserted in the window. 226 */ 227void 228scroll_up(int rows, int fg, int bg) 229{ 230 if(rows==0) rows=25; 231 v86.ctl = 0; |
|
103 v86.addr = 0x10; | 232 v86.addr = 0x10; |
104 v86.eax = 0xe00 | c; 105 v86.ebx = 0x7; | 233 v86.eax = 0x0600+(0x00ff & rows); 234 v86.ebx = (bg<<12)+(fg<<8); 235 v86.ecx = 0x0; 236 v86.edx = 0x184f; |
106 v86int(); | 237 v86int(); |
238} 239 240/* Write character and attribute at cursor position. */ 241void 242write_char(int c, int fg, int bg) 243{ 244 v86.ctl=0; 245 v86.addr = 0x10; 246 v86.eax = 0x0900+(0x00ff & c); 247 v86.ebx = (bg<<4)+fg; 248 v86.ecx = 0x1; 249 v86int(); 250} 251 252/* Calculate power of 10 */ 253int 254pow10(int i) 255{ 256 int res=1; 257 258 while(i-->0) { 259 res*=10; 260 } 261 return res; 262} 263 264/**************************************************************/ 265/* 266 * Screen manipulation functions. They use accumulated data in 267 * args[] and argc variables. 268 * 269 */ 270 271/* Set background color */ 272void 273AB(void){ 274 bg_c=args[0]; 275 end_term(); 276} 277 278/* Set foreground color */ 279void 280AF(void) 281{ 282 fg_c=args[0]; 283 end_term(); 284} 285 286/* Clear display from current position to end of screen */ 287void 288CD(void) 289{ 290 get_pos(); 291 v86.ctl = 0; 292 v86.addr = 0x10; 293 v86.eax = 0x0600; 294 v86.ebx = (bg_c<<4)+fg_c; 295 v86.ecx = v86.edx; 296 v86.edx = 0x184f; 297 v86int(); 298 curx=0; 299 curs_move(curx,cury); 300 end_term(); 301} 302 303/* Absolute cursor move to args[0] rows and args[1] columns 304 * (the coordinates are 1-based). 305 */ 306void 307CM(void) 308{ 309 if(args[0]>0) args[0]--; 310 if(args[1]>0) args[1]--; 311 curs_move(args[1],args[0]); 312 end_term(); 313} 314 315/* Home cursor (left top corner) */ 316void 317HO(void) 318{ 319 argc=1; 320 args[0]=args[1]=1; 321 CM(); 322} 323 324/* Exit attribute mode (reset fore/back-ground colors to defaults) */ 325void 326ME(void) 327{ 328 fg_c=7; 329 bg_c=0; 330 end_term(); 331} 332 333/* Clear internal state of the terminal emulation code */ 334void 335end_term(void) 336{ 337 esc=0; 338 argc=-1; 339 fg=bg=br=0; 340 args[0]=args[1]=0; 341 dig=0; 342} 343 344/* Gracefully exit ESC-sequence processing in case of misunderstanding */ 345void 346bail_out(int c) 347{ 348 char buf[6],*ch; 349 350 if(esc) vidc_rawputchar('\033'); 351 if(br) vidc_rawputchar('['); 352 if(argc>-1) { 353 sprintf(buf,"%d",args[0]); 354 ch=buf; 355 while(*ch) vidc_rawputchar(*ch++); 356 357 if(argc>0) { 358 vidc_rawputchar(';'); 359 sprintf(buf,"%d",args[1]); 360 ch=buf; 361 while(*ch) vidc_rawputchar(*ch++); 362 } 363 } 364 vidc_rawputchar(c); 365 end_term(); 366} 367 368/* Emulate basic capabilities of cons25 terminal */ 369void 370vidc_term_emu(int c) 371{ 372 373 if(!esc) { 374 if(c=='\033') { 375 esc=1; 376 } else { 377 vidc_rawputchar(c); 378 } 379 return; |
|
107 } | 380 } |
381 382 /* Do ESC sequences processing */ 383 switch(c) { 384 case '\033': 385 /* ESC in ESC sequence - error */ 386 bail_out(c); 387 break; 388 case '[': 389 /* Check if it's first char after ESC */ 390 if(argc<0) { 391 br=1; 392 } else { 393 bail_out(c); 394 } 395 break; 396 case 'H': 397 /* Emulate \E[H (cursor home) and 398 * \E%d;%dH (cursor absolute move) */ 399 if(br) { 400 switch(argc) { 401 case -1: 402 HO(); 403 break; 404 case 1: 405 if(fg) args[0]+=pow10(dig)*3; 406 if(bg) args[0]+=pow10(dig)*4; 407 CM(); 408 break; 409 default: 410 bail_out(c); 411 } 412 } else bail_out(c); 413 break; 414 case 'J': 415 /* Emulate \EJ (clear to end of screen) */ 416 if(br && argc<0) { 417 CD(); 418 } else bail_out(c); 419 break; 420 case ';': 421 /* perhaps args separator */ 422 if(br && (argc>-1)) { 423 argc++; 424 } else bail_out(c); 425 break; 426 case 'm': 427 /* Change char attributes */ 428 if(br) { 429 switch(argc) { 430 case -1: 431 ME(); 432 break; 433 case 0: 434 if(fg) AF(); 435 else AB(); 436 break; 437 default: 438 bail_out(c); 439 } 440 } else bail_out(c); 441 break; 442 default: 443 if(isdigit(c)) { 444 /* Carefully collect numeric arguments */ 445 /* XXX this is ugly. */ 446 if(br) { 447 if(argc==-1) { 448 argc=0; 449 args[argc]=0; 450 dig=0; 451 /* in case we're in error... */ 452 if(c=='3') { 453 fg=1; 454 return; 455 } 456 if(c=='4') { 457 bg=1; 458 return; 459 } 460 args[argc]=(int)(c-'0'); 461 dig=1; 462 args[argc+1]=0; 463 } else { 464 args[argc]=args[argc]*10+(int)(c-'0'); 465 if(argc==0) dig++; 466 } 467 } else bail_out(c); 468 } else bail_out(c); 469 break; 470 } |
|
108} | 471} |
472#endif |
|
109 | 473 |
474static void 475vidc_putchar(int c) 476{ 477#ifdef TERM_EMU 478 vidc_term_emu(c); 479#else 480 vidc_rawputchar(c); 481#endif 482} 483 |
|
110static int 111vidc_getchar(void) 112{ 113 if (vidc_ischar()) { 114 v86.ctl = 0; 115 v86.addr = 0x16; 116 v86.eax = 0x0; 117 v86int(); --- 31 unchanged lines hidden (view full) --- 149#define KBDS_INPUT_BUFFER_FULL 0x0002 150#define KBD_ECHO 0x00ee 151 152/* 7 microsec delay necessary for some keyboard controllers */ 153static void 154delay7(void) 155{ 156 /* | 484static int 485vidc_getchar(void) 486{ 487 if (vidc_ischar()) { 488 v86.ctl = 0; 489 v86.addr = 0x16; 490 v86.eax = 0x0; 491 v86int(); --- 31 unchanged lines hidden (view full) --- 523#define KBDS_INPUT_BUFFER_FULL 0x0002 524#define KBD_ECHO 0x00ee 525 526/* 7 microsec delay necessary for some keyboard controllers */ 527static void 528delay7(void) 529{ 530 /* |
157 * I know this is broken, but no timer is avaiable yet at this stage... | 531 * I know this is broken, but no timer is available yet at this stage... |
158 * See also comments in `delay1ms()'. 159 */ 160 inb(IO_DUMMY); inb(IO_DUMMY); 161 inb(IO_DUMMY); inb(IO_DUMMY); 162 inb(IO_DUMMY); inb(IO_DUMMY); 163} 164 165/* --- 79 unchanged lines hidden --- | 532 * See also comments in `delay1ms()'. 533 */ 534 inb(IO_DUMMY); inb(IO_DUMMY); 535 inb(IO_DUMMY); inb(IO_DUMMY); 536 inb(IO_DUMMY); inb(IO_DUMMY); 537} 538 539/* --- 79 unchanged lines hidden --- |