From f08aada59b830c0758fe3291e9b6935b571c370f Mon Sep 17 00:00:00 2001 From: shulkmaster Date: Wed, 2 Dec 2026 10:08:17 -0600 Subject: [PATCH 1/2] Dvd SK units cleanup --- src/dolphin/dvd/dvd.c | 223 +++++++++++++++++++------------------ src/dolphin/dvd/dvdfs.c | 24 ++-- src/dolphin/dvd/dvdlow.c | 33 +++--- src/dolphin/dvd/dvdqueue.c | 8 +- 4 files changed, 148 insertions(+), 140 deletions(-) diff --git a/src/dolphin/dvd/dvd.c b/src/dolphin/dvd/dvd.c index a347e6b..560c30d 100644 --- a/src/dolphin/dvd/dvd.c +++ b/src/dolphin/dvd/dvd.c @@ -125,7 +125,7 @@ void DVDInit() { } static void stateReadingFST() { - LastState = (stateFunc)stateReadingFST; + LastState = stateReadingFST; if (bootInfo->FSTMaxLength < BB2.FSTLength) { #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2002_09 @@ -146,7 +146,7 @@ static void cbForStateReadingFST(u32 intType) { if (intType == 16) { #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02 - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; #endif stateTimeout(); return; @@ -157,7 +157,7 @@ static void cbForStateReadingFST(u32 intType) { __DVDFSInit(); finished = executing; executing = &DummyCommandBlock; - finished->state = 0; + finished->state = DVD_STATE_END; if (finished->callback) { (finished->callback)(0, finished); } @@ -179,11 +179,11 @@ static void cbForStateError(u32 intType) { DVDCommandBlock* finished; #if SDK_VERSION >= SDK_VERSION_DOLPHIN_2003_04 - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; #endif if (intType == 16) { #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02 - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; #endif stateTimeout(); return; @@ -259,7 +259,7 @@ inline static BOOL CheckCancel(u32 resume) { finished = executing; executing = &DummyCommandBlock; - finished->state = 10; + finished->state = DVD_STATE_CANCELED; if (finished->callback) (*finished->callback)(-3, finished); if (CancelCallback) @@ -278,7 +278,7 @@ static void cbForStateGettingError(u32 intType) { if (intType == 16) { #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02 - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; #endif stateTimeout(); return; @@ -286,7 +286,7 @@ static void cbForStateGettingError(u32 intType) { if (intType & 2) { #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02 - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; #endif stateError(0x1234567); return; @@ -299,7 +299,7 @@ static void cbForStateGettingError(u32 intType) { if (errorCategory == 1) { #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02 - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; #endif stateError(error); return; @@ -337,20 +337,20 @@ static void cbForStateGettingError(u32 intType) { } if (status == 0x01000000) { - executing->state = 5; + executing->state = DVD_STATE_COVER_OPEN; stateMotorStopped(); return; } else if (status == 0x02000000) { - executing->state = 3; + executing->state = DVD_STATE_COVER_CLOSED; stateCoverClosed(); return; } else if (status == 0x03000000) { - executing->state = 4; + executing->state = DVD_STATE_NO_DISK; stateMotorStopped(); return; } else { #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02 - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; #endif stateError(0x1234567); return; @@ -360,7 +360,7 @@ static void cbForStateGettingError(u32 intType) { static void cbForUnrecoveredError(u32 intType) { if (intType == 16) { #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02 - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; #endif stateTimeout(); return; @@ -377,13 +377,13 @@ static void cbForUnrecoveredError(u32 intType) { static void cbForUnrecoveredErrorRetry(u32 intType) { if (intType == 16) { #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02 - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; #endif stateTimeout(); return; } #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02 - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; #endif if (intType & 2) { @@ -401,7 +401,7 @@ static void stateGoToRetry() { DVDLowStopMotor(cbForStateGoToRetry); } static void cbForStateGoToRetry(u32 intType) { if (intType == 16) { #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02 - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; #endif stateTimeout(); return; @@ -409,7 +409,7 @@ static void cbForStateGoToRetry(u32 intType) { if (intType & 2) { #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02 - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; #endif stateError(0x1234567); return; @@ -422,7 +422,7 @@ static void cbForStateGoToRetry(u32 intType) { } if (!CheckCancel(2)) { - executing->state = 11; + executing->state = DVD_STATE_RETRY; stateMotorStopped(); } } @@ -433,7 +433,7 @@ static void stateCheckID() { if (DVDCompareDiskID(&CurrDiskID, executing->id)) { memcpy(IDShouldBe, &CurrDiskID, sizeof(DVDDiskID)); - executing->state = 1; + executing->state = DVD_STATE_BUSY; DCInvalidateRange(&BB2, sizeof(DVDBB2)); LastState = stateCheckID2a; stateCheckID2a(executing); @@ -465,7 +465,7 @@ static void stateCheckID2a() { static void cbForStateCheckID2a(u32 intType) { if (intType == 16) { #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02 - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; #endif stateTimeout(); return; @@ -487,7 +487,7 @@ static void stateCheckID2() { static void cbForStateCheckID1(u32 intType) { if (intType == 16) { #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02 - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; #endif stateTimeout(); return; @@ -495,7 +495,7 @@ static void cbForStateCheckID1(u32 intType) { if (intType & 2) { #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02 - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; #endif stateError(0x1234567); return; @@ -504,7 +504,7 @@ static void cbForStateCheckID1(u32 intType) { NumInternalRetry = 0; if (!CheckCancel(1)) { - executing->state = 6; + executing->state = DVD_STATE_WRONG_DISK; stateMotorStopped(); } } @@ -512,7 +512,7 @@ static void cbForStateCheckID1(u32 intType) { static void cbForStateCheckID2(u32 intType) { if (intType == 16) { #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02 - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; #endif stateTimeout(); return; @@ -533,7 +533,7 @@ static void cbForStateCheckID2(u32 intType) { static void cbForStateCheckID3(u32 intType) { if (intType == 16) { #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02 - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; #endif stateTimeout(); return; @@ -544,7 +544,7 @@ static void cbForStateCheckID3(u32 intType) { NumInternalRetry = 0; if (!CheckCancel(0)) { - executing->state = 1; + executing->state = DVD_STATE_BUSY; stateBusy(executing); } } else { @@ -594,7 +594,7 @@ static void stateCoverClosed_CMD(DVDCommandBlock* block) { static void cbForStateCoverClosed(u32 intType) { if (intType == 16) { #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02 - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; #endif stateTimeout(); return; @@ -612,7 +612,7 @@ static void stateMotorStopped(void) { DVDLowWaitCoverClose(cbForStateMotorStoppe static void cbForStateMotorStopped(u32 intType) { __DIRegs[1] = 0; - executing->state = 3; + executing->state = DVD_STATE_COVER_CLOSED; stateCoverClosed(); } @@ -620,20 +620,20 @@ static void stateReady() { DVDCommandBlock* finished; if (!__DVDCheckWaitingQueue()) { - executing = (DVDCommandBlock*)NULL; + executing = NULL; return; } if (PauseFlag) { PausingFlag = TRUE; - executing = (DVDCommandBlock*)NULL; + executing = NULL; return; } executing = __DVDPopWaitingQueue(); if (FatalErrorFlag) { - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; finished = executing; executing = &DummyCommandBlock; if (finished->callback) { @@ -649,36 +649,36 @@ static void stateReady() { switch (ResumeFromHere) { case 1: #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2002_09 - executing->state = 1; + executing->state = DVD_STATE_BUSY; stateCoverClosed(); #else goto cover_closed; #endif break; case 2: - executing->state = 11; + executing->state = DVD_STATE_RETRY; stateMotorStopped(); break; case 3: - executing->state = 4; + executing->state = DVD_STATE_NO_DISK; stateMotorStopped(); break; case 4: - executing->state = 5; + executing->state = DVD_STATE_COVER_OPEN; stateMotorStopped(); break; case 7: case 6: cover_closed: - executing->state = 3; + executing->state = DVD_STATE_COVER_CLOSED; stateCoverClosed(); break; case 5: #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02 - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; #endif stateError(CancelLastError); break; @@ -690,7 +690,7 @@ static void stateReady() { #else } else if (MotorState == 0) { #endif - executing->state = 1; + executing->state = DVD_STATE_BUSY; stateBusy(executing); #if SDK_VERSION >= SDK_VERSION_DOLPHIN_2003_04 } else { @@ -714,7 +714,7 @@ static void stateBusy(DVDCommandBlock* block) { if (!block->length) { finished = executing; executing = &DummyCommandBlock; - finished->state = 0; + finished->state = DVD_STATE_END; if (finished->callback) { finished->callback(0, finished); } @@ -793,7 +793,7 @@ static void stateBusy(DVDCommandBlock* block) { } static u32 ImmCommand[] = {0xffffffff, 0xffffffff, 0xffffffff}; -/* Somehow this got included even though the function is stripped? O.o */ +/* The literal of the stripped DVDChangeDiskAsync stays in the object. */ static char string_DVDChangeDiskAsyncMsg[] = "DVDChangeDiskAsync(): You can't specify NULL to company name. \n"; static u32 DmaCommand[] = {0xffffffff}; @@ -832,7 +832,7 @@ static void cbForStateBusy(u32 intType) { if (intType == 16) { #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02 - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; #endif stateTimeout(); return; @@ -841,7 +841,7 @@ static void cbForStateBusy(u32 intType) { if ((CurrCommand == 3) || (CurrCommand == 15)) { if (intType & 2) { #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02 - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; #endif stateError(0x1234567); return; @@ -857,7 +857,7 @@ static void cbForStateBusy(u32 intType) { return; } - executing->state = 7; + executing->state = DVD_STATE_MOTOR_STOPPED; stateMotorStopped(); return; } @@ -871,7 +871,7 @@ static void cbForStateBusy(u32 intType) { finished = executing; executing = &DummyCommandBlock; - finished->state = 10; + finished->state = DVD_STATE_CANCELED; if (finished->callback) (*finished->callback)(-3, finished); if (CancelCallback) @@ -889,7 +889,7 @@ static void cbForStateBusy(u32 intType) { MotorState = 1; finished = executing; executing = &DummyCommandBlock; - finished->state = 0; + finished->state = DVD_STATE_END; if (finished->callback) { (finished->callback)(0, finished); } @@ -910,7 +910,7 @@ static void cbForStateBusy(u32 intType) { finished = executing; executing = &DummyCommandBlock; - finished->state = 0; + finished->state = DVD_STATE_END; if (finished->callback) { (finished->callback)((s32)finished->transferredSize, finished); } @@ -926,7 +926,7 @@ static void cbForStateBusy(u32 intType) { finished = executing; executing = &DummyCommandBlock; - finished->state = 0; + finished->state = DVD_STATE_END; if (finished->callback) { (finished->callback)(result, finished); } @@ -937,7 +937,7 @@ static void cbForStateBusy(u32 intType) { finished = executing; executing = &DummyCommandBlock; - finished->state = 9; + finished->state = DVD_STATE_IGNORED; if (finished->callback) { (finished->callback)(-2, finished); } @@ -951,7 +951,7 @@ static void cbForStateBusy(u32 intType) { finished = executing; executing = &DummyCommandBlock; - finished->state = 0; + finished->state = DVD_STATE_END; if (finished->callback) { (finished->callback)(0, finished); } @@ -961,7 +961,7 @@ static void cbForStateBusy(u32 intType) { finished = executing; executing = &DummyCommandBlock; - finished->state = 0; + finished->state = DVD_STATE_END; if (finished->callback) { (finished->callback)(0, finished); } @@ -970,7 +970,7 @@ static void cbForStateBusy(u32 intType) { } else { if (CurrCommand == 14) { #if SDK_VERSION <= SDK_VERSION_DOLPHIN_2003_02 - executing->state = -1; + executing->state = DVD_STATE_FATAL_ERROR; #endif stateError(0x01234567); return; @@ -984,7 +984,7 @@ static void cbForStateBusy(u32 intType) { finished = executing; executing = &DummyCommandBlock; - finished->state = 0; + finished->state = DVD_STATE_END; if (finished->callback) { (finished->callback)((s32)finished->transferredSize, finished); } @@ -1007,10 +1007,10 @@ static BOOL issueCommand(s32 prio, DVDCommandBlock* block) { level = OSDisableInterrupts(); - block->state = 2; + block->state = DVD_STATE_WAITING; result = __DVDPushWaitingQueue(prio, block); - if ((executing == (DVDCommandBlock*)NULL) && (PauseFlag == FALSE)) { + if ((executing == NULL) && (PauseFlag == FALSE)) { stateReady(); } @@ -1027,22 +1027,23 @@ BOOL DVDReadAbsAsyncPrio(DVDCommandBlock* block, void* addr, s32 length, s32 off block->length = length; block->offset = offset; block->transferredSize = 0; -#if SDK_VERSION >= SDK_VERSION_DOLPHIN_2003_04 block->callback = callback; idle = issueCommand(prio, block); return idle; } + +#if SDK_VERSION >= SDK_VERSION_DOLPHIN_2003_04 BOOL DVDSeekAbsAsyncPrio(DVDCommandBlock* block, s32 offset, DVDCBCallback callback, s32 prio) { BOOL idle; block->command = 2; block->offset = offset; -#endif block->callback = callback; idle = issueCommand(prio, block); return idle; } +#endif BOOL DVDReadAbsAsyncForBS(DVDCommandBlock* block, void* addr, s32 length, s32 offset, DVDCBCallback callback) { BOOL idle; @@ -1056,12 +1057,12 @@ BOOL DVDReadAbsAsyncForBS(DVDCommandBlock* block, void* addr, s32 length, s32 of idle = issueCommand(2, block); return idle; } + BOOL DVDReadDiskID(DVDCommandBlock* block, DVDDiskID* diskID, DVDCBCallback callback) { BOOL idle; block->command = 5; block->addr = diskID; block->length = sizeof(DVDDiskID); - ; block->offset = 0; block->transferredSize = 0; block->callback = callback; @@ -1069,6 +1070,7 @@ BOOL DVDReadDiskID(DVDCommandBlock* block, DVDDiskID* diskID, DVDCBCallback call idle = issueCommand(2, block); return idle; } + BOOL DVDPrepareStreamAbsAsync(DVDCommandBlock* block, u32 length, u32 offset, DVDCBCallback callback) { BOOL idle; @@ -1080,6 +1082,7 @@ BOOL DVDPrepareStreamAbsAsync(DVDCommandBlock* block, u32 length, u32 offset, idle = issueCommand(1, block); return idle; } + BOOL DVDCancelStreamAsync(DVDCommandBlock* block, DVDCBCallback callback) { BOOL idle; block->command = 7; @@ -1087,6 +1090,7 @@ BOOL DVDCancelStreamAsync(DVDCommandBlock* block, DVDCBCallback callback) { idle = issueCommand(1, block); return idle; } + s32 DVDCancelStream(DVDCommandBlock* block) { BOOL result; s32 state; @@ -1104,7 +1108,7 @@ s32 DVDCancelStream(DVDCommandBlock* block) { while (TRUE) { state = ((volatile DVDCommandBlock*)block)->state; - if (state == 0 || state == -1 || state == 10) { + if (state == DVD_STATE_END || state == DVD_STATE_FATAL_ERROR || state == DVD_STATE_CANCELED) { retVal = (s32)block->transferredSize; break; } @@ -1115,10 +1119,12 @@ s32 DVDCancelStream(DVDCommandBlock* block) { OSRestoreInterrupts(enabled); return retVal; } + static void cbForCancelStreamSync(s32 result, DVDCommandBlock* block) { block->transferredSize = (u32)result; OSWakeupThread(&__DVDThreadQueue); } + BOOL DVDStopStreamAtEndAsync(DVDCommandBlock* block, DVDCBCallback callback) { BOOL idle; @@ -1129,6 +1135,7 @@ BOOL DVDStopStreamAtEndAsync(DVDCommandBlock* block, DVDCBCallback callback) { return idle; } + BOOL DVDGetStreamErrorStatusAsync(DVDCommandBlock* block, DVDCBCallback callback) { BOOL idle; @@ -1139,6 +1146,7 @@ BOOL DVDGetStreamErrorStatusAsync(DVDCommandBlock* block, DVDCBCallback callback return idle; } + BOOL DVDGetStreamPlayAddrAsync(DVDCommandBlock* block, DVDCBCallback callback) { BOOL idle; @@ -1149,6 +1157,7 @@ BOOL DVDGetStreamPlayAddrAsync(DVDCommandBlock* block, DVDCBCallback callback) { return idle; } + BOOL DVDInquiryAsync(DVDCommandBlock* block, DVDDriveInfo* info, DVDCBCallback callback) { BOOL idle; @@ -1177,8 +1186,8 @@ s32 DVDGetCommandBlockStatus(const DVDCommandBlock* block) { enabled = OSDisableInterrupts(); - if (block->state == 3) { - retVal = 1; + if (block->state == DVD_STATE_COVER_CLOSED) { + retVal = DVD_STATE_BUSY; } else { retVal = block->state; } @@ -1195,14 +1204,14 @@ s32 DVDGetDriveStatus() { enabled = OSDisableInterrupts(); if (FatalErrorFlag) { - retVal = -1; + retVal = DVD_STATE_FATAL_ERROR; } else if (PausingFlag) { - retVal = 8; + retVal = DVD_STATE_PAUSING; } else { - if (executing == (DVDCommandBlock*)NULL) { - retVal = 0; + if (executing == NULL) { + retVal = DVD_STATE_END; } else if (executing == &DummyCommandBlock) { - retVal = 0; + retVal = DVD_STATE_END; } else { retVal = DVDGetCommandBlockStatus(executing); } @@ -1224,7 +1233,7 @@ void DVDPause(void) { BOOL level; level = OSDisableInterrupts(); PauseFlag = TRUE; - if (executing == (DVDCommandBlock*)NULL) { + if (executing == NULL) { PausingFlag = TRUE; } OSRestoreInterrupts(level); @@ -1251,14 +1260,14 @@ BOOL DVDCancelAsync(DVDCommandBlock* block, DVDCBCallback callback) { enabled = OSDisableInterrupts(); switch (block->state) { - case -1: - case 0: - case 10: + case DVD_STATE_FATAL_ERROR: + case DVD_STATE_END: + case DVD_STATE_CANCELED: if (callback) (*callback)(0, block); break; - case 1: + case DVD_STATE_BUSY: if (Canceling) { OSRestoreInterrupts(enabled); return FALSE; @@ -1271,16 +1280,16 @@ BOOL DVDCancelAsync(DVDCommandBlock* block, DVDCBCallback callback) { } break; - case 2: + case DVD_STATE_WAITING: __DVDDequeueWaitingQueue(block); - block->state = 10; + block->state = DVD_STATE_CANCELED; if (block->callback) (block->callback)(-3, block); if (callback) (*callback)(0, block); break; - case 3: + case DVD_STATE_COVER_CLOSED: switch (block->command) { case 5: case 4: @@ -1301,31 +1310,31 @@ BOOL DVDCancelAsync(DVDCommandBlock* block, DVDCBCallback callback) { } break; - case 4: - case 5: - case 6: - case 7: - case 11: + case DVD_STATE_NO_DISK: + case DVD_STATE_COVER_OPEN: + case DVD_STATE_WRONG_DISK: + case DVD_STATE_MOTOR_STOPPED: + case DVD_STATE_RETRY: old = DVDLowClearCallback(); if (old != cbForStateMotorStopped) { OSRestoreInterrupts(enabled); return FALSE; } - if (block->state == 4) + if (block->state == DVD_STATE_NO_DISK) ResumeFromHere = 3; - if (block->state == 5) + if (block->state == DVD_STATE_COVER_OPEN) ResumeFromHere = 4; - if (block->state == 6) + if (block->state == DVD_STATE_WRONG_DISK) ResumeFromHere = 1; - if (block->state == 11) + if (block->state == DVD_STATE_RETRY) ResumeFromHere = 2; - if (block->state == 7) + if (block->state == DVD_STATE_MOTOR_STOPPED) ResumeFromHere = 7; #if SDK_VERSION >= SDK_VERSION_DOLPHIN_2002_11 executing = &DummyCommandBlock; #endif - block->state = 10; + block->state = DVD_STATE_CANCELED; if (block->callback) { (block->callback)(-3, block); } @@ -1357,11 +1366,12 @@ s32 DVDCancel(DVDCommandBlock* block) { for (;;) { state = ((volatile DVDCommandBlock*)block)->state; - if ((state == 0) || (state == -1) || (state == 10)) { + if ((state == DVD_STATE_END) || (state == DVD_STATE_FATAL_ERROR) || + (state == DVD_STATE_CANCELED)) { break; } - if (state == 3) { + if (state == DVD_STATE_COVER_CLOSED) { command = ((volatile DVDCommandBlock*)block)->command; if ((command == 4) || (command == 5) || (command == 13) || (command == 15)) { @@ -1392,7 +1402,7 @@ BOOL DVDCancelAllAsync(DVDCBCallback callback) { enabled = OSDisableInterrupts(); DVDPause(); - while ((p = __DVDPopWaitingQueue()) != 0) { + while ((p = __DVDPopWaitingQueue()) != NULL) { DVDCancelAsync(p, NULL); } @@ -1440,6 +1450,7 @@ static void cbForCancelAllSync(s32 result, DVDCommandBlock* block) { } DVDDiskID* DVDGetCurrentDiskID(void) { return (DVDDiskID*)OSPhysicalToCached(0); } + BOOL DVDCheckDisk(void) { BOOL enabled; s32 retVal; @@ -1449,39 +1460,39 @@ BOOL DVDCheckDisk(void) { enabled = OSDisableInterrupts(); if (FatalErrorFlag) { - state = -1; + state = DVD_STATE_FATAL_ERROR; } else if (PausingFlag) { - state = 8; + state = DVD_STATE_PAUSING; } else { - if (executing == (DVDCommandBlock*)NULL) { - state = 0; + if (executing == NULL) { + state = DVD_STATE_END; } else if (executing == &DummyCommandBlock) { - state = 0; + state = DVD_STATE_END; } else { state = executing->state; } } switch (state) { - case 1: - case 9: - case 10: - case 2: + case DVD_STATE_BUSY: + case DVD_STATE_IGNORED: + case DVD_STATE_CANCELED: + case DVD_STATE_WAITING: retVal = TRUE; break; - case -1: - case 11: - case 7: - case 3: - case 4: - case 5: - case 6: + case DVD_STATE_FATAL_ERROR: + case DVD_STATE_RETRY: + case DVD_STATE_MOTOR_STOPPED: + case DVD_STATE_COVER_CLOSED: + case DVD_STATE_NO_DISK: + case DVD_STATE_COVER_OPEN: + case DVD_STATE_WRONG_DISK: retVal = FALSE; break; - case 0: - case 8: + case DVD_STATE_END: + case DVD_STATE_PAUSING: coverReg = __DIRegs[1]; if (((coverReg >> 2) & 1) || (coverReg & 1)) { retVal = FALSE; diff --git a/src/dolphin/dvd/dvdfs.c b/src/dolphin/dvd/dvdfs.c index 54c1901..42073b4 100644 --- a/src/dolphin/dvd/dvdfs.c +++ b/src/dolphin/dvd/dvdfs.c @@ -168,7 +168,7 @@ BOOL DVDFastOpen(s32 entrynum, DVDFileInfo* fileInfo) { fileInfo->startAddr = filePosition(entrynum); fileInfo->length = fileLength(entrynum); - fileInfo->callback = (DVDCallback)NULL; + fileInfo->callback = NULL; fileInfo->cb.state = DVD_STATE_END; return TRUE; @@ -192,7 +192,7 @@ BOOL DVDOpen(char* fileName, DVDFileInfo* fileInfo) { fileInfo->startAddr = filePosition(entry); fileInfo->length = fileLength(entry); - fileInfo->callback = (DVDCallback)NULL; + fileInfo->callback = NULL; fileInfo->cb.state = DVD_STATE_END; return TRUE; @@ -302,6 +302,7 @@ BOOL DVDReadAsyncPrio(DVDFileInfo* fileInfo, void* addr, s32 length, s32 offset, return TRUE; } + #ifndef offsetof #define offsetof(type, memb) ((u32) & ((type*)0)->memb) #endif @@ -315,7 +316,6 @@ static void cbForReadAsync(s32 result, DVDCommandBlock* block) { } } -/* This is based on the revolution SDK, these may not match in all cases I have also left the line numbers at 0 */ s32 DVDReadPrio(DVDFileInfo* fileInfo, void* addr, s32 length, s32 offset, s32 prio) { BOOL result; DVDCommandBlock* block; @@ -324,11 +324,11 @@ s32 DVDReadPrio(DVDFileInfo* fileInfo, void* addr, s32 length, s32 offset, s32 p s32 retVal; if (!((0 <= offset) && (offset <= fileInfo->length))) { - OSPanic(__FILE__, 0, "DVDRead(): specified area is out of the file "); + OSPanic(__FILE__, 820, "DVDRead(): specified area is out of the file "); } if (!((0 <= offset + length) && (offset + length < fileInfo->length + DVD_MIN_TRANSFER_SIZE))) { - OSPanic(__FILE__, 0, "DVDRead(): specified area is out of the file "); + OSPanic(__FILE__, 826, "DVDRead(): specified area is out of the file "); } block = &(fileInfo->cb); @@ -342,7 +342,7 @@ s32 DVDReadPrio(DVDFileInfo* fileInfo, void* addr, s32 length, s32 offset, s32 p enabled = OSDisableInterrupts(); - while(1) { + while (1) { state = ((volatile DVDCommandBlock*)block)->state; if (state == DVD_STATE_END) { @@ -365,8 +365,8 @@ s32 DVDReadPrio(DVDFileInfo* fileInfo, void* addr, s32 length, s32 offset, s32 p return retVal; } -/* This is based on the revolution SDK, these may not match in all cases */ static void cbForReadSync(s32 result, DVDCommandBlock* block) { OSWakeupThread(&__DVDThreadQueue); } + /* This is based on the revolution SDK, these may not match in all cases */ BOOL DVDSeekAsyncPrio(DVDFileInfo* fileInfo, s32 offset, DVDCallback callback, s32 prio) { if (!((0 <= offset) && (offset <= fileInfo->length))) { @@ -379,6 +379,7 @@ BOOL DVDSeekAsyncPrio(DVDFileInfo* fileInfo, s32 offset, DVDCallback callback, s return TRUE; } + /* This is based on the revolution SDK, these may not match in all cases */ static void cbForSeekAsync(s32 result, DVDCommandBlock* block) { DVDFileInfo* fileInfo; @@ -389,6 +390,7 @@ static void cbForSeekAsync(s32 result, DVDCommandBlock* block) { (fileInfo->callback)(result, fileInfo); } } + /* This is based on the revolution SDK, these may not match in all cases */ s32 DVDSeekPrio(DVDFileInfo* fileInfo, s32 offset, s32 prio) { BOOL result; @@ -430,6 +432,7 @@ s32 DVDSeekPrio(DVDFileInfo* fileInfo, s32 offset, s32 prio) { OSRestoreInterrupts(enabled); return retVal; } + /* This is based on the revolution SDK, these may not match in all cases */ static void cbForSeekSync(s32 result, DVDCommandBlock* block) { OSWakeupThread(&__DVDThreadQueue); } @@ -452,7 +455,6 @@ BOOL DVDFastOpenDir(s32 entrynum, DVDDir* dir) { return TRUE; } -/* This is based on the revolution SDK, these may not match in all cases */ BOOL DVDOpenDir(char* dirName, DVDDir* dir) { s32 entry; char currentDir[128]; @@ -489,7 +491,6 @@ BOOL DVDReadDir(DVDDir* dir, DVDDirEntry* dirent) { return TRUE; } -/* This is based on the revolution SDK, these may not match in all cases */ BOOL DVDCloseDir(DVDDir* dir) { return TRUE; } /* This is based on the revolution SDK, these may not match in all cases */ @@ -599,7 +600,7 @@ s32 DVDPrepareStream(DVDFileInfo* fileInfo, u32 length, u32 offset) { enabled = OSDisableInterrupts(); - while(1) { + while (1) { state = ((volatile DVDCommandBlock*)block)->state; if (state == DVD_STATE_END) { @@ -627,7 +628,6 @@ static void cbForPrepareStreamSync(s32 result, DVDCommandBlock* block) { OSWakeupThread(&__DVDThreadQueue); } -/* This is based on the revolution SDK, these may not match in all cases */ s32 DVDGetTransferredSize(DVDFileInfo* fileinfo) { s32 bytes; DVDCommandBlock* cb; @@ -652,7 +652,7 @@ s32 DVDGetTransferredSize(DVDFileInfo* fileinfo) { break; case DVD_STATE_BUSY: - bytes = (s32)(cb->transferredSize + (cb->currTransferSize - DVDLowGetLength())); + bytes = (s32)(cb->transferredSize + (cb->currTransferSize - __DIRegs[6])); break; default: diff --git a/src/dolphin/dvd/dvdlow.c b/src/dolphin/dvd/dvdlow.c index 933b974..1ceb5db 100644 --- a/src/dolphin/dvd/dvdlow.c +++ b/src/dolphin/dvd/dvdlow.c @@ -1,10 +1,7 @@ #include #include "dolphin/DVDPriv.h" #include "dolphin/os.h" - -extern DVDDiskID* DVDGetCurrentDiskID(); - -extern OSTime __OSGetSystemTime(); +#include "dolphin/os/OSPriv.h" static BOOL FirstRead = TRUE; static volatile BOOL StopAtNextInt = FALSE; @@ -54,6 +51,7 @@ static void Read(void* addr, u32 length, u32 offset, DVDLowCallback callback); static BOOL ProcessNextCommand() { s32 n = NextCommandNumber; +#line 57 // ASSERT below must report line 57 (debug builds); recompute on edit ASSERT(n < 3); if (CommandList[n].cmd == 1) { @@ -65,7 +63,7 @@ static BOOL ProcessNextCommand() { ++NextCommandNumber; DVDLowSeek(CommandList[n].offset, CommandList[n].callback); return TRUE; - } + } return FALSE; } @@ -145,7 +143,7 @@ void __DVDInterruptHandler(__OSInterrupt interrupt, OSContext* context) { cause &= ~8; } - if ((cause & 1)) { + if (cause & 1) { if (ProcessNextCommand()) { return; } @@ -172,8 +170,8 @@ void __DVDInterruptHandler(__OSInterrupt interrupt, OSContext* context) { } static void AlarmHandler(OSAlarm* alarm, OSContext* context) { - BOOL error = ProcessNextCommand(); - ASSERTMSG(error != FALSE, "Failed assertion processed"); + BOOL processed = ProcessNextCommand(); + ASSERT(processed); } static void AlarmHandlerForTimeout(OSAlarm* alarm, OSContext* context) { @@ -218,11 +216,12 @@ static void Read(void* addr, u32 length, u32 offset, DVDLowCallback callback) { } BOOL HitCache(DVDBuffer* cur, DVDBuffer* prev) { - u32 uVar1 = (prev->offset + prev->length - 1) >> 15; - u32 uVar2 = (cur->offset >> 15); - u32 iVar3 = (DVDGetCurrentDiskID()->streaming ? TRUE : FALSE) ? 5 : 15; + u32 blockNumOfPrevEnd = (prev->offset + prev->length - 1) >> 15; + u32 blockNumOfCurrStart = (cur->offset >> 15); + u32 cacheBlockSize = (DVDGetCurrentDiskID()->streaming ? TRUE : FALSE) ? 5 : 15; - if ((uVar2 > uVar1 - 2) || (uVar2 < uVar1 + iVar3 + 3)) { + if ((blockNumOfCurrStart > blockNumOfPrevEnd - 2) || + (blockNumOfCurrStart < blockNumOfPrevEnd + cacheBlockSize + 3)) { return TRUE; } return FALSE; @@ -235,11 +234,11 @@ static void DoJustRead(void* addr, u32 length, u32 offset, DVDLowCallback callba } static void SeekTwiceBeforeRead(void* addr, u32 length, u32 offset, DVDLowCallback callback) { - u32 newOffset = offset & ~0x7FFF; - if (!newOffset) { + u32 newOffset; + if ((offset & ~0x7FFF) == 0) { newOffset = 0; } else { - newOffset += WorkAroundSeekLocation; + newOffset = (offset & ~0x7FFF) + WorkAroundSeekLocation; } CommandList[0].cmd = 2; CommandList[0].offset = newOffset; @@ -267,7 +266,6 @@ static void WaitBeforeRead(void* addr, u32 length, u32 offset, DVDLowCallback ca OSSetAlarm(&AlarmForWA, timeout, AlarmHandler); } - BOOL DVDLowRead(void* addr, u32 length, u32 offset, DVDLowCallback callback) { OSTime diff; u32 prev; @@ -397,8 +395,8 @@ BOOL DVDLowAudioBufferConfig(BOOL enable, u32 size, DVDLowCallback callback) { #if SDK_VERSION >= SDK_VERSION_DOLPHIN_2003_04 u32 DVDLowGetLength(void) { return __DIRegs[6]; } - #endif + void DVDLowReset() { u32 reg; OSTime resetStart; @@ -451,5 +449,4 @@ BOOL __DVDLowTestAlarm(const OSAlarm* alarm) { } return FALSE; } - #endif diff --git a/src/dolphin/dvd/dvdqueue.c b/src/dolphin/dvd/dvdqueue.c index a381ccf..6b9d0af 100644 --- a/src/dolphin/dvd/dvdqueue.c +++ b/src/dolphin/dvd/dvdqueue.c @@ -53,8 +53,8 @@ static DVDCommandBlock* PopWaitingQueuePrio(s32 prio) { OSRestoreInterrupts(enabled); - tmp->next = (DVDCommandBlock*)NULL; - tmp->prev = (DVDCommandBlock*)NULL; + tmp->next = NULL; + tmp->prev = NULL; return tmp; } @@ -76,7 +76,7 @@ DVDCommandBlock* __DVDPopWaitingQueue(void) { OSRestoreInterrupts(enabled); - return (DVDCommandBlock*)NULL; + return NULL; } BOOL __DVDCheckWaitingQueue(void) { @@ -109,7 +109,7 @@ BOOL __DVDDequeueWaitingQueue(DVDCommandBlock* block) { prev = block->prev; next = block->next; - if ((prev == (DVDCommandBlock*)NULL) || (next == (DVDCommandBlock*)NULL)) { + if ((prev == NULL) || (next == NULL)) { OSRestoreInterrupts(enabled); return FALSE; } From e0cef60d49db2b785007154bf4cd46c495e23d2b Mon Sep 17 00:00:00 2001 From: shulkmaster Date: Wed, 2 Dec 2026 10:49:03 -0600 Subject: [PATCH 2/2] more dvdv cleanups --- src/dolphin/dvd/dvdfatal.c | 9 +++------ src/dolphin/dvd/dvdidutils.c | 9 ++++----- src/dolphin/dvd/fstload.c | 17 ++++++++--------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/dolphin/dvd/dvdfatal.c b/src/dolphin/dvd/dvdfatal.c index 5b13db2..7ea511e 100644 --- a/src/dolphin/dvd/dvdfatal.c +++ b/src/dolphin/dvd/dvdfatal.c @@ -1,11 +1,9 @@ #include -#include "dolphin/DVDPriv.h" +#include "dolphin/dvd.h" #include "dolphin/gx/GXStruct.h" #include "dolphin/os.h" #include "dolphin/vi.h" -void __DVDPrintFatalMessage(void); - static void (*FatalFunc)(void) = NULL; const char* Japanese = "\n\n\nエラーが発生しました。" @@ -110,8 +108,7 @@ BOOL DVDSetAutoFatalMessaging(BOOL enable) { } void __DVDPrintFatalMessage(void) { - if (!FatalFunc) { - return; + if (FatalFunc) { + FatalFunc(); } - FatalFunc(); } diff --git a/src/dolphin/dvd/dvdidutils.c b/src/dolphin/dvd/dvdidutils.c index a3680ac..2f00ebe 100644 --- a/src/dolphin/dvd/dvdidutils.c +++ b/src/dolphin/dvd/dvdidutils.c @@ -1,16 +1,15 @@ -#include #include -#include #include BOOL DVDCompareDiskID(DVDDiskID* id1, DVDDiskID* id2) { - - if (id1->gameName[0] && id2->gameName[0] && strncmp(&id1->gameName[0], &id2->gameName[0], 4)) { + if (id1->gameName[0] && id2->gameName[0] && + strncmp(id1->gameName, id2->gameName, sizeof(id1->gameName))) { return FALSE; } - if (!id1->company[0] || !id2->company[0] || strncmp(&id1->company[0], &id2->company[0], 2)) { + if (!id1->company[0] || !id2->company[0] || + strncmp(id1->company, id2->company, sizeof(id1->company))) { return FALSE; } diff --git a/src/dolphin/dvd/fstload.c b/src/dolphin/dvd/fstload.c index bfae349..e9e469d 100644 --- a/src/dolphin/dvd/fstload.c +++ b/src/dolphin/dvd/fstload.c @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -8,7 +7,7 @@ static s32 status = 0; static u8 bb2Buf[OSRoundUp32B(sizeof(DVDBB2)) + 31]; -static DVDBB2* bb2 = 0; +static DVDBB2* bb2 = NULL; static DVDDiskID* idTmp = NULL; static void cb(s32 result, DVDCommandBlock* block) { @@ -16,15 +15,15 @@ static void cb(s32 result, DVDCommandBlock* block) { switch (status) { case 0: status = 1; - DVDReadAbsAsyncForBS(block, bb2, OSRoundUp32B(sizeof(bb2)), 0x420, cb); + DVDReadAbsAsyncForBS(block, bb2, OSRoundUp32B(sizeof(DVDBB2)), 0x420, cb); break; case 1: status = 2; DVDReadAbsAsyncForBS(block, bb2->FSTAddress, OSRoundUp32B(bb2->FSTLength), bb2->FSTPosition, cb); + break; } - } else if (result == -1) { - + } else if (result == DVD_RESULT_FATAL_ERROR) { } else if (result == -4) { status = 0; DVDReset(); @@ -32,7 +31,7 @@ static void cb(s32 result, DVDCommandBlock* block) { } } -void __fstLoad() { +void __fstLoad(void) { OSBootInfo* bootInfo; DVDDiskID* id; u8 idTmpBuf[sizeof(DVDDiskID) + 31]; @@ -42,12 +41,12 @@ void __fstLoad() { arenaHi = OSGetArenaHi(); bootInfo = (OSBootInfo*)OSPhysicalToCached(0); - idTmp = (DVDDiskID*)(OSRoundUp32B(idTmpBuf)); - bb2 = (DVDBB2*)(OSRoundUp32B(bb2Buf)); + idTmp = (DVDDiskID*)OSRoundUp32B(idTmpBuf); + bb2 = (DVDBB2*)OSRoundUp32B(bb2Buf); DVDReset(); DVDReadDiskID(&block, idTmp, cb); - while (DVDGetDriveStatus() != 0); + while (DVDGetDriveStatus() != DVD_STATE_END) {} bootInfo->FSTLocation = bb2->FSTAddress; bootInfo->FSTMaxLength = bb2->FSTMaxLength;