Skip to content

Commit

Permalink
- Add game-specific patch for Viewtiful Joe (Europe).
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Dec 9, 2019
1 parent 4d35052 commit a5ca3ea
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 6 deletions.
6 changes: 3 additions & 3 deletions cube/patches/alt/base.S
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ system_call_vector:
mthid0 r9
rfi

.globl dsi_exception_handler
dsi_exception_handler:
.globl exception_handler
exception_handler:
stswi r0, r4, 12
stmw r6, 24 (r4)
mfgqr r0, 1
Expand All @@ -39,7 +39,7 @@ dsi_exception_handler:
mfdsisr r5
mfdar r6
stwu sp, -8 (sp)
bl exception_handler
bl service_exception

.globl load_context, load_context_end
load_context:
Expand Down
26 changes: 23 additions & 3 deletions cube/patches/alt/emulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static bool ppc_step(OSContext *context)
extern void load_context(void) __attribute((noreturn));
extern uint32_t load_context_end[];

void exception_handler(OSException exception, OSContext *context, uint32_t dsisr, uint32_t dar)
void service_exception(OSException exception, OSContext *context, uint32_t dsisr, uint32_t dar)
{
OSExceptionHandler handler;

Expand Down Expand Up @@ -216,6 +216,25 @@ void exception_handler(OSException exception, OSContext *context, uint32_t dsisr
return;
}
}
#ifndef BBA
case OS_EXCEPTION_PROGRAM:
{
uint32_t opcode = *(uint32_t *)context->srr0;

switch (opcode >> 26) {
case 3:
{
trickle_read();
context->srr0 += 4;

*load_context_end = 0x28000000 | (opcode & 0x1FFFFF);
asm volatile("dcbst 0,%0; sync; icbi 0,%0" :: "r" (load_context_end));
load_context();
return;
}
}
}
#endif
default:
{
handler = *OSExceptionHandlerTable;
Expand All @@ -228,7 +247,7 @@ void exception_handler(OSException exception, OSContext *context, uint32_t dsisr
load_context();
}

void dsi_exception_handler(OSException exception, OSContext *context, ...);
void exception_handler(OSException exception, OSContext *context, ...);

static void mem_interrupt_handler(OSInterrupt interrupt, OSContext *context)
{
Expand Down Expand Up @@ -257,7 +276,8 @@ void exi_interrupt_handler(OSInterrupt interrupt, OSContext *context);

OSInterruptHandler set_di_handler(OSInterrupt interrupt, OSInterruptHandler handler)
{
OSSetExceptionHandler(OS_EXCEPTION_DSI, dsi_exception_handler);
OSSetExceptionHandler(OS_EXCEPTION_DSI, exception_handler);
OSSetExceptionHandler(OS_EXCEPTION_PROGRAM, exception_handler);
OSSetInterruptHandler(OS_INTERRUPT_MEM_ADDRESS, mem_interrupt_handler);
#ifdef BBA
OSSetInterruptHandler(OS_INTERRUPT_EXI_2_EXI, exi_interrupt_handler);
Expand Down
44 changes: 44 additions & 0 deletions cube/swiss/source/patcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -7608,6 +7608,28 @@ int Patch_GameSpecificReadAlt(void *data, u32 length, const char *gameID, int da
// Skip second EXIInit call.
*(u32 *)(data + 0x800AF1B4 - 0x80005840 + 0x26C0) = 0x60000000;

print_gecko("Patched:[%.6s]\n", gameID);
patched++;
break;
}
} else if (!strncmp(gameID, "DVJP08", 6) && dataType == PATCH_DOL) {
switch (length) {
case 2556736:
if (devices[DEVICE_CUR] != &__device_fsp) {
// Trap busy-wait for 60Hz periodic alarm.
*(u32 *)(data + 0x800E14B4 - 0x80003480 + 0x480) = 0x0F800000;
}
print_gecko("Patched:[%.6s]\n", gameID);
patched++;
break;
}
} else if (!strncmp(gameID, "G2VP08", 6) && dataType == PATCH_DOL) {
switch (length) {
case 3240352:
if (devices[DEVICE_CUR] != &__device_fsp) {
// Trap busy-wait for 60Hz periodic alarm.
*(u32 *)(data + 0x801FD784 - 0x800034A0 + 0x4A0) = 0x0F800000;
}
print_gecko("Patched:[%.6s]\n", gameID);
patched++;
break;
Expand Down Expand Up @@ -7909,6 +7931,28 @@ int Patch_GameSpecificReadAlt(void *data, u32 length, const char *gameID, int da
*(u32 *)(data + 0x80004B04 - 0x80003100 + 0x100) = 0x60000000;
*(u32 *)(data + 0x80004B08 - 0x80003100 + 0x100) = 0x60000000;

print_gecko("Patched:[%.6s]\n", gameID);
patched++;
break;
}
} else if (!strncmp(gameID, "GVCP08", 6) && dataType == PATCH_DOL) {
switch (length) {
case 3041312:
if (devices[DEVICE_CUR] != &__device_fsp) {
// Trap busy-wait for 60Hz periodic alarm.
*(u32 *)(data + 0x801FBA2C - 0x800034A0 + 0x4A0) = 0x0F800000;
}
print_gecko("Patched:[%.6s]\n", gameID);
patched++;
break;
}
} else if (!strncmp(gameID, "GVJP08", 6) && dataType == PATCH_DOL) {
switch (length) {
case 2568224:
if (devices[DEVICE_CUR] != &__device_fsp) {
// Trap busy-wait for 60Hz periodic alarm.
*(u32 *)(data + 0x800E5390 - 0x80003480 + 0x480) = 0x0CE00001;
}
print_gecko("Patched:[%.6s]\n", gameID);
patched++;
break;
Expand Down

0 comments on commit a5ca3ea

Please sign in to comment.