Change to includes. no more ../h
[unix-history] / usr / src / sys / kern / tty_tb.c
index 59a2ab5..de23b6c 100644 (file)
@@ -1,44 +1,43 @@
-/*     tty_tb.c        4.2     82/08/01        */
+/*     tty_tb.c        6.3     84/08/29        */
 
 #include "tb.h"
 #if NTB > 0
 
 
 #include "tb.h"
 #if NTB > 0
 
-#include "../h/param.h"
-#include "../h/systm.h"
-#include "../h/dir.h"
-#include "../h/user.h"
-#include "../h/tty.h"
-#include "../h/proc.h"
-#include "../h/inode.h"
-#include "../h/file.h"
-#include "../h/conf.h"
-#include "../h/buf.h"
+#include "param.h"
+#include "systm.h"
+#include "dir.h"
+#include "user.h"
+#include "ioctl.h"
+#include "tty.h"
+#include "proc.h"
+#include "inode.h"
+#include "file.h"
+#include "conf.h"
+#include "buf.h"
+#include "uio.h"
 
 /*
  * Line discipline for RS232 tablets.
 
 /*
  * Line discipline for RS232 tablets.
+ * Supplies binary coordinate data.
  *
  *
- * This supplies binary coordinate data to a user level program
- * with a minimum of fuss.
- *
- * This discipline requires that tty device drivers call
- * the line specific l_ioctl routine from their ioctl routines,
- * assigning the result to cmd so that we can refuse most tty specific
- * ioctls which are unsafe because we have ambushed the
- * teletype input queues and other data, overlaying them with
- * the following information: the tty queue header, t_un.T_CTLQ,
- * is overlaid with a MTABCHAR character buffer -- the raw input
- * chars. The local characters (t_rocount on) are overlaid with
- * the current coordinate position.
+ * MAKE TABLET TYPE AN ioctl TO AVOID HAVING ONE DISCIPLINE PER TABLET TYPE.
  */
 
  */
 
-#define MTABCHAR 5
-#define MNTABCHAR 6
-struct tbposition {
-       int xpos;
-       int ypos;
-       short int status;
-       short int scount;
-};
+#define NTBS           (16)
+#define MALLTABCHAR    (8)
+#define MTABCHAR       (5)
+#define MNTABCHAR      (6)
+
+struct tb {
+       short used;
+       char cbuf[MALLTABCHAR];
+       struct tbpos {
+               int     xpos;
+               int     ypos;
+               short   status;
+               short   scount;
+       } tbpos;
+} tb[NTBS];
 
 /*
  * Open as tablet discipline.  Called when discipline changed
 
 /*
  * Open as tablet discipline.  Called when discipline changed
@@ -50,19 +49,23 @@ tbopen(dev, tp)
        dev_t dev;
        register struct tty *tp;
 {
        dev_t dev;
        register struct tty *tp;
 {
-       register struct tbposition *tbp;
-
-       if (u.u_error)
-               return;         /* paranoia */
-       if (tp->t_line == TABLDISC || tp->t_line == NTABLDISC) {
-               u.u_error = EBUSY;
-               return; 
-       }
-       wflushtty(tp);
-       tp->t_cp = (char *) &tp->t_un.T_CTLQ;   /* overlay control queue */
+       register struct tb *tbp;
+
+       if (tp->t_line == TABLDISC || tp->t_line == NTABLDISC)
+               return (ENODEV);
+       ttywflush(tp);
+       for (tbp = tb; tbp < &tb[NTBS]; tbp++)
+               if (!tbp->used)
+                       break;
+       if (tbp >= &tb[NTBS])
+               return (EBUSY);
+       tbp->used++;
+       tp->t_cp = tbp->cbuf;
        tp->t_inbuf = 0;
        tp->t_inbuf = 0;
-       tbp = (struct tbposition *) &tp->t_rocount;
-       tbp->xpos = tbp->ypos = tbp->status = tbp->scount = 0;
+       tbp->tbpos.xpos = tbp->tbpos.ypos = 0;
+       tbp->tbpos.status = tbp->tbpos.scount = 0;
+       tp->T_LINEP = (caddr_t) tbp;
+       return (0);
 }
 
 /*
 }
 
 /*
@@ -70,18 +73,16 @@ tbopen(dev, tp)
  * close routine.
  */
 tbclose(tp)
  * close routine.
  */
 tbclose(tp)
