forked from Lea/invadeez
subtraction
This commit is contained in:
parent
51d2e29775
commit
c29389d3eb
|
@ -25,6 +25,19 @@ pub fn add(byte: u8, carry: bool, state: &mut EmulatorState) {
|
||||||
state.a = result;
|
state.a = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn sub_reg(register: Register, borrow: bool, state: &mut EmulatorState) {
|
||||||
|
sub(get_register(register, state), borrow, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn sub(byte: u8, borrow: bool, state: &mut EmulatorState) {
|
||||||
|
let (a, first) = state.a.overflowing_sub(byte);
|
||||||
|
let (result, second) = a.overflowing_sub(borrow as u8);
|
||||||
|
|
||||||
|
state.cc.c = first != second;
|
||||||
|
set_cc(state, result);
|
||||||
|
state.a = result;
|
||||||
|
}
|
||||||
|
|
||||||
/// Double precision add - Add B&C, D&E or H&L to H&L
|
/// Double precision add - Add B&C, D&E or H&L to H&L
|
||||||
pub fn dad(register: Register, state: &mut EmulatorState) {
|
pub fn dad(register: Register, state: &mut EmulatorState) {
|
||||||
let num = get_register_pair(register, state);
|
let num = get_register_pair(register, state);
|
||||||
|
|
|
@ -116,6 +116,11 @@ fn tick(state: &mut EmulatorState) {
|
||||||
0xc6 => arithmetic::add(next_byte(), false, state), // ADI
|
0xc6 => arithmetic::add(next_byte(), false, state), // ADI
|
||||||
0xce => arithmetic::add(next_byte(), state.cc.c, state), // ACI
|
0xce => arithmetic::add(next_byte(), state.cc.c, state), // ACI
|
||||||
|
|
||||||
|
0x90..=0x97 => arithmetic::sub_reg(register_from_num(instruction & 0xf), false, state), // SUB
|
||||||
|
0x98..=0x9f => arithmetic::sub_reg(register_from_num(instruction & 0xf), state.cc.c, state), // SBB
|
||||||
|
0xd6 => arithmetic::sub(next_byte(), false, state), // SUI
|
||||||
|
0xde => arithmetic::sub(next_byte(), state.cc.c, state), // SBI
|
||||||
|
|
||||||
_ => not_implemented(state),
|
_ => not_implemented(state),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue