home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / ftp.vapor.com / microdot-1 / md1_src_02.lzx / xprzmodem.h < prev    next >
C/C++ Source or Header  |  2014-05-19  |  7KB  |  170 lines

  1. /*
  2.  *  xprzmodem.h: Definitions for xprzmodem.library;
  3.  *  Version 2.0, 28 October 1989, by Rick Huebner.
  4.  *  Released to the Public Domain; do as you like with this code.
  5.  */
  6.  
  7. /* #define DEBUGLOG 1 */
  8.  
  9. #define mysprintf sprintf
  10.  
  11. #include <proto/exec.h>
  12. #include <devices/timer.h>
  13.  
  14. /* Return codes */
  15. #define OK        0
  16. #define ERROR   (-1)
  17. #define TIMEOUT (-2)
  18. #define RCDO    (-3)
  19.  
  20. /* Relevant control characters */
  21. #define CR    ('M' & 0x1F)    /* ^M */
  22. #define DLE    ('P' & 0x1F)    /* ^P */
  23. #define XON    ('Q' & 0x1F)    /* ^Q */
  24. #define XOFF    ('S' & 0x1F)    /* ^S */
  25. #define CAN    ('X' & 0x1F)    /* ^X */
  26. #define CPMEOF    ('Z' & 0x1F)    /* ^Z */
  27.  
  28. /* Misc. program constants */
  29. #define LZMANAG          0    /* Default ZMODEM file management mode */
  30. #define LZTRANS          0    /* Default ZMODEM file transport mode */
  31. #define PATHLEN        256    /* What's the max legal path size? */
  32. #define CONFIGLEN     32    /* Max length of transfer options string */
  33. #define KSIZE           8192    /* Max allowable packet size */
  34. #define MINBLOCK     64    /* Min allowable packet size */
  35. #define MAXGOODNEEDED  8192    /* Max # good bytes req'd to bump packet size */
  36.  
  37. /* Provision for future 7-bit ZMODEM; for now, there's no difference */
  38. #define sendline xsendline
  39.  
  40. /*
  41.  * Replacement for global variables normally used, in order to make code
  42.  * fully reentrant; each invocation allocs their own Vars, and passes the
  43.  * struct pointer down through the entire program so they're always available.
  44.  * Pointer to this struct is usually able to be a register variable, so access
  45.  * is no worse than any stack variable (all register-relative).  Kinda
  46.  * kludgey, but the original ZModem code design depended on lots of globals,
  47.  * and I didn't want to redesign the whole damn thing.  Besides, it's more
  48.  * efficient than constantly pushing & popping args all over the place.
  49.  */
  50.  
  51. struct Vars
  52. {
  53.    struct XPR_IO io;          /* Copy of XProto IO struct passed by term prog. */
  54.    struct XPR_UPDATE __aligned xpru; /* Scratchpad xpr_update() control struct */
  55.    struct timeval __aligned Starttime; /* Time transfer started */
  56.    UBYTE __aligned Rxhdr [4]; /* Received header */
  57.    UBYTE Txhdr [4];           /* Transmitted header */
  58.    UBYTE Msgbuf [128];        /* Scratchpad buffer for printing messages */
  59.    UBYTE Filename [PATHLEN];  /* Name of the file being up/downloaded */
  60.    UBYTE Pktbuf [KSIZE];      /* File data packet buffer */
  61.    UBYTE Modembuf [256];      /* Input buffer for data from modem */
  62.    UBYTE Outbuf [KSIZE * 2 + 256]; /* Output buffer for data to modem */
  63.    UBYTE *Modemchar;          /* Next char to get from Modembuf */
  64.    long  File;                /* Handle of file being transferred */
  65.    long  Baud;                /* BPS setting of modem */
  66.    long  Strtpos;             /* Starting byte position of transfer */
  67.    long  Fsize;               /* Size of file being transferred */
  68.    long  Rxbytes;             /* Number of bytes received so far */
  69.    long  Rxpos;               /* Received file position */
  70.    long  Txpos;               /* Transmitted file position */
  71.    short Filcnt;              /* Number of files opened for transmission */
  72.    short Errcnt;              /* Number of files unreadable */
  73.    short Noroom;              /* Flags 'insufficient disk space' errors */
  74.    short Rxbuflen;            /* Largest frame they're willing to xfer */
  75.    short Tframlen;            /* Largest frame we're willing to xfer */
  76.    short Rxtimeout;           /* Tenths of seconds to wait for something */
  77.    short Tryzhdrtype;         /* Header type to send corresp to Last rx close */
  78.    short Modemcount;          /* Number of bytes available in Modembuf */
  79.    short Outbuflen;           /* Number of bytes currently stored in Outbuf */
  80.    short Rxframeind;          /* ZBIN or ZHEX; type of frame received */
  81.    short Txfcs32;          /* TRUE means send binary frame with 32 bit FCS */
  82.    short Rxflags;          /* Temp register */
  83.    short Wantfcs32;          /* want to send 32 bit FCS */
  84.    short Crc32t;          /* Display flag indicates 32 bit CRC being sent */
  85.    short Crc32;              /* Display flag indicates 32 bit CRC being recd */
  86.    short Rxtype;              /* Type of header received */
  87.    short Rxcount;             /* Count of data bytes received */
  88.    short Znulls;              /* Number of nulls to send at begin of ZDATA hdr */
  89.    short ErrorLimit;          /* How many sequential errors before abort */
  90.    char  Rxbinary;            /* Force binary mode download? */
  91.    char  Rxascii;             /* Force text mode download? */
  92.    char  Thisbinary;          /* Receive this file in binary mode? */
  93.    char  Lzconv;              /* Suggested binary/text mode for uploads */
  94.    char  Eofseen;             /* Text-mode EOF marker (^Z) rec'd on download? */
  95.    UBYTE Zconv;               /* ZMODEM file conversion request */
  96.    UBYTE Zmanag;              /* ZMODEM file management request */
  97.    UBYTE Ztrans;              /* ZMODEM file transport request */
  98.    UBYTE Lastsent;            /* Last text char written by putsec() */
  99.    UBYTE Lastzsent;           /* Last char sent by zsendline() */
  100.    UBYTE Fileflush;           /* Flush file I/O buffer before closing? */
  101.    UBYTE Attn[ZATTNLEN + 1];  /* Attention string rx sends to tx on err */
  102.    };
  103.  
  104. /*
  105.  * Option settings and other variables needed outside of XProtocolSend/Receive;
  106.  * separated from rest of Vars so that huge Vars struct doesn't have to be
  107.  * allocated except during transfers.  Pointer to this struct kept in xpr_data.
  108.  */
  109. struct SetupVars
  110. {
  111.    UBYTE *matchptr, *bufpos;
  112.    short buflen;
  113.    UBYTE option_t[2], option_o[2], option_b[8], option_f[8], option_e[8],
  114.      option_s[4];
  115.    UBYTE option_r[4], option_a[4], option_d[4], option_k[4], option_p[256];
  116.    };
  117.  
  118. /* Function prototypes */
  119.  
  120. long XProtocolSend(struct XPR_IO *xio);
  121.  
  122. long XProtocolReceive(struct XPR_IO *xio);
  123.  
  124. long XProtocolCleanup(struct XPR_IO *xio);
  125. struct Vars *setup(struct XPR_IO *io);
  126. UBYTE *find_option(UBYTE *buf, UBYTE option);
  127. void  set_textmode(struct Vars *v);
  128. void  canit(struct Vars *v);
  129. void  zmputs(struct Vars *v, UBYTE *s);
  130. void  xsendline(struct Vars *v, UBYTE c);
  131. void  sendbuf(struct Vars *v);
  132. short readock(struct Vars *v, short tenths);
  133. char  char_avail(struct Vars *v);
  134. void  update_rate(struct Vars *v);
  135. long  bfopen(struct Vars *v, UBYTE *mode);
  136. void  bfclose(struct Vars *v);
  137. void  bfseek(struct Vars *v, long pos);
  138. long  bfread(struct Vars *v, UBYTE *buf, long length);
  139. long  bfwrite(struct Vars *v, UBYTE *buf, long length);
  140. void  ioerr(struct XPR_IO *io, char *msg);
  141. void  upderr(struct Vars *v, char *msg);
  142. void  updmsg(struct Vars *v, char *msg);
  143. #define getfree() (0x7fffffff)
  144. char  exist(struct Vars *v);
  145. #ifdef DEBUGLOG
  146. void  dlog(struct Vars *v, UBYTE *s);
  147. #endif
  148.  
  149. void  zsbhdr(struct Vars *v, USHORT type);
  150. void  zshhdr(struct Vars *v, USHORT type);
  151. void  zsdata(struct Vars *v, short length, USHORT frameend);
  152. int zrdata(struct Vars *v, UBYTE *buf, short length);
  153. int zrdat32(struct Vars *v, UBYTE *buf, short length);
  154. int zgethdr(struct Vars *v);
  155. int zrbhdr(struct Vars *v);
  156. int zrbhdr32(struct Vars *v);
  157. int zrhhdr(struct Vars *v);
  158. void  zputhex(struct Vars *v, UBYTE c);
  159. void  zsendline(struct Vars *v, UBYTE c);
  160. int zgethex(struct Vars *v);
  161. int zdlread(struct Vars *v);
  162. int noxrd7(struct Vars *v);
  163. void  stohdr(struct Vars *v, long pos);
  164. long  rclhdr(struct Vars *v);
  165.  
  166. extern ULONG UnixTimeOffset;
  167. ULONG getsystime(struct timeval *tv);
  168.  
  169. /* End of XprZmodem.h source */
  170.