From c83fd24a72b14cc38da3ed2ac8ccad5aa48a067f Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sun, 9 Nov 2025 12:03:49 -0600 Subject: [PATCH] feat(console): add ConsoleDetectGetResolutions --- src/console/Detect.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++ src/console/Detect.hpp | 10 ++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/console/Detect.cpp create mode 100644 src/console/Detect.hpp diff --git a/src/console/Detect.cpp b/src/console/Detect.cpp new file mode 100644 index 0000000..d5b3eff --- /dev/null +++ b/src/console/Detect.cpp @@ -0,0 +1,52 @@ +#include "console/Detect.hpp" +#include "gx/Adapter.hpp" + +void AddResolution(TSGrowableArray& resolutions, const C2iVector& resolution) { + resolutions.Add(1, &resolution); +} + +void ConsoleDetectGetResolutions(TSGrowableArray& resolutions, int32_t widescreen) { + // Widescreen resolutions + + if (widescreen) { + TSGrowableArray monitorModes; + GxAdapterMonitorModes(monitorModes); + + C2iVector previousResolution = { 0, 0 }; + + for (uint32_t i = 0; i < monitorModes.Count(); i++) { + auto& monitorMode = monitorModes[i]; + auto& resolution = monitorMode.size; + + // "Widescreen" aspect ratio + if (static_cast(resolution.x) / static_cast(resolution.y) < 1.248f) { + continue; + } + + // At least 640x480 + if (resolution.x < 640 || resolution.y < 480) { + continue; + } + + // Not already present + if (resolution.x == previousResolution.x && resolution.y == previousResolution.y) { + continue; + } + + AddResolution(resolutions, resolution); + previousResolution = resolution; + } + } + + // Fallback resolutions + + if (!widescreen || resolutions.Count() == 0) { + AddResolution(resolutions, { 640, 480 }); + AddResolution(resolutions, { 800, 600 }); + AddResolution(resolutions, { 1024, 768 }); + AddResolution(resolutions, { 1152, 864 }); + AddResolution(resolutions, { 1280, 960 }); + AddResolution(resolutions, { 1280, 1024 }); + AddResolution(resolutions, { 1600, 1200 }); + } +} diff --git a/src/console/Detect.hpp b/src/console/Detect.hpp new file mode 100644 index 0000000..f0d5f75 --- /dev/null +++ b/src/console/Detect.hpp @@ -0,0 +1,10 @@ +#ifndef CONSOLE_DETECT_HPP +#define CONSOLE_DETECT_HPP + +#include +#include +#include + +void ConsoleDetectGetResolutions(TSGrowableArray& resolutions, int32_t widescreen); + +#endif