diff --git a/src/emulator/instructions/arithmetic.rs b/src/emulator/instructions/arithmetic.rs index b3e001a..f376bd2 100644 --- a/src/emulator/instructions/arithmetic.rs +++ b/src/emulator/instructions/arithmetic.rs @@ -38,6 +38,25 @@ pub fn sub(byte: u8, borrow: bool, state: &mut EmulatorState) { state.a = result; } +macro_rules! bitwise_op { + ($name:ident, $reg_name:ident, $op:tt) => { + pub fn $reg_name(register: Register, state: &mut EmulatorState) { + $name(get_register(register, state), state); + } + + pub fn $name(byte: u8, state: &mut EmulatorState) { + let result = state.a $op byte; + state.cc.c = false; + set_cc(state, result); + state.a = result; + } + } +} + +bitwise_op!(and, and_reg, &); +bitwise_op!(or, or_reg, |); +bitwise_op!(xor, xor_reg, ^); + /// Double precision add - Add B&C, D&E or H&L to H&L pub fn dad(register: Register, state: &mut EmulatorState) { let num = get_register_pair(register, state); diff --git a/src/emulator/main.rs b/src/emulator/main.rs index 859423b..d41dcc5 100644 --- a/src/emulator/main.rs +++ b/src/emulator/main.rs @@ -121,6 +121,13 @@ fn tick(state: &mut EmulatorState) { 0xd6 => arithmetic::sub(next_byte(), false, state), // SUI 0xde => arithmetic::sub(next_byte(), state.cc.c, state), // SBI + 0xa0..=0xa7 => arithmetic::and_reg(register_from_num(instruction & 0xf), state), // ANA + 0xa8..=0xaf => arithmetic::xor_reg(register_from_num(instruction & 0xf), state), // XRA + 0xb0..=0xb7 => arithmetic::or_reg(register_from_num(instruction & 0xf), state), // ORA + 0xe6 => arithmetic::and(next_byte(), state), // ANI + 0xee => arithmetic::xor(next_byte(), state), // XRI + 0xf6 => arithmetic::or(next_byte(), state), // ORI + _ => not_implemented(state), }