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