Cleanup and added byteswapping functions for lua.

This commit is contained in:
pasky1382 2014-01-20 17:38:31 +00:00
parent 1fd577fce2
commit 033620a478
2 changed files with 33 additions and 2 deletions

View File

@ -19,6 +19,9 @@ namespace BizHawk.Client.Common
"ror", "ror",
"rshift", "rshift",
"check", "check",
"byteswap_16",
"byteswap_32",
"byteswap_64",
}; };
} }
} }
@ -70,5 +73,26 @@ namespace BizHawk.Client.Common
var value = Convert.ToInt64(LuaLong(num)); var value = Convert.ToInt64(LuaLong(num));
return (value & (1 << (int)(LuaInt(pos)))) != 0; return (value & (1 << (int)(LuaInt(pos)))) != 0;
} }
public static uint bit_byteswap_16(object short_)
{
return (UInt16)((LuaInt(short_) & 0xFFU) << 8 | (LuaInt(short_) & 0xFF00U) >> 8);
}
public static uint bit_byteswap_32(object word_)
{
return (LuaUInt(word_) & 0x000000FFU) << 24 | (LuaUInt(word_) & 0x0000FF00U) << 8 |
(LuaUInt(word_) & 0x00FF0000U) >> 8 | (LuaUInt(word_) & 0xFF000000U) >> 24;
}
public static UInt64 bit_byteswap_64(object long_)
{
UInt64 value = (UInt64)LuaLong(long_);
return (value & 0x00000000000000FFUL) << 56 | (value & 0x000000000000FF00UL) << 40 |
(value & 0x0000000000FF0000UL) << 24 | (value & 0x00000000FF000000UL) << 8 |
(value & 0x000000FF00000000UL) >> 8 | (value & 0x0000FF0000000000UL) >> 24 |
(value & 0x00FF000000000000UL) >> 40 | (value & 0xFF00000000000000UL) >> 56;
}
} }
} }

View File

@ -10,8 +10,9 @@ namespace BizHawk.Client.Common
{ {
return new[] return new[]
{ {
"hex",
"binary", "binary",
"hex",
"octal",
"trim", "trim",
"replace", "replace",
"toupper", "toupper",
@ -19,7 +20,6 @@ namespace BizHawk.Client.Common
"startswith", "startswith",
"substring", "substring",
"contains", "contains",
"endswith", "endswith",
}; };
} }
@ -38,6 +38,13 @@ namespace BizHawk.Client.Common
return binary; return binary;
} }
public static string string_octal(object num)
{
string octal = Convert.ToString(LuaLong(num),8);
if (octal.Length == 1) octal = "0" + octal;
return octal;
}
public static string string_trim(string str) public static string string_trim(string str)
{ {
return str.Trim(); return str.Trim();