📄 console.c
字号:
/* * gotoxy() must verify all boundaries, because the arguments * might also be negative. If the given position is out of * bounds, the cursor is placed at the nearest margin. */static void gotoxy(int currcons, int new_x, int new_y){ int min_y, max_y; if (new_x < 0) x = 0; else if (new_x >= cols) x = cols - 1; else x = new_x; if (decom) { min_y = top; max_y = bottom; } else { min_y = 0; max_y = rows; } if (new_y < min_y) y = min_y; else if (new_y >= max_y) y = max_y - 1; else y = new_y; pos = video_mem_start + y * cols + x; need_wrap = 0;}/* for absolute user moves, when decom is set */static void gotoxay(int currcons, int new_x, int new_y){ gotoxy(currcons, new_x, decom ? (top+new_y) : new_y);}static void hide_cursor(int currcons){ sw->con_cursor(vc_cons[currcons].d,CM_ERASE); return;}static void set_cursor(int currcons){ if (currcons != fg_console || console_blanked || vcmode == KD_GRAPHICS) return; if (deccm) sw->con_cursor(vc_cons[currcons].d,CM_DRAW); else hide_cursor(currcons); return;}void no_scroll(char *str, int *ints){ /* * no_scroll currently does nothing on the m68k. */}/* * Arno: * Why do we need these? The keyboard code doesn't seem to do anything * with them either... */void scrollfront(int l){ return;}void scrollback(int l){ return;}static void scrup(int currcons, unsigned int t, unsigned int b, int nr){ unsigned short *p; int i; if (b > rows || t >= b) return; memmove (video_mem_start + t * cols, video_mem_start + (t + nr) * cols, (b - t - nr) * cols * 2); p = video_mem_start + (b - nr) * cols; for (i = nr * cols; i > 0; i--) *p++ = video_erase_char; if (currcons != fg_console) return;/* * Arno: * Scrolling has now been moved to amicon.c where it should have * been all along. */ sw->con_scroll(vc_cons[currcons].d, t, b, SM_UP, nr); return; }static void scrdown(int currcons, unsigned int t, unsigned int b, int nr){ unsigned short *p; int i; if (b > rows || t >= b) return; memmove (video_mem_start + (t + nr) * cols, video_mem_start + t * cols, (b - t - nr) * cols * 2); p = video_mem_start + t * cols; for (i = nr * cols; i > 0; i--) *p++ = video_erase_char; if (currcons != fg_console) return;/* * Arno: * Scrolling has now been moved to amicon.c where it should have * been all along. */ sw->con_scroll(vc_cons[currcons].d, t, b, SM_DOWN, nr); return;}static void lf(int currcons){ /* don't scroll if above bottom of scrolling region, or * if below scrolling region */ if (y+1 == bottom) scrup(currcons,top,bottom, 1); else if (y < rows-1) { y++; pos += cols; } need_wrap = 0;}static void ri(int currcons){ /* don't scroll if below top of scrolling region, or * if above scrolling region */ if (y == top) scrdown(currcons,top,bottom, 1); else if (y > 0) { y--; pos -= cols; } need_wrap = 0;}static inline void cr(int currcons){ pos -= x; need_wrap = x = 0;}static inline void bs(int currcons){ if (x) { pos--; x--; need_wrap = 0; }}static inline void del(int currcons){ /* ignored */}static void csi_J(int currcons, int vpar){ unsigned long count; unsigned short *start; switch (vpar) { case 0: /* erase from cursor to end of display */ count = (video_mem_start + cols * rows - pos); start = pos; if (currcons != fg_console) break; /* 680x0 do in two stages */ sw->con_clear(vc_cons[currcons].d,y,x,1,cols-x); sw->con_clear(vc_cons[currcons].d,y+1,0,rows-y-1, cols); break; case 1: /* erase from start to cursor */ count = pos - video_mem_start + 1; start = video_mem_start; if (currcons != fg_console) break; /* 680x0 do in two stages */ sw->con_clear(vc_cons[currcons].d,0,0,y, cols); sw->con_clear(vc_cons[currcons].d,y,0,1,x + 1); break; case 2: /* erase whole display */ count = cols * rows; start = video_mem_start; if (currcons != fg_console) break; sw->con_clear(vc_cons[currcons].d,0,0,rows, cols); break; default: return; } while (count-- > 0) *start++ = video_erase_char; need_wrap = 0;}static void csi_K(int currcons, int vpar){ unsigned long count; unsigned short *start; switch (vpar) { case 0: /* erase from cursor to end of line */ count = cols - x; start = pos; if (currcons != fg_console) break; sw->con_clear(vc_cons[currcons].d,y,x,1,cols-x); break; case 1: /* erase from start of line to cursor */ start = pos - x; count = x + 1; if (currcons != fg_console) break; sw->con_clear(vc_cons[currcons].d,y,0,1,x + 1); break; case 2: /* erase whole line */ start = pos - x; count = cols; if (currcons != fg_console) break; sw->con_clear(vc_cons[currcons].d,y,0,1,cols); break; default: return; } while (count-- > 0) *start++ = video_erase_char; need_wrap = 0;}static void csi_X(int currcons, int vpar) /* erase the following vpar positions */{ /* not vt100? */ unsigned long count; unsigned short * start; if (!vpar) vpar++; start=pos; count=(vpar > cols-x) ? (cols-x) : vpar; if (currcons == fg_console) sw->con_clear(vc_cons[currcons].d,y,x,1,count); while (count-- > 0) *start++ = video_erase_char; need_wrap = 0;}/* * Arno: * On 680x0 attributes are currently not used. This piece of code * seems hardware independent, but uses the EGA/VGA way of representing * attributes. * TODO: modify for 680x0 and add attribute processing to putc code. * * ++roman: I completely changed the attribute format for monochrome * mode (!can_do_color). The formerly used MDA (monochrome display * adapter) format didn't allow the combination of certain effects. * Now the attribute is just a bit vector: * Bit 0..1: intensity (0..2) * Bit 2 : underline * Bit 3 : reverse * Bit 7 : blink */static void update_attr(int currcons){ if (!can_do_color) { /* Special treatment for monochrome */ attr = intensity | (underline ? 4 : 0) | ((reverse ^ decscnm) ? 8 : 0) | (blink ? 0x80 : 0); video_erase_char = ' ' | ((reverse ^ decscnm) ? 0x800 : 0); return; } attr = color; if (underline) attr = (attr & 0xf0) | ulcolor; else if (intensity == 0) attr = (attr & 0xf0) | halfcolor; if (reverse ^ decscnm) attr = reverse_video_char(attr); if (blink) attr ^= 0x80; if (intensity == 2) attr ^= 0x08; if (decscnm) video_erase_char = (reverse_video_char(color) << 8) | ' '; else video_erase_char = (color << 8) | ' ';}static void default_attr(int currcons){ intensity = 1; underline = 0; reverse = 0; blink = 0; color = def_color;}static void csi_m(int currcons){ int i; for (i=0;i<=npar;i++) switch (par[i]) { case 0: /* all attributes off */ default_attr(currcons); break; case 1: intensity = 2; break; case 2: intensity = 0; break; case 4: underline = 1; break; case 5: blink = 1; break; case 7: reverse = 1; break; case 10: /* ANSI X3.64-1979 (SCO-ish?) * Select primary font, don't display * control chars if defined, don't set * bit 8 on output. */ translate = set_translate(charset == 0 ? G0_charset : G1_charset); disp_ctrl = 0; toggle_meta = 0; break; case 11: /* ANSI X3.64-1979 (SCO-ish?) * Select first alternate font, let's * chars < 32 be displayed as ROM chars. */ translate = set_translate(IBMPC_MAP); disp_ctrl = 1; toggle_meta = 0; break; case 12: /* ANSI X3.64-1979 (SCO-ish?) * Select second alternate font, toggle * high bit before displaying as ROM char. */ translate = set_translate(IBMPC_MAP); disp_ctrl = 1; toggle_meta = 1; break; case 21: case 22: intensity = 1; break; case 24: underline = 0; break; case 25: blink = 0; break; case 27: reverse = 0; break; case 38: /* ANSI X3.64-1979 (SCO-ish?) * Enables underscore, white foreground * with white underscore (Linux - use * default foreground). */ color = (def_color & 0x0f) | background; underline = 1; break; case 39: /* ANSI X3.64-1979 (SCO-ish?) * Disable underline option. * Reset colour to default? It did this * before... */ color = (def_color & 0x0f) | background; underline = 0; break; case 49: color = (def_color & 0xf0) | foreground; break; default: if (par[i] >= 30 && par[i] <= 37) color = color_table[par[i]-30] | background; else if (par[i] >= 40 && par[i] <= 47) color = (color_table[par[i]-40]<<4) | foreground; break; } update_attr(currcons);}static void respond_string(const char * p, struct tty_struct * tty){ while (*p) { tty_insert_flip_char(tty, *p, 0); p++; } tty_schedule_flip(tty);}static void cursor_report(int currcons, struct tty_struct * tty){ char buf[40]; sprintf(buf, "\033[%ld;%ldR", y + (decom ? top+1 : 1), x+1); respond_string(buf, tty);}static inline void status_report(struct tty_struct * tty){ respond_string("\033[0n", tty); /* Terminal ok */}static inline void respond_ID(struct tty_struct * tty){ respond_string(VT102ID, tty);}void mouse_report(struct tty_struct * tty, int butt, int mrx, int mry){ char buf[8]; sprintf(buf, "\033[M%c%c%c", (char)(' ' + butt), (char)('!' + mrx), (char)('!' + mry)); respond_string(buf, tty);}/* invoked via ioctl(TIOCLINUX) */int mouse_reporting(void){ int currcons = fg_console; return report_mouse;}static inline unsigned short *screenpos(int currcons, int offset, int viewed){ unsigned short *p = (unsigned short *)(origin + offset);#if 0 if (viewed && currcons == fg_console) p -= (__real_origin - __origin);#endif return p;}/* Note: inverting the screen twice should revert to the original state */void invert_screen(int currcons, int offset, int count, int viewed){ unsigned short *p; unsigned short xx, yy, oldattr; count /= 2; p = screenpos(currcons, offset, viewed); xx = (offset >> 1) % cols; yy = (offset >> 1) / cols; oldattr = attr; if (can_do_color) while (count--) { unsigned short old = scr_readw(p); unsigned short new = reverse_video_short(old); scr_writew(new, p); p++; if (currcons != fg_console) continue; attr = new >> 8; sw->con_putc(vc_cons[currcons].d, new & 0xff, yy, xx); if (++xx == cols) xx = 0, ++yy; } else while (count--) { unsigned short old = scr_readw(p); unsigned short new = old ^ 0x800; scr_writew(new, p); p++; if (currcons != fg_console) continue; attr = new >> 8; sw->con_putc(vc_cons[currcons].d, new & 0xff, yy, xx); if (++xx == cols) xx = 0, ++yy; } attr = oldattr;}/* used by selection: complement pointer position */void complement_pos(int currcons, int offset){ static unsigned short *p = NULL; static unsigned short old = 0; static unsigned short oldx = 0, oldy = 0; unsigned short new, oldattr; oldattr = attr; if (p) { scr_writew(old, p);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -