diff --git a/src/processor/opcodes.rs b/src/processor/opcodes.rs index 8aa08f4..a51bfe8 100644 --- a/src/processor/opcodes.rs +++ b/src/processor/opcodes.rs @@ -5,94 +5,183 @@ use super::{ }; impl CPU { - pub fn run_opcode(&mut self, opcode: u8) { + pub fn run_opcode(&mut self, opcode: u8) -> u8 { match opcode { 0x00 => { // noop + 1 + } + 0x01 => { + self.reg.bc = self.ld_immediate_word(); + 3 + } + 0x02 => { + self.memory.set(self.reg.bc, self.reg.get_8(Reg8::A)); + 2 + } + 0x03 => { + self.reg.bc = self.inc_pair(self.reg.bc); + 2 + } + 0x04 => { + self.inc(Reg8::B); + 1 + } + 0x05 => { + self.dec(Reg8::B); + 1 } - 0x01 => self.reg.bc = self.ld_immediate_word(), - 0x02 => self.memory.set(self.reg.bc, self.reg.get_8(Reg8::A)), - 0x03 => self.reg.bc = self.inc_pair(self.reg.bc), - 0x04 => self.inc(Reg8::B), - 0x05 => self.dec(Reg8::B), 0x06 => { let byte = self.ld_immediate_byte(); self.reg.set_8(Reg8::B, byte); + 2 } 0x07 => { let val = self.rlc(self.reg.get_8(Reg8::A)); self.reg.set_8(Reg8::A, val); + 1 } 0x08 => { let addr = self.ld_immediate_word(); self.memory.set(addr, self.reg.sp.get_low()); self.memory .set(addr.wrapping_add(0x1), self.reg.sp.get_high()); + 5 + } + 0x09 => { + self.reg.hl = self.add_u16s(self.reg.hl, self.reg.bc); + 2 + } + 0x0A => { + self.reg.set_8(Reg8::A, self.memory.get(self.reg.bc)); + 2 + } + 0x0B => { + self.reg.bc = self.dec_pair(self.reg.bc); + 2 + } + 0x0C => { + self.inc(Reg8::C); + 1 + } + 0x0D => { + self.dec(Reg8::C); + 1 } - 0x09 => self.reg.hl = self.add_u16s(self.reg.hl, self.reg.bc), - 0x0A => self.reg.set_8(Reg8::A, self.memory.get(self.reg.bc)), - 0x0B => self.reg.bc = self.dec_pair(self.reg.bc), - 0x0C => self.inc(Reg8::C), - 0x0D => self.dec(Reg8::C), 0x0E => { let byte = self.ld_immediate_byte(); self.reg.set_8(Reg8::C, byte); + 2 } 0x0F => { let val = self.rrc(self.reg.get_8(Reg8::A)); self.reg.set_8(Reg8::A, val); + 1 } 0x10 => { // stop + // 1 cycle long panic!("stop instruction"); } - 0x11 => self.reg.de = self.ld_immediate_word(), - 0x12 => self.memory.set(self.reg.de, self.reg.get_8(Reg8::A)), - 0x13 => self.reg.de = self.inc_pair(self.reg.de), - 0x14 => self.inc(Reg8::D), - 0x15 => self.dec(Reg8::D), + 0x11 => { + self.reg.de = self.ld_immediate_word(); + 3 + } + 0x12 => { + self.memory.set(self.reg.de, self.reg.get_8(Reg8::A)); + 2 + } + 0x13 => { + self.reg.de = self.inc_pair(self.reg.de); + 2 + } + 0x14 => { + self.inc(Reg8::D); + 1 + } + 0x15 => { + self.dec(Reg8::D); + 1 + } 0x16 => { let byte = self.ld_immediate_byte(); self.reg.set_8(Reg8::D, byte); + 2 } 0x17 => { let val = self.rl(self.reg.get_8(Reg8::A)); self.reg.set_8(Reg8::A, val); + 1 } 0x18 => { let jump = as_signed(self.ld_immediate_byte()); self.jr(jump); + 3 + } + 0x19 => { + self.reg.hl = self.add_u16s(self.reg.hl, self.reg.de); + 2 + } + 0x1A => { + self.reg.set_8(Reg8::A, self.memory.get(self.reg.de)); + 2 + } + 0x1B => { + self.reg.de = self.dec_pair(self.reg.de); + 2 + } + 0x1C => { + self.inc(Reg8::E); + 1 + } + 0x1D => { + self.dec(Reg8::E); + 1 } - 0x19 => self.reg.hl = self.add_u16s(self.reg.hl, self.reg.de), - 0x1A => self.reg.set_8(Reg8::A, self.memory.get(self.reg.de)), - 0x1B => self.reg.de = self.dec_pair(self.reg.de), - 0x1C => self.inc(Reg8::E), - 0x1D => self.dec(Reg8::E), 0x1E => { let byte = self.ld_immediate_byte(); self.reg.set_8(Reg8::E, byte); + 2 } 0x1F => { let val = self.rr(self.reg.get_8(Reg8::A)); self.reg.set_8(Reg8::A, val); + 2 } 0x20 => { let jump = as_signed(self.ld_immediate_byte()); if !self.is_flag(Flags::Zero) { self.jr(jump); + 3 + } else { + 2 } } - 0x21 => self.reg.hl = self.ld_immediate_word(), + 0x21 => { + self.reg.hl = self.ld_immediate_word(); + 3 + } 0x22 => { self.memory.set(self.reg.hl, self.reg.get_8(Reg8::A)); self.reg.hl = self.inc_pair(self.reg.hl); + 2 + } + 0x23 => { + self.reg.hl = self.inc_pair(self.reg.hl); + 2 + } + 0x24 => { + self.inc(Reg8::H); + 1 + } + 0x25 => { + self.dec(Reg8::H); + 1 } - 0x23 => self.reg.hl = self.inc_pair(self.reg.hl), - 0x24 => self.inc(Reg8::H), - 0x25 => self.dec(Reg8::H), 0x26 => { let byte = self.ld_immediate_byte(); self.reg.set_8(Reg8::H, byte); + 2 } 0x27 => { let mut a = self.reg.get_8(Reg8::A); @@ -118,453 +207,821 @@ impl CPU { self.set_or_clear_flag(Flags::Zero, a == 0); self.clear_flag(Flags::HalfCarry); self.reg.set_8(Reg8::A, a); + 1 } 0x28 => { let jump = as_signed(self.ld_immediate_byte()); if self.is_flag(Flags::Zero) { self.jr(jump); + 3 + } else { + 2 } } - 0x29 => self.reg.hl = self.add_u16s(self.reg.hl, self.reg.hl), + 0x29 => { + self.reg.hl = self.add_u16s(self.reg.hl, self.reg.hl); + 2 + } 0x2A => { self.reg.set_8(Reg8::A, self.memory.get(self.reg.hl)); self.reg.hl = self.inc_pair(self.reg.hl); + 2 + } + 0x2B => { + self.reg.hl = self.dec_pair(self.reg.hl); + 2 + } + 0x2C => { + self.inc(Reg8::L); + 1 + } + 0x2D => { + self.dec(Reg8::L); + 1 } - 0x2B => self.reg.hl = self.dec_pair(self.reg.hl), - 0x2C => self.inc(Reg8::L), - 0x2D => self.dec(Reg8::L), 0x2E => { let byte = self.ld_immediate_byte(); self.reg.set_8(Reg8::L, byte); + 2 } 0x2F => { let val = !self.reg.get_8(Reg8::A); self.reg.set_8(Reg8::A, val); self.set_flag(Flags::NSubtract); self.set_flag(Flags::HalfCarry); + 1 } 0x30 => { let jump = as_signed(self.ld_immediate_byte()); if !self.is_flag(Flags::Carry) { self.jr(jump); + 3 + } else { + 2 } } - 0x31 => self.reg.sp = self.ld_immediate_word(), + 0x31 => { + self.reg.sp = self.ld_immediate_word(); + 3 + } 0x32 => { self.memory.set(self.reg.hl, self.reg.get_8(Reg8::A)); self.reg.hl = self.dec_pair(self.reg.hl); + 2 + } + 0x33 => { + self.reg.sp = self.inc_pair(self.reg.sp); + 2 } - 0x33 => self.reg.sp = self.inc_pair(self.reg.sp), 0x34 => { let val = self.inc_raw(self.memory.get(self.reg.hl)); self.memory.set(self.reg.hl, val); + 3 } 0x35 => { let val = self.dec_raw(self.memory.get(self.reg.hl)); self.memory.set(self.reg.hl, val); + 3 } 0x36 => { let byte = self.ld_immediate_byte(); self.memory.set(self.reg.hl, byte); + 3 } 0x37 => { self.clear_flag(Flags::NSubtract); self.clear_flag(Flags::HalfCarry); self.set_flag(Flags::Carry); + 1 } 0x38 => { let jump = as_signed(self.ld_immediate_byte()); if self.is_flag(Flags::Carry) { self.jr(jump); + 3 + } else { + 2 } } - 0x39 => self.reg.hl = self.add_u16s(self.reg.hl, self.reg.sp), + 0x39 => { + self.reg.hl = self.add_u16s(self.reg.hl, self.reg.sp); + 2 + } 0x3A => { self.reg.set_8(Reg8::A, self.memory.get(self.reg.hl)); self.reg.hl = self.dec_pair(self.reg.hl); + 2 + } + 0x3B => { + self.reg.sp = self.dec_pair(self.reg.sp); + 2 + } + 0x3C => { + self.inc(Reg8::A); + 1 + } + 0x3D => { + self.dec(Reg8::A); + 1 } - 0x3B => self.reg.sp = self.dec_pair(self.reg.sp), - 0x3C => self.inc(Reg8::A), - 0x3D => self.dec(Reg8::A), 0x3E => { let byte = self.ld_immediate_byte(); self.reg.set_8(Reg8::A, byte); + 2 } 0x3F => { self.clear_flag(Flags::NSubtract); self.clear_flag(Flags::HalfCarry); self.set_or_clear_flag(Flags::Carry, !self.is_flag(Flags::Carry)); + 1 + } + 0x40 => { + self.reg.set_8(Reg8::B, self.reg.get_8(Reg8::B)); + 1 + } + 0x41 => { + self.reg.set_8(Reg8::B, self.reg.get_8(Reg8::C)); + 1 + } + 0x42 => { + self.reg.set_8(Reg8::B, self.reg.get_8(Reg8::D)); + 1 + } + 0x43 => { + self.reg.set_8(Reg8::B, self.reg.get_8(Reg8::E)); + 1 + } + 0x44 => { + self.reg.set_8(Reg8::B, self.reg.get_8(Reg8::H)); + 1 + } + 0x45 => { + self.reg.set_8(Reg8::B, self.reg.get_8(Reg8::L)); + 1 + } + 0x46 => { + self.reg.set_8(Reg8::B, self.memory.get(self.reg.hl)); + 1 + } + 0x47 => { + self.reg.set_8(Reg8::B, self.reg.get_8(Reg8::A)); + 1 + } + 0x48 => { + self.reg.set_8(Reg8::C, self.reg.get_8(Reg8::B)); + 1 + } + 0x49 => { + self.reg.set_8(Reg8::C, self.reg.get_8(Reg8::C)); + 1 + } + 0x4A => { + self.reg.set_8(Reg8::C, self.reg.get_8(Reg8::D)); + 1 + } + 0x4B => { + self.reg.set_8(Reg8::C, self.reg.get_8(Reg8::E)); + 1 + } + 0x4C => { + self.reg.set_8(Reg8::C, self.reg.get_8(Reg8::H)); + 1 + } + 0x4D => { + self.reg.set_8(Reg8::C, self.reg.get_8(Reg8::L)); + 1 + } + 0x4E => { + self.reg.set_8(Reg8::C, self.memory.get(self.reg.hl)); + 1 + } + 0x4F => { + self.reg.set_8(Reg8::C, self.reg.get_8(Reg8::A)); + 1 + } + 0x50 => { + self.reg.set_8(Reg8::D, self.reg.get_8(Reg8::B)); + 1 + } + 0x51 => { + self.reg.set_8(Reg8::D, self.reg.get_8(Reg8::C)); + 1 + } + 0x52 => { + self.reg.set_8(Reg8::D, self.reg.get_8(Reg8::D)); + 1 + } + 0x53 => { + self.reg.set_8(Reg8::D, self.reg.get_8(Reg8::E)); + 1 + } + 0x54 => { + self.reg.set_8(Reg8::D, self.reg.get_8(Reg8::H)); + 1 + } + 0x55 => { + self.reg.set_8(Reg8::D, self.reg.get_8(Reg8::L)); + 1 + } + 0x56 => { + self.reg.set_8(Reg8::D, self.memory.get(self.reg.hl)); + 1 + } + 0x57 => { + self.reg.set_8(Reg8::D, self.reg.get_8(Reg8::A)); + 1 + } + 0x58 => { + self.reg.set_8(Reg8::E, self.reg.get_8(Reg8::B)); + 1 + } + 0x59 => { + self.reg.set_8(Reg8::E, self.reg.get_8(Reg8::C)); + 1 + } + 0x5A => { + self.reg.set_8(Reg8::E, self.reg.get_8(Reg8::D)); + 1 + } + 0x5B => { + self.reg.set_8(Reg8::E, self.reg.get_8(Reg8::E)); + 1 + } + 0x5C => { + self.reg.set_8(Reg8::E, self.reg.get_8(Reg8::H)); + 1 + } + 0x5D => { + self.reg.set_8(Reg8::E, self.reg.get_8(Reg8::L)); + 1 + } + 0x5E => { + self.reg.set_8(Reg8::E, self.memory.get(self.reg.hl)); + 1 + } + 0x5F => { + self.reg.set_8(Reg8::E, self.reg.get_8(Reg8::A)); + 1 + } + 0x60 => { + self.reg.set_8(Reg8::H, self.reg.get_8(Reg8::B)); + 1 + } + 0x61 => { + self.reg.set_8(Reg8::H, self.reg.get_8(Reg8::C)); + 1 + } + 0x62 => { + self.reg.set_8(Reg8::H, self.reg.get_8(Reg8::D)); + 1 + } + 0x63 => { + self.reg.set_8(Reg8::H, self.reg.get_8(Reg8::E)); + 1 + } + 0x64 => { + self.reg.set_8(Reg8::H, self.reg.get_8(Reg8::H)); + 1 + } + 0x65 => { + self.reg.set_8(Reg8::H, self.reg.get_8(Reg8::L)); + 1 + } + 0x66 => { + self.reg.set_8(Reg8::H, self.memory.get(self.reg.hl)); + 1 + } + 0x67 => { + self.reg.set_8(Reg8::H, self.reg.get_8(Reg8::A)); + 1 + } + 0x68 => { + self.reg.set_8(Reg8::L, self.reg.get_8(Reg8::B)); + 1 + } + 0x69 => { + self.reg.set_8(Reg8::L, self.reg.get_8(Reg8::C)); + 1 + } + 0x6A => { + self.reg.set_8(Reg8::L, self.reg.get_8(Reg8::D)); + 1 + } + 0x6B => { + self.reg.set_8(Reg8::L, self.reg.get_8(Reg8::E)); + 1 + } + 0x6C => { + self.reg.set_8(Reg8::L, self.reg.get_8(Reg8::H)); + 1 + } + 0x6D => { + self.reg.set_8(Reg8::L, self.reg.get_8(Reg8::L)); + 1 + } + 0x6E => { + self.reg.set_8(Reg8::L, self.memory.get(self.reg.hl)); + 1 + } + 0x6F => { + self.reg.set_8(Reg8::L, self.reg.get_8(Reg8::A)); + 1 + } + 0x70 => { + self.memory.set(self.reg.hl, self.reg.get_8(Reg8::B)); + 2 + } + 0x71 => { + self.memory.set(self.reg.hl, self.reg.get_8(Reg8::C)); + 2 + } + 0x72 => { + self.memory.set(self.reg.hl, self.reg.get_8(Reg8::D)); + 2 + } + 0x73 => { + self.memory.set(self.reg.hl, self.reg.get_8(Reg8::E)); + 2 + } + 0x74 => { + self.memory.set(self.reg.hl, self.reg.get_8(Reg8::H)); + 2 + } + 0x75 => { + self.memory.set(self.reg.hl, self.reg.get_8(Reg8::L)); + 2 + } + 0x76 => { + panic!("halt") + } + 0x77 => { + self.memory.set(self.reg.hl, self.reg.get_8(Reg8::A)); + 2 + } + 0x78 => { + self.reg.set_8(Reg8::A, self.reg.get_8(Reg8::B)); + 1 + } + 0x79 => { + self.reg.set_8(Reg8::A, self.reg.get_8(Reg8::C)); + 1 + } + 0x7A => { + self.reg.set_8(Reg8::A, self.reg.get_8(Reg8::D)); + 1 + } + 0x7B => { + self.reg.set_8(Reg8::A, self.reg.get_8(Reg8::E)); + 1 + } + 0x7C => { + self.reg.set_8(Reg8::A, self.reg.get_8(Reg8::H)); + 1 + } + 0x7D => { + self.reg.set_8(Reg8::A, self.reg.get_8(Reg8::L)); + 1 + } + 0x7E => { + self.reg.set_8(Reg8::A, self.memory.get(self.reg.hl)); + 1 + } + 0x7F => { + self.reg.set_8(Reg8::A, self.reg.get_8(Reg8::A)); + 1 } - 0x40 => self.reg.set_8(Reg8::B, self.reg.get_8(Reg8::B)), - 0x41 => self.reg.set_8(Reg8::B, self.reg.get_8(Reg8::C)), - 0x42 => self.reg.set_8(Reg8::B, self.reg.get_8(Reg8::D)), - 0x43 => self.reg.set_8(Reg8::B, self.reg.get_8(Reg8::E)), - 0x44 => self.reg.set_8(Reg8::B, self.reg.get_8(Reg8::H)), - 0x45 => self.reg.set_8(Reg8::B, self.reg.get_8(Reg8::L)), - 0x46 => self.reg.set_8(Reg8::B, self.memory.get(self.reg.hl)), - 0x47 => self.reg.set_8(Reg8::B, self.reg.get_8(Reg8::A)), - 0x48 => self.reg.set_8(Reg8::C, self.reg.get_8(Reg8::B)), - 0x49 => self.reg.set_8(Reg8::C, self.reg.get_8(Reg8::C)), - 0x4A => self.reg.set_8(Reg8::C, self.reg.get_8(Reg8::D)), - 0x4B => self.reg.set_8(Reg8::C, self.reg.get_8(Reg8::E)), - 0x4C => self.reg.set_8(Reg8::C, self.reg.get_8(Reg8::H)), - 0x4D => self.reg.set_8(Reg8::C, self.reg.get_8(Reg8::L)), - 0x4E => self.reg.set_8(Reg8::C, self.memory.get(self.reg.hl)), - 0x4F => self.reg.set_8(Reg8::C, self.reg.get_8(Reg8::A)), - 0x50 => self.reg.set_8(Reg8::D, self.reg.get_8(Reg8::B)), - 0x51 => self.reg.set_8(Reg8::D, self.reg.get_8(Reg8::C)), - 0x52 => self.reg.set_8(Reg8::D, self.reg.get_8(Reg8::D)), - 0x53 => self.reg.set_8(Reg8::D, self.reg.get_8(Reg8::E)), - 0x54 => self.reg.set_8(Reg8::D, self.reg.get_8(Reg8::H)), - 0x55 => self.reg.set_8(Reg8::D, self.reg.get_8(Reg8::L)), - 0x56 => self.reg.set_8(Reg8::D, self.memory.get(self.reg.hl)), - 0x57 => self.reg.set_8(Reg8::D, self.reg.get_8(Reg8::A)), - 0x58 => self.reg.set_8(Reg8::E, self.reg.get_8(Reg8::B)), - 0x59 => self.reg.set_8(Reg8::E, self.reg.get_8(Reg8::C)), - 0x5A => self.reg.set_8(Reg8::E, self.reg.get_8(Reg8::D)), - 0x5B => self.reg.set_8(Reg8::E, self.reg.get_8(Reg8::E)), - 0x5C => self.reg.set_8(Reg8::E, self.reg.get_8(Reg8::H)), - 0x5D => self.reg.set_8(Reg8::E, self.reg.get_8(Reg8::L)), - 0x5E => self.reg.set_8(Reg8::E, self.memory.get(self.reg.hl)), - 0x5F => self.reg.set_8(Reg8::E, self.reg.get_8(Reg8::A)), - 0x60 => self.reg.set_8(Reg8::H, self.reg.get_8(Reg8::B)), - 0x61 => self.reg.set_8(Reg8::H, self.reg.get_8(Reg8::C)), - 0x62 => self.reg.set_8(Reg8::H, self.reg.get_8(Reg8::D)), - 0x63 => self.reg.set_8(Reg8::H, self.reg.get_8(Reg8::E)), - 0x64 => self.reg.set_8(Reg8::H, self.reg.get_8(Reg8::H)), - 0x65 => self.reg.set_8(Reg8::H, self.reg.get_8(Reg8::L)), - 0x66 => self.reg.set_8(Reg8::H, self.memory.get(self.reg.hl)), - 0x67 => self.reg.set_8(Reg8::H, self.reg.get_8(Reg8::A)), - 0x68 => self.reg.set_8(Reg8::L, self.reg.get_8(Reg8::B)), - 0x69 => self.reg.set_8(Reg8::L, self.reg.get_8(Reg8::C)), - 0x6A => self.reg.set_8(Reg8::L, self.reg.get_8(Reg8::D)), - 0x6B => self.reg.set_8(Reg8::L, self.reg.get_8(Reg8::E)), - 0x6C => self.reg.set_8(Reg8::L, self.reg.get_8(Reg8::H)), - 0x6D => self.reg.set_8(Reg8::L, self.reg.get_8(Reg8::L)), - 0x6E => self.reg.set_8(Reg8::L, self.memory.get(self.reg.hl)), - 0x6F => self.reg.set_8(Reg8::L, self.reg.get_8(Reg8::A)), - 0x70 => self.memory.set(self.reg.hl, self.reg.get_8(Reg8::B)), - 0x71 => self.memory.set(self.reg.hl, self.reg.get_8(Reg8::C)), - 0x72 => self.memory.set(self.reg.hl, self.reg.get_8(Reg8::D)), - 0x73 => self.memory.set(self.reg.hl, self.reg.get_8(Reg8::E)), - 0x74 => self.memory.set(self.reg.hl, self.reg.get_8(Reg8::H)), - 0x75 => self.memory.set(self.reg.hl, self.reg.get_8(Reg8::L)), - 0x76 => panic!("halt"), - 0x77 => self.memory.set(self.reg.hl, self.reg.get_8(Reg8::A)), - 0x78 => self.reg.set_8(Reg8::A, self.reg.get_8(Reg8::B)), - 0x79 => self.reg.set_8(Reg8::A, self.reg.get_8(Reg8::C)), - 0x7A => self.reg.set_8(Reg8::A, self.reg.get_8(Reg8::D)), - 0x7B => self.reg.set_8(Reg8::A, self.reg.get_8(Reg8::E)), - 0x7C => self.reg.set_8(Reg8::A, self.reg.get_8(Reg8::H)), - 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); + 1 } 0x81 => { let val = self.add(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C)); self.reg.set_8(Reg8::A, val); + 1 } 0x82 => { let val = self.add(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D)); self.reg.set_8(Reg8::A, val); + 1 } 0x83 => { let val = self.add(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E)); self.reg.set_8(Reg8::A, val); + 1 } 0x84 => { let val = self.add(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H)); self.reg.set_8(Reg8::A, val); + 1 } 0x85 => { let val = self.add(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L)); self.reg.set_8(Reg8::A, val); + 1 } 0x86 => { let val = self.add(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl)); self.reg.set_8(Reg8::A, val); + 2 } 0x87 => { let val = self.add(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A)); self.reg.set_8(Reg8::A, val); + 1 } 0x88 => { let val = self.adc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::B)); self.reg.set_8(Reg8::A, val); + 1 } 0x89 => { let val = self.adc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C)); self.reg.set_8(Reg8::A, val); + 1 } 0x8A => { let val = self.adc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D)); self.reg.set_8(Reg8::A, val); + 1 } 0x8B => { let val = self.adc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E)); self.reg.set_8(Reg8::A, val); + 1 } 0x8C => { let val = self.adc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H)); self.reg.set_8(Reg8::A, val); + 1 } 0x8D => { let val = self.adc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L)); self.reg.set_8(Reg8::A, val); + 1 } 0x8E => { let val = self.adc(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl)); self.reg.set_8(Reg8::A, val); + 2 } 0x8F => { let val = self.adc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A)); self.reg.set_8(Reg8::A, val); + 1 } 0x90 => { let val = self.sub(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::B)); self.reg.set_8(Reg8::A, val); + 1 } 0x91 => { let val = self.sub(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C)); self.reg.set_8(Reg8::A, val); + 1 } 0x92 => { let val = self.sub(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D)); self.reg.set_8(Reg8::A, val); + 1 } 0x93 => { let val = self.sub(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E)); self.reg.set_8(Reg8::A, val); + 1 } 0x94 => { let val = self.sub(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H)); self.reg.set_8(Reg8::A, val); + 1 } 0x95 => { let val = self.sub(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L)); self.reg.set_8(Reg8::A, val); + 1 } 0x96 => { let val = self.sub(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl)); self.reg.set_8(Reg8::A, val); + 2 } 0x97 => { let val = self.sub(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A)); self.reg.set_8(Reg8::A, val); + 1 } 0x98 => { let val = self.sbc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::B)); self.reg.set_8(Reg8::A, val); + 1 } 0x99 => { let val = self.sbc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C)); self.reg.set_8(Reg8::A, val); + 1 } 0x9A => { let val = self.sbc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D)); self.reg.set_8(Reg8::A, val); + 1 } 0x9B => { let val = self.sbc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E)); self.reg.set_8(Reg8::A, val); + 1 } 0x9C => { let val = self.sbc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H)); self.reg.set_8(Reg8::A, val); + 1 } 0x9D => { let val = self.sbc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L)); self.reg.set_8(Reg8::A, val); + 1 } 0x9E => { let val = self.sbc(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl)); self.reg.set_8(Reg8::A, val); + 2 } 0x9F => { let val = self.sbc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A)); self.reg.set_8(Reg8::A, val); + 1 } 0xA0 => { let val = self.and(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::B)); self.reg.set_8(Reg8::A, val); + 1 } 0xA1 => { let val = self.and(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C)); self.reg.set_8(Reg8::A, val); + 1 } 0xA2 => { let val = self.and(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D)); self.reg.set_8(Reg8::A, val); + 1 } 0xA3 => { let val = self.and(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E)); self.reg.set_8(Reg8::A, val); + 1 } 0xA4 => { let val = self.and(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H)); self.reg.set_8(Reg8::A, val); + 1 } 0xA5 => { let val = self.and(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L)); self.reg.set_8(Reg8::A, val); + 1 } 0xA6 => { let val = self.and(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl)); self.reg.set_8(Reg8::A, val); + 2 } 0xA7 => { let val = self.and(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A)); self.reg.set_8(Reg8::A, val); + 1 } 0xA8 => { let val = self.xor(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::B)); self.reg.set_8(Reg8::A, val); + 1 } 0xA9 => { let val = self.xor(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C)); self.reg.set_8(Reg8::A, val); + 1 } 0xAA => { let val = self.xor(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D)); self.reg.set_8(Reg8::A, val); + 1 } 0xAB => { let val = self.xor(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E)); self.reg.set_8(Reg8::A, val); + 1 } 0xAC => { let val = self.xor(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H)); self.reg.set_8(Reg8::A, val); + 1 } 0xAD => { let val = self.xor(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L)); self.reg.set_8(Reg8::A, val); + 1 } 0xAE => { let val = self.xor(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl)); self.reg.set_8(Reg8::A, val); + 2 } 0xAF => { let val = self.xor(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A)); self.reg.set_8(Reg8::A, val); + 1 } 0xB0 => { let val = self.or(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::B)); self.reg.set_8(Reg8::A, val); + 1 } 0xB1 => { let val = self.or(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C)); self.reg.set_8(Reg8::A, val); + 1 } 0xB2 => { let val = self.or(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D)); self.reg.set_8(Reg8::A, val); + 1 } 0xB3 => { let val = self.or(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E)); self.reg.set_8(Reg8::A, val); + 1 } 0xB4 => { let val = self.or(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H)); self.reg.set_8(Reg8::A, val); + 1 } 0xB5 => { let val = self.or(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L)); self.reg.set_8(Reg8::A, val); + 1 } 0xB6 => { let val = self.or(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl)); self.reg.set_8(Reg8::A, val); + 2 } 0xB7 => { let val = self.or(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A)); self.reg.set_8(Reg8::A, val); + 1 + } + 0xB8 => { + self.cp(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::B)); + 1 + } + 0xB9 => { + self.cp(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C)); + 1 + } + 0xBA => { + self.cp(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D)); + 1 + } + 0xBB => { + self.cp(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E)); + 1 + } + 0xBC => { + self.cp(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H)); + 1 + } + 0xBD => { + self.cp(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L)); + 1 + } + 0xBE => { + self.cp(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl)); + 2 + } + 0xBF => { + self.cp(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A)); + 1 } - 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)), 0xC0 => { if !self.is_flag(Flags::Zero) { self.ret(); + 5 + } else { + 2 } } - 0xC1 => self.reg.bc = self.pop_word(), + 0xC1 => { + self.reg.bc = self.pop_word(); + 3 + } 0xC2 => { let jump = self.ld_immediate_word(); if !self.is_flag(Flags::Zero) { self.reg.pc = jump; + 4 + } else { + 3 } } 0xC3 => { let jump = self.ld_immediate_word(); self.reg.pc = jump; + 4 } 0xC4 => { let pc = self.ld_immediate_word(); if !self.is_flag(Flags::Zero) { self.push(self.reg.pc); self.reg.pc = pc; + 6 + } else { + 3 } } - 0xC5 => self.push(self.reg.bc), + 0xC5 => { + self.push(self.reg.bc); + 4 + } 0xC6 => { let byte = self.ld_immediate_byte(); let val = self.add_u8s(self.reg.get_8(Reg8::A), byte); self.reg.set_8(Reg8::A, val); + 2 + } + 0xC7 => { + self.rst(0x0); + 1 } - 0xC7 => self.rst(0x0), 0xC8 => { if self.is_flag(Flags::Zero) { self.ret(); + 5 + } else { + 2 } } - 0xC9 => self.ret(), + 0xC9 => { + self.ret(); + 4 + } 0xCA => { let jump = self.ld_immediate_word(); if self.is_flag(Flags::Zero) { self.reg.pc = jump; + 4 + } else { + 3 } } 0xCB => { let subop = self.ld_immediate_byte(); - self.cb_subop(subop); + self.cb_subop(subop) } 0xCC => { let pc = self.ld_immediate_word(); if self.is_flag(Flags::Zero) { self.push(self.reg.pc); self.reg.pc = pc; + 6 + } else { + 3 } } 0xCD => { let pc = self.ld_immediate_word(); self.push(self.reg.pc); self.reg.pc = pc; + 6 } 0xCE => { let byte = self.ld_immediate_byte(); let val = self.adc(self.reg.get_8(Reg8::A), byte); self.reg.set_8(Reg8::A, val); + 2 + } + 0xCF => { + self.rst(0x08); + 4 } - 0xCF => self.rst(0x08), 0xD0 => { if !self.is_flag(Flags::Carry) { self.ret(); + 5 + } else { + 2 } } - 0xD1 => self.reg.de = self.pop_word(), + 0xD1 => { + self.reg.de = self.pop_word(); + 3 + } 0xD2 => { let jump = self.ld_immediate_word(); if !self.is_flag(Flags::Carry) { self.reg.pc = jump; + 4 + } else { + 3 } } 0xD4 => { @@ -572,28 +1029,45 @@ impl CPU { if !self.is_flag(Flags::Carry) { self.push(self.reg.pc); self.reg.pc = pc; + 6 + } else { + 3 } } - 0xD5 => self.push(self.reg.de), + 0xD5 => { + self.push(self.reg.de); + 4 + } 0xD6 => { let byte = self.ld_immediate_byte(); let val = self.sub_u8s(self.reg.get_8(Reg8::A), byte); self.reg.set_8(Reg8::A, val); + 2 + } + 0xD7 => { + self.rst(0x10); + 4 } - 0xD7 => self.rst(0x10), 0xD8 => { if self.is_flag(Flags::Carry) { self.ret(); + 5 + } else { + 2 } } 0xD9 => { self.ret(); self.memory.ime = true; + 4 } 0xDA => { let jump = self.ld_immediate_word(); if self.is_flag(Flags::Carry) { self.reg.pc = jump; + 4 + } else { + 3 } } 0xDC => { @@ -601,941 +1075,1369 @@ impl CPU { if self.is_flag(Flags::Carry) { self.push(self.reg.pc); self.reg.pc = pc; + 6 + } else { + 3 } } 0xDE => { let byte = self.ld_immediate_byte(); let val = self.sbc(self.reg.get_8(Reg8::A), byte); self.reg.set_8(Reg8::A, val); + 2 + } + 0xDF => { + self.rst(0x18); + 4 } - 0xDF => self.rst(0x18), 0xE0 => { let mut addr: u16 = 0x0; addr.set_high(0xFF); addr.set_low(self.ld_immediate_byte()); self.memory.set(addr, self.reg.get_8(Reg8::A)); + 3 + } + 0xE1 => { + self.reg.hl = self.pop_word(); + 3 } - 0xE1 => self.reg.hl = self.pop_word(), 0xE2 => { let mut addr: u16 = 0x0; addr.set_high(0xFF); addr.set_low(self.reg.get_8(Reg8::C)); self.memory.set(addr, self.reg.get_8(Reg8::A)); + 2 + } + 0xE5 => { + self.push(self.reg.hl); + 4 } - 0xE5 => self.push(self.reg.hl), 0xE6 => { let byte = self.ld_immediate_byte(); let val = self.and(self.reg.get_8(Reg8::A), byte); self.reg.set_8(Reg8::A, val); + 2 + } + 0xE7 => { + self.rst(0x20); + 4 } - 0xE7 => self.rst(0x20), 0xE8 => { let v = as_signed(self.ld_immediate_byte()); self.reg.sp = self.sp_add(self.reg.sp, v); + 4 } 0xE9 => { self.reg.pc = self.reg.hl; + 1 } 0xEA => { let addr = self.ld_immediate_word(); self.memory.set(addr, self.reg.get_8(Reg8::A)); + 4 } 0xEE => { let byte = self.ld_immediate_byte(); let val = self.xor(self.reg.get_8(Reg8::A), byte); self.reg.set_8(Reg8::A, val); + 2 + } + 0xEF => { + self.rst(0x28); + 4 } - 0xEF => self.rst(0x28), 0xF0 => { let mut addr: u16 = 0x0; addr.set_high(0xFF); addr.set_low(self.ld_immediate_byte()); self.reg.set_8(Reg8::A, self.memory.get(addr)); + 3 + } + 0xF1 => { + self.reg.af = self.pop_word() & 0xF0; + 3 } - 0xF1 => self.reg.af = self.pop_word() & 0xF0, 0xF2 => { let mut addr: u16 = 0x0; addr.set_high(0xFF); addr.set_low(self.reg.get_8(Reg8::C)); self.reg.set_8(Reg8::A, self.memory.get(addr)); + 2 } 0xF3 => { self.memory.ime = false; self.memory.ime_scheduled = 0; + 1 + } + 0xF5 => { + self.push(self.reg.af); + 4 } - 0xF5 => self.push(self.reg.af), 0xF6 => { let byte = self.ld_immediate_byte(); let val = self.or(self.reg.get_8(Reg8::A), byte); self.reg.set_8(Reg8::A, val); + 2 + } + 0xF7 => { + self.rst(0x30); + 4 } - 0xF7 => self.rst(0x30), 0xF8 => { let v = as_signed(self.ld_immediate_byte()); self.reg.hl = self.sp_add(self.reg.sp, v); + 3 } 0xF9 => { self.reg.sp = self.reg.hl; + 2 } 0xFA => { let addr = self.ld_immediate_word(); self.reg.set_8(Reg8::A, self.memory.get(addr)); + 4 + } + 0xFB => { + self.memory.ime_scheduled = 2; + 1 } - 0xFB => self.memory.ime_scheduled = 2, 0xFE => { let byte = self.ld_immediate_byte(); self.cp(self.reg.get_8(Reg8::A), byte); + 2 + } + 0xFF => { + self.rst(0x38); + 4 } - 0xFF => self.rst(0x38), 0xD3 | 0xDB | 0xDD | 0xE3 | 0xE4 | 0xEB | 0xEC | 0xED | 0xF4 | 0xFC | 0xFD => { undefined(opcode) } } } - fn cb_subop(&mut self, subop: u8) { + fn cb_subop(&mut self, subop: u8) -> u8 { match subop { 0x00 => { let val = self.rlc(self.reg.get_8(Reg8::B)); self.reg.set_8(Reg8::B, val); + 2 } 0x01 => { let val = self.rlc(self.reg.get_8(Reg8::C)); self.reg.set_8(Reg8::C, val); + 2 } 0x02 => { let val = self.rlc(self.reg.get_8(Reg8::D)); self.reg.set_8(Reg8::D, val); + 2 } 0x03 => { let val = self.rlc(self.reg.get_8(Reg8::E)); self.reg.set_8(Reg8::E, val); + 2 } 0x04 => { let val = self.rlc(self.reg.get_8(Reg8::H)); self.reg.set_8(Reg8::H, val); + 2 } 0x05 => { let val = self.rlc(self.reg.get_8(Reg8::L)); self.reg.set_8(Reg8::L, val); + 2 } 0x06 => { let val = self.rlc(self.memory.get(self.reg.hl)); self.memory.set(self.reg.hl, val); + 4 } 0x07 => { let val = self.rlc(self.reg.get_8(Reg8::A)); self.reg.set_8(Reg8::A, val); + 2 } 0x08 => { let val = self.rrc(self.reg.get_8(Reg8::B)); self.reg.set_8(Reg8::B, val); + 2 } 0x09 => { let val = self.rrc(self.reg.get_8(Reg8::C)); self.reg.set_8(Reg8::C, val); + 2 } 0x0A => { let val = self.rrc(self.reg.get_8(Reg8::D)); self.reg.set_8(Reg8::D, val); + 2 } 0x0B => { let val = self.rrc(self.reg.get_8(Reg8::E)); self.reg.set_8(Reg8::E, val); + 2 } 0x0C => { let val = self.rrc(self.reg.get_8(Reg8::H)); self.reg.set_8(Reg8::H, val); + 2 } 0x0D => { let val = self.rrc(self.reg.get_8(Reg8::L)); self.reg.set_8(Reg8::L, val); + 2 } 0x0E => { let val = self.rrc(self.memory.get(self.reg.hl)); self.memory.set(self.reg.hl, val); + 4 } 0x0F => { let val = self.rrc(self.reg.get_8(Reg8::A)); self.reg.set_8(Reg8::A, val); + 2 } 0x10 => { let val = self.rl(self.reg.get_8(Reg8::B)); self.reg.set_8(Reg8::B, val); + 2 } 0x11 => { let val = self.rl(self.reg.get_8(Reg8::C)); self.reg.set_8(Reg8::C, val); + 2 } 0x12 => { let val = self.rl(self.reg.get_8(Reg8::D)); self.reg.set_8(Reg8::D, val); + 2 } 0x13 => { let val = self.rl(self.reg.get_8(Reg8::E)); self.reg.set_8(Reg8::E, val); + 2 } 0x14 => { let val = self.rl(self.reg.get_8(Reg8::H)); self.reg.set_8(Reg8::H, val); + 2 } 0x15 => { let val = self.rl(self.reg.get_8(Reg8::L)); self.reg.set_8(Reg8::L, val); + 2 } 0x16 => { let val = self.rl(self.memory.get(self.reg.hl)); self.memory.set(self.reg.hl, val); + 4 } 0x17 => { let val = self.rl(self.reg.get_8(Reg8::A)); self.reg.set_8(Reg8::A, val); + 2 } 0x18 => { let val = self.rr(self.reg.get_8(Reg8::B)); self.reg.set_8(Reg8::B, val); + 2 } 0x19 => { let val = self.rr(self.reg.get_8(Reg8::C)); self.reg.set_8(Reg8::C, val); + 2 } 0x1A => { let val = self.rr(self.reg.get_8(Reg8::D)); self.reg.set_8(Reg8::D, val); + 2 } 0x1B => { let val = self.rr(self.reg.get_8(Reg8::E)); self.reg.set_8(Reg8::E, val); + 2 } 0x1C => { let val = self.rr(self.reg.get_8(Reg8::H)); self.reg.set_8(Reg8::H, val); + 2 } 0x1D => { let val = self.rr(self.reg.get_8(Reg8::L)); self.reg.set_8(Reg8::L, val); + 2 } 0x1E => { let val = self.rr(self.memory.get(self.reg.hl)); self.memory.set(self.reg.hl, val); + 4 } 0x1F => { let val = self.rr(self.reg.get_8(Reg8::A)); self.reg.set_8(Reg8::A, val); + 2 } 0x20 => { let val = self.sla(self.reg.get_8(Reg8::B)); self.reg.set_8(Reg8::B, val); + 2 } 0x21 => { let val = self.sla(self.reg.get_8(Reg8::C)); self.reg.set_8(Reg8::C, val); + 2 } 0x22 => { let val = self.sla(self.reg.get_8(Reg8::D)); self.reg.set_8(Reg8::D, val); + 2 } 0x23 => { let val = self.sla(self.reg.get_8(Reg8::E)); self.reg.set_8(Reg8::E, val); + 2 } 0x24 => { let val = self.sla(self.reg.get_8(Reg8::H)); self.reg.set_8(Reg8::H, val); + 2 } 0x25 => { let val = self.sla(self.reg.get_8(Reg8::L)); self.reg.set_8(Reg8::L, val); + 2 } 0x26 => { let val = self.sla(self.memory.get(self.reg.hl)); self.memory.set(self.reg.hl, val); + 4 } 0x27 => { let val = self.sla(self.reg.get_8(Reg8::A)); self.reg.set_8(Reg8::A, val); + 2 } 0x28 => { let val = self.sra(self.reg.get_8(Reg8::B)); self.reg.set_8(Reg8::B, val); + 2 } 0x29 => { let val = self.sra(self.reg.get_8(Reg8::C)); self.reg.set_8(Reg8::C, val); + 2 } 0x2A => { let val = self.sra(self.reg.get_8(Reg8::D)); self.reg.set_8(Reg8::D, val); + 2 } 0x2B => { let val = self.sra(self.reg.get_8(Reg8::E)); self.reg.set_8(Reg8::E, val); + 2 } 0x2C => { let val = self.sra(self.reg.get_8(Reg8::H)); self.reg.set_8(Reg8::H, val); + 2 } 0x2D => { let val = self.sra(self.reg.get_8(Reg8::L)); self.reg.set_8(Reg8::L, val); + 2 } 0x2E => { let val = self.sra(self.memory.get(self.reg.hl)); self.memory.set(self.reg.hl, val); + 4 } 0x2F => { let val = self.sra(self.reg.get_8(Reg8::A)); self.reg.set_8(Reg8::A, val); + 2 } 0x30 => { let val = self.swap(self.reg.get_8(Reg8::B)); self.reg.set_8(Reg8::B, val); + 2 } 0x31 => { let val = self.swap(self.reg.get_8(Reg8::C)); self.reg.set_8(Reg8::C, val); + 2 } 0x32 => { let val = self.swap(self.reg.get_8(Reg8::D)); self.reg.set_8(Reg8::D, val); + 2 } 0x33 => { let val = self.swap(self.reg.get_8(Reg8::E)); self.reg.set_8(Reg8::E, val); + 2 } 0x34 => { let val = self.swap(self.reg.get_8(Reg8::H)); self.reg.set_8(Reg8::H, val); + 2 } 0x35 => { let val = self.swap(self.reg.get_8(Reg8::L)); self.reg.set_8(Reg8::L, val); + 2 } 0x36 => { let val = self.swap(self.memory.get(self.reg.hl)); self.memory.set(self.reg.hl, val); + 4 } 0x37 => { let val = self.swap(self.reg.get_8(Reg8::A)); self.reg.set_8(Reg8::A, val); + 2 } 0x38 => { let val = self.srl(self.reg.get_8(Reg8::B)); self.reg.set_8(Reg8::B, val); + 2 } 0x39 => { let val = self.srl(self.reg.get_8(Reg8::C)); self.reg.set_8(Reg8::C, val); + 2 } 0x3A => { let val = self.srl(self.reg.get_8(Reg8::D)); self.reg.set_8(Reg8::D, val); + 2 } 0x3B => { let val = self.srl(self.reg.get_8(Reg8::E)); self.reg.set_8(Reg8::E, val); + 2 } 0x3C => { let val = self.srl(self.reg.get_8(Reg8::H)); self.reg.set_8(Reg8::H, val); + 2 } 0x3D => { let val = self.srl(self.reg.get_8(Reg8::L)); self.reg.set_8(Reg8::L, val); + 2 } 0x3E => { let val = self.srl(self.memory.get(self.reg.hl)); self.memory.set(self.reg.hl, val); + 4 } 0x3F => { let val = self.srl(self.reg.get_8(Reg8::A)); self.reg.set_8(Reg8::A, val); + 2 + } + 0x40 => { + self.bit(self.reg.get_8(Reg8::B), 0); + 2 + } + 0x41 => { + self.bit(self.reg.get_8(Reg8::C), 0); + 2 + } + 0x42 => { + self.bit(self.reg.get_8(Reg8::D), 0); + 2 + } + 0x43 => { + self.bit(self.reg.get_8(Reg8::E), 0); + 2 + } + 0x44 => { + self.bit(self.reg.get_8(Reg8::H), 0); + 2 + } + 0x45 => { + self.bit(self.reg.get_8(Reg8::L), 0); + 2 + } + 0x46 => { + self.bit(self.memory.get(self.reg.hl), 0); + 3 + } + 0x47 => { + self.bit(self.reg.get_8(Reg8::A), 0); + 2 + } + 0x48 => { + self.bit(self.reg.get_8(Reg8::B), 1); + 2 + } + 0x49 => { + self.bit(self.reg.get_8(Reg8::C), 1); + 2 + } + 0x4A => { + self.bit(self.reg.get_8(Reg8::D), 1); + 2 + } + 0x4B => { + self.bit(self.reg.get_8(Reg8::E), 1); + 2 + } + 0x4C => { + self.bit(self.reg.get_8(Reg8::H), 1); + 2 + } + 0x4D => { + self.bit(self.reg.get_8(Reg8::L), 1); + 2 + } + 0x4E => { + self.bit(self.memory.get(self.reg.hl), 1); + 3 + } + 0x4F => { + self.bit(self.reg.get_8(Reg8::A), 1); + 2 + } + 0x50 => { + self.bit(self.reg.get_8(Reg8::B), 2); + 2 + } + 0x51 => { + self.bit(self.reg.get_8(Reg8::C), 2); + 2 + } + 0x52 => { + self.bit(self.reg.get_8(Reg8::D), 2); + 2 + } + 0x53 => { + self.bit(self.reg.get_8(Reg8::E), 2); + 2 + } + 0x54 => { + self.bit(self.reg.get_8(Reg8::H), 2); + 2 + } + 0x55 => { + self.bit(self.reg.get_8(Reg8::L), 2); + 2 + } + 0x56 => { + self.bit(self.memory.get(self.reg.hl), 2); + 3 + } + 0x57 => { + self.bit(self.reg.get_8(Reg8::A), 2); + 2 + } + 0x58 => { + self.bit(self.reg.get_8(Reg8::B), 3); + 2 + } + 0x59 => { + self.bit(self.reg.get_8(Reg8::C), 3); + 2 + } + 0x5A => { + self.bit(self.reg.get_8(Reg8::D), 3); + 2 + } + 0x5B => { + self.bit(self.reg.get_8(Reg8::E), 3); + 2 + } + 0x5C => { + self.bit(self.reg.get_8(Reg8::H), 3); + 2 + } + 0x5D => { + self.bit(self.reg.get_8(Reg8::L), 3); + 2 + } + 0x5E => { + self.bit(self.memory.get(self.reg.hl), 3); + 3 + } + 0x5F => { + self.bit(self.reg.get_8(Reg8::A), 3); + 2 + } + 0x60 => { + self.bit(self.reg.get_8(Reg8::B), 4); + 2 + } + 0x61 => { + self.bit(self.reg.get_8(Reg8::C), 4); + 2 + } + 0x62 => { + self.bit(self.reg.get_8(Reg8::D), 4); + 2 + } + 0x63 => { + self.bit(self.reg.get_8(Reg8::E), 4); + 2 + } + 0x64 => { + self.bit(self.reg.get_8(Reg8::H), 4); + 2 + } + 0x65 => { + self.bit(self.reg.get_8(Reg8::L), 4); + 2 + } + 0x66 => { + self.bit(self.memory.get(self.reg.hl), 4); + 3 + } + 0x67 => { + self.bit(self.reg.get_8(Reg8::A), 4); + 2 + } + 0x68 => { + self.bit(self.reg.get_8(Reg8::B), 5); + 2 + } + 0x69 => { + self.bit(self.reg.get_8(Reg8::C), 5); + 2 + } + 0x6A => { + self.bit(self.reg.get_8(Reg8::D), 5); + 2 + } + 0x6B => { + self.bit(self.reg.get_8(Reg8::E), 5); + 2 + } + 0x6C => { + self.bit(self.reg.get_8(Reg8::H), 5); + 2 + } + 0x6D => { + self.bit(self.reg.get_8(Reg8::L), 5); + 2 + } + 0x6E => { + self.bit(self.memory.get(self.reg.hl), 5); + 3 + } + 0x6F => { + self.bit(self.reg.get_8(Reg8::A), 5); + 2 + } + 0x70 => { + self.bit(self.reg.get_8(Reg8::B), 6); + 2 + } + 0x71 => { + self.bit(self.reg.get_8(Reg8::C), 6); + 2 + } + 0x72 => { + self.bit(self.reg.get_8(Reg8::D), 6); + 2 + } + 0x73 => { + self.bit(self.reg.get_8(Reg8::E), 6); + 2 + } + 0x74 => { + self.bit(self.reg.get_8(Reg8::H), 6); + 2 + } + 0x75 => { + self.bit(self.reg.get_8(Reg8::L), 6); + 2 + } + 0x76 => { + self.bit(self.memory.get(self.reg.hl), 6); + 3 + } + 0x77 => { + self.bit(self.reg.get_8(Reg8::A), 6); + 2 + } + 0x78 => { + self.bit(self.reg.get_8(Reg8::B), 7); + 2 + } + 0x79 => { + self.bit(self.reg.get_8(Reg8::C), 7); + 2 + } + 0x7A => { + self.bit(self.reg.get_8(Reg8::D), 7); + 2 + } + 0x7B => { + self.bit(self.reg.get_8(Reg8::E), 7); + 2 + } + 0x7C => { + self.bit(self.reg.get_8(Reg8::H), 7); + 2 + } + 0x7D => { + self.bit(self.reg.get_8(Reg8::L), 7); + 2 + } + 0x7E => { + self.bit(self.memory.get(self.reg.hl), 7); + 3 + } + 0x7F => { + self.bit(self.reg.get_8(Reg8::A), 7); + 2 } - 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); + 2 } 0x81 => { let val = res(self.reg.get_8(Reg8::C), 0); self.reg.set_8(Reg8::C, val); + 2 } 0x82 => { let val = res(self.reg.get_8(Reg8::D), 0); self.reg.set_8(Reg8::D, val); + 2 } 0x83 => { let val = res(self.reg.get_8(Reg8::E), 0); self.reg.set_8(Reg8::E, val); + 2 } 0x84 => { let val = res(self.reg.get_8(Reg8::H), 0); self.reg.set_8(Reg8::H, val); + 2 } 0x85 => { let val = res(self.reg.get_8(Reg8::L), 0); self.reg.set_8(Reg8::L, val); + 2 } 0x86 => { let val = res(self.memory.get(self.reg.hl), 0); self.memory.set(self.reg.hl, val); + 4 } 0x87 => { let val = res(self.reg.get_8(Reg8::A), 0); self.reg.set_8(Reg8::A, val); + 2 } 0x88 => { let val = res(self.reg.get_8(Reg8::B), 1); self.reg.set_8(Reg8::B, val); + 2 } 0x89 => { let val = res(self.reg.get_8(Reg8::C), 1); self.reg.set_8(Reg8::C, val); + 2 } 0x8A => { let val = res(self.reg.get_8(Reg8::D), 1); self.reg.set_8(Reg8::D, val); + 2 } 0x8B => { let val = res(self.reg.get_8(Reg8::E), 1); self.reg.set_8(Reg8::E, val); + 2 } 0x8C => { let val = res(self.reg.get_8(Reg8::H), 1); self.reg.set_8(Reg8::H, val); + 2 } 0x8D => { let val = res(self.reg.get_8(Reg8::L), 1); self.reg.set_8(Reg8::L, val); + 2 } 0x8E => { let val = res(self.memory.get(self.reg.hl), 1); self.memory.set(self.reg.hl, val); + 4 } 0x8F => { let val = res(self.reg.get_8(Reg8::A), 1); self.reg.set_8(Reg8::A, val); + 2 } 0x90 => { let val = res(self.reg.get_8(Reg8::B), 2); self.reg.set_8(Reg8::B, val); + 2 } 0x91 => { let val = res(self.reg.get_8(Reg8::C), 2); self.reg.set_8(Reg8::C, val); + 2 } 0x92 => { let val = res(self.reg.get_8(Reg8::D), 2); self.reg.set_8(Reg8::D, val); + 2 } 0x93 => { let val = res(self.reg.get_8(Reg8::E), 2); self.reg.set_8(Reg8::E, val); + 2 } 0x94 => { let val = res(self.reg.get_8(Reg8::H), 2); self.reg.set_8(Reg8::H, val); + 2 } 0x95 => { let val = res(self.reg.get_8(Reg8::L), 2); self.reg.set_8(Reg8::L, val); + 2 } 0x96 => { let val = res(self.memory.get(self.reg.hl), 2); self.memory.set(self.reg.hl, val); + 4 } 0x97 => { let val = res(self.reg.get_8(Reg8::A), 2); self.reg.set_8(Reg8::A, val); + 2 } 0x98 => { let val = res(self.reg.get_8(Reg8::B), 3); self.reg.set_8(Reg8::B, val); + 2 } 0x99 => { let val = res(self.reg.get_8(Reg8::C), 3); self.reg.set_8(Reg8::C, val); + 2 } 0x9A => { let val = res(self.reg.get_8(Reg8::D), 3); self.reg.set_8(Reg8::D, val); + 2 } 0x9B => { let val = res(self.reg.get_8(Reg8::E), 3); self.reg.set_8(Reg8::E, val); + 2 } 0x9C => { let val = res(self.reg.get_8(Reg8::H), 3); self.reg.set_8(Reg8::H, val); + 2 } 0x9D => { let val = res(self.reg.get_8(Reg8::L), 3); self.reg.set_8(Reg8::L, val); + 2 } 0x9E => { let val = res(self.memory.get(self.reg.hl), 3); self.memory.set(self.reg.hl, val); + 4 } 0x9F => { let val = res(self.reg.get_8(Reg8::A), 3); self.reg.set_8(Reg8::A, val); + 2 } 0xA0 => { let val = res(self.reg.get_8(Reg8::B), 4); self.reg.set_8(Reg8::B, val); + 2 } 0xA1 => { let val = res(self.reg.get_8(Reg8::C), 4); self.reg.set_8(Reg8::C, val); + 2 } 0xA2 => { let val = res(self.reg.get_8(Reg8::D), 4); self.reg.set_8(Reg8::D, val); + 2 } 0xA3 => { let val = res(self.reg.get_8(Reg8::E), 4); self.reg.set_8(Reg8::E, val); + 2 } 0xA4 => { let val = res(self.reg.get_8(Reg8::H), 4); self.reg.set_8(Reg8::H, val); + 2 } 0xA5 => { let val = res(self.reg.get_8(Reg8::L), 4); self.reg.set_8(Reg8::L, val); + 2 } 0xA6 => { let val = res(self.memory.get(self.reg.hl), 4); self.memory.set(self.reg.hl, val); + 4 } 0xA7 => { let val = res(self.reg.get_8(Reg8::A), 4); self.reg.set_8(Reg8::A, val); + 2 } 0xA8 => { let val = res(self.reg.get_8(Reg8::B), 5); self.reg.set_8(Reg8::B, val); + 2 } 0xA9 => { let val = res(self.reg.get_8(Reg8::C), 5); self.reg.set_8(Reg8::C, val); + 2 } 0xAA => { let val = res(self.reg.get_8(Reg8::D), 5); self.reg.set_8(Reg8::D, val); + 2 } 0xAB => { let val = res(self.reg.get_8(Reg8::E), 5); self.reg.set_8(Reg8::E, val); + 2 } 0xAC => { let val = res(self.reg.get_8(Reg8::H), 5); self.reg.set_8(Reg8::H, val); + 2 } 0xAD => { let val = res(self.reg.get_8(Reg8::L), 5); self.reg.set_8(Reg8::L, val); + 2 } 0xAE => { let val = res(self.memory.get(self.reg.hl), 5); self.memory.set(self.reg.hl, val); + 4 } 0xAF => { let val = res(self.reg.get_8(Reg8::A), 5); self.reg.set_8(Reg8::A, val); + 2 } 0xB0 => { let val = res(self.reg.get_8(Reg8::B), 6); self.reg.set_8(Reg8::B, val); + 2 } 0xB1 => { let val = res(self.reg.get_8(Reg8::C), 6); self.reg.set_8(Reg8::C, val); + 2 } 0xB2 => { let val = res(self.reg.get_8(Reg8::D), 6); self.reg.set_8(Reg8::D, val); + 2 } 0xB3 => { let val = res(self.reg.get_8(Reg8::E), 6); self.reg.set_8(Reg8::E, val); + 2 } 0xB4 => { let val = res(self.reg.get_8(Reg8::H), 6); self.reg.set_8(Reg8::H, val); + 2 } 0xB5 => { let val = res(self.reg.get_8(Reg8::L), 6); self.reg.set_8(Reg8::L, val); + 2 } 0xB6 => { let val = res(self.memory.get(self.reg.hl), 6); self.memory.set(self.reg.hl, val); + 4 } 0xB7 => { let val = res(self.reg.get_8(Reg8::A), 6); self.reg.set_8(Reg8::A, val); + 2 } 0xB8 => { let val = res(self.reg.get_8(Reg8::B), 7); self.reg.set_8(Reg8::B, val); + 2 } 0xB9 => { let val = res(self.reg.get_8(Reg8::C), 7); self.reg.set_8(Reg8::C, val); + 2 } 0xBA => { let val = res(self.reg.get_8(Reg8::D), 7); self.reg.set_8(Reg8::D, val); + 2 } 0xBB => { let val = res(self.reg.get_8(Reg8::E), 7); self.reg.set_8(Reg8::E, val); + 2 } 0xBC => { let val = res(self.reg.get_8(Reg8::H), 7); self.reg.set_8(Reg8::H, val); + 2 } 0xBD => { let val = res(self.reg.get_8(Reg8::L), 7); self.reg.set_8(Reg8::L, val); + 2 } 0xBE => { let val = res(self.memory.get(self.reg.hl), 7); self.memory.set(self.reg.hl, val); + 4 } 0xBF => { let val = res(self.reg.get_8(Reg8::A), 7); self.reg.set_8(Reg8::A, val); + 2 } 0xC0 => { let val = set(self.reg.get_8(Reg8::B), 0); self.reg.set_8(Reg8::B, val); + 2 } 0xC1 => { let val = set(self.reg.get_8(Reg8::C), 0); self.reg.set_8(Reg8::C, val); + 2 } 0xC2 => { let val = set(self.reg.get_8(Reg8::D), 0); self.reg.set_8(Reg8::D, val); + 2 } 0xC3 => { let val = set(self.reg.get_8(Reg8::E), 0); self.reg.set_8(Reg8::E, val); + 2 } 0xC4 => { let val = set(self.reg.get_8(Reg8::H), 0); self.reg.set_8(Reg8::H, val); + 2 } 0xC5 => { let val = set(self.reg.get_8(Reg8::L), 0); self.reg.set_8(Reg8::L, val); + 2 } 0xC6 => { let val = set(self.memory.get(self.reg.hl), 0); self.memory.set(self.reg.hl, val); + 4 } 0xC7 => { let val = set(self.reg.get_8(Reg8::A), 0); self.reg.set_8(Reg8::A, val); + 2 } 0xC8 => { let val = set(self.reg.get_8(Reg8::B), 1); self.reg.set_8(Reg8::B, val); + 2 } 0xC9 => { let val = set(self.reg.get_8(Reg8::C), 1); self.reg.set_8(Reg8::C, val); + 2 } 0xCA => { let val = set(self.reg.get_8(Reg8::D), 1); self.reg.set_8(Reg8::D, val); + 2 } 0xCB => { let val = set(self.reg.get_8(Reg8::E), 1); self.reg.set_8(Reg8::E, val); + 2 } 0xCC => { let val = set(self.reg.get_8(Reg8::H), 1); self.reg.set_8(Reg8::H, val); + 2 } 0xCD => { let val = set(self.reg.get_8(Reg8::L), 1); self.reg.set_8(Reg8::L, val); + 2 } 0xCE => { let val = set(self.memory.get(self.reg.hl), 1); self.memory.set(self.reg.hl, val); + 4 } 0xCF => { let val = set(self.reg.get_8(Reg8::A), 1); self.reg.set_8(Reg8::A, val); + 2 } 0xD0 => { let val = set(self.reg.get_8(Reg8::B), 2); self.reg.set_8(Reg8::B, val); + 2 } 0xD1 => { let val = set(self.reg.get_8(Reg8::C), 2); self.reg.set_8(Reg8::C, val); + 2 } 0xD2 => { let val = set(self.reg.get_8(Reg8::D), 2); self.reg.set_8(Reg8::D, val); + 2 } 0xD3 => { let val = set(self.reg.get_8(Reg8::E), 2); self.reg.set_8(Reg8::E, val); + 2 } 0xD4 => { let val = set(self.reg.get_8(Reg8::H), 2); self.reg.set_8(Reg8::H, val); + 2 } 0xD5 => { let val = set(self.reg.get_8(Reg8::L), 2); self.reg.set_8(Reg8::L, val); + 2 } 0xD6 => { let val = set(self.memory.get(self.reg.hl), 2); self.memory.set(self.reg.hl, val); + 4 } 0xD7 => { let val = set(self.reg.get_8(Reg8::A), 2); self.reg.set_8(Reg8::A, val); + 2 } 0xD8 => { let val = set(self.reg.get_8(Reg8::B), 3); self.reg.set_8(Reg8::B, val); + 2 } 0xD9 => { let val = set(self.reg.get_8(Reg8::C), 3); self.reg.set_8(Reg8::C, val); + 2 } 0xDA => { let val = set(self.reg.get_8(Reg8::D), 3); self.reg.set_8(Reg8::D, val); + 2 } 0xDB => { let val = set(self.reg.get_8(Reg8::E), 3); self.reg.set_8(Reg8::E, val); + 2 } 0xDC => { let val = set(self.reg.get_8(Reg8::H), 3); self.reg.set_8(Reg8::H, val); + 2 } 0xDD => { let val = set(self.reg.get_8(Reg8::L), 3); self.reg.set_8(Reg8::L, val); + 2 } 0xDE => { let val = set(self.memory.get(self.reg.hl), 3); self.memory.set(self.reg.hl, val); + 4 } 0xDF => { let val = set(self.reg.get_8(Reg8::A), 3); self.reg.set_8(Reg8::A, val); + 2 } 0xE0 => { let val = set(self.reg.get_8(Reg8::B), 4); self.reg.set_8(Reg8::B, val); + 2 } 0xE1 => { let val = set(self.reg.get_8(Reg8::C), 4); self.reg.set_8(Reg8::C, val); + 2 } 0xE2 => { let val = set(self.reg.get_8(Reg8::D), 4); self.reg.set_8(Reg8::D, val); + 2 } 0xE3 => { let val = set(self.reg.get_8(Reg8::E), 4); self.reg.set_8(Reg8::E, val); + 2 } 0xE4 => { let val = set(self.reg.get_8(Reg8::H), 4); self.reg.set_8(Reg8::H, val); + 2 } 0xE5 => { let val = set(self.reg.get_8(Reg8::L), 4); self.reg.set_8(Reg8::L, val); + 2 } 0xE6 => { let val = set(self.memory.get(self.reg.hl), 4); self.memory.set(self.reg.hl, val); + 4 } 0xE7 => { let val = set(self.reg.get_8(Reg8::A), 4); self.reg.set_8(Reg8::A, val); + 2 } 0xE8 => { let val = set(self.reg.get_8(Reg8::B), 5); self.reg.set_8(Reg8::B, val); + 2 } 0xE9 => { let val = set(self.reg.get_8(Reg8::C), 5); self.reg.set_8(Reg8::C, val); + 2 } 0xEA => { let val = set(self.reg.get_8(Reg8::D), 5); self.reg.set_8(Reg8::D, val); + 2 } 0xEB => { let val = set(self.reg.get_8(Reg8::E), 5); self.reg.set_8(Reg8::E, val); + 2 } 0xEC => { let val = set(self.reg.get_8(Reg8::H), 5); self.reg.set_8(Reg8::H, val); + 2 } 0xED => { let val = set(self.reg.get_8(Reg8::L), 5); self.reg.set_8(Reg8::L, val); + 2 } 0xEE => { let val = set(self.memory.get(self.reg.hl), 5); self.memory.set(self.reg.hl, val); + 4 } 0xEF => { let val = set(self.reg.get_8(Reg8::A), 5); self.reg.set_8(Reg8::A, val); + 2 } 0xF0 => { let val = set(self.reg.get_8(Reg8::B), 6); self.reg.set_8(Reg8::B, val); + 2 } 0xF1 => { let val = set(self.reg.get_8(Reg8::C), 6); self.reg.set_8(Reg8::C, val); + 2 } 0xF2 => { let val = set(self.reg.get_8(Reg8::D), 6); self.reg.set_8(Reg8::D, val); + 2 } 0xF3 => { let val = set(self.reg.get_8(Reg8::E), 6); self.reg.set_8(Reg8::E, val); + 2 } 0xF4 => { let val = set(self.reg.get_8(Reg8::H), 6); self.reg.set_8(Reg8::H, val); + 2 } 0xF5 => { let val = set(self.reg.get_8(Reg8::L), 6); self.reg.set_8(Reg8::L, val); + 2 } 0xF6 => { let val = set(self.memory.get(self.reg.hl), 6); self.memory.set(self.reg.hl, val); + 4 } 0xF7 => { let val = set(self.reg.get_8(Reg8::A), 6); self.reg.set_8(Reg8::A, val); + 2 } 0xF8 => { let val = set(self.reg.get_8(Reg8::B), 7); self.reg.set_8(Reg8::B, val); + 2 } 0xF9 => { let val = set(self.reg.get_8(Reg8::C), 7); self.reg.set_8(Reg8::C, val); + 2 } 0xFA => { let val = set(self.reg.get_8(Reg8::D), 7); self.reg.set_8(Reg8::D, val); + 2 } 0xFB => { let val = set(self.reg.get_8(Reg8::E), 7); self.reg.set_8(Reg8::E, val); + 2 } 0xFC => { let val = set(self.reg.get_8(Reg8::H), 7); self.reg.set_8(Reg8::H, val); + 2 } 0xFD => { let val = set(self.reg.get_8(Reg8::L), 7); self.reg.set_8(Reg8::L, val); + 2 } 0xFE => { let val = set(self.memory.get(self.reg.hl), 7); self.memory.set(self.reg.hl, val); + 4 } 0xFF => { let val = set(self.reg.get_8(Reg8::A), 7); self.reg.set_8(Reg8::A, val); + 2 } } } - - #[allow(dead_code)] - fn instruction_length(&self, _opcode: u8) -> u8 { - 1 - } } -fn undefined(opcode: u8) { +fn undefined(opcode: u8) -> u8 { panic!("Undefined behaviour: opcode {:#X}", opcode); }