Class AbstractCPU
- java.lang.Object
-
- net.emustudio.emulib.plugins.cpu.AbstractCPU
-
- All Implemented Interfaces:
java.util.concurrent.Callable<CPU.RunState>
,CPU
,Plugin
@ThreadSafe public abstract class AbstractCPU extends java.lang.Object implements CPU, java.util.concurrent.Callable<CPU.RunState>
Implements fundamental functionality useful for most of the CPU plugins. Features include:- support of breakpoints - thread safe controlling of run states - managing CPU listeners
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.emustudio.emulib.plugins.cpu.CPU
CPU.CPUListener, CPU.RunState
-
-
Field Summary
Fields Modifier and Type Field Description protected ApplicationApi
applicationApi
emuStudio API.protected long
pluginID
Plugin ID assigned by emuStudioprotected PluginSettings
settings
CPU custom settings.
-
Constructor Summary
Constructors Constructor Description AbstractCPU(long pluginID, ApplicationApi applicationApi, PluginSettings settings)
Creates new instance of CPU.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addCPUListener(CPU.CPUListener listener)
Add new CPU listener to the list of stateObservers.void
destroy()
Destroys all plugin resources.protected abstract void
destroyInternal()
Called by original destroy() method.void
execute()
Runs CPU emulation.java.lang.String
getTitle()
Get run-time title of this plugin.boolean
isBreakpointSet(int location)
Determine if a breakpoint is set at a memory location.boolean
isBreakpointSupported()
This class support breakpoints.boolean
isShowSettingsSupported()
This class does not support showing settingsvoid
pause()
Pauses the CPU emulation.void
removeCPUListener(CPU.CPUListener listener)
Remove CPU listener object from the list of stateObservers.void
reset()
Reset plugin.void
reset(int location)
Resets the CPU and sets instruction position to given program location.protected abstract void
resetInternal(int startPos)
Performs specific CPU reset.void
setBreakpoint(int location)
Set a breakpoint at a memory location.void
showSettings(javax.swing.JFrame parent)
Does nothing.void
step()
Perform one step of CPU emulation.protected abstract CPU.RunState
stepInternal()
Perform one emulation step in synchronized context.void
stop()
Stops the CPU emulation.void
unsetBreakpoint(int location)
Unset a breakpoint at a memory location.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.emustudio.emulib.plugins.cpu.CPU
getDisassembler, getInstructionLocation, getStatusPanel, isAutomationSupported, setInstructionLocation
-
Methods inherited from interface net.emustudio.emulib.plugins.Plugin
getCopyright, getDescription, getVersion, initialize
-
-
-
-
Field Detail
-
pluginID
protected final long pluginID
Plugin ID assigned by emuStudio
-
applicationApi
protected final ApplicationApi applicationApi
emuStudio API.
-
settings
protected final PluginSettings settings
CPU custom settings.
-
-
Constructor Detail
-
AbstractCPU
public AbstractCPU(long pluginID, ApplicationApi applicationApi, PluginSettings settings)
Creates new instance of CPU.- Parameters:
pluginID
- plugin IDapplicationApi
- emuStudio APIsettings
- plugin custom settings
-
-
Method Detail
-
getTitle
public java.lang.String getTitle()
Description copied from interface:Plugin
Get run-time title of this plugin.The title is a matter of change during runtime - for example there might exist a device instantiated more than once, and each instance can have different title assigned at runtime.
-
showSettings
public void showSettings(javax.swing.JFrame parent)
Does nothing. Should be overridden.- Specified by:
showSettings
in interfacePlugin
- Parameters:
parent
- emuStudio main window (if plugin wants to show a dialog which has a parent)
-
isShowSettingsSupported
public boolean isShowSettingsSupported()
This class does not support showing settings- Specified by:
isShowSettingsSupported
in interfacePlugin
- Returns:
- false
-
isBreakpointSupported
public boolean isBreakpointSupported()
This class support breakpoints.- Specified by:
isBreakpointSupported
in interfaceCPU
- Returns:
- true
-
setBreakpoint
public void setBreakpoint(int location)
Description copied from interface:CPU
Set a breakpoint at a memory location.Does nothing if breakpoints are not supported.
- Specified by:
setBreakpoint
in interfaceCPU
- Parameters:
location
- memory location where the breakpoint will be set- See Also:
CPU.isBreakpointSupported()
-
unsetBreakpoint
public void unsetBreakpoint(int location)
Description copied from interface:CPU
Unset a breakpoint at a memory location.Does nothing if breakpoints are not supported.
- Specified by:
unsetBreakpoint
in interfaceCPU
- Parameters:
location
- memory location from where the breakpoint will be unset- See Also:
CPU.isBreakpointSupported()
-
isBreakpointSet
public boolean isBreakpointSet(int location)
Description copied from interface:CPU
Determine if a breakpoint is set at a memory location.- Specified by:
isBreakpointSet
in interfaceCPU
- Parameters:
location
- memory location, from where the breakpoint will be determined- Returns:
- true if breakpoint is set in the location, false otherwise or if breakpoints are not supported.
- See Also:
CPU.isBreakpointSupported()
-
addCPUListener
public void addCPUListener(CPU.CPUListener listener)
Add new CPU listener to the list of stateObservers. CPU listener is an implementation object of CPUListener interface. The methods are called when some events are occured on CPU.- Specified by:
addCPUListener
in interfaceCPU
- Parameters:
listener
- CPUListener object
-
removeCPUListener
public void removeCPUListener(CPU.CPUListener listener)
Remove CPU listener object from the list of stateObservers. If the listener is not included in the list, nothing will be done.- Specified by:
removeCPUListener
in interfaceCPU
- Parameters:
listener
- CPUListener object
-
destroy
public void destroy()
Description copied from interface:Plugin
Destroys all plugin resources.This method is called immediately after user closes the emulator.
Inside the method, the plugin should: - unregister all registered contexts for this plugin - execute clean-up/destroy code for used resources (timers, threads, sockets, memory, etc). - dispose all GUIs
NOTE: If not all resources are properly cleared, emuStudio will forcibly exit anyway, which may cause unexpected damage.
-
destroyInternal
protected abstract void destroyInternal()
Called by original destroy() method. Do not override the original destroy() method. Subsequent calls of destroy() will call this only once.
-
reset
public void reset()
Description copied from interface:Plugin
Reset plugin."Reset" means to bring the plugin to its "initial state", as it was after calling
Plugin.initialize()
.
-
reset
public void reset(int location)
Description copied from interface:CPU
Resets the CPU and sets instruction position to given program location.
-
execute
public void execute()
Description copied from interface:CPU
Runs CPU emulation. Change state of CPU to "running" and start instruction fetch/decode/execute loop.The emuStudio creates separate thread for this purpose.
While CPU is running, the emuStudio will not allow to call method
step()
.A good CPU should performs right timing for instructions here. Debug window should not be updated after each instruction execution, in order to the execution loop would be faster.
-
pause
public void pause()
Description copied from interface:CPU
Pauses the CPU emulation. If a thread was used for CPU execution and is running, then it should be stopped (destroyed) but the CPU state has to be saved for future run. CPU changes it state to "breakpoint".
-
stop
public void stop()
Description copied from interface:CPU
Stops the CPU emulation. If a thread was used for CPU execution and is running, then it should be stopped (destroyed) but the CPU state can be saved. CPU changes its state to "stopped" and main module should now forbid execution any of methodsstep()
,pause()
,execute()
until user resets the CPU. Debug window in main module should be updated with saved CPU state.
-
step
public void step()
Description copied from interface:CPU
Perform one step of CPU emulation. It means that one instruction should be executed. CPU state changes to state "running", then it executes one instruction, and then it should return to state "breakpoint" or "stopped". Correct timing of executed instruction isn't so important.
-
stepInternal
protected abstract CPU.RunState stepInternal() throws java.lang.Exception
Perform one emulation step in synchronized context.- Returns:
- new CPU state. If nothing bad happened, it should return RunState.STATE_STOPPED_BREAK.
- Throws:
java.lang.Exception
- The emulator is allowed to throw any exception
-
resetInternal
protected abstract void resetInternal(int startPos)
Performs specific CPU reset.CONTRACT: If this method throws an exception, the behavior is undefined.
- Parameters:
startPos
- starting position (similar to callingreset(pos)
)
-
-