com.monkeycoder.monkeynes.hardware
Class NesHardware

java.lang.Object
  |
  +--com.monkeycoder.monkeynes.hardware.NesHardware
All Implemented Interfaces:
Runnable

public class NesHardware
extends Object
implements Runnable

This represents the physical NES unit. It contains the CPU, PPU, memory banks, the ROM cartrige, controller ports, the system clock, and a connection to the video screen. This class ties it all together into a nice little bundle.

Originally part of the MonkeyNES project.

Author:
David Stephens

Constructor Summary
NesHardware()
          Creates a new NesHardware which in turn creates all if the internal components of the NES.
 
Method Summary
 void connectController(NesController inController, int inPort)
          Connects a controller to the hardware through a specified controller port.
 void connectVideoScreen(VideoScreen inVidScreen)
          Connects the video screen to the hardware.
 NesController getController(int inPortNum)
          Returns the controller for the specified port.
 NesCpu getCpu()
          Returns the CPU created by and in use by this hardware.
 NesMainMemory getMainMemory()
          Returns the Main Memory bank created by and in use by this hardware.
 MemoryMapper getMemoryMapper()
          Returns the MemoryMapper in use by the NesRom.
 NesPalette getPalette()
          Returns the palette created by and in use by this hardware.
 NesPpu getPpu()
          Returns the PPU created by and in use by this hardware.
 NesRom getRom()
          Returns the NesRom currently in the ROM slot of this hardware.
 NesSpriteMemory getSpriteMemory()
          Returns the Sprite Memory bank created by and in use by this hardware.
 NesVideoMemory getVideoMemory()
          Returns the Video Memory bank created by and in use by this hardware.
 VideoScreen getVideoScreen()
          Returns the VideoScreen that is attached to this hardware.
 void insertRom(NesRom inRom)
          Puts a ROM cartrige into the front of the system.
 boolean isPowerOn()
          Returns whether or not the power is on in the hardware.
 void powerOff()
          Called to tell the hardware that power is now off.
 void powerOn()
          Called to tell the hardware that power is now on.
 NesRom removeRom()
          Removes a ROM cartrige fron the system.
 void reset()
          Called to tell the hardware to reset.
 void run()
          Threaded run method so the hardware can operate in it's own thread.
 void setClockSpeed(long inClockSpeed)
          Sets the speed of the timer chip in the NES.
 String toString()
          Creates a huge text readout detailing everything currently connected to the hardware.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NesHardware

public NesHardware()
Creates a new NesHardware which in turn creates all if the internal components of the NES.

Method Detail

setClockSpeed

public void setClockSpeed(long inClockSpeed)
Sets the speed of the timer chip in the NES.

Parameters:
inClockSpeed - The speed of the timer in Hz.

connectVideoScreen

public void connectVideoScreen(VideoScreen inVidScreen)
Connects the video screen to the hardware.

Parameters:
inVidScreen - The video screen that will receive output from the PPU.

connectController

public void connectController(NesController inController,
                              int inPort)
Connects a controller to the hardware through a specified controller port.

Parameters:
inController - The controller that will be plugged into the port.
inPort - The port the into which the controller will be plugged.

insertRom

public void insertRom(NesRom inRom)
Puts a ROM cartrige into the front of the system. Also creates a mapper if the cartrige needs it.

Think of it as a flawless cartrige insertion every time. No more blowing on the game, no more cleaning the contacts with a Q-Tip, no more wiggling it around. It will just work, every time.

Parameters:
inRom - The cartrige that is being inserted into the hardware.

removeRom

public NesRom removeRom()
Removes a ROM cartrige fron the system.

Returns:
The ROM that was in use.

isPowerOn

public boolean isPowerOn()
Returns whether or not the power is on in the hardware.

Returns:
Whether or not the power is on.

powerOn

public void powerOn()
Called to tell the hardware that power is now on.


powerOff

public void powerOff()
Called to tell the hardware that power is now off.


reset

public void reset()
Called to tell the hardware to reset.


run

public void run()
Threaded run method so the hardware can operate in it's own thread. This allows hardware to be created and placed into a seperate thread and started up and allowed to run on its own. This method manages the operation of the clock and tells all attached components to do cycles as appropriate.

Specified by:
run in interface Runnable

getCpu

public NesCpu getCpu()
Returns the CPU created by and in use by this hardware.

Returns:
The CPU in use by this hardware.

getPpu

public NesPpu getPpu()
Returns the PPU created by and in use by this hardware.

Returns:
The PPU in use by this hardware.

getVideoScreen

public VideoScreen getVideoScreen()
Returns the VideoScreen that is attached to this hardware.

Returns:
The VideoScreen attached to this hardware.

getRom

public NesRom getRom()
Returns the NesRom currently in the ROM slot of this hardware.

Returns:
The NesRom currently in the ROM slot of this hardware.

getMemoryMapper

public MemoryMapper getMemoryMapper()
Returns the MemoryMapper in use by the NesRom.

Returns:
The MemoryMapper in use by the NesRom.

getMainMemory

public NesMainMemory getMainMemory()
Returns the Main Memory bank created by and in use by this hardware.

Returns:
The Main Memory bank in use by this hardware.

getVideoMemory

public NesVideoMemory getVideoMemory()
Returns the Video Memory bank created by and in use by this hardware.

Returns:
The Video Memory bank in use by this hardware.

getSpriteMemory

public NesSpriteMemory getSpriteMemory()
Returns the Sprite Memory bank created by and in use by this hardware.

Returns:
The Sprite Memory bank in use by this hardware.

getPalette

public NesPalette getPalette()
Returns the palette created by and in use by this hardware.

Returns:
The palette created by and in use by this hardware.

getController

public NesController getController(int inPortNum)
Returns the controller for the specified port. Port numbers are zero based.

Parameters:
inPortNum - The port number that will be returned.
Returns:
The controller for the specified port.

toString

public String toString()
Creates a huge text readout detailing everything currently connected to the hardware.

Overrides:
toString in class Object
Returns:
A String containing details on everything connected to the hardware.