Skip to content

Commit

Permalink
- Ensure all devices are deinitialized on exit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Dec 23, 2024
1 parent 128f792 commit 6e2d50c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
23 changes: 23 additions & 0 deletions cube/swiss/source/devices/deviceHandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,29 @@ DEVICEHANDLER_INTERFACE* allDevices[MAX_DEVICES]; // All devices registered in S
DEVICEHANDLER_INTERFACE* devices[MAX_DEVICE_SLOTS]; // Currently used devices


static s32 onreset(s32 final)
{
if (!final) {
for (int i = 0; i < MAX_DEVICE_SLOTS; i++) {
if (devices[i] && !(devices[i]->quirks & QUIRK_NO_DEINIT)) {
devices[i]->deinit(devices[i]->initial);
devices[i] = NULL;
}
}
}
return TRUE;
}

static sys_resetinfo resetinfo = {
{NULL, NULL}, onreset, 0
};

__attribute((constructor))
static void registerResetFunc() {
SYS_RegisterResetFunc(&resetinfo);
}


// Device stat global disable status
static int statEnabled = 1;
void deviceHandler_setStatEnabled(int enable) {statEnabled = enable;}
Expand Down
6 changes: 4 additions & 2 deletions cube/swiss/source/swiss.c
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,9 @@ void load_app(ExecutableFile *fileToPatch)
// Check DVD Status, make sure it's error code 0
print_gecko("DVD: %08X\r\n",dvd_get_error());
}
if(devices[DEVICE_PATCHES] && !(devices[DEVICE_PATCHES]->quirks & QUIRK_NO_DEINIT)) {
devices[DEVICE_PATCHES]->deinit(devices[DEVICE_PATCHES]->initial);
}

DrawDispose(progBox);
DrawShutdown();
Expand Down Expand Up @@ -1388,7 +1391,6 @@ void boot_dol(file_handle* file, int argc, char *argv[])
argz_add(&argz, &argz_len, argv[i]);
}

if(devices[DEVICE_CUR] != NULL) devices[DEVICE_CUR]->deinit( devices[DEVICE_CUR]->initial );
// Boot
if(!memcmp(dol_buffer, ELFMAG, SELFMAG)) {
ELFtoARAM(dol_buffer, argz, argz_len);
Expand Down Expand Up @@ -2164,7 +2166,7 @@ void load_game() {
*(vu8*)VAR_EXI_CPR = (EXI_CHANNEL_MAX << 6) | EXI_SPEED1MHZ;
*(vu8*)VAR_EXI2_CPR = (EXI_CHANNEL_MAX << 6) | EXI_SPEED1MHZ;
*(vu32**)VAR_EXI_REGS = NULL;
net_get_mac_address(VAR_CLIENT_MAC);
net_get_mac_address((u8*)VAR_CLIENT_MAC);
*(vu32**)VAR_EXI2_REGS = NULL;
*(vu8*)VAR_TRIGGER_LEVEL = swissSettings.triggerLevel;
*(vu8*)VAR_CARD_A_ID = 0x00;
Expand Down

0 comments on commit 6e2d50c

Please sign in to comment.