From 58c09c9124649a03e41033523e7872ef6dedd7f1 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Tue, 16 Feb 2016 01:13:27 -0800 Subject: [PATCH] 3DS: Auto-fit aspect ratios --- src/platform/3ds/main.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/platform/3ds/main.c b/src/platform/3ds/main.c index 5a3c30529..28ab8d495 100644 --- a/src/platform/3ds/main.c +++ b/src/platform/3ds/main.c @@ -337,7 +337,17 @@ static void _drawTex(struct mCore* core, bool faded) { unsigned corew, coreh; core->desiredVideoDimensions(core, &corew, &coreh); - int w, h; + int w = corew; + int h = coreh; + // Get greatest common divisor + while (w != 0) { + int temp = h % w; + h = w; + w = temp; + } + int gcd = h; + int aspectw = corew / gcd; + int aspecth = coreh / gcd; switch (screenMode) { case SM_PA_TOP: @@ -347,13 +357,16 @@ static void _drawTex(struct mCore* core, bool faded) { h = coreh; break; case SM_AF_TOP: - w = 360; - h = 240; - break; case SM_AF_BOTTOM: - // Largest possible size with 3:2 aspect ratio and integer dimensions - w = 318; - h = 212; + w = screen_w / aspectw; + h = screen_h / aspecth; + if (w * aspecth > screen_h) { + w = aspectw * h; + h = aspecth * h; + } else { + h = aspecth * w; + w = aspectw * w; + } break; case SM_SF_TOP: case SM_SF_BOTTOM: