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