diff --git a/src/processor/instructions/instructions.rs b/src/processor/instructions/instructions.rs index aefc45e..2872d1a 100644 --- a/src/processor/instructions/instructions.rs +++ b/src/processor/instructions/instructions.rs @@ -37,7 +37,7 @@ impl CPU { } pub(crate) fn adc(&mut self, first: u8, second: u8) -> u8 { - let val = second + self.get_flag(Flags::Carry); + let val = second.wrapping_add(self.get_flag(Flags::Carry)); self.add_u8s(first, val) } @@ -46,7 +46,7 @@ impl CPU { } pub(crate) fn sbc(&mut self, first: u8, second: u8) -> u8 { - let val = second + self.get_flag(Flags::Carry); + let val = second.wrapping_add(self.get_flag(Flags::Carry)); self.sub_u8s(first, val) } @@ -104,6 +104,21 @@ impl CPU { self.shift(byte, Direction::Right) } + pub(crate) fn swap(&mut self, byte: u8) -> u8 { + let swapped = (byte & 0x0F) << 4 | (byte & 0xF0) >> 4; + self.set_or_clear_flag(Flags::Zero, swapped == 0x0); + self.clear_flag(Flags::Carry); + self.clear_flag(Flags::HalfCarry); + self.clear_flag(Flags::NSubtract); + swapped + } + + pub(crate) fn bit(&mut self, byte: u8, bit: u8) { + self.set_or_clear_flag(Flags::Zero, !get_bit(byte, bit)); + self.clear_flag(Flags::NSubtract); + self.set_flag(Flags::HalfCarry); + } + pub(crate) fn rst(&mut self, address: u8) { self.push(self.reg.pc); self.reg.pc.set_high(0x0); @@ -118,3 +133,11 @@ impl CPU { self.reg.pc = self.reg.pc.wrapping_add_signed(jump.into()); } } + +pub(crate) fn res(byte: u8, bit: u8) -> u8 { + byte & !(1 << bit) +} + +pub(crate) fn set(byte: u8, bit: u8) -> u8 { + byte | (1 << bit) +} diff --git a/src/processor/instructions/primitives.rs b/src/processor/instructions/primitives.rs index 9582333..9b52f4c 100644 --- a/src/processor/instructions/primitives.rs +++ b/src/processor/instructions/primitives.rs @@ -1,4 +1,4 @@ -use std::ops::{BitAnd, BitOr, BitXor}; +use std::ops::{BitAnd, BitOr}; use crate::{ processor::{get_bit, get_rotation_carry, rotate, Direction, Flags, SplitRegister, CPU}, @@ -15,11 +15,6 @@ impl CPU { word } - // pub(crate) fn store_word(&mut self, address: u16, word: u16) { - // self.memory.set(address, word.get_high()); - // self.memory.set(address + 1, word.get_low()); - // } - pub(crate) fn push(&mut self, word: u16) { let address = self.reg.sp; self.memory.set(address.wrapping_sub(1), word.get_high()); @@ -70,13 +65,12 @@ impl CPU { if carry { self.set_flag(Flags::Carry); } + self.set_or_clear_flag(Flags::Zero, rotated == 0x0); + self.clear_flag(Flags::HalfCarry); + self.clear_flag(Flags::NSubtract); return rotated; } - pub(crate) fn bit(&mut self, byte: u8, bit: u8) { - self.set_or_clear_flag(Flags::Zero, !get_bit(byte, bit)); - } - pub(crate) fn get_flag(&mut self, flag: Flags) -> u8 { if get_bit(self.reg.af.get_low(), flag as u8) { 0x1 diff --git a/src/processor/mod.rs b/src/processor/mod.rs index 9464812..dba43b0 100644 --- a/src/processor/mod.rs +++ b/src/processor/mod.rs @@ -53,6 +53,7 @@ impl CPU { } } +#[allow(dead_code)] #[derive(Clone, Copy)] pub enum Reg8 { A, @@ -175,15 +176,3 @@ fn get_rotation_carry(direction: &Direction) -> u8 { Direction::Right => 0b10000000, } } - -fn swap_nibbles(byte: u8) -> u8 { - (byte & 0x0F) << 4 | (byte & 0xF0) >> 4 -} - -fn res(byte: u8, bit: u8) -> u8 { - byte & !(1 << bit) -} - -fn set(byte: u8, bit: u8) -> u8 { - byte | (1 << bit) -} diff --git a/src/processor/opcodes.rs b/src/processor/opcodes.rs index 58ea47b..99bd2fb 100644 --- a/src/processor/opcodes.rs +++ b/src/processor/opcodes.rs @@ -1,4 +1,8 @@ -use super::{as_signed, res, set, swap_nibbles, Flags, Reg8, SplitRegister, CPU}; +use super::{ + as_signed, + instructions::instructions::{res, set}, + Flags, Reg8, SplitRegister, CPU, +}; impl CPU { #[allow(dead_code)] @@ -530,7 +534,10 @@ impl CPU { self.reg.pc = jump; } } - 0xCB => panic!("haven't implemented 0xCB opcodes yet!!"), + 0xCB => { + let subop = self.ld_immediate_byte(); + self.cb_subop(subop); + } 0xCC => { let pc = self.ld_immediate_word(); if self.is_flag(Flags::Zero) { @@ -687,360 +694,842 @@ impl CPU { } } - // fn cb_subop(&mut self, subop: u8) { - // match subop { - // 0x00 => unsafe { self.state.bc.as_u8s.left = self.rlc(self.state.bc.as_u8s.left) }, - // 0x01 => unsafe { self.state.bc.as_u8s.right = self.rlc(self.state.bc.as_u8s.right) }, - // 0x02 => unsafe { self.state.de.as_u8s.left = self.rlc(self.state.de.as_u8s.left) }, - // 0x03 => unsafe { self.state.de.as_u8s.right = self.rlc(self.state.de.as_u8s.right) }, - // 0x04 => unsafe { self.state.hl.as_u8s.left = self.rlc(self.state.hl.as_u8s.left) }, - // 0x05 => unsafe { self.state.hl.as_u8s.right = self.rlc(self.state.hl.as_u8s.right) }, - // 0x06 => unsafe { - // let rotated = self.rlc(self.memory.get(self.state.hl.as_u16)); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0x07 => unsafe { self.state.af.as_u8s.left = self.rlc(self.state.af.as_u8s.left) }, - // 0x08 => unsafe { self.state.bc.as_u8s.left = self.rrc(self.state.bc.as_u8s.left) }, - // 0x09 => unsafe { self.state.bc.as_u8s.right = self.rrc(self.state.bc.as_u8s.right) }, - // 0x0A => unsafe { self.state.de.as_u8s.left = self.rrc(self.state.de.as_u8s.left) }, - // 0x0B => unsafe { self.state.de.as_u8s.right = self.rrc(self.state.de.as_u8s.right) }, - // 0x0C => unsafe { self.state.hl.as_u8s.left = self.rrc(self.state.hl.as_u8s.left) }, - // 0x0D => unsafe { self.state.hl.as_u8s.right = self.rrc(self.state.hl.as_u8s.right) }, - // 0x0E => unsafe { - // let rotated = self.rrc(self.memory.get(self.state.hl.as_u16)); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0x0F => unsafe { self.state.af.as_u8s.left = self.rrc(self.state.af.as_u8s.left) }, - // 0x10 => unsafe { self.state.bc.as_u8s.left = self.rl(self.state.bc.as_u8s.left) }, - // 0x11 => unsafe { self.state.bc.as_u8s.right = self.rl(self.state.bc.as_u8s.right) }, - // 0x12 => unsafe { self.state.de.as_u8s.left = self.rl(self.state.de.as_u8s.left) }, - // 0x13 => unsafe { self.state.de.as_u8s.right = self.rl(self.state.de.as_u8s.right) }, - // 0x14 => unsafe { self.state.hl.as_u8s.left = self.rl(self.state.hl.as_u8s.left) }, - // 0x15 => unsafe { self.state.hl.as_u8s.right = self.rl(self.state.hl.as_u8s.right) }, - // 0x16 => unsafe { - // let rotated = self.rl(self.memory.get(self.state.hl.as_u16)); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0x17 => unsafe { self.state.af.as_u8s.left = self.rl(self.state.af.as_u8s.left) }, - // 0x18 => unsafe { self.state.bc.as_u8s.left = self.rr(self.state.bc.as_u8s.left) }, - // 0x19 => unsafe { self.state.bc.as_u8s.right = self.rr(self.state.bc.as_u8s.right) }, - // 0x1A => unsafe { self.state.de.as_u8s.left = self.rr(self.state.de.as_u8s.left) }, - // 0x1B => unsafe { self.state.de.as_u8s.right = self.rr(self.state.de.as_u8s.right) }, - // 0x1C => unsafe { self.state.hl.as_u8s.left = self.rr(self.state.hl.as_u8s.left) }, - // 0x1D => unsafe { self.state.hl.as_u8s.right = self.rr(self.state.hl.as_u8s.right) }, - // 0x1E => unsafe { - // let rotated = self.rr(self.memory.get(self.state.hl.as_u16)); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0x1F => unsafe { self.state.af.as_u8s.left = self.rr(self.state.af.as_u8s.left) }, - // 0x20 => unsafe { self.state.bc.as_u8s.left = self.sla(self.state.bc.as_u8s.left) }, - // 0x21 => unsafe { self.state.bc.as_u8s.right = self.sla(self.state.bc.as_u8s.right) }, - // 0x22 => unsafe { self.state.de.as_u8s.left = self.sla(self.state.de.as_u8s.left) }, - // 0x23 => unsafe { self.state.de.as_u8s.right = self.sla(self.state.de.as_u8s.right) }, - // 0x24 => unsafe { self.state.hl.as_u8s.left = self.sla(self.state.hl.as_u8s.left) }, - // 0x25 => unsafe { self.state.hl.as_u8s.right = self.sla(self.state.hl.as_u8s.right) }, - // 0x26 => unsafe { - // let rotated = self.sla(self.memory.get(self.state.hl.as_u16)); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0x27 => unsafe { self.state.af.as_u8s.left = self.sla(self.state.af.as_u8s.left) }, - // 0x28 => unsafe { self.state.bc.as_u8s.left = self.sra(self.state.bc.as_u8s.left) }, - // 0x29 => unsafe { self.state.bc.as_u8s.right = self.sra(self.state.bc.as_u8s.right) }, - // 0x2A => unsafe { self.state.de.as_u8s.left = self.sra(self.state.de.as_u8s.left) }, - // 0x2B => unsafe { self.state.de.as_u8s.right = self.sra(self.state.de.as_u8s.right) }, - // 0x2C => unsafe { self.state.hl.as_u8s.left = self.sra(self.state.hl.as_u8s.left) }, - // 0x2D => unsafe { self.state.hl.as_u8s.right = self.sra(self.state.hl.as_u8s.right) }, - // 0x2E => unsafe { - // let rotated = self.sra(self.memory.get(self.state.hl.as_u16)); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0x2F => unsafe { self.state.af.as_u8s.left = self.sra(self.state.af.as_u8s.left) }, - // 0x30 => unsafe { self.state.bc.as_u8s.left = swap_nibbles(self.state.bc.as_u8s.left) }, - // 0x31 => unsafe { - // self.state.bc.as_u8s.right = swap_nibbles(self.state.bc.as_u8s.right) - // }, - // 0x32 => unsafe { self.state.de.as_u8s.left = swap_nibbles(self.state.de.as_u8s.left) }, - // 0x33 => unsafe { - // self.state.de.as_u8s.right = swap_nibbles(self.state.de.as_u8s.right) - // }, - // 0x34 => unsafe { self.state.hl.as_u8s.left = swap_nibbles(self.state.hl.as_u8s.left) }, - // 0x35 => unsafe { - // self.state.hl.as_u8s.right = swap_nibbles(self.state.hl.as_u8s.right) - // }, - // 0x36 => unsafe { - // let rotated = swap_nibbles(self.memory.get(self.state.hl.as_u16)); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0x37 => unsafe { self.state.af.as_u8s.left = swap_nibbles(self.state.af.as_u8s.left) }, - // 0x38 => unsafe { self.state.bc.as_u8s.left = self.srl(self.state.bc.as_u8s.left) }, - // 0x39 => unsafe { self.state.bc.as_u8s.right = self.srl(self.state.bc.as_u8s.right) }, - // 0x3A => unsafe { self.state.de.as_u8s.left = self.srl(self.state.de.as_u8s.left) }, - // 0x3B => unsafe { self.state.de.as_u8s.right = self.srl(self.state.de.as_u8s.right) }, - // 0x3C => unsafe { self.state.hl.as_u8s.left = self.srl(self.state.hl.as_u8s.left) }, - // 0x3D => unsafe { self.state.hl.as_u8s.right = self.srl(self.state.hl.as_u8s.right) }, - // 0x3E => unsafe { - // let rotated = self.srl(self.memory.get(self.state.hl.as_u16)); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0x3F => unsafe { self.state.af.as_u8s.left = self.srl(self.state.af.as_u8s.left) }, - // 0x40 => unsafe { self.bit(self.state.bc.as_u8s.left, 0) }, - // 0x41 => unsafe { self.bit(self.state.bc.as_u8s.right, 0) }, - // 0x42 => unsafe { self.bit(self.state.de.as_u8s.left, 0) }, - // 0x43 => unsafe { self.bit(self.state.de.as_u8s.right, 0) }, - // 0x44 => unsafe { self.bit(self.state.hl.as_u8s.left, 0) }, - // 0x45 => unsafe { self.bit(self.state.hl.as_u8s.right, 0) }, - // 0x46 => unsafe { - // self.bit(self.memory.get(self.state.hl.as_u16), 0); - // }, - // 0x47 => unsafe { self.bit(self.state.af.as_u8s.left, 1) }, - // 0x48 => unsafe { self.bit(self.state.bc.as_u8s.left, 1) }, - // 0x49 => unsafe { self.bit(self.state.bc.as_u8s.right, 1) }, - // 0x4A => unsafe { self.bit(self.state.de.as_u8s.left, 1) }, - // 0x4B => unsafe { self.bit(self.state.de.as_u8s.right, 1) }, - // 0x4C => unsafe { self.bit(self.state.hl.as_u8s.left, 1) }, - // 0x4D => unsafe { self.bit(self.state.hl.as_u8s.right, 1) }, - // 0x4E => unsafe { - // self.bit(self.memory.get(self.state.hl.as_u16), 1); - // }, - // 0x4F => unsafe { self.bit(self.state.af.as_u8s.left, 1) }, - // 0x50 => unsafe { self.bit(self.state.bc.as_u8s.left, 2) }, - // 0x51 => unsafe { self.bit(self.state.bc.as_u8s.right, 2) }, - // 0x52 => unsafe { self.bit(self.state.de.as_u8s.left, 2) }, - // 0x53 => unsafe { self.bit(self.state.de.as_u8s.right, 2) }, - // 0x54 => unsafe { self.bit(self.state.hl.as_u8s.left, 2) }, - // 0x55 => unsafe { self.bit(self.state.hl.as_u8s.right, 2) }, - // 0x56 => unsafe { - // self.bit(self.memory.get(self.state.hl.as_u16), 2); - // }, - // 0x57 => unsafe { self.bit(self.state.af.as_u8s.left, 3) }, - // 0x58 => unsafe { self.bit(self.state.bc.as_u8s.left, 3) }, - // 0x59 => unsafe { self.bit(self.state.bc.as_u8s.right, 3) }, - // 0x5A => unsafe { self.bit(self.state.de.as_u8s.left, 3) }, - // 0x5B => unsafe { self.bit(self.state.de.as_u8s.right, 3) }, - // 0x5C => unsafe { self.bit(self.state.hl.as_u8s.left, 3) }, - // 0x5D => unsafe { self.bit(self.state.hl.as_u8s.right, 3) }, - // 0x5E => unsafe { - // self.bit(self.memory.get(self.state.hl.as_u16), 3); - // }, - // 0x5F => unsafe { self.bit(self.state.af.as_u8s.left, 3) }, - // 0x60 => unsafe { self.bit(self.state.bc.as_u8s.left, 4) }, - // 0x61 => unsafe { self.bit(self.state.bc.as_u8s.right, 4) }, - // 0x62 => unsafe { self.bit(self.state.de.as_u8s.left, 4) }, - // 0x63 => unsafe { self.bit(self.state.de.as_u8s.right, 4) }, - // 0x64 => unsafe { self.bit(self.state.hl.as_u8s.left, 4) }, - // 0x65 => unsafe { self.bit(self.state.hl.as_u8s.right, 4) }, - // 0x66 => unsafe { - // self.bit(self.memory.get(self.state.hl.as_u16), 4); - // }, - // 0x67 => unsafe { self.bit(self.state.af.as_u8s.left, 5) }, - // 0x68 => unsafe { self.bit(self.state.bc.as_u8s.left, 5) }, - // 0x69 => unsafe { self.bit(self.state.bc.as_u8s.right, 5) }, - // 0x6A => unsafe { self.bit(self.state.de.as_u8s.left, 5) }, - // 0x6B => unsafe { self.bit(self.state.de.as_u8s.right, 5) }, - // 0x6C => unsafe { self.bit(self.state.hl.as_u8s.left, 5) }, - // 0x6D => unsafe { self.bit(self.state.hl.as_u8s.right, 5) }, - // 0x6E => unsafe { - // self.bit(self.memory.get(self.state.hl.as_u16), 5); - // }, - // 0x6F => unsafe { self.bit(self.state.af.as_u8s.left, 5) }, - // 0x70 => unsafe { self.bit(self.state.bc.as_u8s.left, 6) }, - // 0x71 => unsafe { self.bit(self.state.bc.as_u8s.right, 6) }, - // 0x72 => unsafe { self.bit(self.state.de.as_u8s.left, 6) }, - // 0x73 => unsafe { self.bit(self.state.de.as_u8s.right, 6) }, - // 0x74 => unsafe { self.bit(self.state.hl.as_u8s.left, 6) }, - // 0x75 => unsafe { self.bit(self.state.hl.as_u8s.right, 6) }, - // 0x76 => unsafe { - // self.bit(self.memory.get(self.state.hl.as_u16), 6); - // }, - // 0x77 => unsafe { self.bit(self.state.af.as_u8s.left, 7) }, - // 0x78 => unsafe { self.bit(self.state.bc.as_u8s.left, 7) }, - // 0x79 => unsafe { self.bit(self.state.bc.as_u8s.right, 7) }, - // 0x7A => unsafe { self.bit(self.state.de.as_u8s.left, 7) }, - // 0x7B => unsafe { self.bit(self.state.de.as_u8s.right, 7) }, - // 0x7C => unsafe { self.bit(self.state.hl.as_u8s.left, 7) }, - // 0x7D => unsafe { self.bit(self.state.hl.as_u8s.right, 7) }, - // 0x7E => unsafe { - // self.bit(self.memory.get(self.state.hl.as_u16), 7); - // }, - // 0x7F => unsafe { self.bit(self.state.af.as_u8s.left, 7) }, - // 0x80 => unsafe { self.state.bc.as_u8s.left = res(self.state.bc.as_u8s.left, 0) }, - // 0x81 => unsafe { self.state.bc.as_u8s.right = res(self.state.bc.as_u8s.right, 0) }, - // 0x82 => unsafe { self.state.de.as_u8s.left = res(self.state.de.as_u8s.left, 0) }, - // 0x83 => unsafe { self.state.de.as_u8s.right = res(self.state.de.as_u8s.right, 0) }, - // 0x84 => unsafe { self.state.hl.as_u8s.left = res(self.state.hl.as_u8s.left, 0) }, - // 0x85 => unsafe { self.state.hl.as_u8s.right = res(self.state.hl.as_u8s.right, 0) }, - // 0x86 => unsafe { - // let rotated = res(self.memory.get(self.state.hl.as_u16), 0); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0x87 => unsafe { self.state.af.as_u8s.left = res(self.state.af.as_u8s.left, 0) }, - // 0x88 => unsafe { self.state.bc.as_u8s.left = res(self.state.bc.as_u8s.left, 1) }, - // 0x89 => unsafe { self.state.bc.as_u8s.right = res(self.state.bc.as_u8s.right, 1) }, - // 0x8A => unsafe { self.state.de.as_u8s.left = res(self.state.de.as_u8s.left, 1) }, - // 0x8B => unsafe { self.state.de.as_u8s.right = res(self.state.de.as_u8s.right, 1) }, - // 0x8C => unsafe { self.state.hl.as_u8s.left = res(self.state.hl.as_u8s.left, 1) }, - // 0x8D => unsafe { self.state.hl.as_u8s.right = res(self.state.hl.as_u8s.right, 1) }, - // 0x8E => unsafe { - // let rotated = res(self.memory.get(self.state.hl.as_u16), 1); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0x8F => unsafe { self.state.af.as_u8s.left = res(self.state.af.as_u8s.left, 1) }, - // 0x90 => unsafe { self.state.bc.as_u8s.left = res(self.state.bc.as_u8s.left, 2) }, - // 0x91 => unsafe { self.state.bc.as_u8s.right = res(self.state.bc.as_u8s.right, 2) }, - // 0x92 => unsafe { self.state.de.as_u8s.left = res(self.state.de.as_u8s.left, 2) }, - // 0x93 => unsafe { self.state.de.as_u8s.right = res(self.state.de.as_u8s.right, 2) }, - // 0x94 => unsafe { self.state.hl.as_u8s.left = res(self.state.hl.as_u8s.left, 2) }, - // 0x95 => unsafe { self.state.hl.as_u8s.right = res(self.state.hl.as_u8s.right, 2) }, - // 0x96 => unsafe { - // let rotated = res(self.memory.get(self.state.hl.as_u16), 2); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0x97 => unsafe { self.state.af.as_u8s.left = res(self.state.af.as_u8s.left, 2) }, - // 0x98 => unsafe { self.state.bc.as_u8s.left = res(self.state.bc.as_u8s.left, 3) }, - // 0x99 => unsafe { self.state.bc.as_u8s.right = res(self.state.bc.as_u8s.right, 3) }, - // 0x9A => unsafe { self.state.de.as_u8s.left = res(self.state.de.as_u8s.left, 3) }, - // 0x9B => unsafe { self.state.de.as_u8s.right = res(self.state.de.as_u8s.right, 3) }, - // 0x9C => unsafe { self.state.hl.as_u8s.left = res(self.state.hl.as_u8s.left, 3) }, - // 0x9D => unsafe { self.state.hl.as_u8s.right = res(self.state.hl.as_u8s.right, 3) }, - // 0x9E => unsafe { - // let rotated = res(self.memory.get(self.state.hl.as_u16), 3); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0x9F => unsafe { self.state.af.as_u8s.left = res(self.state.af.as_u8s.left, 3) }, - // 0xA0 => unsafe { self.state.bc.as_u8s.left = res(self.state.bc.as_u8s.left, 4) }, - // 0xA1 => unsafe { self.state.bc.as_u8s.right = res(self.state.bc.as_u8s.right, 4) }, - // 0xA2 => unsafe { self.state.de.as_u8s.left = res(self.state.de.as_u8s.left, 4) }, - // 0xA3 => unsafe { self.state.de.as_u8s.right = res(self.state.de.as_u8s.right, 4) }, - // 0xA4 => unsafe { self.state.hl.as_u8s.left = res(self.state.hl.as_u8s.left, 4) }, - // 0xA5 => unsafe { self.state.hl.as_u8s.right = res(self.state.hl.as_u8s.right, 4) }, - // 0xA6 => unsafe { - // let rotated = res(self.memory.get(self.state.hl.as_u16), 4); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0xA7 => unsafe { self.state.af.as_u8s.left = res(self.state.af.as_u8s.left, 4) }, - // 0xA8 => unsafe { self.state.bc.as_u8s.left = res(self.state.bc.as_u8s.left, 5) }, - // 0xA9 => unsafe { self.state.bc.as_u8s.right = res(self.state.bc.as_u8s.right, 5) }, - // 0xAA => unsafe { self.state.de.as_u8s.left = res(self.state.de.as_u8s.left, 5) }, - // 0xAB => unsafe { self.state.de.as_u8s.right = res(self.state.de.as_u8s.right, 5) }, - // 0xAC => unsafe { self.state.hl.as_u8s.left = res(self.state.hl.as_u8s.left, 5) }, - // 0xAD => unsafe { self.state.hl.as_u8s.right = res(self.state.hl.as_u8s.right, 5) }, - // 0xAE => unsafe { - // let rotated = res(self.memory.get(self.state.hl.as_u16), 5); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0xAF => unsafe { self.state.af.as_u8s.left = res(self.state.af.as_u8s.left, 5) }, - // 0xB0 => unsafe { self.state.bc.as_u8s.left = res(self.state.bc.as_u8s.left, 6) }, - // 0xB1 => unsafe { self.state.bc.as_u8s.right = res(self.state.bc.as_u8s.right, 6) }, - // 0xB2 => unsafe { self.state.de.as_u8s.left = res(self.state.de.as_u8s.left, 6) }, - // 0xB3 => unsafe { self.state.de.as_u8s.right = res(self.state.de.as_u8s.right, 6) }, - // 0xB4 => unsafe { self.state.hl.as_u8s.left = res(self.state.hl.as_u8s.left, 6) }, - // 0xB5 => unsafe { self.state.hl.as_u8s.right = res(self.state.hl.as_u8s.right, 6) }, - // 0xB6 => unsafe { - // let rotated = res(self.memory.get(self.state.hl.as_u16), 6); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0xB7 => unsafe { self.state.af.as_u8s.left = res(self.state.af.as_u8s.left, 6) }, - // 0xB8 => unsafe { self.state.bc.as_u8s.left = res(self.state.bc.as_u8s.left, 7) }, - // 0xB9 => unsafe { self.state.bc.as_u8s.right = res(self.state.bc.as_u8s.right, 7) }, - // 0xBA => unsafe { self.state.de.as_u8s.left = res(self.state.de.as_u8s.left, 7) }, - // 0xBB => unsafe { self.state.de.as_u8s.right = res(self.state.de.as_u8s.right, 7) }, - // 0xBC => unsafe { self.state.hl.as_u8s.left = res(self.state.hl.as_u8s.left, 7) }, - // 0xBD => unsafe { self.state.hl.as_u8s.right = res(self.state.hl.as_u8s.right, 7) }, - // 0xBE => unsafe { - // let rotated = res(self.memory.get(self.state.hl.as_u16), 7); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0xBF => unsafe { self.state.af.as_u8s.left = res(self.state.af.as_u8s.left, 7) }, - // 0xC0 => unsafe { self.state.bc.as_u8s.left = set(self.state.bc.as_u8s.left, 0) }, - // 0xC1 => unsafe { self.state.bc.as_u8s.right = set(self.state.bc.as_u8s.right, 0) }, - // 0xC2 => unsafe { self.state.de.as_u8s.left = set(self.state.de.as_u8s.left, 0) }, - // 0xC3 => unsafe { self.state.de.as_u8s.right = set(self.state.de.as_u8s.right, 0) }, - // 0xC4 => unsafe { self.state.hl.as_u8s.left = set(self.state.hl.as_u8s.left, 0) }, - // 0xC5 => unsafe { self.state.hl.as_u8s.right = set(self.state.hl.as_u8s.right, 0) }, - // 0xC6 => unsafe { - // let rotated = set(self.memory.get(self.state.hl.as_u16), 0); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0xC7 => unsafe { self.state.af.as_u8s.left = set(self.state.af.as_u8s.left, 0) }, - // 0xC8 => unsafe { self.state.bc.as_u8s.left = set(self.state.bc.as_u8s.left, 1) }, - // 0xC9 => unsafe { self.state.bc.as_u8s.right = set(self.state.bc.as_u8s.right, 1) }, - // 0xCA => unsafe { self.state.de.as_u8s.left = set(self.state.de.as_u8s.left, 1) }, - // 0xCB => unsafe { self.state.de.as_u8s.right = set(self.state.de.as_u8s.right, 1) }, - // 0xCC => unsafe { self.state.hl.as_u8s.left = set(self.state.hl.as_u8s.left, 1) }, - // 0xCD => unsafe { self.state.hl.as_u8s.right = set(self.state.hl.as_u8s.right, 1) }, - // 0xCE => unsafe { - // let rotated = set(self.memory.get(self.state.hl.as_u16), 1); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0xCF => unsafe { self.state.af.as_u8s.left = set(self.state.af.as_u8s.left, 1) }, - // 0xD0 => unsafe { self.state.bc.as_u8s.left = set(self.state.bc.as_u8s.left, 2) }, - // 0xD1 => unsafe { self.state.bc.as_u8s.right = set(self.state.bc.as_u8s.right, 2) }, - // 0xD2 => unsafe { self.state.de.as_u8s.left = set(self.state.de.as_u8s.left, 2) }, - // 0xD3 => unsafe { self.state.de.as_u8s.right = set(self.state.de.as_u8s.right, 2) }, - // 0xD4 => unsafe { self.state.hl.as_u8s.left = set(self.state.hl.as_u8s.left, 2) }, - // 0xD5 => unsafe { self.state.hl.as_u8s.right = set(self.state.hl.as_u8s.right, 2) }, - // 0xD6 => unsafe { - // let rotated = set(self.memory.get(self.state.hl.as_u16), 2); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0xD7 => unsafe { self.state.af.as_u8s.left = set(self.state.af.as_u8s.left, 2) }, - // 0xD8 => unsafe { self.state.bc.as_u8s.left = set(self.state.bc.as_u8s.left, 3) }, - // 0xD9 => unsafe { self.state.bc.as_u8s.right = set(self.state.bc.as_u8s.right, 3) }, - // 0xDA => unsafe { self.state.de.as_u8s.left = set(self.state.de.as_u8s.left, 3) }, - // 0xDB => unsafe { self.state.de.as_u8s.right = set(self.state.de.as_u8s.right, 3) }, - // 0xDC => unsafe { self.state.hl.as_u8s.left = set(self.state.hl.as_u8s.left, 3) }, - // 0xDD => unsafe { self.state.hl.as_u8s.right = set(self.state.hl.as_u8s.right, 3) }, - // 0xDE => unsafe { - // let rotated = set(self.memory.get(self.state.hl.as_u16), 3); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0xDF => unsafe { self.state.af.as_u8s.left = set(self.state.af.as_u8s.left, 3) }, - // 0xE0 => unsafe { self.state.bc.as_u8s.left = set(self.state.bc.as_u8s.left, 4) }, - // 0xE1 => unsafe { self.state.bc.as_u8s.right = set(self.state.bc.as_u8s.right, 4) }, - // 0xE2 => unsafe { self.state.de.as_u8s.left = set(self.state.de.as_u8s.left, 4) }, - // 0xE3 => unsafe { self.state.de.as_u8s.right = set(self.state.de.as_u8s.right, 4) }, - // 0xE4 => unsafe { self.state.hl.as_u8s.left = set(self.state.hl.as_u8s.left, 4) }, - // 0xE5 => unsafe { self.state.hl.as_u8s.right = set(self.state.hl.as_u8s.right, 4) }, - // 0xE6 => unsafe { - // let rotated = set(self.memory.get(self.state.hl.as_u16), 4); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0xE7 => unsafe { self.state.af.as_u8s.left = set(self.state.af.as_u8s.left, 4) }, - // 0xE8 => unsafe { self.state.bc.as_u8s.left = set(self.state.bc.as_u8s.left, 5) }, - // 0xE9 => unsafe { self.state.bc.as_u8s.right = set(self.state.bc.as_u8s.right, 5) }, - // 0xEA => unsafe { self.state.de.as_u8s.left = set(self.state.de.as_u8s.left, 5) }, - // 0xEB => unsafe { self.state.de.as_u8s.right = set(self.state.de.as_u8s.right, 5) }, - // 0xEC => unsafe { self.state.hl.as_u8s.left = set(self.state.hl.as_u8s.left, 5) }, - // 0xED => unsafe { self.state.hl.as_u8s.right = set(self.state.hl.as_u8s.right, 5) }, - // 0xEE => unsafe { - // let rotated = set(self.memory.get(self.state.hl.as_u16), 5); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0xEF => unsafe { self.state.af.as_u8s.left = set(self.state.af.as_u8s.left, 5) }, - // 0xF0 => unsafe { self.state.bc.as_u8s.left = set(self.state.bc.as_u8s.left, 6) }, - // 0xF1 => unsafe { self.state.bc.as_u8s.right = set(self.state.bc.as_u8s.right, 6) }, - // 0xF2 => unsafe { self.state.de.as_u8s.left = set(self.state.de.as_u8s.left, 6) }, - // 0xF3 => unsafe { self.state.de.as_u8s.right = set(self.state.de.as_u8s.right, 6) }, - // 0xF4 => unsafe { self.state.hl.as_u8s.left = set(self.state.hl.as_u8s.left, 6) }, - // 0xF5 => unsafe { self.state.hl.as_u8s.right = set(self.state.hl.as_u8s.right, 6) }, - // 0xF6 => unsafe { - // let rotated = set(self.memory.get(self.state.hl.as_u16), 6); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0xF7 => unsafe { self.state.af.as_u8s.left = set(self.state.af.as_u8s.left, 6) }, - // 0xF8 => unsafe { self.state.bc.as_u8s.left = set(self.state.bc.as_u8s.left, 7) }, - // 0xF9 => unsafe { self.state.bc.as_u8s.right = set(self.state.bc.as_u8s.right, 7) }, - // 0xFA => unsafe { self.state.de.as_u8s.left = set(self.state.de.as_u8s.left, 7) }, - // 0xFB => unsafe { self.state.de.as_u8s.right = set(self.state.de.as_u8s.right, 7) }, - // 0xFC => unsafe { self.state.hl.as_u8s.left = set(self.state.hl.as_u8s.left, 7) }, - // 0xFD => unsafe { self.state.hl.as_u8s.right = set(self.state.hl.as_u8s.right, 7) }, - // 0xFE => unsafe { - // let rotated = set(self.memory.get(self.state.hl.as_u16), 7); - // self.memory.set(self.state.hl.as_u16, rotated) - // }, - // 0xFF => unsafe { self.state.af.as_u8s.left = set(self.state.af.as_u8s.left, 7) }, - // } - // } + fn cb_subop(&mut self, subop: u8) { + match subop { + 0x00 => { + let val = self.rlc(self.reg.get_8(Reg8::B)); + self.reg.set_8(Reg8::B, val); + } + 0x01 => { + let val = self.rlc(self.reg.get_8(Reg8::C)); + self.reg.set_8(Reg8::C, val); + } + 0x02 => { + let val = self.rlc(self.reg.get_8(Reg8::D)); + self.reg.set_8(Reg8::D, val); + } + 0x03 => { + let val = self.rlc(self.reg.get_8(Reg8::E)); + self.reg.set_8(Reg8::E, val); + } + 0x04 => { + let val = self.rlc(self.reg.get_8(Reg8::H)); + self.reg.set_8(Reg8::H, val); + } + 0x05 => { + let val = self.rlc(self.reg.get_8(Reg8::L)); + self.reg.set_8(Reg8::L, val); + } + 0x06 => { + let val = self.rlc(self.memory.get(self.reg.hl)); + self.memory.set(self.reg.hl, val); + } + 0x07 => { + let val = self.rlc(self.reg.get_8(Reg8::A)); + self.reg.set_8(Reg8::A, val); + } + 0x08 => { + let val = self.rrc(self.reg.get_8(Reg8::B)); + self.reg.set_8(Reg8::B, val); + } + 0x09 => { + let val = self.rrc(self.reg.get_8(Reg8::C)); + self.reg.set_8(Reg8::C, val); + } + 0x0A => { + let val = self.rrc(self.reg.get_8(Reg8::D)); + self.reg.set_8(Reg8::D, val); + } + 0x0B => { + let val = self.rrc(self.reg.get_8(Reg8::E)); + self.reg.set_8(Reg8::E, val); + } + 0x0C => { + let val = self.rrc(self.reg.get_8(Reg8::H)); + self.reg.set_8(Reg8::H, val); + } + 0x0D => { + let val = self.rrc(self.reg.get_8(Reg8::L)); + self.reg.set_8(Reg8::L, val); + } + 0x0E => { + let val = self.rrc(self.memory.get(self.reg.hl)); + self.memory.set(self.reg.hl, val); + } + 0x0F => { + let val = self.rrc(self.reg.get_8(Reg8::A)); + self.reg.set_8(Reg8::A, val); + } + 0x10 => { + let val = self.rl(self.reg.get_8(Reg8::B)); + self.reg.set_8(Reg8::B, val); + } + 0x11 => { + let val = self.rl(self.reg.get_8(Reg8::C)); + self.reg.set_8(Reg8::C, val); + } + 0x12 => { + let val = self.rl(self.reg.get_8(Reg8::D)); + self.reg.set_8(Reg8::D, val); + } + 0x13 => { + let val = self.rl(self.reg.get_8(Reg8::E)); + self.reg.set_8(Reg8::E, val); + } + 0x14 => { + let val = self.rl(self.reg.get_8(Reg8::H)); + self.reg.set_8(Reg8::H, val); + } + 0x15 => { + let val = self.rl(self.reg.get_8(Reg8::L)); + self.reg.set_8(Reg8::L, val); + } + 0x16 => { + let val = self.rl(self.memory.get(self.reg.hl)); + self.memory.set(self.reg.hl, val); + } + 0x17 => { + let val = self.rl(self.reg.get_8(Reg8::A)); + self.reg.set_8(Reg8::A, val); + } + 0x18 => { + let val = self.rr(self.reg.get_8(Reg8::B)); + self.reg.set_8(Reg8::B, val); + } + 0x19 => { + let val = self.rr(self.reg.get_8(Reg8::C)); + self.reg.set_8(Reg8::C, val); + } + 0x1A => { + let val = self.rr(self.reg.get_8(Reg8::D)); + self.reg.set_8(Reg8::D, val); + } + 0x1B => { + let val = self.rr(self.reg.get_8(Reg8::E)); + self.reg.set_8(Reg8::E, val); + } + 0x1C => { + let val = self.rr(self.reg.get_8(Reg8::H)); + self.reg.set_8(Reg8::H, val); + } + 0x1D => { + let val = self.rr(self.reg.get_8(Reg8::L)); + self.reg.set_8(Reg8::L, val); + } + 0x1E => { + let val = self.rr(self.memory.get(self.reg.hl)); + self.memory.set(self.reg.hl, val); + } + 0x1F => { + let val = self.rr(self.reg.get_8(Reg8::A)); + self.reg.set_8(Reg8::A, val); + } + 0x20 => { + let val = self.sla(self.reg.get_8(Reg8::B)); + self.reg.set_8(Reg8::B, val); + } + 0x21 => { + let val = self.sla(self.reg.get_8(Reg8::C)); + self.reg.set_8(Reg8::C, val); + } + 0x22 => { + let val = self.sla(self.reg.get_8(Reg8::D)); + self.reg.set_8(Reg8::D, val); + } + 0x23 => { + let val = self.sla(self.reg.get_8(Reg8::E)); + self.reg.set_8(Reg8::E, val); + } + 0x24 => { + let val = self.sla(self.reg.get_8(Reg8::H)); + self.reg.set_8(Reg8::H, val); + } + 0x25 => { + let val = self.sla(self.reg.get_8(Reg8::L)); + self.reg.set_8(Reg8::L, val); + } + 0x26 => { + let val = self.sla(self.memory.get(self.reg.hl)); + self.memory.set(self.reg.hl, val); + } + 0x27 => { + let val = self.sla(self.reg.get_8(Reg8::A)); + self.reg.set_8(Reg8::A, val); + } + 0x28 => { + let val = self.sra(self.reg.get_8(Reg8::B)); + self.reg.set_8(Reg8::B, val); + } + 0x29 => { + let val = self.sra(self.reg.get_8(Reg8::C)); + self.reg.set_8(Reg8::C, val); + } + 0x2A => { + let val = self.sra(self.reg.get_8(Reg8::D)); + self.reg.set_8(Reg8::D, val); + } + 0x2B => { + let val = self.sra(self.reg.get_8(Reg8::E)); + self.reg.set_8(Reg8::E, val); + } + 0x2C => { + let val = self.sra(self.reg.get_8(Reg8::H)); + self.reg.set_8(Reg8::H, val); + } + 0x2D => { + let val = self.sra(self.reg.get_8(Reg8::L)); + self.reg.set_8(Reg8::L, val); + } + 0x2E => { + let val = self.sra(self.memory.get(self.reg.hl)); + self.memory.set(self.reg.hl, val); + } + 0x2F => { + let val = self.sra(self.reg.get_8(Reg8::A)); + self.reg.set_8(Reg8::A, val); + } + 0x30 => { + let val = self.swap(self.reg.get_8(Reg8::B)); + self.reg.set_8(Reg8::B, val); + } + 0x31 => { + let val = self.swap(self.reg.get_8(Reg8::C)); + self.reg.set_8(Reg8::C, val); + } + 0x32 => { + let val = self.swap(self.reg.get_8(Reg8::D)); + self.reg.set_8(Reg8::D, val); + } + 0x33 => { + let val = self.swap(self.reg.get_8(Reg8::E)); + self.reg.set_8(Reg8::E, val); + } + 0x34 => { + let val = self.swap(self.reg.get_8(Reg8::H)); + self.reg.set_8(Reg8::H, val); + } + 0x35 => { + let val = self.swap(self.reg.get_8(Reg8::L)); + self.reg.set_8(Reg8::L, val); + } + 0x36 => { + let val = self.swap(self.memory.get(self.reg.hl)); + self.memory.set(self.reg.hl, val); + } + 0x37 => { + let val = self.swap(self.reg.get_8(Reg8::A)); + self.reg.set_8(Reg8::A, val); + } + 0x38 => { + let val = self.srl(self.reg.get_8(Reg8::B)); + self.reg.set_8(Reg8::B, val); + } + 0x39 => { + let val = self.srl(self.reg.get_8(Reg8::C)); + self.reg.set_8(Reg8::C, val); + } + 0x3A => { + let val = self.srl(self.reg.get_8(Reg8::D)); + self.reg.set_8(Reg8::D, val); + } + 0x3B => { + let val = self.srl(self.reg.get_8(Reg8::E)); + self.reg.set_8(Reg8::E, val); + } + 0x3C => { + let val = self.srl(self.reg.get_8(Reg8::H)); + self.reg.set_8(Reg8::H, val); + } + 0x3D => { + let val = self.srl(self.reg.get_8(Reg8::L)); + self.reg.set_8(Reg8::L, val); + } + 0x3E => { + let val = self.srl(self.memory.get(self.reg.hl)); + self.memory.set(self.reg.hl, val); + } + 0x3F => { + let val = self.srl(self.reg.get_8(Reg8::A)); + self.reg.set_8(Reg8::A, val); + } + 0x40 => self.bit(self.reg.get_8(Reg8::B), 0), + 0x41 => self.bit(self.reg.get_8(Reg8::C), 0), + 0x42 => self.bit(self.reg.get_8(Reg8::D), 0), + 0x43 => self.bit(self.reg.get_8(Reg8::E), 0), + 0x44 => self.bit(self.reg.get_8(Reg8::H), 0), + 0x45 => self.bit(self.reg.get_8(Reg8::L), 0), + 0x46 => self.bit(self.memory.get(self.reg.hl), 0), + 0x47 => self.bit(self.reg.get_8(Reg8::A), 0), + 0x48 => self.bit(self.reg.get_8(Reg8::B), 1), + 0x49 => self.bit(self.reg.get_8(Reg8::C), 1), + 0x4A => self.bit(self.reg.get_8(Reg8::D), 1), + 0x4B => self.bit(self.reg.get_8(Reg8::E), 1), + 0x4C => self.bit(self.reg.get_8(Reg8::H), 1), + 0x4D => self.bit(self.reg.get_8(Reg8::L), 1), + 0x4E => self.bit(self.memory.get(self.reg.hl), 1), + 0x4F => self.bit(self.reg.get_8(Reg8::A), 1), + 0x50 => self.bit(self.reg.get_8(Reg8::B), 2), + 0x51 => self.bit(self.reg.get_8(Reg8::C), 2), + 0x52 => self.bit(self.reg.get_8(Reg8::D), 2), + 0x53 => self.bit(self.reg.get_8(Reg8::E), 2), + 0x54 => self.bit(self.reg.get_8(Reg8::H), 2), + 0x55 => self.bit(self.reg.get_8(Reg8::L), 2), + 0x56 => self.bit(self.memory.get(self.reg.hl), 2), + 0x57 => self.bit(self.reg.get_8(Reg8::A), 2), + 0x58 => self.bit(self.reg.get_8(Reg8::B), 3), + 0x59 => self.bit(self.reg.get_8(Reg8::C), 3), + 0x5A => self.bit(self.reg.get_8(Reg8::D), 3), + 0x5B => self.bit(self.reg.get_8(Reg8::E), 3), + 0x5C => self.bit(self.reg.get_8(Reg8::H), 3), + 0x5D => self.bit(self.reg.get_8(Reg8::L), 3), + 0x5E => self.bit(self.memory.get(self.reg.hl), 3), + 0x5F => self.bit(self.reg.get_8(Reg8::A), 3), + 0x60 => self.bit(self.reg.get_8(Reg8::B), 4), + 0x61 => self.bit(self.reg.get_8(Reg8::C), 4), + 0x62 => self.bit(self.reg.get_8(Reg8::D), 4), + 0x63 => self.bit(self.reg.get_8(Reg8::E), 4), + 0x64 => self.bit(self.reg.get_8(Reg8::H), 4), + 0x65 => self.bit(self.reg.get_8(Reg8::L), 4), + 0x66 => self.bit(self.memory.get(self.reg.hl), 4), + 0x67 => self.bit(self.reg.get_8(Reg8::A), 4), + 0x68 => self.bit(self.reg.get_8(Reg8::B), 5), + 0x69 => self.bit(self.reg.get_8(Reg8::C), 5), + 0x6A => self.bit(self.reg.get_8(Reg8::D), 5), + 0x6B => self.bit(self.reg.get_8(Reg8::E), 5), + 0x6C => self.bit(self.reg.get_8(Reg8::H), 5), + 0x6D => self.bit(self.reg.get_8(Reg8::L), 5), + 0x6E => self.bit(self.memory.get(self.reg.hl), 5), + 0x6F => self.bit(self.reg.get_8(Reg8::A), 5), + 0x70 => self.bit(self.reg.get_8(Reg8::B), 6), + 0x71 => self.bit(self.reg.get_8(Reg8::C), 6), + 0x72 => self.bit(self.reg.get_8(Reg8::D), 6), + 0x73 => self.bit(self.reg.get_8(Reg8::E), 6), + 0x74 => self.bit(self.reg.get_8(Reg8::H), 6), + 0x75 => self.bit(self.reg.get_8(Reg8::L), 6), + 0x76 => self.bit(self.memory.get(self.reg.hl), 6), + 0x77 => self.bit(self.reg.get_8(Reg8::A), 6), + 0x78 => self.bit(self.reg.get_8(Reg8::B), 7), + 0x79 => self.bit(self.reg.get_8(Reg8::C), 7), + 0x7A => self.bit(self.reg.get_8(Reg8::D), 7), + 0x7B => self.bit(self.reg.get_8(Reg8::E), 7), + 0x7C => self.bit(self.reg.get_8(Reg8::H), 7), + 0x7D => self.bit(self.reg.get_8(Reg8::L), 7), + 0x7E => self.bit(self.memory.get(self.reg.hl), 7), + 0x7F => self.bit(self.reg.get_8(Reg8::A), 7), + 0x80 => { + let val = res(self.reg.get_8(Reg8::B), 0); + self.reg.set_8(Reg8::B, val); + } + 0x81 => { + let val = res(self.reg.get_8(Reg8::C), 0); + self.reg.set_8(Reg8::C, val); + } + 0x82 => { + let val = res(self.reg.get_8(Reg8::D), 0); + self.reg.set_8(Reg8::D, val); + } + 0x83 => { + let val = res(self.reg.get_8(Reg8::E), 0); + self.reg.set_8(Reg8::E, val); + } + 0x84 => { + let val = res(self.reg.get_8(Reg8::H), 0); + self.reg.set_8(Reg8::H, val); + } + 0x85 => { + let val = res(self.reg.get_8(Reg8::L), 0); + self.reg.set_8(Reg8::L, val); + } + 0x86 => { + let val = res(self.memory.get(self.reg.hl), 0); + self.memory.set(self.reg.hl, val); + } + 0x87 => { + let val = res(self.reg.get_8(Reg8::A), 0); + self.reg.set_8(Reg8::A, val); + } + 0x88 => { + let val = res(self.reg.get_8(Reg8::B), 1); + self.reg.set_8(Reg8::B, val); + } + 0x89 => { + let val = res(self.reg.get_8(Reg8::C), 1); + self.reg.set_8(Reg8::C, val); + } + 0x8A => { + let val = res(self.reg.get_8(Reg8::D), 1); + self.reg.set_8(Reg8::D, val); + } + 0x8B => { + let val = res(self.reg.get_8(Reg8::E), 1); + self.reg.set_8(Reg8::E, val); + } + 0x8C => { + let val = res(self.reg.get_8(Reg8::H), 1); + self.reg.set_8(Reg8::H, val); + } + 0x8D => { + let val = res(self.reg.get_8(Reg8::L), 1); + self.reg.set_8(Reg8::L, val); + } + 0x8E => { + let val = res(self.memory.get(self.reg.hl), 1); + self.memory.set(self.reg.hl, val); + } + 0x8F => { + let val = res(self.reg.get_8(Reg8::A), 1); + self.reg.set_8(Reg8::A, val); + } + 0x90 => { + let val = res(self.reg.get_8(Reg8::B), 2); + self.reg.set_8(Reg8::B, val); + } + 0x91 => { + let val = res(self.reg.get_8(Reg8::C), 2); + self.reg.set_8(Reg8::C, val); + } + 0x92 => { + let val = res(self.reg.get_8(Reg8::D), 2); + self.reg.set_8(Reg8::D, val); + } + 0x93 => { + let val = res(self.reg.get_8(Reg8::E), 2); + self.reg.set_8(Reg8::E, val); + } + 0x94 => { + let val = res(self.reg.get_8(Reg8::H), 2); + self.reg.set_8(Reg8::H, val); + } + 0x95 => { + let val = res(self.reg.get_8(Reg8::L), 2); + self.reg.set_8(Reg8::L, val); + } + 0x96 => { + let val = res(self.memory.get(self.reg.hl), 2); + self.memory.set(self.reg.hl, val); + } + 0x97 => { + let val = res(self.reg.get_8(Reg8::A), 2); + self.reg.set_8(Reg8::A, val); + } + 0x98 => { + let val = res(self.reg.get_8(Reg8::B), 3); + self.reg.set_8(Reg8::B, val); + } + 0x99 => { + let val = res(self.reg.get_8(Reg8::C), 3); + self.reg.set_8(Reg8::C, val); + } + 0x9A => { + let val = res(self.reg.get_8(Reg8::D), 3); + self.reg.set_8(Reg8::D, val); + } + 0x9B => { + let val = res(self.reg.get_8(Reg8::E), 3); + self.reg.set_8(Reg8::E, val); + } + 0x9C => { + let val = res(self.reg.get_8(Reg8::H), 3); + self.reg.set_8(Reg8::H, val); + } + 0x9D => { + let val = res(self.reg.get_8(Reg8::L), 3); + self.reg.set_8(Reg8::L, val); + } + 0x9E => { + let val = res(self.memory.get(self.reg.hl), 3); + self.memory.set(self.reg.hl, val); + } + 0x9F => { + let val = res(self.reg.get_8(Reg8::A), 3); + self.reg.set_8(Reg8::A, val); + } + 0xA0 => { + let val = res(self.reg.get_8(Reg8::B), 4); + self.reg.set_8(Reg8::B, val); + } + 0xA1 => { + let val = res(self.reg.get_8(Reg8::C), 4); + self.reg.set_8(Reg8::C, val); + } + 0xA2 => { + let val = res(self.reg.get_8(Reg8::D), 4); + self.reg.set_8(Reg8::D, val); + } + 0xA3 => { + let val = res(self.reg.get_8(Reg8::E), 4); + self.reg.set_8(Reg8::E, val); + } + 0xA4 => { + let val = res(self.reg.get_8(Reg8::H), 4); + self.reg.set_8(Reg8::H, val); + } + 0xA5 => { + let val = res(self.reg.get_8(Reg8::L), 4); + self.reg.set_8(Reg8::L, val); + } + 0xA6 => { + let val = res(self.memory.get(self.reg.hl), 4); + self.memory.set(self.reg.hl, val); + } + 0xA7 => { + let val = res(self.reg.get_8(Reg8::A), 4); + self.reg.set_8(Reg8::A, val); + } + 0xA8 => { + let val = res(self.reg.get_8(Reg8::B), 5); + self.reg.set_8(Reg8::B, val); + } + 0xA9 => { + let val = res(self.reg.get_8(Reg8::C), 5); + self.reg.set_8(Reg8::C, val); + } + 0xAA => { + let val = res(self.reg.get_8(Reg8::D), 5); + self.reg.set_8(Reg8::D, val); + } + 0xAB => { + let val = res(self.reg.get_8(Reg8::E), 5); + self.reg.set_8(Reg8::E, val); + } + 0xAC => { + let val = res(self.reg.get_8(Reg8::H), 5); + self.reg.set_8(Reg8::H, val); + } + 0xAD => { + let val = res(self.reg.get_8(Reg8::L), 5); + self.reg.set_8(Reg8::L, val); + } + 0xAE => { + let val = res(self.memory.get(self.reg.hl), 5); + self.memory.set(self.reg.hl, val); + } + 0xAF => { + let val = res(self.reg.get_8(Reg8::A), 5); + self.reg.set_8(Reg8::A, val); + } + 0xB0 => { + let val = res(self.reg.get_8(Reg8::B), 6); + self.reg.set_8(Reg8::B, val); + } + 0xB1 => { + let val = res(self.reg.get_8(Reg8::C), 6); + self.reg.set_8(Reg8::C, val); + } + 0xB2 => { + let val = res(self.reg.get_8(Reg8::D), 6); + self.reg.set_8(Reg8::D, val); + } + 0xB3 => { + let val = res(self.reg.get_8(Reg8::E), 6); + self.reg.set_8(Reg8::E, val); + } + 0xB4 => { + let val = res(self.reg.get_8(Reg8::H), 6); + self.reg.set_8(Reg8::H, val); + } + 0xB5 => { + let val = res(self.reg.get_8(Reg8::L), 6); + self.reg.set_8(Reg8::L, val); + } + 0xB6 => { + let val = res(self.memory.get(self.reg.hl), 6); + self.memory.set(self.reg.hl, val); + } + 0xB7 => { + let val = res(self.reg.get_8(Reg8::A), 6); + self.reg.set_8(Reg8::A, val); + } + 0xB8 => { + let val = res(self.reg.get_8(Reg8::B), 7); + self.reg.set_8(Reg8::B, val); + } + 0xB9 => { + let val = res(self.reg.get_8(Reg8::C), 7); + self.reg.set_8(Reg8::C, val); + } + 0xBA => { + let val = res(self.reg.get_8(Reg8::D), 7); + self.reg.set_8(Reg8::D, val); + } + 0xBB => { + let val = res(self.reg.get_8(Reg8::E), 7); + self.reg.set_8(Reg8::E, val); + } + 0xBC => { + let val = res(self.reg.get_8(Reg8::H), 7); + self.reg.set_8(Reg8::H, val); + } + 0xBD => { + let val = res(self.reg.get_8(Reg8::L), 7); + self.reg.set_8(Reg8::L, val); + } + 0xBE => { + let val = res(self.memory.get(self.reg.hl), 7); + self.memory.set(self.reg.hl, val); + } + 0xBF => { + let val = res(self.reg.get_8(Reg8::A), 7); + self.reg.set_8(Reg8::A, val); + } + 0xC0 => { + let val = set(self.reg.get_8(Reg8::B), 0); + self.reg.set_8(Reg8::B, val); + } + 0xC1 => { + let val = set(self.reg.get_8(Reg8::C), 0); + self.reg.set_8(Reg8::C, val); + } + 0xC2 => { + let val = set(self.reg.get_8(Reg8::D), 0); + self.reg.set_8(Reg8::D, val); + } + 0xC3 => { + let val = set(self.reg.get_8(Reg8::E), 0); + self.reg.set_8(Reg8::E, val); + } + 0xC4 => { + let val = set(self.reg.get_8(Reg8::H), 0); + self.reg.set_8(Reg8::H, val); + } + 0xC5 => { + let val = set(self.reg.get_8(Reg8::L), 0); + self.reg.set_8(Reg8::L, val); + } + 0xC6 => { + let val = set(self.memory.get(self.reg.hl), 0); + self.memory.set(self.reg.hl, val); + } + 0xC7 => { + let val = set(self.reg.get_8(Reg8::A), 0); + self.reg.set_8(Reg8::A, val); + } + 0xC8 => { + let val = set(self.reg.get_8(Reg8::B), 1); + self.reg.set_8(Reg8::B, val); + } + 0xC9 => { + let val = set(self.reg.get_8(Reg8::C), 1); + self.reg.set_8(Reg8::C, val); + } + 0xCA => { + let val = set(self.reg.get_8(Reg8::D), 1); + self.reg.set_8(Reg8::D, val); + } + 0xCB => { + let val = set(self.reg.get_8(Reg8::E), 1); + self.reg.set_8(Reg8::E, val); + } + 0xCC => { + let val = set(self.reg.get_8(Reg8::H), 1); + self.reg.set_8(Reg8::H, val); + } + 0xCD => { + let val = set(self.reg.get_8(Reg8::L), 1); + self.reg.set_8(Reg8::L, val); + } + 0xCE => { + let val = set(self.memory.get(self.reg.hl), 1); + self.memory.set(self.reg.hl, val); + } + 0xCF => { + let val = set(self.reg.get_8(Reg8::A), 1); + self.reg.set_8(Reg8::A, val); + } + 0xD0 => { + let val = set(self.reg.get_8(Reg8::B), 2); + self.reg.set_8(Reg8::B, val); + } + 0xD1 => { + let val = set(self.reg.get_8(Reg8::C), 2); + self.reg.set_8(Reg8::C, val); + } + 0xD2 => { + let val = set(self.reg.get_8(Reg8::D), 2); + self.reg.set_8(Reg8::D, val); + } + 0xD3 => { + let val = set(self.reg.get_8(Reg8::E), 2); + self.reg.set_8(Reg8::E, val); + } + 0xD4 => { + let val = set(self.reg.get_8(Reg8::H), 2); + self.reg.set_8(Reg8::H, val); + } + 0xD5 => { + let val = set(self.reg.get_8(Reg8::L), 2); + self.reg.set_8(Reg8::L, val); + } + 0xD6 => { + let val = set(self.memory.get(self.reg.hl), 2); + self.memory.set(self.reg.hl, val); + } + 0xD7 => { + let val = set(self.reg.get_8(Reg8::A), 2); + self.reg.set_8(Reg8::A, val); + } + 0xD8 => { + let val = set(self.reg.get_8(Reg8::B), 3); + self.reg.set_8(Reg8::B, val); + } + 0xD9 => { + let val = set(self.reg.get_8(Reg8::C), 3); + self.reg.set_8(Reg8::C, val); + } + 0xDA => { + let val = set(self.reg.get_8(Reg8::D), 3); + self.reg.set_8(Reg8::D, val); + } + 0xDB => { + let val = set(self.reg.get_8(Reg8::E), 3); + self.reg.set_8(Reg8::E, val); + } + 0xDC => { + let val = set(self.reg.get_8(Reg8::H), 3); + self.reg.set_8(Reg8::H, val); + } + 0xDD => { + let val = set(self.reg.get_8(Reg8::L), 3); + self.reg.set_8(Reg8::L, val); + } + 0xDE => { + let val = set(self.memory.get(self.reg.hl), 3); + self.memory.set(self.reg.hl, val); + } + 0xDF => { + let val = set(self.reg.get_8(Reg8::A), 3); + self.reg.set_8(Reg8::A, val); + } + 0xE0 => { + let val = set(self.reg.get_8(Reg8::B), 4); + self.reg.set_8(Reg8::B, val); + } + 0xE1 => { + let val = set(self.reg.get_8(Reg8::C), 4); + self.reg.set_8(Reg8::C, val); + } + 0xE2 => { + let val = set(self.reg.get_8(Reg8::D), 4); + self.reg.set_8(Reg8::D, val); + } + 0xE3 => { + let val = set(self.reg.get_8(Reg8::E), 4); + self.reg.set_8(Reg8::E, val); + } + 0xE4 => { + let val = set(self.reg.get_8(Reg8::H), 4); + self.reg.set_8(Reg8::H, val); + } + 0xE5 => { + let val = set(self.reg.get_8(Reg8::L), 4); + self.reg.set_8(Reg8::L, val); + } + 0xE6 => { + let val = set(self.memory.get(self.reg.hl), 4); + self.memory.set(self.reg.hl, val); + } + 0xE7 => { + let val = set(self.reg.get_8(Reg8::A), 4); + self.reg.set_8(Reg8::A, val); + } + 0xE8 => { + let val = set(self.reg.get_8(Reg8::B), 5); + self.reg.set_8(Reg8::B, val); + } + 0xE9 => { + let val = set(self.reg.get_8(Reg8::C), 5); + self.reg.set_8(Reg8::C, val); + } + 0xEA => { + let val = set(self.reg.get_8(Reg8::D), 5); + self.reg.set_8(Reg8::D, val); + } + 0xEB => { + let val = set(self.reg.get_8(Reg8::E), 5); + self.reg.set_8(Reg8::E, val); + } + 0xEC => { + let val = set(self.reg.get_8(Reg8::H), 5); + self.reg.set_8(Reg8::H, val); + } + 0xED => { + let val = set(self.reg.get_8(Reg8::L), 5); + self.reg.set_8(Reg8::L, val); + } + 0xEE => { + let val = set(self.memory.get(self.reg.hl), 5); + self.memory.set(self.reg.hl, val); + } + 0xEF => { + let val = set(self.reg.get_8(Reg8::A), 5); + self.reg.set_8(Reg8::A, val); + } + 0xF0 => { + let val = set(self.reg.get_8(Reg8::B), 6); + self.reg.set_8(Reg8::B, val); + } + 0xF1 => { + let val = set(self.reg.get_8(Reg8::C), 6); + self.reg.set_8(Reg8::C, val); + } + 0xF2 => { + let val = set(self.reg.get_8(Reg8::D), 6); + self.reg.set_8(Reg8::D, val); + } + 0xF3 => { + let val = set(self.reg.get_8(Reg8::E), 6); + self.reg.set_8(Reg8::E, val); + } + 0xF4 => { + let val = set(self.reg.get_8(Reg8::H), 6); + self.reg.set_8(Reg8::H, val); + } + 0xF5 => { + let val = set(self.reg.get_8(Reg8::L), 6); + self.reg.set_8(Reg8::L, val); + } + 0xF6 => { + let val = set(self.memory.get(self.reg.hl), 6); + self.memory.set(self.reg.hl, val); + } + 0xF7 => { + let val = set(self.reg.get_8(Reg8::A), 6); + self.reg.set_8(Reg8::A, val); + } + 0xF8 => { + let val = set(self.reg.get_8(Reg8::B), 7); + self.reg.set_8(Reg8::B, val); + } + 0xF9 => { + let val = set(self.reg.get_8(Reg8::C), 7); + self.reg.set_8(Reg8::C, val); + } + 0xFA => { + let val = set(self.reg.get_8(Reg8::D), 7); + self.reg.set_8(Reg8::D, val); + } + 0xFB => { + let val = set(self.reg.get_8(Reg8::E), 7); + self.reg.set_8(Reg8::E, val); + } + 0xFC => { + let val = set(self.reg.get_8(Reg8::H), 7); + self.reg.set_8(Reg8::H, val); + } + 0xFD => { + let val = set(self.reg.get_8(Reg8::L), 7); + self.reg.set_8(Reg8::L, val); + } + 0xFE => { + let val = set(self.memory.get(self.reg.hl), 7); + self.memory.set(self.reg.hl, val); + } + 0xFF => { + let val = set(self.reg.get_8(Reg8::A), 7); + self.reg.set_8(Reg8::A, val); + } + } + } #[allow(dead_code)] fn instruction_length(&self, _opcode: u8) -> u8 {