Skip to content

Commit

Permalink
- Add option to optimize display for the RetroTINK-4K.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Mar 26, 2024
1 parent 52e0c30 commit 5e3c515
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 11 deletions.
3 changes: 3 additions & 0 deletions cube/swiss/include/patcher.h
Expand Up @@ -132,6 +132,8 @@ extern u8 VIConfigureHook1[];
extern u32 VIConfigureHook1_length;
extern u8 VIConfigureHook1GCVideo[];
extern u32 VIConfigureHook1GCVideo_length;
extern u8 VIConfigureHook1RT4K[];
extern u32 VIConfigureHook1RT4K_length;
extern u8 VIConfigureHook2[];
extern u32 VIConfigureHook2_length;
extern u8 VIConfigurePanHook[];
Expand Down Expand Up @@ -173,6 +175,7 @@ enum patchIds {
VI_CONFIGUREAUTOP,
VI_CONFIGUREHOOK1,
VI_CONFIGUREHOOK1_GCVIDEO,
VI_CONFIGUREHOOK1_RT4K,
VI_CONFIGUREHOOK2,
VI_CONFIGUREPANHOOK,
VI_CONFIGUREPANHOOKD,
Expand Down
1 change: 1 addition & 0 deletions cube/swiss/include/swiss.h
Expand Up @@ -141,6 +141,7 @@ typedef struct {
int igrType;
int initNetworkAtStart;
int aveCompat;
int rt4kOptim;
u8 configDeviceId; // see deviceHandler.h
int fileBrowserType;
int bs2Boot;
Expand Down
1 change: 1 addition & 0 deletions cube/swiss/include/video.h
Expand Up @@ -7,6 +7,7 @@

extern u32 *xfb[2];
extern int whichfb;
void updateVideoMode(GXRModeObj *m);
void setVideoMode(GXRModeObj *m);
char* getVideoModeString();
GXRModeObj* getVideoMode();
Expand Down
4 changes: 4 additions & 0 deletions cube/swiss/source/config/config.c
Expand Up @@ -165,6 +165,7 @@ int config_update_global(bool checkConfigDevice) {
fprintf(fp, "InitNetwork=%s\r\n", swissSettings.initNetworkAtStart ? "Yes":"No");
fprintf(fp, "IGRType=%s\r\n", igrTypeStr[swissSettings.igrType]);
fprintf(fp, "AVECompat=%s\r\n", aveCompatStr[swissSettings.aveCompat]);
fprintf(fp, "RT4KOptim=%s\r\n", swissSettings.rt4kOptim ? "Yes":"No");
fprintf(fp, "FileBrowserType=%s\r\n", fileBrowserStr[swissSettings.fileBrowserType]);
fprintf(fp, "BS2Boot=%s\r\n", bs2BootStr[swissSettings.bs2Boot]);
fprintf(fp, "FTPUserName=%s\r\n", swissSettings.ftpUserName);
Expand Down Expand Up @@ -812,6 +813,9 @@ void config_parse_global(char *configData) {
}
}
}
else if(!strcmp("RT4KOptim", name)) {
swissSettings.rt4kOptim = !strcmp("Yes", value);
}
else if(!strcmp("FileBrowserType", name)) {
for(int i = 0; i < 3; i++) {
if(!strcmp(fileBrowserStr[i], value)) {
Expand Down
3 changes: 3 additions & 0 deletions cube/swiss/source/gui/FrameBufferMagic.c
Expand Up @@ -2287,5 +2287,8 @@ void DrawVideoMode(GXRModeObj *videoMode)
if(getVideoMode() != videoMode) {
setVideoMode(videoMode);
}
else {
updateVideoMode(videoMode);
}
LWP_MutexUnlock(_videomutex);
}
14 changes: 11 additions & 3 deletions cube/swiss/source/gui/settings.c
Expand Up @@ -60,8 +60,9 @@ static char *tooltips_global[PAGE_GLOBAL_MAX+1] = {
"Flatten directory:\n\nFlattens a directory structure matching a glob pattern.",
"Stop DVD Motor at startup:\n\nDisabled - Leave it as-is (default)\nEnabled - Stop the DVD drive from spinning when Swiss starts\n\nThis option is mostly for users booting from game\nexploits where the disc will already be spinning.",
"SD/IDE Speed:\n\nThe speed to try and use on the EXI bus for SD Card Adapters or IDE-EXI devices.\n32 MHz may not work on some SD cards.",
"AVE Compatibility:\n\nSets the compatibility mode for the used audio/video encoder.\n\nAVE N-DOL - Output PAL as NTSC 50\nAVE P-DOL - Disable progressive scan mode\nCMPV-DOL - Enable 1080i & 540p\nGCVideo - Apply firmware workarounds for GCVideo (default)\nAVE-RVL - Support 960i & 1152i without WiiVideo",
"Force DTV Status:\n\nDisabled - Use signal from the video interface (default)\nEnabled - Force on in case of hardware fault",
"AVE Compatibility:\n\nSets the compatibility mode for the used audio/video encoder.\n\nAVE N-DOL - Output PAL as NTSC 50\nAVE P-DOL - Disable progressive scan mode\nCMPV-DOL - Enable 1080i & 540p\nGCVideo - Apply general workarounds for GCVideo (default)\nAVE-RVL - Support 960i & 1152i without WiiVideo",
"Force DTV Status:\n\nDisabled - Use detect signal from the Digital AV Out (default)\nEnabled - Force detection in the case of a hardware fault",
"Optimise for RetroTINK-4K:\n\nRequires GCVideo-DVI v3.0 or later with Fix Resolution Off.",
"Enable USB Gecko debug output:\n\nIf a USB Gecko is present in slot B, debug output from\nSwiss & in game (if the game supported output over OSReport)\nwill be output. If nothing is reading the data out from the\ndevice it may cause Swiss/games to hang."
};

Expand All @@ -75,7 +76,7 @@ static char *tooltips_game_global[PAGE_GAME_GLOBAL_MAX+1] = {
NULL,
NULL,
NULL,
NULL,
"Force Video Active:\n\nA workaround for GCVideo-DVI v3.0 series, obsoleted by 3.1.",
NULL,
"Pause for resolution change:\n\nWhen enabled, a change in active video resolution will pause\nthe game for 2 seconds.",
"Auto-load all cheats:\n\nIf enabled, and a cheats file for a particular game is found\ne.g. /swiss/cheats/GPOP8D.txt (on a compatible device)\nthen all cheats in the file will be enabled",
Expand Down Expand Up @@ -244,6 +245,7 @@ uiDrawObj_t* settings_draw_page(int page_num, int option, ConfigEntry *gameConfi
DrawAddChild(page, DrawVertScrollBar(getVideoMode()->fbWidth-45, page_y_ofs, 25, scrollBarHeight, (float)((float)option/(float)(SET_PAGE_1_NEXT-1)),scrollBarTabHeight));
DrawAddChild(page, DrawLabel(page_x_ofs_key, 65, "Global Settings (1/5):"));
bool dtvEnable = swissSettings.aveCompat < 3;
bool rt4kEnable = swissSettings.aveCompat == 1;
bool dbgEnable = devices[DEVICE_CUR] != &__device_usbgecko && deviceHandler_getDeviceAvailable(&__device_usbgecko);
// TODO settings to a new typedef that ties type etc all together, then draw a "page" of these rather than this at some point.
if(option < SET_STOP_MOTOR) {
Expand All @@ -264,6 +266,7 @@ uiDrawObj_t* settings_draw_page(int page_num, int option, ConfigEntry *gameConfi
drawSettingEntryString(page, &page_y_ofs, "SD/IDE Speed:", swissSettings.exiSpeed ? "32 MHz":"16 MHz", option == SET_EXI_SPEED, true);
drawSettingEntryString(page, &page_y_ofs, "AVE Compatibility:", aveCompatStr[swissSettings.aveCompat], option == SET_AVE_COMPAT, true);
drawSettingEntryBoolean(page, &page_y_ofs, "Force DTV Status:", swissSettings.forceDTVStatus, option == SET_FORCE_DTVSTATUS, dtvEnable);
drawSettingEntryBoolean(page, &page_y_ofs, "Optimise for RetroTINK-4K:", swissSettings.rt4kOptim, option == SET_RT4K_OPTIM, rt4kEnable);
drawSettingEntryBoolean(page, &page_y_ofs, "USB Gecko debug output:", swissSettings.debugUSB, option == SET_ENABLE_USBGECKODBG, dbgEnable);
}
}
Expand Down Expand Up @@ -517,6 +520,10 @@ void settings_toggle(int page, int option, int direction, ConfigEntry *gameConfi
if(swissSettings.aveCompat < 3)
swissSettings.forceDTVStatus ^= 1;
break;
case SET_RT4K_OPTIM:
if(swissSettings.aveCompat == 1)
swissSettings.rt4kOptim ^= 1;
break;
case SET_ENABLE_USBGECKODBG:
if(devices[DEVICE_CUR] != &__device_usbgecko && deviceHandler_getDeviceAvailable(&__device_usbgecko))
swissSettings.debugUSB ^= 1;
Expand All @@ -526,6 +533,7 @@ void settings_toggle(int page, int option, int direction, ConfigEntry *gameConfi
case SET_SWISS_VIDEOMODE:
case SET_AVE_COMPAT:
case SET_FORCE_DTVSTATUS:
case SET_RT4K_OPTIM:
{
// Change Swiss video mode if it was modified.
GXRModeObj *forcedMode = getVideoModeFromSwissSetting(swissSettings.uiVMode);
Expand Down
1 change: 1 addition & 0 deletions cube/swiss/source/gui/settings.h
Expand Up @@ -36,6 +36,7 @@ enum SETTINGS_GLOBAL {
SET_EXI_SPEED,
SET_AVE_COMPAT,
SET_FORCE_DTVSTATUS,
SET_RT4K_OPTIM,
SET_ENABLE_USBGECKODBG,
SET_PAGE_1_NEXT,
SET_PAGE_1_SAVE,
Expand Down
12 changes: 9 additions & 3 deletions cube/swiss/source/patcher.c
Expand Up @@ -91,6 +91,8 @@ void *installPatch(int patchId) {
patch = VIConfigureHook1; patchSize = VIConfigureHook1_length; break;
case VI_CONFIGUREHOOK1_GCVIDEO:
patch = VIConfigureHook1GCVideo; patchSize = VIConfigureHook1GCVideo_length; break;
case VI_CONFIGUREHOOK1_RT4K:
patch = VIConfigureHook1RT4K; patchSize = VIConfigureHook1RT4K_length; break;
case VI_CONFIGUREHOOK2:
patch = VIConfigureHook2; patchSize = VIConfigureHook2_length; break;
case VI_CONFIGUREPANHOOK:
Expand Down Expand Up @@ -9444,9 +9446,13 @@ void Patch_Video(u32 *data, u32 length, int dataType)

if (VIConfigure) {
VIConfigureHook2 = getPatchAddr(VI_CONFIGUREHOOK2);
if (swissSettings.aveCompat == 1)
VIConfigureHook1 = getPatchAddr(VI_CONFIGUREHOOK1_GCVIDEO);
else

if (swissSettings.aveCompat == 1) {
if (swissSettings.rt4kOptim)
VIConfigureHook1 = getPatchAddr(VI_CONFIGUREHOOK1_RT4K);
else
VIConfigureHook1 = getPatchAddr(VI_CONFIGUREHOOK1_GCVIDEO);
} else
VIConfigureHook1 = getPatchAddr(VI_CONFIGUREHOOK1);

switch (swissSettings.gameVMode) {
Expand Down
29 changes: 29 additions & 0 deletions cube/swiss/source/patches/vi/VIConfigureHook1RT4K.s
@@ -0,0 +1,29 @@
#include "reservedarea.h"

.globl VIConfigureHook1RT4K
VIConfigureHook1RT4K:
li %r0, 0
lhz %r6, 4 (%r3)
subfic %r5, %r6, 720
srwi %r5, %r5, 1
sth %r0, 12 (%r3)
sth %r5, 18 (%r3)
sth %r6, 20 (%r3)
lis %r4, VAR_AREA
stw %r3, VAR_RMODE (%r4)
lbz %r0, VAR_VFILTER_ON (%r4)
cmpwi %r0, 0
beq 5f
addi %r4, %r4, VAR_VFILTER
addi %r3, %r3, 50
lswi %r5, %r4, 7
stswi %r5, %r3, 7
5: mfmsr %r3
rlwinm %r4, %r3, 0, 17, 15
extrwi %r3, %r3, 1, 16
mtmsr %r4
blr

.globl VIConfigureHook1RT4K_length
VIConfigureHook1RT4K_length:
.long (VIConfigureHook1RT4K_length - VIConfigureHook1RT4K)
22 changes: 17 additions & 5 deletions cube/swiss/source/video.c
Expand Up @@ -85,7 +85,9 @@ int getScanMode() {
}

int getDTVStatus() {
if(!in_range(swissSettings.aveCompat, 3, 4)) {
if(swissSettings.aveCompat == 1 && swissSettings.rt4kOptim) {
return 1;
} else if(!in_range(swissSettings.aveCompat , 3, 4)) {
volatile unsigned short* vireg = (volatile unsigned short*)0xCC002000;
return (vireg[55] & 1) || swissSettings.forceDTVStatus;
}
Expand Down Expand Up @@ -164,7 +166,7 @@ GXRModeObj* getVideoMode() {
return vmode;
}

void setVideoMode(GXRModeObj *m) {
void updateVideoMode(GXRModeObj *m) {
if(swissSettings.aveCompat == 3) {
switch(m->viTVMode) {
case VI_TVMODE_PAL_INT: m->viTVMode = VI_TVMODE_DEBUG_PAL_INT; break;
Expand All @@ -176,9 +178,19 @@ void setVideoMode(GXRModeObj *m) {
case VI_TVMODE_DEBUG_PAL_DS: m->viTVMode = VI_TVMODE_PAL_DS; break;
}
}
m->viWidth = 704;
m->viXOrigin = 8;
if(swissSettings.aveCompat == 1 && swissSettings.rt4kOptim) {
m->viWidth = m->fbWidth;
m->viXOrigin = 40;
} else {
m->viWidth = 704;
m->viXOrigin = 8;
}
VIDEO_Configure (m);
VIDEO_Flush ();
}

void setVideoMode(GXRModeObj *m) {
updateVideoMode(m);
if(xfb[0]) free(MEM_K1_TO_K0(xfb[0]));
if(xfb[1]) free(MEM_K1_TO_K0(xfb[1]));
xfb[0] = (u32 *) SYS_AllocateFramebuffer (m);
Expand All @@ -191,7 +203,7 @@ void setVideoMode(GXRModeObj *m) {
VIDEO_ClearFrameBuffer (m, xfb[1], COLOR_BLACK);
VIDEO_SetNextFramebuffer (xfb[0]);
VIDEO_SetPostRetraceCallback (ProperScanPADS);
VIDEO_SetBlack (0);
VIDEO_SetBlack (false);
VIDEO_Flush ();
VIDEO_WaitVSync ();
if (m->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();
Expand Down

0 comments on commit 5e3c515

Please sign in to comment.