bitwise instructions

This commit is contained in:
Martin Löffler 2023-01-26 03:52:50 +01:00
parent c29389d3eb
commit c61c814e55
Signed by: FatalErrorCoded
GPG key ID: FFEF368AC076566A
2 changed files with 26 additions and 0 deletions
src/emulator

View file

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

View file

@ -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),
}