1 /*---------------------------------------------------------------------------*
2   Project:  SC demo
3   File:     main.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   $NoKeywords: $
14  *---------------------------------------------------------------------------*/
15 #include <revolution/os.h>
16 #include <revolution/sc.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <wchar.h>
20 
21 #define DEMO_USE_MEMLIB=1 // This turns on the DEMO library's MEM heaps.
22 #include <demo.h>
23 
24 #define SCRN_WIDTH      640
25 #define SCRN_HEIGHT     480
26 
27 static u32  DemoFlushCount;
28 static u32  DemoFlushResult;
29 static GXColor Black  = { 0, 0, 0, 0 };
30 
DemoFlushCallback(u32 result)31 static void DemoFlushCallback(u32 result)
32 {
33     DemoFlushResult = result;
34 }
35 
InitDisp(GXRenderModeObj * rmp,GXColor color)36 static void InitDisp(GXRenderModeObj* rmp, GXColor color)
37 {
38     GXSetCopyClear( color, 0x00ffffff );
39     GXCopyDisp( DEMOGetCurrentBuffer(), GX_TRUE );
40     if ( !rmp )
41     {
42         rmp = DEMOGetRenderModeObj();
43     }
44     DEMOInitCaption( DM_FT_XLU, SCRN_WIDTH, SCRN_HEIGHT );
45     DEMOSetROMFontSize(16, -1);
46     GXSetZMode( GX_ENABLE, GX_ALWAYS, GX_ENABLE );                   // Set pixel processing mode
47     GXSetBlendMode( GX_BM_BLEND, GX_BL_ONE, GX_BL_ONE, GX_LO_CLEAR );// Translucent mode
48 }
49 
convertWcharToChar(char * string,wchar_t * w_string)50 static void convertWcharToChar(char* string, wchar_t* w_string)
51 {
52     char nstring[SC_OWNER_NICKNAME_LENGTH_MAX];
53     wcstombs(nstring, w_string, SC_OWNER_NICKNAME_LENGTH_MAX);
54 
55     strncpy(string, nstring, SC_OWNER_NICKNAME_LENGTH_MAX);
56 }
57 
myDEMORFPrintf(char * fmt,...)58 static void myDEMORFPrintf(char* fmt, ...)
59 {
60     va_list     vlist;
61     char        buf[256];
62     const s16   X_POS = 200;
63     const s16   Y_POS = 60;
64     const s16   Z_POS = 0;
65     const s16   incValue = 25;
66     static s16  i = 0;
67 
68     ASSERT( strlen( fmt ) <= 256 );
69 
70     // Get output string
71     va_start(vlist, fmt);
72     vsprintf(buf, fmt, vlist);
73     va_end(vlist);
74 
75     // Feed to puts
76     DEMORFPuts(X_POS, (s16)(Y_POS + i * incValue), Z_POS, buf);
77     i++;
78 }
79 
DemoMain(void)80 static void DemoMain(void)
81 {
82     char                        *msg;
83     u8                          aspectRatio;
84     u8                          language;
85     u8                          euRgb60Mode;
86     u8                          progressiveMode;
87     u8                          soundMode;
88     SCOwnerNickNameInfo         info;
89 
90     u8                          id;
91 
92     OSReport("DemoMain() called\n");
93     DEMOBeforeRender();
94 
95     // Get aspect ratio
96     aspectRatio = SCGetAspectRatio();
97     switch (aspectRatio) {
98       case SC_ASPECT_RATIO_4x3:
99         msg = "4x3";
100         break;
101 
102       case SC_ASPECT_RATIO_16x9:
103         msg = "16x9";
104         break;
105 
106       default:
107         msg = "UNKNOWN";
108         break;
109     }
110     OSReport("Aspect Ratio = %s\n", msg);
111     myDEMORFPrintf("Aspect Ratio = %s\n", msg);
112 
113     // Get language
114     language = SCGetLanguage();
115     switch (language) {
116       case SC_LANG_JAPANESE:
117         msg = "Japanese";
118         break;
119 
120       case SC_LANG_ENGLISH:
121         msg = "English";
122         break;
123 
124       case SC_LANG_GERMAN:
125         msg = "German";
126         break;
127 
128       case SC_LANG_FRENCH:
129         msg = "French";
130         break;
131 
132       case SC_LANG_SPANISH:
133         msg = "Spanish";
134         break;
135 
136       case SC_LANG_ITALIAN:
137         msg = "Italian";
138         break;
139 
140       case SC_LANG_DUTCH:
141         msg = "Dutch";
142         break;
143 
144       case SC_LANG_SIMP_CHINESE:
145         msg = "Simplified Chinese";
146         break;
147 
148       case SC_LANG_TRAD_CHINESE:
149         msg = "Traditional Chinese";
150         break;
151 
152       case SC_LANG_KOREAN:
153         msg = "Korean";
154         break;
155 
156       default:
157         msg = "UNKNOWN";
158         break;
159     }
160 
161     OSReport("Language = %s\n", msg);
162     myDEMORFPrintf("Language = %s\n", msg);
163 
164     // Get EURGB60 mode
165     euRgb60Mode = SCGetEuRgb60Mode();
166     switch (euRgb60Mode) {
167       case SC_EURGB60_MODE_OFF:
168         msg = "OFF";
169         break;
170 
171       case SC_EURGB60_MODE_ON:
172         msg = "ON";
173         break;
174 
175       default:
176         msg = "UNKNOWN";
177         break;
178     }
179     OSReport("EURGB60 Mode = %s\n", msg);
180     myDEMORFPrintf("EURGB60 Mode = %s\n", msg);
181 
182     // Get progressive mode
183     progressiveMode = SCGetProgressiveMode();
184     switch (progressiveMode) {
185       case SC_PROGRESSIVE_MODE_OFF:
186         msg = "OFF";
187         break;
188 
189       case SC_PROGRESSIVE_MODE_ON:
190         msg = "ON";
191         break;
192 
193       default:
194         msg = "UNKNOWN";
195         break;
196     }
197     OSReport("Progressive Mode = %s\n", msg);
198     myDEMORFPrintf("Progressive Mode = %s\n", msg);
199 
200     // Get sound mode
201     soundMode = SCGetSoundMode();
202     switch (soundMode) {
203       case SC_SOUND_MODE_MONO:
204         msg = "MONO";
205         break;
206 
207       case SC_SOUND_MODE_STEREO:
208         msg = "STEREO";
209         break;
210 
211       case SC_SOUND_MODE_SURROUND:
212         msg = "SURROUND";
213         break;
214 
215       default:
216         msg = "UNKNOWN";
217         break;
218     }
219     OSReport("Sound Mode = %s\n", msg);
220     myDEMORFPrintf("Sound Mode = %s\n", msg);
221 
222     // Get nickname
223     if (!SCGetOwnerNickName(&info)) {
224         msg = "UNKNOWN";
225     } else {
226         convertWcharToChar(msg, info.name);
227     }
228     OSReport("Nickname = %s\n", msg );
229     myDEMORFPrintf("Nickname = %s\n", msg ); // multi-byte characters will be garbled in this demo.
230 
231     // Get regionID(Hi)
232     if (!SCGetSimpleAddressRegionIdHi(&id)) {
233         OSReport("Region ID(Hi) = NOT DEFINED\n");
234         myDEMORFPrintf("Region ID(Hi) = NOT DEFINED\n");
235     } else if (id == SC_SIMPLE_ADDRESS_REGION_ID_HI_UNDEFINED || id == SC_SIMPLE_ADDRESS_REGION_ID_HI_UNDEFINED2) {
236         OSReport("Region ID(Hi) = OUT OF RANGE VALUE\n");
237         myDEMORFPrintf("Region ID(Hi) = OUT OF RANGE VALUE\n");
238     } else {
239         OSReport("Region ID(Hi) = %d\n", id);
240         myDEMORFPrintf("Region ID(Hi) = %d\n", id);
241     }
242 }
243 
main(void)244 int main(void)
245 {
246     SCInit();
247     DEMOInit( &GXNtsc480IntDf );
248     DEMOInitROMFont();
249     InitDisp( &GXNtsc480IntDf, Black );
250 
251     {
252         u32 status;
253         u32 count = 0;
254 
255         // Wait until SC initialize finishes
256         do {
257             status = SCCheckStatus();
258             count++;
259         } while (status == SC_STATUS_BUSY);
260 
261         OSReport("SCInit finished. status = %d, count = %d\n", status, count);
262         if (status != SC_STATUS_OK) {
263             myDEMORFPrintf("Demo failed\n");
264             OSHalt("Demo failed");
265         }
266     }
267 
268     DemoMain();
269 
270     {
271         u32 status = SCCheckStatus();
272 
273         if (status == SC_STATUS_OK) {
274             SCFlushAsync(DemoFlushCallback);
275 
276             while (SCCheckStatus() == SC_STATUS_BUSY) {
277                 DemoFlushCount++;
278             }
279             OSReport("SCFlushAsync result=%d, count=%d\n", DemoFlushResult, DemoFlushCount);
280             myDEMORFPrintf("SCFlushAsync result = %d, count = %d\n", DemoFlushResult, DemoFlushCount);
281         } else {
282             OSReport("SCFlushAsync was not executed due to status (%d)\n", status);
283             myDEMORFPrintf("SCFlushAsync was not executed due to status (%d)\n", status);
284         }
285         myDEMORFPrintf("Demo complete\n");
286         DEMODoneRender();
287     }
288 
289     OSReport("\n");
290     OSHalt("Demo complete");
291     return EXIT_SUCCESS;
292 }
293