[FAST486]
[reactos.git] / lib / fast486 / opcodes.c
index 1308503..500b8c7 100644 (file)
 
 /* INCLUDES *******************************************************************/
 
-// #define WIN32_NO_STATUS
-// #define _INC_WINDOWS
 #include <windef.h>
-#include <limits.h>
 
 // #define NDEBUG
 #include <debug.h>
@@ -466,12 +463,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIncrement)
     ULONG Value;
     BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
-
+    TOGGLE_OPSIZE(Size);
     NO_LOCK_PREFIX();
 
     /* Make sure this is the right instruction */
@@ -481,19 +473,19 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIncrement)
     {
         Value = ++State->GeneralRegs[Opcode & 0x07].Long;
 
-        State->Flags.Of = (Value == SIGN_FLAG_LONG) ? TRUE : FALSE;
-        State->Flags.Sf = (Value & SIGN_FLAG_LONG) ? TRUE : FALSE;
+        State->Flags.Of = (Value == SIGN_FLAG_LONG);
+        State->Flags.Sf = ((Value & SIGN_FLAG_LONG) != 0);
     }
     else
     {
         Value = ++State->GeneralRegs[Opcode & 0x07].LowWord;
 
-        State->Flags.Of = (Value == SIGN_FLAG_WORD) ? TRUE : FALSE;
-        State->Flags.Sf = (Value & SIGN_FLAG_WORD) ? TRUE : FALSE;
+        State->Flags.Of = (Value == SIGN_FLAG_WORD);
+        State->Flags.Sf = ((Value & SIGN_FLAG_WORD) != 0);
     }
 
-    State->Flags.Zf = (Value == 0) ? TRUE : FALSE;
-    State->Flags.Af = ((Value & 0x0F) == 0) ? TRUE : FALSE;
+    State->Flags.Zf = (Value == 0);
+    State->Flags.Af = ((Value & 0x0F) == 0);
     State->Flags.Pf = Fast486CalculateParity(LOBYTE(Value));
 
     /* Return success */
@@ -505,12 +497,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeDecrement)
     ULONG Value;
     BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
-    
+    TOGGLE_OPSIZE(Size);
     NO_LOCK_PREFIX();
 
     /* Make sure this is the right instruction */
@@ -520,19 +507,19 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeDecrement)
     {
         Value = --State->GeneralRegs[Opcode & 0x07].Long;
 
-        State->Flags.Of = (Value == (SIGN_FLAG_LONG - 1)) ? TRUE : FALSE;
-        State->Flags.Sf = (Value & SIGN_FLAG_LONG) ? TRUE : FALSE;
+        State->Flags.Of = (Value == (SIGN_FLAG_LONG - 1));
+        State->Flags.Sf = ((Value & SIGN_FLAG_LONG) != 0);
     }
     else
     {
         Value = --State->GeneralRegs[Opcode & 0x07].LowWord;
 
-        State->Flags.Of = (Value == (SIGN_FLAG_WORD - 1)) ? TRUE : FALSE;
-        State->Flags.Sf = (Value & SIGN_FLAG_WORD) ? TRUE : FALSE;
+        State->Flags.Of = (Value == (SIGN_FLAG_WORD - 1));
+        State->Flags.Sf = ((Value & SIGN_FLAG_WORD) != 0);
     }
 
-    State->Flags.Zf = (Value == 0) ? TRUE : FALSE;
-    State->Flags.Af = ((Value & 0x0F) == 0x0F) ? TRUE : FALSE;
+    State->Flags.Zf = (Value == 0);
+    State->Flags.Af = ((Value & 0x0F) == 0x0F);
     State->Flags.Pf = Fast486CalculateParity(LOBYTE(Value));
 
     /* Return success */
@@ -555,12 +542,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePopReg)
     ULONG Value;
     BOOLEAN Size = State->SegmentRegs[FAST486_REG_SS].Size;
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
-
+    TOGGLE_OPSIZE(Size);
     NO_LOCK_PREFIX();
 
     /* Make sure this is the right instruction */
@@ -579,13 +561,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePopReg)
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeNop)
 {
-    if (State->PrefixFlags & ~(FAST486_PREFIX_OPSIZE | FAST486_PREFIX_REP))
-    {
-        /* Allowed prefixes are REP and OPSIZE */
-        Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
-    }
-
     if (State->PrefixFlags & FAST486_PREFIX_REP)
     {
         /* Idle cycle */
@@ -600,12 +575,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeExchangeEax)
     INT Reg = Opcode & 0x07;
     BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
-
+    TOGGLE_OPSIZE(Size);
     NO_LOCK_PREFIX();
 
     /* Make sure this is the right instruction */
@@ -714,7 +684,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeShortConditionalJmp)
 
     if (Jump)
     {
-        /* Move the instruction pointer */        
+        /* Move the instruction pointer */
         State->InstPtr.Long += Offset;
     }
 
@@ -903,7 +873,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeHalt)
     }
 
     /* Halt */
-    while (!State->HardwareInt) State->IdleCallback(State);
+    while (State->IntStatus != FAST486_INT_SIGNAL) State->IdleCallback(State);
 
     /* Return success */
     return TRUE;
@@ -936,7 +906,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeInByte)
     }
 
     /* Read a byte from the I/O port */
-    State->IoReadCallback(State, Port, &Data, sizeof(UCHAR));
+    State->IoReadCallback(State, Port, &Data, 1, sizeof(UCHAR));
 
     /* Store the result in AL */
     State->GeneralRegs[FAST486_REG_EAX].LowByte = Data;
@@ -952,12 +922,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIn)
     /* Make sure this is the right instruction */
     ASSERT((Opcode & 0xF7) == 0xE5);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
-
+    TOGGLE_OPSIZE(Size);
     NO_LOCK_PREFIX();
 
     if (Opcode == 0xE5)
@@ -985,7 +950,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIn)
         ULONG Data;
 
         /* Read a dword from the I/O port */
-        State->IoReadCallback(State, Port, &Data, sizeof(ULONG));
+        State->IoReadCallback(State, Port, &Data, 1, sizeof(ULONG));
 
         /* Store the value in EAX */
         State->GeneralRegs[FAST486_REG_EAX].Long = Data;
@@ -995,7 +960,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIn)
         USHORT Data;
 
         /* Read a word from the I/O port */
-        State->IoReadCallback(State, Port, &Data, sizeof(USHORT));
+        State->IoReadCallback(State, Port, &Data, 1, sizeof(USHORT));
 
         /* Store the value in AX */
         State->GeneralRegs[FAST486_REG_EAX].LowWord = Data;
@@ -1032,9 +997,9 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOutByte)
 
     /* Read the value from AL */
     Data = State->GeneralRegs[FAST486_REG_EAX].LowByte;
-    
+
     /* Write the byte to the I/O port */
-    State->IoWriteCallback(State, Port, &Data, sizeof(UCHAR));
+    State->IoWriteCallback(State, Port, &Data, 1, sizeof(UCHAR));
 
     return TRUE;
 }
@@ -1047,12 +1012,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOut)
     /* Make sure this is the right instruction */
     ASSERT((Opcode & 0xF7) == 0xE7);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
-
+    TOGGLE_OPSIZE(Size);
     NO_LOCK_PREFIX();
 
     if (Opcode == 0xE7)
@@ -1081,7 +1041,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOut)
         ULONG Data = State->GeneralRegs[FAST486_REG_EAX].Long;
 
         /* Write a dword to the I/O port */
-        State->IoReadCallback(State, Port, &Data, sizeof(ULONG));
+        State->IoWriteCallback(State, Port, &Data, 1, sizeof(ULONG));
     }
     else
     {
@@ -1089,7 +1049,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOut)
         USHORT Data = State->GeneralRegs[FAST486_REG_EAX].LowWord;
 
         /* Write a word to the I/O port */
-        State->IoWriteCallback(State, Port, &Data, sizeof(USHORT));
+        State->IoWriteCallback(State, Port, &Data, 1, sizeof(USHORT));
     }
 
     return TRUE;
@@ -1109,7 +1069,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeShortJump)
         return FALSE;
     }
 
-    /* Move the instruction pointer */        
+    /* Move the instruction pointer */
     State->InstPtr.Long += Offset;
 
     return TRUE;
@@ -1122,12 +1082,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovRegImm)
     /* Make sure this is the right instruction */
     ASSERT((Opcode & 0xF8) == 0xB8);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
-
+    TOGGLE_OPSIZE(Size);
     NO_LOCK_PREFIX();
 
     if (Size)
@@ -1206,20 +1161,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddByteModrm)
     /* Make sure this is the right instruction */
     ASSERT((Opcode & 0xFD) == 0x00);
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the size */
-        AddressSize = !AddressSize;
-    }
-    else if (State->PrefixFlags
-             & ~(FAST486_PREFIX_ADSIZE
-             | FAST486_PREFIX_SEG
-             | FAST486_PREFIX_LOCK))
-    {
-        /* Invalid prefix */
-        Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
-    }
+    TOGGLE_ADSIZE(AddressSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -1244,9 +1186,9 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddByteModrm)
     State->Flags.Cf = (Result < FirstValue) && (Result < SecondValue);
     State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) == (SecondValue & SIGN_FLAG_BYTE))
                       && ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE));
-    State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
-    State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-    State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+    State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0);
+    State->Flags.Zf = (Result == 0);
+    State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Write back the result */
@@ -1266,17 +1208,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddModrm)
 
     OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the address size */
-        AddressSize = !AddressSize;
-    }
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the operand size */
-        OperandSize = !OperandSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
+    TOGGLE_OPSIZE(OperandSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -1298,7 +1231,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddModrm)
             /* Exception occurred */
             return FALSE;
         }
-    
+
         /* Calculate the result */
         Result = FirstValue + SecondValue;
 
@@ -1306,9 +1239,9 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddModrm)
         State->Flags.Cf = (Result < FirstValue) && (Result < SecondValue);
         State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) == (SecondValue & SIGN_FLAG_LONG))
                           && ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG));
-        State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+        State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0);
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -1329,7 +1262,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddModrm)
             /* Exception occurred */
             return FALSE;
         }
-    
+
         /* Calculate the result */
         Result = FirstValue + SecondValue;
 
@@ -1337,9 +1270,9 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddModrm)
         State->Flags.Cf = (Result < FirstValue) && (Result < SecondValue);
         State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) == (SecondValue & SIGN_FLAG_WORD))
                           && ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD));
-        State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+        State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0);
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -1378,9 +1311,9 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddAl)
     State->Flags.Cf = (Result < FirstValue) && (Result < SecondValue);
     State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) == (SecondValue & SIGN_FLAG_BYTE))
                       && ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE));
-    State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
-    State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-    State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+    State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0);
+    State->Flags.Zf = (Result == 0);
+    State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Write back the result */
@@ -1397,12 +1330,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddEax)
     ASSERT(Opcode == 0x05);
 
     NO_LOCK_PREFIX();
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
+    TOGGLE_OPSIZE(Size);
 
     if (Size)
     {
@@ -1422,9 +1350,9 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddEax)
         State->Flags.Cf = (Result < FirstValue) && (Result < SecondValue);
         State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) == (SecondValue & SIGN_FLAG_LONG))
                           && ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG));
-        State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+        State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0);
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -1448,9 +1376,9 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddEax)
         State->Flags.Cf = (Result < FirstValue) && (Result < SecondValue);
         State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) == (SecondValue & SIGN_FLAG_WORD))
                           && ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD));
-        State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+        State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0);
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -1469,11 +1397,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOrByteModrm)
     /* Make sure this is the right instruction */
     ASSERT((Opcode & 0xFD) == 0x08);
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the size */
-        AddressSize = !AddressSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -1497,8 +1421,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOrByteModrm)
     /* Update the flags */
     State->Flags.Cf = FALSE;
     State->Flags.Of = FALSE;
-    State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-    State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+    State->Flags.Zf = (Result == 0);
+    State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Write back the result */
@@ -1518,17 +1442,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOrModrm)
 
     OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the address size */
-        AddressSize = !AddressSize;
-    }
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the operand size */
-        OperandSize = !OperandSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
+    TOGGLE_OPSIZE(OperandSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -1550,15 +1465,15 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOrModrm)
             /* Exception occurred */
             return FALSE;
         }
-    
+
         /* Calculate the result */
         Result = FirstValue | SecondValue;
 
         /* Update the flags */
         State->Flags.Cf = FALSE;
         State->Flags.Of = FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -1579,15 +1494,15 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOrModrm)
             /* Exception occurred */
             return FALSE;
         }
-    
+
         /* Calculate the result */
         Result = FirstValue | SecondValue;
 
         /* Update the flags */
         State->Flags.Cf = FALSE;
         State->Flags.Of = FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -1625,8 +1540,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOrAl)
     /* Update the flags */
     State->Flags.Cf = FALSE;
     State->Flags.Of = FALSE;
-    State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-    State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+    State->Flags.Zf = (Result == 0);
+    State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Write back the result */
@@ -1643,12 +1558,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOrEax)
     ASSERT(Opcode == 0x0D);
 
     NO_LOCK_PREFIX();
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
+    TOGGLE_OPSIZE(Size);
 
     if (Size)
     {
@@ -1667,8 +1577,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOrEax)
         /* Update the flags */
         State->Flags.Cf = FALSE;
         State->Flags.Of = FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -1691,8 +1601,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOrEax)
         /* Update the flags */
         State->Flags.Cf = FALSE;
         State->Flags.Of = FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -1711,11 +1621,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAndByteModrm)
     /* Make sure this is the right instruction */
     ASSERT((Opcode & 0xFD) == 0x20);
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the size */
-        AddressSize = !AddressSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -1739,8 +1645,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAndByteModrm)
     /* Update the flags */
     State->Flags.Cf = FALSE;
     State->Flags.Of = FALSE;
-    State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-    State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+    State->Flags.Zf = (Result == 0);
+    State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Write back the result */
@@ -1760,17 +1666,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAndModrm)
 
     OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the address size */
-        AddressSize = !AddressSize;
-    }
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the operand size */
-        OperandSize = !OperandSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
+    TOGGLE_OPSIZE(OperandSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -1792,15 +1689,15 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAndModrm)
             /* Exception occurred */
             return FALSE;
         }
-    
+
         /* Calculate the result */
         Result = FirstValue & SecondValue;
 
         /* Update the flags */
         State->Flags.Cf = FALSE;
         State->Flags.Of = FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -1821,15 +1718,15 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAndModrm)
             /* Exception occurred */
             return FALSE;
         }
-    
+
         /* Calculate the result */
         Result = FirstValue & SecondValue;
 
         /* Update the flags */
         State->Flags.Cf = FALSE;
         State->Flags.Of = FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -1862,8 +1759,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAndAl)
     /* Update the flags */
     State->Flags.Cf = FALSE;
     State->Flags.Of = FALSE;
-    State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-    State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+    State->Flags.Zf = (Result == 0);
+    State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Write back the result */
@@ -1880,12 +1777,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAndEax)
     ASSERT(Opcode == 0x25);
 
     NO_LOCK_PREFIX();
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
+    TOGGLE_OPSIZE(Size);
 
     if (Size)
     {
@@ -1904,8 +1796,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAndEax)
         /* Update the flags */
         State->Flags.Cf = FALSE;
         State->Flags.Of = FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -1928,8 +1820,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAndEax)
         /* Update the flags */
         State->Flags.Cf = FALSE;
         State->Flags.Of = FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -1948,11 +1840,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXorByteModrm)
     /* Make sure this is the right instruction */
     ASSERT((Opcode & 0xFD) == 0x30);
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the size */
-        AddressSize = !AddressSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -1976,8 +1864,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXorByteModrm)
     /* Update the flags */
     State->Flags.Cf = FALSE;
     State->Flags.Of = FALSE;
-    State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-    State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+    State->Flags.Zf = (Result == 0);
+    State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Write back the result */
@@ -1997,17 +1885,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXorModrm)
 
     OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the address size */
-        AddressSize = !AddressSize;
-    }
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the operand size */
-        OperandSize = !OperandSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
+    TOGGLE_OPSIZE(OperandSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -2029,15 +1908,15 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXorModrm)
             /* Exception occurred */
             return FALSE;
         }
-    
+
         /* Calculate the result */
         Result = FirstValue ^ SecondValue;
 
         /* Update the flags */
         State->Flags.Cf = FALSE;
         State->Flags.Of = FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -2058,15 +1937,15 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXorModrm)
             /* Exception occurred */
             return FALSE;
         }
-    
+
         /* Calculate the result */
         Result = FirstValue ^ SecondValue;
 
         /* Update the flags */
         State->Flags.Cf = FALSE;
         State->Flags.Of = FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -2104,8 +1983,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXorAl)
     /* Update the flags */
     State->Flags.Cf = FALSE;
     State->Flags.Of = FALSE;
-    State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-    State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+    State->Flags.Zf = (Result == 0);
+    State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Write back the result */
@@ -2122,12 +2001,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXorEax)
     ASSERT(Opcode == 0x35);
 
     NO_LOCK_PREFIX();
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
+    TOGGLE_OPSIZE(Size);
 
     if (Size)
     {
@@ -2146,8 +2020,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXorEax)
         /* Update the flags */
         State->Flags.Cf = FALSE;
         State->Flags.Of = FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -2170,8 +2044,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXorEax)
         /* Update the flags */
         State->Flags.Cf = FALSE;
         State->Flags.Of = FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -2190,11 +2064,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeTestByteModrm)
     /* Make sure this is the right instruction */
     ASSERT(Opcode == 0x84);
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the size */
-        AddressSize = !AddressSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -2217,8 +2087,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeTestByteModrm)
     /* Update the flags */
     State->Flags.Cf = FALSE;
     State->Flags.Of = FALSE;
-    State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-    State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+    State->Flags.Zf = (Result == 0);
+    State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* The result is discarded */
@@ -2235,17 +2105,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeTestModrm)
 
     OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the address size */
-        AddressSize = !AddressSize;
-    }
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the operand size */
-        OperandSize = !OperandSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
+    TOGGLE_OPSIZE(OperandSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -2267,15 +2128,15 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeTestModrm)
             /* Exception occurred */
             return FALSE;
         }
-    
+
         /* Calculate the result */
         Result = FirstValue & SecondValue;
 
         /* Update the flags */
         State->Flags.Cf = FALSE;
         State->Flags.Of = FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
     }
     else
@@ -2290,15 +2151,15 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeTestModrm)
             /* Exception occurred */
             return FALSE;
         }
-    
+
         /* Calculate the result */
         Result = FirstValue & SecondValue;
 
         /* Update the flags */
         State->Flags.Cf = FALSE;
         State->Flags.Of = FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
     }
 
@@ -2333,8 +2194,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeTestAl)
     /* Update the flags */
     State->Flags.Cf = FALSE;
     State->Flags.Of = FALSE;
-    State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-    State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+    State->Flags.Zf = (Result == 0);
+    State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* The result is discarded */
@@ -2349,12 +2210,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeTestEax)
     ASSERT(Opcode == 0xA9);
 
     NO_LOCK_PREFIX();
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
+    TOGGLE_OPSIZE(Size);
 
     if (Size)
     {
@@ -2373,8 +2229,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeTestEax)
         /* Update the flags */
         State->Flags.Cf = FALSE;
         State->Flags.Of = FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
     }
     else
@@ -2394,8 +2250,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeTestEax)
         /* Update the flags */
         State->Flags.Cf = FALSE;
         State->Flags.Of = FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
     }
 
@@ -2412,11 +2268,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXchgByteModrm)
     /* Make sure this is the right instruction */
     ASSERT(Opcode == 0x86);
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the size */
-        AddressSize = !AddressSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -2467,17 +2319,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXchgModrm)
 
     OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the address size */
-        AddressSize = !AddressSize;
-    }
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the operand size */
-        OperandSize = !OperandSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
+    TOGGLE_OPSIZE(OperandSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -2532,7 +2375,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXchgModrm)
             /* Exception occurred */
             return FALSE;
         }
-    
+
         /* Write the value from the register to the R/M */
         if (!Fast486WriteModrmWordOperands(State,
                                            &ModRegRm,
@@ -2593,11 +2436,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAdcByteModrm)
     /* Make sure this is the right instruction */
     ASSERT((Opcode & 0xFD) == 0x10);
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the size */
-        AddressSize = !AddressSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -2626,9 +2465,9 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAdcByteModrm)
     State->Flags.Cf = State->Flags.Cf || ((Result < FirstValue) && (Result < SecondValue));
     State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) == (SecondValue & SIGN_FLAG_BYTE))
                       && ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE));
-    State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
-    State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-    State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+    State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0);
+    State->Flags.Zf = (Result == 0);
+    State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Write back the result */
@@ -2648,17 +2487,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAdcModrm)
 
     OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the address size */
-        AddressSize = !AddressSize;
-    }
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the operand size */
-        OperandSize = !OperandSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
+    TOGGLE_OPSIZE(OperandSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -2680,7 +2510,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAdcModrm)
             /* Exception occurred */
             return FALSE;
         }
-    
+
         /* Calculate the result */
         Result = FirstValue + SecondValue + State->Flags.Cf;
 
@@ -2692,9 +2522,9 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAdcModrm)
         State->Flags.Cf = State->Flags.Cf || ((Result < FirstValue) && (Result < SecondValue));
         State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) == (SecondValue & SIGN_FLAG_LONG))
                           && ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG));
-        State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+        State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0);
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -2715,7 +2545,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAdcModrm)
             /* Exception occurred */
             return FALSE;
         }
-    
+
         /* Calculate the result */
         Result = FirstValue + SecondValue + State->Flags.Cf;
 
@@ -2727,9 +2557,9 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAdcModrm)
         State->Flags.Cf = State->Flags.Cf || ((Result < FirstValue) && (Result < SecondValue));
         State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) == (SecondValue & SIGN_FLAG_WORD))
                           && ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD));
-        State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+        State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0);
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -2773,9 +2603,9 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAdcAl)
     State->Flags.Cf = State->Flags.Cf || ((Result < FirstValue) && (Result < SecondValue));
     State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) == (SecondValue & SIGN_FLAG_BYTE))
                       && ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE));
-    State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
-    State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-    State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+    State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0);
+    State->Flags.Zf = (Result == 0);
+    State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Write back the result */
@@ -2792,12 +2622,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAdcEax)
     ASSERT(Opcode == 0x15);
 
     NO_LOCK_PREFIX();
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
+    TOGGLE_OPSIZE(Size);
 
     if (Size)
     {
@@ -2821,9 +2646,9 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAdcEax)
         State->Flags.Cf = State->Flags.Cf || ((Result < FirstValue) && (Result < SecondValue));
         State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) == (SecondValue & SIGN_FLAG_LONG))
                           && ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG));
-        State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+        State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0);
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -2851,9 +2676,9 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAdcEax)
         State->Flags.Cf = State->Flags.Cf || ((Result < FirstValue) && (Result < SecondValue));
         State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) == (SecondValue & SIGN_FLAG_WORD))
                           && ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD));
-        State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+        State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0);
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -2893,11 +2718,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbByteModrm)
     /* Make sure this is the right instruction */
     ASSERT((Opcode & 0xFD) == 0x18);
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the size */
-        AddressSize = !AddressSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -2919,9 +2740,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbByteModrm)
     if (!(Opcode & FAST486_OPCODE_WRITE_REG))
     {
         /* Swap the order */
-        FirstValue ^= SecondValue;
-        SecondValue ^= FirstValue;
-        FirstValue ^= SecondValue;
+        SWAP(FirstValue, SecondValue);
     }
 
     /* Calculate the result */
@@ -2932,8 +2751,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbByteModrm)
     State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) != (SecondValue & SIGN_FLAG_BYTE))
                       && ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE));
     State->Flags.Af = (FirstValue & 0x0F) < ((SecondValue + 1) & 0x0F);
-    State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-    State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+    State->Flags.Zf = (Result == 0);
+    State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Write back the result */
@@ -2954,17 +2773,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbModrm)
 
     OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the address size */
-        AddressSize = !AddressSize;
-    }
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the operand size */
-        OperandSize = !OperandSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
+    TOGGLE_OPSIZE(OperandSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -2991,11 +2801,9 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbModrm)
         if (!(Opcode & FAST486_OPCODE_WRITE_REG))
         {
             /* Swap the order */
-            FirstValue ^= SecondValue;
-            SecondValue ^= FirstValue;
-            FirstValue ^= SecondValue;
+            SWAP(FirstValue, SecondValue);
         }
-    
+
         /* Calculate the result */
         Result = FirstValue - SecondValue - Carry;
 
@@ -3004,8 +2812,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbModrm)
         State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) != (SecondValue & SIGN_FLAG_LONG))
                           && ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG));
         State->Flags.Af = (FirstValue & 0x0F) < ((SecondValue + 1) & 0x0F);
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -3026,16 +2834,14 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbModrm)
             /* Exception occurred */
             return FALSE;
         }
-    
+
         /* Check if this is the instruction that writes to R/M */
         if (!(Opcode & FAST486_OPCODE_WRITE_REG))
         {
             /* Swap the order */
-            FirstValue ^= SecondValue;
-            SecondValue ^= FirstValue;
-            FirstValue ^= SecondValue;
+            SWAP(FirstValue, SecondValue);
         }
-    
+
         /* Calculate the result */
         Result = FirstValue - SecondValue - Carry;
 
@@ -3044,8 +2850,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbModrm)
         State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) != (SecondValue & SIGN_FLAG_WORD))
                           && ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD));
         State->Flags.Af = (FirstValue & 0x0F) < ((SecondValue + 1) & 0x0F);
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -3086,8 +2892,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbAl)
     State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) != (SecondValue & SIGN_FLAG_BYTE))
                       && ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE));
     State->Flags.Af = (FirstValue & 0x0F) < ((SecondValue + 1) & 0x0F);
-    State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-    State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+    State->Flags.Zf = (Result == 0);
+    State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Write back the result */
@@ -3106,12 +2912,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbEax)
     ASSERT(Opcode == 0x1D);
 
     NO_LOCK_PREFIX();
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
+    TOGGLE_OPSIZE(Size);
 
     if (Size)
     {
@@ -3132,8 +2933,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbEax)
         State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) != (SecondValue & SIGN_FLAG_LONG))
                           && ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG));
         State->Flags.Af = (FirstValue & 0x0F) < ((SecondValue + Carry) & 0x0F);
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -3158,8 +2959,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbEax)
         State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) != (SecondValue & SIGN_FLAG_WORD))
                           && ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD));
         State->Flags.Af = (FirstValue & 0x0F) < ((SecondValue + Carry) & 0x0F);
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
@@ -3235,11 +3036,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubByteModrm)
     /* Make sure this is the right instruction */
     ASSERT((Opcode & 0xED) == 0x28);
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the size */
-        AddressSize = !AddressSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -3261,21 +3058,19 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubByteModrm)
     if (!(Opcode & FAST486_OPCODE_WRITE_REG))
     {
         /* Swap the order */
-        FirstValue ^= SecondValue;
-        SecondValue ^= FirstValue;
-        FirstValue ^= SecondValue;
+        SWAP(FirstValue, SecondValue);
     }
 
     /* Calculate the result */
     Result = FirstValue - SecondValue;
 
     /* Update the flags */
-    State->Flags.Cf = FirstValue < SecondValue;
+    State->Flags.Cf = (FirstValue < SecondValue);
     State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) != (SecondValue & SIGN_FLAG_BYTE))
                       && ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE));
     State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F);
