Trait z80emu::host::Clock

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

    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§

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

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§

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

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.

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.

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.

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,

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.

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.

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

Implementors§