jmce - 1_02

jmce.sim
Interface CPU

All Superinterfaces:
Hardware, InterruptManager, java.lang.Runnable
All Known Implementing Classes:
AbstractCPU, Altair, AT89C51RD2, CMON51, Diseqc, I8080, I8086, Imsai, LPC764, LPC900, LPC936, M6502, M68HC05, M68HC08, MCS51, MCS52, P2000T, PCXT, S400, Spectrum, Spectrum128K, Spectrum48K, V8052, VIC20, Yaze, Z80, Z80Pack

public interface CPU
extends Hardware, java.lang.Runnable, InterruptManager

This interface rappresent one CPU.

Minimun CPU requirement

Version:
1.02
Author:
Mario Viara

Field Summary
static int BIG_ENDIAN
          Big endian cpu - higghest byte first
static java.lang.String IO_MEMORY
          Name used for i/o memory
static int LITTLE_ENDIAN
          Little endian cpu - lowest byte first
static java.lang.String MAIN_MEMORY
          Name used for main memory
 
Method Summary
 void abort(java.lang.String s)
          Abort the cpu execution.
 void addCycleListener(CycleListener l)
          Register listener so that it will receive cycle event.
 Decoder addDecoder(Decoder d)
          Add a new decoder.
 void addExceptionListener(ExceptionListener l)
          Add a new listener called when one new exception is detected
 BreakPoint addExecBreakPoint(int m, int a)
          Add a new exec break point.
 void addInterrupt(Interrupt isr)
          Add a new interrupt to this CPU
 void addIOReadListener(int a, MemoryReadListener l)
          Add a MemoryReadListener to the I/O memory.
 void addIOReadListener(MemoryReadListener l)
          Add a global MemoryReadListener to the I/O memory,
 void addIOWriteListener(int a, MemoryWriteListener l)
          Add a Memory write listener to the I/O memory.
 void addIOWriteListener(MemoryWriteListener l)
          Add a global MemoryWriteListener to the I/O memory,
 void addMemoryWriteListener(MemoryWriteListener l)
          Add a memory write listener to the system memory.
 BreakPoint addReadBreakPoint(int m, int a)
          Add a new read break point.
 Register addRegister(Register r)
          Add a Register
 void addResetListener(ResetListener l)
          Add a new reset listener.
 void addTimerCycle(Timer t)
          Add a new timer as clock the machine cycle.
 void addTimerMs(Timer t)
          Add a new timer as clock sec/1000 but using the machine cycle.
 void addTraceListener(TraceListener t)
          Add a new trace listener.
 BreakPoint addWriteBreakPoint(int m, int a)
          Add a new write break point.
 java.lang.String decodeAt(int pc)
          Decode the istruction at the specified address.
 void dumpStatistics(java.lang.String filename)
          Create a file with the cpu usage statistics
 int fetch(int pc)
          Fecth a byte from the memory for exec istructions.
 int fireISR(Interrupt isr)
          Fire a new ISR
 int fireNMI(Interrupt i)
          Fire a new non maskerable interrupt.
 BreakPoint getBreakPointAt(int i)
          Return the specified break point.
 int getBreakPointCount()
          Return the number of installed break point.
 int getByte(int a)
          Return a byte of memory from the main memory.
 long getClock()
          Return che CPU clock in Hz.
 int getClockPerCycle()
          Get the number of clock used for cycle
 long getCycle()
          Return the current clock cycle of the CPU.
 long getCycleMillis()
          Return the number of cycle per ms.
 Decoder getDecoderAt(int i)
          Get a decoder.
 int getDecoderCount()
          Get the number of installed decoder
 int getEndian()
          Get the cpu 'endianess'
 ExceptionListener getExceptionListenerAt(int i)
          Return the specified exception listener.
 int getExceptionListenerCount()
          Return the number of exception listener installed.
 int getIOByte(int a)
          Get a byte from the I/O memory.
 int getLenghtAt(int pc)
          Return the lenght in byte of the istruction at the specified address.
 Memory getMemory()
          Return the main memory
 Memory getMemoryAt(int i)
          Return the memory at the specified position
 int getMemoryCount()
          Return the number of memory installed in the cpu
 Memory getMemoryForName(java.lang.String name)
          Return the memory for name.
 boolean getRealTime()
          Return the real time emulation mode.
 Register getRegisterAt(int i)
          Return the specified Register
 int getRegisterCount()
          Get the number of register present in the CPU
 Register getRegisterForName(java.lang.String name)
          Search one register for name
 int getResetAddress()
          Return the value of PC at reset.
 double getUsage()
          Get CPU usage return the CPU usage of the simulator thread, high value (more than 90.00) means the current java machine is too slow to execute the simulator.
 java.lang.String getUsageDesc()
          Get CPU usage in string format.
 int getWord(int a)
          Read one word (16 bit) from the main memory.
 int idle()
          Release the cpu for few ms.
 boolean isBigEndian()
          Return true if the byte order of the cpu is Big Endian
 boolean isInterruptEnabled()
          Return the status of the interrupt enable
 boolean isLittleEndian()
          Return true if the byte order of the cpu is Little Endian
 boolean isRunning()
          Return true is the CPU is running.
 void load(Memory m, java.lang.String name, int base, LoadInfo info)
          Load a program in the specified memory.
 void load(java.lang.String name, int base, LoadInfo info)
          Load a program in the default memory.
 void notifyInterrupt(Interrupt isr)
          Notity the cpu the specified isr can have changed state.
 int pc()
          Return the register used as program counter
 void pc(int value)
          Set the program counter.
 void removeBreakPoint(BreakPoint b)
          Remove the specified breakpoint
 void removeBreakPoint(int i)
          Remove the specified break point.
 void removeExceptionListener(ExceptionListener l)
          Remove one exception listener.
 void removeTraceListener(TraceListener t)
          Remove the specified trace listener
 void setByte(int a, int v)
          Set a byte on the Main memory.
 void setClock(long clock)
          Set the CPU clock in Hz.
 void setClockPerCycle(int n)
          Set the number of clock used for cycle during instruction execution.
 void setEndian(int n)
          Set cpu 'endianess'
 void setIOByte(int a, int v)
          Set a byte in the I/O memory.
 void setRealTime(boolean mode)
          Set the real time emulation mode.
 void setResetAddress(int address)
          Set the value of the PC at reset.
 void setStatusLine(char c)
          Set a char on the status line The status line is the last line of the display and is reserved for JMCE message the first part of the line will display the type of cpu, the configured clock, the current clock and the VM usage.
 void setTill(int address)
          Set the break address.
 void setWord(int a, int v)
          Set one word (16 bit) in the main memory
 void start()
          Start the CPU
 int step()
          Exec one step and return the number of cycle used.
 void stop()
          Stop the CPU
 
