Struct z80emu::z80::Z80

source ·
pub struct Z80<Q: Flavour> {
    pub flavour: Q,
    /* private fields */
}
Expand description

Emulates a Zilog’s Z80 CPU in various “flavours” via the Cpu trait.

Fields§

§flavour: Q

Exposes an instance of the Flavour implementation.

Implementations§

source§

impl<Q: Flavour> Z80<Q>

source

pub fn new() -> Self

Creates a new instance of Z80 with the state just after RESET.

source

pub fn get_memptr(&self) -> u16

Retrieves the internal state of the MEMPTR register.

source

pub fn set_memptr(&mut self, memptr: u16)

Changes the internal state of the MEMPTR register.

source

pub fn normalize_r(&mut self)

The content of the R register is lazy evaluated when its value is being set or retrieved. This method normalizes the internal state of the R register, so e.g. two instances of Z80 can be compared if they represent the same CPU state.

source

pub fn into_flavour<F>(self) -> Z80<F>
where F: From<Q> + Flavour,

Converts between instances of Z80 with different flavours.

NOTE: Some Flavour related information may be lost during conversion.

source

pub fn from_flavour<F: Flavour>(cpu: Z80<F>) -> Self
where Q: From<F>,

Converts between instances of Z80 with different flavours.

NOTE: Some Flavour related information may be lost during conversion.

Trait Implementations§

source§

impl<Q: Clone + Flavour> Clone for Z80<Q>

source§

fn clone(&self) -> Z80<Q>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Q: Flavour> Cpu for Z80<Q>

source§

fn reset(&mut self)

Instantly resets the Cpu to its initial state.
source§

fn get_pc(&self) -> u16

Returns the current value of the program counter.
source§

fn set_pc(&mut self, pc: u16)

Sets the current value of the program counter.
source§

fn get_sp(&self) -> u16

Returns the current value of the stack pointer.
source§

fn set_sp(&mut self, sp: u16)

Sets the current value of the stack pointer.
source§

fn get_acc(&self) -> u8

Returns the Accumulator value as an unsigned 8-bit integer.
source§

fn set_acc(&mut self, val: u8)

Sets the Accumulator value from an unsigned 8-bit integer.
source§

fn get_flags(&self) -> CpuFlags

Returns the current state of the Flags register.
source§

fn set_flags(&mut self, flags: CpuFlags)

Sets the current state of the Flags register.
source§

fn inc_r(&mut self)

Increases the memory refresh counter.
source§

fn add_r(&mut self, delta: i32)

Adds the arbitrary value to the memory refresh counter. This can be used to emulate the Cpu in the HALT state without executing the busy loop.
source§

fn get_r(&self) -> u8

Returns the current value of the memory refresh register R.
source§

fn set_r(&mut self, r: u8)

Sets the memory refresh register R value.
source§

fn get_i(&self) -> u8

Returns the current value of the interrupt page I register.
source§

fn set_i(&mut self, i: u8)

Sets the current value of the interrupt page I register.
source§

fn get_ir(&self) -> u16

Returns the current memory refresh address.
source§

fn get_iffs(&self) -> (bool, bool)

Returns values of interrupt flip-flops (iff1, iff2).
source§

fn set_iffs(&mut self, iff1: bool, iff2: bool)

Sets the values of interrupt flip-flops.
source§

fn halt(&mut self)

Forces Cpu to enter the HALT state. This doesn’t involve Clock and happens instantly. This also can be done by executing HALT instruction with Cpu::execute_instruction.
source§

fn is_halt(&self) -> bool

Returns true if the Cpu is in the HALT state.
source§

fn get_im(&self) -> InterruptMode

Returns the current interrupt mode.
source§

fn set_im(&mut self, im: InterruptMode)

Sets the interrupt mode.
source§

fn ex_af_af(&mut self)

Swaps the AF register with its alternative counterpart AF'.
source§

fn exx(&mut self)

Swaps the BC, DE and HL registers with their alternative counterparts BC', DE' and HL'.
source§

fn get_reg(&self, reg: Reg8, prefix: Option<Prefix>) -> u8

Returns the content of the selected 8-bit register. Read more
source§

fn set_reg(&mut self, dst: Reg8, prefix: Option<Prefix>, val: u8)

Sets the content of the selected 8-bit register. Read more
source§

fn get_reg2(&self, src: StkReg16) -> (u8, u8)

Returns the content of the selected pair of registers as a tuple of 8-bit unsigned integers. Read more
source§

fn get_alt_reg2(&self, src: StkReg16) -> (u8, u8)

Returns the content of the selected pair of alternative registers as a tuple of 8-bit unsigned integers. Read more
source§

fn get_reg16(&self, src: StkReg16) -> u16

Returns the content of the selected pair of registers as an unsigned 16-bit integer.
source§

fn get_alt_reg16(&self, src: StkReg16) -> u16

Returns the content of the selected pair of alternative registers as an unsigned 16-bit integer.
source§

fn set_reg2(&mut self, src: StkReg16, hi: u8, lo: u8)

Sets the content of the selected pair of registers. Read more
source§

fn set_reg16(&mut self, src: StkReg16, val: u16)

Sets the content of the selected pair of registers as an unsigned 16-bit integer.
source§

