From 6517b66f3e9f3be8d709872652432eab541b709e Mon Sep 17 00:00:00 2001 From: hap Date: Sun, 24 Mar 2024 22:46:26 +0100 Subject: [PATCH] avr8: fix SBIW V flag once more --- src/devices/cpu/avr8/avr8ops.hxx | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/devices/cpu/avr8/avr8ops.hxx b/src/devices/cpu/avr8/avr8ops.hxx index 0ac10342616..614adac97b5 100644 --- a/src/devices/cpu/avr8/avr8ops.hxx +++ b/src/devices/cpu/avr8/avr8ops.hxx @@ -1234,10 +1234,10 @@ void avr8_base_device::op_adiw(uint16_t op) if (BIT(pd, 15)) { m_r[SREG] |= SREG_MASK_N; - if (!BIT(rr, 7)) - m_r[SREG] |= SREG_MASK_V; - else + if (BIT(rr, 7)) m_r[SREG] |= SREG_MASK_S; + else + m_r[SREG] |= SREG_MASK_V; } else { @@ -1258,14 +1258,17 @@ void avr8_base_device::op_sbiw(uint16_t op) m_r[SREG] &= ~(SREG_MASK_V | SREG_MASK_N | SREG_MASK_S | SREG_MASK_Z | SREG_MASK_C); if (BIT(pd, 15)) { - m_r[SREG] |= SREG_MASK_N; + m_r[SREG] |= SREG_MASK_N | SREG_MASK_S; if (!BIT(rr, 7)) - m_r[SREG] |= SREG_MASK_V | SREG_MASK_C; - else - m_r[SREG] |= SREG_MASK_S; + m_r[SREG] |= SREG_MASK_C; + } + else + { + if (pd == 0) + m_r[SREG] |= SREG_MASK_Z; + if (BIT(rr, 7)) + m_r[SREG] |= SREG_MASK_V | SREG_MASK_S; } - else if (pd == 0) - m_r[SREG] |= SREG_MASK_Z; m_r[24 + (DCONST(op) << 1)] = pd & 0x00ff; m_r[25 + (DCONST(op) << 1)] = (pd >> 8) & 0x00ff; }