ok alright alright alright alright alright
This commit is contained in:
@@ -1,3 +1,31 @@
|
|||||||
|
pub trait RegisterValue: Sized {
|
||||||
|
fn read_from(raw: i64) -> Self;
|
||||||
|
fn write_to(value: Self) -> i64;
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! impl_register_value {
|
||||||
|
($ty:ty) => {
|
||||||
|
impl RegisterValue for $ty {
|
||||||
|
fn read_from(raw: i64) -> Self {
|
||||||
|
raw as $ty
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_to(value: Self) -> i64 {
|
||||||
|
value as i64
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
impl_register_value!(u8);
|
||||||
|
impl_register_value!(i8);
|
||||||
|
impl_register_value!(u16);
|
||||||
|
impl_register_value!(i16);
|
||||||
|
impl_register_value!(u32);
|
||||||
|
impl_register_value!(i32);
|
||||||
|
impl_register_value!(u64);
|
||||||
|
impl_register_value!(i64);
|
||||||
|
|
||||||
pub struct Registers {
|
pub struct Registers {
|
||||||
delay_slot: bool,
|
delay_slot: bool,
|
||||||
prev_delay_slot: bool,
|
prev_delay_slot: bool,
|
||||||
@@ -37,81 +65,16 @@ impl Registers {
|
|||||||
self.next_pc = self.pc + 4;
|
self.next_pc = self.pc + 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_u8(&self, idx: usize) -> u8 {
|
pub fn read<T: RegisterValue>(&self, idx: usize) -> T {
|
||||||
self.gpr[idx] as u8
|
T::read_from(self.gpr[idx])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_i8(&self, idx: usize) -> i8 {
|
pub fn write<T: RegisterValue>(&mut self, idx: usize, val: T) {
|
||||||
self.gpr[idx] as i8
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn read_u16(&self, idx: usize) -> u16 {
|
|
||||||
self.gpr[idx] as u16
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn read_u32(&self, idx: usize) -> u32 {
|
|
||||||
self.gpr[idx] as u32
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn read_i16(&self, idx: usize) -> i16 {
|
|
||||||
self.gpr[idx] as i16
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn read_i32(&self, idx: usize) -> i32 {
|
|
||||||
self.gpr[idx] as i32
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn write_u8(&mut self, idx: usize, val: u8) {
|
|
||||||
if idx == 0 {
|
if idx == 0 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.constant_regs |= 1 << idx;
|
self.constant_regs |= 1 << idx;
|
||||||
self.gpr[idx] = val as i64;
|
self.gpr[idx] = T::write_to(val);
|
||||||
}
|
|
||||||
|
|
||||||
pub fn write_i8(&mut self, idx: usize, val: i8) {
|
|
||||||
if idx == 0 {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.constant_regs |= 1 << idx;
|
|
||||||
self.gpr[idx] = val as i64;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn write_u16(&mut self, idx: usize, val: u16) {
|
|
||||||
if idx == 0 {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.constant_regs |= 1 << idx;
|
|
||||||
self.gpr[idx] = val as i64;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn write_u32(&mut self, idx: usize, val: u32) {
|
|
||||||
if idx == 0 {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.constant_regs |= 1 << idx;
|
|
||||||
self.gpr[idx] = val as i64;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn write_i16(&mut self, idx: usize, val: i16) {
|
|
||||||
if idx == 0 {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.constant_regs |= 1 << idx;
|
|
||||||
self.gpr[idx] = val as i64;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn write_i32(&mut self, idx: usize, val: i32) {
|
|
||||||
if idx == 0 {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.constant_regs |= 1 << idx;
|
|
||||||
self.gpr[idx] = val as i64;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user