1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - MB - demos - multiboot-Model
3 File: common.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-02-19#$
14 $Rev: 10047 $
15 $Author: nishimoto_takashi $
16 *---------------------------------------------------------------------------*/
17
18 #include <nitro.h>
19
20 #include "common.h"
21 #include "disp.h"
22
23
24 static void VBlankIntr(void);
25
26 /*
27 * Common features used by this entire demo
28 */
29 static u16 padPress;
30 static u16 padTrig;
31
32 /*---------------------------------------------------------------------------*
33 Name: ReadKey
34
35 Description: Processing for reading keys.
36
37 Arguments: None.
38
39 Returns: None.
40 *---------------------------------------------------------------------------*/
ReadKey(void)41 void ReadKey(void)
42 {
43 u16 currData = PAD_Read();
44
45 padTrig = (u16)(~padPress & currData);
46 padPress = currData;
47 }
48
49 /*---------------------------------------------------------------------------*
50 Name: GetPressKey
51
52 Description: Gets pressed key.
53
54 Arguments: None.
55
56 Returns: Bitmap of the pressed key.
57 *---------------------------------------------------------------------------*/
GetPressKey(void)58 u16 GetPressKey(void)
59 {
60 return padPress;
61 }
62
63
64 /*---------------------------------------------------------------------------*
65 Name: GetTrigKey
66
67 Description: Gets key trigger.
68
69 Arguments: None.
70
71 Returns: A bitmap of key triggers.
72 *---------------------------------------------------------------------------*/
GetTrigKey(void)73 u16 GetTrigKey(void)
74 {
75 return padTrig;
76 }
77
78
79 /*---------------------------------------------------------------------------*
80 Name: CommonInit
81
82 Description: Common initialization functions.
83
84 Arguments: None.
85
86 Returns: None.
87 *---------------------------------------------------------------------------*/
CommonInit(void)88 void CommonInit(void)
89 {
90 /* OS initialization */
91 OS_Init();
92 OS_InitTick();
93 OS_InitAlarm();
94 FX_Init();
95
96 /* GX initialization */
97 GX_Init();
98 GX_DispOff();
99 GXS_DispOff();
100
101 /* V-Blank interrupt configuration */
102 (void)OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr);
103 (void)OS_EnableIrqMask(OS_IE_V_BLANK);
104 (void)OS_EnableIrqMask(OS_IE_FIFO_RECV);
105 (void)GX_VBlankIntr(TRUE);
106
107 // Read the key once as empty
108 ReadKey();
109 }
110
111
112 /*---------------------------------------------------------------------------*
113 Name: InitAllocateSystem
114
115 Description: Initializes the memory allocation system within the main memory arena.
116
117 Arguments: None.
118
119 Returns: None.
120 *---------------------------------------------------------------------------*/
InitAllocateSystem(void)121 void InitAllocateSystem(void)
122 {
123 void *tempLo;
124 OSHeapHandle hh;
125
126 // Based on the premise that OS_Init has been already called
127 tempLo = OS_InitAlloc(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi(), 1);
128 OS_SetArenaLo(OS_ARENA_MAIN, tempLo);
129 hh = OS_CreateHeap(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi());
130 if (hh < 0)
131 {
132 OS_Panic("ARM9: Fail to create heap...\n");
133 }
134 hh = OS_SetCurrentHeap(OS_ARENA_MAIN, hh);
135 }
136
137
138
139
140 /*---------------------------------------------------------------------------*
141 Name: VBlankIntr
142
143 Description: Gets key trigger.
144
145 Arguments: None.
146
147 Returns: None.
148 *---------------------------------------------------------------------------*/
VBlankIntr(void)149 static void VBlankIntr(void)
150 {
151 DispVBlankFunc();
152
153 //---- Interrupt check flag
154 OS_SetIrqCheckFlag(OS_IE_V_BLANK);
155 }
156