From 3e89a7f20177f2d18081ddf8cd960c0e3a0f125b Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 28 Mar 2020 11:21:39 -0500 Subject: [PATCH] DS - refactor settings so that it is an enum that then translates to ScreenArranger settings --- .../DisplayManager/DisplayManager.cs | 2 +- .../Consoles/Nintendo/NDS/MelonDS.cs | 2 + .../Consoles/Nintendo/NDS/MelonDS_Settable.cs | 22 ++---- .../Nintendo/NDS/MelonDS_VideoProvider.cs | 7 +- .../Nintendo/NDS/VIdeoScreenOptions.cs | 68 +++++++++++++++++++ BizHawk.sln.DotSettings | 1 + 6 files changed, 80 insertions(+), 22 deletions(-) create mode 100644 BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/VIdeoScreenOptions.cs diff --git a/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs b/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs index 2b22e88a25..97e3f61325 100644 --- a/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs +++ b/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs @@ -402,7 +402,7 @@ namespace BizHawk.Client.EmuHawk // Poop if (Global.Emulator is MelonDS ds) { - Point touchLocation = ds.GetSettings().ScreenOptions.Locations[1]; + Point touchLocation = ds.TouchScreenStart; v.Y = (int)((double)ds.BufferHeight / MelonDS.NativeHeight * (v.Y - touchLocation.Y)); v.X = (int)((double)ds.BufferWidth / MelonDS.NativeWidth * (v.X - touchLocation.X)); } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs index 10a4135dd7..738e8fbfe7 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs @@ -119,6 +119,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS } } + public Point TouchScreenStart => _screenArranger.LayoutSettings.Locations[1]; + /// /// MelonDS expects bios and firmware files at a specific location. /// This should never be called without an accompanying call to PutSyncSettings. diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_Settable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_Settable.cs index 91cfc053e7..5caca31245 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_Settable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_Settable.cs @@ -1,7 +1,6 @@ using System; using System.Text; using System.Runtime.InteropServices; -using System.Drawing; using BizHawk.Emulation.Common; using Newtonsoft.Json; @@ -10,7 +9,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS { unsafe partial class MelonDS : ISettable { - private MelonSettings _settings; + private MelonSettings _settings = new MelonSettings(); public MelonSettings GetSettings() { @@ -32,21 +31,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS public bool PutSettings(MelonSettings o) { - if (o?.ScreenOptions == null) - { - o = new MelonSettings - { - ScreenOptions = new ScreenLayoutSettings - { - Locations = new[] { new Point(0, 0), new Point(0, NativeHeight) }, - Order = new[] { 0, 1 }, - FinalSize = new Size(NativeWidth, NativeHeight * 2) - } - }; - } - - _settings = o; - _screenArranger.LayoutSettings = _settings.ScreenOptions; + _settings = o ?? new MelonSettings(); + _screenArranger.LayoutSettings = _settings.ScreenOptions.ToLayout(); return false; } @@ -93,7 +79,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS public class MelonSettings { - public ScreenLayoutSettings ScreenOptions { get; set; } + public VideoScreenOptions ScreenOptions { get; set; } = VideoScreenOptions.Default; } public class MelonSyncSettings diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_VideoProvider.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_VideoProvider.cs index 5467dd2b81..8069567d03 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_VideoProvider.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_VideoProvider.cs @@ -1,4 +1,5 @@ -using System.Runtime.InteropServices; +using System.Linq; +using System.Runtime.InteropServices; using BizHawk.Emulation.Common; @@ -16,8 +17,8 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS public int VirtualWidth => BufferWidth; public int VirtualHeight => BufferHeight; - public int BufferWidth => _settings.ScreenOptions.FinalSize.Width; - public int BufferHeight => _settings.ScreenOptions.FinalSize.Height; + public int BufferWidth => _screenArranger.LayoutSettings.FinalSize.Width; + public int BufferHeight => _screenArranger.LayoutSettings.FinalSize.Height; public int VsyncNumerator => 60; diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/VIdeoScreenOptions.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/VIdeoScreenOptions.cs new file mode 100644 index 0000000000..a269bc635e --- /dev/null +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/VIdeoScreenOptions.cs @@ -0,0 +1,68 @@ +using System.Drawing; +using BizHawk.Emulation.Common; + +namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS +{ + public enum VideoScreenOptions + { + Default, TopOnly, BottomOnly, SideBySideLR, SideBySideRL /*, Reverse */ + } + + public static class VideoScreenOptionExtensions + { + public static ScreenLayoutSettings ToLayout(this VideoScreenOptions option) + { + return option switch + { + VideoScreenOptions.Default => Default, + VideoScreenOptions.TopOnly => TopOnly, + VideoScreenOptions.BottomOnly => BottomOnly, + VideoScreenOptions.SideBySideLR => SideBySideLR, + VideoScreenOptions.SideBySideRL => SideBySideRL, + _ => Default + }; + } + + private static ScreenLayoutSettings Default => new ScreenLayoutSettings + { + Locations = new[] { new Point(0, 0), new Point(0, MelonDS.NativeHeight) }, + Order = new[] { 0, 1 }, + FinalSize = new Size(MelonDS.NativeWidth, MelonDS.NativeHeight * 2) + }; + + private static ScreenLayoutSettings TopOnly => new ScreenLayoutSettings + { + Locations = new[] { new Point(0, 0), new Point(0, MelonDS.NativeHeight) }, + Order = new[] { 0, 1 }, + FinalSize = new Size(MelonDS.NativeWidth, MelonDS.NativeHeight * 2) + }; + + private static ScreenLayoutSettings BottomOnly => new ScreenLayoutSettings + { + Locations = new[] { new Point(0, 0), new Point(0, MelonDS.NativeHeight) }, + Order = new[] { 0, 1 }, + FinalSize = new Size(MelonDS.NativeWidth, MelonDS.NativeHeight * 2) + }; + + private static ScreenLayoutSettings SideBySideLR => new ScreenLayoutSettings + { + Locations = new[] { new Point(0, 0), new Point(0, MelonDS.NativeHeight) }, + Order = new[] { 0, 1 }, + FinalSize = new Size(MelonDS.NativeWidth, MelonDS.NativeHeight * 2) + }; + + private static ScreenLayoutSettings SideBySideRL => new ScreenLayoutSettings + { + Locations = new[] { new Point(0, 0), new Point(0, MelonDS.NativeHeight) }, + Order = new[] { 0, 1 }, + FinalSize = new Size(MelonDS.NativeWidth, MelonDS.NativeHeight * 2) + }; + + private static ScreenLayoutSettings Reverse => new ScreenLayoutSettings + { + Locations = new[] { new Point(0, 0), new Point(0, MelonDS.NativeHeight) }, + Order = new[] { 0, 1 }, + FinalSize = new Size(MelonDS.NativeWidth, MelonDS.NativeHeight * 2) + }; + } +} diff --git a/BizHawk.sln.DotSettings b/BizHawk.sln.DotSettings index e3c4f9b9a3..fde367c52b 100644 --- a/BizHawk.sln.DotSettings +++ b/BizHawk.sln.DotSettings @@ -109,6 +109,7 @@ PSP PSX RAM + RL RTC SG SGB