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
36 * @(#)ttzapple.c 8.1 (Berkeley) 6/6/93
37 * $FreeBSD: src/usr.bin/window/ttzapple.c,v 1.1.1.1.14.1 2001/05/17 09:45:01 obrien Exp $
38 * $DragonFly: src/usr.bin/window/ttzapple.c,v 1.2 2003/06/17 04:29:34 dillon Exp $
46 zz|zapple|perfect apple:\
47 :am:pt:co#80:li#24:le=^H:nd=^F:up=^K:do=^J:\
48 :ho=\E0:ll=\E1:cm=\E=%+ %+ :ch=\E<%+ :cv=\E>%+ :\
49 :cl=\E4:ce=\E2:cd=\E3:rp=\E@%.%+ :\
51 :dc=\Ec:DC=\EC%+ :ic=\Ei:IC=\EI%+ :\
52 :al=\Ea:AL=\EA%+ :dl=\Ed:DL=\ED%+ :\
53 :sf=\Ef:SF=\EF%+ :sr=\Er:SR=\ER%+ :cs=\E?%+ %+ :\
61 extern short gen_frame[];
63 /* for error correction */
67 /* for checkpointing */
73 if ((tt.tt_modes & WWM_REV) == 0)
76 if (tt.tt_modes & WWM_REV)
104 if (tt.tt_nmodes != tt.tt_modes)
105 zz_setmodes(tt.tt_nmodes);
107 if (++tt.tt_col == NCOL)
108 tt.tt_col = 0, tt.tt_row++;
115 if (tt.tt_nmodes != tt.tt_modes)
116 zz_setmodes(tt.tt_nmodes);
119 if (tt.tt_col == NCOL)
120 tt.tt_col = 0, tt.tt_row++;
128 if (tt.tt_row == row) {
130 if ((x = col - tt.tt_col) == 0)
148 if ((col & 7) == 0 && x > 0 && x <= 16) {
158 if (tt.tt_col == col) {
159 switch (row - tt.tt_row) {
187 if (row == tt.tt_row + 1) {
189 * Do newline first to match the sequence
190 * for scroll down and return
196 if (row == NROW - 1) {
202 /* favor local motion for better compression */
203 if (row == tt.tt_row + 1) {
207 if (row == tt.tt_row - 1) {
222 ttputc(TOKEN_MAX + ' ');
230 zz_setscroll(0, NROW - 1);
237 zz_setscroll(0, NROW - 1);
238 tt.tt_modes = WWM_REV;
240 tt.tt_col = tt.tt_row = -10;
265 tt.tt_col = tt.tt_row = 0;
291 if (tt.tt_row == NROW - 1)
311 zz_setscroll(top, bot)
316 tt.tt_scroll_top = top;
317 tt.tt_scroll_bot = bot;
322 zz_set_token(t, s, n)
325 if (tt.tt_nmodes != tt.tt_modes)
326 zz_setmodes(tt.tt_nmodes);
329 zz_setmodes(WWM_REV);
330 (void) sprintf(buf, "%02x=", t);
342 zz_put_token(t, s, n)
345 if (tt.tt_nmodes != tt.tt_modes)
346 zz_setmodes(tt.tt_nmodes);
349 zz_setmodes(WWM_REV);
350 (void) sprintf(buf, "%02x>", t);
365 for (i = n, q = p; --i >= 0;) {
366 register c = (unsigned char) *p++;
374 case 1: /* start input ecc */
379 case 2: /* ack checkpoint */
384 case 3: /* nack checkpoint */
393 } else if (zz_ecc == 1) {
401 } else if (zz_lastc == c) {
418 register c = *p++ & 0x7f;
420 zz_sum = c << 1 | c >> 11 & 1;
429 tt.tt_checksum = zz_checksum;
434 static char x[] = { ctrl('['), 'V', 0, 0 };
436 zz_checksum(x, sizeof x);
438 ttputc(' ' + (zz_sum & 0x3f));
439 ttputc(' ' + (zz_sum >> 6 & 0x3f));
446 tt.tt_insspace = zz_insspace;
447 tt.tt_delchar = zz_delchar;
448 tt.tt_insline = zz_insline;
449 tt.tt_delline = zz_delline;
450 tt.tt_clreol = zz_clreol;
451 tt.tt_clreos = zz_clreos;
452 tt.tt_scroll_down = zz_scroll_down;
453 tt.tt_scroll_up = zz_scroll_up;
454 tt.tt_setscroll = zz_setscroll;
455 tt.tt_availmodes = WWM_REV;
460 tt.tt_start = zz_start;
461 tt.tt_reset = zz_reset;
463 tt.tt_write = zz_write;
464 tt.tt_putc = zz_putc;
465 tt.tt_move = zz_move;
466 tt.tt_clear = zz_clear;
467 tt.tt_setmodes = zz_setmodes;
468 tt.tt_frame = gen_frame;
469 tt.tt_padc = TT_PADC_NONE;
471 tt.tt_set_token = zz_set_token;
472 tt.tt_put_token = zz_put_token;
474 tt.tt_token_max = TOKEN_MAX;
475 tt.tt_set_token_cost = 2;
476 tt.tt_put_token_cost = 1;
477 tt.tt_compress = zz_compress;
478 tt.tt_checksum = zz_checksum;
479 tt.tt_checkpoint = zz_checkpoint;
480 tt.tt_reset = zz_reset;
481 tt.tt_rint = zz_rint;