1 /* @(#)ttzapple.c 8.1 (Berkeley) 6/6/93 */
2 /* $NetBSD: ttzapple.c,v 1.9 2009/04/14 08:50:06 lukem Exp $ */
5 * Copyright (c) 1989, 1993
6 * The Regents of the University of California. All rights reserved.
8 * This code is derived from software contributed to Berkeley by
9 * Edward Wang at The University of California, Berkeley.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 zz|zapple|perfect apple:\
43 :am:pt:co#80:li#24:le=^H:nd=^F:up=^K:do=^J:\
44 :ho=\E0:ll=\E1:cm=\E=%+ %+ :ch=\E<%+ :cv=\E>%+ :\
45 :cl=\E4:ce=\E2:cd=\E3:rp=\E@%.%+ :\
47 :dc=\Ec:DC=\EC%+ :ic=\Ei:IC=\EI%+ :\
48 :al=\Ea:AL=\EA%+ :dl=\Ed:DL=\ED%+ :\
49 :sf=\Ef:SF=\EF%+ :sr=\Er:SR=\ER%+ :cs=\E?%+ %+ :\
57 extern short gen_frame
[];
59 /* for error correction */
63 /* for checkpointing */
66 void zz_checkpoint(void);
67 void zz_checksum(char *, int);
71 void zz_compress(int);
76 void zz_insspace(int);
77 void zz_move(int, int);
78 void zz_put_token(int, const char *, int);
81 int zz_rint(char *, int);
82 void zz_scroll_down(int);
83 void zz_scroll_up(int);
84 void zz_setmodes(int);
85 void zz_setscroll(int, int);
86 void zz_set_token(int, char *, int);
88 void zz_write(const char *, int);
94 if ((tt
.tt_modes
& WWM_REV
) == 0)
97 if (tt
.tt_modes
& WWM_REV
)
127 if (tt
.tt_nmodes
!= tt
.tt_modes
)
128 zz_setmodes(tt
.tt_nmodes
);
130 if (++tt
.tt_col
== NCOL
)
131 tt
.tt_col
= 0, tt
.tt_row
++;
135 zz_write(const char *p
, int n
)
137 if (tt
.tt_nmodes
!= tt
.tt_modes
)
138 zz_setmodes(tt
.tt_nmodes
);
141 if (tt
.tt_col
== NCOL
)
142 tt
.tt_col
= 0, tt
.tt_row
++;
146 zz_move(int row
, int col
)
150 if (tt
.tt_row
== row
) {
152 if ((x
= col
- tt
.tt_col
) == 0)
172 if ((col
& 7) == 0 && x
> 0 && x
<= 16) {
182 if (tt
.tt_col
== col
) {
183 switch (row
- tt
.tt_row
) {
213 if (row
== tt
.tt_row
+ 1) {
215 * Do newline first to match the sequence
216 * for scroll down and return
222 if (row
== NROW
- 1) {
228 /* favor local motion for better compression */
229 if (row
== tt
.tt_row
+ 1) {
233 if (row
== tt
.tt_row
- 1) {
249 ttputc(TOKEN_MAX
+ ' ');
257 zz_setscroll(0, NROW
- 1);
265 zz_setscroll(0, NROW
- 1);
266 tt
.tt_modes
= WWM_REV
;
268 tt
.tt_col
= tt
.tt_row
= -10;
297 tt
.tt_col
= tt
.tt_row
= 0;
323 zz_scroll_down(int n
)
326 if (tt
.tt_row
== NROW
- 1)
348 zz_setscroll(int top
, int bot
)
353 tt
.tt_scroll_top
= top
;
354 tt
.tt_scroll_bot
= bot
;
360 zz_set_token(int t
, char *s
, int n
)
362 if (tt
.tt_nmodes
!= tt
.tt_modes
)
363 zz_setmodes(tt
.tt_nmodes
);
366 zz_setmodes(WWM_REV
);
367 (void) sprintf(buf
, "%02x=", t
);
379 zz_put_token(int t
, const char *s __unused
, int n __unused
)
381 if (tt
.tt_nmodes
!= tt
.tt_modes
)
382 zz_setmodes(tt
.tt_nmodes
);
385 zz_setmodes(WWM_REV
);
386 (void) sprintf(buf
, "%02x>", t
);
394 zz_rint(char *p
, int n
)
401 for (i
= n
, q
= p
; --i
>= 0;) {
402 int c
= (unsigned char) *p
++;
410 case 1: /* start input ecc */
415 case 2: /* ack checkpoint */
420 case 3: /* nack checkpoint */
429 } else if (zz_ecc
== 1) {
437 } else if (zz_lastc
== c
) {
450 zz_checksum(char *p
, int n
)
455 zz_sum
= c
<< 1 | (c
>> 11 & 1);
460 zz_compress(int flag
)
465 tt
.tt_checksum
= zz_checksum
;
471 static char x
[] = { ctrl('['), 'V', 0, 0 };
473 zz_checksum(x
, sizeof x
);
475 ttputc(' ' + (zz_sum
& 0x3f));
476 ttputc(' ' + (zz_sum
>> 6 & 0x3f));
484 tt
.tt_insspace
= zz_insspace
;
485 tt
.tt_delchar
= zz_delchar
;
486 tt
.tt_insline
= zz_insline
;
487 tt
.tt_delline
= zz_delline
;
488 tt
.tt_clreol
= zz_clreol
;
489 tt
.tt_clreos
= zz_clreos
;
490 tt
.tt_scroll_down
= zz_scroll_down
;
491 tt
.tt_scroll_up
= zz_scroll_up
;
492 tt
.tt_setscroll
= zz_setscroll
;
493 tt
.tt_availmodes
= WWM_REV
;
498 tt
.tt_start
= zz_start
;
499 tt
.tt_reset
= zz_reset
;
501 tt
.tt_write
= zz_write
;
502 tt
.tt_putc
= zz_putc
;
503 tt
.tt_move
= zz_move
;
504 tt
.tt_clear
= zz_clear
;
505 tt
.tt_setmodes
= zz_setmodes
;
506 tt
.tt_frame
= gen_frame
;
507 tt
.tt_padc
= TT_PADC_NONE
;
509 tt
.tt_set_token
= zz_set_token
;
510 tt
.tt_put_token
= zz_put_token
;
512 tt
.tt_token_max
= TOKEN_MAX
;
513 tt
.tt_set_token_cost
= 2;
514 tt
.tt_put_token_cost
= 1;
515 tt
.tt_compress
= zz_compress
;
516 tt
.tt_checksum
= zz_checksum
;
517 tt
.tt_checkpoint
= zz_checkpoint
;
518 tt
.tt_reset
= zz_reset
;
519 tt
.tt_rint
= zz_rint
;