ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
sjis.c
Go to the documentation of this file.
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
9 */
10 
16 #include <string.h>
17 #include <sjis.h>
18 
19 struct charmap_t {
20  unsigned short sjis;
21  unsigned char ascii;
22 };
23 
24 #ifdef F__sjis_internals
25 struct charmap_t sjis_conversion[] = {
26  { 0x4081, ' ' },
27  { 0x6d81, '[' },
28  { 0x6e81, ']' },
29  { 0x7c81, '-' },
30  { 0x5b81, '°' },
31  { 0x4581, '¥' },
32  { 0x4481, '.' },
33  { 0x7B81, '+' },
34  { 0x9681, '*' },
35  { 0x5E81, '/' },
36  { 0x4981, '!' },
37  { 0x6881, '"' },
38  { 0x9481, '#' },
39  { 0x9081, '$' },
40  { 0x9381, '%' },
41  { 0x9581, '&' },
42  { 0x6681, '\'' },
43  { 0x6981, '(' },
44  { 0x6a81, ')' },
45  { 0x8181, '=' },
46  { 0x6281, '|' },
47  { 0x8f81, '\\' },
48  { 0x4881, '?' },
49  { 0x5181, '_' },
50  { 0x6f81, '{' },
51  { 0x7081, '}' },
52  { 0x9781, '@' },
53  { 0x4781, ';' },
54  { 0x4681, ':' },
55  { 0x8381, '<' },
56  { 0x8481, '>' },
57  { 0x4d81, '`' },
58  { 0, 0 }
59 };
60 
61 unsigned char isSpecialSJIS(short sjis)
62 {
63  struct charmap_t *s = &sjis_conversion[0];
64  do {
65  if (s->sjis == sjis) return s->ascii;
66  s++;
67  } while (s->sjis != 0);
68  return 0;
69 }
70 
71 short isSpecialASCII(unsigned char ascii)
72 {
73  struct charmap_t *s = &sjis_conversion[0];
74  do {
75  if (s->ascii == ascii) return s->sjis;
76  s++;
77  } while (s->ascii != 0);
78  return 0;
79 }
80 #else
81 extern struct charmap_t * sjis_conversion;
82 unsigned char isSpecialSJIS(short sjis);
83 short isSpecialASCII(unsigned char ascii);
84 #endif
85 
86 #ifdef F_strcpy_ascii
87 int strcpy_ascii(char* ascii_buff, const short* sjis_buff)
88 {
89  int i;
90  short ascii, sjis;
91 
92  int len = strlen((const char *)sjis_buff)/2;
93 
94  for (i=0;i<len;i++) {
95  sjis = sjis_buff[i];
96  if ((ascii = isSpecialSJIS(sjis)) != 0) {
97  } else {
98  ascii = ((sjis & 0xFF00) >> 8) - 0x1f;
99  if (ascii>96) ascii--;
100  }
101  ascii_buff[i] = ascii;
102  }
103  ascii_buff[i]=0;
104  return len;
105 }
106 #endif
107 
108 #ifdef F_strcpy_sjis
109 int strcpy_sjis(short* sjis_buff, const char* ascii_buff)
110 {
111  int i;
112  short ascii, sjis;
113 
114  int len = strlen(ascii_buff);
115 
116  for (i=0;i<len;i++) {
117  ascii = ascii_buff[i];
118  if ((sjis = isSpecialASCII(ascii)) != 0) {
119  } else {
120  if (ascii>96) ascii++;
121  sjis = ((ascii + 0x1f) << 8) | 0x82;
122  }
123  sjis_buff[i] = sjis;
124  }
125  sjis_buff[i]=0;
126  return len;
127 }
128 #endif
129 
s32 s
Definition: ps2ipc.c:30
struct charmap_t * sjis_conversion
short isSpecialASCII(unsigned char ascii)
unsigned char isSpecialSJIS(short sjis)
int strcpy_ascii(char *ascii_buff, const short *sjis_buff)
int strcpy_sjis(short *sjis_buff, const char *ascii_buff)
Definition: sjis.c:19
unsigned short sjis
Definition: sjis.c:20
unsigned char ascii
Definition: sjis.c:21