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 $
48 zz|zapple|perfect apple:\
49 :am:pt:co#80:li#24:le=^H:nd=^F:up=^K:do=^J:\
50 :ho=\E0:ll=\E1:cm=\E=%+ %+ :ch=\E<%+ :cv=\E>%+ :\
51 :cl=\E4:ce=\E2:cd=\E3:rp=\E@%.%+ :\
53 :dc=\Ec:DC=\EC%+ :ic=\Ei:IC=\EI%+ :\
54 :al=\Ea:AL=\EA%+ :dl=\Ed:DL=\ED%+ :\
55 :sf=\Ef:SF=\EF%+ :sr=\Er:SR=\ER%+ :cs=\E?%+ %+ :\
63 extern short gen_frame
[];
65 /* for error correction */
69 /* for checkpointing */
75 if ((tt
.tt_modes
& WWM_REV
) == 0)
78 if (tt
.tt_modes
& WWM_REV
)
106 if (tt
.tt_nmodes
!= tt
.tt_modes
)
107 zz_setmodes(tt
.tt_nmodes
);
109 if (++tt
.tt_col
== NCOL
)
110 tt
.tt_col
= 0, tt
.tt_row
++;
117 if (tt
.tt_nmodes
!= tt
.tt_modes
)
118 zz_setmodes(tt
.tt_nmodes
);
121 if (tt
.tt_col
== NCOL
)
122 tt
.tt_col
= 0, tt
.tt_row
++;
130 if (tt
.tt_row
== row
) {
132 if ((x
= col
- tt
.tt_col
) == 0)
150 if ((col
& 7) == 0 && x
> 0 && x
<= 16) {
160 if (tt
.tt_col
== col
) {
161 switch (row
- tt
.tt_row
) {
189 if (row
== tt
.tt_row
+ 1) {
191 * Do newline first to match the sequence
192 * for scroll down and return
198 if (row
== NROW
- 1) {
204 /* favor local motion for better compression */
205 if (row
== tt
.tt_row
+ 1) {
209 if (row
== tt
.tt_row
- 1) {
224 ttputc(TOKEN_MAX
+ ' ');
232 zz_setscroll(0, NROW
- 1);
239 zz_setscroll(0, NROW
- 1);
240 tt
.tt_modes
= WWM_REV
;
242 tt
.tt_col
= tt
.tt_row
= -10;
267 tt
.tt_col
= tt
.tt_row
= 0;
293 if (tt
.tt_row
== NROW
- 1)
313 zz_setscroll(top
, bot
)
318 tt
.tt_scroll_top
= top
;
319 tt
.tt_scroll_bot
= bot
;
324 zz_set_token(t
, s
, n
)
327 if (tt
.tt_nmodes
!= tt
.tt_modes
)
328 zz_setmodes(tt
.tt_nmodes
);
331 zz_setmodes(WWM_REV
);
332 (void) sprintf(buf
, "%02x=", t
);
344 zz_put_token(t
, s
, n
)
347 if (tt
.tt_nmodes
!= tt
.tt_modes
)
348 zz_setmodes(tt
.tt_nmodes
);
351 zz_setmodes(WWM_REV
);
352 (void) sprintf(buf
, "%02x>", t
);
367 for (i
= n
, q
= p
; --i
>= 0;) {
368 register c
= (unsigned char) *p
++;
376 case 1: /* start input ecc */
381 case 2: /* ack checkpoint */
386 case 3: /* nack checkpoint */
395 } else if (zz_ecc
== 1) {
403 } else if (zz_lastc
== c
) {
420 register c
= *p
++ & 0x7f;
422 zz_sum
= c
<< 1 | c
>> 11 & 1;
431 tt
.tt_checksum
= zz_checksum
;
436 static char x
[] = { ctrl('['), 'V', 0, 0 };
438 zz_checksum(x
, sizeof x
);
440 ttputc(' ' + (zz_sum
& 0x3f));
441 ttputc(' ' + (zz_sum
>> 6 & 0x3f));
448 tt
.tt_insspace
= zz_insspace
;
449 tt
.tt_delchar
= zz_delchar
;
450 tt
.tt_insline
= zz_insline
;
451 tt
.tt_delline
= zz_delline
;
452 tt
.tt_clreol
= zz_clreol
;
453 tt
.tt_clreos
= zz_clreos
;
454 tt
.tt_scroll_down
= zz_scroll_down
;
455 tt
.tt_scroll_up
= zz_scroll_up
;
456 tt
.tt_setscroll
= zz_setscroll
;
457 tt
.tt_availmodes
= WWM_REV
;
462 tt
.tt_start
= zz_start
;
463 tt
.tt_reset
= zz_reset
;
465 tt
.tt_write
= zz_write
;
466 tt
.tt_putc
= zz_putc
;
467 tt
.tt_move
= zz_move
;
468 tt
.tt_clear
= zz_clear
;
469 tt
.tt_setmodes
= zz_setmodes
;
470 tt
.tt_frame
= gen_frame
;
471 tt
.tt_padc
= TT_PADC_NONE
;
473 tt
.tt_set_token
= zz_set_token
;
474 tt
.tt_put_token
= zz_put_token
;
476 tt
.tt_token_max
= TOKEN_MAX
;
477 tt
.tt_set_token_cost
= 2;
478 tt
.tt_put_token_cost
= 1;
479 tt
.tt_compress
= zz_compress
;
480 tt
.tt_checksum
= zz_checksum
;
481 tt
.tt_checkpoint
= zz_checkpoint
;
482 tt
.tt_reset
= zz_reset
;
483 tt
.tt_rint
= zz_rint
;