diff --git a/cube/patches/stub/asmfunc.S b/cube/patches/stub/asmfunc.S index 8b830ee9..e82727eb 100644 --- a/cube/patches/stub/asmfunc.S +++ b/cube/patches/stub/asmfunc.S @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2024, Extrems + * Copyright (c) 2020-2025, Extrems * * This file is part of Swiss. * @@ -65,13 +65,37 @@ xmit_spi: srwi r3, r0, 24 blr + .globl dvd_reset +dvd_reset: + lis r3, 0x0C00 + li r4, 0x3000 + 9*4 + eciwx r0, r4, r3 + rlwinm r0, r0, 0, 30, 28 + ori r0, r0, 0b001 + ecowx r0, r4, r3 + mftb r5 +1: mftb r6 + sub r0, r6, r5 + cmplwi r0, 486 + blt 1b + eciwx r0, r4, r3 + ori r0, r0, 0b101 + ecowx r0, r4, r3 + blr + .globl dvd_inquiry dvd_inquiry: lis r6, 0x1200 - li r5, 0 +1: li r5, 0 li r4, 32 b dvd_readdma + .globl dvd_read_id +dvd_read_id: + lis r6, 0xA800 + ori r6, r6, 0x0040 + b 1b + .globl dvd_read dvd_read: lis r6, 0xA800 @@ -115,6 +139,20 @@ dvd_readdma: 3: li r3, 0 blr + .globl dvd_stop_motor +dvd_stop_motor: + lis r3, 0x0C00 + li r4, 0x6000 + 2*4 + lis r0, 0xE300 + ecowx r0, r4, r3 + li r4, 0x6000 + 7*4 + li r0, 0b001 + ecowx r0, r4, r3 +1: eciwx r0, r4, r3 + andi. r0, r0, 0b001 + bne 1b + blr + .globl flippy_reset flippy_reset: lis r3, 0x0C00 diff --git a/cube/patches/stub/main.c b/cube/patches/stub/main.c index e3fba1da..9d602c6c 100644 --- a/cube/patches/stub/main.c +++ b/cube/patches/stub/main.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2024, Extrems + * Copyright (c) 2020-2025, Extrems * * This file is part of Swiss. * @@ -51,8 +51,11 @@ static bool memeq(const void *a, const void *b, size_t size) return true; } +void dvd_reset(void); uint32_t dvd_inquiry(DVDDriveInfo *info); +uint32_t dvd_read_id(DVDDiskID *id); uint32_t dvd_read(void *address, uint32_t length, uint32_t offset); +void dvd_stop_motor(void); void flippy_reset(void); static void dvd_load(uint32_t offset) @@ -89,6 +92,15 @@ void dvd_main(void) if (!dvd_inquiry(&info)) return; switch (info.releaseDate) { + case 0x20196C64: + { + dvd_stop_motor(); + dvd_reset(); + dly_us(1150 * 1000); + dvd_reset(); + if (!dvd_read_id(NULL)) return; + break; + } case 0x20220426: flippy_reset(); case 0x20220420: diff --git a/cube/swiss/source/devices/gcloader/deviceHandler-gcloader.c b/cube/swiss/source/devices/gcloader/deviceHandler-gcloader.c index dee44fdb..74b6161a 100644 --- a/cube/swiss/source/devices/gcloader/deviceHandler-gcloader.c +++ b/cube/swiss/source/devices/gcloader/deviceHandler-gcloader.c @@ -44,7 +44,20 @@ s32 deviceHandler_GCLoader_readFile(file_handle* file, void* buffer, u32 length) static char *bootFile_names[] = {"boot.iso", "boot.iso.iso", "boot.gcm", "boot.gcm.gcm"}; -static s32 setupFile(file_handle* file, file_handle* file2, ExecutableFile* filesToPatch, int numToPatch) { +bool gcloaderGetBootFile(file_handle* file) { + int i; + for(i = 0; i < sizeof(bootFile_names)/sizeof(char*); i++) { + memset(file, 0, sizeof(file_handle)); + concat_path(file->name, initial_GCLoader.name, bootFile_names[i]); + + if(!deviceHandler_FAT_statFile(file)) { + return true; + } + } + return false; +} + +static s32 gcloaderSetupFile(file_handle* file, file_handle* file2, ExecutableFile* filesToPatch, int numToPatch) { // GCLoader disc/file fragment setup file_frag *disc1FragList = NULL, *disc2FragList = NULL; u32 disc1Frags = 0, disc2Frags = 0; @@ -113,7 +126,7 @@ s32 deviceHandler_GCLoader_setupFile(file_handle* file, file_handle* file2, Exec file_frag *fragList = NULL; u32 numFrags = 0; - if(!setupFile(file, file2, filesToPatch, numToPatch)) { + if(!gcloaderSetupFile(file, file2, filesToPatch, numToPatch)) { return 0; } if(numToPatch < 0 || !devices[DEVICE_CUR]->emulated()) { @@ -145,15 +158,9 @@ s32 deviceHandler_GCLoader_setupFile(file_handle* file, file_handle* file2, Exec } } - for(i = 0; i < sizeof(bootFile_names)/sizeof(char*); i++) { - file_handle bootFile; - memset(&bootFile, 0, sizeof(file_handle)); - concat_path(bootFile.name, initial_GCLoader.name, bootFile_names[i]); - - if(getFragments(DEVICE_CUR, &bootFile, &fragList, &numFrags, FRAGS_BOOT_GCM, 0, UINT32_MAX)) { - devices[DEVICE_CUR]->closeFile(&bootFile); - break; - } + if(gcloaderGetBootFile(&patchFile)) { + getFragments(DEVICE_CUR, &patchFile, &fragList, &numFrags, FRAGS_BOOT_GCM, 0, UINT32_MAX); + devices[DEVICE_CUR]->closeFile(&patchFile); } if(swissSettings.igrType == IGR_APPLOADER || endsWith(file->name,".tgc")) { @@ -243,16 +250,10 @@ s32 deviceHandler_GCLoader_init(file_handle* file){ s32 deviceHandler_GCLoader_closeFile(file_handle* file) { if(file && file->status == STATUS_MAPPED) { - int i; - for(i = 0; i < sizeof(bootFile_names)/sizeof(char*); i++) { - file_handle bootFile; - memset(&bootFile, 0, sizeof(file_handle)); - concat_path(bootFile.name, initial_GCLoader.name, bootFile_names[i]); - - if(setupFile(&bootFile, NULL, NULL, -1)) { - deviceHandler_FAT_closeFile(&bootFile); - break; - } + file_handle bootFile; + if(gcloaderGetBootFile(&bootFile)) { + gcloaderSetupFile(&bootFile, NULL, NULL, -1); + deviceHandler_FAT_closeFile(&bootFile); } file->status = STATUS_NOT_MAPPED; } diff --git a/cube/swiss/source/devices/gcloader/deviceHandler-gcloader.h b/cube/swiss/source/devices/gcloader/deviceHandler-gcloader.h index aa28507a..d7015f3f 100644 --- a/cube/swiss/source/devices/gcloader/deviceHandler-gcloader.h +++ b/cube/swiss/source/devices/gcloader/deviceHandler-gcloader.h @@ -11,5 +11,7 @@ extern DEVICEHANDLER_INTERFACE __device_gcloader; +bool gcloaderGetBootFile(file_handle* file); + #endif diff --git a/cube/swiss/source/swiss.c b/cube/swiss/source/swiss.c index 863125f7..7a9018cf 100644 --- a/cube/swiss/source/swiss.c +++ b/cube/swiss/source/swiss.c @@ -1349,6 +1349,16 @@ void boot_dol(file_handle* file, int argc, char *argv[]) devices[DEVICE_CUR]->statFile(imageFile); } + file_handle *bootFile = NULL; + if(devices[DEVICE_CUR] == &__device_gcloader) { + bootFile = calloc(1, sizeof(file_handle)); + + if(!gcloaderGetBootFile(bootFile)) { + free(bootFile); + bootFile = NULL; + } + } + // Build a command line to pass to the DOL char *argz = getExternalPath(imageFile->fileType == IS_FILE ? imageFile->name : file->name); size_t argz_len = strlen(argz) + 1; @@ -1412,7 +1422,7 @@ void boot_dol(file_handle* file, int argc, char *argv[]) // Boot if(devices[DEVICE_CUR]->location == LOC_DVD_CONNECTOR) { - devices[DEVICE_CUR]->setupFile(imageFile, NULL, NULL, -1); + devices[DEVICE_CUR]->setupFile(imageFile, bootFile, NULL, -1); } if(!memcmp(buffer, ELFMAG, SELFMAG)) { @@ -1430,7 +1440,9 @@ void boot_dol(file_handle* file, int argc, char *argv[]) free(argz); free(buffer); + devices[DEVICE_CUR]->closeFile(bootFile); devices[DEVICE_CUR]->closeFile(imageFile); + free(bootFile); free(imageFile); }