strategy returns void, ioctl cmd is u_long
[unix-history] / usr / src / sys / hp / dev / ite.c
index 5f47f81..e0dfc68 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright (c) 1988 University of Utah.
 /*
  * Copyright (c) 1988 University of Utah.
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1990, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * the Systems Programming Group of the University of Utah Computer
  *
  * This code is derived from software contributed to Berkeley by
  * the Systems Programming Group of the University of Utah Computer
@@ -9,9 +9,9 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- * from: Utah $Hdr: ite.c 1.1 90/07/09$
+ * from: Utah $Hdr: ite.c 1.28 92/12/20$
  *
  *
- *     @(#)ite.c       7.8 (Berkeley) %G%
+ *     @(#)ite.c       8.3 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
 #undef NITE
 #define NITE   NGRF
 
 #undef NITE
 #define NITE   NGRF
 
-#include "param.h"
-#include "conf.h"
-#include "proc.h"
-#include "ioctl.h"
-#include "tty.h"
-#include "systm.h"
-#include "malloc.h"
+#include <sys/param.h>
+#include <sys/conf.h>
+#include <sys/proc.h>
+#include <sys/ioctl.h>
+#include <sys/tty.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
 
 
-#include "itevar.h"
-#include "iteioctl.h"
-#include "kbdmap.h"
-
-#include "machine/cpu.h"
+#include <hp/dev/grfioctl.h>
+#include <hp/dev/grfvar.h>
+#include <hp/dev/itevar.h>
+#include <hp/dev/kbdmap.h>
 
 #define set_attr(ip, attr)     ((ip)->attribute |= (attr))
 #define clr_attr(ip, attr)     ((ip)->attribute &= ~(attr))
 
 
 #define set_attr(ip, attr)     ((ip)->attribute |= (attr))
 #define clr_attr(ip, attr)     ((ip)->attribute &= ~(attr))
 
-extern  int nodev();
-
-int topcat_scroll(),   topcat_init(),          topcat_deinit();
-int topcat_clear(),    topcat_putc(),          topcat_cursor();
-int gatorbox_scroll(), gatorbox_init(),        gatorbox_deinit();
-int gatorbox_clear(),  gatorbox_putc(),        gatorbox_cursor();
-int rbox_scroll(),     rbox_init(),            rbox_deinit();
-int rbox_clear(),      rbox_putc(),            rbox_cursor();
-int dvbox_scroll(),    dvbox_init(),           dvbox_deinit();
-int dvbox_clear(),     dvbox_putc(),           dvbox_cursor();
-
-struct itesw itesw[] =
-{
-       topcat_init,            topcat_deinit,          topcat_clear,
-       topcat_putc,            topcat_cursor,          topcat_scroll,
-
-       gatorbox_init,          gatorbox_deinit,        gatorbox_clear,
-       gatorbox_putc,          gatorbox_cursor,        gatorbox_scroll,
-
-       rbox_init,              rbox_deinit,            rbox_clear,
-       rbox_putc,              rbox_cursor,            rbox_scroll,
-
-       dvbox_init,             dvbox_deinit,           dvbox_clear,
-       dvbox_putc,             dvbox_cursor,           dvbox_scroll,
-};
+/*
+ * No need to raise SPL above the HIL (the only thing that can
+ * affect our state.
+ */
+#include <hp/dev/hilreg.h>
+#define splite()               splhil()
 
 /*
  * # of chars are output in a single itestart() call.
 
 /*
  * # of chars are output in a single itestart() call.
@@ -83,8 +63,7 @@ struct  tty *kbd_tty = NULL;
 struct tty ite_tty[NITE];
 struct  ite_softc ite_softc[NITE];
 
 struct tty ite_tty[NITE];
 struct  ite_softc ite_softc[NITE];
 
-void   itestart();
-extern int ttrstrt();
+void   itestart(), iterestart();
 extern struct tty *constty;
 
 /*
 extern struct tty *constty;
 
 /*
@@ -94,11 +73,25 @@ extern      struct tty *constty;
  */
 u_char  console_attributes[0x2200];
 
  */
 u_char  console_attributes[0x2200];
 
