Skip to content

Commit

Permalink
- Improve PAL 50Hz forcing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Dec 11, 2018
1 parent 967b264 commit 6bcf3b5
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 37 deletions.
2 changes: 2 additions & 0 deletions cube/reservedarea.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
.set VAR_IGR_DOL_SIZE, 0x2EE0 # IGR DOL Size
.set VAR_READS_IN_AS, 0x2EE4 # How many times have we tried to read while streaming is on?
.set VAR_AS_ENABLED, 0x2EE8 # Is Audio streaming enabled by the user?
.set VAR_RMODE, 0x2EEC # render mode
.set VAR_FAKE_IRQ_SET, 0x2EF8 # flag to say we are ready to fake irq.
.set VAR_SAR_WIDTH, 0x2EFC # sample aspect ratio width
.set VAR_SAR_HEIGHT, 0x2EFE # sample aspect ratio height
Expand Down Expand Up @@ -114,6 +115,7 @@
#define VAR_IGR_DOL_SIZE (VAR_AREA+0x2EE0) // IGR DOL Size
#define VAR_READS_IN_AS (VAR_AREA+0x2EE4) // How many times have we tried to read while streaming is on?
#define VAR_AS_ENABLED (VAR_AREA+0x2EE8) // Is Audio streaming enabled by the user?
#define VAR_RMODE (VAR_AREA+0x2EEC) // render mode
#define VAR_FAKE_IRQ_SET (VAR_AREA+0x2EF8) // flag to say we are ready to fake irq.
#define VAR_SAR_WIDTH (VAR_AREA+0x2EFC) // sample aspect ratio width
#define VAR_SAR_HEIGHT (VAR_AREA+0x2EFE) // sample aspect ratio height
Expand Down
9 changes: 6 additions & 3 deletions cube/swiss/include/patcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ extern u8 VIConfigure1080i50[];
extern u32 VIConfigure1080i50_length;
extern u8 VIConfigure1080i60[];
extern u32 VIConfigure1080i60_length;
extern u8 VIConfigureHook[];
extern u32 VIConfigureHook_length;
extern u8 VIConfigureHook1[];
extern u32 VIConfigureHook1_length;
extern u8 VIConfigureHook2[];
extern u32 VIConfigureHook2_length;
extern u8 VIConfigurePanHook[];
extern u32 VIConfigurePanHook_length;
extern u8 VIRetraceHandlerHook[];
Expand Down Expand Up @@ -109,7 +111,8 @@ enum patchIds {
VI_CONFIGURE576P,
VI_CONFIGURE1080I50,
VI_CONFIGURE1080I60,
VI_CONFIGUREHOOK,
VI_CONFIGUREHOOK1,
VI_CONFIGUREHOOK2,
VI_CONFIGUREPANHOOK,
VI_RETRACEHANDLERHOOK,
MAJORA_SAVEREGS,
Expand Down
55 changes: 34 additions & 21 deletions cube/swiss/source/patcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -868,8 +868,10 @@ void *installPatch(int patchId) {
patchSize = VIConfigure1080i50_length; patchLocation = VIConfigure1080i50; break;
case VI_CONFIGURE1080I60:
patchSize = VIConfigure1080i60_length; patchLocation = VIConfigure1080i60; break;
case VI_CONFIGUREHOOK:
patchSize = VIConfigureHook_length; patchLocation = VIConfigureHook; break;
case VI_CONFIGUREHOOK1:
patchSize = VIConfigureHook1_length; patchLocation = VIConfigureHook1; break;
case VI_CONFIGUREHOOK2:
patchSize = VIConfigureHook2_length; patchLocation = VIConfigureHook2; break;
case VI_CONFIGUREPANHOOK:
patchSize = VIConfigurePanHook_length; patchLocation = VIConfigurePanHook; break;
case VI_RETRACEHANDLERHOOK:
Expand Down Expand Up @@ -1143,57 +1145,59 @@ void Patch_VideoMode(u32 *data, u32 length, int dataType)
for (j = 0; j < sizeof(VIConfigureSigs) / sizeof(FuncPattern); j++) {
if (!VIConfigureSigs[j].offsetFoundAt && compare_pattern(&fp, &VIConfigureSigs[j])) {
u32 *VIConfigure = Calc_ProperAddress(data, dataType, i * sizeof(u32));
u32 *VIConfigureHook = NULL;
u32 *VIConfigureHook1 = NULL;
u32 *VIConfigureHook2 = NULL;
if (VIConfigure) {
print_gecko("Found:[%s] @ %08X\n", VIConfigureSigs[j].Name, VIConfigure);
VIConfigureHook2 = getPatchAddr(VI_CONFIGUREHOOK2);
switch (swissSettings.gameVMode) {
case 1:
case 2:
print_gecko("Patched NTSC Interlaced mode\n");
if (swissSettings.forceVFilter > 0)
vfilter = vertical_filters[swissSettings.forceVFilter];
VIConfigureHook = getPatchAddr(VI_CONFIGURE480I);
VIConfigureHook1 = getPatchAddr(VI_CONFIGURE480I);
break;
case 3:
print_gecko("Patched NTSC Double-Strike mode\n");
vfilter = vertical_reduction[swissSettings.forceVFilter];
VIConfigureHook = getPatchAddr(VI_CONFIGURE240P);
VIConfigureHook1 = getPatchAddr(VI_CONFIGURE240P);
break;
case 4:
print_gecko("Patched NTSC Field Rendering mode\n");
vfilter = vertical_filters[swissSettings.forceVFilter];
VIConfigureHook = getPatchAddr(VI_CONFIGURE1080I60);
VIConfigureHook1 = getPatchAddr(VI_CONFIGURE1080I60);
break;
case 5:
print_gecko("Patched NTSC Progressive mode\n");
vfilter = vertical_filters[swissSettings.forceVFilter];
VIConfigureHook = getPatchAddr(VI_CONFIGURE480P);
VIConfigureHook1 = getPatchAddr(VI_CONFIGURE480P);
break;
case 6:
case 7:
print_gecko("Patched PAL Interlaced mode\n");
if (swissSettings.forceVFilter > 0)
vfilter = vertical_filters[swissSettings.forceVFilter];
VIConfigureHook = getPatchAddr(VI_CONFIGURE576I);
VIConfigureHook1 = getPatchAddr(VI_CONFIGURE576I);
break;
case 8:
print_gecko("Patched PAL Double-Strike mode\n");
vfilter = vertical_reduction[swissSettings.forceVFilter];
VIConfigureHook = getPatchAddr(VI_CONFIGURE288P);
VIConfigureHook1 = getPatchAddr(VI_CONFIGURE288P);
break;
case 9:
print_gecko("Patched PAL Field Rendering mode\n");
vfilter = vertical_filters[swissSettings.forceVFilter];
VIConfigureHook = getPatchAddr(VI_CONFIGURE1080I50);
VIConfigureHook1 = getPatchAddr(VI_CONFIGURE1080I50);
break;
case 10:
print_gecko("Patched PAL Progressive mode\n");
vfilter = vertical_filters[swissSettings.forceVFilter];
VIConfigureHook = getPatchAddr(VI_CONFIGURE576P);
VIConfigureHook1 = getPatchAddr(VI_CONFIGURE576P);
break;
}
if (swissSettings.forceHScale > 0) {
VIConfigureHook = getPatchAddr(VI_CONFIGUREHOOK);
VIConfigureHook1 = getPatchAddr(VI_CONFIGUREHOOK1);
switch (swissSettings.forceHScale) {
case 1:
*(u16*)VAR_SAR_WIDTH = 1;
Expand Down Expand Up @@ -1226,7 +1230,7 @@ void Patch_VideoMode(u32 *data, u32 length, int dataType)

data[i + 54] = data[i + 6];
data[i + 53] = data[i + 5];
data[i + 5] = branchAndLink(VIConfigureHook, VIConfigure + 5);
data[i + 5] = branchAndLink(VIConfigureHook1, VIConfigure + 5);
data[i + 6] = 0x7C771B78; // mr r23, r3
data[i + 64] = 0x541807BE; // clrlwi r24, r0, 30
data[i + 97] = 0x5400003C; // clrrwi r0, r0, 1
Expand All @@ -1238,6 +1242,7 @@ void Patch_VideoMode(u32 *data, u32 length, int dataType)
data[i + 128] = 0xA01E0010; // lhz r0, 16 (r30)
data[i + 218] = 0x801F0114; // lwz r0, 276 (r31)
data[i + 219] = 0x28000002; // cmplwi r0, 2
data[i + 274] = branchAndLink(VIConfigureHook2, VIConfigure + 274);
break;
case 1:
getTimingSigs[1].offsetFoundAt = branchResolve(data, i + 139);
Expand All @@ -1249,7 +1254,7 @@ void Patch_VideoMode(u32 *data, u32 length, int dataType)
data[i + 59] = data[i + 7];
data[i + 8] = data[i + 6];
data[i + 7] = data[i + 5];
data[i + 5] = branchAndLink(VIConfigureHook, VIConfigure + 5);
data[i + 5] = branchAndLink(VIConfigureHook1, VIConfigure + 5);
data[i + 6] = 0x7C781B78; // mr r24, r3
data[i + 90] = 0x5400003C; // clrrwi r0, r0, 1
data[i + 113] = 0xA01E0010; // lhz r0, 16 (r30)
Expand All @@ -1263,13 +1268,14 @@ void Patch_VideoMode(u32 *data, u32 length, int dataType)
data[i + 250] = 0x28000002; // cmplwi r0, 2
data[i + 252] = 0x801F0114; // lwz r0, 276 (r31)
data[i + 253] = 0x28000003; // cmplwi r0, 3
data[i + 308] = branchAndLink(VIConfigureHook2, VIConfigure + 308);
break;
case 2:
getTimingSigs[2].offsetFoundAt = branchResolve(data, i + 77);
setFbbRegsSigs[1].offsetFoundAt = branchResolve(data, i + 409);
setVerticalRegsSigs[1].offsetFoundAt = branchResolve(data, i + 420);

data[i + 7] = branchAndLink(VIConfigureHook, VIConfigure + 7);
data[i + 7] = branchAndLink(VIConfigureHook1, VIConfigure + 7);
data[i + 19] = 0x548307BE; // clrlwi r3, r4, 30
data[i + 35] = 0x5400003C; // clrrwi r0, r0, 1
data[i + 65] = 0xA01F0010; // lhz r0, 16 (r31)
Expand All @@ -1282,13 +1288,14 @@ void Patch_VideoMode(u32 *data, u32 length, int dataType)
data[i + 104] = 0x7CA42B78; // mr r4, r5
data[i + 222] = 0x801B0000; // lwz r0, 0 (r27)
data[i + 224] = 0x28000002; // cmplwi r0, 2
data[i + 422] = branchAndLink(VIConfigureHook2, VIConfigure + 422);
break;
case 3:
getTimingSigs[2].offsetFoundAt = branchResolve(data, i + 69);
setFbbRegsSigs[1].offsetFoundAt = branchResolve(data, i + 401);
setVerticalRegsSigs[1].offsetFoundAt = branchResolve(data, i + 412);

data[i + 7] = branchAndLink(VIConfigureHook, VIConfigure + 7);
data[i + 7] = branchAndLink(VIConfigureHook1, VIConfigure + 7);
data[i + 27] = 0x5400003C; // clrrwi r0, r0, 1
data[i + 57] = 0xA01F0010; // lhz r0, 16 (r31)
data[i + 59] = 0x801C0000; // lwz r0, 0 (r28)
Expand All @@ -1300,13 +1307,14 @@ void Patch_VideoMode(u32 *data, u32 length, int dataType)
data[i + 96] = 0x7CA42B78; // mr r4, r5
data[i + 214] = 0x801C0000; // lwz r0, 0 (r28)
data[i + 216] = 0x28000002; // cmplwi r0, 2
data[i + 414] = branchAndLink(VIConfigureHook2, VIConfigure + 414);
break;
case 4:
getTimingSigs[3].offsetFoundAt = branchResolve(data, i + 104);
setFbbRegsSigs[1].offsetFoundAt = branchResolve(data, i + 445);
setVerticalRegsSigs[1].offsetFoundAt = branchResolve(data, i + 456);

data[i + 9] = branchAndLink(VIConfigureHook, VIConfigure + 9);
data[i + 9] = branchAndLink(VIConfigureHook1, VIConfigure + 9);
data[i + 62] = 0x5400003C; // clrrwi r0, r0, 1
data[i + 92] = 0xA01F0010; // lhz r0, 16 (r31)
data[i + 94] = 0x801C0000; // lwz r0, 0 (r28)
Expand All @@ -1318,13 +1326,14 @@ void Patch_VideoMode(u32 *data, u32 length, int dataType)
data[i + 131] = 0x7CA42B78; // mr r4, r5
data[i + 258] = 0x801C0000; // lwz r0, 0 (r28)
data[i + 260] = 0x28000002; // cmplwi r0, 2
data[i + 458] = branchAndLink(VIConfigureHook2, VIConfigure + 458);
break;
case 5:
getTimingSigs[4].offsetFoundAt = branchResolve(data, i + 123);
setFbbRegsSigs[1].offsetFoundAt = branchResolve(data, i + 468);
setVerticalRegsSigs[1].offsetFoundAt = branchResolve(data, i + 479);

data[i + 9] = branchAndLink(VIConfigureHook, VIConfigure + 9);
data[i + 9] = branchAndLink(VIConfigureHook1, VIConfigure + 9);
data[i + 65] = 0x5400003C; // clrrwi r0, r0, 1
data[i + 95] = 0xA01F0010; // lhz r0, 16 (r31)
data[i + 99] = 0xA01F0010; // lhz r0, 16 (r31)
Expand All @@ -1338,13 +1347,14 @@ void Patch_VideoMode(u32 *data, u32 length, int dataType)
data[i + 280] = 0x801C0000; // lwz r0, 0 (r28)
data[i + 282] = 0x28000002; // cmplwi r0, 2
data[i + 284] = 0x28000003; // cmplwi r0, 3
data[i + 481] = branchAndLink(VIConfigureHook2, VIConfigure + 481);
break;
case 6:
getTimingSigs[5].offsetFoundAt = branchResolve(data, i + 155);
setFbbRegsSigs[1].offsetFoundAt = branchResolve(data, i + 503);
setVerticalRegsSigs[2].offsetFoundAt = branchResolve(data, i + 514);

data[i + 9] = branchAndLink(VIConfigureHook, VIConfigure + 9);
data[i + 9] = branchAndLink(VIConfigureHook1, VIConfigure + 9);
data[i + 97] = 0x5400003C; // clrrwi r0, r0, 1
data[i + 127] = 0xA01F0010; // lhz r0, 16 (r31)
data[i + 131] = 0xA01F0010; // lhz r0, 16 (r31)
Expand All @@ -1359,13 +1369,14 @@ void Patch_VideoMode(u32 *data, u32 length, int dataType)
data[i + 315] = 0x28000002; // cmplwi r0, 2
data[i + 317] = 0x28000003; // cmplwi r0, 3
data[i + 319] = 0x28000002; // cmplwi r0, 2
data[i + 516] = branchAndLink(VIConfigureHook2, VIConfigure + 516);
break;
case 7:
getTimingSigs[6].offsetFoundAt = i;
setFbbRegsSigs[2].offsetFoundAt = branchResolve(data, i + 537);
setVerticalRegsSigs[3].offsetFoundAt = branchResolve(data, i + 550);

data[i + 8] = branchAndLink(VIConfigureHook, VIConfigure + 8);
data[i + 8] = branchAndLink(VIConfigureHook1, VIConfigure + 8);
data[i + 101] = 0x5408003C; // clrrwi r8, r0, 1
data[i + 123] = 0xA0FB0010; // lhz r7, 16 (r27)
data[i + 127] = 0xA0FB0010; // lhz r7, 16 (r27)
Expand All @@ -1378,13 +1389,14 @@ void Patch_VideoMode(u32 *data, u32 length, int dataType)
data[i + 336] = 0x280A0002; // cmplwi r10, 2
data[i + 343] = 0x280A0003; // cmplwi r10, 3
data[i + 345] = 0x280A0002; // cmplwi r10, 2
data[i + 552] = branchAndLink(VIConfigureHook2, VIConfigure + 552);
break;
case 8:
getTimingSigs[7].offsetFoundAt = branchResolve(data, i + 155);
setFbbRegsSigs[1].offsetFoundAt = branchResolve(data, i + 495);
setVerticalRegsSigs[2].offsetFoundAt = branchResolve(data, i + 506);

data[i + 9] = branchAndLink(VIConfigureHook, VIConfigure + 9);
data[i + 9] = branchAndLink(VIConfigureHook1, VIConfigure + 9);
data[i + 97] = 0x5400003C; // clrrwi r0, r0, 1
data[i + 127] = 0xA0130010; // lhz r0, 16 (r19)
data[i + 131] = 0xA0130010; // lhz r0, 16 (r19)
Expand All @@ -1395,6 +1407,7 @@ void Patch_VideoMode(u32 *data, u32 length, int dataType)
data[i + 139] = 0xA0130010; // lhz r0, 16 (r19)
data[i + 180] = 0x38A00000 | (swissSettings.forceVOffset & 0xFFFF);
data[i + 182] = 0x7CA42B78; // mr r4, r5
data[i + 508] = branchAndLink(VIConfigureHook2, VIConfigure + 508);
break;
}
if (swissSettings.gameVMode == 4 || swissSettings.gameVMode == 9) {
Expand Down
3 changes: 2 additions & 1 deletion cube/swiss/source/patches/vi/VIConfigure1080i50.s
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ VIConfigure1080i50:
bne 2f
stw %r5, VAR_TVMODE (%r4)
1: insrwi %r0, %r5, 30, 0
2: li %r7, 1
2: stw %r3, VAR_RMODE (%r4)
li %r7, 1
li %r6, 0
lhz %r5, 8 (%r3)
slwi %r5, %r5, 1
Expand Down
3 changes: 2 additions & 1 deletion cube/swiss/source/patches/vi/VIConfigure1080i60.s
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ VIConfigure1080i60:
bne 2f
stw %r5, VAR_TVMODE (%r4)
1: insrwi %r0, %r5, 30, 0
2: li %r7, 1
2: stw %r3, VAR_RMODE (%r4)
li %r7, 1
li %r6, 0
lhz %r5, 8 (%r3)
slwi %r5, %r5, 1
Expand Down
3 changes: 2 additions & 1 deletion cube/swiss/source/patches/vi/VIConfigure240p.s
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ VIConfigure240p:
bne 2f
stw %r5, VAR_TVMODE (%r4)
1: insrwi %r0, %r5, 30, 0
2: li %r7, 0
2: stw %r3, VAR_RMODE (%r4)
li %r7, 0
li %r6, 0
lhz %r5, 8 (%r3)
slwi %r5, %r5, 1
Expand Down
3 changes: 2 additions & 1 deletion cube/swiss/source/patches/vi/VIConfigure288p.s
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ VIConfigure288p:
bne 2f
stw %r5, VAR_TVMODE (%r4)
1: insrwi %r0, %r5, 30, 0
2: li %r7, 0
2: stw %r3, VAR_RMODE (%r4)
li %r7, 0
li %r6, 0
lhz %r5, 8 (%r3)
slwi %r5, %r5, 1
Expand Down
3 changes: 2 additions & 1 deletion cube/swiss/source/patches/vi/VIConfigure480i.s
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ VIConfigure480i:
bne 2f
stw %r5, VAR_TVMODE (%r4)
1: insrwi %r0, %r5, 30, 0
2: li %r6, 0
2: stw %r3, VAR_RMODE (%r4)
li %r6, 0
lhz %r5, 8 (%r3)
slwi %r5, %r5, 1
cmpwi %r5, 480
Expand Down
3 changes: 2 additions & 1 deletion cube/swiss/source/patches/vi/VIConfigure480p.s
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ VIConfigure480p:
bne 2f
stw %r5, VAR_TVMODE (%r4)
1: insrwi %r0, %r5, 30, 0
2: li %r6, 0
2: stw %r3, VAR_RMODE (%r4)
li %r6, 0
lhz %r5, 8 (%r3)
slwi %r5, %r5, 1
cmpwi %r5, 480
Expand Down
3 changes: 2 additions & 1 deletion cube/swiss/source/patches/vi/VIConfigure576i.s
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ VIConfigure576i:
bne 2f
stw %r5, VAR_TVMODE (%r4)
1: insrwi %r0, %r5, 30, 0
2: li %r6, 0
2: stw %r3, VAR_RMODE (%r4)
li %r6, 0
lhz %r5, 8 (%r3)
slwi %r5, %r5, 1
subic. %r4, %r5, 480
Expand Down
3 changes: 2 additions & 1 deletion cube/swiss/source/patches/vi/VIConfigure576p.s
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ VIConfigure576p:
bne 2f
stw %r5, VAR_TVMODE (%r4)
1: insrwi %r0, %r5, 30, 0
2: li %r6, 0
2: stw %r3, VAR_RMODE (%r4)
li %r6, 0
lhz %r5, 8 (%r3)
slwi %r5, %r5, 1
subic. %r4, %r5, 480
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define _LANGUAGE_ASSEMBLY
#include "../../../../reservedarea.h"

.globl VIConfigureHook
VIConfigureHook:
.globl VIConfigureHook1
VIConfigureHook1:
lis %r4, VAR_AREA
lhz %r5, VAR_SAR_WIDTH (%r4)
lbz %r6, VAR_SAR_HEIGHT (%r4)
Expand All @@ -20,6 +20,6 @@ VIConfigureHook:
sth %r9, 10 (%r3)
sth %r8, 14 (%r3)

.globl VIConfigureHook_length
VIConfigureHook_length:
.long (VIConfigureHook_length - VIConfigureHook)
.globl VIConfigureHook1_length
VIConfigureHook1_length:
.long (VIConfigureHook1_length - VIConfigureHook1)

0 comments on commit 6bcf3b5

Please sign in to comment.