xref: /dragonfly/usr.bin/window/tth19.c (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
1 /*        @(#)tth19.c         8.1 (Berkeley) 6/6/93         */
2 /*        $NetBSD: tth19.c,v 1.7 2009/04/14 08:50:06 lukem 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. Neither the name of the University nor the names of its contributors
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 #include "ww.h"
37 #include "tt.h"
38 #include "char.h"
39 
40 /*
41 kb|h19|heath|h19-b|h19b|heathkit|heath-19|z19|zenith:
42           cr=^M:nl=^J:bl=^G:al=1*\EL:am:le=^H:bs:cd=\EJ:ce=\EK:
43           cl=\EE:cm=\EY%+ %+ :co#80:dc=\EN:dl=1*\EM:do=\EB:
44           ei=\EO:ho=\EH:im=\E@:li#24:mi:nd=\EC:as=\EF:ae=\EG:ms:
45           ta=^I:pt:sr=\EI:se=\Eq:so=\Ep:up=\EA:vs=\Ex4:ve=\Ey4:
46           kb=^h:ku=\EA:kd=\EB:kl=\ED:kr=\EC:kh=\EH:
47           kn#8:k1=\ES:k2=\ET:k3=\EU:k4=\EV:k5=\EW:
48           l6=blue:l7=red:l8=white:k6=\EP:k7=\EQ:k8=\ER:
49           es:hs:ts=\Ej\Ex5\Ex1\EY8%+ \Eo:fs=\Ek\Ey5:ds=\Ey1:
50 */
51 
52 #define NCOL        80
53 #define NROW        24
54 
55 #define G (WWM_GRP << WWC_MSHIFT)
56 short h19_frame[16] = {
57           ' ',      '`'|G,    'a'|G,    'e'|G,
58           '`'|G,    '`'|G,    'f'|G,    'v'|G,
59           'a'|G,    'd'|G,    'a'|G,    'u'|G,
60           'c'|G,    't'|G,    's'|G,    'b'|G
61 };
62 
63 extern struct tt_str *gen_VS;
64 extern struct tt_str *gen_VE;
65 
66 int h19_msp10c;
67 
68 #define PAD(ms10) { \
69           int i; \
70           for (i = ((ms10) + 5) / h19_msp10c; --i >= 0;) \
71                     ttputc('\0'); \
72 }
73 #define ICPAD() PAD((NCOL - tt.tt_col) * 1)       /* 0.1 ms per char */
74 #define ILPAD() PAD((NROW - tt.tt_row) * 10)      /* 1 ms per char */
75 
76 #define H19_SETINSERT(m) ttesc((tt.tt_insert = (m)) ? '@' : 'O')
77 
78 void      h19_clear(void);
79 void      h19_clreol(void);
80 void      h19_clreos(void);
81 void      h19_delchar(int);
82 void      h19_delline(int);
83 void      h19_end(void);
84 void      h19_inschar(char);
85 void      h19_insline(int);
86 void      h19_move(int, int);
87 void      h19_putc(char);
88 void      h19_scroll_up(int);
89 void      h19_scroll_down(int);
90 void      h19_setmodes(int);
91 void      h19_start(void);
92 void      h19_write(const char *, int);
93 
94 void
h19_setmodes(int new)95 h19_setmodes(int new)
96 {
97           int diff;
98 
99           diff = new ^ tt.tt_modes;
100           if (diff & WWM_REV)
101                     ttesc(new & WWM_REV ? 'p' : 'q');
102           if (diff & WWM_GRP)
103                     ttesc(new & WWM_REV ? 'F' : 'G');
104           tt.tt_modes = new;
105 }
106 
107 void
h19_insline(int n)108 h19_insline(int n)
109 {
110           while (--n >= 0) {
111                     ttesc('L');
112                     ILPAD();
113           }
114 }
115 
116 void
h19_delline(int n)117 h19_delline(int n)
118 {
119           while (--n >= 0) {
120                     ttesc('M');
121                     ILPAD();
122           }
123 }
124 
125 void
h19_putc(char c)126 h19_putc(char c)
127 {
128           if (tt.tt_nmodes != tt.tt_modes)
129                     (*tt.tt_setmodes)(tt.tt_nmodes);
130           if (tt.tt_insert)
131                     H19_SETINSERT(0);
132           ttputc(c);
133           if (++tt.tt_col == NCOL)
134                     tt.tt_col = NCOL - 1;
135 }
136 
137 void
h19_write(const char * p,int n)138 h19_write(const char *p, int n)
139 {
140           if (tt.tt_nmodes != tt.tt_modes)
141                     (*tt.tt_setmodes)(tt.tt_nmodes);
142           if (tt.tt_insert)
143                     H19_SETINSERT(0);
144           ttwrite(p, n);
145           tt.tt_col += n;
146           if (tt.tt_col == NCOL)
147                     tt.tt_col = NCOL - 1;
148 }
149 
150 void
h19_move(int row,int col)151 h19_move(int row, int col)
152 {
153           if (tt.tt_row == row) {
154                     if (tt.tt_col == col)
155                               return;
156                     if (col == 0) {
157                               ttctrl('m');
158                               goto out;
159                     }
160                     if (tt.tt_col == col - 1) {
161                               ttesc('C');
162                               goto out;
163                     }
164                     if (tt.tt_col == col + 1) {
165                               ttctrl('h');
166                               goto out;
167                     }
168           }
169           if (tt.tt_col == col) {
170                     if (tt.tt_row == row + 1) {
171                               ttesc('A');
172                               goto out;
173                     }
174                     if (tt.tt_row == row - 1) {
175                               ttctrl('j');
176                               goto out;
177                     }
178           }
179           if (col == 0 && row == 0) {
180                     ttesc('H');
181                     goto out;
182           }
183           ttesc('Y');
184           ttputc(' ' + row);
185           ttputc(' ' + col);
186 out:
187           tt.tt_col = col;
188           tt.tt_row = row;
189 }
190 
191 void
h19_start(void)192 h19_start(void)
193 {
194           if (gen_VS)
195                     ttxputs(gen_VS);
196           ttesc('w');
197           ttesc('E');
198           tt.tt_col = tt.tt_row = 0;
199           tt.tt_insert = 0;
200           tt.tt_nmodes = tt.tt_modes = 0;
201 }
202 
203 void
h19_end(void)204 h19_end(void)
205 {
206           if (tt.tt_insert)
207                     H19_SETINSERT(0);
208           if (gen_VE)
209                     ttxputs(gen_VE);
210           ttesc('v');
211 }
212 
213 void
h19_clreol(void)214 h19_clreol(void)
215 {
216           ttesc('K');
217 }
218 
219 void
h19_clreos(void)220 h19_clreos(void)
221 {
222           ttesc('J');
223 }
224 
225 void
h19_clear(void)226 h19_clear(void)
227 {
228           ttesc('E');
229 }
230 
231 void
h19_inschar(char c)232 h19_inschar(char c)
233 {
234           if (tt.tt_nmodes != tt.tt_modes)
235                     (*tt.tt_setmodes)(tt.tt_nmodes);
236           if (!tt.tt_insert)
237                     H19_SETINSERT(1);
238           ttputc(c);
239           if (tt.tt_insert)
240                     ICPAD();
241           if (++tt.tt_col == NCOL)
242                     tt.tt_col = NCOL - 1;
243 }
244 
245 void
h19_delchar(int n)246 h19_delchar(int n)
247 {
248           while (--n >= 0)
249                     ttesc('N');
250 }
251 
252 void
h19_scroll_down(int n)253 h19_scroll_down(int n)
254 {
255           h19_move(NROW - 1, 0);
256           while (--n >= 0)
257                     ttctrl('j');
258 }
259 
260 void
h19_scroll_up(int n)261 h19_scroll_up(int n)
262 {
263           h19_move(0, 0);
264           while (--n >= 0)
265                     ttesc('I');
266 }
267 
268 int
tt_h19(void)269 tt_h19(void)
270 {
271           float cpms = (float) wwbaud / 10000;    /* char per ms */
272 
273           h19_msp10c = 10 / cpms;                           /* ms per 10 char */
274           gen_VS = ttxgetstr("vs");
275           gen_VE = ttxgetstr("ve");
276 
277           tt.tt_start = h19_start;
278           tt.tt_end = h19_end;
279 
280           tt.tt_insline = h19_insline;
281           tt.tt_delline = h19_delline;
282           tt.tt_inschar = h19_inschar;
283           tt.tt_delchar = h19_delchar;
284           tt.tt_clreol = h19_clreol;
285           tt.tt_clreos = h19_clreos;
286           tt.tt_clear = h19_clear;
287           tt.tt_move = h19_move;
288           tt.tt_write = h19_write;
289           tt.tt_putc = h19_putc;
290           tt.tt_scroll_down = h19_scroll_down;
291           tt.tt_scroll_up = h19_scroll_up;
292           tt.tt_setmodes = h19_setmodes;
293 
294           tt.tt_ncol = NCOL;
295           tt.tt_nrow = NROW;
296           tt.tt_availmodes = WWM_REV|WWM_GRP;
297           tt.tt_frame = h19_frame;
298           return 0;
299 }
300