Skip to content

Commit

Permalink
- Detect disc drive quicker from a cold boot.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Feb 24, 2025
1 parent 0d67aa7 commit 5e74fe7
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 29 deletions.
1 change: 0 additions & 1 deletion cube/swiss/include/swiss.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ extern dvddrvinfo driveInfo;
extern dvddiskid *DVDDiskID;
extern DiskHeader GCMDisk;

extern s32 DVD_LowGetCoverStatus(void);
extern u32 sdgecko_getAddressingType(s32 drv_no);
extern u32 sdgecko_getTransferMode(s32 drv_no);
extern u32 sdgecko_getDevice(s32 drv_no);
Expand Down
3 changes: 1 addition & 2 deletions cube/swiss/source/devices/dvd/deviceHandler-DVD.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ s32 deviceHandler_DVD_init(file_handle* file){

file->status = initialize_disc(ENABLE_BYDISK);
dvd_init = file->status != DRV_ERROR;
return !dvd_init;
return dvd_init ? 0 : EIO;
}

s32 deviceHandler_DVD_deinit(file_handle* file) {
Expand All @@ -550,7 +550,6 @@ s32 deviceHandler_DVD_closeFile(file_handle* file){
}

bool deviceHandler_DVD_test() {
while(DVD_LowGetCoverStatus() == 0);
return swissSettings.hasDVDDrive != 0;
}

Expand Down
11 changes: 6 additions & 5 deletions cube/swiss/source/devices/dvd/dvd.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ volatile unsigned long* dvd = (volatile unsigned long*)0xCC006000;

void dvd_reset()
{
dvd[1] = 2;
volatile unsigned long v = *(volatile unsigned long*)0xcc003024;
*(volatile unsigned long*)0xcc003024 = (v & ~4) | 1;
sleep(1);
*(volatile unsigned long*)0xcc003024 = v | 5;
DVD_Pause();
DVD_Reset(DVD_RESETHARD);
usleep(1150000);
DVD_Reset(DVD_RESETHARD);
DVD_Resume();
while(DVD_GetDriveStatus() == DVD_STATE_BUSY);
}

unsigned int dvd_read_id()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,7 @@ s32 deviceHandler_Flippy_makeDir(file_handle* dir) {
}

bool deviceHandler_Flippy_test() {
while (DVD_LowGetCoverStatus() == 0);

if (swissSettings.hasDVDDrive) {
if (swissSettings.hasDVDDrive == 1) {
switch (driveInfo.rel_date) {
case 0x20010608:
case 0x20010831:
Expand Down
5 changes: 1 addition & 4 deletions cube/swiss/source/devices/flippydrive/flippy.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <stdbool.h>
#include <string.h>
#include <ogc/dvd.h>
#include <ogc/dvdlow.h>
#include <ogc/irq.h>
#include <ogc/lwp.h>
#include <ogc/machine/processor.h>
Expand Down Expand Up @@ -63,10 +64,6 @@
((dvdcmdbuf){(((0xDC) << 24)), (0xE3F72BAB), (0x72648977)})

typedef void (*flippycallback)(flippyfile *file);
typedef void (*dvdcallbacklow)(s32 result);

extern s32 DVD_LowWaitCoverClose(dvdcallbacklow cb);
extern dvdcallbacklow DVD_LowClearCallback(void);

static dvddrvinfo driveinfo ATTRIBUTE_ALIGN(32);
static flippybootstatus bootstatus ATTRIBUTE_ALIGN(32);
Expand Down
4 changes: 1 addition & 3 deletions cube/swiss/source/devices/gcloader/deviceHandler-gcloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,7 @@ bool deviceHandler_GCLoader_test() {
gcloaderVersionStr = NULL;
gcloaderHwVersion = 0;

while (DVD_LowGetCoverStatus() == 0);

if (swissSettings.hasDVDDrive && driveInfo.rel_date == 0x20196c64) {
if (swissSettings.hasDVDDrive == 1 && driveInfo.rel_date == 0x20196c64) {
if (driveInfo.pad[1] == 'w')
__device_gcloader.features |= (FEAT_WRITE | FEAT_CONFIG_DEVICE | FEAT_PATCHES);
else
Expand Down
2 changes: 2 additions & 0 deletions cube/swiss/source/devices/system/deviceHandler-SYS.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ bool is_rom_name(char* filename) {
}

s32 deviceHandler_SYS_init(file_handle* file) {
if(swissSettings.hasDVDDrive > 1) dvd_reset();

AR_Init(NULL, 0);
ARQ_Init();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ s32 deviceHandler_WKF_setupFile(file_handle* file, file_handle* file2, Executabl
}

bool deviceHandler_WKF_test() {
while(DVD_LowGetCoverStatus() == 0);
return swissSettings.hasDVDDrive && (__wkfSpiReadId() != 0 && __wkfSpiReadId() != 0xFFFFFFFF);
return swissSettings.hasDVDDrive == 1 && (__wkfSpiReadId() != 0 && __wkfSpiReadId() != 0xFFFFFFFF);
}

s32 deviceHandler_WKF_init(file_handle* file){
Expand Down
3 changes: 1 addition & 2 deletions cube/swiss/source/devices/wode/deviceHandler-WODE.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,7 @@ static const dvddiskid WODEExtCFG = {
};

bool deviceHandler_WODE_test() {
while(DVD_LowGetCoverStatus() == 0);
return swissSettings.hasDVDDrive && !memcmp(DVDDiskID, &WODEExtCFG, sizeof(dvddiskid));
return swissSettings.hasDVDDrive == 1 && !memcmp(DVDDiskID, &WODEExtCFG, sizeof(dvddiskid));
}

u32 deviceHandler_WODE_emulated() {
Expand Down
9 changes: 7 additions & 2 deletions cube/swiss/source/gui/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ const char* getDeviceInfoString(u32 location) {
sprintf(topStr, "%s (%s)", getHwNameByLocation(location), bba_address_str());
}
else if(device == &__device_dvd) {
u8* driveVersion = (u8*)&driveInfo;
sprintf(topStr,"%s %02X %02X%02X/%02X (%02X)",device->hwName,driveVersion[6],driveVersion[4],driveVersion[5],driveVersion[7],driveVersion[8]);
if(swissSettings.hasDVDDrive == 1) {
u8* driveVersion = (u8*)&driveInfo;
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;
Expand Down
26 changes: 21 additions & 5 deletions cube/swiss/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <gccore.h> /*** Wrapper to include common libogc headers ***/
#include <ogcsys.h> /*** Needed for console support ***/
#include <ogc/color.h>
#include <ogc/dvdlow.h>
#include <ogc/exi.h>
#include <ogc/lwp.h>
#include <ogc/usbgecko.h>
Expand Down Expand Up @@ -47,20 +48,33 @@ static void driveInfoCallback(s32 result, dvdcmdblk *block) {
if(result == DVD_ERROR_CANCELED) {
DVD_StopMotorAsync(block, NULL);
}
else if(result == DVD_ERROR_FATAL) {
swissSettings.hasDVDDrive = 0;
*(u16*)0x800030E6 = 0x0001;
}
else if(result >= 0) {
swissSettings.hasDVDDrive = 1;
*(u16*)0x800030E6 = 0x8000 | driveInfo.dev_code;
}
}

static void resetCoverCallback(s32 result) {
swissSettings.hasDVDDrive = 2;
DVD_Pause();
DVD_Reset(DVD_RESETSOFT);
}

/* Initialise Video, PAD, DVD, Font */
void Initialise(void)
{
PAD_Init ();
DVD_Init();
DVD_LowSetResetCoverCallback(resetCoverCallback);
DVD_Reset(DVD_RESETNONE);
while(DVD_LowGetCoverStatus() == DVD_COVER_RESET);
DVD_LowSetResetCoverCallback(NULL);
DVD_InquiryAsync(&commandBlock, &driveInfo, driveInfoCallback);

// Disable IPL modchips to allow access to IPL ROM fonts
ipl_set_config(6);
usleep(1000); //wait for modchip to disable (overkill)
Expand Down Expand Up @@ -282,9 +296,11 @@ int main(int argc, char *argv[])

DEVICEHANDLER_INTERFACE *device = getDeviceByLocation(LOC_DVD_CONNECTOR);
if(device == &__device_dvd) {
// DVD Motor off setting
if(swissSettings.stopMotor) {
DVD_StopMotor(&commandBlock);
if(DVD_GetCmdBlockStatus(&commandBlock) == DVD_STATE_END) {
// DVD Motor off setting
if(swissSettings.stopMotor) {
DVD_StopMotor(&commandBlock);
}
}
}
else if(device == &__device_flippy) {
Expand Down Expand Up @@ -349,7 +365,7 @@ int main(int argc, char *argv[])
void populateDeviceAvailability() {
uiDrawObj_t *msgBox = DrawPublish(DrawProgressBar(true, 0, "Detecting devices\205\nThis can be skipped by holding B next time"));
while(DVD_GetCmdBlockStatus(&commandBlock) == DVD_STATE_BUSY) {
if(DVD_LowGetCoverStatus() == 1) {
if(DVD_LowGetCoverStatus() == DVD_COVER_OPEN) {
break;
}
if(padsButtonsHeld() & PAD_BUTTON_B) {
Expand Down

0 comments on commit 5e74fe7

Please sign in to comment.