Skip to content

Commit

Permalink
Fix HDMI resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed May 10, 2024
1 parent a29787d commit 08a6dfc
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 16 deletions.
70 changes: 55 additions & 15 deletions source/utils/DrawUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "DrawUtils.h"

#include "globals.h"
#include "logger.h"
#include "utils.h"
#include <avm/tv.h>
Expand All @@ -10,7 +9,6 @@
#include <cstdlib>
#include <png.h>


// buffer width
#define DRC_WIDTH 0x380

Expand All @@ -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);
Expand All @@ -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");
}
Expand Down
1 change: 0 additions & 1 deletion source/utils/config/ConfigUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ void ConfigUtils::openConfigMenu() {
__WriteReg32(0x1848 + SCREEN_DRC * 0x200, drcPitch1);
__WriteReg32(0x1866 + SCREEN_DRC * 0x200, drcPitch2);


if (!skipScreen0Free && screenbuffer0) {
MEMFreeToMappedMemory(screenbuffer0);
}
Expand Down

0 comments on commit 08a6dfc

Please # to comment.