Nugget
Loading...
Searching...
No Matches
sjis-fullwidth-ascii.hh
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2026 PCSX-Redux authors
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26
27#pragma once
28
29#include <stdint.h>
30
31// Lightweight default title encoder: the ASCII-only subset of the BIOS
32// save-title convention. Printable ASCII is promoted to its fullwidth form and
33// looked up in a compact 95-entry table (190 bytes) carved out of the full
34// Unicode->Shift-JIS table; any non-ASCII codepoint becomes '?'. This is what
35// lets a program that only ever uses ASCII titles avoid linking the ~28kB
36// c_unicodeToSjisConvTable. Registering the full encoder (see
37// sjis-title-encoder.h) overrides this with the complete conversion.
38//
39// The table below is generated: for each ASCII value 0x20..0x7e it holds the
40// Shift-JIS encoding of the corresponding fullwidth codepoint (space -> U+3000,
41// 0x21..0x7e -> U+ff01..U+ff5e), taken verbatim from c_unicodeToSjisConvTable.
42// Five fullwidth punctuation forms (" ' - \ ~) have no JIS X 0208 mapping, so
43// their entries are 0 and the encoder emits '?' for them -- identical to what
44// the full encoder does, keeping ASCII output byte-for-byte the same either way.
45
46namespace Sjis {
47
48// Indexed by (ASCII codepoint - 0x20), so [0] is space and [94] is '~'.
49extern const uint16_t c_fullwidthAsciiToSjis[96];
50
51// Encodes a UTF-8 string to Shift-JIS using the BIOS save-title convention,
52// but with ASCII-only support: printable ASCII is promoted to fullwidth via the
53// table above; every non-ASCII codepoint (and the five unmapped fullwidth forms)
54// becomes '?'. Writes up to dstSize bytes, returns the number written; output is
55// not NUL-terminated. Signature matches Sjis::utf8ToSjisTitle so the two are
56// interchangeable behind a function pointer.
57uint32_t asciiToSjisTitle(uint8_t* dst, uint32_t dstSize, const char* src);
58
59// Decodes a Shift-JIS save title back to plain ASCII, the inverse of
60// asciiToSjisTitle: each fullwidth form in the compact table becomes its ASCII
61// character, and anything else (real Japanese, halfwidth kana, an unmapped
62// form) becomes '?'. It uses only the 190-byte fullwidth table, so an ASCII-only
63// program can read titles back without linking the full ~28kB conversion table;
64// Sjis::sjisToUtf8 (sjis-decode.h) is the full-Unicode counterpart. Writes at
65// most dstSize bytes, always NUL-terminating when dstSize > 0, and returns the
66// number written (not counting the terminator). A 0x00 byte ends the input
67// (0x00 is never a Shift-JIS lead or trail byte), giving a C string for the
68// padded 64-byte card title field.
69uint32_t sjisTitleToAscii(char* dst, uint32_t dstSize, const uint8_t* src, uint32_t srcLen);
70
71} // namespace Sjis
Definition sjis-decode.hh:38
uint32_t sjisTitleToAscii(char *dst, uint32_t dstSize, const uint8_t *src, uint32_t srcLen)
Definition sjis-fullwidth-ascii.cc:156
uint32_t asciiToSjisTitle(uint8_t *dst, uint32_t dstSize, const char *src)
Definition sjis-fullwidth-ascii.cc:130
const uint16_t c_fullwidthAsciiToSjis[96]
Definition sjis-fullwidth-ascii.cc:31
static const char * src
Definition syscalls.h:80
void uint32_t(classId, spec)