diff --git a/Makefile.emscripten b/Makefile.emscripten index 42186de..929a3d4 100644 --- a/Makefile.emscripten +++ b/Makefile.emscripten @@ -9,7 +9,7 @@ EMFLAGS += -O2 EMFLAGS += -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1 LFLAGS := $(EMFLAGS) -LFLAGS += -s EXPORTED_FUNCTIONS="['_main','_ags_setAntialiasedStringMode', '_ald_getdata', '_ald_freedata']" +LFLAGS += -s EXPORTED_FUNCTIONS="['_main','_ags_setAntialiasedStringMode', '_ald_getdata', '_ald_freedata', '_sjis2unicode']" WASMFLAGS := -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s "BINARYEN_TRAP_MODE='allow'" ASMJSFLAGS := -s TOTAL_MEMORY=100663296 diff --git a/shell/util.ts b/shell/util.ts index f0f9928..11d2aea 100644 --- a/shell/util.ts +++ b/shell/util.ts @@ -26,15 +26,17 @@ function SJISArrayToString(buffer: DataView): string { if (typeof TextDecoder !== 'undefined') return new TextDecoder('shift_jis').decode(buffer); - let out = ''; + let out = []; for (let i = 0; i < buffer.byteLength; i++) { let c = buffer.getUint8(i); - if (c < 128) - out += String.fromCharCode(c); + if (c >= 0xa0 && c <= 0xdf) + out.push(0xff60 + c - 0xa0); + else if (c < 0x80) + out.push(c); else - out += '%' + c.toString(16); + out.push(_sjis2unicode(c, buffer.getUint8(++i))); } - return out; + return String.fromCharCode.apply(null, out); } declare var WebAssembly: any; @@ -44,6 +46,7 @@ declare function _musfade_setvolval_all(vol: number): void; declare function _ags_setAntialiasedStringMode(on: number): void; declare function _ald_getdata(type: number, no: number): number; declare function _ald_freedata(data: number): void; +declare function _sjis2unicode(byte1: number, byte2: number): void; declare namespace Module { let noInitialRun: boolean; diff --git a/src/utfsjis.c b/src/utfsjis.c index d5c012f..9754e7d 100644 --- a/src/utfsjis.c +++ b/src/utfsjis.c @@ -133,3 +133,12 @@ BYTE *sjis_toupper2(BYTE *src) { sjis_toupper(dst); return dst; } + +#ifdef __EMSCRIPTEN__ +extern unsigned short *s2u[]; + +int sjis2unicode(int byte1, int byte2) { + return s2u[byte1 - 0x80][byte2 - 0x40]; +} + +#endif