Skip to content

Commit

Permalink
- Save device code in SRAM.
Browse files Browse the repository at this point in the history
- Report type of disc drive.
  • Loading branch information
Extrems committed Feb 24, 2025
1 parent 5e74fe7 commit efdcd23
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 27 deletions.
5 changes: 3 additions & 2 deletions cube/swiss/include/swiss.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions cube/swiss/source/devices/dvd/deviceHandler-DVD.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,34 +317,36 @@ 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:
case 0x20020823:
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;
Expand All @@ -361,7 +363,6 @@ bool deviceHandler_Flippy_test() {
return true;
}
}

return false;
}

Expand Down
9 changes: 4 additions & 5 deletions cube/swiss/source/devices/gcloader/deviceHandler-gcloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,17 @@ 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);

__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) {
Expand Down Expand Up @@ -319,7 +319,6 @@ bool deviceHandler_GCLoader_test() {
}
return true;
}

return false;
}

Expand Down
12 changes: 6 additions & 6 deletions cube/swiss/source/gui/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ 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 {
strcpy(topStr, device->hwName);
}
}
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) {
Expand Down Expand Up @@ -74,30 +74,30 @@ 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");
}
else {
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");
}
else {
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)) {
Expand Down
20 changes: 14 additions & 6 deletions cube/swiss/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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"));
Expand Down
2 changes: 1 addition & 1 deletion cube/swiss/source/swiss.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit efdcd23

Please sign in to comment.