gb-emu/src/processor/opcodes.rs

569 lines
34 KiB
Rust
Raw Normal View History

2023-02-01 17:18:08 +11:00
use crate::verbose_println;
2023-01-22 09:39:45 +11:00
use std::ops::{BitAnd, BitOr, BitXor};
2023-02-01 22:46:58 +11:00
use super::{as_signed, res, set, swap_nibbles, Flags, Reg8, SplitRegister, CPU};
2023-01-22 09:39:45 +11:00
impl CPU {
2023-02-01 17:18:08 +11:00
#[allow(dead_code)]
2023-01-22 09:39:45 +11:00
pub fn run_opcode(&mut self, opcode: u8) {
match opcode {
2023-02-01 22:46:58 +11:00
0x00 => {
2023-01-22 09:39:45 +11:00
// noop
}
2023-02-01 22:46:58 +11:00
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);
}
0x07 => {
let val = self.rlc(self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
}
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());
}
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);
}
0x0F => {
let val = self.rrc(self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
}
0x10 => {
// stop
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),
0x16 => {
let byte = self.ld_immediate_byte();
self.reg.set_8(Reg8::D, byte);
}
0x17 => {
let val = self.rl(self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
}
0x18 => {
let jump = as_signed(self.ld_immediate_byte());
self.jr(jump);
}
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);
}
0x1F => {
let val = self.rr(self.reg.get_8(Reg8::A));
self.reg.set_8(Reg8::A, val);
}
0x20 => {
let jump = as_signed(self.ld_immediate_byte());
if !self.is_flag(Flags::Zero) {
self.jr(jump);
}
}
0x21 => self.reg.hl = self.ld_immediate_word(),
0x22 => {
self.memory.set(self.reg.hl, self.reg.get_8(Reg8::A));
self.reg.hl = self.inc_pair(self.reg.hl);
}
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);
}
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 {
a += 0x60;
self.set_flag(Flags::Carry);
}
if self.is_flag(Flags::HalfCarry) || (a & 0x0f) > 0x09 {
a += 0x6;
}
} else {
// after a subtraction, only adjust if (half-)carry occurred
if self.is_flag(Flags::Carry) {
a -= 0x60;
}
if self.is_flag(Flags::HalfCarry) {
a -= 0x6;
}
}
// 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);
}
0x28 => {
let jump = as_signed(self.ld_immediate_byte());
if self.is_flag(Flags::Zero) {
self.jr(jump);
}
}
0x29 => self.reg.hl = self.add_u16s(self.reg.hl, self.reg.hl),
0x2A => {
self.reg.set_8(Reg8::A, self.memory.get(self.reg.hl));
self.reg.hl = self.inc_pair(self.reg.hl);
}
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);
}
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);
}
0x30 => {
let jump = as_signed(self.ld_immediate_byte());
if !self.is_flag(Flags::Carry) {
self.jr(jump);
}
}
0x31 => self.reg.sp = self.ld_immediate_word(),
0x32 => {
self.memory.set(self.reg.hl, self.reg.get_8(Reg8::A));
self.reg.hl = self.dec_pair(self.reg.hl);
}
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);
}
0x35 => {
let val = self.dec_raw(self.memory.get(self.reg.hl));
self.memory.set(self.reg.hl, val);
}
0x36 => {
let byte = self.ld_immediate_byte();
self.memory.set(self.reg.hl, byte);
}
0x37 => {
self.clear_flag(Flags::NSubtract);
self.clear_flag(Flags::HalfCarry);
self.set_flag(Flags::Carry);
}
0x38 => {
let jump = as_signed(self.ld_immediate_byte());
if self.is_flag(Flags::Carry) {
self.jr(jump);
}
}
0x39 => self.reg.hl = self.add_u16s(self.reg.hl, self.reg.sp),
0x3A => {
self.reg.set_8(Reg8::A, self.memory.get(self.reg.hl));
self.reg.hl = self.dec_pair(self.reg.hl);
}
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);
}
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-01 17:18:08 +11:00
_ => {
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-01 17:18:08 +11:00
// fn cb_subop(&mut self, subop: u8) {
// match subop {
// 0x00 => unsafe { self.state.bc.as_u8s.left = self.rlc(self.state.bc.as_u8s.left) },
// 0x01 => unsafe { self.state.bc.as_u8s.right = self.rlc(self.state.bc.as_u8s.right) },
// 0x02 => unsafe { self.state.de.as_u8s.left = self.rlc(self.state.de.as_u8s.left) },
// 0x03 => unsafe { self.state.de.as_u8s.right = self.rlc(self.state.de.as_u8s.right) },
// 0x04 => unsafe { self.state.hl.as_u8s.left = self.rlc(self.state.hl.as_u8s.left) },
// 0x05 => unsafe { self.state.hl.as_u8s.right = self.rlc(self.state.hl.as_u8s.right) },
// 0x06 => unsafe {
// let rotated = self.rlc(self.memory.get(self.state.hl.as_u16));
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0x07 => unsafe { self.state.af.as_u8s.left = self.rlc(self.state.af.as_u8s.left) },
// 0x08 => unsafe { self.state.bc.as_u8s.left = self.rrc(self.state.bc.as_u8s.left) },
// 0x09 => unsafe { self.state.bc.as_u8s.right = self.rrc(self.state.bc.as_u8s.right) },
// 0x0A => unsafe { self.state.de.as_u8s.left = self.rrc(self.state.de.as_u8s.left) },
// 0x0B => unsafe { self.state.de.as_u8s.right = self.rrc(self.state.de.as_u8s.right) },
// 0x0C => unsafe { self.state.hl.as_u8s.left = self.rrc(self.state.hl.as_u8s.left) },
// 0x0D => unsafe { self.state.hl.as_u8s.right = self.rrc(self.state.hl.as_u8s.right) },
// 0x0E => unsafe {
// let rotated = self.rrc(self.memory.get(self.state.hl.as_u16));
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0x0F => unsafe { self.state.af.as_u8s.left = self.rrc(self.state.af.as_u8s.left) },
// 0x10 => unsafe { self.state.bc.as_u8s.left = self.rl(self.state.bc.as_u8s.left) },
// 0x11 => unsafe { self.state.bc.as_u8s.right = self.rl(self.state.bc.as_u8s.right) },
// 0x12 => unsafe { self.state.de.as_u8s.left = self.rl(self.state.de.as_u8s.left) },
// 0x13 => unsafe { self.state.de.as_u8s.right = self.rl(self.state.de.as_u8s.right) },
// 0x14 => unsafe { self.state.hl.as_u8s.left = self.rl(self.state.hl.as_u8s.left) },
// 0x15 => unsafe { self.state.hl.as_u8s.right = self.rl(self.state.hl.as_u8s.right) },
// 0x16 => unsafe {
// let rotated = self.rl(self.memory.get(self.state.hl.as_u16));
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0x17 => unsafe { self.state.af.as_u8s.left = self.rl(self.state.af.as_u8s.left) },
// 0x18 => unsafe { self.state.bc.as_u8s.left = self.rr(self.state.bc.as_u8s.left) },
// 0x19 => unsafe { self.state.bc.as_u8s.right = self.rr(self.state.bc.as_u8s.right) },
// 0x1A => unsafe { self.state.de.as_u8s.left = self.rr(self.state.de.as_u8s.left) },
// 0x1B => unsafe { self.state.de.as_u8s.right = self.rr(self.state.de.as_u8s.right) },
// 0x1C => unsafe { self.state.hl.as_u8s.left = self.rr(self.state.hl.as_u8s.left) },
// 0x1D => unsafe { self.state.hl.as_u8s.right = self.rr(self.state.hl.as_u8s.right) },
// 0x1E => unsafe {
// let rotated = self.rr(self.memory.get(self.state.hl.as_u16));
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0x1F => unsafe { self.state.af.as_u8s.left = self.rr(self.state.af.as_u8s.left) },
// 0x20 => unsafe { self.state.bc.as_u8s.left = self.sla(self.state.bc.as_u8s.left) },
// 0x21 => unsafe { self.state.bc.as_u8s.right = self.sla(self.state.bc.as_u8s.right) },
// 0x22 => unsafe { self.state.de.as_u8s.left = self.sla(self.state.de.as_u8s.left) },
// 0x23 => unsafe { self.state.de.as_u8s.right = self.sla(self.state.de.as_u8s.right) },
// 0x24 => unsafe { self.state.hl.as_u8s.left = self.sla(self.state.hl.as_u8s.left) },
// 0x25 => unsafe { self.state.hl.as_u8s.right = self.sla(self.state.hl.as_u8s.right) },
// 0x26 => unsafe {
// let rotated = self.sla(self.memory.get(self.state.hl.as_u16));
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0x27 => unsafe { self.state.af.as_u8s.left = self.sla(self.state.af.as_u8s.left) },
// 0x28 => unsafe { self.state.bc.as_u8s.left = self.sra(self.state.bc.as_u8s.left) },
// 0x29 => unsafe { self.state.bc.as_u8s.right = self.sra(self.state.bc.as_u8s.right) },
// 0x2A => unsafe { self.state.de.as_u8s.left = self.sra(self.state.de.as_u8s.left) },
// 0x2B => unsafe { self.state.de.as_u8s.right = self.sra(self.state.de.as_u8s.right) },
// 0x2C => unsafe { self.state.hl.as_u8s.left = self.sra(self.state.hl.as_u8s.left) },
// 0x2D => unsafe { self.state.hl.as_u8s.right = self.sra(self.state.hl.as_u8s.right) },
// 0x2E => unsafe {
// let rotated = self.sra(self.memory.get(self.state.hl.as_u16));
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0x2F => unsafe { self.state.af.as_u8s.left = self.sra(self.state.af.as_u8s.left) },
// 0x30 => unsafe { self.state.bc.as_u8s.left = swap_nibbles(self.state.bc.as_u8s.left) },
// 0x31 => unsafe {
// self.state.bc.as_u8s.right = swap_nibbles(self.state.bc.as_u8s.right)
// },
// 0x32 => unsafe { self.state.de.as_u8s.left = swap_nibbles(self.state.de.as_u8s.left) },
// 0x33 => unsafe {
// self.state.de.as_u8s.right = swap_nibbles(self.state.de.as_u8s.right)
// },
// 0x34 => unsafe { self.state.hl.as_u8s.left = swap_nibbles(self.state.hl.as_u8s.left) },
// 0x35 => unsafe {
// self.state.hl.as_u8s.right = swap_nibbles(self.state.hl.as_u8s.right)
// },
// 0x36 => unsafe {
// let rotated = swap_nibbles(self.memory.get(self.state.hl.as_u16));
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0x37 => unsafe { self.state.af.as_u8s.left = swap_nibbles(self.state.af.as_u8s.left) },
// 0x38 => unsafe { self.state.bc.as_u8s.left = self.srl(self.state.bc.as_u8s.left) },
// 0x39 => unsafe { self.state.bc.as_u8s.right = self.srl(self.state.bc.as_u8s.right) },
// 0x3A => unsafe { self.state.de.as_u8s.left = self.srl(self.state.de.as_u8s.left) },
// 0x3B => unsafe { self.state.de.as_u8s.right = self.srl(self.state.de.as_u8s.right) },
// 0x3C => unsafe { self.state.hl.as_u8s.left = self.srl(self.state.hl.as_u8s.left) },
// 0x3D => unsafe { self.state.hl.as_u8s.right = self.srl(self.state.hl.as_u8s.right) },
// 0x3E => unsafe {
// let rotated = self.srl(self.memory.get(self.state.hl.as_u16));
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0x3F => unsafe { self.state.af.as_u8s.left = self.srl(self.state.af.as_u8s.left) },
// 0x40 => unsafe { self.bit(self.state.bc.as_u8s.left, 0) },
// 0x41 => unsafe { self.bit(self.state.bc.as_u8s.right, 0) },
// 0x42 => unsafe { self.bit(self.state.de.as_u8s.left, 0) },
// 0x43 => unsafe { self.bit(self.state.de.as_u8s.right, 0) },
// 0x44 => unsafe { self.bit(self.state.hl.as_u8s.left, 0) },
// 0x45 => unsafe { self.bit(self.state.hl.as_u8s.right, 0) },
// 0x46 => unsafe {
// self.bit(self.memory.get(self.state.hl.as_u16), 0);
// },
// 0x47 => unsafe { self.bit(self.state.af.as_u8s.left, 1) },
// 0x48 => unsafe { self.bit(self.state.bc.as_u8s.left, 1) },
// 0x49 => unsafe { self.bit(self.state.bc.as_u8s.right, 1) },
// 0x4A => unsafe { self.bit(self.state.de.as_u8s.left, 1) },
// 0x4B => unsafe { self.bit(self.state.de.as_u8s.right, 1) },
// 0x4C => unsafe { self.bit(self.state.hl.as_u8s.left, 1) },
// 0x4D => unsafe { self.bit(self.state.hl.as_u8s.right, 1) },
// 0x4E => unsafe {
// self.bit(self.memory.get(self.state.hl.as_u16), 1);
// },
// 0x4F => unsafe { self.bit(self.state.af.as_u8s.left, 1) },
// 0x50 => unsafe { self.bit(self.state.bc.as_u8s.left, 2) },
// 0x51 => unsafe { self.bit(self.state.bc.as_u8s.right, 2) },
// 0x52 => unsafe { self.bit(self.state.de.as_u8s.left, 2) },
// 0x53 => unsafe { self.bit(self.state.de.as_u8s.right, 2) },
// 0x54 => unsafe { self.bit(self.state.hl.as_u8s.left, 2) },
// 0x55 => unsafe { self.bit(self.state.hl.as_u8s.right, 2) },
// 0x56 => unsafe {
// self.bit(self.memory.get(self.state.hl.as_u16), 2);
// },
// 0x57 => unsafe { self.bit(self.state.af.as_u8s.left, 3) },
// 0x58 => unsafe { self.bit(self.state.bc.as_u8s.left, 3) },
// 0x59 => unsafe { self.bit(self.state.bc.as_u8s.right, 3) },
// 0x5A => unsafe { self.bit(self.state.de.as_u8s.left, 3) },
// 0x5B => unsafe { self.bit(self.state.de.as_u8s.right, 3) },
// 0x5C => unsafe { self.bit(self.state.hl.as_u8s.left, 3) },
// 0x5D => unsafe { self.bit(self.state.hl.as_u8s.right, 3) },
// 0x5E => unsafe {
// self.bit(self.memory.get(self.state.hl.as_u16), 3);
// },
// 0x5F => unsafe { self.bit(self.state.af.as_u8s.left, 3) },
// 0x60 => unsafe { self.bit(self.state.bc.as_u8s.left, 4) },
// 0x61 => unsafe { self.bit(self.state.bc.as_u8s.right, 4) },
// 0x62 => unsafe { self.bit(self.state.de.as_u8s.left, 4) },
// 0x63 => unsafe { self.bit(self.state.de.as_u8s.right, 4) },
// 0x64 => unsafe { self.bit(self.state.hl.as_u8s.left, 4) },
// 0x65 => unsafe { self.bit(self.state.hl.as_u8s.right, 4) },
// 0x66 => unsafe {
// self.bit(self.memory.get(self.state.hl.as_u16), 4);
// },
// 0x67 => unsafe { self.bit(self.state.af.as_u8s.left, 5) },
// 0x68 => unsafe { self.bit(self.state.bc.as_u8s.left, 5) },
// 0x69 => unsafe { self.bit(self.state.bc.as_u8s.right, 5) },
// 0x6A => unsafe { self.bit(self.state.de.as_u8s.left, 5) },
// 0x6B => unsafe { self.bit(self.state.de.as_u8s.right, 5) },
// 0x6C => unsafe { self.bit(self.state.hl.as_u8s.left, 5) },
// 0x6D => unsafe { self.bit(self.state.hl.as_u8s.right, 5) },
// 0x6E => unsafe {
// self.bit(self.memory.get(self.state.hl.as_u16), 5);
// },
// 0x6F => unsafe { self.bit(self.state.af.as_u8s.left, 5) },
// 0x70 => unsafe { self.bit(self.state.bc.as_u8s.left, 6) },
// 0x71 => unsafe { self.bit(self.state.bc.as_u8s.right, 6) },
// 0x72 => unsafe { self.bit(self.state.de.as_u8s.left, 6) },
// 0x73 => unsafe { self.bit(self.state.de.as_u8s.right, 6) },
// 0x74 => unsafe { self.bit(self.state.hl.as_u8s.left, 6) },
// 0x75 => unsafe { self.bit(self.state.hl.as_u8s.right, 6) },
// 0x76 => unsafe {
// self.bit(self.memory.get(self.state.hl.as_u16), 6);
// },
// 0x77 => unsafe { self.bit(self.state.af.as_u8s.left, 7) },
// 0x78 => unsafe { self.bit(self.state.bc.as_u8s.left, 7) },
// 0x79 => unsafe { self.bit(self.state.bc.as_u8s.right, 7) },
// 0x7A => unsafe { self.bit(self.state.de.as_u8s.left, 7) },
// 0x7B => unsafe { self.bit(self.state.de.as_u8s.right, 7) },
// 0x7C => unsafe { self.bit(self.state.hl.as_u8s.left, 7) },
// 0x7D => unsafe { self.bit(self.state.hl.as_u8s.right, 7) },
// 0x7E => unsafe {
// self.bit(self.memory.get(self.state.hl.as_u16), 7);
// },
// 0x7F => unsafe { self.bit(self.state.af.as_u8s.left, 7) },
// 0x80 => unsafe { self.state.bc.as_u8s.left = res(self.state.bc.as_u8s.left, 0) },
// 0x81 => unsafe { self.state.bc.as_u8s.right = res(self.state.bc.as_u8s.right, 0) },
// 0x82 => unsafe { self.state.de.as_u8s.left = res(self.state.de.as_u8s.left, 0) },
// 0x83 => unsafe { self.state.de.as_u8s.right = res(self.state.de.as_u8s.right, 0) },
// 0x84 => unsafe { self.state.hl.as_u8s.left = res(self.state.hl.as_u8s.left, 0) },
// 0x85 => unsafe { self.state.hl.as_u8s.right = res(self.state.hl.as_u8s.right, 0) },
// 0x86 => unsafe {
// let rotated = res(self.memory.get(self.state.hl.as_u16), 0);
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0x87 => unsafe { self.state.af.as_u8s.left = res(self.state.af.as_u8s.left, 0) },
// 0x88 => unsafe { self.state.bc.as_u8s.left = res(self.state.bc.as_u8s.left, 1) },
// 0x89 => unsafe { self.state.bc.as_u8s.right = res(self.state.bc.as_u8s.right, 1) },
// 0x8A => unsafe { self.state.de.as_u8s.left = res(self.state.de.as_u8s.left, 1) },
// 0x8B => unsafe { self.state.de.as_u8s.right = res(self.state.de.as_u8s.right, 1) },
// 0x8C => unsafe { self.state.hl.as_u8s.left = res(self.state.hl.as_u8s.left, 1) },
// 0x8D => unsafe { self.state.hl.as_u8s.right = res(self.state.hl.as_u8s.right, 1) },
// 0x8E => unsafe {
// let rotated = res(self.memory.get(self.state.hl.as_u16), 1);
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0x8F => unsafe { self.state.af.as_u8s.left = res(self.state.af.as_u8s.left, 1) },
// 0x90 => unsafe { self.state.bc.as_u8s.left = res(self.state.bc.as_u8s.left, 2) },
// 0x91 => unsafe { self.state.bc.as_u8s.right = res(self.state.bc.as_u8s.right, 2) },
// 0x92 => unsafe { self.state.de.as_u8s.left = res(self.state.de.as_u8s.left, 2) },
// 0x93 => unsafe { self.state.de.as_u8s.right = res(self.state.de.as_u8s.right, 2) },
// 0x94 => unsafe { self.state.hl.as_u8s.left = res(self.state.hl.as_u8s.left, 2) },
// 0x95 => unsafe { self.state.hl.as_u8s.right = res(self.state.hl.as_u8s.right, 2) },
// 0x96 => unsafe {
// let rotated = res(self.memory.get(self.state.hl.as_u16), 2);
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0x97 => unsafe { self.state.af.as_u8s.left = res(self.state.af.as_u8s.left, 2) },
// 0x98 => unsafe { self.state.bc.as_u8s.left = res(self.state.bc.as_u8s.left, 3) },
// 0x99 => unsafe { self.state.bc.as_u8s.right = res(self.state.bc.as_u8s.right, 3) },
// 0x9A => unsafe { self.state.de.as_u8s.left = res(self.state.de.as_u8s.left, 3) },
// 0x9B => unsafe { self.state.de.as_u8s.right = res(self.state.de.as_u8s.right, 3) },
// 0x9C => unsafe { self.state.hl.as_u8s.left = res(self.state.hl.as_u8s.left, 3) },
// 0x9D => unsafe { self.state.hl.as_u8s.right = res(self.state.hl.as_u8s.right, 3) },
// 0x9E => unsafe {
// let rotated = res(self.memory.get(self.state.hl.as_u16), 3);
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0x9F => unsafe { self.state.af.as_u8s.left = res(self.state.af.as_u8s.left, 3) },
// 0xA0 => unsafe { self.state.bc.as_u8s.left = res(self.state.bc.as_u8s.left, 4) },
// 0xA1 => unsafe { self.state.bc.as_u8s.right = res(self.state.bc.as_u8s.right, 4) },
// 0xA2 => unsafe { self.state.de.as_u8s.left = res(self.state.de.as_u8s.left, 4) },
// 0xA3 => unsafe { self.state.de.as_u8s.right = res(self.state.de.as_u8s.right, 4) },
// 0xA4 => unsafe { self.state.hl.as_u8s.left = res(self.state.hl.as_u8s.left, 4) },
// 0xA5 => unsafe { self.state.hl.as_u8s.right = res(self.state.hl.as_u8s.right, 4) },
// 0xA6 => unsafe {
// let rotated = res(self.memory.get(self.state.hl.as_u16), 4);
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0xA7 => unsafe { self.state.af.as_u8s.left = res(self.state.af.as_u8s.left, 4) },
// 0xA8 => unsafe { self.state.bc.as_u8s.left = res(self.state.bc.as_u8s.left, 5) },
// 0xA9 => unsafe { self.state.bc.as_u8s.right = res(self.state.bc.as_u8s.right, 5) },
// 0xAA => unsafe { self.state.de.as_u8s.left = res(self.state.de.as_u8s.left, 5) },
// 0xAB => unsafe { self.state.de.as_u8s.right = res(self.state.de.as_u8s.right, 5) },
// 0xAC => unsafe { self.state.hl.as_u8s.left = res(self.state.hl.as_u8s.left, 5) },
// 0xAD => unsafe { self.state.hl.as_u8s.right = res(self.state.hl.as_u8s.right, 5) },
// 0xAE => unsafe {
// let rotated = res(self.memory.get(self.state.hl.as_u16), 5);
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0xAF => unsafe { self.state.af.as_u8s.left = res(self.state.af.as_u8s.left, 5) },
// 0xB0 => unsafe { self.state.bc.as_u8s.left = res(self.state.bc.as_u8s.left, 6) },
// 0xB1 => unsafe { self.state.bc.as_u8s.right = res(self.state.bc.as_u8s.right, 6) },
// 0xB2 => unsafe { self.state.de.as_u8s.left = res(self.state.de.as_u8s.left, 6) },
// 0xB3 => unsafe { self.state.de.as_u8s.right = res(self.state.de.as_u8s.right, 6) },
// 0xB4 => unsafe { self.state.hl.as_u8s.left = res(self.state.hl.as_u8s.left, 6) },
// 0xB5 => unsafe { self.state.hl.as_u8s.right = res(self.state.hl.as_u8s.right, 6) },
// 0xB6 => unsafe {
// let rotated = res(self.memory.get(self.state.hl.as_u16), 6);
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0xB7 => unsafe { self.state.af.as_u8s.left = res(self.state.af.as_u8s.left, 6) },
// 0xB8 => unsafe { self.state.bc.as_u8s.left = res(self.state.bc.as_u8s.left, 7) },
// 0xB9 => unsafe { self.state.bc.as_u8s.right = res(self.state.bc.as_u8s.right, 7) },
// 0xBA => unsafe { self.state.de.as_u8s.left = res(self.state.de.as_u8s.left, 7) },
// 0xBB => unsafe { self.state.de.as_u8s.right = res(self.state.de.as_u8s.right, 7) },
// 0xBC => unsafe { self.state.hl.as_u8s.left = res(self.state.hl.as_u8s.left, 7) },
// 0xBD => unsafe { self.state.hl.as_u8s.right = res(self.state.hl.as_u8s.right, 7) },
// 0xBE => unsafe {
// let rotated = res(self.memory.get(self.state.hl.as_u16), 7);
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0xBF => unsafe { self.state.af.as_u8s.left = res(self.state.af.as_u8s.left, 7) },
// 0xC0 => unsafe { self.state.bc.as_u8s.left = set(self.state.bc.as_u8s.left, 0) },
// 0xC1 => unsafe { self.state.bc.as_u8s.right = set(self.state.bc.as_u8s.right, 0) },
// 0xC2 => unsafe { self.state.de.as_u8s.left = set(self.state.de.as_u8s.left, 0) },
// 0xC3 => unsafe { self.state.de.as_u8s.right = set(self.state.de.as_u8s.right, 0) },
// 0xC4 => unsafe { self.state.hl.as_u8s.left = set(self.state.hl.as_u8s.left, 0) },
// 0xC5 => unsafe { self.state.hl.as_u8s.right = set(self.state.hl.as_u8s.right, 0) },
// 0xC6 => unsafe {
// let rotated = set(self.memory.get(self.state.hl.as_u16), 0);
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0xC7 => unsafe { self.state.af.as_u8s.left = set(self.state.af.as_u8s.left, 0) },
// 0xC8 => unsafe { self.state.bc.as_u8s.left = set(self.state.bc.as_u8s.left, 1) },
// 0xC9 => unsafe { self.state.bc.as_u8s.right = set(self.state.bc.as_u8s.right, 1) },
// 0xCA => unsafe { self.state.de.as_u8s.left = set(self.state.de.as_u8s.left, 1) },
// 0xCB => unsafe { self.state.de.as_u8s.right = set(self.state.de.as_u8s.right, 1) },
// 0xCC => unsafe { self.state.hl.as_u8s.left = set(self.state.hl.as_u8s.left, 1) },
// 0xCD => unsafe { self.state.hl.as_u8s.right = set(self.state.hl.as_u8s.right, 1) },
// 0xCE => unsafe {
// let rotated = set(self.memory.get(self.state.hl.as_u16), 1);
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0xCF => unsafe { self.state.af.as_u8s.left = set(self.state.af.as_u8s.left, 1) },
// 0xD0 => unsafe { self.state.bc.as_u8s.left = set(self.state.bc.as_u8s.left, 2) },
// 0xD1 => unsafe { self.state.bc.as_u8s.right = set(self.state.bc.as_u8s.right, 2) },
// 0xD2 => unsafe { self.state.de.as_u8s.left = set(self.state.de.as_u8s.left, 2) },
// 0xD3 => unsafe { self.state.de.as_u8s.right = set(self.state.de.as_u8s.right, 2) },
// 0xD4 => unsafe { self.state.hl.as_u8s.left = set(self.state.hl.as_u8s.left, 2) },
// 0xD5 => unsafe { self.state.hl.as_u8s.right = set(self.state.hl.as_u8s.right, 2) },
// 0xD6 => unsafe {
// let rotated = set(self.memory.get(self.state.hl.as_u16), 2);
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0xD7 => unsafe { self.state.af.as_u8s.left = set(self.state.af.as_u8s.left, 2) },
// 0xD8 => unsafe { self.state.bc.as_u8s.left = set(self.state.bc.as_u8s.left, 3) },
// 0xD9 => unsafe { self.state.bc.as_u8s.right = set(self.state.bc.as_u8s.right, 3) },
// 0xDA => unsafe { self.state.de.as_u8s.left = set(self.state.de.as_u8s.left, 3) },
// 0xDB => unsafe { self.state.de.as_u8s.right = set(self.state.de.as_u8s.right, 3) },
// 0xDC => unsafe { self.state.hl.as_u8s.left = set(self.state.hl.as_u8s.left, 3) },
// 0xDD => unsafe { self.state.hl.as_u8s.right = set(self.state.hl.as_u8s.right, 3) },
// 0xDE => unsafe {
// let rotated = set(self.memory.get(self.state.hl.as_u16), 3);
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0xDF => unsafe { self.state.af.as_u8s.left = set(self.state.af.as_u8s.left, 3) },
// 0xE0 => unsafe { self.state.bc.as_u8s.left = set(self.state.bc.as_u8s.left, 4) },
// 0xE1 => unsafe { self.state.bc.as_u8s.right = set(self.state.bc.as_u8s.right, 4) },
// 0xE2 => unsafe { self.state.de.as_u8s.left = set(self.state.de.as_u8s.left, 4) },
// 0xE3 => unsafe { self.state.de.as_u8s.right = set(self.state.de.as_u8s.right, 4) },
// 0xE4 => unsafe { self.state.hl.as_u8s.left = set(self.state.hl.as_u8s.left, 4) },
// 0xE5 => unsafe { self.state.hl.as_u8s.right = set(self.state.hl.as_u8s.right, 4) },
// 0xE6 => unsafe {
// let rotated = set(self.memory.get(self.state.hl.as_u16), 4);
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0xE7 => unsafe { self.state.af.as_u8s.left = set(self.state.af.as_u8s.left, 4) },
// 0xE8 => unsafe { self.state.bc.as_u8s.left = set(self.state.bc.as_u8s.left, 5) },
// 0xE9 => unsafe { self.state.bc.as_u8s.right = set(self.state.bc.as_u8s.right, 5) },
// 0xEA => unsafe { self.state.de.as_u8s.left = set(self.state.de.as_u8s.left, 5) },
// 0xEB => unsafe { self.state.de.as_u8s.right = set(self.state.de.as_u8s.right, 5) },
// 0xEC => unsafe { self.state.hl.as_u8s.left = set(self.state.hl.as_u8s.left, 5) },
// 0xED => unsafe { self.state.hl.as_u8s.right = set(self.state.hl.as_u8s.right, 5) },
// 0xEE => unsafe {
// let rotated = set(self.memory.get(self.state.hl.as_u16), 5);
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0xEF => unsafe { self.state.af.as_u8s.left = set(self.state.af.as_u8s.left, 5) },
// 0xF0 => unsafe { self.state.bc.as_u8s.left = set(self.state.bc.as_u8s.left, 6) },
// 0xF1 => unsafe { self.state.bc.as_u8s.right = set(self.state.bc.as_u8s.right, 6) },
// 0xF2 => unsafe { self.state.de.as_u8s.left = set(self.state.de.as_u8s.left, 6) },
// 0xF3 => unsafe { self.state.de.as_u8s.right = set(self.state.de.as_u8s.right, 6) },
// 0xF4 => unsafe { self.state.hl.as_u8s.left = set(self.state.hl.as_u8s.left, 6) },
// 0xF5 => unsafe { self.state.hl.as_u8s.right = set(self.state.hl.as_u8s.right, 6) },
// 0xF6 => unsafe {
// let rotated = set(self.memory.get(self.state.hl.as_u16), 6);
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0xF7 => unsafe { self.state.af.as_u8s.left = set(self.state.af.as_u8s.left, 6) },
// 0xF8 => unsafe { self.state.bc.as_u8s.left = set(self.state.bc.as_u8s.left, 7) },
// 0xF9 => unsafe { self.state.bc.as_u8s.right = set(self.state.bc.as_u8s.right, 7) },
// 0xFA => unsafe { self.state.de.as_u8s.left = set(self.state.de.as_u8s.left, 7) },
// 0xFB => unsafe { self.state.de.as_u8s.right = set(self.state.de.as_u8s.right, 7) },
// 0xFC => unsafe { self.state.hl.as_u8s.left = set(self.state.hl.as_u8s.left, 7) },
// 0xFD => unsafe { self.state.hl.as_u8s.right = set(self.state.hl.as_u8s.right, 7) },
// 0xFE => unsafe {
// let rotated = set(self.memory.get(self.state.hl.as_u16), 7);
// self.memory.set(self.state.hl.as_u16, rotated)
// },
// 0xFF => unsafe { self.state.af.as_u8s.left = set(self.state.af.as_u8s.left, 7) },
// }
// }
#[allow(dead_code)]
fn instruction_length(&self, _opcode: u8) -> u8 {
1
2023-01-22 09:39:45 +11:00
}
}
fn undefined(opcode: u8) {
panic!("Undefined behaviour: opcode {:#X}", opcode);
}