-    State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-    State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+    State->Flags.Zf = (Result == 0);
+    State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Check if this is not a CMP */
@@ -3304,17 +3099,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubModrm)
 
     OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the address size */
-        AddressSize = !AddressSize;
-    }
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the operand size */
-        OperandSize = !OperandSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
+    TOGGLE_OPSIZE(OperandSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -3341,21 +3127,19 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubModrm)
         if (!(Opcode & FAST486_OPCODE_WRITE_REG))
         {
             /* Swap the order */
-            FirstValue ^= SecondValue;
-            SecondValue ^= FirstValue;
-            FirstValue ^= SecondValue;
+            SWAP(FirstValue, SecondValue);
         }
-    
+
         /* Calculate the result */
         Result = FirstValue - SecondValue;
 
         /* Update the flags */
-        State->Flags.Cf = FirstValue < SecondValue;
+        State->Flags.Cf = (FirstValue < SecondValue);
         State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) != (SecondValue & SIGN_FLAG_LONG))
                           && ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG));
         State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F);
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Check if this is not a CMP */
@@ -3385,26 +3169,24 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubModrm)
             /* Exception occurred */
             return FALSE;
         }
-    
+
         /* Check if this is the instruction that writes to R/M */
         if (!(Opcode & FAST486_OPCODE_WRITE_REG))
         {
             /* Swap the order */
-            FirstValue ^= SecondValue;
-            SecondValue ^= FirstValue;
-            FirstValue ^= SecondValue;
+            SWAP(FirstValue, SecondValue);
         }
-    
+
         /* Calculate the result */
         Result = FirstValue - SecondValue;
 
         /* Update the flags */
-        State->Flags.Cf = FirstValue < SecondValue;
+        State->Flags.Cf = (FirstValue < SecondValue);
         State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) != (SecondValue & SIGN_FLAG_WORD))
                           && ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD));
         State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F);
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Check if this is not a CMP */
@@ -3449,12 +3231,12 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubAl)
     Result = FirstValue - SecondValue;
 
     /* Update the flags */
-    State->Flags.Cf = FirstValue < SecondValue;
+    State->Flags.Cf = (FirstValue < SecondValue);
     State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) != (SecondValue & SIGN_FLAG_BYTE))
                       && ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE));
     State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F);
-    State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-    State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+    State->Flags.Zf = (Result == 0);
+    State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Check if this is not a CMP */
@@ -3475,12 +3257,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubEax)
     ASSERT((Opcode & 0xEF) == 0x2D);
 
     NO_LOCK_PREFIX();
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
+    TOGGLE_OPSIZE(Size);
 
     if (Size)
     {
@@ -3497,12 +3274,12 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubEax)
         Result = FirstValue - SecondValue;
 
         /* Update the flags */
-        State->Flags.Cf = FirstValue < SecondValue;
+        State->Flags.Cf = (FirstValue < SecondValue);
         State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) != (SecondValue & SIGN_FLAG_LONG))
                           && ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG));
         State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F);
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Check if this is not a CMP */
@@ -3527,12 +3304,12 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubEax)
         Result = FirstValue - SecondValue;
 
         /* Update the flags */
-        State->Flags.Cf = FirstValue < SecondValue;
+        State->Flags.Cf = (FirstValue < SecondValue);
         State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) != (SecondValue & SIGN_FLAG_WORD))
                           && ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD));
         State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F);
-        State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-        State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+        State->Flags.Zf = (Result == 0);
+        State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Check if this is not a CMP */
@@ -3649,12 +3426,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePushAll)
     /* Make sure this is the right instruction */
     ASSERT(Opcode == 0x60);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
-
+    TOGGLE_OPSIZE(Size);
     NO_LOCK_PREFIX();
 
     /* Push all the registers in order */
@@ -3693,12 +3465,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePopAll)
     /* Make sure this is the right instruction */
     ASSERT(Opcode == 0x61);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
-
+    TOGGLE_OPSIZE(Size);
     NO_LOCK_PREFIX();
 
     /* Pop all the registers in reverse order */
@@ -3745,11 +3512,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeArpl)
         return FALSE;
     }
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the size */
-        AddressSize = !AddressSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -3797,12 +3560,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePushImm)
     ASSERT(Opcode == 0x68);
 
     NO_LOCK_PREFIX();
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
+    TOGGLE_OPSIZE(Size);
 
     if (Size)
     {
@@ -3844,17 +3602,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeImulModrmImm)
 
     OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the address size */
-        AddressSize = !AddressSize;
-    }
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the operand size */
-        OperandSize = !OperandSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
+    TOGGLE_OPSIZE(OperandSize);
 
     /* Fetch the parameters */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -3942,11 +3691,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeImulModrmImm)
     }
 
     /* Check for carry/overflow */
-    if ((Product < LONG_MIN) || (Product > LONG_MAX))
-    {
-        State->Flags.Cf = State->Flags.Of = TRUE;
-    }
-    else State->Flags.Cf = State->Flags.Of = FALSE;
+    State->Flags.Cf = State->Flags.Of = ((Product < MINLONG) || (Product > MAXLONG));
 
     /* Write-back the result */
     return Fast486WriteModrmDwordOperands(State,
@@ -3981,11 +3726,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovByteModrm)
     /* Make sure this is the right instruction */
     ASSERT((Opcode & 0xFD) == 0x88);
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the size */
-        AddressSize = !AddressSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -4024,17 +3765,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovModrm)
 
     OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the address size */
-        AddressSize = !AddressSize;
-    }
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the operand size */
-        OperandSize = !OperandSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
+    TOGGLE_OPSIZE(OperandSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -4059,7 +3791,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovModrm)
 
         if (Opcode & FAST486_OPCODE_WRITE_REG) Result = SecondValue;
         else Result = FirstValue;
-    
+
         /* Write back the result */
         return Fast486WriteModrmDwordOperands(State,
                                               &ModRegRm,
@@ -4078,7 +3810,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovModrm)
             /* Exception occurred */
             return FALSE;
         }
-    
+
         if (Opcode & FAST486_OPCODE_WRITE_REG) Result = SecondValue;
         else Result = FirstValue;
 
@@ -4100,17 +3832,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovStoreSeg)
     /* Make sure this is the right instruction */
     ASSERT(Opcode == 0x8C);
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the address size */
-        AddressSize = !AddressSize;
-    }
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the operand size */
-        OperandSize = !OperandSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
+    TOGGLE_OPSIZE(OperandSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -4152,17 +3875,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLea)
 
     OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the address size */
-        AddressSize = !AddressSize;
-    }
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the operand size */
-        OperandSize = !OperandSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
+    TOGGLE_OPSIZE(OperandSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -4207,17 +3921,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovLoadSeg)
     /* Make sure this is the right instruction */
     ASSERT(Opcode == 0x8E);
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the address size */
-        AddressSize = !AddressSize;
-    }
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the operand size */
-        OperandSize = !OperandSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
+    TOGGLE_OPSIZE(OperandSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -4267,12 +3972,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCwde)
     /* Make sure this is the right instruction */
     ASSERT(Opcode == 0x98);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
