Use s2utbl as a fallback of TextDecoder

This commit is contained in:
kichikuou
2017-04-02 12:25:43 +09:00
parent ee83411bcd
commit 3fe4435523
3 changed files with 18 additions and 6 deletions
+1 -1
View File
@@ -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
+8 -5
View File
@@ -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;
+9
View File
@@ -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