1  /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - tcl - demos.TWL - tcl-1
3   File:     screen.c
4 
5   Copyright 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-10-07#$
14   $Rev: 8888 $
15   $Author: onozawa_yuki $
16  *---------------------------------------------------------------------------*/
17 #include <twl.h>
18 #include "screen.h"
19 #include "font.h"
20 
21 /*---------------------------------------------------------------------------*
22     Constant Definitions
23  *---------------------------------------------------------------------------*/
24 #define TEXT_SCREEN_SIZE    2048
25 
26 /*---------------------------------------------------------------------------*
27     Internal Variable Definitions
28  *---------------------------------------------------------------------------*/
29 
30 // Virtual screen [number of backgrounds][number of characters]
31 static u16  gScreen[ 1 ][ TEXT_SCREEN_SIZE / sizeof(u16) ] ATTRIBUTE_ALIGN(32);
32 
33 /*---------------------------------------------------------------------------*
34   Name:         InitScreen
35 
36   Description:  Initializes display settings for text display system.
37 
38   Arguments:    None.
39 
40   Returns:      None.
41  *---------------------------------------------------------------------------*/
InitScreen(void)42 void InitScreen(void)
43 {
44     // Bottom screen settings
45     GX_SetBankForSubBG(GX_VRAM_SUB_BG_32_H);
46     G2S_SetBG0Control(GX_BG_SCRSIZE_TEXT_256x256, GX_BG_COLORMODE_16, GX_BG_SCRBASE_0x0000, GX_BG_CHARBASE_0x04000,
47                       GX_BG_EXTPLTT_01);
48     G2S_SetBG0Priority(0);
49     GXS_SetGraphicsMode(GX_BGMODE_0);
50     GXS_SetVisiblePlane(GX_PLANEMASK_BG0);
51     GXS_LoadBG0Char(d_CharData, 0, sizeof(d_CharData));
52     GXS_LoadBGPltt(d_PaletteData, 0, sizeof(d_PaletteData));
53     ((u16*)HW_DB_PLTT)[0] = 0x0000; // Black
54     MI_CpuFillFast(gScreen[0], 0, TEXT_SCREEN_SIZE);
55     DC_StoreRange(gScreen[0], TEXT_SCREEN_SIZE);
56     GXS_LoadBG0Scr(gScreen[0], 0, TEXT_SCREEN_SIZE);
57 }
58 
59 /*---------------------------------------------------------------------------*
60   Name:         ClearScreen
61 
62   Description:  Clears text display from the screen.
63 
64   Arguments:    None.
65 
66   Returns:      None.
67  *---------------------------------------------------------------------------*/
ClearScreen(void)68 void ClearScreen(void)
69 {
70     MI_CpuClearFast(gScreen[0], TEXT_SCREEN_SIZE);
71 }
72 
73 /*---------------------------------------------------------------------------*
74   Name:         PrintSubScreen
75 
76   Description:  Outputs text to the sub-screen.
77 
78   Arguments:    text: String to be output
79                 ...: Virtual argument
80 
81   Returns:      None.
82  *---------------------------------------------------------------------------*/
PutScreen(s32 x,s32 y,u8 palette,char * text,...)83 void PutScreen(s32 x, s32 y, u8 palette, char* text, ...)
84 {
85     va_list vlist;
86     char    temp[33];
87     s32     i;
88 
89     MI_CpuClear(temp, sizeof(temp));
90     va_start(vlist, text);
91     (void)vsnprintf(temp, 33, text, vlist);
92     va_end(vlist);
93 
94     for (i = 0; i < 32; i++)
95     {
96         if (temp[i] == 0x00)
97         {
98             break;
99         }
100 
101         gScreen[0][((y * 32) + x + i) % (32 * 32)] = (u16) (palette << 12 | temp[i]);
102     }
103 }
104 
105 /*---------------------------------------------------------------------------*
106   Name:         UpdateScreen
107 
108   Description:  Applies the virtual screen content to VRAM.
109                 Assumed to be called during the V-Blank period.
110 
111   Arguments:    None.
112 
113   Returns:      None.
114  *---------------------------------------------------------------------------*/
UpdateScreen(void)115 void UpdateScreen(void)
116 {
117     // Applies the virtual screen content to V-RAM
118     DC_StoreRange(gScreen[0], TEXT_SCREEN_SIZE);
119     GXS_LoadBG0Scr(gScreen[0], 0, TEXT_SCREEN_SIZE);
120 }
121 
122 /*---------------------------------------------------------------------------*
123   End of file
124  *---------------------------------------------------------------------------*/
125