From 0422b9b1de764d6dc8cb1f1338519dcd2e27b43d Mon Sep 17 00:00:00 2001 From: adelikat Date: Thu, 2 Apr 2020 17:36:03 -0500 Subject: [PATCH] nitpick cleanup --- .../Consoles/Nintendo/NDS/MelonDS.cs | 4 +--- .../Nintendo/NDS/MelonDS_InputPollable.cs | 17 +++++++++++------ .../Nintendo/NDS/MelonDS_MemoryDomains.cs | 3 --- .../Consoles/Nintendo/NDS/MelonDS_SaveRam.cs | 1 - .../Consoles/Nintendo/NDS/MelonDS_Settable.cs | 18 +++++++++++------- .../Nintendo/NDS/MelonDS_SoundProvider.cs | 6 +++--- .../Consoles/Nintendo/NDS/MelonDS_Statable.cs | 5 ++++- 7 files changed, 30 insertions(+), 24 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs index 0a973c78f1..f465859a3f 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs @@ -1,8 +1,6 @@ using System; using System.Runtime.InteropServices; using System.IO; -using System.Drawing; - using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS @@ -96,7 +94,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS ControllerDefinition.AxisRanges.Add(new ControllerDefinition.AxisRange(0, 96, 191)); CoreComm = comm; - resampler = new SpeexResampler(SpeexResampler.Quality.QUALITY_DEFAULT, 32768, 44100, 32768, 44100); + _resampler = new SpeexResampler(SpeexResampler.Quality.QUALITY_DEFAULT, 32768, 44100, 32768, 44100); SetUpFiles(); if (!Init()) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_InputPollable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_InputPollable.cs index d883ddeabe..268d2a1413 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_InputPollable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_InputPollable.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Runtime.InteropServices; using BizHawk.Emulation.Common; @@ -11,8 +7,17 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS { partial class MelonDS : IInputPollable { - public int LagCount { get => GetLagFrameCount(); set => throw new NotImplementedException(); } - public bool IsLagFrame { get => _IsLagFrame(); set => throw new NotImplementedException(); } + public int LagCount + { + get => GetLagFrameCount(); + set => throw new NotImplementedException(); + } + + public bool IsLagFrame + { + get => _IsLagFrame(); + set => throw new NotImplementedException(); + } public IInputCallbackSystem InputCallbacks => throw new NotImplementedException(); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_MemoryDomains.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_MemoryDomains.cs index 491592fc24..48c8927cd6 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_MemoryDomains.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_MemoryDomains.cs @@ -1,9 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Runtime.InteropServices; using BizHawk.Emulation.Common; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_SaveRam.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_SaveRam.cs index f87d802b42..6e6c98b2cd 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_SaveRam.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_SaveRam.cs @@ -35,6 +35,5 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS private static extern void GetSRAM(byte* dst, int length); [DllImport(dllPath)] private static extern void SetSRAM(byte* src, int length); - } } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_Settable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_Settable.cs index 0c0a1c9f0c..e7d54ada14 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_Settable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_Settable.cs @@ -1,7 +1,5 @@ using System; using System.ComponentModel; -using System.ComponentModel.DataAnnotations; -using System.Drawing; using System.Text; using System.Runtime.InteropServices; @@ -14,19 +12,19 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS { private MelonSettings _settings = new MelonSettings(); - public MelonSettings GetSettings() - { - return _settings; - } + public MelonSettings GetSettings() => _settings; public MelonSyncSettings GetSyncSettings() { - MelonSyncSettings ret = new MelonSyncSettings(); + var ret = new MelonSyncSettings(); fixed (byte* ptr = ret.UserSettings) { if (!GetUserSettings(ptr)) + { return null; + } } + ret.BootToFirmware = !GetDirectBoot(); ret.TimeAtBoot = GetTimeAtBoot(); return ret; @@ -60,6 +58,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS [DllImport(dllPath)] private static extern bool GetUserSettings(byte* dst); + [DllImport(dllPath)] private static extern int GetUserSettingsLength(); @@ -70,11 +69,13 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS [DllImport(dllPath)] private static extern bool GetDirectBoot(); + [DllImport(dllPath)] private static extern void SetDirectBoot(bool value); [DllImport(dllPath)] private static extern void SetTimeAtBoot(uint value); + [DllImport(dllPath)] private static extern uint GetTimeAtBoot(); @@ -155,7 +156,10 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS // I do not know how an actual NDS would handle characters that require more than 2 bytes to encode. // They can't be input normally, so I will ignore attempts to set a nickname that uses them. if (Encoding.Unicode.GetBytes(value, 0, value.Length, nick, 0) != value.Length * 2) + { return; + } + // The extra 2 bytes on the end will overwrite nickname length, which is set immediately after nick.CopyTo(UserSettings, 6); UserSettings[0x1A] = (byte)value.Length; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_SoundProvider.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_SoundProvider.cs index f252314ed9..0a63af72a8 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_SoundProvider.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_SoundProvider.cs @@ -7,7 +7,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS { unsafe partial class MelonDS : ISoundProvider { - SpeexResampler resampler; + private readonly SpeexResampler _resampler; public bool CanProvideAsync => false; @@ -32,8 +32,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS GetSamples(data, nsamp); } // BizHawk requires a sample rate of 44100 Hz. - resampler.EnqueueSamples(samples, nsamp); - resampler.GetSamplesSync(out samples, out nsamp); + _resampler.EnqueueSamples(samples, nsamp); + _resampler.GetSamplesSync(out samples, out nsamp); } public void SetSyncMode(SyncSoundMode mode) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_Statable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_Statable.cs index ecfb764260..c0a765873b 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_Statable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_Statable.cs @@ -9,7 +9,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS { public void LoadStateBinary(BinaryReader reader) { - MemoryStream mStream = new MemoryStream(); + var mStream = new MemoryStream(); reader.BaseStream.CopyTo(mStream); LoadStateByteArray(mStream.GetBuffer(), (int)mStream.Length); @@ -33,6 +33,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS { GetSavestateData(ptr, len); } + return ret; } @@ -44,8 +45,10 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS [DllImport(dllPath)] private static extern bool UseSavestate(byte* data, int len); + [DllImport(dllPath)] private static extern int GetSavestateSize(); + [DllImport(dllPath)] private static extern void GetSavestateData(byte* data, int size); }