1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - nandApp - demos - simple
3 File: main.c
4
5 Copyright 2007-2009 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-08-06#$
14 $Rev: 10986 $
15 $Author: ooshimay $
16 *---------------------------------------------------------------------------*/
17 #include <twl.h>
18 #include <DEMO.h>
19
20 static void PrintBootType();
21
22 static void InitDEMOSystem();
23 static void InitInteruptSystem();
24 static void InitAllocSystem();
25 static void InitFileSystem();
26
27 /*---------------------------------------------------------------------------*
28 Name: TwlMain
29
30 Description: Main function.
31
32 Arguments: None.
33
34 Returns: None.
35 *---------------------------------------------------------------------------*/
TwlMain(void)36 void TwlMain(void)
37 {
38 OS_Init();
39 InitInteruptSystem();
40 InitFileSystem();
41 InitAllocSystem();
42 InitDEMOSystem();
43 OS_Printf("*** start nandApp demo\n");
44
45 PrintBootType();
46
47 // Load file from ROM and display it
48 // The ROM file system can also be used from NAND applications.
49 {
50 BOOL bSuccess;
51 FSFile f;
52 u32 fileSize;
53 s32 readSize;
54 void* pBuffer;
55
56 FS_InitFile(&f);
57
58 bSuccess = FS_OpenFileEx(&f, "build_time.txt", FS_FILEMODE_R);
59 SDK_ASSERT( bSuccess );
60
61 fileSize = FS_GetFileLength(&f);
62 pBuffer = OS_Alloc(fileSize + 1);
63 SDK_POINTER_ASSERT(pBuffer);
64
65 readSize = FS_ReadFile(&f, pBuffer, (s32)fileSize);
66 SDK_ASSERT( readSize == fileSize );
67
68 bSuccess = FS_CloseFile(&f);
69 SDK_ASSERT( bSuccess );
70
71 ((char*)pBuffer)[fileSize] = '\0';
72 OS_Printf("%s\n", pBuffer);
73 OS_Free(pBuffer);
74 }
75
76 OS_Printf("*** End of demo\n");
77 DEMO_DrawFlip();
78 OS_WaitVBlankIntr();
79
80 OS_Terminate();
81 }
82
83
84 /*---------------------------------------------------------------------------*
85 Name: PrintBootType
86
87 Description: Prints the BootType.
88
89 Arguments: None.
90
91 Returns: None.
92 *---------------------------------------------------------------------------*/
PrintBootType()93 static void PrintBootType()
94 {
95 const OSBootType btype = OS_GetBootType();
96
97 switch( btype )
98 {
99 case OS_BOOTTYPE_ROM: OS_TPrintf("OS_GetBootType = OS_BOOTTYPE_ROM\n"); break;
100 case OS_BOOTTYPE_NAND: OS_TPrintf("OS_GetBootType = OS_BOOTTYPE_NAND\n"); break;
101 default:
102 {
103 OS_Warning("unknown BootType(=%d)", btype);
104 }
105 break;
106 }
107 }
108
109 /*---------------------------------------------------------------------------*
110 Name: InitDEMOSystem
111
112 Description: Configures display settings for console screen output.
113
114 Arguments: None.
115
116 Returns: None.
117 *---------------------------------------------------------------------------*/
InitDEMOSystem()118 static void InitDEMOSystem()
119 {
120 // Initialize screen display
121 DEMOInitCommon();
122 DEMOInitVRAM();
123 DEMOInitDisplayBitmap();
124 DEMOHookConsole();
125 DEMOSetBitmapTextColor(GX_RGBA(31, 31, 0, 1));
126 DEMOSetBitmapGroundColor(DEMO_RGB_CLEAR);
127 DEMOStartDisplay();
128 }
129
130 /*---------------------------------------------------------------------------*
131 Name: InitInteruptSystem
132
133 Description: Initializes interrupts.
134
135 Arguments: None.
136
137 Returns: None.
138 *---------------------------------------------------------------------------*/
InitInteruptSystem()139 static void InitInteruptSystem()
140 {
141 // ESnable master interrupt flag
142 (void)OS_EnableIrq();
143
144 // Allow IRQ interrupts
145 (void)OS_EnableInterrupts();
146 }
147
148 /*---------------------------------------------------------------------------*
149 Name: InitAllocSystem
150
151 Description: Creates a heap and makes OS_Alloc usable.
152
153 Arguments: None.
154
155 Returns: None.
156 *---------------------------------------------------------------------------*/
InitAllocSystem()157 static void InitAllocSystem()
158 {
159 void* newArenaLo;
160 OSHeapHandle hHeap;
161
162 // Initialize the main arena's allocation system
163 newArenaLo = OS_InitAlloc(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi(), 1);
164 OS_SetMainArenaLo(newArenaLo);
165
166 // Create a heap in the main arena
167 hHeap = OS_CreateHeap(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi());
168 (void)OS_SetCurrentHeap(OS_ARENA_MAIN, hHeap);
169 }
170
171 /*---------------------------------------------------------------------------*
172 Name: InitFileSystem
173
174 Description: Initializes the file system and makes the ROM accessible.
175 The InitInteruptSystem function must have been called before this function is.
176
177
178 Arguments: None.
179
180 Returns: None.
181 *---------------------------------------------------------------------------*/
InitFileSystem()182 static void InitFileSystem()
183 {
184 // Initialize file system
185 FS_Init( FS_DMA_NOT_USE );
186 }
187