Class IntelHEX

java.lang.Object
net.emustudio.emulib.io.IntelHEX

@NotThreadSafe public class IntelHEX extends Object
Program code of 16-bit Intel HEX files (I8HEX): built by compilers, written into a file, parsed or loaded into memory.

File format is described here: Intel HEX

  • Constructor Details

    • IntelHEX

      public IntelHEX()
  • Method Details

    • add

      public void add(byte... data)
      Adds bytes at the next address, in the given order. Existing bytes are overwritten.
      Parameters:
      data - bytes to add
    • setNextAddress

      public void setNextAddress(int address)
      Sets the address where the next byte will be added.
      Parameters:
      address - next address
    • getCode

      public NavigableMap<Integer,Byte> getCode()
      Returns:
      unmodifiable view of program bytes by address, in ascending address order
    • findProgramLocation

      public int findProgramLocation()
      Returns:
      the lowest address of the program, or 0 if the program is empty
    • loadIntoMemory

      public void loadIntoMemory(MemoryContext<Byte> memory)
      Writes the program into memory.
      Parameters:
      memory - target memory
    • generate

      public void generate(Path outputPath) throws IOException
      Writes the program into an Intel HEX file. Records hold up to 16 bytes and break at address gaps.
      Parameters:
      outputPath - output file
      Throws:
      IOException - if the file could not be written
    • parse

      public static IntelHEX parse(Path file) throws IOException
      Parses an Intel HEX file.

      Blank lines and lines starting with ';' (after leading whitespace) are ignored, as are input checksums and empty records. Only data records are supported. Later records overwrite earlier ones.

      Parameters:
      file - input file
      Returns:
      parsed program
      Throws:
      IOException - if the file cannot be read or is malformed (the message contains the line number)