home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / sys / dev / vs.c < prev   
Encoding:
C/C++ Source or Header  |  1998-02-03  |  1.9 KB  |  139 lines

  1. /*
  2.  * Screw Works interface via DC-11
  3.  */
  4.  
  5. #include "../h/types.h"
  6. #include "../h/tty.h"
  7.  
  8. #define    VSADDR    ((struct device *)0174140)
  9. #define    CDLEAD    01
  10. #define    B1200    030
  11. #define    STOP1    0400
  12. #define    CLSEND    02
  13. #define    RQSEND    01
  14.  
  15. #define    GO    026
  16. #define    COUNT    120
  17.  
  18. struct device {
  19.     int    vsrcsr;
  20.     int    vsrbuf;
  21.     int    vsxcsr;
  22.     int    vsxbuf;
  23. };
  24.  
  25. struct {
  26.     struct    clist    iq;
  27.     int    vtime;
  28.     struct    clist    oq;
  29. } vs;
  30.  
  31.  
  32. vsopen(dev)
  33. {
  34.     register c;
  35.  
  36.     c = VSADDR->vsrcsr;        /* touch register */
  37.     VSADDR->vsrcsr = IENABLE|B1200|CDLEAD;
  38.     VSADDR->vsxcsr = STOP1|IENABLE|B1200;
  39.     vschar(GO);
  40. }
  41.  
  42. vsclose(dev)
  43. {
  44.     vschar(GO);
  45.     VSADDR->vsrcsr &= ~IENABLE;
  46.     while (getc(&vs.iq) >= 0);
  47. }
  48.  
  49. vswrite(dev)
  50. {
  51.     register int count, c;
  52.  
  53.     count = 0;
  54.     while ((c=cpass()) >= 0) {
  55.         if (--count <= 0) {
  56.             count = COUNT;
  57.             vschar(GO);
  58.         }
  59.         vschar(c);
  60.     }
  61.     vschar(GO);
  62. }
  63.  
  64. vschar(c)
  65. {
  66.  
  67.     spl5();
  68.     while (vs.oq.c_cc > 120) {
  69.         vsxintr();
  70.         sleep((caddr_t)&vs.oq, TTIPRI);
  71.     }
  72.     putc(c, &vs.oq);
  73.     vsxintr();
  74.     spl0();
  75. }
  76.  
  77. vstimo()
  78. {
  79.     vs.vtime = 0;
  80.     vsxintr();
  81. }
  82.  
  83. vsxintr()
  84. {
  85.     static lchar;
  86.     register c;
  87.     register int *xcsr;
  88.  
  89.     xcsr = &VSADDR->vsxcsr;
  90.     if (*xcsr&DONE) {
  91.         if (lchar==GO) {
  92.             *xcsr &= ~RQSEND;
  93.             lchar = -1;
  94.             if (vs.oq.c_cc==0) {
  95.                 wakeup((caddr_t)&vs.oq);
  96.                 return;
  97.             }
  98.         }
  99.         if ((*xcsr&CLSEND) == 0) {
  100.             *xcsr |= RQSEND;
  101.             if ((*xcsr&CLSEND) == 0) {
  102.                 if (vs.vtime==0) {
  103.                     vs.vtime++;
  104.                     timeout(vstimo, (caddr_t)0, 60);
  105.                 }
  106.                 return;
  107.             }
  108.         }
  109.         if ((c = getc(&vs.oq)) >= 0)
  110.             VSADDR->vsxbuf = lchar = c;
  111.         else
  112.             *xcsr &= ~RQSEND;
  113.         if (vs.oq.c_cc <= 15)
  114.             wakeup((caddr_t)&vs.oq);
  115.     }
  116. }
  117.  
  118. vsread(dev)
  119. {
  120.     register int c;
  121.  
  122.     spl5();
  123.     while ((c = getc(&vs.iq)) < 0)
  124.         sleep((caddr_t)&vs.iq, TTIPRI);
  125.     spl0();
  126.     passc("?0*#?546?213?879?"[c&017]);
  127. }
  128.  
  129. vsrintr()
  130. {
  131.     register int c;
  132.  
  133.     c = VSADDR->vsrbuf;    /* Register must be read (?) */
  134.     c = VSADDR->vsrbuf;
  135.     if (vs.iq.c_cc<=10)
  136.         putc(c, &vs.iq);
  137.     wakeup((caddr_t)&vs.iq);
  138. }
  139.