diff --git a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj index b1a0b9ef72..a402b54963 100644 --- a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj +++ b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj @@ -244,6 +244,7 @@ + diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.IMemoryDomains.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.IMemoryDomains.cs new file mode 100644 index 0000000000..d5aa342a58 --- /dev/null +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.IMemoryDomains.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; + +using BizHawk.Emulation.Common; +using BizHawk.Emulation.Cores.Nintendo.N64.NativeApi; + +namespace BizHawk.Emulation.Cores.Nintendo.N64 +{ + public partial class N64 : IMemoryDomains + { + private List _memoryDomains = new List(); + + public MemoryDomainList MemoryDomains { get; private set; } + + private void MakeMemoryDomain(string name, mupen64plusApi.N64_MEMORY id, MemoryDomain.Endian endian, bool swizzled = false) + { + int size = api.get_memory_size(id); + + //if this type of memory isnt available, dont make the memory domain + if (size == 0) + { + return; + } + + IntPtr memPtr = api.get_memory_ptr(id); + + Func peekByte; + Action pokeByte; + + if (swizzled) + { + peekByte = delegate(int addr) + { + if (addr < 0 || addr >= size) + { + throw new ArgumentOutOfRangeException(); + } + + return Marshal.ReadByte(memPtr, (addr ^ 3)); + }; + pokeByte = delegate(int addr, byte val) + { + if (addr < 0 || addr >= size) + { + throw new ArgumentOutOfRangeException(); + } + + Marshal.WriteByte(memPtr, (addr ^ 3), val); + }; + } + else + { + peekByte = delegate(int addr) + { + if (addr < 0 || addr >= size) + { + throw new ArgumentOutOfRangeException(); + } + + return Marshal.ReadByte(memPtr, (addr)); + }; + pokeByte = delegate(int addr, byte val) + { + if (addr < 0 || addr >= size) + { + throw new ArgumentOutOfRangeException(); + } + + Marshal.WriteByte(memPtr, (addr), val); + }; + } + + var md = new MemoryDomain(name, size, endian, peekByte, pokeByte); + + _memoryDomains.Add(md); + } + + private void InitMemoryDomains() + { + //zero 07-sep-2014 - made RDRAM big endian domain, but none others. others need to be studied individually. + MakeMemoryDomain("RDRAM", mupen64plusApi.N64_MEMORY.RDRAM, MemoryDomain.Endian.Big, true); + + MakeMemoryDomain("PI Register", mupen64plusApi.N64_MEMORY.PI_REG, MemoryDomain.Endian.Little); + MakeMemoryDomain("SI Register", mupen64plusApi.N64_MEMORY.SI_REG, MemoryDomain.Endian.Little); + MakeMemoryDomain("VI Register", mupen64plusApi.N64_MEMORY.VI_REG, MemoryDomain.Endian.Little); + MakeMemoryDomain("RI Register", mupen64plusApi.N64_MEMORY.RI_REG, MemoryDomain.Endian.Little); + MakeMemoryDomain("AI Register", mupen64plusApi.N64_MEMORY.AI_REG, MemoryDomain.Endian.Little); + + MakeMemoryDomain("EEPROM", mupen64plusApi.N64_MEMORY.EEPROM, MemoryDomain.Endian.Little); + + if (_syncSettings.Controllers[0].IsConnected && + _syncSettings.Controllers[0].PakType == N64SyncSettings.N64ControllerSettings.N64ControllerPakType.MEMORY_CARD) + { + MakeMemoryDomain("Mempak 1", mupen64plusApi.N64_MEMORY.MEMPAK1, MemoryDomain.Endian.Little); + } + + if (_syncSettings.Controllers[1].IsConnected && + _syncSettings.Controllers[1].PakType == N64SyncSettings.N64ControllerSettings.N64ControllerPakType.MEMORY_CARD) + { + MakeMemoryDomain("Mempak 2", mupen64plusApi.N64_MEMORY.MEMPAK2, MemoryDomain.Endian.Little); + } + + if (_syncSettings.Controllers[2].IsConnected && + _syncSettings.Controllers[2].PakType == N64SyncSettings.N64ControllerSettings.N64ControllerPakType.MEMORY_CARD) + { + MakeMemoryDomain("Mempak 3", mupen64plusApi.N64_MEMORY.MEMPAK3, MemoryDomain.Endian.Little); + } + + if (_syncSettings.Controllers[3].IsConnected && + _syncSettings.Controllers[3].PakType == N64SyncSettings.N64ControllerSettings.N64ControllerPakType.MEMORY_CARD) + { + MakeMemoryDomain("Mempak 4", mupen64plusApi.N64_MEMORY.MEMPAK4, MemoryDomain.Endian.Little); + } + + MemoryDomains = new MemoryDomainList(_memoryDomains); + } + } +} diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs index 3f59ba055d..cc2ee0f2a8 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs @@ -2,8 +2,6 @@ using System.Threading; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Runtime.InteropServices; using BizHawk.Common.BufferExtensions; using BizHawk.Emulation.Common; @@ -19,7 +17,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 portedVersion: "2.0", portedUrl: "https://code.google.com/p/mupen64plus/" )] - public class N64 : IEmulator, IMemoryDomains + public partial class N64 : IEmulator, IMemoryDomains { private readonly N64Input _inputProvider; private readonly N64VideoProvider _videoProvider; @@ -39,14 +37,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 private Action _pendingThreadAction; - /// /// Create mupen64plus Emulator /// /// Core communication object /// Game information of game to load /// Rom that should be loaded - /// N64SyncSettings object + /// N64SyncSettings object [CoreConstructor("N64")] public N64(CoreComm comm, GameInfo game, byte[] rom, object settings, object syncSettings) { @@ -173,10 +170,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 private void StartThreadLoop() { - var thread = new Thread(ThreadLoop); - //will this solve the hanging process problem? - thread.IsBackground = true; - thread.Start(); + var thread = new Thread(ThreadLoop) { IsBackground = true }; + thread.Start(); // will this solve the hanging process problem? } private void EndThreadLoop() @@ -472,118 +467,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 #endregion - #region Memory Domains - - private MemoryDomain MakeMemoryDomain(string name, mupen64plusApi.N64_MEMORY id, MemoryDomain.Endian endian, bool swizzled = false) - { - int size = api.get_memory_size(id); - - //if this type of memory isnt available, dont make the memory domain - if (size == 0) - { - return null; - } - - IntPtr memPtr = api.get_memory_ptr(id); - - Func peekByte; - Action pokeByte; - - if (swizzled) - { - peekByte = delegate(int addr) - { - if (addr < 0 || addr >= size) - { - throw new ArgumentOutOfRangeException(); - } - - return Marshal.ReadByte(memPtr, (addr ^ 3)); - }; - pokeByte = delegate(int addr, byte val) - { - if (addr < 0 || addr >= size) - { - throw new ArgumentOutOfRangeException(); - } - - Marshal.WriteByte(memPtr, (addr ^ 3), val); - }; - } - else - { - peekByte = delegate(int addr) - { - if (addr < 0 || addr >= size) - { - throw new ArgumentOutOfRangeException(); - } - - return Marshal.ReadByte(memPtr, (addr)); - }; - pokeByte = delegate(int addr, byte val) - { - if (addr < 0 || addr >= size) - { - throw new ArgumentOutOfRangeException(); - } - - Marshal.WriteByte(memPtr, (addr), val); - }; - } - - var md = new MemoryDomain(name, size, endian, peekByte, pokeByte); - - _memoryDomains.Add(md); - - return md; - } - - private void InitMemoryDomains() - { - //zero 07-sep-2014 - made RDRAM big endian domain, but none others. others need to be studied individually. - MakeMemoryDomain("RDRAM", mupen64plusApi.N64_MEMORY.RDRAM, MemoryDomain.Endian.Big, true); - - MakeMemoryDomain("PI Register", mupen64plusApi.N64_MEMORY.PI_REG, MemoryDomain.Endian.Little); - MakeMemoryDomain("SI Register", mupen64plusApi.N64_MEMORY.SI_REG, MemoryDomain.Endian.Little); - MakeMemoryDomain("VI Register", mupen64plusApi.N64_MEMORY.VI_REG, MemoryDomain.Endian.Little); - MakeMemoryDomain("RI Register", mupen64plusApi.N64_MEMORY.RI_REG, MemoryDomain.Endian.Little); - MakeMemoryDomain("AI Register", mupen64plusApi.N64_MEMORY.AI_REG, MemoryDomain.Endian.Little); - - MakeMemoryDomain("EEPROM", mupen64plusApi.N64_MEMORY.EEPROM, MemoryDomain.Endian.Little); - - if (_syncSettings.Controllers[0].IsConnected && - _syncSettings.Controllers[0].PakType == N64SyncSettings.N64ControllerSettings.N64ControllerPakType.MEMORY_CARD) - { - MakeMemoryDomain("Mempak 1", mupen64plusApi.N64_MEMORY.MEMPAK1, MemoryDomain.Endian.Little); - } - - if (_syncSettings.Controllers[1].IsConnected && - _syncSettings.Controllers[1].PakType == N64SyncSettings.N64ControllerSettings.N64ControllerPakType.MEMORY_CARD) - { - MakeMemoryDomain("Mempak 2", mupen64plusApi.N64_MEMORY.MEMPAK2, MemoryDomain.Endian.Little); - } - - if (_syncSettings.Controllers[2].IsConnected && - _syncSettings.Controllers[2].PakType == N64SyncSettings.N64ControllerSettings.N64ControllerPakType.MEMORY_CARD) - { - MakeMemoryDomain("Mempak 3", mupen64plusApi.N64_MEMORY.MEMPAK3, MemoryDomain.Endian.Little); - } - - if (_syncSettings.Controllers[3].IsConnected && - _syncSettings.Controllers[3].PakType == N64SyncSettings.N64ControllerSettings.N64ControllerPakType.MEMORY_CARD) - { - MakeMemoryDomain("Mempak 4", mupen64plusApi.N64_MEMORY.MEMPAK4, MemoryDomain.Endian.Little); - } - - MemoryDomains = new MemoryDomainList(_memoryDomains); - } - - private List _memoryDomains = new List(); - public MemoryDomainList MemoryDomains { get; private set; } - - #endregion - #region Settings public object GetSettings()