📄 sm.c
字号:
tp->t_state |= TS_ONOCTTY; if ((tp->t_state&TS_ISOPEN) == 0) { ttychars(tp); tp->t_state = TS_ISOPEN|TS_CARR_ON; tp->t_cflag = tp->t_cflag_ext = B4800; tp->t_iflag_ext = 0; tp->t_oflag_ext = 0; tp->t_lflag_ext = 0; if( unit == 0 ) { /*---------------------------------------------------- * Ultrix defaults to a "COOKED" mode on the first * open, while termio defaults to a "RAW" style. * Base this decision by a flag set in the termio * emulation routine for open, or set by an explicit * ioctl call. */ if ( flag & O_TERMIO ) { /*-------------------------------------- * Provide a termio style environment. * "RAW" style by default. */ tp->t_flags = RAW; tp->t_iflag = 0; tp->t_oflag = 0; tp->t_cflag |= CS8|CREAD|HUPCL; tp->t_lflag = 0; /*------------------------------------- * Change to System V line discipline.*/ tp->t_line = TERMIODISC; /*----------------------------------------- * The following three control chars have * different default values than ULTRIX. */ tp->t_cc[VERASE] = '#'; tp->t_cc[VKILL] = '@'; tp->t_cc[VINTR] = 0177; tp->t_cc[VMIN] = 6; tp->t_cc[VTIME] = 1; } else { /*-------------------------------------- * Provide a backward compatible ULTRIX * environment. "COOKED" style. */ tp->t_flags = IFLAGS; tp->t_iflag = IFLAG; tp->t_oflag = OFLAG; tp->t_lflag = LFLAG; tp->t_cflag |= CFLAG; } } else { tp->t_flags = RAW; tp->t_iflag = 0; tp->t_oflag = 0; tp->t_cflag |= CS8|CREAD|HUPCL; tp->t_lflag = 0; } if(tp != &sm_tty) ssparam(unit); else tp->t_iflag |= IXOFF; /* flow control for qconsole */ }/* * Process line discipline specific open if its not the mouse. * For the mouse we init the ring ptr's. */ if (unit != 1) return ((*linesw[tp->t_line].l_open)(dev, tp)); else {/* * set up event queue for later */ sm_mouseon = 1; smiaddr->nb_int_msk |= SINT_VF; qp->qe.events = (smEvent *)qp - SMMAXEVQ; qp->qe.eSize = SMMAXEVQ; qp->qe.eHead = qp->qe.eTail = 0; qp->qe.tcs = (smTimeCoord *)qp->qe.events - MOTION_BUFFER_SIZE; qp->qe.tcSize = MOTION_BUFFER_SIZE; qp->qe.tcNext = 0; return(0); }}/****************************************************************** ** ** ** Routine to close the graphic device. ** ** ** ******************************************************************//*ARGSUSED*/smclose(dev, flag) dev_t dev; int flag;{ register struct tty *tp; register int unit = minor(dev); unit = minor(dev); if ((unit == 2) && (major(dev) == CONSOLEMAJOR)) tp = &sm_tty; else tp = &ss_tty[unit];/* * If unit is not the mouse call the line disc. otherwise clear the state * flag, and put the keyboard into down/up. */ if( unit != 1 ){ (*linesw[tp->t_line].l_close)(tp); ttyclose(tp); sm_dev_inuse &= ~CONS_DEV; sm_keyboard.cntrl = sm_keyboard.shift = 0; } else { sm_mouseon = 0; if (open_flag != 1) return(EBUSY); else open_flag = 0; /* mark the graphics device available */ sm_dev_inuse &= ~GRAPHIC_DEV; sm_init(); if (cur_reg & FOPB) { /* user must have turned the screen off */ register struct nb1_regs *smaddr1 = (struct nb1_regs *)qmem; cur_reg |= ENPA; cur_reg &= ~(FOPB); smaddr1->nb_cur_cmd = cur_reg; } } tp->t_state = 0; /* Remove termio flags that do not map */ tp->t_iflag &= ~TERMIO_ONLY_IFLAG; tp->t_oflag &= ~TERMIO_ONLY_OFLAG; tp->t_cflag &= ~TERMIO_ONLY_CFLAG; tp->t_lflag &= ~TERMIO_ONLY_LFLAG;}/****************************************************************** ** ** ** Mouse activity select routine. ** ** ** ******************************************************************/smselect(dev, rw)dev_t dev;{ register int s = spl5(); register int unit = minor(dev); register struct sm_info *qp = sm_scn; register struct tty *tp; switch(rw) { case FREAD: /* if events okay */ if( unit == 1 ) { if (qp->qe.eHead != qp->qe.eTail) { splx(s); return(1); } rsel = u.u_procp; splx(s); return(0); } else { tp = &sm_tty; if (ttnread(tp)) return(1); tp->t_rsel = u.u_procp; splx(s); return(0); } case FWRITE: /* can never write */ if( unit == 1 ) { splx(s); return(EACCES); } else { tp = &sm_tty; if (tp->t_outq.c_cc <= TTLOWAT(tp)) return(1); tp->t_wsel = u.u_procp; splx(s); return(0); } }}#define CHAR_S 0xc7#define CHAR_Q 0xc1/****************************************************************** ** ** ** Graphice device interrupt routine. ** ** ** ******************************************************************/smkint(ch)register int ch;{ register smEvent *qep; register struct sm_info *qp = sm_scn; struct mouse_report *new_rep; struct tty *tp; register int unit; register u_short c; register int i, j; u_short data; int cnt;/* * Mouse state info */ static char temp, old_switch, new_switch; unit = (ch>>8)&03; new_rep = ¤t_rep; tp = &ss_tty[unit];/* * If graphic device is turned on */ if (sm_mouseon == 1) { cnt = 0; while (cnt++ == 0) {/* * Pick up LK-201 input (if any) */ if (unit == 0) {/* * Get a character. */ data = ch & 0xff;/* * Check for various keyboard errors */ if( data == LK_POWER_ERROR || data == LK_KDOWN_ERROR || data == LK_INPUT_ERROR || data == LK_OUTPUT_ERROR) { mprintf("\nsm0: smkint: keyboard error, code = %x",data); return(0); } if (data < LK_LOWEST) return(0); if ((i = EVROUND(qp->qe.eTail+1)) == qp->qe.eHead) return(0); /* for any key */ qep = &qp->qe.events[qp->qe.eTail]; qep->type = BUTTON_RAW_TYPE; qep->device = KEYBOARD_DEVICE; qep->x = qp->mouse.x; qep->y = qp->mouse.y; qep->time = TOY; qep->key = data; qp->qe.eTail = i; if((i=EVROUND(qp->qe.eTail+1)) == qp->qe.eHead) return(0); qep = &qp->qe.events[qp->qe.eTail]; if (data == CNTRL) sm_keyboard.cntrl = 1; }/* * Pick up the mouse input (if any) */ if ((unit == 1) && (sm_pointer_id == MOUSE_ID)) {/* * see if mouse position has changed */ if( new_rep->dx != 0 || new_rep->dy != 0) { unsigned int millis = TOY;/* * Check to see if we have to accelerate the mouse * */ if (qp->mscale >=0) { if (new_rep->dx >= qp->mthreshold) new_rep->dx += (new_rep->dx - qp->mthreshold)*qp->mscale; if (new_rep->dy >= qp->mthreshold) new_rep->dy += (new_rep->dy - qp->mthreshold)*qp->mscale; }/* * update mouse position */ if( new_rep->state & X_SIGN) { qp->mouse.x += new_rep->dx; if( qp->mouse.x > qp->max_cur_x ) qp->mouse.x = qp->max_cur_x; } else { qp->mouse.x -= new_rep->dx; if( qp->mouse.x < qp->min_cur_x ) qp->mouse.x = qp->min_cur_x; } if( new_rep->state & Y_SIGN) { qp->mouse.y -= new_rep->dy; if( qp->mouse.y < qp->min_cur_y ) qp->mouse.y = qp->min_cur_y; } else { qp->mouse.y += new_rep->dy; if( qp->mouse.y > qp->max_cur_y ) qp->mouse.y = qp->max_cur_y; } if( tp->t_state & TS_ISOPEN ) sm_pos_cur( qp->mouse.x, qp->mouse.y ); qp->qe.tcs[qp->qe.tcNext].time = millis; qp->qe.tcs[qp->qe.tcNext].x = qp->mouse.x; qp->qe.tcs[qp->qe.tcNext].y = qp->mouse.y; if (++(qp->qe.tcNext) >= MOTION_BUFFER_SIZE) qp->qe.tcNext = 0; if (qp->mouse.y < qp->mbox.bottom && qp->mouse.y >= qp->mbox.top && qp->mouse.x < qp->mbox.right && qp->mouse.x >= qp->mbox.left) goto mbuttons; qp->mbox.bottom = 0; /* trash box */ if (EVROUND(qp->qe.eTail+1) == qp->qe.eHead) goto mbuttons; i = EVROUND(qp->qe.eTail -1); if ((qp->qe.eTail != qp->qe.eHead) && (i != qp->qe.eHead)) { qep = & qp->qe.events[i]; if(qep->type == MOTION_TYPE) { qep->x = qp->mouse.x; qep->y = qp->mouse.y; qep->time = millis; qep->device = MOUSE_DEVICE; goto mbuttons; } }/* * Put event into queue and do select */ qep = &qp->qe.events[qp->qe.eTail]; qep->type = MOTION_TYPE; qep->time = millis; qep->x = qp->mouse.x; qep->y = qp->mouse.y; qep->device = MOUSE_DEVICE; qp->qe.eTail = EVROUND(qp->qe.eTail+1); }/* * See if mouse buttons have changed. */mbuttons: new_switch = new_rep->state & 0x07; old_switch = last_rep.state & 0x07; temp = old_switch ^ new_switch; if( temp ) { for (j = 1; j < 8; j <<= 1) {/* check each button */ if (!(j & temp)) /* did this button change? */ continue;/* * Check for room in the queue */ if ((i = EVROUND(qp->qe.eTail+1)) == qp->qe.eHead) return(0);/* put event into queue and do select */ qep = &qp->qe.events[qp->qe.eTail]; switch (j) { case RIGHT_BUTTON: qep->key = EVENT_RIGHT_BUTTON; break; case MIDDLE_BUTTON: qep->key = EVENT_MIDDLE_BUTTON; break; case LEFT_BUTTON: qep->key = EVENT_LEFT_BUTTON; break; } if (new_switch & j) qep->type = BUTTON_DOWN_TYPE; else qep->type = BUTTON_UP_TYPE; qep->device = MOUSE_DEVICE; qep->time = TOY; qep->x = qp->mouse.x; qep->y = qp->mouse.y; } qp->qe.eTail = i;/* update the last report */ last_rep = current_rep; qp->mswitches = new_switch; } } /* Pick up mouse input */ else if ((unit == 1) && (sm_pointer_id == TABLET_ID)) {/* update cursor position coordinates */ new_rep->dx /= TABLET_RES; new_rep->dy = (2200 - new_rep->dy) / TABLET_RES; if( new_rep->dx > qp->max_cur_x ) new_rep->dx = qp->max_cur_x; if( new_rep->dy > qp->max_cur_y ) new_rep->dy = qp->max_cur_y;/* * see if the puck/stylus has moved */ if( qp->mouse.x != new_rep->dx || qp->mouse.y != new_rep->dy) {/* * update cursor position */ qp->mouse.x = new_rep->dx; qp->mouse.y = new_rep->dy; if( tp->t_state & TS_ISOPEN ) sm_pos_cur( qp->mouse.x, qp->mouse.y ); if (qp->mouse.y < qp->mbox.bottom && qp->mouse.y >= qp->mbox.top && qp->mouse.x < qp->mbox.right && qp->mouse.x >= qp->mbox.left) goto tbuttons; qp->mbox.bottom = 0; /* trash box */ if (EVROUND(qp->qe.eTail+1) == qp->qe.eHead) goto tbuttons;/* * Put event into queue and do select */ qep = &qp->qe.events[qp->qe.eTail]; qep->type = MOTION_TYPE; qep->device = TABLET_DEVICE; qep->x = qp->mouse.x; qep->y = qp->mouse.y; qep->key = 0; qep->time = TOY; qep = & qp->qe.events[qp->qe.eTail]; }/* * See if tablet buttons have changed. */tbuttons: new_switch = new_rep->state & 0x1e; old_switch = last_rep.state & 0x1e; temp = old_switch ^ new_switch; if( temp ) { if((i=EVROUND(qp->qe.eTail+1)) == qp->qe.eHead) return(0);/* put event into queue and do select */ qep = &qp->qe.events[qp->qe.eTail]; qep->device = TABLET_DEVICE; qep->x = qp->mouse.x; qep->y = qp->mouse.y; qep->time = TOY;/* define the changed button and if up or down */ for (j = 1; j <= 0x10; j <<= 1) {/* check each button */ if (!(j & temp)) /* did this button change? */ continue; switch (j) { case T_RIGHT_BUTTON: qep->key = EVENT_T_RIGHT_BUTTON; break; case T_FRONT_BUTTON: qep->key = EVENT_T_FRONT_BUTTON; break; case T_BACK_BUTTON: qep->key = EVENT_T_BACK_BUTTON; break; case T_LEFT_BUTTON: qep->key = EVENT_T_LEFT_BUTTON; break; } if (new_switch & j) qep->type = BUTTON_DOWN_TYPE; else qep->type = BUTTON_UP_TYPE; } qp->qe.eTail = i;/* update the last report */ last_rep = current_rep; } } /* Pick up tablet input */ } /* While input available *//* * If we have proc waiting, and event has happened, wake him up */ if(rsel && (qp->qe.eHead != qp->qe.eTail)) { selwakeup(rsel,0); rsel = 0; } }/* * If the graphic device is not turned on, this is console input */ else {/* * Get a character from the keyboard. */ if (ch & 0100000) { data = ch & 0xff;/* * Check for various keyboard errors */ if( data == LK_POWER_ERROR || data == LK_KDOWN_ERROR || data == LK_INPUT_ERROR || data == LK_OUTPUT_ERROR) { mprintf("sm0: Keyboard error, code = %x\n",data); return(0); } if( data < LK_LOWEST ) return(0);/* * See if its a state change key */ switch ( data ) { case LOCK: sm_keyboard.lock ^= 0xffff; /* toggle */ if( sm_keyboard.lock ) sm_key_out( LK_LED_ENABLE ); else sm_key_out( LK_LED_DISABLE ); sm_key_out( LED_3 ); return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -