1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - STD - demos - unicode-1
3   File:     main.c
4 
5   Copyright 2007-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 
18 #include <nitro.h>
19 
20 /*---------------------------------------------------------------------------*
21   Name:         ConvertUnicodeCallback
22 
23   Description:  The callback configured in the STD_ConvertStringSjisToUnicode function.
24 
25   Arguments:    dst: The pointer that stores the converted Unicode characters
26                 dstlen: Number of characters in dst actually converted
27                 src: The pointer that indicates the Shift-JIS characters that should be converted
28                 srclen: Byte size of src that should continue being read by conversion
29 
30   Returns:      The number of characters converted.
31  *---------------------------------------------------------------------------*/
ConvertUnicodeCallback(u16 * dst,int * dstlen,const char * src,int * srclen)32 static STDResult ConvertUnicodeCallback(u16 *dst, int *dstlen, const char *src, int *srclen)
33 {
34 #pragma unused(src)
35     *srclen = 1;
36     *dstlen = 1;
37     MI_StoreLE16(&dst[0], 0x3044);
38     return STD_RESULT_SUCCESS;
39 }
40 
41 /*---------------------------------------------------------------------------*
42   Name:         ConvertSjisCallback
43 
44   Description:  The callback configured in the STD_ConvertStringSjisToUnicode function.
45 
46   Arguments:    dst: The pointer that stores the converted Shift-JIS characters
47                 dstlen: Number of characters in dst actually converted
48                 src: The pointer that indicates the Unicode characters that should be converted
49                 srclen: Number of characters in src that should continue being read by conversion
50 
51   Returns:      The number of bytes converted.
52  *---------------------------------------------------------------------------*/
ConvertSjisCallback(char * dst,int * dstlen,const u16 * src,int * srclen)53 static STDResult ConvertSjisCallback(char *dst, int *dstlen, const u16 *src, int *srclen)
54 {
55 #pragma unused(src)
56     *srclen = 1;
57     *dstlen = 2;
58     dst[0] = (char)0x82;
59     dst[1] = (char)0xA2;
60     return STD_RESULT_SUCCESS;
61 }
62 
63 /*---------------------------------------------------------------------------*
64   Name:         NitroMain
65 
66   Description:  String conversion test.
67 
68   Arguments:    None.
69 
70   Returns:      None.
71  *---------------------------------------------------------------------------*/
NitroMain(void)72 void NitroMain(void)
73 {
74     OS_Init();
75     OS_InitTick();
76     OS_InitThread();
77 
78     (void)OS_EnableIrqMask(OS_IE_V_BLANK);
79     (void)OS_EnableIrq();
80 
81     OS_TPrintf("\n------STD_ConvertStringSjisToUnicode---------\n\n");
82     {
83         static const char mbs[] =
84             "���������ܦ݂�����aiueo��_�`�_���P�P�`�A�����@�����K��/\\���A�B���@";
85         u16     wcs[256];
86         int     wcs_length;
87         int     i;
88         STDResult result;
89 
90         OS_TPrintf("ShiftJIS = ");
91         for (i = 0; mbs[i] != '\0'; i++)
92         {
93             OS_TPrintf("%x ", (u8)mbs[i]);
94         }
95         OS_TPrintf("\n\n");
96 
97         wcs_length = sizeof(wcs) / sizeof(u16);
98         result =
99             STD_ConvertStringSjisToUnicode(wcs, &wcs_length, mbs, NULL, ConvertUnicodeCallback);
100         OS_TPrintf("Unicode = ");
101         for (i = 0; i < wcs_length; i++)
102         {
103             OS_TPrintf("%x ", wcs[i]);
104         }
105         OS_TPrintf("\n");
106     }
107 
108     OS_TPrintf("\n------STD_ConvertStringUnicodeToSjis---------\n\n");
109     {
110         static const u16 wcs[] =
111             L"���������ܦ݂�����aiueo��_�`�_���P�P�`�A�����@�����K��/\\���A�B���@";
112 
113         char    mbs[256];
114         int     mbs_length;
115         int     i;
116         STDResult result;
117 
118         OS_TPrintf("Unicode = ");
119         for (i = 0; wcs[i] != L'\0'; i++)
120         {
121             OS_TPrintf("%x ", wcs[i]);
122         }
123         OS_TPrintf("\n\n");
124 
125         mbs_length = sizeof(mbs) / sizeof(*mbs);
126         result = STD_ConvertStringUnicodeToSjis(mbs, &mbs_length, wcs, NULL, ConvertSjisCallback);
127 
128         OS_TPrintf("ShiftJIS = ");
129         for (i = 0; i < mbs_length; i++)
130         {
131             OS_TPrintf("%x ", (u8)mbs[i]);
132         }
133         OS_TPrintf("\n");
134     }
135 
136     OS_TPrintf("\n------STD_ConverCharSjisToUnicode-----\n\n");
137     {
138         char    mb[] = "��";
139         u16     wc;
140         int     wc_length;
141 
142         OS_TPrintf("ShiftJIS �� = %x, %x\n", (u8)mb[0], (u8)mb[1]);
143 
144         wc_length = STD_ConvertCharSjisToUnicode(&wc, mb);
145 
146         OS_TPrintf("Unicode �� = %x\n", wc);
147     }
148 
149     OS_TPrintf("\n------STD_ConverCharUnicodeToSjis-----\n\n");
150     {
151         u16     wc = L'��';
152         char    mb[2];
153         int     mb_length;
154 
155         OS_TPrintf("Unicode �� = %x\n", wc);
156 
157         mb_length = STD_ConvertCharUnicodeToSjis(mb, wc);
158 
159         OS_TPrintf("ShiftJIS �� = %x, %x\n", (u8)mb[0], (u8)mb[1]);
160 
161     }
162 
163     OS_TPrintf("\n" "++++++++++++++++++++++++++++++++++++++++\n" "Test Finish\n");
164 
165     OS_Terminate();
166 
167 }
168