home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / comm / jmodem.zip / JMODEM.H < prev    next >
Text File  |  1990-06-20  |  21KB  |  285 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. /*    V3.06   Revised                   07-APR-1990  Richard B. Johnson     */
  70. /*                                                                          */
  71. /*      (1)   Put the filename text into the syst structure as a pointer    */
  72. /*            to char. This allowed me to save 56 bytes of code and now     */
  73. /*            only two parameters are passed to the _screen() function.     */
  74. /*                                                                          */
  75. /*      (2)   Modified the syst structure and supporting code.              */
  76. /*                                                                          */
  77. /*      (3)   Moved all external data and functions to the JMODEM.H file.   */
  78. /*                                                                          */
  79. /*      (4)   Moved _disp() "usage" module to JMODEM_F.C                    */
  80. /*                                                                          */
  81. /*      (5)   Changed arrays in JMODEM_B.C to pointers to reduce code-      */
  82. /*            size. Eliminated _strcpy() from the command-line parsing      */
  83. /*            routines. Brought the code-size to less than 12,000 bytes.    */
  84. /*                                                                          */
  85. /*      (6)   Reduced the code-size in the _encode(), _decode(), and        */
  86. /*            _crc() routines in JMODEM_D.C. Removed shifts to improve      */
  87. /*            speed and replaced the shifts with pointers for altering      */
  88. /*            portions of the strings.                                      */
  89. /*                                                                          */
  90. /*      (7)   Made a _cancel() routine in JMODEM_A.C to send ^Xes upon      */
  91. /*            abort.                                                        */
  92. /*                                                                          */
  93. /*      (8)   Removed the bit being set "OUT 1" via the modem-control       */
  94. /*            register in the "open" routine in JMODEM_E.C. This was        */
  95. /*            causing some internal modems to lock up as they use this      */
  96. /*            bit for something. "OUT 2" is used to enable IRQ on most      */
  97. /*            clone RS-232 boards and modems. The Heathkit HZ-100 boards    */
  98. /*            will probably not work anymore because they use "OUT 1".      */
  99. /*                                                                          */
  100. /*    V3.07   Revised                   03-MAY-1990  Richard B. Johnson     */
  101. /*                                                                          */
  102. /*      (1)   Rewrote code to remove the requirement for a file buffer.     */
  103. /*            This means that this buffer does not need to be allocated,    */
  104. /*            saving about 8k of RAM at run-time.  ( JMODEM_A.C )           */
  105. /*                                                                          */
  106. /*            Program now only requires 52k of free RAM to execute okay.    */
  107. /*                                                                          */
  108. /*      (2)   Changed the header file, JMODEM.H, and function calling       */
  109. /*            procedures to file_io() and screen() to allow variable-       */
  110. /*            length parameter-lists. This eliminates the requirement       */
  111. /*            to pass a NULL as a place-holder on procedures that don't     */
  112. /*            always require all possible parameters to be passed. This     */
  113. /*            saved about 50 bytes of code.                                 */
  114. /*                                                                          */
  115. /*      (3)   Changed the "Usage" prompt and code to reduce program size.   */
  116. /*            Saved about 60 bytes.                                         */
  117. /*                                                                          */
  118. /*      (4)   Changed keyboard break interrupt in JMODEM_E.C so it sets     */
  119. /*            the global timer to zero as well as setting the abort flag.   */
  120. /*                                                                          */
  121. /****************************************************************************/
  122. /*                  Parameters that are specific to JMODEM                  */
  123. /****************************************************************************/
  124. #define VERS            "Version 3.07"      /* Version number               */
  125. #define _8K             0x2000              /* 4096 bytes                   */
  126. #define BLK_SIZ         0x200               /* Starting block size          */
  127. #define OVRHD           0x06                /* Private, JMODEM overhead     */
  128. #define DAT_LEN         _8K + 0x400         /* Data buffer length           */
  129. #define DAT_MAX         _8K                 /* Max block length             */
  130. #define OPEN_READ       0x01                /* Private OPEN file function   */
  131. #define CREATE          0x02                /* Private CREATE file function */
  132. #define WRITE           0x03                /* Private WRITE file function  */
  133. #define CLOSE           0x04                /* Private CLOSE file function  */
  134. #define DELETE          0x05                /* Private DELETE file function */
  135. #define READ            0x06                /* Private READ file function   */
  136. #define GET_CRC         0x00                /* Private Get CRC function     */
  137. #define SET_CRC         0x01                /* Private Set CRC function     */
  138. #define NORM            0x01                /* Private, show normal data    */
  139. #define COMP            0x02                /* Private, show compressed     */
  140. #define EOF_            0x04                /* Private, show end of file    */
  141. #define TIMOUT          0x5A                /* Timeout (ticks) for read     */
  142. #define EOT             0x04                /* "D" - 64                     */
  143. #define ACK             0x06                /* "F" - 64                     */
  144. #define NAK             0x15                /* "U" - 64                     */
  145. #define SYN             0x16                /* "V" - 64                     */
  146. #define CAN             0x18                /* "X" - 64                     */
  147. #define SCR_SGN         0x01                /* Signon screen                */
  148. #define SCR_BOX         0x02                /* Write box on the screen      */
  149. #define SCR_TXT         0x03                /* Write text to x/y address    */
  150. #define SCR_STA         0x04                /* Write status box             */
  151. #define SCR_FIL         0x05                /* Write open file box          */
  152. #define SCR_FOK         0x06                /* File open okay               */
  153. #define SCR_FNF         0x07                /* File not found               */
  154. #define SCR_FCR         0x08                /* Can't create the file        */
  155. #define SCR_FRN         0x09                /* Renamed the file             */
  156. #define SCR_SYS         0x0A                /* Show system parameters       */
  157. #define SCR_SYT         0x0B                /* Show trans synchronization   */
  158. #define SCR_SYR         0x0C                /* Show Receive synchronization */
  159. #define SCR_FLG         0x0D                /* Show status flag             */
  160. #define SCR_END         0x0E                /* Exit all screens             */
  161. #define JM_NRM          0x00                /* Normal exit                  */
  162. #define JM_FNF          0x01                /* File not found               */
  163. #define JM_REN          0x02                /* Can't rename the file        */
  164. #define JM_CRE          0x03                /* Can't create the file        */
  165. #define JM_MEM          0x04                /* No memory available          */
  166. #define JM_CAR          0x05                /* Modem carrier failed         */
  167. #define JM_SYN          0x06                /* Can't synchronize            */
  168. #define JM_ABT          0x07                /* Aborted                      */
  169. #define JM_CMD          0x08                /* Command-line error           */
  170. #define JM_TIM          0x09                /* Time-out                     */
  171. #define JM_FAT          0x0A                /* Fatal error                  */
  172. #define JM_MAX          0xFFFF              /* Maximum buffer space exceeded*/
  173.  
  174. /****************************************************************************/
  175. /*                     Structures and templates                             */
  176. /****************************************************************************/
  177. typedef struct
  178.         {                                   /* Structure for JMODEM status  */
  179.         unsigned short  s_blk;              /* Block being sent / received  */
  180.         unsigned short  s_len;              /* Length of the block          */
  181.         unsigned long   s_byt;              /* Bytes so far                 */
  182.         unsigned short  s_cps;              /* Speed, characters / second   */
  183.         unsigned char  *s_sta;              /* Pointer to current status    */
  184.         unsigned char  *s_txt;              /* Pointer to information text  */
  185.         } SYS;
  186.  
  187. typedef struct                             /* JMODEM block header structure */
  188.         {
  189.         unsigned short len;                /* Block length                  */
  190.         unsigned char blk_typ;             /* Kind of block EOF, COMP, etc  */
  191.         unsigned char blk_num;             /* Block number (starts at 1 )   */
  192.         unsigned char blk_dat;             /* First data character          */
  193.         } JBUF;
  194.  
  195. /****************************************************************************/
  196. /*                   External function prototypes                           */
  197. /****************************************************************************/
  198. #ifdef SCREEN
  199.     extern void screen(short, SYS *);       /* Function (in SCREEN.H)       */
  200. #else
  201.     extern void screen(short,...);          /* Show variable length list    */
  202. #endif
  203.  
  204. extern unsigned short open_chan(            /* Open communications channel  */
  205.                 unsigned short);            /* Communications port number   */
  206. extern unsigned short close_chan(           /* Close communications channel */
  207.                 unsigned short);            /* Communications port number   */
  208. extern unsigned short read_chan(            /* Read communications channel  */
  209.                 unsigned short,             /* Bytes to read                */
  210.                 unsigned char *);           /* Pointer to the buffer        */
  211. extern unsigned short write_chan(           /* Write communications channel */
  212.                 unsigned short,             /* Bytes to write (send)        */
  213.                 unsigned char *);           /* Pointer to the buffer        */
  214. extern unsigned short send_blk(             /* Send JMODEM block            */
  215.                 unsigned short,             /* Block length                 */
  216.                 SYS *,                      /* Pointer to status structure  */
  217.                 unsigned char *);           /* Pointer to the data buffer   */
  218. extern unsigned short recv_blk(             /* Receive JMODEM block         */
  219.                 unsigned short *,           /* Pointer to the block length  */
  220.                 unsigned char *);           /* Pointer to the data buffer   */
  221. extern unsigned short encode(               /* Compress the data            */
  222.                 unsigned short,             /* Length of the input data     */
  223.                 unsigned char *,            /* Pointer to the input buffer  */
  224.                 unsigned char *);           /* Pointer to the output buffer */
  225. extern unsigned short decode(               /* Expand compressed data       */
  226.                 unsigned short,             /* Data length                  */
  227.                 unsigned char *,            /* Pointer to the input buffer  */
  228.                 unsigned char *);           /* Pointer to the output buffer */
  229. extern unsigned short calc_crc(             /* Calculate CRC                */
  230.                 unsigned short,             /* Function, GET or SET         */
  231.                 unsigned short,             /* Length of the data buffer    */
  232.                 unsigned char *);           /* Pointer to the data buffer   */
  233.  
  234. #ifdef FILE_IO
  235.     extern unsigned short file_io(          /* File I/O                     */
  236.                 unsigned short,             /* Function code                */
  237.                 short *,                    /* Pointer to the file handle   */
  238.                 unsigned char *,            /* Pointer to the buffer        */
  239.                 unsigned short);            /* Data buffer length           */
  240. #else
  241.     extern unsigned short file_io(          /* File I/O                     */
  242.                 unsigned short,             /* Function code                */
  243.                 short *,...);               /* Variable length param list   */
  244. #endif
  245.  
  246. extern unsigned char *get_inp(              /* Get input file-name          */
  247.                 unsigned short,             /* Number of arguments          */
  248.                 char **);                   /* Pointer to list of pointers  */
  249. extern unsigned char get_fun(               /* Get function (S or R)        */
  250.                 unsigned short,             /* Number of arguments          */
  251.                 char **);                   /* Pointer to command strings   */
  252. extern unsigned short get_port(             /* Get port (1 - 4)             */
  253.                 unsigned short,             /* Number of arguments          */
  254.                 char **);                   /* Pointer to command strings   */
  255. extern void disp(void);                     /* Display 'usage' message      */
  256. extern unsigned char *allocate_memory(      /* Allocate memory              */
  257.                 unsigned short);            /* Bytes to allocate            */
  258. extern void flush (void);                   /* Flush the interrupt buffer   */
  259. extern void cancel(void);                   /* Send ^Xes to cancel transfer */
  260. extern unsigned short tx_sync(void);        /* Synchronize during transmit  */
  261. extern unsigned short rx_sync(void);        /* Synchronize during receive   */
  262. /****************************************************************************/
  263. /*                   Global variables and structures                        */
  264. /****************************************************************************/
  265. extern unsigned char *int_buffer;           /* pointer to interrupt buffer  */
  266. extern unsigned short user_abort;           /* User abort flag              */
  267. extern unsigned short port;                 /* Port number                  */
  268. extern unsigned short timer;                /* Global timer                 */
  269. extern unsigned char abrt[];                /* Six messages in JMODEM_F.C   */
  270. extern unsigned char okay[];
  271. extern unsigned char retry[];
  272. extern unsigned char done[];
  273. extern unsigned char flow[];
  274. extern unsigned char malfail[];
  275. extern SYS syst;                            /* Structure in JMODEM_A.C      */
  276. /****************************************************************************/
  277. /*                         Preprocessor directives                          */
  278. /****************************************************************************/
  279. #pragma intrinsic (inp, outp)               /* Generate in-line code here   */
  280. #pragma intrinsic (_disable, _enable)
  281. #pragma intrinsic (memcpy, _rotl)
  282. #pragma check_stack(off)                   /* No checking between functions */
  283. /****************************************************************************/
  284. /*********************** E N D  OF  M O D U L E *****************************/
  285.