[FAST486]
[reactos.git] / lib / fast486 / opcodes.c
index 39ec666..07e870c 100644 (file)
 
 /* INCLUDES *******************************************************************/
 
-// #define WIN32_NO_STATUS
-// #define _INC_WINDOWS
 #include <windef.h>
-#include <limits.h>
 
 // #define NDEBUG
 #include <debug.h>
@@ -476,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 */
@@ -510,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 */
@@ -687,7 +684,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeShortConditionalJmp)
 
     if (Jump)
     {
-        /* Move the instruction pointer */        
+        /* Move the instruction pointer */
         State->InstPtr.Long += Offset;
     }
 
@@ -876,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;
@@ -909,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;
@@ -953,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;
@@ -963,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;
@@ -1000,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;
 }
@@ -1044,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
     {
@@ -1052,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;
@@ -1072,7 +1069,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeShortJump)
         return FALSE;
     }
 
-    /* Move the instruction pointer */        
+    /* Move the instruction pointer */
     State->InstPtr.Long += Offset;
 
     return TRUE;
@@ -1189,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 */
@@ -1234,7 +1231,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddModrm)
             /* Exception occurred */
             return FALSE;
         }
-    
+
         /* Calculate the result */
         Result = FirstValue + SecondValue;
 
@@ -1242,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 */
@@ -1265,7 +1262,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddModrm)
             /* Exception occurred */
             return FALSE;
         }
-    
+
         /* Calculate the result */
         Result = FirstValue + SecondValue;
 
@@ -1273,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 */
@@ -1314,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 */
@@ -1353,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 */
@@ -1379,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 */
@@ -1424,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 */
@@ -1468,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 */
@@ -1497,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 */
@@ -1543,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 */
@@ -1580,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 */
@@ -1604,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 */
@@ -1648,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 */
@@ -1692,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 */
@@ -1721,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 */
@@ -1762,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 */
@@ -1799,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 */
@@ -1823,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 */
@@ -1867,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 */
@@ -1911,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 */
@@ -1940,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 */
@@ -1986,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 */
@@ -2023,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 */
@@ -2047,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 */
@@ -2090,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 */
@@ -2131,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
@@ -2154,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);
     }
 
@@ -2197,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 */
@@ -2232,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
@@ -2253,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);
     }
 
@@ -2378,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,
@@ -2468,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 */
@@ -2513,7 +2510,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAdcModrm)
             /* Exception occurred */
             return FALSE;
         }
-    
+
         /* Calculate the result */
         Result = FirstValue + SecondValue + State->Flags.Cf;
 
@@ -2525,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 */
@@ -2548,7 +2545,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAdcModrm)
             /* Exception occurred */
             return FALSE;
         }
-    
+
         /* Calculate the result */
         Result = FirstValue + SecondValue + State->Flags.Cf;
 
@@ -2560,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 */
@@ -2606,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 */
@@ -2649,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 */
@@ -2679,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 */
@@ -2743,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 */
@@ -2756,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 */
@@ -2806,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;
 
@@ -2819,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 */
@@ -2841,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;
 
@@ -2859,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 */
@@ -2901,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 */
@@ -2942,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 */
@@ -2968,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 */
@@ -3067,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 */
@@ -3138,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 */
@@ -3182,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 */
@@ -3246,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 */
@@ -3289,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 */
@@ -3319,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 */
@@ -3706,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,
@@ -3810,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,
@@ -3829,7 +3810,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovModrm)
             /* Exception occurred */
             return FALSE;
         }
-    
+
         if (Opcode & FAST486_OPCODE_WRITE_REG) Result = SecondValue;
         else Result = FirstValue;
 
@@ -4253,7 +4234,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePopFlags)
             /* Call the VM86 monitor */
             Fast486ExceptionWithErrorCode(State, FAST486_EXCEPTION_GP, 0);
         }
-        
+
     }
 
     return TRUE;
@@ -4333,6 +4314,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLdsLes)
 
     OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
 
+    TOGGLE_OPSIZE(OperandSize);
     TOGGLE_ADSIZE(AddressSize);
 
     /* Get the operands */
