hades.utils
Class IntelHexFile

java.lang.Object
  extended byhades.utils.IntelHexFile

public class IntelHexFile
extends java.lang.Object

parse and write Intel 'HEX' format programming files.

IntelHexFile - a class to parse and write "Intel HEX files" as used for EPROM and microcontroller programming.

Currently, this class supports both the original byte-oriented Intel version (8048, 8051, etc.) via method "parseIntel8Bit()" as well as the word-oriented (16-bit) version used by Arizona Microchip for their PIC series of microcontrollers via method "parsePic16Bit()".

This class may be used either directly with a Java long[] array for the memory data, or a HADES hades.models.memory.Memory object.

See [Intel xx] for details of the file format. The Arizona Microchip format was 'reverse-engineered' from the (public) examples of the PICDemo boards.

INTEL MCS-86 HEXADECIMAL OBJECT File Format Code 88 The Intel 16-bit Hexadecimal Object record format has a 9-character (4 field) prefix that defines the start of the record, byte count, load address, and record type, as well as a 2-character checksum suffix. The four record types are: 00 = data record 01 = end record(signals end of file) 02 = extended address record(provides the offset to determine the absolute destination address) 03 = start record(ignored during input and not sent during output by Data I/O translator firmware) Input data record(type 00) ---------------------------------------------------------- \ : | BC | AAAA | 00 | HHHHHHHH..HH | CC \ --------------------------------------------------------- start byte hex record HH = checksum char count address type 1 data byte (2 chars) (2 chars) (4 chars) (2 chars) (up to 32 chars) End of File record(type 01) ---------------------------------------- \ : | 00 | 0000 | 01 | FF \ ---------------------------------------- start BC address record checksum char = 00 = 0000 type = FF Extended address record(type 02) ----------------------------------------------------- \ : | 02 | 0000 | 02 | HHHH | CC \ ----------------------------------------------------- start BC address record 2 bytes checksum char = 02 = 0000 type (offset) (2 chars) (4 chars) Start Address record(type 03) not used by Data I/O firmware. The Checksum is the two's complement of the binary summation of the preceding bytes in the record(including the bytecount, address, and any data bytes) in hexadecimal notation. The extended address record(type 02) defines bits 4 to 19 of the 20 bit segment base address. This address will be added to subsequent data record addresses to provide the absolute address. This record can appear randomly in the file, but for this application it will be the initial record. NOTE: Always specify the address offset when using this format, even when the offset is zero.


Constructor Summary
IntelHexFile()
           
 
Method Summary
static void main(java.lang.String[] argv)
           
static void msg(java.lang.String s)
           
 int parseByte(java.lang.String line, int index)
           
 void parseIntel8Bit(java.io.InputStream IS, long[] data)
           
 void parseLine16Bit(java.lang.String line, long[] data)
           
 void parseLine8Bit(java.lang.String line, long[] data)
           
 void parsePic16Bit(java.io.InputStream IS, long[] data)
           
 void writeHexFile(java.io.OutputStream OS, long[] data)
          write the memory contents from data[] in Intel MCS Hex format to output stream OS.
 void writeHexFile16Bit(java.io.OutputStream OS, long[] data)
           
 void writeHexFile16Bit(java.io.PrintWriter writer, long[] data)
          write an Intel HEX file, using the lower 16 bit from each data[] element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IntelHexFile

public IntelHexFile()
Method Detail

parsePic16Bit

public void parsePic16Bit(java.io.InputStream IS,
                          long[] data)
                   throws java.lang.Exception
Throws:
java.lang.Exception

parseLine16Bit

public void parseLine16Bit(java.lang.String line,
                           long[] data)
                    throws java.lang.Exception
Throws:
java.lang.Exception

parseByte

public int parseByte(java.lang.String line,
                     int index)
              throws java.lang.Exception
Throws:
java.lang.Exception

parseIntel8Bit

public void parseIntel8Bit(java.io.InputStream IS,
                           long[] data)
                    throws java.lang.Exception
Throws:
java.lang.Exception

parseLine8Bit

public void parseLine8Bit(java.lang.String line,
                          long[] data)
                   throws java.lang.Exception
Throws:
java.lang.Exception

writeHexFile

public void writeHexFile(java.io.OutputStream OS,
                         long[] data)
                  throws java.lang.Exception
write the memory contents from data[] in Intel MCS Hex format to output stream OS. Note that only the lower byte (lowest 8 bits) of each long word of data are used. This method does not try to compress the file size --- all valid data from address[0] to address[data.length-1] are written.

Throws:
java.lang.Exception

writeHexFile16Bit

public void writeHexFile16Bit(java.io.OutputStream OS,
                              long[] data)
                       throws java.lang.Exception
Throws:
java.lang.Exception

writeHexFile16Bit

public void writeHexFile16Bit(java.io.PrintWriter writer,
                              long[] data)
                       throws java.lang.Exception
write an Intel HEX file, using the lower 16 bit from each data[] element.

Throws:
java.lang.Exception

msg

public static void msg(java.lang.String s)

main

public static void main(java.lang.String[] argv)