mirror of
https://github.com/wiiu-env/WiiUPluginLoaderBackend.git
synced 2026-09-21 10:18:43 -05:00
Fix displaying the config menu when using 480i + 4:3 or 576i as output resolution
This commit is contained in:
@@ -2,32 +2,114 @@
|
||||
|
||||
#include "logger.h"
|
||||
#include "utils.h"
|
||||
#include <avm/tv.h>
|
||||
#include <coreinit/cache.h>
|
||||
#include <coreinit/memory.h>
|
||||
#include <coreinit/screen.h>
|
||||
#include <cstdlib>
|
||||
#include <png.h>
|
||||
|
||||
|
||||
// buffer width
|
||||
#define TV_WIDTH 0x500
|
||||
#define DRC_WIDTH 0x380
|
||||
|
||||
bool DrawUtils::isBackBuffer;
|
||||
|
||||
uint8_t *DrawUtils::tvBuffer = nullptr;
|
||||
uint32_t DrawUtils::tvSize = 0;
|
||||
uint8_t *DrawUtils::drcBuffer = nullptr;
|
||||
uint32_t DrawUtils::drcSize = 0;
|
||||
static SFT pFont = {};
|
||||
uint8_t *DrawUtils::tvBuffer = nullptr;
|
||||
uint32_t DrawUtils::tvSize = 0;
|
||||
uint8_t *DrawUtils::drcBuffer = nullptr;
|
||||
uint32_t DrawUtils::drcSize = 0;
|
||||
uint32_t DrawUtils::usedTVWidth = 1280;
|
||||
float DrawUtils::usedTVScale = 1.5f;
|
||||
static SFT pFont = {};
|
||||
|
||||
static Color font_col(0xFFFFFFFF);
|
||||
|
||||
#define __SetDCPitchReg ((void (*)(uint32_t, uint32_t))(0x101C400 + 0x1e714))
|
||||
|
||||
extern "C" uint32_t __OSPhysicalToEffectiveUncached(uint32_t);
|
||||
|
||||
static uint32_t __ReadReg32(uint32_t index) {
|
||||
if (OSIsECOMode()) {
|
||||
return 0;
|
||||
}
|
||||
auto regs = (uint32_t *) __OSPhysicalToEffectiveUncached(0xc200000);
|
||||
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_;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
auto tvScanBufferWidth = __ReadReg32(0x184d + SCREEN_TV * 0x200);
|
||||
|
||||
if (tvScanBufferWidth == 640) { // 480i/480p/576i 4:3
|
||||
DrawUtils::usedTVWidth = 640;
|
||||
__SetDCPitchReg(SCREEN_TV, 640);
|
||||
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 = bigScale ? 1.0 : 1.0f;
|
||||
} else if (tvScanBufferWidth == 1280) { // 720p 16:9
|
||||
DrawUtils::usedTVWidth = 1280;
|
||||
__SetDCPitchReg(SCREEN_TV, 1280);
|
||||
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 = bigScale ? 2.25 : 1.125f;
|
||||
} else {
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
void DrawUtils::beginDraw() {
|
||||
@@ -83,17 +165,10 @@ void DrawUtils::drawPixel(uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t USED_TV_WIDTH = TV_WIDTH;
|
||||
float scale = 1.5f;
|
||||
if (DrawUtils::tvSize == 0x00FD2000) {
|
||||
USED_TV_WIDTH = 1920;
|
||||
scale = 2.25f;
|
||||
}
|
||||
|
||||
// scale and put pixel in the tv buffer
|
||||
for (uint32_t yy = (y * scale); yy < ((y * scale) + (uint32_t) scale); yy++) {
|
||||
for (uint32_t xx = (x * scale); xx < ((x * scale) + (uint32_t) scale); xx++) {
|
||||
uint32_t i = (xx + yy * USED_TV_WIDTH) * 4;
|
||||
for (uint32_t yy = (y * DrawUtils::usedTVScale); yy < ((y * DrawUtils::usedTVScale) + (uint32_t) DrawUtils::usedTVScale); yy++) {
|
||||
for (uint32_t xx = (x * DrawUtils::usedTVScale); xx < ((x * DrawUtils::usedTVScale) + (uint32_t) DrawUtils::usedTVScale); xx++) {
|
||||
uint32_t i = (xx + yy * DrawUtils::usedTVWidth) * 4;
|
||||
if (i + 3 < tvSize / 2) {
|
||||
if (isBackBuffer) {
|
||||
i += tvSize / 2;
|
||||
|
||||
Reference in New Issue
Block a user