From e4432448f189f7551ddb1fb73eea91b41b0c285b Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Sun, 20 Mar 2022 21:39:22 +0100 Subject: [PATCH] sign extend during shift --- cpu.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cpu.cpp b/cpu.cpp index c987f20..24ed396 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -489,7 +489,12 @@ bool cpu::additional_double_operand_instructions(const uint16_t instr) R <<= 1; } else { - R >>= 64 - shift - 1; + // extend sign-bit + if (R & 0x8000) // convert to unsigned 32b int & extend sign + R = (uint32_t(R) | 0xffff0000) >> (64 - shift - 1); + else + R >>= 64 - shift - 1; + setPSW_c(R & 1); R >>= 1; } @@ -522,7 +527,12 @@ bool cpu::additional_double_operand_instructions(const uint16_t instr) R0R1 <<= 1; } else { - R0R1 >>= 64 - shift - 1; + // extend sign-bit + if (R0R1 & 0x80000000) // convert to unsigned 64b int & extend sign + R0R1 = (uint64_t(R0R1) | 0xffffffff0000) >> (64 - shift - 1); + else + R0R1 >>= 64 - shift - 1; + setPSW_c(R0R1 & 1);