fix ticket file ownership (look at this again later)
[unix-history] / usr / src / usr.bin / window / tth19.c
CommitLineData
60de5df9 1/*
46e9ea25
KB
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
5e8b0e60
KB
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
60de5df9
EW
16 */
17
46e9ea25 18#ifndef lint
ab8b3b31 19static char sccsid[] = "@(#)tth19.c 3.21 (Berkeley) %G%";
46e9ea25
KB
20#endif /* not lint */
21
6869a338 22#include "ww.h"
e908bfac 23#include "tt.h"
6869a338
EW
24
25/*
26kb|h19|heath|h19-b|h19b|heathkit|heath-19|z19|zenith:
27 cr=^M:nl=^J:bl=^G:al=1*\EL:am:le=^H:bs:cd=\EJ:ce=\EK:
28 cl=\EE:cm=\EY%+ %+ :co#80:dc=\EN:dl=1*\EM:do=\EB:
29 ei=\EO:ho=\EH:im=\E@:li#24:mi:nd=\EC:as=\EF:ae=\EG:ms:
30 ta=^I:pt:sr=\EI:se=\Eq:so=\Ep:up=\EA:vs=\Ex4:ve=\Ey4:
31 kb=^h:ku=\EA:kd=\EB:kl=\ED:kr=\EC:kh=\EH:
32 kn#8:k1=\ES:k2=\ET:k3=\EU:k4=\EV:k5=\EW:
33 l6=blue:l7=red:l8=white:k6=\EP:k7=\EQ:k8=\ER:
34 es:hs:ts=\Ej\Ex5\Ex1\EY8%+ \Eo:fs=\Ek\Ey5:ds=\Ey1:
35*/
36
3130283e
EW
37#define NCOL 80
38#define NROW 24
39
a830e8bb
EW
40#define G (WWM_GRP << WWC_MSHIFT)
41short h19_frame[16] = {
42 ' ', '`'|G, 'a'|G, 'e'|G,
43 '`'|G, '`'|G, 'f'|G, 'v'|G,
44 'a'|G, 'd'|G, 'a'|G, 'u'|G,
45 'c'|G, 't'|G, 's'|G, 'b'|G
6869a338
EW
46};
47
e1daf7d6
EW
48extern struct tt_str *gen_VS;
49extern struct tt_str *gen_VE;
3130283e 50
a830e8bb 51int h19_msp10c;
6869a338 52
2d152f42
EW
53#define pc(c) ttputc(c)
54#define esc() pc('\033')
6869a338
EW
55#define PAD(ms10) { \
56 register i; \
57 for (i = ((ms10) + 5) / h19_msp10c; --i >= 0;) \
2d152f42 58 pc('\0'); \
6869a338 59}
3130283e
EW
60#define ICPAD() PAD((NCOL - tt.tt_col) * 1) /* 0.1 ms per char */
61#define ILPAD() PAD((NROW - tt.tt_row) * 10) /* 1 ms per char */
6869a338 62
2d152f42 63#define H19_SETINSERT(m) (esc(), (tt.tt_insert = (m)) ? pc('@') : pc('O'))
c1a57462
EW
64
65h19_setinsert(new)
66{
67 H19_SETINSERT(new);
68}
a830e8bb
EW
69
70h19_setmodes(new)
71register new;
72{
73 register diff;
74
75 diff = new ^ tt.tt_modes;
76 if (diff & WWM_REV) {
77 esc();
78 if (new & WWM_REV)
2d152f42 79 pc('p');
a830e8bb 80 else
2d152f42 81 pc('q');
a830e8bb
EW
82 }
83 if (diff & WWM_GRP) {
84 esc();
85 if (new & WWM_GRP)
2d152f42 86 pc('F');
a830e8bb 87 else
2d152f42 88 pc('G');
a830e8bb
EW
89 }
90 tt.tt_modes = new;
91}
6869a338 92
2d152f42 93h19_insline(n)
6869a338 94{
2d152f42
EW
95 while (--n >= 0) {
96 esc();
97 pc('L');
98 ILPAD();
99 }
6869a338
EW
100}
101
2d152f42 102h19_delline(n)
6869a338 103{
2d152f42
EW
104 while (--n >= 0) {
105 esc();
106 pc('M');
107 ILPAD();
108 }
6869a338
EW
109}
110
111h19_putc(c)
112register char c;
113{
a830e8bb 114 if (tt.tt_nmodes != tt.tt_modes)
c1a57462 115 (*tt.tt_setmodes)(tt.tt_nmodes);
a830e8bb 116 if (tt.tt_ninsert != tt.tt_insert)
c1a57462 117 H19_SETINSERT(tt.tt_ninsert);
2d152f42 118 pc(c);
3130283e 119 if (tt.tt_insert)
6869a338 120 ICPAD();
3130283e
EW
121 if (++tt.tt_col == NCOL)
122 tt.tt_col = NCOL - 1;
6869a338
EW
123}
124
3130283e
EW
125h19_write(p, n)
126register char *p;
127register n;
6869a338 128{
a830e8bb 129 if (tt.tt_nmodes != tt.tt_modes)
c1a57462 130 (*tt.tt_setmodes)(tt.tt_nmodes);
a830e8bb 131 if (tt.tt_ninsert != tt.tt_insert)
c1a57462 132 H19_SETINSERT(tt.tt_ninsert);
3130283e
EW
133 if (tt.tt_insert) {
134 while (--n >= 0) {
2d152f42 135 pc(*p++);
6869a338 136 ICPAD();
3130283e 137 tt.tt_col++;
6869a338
EW
138 }
139 } else {
3130283e 140 tt.tt_col += n;
e1daf7d6 141 ttwrite(p, n);
6869a338 142 }
3130283e
EW
143 if (tt.tt_col == NCOL)
144 tt.tt_col = NCOL - 1;
6869a338
EW
145}
146
147h19_move(row, col)
148register char row, col;
149{
3130283e
EW
150 if (tt.tt_row == row) {
151 if (tt.tt_col == col)
6869a338 152 return;
16ea9636 153 if (col == 0) {
2d152f42 154 pc('\r');
16ea9636
EW
155 goto out;
156 }
3130283e 157 if (tt.tt_col == col - 1) {
6869a338 158 esc();
2d152f42 159 pc('C');
6869a338 160 goto out;
16ea9636
EW
161 }
162 if (tt.tt_col == col + 1) {
2d152f42 163 pc('\b');
6869a338
EW
164 goto out;
165 }
166 }
3130283e
EW
167 if (tt.tt_col == col) {
168 if (tt.tt_row == row + 1) {
6869a338 169 esc();
2d152f42 170 pc('A');
6869a338 171 goto out;
16ea9636
EW
172 }
173 if (tt.tt_row == row - 1) {
2d152f42 174 pc('\n');
6869a338
EW
175 goto out;
176 }
177 }
7aefc9fe 178 if (col == 0 && row == 0) {
6869a338 179 esc();
2d152f42 180 pc('H');
6869a338
EW
181 goto out;
182 }
183 esc();
2d152f42
EW
184 pc('Y');
185 pc(' ' + row);
186 pc(' ' + col);
6869a338 187out:
3130283e
EW
188 tt.tt_col = col;
189 tt.tt_row = row;
6869a338
EW
190}
191
ab8b3b31 192h19_start()
6869a338 193{
3130283e 194 if (gen_VS)
e1daf7d6 195 ttxputs(gen_VS);
6869a338 196 esc();
2d152f42 197 pc('w');
6869a338 198 esc();
2d152f42 199 pc('E');
3130283e
EW
200 tt.tt_col = tt.tt_row = 0;
201 tt.tt_ninsert = tt.tt_insert = 0;
202 tt.tt_nmodes = tt.tt_modes = 0;
6869a338
EW
203}
204
e908bfac 205h19_end()
6869a338 206{
3130283e 207 if (gen_VE)
e1daf7d6 208 ttxputs(gen_VE);
6869a338 209 esc();
2d152f42 210 pc('v');
6869a338
EW
211}
212
213h19_clreol()
214{
215 esc();
2d152f42 216 pc('K');
6869a338
EW
217}
218
219h19_clreos()
220{
221 esc();
2d152f42 222 pc('J');
6869a338
EW
223}
224
225h19_clear()
226{
227 esc();
2d152f42 228 pc('E');
6869a338
EW
229}
230
2d152f42 231h19_delchar(n)
6869a338 232{
2d152f42
EW
233 while (--n >= 0) {
234 esc();
235 pc('N');
236 }
6869a338
EW
237}
238
2d152f42 239h19_scroll_down(n)
16ea9636
EW
240{
241 h19_move(NROW - 1, 0);
2d152f42
EW
242 while (--n >= 0)
243 pc('\n');
16ea9636
EW
244}
245
2d152f42 246h19_scroll_up(n)
16ea9636
EW
247{
248 h19_move(0, 0);
2d152f42
EW
249 while (--n >= 0) {
250 esc();
251 pc('I');
252 }
16ea9636
EW
253}
254
6869a338
EW
255tt_h19()
256{
e908bfac
EW
257 float cpms = (float) wwbaud / 10000; /* char per ms */
258
259 h19_msp10c = 10 / cpms; /* ms per 10 char */
b1189050
EW
260 gen_VS = ttxgetstr("vs");
261 gen_VE = ttxgetstr("ve");
3130283e 262
ab8b3b31 263 tt.tt_start = h19_start;
3130283e
EW
264 tt.tt_end = h19_end;
265
6869a338
EW
266 tt.tt_insline = h19_insline;
267 tt.tt_delline = h19_delline;
268 tt.tt_delchar = h19_delchar;
6869a338
EW
269 tt.tt_clreol = h19_clreol;
270 tt.tt_clreos = h19_clreos;
271 tt.tt_clear = h19_clear;
272 tt.tt_move = h19_move;
6869a338
EW
273 tt.tt_write = h19_write;
274 tt.tt_putc = h19_putc;
16ea9636
EW
275 tt.tt_scroll_down = h19_scroll_down;
276 tt.tt_scroll_up = h19_scroll_up;
c1a57462
EW
277 tt.tt_setinsert = h19_setinsert;
278 tt.tt_setmodes = h19_setmodes;
3130283e
EW
279
280 tt.tt_ncol = NCOL;
281 tt.tt_nrow = NROW;
a830e8bb 282 tt.tt_availmodes = WWM_REV|WWM_GRP;
6869a338
EW
283 tt.tt_frame = h19_frame;
284 return 0;
285}