2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Edward Wang at The University of California, Berkeley.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 static char sccsid[] = "@(#)ttzapple.c 8.1 (Berkeley) 6/6/93";
39 static char rcsid[] = "@(#)$FreeBSD$";
47 zz|zapple|perfect apple:\
48 :am:pt:co#80:li#24:le=^H:nd=^F:up=^K:do=^J:\
49 :ho=\E0:ll=\E1:cm=\E=%+ %+ :ch=\E<%+ :cv=\E>%+ :\
50 :cl=\E4:ce=\E2:cd=\E3:rp=\E@%.%+ :\
52 :dc=\Ec:DC=\EC%+ :ic=\Ei:IC=\EI%+ :\
53 :al=\Ea:AL=\EA%+ :dl=\Ed:DL=\ED%+ :\
54 :sf=\Ef:SF=\EF%+ :sr=\Er:SR=\ER%+ :cs=\E?%+ %+ :\
62 extern short gen_frame[];
64 /* for error correction */
68 /* for checkpointing */
74 if ((tt.tt_modes & WWM_REV) == 0)
77 if (tt.tt_modes & WWM_REV)
105 if (tt.tt_nmodes != tt.tt_modes)
106 zz_setmodes(tt.tt_nmodes);
108 if (++tt.tt_col == NCOL)
109 tt.tt_col = 0, tt.tt_row++;
116 if (tt.tt_nmodes != tt.tt_modes)
117 zz_setmodes(tt.tt_nmodes);
120 if (tt.tt_col == NCOL)
121 tt.tt_col = 0, tt.tt_row++;
129 if (tt.tt_row == row) {
131 if ((x = col - tt.tt_col) == 0)
149 if ((col & 7) == 0 && x > 0 && x <= 16) {
159 if (tt.tt_col == col) {
160 switch (row - tt.tt_row) {
188 if (row == tt.tt_row + 1) {
190 * Do newline first to match the sequence
191 * for scroll down and return
197 if (row == NROW - 1) {
203 /* favor local motion for better compression */
204 if (row == tt.tt_row + 1) {
208 if (row == tt.tt_row - 1) {
223 ttputc(TOKEN_MAX + ' ');
231 zz_setscroll(0, NROW - 1);
238 zz_setscroll(0, NROW - 1);
239 tt.tt_modes = WWM_REV;
241 tt.tt_col = tt.tt_row = -10;
266 tt.tt_col = tt.tt_row = 0;
292 if (tt.tt_row == NROW - 1)
312 zz_setscroll(top, bot)
317 tt.tt_scroll_top = top;
318 tt.tt_scroll_bot = bot;
323 zz_set_token(t, s, n)
326 if (tt.tt_nmodes != tt.tt_modes)
327 zz_setmodes(tt.tt_nmodes);
330 zz_setmodes(WWM_REV);
331 (void) sprintf(buf, "%02x=", t);
343 zz_put_token(t, s, n)
346 if (tt.tt_nmodes != tt.tt_modes)
347 zz_setmodes(tt.tt_nmodes);
350 zz_setmodes(WWM_REV);
351 (void) sprintf(buf, "%02x>", t);
366 for (i = n, q = p; --i >= 0;) {
367 register c = (unsigned char) *p++;
375 case 1: /* start input ecc */
380 case 2: /* ack checkpoint */
385 case 3: /* nack checkpoint */
394 } else if (zz_ecc == 1) {
402 } else if (zz_lastc == c) {
419 register c = *p++ & 0x7f;
421 zz_sum = c << 1 | c >> 11 & 1;
430 tt.tt_checksum = zz_checksum;
435 static char x[] = { ctrl('['), 'V', 0, 0 };
437 zz_checksum(x, sizeof x);
439 ttputc(' ' + (zz_sum & 0x3f));
440 ttputc(' ' + (zz_sum >> 6 & 0x3f));
447 tt.tt_insspace = zz_insspace;
448 tt.tt_delchar = zz_delchar;
449 tt.tt_insline = zz_insline;
450 tt.tt_delline = zz_delline;
451 tt.tt_clreol = zz_clreol;
452 tt.tt_clreos = zz_clreos;
453 tt.tt_scroll_down = zz_scroll_down;
454 tt.tt_scroll_up = zz_scroll_up;
455 tt.tt_setscroll = zz_setscroll;
456 tt.tt_availmodes = WWM_REV;
461 tt.tt_start = zz_start;
462 tt.tt_reset = zz_reset;
464 tt.tt_write = zz_write;
465 tt.tt_putc = zz_putc;
466 tt.tt_move = zz_move;
467 tt.tt_clear = zz_clear;
468 tt.tt_setmodes = zz_setmodes;
469 tt.tt_frame = gen_frame;
470 tt.tt_padc = TT_PADC_NONE;
472 tt.tt_set_token = zz_set_token;
473 tt.tt_put_token = zz_put_token;
475 tt.tt_token_max = TOKEN_MAX;
476 tt.tt_set_token_cost = 2;
477 tt.tt_put_token_cost = 1;
478 tt.tt_compress = zz_compress;
479 tt.tt_checksum = zz_checksum;
480 tt.tt_checkpoint = zz_checkpoint;
481 tt.tt_reset = zz_reset;
482 tt.tt_rint = zz_rint;