From ab03580e88adf3f4dec4201994d1dd1cd344f9b7 Mon Sep 17 00:00:00 2001 From: kudzu_cp <6d05c8c8ef5431987001abfdb2eadc9593ac9498> Date: Mon, 23 Aug 2010 15:50:42 +0000 Subject: [PATCH] Fix for loading of sbyte in ldc --- source2/IL2PCU/Cosmos.IL2CPU/ILReader.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILReader.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILReader.cs index c475c998f..51eff05d8 100644 --- a/source2/IL2PCU/Cosmos.IL2CPU/ILReader.cs +++ b/source2/IL2PCU/Cosmos.IL2CPU/ILReader.cs @@ -289,7 +289,15 @@ namespace Cosmos.IL2CPU { case OperandType.ShortInlineI: switch (xOpCodeVal) { case ILOpCode.Code.Ldc_I4_S: - xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos + 1, xIL[xPos], xCurrentHandler); + // x = x & 0xFFFFFFFC; + // The above code produces: + // ldc.i4.s -4 + // But its getting loaded into a I4, so we have to "extend" it + // + // First we have to cast it to a signed byte, so .NET will extend it properly to a uint. + sbyte xSVal = (sbyte)xIL[xPos]; + uint xVal = (uint)xSVal; + xILOpCode = new ILOpCodes.OpInt(ILOpCode.Code.Ldc_I4, xOpPos, xPos + 1, xVal, xCurrentHandler); break; default: xILOpCode = new ILOpCodes.OpInt(xOpCodeVal, xOpPos, xPos + 1, xIL[xPos], xCurrentHandler);