Skip to content

Commit

Permalink
- Replace GXAdjustForOverscan.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Dec 15, 2018
1 parent 4dfb44a commit 7cbb745
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cube/swiss/include/patcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ extern u8 bba_bin[];
extern u32 bba_bin_size;

/* SDK patches */
extern u8 GXAdjustForOverscan[];
extern u32 GXAdjustForOverscan_length;
extern u8 GXAdjustForOverscanPatch[];
extern u32 GXAdjustForOverscanPatch_length;
extern u8 GXCopyDispHook[];
extern u32 GXCopyDispHook_length;
extern u8 GXInitTexObjLODHook[];
Expand Down
17 changes: 17 additions & 0 deletions cube/swiss/source/patcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,8 @@ void Patch_VideoMode(u32 *data, u32 length, int dataType)
{ 545, 293, 37, 110, 7, 9, NULL, 0, "__GXInitGX E" }, // SN Systems ProDG
{ 589, 333, 34, 119, 28, 11, NULL, 0, "__GXInitGX F" }
};
FuncPattern GXAdjustForOverscanSig =
{ 71, 17, 15, 0, 3, 5, GXAdjustForOverscanPatch, GXAdjustForOverscanPatch_length, "GXAdjustForOverscan" };
FuncPattern GXSetDispCopyYScaleSigs[7] = {
{ 99, 33, 8, 8, 4, 7, GXSetDispCopyYScalePatch1, GXSetDispCopyYScalePatch1_length, "GXSetDispCopyYScaleD A" },
{ 84, 32, 4, 6, 4, 7, GXSetDispCopyYScalePatch1, GXSetDispCopyYScalePatch1_length, "GXSetDispCopyYScaleD B" },
Expand Down Expand Up @@ -1052,6 +1054,9 @@ void Patch_VideoMode(u32 *data, u32 length, int dataType)
}

for (i = 0; i < length / sizeof(u32); i++) {
if (!GXAdjustForOverscanSig.offsetFoundAt && !memcmp(data + i, GXAdjustForOverscan, GXAdjustForOverscan_length))
GXAdjustForOverscanSig.offsetFoundAt = i;

if (data[i] != 0x7C0802A6 && data[i + 1] != 0x7C0802A6)
continue;

Expand Down Expand Up @@ -1730,6 +1735,18 @@ void Patch_VideoMode(u32 *data, u32 length, int dataType)
}

