home *** CD-ROM | disk | FTP | other *** search
/ The CIA World Factbook 1992 / k3bimage.iso / sel / 02 / 0035 / jmodem.h < prev    next >
Encoding:
Text File  |  1991-12-02  |  13.8 KB  |  215 lines

  1. /****************************************************************************/
  2. /*   FILE JMODEM.H                                                          */
  3. /*   Created 11-JAN-1990                Richard B. Johnson                  */
  4. /*                                      405 Broughton Drive                 */
  5. /*                                      Beverly, Massachusetts 01915        */
  6. /*                                      BBS (508) 922-3166                  */
  7. /*                                                                          */
  8. /*    This program requires about 67k of free RAM to execute properly.      */
  9. /*    If you have 66k or less, it will execute, but the screens will        */
  10. /*    not be written or replaced properly. If you have only 64k, the        */
  11. /*    program will exit with an error message.                              */
  12. /*                                                                          */
  13. /*    Revision History:                                                     */
  14. /*    V3.00   Beta test                  11-FEB-1990   Richard B. Johnson   */
  15. /*    V3.01   First release              18-FEB-1990   Richard B. Johnson   */
  16. /*    V3.02   Revised                    19-FEB-1990   Richard B. Johnson   */
  17. /*                                                                          */
  18. /*      (1)   A bug in MicroSoft _calloc()  allocates overlapping           */
  19. /*            buffers so data files were getting corrupted. I had           */
  20. /*            used both _calloc() and _malloc() at the same time and        */
  21. /*            they didn't like it. I changed the memory allocation          */
  22. /*            to _malloc() only and it seems to work okay.                  */
  23. /*                                                                          */
  24. /*      (2)   While debugging, I found some structures I didn't need and    */
  25. /*            removed them. Changed some code to accommodate.               */
  26. /*                                                                          */
  27. /*      (3)   Added a file-size during downloads.                           */
  28. /*                                                                          */
  29. /*      (4)   Changed code in the data encoding (compression) routine       */
  30. /*            in an attempt to speed it up.                                 */
  31. /*                                                                          */
  32. /*    V3.03   Revised                   20-FEB-1990  Richard B. Johnson     */
  33. /*                                                                          */
  34. /*      (5)   Fixed bug in compression routine where the loop wasn't        */
  35. /*            terminating properly, adding random characters. Bug was       */
  36. /*            created during V3.02 change.                                  */
  37. /*                                                                          */
  38. /*    V3.04   Revised                   27-FEB-1990  Richard B. Johnson     */
  39. /*                                                                          */
  40. /*      (1)   Modified the block-size routine and the receive-block         */
  41. /*            routine in an attempt to improve the noise immunity.          */
  42. /*            Does not abort even if you whistle into the telephone         */
  43. /*            during uploads and downloads. Waits 5 seconds to clear        */
  44. /*            the interrupt buffer when a bad block-size is received.       */
  45. /*                                                                          */
  46. /*      (2)   Added a 1/2 second wait for modem status when opening         */
  47. /*            channel. This might accommodate slow modems response to       */
  48. /*            RTS.                                                          */
  49. /*                                                                          */
  50. /*    V3.05   Revised                   22-MAR-1990  Richard B. Johnson     */
  51. /*                                                                          */
  52. /*      (1)   Removed _sprintf() runtime library calls to shorten           */
  53. /*            the code. Saved about 4k.                                     */
  54. /*                                                                          */
  55. /*      (2)   Removed extra spaces in the signon-logo to shorten            */
  56. /*            the program size.                                             */
  57. /*                                                                          */
  58. /*      (3)   Changed the method of creating a fixed-length string          */
  59. /*            for both the block size and cps numbers which saved about     */
  60. /*            800 bytes of program size.                                    */
  61. /*                                                                          */
  62. /*      (4)   Changed numerous array indexes in JMODEM_F.C to pointers      */
  63. /*            to reduce code size. Saved a few hundred bytes and should     */
  64. /*            improve speed of screen output.                               */
  65. /*                                                                          */
  66. /*      (5)   Created a local _puts() routine which saved over 6k from the  */
  67. /*            MicroSoft C runtime library version. (JMODEM_F.C)             */
  68. /*                                                                          */
  69. /*                                                                          */
  70. /****************************************************************************/
  71. /*                  Parameters that are specific to JMODEM                  */
  72. /****************************************************************************/
  73. #define VERS            "Version 3.05"  /* Version number               */
  74. #define _8K             0x2000          /* 4096 bytes                   */
  75. #define BLK_SIZ         0x200           /* Starting block size          */
  76. #define OVRHD           0x06            /* Private, JMODEM overhead     */
  77. #define DAT_LEN         _8K + 1024      /* Data buffer length           */
  78. #define DAT_MAX         _8K             /* Max block length             */
  79. #define OPEN_READ       0x01            /* Private OPEN file function   */
  80. #define CREATE          0x02            /* Private CREATE file function */
  81. #define WRITE           0x03            /* Private WRITE file function  */
  82. #define CLOSE           0x04            /* Private CLOSE file function  */
  83. #define DELETE          0x05            /* Private DELETE file function */
  84. #define READ            0x06            /* Private READ file function   */
  85. #define GET_CRC         0x00            /* Private Get CRC function     */
  86. #define SET_CRC         0x01            /* Private Set CRC function     */
  87. #define NORM            0x01            /* Private, show normal data    */
  88. #define COMP            0x02            /* Private, show compressed     */
  89. #define EOF_            0x04            /* Private, show end of file    */
  90. #define TIMOUT          0x5A            /* Timeout (ticks) for read     */
  91. #define EOT             0x04            /* "D" - 64                     */
  92. #define ACK             0x06            /* "F" - 64                     */
  93. #define NAK             0x15            /* "U" - 64                     */
  94. #define SYN             0x16            /* "V" - 64                     */
  95. #define CAN             0x18            /* "X" - 64                     */
  96. #define SCR_SGN         0x01            /* Signon screen                */
  97. #define SCR_BOX         0x02            /* Write box on the screen      */
  98. #define SCR_TXT         0x03            /* Write text to x/y address    */
  99. #define SCR_STA         0x04            /* Write status box             */
  100. #define SCR_FIL         0x05            /* Write open file box          */
  101. #define SCR_FOK         0x06            /* File open okay               */
  102. #define SCR_FNF         0x07            /* File not found               */
  103. #define SCR_FCR         0x08            /* Can't create the file        */
  104. #define SCR_FRN         0x09            /* Renamed the file             */
  105. #define SCR_SYS         0x0A            /* Show system parameters       */
  106. #define SCR_SYT         0x0B            /* Show trans synchronization   */
  107. #define SCR_SYR         0x0C            /* Show Receive synchronization */
  108. #define SCR_END         0x0D            /* Exit all screens             */
  109. #define JM_NRM          0x00            /* Normal exit                  */
  110. #define JM_FNF          0x01            /* File not found               */
  111. #define JM_REN          0x02            /* Can't rename the file        */
  112. #define JM_CRE          0x03            /* Can't create the file        */
  113. #define JM_MEM          0x04            /* No memory available          */
  114. #define JM_CAR          0x05            /* Modem carrier failed         */
  115. #define JM_SYN          0x06            /* Can't synchronize            */
  116. #define JM_ABT          0x07            /* Aborted                      */
  117. #define JM_CMD          0x08            /* Command-line error           */
  118. #define JM_TIM          0x09            /* Time-out                     */
  119. #define JM_FAT          0x0A            /* Fatal error                  */
  120. #define JM_MAX          0xFFFF          /* Maximum buffer space exceeded*/
  121.  
  122. /****************************************************************************/
  123. /*                     Structures and templates                             */
  124. /****************************************************************************/
  125. typedef struct
  126.         {                               /* Structure for JMODEM status  */
  127.         unsigned short  s_blk;          /* Block being sent / received  */
  128.         unsigned short  s_len;          /* Length of the block          */
  129.         unsigned long   s_byt;          /* Bytes so far                 */
  130.         unsigned short  s_cps;          /* Speed, characters / second   */
  131.         unsigned char  *s_sta;          /* Pointer to current status    */
  132.         } SYS;
  133.  
  134. typedef struct                          /* JMODEM block header structure */
  135.         {
  136.         unsigned short len;             /* Block length                  */
  137.         unsigned char blk_typ;          /* Kind of block EOF, COMP, etc  */
  138.         unsigned char blk_num;          /* Block number (starts at 1 )   */
  139.         unsigned char blk_dat;          /* First data character          */
  140.         } JBUF;
  141.  
  142. /****************************************************************************/
  143. /*                   External function prototypes                           */
  144. /****************************************************************************/
  145. extern short screen(
  146.              short,                     /* Function (in SCREEN.H)       */
  147.              SYS *,                     /* Pointer to status block      */
  148.              char * );                  /* Text                         */
  149. extern unsigned short
  150.        open_chan(unsigned short);       /* Open communications channel  */
  151. extern unsigned short
  152.        close_chan(unsigned short);      /* Close communications channel */
  153. extern unsigned short
  154.        read_chan(unsigned short,
  155.        unsigned char *);                /* Write communications channel */
  156. extern unsigned short
  157.        write_chan(unsigned short,
  158.        unsigned char *);                /* Read communications channel  */
  159. extern unsigned short
  160.        send_blk(unsigned short,
  161.                 SYS *,
  162.        unsigned char *);                /* Send JMODEM block            */
  163. extern unsigned short
  164.        recv_blk(unsigned short *,
  165.        unsigned char *);                /* Receive JMODEM block         */
  166. extern unsigned short
  167.        encode(unsigned short,
  168.        unsigned char *,
  169.        unsigned char *);                /* Data compression routine     */
  170. extern unsigned short
  171.        decode(unsigned short,
  172.        unsigned char *,
  173.        unsigned char *);                /* Data expansion routine       */
  174. extern unsigned short
  175.        calc_crc(unsigned short,
  176.        unsigned short,
  177.        unsigned char *);                /* Calculate CRC                */
  178. extern unsigned short
  179.        file_io(unsigned short,
  180.        short *,
  181.        unsigned char *,
  182.        unsigned short);                 /* File I/O                     */
  183. extern char
  184.        *get_inp(unsigned short,         /* Get input file-name          */
  185.        char **);
  186. extern char get_fun(unsigned short,     /* Get function (S or R)        */
  187.        char **);
  188. extern char get_prt(unsigned short,
  189.        char **);                        /* Get port (1 - 4)             */
  190. extern void
  191.        disp(void);                      /* Display 'usage' message      */
  192. extern unsigned short
  193.        get_port(char);                  /* Convert port number          */
  194. extern unsigned char
  195.       *allocate_memory(unsigned short); /* Allocate memory              */
  196. extern void flush (void);               /* Flush the interrupt buffer   */
  197. extern unsigned short tx_sync(void);    /* Synchronize during transmit  */
  198. extern unsigned short rx_sync(void);    /* Synchronize during receive   */
  199. extern unsigned short port;             /* Port number                  */
  200. extern unsigned short timer;            /* Global timer                 */
  201. extern SYS syst;                        /* In JMODEM_A.C                */
  202. #ifdef NOENV                            /* If a compiler command        */
  203. void _setenvp(void);                    /* Dummy routine prototype      */
  204. void _setenvp()                         /* Dummy routine                */
  205. {}
  206. #endif
  207.  
  208. #pragma intrinsic (inp, outp)           /* Generate in-line code here   */
  209. #pragma intrinsic (_disable, _enable)
  210. #pragma intrinsic (memcpy, _rotl)
  211. #pragma check_stack(off)               /* No checking between functions */
  212.  
  213. /****************************************************************************/
  214. /*********************** E N D  OF  M O D U L E *****************************/
  215.