[ChannelFHawk] Add viewport controls as a SyncSetting

This commit is contained in:
ASNiVOR 2024-09-11 13:43:17 +01:00
parent bf8758e61c
commit 58b5f40277
2 changed files with 49 additions and 6 deletions

View File

@ -25,6 +25,19 @@ namespace BizHawk.Emulation.Cores.Consoles.ChannelF
return ret ? PutSettingsDirtyBits.RebootCore : PutSettingsDirtyBits.None;
}
public enum ViewPort
{
/// <summary>
/// View the entire screen minus flyback areas
/// </summary>
AllVisible,
/// <summary>
/// Trimmed viewport for a more centred display
/// </summary>
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();

View File

@ -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;
}
}
/// <summary>
/// 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;
}