1 /* $NetBSD: tth19.c,v 1.7 2009/04/14 08:50:06 lukem Exp $ */ 2 3 /* 4 * Copyright (c) 1983, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Edward Wang at The University of California, Berkeley. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 35 #include <sys/cdefs.h> 36 #ifndef lint 37 #if 0 38 static char sccsid[] = "@(#)tth19.c 8.1 (Berkeley) 6/6/93"; 39 #else 40 __RCSID("$NetBSD: tth19.c,v 1.7 2009/04/14 08:50:06 lukem Exp $"); 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) { \ 77 int i; \ 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 void h19_clear(void); 87 void h19_clreol(void); 88 void h19_clreos(void); 89 void h19_delchar(int); 90 void h19_delline(int); 91 void h19_end(void); 92 void h19_inschar(char); 93 void h19_insline(int); 94 void h19_move(int, int); 95 void h19_putc(char); 96 void h19_scroll_up(int); 97 void h19_scroll_down(int); 98 void h19_setmodes(int); 99 void h19_start(void); 100 void h19_write(const char *, int); 101 102 void 103 h19_setmodes(int new) 104 { 105 int diff; 106 107 diff = new ^ tt.tt_modes; 108 if (diff & WWM_REV) 109 ttesc(new & WWM_REV ? 'p' : 'q'); 110 if (diff & WWM_GRP) 111 ttesc(new & WWM_REV ? 'F' : 'G'); 112 tt.tt_modes = new; 113 } 114 115 void 116 h19_insline(int n) 117 { 118 while (--n >= 0) { 119 ttesc('L'); 120 ILPAD(); 121 } 122 } 123 124 void 125 h19_delline(int n) 126 { 127 while (--n >= 0) { 128 ttesc('M'); 129 ILPAD(); 130 } 131 } 132 133 void 134 h19_putc(char c) 135 { 136 if (tt.tt_nmodes != tt.tt_modes) 137 (*tt.tt_setmodes)(tt.tt_nmodes); 138 if (tt.tt_insert) 139 H19_SETINSERT(0); 140 ttputc(c); 141 if (++tt.tt_col == NCOL) 142 tt.tt_col = NCOL - 1; 143 } 144 145 void 146 h19_write(const char *p, int n) 147 { 148 if (tt.tt_nmodes != tt.tt_modes) 149 (*tt.tt_setmodes)(tt.tt_nmodes); 150 if (tt.tt_insert) 151 H19_SETINSERT(0); 152 ttwrite(p, n); 153 tt.tt_col += n; 154 if (tt.tt_col == NCOL) 155 tt.tt_col = NCOL - 1; 156 } 157 158 void 159 h19_move(int row, int col) 160 { 161 if (tt.tt_row == row) { 162 if (tt.tt_col == col) 163 return; 164 if (col == 0) { 165 ttctrl('m'); 166 goto out; 167 } 168 if (tt.tt_col == col - 1) { 169 ttesc('C'); 170 goto out; 171 } 172 if (tt.tt_col == col + 1) { 173 ttctrl('h'); 174 goto out; 175 } 176 } 177 if (tt.tt_col == col) { 178 if (tt.tt_row == row + 1) { 179 ttesc('A'); 180 goto out; 181 } 182 if (tt.tt_row == row - 1) { 183 ttctrl('j'); 184 goto out; 185 } 186 } 187 if (col == 0 && row == 0) { 188 ttesc('H'); 189 goto out; 190 } 191 ttesc('Y'); 192 ttputc(' ' + row); 193 ttputc(' ' + col); 194 out: 195 tt.tt_col = col; 196 tt.tt_row = row; 197 } 198 199 void 200 h19_start(void) 201 { 202 if (gen_VS) 203 ttxputs(gen_VS); 204 ttesc('w'); 205 ttesc('E'); 206 tt.tt_col = tt.tt_row = 0; 207 tt.tt_insert = 0; 208 tt.tt_nmodes = tt.tt_modes = 0; 209 } 210 211 void 212 h19_end(void) 213 { 214 if (tt.tt_insert) 215 H19_SETINSERT(0); 216 if (gen_VE) 217 ttxputs(gen_VE); 218 ttesc('v'); 219 } 220 221 void 222 h19_clreol(void) 223 { 224 ttesc('K'); 225 } 226 227 void 228 h19_clreos(void) 229 { 230 ttesc('J'); 231 } 232 233 void 234 h19_clear(void) 235 { 236 ttesc('E'); 237 } 238 239 void 240 h19_inschar(char c) 241 { 242 if (tt.tt_nmodes != tt.tt_modes) 243 (*tt.tt_setmodes)(tt.tt_nmodes); 244 if (!tt.tt_insert) 245 H19_SETINSERT(1); 246 ttputc(c); 247 if (tt.tt_insert) 248 ICPAD(); 249 if (++tt.tt_col == NCOL) 250 tt.tt_col = NCOL - 1; 251 } 252 253 void 254 h19_delchar(int n) 255 { 256 while (--n >= 0) 257 ttesc('N'); 258 } 259 260 void 261 h19_scroll_down(int n) 262 { 263 h19_move(NROW - 1, 0); 264 while (--n >= 0) 265 ttctrl('j'); 266 } 267 268 void 269 h19_scroll_up(int n) 270 { 271 h19_move(0, 0); 272 while (--n >= 0) 273 ttesc('I'); 274 } 275 276 int 277 tt_h19(void) 278 { 279 float cpms = (float) wwbaud / 10000; /* char per ms */ 280 281 h19_msp10c = 10 / cpms; /* ms per 10 char */ 282 gen_VS = ttxgetstr("vs"); 283 gen_VE = ttxgetstr("ve"); 284 285 tt.tt_start = h19_start; 286 tt.tt_end = h19_end; 287 288 tt.tt_insline = h19_insline; 289 tt.tt_delline = h19_delline; 290 tt.tt_inschar = h19_inschar; 291 tt.tt_delchar = h19_delchar; 292 tt.tt_clreol = h19_clreol; 293 tt.tt_clreos = h19_clreos; 294 tt.tt_clear = h19_clear; 295 tt.tt_move = h19_move; 296 tt.tt_write = h19_write; 297 tt.tt_putc = h19_putc; 298 tt.tt_scroll_down = h19_scroll_down; 299 tt.tt_scroll_up = h19_scroll_up; 300 tt.tt_setmodes = h19_setmodes; 301 302 tt.tt_ncol = NCOL; 303 tt.tt_nrow = NROW; 304 tt.tt_availmodes = WWM_REV|WWM_GRP; 305 tt.tt_frame = h19_frame; 306 return 0; 307 } 308