From 827167683b9bbcf99afad5b85c5c3cbb51890f2d Mon Sep 17 00:00:00 2001 From: hap Date: Sun, 8 Jan 2023 18:51:47 +0100 Subject: pic16c5x: no need for m_old_data class variable --- src/devices/cpu/pic16c5x/pic16c5x.cpp | 63 ++++++++++++++--------------------- src/devices/cpu/pic16c5x/pic16c5x.h | 7 ++-- 2 files changed, 27 insertions(+), 43 deletions(-) diff --git a/src/devices/cpu/pic16c5x/pic16c5x.cpp b/src/devices/cpu/pic16c5x/pic16c5x.cpp index 7f9757ab436..05aa42eca34 100644 --- a/src/devices/cpu/pic16c5x/pic16c5x.cpp +++ b/src/devices/cpu/pic16c5x/pic16c5x.cpp @@ -309,44 +309,35 @@ void pic16c5x_device::calc_zero_flag() CLR(STATUS, Z_FLAG); } -void pic16c5x_device::CALCULATE_ADD_CARRY() +void pic16c5x_device::calc_add_flags(u8 augend) { - if (m_old_data > m_ALU) { + calc_zero_flag(); + + if (augend > m_ALU) SET(STATUS, C_FLAG); - } - else { + else CLR(STATUS, C_FLAG); - } -} -void pic16c5x_device::CALCULATE_ADD_DIGITCARRY() -{ - if ((m_old_data & 0x0f) > (m_ALU & 0x0f)) { + if ((augend & 0x0f) > (m_ALU & 0x0f)) SET(STATUS, DC_FLAG); - } - else { + else CLR(STATUS, DC_FLAG); - } + } -void pic16c5x_device::CALCULATE_SUB_CARRY() +void pic16c5x_device::calc_sub_flags(u8 minuend) { - if (m_old_data < m_ALU) { + calc_zero_flag(); + + if (minuend < m_ALU) CLR(STATUS, C_FLAG); - } - else { + else SET(STATUS, C_FLAG); - } -} -void pic16c5x_device::CALCULATE_SUB_DIGITCARRY() -{ - if ((m_old_data & 0x0f) < (m_ALU & 0x0f)) { + if ((minuend & 0x0f) < (m_ALU & 0x0f)) CLR(STATUS, DC_FLAG); - } - else { + else SET(STATUS, DC_FLAG); - } } @@ -573,12 +564,10 @@ void pic16c5x_device::illegal() void pic16c5x_device::addwf() { - m_old_data = get_regfile(ADDR); - m_ALU = m_old_data + m_W; + u8 augend = get_regfile(ADDR); + m_ALU = augend + m_W; store_result(ADDR, m_ALU); - calc_zero_flag(); - CALCULATE_ADD_CARRY(); - CALCULATE_ADD_DIGITCARRY(); + calc_add_flags(augend); } void pic16c5x_device::andwf() @@ -747,12 +736,12 @@ void pic16c5x_device::retlw() void pic16c5x_device::rlf() { m_ALU = get_regfile(ADDR); - u8 bit7 = m_ALU & 0x80; + int carry = BIT(m_ALU, 7); m_ALU <<= 1; if (STATUS & C_FLAG) m_ALU |= 1; store_result(ADDR, m_ALU); - if (bit7) + if (carry) SET(STATUS, C_FLAG); else CLR(STATUS, C_FLAG); @@ -761,12 +750,12 @@ void pic16c5x_device::rlf() void pic16c5x_device::rrf() { m_ALU = get_regfile(ADDR); - u8 bit0 = m_ALU & 1; + int carry = BIT(m_ALU, 0); m_ALU >>= 1; if (STATUS & C_FLAG) m_ALU |= 0x80; store_result(ADDR, m_ALU); - if (bit0) + if (carry) SET(STATUS, C_FLAG); else CLR(STATUS, C_FLAG); @@ -782,12 +771,10 @@ void pic16c5x_device::sleepic() void pic16c5x_device::subwf() { - m_old_data = get_regfile(ADDR); - m_ALU = m_old_data - m_W; + u8 minuend = get_regfile(ADDR); + m_ALU = minuend - m_W; store_result(ADDR, m_ALU); - calc_zero_flag(); - CALCULATE_SUB_CARRY(); - CALCULATE_SUB_DIGITCARRY(); + calc_sub_flags(minuend); } void pic16c5x_device::swapf() diff --git a/src/devices/cpu/pic16c5x/pic16c5x.h b/src/devices/cpu/pic16c5x/pic16c5x.h index 3dd2aca758a..171890538a1 100644 --- a/src/devices/cpu/pic16c5x/pic16c5x.h +++ b/src/devices/cpu/pic16c5x/pic16c5x.h @@ -140,7 +140,6 @@ private: u16 m_temp_config; int m_rtcc; int m_count_cycles; - u8 m_old_data; u8 m_data_mask; u16 m_program_mask; u8 m_status_mask; @@ -174,10 +173,8 @@ private: void update_internalram_ptr(); void calc_zero_flag(); - void CALCULATE_ADD_CARRY(); - void CALCULATE_ADD_DIGITCARRY(); - void CALCULATE_SUB_CARRY(); - void CALCULATE_SUB_DIGITCARRY(); + void calc_add_flags(u8 augend); + void calc_sub_flags(u8 minuend); u16 pop_stack(); void push_stack(u16 data); void set_pc(offs_t addr); -- cgit v1.2.3