nibbles :3
This commit is contained in:
parent
0f38e89312
commit
e80fd6a73a
29
src/util.rs
29
src/util.rs
|
@ -2,9 +2,7 @@ use crate::processor::Direction;
|
||||||
use std::mem::transmute;
|
use std::mem::transmute;
|
||||||
|
|
||||||
pub(crate) fn as_signed(unsigned: u8) -> i8 {
|
pub(crate) fn as_signed(unsigned: u8) -> i8 {
|
||||||
unsafe {
|
unsafe { transmute(unsigned) }
|
||||||
transmute(unsigned)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_bit(byte: u8, flag: u8) -> bool {
|
pub(crate) fn get_bit(byte: u8, flag: u8) -> bool {
|
||||||
|
@ -50,3 +48,28 @@ pub(crate) fn get_rotation_carry(direction: &Direction) -> u8 {
|
||||||
Direction::Right => 0b10000000,
|
Direction::Right => 0b10000000,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait Nibbles {
|
||||||
|
fn get_low_nibble(&self) -> u8;
|
||||||
|
fn get_high_nibble(&self) -> u8;
|
||||||
|
fn set_low_nibble(&mut self, val: u8);
|
||||||
|
fn set_high_nibble(&mut self, val: u8);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Nibbles for u8 {
|
||||||
|
fn get_low_nibble(&self) -> u8 {
|
||||||
|
*self & 0x0F
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_high_nibble(&self) -> u8 {
|
||||||
|
(*self >> 4) & 0x0F
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_low_nibble(&mut self, val: u8) {
|
||||||
|
*self = (*self & 0xF0) | (val & 0x0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_high_nibble(&mut self, val: u8) {
|
||||||
|
*self = (*self & 0x0F) | (val << 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue