From 026072ee6825216c51ec93cef4f6995a634e26b0 Mon Sep 17 00:00:00 2001 From: adelikat Date: Mon, 4 Nov 2013 01:17:59 +0000 Subject: [PATCH] moe IPS.cs from Emulation to Client.Common, until it is needed by cores --- .../BizHawk.Client.Common.csproj | 1 + BizHawk.Client.Common/IPS.cs | 64 +++++++++++++++++++ BizHawk.Emulation/BizHawk.Emulation.csproj | 1 - .../Interfaces/Base Implementations/IPS.cs | 64 ------------------- 4 files changed, 65 insertions(+), 65 deletions(-) create mode 100644 BizHawk.Client.Common/IPS.cs delete mode 100644 BizHawk.Emulation/Interfaces/Base Implementations/IPS.cs diff --git a/BizHawk.Client.Common/BizHawk.Client.Common.csproj b/BizHawk.Client.Common/BizHawk.Client.Common.csproj index 5619cb5705..afc95dbefc 100644 --- a/BizHawk.Client.Common/BizHawk.Client.Common.csproj +++ b/BizHawk.Client.Common/BizHawk.Client.Common.csproj @@ -100,6 +100,7 @@ + diff --git a/BizHawk.Client.Common/IPS.cs b/BizHawk.Client.Common/IPS.cs new file mode 100644 index 0000000000..621ebe6a40 --- /dev/null +++ b/BizHawk.Client.Common/IPS.cs @@ -0,0 +1,64 @@ +using System; +using System.IO; + +namespace BizHawk.Client.Common +{ + public static class IPS + { + public static void Patch(byte[] rom, Stream patch) + { + var ipsHeader = new byte[5]; + patch.Read(ipsHeader, 0, 5); + + string header = "PATCH"; + for (int i = 0; i < 5; i++) + { + if (ipsHeader[i] != header[i]) + { + Console.WriteLine("Patch file specified is invalid."); + return; + } + } + + // header verified, loop over patch entries + uint EOF = ('E' * 0x10000 + 'O' * 0x100 + 'F'); + + while (true) + { + uint offset = Read24(patch); + if (offset == EOF) return; + ushort size = Read16(patch); + + if (size != 0) // non-RLE patch + { + var patchData = new byte[size]; + patch.Read(patchData, 0, size); + for (int i = 0; i < size; i++) + rom[offset++] = patchData[i]; + } + else // RLE patch + { + size = Read16(patch); + byte value = (byte)patch.ReadByte(); + for (int i = 0; i < size; i++) + rom[offset++] = value; + } + } + } + + private static ushort Read16(Stream patch) + { + int Upper = patch.ReadByte(); + int Lower = patch.ReadByte(); + return (ushort)(Upper * 0x100 + Lower); + } + + private static uint Read24(Stream patch) + { + int Upper = patch.ReadByte(); + int Middle = patch.ReadByte(); + int Lower = patch.ReadByte(); + return (uint)(Upper * 0x10000 + Middle * 0x100 + Lower); + } + } +} \ No newline at end of file diff --git a/BizHawk.Emulation/BizHawk.Emulation.csproj b/BizHawk.Emulation/BizHawk.Emulation.csproj index 24cc81b71f..5e1d7d515b 100644 --- a/BizHawk.Emulation/BizHawk.Emulation.csproj +++ b/BizHawk.Emulation/BizHawk.Emulation.csproj @@ -452,7 +452,6 @@ - diff --git a/BizHawk.Emulation/Interfaces/Base Implementations/IPS.cs b/BizHawk.Emulation/Interfaces/Base Implementations/IPS.cs deleted file mode 100644 index 7dcc23c578..0000000000 --- a/BizHawk.Emulation/Interfaces/Base Implementations/IPS.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System; -using System.IO; - -namespace BizHawk -{ - public static class IPS - { - public static void Patch(byte[] rom, Stream patch) - { - var ipsHeader = new byte[5]; - patch.Read(ipsHeader, 0, 5); - - string header = "PATCH"; - for (int i = 0; i < 5; i++) - { - if (ipsHeader[i] != header[i]) - { - Console.WriteLine("Patch file specified is invalid."); - return; - } - } - - // header verified, loop over patch entries - uint EOF = ('E' * 0x10000 + 'O' * 0x100 + 'F'); - - while (true) - { - uint offset = Read24(patch); - if (offset == EOF) return; - ushort size = Read16(patch); - - if (size != 0) // non-RLE patch - { - var patchData = new byte[size]; - patch.Read(patchData, 0, size); - for (int i = 0; i < size; i++) - rom[offset++] = patchData[i]; - } - else // RLE patch - { - size = Read16(patch); - byte value = (byte)patch.ReadByte(); - for (int i = 0; i < size; i++) - rom[offset++] = value; - } - } - } - - private static ushort Read16(Stream patch) - { - int Upper = patch.ReadByte(); - int Lower = patch.ReadByte(); - return (ushort)(Upper * 0x100 + Lower); - } - - private static uint Read24(Stream patch) - { - int Upper = patch.ReadByte(); - int Middle = patch.ReadByte(); - int Lower = patch.ReadByte(); - return (uint)(Upper * 0x10000 + Middle * 0x100 + Lower); - } - } -} \ No newline at end of file