1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - WM - demos - wireless-all
3 File: wh_download.c
4
5 Copyright 2006-2008 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 $Date:: 2009-08-28#$
14 $Rev: 11027 $
15 $Author: tominaga_masafumi $
16 *---------------------------------------------------------------------------*/
17
18 #ifdef SDK_TWL
19 #include <twl.h>
20 #else
21 #include <nitro.h>
22 #endif
23
24 #include "common.h"
25
26
27 /*****************************************************************************/
28 /* Constants */
29
30 /* Download program data (clone boot) */
31 /* *INDENT-OFF* */
32 const MBGameRegistry mbGameList =
33 {
34 NULL,
35 (u16 *)L"wireless-all",
36 (u16 *)L"all of the wireless demo(cloneboot, dataSharing, WFS)",
37 "/icon.char", "/icon.plt",
38 WH_GGID,
39 WH_CHILD_MAX + 1,
40 };
41 /* *INDENT-ON* */
42
43
44 /*****************************************************************************/
45 /* Functions */
46
47 /*****************************************************************************/
48 /* Start the definition range of the .parent section parent device exclusive region */
49 #include <nitro/parent_begin.h>
50 /*****************************************************************************/
51
52 /*---------------------------------------------------------------------------*
53 Name: ConnectMain
54
55 Description: Connect with multiboot.
56
57 Arguments: None.
58
59 Returns: Returns TRUE if the transfer to the child succeeds; returns FALSE if transfer fails or is cancelled.
60
61 *---------------------------------------------------------------------------*/
ConnectMain(void)62 static BOOL ConnectMain(void)
63 {
64 for (;;)
65 {
66 /* Frame wait */
67 (void)WaitNextFrame();
68
69 PrintString(4, 22, PLTT_YELLOW, " MB Parent ");
70
71 switch (MBP_GetState())
72 {
73 //-----------------------------------------
74 // Accepting entry from the child
75 case MBP_STATE_ENTRY:
76 {
77 PrintString(4, 22, PLTT_WHITE, " Now Accepting ");
78
79 if (IS_PAD_TRIGGER(PAD_BUTTON_B))
80 {
81 // Cancel multiboot with B Button
82 MBP_Cancel();
83 break;
84 }
85
86 // If there is at least one child in entry, start is possible
87 if (MBP_GetChildBmp(MBP_BMPTYPE_ENTRY) ||
88 MBP_GetChildBmp(MBP_BMPTYPE_DOWNLOADING) ||
89 MBP_GetChildBmp(MBP_BMPTYPE_BOOTABLE))
90 {
91 PrintString(4, 22, PLTT_WHITE, " Push START Button to start ");
92
93 if (IS_PAD_TRIGGER(PAD_BUTTON_START))
94 {
95 // Start download
96 MBP_StartDownloadAll();
97 }
98 }
99 }
100 break;
101
102 //-----------------------------------------
103 // Program distribution process
104 case MBP_STATE_DATASENDING:
105 {
106
107 // If everyone has completed download, start is possible
108 if (MBP_IsBootableAll())
109 {
110 // Start boot
111 MBP_StartRebootAll();
112 }
113 }
114 break;
115
116 //-----------------------------------------
117 // Reboot process
118 case MBP_STATE_REBOOTING:
119 {
120 PrintString(4, 22, PLTT_WHITE, " Rebooting now ");
121 }
122 break;
123
124 //-----------------------------------------
125 // Reconnect process
126 case MBP_STATE_COMPLETE:
127 {
128 // Once all members have successfully connected, the multiboot processing ends, and restarts the wireless as an normal parent
129 //
130 PrintString(4, 22, PLTT_WHITE, " Reconnecting now ");
131
132 OS_WaitVBlankIntr();
133 return TRUE;
134 }
135 break;
136
137 //-----------------------------------------
138 // Error occurred
139 case MBP_STATE_ERROR:
140 {
141 // Cancel communication
142 MBP_Cancel();
143 }
144 break;
145
146 //-----------------------------------------
147 // Communication cancellation processsing
148 case MBP_STATE_CANCEL:
149 // None.
150 break;
151
152 //-----------------------------------------
153 // Abnormal termination of communication
154 case MBP_STATE_STOP:
155 OS_WaitVBlankIntr();
156 return FALSE;
157 }
158
159 // Display child state
160 {
161 static const char *STATE_NAME[] = {
162 "NONE ",
163 "CONNECTING ",
164 "REQUEST ",
165 "ENTRY ",
166 "DOWNLOADING",
167 "BOOTABLE ",
168 "BOOTING ",
169 };
170 enum
171 {
172 STATE_DISP_X = 2,
173 INFO_DISP_X = 15,
174 BASE_DISP_Y = 2
175 };
176
177 u16 i;
178
179 /* Child list display */
180 for (i = 1; i < WH_PLAYER_MAX; i++)
181 {
182 const MBPChildInfo *childInfo;
183 MBPChildState childState = MBP_GetChildState(i);
184 const u8 *macAddr;
185 // State display
186 PrintString(STATE_DISP_X, i + BASE_DISP_Y, PLTT_WHITE, STATE_NAME[childState]);
187 // User information display
188 childInfo = MBP_GetChildInfo(i);
189 macAddr = MBP_GetChildMacAddress(i);
190 if (macAddr)
191 {
192 PrintString(INFO_DISP_X, i + BASE_DISP_Y, PLTT_WHITE,
193 "%02x%02x%02x%02x%02x%02x",
194 macAddr[0], macAddr[1], macAddr[2], macAddr[3], macAddr[4],
195 macAddr[5]);
196 }
197 }
198 }
199 }
200 }
201
202 /*---------------------------------------------------------------------------*
203 Name: ExecuteDownloadServer
204
205 Description: DS Single-Card play parent processing.
206
207 Arguments: None.
208
209 Returns: None.
210 *---------------------------------------------------------------------------*/
ExecuteDownloadServer(void)211 void ExecuteDownloadServer(void)
212 {
213 WH_SetGgid(WH_GGID);
214
215 for (;;)
216 {
217 /* Wireless initialization */
218 if (!WH_Initialize())
219 {
220 OS_Panic("WH_Initialize failed.");
221 }
222 WaitWHState(WH_SYSSTATE_IDLE);
223 while (!IS_PAD_TRIGGER(PAD_BUTTON_A))
224 {
225 (void)WaitNextFrame();
226 PrintString(4, 22, PLTT_WHITE, " Press A Button to start ");
227 }
228 /* Search for a channel with little traffic */
229 SetCurrentChannel(MeasureChannel());
230
231 /* Start DS Download Play */
232 #if !defined(MBP_USING_MB_EX)
233 (void)WH_End();
234 WaitWHState(WH_SYSSTATE_STOP);
235 #endif
236 MBP_Init(WH_GGID, WM_GetNextTgid());
237 MBP_Start(&mbGameList, GetCurrentChannel());
238
239 if (ConnectMain())
240 {
241 /* Multiboot child startup is successful */
242 break;
243 }
244 else
245 {
246 /* Exit the WH module and repeat */
247 WH_Finalize();
248 WaitWHState(WH_SYSSTATE_IDLE);
249 (void)WH_End();
250 WaitWHState(WH_SYSSTATE_STOP);
251 }
252 }
253
254 }
255
256
257 /*****************************************************************************/
258 /* End the definition boundary of the .parent section parent device exclusive region */
259 #include <nitro/parent_end.h>
260 /*****************************************************************************/
261