add serializer sync method to make a2600 core compile

This commit is contained in:
zeromus 2012-03-30 02:37:17 +00:00
parent 74594b961b
commit d55744e86f
1 changed files with 52 additions and 0 deletions

View File

@ -571,6 +571,31 @@ namespace BizHawk
return ret;
}
public static uint[] ByteBufferToUintBuffer(byte[] buf)
{
int num = buf.Length / 2;
uint[] ret = new uint[num];
for (int i = 0; i < num; i++)
{
ret[i] = (uint)(buf[i * 2] | (buf[i * 4 + 1] << 8) | (buf[i * 4 + 2] << 16) | (buf[i * 4 + 3] << 24));
}
return ret;
}
public static byte[] UintBufferToByteBuffer(uint[] buf)
{
int num = buf.Length;
byte[] ret = new byte[num * 4];
for (int i = 0; i < num; i++)
{
ret[i * 4 + 0] = (byte)(buf[i] & 0xFF);
ret[i * 4 + 1] = (byte)((buf[i] >> 8) & 0xFF);
ret[i * 4 + 2] = (byte)((buf[i] >> 16) & 0xFF);
ret[i * 4 + 3] = (byte)((buf[i] >> 24) & 0xFF);
}
return ret;
}
public static byte[] ReadByteBuffer(BinaryReader br, bool return_null)
{
int len = br.ReadInt32();
@ -821,6 +846,33 @@ namespace BizHawk
}
}
public void Sync(string name, ref uint[] val, bool use_null)
{
if (IsText) SyncText(name, ref val, use_null);
else if (IsReader)
{
val = Util.ByteBufferToUintBuffer(Util.ReadByteBuffer(br, false));
if (val == null && !use_null) val = new uint[0];
}
else Util.WriteByteBuffer(bw, Util.UintBufferToByteBuffer(val));
}
public void SyncText(string name, ref uint[] val, bool use_null)
{
if (IsReader)
{
string[] parts = tr.ReadLine().Split(' ');
byte[] bytes = Util.HexStringToBytes(parts[1]);
val = Util.ByteBufferToUintBuffer(bytes);
if (val.Length == 0 && use_null) val = null;
}
else
{
uint[] temp = val;
if (temp == null) temp = new uint[0];
tw.WriteLine("{0} {1}", name, Util.BytesToHexString(Util.UintBufferToByteBuffer(temp)));
}
}
public void Sync(string name, ref Bit val)
{
if (IsText) SyncText(name, ref val);