sdk-core v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
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
15
16#include <string.h>
17#include <sjis.h>
18
19struct charmap_t {
20 unsigned short sjis;
21 unsigned char ascii;
22};
23
24static const struct charmap_t sjis_conversion[] = {
25 { 0x4081, ' ' },
26 { 0x6d81, '[' },
27 { 0x6e81, ']' },
28 { 0x7c81, '-' },
29 { 0x5b81, '°' },
30 { 0x4581, '¥' },
31 { 0x4481, '.' },
32 { 0x7B81, '+' },
33 { 0x9681, '*' },
34 { 0x5E81, '/' },
35 { 0x4981, '!' },
36 { 0x6881, '"' },
37 { 0x9481, '#' },
38 { 0x9081, '$' },
39 { 0x9381, '%' },
40 { 0x9581, '&' },
41 { 0x6681, '\'' },
42 { 0x6981, '(' },
43 { 0x6a81, ')' },
44 { 0x8181, '=' },
45 { 0x6281, '|' },
46 { 0x8f81, '\\' },
47 { 0x4881, '?' },
48 { 0x5181, '_' },
49 { 0x6f81, '{' },
50 { 0x7081, '}' },
51 { 0x9781, '@' },
52 { 0x4781, ';' },
53 { 0x4681, ':' },
54 { 0x8381, '<' },
55 { 0x8481, '>' },
56 { 0x4d81, '`' },
57 { 0, 0 }
58};
59
60unsigned char isSpecialSJIS(short sjis)
61{
62 const struct charmap_t *s = &sjis_conversion[0];
63 do {
64 if (s->sjis == sjis) return s->ascii;
65 s++;
66 } while (s->sjis != 0);
67 return 0;
68}
69
70short isSpecialASCII(unsigned char ascii)
71{
72 const struct charmap_t *s = &sjis_conversion[0];
73 do {
74 if (s->ascii == ascii) return s->sjis;
75 s++;
76 } while (s->ascii != 0);
77 return 0;
78}
79
80int strcpy_ascii(char* ascii_buff, const short* sjis_buff)
81{
82 int i;
83
84 int len = strlen((const char *)sjis_buff)/2;
85
86 for (i=0;i<len;i++) {
87 short ascii, sjis;
88 sjis = sjis_buff[i];
89 if ((ascii = isSpecialSJIS(sjis)) != 0) {
90 } else {
91 ascii = ((sjis & 0xFF00) >> 8) - 0x1f;
92 if (ascii>96) ascii--;
93 }
94 ascii_buff[i] = ascii;
95 }
96 ascii_buff[i]=0;
97 return len;
98}
99
100int strcpy_sjis(short* sjis_buff, const char* ascii_buff)
101{
102 int i;
103
104 int len = strlen(ascii_buff);
105
106 for (i=0;i<len;i++) {
107 short ascii, sjis;
108 ascii = ascii_buff[i];
109 if ((sjis = isSpecialASCII(ascii)) != 0) {
110 } else {
111 if (ascii>96) ascii++;
112 sjis = ((ascii + 0x1f) << 8) | 0x82;
113 }
114 sjis_buff[i] = sjis;
115 }
116 sjis_buff[i]=0;
117 return len;
118}
119
int strcpy_ascii(char *ascii_buff, const short *sjis_buff)
Definition sjis.c:80
int strcpy_sjis(short *sjis_buff, const char *ascii_buff)
Definition sjis.c:100