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