diff --git a/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs b/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs index 97e3f61325..73d0572602 100644 --- a/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs +++ b/BizHawk.Client.EmuHawk/DisplayManager/DisplayManager.cs @@ -400,9 +400,9 @@ namespace BizHawk.Client.EmuHawk v = _currentFilterProgram.UntransformPoint("default", v); // Poop - if (Global.Emulator is MelonDS ds) + if (Global.Emulator is MelonDS ds && ds.TouchScreenStart.HasValue) { - Point touchLocation = ds.TouchScreenStart; + Point touchLocation = ds.TouchScreenStart.Value; 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.Common/ScreenArranger.cs b/BizHawk.Emulation.Common/ScreenArranger.cs index 9f8ba9536c..8b7a713851 100644 --- a/BizHawk.Emulation.Common/ScreenArranger.cs +++ b/BizHawk.Emulation.Common/ScreenArranger.cs @@ -20,7 +20,9 @@ namespace BizHawk.Emulation.Common public unsafe int[] GenerateFramebuffer(int*[] src, int[] srcLength) { if (src.Length != LayoutSettings.Locations.Length) - return null; + { + throw new InvalidCastException("Buffer length mismatch"); + } var ret = new int[LayoutSettings.FinalSize.Width * LayoutSettings.FinalSize.Height]; for (int iBuf = 0; iBuf < src.Length; iBuf++) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs index 738e8fbfe7..7cb8074c16 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs @@ -119,7 +119,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS } } - public Point TouchScreenStart => _screenArranger.LayoutSettings.Locations[1]; + public Point? TouchScreenStart => _screenArranger.LayoutSettings.Locations.Length > 1 + ? _screenArranger.LayoutSettings.Locations[1] + : (Point?)null; /// /// MelonDS expects bios and firmware files at a specific location. diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_VideoProvider.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_VideoProvider.cs index 8069567d03..eda13f7df1 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_VideoProvider.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS_VideoProvider.cs @@ -42,9 +42,14 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS { if (_getNewBuffer) { + // Shenanigans + var buffers = _settings.ScreenOptions.NeedsBottomScreen() + ? new[] {GetTopScreenBuffer(), GetBottomScreenBuffer()} + : new[] {GetTopScreenBuffer()}; + _getNewBuffer = false; - int*[] buffers = { GetTopScreenBuffer(), GetBottomScreenBuffer() }; + int bufferSize = GetScreenBufferSize(); _buffer = _screenArranger.GenerateFramebuffer(buffers, new[] { bufferSize, bufferSize }); } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/VIdeoScreenOptions.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/VIdeoScreenOptions.cs index a269bc635e..e8daf6e96e 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/VIdeoScreenOptions.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/VIdeoScreenOptions.cs @@ -5,18 +5,22 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS { public enum VideoScreenOptions { - Default, TopOnly, BottomOnly, SideBySideLR, SideBySideRL /*, Reverse */ + Default, TopOnly, SideBySideLR, SideBySideRL /*, Reverse */ } public static class VideoScreenOptionExtensions { + public static bool NeedsBottomScreen(this VideoScreenOptions option) + { + return option != VideoScreenOptions.TopOnly; + } + 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 @@ -32,37 +36,23 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS 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) + Locations = new[] { new Point(0, 0) }, + Order = new[] { 0 }, + FinalSize = new Size(MelonDS.NativeWidth, MelonDS.NativeHeight) }; private static ScreenLayoutSettings SideBySideLR => new ScreenLayoutSettings { - Locations = new[] { new Point(0, 0), new Point(0, MelonDS.NativeHeight) }, + Locations = new[] { new Point(0, 0), new Point(MelonDS.NativeWidth, MelonDS.NativeHeight) }, Order = new[] { 0, 1 }, - FinalSize = new Size(MelonDS.NativeWidth, MelonDS.NativeHeight * 2) + FinalSize = new Size(MelonDS.NativeWidth * 2, MelonDS.NativeHeight) }; private static ScreenLayoutSettings SideBySideRL => new ScreenLayoutSettings { - Locations = new[] { new Point(0, 0), new Point(0, MelonDS.NativeHeight) }, + Locations = new[] {new Point(MelonDS.NativeWidth, MelonDS.NativeHeight), new Point(0, 0) }, 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) + FinalSize = new Size(MelonDS.NativeWidth * 2, MelonDS.NativeHeight) }; } }