Skip to content

Commit 58b5f40

Browse files
committed
[ChannelFHawk] Add viewport controls as a SyncSetting
1 parent bf8758e commit 58b5f40

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.ISettable.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ public PutSettingsDirtyBits PutSyncSettings(ChannelFSyncSettings o)
2525
return ret ? PutSettingsDirtyBits.RebootCore : PutSettingsDirtyBits.None;
2626
}
2727

28+
29+
public enum ViewPort
30+
{
31+
/// <summary>
32+
/// View the entire screen minus flyback areas
33+
/// </summary>
34+
AllVisible,
35+
/// <summary>
36+
/// Trimmed viewport for a more centred display
37+
/// </summary>
38+
Trimmed
39+
}
40+
2841
public enum RegionType
2942
{
3043
NTSC,
@@ -50,6 +63,11 @@ public class ChannelFSyncSettings
5063
[DefaultValue(ConsoleVersion.ChannelF)]
5164
public ConsoleVersion Version { get; set; }
5265

66+
[DisplayName("Viewport")]
67+
[Description("Visable screen area (cropping options)")]
68+
[DefaultValue(ViewPort.Trimmed)]
69+
public ViewPort Viewport { get; set; }
70+
5371
public ChannelFSyncSettings Clone()
5472
=> (ChannelFSyncSettings)MemberwiseClone();
5573

src/BizHawk.Emulation.Cores/Consoles/Fairchild/ChannelF/ChannelF.IVideoProvider.cs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,36 @@ public partial class ChannelF : IVideoProvider, IRegionable
5151
private double PixelClocksPerCpuClock;
5252
private double PixelClocksPerFrame;
5353

54+
private int HDisplayable => HBlankOn - HBlankOff - TrimLeft - TrimRight;
55+
private int VDisplayable => VBlankOn - VBlankOff - TrimTop - TrimBottom;
56+
57+
private int TrimLeft;
58+
private int TrimRight;
59+
private int TrimTop;
60+
private int TrimBottom;
61+
5462
private void SetupVideo()
55-
=> _videoBuffer = new int[HTotal * VTotal];
63+
{
64+
_videoBuffer = new int[HTotal * VTotal];
65+
66+
switch (_syncSettings.Viewport)
67+
{
68+
case ViewPort.AllVisible:
69+
TrimLeft = 0;
70+
TrimRight = 0;
71+
TrimTop = 0;
72+
TrimBottom = 0;
73+
break;
74+
75+
case ViewPort.Trimmed:
76+
// https://channelf.se/veswiki/index.php?title=VRAM
77+
TrimLeft = 0;
78+
TrimRight = HBlankOn - HBlankOff - (95 * PixelWidth);
79+
TrimTop = 0;
80+
TrimBottom = 0;
81+
break;
82+
}
83+
}
5684

5785
/// <summary>
5886
/// Called after every CPU clock
@@ -97,10 +125,7 @@ private void ClockVideo()
97125
{
98126
_pixelClockCounter -= PixelClocksPerFrame;
99127
}
100-
}
101-
102-
private int HDisplayable => HBlankOn - HBlankOff;
103-
private int VDisplayable => VBlankOn - VBlankOff;
128+
}
104129

105130
private static int[] ClampBuffer(int[] buffer, int originalWidth, int originalHeight, int trimLeft, int trimTop, int trimRight, int trimBottom)
106131
{
@@ -147,7 +172,7 @@ private static double GetVerticalModifier(int bufferWidth, int bufferHeight, dou
147172
// VirtualWidth is being used to force the aspect ratio into 4:3
148173
// On real hardware it looks like this (so we are close): https://www.youtube.com/watch?v=ZvQA9tiEIuQ
149174
public int[] GetVideoBuffer()
150-
=> ClampBuffer(_videoBuffer, HTotal, VTotal, HBlankOff, VBlankOff, HTotal - HBlankOn, VTotal - VBlankOn);
175+
=> ClampBuffer(_videoBuffer, HTotal, VTotal, HBlankOff + TrimLeft, VBlankOff + TrimTop, HTotal - HBlankOn + TrimRight, VTotal - VBlankOn + TrimBottom);
151176

152177
public DisplayType Region => _region == RegionType.NTSC ? DisplayType.NTSC : DisplayType.PAL;
153178
}

0 commit comments

Comments
 (0)