forked from Lea/invadeez
bitwise instructions
This commit is contained in:
parent
c29389d3eb
commit
c61c814e55
src/emulator
|
@ -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);
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue