diff --git a/src/emulator/instructions/arithmetic.rs b/src/emulator/instructions/arithmetic.rs index d8dc7d6..e0eaf4a 100644 --- a/src/emulator/instructions/arithmetic.rs +++ b/src/emulator/instructions/arithmetic.rs @@ -13,3 +13,9 @@ pub fn add(register: Register, state: &mut EmulatorState) { set_cc(state, result); state.a = (result & 0xff) as u8; } + +pub fn adi(byte: u8, state: &mut EmulatorState) { + let result = state.a as u16 + byte as u16; + set_cc(state, result); + state.a = result as u8; +} diff --git a/src/emulator/main.rs b/src/emulator/main.rs index 75da473..b324297 100644 --- a/src/emulator/main.rs +++ b/src/emulator/main.rs @@ -1,5 +1,5 @@ use std::{fs, env}; -use instructions::arithmetic::add; +use instructions::arithmetic; mod instructions; @@ -34,6 +34,7 @@ pub struct ConditionCodes { ac: bool, } +#[derive(PartialEq)] pub enum Register { B, C, D, E, H, L, M, A, @@ -120,9 +121,10 @@ fn tick(state: &mut EmulatorState) { }; match instruction { - 0x0 => {} // NOP - 0x80..=0x87 => add(register_from_num(instruction & 0xf), state), // ADD - _ => not_implemented(state), + 0x00 => {} // NOP + 0x80..=0x87 => arithmetic::add(register_from_num(instruction & 0xf), state), // ADD + 0xc6 => arithmetic::adi(next_byte(), state), // ADI + _ => not_implemented(state), } state.pc += 1;