better instructions...
This commit is contained in:
parent
17a140e77c
commit
ce76c32a21
|
@ -6,19 +6,27 @@ use std::ops::{BitAnd, BitOr};
|
|||
|
||||
impl Cpu {
|
||||
pub(crate) fn pop_word(&mut self) -> u16 {
|
||||
let address = self.reg.sp;
|
||||
self.reg.sp = self.reg.sp.wrapping_add(0x2);
|
||||
let mut word: u16 = 0x0;
|
||||
word.set_low(self.memory.get(address));
|
||||
word.set_high(self.memory.get(address.wrapping_add(1)));
|
||||
word.set_low(self.memory.get(self.reg.sp));
|
||||
self.sp_inc();
|
||||
word.set_high(self.memory.get(self.reg.sp));
|
||||
self.sp_inc();
|
||||
word
|
||||
}
|
||||
|
||||
pub(crate) fn push(&mut self, word: u16) {
|
||||
let address = self.reg.sp;
|
||||
self.memory.set(address.wrapping_sub(1), word.get_high());
|
||||
self.memory.set(address.wrapping_sub(2), word.get_low());
|
||||
self.reg.sp = address.wrapping_sub(2);
|
||||
self.sp_dec();
|
||||
self.memory.set(self.reg.sp, word.get_high());
|
||||
self.sp_dec();
|
||||
self.memory.set(self.reg.sp, word.get_low());
|
||||
}
|
||||
|
||||
fn sp_inc(&mut self) {
|
||||
self.reg.sp = self.reg.sp.wrapping_add(1);
|
||||
}
|
||||
|
||||
fn sp_dec(&mut self) {
|
||||
self.reg.sp = self.reg.sp.wrapping_sub(1);
|
||||
}
|
||||
|
||||
pub(crate) fn ld_immediate_byte(&mut self) -> u8 {
|
||||
|
@ -34,11 +42,12 @@ impl Cpu {
|
|||
|
||||
pub(crate) fn rotate_with_carry(&mut self, byte: u8, direction: Direction) -> u8 {
|
||||
let (mut rotated, carry) = rotate(byte, &direction);
|
||||
self.clear_flag(Flags::Carry);
|
||||
if carry {
|
||||
rotated += get_rotation_carry(&direction);
|
||||
self.set_flag(Flags::Carry);
|
||||
}
|
||||
self.set_or_clear_flag(Flags::Zero, rotated == 0x0);
|
||||
self.clear_flag(Flags::Zero);
|
||||
self.clear_flag(Flags::HalfCarry);
|
||||
self.clear_flag(Flags::NSubtract);
|
||||
rotated
|
||||
|
@ -52,8 +61,10 @@ impl Cpu {
|
|||
}
|
||||
if carry {
|
||||
self.set_flag(Flags::Carry);
|
||||
} else {
|
||||
self.clear_flag(Flags::Carry);
|
||||
}
|
||||
self.set_or_clear_flag(Flags::Zero, rotated == 0x0);
|
||||
self.clear_flag(Flags::Zero);
|
||||
self.clear_flag(Flags::HalfCarry);
|
||||
self.clear_flag(Flags::NSubtract);
|
||||
rotated
|
||||
|
|
Loading…
Reference in a new issue