5 #define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)
7 const Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};
8 const Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};
10 SizeT x86_Convert(Byte *buffer, SizeT endPos, UInt32 nowPos, UInt32 *prevMaskMix, int encoding)
12 SizeT bufferPos = 0, prevPosT;
13 UInt32 prevMask = *prevMaskMix & 0x7;
17 prevPosT = (SizeT)0 - 1;
21 Byte *p = buffer + bufferPos;
22 Byte *limit = buffer + endPos - 4;
23 for (; p < limit; p++)
24 if ((*p & 0xFE) == 0xE8)
26 bufferPos = (SizeT)(p - buffer);
29 prevPosT = bufferPos - prevPosT;
34 prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7;
37 Byte b = p[4 - kMaskToBitNumber[prevMask]];
38 if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b))
41 prevMask = ((prevMask << 1) & 0x7) | 1;
49 if (Test86MSByte(p[4]))
51 UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);
58 dest = (nowPos + (UInt32)bufferPos) + src;
60 dest = src - (nowPos + (UInt32)bufferPos);
63 index = kMaskToBitNumber[prevMask] * 8;
64 b = (Byte)(dest >> (24 - index));
67 src = dest ^ ((1 << (32 - index)) - 1);
69 p[4] = (Byte)(~(((dest >> 24) & 1) - 1));
70 p[3] = (Byte)(dest >> 16);
71 p[2] = (Byte)(dest >> 8);
77 prevMask = ((prevMask << 1) & 0x7) | 1;
81 prevPosT = bufferPos - prevPosT;
82 *prevMaskMix = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7));