jmce - 1_02

jmce.sim.memory
Class AbstractMemory

java.lang.Object
  extended by jmce.sim.AbstractHardware
      extended by jmce.sim.AbstractPeripheral
          extended by jmce.sim.memory.AbstractMemory
All Implemented Interfaces:
Hardware, Memory, Peripheral
Direct Known Subclasses:
ArrayMemory, CombinedMemory, DuplicateMemory, PlainMemory

public abstract class AbstractMemory
extends AbstractPeripheral
implements Memory

Abstract implementation of Memory.

All method not relative to set/get memory operation are implemented from this class. Also implements helper to make simple add virtual memory features this make the class a little bit more complex but do not change the performance on critical operation. All subclass must remember to call the method setSize() to allocate space for listener and names.

Version:
1.02
Author:
Mario Viara

Field Summary
protected  int size
          Size of this memory
protected  FastArray<AbstractMemory> vms
          Array with all virtual memory
 
Fields inherited from class jmce.sim.AbstractPeripheral
cpu
 
Constructor Summary
AbstractMemory()
           
AbstractMemory(java.lang.String name)
           
 
Method Summary
 void addHardwareMemory(Memory m)
          Add a new memory and also add to the hardware list.
 void addMemory(Memory v)
          Add virtual memory to the actual list.
 void addMemoryReadListener(int a, MemoryReadListener l)
           
 void addMemoryReadListener(MemoryReadListener l)
           
 void addMemoryWriteListener(int a, MemoryWriteListener l)
          Add a specific MemoryWriteListener.
 void addMemoryWriteListener(MemoryWriteListener l)
          Add a global MemoryWriteListener.
 void clrBit(int a, int mask)
           
protected abstract  int get(int a)
          Get memory.
 int getMemory(int add)
          Get a location of memory.
protected  AbstractMemory getMemoryAt(int i)
          Return the specified memory
protected  int getMemoryCount()
          Return the number of virtual memory
 java.lang.String getMemoryName(int a)
           
 MemoryReadListener getMemoryReadListenerAt(int i)
           
 MemoryReadListener getMemoryReadListenerAt(int a, int i)
           
 int getMemoryReadListenerCount()
           
 int getMemoryReadListenerCount(int a)
           
 MemoryWriteListener getMemoryWriteListenerAt(int i)
           
 MemoryWriteListener getMemoryWriteListenerAt(int a, int i)
           
 int getMemoryWriteListenerCount()
          Return the number of global memory write listener installed.
 int getMemoryWriteListenerCount(int a)
          Return the number of specific memory write listener installed at the specified affress.
 boolean getReadOnly(int add)
          Check if a speficied location is read only.
 int getSize()
          Return the size of the memory in byte.
 boolean isBit(int a, int mask)
           
protected  int mapAddress(int a)
          Map address for virtual memory.
protected  Memory mapMemory(int a)
          Map memory for virtual memory.
 void removeMemoryReadListener(int a, MemoryReadListener l)
           
 void removeMemoryReadListener(MemoryReadListener l)
           
 void removeMemoryWriteListener(int a, MemoryWriteListener l)
          Remove a previus specific installed memory write listener.
 void removeMemoryWriteListener(MemoryWriteListener l)
          Remove a previous global installed memory write listener.
protected abstract  void set(int a, int v)
          Set memory.
 void setBit(int a, int mask)
           
 void setMemory(int add, int v)
          Set a location of memory.
 void setMemoryName(int a, java.lang.String name)
           
 void setReadOnly()
          Set the flag read only for all the memory
 void setReadOnly(int add)
          Set the flag read only for a single address.
 void setReadOnly(int a, int len)
          Set the flag read only for the specified range
 void setSize(int newSize)
          Set the size of the memory.
 java.lang.String toString()
           
 
Methods inherited from class jmce.sim.AbstractPeripheral
idle, registerCPU, setIdle, setLive
 
Methods inherited from class jmce.sim.AbstractHardware
addHardware, createFrame, destroy, getHardware, getHardware, getHardware, getHardware, getHardware, getHardwareCount, getHardwareForName, getHardwareInstances, getHardwareTree, getName, getParent, init, initSwing, removeHardware, removeHardware, reset, setHardware, setHardware, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jmce.sim.Peripheral
idle, registerCPU
 
Methods inherited from interface jmce.sim.Hardware
addHardware, destroy, getHardware, getHardware, getHardware, getHardware, getHardwareCount, getHardwareInstances, getHardwareTree, getName, getParent, init, initSwing, removeHardware, removeHardware, reset, setHardware, setHardware, setName
 

Field Detail

vms

protected FastArray<AbstractMemory> vms
Array with all virtual memory


size

protected int size
Size of this memory

Constructor Detail

AbstractMemory

public AbstractMemory()

AbstractMemory

public AbstractMemory(java.lang.String name)
Method Detail

set

protected abstract void set(int a,
                            int v)
Set memory.

Used by subclass to implement the phisical memory.


get

protected abstract int get(int a)
Get memory.

Used by subclass to implement the phisical memory.


getReadOnly

public final boolean getReadOnly(int add)
Description copied from interface: Memory
Check if a speficied location is read only.

Specified by:
getReadOnly in interface Memory

setReadOnly

public final void setReadOnly()
Description copied from interface: Memory
Set the flag read only for all the memory

Specified by:
setReadOnly in interface Memory

setReadOnly

public final void setReadOnly(int a,
                              int len)
Description copied from interface: Memory
Set the flag read only for the specified range

Specified by:
setReadOnly in interface Memory

setReadOnly

