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