1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - nandApp - demos - sharedFont
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 <twl/na.h>
19 #include <DEMO.h>
20 
21 static void PrintBootType();
22 
23 static void InitDEMOSystem();
24 static void InitInteruptSystem();
25 static void InitAllocSystem();
26 static void InitFileSystem();
27 
28 /*---------------------------------------------------------------------------*
29   Name:         TwlMain
30 
31   Description:  Main function.
32 
33   Arguments:    None.
34 
35   Returns:      None.
36  *---------------------------------------------------------------------------*/
TwlMain(void)37 void TwlMain(void)
38 {
39     OS_Init();
40     InitInteruptSystem();
41     InitFileSystem();
42     InitAllocSystem();
43     InitDEMOSystem();
44     OS_Printf("*** start sharedFont demo\n");
45 
46     PrintBootType();
47 
48     // Load the system's internal font(s)
49     {
50         BOOL bSuccess;
51         int sizeTable;
52         int sizeFont;
53         void* pBufferTable;
54         void* pBufferFont;
55 
56         // Initialize the system internal font API
57         bSuccess = NA_InitSharedFont();
58         SDK_ASSERT( bSuccess );
59 
60         // Get the management information buffer size
61         sizeTable = NA_GetSharedFontTableSize();
62         SDK_ASSERT( sizeTable >= 0 );
63         OS_TPrintf("shared font table size = %d bytes\n", sizeTable);
64 
65         pBufferTable = OS_Alloc((u32)sizeTable);
66         SDK_POINTER_ASSERT(pBufferTable);
67 
68         // Load the management information
69         bSuccess = NA_LoadSharedFontTable(pBufferTable);
70         SDK_ASSERT( bSuccess );
71 
72         // Get the font size
73         sizeFont = NA_GetSharedFontSize(NA_SHARED_FONT_WW_M);
74         SDK_ASSERT( sizeFont >= 0 );
75         OS_TPrintf("shared font(M) size = %d bytes\n", sizeFont);
76 
77         pBufferFont = OS_Alloc((u32)sizeFont);
78         SDK_POINTER_ASSERT(pBufferFont);
79 
80         // Load the font
81         bSuccess = NA_LoadSharedFont(NA_SHARED_FONT_WW_M, pBufferFont);
82         SDK_ASSERT( bSuccess );
83 
84         OS_TPrintf("shared font loaded\n");
85 
86         /*
87         TWL-System is needed in order to use the loaded fonts...
88         {
89             NNSG2dFont font;
90 
91             NNS_G2dFontInitUTF16(&font, pBufferFont);
92             ...
93         }
94         */
95     }
96 
97     OS_Printf("*** End of demo\n");
98     DEMO_DrawFlip();
99     OS_WaitVBlankIntr();
100 
101     OS_Terminate();
102 }
103 
104 
105 /*---------------------------------------------------------------------------*
106   Name:         PrintBootType
107 
108   Description:  Prints the BootType.
109 
110   Arguments:    None.
111 
112   Returns:      None.
113  *---------------------------------------------------------------------------*/
PrintBootType()114 static void PrintBootType()
115 {
116     const OSBootType btype = OS_GetBootType();
117 
118     switch( btype )
119     {
120     case OS_BOOTTYPE_ROM:   OS_TPrintf("OS_GetBootType = OS_BOOTTYPE_ROM\n"); break;
121     case OS_BOOTTYPE_NAND:  OS_TPrintf("OS_GetBootType = OS_BOOTTYPE_NAND\n"); break;
122     default:
123         {
124             OS_Warning("unknown BootType(=%d)", btype);
125         }
126         break;
127     }
128 }
129 
130 /*---------------------------------------------------------------------------*
131   Name:         InitDEMOSystem
132 
133   Description:  Configures display settings for console screen output.
134 
135   Arguments:    None.
136 
137   Returns:      None.
138  *---------------------------------------------------------------------------*/
InitDEMOSystem()139 static void InitDEMOSystem()
140 {
141     // Initialize screen display
142     DEMOInitCommon();
143     DEMOInitVRAM();
144     DEMOInitDisplayBitmap();
145     DEMOHookConsole();
146     DEMOSetBitmapTextColor(GX_RGBA(31, 31, 0, 1));
147     DEMOSetBitmapGroundColor(DEMO_RGB_CLEAR);
148     DEMOStartDisplay();
149 }
150 
151 /*---------------------------------------------------------------------------*
152   Name:         InitInteruptSystem
153 
154   Description:  Initializes interrupts.
155 
156   Arguments:    None.
157 
158   Returns:      None.
159  *---------------------------------------------------------------------------*/
InitInteruptSystem()160 static void InitInteruptSystem()
161 {
162     // Enable master interrupt flag
163     (void)OS_EnableIrq();
164 
165     // Allow IRQ interrupts
166     (void)OS_EnableInterrupts();
167 }
168 
169 /*---------------------------------------------------------------------------*
170   Name:         InitAllocSystem
171 
172   Description:  Creates a heap and makes OS_Alloc usable.
173 
174   Arguments:    None.
175 
176   Returns:      None.
177  *---------------------------------------------------------------------------*/
InitAllocSystem()178 static void InitAllocSystem()
179 {
180     void* newArenaLo;
181     OSHeapHandle hHeap;
182 
183     // Initialize the main arena's allocation system
184     newArenaLo = OS_InitAlloc(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi(), 1);
185     OS_SetMainArenaLo(newArenaLo);
186 
187     // Create a heap in the main arena
188     hHeap = OS_CreateHeap(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi());
189     (void)OS_SetCurrentHeap(OS_ARENA_MAIN, hHeap);
190 }
191 
192 /*---------------------------------------------------------------------------*
193   Name:         InitFileSystem
194 
195   Description:  Initializes the file system and makes the ROM accessible.
196                 The InitInteruptSystem function must have been called before this function is.
197 
198 
199   Arguments:    None.
200 
201   Returns:      None.
202  *---------------------------------------------------------------------------*/
InitFileSystem()203 static void InitFileSystem()
204 {
205     // Initialize file system
206     FS_Init( FS_DMA_NOT_USE );
207 }
208