Methods inherited from interface jmce.sim.Hardware
addHardware, destroy, getHardware, getHardware, getHardware, getHardware, getHardwareCount, getHardwareInstances, getHardwareTree, getName, getParent, init, initSwing, removeHardware, removeHardware, reset, setHardware, setHardware, setName
 
Methods inherited from interface java.lang.Runnable
run
 

Field Detail

MAIN_MEMORY

static final java.lang.String MAIN_MEMORY
Name used for main memory

See Also:
Constant Field Values

IO_MEMORY

static final java.lang.String IO_MEMORY
Name used for i/o memory

See Also:
Constant Field Values

LITTLE_ENDIAN

static final int LITTLE_ENDIAN
Little endian cpu - lowest byte first

See Also:
Constant Field Values

BIG_ENDIAN

static final int BIG_ENDIAN
Big endian cpu - higghest byte first

See Also:
Constant Field Values
Method Detail

setEndian

void setEndian(int n)
Set cpu 'endianess'

See Also:
LITTLE_ENDIAN, BIG_ENDIAN

getEndian

int getEndian()
Get the cpu 'endianess'

See Also:
LITTLE_ENDIAN, BIG_ENDIAN

isBigEndian

boolean isBigEndian()
Return true if the byte order of the cpu is Big Endian


isLittleEndian

boolean isLittleEndian()
Return true if the byte order of the cpu is Little Endian


getClock

long getClock()
Return che CPU clock in Hz.


setClock

void setClock(long clock)
Set the CPU clock in Hz.


setClockPerCycle

void setClockPerCycle(int n)
Set the number of clock used for cycle during instruction execution.


getClockPerCycle

int getClockPerCycle()
Get the number of clock used for cycle


getCycle

long getCycle()
Return the current clock cycle of the CPU. This value will be set to 0 after any reset.


addCycleListener

void addCycleListener(CycleListener l)
Register listener so that it will receive cycle event.

This event is fired after the execution of every instructions. Please use only when necessary because can have large impact on simulator performance.

Parameters:
l - - The listener to register.

addRegister

Register addRegister(Register r)
Add a Register


getRegisterAt

Register getRegisterAt(int i)
Return the specified Register


getRegisterCount

int getRegisterCount()
Get the number of register present in the CPU


