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