-register struct tty *tp;
+       register struct tty *tp;
 {
 {
-       register s;
+       register int s = spl5();
 
 
-       s = spl5();
+       ((struct tb *) tp->T_LINEP)->used = 0;
        tp->t_cp = 0;
        tp->t_inbuf = 0;
        tp->t_rawq.c_cc = 0;            /* clear queues -- paranoid */
        tp->t_canq.c_cc = 0;
        tp->t_cp = 0;
        tp->t_inbuf = 0;
        tp->t_rawq.c_cc = 0;            /* clear queues -- paranoid */
        tp->t_canq.c_cc = 0;
-       tp->t_un.T_CTLQ.c_cc = 0;       /* clear overlaid queue status */
-       tp->t_un.T_CTLQ.c_cf = tp->t_un.T_CTLQ.c_cl = NULL;
-       tp->t_line = 0;         /* paranoid: avoid races */
+       tp->t_line = 0;                 /* paranoid: avoid races */
        splx(s);
 }
 
        splx(s);
 }
 
@@ -90,23 +91,16 @@ register struct tty *tp;
  * Characters have been buffered in a buffer and
  * decoded. The coordinates are now sluffed back to the user.
  */
  * Characters have been buffered in a buffer and
  * decoded. The coordinates are now sluffed back to the user.
  */
