Fix 32-bit TEST instructions and DOOM memory allocation hang
authorRobert Pengelly <robertapengelly@hotmail.com>
Sat, 24 Oct 2026 04:13:15 +0000 (05:13 +0100)
committerRobert Pengelly <robertapengelly@hotmail.com>
Sat, 24 Oct 2026 04:13:15 +0000 (05:13 +0100)
cpu.c

diff --git a/cpu.c b/cpu.c
index e407da41d9cde59d0737ca4db11c06a46102c011..d6cca025f616b145d3caeaf489eb2ff0270a7fa5 100644 (file)
--- a/cpu.c
+++ b/cpu.c
@@ -4339,10 +4339,12 @@ fetch_instruction:
             
             OperandRef rm = decode_rm_operand (cpu, modrm);
             
-            uint16_t val1 = operand_read16 (cpu, &rm);
-            uint16_t val2 = cpu->regs[reg & 7];
+            if (cpu->has_operand_override) {
+                and32 (cpu, operand_read32 (cpu, &rm), get_reg32 (cpu, reg));
+            } else {
+                and16 (cpu, operand_read16 (cpu, &rm), cpu->regs[reg]);
+            }
             
-            and16 (cpu, val1, val2);
             break;
         
         }
@@ -5030,11 +5032,14 @@ fetch_instruction:
         
         }
         
-        case 0xA9: {                    /* TEST AX, imm16 */
+        case 0xA9: {                    /* TEST AX/EAX, imm16/32 */
         
-            uint16_t imm16 = fetch16 (cpu);
+            if (cpu->has_operand_override) {
+                and32 (cpu, get_reg32 (cpu, REG_AX), fetch32 (cpu));
+            } else {
+                and16 (cpu, cpu->regs[REG_AX], fetch16 (cpu));
+            }
             
-            and16 (cpu, cpu->regs[REG_AX], imm16);
             break;
         
         }