diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/library.js | 117 | ||||
-rw-r--r-- | src/library_openal.js | 195 | ||||
-rw-r--r-- | src/parseTools.js | 4 | ||||
-rw-r--r-- | src/runtime.js | 4 |
4 files changed, 286 insertions, 34 deletions
diff --git a/src/library.js b/src/library.js index fc2e8a64..4c0f790f 100644 --- a/src/library.js +++ b/src/library.js @@ -162,7 +162,7 @@ LibraryManager.library = { if (times) { // NOTE: We don't keep track of access timestamps. var offset = {{{ C_STRUCTS.utimbuf.modtime }}}; - time = {{{ makeGetValue('times', 'offset', 'i32') }}} + time = {{{ makeGetValue('times', 'offset', 'i32') }}}; time *= 1000; } else { time = Date.now(); @@ -1182,7 +1182,7 @@ LibraryManager.library = { for (var i = 0; i < length; i++) { {{{ makeSetValue('buf', 'i', 'value.charCodeAt(i)', 'i8') }}}; } - if (len > length) {{{ makeSetValue('buf', 'i++', '0', 'i8') }}} + if (len > length) {{{ makeSetValue('buf', 'i++', '0', 'i8') }}}; return i; } }, @@ -3229,22 +3229,34 @@ LibraryManager.library = { strtoll: function(str, endptr, base) { return __parseInt64(str, endptr, base, '-9223372036854775808', '9223372036854775807'); // LLONG_MIN, LLONG_MAX. }, - strtoll_l: 'strtoll', // no locale support yet + strtoll_l__deps: ['strtoll'], + strtoll_l: function(str, endptr, base) { + return _strtoll(str, endptr, base); // no locale support yet + }, strtol__deps: ['_parseInt'], strtol: function(str, endptr, base) { return __parseInt(str, endptr, base, -2147483648, 2147483647, 32); // LONG_MIN, LONG_MAX. }, - strtol_l: 'strtol', // no locale support yet + strtol_l__deps: ['strtol'], + strtol_l: function(str, endptr, base) { + return _strtol(str, endptr, base); // no locale support yet + }, strtoul__deps: ['_parseInt'], strtoul: function(str, endptr, base) { return __parseInt(str, endptr, base, 0, 4294967295, 32, true); // ULONG_MAX. }, - strtoul_l: 'strtoul', // no locale support yet + strtoul_l__deps: ['strtoul'], + strtoul_l: function(str, endptr, base) { + return _strtoul(str, endptr, base); // no locale support yet + }, strtoull__deps: ['_parseInt64'], strtoull: function(str, endptr, base) { return __parseInt64(str, endptr, base, 0, '18446744073709551615', true); // ULONG_MAX. }, - strtoull_l: 'strtoull', // no locale support yet + strtoull_l__deps: ['strtoull'], + strtoull_l: function(str, endptr, base) { + return _strtoull(str, endptr, base); // no locale support yet + }, atoi__deps: ['strtol'], atoi: function(ptr) { @@ -3735,7 +3747,10 @@ LibraryManager.library = { }, // We always assume ASCII locale. strcoll: 'strcmp', - strcoll_l: 'strcmp', + strcoll_l__deps: ['strcoll'], + strcoll_l: function(px, py) { + return _strcoll(px, py); // no locale support yet + }, strcasecmp__asm: true, strcasecmp__sig: 'iii', @@ -4000,7 +4015,10 @@ LibraryManager.library = { } }, _toupper: 'toupper', - toupper_l: 'toupper', + toupper_l__deps: ['toupper'], + toupper_l: function(str, endptr, base) { + return _toupper(str, endptr, base); // no locale support yet + }, tolower__asm: true, tolower__sig: 'ii', @@ -4011,65 +4029,104 @@ LibraryManager.library = { return (chr - {{{ charCode('A') }}} + {{{ charCode('a') }}})|0; }, _tolower: 'tolower', - tolower_l: 'tolower', + tolower_l__deps: ['tolower'], + tolower_l: function(chr) { + return _tolower(chr); // no locale support yet + }, // The following functions are defined as macros in glibc. islower: function(chr) { return chr >= {{{ charCode('a') }}} && chr <= {{{ charCode('z') }}}; }, - islower_l: 'islower', + islower_l__deps: ['islower'], + islower_l: function(chr) { + return _islower(chr); // no locale support yet + }, isupper: function(chr) { return chr >= {{{ charCode('A') }}} && chr <= {{{ charCode('Z') }}}; }, - isupper_l: 'isupper', + isupper_l__deps: ['isupper'], + isupper_l: function(chr) { + return _isupper(chr); // no locale support yet + }, isalpha: function(chr) { return (chr >= {{{ charCode('a') }}} && chr <= {{{ charCode('z') }}}) || (chr >= {{{ charCode('A') }}} && chr <= {{{ charCode('Z') }}}); }, - isalpha_l: 'isalpha', + isalpha_l__deps: ['isalpha'], + isalpha_l: function(chr) { + return _isalpha(chr); // no locale support yet + }, isdigit: function(chr) { return chr >= {{{ charCode('0') }}} && chr <= {{{ charCode('9') }}}; }, - isdigit_l: 'isdigit', + isdigit_l__deps: ['isdigit'], + isdigit_l: function(chr) { + return _isdigit(chr); // no locale support yet + }, isxdigit: function(chr) { return (chr >= {{{ charCode('0') }}} && chr <= {{{ charCode('9') }}}) || (chr >= {{{ charCode('a') }}} && chr <= {{{ charCode('f') }}}) || (chr >= {{{ charCode('A') }}} && chr <= {{{ charCode('F') }}}); }, - isxdigit_l: 'isxdigit', + isxdigit_l__deps: ['isxdigit'], + isxdigit_l: function(chr) { + return _isxdigit(chr); // no locale support yet + }, isalnum: function(chr) { return (chr >= {{{ charCode('0') }}} && chr <= {{{ charCode('9') }}}) || (chr >= {{{ charCode('a') }}} && chr <= {{{ charCode('z') }}}) || (chr >= {{{ charCode('A') }}} && chr <= {{{ charCode('Z') }}}); }, - isalnum_l: 'isalnum', + isalnum_l__deps: ['isalnum'], + isalnum_l: function(chr) { + return _isalnum(chr); // no locale support yet + }, ispunct: function(chr) { return (chr >= {{{ charCode('!') }}} && chr <= {{{ charCode('/') }}}) || (chr >= {{{ charCode(':') }}} && chr <= {{{ charCode('@') }}}) || (chr >= {{{ charCode('[') }}} && chr <= {{{ charCode('`') }}}) || (chr >= {{{ charCode('{') }}} && chr <= {{{ charCode('~') }}}); }, - ispunct_l: 'ispunct', + ispunct_l__deps: ['ispunct'], + ispunct_l: function(chr) { + return _ispunct(chr); // no locale support yet + }, isspace: function(chr) { return (chr == 32) || (chr >= 9 && chr <= 13); }, - isspace_l: 'isspace', + isspace_l__deps: ['isspace'], + isspace_l: function(chr) { + return _isspace(chr); // no locale support yet + }, isblank: function(chr) { return chr == {{{ charCode(' ') }}} || chr == {{{ charCode('\t') }}}; }, - isblank_l: 'isblank', + isblank_l__deps: ['isblank'], + isblank_l: function(chr) { + return _isblank(chr); // no locale support yet + }, iscntrl: function(chr) { return (0 <= chr && chr <= 0x1F) || chr === 0x7F; }, - iscntrl_l: 'iscntrl', + iscntrl_l__deps: ['iscntrl'], + iscntrl_l: function(chr) { + return _iscntrl(chr); // no locale support yet + }, isprint: function(chr) { return 0x1F < chr && chr < 0x7F; }, - isprint_l: 'isprint', + isprint_l__deps: ['isprint'], + isprint_l: function(chr) { + return _isprint(chr); // no locale support yet + }, isgraph: function(chr) { return 0x20 < chr && chr < 0x7F; }, - isgraph_l: 'isgraph', + isgraph_l__deps: ['isgraph'], + isgraph_l: function(chr) { + return _isgraph(chr); // no locale support yet + }, // Lookup tables for glibc ctype implementation. __ctype_b_loc: function() { // http://refspecs.freestandards.org/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/baselib---ctype-b-loc.html @@ -4365,8 +4422,8 @@ LibraryManager.library = { Module.printErr('Compiled code throwing an exception, ' + [ptr,type,destructor] + ', at ' + stackTrace()); #endif var header = ptr - ___cxa_exception_header_size; - {{{ makeSetValue('header', 0, 'type', 'void*') }}} - {{{ makeSetValue('header', 4, 'destructor', 'void*') }}} + {{{ makeSetValue('header', 0, 'type', 'void*') }}}; + {{{ makeSetValue('header', 4, 'destructor', 'void*') }}}; ___cxa_last_thrown_exception = ptr; if (!("uncaught_exception" in __ZSt18uncaught_exceptionv)) { __ZSt18uncaught_exceptionv.uncaught_exception = 1; @@ -4434,7 +4491,7 @@ LibraryManager.library = { var destructor = {{{ makeGetValue('header', 4, 'void*') }}}; if (destructor) { Runtime.dynCall('vi', destructor, [ptr]); - {{{ makeSetValue('header', 4, '0', 'i32') }}} + {{{ makeSetValue('header', 4, '0', 'i32') }}}; } ___cxa_free_exception(ptr); ___cxa_last_thrown_exception = 0; @@ -5887,7 +5944,10 @@ LibraryManager.library = { writeArrayToMemory(bytes, s); return bytes.length-1; }, - strftime_l: 'strftime', // no locale support yet + strftime_l__deps: ['strftime'], + strftime_l: function(s, maxsize, format, tm) { + return _strftime(s, maxsize, format, tm); // no locale support yet + }, strptime__deps: ['_isLeapYear', '_arraySum', '_addDays', '_MONTH_DAYS_REGULAR', '_MONTH_DAYS_LEAP'], strptime: function(buf, format, tm) { @@ -6129,7 +6189,10 @@ LibraryManager.library = { return 0; }, - strptime_l: 'strptime', // no locale support yet + strptime_l__deps: ['strptime'], + strptime_l: function(buf, format, tm) { + return _strptime(buf, format, tm); // no locale support yet + }, getdate: function(string) { // struct tm *getdate(const char *string); @@ -7630,7 +7693,7 @@ LibraryManager.library = { node = DNS.lookup_name(node); addr = __inet_pton4_raw(node); if (family === {{{ cDefine('AF_UNSPEC') }}}) { - family = {{{ cDefine('AF_INET') }}} + family = {{{ cDefine('AF_INET') }}}; } else if (family === {{{ cDefine('AF_INET6') }}}) { addr = [0, 0, _htonl(0xffff), addr]; } diff --git a/src/library_openal.js b/src/library_openal.js index 67481824..ac49fe95 100644 --- a/src/library_openal.js +++ b/src/library_openal.js @@ -5,6 +5,10 @@ var LibraryOpenAL = { $AL: { contexts: [], currentContext: null, + + stringCache: {}, + alcStringCache: {}, + QUEUE_INTERVAL: 25, QUEUE_LOOKAHEAD: 100, @@ -235,6 +239,42 @@ var LibraryOpenAL = { return _alGetError(); }, + alcGetIntegerv: function(device, param, size, data) { + if (size == 0 || !data) { + AL.currentContext.err = 0xA003 /* AL_INVALID_VALUE */; + return; + } + + switch(param) { + case 0x1000 /* ALC_MAJOR_VERSION */: + {{{ makeSetValue('data', '0', '1', 'i32') }}}; + break; + case 0x1001 /* ALC_MINOR_VERSION */: + {{{ makeSetValue('data', '0', '1', 'i32') }}}; + break; + case 0x1002 /* ALC_ATTRIBUTES_SIZE */: + if (!device) { + AL.currentContext.err = 0xA001 /* ALC_INVALID_DEVICE */; + return 0; + } + {{{ makeSetValue('data', '0', '1', 'i32') }}}; + break; + case 0x1003 /* ALC_ALL_ATTRIBUTES */: + if (!device) { + AL.currentContext.err = 0xA001 /* ALC_INVALID_DEVICE */; + return 0; + } + {{{ makeSetValue('data', '0', '0', 'i32') }}}; + break; + default: +#if OPENAL_DEBUG + console.log("alcGetIntegerv with param " + param + " not implemented yet"); +#endif + AL.currentContext.err = 0xA003 /* ALC_INVALID_ENUM */; + break; + } + }, + alDeleteSources: function(count, sources) { if (!AL.currentContext) { #if OPENAL_DEBUG @@ -334,6 +374,18 @@ var LibraryOpenAL = { } }, + alIsSource: function(sourceId) { + if (!AL.currentContext) { + return false; + } + + if (!AL.currentContext.src[sourceId - 1]) { + return false; + } else { + return true; + } + }, + alSourcei__deps: ['updateSource'], alSourcei: function(source, param, value) { if (!AL.currentContext) { @@ -691,6 +743,7 @@ var LibraryOpenAL = { } try { AL.currentContext.buf[buffer - 1] = AL.currentContext.ctx.createBuffer(channels, size / (bytes * channels), freq); + AL.currentContext.buf[buffer - 1].bytesPerSample = bytes; } catch (e) { AL.currentContext.err = 0xA003 /* AL_INVALID_VALUE */; return; @@ -715,6 +768,41 @@ var LibraryOpenAL = { } }, + alGetBufferi: function(buffer, param, value) + { + if (!AL.currentContext) { +#if OPENAL_DEBUG + console.error("alGetBufferi called without a valid context"); +#endif + return; + } + var buf = AL.currentContext.buf[buffer - 1]; + if (!buf) { +#if OPENAL_DEBUG + console.error("alGetBufferi called with an invalid buffer"); +#endif + AL.currentContext.err = 0xA001 /* AL_INVALID_NAME */; + return; + } + switch (param) { + case 0x2001 /* AL_FREQUENCY */: + {{{ makeSetValue('value', '0', 'buf.sampleRate', 'i32') }}}; + break; + case 0x2002 /* AL_BITS */: + {{{ makeSetValue('value', '0', 'buf.bytesPerSample * 8', 'i32') }}}; + break; + case 0x2003 /* AL_CHANNELS */: + {{{ makeSetValue('value', '0', 'buf.numberOfChannels', 'i32') }}}; + break; + case 0x2004 /* AL_SIZE */: + {{{ makeSetValue('value', '0', 'buf.length * buf.bytesPerSample * buf.numberOfChannels', 'i32') }}}; + break; + default: + AL.currentContext.err = 0xA002 /* AL_INVALID_ENUM */; + break; + } + }, + alSourcePlay__deps: ['setSourceState'], alSourcePlay: function(source) { if (!AL.currentContext) { @@ -1128,15 +1216,116 @@ var LibraryOpenAL = { }, alGetString: function(param) { - return allocate(intArrayFromString('NA'), 'i8', ALLOC_NORMAL); + if (AL.stringCache[param]) return AL.stringCache[param]; + var ret; + switch (param) { + case 0 /* AL_NO_ERROR */: + ret = 'No Error'; + break; + case 0xA001 /* AL_INVALID_NAME */: + ret = 'Invalid Name'; + break; + case 0xA002 /* AL_INVALID_ENUM */: + ret = 'Invalid Enum'; + break; + case 0xA003 /* AL_INVALID_VALUE */: + ret = 'Invalid Value'; + break; + case 0xA004 /* AL_INVALID_OPERATION */: + ret = 'Invalid Operation'; + break; + case 0xA005 /* AL_OUT_OF_MEMORY */: + ret = 'Out of Memory'; + break; + case 0xB001 /* AL_VENDOR */: + ret = 'Emscripten'; + break; + case 0xB002 /* AL_VERSION */: + ret = '1.1'; + break; + case 0xB003 /* AL_RENDERER */: + ret = 'WebAudio'; + break; + case 0xB004 /* AL_EXTENSIONS */: + ret = ''; + break; + default: + AL.currentContext.err = 0xA002 /* AL_INVALID_ENUM */; + return 0; + } + + ret = allocate(intArrayFromString(ret), 'i8', ALLOC_NORMAL); + + AL.stringCache[param] = ret; + + return ret; }, alGetProcAddress: function(fname) { return 0; }, - alcGetString: function(param) { - return allocate(intArrayFromString('NA'), 'i8', ALLOC_NORMAL); + alcGetString: function(device, param) { + if (AL.alcStringCache[param]) return AL.alcStringCache[param]; + var ret; + switch (param) { + case 0 /* ALC_NO_ERROR */: + ret = 'No Error'; + break; + case 0xA001 /* ALC_INVALID_DEVICE */: + ret = 'Invalid Device'; + break; + case 0xA002 /* ALC_INVALID_CONTEXT */: + ret = 'Invalid Context'; + break; + case 0xA003 /* ALC_INVALID_ENUM */: + ret = 'Invalid Enum'; + break; + case 0xA004 /* ALC_INVALID_VALUE */: + ret = 'Invalid Value'; + break; + case 0xA005 /* ALC_OUT_OF_MEMORY */: + ret = 'Out of Memory'; + break; + case 0x1004 /* ALC_DEFAULT_DEVICE_SPECIFIER */: + if (typeof(AudioContext) == "function" || + typeof(webkitAudioContext) == "function") { + ret = 'Device'; + } else { + return 0; + } + break; + case 0x1005 /* ALC_DEVICE_SPECIFIER */: + if (typeof(AudioContext) == "function" || + typeof(webkitAudioContext) == "function") { + ret = 'Device\0'; + } else { + ret = '\0'; + } + break; + case 0x311 /* ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER */: + return 0; + break; + case 0x310 /* ALC_CAPTURE_DEVICE_SPECIFIER */: + ret = '\0' + break; + case 0x1006 /* ALC_EXTENSIONS */: + if (!device) { + AL.currentContext.err = 0xA001 /* ALC_INVALID_DEVICE */; + return 0; + } + ret = ''; + break; + default: + AL.currentContext.err = 0xA003 /* ALC_INVALID_ENUM */; + return 0; + } + + ret = allocate(intArrayFromString(ret), 'i8', ALLOC_NORMAL); + + AL.alcStringCache[param] = ret; + + return ret; }, alcGetProcAddress: function(device, fname) { diff --git a/src/parseTools.js b/src/parseTools.js index e09cd2e2..bad080b7 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -1332,7 +1332,7 @@ function makeGetValue(ptr, pos, type, noNeedFirst, unsigned, ignore, align, noSa if (printType !== 'null' && printType[0] !== '#') printType = '"' + safeQuote(printType) + '"'; if (printType[0] === '#') printType = printType.substr(1); if (ASM_JS) { - if (!ignore) return asmCoercion('SAFE_HEAP_LOAD(' + asmCoercion(offset, 'i32') + ', ' + Runtime.getNativeTypeSize(type) + ', ' + ((type in Runtime.FLOAT_TYPES)|0) + ', ' + (!!unsigned+0) + ')', type); + if (!ignore && phase !== 'funcs') return asmCoercion('SAFE_HEAP_LOAD(' + asmCoercion(offset, 'i32') + ', ' + Runtime.getNativeTypeSize(type) + ', ' + ((type in Runtime.FLOAT_TYPES)|0) + ', ' + (!!unsigned+0) + ')', type); // else fall through } else { return asmCoercion('SAFE_HEAP_LOAD(' + offset + ', ' + (ASM_JS ? 0 : printType) + ', ' + (!!unsigned+0) + ', ' + ((!checkSafeHeap() || ignore)|0) + ')', type); @@ -1444,7 +1444,7 @@ function makeSetValue(ptr, pos, value, type, noNeedFirst, ignore, align, noSafe, if (printType !== 'null' && printType[0] !== '#') printType = '"' + safeQuote(printType) + '"'; if (printType[0] === '#') printType = printType.substr(1); if (ASM_JS) { - if (!ignore) return asmCoercion('SAFE_HEAP_STORE(' + asmCoercion(offset, 'i32') + ', ' + asmCoercion(value, type) + ', ' + Runtime.getNativeTypeSize(type) + ', ' + ((type in Runtime.FLOAT_TYPES)|0) + ')', type); + if (!ignore && phase !== 'funcs') return asmCoercion('SAFE_HEAP_STORE(' + asmCoercion(offset, 'i32') + ', ' + asmCoercion(value, type) + ', ' + Runtime.getNativeTypeSize(type) + ', ' + ((type in Runtime.FLOAT_TYPES)|0) + ')', type); // else fall through } else { return 'SAFE_HEAP_STORE(' + offset + ', ' + value + ', ' + (ASM_JS ? 0 : printType) + ', ' + ((!checkSafeHeap() || ignore)|0) + ')'; diff --git a/src/runtime.js b/src/runtime.js index 4fcca56b..a9265e70 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -565,7 +565,7 @@ function getRuntime() { // Converts a value we have as signed, into an unsigned value. For // example, -1 in int32 would be a very large number as unsigned. -function unSign(value, bits, ignore, sig) { +function unSign(value, bits, ignore) { if (value >= 0) { return value; } @@ -578,7 +578,7 @@ function unSign(value, bits, ignore, sig) { // Converts a value we have as unsigned, into a signed value. For // example, 200 in a uint8 would be a negative number. -function reSign(value, bits, ignore, sig) { +function reSign(value, bits, ignore) { if (value <= 0) { return value; } |