[FAST486]

Fix the BSF and BSR instructions. Partially fix SHLD and SHRD.


svn path=/branches/ntvdm/; revision=60987
This commit is contained in:
Aleksandar Andrejevic 2013-11-14 02:39:54 +00:00
parent a3513c8f18
commit cdf876ead9

View file

@ -669,6 +669,7 @@ FAST486_OPCODE_HANDLER(Fast486ExtOpcodeShld)
else else
{ {
USHORT Source, Destination, Result; USHORT Source, Destination, Result;
ULONG DoubleSource;
if (!Fast486ReadModrmWordOperands(State, &ModRegRm, &Source, &Destination)) if (!Fast486ReadModrmWordOperands(State, &ModRegRm, &Source, &Destination))
{ {
@ -676,8 +677,10 @@ FAST486_OPCODE_HANDLER(Fast486ExtOpcodeShld)
return FALSE; return FALSE;
} }
DoubleSource = Source | (Source << 16);
/* Calculate the result */ /* Calculate the result */
Result = (Destination << Count) | (Source >> (16 - Count)); Result = (Destination << Count) | (DoubleSource >> (32 - Count));
/* Update flags */ /* Update flags */
State->Flags.Cf = (Destination >> (16 - Count)) & 1; State->Flags.Cf = (Destination >> (16 - Count)) & 1;
@ -881,6 +884,8 @@ FAST486_OPCODE_HANDLER(Fast486ExtOpcodeShrd)
/* Calculate the result */ /* Calculate the result */
Result = (Destination >> Count) | (Source << (16 - Count)); Result = (Destination >> Count) | (Source << (16 - Count));
if (Count >= 16) Result |= (ULONG)(Source | (Source << 16)) >> (Count - 16);
/* Update flags */ /* Update flags */
State->Flags.Cf = (Result >> (Count - 1)) & 1; State->Flags.Cf = (Result >> (Count - 1)) & 1;
if (Count == 1) State->Flags.Of = (Result & SIGN_FLAG_WORD) if (Count == 1) State->Flags.Of = (Result & SIGN_FLAG_WORD)
@ -1535,16 +1540,14 @@ FAST486_OPCODE_HANDLER(Fast486ExtOpcodeBsf)
} }
} }
/* Clear ZF */ /* Set ZF */
State->Flags.Zf = FALSE; State->Flags.Zf = (Value == 0);
if (State->Flags.Zf) return TRUE;
for (i = 0; i < DataSize; i++) for (i = 0; i < DataSize; i++)
{ {
if(Value & (1 << i)) if(Value & (1 << i))
{ {
/* Set ZF */
State->Flags.Zf = TRUE;
/* Save the bit number */ /* Save the bit number */
BitNumber = i; BitNumber = i;
@ -1553,8 +1556,6 @@ FAST486_OPCODE_HANDLER(Fast486ExtOpcodeBsf)
} }
} }
if (State->Flags.Zf)
{
/* Write back the result */ /* Write back the result */
if (OperandSize) if (OperandSize)
{ {
@ -1572,7 +1573,6 @@ FAST486_OPCODE_HANDLER(Fast486ExtOpcodeBsf)
return FALSE; return FALSE;
} }
} }
}
return TRUE; return TRUE;
} }
@ -1625,16 +1625,14 @@ FAST486_OPCODE_HANDLER(Fast486ExtOpcodeBsr)
} }
} }
/* Clear ZF */ /* Set ZF according to the value */
State->Flags.Zf = FALSE; State->Flags.Zf = (Value == 0);
if (State->Flags.Zf) return TRUE;
for (i = DataSize - 1; i >= 0; i--) for (i = DataSize - 1; i >= 0; i--)
{ {
if(Value & (1 << i)) if(Value & (1 << i))
{ {
/* Set ZF */
State->Flags.Zf = TRUE;
/* Save the bit number */ /* Save the bit number */
BitNumber = i; BitNumber = i;
@ -1643,8 +1641,6 @@ FAST486_OPCODE_HANDLER(Fast486ExtOpcodeBsr)
} }
} }
if (State->Flags.Zf)
{
/* Write back the result */ /* Write back the result */
if (OperandSize) if (OperandSize)
{ {
@ -1662,7 +1658,6 @@ FAST486_OPCODE_HANDLER(Fast486ExtOpcodeBsr)
return FALSE; return FALSE;
} }
} }
}
return TRUE; return TRUE;
} }