@@ -4350,10 +4332,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;
@@ -4632,7 +4614,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;
@@ -4796,7 +4778,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;
@@ -4866,8 +4848,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;
@@ -4892,8 +4874,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;
@@ -4994,7 +4976,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeJecxz)
 
     if (Condition)
     {
-        /* Move the instruction pointer */        
+        /* Move the instruction pointer */
         State->InstPtr.Long += Offset;
     }
 
@@ -5029,7 +5011,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCall)
             return FALSE;
         }
 
-        /* Move the instruction pointer */        
+        /* Move the instruction pointer */
         State->InstPtr.Long += Offset;
     }
     else
@@ -5050,7 +5032,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCall)
             return FALSE;
         }
 
-        /* Move the instruction pointer */        
+        /* Move the instruction pointer */
         State->InstPtr.LowWord += Offset;
     }
 
@@ -5078,7 +5060,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeJmp)
             return FALSE;
         }
 
-        /* Move the instruction pointer */        
+        /* Move the instruction pointer */
         State->InstPtr.Long += Offset;
     }
     else
@@ -5092,7 +5074,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeJmp)
             return FALSE;
         }
 
-        /* Move the instruction pointer */        
+        /* Move the instruction pointer */
         State->InstPtr.LowWord += Offset;
     }
 
@@ -5152,15 +5134,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);
 
-    TOGGLE_OPSIZE(Size);
+    TOGGLE_ADSIZE(AddressSize);
 
-    if (Size)
+    if (AddressSize)
     {
         if (!Fast486FetchDword(State, &Offset))
         {
@@ -5193,14 +5175,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);
 
-    TOGGLE_OPSIZE(Size);
+    TOGGLE_OPSIZE(OperandSize);
+    TOGGLE_ADSIZE(AddressSize);
 
-    if (Size)
+    if (AddressSize)
     {
         ULONG Offset;
 
@@ -5211,13 +5196,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
     {
@@ -5230,27 +5228,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);
 
-    TOGGLE_OPSIZE(Size);
+    TOGGLE_ADSIZE(AddressSize);
 
-    if (Size)
+    if (AddressSize)
     {
         if (!Fast486FetchDword(State, &Offset))
         {
@@ -5282,14 +5293,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);
 
-    TOGGLE_OPSIZE(Size);
+    TOGGLE_OPSIZE(OperandSize);
+    TOGGLE_ADSIZE(AddressSize);
 
-    if (Size)
+    if (AddressSize)
     {
         ULONG Offset;
 
@@ -5300,12 +5314,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
     {
@@ -5318,12 +5344,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));
+        }
     }
 }
 
@@ -5585,12 +5623,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 */
@@ -5626,7 +5664,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmps)
         || (State->PrefixFlags & FAST486_PREFIX_REPNZ))
     {
         BOOLEAN Repeat = TRUE;
-        
+
         if (OperandSize)
         {
             if ((--State->GeneralRegs[FAST486_REG_ECX].Long) == 0)
@@ -5909,12 +5947,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 */
@@ -5934,7 +5972,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeScas)
         || (State->PrefixFlags & FAST486_PREFIX_REPNZ))
     {
         BOOLEAN Repeat = TRUE;
-        
+
         if (OperandSize)
         {
             if ((--State->GeneralRegs[FAST486_REG_ECX].Long) == 0)
@@ -6016,7 +6054,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIns)
             State->IoReadCallback(State,
                                   State->GeneralRegs[FAST486_REG_EDX].LowWord,
                                   Block,
-                                  Processed * DataSize);
+                                  Processed,
+                                  DataSize);
 
             if (State->Flags.Df)
             {
@@ -6078,6 +6117,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIns)
         State->IoReadCallback(State,
                               State->GeneralRegs[FAST486_REG_EDX].LowWord,
                               &Data,
+                              1,
                               DataSize);
 
         /* Write to the destination operand */
@@ -6193,7 +6233,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOuts)
             State->IoWriteCallback(State,
                                    State->GeneralRegs[FAST486_REG_EDX].LowWord,
                                    Block,
-                                   Processed * DataSize);
+                                   Processed,
+                                   DataSize);
 
             if (!State->Flags.Df)
             {
@@ -6231,6 +6272,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOuts)
         State->IoWriteCallback(State,
                                State->GeneralRegs[FAST486_REG_EDX].LowWord,
                                &Data,
+                               1,
                                DataSize);
 
         /* Increment/decrement ESI */