Interface CPU

  • All Superinterfaces:
    Plugin
    All Known Implementing Classes:
    AbstractCPU

    public interface CPU
    extends Plugin
    CPU plugin root interface.

    Should be implemented by a plugin. There should exist just one implementation.

    CPU can define one or more "CPU contexts" (usually just one), which can extend the runtime functionality accessible to plugins.

    See Also:
    CPUContext
    • Method Detail

      • addCPUListener

        void addCPUListener​(CPU.CPUListener listener)
        Adds the specified CPU listener to receive CPU events from this CPU.

        CPU events occur when CPU changes its state, or run state. CPU state events don't occur if CPU is running, only happens with run state changes. If listener is null, no exception is thrown and no action is performed.

        Parameters:
        listener - the CPU listener
      • removeCPUListener

        void removeCPUListener​(CPU.CPUListener listener)
        Removes the specified CPU listener so that it no longer receives CPU events from this CPU.

        CPU events occur when CPU changes its state, or run state. CPU state events don't occur if CPU is running, only happens with run state changes. If listener is null, no exception is thrown and no action is performed.

        Parameters:
        listener - the CPU listener to be removed
      • step

        void step()
        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.
      • execute

        void execute()
        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

        void pause()
        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

        void stop()
        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.
      • getStatusPanel

        javax.swing.JPanel getStatusPanel()
        Get CPU status panel.

        Each CPU plugin must have a status panel that shows some important CPU status (e.g. registers, flags, run state, etc.) and allows to manage some settings (e.g. a runtime frequency, etc.).

        This panel is located on the right side in the "emulation" panel of the main module.

        CPU itself should take care about updating the panel when it is appropriate.

        Returns:
        CPU status panel
      • isBreakpointSupported

        boolean isBreakpointSupported()
        Determine whether breakpoints are supported by CPU.
        Returns:
        true if breakpoints are supported, false otherwise
      • setBreakpoint

        void setBreakpoint​(int location)
        Set a breakpoint at a memory location.

        Does nothing if breakpoints are not supported.

        Parameters:
        location - memory location where the breakpoint will be set
        Throws:
        java.lang.IndexOutOfBoundsException - if the memLocation is out of bounds
        See Also:
        isBreakpointSupported()
      • unsetBreakpoint

        void unsetBreakpoint​(int location)
        Unset a breakpoint at a memory location.

        Does nothing if breakpoints are not supported.

        Parameters:
        location - memory location from where the breakpoint will be unset
        Throws:
        java.lang.IndexOutOfBoundsException - if the memLocation is out of bounds
        See Also:
        isBreakpointSupported()
      • isBreakpointSet

        boolean isBreakpointSet​(int location)
        Determine if a breakpoint is set at a memory location.
        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.
        Throws:
        java.lang.IndexOutOfBoundsException - if the memLocation is out of bounds
        See Also:
        isBreakpointSupported()
      • reset

        void reset​(int location)
        Resets the CPU and sets instruction position to given program location.
        Parameters:
        location - Program location in memory
      • getInstructionLocation

        int getInstructionLocation()
        Get memory location of an instruction which will be emulated as next.

        Instruction position is more "abstract" name for "program counter", which is mostly used in 8-bit architectures.

        Returns:
        memory location of an instruction which will be emulated as next
      • setInstructionLocation

        boolean setInstructionLocation​(int location)
        Set memory location of an instruction which will be emulated as next.

        Instruction position is more "abstract" name for "program counter", which is mostly used in 8-bit architectures.

        This method is called by emuStudio application when a user perform "jump to address" operation.

        Parameters:
        location - new address of actual instruction
        Returns:
        true if operation was successful, false otherwise
      • getDisassembler

        Disassembler getDisassembler()
        Get disassembler.

        EmuStudio uses it for filling up the debugger table.

        Returns:
        disassembler of CPU instructions