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