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