diff --git a/src/devices/cpu/unsp/unsp.cpp b/src/devices/cpu/unsp/unsp.cpp index 3703735f886..72d8ef35d07 100644 --- a/src/devices/cpu/unsp/unsp.cpp +++ b/src/devices/cpu/unsp/unsp.cpp @@ -393,10 +393,10 @@ void unsp_device::state_import(const device_state_entry &entry) /*****************************************************************************/ -void unsp_device::update_nzsc(uint32_t value, int32_t svalue) +void unsp_device::update_nzsc(uint32_t value, uint16_t r0, uint16_t r1) { m_core->m_r[REG_SR] &= ~(UNSP_N | UNSP_Z | UNSP_S | UNSP_C); - if (svalue < 0) + if (BIT(value, 16) != BIT((r0 ^ r1), 15)) m_core->m_r[REG_SR] |= UNSP_S; if (BIT(value, 15)) m_core->m_r[REG_SR] |= UNSP_N; diff --git a/src/devices/cpu/unsp/unsp.h b/src/devices/cpu/unsp/unsp.h index 38f04ee56df..4515e82bab4 100644 --- a/src/devices/cpu/unsp/unsp.h +++ b/src/devices/cpu/unsp/unsp.h @@ -234,7 +234,7 @@ protected: uint16_t pop(uint32_t *reg); void update_nz(uint32_t value); - void update_nzsc(uint32_t value, int32_t svalue); + void update_nzsc(uint32_t value, uint16_t r0, uint16_t r1); bool do_basic_alu_ops(const uint16_t& op0, uint32_t& lres, uint16_t& r0, uint16_t& r1, uint32_t& r2, bool update_flags); private: diff --git a/src/devices/cpu/unsp/unsp_other.cpp b/src/devices/cpu/unsp/unsp_other.cpp index d02e9ee579e..2300f2a5bc0 100644 --- a/src/devices/cpu/unsp/unsp_other.cpp +++ b/src/devices/cpu/unsp/unsp_other.cpp @@ -281,46 +281,40 @@ void unsp_device::execute_remaining(const uint16_t op) bool unsp_device::do_basic_alu_ops(const uint16_t &op0, uint32_t &lres, uint16_t &r0, uint16_t &r1, uint32_t &r2, bool update_flags) { - int32_t sres = 0; switch (op0) { case 0x00: // Add { lres = r0 + r1; - sres = (int16_t)r0 + (int16_t)r1; if (update_flags) - update_nzsc(lres, sres); + update_nzsc(lres, r0, r1); break; } case 0x01: // Add w/ carry { uint32_t c = (m_core->m_r[REG_SR] & UNSP_C) ? 1 : 0; lres = r0 + r1 + c; - sres = (int16_t)r0 + (int16_t)r1 + (int16_t)c; if (update_flags) - update_nzsc(lres, sres); + update_nzsc(lres, r0, r1); break; } case 0x02: // Subtract lres = r0 + (uint16_t)(~r1) + uint32_t(1); - sres = (int16_t)r0 - (int16_t)r1; if (update_flags) - update_nzsc(lres, sres); + update_nzsc(lres, r0, ~r1); break; case 0x03: // Subtract w/ carry { uint32_t c = (m_core->m_r[REG_SR] & UNSP_C) ? 1 : 0; lres = r0 + (uint16_t)(~r1) + c; - sres = (int16_t)r0 - ((int16_t)r1 - (int16_t)c); if (update_flags) - update_nzsc(lres, sres); + update_nzsc(lres, r0, ~r1); break; } case 0x04: // Compare lres = r0 + (uint16_t)(~r1) + uint32_t(1); - sres = (int16_t)r0 - (int16_t)r1; if (update_flags) - update_nzsc(lres, sres); + update_nzsc(lres, r0, ~r1); return false; case 0x06: // Negate lres = -r1;