Commit | Line | Data |
---|---|---|
9d8a6612 DR |
1 | # |
2 | /* | |
3 | * Copyright 1973 Bell Telephone Laboratories Inc | |
4 | */ | |
5 | ||
6 | /* | |
7 | * LP-11 Line printer driver | |
8 | */ | |
9 | ||
10 | #include "../param.h" | |
11 | #include "../conf.h" | |
12 | #include "../user.h" | |
13 | ||
14 | #define LPADDR 0177514 | |
15 | ||
16 | #define IENABLE 0100 | |
17 | #define DONE 0200 | |
18 | ||
19 | #define LPPRI 10 | |
20 | #define LPLWAT 50 | |
21 | #define LPHWAT 100 | |
22 | #define EJLINE 60 | |
23 | #define MAXCOL 80 | |
24 | ||
25 | struct { | |
26 | int lpsr; | |
27 | int lpbuf; | |
28 | }; | |
29 | ||
30 | struct { | |
31 | int cc; | |
32 | int cf; | |
33 | int cl; | |
34 | int flag; | |
35 | int mcc; | |
36 | int ccc; | |
37 | int mlc; | |
38 | } lp11; | |
39 | ||
40 | #define CAP 01 | |
41 | #define EJECT 02 | |
42 | #define OPEN 04 | |
43 | ||
44 | #define FORM 014 | |
45 | ||
46 | lpopen(dev, flag) | |
47 | { | |
48 | ||
49 | if(lp11.flag & OPEN || LPADDR->lpsr < 0) { | |
50 | u.u_error = EIO; | |
51 | return; | |
52 | } | |
53 | lp11.flag =| (CAP|EJECT|OPEN); | |
54 | LPADDR->lpsr =| IENABLE; | |
55 | lpcanon(FORM); | |
56 | } | |
57 | ||
58 | lpclose(dev, flag) | |
59 | { | |
60 | lpcanon(FORM); | |
61 | lp11.flag = 0; | |
62 | } | |
63 | ||
64 | lpwrite() | |
65 | { | |
66 | register int c; | |
67 | ||
68 | while ((c=cpass())>=0) | |
69 | lpcanon(c); | |
70 | } | |
71 | ||
72 | lpcanon(c) | |
73 | { | |
74 | register c1, c2; | |
75 | ||
76 | c1 = c; | |
77 | if(lp11.flag&CAP) { | |
78 | if(c1>='a' && c1<='z') | |
79 | c1 =+ 'A'-'a'; else | |
80 | switch(c1) { | |
81 | ||
82 | case '{': | |
83 | c2 = '('; | |
84 | goto esc; | |
85 | ||
86 | case '}': | |
87 | c2 = ')'; | |
88 | goto esc; | |
89 | ||
90 | case '`': | |
91 | c2 = '\''; | |
92 | goto esc; | |
93 | ||
94 | case '|': | |
95 | c2 = '!'; | |
96 | goto esc; | |
97 | ||
98 | case '~': | |
99 | c2 = '^'; | |
100 | ||
101 | esc: | |
102 | lpcanon(c2); | |
103 | lp11.ccc--; | |
104 | c1 = '-'; | |
105 | } | |
106 | } | |
107 | ||
108 | switch(c1) { | |
109 | ||
110 | case '\t': | |
111 | lp11.ccc = (lp11.ccc+8) & ~7; | |
112 | return; | |
113 | ||
114 | case FORM: | |
115 | case '\n': | |
116 | if((lp11.flag&EJECT) == 0 || | |
117 | lp11.mcc!=0 || lp11.mlc!=0) { | |
118 | lp11.mcc = 0; | |
119 | lp11.mlc++; | |
120 | if(lp11.mlc >= EJLINE && lp11.flag&EJECT) | |
121 | c1 = FORM; | |
122 | lpoutput(c1); | |
123 | if(c1 == FORM) | |
124 | lp11.mlc = 0; | |
125 | } | |
126 | ||
127 | case '\r': | |
128 | lp11.ccc = 0; | |
129 | return; | |
130 | ||
131 | case 010: | |
132 | if(lp11.ccc > 0) | |
133 | lp11.ccc--; | |
134 | return; | |
135 | ||
136 | case ' ': | |
137 | lp11.ccc++; | |
138 | return; | |
139 | ||
140 | default: | |
141 | if(lp11.ccc < lp11.mcc) { | |
142 | lpoutput('\r'); | |
143 | lp11.mcc = 0; | |
144 | } | |
145 | if(lp11.ccc < MAXCOL) { | |
146 | while(lp11.ccc > lp11.mcc) { | |
147 | lpoutput(' '); | |
148 | lp11.mcc++; | |
149 | } | |
150 | lpoutput(c1); | |
151 | lp11.mcc++; | |
152 | } | |
153 | lp11.ccc++; | |
154 | } | |
155 | } | |
156 | ||
157 | lpstart() | |
158 | { | |
159 | register int c; | |
160 | ||
161 | while (LPADDR->lpsr&DONE && (c = getc(&lp11)) >= 0) | |
162 | LPADDR->lpbuf = c; | |
163 | } | |
164 | ||
165 | lpint() | |
166 | { | |
167 | register int c; | |
168 | ||
169 | lpstart(); | |
170 | if (lp11.cc == LPLWAT || lp11.cc == 0) | |
171 | wakeup(&lp11); | |
172 | } | |
173 | ||
174 | lpoutput(c) | |
175 | { | |
176 | if (lp11.cc >= LPHWAT) | |
177 | sleep(&lp11, LPPRI); | |
178 | putc(c, &lp11); | |
179 | spl4(); | |
180 | lpstart(); | |
181 | spl0(); | |
182 | } |