gb-emu/src/processor/instructions/instructions.rs

44 lines
1.1 KiB
Rust
Raw Normal View History

2023-01-31 10:05:36 +11:00
use crate::processor::{get_bit, Direction, CPU};
impl CPU {
pub(crate) fn rlc(&mut self, byte: u8) -> u8 {
self.rotate_c(byte, Direction::Left)
}
pub(crate) fn rrc(&mut self, byte: u8) -> u8 {
self.rotate_c(byte, Direction::Right)
}
pub(crate) fn rl(&mut self, byte: u8) -> u8 {
self.rotate(byte, Direction::Left)
}
pub(crate) fn rr(&mut self, byte: u8) -> u8 {
self.rotate(byte, Direction::Right)
}
pub(crate) fn sla(&mut self, byte: u8) -> u8 {
self.shift(byte, Direction::Left)
}
pub(crate) fn sra(&mut self, byte: u8) -> u8 {
let b = get_bit(byte, 7);
let val = self.shift(byte, Direction::Right);
if b {
val + 0b10000000
} else {
val
}
}
pub(crate) fn srl(&mut self, byte: u8) -> u8 {
self.shift(byte, Direction::Right)
}
pub(crate) fn rst(&mut self, address: u16) {
self.push(self.state.pc);
self.state.pc.as_u8s.left = 0x0;
self.state.pc.as_u8s.right = self.memory.get(address);
}
}