📄 console.h
字号:
14234
14235 case 7: /* REVERSE */
14236 if (color) {
14237 /* Swap fg and bg colors */
14238 cons->c_attr =
14239 ((cons->c_attr & 0xf000) >> 4) |
14240 ((cons->c_attr & 0x0f00) << 4);
14241 } else
14242 if ((cons->c_attr & 0x7000) == 0) {
14243 cons->c_attr = (cons->c_attr & 0x8800) | 0x7000;
14244 } else {
14245 cons->c_attr = (cons->c_attr & 0x8800) | 0x0700;
14246 }
14247 break;
14248
14249 default: /* COLOR */
14250 if (30 <= value && value <= 37) {
14251 cons->c_attr =
14252 (cons->c_attr & 0xf0ff) |
14253 (ansi_colors[(value - 30)] << 8);
14254 cons->c_blank =
14255 (cons->c_blank & 0xf0ff) |
14256 (ansi_colors[(value - 30)] << 8);
14257 } else
14258 if (40 <= value && value <= 47) {
14259 cons->c_attr =
14260 (cons->c_attr & 0x0fff) |
14261 (ansi_colors[(value - 40)] << 12);
14262 cons->c_blank =
14263 (cons->c_blank & 0x0fff) |
14264 (ansi_colors[(value - 40)] << 12);
14265 } else {
14266 cons->c_attr = cons->c_blank;
14267 }
14268 break;
14269 }
14270 break;
14271 }
14272 }
14273 cons->c_esc_state = 0;
14274 }
14277 /*===========================================================================*
14278 * set_6845 *
14279 *===========================================================================*/
14280 PRIVATE void set_6845(reg, val)
14281 int reg; /* which register pair to set */
14282 unsigned val; /* 16-bit value to set it to */
14283 {
14284 /* Set a register pair inside the 6845.
14285 * Registers 12-13 tell the 6845 where in video ram to start
14286 * Registers 14-15 tell the 6845 where to put the cursor
14287 */
14288 lock(); /* try to stop h/w loading in-between value */
14289 out_byte(vid_port + INDEX, reg); /* set the index register */
14290 out_byte(vid_port + DATA, (val>>8) & BYTE); /* output high byte */
14291 out_byte(vid_port + INDEX, reg + 1); /* again */
14292 out_byte(vid_port + DATA, val&BYTE); /* output low byte */
14293 unlock();
14294 }
14297 /*===========================================================================*
14298 * beep *
14299 *===========================================================================*/
14300 PRIVATE void beep()
14301 {
14302 /* Making a beeping sound on the speaker (output for CRTL-G).
14303 * This routine works by turning on the bits 0 and 1 in port B of the 8255
14304 * chip that drives the speaker.
14305 */
14306
14307 message mess;
14308
14309 if (beeping) return;
14310 out_byte(TIMER_MODE, 0xB6); /* set up timer channel 2 (square wave) */
14311 out_byte(TIMER2, BEEP_FREQ & BYTE); /* load low-order bits of frequency */
14312 out_byte(TIMER2, (BEEP_FREQ >> 8) & BYTE); /* now high-order bits */
14313 lock(); /* guard PORT_B from keyboard intr handler */
14314 out_byte(PORT_B, in_byte(PORT_B) | 3); /* turn on beep bits */
14315 unlock();
14316 beeping = TRUE;
14317
14318 mess.m_type = SET_ALARM;
14319 mess.CLOCK_PROC_NR = TTY;
14320 mess.DELTA_TICKS = B_TIME;
14321 mess.FUNC_TO_CALL = (sighandler_t) stop_beep;
14322 sendrec(CLOCK, &mess);
14323 }
14326 /*===========================================================================*
14327 * stop_beep *
14328 *===========================================================================*/
14329 PRIVATE void stop_beep()
14330 {
14331 /* Turn off the beeper by turning off bits 0 and 1 in PORT_B. */
14332
14333 lock(); /* guard PORT_B from keyboard intr handler */
14334 out_byte(PORT_B, in_byte(PORT_B) & ~3);
14335 beeping = FALSE;
14336 unlock();
14337 }
14340 /*===========================================================================*
14341 * scr_init *
14342 *===========================================================================*/
14343 PUBLIC void scr_init(tp)
14344 tty_t *tp;
14345 {
14346 /* Initialize the screen driver. */
14347 console_t *cons;
14348 phys_bytes vid_base;
14349 u16_t bios_crtbase;
14350 int line;
14351 unsigned page_size;
14352
14353 /* Associate console and TTY. */
14354 line = tp - &tty_table[0];
14355 if (line >= nr_cons) return;
14356 cons = &cons_table[line];
14357 cons->c_tty = tp;
14358 tp->tty_priv = cons;
14359
14360 /* Initialize the keyboard driver. */
14361 kb_init(tp);
14362
14363 /* Output functions. */
14364 tp->tty_devwrite = cons_write;
14365 tp->tty_echo = cons_echo;
14366
14367 /* Get the BIOS parameters that tells the VDU I/O base register. */
14368 phys_copy(0x463L, vir2phys(&bios_crtbase), 2L);
14369
14370 vid_port = bios_crtbase;
14371
14372 if (color) {
14373 vid_base = COLOR_BASE;
14374 vid_size = COLOR_SIZE;
14375 } else {
14376 vid_base = MONO_BASE;
14377 vid_size = MONO_SIZE;
14378 }
14379 if (ega) vid_size = EGA_SIZE; /* for both EGA and VGA */
14380 wrap = !ega;
14381
14382 vid_seg = protected_mode ? VIDEO_SELECTOR : physb_to_hclick(vid_base);
14383 init_dataseg(&gdt[VIDEO_INDEX], vid_base, (phys_bytes) vid_size,
14384 TASK_PRIVILEGE);
14385 vid_size >>= 1; /* word count */
14386 vid_mask = vid_size - 1;
14387
14388 /* There can be as many consoles as video memory allows. */
14389 nr_cons = vid_size / scr_size;
14390 if (nr_cons > NR_CONS) nr_cons = NR_CONS;
14391 if (nr_cons > 1) wrap = 0;
14392 page_size = vid_size / nr_cons;
14393 cons->c_start = line * page_size;
14394 cons->c_limit = cons->c_start + page_size;
14395 cons->c_org = cons->c_start;
14396 cons->c_attr = cons->c_blank = BLANK_COLOR;
14397
14398 /* Clear the screen. */
14399 blank_color = BLANK_COLOR;
14400 mem_vid_copy(BLANK_MEM, cons->c_start, scr_size);
14401 select_console(0);
14402 }
14405 /*===========================================================================*
14406 * putk *
14407 *===========================================================================*/
14408 PUBLIC void putk(c)
14409 int c; /* character to print */
14410 {
14411 /* This procedure is used by the version of printf() that is linked with
14412 * the kernel itself. The one in the library sends a message to FS, which is
14413 * not what is needed for printing within the kernel. This version just queues
14414 * the character and starts the output.
14415 */
14416
14417 if (c != 0) {
14418 if (c == '\n') putk('\r');
14419 out_char(&cons_table[0], (int) c);
14420 } else {
14421 flush(&cons_table[0]);
14422 }
14423 }
14426 /*===========================================================================*
14427 * toggle_scroll *
14428 *===========================================================================*/
14429 PUBLIC void toggle_scroll()
14430 {
14431 /* Toggle between hardware and software scroll. */
14432
14433 cons_org0();
14434 softscroll = !softscroll;
14435 printf("%sware scrolling enabled.\n", softscroll ? "Soft" : "Hard");
14436 }
14439 /*===========================================================================*
14440 * cons_stop *
14441 *===========================================================================*/
14442 PUBLIC void cons_stop()
14443 {
14444 /* Prepare for halt or reboot. */
14445
14446 cons_org0();
14447 softscroll = 1;
14448 select_console(0);
14449 cons_table[0].c_attr = cons_table[0].c_blank = BLANK_COLOR;
14450 }
14453 /*===========================================================================*
14454 * cons_org0 *
14455 *===========================================================================*/
14456 PRIVATE void cons_org0()
14457 {
14458 /* Scroll video memory back to put the origin at 0. */
14459
14460 int cons_line;
14461 console_t *cons;
14462 unsigned n;
14463
14464 for (cons_line = 0; cons_line < nr_cons; cons_line++) {
14465 cons = &cons_table[cons_line];
14466 while (cons->c_org > cons->c_start) {
14467 n = vid_size - scr_size; /* amount of unused memory */
14468 if (n > cons->c_org - cons->c_start)
14469 n = cons->c_org - cons->c_start;
14470 vid_vid_copy(cons->c_org, cons->c_org - n, scr_size);
14471 cons->c_org -= n;
14472 }
14473 flush(cons);
14474 }
14475 select_console(current);
14476 }
14479 /*===========================================================================*
14480 * select_console *
14481 *===========================================================================*/
14482 PUBLIC void select_console(int cons_line)
14483 {
14484 /* Set the current console to console number 'cons_line'. */
14485
14486 if (cons_line < 0 || cons_line >= nr_cons) return;
14487 current = cons_line;
14488 curcons = &cons_table[cons_line];
14489 set_6845(VID_ORG, curcons->c_org);
14490 set_6845(CURSOR, curcons->c_cur);
14491 }
14494 /*===========================================================================*
14495 * con_loadfont *
14496 *===========================================================================*/
14497 PUBLIC int con_loadfont(user_phys)
14498 phys_bytes user_phys;
14499 {
14500 /* Load a font into the EGA or VGA adapter. */
14501
14502 static struct sequence seq1[7] = {
14503 { GA_SEQUENCER_INDEX, 0x00, 0x01 },
14504 { GA_SEQUENCER_INDEX, 0x02, 0x04 },
14505 { GA_SEQUENCER_INDEX, 0x04, 0x07 },
14506 { GA_SEQUENCER_INDEX, 0x00, 0x03 },
14507 { GA_GRAPHICS_INDEX, 0x04, 0x02 },
14508 { GA_GRAPHICS_INDEX, 0x05, 0x00 },
14509 { GA_GRAPHICS_INDEX, 0x06, 0x00 },
14510 };
14511 static struct sequence seq2[7] = {
14512 { GA_SEQUENCER_INDEX, 0x00, 0x01 },
14513 { GA_SEQUENCER_INDEX, 0x02, 0x03 },
14514 { GA_SEQUENCER_INDEX, 0x04, 0x03 },
14515 { GA_SEQUENCER_INDEX, 0x00, 0x03 },
14516 { GA_GRAPHICS_INDEX, 0x04, 0x00 },
14517 { GA_GRAPHICS_INDEX, 0x05, 0x10 },
14518 { GA_GRAPHICS_INDEX, 0x06, 0 },
14519 };
14520
14521 seq2[6].value= color ? 0x0E : 0x0A;
14522
14523 if (!ega) return(ENOTTY);
14524
14525 lock();
14526 ga_program(seq1); /* bring font memory into view */
14527
14528 phys_copy(user_phys, (phys_bytes)GA_VIDEO_ADDRESS, (phys_bytes)GA_FONT_SIZE);
14529
14530 ga_program(seq2); /* restore */
14531 unlock();
14532
14533 return(OK);
14534 }
14537 /*===========================================================================*
14538 * ga_program *
14539 *===========================================================================*/
14540 PRIVATE void ga_program(seq)
14541 struct sequence *seq;
14542 {
14543 /* support function for con_loadfont */
14544
14545 int len= 7;
14546 do {
14547 out_byte(seq->index, seq->port);
14548 out_byte(seq->index+1, seq->value);
14549 seq++;
14550 } while (--len > 0);
14551 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -