1 /* $NetBSD: ttzapple.c,v 1.9 2009/04/14 08:50:06 lukem Exp $ */
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Edward Wang at The University of California, Berkeley.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
38 static char sccsid
[] = "@(#)ttzapple.c 8.1 (Berkeley) 6/6/93";
40 __RCSID("$NetBSD: ttzapple.c,v 1.9 2009/04/14 08:50:06 lukem Exp $");
50 zz|zapple|perfect apple:\
51 :am:pt:co#80:li#24:le=^H:nd=^F:up=^K:do=^J:\
52 :ho=\E0:ll=\E1:cm=\E=%+ %+ :ch=\E<%+ :cv=\E>%+ :\
53 :cl=\E4:ce=\E2:cd=\E3:rp=\E@%.%+ :\
55 :dc=\Ec:DC=\EC%+ :ic=\Ei:IC=\EI%+ :\
56 :al=\Ea:AL=\EA%+ :dl=\Ed:DL=\ED%+ :\
57 :sf=\Ef:SF=\EF%+ :sr=\Er:SR=\ER%+ :cs=\E?%+ %+ :\
65 extern short gen_frame
[];
67 /* for error correction */
71 /* for checkpointing */
74 void zz_checkpoint(void);
75 void zz_checksum(char *, int);
79 void zz_compress(int);
84 void zz_insspace(int);
85 void zz_move(int, int);
86 void zz_put_token(int, const char *, int);
89 int zz_rint(char *, int);
90 void zz_scroll_down(int);
91 void zz_scroll_up(int);
92 void zz_setmodes(int);
93 void zz_setscroll(int, int);
94 void zz_set_token(int, char *, int);
96 void zz_write(const char *, int);
102 if ((tt
.tt_modes
& WWM_REV
) == 0)
105 if (tt
.tt_modes
& WWM_REV
)
135 if (tt
.tt_nmodes
!= tt
.tt_modes
)
136 zz_setmodes(tt
.tt_nmodes
);
138 if (++tt
.tt_col
== NCOL
)
139 tt
.tt_col
= 0, tt
.tt_row
++;
143 zz_write(const char *p
, int n
)
145 if (tt
.tt_nmodes
!= tt
.tt_modes
)
146 zz_setmodes(tt
.tt_nmodes
);
149 if (tt
.tt_col
== NCOL
)
150 tt
.tt_col
= 0, tt
.tt_row
++;
154 zz_move(int row
, int col
)
158 if (tt
.tt_row
== row
) {
160 if ((x
= col
- tt
.tt_col
) == 0)
178 if ((col
& 7) == 0 && x
> 0 && x
<= 16) {
188 if (tt
.tt_col
== col
) {
189 switch (row
- tt
.tt_row
) {
217 if (row
== tt
.tt_row
+ 1) {
219 * Do newline first to match the sequence
220 * for scroll down and return
226 if (row
== NROW
- 1) {
232 /* favor local motion for better compression */
233 if (row
== tt
.tt_row
+ 1) {
237 if (row
== tt
.tt_row
- 1) {
253 ttputc(TOKEN_MAX
+ ' ');
261 zz_setscroll(0, NROW
- 1);
269 zz_setscroll(0, NROW
- 1);
270 tt
.tt_modes
= WWM_REV
;
272 tt
.tt_col
= tt
.tt_row
= -10;
301 tt
.tt_col
= tt
.tt_row
= 0;
327 zz_scroll_down(int n
)
330 if (tt
.tt_row
== NROW
- 1)
352 zz_setscroll(int top
, int bot
)
357 tt
.tt_scroll_top
= top
;
358 tt
.tt_scroll_bot
= bot
;
364 zz_set_token(int t
, char *s
, int n
)
366 if (tt
.tt_nmodes
!= tt
.tt_modes
)
367 zz_setmodes(tt
.tt_nmodes
);
370 zz_setmodes(WWM_REV
);
371 (void) sprintf(buf
, "%02x=", t
);
383 zz_put_token(int t
, const char *s __unused
, int n __unused
)
385 if (tt
.tt_nmodes
!= tt
.tt_modes
)
386 zz_setmodes(tt
.tt_nmodes
);
389 zz_setmodes(WWM_REV
);
390 (void) sprintf(buf
, "%02x>", t
);
398 zz_rint(char *p
, int n
)
405 for (i
= n
, q
= p
; --i
>= 0;) {
406 int c
= (unsigned char) *p
++;
414 case 1: /* start input ecc */
419 case 2: /* ack checkpoint */
424 case 3: /* nack checkpoint */
433 } else if (zz_ecc
== 1) {
441 } else if (zz_lastc
== c
) {
454 zz_checksum(char *p
, int n
)
459 zz_sum
= c
<< 1 | (c
>> 11 & 1);
464 zz_compress(int flag
)
469 tt
.tt_checksum
= zz_checksum
;
475 static char x
[] = { ctrl('['), 'V', 0, 0 };
477 zz_checksum(x
, sizeof x
);
479 ttputc(' ' + (zz_sum
& 0x3f));
480 ttputc(' ' + (zz_sum
>> 6 & 0x3f));
488 tt
.tt_insspace
= zz_insspace
;
489 tt
.tt_delchar
= zz_delchar
;
490 tt
.tt_insline
= zz_insline
;
491 tt
.tt_delline
= zz_delline
;
492 tt
.tt_clreol
= zz_clreol
;
493 tt
.tt_clreos
= zz_clreos
;
494 tt
.tt_scroll_down
= zz_scroll_down
;
495 tt
.tt_scroll_up
= zz_scroll_up
;
496 tt
.tt_setscroll
= zz_setscroll
;
497 tt
.tt_availmodes
= WWM_REV
;
502 tt
.tt_start
= zz_start
;
503 tt
.tt_reset
= zz_reset
;
505 tt
.tt_write
= zz_write
;
506 tt
.tt_putc
= zz_putc
;
507 tt
.tt_move
= zz_move
;
508 tt
.tt_clear
= zz_clear
;
509 tt
.tt_setmodes
= zz_setmodes
;
510 tt
.tt_frame
= gen_frame
;
511 tt
.tt_padc
= TT_PADC_NONE
;
513 tt
.tt_set_token
= zz_set_token
;
514 tt
.tt_put_token
= zz_put_token
;
516 tt
.tt_token_max
= TOKEN_MAX
;
517 tt
.tt_set_token_cost
= 2;
518 tt
.tt_put_token_cost
= 1;
519 tt
.tt_compress
= zz_compress
;
520 tt
.tt_checksum
= zz_checksum
;
521 tt
.tt_checkpoint
= zz_checkpoint
;
522 tt
.tt_reset
= zz_reset
;
523 tt
.tt_rint
= zz_rint
;