📄 console.c
字号:
bottom = video_num_lines; scrdown(); top=oldtop; bottom=oldbottom;}static void delete_char(void)/*删除一个字符*/{ int i; unsigned short * p = (unsigned short *) pos; if (x>=video_num_columns) return; i = x; while (++i < video_num_columns) { *p = *(p+1); p++; } *p = video_erase_char;}static void delete_line(void)/*删除行*/{ int oldtop,oldbottom; oldtop=top; oldbottom=bottom; top=y; bottom = video_num_lines; scrup(); top=oldtop; bottom=oldbottom;}static void csi_at(unsigned int nr)/*插入nr个字符*/{ if (nr > video_num_columns) nr = video_num_columns; else if (!nr) nr = 1; while (nr--) insert_char();}static void csi_L(unsigned int nr)/*插入nr行*/{ if (nr > video_num_lines) nr = video_num_lines; else if (!nr) nr = 1; while (nr--) insert_line();}static void csi_P(unsigned int nr)/*删除nr个字符*/{ if (nr > video_num_columns) nr = video_num_columns; else if (!nr) nr = 1; while (nr--) delete_char();}static void csi_M(unsigned int nr)/*删除nr行*/{ if (nr > video_num_lines) nr = video_num_lines; else if (!nr) nr=1; while (nr--) delete_line();}static int saved_x=0;static int saved_y=0;static void save_cur(void)/*保存光标*/{ saved_x=x; saved_y=y;}static void restore_cur(void)/*恢复保存的光标位置*/{ gotoxy(saved_x, saved_y);}void con_write(struct tty_struct * tty)/*控制台写函数(p362)*/{ int nr; char c; nr = CHARS(tty->write_q); while (nr--) { GETCH(tty->write_q,c); switch(state) { case 0: if (c>31 && c<127) { if (x>=video_num_columns) { x -= video_num_columns; pos -= video_size_row; lf(); } __asm__("movb _attr,%%ah\n\t" "movw %%ax,%1\n\t" ::"a" (c),"m" (*(short *)pos) :"ax"); pos += 2; x++; } else if (c==27) state=1; else if (c==10 || c==11 || c==12) lf(); else if (c==13) cr(); else if (c==ERASE_CHAR(tty)) del(); else if (c==8) { if (x) { x--; pos -= 2; } } else if (c==9) { c=8-(x&7); x += c; pos += c<<1; if (x>video_num_columns) { x -= video_num_columns; pos -= video_size_row; lf(); } c=9; } else if (c==7) sysbeep(); break; case 1: state=0; if (c=='[') state=2; else if (c=='E') gotoxy(0,y+1); else if (c=='M') ri(); else if (c=='D') lf(); else if (c=='Z') respond(tty); else if (x=='7') save_cur(); else if (x=='8') restore_cur(); break; case 2: for(npar=0;npar<NPAR;npar++) par[npar]=0; npar=0; state=3; if (ques=(c=='?')) break; case 3: if (c==';' && npar<NPAR-1) { npar++; break; } else if (c>='0' && c<='9') { par[npar]=10*par[npar]+c-'0'; break; } else state=4; case 4: state=0; switch(c) { case 'G': case '`': if (par[0]) par[0]--; gotoxy(par[0],y); break; case 'A': if (!par[0]) par[0]++; gotoxy(x,y-par[0]); break; case 'B': case 'e': if (!par[0]) par[0]++; gotoxy(x,y+par[0]); break; case 'C': case 'a': if (!par[0]) par[0]++; gotoxy(x+par[0],y); break; case 'D': if (!par[0]) par[0]++; gotoxy(x-par[0],y); break; case 'E': if (!par[0]) par[0]++; gotoxy(0,y+par[0]); break; case 'F': if (!par[0]) par[0]++; gotoxy(0,y-par[0]); break; case 'd': if (par[0]) par[0]--; gotoxy(x,par[0]); break; case 'H': case 'f': if (par[0]) par[0]--; if (par[1]) par[1]--; gotoxy(par[1],par[0]); break; case 'J': csi_J(par[0]); break; case 'K': csi_K(par[0]); break; case 'L': csi_L(par[0]); break; case 'M': csi_M(par[0]); break; case 'P': csi_P(par[0]); break; case '@': csi_at(par[0]); break; case 'm': csi_m(); break; case 'r': if (par[0]) par[0]--; if (!par[1]) par[1] = video_num_lines; if (par[0] < par[1] && par[1] <= video_num_lines) { top=par[0]; bottom=par[1]; } break; case 's': save_cur(); break; case 'u': restore_cur(); break; } } } set_cursor();}/* * void con_init(void); * * This routine initalizes console interrupts, and does nothing * else. If you want the screen to clear, call tty_write with * the appropriate escape-sequece. * * Reads the information preserved by setup.s to determine the current display * type and sets everything accordingly. */void con_init(void) /*控制台初始化:显示器显卡参数设置,开键盘中断*/{ register unsigned char a; char *display_desc = "????"; char *display_ptr; video_num_columns = ORIG_VIDEO_COLS;/*显示器显示字符列数*/ video_size_row = video_num_columns * 2;/*每行字符需使用的字节数*/ video_num_lines = ORIG_VIDEO_LINES;/*显示器显示字符行数*/ video_page = ORIG_VIDEO_PAGE;/*当前显示页面*/ video_erase_char = 0x0720;/*擦除字符(0x20是字符,0x07是属性)*/ /*判断是显卡及显示器类型*/ if (ORIG_VIDEO_MODE == 7) /*判断是否是单色显示器*/ { /*为单色的情况*/ video_mem_start = 0xb0000; /*设置单色显示器显存起始地址*/ video_port_reg = 0x3b4; /*设置单色显示器索引寄存器端口号*/ video_port_val = 0x3b5; /*设置单色显示器数据寄存器端口*/ if ((ORIG_VIDEO_EGA_BX & 0xff) != 0x10) /*判断是单色显卡还是彩色显卡*/ { video_type = VIDEO_TYPE_EGAM; /*设置显示类型(EGA单色)*/ video_mem_end = 0xb8000; /*设置显示内存末端地址*/ display_desc = "EGAm"; /*设置显示描述字符串*/ } else { video_type = VIDEO_TYPE_MDA; /*设置显示类型(MDA单色)*/ video_mem_end = 0xb2000; /*设置显示内存末端地址*/ display_desc = "*MDA"; /*设置显示描述字符串*/ } } else /* If not, it is color. */ { /*为彩色的情况*/ video_mem_start = 0xb8000;/*设置彩色显示器显存起始地址*/ video_port_reg = 0x3d4;/*设置彩色显示器索引寄存器端口号*/ video_port_val = 0x3d5; /*设置彩色显示器数据寄存器端口*/ if ((ORIG_VIDEO_EGA_BX & 0xff) != 0x10) /*判断是单色显卡还是彩色显卡*/ { video_type = VIDEO_TYPE_EGAC; video_mem_end = 0xbc000; display_desc = "EGAc"; } else { video_type = VIDEO_TYPE_CGA; video_mem_end = 0xba000; display_desc = "*CGA"; } } /* Let the user known what kind of display driver we are using */ /*在屏幕右上角显示描述字符串(好像不能显示?)*/ display_ptr = ((char *)video_mem_start) + video_size_row - 8; /*直接将字符串写道显存中相应的位置*/ while (*display_desc) { *display_ptr++ = *display_desc++; /*复制描述字符串*/ display_ptr++; } /* Initialize the variables used for scrolling (mostly EGA/VGA) */ /*初始化用于滚屏的变量*/ origin = video_mem_start; /*滚屏起始显示内存地址*/ scr_end = video_mem_start + video_num_lines * video_size_row; /*结束地址*/ top = 0; /*最顶行号*/ bottom = video_num_lines; /*最底行号*/ gotoxy(ORIG_X,ORIG_Y); /*初始化光标当前所在位置和光标对应的内存位置pos。*/ set_trap_gate(0x21,&keyboard_interrupt); /*设置键盘中断*/ outb_p(inb_p(0x21)&0xfd,0x21); /*取消8259A对键盘中断的屏蔽*/ a=inb_p(0x61); /*读取键盘端口*/ outb_p(a|0x80,0x61); /*设置禁止键盘工作*/ outb(a,0x61); /*再允许键盘工作,用以复位键盘*/}/* from bsd-net-2: */void sysbeepstop(void){ /* disable counter 2 */ outb(inb_p(0x61)&0xFC, 0x61);}int beepcount = 0;static void sysbeep(void){ /* enable counter 2 */ outb_p(inb_p(0x61)|3, 0x61); /* set command for counter 2, 2 byte write */ outb_p(0xB6, 0x43); /* send 0x637 for 750 HZ */ outb_p(0x37, 0x42); outb(0x06, 0x42); /* 1/8 second */ beepcount = HZ/8; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -