xref: /original-bsd/usr.bin/window/tth19.c (revision 2ce9ec30)
1 /*
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.
11  */
12 
13 #ifndef lint
14 static char sccsid[] = "@(#)tth19.c	3.18 (Berkeley) 05/11/88";
15 #endif /* not lint */
16 
17 #include "ww.h"
18 #include "tt.h"
19 
20 /*
21 kb|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 
32 #define NCOL	80
33 #define NROW	24
34 
35 #define G (WWM_GRP << WWC_MSHIFT)
36 short 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
41 };
42 
43 extern struct tt_str *gen_VS;
44 extern struct tt_str *gen_VE;
45 
46 int h19_msp10c;
47 
48 #define pc(c)	ttputc('c')
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 }
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 */
57 
58 #define H19_SETINSERT(m) (esc(), (tt.tt_insert = (m)) ? pc(@) : pc(O))
59 
60 h19_setinsert(new)
61 {
62 	H19_SETINSERT(new);
63 }
64 
65 h19_setmodes(new)
66 register 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 }
87 
88 h19_insline()
89 {
90 	esc();
91 	pc(L);
92 	ILPAD();
93 }
94 
95 h19_delline()
96 {
97 	esc();
98 	pc(M);
99 	ILPAD();
100 }
101 
102 h19_putc(c)
103 register char c;
104 {
105 	if (tt.tt_nmodes != tt.tt_modes)
106 		(*tt.tt_setmodes)(tt.tt_nmodes);
107 	if (tt.tt_ninsert != tt.tt_insert)
108 		H19_SETINSERT(tt.tt_ninsert);
109 	ttputc(c);
110 	if (tt.tt_insert)
111 		ICPAD();
112 	if (++tt.tt_col == NCOL)
113 		tt.tt_col = NCOL - 1;
114 }
115 
116 h19_write(p, n)
117 register char *p;
118 register n;
119 {
120 	if (tt.tt_nmodes != tt.tt_modes)
121 		(*tt.tt_setmodes)(tt.tt_nmodes);
122 	if (tt.tt_ninsert != tt.tt_insert)
123 		H19_SETINSERT(tt.tt_ninsert);
124 	if (tt.tt_insert) {
125 		while (--n >= 0) {
126 			ttputc(*p++);
127 			ICPAD();
128 			tt.tt_col++;
129 		}
130 	} else {
131 		tt.tt_col += n;
132 		ttwrite(p, n);
133 	}
134 	if (tt.tt_col == NCOL)
135 		tt.tt_col = NCOL - 1;
136 }
137 
138 h19_move(row, col)
139 register char row, col;
140 {
141 	if (tt.tt_row == row) {
142 		if (tt.tt_col == col)
143 			return;
144 		if (col == 0) {
145 			pc(\r);
146 			goto out;
147 		}
148 		if (tt.tt_col == col - 1) {
149 			esc();
150 			pc(C);
151 			goto out;
152 		}
153 		if (tt.tt_col == col + 1) {
154 			pc(\b);
155 			goto out;
156 		}
157 	}
158 	if (tt.tt_col == col) {
159 		if (tt.tt_row == row + 1) {
160 			esc();
161 			pc(A);
162 			goto out;
163 		}
164 		if (tt.tt_row == row - 1) {
165 			pc(\n);
166 			goto out;
167 		}
168 	}
169 	if (col == 0 && row == 0) {
170 		esc();
171 		pc(H);
172 		goto out;
173 	}
174 	esc();
175 	pc(Y);
176 	ttputc(' ' + row);
177 	ttputc(' ' + col);
178 out:
179 	tt.tt_col = col;
180 	tt.tt_row = row;
181 }
182 
183 h19_init()
184 {
185 	if (gen_VS)
186 		ttxputs(gen_VS);
187 	esc();
188 	pc(w);
189 	esc();
190 	pc(E);
191 	tt.tt_col = tt.tt_row = 0;
192 	tt.tt_ninsert = tt.tt_insert = 0;
193 	tt.tt_nmodes = tt.tt_modes = 0;
194 }
195 
196 h19_end()
197 {
198 	if (gen_VE)
199 		ttxputs(gen_VE);
200 	esc();
201 	pc(v);
202 }
203 
204 h19_clreol()
205 {
206 	esc();
207 	pc(K);
208 }
209 
210 h19_clreos()
211 {
212 	esc();
213 	pc(J);
214 }
215 
216 h19_clear()
217 {
218 	esc();
219 	pc(E);
220 }
221 
222 h19_delchar()
223 {
224 	esc();
225 	pc(N);
226 }
227 
228 h19_scroll_down()
229 {
230 	h19_move(NROW - 1, 0);
231 	pc(\n);
232 }
233 
234 h19_scroll_up()
235 {
236 	h19_move(0, 0);
237 	esc();
238 	pc(I);
239 }
240 
241 tt_h19()
242 {
243 	float cpms = (float) wwbaud / 10000;	/* char per ms */
244 
245 	h19_msp10c = 10 / cpms;			/* ms per 10 char */
246 	gen_VS = ttxgetstr("vs");
247 	gen_VE = ttxgetstr("ve");
248 
249 	tt.tt_init = h19_init;
250 	tt.tt_end = h19_end;
251 
252 	tt.tt_insline = h19_insline;
253 	tt.tt_delline = h19_delline;
254 	tt.tt_delchar = h19_delchar;
255 	tt.tt_clreol = h19_clreol;
256 	tt.tt_clreos = h19_clreos;
257 	tt.tt_clear = h19_clear;
258 	tt.tt_move = h19_move;
259 	tt.tt_write = h19_write;
260 	tt.tt_putc = h19_putc;
261 	tt.tt_scroll_down = h19_scroll_down;
262 	tt.tt_scroll_up = h19_scroll_up;
263 	tt.tt_setinsert = h19_setinsert;
264 	tt.tt_setmodes = h19_setmodes;
265 
266 	tt.tt_ncol = NCOL;
267 	tt.tt_nrow = NROW;
268 	tt.tt_hasinsert = 1;
269 	tt.tt_availmodes = WWM_REV|WWM_GRP;
270 	tt.tt_frame = h19_frame;
271 	return 0;
272 }
273