Skip to content

Commit

Permalink
- Add IGR combo to forcibly reset game. (R, Z and START/PAUSE)
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Mar 17, 2022
1 parent 4d020be commit 19c2792
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 38 deletions.
2 changes: 1 addition & 1 deletion cube/patches/base/base.S
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ _start:
b mask_irq
b unmask_irq
b idle_thread
b check_pad
b check_status
b fini

unhandled_exception:
Expand Down
7 changes: 5 additions & 2 deletions cube/patches/base/dolphin/pad.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
#define PAD_BUTTON_START 0x1000
#define PAD_GET_ORIGIN 0x2000

#define PAD_COMBO_EXIT1 (PAD_BUTTON_B | PAD_BUTTON_R | PAD_BUTTON_Z | PAD_BUTTON_DOWN)
#define PAD_COMBO_EXIT2 (PAD_BUTTON_A | PAD_BUTTON_Z | PAD_BUTTON_START)
#define PAD_COMBO_EXIT1 (PAD_BUTTON_B | PAD_BUTTON_R | PAD_BUTTON_Z | PAD_BUTTON_DOWN)
#define PAD_COMBO_EXIT2 (PAD_BUTTON_A | PAD_BUTTON_Z | PAD_BUTTON_START)
#define PAD_COMBO_ORIGIN (PAD_BUTTON_Y | PAD_BUTTON_X | PAD_BUTTON_START)
#define PAD_COMBO_RESET (PAD_BUTTON_B | PAD_BUTTON_X | PAD_BUTTON_START)
#define PAD_COMBO_RESTART (PAD_BUTTON_R | PAD_BUTTON_Z | PAD_BUTTON_START)

typedef struct PADStatus {
u16 button;
Expand Down
6 changes: 6 additions & 0 deletions cube/patches/base/emulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1284,3 +1284,9 @@ void idle_thread(void)
#endif
enable_interrupts_idle();
}

void fini(void)
{
disable_interrupts();
reset_device();
}
45 changes: 20 additions & 25 deletions cube/patches/base/igr.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
#include "common.h"
#include "dolphin/os.h"
#include "dolphin/pad.h"
#include "emulator.h"

