com.monkeycoder.monkeynes.hardware
Class NesMainMemory

java.lang.Object
  |
  +--java.util.Observable
        |
        +--com.monkeycoder.monkeynes.hardware.NesMainMemory

public class NesMainMemory
extends Observable

This is a main memory bank for the NES. It has only 64k and part of that is actually from the ROM. This class is observable and will send all varieties of access messages to all its observers. There is also a full second set of access functions that do not send out messages. These are intended for use by speed intensive pieces of code where messages aren't needed. Please note that each byte of memory is actual a 32-bit integer and will be automatically limited to 8-bits internally.

Originally part of the MonkeyNES project.

Author:
David Stephens

Constructor Summary
NesMainMemory()
          Creates a new NesMainMemory initialized to all 0's.
NesMainMemory(MemoryFilter inFilter)
          Creates a new NesMainMemory with the specified MemoryFilter.
 
Method Summary
 void clear()
          Reinitializes the memory bank to all zeros.
 int read(int addr)
          Reads the memory at the requested address.
 int[] read(int startAddr, int stopAddr)
          Reads the memory at the requested address range.
 int readNoMessage(int addr)
          Reads the memory at the requested address.
 int[] readNoMessage(int startAddr, int stopAddr)
          Reads the memory at the requested address range.
 int readWord(int addr)
          Reads 2-bytes of memory starting at the requested address.
 int readWordNoMessage(int addr)
          Reads 2-bytes of memory starting at the requested address.
 void setDmaManager(DmaManager inDmaManager)
          Sets the DMA Manager that will be used by this bank of main memory.
 void setMemoryFilter(MemoryFilter inFilter)
          Sets the MemoryFilter that will be used by this bank of main memory.
 void setMemoryMapper(MemoryMapper inMapper)
          Sets the Memory Mapper that will be used by this bank of main memory.
 void write(int addr, int val)
          Updates the memory at the specified address with a new value.
 void write(int startAddr, int[] data)
          Updates the memory starting at the specified address with a new values.
 void write(int startAddr, int[] data, int len)
          Updates the memory starting at the specified address with a new values.
 void writeIgnoreMapper(int addr, int val)
          Updates the memory at the specified address with a new value.
 void writeIgnoreMapper(int startAddr, int[] data)
          Updates the memory at the specified address with a new value.
 void writeIgnoreMapperNoMessage(int addr, int val)
          Updates the memory at the specified address with a new value.
 void writeNoMessage(int addr, int val)
          Updates the memory at the specified address with a new value.
 void writeNoMessage(int startAddr, int[] data)
          Updates the memory starting at the specified address with a new values.
 void writeNoMessage(int startAddr, int[] data, int len)
          Updates the memory starting at the specified address with a new values.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NesMainMemory

public NesMainMemory()
Creates a new NesMainMemory initialized to all 0's. A DefaultMemoryFilter is used automatically.
Note: setDmaManager() must be called before using this class. Note: setMemoryMapper() must be called before using this class.

See Also:
MemoryFilter, DefaultMemoryFilter, setDmaManager(DmaManager), setMemoryMapper(MemoryMapper)

NesMainMemory

public NesMainMemory(MemoryFilter inFilter)
Creates a new NesMainMemory with the specified MemoryFilter.
Note: setDmaManager() must be called before using this class. Note: setMemoryMapper() must be called before using this class.

Parameters:
inFilter - The MemoryFilter to use instead of a DefaultMemoryFilter.
See Also:
MemoryFilter, setDmaManager(DmaManager), setMemoryMapper(MemoryMapper)
Method Detail

setDmaManager

public void setDmaManager(DmaManager inDmaManager)
Sets the DMA Manager that will be used by this bank of main memory.
Note: This class does NOT check for the existance of a DmaManager and will cause null pointer exceptions if one is not set.

Parameters:
inDmaManager - The DmaManager that this bank of memory will use.

setMemoryMapper

public void setMemoryMapper(MemoryMapper inMapper)
Sets the Memory Mapper that will be used by this bank of main memory.
Note: This class does NOT check for the existance of a MemoryMapper and will cause null pointer exceptions if one is not set.

Parameters:
inMapper - The MemoryMapper that this bank of memory will use.

setMemoryFilter

public void setMemoryFilter(MemoryFilter inFilter)
Sets the MemoryFilter that will be used by this bank of main memory.

Parameters:
inFilter - The MemoryFilter to use instead of a DefaultMemoryFilter.

clear

public void clear()
Reinitializes the memory bank to all zeros.


read

public int read(int addr)
Reads the memory at the requested address. This function sends out a MemoryAccessMessage indicating what was accessed.

