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