1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - MB - demos - multiboot-PowerSave
3   File:     main.c
4 
5   Copyright 2006-2008 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   $Date:: 2009-03-02#$
14   $Rev: 10122 $
15   $Author: kitase_hirotake $
16  *---------------------------------------------------------------------------*/
17 
18 
19 #ifdef SDK_TWL
20 #include	<twl.h>
21 #else
22 #include	<nitro.h>
23 #endif
24 
25 
26 #include "common.h"
27 #include "dispfunc.h"
28 
29 /*
30  * This is a sample parent for DS Download Play that explicitly changes the setting for the power-save mode.
31  *
32  * MB library samples use wireless features, so multiple development systems with the same communications environment (wired or wireless) are required.
33  *
34  * The mb_child_NITRO.srl and mb_child_TWL.srl sample programs in the $TwlSDK/bin/ARM9-TS/Rom/ directory provide the same features as a commercial system that is a child device for DS Download Play. Load these binaries on other systems as with any sample program and then run them together.
35  *
36  *
37  *
38  *
39  */
40 
41 
42 /*****************************************************************************/
43 /* Functions */
44 
45 /*---------------------------------------------------------------------------*
46   Name:         VBlankIntr
47 
48   Description:  V-Blank interrupt handler to update images.
49 
50   Arguments:    None.
51 
52   Returns:      None.
53  *---------------------------------------------------------------------------*/
VBlankIntr(void)54 static void VBlankIntr(void)
55 {
56     BgUpdate();
57     OS_SetIrqCheckFlag(OS_IE_V_BLANK);
58 }
59 
60 /*---------------------------------------------------------------------------*
61   Name:         NitroMain
62 
63   Description:  Application's main entry.
64 
65   Arguments:    None.
66 
67   Returns:      None.
68  *---------------------------------------------------------------------------*/
NitroMain(void)69 void NitroMain(void)
70 {
71     /* OS initialization */
72     OS_Init();
73     OS_InitTick();
74     OS_InitAlarm();
75     FX_Init();
76 
77     /* GX initialization */
78     GX_Init();
79     GX_DispOff();
80     GXS_DispOff();
81 
82     /* Memory allocation initialization */
83     {
84         OSHeapHandle hh;
85         static const u32 MAIN_HEAP_SIZE = 0x80000;
86         void   *heapStart;
87         void   *nstart = OS_InitAlloc(OS_ARENA_MAIN,
88                                       OS_GetMainArenaLo(), OS_GetMainArenaHi(), 16);
89         OS_SetMainArenaLo(nstart);
90         heapStart = OS_AllocFromMainArenaLo(MAIN_HEAP_SIZE, 32);
91         hh = OS_CreateHeap(OS_ARENA_MAIN, heapStart, (void *)((u32)heapStart + MAIN_HEAP_SIZE));
92         if (hh < 0)
93         {
94             OS_Panic("ARM9: Fail to create heap...\n");
95         }
96         (void)OS_SetCurrentHeap(OS_ARENA_MAIN, hh);
97     }
98 
99     (void)OS_EnableIrq();
100     (void)OS_EnableInterrupts();
101 
102     /* FS initialization */
103     FS_Init(FS_DMA_NOT_USE);
104     {
105         u32     need_size = FS_GetTableSize();
106         void   *p_table = OS_Alloc(need_size);
107         SDK_ASSERT(p_table != NULL);
108         (void)FS_LoadTable(p_table, need_size);
109     }
110 
111     /* Initialize drawing setting */
112     {
113         GX_SetBankForLCDC(GX_VRAM_LCDC_ALL);
114         MI_CpuClearFast((void *)HW_LCDC_VRAM, HW_LCDC_VRAM_SIZE);
115         (void)GX_DisableBankForLCDC();
116         MI_CpuFillFast((void *)HW_OAM, 192, HW_OAM_SIZE);
117         MI_CpuClearFast((void *)HW_PLTT, HW_PLTT_SIZE);
118         MI_CpuFillFast((void *)HW_DB_OAM, 192, HW_DB_OAM_SIZE);
119         MI_CpuClearFast((void *)HW_DB_PLTT, HW_DB_PLTT_SIZE);
120         BgInit();
121     }
122 
123     /* V-Blank interrupt configuration */
124     (void)OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr);
125     (void)OS_EnableIrqMask(OS_IE_V_BLANK);
126     (void)OS_EnableIrqMask(OS_IE_FIFO_RECV);
127 //    (void)OS_EnableIrq();
128 //    (void)OS_EnableInterrupts();
129     (void)GX_VBlankIntr(TRUE);
130 
131     /* Main loop */
132     for (;;)
133     {
134         MenuMode();
135         ParentMode();
136     }
137 
138 }
139