com.monkeycoder.monkeynes.hardware
Class CpuRegister

java.lang.Object
  |
  +--com.monkeycoder.monkeynes.hardware.CpuRegister
Direct Known Subclasses:
CpuRegister16

public class CpuRegister
extends Object

This class represents an 8-bit CPU register.

Originally part of the MonkeyNES project.

Author:
David Stephens

Field Summary
static int PS_BREAK_COMMAND
           
static int PS_CARRY_FLAG
           
static int PS_DECIMAL_MODE
           
static int PS_INTERRUPT_DISABLE
           
static int PS_NEGATIVE_FLAG
           
static int PS_OVERFLOW_FLAG
           
static int PS_UNUSED
           
static int PS_ZERO_FLAG
           
 
Constructor Summary
CpuRegister()
          Creates a new CpuRegister set to 0.
CpuRegister(int inData)
          Creates a new CpuRegister set to a specific value.
 
Method Summary
 void andEquals(int inVal)
          Performs a bitwise AND with a value and this register's existing value.
 void cage()
          This function sets all bits that are not supposed to be in use by a register of this size to 0.
 void decrement()
          Decrements the value of this register.
 int getBitValue(int inMask)
          Gets the value of a specific bit as a 0 or 1.
 boolean getBooleanBitValue(int inMask)
          Gets the value of a specific bit as a boolean.
 int getValue()
          Gets the entire data value of this register.
 void increment()
          Increments the value of this register.
 void minusEquals(int inVal)
          Subtracts a value from this register's existing value.
 void orEquals(int inVal)
          Performs a bitwise OR with a value and this register's existing value.
 void plusEquals(int inVal)
          Adds a value to this register's existing value.
 void setBitOff(int inMask)
          Turns off specific bits based on a mask.
 void setBitOn(int inMask)
          Turns on specific bits based on a mask.
 void setBitValue(int inMask, boolean inVal)
          Sets the value of any number of specific bits based on a mask.
 void setBitValue(int inMask, int inVal)
          Sets the value of any number of specific bits based on a mask.
 void setValue(int inVal)
          Sets the entire data value of this register.
 String toString()
          This function returns the current data value of this register as a String.
 void xorEquals(int inVal)
          Performs a bitwise XOR with a value and this register's existing value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PS_CARRY_FLAG

public static final int PS_CARRY_FLAG
See Also:
Constant Field Values

PS_ZERO_FLAG

public static final int PS_ZERO_FLAG
See Also:
Constant Field Values

PS_INTERRUPT_DISABLE

public static final int PS_INTERRUPT_DISABLE
See Also:
Constant Field Values

PS_DECIMAL_MODE

public static final int PS_DECIMAL_MODE
See Also:
Constant Field Values

PS_BREAK_COMMAND

public static final int PS_BREAK_COMMAND
See Also:
Constant Field Values

PS_UNUSED

public static final int PS_UNUSED
See Also:
Constant Field Values

PS_OVERFLOW_FLAG

public static final int PS_OVERFLOW_FLAG
See Also:
Constant Field Values

PS_NEGATIVE_FLAG

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

CpuRegister

public CpuRegister()
Creates a new CpuRegister set to 0.


CpuRegister

public CpuRegister(int inData)
Creates a new CpuRegister set to a specific value.

Parameters:
inData - The value to which the register will be set.
Method Detail

getValue

public int getValue()
Gets the entire data value of this register.

Returns:
The value of this register as an int.

getBooleanBitValue

public boolean getBooleanBitValue(int inMask)
Gets the value of a specific bit as a boolean. This function also works with masks that test more than one bit, but will only return true if all bits in the mask are on.

Parameters:
inMask - A mask of the bits to check.
Returns:
The value of masked bit as a boolean.

getBitValue

public int getBitValue(int inMask)
Gets the value of a specific bit as a 0 or 1. This function also works with masks that test more than one bit, but will only return 1 if all bits in the mask are on.

Parameters:
inMask - A mask of the bits to check.
Returns:
The value of masked bit as 0 or 1.

setValue

public void setValue(int inVal)
Sets the entire data value of this register.

Parameters:
inVal - The value to which this register will be set.

setBitValue

public void setBitValue(int inMask,
                        int inVal)
Sets the value of any number of specific bits based on a mask. All other bits are left untouched.

Parameters:
inMask - A mask of the bits to set.
inVal - 0 to turn off the requested bits, any other value to turn them on.

setBitValue

public void setBitValue(int inMask,
                        boolean inVal)
Sets the value of any number of specific bits based on a mask. All other bits are left untouched.

Parameters:
inMask - A mask of the bits to set.
inVal - false to turn off the requested bits, true to turn them on.

setBitOn

public void setBitOn(int inMask)
Turns on specific bits based on a mask. All other bits are left untouched.

Parameters:
inMask - A mask of the bits to set.

setBitOff

public void setBitOff(int inMask)
Turns off specific bits based on a mask. All other bits are left untouched.

Parameters:
inMask - A mask of the bits to set.

increment

public void increment()
Increments the value of this register.


decrement

public void decrement()
Decrements the value of this register.


plusEquals

public void plusEquals(int inVal)
Adds a value to this register's existing value.

Parameters:
inVal - The value to add to this register.

minusEquals

public void minusEquals(int inVal)
Subtracts a value from this register's existing value.

Parameters:
inVal - The value to subtract from this register.

andEquals

public void andEquals(int inVal)
Performs a bitwise AND with a value and this register's existing value.

Parameters:
inVal - The value to AND with this register.

orEquals

public void orEquals(int inVal)
Performs a bitwise OR with a value and this register's existing value.

Parameters:
inVal - The value to OR with this register.

xorEquals

public void xorEquals(int inVal)
Performs a bitwise XOR with a value and this register's existing value.

Parameters:
inVal - The value to XOR with this register.

cage

public void cage()
This function sets all bits that are not supposed to be in use by a register of this size to 0.


toString

public String toString()
This function returns the current data value of this register as a String.

Overrides:
toString in class Object
Returns:
The value of this register as a String.