de.michab.simulator.mos6502
Class Cpu6510

java.lang.Object
  extended byde.michab.simulator.DefaultChip
      extended byde.michab.simulator.mos6502.Cpu6510
All Implemented Interfaces:
Addressable, Chip, Processor

public class Cpu6510
extends DefaultChip
implements Processor

Implements a MOS6510 processor as built into the C64. For the implementation the following documentation was used:

Version:
$Revision: 1.37 $
Author:
Michael Binz

Field Summary
static int IRQ_VECTOR
           
static int NMI_VECTOR
           
static int RESET_VECTOR
          Processor specific constants.
static int STATUS_FLAG_BREAK
           
static int STATUS_FLAG_CARRY
           
static int STATUS_FLAG_DECIMAL
           
static int STATUS_FLAG_INTERRUPT
           
static int STATUS_FLAG_NEGATIVE
           
static int STATUS_FLAG_OVERFLOW
           
static int STATUS_FLAG_ZERO
           
 
Fields inherited from interface de.michab.simulator.Processor
BIT_0, BIT_1, BIT_2, BIT_3, BIT_4, BIT_5, BIT_6, BIT_7, BIT_8, DEC_0, DEC_1, DEC_2, DEC_3, DEC_4, DEC_5, DEC_6, DEC_7, DEC_8, DEC_9
 
Constructor Summary
Cpu6510(Memory mem, Clock clock)
          Create a processor tied to the passed memory.
 
Method Summary
 int getAccu()
          Read the accu.
 Memory getMemory()
          Get the Memory this CPU is attached to.
 int getPC()
          Read the program counter.
 Port[] getPorts()
          Get this processors ports.
 byte getStatusRegister()
          Get our status flags into a byte value.
 int getX()
          Read the x register.
 int getY()
          Read the y register.
 void IRQ()
          Handles the IRQ interrupt.
 boolean isStatusFlagSet(int statusEnum)
          Test a single status register flag.
 void NMI()
          Handles the NMI interrupt.
 byte read(int i)
          Read this processor's ports.
 void reset()
          Initialises the program counter from the reset vector.
 void setAccu(int a)
          Sets the accu register.
 void setDebugger(Debugger d)
          Sets a debugger on this processor instance.
 void setPC(int pc)
          Set the program counter to a new address.
 void setPortListener(int portId, Forwarder listener)
          Sets a listener on the passed port.
 void setStatusRegister(byte status)
          Set our status flags from a byte value.
 void setX(int x)
          Sets the x register.
 void setY(int y)
          Sets the y register.
 void stealCycles(int count)
          experimental TODO
 java.lang.String toString()
          Returns a string representation of this processor for debug purposes.
 void write(int i, byte b)
          Write this processor's ports.
 
Methods inherited from class de.michab.simulator.DefaultChip
createPorts
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STATUS_FLAG_CARRY

public static final int STATUS_FLAG_CARRY
See Also:
Constant Field Values

STATUS_FLAG_ZERO

public static final int STATUS_FLAG_ZERO
See Also:
Constant Field Values

STATUS_FLAG_INTERRUPT

public static final int STATUS_FLAG_INTERRUPT
See Also:
Constant Field Values

STATUS_FLAG_DECIMAL

public static final int STATUS_FLAG_DECIMAL
See Also:
Constant Field Values

STATUS_FLAG_BREAK

public static final int STATUS_FLAG_BREAK
See Also:
Constant Field Values

STATUS_FLAG_OVERFLOW

public static final int STATUS_FLAG_OVERFLOW
See Also:
Constant Field Values

STATUS_FLAG_NEGATIVE

public static final int STATUS_FLAG_NEGATIVE
See Also:
Constant Field Values

RESET_VECTOR

public static final int RESET_VECTOR
Processor specific constants.

See Also:
Constant Field Values

IRQ_VECTOR

public static final int IRQ_VECTOR
See Also:
Constant Field Values

NMI_VECTOR

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

Cpu6510

public Cpu6510(Memory mem,
               Clock clock)
Create a processor tied to the passed memory. Note that this memory has to contain some valid instruction sequences. Especially a valid reset vector has to be included to successfully start the emulation.

Parameters:
mem - The memory to attach to the new processor instance.
clock - A reference to the system clock.
Method Detail

getMemory

public Memory getMemory()
Get the Memory this CPU is attached to.

Returns:
The Memory this CPU is attached to.

write

public void write(int i,
                  byte b)
Write this processor's ports.

Specified by:
write in interface Addressable
Parameters:
i - The port number to write.
b - The value to write.

read

public byte read(int i)
Read this processor's ports.

Specified by:
read in interface Addressable
Parameters:
i - The port number.
Returns:
The value read from the port.

setPortListener

public void setPortListener(int portId,
                            Forwarder listener)
Sets a listener on the passed port.

Parameters:
portId - The port the listener is assigned to.
listener - The listener for the port.

getPorts

public Port[] getPorts()
Get this processors ports.

Specified by:
getPorts in interface Chip
Returns:
An array of ports.

getX

public int getX()
Read the x register. Result is normalised into range [0..255].

Returns:
The contents of the x register.

setX

public void setX(int x)
Sets the x register. Note that this must be called from the thread running the processor. This is not enforced because of performance reasons.

Parameters:
x - The new content for the x register.

getY

public int getY()
Read the y register.

Returns:
The contents of the y register.

setY

public void setY(int y)
Sets the y register. Note that this must be called from the thread running the processor. This is not enforced because of performance reasons.

Parameters:
y - The new value for the y register.

getAccu

public int getAccu()
Read the accu.

Returns:
The current contents of the accumulator register.

setAccu

public void setAccu(int a)
Sets the accu register. Note that this must be called from the thread running the processor. This is not enforced because of performance reasons.

Parameters:
a - The new value for the accumulator.

setPC

public void setPC(int pc)
Set the program counter to a new address.

Parameters:
pc - The new address for the program counter.

getPC

public int getPC()
Read the program counter.

Returns:
the current PC.

IRQ

public void IRQ()
Handles the IRQ interrupt. This method will be the entry point for threads controlling other chips in the simulation, hence needs to be synchronised.


NMI

public void NMI()
Handles the NMI interrupt.


stealCycles

public void stealCycles(int count)
experimental TODO

Parameters:
count -

getStatusRegister

public final byte getStatusRegister()
Get our status flags into a byte value.

Returns:
The contents of the status register.
See Also:
setStatusRegister(byte)

setStatusRegister

public final void setStatusRegister(byte status)
Set our status flags from a byte value.

Parameters:
status - The new value of the status register.

isStatusFlagSet

public boolean isStatusFlagSet(int statusEnum)
Test a single status register flag.

Parameters:
statusEnum - One of the status register constants, e.g. STATUS_FLAG_BREAK.
Returns:
The boolean value of the status flag.
See Also:
STATUS_FLAG_BREAK, STATUS_FLAG_CARRY, STATUS_FLAG_DECIMAL, STATUS_FLAG_INTERRUPT, STATUS_FLAG_NEGATIVE, STATUS_FLAG_OVERFLOW, STATUS_FLAG_ZERO

reset

public void reset()
Initialises the program counter from the reset vector.

Specified by:
reset in interface Chip

toString

public java.lang.String toString()
Returns a string representation of this processor for debug purposes.

Returns:
A string representation of this processor for debug purposes.

setDebugger

public void setDebugger(Debugger d)
Sets a debugger on this processor instance. To switch off debugging set this to null.

Specified by:
setDebugger in interface Processor
Parameters:
d - The debugger to be set.
See Also:
Processor.setDebugger( Debugger )