From d55744e86fb678d8451490fea7df4bdf94cdda64 Mon Sep 17 00:00:00 2001 From: zeromus Date: Fri, 30 Mar 2012 02:37:17 +0000 Subject: [PATCH] add serializer sync method to make a2600 core compile --- BizHawk.Emulation/Util.cs | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/BizHawk.Emulation/Util.cs b/BizHawk.Emulation/Util.cs index e21ed8a1aa..ef41c4eb72 100644 --- a/BizHawk.Emulation/Util.cs +++ b/BizHawk.Emulation/Util.cs @@ -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);