gb-emu/src/processor/opcodes.rs

2447 lines
75 KiB
Rust
Raw Normal View History

2023-02-12 09:27:41 +11:00
use crate::{
processor::{
instructions::instructions::{res, set},
2023-02-12 09:46:47 +11:00
Cpu, Flags, Reg8, SplitRegister,
2023-02-12 09:27:41 +11:00
},
util::as_signed,
2023-02-02 11:52:45 +11:00
};
2023-01-22 09:39:45 +11:00
2023-02-12 09:46:47 +11:00
impl Cpu {
2023-02-02 16:28:49 +11:00
pub fn run_opcode(&mut self, opcode: u8) -> u8 {
2023-01-22 09:39:45 +11:00
match opcode {
2023-02-01 22:46:58 +11:00
0x00 => {
2023-01-22 09:39:45 +11:00
// noop
2023-02-02 16:28:49 +11:00
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
2023-01-22 09:39:45 +11:00
}
2023-02-01 22:46:58 +11:00
0x06 => {
let byte = self.ld_immediate_byte();
self.reg.set_8(Reg8::B, byte);
2023-02-02 16:28:49 +11:00
2
2023-02-01 22:46:58 +11:00
}
0x07 => {
let val = self.rlc(self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 22:46:58 +11:00
}
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());
2023-02-02 16:28:49 +11:00
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
2023-02-01 22:46:58 +11:00
}
0x0E => {
let byte = self.ld_immediate_byte();
self.reg.set_8(Reg8::C, byte);
2023-02-02 16:28:49 +11:00
2
2023-02-01 22:46:58 +11:00
}
0x0F => {
let val = self.rrc(self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 22:46:58 +11:00
}
0x10 => {
// stop
2023-02-02 16:28:49 +11:00
// 1 cycle long
2023-02-01 22:46:58 +11:00
panic!("stop instruction");
}
2023-02-02 16:28:49 +11:00
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
}
2023-02-01 22:46:58 +11:00
0x16 => {
let byte = self.ld_immediate_byte();
self.reg.set_8(Reg8::D, byte);
2023-02-02 16:28:49 +11:00
2
2023-02-01 22:46:58 +11:00
}
0x17 => {
let val = self.rl(self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 22:46:58 +11:00
}
0x18 => {
let jump = as_signed(self.ld_immediate_byte());
self.jr(jump);
2023-02-02 16:28:49 +11:00
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
2023-02-01 22:46:58 +11:00
}
0x1E => {
let byte = self.ld_immediate_byte();
self.reg.set_8(Reg8::E, byte);
2023-02-02 16:28:49 +11:00
2
2023-02-01 22:46:58 +11:00
}
0x1F => {
let val = self.rr(self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-01 22:46:58 +11:00
}
0x20 => {
let jump = as_signed(self.ld_immediate_byte());
if !self.is_flag(Flags::Zero) {
self.jr(jump);
2023-02-02 16:28:49 +11:00
3
} else {
2
2023-02-01 22:46:58 +11:00
}
}
2023-02-02 16:28:49 +11:00
0x21 => {
self.reg.hl = self.ld_immediate_word();
3
}
2023-02-01 22:46:58 +11:00
0x22 => {
self.memory.set(self.reg.hl, self.reg.get_8(Reg8::A));
self.reg.hl = self.inc_pair(self.reg.hl);
2023-02-02 16:28:49 +11:00
2
}
0x23 => {
self.reg.hl = self.inc_pair(self.reg.hl);
2
}
0x24 => {
self.inc(Reg8::H);
1
}
0x25 => {
self.dec(Reg8::H);
1
2023-02-01 22:46:58 +11:00
}
0x26 => {
let byte = self.ld_immediate_byte();
self.reg.set_8(Reg8::H, byte);
2023-02-02 16:28:49 +11:00
2
2023-02-01 22:46:58 +11:00
}
0x27 => {
let mut a = self.reg.get_8(Reg8::A);
if !self.is_flag(Flags::NSubtract) {
// after an addition, adjust if (half-)carry occurred or if result is out of bounds
if self.is_flag(Flags::Carry) || a > 0x99 {
2023-02-09 17:30:50 +11:00
a = a.wrapping_add(0x60);
2023-02-01 22:46:58 +11:00
self.set_flag(Flags::Carry);
}
if self.is_flag(Flags::HalfCarry) || (a & 0x0f) > 0x09 {
2023-02-09 17:30:50 +11:00
a = a.wrapping_add(0x6);
2023-02-01 22:46:58 +11:00
}
} else {
// after a subtraction, only adjust if (half-)carry occurred
if self.is_flag(Flags::Carry) {
2023-02-09 17:30:50 +11:00
a = a.wrapping_sub(0x60);
2023-02-01 22:46:58 +11:00
}
if self.is_flag(Flags::HalfCarry) {
2023-02-09 17:30:50 +11:00
a = a.wrapping_sub(0x6);
2023-02-01 22:46:58 +11:00
}
}
// these flags are always updated
self.set_or_clear_flag(Flags::Zero, a == 0);
self.clear_flag(Flags::HalfCarry);
self.reg.set_8(Reg8::A, a);
2023-02-02 16:28:49 +11:00
1
2023-02-01 22:46:58 +11:00
}
0x28 => {
let jump = as_signed(self.ld_immediate_byte());
if self.is_flag(Flags::Zero) {
self.jr(jump);
2023-02-02 16:28:49 +11:00
3
} else {
2
2023-02-01 22:46:58 +11:00
}
}
2023-02-02 16:28:49 +11:00
0x29 => {
self.reg.hl = self.add_u16s(self.reg.hl, self.reg.hl);
2
}
2023-02-01 22:46:58 +11:00
0x2A => {
self.reg.set_8(Reg8::A, self.memory.get(self.reg.hl));
self.reg.hl = self.inc_pair(self.reg.hl);
2023-02-02 16:28:49 +11:00
2
}
0x2B => {
self.reg.hl = self.dec_pair(self.reg.hl);
2
}
0x2C => {
self.inc(Reg8::L);
1
}
0x2D => {
self.dec(Reg8::L);
1
2023-02-01 22:46:58 +11:00
}
0x2E => {
let byte = self.ld_immediate_byte();
self.reg.set_8(Reg8::L, byte);
2023-02-02 16:28:49 +11:00
2
2023-02-01 22:46:58 +11:00
}
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);
2023-02-02 16:28:49 +11:00
1
2023-02-01 22:46:58 +11:00
}
0x30 => {
let jump = as_signed(self.ld_immediate_byte());
if !self.is_flag(Flags::Carry) {
self.jr(jump);
2023-02-02 16:28:49 +11:00
3
} else {
2
2023-02-01 22:46:58 +11:00
}
}
2023-02-02 16:28:49 +11:00
0x31 => {
self.reg.sp = self.ld_immediate_word();
3
}
2023-02-01 22:46:58 +11:00
0x32 => {
self.memory.set(self.reg.hl, self.reg.get_8(Reg8::A));
self.reg.hl = self.dec_pair(self.reg.hl);
2023-02-02 16:28:49 +11:00
2
}
0x33 => {
self.reg.sp = self.inc_pair(self.reg.sp);
2
2023-02-01 22:46:58 +11:00
}
0x34 => {
let val = self.inc_raw(self.memory.get(self.reg.hl));
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
3
2023-02-01 22:46:58 +11:00
}
0x35 => {
let val = self.dec_raw(self.memory.get(self.reg.hl));
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
3
2023-02-01 22:46:58 +11:00
}
0x36 => {
let byte = self.ld_immediate_byte();
self.memory.set(self.reg.hl, byte);
2023-02-02 16:28:49 +11:00
3
2023-02-01 22:46:58 +11:00
}
0x37 => {
self.clear_flag(Flags::NSubtract);
self.clear_flag(Flags::HalfCarry);
self.set_flag(Flags::Carry);
2023-02-02 16:28:49 +11:00
1
2023-02-01 22:46:58 +11:00
}
0x38 => {
let jump = as_signed(self.ld_immediate_byte());
if self.is_flag(Flags::Carry) {
self.jr(jump);
2023-02-02 16:28:49 +11:00
3
} else {
2
2023-02-01 22:46:58 +11:00
}
}
2023-02-02 16:28:49 +11:00
0x39 => {
self.reg.hl = self.add_u16s(self.reg.hl, self.reg.sp);
2
}
2023-02-01 22:46:58 +11:00
0x3A => {
self.reg.set_8(Reg8::A, self.memory.get(self.reg.hl));
self.reg.hl = self.dec_pair(self.reg.hl);
2023-02-02 16:28:49 +11:00
2
}
0x3B => {
self.reg.sp = self.dec_pair(self.reg.sp);
2
}
0x3C => {
self.inc(Reg8::A);
1
}
0x3D => {
self.dec(Reg8::A);
1
2023-02-01 22:46:58 +11:00
}
0x3E => {
let byte = self.ld_immediate_byte();
self.reg.set_8(Reg8::A, byte);
2023-02-02 16:28:49 +11:00
2
2023-02-01 22:46:58 +11:00
}
0x3F => {
self.clear_flag(Flags::NSubtract);
self.clear_flag(Flags::HalfCarry);
self.set_or_clear_flag(Flags::Carry, !self.is_flag(Flags::Carry));
2023-02-02 16:28:49 +11:00
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 => {
2023-02-07 22:49:08 +11:00
self.halted = true;
1
2023-02-02 16:28:49 +11:00
}
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
2023-02-01 22:46:58 +11:00
}
2023-02-01 23:08:51 +11:00
0x80 => {
let val = self.add(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::B));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x81 => {
let val = self.add(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x82 => {
let val = self.add(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x83 => {
let val = self.add(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x84 => {
let val = self.add(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x85 => {
let val = self.add(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x86 => {
let val = self.add(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-01 23:08:51 +11:00
}
0x87 => {
let val = self.add(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x88 => {
let val = self.adc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::B));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x89 => {
let val = self.adc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x8A => {
let val = self.adc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x8B => {
let val = self.adc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x8C => {
let val = self.adc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x8D => {
let val = self.adc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x8E => {
let val = self.adc(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-01 23:08:51 +11:00
}
0x8F => {
let val = self.adc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x90 => {
let val = self.sub(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::B));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x91 => {
let val = self.sub(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x92 => {
let val = self.sub(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x93 => {
let val = self.sub(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x94 => {
let val = self.sub(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x95 => {
let val = self.sub(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x96 => {
let val = self.sub(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-01 23:08:51 +11:00
}
0x97 => {
let val = self.sub(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x98 => {
let val = self.sbc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::B));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x99 => {
let val = self.sbc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x9A => {
let val = self.sbc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x9B => {
let val = self.sbc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x9C => {
let val = self.sbc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x9D => {
let val = self.sbc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0x9E => {
let val = self.sbc(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-01 23:08:51 +11:00
}
0x9F => {
let val = self.sbc(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0xA0 => {
let val = self.and(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::B));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0xA1 => {
let val = self.and(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0xA2 => {
let val = self.and(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0xA3 => {
let val = self.and(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0xA4 => {
let val = self.and(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0xA5 => {
let val = self.and(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0xA6 => {
let val = self.and(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-01 23:08:51 +11:00
}
0xA7 => {
let val = self.and(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0xA8 => {
let val = self.xor(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::B));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0xA9 => {
let val = self.xor(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0xAA => {
let val = self.xor(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0xAB => {
let val = self.xor(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0xAC => {
let val = self.xor(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0xAD => {
let val = self.xor(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0xAE => {
let val = self.xor(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-01 23:08:51 +11:00
}
0xAF => {
let val = self.xor(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0xB0 => {
let val = self.or(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::B));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0xB1 => {
let val = self.or(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::C));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0xB2 => {
let val = self.or(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::D));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0xB3 => {
let val = self.or(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::E));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0xB4 => {
let val = self.or(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::H));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0xB5 => {
let val = self.or(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::L));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
1
2023-02-01 23:08:51 +11:00
}
0xB6 => {
let val = self.or(self.reg.get_8(Reg8::A), self.memory.get(self.reg.hl));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-01 23:08:51 +11:00
}
0xB7 => {
let val = self.or(self.reg.get_8(Reg8::A), self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
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
2023-02-01 23:08:51 +11:00
}
2023-02-02 10:54:16 +11:00
0xC0 => {
if !self.is_flag(Flags::Zero) {
self.ret();
2023-02-02 16:28:49 +11:00
5
} else {
2
2023-02-02 10:54:16 +11:00
}
}
2023-02-02 16:28:49 +11:00
0xC1 => {
self.reg.bc = self.pop_word();
3
}
2023-02-02 10:54:16 +11:00
0xC2 => {
let jump = self.ld_immediate_word();
if !self.is_flag(Flags::Zero) {
self.reg.pc = jump;
2023-02-02 16:28:49 +11:00
4
} else {
3
2023-02-02 10:54:16 +11:00
}
}
0xC3 => {
let jump = self.ld_immediate_word();
self.reg.pc = jump;
2023-02-02 16:28:49 +11:00
4
2023-02-02 10:54:16 +11:00
}
0xC4 => {
let pc = self.ld_immediate_word();
if !self.is_flag(Flags::Zero) {
self.push(self.reg.pc);
self.reg.pc = pc;
2023-02-02 16:28:49 +11:00
6
} else {
3
2023-02-02 10:54:16 +11:00
}
}
2023-02-02 16:28:49 +11:00
0xC5 => {
self.push(self.reg.bc);
4
}
2023-02-02 10:54:16 +11:00
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);
2023-02-02 16:28:49 +11:00
2
}
0xC7 => {
self.rst(0x0);
1
2023-02-02 10:54:16 +11:00
}
0xC8 => {
if self.is_flag(Flags::Zero) {
self.ret();
2023-02-02 16:28:49 +11:00
5
} else {
2
2023-02-02 10:54:16 +11:00
}
}
2023-02-02 16:28:49 +11:00
0xC9 => {
self.ret();
4
}
2023-02-02 10:54:16 +11:00
0xCA => {
let jump = self.ld_immediate_word();
if self.is_flag(Flags::Zero) {
self.reg.pc = jump;
2023-02-02 16:28:49 +11:00
4
} else {
3
2023-02-02 10:54:16 +11:00
}
}
2023-02-02 11:52:45 +11:00
0xCB => {
let subop = self.ld_immediate_byte();
2023-02-02 16:28:49 +11:00
self.cb_subop(subop)
2023-02-02 11:52:45 +11:00
}
2023-02-02 10:54:16 +11:00
0xCC => {
let pc = self.ld_immediate_word();
if self.is_flag(Flags::Zero) {
self.push(self.reg.pc);
self.reg.pc = pc;
2023-02-02 16:28:49 +11:00
6
} else {
3
2023-02-02 10:54:16 +11:00
}
}
0xCD => {
let pc = self.ld_immediate_word();
self.push(self.reg.pc);
self.reg.pc = pc;
2023-02-02 16:28:49 +11:00
6
2023-02-02 10:54:16 +11:00
}
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);
2023-02-02 16:28:49 +11:00
2
}
0xCF => {
self.rst(0x08);
4
2023-02-02 10:54:16 +11:00
}
0xD0 => {
if !self.is_flag(Flags::Carry) {
self.ret();
2023-02-02 16:28:49 +11:00
5
} else {
2
2023-02-02 10:54:16 +11:00
}
}
2023-02-02 16:28:49 +11:00
0xD1 => {
self.reg.de = self.pop_word();
3
}
2023-02-02 10:54:16 +11:00
0xD2 => {
let jump = self.ld_immediate_word();
if !self.is_flag(Flags::Carry) {
self.reg.pc = jump;
2023-02-02 16:28:49 +11:00
4
} else {
3
2023-02-02 10:54:16 +11:00
}
}
0xD4 => {
let pc = self.ld_immediate_word();
if !self.is_flag(Flags::Carry) {
self.push(self.reg.pc);
self.reg.pc = pc;
2023-02-02 16:28:49 +11:00
6
} else {
3
2023-02-02 10:54:16 +11:00
}
}
2023-02-02 16:28:49 +11:00
0xD5 => {
self.push(self.reg.de);
4
}
2023-02-02 10:54:16 +11:00
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);
2023-02-02 16:28:49 +11:00
2
}
0xD7 => {
self.rst(0x10);
4
2023-02-02 10:54:16 +11:00
}
0xD8 => {
if self.is_flag(Flags::Carry) {
self.ret();
2023-02-02 16:28:49 +11:00
5
} else {
2
2023-02-02 10:54:16 +11:00
}
}
0xD9 => {
self.ret();
self.memory.ime = true;
2023-02-02 16:28:49 +11:00
4
2023-02-02 10:54:16 +11:00
}
0xDA => {
let jump = self.ld_immediate_word();
if self.is_flag(Flags::Carry) {
self.reg.pc = jump;
2023-02-02 16:28:49 +11:00
4
} else {
3
2023-02-02 10:54:16 +11:00
}
}
0xDC => {
let pc = self.ld_immediate_word();
if self.is_flag(Flags::Carry) {
self.push(self.reg.pc);
self.reg.pc = pc;
2023-02-02 16:28:49 +11:00
6
} else {
3
2023-02-02 10:54:16 +11:00
}
}
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);
2023-02-02 16:28:49 +11:00
2
}
0xDF => {
self.rst(0x18);
4
2023-02-02 10:54:16 +11:00
}
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));
2023-02-02 16:28:49 +11:00
3
}
0xE1 => {
self.reg.hl = self.pop_word();
3
2023-02-02 10:54:16 +11:00
}
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));
2023-02-02 16:28:49 +11:00
2
}
0xE5 => {
self.push(self.reg.hl);
4
2023-02-02 10:54:16 +11:00
}
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);
2023-02-02 16:28:49 +11:00
2
}
0xE7 => {
self.rst(0x20);
4
2023-02-02 10:54:16 +11:00
}
0xE8 => {
let v = as_signed(self.ld_immediate_byte());
self.reg.sp = self.sp_add(self.reg.sp, v);
2023-02-02 16:28:49 +11:00
4
2023-02-02 10:54:16 +11:00
}
0xE9 => {
self.reg.pc = self.reg.hl;
2023-02-02 16:28:49 +11:00
1
2023-02-02 10:54:16 +11:00
}
0xEA => {
let addr = self.ld_immediate_word();
self.memory.set(addr, self.reg.get_8(Reg8::A));
2023-02-02 16:28:49 +11:00
4
2023-02-02 10:54:16 +11:00
}
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);
2023-02-02 16:28:49 +11:00
2
}
0xEF => {
self.rst(0x28);
4
2023-02-02 10:54:16 +11:00
}
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));
2023-02-02 16:28:49 +11:00
3
}
0xF1 => {
2023-02-12 10:22:52 +11:00
self.reg.af = self.pop_word() & 0xFFF0;
2023-02-02 16:28:49 +11:00
3
2023-02-02 10:54:16 +11:00
}
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));
2023-02-02 16:28:49 +11:00
2
2023-02-02 10:54:16 +11:00
}
0xF3 => {
self.memory.ime = false;
self.memory.ime_scheduled = 0;
2023-02-02 16:28:49 +11:00
1
}
0xF5 => {
self.push(self.reg.af);
4
2023-02-02 10:54:16 +11:00
}
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);
2023-02-02 16:28:49 +11:00
2
}
0xF7 => {
self.rst(0x30);
4
2023-02-02 10:54:16 +11:00
}
0xF8 => {
let v = as_signed(self.ld_immediate_byte());
self.reg.hl = self.sp_add(self.reg.sp, v);
2023-02-02 16:28:49 +11:00
3
2023-02-02 10:54:16 +11:00
}
0xF9 => {
self.reg.sp = self.reg.hl;
2023-02-02 16:28:49 +11:00
2
2023-02-02 10:54:16 +11:00
}
0xFA => {
let addr = self.ld_immediate_word();
self.reg.set_8(Reg8::A, self.memory.get(addr));
2023-02-02 16:28:49 +11:00
4
}
0xFB => {
self.memory.ime_scheduled = 2;
1
2023-02-02 10:54:16 +11:00
}
0xFE => {
let byte = self.ld_immediate_byte();
self.cp(self.reg.get_8(Reg8::A), byte);
2023-02-02 16:28:49 +11:00
2
}
0xFF => {
self.rst(0x38);
4
2023-02-02 10:54:16 +11:00
}
0xD3 | 0xDB | 0xDD | 0xE3 | 0xE4 | 0xEB | 0xEC | 0xED | 0xF4 | 0xFC | 0xFD => {
undefined(opcode)
2023-01-22 09:39:45 +11:00
}
2023-02-01 17:18:08 +11:00
}
2023-01-22 09:39:45 +11:00
}
2023-02-02 16:28:49 +11:00
fn cb_subop(&mut self, subop: u8) -> u8 {
2023-02-02 11:52:45 +11:00
match subop {
0x00 => {
let val = self.rlc(self.reg.get_8(Reg8::B));
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x01 => {
let val = self.rlc(self.reg.get_8(Reg8::C));
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x02 => {
let val = self.rlc(self.reg.get_8(Reg8::D));
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x03 => {
let val = self.rlc(self.reg.get_8(Reg8::E));
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x04 => {
let val = self.rlc(self.reg.get_8(Reg8::H));
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x05 => {
let val = self.rlc(self.reg.get_8(Reg8::L));
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x06 => {
let val = self.rlc(self.memory.get(self.reg.hl));
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0x07 => {
let val = self.rlc(self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x08 => {
let val = self.rrc(self.reg.get_8(Reg8::B));
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x09 => {
let val = self.rrc(self.reg.get_8(Reg8::C));
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x0A => {
let val = self.rrc(self.reg.get_8(Reg8::D));
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x0B => {
let val = self.rrc(self.reg.get_8(Reg8::E));
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x0C => {
let val = self.rrc(self.reg.get_8(Reg8::H));
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x0D => {
let val = self.rrc(self.reg.get_8(Reg8::L));
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x0E => {
let val = self.rrc(self.memory.get(self.reg.hl));
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0x0F => {
let val = self.rrc(self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x10 => {
let val = self.rl(self.reg.get_8(Reg8::B));
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x11 => {
let val = self.rl(self.reg.get_8(Reg8::C));
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x12 => {
let val = self.rl(self.reg.get_8(Reg8::D));
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x13 => {
let val = self.rl(self.reg.get_8(Reg8::E));
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x14 => {
let val = self.rl(self.reg.get_8(Reg8::H));
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x15 => {
let val = self.rl(self.reg.get_8(Reg8::L));
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x16 => {
let val = self.rl(self.memory.get(self.reg.hl));
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0x17 => {
let val = self.rl(self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x18 => {
let val = self.rr(self.reg.get_8(Reg8::B));
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x19 => {
let val = self.rr(self.reg.get_8(Reg8::C));
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x1A => {
let val = self.rr(self.reg.get_8(Reg8::D));
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x1B => {
let val = self.rr(self.reg.get_8(Reg8::E));
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x1C => {
let val = self.rr(self.reg.get_8(Reg8::H));
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x1D => {
let val = self.rr(self.reg.get_8(Reg8::L));
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x1E => {
let val = self.rr(self.memory.get(self.reg.hl));
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0x1F => {
let val = self.rr(self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x20 => {
let val = self.sla(self.reg.get_8(Reg8::B));
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x21 => {
let val = self.sla(self.reg.get_8(Reg8::C));
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x22 => {
let val = self.sla(self.reg.get_8(Reg8::D));
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x23 => {
let val = self.sla(self.reg.get_8(Reg8::E));
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x24 => {
let val = self.sla(self.reg.get_8(Reg8::H));
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x25 => {
let val = self.sla(self.reg.get_8(Reg8::L));
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x26 => {
let val = self.sla(self.memory.get(self.reg.hl));
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0x27 => {
let val = self.sla(self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x28 => {
let val = self.sra(self.reg.get_8(Reg8::B));
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x29 => {
let val = self.sra(self.reg.get_8(Reg8::C));
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x2A => {
let val = self.sra(self.reg.get_8(Reg8::D));
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x2B => {
let val = self.sra(self.reg.get_8(Reg8::E));
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x2C => {
let val = self.sra(self.reg.get_8(Reg8::H));
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x2D => {
let val = self.sra(self.reg.get_8(Reg8::L));
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x2E => {
let val = self.sra(self.memory.get(self.reg.hl));
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0x2F => {
let val = self.sra(self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x30 => {
let val = self.swap(self.reg.get_8(Reg8::B));
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x31 => {
let val = self.swap(self.reg.get_8(Reg8::C));
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x32 => {
let val = self.swap(self.reg.get_8(Reg8::D));
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x33 => {
let val = self.swap(self.reg.get_8(Reg8::E));
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x34 => {
let val = self.swap(self.reg.get_8(Reg8::H));
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x35 => {
let val = self.swap(self.reg.get_8(Reg8::L));
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x36 => {
let val = self.swap(self.memory.get(self.reg.hl));
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0x37 => {
let val = self.swap(self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x38 => {
let val = self.srl(self.reg.get_8(Reg8::B));
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x39 => {
let val = self.srl(self.reg.get_8(Reg8::C));
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x3A => {
let val = self.srl(self.reg.get_8(Reg8::D));
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x3B => {
let val = self.srl(self.reg.get_8(Reg8::E));
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x3C => {
let val = self.srl(self.reg.get_8(Reg8::H));
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x3D => {
let val = self.srl(self.reg.get_8(Reg8::L));
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x3E => {
let val = self.srl(self.memory.get(self.reg.hl));
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0x3F => {
let val = self.srl(self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
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
2023-02-02 11:52:45 +11:00
}
0x80 => {
let val = res(self.reg.get_8(Reg8::B), 0);
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x81 => {
let val = res(self.reg.get_8(Reg8::C), 0);
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x82 => {
let val = res(self.reg.get_8(Reg8::D), 0);
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x83 => {
let val = res(self.reg.get_8(Reg8::E), 0);
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x84 => {
let val = res(self.reg.get_8(Reg8::H), 0);
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x85 => {
let val = res(self.reg.get_8(Reg8::L), 0);
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x86 => {
let val = res(self.memory.get(self.reg.hl), 0);
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0x87 => {
let val = res(self.reg.get_8(Reg8::A), 0);
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x88 => {
let val = res(self.reg.get_8(Reg8::B), 1);
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x89 => {
let val = res(self.reg.get_8(Reg8::C), 1);
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x8A => {
let val = res(self.reg.get_8(Reg8::D), 1);
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x8B => {
let val = res(self.reg.get_8(Reg8::E), 1);
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x8C => {
let val = res(self.reg.get_8(Reg8::H), 1);
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x8D => {
let val = res(self.reg.get_8(Reg8::L), 1);
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x8E => {
let val = res(self.memory.get(self.reg.hl), 1);
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0x8F => {
let val = res(self.reg.get_8(Reg8::A), 1);
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x90 => {
let val = res(self.reg.get_8(Reg8::B), 2);
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x91 => {
let val = res(self.reg.get_8(Reg8::C), 2);
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x92 => {
let val = res(self.reg.get_8(Reg8::D), 2);
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x93 => {
let val = res(self.reg.get_8(Reg8::E), 2);
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x94 => {
let val = res(self.reg.get_8(Reg8::H), 2);
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x95 => {
let val = res(self.reg.get_8(Reg8::L), 2);
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x96 => {
let val = res(self.memory.get(self.reg.hl), 2);
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0x97 => {
let val = res(self.reg.get_8(Reg8::A), 2);
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x98 => {
let val = res(self.reg.get_8(Reg8::B), 3);
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x99 => {
let val = res(self.reg.get_8(Reg8::C), 3);
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x9A => {
let val = res(self.reg.get_8(Reg8::D), 3);
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x9B => {
let val = res(self.reg.get_8(Reg8::E), 3);
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x9C => {
let val = res(self.reg.get_8(Reg8::H), 3);
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x9D => {
let val = res(self.reg.get_8(Reg8::L), 3);
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0x9E => {
let val = res(self.memory.get(self.reg.hl), 3);
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0x9F => {
let val = res(self.reg.get_8(Reg8::A), 3);
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xA0 => {
let val = res(self.reg.get_8(Reg8::B), 4);
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xA1 => {
let val = res(self.reg.get_8(Reg8::C), 4);
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xA2 => {
let val = res(self.reg.get_8(Reg8::D), 4);
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xA3 => {
let val = res(self.reg.get_8(Reg8::E), 4);
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xA4 => {
let val = res(self.reg.get_8(Reg8::H), 4);
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xA5 => {
let val = res(self.reg.get_8(Reg8::L), 4);
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xA6 => {
let val = res(self.memory.get(self.reg.hl), 4);
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0xA7 => {
let val = res(self.reg.get_8(Reg8::A), 4);
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xA8 => {
let val = res(self.reg.get_8(Reg8::B), 5);
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xA9 => {
let val = res(self.reg.get_8(Reg8::C), 5);
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xAA => {
let val = res(self.reg.get_8(Reg8::D), 5);
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xAB => {
let val = res(self.reg.get_8(Reg8::E), 5);
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xAC => {
let val = res(self.reg.get_8(Reg8::H), 5);
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xAD => {
let val = res(self.reg.get_8(Reg8::L), 5);
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xAE => {
let val = res(self.memory.get(self.reg.hl), 5);
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0xAF => {
let val = res(self.reg.get_8(Reg8::A), 5);
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xB0 => {
let val = res(self.reg.get_8(Reg8::B), 6);
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xB1 => {
let val = res(self.reg.get_8(Reg8::C), 6);
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xB2 => {
let val = res(self.reg.get_8(Reg8::D), 6);
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xB3 => {
let val = res(self.reg.get_8(Reg8::E), 6);
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xB4 => {
let val = res(self.reg.get_8(Reg8::H), 6);
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xB5 => {
let val = res(self.reg.get_8(Reg8::L), 6);
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xB6 => {
let val = res(self.memory.get(self.reg.hl), 6);
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0xB7 => {
let val = res(self.reg.get_8(Reg8::A), 6);
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xB8 => {
let val = res(self.reg.get_8(Reg8::B), 7);
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xB9 => {
let val = res(self.reg.get_8(Reg8::C), 7);
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xBA => {
let val = res(self.reg.get_8(Reg8::D), 7);
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xBB => {
let val = res(self.reg.get_8(Reg8::E), 7);
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xBC => {
let val = res(self.reg.get_8(Reg8::H), 7);
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xBD => {
let val = res(self.reg.get_8(Reg8::L), 7);
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xBE => {
let val = res(self.memory.get(self.reg.hl), 7);
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0xBF => {
let val = res(self.reg.get_8(Reg8::A), 7);
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xC0 => {
let val = set(self.reg.get_8(Reg8::B), 0);
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xC1 => {
let val = set(self.reg.get_8(Reg8::C), 0);
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xC2 => {
let val = set(self.reg.get_8(Reg8::D), 0);
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xC3 => {
let val = set(self.reg.get_8(Reg8::E), 0);
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xC4 => {
let val = set(self.reg.get_8(Reg8::H), 0);
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xC5 => {
let val = set(self.reg.get_8(Reg8::L), 0);
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xC6 => {
let val = set(self.memory.get(self.reg.hl), 0);
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0xC7 => {
let val = set(self.reg.get_8(Reg8::A), 0);
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xC8 => {
let val = set(self.reg.get_8(Reg8::B), 1);
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xC9 => {
let val = set(self.reg.get_8(Reg8::C), 1);
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xCA => {
let val = set(self.reg.get_8(Reg8::D), 1);
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xCB => {
let val = set(self.reg.get_8(Reg8::E), 1);
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xCC => {
let val = set(self.reg.get_8(Reg8::H), 1);
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xCD => {
let val = set(self.reg.get_8(Reg8::L), 1);
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xCE => {
let val = set(self.memory.get(self.reg.hl), 1);
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0xCF => {
let val = set(self.reg.get_8(Reg8::A), 1);
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xD0 => {
let val = set(self.reg.get_8(Reg8::B), 2);
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xD1 => {
let val = set(self.reg.get_8(Reg8::C), 2);
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xD2 => {
let val = set(self.reg.get_8(Reg8::D), 2);
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xD3 => {
let val = set(self.reg.get_8(Reg8::E), 2);
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xD4 => {
let val = set(self.reg.get_8(Reg8::H), 2);
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xD5 => {
let val = set(self.reg.get_8(Reg8::L), 2);
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xD6 => {
let val = set(self.memory.get(self.reg.hl), 2);
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0xD7 => {
let val = set(self.reg.get_8(Reg8::A), 2);
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xD8 => {
let val = set(self.reg.get_8(Reg8::B), 3);
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xD9 => {
let val = set(self.reg.get_8(Reg8::C), 3);
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xDA => {
let val = set(self.reg.get_8(Reg8::D), 3);
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xDB => {
let val = set(self.reg.get_8(Reg8::E), 3);
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xDC => {
let val = set(self.reg.get_8(Reg8::H), 3);
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xDD => {
let val = set(self.reg.get_8(Reg8::L), 3);
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xDE => {
let val = set(self.memory.get(self.reg.hl), 3);
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0xDF => {
let val = set(self.reg.get_8(Reg8::A), 3);
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xE0 => {
let val = set(self.reg.get_8(Reg8::B), 4);
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xE1 => {
let val = set(self.reg.get_8(Reg8::C), 4);
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xE2 => {
let val = set(self.reg.get_8(Reg8::D), 4);
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xE3 => {
let val = set(self.reg.get_8(Reg8::E), 4);
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xE4 => {
let val = set(self.reg.get_8(Reg8::H), 4);
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xE5 => {
let val = set(self.reg.get_8(Reg8::L), 4);
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xE6 => {
let val = set(self.memory.get(self.reg.hl), 4);
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0xE7 => {
let val = set(self.reg.get_8(Reg8::A), 4);
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xE8 => {
let val = set(self.reg.get_8(Reg8::B), 5);
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xE9 => {
let val = set(self.reg.get_8(Reg8::C), 5);
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xEA => {
let val = set(self.reg.get_8(Reg8::D), 5);
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xEB => {
let val = set(self.reg.get_8(Reg8::E), 5);
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xEC => {
let val = set(self.reg.get_8(Reg8::H), 5);
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xED => {
let val = set(self.reg.get_8(Reg8::L), 5);
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xEE => {
let val = set(self.memory.get(self.reg.hl), 5);
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0xEF => {
let val = set(self.reg.get_8(Reg8::A), 5);
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xF0 => {
let val = set(self.reg.get_8(Reg8::B), 6);
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xF1 => {
let val = set(self.reg.get_8(Reg8::C), 6);
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xF2 => {
let val = set(self.reg.get_8(Reg8::D), 6);
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xF3 => {
let val = set(self.reg.get_8(Reg8::E), 6);
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xF4 => {
let val = set(self.reg.get_8(Reg8::H), 6);
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xF5 => {
let val = set(self.reg.get_8(Reg8::L), 6);
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xF6 => {
let val = set(self.memory.get(self.reg.hl), 6);
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0xF7 => {
let val = set(self.reg.get_8(Reg8::A), 6);
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xF8 => {
let val = set(self.reg.get_8(Reg8::B), 7);
self.reg.set_8(Reg8::B, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xF9 => {
let val = set(self.reg.get_8(Reg8::C), 7);
self.reg.set_8(Reg8::C, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xFA => {
let val = set(self.reg.get_8(Reg8::D), 7);
self.reg.set_8(Reg8::D, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xFB => {
let val = set(self.reg.get_8(Reg8::E), 7);
self.reg.set_8(Reg8::E, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xFC => {
let val = set(self.reg.get_8(Reg8::H), 7);
self.reg.set_8(Reg8::H, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xFD => {
let val = set(self.reg.get_8(Reg8::L), 7);
self.reg.set_8(Reg8::L, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
0xFE => {
let val = set(self.memory.get(self.reg.hl), 7);
self.memory.set(self.reg.hl, val);
2023-02-02 16:28:49 +11:00
4
2023-02-02 11:52:45 +11:00
}
0xFF => {
let val = set(self.reg.get_8(Reg8::A), 7);
self.reg.set_8(Reg8::A, val);
2023-02-02 16:28:49 +11:00
2
2023-02-02 11:52:45 +11:00
}
}
}
2023-01-22 09:39:45 +11:00
}
2023-02-02 16:28:49 +11:00
fn undefined(opcode: u8) -> u8 {
2023-02-12 09:41:34 +11:00
panic!("Undefined behaviour: opcode {opcode:#X}");
2023-01-22 09:39:45 +11:00
}