1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - WVR - demos - switchover
3   File:     main.c
4 
5   Copyright 2005-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:: 2008-09-17#$
14   $Rev: 8556 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 
18 #include    <nitro.h>
19 #include "common.h"
20 
21 
22 /*---------------------------------------------------------------------------*
23     Function Definitions
24  *---------------------------------------------------------------------------*/
25 
26 /*---------------------------------------------------------------------------*
27   Name:         InitializeAllocateSystem
28 
29   Description:  Initializes the memory allocation system within the main memory arena.
30 
31   Arguments:    None.
32 
33   Returns:      None.
34  *---------------------------------------------------------------------------*/
InitializeAllocateSystem(void)35 static void InitializeAllocateSystem(void)
36 {
37     void   *tempLo;
38     OSHeapHandle hh;
39 
40     // Based on the premise that OS_Init has been already called
41     tempLo = OS_InitAlloc(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi(), 1);
42     OS_SetArenaLo(OS_ARENA_MAIN, tempLo);
43     hh = OS_CreateHeap(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi());
44     if (hh < 0)
45     {
46         OS_Panic("ARM9: Fail to create heap...\n");
47     }
48     hh = OS_SetCurrentHeap(OS_ARENA_MAIN, hh);
49 }
50 
51 /*---------------------------------------------------------------------------*
52   Name:         NitroMain
53 
54   Description:  Initialization and main loop.
55 
56   Arguments:    None.
57 
58   Returns:      None.
59  *---------------------------------------------------------------------------*/
NitroMain(void)60 void NitroMain(void)
61 {
62     /* Library initialization */
63     OS_Init();
64     FX_Init();
65     GX_Init();
66 
67     /* Memory allocation */
68     InitializeAllocateSystem();
69 
70     {
71         BOOL    bSwitch = FALSE;
72         for (;; bSwitch = !bSwitch)
73         {
74             if (bSwitch)
75             {
76                 GraphicMain();
77             }
78             else
79             {
80                 WirelessMain();
81             }
82             (void)OS_DisableIrq();
83             (void)OS_DisableInterrupts();
84 
85             (void)GX_DisableBankForLCDC();
86             (void)GX_DisableBankForTex();
87             (void)GX_DisableBankForTexPltt();
88             (void)GX_DisableBankForBG();
89             (void)GX_DisableBankForOBJ();
90             (void)GX_DisableBankForSubBG();
91             (void)GX_DisableBankForSubOBJ();
92 
93         }
94     }
95 }
96