* Sync up to trunk head (r64995).
[reactos.git] / lib / fast486 / opcodes.c
index 4eb2e6b..f31ce73 100644 (file)
@@ -2,7 +2,7 @@
  * Fast486 386/486 CPU Emulation Library
  * opcodes.c
  *
- * Copyright (C) 2013 Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
+ * Copyright (C) 2014 Aleksandar Andrejevic <theflash AT sdf DOT lonestar DOT org>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
 #include "opgroups.h"
 #include "extraops.h"
 #include "common.h"
+#include "fpu.h"
 
 /* PUBLIC VARIABLES ***********************************************************/
 
 FAST486_OPCODE_HANDLER_PROC
 Fast486OpcodeHandlers[FAST486_NUM_OPCODE_HANDLERS] =
 {
-    Fast486OpcodeAddByteModrm,
+    Fast486OpcodeAddByteModrm,          /* 0x00 - 0x03 */
     Fast486OpcodeAddModrm,
     Fast486OpcodeAddByteModrm,
     Fast486OpcodeAddModrm,
-    Fast486OpcodeAddAl,
-    Fast486OpcodeAddEax,
-    Fast486OpcodePushEs,
-    Fast486OpcodePopEs,
-    Fast486OpcodeOrByteModrm,
+    Fast486OpcodeAddAl,                 /* 0x04 */
+    Fast486OpcodeAddEax,                /* 0x05 */
+    Fast486OpcodePushEs,                /* 0x06 */
+    Fast486OpcodePopEs,                 /* 0x07 */
+    Fast486OpcodeOrByteModrm,           /* 0x08 - 0x0B */
     Fast486OpcodeOrModrm,
     Fast486OpcodeOrByteModrm,
     Fast486OpcodeOrModrm,
-    Fast486OpcodeOrAl,
-    Fast486OpcodeOrEax,
-    Fast486OpcodePushCs,
-    Fast486OpcodeExtended,
-    Fast486OpcodeAdcByteModrm,
+    Fast486OpcodeOrAl,                  /* 0x0C */
+    Fast486OpcodeOrEax,                 /* 0x0D */
+    Fast486OpcodePushCs,                /* 0x0E */
+    Fast486OpcodeExtended,              /* 0x0F */
+    Fast486OpcodeAdcByteModrm,          /* 0x10 - 0x13 */
     Fast486OpcodeAdcModrm,
     Fast486OpcodeAdcByteModrm,
     Fast486OpcodeAdcModrm,
-    Fast486OpcodeAdcAl,
-    Fast486OpcodeAdcEax,
-    Fast486OpcodePushSs,
-    Fast486OpcodePopSs,
-    Fast486OpcodeSbbByteModrm,
+    Fast486OpcodeAdcAl,                 /* 0x14 */
+    Fast486OpcodeAdcEax,                /* 0x15 */
+    Fast486OpcodePushSs,                /* 0x16 */
+    Fast486OpcodePopSs,                 /* 0x17 */
+    Fast486OpcodeSbbByteModrm,          /* 0x18 - 0x1B */
     Fast486OpcodeSbbModrm,
     Fast486OpcodeSbbByteModrm,
     Fast486OpcodeSbbModrm,
-    Fast486OpcodeSbbAl,
-    Fast486OpcodeSbbEax,
-    Fast486OpcodePushDs,
-    Fast486OpcodePopDs,
-    Fast486OpcodeAndByteModrm,
+    Fast486OpcodeSbbAl,                 /* 0x1C */
+    Fast486OpcodeSbbEax,                /* 0x1D */
+    Fast486OpcodePushDs,                /* 0x1E */
+    Fast486OpcodePopDs,                 /* 0x1F */
+    Fast486OpcodeAndByteModrm,          /* 0x20 - 0x23 */
     Fast486OpcodeAndModrm,
     Fast486OpcodeAndByteModrm,
     Fast486OpcodeAndModrm,
-    Fast486OpcodeAndAl,
-    Fast486OpcodeAndEax,
-    Fast486OpcodePrefix,
-    Fast486OpcodeDaa,
-    Fast486OpcodeCmpSubByteModrm,
+    Fast486OpcodeAndAl,                 /* 0x24 */
+    Fast486OpcodeAndEax,                /* 0x25 */
+    Fast486OpcodePrefix,                /* 0x26 */
+    Fast486OpcodeDaa,                   /* 0x27 */
+    Fast486OpcodeCmpSubByteModrm,       /* 0x28 - 0x2B */
     Fast486OpcodeCmpSubModrm,
     Fast486OpcodeCmpSubByteModrm,
     Fast486OpcodeCmpSubModrm,
-    Fast486OpcodeCmpSubAl,
-    Fast486OpcodeCmpSubEax,
-    Fast486OpcodePrefix,
-    Fast486OpcodeDas,
-    Fast486OpcodeXorByteModrm,
+    Fast486OpcodeCmpSubAl,              /* 0x2C */
+    Fast486OpcodeCmpSubEax,             /* 0x2D */
+    Fast486OpcodePrefix,                /* 0x2E */
+    Fast486OpcodeDas,                   /* 0x2F */
+    Fast486OpcodeXorByteModrm,          /* 0x30 - 0x33 */
     Fast486OpcodeXorModrm,
     Fast486OpcodeXorByteModrm,
     Fast486OpcodeXorModrm,
-    Fast486OpcodeXorAl,
-    Fast486OpcodeXorEax,
-    Fast486OpcodePrefix,
-    Fast486OpcodeAaa,
-    Fast486OpcodeCmpSubByteModrm,
+    Fast486OpcodeXorAl,                 /* 0x34 */
+    Fast486OpcodeXorEax,                /* 0x35 */
+    Fast486OpcodePrefix,                /* 0x36 */
+    Fast486OpcodeAaa,                   /* 0x37 */
+    Fast486OpcodeCmpSubByteModrm,       /* 0x38 - 0x3B */
     Fast486OpcodeCmpSubModrm,
     Fast486OpcodeCmpSubByteModrm,
     Fast486OpcodeCmpSubModrm,
-    Fast486OpcodeCmpSubAl,
-    Fast486OpcodeCmpSubEax,
-    Fast486OpcodePrefix,
-    Fast486OpcodeAas,
+    Fast486OpcodeCmpSubAl,              /* 0x3C */
+    Fast486OpcodeCmpSubEax,             /* 0x3D */
+    Fast486OpcodePrefix,                /* 0x3E */
+    Fast486OpcodeAas,                   /* 0x3F */
+    Fast486OpcodeIncrement,             /* 0x40 - 0x47 */
     Fast486OpcodeIncrement,
     Fast486OpcodeIncrement,
     Fast486OpcodeIncrement,
@@ -108,8 +110,7 @@ Fast486OpcodeHandlers[FAST486_NUM_OPCODE_HANDLERS] =
     Fast486OpcodeIncrement,
     Fast486OpcodeIncrement,
     Fast486OpcodeIncrement,
-    Fast486OpcodeIncrement,
-    Fast486OpcodeDecrement,
+    Fast486OpcodeDecrement,             /* 0x48 - 0x4F */
     Fast486OpcodeDecrement,
     Fast486OpcodeDecrement,
     Fast486OpcodeDecrement,
@@ -117,6 +118,7 @@ Fast486OpcodeHandlers[FAST486_NUM_OPCODE_HANDLERS] =
     Fast486OpcodeDecrement,
     Fast486OpcodeDecrement,
     Fast486OpcodeDecrement,
+    Fast486OpcodePushReg,               /* 0x50 - 0x57 */
     Fast486OpcodePushReg,
     Fast486OpcodePushReg,
     Fast486OpcodePushReg,
@@ -124,8 +126,7 @@ Fast486OpcodeHandlers[FAST486_NUM_OPCODE_HANDLERS] =
     Fast486OpcodePushReg,
     Fast486OpcodePushReg,
     Fast486OpcodePushReg,
-    Fast486OpcodePushReg,
-    Fast486OpcodePopReg,
+    Fast486OpcodePopReg,                /* 0x58 - 0x5F */
     Fast486OpcodePopReg,
     Fast486OpcodePopReg,
     Fast486OpcodePopReg,
@@ -133,23 +134,23 @@ Fast486OpcodeHandlers[FAST486_NUM_OPCODE_HANDLERS] =
     Fast486OpcodePopReg,
     Fast486OpcodePopReg,
     Fast486OpcodePopReg,
-    Fast486OpcodePushAll,
-    Fast486OpcodePopAll,
-    Fast486OpcodeBound,
-    Fast486OpcodeArpl,
+    Fast486OpcodePushAll,               /* 0x60 */
+    Fast486OpcodePopAll,                /* 0x61 */
+    Fast486OpcodeBound,                 /* 0x62 */
+    Fast486OpcodeArpl,                  /* 0x63 */
+    Fast486OpcodePrefix,                /* 0x64 - 0x67 */
     Fast486OpcodePrefix,
     Fast486OpcodePrefix,
     Fast486OpcodePrefix,
-    Fast486OpcodePrefix,
-    Fast486OpcodePushImm,
-    Fast486OpcodeImulModrmImm,
-    Fast486OpcodePushByteImm,
-    Fast486OpcodeImulModrmImm,
-    Fast486OpcodeIns,
-    Fast486OpcodeIns,
-    Fast486OpcodeOuts,
-    Fast486OpcodeOuts,
-    Fast486OpcodeShortConditionalJmp,
+    Fast486OpcodePushImm,               /* 0x68 */
+    Fast486OpcodeImulModrmImm,          /* 0x69 */
+    Fast486OpcodePushByteImm,           /* 0x6A */
+    Fast486OpcodeImulModrmImm,          /* 0x6B */
+    Fast486OpcodeIns,                   /* 0x6C */
+    Fast486OpcodeIns,                   /* 0x6D */
+    Fast486OpcodeOuts,                  /* 0x6E */
+    Fast486OpcodeOuts,                  /* 0x6F */
+    Fast486OpcodeShortConditionalJmp,   /* 0x70 - 0x7F */
     Fast486OpcodeShortConditionalJmp,
     Fast486OpcodeShortConditionalJmp,
     Fast486OpcodeShortConditionalJmp,
@@ -165,55 +166,55 @@ Fast486OpcodeHandlers[FAST486_NUM_OPCODE_HANDLERS] =
     Fast486OpcodeShortConditionalJmp,
     Fast486OpcodeShortConditionalJmp,
     Fast486OpcodeShortConditionalJmp,
-    Fast486OpcodeGroup8082,
-    Fast486OpcodeGroup81,
-    Fast486OpcodeGroup8082,
-    Fast486OpcodeGroup83,
-    Fast486OpcodeTestByteModrm,
-    Fast486OpcodeTestModrm,
-    Fast486OpcodeXchgByteModrm,
-    Fast486OpcodeXchgModrm,
-    Fast486OpcodeMovByteModrm,
-    Fast486OpcodeMovModrm,
-    Fast486OpcodeMovByteModrm,
-    Fast486OpcodeMovModrm,
-    Fast486OpcodeMovStoreSeg,
-    Fast486OpcodeLea,
-    Fast486OpcodeMovLoadSeg,
-    Fast486OpcodeGroup8F,
-    Fast486OpcodeNop,
+    Fast486OpcodeGroup8082,             /* 0x80 */
+    Fast486OpcodeGroup81,               /* 0x81 */
+    Fast486OpcodeGroup8082,             /* 0x82 */
+    Fast486OpcodeGroup83,               /* 0x83 */
+    Fast486OpcodeTestByteModrm,         /* 0x84 */
+    Fast486OpcodeTestModrm,             /* 0x85 */
+    Fast486OpcodeXchgByteModrm,         /* 0x86 */
+    Fast486OpcodeXchgModrm,             /* 0x87 */
+    Fast486OpcodeMovByteModrm,          /* 0x88 */
+    Fast486OpcodeMovModrm,              /* 0x89 */
+    Fast486OpcodeMovByteModrm,          /* 0x8A */
+    Fast486OpcodeMovModrm,              /* 0x8B */
+    Fast486OpcodeMovStoreSeg,           /* 0x8C */
+    Fast486OpcodeLea,                   /* 0x8D */
+    Fast486OpcodeMovLoadSeg,            /* 0x8E */
+    Fast486OpcodeGroup8F,               /* 0x8F */
+    Fast486OpcodeNop,                   /* 0x90 */
+    Fast486OpcodeExchangeEax,           /* 0x91 - 0x97 */
     Fast486OpcodeExchangeEax,
     Fast486OpcodeExchangeEax,
     Fast486OpcodeExchangeEax,
     Fast486OpcodeExchangeEax,
     Fast486OpcodeExchangeEax,
     Fast486OpcodeExchangeEax,
-    Fast486OpcodeExchangeEax,
-    Fast486OpcodeCwde,
-    Fast486OpcodeCdq,
-    Fast486OpcodeCallAbs,
-    Fast486OpcodeWait,
-    Fast486OpcodePushFlags,
-    Fast486OpcodePopFlags,
-    Fast486OpcodeSahf,
-    Fast486OpcodeLahf,
-    Fast486OpcodeMovAlOffset,
-    Fast486OpcodeMovEaxOffset,
-    Fast486OpcodeMovOffsetAl,
-    Fast486OpcodeMovOffsetEax,
-    Fast486OpcodeMovs,
-    Fast486OpcodeMovs,
-    Fast486OpcodeCmps,
-    Fast486OpcodeCmps,
-    Fast486OpcodeTestAl,
-    Fast486OpcodeTestEax,
-    Fast486OpcodeStos,
-    Fast486OpcodeStos,
-    Fast486OpcodeLods,
-    Fast486OpcodeLods,
-    Fast486OpcodeScas,
-    Fast486OpcodeScas,
-    Fast486OpcodeMovByteRegImm,
+    Fast486OpcodeCwde,                  /* 0x98 */
+    Fast486OpcodeCdq,                   /* 0x99 */
+    Fast486OpcodeCallAbs,               /* 0x9A */
+    Fast486OpcodeWait,                  /* 0x9B */
+    Fast486OpcodePushFlags,             /* 0x9C */
+    Fast486OpcodePopFlags,              /* 0x9D */
+    Fast486OpcodeSahf,                  /* 0x9E */
+    Fast486OpcodeLahf,                  /* 0x9F */
+    Fast486OpcodeMovAlOffset,           /* 0xA0 */
+    Fast486OpcodeMovEaxOffset,          /* 0xA1 */
+    Fast486OpcodeMovOffsetAl,           /* 0xA2 */
+    Fast486OpcodeMovOffsetEax,          /* 0xA3 */
+    Fast486OpcodeMovs,                  /* 0xA4 */
+    Fast486OpcodeMovs,                  /* 0xA5 */
+    Fast486OpcodeCmps,                  /* 0xA6 */
+    Fast486OpcodeCmps,                  /* 0xA7 */
+    Fast486OpcodeTestAl,                /* 0xA8 */
+    Fast486OpcodeTestEax,               /* 0xA9 */
+    Fast486OpcodeStos,                  /* 0xAA */
+    Fast486OpcodeStos,                  /* 0xAB */
+    Fast486OpcodeLods,                  /* 0xAC */
+    Fast486OpcodeLods,                  /* 0xAD */
+    Fast486OpcodeScas,                  /* 0xAE */
+    Fast486OpcodeScas,                  /* 0xAF */
+    Fast486OpcodeMovByteRegImm,         /* 0xB0 - 0xB7 */
     Fast486OpcodeMovByteRegImm,
     Fast486OpcodeMovByteRegImm,
     Fast486OpcodeMovByteRegImm,
@@ -221,6 +222,7 @@ Fast486OpcodeHandlers[FAST486_NUM_OPCODE_HANDLERS] =
     Fast486OpcodeMovByteRegImm,
     Fast486OpcodeMovByteRegImm,
     Fast486OpcodeMovByteRegImm,
+    Fast486OpcodeMovRegImm,             /* 0xB8 - 0xBF */
     Fast486OpcodeMovRegImm,
     Fast486OpcodeMovRegImm,
     Fast486OpcodeMovRegImm,
@@ -228,75 +230,85 @@ Fast486OpcodeHandlers[FAST486_NUM_OPCODE_HANDLERS] =
     Fast486OpcodeMovRegImm,
     Fast486OpcodeMovRegImm,
     Fast486OpcodeMovRegImm,
-    Fast486OpcodeMovRegImm,
-    Fast486OpcodeGroupC0,
-    Fast486OpcodeGroupC1,
-    Fast486OpcodeRet,
-    Fast486OpcodeRet,
-    Fast486OpcodeLdsLes,
-    Fast486OpcodeLdsLes,
-    Fast486OpcodeGroupC6,
-    Fast486OpcodeGroupC7,
-    Fast486OpcodeEnter,
-    Fast486OpcodeLeave,
-    Fast486OpcodeRetFar,
-    Fast486OpcodeRetFar,
-    Fast486OpcodeInt,
-    Fast486OpcodeInt,
-    Fast486OpcodeInt,
-    Fast486OpcodeIret,
-    Fast486OpcodeGroupD0,
+    Fast486OpcodeGroupC0,               /* 0xC0 */
+    Fast486OpcodeGroupC1,               /* 0xC1 */
+    Fast486OpcodeRet,                   /* 0xC2 */
+    Fast486OpcodeRet,                   /* 0xC3 */
+    Fast486OpcodeLdsLes,                /* 0xC4 */
+    Fast486OpcodeLdsLes,                /* 0xC5 */
+    Fast486OpcodeGroupC6,               /* 0xC6 */
+    Fast486OpcodeGroupC7,               /* 0xC7 */
+    Fast486OpcodeEnter,                 /* 0xC8 */
+    Fast486OpcodeLeave,                 /* 0xC9 */
+    Fast486OpcodeRetFar,                /* 0xCA */
+    Fast486OpcodeRetFar,                /* 0xCB */
+    Fast486OpcodeInt,                   /* 0xCC */
+    Fast486OpcodeInt,                   /* 0xCD */
+    Fast486OpcodeInt,                   /* 0xCE */
+    Fast486OpcodeIret,                  /* 0xCF */
+    Fast486OpcodeGroupD0,               /* 0xD0 - 0xD3 */
     Fast486OpcodeGroupD1,
     Fast486OpcodeGroupD2,
     Fast486OpcodeGroupD3,
-    Fast486OpcodeAam,
-    Fast486OpcodeAad,
-    Fast486OpcodeSalc,
-    Fast486OpcodeXlat,
-    NULL, // TODO: OPCODE 0xD8 NOT SUPPORTED
-    NULL, // TODO: OPCODE 0xD9 NOT SUPPORTED
-    NULL, // TODO: OPCODE 0xDA NOT SUPPORTED
-    NULL, // TODO: OPCODE 0xDB NOT SUPPORTED
-    NULL, // TODO: OPCODE 0xDC NOT SUPPORTED
-    NULL, // TODO: OPCODE 0xDD NOT SUPPORTED
-    NULL, // TODO: OPCODE 0xDE NOT SUPPORTED
-    NULL, // TODO: OPCODE 0xDF NOT SUPPORTED
-    Fast486OpcodeLoop,
+    Fast486OpcodeAam,                   /* 0xD4 */
+    Fast486OpcodeAad,                   /* 0xD5 */
+    Fast486OpcodeSalc,                  /* 0xD6 */
+    Fast486OpcodeXlat,                  /* 0xD7 */
+    Fast486FpuOpcodeD8DC,               /* 0xD8 - 0xDF */
+    Fast486FpuOpcodeD9,
+    Fast486FpuOpcodeDA,
+    Fast486FpuOpcodeDB,
+    Fast486FpuOpcodeD8DC,
+    Fast486FpuOpcodeDD,
+    Fast486FpuOpcodeDE,
+    Fast486FpuOpcodeDF,
+    Fast486OpcodeLoop,                  /* 0xE0 - 0xE2 */
     Fast486OpcodeLoop,
     Fast486OpcodeLoop,
-    Fast486OpcodeJecxz,
-    Fast486OpcodeInByte,
-    Fast486OpcodeIn,
-    Fast486OpcodeOutByte,
-    Fast486OpcodeOut,
-    Fast486OpcodeCall,
-    Fast486OpcodeJmp,
-    Fast486OpcodeJmpAbs,
-    Fast486OpcodeShortJump,
-    Fast486OpcodeInByte,
-    Fast486OpcodeIn,
-    Fast486OpcodeOutByte,
-    Fast486OpcodeOut,
-    Fast486OpcodePrefix,
-    NULL, // Invalid
-    Fast486OpcodePrefix,
-    Fast486OpcodePrefix,
-    Fast486OpcodeHalt,
-    Fast486OpcodeComplCarry,
-    Fast486OpcodeGroupF6,
-    Fast486OpcodeGroupF7,
-    Fast486OpcodeClearCarry,
-    Fast486OpcodeSetCarry,
-    Fast486OpcodeClearInt,
-    Fast486OpcodeSetInt,
-    Fast486OpcodeClearDir,
-    Fast486OpcodeSetDir,
-    Fast486OpcodeGroupFE,
-    Fast486OpcodeGroupFF,
+    Fast486OpcodeJecxz,                 /* 0xE3 */
+    Fast486OpcodeInByte,                /* 0xE4 */
+    Fast486OpcodeIn,                    /* 0xE5 */
+    Fast486OpcodeOutByte,               /* 0xE6 */
+    Fast486OpcodeOut,                   /* 0xE7 */
+    Fast486OpcodeCall,                  /* 0xE8 */
+    Fast486OpcodeJmp,                   /* 0xE9 */
+    Fast486OpcodeJmpAbs,                /* 0xEA */
+    Fast486OpcodeShortJump,             /* 0xEB */
+    Fast486OpcodeInByte,                /* 0xEC */
+    Fast486OpcodeIn,                    /* 0xED */
+    Fast486OpcodeOutByte,               /* 0xEE */
+    Fast486OpcodeOut,                   /* 0xEF */
+    Fast486OpcodePrefix,                /* 0xF0 */
+    Fast486OpcodeInvalid,               /* 0xF1 */  // Invalid opcode -- ICEBP/INT01 opcode
+    Fast486OpcodePrefix,                /* 0xF2 */
+    Fast486OpcodePrefix,                /* 0xF3 */
+    Fast486OpcodeHalt,                  /* 0xF4 */
+    Fast486OpcodeComplCarry,            /* 0xF5 */
+    Fast486OpcodeGroupF6,               /* 0xF6 */
+    Fast486OpcodeGroupF7,               /* 0xF7 */
+    Fast486OpcodeClearCarry,            /* 0xF8 */
+    Fast486OpcodeSetCarry,              /* 0xF9 */
+    Fast486OpcodeClearInt,              /* 0xFA */
+    Fast486OpcodeSetInt,                /* 0xFB */
+    Fast486OpcodeClearDir,              /* 0xFC */
+    Fast486OpcodeSetDir,                /* 0xFD */
+    Fast486OpcodeGroupFE,               /* 0xFE */
+    Fast486OpcodeGroupFF,               /* 0xFF */
 };
 
 /* PUBLIC FUNCTIONS ***********************************************************/
 
+FAST486_OPCODE_HANDLER(Fast486OpcodeInvalid)
+{
+    /*
+     * This is not a valid opcode.
+     * Well, not totally: see http://www.rcollins.org/secrets/opcodes/ICEBP.html
+     * for more details.
+     */
+    DPRINT1("FAST486 -- Calling ICEBP opcode\n");
+    Fast486Exception(State, FAST486_EXCEPTION_UD);
+}
+
 FAST486_OPCODE_HANDLER(Fast486OpcodePrefix)
 {
     BOOLEAN Valid = FALSE;
@@ -452,10 +464,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePrefix)
 
         /* Throw an exception */
         Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeIncrement)
@@ -487,9 +496,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIncrement)
     State->Flags.Zf = (Value == 0);
     State->Flags.Af = ((Value & 0x0F) == 0);
     State->Flags.Pf = Fast486CalculateParity(LOBYTE(Value));
-
-    /* Return success */
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeDecrement)
@@ -521,9 +527,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeDecrement)
     State->Flags.Zf = (Value == 0);
     State->Flags.Af = ((Value & 0x0F) == 0x0F);
     State->Flags.Pf = Fast486CalculateParity(LOBYTE(Value));
-
-    /* Return success */
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodePushReg)
@@ -534,13 +537,13 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePushReg)
     ASSERT((Opcode & 0xF8) == 0x50);
 
     /* Call the internal function */
-    return Fast486StackPush(State, State->GeneralRegs[Opcode & 0x07].Long);
+    Fast486StackPush(State, State->GeneralRegs[Opcode & 0x07].Long);
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodePopReg)
 {
     ULONG Value;
-    BOOLEAN Size = State->SegmentRegs[FAST486_REG_SS].Size;
+    BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
 
     TOGGLE_OPSIZE(Size);
     NO_LOCK_PREFIX();
@@ -549,25 +552,15 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePopReg)
     ASSERT((Opcode & 0xF8) == 0x58);
 
     /* Call the internal function */
-    if (!Fast486StackPop(State, &Value)) return FALSE;
+    if (!Fast486StackPop(State, &Value)) return;
 
     /* Store the value */
     if (Size) State->GeneralRegs[Opcode & 0x07].Long = Value;
     else State->GeneralRegs[Opcode & 0x07].LowWord = Value;
-
-    /* Return success */
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeNop)
 {
-    if (State->PrefixFlags & FAST486_PREFIX_REP)
-    {
-        /* Idle cycle */
-        State->IdleCallback(State);
-    }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeExchangeEax)
@@ -598,23 +591,24 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeExchangeEax)
         State->GeneralRegs[Reg].LowWord = State->GeneralRegs[FAST486_REG_EAX].LowWord;
         State->GeneralRegs[FAST486_REG_EAX].LowWord = Value;
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeShortConditionalJmp)
 {
     BOOLEAN Jump = FALSE;
     CHAR Offset = 0;
+    BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
 
     /* Make sure this is the right instruction */
     ASSERT((Opcode & 0xF0) == 0x70);
 
+    TOGGLE_OPSIZE(Size);
+
     /* Fetch the offset */
     if (!Fast486FetchByte(State, (PUCHAR)&Offset))
     {
         /* An exception occurred */
-        return FALSE;
+        return;
     }
 
     switch ((Opcode & 0x0F) >> 1)
@@ -686,10 +680,13 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeShortConditionalJmp)
     {
         /* Move the instruction pointer */
         State->InstPtr.Long += Offset;
-    }
 
-    /* Return success */
-    return TRUE;
+        if (!Size)
+        {
+            /* Clear the top half of EIP */
+            State->InstPtr.Long &= 0xFFFF;
+        }
+    }
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeClearCarry)
@@ -701,12 +698,11 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeClearCarry)
     if (State->PrefixFlags)
     {
         Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
+        return;
     }
 
     /* Clear CF and return success */
     State->Flags.Cf = FALSE;
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeSetCarry)
@@ -718,12 +714,11 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSetCarry)
     if (State->PrefixFlags)
     {
         Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
+        return;
     }
 
     /* Set CF and return success*/
     State->Flags.Cf = TRUE;
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeComplCarry)
@@ -735,12 +730,12 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeComplCarry)
     if (State->PrefixFlags)
     {
         Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
+        return;
     }
 
     /* Toggle CF and return success */
     State->Flags.Cf = !State->Flags.Cf;
-    return TRUE;
+    return;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeClearInt)
@@ -752,7 +747,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeClearInt)
     if (State->PrefixFlags)
     {
         Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
+        return;
     }
 
     /* Check for protected mode */
@@ -768,7 +763,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeClearInt)
         {
             /* General Protection Fault */
             Fast486Exception(State, FAST486_EXCEPTION_GP);
-            return FALSE;
+            return;
         }
     }
     else
@@ -776,9 +771,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeClearInt)
         /* Just clear the interrupt flag */
         State->Flags.If = FALSE;
     }
-
-    /* Return success */
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeSetInt)
@@ -790,7 +782,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSetInt)
     if (State->PrefixFlags)
     {
         Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
+        return;
     }
 
     /* Check for protected mode */
@@ -806,7 +798,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSetInt)
         {
             /* General Protection Fault */
             Fast486Exception(State, FAST486_EXCEPTION_GP);
-            return FALSE;
+            return;
         }
     }
     else
@@ -814,9 +806,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSetInt)
         /* Just set the interrupt flag */
         State->Flags.If = TRUE;
     }
-
-    /* Return success */
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeClearDir)
@@ -828,12 +817,11 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeClearDir)
     if (State->PrefixFlags)
     {
         Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
+        return;
     }
 
-    /* Clear DF and return success */
+    /* Clear DF */
     State->Flags.Df = FALSE;
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeSetDir)
@@ -845,12 +833,11 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSetDir)
     if (State->PrefixFlags)
     {
         Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
+        return;
     }
 
-    /* Set DF and return success*/
+    /* Set DF */
     State->Flags.Df = TRUE;
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeHalt)
@@ -862,21 +849,18 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeHalt)
     if (State->PrefixFlags)
     {
         Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
+        return;
     }
 
     /* Privileged instructions can only be executed under CPL = 0 */
     if (State->SegmentRegs[FAST486_REG_CS].Dpl != 0)
     {
         Fast486Exception(State, FAST486_EXCEPTION_GP);
-        return FALSE;
+        return;
     }
 
     /* Halt */
-    while (State->IntStatus != FAST486_INT_SIGNAL) State->IdleCallback(State);
-
-    /* Return success */
-    return TRUE;
+    State->Halted = TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeInByte)
@@ -893,7 +877,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeInByte)
         if (!Fast486FetchByte(State, &Data))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Set the port number to the parameter */
@@ -910,8 +894,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeInByte)
 
     /* Store the result in AL */
     State->GeneralRegs[FAST486_REG_EAX].LowByte = Data;
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeIn)
@@ -933,7 +915,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIn)
         if (!Fast486FetchByte(State, &Data))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Set the port number to the parameter */
@@ -965,8 +947,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIn)
         /* Store the value in AX */
         State->GeneralRegs[FAST486_REG_EAX].LowWord = Data;
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeOutByte)
@@ -983,7 +963,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOutByte)
         if (!Fast486FetchByte(State, &Data))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Set the port number to the parameter */
@@ -1000,8 +980,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOutByte)
 
     /* Write the byte to the I/O port */
     State->IoWriteCallback(State, Port, &Data, 1, sizeof(UCHAR));
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeOut)
@@ -1023,7 +1001,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOut)
         if (!Fast486FetchByte(State, &Data))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Set the port number to the parameter */
@@ -1051,13 +1029,14 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOut)
         /* Write a word to the I/O port */
         State->IoWriteCallback(State, Port, &Data, 1, sizeof(USHORT));
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeShortJump)
 {
     CHAR Offset = 0;
+    BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
+
+    TOGGLE_OPSIZE(Size);
 
     /* Make sure this is the right instruction */
     ASSERT(Opcode == 0xEB);
@@ -1066,13 +1045,17 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeShortJump)
     if (!Fast486FetchByte(State, (PUCHAR)&Offset))
     {
         /* An exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Move the instruction pointer */
     State->InstPtr.Long += Offset;
 
-    return TRUE;
+    if (!Size)
+    {
+        /* Clear the top half of EIP */
+        State->InstPtr.Long &= 0xFFFF;
+    }
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeMovRegImm)
@@ -1093,7 +1076,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovRegImm)
         if (!Fast486FetchDword(State, &Value))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Store the value in the register */
@@ -1107,14 +1090,12 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovRegImm)
         if (!Fast486FetchWord(State, &Value))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Store the value in the register */
         State->GeneralRegs[Opcode & 0x07].LowWord = Value;
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeMovByteRegImm)
@@ -1128,14 +1109,14 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovByteRegImm)
     {
         /* Invalid prefix */
         Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
+        return;
     }
 
     /* Fetch the byte */
     if (!Fast486FetchByte(State, &Value))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     if (Opcode & 0x04)
@@ -1148,8 +1129,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovByteRegImm)
         /* AL, CL, DL or BL */
         State->GeneralRegs[Opcode & 0x03].LowByte = Value;
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeAddByteModrm)
@@ -1167,7 +1146,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddByteModrm)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     if (!Fast486ReadModrmByteOperands(State,
@@ -1176,7 +1155,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddByteModrm)
                                       &SecondValue))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Calculate the result */
