From 598be2464410327ca7c1e21138b17846997aae35 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 25 May 2017 21:23:38 -0400 Subject: [PATCH] Fixed overflow for 8-bit decrementing. --- Processors/Z80/Z80.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Processors/Z80/Z80.hpp b/Processors/Z80/Z80.hpp index 29a7bad6d..f32a6455b 100644 --- a/Processors/Z80/Z80.hpp +++ b/Processors/Z80/Z80.hpp @@ -726,9 +726,9 @@ template class Processor: public MicroOpScheduler { uint8_t value = *(uint8_t *)operation->source; int result = value - 1; - // with an increment, overflow occurs if the sign changes from - // positive to negative - int overflow = (value ^ result) & ~value; + // with a decrement, overflow occurs if the sign changes from + // negative to positive + int overflow = (value ^ result) & value; int half_result = (value&0xf) - 1; *(uint8_t *)operation->source = (uint8_t)result; @@ -918,7 +918,7 @@ template class Processor: public MicroOpScheduler { @returns The current value of the flags register. */ uint8_t get_flags() { - return + uint8_t result = (sign_result_ & Flag::Sign) | (zero_result_ ? 0 : Flag::Zero) | (bit5_result_ & Flag::Bit5) | @@ -927,6 +927,7 @@ template class Processor: public MicroOpScheduler { parity_overflow_flag_ | subtract_flag_ | carry_flag_; + return result; } /*!