use core::{fmt, ops};
use crate::vram::Vram;
#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct VramOffset {
inner: i32,
}
impl VramOffset {
#[must_use]
pub const fn new(value: i32) -> Self {
Self { inner: value }
}
#[must_use]
pub const fn inner(&self) -> i32 {
self.inner
}
#[must_use]
pub const fn add_vram(&self, rhs: &Vram) -> Vram {
rhs.add_offset(self)
}
#[must_use]
pub const fn is_zero(&self) -> bool {
self.inner == 0
}
#[must_use]
pub const fn is_positive(&self) -> bool {
self.inner > 0
}
#[must_use]
pub const fn is_negative(&self) -> bool {
self.inner < 0
}
}
impl ops::Add<Vram> for VramOffset {
type Output = Vram;
fn add(self, rhs: Vram) -> Self::Output {
self.add_vram(&rhs)
}
}
impl ops::Add<&Vram> for VramOffset {
type Output = Vram;
fn add(self, rhs: &Vram) -> Self::Output {
self.add_vram(rhs)
}
}
impl fmt::Debug for VramOffset {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "VramOffset {{ ")?;
let mut inner = self.inner as i64;
if inner < 0 {
inner = -inner;
write!(f, "-")?;
}
write!(f, "0x{:X} }}", inner)
}
}
impl fmt::Display for VramOffset {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:X}", self.inner)
}
}