Exemplo n.º 1
0
/*
 * näppisajuri syöttää vt_keyboard_eventille näppäinkoodin ja tiedon
 * näppäimen suunnasta.
 *
 * vt:n säilömä keyeventti koostuu keycodesta ja 0x100:n kohdalla olevasta
 * bitistä joka ilmaisee onko nappula mennyt ylös vai alas (1=ylös).
 */
void vt_keyboard_event(int code, int up)
{
	if(!initialized) return;
	if(!vt[cur_vt].kb_buf) return; //(näin ei taida kyllä edes voida käydä)

	code &= 0xff;

	//kprintf("\n[event,c=%i,u=%i]", code, up);

	//spinl_lock(&vt[cur_vt].kb_buf_lock);

	switch(code){
		case KEYCODE_PGUP:
			if ((vt[cur_vt].kb_mods & KEYB_MOD_SHIFT)){
				if(!up) vt_scroll(vt_get_display_height()/2);
				return;
			}
		case KEYCODE_PGDOWN:
			if ((vt[cur_vt].kb_mods & KEYB_MOD_SHIFT)){
				//vt_scroll(-1);
				if(!up) vt_scroll(-(int)vt_get_display_height()/2);
				return;
			}
		default:
			if (KEYCODE_F1 <= code && code <= KEYCODE_F6) { // f1-f6
				if(!up) vt_change(code - KEYCODE_F1);
				return;
			}
			else if ((code == KEYCODE_C) && (vt[cur_vt].realtime_kb_mods & KEYB_MOD_CTRL)) {
#if 0
				if(!up){
					extern tid_t sh_tid;
					kill_thread(sh_tid);
					vt_unlockspinlocks();
					sh_tid = new_thread(run_sh, 0, 0, 0);
				}
				return;
#endif
			}
	}

	do_kb_mods(code, up, &vt[cur_vt].realtime_kb_mods);

	//kprintf(" [[[%s]]] ",(vt[cur_vt].kb_mods&(KEYB_MOD_LSHIFT|KEYB_MOD_RSHIFT))?"s":"n");

	vt[cur_vt].kb_buf[vt[cur_vt].kb_buf_end] = code | (up ? 0x100 : 0);
	++vt[cur_vt].kb_buf_count;
	++vt[cur_vt].kb_buf_end;
	vt[cur_vt].kb_buf_end %= VT_KB_BUFFER_SIZE;

	//spinl_unlock(&vt[cur_vt].kb_buf_lock);
}
Exemplo n.º 2
0
static void
vt_scrollmode_kbdevent(struct vt_window *vw, int c, int console)
{
	struct vt_device *vd;
	term_pos_t size;

	vd = vw->vw_device;
	/* Only special keys handled in ScrollLock mode */
	if ((c & SPCLKEY) == 0)
		return;

	c &= ~SPCLKEY;

	if (console == 0) {
		if (c >= F_SCR && c <= MIN(L_SCR, F_SCR + VT_MAXWINDOWS - 1)) {
			vw = vd->vd_windows[c - F_SCR];
			if (vw != NULL)
				vt_proc_window_switch(vw);
			return;
		}
		VT_LOCK(vd);
	}

	switch (c) {
	case SLK: {
		/* Turn scrolling off. */
		vt_scroll(vw, 0, VHS_END);
		VTBUF_SLCK_DISABLE(&vw->vw_buf);
		vw->vw_flags &= ~VWF_SCROLL;
		break;
	}
	case FKEY | F(49): /* Home key. */
		vt_scroll(vw, 0, VHS_SET);
		break;
	case FKEY | F(50): /* Arrow up. */
		vt_scroll(vw, -1, VHS_CUR);
		break;
	case FKEY | F(51): /* Page up. */
		vt_termsize(vd, vw->vw_font, &size);
		vt_scroll(vw, -size.tp_row, VHS_CUR);
		break;
	case FKEY | F(57): /* End key. */
		vt_scroll(vw, 0, VHS_END);
		break;
	case FKEY | F(58): /* Arrow down. */
		vt_scroll(vw, 1, VHS_CUR);
		break;
	case FKEY | F(59): /* Page down. */
		vt_termsize(vd, vw->vw_font, &size);
		vt_scroll(vw, size.tp_row, VHS_CUR);
		break;
	}

	if (console == 0)
		VT_UNLOCK(vd);
}
Exemplo n.º 3
0
static int
vt_processkey(keyboard_t *kbd, struct vt_device *vd, int c)
{
	struct vt_window *vw = vd->vd_curwindow;
	int state = 0;

#if VT_ALT_TO_ESC_HACK
	if (c & RELKEY) {
		switch (c & ~RELKEY) {
		case (SPCLKEY | RALT):
			if (vt_enable_altgr != 0)
				break;
		case (SPCLKEY | LALT):
			vd->vd_kbstate &= ~ALKED;
		}
		/* Other keys ignored for RELKEY event. */
		return (0);
	} else {
		switch (c & ~RELKEY) {
		case (SPCLKEY | RALT):
			if (vt_enable_altgr != 0)
				break;
		case (SPCLKEY | LALT):
			vd->vd_kbstate |= ALKED;
		}
	}
#else
	if (c & RELKEY)
		/* Other keys ignored for RELKEY event. */
		return (0);
#endif

	if (vt_machine_kbdevent(c))
		return (0);

	if (vw->vw_flags & VWF_SCROLL) {
		vt_scrollmode_kbdevent(vw, c, 0/* Not a console */);
		/* Scroll mode keys handled, nothing to do more. */
		return (0);
	}

	if (c & SPCLKEY) {
		c &= ~SPCLKEY;

		if (c >= F_SCR && c <= MIN(L_SCR, F_SCR + VT_MAXWINDOWS - 1)) {
			vw = vd->vd_windows[c - F_SCR];
			if (vw != NULL)
				vt_proc_window_switch(vw);
			return (0);
		}

		switch (c) {
		case SLK: {

			kbdd_ioctl(kbd, KDGKBSTATE, (caddr_t)&state);
			VT_LOCK(vd);
			if (state & SLKED) {
				/* Turn scrolling on. */
				vw->vw_flags |= VWF_SCROLL;
				VTBUF_SLCK_ENABLE(&vw->vw_buf);
			} else {
				/* Turn scrolling off. */
				vw->vw_flags &= ~VWF_SCROLL;
				VTBUF_SLCK_DISABLE(&vw->vw_buf);
				vt_scroll(vw, 0, VHS_END);
			}
			VT_UNLOCK(vd);
			break;
		}
		case FKEY | F(1):  case FKEY | F(2):  case FKEY | F(3):
		case FKEY | F(4):  case FKEY | F(5):  case FKEY | F(6):
		case FKEY | F(7):  case FKEY | F(8):  case FKEY | F(9):
		case FKEY | F(10): case FKEY | F(11): case FKEY | F(12):
			/* F1 through F12 keys. */
			terminal_input_special(vw->vw_terminal,
			    TKEY_F1 + c - (FKEY | F(1)));
			break;
		case FKEY | F(49): /* Home key. */
			terminal_input_special(vw->vw_terminal, TKEY_HOME);
			break;
		case FKEY | F(50): /* Arrow up. */
			terminal_input_special(vw->vw_terminal, TKEY_UP);
			break;
		case FKEY | F(51): /* Page up. */
			terminal_input_special(vw->vw_terminal, TKEY_PAGE_UP);
			break;
		case FKEY | F(53): /* Arrow left. */
			terminal_input_special(vw->vw_terminal, TKEY_LEFT);
			break;
		case FKEY | F(55): /* Arrow right. */
			terminal_input_special(vw->vw_terminal, TKEY_RIGHT);
			break;
		case FKEY | F(57): /* End key. */
			terminal_input_special(vw->vw_terminal, TKEY_END);
			break;
		case FKEY | F(58): /* Arrow down. */
			terminal_input_special(vw->vw_terminal, TKEY_DOWN);
			break;
		case FKEY | F(59): /* Page down. */
			terminal_input_special(vw->vw_terminal, TKEY_PAGE_DOWN);
			break;
		case FKEY | F(60): /* Insert key. */
			terminal_input_special(vw->vw_terminal, TKEY_INSERT);
			break;
		case FKEY | F(61): /* Delete key. */
			terminal_input_special(vw->vw_terminal, TKEY_DELETE);
			break;
		}
	} else if (KEYFLAGS(c) == 0) {
		/* Don't do UTF-8 conversion when doing raw mode. */
		if (vw->vw_kbdmode == K_XLATE) {
#if VT_ALT_TO_ESC_HACK
			if (vd->vd_kbstate & ALKED) {
				/*
				 * Prepend ESC sequence if one of ALT keys down.
				 */
				terminal_input_char(vw->vw_terminal, 0x1b);
			}
#endif

			terminal_input_char(vw->vw_terminal, KEYCHAR(c));
		} else
			terminal_input_raw(vw->vw_terminal, c);
	}
	return (0);
}
Exemplo n.º 4
0
int vt_putch(struct vt_file *f, int c)
{
	struct vt *vtptr;
	if (!initialized) return -1;
	if (!f || !(vtptr = f->vtptr)) return -1;
	if (is_threading()) {
		spinl_lock(&vtptr->writelock);
	}

	if (vtptr->scroll != 0) {
		vtptr->scroll = 0;
		vt_scroll(0);
	}

	if (0) {}
	else if (c >= ' ') { /* printable character */
		vt_scroll_if_needed(f);
		if (vtptr->index == cur_vt) {
			if(driverstream){
				char cc[2];
				cc[0] = c;
				cc[1] = f->color;
				fwrite(cc, 1, 2, driverstream);
			}
			else{
				*(char*)(0xB8000 + vtptr->cy * 160 + vtptr->cx * 2) = c;
				*(char*)(0xB8000 + vtptr->cy * 160 + vtptr->cx * 2 + 1) = 0x7;
			}
		}
		if(vtptr->buffer && initialized) {
			*(vtptr->buffer + vtptr->bufsize - (driverinfo.h*driverinfo.w*2) + vtptr->cy * (driverinfo.w*2) + vtptr->cx * 2) = c;
			*(vtptr->buffer + vtptr->bufsize - (driverinfo.h*driverinfo.w*2) + vtptr->cy * (driverinfo.w*2) + vtptr->cx * 2 + 1) = f->color;
		}
		vtptr->cx++;
	}
	else if (c == '\n') { /* new line */
		vtptr->cx = 0;
		vt_scroll_if_needed(f);
		vtptr->cy++;
		vt_update_cursor();
	}
	else if (c == '\r') { /* return */
		vtptr->cx = 0;
		vt_update_cursor();
	}
	else if (c == '\t') { /* tab */
		vtptr->cx = (vtptr->cx + 8) & ~7;
		vt_update_cursor();
	}
	else if (c == '\b') { /* backspace */
		if (vtptr->cx > 0) {
			vtptr->cx--;
		} else {
			vtptr->cx = (driverinfo.w) - 1;
			vtptr->cy--;
		}
		vt_update_cursor();
	}

	if (driverstream) {
		if (vtptr->cx >= (driverinfo.w)) {
			vtptr->cx = 0;
			vtptr->cy++;
		}
	}
	else {
		if (vtptr->cx >= 80) {
			vtptr->cx = 0;
			vtptr->cy++;
		}
	}

	if (is_threading()) {
		spinl_unlock(&vtptr->writelock);
	}
	do_eop();
	return 0;
}
Exemplo n.º 5
0
/* This is the function we register with the interrupt handler - it reads the
 * scancode and, if appropriate, call's the tty's receive_char function */