+#define ite_erasecursor(ip, sp)        { \
+       if ((ip)->flags & ITE_CURSORON) \
+               (*(sp)->ite_cursor)((ip), ERASE_CURSOR); \
+}
+#define ite_drawcursor(ip, sp) { \
+       if ((ip)->flags & ITE_CURSORON) \
+               (*(sp)->ite_cursor)((ip), DRAW_CURSOR); \
+}
+#define ite_movecursor(ip, sp) { \
+       if ((ip)->flags & ITE_CURSORON) \
+               (*(sp)->ite_cursor)((ip), MOVE_CURSOR); \
+}
+
 /*
  * Perform functions necessary to setup device as a terminal emulator.
  */
 iteon(dev, flag)
        dev_t dev;
 /*
  * Perform functions necessary to setup device as a terminal emulator.
  */
 iteon(dev, flag)
        dev_t dev;
+       int flag;
 {
        int unit = UNIT(dev);
        struct tty *tp = &ite_tty[unit];
 {
        int unit = UNIT(dev);
        struct tty *tp = &ite_tty[unit];
@@ -122,7 +115,7 @@ iteon(dev, flag)
                return(0);
        if (kbd_tty == NULL || kbd_tty == tp) {
                kbd_tty = tp;
                return(0);
        if (kbd_tty == NULL || kbd_tty == tp) {
                kbd_tty = tp;
-               kbdenable();
+               kbdenable(unit);
        }
        iteinit(dev);
        return(0);
        }
        iteinit(dev);
        return(0);
@@ -142,8 +135,9 @@ iteinit(dev)
        ip->cursorx = 0;
        ip->cursory = 0;
 
        ip->cursorx = 0;
        ip->cursory = 0;
 
-       (*itesw[ip->type].ite_init)(ip);
-       (*itesw[ip->type].ite_cursor)(ip, DRAW_CURSOR);
+       (*ip->isw->ite_init)(ip);
+       ip->flags |= ITE_CURSORON;
+       ite_drawcursor(ip, ip->isw);
 
        ip->attribute = 0;
        if (ip->attrbuf == NULL)
 
        ip->attribute = 0;
        if (ip->attrbuf == NULL)
@@ -163,16 +157,19 @@ iteinit(dev)
  */
 iteoff(dev, flag)
        dev_t dev;
  */
 iteoff(dev, flag)
        dev_t dev;
+       int flag;
 {
        register struct ite_softc *ip = &ite_softc[UNIT(dev)];
 
 {
        register struct ite_softc *ip = &ite_softc[UNIT(dev)];
 
-       if (flag & 2)
+       if (flag & 2) {
                ip->flags |= ITE_INGRF;
                ip->flags |= ITE_INGRF;
+               ip->flags &= ~ITE_CURSORON;
+       }
        if ((ip->flags & ITE_ACTIVE) == 0)
                return;
        if ((flag & 1) ||
            (ip->flags & (ITE_INGRF|ITE_ISCONS|ITE_INITED)) == ITE_INITED)
        if ((ip->flags & ITE_ACTIVE) == 0)
                return;
        if ((flag & 1) ||
            (ip->flags & (ITE_INGRF|ITE_ISCONS|ITE_INITED)) == ITE_INITED)
-               (*itesw[ip->type].ite_deinit)(ip);
+               (*ip->isw->ite_deinit)(ip);
        if ((flag & 2) == 0)
                ip->flags &= ~ITE_ACTIVE;
 }
        if ((flag & 2) == 0)
                ip->flags &= ~ITE_ACTIVE;
 }
@@ -241,6 +238,7 @@ iteclose(dev, flag, mode, p)
 iteread(dev, uio, flag)
        dev_t dev;
        struct uio *uio;
 iteread(dev, uio, flag)
        dev_t dev;
        struct uio *uio;
+       int flag;
 {
        register struct tty *tp = &ite_tty[UNIT(dev)];
 
 {
        register struct tty *tp = &ite_tty[UNIT(dev)];
 
@@ -250,6 +248,7 @@ iteread(dev, uio, flag)
 itewrite(dev, uio, flag)
        dev_t dev;
        struct uio *uio;
 itewrite(dev, uio, flag)
        dev_t dev;
        struct uio *uio;
+       int flag;
 {
        int unit = UNIT(dev);
        register struct tty *tp = &ite_tty[unit];
 {
        int unit = UNIT(dev);
        register struct tty *tp = &ite_tty[unit];
@@ -260,14 +259,17 @@ itewrite(dev, uio, flag)
        return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
 }
 
        return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
 }
 
-iteioctl(dev, cmd, addr, flag)
+iteioctl(dev, cmd, addr, flag, p)
        dev_t dev;
        dev_t dev;
+       u_long cmd;
        caddr_t addr;
        caddr_t addr;
+       int flag;
+       struct proc *p;
 {
        register struct tty *tp = &ite_tty[UNIT(dev)];
        int error;
 
 {
        register struct tty *tp = &ite_tty[UNIT(dev)];
        int error;
 
-       error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, addr, flag);
+       error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, addr, flag, p);
        if (error >= 0)
                return (error);
        error = ttioctl(tp, cmd, addr, flag);
        if (error >= 0)
                return (error);
        error = ttioctl(tp, cmd, addr, flag);
@@ -276,14 +278,31 @@ iteioctl(dev, cmd, addr, flag)
        return (ENOTTY);
 }
 
        return (ENOTTY);
 }
 
+void
+iterestart(tp)
+       register struct tty *tp;
+{
+       register int s = splite();
+
+       tp->t_state &= ~TS_TIMEOUT;
+       itestart(tp);
+       splx(s);
+}
+
 void
 itestart(tp)
        register struct tty *tp;
 {
        register int cc, s;
 void
 itestart(tp)
        register struct tty *tp;
 {
        register int cc, s;
-       int hiwat = 0;
+       int hiwat = 0, hadcursor = 0;
+       struct ite_softc *ip;
 
 
-       s = spltty();
+       /*
+        * (Potentially) lower priority.  We only need to protect ourselves
+        * from keyboard interrupts since that is all that can affect the
+        * state of our tty (kernel printf doesn't go through this routine).
+        */
+       s = splite();
        if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) {
                splx(s);
                return;
        if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) {
                splx(s);
                return;
@@ -295,47 +314,49 @@ itestart(tp)
                        tp->t_state &= ~TS_ASLEEP;
                        wakeup((caddr_t)&tp->t_outq);
                }
                        tp->t_state &= ~TS_ASLEEP;
                        wakeup((caddr_t)&tp->t_outq);
                }
-               if (tp->t_wsel) {
-                       selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL);
-                       tp->t_wsel = 0;
-                       tp->t_state &= ~TS_WCOLL;
-               }
+               selwakeup(&tp->t_wsel);
        }
        /*
        }
        /*
-        * Limit the amount of output we do in one burst
-        * to prevent hogging the CPU.
+        * Handle common (?) case
         */
         */
