|
jmce - 1_02 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjmce.sim.AbstractHardware
jmce.sim.cpu.AbstractCPU
public abstract class AbstractCPU
Abstract implementation of CPU.
For performance reason log are conditioned to static flag and can be changed only recompiling this class.
At default the cpu will not start in real time mode but will use all the
resource available from the Java Virtual Machine. This can be a
little problem for play game, in this case use the method setRealTime(boolean)
to enable the real time emulation.
setRealTime(boolean)
Field Summary | |
---|---|
protected FastArray<Interrupt> |
interrupts
Array with all installed interrupt |
protected Memory |
io
I/O memory |
protected Memory |
memory
Main memory. |
static long |
NS100MS
Number of ns in 100 ms |
static long |
NS1MS
Number of ns in 1 ms |
Fields inherited from interface jmce.sim.CPU |
---|
BIG_ENDIAN, IO_MEMORY, LITTLE_ENDIAN, MAIN_MEMORY |
Constructor Summary | |
---|---|
AbstractCPU(java.lang.String name)
|
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 irq)
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 |
addLoader(Loader loader)
|
void |
addMemoryWriteListener(MemoryWriteListener l)
Add a memory write listener to the system memory. |
int |
addOffset(int word,
int offset)
Add a 8 bit signed offset to a 16 bit word |
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. |
static boolean |
bit0(int value)
Check the bit 0 of a value. |
static boolean |
bit7(int value)
Check the 7 bit of a value. |
void |
breakPointEvent(BreakPoint bp,
java.lang.String msg)
Break point event. |
protected CpuRuntime |
createRuntime()
CPU implementing istruction with RuntimeOpcode must in this method create the appropriate runtime class. |
java.lang.String |
decodeAt(int pc)
Decode the istruction at the specified address. |
void |
destroy()
Destroy the device. |
void |
dumpStatistics(java.io.PrintStream ps)
Dump cpu execution statistics in the specified stream. |
void |
dumpStatistics(java.lang.String file)
Dump cpu execution statistics in the specified file. |
protected void |
dumpTitle(java.io.PrintStream ps,
java.lang.String s1,
java.lang.String s2)
Dump the title of new section. |
protected void |
dumpValue(java.io.PrintStream ps,
long n,
java.lang.String s)
Dump a vale on the specificed stream. |
protected void |
dumpValue(java.io.PrintStream ps,
java.lang.String s1,
java.lang.String s2)
Dump a value on the speficied stream. |
int |
fetch(int a)
Fecth a byte from the memory for exec istructions. |
int |
fireISR(Interrupt i)
This function must be overridden from sub class that implements interrupt. |
int |
fireNMI(Interrupt i)
This function must be overridden from sub class that implements NMI interrupt. |
static java.lang.String |
formatFrequence(long hz)
|
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. |
CallListener |
getCallListener(int a)
|
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. |
jmce.sim.cpu.SortedVector<Opcode> |
getExecStatistics()
|
int |
getInterruptCount()
|
int |
getInterruptCounter(int n)
|
java.lang.String |
getInterruptName(int n)
|
int |
getIOByte(int a)
Get a byte from the I/O memory. |
int |
getLenghtAt(int pc)
Return the lenght of one instruction |
Memory |
getMemory()
Return the main memory |
Memory |
getMemoryAt(int i)
Return the memory at the specified position |
int |
getMemoryCount()
Debug interface |
Memory |
getMemoryForName(java.lang.String name)
Return the memory for name. |
AbstractOpcode |
getOpcodeAt(int pc)
|
MultiOpcode |
getOpcodes()
Return the CPU opocode table. |
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 |
getWordBig(int a)
|
int |
getWordLittle(int a)
|
protected void |
halt()
Special istruction general pourpse HALT If interrupt are disable one exception is thrown otherwise call the idle() method till one interrupt will be fired. |
int |
idle()
Idle cycle. |
void |
init(Hardware parent)
Initialize the hardware. |
boolean |
isBigEndian()
Return true if the byte order of the cpu is Big Endian |
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 irq)
Notity the cpu the specified isr can have changed state. |
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 |
reset()
Reset the CPU and call all installed ResetListener. |
protected void |
resetRegisters()
Reset all register to default value. |
void |
run()
|
void |
run0()
Run the cpu till one exception occour. |
void |
setByte(int a,
int value)
Set a byte on the Main memory. |
void |
setCallListener(int a,
CallListener l)
|
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 |
setIO(Memory io)
|
void |
setIOByte(int a,
int v)
Set a byte in the I/O memory. |
protected void |
setMemory(Memory m)
|
void |
setOpcode(AbstractOpcode o)
|
void |
setRealTime(boolean mode)
Set the real time emulation mode. |
void |
setResetAddress(int value)
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 till)
Set the break address. |
void |
start()
Start the CPU |
int |
step()
Exec one step and return the number of cycle used. |
int |
step0()
Exec one instruction. |
int |
stepNoBreak()
|
void |
stop()
Stop the CPU |
Methods inherited from class jmce.sim.AbstractHardware |
---|
addHardware, createFrame, getHardware, getHardware, getHardware, getHardware, getHardware, getHardwareCount, getHardwareForName, getHardwareInstances, getHardwareTree, getName, getParent, initSwing, removeHardware, removeHardware, setHardware, setHardware, setName, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface jmce.sim.CPU |
---|
getWord, isInterruptEnabled, pc, pc, setWord |
Methods inherited from interface jmce.sim.Hardware |
---|
addHardware, getHardware, getHardware, getHardware, getHardware, getHardwareCount, getHardwareInstances, getHardwareTree, getName, getParent, initSwing, removeHardware, removeHardware, setHardware, setHardware, setName |
Field Detail |
---|
public static final long NS1MS
public static final long NS100MS
protected FastArray<Interrupt> interrupts
protected Memory memory
protected Memory io
Constructor Detail |
---|
public AbstractCPU(java.lang.String name)
Method Detail |
---|
public final int addOffset(int word, int offset)
word
- - Source wordoffset
- - 8 bit signed offset
public long getCycle()
CPU
getCycle
in interface CPU
public long getClock()
CPU
getClock
in interface CPU
public void setClock(long clock)
CPU
setClock
in interface CPU
public void setClockPerCycle(int n)
CPU
setClockPerCycle
in interface CPU
public int getClockPerCycle()
CPU
getClockPerCycle
in interface CPU
public int getDecoderCount()
CPU
getDecoderCount
in interface CPU
public Decoder addDecoder(Decoder d)
CPU
addDecoder
in interface CPU
d
- - DecoderDecoder
public Decoder getDecoderAt(int i)
CPU
getDecoderAt
in interface CPU
public int getRegisterCount()
CPU
getRegisterCount
in interface CPU
public Register getRegisterForName(java.lang.String name)
CPU
getRegisterForName
in interface CPU
public Register addRegister(Register r)
CPU
addRegister
in interface CPU
public Register getRegisterAt(int i)
CPU
getRegisterAt
in interface CPU
public void setEndian(int n)
CPU
setEndian
in interface CPU
CPU.LITTLE_ENDIAN
,
CPU.BIG_ENDIAN
public final int getEndian()
CPU
getEndian
in interface CPU
CPU.LITTLE_ENDIAN
,
CPU.BIG_ENDIAN
public final boolean isLittleEndian()
CPU
isLittleEndian
in interface CPU
public final boolean isBigEndian()
CPU
isBigEndian
in interface CPU
public void addMemoryWriteListener(MemoryWriteListener l)
CPU
addMemoryWriteListener
in interface CPU
public final Memory getMemory()
CPU
getMemory
in interface CPU
protected final void setMemory(Memory m)
public void addCycleListener(CycleListener l)
CPU
This event is fired after the execution of every instructions. Please use only when necessary because can have large impact on simulator performance.
addCycleListener
in interface CPU
l
- - The listener to register.public void setOpcode(AbstractOpcode o)
public final AbstractOpcode getOpcodeAt(int pc) throws SIMException
SIMException
public final int getLenghtAt(int pc) throws SIMException
getLenghtAt
in interface CPU
SIMException
public java.lang.String decodeAt(int pc) throws SIMException
CPU
decodeAt
in interface CPU
SIMException
public final void setByte(int a, int value) throws SIMException
CPU
setByte
in interface CPU
a
- - Addressvalue
- - Value.
SIMException
public final int fetch(int a) throws SIMException
CPU
fetch
in interface CPU
SIMException
public final int getByte(int a) throws SIMException
CPU
getByte
in interface CPU
a
- - Address
SIMException
public final int getWordLittle(int a) throws SIMException
SIMException
public final int getWordBig(int a) throws SIMException
SIMException
protected void resetRegisters() throws SIMException
SIMException
public void reset() throws SIMException
Reset is performed in this order :
reset
in interface Hardware
reset
in class AbstractHardware
SIMException
public void setTill(int till)
CPU
setTill
in interface CPU
public long getCycleMillis()
CPU
getCycleMillis
in interface CPU
public void addTimerMs(Timer t)
CPU
After every sec/1000 calculated using the clock machine the timer is decremeted and when reach 0 the timer is fired.
addTimerMs
in interface CPU
t
- - the timer.Timer
public void addTimerCycle(Timer t)
CPU
After every clock machine the timer is decremented and when reach 0 the timer is fired.
addTimerCycle
in interface CPU
t
- - the timer.Timer
public int step() throws SIMException
CPU
step
in interface CPU
SIMException
public final int stepNoBreak() throws SIMException
SIMException
public final int step0() throws SIMException
SIMException
public final void run0() throws SIMException
SIMException
public final void run()
run
in interface java.lang.Runnable
public boolean isRunning()
CPU
isRunning
in interface CPU
public void start()
CPU
start
in interface CPU
CPU.isRunning()
public void stop()
CPU
stop
in interface CPU
CPU.isRunning()
protected void dumpValue(java.io.PrintStream ps, java.lang.String s1, java.lang.String s2)
protected void dumpTitle(java.io.PrintStream ps, java.lang.String s1, java.lang.String s2)
protected void dumpValue(java.io.PrintStream ps, long n, java.lang.String s)
public void dumpStatistics(java.lang.String file) throws SIMException
dumpStatistics
in interface CPU
file
- - File name where dump cpu statistics.
SIMException
public void dumpStatistics(java.io.PrintStream ps)
ps
- - The print stream.public void destroy() throws SIMException
Hardware
destroy
in interface Hardware
destroy
in class AbstractHardware
SIMException
public ExceptionListener getExceptionListenerAt(int i)
CPU
getExceptionListenerAt
in interface CPU
public void addExceptionListener(ExceptionListener l)
CPU
addExceptionListener
in interface CPU
public int getExceptionListenerCount()
CPU
getExceptionListenerCount
in interface CPU
public void removeExceptionListener(ExceptionListener l)
CPU
removeExceptionListener
in interface CPU
public final int idle() throws SIMException
When called from the cpu emulation thread advance counter and check for new interrupt available if a new interrupt is available throw SIMInterrupted
idle
in interface CPU
SIMInterrupted
- When a new interrupt is available.
SIMException
public Memory getMemoryForName(java.lang.String name)
CPU
If no memory with the specified name is present return null.
getMemoryForName
in interface CPU
name
- - Name of the memory to be searched.
public void addLoader(Loader loader)
public void load(java.lang.String name, int base, LoadInfo info) throws SIMException
CPU
load
in interface CPU
name
- - Name of the file.base
- - Base address.info
- - Information filled when return.
SIMException
public void load(Memory m, java.lang.String name, int base, LoadInfo info) throws SIMException
CPU
load
in interface CPU
m
- - Memory where to load.name
- - Name of the file.base
- - Base address.info
- - Information filled when return.
SIMException
public int fireISR(Interrupt i) throws SIMException
fireISR
in interface CPU
SIMException
public int fireNMI(Interrupt i) throws SIMException
fireNMI
in interface CPU
SIMException
public static final java.lang.String formatFrequence(long hz)
public java.lang.String getUsageDesc()
CPU
This method is like getUsage() but return one string with nome information.
getUsageDesc
in interface CPU
public double getUsage()
CPU
getUsage
in interface CPU
public final MultiOpcode getOpcodes()
public void init(Hardware parent) throws SIMException
Hardware
init
in interface Hardware
init
in class AbstractHardware
parent
- Parent of this hardware.
SIMException
public void addResetListener(ResetListener l)
CPU
addResetListener
in interface CPU
l
- - Listenerpublic int getMemoryCount()
getMemoryCount
in interface CPU
public Memory getMemoryAt(int i)
CPU
getMemoryAt
in interface CPU
public int getBreakPointCount()
CPU
getBreakPointCount
in interface CPU
public BreakPoint getBreakPointAt(int i)
CPU
getBreakPointAt
in interface CPU
public void removeBreakPoint(BreakPoint b)
CPU
removeBreakPoint
in interface CPU
public void removeBreakPoint(int i)
CPU
removeBreakPoint
in interface CPU
public BreakPoint addExecBreakPoint(int m, int a)
CPU
Triggered when the specified location is executed from the cpu.
addExecBreakPoint
in interface CPU
public BreakPoint addReadBreakPoint(int m, int a)
CPU
Trigger when the specified location is readed from the cpu.
addReadBreakPoint
in interface CPU
public BreakPoint addWriteBreakPoint(int m, int a)
CPU
Triggered when the specified location si written from the cpu.
addWriteBreakPoint
in interface CPU
public void breakPointEvent(BreakPoint bp, java.lang.String msg)
BreakPointListener
breakPointEvent
in interface BreakPointListener
bp
- - Source BreakPointmsg
- - Short description of the breakpoint.public void addTraceListener(TraceListener t)
CPU
When a trace listener is installed it will be called with one or more string with the cpu trace in human reeadable form.
addTraceListener
in interface CPU
public void removeTraceListener(TraceListener t)
CPU
removeTraceListener
in interface CPU
public void setIO(Memory io)
public void addIOReadListener(MemoryReadListener l)
CPU
addIOReadListener
in interface CPU
public void addIOReadListener(int a, MemoryReadListener l)
CPU
addIOReadListener
in interface CPU
public void addIOWriteListener(int a, MemoryWriteListener l)
CPU
addIOWriteListener
in interface CPU
public void addIOWriteListener(MemoryWriteListener l)
CPU
addIOWriteListener
in interface CPU
public final void setIOByte(int a, int v) throws SIMException
CPU
setIOByte
in interface CPU
SIMException
public final int getIOByte(int a) throws SIMException
CPU
getIOByte
in interface CPU
SIMException
public void setResetAddress(int value)
CPU
setResetAddress
in interface CPU
public int getResetAddress()
CPU
getResetAddress
in interface CPU
public int getInterruptCount()
public java.lang.String getInterruptName(int n)
public int getInterruptCounter(int n)
public void setRealTime(boolean mode)
CPU
If the realtime mode is selected the cpu will run at the current clock. original speed.
setRealTime
in interface CPU
mode
- - Real time emulation mode.CPU.setClock(long)
public boolean getRealTime()
CPU
getRealTime
in interface CPU
CPU.setRealTime(boolean)
public void abort(java.lang.String s)
CPU
This method can be called from any thread.
abort
in interface CPU
public jmce.sim.cpu.SortedVector<Opcode> getExecStatistics()
protected void halt() throws SIMException
If interrupt are disable one exception is thrown otherwise call the idle() method till one interrupt will be fired.
This instructions is the only istruction multi cpu !!
SIMException
protected CpuRuntime createRuntime() throws SIMException
SIMException
public void setCallListener(int a, CallListener l)
public CallListener getCallListener(int a)
public void setStatusLine(char c)
CPU
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.
setStatusLine
in interface CPU
public final void addInterrupt(Interrupt irq)
CPU
addInterrupt
in interface CPU
addInterrupt
in interface InterruptManager
public final void notifyInterrupt(Interrupt irq)
CPU
notifyInterrupt
in interface CPU
notifyInterrupt
in interface InterruptManager
public static final boolean bit7(int value)
public static final boolean bit0(int value)
|
jmce - 1_02 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |