Skip to content

Commit

Permalink
- Improve in-game SD card compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Dec 7, 2019
1 parent bb04e9d commit b8eec60
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 8 deletions.
1 change: 1 addition & 0 deletions cube/patches/alt/base.S
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ realmode:

.globl _start
_start:
b exi_probe
b exi_trylock
b set_di_handler
b set_breakpoint
Expand Down
11 changes: 11 additions & 0 deletions cube/patches/alt/blockdevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,21 @@
#include "../base/common.h"
#include "../base/exi.h"

bool exi_probe(int32_t chan)
{
if (chan == EXI_CHANNEL_2)
return false;
if (chan == *(uint8_t *)VAR_EXI_SLOT)
return false;
return true;
}

bool exi_trylock(int32_t chan, uint32_t dev, EXIControl *exi)
{
if (!(exi->state & EXI_STATE_LOCKED) || exi->dev != dev)
return false;
if (chan == *(uint8_t *)VAR_EXI_SLOT && dev == EXI_DEVICE_0)
return false;
if (chan == *(uint8_t *)VAR_EXI_SLOT)
end_read();
return true;
Expand Down
11 changes: 11 additions & 0 deletions cube/patches/bba/bba.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,23 @@ void exi_interrupt_handler(OSInterrupt interrupt, OSContext *context)
bba_cmd_out8(0x02, BBA_CMD_IRMASKNONE);
}

bool exi_probe(int32_t chan)
{
if (chan == EXI_CHANNEL_2)
return false;
if (chan == *(uint8_t *)VAR_EXI_SLOT)
return false;
return true;
}

bool exi_trylock(int32_t chan, uint32_t dev, EXIControl *exi)
{
if (!(exi->state & EXI_STATE_LOCKED) || exi->dev != dev)
return false;
if (chan == EXI_CHANNEL_0 && dev == EXI_DEVICE_2)
return false;
if (chan == *(uint8_t *)VAR_EXI_SLOT && dev == EXI_DEVICE_0)
return false;
return true;
}

Expand Down
11 changes: 11 additions & 0 deletions cube/patches/usbgecko/usbgecko.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,21 @@ void usb_request(uint32_t offset, uint32_t size)
usb_transmit(&request, sizeof(request), sizeof(request));
}

bool exi_probe(int32_t chan)
{
if (chan == EXI_CHANNEL_2)
return false;
if (chan == *(uint8_t *)VAR_EXI_SLOT)
return false;
return true;
}

bool exi_trylock(int32_t chan, uint32_t dev, EXIControl *exi)
{
if (!(exi->state & EXI_STATE_LOCKED) || exi->dev != dev)
return false;
if (chan == *(uint8_t *)VAR_EXI_SLOT && dev == EXI_DEVICE_0)
return false;
return true;
}

Expand Down
17 changes: 9 additions & 8 deletions cube/swiss/include/patcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,15 @@ enum patchIds {
#define IGR_EXIT_WKF (void*)(LO_RESERVE | 0x0C)

/* Function jump locations for the SD/IDE/USBGecko/BBA patch */
#define EXI_TRYLOCK (void*)(LO_RESERVE_ALT | 0x158)
#define SET_DI_HANDLER (void*)(LO_RESERVE_ALT | 0x15C)
#define SET_BREAKPOINT (void*)(LO_RESERVE_ALT | 0x160)
#define UNSET_BREAKPOINT (void*)(LO_RESERVE_ALT | 0x164)
#define IDLE_THREAD (void*)(LO_RESERVE_ALT | 0x168)
#define TRICKLE_READ (void*)(LO_RESERVE_ALT | 0x16C)
#define CHECK_PAD_ALT (void*)(LO_RESERVE_ALT | 0x170)
#define IGR_EXIT_ALT (void*)(LO_RESERVE_ALT | 0x174)
#define EXI_PROBE (void*)(LO_RESERVE_ALT | 0x158)
#define EXI_TRYLOCK (void*)(LO_RESERVE_ALT | 0x15C)
#define SET_DI_HANDLER (void*)(LO_RESERVE_ALT | 0x160)
#define SET_BREAKPOINT (void*)(LO_RESERVE_ALT | 0x164)
#define UNSET_BREAKPOINT (void*)(LO_RESERVE_ALT | 0x168)
#define IDLE_THREAD (void*)(LO_RESERVE_ALT | 0x16C)
#define TRICKLE_READ (void*)(LO_RESERVE_ALT | 0x170)
#define CHECK_PAD_ALT (void*)(LO_RESERVE_ALT | 0x174)
#define IGR_EXIT_ALT (void*)(LO_RESERVE_ALT | 0x178)

#define READ_PATCHED_ALL (0x111)

Expand Down
60 changes: 60 additions & 0 deletions cube/swiss/source/patcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -3125,6 +3125,66 @@ int Patch_DVDLowLevelReadAlt(u32 *data, u32 length, int dataType)
}
}

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

if (j < sizeof(__EXIProbeSigs) / sizeof(FuncPattern) && (i = __EXIProbeSigs[j].offsetFoundAt)) {
u32 *__EXIProbe = Calc_ProperAddress(data, dataType, i * sizeof(u32));

if (__EXIProbe) {
switch (j) {
case 0:
data[i + 19] = 0x387F0000; // addi r3, r31, 0
data[i + 20] = branchAndLink(EXI_PROBE, __EXIProbe + 20);
data[i + 21] = 0x2C030000; // cmpwi r3, 0
data[i + 22] = 0x41820144; // beq +81
break;
case 1:
data[i + 19] = 0x387F0000; // addi r3, r31, 0
data[i + 20] = branchAndLink(EXI_PROBE, __EXIProbe + 20);
data[i + 21] = 0x2C030000; // cmpwi r3, 0
data[i + 22] = 0x41820150; // beq +84
break;
case 2:
data[i + 20] = 0x387F0000; // addi r3, r31, 0
data[i + 21] = branchAndLink(EXI_PROBE, __EXIProbe + 21);
data[i + 22] = 0x2C030000; // cmpwi r3, 0
data[i + 23] = 0x41820150; // beq +84
break;
case 3:
data[i + 8] = data[i + 9];
data[i + 9] = 0x387D0000; // addi r3, r29, 0
data[i + 10] = branchAndLink(EXI_PROBE, __EXIProbe + 10);
data[i + 11] = 0x2C030000; // cmpwi r3, 0
data[i + 12] = 0x41820124; // beq +73
break;
case 4:
data[i + 6] = data[i + 7];
data[i + 7] = data[i + 8];
data[i + 8] = data[i + 9];
data[i + 9] = 0x387C0000; // addi r3, r28, 0
data[i + 10] = branchAndLink(EXI_PROBE, __EXIProbe + 10);
data[i + 11] = 0x2C030000; // cmpwi r3, 0
data[i + 12] = 0x41820130; // beq +76
break;
case 5:
data[i + 9] = 0x387C0000; // addi r3, r28, 0
data[i + 10] = branchAndLink(EXI_PROBE, __EXIProbe + 10);
data[i + 11] = 0x2C030000; // cmpwi r3, 0
data[i + 12] = 0x41820130; // beq +76
break;
case 6:
data[i + 9] = 0x387F0000; // addi r3, r31, 0
data[i + 10] = branchAndLink(EXI_PROBE, __EXIProbe + 10);
data[i + 11] = 0x2C030000; // cmpwi r3, 0
data[i + 12] = 0x41820170; // beq +92
break;
}
print_gecko("Found:[%s] @ %08X\n", __EXIProbeSigs[j].Name, __EXIProbe);
patched++;
}
}

if ((i = EXISelectSDSig.offsetFoundAt)) {
u32 *EXISelectSD = Calc_ProperAddress(data, dataType, i * sizeof(u32));

Expand Down

0 comments on commit b8eec60

Please sign in to comment.