1 /*---------------------------------------------------------------------------*
2   Project:  Revolution SDK DS-download test
3   File:     mpfssimple.c
4 
5   Copyright 2006,2007 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   $Log: mpfssimple.c,v $
14   Revision 1.2  2007/02/09 04:30:11  yosizaki
15   fixed about includes.
16 
17   Revision 1.1  2007/01/16 08:33:30  yosizaki
18   initial upload.
19 
20   $NoKeywords: $
21  *---------------------------------------------------------------------------*/
22 
23 
24 #include <revolution.h>
25 #include <revolution/mpdl.h>
26 #include <revolution/mpfs.h>
27 #include <revolution/mem.h>
28 
29 #include "rexdemo/demokpad.h"
30 #include "rexdemo/graphic.h"
31 
32 
33 /*===========================================================================*/
34 /* declarations */
35 
36 void    ExecuteDownload(void* (*alloc)(u32), void (*free)(void*), const void *program);
37 void    ExecuteWireless(void* (*alloc)(u32), void (*free)(void*), MEMHeapHandle heap, const void *program);
38 
39 
40 /*===========================================================================*/
41 /* constants */
42 
43 #define     USERHEAP_SIZE ( 1024 * 1024 )
44 
45 
46 /*===========================================================================*/
47 /* variable */
48 
49 /* NintendoDS program image on memory */
50 static const u32 program_buffer_max = (u32)(3 * 1024 * 1024);
51 static u8 program_buffer[program_buffer_max] ATTRIBUTE_ALIGN(32);
52 static const char *program_path = "ds_program.srl";
53 static MEMHeapHandle    userHeap;
54 
55 
56 /*===========================================================================*/
57 /* functions */
58 
MyAlloc(u32 size)59 static void* MyAlloc(u32 size)
60 {
61     return MEMAllocFromExpHeapEx(userHeap, size, 32);
62 }
63 
MyFree(void * ptr)64 static void MyFree(void* ptr)
65 {
66     MEMFreeToExpHeap(userHeap, ptr);
67 }
68 
69 
main(void)70 void main(void)
71 {
72     /* initialize OS and memory heap */
73     DVDInit();
74     OSReport("startup mpdlsimple demo\n");
75     REXDEMOKPadInit();
76     REXDEMOInitScreen(FALSE);
77     REXDEMOSetGroundColor(REXDEMO_COLOR_BLACK);
78     REXDEMOSetFontSize(10, 20);
79     REXDEMOBeginRender();
80     REXDEMOWaitRetrace();
81     {
82         void*   heapAddress;
83         heapAddress = OSGetMEM2ArenaLo();
84         OSSetMEM2ArenaLo( (void*)OSRoundUp32B((u32)heapAddress + USERHEAP_SIZE));
85         userHeap = MEMCreateExpHeapEx(heapAddress, USERHEAP_SIZE, MEM_HEAP_OPT_THREAD_SAFE);
86         if(userHeap == NULL)
87         {
88             OSHalt( "Could not create heap.\n" );
89         }
90     }
91 
92     /* load NintendoDS program from DVD */
93     {
94         DVDFileInfo file[1];
95         if (!DVDOpen(program_path, file))
96         {
97             OSHalt("failed to read NintendoDS program file from DVD.\n");
98         }
99         else
100         {
101             const u32 file_len = ((DVDGetLength(file) + 31) & ~31);
102             if (file_len > program_buffer_max)
103             {
104                 OSHalt("specified program file is too large.\n");
105             }
106             else if (DVDRead(file, program_buffer, (int)file_len, 0) <= 0)
107             {
108                 OSHalt("failed to read NintendoDS program file from DVD.\n");
109             }
110             (void)DVDClose(file);
111         }
112     }
113 
114     /* demo sequence : do MPDL & MPFS repeadly */
115     for (; ;)
116     {
117         ExecuteDownload(MyAlloc, MyFree, program_buffer);
118         ExecuteWireless(MyAlloc, MyFree, userHeap, program_buffer);
119     }
120 
121 }
122 
123 
124 /*===========================================================================*/
125