fn get_index2(&self, prefix: Prefix) -> (u8, u8)

Returns the content of one of the index registers as a tuple of 8-bit unsigned integers. Read more
source§

fn get_index16(&self, prefix: Prefix) -> u16

Returns the content of one of the index registers as a 16-bit unsigned integer. Read more
source§

fn set_index2(&mut self, prefix: Prefix, hi: u8, lo: u8)

Sets the content of one of the index registers. Read more
source§

fn set_index16(&mut self, prefix: Prefix, val: u16)

Sets the content of one of the index registers as a 16-bit unsigned integer. Read more
source§

fn is_irq_allowed(&self) -> bool

Returns true if the Cpu will accept the interrupt request before executing the next opcode.
source§

fn is_nmi_allowed(&self) -> bool

Returns true if the Cpu will accept the non-maskable interrupt before executing the next opcode.
source§

fn restore_iff1(&mut self)

Restores the content of the interrupt flip-flop 1 from the content of the interrupt flip-flop 2. This is what RETN instruction usually does.
source§

fn disable_interrupts(&mut self)

Disables the maskable interrupts by resetting both interrupt flip-flops to Off. Read more
source§

fn enable_interrupts(&mut self)

Enabes the maskable interrupts by setting both interrupt flip-flops to On. Read more
source§

fn is_after_ei(&self) -> bool

Returns true if the last command executed was EI.
source§

fn is_after_prefix(&self) -> bool

Returns true if the last command executed was a 0xDD or a 0xFD prefix. Read more
source§

fn get_prefix(&self) -> Option<Prefix>

Returns the prefix value after executing the last command. Read more
source§

fn irq<M, T, F>( &mut self, control: &mut M, tsc: &mut T, debug: Option<F> ) -> Option<Result<M::WrIoBreak, M::RetiBreak>>
where M: Memory<Timestamp = T::Timestamp> + Io<Timestamp = T::Timestamp>, T: Clock, F: FnOnce(CpuDebug),

Requests a maskable interrupt. Read more
source§

fn nmi<M, T>(&mut self, control: &mut M, tsc: &mut T) -> bool
where M: Memory<Timestamp = T::Timestamp> + Io<Timestamp = T::Timestamp>, T: Clock,

Attempts to trigger a non-maskable interrupt. Read more
source§

fn execute_instruction<M, T, F>( &mut self, control: &mut M, tsc: &mut T, debug: Option<F>, code: u8 ) -> Result<M::WrIoBreak, M::RetiBreak>
where M: Memory<Timestamp = T::Timestamp> + Io<Timestamp = T::Timestamp>, T: Clock, F: FnOnce(CpuDebug),

Executes a single instruction given as code. If the instruction is a first byte of the multi-byte instruction the rest of the instruction body will be fetched via calls to Memory::read_opcode. Read more
source§

fn execute_next<M, T, F>( &mut self, control: &mut M, tsc: &mut T, debug: Option<F> ) -> Result<M::WrIoBreak, M::RetiBreak>
where M: Memory<Timestamp = T::Timestamp> + Io<Timestamp = T::Timestamp>, T: Clock, F: FnOnce(CpuDebug),

Executes the next instruction present in the Memory at the program counter fetched via Memory::read_opcode. Read more
source§

fn execute_with_limit<M, T>( &mut self, control: &mut M, tsc: &mut T, vc_limit: T::Limit ) -> Result<M::WrIoBreak, M::RetiBreak>
where M: Memory<Timestamp = T::Timestamp> + Io<Timestamp = T::Timestamp>, T: Clock,

Executes instructions until Clock reaches the given limit or when other conditions are met. Read more
source§

impl<Q: Flavour> Debug for Z80<Q>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<Q: Default + Flavour> Default for Z80<Q>

source§

fn default() -> Z80<Q>

Returns the “default value” for a type. Read more
source§

impl<'de, Q> Deserialize<'de> for Z80<Q>
where Q: Flavour + Deserialize<'de>,

source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
source§

impl<Q: Flavour> From<Z80<Q>> for Z80Any

source§

fn from(cpu: Z80<Q>) -> Z80Any

Converts to this type from the input type.
source§

impl<Q> From<Z80Any> for Z80<Q>
where Q: Flavour + From<NMOS> + From<CMOS> + From<BM1>,

source§

fn from(cpu_any: Z80Any) -> Z80<Q>

Converts to this type from the input type.
source§

impl<Q: PartialEq + Flavour> PartialEq for Z80<Q>

source§

fn eq(&self, other: &Z80<Q>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<Q: Flavour + Serialize> Serialize for Z80<Q>

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<Q: Eq + Flavour> Eq for Z80<Q>

source§

impl<Q: Flavour> StructuralPartialEq for Z80<Q>

Auto Trait Implementations§

§

impl<Q> RefUnwindSafe for Z80<Q>
where Q: RefUnwindSafe,

§

impl<Q> Send for Z80<Q>
where Q: Send,

§

impl<Q> Sync for Z80<Q>
where Q: Sync,

§

impl<Q> Unpin for Z80<Q>
where Q: Unpin,

§

impl<Q> UnwindSafe for Z80<Q>
where Q: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,