diff --git a/source/utils/DrawUtils.cpp b/source/utils/DrawUtils.cpp index e7cd9e0..8e88c8c 100644 --- a/source/utils/DrawUtils.cpp +++ b/source/utils/DrawUtils.cpp @@ -1,6 +1,5 @@ #include "DrawUtils.h" -#include "globals.h" #include "logger.h" #include "utils.h" #include @@ -10,7 +9,6 @@ #include #include - // buffer width #define DRC_WIDTH 0x380 @@ -26,7 +24,6 @@ static SFT pFont = {}; static Color font_col(0xFFFFFFFF); - #define __SetDCPitchReg ((void (*)(uint32_t, uint32_t))(0x101C400 + 0x1e714)) extern "C" uint32_t __OSPhysicalToEffectiveUncached(uint32_t); @@ -39,34 +36,77 @@ static uint32_t __ReadReg32(uint32_t index) { return regs[index]; } - void DrawUtils::initBuffers(void *tvBuffer_, uint32_t tvSize_, void *drcBuffer_, uint32_t drcSize_) { DrawUtils::tvBuffer = (uint8_t *) tvBuffer_; DrawUtils::tvSize = tvSize_; DrawUtils::drcBuffer = (uint8_t *) drcBuffer_; DrawUtils::drcSize = drcSize_; - auto tv_width = __ReadReg32(0x184d + SCREEN_TV * 0x200); + bool bigScale = true; + switch (TVEGetCurrentPort()) { + case TVE_PORT_HDMI: + bigScale = true; + break; + case TVE_PORT_COMPONENT: + case TVE_PORT_COMPOSITE: + case TVE_PORT_SCART: + bigScale = false; + break; + } + + AVMTvResolution tvResolution = AVM_TV_RESOLUTION_720P; + if (AVMGetTVScanMode(&tvResolution)) { + switch (tvResolution) { + case AVM_TV_RESOLUTION_480P: + case AVM_TV_RESOLUTION_720P: + case AVM_TV_RESOLUTION_720P_3D: + case AVM_TV_RESOLUTION_1080I: + case AVM_TV_RESOLUTION_1080P: + case AVM_TV_RESOLUTION_576P: + case AVM_TV_RESOLUTION_720P_50HZ: + case AVM_TV_RESOLUTION_1080I_50HZ: + case AVM_TV_RESOLUTION_1080P_50HZ: + bigScale = true; + break; + case AVM_TV_RESOLUTION_576I: + case AVM_TV_RESOLUTION_480I: + case AVM_TV_RESOLUTION_480I_PAL60: + break; + } + } - if (tv_width == 640) { + auto tvScanBufferWidth = __ReadReg32(0x184d + SCREEN_TV * 0x200); + + if (tvScanBufferWidth == 640) { // 480i/480p/576i 4:3 DrawUtils::usedTVWidth = 640; __SetDCPitchReg(SCREEN_TV, 640); - DrawUtils::usedTVScale = 0.75f; - } else if (tv_width == 854) { + DrawUtils::usedTVScale = bigScale ? 0.75 : 0.75f; + } else if (tvScanBufferWidth == 854) { // 480i/480p/576i 16:9 DrawUtils::usedTVWidth = 896; __SetDCPitchReg(SCREEN_TV, 896); - DrawUtils::usedTVScale = 1.0f; - } else if (tv_width == 1280) { + DrawUtils::usedTVScale = bigScale ? 1.0 : 1.0f; + } else if (tvScanBufferWidth == 1280) { // 720p 16:9 DrawUtils::usedTVWidth = 1280; __SetDCPitchReg(SCREEN_TV, 1280); - DrawUtils::usedTVScale = 0.75f; - } else if (tv_width == 1920) { + if (bigScale) { + DrawUtils::usedTVScale = 1.5; + } else { + DrawUtils::usedTVScale = 0.75f; + if (tvResolution == AVM_TV_RESOLUTION_480I_PAL60 || tvResolution == AVM_TV_RESOLUTION_480I) { + AVMTvAspectRatio tvAspectRatio; + if (AVMGetTVAspectRatio(&tvAspectRatio) && tvAspectRatio == AVM_TV_ASPECT_RATIO_16_9) { + DEBUG_FUNCTION_LINE_WARN("force big scaling for 480i + 16:9"); + DrawUtils::usedTVScale = 1.5; + } + } + } + } else if (tvScanBufferWidth == 1920) { // 1080i/1080p 16:9 DrawUtils::usedTVWidth = 1920; __SetDCPitchReg(SCREEN_TV, 1920); - DrawUtils::usedTVScale = 1.125f; + DrawUtils::usedTVScale = bigScale ? 2.25 : 1.125f; } else { - DrawUtils::usedTVWidth = tv_width; - __SetDCPitchReg(SCREEN_TV, tv_width); + DrawUtils::usedTVWidth = tvScanBufferWidth; + __SetDCPitchReg(SCREEN_TV, tvScanBufferWidth); DrawUtils::usedTVScale = 1.0f; DEBUG_FUNCTION_LINE_WARN("Unknown tv width detected, config menu might not show properly"); } diff --git a/source/utils/config/ConfigUtils.cpp b/source/utils/config/ConfigUtils.cpp index 4ebee37..f355023 100644 --- a/source/utils/config/ConfigUtils.cpp +++ b/source/utils/config/ConfigUtils.cpp @@ -354,7 +354,6 @@ void ConfigUtils::openConfigMenu() { __WriteReg32(0x1848 + SCREEN_DRC * 0x200, drcPitch1); __WriteReg32(0x1866 + SCREEN_DRC * 0x200, drcPitch2); - if (!skipScreen0Free && screenbuffer0) { MEMFreeToMappedMemory(screenbuffer0); }