1 /*---------------------------------------------------------------------------*
2 Project: THP Simple Player demo
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/10/11 02:51:31 aka
15 Revised HOLLYWOOD_REV.
16
17 Revision 1.1 2006/02/03 10:01:13 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:18a Suzuki
25 Support multi audio track
26
27 2 02/02/28 6:38p Akagi
28 enabled to use with MusyX/AX by Suzuki-san (IRD).
29
30 1 02/01/16 10:54a Akagi
31 Initial revision made by Suzuki-san (IRD).
32
33 $NoKeywords: $
34
35 *---------------------------------------------------------------------------*/
36
37 #include <stdlib.h>
38 #include <string.h>
39 #include <demo.h>
40 #include <revolution/mem.h>
41
42 #include "THPSimple.h"
43 #include "axseq.h"
44
45 MEMHeapHandle __ExpHeap;
46
main(void)47 void main(void)
48 {
49 u32 size, x, y, count;
50 s32 frame, start, vol, audioTrack;
51 u16 buttonDown, button;
52 u8 *buffer;
53 GXRenderModeObj *rmode;
54 THPVideoInfo videoInfo;
55 THPAudioInfo audioInfo;
56 void *arenaMem2Lo;
57 void *arenaMem2Hi;
58
59 DEMOInit(&GXNtsc480Int);
60
61 arenaMem2Lo = OSGetMEM2ArenaLo();
62 arenaMem2Hi = OSGetMEM2ArenaHi();
63 __ExpHeap = MEMCreateExpHeap(arenaMem2Lo, (u32)arenaMem2Hi - (u32) arenaMem2Lo);
64
65 AIInit(NULL);
66
67 AXSeqSetup();
68
69 THPSimpleInit(THP_MODE_WITH_AX);
70
71 GXSetDispCopyGamma(GX_GM_1_0);
72
73 // Open THP file
74 if (THPSimpleOpen("thpdemo/fish_mlt.thp") == FALSE)
75 {
76 OSHalt("THPSimpleOpen fail");
77 }
78
79 THPSimpleGetVideoInfo(&videoInfo);
80 THPSimpleGetAudioInfo(&audioInfo);
81
82 rmode = DEMOGetRenderModeObj();
83
84 x = (rmode->fbWidth - videoInfo.xSize) / 2;
85 y = (rmode->efbHeight - videoInfo.ySize) / 2;
86
87 // Set aside work area
88 size = THPSimpleCalcNeedMemory();
89
90 buffer = MEMAllocFromExpHeapEx(__ExpHeap, size, 32);
91
92 if (!buffer)
93 {
94 OSHalt("Can't allocate the memory\n");
95 }
96
97 THPSimpleSetBuffer(buffer);
98
99 OSReport("\n#######################################\n");
100 OSReport("Push A button : restart the movie, select audio track at random\n");
101 OSReport("Push B button : play/stop midi file using AX\n");
102 OSReport("Push Start button : application end\n");
103 OSReport("Pad up : volume up\n");
104 OSReport("Pad down : volume down\n");
105 OSReport("#######################################\n");
106
107 RESTART:
108 // Preload for playback
109 if (THPSimplePreLoad(THP_PLAY_LOOP) == FALSE)
110 {
111 OSHalt("THPSimplePreLoad fail");
112 }
113
114 audioTrack = (s32)(OSGetTick() % audioInfo.sndNumTracks);
115
116 start = 1;
117
118 count = VIGetRetraceCount();
119
120 while(1)
121 {
122 DEMOPadRead();
123
124 buttonDown = DEMOPadGetButtonDown(PAD_CHAN0);
125 button = DEMOPadGetButton(PAD_CHAN0);
126
127 DEMOBeforeRender();
128
129 // Decode 1 frame of THP data
130 if (THPSimpleDecode(audioTrack) == THP_VIDEO_DECODE_FAIL)
131 {
132 OSHalt("Failed to decode video data");
133 }
134
135 // Draw decoded THP video data
136 frame = THPSimpleDrawCurrentFrame(rmode, x, y, videoInfo.xSize, videoInfo.ySize);
137
138 while (VIGetRetraceCount() < count + 1)
139 {
140 VIWaitForRetrace();
141 }
142
143 DEMODoneRender();
144
145 count = VIGetRetraceCount();
146
147 if (start)
148 {
149 // Allow audio output
150 THPSimpleAudioStart();
151 start = 0;
152 }
153
154 if (buttonDown & PAD_BUTTON_A)
155 {
156 // Stop playback and then restart
157 THPSimpleAudioStop();
158 THPSimpleLoadStop();
159 goto RESTART;
160 }
161
162 if (buttonDown & PAD_BUTTON_START)
163 {
164 // Stop playback and exit from main loop
165 THPSimpleAudioStop();
166 THPSimpleLoadStop();
167 THPSimpleClose();
168
169 MEMFreeToExpHeap(__ExpHeap, buffer);
170
171 break;
172 }
173
174 if (buttonDown & PAD_BUTTON_B)
175 {
176 if (GetSeqState())
177 {
178 SeqStop();
179 }
180 else
181 {
182 SeqPlay();
183 }
184 }
185
186 if (button & PAD_BUTTON_UP)
187 {
188 vol = THPSimpleGetVolume() + 1;
189 if (vol > 127)
190 {
191 vol = 127;
192 }
193 THPSimpleSetVolume(vol, 0);
194 }
195
196 if (button & PAD_BUTTON_DOWN)
197 {
198 vol = THPSimpleGetVolume() - 1;
199 if (vol < 0)
200 {
201 vol = 0;
202 }
203 THPSimpleSetVolume(vol, 0);
204 }
205 }
206
207 THPSimpleQuit();
208
209 VIWaitForRetrace();
210
211 OSHalt("application end\n");
212
213 return;
214 }
215