/*---------------------------------------------------------------------------* Project: Revolution DVD check disk demo File: checkdisk.c Copyright 2009 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Log: checkdisk.c,v $ Revision 1.2 2009/01/30 01:36:23 ooizumi Added checkdisk demo. $NoKeywords: $ *---------------------------------------------------------------------------*/ #include #include // This variable should be declared "volatile" because this is shared // by two contexts. volatile s32 readDone = 1; volatile s32 commandDone = 0; /*---------------------------------------------------------------------------* Name: readCallback Description: callback function for DVDReadAsync Arguments: result -1 if read fails, file size if succeeded. fileInfo fileInfo for the file transferred. Returns: none *---------------------------------------------------------------------------*/ static void readCallback(s32 result, DVDFileInfo* fileInfo) { #pragma unused(fileInfo) if (result == -1) { readDone = -1; } else { readDone = 1; } OSReport("DVDReadAsync done %d\n", result); return; } /*---------------------------------------------------------------------------* Name: checkCallback Description: callback function for DVDCheckDiskAsync Arguments: result 0 if check fails, 1 if succeeded. block command block for the command transferred. Returns: none *---------------------------------------------------------------------------*/ static void checkCallback(s32 result, DVDCommandBlock* block) { #pragma unused(block) if (result == 1) { commandDone = 1; } else { commandDone = -1; } return; } #define DVD_BUFFER_SIZE 0xf00000 static void* Buffer; static char* readString[] = { "PROCESSING", "DONE" }; static char* statusString[] = { "DVD_STATE_END", "DVD_STATE_BUSY", "DVD_STATE_WAITING", "DVD_STATE_COVER_CLOSED", "DVD_STATE_NO_DISK", "DVD_STATE_COVER_OPEN", "DVD_STATE_WRONG_DISK", "DVD_STATE_MOTOR_STOPPED", "DVD_STATE_PAUSING", "DVD_STATE_IGNORED", "DVD_STATE_CANCELED", "DVD_STATE_RETRY" }; // The name of the file we are going to read. const char* Filename = "abc.ecd"; GXColor Black = { 0, 0, 0, 0 }; void main(void) { void* arenaLo; DVDFileInfo fileInfo; DVDCommandBlock block; u32 fileSize; arenaLo = OSGetArenaLo(); Buffer = arenaLo; OSSetArenaLo((void*)((u32)arenaLo + DVD_BUFFER_SIZE)); DEMOInit(NULL); DEMOInitROMFont(); OSReport("Eject or Insert disc and issue DVDRead to see how DVD APIs handle the disc status.\n"); OSReport("Press A to issue DVDReadAsync.\n"); DVDSetAutoFatalMessaging(TRUE); // We MUST open the file before accessing the file if (FALSE == DVDOpen(Filename, &fileInfo)) { OSHalt("Cannot open file"); } // Get the size of the file fileSize = DVDGetLength(&fileInfo); for (;;) { // Clear EFB GXSetCopyClear(Black, 0x00ffffff); GXCopyDisp(DEMOGetCurrentBuffer(), GX_TRUE); DEMOBeforeRender(); { GXRenderModeObj* rmp; rmp = DEMOGetRenderModeObj(); DEMOInitCaption(DM_FT_XLU, (s16) rmp->fbWidth, (s16) rmp->efbHeight); DEMOSetROMFontSize(24, -1); DEMORFPrintf( 40, 40, 0, "dvd checkdisk demo"); DEMORFPrintf( 40, 90, 0, "DVDReadAsync"); DEMORFPrintf(320, 90, 0, "%s", readString[!readDone ? 0 : 1]); DEMORFPrintf( 40, 140, 0, "DVDGetDriveStatus"); DEMORFPrintf( 40, 165, 0, "DVDIsDiskIdentified"); DEMORFPrintf( 40, 190, 0, "DVDCheckDiskAsync"); DEMORFPrintf(320, 140, 0, "%s", statusString[DVDGetDriveStatus()]); DEMORFPrintf(320, 165, 0, "%s", DVDIsDiskIdentified() ? "TRUE" : "FALSE"); DEMORFPrintf(320, 190, 0, "%s", (commandDone == 1) ? "TRUE" : "FALSE"); DEMORFPrintf( 40, 240, 0, "Eject or Insert disc and issue DVDRead to see"); DEMORFPrintf( 40, 265, 0, "how DVD APIs handle the disc status."); DEMORFPrintf( 40, 290, 0, "Press A to issue DVDReadAsync"); } DEMODoneRender(); DEMOPadRead(); // read the entire file here if (readDone && (DEMOPadGetButton(0) & PAD_BUTTON_A)) { OSReport("Issuing DVDReadAsync\n"); readDone = 0; if (0 > DVDReadAsync(&fileInfo, Buffer, (s32)OSRoundUp32B(fileSize), 0, readCallback)) { OSHalt("Error occurred when reading file"); } } commandDone = 0; DVDCheckDiskAsync(&block, checkCallback); while (!commandDone) { ; } VIWaitForRetrace(); } // NOT REACHED HERE }