1 /*---------------------------------------------------------------------------*
2   Project:  Revolution DVD check disk demo
3   File:     checkdisk.c
4 
5   Copyright 2009 Nintendo.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Log: checkdisk.c,v $
14   Revision 1.1.2.1  2009/01/16 01:46:58  ooizumi
15   Added checkdisk demo.
16 
17   $NoKeywords: $
18  *---------------------------------------------------------------------------*/
19 
20 #include <demo.h>
21 
22 #include <revolution.h>
23 
24 // This variable should be declared "volatile" because this is shared
25 // by two contexts.
26 volatile s32 readDone    = 1;
27 volatile s32 commandDone = 0;
28 
29  /*---------------------------------------------------------------------------*
30     Name:               readCallback
31 
32     Description:        callback function for DVDReadAsync
33 
34     Arguments:          result     -1 if read fails, file size if succeeded.
35                         fileInfo   fileInfo for the file transferred.
36 
37     Returns:            none
38  *---------------------------------------------------------------------------*/
readCallback(s32 result,DVDFileInfo * fileInfo)39 static void readCallback(s32 result, DVDFileInfo* fileInfo)
40 {
41 #pragma unused(fileInfo)
42 
43     if (result == -1)
44     {
45         readDone = -1;
46     }
47     else
48     {
49         readDone = 1;
50     }
51     OSReport("DVDReadAsync done %d\n", result);
52     return;
53 }
54 
55  /*---------------------------------------------------------------------------*
56     Name:               checkCallback
57 
58     Description:        callback function for DVDCheckDiskAsync
59 
60     Arguments:          result   0 if check fails, 1 if succeeded.
61                         block    command block for the command transferred.
62 
63     Returns:            none
64  *---------------------------------------------------------------------------*/
checkCallback(s32 result,DVDCommandBlock * block)65 static void checkCallback(s32 result, DVDCommandBlock* block)
66 {
67 #pragma unused(block)
68 
69     if (result == 1)
70     {
71         commandDone = 1;
72     }
73     else
74     {
75         commandDone = -1;
76     }
77     return;
78 }
79 
80 #define DVD_BUFFER_SIZE  0xf00000
81 static void*             Buffer;
82 
83 static char* readString[] =
84 {
85     "PROCESSING",
86     "DONE"
87 };
88 
89 static char* statusString[] =
90 {
91     "DVD_STATE_END",
92     "DVD_STATE_BUSY",
93     "DVD_STATE_WAITING",
94     "DVD_STATE_COVER_CLOSED",
95     "DVD_STATE_NO_DISK",
96     "DVD_STATE_COVER_OPEN",
97     "DVD_STATE_WRONG_DISK",
98     "DVD_STATE_MOTOR_STOPPED",
99     "DVD_STATE_PAUSING",
100     "DVD_STATE_IGNORED",
101     "DVD_STATE_CANCELED",
102     "DVD_STATE_RETRY"
103 };
104 
105 // The name of the file we are going to read.
106 const char* Filename = "abc.ecd";
107 
108 GXColor Black  = {   0,   0,   0, 0 };
109 
main(void)110 void main(void)
111 {
112     void*           arenaLo;
113     DVDFileInfo     fileInfo;
114     DVDCommandBlock block;
115     u32             fileSize;
116 
117     arenaLo = OSGetArenaLo();
118     Buffer = arenaLo;
119     OSSetArenaLo((void*)((u32)arenaLo + DVD_BUFFER_SIZE));
120 
121     DEMOInit(NULL);
122     DEMOInitROMFont();
123 
124     OSReport("Eject or Insert disc and issue DVDRead to see how DVD APIs handle the disc status.\n");
125     OSReport("Press A to issue DVDReadAsync.\n");
126 
127     DVDSetAutoFatalMessaging(TRUE);
128 
129     // We MUST open the file before accessing the file
130     if (FALSE == DVDOpen(Filename, &fileInfo))
131     {
132         OSHalt("Cannot open file");
133     }
134 
135     // Get the size of the file
136     fileSize = DVDGetLength(&fileInfo);
137 
138     for (;;)
139     {
140         // Clear EFB
141         GXSetCopyClear(Black, 0x00ffffff);
142         GXCopyDisp(DEMOGetCurrentBuffer(), GX_TRUE);
143 
144         DEMOBeforeRender();
145         {
146             GXRenderModeObj* rmp;
147 
148             rmp = DEMOGetRenderModeObj();
149 
150             DEMOInitCaption(DM_FT_XLU, (s16) rmp->fbWidth, (s16) rmp->efbHeight);
151             DEMOSetROMFontSize(24, -1);
152 
153             DEMORFPrintf( 40,  40, 0, "dvd checkdisk demo");
154 
155             DEMORFPrintf( 40,  90, 0, "DVDReadAsync");
156             DEMORFPrintf(320,  90, 0, "%s", readString[!readDone ? 0 : 1]);
157 
158             DEMORFPrintf( 40, 140, 0, "DVDGetDriveStatus");
159             DEMORFPrintf( 40, 165, 0, "DVDIsDiskIdentified");
160             DEMORFPrintf( 40, 190, 0, "DVDCheckDiskAsync");
161 
162             DEMORFPrintf(320, 140, 0, "%s", statusString[DVDGetDriveStatus()]);
163             DEMORFPrintf(320, 165, 0, "%s", DVDIsDiskIdentified() ? "TRUE" : "FALSE");
164             DEMORFPrintf(320, 190, 0, "%s", (commandDone == 1) ? "TRUE" : "FALSE");
165 
166             DEMORFPrintf( 40, 240, 0, "Eject or Insert disc and issue DVDRead to see");
167             DEMORFPrintf( 40, 265, 0, "how DVD APIs handle the disc status.");
168             DEMORFPrintf( 40, 290, 0, "Press A to issue DVDReadAsync");
169         }
170         DEMODoneRender();
171 
172         DEMOPadRead();
173 
174         // read the entire file here
175         if (readDone && (DEMOPadGetButton(0) & PAD_BUTTON_A))
176         {
177             OSReport("Issuing DVDReadAsync\n");
178             readDone = 0;
179             if (0 > DVDReadAsync(&fileInfo, Buffer, (s32)OSRoundUp32B(fileSize), 0, readCallback))
180             {
181                 OSHalt("Error occurred when reading file");
182             }
183         }
184 
185         commandDone = 0;
186         DVDCheckDiskAsync(&block, checkCallback);
187         while (!commandDone)
188         {
189             ;
190         }
191 
192         VIWaitForRetrace();
193     }
194     // NOT REACHED HERE
195 }
196