impl 0x80 to 0xBF

This commit is contained in:
Alex Janka 2023-02-01 23:08:51 +11:00
parent d03043bef9
commit f07c6a41a3
2 changed files with 263 additions and 0 deletions

View file

@ -1,6 +1,37 @@
use crate::processor::{get_bit, Direction, Flags, Reg8, SplitRegister, CPU};
impl CPU {
pub(crate) fn and(&mut self, first: u8, second: u8) -> u8 {
let result = first & second;
self.set_or_clear_flag(Flags::Zero, result == 0x0);
self.clear_flag(Flags::NSubtract);
self.clear_flag(Flags::Carry);
self.set_flag(Flags::HalfCarry);
result
}
pub(crate) fn xor(&mut self, first: u8, second: u8) -> u8 {
let result = first ^ second;
self.set_or_clear_flag(Flags::Zero, result == 0x0);
self.clear_flag(Flags::NSubtract);
self.clear_flag(Flags::Carry);
self.clear_flag(Flags::HalfCarry);
result
}
pub(crate) fn or(&mut self, first: u8, second: u8) -> u8 {
let result = first | second;
self.set_or_clear_flag(Flags::Zero, result == 0x0);
self.clear_flag(Flags::NSubtract);
self.clear_flag(Flags::Carry);
self.clear_flag(Flags::HalfCarry);
result
}
pub(crate) fn cp(&mut self, first: u8, second: u8) {
self.sub_u8s(first, second);
}
pub(crate) fn add(&mut self, first: u8, second: u8) -> u8 {
self.add_u8s(first, second)
}

View file

@ -259,6 +259,238 @@ impl CPU {
0x7D => self.reg.set_8(Reg8::A, self.reg.get_8(Reg8::L)),
0x7E => self.reg.set_8(Reg8::A, self.memory.get(self.reg.hl)),
0x7F => self.reg.set_8(Reg8::A, self.reg.get_8(Reg8::A)),
0x80 => {
let val = self.add(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::B));
self.reg.set_8(Reg8::A, val);
}
0x81 => {
let val = self.add(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C));
self.reg.set_8(Reg8::A, val);
}
0x82 => {
let val = self.add(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D));
self.reg.set_8(Reg8::A, val);
}
0x83 => {
let val = self.add(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E));
self.reg.set_8(Reg8::A, val);
}
0x84 => {
let val = self.add(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H));
self.reg.set_8(Reg8::A, val);
}
0x85 => {
let val = self.add(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L));
self.reg.set_8(Reg8::A, val);
}
0x86 => {
let val = self.add(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl));
self.reg.set_8(Reg8::A, val);
}
0x87 => {
let val = self.add(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
}
0x88 => {
let val = self.adc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::B));
self.reg.set_8(Reg8::A, val);
}
0x89 => {
let val = self.adc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C));
self.reg.set_8(Reg8::A, val);
}
0x8A => {
let val = self.adc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D));
self.reg.set_8(Reg8::A, val);
}
0x8B => {
let val = self.adc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E));
self.reg.set_8(Reg8::A, val);
}
0x8C => {
let val = self.adc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H));
self.reg.set_8(Reg8::A, val);
}
0x8D => {
let val = self.adc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L));
self.reg.set_8(Reg8::A, val);
}
0x8E => {
let val = self.adc(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl));
self.reg.set_8(Reg8::A, val);
}
0x8F => {
let val = self.adc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
}
0x90 => {
let val = self.sub(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::B));
self.reg.set_8(Reg8::A, val);
}
0x91 => {
let val = self.sub(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C));
self.reg.set_8(Reg8::A, val);
}
0x92 => {
let val = self.sub(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D));
self.reg.set_8(Reg8::A, val);
}
0x93 => {
let val = self.sub(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E));
self.reg.set_8(Reg8::A, val);
}
0x94 => {
let val = self.sub(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H));
self.reg.set_8(Reg8::A, val);
}
0x95 => {
let val = self.sub(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L));
self.reg.set_8(Reg8::A, val);
}
0x96 => {
let val = self.sub(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl));
self.reg.set_8(Reg8::A, val);
}
0x97 => {
let val = self.sub(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
}
0x98 => {
let val = self.sbc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::B));
self.reg.set_8(Reg8::A, val);
}
0x99 => {
let val = self.sbc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C));
self.reg.set_8(Reg8::A, val);
}
0x9A => {
let val = self.sbc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D));
self.reg.set_8(Reg8::A, val);
}
0x9B => {
let val = self.sbc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E));
self.reg.set_8(Reg8::A, val);
}
0x9C => {
let val = self.sbc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H));
self.reg.set_8(Reg8::A, val);
}
0x9D => {
let val = self.sbc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L));
self.reg.set_8(Reg8::A, val);
}
0x9E => {
let val = self.sbc(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl));
self.reg.set_8(Reg8::A, val);
}
0x9F => {
let val = self.sbc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
}
0xA0 => {
let val = self.and(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::B));
self.reg.set_8(Reg8::A, val);
}
0xA1 => {
let val = self.and(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C));
self.reg.set_8(Reg8::A, val);
}
0xA2 => {
let val = self.and(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D));
self.reg.set_8(Reg8::A, val);
}
0xA3 => {
let val = self.and(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E));
self.reg.set_8(Reg8::A, val);
}
0xA4 => {
let val = self.and(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H));
self.reg.set_8(Reg8::A, val);
}
0xA5 => {
let val = self.and(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L));
self.reg.set_8(Reg8::A, val);
}
0xA6 => {
let val = self.and(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl));
self.reg.set_8(Reg8::A, val);
}
0xA7 => {
let val = self.and(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
}
0xA8 => {
let val = self.xor(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::B));
self.reg.set_8(Reg8::A, val);
}
0xA9 => {
let val = self.xor(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C));
self.reg.set_8(Reg8::A, val);
}
0xAA => {
let val = self.xor(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D));
self.reg.set_8(Reg8::A, val);
}
0xAB => {
let val = self.xor(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E));
self.reg.set_8(Reg8::A, val);
}
0xAC => {
let val = self.xor(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H));
self.reg.set_8(Reg8::A, val);
}
0xAD => {
let val = self.xor(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L));
self.reg.set_8(Reg8::A, val);
}
0xAE => {
let val = self.xor(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl));
self.reg.set_8(Reg8::A, val);
}
0xAF => {
let val = self.xor(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
}
0xB0 => {
let val = self.or(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::B));
self.reg.set_8(Reg8::A, val);
}
0xB1 => {
let val = self.or(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C));
self.reg.set_8(Reg8::A, val);
}
0xB2 => {
let val = self.or(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D));
self.reg.set_8(Reg8::A, val);
}
0xB3 => {
let val = self.or(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E));
self.reg.set_8(Reg8::A, val);
}
0xB4 => {
let val = self.or(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H));
self.reg.set_8(Reg8::A, val);
}
0xB5 => {
let val = self.or(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L));
self.reg.set_8(Reg8::A, val);
}
0xB6 => {
let val = self.or(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl));
self.reg.set_8(Reg8::A, val);
}
0xB7 => {
let val = self.or(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
}
0xB8 => self.cp(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::B)),
0xB9 => self.cp(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C)),
0xBA => self.cp(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D)),
0xBB => self.cp(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E)),
0xBC => self.cp(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H)),
0xBD => self.cp(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L)),
0xBE => self.cp(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl)),
0xBF => self.cp(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A)),
_ => {
undefined(opcode);