home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / intel / 2716 < prev    next >
Encoding:
Text File  |  1992-12-15  |  14.2 KB  |  316 lines

  1. Newsgroups: comp.sys.intel
  2. Path: sparky!uunet!world!hsmith
  3. From: hsmith@world.std.com (heath smith)
  4. Subject: Re: Intel hHEX format
  5. Message-ID: <BzBvx4.H3w@world.std.com>
  6. Keywords: 8051,"intel hex"
  7. Organization: The World Public Access UNIX, Brookline, MA
  8. References: <martling.724456494@phage.cshl.org>
  9. Date: Wed, 16 Dec 1992 01:24:38 GMT
  10. Lines: 304
  11.  
  12.               BINTEL.DOC  Version 1.0  February 1987            page 1 of 6
  13.  
  14.                      BINTEL.COM Binary-Intel Hex Convertor
  15.                               -- R. M. Baldwin --
  16.  
  17.     BINTEL is a utility program for inter-converting binary files and Intel
  18.     Hex files.  Intel Hex files are a form of ASCII representation of binary
  19.     data with error-checking.  The program was written as a utility for
  20.     downloading binary files after building Steve Ciarcia's Circuit Cellar
  21.     Serial EPROM Programmer ("CCSP" or "SEPP"), described in the October
  22.     1986 issue of Byte.
  23.  
  24.     In Intel Hex format, binary data are encoded in groups of records called
  25.     'paragraphs', typically 16 bytes per paragraph.  Each paragraph is begun
  26.     with a colon (':') and ended with a carriage return.  For example:
  27.  
  28.     Binary data = (in hex)
  29.  
  30.      31 80 08 3E 89 D3 03 AF D3 00 D3 01 06 07 11 FF
  31.      FF 21 FF FF 19 DA 14 00 10 F7 3E 10 D3
  32.  
  33.     Intel Hex Representation (in ASCII) =
  34.  
  35.      :100000003180083E89D303AFD300D301060711FF27 (1st paragraph  = 16 bytes)
  36.      :0D001000FF21FFFF19DA140010F73E10D396       (2nd paragraph  = 13 bytes)
  37.      :00000001FF                                 (last paragraph =  0 bytes)
  38.  
  39.     Meaning of each field:
  40.  
  41.     Colon  Data    Address of  Paragr  Data (pairs of nibbles)    CRC
  42.            Count    1st data   Type     in ASCII form          (check sum)
  43.                       byte
  44.  
  45.       :     10       0000       00      31 80 08 3E ...    FF     27
  46.       :     0D       0010       00      FF 21 FF FF ... D3        96
  47.       :     00       0000       01      {none}                    FF
  48.  
  49.     All numbers are in upper-case Ascii hexadecimal representation.
  50.  
  51.     Data count: # data bytes in the paragraph.
  52.     Address:    Address (offset) where 1st data byte goes.
  53.     Para type:  00 = not the end yet, 01 = last paragraph.
  54.     CRC:        Check sum = 2's complement of the 8-bit addition  of the
  55.                 binary values of all the other bytes. (ie the sum of the CRC
  56.                 plus all the other bytes = 0).
  57.     Delimiter:  Each "paragraph" is ended with a carriage return.
  58.  
  59.     The last paragraph is a null paragraph, with zero data bytes; its para-
  60.     graph attribute is '01'.
  61.  
  62.  
  63.     This program is hereby donated to the public domain for non-commercial
  64.     use and distribution without restrictions (and without guarantees).  I
  65.     would appreciate feedback on the program,  especially bugs.  I can be
  66.     reached on an irregular basis on BIX (bixname rmb).
  67.  
  68.                      Ron Baldwin, Concord, CA, March, 1987.
  69.               BINTEL.DOC  Version 1.0  February 1987            page 2 of 6
  70.  
  71.                        REQUIREMENTS FOR RUNNING BINTEL.COM
  72.                        -----------------------------------
  73.  
  74.     MS-DOS or PC-DOS 2.00 or later,  at least one disk drive. BINTEL uses
  75.     standard DOS function calls and doesn't do anything specific to IBM-
  76.     compatible hardware, so it *should* work on any MS DOS machine. I have
  77.     used it successfully  with a true blue IBM PC, several flavors of Com-
  78.     paqs, and a Hewlett-Packard HP110 portable.  It was developed on a PC
  79.     clone built from Display Telecommunications Corporation MegaBoard, with
  80.     448K RAM on the motherboard, a NEC V20 CPU, and 20 MB hard disk.
  81.  
  82.     The disk storage space required can be calculated roughly from the
  83.     following relationship:
  84.  
  85.     Hex = 13 + [(Bin div 16) * (13 + 2*16)] + [13 + 2 * (Bin mod 16)] + 1
  86.  
  87.     where Hex = size of Hex file in bytes
  88.           Bin = size of binary file in bytes
  89.  
  90.  
  91.                                  CAVEATS & NOTES
  92.                                  ---------------
  93.  
  94.       1.  Obviously, the program was written to satisfy my idiosyncrasies
  95.     and with my applications in mind. Not being a professional programmer,
  96.     the program may not be coded in the most efficient way.
  97.  
  98.       2. The binary to hex conversion was done first as a quick-and-dirty
  99.     proposition, just to download a hardware diagnostic routine; then I went
  100.     back to add the hex to binary conversion. I tried to redo it to avoid
  101.     overlapping functions, but there are still redundancies and inconsistent
  102.     ways of doing things.
  103.  
  104.       3. The assembly source is in BINTEL.ASM. It was assembled with Micro-
  105.     soft Macro Assembler (MASM) 4.00.  All the equates and macros are listed
  106.     near the beginning of the program.
  107.  
  108.       4. The buffers for input and output data can be enlarged for faster
  109.     running with large files. The variables BinBufSize and Hex BufSize con-
  110.     tain the number of bytes allocated to each. They are defined in terms of
  111.     the number of 'paragraphs', whose length in bytes is given by RecLen. As
  112.     written, the binary buffer is set at 16 paragraphs (256 bytes) and the
  113.     hex buffer is set at 3 times the binary for a total of 1 K allocated to
  114.     data buffers.
  115.  
  116.               BINTEL.DOC  Version 1.0  February 1987            page 3 of 6
  117.  
  118.                         DIRECTIONS FOR USE OF BINTEL.COM
  119.                         --------------------------------
  120.  
  121.     BINARY FILE TO INTEL HEX FILE CONVERSION
  122.  
  123.     To convert a binary file into Intel hex format, enter BINTEL with the
  124.     name of the file to be converted.  If no extension is entered, then a
  125.     default extension will be supplied.  The default file extensions are BIN
  126.     and COM, in that order of priority; ie, if files TEST.BIN & TEST.COM are
  127.     both in the current directory, then TEST.BIN will be processed in pref-
  128.     erence to TEST.COM, unless you specifically enter BINTEL TEST.COM.  A
  129.     file with the same file name but with the extension HEX will be created
  130.     for output.  You can specify any extension by typing it in explicitly;
  131.     enter the filename with only a dot if there is no extension.
  132.  
  133.       * NOTE: no check is made to prevent over-writing an existing file. *
  134.  
  135.     Examples:
  136.  
  137.      bintel test     converts TEST.BIN to TEST.HEX
  138.      bintel test.    converts TEST     to TEST.HEX
  139.      bintel foo.bar  converts FOO.BAR  to  FOO.HEX
  140.      bintel c:\path1\path2\foobar
  141.             converts C:\PATH1\PATH2\FOOBAR.BIN to C:\PATH1\PATH2\FOOBAR.HEX
  142.  
  143.     The extension BIN was chosen to avoid confusion with MS DOS executable
  144.     COM files.  Since my application is to program 2716 EPROMs for a process
  145.     controller, using Z80 code, the starting address (offset) is set arbit-
  146.     rarily at zero.  Any relocation can usually be handled at the EPROM pro-
  147.     grammer end if needed. (Future versions may allow specifying the start-
  148.     ing address).
  149.  
  150.     Sixteen byte paragraphs are chosen by default.  If not an even multiple
  151.     of 16 bytes, the next to last paragraph will contain less than 16 data
  152.     bytes. The last paragraph is always a null paragraph with 0 data bytes.
  153.  
  154.     Paragraphs are terminated with carriage return, line feed to make the
  155.     HEX files easier to examine with text editors or from DOS. Since most
  156.     terminal emulator communications programs transmit ASCII data terminated
  157.     with carriage return only, there is no conflict, and anyway, strict
  158.     interpretation of Intel hex format should ignore anything between the
  159.     carriage return and the next ':'.  BINTEL itself is even less picky (see
  160.     below).
  161.  
  162.     The progress of the conversion is shown by displaying the hexadecimal
  163.     paragraph address continuously.  The address of the last paragraph with
  164.     data will be showing when the program ends.
  165.  
  166.               BINTEL.DOC  Version 1.0  February 1987            page 4 of 6
  167.  
  168.     INTEL HEX FILE TO BINARY FILE CONVERSION
  169.  
  170.     The command switch /H directs BINTEL to interpret the filename as an
  171.     ASCII file in Intel Hex format and to convert it to a binary file. The
  172.     default extension for the input file is HEX, but can be overridden by
  173.     explicitly entering an extension; the output file is invariably given
  174.     the extension BIN.
  175.  
  176.      * NOTE: no check is made to prevent over-writing an existing file. *
  177.  
  178.     Examples:
  179.  
  180.       bintel test  /h     converts TEST.HEX to TEST.BIN
  181.       bintel test.asc /h  converts TEST.ASC to TEST.BIN
  182.       bintel test. /h     converts TEST     to TEST.BIN
  183.  
  184.     In processing the [ASCII] file, BINTEL ignores everything but what comes
  185.     between the ':' and the carriage return signifying the end of the para-
  186.     graph.  This means that the file can be liberally interspersed with com-
  187.     ments, if desired, so long as a colon (':') does not appear in the text.
  188.     Also, all characters other than '0' to '9' and 'A' to 'F' (upper or low-
  189.     er case) are ignored, so that spaces can be used, if desired, to improve
  190.     the legibility of the ASCII file.  Actually, even embedded carriage re-
  191.     turns and control characters can be present, since the program counts
  192.     the paragraph from the data byte value and the Intel syntax rather than
  193.     looking for the carriage return.  Some very strange looking "text" files
  194.     can thus be converted.
  195.  
  196.     Although the structure of the Intel specification appears to allow flex-
  197.     ibility in the order in which the paragraphs are arranged (for instance,
  198.     the paragraph at address 01F0 might appear earlier in the file than add-
  199.     ress 0020), BINTEL assumes that the paragraphs are arranged in contig-
  200.     uous ascending order, and assembles the binary file accordingly. If it
  201.     detects a discontinuity, it will give an error message as a warning, but
  202.     otherwise it ignores the file's address value.
  203.  
  204.     BINTEL keeps track of the CRC, and if its calculation doesn't agree with
  205.     the value stored in the paragraph, it will flag and display the offen-
  206.     ding line number and paragraph number, but will continue to process the
  207.     file.  CRC errors may indicate errors in transmitting the file if it was
  208.     up- or downloaded, or incorrect format of the hex file.
  209.  
  210.     The progress of the conversion is shown by displaying the decimal line
  211.     number (marked by carriage return) and the paragraph number continuous-
  212.     ly. The number of the last line and last paragraph will show on the
  213.     screen when it's done.
  214.               BINTEL.DOC  Version 1.0  February 1987            page 5 of 6
  215.  
  216.                                ERROR MESSAGES
  217.                                --------------
  218.  
  219.     To keep the program relatively simple, BINTEL has only rudimentary
  220.     error-correcting features.  If it encounters a serious error, it will
  221.     exit with a 'generic' message indicating the general nature of the
  222.     problem.  It provides a return code when it exits to DOS, which can be
  223.     checked with the DOS function ERRORLEVEL, by including a statement like
  224.     'if not errorlevel 1 goto Next' in the batch file.
  225.  
  226.     The meaning of the return codes are:
  227.       0 = successful completion (no error)
  228.       1 = 'serious' error
  229.       2 = warning.
  230.  
  231.     Here is a list of the error messages and their most likely causes.
  232.  
  233.      1. Wrong DOS version ...
  234.  
  235.         BINTEL uses DOS 2.xx function calls, and requires MS DOS or PC DOS
  236.         2.0 or later.
  237.  
  238.      2. Error trying to open file:  FILENAME.IN     (return code 1)
  239.  
  240.         File not found.  Possibilities:
  241.         a) the filename was misspelled;
  242.         b) the file doesn't have the extension BIN or COM and the extension
  243.            wasn't specified;  to process file FOOBAR (no extension) enter
  244.            "BINTEL FOOBAR." (a dot with no extension);
  245.         c) the drive or path (if used) was entered incorrectly.
  246.         d) Other possibilities are invalid characters in the name, or
  247.            anything else that normally makes DOS choke.
  248.  
  249.      3. Error reading file:  FILENAME.IN            (return code 1)
  250.  
  251.         Bad disk or corrupted directory/FAT?  It hasn't happened to me yet.
  252.  
  253.      4. Error writing file:  FILENAME.OUT           (return code 1)
  254.  
  255.         The disk is probably full. A partial file may have been stored.
  256.  
  257.      5. Error trying to close file:  FILENAME.XXX   (return code 1)
  258.  
  259.         This shouldn't happen.  It hasn't happened to me except in testing
  260.         incomplete versions of the program.
  261.  
  262.      6. Fatal Error ...                             (return code 1)
  263.  
  264.         Something inexplicable happened, and the program aborted rather than
  265.         lock up the system.
  266.  
  267.               BINTEL.DOC  Version 1.0  February 1987            page 6 of 6
  268.  
  269.      7. Not ready error ...
  270.           Abort, Retry, Ignore?
  271.  
  272.         DOS messages covering most I/O operations. Refer to DOS manual for
  273.         details.  Common problems are disk drive door left open, write-
  274.         protect tabs covered,  etc...
  275.  
  276.      8. Unrecognized command:  /X           (return code 0 -- no error)
  277.  
  278.         This is a warning message that has no effect on the program.  A
  279.         switch command was entered that BINTEL doesn't recognize and it was
  280.         ignored.
  281.  
  282.      9. <Address> *** WARNING! Address overflow occurred ***
  283.         (Binary --> Hex)                    (return code 2)
  284.  
  285.         If the binary file contains more than 64 K bytes, the address coun-
  286.         ter will overflow, since Intel format only allows 2-byte addresses.
  287.         Why would you want to download bigger files anyway, at least until
  288.         '271024' EPROM chips are available?  <Address> is the offset in
  289.         hexadecimal notation of the last paragraph before overflow.
  290.  
  291.     10. <Line #> <Paragr #> CRC error ...
  292.         (Hex --> binary)                    (return code 1)
  293.  
  294.         The CRC value calculated by BINTEL doesn't agree with the one en-
  295.         coded in the Intel Hex file.  This may be a result of an error in
  296.         transmission or an incorrect format of the hex file.  <Line #> is
  297.         the line of the ASCII file, and <Paragr #> is the number of the
  298.         paragraph in which the discrepancy occurred.  Both are in decimal
  299.         notation.   BINTEL will process the whole file,  listing all para-
  300.         graphs with errors.
  301.  
  302.     11. <Line #> <Paragr #> Address error ...
  303.         (Hex --> binary)                    (return code 1)
  304.  
  305.         The address value calculated by BINTEL doesn't agree with the one
  306.         given in the Intel Hex file. See comments under CRC error.
  307.  
  308.                           ---  End of BINTEL.DOC  ---
  309.  
  310.  
  311. This program and other i8051 family utility programs are available
  312. at the Bitbus Board 313-229-9072, weekends, and sometimes weeknights.
  313.  
  314.  
  315.  
  316.