lemurs_8080/chip/
mod.rs

1use crate::prelude::*;
2
3pub mod access;
4mod execution;
5pub use execution::opcode;
6
7/// This struct stores the internal registers and flags of the 8080 CPU.
8#[repr(C)]
9#[cfg_attr(feature="open", disclose)]
10pub struct State {
11	pc: u16,
12	sp: u16,
13	register: [u8;7],
14	c: bool, a: bool, p: bool, m: bool, z: bool,
15	active: bool, interrupts: bool,
16}
17
18impl State {
19	/// Creates a fresh state with the processor in an active state and all registers reset.
20	pub fn new() -> Self {
21		Self {
22			register: [Wrapping(0);7],
23			c: false, a: false, p: false, m: false, z: false,
24			active: true, interrupts: false,
25			pc: Wrapping(0), sp: Wrapping(0),
26		}
27	}
28}
29
30#[cfg(feature="open")]
31impl<H: Harness + ?Sized, C: BorrowMut<H>> Iterator for Machine<H, C> {
32	type Item = Result<raw::u8, String>;
33	fn next(&mut self) -> Option<Self::Item> {
34		let result = self.execute();
35		match result {
36			Ok(Some(cycles)) => Some(Ok(cycles.get())),
37			Ok(None) => None,
38			Err(e) => Some(Err(e)),
39		}
40	}
41}
42
43#[cfg(not(feature="open"))]
44impl<H: Harness + ?Sized, C: BorrowMut<H>> Iterator for Machine<H, C> {
45	type Item = core::primitive::u8;
46	fn next(&mut self) -> Option<Self::Item> {
47		use core::num::NonZeroU8;
48		self.execute().map(NonZeroU8::get)
49	}
50}
51