From 8b60e74b8730046735809947799fc23fb6eb131e Mon Sep 17 00:00:00 2001 From: goyuken Date: Wed, 14 Jan 2015 22:00:46 +0000 Subject: [PATCH] swan: factor out some stuff into seperate files --- .../BizHawk.Emulation.Cores.csproj | 8 ++- .../WonderSwan/WonderSwan.IMemoryDomains.cs | 32 +++++++++++ .../WonderSwan/WonderSwan.ISaveRam.cs | 38 +++++++++++++ .../WonderSwan/WonderSwan.IStatable.cs | 6 ++ .../Consoles/WonderSwan/WonderSwan.cs | 56 ++----------------- 5 files changed, 87 insertions(+), 53 deletions(-) create mode 100644 BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.IMemoryDomains.cs create mode 100644 BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.ISaveRam.cs diff --git a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj index 1fa1b883c1..c95a6f3006 100644 --- a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj +++ b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj @@ -577,7 +577,13 @@ WonderSwan.cs - + + WonderSwan.cs + + + WonderSwan.cs + + WonderSwan.cs diff --git a/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.IMemoryDomains.cs b/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.IMemoryDomains.cs new file mode 100644 index 0000000000..39a63c507e --- /dev/null +++ b/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.IMemoryDomains.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Runtime.InteropServices; + +using BizHawk.Emulation.Common; + + +namespace BizHawk.Emulation.Cores.WonderSwan +{ + partial class WonderSwan + { + void InitIMemoryDomains() + { + var mmd = new List(); + for (int i = 0; ; i++) + { + IntPtr name; + int size; + IntPtr data; + if (!BizSwan.bizswan_getmemoryarea(Core, i, out name, out size, out data)) + break; + if (size == 0) + continue; + string sname = Marshal.PtrToStringAnsi(name); + mmd.Add(MemoryDomain.FromIntPtr(sname, size, MemoryDomain.Endian.Little, data)); + } + (ServiceProvider as BasicServiceProvider).Register(new MemoryDomainList(mmd, 0)); + } + } +} diff --git a/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.ISaveRam.cs b/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.ISaveRam.cs new file mode 100644 index 0000000000..0c83a13649 --- /dev/null +++ b/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.ISaveRam.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using BizHawk.Emulation.Common; + + +namespace BizHawk.Emulation.Cores.WonderSwan +{ + partial class WonderSwan : ISaveRam + { + byte[] saverambuff; + + void InitISaveRam() + { + saverambuff = new byte[BizSwan.bizswan_saveramsize(Core)]; + } + + public byte[] CloneSaveRam() + { + if (!BizSwan.bizswan_saveramsave(Core, saverambuff, saverambuff.Length)) + throw new InvalidOperationException("bizswan_saveramsave() returned false!"); + return (byte[])saverambuff.Clone(); + } + + public void StoreSaveRam(byte[] data) + { + if (!BizSwan.bizswan_saveramload(Core, data, data.Length)) + throw new InvalidOperationException("bizswan_saveramload() returned false!"); + } + + public bool SaveRamModified + { + get { return BizSwan.bizswan_saveramsize(Core) > 0; } + } + } +} diff --git a/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.IStatable.cs index 146dfc9266..d6241fcec0 100644 --- a/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.IStatable.cs @@ -12,6 +12,12 @@ namespace BizHawk.Emulation.Cores.WonderSwan { partial class WonderSwan: IStatable { + void InitIStatable() + { + savebuff = new byte[BizSwan.bizswan_binstatesize(Core)]; + savebuff2 = new byte[savebuff.Length + 13]; + } + JsonSerializer ser = new JsonSerializer() { Formatting = Formatting.Indented }; [StructLayout(LayoutKind.Sequential)] diff --git a/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.cs b/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.cs index fc89a0159d..0535b042ee 100644 --- a/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.cs +++ b/BizHawk.Emulation.Cores/Consoles/WonderSwan/WonderSwan.cs @@ -12,7 +12,7 @@ namespace BizHawk.Emulation.Cores.WonderSwan { [CoreAttributes("Cygne/Mednafen", "Dox", true, true, "0.9.36.5", "http://mednafen.sourceforge.net/")] [ServiceNotApplicable(typeof(IDriveLight))] - public partial class WonderSwan : IEmulator, IVideoProvider, ISyncSoundProvider, ISaveRam, + public partial class WonderSwan : IEmulator, IVideoProvider, ISyncSoundProvider, IInputPollable, IDebuggable { [CoreConstructor("WSWAN")] @@ -41,15 +41,13 @@ namespace BizHawk.Emulation.Cores.WonderSwan CoreComm.VsyncNum = 3072000; // master CPU clock, also pixel clock CoreComm.VsyncDen = (144 + 15) * (224 + 32); // 144 vislines, 15 vblank lines; 224 vispixels, 32 hblank pixels - saverambuff = new byte[BizSwan.bizswan_saveramsize(Core)]; + InitISaveRam(); InitVideo(rotate); PutSettings(_Settings); - SetMemoryDomains(); - - savebuff = new byte[BizSwan.bizswan_binstatesize(Core)]; - savebuff2 = new byte[savebuff.Length + 13]; + InitIMemoryDomains(); + InitIStatable(); InitDebugCallbacks(); } catch @@ -109,60 +107,14 @@ namespace BizHawk.Emulation.Cores.WonderSwan public bool DeterministicEmulation { get; private set; } public string BoardName { get { return null; } } - #region SaveRam - - byte[] saverambuff; - - public byte[] CloneSaveRam() - { - if (!BizSwan.bizswan_saveramsave(Core, saverambuff, saverambuff.Length)) - throw new InvalidOperationException("bizswan_saveramsave() returned false!"); - return (byte[])saverambuff.Clone(); - } - - public void StoreSaveRam(byte[] data) - { - if (!BizSwan.bizswan_saveramload(Core, data, data.Length)) - throw new InvalidOperationException("bizswan_saveramload() returned false!"); - } - - public bool SaveRamModified - { - get { return BizSwan.bizswan_saveramsize(Core) > 0; } - } - - #endregion - #region Debugging - void SetMemoryDomains() - { - var mmd = new List(); - for (int i = 0; ; i++) - { - IntPtr name; - int size; - IntPtr data; - if (!BizSwan.bizswan_getmemoryarea(Core, i, out name, out size, out data)) - break; - if (size == 0) - continue; - string sname = Marshal.PtrToStringAnsi(name); - mmd.Add(MemoryDomain.FromIntPtr(sname, size, MemoryDomain.Endian.Little, data)); - } - - MemoryDomains = new MemoryDomainList(mmd, 0); - (ServiceProvider as BasicServiceProvider).Register(MemoryDomains); - } - private readonly InputCallbackSystem _inputCallbacks = new InputCallbackSystem(); public IInputCallbackSystem InputCallbacks { get { return _inputCallbacks; } } private readonly MemoryCallbackSystem _memorycallbacks = new MemoryCallbackSystem(); public IMemoryCallbackSystem MemoryCallbacks { get { return _memorycallbacks; } } - private IMemoryDomains MemoryDomains; - public IDictionary GetCpuFlagsAndRegisters() { var ret = new Dictionary();