|
|
1.1 ! root 1: From IngVAX:eric Sun Nov 2 16:10:46 1980 ! 2: To: v:bill ! 3: Subject: hacked up lp driver ! 4: ! 5: You should probably test this, I haven't had a chance.... ! 6: ! 7: ---- lp.c ! 8: /* ! 9: * Line printer driver ! 10: */ ! 11: ! 12: #include "../h/param.h" ! 13: #include "../h/dir.h" ! 14: #include "../h/user.h" ! 15: #include "../h/tty.h" ! 16: #include "../h/uba.h" ! 17: ! 18: struct device *lp_addr[] = { (struct device *)(UBA0_DEV+0177514) }; ! 19: ! 20: #define LPPRI PZERO+10 ! 21: #define LPLOWAT 50 ! 22: #define LPHIWAT 100 ! 23: #define LPMAX 2 ! 24: ! 25: struct device { ! 26: short lpcsr, lpbuf; ! 27: }; ! 28: int lp_cnt = 1; ! 29: ! 30: struct lp { ! 31: struct clist l_outq; ! 32: char flag, ind; ! 33: short ccc, mcc, mlc; ! 34: short line, col; ! 35: } lp_dt[LPMAX]; ! 36: ! 37: #define OPEN 010 ! 38: #define CAP 020 ! 39: #define NOCR 040 ! 40: #define ASLP 0100 ! 41: ! 42: #define FORM 014 ! 43: ! 44: lpopen(dev, flag) ! 45: { ! 46: register unit; ! 47: register struct lp *lp; ! 48: ! 49: unit = dev&07; ! 50: if (unit >= lp_cnt || unit >= LPMAX || ! 51: (lp = &lp_dt[unit])->flag || lp_addr[unit]->lpcsr <0 ) { ! 52: u.u_error = EIO; ! 53: return; ! 54: } ! 55: lp->flag = (dev&077)|OPEN; ! 56: lp->ind = 4; ! 57: lp->col = 80; ! 58: lp->line = 66; ! 59: lpoutput(unit, FORM); ! 60: } ! 61: ! 62: lpclose(dev) ! 63: { ! 64: register unit; ! 65: ! 66: unit = dev&07; ! 67: lpoutput(unit, FORM); ! 68: lp_dt[unit].flag = 0; ! 69: } ! 70: ! 71: lpwrite(dev) ! 72: { ! 73: register c; ! 74: ! 75: while ((c=cpass())>=0) ! 76: lpoutput(dev&07, c); ! 77: } ! 78: ! 79: lpoutput(dev, c) ! 80: register dev, c; ! 81: { ! 82: register struct lp *lp; ! 83: ! 84: lp = &lp_dt[dev]; ! 85: if(lp->flag&CAP) { ! 86: if(c>='a' && c<='z') ! 87: c += 'A'-'a'; else ! 88: switch(c) { ! 89: case '{': ! 90: c = '('; ! 91: goto esc; ! 92: case '}': ! 93: c = ')'; ! 94: goto esc; ! 95: case '`': ! 96: c = '\''; ! 97: goto esc; ! 98: case '|': ! 99: c = '!'; ! 100: goto esc; ! 101: case '~': ! 102: c = '^'; ! 103: esc: ! 104: lpoutput(dev, c); ! 105: lp->ccc--; ! 106: c = '-'; ! 107: } ! 108: } ! 109: switch(c) { ! 110: case '\t': ! 111: lp->ccc = ((lp->ccc+8-lp->ind) & ~7) + lp->ind; ! 112: return; ! 113: case '\n': ! 114: lp->mlc++; ! 115: if(lp->mlc >= lp->line ) ! 116: c = FORM; ! 117: case FORM: ! 118: lp->mcc = 0; ! 119: if (lp->mlc) { ! 120: lpputc(dev, c); ! 121: if(c == FORM) ! 122: lp->mlc = 0; ! 123: } ! 124: case '\r': ! 125: lp->ccc = lp->ind; ! 126: return; ! 127: case 010: ! 128: if(lp->ccc > lp->ind) ! 129: lp->ccc--; ! 130: return; ! 131: case ' ': ! 132: lp->ccc++; ! 133: return; ! 134: default: ! 135: if(lp->ccc < lp->mcc) { ! 136: if (lp->flag&NOCR) { ! 137: lp->ccc++; ! 138: return; ! 139: } ! 140: lpputc(dev, '\r'); ! 141: lp->mcc = 0; ! 142: } ! 143: if(lp->ccc < lp->col) { ! 144: while(lp->ccc > lp->mcc) { ! 145: lpputc(dev, ' '); ! 146: lp->mcc++; ! 147: } ! 148: lpputc(dev, c); ! 149: lp->mcc++; ! 150: } ! 151: lp->ccc++; ! 152: } ! 153: } ! 154: ! 155: lpputc(dev, c) ! 156: register dev, c; ! 157: { ! 158: register struct lp *lp; ! 159: ! 160: lp = &lp_dt[dev]; ! 161: spl4(); ! 162: while (lp->l_outq.c_cc > LPHIWAT) { ! 163: lp->flag |= ASLP; ! 164: sleep(lp, LPPRI); ! 165: } ! 166: putc(c, &lp->l_outq); ! 167: lpintr(dev); ! 168: spl0(); ! 169: } ! 170: ! 171: lpintr(dev) ! 172: register dev; ! 173: { ! 174: register struct lp *lp; ! 175: register c; ! 176: ! 177: lp_addr[dev]->lpcsr &= ~IENABLE; ! 178: lp = &lp_dt[dev]; ! 179: while (lp_addr[dev]->lpcsr&DONE && (c = getc(&lp->l_outq)) >= 0) ! 180: lp_addr[dev]->lpbuf = c; ! 181: if (lp->l_outq.c_cc <= LPLOWAT && lp->flag&ASLP) { ! 182: lp->flag &= ~ASLP; ! 183: wakeup(lp); ! 184: } ! 185: if (lp->l_outq.c_cc > 0) ! 186: lp_addr[dev]->lpcsr |= IENABLE; ! 187: } ! 188: ! 189: lpioctl(dev, cmd, addr, flag) ! 190: register caddr_t addr; ! 191: { ! 192: register int m; ! 193: struct lp *lp; ! 194: struct {char lsg_flag, lsg_ind; short lsg_line, lsg_col;} lpios; ! 195: ! 196: lp = &lp_dt[dev]; ! 197: switch (cmd) { ! 198: ! 199: case ('v'<<8)+0: ! 200: lpios.lsg_flag = lp->flag; ! 201: lpios.lsg_ind = lp->ind; ! 202: lpios.lsg_line = lp->line; ! 203: lpios.lsg_col = lp->col; ! 204: copyout(&lpios, addr, sizeof lpios); ! 205: return; ! 206: ! 207: case ('v'<<8)+1: ! 208: m = copyin(addr, &lpios, sizeof lpios); ! 209: if (m == -1) { ! 210: u.u_error = EFAULT; ! 211: return; ! 212: } ! 213: lp->flag = lpios.lsg_flag; ! 214: lp->ind = lpios.lsg_ind; ! 215: lp->line = lpios.lsg_line; ! 216: lp->col = lpios.lsg_col; ! 217: return; ! 218: ! 219: default: ! 220: u.u_error = ENOTTY; ! 221: return; ! 222: } ! 223: } ! 224: ! 225: ---- END ! 226:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.