PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
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
19struct charmap_t {
20 unsigned short sjis;
21 unsigned char ascii;
22};
23
24#if defined(F_isSpecialSJIS) || defined(F_isSpecialASCII)
25static 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#endif
61
62#ifdef F_isSpecialSJIS
63unsigned char isSpecialSJIS(short sjis)
64{
65 struct charmap_t *s = &sjis_conversion[0];
66 do {
67 if (s->sjis == sjis) return s->ascii;
68 s++;
69 } while (s->sjis != 0);
70 return 0;
71}
72#else
73unsigned char isSpecialSJIS(short sjis);
74#endif
75
76#ifdef F_isSpecialASCII
77short isSpecialASCII(unsigned char ascii)
78{
79 struct charmap_t *s = &sjis_conversion[0];
80 do {
81 if (s->ascii == ascii) return s->sjis;
82 s++;
83 } while (s->ascii != 0);
84 return 0;
85}
86#else
87short isSpecialASCII(unsigned char ascii);
88#endif
89
90#ifdef F_strcpy_ascii
91int strcpy_ascii(char* ascii_buff, const short* sjis_buff)
92{
93 int i;
94
95 int len = strlen((const char *)sjis_buff)/2;
96
97 for (i=0;i<len;i++) {
98 short ascii, sjis;
99 sjis = sjis_buff[i];
100 if ((ascii = isSpecialSJIS(sjis)) != 0) {
101 } else {
102 ascii = ((sjis & 0xFF00) >> 8) - 0x1f;
103 if (ascii>96) ascii--;
104 }
105 ascii_buff[i] = ascii;
106 }
107 ascii_buff[i]=0;
108 return len;
109}
110#endif
111
112#ifdef F_strcpy_sjis
113int strcpy_sjis(short* sjis_buff, const char* ascii_buff)
114{
115 int i;
116
117 int len = strlen(ascii_buff);
118
119 for (i=0;i<len;i++) {
120 short ascii, sjis;
121 ascii = ascii_buff[i];
122 if ((sjis = isSpecialASCII(ascii)) != 0) {
123 } else {
124 if (ascii>96) ascii++;
125 sjis = ((ascii + 0x1f) << 8) | 0x82;
126 }
127 sjis_buff[i] = sjis;
128 }
129 sjis_buff[i]=0;
130 return len;
131}
132#endif
133
int strcpy_ascii(char *ascii_buff, const short *sjis_buff)
int strcpy_sjis(short *sjis_buff, const char *ascii_buff)