Compare commits

..

3 commits

3 changed files with 25 additions and 7 deletions

View file

@ -57,6 +57,16 @@ bitwise_op!(and, and_reg, &);
bitwise_op!(or, or_reg, |); bitwise_op!(or, or_reg, |);
bitwise_op!(xor, xor_reg, ^); bitwise_op!(xor, xor_reg, ^);
pub fn cmp_reg(register: Register, state: &mut EmulatorState) {
cmp(get_register(register, state), state);
}
pub fn cmp(byte: u8, state: &mut EmulatorState) {
let (result, carry) = state.a.overflowing_sub(byte);
state.cc.c = carry;
set_cc(state, 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);

View file

@ -111,22 +111,29 @@ fn tick(state: &mut EmulatorState) {
0x2b => arithmetic::dcx(Register::H, state), 0x2b => arithmetic::dcx(Register::H, state),
0x3b => arithmetic::dcx(Register::SP, state), 0x3b => arithmetic::dcx(Register::SP, state),
0x80..=0x87 => arithmetic::add_reg(register_from_num(instruction & 0xf), false, state), // ADD 0x27 => panic!("Auxiliary Carry not implemented, unable to execute DAA instruction"),
0x88..=0x8f => arithmetic::add_reg(register_from_num(instruction & 0xf), state.cc.c, state), // ADC 0x2f => state.a = !state.a, // CMA
0x37 => state.cc.c = true, // STC
0x3f => state.cc.c = !state.cc.c, // CMC
0x80..=0x87 => arithmetic::add_reg(register_from_num(instruction & 0x7), false, state), // ADD
0x88..=0x8f => arithmetic::add_reg(register_from_num(instruction & 0x7), state.cc.c, state), // ADC
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 0x90..=0x97 => arithmetic::sub_reg(register_from_num(instruction & 0x7), false, state), // SUB
0x98..=0x9f => arithmetic::sub_reg(register_from_num(instruction & 0xf), state.cc.c, state), // SBB 0x98..=0x9f => arithmetic::sub_reg(register_from_num(instruction & 0x7), state.cc.c, state), // SBB
0xd6 => arithmetic::sub(next_byte(), false, state), // SUI 0xd6 => arithmetic::sub(next_byte(), false, state), // SUI
0xde => arithmetic::sub(next_byte(), state.cc.c, state), // SBI 0xde => arithmetic::sub(next_byte(), state.cc.c, state), // SBI
0xa0..=0xa7 => arithmetic::and_reg(register_from_num(instruction & 0xf), state), // ANA 0xa0..=0xa7 => arithmetic::and_reg(register_from_num(instruction & 0x7), state), // ANA
0xa8..=0xaf => arithmetic::xor_reg(register_from_num(instruction & 0xf), state), // XRA 0xa8..=0xaf => arithmetic::xor_reg(register_from_num(instruction & 0x7), state), // XRA
0xb0..=0xb7 => arithmetic::or_reg(register_from_num(instruction & 0xf), state), // ORA 0xb0..=0xb7 => arithmetic::or_reg(register_from_num(instruction & 0x7), state), // ORA
0xb8..=0xbf => arithmetic::cmp_reg(register_from_num(instruction & 0x7), state), // CMP
0xe6 => arithmetic::and(next_byte(), state), // ANI 0xe6 => arithmetic::and(next_byte(), state), // ANI
0xee => arithmetic::xor(next_byte(), state), // XRI 0xee => arithmetic::xor(next_byte(), state), // XRI
0xf6 => arithmetic::or(next_byte(), state), // ORI 0xf6 => arithmetic::or(next_byte(), state), // ORI
0xfe => arithmetic::cmp(next_byte(), state), // CPI
_ => not_implemented(state), _ => not_implemented(state),
} }

View file

@ -51,6 +51,7 @@ pub enum Register {
} }
/// Returns a Register enum based on the input number 0..7 in the order B,C,D,E,H,L,M,A /// Returns a Register enum based on the input number 0..7 in the order B,C,D,E,H,L,M,A
#[track_caller]
pub fn register_from_num(b: u8) -> Register { pub fn register_from_num(b: u8) -> Register {
match b { match b {
0 => Register::B, 0 => Register::B,