/*---------------------------------------------------------------------------* Project: SC demo File: main.c Copyright 2006 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $NoKeywords: $ *---------------------------------------------------------------------------*/ #include #include #include #include #include #define DEMO_USE_MEMLIB=1 // This turns on the DEMO library's MEM heaps. #include #define SCRN_WIDTH 640 #define SCRN_HEIGHT 480 static u32 DemoFlushCount; static u32 DemoFlushResult; static GXColor Black = { 0, 0, 0, 0 }; static void DemoFlushCallback(u32 result) { DemoFlushResult = result; } static void InitDisp(GXRenderModeObj* rmp, GXColor color) { GXSetCopyClear( color, 0x00ffffff ); GXCopyDisp( DEMOGetCurrentBuffer(), GX_TRUE ); if ( !rmp ) { rmp = DEMOGetRenderModeObj(); } DEMOInitCaption( DM_FT_XLU, SCRN_WIDTH, SCRN_HEIGHT ); DEMOSetROMFontSize(16, -1); GXSetZMode( GX_ENABLE, GX_ALWAYS, GX_ENABLE ); // Set pixel processing mode GXSetBlendMode( GX_BM_BLEND, GX_BL_ONE, GX_BL_ONE, GX_LO_CLEAR );// Translucent mode } static void convertWcharToChar(char* string, wchar_t* w_string) { char nstring[SC_OWNER_NICKNAME_LENGTH_MAX]; wcstombs(nstring, w_string, SC_OWNER_NICKNAME_LENGTH_MAX); strncpy(string, nstring, SC_OWNER_NICKNAME_LENGTH_MAX); } static void myDEMORFPrintf(char* fmt, ...) { va_list vlist; char buf[256]; const s16 X_POS = 200; const s16 Y_POS = 60; const s16 Z_POS = 0; const s16 incValue = 25; static s16 i = 0; ASSERT( strlen( fmt ) <= 256 ); // Get output string va_start(vlist, fmt); vsprintf(buf, fmt, vlist); va_end(vlist); // Feed to puts DEMORFPuts(X_POS, (s16)(Y_POS + i * incValue), Z_POS, buf); i++; } static void DemoMain(void) { char *msg; u8 aspectRatio; u8 language; u8 euRgb60Mode; u8 progressiveMode; u8 soundMode; SCOwnerNickNameInfo info; u8 id; OSReport("DemoMain() called\n"); DEMOBeforeRender(); // Get aspect ratio aspectRatio = SCGetAspectRatio(); switch (aspectRatio) { case SC_ASPECT_RATIO_4x3: msg = "4x3"; break; case SC_ASPECT_RATIO_16x9: msg = "16x9"; break; default: msg = "UNKNOWN"; break; } OSReport("Aspect Ratio = %s\n", msg); myDEMORFPrintf("Aspect Ratio = %s\n", msg); // Get language language = SCGetLanguage(); switch (language) { case SC_LANG_JAPANESE: msg = "Japanese"; break; case SC_LANG_ENGLISH: msg = "English"; break; case SC_LANG_GERMAN: msg = "German"; break; case SC_LANG_FRENCH: msg = "French"; break; case SC_LANG_SPANISH: msg = "Spanish"; break; case SC_LANG_ITALIAN: msg = "Italian"; break; case SC_LANG_DUTCH: msg = "Dutch"; break; case SC_LANG_SIMP_CHINESE: msg = "Simplified Chinese"; break; case SC_LANG_TRAD_CHINESE: msg = "Traditional Chinese"; break; case SC_LANG_KOREAN: msg = "Korean"; break; default: msg = "UNKNOWN"; break; } OSReport("Language = %s\n", msg); myDEMORFPrintf("Language = %s\n", msg); // Get EURGB60 mode euRgb60Mode = SCGetEuRgb60Mode(); switch (euRgb60Mode) { case SC_EURGB60_MODE_OFF: msg = "OFF"; break; case SC_EURGB60_MODE_ON: msg = "ON"; break; default: msg = "UNKNOWN"; break; } OSReport("EURGB60 Mode = %s\n", msg); myDEMORFPrintf("EURGB60 Mode = %s\n", msg); // Get progressive mode progressiveMode = SCGetProgressiveMode(); switch (progressiveMode) { case SC_PROGRESSIVE_MODE_OFF: msg = "OFF"; break; case SC_PROGRESSIVE_MODE_ON: msg = "ON"; break; default: msg = "UNKNOWN"; break; } OSReport("Progressive Mode = %s\n", msg); myDEMORFPrintf("Progressive Mode = %s\n", msg); // Get sound mode soundMode = SCGetSoundMode(); switch (soundMode) { case SC_SOUND_MODE_MONO: msg = "MONO"; break; case SC_SOUND_MODE_STEREO: msg = "STEREO"; break; case SC_SOUND_MODE_SURROUND: msg = "SURROUND"; break; default: msg = "UNKNOWN"; break; } OSReport("Sound Mode = %s\n", msg); myDEMORFPrintf("Sound Mode = %s\n", msg); // Get nickname if (!SCGetOwnerNickName(&info)) { msg = "UNKNOWN"; } else { convertWcharToChar(msg, info.name); } OSReport("Nickname = %s\n", msg ); myDEMORFPrintf("Nickname = %s\n", msg ); // multi-byte characters will be garbled in this demo. // Get regionID(Hi) if (!SCGetSimpleAddressRegionIdHi(&id)) { OSReport("Region ID(Hi) = NOT DEFINED\n"); myDEMORFPrintf("Region ID(Hi) = NOT DEFINED\n"); } else if (id == SC_SIMPLE_ADDRESS_REGION_ID_HI_UNDEFINED || id == SC_SIMPLE_ADDRESS_REGION_ID_HI_UNDEFINED2) { OSReport("Region ID(Hi) = OUT OF RANGE VALUE\n"); myDEMORFPrintf("Region ID(Hi) = OUT OF RANGE VALUE\n"); } else { OSReport("Region ID(Hi) = %d\n", id); myDEMORFPrintf("Region ID(Hi) = %d\n", id); } } int main(void) { SCInit(); DEMOInit( &GXNtsc480IntDf ); DEMOInitROMFont(); InitDisp( &GXNtsc480IntDf, Black ); { u32 status; u32 count = 0; // Wait until SC initialize finishes do { status = SCCheckStatus(); count++; } while (status == SC_STATUS_BUSY); OSReport("SCInit finished. status = %d, count = %d\n", status, count); if (status != SC_STATUS_OK) { myDEMORFPrintf("Demo failed\n"); OSHalt("Demo failed"); } } DemoMain(); { u32 status = SCCheckStatus(); if (status == SC_STATUS_OK) { SCFlushAsync(DemoFlushCallback); while (SCCheckStatus() == SC_STATUS_BUSY) { DemoFlushCount++; } OSReport("SCFlushAsync result=%d, count=%d\n", DemoFlushResult, DemoFlushCount); myDEMORFPrintf("SCFlushAsync result = %d, count = %d\n", DemoFlushResult, DemoFlushCount); } else { OSReport("SCFlushAsync was not executed due to status (%d)\n", status); myDEMORFPrintf("SCFlushAsync was not executed due to status (%d)\n", status); } myDEMORFPrintf("Demo complete\n"); DEMODoneRender(); } OSReport("\n"); OSHalt("Demo complete"); return EXIT_SUCCESS; }