getRegisterForName

Register getRegisterForName(java.lang.String name)
Search one register for name


addDecoder

Decoder addDecoder(Decoder d)
Add a new decoder.

Parameters:
d - - Decoder
See Also:
Decoder

getDecoderCount

int getDecoderCount()
Get the number of installed decoder

Returns:
the number of installed decoders.

getDecoderAt

Decoder getDecoderAt(int i)
Get a decoder.

Returns:
the specified decoder.

isRunning

boolean isRunning()
Return true is the CPU is running.

Returns:
true if the CPU is running

start

void start()
Start the CPU

See Also:
isRunning()

stop

void stop()
Stop the CPU

See Also:
isRunning()

addExceptionListener

void addExceptionListener(ExceptionListener l)
Add a new listener called when one new exception is detected


removeExceptionListener

void removeExceptionListener(ExceptionListener l)
Remove one exception listener.


getExceptionListenerCount

int getExceptionListenerCount()
Return the number of exception listener installed.


getExceptionListenerAt

ExceptionListener getExceptionListenerAt(int i)
Return the specified exception listener.


step

int step()
         throws SIMException
Exec one step and return the number of cycle used.

Throws:
SIMException

idle

int idle()
         throws SIMException
Release the cpu for few ms. Return the number of ms elapsed. Normally called only from peripheral that run in thread context of the cpu.

Throws:
SIMException

setTill

void setTill(int address)
Set the break address.


pc

int pc()
       throws SIMException
Return the register used as program counter

Returns:
- Program counter.
Throws:
SIMException

pc

void pc(int value)
        throws SIMException
Set the program counter.

Parameters:
value - - New value for the program counter.
Throws:
SIMException

setByte

void setByte(int a,
             int v)
             throws SIMException
Set a byte on the Main memory. Set one byte on the main memory.

Parameters:
a - - Address
v - - Value.
Throws:
SIMException

setWord

void setWord(int a,
             int v)
             throws SIMException
Set one word (16 bit) in the main memory

Parameters:
a - - Address
v - - value
Throws:
SIMException

getWord

int getWord(int a)
            throws SIMException
Read one word (16 bit) from the main memory.

Parameters:
a - - Address
Returns:
The word at the specified address.
Throws:
SIMException

getByte

int getByte(int a)
            throws SIMException
Return a byte of memory from the main memory.

Parameters:
a - - Address
Returns:
byte read from the memory.
Throws:
SIMException

fetch

int fetch(int pc)
          throws SIMException
Fecth a byte from the memory for exec istructions. For not segmented CPU do the same of getByte.

Throws:
SIMException
Since:
1.01

decodeAt

java.lang.String decodeAt(int pc)
                          throws SIMException
Decode the istruction at the specified address.

Returns:
The decoded istruction of null if undefined.
Throws:
SIMException

getLenghtAt

int getLenghtAt(int pc)
                throws SIMException
Return the lenght in byte of the istruction at the specified address.

Throws:
SIMException

load

void load(Memory m,
          java.lang.String name,
          int base,
          LoadInfo info)
          throws SIMException
Load a program in the specified memory.

Parameters:
m - - Memory where to load.
name - - Name of the file.
base - - Base address.
info - - Information filled when return.
Throws:
SIMException

load

void load(java.lang.String name,
          int base,
          LoadInfo info)
          throws SIMException
Load a program in the default memory.

Parameters:
name - - Name of the file.
base - - Base address.
info - - Information filled when return.
Throws:
SIMException

addTimerCycle

void addTimerCycle(Timer t)
Add a new timer as clock the machine cycle.

After every clock machine the timer is decremented and when reach 0 the timer is fired.

Parameters:
t - - the timer.
See Also:
Timer

addTimerMs

void addTimerMs(Timer t)
Add a new timer as clock sec/1000 but using the machine cycle.

After every sec/1000 calculated using the clock machine the timer is decremeted and when reach 0 the timer is fired.

Parameters:
t - - the timer.
See Also:
Timer

getCycleMillis

long getCycleMillis()
Return the number of cycle per ms.


fireNMI

int fireNMI(Interrupt i)
            throws SIMException
Fire a new non maskerable interrupt. Only one NMI can be active at the same time on the system.

Throws:
SIMException

isInterruptEnabled

boolean isInterruptEnabled()
Return the status of the interrupt enable


getUsage

double getUsage()
Get CPU usage return the CPU usage of the simulator thread, high value (more than 90.00) means the current java machine is too slow to execute the simulator.

Returns:
cpu usage %

