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