-
+    TOGGLE_OPSIZE(Size);
     NO_LOCK_PREFIX();
 
     if (Size)
@@ -4303,12 +4003,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCdq)
     /* Make sure this is the right instruction */
     ASSERT(Opcode == 0x99);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
-
+    TOGGLE_OPSIZE(Size);
     NO_LOCK_PREFIX();
 
     if (Size)
@@ -4338,12 +4033,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCallAbs)
     /* Make sure this is the right instruction */
     ASSERT(Opcode == 0x9A);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
-
+    TOGGLE_OPSIZE(Size);
     NO_LOCK_PREFIX();
 
     /* Fetch the offset */
@@ -4412,12 +4102,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePushFlags)
     BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
 
     NO_LOCK_PREFIX();
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* This OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
+    TOGGLE_OPSIZE(Size);
 
     /* Check for VM86 mode when IOPL is not 3 */
     if (State->Flags.Vm && (State->Flags.Iopl != 3))
@@ -4439,12 +4124,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePopFlags)
     ULONG NewFlags;
 
     NO_LOCK_PREFIX();
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* This OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
+    TOGGLE_OPSIZE(Size);
 
     /* Pop the new flags */
     if (!Fast486StackPop(State, &NewFlags))
@@ -4554,7 +4234,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePopFlags)
             /* Call the VM86 monitor */
             Fast486ExceptionWithErrorCode(State, FAST486_EXCEPTION_GP, 0);
         }
-        
+
     }
 
     return TRUE;
@@ -4597,12 +4277,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeRet)
     ASSERT((Opcode & 0xFE) == 0xC2);
 
     NO_LOCK_PREFIX();
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
+    TOGGLE_OPSIZE(Size);
 
     if (Opcode == 0xC2)
     {
@@ -4639,11 +4314,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLdsLes)
 
     OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the size */
-        AddressSize = !AddressSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
@@ -4660,10 +4331,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLdsLes)
             && (ModRegRm.SecondRegister == FAST486_REG_ESP)
             && (State->BopCallback != NULL))
         {
-            USHORT BopCode;
+            UCHAR BopCode;
 
             /* Fetch the BOP code */
-            if (!Fast486FetchWord(State, &BopCode))
+            if (!Fast486FetchByte(State, &BopCode))
             {
                 /* Exception occurred */
                 return FALSE;
@@ -4735,12 +4406,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeEnter)
     ASSERT(Opcode == 0xC8);
 
     NO_LOCK_PREFIX();
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
+    TOGGLE_OPSIZE(Size);
 
     if (!Fast486FetchWord(State, &FrameSize))
     {
@@ -4799,12 +4465,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLeave)
     ASSERT(Opcode == 0xC9);
 
     NO_LOCK_PREFIX();
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
+    TOGGLE_OPSIZE(Size);
 
     if (Size)
     {
@@ -4841,12 +4502,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeRetFar)
     /* Make sure this is the right instruction */
     ASSERT((Opcode & 0xFE) == 0xCA);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
-
+    TOGGLE_OPSIZE(Size);
     NO_LOCK_PREFIX();
 
     if (Opcode == 0xCA)
@@ -4957,7 +4613,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeInt)
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeIret)
 {
-    INT i;
+    FAST486_SEG_REGS i;
     ULONG InstPtr, CodeSel, StackPtr, StackSel;
     FAST486_FLAGS_REG NewFlags;
     BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
@@ -4966,12 +4622,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIret)
     ASSERT(Opcode == 0xCF);
 
     NO_LOCK_PREFIX();
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
+    TOGGLE_OPSIZE(Size);
 
     /* Pop EIP */
     if (!Fast486StackPop(State, &InstPtr))
@@ -5126,7 +4777,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIret)
             Cpl = Fast486GetCurrentPrivLevel(State);
 
             /* Check segment security */
-            for (i = 0; i <= FAST486_NUM_SEG_REGS; i++)
+            for (i = 0; i < FAST486_NUM_SEG_REGS; i++)
             {
                 /* Don't check CS or SS */
                 if ((i == FAST486_REG_CS) || (i == FAST486_REG_SS)) continue;
@@ -5196,8 +4847,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAam)
     State->GeneralRegs[FAST486_REG_EAX].LowByte = Value %= Base;
 
     /* Update flags */
-    State->Flags.Zf = (Value == 0) ? TRUE : FALSE;
-    State->Flags.Sf = (Value & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+    State->Flags.Zf = (Value == 0);
+    State->Flags.Sf = ((Value & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Value);
 
     return TRUE;
@@ -5222,8 +4873,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAad)
     State->GeneralRegs[FAST486_REG_EAX].LowByte = Value;
 
     /* Update flags */
-    State->Flags.Zf = (Value == 0) ? TRUE : FALSE;
-    State->Flags.Sf = (Value & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+    State->Flags.Zf = (Value == 0);
+    State->Flags.Sf = ((Value & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Value);
 
     return TRUE;
@@ -5234,11 +4885,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXlat)
     UCHAR Value;
     BOOLEAN AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
 
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the size */
-        AddressSize = !AddressSize;
-    }
+    TOGGLE_ADSIZE(AddressSize);
 
     /* Read a byte from DS:[(E)BX + AL] */
     if (!Fast486ReadMemory(State,
@@ -5271,12 +4918,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLoop)
     ASSERT((Opcode >= 0xE0) && (Opcode <= 0xE2));
 
     NO_LOCK_PREFIX();
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
+    TOGGLE_OPSIZE(Size);
 
     if (Size) Condition = ((--State->GeneralRegs[FAST486_REG_ECX].Long) != 0);
     else Condition = ((--State->GeneralRegs[FAST486_REG_ECX].LowWord) != 0);
@@ -5319,12 +4961,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeJecxz)
     ASSERT(Opcode == 0xE3);
 
     NO_LOCK_PREFIX();
-
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
+    TOGGLE_OPSIZE(Size);
 
     if (Size) Condition = (State->GeneralRegs[FAST486_REG_ECX].Long == 0);
     else Condition = (State->GeneralRegs[FAST486_REG_ECX].LowWord == 0);
@@ -5338,7 +4975,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeJecxz)
 
     if (Condition)
     {
-        /* Move the instruction pointer */        
+        /* Move the instruction pointer */
         State->InstPtr.Long += Offset;
     }
 
@@ -5352,12 +4989,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCall)
     /* Make sure this is the right instruction */
     ASSERT(Opcode == 0xE8);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
-
+    TOGGLE_OPSIZE(Size);
     NO_LOCK_PREFIX();
 
     if (Size)
@@ -5378,7 +5010,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCall)
             return FALSE;
         }
 
-        /* Move the instruction pointer */        
+        /* Move the instruction pointer */
         State->InstPtr.Long += Offset;
     }
     else
@@ -5399,7 +5031,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCall)
             return FALSE;
         }
 
