Class IntelHEX


  • public class IntelHEX
    extends java.lang.Object
    Generator and loader of 16-bit Intel Hex files (I8HEX).

    File format is described here: https://en.wikipedia.org/wiki/Intel_HEX

    • Constructor Summary

      Constructors 
      Constructor Description
      IntelHEX()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addTable​(java.util.Map<java.lang.Integer,​java.lang.String> ha)
      Keys of the HashMap have to represent adresses and values have to represent compiled code.
      void generate​(java.io.Writer writer)
      Generates a Intel Hex file based on the cached program map.
      void generate​(java.lang.String outputFileName)
      Generates a Intel Hex file based on the cached program map.
      int getProgramLocation()
      Get program location in memory.
      java.util.Map<java.lang.Integer,​java.lang.String> getTable()
      Get the Map representing the program hex code.
      static int loadIntoMemory​(java.io.File file, MemoryContext<java.lang.Short> memory)  
      void loadIntoMemory​(MemoryContext<java.lang.Short> mem)
      Method is similar to generateHex() method in that way, that compiled program is also transformed into chunk of bytes, but not to hex file but to the operating memory.
      static IntelHEX parseFromFile​(java.io.File file)  
      int putCode​(java.lang.String code)
      Put a series of bytes to the code table.
      void setNextAddress​(int address)
      Set the next address where the next value will be assigned.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • IntelHEX

        public IntelHEX()
    • Method Detail

      • putCode

        public int putCode​(java.lang.String code)
        Put a series of bytes to the code table.

        The bytes must be given as a hexadecimal string of any length. Each byte must have a form of two characters. For example: 0A0B10

        represents 3 bytes: 0x0A, 0x0B and 0x10.

        The code table is modified so that all addresses starting from the current one up to the code length will contain corresponding byte.

        The current address is then increased by the code length. If a byte exists on an address already, it is overwritten.

        Parameters:
        code - Hexadecimal representation of binary code
        Returns:
        updated current address
      • setNextAddress

        public void setNextAddress​(int address)
        Set the next address where the next value will be assigned.
        Parameters:
        address - next address
      • addTable

        public void addTable​(java.util.Map<java.lang.Integer,​java.lang.String> ha)
        Keys of the HashMap have to represent adresses and values have to represent compiled code. Method copies all elements from param HashMap to internal data member.
        Parameters:
        ha - sub-table with addresses and codes
      • getTable

        public java.util.Map<java.lang.Integer,​java.lang.String> getTable()
        Get the Map representing the program hex code.
        Returns:
        Map representing the program hex code
      • loadIntoMemory

        public void loadIntoMemory​(MemoryContext<java.lang.Short> mem)
        Method is similar to generateHex() method in that way, that compiled program is also transformed into chunk of bytes, but not to hex file but to the operating memory.
        Parameters:
        mem - context of operating memory
      • generate

        public void generate​(java.lang.String outputFileName)
                      throws java.io.IOException
        Generates a Intel Hex file based on the cached program map.
        Parameters:
        outputFileName - file name where to store the hex file
        Throws:
        java.io.IOException - if the HEX file could not be written
      • generate

        public void generate​(java.io.Writer writer)
                      throws java.io.IOException
        Generates a Intel Hex file based on the cached program map.
        Parameters:
        writer - Writer used to store the Intel HEX content
        Throws:
        java.io.IOException - if the HEX file could not be written
      • getProgramLocation

        public int getProgramLocation()
        Get program location in memory.

        It is actually the the first address which has occurred in the program HashMap.

        Returns:
        program memory location
      • parseFromFile

        public static IntelHEX parseFromFile​(java.io.File file)
                                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • loadIntoMemory

        public static int loadIntoMemory​(java.io.File file,
                                         MemoryContext<java.lang.Short> memory)
                                  throws java.lang.Exception
        Throws:
        java.lang.Exception