[][src]Trait z80emu::host::Clock

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; }

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.

Associated Types

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.

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.

Loading content...

Required methods

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

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

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.

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.

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.

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,

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.

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.

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

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

Loading content...

Implementors

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

type Limit = T

type Timestamp = T

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

Returns true if self as T >= limit. Otherwise returns false.

fn add_irq(&mut self, _addr: u16) -> T[src]

Returns self after adding INT_IORQ_LOW_TS as T. Updates self by adding IRQ_ACK_CYCLE_TS to the previous value of self.

fn add_no_mreq(&mut self, _addr: u16, add_ts: NonZeroU8)[src]

Updates self by adding add_ts T-states to the previous value of self.

fn add_io(&mut self, _port: u16) -> T[src]

Returns self after adding IO_IORQ_LOW_TS as T. Updates self by adding IO_CYCLE_TS to the previous value of self.

fn add_mreq(&mut self, _addr: u16) -> T[src]

Updates self by adding MEMRW_CYCLE_TS to the previous value of self. Returns self after updating as T.

fn add_m1(&mut self, _addr: u16) -> T[src]

Updates self by adding M1_CYCLE_TS to the previous value of self. Returns self after updating as T.

fn add_wait_states(&mut self, _bus: u16, wait_states: NonZeroU16)[src]

Updates self by adding wait_states T-states to the previous value of self.

fn as_timestamp(&self) -> T[src]

Returns a copy of self as T.

Loading content...