/*---------------------------------------------------------------------------* Copyright 2010-2012 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. *---------------------------------------------------------------------------*/ ////=========================================================================== /// demoSystem.c /// /// This is system code for the demo library. /// ////=========================================================================== #include #include #include #include #include void (*DEMOReleaseCallback)(void); #define MAX_BUFSIZ 512 extern unsigned int TCoreMEM2Limit(void); extern unsigned int TCoreMEM2Limit(void) { // Limit TCore MEM2 Usage to: 12MB // TOD0: Pick a less randmon TCore MEM limit return 0x00C00000; } u32 DEMOSaveCallback(void* unused) { // Finish any saving before calling OSSavesDone_ReadyToRelease OSSavesDone_ReadyToRelease(); return 0; } void DEMOEmptyReleaseCallback(void) { // If fading or something else is desired, this call can be postponed ProcUIDrawDoneRelease(); } void DEMOSetReleaseCallback(DEMOReleaseCallbackFunc func) { DEMOReleaseCallback = func; } static BOOL gDemoRunningFlag; static int sMainCore; static DEMODefaultAllocateFunc gpAllocFunc = NULL; static DEMODefaultFreeFunc gpFreeFunc = NULL; void DEMOInit() { OSReport("DEMO: Build date - %s %s\n", __DATE__, __TIME__); gDemoRunningFlag = TRUE; sMainCore = OSGetCoreId(); DEMOPadInit(); ProcUIInitEx(&DEMOSaveCallback, NULL); DEMOReleaseCallback = &DEMOEmptyReleaseCallback; } void DEMOSetMainCore(int core) { sMainCore = core; } void DEMOStopRunning() { gDemoRunningFlag = FALSE; } void DEMOShutdown() { DEMOStopRunning(); DEMOPadShutdown(); gpAllocFunc = NULL; gpFreeFunc = NULL; OSReport("\nEnd of demo\n"); } BOOL DEMOIsRunning() { // Only do extra on the proper core if (OSGetCoreId() != sMainCore) { ProcUISubProcessMessages(TRUE); return gDemoRunningFlag; } // See if test action needs to be taken DEMOTestCheck(); // See if any process switching or exiting is going on ProcUIStatus status; // Block if we're in the background status = ProcUIProcessMessages(TRUE); // Handle exiting or release if (status == PROCUI_STATUS_EXIT) DEMOStopRunning(); else if (status == PROCUI_STATUS_RELEASING) DEMOReleaseCallback(); if (!gDemoRunningFlag) { // This function can only be called when in the foreground // This must be called prior to freeing any shaders or other memory the GPU might be using DEMOGfxDrawDone(); ProcUIShutdown(); } return gDemoRunningFlag; } void DEMOSetDefaultAllocator(DEMODefaultAllocateFunc pfnAlloc, DEMODefaultFreeFunc pfnFree) { gpAllocFunc = pfnAlloc; gpFreeFunc = pfnFree; } void DEMOGetDefaultAllocator(DEMODefaultAllocateFunc *ppfnAlloc, DEMODefaultFreeFunc *ppfnFree) { if (ppfnAlloc) *ppfnAlloc = gpAllocFunc; if (ppfnFree) *ppfnFree = gpFreeFunc; } void* DEMOAlloc(u32 size) { if (!gpAllocFunc) { return MEMAllocFromDefaultHeapEx(size, PPC_IO_BUFFER_ALIGN); } return gpAllocFunc(size, PPC_IO_BUFFER_ALIGN); } void* DEMOAllocEx(u32 size, u32 align) { if (!gpAllocFunc) { return MEMAllocFromDefaultHeapEx(size, align); } return gpAllocFunc(size, align); } void DEMOFree(void* ptr) { if (!gpFreeFunc) { MEMFreeToDefaultHeap(ptr); } else { gpFreeFunc(ptr); } } // ---------------------------------------------------------------------------- // Print // ---------------------------------------------------------------------------- void DEMOPrintf(const char* msg, ...) { va_list args; va_start(args, msg); vprintf(msg, args); va_end(args); }