Trait z80emu::host::Clock

source ·
pub trait Clock {
    type Limit: Sized + Copy;
    type Timestamp: Sized;

    // Required methods
    fn is_past_limit(&self, limit: Self::Limit) -> bool;
    fn add_irq(&mut self, pc: u16) -> Self::Timestamp;
    fn add_no_mreq(&mut self, address: u16, add_ts: NonZeroU8);
    fn add_m1(&mut self, address: u16) -> Self::Timestamp;
    fn add_mreq(&mut self, address: u16) -> Self::Timestamp;
    fn add_io(&mut self, port: u16) -> Self::Timestamp;
    fn add_wait_states(&mut self, bus: u16, wait_states: NonZeroU16);
    fn as_timestamp(&self) -> Self::Timestamp;
}
Expand description

This trait defines an interface to the system clock from the Cpu emulation perspective.

An implementation of this trait is responsible for counting T-states during various Cpu cycles.

It is however up to the implementation to determine how the counter is being represented and updated.

This trait can be used to emulate the Cpu contention by increasing the counter more than the required number of T-states.

Required Associated Types§

source

type Limit: Sized + Copy

This type is being used for an arbitrary representation of the limit argument when executing instructions. See Cpu::execute_with_limit for an explanation.

source

type Timestamp: Sized

This type is being used for timestamping the interactions between Cpu, Io and Memory implementations.

The implementations of Clock, Io and Memory should have the same exact type assigned as their Timestamp associated type in order for the Cpu to execute instructions.

Values of this type are returned by some of the methods in this trait.

Required Methods§

source

fn is_past_limit(&self, limit: Self::Limit) -> bool

Should return true if the Clock has reached the given limit otherwise should return false.

source

fn add_irq(&mut self, pc: u16) -> Self::Timestamp

This method should increase the counter by at least IRQ_ACK_CYCLE_TS 6 T-states. The method should return the timestamp that may be passed to Io::irq_data. It’s being used at the beginning of the maskable interrupt request/acknowledge cycle. The pc is a value of the program counter when the interrupt was accepted.

source

fn add_no_mreq(&mut self, address: u16, add_ts: NonZeroU8)

This method should increase the counter by at least the value given in add_ts. It’s being used by internal operations of the Cpu without any external access. The address given here is whatever was put on the address bus before.

source

fn add_m1(&mut self, address: u16) -> Self::Timestamp

This method should increase the counter by at least M1_CYCLE_TS 4 and should return the timestamp that may be passed to Memory::read_opcode. This method is also being used when the non-maskable interrupt is being accepted and while the Cpu is wasting cycles in the halted state.

source

fn add_mreq(&mut self, address: u16) -> Self::Timestamp

This method should increase the counter by at least the value given in MEMRW_CYCLE_TS 3 and should return the timestamp that may be passed to Memory::read_mem,

source

fn add_io(&mut self, port: u16) -> Self::Timestamp

This method should increase the counter by at least IO_CYCLE_TS 4 T-states and should return the timestamp that may be passed to Io::read_io or Io::write_io.

source

fn add_wait_states(&mut self, bus: u16, wait_states: NonZeroU16)

This method should increase the counter by the value given in wait_states. A call to one of Io::read_io, Io::write_io or Io::irq_data may request such additional number of wait states to be added.

source

fn as_timestamp(&self) -> Self::Timestamp

Should return the current state of the Clock as a timestamp.

Implementors§

source§

impl<T> Clock for TsCounter<T>
where T: Copy + PartialEq + PartialOrd + From<u8> + From<u16>, Wrapping<T>: AddAssign + Add<Output = Wrapping<T>>,

§

type Limit = T

§

type Timestamp = T