void check_pad(int32_t chan, PADStatus *status)
void check_status(int32_t chan, PADStatus *status)
{
if (*VAR_TRIGGER_LEVEL > 0) {
if (status->triggerL >= *VAR_TRIGGER_LEVEL)
Expand All @@ -32,32 +31,28 @@ void check_pad(int32_t chan, PADStatus *status)
status->button |= PAD_BUTTON_R;
}

if ((status->button & PAD_COMBO_EXIT1) == PAD_COMBO_EXIT1 ||
(status->button & PAD_COMBO_EXIT2) == PAD_COMBO_EXIT2) {
switch (*VAR_IGR_TYPE) {
case IGR_HARDRESET:
if (OSResetSystem) {
enable_interrupts();
OSResetSystem(OS_RESET_HOTRESET, 0, 0);
disable_interrupts();
}
break;
case IGR_BOOTBIN:
if (OSResetSystem) {
*VAR_IGR_TYPE |= 0x80;
enable_interrupts();
uint8_t igr_type = *VAR_IGR_TYPE & ~0x80;

if (igr_type != IGR_OFF) {
if ((status->button & PAD_COMBO_EXIT1) == PAD_COMBO_EXIT1 ||
(status->button & PAD_COMBO_EXIT2) == PAD_COMBO_EXIT2) {
if (OSResetSystem) {
enable_interrupts();
*VAR_IGR_TYPE = IGR_OFF | 0x80;
if (igr_type == IGR_BOOTBIN)
OSResetSystem(OS_RESET_RESTART, 0, 0);
disable_interrupts();
}
break;
else
OSResetSystem(OS_RESET_HOTRESET, 0, 0);
__builtin_trap();
}
} else if ((status->button & PAD_COMBO_RESTART) == PAD_COMBO_RESTART) {
if (OSResetSystem) {
enable_interrupts();
OSResetSystem(OS_RESET_RESTART, 0, 0);
__builtin_trap();
}
}
}

status->button &= ~PAD_USE_ORIGIN;
}

void fini(void)
{
disable_interrupts();
reset_device();
}
2 changes: 1 addition & 1 deletion cube/swiss/include/patcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ enum patchIds {
#define MASK_IRQ (u32 *)(LO_RESERVE + 0x10C)
#define UNMASK_IRQ (u32 *)(LO_RESERVE + 0x110)
#define IDLE_THREAD (u32 *)(LO_RESERVE + 0x114)
#define CHECK_PAD (u32 *)(LO_RESERVE + 0x118)
#define CHECK_STATUS (u32 *)(LO_RESERVE + 0x118)
#define FINI (u32 *)(LO_RESERVE + 0x11C)

/* Types of files we may patch */
Expand Down
18 changes: 9 additions & 9 deletions cube/swiss/source/patcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -14375,47 +14375,47 @@ int Patch_Miscellaneous(u32 *data, u32 length, int dataType)
case 0:
data[i + 159] = 0x387E0000; // addi r3, r30, 0
data[i + 160] = 0x389F0000; // addi r4, r31, 0
data[i + 161] = branchAndLink(CHECK_PAD, PADRead + 161);
data[i + 161] = branchAndLink(CHECK_STATUS, PADRead + 161);
break;
case 1:
data[i + 156] = 0x387E0000; // addi r3, r30, 0
data[i + 157] = 0x389F0000; // addi r4, r31, 0
data[i + 158] = branchAndLink(CHECK_PAD, PADRead + 158);
data[i + 158] = branchAndLink(CHECK_STATUS, PADRead + 158);
break;
case 2:
data[i + 100] = 0x387D0000; // addi r3, r29, 0
data[i + 101] = 0x389B0000; // addi r4, r27, 0
data[i + 102] = branchAndLink(CHECK_PAD, PADRead + 102);
data[i + 102] = branchAndLink(CHECK_STATUS, PADRead + 102);
break;
case 3:
data[i + 185] = 0x38760000; // addi r3, r22, 0
data[i + 186] = 0x38950000; // addi r4, r21, 0
data[i + 187] = branchAndLink(CHECK_PAD, PADRead + 187);
data[i + 187] = branchAndLink(CHECK_STATUS, PADRead + 187);
break;
case 4:
data[i + 190] = 0x38770000; // addi r3, r23, 0
data[i + 191] = 0x38950000; // addi r4, r21, 0
data[i + 192] = branchAndLink(CHECK_PAD, PADRead + 192);
data[i + 192] = branchAndLink(CHECK_STATUS, PADRead + 192);
break;
case 5:
data[i + 221] = 0x38750000; // addi r3, r21, 0
data[i + 222] = 0x389F0000; // addi r4, r31, 0
data[i + 223] = branchAndLink(CHECK_PAD, PADRead + 223);
data[i + 223] = branchAndLink(CHECK_STATUS, PADRead + 223);
break;
case 6:
data[i + 219] = 0x38750000; // addi r3, r21, 0
data[i + 220] = 0x389F0000; // addi r4, r31, 0
data[i + 221] = branchAndLink(CHECK_PAD, PADRead + 221);
data[i + 221] = branchAndLink(CHECK_STATUS, PADRead + 221);
break;
case 7:
data[i + 216] = 0x7F63DB78; // mr r3, r27
data[i + 217] = 0x7F24CB78; // mr r4, r25
data[i + 218] = branchAndLink(CHECK_PAD, PADRead + 218);
data[i + 218] = branchAndLink(CHECK_STATUS, PADRead + 218);
break;
case 8:
data[i + 176] = 0x38790000; // addi r3, r25, 0
data[i + 177] = 0x38970000; // addi r4, r23, 0
data[i + 178] = branchAndLink(CHECK_PAD, PADRead + 178);
data[i + 178] = branchAndLink(CHECK_STATUS, PADRead + 178);
break;
}
}
Expand Down

0 comments on commit 19c2792

Please sign in to comment.