@@ -1192,10 +1171,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddByteModrm)
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Write back the result */
-    return Fast486WriteModrmByteOperands(State,
-                                         &ModRegRm,
-                                         Opcode & FAST486_OPCODE_WRITE_REG,
-                                         Result);
+    Fast486WriteModrmByteOperands(State,
+                                  &ModRegRm,
+                                  Opcode & FAST486_OPCODE_WRITE_REG,
+                                  Result);
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeAddModrm)
@@ -1215,7 +1194,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddModrm)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Check the operand size */
@@ -1229,7 +1208,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddModrm)
                                           &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -1245,10 +1224,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddModrm)
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
-        return Fast486WriteModrmDwordOperands(State,
-                                              &ModRegRm,
-                                              Opcode & FAST486_OPCODE_WRITE_REG,
-                                              Result);
+        Fast486WriteModrmDwordOperands(State,
+                                       &ModRegRm,
+                                       Opcode & FAST486_OPCODE_WRITE_REG,
+                                       Result);
     }
     else
     {
@@ -1260,7 +1239,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddModrm)
                                           &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -1276,10 +1255,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddModrm)
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
-        return Fast486WriteModrmWordOperands(State,
-                                              &ModRegRm,
-                                              Opcode & FAST486_OPCODE_WRITE_REG,
-                                              Result);
+        Fast486WriteModrmWordOperands(State,
+                                       &ModRegRm,
+                                       Opcode & FAST486_OPCODE_WRITE_REG,
+                                       Result);
     }
 }
 
@@ -1295,13 +1274,13 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddAl)
     {
         /* This opcode doesn't take any prefixes */
         Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
+        return;
     }
 
     if (!Fast486FetchByte(State, &SecondValue))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Calculate the result */
@@ -1318,8 +1297,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddAl)
 
     /* Write back the result */
     State->GeneralRegs[FAST486_REG_EAX].LowByte = Result;
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeAddEax)
@@ -1340,7 +1317,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddEax)
         if (!Fast486FetchDword(State, &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -1366,7 +1343,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddEax)
         if (!Fast486FetchWord(State, &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -1384,8 +1361,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAddEax)
         /* Write back the result */
         State->GeneralRegs[FAST486_REG_EAX].LowWord = Result;
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeOrByteModrm)
@@ -1403,7 +1378,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOrByteModrm)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     if (!Fast486ReadModrmByteOperands(State,
@@ -1412,7 +1387,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOrByteModrm)
                                       &SecondValue))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Calculate the result */
@@ -1426,10 +1401,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOrByteModrm)
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Write back the result */
-    return Fast486WriteModrmByteOperands(State,
-                                         &ModRegRm,
-                                         Opcode & FAST486_OPCODE_WRITE_REG,
-                                         Result);
+    Fast486WriteModrmByteOperands(State,
+                                  &ModRegRm,
+                                  Opcode & FAST486_OPCODE_WRITE_REG,
+                                  Result);
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeOrModrm)
@@ -1449,7 +1424,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOrModrm)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Check the operand size */
@@ -1463,7 +1438,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOrModrm)
                                           &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -1477,10 +1452,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOrModrm)
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
-        return Fast486WriteModrmDwordOperands(State,
-                                              &ModRegRm,
-                                              Opcode & FAST486_OPCODE_WRITE_REG,
-                                              Result);
+        Fast486WriteModrmDwordOperands(State,
+                                       &ModRegRm,
+                                       Opcode & FAST486_OPCODE_WRITE_REG,
+                                       Result);
     }
     else
     {
@@ -1492,7 +1467,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOrModrm)
                                           &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -1506,10 +1481,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOrModrm)
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
-        return Fast486WriteModrmWordOperands(State,
-                                              &ModRegRm,
-                                              Opcode & FAST486_OPCODE_WRITE_REG,
-                                              Result);
+        Fast486WriteModrmWordOperands(State,
+                                       &ModRegRm,
+                                       Opcode & FAST486_OPCODE_WRITE_REG,
+                                       Result);
     }
 }
 
@@ -1525,13 +1500,13 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOrAl)
     {
         /* This opcode doesn't take any prefixes */
         Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
+        return;
     }
 
     if (!Fast486FetchByte(State, &SecondValue))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Calculate the result */
@@ -1546,8 +1521,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOrAl)
 
     /* Write back the result */
     State->GeneralRegs[FAST486_REG_EAX].LowByte = Result;
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeOrEax)
@@ -1568,7 +1541,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOrEax)
         if (!Fast486FetchDword(State, &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -1592,7 +1565,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOrEax)
         if (!Fast486FetchWord(State, &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -1608,8 +1581,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOrEax)
         /* Write back the result */
         State->GeneralRegs[FAST486_REG_EAX].LowWord = Result;
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeAndByteModrm)
@@ -1627,7 +1598,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAndByteModrm)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     if (!Fast486ReadModrmByteOperands(State,
@@ -1636,7 +1607,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAndByteModrm)
                                       &SecondValue))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Calculate the result */
@@ -1650,10 +1621,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAndByteModrm)
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Write back the result */
-    return Fast486WriteModrmByteOperands(State,
-                                         &ModRegRm,
-                                         Opcode & FAST486_OPCODE_WRITE_REG,
-                                         Result);
+    Fast486WriteModrmByteOperands(State,
+                                  &ModRegRm,
+                                  Opcode & FAST486_OPCODE_WRITE_REG,
+                                  Result);
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeAndModrm)
@@ -1673,7 +1644,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAndModrm)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Check the operand size */
@@ -1687,7 +1658,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAndModrm)
                                           &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -1701,10 +1672,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAndModrm)
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
-        return Fast486WriteModrmDwordOperands(State,
-                                              &ModRegRm,
-                                              Opcode & FAST486_OPCODE_WRITE_REG,
-                                              Result);
+        Fast486WriteModrmDwordOperands(State,
+                                       &ModRegRm,
+                                       Opcode & FAST486_OPCODE_WRITE_REG,
+                                       Result);
     }
     else
     {
@@ -1716,7 +1687,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAndModrm)
                                           &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -1730,10 +1701,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAndModrm)
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
-        return Fast486WriteModrmWordOperands(State,
-                                              &ModRegRm,
-                                              Opcode & FAST486_OPCODE_WRITE_REG,
-                                              Result);
+        Fast486WriteModrmWordOperands(State,
+                                       &ModRegRm,
+                                       Opcode & FAST486_OPCODE_WRITE_REG,
+                                       Result);
     }
 }
 
@@ -1750,7 +1721,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAndAl)
     if (!Fast486FetchByte(State, &SecondValue))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Calculate the result */
@@ -1765,8 +1736,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAndAl)
 
     /* Write back the result */
     State->GeneralRegs[FAST486_REG_EAX].LowByte = Result;
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeAndEax)
@@ -1787,7 +1756,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAndEax)
         if (!Fast486FetchDword(State, &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -1811,7 +1780,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAndEax)
         if (!Fast486FetchWord(State, &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -1827,8 +1796,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAndEax)
         /* Write back the result */
         State->GeneralRegs[FAST486_REG_EAX].LowWord = Result;
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeXorByteModrm)
@@ -1846,7 +1813,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXorByteModrm)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     if (!Fast486ReadModrmByteOperands(State,
@@ -1855,7 +1822,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXorByteModrm)
                                       &SecondValue))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Calculate the result */
@@ -1869,10 +1836,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXorByteModrm)
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Write back the result */
-    return Fast486WriteModrmByteOperands(State,
-                                         &ModRegRm,
-                                         Opcode & FAST486_OPCODE_WRITE_REG,
-                                         Result);
+    Fast486WriteModrmByteOperands(State,
+                                  &ModRegRm,
+                                  Opcode & FAST486_OPCODE_WRITE_REG,
+                                  Result);
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeXorModrm)
@@ -1892,7 +1859,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXorModrm)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Check the operand size */
@@ -1906,7 +1873,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXorModrm)
                                           &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -1920,10 +1887,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXorModrm)
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
-        return Fast486WriteModrmDwordOperands(State,
-                                              &ModRegRm,
-                                              Opcode & FAST486_OPCODE_WRITE_REG,
-                                              Result);
+        Fast486WriteModrmDwordOperands(State,
+                                       &ModRegRm,
+                                       Opcode & FAST486_OPCODE_WRITE_REG,
+                                       Result);
     }
     else
     {
@@ -1935,7 +1902,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXorModrm)
                                           &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -1949,10 +1916,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXorModrm)
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
-        return Fast486WriteModrmWordOperands(State,
-                                              &ModRegRm,
-                                              Opcode & FAST486_OPCODE_WRITE_REG,
-                                              Result);
+        Fast486WriteModrmWordOperands(State,
+                                      &ModRegRm,
+                                      Opcode & FAST486_OPCODE_WRITE_REG,
+                                      Result);
     }
 }
 
@@ -1968,13 +1935,13 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXorAl)
     {
         /* This opcode doesn't take any prefixes */
         Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
+        return;
     }
 
     if (!Fast486FetchByte(State, &SecondValue))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Calculate the result */
@@ -1989,8 +1956,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXorAl)
 
     /* Write back the result */
     State->GeneralRegs[FAST486_REG_EAX].LowByte = Result;
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeXorEax)
@@ -2011,7 +1976,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXorEax)
         if (!Fast486FetchDword(State, &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -2035,7 +2000,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXorEax)
         if (!Fast486FetchWord(State, &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -2051,8 +2016,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXorEax)
         /* Write back the result */
         State->GeneralRegs[FAST486_REG_EAX].LowWord = Result;
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeTestByteModrm)
@@ -2070,7 +2033,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeTestByteModrm)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     if (!Fast486ReadModrmByteOperands(State,
@@ -2079,7 +2042,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeTestByteModrm)
                                       &SecondValue))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
     /* Calculate the result */
     Result = FirstValue & SecondValue;
@@ -2090,9 +2053,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeTestByteModrm)
     State->Flags.Zf = (Result == 0);
     State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
-
-    /* The result is discarded */
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeTestModrm)
@@ -2112,7 +2072,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeTestModrm)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Check the operand size */
@@ -2126,7 +2086,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeTestModrm)
                                           &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -2149,7 +2109,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeTestModrm)
                                           &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -2162,9 +2122,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeTestModrm)
         State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
     }
-
-    /* The result is discarded */
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeTestAl)
@@ -2179,13 +2136,13 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeTestAl)
     {
         /* This opcode doesn't take any prefixes */
         Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
+        return;
     }
 
     if (!Fast486FetchByte(State, &SecondValue))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Calculate the result */
@@ -2197,9 +2154,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeTestAl)
     State->Flags.Zf = (Result == 0);
     State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
-
-    /* The result is discarded */
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeTestEax)
@@ -2220,7 +2174,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeTestEax)
         if (!Fast486FetchDword(State, &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -2241,7 +2195,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeTestEax)
         if (!Fast486FetchWord(State, &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -2254,9 +2208,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeTestEax)
         State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
     }
-
-    /* The result is discarded */
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeXchgByteModrm)
@@ -2274,7 +2225,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXchgByteModrm)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     if (!Fast486ReadModrmByteOperands(State,
@@ -2283,7 +2234,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXchgByteModrm)
                                       &SecondValue))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Write the value from the register to the R/M */
@@ -2293,20 +2244,14 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXchgByteModrm)
                                        FirstValue))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Write the value from the R/M to the register */
-    if (!Fast486WriteModrmByteOperands(State,
-                                       &ModRegRm,
-                                       TRUE,
-                                       SecondValue))
-    {
-        /* Exception occurred */
-        return FALSE;
-    }
-
-    return TRUE;
+    Fast486WriteModrmByteOperands(State,
+                                  &ModRegRm,
+                                  TRUE,
+                                  SecondValue);
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeXchgModrm)
@@ -2326,7 +2271,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXchgModrm)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Check the operand size */
@@ -2340,7 +2285,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXchgModrm)
                                           &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Write the value from the register to the R/M */
@@ -2350,18 +2295,14 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXchgModrm)
                                             FirstValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Write the value from the R/M to the register */
-        if (!Fast486WriteModrmDwordOperands(State,
-                                            &ModRegRm,
-                                            TRUE,
-                                            SecondValue))
-        {
-            /* Exception occurred */
-            return FALSE;
-        }
+        Fast486WriteModrmDwordOperands(State,
+                                       &ModRegRm,
+                                       TRUE,
+                                       SecondValue);
     }
     else
     {
@@ -2373,7 +2314,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXchgModrm)
                                           &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Write the value from the register to the R/M */
@@ -2383,28 +2324,21 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXchgModrm)
                                            FirstValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Write the value from the R/M to the register */
-        if (!Fast486WriteModrmWordOperands(State,
-                                           &ModRegRm,
-                                           TRUE,
-                                           SecondValue))
-        {
-            /* Exception occurred */
-            return FALSE;
-        }
+        Fast486WriteModrmWordOperands(State,
+                                      &ModRegRm,
+                                      TRUE,
+                                      SecondValue);
     }
-
-    /* The result is discarded */
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodePushEs)
 {
     /* Call the internal API */
-    return Fast486StackPush(State, State->SegmentRegs[FAST486_REG_ES].Selector);
+    Fast486StackPush(State, State->SegmentRegs[FAST486_REG_ES].Selector);
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodePopEs)
@@ -2414,17 +2348,17 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePopEs)
     if (!Fast486StackPop(State, &NewSelector))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Call the internal API */
-    return Fast486LoadSegment(State, FAST486_REG_ES, LOWORD(NewSelector));
+    Fast486LoadSegment(State, FAST486_REG_ES, LOWORD(NewSelector));
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodePushCs)
 {
     /* Call the internal API */
-    return Fast486StackPush(State, State->SegmentRegs[FAST486_REG_CS].Selector);
+    Fast486StackPush(State, State->SegmentRegs[FAST486_REG_CS].Selector);
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeAdcByteModrm)
@@ -2442,7 +2376,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAdcByteModrm)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     if (!Fast486ReadModrmByteOperands(State,
@@ -2451,7 +2385,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAdcByteModrm)
                                       &SecondValue))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Calculate the result */
@@ -2465,16 +2399,16 @@ 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) != 0);
+    State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
     State->Flags.Zf = (Result == 0);
     State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Write back the result */
-    return Fast486WriteModrmByteOperands(State,
-                                         &ModRegRm,
-                                         Opcode & FAST486_OPCODE_WRITE_REG,
-                                         Result);
+    Fast486WriteModrmByteOperands(State,
+                                  &ModRegRm,
+                                  Opcode & FAST486_OPCODE_WRITE_REG,
+                                  Result);
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeAdcModrm)
@@ -2494,7 +2428,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAdcModrm)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Check the operand size */
@@ -2508,7 +2442,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAdcModrm)
                                           &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -2522,16 +2456,16 @@ 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) != 0);
+        State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
         State->Flags.Zf = (Result == 0);
         State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
-        return Fast486WriteModrmDwordOperands(State,
-                                              &ModRegRm,
-                                              Opcode & FAST486_OPCODE_WRITE_REG,
-                                              Result);
+        Fast486WriteModrmDwordOperands(State,
+                                       &ModRegRm,
+                                       Opcode & FAST486_OPCODE_WRITE_REG,
+                                       Result);
     }
     else
     {
@@ -2543,7 +2477,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAdcModrm)
                                           &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -2557,16 +2491,16 @@ 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) != 0);
+        State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
         State->Flags.Zf = (Result == 0);
         State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
-        return Fast486WriteModrmWordOperands(State,
-                                              &ModRegRm,
-                                              Opcode & FAST486_OPCODE_WRITE_REG,
-                                              Result);
+        Fast486WriteModrmWordOperands(State,
+                                       &ModRegRm,
+                                       Opcode & FAST486_OPCODE_WRITE_REG,
+                                       Result);
     }
 
 }
@@ -2583,13 +2517,13 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAdcAl)
     {
         /* This opcode doesn't take any prefixes */
         Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
+        return;
     }
 
     if (!Fast486FetchByte(State, &SecondValue))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Calculate the result */
@@ -2603,15 +2537,13 @@ 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) != 0);
+    State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
     State->Flags.Zf = (Result == 0);
     State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Write back the result */
     State->GeneralRegs[FAST486_REG_EAX].LowByte = Result;
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeAdcEax)
@@ -2632,7 +2564,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAdcEax)
         if (!Fast486FetchDword(State, &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -2646,7 +2578,7 @@ 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) != 0);
+        State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
         State->Flags.Zf = (Result == 0);
         State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
@@ -2662,7 +2594,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAdcEax)
         if (!Fast486FetchWord(State, &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -2676,7 +2608,7 @@ 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) != 0);
+        State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
         State->Flags.Zf = (Result == 0);
         State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
@@ -2684,14 +2616,12 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAdcEax)
         /* Write back the result */
         State->GeneralRegs[FAST486_REG_EAX].LowWord = Result;
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodePushSs)
 {
     /* Call the internal API */
-    return Fast486StackPush(State, State->SegmentRegs[FAST486_REG_SS].Selector);
+    Fast486StackPush(State, State->SegmentRegs[FAST486_REG_SS].Selector);
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodePopSs)
@@ -2701,11 +2631,11 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePopSs)
     if (!Fast486StackPop(State, &NewSelector))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Call the internal API */
-    return Fast486LoadSegment(State, FAST486_REG_SS, LOWORD(NewSelector));
+    Fast486LoadSegment(State, FAST486_REG_SS, LOWORD(NewSelector));
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeSbbByteModrm)
@@ -2724,7 +2654,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbByteModrm)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     if (!Fast486ReadModrmByteOperands(State,
@@ -2733,7 +2663,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbByteModrm)
                                       &SecondValue))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Check if this is the instruction that writes to R/M */
@@ -2747,19 +2677,19 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbByteModrm)
     Result = FirstValue - SecondValue - Carry;
 
     /* Update the flags */
-    State->Flags.Cf = FirstValue < (SecondValue + 1);
+    State->Flags.Cf = Carry ? (FirstValue <= SecondValue) : (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 + 1) & 0x0F);
+    State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
     State->Flags.Zf = (Result == 0);
     State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Write back the result */
-    return Fast486WriteModrmByteOperands(State,
-                                         &ModRegRm,
-                                         Opcode & FAST486_OPCODE_WRITE_REG,
-                                         Result);
+    Fast486WriteModrmByteOperands(State,
+                                  &ModRegRm,
+                                  Opcode & FAST486_OPCODE_WRITE_REG,
+                                  Result);
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeSbbModrm)
@@ -2780,7 +2710,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbModrm)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Check the operand size */
@@ -2794,7 +2724,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbModrm)
                                            &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Check if this is the instruction that writes to R/M */
@@ -2808,19 +2738,19 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbModrm)
         Result = FirstValue - SecondValue - Carry;
 
         /* Update the flags */
-        State->Flags.Cf = FirstValue < (SecondValue + Carry);
+        State->Flags.Cf = Carry ? (FirstValue <= SecondValue) : (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 + 1) & 0x0F);
+        State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
         State->Flags.Zf = (Result == 0);
         State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
-        return Fast486WriteModrmDwordOperands(State,
-                                              &ModRegRm,
-                                              Opcode & FAST486_OPCODE_WRITE_REG,
-                                              Result);
+        Fast486WriteModrmDwordOperands(State,
+                                       &ModRegRm,
+                                       Opcode & FAST486_OPCODE_WRITE_REG,
+                                       Result);
     }
     else
     {
@@ -2832,7 +2762,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbModrm)
                                           &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Check if this is the instruction that writes to R/M */
@@ -2846,19 +2776,19 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbModrm)
         Result = FirstValue - SecondValue - Carry;
 
         /* Update the flags */
-        State->Flags.Cf = FirstValue < (SecondValue + Carry);
+        State->Flags.Cf = Carry ? (FirstValue <= SecondValue) : (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 + 1) & 0x0F);
+        State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
         State->Flags.Zf = (Result == 0);
         State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
 
         /* Write back the result */
-        return Fast486WriteModrmWordOperands(State,
-                                             &ModRegRm,
-                                             Opcode & FAST486_OPCODE_WRITE_REG,
-                                             Result);
+        Fast486WriteModrmWordOperands(State,
+                                      &ModRegRm,
+                                      Opcode & FAST486_OPCODE_WRITE_REG,
+                                      Result);
     }
 }
 
@@ -2875,32 +2805,29 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbAl)
     {
         /* This opcode doesn't take any prefixes */
         Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
+        return;
     }
 
     if (!Fast486FetchByte(State, &SecondValue))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Calculate the result */
     Result = FirstValue - SecondValue - Carry;
 
     /* Update the flags */
-    State->Flags.Cf = FirstValue < (SecondValue + Carry);
+    State->Flags.Cf = Carry ? (FirstValue <= SecondValue) : (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 + 1) & 0x0F);
+    State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
     State->Flags.Zf = (Result == 0);
     State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Write back the result */
     State->GeneralRegs[FAST486_REG_EAX].LowByte = Result;
-
-    return TRUE;
-
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeSbbEax)
@@ -2922,17 +2849,17 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbEax)
         if (!Fast486FetchDword(State, &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
         Result = FirstValue - SecondValue - Carry;
 
         /* Update the flags */
-        State->Flags.Cf = FirstValue < (SecondValue + Carry);
+        State->Flags.Cf = Carry ? (FirstValue <= SecondValue) : (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 + Carry) & 0x0F);
+        State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
         State->Flags.Zf = (Result == 0);
         State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
@@ -2948,17 +2875,17 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbEax)
         if (!Fast486FetchWord(State, &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
         Result = FirstValue - SecondValue - Carry;
 
         /* Update the flags */
-        State->Flags.Cf = FirstValue < (SecondValue + Carry);
+        State->Flags.Cf = Carry ? (FirstValue <= SecondValue) : (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 + Carry) & 0x0F);
+        State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
         State->Flags.Zf = (Result == 0);
         State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
         State->Flags.Pf = Fast486CalculateParity(Result);
@@ -2966,15 +2893,12 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbEax)
         /* Write back the result */
         State->GeneralRegs[FAST486_REG_EAX].LowWord = Result;
     }
-
-    return TRUE;
-
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodePushDs)
 {
     /* Call the internal API */
-    return Fast486StackPush(State, State->SegmentRegs[FAST486_REG_DS].Selector);
+    Fast486StackPush(State, State->SegmentRegs[FAST486_REG_DS].Selector);
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodePopDs)
@@ -2984,11 +2908,11 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePopDs)
     if (!Fast486StackPop(State, &NewSelector))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Call the internal API */
-    return Fast486LoadSegment(State, FAST486_REG_DS, LOWORD(NewSelector));
+    Fast486LoadSegment(State, FAST486_REG_DS, LOWORD(NewSelector));
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeDaa)
@@ -3024,7 +2948,12 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeDaa)
         State->Flags.Cf = TRUE;
     }
 
-    return TRUE;
+    Value = State->GeneralRegs[FAST486_REG_EAX].LowByte;
+
+    /* Update the flags */
+    State->Flags.Sf = (Value & SIGN_FLAG_BYTE) != 0;
+    State->Flags.Zf = (Value == 0);
+    State->Flags.Pf = Fast486CalculateParity(Value);
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubByteModrm)
@@ -3042,7 +2971,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubByteModrm)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     if (!Fast486ReadModrmByteOperands(State,
@@ -3051,7 +2980,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubByteModrm)
                                       &SecondValue))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Check if this is the instruction that writes to R/M */
@@ -3077,15 +3006,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubByteModrm)
     if (!(Opcode & 0x10))
     {
         /* Write back the result */
-        return Fast486WriteModrmByteOperands(State,
-                                             &ModRegRm,
-                                             Opcode & FAST486_OPCODE_WRITE_REG,
-                                             Result);
-    }
-    else
-    {
-        /* Discard the result */
-        return TRUE;
+        Fast486WriteModrmByteOperands(State,
+                                      &ModRegRm,
+                                      Opcode & FAST486_OPCODE_WRITE_REG,
+                                      Result);
     }
 }
 
@@ -3106,7 +3030,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubModrm)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Check the operand size */
@@ -3120,7 +3044,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubModrm)
                                           &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Check if this is the instruction that writes to R/M */
@@ -3146,15 +3070,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubModrm)
         if (!(Opcode & 0x10))
         {
             /* Write back the result */
-            return Fast486WriteModrmDwordOperands(State,
-                                                  &ModRegRm,
-                                                  Opcode & FAST486_OPCODE_WRITE_REG,
-                                                  Result);
-        }
-        else
-        {
-            /* Discard the result */
-            return TRUE;
+            Fast486WriteModrmDwordOperands(State,
+                                           &ModRegRm,
+                                           Opcode & FAST486_OPCODE_WRITE_REG,
+                                           Result);
         }
     }
     else
@@ -3167,7 +3086,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubModrm)
                                           &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Check if this is the instruction that writes to R/M */
@@ -3193,15 +3112,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubModrm)
         if (!(Opcode & 0x10))
         {
             /* Write back the result */
-            return Fast486WriteModrmWordOperands(State,
-                                                 &ModRegRm,
-                                                 Opcode & FAST486_OPCODE_WRITE_REG,
-                                                 Result);
-        }
-        else
-        {
-            /* Discard the result */
-            return TRUE;
+            Fast486WriteModrmWordOperands(State,
+                                          &ModRegRm,
+                                          Opcode & FAST486_OPCODE_WRITE_REG,
+                                          Result);
         }
     }
 }
@@ -3218,13 +3132,13 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubAl)
     {
         /* This opcode doesn't take any prefixes */
         Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
+        return;
     }
 
     if (!Fast486FetchByte(State, &SecondValue))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Calculate the result */
@@ -3245,8 +3159,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubAl)
         /* Write back the result */
         State->GeneralRegs[FAST486_REG_EAX].LowByte = Result;
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubEax)
@@ -3267,7 +3179,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubEax)
         if (!Fast486FetchDword(State, &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -3297,7 +3209,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubEax)
         if (!Fast486FetchWord(State, &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Calculate the result */
@@ -3319,8 +3231,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubEax)
             State->GeneralRegs[FAST486_REG_EAX].LowWord = Result;
         }
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeDas)
@@ -3356,7 +3266,12 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeDas)
         State->Flags.Cf = TRUE;
     }
 
-    return TRUE;
+    Value = State->GeneralRegs[FAST486_REG_EAX].LowByte;
+
+    /* Update the flags */
+    State->Flags.Sf = (Value & SIGN_FLAG_BYTE) != 0;
+    State->Flags.Zf = (Value == 0);
+    State->Flags.Pf = Fast486CalculateParity(Value);
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeAaa)
@@ -3370,7 +3285,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAaa)
     if (((Value & 0x0F) > 9) || State->Flags.Af)
     {
         /* Correct it */
-        State->GeneralRegs[FAST486_REG_EAX].LowByte += 0x06;
+        State->GeneralRegs[FAST486_REG_EAX].LowWord += 0x06;
         State->GeneralRegs[FAST486_REG_EAX].HighByte++;
 
         /* Set CF and AF */
@@ -3384,8 +3299,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAaa)
 
     /* Keep only the lowest 4 bits of AL */
     State->GeneralRegs[FAST486_REG_EAX].LowByte &= 0x0F;
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeAas)
@@ -3399,7 +3312,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAas)
     if (((Value & 0x0F) > 9) || State->Flags.Af)
     {
         /* Correct it */
-        State->GeneralRegs[FAST486_REG_EAX].LowByte -= 0x06;
+        State->GeneralRegs[FAST486_REG_EAX].LowWord -= 0x06;
         State->GeneralRegs[FAST486_REG_EAX].HighByte--;
 
         /* Set CF and AF */
@@ -3413,8 +3326,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAas)
 
     /* Keep only the lowest 4 bits of AL */
     State->GeneralRegs[FAST486_REG_EAX].LowByte &= 0x0F;
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodePushAll)
@@ -3438,7 +3349,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePushAll)
             if (!Fast486StackPush(State, Size ? SavedEsp.Long : SavedEsp.LowWord))
             {
                 /* Exception occurred */
-                return FALSE;
+                return;
             }
         }
         else
@@ -3448,12 +3359,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePushAll)
                                               : State->GeneralRegs[i].LowWord))
             {
                 /* Exception occurred */
-                return FALSE;
+                return;
             }
         }
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodePopAll)
@@ -3475,7 +3384,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePopAll)
         if (!Fast486StackPop(State, &Value))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Don't modify ESP */
@@ -3485,16 +3394,102 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePopAll)
             else State->GeneralRegs[i].LowWord = LOWORD(Value);
         }
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeBound)
 {
-    // TODO: NOT IMPLEMENTED
-    UNIMPLEMENTED;
+    BOOLEAN OperandSize, AddressSize;
+    FAST486_MOD_REG_RM ModRegRm;
+    FAST486_SEG_REGS Segment = FAST486_REG_DS;
+
+    OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
+
+    NO_LOCK_PREFIX();
+    TOGGLE_OPSIZE(OperandSize);
+    TOGGLE_ADSIZE(AddressSize);
+
+    if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
+    {
+        /* Exception occurred */
+        return;
+    }
+
+    if (!ModRegRm.Memory)
+    {
+        /* Invalid */
+        Fast486Exception(State, FAST486_EXCEPTION_UD);
+        return;
+    }
+
+    /* Check for the segment override */
+    if (State->PrefixFlags & FAST486_PREFIX_SEG)
+    {
+        /* Use the override segment instead */
+        Segment = State->SegmentOverride;
+    }
+
+    if (OperandSize)
+    {
+        LONG Index, LowerBound, UpperBound;
+
+        /* Read the operands */
+        if (!Fast486ReadModrmDwordOperands(State,
+                                           &ModRegRm,
+                                           (PULONG)&Index,
+                                           (PULONG)&LowerBound))
+        {
+            /* Exception occurred */
+            return;
+        }
+
+        if (!Fast486ReadMemory(State,
+                               Segment,
+                               ModRegRm.MemoryAddress + sizeof(ULONG),
+                               FALSE,
+                               &UpperBound,
+                               sizeof(ULONG)))
+        {
+            /* Exception occurred */
+            return;
+        }
+
+        if ((Index < LowerBound) || (Index > UpperBound))
+        {
+            /* Out of bounds */
+            Fast486Exception(State, FAST486_EXCEPTION_BR);
+        }
+    }
+    else
+    {
+        SHORT Index, LowerBound, UpperBound;
+
+        /* Read the operands */
+        if (!Fast486ReadModrmWordOperands(State,
+                                          &ModRegRm,
+                                          (PUSHORT)&Index,
+                                          (PUSHORT)&LowerBound))
+        {
+            /* Exception occurred */
+            return;
+        }
+
+        if (!Fast486ReadMemory(State,
+                               Segment,
+                               ModRegRm.MemoryAddress + sizeof(USHORT),
+                               FALSE,
+                               &UpperBound,
+                               sizeof(USHORT)))
+        {
+            /* Exception occurred */
+            return;
+        }
 
-    return FALSE;
+        if ((Index < LowerBound) || (Index > UpperBound))
+        {
+            /* Out of bounds */
+            Fast486Exception(State, FAST486_EXCEPTION_BR);
+        }
+    }
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeArpl)
@@ -3509,7 +3504,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeArpl)
     {
         /* Cannot be used in real mode or with a LOCK prefix */
         Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
+        return;
     }
 
     TOGGLE_ADSIZE(AddressSize);
@@ -3518,7 +3513,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeArpl)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Read the operands */
@@ -3528,7 +3523,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeArpl)
                                       &SecondValue))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Check if the RPL needs adjusting */
@@ -3542,13 +3537,12 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeArpl)
         State->Flags.Zf = TRUE;
 
         /* Write back the result */
-        return Fast486WriteModrmWordOperands(State, &ModRegRm, FALSE, SecondValue);
+        Fast486WriteModrmWordOperands(State, &ModRegRm, FALSE, SecondValue);
     }
     else
     {
         /* Clear ZF */
         State->Flags.Zf = FALSE;
-        return TRUE;
     }
 }
 
@@ -3569,24 +3563,24 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePushImm)
         if (!Fast486FetchDword(State, &Data))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Call the internal API */
-        return Fast486StackPush(State, Data);
+        Fast486StackPush(State, Data);
     }
     else
     {
-        USHORT Data;
+        SHORT Data;
 
-        if (!Fast486FetchWord(State, &Data))
+        if (!Fast486FetchWord(State, (PUSHORT)&Data))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Call the internal API */
-        return Fast486StackPush(State, Data);
+        Fast486StackPush(State, Data);
     }
 }
 
@@ -3595,7 +3589,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeImulModrmImm)
     BOOLEAN OperandSize, AddressSize;
     FAST486_MOD_REG_RM ModRegRm;
     LONG Multiplier;
-    LONGLONG Product;
 
     /* Make sure this is the right instruction */
     ASSERT((Opcode & 0xFD) == 0x69);
@@ -3609,7 +3602,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeImulModrmImm)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     if (Opcode == 0x6B)
@@ -3620,7 +3613,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeImulModrmImm)
         if (!Fast486FetchByte(State, (PUCHAR)&Byte))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         Multiplier = (LONG)Byte;
@@ -3635,7 +3628,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeImulModrmImm)
             if (!Fast486FetchDword(State, (PULONG)&Dword))
             {
                 /* Exception occurred */
-                return FALSE;
+                return;
             }
 
             Multiplier = Dword;
@@ -3648,7 +3641,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeImulModrmImm)
             if (!Fast486FetchWord(State, (PUSHORT)&Word))
             {
                 /* Exception occurred */
-                return FALSE;
+                return;
             }
 
             Multiplier = (LONG)Word;
@@ -3658,6 +3651,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeImulModrmImm)
     if (OperandSize)
     {
         LONG RegValue, Multiplicand;
+        LONGLONG Product;
 
         /* Read the operands */
         if (!Fast486ReadModrmDwordOperands(State,
@@ -3666,15 +3660,25 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeImulModrmImm)
                                            (PULONG)&Multiplicand))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Multiply */
         Product = (LONGLONG)Multiplicand * (LONGLONG)Multiplier;
+
+        /* Check for carry/overflow */
+        State->Flags.Cf = State->Flags.Of = ((Product < MINLONG) || (Product > MAXLONG));
+
+        /* Write-back the result */
+        Fast486WriteModrmDwordOperands(State,
+                                       &ModRegRm,
+                                       TRUE,
+                                       (ULONG)((LONG)Product));
     }
     else
     {
         SHORT RegValue, Multiplicand;
+        LONG Product;
 
         /* Read the operands */
         if (!Fast486ReadModrmWordOperands(State,
@@ -3683,38 +3687,38 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeImulModrmImm)
                                           (PUSHORT)&Multiplicand))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Multiply */
-        Product = (LONGLONG)Multiplicand * (LONGLONG)Multiplier;
-    }
+        Product = (LONG)Multiplicand * (LONG)Multiplier;
 
-    /* Check for carry/overflow */
-    State->Flags.Cf = State->Flags.Of = ((Product < MINLONG) || (Product > MAXLONG));
+        /* Check for carry/overflow */
+        State->Flags.Cf = State->Flags.Of = ((Product < MINSHORT) || (Product > MAXSHORT));
 
-    /* Write-back the result */
-    return Fast486WriteModrmDwordOperands(State,
-                                          &ModRegRm,
-                                          TRUE,
-                                          (ULONG)((LONG)Product));
+        /* Write-back the result */
+        Fast486WriteModrmWordOperands(State,
+                                      &ModRegRm,
+                                      TRUE,
+                                      (USHORT)((SHORT)Product));
+    }
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodePushByteImm)
 {
-    UCHAR Data;
+    CHAR Data;
 
     /* Make sure this is the right instruction */
     ASSERT(Opcode == 0x6A);
 
-    if (!Fast486FetchByte(State, &Data))
+    if (!Fast486FetchByte(State, (PUCHAR)&Data))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Call the internal API */
-    return Fast486StackPush(State, Data);
+    Fast486StackPush(State, Data);
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeMovByteModrm)
@@ -3732,7 +3736,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovByteModrm)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     if (!Fast486ReadModrmByteOperands(State,
@@ -3741,17 +3745,17 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovByteModrm)
                                       &SecondValue))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     if (Opcode & FAST486_OPCODE_WRITE_REG) Result = SecondValue;
     else Result = FirstValue;
 
     /* Write back the result */
-    return Fast486WriteModrmByteOperands(State,
-                                         &ModRegRm,
-                                         Opcode & FAST486_OPCODE_WRITE_REG,
-                                         Result);
+    Fast486WriteModrmByteOperands(State,
+                                  &ModRegRm,
+                                  Opcode & FAST486_OPCODE_WRITE_REG,
+                                  Result);
 
 }
 
@@ -3772,7 +3776,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovModrm)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Check the operand size */
@@ -3786,17 +3790,17 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovModrm)
                                           &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         if (Opcode & FAST486_OPCODE_WRITE_REG) Result = SecondValue;
         else Result = FirstValue;
 
         /* Write back the result */
-        return Fast486WriteModrmDwordOperands(State,
-                                              &ModRegRm,
-                                              Opcode & FAST486_OPCODE_WRITE_REG,
-                                              Result);
+        Fast486WriteModrmDwordOperands(State,
+                                       &ModRegRm,
+                                       Opcode & FAST486_OPCODE_WRITE_REG,
+                                       Result);
     }
     else
     {
@@ -3808,17 +3812,17 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovModrm)
                                           &SecondValue))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         if (Opcode & FAST486_OPCODE_WRITE_REG) Result = SecondValue;
         else Result = FirstValue;
 
         /* Write back the result */
-        return Fast486WriteModrmWordOperands(State,
-                                             &ModRegRm,
-                                             Opcode & FAST486_OPCODE_WRITE_REG,
-                                             Result);
+        Fast486WriteModrmWordOperands(State,
+                                      &ModRegRm,
+                                      Opcode & FAST486_OPCODE_WRITE_REG,
+                                      Result);
     }
 }
 
@@ -3839,29 +3843,29 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovStoreSeg)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     if (ModRegRm.Register >= FAST486_NUM_SEG_REGS)
     {
         /* Invalid */
         Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
+        return;
     }
 
     if (OperandSize)
     {
-        return Fast486WriteModrmDwordOperands(State,
-                                              &ModRegRm,
-                                              FALSE,
-                                              State->SegmentRegs[ModRegRm.Register].Selector);
+        Fast486WriteModrmDwordOperands(State,
+                                       &ModRegRm,
+                                       FALSE,
+                                       State->SegmentRegs[ModRegRm.Register].Selector);
     }
     else
     {
-        return Fast486WriteModrmWordOperands(State,
-                                             &ModRegRm,
-                                             FALSE,
-                                             State->SegmentRegs[ModRegRm.Register].Selector);
+        Fast486WriteModrmWordOperands(State,
+                                      &ModRegRm,
+                                      FALSE,
+                                      State->SegmentRegs[ModRegRm.Register].Selector);
     }
 }
 
@@ -3882,7 +3886,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLea)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* The second operand must be memory */
@@ -3890,23 +3894,23 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLea)
     {
         /* Invalid */
         Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
+        return;
     }
 
     /* Write the address to the register */
     if (OperandSize)
     {
-        return Fast486WriteModrmDwordOperands(State,
-                                              &ModRegRm,
-                                              TRUE,
-                                              ModRegRm.MemoryAddress);
+        Fast486WriteModrmDwordOperands(State,
+                                       &ModRegRm,
+                                       TRUE,
+                                       ModRegRm.MemoryAddress);
     }
     else
     {
-        return Fast486WriteModrmWordOperands(State,
-                                             &ModRegRm,
-                                             TRUE,
-                                             ModRegRm.MemoryAddress);
+        Fast486WriteModrmWordOperands(State,
+                                      &ModRegRm,
+                                      TRUE,
+                                      ModRegRm.MemoryAddress);
 
     }
 }
@@ -3928,7 +3932,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovLoadSeg)
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     if ((ModRegRm.Register >= FAST486_NUM_SEG_REGS)
@@ -3936,32 +3940,32 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovLoadSeg)
     {
         /* Invalid */
         Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
+        return;
     }
 
     if (OperandSize)
     {
-        ULONG Dummy, Selector;
+        ULONG Selector;
 
-        if (!Fast486ReadModrmDwordOperands(State, &ModRegRm, &Dummy, &Selector))
+        if (!Fast486ReadModrmDwordOperands(State, &ModRegRm, NULL, &Selector))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
-        return Fast486LoadSegment(State, ModRegRm.Register, LOWORD(Selector));
+        Fast486LoadSegment(State, ModRegRm.Register, LOWORD(Selector));
     }
     else
     {
-        USHORT Dummy, Selector;
+        USHORT Selector;
 
-        if (!Fast486ReadModrmWordOperands(State, &ModRegRm, &Dummy, &Selector))
+        if (!Fast486ReadModrmWordOperands(State, &ModRegRm, NULL, &Selector))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
-        return Fast486LoadSegment(State, ModRegRm.Register, Selector);
+        Fast486LoadSegment(State, ModRegRm.Register, Selector);
     }
 }
 
@@ -3992,8 +3996,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCwde)
         (State->GeneralRegs[FAST486_REG_EAX].LowByte & SIGN_FLAG_BYTE)
         ? 0xFF : 0x00;
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeCdq)
@@ -4020,8 +4022,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCdq)
         (State->GeneralRegs[FAST486_REG_EAX].LowWord & SIGN_FLAG_WORD)
         ? 0xFFFF : 0x0000;
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeCallAbs)
@@ -4042,7 +4042,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCallAbs)
         if (!Fast486FetchDword(State, &Offset))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
     }
     else
@@ -4050,7 +4050,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCallAbs)
         if (!Fast486FetchWord(State, (PUSHORT)&Offset))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
     }
 
@@ -4058,43 +4058,39 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCallAbs)
     if (!Fast486FetchWord(State, &Segment))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Push the current code segment selector */
     if (!Fast486StackPush(State, State->SegmentRegs[FAST486_REG_CS].Selector))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Push the current value of the instruction pointer */
     if (!Fast486StackPush(State, State->InstPtr.Long))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Load the new CS */
     if (!Fast486LoadSegment(State, FAST486_REG_CS, Segment))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Load new (E)IP */
     if (Size) State->InstPtr.Long = Offset;
     else State->InstPtr.LowWord = LOWORD(Offset);
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeWait)
 {
     // TODO: NOT IMPLEMENTED
     UNIMPLEMENTED;
-
-    return FALSE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodePushFlags)
@@ -4109,152 +4105,66 @@ FAST486_OPCODE_HANDLER(Fast486OpcodePushFlags)
     {
         /* Call the VM86 monitor */
         Fast486ExceptionWithErrorCode(State, FAST486_EXCEPTION_GP, 0);
-        return FALSE;
+        return;
     }
 
     /* Push the flags */
-    if (Size) return Fast486StackPush(State, State->Flags.Long);
-    else return Fast486StackPush(State, LOWORD(State->Flags.Long));
+    if (Size) Fast486StackPush(State, State->Flags.Long);
+    else Fast486StackPush(State, LOWORD(State->Flags.Long));
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodePopFlags)
 {
     BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
     INT Cpl = Fast486GetCurrentPrivLevel(State);
-    ULONG NewFlags;
+    FAST486_FLAGS_REG NewFlags;
 
     NO_LOCK_PREFIX();
     TOGGLE_OPSIZE(Size);
 
     /* Pop the new flags */
-    if (!Fast486StackPop(State, &NewFlags))
+    if (!Fast486StackPop(State, &NewFlags.Long))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
-    if (!State->Flags.Vm)
+    /* Check for VM86 mode when IOPL is not 3 */
+    if (State->Flags.Vm && (State->Flags.Iopl != 3))
     {
-        /* Check the current privilege level */
-        if (Cpl == 0)
-        {
-            /* Supervisor */
-
-            /* Set the flags */
-            if (Size)
-            {
-                /* Memorize the old state of RF */
-                BOOLEAN OldRf = State->Flags.Rf;
+        /* Call the VM86 monitor */
+        Fast486ExceptionWithErrorCode(State, FAST486_EXCEPTION_GP, 0);
+        return;
+    }
+
+    State->Flags.Cf = NewFlags.Cf;
+    State->Flags.Pf = NewFlags.Pf;
+    State->Flags.Af = NewFlags.Af;
+    State->Flags.Zf = NewFlags.Zf;
+    State->Flags.Sf = NewFlags.Sf;
+    State->Flags.Tf = NewFlags.Tf;
+    State->Flags.Df = NewFlags.Df;
+    State->Flags.Of = NewFlags.Of;
+    State->Flags.Nt = NewFlags.Nt;
+    State->Flags.Ac = NewFlags.Ac;
+
+    if (Cpl == 0) State->Flags.Iopl = NewFlags.Iopl;
+    if (Cpl <= State->Flags.Iopl) State->Flags.If = NewFlags.If;
+}
 
-                State->Flags.Long = NewFlags;
+FAST486_OPCODE_HANDLER(Fast486OpcodeSahf)
+{
+    /* Make sure this is the right instruction */
+    ASSERT(Opcode == 0x9E);
 
-                /* Restore VM and RF */
-                State->Flags.Vm = FALSE;
-                State->Flags.Rf = OldRf;
+    /* Set the low-order byte of FLAGS to AH */
+    State->Flags.Long &= 0xFFFFFF00;
+    State->Flags.Long |= State->GeneralRegs[FAST486_REG_EAX].HighByte;
 
-                /* Clear VIF and VIP */
-                State->Flags.Vif = State->Flags.Vip = FALSE;
-            }
-            else State->Flags.LowWord = LOWORD(NewFlags);
-
-            /* Restore the reserved bits */
-            State->Flags.AlwaysSet = TRUE;
-            State->Flags.Reserved0 = FALSE;
-            State->Flags.Reserved1 = FALSE;
-        }
-        else
-        {
-            /* User */
-
-            /* Memorize the old state of IF and IOPL */
-            BOOLEAN OldIf = State->Flags.If;
-            UINT OldIopl = State->Flags.Iopl;
-
-            /* Set the flags */
-            if (Size)
-            {
-                /* Memorize the old state of RF */
-                BOOLEAN OldRf = State->Flags.Rf;
-
-                State->Flags.Long = NewFlags;
-
-                /* Restore VM and RF */
-                State->Flags.Vm = FALSE;
-                State->Flags.Rf = OldRf;
-
-                /* Clear VIF and VIP */
-                State->Flags.Vif = State->Flags.Vip = FALSE;
-            }
-            else State->Flags.LowWord = LOWORD(NewFlags);
-
-            /* Restore the reserved bits and IOPL */
-            State->Flags.AlwaysSet = TRUE;
-            State->Flags.Reserved0 = FALSE;
-            State->Flags.Reserved1 = FALSE;
-            State->Flags.Iopl = OldIopl;
-
-            /* Check if the user doesn't have the privilege to change IF */
-            if (Cpl > State->Flags.Iopl)
-            {
-                /* Restore IF */
-                State->Flags.If = OldIf;
-            }
-        }
-    }
-    else
-    {
-        /* Check the IOPL */
-        if (State->Flags.Iopl == 3)
-        {
-            if (Size)
-            {
-                /* Memorize the old state of RF, VIF and VIP */
-                BOOLEAN OldRf = State->Flags.Rf;
-                BOOLEAN OldVif = State->Flags.Vif;
-                BOOLEAN OldVip = State->Flags.Vip;
-
-                State->Flags.Long = NewFlags;
-
-                /* Restore VM, RF, VIF and VIP */
-                State->Flags.Vm = TRUE;
-                State->Flags.Rf = OldRf;
-                State->Flags.Vif = OldVif;
-                State->Flags.Vip = OldVip;
-            }
-            else State->Flags.LowWord = LOWORD(NewFlags);
-
-            /* Restore the reserved bits and IOPL */
-            State->Flags.AlwaysSet = TRUE;
-            State->Flags.Reserved0 = FALSE;
-            State->Flags.Reserved1 = FALSE;
-            State->Flags.Iopl = 3;
-        }
-        else
-        {
-            /* Call the VM86 monitor */
-            Fast486ExceptionWithErrorCode(State, FAST486_EXCEPTION_GP, 0);
-        }
-
-    }
-
-    return TRUE;
-}
-
-FAST486_OPCODE_HANDLER(Fast486OpcodeSahf)
-{
-    /* Make sure this is the right instruction */
-    ASSERT(Opcode == 0x9E);
-
-    /* Set the low-order byte of FLAGS to AH */
-    State->Flags.Long &= 0xFFFFFF00;
-    State->Flags.Long |= State->GeneralRegs[FAST486_REG_EAX].HighByte;
-
-    /* Restore the reserved bits of FLAGS */
-    State->Flags.AlwaysSet = TRUE;
-    State->Flags.Reserved0 = State->Flags.Reserved1 = FALSE;
-
-    return FALSE;
-}
+    /* Restore the reserved bits of FLAGS */
+    State->Flags.AlwaysSet = TRUE;
+    State->Flags.Reserved0 = State->Flags.Reserved1 = FALSE;
+}
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeLahf)
 {
@@ -4263,8 +4173,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLahf)
 
     /* Set AH to the low-order byte of FLAGS */
     State->GeneralRegs[FAST486_REG_EAX].HighByte = LOBYTE(State->Flags.Long);
-
-    return FALSE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeRet)
@@ -4282,11 +4190,11 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeRet)
     if (Opcode == 0xC2)
     {
         /* Fetch the number of bytes to pop after the return */
-        if (!Fast486FetchWord(State, &BytesToPop)) return FALSE;
+        if (!Fast486FetchWord(State, &BytesToPop)) return;
     }
 
     /* Pop the return address */