getUsageDesc

java.lang.String getUsageDesc()
Get CPU usage in string format.

This method is like getUsage() but return one string with nome information.

Returns:
One string with current cpu usage.

addResetListener

void addResetListener(ResetListener l)
Add a new reset listener. This type of listener will be called after inizialization and when the lister is called the machine is ready to run.

Parameters:
l - - Listener

getMemoryCount

int getMemoryCount()
Return the number of memory installed in the cpu


getMemory

Memory getMemory()
Return the main memory

Since:
1.02

getMemoryAt

Memory getMemoryAt(int i)
Return the memory at the specified position


getMemoryForName

Memory getMemoryForName(java.lang.String name)
Return the memory for name.

If no memory with the specified name is present return null.

Parameters:
name - - Name of the memory to be searched.
Returns:
The memory or null

getBreakPointCount

int getBreakPointCount()
Return the number of installed break point.


getBreakPointAt

BreakPoint getBreakPointAt(int i)
Return the specified break point.


removeBreakPoint

void removeBreakPoint(int i)
Remove the specified break point.


removeBreakPoint

void removeBreakPoint(BreakPoint b)
Remove the specified breakpoint

Since:
1.02

addExecBreakPoint

BreakPoint addExecBreakPoint(int m,
                             int a)
Add a new exec break point.

Triggered when the specified location is executed from the cpu.


addReadBreakPoint

BreakPoint addReadBreakPoint(int m,
                             int a)
Add a new read break point.

Trigger when the specified location is readed from the cpu.


addWriteBreakPoint

BreakPoint addWriteBreakPoint(int m,
                              int a)
Add a new write break point.

Triggered when the specified location si written from the cpu.


addTraceListener

void addTraceListener(TraceListener t)
Add a new trace listener.

When a trace listener is installed it will be called with one or more string with the cpu trace in human reeadable form.


removeTraceListener

void removeTraceListener(TraceListener t)
Remove the specified trace listener


addIOReadListener

void addIOReadListener(int a,
                       MemoryReadListener l)
Add a MemoryReadListener to the I/O memory.


addIOReadListener

void addIOReadListener(MemoryReadListener l)
Add a global MemoryReadListener to the I/O memory,

Since:
1.02

addIOWriteListener

void addIOWriteListener(MemoryWriteListener l)
Add a global MemoryWriteListener to the I/O memory,

Since:
1.02

addMemoryWriteListener

void addMemoryWriteListener(MemoryWriteListener l)
Add a memory write listener to the system memory.

Since:
1.01

addIOWriteListener

void addIOWriteListener(int a,
                        MemoryWriteListener l)
Add a Memory write listener to the I/O memory.


setIOByte

void setIOByte(int a,
               int v)
               throws SIMException
Set a byte in the I/O memory.

Throws:
SIMException

getIOByte

int getIOByte(int a)
              throws SIMException
Get a byte from the I/O memory.

Throws:
SIMException

setResetAddress

void setResetAddress(int address)
                     throws SIMException
Set the value of the PC at reset.

Throws:
SIMException

getResetAddress

int getResetAddress()
Return the value of PC at reset.


setRealTime

void setRealTime(boolean mode)
Set the real time emulation mode.

If the realtime mode is selected the cpu will run at the current clock. original speed.

Parameters:
mode - - Real time emulation mode.
See Also:
setClock(long)

getRealTime

boolean getRealTime()
Return the real time emulation mode.

See Also:
setRealTime(boolean)

abort

void abort(java.lang.String s)
Abort the cpu execution.

This method can be called from any thread.


dumpStatistics

void dumpStatistics(java.lang.String filename)
                    throws SIMException
Create a file with the cpu usage statistics

Throws:
SIMException

setStatusLine

void setStatusLine(char c)
Set a char on the status line

The status line is the last line of the display and is reserved for JMCE message the first part of the line will display the type of cpu, the configured clock, the current clock and the VM usage. The last char of the line display a character with the last I/O operation :

The status line will display the last status till do not change.

Since:
1.01

fireISR

int fireISR(Interrupt isr)
            throws SIMException
Fire a new ISR

Throws:
SIMException
Since:
1.01

notifyInterrupt

void notifyInterrupt(Interrupt isr)
Notity the cpu the specified isr can have changed state.

Specified by:
notifyInterrupt in interface InterruptManager
Since:
1.01

addInterrupt

void addInterrupt(Interrupt isr)
Add a new interrupt to this CPU

Specified by:
addInterrupt in interface InterruptManager
Since:
1.01

jmce - 1_02