insert mode bug fix and cleanup
[unix-history] / usr / src / usr.bin / window / tth19.c
CommitLineData
60de5df9 1/*
46e9ea25
KB
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
5e8b0e60
KB
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
60de5df9
EW
16 */
17
46e9ea25 18#ifndef lint
d9375810 19static char sccsid[] = "@(#)tth19.c 3.22 (Berkeley) %G%";
46e9ea25
KB
20#endif /* not lint */
21
6869a338 22#include "ww.h"
e908bfac 23#include "tt.h"
6869a338
EW
24
25/*
26kb|h19|heath|h19-b|h19b|heathkit|heath-19|z19|zenith:
27 cr=^M:nl=^J:bl=^G:al=1*\EL:am:le=^H:bs:cd=\EJ:ce=\EK:
28 cl=\EE:cm=\EY%+ %+ :co#80:dc=\EN:dl=1*\EM:do=\EB:
29 ei=\EO:ho=\EH:im=\E@:li#24:mi:nd=\EC:as=\EF:ae=\EG:ms:
30 ta=^I:pt:sr=\EI:se=\Eq:so=\Ep:up=\EA:vs=\Ex4:ve=\Ey4:
31 kb=^h:ku=\EA:kd=\EB:kl=\ED:kr=\EC:kh=\EH:
32 kn#8:k1=\ES:k2=\ET:k3=\EU:k4=\EV:k5=\EW:
33 l6=blue:l7=red:l8=white:k6=\EP:k7=\EQ:k8=\ER:
34 es:hs:ts=\Ej\Ex5\Ex1\EY8%+ \Eo:fs=\Ek\Ey5:ds=\Ey1:
35*/
36
3130283e
EW
37#define NCOL 80
38#define NROW 24
39
a830e8bb
EW
40#define G (WWM_GRP << WWC_MSHIFT)
41short h19_frame[16] = {
42 ' ', '`'|G, 'a'|G, 'e'|G,
43 '`'|G, '`'|G, 'f'|G, 'v'|G,
44 'a'|G, 'd'|G, 'a'|G, 'u'|G,
45 'c'|G, 't'|G, 's'|G, 'b'|G
6869a338
EW
46};
47
e1daf7d6
EW
48extern struct tt_str *gen_VS;
49extern struct tt_str *gen_VE;
3130283e 50
a830e8bb 51int h19_msp10c;
6869a338 52
2d152f42
EW
53#define pc(c) ttputc(c)
54#define esc() pc('\033')
6869a338
EW
55#define PAD(ms10) { \
56 register i; \
57 for (i = ((ms10) + 5) / h19_msp10c; --i >= 0;) \
2d152f42 58 pc('\0'); \
6869a338 59}
3130283e
EW
60#define ICPAD() PAD((NCOL - tt.tt_col) * 1) /* 0.1 ms per char */
61#define ILPAD() PAD((NROW - tt.tt_row) * 10) /* 1 ms per char */
6869a338 62
2d152f42 63#define H19_SETINSERT(m) (esc(), (tt.tt_insert = (m)) ? pc('@') : pc('O'))
c1a57462 64
a830e8bb
EW
65h19_setmodes(new)
66register new;
67{
68 register diff;
69
70 diff = new ^ tt.tt_modes;
71 if (diff & WWM_REV) {
72 esc();
73 if (new & WWM_REV)
2d152f42 74 pc('p');
a830e8bb 75 else
2d152f42 76 pc('q');
a830e8bb
EW
77 }
78 if (diff & WWM_GRP) {
79 esc();
80 if (new & WWM_GRP)
2d152f42 81 pc('F');
a830e8bb 82 else
2d152f42 83 pc('G');
a830e8bb
EW
84 }
85 tt.tt_modes = new;
86}
6869a338 87
2d152f42 88h19_insline(n)
6869a338 89{
2d152f42
EW
90 while (--n >= 0) {
91 esc();
92 pc('L');
93 ILPAD();
94 }
6869a338
EW
95}
96
2d152f42 97h19_delline(n)
6869a338 98{
2d152f42
EW
99 while (--n >= 0) {
100 esc();
101 pc('M');
102 ILPAD();
103 }
6869a338
EW
104}
105
106h19_putc(c)
107register char c;
108{
a830e8bb 109 if (tt.tt_nmodes != tt.tt_modes)
c1a57462 110 (*tt.tt_setmodes)(tt.tt_nmodes);
3130283e 111 if (tt.tt_insert)
d9375810
EW
112 H19_SETINSERT(0);
113 pc(c);
3130283e
EW
114 if (++tt.tt_col == NCOL)
115 tt.tt_col = NCOL - 1;
6869a338
EW
116}
117
3130283e
EW
118h19_write(p, n)
119register char *p;
120register n;
6869a338 121{
a830e8bb 122 if (tt.tt_nmodes != tt.tt_modes)
c1a57462 123 (*tt.tt_setmodes)(tt.tt_nmodes);
d9375810
EW
124 if (tt.tt_insert)
125 H19_SETINSERT(0);
126 ttwrite(p, n);
127 tt.tt_col += n;
3130283e
EW
128 if (tt.tt_col == NCOL)
129 tt.tt_col = NCOL - 1;
6869a338
EW
130}
131
132h19_move(row, col)
133register char row, col;
134{
3130283e
EW
135 if (tt.tt_row == row) {
136 if (tt.tt_col == col)
6869a338 137 return;
16ea9636 138 if (col == 0) {
2d152f42 139 pc('\r');
16ea9636
EW
140 goto out;
141 }
3130283e 142 if (tt.tt_col == col - 1) {
6869a338 143 esc();
2d152f42 144 pc('C');
6869a338 145 goto out;
16ea9636
EW
146 }
147 if (tt.tt_col == col + 1) {
2d152f42 148 pc('\b');
6869a338
EW
149 goto out;
150 }
151 }
3130283e
EW
152 if (tt.tt_col == col) {
153 if (tt.tt_row == row + 1) {
6869a338 154 esc();
2d152f42 155 pc('A');
6869a338 156 goto out;
16ea9636
EW
157 }
158 if (tt.tt_row == row - 1) {
2d152f42 159 pc('\n');
6869a338
EW
160 goto out;
161 }
162 }
7aefc9fe 163 if (col == 0 && row == 0) {
6869a338 164 esc();
2d152f42 165 pc('H');
6869a338
EW
166 goto out;
167 }
168 esc();
2d152f42
EW
169 pc('Y');
170 pc(' ' + row);
171 pc(' ' + col);
6869a338 172out:
3130283e
EW
173 tt.tt_col = col;
174 tt.tt_row = row;
6869a338
EW
175}
176
ab8b3b31 177h19_start()
6869a338 178{
3130283e 179 if (gen_VS)
e1daf7d6 180 ttxputs(gen_VS);
6869a338 181 esc();
2d152f42 182 pc('w');
6869a338 183 esc();
2d152f42 184 pc('E');
3130283e 185 tt.tt_col = tt.tt_row = 0;
d9375810 186 tt.tt_insert = 0;
3130283e 187 tt.tt_nmodes = tt.tt_modes = 0;
6869a338
EW
188}
189
e908bfac 190h19_end()
6869a338 191{
d9375810
EW
192 if (tt.tt_insert)
193 H19_SETINSERT(0);
3130283e 194 if (gen_VE)
e1daf7d6 195 ttxputs(gen_VE);
6869a338 196 esc();
2d152f42 197 pc('v');
6869a338
EW
198}
199
200h19_clreol()
201{
202 esc();
2d152f42 203 pc('K');
6869a338
EW
204}
205
206h19_clreos()
207{
208 esc();
2d152f42 209 pc('J');
6869a338
EW
210}
211
212h19_clear()
213{
214 esc();
2d152f42 215 pc('E');
6869a338
EW
216}
217
d9375810
EW
218h19_inschar(c)
219register char c;
220{
221 if (tt.tt_nmodes != tt.tt_modes)
222 (*tt.tt_setmodes)(tt.tt_nmodes);
223 if (!tt.tt_insert)
224 H19_SETINSERT(1);
225 pc(c);
226 if (tt.tt_insert)
227 ICPAD();
228 if (++tt.tt_col == NCOL)
229 tt.tt_col = NCOL - 1;
230}
231
2d152f42 232h19_delchar(n)
6869a338 233{
2d152f42
EW
234 while (--n >= 0) {
235 esc();
236 pc('N');
237 }
6869a338
EW
238}
239
2d152f42 240h19_scroll_down(n)
16ea9636
EW
241{
242 h19_move(NROW - 1, 0);
2d152f42
EW
243 while (--n >= 0)
244 pc('\n');
16ea9636
EW
245}
246
2d152f42 247h19_scroll_up(n)
16ea9636
EW
248{
249 h19_move(0, 0);
2d152f42
EW
250 while (--n >= 0) {
251 esc();
252 pc('I');
253 }
16ea9636
EW
254}
255
6869a338
EW
256tt_h19()
257{
e908bfac
EW
258 float cpms = (float) wwbaud / 10000; /* char per ms */
259
260 h19_msp10c = 10 / cpms; /* ms per 10 char */
b1189050
EW
261 gen_VS = ttxgetstr("vs");
262 gen_VE = ttxgetstr("ve");
3130283e 263
ab8b3b31 264 tt.tt_start = h19_start;
3130283e
EW
265 tt.tt_end = h19_end;
266
6869a338
EW
267 tt.tt_insline = h19_insline;
268 tt.tt_delline = h19_delline;
d9375810 269 tt.tt_inschar = h19_inschar;
6869a338 270 tt.tt_delchar = h19_delchar;
6869a338
EW
271 tt.tt_clreol = h19_clreol;
272 tt.tt_clreos = h19_clreos;
273 tt.tt_clear = h19_clear;
274 tt.tt_move = h19_move;
6869a338
EW
275 tt.tt_write = h19_write;
276 tt.tt_putc = h19_putc;
16ea9636
EW
277 tt.tt_scroll_down = h19_scroll_down;
278 tt.tt_scroll_up = h19_scroll_up;
c1a57462 279 tt.tt_setmodes = h19_setmodes;
3130283e
EW
280
281 tt.tt_ncol = NCOL;
282 tt.tt_nrow = NROW;
a830e8bb 283 tt.tt_availmodes = WWM_REV|WWM_GRP;
6869a338
EW
284 tt.tt_frame = h19_frame;
285 return 0;
286}