8800: #
8801: /*
8802:  */
8803: 
8804: /*
8805:  * LP-11 Line printer driver
8806:  */
8807: 
8808: #include "../param.h"
8809: #include "../conf.h"
8810: #include "../user.h"
8811: 
8812: #define LPADDR  0177514
8813: 
8814: #define IENABLE 0100
8815: #define DONE    0200
8816: 
8817: #define LPPRI   10
8818: #define LPLWAT  50
8819: #define LPHWAT  100
8820: #define EJLINE  60
8821: #define MAXCOL  80
8822: 
8823: struct {
8824:         int lpsr;
8825:         int lpbuf;
8826: };
8827: /* ---------------------------       */
8828: 
8829: struct  {
8830:         int     cc;
8831:         int     cf;
8832:         int     cl;
8833:         int     flag;
8834:         int     mcc;
8835:         int     ccc;
8836:         int     mlc;
8837: } lp11;
8838: /* ---------------------------       */
8839: 
8840: #define CAP     01              /* Set to 0 for 96-char printer, else to 01 */
8841: 
8842: #define EJECT   02
8843: #define OPEN    04
8844: #define IND     010             /* Set to 0 for no indent, else to 010 */
8845: 
8846: 
8847: #define FORM    014
8848: 
8849: 
8850: lpopen(dev, flag)
8851: {
8852: 
8853:         if(lp11.flag & OPEN || LPADDR->lpsr < 0) {
8854:                 u.u_error = EIO;
8855:                 return;
8856:         }
8857:         lp11.flag =| (IND|EJECT|OPEN);
8858:         LPADDR->lpsr =| IENABLE;
8859:         lpcanon(FORM);
8860: }
8861: /* ---------------------------       */
8862: 
8863: lpclose(dev, flag)
8864: {
8865:         lpcanon(FORM);
8866:         lp11.flag = 0;
8867: }
8868: /* ---------------------------       */
8869: 
8870: lpwrite()
8871: {
8872:         register int c;
8873: 
8874:         while ((c=cpass())>=0)
8875:                 lpcanon(c);
8876: }
8877: /* ---------------------------       */
8878: 
8879: lpcanon(c)
8880: {
8881:         register c1, c2;
8882: 
8883:         c1 = c;
8884:         if(lp11.flag&CAP) {
8885:                 if(c1>='a' && c1<='z')
8886:                         c1 =+ 'A'-'a'; else
8887:                 switch(c1) {
8888: 
8889:                 case '{':
8890:                         c2 = '(';
8891:                         goto esc;
8892: 
8893:                 case '}':
8894:                         c2 = ')';
8895:                         goto esc;
8896: 
8897:                 case '`':
8898:                         c2 = '\'';
8899:                         goto esc;
8900: 
8901:                 case '|':
8902:                         c2 = '!';
8903:                         goto esc;
8904: 
8905:                 case '~':
8906:                         c2 = '^';
8907: 
8908:                 esc:
8909:                         lpcanon(c2);
8910:                         lp11.ccc--;
8911:                         c1 = '-';
8912:                 }
8913:         }
8914: 
8915:         switch(c1) {
8916: 
8917:         case '\t':
8918:                 lp11.ccc = (lp11.ccc+8) & ~7;
8919:                 return;
8920: 
8921:         case FORM:
8922:         case '\n':
8923:                 if((lp11.flag&EJECT) == 0 ||
8924:                    lp11.mcc!=0 || lp11.mlc!=0) {
8925:                         lp11.mcc = 0;
8926:                         lp11.mlc++;
8927:                         if(lp11.mlc >= EJLINE && lp11.flag&EJECT)
8928:                                 c1 = FORM;
8929:                         lpoutput(c1);
8930:                         if(c1 == FORM)
8931:                                 lp11.mlc = 0;
8932:                 }
8933: 
8934:         case '\r':
8935:                 lp11.ccc = 0;
8936:                 if(lp11.flag&IND)
8937:                         lp11.ccc = 8;
8938:                 return;
8939: 
8940:         case 010:
8941:                 if(lp11.ccc > 0)
8942:                         lp11.ccc--;
8943:                 return;
8944: 
8945:         case ' ':
8946:                 lp11.ccc++;
8947:                 return;
8948: 
8949:         default:
8950:                 if(lp11.ccc < lp11.mcc) {
8951:                         lpoutput('\r');
8952:                         lp11.mcc = 0;
8953:                 }
8954:                 if(lp11.ccc < MAXCOL) {
8955:                         while(lp11.ccc > lp11.mcc) {
8956:                                 lpoutput(' ');
8957:                                 lp11.mcc++;
8958:                         }
8959:                         lpoutput(c1);
8960:                         lp11.mcc++;
8961:                 }
8962:                 lp11.ccc++;
8963:         }
8964: }
8965: /* ---------------------------       */
8966: 
8967: lpstart()
8968: {
8969:         register int c;
8970: 
8971:         while (LPADDR->lpsr&DONE && (c = getc(&lp11)) >= 0)
8972:                 LPADDR->lpbuf = c;
8973: }
8974: /* ---------------------------       */
8975: 
8976: lpint()
8977: {
8978:         register int c;
8979: 
8980:         lpstart();
8981:         if (lp11.cc == LPLWAT || lp11.cc == 0)
8982:                 wakeup(&lp11);
8983: }
8984: /* ---------------------------       */
8985: 
8986: lpoutput(c)
8987: {
8988:         if (lp11.cc >= LPHWAT)
8989:                 sleep(&lp11, LPPRI);
8990:         putc(c, &lp11);
8991:         spl4();
8992:         lpstart();
8993:         spl0();
8994: }
8995: /* ---------------------------       */