Fix 16-bit shift and rotate result truncation master
authorRobert Pengelly <robertapengelly@hotmail.com>
Sat, 17 Oct 2026 09:28:32 +0000 (10:28 +0100)
committerRobert Pengelly <robertapengelly@hotmail.com>
Sat, 17 Oct 2026 09:28:32 +0000 (10:28 +0100)
cpu.c

diff --git a/cpu.c b/cpu.c
index 8c03315e740df940fbf04d06c73b178555316284..3f42cde568e31f800f22a12fae3bbff4119d5a36 100644 (file)
--- a/cpu.c
+++ b/cpu.c
@@ -2930,9 +2930,10 @@ fetch_instruction:
         
         case 0xC1: {           /*16-bit Shift/Rotate by imm8 (80186+) */
         
-            uint8_t modrm = fetch8 (cpu), result;
+            uint8_t modrm = fetch8 (cpu);
             int subop = (modrm >> 3) & 7;
             
+            uint16_t result;
             OperandRef rm = decode_rm_operand (cpu, modrm);
             
             uint16_t val = operand_read16 (cpu, &rm);
@@ -3138,7 +3139,7 @@ fetch_instruction:
                 
                     if (count > 16) {
                     
-                        result = (val & 0x8000) ? 0xFFFF : 0x0000;
+                        result = (uint16_t) ((val & 0x8000) ? 0xFFFF : 0x0000);
                         
                         if (val & 0x8000) {
                             cpu->flags |= FLAG_CF;