-       if (cc > iteburst) {
-               hiwat++;
-               cc = iteburst;
-       }
-       while (--cc >= 0) {
-               register int c;
-
-               c = getc(&tp->t_outq);
+       if (cc == 1) {
+               iteputchar(getc(&tp->t_outq), tp->t_dev);
+       } else if (cc) {
                /*
                /*
-                * iteputchar() may take a long time and we don't want to
-                * block all interrupts for long periods of time.  Since
-                * there is no need to stay at high priority while outputing
-                * the character (since we don't have to worry about
-                * interrupts), we don't.  We just need to make sure that
-                * we don't reenter iteputchar, which is guarenteed by the
-                * earlier setting of TS_BUSY.
+                * Limit the amount of output we do in one burst
+                * to prevent hogging the CPU.
                 */
                 */
-               splx(s);
-               iteputchar(c, tp->t_dev);
-               spltty();
-       }
-       if (hiwat) {
-               tp->t_state |= TS_TIMEOUT;
-               timeout(ttrstrt, tp, 1);
+               if (cc > iteburst) {
+                       hiwat++;
+                       cc = iteburst;
+               }
+               /*
+                * Turn off cursor while we output multiple characters.
+                * Saves a lot of expensive window move operations.
+                */
+               ip = &ite_softc[UNIT(tp->t_dev)];
+               if (ip->flags & ITE_CURSORON) {
+                       ite_erasecursor(ip, ip->isw);
+                       ip->flags &= ~ITE_CURSORON;
+                       hadcursor = 1;
+               }
+               while (--cc >= 0)
+                       iteputchar(getc(&tp->t_outq), tp->t_dev);
+               if (hadcursor) {
+                       ip->flags |= ITE_CURSORON;
+                       ite_drawcursor(ip, ip->isw);
+               }
+               if (hiwat) {
+                       tp->t_state |= TS_TIMEOUT;
+                       timeout(iterestart, tp, 1);
+               }
        }
        tp->t_state &= ~TS_BUSY;
        splx(s);
 }
 
 itefilter(stat, c)
        }
        tp->t_state &= ~TS_BUSY;
        splx(s);
 }
 
 itefilter(stat, c)
