1 /* 2 * Copyright (c) 1989 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 the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 */ 17 18 #ifndef lint 19 static char sccsid[] = "@(#)ttzapple.c 3.8 (Berkeley) 09/15/89"; 20 #endif /* not lint */ 21 22 #include "ww.h" 23 #include "tt.h" 24 #include "char.h" 25 26 /* 27 zz|zapple|perfect apple:\ 28 :am:pt:co#80:li#24:le=^H:nd=^F:up=^K:do=^J:\ 29 :ho=\E0:ll=\E1:cm=\E=%+ %+ :ch=\E<%+ :cv=\E>%+ :\ 30 :cl=\E4:ce=\E2:cd=\E3:rp=\E@%.%+ :\ 31 :so=\E+:se=\E-:\ 32 :dc=\Ec:DC=\EC%+ :ic=\Ei:IC=\EI%+ :\ 33 :al=\Ea:AL=\EA%+ :dl=\Ed:DL=\ED%+ :\ 34 :sf=\Ef:SF=\EF%+ :sr=\Er:SR=\ER%+ :cs=\E?%+ %+ :\ 35 :is=\E-\ET : 36 */ 37 38 #define NCOL 80 39 #define NROW 24 40 #define TOKEN_MAX 32 41 42 extern short gen_frame[]; 43 44 zz_setmodes(new) 45 { 46 if (new & WWM_REV) { 47 if ((tt.tt_modes & WWM_REV) == 0) 48 ttesc('+'); 49 } else 50 if (tt.tt_modes & WWM_REV) 51 ttesc('-'); 52 tt.tt_modes = new; 53 } 54 55 zz_insline(n) 56 { 57 if (n == 1) 58 ttesc('a'); 59 else { 60 ttesc('A'); 61 ttputc(n + ' '); 62 } 63 } 64 65 zz_delline(n) 66 { 67 if (n == 1) 68 ttesc('d'); 69 else { 70 ttesc('D'); 71 ttputc(n + ' '); 72 } 73 } 74 75 zz_putc(c) 76 char c; 77 { 78 if (tt.tt_nmodes != tt.tt_modes) 79 zz_setmodes(tt.tt_nmodes); 80 ttputc(c); 81 if (++tt.tt_col == NCOL) 82 tt.tt_col = 0, tt.tt_row++; 83 } 84 85 zz_write(p, n) 86 register char *p; 87 register n; 88 { 89 if (tt.tt_nmodes != tt.tt_modes) 90 zz_setmodes(tt.tt_nmodes); 91 ttwrite(p, n); 92 tt.tt_col += n; 93 if (tt.tt_col == NCOL) 94 tt.tt_col = 0, tt.tt_row++; 95 } 96 97 zz_move(row, col) 98 register row, col; 99 { 100 register x; 101 102 if (tt.tt_row == row) { 103 same_row: 104 if ((x = col - tt.tt_col) == 0) 105 return; 106 if (col == 0) { 107 ttctrl('m'); 108 goto out; 109 } 110 switch (x) { 111 case 2: 112 ttctrl('f'); 113 case 1: 114 ttctrl('f'); 115 goto out; 116 case -2: 117 ttctrl('h'); 118 case -1: 119 ttctrl('h'); 120 goto out; 121 } 122 if (col & 7 == 0 && x > 0 && x <= 16) { 123 ttctrl('i'); 124 if (x > 8) 125 ttctrl('i'); 126 goto out; 127 } 128 ttesc('<'); 129 ttputc(col + ' '); 130 goto out; 131 } 132 if (tt.tt_col == col) { 133 switch (row - tt.tt_row) { 134 case 2: 135 ttctrl('j'); 136 case 1: 137 ttctrl('j'); 138 goto out; 139 case -2: 140 ttctrl('k'); 141 case -1: 142 ttctrl('k'); 143 goto out; 144 } 145 if (col == 0) { 146 if (row == 0) 147 goto home; 148 if (row == NROW - 1) 149 goto ll; 150 } 151 ttesc('>'); 152 ttputc(row + ' '); 153 goto out; 154 } 155 if (col == 0) { 156 if (row == 0) { 157 home: 158 ttesc('0'); 159 goto out; 160 } 161 if (row == tt.tt_row + 1) { 162 /* 163 * Do newline first to match the sequence 164 * for scroll down and return 165 */ 166 ttctrl('j'); 167 ttctrl('m'); 168 goto out; 169 } 170 if (row == NROW - 1) { 171 ll: 172 ttesc('1'); 173 goto out; 174 } 175 } 176 /* favor local motion for better compression */ 177 if (row == tt.tt_row + 1) { 178 ttctrl('j'); 179 goto same_row; 180 } 181 if (row == tt.tt_row - 1) { 182 ttctrl('k'); 183 goto same_row; 184 } 185 ttesc('='); 186 ttputc(' ' + row); 187 ttputc(' ' + col); 188 out: 189 tt.tt_col = col; 190 tt.tt_row = row; 191 } 192 193 zz_start() 194 { 195 zz_setmodes(0); 196 zz_setscroll(0, NROW - 1); 197 zz_clear(); 198 ttesc('T'); 199 ttputc(TOKEN_MAX + ' '); 200 } 201 202 zz_end() 203 { 204 ttesc('T'); 205 ttputc(' '); 206 } 207 208 zz_clreol() 209 { 210 ttesc('2'); 211 } 212 213 zz_clreos() 214 { 215 ttesc('3'); 216 } 217 218 zz_clear() 219 { 220 ttesc('4'); 221 tt.tt_col = tt.tt_row = 0; 222 } 223 224 zz_insspace(n) 225 { 226 if (n == 1) 227 ttesc('i'); 228 else { 229 ttesc('I'); 230 ttputc(n + ' '); 231 } 232 } 233 234 zz_delchar(n) 235 { 236 if (n == 1) 237 ttesc('c'); 238 else { 239 ttesc('C'); 240 ttputc(n + ' '); 241 } 242 } 243 244 zz_scroll_down(n) 245 { 246 if (n == 1) 247 if (tt.tt_row == NROW - 1) 248 ttctrl('j'); 249 else 250 ttesc('f'); 251 else { 252 ttesc('F'); 253 ttputc(n + ' '); 254 } 255 } 256 257 zz_scroll_up(n) 258 { 259 if (n == 1) 260 ttesc('r'); 261 else { 262 ttesc('R'); 263 ttputc(n + ' '); 264 } 265 } 266 267 zz_setscroll(top, bot) 268 { 269 ttesc('?'); 270 ttputc(top + ' '); 271 ttputc(bot + ' '); 272 tt.tt_scroll_top = top; 273 tt.tt_scroll_bot = bot; 274 } 275 276 int zz_debug = 0; 277 278 zz_set_token(t, s, n) 279 char *s; 280 { 281 if (tt.tt_nmodes != tt.tt_modes) 282 zz_setmodes(tt.tt_nmodes); 283 if (zz_debug) { 284 char buf[100]; 285 zz_setmodes(WWM_REV); 286 (void) sprintf(buf, "%02x=", t); 287 ttputs(buf); 288 tt.tt_col += 3; 289 } 290 ttputc(0x80); 291 ttputc(t + 1); 292 s[n - 1] |= 0x80; 293 ttwrite(s, n); 294 s[n - 1] &= ~0x80; 295 } 296 297 /*ARGSUSED*/ 298 zz_put_token(t, s, n) 299 char *s; 300 { 301 if (tt.tt_nmodes != tt.tt_modes) 302 zz_setmodes(tt.tt_nmodes); 303 if (zz_debug) { 304 char buf[100]; 305 zz_setmodes(WWM_REV); 306 (void) sprintf(buf, "%02x>", t); 307 ttputs(buf); 308 tt.tt_col += 3; 309 } 310 ttputc(t + 0x81); 311 } 312 313 tt_zapple() 314 { 315 tt.tt_insspace = zz_insspace; 316 tt.tt_delchar = zz_delchar; 317 tt.tt_insline = zz_insline; 318 tt.tt_delline = zz_delline; 319 tt.tt_clreol = zz_clreol; 320 tt.tt_clreos = zz_clreos; 321 tt.tt_scroll_down = zz_scroll_down; 322 tt.tt_scroll_up = zz_scroll_up; 323 tt.tt_setscroll = zz_setscroll; 324 tt.tt_availmodes = WWM_REV; 325 tt.tt_wrap = 1; 326 tt.tt_retain = 0; 327 tt.tt_ncol = NCOL; 328 tt.tt_nrow = NROW; 329 tt.tt_start = zz_start; 330 tt.tt_end = zz_end; 331 tt.tt_write = zz_write; 332 tt.tt_putc = zz_putc; 333 tt.tt_move = zz_move; 334 tt.tt_clear = zz_clear; 335 tt.tt_setmodes = zz_setmodes; 336 tt.tt_frame = gen_frame; 337 tt.tt_padc = TT_PADC_NONE; 338 tt.tt_ntoken = 127; 339 tt.tt_set_token = zz_set_token; 340 tt.tt_put_token = zz_put_token; 341 tt.tt_token_min = 1; 342 tt.tt_token_max = TOKEN_MAX; 343 tt.tt_set_token_cost = 2; 344 tt.tt_put_token_cost = 1; 345 return 0; 346 } 347