win32: Unicode - fix Custom ROM dialog to show half-width katakana
Code:
83594657052359eb030726dff32ade38588f7cda
win32/_tfwopen.cpp | 6 ++++++
win32/_tfwopen.h | 9 +++++++++
win32/wsnes9x.cpp | 8 ++++----
win32/wsnes9x.h | 2 ++
4 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/win32/_tfwopen.cpp b/win32/_tfwopen.cpp
index 537b3c7..8f0d82e 100644
--- a/win32/_tfwopen.cpp
+++ b/win32/_tfwopen.cpp
@@ -192,6 +192,12 @@ WideToUtf8::WideToUtf8(const wchar_t *wideChars) {
WideCharToMultiByte(CP_UTF8,0,wideChars,-1,utf8Chars,requiredChars,NULL,NULL);
}
+MS932ToWide::MS932ToWide(const char *ms932Chars) {
+ int requiredChars = MultiByteToWideChar(932,0,ms932Chars,-1,wideChars,0);
+ wideChars = new wchar_t[requiredChars];
+ MultiByteToWideChar(932,0,ms932Chars,-1,wideChars,requiredChars);
+}
+
extern "C" FILE *_tfwopen(const char *filename, const char *mode ) {
wchar_t mode_w[30];
lstrcpyn(mode_w,Utf8ToWide(mode),29);
diff --git a/win32/_tfwopen.h b/win32/_tfwopen.h
index 5cb88e1..8429b99 100644
--- a/win32/_tfwopen.h
+++ b/win32/_tfwopen.h
@@ -227,6 +227,15 @@ public:
operator char *() { return utf8Chars; }
};
+class MS932ToWide {
+private:
+ wchar_t *wideChars;
+public:
+ MS932ToWide(const char *ms932Chars);
+ ~MS932ToWide() { delete [] wideChars; }
+ operator wchar_t *() { return wideChars; }
+};
+
namespace std {
class u8nifstream: public std::ifstream
{
diff --git a/win32/wsnes9x.cpp b/win32/wsnes9x.cpp
index a2319b3..8dfc254 100644
--- a/win32/wsnes9x.cpp
+++ b/win32/wsnes9x.cpp
@@ -5322,7 +5322,7 @@ void rominfo(const TCHAR *filename, TCHAR *namebuffer, TCHAR *sizebuffer)
if (InfoScore((char *)HeaderBuffer) > 1)
{
EHi = true;
- _tcsncpy(namebuffer, _tFromChar((char *)HeaderBuffer), 21);
+ _tcsncpy(namebuffer, _tFromMS932((char *)HeaderBuffer), 21);
}
}
@@ -5340,7 +5340,7 @@ void rominfo(const TCHAR *filename, TCHAR *namebuffer, TCHAR *sizebuffer)
ROMFile.read(HiHead, INFO_LEN);
int HiScore = InfoScore(HiHead);
- _tcsncpy(namebuffer, _tFromChar(LoScore > HiScore ? LoHead : HiHead), 21);
+ _tcsncpy(namebuffer, _tFromMS932(LoScore > HiScore ? LoHead : HiHead), 21);
if (filestats.st_size - HeaderSize >= 0x20000)
{
@@ -5350,7 +5350,7 @@ void rominfo(const TCHAR *filename, TCHAR *namebuffer, TCHAR *sizebuffer)
if (IntLScore > LoScore && IntLScore > HiScore)
{
- _tcsncpy(namebuffer, _tFromChar(LoHead), 21);
+ _tcsncpy(namebuffer, _tFromMS932(LoHead), 21);
}
}
}
@@ -5359,7 +5359,7 @@ void rominfo(const TCHAR *filename, TCHAR *namebuffer, TCHAR *sizebuffer)
char buf[21];
ROMFile.seekg(0x7FC0 + HeaderSize, ios::beg);
ROMFile.read(buf, 21);
- _tcsncpy(namebuffer,_tFromChar(buf),21);
+ _tcsncpy(namebuffer,_tFromMS932(buf),21);
}
}
ROMFile.close();
diff --git a/win32/wsnes9x.h b/win32/wsnes9x.h
index 0e0e6e5..415c9c3 100644
--- a/win32/wsnes9x.h
+++ b/win32/wsnes9x.h
@@ -217,9 +217,11 @@
#ifdef UNICODE
#define _tToChar WideToUtf8
#define _tFromChar Utf8ToWide
+#define _tFromMS932 MS932ToWide
#else
#define _tToChar
#define _tFromChar
+#define _tFromMS932
#endif
/****************************************************************************/