-        /* Move the instruction pointer */        
+        /* Move the instruction pointer */
         State->InstPtr.LowWord += Offset;
     }
 
@@ -5413,12 +5045,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeJmp)
     /* Make sure this is the right instruction */
     ASSERT(Opcode == 0xE9);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
-
+    TOGGLE_OPSIZE(Size);
     NO_LOCK_PREFIX();
 
     if (Size)
@@ -5432,7 +5059,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeJmp)
             return FALSE;
         }
 
-        /* Move the instruction pointer */        
+        /* Move the instruction pointer */
         State->InstPtr.Long += Offset;
     }
     else
@@ -5446,7 +5073,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeJmp)
             return FALSE;
         }
 
-        /* Move the instruction pointer */        
+        /* Move the instruction pointer */
         State->InstPtr.LowWord += Offset;
     }
 
@@ -5462,12 +5089,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeJmpAbs)
     /* Make sure this is the right instruction */
     ASSERT(Opcode == 0xEA);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
-
+    TOGGLE_OPSIZE(Size);
     NO_LOCK_PREFIX();
 
     /* Fetch the offset */
@@ -5511,19 +5133,15 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeJmpAbs)
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeMovAlOffset)
 {
-    BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
+    BOOLEAN AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
     ULONG Offset;
 
     /* Make sure this is the right instruction */
     ASSERT(Opcode == 0xA0);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
+    TOGGLE_ADSIZE(AddressSize);
 
-    if (Size)
+    if (AddressSize)
     {
         if (!Fast486FetchDword(State, &Offset))
         {
@@ -5556,18 +5174,17 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovAlOffset)
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeMovEaxOffset)
 {
-    BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
+    BOOLEAN OperandSize, AddressSize;
+
+    OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
 
     /* Make sure this is the right instruction */
     ASSERT(Opcode == 0xA1);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
+    TOGGLE_OPSIZE(OperandSize);
+    TOGGLE_ADSIZE(AddressSize);
 
-    if (Size)
+    if (AddressSize)
     {
         ULONG Offset;
 
@@ -5578,13 +5195,26 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovEaxOffset)
         }
 
         /* Read from memory */
-        return Fast486ReadMemory(State,
-                                 (State->PrefixFlags & FAST486_PREFIX_SEG) ?
-                                 State->SegmentOverride : FAST486_REG_DS,
-                                 Offset,
-                                 FALSE,
-                                 &State->GeneralRegs[FAST486_REG_EAX].Long,
-                                 sizeof(ULONG));
+        if (OperandSize)
+        {
+            return Fast486ReadMemory(State,
+                                     (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+                                     State->SegmentOverride : FAST486_REG_DS,
+                                     Offset,
+                                     FALSE,
+                                     &State->GeneralRegs[FAST486_REG_EAX].Long,
+                                     sizeof(ULONG));
+        }
+        else
+        {
+            return Fast486ReadMemory(State,
+                                     (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+                                     State->SegmentOverride : FAST486_REG_DS,
+                                     Offset,
+                                     FALSE,
+                                     &State->GeneralRegs[FAST486_REG_EAX].LowWord,
+                                     sizeof(USHORT));
+        }
     }
     else
     {
@@ -5597,31 +5227,40 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovEaxOffset)
         }
 
         /* Read from memory */
-        return Fast486ReadMemory(State,
-                                 (State->PrefixFlags & FAST486_PREFIX_SEG) ?
-                                 State->SegmentOverride : FAST486_REG_DS,
-                                 Offset,
-                                 FALSE,
-                                 &State->GeneralRegs[FAST486_REG_EAX].LowWord,
-                                 sizeof(USHORT));
+        if (OperandSize)
+        {
+            return Fast486ReadMemory(State,
+                                     (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+                                     State->SegmentOverride : FAST486_REG_DS,
+                                     Offset,
+                                     FALSE,
+                                     &State->GeneralRegs[FAST486_REG_EAX].Long,
+                                     sizeof(ULONG));
+        }
+        else
+        {
+            return Fast486ReadMemory(State,
+                                     (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+                                     State->SegmentOverride : FAST486_REG_DS,
+                                     Offset,
+                                     FALSE,
+                                     &State->GeneralRegs[FAST486_REG_EAX].LowWord,
+                                     sizeof(USHORT));
+        }
     }
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeMovOffsetAl)
 {
-    BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
+    BOOLEAN AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
     ULONG Offset;
 
     /* Make sure this is the right instruction */
     ASSERT(Opcode == 0xA2);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
+    TOGGLE_ADSIZE(AddressSize);
 
-    if (Size)
+    if (AddressSize)
     {
         if (!Fast486FetchDword(State, &Offset))
         {
@@ -5653,18 +5292,17 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovOffsetAl)
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeMovOffsetEax)
 {
-    BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
+    BOOLEAN OperandSize, AddressSize;
+    
+    OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
 
     /* Make sure this is the right instruction */
     ASSERT(Opcode == 0xA3);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        Size = !Size;
-    }
+    TOGGLE_OPSIZE(OperandSize);
+    TOGGLE_ADSIZE(AddressSize);
 
-    if (Size)
+    if (AddressSize)
     {
         ULONG Offset;
 
@@ -5675,12 +5313,24 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovOffsetEax)
         }
 
         /* Write to memory */
-        return Fast486WriteMemory(State,
-                                  (State->PrefixFlags & FAST486_PREFIX_SEG) ?
-                                  State->SegmentOverride : FAST486_REG_DS,
-                                  Offset,
-                                  &State->GeneralRegs[FAST486_REG_EAX].Long,
-                                  sizeof(ULONG));
+        if (OperandSize)
+        {
+            return Fast486WriteMemory(State,
+                                      (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+                                      State->SegmentOverride : FAST486_REG_DS,
+                                      Offset,
+                                      &State->GeneralRegs[FAST486_REG_EAX].Long,
+                                      sizeof(ULONG));
+        }
+        else
+        {
+            return Fast486WriteMemory(State,
+                                      (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+                                      State->SegmentOverride : FAST486_REG_DS,
+                                      Offset,
+                                      &State->GeneralRegs[FAST486_REG_EAX].LowWord,
+                                      sizeof(USHORT));
+        }
     }
     else
     {
@@ -5693,12 +5343,24 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovOffsetEax)
         }
 
         /* Write to memory */
-        return Fast486WriteMemory(State,
-                                  (State->PrefixFlags & FAST486_PREFIX_SEG) ?
-                                  State->SegmentOverride : FAST486_REG_DS,
-                                  Offset,
-                                  &State->GeneralRegs[FAST486_REG_EAX].LowWord,
-                                  sizeof(USHORT));
+        if (OperandSize)
+        {
+            return Fast486WriteMemory(State,
+                                      (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+                                      State->SegmentOverride : FAST486_REG_DS,
+                                      Offset,
+                                      &State->GeneralRegs[FAST486_REG_EAX].Long,
+                                      sizeof(ULONG));
+        }
+        else
+        {
+            return Fast486WriteMemory(State,
+                                      (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+                                      State->SegmentOverride : FAST486_REG_DS,
+                                      Offset,
+                                      &State->GeneralRegs[FAST486_REG_EAX].LowWord,
+                                      sizeof(USHORT));
+        }
     }
 }
 
@@ -5726,17 +5388,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovs)
     /* Make sure this is the right instruction */
     ASSERT((Opcode & 0xFE) == 0xA4);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        OperandSize = !OperandSize;