static void
keyboard_intr_handler(regs_t *regs)
{
        uint8_t sc; /* The scancode we receive */
        int break_code; /* Was it a break code */
        /* the resulting character ('\0' -> ignored char) */
        uint8_t c = NO_CHAR;
        /* Get the scancode */
        sc = inb(KEYBOARD_IN_PORT);

        /* Separate out the break code */
        break_code = sc & BREAK_MASK;
        sc &= ~BREAK_MASK;

        /* dbg(DBG_KB, ("scancode 0x%x, break 0x%x\n", sc, break_code)); */

        /* The order of this conditional is very, very tricky - be careful when
         * editing! */

        /* Most break codes are ignored */
        if (break_code) {
                /* Shift/ctrl release */
                if (sc == LSHIFT || sc == RSHIFT)
                        curmask &= ~SHIFT_MASK;
                else if (sc == CTRL)
                        curmask &= ~CTRL_MASK;
        }
        /* Check for the special keys */
        else if (sc == LSHIFT || sc == RSHIFT) {
                curmask |= SHIFT_MASK;
        } else if (sc == CTRL) {
                curmask |= CTRL_MASK;
        }
        /* All escaped keys past this point (anything except right shift and right
         * ctrl) will be ignored */
        else if (curmask & ESC_MASK) {
                /* Escape mask only lasts for one key */
                curmask &= ~ESC_MASK;
        }
        /* Now check for escape code */
        else if (sc == ESC0 || sc == ESC1) {
                curmask |= ESC_MASK;
        }
        /* Check for Ctrl+Fn key which indicates virt term switch */
        else if (sc >= VT_KEY_LOW && sc <= VT_KEY_HIGH) {
                vt_switch(sc - VT_KEY_LOW);
        }
        /* Check for Ctrl+Backspace which indicates scroll down */
        else if ((curmask & CTRL_MASK) && sc == SCROLL_DOWN) {
                vt_scroll(DISPLAY_HEIGHT, 0);
        }
        /* Check for Ctrl+Enter which indicates scroll down */
        else if ((curmask & CTRL_MASK) && sc == SCROLL_UP) {
                vt_scroll(DISPLAY_HEIGHT, 1);
        }
        /* Check to make sure the key isn't high enough that it won't be found in
         * tables */
        else if (sc > NORMAL_KEY_HIGH) {
                /* ignore */
        }
        /* Control characters */
        else if (curmask & CTRL_MASK) {
                /* Because of the way ASCII works, the control chars are based on the
                 * values of the shifted chars produced without control */
                c = shift_scancodes[sc];
                /* Range of chars that have corresponding control chars */
                if (c >= 0x40 && c < 0x60)
                        c -= 0x40;
                else
                        c = NO_CHAR;
        }
        /* Capitals */
        else if (curmask & SHIFT_MASK) {
                c = shift_scancodes[sc];
        } else {
                c = normal_scancodes[sc];
        }

        /* Give the key to the vt system, which passes it to the tty */
        if (c != NO_CHAR && keyboard_handler) {
                keyboard_handler(c);
        }
}