1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - WXC - demos - wxc-dataShare
3 File: gmain.c
4
5 Copyright 2005-2009 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:: 2007-11-15#$
14 $Rev: 2414 $
15 $Author: hatamoto_minoru $
16 *---------------------------------------------------------------------------*/
17
18
19 #include <nitro.h>
20
21 #include "gmain.h"
22 #include "common.h"
23 #include "disp.h"
24 #include "wh.h"
25
26
27
28 //============================================================================
29 // Variable Definitions
30 //============================================================================
31
32 //-----------------------
33 // For data sharing
34 //-----------------------
35 static u8 sSendBuf[256] ATTRIBUTE_ALIGN(32); // Send buffer (must be 32-byte aligned)
36 static u8 sRecvBuf[256] ATTRIBUTE_ALIGN(32); // Receive buffer (must 32-byte aligned)
37 static BOOL sRecvFlag[1 + WM_NUM_MAX_CHILD]; // Receive flag
38 static GShareData *sShareDataPtr;
39
40 //============================================================================
41 // Function Definitions
42 //============================================================================
43
44 /*---------------------------------------------------------------------------*
45 Name: GInitDataShare
46
47 Description: Initializes settings for data-sharing buffer.
48
49 Arguments: None.
50
51 Returns: None.
52 *---------------------------------------------------------------------------*/
GInitDataShare(void)53 void GInitDataShare(void)
54 {
55 sShareDataPtr = (GShareData *) sSendBuf;
56
57 DC_FlushRange(sSendBuf, 4);
58 DC_WaitWriteBufferEmpty();
59 }
60
61
62 /*---------------------------------------------------------------------------*
63 Name: GStepDataShare
64
65 Description: Proceeds to the next data sharing synchronization.
66
67 Arguments: None.
68
69 Returns: None.
70 *---------------------------------------------------------------------------*/
GStepDataShare(s32 frame)71 BOOL GStepDataShare(s32 frame)
72 {
73 sShareDataPtr->count = (u32)frame;
74
75 switch (WH_GetSystemState())
76 {
77 //------------------------------
78 // Data-sharing communication
79 case WH_SYSSTATE_DATASHARING:
80 {
81 u16 i;
82 u8 *adr;
83
84 if (!WH_StepDS(sSendBuf))
85 {
86 // Data-sharing communication failure
87 return FALSE;
88 }
89
90 for (i = 0; i < 16; ++i)
91 {
92 adr = (u8 *)WH_GetSharedDataAdr(i);
93 if (adr != NULL)
94 {
95 MI_CpuCopy8(adr, &(sRecvBuf[i * sizeof(GShareData)]), sizeof(GShareData));
96 sRecvFlag[i] = TRUE;
97 }
98 else
99 {
100 sRecvFlag[i] = FALSE;
101 }
102 }
103 }
104 break;
105 }
106 return TRUE;
107 }
108
109
110
111
112
113
114 /*---------------------------------------------------------------------------*
115 Name: GMain
116
117 Description: Parent-child common main routine.
118
119 Arguments: None.
120
121 Returns: None.
122 *---------------------------------------------------------------------------*/
GMain(void)123 void GMain(void)
124 {
125
126 BgPrintStr(4, 3, 0x4, "Send: %04x-%04x", sShareDataPtr->key, sShareDataPtr->count);
127 BgPutString(4, 5, 0x4, "Receive:");
128 {
129 s32 i;
130
131 for (i = 0; i < (WM_NUM_MAX_CHILD + 1); i++)
132 {
133 if (sRecvFlag[i])
134 {
135 GShareData *sd;
136 sd = (GShareData *) (&(sRecvBuf[i * sizeof(GShareData)]));
137
138 BgPrintStr(4, (s16)(6 + i), 0x4,
139 "Player%02d: %04x-%04x", i, sd->key, sd->count & 0xffff);
140 }
141 else
142 {
143 BgPutString(4, (s16)(6 + i), 0x7, "No child");
144 }
145 }
146 }
147 }
148