1 /*---------------------------------------------------------------------------*
2 Project: Dolphin DVD Demo1
3 File: dvddemo1.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: dvddemo1.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 9 9/13/99 3:56p Hashida
38 Removed warnings.
39
40 8 8/26/99 10:44p Hashida
41 Removed DCInvalidate because DVDRead* functions do that now.
42
43 5 6/11/99 10:50p Hashida
44 Changed to use DVDSetRoot()
45
46 4 6/09/99 9:22p Hashida
47 Changed to use OSAlloc to allocate the buffer for files.
48 Added "volatile" to the variables that are accessed from two contexts.
49 Used DVDGetLength for demo1 and demo2.
50
51 2 6/07/99 8:26p Hashida
52 changed the files' path name from "dvdoverview" to "dvddemo"
53
54 1 6/07/99 2:47p Hashida
55 initial revision
56
57 $NoKeywords: $
58 *---------------------------------------------------------------------------*/
59
60 /*---------------------------------------------------------------------------*
61 This program shows how to use synchronous read function
62 *---------------------------------------------------------------------------*/
63
64
65 #include <revolution.h>
66
67 void main ( void );
68 static void MyOSInit ( void );
69
70 // The name of the file we are going to read.
71 char* fileName = "texts/test1.txt";
72
73
main(void)74 void main(void)
75 {
76 DVDFileInfo fileInfo;
77 u32 fileSize;
78 u8* buffer; // pointer to the buffer
79 u8* ptr;
80 u32 i;
81
82 // Init the OS and heap
83 MyOSInit();
84
85 #ifdef MAC
86 OSReport("\n-----------------------------------");
87 OSReport("\n Hit Command+Q to quit this demo");
88 OSReport("\n-----------------------------------\n\n");
89 #endif
90
91 DVDInit();
92
93 #ifdef MAC
94 DVDSetRoot("DOLPHIN/dvddata");
95 #endif
96
97 // We MUST open the file before accessing the file
98 if (FALSE == DVDOpen(fileName, &fileInfo))
99 {
100 OSHalt("Cannot open file");
101 }
102
103 // Get the size of the file
104 fileSize = DVDGetLength(&fileInfo);
105
106 // Allocate a buffer to read the file.
107 // Note that pointers returned by OSAlloc are always 32byte aligned.
108 buffer = (u8*)OSAlloc(OSRoundUp32B(fileSize));
109
110 // read the entire file here
111 if (0 > DVDRead(&fileInfo, (void*)buffer, (s32)OSRoundUp32B(fileSize), 0))
112 {
113 OSHalt("Error occurred when reading file");
114 }
115
116 // From here, we can use the file
117 OSReport("read end\n");
118
119 // Close the file
120 DVDClose(&fileInfo);
121
122 // Show the files
123 OSReport("\n");
124 ptr = buffer;
125 for (i = 0; i < fileSize; i++)
126 {
127 OSReport("%c", *ptr++);
128 }
129 OSReport("\n\n");
130
131 OSFree(buffer);
132
133 OSHalt("End of demo");
134
135 // NOT REACHED HERE
136 }
137
138 /*---------------------------------------------------------------------------*
139 Name: MyOSInit
140
141 Description: Initialize the operating system.
142 Create a heap so we can use OSAlloc().
143
144 Arguments: none
145
146 Returns: none
147 *---------------------------------------------------------------------------*/
MyOSInit(void)148 static void MyOSInit(void)
149 {
150 void* arenaLo;
151 void* arenaHi;
152
153 OSInit();
154
155 arenaLo = OSGetArenaLo();
156 arenaHi = OSGetArenaHi();
157
158 // OSInitAlloc should only ever be invoked once.
159 arenaLo = OSInitAlloc(arenaLo, arenaHi, 1); // 1 heap
160 OSSetArenaLo(arenaLo);
161
162 // The boundaries given to OSCreateHeap should be 32B aligned
163 OSSetCurrentHeap(OSCreateHeap((void*)OSRoundUp32B(arenaLo),
164 (void*)OSRoundDown32B(arenaHi)));
165 // From here on out, OSAlloc and OSFree behave like malloc and free
166 // respectively
167
168 OSSetArenaLo(arenaLo = arenaHi);
169
170 return;
171 }
172