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

70 lines
1.8 KiB
Rust
Raw Normal View History

2023-02-01 17:18:08 +11:00
use crate::processor::{get_bit, Direction, SplitRegister, CPU, FLAGS};
2023-01-31 10:05:36 +11:00
impl CPU {
2023-02-01 17:18:08 +11:00
pub(crate) fn add(&mut self, first: u8, second: u8) -> u8 {
self.add_u8s(first, second)
}
pub(crate) fn adc(&mut self, first: u8, second: u8) -> u8 {
let val = second + self.get_flag(FLAGS::Carry);
self.add_u8s(first, val)
}
pub(crate) fn sub(&mut self, first: u8, second: u8) -> u8 {
self.sub_u8s(first, second)
}
pub(crate) fn sbc(&mut self, first: u8, second: u8) -> u8 {
let val = second + self.get_flag(FLAGS::Carry);
self.sub_u8s(first, val)
}
pub(crate) fn inc(&mut self, val: u8) -> u8 {
self.add_u8s(val, 0x1)
}
pub(crate) fn dec(&mut self, val: u8) -> u8 {
self.sub_u8s(val, 0x1)
}
2023-01-31 10:05:36 +11:00
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)
}
2023-02-01 17:18:08 +11:00
pub(crate) fn rst(&mut self, address: u8) {
self.push(self.reg.pc);
self.reg.pc.set_high(0x0);
self.reg.pc.set_low(address);
2023-01-31 10:05:36 +11:00
}
}