Trait ControlUnit

Source
pub trait ControlUnit {
    type BusDevice: BusDevice;

    // Required methods
    fn bus_device_mut(&mut self) -> &mut Self::BusDevice;
    fn bus_device_ref(&self) -> &Self::BusDevice;
    fn into_bus_device(self) -> Self::BusDevice;
    fn reset<C>(&mut self, cpu: &mut C, hard: bool)
       where C: Cpu;
    fn nmi<C>(&mut self, cpu: &mut C) -> bool
       where C: Cpu;
    fn execute_next_frame<C>(&mut self, cpu: &mut C)
       where C: Cpu;
    fn ensure_next_frame(&mut self);
    fn execute_single_step<C, F>(
        &mut self,
        cpu: &mut C,
        debug: Option<F>,
    ) -> Result<(), BreakCause<(), ()>>
       where C: Cpu,
             F: FnOnce(CpuDebug);
}
Expand description

This trait provides the interface for running the emulation and accessing instances of peripheral devices.

It’s being implemented by the emulators of core chipsets.

Required Associated Types§

Source

type BusDevice: BusDevice

A type of a chain of emulated peripheral devices should be declared here.

This determines which devices, the emulated computer will be able to interact with.

An associated constant: BusDevice::Timestamp must match the associated type declared for implementations of z80emu traits such as Io::Timestamp or Memory::Timestamp.

Required Methods§

Source

fn bus_device_mut(&mut self) -> &mut Self::BusDevice

Returns a mutable reference to the instance of the first bus device in the device chain.

Source

fn bus_device_ref(&self) -> &Self::BusDevice

Returns a reference to the the instance of the first bus device in the device chain.

Source

fn into_bus_device(self) -> Self::BusDevice

Destructs self and returns the instance of the bus device.

Source

fn reset<C>(&mut self, cpu: &mut C, hard: bool)
where C: Cpu,

Performs a system reset.

When hard is:

  • true emulates a RESET signal being active for the cpu and all bus devices.
  • false executes a RST 0 instruction on the cpu but without forwarding the clock counter.

In any case, this operation is always instant.

Source

fn nmi<C>(&mut self, cpu: &mut C) -> bool
where C: Cpu,

Triggers a non-maskable interrupt. Returns true if NMI was accepted.

Returns false when the cpu has just executed an EI instruction or one of 0xDD, 0xFD prefixes. In this instance, calling this method is a no-op, and it returns false.

For more details see z80emu::Cpu::nmi.

Source

fn execute_next_frame<C>(&mut self, cpu: &mut C)
where C: Cpu,

Conditionally prepares the internal state for the next frame and executes instructions on the cpu as fast as possible, until the near end of that frame.

Source

fn ensure_next_frame(&mut self)

Conditionally prepares the internal state for the next frame, advances the frame counter, and wraps the T-state counter if it is near the end of a frame.

This method should be called after all side effects (e.g. video and audio rendering) have been taken care of. Usually, implementations will clear internal data from a previous frame.

Both ControlUnit::execute_next_frame and ControlUnit::execute_single_step invoke this method internally, so the only reason to call this method from the emulator program would be to make sure internal buffers are empty before feeding the implementation with external data that will be consumed by devices during the next frame.

Source

fn execute_single_step<C, F>( &mut self, cpu: &mut C, debug: Option<F>, ) -> Result<(), BreakCause<(), ()>>
where C: Cpu, F: FnOnce(CpuDebug),

Executes a single instruction on the cpu with the option to pass a debugging function.

If the T-state counter value is near the end of a frame, prepares the internal state for the next frame before executing the next instruction.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<B, X> ControlUnit for Ula3<B, X>

Source§

impl<B, X> ControlUnit for Ula128<B, X>

Source§

impl<M, B, X, V> ControlUnit for Scld<M, B, X, V>

Source§

impl<M, B, X, V> ControlUnit for Ula<M, B, X, V>

Source§

impl<P: AyPortDecode> ControlUnit for AyPlayer<P>

Source§

impl<U, B, X> ControlUnit for UlaPlus<U>
where U: for<'a> UlaPlusInner<'a> + ControlUnit<BusDevice = B> + UlaControlExt + MemoryAccess<MemoryExt = X> + Memory<Timestamp = VideoTs> + Io<Timestamp = VideoTs, WrIoBreak = (), RetiBreak = ()>, B: BusDevice, B::Timestamp: From<VFrameTs<U::VideoFrame>>, X: MemoryExtension,