fix wrong registers being parsed from instructions

This commit is contained in:
Martin Löffler 2023-01-26 04:29:58 +01:00
parent d8cf03afa1
commit 08a15a2e51
Signed by: FatalErrorCoded
GPG key ID: FFEF368AC076566A
2 changed files with 9 additions and 8 deletions

View file

@ -116,20 +116,20 @@ fn tick(state: &mut EmulatorState) {
0x37 => state.cc.c = true, // STC
0x3f => state.cc.c = !state.cc.c, // CMC
0x80..=0x87 => arithmetic::add_reg(register_from_num(instruction & 0xf), false, state), // ADD
0x88..=0x8f => arithmetic::add_reg(register_from_num(instruction & 0xf), state.cc.c, state), // ADC
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
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
0x90..=0x97 => arithmetic::sub_reg(register_from_num(instruction & 0x7), false, state), // SUB
0x98..=0x9f => arithmetic::sub_reg(register_from_num(instruction & 0x7), state.cc.c, state), // SBB
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
0xb8..=0xbf => arithmetic::cmp_reg(register_from_num(instruction & 0xf), state), // CMP
0xa0..=0xa7 => arithmetic::and_reg(register_from_num(instruction & 0x7), state), // ANA
0xa8..=0xaf => arithmetic::xor_reg(register_from_num(instruction & 0x7), state), // XRA
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
0xee => arithmetic::xor(next_byte(), state), // XRI
0xf6 => arithmetic::or(next_byte(), state), // ORI

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
#[track_caller]
pub fn register_from_num(b: u8) -> Register {
match b {
0 => Register::B,