/*---------------------------------------------------------------------------* Project: Revolution SDK DS-download test File: mpfssimple.c Copyright 2006,2007 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. $Log: mpfssimple.c,v $ Revision 1.2 2007/02/09 04:30:11 yosizaki fixed about includes. Revision 1.1 2007/01/16 08:33:30 yosizaki initial upload. $NoKeywords: $ *---------------------------------------------------------------------------*/ #include #include #include #include #include "rexdemo/demokpad.h" #include "rexdemo/graphic.h" /*===========================================================================*/ /* declarations */ void ExecuteDownload(void* (*alloc)(u32), void (*free)(void*), const void *program); void ExecuteWireless(void* (*alloc)(u32), void (*free)(void*), MEMHeapHandle heap, const void *program); /*===========================================================================*/ /* constants */ #define USERHEAP_SIZE ( 1024 * 1024 ) /*===========================================================================*/ /* variable */ /* NintendoDS program image on memory */ static const u32 program_buffer_max = (u32)(3 * 1024 * 1024); static u8 program_buffer[program_buffer_max] ATTRIBUTE_ALIGN(32); static const char *program_path = "ds_program.srl"; static MEMHeapHandle userHeap; /*===========================================================================*/ /* functions */ static void* MyAlloc(u32 size) { return MEMAllocFromExpHeapEx(userHeap, size, 32); } static void MyFree(void* ptr) { MEMFreeToExpHeap(userHeap, ptr); } void main(void) { /* initialize OS and memory heap */ DVDInit(); OSReport("startup mpdlsimple demo\n"); REXDEMOKPadInit(); REXDEMOInitScreen(FALSE); REXDEMOSetGroundColor(REXDEMO_COLOR_BLACK); REXDEMOSetFontSize(10, 20); REXDEMOBeginRender(); REXDEMOWaitRetrace(); { void* heapAddress; heapAddress = OSGetMEM2ArenaLo(); OSSetMEM2ArenaLo( (void*)OSRoundUp32B((u32)heapAddress + USERHEAP_SIZE)); userHeap = MEMCreateExpHeapEx(heapAddress, USERHEAP_SIZE, MEM_HEAP_OPT_THREAD_SAFE); if(userHeap == NULL) { OSHalt( "Could not create heap.\n" ); } } /* load NintendoDS program from DVD */ { DVDFileInfo file[1]; if (!DVDOpen(program_path, file)) { OSHalt("failed to read NintendoDS program file from DVD.\n"); } else { const u32 file_len = ((DVDGetLength(file) + 31) & ~31); if (file_len > program_buffer_max) { OSHalt("specified program file is too large.\n"); } else if (DVDRead(file, program_buffer, (int)file_len, 0) <= 0) { OSHalt("failed to read NintendoDS program file from DVD.\n"); } (void)DVDClose(file); } } /* demo sequence : do MPDL & MPFS repeadly */ for (; ;) { ExecuteDownload(MyAlloc, MyFree, program_buffer); ExecuteWireless(MyAlloc, MyFree, userHeap, program_buffer); } } /*===========================================================================*/