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