-    if (!Fast486StackPop(State, &ReturnAddress)) return FALSE;
+    if (!Fast486StackPop(State, &ReturnAddress)) return;
 
     /* Return to the calling procedure, and if necessary, pop the parameters */
     if (Size)
@@ -4299,8 +4207,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeRet)
         State->InstPtr.LowWord = LOWORD(ReturnAddress);
         State->GeneralRegs[FAST486_REG_ESP].LowWord += BytesToPop;
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeLdsLes)
@@ -4314,13 +4220,14 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLdsLes)
 
     OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
 
+    TOGGLE_OPSIZE(OperandSize);
     TOGGLE_ADSIZE(AddressSize);
 
     /* Get the operands */
     if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     if (!ModRegRm.Memory)
@@ -4337,19 +4244,29 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLdsLes)
             if (!Fast486FetchByte(State, &BopCode))
             {
                 /* Exception occurred */
-                return FALSE;
+                return;
             }
 
             /* Call the BOP handler */
             State->BopCallback(State, BopCode);
 
-            /* Return success */
-            return TRUE;
+            /*
+             * If an interrupt should occur at this time, delay it.
+             * We must do this because if an interrupt begins and the BOP callback
+             * changes the CS:IP, the interrupt handler won't execute and the
+             * stack pointer will never be restored.
+             */
+            if (State->IntStatus == FAST486_INT_EXECUTE)
+            {
+                State->IntStatus = FAST486_INT_DELAYED;
+            }
+
+            return;
         }
 
         /* Invalid */
         Fast486Exception(State, FAST486_EXCEPTION_UD);
-        return FALSE;
+        return;
     }
 
     if (!Fast486ReadMemory(State,
@@ -4361,7 +4278,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLdsLes)
                            OperandSize ? 6 : 4))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     if (OperandSize)
@@ -4373,10 +4290,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLdsLes)
         State->GeneralRegs[ModRegRm.Register].Long = Offset;
 
         /* Load the segment */
-        return Fast486LoadSegment(State,
-                                  (Opcode == 0xC4)
-                                  ? FAST486_REG_ES : FAST486_REG_DS,
-                                  Segment);
+        Fast486LoadSegment(State,
+                           (Opcode == 0xC4)
+                           ? FAST486_REG_ES : FAST486_REG_DS,
+                           Segment);
     }
     else
     {
@@ -4387,10 +4304,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLdsLes)
         State->GeneralRegs[ModRegRm.Register].LowWord = Offset;
 
         /* Load the segment */
-        return Fast486LoadSegment(State,
-                                  (Opcode == 0xC4)
-                                  ? FAST486_REG_ES : FAST486_REG_DS,
-                                  Segment);
+        Fast486LoadSegment(State,
+                           (Opcode == 0xC4)
+                           ? FAST486_REG_ES : FAST486_REG_DS,
+                           Segment);
     }
 }
 
@@ -4411,20 +4328,20 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeEnter)
     if (!Fast486FetchWord(State, &FrameSize))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     if (!Fast486FetchByte(State, &NestingLevel))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Push EBP */
     if (!Fast486StackPush(State, State->GeneralRegs[FAST486_REG_EBP].Long))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Save ESP */
@@ -4453,8 +4370,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeEnter)
     /* Reserve space for the frame */
     if (Size) State->GeneralRegs[FAST486_REG_ESP].Long -= (ULONG)FrameSize;
     else State->GeneralRegs[FAST486_REG_ESP].LowWord -= FrameSize;
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeLeave)
@@ -4473,7 +4388,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLeave)
         State->GeneralRegs[FAST486_REG_ESP].Long = State->GeneralRegs[FAST486_REG_EBP].Long;
 
         /* Pop the saved base pointer from the stack */
-        return Fast486StackPop(State, &State->GeneralRegs[FAST486_REG_EBP].Long);
+        Fast486StackPop(State, &State->GeneralRegs[FAST486_REG_EBP].Long);
     }
     else
     {
@@ -4486,9 +4401,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLeave)
         if (Fast486StackPop(State, &Value))
         {
             State->GeneralRegs[FAST486_REG_EBP].LowWord = LOWORD(Value);
-            return TRUE;
         }
-        else return FALSE;
     }
 }
 
@@ -4508,28 +4421,28 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeRetFar)
     if (Opcode == 0xCA)
     {
         /* Fetch the number of bytes to pop after the return */
-        if (!Fast486FetchWord(State, &BytesToPop)) return FALSE;
+        if (!Fast486FetchWord(State, &BytesToPop)) return;
     }
 
     /* Pop the offset */
     if (!Fast486StackPop(State, &Offset))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Pop the segment */
     if (!Fast486StackPop(State, &Segment))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Load the new CS */
     if (!Fast486LoadSegment(State, FAST486_REG_CS, Segment))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Load new (E)IP, and if necessary, pop the parameters */
@@ -4543,40 +4456,37 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeRetFar)
         State->InstPtr.LowWord = LOWORD(Offset);
         State->GeneralRegs[FAST486_REG_ESP].LowWord += BytesToPop;
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeInt)
 {
     UCHAR IntNum;
-    FAST486_IDT_ENTRY IdtEntry;
 
     switch (Opcode)
     {
-        case 0xCC:
+        case 0xCC:  // INT 3
         {
             /* This is the INT3 instruction */
             IntNum = 3;
             break;
         }
 
-        case 0xCD:
+        case 0xCD:  // INT xx
         {
             /* Fetch the interrupt number */
             if (!Fast486FetchByte(State, &IntNum))
             {
                 /* Exception occurred */
-                return FALSE;
+                return;
             }
 
             break;
         }
 
-        case 0xCE:
+        case 0xCE:  // INTO
         {
             /* Don't do anything if OF is cleared */
-            if (!State->Flags.Of) return TRUE;
+            if (!State->Flags.Of) return;
 
             /* Exception #OF */
             IntNum = FAST486_EXCEPTION_OF;
@@ -4591,24 +4501,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeInt)
         }
     }
 
-    /* Get the interrupt vector */
-    if (!Fast486GetIntVector(State, IntNum, &IdtEntry))
-    {
-        /* Exception occurred */
-        return FALSE;
-    }
-
     /* Perform the interrupt */
-    if (!Fast486InterruptInternal(State,
-                                  IdtEntry.Selector,
-                                  MAKELONG(IdtEntry.Offset, IdtEntry.OffsetHigh),
-                                  IdtEntry.Type))
-    {
-        /* Exception occurred */
-        return FALSE;
-    }
-
-    return TRUE;
+    Fast486PerformInterrupt(State, IntNum);
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeIret)
@@ -4628,21 +4522,21 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIret)
     if (!Fast486StackPop(State, &InstPtr))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Pop CS */
     if (!Fast486StackPop(State, &CodeSel))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Pop EFLAGS */
     if (!Fast486StackPop(State, &NewFlags.Long))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Check for protected mode */
@@ -4664,7 +4558,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIret)
                 if (!Fast486LoadSegment(State, FAST486_REG_CS, CodeSel))
                 {
                     /* Exception occurred */
-                    return FALSE;
+                    return;
                 }
 
                 /* Set the new flags */
@@ -4677,10 +4571,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIret)
             {
                 /* Call the VM86 monitor */
                 Fast486ExceptionWithErrorCode(State, FAST486_EXCEPTION_GP, 0);
-                return FALSE;
+                return;
             }
 
-            return TRUE;
+            return;
         }
 
         if (State->Flags.Nt)
@@ -4688,7 +4582,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIret)
             /* Nested task return */
 
             UNIMPLEMENTED;
-            return FALSE;
+            return;
         }
 
         if (NewFlags.Vm)
@@ -4697,12 +4591,12 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIret)
             ULONG Es, Ds, Fs, Gs;
 
             /* Pop ESP, SS, ES, FS, GS */
-            if (!Fast486StackPop(State, &StackPtr)) return FALSE;
-            if (!Fast486StackPop(State, &StackSel)) return FALSE;
-            if (!Fast486StackPop(State, &Es)) return FALSE;
-            if (!Fast486StackPop(State, &Ds)) return FALSE;
-            if (!Fast486StackPop(State, &Fs)) return FALSE;
-            if (!Fast486StackPop(State, &Gs)) return FALSE;
+            if (!Fast486StackPop(State, &StackPtr)) return;
+            if (!Fast486StackPop(State, &StackSel)) return;
+            if (!Fast486StackPop(State, &Es)) return;
+            if (!Fast486StackPop(State, &Ds)) return;
+            if (!Fast486StackPop(State, &Fs)) return;
+            if (!Fast486StackPop(State, &Gs)) return;
 
             /* Set the new IP */
             State->InstPtr.Long = LOWORD(InstPtr);
@@ -4713,21 +4607,21 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIret)
             State->Flags.AlwaysSet = State->Flags.Vm = TRUE;
 
             /* Load the new segments */
-            if (!Fast486LoadSegment(State, FAST486_REG_CS, CodeSel)) return FALSE;
-            if (!Fast486LoadSegment(State, FAST486_REG_SS, StackSel)) return FALSE;
-            if (!Fast486LoadSegment(State, FAST486_REG_ES, Es)) return FALSE;
-            if (!Fast486LoadSegment(State, FAST486_REG_DS, Ds)) return FALSE;
-            if (!Fast486LoadSegment(State, FAST486_REG_FS, Fs)) return FALSE;
-            if (!Fast486LoadSegment(State, FAST486_REG_GS, Gs)) return FALSE;
+            if (!Fast486LoadSegment(State, FAST486_REG_CS, CodeSel)) return;
+            if (!Fast486LoadSegment(State, FAST486_REG_SS, StackSel)) return;
+            if (!Fast486LoadSegment(State, FAST486_REG_ES, Es)) return;
+            if (!Fast486LoadSegment(State, FAST486_REG_DS, Ds)) return;
+            if (!Fast486LoadSegment(State, FAST486_REG_FS, Fs)) return;
+            if (!Fast486LoadSegment(State, FAST486_REG_GS, Gs)) return;
 
-            return TRUE;
+            return;
         }
 
         /* Load the new CS */
         if (!Fast486LoadSegment(State, FAST486_REG_CS, CodeSel))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Set EIP */
@@ -4740,21 +4634,21 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIret)
             if (!Fast486StackPop(State, &StackPtr))
             {
                 /* Exception */
-                return FALSE;
+                return;
             }
 
             /* Pop SS */
             if (!Fast486StackPop(State, &StackSel))
             {
                 /* Exception */
-                return FALSE;
+                return;
             }
 
             /* Load new SS */
             if (!Fast486LoadSegment(State, FAST486_REG_SS, StackSel))
             {
                 /* Exception */
-                return FALSE;
+                return;
             }
 
             /* Set ESP */
@@ -4787,7 +4681,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIret)
                     || !State->SegmentRegs[i].DirConf))
                 {
                     /* Load the NULL descriptor in the segment */
-                    if (!Fast486LoadSegment(State, i, 0)) return FALSE;
+                    if (!Fast486LoadSegment(State, i, 0)) return;
                 }
             }
         }
@@ -4798,7 +4692,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIret)
         {
             /* Invalid */
             Fast486ExceptionWithErrorCode(State, FAST486_EXCEPTION_GP, 0);
-            return FALSE;
+            return;
         }
 
         /* Set new EIP */
@@ -4808,7 +4702,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIret)
         if (!Fast486LoadSegment(State, FAST486_REG_CS, CodeSel))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Set the new flags */
@@ -4816,8 +4710,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIret)
         else State->Flags.LowWord = NewFlags.LowWord & REAL_MODE_FLAGS_MASK;
         State->Flags.AlwaysSet = TRUE;
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeAam)
@@ -4831,7 +4723,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAam)
     if (!Fast486FetchByte(State, &Base))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Check if the base is zero */
@@ -4839,7 +4731,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAam)
     {
         /* Divide error */
         Fast486Exception(State, FAST486_EXCEPTION_DE);
-        return FALSE;
+        return;
     }
 
     /* Adjust */
@@ -4847,11 +4739,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAam)
     State->GeneralRegs[FAST486_REG_EAX].LowByte = Value %= Base;
 
     /* Update flags */
+    State->Flags.Af = FALSE;
     State->Flags.Zf = (Value == 0);
     State->Flags.Sf = ((Value & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Value);
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeAad)
@@ -4865,19 +4756,18 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeAad)
     if (!Fast486FetchByte(State, &Base))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Adjust */
     Value += State->GeneralRegs[FAST486_REG_EAX].HighByte * Base;
-    State->GeneralRegs[FAST486_REG_EAX].LowByte = Value;
+    State->GeneralRegs[FAST486_REG_EAX].LowWord = Value;
 
     /* Update flags */
+    State->Flags.Af = FALSE;
     State->Flags.Zf = (Value == 0);
     State->Flags.Sf = ((Value & SIGN_FLAG_BYTE) != 0);
     State->Flags.Pf = Fast486CalculateParity(Value);
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeXlat)
@@ -4889,23 +4779,21 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeXlat)
 
     /* Read a byte from DS:[(E)BX + AL] */
     if (!Fast486ReadMemory(State,
-                           FAST486_REG_DS,
-                           AddressSize ? State->GeneralRegs[FAST486_REG_EBX].Long
-                                       : State->GeneralRegs[FAST486_REG_EBX].LowWord
+                           (State->PrefixFlags & FAST486_PREFIX_SEG)
+                           ? State->SegmentOverride : FAST486_REG_DS,
+                           (AddressSize ? State->GeneralRegs[FAST486_REG_EBX].Long
+                                        : State->GeneralRegs[FAST486_REG_EBX].LowWord)
                            + State->GeneralRegs[FAST486_REG_EAX].LowByte,
                            FALSE,
                            &Value,
                            sizeof(UCHAR)))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Set AL to the result */
     State->GeneralRegs[FAST486_REG_EAX].LowByte = Value;
-
-    /* Return success */
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeLoop)
@@ -4918,7 +4806,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLoop)
     ASSERT((Opcode >= 0xE0) && (Opcode <= 0xE2));
 
     NO_LOCK_PREFIX();
-    TOGGLE_OPSIZE(Size);
+    TOGGLE_ADSIZE(Size);
 
     if (Size) Condition = ((--State->GeneralRegs[FAST486_REG_ECX].Long) != 0);
     else Condition = ((--State->GeneralRegs[FAST486_REG_ECX].LowWord) != 0);
@@ -4928,8 +4816,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLoop)
         /* Additional rule for LOOPNZ */
         if (State->Flags.Zf) Condition = FALSE;
     }
-
-    if (Opcode == 0xE1)
+    else if (Opcode == 0xE1)
     {
         /* Additional rule for LOOPZ */
         if (!State->Flags.Zf) Condition = FALSE;
@@ -4939,16 +4826,15 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLoop)
     if (!Fast486FetchByte(State, (PUCHAR)&Offset))
     {
         /* An exception occurred */
-        return FALSE;
+        return;
     }
 
     if (Condition)
     {
         /* Move the instruction pointer */
-        State->InstPtr.Long += Offset;
+        if (Size) State->InstPtr.Long += Offset;
+        else State->InstPtr.LowWord += Offset;
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeJecxz)
@@ -4961,7 +4847,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeJecxz)
     ASSERT(Opcode == 0xE3);
 
     NO_LOCK_PREFIX();
-    TOGGLE_OPSIZE(Size);
+    TOGGLE_ADSIZE(Size);
 
     if (Size) Condition = (State->GeneralRegs[FAST486_REG_ECX].Long == 0);
     else Condition = (State->GeneralRegs[FAST486_REG_ECX].LowWord == 0);
@@ -4970,16 +4856,15 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeJecxz)
     if (!Fast486FetchByte(State, (PUCHAR)&Offset))
     {
         /* An exception occurred */
-        return FALSE;
+        return;
     }
 
     if (Condition)
     {
         /* Move the instruction pointer */
-        State->InstPtr.Long += Offset;
+        if (Size) State->InstPtr.Long += Offset;
+        else State->InstPtr.LowWord += Offset;
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeCall)
@@ -5000,14 +4885,14 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCall)
         if (!Fast486FetchDword(State, (PULONG)&Offset))
         {
             /* An exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Push the current value of the instruction pointer */
         if (!Fast486StackPush(State, State->InstPtr.Long))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Move the instruction pointer */
@@ -5021,21 +4906,19 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCall)
         if (!Fast486FetchWord(State, (PUSHORT)&Offset))
         {
             /* An exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Push the current value of the instruction pointer */
         if (!Fast486StackPush(State, State->InstPtr.Long))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Move the instruction pointer */
         State->InstPtr.LowWord += Offset;
     }
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeJmp)
@@ -5056,7 +4939,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeJmp)
         if (!Fast486FetchDword(State, (PULONG)&Offset))
         {
             /* An exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Move the instruction pointer */
@@ -5070,14 +4953,15 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeJmp)
         if (!Fast486FetchWord(State, (PUSHORT)&Offset))
         {
             /* An exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Move the instruction pointer */
-        State->InstPtr.LowWord += Offset;
-    }
+        State->InstPtr.Long += Offset;
 
