From 06447c917a6a7ef90be7f7c463a1a03b71ca9d55 Mon Sep 17 00:00:00 2001 From: Lea Date: Wed, 25 Jan 2023 15:32:39 +0100 Subject: [PATCH] implement ADI --- src/emulator/instructions/arithmetic.rs | 6 ++++++ src/emulator/main.rs | 10 ++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) 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;