xref: /original-bsd/usr.bin/window/tth19.c (revision 4c01ad61)
1 #ifndef lint
2 static char sccsid[] = "@(#)tth19.c	3.14 04/24/85";
3 #endif
4 
5 /*
6  * Copyright (c) 1983 Regents of the University of California,
7  * All rights reserved.  Redistribution permitted subject to
8  * the terms of the Berkeley Software License Agreement.
9  */
10 
11 #include "ww.h"
12 #include "tt.h"
13 
14 /*
15 kb|h19|heath|h19-b|h19b|heathkit|heath-19|z19|zenith:
16 	cr=^M:nl=^J:bl=^G:al=1*\EL:am:le=^H:bs:cd=\EJ:ce=\EK:
17 	cl=\EE:cm=\EY%+ %+ :co#80:dc=\EN:dl=1*\EM:do=\EB:
18 	ei=\EO:ho=\EH:im=\E@:li#24:mi:nd=\EC:as=\EF:ae=\EG:ms:
19 	ta=^I:pt:sr=\EI:se=\Eq:so=\Ep:up=\EA:vs=\Ex4:ve=\Ey4:
20 	kb=^h:ku=\EA:kd=\EB:kl=\ED:kr=\EC:kh=\EH:
21 	kn#8:k1=\ES:k2=\ET:k3=\EU:k4=\EV:k5=\EW:
22 	l6=blue:l7=red:l8=white:k6=\EP:k7=\EQ:k8=\ER:
23 	es:hs:ts=\Ej\Ex5\Ex1\EY8%+ \Eo:fs=\Ek\Ey5:ds=\Ey1:
24 */
25 
26 #define NCOL	80
27 #define NROW	24
28 
29 #define G (WWM_GRP << WWC_MSHIFT)
30 short h19_frame[16] = {
31 	' ',	'`'|G,	'a'|G,	'e'|G,
32 	'`'|G,	'`'|G,	'f'|G,	'v'|G,
33 	'a'|G,	'd'|G,	'a'|G,	'u'|G,
34 	'c'|G,	't'|G,	's'|G,	'b'|G
35 };
36 
37 extern char *gen_VS;
38 extern char *gen_VE;
39 
40 int h19_msp10c;
41 
42 #define pc(c)	ttputc('c')
43 #define esc()	pc(\033)
44 #define PAD(ms10) { \
45 	register i; \
46 	for (i = ((ms10) + 5) / h19_msp10c; --i >= 0;) \
47 		pc(\0); \
48 }
49 #define ICPAD() PAD((NCOL - tt.tt_col) * 1)	/* 0.1 ms per char */
50 #define ILPAD() PAD((NROW - tt.tt_row) * 10)	/* 1 ms per char */
51 
52 #define h19_setinsert(m) (esc(), (tt.tt_insert = (m)) ? pc(@) : pc(O))
53 
54 h19_setmodes(new)
55 register new;
56 {
57 	register diff;
58 
59 	diff = new ^ tt.tt_modes;
60 	if (diff & WWM_REV) {
61 		esc();
62 		if (new & WWM_REV)
63 			pc(p);
64 		else
65 			pc(q);
66 	}
67 	if (diff & WWM_GRP) {
68 		esc();
69 		if (new & WWM_GRP)
70 			pc(F);
71 		else
72 			pc(G);
73 	}
74 	tt.tt_modes = new;
75 }
76 
77 h19_insline()
78 {
79 	esc();
80 	pc(L);
81 	ILPAD();
82 }
83 
84 h19_delline()
85 {
86 	esc();
87 	pc(M);
88 	ILPAD();
89 }
90 
91 h19_putc(c)
92 register char c;
93 {
94 	if (tt.tt_nmodes != tt.tt_modes)
95 		h19_setmodes(tt.tt_nmodes);
96 	if (tt.tt_ninsert != tt.tt_insert)
97 		h19_setinsert(tt.tt_ninsert);
98 	ttputc(c);
99 	if (tt.tt_insert)
100 		ICPAD();
101 	if (++tt.tt_col == NCOL)
102 		tt.tt_col = NCOL - 1;
103 }
104 
105 h19_write(p, n)
106 register char *p;
107 register n;
108 {
109 	if (tt.tt_nmodes != tt.tt_modes)
110 		h19_setmodes(tt.tt_nmodes);
111 	if (tt.tt_ninsert != tt.tt_insert)
112 		h19_setinsert(tt.tt_ninsert);
113 	if (tt.tt_insert) {
114 		while (--n >= 0) {
115 			ttputc(*p++);
116 			ICPAD();
117 			tt.tt_col++;
118 		}
119 	} else {
120 		tt.tt_col += n;
121 		while (--n >= 0)
122 			ttputc(*p++);
123 	}
124 	if (tt.tt_col == NCOL)
125 		tt.tt_col = NCOL - 1;
126 }
127 
128 h19_move(row, col)
129 register char row, col;
130 {
131 	if (tt.tt_row == row) {
132 		if (tt.tt_col == col)
133 			return;
134 		if (tt.tt_col == col - 1) {
135 			esc();
136 			pc(C);
137 			goto out;
138 		} else if (tt.tt_col == col + 1) {
139 			pc(\b);
140 			goto out;
141 		}
142 	}
143 	if (tt.tt_col == col) {
144 		if (tt.tt_row == row + 1) {
145 			esc();
146 			pc(A);
147 			goto out;
148 		} else if (tt.tt_row == row - 1) {
149 			pc(\n);
150 			goto out;
151 		}
152 	}
153 	if (col == 0 && row == 0) {
154 		esc();
155 		pc(H);
156 		goto out;
157 	}
158 	esc();
159 	pc(Y);
160 	ttputc(' ' + row);
161 	ttputc(' ' + col);
162 out:
163 	tt.tt_col = col;
164 	tt.tt_row = row;
165 }
166 
167 h19_init()
168 {
169 	if (gen_VS)
170 		ttputs(gen_VS);
171 	esc();
172 	pc(w);
173 	esc();
174 	pc(E);
175 	tt.tt_col = tt.tt_row = 0;
176 	tt.tt_ninsert = tt.tt_insert = 0;
177 	tt.tt_nmodes = tt.tt_modes = 0;
178 }
179 
180 h19_end()
181 {
182 	h19_setmodes(0);
183 	h19_setinsert(0);
184 	if (gen_VE)
185 		ttputs(gen_VE);
186 	esc();
187 	pc(v);
188 }
189 
190 h19_clreol()
191 {
192 	esc();
193 	pc(K);
194 }
195 
196 h19_clreos()
197 {
198 	esc();
199 	pc(J);
200 }
201 
202 h19_clear()
203 {
204 	esc();
205 	pc(E);
206 }
207 
208 h19_delchar()
209 {
210 	esc();
211 	pc(N);
212 }
213 
214 tt_h19()
215 {
216 	float cpms = (float) wwbaud / 10000;	/* char per ms */
217 
218 	h19_msp10c = 10 / cpms;			/* ms per 10 char */
219 	gen_VS = ttxgetstr("vs");
220 	gen_VE = ttxgetstr("ve");
221 
222 	tt.tt_init = h19_init;
223 	tt.tt_end = h19_end;
224 
225 	tt.tt_insline = h19_insline;
226 	tt.tt_delline = h19_delline;
227 	tt.tt_delchar = h19_delchar;
228 	tt.tt_clreol = h19_clreol;
229 	tt.tt_clreos = h19_clreos;
230 	tt.tt_clear = h19_clear;
231 	tt.tt_move = h19_move;
232 	tt.tt_write = h19_write;
233 	tt.tt_putc = h19_putc;
234 
235 	tt.tt_ncol = NCOL;
236 	tt.tt_nrow = NROW;
237 	tt.tt_hasinsert = 1;
238 	tt.tt_availmodes = WWM_REV|WWM_GRP;
239 	tt.tt_frame = h19_frame;
240 	return 0;
241 }
242