1 /*---------------------------------------------------------------------------*
2 Project: Dolphin DVD Demo2
3 File: dvddemo2.c
4
5 Copyright 1998, 1999 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: dvddemo2.c,v $
14 Revision 1.2 02/20/2006 04:13:09 mitu
15 changed include path from dolphin/ to revolution/.
16
17 Revision 1.1 2006/01/17 02:43:50 hiratsu
18 Initial check in.
19
20
21 6 5/26/00 5:45p Hashida
22 #ifdef'ed out the comment "Hit Command+Q to quit this demo, which is
23 only needed for Mac.
24
25 5 3/01/00 3:27p Hashida
26 Changed #ifndef EPPC to #ifdef MAC to ifdef out DVDSetRoot.
27
28 4 2/29/00 5:55p Hashida
29 Changed /dolphin/data to /dolphin/dvddata
30
31 3 2/25/00 5:34p Hashida
32 Changed so that it works on MINNOW_MARLIN
33
34 2 2/16/00 2:39p Tian
35 Removed DVDSetRoot for EPPC builds
36
37 11 9/13/99 3:56p Hashida
38 Removed warnings.
39
40 10 8/27/99 3:35p Yasu
41 Add #pragma unused() to avoid warning message
42
43 9 8/26/99 10:45p Hashida
44 Removed DCInvalidate because DVDRead* functions do that now.
45
46 6 6/11/99 10:50p Hashida
47 Changed to use DVDSetRoot()
48
49 5 6/09/99 9:22p Hashida
50 Changed to use OSAlloc to allocate the buffer for files.
51 Added "volatile" to the variables that are accessed from two contexts.
52 Used DVDGetLength for demo1 and demo2.
53
54 2 6/07/99 8:26p Hashida
55 changed the files' path name from "dvdoverview" to "dvddemo"
56
57 1 6/07/99 2:47p Hashida
58 initial revision
59
60 $NoKeywords: $
61 *---------------------------------------------------------------------------*/
62
63 /*---------------------------------------------------------------------------*
64 This program shows how to use asynchronous read function
65 *---------------------------------------------------------------------------*/
66
67
68 #include <revolution.h>
69
70 void main ( void );
71 static void MyOSInit( void );
72 static void callback(s32 result, DVDFileInfo* fileInfo);
73
74 // This variable should be declared "volatile" because this is shared
75 // by two contexts.
76 volatile s32 readDone = 0;
77
78 // The name of the file we are going to read.
79 char* fileName = "texts/test1.txt";
80
81
82 /*---------------------------------------------------------------------------*
83 Name: callback
84
85 Description: callback function for DVDReadAsync
86
87 Arguments: result -1 if read fails, file size if succeeded.
88 fileInfo fileInfo for the file transferred.
89
90 Returns: none
91 *---------------------------------------------------------------------------*/
callback(s32 result,DVDFileInfo * fileInfo)92 static void callback(s32 result, DVDFileInfo* fileInfo)
93 {
94 #pragma unused(fileInfo)
95
96 if (result == -1)
97 {
98 readDone = -1;
99 }
100 else
101 {
102 readDone = 1;
103 }
104 return;
105 }
106
main(void)107 void main(void)
108 {
109 DVDFileInfo fileInfo;
110 u32 fileSize;
111 u8* buffer; // pointer to the buffer
112 u8* ptr;
113 u32 i;
114
115 MyOSInit();
116
117 #ifdef MAC
118 OSReport("\n-----------------------------------");
119 OSReport("\n Hit Command+Q to quit this demo");
120 OSReport("\n-----------------------------------\n\n");
121 #endif
122
123 DVDInit();
124
125 #ifdef MAC
126 DVDSetRoot("DOLPHIN/dvddata");
127 #endif
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 // Allocate a buffer to read the file.
139 // Note that pointers returned by OSAlloc are always 32byte aligned.
140 buffer = (u8*)OSAlloc(OSRoundUp32B(fileSize));
141
142 // This function only starts reading the file.
143 // The read keeps going in the background after the function returns
144 if (FALSE == DVDReadAsync(&fileInfo, (void*)buffer,
145 (s32)OSRoundUp32B(fileSize), 0, callback))
146 {
147 OSHalt("Error occurred when issuing read");
148 }
149
150 while (1)
151 {
152 switch (readDone)
153 {
154 case 1: // the read succeeded
155 goto exit;
156 // NOT REACHED HERE
157 case -1: // the read failed
158 OSHalt("Error occurred when reading file");
159 // NOT REACHED HERE
160 case 0: // processing...
161 // do something
162 break;
163 }
164 }
165
166 exit:
167 // From here, we can use the file
168 OSReport("read end\n");
169
170 // Close the file
171 DVDClose(&fileInfo);
172
173 // Show the files
174 OSReport("\n");
175 ptr = buffer;
176 for (i = 0; i < fileSize; i++)
177 {
178 OSReport("%c", *ptr++);
179 }
180 OSReport("\n\n");
181
182 OSFree(buffer);
183
184 OSHalt("End of demo");
185
186 // NOT REACHED HERE
187 }
188
189 /*---------------------------------------------------------------------------*
190 Name: MyOSInit
191
192 Description: Initialize the operating system.
193 Create a heap so we can use OSAlloc().
194
195 Arguments: none
196
197 Returns: none
198 *---------------------------------------------------------------------------*/
MyOSInit(void)199 static void MyOSInit ( void )
200 {
201 void* arenaLo;
202 void* arenaHi;
203
204 OSInit();
205
206 arenaLo = OSGetArenaLo();
207 arenaHi = OSGetArenaHi();
208
209 // OSInitAlloc should only ever be invoked once.
210 arenaLo = OSInitAlloc(arenaLo, arenaHi, 1); // 1 heap
211 OSSetArenaLo(arenaLo);
212
213 // The boundaries given to OSCreateHeap should be 32B aligned
214 OSSetCurrentHeap(OSCreateHeap((void*)OSRoundUp32B(arenaLo),
215 (void*)OSRoundDown32B(arenaHi)));
216 // From here on out, OSAlloc and OSFree behave like malloc and free
217 // respectively
218
219 OSSetArenaLo(arenaLo = arenaHi);
220
221 return;
222 }
223