-    return TRUE;
+        /* Clear the top half of EIP */
+        State->InstPtr.Long &= 0xFFFF;
+    }
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeJmpAbs)
@@ -5098,7 +4982,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeJmpAbs)
         if (!Fast486FetchDword(State, &Offset))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
     }
     else
@@ -5106,7 +4990,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeJmpAbs)
         if (!Fast486FetchWord(State, (PUSHORT)&Offset))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
     }
 
@@ -5114,39 +4998,36 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeJmpAbs)
     if (!Fast486FetchWord(State, &Segment))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Load the new CS */
     if (!Fast486LoadSegment(State, FAST486_REG_CS, Segment))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
-    /* Load new (E)IP */
-    if (Size) State->InstPtr.Long = Offset;
-    else State->InstPtr.LowWord = LOWORD(Offset);
-
-    return TRUE;
+    /* Load new EIP */
+    State->InstPtr.Long = Offset;
 }
 
 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))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
     }
     else
@@ -5156,49 +5037,65 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovAlOffset)
         if (!Fast486FetchWord(State, &WordOffset))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         Offset = (ULONG)WordOffset;
     }
 
     /* Read from memory */
-    return Fast486ReadMemory(State,
-                             (State->PrefixFlags & FAST486_PREFIX_SEG) ?
-                             State->SegmentOverride : FAST486_REG_DS,
-                             Offset,
-                             FALSE,
-                             &State->GeneralRegs[FAST486_REG_EAX].LowByte,
-                             sizeof(UCHAR));
+    Fast486ReadMemory(State,
+                      (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+                      State->SegmentOverride : FAST486_REG_DS,
+                      Offset,
+                      FALSE,
+                      &State->GeneralRegs[FAST486_REG_EAX].LowByte,
+                      sizeof(UCHAR));
 }
 
 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;
 
         if (!Fast486FetchDword(State, &Offset))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* 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)
+        {
+            Fast486ReadMemory(State,
+                              (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+                              State->SegmentOverride : FAST486_REG_DS,
+                              Offset,
+                              FALSE,
+                              &State->GeneralRegs[FAST486_REG_EAX].Long,
+                              sizeof(ULONG));
+        }
+        else
+        {
+            Fast486ReadMemory(State,
+                              (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+                              State->SegmentOverride : FAST486_REG_DS,
+                              Offset,
+                              FALSE,
+                              &State->GeneralRegs[FAST486_REG_EAX].LowWord,
+                              sizeof(USHORT));
+        }
     }
     else
     {
@@ -5207,17 +5104,30 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovEaxOffset)
         if (!Fast486FetchWord(State, &Offset))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* 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)
+        {
+            Fast486ReadMemory(State,
+                              (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+                              State->SegmentOverride : FAST486_REG_DS,
+                              Offset,
+                              FALSE,
+                              &State->GeneralRegs[FAST486_REG_EAX].Long,
+                              sizeof(ULONG));
+        }
+        else
+        {
+            Fast486ReadMemory(State,
+                              (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+                              State->SegmentOverride : FAST486_REG_DS,
+                              Offset,
+                              FALSE,
+                              &State->GeneralRegs[FAST486_REG_EAX].LowWord,
+                              sizeof(USHORT));
+        }
     }
 }
 
@@ -5236,7 +5146,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovOffsetAl)
         if (!Fast486FetchDword(State, &Offset))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
     }
     else
@@ -5246,19 +5156,19 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovOffsetAl)
         if (!Fast486FetchWord(State, &WordOffset))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         Offset = (ULONG)WordOffset;
     }
 
     /* Write to memory */
-    return Fast486WriteMemory(State,
-                             (State->PrefixFlags & FAST486_PREFIX_SEG) ?
-                             State->SegmentOverride : FAST486_REG_DS,
-                             Offset,
-                             &State->GeneralRegs[FAST486_REG_EAX].LowByte,
-                             sizeof(UCHAR));
+    Fast486WriteMemory(State,
+                      (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+                      State->SegmentOverride : FAST486_REG_DS,
+                      Offset,
+                      &State->GeneralRegs[FAST486_REG_EAX].LowByte,
+                      sizeof(UCHAR));
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeMovOffsetEax)
@@ -5280,27 +5190,27 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovOffsetEax)
         if (!Fast486FetchDword(State, &Offset))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Write to memory */
         if (OperandSize)
         {
-            return Fast486WriteMemory(State,
-                                      (State->PrefixFlags & FAST486_PREFIX_SEG) ?
-                                      State->SegmentOverride : FAST486_REG_DS,
-                                      Offset,
-                                      &State->GeneralRegs[FAST486_REG_EAX].Long,
-                                      sizeof(ULONG));
+            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));
+            Fast486WriteMemory(State,
+                               (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+                               State->SegmentOverride : FAST486_REG_DS,
+                               Offset,
+                               &State->GeneralRegs[FAST486_REG_EAX].LowWord,
+                               sizeof(USHORT));
         }
     }
     else
@@ -5310,33 +5220,38 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovOffsetEax)
         if (!Fast486FetchWord(State, &Offset))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Write to memory */
         if (OperandSize)
         {
-            return Fast486WriteMemory(State,
-                                      (State->PrefixFlags & FAST486_PREFIX_SEG) ?
-                                      State->SegmentOverride : FAST486_REG_DS,
-                                      Offset,
-                                      &State->GeneralRegs[FAST486_REG_EAX].Long,
-                                      sizeof(ULONG));
+            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));
+            Fast486WriteMemory(State,
+                               (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+                               State->SegmentOverride : FAST486_REG_DS,
+                               Offset,
+                               &State->GeneralRegs[FAST486_REG_EAX].LowWord,
+                               sizeof(USHORT));
         }
     }
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeSalc)
 {
+    /*
+     * See: http://www.rcollins.org/secrets/opcodes/SALC.html
+     * for more information.
+     */
+
     /* Make sure this is the right instruction */
     ASSERT(Opcode == 0xD6);
 
@@ -5344,8 +5259,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSalc)
 
     /* Set all the bits of AL to CF */
     State->GeneralRegs[FAST486_REG_EAX].LowByte = State->Flags.Cf ? 0xFF : 0x00;
-
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeMovs)
@@ -5368,168 +5281,93 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeMovs)
         Segment = State->SegmentOverride;
     }
 
+    if (State->PrefixFlags & (FAST486_PREFIX_REP | FAST486_PREFIX_REPNZ))
+    {
+        if ((AddressSize && (State->GeneralRegs[FAST486_REG_ECX].Long == 0))
+            || (!AddressSize && (State->GeneralRegs[FAST486_REG_ECX].LowWord == 0)))
+        {
+            /* Do nothing */
+            return;
+        }
+    }
+
     /* Calculate the size */
     if (Opcode == 0xA4) DataSize = sizeof(UCHAR);
     else DataSize = OperandSize ? sizeof(ULONG) : sizeof(USHORT);
 
-    if (State->PrefixFlags & FAST486_PREFIX_REP)
+    /* Read from the source operand */
+    if (!Fast486ReadMemory(State,
+                           Segment,
+                           AddressSize ? State->GeneralRegs[FAST486_REG_ESI].Long
+                                       : State->GeneralRegs[FAST486_REG_ESI].LowWord,
+                           FALSE,
+                           &Data,
+                           DataSize))
     {
-        UCHAR Block[STRING_BLOCK_SIZE];
-        ULONG Count = OperandSize ? State->GeneralRegs[FAST486_REG_ECX].Long
-                                  : State->GeneralRegs[FAST486_REG_ECX].LowWord;
+        /* Exception occurred */
+        return;
+    }
 
-        /* Clear the memory block */
-        RtlZeroMemory(Block, sizeof(Block));
+    /* Write to the destination operand */
+    if (!Fast486WriteMemory(State,
+                            FAST486_REG_ES,
+                            AddressSize ? State->GeneralRegs[FAST486_REG_EDI].Long
+                                        : State->GeneralRegs[FAST486_REG_EDI].LowWord,
+                            &Data,
+                            DataSize))
+    {
+        /* Exception occurred */
+        return;
+    }
 
-        /* Transfer until finished */
-        while (Count)
+    /* Increment/decrement ESI and EDI */
+    if (AddressSize)
+    {
+        if (!State->Flags.Df)
         {
-            ULONG Processed = min(Count, STRING_BLOCK_SIZE / DataSize);
-
-            /* Simulate the 16-bit wrap-around of SI and DI in 16-bit address mode */
-            if (!AddressSize)
-            {
-                ULONG MaxBytesSrc = State->Flags.Df
-                                    ? (ULONG)State->GeneralRegs[FAST486_REG_ESI].LowWord
-                                    : (0x10000 - (ULONG)State->GeneralRegs[FAST486_REG_ESI].LowWord);
-                ULONG MaxBytesDest = State->Flags.Df
-                                     ? (ULONG)State->GeneralRegs[FAST486_REG_EDI].LowWord
-                                     : (0x10000 - (ULONG)State->GeneralRegs[FAST486_REG_EDI].LowWord);
-
-
-                Processed = min(Processed, min(MaxBytesSrc, MaxBytesDest) / DataSize);
-                if (Processed == 0) Processed = 1;
-            }
-
-            if (State->Flags.Df)
-            {
-                /* Reduce ESI and EDI by the number of bytes to transfer */
-                if (AddressSize)
-                {
-                    State->GeneralRegs[FAST486_REG_ESI].Long -= Processed * DataSize;
-                    State->GeneralRegs[FAST486_REG_EDI].Long -= Processed * DataSize;
-                }
-                else
-                {
-                    State->GeneralRegs[FAST486_REG_ESI].LowWord -= Processed * DataSize;
-                    State->GeneralRegs[FAST486_REG_EDI].LowWord -= Processed * DataSize;
-                }
-            }
-
-            /* Read from memory */
-            if (!Fast486ReadMemory(State,
-                                   Segment,
-                                   AddressSize ? State->GeneralRegs[FAST486_REG_ESI].Long
-                                               : State->GeneralRegs[FAST486_REG_ESI].LowWord,
-                                   FALSE,
-                                   Block,
-                                   Processed * DataSize))
-            {
-                /* Set ECX */
-                if (OperandSize) State->GeneralRegs[FAST486_REG_ECX].Long = Count;
-                else State->GeneralRegs[FAST486_REG_ECX].LowWord = LOWORD(Count);
-
-                /* Exception occurred */
-                return FALSE;
-            }
-
-            /* Write to memory */
-            if (!Fast486WriteMemory(State,
-                                    FAST486_REG_ES,
-                                    AddressSize ? State->GeneralRegs[FAST486_REG_EDI].Long
-                                                : State->GeneralRegs[FAST486_REG_EDI].LowWord,
-                                    Block,
-                                    Processed * DataSize))
-            {
-                /* Set ECX */
-                if (OperandSize) State->GeneralRegs[FAST486_REG_ECX].Long = Count;
-                else State->GeneralRegs[FAST486_REG_ECX].LowWord = LOWORD(Count);
-
-                /* Exception occurred */
-                return FALSE;
-            }
-
-            if (!State->Flags.Df)
-            {
-                /* Increase ESI and EDI by the number of bytes transfered */
-                if (AddressSize)
-                {
-                    State->GeneralRegs[FAST486_REG_ESI].Long += Processed * DataSize;
-                    State->GeneralRegs[FAST486_REG_EDI].Long += Processed * DataSize;
-                }
-                else
-                {
-                    State->GeneralRegs[FAST486_REG_ESI].LowWord += Processed * DataSize;
-                    State->GeneralRegs[FAST486_REG_EDI].LowWord += Processed * DataSize;
-                }
-            }
-
-            /* Reduce the total count by the number processed in this run */
-            Count -= Processed;
+            State->GeneralRegs[FAST486_REG_ESI].Long += DataSize;
+            State->GeneralRegs[FAST486_REG_EDI].Long += DataSize;
+        }
+        else
+        {
+            State->GeneralRegs[FAST486_REG_ESI].Long -= DataSize;
+            State->GeneralRegs[FAST486_REG_EDI].Long -= DataSize;
         }
-
-        /* Clear ECX */
-        if (OperandSize) State->GeneralRegs[FAST486_REG_ECX].Long = 0;
-        else State->GeneralRegs[FAST486_REG_ECX].LowWord = 0;
     }
     else
     {
-        /* Read from the source operand */
-        if (!Fast486ReadMemory(State,
-                               FAST486_REG_DS,
-                               AddressSize ? State->GeneralRegs[FAST486_REG_ESI].Long
-                                           : State->GeneralRegs[FAST486_REG_ESI].LowWord,
-                               FALSE,
-                               &Data,
-                               DataSize))
+        if (!State->Flags.Df)
         {
-            /* Exception occurred */
-            return FALSE;
+            State->GeneralRegs[FAST486_REG_ESI].LowWord += DataSize;
+            State->GeneralRegs[FAST486_REG_EDI].LowWord += DataSize;
         }
-
-        /* Write to the destination operand */
-        if (!Fast486WriteMemory(State,
-                                FAST486_REG_ES,
-                                AddressSize ? State->GeneralRegs[FAST486_REG_EDI].Long
-                                            : State->GeneralRegs[FAST486_REG_EDI].LowWord,
-                                &Data,
-                                DataSize))
+        else
         {
-            /* Exception occurred */
-            return FALSE;
+            State->GeneralRegs[FAST486_REG_ESI].LowWord -= DataSize;
+            State->GeneralRegs[FAST486_REG_EDI].LowWord -= DataSize;
         }
+    }
 
-        /* Increment/decrement ESI and EDI */
-        if (OperandSize)
+    // FIXME: This method is slow!
+    if (State->PrefixFlags & (FAST486_PREFIX_REP | FAST486_PREFIX_REPNZ))
+    {
+        if (AddressSize)
         {
-            if (!State->Flags.Df)
+            if (--State->GeneralRegs[FAST486_REG_ECX].Long)
             {
-                State->GeneralRegs[FAST486_REG_ESI].Long += DataSize;
-                State->GeneralRegs[FAST486_REG_EDI].Long += DataSize;
-            }
-            else
-            {
-                State->GeneralRegs[FAST486_REG_ESI].Long -= DataSize;
-                State->GeneralRegs[FAST486_REG_EDI].Long -= DataSize;
+                /* Repeat the instruction */
+                State->InstPtr = State->SavedInstPtr;
             }
         }
         else
         {
-            if (!State->Flags.Df)
+            if (--State->GeneralRegs[FAST486_REG_ECX].LowWord)
             {
-                State->GeneralRegs[FAST486_REG_ESI].LowWord += DataSize;
-                State->GeneralRegs[FAST486_REG_EDI].LowWord += DataSize;
-            }
-            else
-            {
-                State->GeneralRegs[FAST486_REG_ESI].LowWord -= DataSize;
-                State->GeneralRegs[FAST486_REG_EDI].LowWord -= DataSize;
+                /* Repeat the instruction */
+                State->InstPtr = State->SavedInstPtr;
             }
         }
     }
-
-    /* Return success */
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeCmps)
@@ -5553,13 +5391,24 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmps)
         Segment = State->SegmentOverride;
     }
 
+    if ((State->PrefixFlags & FAST486_PREFIX_REP)
+        || (State->PrefixFlags & FAST486_PREFIX_REPNZ))
+    {
+        if ((AddressSize && (State->GeneralRegs[FAST486_REG_ECX].Long == 0))
+            || (!AddressSize && (State->GeneralRegs[FAST486_REG_ECX].LowWord == 0)))
+        {
+            /* Do nothing */
+            return;
+        }
+    }
+
     /* Calculate the size */
     if (Opcode == 0xA6) DataSize = sizeof(UCHAR);
     else DataSize = OperandSize ? sizeof(ULONG) : sizeof(USHORT);
 
     /* Calculate the mask and sign flag */
-    DataMask = (1 << (DataSize * 8)) - 1;
     SignFlag = 1 << ((DataSize * 8) - 1);
