1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - demos - os - reset-1
3   File:     font.c
4 
5   Copyright 2003-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-09-18#$
14   $Rev: 8573 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 #ifdef  SDK_TWL
18 #include  <twl.h>
19 #else
20 #include  <nitro.h>
21 #endif
22 #include  "screen.h"
23 
24 u16     gScreen[32 * 32];
25 
26 // ** these code are refer to rtc sample. thanks.
27 /*---------------------------------------------------------------------------*
28   Name:         ClearScreen
29 
30   Description:  clear screen buffer
31 
32   Arguments:    None.
33 
34   Returns:      None.
35  *---------------------------------------------------------------------------*/
ClearScreen(void)36 void ClearScreen(void)
37 {
38     MI_CpuClearFast((void *)gScreen, sizeof(gScreen));
39 }
40 
41 /*---------------------------------------------------------------------------*
42   Name:         PrintString
43 
44   Description:  enter string into screen buffer
45                 string must be within 32 chars
46 
47   Arguments:    x       : x
48                 y       : y
49                 palette : color (0-15)
50                 text    : string. end mark is NULL
51 
52   Returns:      None.
53  *---------------------------------------------------------------------------*/
PrintString(s16 x,s16 y,u8 palette,char * text,...)54 void PrintString(s16 x, s16 y, u8 palette, char *text, ...)
55 {
56     va_list vlist;
57     char    temp[32 + 2], *tempPtr;
58     s32     i;
59     u16    *p, *pLimit;
60 
61     va_start(vlist, text);
62     (void)vsnprintf(temp, 33, text, vlist);
63     va_end(vlist);
64 
65     *(u16 *)(&temp[32]) = 0;
66     p = &gScreen[((y * 32) + x) % (32 * 32)];
67     pLimit = &gScreen[32 * 32];
68     tempPtr = &temp[0];
69 
70     for (i = 0; *tempPtr; i++, tempPtr++)
71     {
72         *p = (u16)((palette << 12) | *tempPtr);
73         if (++p >= pLimit)
74         {
75             p = &gScreen[0];
76         }
77     }
78 }
79 
80 /*---------------------------------------------------------------------------*
81   Name:         ColorString
82 
83   Description:  change string color which is put in screen buffer
84 
85   Arguments:    x       : x
86                 y       : y
87                 length  : number of characters to change color
88                 palette : color (0-15)
89 
90   Returns:      None.
91  *---------------------------------------------------------------------------*/
ColorString(s16 x,s16 y,s16 length,u8 palette)92 void ColorString(s16 x, s16 y, s16 length, u8 palette)
93 {
94     s32     i;
95     u16    *p, *pLimit;
96 
97     if (length < 0)
98         return;
99 
100     p = &gScreen[((y * 32) + x) % (32 * 32)];
101     pLimit = &gScreen[32 * 32];
102 
103     for (i = 0; i < length; i++)
104     {
105         u16     temp = *p;
106         temp &= 0x0fff;
107         temp |= (palette << 12);
108         *p = temp;
109 
110         if (++p >= pLimit)
111         {
112             p = &gScreen[0];
113         }
114     }
115 }
116