com.monkeycoder.monkeynes.hardware
Class NesSpriteMemory

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

public class NesSpriteMemory
extends Observable

This is a sprite memory bank for the NES. It has only 256 bytes and is accessible via DMA registers. 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
NesSpriteMemory()
          Creates a new NesSpriteMemory initialized to all 0's.
 
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 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 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

NesSpriteMemory

public NesSpriteMemory()
Creates a new NesSpriteMemory initialized to all 0's.

Method Detail

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)

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[])

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)