Skip to content

Commit 6e2d50c

Browse files
committed
- Ensure all devices are deinitialized on exit.
1 parent 128f792 commit 6e2d50c

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

cube/swiss/source/devices/deviceHandler.c

+23
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,29 @@ DEVICEHANDLER_INTERFACE* allDevices[MAX_DEVICES]; // All devices registered in S
2121
DEVICEHANDLER_INTERFACE* devices[MAX_DEVICE_SLOTS]; // Currently used devices
2222

2323

24+
static s32 onreset(s32 final)
25+
{
26+
if (!final) {
27+
for (int i = 0; i < MAX_DEVICE_SLOTS; i++) {
28+
if (devices[i] && !(devices[i]->quirks & QUIRK_NO_DEINIT)) {
29+
devices[i]->deinit(devices[i]->initial);
30+
devices[i] = NULL;
31+
}
32+
}
33+
}
34+
return TRUE;
35+
}
36+
37+
static sys_resetinfo resetinfo = {
38+
{NULL, NULL}, onreset, 0
39+
};
40+
41+
__attribute((constructor))
42+
static void registerResetFunc() {
43+
SYS_RegisterResetFunc(&resetinfo);
44+
}
45+
46+
2447
// Device stat global disable status
2548
static int statEnabled = 1;
2649
void deviceHandler_setStatEnabled(int enable) {statEnabled = enable;}

cube/swiss/source/swiss.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,9 @@ void load_app(ExecutableFile *fileToPatch)
12111211
// Check DVD Status, make sure it's error code 0
12121212
print_gecko("DVD: %08X\r\n",dvd_get_error());
12131213
}
1214+
if(devices[DEVICE_PATCHES] && !(devices[DEVICE_PATCHES]->quirks & QUIRK_NO_DEINIT)) {
1215+
devices[DEVICE_PATCHES]->deinit(devices[DEVICE_PATCHES]->initial);
1216+
}
12141217

12151218
DrawDispose(progBox);
12161219
DrawShutdown();
@@ -1388,7 +1391,6 @@ void boot_dol(file_handle* file, int argc, char *argv[])
13881391
argz_add(&argz, &argz_len, argv[i]);
13891392
}
13901393

1391-
if(devices[DEVICE_CUR] != NULL) devices[DEVICE_CUR]->deinit( devices[DEVICE_CUR]->initial );
13921394
// Boot
13931395
if(!memcmp(dol_buffer, ELFMAG, SELFMAG)) {
13941396
ELFtoARAM(dol_buffer, argz, argz_len);
@@ -2164,7 +2166,7 @@ void load_game() {
21642166
*(vu8*)VAR_EXI_CPR = (EXI_CHANNEL_MAX << 6) | EXI_SPEED1MHZ;
21652167
*(vu8*)VAR_EXI2_CPR = (EXI_CHANNEL_MAX << 6) | EXI_SPEED1MHZ;
21662168
*(vu32**)VAR_EXI_REGS = NULL;
2167-
net_get_mac_address(VAR_CLIENT_MAC);
2169+
net_get_mac_address((u8*)VAR_CLIENT_MAC);
21682170
*(vu32**)VAR_EXI2_REGS = NULL;
21692171
*(vu8*)VAR_TRIGGER_LEVEL = swissSettings.triggerLevel;
21702172
*(vu8*)VAR_CARD_A_ID = 0x00;

0 commit comments

Comments
 (0)