if (swissSettings.gameVMode >= 1 && swissSettings.gameVMode <= 5) {
if ((i = GXAdjustForOverscanSig.offsetFoundAt)) {
u32 *GXAdjustForOverscan = Calc_ProperAddress(data, dataType, i * sizeof(u32));

if (GXAdjustForOverscan) {
if (GXAdjustForOverscanSig.Patch) {
memset(data + i, 0, GXAdjustForOverscanSig.Length * sizeof(u32));
memcpy(data + i, GXAdjustForOverscanSig.Patch, GXAdjustForOverscanSig.PatchLength);
}
print_gecko("Found:[%s] @ %08X\n", GXAdjustForOverscanSig.Name, GXAdjustForOverscan);
}
}

for (j = 0; j < sizeof(GXSetDispCopyYScaleSigs) / sizeof(FuncPattern); j++)
if (GXSetDispCopyYScaleSigs[j].offsetFoundAt) break;

Expand Down
82 changes: 82 additions & 0 deletions cube/swiss/source/patches/gx/GXAdjustForOverscan.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include "../asm.h"
#define _LANGUAGE_ASSEMBLY
#include "../../../../reservedarea.h"

.globl GXAdjustForOverscan
GXAdjustForOverscan:
cmplw %r3, %r4
clrlwi %r7, %r5, 16
clrlwi %r0, %r6, 16
rlwinm %r5, %r5, 1, 16, 30
rlwinm %r6, %r6, 1, 16, 30
beq 1f
lwz %r9, 0 (%r3)
lwz %r8, 4 (%r3)
stw %r9, 0 (%r4)
stw %r8, 4 (%r4)
lwz %r9, 8 (%r3)
lwz %r8, 12 (%r3)
stw %r9, 8 (%r4)
stw %r8, 12 (%r4)
lwz %r9, 16 (%r3)
lwz %r8, 20 (%r3)
stw %r9, 16 (%r4)
stw %r8, 20 (%r4)
lwz %r9, 24 (%r3)
lwz %r8, 28 (%r3)
stw %r9, 24 (%r4)
stw %r8, 28 (%r4)
lwz %r9, 32 (%r3)
lwz %r8, 36 (%r3)
stw %r9, 32 (%r4)
stw %r8, 36 (%r4)
lwz %r9, 40 (%r3)
lwz %r8, 44 (%r3)
stw %r9, 40 (%r4)
stw %r8, 44 (%r4)
lwz %r9, 48 (%r3)
lwz %r8, 52 (%r3)
stw %r9, 48 (%r4)
stw %r8, 52 (%r4)
lwz %r8, 56 (%r3)
stw %r8, 56 (%r4)
1: lhz %r8, 4 (%r3)
sub %r8, %r8, %r5
sth %r8, 4 (%r4)
lhz %r10, 6 (%r3)
lhz %r8, 8 (%r3)
mullw %r9, %r6, %r10
divwu %r8, %r9, %r8
sub %r8, %r10, %r8
sth %r8, 6 (%r4)
lwz %r8, 20 (%r3)
cmpwi %r8, 0
bne 2f
lwz %r8, 0 (%r3)
rlwinm %r8, %r8, 0, 30, 30
cmpwi %r8, 2
beq 2f
lhz %r8, 8 (%r3)
sub %r8, %r8, %r0
sth %r8, 8 (%r4)
b 3f
2: lhz %r8, 8 (%r3)
sub %r8, %r8, %r6
sth %r8, 8 (%r4)
3: lhz %r8, 14 (%r3)
sub %r5, %r8, %r5
sth %r5, 14 (%r4)
lhz %r5, 16 (%r3)
sub %r5, %r5, %r6
sth %r5, 16 (%r4)
lhz %r5, 10 (%r3)
add %r5, %r5, %r7
sth %r5, 10 (%r4)
lhz %r3, 12 (%r3)
add %r0, %r3, %r0
sth %r0, 12 (%r4)
blr

.globl GXAdjustForOverscan_length
GXAdjustForOverscan_length:
.long (GXAdjustForOverscan_length - GXAdjustForOverscan)
61 changes: 61 additions & 0 deletions cube/swiss/source/patches/gx/GXAdjustForOverscanPatch.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "../asm.h"
#define _LANGUAGE_ASSEMBLY
#include "../../../../reservedarea.h"

.globl GXAdjustForOverscanPatch
GXAdjustForOverscanPatch:
lwz %r0, 0 (%r3)
stw %r0, 0 (%r4)
lhz %r8, 6 (%r3)
lhz %r9, 8 (%r3)
cmpwi %r9, 480
ble 2f
clrrwi %r6, %r6, 2
sub %r7, %r9, %r8
cmpwi %r8, 480
mr %r8, %r9
ble 1f
subi %r7, %r8, 480
1: srwi %r7, %r7, 1
add %r6, %r6, %r7
2: slwi %r7, %r6, 1
mullw %r10, %r8, %r7
divwu %r10, %r10, %r9
sub %r8, %r8, %r10
lwz %r10, 20 (%r3)
cmpwi %r10, 0
bne 3f
andi. %r0, %r0, 2
beq 4f
3: sub %r9, %r9, %r6
4: sub %r9, %r9, %r6
sth %r8, 6 (%r4)
sth %r9, 8 (%r4)
lhz %r8, 12 (%r3)
lhz %r9, 16 (%r3)
add %r8, %r8, %r6
sub %r9, %r9, %r7
sth %r8, 12 (%r4)
sth %r9, 16 (%r4)
stw %r10, 20 (%r4)
slwi %r6, %r5, 1
lhz %r7, 4 (%r3)
lhz %r8, 10 (%r3)
lhz %r9, 14 (%r3)
lwz %r0, 24 (%r3)
sub %r7, %r7, %r6
add %r8, %r8, %r5
sub %r9, %r9, %r6
sth %r7, 4 (%r4)
sth %r8, 10 (%r4)
sth %r9, 14 (%r4)
stw %r0, 24 (%r4)
addi %r3, %r3, 28
addi %r4, %r4, 28
lswi %r5, %r3, 32
stswi %r5, %r4, 32
blr

.globl GXAdjustForOverscanPatch_length
GXAdjustForOverscanPatch_length:
.long (GXAdjustForOverscanPatch_length - GXAdjustForOverscanPatch)

0 comments on commit 7cbb745

Please sign in to comment.