2019-10-11 15:22:24 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Common
|
2018-03-12 01:05:39 +00:00
|
|
|
|
{
|
2019-10-11 15:22:24 +00:00
|
|
|
|
public static class EndianSwap
|
2018-03-12 01:05:39 +00:00
|
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
|
public static ushort Swap16(ushort value) => (ushort)(((value >> 8) & 0xff) | (value << 8));
|
2018-08-16 23:47:36 +00:00
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
|
public static int Swap32(int value)
|
2018-06-18 02:28:11 +00:00
|
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
|
uint uintVal = (uint)value;
|
2018-06-18 02:28:11 +00:00
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
|
return (int)(((uintVal >> 24) & 0x000000ff) |
|
|
|
|
|
((uintVal >> 8) & 0x0000ff00) |
|
|
|
|
|
((uintVal << 8) & 0x00ff0000) |
|
|
|
|
|
((uintVal << 24) & 0xff000000));
|
2018-06-18 02:28:11 +00:00
|
|
|
|
}
|
2019-10-11 15:22:24 +00:00
|
|
|
|
|
|
|
|
|
public static uint FromBigEndianToPlatformEndian(uint value)
|
|
|
|
|
{
|
|
|
|
|
uint result = value;
|
|
|
|
|
|
|
|
|
|
if (BitConverter.IsLittleEndian)
|
|
|
|
|
{
|
|
|
|
|
result = (uint)EndianSwap.Swap32((int)result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2018-03-12 01:05:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|