⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 console.h

📁 一个简单的操作系统minix的核心代码
💻 H
📖 第 1 页 / 共 3 页
字号:
13915	                vid_vid_copy(cons->c_start + scr_width, cons->c_start, chars);
13916	        } else
13917	        if (!wrap && cons->c_org + scr_size + scr_width >= cons->c_limit) {
13918	                vid_vid_copy(cons->c_org + scr_width, cons->c_start, chars);
13919	                cons->c_org = cons->c_start;
13920	        } else {
13921	                cons->c_org = (cons->c_org + scr_width) & vid_mask;
13922	        }
13923	        new_line = (cons->c_org + chars) & vid_mask;
13924	  } else {
13925	        /* Scroll one line down in 3 ways: soft, avoid wrap, use origin. */
13926	        if (softscroll) {
13927	                vid_vid_copy(cons->c_start, cons->c_start + scr_width, chars);
13928	        } else
13929	        if (!wrap && cons->c_org < cons->c_start + scr_width) {
13930	                new_org = cons->c_limit - scr_size;
13931	                vid_vid_copy(cons->c_org, new_org + scr_width, chars);
13932	                cons->c_org = new_org;
13933	        } else {
13934	                cons->c_org = (cons->c_org - scr_width) & vid_mask;
13935	        }
13936	        new_line = cons->c_org;
13937	  }
13938	  /* Blank the new line at top or bottom. */
13939	  blank_color = cons->c_blank;
13940	  mem_vid_copy(BLANK_MEM, new_line, scr_width);
13941	
13942	  /* Set the new video origin. */
13943	  if (cons == curcons) set_6845(VID_ORG, cons->c_org);
13944	  flush(cons);
13945	}
	
	
13948	/*===========================================================================*
13949	 *                              flush                                        *
13950	 *===========================================================================*/
13951	PRIVATE void flush(cons)
13952	register console_t *cons;       /* pointer to console struct */
13953	{
13954	/* Send characters buffered in 'ramqueue' to screen memory, check the new
13955	 * cursor position, compute the new hardware cursor position and set it.
13956	 */
13957	  unsigned cur;
13958	  tty_t *tp = cons->c_tty;
13959	
13960	  /* Have the characters in 'ramqueue' transferred to the screen. */
13961	  if (cons->c_rwords > 0) {
13962	        mem_vid_copy(cons->c_ramqueue, cons->c_cur, cons->c_rwords);
13963	        cons->c_rwords = 0;
13964	
13965	        /* TTY likes to know the current column and if echoing messed up. */
13966	        tp->tty_position = cons->c_column;
13967	        tp->tty_reprint = TRUE;
13968	  }
13969	
13970	  /* Check and update the cursor position. */
13971	  if (cons->c_column < 0) cons->c_column = 0;
13972	  if (cons->c_column > scr_width) cons->c_column = scr_width;
13973	  if (cons->c_row < 0) cons->c_row = 0;
13974	  if (cons->c_row >= scr_lines) cons->c_row = scr_lines - 1;
13975	  cur = cons->c_org + cons->c_row * scr_width + cons->c_column;
13976	  if (cur != cons->c_cur) {
13977	        if (cons == curcons) set_6845(CURSOR, cur);
13978	        cons->c_cur = cur;
13979	  }
13980	}
	
	
13983	/*===========================================================================*
13984	 *                              parse_escape                                 *
13985	 *===========================================================================*/
13986	PRIVATE void parse_escape(cons, c)
13987	register console_t *cons;       /* pointer to console struct */
13988	char c;                         /* next character in escape sequence */
13989	{
13990	/* The following ANSI escape sequences are currently supported.
13991	 * If n and/or m are omitted, they default to 1. Omitted s defaults to 0.
13992	 *   ESC [nA moves up n lines
13993	 *   ESC [nB moves down n lines
13994	 *   ESC [nC moves right n spaces
13995	 *   ESC [nD moves left n spaces
13996	 *   ESC [m;nH moves cursor to (m,n)
13997	 *   ESC [sJ clears screen relative to cursor (0 to end, 1 from start, 2 all)
13998	 *   ESC [sK clears line relative to cursor (0 to end, 1 from start, 2 all)
13999	 *   ESC [nL inserts n lines at cursor
14000	 *   ESC [nM deletes n lines at cursor
14001	 *   ESC [nP deletes n chars at cursor
14002	 *   ESC [n@ inserts n chars at cursor
14003	 *   ESC [nm enables rendition n (0= normal, 1=bold, 4=underline, 5=blinking,
14004	 *       7=reverse, 30..37 set foreground color, 40..47 set background color)
14005	 *   ESC M scrolls the screen backwards if the cursor is on the top line
14006	 */
14007	
14008	  switch (cons->c_esc_state) {
14009	    case 1:                     /* ESC seen */
14010	        cons->c_esc_intro = '\0';
14011	        cons->c_esc_parmp = cons->c_esc_parmv;
14012	        cons->c_esc_parmv[0] = cons->c_esc_parmv[1] = 0;
14013	        switch (c) {
14014	            case '[':   /* Control Sequence Introducer */
14015	                cons->c_esc_intro = c;
14016	                cons->c_esc_state = 2;
14017	                break;
14018	            case 'M':   /* Reverse Index */
14019	                do_escape(cons, c);
14020	                break;
14021	            default:
14022	                cons->c_esc_state = 0;
14023	        }
14024	        break;
14025	
14026	    case 2:                     /* ESC [ seen */
14027	        if (c >= '0' && c <= '9') {
14028	                if (cons->c_esc_parmp < bufend(cons->c_esc_parmv))
14029	                        *cons->c_esc_parmp = *cons->c_esc_parmp * 10 + (c-'0');
14030	        } else
14031	        if (c == ';') {
14032	                if (++cons->c_esc_parmp < bufend(cons->c_esc_parmv))
14033	                        *cons->c_esc_parmp = 0;
14034	        } else {
14035	                do_escape(cons, c);
14036	        }
14037	        break;
14038	  }
14039	}
	
	
14042	/*===========================================================================*
14043	 *                              do_escape                                    *
14044	 *===========================================================================*/
14045	PRIVATE void do_escape(cons, c)
14046	register console_t *cons;       /* pointer to console struct */
14047	char c;                         /* next character in escape sequence */
14048	{
14049	  int value, n;
14050	  unsigned src, dst, count;
14051	
14052	  /* Some of these things hack on screen RAM, so it had better be up to date */
14053	  flush(cons);
14054	
14055	  if (cons->c_esc_intro == '\0') {
14056	        /* Handle a sequence beginning with just ESC */
14057	        switch (c) {
14058	            case 'M':           /* Reverse Index */
14059	                if (cons->c_row == 0) {
14060	                        scroll_screen(cons, SCROLL_DOWN);
14061	                } else {
14062	                        cons->c_row--;
14063	                }
14064	                flush(cons);
14065	                break;
14066	
14067	            default: break;
14068	        }
14069	  } else
14070	  if (cons->c_esc_intro == '[') {
14071	        /* Handle a sequence beginning with ESC [ and parameters */
14072	        value = cons->c_esc_parmv[0];
14073	        switch (c) {
14074	            case 'A':           /* ESC [nA moves up n lines */
14075	                n = (value == 0 ? 1 : value);
14076	                cons->c_row -= n;
14077	                flush(cons);
14078	                break;
14079	
14080	            case 'B':           /* ESC [nB moves down n lines */
14081	                n = (value == 0 ? 1 : value);
14082	                cons->c_row += n;
14083	                flush(cons);
14084	                break;
14085	
14086	            case 'C':           /* ESC [nC moves right n spaces */
14087	                n = (value == 0 ? 1 : value);
14088	                cons->c_column += n;
14089	                flush(cons);
14090	                break;
14091	
14092	            case 'D':           /* ESC [nD moves left n spaces */
14093	                n = (value == 0 ? 1 : value);
14094	                cons->c_column -= n;
14095	                flush(cons);
14096	                break;
14097	
14098	            case 'H':           /* ESC [m;nH" moves cursor to (m,n) */
14099	                cons->c_row = cons->c_esc_parmv[0] - 1;
14100	                cons->c_column = cons->c_esc_parmv[1] - 1;
14101	                flush(cons);
14102	                break;
14103	
14104	            case 'J':           /* ESC [sJ clears in display */
14105	                switch (value) {
14106	                    case 0:     /* Clear from cursor to end of screen */
14107	                        count = scr_size - (cons->c_cur - cons->c_org);
14108	                        dst = cons->c_cur;
14109	                        break;
14110	                    case 1:     /* Clear from start of screen to cursor */
14111	                        count = cons->c_cur - cons->c_org;
14112	                        dst = cons->c_org;
14113	                        break;
14114	                    case 2:     /* Clear entire screen */
14115	                        count = scr_size;
14116	                        dst = cons->c_org;
14117	                        break;
14118	                    default:    /* Do nothing */
14119	                        count = 0;
14120	                        dst = cons->c_org;
14121	                }
14122	                blank_color = cons->c_blank;
14123	                mem_vid_copy(BLANK_MEM, dst, count);
14124	                break;
14125	
14126	            case 'K':           /* ESC [sK clears line from cursor */
14127	                switch (value) {
14128	                    case 0:     /* Clear from cursor to end of line */
14129	                        count = scr_width - cons->c_column;
14130	                        dst = cons->c_cur;
14131	                        break;
14132	                    case 1:     /* Clear from beginning of line to cursor */
14133	                        count = cons->c_column;
14134	                        dst = cons->c_cur - cons->c_column;
14135	                        break;
14136	                    case 2:     /* Clear entire line */
14137	                        count = scr_width;
14138	                        dst = cons->c_cur - cons->c_column;
14139	                        break;
14140	                    default:    /* Do nothing */
14141	                        count = 0;
14142	                        dst = cons->c_cur;
14143	                }
14144	                blank_color = cons->c_blank;
14145	                mem_vid_copy(BLANK_MEM, dst, count);
14146	                break;
14147	
14148	            case 'L':           /* ESC [nL inserts n lines at cursor */
14149	                n = value;
14150	                if (n < 1) n = 1;
14151	                if (n > (scr_lines - cons->c_row))
14152	                        n = scr_lines - cons->c_row;
14153	
14154	                src = cons->c_org + cons->c_row * scr_width;
14155	                dst = src + n * scr_width;
14156	                count = (scr_lines - cons->c_row - n) * scr_width;
14157	                vid_vid_copy(src, dst, count);
14158	                blank_color = cons->c_blank;
14159	                mem_vid_copy(BLANK_MEM, src, n * scr_width);
14160	                break;
14161	
14162	            case 'M':           /* ESC [nM deletes n lines at cursor */
14163	                n = value;
14164	                if (n < 1) n = 1;
14165	                if (n > (scr_lines - cons->c_row))
14166	                        n = scr_lines - cons->c_row;
14167	
14168	                dst = cons->c_org + cons->c_row * scr_width;
14169	                src = dst + n * scr_width;
14170	                count = (scr_lines - cons->c_row - n) * scr_width;
14171	                vid_vid_copy(src, dst, count);
14172	                blank_color = cons->c_blank;
14173	                mem_vid_copy(BLANK_MEM, dst + count, n * scr_width);
14174	                break;
14175	
14176	            case '@':           /* ESC [n@ inserts n chars at cursor */
14177	                n = value;
14178	                if (n < 1) n = 1;
14179	                if (n > (scr_width - cons->c_column))
14180	                        n = scr_width - cons->c_column;
14181	
14182	                src = cons->c_cur;
14183	                dst = src + n;
14184	                count = scr_width - cons->c_column - n;
14185	                vid_vid_copy(src, dst, count);
14186	                blank_color = cons->c_blank;
14187	                mem_vid_copy(BLANK_MEM, src, n);
14188	                break;
14189	
14190	            case 'P':           /* ESC [nP deletes n chars at cursor */
14191	                n = value;
14192	                if (n < 1) n = 1;
14193	                if (n > (scr_width - cons->c_column))
14194	                        n = scr_width - cons->c_column;
14195	
14196	                dst = cons->c_cur;
14197	                src = dst + n;
14198	                count = scr_width - cons->c_column - n;
14199	                vid_vid_copy(src, dst, count);
14200	                blank_color = cons->c_blank;
14201	                mem_vid_copy(BLANK_MEM, dst + count, n);
14202	                break;
14203	
14204	            case 'm':           /* ESC [nm enables rendition n */
14205	                switch (value) {
14206	                    case 1:     /* BOLD  */
14207	                        if (color) {
14208	                                /* Can't do bold, so use yellow */
14209	                                cons->c_attr = (cons->c_attr & 0xf0ff) | 0x0E00;
14210	                        } else {
14211	                                /* Set intensity bit */
14212	                                cons->c_attr |= 0x0800;
14213	                        }
14214	                        break;
14215	
14216	                    case 4:     /* UNDERLINE */
14217	                        if (color) {
14218	                                /* Use light green */
14219	                                cons->c_attr = (cons->c_attr & 0xf0ff) | 0x0A00;
14220	                        } else {
14221	                                cons->c_attr = (cons->c_attr & 0x8900);
14222	                        }
14223	                        break;
14224	
14225	                    case 5:     /* BLINKING */
14226	                        if (color) {
14227	                                /* Use magenta */
14228	                                cons->c_attr = (cons->c_attr & 0xf0ff) | 0x0500;
14229	                        } else {
14230	                                /* Set the blink bit */
14231	                                cons->c_attr |= 0x8000;
14232	                        }
14233	                        break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -