diff --git a/BizHawk.Emulation/Consoles/Sega/Saturn/Yabause.cs b/BizHawk.Emulation/Consoles/Sega/Saturn/Yabause.cs index aa8f40122a..019c951ecb 100644 --- a/BizHawk.Emulation/Consoles/Sega/Saturn/Yabause.cs +++ b/BizHawk.Emulation/Consoles/Sega/Saturn/Yabause.cs @@ -350,7 +350,7 @@ namespace BizHawk.Emulation.Consoles.Sega.Saturn hex = reader.ReadLine(); } byte[] state = new byte[hex.Length / 2]; - state.ReadFromHex(hex); + state.ReadFromHexFast(hex); LoadStateBinary(new BinaryReader(new MemoryStream(state))); } diff --git a/BizHawk.Emulation/Util.cs b/BizHawk.Emulation/Util.cs index e15c4f47ca..eb59bf9475 100644 --- a/BizHawk.Emulation/Util.cs +++ b/BizHawk.Emulation/Util.cs @@ -364,6 +364,34 @@ namespace BizHawk } } + private static int Hex2Int(char c) + { + if (c <= '9') + return c - '0'; + else if (c <= 'F') + return c - '7'; + else + return c - 'W'; + } + + public static void ReadFromHexFast(this byte[] buffer, string hex) + { + //if (hex.Length % 2 != 0) + // throw new Exception("Hex value string does not appear to be properly formatted."); + for (int i = 0; i < buffer.Length && i * 2 < hex.Length; i++) + { + buffer[i] = (byte)(Hex2Int(hex[i * 2]) * 16 + Hex2Int(hex[i * 2 + 1])); + } + /* + var b = new byte[buffer.Length]; + b.ReadFromHex(hex); + for (int i = 0; i < buffer.Length; i++) + { + if (b[i] != buffer[i]) + throw new Exception(); + }*/ + } + public static void ReadFromHex(this short[] buffer, string hex) { if (hex.Length % 4 != 0)