-     register char stat, c;
+       register char stat, c;
 {
        static int capsmode = 0;
        static int metamode = 0;
 {
        static int capsmode = 0;
        static int metamode = 0;
@@ -368,7 +389,7 @@ itefilter(stat, c)
                        code = kbd_keymap[c];
                        break;
                }
                        code = kbd_keymap[c];
                        break;
                }
-               /* fall into... */
+               /* FALLTHROUGH */
 
        case KBD_SHIFT:
                code = kbd_shiftmap[c];
 
        case KBD_SHIFT:
                code = kbd_shiftmap[c];
@@ -399,7 +420,7 @@ iteputchar(c, dev)
 {
        int unit = UNIT(dev);
        register struct ite_softc *ip = &ite_softc[unit];
 {
        int unit = UNIT(dev);
        register struct ite_softc *ip = &ite_softc[unit];
-       register struct itesw *sp = &itesw[ip->type];
+       register struct itesw *sp = ip->isw;
        register int n;
 
        if ((ip->flags & (ITE_ACTIVE|ITE_INGRF)) != ITE_ACTIVE)
        register int n;
 
        if ((ip->flags & (ITE_ACTIVE|ITE_INGRF)) != ITE_ACTIVE)
@@ -420,24 +441,24 @@ doesc:
                        switch (c) {
 
                        case 'Y':                       /* Only y coord. */
                        switch (c) {
 
                        case 'Y':                       /* Only y coord. */
-                               ip->cury = MIN(ip->pos, ip->rows-1);
+                               ip->cury = min(ip->pos, ip->rows-1);
                                ip->pos = 0;
                                ip->escape = 0;
                                ip->pos = 0;
                                ip->escape = 0;
-                               (*sp->ite_cursor)(ip, MOVE_CURSOR);
+                               ite_movecursor(ip, sp);
                                clr_attr(ip, ATTR_INV);
                                break;
 
                        case 'y':                       /* y coord first */
                                clr_attr(ip, ATTR_INV);
                                break;
 
                        case 'y':                       /* y coord first */
-                               ip->cury = MIN(ip->pos, ip->rows-1);
+                               ip->cury = min(ip->pos, ip->rows-1);
                                ip->pos = 0;
                                ip->fpd = 0;
                                break;
 
                        case 'C':                       /* x coord */
                                ip->pos = 0;
                                ip->fpd = 0;
                                break;
 
                        case 'C':                       /* x coord */
-                               ip->curx = MIN(ip->pos, ip->cols-1);
+                               ip->curx = min(ip->pos, ip->cols-1);
                                ip->pos = 0;
                                ip->escape = 0;
                                ip->pos = 0;
                                ip->escape = 0;
-                               (*sp->ite_cursor)(ip, MOVE_CURSOR);
+                               ite_movecursor(ip, sp);
                                clr_attr(ip, ATTR_INV);
                                break;
 
                                clr_attr(ip, ATTR_INV);
                                break;
 
@@ -501,7 +522,7 @@ doesc:
                                ip->curx -= n;
                        } else
                                ip->curx = 0;
                                ip->curx -= n;
                        } else
                                ip->curx = 0;
-                       (*sp->ite_cursor)(ip, MOVE_CURSOR);
+                       ite_movecursor(ip, sp);
                        ip->escape = 0;
                        return;
 
                        ip->escape = 0;
                        return;
 
@@ -521,11 +542,12 @@ doesc:
                case 'B':                       /* cursor down 1 line */
                        if (++ip->cury == ip->rows) {
                                --ip->cury;
                case 'B':                       /* cursor down 1 line */
                        if (++ip->cury == ip->rows) {
                                --ip->cury;
+                               ite_erasecursor(ip, sp);
                                (*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
                                ite_clrtoeol(ip, sp, ip->cury, 0);
                        }
                        else
                                (*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
                                ite_clrtoeol(ip, sp, ip->cury, 0);
                        }
                        else
-                               (*sp->ite_cursor)(ip, MOVE_CURSOR);
+                               ite_movecursor(ip, sp);
                        clr_attr(ip, ATTR_INV);
                        ip->escape = 0;
                        return;
                        clr_attr(ip, ATTR_INV);
                        ip->escape = 0;
                        return;
@@ -538,7 +560,7 @@ doesc:
                case 'A':                       /* cursor up 1 line */
                        if (ip->cury > 0) {
                                ip->cury--;
                case 'A':                       /* cursor up 1 line */
                        if (ip->cury > 0) {
                                ip->cury--;
-                               (*sp->ite_cursor)(ip, MOVE_CURSOR);
+                               ite_movecursor(ip, sp);
                        }
                        ip->escape = 0;
                        clr_attr(ip, ATTR_INV);
                        }
                        ip->escape = 0;
                        clr_attr(ip, ATTR_INV);
@@ -571,14 +593,14 @@ doesc:
 
                case 'h':                       /* home key */
                        ip->cury = ip->curx = 0;
 
                case 'h':                       /* home key */
                        ip->cury = ip->curx = 0;
-                       (*sp->ite_cursor)(ip, MOVE_CURSOR);
+                       ite_movecursor(ip, sp);
                        ip->escape = 0;
                        return;
 
                case 'D':                       /* left arrow key */
                        if (ip->curx > 0) {
                                ip->curx--;
                        ip->escape = 0;
                        return;
 
                case 'D':                       /* left arrow key */
                        if (ip->curx > 0) {
                                ip->curx--;
-                               (*sp->ite_cursor)(ip, MOVE_CURSOR);
+                               ite_movecursor(ip, sp);
                        }
                        ip->escape = 0;
                        return;
                        }
                        ip->escape = 0;
                        return;
@@ -606,18 +628,18 @@ ignore:
 
                if (++ip->cury == ip->rows) {
                        --ip->cury;
 
                if (++ip->cury == ip->rows) {
                        --ip->cury;
+                       ite_erasecursor(ip, sp);
                        (*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
                        ite_clrtoeol(ip, sp, ip->cury, 0);
                        (*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
                        ite_clrtoeol(ip, sp, ip->cury, 0);
-               }
-               else
-                       (*sp->ite_cursor)(ip, MOVE_CURSOR);
+               } else
+                       ite_movecursor(ip, sp);
                clr_attr(ip, ATTR_INV);
                break;
 
        case '\r':
                if (ip->curx) {
                        ip->curx = 0;
                clr_attr(ip, ATTR_INV);
                break;
 
        case '\r':
                if (ip->curx) {
                        ip->curx = 0;
-                       (*sp->ite_cursor)(ip, MOVE_CURSOR);
+                       ite_movecursor(ip, sp);
                }
                break;
        
                }
                break;
        
@@ -625,21 +647,21 @@ ignore:
                if (--ip->curx < 0)
                        ip->curx = 0;
                else
                if (--ip->curx < 0)
                        ip->curx = 0;
                else
-                       (*sp->ite_cursor)(ip, MOVE_CURSOR);
+                       ite_movecursor(ip, sp);
                break;
 
        case '\t':
                if (ip->curx < TABEND(unit)) {
                        n = TABSIZE - (ip->curx & (TABSIZE - 1));
                        ip->curx += n;
                break;
 
        case '\t':
                if (ip->curx < TABEND(unit)) {
                        n = TABSIZE - (ip->curx & (TABSIZE - 1));
                        ip->curx += n;
-                       (*sp->ite_cursor)(ip, MOVE_CURSOR);
+                       ite_movecursor(ip, sp);
                } else
                        itecheckwrap(ip, sp);
                break;
 
        case CTRL('G'):
                if (&ite_tty[unit] == kbd_tty)
                } else
                        itecheckwrap(ip, sp);
                break;
 
        case CTRL('G'):
                if (&ite_tty[unit] == kbd_tty)
-                       kbdbell();
+                       kbdbell(unit);
                break;
 
        case ESC:
                break;
 
        case ESC:
@@ -654,10 +676,9 @@ ignore:
                if ((ip->attribute & ATTR_INV) || attrtest(ip, ATTR_INV)) {
                        attrset(ip, ATTR_INV);
                        (*sp->ite_putc)(ip, c, ip->cury, ip->curx, ATTR_INV);
                if ((ip->attribute & ATTR_INV) || attrtest(ip, ATTR_INV)) {
                        attrset(ip, ATTR_INV);
                        (*sp->ite_putc)(ip, c, ip->cury, ip->curx, ATTR_INV);
-               }                       
-               else
+               } else
                        (*sp->ite_putc)(ip, c, ip->cury, ip->curx, ATTR_NOR);
                        (*sp->ite_putc)(ip, c, ip->cury, ip->curx, ATTR_NOR);
-               (*sp->ite_cursor)(ip, DRAW_CURSOR);
+               ite_drawcursor(ip, sp);
                itecheckwrap(ip, sp);
                break;
        }
                itecheckwrap(ip, sp);
                break;
        }
@@ -672,45 +693,55 @@ itecheckwrap(ip, sp)
                clr_attr(ip, ATTR_INV);
                if (++ip->cury == ip->rows) {
                        --ip->cury;
                clr_attr(ip, ATTR_INV);
                if (++ip->cury == ip->rows) {
                        --ip->cury;
+                       ite_erasecursor(ip, sp);
                        (*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
                        ite_clrtoeol(ip, sp, ip->cury, 0);
                        return;
                }
        }
                        (*sp->ite_scroll)(ip, 1, 0, 1, SCROLL_UP);
                        ite_clrtoeol(ip, sp, ip->cury, 0);
                        return;
                }
        }
-       (*sp->ite_cursor)(ip, MOVE_CURSOR);
+       ite_movecursor(ip, sp);
 }
 
 ite_dchar(ip, sp)
      register struct ite_softc *ip;
      register struct itesw *sp;
 {
 }
 
 ite_dchar(ip, sp)
      register struct ite_softc *ip;
      register struct itesw *sp;
 {
-       (*sp->ite_scroll)(ip, ip->cury, ip->curx + 1, 1, SCROLL_LEFT);
-       attrmov(ip, ip->cury, ip->curx + 1, ip->cury, ip->curx,
-               1, ip->cols - ip->curx - 1);
+       if (ip->curx < ip->cols - 1) {
+               ite_erasecursor(ip, sp);
+               (*sp->ite_scroll)(ip, ip->cury, ip->curx + 1, 1, SCROLL_LEFT);
+               attrmov(ip, ip->cury, ip->curx + 1, ip->cury, ip->curx,
+                       1, ip->cols - ip->curx - 1);
+       }
        attrclr(ip, ip->cury, ip->cols - 1, 1, 1);
        (*sp->ite_putc)(ip, ' ', ip->cury, ip->cols - 1, ATTR_NOR);
        attrclr(ip, ip->cury, ip->cols - 1, 1, 1);
        (*sp->ite_putc)(ip, ' ', ip->cury, ip->cols - 1, ATTR_NOR);
-       (*sp->ite_cursor)(ip, DRAW_CURSOR);
+       ite_drawcursor(ip, sp);
 }
 
 ite_ichar(ip, sp)
      register struct ite_softc *ip;
      register struct itesw *sp;
 {
 }
 
 ite_ichar(ip, sp)
      register struct ite_softc *ip;
      register struct itesw *sp;
 {
-       (*sp->ite_scroll)(ip, ip->cury, ip->curx, 1, SCROLL_RIGHT);
-       attrmov(ip, ip->cury, ip->curx, ip->cury, ip->curx + 1,
-               1, ip->cols - ip->curx - 1);
+       if (ip->curx < ip->cols - 1) {
+               ite_erasecursor(ip, sp);
+               (*sp->ite_scroll)(ip, ip->cury, ip->curx, 1, SCROLL_RIGHT);
+               attrmov(ip, ip->cury, ip->curx, ip->cury, ip->curx + 1,
+                       1, ip->cols - ip->curx - 1);
+       }
        attrclr(ip, ip->cury, ip->curx, 1, 1);
        (*sp->ite_putc)(ip, ' ', ip->cury, ip->curx, ATTR_NOR);
        attrclr(ip, ip->cury, ip->curx, 1, 1);
        (*sp->ite_putc)(ip, ' ', ip->cury, ip->curx, ATTR_NOR);
-       (*sp->ite_cursor)(ip, DRAW_CURSOR);
+       ite_drawcursor(ip, sp);
 }
 
 ite_dline(ip, sp)
      register struct ite_softc *ip;
      register struct itesw *sp;
 {
 }
 
 ite_dline(ip, sp)
      register struct ite_softc *ip;
      register struct itesw *sp;
 {
-       (*sp->ite_scroll)(ip, ip->cury + 1, 0, 1, SCROLL_UP);
-       attrmov(ip, ip->cury + 1, 0, ip->cury, 0,
-               ip->rows - ip->cury - 1, ip->cols);
+       if (ip->cury < ip->rows - 1) {
+               ite_erasecursor(ip, sp);
+               (*sp->ite_scroll)(ip, ip->cury + 1, 0, 1, SCROLL_UP);
+               attrmov(ip, ip->cury + 1, 0, ip->cury, 0,
+                       ip->rows - ip->cury - 1, ip->cols);
+       }
        ite_clrtoeol(ip, sp, ip->rows - 1, 0);
 }
 
        ite_clrtoeol(ip, sp, ip->rows - 1, 0);
 }
 
@@ -718,9 +749,12 @@ ite_iline(ip, sp)
      register struct ite_softc *ip;
      register struct itesw *sp;
 {
      register struct ite_softc *ip;
      register struct itesw *sp;
 {
-       (*sp->ite_scroll)(ip, ip->cury, 0, 1, SCROLL_DOWN);
-       attrmov(ip, ip->cury, 0, ip->cury + 1, 0,
-               ip->rows - ip->cury - 1, ip->cols);
+       if (ip->cury < ip->rows - 1) {
+               ite_erasecursor(ip, sp);
+               (*sp->ite_scroll)(ip, ip->cury, 0, 1, SCROLL_DOWN);
+               attrmov(ip, ip->cury, 0, ip->cury + 1, 0,
+                       ip->rows - ip->cury - 1, ip->cols);
+       }
        ite_clrtoeol(ip, sp, ip->cury, 0);
 }
 
        ite_clrtoeol(ip, sp, ip->cury, 0);
 }
 
@@ -731,7 +765,7 @@ ite_clrtoeol(ip, sp, y, x)
 {
        (*sp->ite_clear)(ip, y, x, 1, ip->cols - x);
        attrclr(ip, y, x, 1, ip->cols - x);
 {
        (*sp->ite_clear)(ip, y, x, 1, ip->cols - x);
        attrclr(ip, y, x, 1, ip->cols - x);
-       (*sp->ite_cursor)(ip, DRAW_CURSOR);
+       ite_drawcursor(ip, sp);
 }
 
 ite_clrtoeos(ip, sp)
 }
 
 ite_clrtoeos(ip, sp)
@@ -740,15 +774,16 @@ ite_clrtoeos(ip, sp)
 {
        (*sp->ite_clear)(ip, ip->cury, 0, ip->rows - ip->cury, ip->cols);
        attrclr(ip, ip->cury, 0, ip->rows - ip->cury, ip->cols);
 {
        (*sp->ite_clear)(ip, ip->cury, 0, ip->rows - ip->cury, ip->cols);
        attrclr(ip, ip->cury, 0, ip->rows - ip->cury, ip->cols);
-       (*sp->ite_cursor)(ip, DRAW_CURSOR);
+       ite_drawcursor(ip, sp);
 }
 
 /*
  * Console functions
  */
 }
 
 /*
  * Console functions
  */
-#include "../hp300/cons.h"
-#include "grfioctl.h"
-#include "grfvar.h"
+#include <hp/dev/cons.h>
+#ifdef hp300
+#include <hp/dev/grfreg.h>
+#endif
 
 #ifdef DEBUG
 /*
 
 #ifdef DEBUG
 /*
@@ -763,7 +798,7 @@ itecnprobe(cp)
        struct consdev *cp;
 {
        register struct ite_softc *ip;
        struct consdev *cp;
 {
        register struct ite_softc *ip;
-       int i, maj, unit, pri;
+       int i, sw, maj, unit, pri;
 
        /* locate the major number */
        for (maj = 0; maj < nchrdev; maj++)
 
        /* locate the major number */
        for (maj = 0; maj < nchrdev; maj++)
@@ -784,29 +819,20 @@ itecnprobe(cp)
                        continue;
                ip->flags = (ITE_ALIVE|ITE_CONSOLE);
 
                        continue;
                ip->flags = (ITE_ALIVE|ITE_CONSOLE);
 
-               /* XXX - we need to do something about mapping these */
-               switch (gp->g_type) {
+               /* locate the proper switch table. */
+               for (sw = 0; sw < nitesw; sw++)
+                       if (itesw[sw].ite_hwid == gp->g_sw->gd_hwid)
+                               break;
 
 
-               case GT_TOPCAT:
-               case GT_LRCATSEYE:
-               case GT_HRCCATSEYE:
-               case GT_HRMCATSEYE:
-                       ip->type = ITE_TOPCAT;
-                       break;
-               case GT_GATORBOX:
-                       ip->type = ITE_GATORBOX;
-                       break;
-               case GT_RENAISSANCE:
-                       ip->type = ITE_RENAISSANCE;
-                       break;
-               case GT_DAVINCI:
-                       ip->type = ITE_DAVINCI;
-                       break;
-               }
+               if (sw == nitesw)
+                       continue;
 #ifdef DEBUG
                if (i < whichconsole)
                        continue;
 #endif
 #ifdef DEBUG
                if (i < whichconsole)
                        continue;
 #endif
+               ip->isw = &itesw[sw];
+               ip->grf = gp;
+#ifdef hp300
                if ((int)gp->g_display.gd_regaddr == GRFIADDR) {
                        pri = CN_INTERNAL;
                        unit = i;
                if ((int)gp->g_display.gd_regaddr == GRFIADDR) {
                        pri = CN_INTERNAL;
                        unit = i;
@@ -814,6 +840,14 @@ itecnprobe(cp)
                        pri = CN_NORMAL;
                        unit = i;
                }
                        pri = CN_NORMAL;
                        unit = i;
                }
+#endif
+#ifdef hp800
+               /* XXX use the first one for now */
+               if (unit < 0) {
+                       pri = CN_INTERNAL;
+                       unit = i;
+               }
+#endif
        }
 
        /* initialize required fields */
        }
 
        /* initialize required fields */
@@ -841,7 +875,7 @@ itecngetc(dev)
        register int c;
        int stat;
 
        register int c;
        int stat;
 
-       c = kbdgetc(&stat);
+       c = kbdgetc(0, &stat);  /* XXX always read from keyboard 0 for now */
        switch ((stat >> KBD_SSHIFT) & KBD_SMASK) {
        case KBD_SHIFT:
                c = kbd_shiftmap[c & KBD_CHARMASK];
        switch ((stat >> KBD_SSHIFT) & KBD_SMASK) {
        case KBD_SHIFT:
                c = kbd_shiftmap[c & KBD_CHARMASK];