X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/1c15e88899094343f75aeba04122cd96a96b428e..ad7871609881e73855d0b04da49b486cd93efca7:/usr/src/usr.bin/window/ttzapple.c diff --git a/usr/src/usr.bin/window/ttzapple.c b/usr/src/usr.bin/window/ttzapple.c index d7c84ec8c1..a285712f8b 100644 --- a/usr/src/usr.bin/window/ttzapple.c +++ b/usr/src/usr.bin/window/ttzapple.c @@ -1,27 +1,41 @@ /* - * Copyright (c) 1989 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1989, 1993 + * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Edward Wang at The University of California, Berkeley. * - * Redistribution and use in source and binary forms are permitted provided - * that: (1) source distributions retain this entire copyright notice and - * comment, and (2) distributions including binaries display the following - * acknowledgement: ``This product includes software developed by the - * University of California, Berkeley and its contributors'' in the - * documentation or other materials provided with the distribution and in - * all advertising materials mentioning features or use of this software. - * Neither the name of the University nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. */ #ifndef lint -static char sccsid[] = "@(#)ttzapple.c 3.11 (Berkeley) 6/6/90"; +static char sccsid[] = "@(#)ttzapple.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ #include "ww.h" @@ -46,6 +60,13 @@ zz|zapple|perfect apple:\ extern short gen_frame[]; + /* for error correction */ +int zz_ecc; +int zz_lastc; + + /* for checkpointing */ +int zz_sum; + zz_setmodes(new) { if (new & WWM_REV) { @@ -197,17 +218,35 @@ out: zz_start() { - zz_setmodes(0); - zz_setscroll(0, NROW - 1); - zz_clear(); ttesc('T'); ttputc(TOKEN_MAX + ' '); + ttesc('U'); + ttputc('!'); + zz_ecc = 1; + zz_lastc = -1; + ttesc('v'); + ttflush(); + zz_sum = 0; + zz_setscroll(0, NROW - 1); + zz_clear(); + zz_setmodes(0); +} + +zz_reset() +{ + zz_setscroll(0, NROW - 1); + tt.tt_modes = WWM_REV; + zz_setmodes(0); + tt.tt_col = tt.tt_row = -10; } zz_end() { ttesc('T'); ttputc(' '); + ttesc('U'); + ttputc(' '); + zz_ecc = 0; } zz_clreol() @@ -315,6 +354,93 @@ zz_put_token(t, s, n) ttputc(t + 0x81); } +zz_rint(p, n) + char *p; +{ + register i; + register char *q; + + if (!zz_ecc) + return n; + for (i = n, q = p; --i >= 0;) { + register c = (unsigned char) *p++; + + if (zz_lastc == 0) { + switch (c) { + case 0: + *q++ = 0; + zz_lastc = -1; + break; + case 1: /* start input ecc */ + zz_ecc = 2; + zz_lastc = -1; + wwnreadstat++; + break; + case 2: /* ack checkpoint */ + tt.tt_ack = 1; + zz_lastc = -1; + wwnreadack++; + break; + case 3: /* nack checkpoint */ + tt.tt_ack = -1; + zz_lastc = -1; + wwnreadnack++; + break; + default: + zz_lastc = c; + wwnreadec++; + } + } else if (zz_ecc == 1) { + if (c) + *q++ = c; + else + zz_lastc = 0; + } else { + if (zz_lastc < 0) { + zz_lastc = c; + } else if (zz_lastc == c) { + *q++ = zz_lastc; + zz_lastc = -1; + } else { + wwnreadec++; + zz_lastc = c; + } + } + } + return q - (p - n); +} + +zz_checksum(p, n) + register char *p; + register n; +{ + while (--n >= 0) { + register c = *p++ & 0x7f; + c ^= zz_sum; + zz_sum = c << 1 | c >> 11 & 1; + } +} + +zz_compress(flag) +{ + if (flag) + tt.tt_checksum = 0; + else + tt.tt_checksum = zz_checksum; +} + +zz_checkpoint() +{ + static char x[] = { ctrl('['), 'V', 0, 0 }; + + zz_checksum(x, sizeof x); + ttesc('V'); + ttputc(' ' + (zz_sum & 0x3f)); + ttputc(' ' + (zz_sum >> 6 & 0x3f)); + ttflush(); + zz_sum = 0; +} + tt_zapple() { tt.tt_insspace = zz_insspace; @@ -332,6 +458,7 @@ tt_zapple() tt.tt_ncol = NCOL; tt.tt_nrow = NROW; tt.tt_start = zz_start; + tt.tt_reset = zz_reset; tt.tt_end = zz_end; tt.tt_write = zz_write; tt.tt_putc = zz_putc; @@ -347,5 +474,10 @@ tt_zapple() tt.tt_token_max = TOKEN_MAX; tt.tt_set_token_cost = 2; tt.tt_put_token_cost = 1; + tt.tt_compress = zz_compress; + tt.tt_checksum = zz_checksum; + tt.tt_checkpoint = zz_checkpoint; + tt.tt_reset = zz_reset; + tt.tt_rint = zz_rint; return 0; }