Interface MemoryContext<CellType>

  • Type Parameters:
    CellType - type of the memory cell
    All Superinterfaces:
    Context
    All Known Implementing Classes:
    AbstractMemoryContext

    public interface MemoryContext<CellType>
    extends Context
    This memory context supports basic methods for accessing the memory, like reading and writing memory cells. If the memory wants to support additional functionality, it should extend this interface.

    Plugins which need the specific memory contexts, should declare a dependency on the memory plugin.

    • Method Detail

      • read

        CellType read​(int memoryPosition)
        Reads one cell from a memory.
        Parameters:
        memoryPosition - memory position (address) of the read cell
        Returns:
        read cell
      • read

        CellType[] read​(int memoryPosition,
                        int count)
        Reads one or more adjacent cells from a memory at once.

        Implementation of return value is up to plugin programmer (e.g. ordering of cells). If cells in memory are pure bytes (java type is e.g. short), concatenation can be realized as (in small endian):

         
         result = (mem[from]&0xFF) | ((mem[from+1]<<8)&0xFF) | ...;
         
         

        and in big endian as:

         
         result = ((mem[from]<<(count *8 ))&0xFF) | (mem[from+1]<<((count-1)*8)&0xFF) | ...;
         
         

        If memory size is smaller than (memoryPosition+count), then only available cells are returned - returned array size can be less than count.

        Parameters:
        memoryPosition - memory position (address) of the read cells
        count - how many cells should be read
        Returns:
        one or more read cells, accessible at indexes 0 and 1, respectively.
        Throws:
        java.lang.RuntimeException - if memory size is smaller than (memoryPosition+count)
      • write

        void write​(int memoryPosition,
                   CellType value)
        Write one cell-size (e.g. byte) data to a cell to a memory at specified location.
        Parameters:
        memoryPosition - memory position (address) of the cell where data will be written
        value - data to be written
      • write

        void write​(int memoryPosition,
                   CellType[] values,
                   int count)
        Write an array of data to a memory at specified location. Data will be written in small endian order.
        Parameters:
        memoryPosition - memory position (address) of the cell with index 0
        values - data to be written
        count - how many values should be taken
        Throws:
        java.lang.RuntimeException - if memory size is smaller than (memoryPosition+values.length)
      • write

        default void write​(int memoryPosition,
                           CellType[] values)
        Write an array of data to a memory at specified location. Data will be written in small endian order.
        Parameters:
        memoryPosition - memory position (address) of the cell with index 0
        values - data to be written
        Throws:
        java.lang.RuntimeException - if memory size is smaller than (memoryPosition+values.length)
      • getDataType

        java.lang.Class<CellType> getDataType()
        Get the type of memory cells.
        Returns:
        Java data type of memory cells
      • clear

        void clear()
        Clears the memory.
      • addMemoryListener

        void addMemoryListener​(Memory.MemoryListener listener)
        Adds the specified memory listener to receive memory events from this memory. Memory events occur even if single cell is changed in memory. If listener is null, no exception is thrown and no action is performed.
        Parameters:
        listener - the memory listener
      • removeMemoryListener

        void removeMemoryListener​(Memory.MemoryListener listener)
        Removes the specified memory listener so that it no longer receives memory events from this memory. Memory events occur even if single cell is changed in memory. If listener is null, no exception is thrown and no action is performed.
        Parameters:
        listener - the memory listener to be removed
      • getSize

        int getSize()
        Get memory size.

        The size is a number of cells of the generic type T.

        Returns:
        memory size
      • setMemoryNotificationsEnabled

        void setMemoryNotificationsEnabled​(boolean enabled)
        Enable/disable notifications of memory changes globally.

        Enabled by default.

        Parameters:
        enabled - - true if enabled, false if disabled.
      • areMemoryNotificationsEnabled

        boolean areMemoryNotificationsEnabled()
        Determine if notifications of memory changes are globally enabled or disabled.
        Returns:
        true if notifications are enabled, false if disabled.