                A brief explanation of the IntelHex file format.

IntelHex file records are a text representation of Hexadecimal coded binary
data. All data uses only ASCII characters, so the format is portable across
virtually all computer platforms. The most common format, described here, is for
eight bit data stored within a 64Kbyte address space.

(The '$' will be used throughout to indicate a hexadecimal value.)

Each line in an IntelHex file is called a 'record'. Records always begin with a
colon (:), followed by the number of data bytes in each record. This value
cannot exceed 255 bytes, since it must be a hexadecimal number between $00 and
$FF.

The next pair of numbers represent the 16-bit starting address of the data in
the record. This is the absolute location in the EPROM.

The starting address is followed by a byte representing the record type. If this
is $00, the next bytes will be the actual data to be stored in EPROM. A $01
indicates that this is the end of the file. There are others, but they are rare,
and honestly I don't know much about them. Only the $00 record type should
contain EPROM data.

Following the record type are the hex representations of the data to be stored.

The last byte is a two's complement checksum of all of the bytes in the record,
not including the colon. Note that this value is derived from the binary values
of the bytes, not the ASCII representation.

A standard CR/LF pair (carriage return/linefeed, $0D $0A) terminates the record.


This a sample IntelHex record.

:10017000707172737475767778797A7B7C7D7E7F07 (CR/LF)

Broken down, it looks as follows:

:               - Colon, indicates that this is IntelHex

10              - Number of data bytes to follow = $10, or 16 decimal

0170            - Starting address in the EPROM for this record.

00              - This is the record type -- $00 = Data

70              - These are the data bytes (in hex) - 16 of them as noted above
71                The first byte ($70) will be stored at $0170, with the
72                remaining bytes following in sequence.
73
74
75
76
77
78
79
7A
7B
7C
7D
7E
7F

07              - This is the checksum. If you add all of the successive bytes
                  (note that the address is treated as two individual bytes) the
                  result is $7F9. Truncating this to eight bits yields $F9. The
                  two's complement of $F9 is $07. (This may be derived by
                  subtracting $F9 from $100, or by inverting the bits and adding
                  one to the result.)

(CR/LF)         - End of this record -- I think the linefeed may be optional.

The use of the starting address in each record makes it possible to store data
in non-contiguous areas of the EPROM. Each line of data is therefore entirely
self-contained. This is useful when areas of the EPROM are unused, as no space
in the IntelHex file need be wasted by representation of blank data. It is
perfectly possible, albeit not recommended, to scramble all of the record lines
in an IntelHex file and still end up with a correct EPROM image.

The end record (end of file) is almost the same:

:00000001FF

:               - Colon, indicates that this is IntelHex

00              - Number of data bytes - should be zero

0000            - Address, usually zero, but I have seen this referred to as the
                  transfer address. Again, I am not sure of the purpose here.

                - Zero data bytes here (obviously)

01              - This is the record type -- $01 this time, indicates end record

FF              - The checksum, calculated as above.


I hope this helps.
                                Sanjaya Vatuk           11/4/96
                                sanjaya@concentric.net
