Class AbstractCPU

java.lang.Object
net.emustudio.emulib.plugin.AbstractPlugin
net.emustudio.emulib.plugin.cpu.AbstractCPU
All Implemented Interfaces:
CPU, Plugin

public abstract class AbstractCPU extends AbstractPlugin implements CPU
Publishes CPU context state for synchronous operations scheduled by the host.
  • Constructor Details

    • 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 Details

    • reset

      public final void reset()
      Description copied from interface: Plugin
      Reset plugin to its "initial state", as it was after calling Plugin.initialize().
      Specified by:
      reset in interface Plugin
    • reset

      public final void reset(int location)
      Description copied from interface: CPU
      Resets the CPU synchronously after the host has acknowledged actual execution exit.
      Specified by:
      reset in interface CPU
      Parameters:
      location - Program location in memory
    • setInstructionLocation

      public final boolean setInstructionLocation(int location)
      Description copied from interface: CPU
      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.

      Specified by:
      setInstructionLocation in interface CPU
      Parameters:
      location - new address of actual instruction
      Returns:
      true if operation was successful, false otherwise
    • execute

      public final CPU.RunState execute() throws Exception
      Description copied from interface: CPU
      Runs the instruction loop synchronously until natural completion or cooperative interruption. The host supplies the worker thread, serializes CPU mutations, and publishes lifecycle events. Return STATE_RUNNING when interrupted without another terminal reason; the host applies the requested pause/stop state. Natural halt, breakpoint, and failures must retain their actual result.
      Specified by:
      execute in interface CPU
      Throws:
      Exception
    • step

      public final CPU.RunState step() throws Exception
      Description copied from interface: CPU
      Executes one instruction synchronously on the host's CPU worker and returns its result.
      Specified by:
      step in interface CPU
      Throws:
      Exception
    • classifyExecutionFailure

      public static CPU.RunState classifyExecutionFailure(Throwable failure)
      Classifies a thrown execution failure, including an address error wrapped by a CPU engine.
    • cpuContext

      protected abstract AbstractCPUContext cpuContext()
      Returns the same context instance the plugin registers for the host.
    • executeInternal

      protected abstract CPU.RunState executeInternal() throws Exception
      Throws:
      Exception
    • stepInternal

      protected abstract CPU.RunState stepInternal() throws Exception
      Throws:
      Exception
    • resetInternal

      protected abstract void resetInternal(int location)
    • setInstructionLocationInternal

      protected abstract boolean setInstructionLocationInternal(int location)
    • destroy

      public final void destroy()
      Host calls only after actual execution exit. No stop request or thread waiting occurs here.
      Specified by:
      destroy in interface Plugin
    • destroyInternal

      protected abstract void destroyInternal()