let c_window() take 0 as starting row
[unix-history] / usr / src / usr.bin / window / tth19.c
... / ...
CommitLineData
1#ifndef lint
2static char *sccsid = "@(#)tth19.c 3.10 83/12/02";
3#endif
4
5#include "ww.h"
6#include "tt.h"
7
8/*
9kb|h19|heath|h19-b|h19b|heathkit|heath-19|z19|zenith:
10 cr=^M:nl=^J:bl=^G:al=1*\EL:am:le=^H:bs:cd=\EJ:ce=\EK:
11 cl=\EE:cm=\EY%+ %+ :co#80:dc=\EN:dl=1*\EM:do=\EB:
12 ei=\EO:ho=\EH:im=\E@:li#24:mi:nd=\EC:as=\EF:ae=\EG:ms:
13 ta=^I:pt:sr=\EI:se=\Eq:so=\Ep:up=\EA:vs=\Ex4:ve=\Ey4:
14 kb=^h:ku=\EA:kd=\EB:kl=\ED:kr=\EC:kh=\EH:
15 kn#8:k1=\ES:k2=\ET:k3=\EU:k4=\EV:k5=\EW:
16 l6=blue:l7=red:l8=white:k6=\EP:k7=\EQ:k8=\ER:
17 es:hs:ts=\Ej\Ex5\Ex1\EY8%+ \Eo:fs=\Ek\Ey5:ds=\Ey1:
18*/
19
20#define NCOL 80
21#define NROW 24
22
23char h19_frame[16] = {
24 ' ', '`'|0x80, 'a'|0x80, 'e'|0x80,
25 '`'|0x80, '`'|0x80, 'f'|0x80, 'v'|0x80,
26 'a'|0x80, 'd'|0x80, 'a'|0x80, 'u'|0x80,
27 'c'|0x80, 't'|0x80, 's'|0x80, 'b'|0x80
28};
29
30extern char *gen_VS;
31extern char *gen_VE;
32
33char h19_graphics; /* in graphics mode */
34short h19_msp10c;
35
36#define pc(c) putchar('c')
37#define esc() pc(\033)
38#define PAD(ms10) { \
39 register i; \
40 for (i = ((ms10) + 5) / h19_msp10c; --i >= 0;) \
41 pc(\0); \
42}
43#define ICPAD() PAD((NCOL - tt.tt_col) * 1) /* 0.1 ms per char */
44#define ILPAD() PAD((NROW - tt.tt_row) * 10) /* 1 ms per char */
45
46#define SETINSERT(m) \
47 ((m) != tt.tt_insert \
48 ? (esc(), (tt.tt_insert = (m)) ? pc(@) : pc(O)) : 0)
49#define SETMODES(m) \
50 ((m) != tt.tt_modes \
51 ? (esc(), (tt.tt_modes = (m)) ? pc(p) : pc(q)) : 0)
52#define SETGRAPHICS(m) \
53 ((m) != h19_graphics \
54 ? (esc(), (h19_graphics = (m)) ? pc(F) : pc(G)) : 0)
55
56h19_insline()
57{
58 esc();
59 pc(L);
60 ILPAD();
61}
62
63h19_delline()
64{
65 esc();
66 pc(M);
67 ILPAD();
68}
69
70h19_putc(c)
71register char c;
72{
73 SETMODES(tt.tt_nmodes);
74 SETINSERT(tt.tt_ninsert);
75 if (c & 0x80) {
76 SETGRAPHICS(1);
77 putchar(c & 0x7f);
78 } else {
79 SETGRAPHICS(0);
80 putchar(c);
81 }
82 if (tt.tt_insert)
83 ICPAD();
84 if (++tt.tt_col == NCOL)
85 tt.tt_col = NCOL - 1;
86}
87
88h19_write(p, n)
89register char *p;
90register n;
91{
92 register char c;
93
94 SETMODES(tt.tt_nmodes);
95 SETINSERT(tt.tt_ninsert);
96 if (tt.tt_insert) {
97 while (--n >= 0) {
98 if ((c = *p++) & 0x80) {
99 SETGRAPHICS(1);
100 putchar(c & 0x7f);
101 } else {
102 SETGRAPHICS(0);
103 putchar(c);
104 }
105 ICPAD();
106 tt.tt_col++;
107 }
108 } else {
109 tt.tt_col += n;
110 while (--n >= 0)
111 if ((c = *p++) & 0x80) {
112 SETGRAPHICS(1);
113 putchar(c & 0x7f);
114 } else {
115 SETGRAPHICS(0);
116 putchar(c);
117 }
118 }
119 if (tt.tt_col == NCOL)
120 tt.tt_col = NCOL - 1;
121}
122
123h19_move(row, col)
124register char row, col;
125{
126 if (tt.tt_row == row) {
127 if (tt.tt_col == col)
128 return;
129 if (tt.tt_col == col - 1) {
130 esc();
131 pc(C);
132 goto out;
133 } else if (tt.tt_col == col + 1) {
134 pc(\b);
135 goto out;
136 }
137 }
138 if (tt.tt_col == col) {
139 if (tt.tt_row == row + 1) {
140 esc();
141 pc(A);
142 goto out;
143 } else if (tt.tt_row == row - 1) {
144 pc(\n);
145 goto out;
146 }
147 }
148 if (col == 0 && row == 0) {
149 esc();
150 pc(H);
151 goto out;
152 }
153 esc();
154 pc(Y);
155 putchar(' ' + row);
156 putchar(' ' + col);
157out:
158 tt.tt_col = col;
159 tt.tt_row = row;
160}
161
162h19_init()
163{
164 if (gen_VS)
165 fputs(gen_VS, stdout);
166 esc();
167 pc(w);
168 esc();
169 pc(E);
170 tt.tt_col = tt.tt_row = 0;
171 tt.tt_ninsert = tt.tt_insert = 0;
172 tt.tt_nmodes = tt.tt_modes = 0;
173 h19_graphics = 0;
174}
175
176h19_end()
177{
178 SETMODES(0);
179 SETINSERT(0);
180 SETGRAPHICS(0);
181 if (gen_VE)
182 fputs(gen_VE, stdout);
183 esc();
184 pc(v);
185}
186
187h19_clreol()
188{
189 esc();
190 pc(K);
191}
192
193h19_clreos()
194{
195 esc();
196 pc(J);
197}
198
199h19_clear()
200{
201 esc();
202 pc(E);
203}
204
205h19_delchar()
206{
207 esc();
208 pc(N);
209}
210
211tt_h19()
212{
213 float cpms = (float) wwbaud / 10000; /* char per ms */
214
215 h19_msp10c = 10 / cpms; /* ms per 10 char */
216 gen_VS = tt_xgetstr("vs");
217 gen_VE = tt_xgetstr("ve");
218
219 tt.tt_init = h19_init;
220 tt.tt_end = h19_end;
221
222 tt.tt_insline = h19_insline;
223 tt.tt_delline = h19_delline;
224 tt.tt_delchar = h19_delchar;
225 tt.tt_clreol = h19_clreol;
226 tt.tt_clreos = h19_clreos;
227 tt.tt_clear = h19_clear;
228 tt.tt_move = h19_move;
229 tt.tt_write = h19_write;
230 tt.tt_putc = h19_putc;
231
232 tt.tt_ncol = NCOL;
233 tt.tt_nrow = NROW;
234 tt.tt_hasinsert = 1;
235 tt.tt_availmodes = WWM_REV;
236 tt.tt_frame = h19_frame;
237 return 0;
238}