Class 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

    • 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 ID
        applicationApi - emuStudio API
        settings - 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.

        Specified by:
        getTitle in interface Plugin
        Returns:
        run-time title of the plugin
      • showSettings

        public void showSettings​(javax.swing.JFrame parent)
        Does nothing. Should be overridden.
        Specified by:
        showSettings in interface Plugin
        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 interface Plugin
        Returns:
        false
      • isBreakpointSupported

        public boolean isBreakpointSupported()
        This class support breakpoints.
        Specified by:
        isBreakpointSupported in interface CPU
        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 interface CPU
        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 interface CPU
        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 interface CPU
        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 interface CPU
        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 interface CPU
        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.

        Specified by:
        destroy in interface Plugin
      • 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().

        Specified by:
        reset in interface Plugin
      • reset

        public void reset​(int location)
        Description copied from interface: CPU
        Resets the CPU and sets instruction position to given program location.
        Specified by:
        reset in interface CPU
        Parameters:
        location - Program location in memory
      • 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.

        Specified by:
        execute in interface CPU
      • 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".
        Specified by:
        pause in interface CPU
      • 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 methods step(), pause(), execute() until user resets the CPU. Debug window in main module should be updated with saved CPU state.
        Specified by:
        stop in interface CPU
      • 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.
        Specified by:
        step in interface CPU
      • 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 calling reset(pos))