Parameters:
addr - The address to read.
Returns:
The value found in memory at the requested address.
See Also:
readNoMessage(int)

readNoMessage

public int readNoMessage(int addr)
Reads the memory at the requested address. This function does not send out a MemoryAccessMessage.

Parameters:
addr - The address to read.
Returns:
The value found in memory at the requested address.
See Also:
read(int)

readWord

public int readWord(int addr)
Reads 2-bytes of memory starting at the requested address. This function sends out a MemoryAccessMessage indicating what was accessed.

Parameters:
addr - The address of the start of the word to read.
Returns:
The value found in memory at the requested address.
See Also:
readWordNoMessage(int)

readWordNoMessage

public int readWordNoMessage(int addr)
Reads 2-bytes of memory starting at the requested address. This function does not send out a MemoryAccessMessage.

Parameters:
addr - The address of the start of the word to read.
Returns:
The value found in memory at the requested address.
See Also:
readWord(int)

read

public int[] read(int startAddr,
                  int stopAddr)
Reads the memory at the requested address range. The access is inclusive to both ends of the range. This function sends out a MemoryAccessMessage indicating what was accessed.

Parameters:
startAddr - The address at which the read will start.
stopAddr - The address at which the read will stop.
Returns:
The value found in memory at the requested address.
See Also:
readNoMessage(int,int)

readNoMessage

public int[] readNoMessage(int startAddr,
                           int stopAddr)
Reads the memory at the requested address range. The access is inclusive to both ends of the range. This function does not send out a MemoryAccessMessage.

Parameters:
startAddr - The address at which the read will start.
stopAddr - The address at which the read will stop.
Returns:
The value found in memory at the requested address.
See Also:
read(int,int)

write

public void write(int addr,
                  int val)
Updates the memory at the specified address with a new value. This function sends out a MemoryAccessMessage indicating what was accessed.

Parameters:
addr - The address to write.
val - The value to write.
See Also:
writeNoMessage(int,int)

writeIgnoreMapper

public void writeIgnoreMapper(int addr,
                              int val)
Updates the memory at the specified address with a new value. This function does not use the active mapper. This function sends out a MemoryAccessMessage indicating what was accessed.

Parameters:
addr - The address to write.
val - The value to write.
See Also:
writeNoMessage(int,int)

writeIgnoreMapperNoMessage

public void writeIgnoreMapperNoMessage(int addr,
                                       int val)
Updates the memory at the specified address with a new value. This function does not use the active mapper. This function does not send out a MemoryAccessMessage indicating what was accessed.

Parameters:
addr - The address to write.
val - The value to write.
See Also:
writeNoMessage(int,int)

writeNoMessage

public void writeNoMessage(int addr,
                           int val)
Updates the memory at the specified address with a new value. This function does not send out a MemoryAccessMessage.

Parameters:
addr - The address to write.
val - The value to write.
See Also:
write(int,int)

write

public void write(int startAddr,
                  int[] data)
Updates the memory starting at the specified address with a new values. The entire incoming data block is written. This function sends out a MemoryAccessMessage indicating what was accessed.

Parameters:
startAddr - The address at which to start writing.
data - The incoming data block to write.
See Also:
writeNoMessage(int,int[])

writeIgnoreMapper

public void writeIgnoreMapper(int startAddr,
                              int[] data)
Updates the memory at the specified address with a new value. This function does not use the active mapper. This function sends out a MemoryAccessMessage indicating what was accessed.

See Also:
writeNoMessage(int,int)

writeNoMessage

public void writeNoMessage(int startAddr,
                           int[] data)
Updates the memory starting at the specified address with a new values. The entire incoming data block is written. This function does not send out a MemoryAccessMessage.

Parameters:
startAddr - The address at which to start writing.
data - The incoming data block to write.
See Also:
write(int,int[])

write

public void write(int startAddr,
                  int[] data,
                  int len)
Updates the memory starting at the specified address with a new values. The incoming data block is written from the beginning but only until the specified number of bytes has been written. This function sends out a MemoryAccessMessage indicating what was accessed.

Parameters:
startAddr - The address at which to start writing.
data - The incoming data block to write.
len - The number of bytes to write.
See Also:
writeNoMessage(int,int[],int)

writeNoMessage

public void writeNoMessage(int startAddr,
                           int[] data,
                           int len)
Updates the memory starting at the specified address with a new values. The incoming data block is written from the beginning but only until the specified number of bytes has been written. This function does not send out a MemoryAccessMessage.

Parameters:
startAddr - The address at which to start writing.
data - The incoming data block to write.
len - The number of bytes to write.
See Also:
write(int,int[],int)