public final void setReadOnly(int add)
Description copied from interface: Memory
Set the flag read only for a single address.

Specified by:
setReadOnly in interface Memory

addMemoryWriteListener

public final void addMemoryWriteListener(MemoryWriteListener l)
Description copied from interface: Memory
Add a global MemoryWriteListener.

The listener will be called when any location of the memory is writed.

Specified by:
addMemoryWriteListener in interface Memory
Parameters:
l - - Memory write listener called when the memory is writed.

removeMemoryWriteListener

public final void removeMemoryWriteListener(MemoryWriteListener l)
Description copied from interface: Memory
Remove a previous global installed memory write listener.

Specified by:
removeMemoryWriteListener in interface Memory

addMemoryWriteListener

public final void addMemoryWriteListener(int a,
                                         MemoryWriteListener l)
Description copied from interface: Memory
Add a specific MemoryWriteListener.

The listener will be called when the specified memory location is written.

Specified by:
addMemoryWriteListener in interface Memory
Parameters:
a - - Address where to install the listener.
l - - Memory write listener called when the memory is writed.

removeMemoryWriteListener

public void removeMemoryWriteListener(int a,
                                      MemoryWriteListener l)
Description copied from interface: Memory
Remove a previus specific installed memory write listener.

Specified by:
removeMemoryWriteListener in interface Memory

addMemoryReadListener

public void addMemoryReadListener(MemoryReadListener l)
Specified by:
addMemoryReadListener in interface Memory

removeMemoryReadListener

public void removeMemoryReadListener(MemoryReadListener l)
Specified by:
removeMemoryReadListener in interface Memory

removeMemoryReadListener

public void removeMemoryReadListener(int a,
                                     MemoryReadListener l)
Specified by:
removeMemoryReadListener in interface Memory

addMemoryReadListener

public void addMemoryReadListener(int a,
                                  MemoryReadListener l)
Specified by:
addMemoryReadListener in interface Memory

getMemoryWriteListenerCount

public int getMemoryWriteListenerCount()
Description copied from interface: Memory
Return the number of global memory write listener installed.

Specified by:
getMemoryWriteListenerCount in interface Memory

getMemoryWriteListenerCount

public int getMemoryWriteListenerCount(int a)
Description copied from interface: Memory
Return the number of specific memory write listener installed at the specified affress.

Specified by:
getMemoryWriteListenerCount in interface Memory

getMemoryReadListenerCount

public int getMemoryReadListenerCount()
Specified by:
getMemoryReadListenerCount in interface Memory

getMemoryReadListenerCount

public int getMemoryReadListenerCount(int a)
Specified by:
getMemoryReadListenerCount in interface Memory

getMemoryWriteListenerAt

public MemoryWriteListener getMemoryWriteListenerAt(int i)
Specified by:
getMemoryWriteListenerAt in interface Memory

getMemoryReadListenerAt

public MemoryReadListener getMemoryReadListenerAt(int i)
Specified by:
getMemoryReadListenerAt in interface Memory

getMemoryWriteListenerAt

public MemoryWriteListener getMemoryWriteListenerAt(int a,
                                                    int i)
Specified by:
getMemoryWriteListenerAt in interface Memory

getMemoryReadListenerAt

public MemoryReadListener getMemoryReadListenerAt(int a,
                                                  int i)
Specified by:
getMemoryReadListenerAt in interface Memory

setSize

public void setSize(int newSize)
Description copied from interface: Memory
Set the size of the memory.

Specified by:
setSize in interface Memory

getSize

public int getSize()
Description copied from interface: Memory
Return the size of the memory in byte.

Specified by:
getSize in interface Memory

setMemoryName

public final void setMemoryName(int a,
                                java.lang.String name)
Specified by:
setMemoryName in interface Memory

getMemoryName

public final java.lang.String getMemoryName(int a)
Specified by:
getMemoryName in interface Memory

addHardwareMemory

public void addHardwareMemory(Memory m)
Add a new memory and also add to the hardware list.

Parameters:
m - - Memory to add.
Since:
1.01

addMemory

public void addMemory(Memory v)
Add virtual memory to the actual list.


getMemoryCount

protected int getMemoryCount()
Return the number of virtual memory


getMemoryAt

protected AbstractMemory getMemoryAt(int i)
Return the specified memory


isBit

public boolean isBit(int a,
                     int mask)
              throws MemoryException
Specified by:
isBit in interface Memory
Throws:
MemoryException

setBit

public void setBit(int a,
                   int mask)
            throws SIMException
Specified by:
setBit in interface Memory
Throws:
SIMException

clrBit

public void clrBit(int a,
                   int mask)
            throws SIMException
Specified by:
clrBit in interface Memory
Throws:
SIMException

getMemory

public final int getMemory(int add)
                    throws SIMException
Description copied from interface: Memory
Get a location of memory.

Specified by:
getMemory in interface Memory
Parameters:
add - - Location
Returns:
A byte from the memory.
Throws:
SIMException

setMemory

public final void setMemory(int add,
                            int v)
                     throws SIMException
Description copied from interface: Memory
Set a location of memory.

Specified by:
setMemory in interface Memory
Parameters:
add - - Memory address
v - - Value to set only 8 bit are used
Throws:
SIMException

mapMemory

protected Memory mapMemory(int a)
Map memory for virtual memory.

This method must be overriden from virtual memory sub class.


mapAddress

protected int mapAddress(int a)
Map address for virtual memory.

This method must be overridden from virtual memory sub class.


toString

public java.lang.String toString()
Overrides:
toString in class AbstractHardware

jmce - 1_02