-    }
-
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the size */
-        AddressSize = !AddressSize;
-    }
+    TOGGLE_OPSIZE(OperandSize);
+    TOGGLE_ADSIZE(AddressSize);
 
     if (State->PrefixFlags & FAST486_PREFIX_SEG)
     {
@@ -5920,17 +5573,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmps)
     /* Make sure this is the right instruction */
     ASSERT((Opcode & 0xFE) == 0xA6);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        OperandSize = !OperandSize;
-    }
-
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the size */
-        AddressSize = !AddressSize;
-    }
+    TOGGLE_OPSIZE(OperandSize);
+    TOGGLE_ADSIZE(AddressSize);
 
     if (State->PrefixFlags & FAST486_PREFIX_SEG)
     {
@@ -5978,12 +5622,12 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmps)
     Result = (FirstValue - SecondValue) & DataMask;
 
     /* Update the flags */
-    State->Flags.Cf = FirstValue < SecondValue;
+    State->Flags.Cf = (FirstValue < SecondValue);
     State->Flags.Of = ((FirstValue & SignFlag) != (SecondValue & SignFlag))
                       && ((FirstValue & SignFlag) != (Result & SignFlag));
     State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F);
-    State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-    State->Flags.Sf = (Result & SignFlag) ? TRUE : FALSE;
+    State->Flags.Zf = (Result == 0);
+    State->Flags.Sf = ((Result & SignFlag) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Increment/decrement ESI and EDI */
@@ -6019,7 +5663,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmps)
         || (State->PrefixFlags & FAST486_PREFIX_REPNZ))
     {
         BOOLEAN Repeat = TRUE;
-        
+
         if (OperandSize)
         {
             if ((--State->GeneralRegs[FAST486_REG_ECX].Long) == 0)
@@ -6065,17 +5709,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeStos)
     /* Make sure this is the right instruction */
     ASSERT((Opcode & 0xFE) == 0xAA);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        OperandSize = !OperandSize;
-    }
-
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the size */
-        AddressSize = !AddressSize;
-    }
+    TOGGLE_OPSIZE(OperandSize);
+    TOGGLE_ADSIZE(AddressSize);
 
     /* Calculate the size */
     if (Opcode == 0xAA) DataSize = sizeof(UCHAR);
@@ -6205,17 +5840,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLods)
     /* Make sure this is the right instruction */
     ASSERT((Opcode & 0xFE) == 0xAC);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        OperandSize = !OperandSize;
-    }
-
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the size */
-        AddressSize = !AddressSize;
-    }
+    TOGGLE_OPSIZE(OperandSize);
+    TOGGLE_ADSIZE(AddressSize);
 
     if (State->PrefixFlags & FAST486_PREFIX_SEG)
     {
@@ -6290,17 +5916,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeScas)
     /* Make sure this is the right instruction */
     ASSERT((Opcode & 0xFE) == 0xAE);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        OperandSize = !OperandSize;
-    }
-
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the size */
-        AddressSize = !AddressSize;
-    }
+    TOGGLE_OPSIZE(OperandSize);
+    TOGGLE_ADSIZE(AddressSize);
 
     /* Calculate the size */
     if (Opcode == 0xAE) DataSize = sizeof(UCHAR);
@@ -6329,12 +5946,12 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeScas)
     Result = (FirstValue - SecondValue) & DataMask;
 
     /* Update the flags */
-    State->Flags.Cf = FirstValue < SecondValue;
+    State->Flags.Cf = (FirstValue < SecondValue);
     State->Flags.Of = ((FirstValue & SignFlag) != (SecondValue & SignFlag))
                       && ((FirstValue & SignFlag) != (Result & SignFlag));
     State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F);
-    State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
-    State->Flags.Sf = (Result & SignFlag) ? TRUE : FALSE;
+    State->Flags.Zf = (Result == 0);
+    State->Flags.Sf = ((Result & SignFlag) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Increment/decrement EDI */
@@ -6354,7 +5971,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeScas)
         || (State->PrefixFlags & FAST486_PREFIX_REPNZ))
     {
         BOOLEAN Repeat = TRUE;
-        
+
         if (OperandSize)
         {
             if ((--State->GeneralRegs[FAST486_REG_ECX].Long) == 0)
@@ -6400,17 +6017,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIns)
     /* Make sure this is the right instruction */
     ASSERT((Opcode & 0xFE) == 0x6C);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        OperandSize = !OperandSize;
-    }
-
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the size */
-        AddressSize = !AddressSize;
-    }
+    TOGGLE_OPSIZE(OperandSize);
+    TOGGLE_ADSIZE(AddressSize);
 
     /* Calculate the size */
     if (Opcode == 0x6C) DataSize = sizeof(UCHAR);
@@ -6445,7 +6053,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIns)
             State->IoReadCallback(State,
                                   State->GeneralRegs[FAST486_REG_EDX].LowWord,
                                   Block,
-                                  Processed * DataSize);
+                                  Processed,
+                                  DataSize);
 
             if (State->Flags.Df)
             {
@@ -6507,6 +6116,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIns)
         State->IoReadCallback(State,
                               State->GeneralRegs[FAST486_REG_EDX].LowWord,
                               &Data,
+                              1,
                               DataSize);
 
         /* Write to the destination operand */
@@ -6548,17 +6158,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOuts)
     /* Make sure this is the right instruction */
     ASSERT((Opcode & 0xFE) == 0x6E);
 
-    if (State->PrefixFlags & FAST486_PREFIX_OPSIZE)
-    {
-        /* The OPSIZE prefix toggles the size */
-        OperandSize = !OperandSize;
-    }
-
-    if (State->PrefixFlags & FAST486_PREFIX_ADSIZE)
-    {
-        /* The ADSIZE prefix toggles the size */
-        AddressSize = !AddressSize;
-    }
+    TOGGLE_OPSIZE(OperandSize);
+    TOGGLE_ADSIZE(AddressSize);
 
     /* Calculate the size */
     if (Opcode == 0x6E) DataSize = sizeof(UCHAR);
@@ -6631,7 +6232,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOuts)
             State->IoWriteCallback(State,
                                    State->GeneralRegs[FAST486_REG_EDX].LowWord,
                                    Block,
-                                   Processed * DataSize);
+                                   Processed,
+                                   DataSize);
 
             if (!State->Flags.Df)
             {
@@ -6669,6 +6271,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOuts)
         State->IoWriteCallback(State,
                                State->GeneralRegs[FAST486_REG_EDX].LowWord,
                                &Data,
+                               1,
                                DataSize);
 
         /* Increment/decrement ESI */