com.monkeycoder.monkeynes.hardware
Class NesRom

java.lang.Object
  |
  +--com.monkeycoder.monkeynes.hardware.NesRom

public class NesRom
extends Object

The NesRom class represents a physical NES game cartrige. It contains all of the program and graphics data, information about the structure of the data and about the presence or abscence of hardware used to manipulate the data. At the moment the only supported file format that can be used to create a NesRom is the INES format. This is due to the completeness of the format as well as for the fact that virtually no other formats even exist in circulation anymore.

Originally part of the MonkeyNES project.

Author:
David Stephens

Field Summary
static int ROM_FORMAT_INES
           
static int ROM_FORMAT_UNKNOWN
           
 
Constructor Summary
NesRom()
          Creates an empty NesRom.
 
Method Summary
 int[] getChrRomPage(int pageNum)
          Returns the data from the ROM representing the requested page of CHR-ROM.
 byte[] getHeaderData()
          Returns the raw header data as it was passed in.
 InesRomHeader getInesRomHeader()
          Returns the InesRomHeader generated when the raw header data was passed in.
 int[] getPrgRomPage(int pageNum)
          Returns the data from the ROM representing the requested page of PRG-ROM.
 int[] getRomData()
          Returns the raw game data as it was passed in.
 String getRomFileName()
          Returns the file filename from which the data for this ROM was loaded.
 int getRomFormat()
          Returns the file format identifier.
 int getRomFormatHeaderSize(int inRomFormat)
          Returns the size of the header data in bytes.
 int read(int addr)
          Reads any single byte of data from the ROM data.
 int[] read(int startAddr, int stopAddr)
          Reads a range of bytes from the ROM data.
 void setHeaderData(byte[] inHeaderData)
          Sets the ROM header data.
 void setRomData(int[] inRomData)
          Sets the ROM data.
 void setRomFileName(String inRomFileName)
          Sets the filename from which the data for this ROM was loaded.
 void setRomFormat(int inRomFormat)
          Sets the ROM format.
 String toString()
          Creates a text readout detailing all known data for this ROM.
 void write(int addr, int val)
          Updates the ROM data at the specified address with a new value.
 void write(int startAddr, int[] data)
          Updates the ROM data starting at the specified address with a new values.
 void write(int startAddr, int[] data, int len)
          Updates the ROM data starting at the specified address with a new values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ROM_FORMAT_UNKNOWN

public static final int ROM_FORMAT_UNKNOWN
See Also:
Constant Field Values

ROM_FORMAT_INES

public static final int ROM_FORMAT_INES
See Also:
Constant Field Values
Constructor Detail

NesRom

public NesRom()
Creates an empty NesRom.

Method Detail

setRomFileName

public void setRomFileName(String inRomFileName)
Sets the filename from which the data for this ROM was loaded.

Parameters:
inRomFileName - The filename.

setRomFormat

public void setRomFormat(int inRomFormat)
Sets the ROM format.

Parameters:
inRomFormat - The format identifier.

setHeaderData

public void setHeaderData(byte[] inHeaderData)
Sets the ROM header data. This data is expected to be identical to the file header located in the ROM file. This data is converted into an InesRomHeader.

Parameters:
inHeaderData - An array of bytes from the ROM file representing the header.
See Also:
InesRomHeader

setRomData

public void setRomData(int[] inRomData)
Sets the ROM data. This data is expected to be identical to the complete data for the game ROM located in the ROM file.

Parameters:
inRomData - An array of bytes from the ROM file representing the game data.

getRomFileName

public String getRomFileName()
Returns the file filename from which the data for this ROM was loaded.

Returns:
The filename.

getRomFormat

public int getRomFormat()
Returns the file format identifier.

Returns:
The file format identifier.

getInesRomHeader

public InesRomHeader getInesRomHeader()
Returns the InesRomHeader generated when the raw header data was passed in.

Returns:
The InesRomHeader.
See Also:
InesRomHeader

getHeaderData

public byte[] getHeaderData()
Returns the raw header data as it was passed in.

Returns:
The raw header data.

getRomData

public int[] getRomData()
Returns the raw game data as it was passed in.

Returns:
The raw game data.

getRomFormatHeaderSize

public int getRomFormatHeaderSize(int inRomFormat)
Returns the size of the header data in bytes.

Returns:
The size of the header data in bytes.

getPrgRomPage

public int[] getPrgRomPage(int pageNum)
Returns the data from the ROM representing the requested page of PRG-ROM. Pages are numbered starting with 0.

Parameters:
pageNum - The requested page of PRG-ROM.
Returns:
The page of PRG-ROM.

getChrRomPage

public int[] getChrRomPage(int pageNum)
Returns the data from the ROM representing the requested page of CHR-ROM. Pages are numbered starting with 0.

Parameters:
pageNum - The requested page of CHR-ROM.
Returns:
The page of CHR-ROM.

read

public int read(int addr)
Reads any single byte of data from the ROM data. There are no hints provided about what type of data might be at the requested address.

Parameters:
addr - The address of the requested data.
Returns:
The byte of data requested.

read

public int[] read(int startAddr,
                  int stopAddr)
Reads a range of bytes from the ROM data. There are no hints provided about what type of data might be at the requested address range. The range is inclusive.

Parameters:
startAddr - The starting address of the requested data.
stopAddr - The ending address of the requested data.
Returns:
The bytes of data requested.

write

public void write(int addr,
                  int val)
Updates the ROM data at the specified address with a new value.

Parameters:
addr - The address to write.
val - The value to write.

write

public void write(int startAddr,
                  int[] data)
Updates the ROM data starting at the specified address with a new values. The entire incoming data block is written.

Parameters:
startAddr - The address at which to start writing.
data - The incoming data block to write.

write

public void write(int startAddr,
                  int[] data,
                  int len)
Updates the ROM data 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.

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:
NesVideoMemory.writeNoMessage(int,int[],int)

toString

public String toString()
Creates a text readout detailing all known data for this ROM.

Overrides:
toString in class Object
Returns:
A String containing details on everything known about this ROM.