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

📄 console.c

📁 powerpc内核mpc8241linux系统下char驱动程序
💻 C
📖 第 1 页 / 共 5 页
字号:
					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++;	}	con_schedule_flip(tty);}static void cursor_report(int currcons, struct tty_struct * tty){	char buf[40];	sprintf(buf, "\033[%d;%dR", 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) and through set_selection */int mouse_reporting(void){	int currcons = fg_console;	return report_mouse;}static void set_mode(int currcons, int on_off){	int i;	for (i=0; i<=npar; i++)		if (ques) switch(par[i]) {	/* DEC private modes set/reset */			case 1:			/* Cursor keys send ^[Ox/^[[x */				if (on_off)					set_kbd(decckm);				else					clr_kbd(decckm);				break;			case 3:	/* 80/132 mode switch unimplemented */				deccolm = on_off;#if 0				(void) vc_resize(video_num_lines, deccolm ? 132 : 80);				/* this alone does not suffice; some user mode				   utility has to change the hardware regs */#endif				break;			case 5:			/* Inverted screen on/off */				if (decscnm != on_off) {					decscnm = on_off;					invert_screen(currcons, 0, screenbuf_size, 0);					update_attr(currcons);				}				break;			case 6:			/* Origin relative/absolute */				decom = on_off;				gotoxay(currcons,0,0);				break;			case 7:			/* Autowrap on/off */				decawm = on_off;				break;			case 8:			/* Autorepeat on/off */				if (on_off)					set_kbd(decarm);				else					clr_kbd(decarm);				break;			case 9:				report_mouse = on_off ? 1 : 0;				break;			case 25:		/* Cursor on/off */				deccm = on_off;				break;			case 1000:				report_mouse = on_off ? 2 : 0;				break;		} else switch(par[i]) {		/* ANSI modes set/reset */			case 3:			/* Monitor (display ctrls) */				disp_ctrl = on_off;				break;			case 4:			/* Insert Mode on/off */				decim = on_off;				break;			case 20:		/* Lf, Enter == CrLf/Lf */				if (on_off)					set_kbd(lnm);				else					clr_kbd(lnm);				break;		}}static void setterm_command(int currcons){	switch(par[0]) {		case 1:	/* set color for underline mode */			if (can_do_color && par[1] < 16) {				ulcolor = color_table[par[1]];				if (underline)					update_attr(currcons);			}			break;		case 2:	/* set color for half intensity mode */			if (can_do_color && par[1] < 16) {				halfcolor = color_table[par[1]];				if (intensity == 0)					update_attr(currcons);			}			break;		case 8:	/* store colors as defaults */			def_color = attr;			if (hi_font_mask == 0x100)				def_color >>= 1;			default_attr(currcons);			update_attr(currcons);			break;		case 9:	/* set blanking interval */			blankinterval = ((par[1] < 60) ? par[1] : 60) * 60 * HZ;			poke_blanked_console();			break;		case 10: /* set bell frequency in Hz */			if (npar >= 1)				bell_pitch = par[1];			else				bell_pitch = DEFAULT_BELL_PITCH;			break;		case 11: /* set bell duration in msec */			if (npar >= 1)				bell_duration = (par[1] < 2000) ?					par[1]*HZ/1000 : 0;			else				bell_duration = DEFAULT_BELL_DURATION;			break;		case 12: /* bring specified console to the front */			if (par[1] >= 1 && vc_cons_allocated(par[1]-1))				set_console(par[1] - 1);			break;		case 13: /* unblank the screen */			poke_blanked_console();			break;		case 14: /* set vesa powerdown interval */			vesa_off_interval = ((par[1] < 60) ? par[1] : 60) * 60 * HZ;			break;	}}static void insert_line(int currcons, unsigned int nr){	scrdown(currcons,y,bottom,nr);	need_wrap = 0;}static void delete_line(int currcons, unsigned int nr){	scrup(currcons,y,bottom,nr);	need_wrap = 0;}static void csi_at(int currcons, unsigned int nr){	if (nr > video_num_columns - x)		nr = video_num_columns - x;	else if (!nr)		nr = 1;	insert_char(currcons, nr);}static void csi_L(int currcons, unsigned int nr){	if (nr > video_num_lines - y)		nr = video_num_lines - y;	else if (!nr)		nr = 1;	insert_line(currcons, nr);}static void csi_P(int currcons, unsigned int nr){	if (nr > video_num_columns - x)		nr = video_num_columns - x;	else if (!nr)		nr = 1;	delete_char(currcons, nr);}static void csi_M(int currcons, unsigned int nr){	if (nr > video_num_lines - y)		nr = video_num_lines - y;	else if (!nr)		nr=1;	delete_line(currcons, nr);}static void save_cur(int currcons){	saved_x		= x;	saved_y		= y;	s_intensity	= intensity;	s_underline	= underline;	s_blink		= blink;	s_reverse	= reverse;	s_charset	= charset;	s_color		= color;	saved_G0	= G0_charset;	saved_G1	= G1_charset;}static void restore_cur(int currcons){	gotoxy(currcons,saved_x,saved_y);	intensity	= s_intensity;	underline	= s_underline;	blink		= s_blink;	reverse		= s_reverse;	charset		= s_charset;	color		= s_color;	G0_charset	= saved_G0;	G1_charset	= saved_G1;	translate	= set_translate(charset ? G1_charset : G0_charset,currcons);	update_attr(currcons);	need_wrap = 0;}enum { ESnormal, ESesc, ESsquare, ESgetpars, ESgotpars, ESfunckey,	EShash, ESsetG0, ESsetG1, ESpercent, ESignore, ESnonstd,	ESpalette };static void reset_terminal(int currcons, int do_clear){	top		= 0;	bottom		= video_num_lines;	vc_state	= ESnormal;	ques		= 0;	translate	= set_translate(LAT1_MAP,currcons);	G0_charset	= LAT1_MAP;	G1_charset	= GRAF_MAP;	charset		= 0;	need_wrap	= 0;	report_mouse	= 0;	utf             = 0;	utf_count       = 0;	disp_ctrl	= 0;	toggle_meta	= 0;	decscnm		= 0;	decom		= 0;	decawm		= 1;	deccm		= 1;	decim		= 0;	set_kbd(decarm);	clr_kbd(decckm);	clr_kbd(kbdapplic);	clr_kbd(lnm);	kbd_table[currcons].lockstate = 0;	kbd_table[currcons].slockstate = 0;	kbd_table[currcons].ledmode = LED_SHOW_FLAGS;	kbd_table[currcons].ledflagstate = kbd_table[currcons].default_ledflagstate;	set_leds();	cursor_type = CUR_DEFAULT;	complement_mask = s_complement_mask;	default_attr(currcons);	update_attr(currcons);	tab_stop[0]	= 0x01010100;	tab_stop[1]	=	tab_stop[2]	=	tab_stop[3]	=	tab_stop[4]	= 0x01010101;	bell_pitch = DEFAULT_BELL_PITCH;	bell_duration = DEFAULT_BELL_DURATION;	gotoxy(currcons,0,0);	save_cur(currcons);	if (do_clear)	    csi_J(currcons,2);}static void do_con_trol(struct tty_struct *tty, unsigned int currcons, int c){	/*	 *  Control characters can be used in the _middle_	 *  of an escape sequence.	 */	switch (c) {	case 0:		return;	case 7:		if (bell_duration)			kd_mksound(bell_pitch, bell_duration);		return;	case 8:		bs(currcons);		return;	case 9:		pos -= (x << 1);		while (x < video_num_columns - 1) {			x++;			if (tab_stop[x >> 5] & (1 << (x & 31)))				break;		}		pos += (x << 1);		return;	case 10: case 11: case 12:		lf(currcons);		if (!is_kbd(lnm))			return;	case 13:		cr(currcons);		return;	case 14:		charset = 1;		translate = set_translate(G1_charset,currcons);		disp_ctrl = 1;		return;	case 15:		charset = 0;		translate = set_translate(G0_charset,currcons);		disp_ctrl = 0;		return;	case 24: case 26:		vc_state = ESnormal;		return;	case 27:		vc_state = ESesc;		return;	case 127:		del(currcons);		return;	case 128+27:		vc_state = ESsquare;		return;	}	switch(vc_state) {	case ESesc:		vc_state = ESnormal;		switch (c) {		case '[':			vc_state = ESsquare;			return;		case ']':			vc_state = ESnonstd;			return;		case '%':			vc_state = ESpercent;			return;		case 'E':			cr(currcons);			lf(currcons);			return;		case 'M':			ri(currcons);			return;		case 'D':			lf(currcons);			return;		case 'H':			tab_stop[x >> 5] |= (1 << (x & 31));			return;		case 'Z':			respond_ID(tty);			return;		case '7':			save_cur(currcons);			return;		case '8':			restore_cur(currcons);			return;		case '(':			vc_state = ESsetG0;			return;		case ')':			vc_state = ESsetG1;			return;		case '#':			vc_state = EShash;			return;		case 'c':			reset_terminal(currcons,1);			return;		case '>':  /* Numeric keypad */			clr_kbd(kbdapplic);			return;		case '=':  /* Appl. keypad */			set_kbd(kbdapplic);			return;		}		return;	case ESnonstd:		if (c=='P') {   /* palette escape sequence */			for (npar=0; npar<NPAR; npar++)				par[npar] = 0 ;			npar = 0 ;			vc_state = ESpalette;			return;		} else if (c=='R') {   /* reset palette */			reset_palette(currcons);			vc_state = ESnormal;		} else			vc_state = ESnormal;		return;	case ESpalette:		if ( (c>='0'&&c<='9') || (c>='A'&&c<='F') || (c>='a'&&c<='f') ) {			par[npar++] = (c>'9' ? (c&0xDF)-'A'+10 : c-'0') ;			if (npar==7) {				int i = par[0]*3, j = 1;				palette[i] = 16*par[j++];				palette[i++] += par[j++];				palette[i] = 16*par[j++];				palette[i++] += par[j++];				palette[i] = 16*par[j++];				palette[i] += par[j];				set_palette(currcons);				vc_state = ESnormal;			}		} else			vc_state = ESnormal;		return;	case ESsquare:		for(npar = 0 ; npar < NPAR ; npar++)			par[npar] = 0;		npar = 0;		vc_state = ESgetpars;		if (c == '[') { /* Function key */			vc_state=ESfunckey;			return;		}		ques = (c=='?');		if (ques)			return;	case ESgetpars:		if (c==';' && npar<NPAR-1) {			npar++;			return;		} else if (c>='0' && c<='9') {			par[npar] *= 10;			par[npar] += c-'0';			return;		} else vc_state=ESgotpars;	case ESgotpars:		vc_state = ESnormal;		switch(c) {		case 'h':			set_mode(currcons,1);			return;		case 'l':			set_mode(currcons,0);			return;		case 'c':			if (ques) {				if (par[0])					cursor_type = par[0] | (par[1]<<8) | (par[2]<<16);				else					cursor_type = CUR_DEFAULT;				return;			}			break;		case 'm':			if (ques) {				clear_selection();				if (par[0])					complement_mask = par[0]<<8 | par[1];				else					complement_mask = s_complement_mask;				return;			}			break;		case 'n':			if (!ques) {				if (par[0] == 5)					status_report(tty);				else if (par[0] == 6)					cursor_report(currcons,tty);			}			return;		}		if (ques) {			ques = 0;			return;		}		switch(c) {		case 'G': case '`':			if (par[0]) par[0]--;			gotoxy(currcons,par[0],y);			return;		case 'A':			if (!par[0]) par[0]++;			gotoxy(currcons,x,y-par[0]);			return;		case 'B': case 'e':			if (!par[0]) par[0]++;			gotoxy(currcons,x,y+par[0]);			return;		case 'C': case 'a':			if (!par[0]) par[0]++;			gotoxy(currcons,x+par[0],y);			return;		case 'D':			if (!par[0]) par[0]++;			gotoxy(currcons,x-par[0],y);			return;		case 'E':			if (!par[0]) par[0]++;			gotoxy(currcons,0,y+par[0]);			return;		case 'F':			if (!par[0]) par[0]++;			gotoxy(currcons,0,y-par[0]);			return;		case 'd':			if (par[0]) par[0]--;			gotoxay(currcons,x,par[0]);			return;		case 'H': case 'f':			if (par[0]) par[0]--;			if (par[1]) par[1]--;			gotoxay(currcons,par[1],par[0]);			return;		case 'J':

⌨️ 快捷键说明

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