DataMuseum.dk

Presents historical artifacts from the history of:

Commodore CBM-900

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about Commodore CBM-900

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦45bcec37b⟧

    Length: 4977 (0x1371)
    Notes: UNIX file
    Names: »cudld.c«

Derivation

└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
    └─⟦f4b8d8c84⟧ UNIX V7 Filesystem
        └─ ⟦this⟧ »cmd/cu/cudld.c« 

Hex Dump

0x0000…0020 2f 2a 0a 20 2a 20 44 6f 77 6e 6c 6f 61 64 69 6e 67 20 72 6f 75 74 69 6e 65 73 20 66 6f 72 20 75   ┆/*  * Downloading routines for u┆
0x0020…0040 73 65 20 62 79 0a 20 2a 20 74 68 65 20 43 55 20 74 65 72 6d 69 6e 61 6c 20 65 6d 75 6c 61 74 6f   ┆se by  * the CU terminal emulato┆
0x0040…0060 72 2e 0a 20 2a 20 41 20 70 61 63 6b 65 74 20 63 6f 6e 73 69 73 74 73 20 6f 66 20 61 6e 20 53 54   ┆r.  * A packet consists of an ST┆
0x0060…0080 58 2c 20 70 61 63 6b 65 74 20 74 79 70 65 20 61 6e 64 20 73 65 71 75 65 6e 63 65 2c 20 69 6e 66   ┆X, packet type and sequence, inf┆
0x0080…00a0 6f 72 6d 61 74 69 6f 6e 2c 0a 20 2a 20 61 6e 20 45 54 58 20 61 6e 64 20 74 68 65 6e 20 61 20 74   ┆ormation,  * an ETX and then a t┆
0x00a0…00c0 77 6f 20 63 68 61 72 61 63 74 65 72 20 43 52 43 20 63 68 61 72 61 63 74 65 72 2e 0a 20 2a 2f 0a   ┆wo character CRC character.  */ ┆
0x00c0…00e0 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 69   ┆ #include <stdio.h> #include <si┆
0x00e0…0100 67 6e 61 6c 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 22 63 75 2e 68 22 0a 0a 50 4b 54 09 72 70 6b   ┆gnal.h> #include "cu.h"  PKT rpk┆
0x0100…0120 74 3b 09 09 09 2f 2a 20 52 65 63 65 69 76 65 64 20 64 61 74 61 20 28 6e 6f 20 77 69 6e 64 6f 77   ┆t;   /* Received data (no window┆
0x0120…0140 69 6e 67 20 79 65 74 29 20 2a 2f 0a 50 4b 54 09 78 70 6b 74 3b 09 09 09 2f 2a 20 54 72 61 6e 73   ┆ing yet) */ PKT xpkt;   /* Trans┆
0x0140…0160 6d 69 74 74 65 64 20 64 61 74 61 20 2a 2f 0a 73 74 61 74 69 63 09 75 6e 73 69 67 6e 65 64 20 61   ┆mitted data */ static unsigned a┆
0x0160…0180 63 63 72 63 3b 09 09 2f 2a 20 46 6f 72 20 69 6e 63 72 65 6d 65 6e 74 61 6c 20 43 12 43 2d 31 36   ┆ccrc;  /* For incremental C C-16┆
0x0180…01a0 20 63 6f 6d 70 75 74 61 74 69 6f 6e 20 2a 2f 0a 69 6e 74 09 6e 72 65 74 72 79 3b 09 09 09 2f 2a   ┆ computation */ int nretry;   /*┆
0x01a0…01c0 20 4e 75 6d 62 65 72 20 6f 66 20 72 65 74 72 69 65 73 20 2a 2f 0a 0a 69 6e 74 09 74 69 6d 65 6f   ┆ Number of retries */  int timeo┆
0x01c0…01e0 75 74 28 29 3b 0a 0a 2f 2a 0a 20 2a 20 45 6e 63 6f 64 65 20 63 68 61 72 61 63 74 65 72 73 20 74   ┆ut();  /*  * Encode characters t┆
0x01e0…0200 68 61 74 20 6e 65 65 64 20 65 73 63 61 70 69 6e 67 20 6f 6e 20 74 68 65 20 6c 69 6e 65 0a 20 2a   ┆hat need escaping on the line  *┆
0x0200…0220 20 41 6e 79 20 65 6e 74 72 79 20 74 68 61 74 20 69 73 20 7a 65 72 6f 20 6e 65 65 64 20 6e 6f 74   ┆ Any entry that is zero need not┆
0x0220…0240 20 62 65 20 74 6f 75 63 68 65 64 2e 0a 20 2a 2f 0a 73 74 61 74 69 63 09 63 68 61 72 09 65 6e 63   ┆ be touched.  */ static char enc┆
0x0240…0260 6f 64 65 5b 32 35 36 5d 20 3d 20 7b 0a 09 30 31 30 30 2c 20 30 31 30 31 2c 20 30 31 30 32 2c 20   ┆ode[256] = {  0100, 0101, 0102, ┆
0x0260…0280 30 31 30 33 2c 20 30 31 30 34 2c 20 30 31 30 35 2c 20 30 31 30 36 2c 20 30 31 30 37 2c 09 09 2f   ┆0103, 0104, 0105, 0106, 0107,  /┆
0x0280…02a0 2a 30 30 30 2d 30 30 37 2a 2f 0a 09 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30   ┆*000-007*/  0000, 0000, 0000, 00┆
0x02a0…02c0 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 09 09 2f 2a 30   ┆00, 0000, 0000, 0000, 0000,  /*0┆
0x02c0…02e0 31 30 2d 30 31 37 2a 2f 0a 09 30 31 32 30 2c 20 30 31 32 31 2c 20 30 31 32 32 2c 20 30 31 32 33   ┆10-017*/  0120, 0121, 0122, 0123┆
0x02e0…0300 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 09 09 2f 2a 30 31 30   ┆, 0000, 0000, 0000, 0000,  /*010┆
0x0300…0320 2d 30 31 37 2a 2f 0a 09 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20   ┆-017*/  0000, 0000, 0000, 0000, ┆
0x0320…0340 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 09 09 2f 2a 30 33 30 2d 30   ┆0000, 0000, 0000, 0000,  /*030-0┆
0x0340…0360 33 37 2a 2f 0a 09 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30   ┆37*/  0000, 0000, 0000, 0000, 00┆
0x0360…0380 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 09 09 2f 2a 30 34 30 2d 30 34 37   ┆00, 0000, 0000, 0000,  /*040-047┆
0x0380…03a0 2a 2f 0a 09 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30   ┆*/  0000, 0000, 0000, 0000, 0000┆
0x03a0…03c0 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 09 09 2f 2a 30 35 30 2d 30 35 37 2a 2f   ┆, 0000, 0000, 0000,  /*050-057*/┆
0x03c0…03e0 0a 09 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20   ┆  0000, 0000, 0000, 0000, 0000, ┆
0x03e0…0400 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 09 09 2f 2a 30 36 30 2d 30 36 37 2a 2f 0a 09   ┆0000, 0000, 0000,  /*060-067*/  ┆
0x0400…0420 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30   ┆0000, 0000, 0000, 0000, 0000, 00┆
0x0420…0440 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 09 09 2f 2a 30 37 30 2d 30 37 37 2a 2f 0a 09 30 30   ┆00, 0000, 0000,  /*070-077*/  00┆
0x0440…0460 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30   ┆00, 0000, 0000, 0000, 0000, 0000┆
0x0460…0480 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 09 09 2f 2a 31 30 30 2d 31 30 37 2a 2f 0a 09 30 30 30 30   ┆, 0000, 0000,  /*100-107*/  0000┆
0x0480…04a0 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20   ┆, 0000, 0000, 0000, 0000, 0000, ┆
0x04a0…04c0 30 30 30 30 2c 20 30 30 30 30 2c 09 09 2f 2a 31 31 30 2d 31 31 37 2a 2f 0a 09 30 30 30 30 2c 20   ┆0000, 0000,  /*110-117*/  0000, ┆
0x04c0…04e0 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30   ┆0000, 0000, 0000, 0000, 0000, 00┆
0x04e0…0500 30 30 2c 20 30 30 30 30 2c 09 09 2f 2a 31 32 30 2d 31 32 37 2a 2f 0a 09 30 30 30 30 2c 20 30 30   ┆00, 0000,  /*120-127*/  0000, 00┆
0x0500…0520 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30   ┆00, 0000, 0000, 0000, 0000, 0000┆
0x0520…0540 2c 20 30 30 30 30 2c 09 09 2f 2a 31 33 30 2d 31 33 37 2a 2f 0a 09 30 30 30 30 2c 20 30 30 30 30   ┆, 0000,  /*130-137*/  0000, 0000┆
0x0540…0560 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20   ┆, 0000, 0000, 0000, 0000, 0000, ┆
0x0560…0580 30 30 30 30 2c 09 09 2f 2a 31 34 30 2d 31 34 37 2a 2f 0a 09 30 30 30 30 2c 20 30 30 30 30 2c 20   ┆0000,  /*140-147*/  0000, 0000, ┆
0x0580…05a0 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30   ┆0000, 0000, 0000, 0000, 0000, 00┆
0x05a0…05c0 30 30 2c 09 09 2f 2a 31 35 30 2d 31 35 37 2a 2f 0a 09 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30   ┆00,  /*150-157*/  0000, 0000, 00┆
0x05c0…05e0 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30   ┆00, 0000, 0000, 0000, 0000, 0000┆
0x05e0…0600 2c 09 09 2f 2a 31 36 30 2d 31 36 37 2a 2f 0a 09 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30   ┆,  /*160-167*/  0000, 0000, 0000┆
0x0600…0620 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 30 30 2c 20 30 30 37 37 2c 09   ┆, 0000, 0000, 0000, 0000, 0077, ┆
0x0620…0640 09 2f 2a 31 37 30 2d 31 37 37 2a 2f 0a 7d 3b 0a 0a 2f 2a 0a 20 2a 20 43 61 6c 6c 6c 65 64 20 74   ┆ /*170-177*/ };  /*  * Callled t┆
0x0640…0660 6f 20 69 6e 69 74 69 61 6c 69 73 65 20 65 76 65 72 79 74 68 69 6e 67 0a 20 2a 20 66 6f 72 20 74   ┆o initialise everything  * for t┆
0x0660…0680 68 65 20 70 61 63 6b 65 74 20 72 6f 75 74 69 6e 65 73 2e 0a 20 2a 2f 0a 70 6b 74 69 6e 69 74 28   ┆he packet routines.  */ pktinit(┆
0x0680…06a0 29 0a 7b 0a 09 73 69 67 6e 61 6c 28 53 49 47 41 4c 52 4d 2c 20 74 69 6d 65 6f 75 74 29 3b 0a 7d   ┆) {  signal(SIGALRM, timeout); }┆
0x06a0…06c0 0a 0a 50 4b 54 20 2a 0a 67 65 74 70 6b 74 28 29 0a 7b 0a 09 72 65 67 69 73 74 65 72 20 75 6e 73   ┆  PKT * getpkt() {  register uns┆
0x06c0…06e0 69 67 6e 65 64 20 63 68 61 72 20 63 3b 0a 09 72 65 67 69 73 74 65 72 20 63 68 61 72 20 2a 63 70   ┆igned char c;  register char *cp┆
0x06e0…0700 3b 0a 09 72 65 67 69 73 74 65 72 20 50 4b 54 20 2a 70 70 3b 0a 0a 09 61 6c 61 72 6d 28 54 4c 45   ┆;  register PKT *pp;   alarm(TLE┆
0x0700…0720 4e 29 3b 0a 09 70 70 20 3d 20 26 72 70 6b 74 3b 0a 09 63 70 20 3d 20 26 70 70 2d 3e 70 5f 74 79   ┆N);  pp = &rpkt;  cp = &pp->p_ty┆
0x0720…0740 70 65 3b 0a 09 70 70 2d 3e 70 5f 66 6c 61 67 73 20 3d 20 30 3b 0a 09 61 63 63 72 63 20 3d 20 30   ┆pe;  pp->p_flags = 0;  accrc = 0┆
0x0740…0760 3b 0a 09 77 68 69 6c 65 20 28 28 63 20 3d 20 73 67 65 74 28 29 29 20 21 3d 20 53 54 58 29 0a 09   ┆;  while ((c = sget()) != STX)  ┆
0x0760…0780 09 69 66 20 28 70 70 2d 3e 70 5f 66 6c 61 67 73 20 21 3d 20 30 29 0a 09 09 09 67 6f 74 6f 20 62   ┆ if (pp->p_flags != 0)    goto b┆
0x0780…07a0 61 64 3b 0a 09 77 68 69 6c 65 20 28 28 63 20 3d 20 73 67 65 74 28 29 29 20 21 3d 20 45 54 58 29   ┆ad;  while ((c = sget()) != ETX)┆
0x07a0…07c0 20 7b 0a 09 09 69 66 20 28 70 70 2d 3e 70 5f 66 6c 61 67 73 20 21 3d 20 30 29 0a 09 09 09 67 6f   ┆ {   if (pp->p_flags != 0)    go┆
0x07c0…07e0 74 6f 20 62 61 64 3b 0a 09 09 69 66 20 28 63 20 3d 3d 20 44 4c 45 29 20 7b 0a 09 09 09 69 66 20   ┆to bad;   if (c == DLE) {    if ┆
0x07e0…0800 28 28 63 20 3d 20 73 67 65 74 28 29 29 20 3d 3d 20 45 4f 46 29 0a 09 09 09 09 62 72 65 61 6b 3b   ┆((c = sget()) == EOF)     break;┆
0x0800…0820 0a 09 09 09 63 20 5e 3d 20 30 31 30 30 3b 0a 09 09 7d 0a 09 09 63 72 63 63 68 61 72 28 63 29 3b   ┆    c ^= 0100;   }   crcchar(c);┆
0x0820…0840 0a 09 09 2a 63 70 2b 2b 20 3d 20 63 3b 0a 09 7d 0a 09 63 68 65 63 6b 63 72 63 28 70 70 29 3b 0a   ┆   *cp++ = c;  }  checkcrc(pp); ┆
0x0840…0860 62 61 64 3a 0a 09 70 70 2d 3e 70 5f 6c 65 6e 20 3d 20 63 70 20 2d 20 28 63 68 61 72 20 2a 29 28   ┆bad:  pp->p_len = cp - (char *)(┆
0x0860…0880 26 70 70 2d 3e 70 5f 74 79 70 65 29 3b 0a 09 61 6c 61 72 6d 28 30 29 3b 0a 09 72 65 74 75 72 6e   ┆&pp->p_type);  alarm(0);  return┆
0x0880…08a0 20 28 70 70 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 50 75 74 20 6f 75 74 20 61 20 70 61 63 6b 65 74   ┆ (pp); }  /*  * Put out a packet┆
0x08a0…08c0 20 6f 66 20 6c 65 6e 67 74 68 20 60 6e 62 27 0a 20 2a 20 62 79 74 65 73 2e 20 20 54 68 69 73 20   ┆ of length `nb'  * bytes.  This ┆
0x08c0…08e0 61 6c 73 6f 20 73 65 6e 64 73 20 74 68 65 0a 20 2a 20 70 72 6f 70 65 72 20 43 52 43 2d 31 36 20   ┆also sends the  * proper CRC-16 ┆
0x08e0…0900 63 68 65 63 6b 20 63 68 61 72 61 63 74 65 72 2e 0a 20 2a 2f 0a 70 75 74 70 6b 74 28 70 70 29 0a   ┆check character.  */ putpkt(pp) ┆
0x0900…0920 50 4b 54 20 2a 70 70 3b 0a 7b 0a 09 72 65 67 69 73 74 65 72 20 75 6e 73 69 67 6e 65 64 20 63 68   ┆PKT *pp; {  register unsigned ch┆
0x0920…0940 61 72 20 2a 63 70 3b 0a 09 72 65 67 69 73 74 65 72 20 75 6e 73 69 67 6e 65 64 20 6e 62 3b 0a 09   ┆ar *cp;  register unsigned nb;  ┆
0x0940…0960 72 65 67 69 73 74 65 72 20 75 6e 73 69 67 6e 65 64 20 63 3b 0a 0a 09 73 70 75 74 28 53 54 58 29   ┆register unsigned c;   sput(STX)┆
0x0960…0980 3b 0a 09 61 63 63 72 63 20 3d 20 30 3b 0a 09 63 70 20 3d 20 26 70 70 2d 3e 70 5f 74 79 70 65 3b   ┆;  accrc = 0;  cp = &pp->p_type;┆
0x0980…09a0 0a 09 6e 62 20 3d 20 70 70 2d 3e 70 5f 6c 65 6e 3b 0a 09 64 6f 20 7b 0a 09 09 6d 70 75 74 28 2a   ┆  nb = pp->p_len;  do {   mput(*┆
0x09a0…09c0 63 70 2b 2b 29 3b 0a 09 7d 20 77 68 69 6c 65 20 28 2d 2d 6e 62 29 3b 0a 09 73 70 75 74 28 45 54   ┆cp++);  } while (--nb);  sput(ET┆
0x09c0…09e0 58 29 3b 0a 09 63 20 3d 20 61 63 63 72 63 3b 0a 09 6d 70 75 74 28 63 26 30 78 46 46 29 3b 0a 09   ┆X);  c = accrc;  mput(c&0xFF);  ┆
0x09e0…0a00 6d 70 75 74 28 63 3e 3e 38 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 4d 61 70 70 65 64 20 70 75 74 74   ┆mput(c>>8); }  /*  * Mapped putt┆
0x0a00…0a20 69 6e 67 20 6f 66 20 61 20 63 68 61 72 61 63 74 65 72 2e 0a 20 2a 2f 0a 6d 70 75 74 28 63 29 0a   ┆ing of a character.  */ mput(c) ┆
0x0a20…0a40 72 65 67 69 73 74 65 72 20 69 6e 74 20 63 3b 0a 7b 0a 09 72 65 67 69 73 74 65 72 20 69 6e 74 20   ┆register int c; {  register int ┆
0x0a40…0a60 63 31 3b 0a 0a 09 69 66 20 28 28 63 31 20 3d 20 65 6e 63 6f 64 65 5b 63 5d 29 20 21 3d 20 30 29   ┆c1;   if ((c1 = encode[c]) != 0)┆
0x0a60…0a80 20 7b 0a 09 09 73 70 75 74 28 44 4c 45 29 3b 0a 09 09 73 70 75 74 28 63 31 29 3b 0a 09 7d 20 65   ┆ {   sput(DLE);   sput(c1);  } e┆
0x0a80…0aa0 6c 73 65 0a 09 09 73 70 75 74 28 63 29 3b 0a 09 63 72 63 63 68 61 72 28 63 29 3b 0a 7d 0a 0a 2f   ┆lse   sput(c);  crcchar(c); }  /┆
0x0aa0…0ac0 2a 0a 20 2a 20 53 65 6e 64 20 74 68 65 20 70 61 63 6b 65 74 20 75 73 69 6e 67 20 74 68 65 20 6c   ┆*  * Send the packet using the l┆
0x0ac0…0ae0 6f 77 65 72 2d 6c 65 76 65 6c 20 72 6f 75 74 69 6e 65 73 20 74 6f 20 64 6f 0a 20 2a 20 72 65 74   ┆ower-level routines to do  * ret┆
0x0ae0…0b00 72 61 6e 73 6d 69 73 73 69 6f 6e 20 6f 6e 20 74 68 65 20 6c 69 6e 65 2e 20 0a 20 2a 2f 0a 73 65   ┆ransmission on the line.   */ se┆
0x0b00…0b20 6e 64 70 6b 74 28 78 70 70 29 0a 72 65 67 69 73 74 65 72 20 50 4b 54 20 2a 78 70 70 3b 0a 7b 0a   ┆ndpkt(xpp) register PKT *xpp; { ┆
0x0b20…0b40 09 72 65 67 69 73 74 65 72 20 50 4b 54 20 2a 72 70 70 3b 0a 0a 09 66 6f 72 20 28 3b 3b 29 20 7b   ┆ register PKT *rpp;   for (;;) {┆
0x0b40…0b60 0a 09 09 70 75 74 70 6b 74 28 78 70 70 29 3b 0a 09 09 72 70 70 20 3d 20 67 65 74 70 6b 74 28 29   ┆   putpkt(xpp);   rpp = getpkt()┆
0x0b60…0b80 3b 0a 09 09 69 66 20 28 72 70 70 2d 3e 70 5f 74 79 70 65 20 3d 3d 20 27 45 27 29 0a 09 09 09 64   ┆;   if (rpp->p_type == 'E')    d┆
0x0b80…0ba0 6f 65 6e 64 28 72 70 70 29 3b 0a 09 09 69 66 20 28 72 70 70 2d 3e 70 5f 66 6c 61 67 73 3d 3d 30   ┆oend(rpp);   if (rpp->p_flags==0┆
0x0ba0…0bc0 20 26 26 20 72 70 70 2d 3e 70 5f 74 79 70 65 3d 3d 27 41 27 29 0a 09 09 09 62 72 65 61 6b 3b 0a   ┆ && rpp->p_type=='A')    break; ┆
0x0bc0…0be0 09 09 2f 2a 20 45 72 72 6f 72 20 2a 2f 0a 09 09 6e 72 65 74 72 79 2b 2b 3b 0a 09 7d 0a 7d 0a 0a   ┆  /* Error */   nretry++;  } }  ┆
0x0be0…0c00 2f 2a 0a 20 2a 20 52 65 63 65 69 76 65 20 61 20 70 61 63 6b 65 74 2e 0a 20 2a 20 4d 61 6e 61 67   ┆/*  * Receive a packet.  * Manag┆
0x0c00…0c20 65 20 74 68 65 20 73 65 71 75 65 6e 63 65 20 6e 75 6d 62 65 72 73 2e 0a 20 2a 2f 0a 50 4b 54 20   ┆e the sequence numbers.  */ PKT ┆
0x0c20…0c40 2a 0a 72 63 76 70 6b 74 28 73 65 71 6e 6f 29 0a 75 6e 73 69 67 6e 65 64 20 73 65 71 6e 6f 3b 0a   ┆* rcvpkt(seqno) unsigned seqno; ┆
0x0c40…0c60 7b 0a 09 72 65 67 69 73 74 65 72 20 50 4b 54 20 2a 72 70 70 3b 0a 09 72 65 67 69 73 74 65 72 20   ┆{  register PKT *rpp;  register ┆
0x0c60…0c80 75 6e 73 69 67 6e 65 64 20 72 73 65 71 3b 0a 0a 09 66 6f 72 20 28 3b 3b 29 20 7b 0a 09 09 72 70   ┆unsigned rseq;   for (;;) {   rp┆
0x0c80…0ca0 70 20 3d 20 67 65 74 70 6b 74 28 29 3b 0a 09 09 69 66 20 28 72 70 70 2d 3e 70 5f 66 6c 61 67 73   ┆p = getpkt();   if (rpp->p_flags┆
0x0ca0…0cc0 20 21 3d 20 30 29 20 7b 0a 09 09 09 6e 72 65 74 72 79 2b 2b 3b 0a 09 09 09 6e 61 6b 70 6b 74 28   ┆ != 0) {    nretry++;    nakpkt(┆
0x0cc0…0ce0 29 3b 0a 09 09 09 63 6f 6e 74 69 6e 75 65 3b 0a 09 09 7d 0a 09 09 69 66 20 28 72 70 70 2d 3e 70   ┆);    continue;   }   if (rpp->p┆
0x0ce0…0d00 5f 74 79 70 65 20 3d 3d 20 27 45 27 29 0a 09 09 09 64 6f 65 6e 64 28 72 70 70 29 3b 0a 09 09 72   ┆_type == 'E')    doend(rpp);   r┆
0x0d00…0d20 73 65 71 20 3d 20 28 72 70 70 2d 3e 70 5f 73 65 71 5b 31 5d 20 3c 3c 20 38 29 20 2b 20 72 70 70   ┆seq = (rpp->p_seq[1] << 8) + rpp┆
0x0d20…0d40 2d 3e 70 5f 73 65 71 5b 30 5d 3b 0a 09 09 69 66 20 28 72 70 70 2d 3e 70 5f 74 79 70 65 3d 3d 27   ┆->p_seq[0];   if (rpp->p_type=='┆
0x0d40…0d60 49 27 20 26 26 20 72 73 65 71 21 3d 73 65 71 6e 6f 29 0a 09 09 09 6e 61 6b 70 6b 74 28 29 3b 0a   ┆I' && rseq!=seqno)    nakpkt(); ┆
0x0d60…0d80 09 09 65 6c 73 65 0a 09 09 09 62 72 65 61 6b 3b 0a 09 7d 0a 09 72 65 74 75 72 6e 20 28 72 70 70   ┆  else    break;  }  return (rpp┆
0x0d80…0da0 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 6e 65 72 61 74 65 20 61 20 4e 61 6b 20 70 61 63 6b 65   ┆); }  /*  * Generate a Nak packe┆
0x0da0…0dc0 74 0a 20 2a 2f 0a 6e 61 6b 70 6b 74 28 29 0a 7b 0a 09 78 70 6b 74 2e 70 5f 74 79 70 65 20 3d 20   ┆t  */ nakpkt() {  xpkt.p_type = ┆
0x0dc0…0de0 27 4e 27 3b 0a 09 78 70 6b 74 2e 70 5f 6c 65 6e 20 3d 20 31 3b 0a 09 70 75 74 70 6b 74 28 26 78   ┆'N';  xpkt.p_len = 1;  putpkt(&x┆
0x0de0…0e00 70 6b 74 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 6e 65 72 61 74 65 20 61 6e 20 61 63 6b 6e 6f   ┆pkt); }  /*  * Generate an ackno┆
0x0e00…0e20 77 6c 65 64 67 65 6d 65 6e 74 0a 20 2a 2f 0a 61 63 6b 70 6b 74 28 29 0a 7b 0a 09 78 70 6b 74 2e   ┆wledgement  */ ackpkt() {  xpkt.┆
0x0e20…0e40 70 5f 74 79 70 65 20 3d 20 27 41 27 3b 0a 09 78 70 6b 74 2e 70 5f 6c 65 6e 20 3d 20 31 3b 0a 09   ┆p_type = 'A';  xpkt.p_len = 1;  ┆
0x0e40…0e60 70 75 74 70 6b 74 28 26 78 70 6b 74 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 6e 65 72 61 74 65   ┆putpkt(&xpkt); }  /*  * Generate┆
0x0e60…0e80 20 61 6e 20 65 6e 64 20 70 61 63 6b 65 74 2e 0a 20 2a 2f 0a 65 6e 64 70 6b 74 28 73 2c 20 66 29   ┆ an end packet.  */ endpkt(s, f)┆
0x0e80…0ea0 0a 72 65 67 69 73 74 65 72 20 63 68 61 72 20 2a 73 3b 0a 69 6e 74 20 66 3b 0a 7b 0a 09 72 65 67   ┆ register char *s; int f; {  reg┆
0x0ea0…0ec0 69 73 74 65 72 20 75 6e 73 69 67 6e 65 64 20 6e 3b 0a 0a 09 78 70 6b 74 2e 70 5f 74 79 70 65 20   ┆ister unsigned n;   xpkt.p_type ┆
0x0ec0…0ee0 3d 20 27 45 27 3b 0a 09 6e 20 3d 20 73 74 72 6c 65 6e 28 73 29 2b 31 3b 0a 09 78 70 6b 74 2e 70   ┆= 'E';  n = strlen(s)+1;  xpkt.p┆
0x0ee0…0f00 5f 6c 65 6e 20 3d 20 6e 20 2b 20 33 3b 0a 09 73 74 72 6e 63 70 79 28 26 78 70 6b 74 2e 70 5f 64   ┆_len = n + 3;  strncpy(&xpkt.p_d┆
0x0f00…0f20 61 74 61 5b 30 5d 2c 20 73 2c 20 6e 29 3b 0a 09 70 75 74 70 6b 74 28 26 78 70 6b 74 29 3b 0a 09   ┆ata[0], s, n);  putpkt(&xpkt);  ┆
0x0f20…0f40 69 66 20 28 66 29 0a 09 09 67 65 74 70 6b 74 28 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 52 65 61 64   ┆if (f)   getpkt(); }  /*  * Read┆
0x0f40…0f60 20 69 6e 20 61 20 43 52 43 20 66 72 6f 6d 20 74 68 65 20 6c 69 6e 65 0a 20 2a 20 61 6e 64 20 63   ┆ in a CRC from the line  * and c┆
0x0f60…0f80 6f 6d 70 61 72 65 20 69 74 20 74 6f 20 74 68 65 20 65 78 70 65 63 74 65 64 20 6f 6e 65 2e 0a 20   ┆ompare it to the expected one.  ┆
0x0f80…0fa0 2a 2f 0a 63 68 65 63 6b 63 72 63 28 70 70 29 0a 50 4b 54 20 2a 70 70 3b 0a 7b 0a 09 72 65 67 69   ┆*/ checkcrc(pp) PKT *pp; {  regi┆
0x0fa0…0fc0 73 74 65 72 20 69 6e 74 20 63 3b 0a 09 72 65 67 69 73 74 65 72 20 69 6e 74 20 69 3b 0a 09 72 65   ┆ster int c;  register int i;  re┆
0x0fc0…0fe0 67 69 73 74 65 72 20 75 6e 73 69 67 6e 65 64 20 63 72 63 3b 0a 09 73 74 61 74 69 63 20 75 6e 73   ┆gister unsigned crc;  static uns┆
0x0fe0…1000 69 67 6e 65 64 20 63 68 61 72 20 78 5b 32 5d 3b 0a 0a 09 66 6f 72 20 28 69 3d 30 3b 20 69 3c 32   ┆igned char x[2];   for (i=0; i<2┆
0x1000…1020 3b 20 69 2b 2b 29 20 7b 0a 09 09 69 66 20 28 28 63 20 3d 20 73 67 65 74 28 29 29 20 3d 3d 20 45   ┆; i++) {   if ((c = sget()) == E┆
0x1020…1040 4f 46 29 0a 09 09 09 62 72 65 61 6b 3b 0a 09 09 69 66 20 28 63 20 3d 3d 20 44 4c 45 29 20 7b 0a   ┆OF)    break;   if (c == DLE) { ┆
0x1040…1060 09 09 09 69 66 20 28 28 63 20 3d 20 73 67 65 74 28 29 29 20 3d 3d 20 45 4f 46 29 0a 09 09 09 09   ┆   if ((c = sget()) == EOF)     ┆
0x1060…1080 62 72 65 61 6b 3b 0a 09 09 09 63 20 5e 3d 20 30 31 30 30 3b 0a 09 09 7d 0a 09 09 78 5b 69 5d 20   ┆break;    c ^= 0100;   }   x[i] ┆
0x1080…10a0 3d 20 63 3b 0a 09 7d 0a 09 63 72 63 20 3d 20 78 5b 30 5d 20 7c 20 28 78 5b 31 5d 3c 3c 38 29 3b   ┆= c;  }  crc = x[0] | (x[1]<<8);┆
0x10a0…10c0 0a 09 69 66 20 28 63 72 63 20 21 3d 20 61 63 63 72 63 29 0a 09 09 70 70 2d 3e 70 5f 66 6c 61 67   ┆  if (crc != accrc)   pp->p_flag┆
0x10c0…10e0 73 20 7c 3d 20 50 43 52 43 3b 20 65 6c 73 65 0a 09 09 70 70 2d 3e 70 5f 66 6c 61 67 73 20 26 3d   ┆s |= PCRC; else   pp->p_flags &=┆
0x10e0…1100 20 7e 50 43 52 43 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 43 61 6c 6c 65 64 20 6f 6e 20 6c 69 6e 65 20   ┆ ~PCRC; }  /*  * Called on line ┆
0x1100…1120 74 69 6d 65 6f 75 74 2e 0a 20 2a 2f 0a 74 69 6d 65 6f 75 74 28 29 0a 7b 0a 09 73 69 67 6e 61 6c   ┆timeout.  */ timeout() {  signal┆
0x1120…1140 28 53 49 47 41 4c 52 4d 2c 20 74 69 6d 65 6f 75 74 29 3b 0a 09 72 70 6b 74 2e 70 5f 66 6c 61 67   ┆(SIGALRM, timeout);  rpkt.p_flag┆
0x1140…1160 73 20 7c 3d 20 50 54 4f 55 54 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 43 52 43 20 43 61 6c 63 75 6c 61   ┆s |= PTOUT; }  /*  * CRC Calcula┆
0x1160…1180 74 69 6f 6e 20 75 73 69 6e 67 20 74 68 65 20 42 4e 52 20 66 61 73 74 20 4d 61 74 72 69 78 20 4d   ┆tion using the BNR fast Matrix M┆
0x1180…11a0 75 6c 74 69 70 6c 79 0a 20 2a 20 61 6e 64 20 54 61 62 6c 65 20 4c 6f 6f 6b 75 70 20 41 6c 67 6f   ┆ultiply  * and Table Lookup Algo┆
0x11a0…11c0 72 69 74 68 6d 0a 20 2a 2f 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 79 74 61 62 5b 5d 20 3d 20 7b   ┆rithm  */  static int ytab[] = {┆
0x11c0…11e0 0a 20 20 20 20 20 20 20 20 30 2c 20 30 31 34 36 30 30 31 2c 20 30 31 35 34 30 30 31 2c 20 30 31   ┆         0, 0146001, 0154001, 01┆
0x11e0…1200 32 30 30 30 2c 20 30 31 37 30 30 30 31 2c 20 30 33 36 30 30 30 2c 0a 09 30 32 34 30 30 30 2c 20   ┆2000, 0170001, 036000,  024000, ┆
0x1200…1220 30 31 36 32 30 30 31 2c 20 30 31 32 30 30 30 31 2c 20 30 36 36 30 30 30 2c 20 30 37 34 30 30 30   ┆0162001, 0120001, 066000, 074000┆
0x1220…1240 2c 0a 09 30 31 33 32 30 30 31 2c 20 30 35 30 30 30 30 2c 20 30 31 31 36 30 30 31 2c 20 30 31 30   ┆,  0132001, 050000, 0116001, 010┆
0x1240…1260 34 30 30 31 2c 20 30 34 32 30 30 30 0a 7d 3b 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 7a 74 61 62   ┆4001, 042000 };  static int ztab┆
0x1260…1280 5b 5d 20 3d 20 7b 0a 20 20 20 20 20 20 20 20 30 2c 20 30 31 34 30 33 30 31 2c 20 30 31 34 30 36   ┆[] = {         0, 0140301, 01406┆
0x1280…12a0 30 31 2c 20 30 35 30 30 2c 20 30 31 34 31 34 30 31 2c 20 30 31 37 30 30 2c 0a 20 20 20 20 20 20   ┆01, 0500, 0141401, 01700,       ┆
0x12a0…12c0 20 20 30 31 32 30 30 2c 20 30 31 34 31 31 30 31 2c 20 30 31 34 33 30 30 31 2c 20 30 33 33 30 30   ┆  01200, 0141101, 0143001, 03300┆
0x12c0…12e0 2c 20 30 33 36 30 30 2c 20 30 31 34 33 35 30 31 2c 0a 20 20 20 20 20 20 20 20 30 32 34 30 30 2c   ┆, 03600, 0143501,         02400,┆
0x12e0…1300 20 30 31 34 32 37 30 31 2c 20 30 31 34 32 32 30 31 2c 20 30 32 31 30 30 0a 7d 3b 0a 0a 63 72 63   ┆ 0142701, 0142201, 02100 };  crc┆
0x1300…1320 63 68 61 72 28 63 29 0a 72 65 67 69 73 74 65 72 20 63 3b 0a 7b 0a 20 20 20 20 20 20 20 20 61 63   ┆char(c) register c; {         ac┆
0x1320…1340 63 72 63 20 5e 3d 20 63 3b 0a 20 20 20 20 20 20 20 20 61 63 63 72 63 20 3d 20 28 61 63 63 72 63   ┆crc ^= c;         accrc = (accrc┆
0x1340…1360 3e 3e 38 29 20 5e 20 7a 74 61 62 5b 61 63 63 72 63 26 30 78 46 5d 20 5e 20 79 74 61 62 5b 28 61   ┆>>8) ^ ztab[accrc&0xF] ^ ytab[(a┆
0x1360…1371 63 63 72 63 3e 3e 34 29 26 30 78 46 5d 3b 0a 7d 0a   ┆ccrc>>4)&0xF]; } ┆