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