+    DataMask = SignFlag | (SignFlag - 1);
 
     /* Read from the first source operand */
     if (!Fast486ReadMemory(State,
@@ -5571,7 +5420,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmps)
                            DataSize))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Read from the second source operand */
@@ -5584,7 +5433,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmps)
                            DataSize))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Calculate the result */
@@ -5602,7 +5451,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmps)
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Increment/decrement ESI and EDI */
-    if (OperandSize)
+    if (AddressSize)
     {
         if (!State->Flags.Df)
         {
@@ -5635,7 +5484,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmps)
     {
         BOOLEAN Repeat = TRUE;
 
-        if (OperandSize)
+        if (AddressSize)
         {
             if ((--State->GeneralRegs[FAST486_REG_ECX].Long) == 0)
             {
@@ -5665,9 +5514,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmps)
             State->InstPtr = State->SavedInstPtr;
         }
     }
-
-    /* Return success */
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeStos)
@@ -5687,10 +5533,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeStos)
     if (Opcode == 0xAA) DataSize = sizeof(UCHAR);
     else DataSize = OperandSize ? sizeof(ULONG) : sizeof(USHORT);
 
-    if (State->PrefixFlags & FAST486_PREFIX_REP)
+    if (State->PrefixFlags & (FAST486_PREFIX_REP | FAST486_PREFIX_REPNZ))
     {
         UCHAR Block[STRING_BLOCK_SIZE];
-        ULONG Count = OperandSize ? State->GeneralRegs[FAST486_REG_ECX].Long
+        ULONG Count = AddressSize ? State->GeneralRegs[FAST486_REG_ECX].Long
                                   : State->GeneralRegs[FAST486_REG_ECX].LowWord;
 
         /* Fill the memory block with the data */
@@ -5733,9 +5579,9 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeStos)
 
             if (State->Flags.Df)
             {
-                /* Reduce EDI by the number of bytes to transfer */
-                if (AddressSize) State->GeneralRegs[FAST486_REG_EDI].Long -= Processed * DataSize;
-                else State->GeneralRegs[FAST486_REG_EDI].LowWord -= Processed * DataSize;
+                /* Set EDI to the starting location */
+                if (AddressSize) State->GeneralRegs[FAST486_REG_EDI].Long -= (Processed - 1) * DataSize;
+                else State->GeneralRegs[FAST486_REG_EDI].LowWord -= (Processed - 1) * DataSize;
             }
 
             /* Write to memory */
@@ -5747,11 +5593,11 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeStos)
                                     Processed * DataSize))
             {
                 /* Set ECX */
-                if (OperandSize) State->GeneralRegs[FAST486_REG_ECX].Long = Count;
+                if (AddressSize) State->GeneralRegs[FAST486_REG_ECX].Long = Count;
                 else State->GeneralRegs[FAST486_REG_ECX].LowWord = LOWORD(Count);
 
                 /* Exception occurred */
-                return FALSE;
+                return;
             }
 
             if (!State->Flags.Df)
@@ -5760,13 +5606,19 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeStos)
                 if (AddressSize) State->GeneralRegs[FAST486_REG_EDI].Long += Processed * DataSize;
                 else State->GeneralRegs[FAST486_REG_EDI].LowWord += Processed * DataSize;
             }
+            else
+            {
+                /* Reduce EDI */
+                if (AddressSize) State->GeneralRegs[FAST486_REG_EDI].Long -= DataSize;
+                else State->GeneralRegs[FAST486_REG_EDI].LowWord -= DataSize;
+            }
 
             /* Reduce the total count by the number processed in this run */
             Count -= Processed;
         }
 
         /* Clear ECX */
-        if (OperandSize) State->GeneralRegs[FAST486_REG_ECX].Long = 0;
+        if (AddressSize) State->GeneralRegs[FAST486_REG_ECX].Long = 0;
         else State->GeneralRegs[FAST486_REG_ECX].LowWord = 0;
     }
     else
@@ -5780,11 +5632,11 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeStos)
                                 DataSize))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Increment/decrement EDI */
-        if (OperandSize)
+        if (AddressSize)
         {
             if (!State->Flags.Df) State->GeneralRegs[FAST486_REG_EDI].Long += DataSize;
             else State->GeneralRegs[FAST486_REG_EDI].Long -= DataSize;
@@ -5795,9 +5647,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeStos)
             else State->GeneralRegs[FAST486_REG_EDI].LowWord -= DataSize;
         }
     }
-
-    /* Return success */
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeLods)
@@ -5824,13 +5673,13 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLods)
     if (Opcode == 0xAC) DataSize = sizeof(UCHAR);
     else DataSize = OperandSize ? sizeof(ULONG) : sizeof(USHORT);
 
-    if (State->PrefixFlags & FAST486_PREFIX_REP)
+    if (State->PrefixFlags & (FAST486_PREFIX_REP | FAST486_PREFIX_REPNZ))
     {
-        ULONG Count = OperandSize ? State->GeneralRegs[FAST486_REG_ECX].Long
+        ULONG Count = AddressSize ? State->GeneralRegs[FAST486_REG_ECX].Long
                                   : State->GeneralRegs[FAST486_REG_ECX].LowWord;
 
         /* If the count is 0, do nothing */
-        if (Count == 0) return TRUE;
+        if (Count == 0) return;
 
         /* Only the last entry will be loaded */
         if (!State->Flags.Df)
@@ -5843,6 +5692,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLods)
             if (AddressSize) State->GeneralRegs[FAST486_REG_ESI].Long -= (Count - 1) * DataSize;
             else State->GeneralRegs[FAST486_REG_ESI].LowWord -= (Count - 1) * DataSize;
         }
+
+        /* Clear ECX */
+        if (AddressSize) State->GeneralRegs[FAST486_REG_ECX].Long = 0;
+        else State->GeneralRegs[FAST486_REG_ECX].LowWord = 0;
     }
 
     /* Read from the source operand */
@@ -5855,11 +5708,11 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLods)
                            DataSize))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Increment/decrement ESI */
-    if (OperandSize)
+    if (AddressSize)
     {
         if (!State->Flags.Df) State->GeneralRegs[FAST486_REG_ESI].Long += DataSize;
         else State->GeneralRegs[FAST486_REG_ESI].Long -= DataSize;
@@ -5869,9 +5722,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeLods)
         if (!State->Flags.Df) State->GeneralRegs[FAST486_REG_ESI].LowWord += DataSize;
         else State->GeneralRegs[FAST486_REG_ESI].LowWord -= DataSize;
     }
-
-    /* Return success */
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeScas)
@@ -5890,13 +5740,24 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeScas)
     TOGGLE_OPSIZE(OperandSize);
     TOGGLE_ADSIZE(AddressSize);
 
+    if ((State->PrefixFlags & FAST486_PREFIX_REP)
+        || (State->PrefixFlags & FAST486_PREFIX_REPNZ))
+    {
+        if ((AddressSize && (State->GeneralRegs[FAST486_REG_ECX].Long == 0))
+            || (!AddressSize && (State->GeneralRegs[FAST486_REG_ECX].LowWord == 0)))
+        {
+            /* Do nothing */
+            return; 
+        }
+    }
+
     /* Calculate the size */
     if (Opcode == 0xAE) DataSize = sizeof(UCHAR);
     else DataSize = OperandSize ? sizeof(ULONG) : sizeof(USHORT);
 
     /* Calculate the mask and sign flag */
-    DataMask = (1 << (DataSize * 8)) - 1;
     SignFlag = 1 << ((DataSize * 8) - 1);
+    DataMask = SignFlag | (SignFlag - 1);
 
     /* Read from the source operand */
     if (!Fast486ReadMemory(State,
@@ -5908,7 +5769,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeScas)
                            DataSize))
     {
         /* Exception occurred */
-        return FALSE;
+        return;
     }
 
     /* Calculate the result */
@@ -5926,7 +5787,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeScas)
     State->Flags.Pf = Fast486CalculateParity(Result);
 
     /* Increment/decrement EDI */
-    if (OperandSize)
+    if (AddressSize)
     {
         if (!State->Flags.Df) State->GeneralRegs[FAST486_REG_EDI].Long += DataSize;
         else State->GeneralRegs[FAST486_REG_EDI].Long -= DataSize;
@@ -5943,7 +5804,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeScas)
     {
         BOOLEAN Repeat = TRUE;
 
-        if (OperandSize)
+        if (AddressSize)
         {
             if ((--State->GeneralRegs[FAST486_REG_ECX].Long) == 0)
             {
@@ -5973,9 +5834,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeScas)
             State->InstPtr = State->SavedInstPtr;
         }
     }
-
-    /* Return success */
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeIns)
@@ -5995,10 +5853,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIns)
     if (Opcode == 0x6C) DataSize = sizeof(UCHAR);
     else DataSize = OperandSize ? sizeof(ULONG) : sizeof(USHORT);
 
-    if (State->PrefixFlags & FAST486_PREFIX_REP)
+    if (State->PrefixFlags & (FAST486_PREFIX_REP | FAST486_PREFIX_REPNZ))
     {
         UCHAR Block[STRING_BLOCK_SIZE];
-        ULONG Count = OperandSize ? State->GeneralRegs[FAST486_REG_ECX].Long
+        ULONG Count = AddressSize ? State->GeneralRegs[FAST486_REG_ECX].Long
                                   : State->GeneralRegs[FAST486_REG_ECX].LowWord;
 
         /* Clear the memory block */
@@ -6057,11 +5915,11 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIns)
                                     Processed * DataSize))
             {
                 /* Set ECX */
-                if (OperandSize) State->GeneralRegs[FAST486_REG_ECX].Long = Count;
+                if (AddressSize) State->GeneralRegs[FAST486_REG_ECX].Long = Count;
                 else State->GeneralRegs[FAST486_REG_ECX].LowWord = LOWORD(Count);
 
                 /* Exception occurred */
-                return FALSE;
+                return;
             }
 
             if (!State->Flags.Df)
@@ -6076,7 +5934,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIns)
         }
 
         /* Clear ECX */
-        if (OperandSize) State->GeneralRegs[FAST486_REG_ECX].Long = 0;
+        if (AddressSize) State->GeneralRegs[FAST486_REG_ECX].Long = 0;
         else State->GeneralRegs[FAST486_REG_ECX].LowWord = 0;
     }
     else
@@ -6099,11 +5957,11 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIns)
                                 DataSize))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Increment/decrement EDI */
-        if (OperandSize)
+        if (AddressSize)
         {
             if (!State->Flags.Df) State->GeneralRegs[FAST486_REG_EDI].Long += DataSize;
             else State->GeneralRegs[FAST486_REG_EDI].Long -= DataSize;
@@ -6114,9 +5972,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeIns)
             else State->GeneralRegs[FAST486_REG_EDI].LowWord -= DataSize;
         }
     }
-
-    /* Return success */
-    return TRUE;
 }
 
 FAST486_OPCODE_HANDLER(Fast486OpcodeOuts)
@@ -6136,10 +5991,10 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOuts)
     if (Opcode == 0x6E) DataSize = sizeof(UCHAR);
     else DataSize = OperandSize ? sizeof(ULONG) : sizeof(USHORT);
 
-    if (State->PrefixFlags & FAST486_PREFIX_REP)
+    if (State->PrefixFlags & (FAST486_PREFIX_REP | FAST486_PREFIX_REPNZ))
     {
         UCHAR Block[STRING_BLOCK_SIZE];
-        ULONG Count = OperandSize ? State->GeneralRegs[FAST486_REG_ECX].Long
+        ULONG Count = AddressSize ? State->GeneralRegs[FAST486_REG_ECX].Long
                                   : State->GeneralRegs[FAST486_REG_ECX].LowWord;
 
         /* Clear the memory block */
@@ -6154,8 +6009,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOuts)
             if (!AddressSize)
             {
                 ULONG MaxBytes = State->Flags.Df
-                                 ? (ULONG)State->GeneralRegs[FAST486_REG_EDI].LowWord
-                                 : (0x10000 - (ULONG)State->GeneralRegs[FAST486_REG_EDI].LowWord);
+                                 ? (ULONG)State->GeneralRegs[FAST486_REG_ESI].LowWord
+                                 : (0x10000 - (ULONG)State->GeneralRegs[FAST486_REG_ESI].LowWord);
 
                 Processed = min(Processed, MaxBytes / DataSize);
                 if (Processed == 0) Processed = 1;
@@ -6163,28 +6018,29 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOuts)
 
             /* Read from memory */
             if (!Fast486ReadMemory(State,
-                                   FAST486_REG_ES,
-                                   AddressSize ? State->GeneralRegs[FAST486_REG_EDI].Long
-                                               : State->GeneralRegs[FAST486_REG_EDI].LowWord,
+                                   (State->PrefixFlags & FAST486_PREFIX_SEG)
+                                   ? State->SegmentOverride : FAST486_REG_DS,
+                                   AddressSize ? State->GeneralRegs[FAST486_REG_ESI].Long
+                                               : State->GeneralRegs[FAST486_REG_ESI].LowWord,
                                    FALSE,
                                    Block,
                                    Processed * DataSize))
             {
                 /* Set ECX */
-                if (OperandSize) State->GeneralRegs[FAST486_REG_ECX].Long = Count;
+                if (AddressSize) State->GeneralRegs[FAST486_REG_ECX].Long = Count;
                 else State->GeneralRegs[FAST486_REG_ECX].LowWord = LOWORD(Count);
 
                 /* Exception occurred */
-                return FALSE;
+                return;
             }
 
             if (State->Flags.Df)
             {
                 ULONG i, j;
 
-                /* Reduce EDI by the number of bytes to transfer */
-                if (AddressSize) State->GeneralRegs[FAST486_REG_EDI].Long -= Processed * DataSize;
-                else State->GeneralRegs[FAST486_REG_EDI].LowWord -= Processed * DataSize;
+                /* Reduce ESI by the number of bytes to transfer */
+                if (AddressSize) State->GeneralRegs[FAST486_REG_ESI].Long -= Processed * DataSize;
+                else State->GeneralRegs[FAST486_REG_ESI].LowWord -= Processed * DataSize;
 
                 /* Reverse the block data */
                 for (i = 0; i < Processed / 2; i++)
@@ -6208,9 +6064,9 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOuts)
 
             if (!State->Flags.Df)
             {
-                /* Increase EDI by the number of bytes transfered */
-                if (AddressSize) State->GeneralRegs[FAST486_REG_EDI].Long += Processed * DataSize;
-                else State->GeneralRegs[FAST486_REG_EDI].LowWord += Processed * DataSize;
+                /* Increase ESI by the number of bytes transfered */
+                if (AddressSize) State->GeneralRegs[FAST486_REG_ESI].Long += Processed * DataSize;
+                else State->GeneralRegs[FAST486_REG_ESI].LowWord += Processed * DataSize;
             }
 
             /* Reduce the total count by the number processed in this run */
@@ -6218,7 +6074,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOuts)
         }
 
         /* Clear ECX */
-        if (OperandSize) State->GeneralRegs[FAST486_REG_ECX].Long = 0;
+        if (AddressSize) State->GeneralRegs[FAST486_REG_ECX].Long = 0;
         else State->GeneralRegs[FAST486_REG_ECX].LowWord = 0;
     }
     else
@@ -6227,7 +6083,8 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOuts)
 
         /* Read from the source operand */
         if (!Fast486ReadMemory(State,
-                               FAST486_REG_DS,
+                               (State->PrefixFlags & FAST486_PREFIX_SEG)
+                               ? State->SegmentOverride : FAST486_REG_DS,
                                AddressSize ? State->GeneralRegs[FAST486_REG_ESI].Long
                                            : State->GeneralRegs[FAST486_REG_ESI].LowWord,
                                FALSE,
@@ -6235,7 +6092,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOuts)
                                DataSize))
         {
             /* Exception occurred */
-            return FALSE;
+            return;
         }
 
         /* Write to the I/O port */
@@ -6246,7 +6103,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOuts)
                                DataSize);
 
         /* Increment/decrement ESI */
-        if (OperandSize)
+        if (AddressSize)
         {
             if (!State->Flags.Df) State->GeneralRegs[FAST486_REG_ESI].Long += DataSize;
             else State->GeneralRegs[FAST486_REG_ESI].Long -= DataSize;
@@ -6257,7 +6114,6 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeOuts)
             else State->GeneralRegs[FAST486_REG_ESI].LowWord -= DataSize;
         }
     }
-
-    /* Return success */
-    return TRUE;
 }
+
+/* EOF */