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