1 /*---------------------------------------------------------------------------*
2 Project: THP Player
3 File: main.c
4
5 Copyright (C)2002-2006 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: main.c,v $
14 Revision 1.2 2006/03/06 09:59:05 kawaset
15 Eliminated warnings.
16
17 Revision 1.1 02/03/2006 10:01:41 aka
18 Imported from Dolphin tree.
19
20
21 4 03/11/25 11:24 Dante
22 Japanese to English translation of comments and text strings
23
24 3 02/05/14 9:08a Suzuki
25 supported multi audio track
26
27 2 02/02/28 6:36p Akagi
28 enabled to use with MusyX/AX by Suzuki-san (IRD).
29
30 1 02/01/16 10:52a Akagi
31 Initial revision made by Suzuki-san (IRD).
32
33 $NoKeywords: $
34
35 *---------------------------------------------------------------------------*/
36
37 #include <string.h>
38 #include <math.h>
39 #include <demo.h>
40 #ifdef HOLLYWOOD_REV
41 #include <revolution/mem.h>
42 #endif
43 #include "axseq.h"
44
45 #include "THPPlayer.h"
46
47 static void MovieDoneRender(void);
48
49 #ifdef HOLLYWOOD_REV
50 MEMHeapHandle __ExpHeap;
51 #endif
52
main(void)53 void main(void)
54 {
55 u32 size, x, y;
56 u8 *buffer;
57 GXRenderModeObj *rmode;
58 GXColor black;
59 THPVideoInfo videoInfo;
60 THPAudioInfo audioInfo;
61 s32 frame, vol, audioTrack;
62 u16 buttonDown, button, dir;
63 char *fileName;
64 BOOL open, play, onMemory;
65 #ifdef HOLLYWOOD_REV
66 void *arenaMem2Lo;
67 void *arenaMem2Hi;
68 #endif
69
70 black.r = 0;
71 black.g = 0;
72 black.b = 0;
73 black.a = 255;
74
75 DEMOInit(&GXNtsc480Int);
76
77 #ifdef HOLLYWOOD_REV
78 arenaMem2Lo = OSGetMEM2ArenaLo();
79 arenaMem2Hi = OSGetMEM2ArenaHi();
80 __ExpHeap = MEMCreateExpHeap(arenaMem2Lo, (u32)arenaMem2Hi - (u32) arenaMem2Lo);
81 #endif
82
83 GXSetDispCopyGamma(GX_GM_1_0);
84 GXSetCopyFilter(FALSE, NULL, FALSE, NULL);
85 GXSetCopyClear(black, 0xffffff);
86
87 rmode = DEMOGetRenderModeObj();
88
89 AIInit(NULL);
90 AXSeqSetup();
91 THPPlayerInit(THP_MODE_WITH_AX);
92
93 open = FALSE;
94 play = FALSE;
95 onMemory = FALSE;
96
97 OSReport("\n");
98 OSReport("###########################################################\n");
99 OSReport("Push A Button : Play the movie with audio\n");
100 OSReport("Push B Button : Play the movie with audio on the memory\n");
101 OSReport("Push X Button : Play the interlace movie\n");
102 OSReport("Push Y Button : Play the movie with multiple audio track,\n");
103 OSReport(" : select audio track at random\n");
104 OSReport("Push L Trigger : Pause / Restart the movie\n");
105 OSReport("Push R Trigger : Skip one frame if the movie is paused\n");
106 OSReport("Pad Up : Volume up\n");
107 OSReport("Pad Down : Volume down\n");
108 OSReport("Pad Right : Play/stop midi file using AX\n");
109 OSReport("Push Start Button : Application end\n");
110 OSReport("###########################################################\n");
111
112 while(1)
113 {
114 DEMOPadRead();
115
116 buttonDown = DEMOPadGetButtonDown(PAD_CHAN0);
117 button = DEMOPadGetButton(PAD_CHAN0);
118 dir = DEMOPadGetDirs(PAD_CHAN0);
119
120 DEMOBeforeRender();
121
122 if (play)
123 {
124 frame = THPPlayerDrawCurrentFrame(rmode, x, y, videoInfo.xSize, videoInfo.ySize);
125 }
126
127 // Movie Playback DoneRender
128 MovieDoneRender();
129
130 // Check player state
131 if (THPPlayerGetState() == THP_PLAYER_ERROR)
132 {
133 THPPlayerStop();
134 THPPlayerClose();
135 #ifndef HOLLYWOOD_REV
136 OSFree(buffer);
137 #else
138 MEMFreeToExpHeap(__ExpHeap, buffer);
139 #endif
140 OSHalt("Error happen");
141 }
142
143 if (buttonDown & PAD_BUTTON_A)
144 {
145 fileName = "thpdemo/rebirth.thp";
146 open = TRUE;
147 onMemory = FALSE;
148 }
149
150 if (buttonDown & PAD_BUTTON_B)
151 {
152 fileName = "thpdemo/fish.thp";
153 open = TRUE;
154 onMemory = TRUE;
155 }
156
157 if (buttonDown & PAD_BUTTON_X)
158 {
159 fileName = "thpdemo/fish_int.thp";
160 open = TRUE;
161 onMemory = FALSE;
162 }
163
164 if (buttonDown & PAD_BUTTON_Y)
165 {
166 fileName = "thpdemo/fish_mlt.thp";
167 open = TRUE;
168 onMemory = FALSE;
169 }
170
171 if (buttonDown & PAD_TRIGGER_L)
172 {
173 if (THPPlayerGetState() == THP_PLAYER_PAUSE)
174 {
175 THPPlayerPlay();
176 }
177 else
178 {
179 THPPlayerPause();
180 }
181 }
182
183 if (buttonDown & PAD_TRIGGER_R)
184 {
185 THPPlayerSkip();
186 }
187
188 if (buttonDown & PAD_BUTTON_START)
189 {
190 if (play)
191 {
192 THPPlayerStop();
193 THPPlayerClose();
194 #ifndef HOLLYWOOD_REV
195 OSFree(buffer);
196 #else
197 MEMFreeToExpHeap(__ExpHeap, buffer);
198 #endif
199 }
200
201 break;
202 }
203
204 if (button & PAD_BUTTON_UP)
205 {
206 vol = THPPlayerGetVolume() + 1;
207 if (vol > 127)
208 {
209 vol = 127;
210 }
211 THPPlayerSetVolume(vol, 0);
212 }
213
214 if (button & PAD_BUTTON_DOWN)
215 {
216 vol = THPPlayerGetVolume() - 1;
217 if (vol < 0)
218 {
219 vol = 0;
220 }
221 THPPlayerSetVolume(vol, 0);
222 }
223
224 if (buttonDown & PAD_BUTTON_RIGHT)
225 {
226 if (GetSeqState())
227 {
228 SeqStop();
229 }
230 else
231 {
232 SeqPlay();
233 }
234 }
235
236 if (open)
237 {
238 // If playing back, release Stop and work area
239 if (play)
240 {
241 THPPlayerStop();
242 THPPlayerClose();
243 #ifndef HOLLYWOOD_REV
244 OSFree(buffer);
245 #else
246 MEMFreeToExpHeap(__ExpHeap, buffer);
247 #endif
248 play = FALSE;
249 }
250 }
251
252 if (open && !play)
253 {
254 // Open THP file
255 if (THPPlayerOpen(fileName, onMemory) == FALSE)
256 {
257 OSHalt("Fail to open the thp file\n");
258 }
259
260 THPPlayerGetVideoInfo(&videoInfo);
261 THPPlayerGetAudioInfo(&audioInfo);
262
263 x = (rmode->fbWidth - videoInfo.xSize) / 2;
264 y = (rmode->efbHeight - videoInfo.ySize) / 2;
265
266 // Set aside work area
267 size = THPPlayerCalcNeedMemory();
268
269 #ifndef HOLLYWOOD_REV
270 buffer = (u8 *)OSAlloc(size);
271 #else
272 buffer = MEMAllocFromExpHeapEx(__ExpHeap, size, 32);
273 #endif
274
275 if (!buffer)
276 {
277 OSHalt("Can't allocate the memory");
278 }
279
280 // Set work area
281 THPPlayerSetBuffer(buffer);
282
283 // Select randomly, if there are multiple audio tracks.
284 if (audioInfo.sndNumTracks != 1)
285 {
286 audioTrack = (s32)(OSGetTick() % audioInfo.sndNumTracks);
287 }
288 else
289 {
290 audioTrack = 0;
291 }
292
293 // Preparation before playback
294 if (THPPlayerPrepare(0, THP_PLAY_LOOP, audioTrack) == FALSE)
295 {
296 OSHalt("Fail to prepare\n");
297 }
298
299 // Start playback
300 THPPlayerPlay();
301
302 open = FALSE;
303 play = TRUE;
304 }
305 }
306
307 THPPlayerQuit();
308
309 VIWaitForRetrace();
310
311 OSHalt("application end\n");
312
313 return;
314 }
315
MovieDoneRender(void)316 static void MovieDoneRender(void)
317 {
318 // Release used THP video data at same time as graphics processor
319 THPPlayerDrawDone();
320
321 DEMODoneRender();
322 }
323