Skip to content

Commit 53962cd

Browse files
Add crop overscan option
This option fixes NTSC video output for CRT displays by cropping the 528-line EFB to standard 480i/p resolution.
1 parent 5547873 commit 53962cd

File tree

6 files changed

+54
-4
lines changed

6 files changed

+54
-4
lines changed

Source/Core/Common/DirectIOFile.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ bool DirectIOFile::Open(const std::string& path, AccessMode access_mode, OpenMod
8989
// Allow deleting and renaming through our handle.
9090
desired_access |= DELETE;
9191

92+
#ifdef __LIBRETRO__
93+
// The DELETE flag prevents the Libretro implementation of RetroAchievements from
94+
// opening the file so make sure only GENERIC_READ is set when we're in read mode.
95+
if (access_mode == AccessMode::Read)
96+
desired_access = GENERIC_READ;
97+
#endif
98+
9299
// All sharing is allowed to more closely match default behavior on other OSes.
93100
constexpr DWORD share_mode = FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE;
94101

Source/Core/DolphinLibretro/Boot.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "Common/CommonPaths.h"
88
#include "Common/FileUtil.h"
9+
#include "Common/Version.h"
910
#include "Core/Boot/Boot.h"
1011
#include "Core/BootManager.h"
1112
#include "Core/Config/GraphicsSettings.h"
@@ -103,6 +104,7 @@ bool retro_load_game(const struct retro_game_info* game)
103104
return true; // Always "continue"
104105
});
105106

107+
INFO_LOG_FMT(COMMON, "SCM Git revision: {}", Common::GetScmRevGitStr());
106108
INFO_LOG_FMT(COMMON, "User Directory set to '{}'", user_dir);
107109
INFO_LOG_FMT(COMMON, "System Directory set to '{}'", sys_dir);
108110

Source/Core/DolphinLibretro/Common/Options.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,20 @@ static struct retro_core_option_v2_definition option_defs[] = {
563563
},
564564
"disabled"
565565
},
566+
{
567+
Libretro::Options::gfx_settings::CROP_OVERSCAN,
568+
"Graphics > Settings > Crop Overscan",
569+
"Crop Overscan",
570+
"Crop overscan to match standard NTSC output resolutions. Recommended for NTSC CRTs.",
571+
nullptr,
572+
CATEGORY_GFX_SETTINGS,
573+
{
574+
{ "disabled", nullptr },
575+
{ "enabled", nullptr },
576+
{ nullptr, nullptr }
577+
},
578+
"disabled"
579+
},
566580
{
567581
Libretro::Options::gfx_settings::EFB_SCALE,
568582
"Graphics > Settings > Internal Resolution",

Source/Core/DolphinLibretro/Common/Options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ namespace gfx_hardware {
182182
namespace gfx_settings {
183183
constexpr const char RENDERER[] = "dolphin_renderer";
184184
constexpr const char WIDESCREEN_HACK[] = "dolphin_widescreen_hack";
185+
constexpr const char CROP_OVERSCAN[] = "dolphin_crop_overscan";
185186
constexpr const char EFB_SCALE[] = "dolphin_efb_scale";
186187
constexpr const char SHADER_COMPILATION_MODE[] = "dolphin_shader_compilation_mode";
187188
constexpr const char WAIT_FOR_SHADERS[] = "dolphin_wait_for_shaders";

Source/Core/DolphinLibretro/Main.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,15 @@ void retro_get_system_av_info(retro_system_av_info* info)
102102
int efbScale = Libretro::Options::GetCached<int>(
103103
Libretro::Options::gfx_settings::EFB_SCALE);
104104

105+
int base_height = EFB_HEIGHT;
106+
const bool crop_overscan = Libretro::Options::GetCached<bool>(
107+
Libretro::Options::gfx_settings::CROP_OVERSCAN);
108+
109+
if (crop_overscan && retro_get_region() == RETRO_REGION_NTSC)
110+
base_height = 480;
111+
105112
info->geometry.base_width = EFB_WIDTH * efbScale;
106-
info->geometry.base_height = EFB_HEIGHT * efbScale;
113+
info->geometry.base_height = base_height * efbScale;
107114

108115
info->geometry.max_width = info->geometry.base_width;
109116
info->geometry.max_height = info->geometry.base_height;
@@ -142,6 +149,14 @@ void retro_run(void)
142149
g_Config.bWidescreenHack = Libretro::Options::GetCached<bool>(
143150
Libretro::Options::gfx_settings::WIDESCREEN_HACK);
144151

152+
const bool crop_overscan = Libretro::Options::GetCached<bool>(
153+
Libretro::Options::gfx_settings::CROP_OVERSCAN);
154+
155+
if (crop_overscan && retro_get_region() == RETRO_REGION_NTSC)
156+
g_Config.bCrop = true;
157+
else
158+
g_Config.bCrop = false;
159+
145160
Libretro::Input::Update();
146161

147162
Core::System& system = Core::System::GetInstance();

Source/Core/DolphinLibretro/Video.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ static Common::DynamicLibrary d3d11_library;
6565
static Common::DynamicLibrary d3d12_library;
6666
#endif
6767

68+
static int GetAdjustedBaseHeight()
69+
{
70+
const bool crop_overscan = Libretro::Options::GetCached<bool>(
71+
Libretro::Options::gfx_settings::CROP_OVERSCAN);
72+
73+
if (crop_overscan && retro_get_region() == RETRO_REGION_NTSC)
74+
return 480;
75+
76+
return EFB_HEIGHT;
77+
}
78+
6879
void Init()
6980
{
7081
DEBUG_LOG_FMT(VIDEO, "Video - Init");
@@ -239,7 +250,7 @@ void ContextReset(void)
239250
int efbScale = Libretro::Options::GetCached<int>(
240251
Libretro::Options::gfx_settings::EFB_SCALE, 1);
241252
Vk::SetSurfaceSize(EFB_WIDTH * efbScale,
242-
EFB_HEIGHT * efbScale);
253+
GetAdjustedBaseHeight() * efbScale);
243254
}
244255
#endif
245256

@@ -296,7 +307,7 @@ void ContextReset(void)
296307
UpdateActiveConfig();
297308

298309
std::unique_ptr<DX11SwapChain> swap_chain = std::make_unique<DX11SwapChain>(
299-
wsi, EFB_WIDTH * efbScale, EFB_HEIGHT * efbScale,
310+
wsi, EFB_WIDTH * efbScale, GetAdjustedBaseHeight() * efbScale,
300311
nullptr, nullptr);
301312

302313
auto gfx = std::make_unique<DX11::Gfx>(std::move(swap_chain), wsi.render_surface_scale);
@@ -373,7 +384,7 @@ void ContextReset(void)
373384
UpdateActiveConfig();
374385

375386
auto swap_chain = std::make_unique<DX12SwapChain>(
376-
wsi, EFB_WIDTH * efbScale, EFB_HEIGHT * efbScale, d3d12);
387+
wsi, EFB_WIDTH * efbScale, GetAdjustedBaseHeight() * efbScale, d3d12);
377388

378389
if (!swap_chain->Initialize())
379390
{

0 commit comments

Comments
 (0)