implement ADI

This commit is contained in:
Lea 2023-01-25 15:32:39 +01:00
parent a867c30f16
commit 06447c917a
Signed by: Lea
GPG key ID: 1BAFFE8347019C42
2 changed files with 12 additions and 4 deletions

View file

@ -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;
}

View file

@ -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,8 +121,9 @@ fn tick(state: &mut EmulatorState) {
};
match instruction {
0x0 => {} // NOP
0x80..=0x87 => add(register_from_num(instruction & 0xf), state), // ADD
0x00 => {} // NOP
0x80..=0x87 => arithmetic::add(register_from_num(instruction & 0xf), state), // ADD
0xc6 => arithmetic::adi(next_byte(), state), // ADI
_ => not_implemented(state),
}