From 58b5f402770620c648401fea67a9716fdba79244 Mon Sep 17 00:00:00 2001 From: ASNiVOR Date: Wed, 11 Sep 2024 13:43:17 +0100 Subject: [PATCH] [ChannelFHawk] Add viewport controls as a SyncSetting --- .../Fairchild/ChannelF/ChannelF.ISettable.cs | 18 +++++++++ .../ChannelF/ChannelF.IVideoProvider.cs | 37 ++++++++++++++++--- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.ISettable.cs b/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.ISettable.cs index 98af9cd565..1a7d2daa5c 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.ISettable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.ISettable.cs @@ -25,6 +25,19 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF return ret ? PutSettingsDirtyBits.RebootCore : PutSettingsDirtyBits.None; } + + public enum ViewPort + { + /// + /// View the entire screen minus flyback areas + /// + AllVisible, + /// + /// Trimmed viewport for a more centred display + /// + Trimmed + } + public enum RegionType { NTSC, @@ -50,6 +63,11 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF [DefaultValue(ConsoleVersion.ChannelF)] public ConsoleVersion Version { get; set; } + [DisplayName("Viewport")] + [Description("Visable screen area (cropping options)")] + [DefaultValue(ViewPort.Trimmed)] + public ViewPort Viewport { get; set; } + public ChannelFSyncSettings Clone() => (ChannelFSyncSettings)MemberwiseClone(); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.IVideoProvider.cs b/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.IVideoProvider.cs index d0f9e677ba..b097bf267d 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.IVideoProvider.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.IVideoProvider.cs @@ -51,8 +51,36 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF private double PixelClocksPerCpuClock; private double PixelClocksPerFrame; + private int HDisplayable => HBlankOn - HBlankOff - TrimLeft - TrimRight; + private int VDisplayable => VBlankOn - VBlankOff - TrimTop - TrimBottom; + + private int TrimLeft; + private int TrimRight; + private int TrimTop; + private int TrimBottom; + private void SetupVideo() - => _videoBuffer = new int[HTotal * VTotal]; + { + _videoBuffer = new int[HTotal * VTotal]; + + switch (_syncSettings.Viewport) + { + case ViewPort.AllVisible: + TrimLeft = 0; + TrimRight = 0; + TrimTop = 0; + TrimBottom = 0; + break; + + case ViewPort.Trimmed: + // https://channelf.se/veswiki/index.php?title=VRAM + TrimLeft = 0; + TrimRight = HBlankOn - HBlankOff - (95 * PixelWidth); + TrimTop = 0; + TrimBottom = 0; + break; + } + } /// /// Called after every CPU clock @@ -97,10 +125,7 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF { _pixelClockCounter -= PixelClocksPerFrame; } - } - - private int HDisplayable => HBlankOn - HBlankOff; - private int VDisplayable => VBlankOn - VBlankOff; + } private static int[] ClampBuffer(int[] buffer, int originalWidth, int originalHeight, int trimLeft, int trimTop, int trimRight, int trimBottom) { @@ -147,7 +172,7 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF // VirtualWidth is being used to force the aspect ratio into 4:3 // On real hardware it looks like this (so we are close): https://www.youtube.com/watch?v=ZvQA9tiEIuQ public int[] GetVideoBuffer() - => ClampBuffer(_videoBuffer, HTotal, VTotal, HBlankOff, VBlankOff, HTotal - HBlankOn, VTotal - VBlankOn); + => ClampBuffer(_videoBuffer, HTotal, VTotal, HBlankOff + TrimLeft, VBlankOff + TrimTop, HTotal - HBlankOn + TrimRight, VTotal - VBlankOn + TrimBottom); public DisplayType Region => _region == RegionType.NTSC ? DisplayType.NTSC : DisplayType.PAL; }