mod tests;
use crate::isa::{An, Long, Dn, Sr};
#[derive(Debug)]
pub struct Regs {
data: [Long; 8],
address: [Long; 8],
pc: Long,
sr: Sr,
}
impl Regs {
#[inline]
#[must_use]
pub const fn new() -> Self {
Self {
data: [Default::default(); _],
address: [Default::default(); _],
pc: Default::default(),
sr: Default::default(),
}
}
pub fn print(&self) {
eprintln!();
eprintln!("d0: {} a0: {}", self.dn(Dn::D0), self.an(An::A0));
eprintln!("d1: {} a1: {}", self.dn(Dn::D1), self.an(An::A1));
eprintln!("d2: {} a2: {}", self.dn(Dn::D2), self.an(An::A2));
eprintln!("d3: {} a3: {}", self.dn(Dn::D3), self.an(An::A3));
eprintln!("d4: {} a4: {}", self.dn(Dn::D4), self.an(An::A4));
eprintln!("d5: {} a5: {}", self.dn(Dn::D5), self.an(An::A5));
eprintln!("d6: {} fp: {}", self.dn(Dn::D6), self.an(An::Fp));
eprintln!("d7: {} sp: {}", self.dn(Dn::D7), self.an(An::Sp));
eprintln!("pc: {} sr: {:?}", self.pc(), self.sr());
}
#[inline]
#[must_use]
pub const fn dn(&self, index: Dn) -> Long {
self.data[index.as_usize()]
}
#[inline]
pub const fn dn_mut(&mut self, index: Dn) -> &mut Long {
&mut self.data[index.as_usize()]
}
#[inline]
#[must_use]
pub const fn an(&self, index: An) -> Long {
self.address[index.as_usize()]
}
#[inline]
pub const fn an_mut(&mut self, index: An) -> &mut Long {
&mut self.address[index.as_usize()]
}
#[inline(always)]
#[must_use]
pub const fn pc(&self) -> Long {
self.pc
}
#[inline(always)]
#[must_use]
pub const fn pc_mut(&mut self) -> &mut Long {
&mut self.pc
}
#[inline]
pub const fn inc_pc(&mut self, value: u32) {
let result = self.pc.as_u32().wrapping_add(value);
self.pc = Long::from_u32(result);
}
#[inline(always)]
#[must_use]
pub const fn sr(&self) -> Sr {
self.sr
}
#[inline(always)]
#[must_use]
pub const fn sr_mut(&mut self) -> &mut Sr {
&mut self.sr
}
#[inline]
pub const fn clear(&mut self) {
*self = Self::new();
}
}
const impl Default for Regs {
#[inline(always)]
fn default() -> Self {
const { Self::new() }
}
}