make sure unavailable mode bits are not set,
[unix-history] / usr / src / usr.bin / window / tth19.c
CommitLineData
6869a338 1#ifndef lint
4c049d16 2static char sccsid[] = "@(#)tth19.c 3.17 %G%";
6869a338
EW
3#endif
4
60de5df9
EW
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
6869a338 11#include "ww.h"
e908bfac 12#include "tt.h"
6869a338
EW
13
14/*
15kb|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
3130283e
EW
26#define NCOL 80
27#define NROW 24
28
a830e8bb
EW
29#define G (WWM_GRP << WWC_MSHIFT)
30short 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
6869a338
EW
35};
36
e1daf7d6
EW
37extern struct tt_str *gen_VS;
38extern struct tt_str *gen_VE;
3130283e 39
a830e8bb 40int h19_msp10c;
6869a338 41
b1189050 42#define pc(c) ttputc('c')
6869a338
EW
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}
3130283e
EW
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 */
6869a338 51
c1a57462
EW
52#define H19_SETINSERT(m) (esc(), (tt.tt_insert = (m)) ? pc(@) : pc(O))
53
54h19_setinsert(new)
55{
56 H19_SETINSERT(new);
57}
a830e8bb
EW
58
59h19_setmodes(new)
60register new;
61{
62 register diff;
63
64 diff = new ^ tt.tt_modes;
65 if (diff & WWM_REV) {
66 esc();
67 if (new & WWM_REV)
68 pc(p);
69 else
70 pc(q);
71 }
72 if (diff & WWM_GRP) {
73 esc();
74 if (new & WWM_GRP)
75 pc(F);
76 else
77 pc(G);
78 }
79 tt.tt_modes = new;
80}
6869a338 81
6869a338
EW
82h19_insline()
83{
84 esc();
85 pc(L);
86 ILPAD();
87}
88
89h19_delline()
90{
91 esc();
92 pc(M);
93 ILPAD();
94}
95
96h19_putc(c)
97register char c;
98{
a830e8bb 99 if (tt.tt_nmodes != tt.tt_modes)
c1a57462 100 (*tt.tt_setmodes)(tt.tt_nmodes);
a830e8bb 101 if (tt.tt_ninsert != tt.tt_insert)
c1a57462 102 H19_SETINSERT(tt.tt_ninsert);
b1189050 103 ttputc(c);
3130283e 104 if (tt.tt_insert)
6869a338 105 ICPAD();
3130283e
EW
106 if (++tt.tt_col == NCOL)
107 tt.tt_col = NCOL - 1;
6869a338
EW
108}
109
3130283e
EW
110h19_write(p, n)
111register char *p;
112register n;
6869a338 113{
a830e8bb 114 if (tt.tt_nmodes != tt.tt_modes)
c1a57462 115 (*tt.tt_setmodes)(tt.tt_nmodes);
a830e8bb 116 if (tt.tt_ninsert != tt.tt_insert)
c1a57462 117 H19_SETINSERT(tt.tt_ninsert);
3130283e
EW
118 if (tt.tt_insert) {
119 while (--n >= 0) {
b1189050 120 ttputc(*p++);
6869a338 121 ICPAD();
3130283e 122 tt.tt_col++;
6869a338
EW
123 }
124 } else {
3130283e 125 tt.tt_col += n;
e1daf7d6 126 ttwrite(p, n);
6869a338 127 }
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;
3130283e 138 if (tt.tt_col == col - 1) {
6869a338
EW
139 esc();
140 pc(C);
141 goto out;
3130283e 142 } else if (tt.tt_col == col + 1) {
6869a338
EW
143 pc(\b);
144 goto out;
145 }
146 }
3130283e
EW
147 if (tt.tt_col == col) {
148 if (tt.tt_row == row + 1) {
6869a338
EW
149 esc();
150 pc(A);
151 goto out;
adb609f3 152 } else if (tt.tt_row == row - 1) {
6869a338
EW
153 pc(\n);
154 goto out;
155 }
156 }
7aefc9fe 157 if (col == 0 && row == 0) {
6869a338
EW
158 esc();
159 pc(H);
160 goto out;
161 }
162 esc();
163 pc(Y);
b1189050
EW
164 ttputc(' ' + row);
165 ttputc(' ' + col);
6869a338 166out:
3130283e
EW
167 tt.tt_col = col;
168 tt.tt_row = row;
6869a338
EW
169}
170
171h19_init()
6869a338 172{
3130283e 173 if (gen_VS)
e1daf7d6 174 ttxputs(gen_VS);
6869a338 175 esc();
c3f80cb5 176 pc(w);
6869a338
EW
177 esc();
178 pc(E);
3130283e
EW
179 tt.tt_col = tt.tt_row = 0;
180 tt.tt_ninsert = tt.tt_insert = 0;
181 tt.tt_nmodes = tt.tt_modes = 0;
6869a338
EW
182}
183
e908bfac 184h19_end()
6869a338 185{
3130283e 186 if (gen_VE)
e1daf7d6 187 ttxputs(gen_VE);
6869a338
EW
188 esc();
189 pc(v);
190}
191
192h19_clreol()
193{
194 esc();
195 pc(K);
196}
197
198h19_clreos()
199{
200 esc();
201 pc(J);
202}
203
204h19_clear()
205{
206 esc();
207 pc(E);
208}
209
210h19_delchar()
211{
212 esc();
213 pc(N);
214}
215
216tt_h19()
217{
e908bfac
EW
218 float cpms = (float) wwbaud / 10000; /* char per ms */
219
220 h19_msp10c = 10 / cpms; /* ms per 10 char */
b1189050
EW
221 gen_VS = ttxgetstr("vs");
222 gen_VE = ttxgetstr("ve");
3130283e
EW
223
224 tt.tt_init = h19_init;
225 tt.tt_end = h19_end;
226
6869a338
EW
227 tt.tt_insline = h19_insline;
228 tt.tt_delline = h19_delline;
229 tt.tt_delchar = h19_delchar;
6869a338
EW
230 tt.tt_clreol = h19_clreol;
231 tt.tt_clreos = h19_clreos;
232 tt.tt_clear = h19_clear;
233 tt.tt_move = h19_move;
6869a338
EW
234 tt.tt_write = h19_write;
235 tt.tt_putc = h19_putc;
c1a57462
EW
236 tt.tt_setinsert = h19_setinsert;
237 tt.tt_setmodes = h19_setmodes;
3130283e
EW
238
239 tt.tt_ncol = NCOL;
240 tt.tt_nrow = NROW;
241 tt.tt_hasinsert = 1;
a830e8bb 242 tt.tt_availmodes = WWM_REV|WWM_GRP;
6869a338
EW
243 tt.tt_frame = h19_frame;
244 return 0;
245}