-tbread(tp)
-register struct tty *tp;
+tbread(tp, uio)
+       register struct tty *tp;
+       struct uio *uio;
 {
 {
-       register int i;
-       register s;
-       struct tbposition tbposition;
+       struct tbpos *tbpos;
 
        if ((tp->t_state&TS_CARR_ON)==0)
 
        if ((tp->t_state&TS_CARR_ON)==0)
-               return (-1);
-       if (copyout(&tp->t_rocount, u.u_base, (unsigned)(sizeof tbposition))) {
-               u.u_error = EFAULT;
-               return (-1);
-       }
-       u.u_count -= sizeof tbposition;
-       u.u_base += sizeof tbposition;
-       u.u_offset += sizeof tbposition;
-       return (0);
+               return (EIO);
+       tbpos = &(((struct tb *) (tp->T_LINEP))->tbpos);
+       return (uiomove(tbpos, sizeof *tbpos, UIO_READ, uio));
 }
 
 /*
 }
 
 /*
@@ -117,30 +111,30 @@ register struct tty *tp;
  * This routine could be expanded in-line in the receiver
  * interrupt routine of the dh-11 to make it run as fast as possible.
  */
  * This routine could be expanded in-line in the receiver
  * interrupt routine of the dh-11 to make it run as fast as possible.
  */
-int LASTTABC;
+int    LASTTABC;
+
 tbinput(c, tp)
 tbinput(c, tp)
-register c;
-register struct tty *tp;
+       register int c;
+       register struct tty *tp;
 {
 {
+       register struct tb *tbp = (struct tb *) tp->T_LINEP;
 
 
-       if(tp->t_line == TABLDISC) {
-               if((c&0200) || (tp->t_inbuf == MTABCHAR)) {
-                       tp->t_cp = (char *) &tp->t_un.T_CTLQ;
+       if (tp->t_line == TABLDISC) {
+               if ((c&0200) || (tp->t_inbuf == MTABCHAR)) {
+                       tp->t_cp = tbp->cbuf;
                        tp->t_inbuf = 0;
                }
                *tp->t_cp++ = c&0177;
                        tp->t_inbuf = 0;
                }
                *tp->t_cp++ = c&0177;
-               if(++tp->t_inbuf == MTABCHAR)
-                       tbdecode((char *) &tp->t_un.T_CTLQ,
-                                       (struct tbposition *) &tp->t_rocount);
-       } else if(tp->t_line == NTABLDISC) {
-               if((c&0200) || (tp->t_inbuf == MNTABCHAR)) {
-                       tp->t_cp = (char *) &tp->t_un.T_CTLQ;
+               if (++tp->t_inbuf == MTABCHAR)
+                       tbdecode(tbp->cbuf, &tbp->tbpos);
+       } else if (tp->t_line == NTABLDISC) {
+               if ((c&0200) || (tp->t_inbuf == MNTABCHAR)) {
+                       tp->t_cp = tbp->cbuf;
                        tp->t_inbuf = 0;
                }
                *tp->t_cp++ = c&0177;
                        tp->t_inbuf = 0;
                }
                *tp->t_cp++ = c&0177;
-               if(++tp->t_inbuf == MNTABCHAR)
-                       tbndecode((char *) &tp->t_un.T_CTLQ,
-                                       (struct tbposition *) &tp->t_rocount);
+               if (++tp->t_inbuf == MNTABCHAR)
+                       tbndecode(tbp->cbuf, &tbp->tbpos);
        }
 }
 
        }
 }
 
@@ -148,28 +142,28 @@ register struct tty *tp;
  * Decode tablet coordinates from ascii to binary.
  *     (gtco 6 character format)
  */
  * Decode tablet coordinates from ascii to binary.
  *     (gtco 6 character format)
  */
-tbndecode(cp, tbposition)
+tbndecode(cp, tbpos)
        register char *cp;
        register char *cp;
-       register struct tbposition *tbposition;
+       register struct tbpos *tbpos;
 {
 
 {
 
-       tbposition->status = *cp>>2;    /* this needs to be decoded */
-       tbposition->xpos = ((*cp++)&03)<<14;
-       tbposition->xpos |= (*cp++)<<7;
-       tbposition->xpos |= (*cp++);
-       tbposition->ypos = ((*cp++)&03)<<14;
-       tbposition->ypos |= (*cp++)<<7;
-       tbposition->ypos |= (*cp++);
-       tbposition->scount++;
+       tbpos->status = *cp>>2; /* this needs to be decoded */
+       tbpos->xpos = ((*cp++)&03)<<14;
+       tbpos->xpos |= (*cp++)<<7;
+       tbpos->xpos |= (*cp++);
+       tbpos->ypos = ((*cp++)&03)<<14;
+       tbpos->ypos |= (*cp++)<<7;
+       tbpos->ypos |= (*cp++);
+       tbpos->scount++;
 }
 
 /*
  * Decode tablet coordinates from ascii to binary.
  *     (hitachi 5 character format)
  */
 }
 
 /*
  * Decode tablet coordinates from ascii to binary.
  *     (hitachi 5 character format)
  */
-tbdecode(cp, tbposition)
+tbdecode(cp, tbpos)
        register char *cp;
        register char *cp;
-       register struct tbposition *tbposition;
+       register struct tbpos *tbpos;
 {
        register int status;
        register char byte;
 {
        register int status;
        register char byte;
@@ -177,16 +171,16 @@ tbdecode(cp, tbposition)
        byte = *cp++;
        status = (byte&0100) ? 0100000 : 0;
        byte &= ~0100;
        byte = *cp++;
        status = (byte&0100) ? 0100000 : 0;
        byte &= ~0100;
-       if(byte > 036)
+       if (byte > 036)
                status |= 1<<((byte-040)/2);
                status |= 1<<((byte-040)/2);
-       tbposition->xpos = (*cp++)<<7;
-       tbposition->xpos |= (*cp++);
-       if(tbposition->xpos < 256)      /* tablet wraps around at 256 */
+       tbpos->xpos = (*cp++)<<7;
+       tbpos->xpos |= (*cp++);
+       if (tbpos->xpos < 256)          /* tablet wraps around at 256 */
                status &= 077777;       /* make it out of proximity */
                status &= 077777;       /* make it out of proximity */
-       tbposition->ypos = (*cp++)<<7;
-       tbposition->ypos |= (*cp++);
-       tbposition->status  = status;
-       tbposition->scount++;
+       tbpos->ypos = (*cp++)<<7;
+       tbpos->ypos |= (*cp++);
+       tbpos->status  = status;
+       tbpos->scount++;
 }
 
 /*
 }
 
 /*