1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - WXC - demos - wxc-pm
3   File:     print.c
4 
5   Copyright 2005-2009 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:: 2007-11-15#$
14   $Rev: 2414 $
15   $Author: hatamoto_minoru $
16  *---------------------------------------------------------------------------*/
17 
18 #include    "print.h"
19 
20 extern u16 gScreen[32 * 32];           // Virtual screen
21 
22 /*---------------------------------------------------------------------------*
23   Name:         ClearStringY
24 
25   Description:  Clears the virtual screen (single line).
26 
27   Arguments:    y: Line to be deleted
28 
29   Returns:      None.
30  *---------------------------------------------------------------------------*/
ClearStringY(s16 y)31 void ClearStringY(s16 y)
32 {
33     MI_CpuClearFast((void *)(&gScreen[(y * 32)]), sizeof(u16)*32);
34 }
35 
36 
37 /*---------------------------------------------------------------------------*
38   Name:         ClearString
39 
40   Description:  Clears the virtual screen.
41 
42   Arguments:    None.
43 
44   Returns:      None.
45  *---------------------------------------------------------------------------*/
ClearString(void)46 void ClearString(void)
47 {
48     MI_CpuClearFast((void *)gScreen, sizeof(gScreen));
49 }
50 
51 
52 /*---------------------------------------------------------------------------*
53   Name:         PrintString
54 
55   Description:  Positions the text string on the virtual screen. The string can be up to 32 chars.
56 
57   Arguments:    x: X-coordinate where character string starts (x 8 dots)
58                 y: Y-coordinate where character string starts (x 8 dots)
59                 palette: Specify text color by palette number
60                 text: Text string to position. Null-terminated.
61                 ...: Virtual argument
62 
63   Returns:      None.
64  *---------------------------------------------------------------------------*/
PrintString(s16 x,s16 y,u8 palette,char * text,...)65 void PrintString(s16 x, s16 y, u8 palette, char *text, ...)
66 {
67     va_list vlist;
68     char temp[32 + 2];
69     s32 i;
70 
71     va_start(vlist, text);
72     (void)OS_VSNPrintf(temp, 33, text, vlist);
73     va_end(vlist);
74 
75     *(u16 *)(&temp[32]) = 0x0000;
76     for (i = 0;; i++)
77     {
78         if (temp[i] == 0x00)
79         {
80             break;
81         }
82         gScreen[((y * 32) + x + i) % (32 * 32)] = (u16)((palette << 12) | temp[i]);
83     }
84 }
85