use std::ops::RangeInclusive;
use std::hash::{Hash, Hasher};
use std::fmt::{Debug, Display, Formatter};
use osiris_data::data::identification::Identifier;
pub const REGISTERS_IN_BANK: usize = 65536;
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub struct RegisterId(u16);
impl RegisterId {
pub const fn new(raw: u16) -> Self { Self(raw) }
pub const fn to_u16(&self) -> u16 { self.0 }
}
impl Hash for RegisterId {
fn hash<H: Hasher>(&self, state: &mut H) {
state.write_usize(self.to_usize());
}
}
impl Identifier for RegisterId {
fn to_usize(&self) -> usize { self.0 as usize }
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub struct RegisterRange {
pub start: RegisterId,
pub end: RegisterId,
}
impl RegisterRange {
pub fn new(start: RegisterId, end: RegisterId) -> Self {
if end < start {
panic!("End of a range cannot be lower to its start.")
}
Self { start, end }
}
pub fn from_u32(data: u32) -> Self {
Self {
start: RegisterId((data >> 16) as u16),
end: RegisterId(data as u16),
}
}
pub fn to_usize_range(&self) -> RangeInclusive<usize> { self.start.to_usize()..=self.end.to_usize() }
pub fn to_u32(&self) -> u32 { (self.start.to_u16() as u32) << 16 | self.end.to_u16() as u32 }
#[allow(clippy::len_without_is_empty)]
pub fn len(&self) -> usize { self.end.to_usize() - self.start.to_usize() }
}
impl Display for RegisterRange {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "[{:04x}:{:04x}]", self.start.to_u16(), self.end.to_u16())
}
}
#[derive(Copy, Clone, Debug)]
pub struct CpuConfiguration {
pub frequency: usize,
}
impl CpuConfiguration {
pub const DEFAULT_FREQUENCY: usize = 60;
}
impl Default for CpuConfiguration {
fn default() -> Self {
CpuConfiguration {
frequency: Self::DEFAULT_FREQUENCY,
}
}
}
pub mod integral;
pub mod floating_point;
pub mod state;