1 /*---------------------------------------------------------------------------*
2 Project: Revolution SDK DS-Wireless FileSystem demo
3 File: download.c
4
5 Copyright 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: download.c,v $
14 Revision 1.5 2007/10/26 08:06:56 seiki_masashi
15 Support for REXDEMOGetAnyMixedPadTrigger.
16
17 Revision 1.4 2007/08/01 09:36:29 kitase_hirotake
18 Changed TAB to SPACE.
19
20 Revision 1.3 2007/02/27 00:26:06 yosizaki
21 Changed type of the playerbits (from int to u32)
22
23 Revision 1.2 2007/02/21 08:08:41 okubata_ryoma
24 Small fix
25
26 Revision 1.1 2007/01/16 08:33:30 yosizaki
27 Initial upload.
28
29 $NoKeywords: $
30 *---------------------------------------------------------------------------*/
31
32
33 #include <revolution.h>
34 #include <revolution/mpdl.h>
35 #include <revolution/mem.h>
36
37 #include "rexdemo/demokpad.h"
38 #include "rexdemo/graphic.h"
39
40
41 /*===========================================================================*/
42 /* Variables */
43
44 /* MPDL work structure */
45 static MPDLConfig mpdlConfig ATTRIBUTE_ALIGN(32) =
46 {
47 NULL,
48 NULL,
49 2, // threadPriority
50 0x00000000, // ggid
51 MP_TGID_AUTO, // tgid
52 MP_CHANNEL_AUTO, // channel
53
54 0, // serverColor
55 L"Wii", // serverName
56 L"MPFS sample", // programTitle
57 L"do MPDL��MPFS", // programComment
58 3, // programMaxEntry
59 NULL, // programImage
60 };
61
62
63 /*===========================================================================*/
64 /* Functions */
65
66 // MPDL driver
67 void ExecuteDownload(void* (*alloc)(u32), void (*free)(void*), const void *program);
68
69
ExecuteDownload(void * (* alloc)(u32),void (* free)(void *),const void * program)70 void ExecuteDownload(void* (*alloc)(u32), void (*free)(void*), const void *program)
71 {
72 enum
73 {
74 MODE_AUTODOWNLOAD,
75 MODE_MAX
76 };
77
78 static BOOL auto_download_mode = TRUE;
79 int mode_cursor = 0;
80 BOOL is_entry_closed = FALSE;
81 u32 fixed_entry = 0;
82 MPDLConfig * const config = &mpdlConfig;
83
84 config->alloc = alloc;
85 config->free = free;
86 config->programImage = (void*)program;
87
88 /* Initialize and startup MPDL */
89 if ( MPDLStartup( config ) != MP_RESULT_OK )
90 {
91 OSHalt( "failed to startup MPDL!\n" );
92 }
93
94 for (; ;)
95 {
96 int i;
97 u32 entry;
98 u32 booted;
99
100 REXDEMOKPadRead();
101
102 /* Update sequence */
103 entry = MPDLGetEntryBitmap();
104 booted = MPDLGetBootedBitmap();
105 if (!is_entry_closed)
106 {
107 const u32 full_entry = (u32)(((1 << config->programMaxEntry) - 1) & ~1);
108 /* Move cursor and select options */
109 if ((REXDEMOGetAnyMixedPadTrigger() & (KPAD_BUTTON_RIGHT | KPAD_BUTTON_LEFT | (PAD_BUTTON_RIGHT << 16) | (PAD_BUTTON_LEFT << 16))) != 0)
110 {
111 switch (mode_cursor)
112 {
113 case MODE_AUTODOWNLOAD:
114 auto_download_mode = !auto_download_mode;
115 break;
116 default:
117 break;
118 }
119 }
120 if (((REXDEMOGetAnyMixedPadTrigger() & (KPAD_BUTTON_UP | (PAD_BUTTON_UP << 16))) != 0) && (--mode_cursor < 0))
121 {
122 mode_cursor += MODE_MAX;
123 }
124 if (((REXDEMOGetAnyMixedPadTrigger() & (KPAD_BUTTON_DOWN | (PAD_BUTTON_DOWN << 16))) != 0) && (++mode_cursor >= MODE_MAX))
125 {
126 mode_cursor -= MODE_MAX;
127 }
128 /* Close entry and start download */
129 if (((entry == full_entry) && auto_download_mode) ||
130 ((REXDEMOGetAnyMixedPadTrigger() & (KPAD_BUTTON_A | (PAD_BUTTON_A << 16))) != 0))
131 {
132 is_entry_closed = TRUE;
133 fixed_entry = MPDLStartDownload();
134 }
135 }
136 else if (entry == 0)
137 {
138 MPDLEnableFlag(TRUE, FALSE);
139 if ((REXDEMOGetAnyMixedPadTrigger() & (KPAD_BUTTON_A | (PAD_BUTTON_A << 16))) != 0)
140 {
141 break;
142 }
143 }
144
145 /* DrawFrame */
146 REXDEMOBeginRender();
147 {
148 /* *INDENT-OFF* */
149 static const GXColor ds_ipl_color_table[16] =
150 {
151 { 0x63, 0x84, 0x9C, }, /* GRAY */
152 { 0xBD, 0x4A, 0x00, }, /* BROWN */
153 { 0xFF, 0x00, 0x18, }, /* RED */
154 { 0xFF, 0x8C, 0xFF, }, /* PINK */
155 { 0xFF, 0x94, 0x00, }, /* ORANGE */
156 { 0xF7, 0xE7, 0x00, }, /* YELLOW */
157 { 0xAD, 0xFF, 0x00, }, /* LIME_GREEN */
158 { 0x00, 0xFF, 0x00, }, /* GREEN */
159 { 0x00, 0xA5, 0x39, }, /* DARK_GREEN */
160 { 0x4A, 0xDE, 0x8C, }, /* SEA_GREEN */
161 { 0x31, 0xBD, 0xF7, }, /* TURQUOISE */
162 { 0x00, 0x5A, 0xF7, }, /* BLUE */
163 { 0x00, 0x00, 0x94, }, /* DARK_BLUE */
164 { 0x8C, 0x00, 0xD6, }, /* PURPLE */
165 { 0xD6, 0x00, 0xEF, }, /* VIOLET */
166 { 0xFF, 0x00, 0x94, }, /* MAGENTA */
167 };
168 /* *INDENT-ON* */
169 const s16 ox = 4, oy = 158;
170
171 /* header */
172 REXDEMOSetTextColor(REXDEMO_COLOR_WHITE);
173 REXDEMOPrintf(4, 8, 0, "MPDL simple sample");
174 REXDEMOSetTextColor(REXDEMO_COLOR_YELLOW);
175 if (!is_entry_closed)
176 {
177 REXDEMOPrintf(4, 24, 0, "entry is opened.");
178 REXDEMOPrintf(200, 24, 0, "(press A to start download)");
179 }
180 else if (entry > 0)
181 {
182 REXDEMOPrintf(4, 24, 0, "entry is closed, now downloading...");
183 }
184 else
185 {
186 REXDEMOPrintf(4, 24, 0, "download has been completed.");
187 REXDEMOPrintf(320, 24, 0, "(press A to restart as FS server)");
188 }
189
190 REXDEMOSetTextColor(REXDEMO_COLOR_WHITE);
191 REXDEMOPrintf(30, 60, 0, "auto-download mode : ON OFF");
192 REXDEMOSetTextColor(REXDEMO_COLOR_YELLOW);
193 REXDEMOPrintf(10, 60 + mode_cursor * 10, 0, ">");
194 REXDEMOPrintf(30, 60, 0, " %s %s",
195 auto_download_mode ? "[ ]" : " ",
196 auto_download_mode ? " " : "[ ]");
197
198 /* entries */
199 REXDEMOSetTextColor(REXDEMO_COLOR_WHITE);
200 REXDEMOPrintf(ox, oy, 0, "AID STATUS MAC-ADDR NAME");
201 for (i = 1; i < 16; ++i)
202 {
203 const s16 sy = (s16)(oy + i * 15);
204 MPDLPlayerInfo info[1];
205 BOOL valid_player = MPDLGetPlayerInfo(i, info);
206 REXDEMOSetTextColor(valid_player ? ds_ipl_color_table[info->color] : REXDEMO_COLOR_GRAY);
207
208 /* AID */
209 REXDEMOPrintf(ox + 5, sy, 0, "%2d", i);
210
211 /* STATUS */
212 if (!is_entry_closed)
213 {
214 if (valid_player)
215 {
216 REXDEMOPrintf(ox + 40, sy, 0, "ready");
217 }
218 else if (i < config->programMaxEntry)
219 {
220 REXDEMOPrintf(ox + 40, sy, 0, " none ");
221 }
222 }
223 else
224 {
225 if (valid_player)
226 {
227 if ((booted & (1 << i)) != 0)
228 {
229 REXDEMOPrintf(ox + 40, sy, 0, "booted");
230 }
231 else
232 {
233 REXDEMOPrintf(ox + 40, sy, 0, " %3d%% ", info->progress);
234 }
235 }
236 else if ((fixed_entry & (1 << i)) != 0)
237 {
238 REXDEMOPrintf(ox + 40, sy, 0, "failed");
239 }
240 }
241
242 /* MAC-ADDR & NAME */
243 if (valid_player)
244 {
245 char name[MPDL_PLAYER_NAME_MAX + 1];
246 int n;
247 for (n = 0; n < info->name_length; ++n)
248 {
249 u16 c = info->name[n];
250 name[n] = (char)(((c & 0xFF) == 0) ? (c >> 8) : '?');
251 }
252 name[n] = '\0';
253 REXDEMOPrintf(ox + 110, sy, 0,
254 "%02X%02X%02X:%02X%02X%02X %-10s",
255 info->mac[0], info->mac[1], info->mac[2],
256 info->mac[3], info->mac[4], info->mac[5], name);
257 }
258
259 }
260 }
261
262 REXDEMOWaitRetrace();
263 }
264 (void)MPDLCleanup();
265 }
266
267
268 /*===========================================================================*/
269