diff --git a/src/emulator/instructions/arithmetic.rs b/src/emulator/instructions/arithmetic.rs index f376bd2..6a5f77f 100644 --- a/src/emulator/instructions/arithmetic.rs +++ b/src/emulator/instructions/arithmetic.rs @@ -57,6 +57,16 @@ bitwise_op!(and, and_reg, &); bitwise_op!(or, or_reg, |); bitwise_op!(xor, xor_reg, ^); +pub fn cmp_reg(register: Register, state: &mut EmulatorState) { + cmp(get_register(register, state), state); +} + +pub fn cmp(byte: u8, state: &mut EmulatorState) { + let (result, carry) = state.a.overflowing_sub(byte); + state.cc.c = carry; + set_cc(state, result); +} + /// 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 d41dcc5..5cc4584 100644 --- a/src/emulator/main.rs +++ b/src/emulator/main.rs @@ -124,9 +124,11 @@ fn tick(state: &mut EmulatorState) { 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 + 0xb8..=0xbf => arithmetic::cmp_reg(register_from_num(instruction & 0xf), state), // CMP 0xe6 => arithmetic::and(next_byte(), state), // ANI 0xee => arithmetic::xor(next_byte(), state), // XRI 0xf6 => arithmetic::or(next_byte(), state), // ORI + 0xfe => arithmetic::cmp(next_byte(), state), // CPI _ => not_implemented(state), }