diff --git a/cube/swiss/include/swiss.h b/cube/swiss/include/swiss.h index 96de3be5..8889af77 100644 --- a/cube/swiss/include/swiss.h +++ b/cube/swiss/include/swiss.h @@ -39,8 +39,9 @@ extern file_handle curFile; extern file_handle curDir; extern char IPLInfo[256] __attribute__((aligned(32))); extern dvdcmdblk commandBlock; -extern dvddrvinfo driveInfo; -extern dvddiskid *DVDDiskID; +extern dvddrvinfo DVDDriveInfo; +extern u16* const DVDDeviceCode; +extern dvddiskid* DVDDiskID; extern DiskHeader GCMDisk; extern u32 sdgecko_getAddressingType(s32 drv_no); diff --git a/cube/swiss/source/devices/dvd/deviceHandler-DVD.c b/cube/swiss/source/devices/dvd/deviceHandler-DVD.c index 06f29765..033241d9 100644 --- a/cube/swiss/source/devices/dvd/deviceHandler-DVD.c +++ b/cube/swiss/source/devices/dvd/deviceHandler-DVD.c @@ -550,6 +550,34 @@ s32 deviceHandler_DVD_closeFile(file_handle* file){ } bool deviceHandler_DVD_test() { + if (*DVDDeviceCode & 0x8000) { + switch (*DVDDeviceCode & ~0x8000) { + case 0x0000: + __device_dvd.hwName = "NROM Reader"; + break; + case 0x0001: + __device_dvd.hwName = "NR Reader"; + break; + case 0x0002: + __device_dvd.hwName = "RVL-ROM Reader"; + break; + case 0x0003: + __device_dvd.hwName = "RVL-R Reader"; + break; + case 0x0200: + __device_dvd.hwName = "NPDP Reader"; + break; + case 0x0201: + __device_dvd.hwName = "GDEV"; + break; + case 0x0202: + __device_dvd.hwName = "NDEV"; + break; + case 0x0203: + __device_dvd.hwName = "RVL-H Reader"; + break; + } + } return swissSettings.hasDVDDrive != 0; } diff --git a/cube/swiss/source/devices/flippydrive/deviceHandler-flippydrive.c b/cube/swiss/source/devices/flippydrive/deviceHandler-flippydrive.c index f6dd91f1..b2dd05ce 100644 --- a/cube/swiss/source/devices/flippydrive/deviceHandler-flippydrive.c +++ b/cube/swiss/source/devices/flippydrive/deviceHandler-flippydrive.c @@ -317,7 +317,7 @@ s32 deviceHandler_Flippy_makeDir(file_handle* dir) { bool deviceHandler_Flippy_test() { if (swissSettings.hasDVDDrive == 1) { - switch (driveInfo.rel_date) { + switch (DVDDriveInfo.rel_date) { case 0x20010608: case 0x20010831: case 0x20020402: @@ -325,26 +325,28 @@ bool deviceHandler_Flippy_test() { if (flippy_bypass(false) != FLIPPY_RESULT_OK) return false; - if (DVD_Inquiry(&commandBlock, &driveInfo) < 0) { + if (DVD_Inquiry(&commandBlock, &DVDDriveInfo) < 0) { swissSettings.hasDVDDrive = 0; + *DVDDeviceCode = 0x0001; return false; } break; } - switch (driveInfo.rel_date) { + switch (DVDDriveInfo.rel_date) { case 0x20220420: if (flippy_boot(FLIPPY_MODE_BOOT) != FLIPPY_RESULT_OK || flippy_boot(FLIPPY_MODE_NOUPDATE) != FLIPPY_RESULT_OK) return false; - while (driveInfo.rel_date != 0x20220426) { - if (DVD_Inquiry(&commandBlock, &driveInfo) < 0) { + while (DVDDriveInfo.rel_date != 0x20220426) { + if (DVD_Inquiry(&commandBlock, &DVDDriveInfo) < 0) { swissSettings.hasDVDDrive = 0; + *DVDDeviceCode = 0x0001; return false; } } case 0x20220426: - flippyversion *version = (flippyversion *)driveInfo.pad; + flippyversion *version = (flippyversion *)DVDDriveInfo.pad; u32 flippy_version = FLIPPY_VERSION(version->major, version->minor, version->build); __device_flippy.quirks = QUIRK_NO_DEINIT; @@ -361,7 +363,6 @@ bool deviceHandler_Flippy_test() { return true; } } - return false; } diff --git a/cube/swiss/source/devices/gcloader/deviceHandler-gcloader.c b/cube/swiss/source/devices/gcloader/deviceHandler-gcloader.c index 22e0dd93..27a66d5f 100644 --- a/cube/swiss/source/devices/gcloader/deviceHandler-gcloader.c +++ b/cube/swiss/source/devices/gcloader/deviceHandler-gcloader.c @@ -275,8 +275,8 @@ bool deviceHandler_GCLoader_test() { gcloaderVersionStr = NULL; gcloaderHwVersion = 0; - if (swissSettings.hasDVDDrive == 1 && driveInfo.rel_date == 0x20196c64) { - if (driveInfo.pad[1] == 'w') + if (swissSettings.hasDVDDrive == 1 && DVDDriveInfo.rel_date == 0x20196c64) { + if (DVDDriveInfo.pad[1] == 'w') __device_gcloader.features |= (FEAT_WRITE | FEAT_CONFIG_DEVICE | FEAT_PATCHES); else __device_gcloader.features &= ~(FEAT_WRITE | FEAT_CONFIG_DEVICE | FEAT_PATCHES); @@ -284,8 +284,8 @@ bool deviceHandler_GCLoader_test() { __device_gcloader.quirks = QUIRK_NONE; if (gcloaderReadId() == 0xAAAAAAAA) { - gcloaderHwVersion = driveInfo.pad[2] + 1; - gcloaderVersionStr = gcloaderGetVersion(driveInfo.pad[2]); + gcloaderHwVersion = DVDDriveInfo.pad[2] + 1; + gcloaderVersionStr = gcloaderGetVersion(DVDDriveInfo.pad[2]); if (gcloaderVersionStr) { switch (gcloaderHwVersion) { @@ -319,7 +319,6 @@ bool deviceHandler_GCLoader_test() { } return true; } - return false; } diff --git a/cube/swiss/source/gui/info.c b/cube/swiss/source/gui/info.c index 44f6a3b4..c1f35694 100644 --- a/cube/swiss/source/gui/info.c +++ b/cube/swiss/source/gui/info.c @@ -28,7 +28,7 @@ const char* getDeviceInfoString(u32 location) { } else if(device == &__device_dvd) { if(swissSettings.hasDVDDrive == 1) { - u8* driveVersion = (u8*)&driveInfo; + u8* driveVersion = (u8*)&DVDDriveInfo; sprintf(topStr,"%s %02X %02X%02X/%02X (%02X)",device->hwName,driveVersion[6],driveVersion[4],driveVersion[5],driveVersion[7],driveVersion[8]); } else { @@ -36,7 +36,7 @@ const char* getDeviceInfoString(u32 location) { } } else if(device == &__device_flippy) { - flippyversion *version = (flippyversion*)driveInfo.pad; + flippyversion *version = (flippyversion*)DVDDriveInfo.pad; sprintf(topStr, "%s (%u.%u.%u%s)", device->hwName, version->major, version->minor, version->build, version->dirty ? "-dirtyboi" : ""); } else if(device == &__device_gcloader) { @@ -74,14 +74,14 @@ uiDrawObj_t * info_draw_page(int page_num) { // Model DrawAddChild(container, DrawStyledLabel(640/2, 90, (char*)"MODEL", 0.65f, true, defaultColor)); if(!strncmp(IPLInfo, "(C) ", 4)) { - if(driveInfo.dev_code == 0x0201) { + if(*DVDDeviceCode == 0x8201) { strcpy(topStr, "NPDP-GDEV (GCT-0100)"); } else if(!strncmp(&IPLInfo[0x55], "TDEV", 4) || !strncmp(&IPLInfo[0x55], "DEV Revision 0.1", 0x11)) { strcpy(topStr, "Nintendo GameCube DOT-006"); } - else if(driveInfo.dev_code == 0x0200) { + else if(*DVDDeviceCode == 0x8200) { if(!strncmp(&IPLInfo[0x55], "PAL ", 4)) { strcpy(topStr, "Nintendo GameCube DOT-002P"); } @@ -89,7 +89,7 @@ uiDrawObj_t * info_draw_page(int page_num) { strcpy(topStr, "Nintendo GameCube DOT-002"); } } - else if(driveInfo.dev_code == 0x0001) { + else if(*DVDDeviceCode == 0x8001) { if(!strncmp(&IPLInfo[0x55], "PAL ", 4)) { strcpy(topStr, "Nintendo GameCube DOT-001P"); } @@ -97,7 +97,7 @@ uiDrawObj_t * info_draw_page(int page_num) { strcpy(topStr, "Nintendo GameCube DOT-001"); } } - else if(driveInfo.dev_code == 0x0000 && driveInfo.pad[1] == 'M') { + else if(*DVDDeviceCode == 0x8000 && DVDDriveInfo.pad[1] == 'M') { strcpy(topStr, "Panasonic Q SL-GC10-S"); } else if(!strncmp(&IPLInfo[0x55], "PAL Revision 1.2", 0x11)) { diff --git a/cube/swiss/source/main.c b/cube/swiss/source/main.c index 69a283f1..e823031f 100644 --- a/cube/swiss/source/main.c +++ b/cube/swiss/source/main.c @@ -40,26 +40,34 @@ #include "devices/filemeta.h" dvdcmdblk commandBlock; -dvddrvinfo driveInfo __attribute__((aligned(32))); -dvddiskid *DVDDiskID = (dvddiskid*)0x80000000; +dvddrvinfo DVDDriveInfo __attribute__((aligned(32))); +u16* const DVDDeviceCode = (u16*)0x800030E6; +dvddiskid* DVDDiskID = (dvddiskid*)0x80000000; SwissSettings swissSettings; static void driveInfoCallback(s32 result, dvdcmdblk *block) { if(result == DVD_ERROR_CANCELED) { DVD_StopMotorAsync(block, NULL); + return; } else if(result == DVD_ERROR_FATAL) { swissSettings.hasDVDDrive = 0; - *(u16*)0x800030E6 = 0x0001; + *DVDDeviceCode = 0x0001; } else if(result >= 0) { swissSettings.hasDVDDrive = 1; - *(u16*)0x800030E6 = 0x8000 | driveInfo.dev_code; + *DVDDeviceCode = 0x8000 | DVDDriveInfo.dev_code; } + syssramex* sramex = __SYS_LockSramEx(); + sramex->dvddev_code = *DVDDeviceCode; + __SYS_UnlockSramEx(TRUE); } static void resetCoverCallback(s32 result) { swissSettings.hasDVDDrive = 2; + syssramex* sramex = __SYS_LockSramEx(); + *DVDDeviceCode = sramex->dvddev_code; + __SYS_UnlockSramEx(FALSE); DVD_Pause(); DVD_Reset(DVD_RESETSOFT); } @@ -73,7 +81,7 @@ void Initialise(void) DVD_Reset(DVD_RESETNONE); while(DVD_LowGetCoverStatus() == DVD_COVER_RESET); DVD_LowSetResetCoverCallback(NULL); - DVD_InquiryAsync(&commandBlock, &driveInfo, driveInfoCallback); + DVD_InquiryAsync(&commandBlock, &DVDDriveInfo, driveInfoCallback); // Disable IPL modchips to allow access to IPL ROM fonts ipl_set_config(6); @@ -304,7 +312,7 @@ int main(int argc, char *argv[]) } } else if(device == &__device_flippy) { - flippyversion *version = (flippyversion*)driveInfo.pad; + flippyversion *version = (flippyversion*)DVDDriveInfo.pad; u32 flippy_version = FLIPPY_VERSION(version->major, version->minor, version->build); if(flippy_version < FLIPPY_VERSION(FLIPPY_MINVER_MAJOR, FLIPPY_MINVER_MINOR, FLIPPY_MINVER_BUILD)) { uiDrawObj_t *msgBox = DrawPublish(DrawMessageBox(D_WARN, "A firmware update is required.\nflippydrive.com/updates")); diff --git a/cube/swiss/source/swiss.c b/cube/swiss/source/swiss.c index 829a2a31..6aa14ee9 100644 --- a/cube/swiss/source/swiss.c +++ b/cube/swiss/source/swiss.c @@ -2279,7 +2279,7 @@ void load_file() uiDrawObj_t *progBar = DrawPublish(DrawProgressBar(true, 0, "Resetting RP2040")); flippy_closefrom(1); flippy_reset(); - DVD_Inquiry(&commandBlock, &driveInfo); + DVD_Inquiry(&commandBlock, &DVDDriveInfo); flippy_boot(FLIPPY_MODE_UPDATE); flippybootstatus *status; while((status = flippy_getbootstatus()) && status->current_progress != 0xFFFF) {