You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
9990 lines
1.4 MiB
JavaScript
9990 lines
1.4 MiB
JavaScript
9 years ago
|
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
||
|
var xtend = require('xtend')
|
||
|
var pcejs = require('./lib/pcejs-macplus')
|
||
|
|
||
|
var configOpts = {
|
||
|
'arguments': ['-c','pce-config.cfg','-r'],
|
||
|
}
|
||
|
|
||
|
module.exports = function (opts) {
|
||
|
// inject dependencies and config
|
||
|
var config = xtend(configOpts, opts)
|
||
|
var deps = {
|
||
|
extend: xtend,
|
||
|
}
|
||
|
return pcejs(deps, config)
|
||
|
}
|
||
|
},{"./lib/pcejs-macplus":2,"xtend":3}],2:[function(require,module,exports){
|
||
|
module.exports = function(deps, opts) {
|
||
|
var Module = opts || {};
|
||
|
|
||
|
// hide node/commonjs globals so emscripten doesn't get confused
|
||
|
var process = null;
|
||
|
var require = null;
|
||
|
|
||
|
var pathGetFilenameRegex = /\/([^\/]+)$/;
|
||
|
|
||
|
function pathGetFilename(path) {
|
||
|
var matches = path.match(pathGetFilenameRegex);
|
||
|
if (matches && matches.length) {
|
||
|
return matches[1];
|
||
|
} else {
|
||
|
return path;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function addAutoloader(module) {
|
||
|
var loadDatafiles = function() {
|
||
|
module.autoloadFiles.forEach(function(filepath) {
|
||
|
module.FS_createPreloadedFile('/', pathGetFilename(filepath), filepath, true, true);
|
||
|
});
|
||
|
};
|
||
|
|
||
|
if (module.autoloadFiles) {
|
||
|
module.preRun = module.preRun || [];
|
||
|
module.preRun.unshift(loadDatafiles);
|
||
|
}
|
||
|
|
||
|
return module;
|
||
|
}
|
||
|
|
||
|
// inject extra behaviours
|
||
|
addAutoloader(Module);
|
||
|
|
||
|
// The Module object: Our interface to the outside world. We import
|
||
|
// and export values on it, and do the work to get that through
|
||
|
// closure compiler if necessary. There are various ways Module can be used:
|
||
|
// 1. Not defined. We create it here
|
||
|
// 2. A function parameter, function(Module) { ..generated code.. }
|
||
|
// 3. pre-run appended it, var Module = {}; ..generated code..
|
||
|
// 4. External script tag defines var Module.
|
||
|
// We need to do an eval in order to handle the closure compiler
|
||
|
// case, where this code here is minified but Module was defined
|
||
|
// elsewhere (e.g. case 4 above). We also need to check if Module
|
||
|
// already exists (e.g. case 3 above).
|
||
|
// Note that if you want to run closure, and also to use Module
|
||
|
// after the generated code, you will need to define var Module = {};
|
||
|
// before the code. Then that object will be used in the code, and you
|
||
|
// can continue to use Module afterwards as well.
|
||
|
var Module;
|
||
|
if (!Module) Module = (typeof Module !== 'undefined' ? Module : null) || {};
|
||
|
|
||
|
// Sometimes an existing Module object exists with properties
|
||
|
// meant to overwrite the default module functionality. Here
|
||
|
// we collect those properties and reapply _after_ we configure
|
||
|
// the current environment's defaults to avoid having to be so
|
||
|
// defensive during initialization.
|
||
|
var moduleOverrides = {};
|
||
|
for (var key in Module) {
|
||
|
if (Module.hasOwnProperty(key)) {
|
||
|
moduleOverrides[key] = Module[key];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// The environment setup code below is customized to use Module.
|
||
|
// *** Environment setup code ***
|
||
|
var ENVIRONMENT_IS_NODE = typeof process === 'object' && typeof require === 'function';
|
||
|
var ENVIRONMENT_IS_WEB = typeof window === 'object';
|
||
|
var ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
|
||
|
var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
|
||
|
|
||
|
if (ENVIRONMENT_IS_NODE) {
|
||
|
// Expose functionality in the same simple way that the shells work
|
||
|
// Note that we pollute the global namespace here, otherwise we break in node
|
||
|
if (!Module['print']) Module['print'] = function print(x) {
|
||
|
process['stdout'].write(x + '\n');
|
||
|
};
|
||
|
if (!Module['printErr']) Module['printErr'] = function printErr(x) {
|
||
|
process['stderr'].write(x + '\n');
|
||
|
};
|
||
|
|
||
|
var nodeFS = require('fs');
|
||
|
var nodePath = require('path');
|
||
|
|
||
|
Module['read'] = function read(filename, binary) {
|
||
|
filename = nodePath['normalize'](filename);
|
||
|
var ret = nodeFS['readFileSync'](filename);
|
||
|
// The path is absolute if the normalized version is the same as the resolved.
|
||
|
if (!ret && filename != nodePath['resolve'](filename)) {
|
||
|
filename = path.join(__dirname, '..', 'src', filename);
|
||
|
ret = nodeFS['readFileSync'](filename);
|
||
|
}
|
||
|
if (ret && !binary) ret = ret.toString();
|
||
|
return ret;
|
||
|
};
|
||
|
|
||
|
Module['readBinary'] = function readBinary(filename) { return Module['read'](filename, true) };
|
||
|
|
||
|
Module['load'] = function load(f) {
|
||
|
globalEval(read(f));
|
||
|
};
|
||
|
|
||
|
Module['arguments'] = process['argv'].slice(2);
|
||
|
|
||
|
module['exports'] = Module;
|
||
|
}
|
||
|
else if (ENVIRONMENT_IS_SHELL) {
|
||
|
if (!Module['print']) Module['print'] = print;
|
||
|
if (typeof printErr != 'undefined') Module['printErr'] = printErr; // not present in v8 or older sm
|
||
|
|
||
|
if (typeof read != 'undefined') {
|
||
|
Module['read'] = read;
|
||
|
} else {
|
||
|
Module['read'] = function read() { throw 'no read() available (jsc?)' };
|
||
|
}
|
||
|
|
||
|
Module['readBinary'] = function readBinary(f) {
|
||
|
return read(f, 'binary');
|
||
|
};
|
||
|
|
||
|
if (typeof scriptArgs != 'undefined') {
|
||
|
Module['arguments'] = scriptArgs;
|
||
|
} else if (typeof arguments != 'undefined') {
|
||
|
Module['arguments'] = arguments;
|
||
|
}
|
||
|
|
||
|
this['Module'] = Module;
|
||
|
|
||
|
eval("if (typeof gc === 'function' && gc.toString().indexOf('[native code]') > 0) var gc = undefined"); // wipe out the SpiderMonkey shell 'gc' function, which can confuse closure (uses it as a minified name, and it is then initted to a non-falsey value unexpectedly)
|
||
|
}
|
||
|
else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
|
||
|
Module['read'] = function read(url) {
|
||
|
var xhr = new XMLHttpRequest();
|
||
|
xhr.open('GET', url, false);
|
||
|
xhr.send(null);
|
||
|
return xhr.responseText;
|
||
|
};
|
||
|
|
||
|
if (typeof arguments != 'undefined') {
|
||
|
Module['arguments'] = arguments;
|
||
|
}
|
||
|
|
||
|
if (typeof console !== 'undefined') {
|
||
|
if (!Module['print']) Module['print'] = function print(x) {
|
||
|
console.log(x);
|
||
|
};
|
||
|
if (!Module['printErr']) Module['printErr'] = function printErr(x) {
|
||
|
console.log(x);
|
||
|
};
|
||
|
} else {
|
||
|
// Probably a worker, and without console.log. We can do very little here...
|
||
|
var TRY_USE_DUMP = false;
|
||
|
if (!Module['print']) Module['print'] = (TRY_USE_DUMP && (typeof(dump) !== "undefined") ? (function(x) {
|
||
|
dump(x);
|
||
|
}) : (function(x) {
|
||
|
// self.postMessage(x); // enable this if you want stdout to be sent as messages
|
||
|
}));
|
||
|
}
|
||
|
|
||
|
if (ENVIRONMENT_IS_WEB) {
|
||
|
window['Module'] = Module;
|
||
|
} else {
|
||
|
Module['load'] = importScripts;
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
// Unreachable because SHELL is dependant on the others
|
||
|
throw 'Unknown runtime environment. Where are we?';
|
||
|
}
|
||
|
|
||
|
function globalEval(x) {
|
||
|
eval.call(null, x);
|
||
|
}
|
||
|
if (!Module['load'] == 'undefined' && Module['read']) {
|
||
|
Module['load'] = function load(f) {
|
||
|
globalEval(Module['read'](f));
|
||
|
};
|
||
|
}
|
||
|
if (!Module['print']) {
|
||
|
Module['print'] = function(){};
|
||
|
}
|
||
|
if (!Module['printErr']) {
|
||
|
Module['printErr'] = Module['print'];
|
||
|
}
|
||
|
if (!Module['arguments']) {
|
||
|
Module['arguments'] = [];
|
||
|
}
|
||
|
// *** Environment setup code ***
|
||
|
|
||
|
// Closure helpers
|
||
|
Module.print = Module['print'];
|
||
|
Module.printErr = Module['printErr'];
|
||
|
|
||
|
// Callbacks
|
||
|
Module['preRun'] = [];
|
||
|
Module['postRun'] = [];
|
||
|
|
||
|
// Merge back in the overrides
|
||
|
for (var key in moduleOverrides) {
|
||
|
if (moduleOverrides.hasOwnProperty(key)) {
|
||
|
Module[key] = moduleOverrides[key];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
// === Auto-generated preamble library stuff ===
|
||
|
|
||
|
//========================================
|
||
|
// Runtime code shared with compiler
|
||
|
//========================================
|
||
|
|
||
|
var Runtime = {
|
||
|
setTempRet0: function (value) {
|
||
|
tempRet0 = value;
|
||
|
},
|
||
|
getTempRet0: function () {
|
||
|
return tempRet0;
|
||
|
},
|
||
|
stackSave: function () {
|
||
|
return STACKTOP;
|
||
|
},
|
||
|
stackRestore: function (stackTop) {
|
||
|
STACKTOP = stackTop;
|
||
|
},
|
||
|
forceAlign: function (target, quantum) {
|
||
|
quantum = quantum || 4;
|
||
|
if (quantum == 1) return target;
|
||
|
if (isNumber(target) && isNumber(quantum)) {
|
||
|
return Math.ceil(target/quantum)*quantum;
|
||
|
} else if (isNumber(quantum) && isPowerOfTwo(quantum)) {
|
||
|
return '(((' +target + ')+' + (quantum-1) + ')&' + -quantum + ')';
|
||
|
}
|
||
|
return 'Math.ceil((' + target + ')/' + quantum + ')*' + quantum;
|
||
|
},
|
||
|
isNumberType: function (type) {
|
||
|
return type in Runtime.INT_TYPES || type in Runtime.FLOAT_TYPES;
|
||
|
},
|
||
|
isPointerType: function isPointerType(type) {
|
||
|
return type[type.length-1] == '*';
|
||
|
},
|
||
|
isStructType: function isStructType(type) {
|
||
|
if (isPointerType(type)) return false;
|
||
|
if (isArrayType(type)) return true;
|
||
|
if (/<?\{ ?[^}]* ?\}>?/.test(type)) return true; // { i32, i8 } etc. - anonymous struct types
|
||
|
// See comment in isStructPointerType()
|
||
|
return type[0] == '%';
|
||
|
},
|
||
|
INT_TYPES: {"i1":0,"i8":0,"i16":0,"i32":0,"i64":0},
|
||
|
FLOAT_TYPES: {"float":0,"double":0},
|
||
|
or64: function (x, y) {
|
||
|
var l = (x | 0) | (y | 0);
|
||
|
var h = (Math.round(x / 4294967296) | Math.round(y / 4294967296)) * 4294967296;
|
||
|
return l + h;
|
||
|
},
|
||
|
and64: function (x, y) {
|
||
|
var l = (x | 0) & (y | 0);
|
||
|
var h = (Math.round(x / 4294967296) & Math.round(y / 4294967296)) * 4294967296;
|
||
|
return l + h;
|
||
|
},
|
||
|
xor64: function (x, y) {
|
||
|
var l = (x | 0) ^ (y | 0);
|
||
|
var h = (Math.round(x / 4294967296) ^ Math.round(y / 4294967296)) * 4294967296;
|
||
|
return l + h;
|
||
|
},
|
||
|
getNativeTypeSize: function (type) {
|
||
|
switch (type) {
|
||
|
case 'i1': case 'i8': return 1;
|
||
|
case 'i16': return 2;
|
||
|
case 'i32': return 4;
|
||
|
case 'i64': return 8;
|
||
|
case 'float': return 4;
|
||
|
case 'double': return 8;
|
||
|
default: {
|
||
|
if (type[type.length-1] === '*') {
|
||
|
return Runtime.QUANTUM_SIZE; // A pointer
|
||
|
} else if (type[0] === 'i') {
|
||
|
var bits = parseInt(type.substr(1));
|
||
|
assert(bits % 8 === 0);
|
||
|
return bits/8;
|
||
|
} else {
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
getNativeFieldSize: function (type) {
|
||
|
return Math.max(Runtime.getNativeTypeSize(type), Runtime.QUANTUM_SIZE);
|
||
|
},
|
||
|
dedup: function dedup(items, ident) {
|
||
|
var seen = {};
|
||
|
if (ident) {
|
||
|
return items.filter(function(item) {
|
||
|
if (seen[item[ident]]) return false;
|
||
|
seen[item[ident]] = true;
|
||
|
return true;
|
||
|
});
|
||
|
} else {
|
||
|
return items.filter(function(item) {
|
||
|
if (seen[item]) return false;
|
||
|
seen[item] = true;
|
||
|
return true;
|
||
|
});
|
||
|
}
|
||
|
},
|
||
|
set: function set() {
|
||
|
var args = typeof arguments[0] === 'object' ? arguments[0] : arguments;
|
||
|
var ret = {};
|
||
|
for (var i = 0; i < args.length; i++) {
|
||
|
ret[args[i]] = 0;
|
||
|
}
|
||
|
return ret;
|
||
|
},
|
||
|
STACK_ALIGN: 8,
|
||
|
getAlignSize: function (type, size, vararg) {
|
||
|
// we align i64s and doubles on 64-bit boundaries, unlike x86
|
||
|
if (!vararg && (type == 'i64' || type == 'double')) return 8;
|
||
|
if (!type) return Math.min(size, 8); // align structures internally to 64 bits
|
||
|
return Math.min(size || (type ? Runtime.getNativeFieldSize(type) : 0), Runtime.QUANTUM_SIZE);
|
||
|
},
|
||
|
calculateStructAlignment: function calculateStructAlignment(type) {
|
||
|
type.flatSize = 0;
|
||
|
type.alignSize = 0;
|
||
|
var diffs = [];
|
||
|
var prev = -1;
|
||
|
var index = 0;
|
||
|
type.flatIndexes = type.fields.map(function(field) {
|
||
|
index++;
|
||
|
var size, alignSize;
|
||
|
if (Runtime.isNumberType(field) || Runtime.isPointerType(field)) {
|
||
|
size = Runtime.getNativeTypeSize(field); // pack char; char; in structs, also char[X]s.
|
||
|
alignSize = Runtime.getAlignSize(field, size);
|
||
|
} else if (Runtime.isStructType(field)) {
|
||
|
if (field[1] === '0') {
|
||
|
// this is [0 x something]. When inside another structure like here, it must be at the end,
|
||
|
// and it adds no size
|
||
|
// XXX this happens in java-nbody for example... assert(index === type.fields.length, 'zero-length in the middle!');
|
||
|
size = 0;
|
||
|
if (Types.types[field]) {
|
||
|
alignSize = Runtime.getAlignSize(null, Types.types[field].alignSize);
|
||
|
} else {
|
||
|
alignSize = type.alignSize || QUANTUM_SIZE;
|
||
|
}
|
||
|
} else {
|
||
|
size = Types.types[field].flatSize;
|
||
|
alignSize = Runtime.getAlignSize(null, Types.types[field].alignSize);
|
||
|
}
|
||
|
} else if (field[0] == 'b') {
|
||
|
// bN, large number field, like a [N x i8]
|
||
|
size = field.substr(1)|0;
|
||
|
alignSize = 1;
|
||
|
} else if (field[0] === '<') {
|
||
|
// vector type
|
||
|
size = alignSize = Types.types[field].flatSize; // fully aligned
|
||
|
} else if (field[0] === 'i') {
|
||
|
// illegal integer field, that could not be legalized because it is an internal structure field
|
||
|
// it is ok to have such fields, if we just use them as markers of field size and nothing more complex
|
||
|
size = alignSize = parseInt(field.substr(1))/8;
|
||
|
assert(size % 1 === 0, 'cannot handle non-byte-size field ' + field);
|
||
|
} else {
|
||
|
assert(false, 'invalid type for calculateStructAlignment');
|
||
|
}
|
||
|
if (type.packed) alignSize = 1;
|
||
|
type.alignSize = Math.max(type.alignSize, alignSize);
|
||
|
var curr = Runtime.alignMemory(type.flatSize, alignSize); // if necessary, place this on aligned memory
|
||
|
type.flatSize = curr + size;
|
||
|
if (prev >= 0) {
|
||
|
diffs.push(curr-prev);
|
||
|
}
|
||
|
prev = curr;
|
||
|
return curr;
|
||
|
});
|
||
|
if (type.name_ && type.name_[0] === '[') {
|
||
|
// arrays have 2 elements, so we get the proper difference. then we scale here. that way we avoid
|
||
|
// allocating a potentially huge array for [999999 x i8] etc.
|
||
|
type.flatSize = parseInt(type.name_.substr(1))*type.flatSize/2;
|
||
|
}
|
||
|
type.flatSize = Runtime.alignMemory(type.flatSize, type.alignSize);
|
||
|
if (diffs.length == 0) {
|
||
|
type.flatFactor = type.flatSize;
|
||
|
} else if (Runtime.dedup(diffs).length == 1) {
|
||
|
type.flatFactor = diffs[0];
|
||
|
}
|
||
|
type.needsFlattening = (type.flatFactor != 1);
|
||
|
return type.flatIndexes;
|
||
|
},
|
||
|
generateStructInfo: function (struct, typeName, offset) {
|
||
|
var type, alignment;
|
||
|
if (typeName) {
|
||
|
offset = offset || 0;
|
||
|
type = (typeof Types === 'undefined' ? Runtime.typeInfo : Types.types)[typeName];
|
||
|
if (!type) return null;
|
||
|
if (type.fields.length != struct.length) {
|
||
|
printErr('Number of named fields must match the type for ' + typeName + ': possibly duplicate struct names. Cannot return structInfo');
|
||
|
return null;
|
||
|
}
|
||
|
alignment = type.flatIndexes;
|
||
|
} else {
|
||
|
var type = { fields: struct.map(function(item) { return item[0] }) };
|
||
|
alignment = Runtime.calculateStructAlignment(type);
|
||
|
}
|
||
|
var ret = {
|
||
|
__size__: type.flatSize
|
||
|
};
|
||
|
if (typeName) {
|
||
|
struct.forEach(function(item, i) {
|
||
|
if (typeof item === 'string') {
|
||
|
ret[item] = alignment[i] + offset;
|
||
|
} else {
|
||
|
// embedded struct
|
||
|
var key;
|
||
|
for (var k in item) key = k;
|
||
|
ret[key] = Runtime.generateStructInfo(item[key], type.fields[i], alignment[i]);
|
||
|
}
|
||
|
});
|
||
|
} else {
|
||
|
struct.forEach(function(item, i) {
|
||
|
ret[item[1]] = alignment[i];
|
||
|
});
|
||
|
}
|
||
|
return ret;
|
||
|
},
|
||
|
dynCall: function (sig, ptr, args) {
|
||
|
if (args && args.length) {
|
||
|
if (!args.splice) args = Array.prototype.slice.call(args);
|
||
|
args.splice(0, 0, ptr);
|
||
|
return Module['dynCall_' + sig].apply(null, args);
|
||
|
} else {
|
||
|
return Module['dynCall_' + sig].call(null, ptr);
|
||
|
}
|
||
|
},
|
||
|
functionPointers: [],
|
||
|
addFunction: function (func) {
|
||
|
for (var i = 0; i < Runtime.functionPointers.length; i++) {
|
||
|
if (!Runtime.functionPointers[i]) {
|
||
|
Runtime.functionPointers[i] = func;
|
||
|
return 2*(1 + i);
|
||
|
}
|
||
|
}
|
||
|
throw 'Finished up all reserved function pointers. Use a higher value for RESERVED_FUNCTION_POINTERS.';
|
||
|
},
|
||
|
removeFunction: function (index) {
|
||
|
Runtime.functionPointers[(index-2)/2] = null;
|
||
|
},
|
||
|
getAsmConst: function (code, numArgs) {
|
||
|
// code is a constant string on the heap, so we can cache these
|
||
|
if (!Runtime.asmConstCache) Runtime.asmConstCache = {};
|
||
|
var func = Runtime.asmConstCache[code];
|
||
|
if (func) return func;
|
||
|
var args = [];
|
||
|
for (var i = 0; i < numArgs; i++) {
|
||
|
args.push(String.fromCharCode(36) + i); // $0, $1 etc
|
||
|
}
|
||
|
var source = Pointer_stringify(code);
|
||
|
if (source[0] === '"') {
|
||
|
// tolerate EM_ASM("..code..") even though EM_ASM(..code..) is correct
|
||
|
if (source.indexOf('"', 1) === source.length-1) {
|
||
|
source = source.substr(1, source.length-2);
|
||
|
} else {
|
||
|
// something invalid happened, e.g. EM_ASM("..code($0)..", input)
|
||
|
abort('invalid EM_ASM input |' + source + '|. Please use EM_ASM(..code..) (no quotes) or EM_ASM({ ..code($0).. }, input) (to input values)');
|
||
|
}
|
||
|
}
|
||
|
try {
|
||
|
var evalled = eval('(function(' + args.join(',') + '){ ' + source + ' })'); // new Function does not allow upvars in node
|
||
|
} catch(e) {
|
||
|
Module.printErr('error in executing inline EM_ASM code: ' + e + ' on: \n\n' + source + '\n\nwith args |' + args + '| (make sure to use the right one out of EM_ASM, EM_ASM_ARGS, etc.)');
|
||
|
throw e;
|
||
|
}
|
||
|
return Runtime.asmConstCache[code] = evalled;
|
||
|
},
|
||
|
warnOnce: function (text) {
|
||
|
if (!Runtime.warnOnce.shown) Runtime.warnOnce.shown = {};
|
||
|
if (!Runtime.warnOnce.shown[text]) {
|
||
|
Runtime.warnOnce.shown[text] = 1;
|
||
|
Module.printErr(text);
|
||
|
}
|
||
|
},
|
||
|
funcWrappers: {},
|
||
|
getFuncWrapper: function (func, sig) {
|
||
|
assert(sig);
|
||
|
if (!Runtime.funcWrappers[func]) {
|
||
|
Runtime.funcWrappers[func] = function dynCall_wrapper() {
|
||
|
return Runtime.dynCall(sig, func, arguments);
|
||
|
};
|
||
|
}
|
||
|
return Runtime.funcWrappers[func];
|
||
|
},
|
||
|
UTF8Processor: function () {
|
||
|
var buffer = [];
|
||
|
var needed = 0;
|
||
|
this.processCChar = function (code) {
|
||
|
code = code & 0xFF;
|
||
|
|
||
|
if (buffer.length == 0) {
|
||
|
if ((code & 0x80) == 0x00) { // 0xxxxxxx
|
||
|
return String.fromCharCode(code);
|
||
|
}
|
||
|
buffer.push(code);
|
||
|
if ((code & 0xE0) == 0xC0) { // 110xxxxx
|
||
|
needed = 1;
|
||
|
} else if ((code & 0xF0) == 0xE0) { // 1110xxxx
|
||
|
needed = 2;
|
||
|
} else { // 11110xxx
|
||
|
needed = 3;
|
||
|
}
|
||
|
return '';
|
||
|
}
|
||
|
|
||
|
if (needed) {
|
||
|
buffer.push(code);
|
||
|
needed--;
|
||
|
if (needed > 0) return '';
|
||
|
}
|
||
|
|
||
|
var c1 = buffer[0];
|
||
|
var c2 = buffer[1];
|
||
|
var c3 = buffer[2];
|
||
|
var c4 = buffer[3];
|
||
|
var ret;
|
||
|
if (buffer.length == 2) {
|
||
|
ret = String.fromCharCode(((c1 & 0x1F) << 6) | (c2 & 0x3F));
|
||
|
} else if (buffer.length == 3) {
|
||
|
ret = String.fromCharCode(((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F));
|
||
|
} else {
|
||
|
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
||
|
var codePoint = ((c1 & 0x07) << 18) | ((c2 & 0x3F) << 12) |
|
||
|
((c3 & 0x3F) << 6) | (c4 & 0x3F);
|
||
|
ret = String.fromCharCode(
|
||
|
Math.floor((codePoint - 0x10000) / 0x400) + 0xD800,
|
||
|
(codePoint - 0x10000) % 0x400 + 0xDC00);
|
||
|
}
|
||
|
buffer.length = 0;
|
||
|
return ret;
|
||
|
}
|
||
|
this.processJSString = function processJSString(string) {
|
||
|
/* TODO: use TextEncoder when present,
|
||
|
var encoder = new TextEncoder();
|
||
|
encoder['encoding'] = "utf-8";
|
||
|
var utf8Array = encoder['encode'](aMsg.data);
|
||
|
*/
|
||
|
string = unescape(encodeURIComponent(string));
|
||
|
var ret = [];
|
||
|
for (var i = 0; i < string.length; i++) {
|
||
|
ret.push(string.charCodeAt(i));
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
},
|
||
|
getCompilerSetting: function (name) {
|
||
|
throw 'You must build with -s RETAIN_COMPILER_SETTINGS=1 for Runtime.getCompilerSetting or emscripten_get_compiler_setting to work';
|
||
|
},
|
||
|
stackAlloc: function (size) { var ret = STACKTOP;STACKTOP = (STACKTOP + size)|0;STACKTOP = (((STACKTOP)+7)&-8); return ret; },
|
||
|
staticAlloc: function (size) { var ret = STATICTOP;STATICTOP = (STATICTOP + size)|0;STATICTOP = (((STATICTOP)+7)&-8); return ret; },
|
||
|
dynamicAlloc: function (size) { var ret = DYNAMICTOP;DYNAMICTOP = (DYNAMICTOP + size)|0;DYNAMICTOP = (((DYNAMICTOP)+7)&-8); if (DYNAMICTOP >= TOTAL_MEMORY) enlargeMemory();; return ret; },
|
||
|
alignMemory: function (size,quantum) { var ret = size = Math.ceil((size)/(quantum ? quantum : 8))*(quantum ? quantum : 8); return ret; },
|
||
|
makeBigInt: function (low,high,unsigned) { var ret = (unsigned ? ((+((low>>>0)))+((+((high>>>0)))*(+4294967296))) : ((+((low>>>0)))+((+((high|0)))*(+4294967296)))); return ret; },
|
||
|
GLOBAL_BASE: 8,
|
||
|
QUANTUM_SIZE: 4,
|
||
|
__dummy__: 0
|
||
|
}
|
||
|
|
||
|
|
||
|
Module['Runtime'] = Runtime;
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//========================================
|
||
|
// Runtime essentials
|
||
|
//========================================
|
||
|
|
||
|
var __THREW__ = 0; // Used in checking for thrown exceptions.
|
||
|
|
||
|
var ABORT = false; // whether we are quitting the application. no code should run after this. set in exit() and abort()
|
||
|
var EXITSTATUS = 0;
|
||
|
|
||
|
var undef = 0;
|
||
|
// tempInt is used for 32-bit signed values or smaller. tempBigInt is used
|
||
|
// for 32-bit unsigned values or more than 32 bits. TODO: audit all uses of tempInt
|
||
|
var tempValue, tempInt, tempBigInt, tempInt2, tempBigInt2, tempPair, tempBigIntI, tempBigIntR, tempBigIntS, tempBigIntP, tempBigIntD, tempDouble, tempFloat;
|
||
|
var tempI64, tempI64b;
|
||
|
var tempRet0, tempRet1, tempRet2, tempRet3, tempRet4, tempRet5, tempRet6, tempRet7, tempRet8, tempRet9;
|
||
|
|
||
|
function assert(condition, text) {
|
||
|
if (!condition) {
|
||
|
abort('Assertion failed: ' + text);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var globalScope = this;
|
||
|
|
||
|
// C calling interface. A convenient way to call C functions (in C files, or
|
||
|
// defined with extern "C").
|
||
|
//
|
||
|
// Note: LLVM optimizations can inline and remove functions, after which you will not be
|
||
|
// able to call them. Closure can also do so. To avoid that, add your function to
|
||
|
// the exports using something like
|
||
|
//
|
||
|
// -s EXPORTED_FUNCTIONS='["_main", "_myfunc"]'
|
||
|
//
|
||
|
// @param ident The name of the C function (note that C++ functions will be name-mangled - use extern "C")
|
||
|
// @param returnType The return type of the function, one of the JS types 'number', 'string' or 'array' (use 'number' for any C pointer, and
|
||
|
// 'array' for JavaScript arrays and typed arrays; note that arrays are 8-bit).
|
||
|
// @param argTypes An array of the types of arguments for the function (if there are no arguments, this can be ommitted). Types are as in returnType,
|
||
|
// except that 'array' is not possible (there is no way for us to know the length of the array)
|
||
|
// @param args An array of the arguments to the function, as native JS values (as in returnType)
|
||
|
// Note that string arguments will be stored on the stack (the JS string will become a C string on the stack).
|
||
|
// @return The return value, as a native JS value (as in returnType)
|
||
|
function ccall(ident, returnType, argTypes, args) {
|
||
|
return ccallFunc(getCFunc(ident), returnType, argTypes, args);
|
||
|
}
|
||
|
Module["ccall"] = ccall;
|
||
|
|
||
|
// Returns the C function with a specified identifier (for C++, you need to do manual name mangling)
|
||
|
function getCFunc(ident) {
|
||
|
try {
|
||
|
var func = Module['_' + ident]; // closure exported function
|
||
|
if (!func) func = eval('_' + ident); // explicit lookup
|
||
|
} catch(e) {
|
||
|
}
|
||
|
assert(func, 'Cannot call unknown function ' + ident + ' (perhaps LLVM optimizations or closure removed it?)');
|
||
|
return func;
|
||
|
}
|
||
|
|
||
|
// Internal function that does a C call using a function, not an identifier
|
||
|
function ccallFunc(func, returnType, argTypes, args) {
|
||
|
var stack = 0;
|
||
|
function toC(value, type) {
|
||
|
if (type == 'string') {
|
||
|
if (value === null || value === undefined || value === 0) return 0; // null string
|
||
|
value = intArrayFromString(value);
|
||
|
type = 'array';
|
||
|
}
|
||
|
if (type == 'array') {
|
||
|
if (!stack) stack = Runtime.stackSave();
|
||
|
var ret = Runtime.stackAlloc(value.length);
|
||
|
writeArrayToMemory(value, ret);
|
||
|
return ret;
|
||
|
}
|
||
|
return value;
|
||
|
}
|
||
|
function fromC(value, type) {
|
||
|
if (type == 'string') {
|
||
|
return Pointer_stringify(value);
|
||
|
}
|
||
|
assert(type != 'array');
|
||
|
return value;
|
||
|
}
|
||
|
var i = 0;
|
||
|
var cArgs = args ? args.map(function(arg) {
|
||
|
return toC(arg, argTypes[i++]);
|
||
|
}) : [];
|
||
|
var ret = fromC(func.apply(null, cArgs), returnType);
|
||
|
if (stack) Runtime.stackRestore(stack);
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
// Returns a native JS wrapper for a C function. This is similar to ccall, but
|
||
|
// returns a function you can call repeatedly in a normal way. For example:
|
||
|
//
|
||
|
// var my_function = cwrap('my_c_function', 'number', ['number', 'number']);
|
||
|
// alert(my_function(5, 22));
|
||
|
// alert(my_function(99, 12));
|
||
|
//
|
||
|
function cwrap(ident, returnType, argTypes) {
|
||
|
var func = getCFunc(ident);
|
||
|
return function() {
|
||
|
return ccallFunc(func, returnType, argTypes, Array.prototype.slice.call(arguments));
|
||
|
}
|
||
|
}
|
||
|
Module["cwrap"] = cwrap;
|
||
|
|
||
|
// Sets a value in memory in a dynamic way at run-time. Uses the
|
||
|
// type data. This is the same as makeSetValue, except that
|
||
|
// makeSetValue is done at compile-time and generates the needed
|
||
|
// code then, whereas this function picks the right code at
|
||
|
// run-time.
|
||
|
// Note that setValue and getValue only do *aligned* writes and reads!
|
||
|
// Note that ccall uses JS types as for defining types, while setValue and
|
||
|
// getValue need LLVM types ('i8', 'i32') - this is a lower-level operation
|
||
|
function setValue(ptr, value, type, noSafe) {
|
||
|
type = type || 'i8';
|
||
|
if (type.charAt(type.length-1) === '*') type = 'i32'; // pointers are 32-bit
|
||
|
switch(type) {
|
||
|
case 'i1': HEAP8[((ptr)>>0)]=value; break;
|
||
|
case 'i8': HEAP8[((ptr)>>0)]=value; break;
|
||
|
case 'i16': HEAP16[((ptr)>>1)]=value; break;
|
||
|
case 'i32': HEAP32[((ptr)>>2)]=value; break;
|
||
|
case 'i64': (tempI64 = [value>>>0,(tempDouble=value,(+(Math_abs(tempDouble))) >= (+1) ? (tempDouble > (+0) ? ((Math_min((+(Math_floor((tempDouble)/(+4294967296)))), (+4294967295)))|0)>>>0 : (~~((+(Math_ceil((tempDouble - +(((~~(tempDouble)))>>>0))/(+4294967296))))))>>>0) : 0)],HEAP32[((ptr)>>2)]=tempI64[0],HEAP32[(((ptr)+(4))>>2)]=tempI64[1]); break;
|
||
|
case 'float': HEAPF32[((ptr)>>2)]=value; break;
|
||
|
case 'double': HEAPF64[((ptr)>>3)]=value; break;
|
||
|
default: abort('invalid type for setValue: ' + type);
|
||
|
}
|
||
|
}
|
||
|
Module['setValue'] = setValue;
|
||
|
|
||
|
// Parallel to setValue.
|
||
|
function getValue(ptr, type, noSafe) {
|
||
|
type = type || 'i8';
|
||
|
if (type.charAt(type.length-1) === '*') type = 'i32'; // pointers are 32-bit
|
||
|
switch(type) {
|
||
|
case 'i1': return HEAP8[((ptr)>>0)];
|
||
|
case 'i8': return HEAP8[((ptr)>>0)];
|
||
|
case 'i16': return HEAP16[((ptr)>>1)];
|
||
|
case 'i32': return HEAP32[((ptr)>>2)];
|
||
|
case 'i64': return HEAP32[((ptr)>>2)];
|
||
|
case 'float': return HEAPF32[((ptr)>>2)];
|
||
|
case 'double': return HEAPF64[((ptr)>>3)];
|
||
|
default: abort('invalid type for setValue: ' + type);
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
Module['getValue'] = getValue;
|
||
|
|
||
|
var ALLOC_NORMAL = 0; // Tries to use _malloc()
|
||
|
var ALLOC_STACK = 1; // Lives for the duration of the current function call
|
||
|
var ALLOC_STATIC = 2; // Cannot be freed
|
||
|
var ALLOC_DYNAMIC = 3; // Cannot be freed except through sbrk
|
||
|
var ALLOC_NONE = 4; // Do not allocate
|
||
|
Module['ALLOC_NORMAL'] = ALLOC_NORMAL;
|
||
|
Module['ALLOC_STACK'] = ALLOC_STACK;
|
||
|
Module['ALLOC_STATIC'] = ALLOC_STATIC;
|
||
|
Module['ALLOC_DYNAMIC'] = ALLOC_DYNAMIC;
|
||
|
Module['ALLOC_NONE'] = ALLOC_NONE;
|
||
|
|
||
|
// allocate(): This is for internal use. You can use it yourself as well, but the interface
|
||
|
// is a little tricky (see docs right below). The reason is that it is optimized
|
||
|
// for multiple syntaxes to save space in generated code. So you should
|
||
|
// normally not use allocate(), and instead allocate memory using _malloc(),
|
||
|
// initialize it with setValue(), and so forth.
|
||
|
// @slab: An array of data, or a number. If a number, then the size of the block to allocate,
|
||
|
// in *bytes* (note that this is sometimes confusing: the next parameter does not
|
||
|
// affect this!)
|
||
|
// @types: Either an array of types, one for each byte (or 0 if no type at that position),
|
||
|
// or a single type which is used for the entire block. This only matters if there
|
||
|
// is initial data - if @slab is a number, then this does not matter at all and is
|
||
|
// ignored.
|
||
|
// @allocator: How to allocate memory, see ALLOC_*
|
||
|
function allocate(slab, types, allocator, ptr) {
|
||
|
var zeroinit, size;
|
||
|
if (typeof slab === 'number') {
|
||
|
zeroinit = true;
|
||
|
size = slab;
|
||
|
} else {
|
||
|
zeroinit = false;
|
||
|
size = slab.length;
|
||
|
}
|
||
|
|
||
|
var singleType = typeof types === 'string' ? types : null;
|
||
|
|
||
|
var ret;
|
||
|
if (allocator == ALLOC_NONE) {
|
||
|
ret = ptr;
|
||
|
} else {
|
||
|
ret = [_malloc, Runtime.stackAlloc, Runtime.staticAlloc, Runtime.dynamicAlloc][allocator === undefined ? ALLOC_STATIC : allocator](Math.max(size, singleType ? 1 : types.length));
|
||
|
}
|
||
|
|
||
|
if (zeroinit) {
|
||
|
var ptr = ret, stop;
|
||
|
assert((ret & 3) == 0);
|
||
|
stop = ret + (size & ~3);
|
||
|
for (; ptr < stop; ptr += 4) {
|
||
|
HEAP32[((ptr)>>2)]=0;
|
||
|
}
|
||
|
stop = ret + size;
|
||
|
while (ptr < stop) {
|
||
|
HEAP8[((ptr++)>>0)]=0;
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
if (singleType === 'i8') {
|
||
|
if (slab.subarray || slab.slice) {
|
||
|
HEAPU8.set(slab, ret);
|
||
|
} else {
|
||
|
HEAPU8.set(new Uint8Array(slab), ret);
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
var i = 0, type, typeSize, previousType;
|
||
|
while (i < size) {
|
||
|
var curr = slab[i];
|
||
|
|
||
|
if (typeof curr === 'function') {
|
||
|
curr = Runtime.getFunctionIndex(curr);
|
||
|
}
|
||
|
|
||
|
type = singleType || types[i];
|
||
|
if (type === 0) {
|
||
|
i++;
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
if (type == 'i64') type = 'i32'; // special case: we have one i32 here, and one i32 later
|
||
|
|
||
|
setValue(ret+i, curr, type);
|
||
|
|
||
|
// no need to look up size unless type changes, so cache it
|
||
|
if (previousType !== type) {
|
||
|
typeSize = Runtime.getNativeTypeSize(type);
|
||
|
previousType = type;
|
||
|
}
|
||
|
i += typeSize;
|
||
|
}
|
||
|
|
||
|
return ret;
|
||
|
}
|
||
|
Module['allocate'] = allocate;
|
||
|
|
||
|
function Pointer_stringify(ptr, /* optional */ length) {
|
||
|
// TODO: use TextDecoder
|
||
|
// Find the length, and check for UTF while doing so
|
||
|
var hasUtf = false;
|
||
|
var t;
|
||
|
var i = 0;
|
||
|
while (1) {
|
||
|
t = HEAPU8[(((ptr)+(i))>>0)];
|
||
|
if (t >= 128) hasUtf = true;
|
||
|
else if (t == 0 && !length) break;
|
||
|
i++;
|
||
|
if (length && i == length) break;
|
||
|
}
|
||
|
if (!length) length = i;
|
||
|
|
||
|
var ret = '';
|
||
|
|
||
|
if (!hasUtf) {
|
||
|
var MAX_CHUNK = 1024; // split up into chunks, because .apply on a huge string can overflow the stack
|
||
|
var curr;
|
||
|
while (length > 0) {
|
||
|
curr = String.fromCharCode.apply(String, HEAPU8.subarray(ptr, ptr + Math.min(length, MAX_CHUNK)));
|
||
|
ret = ret ? ret + curr : curr;
|
||
|
ptr += MAX_CHUNK;
|
||
|
length -= MAX_CHUNK;
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
var utf8 = new Runtime.UTF8Processor();
|
||
|
for (i = 0; i < length; i++) {
|
||
|
t = HEAPU8[(((ptr)+(i))>>0)];
|
||
|
ret += utf8.processCChar(t);
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
Module['Pointer_stringify'] = Pointer_stringify;
|
||
|
|
||
|
// Given a pointer 'ptr' to a null-terminated UTF16LE-encoded string in the emscripten HEAP, returns
|
||
|
// a copy of that string as a Javascript String object.
|
||
|
function UTF16ToString(ptr) {
|
||
|
var i = 0;
|
||
|
|
||
|
var str = '';
|
||
|
while (1) {
|
||
|
var codeUnit = HEAP16[(((ptr)+(i*2))>>1)];
|
||
|
if (codeUnit == 0)
|
||
|
return str;
|
||
|
++i;
|
||
|
// fromCharCode constructs a character from a UTF-16 code unit, so we can pass the UTF16 string right through.
|
||
|
str += String.fromCharCode(codeUnit);
|
||
|
}
|
||
|
}
|
||
|
Module['UTF16ToString'] = UTF16ToString;
|
||
|
|
||
|
// Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
|
||
|
// null-terminated and encoded in UTF16LE form. The copy will require at most (str.length*2+1)*2 bytes of space in the HEAP.
|
||
|
function stringToUTF16(str, outPtr) {
|
||
|
for(var i = 0; i < str.length; ++i) {
|
||
|
// charCodeAt returns a UTF-16 encoded code unit, so it can be directly written to the HEAP.
|
||
|
var codeUnit = str.charCodeAt(i); // possibly a lead surrogate
|
||
|
HEAP16[(((outPtr)+(i*2))>>1)]=codeUnit;
|
||
|
}
|
||
|
// Null-terminate the pointer to the HEAP.
|
||
|
HEAP16[(((outPtr)+(str.length*2))>>1)]=0;
|
||
|
}
|
||
|
Module['stringToUTF16'] = stringToUTF16;
|
||
|
|
||
|
// Given a pointer 'ptr' to a null-terminated UTF32LE-encoded string in the emscripten HEAP, returns
|
||
|
// a copy of that string as a Javascript String object.
|
||
|
function UTF32ToString(ptr) {
|
||
|
var i = 0;
|
||
|
|
||
|
var str = '';
|
||
|
while (1) {
|
||
|
var utf32 = HEAP32[(((ptr)+(i*4))>>2)];
|
||
|
if (utf32 == 0)
|
||
|
return str;
|
||
|
++i;
|
||
|
// Gotcha: fromCharCode constructs a character from a UTF-16 encoded code (pair), not from a Unicode code point! So encode the code point to UTF-16 for constructing.
|
||
|
if (utf32 >= 0x10000) {
|
||
|
var ch = utf32 - 0x10000;
|
||
|
str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
|
||
|
} else {
|
||
|
str += String.fromCharCode(utf32);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
Module['UTF32ToString'] = UTF32ToString;
|
||
|
|
||
|
// Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
|
||
|
// null-terminated and encoded in UTF32LE form. The copy will require at most (str.length+1)*4 bytes of space in the HEAP,
|
||
|
// but can use less, since str.length does not return the number of characters in the string, but the number of UTF-16 code units in the string.
|
||
|
function stringToUTF32(str, outPtr) {
|
||
|
var iChar = 0;
|
||
|
for(var iCodeUnit = 0; iCodeUnit < str.length; ++iCodeUnit) {
|
||
|
// Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! We must decode the string to UTF-32 to the heap.
|
||
|
var codeUnit = str.charCodeAt(iCodeUnit); // possibly a lead surrogate
|
||
|
if (codeUnit >= 0xD800 && codeUnit <= 0xDFFF) {
|
||
|
var trailSurrogate = str.charCodeAt(++iCodeUnit);
|
||
|
codeUnit = 0x10000 + ((codeUnit & 0x3FF) << 10) | (trailSurrogate & 0x3FF);
|
||
|
}
|
||
|
HEAP32[(((outPtr)+(iChar*4))>>2)]=codeUnit;
|
||
|
++iChar;
|
||
|
}
|
||
|
// Null-terminate the pointer to the HEAP.
|
||
|
HEAP32[(((outPtr)+(iChar*4))>>2)]=0;
|
||
|
}
|
||
|
Module['stringToUTF32'] = stringToUTF32;
|
||
|
|
||
|
function demangle(func) {
|
||
|
var i = 3;
|
||
|
// params, etc.
|
||
|
var basicTypes = {
|
||
|
'v': 'void',
|
||
|
'b': 'bool',
|
||
|
'c': 'char',
|
||
|
's': 'short',
|
||
|
'i': 'int',
|
||
|
'l': 'long',
|
||
|
'f': 'float',
|
||
|
'd': 'double',
|
||
|
'w': 'wchar_t',
|
||
|
'a': 'signed char',
|
||
|
'h': 'unsigned char',
|
||
|
't': 'unsigned short',
|
||
|
'j': 'unsigned int',
|
||
|
'm': 'unsigned long',
|
||
|
'x': 'long long',
|
||
|
'y': 'unsigned long long',
|
||
|
'z': '...'
|
||
|
};
|
||
|
var subs = [];
|
||
|
var first = true;
|
||
|
function dump(x) {
|
||
|
//return;
|
||
|
if (x) Module.print(x);
|
||
|
Module.print(func);
|
||
|
var pre = '';
|
||
|
for (var a = 0; a < i; a++) pre += ' ';
|
||
|
Module.print (pre + '^');
|
||
|
}
|
||
|
function parseNested() {
|
||
|
i++;
|
||
|
if (func[i] === 'K') i++; // ignore const
|
||
|
var parts = [];
|
||
|
while (func[i] !== 'E') {
|
||
|
if (func[i] === 'S') { // substitution
|
||
|
i++;
|
||
|
var next = func.indexOf('_', i);
|
||
|
var num = func.substring(i, next) || 0;
|
||
|
parts.push(subs[num] || '?');
|
||
|
i = next+1;
|
||
|
continue;
|
||
|
}
|
||
|
if (func[i] === 'C') { // constructor
|
||
|
parts.push(parts[parts.length-1]);
|
||
|
i += 2;
|
||
|
continue;
|
||
|
}
|
||
|
var size = parseInt(func.substr(i));
|
||
|
var pre = size.toString().length;
|
||
|
if (!size || !pre) { i--; break; } // counter i++ below us
|
||
|
var curr = func.substr(i + pre, size);
|
||
|
parts.push(curr);
|
||
|
subs.push(curr);
|
||
|
i += pre + size;
|
||
|
}
|
||
|
i++; // skip E
|
||
|
return parts;
|
||
|
}
|
||
|
function parse(rawList, limit, allowVoid) { // main parser
|
||
|
limit = limit || Infinity;
|
||
|
var ret = '', list = [];
|
||
|
function flushList() {
|
||
|
return '(' + list.join(', ') + ')';
|
||
|
}
|
||
|
var name;
|
||
|
if (func[i] === 'N') {
|
||
|
// namespaced N-E
|
||
|
name = parseNested().join('::');
|
||
|
limit--;
|
||
|
if (limit === 0) return rawList ? [name] : name;
|
||
|
} else {
|
||
|
// not namespaced
|
||
|
if (func[i] === 'K' || (first && func[i] === 'L')) i++; // ignore const and first 'L'
|
||
|
var size = parseInt(func.substr(i));
|
||
|
if (size) {
|
||
|
var pre = size.toString().length;
|
||
|
name = func.substr(i + pre, size);
|
||
|
i += pre + size;
|
||
|
}
|
||
|
}
|
||
|
first = false;
|
||
|
if (func[i] === 'I') {
|
||
|
i++;
|
||
|
var iList = parse(true);
|
||
|
var iRet = parse(true, 1, true);
|
||
|
ret += iRet[0] + ' ' + name + '<' + iList.join(', ') + '>';
|
||
|
} else {
|
||
|
ret = name;
|
||
|
}
|
||
|
paramLoop: while (i < func.length && limit-- > 0) {
|
||
|
//dump('paramLoop');
|
||
|
var c = func[i++];
|
||
|
if (c in basicTypes) {
|
||
|
list.push(basicTypes[c]);
|
||
|
} else {
|
||
|
switch (c) {
|
||
|
case 'P': list.push(parse(true, 1, true)[0] + '*'); break; // pointer
|
||
|
case 'R': list.push(parse(true, 1, true)[0] + '&'); break; // reference
|
||
|
case 'L': { // literal
|
||
|
i++; // skip basic type
|
||
|
var end = func.indexOf('E', i);
|
||
|
var size = end - i;
|
||
|
list.push(func.substr(i, size));
|
||
|
i += size + 2; // size + 'EE'
|
||
|
break;
|
||
|
}
|
||
|
case 'A': { // array
|
||
|
var size = parseInt(func.substr(i));
|
||
|
i += size.toString().length;
|
||
|
if (func[i] !== '_') throw '?';
|
||
|
i++; // skip _
|
||
|
list.push(parse(true, 1, true)[0] + ' [' + size + ']');
|
||
|
break;
|
||
|
}
|
||
|
case 'E': break paramLoop;
|
||
|
default: ret += '?' + c; break paramLoop;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if (!allowVoid && list.length === 1 && list[0] === 'void') list = []; // avoid (void)
|
||
|
if (rawList) {
|
||
|
if (ret) {
|
||
|
list.push(ret + '?');
|
||
|
}
|
||
|
return list;
|
||
|
} else {
|
||
|
return ret + flushList();
|
||
|
}
|
||
|
}
|
||
|
try {
|
||
|
// Special-case the entry point, since its name differs from other name mangling.
|
||
|
if (func == 'Object._main' || func == '_main') {
|
||
|
return 'main()';
|
||
|
}
|
||
|
if (typeof func === 'number') func = Pointer_stringify(func);
|
||
|
if (func[0] !== '_') return func;
|
||
|
if (func[1] !== '_') return func; // C function
|
||
|
if (func[2] !== 'Z') return func;
|
||
|
switch (func[3]) {
|
||
|
case 'n': return 'operator new()';
|
||
|
case 'd': return 'operator delete()';
|
||
|
}
|
||
|
return parse();
|
||
|
} catch(e) {
|
||
|
return func;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function demangleAll(text) {
|
||
|
return text.replace(/__Z[\w\d_]+/g, function(x) { var y = demangle(x); return x === y ? x : (x + ' [' + y + ']') });
|
||
|
}
|
||
|
|
||
|
function stackTrace() {
|
||
|
var stack = new Error().stack;
|
||
|
return stack ? demangleAll(stack) : '(no stack trace available)'; // Stack trace is not available at least on IE10 and Safari 6.
|
||
|
}
|
||
|
|
||
|
// Memory management
|
||
|
|
||
|
var PAGE_SIZE = 4096;
|
||
|
function alignMemoryPage(x) {
|
||
|
return (x+4095)&-4096;
|
||
|
}
|
||
|
|
||
|
var HEAP;
|
||
|
var HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64;
|
||
|
|
||
|
var STATIC_BASE = 0, STATICTOP = 0, staticSealed = false; // static area
|
||
|
var STACK_BASE = 0, STACKTOP = 0, STACK_MAX = 0; // stack area
|
||
|
var DYNAMIC_BASE = 0, DYNAMICTOP = 0; // dynamic area handled by sbrk
|
||
|
|
||
|
function enlargeMemory() {
|
||
|
abort('Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value ' + TOTAL_MEMORY + ', (2) compile with ALLOW_MEMORY_GROWTH which adjusts the size at runtime but prevents some optimizations, or (3) set Module.TOTAL_MEMORY before the program runs.');
|
||
|
}
|
||
|
|
||
|
var TOTAL_STACK = Module['TOTAL_STACK'] || 5242880;
|
||
|
var TOTAL_MEMORY = Module['TOTAL_MEMORY'] || 134217728;
|
||
|
var FAST_MEMORY = Module['FAST_MEMORY'] || 2097152;
|
||
|
|
||
|
var totalMemory = 4096;
|
||
|
while (totalMemory < TOTAL_MEMORY || totalMemory < 2*TOTAL_STACK) {
|
||
|
if (totalMemory < 16*1024*1024) {
|
||
|
totalMemory *= 2;
|
||
|
} else {
|
||
|
totalMemory += 16*1024*1024
|
||
|
}
|
||
|
}
|
||
|
if (totalMemory !== TOTAL_MEMORY) {
|
||
|
Module.printErr('increasing TOTAL_MEMORY to ' + totalMemory + ' to be more reasonable');
|
||
|
TOTAL_MEMORY = totalMemory;
|
||
|
}
|
||
|
|
||
|
// Initialize the runtime's memory
|
||
|
// check for full engine support (use string 'subarray' to avoid closure compiler confusion)
|
||
|
assert(typeof Int32Array !== 'undefined' && typeof Float64Array !== 'undefined' && !!(new Int32Array(1)['subarray']) && !!(new Int32Array(1)['set']),
|
||
|
'JS engine does not provide full typed array support');
|
||
|
|
||
|
var buffer = new ArrayBuffer(TOTAL_MEMORY);
|
||
|
HEAP8 = new Int8Array(buffer);
|
||
|
HEAP16 = new Int16Array(buffer);
|
||
|
HEAP32 = new Int32Array(buffer);
|
||
|
HEAPU8 = new Uint8Array(buffer);
|
||
|
HEAPU16 = new Uint16Array(buffer);
|
||
|
HEAPU32 = new Uint32Array(buffer);
|
||
|
HEAPF32 = new Float32Array(buffer);
|
||
|
HEAPF64 = new Float64Array(buffer);
|
||
|
|
||
|
// Endianness check (note: assumes compiler arch was little-endian)
|
||
|
HEAP32[0] = 255;
|
||
|
assert(HEAPU8[0] === 255 && HEAPU8[3] === 0, 'Typed arrays 2 must be run on a little-endian system');
|
||
|
|
||
|
Module['HEAP'] = HEAP;
|
||
|
Module['HEAP8'] = HEAP8;
|
||
|
Module['HEAP16'] = HEAP16;
|
||
|
Module['HEAP32'] = HEAP32;
|
||
|
Module['HEAPU8'] = HEAPU8;
|
||
|
Module['HEAPU16'] = HEAPU16;
|
||
|
Module['HEAPU32'] = HEAPU32;
|
||
|
Module['HEAPF32'] = HEAPF32;
|
||
|
Module['HEAPF64'] = HEAPF64;
|
||
|
|
||
|
function callRuntimeCallbacks(callbacks) {
|
||
|
while(callbacks.length > 0) {
|
||
|
var callback = callbacks.shift();
|
||
|
if (typeof callback == 'function') {
|
||
|
callback();
|
||
|
continue;
|
||
|
}
|
||
|
var func = callback.func;
|
||
|
if (typeof func === 'number') {
|
||
|
if (callback.arg === undefined) {
|
||
|
Runtime.dynCall('v', func);
|
||
|
} else {
|
||
|
Runtime.dynCall('vi', func, [callback.arg]);
|
||
|
}
|
||
|
} else {
|
||
|
func(callback.arg === undefined ? null : callback.arg);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var __ATPRERUN__ = []; // functions called before the runtime is initialized
|
||
|
var __ATINIT__ = []; // functions called during startup
|
||
|
var __ATMAIN__ = []; // functions called when main() is to be run
|
||
|
var __ATEXIT__ = []; // functions called during shutdown
|
||
|
var __ATPOSTRUN__ = []; // functions called after the runtime has exited
|
||
|
|
||
|
var runtimeInitialized = false;
|
||
|
|
||
|
function preRun() {
|
||
|
// compatibility - merge in anything from Module['preRun'] at this time
|
||
|
if (Module['preRun']) {
|
||
|
if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
|
||
|
while (Module['preRun'].length) {
|
||
|
addOnPreRun(Module['preRun'].shift());
|
||
|
}
|
||
|
}
|
||
|
callRuntimeCallbacks(__ATPRERUN__);
|
||
|
}
|
||
|
|
||
|
function ensureInitRuntime() {
|
||
|
if (runtimeInitialized) return;
|
||
|
runtimeInitialized = true;
|
||
|
callRuntimeCallbacks(__ATINIT__);
|
||
|
}
|
||
|
|
||
|
function preMain() {
|
||
|
callRuntimeCallbacks(__ATMAIN__);
|
||
|
}
|
||
|
|
||
|
function exitRuntime() {
|
||
|
callRuntimeCallbacks(__ATEXIT__);
|
||
|
}
|
||
|
|
||
|
function postRun() {
|
||
|
// compatibility - merge in anything from Module['postRun'] at this time
|
||
|
if (Module['postRun']) {
|
||
|
if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
|
||
|
while (Module['postRun'].length) {
|
||
|
addOnPostRun(Module['postRun'].shift());
|
||
|
}
|
||
|
}
|
||
|
callRuntimeCallbacks(__ATPOSTRUN__);
|
||
|
}
|
||
|
|
||
|
function addOnPreRun(cb) {
|
||
|
__ATPRERUN__.unshift(cb);
|
||
|
}
|
||
|
Module['addOnPreRun'] = Module.addOnPreRun = addOnPreRun;
|
||
|
|
||
|
function addOnInit(cb) {
|
||
|
__ATINIT__.unshift(cb);
|
||
|
}
|
||
|
Module['addOnInit'] = Module.addOnInit = addOnInit;
|
||
|
|
||
|
function addOnPreMain(cb) {
|
||
|
__ATMAIN__.unshift(cb);
|
||
|
}
|
||
|
Module['addOnPreMain'] = Module.addOnPreMain = addOnPreMain;
|
||
|
|
||
|
function addOnExit(cb) {
|
||
|
__ATEXIT__.unshift(cb);
|
||
|
}
|
||
|
Module['addOnExit'] = Module.addOnExit = addOnExit;
|
||
|
|
||
|
function addOnPostRun(cb) {
|
||
|
__ATPOSTRUN__.unshift(cb);
|
||
|
}
|
||
|
Module['addOnPostRun'] = Module.addOnPostRun = addOnPostRun;
|
||
|
|
||
|
// Tools
|
||
|
|
||
|
// This processes a JS string into a C-line array of numbers, 0-terminated.
|
||
|
// For LLVM-originating strings, see parser.js:parseLLVMString function
|
||
|
function intArrayFromString(stringy, dontAddNull, length /* optional */) {
|
||
|
var ret = (new Runtime.UTF8Processor()).processJSString(stringy);
|
||
|
if (length) {
|
||
|
ret.length = length;
|
||
|
}
|
||
|
if (!dontAddNull) {
|
||
|
ret.push(0);
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
Module['intArrayFromString'] = intArrayFromString;
|
||
|
|
||
|
function intArrayToString(array) {
|
||
|
var ret = [];
|
||
|
for (var i = 0; i < array.length; i++) {
|
||
|
var chr = array[i];
|
||
|
if (chr > 0xFF) {
|
||
|
chr &= 0xFF;
|
||
|
}
|
||
|
ret.push(String.fromCharCode(chr));
|
||
|
}
|
||
|
return ret.join('');
|
||
|
}
|
||
|
Module['intArrayToString'] = intArrayToString;
|
||
|
|
||
|
// Write a Javascript array to somewhere in the heap
|
||
|
function writeStringToMemory(string, buffer, dontAddNull) {
|
||
|
var array = intArrayFromString(string, dontAddNull);
|
||
|
var i = 0;
|
||
|
while (i < array.length) {
|
||
|
var chr = array[i];
|
||
|
HEAP8[(((buffer)+(i))>>0)]=chr;
|
||
|
i = i + 1;
|
||
|
}
|
||
|
}
|
||
|
Module['writeStringToMemory'] = writeStringToMemory;
|
||
|
|
||
|
function writeArrayToMemory(array, buffer) {
|
||
|
for (var i = 0; i < array.length; i++) {
|
||
|
HEAP8[(((buffer)+(i))>>0)]=array[i];
|
||
|
}
|
||
|
}
|
||
|
Module['writeArrayToMemory'] = writeArrayToMemory;
|
||
|
|
||
|
function writeAsciiToMemory(str, buffer, dontAddNull) {
|
||
|
for (var i = 0; i < str.length; i++) {
|
||
|
HEAP8[(((buffer)+(i))>>0)]=str.charCodeAt(i);
|
||
|
}
|
||
|
if (!dontAddNull) HEAP8[(((buffer)+(str.length))>>0)]=0;
|
||
|
}
|
||
|
Module['writeAsciiToMemory'] = writeAsciiToMemory;
|
||
|
|
||
|
function unSign(value, bits, ignore) {
|
||
|
if (value >= 0) {
|
||
|
return value;
|
||
|
}
|
||
|
return bits <= 32 ? 2*Math.abs(1 << (bits-1)) + value // Need some trickery, since if bits == 32, we are right at the limit of the bits JS uses in bitshifts
|
||
|
: Math.pow(2, bits) + value;
|
||
|
}
|
||
|
function reSign(value, bits, ignore) {
|
||
|
if (value <= 0) {
|
||
|
return value;
|
||
|
}
|
||
|
var half = bits <= 32 ? Math.abs(1 << (bits-1)) // abs is needed if bits == 32
|
||
|
: Math.pow(2, bits-1);
|
||
|
if (value >= half && (bits <= 32 || value > half)) { // for huge values, we can hit the precision limit and always get true here. so don't do that
|
||
|
// but, in general there is no perfect solution here. With 64-bit ints, we get rounding and errors
|
||
|
// TODO: In i64 mode 1, resign the two parts separately and safely
|
||
|
value = -2*half + value; // Cannot bitshift half, as it may be at the limit of the bits JS uses in bitshifts
|
||
|
}
|
||
|
return value;
|
||
|
}
|
||
|
|
||
|
// check for imul support, and also for correctness ( https://bugs.webkit.org/show_bug.cgi?id=126345 )
|
||
|
if (!Math['imul'] || Math['imul'](0xffffffff, 5) !== -5) Math['imul'] = function imul(a, b) {
|
||
|
var ah = a >>> 16;
|
||
|
var al = a & 0xffff;
|
||
|
var bh = b >>> 16;
|
||
|
var bl = b & 0xffff;
|
||
|
return (al*bl + ((ah*bl + al*bh) << 16))|0;
|
||
|
};
|
||
|
Math.imul = Math['imul'];
|
||
|
|
||
|
|
||
|
var Math_abs = Math.abs;
|
||
|
var Math_cos = Math.cos;
|
||
|
var Math_sin = Math.sin;
|
||
|
var Math_tan = Math.tan;
|
||
|
var Math_acos = Math.acos;
|
||
|
var Math_asin = Math.asin;
|
||
|
var Math_atan = Math.atan;
|
||
|
var Math_atan2 = Math.atan2;
|
||
|
var Math_exp = Math.exp;
|
||
|
var Math_log = Math.log;
|
||
|
var Math_sqrt = Math.sqrt;
|
||
|
var Math_ceil = Math.ceil;
|
||
|
var Math_floor = Math.floor;
|
||
|
var Math_pow = Math.pow;
|
||
|
var Math_imul = Math.imul;
|
||
|
var Math_fround = Math.fround;
|
||
|
var Math_min = Math.min;
|
||
|
|
||
|
// A counter of dependencies for calling run(). If we need to
|
||
|
// do asynchronous work before running, increment this and
|
||
|
// decrement it. Incrementing must happen in a place like
|
||
|
// PRE_RUN_ADDITIONS (used by emcc to add file preloading).
|
||
|
// Note that you can add dependencies in preRun, even though
|
||
|
// it happens right before run - run will be postponed until
|
||
|
// the dependencies are met.
|
||
|
var runDependencies = 0;
|
||
|
var runDependencyWatcher = null;
|
||
|
var dependenciesFulfilled = null; // overridden to take different actions when all run dependencies are fulfilled
|
||
|
|
||
|
function addRunDependency(id) {
|
||
|
runDependencies++;
|
||
|
if (Module['monitorRunDependencies']) {
|
||
|
Module['monitorRunDependencies'](runDependencies);
|
||
|
}
|
||
|
}
|
||
|
Module['addRunDependency'] = addRunDependency;
|
||
|
function removeRunDependency(id) {
|
||
|
runDependencies--;
|
||
|
if (Module['monitorRunDependencies']) {
|
||
|
Module['monitorRunDependencies'](runDependencies);
|
||
|
}
|
||
|
if (runDependencies == 0) {
|
||
|
if (runDependencyWatcher !== null) {
|
||
|
clearInterval(runDependencyWatcher);
|
||
|
runDependencyWatcher = null;
|
||
|
}
|
||
|
if (dependenciesFulfilled) {
|
||
|
var callback = dependenciesFulfilled;
|
||
|
dependenciesFulfilled = null;
|
||
|
callback(); // can add another dependenciesFulfilled
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
Module['removeRunDependency'] = removeRunDependency;
|
||
|
|
||
|
Module["preloadedImages"] = {}; // maps url to image data
|
||
|
Module["preloadedAudios"] = {}; // maps url to audio data
|
||
|
|
||
|
|
||
|
var memoryInitializer = null;
|
||
|
|
||
|
// === Body ===
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
STATIC_BASE = 8;
|
||
|
|
||
|
STATICTOP = STATIC_BASE + Runtime.alignMemory(63547);
|
||
|
/* global initializers */ __ATINIT__.push();
|
||
|
|
||
|
|
||
|
/* memory initializer */ allocate([97,100,98,58,32,117,110,107,110,111,119,110,32,99,109,100,32,40,37,48,50,88,41,10,0,0,0,0,0,0,0,0,105,103,110,111,114,105,110,103,32,112,99,101,32,107,101,121,58,32,48,120,37,48,52,120,32,40,37,115,41,10,0,0,60,110,111,110,101,62,0,0,1,0,0,0,53,0,0,0,2,0,0,0,122,0,0,0,3,0,0,0,120,0,0,0,4,0,0,0,99,0,0,0,5,0,0,0,118,0,0,0,6,0,0,0,96,0,0,0,7,0,0,0,97,0,0,0,8,0,0,0,98,0,0,0,9,0,0,0,100,0,0,0,10,0,0,0,101,0,0,0,11,0,0,0,109,0,0,0,12,0,0,0,103,0,0,0,13,0,0,0,111,0,0,0,17,0,0,0,50,0,0,0,18,0,0,0,18,0,0,0,19,0,0,0,19,0,0,0,20,0,0,0,20,0,0,0,21,0,0,0,21,0,0,0,22,0,0,0,23,0,0,0,23,0,0,0,22,0,0,0,24,0,0,0,26,0,0,0,25,0,0,0,28,0,0,0,26,0,0,0,25,0,0,0,27,0,0,0,29,0,0,0,28,0,0,0,27,0,0,0,29,0,0,0,24,0,0,0,30,0,0,0,51,0,0,0,31,0,0,0,48,0,0,0,32,0,0,0,12,0,0,0,33,0,0,0,13,0,0,0,34,0,0,0,14,0,0,0,35,0,0,0,15,0,0,0,36,0,0,0,17,0,0,0,37,0,0,0,16,0,0,0,38,0,0,0,32,0,0,0,39,0,0,0,34,0,0,0,40,0,0,0,31,0,0,0,41,0,0,0,35,0,0,0,42,0,0,0,33,0,0,0,43,0,0,0,30,0,0,0,57,0,0,0,42,0,0,0,45,0,0,0,57,0,0,0,46,0,0,0,0,0,0,0,47,0,0,0,1,0,0,0,48,0,0,0,2,0,0,0,49,0,0,0,3,0,0,0,50,0,0,0,5,0,0,0,51,0,0,0,4,0,0,0,52,0,0,0,38,0,0,0,53,0,0,0,40,0,0,0,54,0,0,0,37,0,0,0,55,0,0,0,41,0,0,0,56,0,0,0,39,0,0,0,44,0,0,0,36,0,0,0,58,0,0,0,56,0,0,0,60,0,0,0,6,0,0,0,61,0,0,0,7,0,0,0,62,0,0,0,8,0,0,0,63,0,0,0,9,0,0,0,64,0,0,0,11,0,0,0,66,0,0,0,45,0,0,0,65,0,0,0,46,0,0,0,67,0,0,0,43,0,0,0,68,0,0,0,47,0,0,0,69,0,0,0,44,0,0,0,70,0,0,0,56,0,0,0,71,0,0,0,54,0,0,0,72,0,0,0,58,0,0,0,74,0,0,0,58,0,0,0,75,0,0,0,55,0,0,0,76,0,0,0,49,0,0,0,77,0,0,0,55,0,0,0,81,0,0,0,54,0,0,0,99,0,0,0,114,0,0,0,100,0,0,0,115,0,0,0,101,0,0,0,116,0,0,0,102,0,0,0,117,0,0,0,103,0,0,0,119,0,0,0,104,0,0,0,121,0,0,0,105,0,0,0,62,0,0,0,106,0,0,0,59,0,0,0,108,0,0,0,60,0,0,0,107,0,0,0,61,0,0,0,82,0,0,0,71,0,0,0,83,0,0,0,75,0,0,0,84,0,0,0,67,0,0,0,86,0,0,0,89,0,0,0,87,0,0,0,91,0,0,0,88,0,0,0,92,0,0,0,85,0,0,0,78,0,0,0,90,0,0,0,86,0,0,0,91,0,0,0,87,0,0,0,92,0,0,0,88,0,0,0,89,0,0,0,69,0,0,0,93,0,0,0,83,0,0,0,94,0,0,0,84,0,0,0,95,0,0,0,85,0,0,0,96,0,0,0,76,0,0,0,97,0,0,0,82,0,0,0,98,0,0,0,65,0,0,0,0,0,0,0,0,0,0,0,97,100,98,45,107,98,100,58,32,108,105,115,116,101,110,32,37,117,10,0,0,0,0,0,97,100,98,45,107,98,100,58,32,116,97,108,107,32,37,117,10,0,0,0,0,0,0,0,97,100,98,45,107,98,100,58,32,116,97,108,107,32,50,10,0,0,0,0,0,0,0,0,86,0,0,0,89,0,0,0,87,0,0,0,91,0,0,0,88,0,0,0,92,0,0,0,90,0,0,0,86,0,0,0,91,0,0,0,87,0,0,0,92,0,0,0,88,0,0,0,93,0,0,0,83,0,0,0,94,0,0,0,84,0,0,0,95,0,0,0,85,0,0,0,97,0,0,0,82,0,0,0,98,0,0,0,65,0,0,0,96,0,0,0,76,0,0,0,0,0,0,0,0,0,0,0,86,0,0,0,115,0,0,0,87,0,0,0,62,0,0,0,88,0,0,0,116,0,0,0,90,0,0,0,59,0,0,0,91,0,0,0,87,0,0,0,92,0,0,0,60,0,0,0,93,0,0,0,119,0,0,0,94,0,0,0,61,0,0,0,95,0,0,0,121,0,0,0,97,0,0,0,114,0,0,0,98,0,0,0,117,0,0,0,96,0,0,0,36,0,0,0,0,0,0,0,0,0,0,0,99,0,0,0,0,0,0,0,91,99,110,116,93,0,0,0,99,108,111,99,107,0,0,0,103,98,0,0,0,0,0,0,91,97,100,100,114,46,46,93,0,0,0,0,0,0,0,0,114,117,110,32,119,105,116,104,32,98,114,101,97,107,112,111,105,110,116,115,32,97,116,32,97,100,100,114,0,0,0,0,103,101,0,0,0,0,0,0,91,101,120,99,101,112,116,105,111,110,93,0,0,0,0,0,114,117,110,32,117,110,116,105,108,32,101,120,99,101,112,116,105,111,110,0,0,0,0,0,103,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,114,117,110,0,0,0,0,0,104,97,108,116,0,0,0,0,91,118,97,108,93,0,0,0,115,101,116,32,104,97,108,116,32,115,116,97,116,101,32,91,50,93,0,0,0,0,0,0,112,0,0,0,0,0,0,0,101,120,101,99,117,116,101,32,99,110,116,32,105,110,115,116,114,117,99,116,105,111,110,115,44,32,115,107,105,112,32,99,97,108,108,115,32,91,49,93,0,0,0,0,0,0,0,0,114,101,115,101,116,0,0,0,114,116,101,0,0,0,0,0,101,120,101,99,117,116,101,32,116,111,32,110,101,120,116,32,114,116,101,0,0,0,0,0,114,0,0,0,0,0,0,0,114,101,103,32,91,118,97,108,93,0,0,0,0,0,0,0,103,101,116,32,111,114,32,115,101,116,32,97,32,114,101,103,105,115,116,101,114,0,0,0,115,0,0,0,0,0,0,0,91,119,104,97,116,93,0,0,112,114,105,110,116,32,115,116,97,116,117,115,32,40,99,112,117,124,109,101,109,124,115,99,99,124,118,105,97,41,0,0,116,0,0,0,0,0,0,0,101,120,101,99,117,116,101,32,99,110,116,32,105,110,115,116,114,117,99,116,105,111,110,115,32,91,49,93,0,0,0,0,1
|
||
|
/* memory initializer */ allocate([101,32,115,111,117,110,100,32,98,117,102,102,101,114,10,0,99,112,117,0,0,0,0,0,115,112,101,101,100,0,0,0,67,80,85,58,0,0,0,0,109,111,100,101,108,61,37,115,32,115,112,101,101,100,61,37,100,10,0,0,0,0,0,0,42,42,42,32,117,110,107,110,111,119,110,32,99,112,117,32,109,111,100,101,108,32,40,37,115,41,10,0,0,0,0,0,42,42,42,32,82,65,77,32,110,111,116,32,102,111,117,110,100,32,97,116,32,48,48,48,48,48,48,10,0,0,0,0,42,42,42,32,82,79,77,32,110,111,116,32,102,111,117,110,100,32,97,116,32,52,48,48,48,48,48,10,0,0,0,0,109,101,109,116,101,115,116,0,82,65,77,58,0,0,0,0,100,105,115,97,98,108,105,110,103,32,109,101,109,111,114,121,32,116,101,115,116,10,0,0,115,121,115,116,101,109,0,0,109,97,99,45,112,108,117,115,0,0,0,0,0,0,0,0,83,89,83,84,69,77,58,0,109,111,100,101,108,61,37,115,10,0,0,0,0,0,0,0,109,97,99,45,115,101,0,0,109,97,99,45,99,108,97,115,115,105,99,0,0,0,0,0,42,42,42,32,117,110,107,110,111,119,110,32,109,111,100,101,108,32,40,37,115,41,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,112,99,101,45,109,97,99,112,108,117,115,58,32,115,101,103,109,101,110,116,97,116,105,111,110,32,102,97,117,108,116,10,0,0,0,0,0,0,0,0,99,112,117,0,0,0,0,0,112,99,101,45,109,97,99,112,108,117,115,58,32,115,105,103,110,97,108,32,37,100,10,0,91,37,48,54,108,88,93,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,112,99,101,45,99,111,110,102,105,103,46,99,102,103,0,0,63,0,0,0,16,45,0,0,0,0,0,0,24,45,0,0,98,0,1,0,48,45,0,0,64,45,0,0,72,45,0,0,66,0,2,0,112,45,0,0,128,45,0,0,144,45,0,0,99,0,1,0,168,45,0,0,176,45,0,0,184,45,0,0,100,0,1,0,216,45,0,0,176,45,0,0,224,45,0,0,105,0,1,0,8,46,0,0,176,45,0,0,24,46,0,0,73,0,1,0,72,46,0,0,176,45,0,0,88,46,0,0,108,0,1,0,128,46,0,0,176,45,0,0,136,46,0,0,112,0,1,0,128,41,0,0,176,45,0,0,168,46,0,0,113,0,0,0,192,46,0,0,0,0,0,0,200,46,0,0,114,0,0,0,232,46,0,0,0,0,0,0,240,46,0,0,82,0,0,0,16,47,0,0,0,0,0,0,32,47,0,0,115,0,1,0,56,47,0,0,64,47,0,0,72,47,0,0,116,0,1,0,96,47,0,0,176,45,0,0,112,47,0,0,118,0,0,0,136,47,0,0,0,0,0,0,144,47,0,0,86,0,0,0,176,47,0,0,0,0,0,0,184,47,0,0,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,115,58,32,98,97,100,32,100,114,105,118,101,32,110,117,109,98,101,114,32,40,37,117,41,10,0,0,0,0,0,0,37,115,58,32,101,114,114,111,114,32,112,97,114,115,105,110,103,32,105,110,105,32,115,116,114,105,110,103,32,40,37,115,41,10,0,0,0,0,0,0,10,0,0,0,0,0,0,0,99,112,117,46,109,111,100,101,108,32,61,32,34,0,0,0,34,10,0,0,0,0,0,0,99,112,117,46,115,112,101,101,100,32,61,32,0,0,0,0,37,115,58,32,117,110,107,110,111,119,110,32,111,112,116,105,111,110,32,40,37,115,41,10,0,0,0,0,0,0,0,0,109,97,99,112,108,117,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,67,79,78,70,73,71,58,0,102,105,108,101,61,34,37,115,34,10,0,0,0,0,0,0,42,42,42,32,108,111,97,100,105,110,103,32,99,111,110,102,105,103,32,102,105,108,101,32,102,97,105,108,101,100,10,0,112,99,101,45,109,97,99,112,108,117,115,32,118,101,114,115,105,111,110,32,50,48,49,52,48,57,50,55,45,51,101,97,52,98,51,52,45,109,111,100,10,67,111,112,121,114,105,103,104,116,32,40,67,41,32,50,48,48,55,45,50,48,49,50,32,72,97,109,112,97,32,72,117,103,32,60,104,97,109,112,97,64,104,97,109,112,97,46,99,104,62,10,0,0,0,0,112,99,101,45,109,97,99,112,108,117,115,32,118,101,114,115,105,111,110,32,50,48,49,52,48,57,50,55,45,51,101,97,52,98,51,52,45,109,111,100,10,10,67,111,112,121,114,105,103,104,116,32,40,67,41,32,50,48,48,55,45,50,48,49,50,32,72,97,109,112,97,32,72,117,103,32,60,104,97,109,112,97,64,104,97,109,112,97,46,99,104,62,10,0,0,0,112,99,101,45,109,97,99,112,108,117,115,58,32,77,97,99,105,110,116,111,115,104,32,80,108,117,115,32,101,109,117,108,97,116,111,114,0,0,0,0,117,115,97,103,101,58,32,112,99,101,45,109,97,99,112,108,117,115,32,91,111,112,116,105,111,110,115,93,0,0,0,0,104,101,108,112,0,0,0,0,80,114,105,110,116,32,117,115,97,103,101,32,105,110,102,111,114,109,97,116,105,111,110,0,100,105,115,107,45,100,101,108,97,121,45,49,0,0,0,0,100,101,108,97,121,0,0,0,83,101,116,32,116,104,101,32,100,105,115,107,32
|
||
|
/* memory initializer */ allocate([82,101,97,100,0,0,0,0,87,114,105,116,101,0,0,0,67,111,110,116,114,111,108,0,83,116,97,116,117,115,0,0,75,105,108,108,73,79,0,0,71,101,116,86,111,108,73,110,102,111,0,0,0,0,0,0,67,114,101,97,116,101,0,0,68,101,108,101,116,101,0,0,79,112,101,110,82,70,0,0,82,101,110,97,109,101,0,0,71,101,116,70,105,108,101,73,110,102,111,0,0,0,0,0,83,101,116,70,105,108,101,73,110,102,111,0,0,0,0,0,85,110,109,111,117,110,116,86,111,108,0,0,0,0,0,0,77,111,117,110,116,86,111,108,0,0,0,0,0,0,0,0,65,108,108,111,99,97,116,101,0,0,0,0,0,0,0,0,71,101,116,69,79,70,0,0,83,101,116,69,79,70,0,0,70,108,117,115,104,86,111,108,0,0,0,0,0,0,0,0,71,101,116,86,111,108,0,0,83,101,116,86,111,108,0,0,73,110,105,116,81,117,101,117,101,0,0,0,0,0,0,0,69,106,101,99,116,0,0,0,71,101,116,70,80,111,115,0,73,110,105,116,90,111,110,101,0,0,0,0,0,0,0,0,71,101,116,90,111,110,101,0,83,101,116,90,111,110,101,0,70,114,101,101,77,101,109,0,77,97,120,77,101,109,0,0,78,101,119,80,116,114,0,0,68,105,115,112,111,115,80,116,114,0,0,0,0,0,0,0,83,101,116,80,116,114,83,105,122,101,0,0,0,0,0,0,71,101,116,80,116,114,83,105,122,101,0,0,0,0,0,0,78,101,119,72,97,110,100,108,101,0,0,0,0,0,0,0,68,105,115,112,111,115,72,97,110,100,108,101,0,0,0,0,83,101,116,72,97,110,100,108,101,83,105,122,101,0,0,0,71,101,116,72,97,110,100,108,101,83,105,122,101,0,0,0,72,97,110,100,108,101,90,111,110,101,0,0,0,0,0,0,82,101,97,108,108,111,99,72,97,110,100,108,101,0,0,0,82,101,99,111,118,101,114,72,97,110,100,108,101,0,0,0,72,76,111,99,107,0,0,0,72,85,110,108,111,99,107,0,69,109,112,116,121,72,97,110,100,108,101,0,0,0,0,0,73,110,105,116,65,112,112,108,90,111,110,101,0,0,0,0,83,101,116,65,112,112,108,76,105,109,105,116,0,0,0,0,66,108,111,99,107,77,111,118,101,0,0,0,0,0,0,0,80,111,115,116,69,118,101,110,116,0,0,0,0,0,0,0,79,83,69,118,101,110,116,65,118,97,105,108,0,0,0,0,71,101,116,79,83,69,118,101,110,116,0,0,0,0,0,0,70,108,117,115,104,69,118,101,110,116,115,0,0,0,0,0,86,73,110,115,116,97,108,108,0,0,0,0,0,0,0,0,86,82,101,109,111,118,101,0,79,102,102,108,105,110,101,0,77,111,114,101,77,97,115,116,101,114,115,0,0,0,0,0,87,114,105,116,101,80,97,114,97,109,0,0,0,0,0,0,82,101,97,100,68,97,116,101,84,105,109,101,0,0,0,0,83,101,116,68,97,116,101,84,105,109,101,0,0,0,0,0,68,101,108,97,121,0,0,0,67,109,112,83,116,114,105,110,103,0,0,0,0,0,0,0,68,114,118,114,73,110,115,116,97,108,108,0,0,0,0,0,68,114,118,114,82,101,109,111,118,101,0,0,0,0,0,0,73,110,105,116,85,116,105,108,0,0,0,0,0,0,0,0,82,101,115,114,118,77,101,109,0,0,0,0,0,0,0,0,83,101,116,70,105,108,76,111,99,107,0,0,0,0,0,0,82,115,116,70,105,108,76,111,99,107,0,0,0,0,0,0,83,101,116,70,105,108,84,121,112,101,0,0,0,0,0,0,83,101,116,70,80,111,115,0,70,108,117,115,104,70,105,108,101,0,0,0,0,0,0,0,71,101,116,84,114,97,112,65,100,100,114,101,115,115,0,0,83,101,116,84,114,97,112,65,100,100,114,101,115,115,0,0,80,116,114,90,111,110,101,0,72,80,117,114,103,101,0,0,72,78,111,80,117,114,103,101,0,0,0,0,0,0,0,0,83,101,116,71,114,111,119,90,111,110,101,0,0,0,0,0,67,111,109,112,97,99,116,77,101,109,0,0,0,0,0,0,80,117,114,103,101,77,101,109,0,0,0,0,0,0,0,0,65,100,100,68,114,105,118,101,0,0,0,0,0,0,0,0,82,68,114,118,114,73,110,115,116,97,108,108,0,0,0,0,82,101,108,83,116,114,105,110,103,0,0,0,0,0,0,0,82,101,97,100,88,80,114,97,109,0,0,0,0,0,0,0,87,114,105,116,101,88,80,114,97,109,0,0,0,0,0,0,85,112,114,83,116,114,105,110,103,0,0,0,0,0,0,0,83,116,114,105,112,65,100,100,114,101,115,115,0,0,0,0,76,111,119,101,114,84,101,120,116,0,0,0,0,0,0,0,83,101,116,65,112,112,66,97,115,101,0,0,0,0,0,0,73,110,115,84,105,109,101,0,82,109,118,84,105,109,101,0,80,114,105,109,101,84,105,109,101,0,0,0,0,0,0,0,80,111,119,101,114,79,102,102,0,0,0,0,0,0,0,0,77,101,109,111,114,121,68,105,115,112,97,116,99,104,0,0,83,119,97,112,77,77,85,77,111,100,101,0,0,0,0,0,78,77,73,110,115,116,97,108,108,0,0,0,0,0,0,0,78,77,82,101,109,111,118,101,0,0,0,0,0,0,0,0,72,70,83,68,105,115,112,97,116,99,104,0,0,0,0,0,77,97,120,66,108,111,99,107,0,0,0,0,0,0,0,0,80,117,114,103,101,83,112,97,99,101,0,0,0,0,0,0,77,97,120,65,112,112,108,90,111,110,101,0,0,0,0,0,77,111,118,101,72,72,105,0,83,116
|
||
|
/* memory initializer */ allocate([110,0,0,0,0,0,0,0,83,101,116,67,116,108,67,111,108,111,114,0,0,0,0,0,71,101,116,65,117,120,67,116,108,0,0,0,0,0,0,0,78,101,119,67,87,105,110,100,111,119,0,0,0,0,0,0,71,101,116,78,101,119,67,87,105,110,100,111,119,0,0,0,83,101,116,68,101,115,107,67,80,97,116,0,0,0,0,0,71,101,116,67,87,77,103,114,80,111,114,116,0,0,0,0,83,97,118,101,69,110,116,114,105,101,115,0,0,0,0,0,82,101,115,116,111,114,101,69,110,116,114,105,101,115,0,0,78,101,119,67,68,105,97,108,111,103,0,0,0,0,0,0,68,101,108,83,101,97,114,99,104,0,0,0,0,0,0,0,68,101,108,67,111,109,112,0,83,101,116,83,116,100,67,80,114,111,99,115,0,0,0,0,67,97,108,99,67,77,97,115,107,0,0,0,0,0,0,0,83,101,101,100,67,70,105,108,108,0,0,0,0,0,0,0,67,111,112,121,68,101,101,112,77,97,115,107,0,0,0,0,72,105,103,104,76,101,118,101,108,70,83,68,105,115,112,97,116,99,104,0,0,0,0,0,68,101,108,77,67,69,110,116,114,105,101,115,0,0,0,0,71,101,116,77,67,73,110,102,111,0,0,0,0,0,0,0,83,101,116,77,67,73,110,102,111,0,0,0,0,0,0,0,68,105,115,112,77,67,69,110,116,114,105,101,115,0,0,0,71,101,116,77,67,69,110,116,114,121,0,0,0,0,0,0,83,101,116,77,67,69,110,116,114,105,101,115,0,0,0,0,77,101,110,117,67,104,111,105,99,101,0,0,0,0,0,0,77,111,100,97,108,68,105,97,108,111,103,77,101,110,117,83,101,116,117,112,0,0,0,0,68,105,97,108,111,103,68,105,115,112,97,116,99,104,0,0,1,0,0,0,2,0,0,0,3,0,0,0,4,0,0,0,5,0,0,0,6,0,0,0,7,0,0,0,8,0,0,0,9,0,0,0,10,0,0,0,11,0,0,0,12,0,0,0,5,0,0,0,6,0,0,0,7,0,0,0,8,0,0,0,13,0,0,0,14,0,0,0,15,0,0,0,16,0,0,0,5,0,0,0,6,0,0,0,7,0,0,0,8,0,0,0,17,0,0,0,18,0,0,0,19,0,0,0,20,0,0,0,5,0,0,0,6,0,0,0,7,0,0,0,8,0,0,0,21,0,0,0,22,0,0,0,23,0,0,0,24,0,0,0,5,0,0,0,6,0,0,0,7,0,0,0,8,0,0,0,25,0,0,0,26,0,0,0,27,0,0,0,20,0,0,0,5,0,0,0,6,0,0,0,7,0,0,0,8,0,0,0,28,0,0,0,29,0,0,0,30,0,0,0,20,0,0,0,5,0,0,0,6,0,0,0,7,0,0,0,8,0,0,0,31,0,0,0,32,0,0,0,33,0,0,0,34,0,0,0,5,0,0,0,6,0,0,0,7,0,0,0,8,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,35,0,0,0,36,0,0,0,37,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,37,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,37,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,37,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,37,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,37,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,37,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,37,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,36,0,0,0,38,0,0,0,39,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,39,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,39,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,39,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,39,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,39,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,39,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,39,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,38,0,0,0,40,0,0,0,41,0,0,0,42,0,0,0,43,0,0,0,20,0,0,0,20,0,0,0,44,0,0,0,45,0,0,0,46,0,0,0,47,0,0,0,48,0,0,0,49,0,0,0,20,0,0,0,20,0,0,0,44,0,0,0,45,0,0,0,50,0,0,0,51,0,0,0,52,0,0,0,53,0,0,0,20,0,0,0,20,0,0,0,44,0,0,0,45,0,0,0,54,0,0,0,55,0,0,0,56,0,0,0,57,0,0,0,20,0,0,0,20,0,0,0,44,0,0,0,45,0,0,0,58,0,0,0,59,0,0,0,60,0,0,0,61,0,0,0,20,0,0,0,20,0,0,0,44,0,0,0,62,0,0,0,63,0,0,0,64,0,0,0,65,0,0,0,66,0,0,0,20,0,0,0,20,0,0,0,44,0,0,0,45,0,0,0,67,0,0,0,68,0,0,0,69,0,0,0,70,0,0,0,20,0,0,0,20,0,0,0,
|
||
|
/* memory initializer */ allocate([131,0,0,0,132,0,0,0,133,0,0,0,134,0,0,0,135,0,0,0,136,0,0,0,137,0,0,0,138,0,0,0,131,0,0,0,132,0,0,0,133,0,0,0,134,0,0,0,135,0,0,0,136,0,0,0,137,0,0,0,138,0,0,0,131,0,0,0,132,0,0,0,133,0,0,0,134,0,0,0,135,0,0,0,136,0,0,0,137,0,0,0,138,0,0,0,131,0,0,0,132,0,0,0,133,0,0,0,134,0,0,0,135,0,0,0,136,0,0,0,137,0,0,0,138,0,0,0,131,0,0,0,132,0,0,0,133,0,0,0,134,0,0,0,135,0,0,0,136,0,0,0,137,0,0,0,138,0,0,0,131,0,0,0,132,0,0,0,133,0,0,0,134,0,0,0,135,0,0,0,136,0,0,0,137,0,0,0,138,0,0,0,139,0,0,0,140,0,0,0,141,0,0,0,142,0,0,0,143,0,0,0,144,0,0,0,145,0,0,0,146,0,0,0,139,0,0,0,140,0,0,0,141,0,0,0,142,0,0,0,143,0,0,0,144,0,0,0,145,0,0,0,146,0,0,0,139,0,0,0,140,0,0,0,141,0,0,0,142,0,0,0,143,0,0,0,144,0,0,0,145,0,0,0,146,0,0,0,139,0,0,0,140,0,0,0,141,0,0,0,142,0,0,0,143,0,0,0,144,0,0,0,145,0,0,0,146,0,0,0,139,0,0,0,140,0,0,0,141,0,0,0,142,0,0,0,143,0,0,0,144,0,0,0,145,0,0,0,146,0,0,0,139,0,0,0,140,0,0,0,141,0,0,0,142,0,0,0,143,0,0,0,144,0,0,0,145,0,0,0,146,0,0,0,139,0,0,0,140,0,0,0,141,0,0,0,142,0,0,0,143,0,0,0,144,0,0,0,145,0,0,0,146,0,0,0,139,0,0,0,140,0,0,0,141,0,0,0,142,0,0,0,143,0,0,0,144,0,0,0,145,0,0,0,146,0,0,0,147,0,0,0,148,0,0,0,149,0,0,0,150,0,0,0,151,0,0,0,152,0,0,0,153,0,0,0,154,0,0,0,147,0,0,0,148,0,0,0,149,0,0,0,155,0,0,0,151,0,0,0,152,0,0,0,153,0,0,0,156,0,0,0,147,0,0,0,148,0,0,0,149,0,0,0,157,0,0,0,151,0,0,0,152,0,0,0,153,0,0,0,158,0,0,0,147,0,0,0,148,0,0,0,149,0,0,0,159,0,0,0,151,0,0,0,152,0,0,0,153,0,0,0,160,0,0,0,147,0,0,0,148,0,0,0,149,0,0,0,0,0,0,0,151,0,0,0,152,0,0,0,153,0,0,0,0,0,0,0,147,0,0,0,148,0,0,0,149,0,0,0,0,0,0,0,151,0,0,0,152,0,0,0,153,0,0,0,0,0,0,0,147,0,0,0,148,0,0,0,149,0,0,0,0,0,0,0,151,0,0,0,152,0,0,0,153,0,0,0,0,0,0,0,147,0,0,0,148,0,0,0,149,0,0,0,0,0,0,0,151,0,0,0,152,0,0,0,153,0,0,0,0,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,161,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,162,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,162,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,162,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||
|
/* memory initializer */ allocate([201,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,202,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,203,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,204,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,205,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,206,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,207,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,2,0,0,0,3,0,0,0,3,0,0,0,3,0,0,0,3,0,0,0,3,0,0,0,3,0,0,0,3,0,0,0,3,0,0,0,4,0,0,0,4,0,0,0,4,0,0,0,4,0,0,0,4,0,0,0,4,0,0,0,4,0,0,0,5,0,0,0,6,0,0,0,6,0,0,0,6,0,0,0,6,0,0,0,6,0,0,0,6,0,0,0,6,0,0,0,7,0,0,0,8,0,0,0,8,0,0,0,8,0,0,0,8,0,0,0,8,0,0,0,8,0,0,0,8,0,0,0,8,0,0,0,9,0,0,0,9,0,0,0,9,0,0,0,9,0,0,0,9,0,0,0,9,0,0,0,9,0,0,0,9,0,0,0,10,0,0,0,11,0,0,0,12,0,0,0,13,0,0,0,14,0,0,0,15,0,0,0,15,0,0,0,15,0,0,0,66,76,75,32,37,48,52,88,58,32,65,49,61,37,48,56,108,88,32,65,50,61,37,48,56,108,88,32,83,61,37,48,56,108,88,32,82,79,61,37,100,10,0,0,0,0,0,0,114,98,0,0,0,0,0,0,114,43,98,0,0,0,0,0,99,111,109,109,105,116,0,0,100,105,115,107,32,37,117,58,32,119,114,105,116,105,110,103,32,98,97,99,107,32,102,100,99,32,105,109,97,103,101,10,0,0,0,0,0,0,0,0,100,105,115,107,32,37,117,58,32,119,114,105,116,105,110,103,32,98,97,99,107,32,102,97,105,108,101,100,10,0,0,0,99,111,109,109,105,116,0,0,0,0,0,0,0,0,0,0,68,79,83,69,77,85,0,0,114,98,0,0,0,0,0,0,114,43,98,0,0,0,0,0,114,98,0,0,0,0,0,0,114,43,98,0,0,0,0,0,99,111,109,109,105,116,0,0,114,98,0,0,0,0,0,0,114,43,98,0,0,0,0,0,119,98,0,0,0,0,0,0,99,111,109,109,105,116,0,0,113,101,100,58,32,117,110,107,110,111,119,110,32,102,101,97,116,117,114,101,115,32,40,48,120,37,48,56,108,108,120,41,10,0,0,0,0,0,0,0,114,98,0,0,0,0,0,0,114,43,98,0,0,0,0,0,109,111,117,115,101,0,0,0,110,117,108,108,0,0,0,0,112,111,115,105,120,0,0,0,115,101,114,99,111,110,0,0,112,116,121,0,0,0,0,0,115,116,100,105,111,0,0,0,240,181,0,0,1,0,0,0,248,181,0,0,2,0,0,0,0,182,0,0,3,0,0,0,8,182,0,0,3,0,0,0,16,182,0,0,4,0,0,0,24,182,0,0,5,0,0,0,0,0,0,0,0,0,0,0,119,0,0,0,0,0,0,0,108,111,103,0,0,0,0,0,78,0,0,0,0,0,0,0,79,0,0,0,0,0,0,0,69,0,0,0,0,0,0,0,63,0,0,0,0,0,0,0,45,45,32,37,108,117,32,37,117,37,115,37,117,10,0,0,67,84,83,0,0,0,0,0,68,84,82,0,0,0,0,0,82,84,83,0,0,0,0,0,68,83,82,0,0,0,0,0,67,68,0,0,0,0,0,0,82,73,0,0,0,0,0,0,45,45,32,37,115,61,37,100,10,0,0,0,0,0,0,0,37,115,32,37,48,50,88,0,45,62,0,0,0,0,0,0,60,45,0,0,0,0,0,0,32,37,48,50,88,0,0,0,32,32,32,0,0,0,0,0,32,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,112,114,111,116,111,99,111,108,0,0,0,0,0,0,0,0,109,105,99,114,111,115,111,102,116,0,0,0,0,0,0,0,109,115,121,115,0,0,0,0,120,109,117,108,0,0,0,0,120,100,105,118,0,0,0,0,121,109,117,108,0,0,0,0,121,100,105,118,0,0,0,0,102,105,108,101,0,0,0,0,114,101,97,100,0,0,0,0,119,114,105,116,101,0,0,0,45,0,0,0,0,0,0,0,45,45,0,0,0,0,0,0,115,101,114,99,111,110,0,0,115,121,109,108,105,110,107,0,42,42,42,32,101,114,114,111,114,32,99,114,101,97,116,105,110,103,32,115,121,109,108,105,110,107,32,37,115,32,45,62,32,37,115,10,0,0,0,0,99,104,97,114,45,112,116,121,58,32,37,115,10,0,0,0,102,105,108,101,0,0,0,0,102,108,117,115,104,0,0,0,45,0,0,0,0,0,0,0,119,98,0,0,0,0,0,0,230,41,1,0,14,17,1,0,52,248,0,0,102,223,0,0,150,198,0,0,0,0,0,0,150,151,154,155,157,158,159,166,167,171,172,173,174,175,178,179,180,181,182,183,185,186,187,188,189,190,191,203,205,206,207,211,214,215,217,218,219,220,221,222,223,229,230,231,233,234,235,236,237,238,239,242,243,244,245,246,247,249,250,251,252,253,254,255,103,99,114,58,32,100,97,116,97,32,99,114,99,32,101,114,114,111,114,32,40,37,117,47,37,117,47,37,117,41,10,0,255,255,255,255,255,255,255,2
|
||
|
/* memory initializer */ allocate([112,114,105,58,32,99,114,99,32,101,114,114,111,114,10,0,112,114,105,58,32,117,110,107,110,111,119,110,32,118,101,114,115,105,111,110,32,110,117,109,98,101,114,32,40,37,108,117,41,10], "i8", ALLOC_NONE, Runtime.GLOBAL_BASE+48560);
|
||
|
/* memory initializer */ allocate([112,114,105,58,32,99,114,99,32,101,114,114,111,114,10,0,112,114,105,58,32,117,110,107,110,111,119,110,32,118,101,114,115,105,111,110,32,110,117,109,98,101,114,32,40,37,117,41,10,0,0,0,0,0,0,0,46,97,110,97,0,0,0,0,46,99,112,50,0,0,0,0,46,105,109,97,103,101,0,0,46,105,109,97,0,0,0,0,46,105,109,100,0,0,0,0,46,105,109,103,0,0,0,0,46,109,115,97,0,0,0,0,46,112,102,100,99,0,0,0,46,112,115,105,0,0,0,0,46,114,97,119,0,0,0,0,46,115,116,0,0,0,0,0,46,115,116,120,0,0,0,0,46,116,99,0,0,0,0,0,46,116,100,48,0,0,0,0,46,120,100,102,0,0,0,0,114,98,0,0,0,0,0,0,119,98,0,0,0,0,0,0,0,0,0,0,0,0,0,0,99,112,50,58,32,37,117,47,37,117,47,37,117,58,32,115,101,99,116,111,114,32,100,97,116,97,32,116,111,111,32,98,105,103,32,40,37,117,41,10,0,0,0,0,0,0,0,0,99,112,50,58,32,37,117,47,37,117,47,37,117,58,0,0,32,45,0,0,0,0,0,0,32,37,48,50,88,0,0,0,83,79,70,84,87,65,82,69,32,80,73,82,65,84,69,83,99,112,50,58,32,110,111,116,32,97,32,67,80,50,32,102,105,108,101,10,0,0,0,0,120,195,0,0,136,195,0,0,152,195,0,0,168,195,0,0,184,195,0,0,0,0,0,0,99,112,50,58,32,119,97,114,110,105,110,103,58,32,117,110,107,110,111,119,110,32,67,80,50,32,118,101,114,115,105,111,110,10,0,0,0,0,0,0,82,101,108,101,97,115,101,32,51,46,48,50,36,48,0,0,82,101,108,101,97,115,101,32,51,46,48,55,36,48,0,0,82,101,108,101,97,115,101,32,52,46,48,48,36,48,0,0,82,101,108,101,97,115,101,32,53,46,48,49,36,48,0,0,82,101,108,101,97,115,101,32,54,46,48,10,36,48,0,0,6,78,111,110,97,109,101,0,100,99,52,50,58,32,100,97,116,97,32,99,104,101,99,107,115,117,109,32,101,114,114,111,114,10,0,0,0,0,0,0,100,99,52,50,58,32,116,97,103,32,99,104,101,99,107,115,117,109,32,101,114,114,111,114,10,0,0,0,0,0,0,0,73,77,68,32,49,46,49,55,58,32,37,50,100,47,37,50,100,47,37,52,100,32,37,48,50,100,58,37,48,50,100,58,37,48,50,100,0,0,0,0,112,102,100,99,58,32,119,97,114,110,105,110,103,58,32,108,111,97,100,105,110,103,32,100,101,112,114,101,99,97,116,101,100,32,118,101,114,115,105,111,110,32,48,32,102,105,108,101,10,0,0,0,0,0,0,0,112,102,100,99,58,32,119,97,114,110,105,110,103,58,32,108,111,97,100,105,110,103,32,100,101,112,114,101,99,97,116,101,100,32,118,101,114,115,105,111,110,32,49,32,102,105,108,101,10,0,0,0,0,0,0,0,112,102,100,99,58,32,119,97,114,110,105,110,103,58,32,108,111,97,100,105,110,103,32,100,101,112,114,101,99,97,116,101,100,32,118,101,114,115,105,111,110,32,50,32,102,105,108,101,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,112,102,100,99,58,32,99,114,99,32,101,114,114,111,114,10,0,0,0,0,0,0,0,0,112,102,100,99,58,32,111,114,112,104,97,110,101,100,32,97,108,116,101,114,110,97,116,101,32,115,101,99,116,111,114,10,0,0,0,0,0,0,0,0,112,102,100,99,58,32,117,110,107,110,111,119,110,32,118,101,114,115,105,111,110,32,40,37,108,117,41,10], "i8", ALLOC_NONE, Runtime.GLOBAL_BASE+49648);
|
||
|
/* memory initializer */ allocate([112,115,105,58,32,99,114,99,32,101,114,114,111,114,10,0,112,115,105,58,32,111,114,112,104,97,110,101,100,32,97,108,116,101,114,110,97,116,101,32,115,101,99,116,111,114,10,0,112,115,105,58,32,117,110,107,110,111,119,110,32,118,101,114,115,105,111,110,32,40,37,108,117,41,10,0,0,0,0,0,0,128,2,0,40,0,0,0,1,0,0,0,8,0,0,0,0,2,0,0,2,0,0,0,0,208,2,0,40,0,0,0,1,0,0,0,9,0,0,0,0,2,0,0,2,0,0,0,0,0,5,0,40,0,0,0,2,0,0,0,8,0,0,0,0,2,0,0,2,0,0,0,0,160,5,0,40,0,0,0,2,0,0,0,9,0,0,0,0,2,0,0,2,0,0,0,0,0,10,0,80,0,0,0,2,0,0,0,8,0,0,0,0,2,0,0,2,0,0,0,0,64,11,0,80,0,0,0,2,0,0,0,9,0,0,0,0,2,0,0,2,0,0,0,0,128,12,0,80,0,0,0,2,0,0,0,10,0,0,0,0,2,0,0,2,0,0,0,0,192,18,0,80,0,0,0,2,0,0,0,15,0,0,0,0,2,0,0,2,128,0,0,0,128,22,0,80,0,0,0,2,0,0,0,18,0,0,0,0,2,0,0,2,128,0,0,0,0,45,0,80,0,0,0,2,0,0,0,36,0,0,0,0,2,0,0,2,128,0,0,0,64,19,0,77,0,0,0,2,0,0,0,8,0,0,0,0,4,0,0,2,128,0,0,0,233,3,0,77,0,0,0,1,0,0,0,26,0,0,0,128,0,0,0,1,128,0,0,0,210,7,0,77,0,0,0,2,0,0,0,26,0,0,0,128,0,0,0,1,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,80,0,0,0,1,0,0,0,8,0,0,0,0,2,0,0,2,0,0,0,0,160,5,0,80,0,0,0,1,0,0,0,9,0,0,0,0,2,0,0,2,0,0,0,0,178,5,0,81,0,0,0,1,0,0,0,9,0,0,0,0,2,0,0,2,0,0,0,0,196,5,0,82,0,0,0,1,0,0,0,9,0,0,0,0,2,0,0,2,0,0,0,0,214,5,0,83,0,0,0,1,0,0,0,9,0,0,0,0,2,0,0,2,0,0,0,0,64,6,0,80,0,0,0,1,0,0,0,10,0,0,0,0,2,0,0,2,0,0,0,0,84,6,0,81,0,0,0,1,0,0,0,10,0,0,0,0,2,0,0,2,0,0,0,0,104,6,0,82,0,0,0,1,0,0,0,10,0,0,0,0,2,0,0,2,0,0,0,0,124,6,0,83,0,0,0,1,0,0,0,10,0,0,0,0,2,0,0,2,0,0,0,0,224,6,0,80,0,0,0,1,0,0,0,11,0,0,0,0,2,0,0,2,0,0,0,0,246,6,0,81,0,0,0,1,0,0,0,11,0,0,0,0,2,0,0,2,0,0,0,0,12,7,0,82,0,0,0,1,0,0,0,11,0,0,0,0,2,0,0,2,0,0,0,0,34,7,0,83,0,0,0,1,0,0,0,11,0,0,0,0,2,0,0,2,0,0,0,0,0,10,0,80,0,0,0,2,0,0,0,8,0,0,0,0,2,0,0,2,0,0,0,0,64,11,0,80,0,0,0,2,0,0,0,9,0,0,0,0,2,0,0,2,0,0,0,0,100,11,0,81,0,0,0,2,0,0,0,9,0,0,0,0,2,0,0,2,0,0,0,0,136,11,0,82,0,0,0,2,0,0,0,9,0,0,0,0,2,0,0,2,0,0,0,0,172,11,0,83,0,0,0,2,0,0,0,9,0,0,0,0,2,0,0,2,0,0,0,0,128,12,0,80,0,0,0,2,0,0,0,10,0,0,0,0,2,0,0,2,0,0,0,0,168,12,0,81,0,0,0,2,0,0,0,10,0,0,0,0,2,0,0,2,0,0,0,0,208,12,0,82,0,0,0,2,0,0,0,10,0,0,0,0,2,0,0,2,0,0,0,0,248,12,0,83,0,0,0,2,0,0,0,10,0,0,0,0,2,0,0,2,0,0,0,0,192,13,0,80,0,0,0,2,0,0,0,11,0,0,0,0,2,0,0,2,0,0,0,0,236,13,0,81,0,0,0,2,0,0,0,11,0,0,0,0,2,0,0,2,0,0,0,0,24,14,0,82,0,0,0,2,0,0,0,11,0,0,0,0,2,0,0,2,0,0,0,0,68,14,0,83,0,0,0,2,0,0,0,11,0,0,0,0,2,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,115,116,120,58,32,98,97,100,32,109,97,103,105,99,10,0,115,116,120,58,32,114,101,97,100,32,101,114,114,111,114,32,40,116,114,97,99,107,32,104,101,97,100,101,114,41,10,0,115,116,120,58,32,114,101,97,100,32,101,114,114,111,114,32,40,115,101,99,116,111,114,32,104,101,97,100,101,114,41,10,0,0,0,0,0,0,0,0,37,117,47,37,117,47,37,117,10,0,0,0,0,0,0,0,115,116,120,58,32,114,101,97,100,32,101,114,114,111,114,32,40,115,101,99,116,111,114,32,100,97,116,97,41,10,0,0,116,99,58,32,117,110,107,110,111,119,110,32,109,97,114,107,32,48,120,37,48,50,120,32,40,37,115,44,32,99,61,37,117,44,32,104,61,37,117,44,32,98,105,116,61,37,108,117,47,37,108,117,41,10,0,0,102,109,0,0,0,0,0,0,109,102,109,0,0,0,0,0,116,100,48,58,32,97,100,118,97,110,99,101,100,32,99,111,109,112,114,101,115,115,105,111,110,32,110,111,116,32,115,117,112,112,111,114,116,101,100,10,0,0,0,0,0,0,0,0,116,100,48,58,32,104,101,97,100,101,114,32,99,114,99,32,40,37,48,52,88,32,37,48,52,88,41,10,0,0,0,0,116,100,48,58,32,116,114,97,99,107,32,99,114,99,32,40,37,48,50,88,32,37,48,52,88,41,10,0,0,0,0,0,116,100,48,58,32,99,114,99,32,101,114,114,111,114,32,97,116,32,115,101,99,116,111,114,32,37,117,47,37,117,47,37,117,32,40,110,111,32,100,97,116,97,41,10,0,0,0,0,116,100,48,58,32,122,101,114,111,32,100,97,116,97,32,108,101,110,103,116,104,32,40,37,117,47,37,117,47,37,117,41,10,0,0,0,0,0,0,0,116,100,48,58,32,117,110,107,110,111,119,110,32,99,111,109,112,114,101,115,115,105,111,110,32,40,37,117,47,37,117,47,37,117,32,37,117,41,10,0,116,100,48,58,32,115,101,99,116,111,114,32,99,114,99,32,111,118,101,114,32,104,101,97,100,101,114,43,100,97,116,97,10,0,0,0,0,0,0,0,116,100,48,58,32,99,114,99,32,101,114,
|
||
|
/* memory initializer */ allocate([101,109,117,46,101,120,105,116,0,0,0,0,0,0,0,0,49,0,0,0,0,0,0,0,101,109,117,46,115,116,111,112,0,0,0,0,0,0,0,0,115,100,108,58,32,107,101,121,32,61,32,48,120,37,48,52,120,10,0,0,0,0,0,0,115,100,108,58,32,98,108,105,116,32,101,114,114,111,114,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,116,101,114,109,46,103,114,97,98,0,0,0,0,0,0,0,116,101,114,109,46,114,101,108,101,97,115,101,0,0,0,0,116,101,114,109,46,116,105,116,108,101,0,0,0,0,0,0,116,101,114,109,46,115,101,116,95,98,111,114,100,101,114,95,120,0,0,0,0,0,0,0,116,101,114,109,46,115,101,116,95,98,111,114,100,101,114,95,121,0,0,0,0,0,0,0,116,101,114,109,46,102,117,108,108,115,99,114,101,101,110,46,116,111,103,103,108,101,0,0,116,101,114,109,46,102,117,108,108,115,99,114,101,101,110,0,112,99,101,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], "i8", ALLOC_NONE, Runtime.GLOBAL_BASE+62808);
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
var tempDoublePtr = Runtime.alignMemory(allocate(12, "i8", ALLOC_STATIC), 8);
|
||
|
|
||
|
assert(tempDoublePtr % 8 == 0);
|
||
|
|
||
|
function copyTempFloat(ptr) { // functions, because inlining this code increases code size too much
|
||
|
|
||
|
HEAP8[tempDoublePtr] = HEAP8[ptr];
|
||
|
|
||
|
HEAP8[tempDoublePtr+1] = HEAP8[ptr+1];
|
||
|
|
||
|
HEAP8[tempDoublePtr+2] = HEAP8[ptr+2];
|
||
|
|
||
|
HEAP8[tempDoublePtr+3] = HEAP8[ptr+3];
|
||
|
|
||
|
}
|
||
|
|
||
|
function copyTempDouble(ptr) {
|
||
|
|
||
|
HEAP8[tempDoublePtr] = HEAP8[ptr];
|
||
|
|
||
|
HEAP8[tempDoublePtr+1] = HEAP8[ptr+1];
|
||
|
|
||
|
HEAP8[tempDoublePtr+2] = HEAP8[ptr+2];
|
||
|
|
||
|
HEAP8[tempDoublePtr+3] = HEAP8[ptr+3];
|
||
|
|
||
|
HEAP8[tempDoublePtr+4] = HEAP8[ptr+4];
|
||
|
|
||
|
HEAP8[tempDoublePtr+5] = HEAP8[ptr+5];
|
||
|
|
||
|
HEAP8[tempDoublePtr+6] = HEAP8[ptr+6];
|
||
|
|
||
|
HEAP8[tempDoublePtr+7] = HEAP8[ptr+7];
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
Module["_i64Subtract"] = _i64Subtract;
|
||
|
|
||
|
|
||
|
Module["_i64Add"] = _i64Add;
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
var ERRNO_CODES={EPERM:1,ENOENT:2,ESRCH:3,EINTR:4,EIO:5,ENXIO:6,E2BIG:7,ENOEXEC:8,EBADF:9,ECHILD:10,EAGAIN:11,EWOULDBLOCK:11,ENOMEM:12,EACCES:13,EFAULT:14,ENOTBLK:15,EBUSY:16,EEXIST:17,EXDEV:18,ENODEV:19,ENOTDIR:20,EISDIR:21,EINVAL:22,ENFILE:23,EMFILE:24,ENOTTY:25,ETXTBSY:26,EFBIG:27,ENOSPC:28,ESPIPE:29,EROFS:30,EMLINK:31,EPIPE:32,EDOM:33,ERANGE:34,ENOMSG:42,EIDRM:43,ECHRNG:44,EL2NSYNC:45,EL3HLT:46,EL3RST:47,ELNRNG:48,EUNATCH:49,ENOCSI:50,EL2HLT:51,EDEADLK:35,ENOLCK:37,EBADE:52,EBADR:53,EXFULL:54,ENOANO:55,EBADRQC:56,EBADSLT:57,EDEADLOCK:35,EBFONT:59,ENOSTR:60,ENODATA:61,ETIME:62,ENOSR:63,ENONET:64,ENOPKG:65,EREMOTE:66,ENOLINK:67,EADV:68,ESRMNT:69,ECOMM:70,EPROTO:71,EMULTIHOP:72,EDOTDOT:73,EBADMSG:74,ENOTUNIQ:76,EBADFD:77,EREMCHG:78,ELIBACC:79,ELIBBAD:80,ELIBSCN:81,ELIBMAX:82,ELIBEXEC:83,ENOSYS:38,ENOTEMPTY:39,ENAMETOOLONG:36,ELOOP:40,EOPNOTSUPP:95,EPFNOSUPPORT:96,ECONNRESET:104,ENOBUFS:105,EAFNOSUPPORT:97,EPROTOTYPE:91,ENOTSOCK:88,ENOPROTOOPT:92,ESHUTDOWN:108,ECONNREFUSED:111,EADDRINUSE:98,ECONNABORTED:103,ENETUNREACH:101,ENETDOWN:100,ETIMEDOUT:110,EHOSTDOWN:112,EHOSTUNREACH:113,EINPROGRESS:115,EALREADY:114,EDESTADDRREQ:89,EMSGSIZE:90,EPROTONOSUPPORT:93,ESOCKTNOSUPPORT:94,EADDRNOTAVAIL:99,ENETRESET:102,EISCONN:106,ENOTCONN:107,ETOOMANYREFS:109,EUSERS:87,EDQUOT:122,ESTALE:116,ENOTSUP:95,ENOMEDIUM:123,EILSEQ:84,EOVERFLOW:75,ECANCELED:125,ENOTRECOVERABLE:131,EOWNERDEAD:130,ESTRPIPE:86};
|
||
|
|
||
|
var ERRNO_MESSAGES={0:"Success",1:"Not super-user",2:"No such file or directory",3:"No such process",4:"Interrupted system call",5:"I/O error",6:"No such device or address",7:"Arg list too long",8:"Exec format error",9:"Bad file number",10:"No children",11:"No more processes",12:"Not enough core",13:"Permission denied",14:"Bad address",15:"Block device required",16:"Mount device busy",17:"File exists",18:"Cross-device link",19:"No such device",20:"Not a directory",21:"Is a directory",22:"Invalid argument",23:"Too many open files in system",24:"Too many open files",25:"Not a typewriter",26:"Text file busy",27:"File too large",28:"No space left on device",29:"Illegal seek",30:"Read only file system",31:"Too many links",32:"Broken pipe",33:"Math arg out of domain of func",34:"Math result not representable",35:"File locking deadlock error",36:"File or path name too long",37:"No record locks available",38:"Function not implemented",39:"Directory not empty",40:"Too many symbolic links",42:"No message of desired type",43:"Identifier removed",44:"Channel number out of range",45:"Level 2 not synchronized",46:"Level 3 halted",47:"Level 3 reset",48:"Link number out of range",49:"Protocol driver not attached",50:"No CSI structure available",51:"Level 2 halted",52:"Invalid exchange",53:"Invalid request descriptor",54:"Exchange full",55:"No anode",56:"Invalid request code",57:"Invalid slot",59:"Bad font file fmt",60:"Device not a stream",61:"No data (for no delay io)",62:"Timer expired",63:"Out of streams resources",64:"Machine is not on the network",65:"Package not installed",66:"The object is remote",67:"The link has been severed",68:"Advertise error",69:"Srmount error",70:"Communication error on send",71:"Protocol error",72:"Multihop attempted",73:"Cross mount point (not really error)",74:"Trying to read unreadable message",75:"Value too large for defined data type",76:"Given log. name not unique",77:"f.d. invalid for this operation",78:"Remote address changed",79:"Can access a needed shared lib",80:"Accessing a corrupted shared lib",81:".lib section in a.out corrupted",82:"Attempting to link in too many libs",83:"Attempting to exec a shared library",84:"Illegal byte sequence",86:"Streams pipe error",87:"Too many users",88:"Socket operation on non-socket",89:"Destination address required",90:"Message too long",91:"Protocol wrong type for socket",92:"Protocol not available",93:"Unknown protocol",94:"Socket type not supported",95:"Not supported",96:"Protocol family not supported",97:"Address family not supported by protocol family",98:"Address already in use",99:"Address not available",100:"Network interface is not configured",101:"Network is unreachable",102:"Connection reset by network",103:"Connection aborted",104:"Connection reset by peer",105:"No buffer space available",106:"Socket is already connected",107:"Socket is not connected",108:"Can't send after socket shutdown",109:"Too many references",110:"Connection timed out",111:"Connection refused",112:"Host is down",113:"Host is unreachable",114:"Socket already connected",115:"Connection already in progress",116:"Stale file handle",122:"Quota exceeded",123:"No medium (in tape drive)",125:"Operation canceled",130:"Previous owner died",131:"State not recoverable"};
|
||
|
|
||
|
|
||
|
var ___errno_state=0;function ___setErrNo(value) {
|
||
|
// For convenient setting and returning of errno.
|
||
|
HEAP32[((___errno_state)>>2)]=value;
|
||
|
return value;
|
||
|
}
|
||
|
|
||
|
var PATH={splitPath:function (filename) {
|
||
|
var splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
|
||
|
return splitPathRe.exec(filename).slice(1);
|
||
|
},normalizeArray:function (parts, allowAboveRoot) {
|
||
|
// if the path tries to go above the root, `up` ends up > 0
|
||
|
var up = 0;
|
||
|
for (var i = parts.length - 1; i >= 0; i--) {
|
||
|
var last = parts[i];
|
||
|
if (last === '.') {
|
||
|
parts.splice(i, 1);
|
||
|
} else if (last === '..') {
|
||
|
parts.splice(i, 1);
|
||
|
up++;
|
||
|
} else if (up) {
|
||
|
parts.splice(i, 1);
|
||
|
up--;
|
||
|
}
|
||
|
}
|
||
|
// if the path is allowed to go above the root, restore leading ..s
|
||
|
if (allowAboveRoot) {
|
||
|
for (; up--; up) {
|
||
|
parts.unshift('..');
|
||
|
}
|
||
|
}
|
||
|
return parts;
|
||
|
},normalize:function (path) {
|
||
|
var isAbsolute = path.charAt(0) === '/',
|
||
|
trailingSlash = path.substr(-1) === '/';
|
||
|
// Normalize the path
|
||
|
path = PATH.normalizeArray(path.split('/').filter(function(p) {
|
||
|
return !!p;
|
||
|
}), !isAbsolute).join('/');
|
||
|
if (!path && !isAbsolute) {
|
||
|
path = '.';
|
||
|
}
|
||
|
if (path && trailingSlash) {
|
||
|
path += '/';
|
||
|
}
|
||
|
return (isAbsolute ? '/' : '') + path;
|
||
|
},dirname:function (path) {
|
||
|
var result = PATH.splitPath(path),
|
||
|
root = result[0],
|
||
|
dir = result[1];
|
||
|
if (!root && !dir) {
|
||
|
// No dirname whatsoever
|
||
|
return '.';
|
||
|
}
|
||
|
if (dir) {
|
||
|
// It has a dirname, strip trailing slash
|
||
|
dir = dir.substr(0, dir.length - 1);
|
||
|
}
|
||
|
return root + dir;
|
||
|
},basename:function (path) {
|
||
|
// EMSCRIPTEN return '/'' for '/', not an empty string
|
||
|
if (path === '/') return '/';
|
||
|
var lastSlash = path.lastIndexOf('/');
|
||
|
if (lastSlash === -1) return path;
|
||
|
return path.substr(lastSlash+1);
|
||
|
},extname:function (path) {
|
||
|
return PATH.splitPath(path)[3];
|
||
|
},join:function () {
|
||
|
var paths = Array.prototype.slice.call(arguments, 0);
|
||
|
return PATH.normalize(paths.join('/'));
|
||
|
},join2:function (l, r) {
|
||
|
return PATH.normalize(l + '/' + r);
|
||
|
},resolve:function () {
|
||
|
var resolvedPath = '',
|
||
|
resolvedAbsolute = false;
|
||
|
for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
||
|
var path = (i >= 0) ? arguments[i] : FS.cwd();
|
||
|
// Skip empty and invalid entries
|
||
|
if (typeof path !== 'string') {
|
||
|
throw new TypeError('Arguments to path.resolve must be strings');
|
||
|
} else if (!path) {
|
||
|
continue;
|
||
|
}
|
||
|
resolvedPath = path + '/' + resolvedPath;
|
||
|
resolvedAbsolute = path.charAt(0) === '/';
|
||
|
}
|
||
|
// At this point the path should be resolved to a full absolute path, but
|
||
|
// handle relative paths to be safe (might happen when process.cwd() fails)
|
||
|
resolvedPath = PATH.normalizeArray(resolvedPath.split('/').filter(function(p) {
|
||
|
return !!p;
|
||
|
}), !resolvedAbsolute).join('/');
|
||
|
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
|
||
|
},relative:function (from, to) {
|
||
|
from = PATH.resolve(from).substr(1);
|
||
|
to = PATH.resolve(to).substr(1);
|
||
|
function trim(arr) {
|
||
|
var start = 0;
|
||
|
for (; start < arr.length; start++) {
|
||
|
if (arr[start] !== '') break;
|
||
|
}
|
||
|
var end = arr.length - 1;
|
||
|
for (; end >= 0; end--) {
|
||
|
if (arr[end] !== '') break;
|
||
|
}
|
||
|
if (start > end) return [];
|
||
|
return arr.slice(start, end - start + 1);
|
||
|
}
|
||
|
var fromParts = trim(from.split('/'));
|
||
|
var toParts = trim(to.split('/'));
|
||
|
var length = Math.min(fromParts.length, toParts.length);
|
||
|
var samePartsLength = length;
|
||
|
for (var i = 0; i < length; i++) {
|
||
|
if (fromParts[i] !== toParts[i]) {
|
||
|
samePartsLength = i;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
var outputParts = [];
|
||
|
for (var i = samePartsLength; i < fromParts.length; i++) {
|
||
|
outputParts.push('..');
|
||
|
}
|
||
|
outputParts = outputParts.concat(toParts.slice(samePartsLength));
|
||
|
return outputParts.join('/');
|
||
|
}};
|
||
|
|
||
|
var TTY={ttys:[],init:function () {
|
||
|
// https://github.com/kripken/emscripten/pull/1555
|
||
|
// if (ENVIRONMENT_IS_NODE) {
|
||
|
// // currently, FS.init does not distinguish if process.stdin is a file or TTY
|
||
|
// // device, it always assumes it's a TTY device. because of this, we're forcing
|
||
|
// // process.stdin to UTF8 encoding to at least make stdin reading compatible
|
||
|
// // with text files until FS.init can be refactored.
|
||
|
// process['stdin']['setEncoding']('utf8');
|
||
|
// }
|
||
|
},shutdown:function () {
|
||
|
// https://github.com/kripken/emscripten/pull/1555
|
||
|
// if (ENVIRONMENT_IS_NODE) {
|
||
|
// // inolen: any idea as to why node -e 'process.stdin.read()' wouldn't exit immediately (with process.stdin being a tty)?
|
||
|
// // isaacs: because now it's reading from the stream, you've expressed interest in it, so that read() kicks off a _read() which creates a ReadReq operation
|
||
|
// // inolen: I thought read() in that case was a synchronous operation that just grabbed some amount of buffered data if it exists?
|
||
|
// // isaacs: it is. but it also triggers a _read() call, which calls readStart() on the handle
|
||
|
// // isaacs: do process.stdin.pause() and i'd think it'd probably close the pending call
|
||
|
// process['stdin']['pause']();
|
||
|
// }
|
||
|
},register:function (dev, ops) {
|
||
|
TTY.ttys[dev] = { input: [], output: [], ops: ops };
|
||
|
FS.registerDevice(dev, TTY.stream_ops);
|
||
|
},stream_ops:{open:function (stream) {
|
||
|
var tty = TTY.ttys[stream.node.rdev];
|
||
|
if (!tty) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ENODEV);
|
||
|
}
|
||
|
stream.tty = tty;
|
||
|
stream.seekable = false;
|
||
|
},close:function (stream) {
|
||
|
// flush any pending line data
|
||
|
if (stream.tty.output.length) {
|
||
|
stream.tty.ops.put_char(stream.tty, 10);
|
||
|
}
|
||
|
},read:function (stream, buffer, offset, length, pos /* ignored */) {
|
||
|
if (!stream.tty || !stream.tty.ops.get_char) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ENXIO);
|
||
|
}
|
||
|
var bytesRead = 0;
|
||
|
for (var i = 0; i < length; i++) {
|
||
|
var result;
|
||
|
try {
|
||
|
result = stream.tty.ops.get_char(stream.tty);
|
||
|
} catch (e) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EIO);
|
||
|
}
|
||
|
if (result === undefined && bytesRead === 0) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EAGAIN);
|
||
|
}
|
||
|
if (result === null || result === undefined) break;
|
||
|
bytesRead++;
|
||
|
buffer[offset+i] = result;
|
||
|
}
|
||
|
if (bytesRead) {
|
||
|
stream.node.timestamp = Date.now();
|
||
|
}
|
||
|
return bytesRead;
|
||
|
},write:function (stream, buffer, offset, length, pos) {
|
||
|
if (!stream.tty || !stream.tty.ops.put_char) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ENXIO);
|
||
|
}
|
||
|
for (var i = 0; i < length; i++) {
|
||
|
try {
|
||
|
stream.tty.ops.put_char(stream.tty, buffer[offset+i]);
|
||
|
} catch (e) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EIO);
|
||
|
}
|
||
|
}
|
||
|
if (length) {
|
||
|
stream.node.timestamp = Date.now();
|
||
|
}
|
||
|
return i;
|
||
|
}},default_tty_ops:{get_char:function (tty) {
|
||
|
if (!tty.input.length) {
|
||
|
var result = null;
|
||
|
if (ENVIRONMENT_IS_NODE) {
|
||
|
result = process['stdin']['read']();
|
||
|
if (!result) {
|
||
|
if (process['stdin']['_readableState'] && process['stdin']['_readableState']['ended']) {
|
||
|
return null; // EOF
|
||
|
}
|
||
|
return undefined; // no data available
|
||
|
}
|
||
|
} else if (typeof window != 'undefined' &&
|
||
|
typeof window.prompt == 'function') {
|
||
|
// Browser.
|
||
|
result = window.prompt('Input: '); // returns null on cancel
|
||
|
if (result !== null) {
|
||
|
result += '\n';
|
||
|
}
|
||
|
} else if (typeof readline == 'function') {
|
||
|
// Command line.
|
||
|
result = readline();
|
||
|
if (result !== null) {
|
||
|
result += '\n';
|
||
|
}
|
||
|
}
|
||
|
if (!result) {
|
||
|
return null;
|
||
|
}
|
||
|
tty.input = intArrayFromString(result, true);
|
||
|
}
|
||
|
return tty.input.shift();
|
||
|
},put_char:function (tty, val) {
|
||
|
if (val === null || val === 10) {
|
||
|
Module['print'](tty.output.join(''));
|
||
|
tty.output = [];
|
||
|
} else {
|
||
|
tty.output.push(TTY.utf8.processCChar(val));
|
||
|
}
|
||
|
}},default_tty1_ops:{put_char:function (tty, val) {
|
||
|
if (val === null || val === 10) {
|
||
|
Module['printErr'](tty.output.join(''));
|
||
|
tty.output = [];
|
||
|
} else {
|
||
|
tty.output.push(TTY.utf8.processCChar(val));
|
||
|
}
|
||
|
}}};
|
||
|
|
||
|
var MEMFS={ops_table:null,CONTENT_OWNING:1,CONTENT_FLEXIBLE:2,CONTENT_FIXED:3,mount:function (mount) {
|
||
|
return MEMFS.createNode(null, '/', 16384 | 511 /* 0777 */, 0);
|
||
|
},createNode:function (parent, name, mode, dev) {
|
||
|
if (FS.isBlkdev(mode) || FS.isFIFO(mode)) {
|
||
|
// no supported
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EPERM);
|
||
|
}
|
||
|
if (!MEMFS.ops_table) {
|
||
|
MEMFS.ops_table = {
|
||
|
dir: {
|
||
|
node: {
|
||
|
getattr: MEMFS.node_ops.getattr,
|
||
|
setattr: MEMFS.node_ops.setattr,
|
||
|
lookup: MEMFS.node_ops.lookup,
|
||
|
mknod: MEMFS.node_ops.mknod,
|
||
|
rename: MEMFS.node_ops.rename,
|
||
|
unlink: MEMFS.node_ops.unlink,
|
||
|
rmdir: MEMFS.node_ops.rmdir,
|
||
|
readdir: MEMFS.node_ops.readdir,
|
||
|
symlink: MEMFS.node_ops.symlink
|
||
|
},
|
||
|
stream: {
|
||
|
llseek: MEMFS.stream_ops.llseek
|
||
|
}
|
||
|
},
|
||
|
file: {
|
||
|
node: {
|
||
|
getattr: MEMFS.node_ops.getattr,
|
||
|
setattr: MEMFS.node_ops.setattr
|
||
|
},
|
||
|
stream: {
|
||
|
llseek: MEMFS.stream_ops.llseek,
|
||
|
read: MEMFS.stream_ops.read,
|
||
|
write: MEMFS.stream_ops.write,
|
||
|
allocate: MEMFS.stream_ops.allocate,
|
||
|
mmap: MEMFS.stream_ops.mmap
|
||
|
}
|
||
|
},
|
||
|
link: {
|
||
|
node: {
|
||
|
getattr: MEMFS.node_ops.getattr,
|
||
|
setattr: MEMFS.node_ops.setattr,
|
||
|
readlink: MEMFS.node_ops.readlink
|
||
|
},
|
||
|
stream: {}
|
||
|
},
|
||
|
chrdev: {
|
||
|
node: {
|
||
|
getattr: MEMFS.node_ops.getattr,
|
||
|
setattr: MEMFS.node_ops.setattr
|
||
|
},
|
||
|
stream: FS.chrdev_stream_ops
|
||
|
},
|
||
|
};
|
||
|
}
|
||
|
var node = FS.createNode(parent, name, mode, dev);
|
||
|
if (FS.isDir(node.mode)) {
|
||
|
node.node_ops = MEMFS.ops_table.dir.node;
|
||
|
node.stream_ops = MEMFS.ops_table.dir.stream;
|
||
|
node.contents = {};
|
||
|
} else if (FS.isFile(node.mode)) {
|
||
|
node.node_ops = MEMFS.ops_table.file.node;
|
||
|
node.stream_ops = MEMFS.ops_table.file.stream;
|
||
|
node.contents = [];
|
||
|
node.contentMode = MEMFS.CONTENT_FLEXIBLE;
|
||
|
} else if (FS.isLink(node.mode)) {
|
||
|
node.node_ops = MEMFS.ops_table.link.node;
|
||
|
node.stream_ops = MEMFS.ops_table.link.stream;
|
||
|
} else if (FS.isChrdev(node.mode)) {
|
||
|
node.node_ops = MEMFS.ops_table.chrdev.node;
|
||
|
node.stream_ops = MEMFS.ops_table.chrdev.stream;
|
||
|
}
|
||
|
node.timestamp = Date.now();
|
||
|
// add the new node to the parent
|
||
|
if (parent) {
|
||
|
parent.contents[name] = node;
|
||
|
}
|
||
|
return node;
|
||
|
},ensureFlexible:function (node) {
|
||
|
if (node.contentMode !== MEMFS.CONTENT_FLEXIBLE) {
|
||
|
var contents = node.contents;
|
||
|
node.contents = Array.prototype.slice.call(contents);
|
||
|
node.contentMode = MEMFS.CONTENT_FLEXIBLE;
|
||
|
}
|
||
|
},node_ops:{getattr:function (node) {
|
||
|
var attr = {};
|
||
|
// device numbers reuse inode numbers.
|
||
|
attr.dev = FS.isChrdev(node.mode) ? node.id : 1;
|
||
|
attr.ino = node.id;
|
||
|
attr.mode = node.mode;
|
||
|
attr.nlink = 1;
|
||
|
attr.uid = 0;
|
||
|
attr.gid = 0;
|
||
|
attr.rdev = node.rdev;
|
||
|
if (FS.isDir(node.mode)) {
|
||
|
attr.size = 4096;
|
||
|
} else if (FS.isFile(node.mode)) {
|
||
|
attr.size = node.contents.length;
|
||
|
} else if (FS.isLink(node.mode)) {
|
||
|
attr.size = node.link.length;
|
||
|
} else {
|
||
|
attr.size = 0;
|
||
|
}
|
||
|
attr.atime = new Date(node.timestamp);
|
||
|
attr.mtime = new Date(node.timestamp);
|
||
|
attr.ctime = new Date(node.timestamp);
|
||
|
// NOTE: In our implementation, st_blocks = Math.ceil(st_size/st_blksize),
|
||
|
// but this is not required by the standard.
|
||
|
attr.blksize = 4096;
|
||
|
attr.blocks = Math.ceil(attr.size / attr.blksize);
|
||
|
return attr;
|
||
|
},setattr:function (node, attr) {
|
||
|
if (attr.mode !== undefined) {
|
||
|
node.mode = attr.mode;
|
||
|
}
|
||
|
if (attr.timestamp !== undefined) {
|
||
|
node.timestamp = attr.timestamp;
|
||
|
}
|
||
|
if (attr.size !== undefined) {
|
||
|
MEMFS.ensureFlexible(node);
|
||
|
var contents = node.contents;
|
||
|
if (attr.size < contents.length) contents.length = attr.size;
|
||
|
else while (attr.size > contents.length) contents.push(0);
|
||
|
}
|
||
|
},lookup:function (parent, name) {
|
||
|
throw FS.genericErrors[ERRNO_CODES.ENOENT];
|
||
|
},mknod:function (parent, name, mode, dev) {
|
||
|
return MEMFS.createNode(parent, name, mode, dev);
|
||
|
},rename:function (old_node, new_dir, new_name) {
|
||
|
// if we're overwriting a directory at new_name, make sure it's empty.
|
||
|
if (FS.isDir(old_node.mode)) {
|
||
|
var new_node;
|
||
|
try {
|
||
|
new_node = FS.lookupNode(new_dir, new_name);
|
||
|
} catch (e) {
|
||
|
}
|
||
|
if (new_node) {
|
||
|
for (var i in new_node.contents) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ENOTEMPTY);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
// do the internal rewiring
|
||
|
delete old_node.parent.contents[old_node.name];
|
||
|
old_node.name = new_name;
|
||
|
new_dir.contents[new_name] = old_node;
|
||
|
old_node.parent = new_dir;
|
||
|
},unlink:function (parent, name) {
|
||
|
delete parent.contents[name];
|
||
|
},rmdir:function (parent, name) {
|
||
|
var node = FS.lookupNode(parent, name);
|
||
|
for (var i in node.contents) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ENOTEMPTY);
|
||
|
}
|
||
|
delete parent.contents[name];
|
||
|
},readdir:function (node) {
|
||
|
var entries = ['.', '..']
|
||
|
for (var key in node.contents) {
|
||
|
if (!node.contents.hasOwnProperty(key)) {
|
||
|
continue;
|
||
|
}
|
||
|
entries.push(key);
|
||
|
}
|
||
|
return entries;
|
||
|
},symlink:function (parent, newname, oldpath) {
|
||
|
var node = MEMFS.createNode(parent, newname, 511 /* 0777 */ | 40960, 0);
|
||
|
node.link = oldpath;
|
||
|
return node;
|
||
|
},readlink:function (node) {
|
||
|
if (!FS.isLink(node.mode)) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
||
|
}
|
||
|
return node.link;
|
||
|
}},stream_ops:{read:function (stream, buffer, offset, length, position) {
|
||
|
var contents = stream.node.contents;
|
||
|
if (position >= contents.length)
|
||
|
return 0;
|
||
|
var size = Math.min(contents.length - position, length);
|
||
|
assert(size >= 0);
|
||
|
if (size > 8 && contents.subarray) { // non-trivial, and typed array
|
||
|
buffer.set(contents.subarray(position, position + size), offset);
|
||
|
} else
|
||
|
{
|
||
|
for (var i = 0; i < size; i++) {
|
||
|
buffer[offset + i] = contents[position + i];
|
||
|
}
|
||
|
}
|
||
|
return size;
|
||
|
},write:function (stream, buffer, offset, length, position, canOwn) {
|
||
|
var node = stream.node;
|
||
|
node.timestamp = Date.now();
|
||
|
var contents = node.contents;
|
||
|
if (length && contents.length === 0 && position === 0 && buffer.subarray) {
|
||
|
// just replace it with the new data
|
||
|
if (canOwn && offset === 0) {
|
||
|
node.contents = buffer; // this could be a subarray of Emscripten HEAP, or allocated from some other source.
|
||
|
node.contentMode = (buffer.buffer === HEAP8.buffer) ? MEMFS.CONTENT_OWNING : MEMFS.CONTENT_FIXED;
|
||
|
} else {
|
||
|
node.contents = new Uint8Array(buffer.subarray(offset, offset+length));
|
||
|
node.contentMode = MEMFS.CONTENT_FIXED;
|
||
|
}
|
||
|
return length;
|
||
|
}
|
||
|
MEMFS.ensureFlexible(node);
|
||
|
var contents = node.contents;
|
||
|
while (contents.length < position) contents.push(0);
|
||
|
for (var i = 0; i < length; i++) {
|
||
|
contents[position + i] = buffer[offset + i];
|
||
|
}
|
||
|
return length;
|
||
|
},llseek:function (stream, offset, whence) {
|
||
|
var position = offset;
|
||
|
if (whence === 1) { // SEEK_CUR.
|
||
|
position += stream.position;
|
||
|
} else if (whence === 2) { // SEEK_END.
|
||
|
if (FS.isFile(stream.node.mode)) {
|
||
|
position += stream.node.contents.length;
|
||
|
}
|
||
|
}
|
||
|
if (position < 0) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
||
|
}
|
||
|
stream.ungotten = [];
|
||
|
stream.position = position;
|
||
|
return position;
|
||
|
},allocate:function (stream, offset, length) {
|
||
|
MEMFS.ensureFlexible(stream.node);
|
||
|
var contents = stream.node.contents;
|
||
|
var limit = offset + length;
|
||
|
while (limit > contents.length) contents.push(0);
|
||
|
},mmap:function (stream, buffer, offset, length, position, prot, flags) {
|
||
|
if (!FS.isFile(stream.node.mode)) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ENODEV);
|
||
|
}
|
||
|
var ptr;
|
||
|
var allocated;
|
||
|
var contents = stream.node.contents;
|
||
|
// Only make a new copy when MAP_PRIVATE is specified.
|
||
|
if ( !(flags & 2) &&
|
||
|
(contents.buffer === buffer || contents.buffer === buffer.buffer) ) {
|
||
|
// We can't emulate MAP_SHARED when the file is not backed by the buffer
|
||
|
// we're mapping to (e.g. the HEAP buffer).
|
||
|
allocated = false;
|
||
|
ptr = contents.byteOffset;
|
||
|
} else {
|
||
|
// Try to avoid unnecessary slices.
|
||
|
if (position > 0 || position + length < contents.length) {
|
||
|
if (contents.subarray) {
|
||
|
contents = contents.subarray(position, position + length);
|
||
|
} else {
|
||
|
contents = Array.prototype.slice.call(contents, position, position + length);
|
||
|
}
|
||
|
}
|
||
|
allocated = true;
|
||
|
ptr = _malloc(length);
|
||
|
if (!ptr) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ENOMEM);
|
||
|
}
|
||
|
buffer.set(contents, ptr);
|
||
|
}
|
||
|
return { ptr: ptr, allocated: allocated };
|
||
|
}}};
|
||
|
|
||
|
var IDBFS={dbs:{},indexedDB:function () {
|
||
|
return window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
|
||
|
},DB_VERSION:21,DB_STORE_NAME:"FILE_DATA",mount:function (mount) {
|
||
|
// reuse all of the core MEMFS functionality
|
||
|
return MEMFS.mount.apply(null, arguments);
|
||
|
},syncfs:function (mount, populate, callback) {
|
||
|
IDBFS.getLocalSet(mount, function(err, local) {
|
||
|
if (err) return callback(err);
|
||
|
|
||
|
IDBFS.getRemoteSet(mount, function(err, remote) {
|
||
|
if (err) return callback(err);
|
||
|
|
||
|
var src = populate ? remote : local;
|
||
|
var dst = populate ? local : remote;
|
||
|
|
||
|
IDBFS.reconcile(src, dst, callback);
|
||
|
});
|
||
|
});
|
||
|
},getDB:function (name, callback) {
|
||
|
// check the cache first
|
||
|
var db = IDBFS.dbs[name];
|
||
|
if (db) {
|
||
|
return callback(null, db);
|
||
|
}
|
||
|
|
||
|
var req;
|
||
|
try {
|
||
|
req = IDBFS.indexedDB().open(name, IDBFS.DB_VERSION);
|
||
|
} catch (e) {
|
||
|
return callback(e);
|
||
|
}
|
||
|
req.onupgradeneeded = function(e) {
|
||
|
var db = e.target.result;
|
||
|
var transaction = e.target.transaction;
|
||
|
|
||
|
var fileStore;
|
||
|
|
||
|
if (db.objectStoreNames.contains(IDBFS.DB_STORE_NAME)) {
|
||
|
fileStore = transaction.objectStore(IDBFS.DB_STORE_NAME);
|
||
|
} else {
|
||
|
fileStore = db.createObjectStore(IDBFS.DB_STORE_NAME);
|
||
|
}
|
||
|
|
||
|
fileStore.createIndex('timestamp', 'timestamp', { unique: false });
|
||
|
};
|
||
|
req.onsuccess = function() {
|
||
|
db = req.result;
|
||
|
|
||
|
// add to the cache
|
||
|
IDBFS.dbs[name] = db;
|
||
|
callback(null, db);
|
||
|
};
|
||
|
req.onerror = function() {
|
||
|
callback(this.error);
|
||
|
};
|
||
|
},getLocalSet:function (mount, callback) {
|
||
|
var entries = {};
|
||
|
|
||
|
function isRealDir(p) {
|
||
|
return p !== '.' && p !== '..';
|
||
|
};
|
||
|
function toAbsolute(root) {
|
||
|
return function(p) {
|
||
|
return PATH.join2(root, p);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
var check = FS.readdir(mount.mountpoint).filter(isRealDir).map(toAbsolute(mount.mountpoint));
|
||
|
|
||
|
while (check.length) {
|
||
|
var path = check.pop();
|
||
|
var stat;
|
||
|
|
||
|
try {
|
||
|
stat = FS.stat(path);
|
||
|
} catch (e) {
|
||
|
return callback(e);
|
||
|
}
|
||
|
|
||
|
if (FS.isDir(stat.mode)) {
|
||
|
check.push.apply(check, FS.readdir(path).filter(isRealDir).map(toAbsolute(path)));
|
||
|
}
|
||
|
|
||
|
entries[path] = { timestamp: stat.mtime };
|
||
|
}
|
||
|
|
||
|
return callback(null, { type: 'local', entries: entries });
|
||
|
},getRemoteSet:function (mount, callback) {
|
||
|
var entries = {};
|
||
|
|
||
|
IDBFS.getDB(mount.mountpoint, function(err, db) {
|
||
|
if (err) return callback(err);
|
||
|
|
||
|
var transaction = db.transaction([IDBFS.DB_STORE_NAME], 'readonly');
|
||
|
transaction.onerror = function() { callback(this.error); };
|
||
|
|
||
|
var store = transaction.objectStore(IDBFS.DB_STORE_NAME);
|
||
|
var index = store.index('timestamp');
|
||
|
|
||
|
index.openKeyCursor().onsuccess = function(event) {
|
||
|
var cursor = event.target.result;
|
||
|
|
||
|
if (!cursor) {
|
||
|
return callback(null, { type: 'remote', db: db, entries: entries });
|
||
|
}
|
||
|
|
||
|
entries[cursor.primaryKey] = { timestamp: cursor.key };
|
||
|
|
||
|
cursor.continue();
|
||
|
};
|
||
|
});
|
||
|
},loadLocalEntry:function (path, callback) {
|
||
|
var stat, node;
|
||
|
|
||
|
try {
|
||
|
var lookup = FS.lookupPath(path);
|
||
|
node = lookup.node;
|
||
|
stat = FS.stat(path);
|
||
|
} catch (e) {
|
||
|
return callback(e);
|
||
|
}
|
||
|
|
||
|
if (FS.isDir(stat.mode)) {
|
||
|
return callback(null, { timestamp: stat.mtime, mode: stat.mode });
|
||
|
} else if (FS.isFile(stat.mode)) {
|
||
|
return callback(null, { timestamp: stat.mtime, mode: stat.mode, contents: node.contents });
|
||
|
} else {
|
||
|
return callback(new Error('node type not supported'));
|
||
|
}
|
||
|
},storeLocalEntry:function (path, entry, callback) {
|
||
|
try {
|
||
|
if (FS.isDir(entry.mode)) {
|
||
|
FS.mkdir(path, entry.mode);
|
||
|
} else if (FS.isFile(entry.mode)) {
|
||
|
FS.writeFile(path, entry.contents, { encoding: 'binary', canOwn: true });
|
||
|
} else {
|
||
|
return callback(new Error('node type not supported'));
|
||
|
}
|
||
|
|
||
|
FS.utime(path, entry.timestamp, entry.timestamp);
|
||
|
} catch (e) {
|
||
|
return callback(e);
|
||
|
}
|
||
|
|
||
|
callback(null);
|
||
|
},removeLocalEntry:function (path, callback) {
|
||
|
try {
|
||
|
var lookup = FS.lookupPath(path);
|
||
|
var stat = FS.stat(path);
|
||
|
|
||
|
if (FS.isDir(stat.mode)) {
|
||
|
FS.rmdir(path);
|
||
|
} else if (FS.isFile(stat.mode)) {
|
||
|
FS.unlink(path);
|
||
|
}
|
||
|
} catch (e) {
|
||
|
return callback(e);
|
||
|
}
|
||
|
|
||
|
callback(null);
|
||
|
},loadRemoteEntry:function (store, path, callback) {
|
||
|
var req = store.get(path);
|
||
|
req.onsuccess = function(event) { callback(null, event.target.result); };
|
||
|
req.onerror = function() { callback(this.error); };
|
||
|
},storeRemoteEntry:function (store, path, entry, callback) {
|
||
|
var req = store.put(entry, path);
|
||
|
req.onsuccess = function() { callback(null); };
|
||
|
req.onerror = function() { callback(this.error); };
|
||
|
},removeRemoteEntry:function (store, path, callback) {
|
||
|
var req = store.delete(path);
|
||
|
req.onsuccess = function() { callback(null); };
|
||
|
req.onerror = function() { callback(this.error); };
|
||
|
},reconcile:function (src, dst, callback) {
|
||
|
var total = 0;
|
||
|
|
||
|
var create = [];
|
||
|
Object.keys(src.entries).forEach(function (key) {
|
||
|
var e = src.entries[key];
|
||
|
var e2 = dst.entries[key];
|
||
|
if (!e2 || e.timestamp > e2.timestamp) {
|
||
|
create.push(key);
|
||
|
total++;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
var remove = [];
|
||
|
Object.keys(dst.entries).forEach(function (key) {
|
||
|
var e = dst.entries[key];
|
||
|
var e2 = src.entries[key];
|
||
|
if (!e2) {
|
||
|
remove.push(key);
|
||
|
total++;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
if (!total) {
|
||
|
return callback(null);
|
||
|
}
|
||
|
|
||
|
var errored = false;
|
||
|
var completed = 0;
|
||
|
var db = src.type === 'remote' ? src.db : dst.db;
|
||
|
var transaction = db.transaction([IDBFS.DB_STORE_NAME], 'readwrite');
|
||
|
var store = transaction.objectStore(IDBFS.DB_STORE_NAME);
|
||
|
|
||
|
function done(err) {
|
||
|
if (err) {
|
||
|
if (!done.errored) {
|
||
|
done.errored = true;
|
||
|
return callback(err);
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
if (++completed >= total) {
|
||
|
return callback(null);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
transaction.onerror = function() { done(this.error); };
|
||
|
|
||
|
// sort paths in ascending order so directory entries are created
|
||
|
// before the files inside them
|
||
|
create.sort().forEach(function (path) {
|
||
|
if (dst.type === 'local') {
|
||
|
IDBFS.loadRemoteEntry(store, path, function (err, entry) {
|
||
|
if (err) return done(err);
|
||
|
IDBFS.storeLocalEntry(path, entry, done);
|
||
|
});
|
||
|
} else {
|
||
|
IDBFS.loadLocalEntry(path, function (err, entry) {
|
||
|
if (err) return done(err);
|
||
|
IDBFS.storeRemoteEntry(store, path, entry, done);
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// sort paths in descending order so files are deleted before their
|
||
|
// parent directories
|
||
|
remove.sort().reverse().forEach(function(path) {
|
||
|
if (dst.type === 'local') {
|
||
|
IDBFS.removeLocalEntry(path, done);
|
||
|
} else {
|
||
|
IDBFS.removeRemoteEntry(store, path, done);
|
||
|
}
|
||
|
});
|
||
|
}};
|
||
|
|
||
|
var NODEFS={isWindows:false,staticInit:function () {
|
||
|
NODEFS.isWindows = !!process.platform.match(/^win/);
|
||
|
},mount:function (mount) {
|
||
|
assert(ENVIRONMENT_IS_NODE);
|
||
|
return NODEFS.createNode(null, '/', NODEFS.getMode(mount.opts.root), 0);
|
||
|
},createNode:function (parent, name, mode, dev) {
|
||
|
if (!FS.isDir(mode) && !FS.isFile(mode) && !FS.isLink(mode)) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
||
|
}
|
||
|
var node = FS.createNode(parent, name, mode);
|
||
|
node.node_ops = NODEFS.node_ops;
|
||
|
node.stream_ops = NODEFS.stream_ops;
|
||
|
return node;
|
||
|
},getMode:function (path) {
|
||
|
var stat;
|
||
|
try {
|
||
|
stat = fs.lstatSync(path);
|
||
|
if (NODEFS.isWindows) {
|
||
|
// On Windows, directories return permission bits 'rw-rw-rw-', even though they have 'rwxrwxrwx', so
|
||
|
// propagate write bits to execute bits.
|
||
|
stat.mode = stat.mode | ((stat.mode & 146) >> 1);
|
||
|
}
|
||
|
} catch (e) {
|
||
|
if (!e.code) throw e;
|
||
|
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
||
|
}
|
||
|
return stat.mode;
|
||
|
},realPath:function (node) {
|
||
|
var parts = [];
|
||
|
while (node.parent !== node) {
|
||
|
parts.push(node.name);
|
||
|
node = node.parent;
|
||
|
}
|
||
|
parts.push(node.mount.opts.root);
|
||
|
parts.reverse();
|
||
|
return PATH.join.apply(null, parts);
|
||
|
},flagsToPermissionStringMap:{0:"r",1:"r+",2:"r+",64:"r",65:"r+",66:"r+",129:"rx+",193:"rx+",514:"w+",577:"w",578:"w+",705:"wx",706:"wx+",1024:"a",1025:"a",1026:"a+",1089:"a",1090:"a+",1153:"ax",1154:"ax+",1217:"ax",1218:"ax+",4096:"rs",4098:"rs+"},flagsToPermissionString:function (flags) {
|
||
|
if (flags in NODEFS.flagsToPermissionStringMap) {
|
||
|
return NODEFS.flagsToPermissionStringMap[flags];
|
||
|
} else {
|
||
|
return flags;
|
||
|
}
|
||
|
},node_ops:{getattr:function (node) {
|
||
|
var path = NODEFS.realPath(node);
|
||
|
var stat;
|
||
|
try {
|
||
|
stat = fs.lstatSync(path);
|
||
|
} catch (e) {
|
||
|
if (!e.code) throw e;
|
||
|
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
||
|
}
|
||
|
// node.js v0.10.20 doesn't report blksize and blocks on Windows. Fake them with default blksize of 4096.
|
||
|
// See http://support.microsoft.com/kb/140365
|
||
|
if (NODEFS.isWindows && !stat.blksize) {
|
||
|
stat.blksize = 4096;
|
||
|
}
|
||
|
if (NODEFS.isWindows && !stat.blocks) {
|
||
|
stat.blocks = (stat.size+stat.blksize-1)/stat.blksize|0;
|
||
|
}
|
||
|
return {
|
||
|
dev: stat.dev,
|
||
|
ino: stat.ino,
|
||
|
mode: stat.mode,
|
||
|
nlink: stat.nlink,
|
||
|
uid: stat.uid,
|
||
|
gid: stat.gid,
|
||
|
rdev: stat.rdev,
|
||
|
size: stat.size,
|
||
|
atime: stat.atime,
|
||
|
mtime: stat.mtime,
|
||
|
ctime: stat.ctime,
|
||
|
blksize: stat.blksize,
|
||
|
blocks: stat.blocks
|
||
|
};
|
||
|
},setattr:function (node, attr) {
|
||
|
var path = NODEFS.realPath(node);
|
||
|
try {
|
||
|
if (attr.mode !== undefined) {
|
||
|
fs.chmodSync(path, attr.mode);
|
||
|
// update the common node structure mode as well
|
||
|
node.mode = attr.mode;
|
||
|
}
|
||
|
if (attr.timestamp !== undefined) {
|
||
|
var date = new Date(attr.timestamp);
|
||
|
fs.utimesSync(path, date, date);
|
||
|
}
|
||
|
if (attr.size !== undefined) {
|
||
|
fs.truncateSync(path, attr.size);
|
||
|
}
|
||
|
} catch (e) {
|
||
|
if (!e.code) throw e;
|
||
|
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
||
|
}
|
||
|
},lookup:function (parent, name) {
|
||
|
var path = PATH.join2(NODEFS.realPath(parent), name);
|
||
|
var mode = NODEFS.getMode(path);
|
||
|
return NODEFS.createNode(parent, name, mode);
|
||
|
},mknod:function (parent, name, mode, dev) {
|
||
|
var node = NODEFS.createNode(parent, name, mode, dev);
|
||
|
// create the backing node for this in the fs root as well
|
||
|
var path = NODEFS.realPath(node);
|
||
|
try {
|
||
|
if (FS.isDir(node.mode)) {
|
||
|
fs.mkdirSync(path, node.mode);
|
||
|
} else {
|
||
|
fs.writeFileSync(path, '', { mode: node.mode });
|
||
|
}
|
||
|
} catch (e) {
|
||
|
if (!e.code) throw e;
|
||
|
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
||
|
}
|
||
|
return node;
|
||
|
},rename:function (oldNode, newDir, newName) {
|
||
|
var oldPath = NODEFS.realPath(oldNode);
|
||
|
var newPath = PATH.join2(NODEFS.realPath(newDir), newName);
|
||
|
try {
|
||
|
fs.renameSync(oldPath, newPath);
|
||
|
} catch (e) {
|
||
|
if (!e.code) throw e;
|
||
|
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
||
|
}
|
||
|
},unlink:function (parent, name) {
|
||
|
var path = PATH.join2(NODEFS.realPath(parent), name);
|
||
|
try {
|
||
|
fs.unlinkSync(path);
|
||
|
} catch (e) {
|
||
|
if (!e.code) throw e;
|
||
|
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
||
|
}
|
||
|
},rmdir:function (parent, name) {
|
||
|
var path = PATH.join2(NODEFS.realPath(parent), name);
|
||
|
try {
|
||
|
fs.rmdirSync(path);
|
||
|
} catch (e) {
|
||
|
if (!e.code) throw e;
|
||
|
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
||
|
}
|
||
|
},readdir:function (node) {
|
||
|
var path = NODEFS.realPath(node);
|
||
|
try {
|
||
|
return fs.readdirSync(path);
|
||
|
} catch (e) {
|
||
|
if (!e.code) throw e;
|
||
|
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
||
|
}
|
||
|
},symlink:function (parent, newName, oldPath) {
|
||
|
var newPath = PATH.join2(NODEFS.realPath(parent), newName);
|
||
|
try {
|
||
|
fs.symlinkSync(oldPath, newPath);
|
||
|
} catch (e) {
|
||
|
if (!e.code) throw e;
|
||
|
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
||
|
}
|
||
|
},readlink:function (node) {
|
||
|
var path = NODEFS.realPath(node);
|
||
|
try {
|
||
|
return fs.readlinkSync(path);
|
||
|
} catch (e) {
|
||
|
if (!e.code) throw e;
|
||
|
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
||
|
}
|
||
|
}},stream_ops:{open:function (stream) {
|
||
|
var path = NODEFS.realPath(stream.node);
|
||
|
try {
|
||
|
if (FS.isFile(stream.node.mode)) {
|
||
|
stream.nfd = fs.openSync(path, NODEFS.flagsToPermissionString(stream.flags));
|
||
|
}
|
||
|
} catch (e) {
|
||
|
if (!e.code) throw e;
|
||
|
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
||
|
}
|
||
|
},close:function (stream) {
|
||
|
try {
|
||
|
if (FS.isFile(stream.node.mode) && stream.nfd) {
|
||
|
fs.closeSync(stream.nfd);
|
||
|
}
|
||
|
} catch (e) {
|
||
|
if (!e.code) throw e;
|
||
|
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
||
|
}
|
||
|
},read:function (stream, buffer, offset, length, position) {
|
||
|
// FIXME this is terrible.
|
||
|
var nbuffer = new Buffer(length);
|
||
|
var res;
|
||
|
try {
|
||
|
res = fs.readSync(stream.nfd, nbuffer, 0, length, position);
|
||
|
} catch (e) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
||
|
}
|
||
|
if (res > 0) {
|
||
|
for (var i = 0; i < res; i++) {
|
||
|
buffer[offset + i] = nbuffer[i];
|
||
|
}
|
||
|
}
|
||
|
return res;
|
||
|
},write:function (stream, buffer, offset, length, position) {
|
||
|
// FIXME this is terrible.
|
||
|
var nbuffer = new Buffer(buffer.subarray(offset, offset + length));
|
||
|
var res;
|
||
|
try {
|
||
|
res = fs.writeSync(stream.nfd, nbuffer, 0, length, position);
|
||
|
} catch (e) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
||
|
}
|
||
|
return res;
|
||
|
},llseek:function (stream, offset, whence) {
|
||
|
var position = offset;
|
||
|
if (whence === 1) { // SEEK_CUR.
|
||
|
position += stream.position;
|
||
|
} else if (whence === 2) { // SEEK_END.
|
||
|
if (FS.isFile(stream.node.mode)) {
|
||
|
try {
|
||
|
var stat = fs.fstatSync(stream.nfd);
|
||
|
position += stat.size;
|
||
|
} catch (e) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (position < 0) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
||
|
}
|
||
|
|
||
|
stream.position = position;
|
||
|
return position;
|
||
|
}}};
|
||
|
|
||
|
var _stdin=allocate(1, "i32*", ALLOC_STATIC);
|
||
|
|
||
|
var _stdout=allocate(1, "i32*", ALLOC_STATIC);
|
||
|
|
||
|
var _stderr=allocate(1, "i32*", ALLOC_STATIC);
|
||
|
|
||
|
function _fflush(stream) {
|
||
|
// int fflush(FILE *stream);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/fflush.html
|
||
|
// we don't currently perform any user-space buffering of data
|
||
|
}var FS={root:null,mounts:[],devices:[null],streams:[],nextInode:1,nameTable:null,currentPath:"/",initialized:false,ignorePermissions:true,trackingDelegate:{},tracking:{openFlags:{READ:1,WRITE:2}},ErrnoError:null,genericErrors:{},handleFSError:function (e) {
|
||
|
if (!(e instanceof FS.ErrnoError)) throw e + ' : ' + stackTrace();
|
||
|
return ___setErrNo(e.errno);
|
||
|
},lookupPath:function (path, opts) {
|
||
|
path = PATH.resolve(FS.cwd(), path);
|
||
|
opts = opts || {};
|
||
|
|
||
|
var defaults = {
|
||
|
follow_mount: true,
|
||
|
recurse_count: 0
|
||
|
};
|
||
|
for (var key in defaults) {
|
||
|
if (opts[key] === undefined) {
|
||
|
opts[key] = defaults[key];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (opts.recurse_count > 8) { // max recursive lookup of 8
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ELOOP);
|
||
|
}
|
||
|
|
||
|
// split the path
|
||
|
var parts = PATH.normalizeArray(path.split('/').filter(function(p) {
|
||
|
return !!p;
|
||
|
}), false);
|
||
|
|
||
|
// start at the root
|
||
|
var current = FS.root;
|
||
|
var current_path = '/';
|
||
|
|
||
|
for (var i = 0; i < parts.length; i++) {
|
||
|
var islast = (i === parts.length-1);
|
||
|
if (islast && opts.parent) {
|
||
|
// stop resolving
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
current = FS.lookupNode(current, parts[i]);
|
||
|
current_path = PATH.join2(current_path, parts[i]);
|
||
|
|
||
|
// jump to the mount's root node if this is a mountpoint
|
||
|
if (FS.isMountpoint(current)) {
|
||
|
if (!islast || (islast && opts.follow_mount)) {
|
||
|
current = current.mounted.root;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// by default, lookupPath will not follow a symlink if it is the final path component.
|
||
|
// setting opts.follow = true will override this behavior.
|
||
|
if (!islast || opts.follow) {
|
||
|
var count = 0;
|
||
|
while (FS.isLink(current.mode)) {
|
||
|
var link = FS.readlink(current_path);
|
||
|
current_path = PATH.resolve(PATH.dirname(current_path), link);
|
||
|
|
||
|
var lookup = FS.lookupPath(current_path, { recurse_count: opts.recurse_count });
|
||
|
current = lookup.node;
|
||
|
|
||
|
if (count++ > 40) { // limit max consecutive symlinks to 40 (SYMLOOP_MAX).
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ELOOP);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return { path: current_path, node: current };
|
||
|
},getPath:function (node) {
|
||
|
var path;
|
||
|
while (true) {
|
||
|
if (FS.isRoot(node)) {
|
||
|
var mount = node.mount.mountpoint;
|
||
|
if (!path) return mount;
|
||
|
return mount[mount.length-1] !== '/' ? mount + '/' + path : mount + path;
|
||
|
}
|
||
|
path = path ? node.name + '/' + path : node.name;
|
||
|
node = node.parent;
|
||
|
}
|
||
|
},hashName:function (parentid, name) {
|
||
|
var hash = 0;
|
||
|
|
||
|
|
||
|
for (var i = 0; i < name.length; i++) {
|
||
|
hash = ((hash << 5) - hash + name.charCodeAt(i)) | 0;
|
||
|
}
|
||
|
return ((parentid + hash) >>> 0) % FS.nameTable.length;
|
||
|
},hashAddNode:function (node) {
|
||
|
var hash = FS.hashName(node.parent.id, node.name);
|
||
|
node.name_next = FS.nameTable[hash];
|
||
|
FS.nameTable[hash] = node;
|
||
|
},hashRemoveNode:function (node) {
|
||
|
var hash = FS.hashName(node.parent.id, node.name);
|
||
|
if (FS.nameTable[hash] === node) {
|
||
|
FS.nameTable[hash] = node.name_next;
|
||
|
} else {
|
||
|
var current = FS.nameTable[hash];
|
||
|
while (current) {
|
||
|
if (current.name_next === node) {
|
||
|
current.name_next = node.name_next;
|
||
|
break;
|
||
|
}
|
||
|
current = current.name_next;
|
||
|
}
|
||
|
}
|
||
|
},lookupNode:function (parent, name) {
|
||
|
var err = FS.mayLookup(parent);
|
||
|
if (err) {
|
||
|
throw new FS.ErrnoError(err);
|
||
|
}
|
||
|
var hash = FS.hashName(parent.id, name);
|
||
|
for (var node = FS.nameTable[hash]; node; node = node.name_next) {
|
||
|
var nodeName = node.name;
|
||
|
if (node.parent.id === parent.id && nodeName === name) {
|
||
|
return node;
|
||
|
}
|
||
|
}
|
||
|
// if we failed to find it in the cache, call into the VFS
|
||
|
return FS.lookup(parent, name);
|
||
|
},createNode:function (parent, name, mode, rdev) {
|
||
|
if (!FS.FSNode) {
|
||
|
FS.FSNode = function(parent, name, mode, rdev) {
|
||
|
if (!parent) {
|
||
|
parent = this; // root node sets parent to itself
|
||
|
}
|
||
|
this.parent = parent;
|
||
|
this.mount = parent.mount;
|
||
|
this.mounted = null;
|
||
|
this.id = FS.nextInode++;
|
||
|
this.name = name;
|
||
|
this.mode = mode;
|
||
|
this.node_ops = {};
|
||
|
this.stream_ops = {};
|
||
|
this.rdev = rdev;
|
||
|
};
|
||
|
|
||
|
FS.FSNode.prototype = {};
|
||
|
|
||
|
// compatibility
|
||
|
var readMode = 292 | 73;
|
||
|
var writeMode = 146;
|
||
|
|
||
|
// NOTE we must use Object.defineProperties instead of individual calls to
|
||
|
// Object.defineProperty in order to make closure compiler happy
|
||
|
Object.defineProperties(FS.FSNode.prototype, {
|
||
|
read: {
|
||
|
get: function() { return (this.mode & readMode) === readMode; },
|
||
|
set: function(val) { val ? this.mode |= readMode : this.mode &= ~readMode; }
|
||
|
},
|
||
|
write: {
|
||
|
get: function() { return (this.mode & writeMode) === writeMode; },
|
||
|
set: function(val) { val ? this.mode |= writeMode : this.mode &= ~writeMode; }
|
||
|
},
|
||
|
isFolder: {
|
||
|
get: function() { return FS.isDir(this.mode); },
|
||
|
},
|
||
|
isDevice: {
|
||
|
get: function() { return FS.isChrdev(this.mode); },
|
||
|
},
|
||
|
});
|
||
|
}
|
||
|
|
||
|
var node = new FS.FSNode(parent, name, mode, rdev);
|
||
|
|
||
|
FS.hashAddNode(node);
|
||
|
|
||
|
return node;
|
||
|
},destroyNode:function (node) {
|
||
|
FS.hashRemoveNode(node);
|
||
|
},isRoot:function (node) {
|
||
|
return node === node.parent;
|
||
|
},isMountpoint:function (node) {
|
||
|
return !!node.mounted;
|
||
|
},isFile:function (mode) {
|
||
|
return (mode & 61440) === 32768;
|
||
|
},isDir:function (mode) {
|
||
|
return (mode & 61440) === 16384;
|
||
|
},isLink:function (mode) {
|
||
|
return (mode & 61440) === 40960;
|
||
|
},isChrdev:function (mode) {
|
||
|
return (mode & 61440) === 8192;
|
||
|
},isBlkdev:function (mode) {
|
||
|
return (mode & 61440) === 24576;
|
||
|
},isFIFO:function (mode) {
|
||
|
return (mode & 61440) === 4096;
|
||
|
},isSocket:function (mode) {
|
||
|
return (mode & 49152) === 49152;
|
||
|
},flagModes:{"r":0,"rs":1052672,"r+":2,"w":577,"wx":705,"xw":705,"w+":578,"wx+":706,"xw+":706,"a":1089,"ax":1217,"xa":1217,"a+":1090,"ax+":1218,"xa+":1218},modeStringToFlags:function (str) {
|
||
|
var flags = FS.flagModes[str];
|
||
|
if (typeof flags === 'undefined') {
|
||
|
throw new Error('Unknown file open mode: ' + str);
|
||
|
}
|
||
|
return flags;
|
||
|
},flagsToPermissionString:function (flag) {
|
||
|
var accmode = flag & 2097155;
|
||
|
var perms = ['r', 'w', 'rw'][accmode];
|
||
|
if ((flag & 512)) {
|
||
|
perms += 'w';
|
||
|
}
|
||
|
return perms;
|
||
|
},nodePermissions:function (node, perms) {
|
||
|
if (FS.ignorePermissions) {
|
||
|
return 0;
|
||
|
}
|
||
|
// return 0 if any user, group or owner bits are set.
|
||
|
if (perms.indexOf('r') !== -1 && !(node.mode & 292)) {
|
||
|
return ERRNO_CODES.EACCES;
|
||
|
} else if (perms.indexOf('w') !== -1 && !(node.mode & 146)) {
|
||
|
return ERRNO_CODES.EACCES;
|
||
|
} else if (perms.indexOf('x') !== -1 && !(node.mode & 73)) {
|
||
|
return ERRNO_CODES.EACCES;
|
||
|
}
|
||
|
return 0;
|
||
|
},mayLookup:function (dir) {
|
||
|
return FS.nodePermissions(dir, 'x');
|
||
|
},mayCreate:function (dir, name) {
|
||
|
try {
|
||
|
var node = FS.lookupNode(dir, name);
|
||
|
return ERRNO_CODES.EEXIST;
|
||
|
} catch (e) {
|
||
|
}
|
||
|
return FS.nodePermissions(dir, 'wx');
|
||
|
},mayDelete:function (dir, name, isdir) {
|
||
|
var node;
|
||
|
try {
|
||
|
node = FS.lookupNode(dir, name);
|
||
|
} catch (e) {
|
||
|
return e.errno;
|
||
|
}
|
||
|
var err = FS.nodePermissions(dir, 'wx');
|
||
|
if (err) {
|
||
|
return err;
|
||
|
}
|
||
|
if (isdir) {
|
||
|
if (!FS.isDir(node.mode)) {
|
||
|
return ERRNO_CODES.ENOTDIR;
|
||
|
}
|
||
|
if (FS.isRoot(node) || FS.getPath(node) === FS.cwd()) {
|
||
|
return ERRNO_CODES.EBUSY;
|
||
|
}
|
||
|
} else {
|
||
|
if (FS.isDir(node.mode)) {
|
||
|
return ERRNO_CODES.EISDIR;
|
||
|
}
|
||
|
}
|
||
|
return 0;
|
||
|
},mayOpen:function (node, flags) {
|
||
|
if (!node) {
|
||
|
return ERRNO_CODES.ENOENT;
|
||
|
}
|
||
|
if (FS.isLink(node.mode)) {
|
||
|
return ERRNO_CODES.ELOOP;
|
||
|
} else if (FS.isDir(node.mode)) {
|
||
|
if ((flags & 2097155) !== 0 || // opening for write
|
||
|
(flags & 512)) {
|
||
|
return ERRNO_CODES.EISDIR;
|
||
|
}
|
||
|
}
|
||
|
return FS.nodePermissions(node, FS.flagsToPermissionString(flags));
|
||
|
},MAX_OPEN_FDS:4096,nextfd:function (fd_start, fd_end) {
|
||
|
fd_start = fd_start || 0;
|
||
|
fd_end = fd_end || FS.MAX_OPEN_FDS;
|
||
|
for (var fd = fd_start; fd <= fd_end; fd++) {
|
||
|
if (!FS.streams[fd]) {
|
||
|
return fd;
|
||
|
}
|
||
|
}
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EMFILE);
|
||
|
},getStream:function (fd) {
|
||
|
return FS.streams[fd];
|
||
|
},createStream:function (stream, fd_start, fd_end) {
|
||
|
if (!FS.FSStream) {
|
||
|
FS.FSStream = function(){};
|
||
|
FS.FSStream.prototype = {};
|
||
|
// compatibility
|
||
|
Object.defineProperties(FS.FSStream.prototype, {
|
||
|
object: {
|
||
|
get: function() { return this.node; },
|
||
|
set: function(val) { this.node = val; }
|
||
|
},
|
||
|
isRead: {
|
||
|
get: function() { return (this.flags & 2097155) !== 1; }
|
||
|
},
|
||
|
isWrite: {
|
||
|
get: function() { return (this.flags & 2097155) !== 0; }
|
||
|
},
|
||
|
isAppend: {
|
||
|
get: function() { return (this.flags & 1024); }
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
// clone it, so we can return an instance of FSStream
|
||
|
var newStream = new FS.FSStream();
|
||
|
for (var p in stream) {
|
||
|
newStream[p] = stream[p];
|
||
|
}
|
||
|
stream = newStream;
|
||
|
var fd = FS.nextfd(fd_start, fd_end);
|
||
|
stream.fd = fd;
|
||
|
FS.streams[fd] = stream;
|
||
|
return stream;
|
||
|
},closeStream:function (fd) {
|
||
|
FS.streams[fd] = null;
|
||
|
},getStreamFromPtr:function (ptr) {
|
||
|
return FS.streams[ptr - 1];
|
||
|
},getPtrForStream:function (stream) {
|
||
|
return stream ? stream.fd + 1 : 0;
|
||
|
},chrdev_stream_ops:{open:function (stream) {
|
||
|
var device = FS.getDevice(stream.node.rdev);
|
||
|
// override node's stream ops with the device's
|
||
|
stream.stream_ops = device.stream_ops;
|
||
|
// forward the open call
|
||
|
if (stream.stream_ops.open) {
|
||
|
stream.stream_ops.open(stream);
|
||
|
}
|
||
|
},llseek:function () {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ESPIPE);
|
||
|
}},major:function (dev) {
|
||
|
return ((dev) >> 8);
|
||
|
},minor:function (dev) {
|
||
|
return ((dev) & 0xff);
|
||
|
},makedev:function (ma, mi) {
|
||
|
return ((ma) << 8 | (mi));
|
||
|
},registerDevice:function (dev, ops) {
|
||
|
FS.devices[dev] = { stream_ops: ops };
|
||
|
},getDevice:function (dev) {
|
||
|
return FS.devices[dev];
|
||
|
},getMounts:function (mount) {
|
||
|
var mounts = [];
|
||
|
var check = [mount];
|
||
|
|
||
|
while (check.length) {
|
||
|
var m = check.pop();
|
||
|
|
||
|
mounts.push(m);
|
||
|
|
||
|
check.push.apply(check, m.mounts);
|
||
|
}
|
||
|
|
||
|
return mounts;
|
||
|
},syncfs:function (populate, callback) {
|
||
|
if (typeof(populate) === 'function') {
|
||
|
callback = populate;
|
||
|
populate = false;
|
||
|
}
|
||
|
|
||
|
var mounts = FS.getMounts(FS.root.mount);
|
||
|
var completed = 0;
|
||
|
|
||
|
function done(err) {
|
||
|
if (err) {
|
||
|
if (!done.errored) {
|
||
|
done.errored = true;
|
||
|
return callback(err);
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
if (++completed >= mounts.length) {
|
||
|
callback(null);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// sync all mounts
|
||
|
mounts.forEach(function (mount) {
|
||
|
if (!mount.type.syncfs) {
|
||
|
return done(null);
|
||
|
}
|
||
|
mount.type.syncfs(mount, populate, done);
|
||
|
});
|
||
|
},mount:function (type, opts, mountpoint) {
|
||
|
var root = mountpoint === '/';
|
||
|
var pseudo = !mountpoint;
|
||
|
var node;
|
||
|
|
||
|
if (root && FS.root) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EBUSY);
|
||
|
} else if (!root && !pseudo) {
|
||
|
var lookup = FS.lookupPath(mountpoint, { follow_mount: false });
|
||
|
|
||
|
mountpoint = lookup.path; // use the absolute path
|
||
|
node = lookup.node;
|
||
|
|
||
|
if (FS.isMountpoint(node)) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EBUSY);
|
||
|
}
|
||
|
|
||
|
if (!FS.isDir(node.mode)) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ENOTDIR);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var mount = {
|
||
|
type: type,
|
||
|
opts: opts,
|
||
|
mountpoint: mountpoint,
|
||
|
mounts: []
|
||
|
};
|
||
|
|
||
|
// create a root node for the fs
|
||
|
var mountRoot = type.mount(mount);
|
||
|
mountRoot.mount = mount;
|
||
|
mount.root = mountRoot;
|
||
|
|
||
|
if (root) {
|
||
|
FS.root = mountRoot;
|
||
|
} else if (node) {
|
||
|
// set as a mountpoint
|
||
|
node.mounted = mount;
|
||
|
|
||
|
// add the new mount to the current mount's children
|
||
|
if (node.mount) {
|
||
|
node.mount.mounts.push(mount);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return mountRoot;
|
||
|
},unmount:function (mountpoint) {
|
||
|
var lookup = FS.lookupPath(mountpoint, { follow_mount: false });
|
||
|
|
||
|
if (!FS.isMountpoint(lookup.node)) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
||
|
}
|
||
|
|
||
|
// destroy the nodes for this mount, and all its child mounts
|
||
|
var node = lookup.node;
|
||
|
var mount = node.mounted;
|
||
|
var mounts = FS.getMounts(mount);
|
||
|
|
||
|
Object.keys(FS.nameTable).forEach(function (hash) {
|
||
|
var current = FS.nameTable[hash];
|
||
|
|
||
|
while (current) {
|
||
|
var next = current.name_next;
|
||
|
|
||
|
if (mounts.indexOf(current.mount) !== -1) {
|
||
|
FS.destroyNode(current);
|
||
|
}
|
||
|
|
||
|
current = next;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
// no longer a mountpoint
|
||
|
node.mounted = null;
|
||
|
|
||
|
// remove this mount from the child mounts
|
||
|
var idx = node.mount.mounts.indexOf(mount);
|
||
|
assert(idx !== -1);
|
||
|
node.mount.mounts.splice(idx, 1);
|
||
|
},lookup:function (parent, name) {
|
||
|
return parent.node_ops.lookup(parent, name);
|
||
|
},mknod:function (path, mode, dev) {
|
||
|
var lookup = FS.lookupPath(path, { parent: true });
|
||
|
var parent = lookup.node;
|
||
|
var name = PATH.basename(path);
|
||
|
var err = FS.mayCreate(parent, name);
|
||
|
if (err) {
|
||
|
throw new FS.ErrnoError(err);
|
||
|
}
|
||
|
if (!parent.node_ops.mknod) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EPERM);
|
||
|
}
|
||
|
return parent.node_ops.mknod(parent, name, mode, dev);
|
||
|
},create:function (path, mode) {
|
||
|
mode = mode !== undefined ? mode : 438 /* 0666 */;
|
||
|
mode &= 4095;
|
||
|
mode |= 32768;
|
||
|
return FS.mknod(path, mode, 0);
|
||
|
},mkdir:function (path, mode) {
|
||
|
mode = mode !== undefined ? mode : 511 /* 0777 */;
|
||
|
mode &= 511 | 512;
|
||
|
mode |= 16384;
|
||
|
return FS.mknod(path, mode, 0);
|
||
|
},mkdev:function (path, mode, dev) {
|
||
|
if (typeof(dev) === 'undefined') {
|
||
|
dev = mode;
|
||
|
mode = 438 /* 0666 */;
|
||
|
}
|
||
|
mode |= 8192;
|
||
|
return FS.mknod(path, mode, dev);
|
||
|
},symlink:function (oldpath, newpath) {
|
||
|
var lookup = FS.lookupPath(newpath, { parent: true });
|
||
|
var parent = lookup.node;
|
||
|
var newname = PATH.basename(newpath);
|
||
|
var err = FS.mayCreate(parent, newname);
|
||
|
if (err) {
|
||
|
throw new FS.ErrnoError(err);
|
||
|
}
|
||
|
if (!parent.node_ops.symlink) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EPERM);
|
||
|
}
|
||
|
return parent.node_ops.symlink(parent, newname, oldpath);
|
||
|
},rename:function (old_path, new_path) {
|
||
|
var old_dirname = PATH.dirname(old_path);
|
||
|
var new_dirname = PATH.dirname(new_path);
|
||
|
var old_name = PATH.basename(old_path);
|
||
|
var new_name = PATH.basename(new_path);
|
||
|
// parents must exist
|
||
|
var lookup, old_dir, new_dir;
|
||
|
try {
|
||
|
lookup = FS.lookupPath(old_path, { parent: true });
|
||
|
old_dir = lookup.node;
|
||
|
lookup = FS.lookupPath(new_path, { parent: true });
|
||
|
new_dir = lookup.node;
|
||
|
} catch (e) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EBUSY);
|
||
|
}
|
||
|
// need to be part of the same mount
|
||
|
if (old_dir.mount !== new_dir.mount) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EXDEV);
|
||
|
}
|
||
|
// source must exist
|
||
|
var old_node = FS.lookupNode(old_dir, old_name);
|
||
|
// old path should not be an ancestor of the new path
|
||
|
var relative = PATH.relative(old_path, new_dirname);
|
||
|
if (relative.charAt(0) !== '.') {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
||
|
}
|
||
|
// new path should not be an ancestor of the old path
|
||
|
relative = PATH.relative(new_path, old_dirname);
|
||
|
if (relative.charAt(0) !== '.') {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ENOTEMPTY);
|
||
|
}
|
||
|
// see if the new path already exists
|
||
|
var new_node;
|
||
|
try {
|
||
|
new_node = FS.lookupNode(new_dir, new_name);
|
||
|
} catch (e) {
|
||
|
// not fatal
|
||
|
}
|
||
|
// early out if nothing needs to change
|
||
|
if (old_node === new_node) {
|
||
|
return;
|
||
|
}
|
||
|
// we'll need to delete the old entry
|
||
|
var isdir = FS.isDir(old_node.mode);
|
||
|
var err = FS.mayDelete(old_dir, old_name, isdir);
|
||
|
if (err) {
|
||
|
throw new FS.ErrnoError(err);
|
||
|
}
|
||
|
// need delete permissions if we'll be overwriting.
|
||
|
// need create permissions if new doesn't already exist.
|
||
|
err = new_node ?
|
||
|
FS.mayDelete(new_dir, new_name, isdir) :
|
||
|
FS.mayCreate(new_dir, new_name);
|
||
|
if (err) {
|
||
|
throw new FS.ErrnoError(err);
|
||
|
}
|
||
|
if (!old_dir.node_ops.rename) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EPERM);
|
||
|
}
|
||
|
if (FS.isMountpoint(old_node) || (new_node && FS.isMountpoint(new_node))) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EBUSY);
|
||
|
}
|
||
|
// if we are going to change the parent, check write permissions
|
||
|
if (new_dir !== old_dir) {
|
||
|
err = FS.nodePermissions(old_dir, 'w');
|
||
|
if (err) {
|
||
|
throw new FS.ErrnoError(err);
|
||
|
}
|
||
|
}
|
||
|
try {
|
||
|
if (FS.trackingDelegate['willMovePath']) {
|
||
|
FS.trackingDelegate['willMovePath'](old_path, new_path);
|
||
|
}
|
||
|
} catch(e) {
|
||
|
console.log("FS.trackingDelegate['willMovePath']('"+old_path+"', '"+new_path+"') threw an exception: " + e.message);
|
||
|
}
|
||
|
// remove the node from the lookup hash
|
||
|
FS.hashRemoveNode(old_node);
|
||
|
// do the underlying fs rename
|
||
|
try {
|
||
|
old_dir.node_ops.rename(old_node, new_dir, new_name);
|
||
|
} catch (e) {
|
||
|
throw e;
|
||
|
} finally {
|
||
|
// add the node back to the hash (in case node_ops.rename
|
||
|
// changed its name)
|
||
|
FS.hashAddNode(old_node);
|
||
|
}
|
||
|
try {
|
||
|
if (FS.trackingDelegate['onMovePath']) FS.trackingDelegate['onMovePath'](old_path, new_path);
|
||
|
} catch(e) {
|
||
|
console.log("FS.trackingDelegate['onMovePath']('"+old_path+"', '"+new_path+"') threw an exception: " + e.message);
|
||
|
}
|
||
|
},rmdir:function (path) {
|
||
|
var lookup = FS.lookupPath(path, { parent: true });
|
||
|
var parent = lookup.node;
|
||
|
var name = PATH.basename(path);
|
||
|
var node = FS.lookupNode(parent, name);
|
||
|
var err = FS.mayDelete(parent, name, true);
|
||
|
if (err) {
|
||
|
throw new FS.ErrnoError(err);
|
||
|
}
|
||
|
if (!parent.node_ops.rmdir) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EPERM);
|
||
|
}
|
||
|
if (FS.isMountpoint(node)) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EBUSY);
|
||
|
}
|
||
|
try {
|
||
|
if (FS.trackingDelegate['willDeletePath']) {
|
||
|
FS.trackingDelegate['willDeletePath'](path);
|
||
|
}
|
||
|
} catch(e) {
|
||
|
console.log("FS.trackingDelegate['willDeletePath']('"+path+"') threw an exception: " + e.message);
|
||
|
}
|
||
|
parent.node_ops.rmdir(parent, name);
|
||
|
FS.destroyNode(node);
|
||
|
try {
|
||
|
if (FS.trackingDelegate['onDeletePath']) FS.trackingDelegate['onDeletePath'](path);
|
||
|
} catch(e) {
|
||
|
console.log("FS.trackingDelegate['onDeletePath']('"+path+"') threw an exception: " + e.message);
|
||
|
}
|
||
|
},readdir:function (path) {
|
||
|
var lookup = FS.lookupPath(path, { follow: true });
|
||
|
var node = lookup.node;
|
||
|
if (!node.node_ops.readdir) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ENOTDIR);
|
||
|
}
|
||
|
return node.node_ops.readdir(node);
|
||
|
},unlink:function (path) {
|
||
|
var lookup = FS.lookupPath(path, { parent: true });
|
||
|
var parent = lookup.node;
|
||
|
var name = PATH.basename(path);
|
||
|
var node = FS.lookupNode(parent, name);
|
||
|
var err = FS.mayDelete(parent, name, false);
|
||
|
if (err) {
|
||
|
// POSIX says unlink should set EPERM, not EISDIR
|
||
|
if (err === ERRNO_CODES.EISDIR) err = ERRNO_CODES.EPERM;
|
||
|
throw new FS.ErrnoError(err);
|
||
|
}
|
||
|
if (!parent.node_ops.unlink) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EPERM);
|
||
|
}
|
||
|
if (FS.isMountpoint(node)) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EBUSY);
|
||
|
}
|
||
|
try {
|
||
|
if (FS.trackingDelegate['willDeletePath']) {
|
||
|
FS.trackingDelegate['willDeletePath'](path);
|
||
|
}
|
||
|
} catch(e) {
|
||
|
console.log("FS.trackingDelegate['willDeletePath']('"+path+"') threw an exception: " + e.message);
|
||
|
}
|
||
|
parent.node_ops.unlink(parent, name);
|
||
|
FS.destroyNode(node);
|
||
|
try {
|
||
|
if (FS.trackingDelegate['onDeletePath']) FS.trackingDelegate['onDeletePath'](path);
|
||
|
} catch(e) {
|
||
|
console.log("FS.trackingDelegate['onDeletePath']('"+path+"') threw an exception: " + e.message);
|
||
|
}
|
||
|
},readlink:function (path) {
|
||
|
var lookup = FS.lookupPath(path);
|
||
|
var link = lookup.node;
|
||
|
if (!link.node_ops.readlink) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
||
|
}
|
||
|
return link.node_ops.readlink(link);
|
||
|
},stat:function (path, dontFollow) {
|
||
|
var lookup = FS.lookupPath(path, { follow: !dontFollow });
|
||
|
var node = lookup.node;
|
||
|
if (!node.node_ops.getattr) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EPERM);
|
||
|
}
|
||
|
return node.node_ops.getattr(node);
|
||
|
},lstat:function (path) {
|
||
|
return FS.stat(path, true);
|
||
|
},chmod:function (path, mode, dontFollow) {
|
||
|
var node;
|
||
|
if (typeof path === 'string') {
|
||
|
var lookup = FS.lookupPath(path, { follow: !dontFollow });
|
||
|
node = lookup.node;
|
||
|
} else {
|
||
|
node = path;
|
||
|
}
|
||
|
if (!node.node_ops.setattr) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EPERM);
|
||
|
}
|
||
|
node.node_ops.setattr(node, {
|
||
|
mode: (mode & 4095) | (node.mode & ~4095),
|
||
|
timestamp: Date.now()
|
||
|
});
|
||
|
},lchmod:function (path, mode) {
|
||
|
FS.chmod(path, mode, true);
|
||
|
},fchmod:function (fd, mode) {
|
||
|
var stream = FS.getStream(fd);
|
||
|
if (!stream) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EBADF);
|
||
|
}
|
||
|
FS.chmod(stream.node, mode);
|
||
|
},chown:function (path, uid, gid, dontFollow) {
|
||
|
var node;
|
||
|
if (typeof path === 'string') {
|
||
|
var lookup = FS.lookupPath(path, { follow: !dontFollow });
|
||
|
node = lookup.node;
|
||
|
} else {
|
||
|
node = path;
|
||
|
}
|
||
|
if (!node.node_ops.setattr) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EPERM);
|
||
|
}
|
||
|
node.node_ops.setattr(node, {
|
||
|
timestamp: Date.now()
|
||
|
// we ignore the uid / gid for now
|
||
|
});
|
||
|
},lchown:function (path, uid, gid) {
|
||
|
FS.chown(path, uid, gid, true);
|
||
|
},fchown:function (fd, uid, gid) {
|
||
|
var stream = FS.getStream(fd);
|
||
|
if (!stream) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EBADF);
|
||
|
}
|
||
|
FS.chown(stream.node, uid, gid);
|
||
|
},truncate:function (path, len) {
|
||
|
if (len < 0) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
||
|
}
|
||
|
var node;
|
||
|
if (typeof path === 'string') {
|
||
|
var lookup = FS.lookupPath(path, { follow: true });
|
||
|
node = lookup.node;
|
||
|
} else {
|
||
|
node = path;
|
||
|
}
|
||
|
if (!node.node_ops.setattr) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EPERM);
|
||
|
}
|
||
|
if (FS.isDir(node.mode)) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EISDIR);
|
||
|
}
|
||
|
if (!FS.isFile(node.mode)) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
||
|
}
|
||
|
var err = FS.nodePermissions(node, 'w');
|
||
|
if (err) {
|
||
|
throw new FS.ErrnoError(err);
|
||
|
}
|
||
|
node.node_ops.setattr(node, {
|
||
|
size: len,
|
||
|
timestamp: Date.now()
|
||
|
});
|
||
|
},ftruncate:function (fd, len) {
|
||
|
var stream = FS.getStream(fd);
|
||
|
if (!stream) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EBADF);
|
||
|
}
|
||
|
if ((stream.flags & 2097155) === 0) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
||
|
}
|
||
|
FS.truncate(stream.node, len);
|
||
|
},utime:function (path, atime, mtime) {
|
||
|
var lookup = FS.lookupPath(path, { follow: true });
|
||
|
var node = lookup.node;
|
||
|
node.node_ops.setattr(node, {
|
||
|
timestamp: Math.max(atime, mtime)
|
||
|
});
|
||
|
},open:function (path, flags, mode, fd_start, fd_end) {
|
||
|
flags = typeof flags === 'string' ? FS.modeStringToFlags(flags) : flags;
|
||
|
mode = typeof mode === 'undefined' ? 438 /* 0666 */ : mode;
|
||
|
if ((flags & 64)) {
|
||
|
mode = (mode & 4095) | 32768;
|
||
|
} else {
|
||
|
mode = 0;
|
||
|
}
|
||
|
var node;
|
||
|
if (typeof path === 'object') {
|
||
|
node = path;
|
||
|
} else {
|
||
|
path = PATH.normalize(path);
|
||
|
try {
|
||
|
var lookup = FS.lookupPath(path, {
|
||
|
follow: !(flags & 131072)
|
||
|
});
|
||
|
node = lookup.node;
|
||
|
} catch (e) {
|
||
|
// ignore
|
||
|
}
|
||
|
}
|
||
|
// perhaps we need to create the node
|
||
|
if ((flags & 64)) {
|
||
|
if (node) {
|
||
|
// if O_CREAT and O_EXCL are set, error out if the node already exists
|
||
|
if ((flags & 128)) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EEXIST);
|
||
|
}
|
||
|
} else {
|
||
|
// node doesn't exist, try to create it
|
||
|
node = FS.mknod(path, mode, 0);
|
||
|
}
|
||
|
}
|
||
|
if (!node) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ENOENT);
|
||
|
}
|
||
|
// can't truncate a device
|
||
|
if (FS.isChrdev(node.mode)) {
|
||
|
flags &= ~512;
|
||
|
}
|
||
|
// check permissions
|
||
|
var err = FS.mayOpen(node, flags);
|
||
|
if (err) {
|
||
|
throw new FS.ErrnoError(err);
|
||
|
}
|
||
|
// do truncation if necessary
|
||
|
if ((flags & 512)) {
|
||
|
FS.truncate(node, 0);
|
||
|
}
|
||
|
// we've already handled these, don't pass down to the underlying vfs
|
||
|
flags &= ~(128 | 512);
|
||
|
|
||
|
// register the stream with the filesystem
|
||
|
var stream = FS.createStream({
|
||
|
node: node,
|
||
|
path: FS.getPath(node), // we want the absolute path to the node
|
||
|
flags: flags,
|
||
|
seekable: true,
|
||
|
position: 0,
|
||
|
stream_ops: node.stream_ops,
|
||
|
// used by the file family libc calls (fopen, fwrite, ferror, etc.)
|
||
|
ungotten: [],
|
||
|
error: false
|
||
|
}, fd_start, fd_end);
|
||
|
// call the new stream's open function
|
||
|
if (stream.stream_ops.open) {
|
||
|
stream.stream_ops.open(stream);
|
||
|
}
|
||
|
if (Module['logReadFiles'] && !(flags & 1)) {
|
||
|
if (!FS.readFiles) FS.readFiles = {};
|
||
|
if (!(path in FS.readFiles)) {
|
||
|
FS.readFiles[path] = 1;
|
||
|
Module['printErr']('read file: ' + path);
|
||
|
}
|
||
|
}
|
||
|
try {
|
||
|
if (FS.trackingDelegate['onOpenFile']) {
|
||
|
var trackingFlags = 0;
|
||
|
if ((flags & 2097155) !== 1) {
|
||
|
trackingFlags |= FS.tracking.openFlags.READ;
|
||
|
}
|
||
|
if ((flags & 2097155) !== 0) {
|
||
|
trackingFlags |= FS.tracking.openFlags.WRITE;
|
||
|
}
|
||
|
FS.trackingDelegate['onOpenFile'](path, trackingFlags);
|
||
|
}
|
||
|
} catch(e) {
|
||
|
console.log("FS.trackingDelegate['onOpenFile']('"+path+"', flags) threw an exception: " + e.message);
|
||
|
}
|
||
|
return stream;
|
||
|
},close:function (stream) {
|
||
|
try {
|
||
|
if (stream.stream_ops.close) {
|
||
|
stream.stream_ops.close(stream);
|
||
|
}
|
||
|
} catch (e) {
|
||
|
throw e;
|
||
|
} finally {
|
||
|
FS.closeStream(stream.fd);
|
||
|
}
|
||
|
},llseek:function (stream, offset, whence) {
|
||
|
if (!stream.seekable || !stream.stream_ops.llseek) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ESPIPE);
|
||
|
}
|
||
|
return stream.stream_ops.llseek(stream, offset, whence);
|
||
|
},read:function (stream, buffer, offset, length, position) {
|
||
|
if (length < 0 || position < 0) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
||
|
}
|
||
|
if ((stream.flags & 2097155) === 1) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EBADF);
|
||
|
}
|
||
|
if (FS.isDir(stream.node.mode)) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EISDIR);
|
||
|
}
|
||
|
if (!stream.stream_ops.read) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
||
|
}
|
||
|
var seeking = true;
|
||
|
if (typeof position === 'undefined') {
|
||
|
position = stream.position;
|
||
|
seeking = false;
|
||
|
} else if (!stream.seekable) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ESPIPE);
|
||
|
}
|
||
|
var bytesRead = stream.stream_ops.read(stream, buffer, offset, length, position);
|
||
|
if (!seeking) stream.position += bytesRead;
|
||
|
return bytesRead;
|
||
|
},write:function (stream, buffer, offset, length, position, canOwn) {
|
||
|
if (length < 0 || position < 0) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
||
|
}
|
||
|
if ((stream.flags & 2097155) === 0) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EBADF);
|
||
|
}
|
||
|
if (FS.isDir(stream.node.mode)) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EISDIR);
|
||
|
}
|
||
|
if (!stream.stream_ops.write) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
||
|
}
|
||
|
var seeking = true;
|
||
|
if (typeof position === 'undefined') {
|
||
|
position = stream.position;
|
||
|
seeking = false;
|
||
|
} else if (!stream.seekable) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ESPIPE);
|
||
|
}
|
||
|
if (stream.flags & 1024) {
|
||
|
// seek to the end before writing in append mode
|
||
|
FS.llseek(stream, 0, 2);
|
||
|
}
|
||
|
var bytesWritten = stream.stream_ops.write(stream, buffer, offset, length, position, canOwn);
|
||
|
if (!seeking) stream.position += bytesWritten;
|
||
|
try {
|
||
|
if (stream.path && FS.trackingDelegate['onWriteToFile']) FS.trackingDelegate['onWriteToFile'](stream.path);
|
||
|
} catch(e) {
|
||
|
console.log("FS.trackingDelegate['onWriteToFile']('"+path+"') threw an exception: " + e.message);
|
||
|
}
|
||
|
return bytesWritten;
|
||
|
},allocate:function (stream, offset, length) {
|
||
|
if (offset < 0 || length <= 0) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
||
|
}
|
||
|
if ((stream.flags & 2097155) === 0) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EBADF);
|
||
|
}
|
||
|
if (!FS.isFile(stream.node.mode) && !FS.isDir(node.mode)) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ENODEV);
|
||
|
}
|
||
|
if (!stream.stream_ops.allocate) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EOPNOTSUPP);
|
||
|
}
|
||
|
stream.stream_ops.allocate(stream, offset, length);
|
||
|
},mmap:function (stream, buffer, offset, length, position, prot, flags) {
|
||
|
// TODO if PROT is PROT_WRITE, make sure we have write access
|
||
|
if ((stream.flags & 2097155) === 1) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EACCES);
|
||
|
}
|
||
|
if (!stream.stream_ops.mmap) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ENODEV);
|
||
|
}
|
||
|
return stream.stream_ops.mmap(stream, buffer, offset, length, position, prot, flags);
|
||
|
},ioctl:function (stream, cmd, arg) {
|
||
|
if (!stream.stream_ops.ioctl) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ENOTTY);
|
||
|
}
|
||
|
return stream.stream_ops.ioctl(stream, cmd, arg);
|
||
|
},readFile:function (path, opts) {
|
||
|
opts = opts || {};
|
||
|
opts.flags = opts.flags || 'r';
|
||
|
opts.encoding = opts.encoding || 'binary';
|
||
|
if (opts.encoding !== 'utf8' && opts.encoding !== 'binary') {
|
||
|
throw new Error('Invalid encoding type "' + opts.encoding + '"');
|
||
|
}
|
||
|
var ret;
|
||
|
var stream = FS.open(path, opts.flags);
|
||
|
var stat = FS.stat(path);
|
||
|
var length = stat.size;
|
||
|
var buf = new Uint8Array(length);
|
||
|
FS.read(stream, buf, 0, length, 0);
|
||
|
if (opts.encoding === 'utf8') {
|
||
|
ret = '';
|
||
|
var utf8 = new Runtime.UTF8Processor();
|
||
|
for (var i = 0; i < length; i++) {
|
||
|
ret += utf8.processCChar(buf[i]);
|
||
|
}
|
||
|
} else if (opts.encoding === 'binary') {
|
||
|
ret = buf;
|
||
|
}
|
||
|
FS.close(stream);
|
||
|
return ret;
|
||
|
},writeFile:function (path, data, opts) {
|
||
|
opts = opts || {};
|
||
|
opts.flags = opts.flags || 'w';
|
||
|
opts.encoding = opts.encoding || 'utf8';
|
||
|
if (opts.encoding !== 'utf8' && opts.encoding !== 'binary') {
|
||
|
throw new Error('Invalid encoding type "' + opts.encoding + '"');
|
||
|
}
|
||
|
var stream = FS.open(path, opts.flags, opts.mode);
|
||
|
if (opts.encoding === 'utf8') {
|
||
|
var utf8 = new Runtime.UTF8Processor();
|
||
|
var buf = new Uint8Array(utf8.processJSString(data));
|
||
|
FS.write(stream, buf, 0, buf.length, 0, opts.canOwn);
|
||
|
} else if (opts.encoding === 'binary') {
|
||
|
FS.write(stream, data, 0, data.length, 0, opts.canOwn);
|
||
|
}
|
||
|
FS.close(stream);
|
||
|
},cwd:function () {
|
||
|
return FS.currentPath;
|
||
|
},chdir:function (path) {
|
||
|
var lookup = FS.lookupPath(path, { follow: true });
|
||
|
if (!FS.isDir(lookup.node.mode)) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ENOTDIR);
|
||
|
}
|
||
|
var err = FS.nodePermissions(lookup.node, 'x');
|
||
|
if (err) {
|
||
|
throw new FS.ErrnoError(err);
|
||
|
}
|
||
|
FS.currentPath = lookup.path;
|
||
|
},createDefaultDirectories:function () {
|
||
|
FS.mkdir('/tmp');
|
||
|
},createDefaultDevices:function () {
|
||
|
// create /dev
|
||
|
FS.mkdir('/dev');
|
||
|
// setup /dev/null
|
||
|
FS.registerDevice(FS.makedev(1, 3), {
|
||
|
read: function() { return 0; },
|
||
|
write: function() { return 0; }
|
||
|
});
|
||
|
FS.mkdev('/dev/null', FS.makedev(1, 3));
|
||
|
// setup /dev/tty and /dev/tty1
|
||
|
// stderr needs to print output using Module['printErr']
|
||
|
// so we register a second tty just for it.
|
||
|
TTY.register(FS.makedev(5, 0), TTY.default_tty_ops);
|
||
|
TTY.register(FS.makedev(6, 0), TTY.default_tty1_ops);
|
||
|
FS.mkdev('/dev/tty', FS.makedev(5, 0));
|
||
|
FS.mkdev('/dev/tty1', FS.makedev(6, 0));
|
||
|
// we're not going to emulate the actual shm device,
|
||
|
// just create the tmp dirs that reside in it commonly
|
||
|
FS.mkdir('/dev/shm');
|
||
|
FS.mkdir('/dev/shm/tmp');
|
||
|
},createStandardStreams:function () {
|
||
|
// TODO deprecate the old functionality of a single
|
||
|
// input / output callback and that utilizes FS.createDevice
|
||
|
// and instead require a unique set of stream ops
|
||
|
|
||
|
// by default, we symlink the standard streams to the
|
||
|
// default tty devices. however, if the standard streams
|
||
|
// have been overwritten we create a unique device for
|
||
|
// them instead.
|
||
|
if (Module['stdin']) {
|
||
|
FS.createDevice('/dev', 'stdin', Module['stdin']);
|
||
|
} else {
|
||
|
FS.symlink('/dev/tty', '/dev/stdin');
|
||
|
}
|
||
|
if (Module['stdout']) {
|
||
|
FS.createDevice('/dev', 'stdout', null, Module['stdout']);
|
||
|
} else {
|
||
|
FS.symlink('/dev/tty', '/dev/stdout');
|
||
|
}
|
||
|
if (Module['stderr']) {
|
||
|
FS.createDevice('/dev', 'stderr', null, Module['stderr']);
|
||
|
} else {
|
||
|
FS.symlink('/dev/tty1', '/dev/stderr');
|
||
|
}
|
||
|
|
||
|
// open default streams for the stdin, stdout and stderr devices
|
||
|
var stdin = FS.open('/dev/stdin', 'r');
|
||
|
HEAP32[((_stdin)>>2)]=FS.getPtrForStream(stdin);
|
||
|
assert(stdin.fd === 0, 'invalid handle for stdin (' + stdin.fd + ')');
|
||
|
|
||
|
var stdout = FS.open('/dev/stdout', 'w');
|
||
|
HEAP32[((_stdout)>>2)]=FS.getPtrForStream(stdout);
|
||
|
assert(stdout.fd === 1, 'invalid handle for stdout (' + stdout.fd + ')');
|
||
|
|
||
|
var stderr = FS.open('/dev/stderr', 'w');
|
||
|
HEAP32[((_stderr)>>2)]=FS.getPtrForStream(stderr);
|
||
|
assert(stderr.fd === 2, 'invalid handle for stderr (' + stderr.fd + ')');
|
||
|
},ensureErrnoError:function () {
|
||
|
if (FS.ErrnoError) return;
|
||
|
FS.ErrnoError = function ErrnoError(errno) {
|
||
|
this.errno = errno;
|
||
|
for (var key in ERRNO_CODES) {
|
||
|
if (ERRNO_CODES[key] === errno) {
|
||
|
this.code = key;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
this.message = ERRNO_MESSAGES[errno];
|
||
|
};
|
||
|
FS.ErrnoError.prototype = new Error();
|
||
|
FS.ErrnoError.prototype.constructor = FS.ErrnoError;
|
||
|
// Some errors may happen quite a bit, to avoid overhead we reuse them (and suffer a lack of stack info)
|
||
|
[ERRNO_CODES.ENOENT].forEach(function(code) {
|
||
|
FS.genericErrors[code] = new FS.ErrnoError(code);
|
||
|
FS.genericErrors[code].stack = '<generic error, no stack>';
|
||
|
});
|
||
|
},staticInit:function () {
|
||
|
FS.ensureErrnoError();
|
||
|
|
||
|
FS.nameTable = new Array(4096);
|
||
|
|
||
|
FS.mount(MEMFS, {}, '/');
|
||
|
|
||
|
FS.createDefaultDirectories();
|
||
|
FS.createDefaultDevices();
|
||
|
},init:function (input, output, error) {
|
||
|
assert(!FS.init.initialized, 'FS.init was previously called. If you want to initialize later with custom parameters, remove any earlier calls (note that one is automatically added to the generated code)');
|
||
|
FS.init.initialized = true;
|
||
|
|
||
|
FS.ensureErrnoError();
|
||
|
|
||
|
// Allow Module.stdin etc. to provide defaults, if none explicitly passed to us here
|
||
|
Module['stdin'] = input || Module['stdin'];
|
||
|
Module['stdout'] = output || Module['stdout'];
|
||
|
Module['stderr'] = error || Module['stderr'];
|
||
|
|
||
|
FS.createStandardStreams();
|
||
|
},quit:function () {
|
||
|
FS.init.initialized = false;
|
||
|
for (var i = 0; i < FS.streams.length; i++) {
|
||
|
var stream = FS.streams[i];
|
||
|
if (!stream) {
|
||
|
continue;
|
||
|
}
|
||
|
FS.close(stream);
|
||
|
}
|
||
|
},getMode:function (canRead, canWrite) {
|
||
|
var mode = 0;
|
||
|
if (canRead) mode |= 292 | 73;
|
||
|
if (canWrite) mode |= 146;
|
||
|
return mode;
|
||
|
},joinPath:function (parts, forceRelative) {
|
||
|
var path = PATH.join.apply(null, parts);
|
||
|
if (forceRelative && path[0] == '/') path = path.substr(1);
|
||
|
return path;
|
||
|
},absolutePath:function (relative, base) {
|
||
|
return PATH.resolve(base, relative);
|
||
|
},standardizePath:function (path) {
|
||
|
return PATH.normalize(path);
|
||
|
},findObject:function (path, dontResolveLastLink) {
|
||
|
var ret = FS.analyzePath(path, dontResolveLastLink);
|
||
|
if (ret.exists) {
|
||
|
return ret.object;
|
||
|
} else {
|
||
|
___setErrNo(ret.error);
|
||
|
return null;
|
||
|
}
|
||
|
},analyzePath:function (path, dontResolveLastLink) {
|
||
|
// operate from within the context of the symlink's target
|
||
|
try {
|
||
|
var lookup = FS.lookupPath(path, { follow: !dontResolveLastLink });
|
||
|
path = lookup.path;
|
||
|
} catch (e) {
|
||
|
}
|
||
|
var ret = {
|
||
|
isRoot: false, exists: false, error: 0, name: null, path: null, object: null,
|
||
|
parentExists: false, parentPath: null, parentObject: null
|
||
|
};
|
||
|
try {
|
||
|
var lookup = FS.lookupPath(path, { parent: true });
|
||
|
ret.parentExists = true;
|
||
|
ret.parentPath = lookup.path;
|
||
|
ret.parentObject = lookup.node;
|
||
|
ret.name = PATH.basename(path);
|
||
|
lookup = FS.lookupPath(path, { follow: !dontResolveLastLink });
|
||
|
ret.exists = true;
|
||
|
ret.path = lookup.path;
|
||
|
ret.object = lookup.node;
|
||
|
ret.name = lookup.node.name;
|
||
|
ret.isRoot = lookup.path === '/';
|
||
|
} catch (e) {
|
||
|
ret.error = e.errno;
|
||
|
};
|
||
|
return ret;
|
||
|
},createFolder:function (parent, name, canRead, canWrite) {
|
||
|
var path = PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name);
|
||
|
var mode = FS.getMode(canRead, canWrite);
|
||
|
return FS.mkdir(path, mode);
|
||
|
},createPath:function (parent, path, canRead, canWrite) {
|
||
|
parent = typeof parent === 'string' ? parent : FS.getPath(parent);
|
||
|
var parts = path.split('/').reverse();
|
||
|
while (parts.length) {
|
||
|
var part = parts.pop();
|
||
|
if (!part) continue;
|
||
|
var current = PATH.join2(parent, part);
|
||
|
try {
|
||
|
FS.mkdir(current);
|
||
|
} catch (e) {
|
||
|
// ignore EEXIST
|
||
|
}
|
||
|
parent = current;
|
||
|
}
|
||
|
return current;
|
||
|
},createFile:function (parent, name, properties, canRead, canWrite) {
|
||
|
var path = PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name);
|
||
|
var mode = FS.getMode(canRead, canWrite);
|
||
|
return FS.create(path, mode);
|
||
|
},createDataFile:function (parent, name, data, canRead, canWrite, canOwn) {
|
||
|
var path = name ? PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name) : parent;
|
||
|
var mode = FS.getMode(canRead, canWrite);
|
||
|
var node = FS.create(path, mode);
|
||
|
if (data) {
|
||
|
if (typeof data === 'string') {
|
||
|
var arr = new Array(data.length);
|
||
|
for (var i = 0, len = data.length; i < len; ++i) arr[i] = data.charCodeAt(i);
|
||
|
data = arr;
|
||
|
}
|
||
|
// make sure we can write to the file
|
||
|
FS.chmod(node, mode | 146);
|
||
|
var stream = FS.open(node, 'w');
|
||
|
FS.write(stream, data, 0, data.length, 0, canOwn);
|
||
|
FS.close(stream);
|
||
|
FS.chmod(node, mode);
|
||
|
}
|
||
|
return node;
|
||
|
},createDevice:function (parent, name, input, output) {
|
||
|
var path = PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name);
|
||
|
var mode = FS.getMode(!!input, !!output);
|
||
|
if (!FS.createDevice.major) FS.createDevice.major = 64;
|
||
|
var dev = FS.makedev(FS.createDevice.major++, 0);
|
||
|
// Create a fake device that a set of stream ops to emulate
|
||
|
// the old behavior.
|
||
|
FS.registerDevice(dev, {
|
||
|
open: function(stream) {
|
||
|
stream.seekable = false;
|
||
|
},
|
||
|
close: function(stream) {
|
||
|
// flush any pending line data
|
||
|
if (output && output.buffer && output.buffer.length) {
|
||
|
output(10);
|
||
|
}
|
||
|
},
|
||
|
read: function(stream, buffer, offset, length, pos /* ignored */) {
|
||
|
var bytesRead = 0;
|
||
|
for (var i = 0; i < length; i++) {
|
||
|
var result;
|
||
|
try {
|
||
|
result = input();
|
||
|
} catch (e) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EIO);
|
||
|
}
|
||
|
if (result === undefined && bytesRead === 0) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EAGAIN);
|
||
|
}
|
||
|
if (result === null || result === undefined) break;
|
||
|
bytesRead++;
|
||
|
buffer[offset+i] = result;
|
||
|
}
|
||
|
if (bytesRead) {
|
||
|
stream.node.timestamp = Date.now();
|
||
|
}
|
||
|
return bytesRead;
|
||
|
},
|
||
|
write: function(stream, buffer, offset, length, pos) {
|
||
|
for (var i = 0; i < length; i++) {
|
||
|
try {
|
||
|
output(buffer[offset+i]);
|
||
|
} catch (e) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EIO);
|
||
|
}
|
||
|
}
|
||
|
if (length) {
|
||
|
stream.node.timestamp = Date.now();
|
||
|
}
|
||
|
return i;
|
||
|
}
|
||
|
});
|
||
|
return FS.mkdev(path, mode, dev);
|
||
|
},createLink:function (parent, name, target, canRead, canWrite) {
|
||
|
var path = PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name);
|
||
|
return FS.symlink(target, path);
|
||
|
},forceLoadFile:function (obj) {
|
||
|
if (obj.isDevice || obj.isFolder || obj.link || obj.contents) return true;
|
||
|
var success = true;
|
||
|
if (typeof XMLHttpRequest !== 'undefined') {
|
||
|
throw new Error("Lazy loading should have been performed (contents set) in createLazyFile, but it was not. Lazy loading only works in web workers. Use --embed-file or --preload-file in emcc on the main thread.");
|
||
|
} else if (Module['read']) {
|
||
|
// Command-line.
|
||
|
try {
|
||
|
// WARNING: Can't read binary files in V8's d8 or tracemonkey's js, as
|
||
|
// read() will try to parse UTF8.
|
||
|
obj.contents = intArrayFromString(Module['read'](obj.url), true);
|
||
|
} catch (e) {
|
||
|
success = false;
|
||
|
}
|
||
|
} else {
|
||
|
throw new Error('Cannot load without read() or XMLHttpRequest.');
|
||
|
}
|
||
|
if (!success) ___setErrNo(ERRNO_CODES.EIO);
|
||
|
return success;
|
||
|
},createLazyFile:function (parent, name, url, canRead, canWrite) {
|
||
|
// Lazy chunked Uint8Array (implements get and length from Uint8Array). Actual getting is abstracted away for eventual reuse.
|
||
|
function LazyUint8Array() {
|
||
|
this.lengthKnown = false;
|
||
|
this.chunks = []; // Loaded chunks. Index is the chunk number
|
||
|
}
|
||
|
LazyUint8Array.prototype.get = function LazyUint8Array_get(idx) {
|
||
|
if (idx > this.length-1 || idx < 0) {
|
||
|
return undefined;
|
||
|
}
|
||
|
var chunkOffset = idx % this.chunkSize;
|
||
|
var chunkNum = Math.floor(idx / this.chunkSize);
|
||
|
return this.getter(chunkNum)[chunkOffset];
|
||
|
}
|
||
|
LazyUint8Array.prototype.setDataGetter = function LazyUint8Array_setDataGetter(getter) {
|
||
|
this.getter = getter;
|
||
|
}
|
||
|
LazyUint8Array.prototype.cacheLength = function LazyUint8Array_cacheLength() {
|
||
|
// Find length
|
||
|
var xhr = new XMLHttpRequest();
|
||
|
xhr.open('HEAD', url, false);
|
||
|
xhr.send(null);
|
||
|
if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
|
||
|
var datalength = Number(xhr.getResponseHeader("Content-length"));
|
||
|
var header;
|
||
|
var hasByteServing = (header = xhr.getResponseHeader("Accept-Ranges")) && header === "bytes";
|
||
|
var chunkSize = 1024*1024; // Chunk size in bytes
|
||
|
|
||
|
if (!hasByteServing) chunkSize = datalength;
|
||
|
|
||
|
// Function to get a range from the remote URL.
|
||
|
var doXHR = (function(from, to) {
|
||
|
if (from > to) throw new Error("invalid range (" + from + ", " + to + ") or no bytes requested!");
|
||
|
if (to > datalength-1) throw new Error("only " + datalength + " bytes available! programmer error!");
|
||
|
|
||
|
// TODO: Use mozResponseArrayBuffer, responseStream, etc. if available.
|
||
|
var xhr = new XMLHttpRequest();
|
||
|
xhr.open('GET', url, false);
|
||
|
if (datalength !== chunkSize) xhr.setRequestHeader("Range", "bytes=" + from + "-" + to);
|
||
|
|
||
|
// Some hints to the browser that we want binary data.
|
||
|
if (typeof Uint8Array != 'undefined') xhr.responseType = 'arraybuffer';
|
||
|
if (xhr.overrideMimeType) {
|
||
|
xhr.overrideMimeType('text/plain; charset=x-user-defined');
|
||
|
}
|
||
|
|
||
|
xhr.send(null);
|
||
|
if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
|
||
|
if (xhr.response !== undefined) {
|
||
|
return new Uint8Array(xhr.response || []);
|
||
|
} else {
|
||
|
return intArrayFromString(xhr.responseText || '', true);
|
||
|
}
|
||
|
});
|
||
|
var lazyArray = this;
|
||
|
lazyArray.setDataGetter(function(chunkNum) {
|
||
|
var start = chunkNum * chunkSize;
|
||
|
var end = (chunkNum+1) * chunkSize - 1; // including this byte
|
||
|
end = Math.min(end, datalength-1); // if datalength-1 is selected, this is the last block
|
||
|
if (typeof(lazyArray.chunks[chunkNum]) === "undefined") {
|
||
|
lazyArray.chunks[chunkNum] = doXHR(start, end);
|
||
|
}
|
||
|
if (typeof(lazyArray.chunks[chunkNum]) === "undefined") throw new Error("doXHR failed!");
|
||
|
return lazyArray.chunks[chunkNum];
|
||
|
});
|
||
|
|
||
|
this._length = datalength;
|
||
|
this._chunkSize = chunkSize;
|
||
|
this.lengthKnown = true;
|
||
|
}
|
||
|
if (typeof XMLHttpRequest !== 'undefined') {
|
||
|
if (!ENVIRONMENT_IS_WORKER) throw 'Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc';
|
||
|
var lazyArray = new LazyUint8Array();
|
||
|
Object.defineProperty(lazyArray, "length", {
|
||
|
get: function() {
|
||
|
if(!this.lengthKnown) {
|
||
|
this.cacheLength();
|
||
|
}
|
||
|
return this._length;
|
||
|
}
|
||
|
});
|
||
|
Object.defineProperty(lazyArray, "chunkSize", {
|
||
|
get: function() {
|
||
|
if(!this.lengthKnown) {
|
||
|
this.cacheLength();
|
||
|
}
|
||
|
return this._chunkSize;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
var properties = { isDevice: false, contents: lazyArray };
|
||
|
} else {
|
||
|
var properties = { isDevice: false, url: url };
|
||
|
}
|
||
|
|
||
|
var node = FS.createFile(parent, name, properties, canRead, canWrite);
|
||
|
// This is a total hack, but I want to get this lazy file code out of the
|
||
|
// core of MEMFS. If we want to keep this lazy file concept I feel it should
|
||
|
// be its own thin LAZYFS proxying calls to MEMFS.
|
||
|
if (properties.contents) {
|
||
|
node.contents = properties.contents;
|
||
|
} else if (properties.url) {
|
||
|
node.contents = null;
|
||
|
node.url = properties.url;
|
||
|
}
|
||
|
// override each stream op with one that tries to force load the lazy file first
|
||
|
var stream_ops = {};
|
||
|
var keys = Object.keys(node.stream_ops);
|
||
|
keys.forEach(function(key) {
|
||
|
var fn = node.stream_ops[key];
|
||
|
stream_ops[key] = function forceLoadLazyFile() {
|
||
|
if (!FS.forceLoadFile(node)) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EIO);
|
||
|
}
|
||
|
return fn.apply(null, arguments);
|
||
|
};
|
||
|
});
|
||
|
// use a custom read function
|
||
|
stream_ops.read = function stream_ops_read(stream, buffer, offset, length, position) {
|
||
|
if (!FS.forceLoadFile(node)) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EIO);
|
||
|
}
|
||
|
var contents = stream.node.contents;
|
||
|
if (position >= contents.length)
|
||
|
return 0;
|
||
|
var size = Math.min(contents.length - position, length);
|
||
|
assert(size >= 0);
|
||
|
if (contents.slice) { // normal array
|
||
|
for (var i = 0; i < size; i++) {
|
||
|
buffer[offset + i] = contents[position + i];
|
||
|
}
|
||
|
} else {
|
||
|
for (var i = 0; i < size; i++) { // LazyUint8Array from sync binary XHR
|
||
|
buffer[offset + i] = contents.get(position + i);
|
||
|
}
|
||
|
}
|
||
|
return size;
|
||
|
};
|
||
|
node.stream_ops = stream_ops;
|
||
|
return node;
|
||
|
},createPreloadedFile:function (parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile, canOwn) {
|
||
|
Browser.init();
|
||
|
// TODO we should allow people to just pass in a complete filename instead
|
||
|
// of parent and name being that we just join them anyways
|
||
|
var fullname = name ? PATH.resolve(PATH.join2(parent, name)) : parent;
|
||
|
function processData(byteArray) {
|
||
|
function finish(byteArray) {
|
||
|
if (!dontCreateFile) {
|
||
|
FS.createDataFile(parent, name, byteArray, canRead, canWrite, canOwn);
|
||
|
}
|
||
|
if (onload) onload();
|
||
|
removeRunDependency('cp ' + fullname);
|
||
|
}
|
||
|
var handled = false;
|
||
|
Module['preloadPlugins'].forEach(function(plugin) {
|
||
|
if (handled) return;
|
||
|
if (plugin['canHandle'](fullname)) {
|
||
|
plugin['handle'](byteArray, fullname, finish, function() {
|
||
|
if (onerror) onerror();
|
||
|
removeRunDependency('cp ' + fullname);
|
||
|
});
|
||
|
handled = true;
|
||
|
}
|
||
|
});
|
||
|
if (!handled) finish(byteArray);
|
||
|
}
|
||
|
addRunDependency('cp ' + fullname);
|
||
|
if (typeof url == 'string') {
|
||
|
Browser.asyncLoad(url, function(byteArray) {
|
||
|
processData(byteArray);
|
||
|
}, onerror);
|
||
|
} else {
|
||
|
processData(url);
|
||
|
}
|
||
|
},indexedDB:function () {
|
||
|
return window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
|
||
|
},DB_NAME:function () {
|
||
|
return 'EM_FS_' + window.location.pathname;
|
||
|
},DB_VERSION:20,DB_STORE_NAME:"FILE_DATA",saveFilesToDB:function (paths, onload, onerror) {
|
||
|
onload = onload || function(){};
|
||
|
onerror = onerror || function(){};
|
||
|
var indexedDB = FS.indexedDB();
|
||
|
try {
|
||
|
var openRequest = indexedDB.open(FS.DB_NAME(), FS.DB_VERSION);
|
||
|
} catch (e) {
|
||
|
return onerror(e);
|
||
|
}
|
||
|
openRequest.onupgradeneeded = function openRequest_onupgradeneeded() {
|
||
|
console.log('creating db');
|
||
|
var db = openRequest.result;
|
||
|
db.createObjectStore(FS.DB_STORE_NAME);
|
||
|
};
|
||
|
openRequest.onsuccess = function openRequest_onsuccess() {
|
||
|
var db = openRequest.result;
|
||
|
var transaction = db.transaction([FS.DB_STORE_NAME], 'readwrite');
|
||
|
var files = transaction.objectStore(FS.DB_STORE_NAME);
|
||
|
var ok = 0, fail = 0, total = paths.length;
|
||
|
function finish() {
|
||
|
if (fail == 0) onload(); else onerror();
|
||
|
}
|
||
|
paths.forEach(function(path) {
|
||
|
var putRequest = files.put(FS.analyzePath(path).object.contents, path);
|
||
|
putRequest.onsuccess = function putRequest_onsuccess() { ok++; if (ok + fail == total) finish() };
|
||
|
putRequest.onerror = function putRequest_onerror() { fail++; if (ok + fail == total) finish() };
|
||
|
});
|
||
|
transaction.onerror = onerror;
|
||
|
};
|
||
|
openRequest.onerror = onerror;
|
||
|
},loadFilesFromDB:function (paths, onload, onerror) {
|
||
|
onload = onload || function(){};
|
||
|
onerror = onerror || function(){};
|
||
|
var indexedDB = FS.indexedDB();
|
||
|
try {
|
||
|
var openRequest = indexedDB.open(FS.DB_NAME(), FS.DB_VERSION);
|
||
|
} catch (e) {
|
||
|
return onerror(e);
|
||
|
}
|
||
|
openRequest.onupgradeneeded = onerror; // no database to load from
|
||
|
openRequest.onsuccess = function openRequest_onsuccess() {
|
||
|
var db = openRequest.result;
|
||
|
try {
|
||
|
var transaction = db.transaction([FS.DB_STORE_NAME], 'readonly');
|
||
|
} catch(e) {
|
||
|
onerror(e);
|
||
|
return;
|
||
|
}
|
||
|
var files = transaction.objectStore(FS.DB_STORE_NAME);
|
||
|
var ok = 0, fail = 0, total = paths.length;
|
||
|
function finish() {
|
||
|
if (fail == 0) onload(); else onerror();
|
||
|
}
|
||
|
paths.forEach(function(path) {
|
||
|
var getRequest = files.get(path);
|
||
|
getRequest.onsuccess = function getRequest_onsuccess() {
|
||
|
if (FS.analyzePath(path).exists) {
|
||
|
FS.unlink(path);
|
||
|
}
|
||
|
FS.createDataFile(PATH.dirname(path), PATH.basename(path), getRequest.result, true, true, true);
|
||
|
ok++;
|
||
|
if (ok + fail == total) finish();
|
||
|
};
|
||
|
getRequest.onerror = function getRequest_onerror() { fail++; if (ok + fail == total) finish() };
|
||
|
});
|
||
|
transaction.onerror = onerror;
|
||
|
};
|
||
|
openRequest.onerror = onerror;
|
||
|
}};
|
||
|
|
||
|
var Browser={mainLoop:{scheduler:null,method:"",shouldPause:false,paused:false,queue:[],pause:function () {
|
||
|
Browser.mainLoop.shouldPause = true;
|
||
|
},resume:function () {
|
||
|
if (Browser.mainLoop.paused) {
|
||
|
Browser.mainLoop.paused = false;
|
||
|
Browser.mainLoop.scheduler();
|
||
|
}
|
||
|
Browser.mainLoop.shouldPause = false;
|
||
|
},updateStatus:function () {
|
||
|
if (Module['setStatus']) {
|
||
|
var message = Module['statusMessage'] || 'Please wait...';
|
||
|
var remaining = Browser.mainLoop.remainingBlockers;
|
||
|
var expected = Browser.mainLoop.expectedBlockers;
|
||
|
if (remaining) {
|
||
|
if (remaining < expected) {
|
||
|
Module['setStatus'](message + ' (' + (expected - remaining) + '/' + expected + ')');
|
||
|
} else {
|
||
|
Module['setStatus'](message);
|
||
|
}
|
||
|
} else {
|
||
|
Module['setStatus']('');
|
||
|
}
|
||
|
}
|
||
|
}},isFullScreen:false,pointerLock:false,moduleContextCreatedCallbacks:[],workers:[],init:function () {
|
||
|
if (!Module["preloadPlugins"]) Module["preloadPlugins"] = []; // needs to exist even in workers
|
||
|
|
||
|
if (Browser.initted || ENVIRONMENT_IS_WORKER) return;
|
||
|
Browser.initted = true;
|
||
|
|
||
|
try {
|
||
|
new Blob();
|
||
|
Browser.hasBlobConstructor = true;
|
||
|
} catch(e) {
|
||
|
Browser.hasBlobConstructor = false;
|
||
|
console.log("warning: no blob constructor, cannot create blobs with mimetypes");
|
||
|
}
|
||
|
Browser.BlobBuilder = typeof MozBlobBuilder != "undefined" ? MozBlobBuilder : (typeof WebKitBlobBuilder != "undefined" ? WebKitBlobBuilder : (!Browser.hasBlobConstructor ? console.log("warning: no BlobBuilder") : null));
|
||
|
Browser.URLObject = typeof window != "undefined" ? (window.URL ? window.URL : window.webkitURL) : undefined;
|
||
|
if (!Module.noImageDecoding && typeof Browser.URLObject === 'undefined') {
|
||
|
console.log("warning: Browser does not support creating object URLs. Built-in browser image decoding will not be available.");
|
||
|
Module.noImageDecoding = true;
|
||
|
}
|
||
|
|
||
|
// Support for plugins that can process preloaded files. You can add more of these to
|
||
|
// your app by creating and appending to Module.preloadPlugins.
|
||
|
//
|
||
|
// Each plugin is asked if it can handle a file based on the file's name. If it can,
|
||
|
// it is given the file's raw data. When it is done, it calls a callback with the file's
|
||
|
// (possibly modified) data. For example, a plugin might decompress a file, or it
|
||
|
// might create some side data structure for use later (like an Image element, etc.).
|
||
|
|
||
|
var imagePlugin = {};
|
||
|
imagePlugin['canHandle'] = function imagePlugin_canHandle(name) {
|
||
|
return !Module.noImageDecoding && /\.(jpg|jpeg|png|bmp)$/i.test(name);
|
||
|
};
|
||
|
imagePlugin['handle'] = function imagePlugin_handle(byteArray, name, onload, onerror) {
|
||
|
var b = null;
|
||
|
if (Browser.hasBlobConstructor) {
|
||
|
try {
|
||
|
b = new Blob([byteArray], { type: Browser.getMimetype(name) });
|
||
|
if (b.size !== byteArray.length) { // Safari bug #118630
|
||
|
// Safari's Blob can only take an ArrayBuffer
|
||
|
b = new Blob([(new Uint8Array(byteArray)).buffer], { type: Browser.getMimetype(name) });
|
||
|
}
|
||
|
} catch(e) {
|
||
|
Runtime.warnOnce('Blob constructor present but fails: ' + e + '; falling back to blob builder');
|
||
|
}
|
||
|
}
|
||
|
if (!b) {
|
||
|
var bb = new Browser.BlobBuilder();
|
||
|
bb.append((new Uint8Array(byteArray)).buffer); // we need to pass a buffer, and must copy the array to get the right data range
|
||
|
b = bb.getBlob();
|
||
|
}
|
||
|
var url = Browser.URLObject.createObjectURL(b);
|
||
|
var img = new Image();
|
||
|
img.onload = function img_onload() {
|
||
|
assert(img.complete, 'Image ' + name + ' could not be decoded');
|
||
|
var canvas = document.createElement('canvas');
|
||
|
canvas.width = img.width;
|
||
|
canvas.height = img.height;
|
||
|
var ctx = canvas.getContext('2d');
|
||
|
ctx.drawImage(img, 0, 0);
|
||
|
Module["preloadedImages"][name] = canvas;
|
||
|
Browser.URLObject.revokeObjectURL(url);
|
||
|
if (onload) onload(byteArray);
|
||
|
};
|
||
|
img.onerror = function img_onerror(event) {
|
||
|
console.log('Image ' + url + ' could not be decoded');
|
||
|
if (onerror) onerror();
|
||
|
};
|
||
|
img.src = url;
|
||
|
};
|
||
|
Module['preloadPlugins'].push(imagePlugin);
|
||
|
|
||
|
var audioPlugin = {};
|
||
|
audioPlugin['canHandle'] = function audioPlugin_canHandle(name) {
|
||
|
return !Module.noAudioDecoding && name.substr(-4) in { '.ogg': 1, '.wav': 1, '.mp3': 1 };
|
||
|
};
|
||
|
audioPlugin['handle'] = function audioPlugin_handle(byteArray, name, onload, onerror) {
|
||
|
var done = false;
|
||
|
function finish(audio) {
|
||
|
if (done) return;
|
||
|
done = true;
|
||
|
Module["preloadedAudios"][name] = audio;
|
||
|
if (onload) onload(byteArray);
|
||
|
}
|
||
|
function fail() {
|
||
|
if (done) return;
|
||
|
done = true;
|
||
|
Module["preloadedAudios"][name] = new Audio(); // empty shim
|
||
|
if (onerror) onerror();
|
||
|
}
|
||
|
if (Browser.hasBlobConstructor) {
|
||
|
try {
|
||
|
var b = new Blob([byteArray], { type: Browser.getMimetype(name) });
|
||
|
} catch(e) {
|
||
|
return fail();
|
||
|
}
|
||
|
var url = Browser.URLObject.createObjectURL(b); // XXX we never revoke this!
|
||
|
var audio = new Audio();
|
||
|
audio.addEventListener('canplaythrough', function() { finish(audio) }, false); // use addEventListener due to chromium bug 124926
|
||
|
audio.onerror = function audio_onerror(event) {
|
||
|
if (done) return;
|
||
|
console.log('warning: browser could not fully decode audio ' + name + ', trying slower base64 approach');
|
||
|
function encode64(data) {
|
||
|
var BASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
||
|
var PAD = '=';
|
||
|
var ret = '';
|
||
|
var leftchar = 0;
|
||
|
var leftbits = 0;
|
||
|
for (var i = 0; i < data.length; i++) {
|
||
|
leftchar = (leftchar << 8) | data[i];
|
||
|
leftbits += 8;
|
||
|
while (leftbits >= 6) {
|
||
|
var curr = (leftchar >> (leftbits-6)) & 0x3f;
|
||
|
leftbits -= 6;
|
||
|
ret += BASE[curr];
|
||
|
}
|
||
|
}
|
||
|
if (leftbits == 2) {
|
||
|
ret += BASE[(leftchar&3) << 4];
|
||
|
ret += PAD + PAD;
|
||
|
} else if (leftbits == 4) {
|
||
|
ret += BASE[(leftchar&0xf) << 2];
|
||
|
ret += PAD;
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
audio.src = 'data:audio/x-' + name.substr(-3) + ';base64,' + encode64(byteArray);
|
||
|
finish(audio); // we don't wait for confirmation this worked - but it's worth trying
|
||
|
};
|
||
|
audio.src = url;
|
||
|
// workaround for chrome bug 124926 - we do not always get oncanplaythrough or onerror
|
||
|
Browser.safeSetTimeout(function() {
|
||
|
finish(audio); // try to use it even though it is not necessarily ready to play
|
||
|
}, 10000);
|
||
|
} else {
|
||
|
return fail();
|
||
|
}
|
||
|
};
|
||
|
Module['preloadPlugins'].push(audioPlugin);
|
||
|
|
||
|
// Canvas event setup
|
||
|
|
||
|
var canvas = Module['canvas'];
|
||
|
if (canvas) {
|
||
|
// forced aspect ratio can be enabled by defining 'forcedAspectRatio' on Module
|
||
|
// Module['forcedAspectRatio'] = 4 / 3;
|
||
|
|
||
|
canvas.requestPointerLock = canvas['requestPointerLock'] ||
|
||
|
canvas['mozRequestPointerLock'] ||
|
||
|
canvas['webkitRequestPointerLock'] ||
|
||
|
canvas['msRequestPointerLock'] ||
|
||
|
function(){};
|
||
|
canvas.exitPointerLock = document['exitPointerLock'] ||
|
||
|
document['mozExitPointerLock'] ||
|
||
|
document['webkitExitPointerLock'] ||
|
||
|
document['msExitPointerLock'] ||
|
||
|
function(){}; // no-op if function does not exist
|
||
|
canvas.exitPointerLock = canvas.exitPointerLock.bind(document);
|
||
|
|
||
|
function pointerLockChange() {
|
||
|
Browser.pointerLock = document['pointerLockElement'] === canvas ||
|
||
|
document['mozPointerLockElement'] === canvas ||
|
||
|
document['webkitPointerLockElement'] === canvas ||
|
||
|
document['msPointerLockElement'] === canvas;
|
||
|
}
|
||
|
|
||
|
document.addEventListener('pointerlockchange', pointerLockChange, false);
|
||
|
document.addEventListener('mozpointerlockchange', pointerLockChange, false);
|
||
|
document.addEventListener('webkitpointerlockchange', pointerLockChange, false);
|
||
|
document.addEventListener('mspointerlockchange', pointerLockChange, false);
|
||
|
|
||
|
if (Module['elementPointerLock']) {
|
||
|
canvas.addEventListener("click", function(ev) {
|
||
|
if (!Browser.pointerLock && canvas.requestPointerLock) {
|
||
|
canvas.requestPointerLock();
|
||
|
ev.preventDefault();
|
||
|
}
|
||
|
}, false);
|
||
|
}
|
||
|
}
|
||
|
},createContext:function (canvas, useWebGL, setInModule, webGLContextAttributes) {
|
||
|
var ctx;
|
||
|
var errorInfo = '?';
|
||
|
function onContextCreationError(event) {
|
||
|
errorInfo = event.statusMessage || errorInfo;
|
||
|
}
|
||
|
try {
|
||
|
if (useWebGL) {
|
||
|
var contextAttributes = {
|
||
|
antialias: false,
|
||
|
alpha: false
|
||
|
};
|
||
|
|
||
|
if (webGLContextAttributes) {
|
||
|
for (var attribute in webGLContextAttributes) {
|
||
|
contextAttributes[attribute] = webGLContextAttributes[attribute];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
canvas.addEventListener('webglcontextcreationerror', onContextCreationError, false);
|
||
|
try {
|
||
|
['experimental-webgl', 'webgl'].some(function(webglId) {
|
||
|
return ctx = canvas.getContext(webglId, contextAttributes);
|
||
|
});
|
||
|
} finally {
|
||
|
canvas.removeEventListener('webglcontextcreationerror', onContextCreationError, false);
|
||
|
}
|
||
|
} else {
|
||
|
ctx = canvas.getContext('2d');
|
||
|
}
|
||
|
if (!ctx) throw ':(';
|
||
|
} catch (e) {
|
||
|
Module.print('Could not create canvas: ' + [errorInfo, e]);
|
||
|
return null;
|
||
|
}
|
||
|
if (useWebGL) {
|
||
|
// Set the background of the WebGL canvas to black
|
||
|
canvas.style.backgroundColor = "black";
|
||
|
|
||
|
// Warn on context loss
|
||
|
canvas.addEventListener('webglcontextlost', function(event) {
|
||
|
alert('WebGL context lost. You will need to reload the page.');
|
||
|
}, false);
|
||
|
}
|
||
|
if (setInModule) {
|
||
|
GLctx = Module.ctx = ctx;
|
||
|
Module.useWebGL = useWebGL;
|
||
|
Browser.moduleContextCreatedCallbacks.forEach(function(callback) { callback() });
|
||
|
Browser.init();
|
||
|
}
|
||
|
return ctx;
|
||
|
},destroyContext:function (canvas, useWebGL, setInModule) {},fullScreenHandlersInstalled:false,lockPointer:undefined,resizeCanvas:undefined,requestFullScreen:function (lockPointer, resizeCanvas) {
|
||
|
Browser.lockPointer = lockPointer;
|
||
|
Browser.resizeCanvas = resizeCanvas;
|
||
|
if (typeof Browser.lockPointer === 'undefined') Browser.lockPointer = true;
|
||
|
if (typeof Browser.resizeCanvas === 'undefined') Browser.resizeCanvas = false;
|
||
|
|
||
|
var canvas = Module['canvas'];
|
||
|
function fullScreenChange() {
|
||
|
Browser.isFullScreen = false;
|
||
|
var canvasContainer = canvas.parentNode;
|
||
|
if ((document['webkitFullScreenElement'] || document['webkitFullscreenElement'] ||
|
||
|
document['mozFullScreenElement'] || document['mozFullscreenElement'] ||
|
||
|
document['fullScreenElement'] || document['fullscreenElement'] ||
|
||
|
document['msFullScreenElement'] || document['msFullscreenElement'] ||
|
||
|
document['webkitCurrentFullScreenElement']) === canvasContainer) {
|
||
|
canvas.cancelFullScreen = document['cancelFullScreen'] ||
|
||
|
document['mozCancelFullScreen'] ||
|
||
|
document['webkitCancelFullScreen'] ||
|
||
|
document['msExitFullscreen'] ||
|
||
|
document['exitFullscreen'] ||
|
||
|
function() {};
|
||
|
canvas.cancelFullScreen = canvas.cancelFullScreen.bind(document);
|
||
|
if (Browser.lockPointer) canvas.requestPointerLock();
|
||
|
Browser.isFullScreen = true;
|
||
|
if (Browser.resizeCanvas) Browser.setFullScreenCanvasSize();
|
||
|
} else {
|
||
|
|
||
|
// remove the full screen specific parent of the canvas again to restore the HTML structure from before going full screen
|
||
|
canvasContainer.parentNode.insertBefore(canvas, canvasContainer);
|
||
|
canvasContainer.parentNode.removeChild(canvasContainer);
|
||
|
|
||
|
if (Browser.resizeCanvas) Browser.setWindowedCanvasSize();
|
||
|
}
|
||
|
if (Module['onFullScreen']) Module['onFullScreen'](Browser.isFullScreen);
|
||
|
Browser.updateCanvasDimensions(canvas);
|
||
|
}
|
||
|
|
||
|
if (!Browser.fullScreenHandlersInstalled) {
|
||
|
Browser.fullScreenHandlersInstalled = true;
|
||
|
document.addEventListener('fullscreenchange', fullScreenChange, false);
|
||
|
document.addEventListener('mozfullscreenchange', fullScreenChange, false);
|
||
|
document.addEventListener('webkitfullscreenchange', fullScreenChange, false);
|
||
|
document.addEventListener('MSFullscreenChange', fullScreenChange, false);
|
||
|
}
|
||
|
|
||
|
// create a new parent to ensure the canvas has no siblings. this allows browsers to optimize full screen performance when its parent is the full screen root
|
||
|
var canvasContainer = document.createElement("div");
|
||
|
canvas.parentNode.insertBefore(canvasContainer, canvas);
|
||
|
canvasContainer.appendChild(canvas);
|
||
|
|
||
|
// use parent of canvas as full screen root to allow aspect ratio correction (Firefox stretches the root to screen size)
|
||
|
canvasContainer.requestFullScreen = canvasContainer['requestFullScreen'] ||
|
||
|
canvasContainer['mozRequestFullScreen'] ||
|
||
|
canvasContainer['msRequestFullscreen'] ||
|
||
|
(canvasContainer['webkitRequestFullScreen'] ? function() { canvasContainer['webkitRequestFullScreen'](Element['ALLOW_KEYBOARD_INPUT']) } : null);
|
||
|
canvasContainer.requestFullScreen();
|
||
|
},requestAnimationFrame:function requestAnimationFrame(func) {
|
||
|
if (typeof window === 'undefined') { // Provide fallback to setTimeout if window is undefined (e.g. in Node.js)
|
||
|
setTimeout(func, 1000/60);
|
||
|
} else {
|
||
|
if (!window.requestAnimationFrame) {
|
||
|
window.requestAnimationFrame = window['requestAnimationFrame'] ||
|
||
|
window['mozRequestAnimationFrame'] ||
|
||
|
window['webkitRequestAnimationFrame'] ||
|
||
|
window['msRequestAnimationFrame'] ||
|
||
|
window['oRequestAnimationFrame'] ||
|
||
|
window['setTimeout'];
|
||
|
}
|
||
|
window.requestAnimationFrame(func);
|
||
|
}
|
||
|
},safeCallback:function (func) {
|
||
|
return function() {
|
||
|
if (!ABORT) return func.apply(null, arguments);
|
||
|
};
|
||
|
},safeRequestAnimationFrame:function (func) {
|
||
|
return Browser.requestAnimationFrame(function() {
|
||
|
if (!ABORT) func();
|
||
|
});
|
||
|
},safeSetTimeout:function (func, timeout) {
|
||
|
Module['noExitRuntime'] = true;
|
||
|
return setTimeout(function() {
|
||
|
if (!ABORT) func();
|
||
|
}, timeout);
|
||
|
},safeSetInterval:function (func, timeout) {
|
||
|
Module['noExitRuntime'] = true;
|
||
|
return setInterval(function() {
|
||
|
if (!ABORT) func();
|
||
|
}, timeout);
|
||
|
},getMimetype:function (name) {
|
||
|
return {
|
||
|
'jpg': 'image/jpeg',
|
||
|
'jpeg': 'image/jpeg',
|
||
|
'png': 'image/png',
|
||
|
'bmp': 'image/bmp',
|
||
|
'ogg': 'audio/ogg',
|
||
|
'wav': 'audio/wav',
|
||
|
'mp3': 'audio/mpeg'
|
||
|
}[name.substr(name.lastIndexOf('.')+1)];
|
||
|
},getUserMedia:function (func) {
|
||
|
if(!window.getUserMedia) {
|
||
|
window.getUserMedia = navigator['getUserMedia'] ||
|
||
|
navigator['mozGetUserMedia'];
|
||
|
}
|
||
|
window.getUserMedia(func);
|
||
|
},getMovementX:function (event) {
|
||
|
return event['movementX'] ||
|
||
|
event['mozMovementX'] ||
|
||
|
event['webkitMovementX'] ||
|
||
|
0;
|
||
|
},getMovementY:function (event) {
|
||
|
return event['movementY'] ||
|
||
|
event['mozMovementY'] ||
|
||
|
event['webkitMovementY'] ||
|
||
|
0;
|
||
|
},getMouseWheelDelta:function (event) {
|
||
|
return Math.max(-1, Math.min(1, event.type === 'DOMMouseScroll' ? event.detail : -event.wheelDelta));
|
||
|
},mouseX:0,mouseY:0,mouseMovementX:0,mouseMovementY:0,touches:{},lastTouches:{},calculateMouseEvent:function (event) { // event should be mousemove, mousedown or mouseup
|
||
|
if (Browser.pointerLock) {
|
||
|
// When the pointer is locked, calculate the coordinates
|
||
|
// based on the movement of the mouse.
|
||
|
// Workaround for Firefox bug 764498
|
||
|
if (event.type != 'mousemove' &&
|
||
|
('mozMovementX' in event)) {
|
||
|
Browser.mouseMovementX = Browser.mouseMovementY = 0;
|
||
|
} else {
|
||
|
Browser.mouseMovementX = Browser.getMovementX(event);
|
||
|
Browser.mouseMovementY = Browser.getMovementY(event);
|
||
|
}
|
||
|
|
||
|
// check if SDL is available
|
||
|
if (typeof SDL != "undefined") {
|
||
|
Browser.mouseX = SDL.mouseX + Browser.mouseMovementX;
|
||
|
Browser.mouseY = SDL.mouseY + Browser.mouseMovementY;
|
||
|
} else {
|
||
|
// just add the mouse delta to the current absolut mouse position
|
||
|
// FIXME: ideally this should be clamped against the canvas size and zero
|
||
|
Browser.mouseX += Browser.mouseMovementX;
|
||
|
Browser.mouseY += Browser.mouseMovementY;
|
||
|
}
|
||
|
} else {
|
||
|
// Otherwise, calculate the movement based on the changes
|
||
|
// in the coordinates.
|
||
|
var rect = Module["canvas"].getBoundingClientRect();
|
||
|
var cw = Module["canvas"].width;
|
||
|
var ch = Module["canvas"].height;
|
||
|
|
||
|
// Neither .scrollX or .pageXOffset are defined in a spec, but
|
||
|
// we prefer .scrollX because it is currently in a spec draft.
|
||
|
// (see: http://www.w3.org/TR/2013/WD-cssom-view-20131217/)
|
||
|
var scrollX = ((typeof window.scrollX !== 'undefined') ? window.scrollX : window.pageXOffset);
|
||
|
var scrollY = ((typeof window.scrollY !== 'undefined') ? window.scrollY : window.pageYOffset);
|
||
|
|
||
|
if (event.type === 'touchstart' || event.type === 'touchend' || event.type === 'touchmove') {
|
||
|
var touch = event.touch;
|
||
|
if (touch === undefined) {
|
||
|
return; // the "touch" property is only defined in SDL
|
||
|
|
||
|
}
|
||
|
var adjustedX = touch.pageX - (scrollX + rect.left);
|
||
|
var adjustedY = touch.pageY - (scrollY + rect.top);
|
||
|
|
||
|
adjustedX = adjustedX * (cw / rect.width);
|
||
|
adjustedY = adjustedY * (ch / rect.height);
|
||
|
|
||
|
var coords = { x: adjustedX, y: adjustedY };
|
||
|
|
||
|
if (event.type === 'touchstart') {
|
||
|
Browser.lastTouches[touch.identifier] = coords;
|
||
|
Browser.touches[touch.identifier] = coords;
|
||
|
} else if (event.type === 'touchend' || event.type === 'touchmove') {
|
||
|
Browser.lastTouches[touch.identifier] = Browser.touches[touch.identifier];
|
||
|
Browser.touches[touch.identifier] = { x: adjustedX, y: adjustedY };
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
var x = event.pageX - (scrollX + rect.left);
|
||
|
var y = event.pageY - (scrollY + rect.top);
|
||
|
|
||
|
// the canvas might be CSS-scaled compared to its backbuffer;
|
||
|
// SDL-using content will want mouse coordinates in terms
|
||
|
// of backbuffer units.
|
||
|
x = x * (cw / rect.width);
|
||
|
y = y * (ch / rect.height);
|
||
|
|
||
|
Browser.mouseMovementX = x - Browser.mouseX;
|
||
|
Browser.mouseMovementY = y - Browser.mouseY;
|
||
|
Browser.mouseX = x;
|
||
|
Browser.mouseY = y;
|
||
|
}
|
||
|
},xhrLoad:function (url, onload, onerror) {
|
||
|
var xhr = new XMLHttpRequest();
|
||
|
xhr.open('GET', url, true);
|
||
|
xhr.responseType = 'arraybuffer';
|
||
|
xhr.onload = function xhr_onload() {
|
||
|
if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
|
||
|
onload(xhr.response);
|
||
|
} else {
|
||
|
onerror();
|
||
|
}
|
||
|
};
|
||
|
xhr.onerror = onerror;
|
||
|
xhr.send(null);
|
||
|
},asyncLoad:function (url, onload, onerror, noRunDep) {
|
||
|
Browser.xhrLoad(url, function(arrayBuffer) {
|
||
|
assert(arrayBuffer, 'Loading data file "' + url + '" failed (no arrayBuffer).');
|
||
|
onload(new Uint8Array(arrayBuffer));
|
||
|
if (!noRunDep) removeRunDependency('al ' + url);
|
||
|
}, function(event) {
|
||
|
if (onerror) {
|
||
|
onerror();
|
||
|
} else {
|
||
|
throw 'Loading data file "' + url + '" failed.';
|
||
|
}
|
||
|
});
|
||
|
if (!noRunDep) addRunDependency('al ' + url);
|
||
|
},resizeListeners:[],updateResizeListeners:function () {
|
||
|
var canvas = Module['canvas'];
|
||
|
Browser.resizeListeners.forEach(function(listener) {
|
||
|
listener(canvas.width, canvas.height);
|
||
|
});
|
||
|
},setCanvasSize:function (width, height, noUpdates) {
|
||
|
var canvas = Module['canvas'];
|
||
|
Browser.updateCanvasDimensions(canvas, width, height);
|
||
|
if (!noUpdates) Browser.updateResizeListeners();
|
||
|
},windowedWidth:0,windowedHeight:0,setFullScreenCanvasSize:function () {
|
||
|
// check if SDL is available
|
||
|
if (typeof SDL != "undefined") {
|
||
|
var flags = HEAPU32[((SDL.screen+Runtime.QUANTUM_SIZE*0)>>2)];
|
||
|
flags = flags | 0x00800000; // set SDL_FULLSCREEN flag
|
||
|
HEAP32[((SDL.screen+Runtime.QUANTUM_SIZE*0)>>2)]=flags
|
||
|
}
|
||
|
Browser.updateResizeListeners();
|
||
|
},setWindowedCanvasSize:function () {
|
||
|
// check if SDL is available
|
||
|
if (typeof SDL != "undefined") {
|
||
|
var flags = HEAPU32[((SDL.screen+Runtime.QUANTUM_SIZE*0)>>2)];
|
||
|
flags = flags & ~0x00800000; // clear SDL_FULLSCREEN flag
|
||
|
HEAP32[((SDL.screen+Runtime.QUANTUM_SIZE*0)>>2)]=flags
|
||
|
}
|
||
|
Browser.updateResizeListeners();
|
||
|
},updateCanvasDimensions:function (canvas, wNative, hNative) {
|
||
|
if (wNative && hNative) {
|
||
|
canvas.widthNative = wNative;
|
||
|
canvas.heightNative = hNative;
|
||
|
} else {
|
||
|
wNative = canvas.widthNative;
|
||
|
hNative = canvas.heightNative;
|
||
|
}
|
||
|
var w = wNative;
|
||
|
var h = hNative;
|
||
|
if (Module['forcedAspectRatio'] && Module['forcedAspectRatio'] > 0) {
|
||
|
if (w/h < Module['forcedAspectRatio']) {
|
||
|
w = Math.round(h * Module['forcedAspectRatio']);
|
||
|
} else {
|
||
|
h = Math.round(w / Module['forcedAspectRatio']);
|
||
|
}
|
||
|
}
|
||
|
if (((document['webkitFullScreenElement'] || document['webkitFullscreenElement'] ||
|
||
|
document['mozFullScreenElement'] || document['mozFullscreenElement'] ||
|
||
|
document['fullScreenElement'] || document['fullscreenElement'] ||
|
||
|
document['msFullScreenElement'] || document['msFullscreenElement'] ||
|
||
|
document['webkitCurrentFullScreenElement']) === canvas.parentNode) && (typeof screen != 'undefined')) {
|
||
|
var factor = Math.min(screen.width / w, screen.height / h);
|
||
|
w = Math.round(w * factor);
|
||
|
h = Math.round(h * factor);
|
||
|
}
|
||
|
if (Browser.resizeCanvas) {
|
||
|
if (canvas.width != w) canvas.width = w;
|
||
|
if (canvas.height != h) canvas.height = h;
|
||
|
if (typeof canvas.style != 'undefined') {
|
||
|
canvas.style.removeProperty( "width");
|
||
|
canvas.style.removeProperty("height");
|
||
|
}
|
||
|
} else {
|
||
|
if (canvas.width != wNative) canvas.width = wNative;
|
||
|
if (canvas.height != hNative) canvas.height = hNative;
|
||
|
if (typeof canvas.style != 'undefined') {
|
||
|
if (w != wNative || h != hNative) {
|
||
|
canvas.style.setProperty( "width", w + "px", "important");
|
||
|
canvas.style.setProperty("height", h + "px", "important");
|
||
|
} else {
|
||
|
canvas.style.removeProperty( "width");
|
||
|
canvas.style.removeProperty("height");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}};
|
||
|
|
||
|
function _SDL_GetTicks() {
|
||
|
return Math.floor(Date.now() - SDL.startTime);
|
||
|
}var SDL={defaults:{width:320,height:200,copyOnLock:true},version:null,surfaces:{},canvasPool:[],events:[],fonts:[null],audios:[null],rwops:[null],music:{audio:null,volume:1},mixerFrequency:22050,mixerFormat:32784,mixerNumChannels:2,mixerChunkSize:1024,channelMinimumNumber:0,GL:false,glAttributes:{0:3,1:3,2:2,3:0,4:0,5:1,6:16,7:0,8:0,9:0,10:0,11:0,12:0,13:0,14:0,15:1,16:0,17:0,18:0},keyboardState:null,keyboardMap:{},canRequestFullscreen:false,isRequestingFullscreen:false,textInput:false,startTime:null,initFlags:0,buttonState:0,modState:0,DOMButtons:[0,0,0],DOMEventToSDLEvent:{},TOUCH_DEFAULT_ID:0,keyCodes:{16:1249,17:1248,18:1250,20:1081,33:1099,34:1102,35:1101,36:1098,37:1104,38:1106,39:1103,40:1105,44:316,45:1097,46:127,91:1251,93:1125,96:1122,97:1113,98:1114,99:1115,100:1116,101:1117,102:1118,103:1119,104:1120,105:1121,106:1109,107:1111,109:1110,110:1123,111:1108,112:1082,113:1083,114:1084,115:1085,116:1086,117:1087,118:1088,119:1089,120:1090,121:1091,122:1092,123:1093,124:1128,125:1129,126:1130,127:1131,128:1132,129:1133,130:1134,131:1135,132:1136,133:1137,134:1138,135:1139,144:1107,160:94,161:33,162:34,163:35,164:36,165:37,166:38,167:95,168:40,169:41,170:42,171:43,172:124,173:45,174:123,175:125,176:126,181:127,182:129,183:128,188:44,190:46,191:47,192:96,219:91,220:92,221:93,222:39},scanCodes:{8:42,9:43,13:40,27:41,32:44,35:204,39:53,44:54,46:55,47:56,48:39,49:30,50:31,51:32,52:33,53:34,54:35,55:36,56:37,57:38,58:203,59:51,61:46,91:47,92:49,93:48,96:52,97:4,98:5,99:6,100:7,101:8,102:9,103:10,104:11,105:12,106:13,107:14,108:15,109:16,110:17,111:18,112:19,113:20,114:21,115:22,116:23,117:24,118:25,119:26,120:27,121:28,122:29,127:76,305:224,308:226,316:70},loadRect:function (rect) {
|
||
|
return {
|
||
|
x: HEAP32[((rect + 0)>>2)],
|
||
|
y: HEAP32[((rect + 4)>>2)],
|
||
|
w: HEAP32[((rect + 8)>>2)],
|
||
|
h: HEAP32[((rect + 12)>>2)]
|
||
|
};
|
||
|
},loadColorToCSSRGB:function (color) {
|
||
|
var rgba = HEAP32[((color)>>2)];
|
||
|
return 'rgb(' + (rgba&255) + ',' + ((rgba >> 8)&255) + ',' + ((rgba >> 16)&255) + ')';
|
||
|
},loadColorToCSSRGBA:function (color) {
|
||
|
var rgba = HEAP32[((color)>>2)];
|
||
|
return 'rgba(' + (rgba&255) + ',' + ((rgba >> 8)&255) + ',' + ((rgba >> 16)&255) + ',' + (((rgba >> 24)&255)/255) + ')';
|
||
|
},translateColorToCSSRGBA:function (rgba) {
|
||
|
return 'rgba(' + (rgba&0xff) + ',' + (rgba>>8 & 0xff) + ',' + (rgba>>16 & 0xff) + ',' + (rgba>>>24)/0xff + ')';
|
||
|
},translateRGBAToCSSRGBA:function (r, g, b, a) {
|
||
|
return 'rgba(' + (r&0xff) + ',' + (g&0xff) + ',' + (b&0xff) + ',' + (a&0xff)/255 + ')';
|
||
|
},translateRGBAToColor:function (r, g, b, a) {
|
||
|
return r | g << 8 | b << 16 | a << 24;
|
||
|
},makeSurface:function (width, height, flags, usePageCanvas, source, rmask, gmask, bmask, amask) {
|
||
|
flags = flags || 0;
|
||
|
var is_SDL_HWSURFACE = flags & 0x00000001;
|
||
|
var is_SDL_HWPALETTE = flags & 0x00200000;
|
||
|
var is_SDL_OPENGL = flags & 0x04000000;
|
||
|
|
||
|
var surf = _malloc(60);
|
||
|
var pixelFormat = _malloc(44);
|
||
|
//surface with SDL_HWPALETTE flag is 8bpp surface (1 byte)
|
||
|
var bpp = is_SDL_HWPALETTE ? 1 : 4;
|
||
|
var buffer = 0;
|
||
|
|
||
|
// preemptively initialize this for software surfaces,
|
||
|
// otherwise it will be lazily initialized inside of SDL_LockSurface
|
||
|
if (!is_SDL_HWSURFACE && !is_SDL_OPENGL) {
|
||
|
buffer = _malloc(width * height * 4);
|
||
|
}
|
||
|
|
||
|
HEAP32[((surf)>>2)]=flags;
|
||
|
HEAP32[(((surf)+(4))>>2)]=pixelFormat;
|
||
|
HEAP32[(((surf)+(8))>>2)]=width;
|
||
|
HEAP32[(((surf)+(12))>>2)]=height;
|
||
|
HEAP32[(((surf)+(16))>>2)]=width * bpp; // assuming RGBA or indexed for now,
|
||
|
// since that is what ImageData gives us in browsers
|
||
|
HEAP32[(((surf)+(20))>>2)]=buffer;
|
||
|
HEAP32[(((surf)+(36))>>2)]=0;
|
||
|
HEAP32[(((surf)+(56))>>2)]=1;
|
||
|
|
||
|
HEAP32[((pixelFormat)>>2)]=0 /* XXX missing C define SDL_PIXELFORMAT_RGBA8888 */;
|
||
|
HEAP32[(((pixelFormat)+(4))>>2)]=0;// TODO
|
||
|
HEAP8[(((pixelFormat)+(8))>>0)]=bpp * 8;
|
||
|
HEAP8[(((pixelFormat)+(9))>>0)]=bpp;
|
||
|
|
||
|
HEAP32[(((pixelFormat)+(12))>>2)]=rmask || 0x000000ff;
|
||
|
HEAP32[(((pixelFormat)+(16))>>2)]=gmask || 0x0000ff00;
|
||
|
HEAP32[(((pixelFormat)+(20))>>2)]=bmask || 0x00ff0000;
|
||
|
HEAP32[(((pixelFormat)+(24))>>2)]=amask || 0xff000000;
|
||
|
|
||
|
// Decide if we want to use WebGL or not
|
||
|
SDL.GL = SDL.GL || is_SDL_OPENGL;
|
||
|
var canvas;
|
||
|
if (!usePageCanvas) {
|
||
|
if (SDL.canvasPool.length > 0) {
|
||
|
canvas = SDL.canvasPool.pop();
|
||
|
} else {
|
||
|
canvas = document.createElement('canvas');
|
||
|
}
|
||
|
canvas.width = width;
|
||
|
canvas.height = height;
|
||
|
} else {
|
||
|
canvas = Module['canvas'];
|
||
|
}
|
||
|
|
||
|
var webGLContextAttributes = {
|
||
|
antialias: ((SDL.glAttributes[13 /*SDL_GL_MULTISAMPLEBUFFERS*/] != 0) && (SDL.glAttributes[14 /*SDL_GL_MULTISAMPLESAMPLES*/] > 1)),
|
||
|
depth: (SDL.glAttributes[6 /*SDL_GL_DEPTH_SIZE*/] > 0),
|
||
|
stencil: (SDL.glAttributes[7 /*SDL_GL_STENCIL_SIZE*/] > 0)
|
||
|
};
|
||
|
|
||
|
var ctx = Browser.createContext(canvas, is_SDL_OPENGL, usePageCanvas, webGLContextAttributes);
|
||
|
|
||
|
SDL.surfaces[surf] = {
|
||
|
width: width,
|
||
|
height: height,
|
||
|
canvas: canvas,
|
||
|
ctx: ctx,
|
||
|
surf: surf,
|
||
|
buffer: buffer,
|
||
|
pixelFormat: pixelFormat,
|
||
|
alpha: 255,
|
||
|
flags: flags,
|
||
|
locked: 0,
|
||
|
usePageCanvas: usePageCanvas,
|
||
|
source: source,
|
||
|
|
||
|
isFlagSet: function(flag) {
|
||
|
return flags & flag;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
return surf;
|
||
|
},copyIndexedColorData:function (surfData, rX, rY, rW, rH) {
|
||
|
// HWPALETTE works with palette
|
||
|
// setted by SDL_SetColors
|
||
|
if (!surfData.colors) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
var fullWidth = Module['canvas'].width;
|
||
|
var fullHeight = Module['canvas'].height;
|
||
|
|
||
|
var startX = rX || 0;
|
||
|
var startY = rY || 0;
|
||
|
var endX = (rW || (fullWidth - startX)) + startX;
|
||
|
var endY = (rH || (fullHeight - startY)) + startY;
|
||
|
|
||
|
var buffer = surfData.buffer;
|
||
|
var data = surfData.image.data;
|
||
|
var colors = surfData.colors;
|
||
|
|
||
|
for (var y = startY; y < endY; ++y) {
|
||
|
var indexBase = y * fullWidth;
|
||
|
var colorBase = indexBase * 4;
|
||
|
for (var x = startX; x < endX; ++x) {
|
||
|
// HWPALETTE have only 256 colors (not rgba)
|
||
|
var index = HEAPU8[((buffer + indexBase + x)>>0)] * 3;
|
||
|
var colorOffset = colorBase + x * 4;
|
||
|
|
||
|
data[colorOffset ] = colors[index ];
|
||
|
data[colorOffset +1] = colors[index +1];
|
||
|
data[colorOffset +2] = colors[index +2];
|
||
|
//unused: data[colorOffset +3] = color[index +3];
|
||
|
}
|
||
|
}
|
||
|
},freeSurface:function (surf) {
|
||
|
var refcountPointer = surf + 56;
|
||
|
var refcount = HEAP32[((refcountPointer)>>2)];
|
||
|
if (refcount > 1) {
|
||
|
HEAP32[((refcountPointer)>>2)]=refcount - 1;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
var info = SDL.surfaces[surf];
|
||
|
if (!info) return; // surface has already been freed
|
||
|
if (!info.usePageCanvas && info.canvas) SDL.canvasPool.push(info.canvas);
|
||
|
if (info.buffer) _free(info.buffer);
|
||
|
_free(info.pixelFormat);
|
||
|
_free(surf);
|
||
|
SDL.surfaces[surf] = null;
|
||
|
|
||
|
if (surf === SDL.screen) {
|
||
|
SDL.screen = null;
|
||
|
}
|
||
|
},downFingers:{},savedKeydown:null,receiveEvent:function (event) {
|
||
|
switch(event.type) {
|
||
|
case 'touchstart': case 'touchmove': {
|
||
|
event.preventDefault();
|
||
|
|
||
|
var touches = [];
|
||
|
|
||
|
// Clear out any touchstart events that we've already processed
|
||
|
if (event.type === 'touchstart') {
|
||
|
for (var i = 0; i < event.touches.length; i++) {
|
||
|
var touch = event.touches[i];
|
||
|
if (SDL.downFingers[touch.identifier] != true) {
|
||
|
SDL.downFingers[touch.identifier] = true;
|
||
|
touches.push(touch);
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
|
touches = event.touches;
|
||
|
}
|
||
|
|
||
|
var firstTouch = touches[0];
|
||
|
if (event.type == 'touchstart') {
|
||
|
SDL.DOMButtons[0] = 1;
|
||
|
}
|
||
|
var mouseEventType;
|
||
|
switch(event.type) {
|
||
|
case 'touchstart': mouseEventType = 'mousedown'; break;
|
||
|
case 'touchmove': mouseEventType = 'mousemove'; break;
|
||
|
}
|
||
|
var mouseEvent = {
|
||
|
type: mouseEventType,
|
||
|
button: 0,
|
||
|
pageX: firstTouch.clientX,
|
||
|
pageY: firstTouch.clientY
|
||
|
};
|
||
|
SDL.events.push(mouseEvent);
|
||
|
|
||
|
for (var i = 0; i < touches.length; i++) {
|
||
|
var touch = touches[i];
|
||
|
SDL.events.push({
|
||
|
type: event.type,
|
||
|
touch: touch
|
||
|
});
|
||
|
};
|
||
|
break;
|
||
|
}
|
||
|
case 'touchend': {
|
||
|
event.preventDefault();
|
||
|
|
||
|
// Remove the entry in the SDL.downFingers hash
|
||
|
// because the finger is no longer down.
|
||
|
for(var i = 0; i < event.changedTouches.length; i++) {
|
||
|
var touch = event.changedTouches[i];
|
||
|
if (SDL.downFingers[touch.identifier] === true) {
|
||
|
delete SDL.downFingers[touch.identifier];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var mouseEvent = {
|
||
|
type: 'mouseup',
|
||
|
button: 0,
|
||
|
pageX: event.changedTouches[0].clientX,
|
||
|
pageY: event.changedTouches[0].clientY
|
||
|
};
|
||
|
SDL.DOMButtons[0] = 0;
|
||
|
SDL.events.push(mouseEvent);
|
||
|
|
||
|
for (var i = 0; i < event.changedTouches.length; i++) {
|
||
|
var touch = event.changedTouches[i];
|
||
|
SDL.events.push({
|
||
|
type: 'touchend',
|
||
|
touch: touch
|
||
|
});
|
||
|
};
|
||
|
break;
|
||
|
}
|
||
|
case 'mousemove':
|
||
|
if (SDL.DOMButtons[0] === 1) {
|
||
|
SDL.events.push({
|
||
|
type: 'touchmove',
|
||
|
touch: {
|
||
|
identifier: 0,
|
||
|
deviceID: -1,
|
||
|
pageX: event.pageX,
|
||
|
pageY: event.pageY
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
if (Browser.pointerLock) {
|
||
|
// workaround for firefox bug 750111
|
||
|
if ('mozMovementX' in event) {
|
||
|
event['movementX'] = event['mozMovementX'];
|
||
|
event['movementY'] = event['mozMovementY'];
|
||
|
}
|
||
|
// workaround for Firefox bug 782777
|
||
|
if (event['movementX'] == 0 && event['movementY'] == 0) {
|
||
|
// ignore a mousemove event if it doesn't contain any movement info
|
||
|
// (without pointer lock, we infer movement from pageX/pageY, so this check is unnecessary)
|
||
|
event.preventDefault();
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
// fall through
|
||
|
case 'keydown': case 'keyup': case 'keypress': case 'mousedown': case 'mouseup': case 'DOMMouseScroll': case 'mousewheel':
|
||
|
// If we preventDefault on keydown events, the subsequent keypress events
|
||
|
// won't fire. However, it's fine (and in some cases necessary) to
|
||
|
// preventDefault for keys that don't generate a character. Otherwise,
|
||
|
// preventDefault is the right thing to do in general.
|
||
|
if (event.type !== 'keydown' || (!SDL.unicode && !SDL.textInput) || (event.keyCode === 8 /* backspace */ || event.keyCode === 9 /* tab */)) {
|
||
|
event.preventDefault();
|
||
|
}
|
||
|
|
||
|
if (event.type == 'DOMMouseScroll' || event.type == 'mousewheel') {
|
||
|
var button = Browser.getMouseWheelDelta(event) > 0 ? 4 : 3;
|
||
|
var event2 = {
|
||
|
type: 'mousedown',
|
||
|
button: button,
|
||
|
pageX: event.pageX,
|
||
|
pageY: event.pageY
|
||
|
};
|
||
|
SDL.events.push(event2);
|
||
|
event = {
|
||
|
type: 'mouseup',
|
||
|
button: button,
|
||
|
pageX: event.pageX,
|
||
|
pageY: event.pageY
|
||
|
};
|
||
|
} else if (event.type == 'mousedown') {
|
||
|
SDL.DOMButtons[event.button] = 1;
|
||
|
SDL.events.push({
|
||
|
type: 'touchstart',
|
||
|
touch: {
|
||
|
identifier: 0,
|
||
|
deviceID: -1,
|
||
|
pageX: event.pageX,
|
||
|
pageY: event.pageY
|
||
|
}
|
||
|
});
|
||
|
} else if (event.type == 'mouseup') {
|
||
|
// ignore extra ups, can happen if we leave the canvas while pressing down, then return,
|
||
|
// since we add a mouseup in that case
|
||
|
if (!SDL.DOMButtons[event.button]) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
SDL.events.push({
|
||
|
type: 'touchend',
|
||
|
touch: {
|
||
|
identifier: 0,
|
||
|
deviceID: -1,
|
||
|
pageX: event.pageX,
|
||
|
pageY: event.pageY
|
||
|
}
|
||
|
});
|
||
|
SDL.DOMButtons[event.button] = 0;
|
||
|
}
|
||
|
|
||
|
// We can only request fullscreen as the result of user input.
|
||
|
// Due to this limitation, we toggle a boolean on keydown which
|
||
|
// SDL_WM_ToggleFullScreen will check and subsequently set another
|
||
|
// flag indicating for us to request fullscreen on the following
|
||
|
// keyup. This isn't perfect, but it enables SDL_WM_ToggleFullScreen
|
||
|
// to work as the result of a keypress (which is an extremely
|
||
|
// common use case).
|
||
|
if (event.type === 'keydown' || event.type === 'mousedown') {
|
||
|
SDL.canRequestFullscreen = true;
|
||
|
} else if (event.type === 'keyup' || event.type === 'mouseup') {
|
||
|
if (SDL.isRequestingFullscreen) {
|
||
|
Module['requestFullScreen'](true, true);
|
||
|
SDL.isRequestingFullscreen = false;
|
||
|
}
|
||
|
SDL.canRequestFullscreen = false;
|
||
|
}
|
||
|
|
||
|
// SDL expects a unicode character to be passed to its keydown events.
|
||
|
// Unfortunately, the browser APIs only provide a charCode property on
|
||
|
// keypress events, so we must backfill in keydown events with their
|
||
|
// subsequent keypress event's charCode.
|
||
|
if (event.type === 'keypress' && SDL.savedKeydown) {
|
||
|
// charCode is read-only
|
||
|
SDL.savedKeydown.keypressCharCode = event.charCode;
|
||
|
SDL.savedKeydown = null;
|
||
|
} else if (event.type === 'keydown') {
|
||
|
SDL.savedKeydown = event;
|
||
|
}
|
||
|
|
||
|
// Don't push keypress events unless SDL_StartTextInput has been called.
|
||
|
if (event.type !== 'keypress' || SDL.textInput) {
|
||
|
SDL.events.push(event);
|
||
|
}
|
||
|
break;
|
||
|
case 'mouseout':
|
||
|
// Un-press all pressed mouse buttons, because we might miss the release outside of the canvas
|
||
|
for (var i = 0; i < 3; i++) {
|
||
|
if (SDL.DOMButtons[i]) {
|
||
|
SDL.events.push({
|
||
|
type: 'mouseup',
|
||
|
button: i,
|
||
|
pageX: event.pageX,
|
||
|
pageY: event.pageY
|
||
|
});
|
||
|
SDL.DOMButtons[i] = 0;
|
||
|
}
|
||
|
}
|
||
|
event.preventDefault();
|
||
|
break;
|
||
|
case 'blur':
|
||
|
case 'visibilitychange': {
|
||
|
// Un-press all pressed keys: TODO
|
||
|
for (var code in SDL.keyboardMap) {
|
||
|
SDL.events.push({
|
||
|
type: 'keyup',
|
||
|
keyCode: SDL.keyboardMap[code]
|
||
|
});
|
||
|
}
|
||
|
event.preventDefault();
|
||
|
break;
|
||
|
}
|
||
|
case 'unload':
|
||
|
if (Browser.mainLoop.runner) {
|
||
|
SDL.events.push(event);
|
||
|
// Force-run a main event loop, since otherwise this event will never be caught!
|
||
|
Browser.mainLoop.runner();
|
||
|
}
|
||
|
return;
|
||
|
case 'resize':
|
||
|
SDL.events.push(event);
|
||
|
// manually triggered resize event doesn't have a preventDefault member
|
||
|
if (event.preventDefault) {
|
||
|
event.preventDefault();
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
if (SDL.events.length >= 10000) {
|
||
|
Module.printErr('SDL event queue full, dropping events');
|
||
|
SDL.events = SDL.events.slice(0, 10000);
|
||
|
}
|
||
|
return;
|
||
|
},handleEvent:function (event) {
|
||
|
if (event.handled) return;
|
||
|
event.handled = true;
|
||
|
|
||
|
switch (event.type) {
|
||
|
case 'touchstart': case 'touchend': case 'touchmove': {
|
||
|
Browser.calculateMouseEvent(event);
|
||
|
break;
|
||
|
}
|
||
|
case 'keydown': case 'keyup': {
|
||
|
var down = event.type === 'keydown';
|
||
|
var code = event.keyCode;
|
||
|
if (code >= 65 && code <= 90) {
|
||
|
code += 32; // make lowercase for SDL
|
||
|
} else {
|
||
|
code = SDL.keyCodes[event.keyCode] || event.keyCode;
|
||
|
}
|
||
|
HEAP8[(((SDL.keyboardState)+(code))>>0)]=down;
|
||
|
// TODO: lmeta, rmeta, numlock, capslock, KMOD_MODE, KMOD_RESERVED
|
||
|
SDL.modState = (HEAP8[(((SDL.keyboardState)+(1248))>>0)] ? 0x0040 | 0x0080 : 0) | // KMOD_LCTRL & KMOD_RCTRL
|
||
|
(HEAP8[(((SDL.keyboardState)+(1249))>>0)] ? 0x0001 | 0x0002 : 0) | // KMOD_LSHIFT & KMOD_RSHIFT
|
||
|
(HEAP8[(((SDL.keyboardState)+(1250))>>0)] ? 0x0100 | 0x0200 : 0); // KMOD_LALT & KMOD_RALT
|
||
|
|
||
|
if (down) {
|
||
|
SDL.keyboardMap[code] = event.keyCode; // save the DOM input, which we can use to unpress it during blur
|
||
|
} else {
|
||
|
delete SDL.keyboardMap[code];
|
||
|
}
|
||
|
|
||
|
break;
|
||
|
}
|
||
|
case 'mousedown': case 'mouseup':
|
||
|
if (event.type == 'mousedown') {
|
||
|
// SDL_BUTTON(x) is defined as (1 << ((x)-1)). SDL buttons are 1-3,
|
||
|
// and DOM buttons are 0-2, so this means that the below formula is
|
||
|
// correct.
|
||
|
SDL.buttonState |= 1 << event.button;
|
||
|
} else if (event.type == 'mouseup') {
|
||
|
SDL.buttonState &= ~(1 << event.button);
|
||
|
}
|
||
|
// fall through
|
||
|
case 'mousemove': {
|
||
|
Browser.calculateMouseEvent(event);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
},makeCEvent:function (event, ptr) {
|
||
|
if (typeof event === 'number') {
|
||
|
// This is a pointer to a native C event that was SDL_PushEvent'ed
|
||
|
_memcpy(ptr, event, 28); // XXX
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
SDL.handleEvent(event);
|
||
|
|
||
|
switch (event.type) {
|
||
|
case 'keydown': case 'keyup': {
|
||
|
var down = event.type === 'keydown';
|
||
|
//Module.print('Received key event: ' + event.keyCode);
|
||
|
var key = event.keyCode;
|
||
|
if (key >= 65 && key <= 90) {
|
||
|
key += 32; // make lowercase for SDL
|
||
|
} else {
|
||
|
key = SDL.keyCodes[event.keyCode] || event.keyCode;
|
||
|
}
|
||
|
var scan;
|
||
|
if (key >= 1024) {
|
||
|
scan = key - 1024;
|
||
|
} else {
|
||
|
scan = SDL.scanCodes[key] || key;
|
||
|
}
|
||
|
|
||
|
HEAP32[((ptr)>>2)]=SDL.DOMEventToSDLEvent[event.type];
|
||
|
HEAP8[(((ptr)+(8))>>0)]=down ? 1 : 0;
|
||
|
HEAP8[(((ptr)+(9))>>0)]=0; // TODO
|
||
|
HEAP32[(((ptr)+(12))>>2)]=scan;
|
||
|
HEAP32[(((ptr)+(16))>>2)]=key;
|
||
|
HEAP16[(((ptr)+(20))>>1)]=SDL.modState;
|
||
|
// some non-character keys (e.g. backspace and tab) won't have keypressCharCode set, fill in with the keyCode.
|
||
|
HEAP32[(((ptr)+(24))>>2)]=event.keypressCharCode || key;
|
||
|
|
||
|
break;
|
||
|
}
|
||
|
case 'keypress': {
|
||
|
HEAP32[((ptr)>>2)]=SDL.DOMEventToSDLEvent[event.type];
|
||
|
// Not filling in windowID for now
|
||
|
var cStr = intArrayFromString(String.fromCharCode(event.charCode));
|
||
|
for (var i = 0; i < cStr.length; ++i) {
|
||
|
HEAP8[(((ptr)+(8 + i))>>0)]=cStr[i];
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
case 'mousedown': case 'mouseup': case 'mousemove': {
|
||
|
if (event.type != 'mousemove') {
|
||
|
var down = event.type === 'mousedown';
|
||
|
HEAP32[((ptr)>>2)]=SDL.DOMEventToSDLEvent[event.type];
|
||
|
HEAP32[(((ptr)+(4))>>2)]=0;
|
||
|
HEAP32[(((ptr)+(8))>>2)]=0;
|
||
|
HEAP32[(((ptr)+(12))>>2)]=0;
|
||
|
HEAP8[(((ptr)+(16))>>0)]=event.button+1; // DOM buttons are 0-2, SDL 1-3
|
||
|
HEAP8[(((ptr)+(17))>>0)]=down ? 1 : 0;
|
||
|
HEAP32[(((ptr)+(20))>>2)]=Browser.mouseX;
|
||
|
HEAP32[(((ptr)+(24))>>2)]=Browser.mouseY;
|
||
|
} else {
|
||
|
HEAP32[((ptr)>>2)]=SDL.DOMEventToSDLEvent[event.type];
|
||
|
HEAP32[(((ptr)+(4))>>2)]=0;
|
||
|
HEAP32[(((ptr)+(8))>>2)]=0;
|
||
|
HEAP32[(((ptr)+(12))>>2)]=0;
|
||
|
HEAP32[(((ptr)+(16))>>2)]=SDL.buttonState;
|
||
|
HEAP32[(((ptr)+(20))>>2)]=Browser.mouseX;
|
||
|
HEAP32[(((ptr)+(24))>>2)]=Browser.mouseY;
|
||
|
HEAP32[(((ptr)+(28))>>2)]=Browser.mouseMovementX;
|
||
|
HEAP32[(((ptr)+(32))>>2)]=Browser.mouseMovementY;
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
case 'touchstart': case 'touchend': case 'touchmove': {
|
||
|
var touch = event.touch;
|
||
|
if (!Browser.touches[touch.identifier]) break;
|
||
|
var w = Module['canvas'].width;
|
||
|
var h = Module['canvas'].height;
|
||
|
var x = Browser.touches[touch.identifier].x / w;
|
||
|
var y = Browser.touches[touch.identifier].y / h;
|
||
|
var lx = Browser.lastTouches[touch.identifier].x / w;
|
||
|
var ly = Browser.lastTouches[touch.identifier].y / h;
|
||
|
var dx = x - lx;
|
||
|
var dy = y - ly;
|
||
|
if (touch['deviceID'] === undefined) touch.deviceID = SDL.TOUCH_DEFAULT_ID;
|
||
|
if (dx === 0 && dy === 0 && event.type === 'touchmove') return; // don't send these if nothing happened
|
||
|
HEAP32[((ptr)>>2)]=SDL.DOMEventToSDLEvent[event.type];
|
||
|
HEAP32[(((ptr)+(4))>>2)]=_SDL_GetTicks();
|
||
|
(tempI64 = [touch.deviceID>>>0,(tempDouble=touch.deviceID,(+(Math_abs(tempDouble))) >= (+1) ? (tempDouble > (+0) ? ((Math_min((+(Math_floor((tempDouble)/(+4294967296)))), (+4294967295)))|0)>>>0 : (~~((+(Math_ceil((tempDouble - +(((~~(tempDouble)))>>>0))/(+4294967296))))))>>>0) : 0)],HEAP32[(((ptr)+(8))>>2)]=tempI64[0],HEAP32[(((ptr)+(12))>>2)]=tempI64[1]);
|
||
|
(tempI64 = [touch.identifier>>>0,(tempDouble=touch.identifier,(+(Math_abs(tempDouble))) >= (+1) ? (tempDouble > (+0) ? ((Math_min((+(Math_floor((tempDouble)/(+4294967296)))), (+4294967295)))|0)>>>0 : (~~((+(Math_ceil((tempDouble - +(((~~(tempDouble)))>>>0))/(+4294967296))))))>>>0) : 0)],HEAP32[(((ptr)+(16))>>2)]=tempI64[0],HEAP32[(((ptr)+(20))>>2)]=tempI64[1]);
|
||
|
HEAPF32[(((ptr)+(24))>>2)]=x;
|
||
|
HEAPF32[(((ptr)+(28))>>2)]=y;
|
||
|
HEAPF32[(((ptr)+(32))>>2)]=dx;
|
||
|
HEAPF32[(((ptr)+(36))>>2)]=dy;
|
||
|
if (touch.force !== undefined) {
|
||
|
HEAPF32[(((ptr)+(40))>>2)]=touch.force;
|
||
|
} else { // No pressure data, send a digital 0/1 pressure.
|
||
|
HEAPF32[(((ptr)+(40))>>2)]=event.type == "touchend" ? 0 : 1;
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
case 'unload': {
|
||
|
HEAP32[((ptr)>>2)]=SDL.DOMEventToSDLEvent[event.type];
|
||
|
break;
|
||
|
}
|
||
|
case 'resize': {
|
||
|
HEAP32[((ptr)>>2)]=SDL.DOMEventToSDLEvent[event.type];
|
||
|
HEAP32[(((ptr)+(4))>>2)]=event.w;
|
||
|
HEAP32[(((ptr)+(8))>>2)]=event.h;
|
||
|
break;
|
||
|
}
|
||
|
case 'joystick_button_up': case 'joystick_button_down': {
|
||
|
var state = event.type === 'joystick_button_up' ? 0 : 1;
|
||
|
HEAP32[((ptr)>>2)]=SDL.DOMEventToSDLEvent[event.type];
|
||
|
HEAP8[(((ptr)+(4))>>0)]=event.index;
|
||
|
HEAP8[(((ptr)+(5))>>0)]=event.button;
|
||
|
HEAP8[(((ptr)+(6))>>0)]=state;
|
||
|
break;
|
||
|
}
|
||
|
case 'joystick_axis_motion': {
|
||
|
HEAP32[((ptr)>>2)]=SDL.DOMEventToSDLEvent[event.type];
|
||
|
HEAP8[(((ptr)+(4))>>0)]=event.index;
|
||
|
HEAP8[(((ptr)+(5))>>0)]=event.axis;
|
||
|
HEAP32[(((ptr)+(8))>>2)]=SDL.joystickAxisValueConversion(event.value);
|
||
|
break;
|
||
|
}
|
||
|
default: throw 'Unhandled SDL event: ' + event.type;
|
||
|
}
|
||
|
},estimateTextWidth:function (fontData, text) {
|
||
|
var h = fontData.size;
|
||
|
var fontString = h + 'px ' + fontData.name;
|
||
|
var tempCtx = SDL.ttfContext;
|
||
|
tempCtx.save();
|
||
|
tempCtx.font = fontString;
|
||
|
var ret = tempCtx.measureText(text).width | 0;
|
||
|
tempCtx.restore();
|
||
|
return ret;
|
||
|
},allocateChannels:function (num) { // called from Mix_AllocateChannels and init
|
||
|
if (SDL.numChannels && SDL.numChannels >= num && num != 0) return;
|
||
|
SDL.numChannels = num;
|
||
|
SDL.channels = [];
|
||
|
for (var i = 0; i < num; i++) {
|
||
|
SDL.channels[i] = {
|
||
|
audio: null,
|
||
|
volume: 1.0
|
||
|
};
|
||
|
}
|
||
|
},setGetVolume:function (info, volume) {
|
||
|
if (!info) return 0;
|
||
|
var ret = info.volume * 128; // MIX_MAX_VOLUME
|
||
|
if (volume != -1) {
|
||
|
info.volume = volume / 128;
|
||
|
if (info.audio) info.audio.volume = info.volume;
|
||
|
}
|
||
|
return ret;
|
||
|
},fillWebAudioBufferFromHeap:function (heapPtr, sizeSamplesPerChannel, dstAudioBuffer) {
|
||
|
// The input audio data is interleaved across the channels, i.e. [L, R, L, R, L, R, ...] and is either 8-bit or 16-bit as
|
||
|
// supported by the SDL API. The output audio wave data for Web Audio API must be in planar buffers of [-1,1]-normalized Float32 data,
|
||
|
// so perform a buffer conversion for the data.
|
||
|
var numChannels = SDL.audio.channels;
|
||
|
for(var c = 0; c < numChannels; ++c) {
|
||
|
var channelData = dstAudioBuffer['getChannelData'](c);
|
||
|
if (channelData.length != sizeSamplesPerChannel) {
|
||
|
throw 'Web Audio output buffer length mismatch! Destination size: ' + channelData.length + ' samples vs expected ' + sizeSamplesPerChannel + ' samples!';
|
||
|
}
|
||
|
if (SDL.audio.format == 0x8010 /*AUDIO_S16LSB*/) {
|
||
|
for(var j = 0; j < sizeSamplesPerChannel; ++j) {
|
||
|
channelData[j] = (HEAP16[(((heapPtr)+((j*numChannels + c)*2))>>1)]) / 0x8000;
|
||
|
}
|
||
|
} else if (SDL.audio.format == 0x0008 /*AUDIO_U8*/) {
|
||
|
for(var j = 0; j < sizeSamplesPerChannel; ++j) {
|
||
|
var v = (HEAP8[(((heapPtr)+(j*numChannels + c))>>0)]);
|
||
|
channelData[j] = ((v >= 0) ? v-128 : v+128) /128;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
},debugSurface:function (surfData) {
|
||
|
console.log('dumping surface ' + [surfData.surf, surfData.source, surfData.width, surfData.height]);
|
||
|
var image = surfData.ctx.getImageData(0, 0, surfData.width, surfData.height);
|
||
|
var data = image.data;
|
||
|
var num = Math.min(surfData.width, surfData.height);
|
||
|
for (var i = 0; i < num; i++) {
|
||
|
console.log(' diagonal ' + i + ':' + [data[i*surfData.width*4 + i*4 + 0], data[i*surfData.width*4 + i*4 + 1], data[i*surfData.width*4 + i*4 + 2], data[i*surfData.width*4 + i*4 + 3]]);
|
||
|
}
|
||
|
},joystickEventState:1,lastJoystickState:{},joystickNamePool:{},recordJoystickState:function (joystick, state) {
|
||
|
// Standardize button state.
|
||
|
var buttons = new Array(state.buttons.length);
|
||
|
for (var i = 0; i < state.buttons.length; i++) {
|
||
|
buttons[i] = SDL.getJoystickButtonState(state.buttons[i]);
|
||
|
}
|
||
|
|
||
|
SDL.lastJoystickState[joystick] = {
|
||
|
buttons: buttons,
|
||
|
axes: state.axes.slice(0),
|
||
|
timestamp: state.timestamp,
|
||
|
index: state.index,
|
||
|
id: state.id
|
||
|
};
|
||
|
},getJoystickButtonState:function (button) {
|
||
|
if (typeof button === 'object') {
|
||
|
// Current gamepad API editor's draft (Firefox Nightly)
|
||
|
// https://dvcs.w3.org/hg/gamepad/raw-file/default/gamepad.html#idl-def-GamepadButton
|
||
|
return button.pressed;
|
||
|
} else {
|
||
|
// Current gamepad API working draft (Firefox / Chrome Stable)
|
||
|
// http://www.w3.org/TR/2012/WD-gamepad-20120529/#gamepad-interface
|
||
|
return button > 0;
|
||
|
}
|
||
|
},queryJoysticks:function () {
|
||
|
for (var joystick in SDL.lastJoystickState) {
|
||
|
var state = SDL.getGamepad(joystick - 1);
|
||
|
var prevState = SDL.lastJoystickState[joystick];
|
||
|
// Check only if the timestamp has differed.
|
||
|
// NOTE: Timestamp is not available in Firefox.
|
||
|
if (typeof state.timestamp !== 'number' || state.timestamp !== prevState.timestamp) {
|
||
|
var i;
|
||
|
for (i = 0; i < state.buttons.length; i++) {
|
||
|
var buttonState = SDL.getJoystickButtonState(state.buttons[i]);
|
||
|
// NOTE: The previous state already has a boolean representation of
|
||
|
// its button, so no need to standardize its button state here.
|
||
|
if (buttonState !== prevState.buttons[i]) {
|
||
|
// Insert button-press event.
|
||
|
SDL.events.push({
|
||
|
type: buttonState ? 'joystick_button_down' : 'joystick_button_up',
|
||
|
joystick: joystick,
|
||
|
index: joystick - 1,
|
||
|
button: i
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
for (i = 0; i < state.axes.length; i++) {
|
||
|
if (state.axes[i] !== prevState.axes[i]) {
|
||
|
// Insert axes-change event.
|
||
|
SDL.events.push({
|
||
|
type: 'joystick_axis_motion',
|
||
|
joystick: joystick,
|
||
|
index: joystick - 1,
|
||
|
axis: i,
|
||
|
value: state.axes[i]
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
SDL.recordJoystickState(joystick, state);
|
||
|
}
|
||
|
}
|
||
|
},joystickAxisValueConversion:function (value) {
|
||
|
// Ensures that 0 is 0, 1 is 32767, and -1 is 32768.
|
||
|
return Math.ceil(((value+1) * 32767.5) - 32768);
|
||
|
},getGamepads:function () {
|
||
|
var fcn = navigator.getGamepads || navigator.webkitGamepads || navigator.mozGamepads || navigator.gamepads || navigator.webkitGetGamepads;
|
||
|
if (fcn !== undefined) {
|
||
|
// The function must be applied on the navigator object.
|
||
|
return fcn.apply(navigator);
|
||
|
} else {
|
||
|
return [];
|
||
|
}
|
||
|
},getGamepad:function (deviceIndex) {
|
||
|
var gamepads = SDL.getGamepads();
|
||
|
if (gamepads.length > deviceIndex && deviceIndex >= 0) {
|
||
|
return gamepads[deviceIndex];
|
||
|
}
|
||
|
return null;
|
||
|
}};function _SDL_EventState() {}
|
||
|
|
||
|
|
||
|
function _close(fildes) {
|
||
|
// int close(int fildes);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/close.html
|
||
|
var stream = FS.getStream(fildes);
|
||
|
if (!stream) {
|
||
|
___setErrNo(ERRNO_CODES.EBADF);
|
||
|
return -1;
|
||
|
}
|
||
|
try {
|
||
|
FS.close(stream);
|
||
|
return 0;
|
||
|
} catch (e) {
|
||
|
FS.handleFSError(e);
|
||
|
return -1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function _fsync(fildes) {
|
||
|
// int fsync(int fildes);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/fsync.html
|
||
|
var stream = FS.getStream(fildes);
|
||
|
if (stream) {
|
||
|
// We write directly to the file system, so there's nothing to do here.
|
||
|
return 0;
|
||
|
} else {
|
||
|
___setErrNo(ERRNO_CODES.EBADF);
|
||
|
return -1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function _fileno(stream) {
|
||
|
// int fileno(FILE *stream);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/fileno.html
|
||
|
stream = FS.getStreamFromPtr(stream);
|
||
|
if (!stream) return -1;
|
||
|
return stream.fd;
|
||
|
}function _fclose(stream) {
|
||
|
// int fclose(FILE *stream);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/fclose.html
|
||
|
var fd = _fileno(stream);
|
||
|
_fsync(fd);
|
||
|
return _close(fd);
|
||
|
}
|
||
|
|
||
|
function _SDL_CreateRGBSurfaceFrom(pixels, width, height, depth, pitch, rmask, gmask, bmask, amask) {
|
||
|
// TODO: Take into account depth and pitch parameters.
|
||
|
|
||
|
var surface = SDL.makeSurface(width, height, 0, false, 'CreateRGBSurfaceFrom', rmask, gmask, bmask, amask);
|
||
|
|
||
|
var surfaceData = SDL.surfaces[surface];
|
||
|
var surfaceImageData = surfaceData.ctx.getImageData(0, 0, width, height);
|
||
|
var surfacePixelData = surfaceImageData.data;
|
||
|
|
||
|
// Fill pixel data to created surface.
|
||
|
// Supports SDL_PIXELFORMAT_RGBA8888 and SDL_PIXELFORMAT_RGB888
|
||
|
var channels = amask ? 4 : 3; // RGBA8888 or RGB888
|
||
|
for (var pixelOffset = 0; pixelOffset < width*height; pixelOffset++) {
|
||
|
|
||
|
surfacePixelData[pixelOffset*4] = HEAPU8[(((pixels)+(pixelOffset*channels))>>0)]; // R
|
||
|
surfacePixelData[pixelOffset*4+1] = HEAPU8[(((pixels)+(pixelOffset*channels+1))>>0)]; // G
|
||
|
surfacePixelData[pixelOffset*4+2] = HEAPU8[(((pixels)+(pixelOffset*channels+2))>>0)]; // B
|
||
|
surfacePixelData[pixelOffset*4+3] = amask ? HEAPU8[(((pixels)+(pixelOffset*channels+3))>>0)] : 0xff; // A
|
||
|
};
|
||
|
|
||
|
surfaceData.ctx.putImageData(surfaceImageData, 0, 0);
|
||
|
|
||
|
return surface;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
function _isspace(chr) {
|
||
|
return (chr == 32) || (chr >= 9 && chr <= 13);
|
||
|
}function __parseInt(str, endptr, base, min, max, bits, unsign) {
|
||
|
// Skip space.
|
||
|
while (_isspace(HEAP8[((str)>>0)])) str++;
|
||
|
|
||
|
// Check for a plus/minus sign.
|
||
|
var multiplier = 1;
|
||
|
if (HEAP8[((str)>>0)] == 45) {
|
||
|
multiplier = -1;
|
||
|
str++;
|
||
|
} else if (HEAP8[((str)>>0)] == 43) {
|
||
|
str++;
|
||
|
}
|
||
|
|
||
|
// Find base.
|
||
|
var finalBase = base;
|
||
|
if (!finalBase) {
|
||
|
if (HEAP8[((str)>>0)] == 48) {
|
||
|
if (HEAP8[((str+1)>>0)] == 120 ||
|
||
|
HEAP8[((str+1)>>0)] == 88) {
|
||
|
finalBase = 16;
|
||
|
str += 2;
|
||
|
} else {
|
||
|
finalBase = 8;
|
||
|
str++;
|
||
|
}
|
||
|
}
|
||
|
} else if (finalBase==16) {
|
||
|
if (HEAP8[((str)>>0)] == 48) {
|
||
|
if (HEAP8[((str+1)>>0)] == 120 ||
|
||
|
HEAP8[((str+1)>>0)] == 88) {
|
||
|
str += 2;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if (!finalBase) finalBase = 10;
|
||
|
|
||
|
// Get digits.
|
||
|
var chr;
|
||
|
var ret = 0;
|
||
|
while ((chr = HEAP8[((str)>>0)]) != 0) {
|
||
|
var digit = parseInt(String.fromCharCode(chr), finalBase);
|
||
|
if (isNaN(digit)) {
|
||
|
break;
|
||
|
} else {
|
||
|
ret = ret * finalBase + digit;
|
||
|
str++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Apply sign.
|
||
|
ret *= multiplier;
|
||
|
|
||
|
// Set end pointer.
|
||
|
if (endptr) {
|
||
|
HEAP32[((endptr)>>2)]=str;
|
||
|
}
|
||
|
|
||
|
// Unsign if needed.
|
||
|
if (unsign) {
|
||
|
if (Math.abs(ret) > max) {
|
||
|
ret = max;
|
||
|
___setErrNo(ERRNO_CODES.ERANGE);
|
||
|
} else {
|
||
|
ret = unSign(ret, bits);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Validate range.
|
||
|
if (ret > max || ret < min) {
|
||
|
ret = ret > max ? max : min;
|
||
|
___setErrNo(ERRNO_CODES.ERANGE);
|
||
|
}
|
||
|
|
||
|
if (bits == 64) {
|
||
|
return ((asm["setTempRet0"]((tempDouble=ret,(+(Math_abs(tempDouble))) >= (+1) ? (tempDouble > (+0) ? ((Math_min((+(Math_floor((tempDouble)/(+4294967296)))), (+4294967295)))|0)>>>0 : (~~((+(Math_ceil((tempDouble - +(((~~(tempDouble)))>>>0))/(+4294967296))))))>>>0) : 0)),ret>>>0)|0);
|
||
|
}
|
||
|
|
||
|
return ret;
|
||
|
}function _strtoul(str, endptr, base) {
|
||
|
return __parseInt(str, endptr, base, 0, 4294967295, 32, true); // ULONG_MAX.
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
function _mkport() { throw 'TODO' }var SOCKFS={mount:function (mount) {
|
||
|
return FS.createNode(null, '/', 16384 | 511 /* 0777 */, 0);
|
||
|
},createSocket:function (family, type, protocol) {
|
||
|
var streaming = type == 1;
|
||
|
if (protocol) {
|
||
|
assert(streaming == (protocol == 6)); // if SOCK_STREAM, must be tcp
|
||
|
}
|
||
|
|
||
|
// create our internal socket structure
|
||
|
var sock = {
|
||
|
family: family,
|
||
|
type: type,
|
||
|
protocol: protocol,
|
||
|
server: null,
|
||
|
peers: {},
|
||
|
pending: [],
|
||
|
recv_queue: [],
|
||
|
sock_ops: SOCKFS.websocket_sock_ops
|
||
|
};
|
||
|
|
||
|
// create the filesystem node to store the socket structure
|
||
|
var name = SOCKFS.nextname();
|
||
|
var node = FS.createNode(SOCKFS.root, name, 49152, 0);
|
||
|
node.sock = sock;
|
||
|
|
||
|
// and the wrapping stream that enables library functions such
|
||
|
// as read and write to indirectly interact with the socket
|
||
|
var stream = FS.createStream({
|
||
|
path: name,
|
||
|
node: node,
|
||
|
flags: FS.modeStringToFlags('r+'),
|
||
|
seekable: false,
|
||
|
stream_ops: SOCKFS.stream_ops
|
||
|
});
|
||
|
|
||
|
// map the new stream to the socket structure (sockets have a 1:1
|
||
|
// relationship with a stream)
|
||
|
sock.stream = stream;
|
||
|
|
||
|
return sock;
|
||
|
},getSocket:function (fd) {
|
||
|
var stream = FS.getStream(fd);
|
||
|
if (!stream || !FS.isSocket(stream.node.mode)) {
|
||
|
return null;
|
||
|
}
|
||
|
return stream.node.sock;
|
||
|
},stream_ops:{poll:function (stream) {
|
||
|
var sock = stream.node.sock;
|
||
|
return sock.sock_ops.poll(sock);
|
||
|
},ioctl:function (stream, request, varargs) {
|
||
|
var sock = stream.node.sock;
|
||
|
return sock.sock_ops.ioctl(sock, request, varargs);
|
||
|
},read:function (stream, buffer, offset, length, position /* ignored */) {
|
||
|
var sock = stream.node.sock;
|
||
|
var msg = sock.sock_ops.recvmsg(sock, length);
|
||
|
if (!msg) {
|
||
|
// socket is closed
|
||
|
return 0;
|
||
|
}
|
||
|
buffer.set(msg.buffer, offset);
|
||
|
return msg.buffer.length;
|
||
|
},write:function (stream, buffer, offset, length, position /* ignored */) {
|
||
|
var sock = stream.node.sock;
|
||
|
return sock.sock_ops.sendmsg(sock, buffer, offset, length);
|
||
|
},close:function (stream) {
|
||
|
var sock = stream.node.sock;
|
||
|
sock.sock_ops.close(sock);
|
||
|
}},nextname:function () {
|
||
|
if (!SOCKFS.nextname.current) {
|
||
|
SOCKFS.nextname.current = 0;
|
||
|
}
|
||
|
return 'socket[' + (SOCKFS.nextname.current++) + ']';
|
||
|
},websocket_sock_ops:{createPeer:function (sock, addr, port) {
|
||
|
var ws;
|
||
|
|
||
|
if (typeof addr === 'object') {
|
||
|
ws = addr;
|
||
|
addr = null;
|
||
|
port = null;
|
||
|
}
|
||
|
|
||
|
if (ws) {
|
||
|
// for sockets that've already connected (e.g. we're the server)
|
||
|
// we can inspect the _socket property for the address
|
||
|
if (ws._socket) {
|
||
|
addr = ws._socket.remoteAddress;
|
||
|
port = ws._socket.remotePort;
|
||
|
}
|
||
|
// if we're just now initializing a connection to the remote,
|
||
|
// inspect the url property
|
||
|
else {
|
||
|
var result = /ws[s]?:\/\/([^:]+):(\d+)/.exec(ws.url);
|
||
|
if (!result) {
|
||
|
throw new Error('WebSocket URL must be in the format ws(s)://address:port');
|
||
|
}
|
||
|
addr = result[1];
|
||
|
port = parseInt(result[2], 10);
|
||
|
}
|
||
|
} else {
|
||
|
// create the actual websocket object and connect
|
||
|
try {
|
||
|
// runtimeConfig gets set to true if WebSocket runtime configuration is available.
|
||
|
var runtimeConfig = (Module['websocket'] && ('object' === typeof Module['websocket']));
|
||
|
|
||
|
// The default value is 'ws://' the replace is needed because the compiler replaces "//" comments with '#'
|
||
|
// comments without checking context, so we'd end up with ws:#, the replace swaps the "#" for "//" again.
|
||
|
var url = 'ws:#'.replace('#', '//');
|
||
|
|
||
|
if (runtimeConfig) {
|
||
|
if ('string' === typeof Module['websocket']['url']) {
|
||
|
url = Module['websocket']['url']; // Fetch runtime WebSocket URL config.
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (url === 'ws://' || url === 'wss://') { // Is the supplied URL config just a prefix, if so complete it.
|
||
|
url = url + addr + ':' + port;
|
||
|
}
|
||
|
|
||
|
// Make the WebSocket subprotocol (Sec-WebSocket-Protocol) default to binary if no configuration is set.
|
||
|
var subProtocols = 'binary'; // The default value is 'binary'
|
||
|
|
||
|
if (runtimeConfig) {
|
||
|
if ('string' === typeof Module['websocket']['subprotocol']) {
|
||
|
subProtocols = Module['websocket']['subprotocol']; // Fetch runtime WebSocket subprotocol config.
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// The regex trims the string (removes spaces at the beginning and end, then splits the string by
|
||
|
// <any space>,<any space> into an Array. Whitespace removal is important for Websockify and ws.
|
||
|
subProtocols = subProtocols.replace(/^ +| +$/g,"").split(/ *, */);
|
||
|
|
||
|
// The node ws library API for specifying optional subprotocol is slightly different than the browser's.
|
||
|
var opts = ENVIRONMENT_IS_NODE ? {'protocol': subProtocols.toString()} : subProtocols;
|
||
|
|
||
|
// If node we use the ws library.
|
||
|
var WebSocket = ENVIRONMENT_IS_NODE ? require('ws') : window['WebSocket'];
|
||
|
ws = new WebSocket(url, opts);
|
||
|
ws.binaryType = 'arraybuffer';
|
||
|
} catch (e) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EHOSTUNREACH);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
var peer = {
|
||
|
addr: addr,
|
||
|
port: port,
|
||
|
socket: ws,
|
||
|
dgram_send_queue: []
|
||
|
};
|
||
|
|
||
|
SOCKFS.websocket_sock_ops.addPeer(sock, peer);
|
||
|
SOCKFS.websocket_sock_ops.handlePeerEvents(sock, peer);
|
||
|
|
||
|
// if this is a bound dgram socket, send the port number first to allow
|
||
|
// us to override the ephemeral port reported to us by remotePort on the
|
||
|
// remote end.
|
||
|
if (sock.type === 2 && typeof sock.sport !== 'undefined') {
|
||
|
peer.dgram_send_queue.push(new Uint8Array([
|
||
|
255, 255, 255, 255,
|
||
|
'p'.charCodeAt(0), 'o'.charCodeAt(0), 'r'.charCodeAt(0), 't'.charCodeAt(0),
|
||
|
((sock.sport & 0xff00) >> 8) , (sock.sport & 0xff)
|
||
|
]));
|
||
|
}
|
||
|
|
||
|
return peer;
|
||
|
},getPeer:function (sock, addr, port) {
|
||
|
return sock.peers[addr + ':' + port];
|
||
|
},addPeer:function (sock, peer) {
|
||
|
sock.peers[peer.addr + ':' + peer.port] = peer;
|
||
|
},removePeer:function (sock, peer) {
|
||
|
delete sock.peers[peer.addr + ':' + peer.port];
|
||
|
},handlePeerEvents:function (sock, peer) {
|
||
|
var first = true;
|
||
|
|
||
|
var handleOpen = function () {
|
||
|
try {
|
||
|
var queued = peer.dgram_send_queue.shift();
|
||
|
while (queued) {
|
||
|
peer.socket.send(queued);
|
||
|
queued = peer.dgram_send_queue.shift();
|
||
|
}
|
||
|
} catch (e) {
|
||
|
// not much we can do here in the way of proper error handling as we've already
|
||
|
// lied and said this data was sent. shut it down.
|
||
|
peer.socket.close();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
function handleMessage(data) {
|
||
|
assert(typeof data !== 'string' && data.byteLength !== undefined); // must receive an ArrayBuffer
|
||
|
data = new Uint8Array(data); // make a typed array view on the array buffer
|
||
|
|
||
|
|
||
|
// if this is the port message, override the peer's port with it
|
||
|
var wasfirst = first;
|
||
|
first = false;
|
||
|
if (wasfirst &&
|
||
|
data.length === 10 &&
|
||
|
data[0] === 255 && data[1] === 255 && data[2] === 255 && data[3] === 255 &&
|
||
|
data[4] === 'p'.charCodeAt(0) && data[5] === 'o'.charCodeAt(0) && data[6] === 'r'.charCodeAt(0) && data[7] === 't'.charCodeAt(0)) {
|
||
|
// update the peer's port and it's key in the peer map
|
||
|
var newport = ((data[8] << 8) | data[9]);
|
||
|
SOCKFS.websocket_sock_ops.removePeer(sock, peer);
|
||
|
peer.port = newport;
|
||
|
SOCKFS.websocket_sock_ops.addPeer(sock, peer);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
sock.recv_queue.push({ addr: peer.addr, port: peer.port, data: data });
|
||
|
};
|
||
|
|
||
|
if (ENVIRONMENT_IS_NODE) {
|
||
|
peer.socket.on('open', handleOpen);
|
||
|
peer.socket.on('message', function(data, flags) {
|
||
|
if (!flags.binary) {
|
||
|
return;
|
||
|
}
|
||
|
handleMessage((new Uint8Array(data)).buffer); // copy from node Buffer -> ArrayBuffer
|
||
|
});
|
||
|
peer.socket.on('error', function() {
|
||
|
// don't throw
|
||
|
});
|
||
|
} else {
|
||
|
peer.socket.onopen = handleOpen;
|
||
|
peer.socket.onmessage = function peer_socket_onmessage(event) {
|
||
|
handleMessage(event.data);
|
||
|
};
|
||
|
}
|
||
|
},poll:function (sock) {
|
||
|
if (sock.type === 1 && sock.server) {
|
||
|
// listen sockets should only say they're available for reading
|
||
|
// if there are pending clients.
|
||
|
return sock.pending.length ? (64 | 1) : 0;
|
||
|
}
|
||
|
|
||
|
var mask = 0;
|
||
|
var dest = sock.type === 1 ? // we only care about the socket state for connection-based sockets
|
||
|
SOCKFS.websocket_sock_ops.getPeer(sock, sock.daddr, sock.dport) :
|
||
|
null;
|
||
|
|
||
|
if (sock.recv_queue.length ||
|
||
|
!dest || // connection-less sockets are always ready to read
|
||
|
(dest && dest.socket.readyState === dest.socket.CLOSING) ||
|
||
|
(dest && dest.socket.readyState === dest.socket.CLOSED)) { // let recv return 0 once closed
|
||
|
mask |= (64 | 1);
|
||
|
}
|
||
|
|
||
|
if (!dest || // connection-less sockets are always ready to write
|
||
|
(dest && dest.socket.readyState === dest.socket.OPEN)) {
|
||
|
mask |= 4;
|
||
|
}
|
||
|
|
||
|
if ((dest && dest.socket.readyState === dest.socket.CLOSING) ||
|
||
|
(dest && dest.socket.readyState === dest.socket.CLOSED)) {
|
||
|
mask |= 16;
|
||
|
}
|
||
|
|
||
|
return mask;
|
||
|
},ioctl:function (sock, request, arg) {
|
||
|
switch (request) {
|
||
|
case 21531:
|
||
|
var bytes = 0;
|
||
|
if (sock.recv_queue.length) {
|
||
|
bytes = sock.recv_queue[0].data.length;
|
||
|
}
|
||
|
HEAP32[((arg)>>2)]=bytes;
|
||
|
return 0;
|
||
|
default:
|
||
|
return ERRNO_CODES.EINVAL;
|
||
|
}
|
||
|
},close:function (sock) {
|
||
|
// if we've spawned a listen server, close it
|
||
|
if (sock.server) {
|
||
|
try {
|
||
|
sock.server.close();
|
||
|
} catch (e) {
|
||
|
}
|
||
|
sock.server = null;
|
||
|
}
|
||
|
// close any peer connections
|
||
|
var peers = Object.keys(sock.peers);
|
||
|
for (var i = 0; i < peers.length; i++) {
|
||
|
var peer = sock.peers[peers[i]];
|
||
|
try {
|
||
|
peer.socket.close();
|
||
|
} catch (e) {
|
||
|
}
|
||
|
SOCKFS.websocket_sock_ops.removePeer(sock, peer);
|
||
|
}
|
||
|
return 0;
|
||
|
},bind:function (sock, addr, port) {
|
||
|
if (typeof sock.saddr !== 'undefined' || typeof sock.sport !== 'undefined') {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EINVAL); // already bound
|
||
|
}
|
||
|
sock.saddr = addr;
|
||
|
sock.sport = port || _mkport();
|
||
|
// in order to emulate dgram sockets, we need to launch a listen server when
|
||
|
// binding on a connection-less socket
|
||
|
// note: this is only required on the server side
|
||
|
if (sock.type === 2) {
|
||
|
// close the existing server if it exists
|
||
|
if (sock.server) {
|
||
|
sock.server.close();
|
||
|
sock.server = null;
|
||
|
}
|
||
|
// swallow error operation not supported error that occurs when binding in the
|
||
|
// browser where this isn't supported
|
||
|
try {
|
||
|
sock.sock_ops.listen(sock, 0);
|
||
|
} catch (e) {
|
||
|
if (!(e instanceof FS.ErrnoError)) throw e;
|
||
|
if (e.errno !== ERRNO_CODES.EOPNOTSUPP) throw e;
|
||
|
}
|
||
|
}
|
||
|
},connect:function (sock, addr, port) {
|
||
|
if (sock.server) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODS.EOPNOTSUPP);
|
||
|
}
|
||
|
|
||
|
// TODO autobind
|
||
|
// if (!sock.addr && sock.type == 2) {
|
||
|
// }
|
||
|
|
||
|
// early out if we're already connected / in the middle of connecting
|
||
|
if (typeof sock.daddr !== 'undefined' && typeof sock.dport !== 'undefined') {
|
||
|
var dest = SOCKFS.websocket_sock_ops.getPeer(sock, sock.daddr, sock.dport);
|
||
|
if (dest) {
|
||
|
if (dest.socket.readyState === dest.socket.CONNECTING) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EALREADY);
|
||
|
} else {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EISCONN);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// add the socket to our peer list and set our
|
||
|
// destination address / port to match
|
||
|
var peer = SOCKFS.websocket_sock_ops.createPeer(sock, addr, port);
|
||
|
sock.daddr = peer.addr;
|
||
|
sock.dport = peer.port;
|
||
|
|
||
|
// always "fail" in non-blocking mode
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EINPROGRESS);
|
||
|
},listen:function (sock, backlog) {
|
||
|
if (!ENVIRONMENT_IS_NODE) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EOPNOTSUPP);
|
||
|
}
|
||
|
if (sock.server) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EINVAL); // already listening
|
||
|
}
|
||
|
var WebSocketServer = require('ws').Server;
|
||
|
var host = sock.saddr;
|
||
|
sock.server = new WebSocketServer({
|
||
|
host: host,
|
||
|
port: sock.sport
|
||
|
// TODO support backlog
|
||
|
});
|
||
|
|
||
|
sock.server.on('connection', function(ws) {
|
||
|
if (sock.type === 1) {
|
||
|
var newsock = SOCKFS.createSocket(sock.family, sock.type, sock.protocol);
|
||
|
|
||
|
// create a peer on the new socket
|
||
|
var peer = SOCKFS.websocket_sock_ops.createPeer(newsock, ws);
|
||
|
newsock.daddr = peer.addr;
|
||
|
newsock.dport = peer.port;
|
||
|
|
||
|
// push to queue for accept to pick up
|
||
|
sock.pending.push(newsock);
|
||
|
} else {
|
||
|
// create a peer on the listen socket so calling sendto
|
||
|
// with the listen socket and an address will resolve
|
||
|
// to the correct client
|
||
|
SOCKFS.websocket_sock_ops.createPeer(sock, ws);
|
||
|
}
|
||
|
});
|
||
|
sock.server.on('closed', function() {
|
||
|
sock.server = null;
|
||
|
});
|
||
|
sock.server.on('error', function() {
|
||
|
// don't throw
|
||
|
});
|
||
|
},accept:function (listensock) {
|
||
|
if (!listensock.server) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
||
|
}
|
||
|
var newsock = listensock.pending.shift();
|
||
|
newsock.stream.flags = listensock.stream.flags;
|
||
|
return newsock;
|
||
|
},getname:function (sock, peer) {
|
||
|
var addr, port;
|
||
|
if (peer) {
|
||
|
if (sock.daddr === undefined || sock.dport === undefined) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ENOTCONN);
|
||
|
}
|
||
|
addr = sock.daddr;
|
||
|
port = sock.dport;
|
||
|
} else {
|
||
|
// TODO saddr and sport will be set for bind()'d UDP sockets, but what
|
||
|
// should we be returning for TCP sockets that've been connect()'d?
|
||
|
addr = sock.saddr || 0;
|
||
|
port = sock.sport || 0;
|
||
|
}
|
||
|
return { addr: addr, port: port };
|
||
|
},sendmsg:function (sock, buffer, offset, length, addr, port) {
|
||
|
if (sock.type === 2) {
|
||
|
// connection-less sockets will honor the message address,
|
||
|
// and otherwise fall back to the bound destination address
|
||
|
if (addr === undefined || port === undefined) {
|
||
|
addr = sock.daddr;
|
||
|
port = sock.dport;
|
||
|
}
|
||
|
// if there was no address to fall back to, error out
|
||
|
if (addr === undefined || port === undefined) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EDESTADDRREQ);
|
||
|
}
|
||
|
} else {
|
||
|
// connection-based sockets will only use the bound
|
||
|
addr = sock.daddr;
|
||
|
port = sock.dport;
|
||
|
}
|
||
|
|
||
|
// find the peer for the destination address
|
||
|
var dest = SOCKFS.websocket_sock_ops.getPeer(sock, addr, port);
|
||
|
|
||
|
// early out if not connected with a connection-based socket
|
||
|
if (sock.type === 1) {
|
||
|
if (!dest || dest.socket.readyState === dest.socket.CLOSING || dest.socket.readyState === dest.socket.CLOSED) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ENOTCONN);
|
||
|
} else if (dest.socket.readyState === dest.socket.CONNECTING) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EAGAIN);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// create a copy of the incoming data to send, as the WebSocket API
|
||
|
// doesn't work entirely with an ArrayBufferView, it'll just send
|
||
|
// the entire underlying buffer
|
||
|
var data;
|
||
|
if (buffer instanceof Array || buffer instanceof ArrayBuffer) {
|
||
|
data = buffer.slice(offset, offset + length);
|
||
|
} else { // ArrayBufferView
|
||
|
data = buffer.buffer.slice(buffer.byteOffset + offset, buffer.byteOffset + offset + length);
|
||
|
}
|
||
|
|
||
|
// if we're emulating a connection-less dgram socket and don't have
|
||
|
// a cached connection, queue the buffer to send upon connect and
|
||
|
// lie, saying the data was sent now.
|
||
|
if (sock.type === 2) {
|
||
|
if (!dest || dest.socket.readyState !== dest.socket.OPEN) {
|
||
|
// if we're not connected, open a new connection
|
||
|
if (!dest || dest.socket.readyState === dest.socket.CLOSING || dest.socket.readyState === dest.socket.CLOSED) {
|
||
|
dest = SOCKFS.websocket_sock_ops.createPeer(sock, addr, port);
|
||
|
}
|
||
|
dest.dgram_send_queue.push(data);
|
||
|
return length;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
// send the actual data
|
||
|
dest.socket.send(data);
|
||
|
return length;
|
||
|
} catch (e) {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
|
||
|
}
|
||
|
},recvmsg:function (sock, length) {
|
||
|
// http://pubs.opengroup.org/onlinepubs/7908799/xns/recvmsg.html
|
||
|
if (sock.type === 1 && sock.server) {
|
||
|
// tcp servers should not be recv()'ing on the listen socket
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ENOTCONN);
|
||
|
}
|
||
|
|
||
|
var queued = sock.recv_queue.shift();
|
||
|
if (!queued) {
|
||
|
if (sock.type === 1) {
|
||
|
var dest = SOCKFS.websocket_sock_ops.getPeer(sock, sock.daddr, sock.dport);
|
||
|
|
||
|
if (!dest) {
|
||
|
// if we have a destination address but are not connected, error out
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.ENOTCONN);
|
||
|
}
|
||
|
else if (dest.socket.readyState === dest.socket.CLOSING || dest.socket.readyState === dest.socket.CLOSED) {
|
||
|
// return null if the socket has closed
|
||
|
return null;
|
||
|
}
|
||
|
else {
|
||
|
// else, our socket is in a valid state but truly has nothing available
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EAGAIN);
|
||
|
}
|
||
|
} else {
|
||
|
throw new FS.ErrnoError(ERRNO_CODES.EAGAIN);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// queued.data will be an ArrayBuffer if it's unadulterated, but if it's
|
||
|
// requeued TCP data it'll be an ArrayBufferView
|
||
|
var queuedLength = queued.data.byteLength || queued.data.length;
|
||
|
var queuedOffset = queued.data.byteOffset || 0;
|
||
|
var queuedBuffer = queued.data.buffer || queued.data;
|
||
|
var bytesRead = Math.min(length, queuedLength);
|
||
|
var res = {
|
||
|
buffer: new Uint8Array(queuedBuffer, queuedOffset, bytesRead),
|
||
|
addr: queued.addr,
|
||
|
port: queued.port
|
||
|
};
|
||
|
|
||
|
|
||
|
// push back any unread data for TCP connections
|
||
|
if (sock.type === 1 && bytesRead < queuedLength) {
|
||
|
var bytesRemaining = queuedLength - bytesRead;
|
||
|
queued.data = new Uint8Array(queuedBuffer, queuedOffset + bytesRead, bytesRemaining);
|
||
|
sock.recv_queue.unshift(queued);
|
||
|
}
|
||
|
|
||
|
return res;
|
||
|
}}};function _send(fd, buf, len, flags) {
|
||
|
var sock = SOCKFS.getSocket(fd);
|
||
|
if (!sock) {
|
||
|
___setErrNo(ERRNO_CODES.EBADF);
|
||
|
return -1;
|
||
|
}
|
||
|
// TODO honor flags
|
||
|
return _write(fd, buf, len);
|
||
|
}
|
||
|
|
||
|
function _pwrite(fildes, buf, nbyte, offset) {
|
||
|
// ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/write.html
|
||
|
var stream = FS.getStream(fildes);
|
||
|
if (!stream) {
|
||
|
___setErrNo(ERRNO_CODES.EBADF);
|
||
|
return -1;
|
||
|
}
|
||
|
try {
|
||
|
var slab = HEAP8;
|
||
|
return FS.write(stream, slab, buf, nbyte, offset);
|
||
|
} catch (e) {
|
||
|
FS.handleFSError(e);
|
||
|
return -1;
|
||
|
}
|
||
|
}function _write(fildes, buf, nbyte) {
|
||
|
// ssize_t write(int fildes, const void *buf, size_t nbyte);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/write.html
|
||
|
var stream = FS.getStream(fildes);
|
||
|
if (!stream) {
|
||
|
___setErrNo(ERRNO_CODES.EBADF);
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
|
||
|
try {
|
||
|
var slab = HEAP8;
|
||
|
return FS.write(stream, slab, buf, nbyte);
|
||
|
} catch (e) {
|
||
|
FS.handleFSError(e);
|
||
|
return -1;
|
||
|
}
|
||
|
}function _fwrite(ptr, size, nitems, stream) {
|
||
|
// size_t fwrite(const void *restrict ptr, size_t size, size_t nitems, FILE *restrict stream);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/fwrite.html
|
||
|
var bytesToWrite = nitems * size;
|
||
|
if (bytesToWrite == 0) return 0;
|
||
|
var fd = _fileno(stream);
|
||
|
var bytesWritten = _write(fd, ptr, bytesToWrite);
|
||
|
if (bytesWritten == -1) {
|
||
|
var streamObj = FS.getStreamFromPtr(stream);
|
||
|
if (streamObj) streamObj.error = true;
|
||
|
return 0;
|
||
|
} else {
|
||
|
return Math.floor(bytesWritten / size);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
Module["_strlen"] = _strlen;
|
||
|
|
||
|
function __reallyNegative(x) {
|
||
|
return x < 0 || (x === 0 && (1/x) === -Infinity);
|
||
|
}function __formatString(format, varargs) {
|
||
|
var textIndex = format;
|
||
|
var argIndex = 0;
|
||
|
function getNextArg(type) {
|
||
|
// NOTE: Explicitly ignoring type safety. Otherwise this fails:
|
||
|
// int x = 4; printf("%c\n", (char)x);
|
||
|
var ret;
|
||
|
if (type === 'double') {
|
||
|
ret = (HEAP32[((tempDoublePtr)>>2)]=HEAP32[(((varargs)+(argIndex))>>2)],HEAP32[(((tempDoublePtr)+(4))>>2)]=HEAP32[(((varargs)+((argIndex)+(4)))>>2)],(+(HEAPF64[(tempDoublePtr)>>3])));
|
||
|
} else if (type == 'i64') {
|
||
|
ret = [HEAP32[(((varargs)+(argIndex))>>2)],
|
||
|
HEAP32[(((varargs)+(argIndex+4))>>2)]];
|
||
|
|
||
|
} else {
|
||
|
type = 'i32'; // varargs are always i32, i64, or double
|
||
|
ret = HEAP32[(((varargs)+(argIndex))>>2)];
|
||
|
}
|
||
|
argIndex += Runtime.getNativeFieldSize(type);
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
var ret = [];
|
||
|
var curr, next, currArg;
|
||
|
while(1) {
|
||
|
var startTextIndex = textIndex;
|
||
|
curr = HEAP8[((textIndex)>>0)];
|
||
|
if (curr === 0) break;
|
||
|
next = HEAP8[((textIndex+1)>>0)];
|
||
|
if (curr == 37) {
|
||
|
// Handle flags.
|
||
|
var flagAlwaysSigned = false;
|
||
|
var flagLeftAlign = false;
|
||
|
var flagAlternative = false;
|
||
|
var flagZeroPad = false;
|
||
|
var flagPadSign = false;
|
||
|
flagsLoop: while (1) {
|
||
|
switch (next) {
|
||
|
case 43:
|
||
|
flagAlwaysSigned = true;
|
||
|
break;
|
||
|
case 45:
|
||
|
flagLeftAlign = true;
|
||
|
break;
|
||
|
case 35:
|
||
|
flagAlternative = true;
|
||
|
break;
|
||
|
case 48:
|
||
|
if (flagZeroPad) {
|
||
|
break flagsLoop;
|
||
|
} else {
|
||
|
flagZeroPad = true;
|
||
|
break;
|
||
|
}
|
||
|
case 32:
|
||
|
flagPadSign = true;
|
||
|
break;
|
||
|
default:
|
||
|
break flagsLoop;
|
||
|
}
|
||
|
textIndex++;
|
||
|
next = HEAP8[((textIndex+1)>>0)];
|
||
|
}
|
||
|
|
||
|
// Handle width.
|
||
|
var width = 0;
|
||
|
if (next == 42) {
|
||
|
width = getNextArg('i32');
|
||
|
textIndex++;
|
||
|
next = HEAP8[((textIndex+1)>>0)];
|
||
|
} else {
|
||
|
while (next >= 48 && next <= 57) {
|
||
|
width = width * 10 + (next - 48);
|
||
|
textIndex++;
|
||
|
next = HEAP8[((textIndex+1)>>0)];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Handle precision.
|
||
|
var precisionSet = false, precision = -1;
|
||
|
if (next == 46) {
|
||
|
precision = 0;
|
||
|
precisionSet = true;
|
||
|
textIndex++;
|
||
|
next = HEAP8[((textIndex+1)>>0)];
|
||
|
if (next == 42) {
|
||
|
precision = getNextArg('i32');
|
||
|
textIndex++;
|
||
|
} else {
|
||
|
while(1) {
|
||
|
var precisionChr = HEAP8[((textIndex+1)>>0)];
|
||
|
if (precisionChr < 48 ||
|
||
|
precisionChr > 57) break;
|
||
|
precision = precision * 10 + (precisionChr - 48);
|
||
|
textIndex++;
|
||
|
}
|
||
|
}
|
||
|
next = HEAP8[((textIndex+1)>>0)];
|
||
|
}
|
||
|
if (precision < 0) {
|
||
|
precision = 6; // Standard default.
|
||
|
precisionSet = false;
|
||
|
}
|
||
|
|
||
|
// Handle integer sizes. WARNING: These assume a 32-bit architecture!
|
||
|
var argSize;
|
||
|
switch (String.fromCharCode(next)) {
|
||
|
case 'h':
|
||
|
var nextNext = HEAP8[((textIndex+2)>>0)];
|
||
|
if (nextNext == 104) {
|
||
|
textIndex++;
|
||
|
argSize = 1; // char (actually i32 in varargs)
|
||
|
} else {
|
||
|
argSize = 2; // short (actually i32 in varargs)
|
||
|
}
|
||
|
break;
|
||
|
case 'l':
|
||
|
var nextNext = HEAP8[((textIndex+2)>>0)];
|
||
|
if (nextNext == 108) {
|
||
|
textIndex++;
|
||
|
argSize = 8; // long long
|
||
|
} else {
|
||
|
argSize = 4; // long
|
||
|
}
|
||
|
break;
|
||
|
case 'L': // long long
|
||
|
case 'q': // int64_t
|
||
|
case 'j': // intmax_t
|
||
|
argSize = 8;
|
||
|
break;
|
||
|
case 'z': // size_t
|
||
|
case 't': // ptrdiff_t
|
||
|
case 'I': // signed ptrdiff_t or unsigned size_t
|
||
|
argSize = 4;
|
||
|
break;
|
||
|
default:
|
||
|
argSize = null;
|
||
|
}
|
||
|
if (argSize) textIndex++;
|
||
|
next = HEAP8[((textIndex+1)>>0)];
|
||
|
|
||
|
// Handle type specifier.
|
||
|
switch (String.fromCharCode(next)) {
|
||
|
case 'd': case 'i': case 'u': case 'o': case 'x': case 'X': case 'p': {
|
||
|
// Integer.
|
||
|
var signed = next == 100 || next == 105;
|
||
|
argSize = argSize || 4;
|
||
|
var currArg = getNextArg('i' + (argSize * 8));
|
||
|
var origArg = currArg;
|
||
|
var argText;
|
||
|
// Flatten i64-1 [low, high] into a (slightly rounded) double
|
||
|
if (argSize == 8) {
|
||
|
currArg = Runtime.makeBigInt(currArg[0], currArg[1], next == 117);
|
||
|
}
|
||
|
// Truncate to requested size.
|
||
|
if (argSize <= 4) {
|
||
|
var limit = Math.pow(256, argSize) - 1;
|
||
|
currArg = (signed ? reSign : unSign)(currArg & limit, argSize * 8);
|
||
|
}
|
||
|
// Format the number.
|
||
|
var currAbsArg = Math.abs(currArg);
|
||
|
var prefix = '';
|
||
|
if (next == 100 || next == 105) {
|
||
|
if (argSize == 8 && i64Math) argText = i64Math.stringify(origArg[0], origArg[1], null); else
|
||
|
argText = reSign(currArg, 8 * argSize, 1).toString(10);
|
||
|
} else if (next == 117) {
|
||
|
if (argSize == 8 && i64Math) argText = i64Math.stringify(origArg[0], origArg[1], true); else
|
||
|
argText = unSign(currArg, 8 * argSize, 1).toString(10);
|
||
|
currArg = Math.abs(currArg);
|
||
|
} else if (next == 111) {
|
||
|
argText = (flagAlternative ? '0' : '') + currAbsArg.toString(8);
|
||
|
} else if (next == 120 || next == 88) {
|
||
|
prefix = (flagAlternative && currArg != 0) ? '0x' : '';
|
||
|
if (argSize == 8 && i64Math) {
|
||
|
if (origArg[1]) {
|
||
|
argText = (origArg[1]>>>0).toString(16);
|
||
|
var lower = (origArg[0]>>>0).toString(16);
|
||
|
while (lower.length < 8) lower = '0' + lower;
|
||
|
argText += lower;
|
||
|
} else {
|
||
|
argText = (origArg[0]>>>0).toString(16);
|
||
|
}
|
||
|
} else
|
||
|
if (currArg < 0) {
|
||
|
// Represent negative numbers in hex as 2's complement.
|
||
|
currArg = -currArg;
|
||
|
argText = (currAbsArg - 1).toString(16);
|
||
|
var buffer = [];
|
||
|
for (var i = 0; i < argText.length; i++) {
|
||
|
buffer.push((0xF - parseInt(argText[i], 16)).toString(16));
|
||
|
}
|
||
|
argText = buffer.join('');
|
||
|
while (argText.length < argSize * 2) argText = 'f' + argText;
|
||
|
} else {
|
||
|
argText = currAbsArg.toString(16);
|
||
|
}
|
||
|
if (next == 88) {
|
||
|
prefix = prefix.toUpperCase();
|
||
|
argText = argText.toUpperCase();
|
||
|
}
|
||
|
} else if (next == 112) {
|
||
|
if (currAbsArg === 0) {
|
||
|
argText = '(nil)';
|
||
|
} else {
|
||
|
prefix = '0x';
|
||
|
argText = currAbsArg.toString(16);
|
||
|
}
|
||
|
}
|
||
|
if (precisionSet) {
|
||
|
while (argText.length < precision) {
|
||
|
argText = '0' + argText;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Add sign if needed
|
||
|
if (currArg >= 0) {
|
||
|
if (flagAlwaysSigned) {
|
||
|
prefix = '+' + prefix;
|
||
|
} else if (flagPadSign) {
|
||
|
prefix = ' ' + prefix;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Move sign to prefix so we zero-pad after the sign
|
||
|
if (argText.charAt(0) == '-') {
|
||
|
prefix = '-' + prefix;
|
||
|
argText = argText.substr(1);
|
||
|
}
|
||
|
|
||
|
// Add padding.
|
||
|
while (prefix.length + argText.length < width) {
|
||
|
if (flagLeftAlign) {
|
||
|
argText += ' ';
|
||
|
} else {
|
||
|
if (flagZeroPad) {
|
||
|
argText = '0' + argText;
|
||
|
} else {
|
||
|
prefix = ' ' + prefix;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Insert the result into the buffer.
|
||
|
argText = prefix + argText;
|
||
|
argText.split('').forEach(function(chr) {
|
||
|
ret.push(chr.charCodeAt(0));
|
||
|
});
|
||
|
break;
|
||
|
}
|
||
|
case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': {
|
||
|
// Float.
|
||
|
var currArg = getNextArg('double');
|
||
|
var argText;
|
||
|
if (isNaN(currArg)) {
|
||
|
argText = 'nan';
|
||
|
flagZeroPad = false;
|
||
|
} else if (!isFinite(currArg)) {
|
||
|
argText = (currArg < 0 ? '-' : '') + 'inf';
|
||
|
flagZeroPad = false;
|
||
|
} else {
|
||
|
var isGeneral = false;
|
||
|
var effectivePrecision = Math.min(precision, 20);
|
||
|
|
||
|
// Convert g/G to f/F or e/E, as per:
|
||
|
// http://pubs.opengroup.org/onlinepubs/9699919799/functions/printf.html
|
||
|
if (next == 103 || next == 71) {
|
||
|
isGeneral = true;
|
||
|
precision = precision || 1;
|
||
|
var exponent = parseInt(currArg.toExponential(effectivePrecision).split('e')[1], 10);
|
||
|
if (precision > exponent && exponent >= -4) {
|
||
|
next = ((next == 103) ? 'f' : 'F').charCodeAt(0);
|
||
|
precision -= exponent + 1;
|
||
|
} else {
|
||
|
next = ((next == 103) ? 'e' : 'E').charCodeAt(0);
|
||
|
precision--;
|
||
|
}
|
||
|
effectivePrecision = Math.min(precision, 20);
|
||
|
}
|
||
|
|
||
|
if (next == 101 || next == 69) {
|
||
|
argText = currArg.toExponential(effectivePrecision);
|
||
|
// Make sure the exponent has at least 2 digits.
|
||
|
if (/[eE][-+]\d$/.test(argText)) {
|
||
|
argText = argText.slice(0, -1) + '0' + argText.slice(-1);
|
||
|
}
|
||
|
} else if (next == 102 || next == 70) {
|
||
|
argText = currArg.toFixed(effectivePrecision);
|
||
|
if (currArg === 0 && __reallyNegative(currArg)) {
|
||
|
argText = '-' + argText;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var parts = argText.split('e');
|
||
|
if (isGeneral && !flagAlternative) {
|
||
|
// Discard trailing zeros and periods.
|
||
|
while (parts[0].length > 1 && parts[0].indexOf('.') != -1 &&
|
||
|
(parts[0].slice(-1) == '0' || parts[0].slice(-1) == '.')) {
|
||
|
parts[0] = parts[0].slice(0, -1);
|
||
|
}
|
||
|
} else {
|
||
|
// Make sure we have a period in alternative mode.
|
||
|
if (flagAlternative && argText.indexOf('.') == -1) parts[0] += '.';
|
||
|
// Zero pad until required precision.
|
||
|
while (precision > effectivePrecision++) parts[0] += '0';
|
||
|
}
|
||
|
argText = parts[0] + (parts.length > 1 ? 'e' + parts[1] : '');
|
||
|
|
||
|
// Capitalize 'E' if needed.
|
||
|
if (next == 69) argText = argText.toUpperCase();
|
||
|
|
||
|
// Add sign.
|
||
|
if (currArg >= 0) {
|
||
|
if (flagAlwaysSigned) {
|
||
|
argText = '+' + argText;
|
||
|
} else if (flagPadSign) {
|
||
|
argText = ' ' + argText;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Add padding.
|
||
|
while (argText.length < width) {
|
||
|
if (flagLeftAlign) {
|
||
|
argText += ' ';
|
||
|
} else {
|
||
|
if (flagZeroPad && (argText[0] == '-' || argText[0] == '+')) {
|
||
|
argText = argText[0] + '0' + argText.slice(1);
|
||
|
} else {
|
||
|
argText = (flagZeroPad ? '0' : ' ') + argText;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Adjust case.
|
||
|
if (next < 97) argText = argText.toUpperCase();
|
||
|
|
||
|
// Insert the result into the buffer.
|
||
|
argText.split('').forEach(function(chr) {
|
||
|
ret.push(chr.charCodeAt(0));
|
||
|
});
|
||
|
break;
|
||
|
}
|
||
|
case 's': {
|
||
|
// String.
|
||
|
var arg = getNextArg('i8*');
|
||
|
var argLength = arg ? _strlen(arg) : '(null)'.length;
|
||
|
if (precisionSet) argLength = Math.min(argLength, precision);
|
||
|
if (!flagLeftAlign) {
|
||
|
while (argLength < width--) {
|
||
|
ret.push(32);
|
||
|
}
|
||
|
}
|
||
|
if (arg) {
|
||
|
for (var i = 0; i < argLength; i++) {
|
||
|
ret.push(HEAPU8[((arg++)>>0)]);
|
||
|
}
|
||
|
} else {
|
||
|
ret = ret.concat(intArrayFromString('(null)'.substr(0, argLength), true));
|
||
|
}
|
||
|
if (flagLeftAlign) {
|
||
|
while (argLength < width--) {
|
||
|
ret.push(32);
|
||
|
}
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
case 'c': {
|
||
|
// Character.
|
||
|
if (flagLeftAlign) ret.push(getNextArg('i8'));
|
||
|
while (--width > 0) {
|
||
|
ret.push(32);
|
||
|
}
|
||
|
if (!flagLeftAlign) ret.push(getNextArg('i8'));
|
||
|
break;
|
||
|
}
|
||
|
case 'n': {
|
||
|
// Write the length written so far to the next parameter.
|
||
|
var ptr = getNextArg('i32*');
|
||
|
HEAP32[((ptr)>>2)]=ret.length;
|
||
|
break;
|
||
|
}
|
||
|
case '%': {
|
||
|
// Literal percent sign.
|
||
|
ret.push(curr);
|
||
|
break;
|
||
|
}
|
||
|
default: {
|
||
|
// Unknown specifiers remain untouched.
|
||
|
for (var i = startTextIndex; i < textIndex + 2; i++) {
|
||
|
ret.push(HEAP8[((i)>>0)]);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
textIndex += 2;
|
||
|
// TODO: Support a/A (hex float) and m (last error) specifiers.
|
||
|
// TODO: Support %1${specifier} for arg selection.
|
||
|
} else {
|
||
|
ret.push(curr);
|
||
|
textIndex += 1;
|
||
|
}
|
||
|
}
|
||
|
return ret;
|
||
|
}function _fprintf(stream, format, varargs) {
|
||
|
// int fprintf(FILE *restrict stream, const char *restrict format, ...);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/printf.html
|
||
|
var result = __formatString(format, varargs);
|
||
|
var stack = Runtime.stackSave();
|
||
|
var ret = _fwrite(allocate(result, 'i8', ALLOC_STACK), 1, result.length, stream);
|
||
|
Runtime.stackRestore(stack);
|
||
|
return ret;
|
||
|
}function _printf(format, varargs) {
|
||
|
// int printf(const char *restrict format, ...);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/printf.html
|
||
|
var stdout = HEAP32[((_stdout)>>2)];
|
||
|
return _fprintf(stdout, format, varargs);
|
||
|
}
|
||
|
|
||
|
function _unlockpt() {
|
||
|
Module['printErr']('missing function: unlockpt'); abort(-1);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
var ___DEFAULT_POLLMASK=5;function _poll(fds, nfds, timeout) {
|
||
|
// int poll(struct pollfd fds[], nfds_t nfds, int timeout);
|
||
|
// http://pubs.opengroup.org/onlinepubs/009695399/functions/poll.html
|
||
|
var nonzero = 0;
|
||
|
for (var i = 0; i < nfds; i++) {
|
||
|
var pollfd = fds + 8 * i;
|
||
|
var fd = HEAP32[((pollfd)>>2)];
|
||
|
var events = HEAP16[(((pollfd)+(4))>>1)];
|
||
|
var mask = 32;
|
||
|
var stream = FS.getStream(fd);
|
||
|
if (stream) {
|
||
|
mask = ___DEFAULT_POLLMASK;
|
||
|
if (stream.stream_ops.poll) {
|
||
|
mask = stream.stream_ops.poll(stream);
|
||
|
}
|
||
|
}
|
||
|
mask &= events | 8 | 16;
|
||
|
if (mask) nonzero++;
|
||
|
HEAP16[(((pollfd)+(6))>>1)]=mask;
|
||
|
}
|
||
|
return nonzero;
|
||
|
}
|
||
|
|
||
|
function _open(path, oflag, varargs) {
|
||
|
// int open(const char *path, int oflag, ...);
|
||
|
// http://pubs.opengroup.org/onlinepubs/009695399/functions/open.html
|
||
|
var mode = HEAP32[((varargs)>>2)];
|
||
|
path = Pointer_stringify(path);
|
||
|
try {
|
||
|
var stream = FS.open(path, oflag, mode);
|
||
|
return stream.fd;
|
||
|
} catch (e) {
|
||
|
FS.handleFSError(e);
|
||
|
return -1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function _strtol(str, endptr, base) {
|
||
|
return __parseInt(str, endptr, base, -2147483648, 2147483647, 32); // LONG_MIN, LONG_MAX.
|
||
|
}
|
||
|
|
||
|
function _fputc(c, stream) {
|
||
|
// int fputc(int c, FILE *stream);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/fputc.html
|
||
|
var chr = unSign(c & 0xFF);
|
||
|
HEAP8[((_fputc.ret)>>0)]=chr;
|
||
|
var fd = _fileno(stream);
|
||
|
var ret = _write(fd, _fputc.ret, 1);
|
||
|
if (ret == -1) {
|
||
|
var streamObj = FS.getStreamFromPtr(stream);
|
||
|
if (streamObj) streamObj.error = true;
|
||
|
return -1;
|
||
|
} else {
|
||
|
return chr;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function _sysconf(name) {
|
||
|
// long sysconf(int name);
|
||
|
// http://pubs.opengroup.org/onlinepubs/009695399/functions/sysconf.html
|
||
|
switch(name) {
|
||
|
case 30: return PAGE_SIZE;
|
||
|
case 132:
|
||
|
case 133:
|
||
|
case 12:
|
||
|
case 137:
|
||
|
case 138:
|
||
|
case 15:
|
||
|
case 235:
|
||
|
case 16:
|
||
|
case 17:
|
||
|
case 18:
|
||
|
case 19:
|
||
|
case 20:
|
||
|
case 149:
|
||
|
case 13:
|
||
|
case 10:
|
||
|
case 236:
|
||
|
case 153:
|
||
|
case 9:
|
||
|
case 21:
|
||
|
case 22:
|
||
|
case 159:
|
||
|
case 154:
|
||
|
case 14:
|
||
|
case 77:
|
||
|
case 78:
|
||
|
case 139:
|
||
|
case 80:
|
||
|
case 81:
|
||
|
case 79:
|
||
|
case 82:
|
||
|
case 68:
|
||
|
case 67:
|
||
|
case 164:
|
||
|
case 11:
|
||
|
case 29:
|
||
|
case 47:
|
||
|
case 48:
|
||
|
case 95:
|
||
|
case 52:
|
||
|
case 51:
|
||
|
case 46:
|
||
|
return 200809;
|
||
|
case 27:
|
||
|
case 246:
|
||
|
case 127:
|
||
|
case 128:
|
||
|
case 23:
|
||
|
case 24:
|
||
|
case 160:
|
||
|
case 161:
|
||
|
case 181:
|
||
|
case 182:
|
||
|
case 242:
|
||
|
case 183:
|
||
|
case 184:
|
||
|
case 243:
|
||
|
case 244:
|
||
|
case 245:
|
||
|
case 165:
|
||
|
case 178:
|
||
|
case 179:
|
||
|
case 49:
|
||
|
case 50:
|
||
|
case 168:
|
||
|
case 169:
|
||
|
case 175:
|
||
|
case 170:
|
||
|
case 171:
|
||
|
case 172:
|
||
|
case 97:
|
||
|
case 76:
|
||
|
case 32:
|
||
|
case 173:
|
||
|
case 35:
|
||
|
return -1;
|
||
|
case 176:
|
||
|
case 177:
|
||
|
case 7:
|
||
|
case 155:
|
||
|
case 8:
|
||
|
case 157:
|
||
|
case 125:
|
||
|
case 126:
|
||
|
case 92:
|
||
|
case 93:
|
||
|
case 129:
|
||
|
case 130:
|
||
|
case 131:
|
||
|
case 94:
|
||
|
case 91:
|
||
|
return 1;
|
||
|
case 74:
|
||
|
case 60:
|
||
|
case 69:
|
||
|
case 70:
|
||
|
case 4:
|
||
|
return 1024;
|
||
|
case 31:
|
||
|
case 42:
|
||
|
case 72:
|
||
|
return 32;
|
||
|
case 87:
|
||
|
case 26:
|
||
|
case 33:
|
||
|
return 2147483647;
|
||
|
case 34:
|
||
|
case 1:
|
||
|
return 47839;
|
||
|
case 38:
|
||
|
case 36:
|
||
|
return 99;
|
||
|
case 43:
|
||
|
case 37:
|
||
|
return 2048;
|
||
|
case 0: return 2097152;
|
||
|
case 3: return 65536;
|
||
|
case 28: return 32768;
|
||
|
case 44: return 32767;
|
||
|
case 75: return 16384;
|
||
|
case 39: return 1000;
|
||
|
case 89: return 700;
|
||
|
case 71: return 256;
|
||
|
case 40: return 255;
|
||
|
case 2: return 100;
|
||
|
case 180: return 64;
|
||
|
case 25: return 20;
|
||
|
case 5: return 16;
|
||
|
case 6: return 6;
|
||
|
case 73: return 4;
|
||
|
case 84: return 1;
|
||
|
}
|
||
|
___setErrNo(ERRNO_CODES.EINVAL);
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
function _SDL_PollEvent(ptr) {
|
||
|
if (SDL.initFlags & 0x200 && SDL.joystickEventState) {
|
||
|
// If SDL_INIT_JOYSTICK was supplied AND the joystick system is configured
|
||
|
// to automatically query for events, query for joystick events.
|
||
|
SDL.queryJoysticks();
|
||
|
}
|
||
|
if (SDL.events.length === 0) return 0;
|
||
|
if (ptr) {
|
||
|
SDL.makeCEvent(SDL.events.shift(), ptr);
|
||
|
}
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
function _SDL_GetVideoInfo() {
|
||
|
// %struct.SDL_VideoInfo = type { i32, i32, %struct.SDL_PixelFormat*, i32, i32 } - 5 fields of quantum size
|
||
|
var ret = _malloc(5*Runtime.QUANTUM_SIZE);
|
||
|
HEAP32[((ret+Runtime.QUANTUM_SIZE*0)>>2)]=0; // TODO
|
||
|
HEAP32[((ret+Runtime.QUANTUM_SIZE*1)>>2)]=0; // TODO
|
||
|
HEAP32[((ret+Runtime.QUANTUM_SIZE*2)>>2)]=0;
|
||
|
HEAP32[((ret+Runtime.QUANTUM_SIZE*3)>>2)]=Module["canvas"].width;
|
||
|
HEAP32[((ret+Runtime.QUANTUM_SIZE*4)>>2)]=Module["canvas"].height;
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
function _usleep(useconds) {
|
||
|
// int usleep(useconds_t useconds);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/usleep.html
|
||
|
// We're single-threaded, so use a busy loop. Super-ugly.
|
||
|
var msec = useconds / 1000;
|
||
|
if (ENVIRONMENT_IS_WEB && window['performance'] && window['performance']['now']) {
|
||
|
var start = window['performance']['now']();
|
||
|
while (window['performance']['now']() - start < msec) {
|
||
|
// Do nothing.
|
||
|
}
|
||
|
} else {
|
||
|
var start = Date.now();
|
||
|
while (Date.now() - start < msec) {
|
||
|
// Do nothing.
|
||
|
}
|
||
|
}
|
||
|
return 0;
|
||
|
}function _nanosleep(rqtp, rmtp) {
|
||
|
// int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
|
||
|
var seconds = HEAP32[((rqtp)>>2)];
|
||
|
var nanoseconds = HEAP32[(((rqtp)+(4))>>2)];
|
||
|
if (rmtp !== 0) {
|
||
|
HEAP32[((rmtp)>>2)]=0;
|
||
|
HEAP32[(((rmtp)+(4))>>2)]=0;
|
||
|
}
|
||
|
return _usleep((seconds * 1e6) + (nanoseconds / 1000));
|
||
|
}
|
||
|
|
||
|
function _SDL_Flip(surf) {
|
||
|
// We actually do this in Unlock, since the screen surface has as its canvas
|
||
|
// backing the page canvas element
|
||
|
}
|
||
|
|
||
|
function _ptsname() {
|
||
|
Module['printErr']('missing function: ptsname'); abort(-1);
|
||
|
}
|
||
|
|
||
|
function _SDL_GetMouseState(x, y) {
|
||
|
if (x) HEAP32[((x)>>2)]=Browser.mouseX;
|
||
|
if (y) HEAP32[((y)>>2)]=Browser.mouseY;
|
||
|
return SDL.buttonState;
|
||
|
}
|
||
|
|
||
|
function _fputs(s, stream) {
|
||
|
// int fputs(const char *restrict s, FILE *restrict stream);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/fputs.html
|
||
|
var fd = _fileno(stream);
|
||
|
return _write(fd, s, _strlen(s));
|
||
|
}
|
||
|
|
||
|
function _tcflush() {
|
||
|
Module['printErr']('missing function: tcflush'); abort(-1);
|
||
|
}
|
||
|
|
||
|
function _SDL_InitSubSystem(flags) { return 0 }
|
||
|
|
||
|
|
||
|
function _SDL_GetError() {
|
||
|
if (!SDL.errorMessage) {
|
||
|
SDL.errorMessage = allocate(intArrayFromString("unknown SDL-emscripten error"), 'i8', ALLOC_NORMAL);
|
||
|
}
|
||
|
return SDL.errorMessage;
|
||
|
}
|
||
|
|
||
|
function _emscripten_cancel_main_loop() {
|
||
|
Browser.mainLoop.scheduler = null;
|
||
|
Browser.mainLoop.shouldPause = true;
|
||
|
}
|
||
|
|
||
|
|
||
|
function _malloc(bytes) {
|
||
|
/* Over-allocate to make sure it is byte-aligned by 8.
|
||
|
* This will leak memory, but this is only the dummy
|
||
|
* implementation (replaced by dlmalloc normally) so
|
||
|
* not an issue.
|
||
|
*/
|
||
|
var ptr = Runtime.dynamicAlloc(bytes + 8);
|
||
|
return (ptr+8) & 0xFFFFFFF8;
|
||
|
}
|
||
|
Module["_malloc"] = _malloc;
|
||
|
|
||
|
var ___tm_current=allocate(44, "i8", ALLOC_STATIC);
|
||
|
|
||
|
|
||
|
var ___tm_timezone=allocate(intArrayFromString("GMT"), "i8", ALLOC_STATIC);
|
||
|
|
||
|
|
||
|
var _tzname=allocate(8, "i32*", ALLOC_STATIC);
|
||
|
|
||
|
var _daylight=allocate(1, "i32*", ALLOC_STATIC);
|
||
|
|
||
|
var _timezone=allocate(1, "i32*", ALLOC_STATIC);function _tzset() {
|
||
|
// TODO: Use (malleable) environment variables instead of system settings.
|
||
|
if (_tzset.called) return;
|
||
|
_tzset.called = true;
|
||
|
|
||
|
HEAP32[((_timezone)>>2)]=-(new Date()).getTimezoneOffset() * 60;
|
||
|
|
||
|
var winter = new Date(2000, 0, 1);
|
||
|
var summer = new Date(2000, 6, 1);
|
||
|
HEAP32[((_daylight)>>2)]=Number(winter.getTimezoneOffset() != summer.getTimezoneOffset());
|
||
|
|
||
|
var winterName = 'GMT'; // XXX do not rely on browser timezone info, it is very unpredictable | winter.toString().match(/\(([A-Z]+)\)/)[1];
|
||
|
var summerName = 'GMT'; // XXX do not rely on browser timezone info, it is very unpredictable | summer.toString().match(/\(([A-Z]+)\)/)[1];
|
||
|
var winterNamePtr = allocate(intArrayFromString(winterName), 'i8', ALLOC_NORMAL);
|
||
|
var summerNamePtr = allocate(intArrayFromString(summerName), 'i8', ALLOC_NORMAL);
|
||
|
HEAP32[((_tzname)>>2)]=winterNamePtr;
|
||
|
HEAP32[(((_tzname)+(4))>>2)]=summerNamePtr;
|
||
|
}function _localtime_r(time, tmPtr) {
|
||
|
_tzset();
|
||
|
var date = new Date(HEAP32[((time)>>2)]*1000);
|
||
|
HEAP32[((tmPtr)>>2)]=date.getSeconds();
|
||
|
HEAP32[(((tmPtr)+(4))>>2)]=date.getMinutes();
|
||
|
HEAP32[(((tmPtr)+(8))>>2)]=date.getHours();
|
||
|
HEAP32[(((tmPtr)+(12))>>2)]=date.getDate();
|
||
|
HEAP32[(((tmPtr)+(16))>>2)]=date.getMonth();
|
||
|
HEAP32[(((tmPtr)+(20))>>2)]=date.getFullYear()-1900;
|
||
|
HEAP32[(((tmPtr)+(24))>>2)]=date.getDay();
|
||
|
|
||
|
var start = new Date(date.getFullYear(), 0, 1);
|
||
|
var yday = Math.floor((date.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
|
||
|
HEAP32[(((tmPtr)+(28))>>2)]=yday;
|
||
|
HEAP32[(((tmPtr)+(36))>>2)]=start.getTimezoneOffset() * 60;
|
||
|
|
||
|
var dst = Number(start.getTimezoneOffset() != date.getTimezoneOffset());
|
||
|
HEAP32[(((tmPtr)+(32))>>2)]=dst;
|
||
|
|
||
|
HEAP32[(((tmPtr)+(40))>>2)]=___tm_timezone;
|
||
|
|
||
|
return tmPtr;
|
||
|
}function _localtime(time) {
|
||
|
return _localtime_r(time, ___tm_current);
|
||
|
}
|
||
|
|
||
|
|
||
|
Module["_bitshift64Lshr"] = _bitshift64Lshr;
|
||
|
|
||
|
|
||
|
|
||
|
function _recv(fd, buf, len, flags) {
|
||
|
var sock = SOCKFS.getSocket(fd);
|
||
|
if (!sock) {
|
||
|
___setErrNo(ERRNO_CODES.EBADF);
|
||
|
return -1;
|
||
|
}
|
||
|
// TODO honor flags
|
||
|
return _read(fd, buf, len);
|
||
|
}
|
||
|
|
||
|
function _pread(fildes, buf, nbyte, offset) {
|
||
|
// ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/read.html
|
||
|
var stream = FS.getStream(fildes);
|
||
|
if (!stream) {
|
||
|
___setErrNo(ERRNO_CODES.EBADF);
|
||
|
return -1;
|
||
|
}
|
||
|
try {
|
||
|
var slab = HEAP8;
|
||
|
return FS.read(stream, slab, buf, nbyte, offset);
|
||
|
} catch (e) {
|
||
|
FS.handleFSError(e);
|
||
|
return -1;
|
||
|
}
|
||
|
}function _read(fildes, buf, nbyte) {
|
||
|
// ssize_t read(int fildes, void *buf, size_t nbyte);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/read.html
|
||
|
var stream = FS.getStream(fildes);
|
||
|
if (!stream) {
|
||
|
___setErrNo(ERRNO_CODES.EBADF);
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
|
||
|
try {
|
||
|
var slab = HEAP8;
|
||
|
return FS.read(stream, slab, buf, nbyte);
|
||
|
} catch (e) {
|
||
|
FS.handleFSError(e);
|
||
|
return -1;
|
||
|
}
|
||
|
}function _fread(ptr, size, nitems, stream) {
|
||
|
// size_t fread(void *restrict ptr, size_t size, size_t nitems, FILE *restrict stream);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/fread.html
|
||
|
var bytesToRead = nitems * size;
|
||
|
if (bytesToRead == 0) {
|
||
|
return 0;
|
||
|
}
|
||
|
var bytesRead = 0;
|
||
|
var streamObj = FS.getStreamFromPtr(stream);
|
||
|
if (!streamObj) {
|
||
|
___setErrNo(ERRNO_CODES.EBADF);
|
||
|
return 0;
|
||
|
}
|
||
|
while (streamObj.ungotten.length && bytesToRead > 0) {
|
||
|
HEAP8[((ptr++)>>0)]=streamObj.ungotten.pop();
|
||
|
bytesToRead--;
|
||
|
bytesRead++;
|
||
|
}
|
||
|
var err = _read(streamObj.fd, ptr, bytesToRead);
|
||
|
if (err == -1) {
|
||
|
if (streamObj) streamObj.error = true;
|
||
|
return 0;
|
||
|
}
|
||
|
bytesRead += err;
|
||
|
if (bytesRead < bytesToRead) streamObj.eof = true;
|
||
|
return Math.floor(bytesRead / size);
|
||
|
}
|
||
|
|
||
|
|
||
|
function _SDL_Init(initFlags) {
|
||
|
SDL.startTime = Date.now();
|
||
|
SDL.initFlags = initFlags;
|
||
|
|
||
|
// capture all key events. we just keep down and up, but also capture press to prevent default actions
|
||
|
if (!Module['doNotCaptureKeyboard']) {
|
||
|
document.addEventListener("keydown", SDL.receiveEvent);
|
||
|
document.addEventListener("keyup", SDL.receiveEvent);
|
||
|
document.addEventListener("keypress", SDL.receiveEvent);
|
||
|
window.addEventListener("blur", SDL.receiveEvent);
|
||
|
document.addEventListener("visibilitychange", SDL.receiveEvent);
|
||
|
}
|
||
|
|
||
|
if (initFlags & 0x200) {
|
||
|
// SDL_INIT_JOYSTICK
|
||
|
// Firefox will not give us Joystick data unless we register this NOP
|
||
|
// callback.
|
||
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=936104
|
||
|
addEventListener("gamepadconnected", function() {});
|
||
|
}
|
||
|
|
||
|
window.addEventListener("unload", SDL.receiveEvent);
|
||
|
SDL.keyboardState = _malloc(0x10000); // Our SDL needs 512, but 64K is safe for older SDLs
|
||
|
_memset(SDL.keyboardState, 0, 0x10000);
|
||
|
// Initialize this structure carefully for closure
|
||
|
SDL.DOMEventToSDLEvent['keydown'] = 0x300 /* SDL_KEYDOWN */;
|
||
|
SDL.DOMEventToSDLEvent['keyup'] = 0x301 /* SDL_KEYUP */;
|
||
|
SDL.DOMEventToSDLEvent['keypress'] = 0x303 /* SDL_TEXTINPUT */;
|
||
|
SDL.DOMEventToSDLEvent['mousedown'] = 0x401 /* SDL_MOUSEBUTTONDOWN */;
|
||
|
SDL.DOMEventToSDLEvent['mouseup'] = 0x402 /* SDL_MOUSEBUTTONUP */;
|
||
|
SDL.DOMEventToSDLEvent['mousemove'] = 0x400 /* SDL_MOUSEMOTION */;
|
||
|
SDL.DOMEventToSDLEvent['touchstart'] = 0x700 /* SDL_FINGERDOWN */;
|
||
|
SDL.DOMEventToSDLEvent['touchend'] = 0x701 /* SDL_FINGERUP */;
|
||
|
SDL.DOMEventToSDLEvent['touchmove'] = 0x702 /* SDL_FINGERMOTION */;
|
||
|
SDL.DOMEventToSDLEvent['unload'] = 0x100 /* SDL_QUIT */;
|
||
|
SDL.DOMEventToSDLEvent['resize'] = 0x7001 /* SDL_VIDEORESIZE/SDL_EVENT_COMPAT2 */;
|
||
|
// These are not technically DOM events; the HTML gamepad API is poll-based.
|
||
|
// However, we define them here, as the rest of the SDL code assumes that
|
||
|
// all SDL events originate as DOM events.
|
||
|
SDL.DOMEventToSDLEvent['joystick_axis_motion'] = 0x600 /* SDL_JOYAXISMOTION */;
|
||
|
SDL.DOMEventToSDLEvent['joystick_button_down'] = 0x603 /* SDL_JOYBUTTONDOWN */;
|
||
|
SDL.DOMEventToSDLEvent['joystick_button_up'] = 0x604 /* SDL_JOYBUTTONUP */;
|
||
|
return 0; // success
|
||
|
}function _SDL_WasInit() {
|
||
|
if (SDL.startTime === null) {
|
||
|
_SDL_Init();
|
||
|
}
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
|
||
|
function _SDL_WM_ToggleFullScreen(surf) {
|
||
|
if (Browser.isFullScreen) {
|
||
|
Module['canvas'].cancelFullScreen();
|
||
|
return 1;
|
||
|
} else {
|
||
|
if (!SDL.canRequestFullscreen) {
|
||
|
return 0;
|
||
|
}
|
||
|
SDL.isRequestingFullscreen = true;
|
||
|
return 1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function _gettimeofday(ptr) {
|
||
|
var now = Date.now();
|
||
|
HEAP32[((ptr)>>2)]=Math.floor(now/1000); // seconds
|
||
|
HEAP32[(((ptr)+(4))>>2)]=Math.floor((now-1000*Math.floor(now/1000))*1000); // microseconds
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
function _vfprintf(s, f, va_arg) {
|
||
|
return _fprintf(s, f, HEAP32[((va_arg)>>2)]);
|
||
|
}
|
||
|
|
||
|
function _SDL_WM_SetCaption(title, icon) {
|
||
|
title = title && Pointer_stringify(title);
|
||
|
icon = icon && Pointer_stringify(icon);
|
||
|
}
|
||
|
|
||
|
|
||
|
function _emscripten_memcpy_big(dest, src, num) {
|
||
|
HEAPU8.set(HEAPU8.subarray(src, src+num), dest);
|
||
|
return dest;
|
||
|
}
|
||
|
Module["_memcpy"] = _memcpy;
|
||
|
|
||
|
|
||
|
function _sbrk(bytes) {
|
||
|
// Implement a Linux-like 'memory area' for our 'process'.
|
||
|
// Changes the size of the memory area by |bytes|; returns the
|
||
|
// address of the previous top ('break') of the memory area
|
||
|
// We control the "dynamic" memory - DYNAMIC_BASE to DYNAMICTOP
|
||
|
var self = _sbrk;
|
||
|
if (!self.called) {
|
||
|
DYNAMICTOP = alignMemoryPage(DYNAMICTOP); // make sure we start out aligned
|
||
|
self.called = true;
|
||
|
assert(Runtime.dynamicAlloc);
|
||
|
self.alloc = Runtime.dynamicAlloc;
|
||
|
Runtime.dynamicAlloc = function() { abort('cannot dynamically allocate, sbrk now has control') };
|
||
|
}
|
||
|
var ret = DYNAMICTOP;
|
||
|
if (bytes != 0) self.alloc(bytes);
|
||
|
return ret; // Previous break location.
|
||
|
}
|
||
|
|
||
|
|
||
|
Module["_bitshift64Shl"] = _bitshift64Shl;
|
||
|
|
||
|
function _signal(sig, func) {
|
||
|
// TODO
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
function ___errno_location() {
|
||
|
return ___errno_state;
|
||
|
}
|
||
|
|
||
|
function _SDL_LockAudio() {}
|
||
|
|
||
|
function _SDL_OpenAudio(desired, obtained) {
|
||
|
try {
|
||
|
SDL.audio = {
|
||
|
freq: HEAPU32[((desired)>>2)],
|
||
|
format: HEAPU16[(((desired)+(4))>>1)],
|
||
|
channels: HEAPU8[(((desired)+(6))>>0)],
|
||
|
samples: HEAPU16[(((desired)+(8))>>1)], // Samples in the CB buffer per single sound channel.
|
||
|
callback: HEAPU32[(((desired)+(16))>>2)],
|
||
|
userdata: HEAPU32[(((desired)+(20))>>2)],
|
||
|
paused: true,
|
||
|
timer: null
|
||
|
};
|
||
|
// The .silence field tells the constant sample value that corresponds to the safe un-skewed silence value for the wave data.
|
||
|
if (SDL.audio.format == 0x0008 /*AUDIO_U8*/) {
|
||
|
SDL.audio.silence = 128; // Audio ranges in [0, 255], so silence is half-way in between.
|
||
|
} else if (SDL.audio.format == 0x8010 /*AUDIO_S16LSB*/) {
|
||
|
SDL.audio.silence = 0; // Signed data in range [-32768, 32767], silence is 0.
|
||
|
} else {
|
||
|
throw 'Invalid SDL audio format ' + SDL.audio.format + '!';
|
||
|
}
|
||
|
// Round the desired audio frequency up to the next 'common' frequency value.
|
||
|
// Web Audio API spec states 'An implementation must support sample-rates in at least the range 22050 to 96000.'
|
||
|
if (SDL.audio.freq <= 0) {
|
||
|
throw 'Unsupported sound frequency ' + SDL.audio.freq + '!';
|
||
|
} else if (SDL.audio.freq <= 22050) {
|
||
|
SDL.audio.freq = 22050; // Take it safe and clamp everything lower than 22kHz to that.
|
||
|
} else if (SDL.audio.freq <= 32000) {
|
||
|
SDL.audio.freq = 32000;
|
||
|
} else if (SDL.audio.freq <= 44100) {
|
||
|
SDL.audio.freq = 44100;
|
||
|
} else if (SDL.audio.freq <= 48000) {
|
||
|
SDL.audio.freq = 48000;
|
||
|
} else if (SDL.audio.freq <= 96000) {
|
||
|
SDL.audio.freq = 96000;
|
||
|
} else {
|
||
|
throw 'Unsupported sound frequency ' + SDL.audio.freq + '!';
|
||
|
}
|
||
|
if (SDL.audio.channels == 0) {
|
||
|
SDL.audio.channels = 1; // In SDL both 0 and 1 mean mono.
|
||
|
} else if (SDL.audio.channels < 0 || SDL.audio.channels > 32) {
|
||
|
throw 'Unsupported number of audio channels for SDL audio: ' + SDL.audio.channels + '!';
|
||
|
} else if (SDL.audio.channels != 1 && SDL.audio.channels != 2) { // Unsure what SDL audio spec supports. Web Audio spec supports up to 32 channels.
|
||
|
console.log('Warning: Using untested number of audio channels ' + SDL.audio.channels);
|
||
|
}
|
||
|
if (SDL.audio.samples < 128 || SDL.audio.samples > 524288 /* arbitrary cap */) {
|
||
|
throw 'Unsupported audio callback buffer size ' + SDL.audio.samples + '!';
|
||
|
} else if ((SDL.audio.samples & (SDL.audio.samples-1)) != 0) {
|
||
|
throw 'Audio callback buffer size ' + SDL.audio.samples + ' must be a power-of-two!';
|
||
|
}
|
||
|
|
||
|
var totalSamples = SDL.audio.samples*SDL.audio.channels;
|
||
|
SDL.audio.bytesPerSample = (SDL.audio.format == 0x0008 /*AUDIO_U8*/ || SDL.audio.format == 0x8008 /*AUDIO_S8*/) ? 1 : 2;
|
||
|
SDL.audio.bufferSize = totalSamples*SDL.audio.bytesPerSample;
|
||
|
SDL.audio.buffer = _malloc(SDL.audio.bufferSize);
|
||
|
|
||
|
// To account for jittering in frametimes, always have multiple audio buffers queued up for the audio output device.
|
||
|
// This helps that we won't starve that easily if a frame takes long to complete.
|
||
|
SDL.audio.numSimultaneouslyQueuedBuffers = Module['SDL_numSimultaneouslyQueuedBuffers'] || 3;
|
||
|
|
||
|
// Create a callback function that will be routinely called to ask more audio data from the user application.
|
||
|
SDL.audio.caller = function SDL_audio_caller() {
|
||
|
if (!SDL.audio) {
|
||
|
return;
|
||
|
}
|
||
|
Runtime.dynCall('viii', SDL.audio.callback, [SDL.audio.userdata, SDL.audio.buffer, SDL.audio.bufferSize]);
|
||
|
SDL.audio.pushAudio(SDL.audio.buffer, SDL.audio.bufferSize);
|
||
|
};
|
||
|
|
||
|
SDL.audio.audioOutput = new Audio();
|
||
|
// As a workaround use Mozilla Audio Data API on Firefox until it ships with Web Audio and sound quality issues are fixed.
|
||
|
if (typeof(SDL.audio.audioOutput['mozSetup'])==='function') {
|
||
|
SDL.audio.audioOutput['mozSetup'](SDL.audio.channels, SDL.audio.freq); // use string attributes on mozOutput for closure compiler
|
||
|
SDL.audio.mozBuffer = new Float32Array(totalSamples);
|
||
|
SDL.audio.nextPlayTime = 0;
|
||
|
SDL.audio.pushAudio = function SDL_audio_pushAudio(ptr, size) {
|
||
|
--SDL.audio.numAudioTimersPending;
|
||
|
var mozBuffer = SDL.audio.mozBuffer;
|
||
|
// The input audio data for SDL audio is either 8-bit or 16-bit interleaved across channels, output for Mozilla Audio Data API
|
||
|
// needs to be Float32 interleaved, so perform a sample conversion.
|
||
|
if (SDL.audio.format == 0x8010 /*AUDIO_S16LSB*/) {
|
||
|
for (var i = 0; i < totalSamples; i++) {
|
||
|
mozBuffer[i] = (HEAP16[(((ptr)+(i*2))>>1)]) / 0x8000;
|
||
|
}
|
||
|
} else if (SDL.audio.format == 0x0008 /*AUDIO_U8*/) {
|
||
|
for (var i = 0; i < totalSamples; i++) {
|
||
|
var v = (HEAP8[(((ptr)+(i))>>0)]);
|
||
|
mozBuffer[i] = ((v >= 0) ? v-128 : v+128) /128;
|
||
|
}
|
||
|
}
|
||
|
// Submit the audio data to audio device.
|
||
|
SDL.audio.audioOutput['mozWriteAudio'](mozBuffer);
|
||
|
|
||
|
// Compute when the next audio callback should be called.
|
||
|
var curtime = Date.now() / 1000.0 - SDL.audio.startTime;
|
||
|
var playtime = Math.max(curtime, SDL.audio.nextPlayTime);
|
||
|
var buffer_duration = SDL.audio.samples / SDL.audio.freq;
|
||
|
SDL.audio.nextPlayTime = playtime + buffer_duration;
|
||
|
// Schedule the next audio callback call to occur when the current one finishes.
|
||
|
SDL.audio.timer = Browser.safeSetTimeout(SDL.audio.caller, 1000.0 * (playtime-curtime));
|
||
|
++SDL.audio.numAudioTimersPending;
|
||
|
// And also schedule extra buffers _now_ if we have too few in queue.
|
||
|
if (SDL.audio.numAudioTimersPending < SDL.audio.numSimultaneouslyQueuedBuffers) {
|
||
|
++SDL.audio.numAudioTimersPending;
|
||
|
Browser.safeSetTimeout(SDL.audio.caller, 1.0);
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
|
// Initialize Web Audio API if we haven't done so yet. Note: Only initialize Web Audio context ever once on the web page,
|
||
|
// since initializing multiple times fails on Chrome saying 'audio resources have been exhausted'.
|
||
|
if (!SDL.audioContext) {
|
||
|
if (typeof(AudioContext) !== 'undefined') {
|
||
|
SDL.audioContext = new AudioContext();
|
||
|
} else if (typeof(webkitAudioContext) !== 'undefined') {
|
||
|
SDL.audioContext = new webkitAudioContext();
|
||
|
} else {
|
||
|
throw 'Web Audio API is not available!';
|
||
|
}
|
||
|
}
|
||
|
SDL.audio.soundSource = new Array(); // Use an array of sound sources as a ring buffer to queue blocks of synthesized audio to Web Audio API.
|
||
|
SDL.audio.nextSoundSource = 0; // Index of the next sound buffer in the ring buffer queue to play.
|
||
|
SDL.audio.nextPlayTime = 0; // Time in seconds when the next audio block is due to start.
|
||
|
|
||
|
// The pushAudio function with a new audio buffer whenever there is new audio data to schedule to be played back on the device.
|
||
|
SDL.audio.pushAudio=function(ptr,sizeBytes) {
|
||
|
try {
|
||
|
--SDL.audio.numAudioTimersPending;
|
||
|
if (SDL.audio.paused) return;
|
||
|
|
||
|
var sizeSamples = sizeBytes / SDL.audio.bytesPerSample; // How many samples fit in the callback buffer?
|
||
|
var sizeSamplesPerChannel = sizeSamples / SDL.audio.channels; // How many samples per a single channel fit in the cb buffer?
|
||
|
if (sizeSamplesPerChannel != SDL.audio.samples) {
|
||
|
throw 'Received mismatching audio buffer size!';
|
||
|
}
|
||
|
// Allocate new sound buffer to be played.
|
||
|
var source = SDL.audioContext['createBufferSource']();
|
||
|
if (SDL.audio.soundSource[SDL.audio.nextSoundSource]) {
|
||
|
SDL.audio.soundSource[SDL.audio.nextSoundSource]['disconnect'](); // Explicitly disconnect old source, since we know it shouldn't be running anymore.
|
||
|
}
|
||
|
SDL.audio.soundSource[SDL.audio.nextSoundSource] = source;
|
||
|
var soundBuffer = SDL.audioContext['createBuffer'](SDL.audio.channels,sizeSamplesPerChannel,SDL.audio.freq);
|
||
|
SDL.audio.soundSource[SDL.audio.nextSoundSource]['connect'](SDL.audioContext['destination']);
|
||
|
|
||
|
SDL.fillWebAudioBufferFromHeap(ptr, sizeSamplesPerChannel, soundBuffer);
|
||
|
// Workaround https://bugzilla.mozilla.org/show_bug.cgi?id=883675 by setting the buffer only after filling. The order is important here!
|
||
|
source['buffer'] = soundBuffer;
|
||
|
|
||
|
// Schedule the generated sample buffer to be played out at the correct time right after the previously scheduled
|
||
|
// sample buffer has finished.
|
||
|
var curtime = SDL.audioContext['currentTime'];
|
||
|
var playtime = Math.max(curtime, SDL.audio.nextPlayTime);
|
||
|
var ss = SDL.audio.soundSource[SDL.audio.nextSoundSource];
|
||
|
if (typeof ss['start'] !== 'undefined') {
|
||
|
ss['start'](playtime);
|
||
|
} else if (typeof ss['noteOn'] !== 'undefined') {
|
||
|
ss['noteOn'](playtime);
|
||
|
}
|
||
|
var buffer_duration = sizeSamplesPerChannel / SDL.audio.freq;
|
||
|
SDL.audio.nextPlayTime = playtime + buffer_duration;
|
||
|
// Timer will be scheduled before the buffer completed playing.
|
||
|
// Extra buffers are needed to avoid disturbing playing buffer.
|
||
|
SDL.audio.nextSoundSource = (SDL.audio.nextSoundSource + 1) % (SDL.audio.numSimultaneouslyQueuedBuffers + 2);
|
||
|
var secsUntilNextCall = playtime-curtime;
|
||
|
|
||
|
// Queue the next audio frame push to be performed when the previously queued buffer has finished playing.
|
||
|
var preemptBufferFeedMSecs = 1000*buffer_duration/2.0;
|
||
|
SDL.audio.timer = Browser.safeSetTimeout(SDL.audio.caller, Math.max(0.0, 1000.0*secsUntilNextCall-preemptBufferFeedMSecs));
|
||
|
++SDL.audio.numAudioTimersPending;
|
||
|
|
||
|
// If we are risking starving, immediately queue extra buffers.
|
||
|
if (SDL.audio.numAudioTimersPending < SDL.audio.numSimultaneouslyQueuedBuffers) {
|
||
|
++SDL.audio.numAudioTimersPending;
|
||
|
Browser.safeSetTimeout(SDL.audio.caller, 1.0);
|
||
|
}
|
||
|
} catch(e) {
|
||
|
console.log('Web Audio API error playing back audio: ' + e.toString());
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (obtained) {
|
||
|
// Report back the initialized audio parameters.
|
||
|
HEAP32[((obtained)>>2)]=SDL.audio.freq;
|
||
|
HEAP16[(((obtained)+(4))>>1)]=SDL.audio.format;
|
||
|
HEAP8[(((obtained)+(6))>>0)]=SDL.audio.channels;
|
||
|
HEAP8[(((obtained)+(7))>>0)]=SDL.audio.silence;
|
||
|
HEAP16[(((obtained)+(8))>>1)]=SDL.audio.samples;
|
||
|
HEAP32[(((obtained)+(16))>>2)]=SDL.audio.callback;
|
||
|
HEAP32[(((obtained)+(20))>>2)]=SDL.audio.userdata;
|
||
|
}
|
||
|
SDL.allocateChannels(32);
|
||
|
|
||
|
} catch(e) {
|
||
|
console.log('Initializing SDL audio threw an exception: "' + e.toString() + '"! Continuing without audio.');
|
||
|
SDL.audio = null;
|
||
|
SDL.allocateChannels(0);
|
||
|
if (obtained) {
|
||
|
HEAP32[((obtained)>>2)]=0;
|
||
|
HEAP16[(((obtained)+(4))>>1)]=0;
|
||
|
HEAP8[(((obtained)+(6))>>0)]=0;
|
||
|
HEAP8[(((obtained)+(7))>>0)]=0;
|
||
|
HEAP16[(((obtained)+(8))>>1)]=0;
|
||
|
HEAP32[(((obtained)+(16))>>2)]=0;
|
||
|
HEAP32[(((obtained)+(20))>>2)]=0;
|
||
|
}
|
||
|
}
|
||
|
if (!SDL.audio) {
|
||
|
return -1;
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
function _SDL_UnlockAudio() {}
|
||
|
|
||
|
function _SDL_EnableKeyRepeat(delay, interval) {
|
||
|
// TODO
|
||
|
}
|
||
|
|
||
|
function _fgetc(stream) {
|
||
|
// int fgetc(FILE *stream);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/fgetc.html
|
||
|
var streamObj = FS.getStreamFromPtr(stream);
|
||
|
if (!streamObj) return -1;
|
||
|
if (streamObj.eof || streamObj.error) return -1;
|
||
|
var ret = _fread(_fgetc.ret, 1, 1, stream);
|
||
|
if (ret == 0) {
|
||
|
return -1;
|
||
|
} else if (ret == -1) {
|
||
|
streamObj.error = true;
|
||
|
return -1;
|
||
|
} else {
|
||
|
return HEAPU8[((_fgetc.ret)>>0)];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function _SDL_PauseAudio(pauseOn) {
|
||
|
if (!SDL.audio) {
|
||
|
return;
|
||
|
}
|
||
|
if (pauseOn) {
|
||
|
if (SDL.audio.timer !== undefined) {
|
||
|
clearTimeout(SDL.audio.timer);
|
||
|
SDL.audio.numAudioTimersPending = 0;
|
||
|
SDL.audio.timer = undefined;
|
||
|
}
|
||
|
if (SDL.audio.scriptProcessorNode !== undefined) {
|
||
|
SDL.audio.scriptProcessorNode['disconnect']();
|
||
|
SDL.audio.scriptProcessorNode = undefined;
|
||
|
}
|
||
|
} else if (!SDL.audio.timer && !SDL.audio.scriptProcessorNode) {
|
||
|
// If we are using the same sampling frequency as the native sampling rate of the Web Audio graph is using, we can feed our buffers via
|
||
|
// Web Audio ScriptProcessorNode, which is a pull-mode API that calls back to our code to get audio data.
|
||
|
if (SDL.audioContext !== undefined && SDL.audio.freq == SDL.audioContext['sampleRate'] && typeof SDL.audioContext['createScriptProcessor'] !== 'undefined') {
|
||
|
var sizeSamplesPerChannel = SDL.audio.bufferSize / SDL.audio.bytesPerSample / SDL.audio.channels; // How many samples per a single channel fit in the cb buffer?
|
||
|
SDL.audio.scriptProcessorNode = SDL.audioContext['createScriptProcessor'](sizeSamplesPerChannel, 0, SDL.audio.channels);
|
||
|
SDL.audio.scriptProcessorNode['onaudioprocess'] = function (e) {
|
||
|
Runtime.dynCall('viii', SDL.audio.callback, [SDL.audio.userdata, SDL.audio.buffer, SDL.audio.bufferSize]);
|
||
|
SDL.fillWebAudioBufferFromHeap(SDL.audio.buffer, sizeSamplesPerChannel, e['outputBuffer']);
|
||
|
}
|
||
|
SDL.audio.scriptProcessorNode['connect'](SDL.audioContext['destination']);
|
||
|
} else { // If we are using a different sampling rate, must manually queue audio data to the graph via timers.
|
||
|
// Start the audio playback timer callback loop.
|
||
|
SDL.audio.numAudioTimersPending = 1;
|
||
|
SDL.audio.timer = Browser.safeSetTimeout(SDL.audio.caller, 1);
|
||
|
SDL.audio.startTime = Date.now() / 1000.0; // Only used for Mozilla Audio Data API. Not needed for Web Audio API.
|
||
|
}
|
||
|
}
|
||
|
SDL.audio.paused = pauseOn;
|
||
|
}
|
||
|
|
||
|
|
||
|
Module["_memset"] = _memset;
|
||
|
|
||
|
|
||
|
Module["_strcat"] = _strcat;
|
||
|
|
||
|
function _atexit(func, arg) {
|
||
|
__ATEXIT__.unshift({ func: func, arg: arg });
|
||
|
}
|
||
|
|
||
|
function _abort() {
|
||
|
Module['abort']();
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
function _free() {
|
||
|
}
|
||
|
Module["_free"] = _free;function _SDL_CloseAudio() {
|
||
|
if (SDL.audio) {
|
||
|
try{
|
||
|
for(var i = 0; i < SDL.audio.soundSource.length; ++i) {
|
||
|
if (!(typeof(SDL.audio.soundSource[i]==='undefined'))) {
|
||
|
SDL.audio.soundSource[i].stop(0);
|
||
|
}
|
||
|
}
|
||
|
} catch(e) {}
|
||
|
SDL.audio.soundSource = null;
|
||
|
_SDL_PauseAudio(1);
|
||
|
_free(SDL.audio.buffer);
|
||
|
SDL.audio = null;
|
||
|
SDL.allocateChannels(0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
var _tan=Math_tan;
|
||
|
|
||
|
|
||
|
function _SDL_SetVideoMode(width, height, depth, flags) {
|
||
|
['touchstart', 'touchend', 'touchmove', 'mousedown', 'mouseup', 'mousemove', 'DOMMouseScroll', 'mousewheel', 'mouseout'].forEach(function(event) {
|
||
|
Module['canvas'].addEventListener(event, SDL.receiveEvent, true);
|
||
|
});
|
||
|
|
||
|
// (0,0) means 'use fullscreen' in native; in Emscripten, use the current canvas size.
|
||
|
if (width == 0 && height == 0) {
|
||
|
var canvas = Module['canvas'];
|
||
|
width = canvas.width;
|
||
|
height = canvas.height;
|
||
|
}
|
||
|
|
||
|
Browser.setCanvasSize(width, height, true);
|
||
|
// Free the old surface first.
|
||
|
if (SDL.screen) {
|
||
|
SDL.freeSurface(SDL.screen);
|
||
|
assert(!SDL.screen);
|
||
|
}
|
||
|
SDL.screen = SDL.makeSurface(width, height, flags, true, 'screen');
|
||
|
if (!SDL.addedResizeListener) {
|
||
|
SDL.addedResizeListener = true;
|
||
|
Browser.resizeListeners.push(function(w, h) {
|
||
|
SDL.receiveEvent({
|
||
|
type: 'resize',
|
||
|
w: w,
|
||
|
h: h
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
return SDL.screen;
|
||
|
}
|
||
|
|
||
|
function _tcsetattr(fildes, optional_actions, termios_p) {
|
||
|
// http://pubs.opengroup.org/onlinepubs/7908799/xsh/tcsetattr.html
|
||
|
var stream = FS.getStream(fildes);
|
||
|
if (!stream) {
|
||
|
___setErrNo(ERRNO_CODES.EBADF);
|
||
|
return -1;
|
||
|
}
|
||
|
if (!stream.tty) {
|
||
|
___setErrNo(ERRNO_CODES.ENOTTY);
|
||
|
return -1;
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
function _tcgetattr(fildes, termios_p) {
|
||
|
// http://pubs.opengroup.org/onlinepubs/009695399/functions/tcgetattr.html
|
||
|
var stream = FS.getStream(fildes);
|
||
|
if (!stream) {
|
||
|
___setErrNo(ERRNO_CODES.EBADF);
|
||
|
return -1;
|
||
|
}
|
||
|
if (!stream.tty) {
|
||
|
___setErrNo(ERRNO_CODES.ENOTTY);
|
||
|
return -1;
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
function _fopen(filename, mode) {
|
||
|
// FILE *fopen(const char *restrict filename, const char *restrict mode);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/fopen.html
|
||
|
var flags;
|
||
|
mode = Pointer_stringify(mode);
|
||
|
if (mode[0] == 'r') {
|
||
|
if (mode.indexOf('+') != -1) {
|
||
|
flags = 2;
|
||
|
} else {
|
||
|
flags = 0;
|
||
|
}
|
||
|
} else if (mode[0] == 'w') {
|
||
|
if (mode.indexOf('+') != -1) {
|
||
|
flags = 2;
|
||
|
} else {
|
||
|
flags = 1;
|
||
|
}
|
||
|
flags |= 64;
|
||
|
flags |= 512;
|
||
|
} else if (mode[0] == 'a') {
|
||
|
if (mode.indexOf('+') != -1) {
|
||
|
flags = 2;
|
||
|
} else {
|
||
|
flags = 1;
|
||
|
}
|
||
|
flags |= 64;
|
||
|
flags |= 1024;
|
||
|
} else {
|
||
|
___setErrNo(ERRNO_CODES.EINVAL);
|
||
|
return 0;
|
||
|
}
|
||
|
var fd = _open(filename, flags, allocate([0x1FF, 0, 0, 0], 'i32', ALLOC_STACK)); // All creation permissions.
|
||
|
return fd === -1 ? 0 : FS.getPtrForStream(FS.getStream(fd));
|
||
|
}
|
||
|
|
||
|
function _posix_openpt() {
|
||
|
Module['printErr']('missing function: posix_openpt'); abort(-1);
|
||
|
}
|
||
|
|
||
|
|
||
|
function _lseek(fildes, offset, whence) {
|
||
|
// off_t lseek(int fildes, off_t offset, int whence);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/lseek.html
|
||
|
var stream = FS.getStream(fildes);
|
||
|
if (!stream) {
|
||
|
___setErrNo(ERRNO_CODES.EBADF);
|
||
|
return -1;
|
||
|
}
|
||
|
try {
|
||
|
return FS.llseek(stream, offset, whence);
|
||
|
} catch (e) {
|
||
|
FS.handleFSError(e);
|
||
|
return -1;
|
||
|
}
|
||
|
}function _fseek(stream, offset, whence) {
|
||
|
// int fseek(FILE *stream, long offset, int whence);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/fseek.html
|
||
|
var fd = _fileno(stream);
|
||
|
var ret = _lseek(fd, offset, whence);
|
||
|
if (ret == -1) {
|
||
|
return -1;
|
||
|
}
|
||
|
stream = FS.getStreamFromPtr(stream);
|
||
|
stream.eof = false;
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
function _grantpt() {
|
||
|
Module['printErr']('missing function: grantpt'); abort(-1);
|
||
|
}
|
||
|
|
||
|
function _ftell(stream) {
|
||
|
// long ftell(FILE *stream);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/ftell.html
|
||
|
stream = FS.getStreamFromPtr(stream);
|
||
|
if (!stream) {
|
||
|
___setErrNo(ERRNO_CODES.EBADF);
|
||
|
return -1;
|
||
|
}
|
||
|
if (FS.isChrdev(stream.node.mode)) {
|
||
|
___setErrNo(ERRNO_CODES.ESPIPE);
|
||
|
return -1;
|
||
|
} else {
|
||
|
return stream.position;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
function __exit(status) {
|
||
|
// void _exit(int status);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/exit.html
|
||
|
Module['exit'](status);
|
||
|
}function _exit(status) {
|
||
|
__exit(status);
|
||
|
}
|
||
|
|
||
|
|
||
|
function _snprintf(s, n, format, varargs) {
|
||
|
// int snprintf(char *restrict s, size_t n, const char *restrict format, ...);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/printf.html
|
||
|
var result = __formatString(format, varargs);
|
||
|
var limit = (n === undefined) ? result.length
|
||
|
: Math.min(result.length, Math.max(n - 1, 0));
|
||
|
if (s < 0) {
|
||
|
s = -s;
|
||
|
var buf = _malloc(limit+1);
|
||
|
HEAP32[((s)>>2)]=buf;
|
||
|
s = buf;
|
||
|
}
|
||
|
for (var i = 0; i < limit; i++) {
|
||
|
HEAP8[(((s)+(i))>>0)]=result[i];
|
||
|
}
|
||
|
if (limit < n || (n === undefined)) HEAP8[(((s)+(i))>>0)]=0;
|
||
|
return result.length;
|
||
|
}function _sprintf(s, format, varargs) {
|
||
|
// int sprintf(char *restrict s, const char *restrict format, ...);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/printf.html
|
||
|
return _snprintf(s, undefined, format, varargs);
|
||
|
}
|
||
|
|
||
|
function _fcntl(fildes, cmd, varargs, dup2) {
|
||
|
// int fcntl(int fildes, int cmd, ...);
|
||
|
// http://pubs.opengroup.org/onlinepubs/009695399/functions/fcntl.html
|
||
|
var stream = FS.getStream(fildes);
|
||
|
if (!stream) {
|
||
|
___setErrNo(ERRNO_CODES.EBADF);
|
||
|
return -1;
|
||
|
}
|
||
|
switch (cmd) {
|
||
|
case 0:
|
||
|
var arg = HEAP32[((varargs)>>2)];
|
||
|
if (arg < 0) {
|
||
|
___setErrNo(ERRNO_CODES.EINVAL);
|
||
|
return -1;
|
||
|
}
|
||
|
var newStream;
|
||
|
try {
|
||
|
newStream = FS.open(stream.path, stream.flags, 0, arg);
|
||
|
} catch (e) {
|
||
|
FS.handleFSError(e);
|
||
|
return -1;
|
||
|
}
|
||
|
return newStream.fd;
|
||
|
case 1:
|
||
|
case 2:
|
||
|
return 0; // FD_CLOEXEC makes no sense for a single process.
|
||
|
case 3:
|
||
|
return stream.flags;
|
||
|
case 4:
|
||
|
var arg = HEAP32[((varargs)>>2)];
|
||
|
stream.flags |= arg;
|
||
|
return 0;
|
||
|
case 12:
|
||
|
case 12:
|
||
|
var arg = HEAP32[((varargs)>>2)];
|
||
|
var offset = 0;
|
||
|
// We're always unlocked.
|
||
|
HEAP16[(((arg)+(offset))>>1)]=2;
|
||
|
return 0;
|
||
|
case 13:
|
||
|
case 14:
|
||
|
case 13:
|
||
|
case 14:
|
||
|
// Pretend that the locking is successful.
|
||
|
return 0;
|
||
|
case 8:
|
||
|
case 9:
|
||
|
// These are for sockets. We don't have them fully implemented yet.
|
||
|
___setErrNo(ERRNO_CODES.EINVAL);
|
||
|
return -1;
|
||
|
default:
|
||
|
___setErrNo(ERRNO_CODES.EINVAL);
|
||
|
return -1;
|
||
|
}
|
||
|
// Should never be reached. Only to silence strict warnings.
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
|
||
|
Module["_tolower"] = _tolower;
|
||
|
|
||
|
function _SDL_ShowCursor(toggle) {
|
||
|
switch (toggle) {
|
||
|
case 0: // SDL_DISABLE
|
||
|
if (Browser.isFullScreen) { // only try to lock the pointer when in full screen mode
|
||
|
Module['canvas'].requestPointerLock();
|
||
|
return 0;
|
||
|
} else { // else return SDL_ENABLE to indicate the failure
|
||
|
return 1;
|
||
|
}
|
||
|
break;
|
||
|
case 1: // SDL_ENABLE
|
||
|
Module['canvas'].exitPointerLock();
|
||
|
return 1;
|
||
|
break;
|
||
|
case -1: // SDL_QUERY
|
||
|
return !Browser.pointerLock;
|
||
|
break;
|
||
|
default:
|
||
|
console.log( "SDL_ShowCursor called with unknown toggle parameter value: " + toggle + "." );
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function _emscripten_set_main_loop(func, fps, simulateInfiniteLoop, arg) {
|
||
|
Module['noExitRuntime'] = true;
|
||
|
|
||
|
assert(!Browser.mainLoop.scheduler, 'there can only be one main loop function at once: call emscripten_cancel_main_loop to cancel the previous one, if you want to');
|
||
|
|
||
|
Browser.mainLoop.runner = function Browser_mainLoop_runner() {
|
||
|
if (ABORT) return;
|
||
|
if (Browser.mainLoop.queue.length > 0) {
|
||
|
var start = Date.now();
|
||
|
var blocker = Browser.mainLoop.queue.shift();
|
||
|
blocker.func(blocker.arg);
|
||
|
if (Browser.mainLoop.remainingBlockers) {
|
||
|
var remaining = Browser.mainLoop.remainingBlockers;
|
||
|
var next = remaining%1 == 0 ? remaining-1 : Math.floor(remaining);
|
||
|
if (blocker.counted) {
|
||
|
Browser.mainLoop.remainingBlockers = next;
|
||
|
} else {
|
||
|
// not counted, but move the progress along a tiny bit
|
||
|
next = next + 0.5; // do not steal all the next one's progress
|
||
|
Browser.mainLoop.remainingBlockers = (8*remaining + next)/9;
|
||
|
}
|
||
|
}
|
||
|
console.log('main loop blocker "' + blocker.name + '" took ' + (Date.now() - start) + ' ms'); //, left: ' + Browser.mainLoop.remainingBlockers);
|
||
|
Browser.mainLoop.updateStatus();
|
||
|
setTimeout(Browser.mainLoop.runner, 0);
|
||
|
return;
|
||
|
}
|
||
|
if (Browser.mainLoop.shouldPause) {
|
||
|
// catch pauses from non-main loop sources
|
||
|
Browser.mainLoop.paused = true;
|
||
|
Browser.mainLoop.shouldPause = false;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// Signal GL rendering layer that processing of a new frame is about to start. This helps it optimize
|
||
|
// VBO double-buffering and reduce GPU stalls.
|
||
|
|
||
|
if (Browser.mainLoop.method === 'timeout' && Module.ctx) {
|
||
|
Module.printErr('Looks like you are rendering without using requestAnimationFrame for the main loop. You should use 0 for the frame rate in emscripten_set_main_loop in order to use requestAnimationFrame, as that can greatly improve your frame rates!');
|
||
|
Browser.mainLoop.method = ''; // just warn once per call to set main loop
|
||
|
}
|
||
|
|
||
|
if (Module['preMainLoop']) {
|
||
|
Module['preMainLoop']();
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
if (typeof arg !== 'undefined') {
|
||
|
Runtime.dynCall('vi', func, [arg]);
|
||
|
} else {
|
||
|
Runtime.dynCall('v', func);
|
||
|
}
|
||
|
} catch (e) {
|
||
|
if (e instanceof ExitStatus) {
|
||
|
return;
|
||
|
} else {
|
||
|
if (e && typeof e === 'object' && e.stack) Module.printErr('exception thrown: ' + [e, e.stack]);
|
||
|
throw e;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (Module['postMainLoop']) {
|
||
|
Module['postMainLoop']();
|
||
|
}
|
||
|
|
||
|
if (Browser.mainLoop.shouldPause) {
|
||
|
// catch pauses from the main loop itself
|
||
|
Browser.mainLoop.paused = true;
|
||
|
Browser.mainLoop.shouldPause = false;
|
||
|
return;
|
||
|
}
|
||
|
Browser.mainLoop.scheduler();
|
||
|
}
|
||
|
if (fps && fps > 0) {
|
||
|
Browser.mainLoop.scheduler = function Browser_mainLoop_scheduler() {
|
||
|
setTimeout(Browser.mainLoop.runner, 1000/fps); // doing this each time means that on exception, we stop
|
||
|
};
|
||
|
Browser.mainLoop.method = 'timeout';
|
||
|
} else {
|
||
|
Browser.mainLoop.scheduler = function Browser_mainLoop_scheduler() {
|
||
|
Browser.requestAnimationFrame(Browser.mainLoop.runner);
|
||
|
};
|
||
|
Browser.mainLoop.method = 'rAF';
|
||
|
}
|
||
|
Browser.mainLoop.scheduler();
|
||
|
|
||
|
if (simulateInfiniteLoop) {
|
||
|
throw 'SimulateInfiniteLoop';
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
function _gmtime_r(time, tmPtr) {
|
||
|
var date = new Date(HEAP32[((time)>>2)]*1000);
|
||
|
HEAP32[((tmPtr)>>2)]=date.getUTCSeconds();
|
||
|
HEAP32[(((tmPtr)+(4))>>2)]=date.getUTCMinutes();
|
||
|
HEAP32[(((tmPtr)+(8))>>2)]=date.getUTCHours();
|
||
|
HEAP32[(((tmPtr)+(12))>>2)]=date.getUTCDate();
|
||
|
HEAP32[(((tmPtr)+(16))>>2)]=date.getUTCMonth();
|
||
|
HEAP32[(((tmPtr)+(20))>>2)]=date.getUTCFullYear()-1900;
|
||
|
HEAP32[(((tmPtr)+(24))>>2)]=date.getUTCDay();
|
||
|
HEAP32[(((tmPtr)+(36))>>2)]=0;
|
||
|
HEAP32[(((tmPtr)+(32))>>2)]=0;
|
||
|
var start = new Date(date); // define date using UTC, start from Jan 01 00:00:00 UTC
|
||
|
start.setUTCDate(1);
|
||
|
start.setUTCMonth(0);
|
||
|
start.setUTCHours(0);
|
||
|
start.setUTCMinutes(0);
|
||
|
start.setUTCSeconds(0);
|
||
|
start.setUTCMilliseconds(0);
|
||
|
var yday = Math.floor((date.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
|
||
|
HEAP32[(((tmPtr)+(28))>>2)]=yday;
|
||
|
HEAP32[(((tmPtr)+(40))>>2)]=___tm_timezone;
|
||
|
|
||
|
return tmPtr;
|
||
|
}function _gmtime(time) {
|
||
|
return _gmtime_r(time, ___tm_current);
|
||
|
}
|
||
|
|
||
|
function _symlink(path1, path2) {
|
||
|
// int symlink(const char *path1, const char *path2);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/symlink.html
|
||
|
path1 = Pointer_stringify(path1);
|
||
|
path2 = Pointer_stringify(path2);
|
||
|
try {
|
||
|
FS.symlink(path1, path2);
|
||
|
return 0;
|
||
|
} catch (e) {
|
||
|
FS.handleFSError(e);
|
||
|
return -1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
function _truncate(path, length) {
|
||
|
// int truncate(const char *path, off_t length);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/truncate.html
|
||
|
// NOTE: The path argument may be a string, to simplify ftruncate().
|
||
|
if (typeof path !== 'string') path = Pointer_stringify(path);
|
||
|
try {
|
||
|
FS.truncate(path, length);
|
||
|
return 0;
|
||
|
} catch (e) {
|
||
|
FS.handleFSError(e);
|
||
|
return -1;
|
||
|
}
|
||
|
}function _ftruncate(fildes, length) {
|
||
|
// int ftruncate(int fildes, off_t length);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/ftruncate.html
|
||
|
try {
|
||
|
FS.ftruncate(fildes, length);
|
||
|
return 0;
|
||
|
} catch (e) {
|
||
|
FS.handleFSError(e);
|
||
|
return -1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function _unlink(path) {
|
||
|
// int unlink(const char *path);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/unlink.html
|
||
|
path = Pointer_stringify(path);
|
||
|
try {
|
||
|
FS.unlink(path);
|
||
|
return 0;
|
||
|
} catch (e) {
|
||
|
FS.handleFSError(e);
|
||
|
return -1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function _puts(s) {
|
||
|
// int puts(const char *s);
|
||
|
// http://pubs.opengroup.org/onlinepubs/000095399/functions/puts.html
|
||
|
// NOTE: puts() always writes an extra newline.
|
||
|
var stdout = HEAP32[((_stdout)>>2)];
|
||
|
var ret = _fputs(s, stdout);
|
||
|
if (ret < 0) {
|
||
|
return ret;
|
||
|
} else {
|
||
|
var newlineRet = _fputc(10, stdout);
|
||
|
return (newlineRet < 0) ? -1 : ret + 1;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
function _SDL_LockSurface(surf) {
|
||
|
var surfData = SDL.surfaces[surf];
|
||
|
|
||
|
surfData.locked++;
|
||
|
if (surfData.locked > 1) return 0;
|
||
|
|
||
|
if (!surfData.buffer) {
|
||
|
surfData.buffer = _malloc(surfData.width * surfData.height * 4);
|
||
|
HEAP32[(((surf)+(20))>>2)]=surfData.buffer;
|
||
|
}
|
||
|
|
||
|
// Mark in C/C++-accessible SDL structure
|
||
|
// SDL_Surface has the following fields: Uint32 flags, SDL_PixelFormat *format; int w, h; Uint16 pitch; void *pixels; ...
|
||
|
// So we have fields all of the same size, and 5 of them before us.
|
||
|
// TODO: Use macros like in library.js
|
||
|
HEAP32[(((surf)+(20))>>2)]=surfData.buffer;
|
||
|
|
||
|
if (surf == SDL.screen && Module.screenIsReadOnly && surfData.image) return 0;
|
||
|
|
||
|
surfData.image = surfData.ctx.getImageData(0, 0, surfData.width, surfData.height);
|
||
|
if (surf == SDL.screen) {
|
||
|
var data = surfData.image.data;
|
||
|
var num = data.length;
|
||
|
for (var i = 0; i < num/4; i++) {
|
||
|
data[i*4+3] = 255; // opacity, as canvases blend alpha
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (SDL.defaults.copyOnLock) {
|
||
|
// Copy pixel data to somewhere accessible to 'C/C++'
|
||
|
if (surfData.isFlagSet(0x00200000 /* SDL_HWPALETTE */)) {
|
||
|
// If this is neaded then
|
||
|
// we should compact the data from 32bpp to 8bpp index.
|
||
|
// I think best way to implement this is use
|
||
|
// additional colorMap hash (color->index).
|
||
|
// Something like this:
|
||
|
//
|
||
|
// var size = surfData.width * surfData.height;
|
||
|
// var data = '';
|
||
|
// for (var i = 0; i<size; i++) {
|
||
|
// var color = SDL.translateRGBAToColor(
|
||
|
// surfData.image.data[i*4 ],
|
||
|
// surfData.image.data[i*4 +1],
|
||
|
// surfData.image.data[i*4 +2],
|
||
|
// 255);
|
||
|
// var index = surfData.colorMap[color];
|
||
|
// HEAP8[(((surfData.buffer)+(i))>>0)]=index;
|
||
|
// }
|
||
|
throw 'CopyOnLock is not supported for SDL_LockSurface with SDL_HWPALETTE flag set' + new Error().stack;
|
||
|
} else {
|
||
|
HEAPU8.set(surfData.image.data, surfData.buffer);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}function _SDL_UpperBlit(src, srcrect, dst, dstrect) {
|
||
|
var srcData = SDL.surfaces[src];
|
||
|
var dstData = SDL.surfaces[dst];
|
||
|
var sr, dr;
|
||
|
if (srcrect) {
|
||
|
sr = SDL.loadRect(srcrect);
|
||
|
} else {
|
||
|
sr = { x: 0, y: 0, w: srcData.width, h: srcData.height };
|
||
|
}
|
||
|
if (dstrect) {
|
||
|
dr = SDL.loadRect(dstrect);
|
||
|
} else {
|
||
|
dr = { x: 0, y: 0, w: -1, h: -1 };
|
||
|
}
|
||
|
var oldAlpha = dstData.ctx.globalAlpha;
|
||
|
dstData.ctx.globalAlpha = srcData.alpha/255;
|
||
|
dstData.ctx.drawImage(srcData.canvas, sr.x, sr.y, sr.w, sr.h, dr.x, dr.y, sr.w, sr.h);
|
||
|
dstData.ctx.globalAlpha = oldAlpha;
|
||
|
if (dst != SDL.screen) {
|
||
|
// XXX As in IMG_Load, for compatibility we write out |pixels|
|
||
|
Runtime.warnOnce('WARNING: copying canvas data to memory for compatibility');
|
||
|
_SDL_LockSurface(dst);
|
||
|
dstData.locked--; // The surface is not actually locked in this hack
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
Module["_strcpy"] = _strcpy;
|
||
|
|
||
|
function _SDL_FreeSurface(surf) {
|
||
|
if (surf) SDL.freeSurface(surf);
|
||
|
}
|
||
|
|
||
|
function _time(ptr) {
|
||
|
var ret = Math.floor(Date.now()/1000);
|
||
|
if (ptr) {
|
||
|
HEAP32[((ptr)>>2)]=ret;
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
function _SDL_WM_GrabInput() {}
|
||
|
|
||
|
|
||
|
|
||
|
FS.staticInit();__ATINIT__.unshift({ func: function() { if (!Module["noFSInit"] && !FS.init.initialized) FS.init() } });__ATMAIN__.push({ func: function() { FS.ignorePermissions = false } });__ATEXIT__.push({ func: function() { FS.quit() } });Module["FS_createFolder"] = FS.createFolder;Module["FS_createPath"] = FS.createPath;Module["FS_createDataFile"] = FS.createDataFile;Module["FS_createPreloadedFile"] = FS.createPreloadedFile;Module["FS_createLazyFile"] = FS.createLazyFile;Module["FS_createLink"] = FS.createLink;Module["FS_createDevice"] = FS.createDevice;
|
||
|
___errno_state = Runtime.staticAlloc(4); HEAP32[((___errno_state)>>2)]=0;
|
||
|
__ATINIT__.unshift({ func: function() { TTY.init() } });__ATEXIT__.push({ func: function() { TTY.shutdown() } });TTY.utf8 = new Runtime.UTF8Processor();
|
||
|
if (ENVIRONMENT_IS_NODE) { var fs = require("fs"); NODEFS.staticInit(); }
|
||
|
Module["requestFullScreen"] = function Module_requestFullScreen(lockPointer, resizeCanvas) { Browser.requestFullScreen(lockPointer, resizeCanvas) };
|
||
|
Module["requestAnimationFrame"] = function Module_requestAnimationFrame(func) { Browser.requestAnimationFrame(func) };
|
||
|
Module["setCanvasSize"] = function Module_setCanvasSize(width, height, noUpdates) { Browser.setCanvasSize(width, height, noUpdates) };
|
||
|
Module["pauseMainLoop"] = function Module_pauseMainLoop() { Browser.mainLoop.pause() };
|
||
|
Module["resumeMainLoop"] = function Module_resumeMainLoop() { Browser.mainLoop.resume() };
|
||
|
Module["getUserMedia"] = function Module_getUserMedia() { Browser.getUserMedia() }
|
||
|
__ATINIT__.push({ func: function() { SOCKFS.root = FS.mount(SOCKFS, {}, null); } });
|
||
|
_fputc.ret = allocate([0], "i8", ALLOC_STATIC);
|
||
|
_fgetc.ret = allocate([0], "i8", ALLOC_STATIC);
|
||
|
STACK_BASE = STACKTOP = Runtime.alignMemory(STATICTOP);
|
||
|
|
||
|
staticSealed = true; // seal the static portion of memory
|
||
|
|
||
|
STACK_MAX = STACK_BASE + 5242880;
|
||
|
|
||
|
DYNAMIC_BASE = DYNAMICTOP = Runtime.alignMemory(STACK_MAX);
|
||
|
|
||
|
assert(DYNAMIC_BASE < TOTAL_MEMORY, "TOTAL_MEMORY not big enough for stack");
|
||
|
|
||
|
var ctlz_i8 = allocate([8,7,6,6,5,5,5,5,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], "i8", ALLOC_DYNAMIC);
|
||
|
var cttz_i8 = allocate([8,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,7,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0], "i8", ALLOC_DYNAMIC);
|
||
|
|
||
|
var Math_min = Math.min;
|
||
|
function invoke_iiii(index,a1,a2,a3) {
|
||
|
try {
|
||
|
return Module["dynCall_iiii"](index,a1,a2,a3);
|
||
|
} catch(e) {
|
||
|
if (typeof e !== 'number' && e !== 'longjmp') throw e;
|
||
|
asm["setThrew"](1, 0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function invoke_viiiii(index,a1,a2,a3,a4,a5) {
|
||
|
try {
|
||
|
Module["dynCall_viiiii"](index,a1,a2,a3,a4,a5);
|
||
|
} catch(e) {
|
||
|
if (typeof e !== 'number' && e !== 'longjmp') throw e;
|
||
|
asm["setThrew"](1, 0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function invoke_vi(index,a1) {
|
||
|
try {
|
||
|
Module["dynCall_vi"](index,a1);
|
||
|
} catch(e) {
|
||
|
if (typeof e !== 'number' && e !== 'longjmp') throw e;
|
||
|
asm["setThrew"](1, 0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function invoke_vii(index,a1,a2) {
|
||
|
try {
|
||
|
Module["dynCall_vii"](index,a1,a2);
|
||
|
} catch(e) {
|
||
|
if (typeof e !== 'number' && e !== 'longjmp') throw e;
|
||
|
asm["setThrew"](1, 0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function invoke_ii(index,a1) {
|
||
|
try {
|
||
|
return Module["dynCall_ii"](index,a1);
|
||
|
} catch(e) {
|
||
|
if (typeof e !== 'number' && e !== 'longjmp') throw e;
|
||
|
asm["setThrew"](1, 0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function invoke_viii(index,a1,a2,a3) {
|
||
|
try {
|
||
|
Module["dynCall_viii"](index,a1,a2,a3);
|
||
|
} catch(e) {
|
||
|
if (typeof e !== 'number' && e !== 'longjmp') throw e;
|
||
|
asm["setThrew"](1, 0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function invoke_v(index) {
|
||
|
try {
|
||
|
Module["dynCall_v"](index);
|
||
|
} catch(e) {
|
||
|
if (typeof e !== 'number' && e !== 'longjmp') throw e;
|
||
|
asm["setThrew"](1, 0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function invoke_iiiii(index,a1,a2,a3,a4) {
|
||
|
try {
|
||
|
return Module["dynCall_iiiii"](index,a1,a2,a3,a4);
|
||
|
} catch(e) {
|
||
|
if (typeof e !== 'number' && e !== 'longjmp') throw e;
|
||
|
asm["setThrew"](1, 0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function invoke_iii(index,a1,a2) {
|
||
|
try {
|
||
|
return Module["dynCall_iii"](index,a1,a2);
|
||
|
} catch(e) {
|
||
|
if (typeof e !== 'number' && e !== 'longjmp') throw e;
|
||
|
asm["setThrew"](1, 0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function invoke_iiiiii(index,a1,a2,a3,a4,a5) {
|
||
|
try {
|
||
|
return Module["dynCall_iiiiii"](index,a1,a2,a3,a4,a5);
|
||
|
} catch(e) {
|
||
|
if (typeof e !== 'number' && e !== 'longjmp') throw e;
|
||
|
asm["setThrew"](1, 0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function invoke_viiii(index,a1,a2,a3,a4) {
|
||
|
try {
|
||
|
Module["dynCall_viiii"](index,a1,a2,a3,a4);
|
||
|
} catch(e) {
|
||
|
if (typeof e !== 'number' && e !== 'longjmp') throw e;
|
||
|
asm["setThrew"](1, 0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function asmPrintInt(x, y) {
|
||
|
Module.print('int ' + x + ',' + y);// + ' ' + new Error().stack);
|
||
|
}
|
||
|
function asmPrintFloat(x, y) {
|
||
|
Module.print('float ' + x + ',' + y);// + ' ' + new Error().stack);
|
||
|
}
|
||
|
// EMSCRIPTEN_START_ASM
|
||
|
var asm=(function(global,env,buffer){"use asm";var a=new global.Int8Array(buffer);var b=new global.Int16Array(buffer);var c=new global.Int32Array(buffer);var d=new global.Uint8Array(buffer);var e=new global.Uint16Array(buffer);var f=new global.Uint32Array(buffer);var g=new global.Float32Array(buffer);var h=new global.Float64Array(buffer);var i=env.STACKTOP|0;var j=env.STACK_MAX|0;var k=env.tempDoublePtr|0;var l=env.ABORT|0;var m=env.cttz_i8|0;var n=env.ctlz_i8|0;var o=env._stderr|0;var p=env._stdin|0;var q=env._stdout|0;var r=0;var s=0;var t=0;var u=0;var v=+env.NaN,w=+env.Infinity;var x=0,y=0,z=0,A=0,B=0.0,C=0,D=0,E=0,F=0.0;var G=0;var H=0;var I=0;var J=0;var K=0;var L=0;var M=0;var N=0;var O=0;var P=0;var Q=global.Math.floor;var R=global.Math.abs;var S=global.Math.sqrt;var T=global.Math.pow;var U=global.Math.cos;var V=global.Math.sin;var W=global.Math.tan;var X=global.Math.acos;var Y=global.Math.asin;var Z=global.Math.atan;var _=global.Math.atan2;var $=global.Math.exp;var aa=global.Math.log;var ba=global.Math.ceil;var ca=global.Math.imul;var da=env.abort;var ea=env.assert;var fa=env.asmPrintInt;var ga=env.asmPrintFloat;var ha=env.min;var ia=env.invoke_iiii;var ja=env.invoke_viiiii;var ka=env.invoke_vi;var la=env.invoke_vii;var ma=env.invoke_ii;var na=env.invoke_viii;var oa=env.invoke_v;var pa=env.invoke_iiiii;var qa=env.invoke_iii;var ra=env.invoke_iiiiii;var sa=env.invoke_viiii;var ta=env._fread;var ua=env._SDL_PauseAudio;var va=env._atexit;var wa=env._truncate;var xa=env._fsync;var ya=env._SDL_GetError;var za=env._signal;var Aa=env._sbrk;var Ba=env._SDL_OpenAudio;var Ca=env._SDL_FreeSurface;var Da=env._emscripten_memcpy_big;var Ea=env._tcgetattr;var Fa=env._sysconf;var Ga=env._close;var Ha=env._SDL_InitSubSystem;var Ia=env._posix_openpt;var Ja=env._puts;var Ka=env._write;var La=env._ftell;var Ma=env._gmtime_r;var Na=env._SDL_WM_SetCaption;var Oa=env._SDL_WasInit;var Pa=env._send;var Qa=env._SDL_CreateRGBSurfaceFrom;var Ra=env._SDL_GetTicks;var Sa=env._fcntl;var Ta=env._SDL_LockAudio;var Ua=env._SDL_LockSurface;var Va=env._strtol;var Wa=env.___setErrNo;var Xa=env._grantpt;var Ya=env._unlink;var Za=env._nanosleep;var _a=env._gmtime;var $a=env._printf;var ab=env._sprintf;var bb=env._poll;var cb=env._localtime;var db=env._read;var eb=env._SDL_SetVideoMode;var fb=env._fwrite;var gb=env._time;var hb=env._fprintf;var ib=env._gettimeofday;var jb=env._ptsname;var kb=env._exit;var lb=env._SDL_ShowCursor;var mb=env._lseek;var nb=env._vfprintf;var ob=env._pwrite;var pb=env._unlockpt;var qb=env._localtime_r;var rb=env._tzset;var sb=env._open;var tb=env._SDL_Init;var ub=env._SDL_WM_GrabInput;var vb=env._snprintf;var wb=env._ftruncate;var xb=env._fseek;var yb=env._SDL_GetMouseState;var zb=env._fclose;var Ab=env.__parseInt;var Bb=env._recv;var Cb=env._tan;var Db=env._symlink;var Eb=env._abort;var Fb=env._SDL_Flip;var Gb=env._isspace;var Hb=env._strtoul;var Ib=env._fopen;var Jb=env._SDL_UnlockAudio;var Kb=env._tcflush;var Lb=env._SDL_CloseAudio;var Mb=env._usleep;var Nb=env._fflush;var Ob=env._SDL_GetVideoInfo;var Pb=env.__reallyNegative;var Qb=env._SDL_PollEvent;var Rb=env._fileno;var Sb=env.__exit;var Tb=env._tcsetattr;var Ub=env._fputs;var Vb=env._SDL_EventState;var Wb=env._pread;var Xb=env._mkport;var Yb=env._emscripten_set_main_loop;var Zb=env.___errno_location;var _b=env._fgetc;var $b=env._fputc;var ac=env._emscripten_cancel_main_loop;var bc=env.__formatString;var cc=env._SDL_WM_ToggleFullScreen;var dc=env._SDL_UpperBlit;var ec=env._SDL_EnableKeyRepeat;var fc=0.0;
|
||
|
// EMSCRIPTEN_START_FUNCS
|
||
|
function Vg(b,e){b=b|0;e=e|0;var f=0,g=0,h=0;f=i;i=i+16|0;g=f;h=b+32|0;a[h+0>>0]=a[37464>>0]|0;a[h+1>>0]=a[37465>>0]|0;a[h+2>>0]=a[37466>>0]|0;a[h+3>>0]=a[37467>>0]|0;a[h+4>>0]=a[37468>>0]|0;c[b+28>>2]=2;h=d[e+3>>0]|0;c[g>>2]=35704;c[g+4>>2]=h;ab(b+96|0,35352,g|0)|0;g=b+8|0;c[g>>2]=(c[g>>2]|0)+1;kj(b,b+160|0,e,a[e+1>>0]&63,8);i=f;return}function Wg(b,e){b=b|0;e=e|0;var f=0,g=0,h=0;f=i;i=i+16|0;g=f;h=b+32|0;a[h+0>>0]=a[37456>>0]|0;a[h+1>>0]=a[37457>>0]|0;a[h+2>>0]=a[37458>>0]|0;a[h+3>>0]=a[37459>>0]|0;a[h+4>>0]=a[37460>>0]|0;c[b+28>>2]=2;h=d[e+3>>0]|0;c[g>>2]=35704;c[g+4>>2]=h;ab(b+96|0,35352,g|0)|0;g=b+8|0;c[g>>2]=(c[g>>2]|0)+1;kj(b,b+160|0,e,a[e+1>>0]&63,8);i=f;return}function Xg(b,e){b=b|0;e=e|0;var f=0,g=0,h=0;f=i;i=i+16|0;g=f;h=b+32|0;a[h+0>>0]=a[37448>>0]|0;a[h+1>>0]=a[37449>>0]|0;a[h+2>>0]=a[37450>>0]|0;a[h+3>>0]=a[37451>>0]|0;a[h+4>>0]=a[37452>>0]|0;c[b+28>>2]=2;h=d[e+3>>0]|0;c[g>>2]=35704;c[g+4>>2]=h;ab(b+96|0,35352,g|0)|0;g=b+8|0;c[g>>2]=(c[g>>2]|0)+1;kj(b,b+160|0,e,a[e+1>>0]&63,8);i=f;return}function Yg(b,e){b=b|0;e=e|0;var f=0,g=0,h=0;f=i;i=i+16|0;g=f;h=b+32|0;a[h+0>>0]=a[37440>>0]|0;a[h+1>>0]=a[37441>>0]|0;a[h+2>>0]=a[37442>>0]|0;a[h+3>>0]=a[37443>>0]|0;a[h+4>>0]=a[37444>>0]|0;c[b+28>>2]=2;h=d[e+3>>0]|0;c[g>>2]=35704;c[g+4>>2]=h;ab(b+96|0,35352,g|0)|0;g=b+8|0;c[g>>2]=(c[g>>2]|0)+1;kj(b,b+160|0,e,a[e+1>>0]&63,8);i=f;return}function Zg(e,f){e=e|0;f=f|0;var g=0,h=0,j=0,k=0;g=i;i=i+16|0;h=g;j=(b[e+12>>1]&63)==60;k=e+32|0;a[k+0>>0]=a[37432>>0]|0;a[k+1>>0]=a[37433>>0]|0;a[k+2>>0]=a[37434>>0]|0;a[k+3>>0]=a[37435>>0]|0;a[k+4>>0]=a[37436>>0]|0;a[k+5>>0]=a[37437>>0]|0;a[k+6>>0]=a[37438>>0]|0;c[e+28>>2]=2;k=d[f+3>>0]|0;c[h>>2]=35704;c[h+4>>2]=k;ab(e+96|0,35352,h|0)|0;h=e+8|0;c[h>>2]=(c[h>>2]|0)+1;h=e+160|0;if(j){a[h>>0]=5391171;a[h+1>>0]=21059;a[h+2>>0]=82;a[h+3>>0]=0;i=g;return}else{kj(e,h,f,a[f+1>>0]&63,8);i=g;return}}function _g(e,f){e=e|0;f=f|0;var g=0,h=0,j=0,k=0;g=i;i=i+16|0;h=g;j=(b[e+12>>1]&63)==60;k=e+32|0;a[k+0>>0]=a[37424>>0]|0;a[k+1>>0]=a[37425>>0]|0;a[k+2>>0]=a[37426>>0]|0;a[k+3>>0]=a[37427>>0]|0;a[k+4>>0]=a[37428>>0]|0;a[k+5>>0]=a[37429>>0]|0;a[k+6>>0]=a[37430>>0]|0;c[e+28>>2]=2;k=(d[f+2>>0]|0)<<8|(d[f+3>>0]|0);c[h>>2]=35704;c[h+4>>2]=k;ab(e+96|0,35256,h|0)|0;h=e+8|0;c[h>>2]=(c[h>>2]|0)+1;h=e+160|0;if(j){a[h+0>>0]=a[35392>>0]|0;a[h+1>>0]=a[35393>>0]|0;a[h+2>>0]=a[35394>>0]|0;c[e>>2]=c[e>>2]|1;i=g;return}else{kj(e,h,f,a[f+1>>0]&63,16);i=g;return}}function $g(b,e){b=b|0;e=e|0;var f=0,g=0,h=0;f=i;i=i+16|0;g=f;h=b+32|0;a[h+0>>0]=a[37416>>0]|0;a[h+1>>0]=a[37417>>0]|0;a[h+2>>0]=a[37418>>0]|0;a[h+3>>0]=a[37419>>0]|0;a[h+4>>0]=a[37420>>0]|0;a[h+5>>0]=a[37421>>0]|0;a[h+6>>0]=a[37422>>0]|0;c[b+28>>2]=2;h=(((d[e+2>>0]|0)<<8|(d[e+3>>0]|0))<<8|(d[e+4>>0]|0))<<8|(d[e+5>>0]|0);c[g>>2]=35704;c[g+4>>2]=h;ab(b+96|0,35360,g|0)|0;g=b+8|0;c[g>>2]=(c[g>>2]|0)+2;kj(b,b+160|0,e,a[e+1>>0]&63,32);i=f;return}function ah(b,e){b=b|0;e=e|0;var f=0,g=0,h=0;f=i;i=i+16|0;g=f;h=b+32|0;a[h+0>>0]=a[37408>>0]|0;a[h+1>>0]=a[37409>>0]|0;a[h+2>>0]=a[37410>>0]|0;a[h+3>>0]=a[37411>>0]|0;a[h+4>>0]=a[37412>>0]|0;a[h+5>>0]=a[37413>>0]|0;a[h+6>>0]=a[37414>>0]|0;c[b+28>>2]=2;h=d[e+3>>0]|0;c[g>>2]=35704;c[g+4>>2]=h;ab(b+96|0,35352,g|0)|0;g=b+8|0;c[g>>2]=(c[g>>2]|0)+1;kj(b,b+160|0,e,a[e+1>>0]&63,8);i=f;return}function bh(b,e){b=b|0;e=e|0;var f=0,g=0,h=0;f=i;i=i+16|0;g=f;h=b+32|0;a[h+0>>0]=a[37400>>0]|0;a[h+1>>0]=a[37401>>0]|0;a[h+2>>0]=a[37402>>0]|0;a[h+3>>0]=a[37403>>0]|0;a[h+4>>0]=a[37404>>0]|0;a[h+5>>0]=a[37405>>0]|0;a[h+6>>0]=a[37406>>0]|0;c[b+28>>2]=2;h=(d[e+2>>0]|0)<<8|(d[e+3>>0]|0);c[g>>2]=35704;c[g+4>>2]=h;ab(b+96|0,35256,g|0)|0;g=b+8|0;c[g>>2]=(c[g>>2]|0)+1;kj(b,b+160|0,e,a[e+1>>0]&63,16);i=f;return}function ch(b,e){b=b|0;e=e|0;var f=0,g=0,h=0;f=i;i=i+16|0;g=f;h=b+32|0;a[h+0>>0]=a[37392>>0]|0;a[h+1>>0]=a[37393>>0]|0;a[h+2>>0]=a[37394>>0]|0;a[h+3>>0]=a[37395>>0]|0;a[h+4>>0]=a[37396>>0]|0;a[h+5>>0]=a[37397>>0]|0;a[h+6>>0]=a[37398>>0]|0;c[b+28>>2]=2;h=(((d[e+2>>0]|0)<<8|(d[e+3>>0]|0))<<8|(d[e+4>>0]|0))<<8|(d[e+5>>0]|0);c[g>>2]=35704;c[g+4>>2]=h;ab(b+96|0,35360,g|0)|0;g=b+8|0;c[g>>2]=(c[g>>2]|0)+2;kj(b,b+160|0,e,a[e+1>>0]&63,32);i=f;return}function
|
||
|
|
||
|
|
||
|
|
||
|
function rc(a){a=a|0;var b=0;b=i;i=i+a|0;i=i+7&-8;return b|0}function sc(){return i|0}function tc(a){a=a|0;i=a}function uc(a,b){a=a|0;b=b|0;if((r|0)==0){r=a;s=b}}function vc(b){b=b|0;a[k>>0]=a[b>>0];a[k+1>>0]=a[b+1>>0];a[k+2>>0]=a[b+2>>0];a[k+3>>0]=a[b+3>>0]}function wc(b){b=b|0;a[k>>0]=a[b>>0];a[k+1>>0]=a[b+1>>0];a[k+2>>0]=a[b+2>>0];a[k+3>>0]=a[b+3>>0];a[k+4>>0]=a[b+4>>0];a[k+5>>0]=a[b+5>>0];a[k+6>>0]=a[b+6>>0];a[k+7>>0]=a[b+7>>0]}function xc(a){a=a|0;G=a}function yc(){return G|0}function zc(b){b=b|0;var e=0,f=0,g=0,h=0,j=0;h=i;f=a[b+5>>0]|0;a[b+4>>0]=f;g=b+20|0;j=b+7|0;e=j+13|0;do{a[j>>0]=0;j=j+1|0}while((j|0)<(e|0));c[g>>2]=(f&255)<<8&3840|(d[b+6>>0]|0)|24576;i=h;return}function Ac(b){b=b|0;a[b+7>>0]=0;return}function Bc(b,d,e){b=b|0;d=d|0;e=e|0;var f=0;f=i;if((d|0)!=3){d=0;i=f;return d|0}d=b+20|0;a[e+1>>0]=c[d>>2];a[e>>0]=(c[d>>2]|0)>>>8;d=2;i=f;return d|0}function Cc(a,b){a=a|0;b=b|0;return}function Dc(b,d,e,f){b=b|0;d=d|0;e=e|0;f=f|0;var g=0;g=i;if((d|0)!=3|f>>>0<2){i=g;return}if(!((a[e+1>>0]|0)==-2)){i=g;return}f=a[e>>0]&15;a[b+4>>0]=f;d=b+20|0;c[d>>2]=f<<8|c[d>>2]&61695;i=g;return}function Ec(b,d,e){b=b|0;d=d|0;e=e|0;var f=0,g=0,h=0,j=0;h=i;c[b>>2]=0;g=d&255;a[b+4>>0]=g;a[b+5>>0]=g;a[b+6>>0]=e;g=b+20|0;j=b+7|0;f=j+13|0;do{a[j>>0]=0;j=j+1|0}while((j|0)<(f|0));c[g>>2]=d<<8&3840|e&255|24576;c[b+24>>2]=0;c[b+28>>2]=208;c[b+32>>2]=209;c[b+36>>2]=23;c[b+40>>2]=145;c[b+44>>2]=1;i=h;return}function Fc(){var b=0,d=0,e=0,f=0,g=0;b=i;d=yz(120)|0;if((d|0)==0){g=0;i=b;return g|0}a[d>>0]=3;e=d+1|0;g=d+14|0;f=d+92|0;c[d+112>>2]=0;c[d+116>>2]=0;a[e+0>>0]=0;a[e+1>>0]=0;a[e+2>>0]=0;a[e+3>>0]=0;a[e+4>>0]=0;g=g+0|0;e=g+14|0;do{a[g>>0]=0;g=g+1|0}while((g|0)<(e|0));c[f+0>>2]=0;c[f+4>>2]=0;c[f+8>>2]=0;c[f+12>>2]=0;a[f+16>>0]=0;g=d;i=b;return g|0}function Gc(a,b,d){a=a|0;b=b|0;d=d|0;c[a+92>>2]=b;c[a+96>>2]=d;return}function Hc(a,b,d){a=a|0;b=b|0;d=d|0;c[a+100>>2]=b;c[a+104>>2]=d;return}function Ic(a,b,d){a=a|0;b=b|0;d=d|0;c[a+112>>2]=b;c[a+116>>2]=d;return}function Jc(a,b){a=a|0;b=b|0;var d=0,e=0,f=0,g=0,h=0,j=0;d=i;f=a+24|0;g=c[f>>2]|0;if((g|0)!=0){h=0;do{j=h;h=h+1|0;if((c[a+(j<<2)+28>>2]|0)==(b|0)){f=1;e=6;break}}while(h>>>0<g>>>0);if((e|0)==6){i=d;return f|0}if(g>>>0>15){j=1;i=d;return j|0}}else{g=0}c[f>>2]=g+1;c[a+(g<<2)+28>>2]=b;j=0;i=d;return j|0}function Kc(b){b=b|0;var d=0,e=0,f=0,g=0;d=i;e=b+24|0;if((c[e>>2]|0)!=0){f=0;do{g=c[b+(f<<2)+28>>2]|0;ic[c[g+28>>2]&511](g);f=f+1|0}while(f>>>0<(c[e>>2]|0)>>>0)}a[b>>0]=3;a[b+1>>0]=1;g=b+2|0;f=b+108|0;a[g>>0]=0;a[g+1>>0]=0;a[g+2>>0]=0;a[g+3>>0]=0;g=b+14|0;e=g+10|0;do{a[g>>0]=0;g=g+1|0}while((g|0)<(e|0));if((a[f>>0]|0)==0){i=d;return}a[f>>0]=0;e=c[b+116>>2]|0;if((e|0)==0){i=d;return}jc[e&255](c[b+112>>2]|0,0);i=d;return}function Lc(b,e){b=b|0;e=e|0;var f=0,g=0,h=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;f=i;e=e&3;n=e&255;if((d[b>>0]|0)==(e|0)){i=f;return}p=b+16|0;c[p>>2]=(c[p>>2]|0)+783;a:do{if((((e|0)==0|(e|0)==3?(m=a[b+5>>0]|0,(d[b+4>>0]|0)<(m&255)):0)?(o=a[b+2>>0]|0,(o&12)==8):0)?(a[b+1>>0]=0,k=o&255,j=k>>>4,l=c[b+24>>2]|0,(l|0)!=0):0){o=0;while(1){p=c[b+(o<<2)+28>>2]|0;o=o+1|0;if((d[p+4>>0]|0)==(j|0)){break}if(!(o>>>0<l>>>0)){break a}}if((p|0)!=0){qc[c[p+44>>2]&3](p,k&3,b+6|0,m&255)}}}while(0);a[b>>0]=n;j=b+108|0;if((a[j>>0]|0)!=0?(a[j>>0]=0,h=c[b+116>>2]|0,(h|0)!=0):0){jc[h&255](c[b+112>>2]|0,0)}if((e|0)==0){a[b+1>>0]=0;a[b+4>>0]=0;a[b+5>>0]=0;a[b+14>>0]=8;a[b+15>>0]=0;i=f;return}else if((e|0)==2|(e|0)==1){if((a[b+1>>0]|0)==0){a[b+14>>0]=8;a[b+15>>0]=0;i=f;return}k=b+4|0;l=a[k>>0]|0;h=a[b+5>>0]|0;a[b+14>>0]=8;if(!((l&255)<(h&255))){a[b+15>>0]=-86;if((a[j>>0]|0)==1){i=f;return}a[j>>0]=1;g=c[b+116>>2]|0;if((g|0)==0){i=f;return}jc[g&255](c[b+112>>2]|0,1);i=f;return}p=l+1<<24>>24;a[k>>0]=p;a[b+15>>0]=a[b+(l&255)+6>>0]|0;if((p&255)<(h&255)){i=f;return}l=d[b+2>>0]|0;j=l>>>4;k=c[b+24>>2]|0;if((k|0)==0){i=f;return}else{e=0}while(1){h=c[b+(e<<2)+28>>2]|0;e=e+1|0;if((d[h+4>>0]|0)==(j|0)){break}if(!(e>>>0<k>>>0)){g=28;break}}if((g|0)==28){i=f;return}if((h|0)==0){i=f;return}jc[c[h+40>>2]&255](h,l&3);i=f;return}else if((e|0)==3){a[b+1>>0]=1;a[b+4>>0]=0;a[b+5>>0]=0;a[b+14>>0]=0;a[b+15>>0]=0;c[b+20>>2]=0;i=f;r
|
||
|
|
||
|
|
||
|
|
||
|
function lw(b,d,e){b=b|0;d=d|0;e=e|0;var f=0,g=0,h=0,j=0,k=0,l=0,m=0,n=0;f=i;i=i+16|0;g=f;h=c[b>>2]|0;if((mw(b,d,e)|0)==0){n=0;i=f;return n|0}a:while(1){k=c[b>>2]|0;while(1){n=a[b+k+4>>0]|0;if(!(n<<24>>24==10|n<<24>>24==9|n<<24>>24==32|n<<24>>24==13)){break}k=k+1|0}c[b>>2]=k;j=55344;m=60;l=k;while(1){if(!((a[b+l+4>>0]|0)==m<<24>>24)){j=9;break}l=l+1|0;j=j+1|0;m=a[j>>0]|0;if(m<<24>>24==0){j=8;break}}do{if((j|0)==8){j=0;c[b>>2]=l;k=1}else if((j|0)==9){while(1){j=0;n=a[b+k+4>>0]|0;if(!(n<<24>>24==10|n<<24>>24==9|n<<24>>24==32|n<<24>>24==13)){break}k=k+1|0;j=9}c[b>>2]=k;if((a[b+k+4>>0]|0)==60){c[b>>2]=k+1;k=2;break}while(1){n=a[b+k+4>>0]|0;if(!(n<<24>>24==10|n<<24>>24==9|n<<24>>24==32|n<<24>>24==13)){break}k=k+1|0}c[b>>2]=k;l=55352;n=62;m=k;while(1){if(!((a[b+m+4>>0]|0)==n<<24>>24)){break}m=m+1|0;l=l+1|0;n=a[l>>0]|0;if(n<<24>>24==0){j=18;break}}if((j|0)==18){j=0;c[b>>2]=m;k=3;break}while(1){n=a[b+k+4>>0]|0;if(!(n<<24>>24==10|n<<24>>24==9|n<<24>>24==32|n<<24>>24==13)){break}k=k+1|0}c[b>>2]=k;if((a[b+k+4>>0]|0)!=62){b=1;j=30;break a}c[b>>2]=k+1;k=4}}while(0);if((mw(b,g,e)|0)==0){break}if((k|0)==1){c[d>>2]=(c[d>>2]|0)>>>0<=(c[g>>2]|0)>>>0;continue}else if((k|0)==3){c[d>>2]=(c[d>>2]|0)>>>0>=(c[g>>2]|0)>>>0;continue}else if((k|0)==4){c[d>>2]=(c[d>>2]|0)>>>0>(c[g>>2]|0)>>>0;continue}else if((k|0)==2){c[d>>2]=(c[d>>2]|0)>>>0<(c[g>>2]|0)>>>0;continue}else{continue}}if((j|0)==30){i=f;return b|0}c[b>>2]=h;n=0;i=f;return n|0}function mw(b,d,e){b=b|0;d=d|0;e=e|0;var f=0,g=0,h=0,j=0,k=0,l=0,m=0,n=0,o=0;f=i;i=i+16|0;m=f+8|0;h=f+4|0;g=f;j=c[b>>2]|0;if((nw(b,d,e)|0)==0){o=0;i=f;return o|0}while(1){l=c[b>>2]|0;while(1){o=a[b+l+4>>0]|0;if(!(o<<24>>24==10|o<<24>>24==9|o<<24>>24==32|o<<24>>24==13)){break}l=l+1|0}c[b>>2]=l;if((a[b+l+4>>0]|0)!=43){while(1){o=a[b+l+4>>0]|0;if(!(o<<24>>24==10|o<<24>>24==9|o<<24>>24==32|o<<24>>24==13)){break}l=l+1|0}c[b>>2]=l;if((a[b+l+4>>0]|0)==45){n=2}else{break}}else{n=1}c[b>>2]=l+1;if((nw(b,m,e)|0)==0){k=11;break}l=c[m>>2]|0;c[d>>2]=(c[d>>2]|0)+((n|0)==1?l:0-l|0)}if((k|0)==11){c[b>>2]=j;o=0;i=f;return o|0}a:while(1){o=a[b+l+4>>0]|0;if(o<<24>>24==10|o<<24>>24==9|o<<24>>24==32|o<<24>>24==13){l=l+1|0;continue}c[b>>2]=l;k=55360;n=60;m=l;while(1){if(!((a[b+m+4>>0]|0)==n<<24>>24)){k=19;break}m=m+1|0;k=k+1|0;n=a[k>>0]|0;if(n<<24>>24==0){k=18;break}}do{if((k|0)==18){k=0;c[b>>2]=m;l=1}else if((k|0)==19){while(1){k=0;o=a[b+l+4>>0]|0;if(!(o<<24>>24==10|o<<24>>24==9|o<<24>>24==32|o<<24>>24==13)){break}l=l+1|0;k=19}c[b>>2]=l;n=55368;o=62;m=l;while(1){if(!((a[b+m+4>>0]|0)==o<<24>>24)){break}m=m+1|0;n=n+1|0;o=a[n>>0]|0;if(o<<24>>24==0){k=24;break}}if((k|0)==24){k=0;c[b>>2]=m;l=2;break}while(1){o=a[b+l+4>>0]|0;if(!(o<<24>>24==10|o<<24>>24==9|o<<24>>24==32|o<<24>>24==13)){break}l=l+1|0}c[b>>2]=l;n=55376;o=60;m=l;while(1){if(!((a[b+m+4>>0]|0)==o<<24>>24)){break}m=m+1|0;n=n+1|0;o=a[n>>0]|0;if(o<<24>>24==0){k=30;break}}if((k|0)==30){k=0;c[b>>2]=m;l=3;break}while(1){o=a[b+l+4>>0]|0;if(!(o<<24>>24==10|o<<24>>24==9|o<<24>>24==32|o<<24>>24==13)){break}l=l+1|0}c[b>>2]=l;n=55384;m=62;do{if(!((a[b+l+4>>0]|0)==m<<24>>24)){b=1;k=54;break a}l=l+1|0;n=n+1|0;m=a[n>>0]|0}while(!(m<<24>>24==0));c[b>>2]=l;m=l;l=4}}while(0);if((nw(b,g,e)|0)==0){break}while(1){n=c[b>>2]|0;while(1){o=a[b+n+4>>0]|0;if(!(o<<24>>24==10|o<<24>>24==9|o<<24>>24==32|o<<24>>24==13)){break}n=n+1|0}c[b>>2]=n;if((a[b+n+4>>0]|0)!=43){while(1){o=a[b+n+4>>0]|0;if(!(o<<24>>24==10|o<<24>>24==9|o<<24>>24==32|o<<24>>24==13)){break}n=n+1|0}c[b>>2]=n;if((a[b+n+4>>0]|0)==45){k=2}else{break}}else{k=1}c[b>>2]=n+1;if((nw(b,h,e)|0)==0){k=46;break a}n=c[h>>2]|0;c[g>>2]=(c[g>>2]|0)+((k|0)==1?n:0-n|0)}k=c[g>>2]&31;c[g>>2]=k;if((l|0)==1){l=c[d>>2]|0;c[d>>2]=l<<k|l>>>(32-k|0);l=n;continue}else if((l|0)==2){l=c[d>>2]|0;c[d>>2]=l>>>k|l<<32-k;l=n;continue}else if((l|0)==4){c[d>>2]=(c[d>>2]|0)>>>k;l=n;continue}else if((l|0)==3){c[d>>2]=c[d>>2]<<k;l=n;continue}else{l=n;continue}}if((k|0)==46){c[b>>2]=m}else if((k|0)==54){i=f;return b|0}c[b>>2]=j;o=0;i=f;return o|0}function nw(b,d,e){b=b|0;d=d|0;e=e|0;var f=0,g=0,h=0,j=0,k=0,l=0,m=0;g=i;i=i+16|0;j=g;h=c[b>>2]|0;if((ow(b,d,e)|0)==0){m=0;i=g;return m|0
|
||
|
|
||
|
|
||
|
|
||
|
function $m(f){f=f|0;var g=0,h=0,j=0,k=0,l=0,m=0,n=0;g=i;i=i+16|0;h=g;m=b[f+160>>1]&63;if((nc[c[46024+(m<<2)>>2]&63](f,m,508,16)|0)!=0){i=g;return}if((Ko(f,h)|0)!=0){i=g;return}h=e[h>>1]|0;m=h>>>15;h=(h<<1|m)&65535;k=f+372|0;c[k>>2]=(c[k>>2]|0)+8;co(f,14,h);k=f+166|0;j=e[k>>1]|0;b[k>>1]=(m|0)==0?j&65534:j|1;k=f+156|0;l=c[k>>2]|0;if((l&1|0)!=0){Mj(f,l,0,0);i=g;return}j=f+164|0;b[f+162>>1]=b[j>>1]|0;l=l&16777215;m=l+1|0;if(m>>>0<(c[f+36>>2]|0)>>>0){n=c[f+32>>2]|0;l=(d[n+l>>0]<<8|d[n+m>>0])&65535}else{l=oc[c[f+12>>2]&31](c[f+4>>2]|0,l)|0}b[j>>1]=l;if((a[f+336>>0]|0)==0){c[k>>2]=(c[k>>2]|0)+2;n=f+152|0;c[n>>2]=(c[n>>2]|0)+2;No(f,h)|0;i=g;return}else{Kj(f);i=g;return}}function an(a){a=a|0;var c=0;c=i;b[a+330>>1]=b[a+160>>1]|0;Tj(a);i=c;return}function bn(f,g){f=f|0;g=g|0;var h=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0;h=i;j=f+152|0;l=(c[j>>2]|0)+2|0;k=f+160|0;m=e[k>>1]|0;m=(m&128|0)!=0?m|-256:m&255;do{if((m|0)==0){m=f+156|0;p=c[m>>2]|0;if((p&1|0)!=0){Mj(f,p,0,0);i=h;return}o=f+164|0;n=f+162|0;b[n>>1]=b[o>>1]|0;p=p&16777215;q=p+1|0;if(q>>>0<(c[f+36>>2]|0)>>>0){r=c[f+32>>2]|0;p=(d[r+p>>0]<<8|d[r+q>>0])&65535}else{p=oc[c[f+12>>2]&31](c[f+4>>2]|0,p)|0}b[o>>1]=p;if((a[f+336>>0]|0)==0){c[m>>2]=(c[m>>2]|0)+2;c[j>>2]=(c[j>>2]|0)+2;m=e[n>>1]|0;m=(m&32768|0)!=0?m|-65536:m;break}Kj(f);i=h;return}}while(0);do{if((g|0)==0){g=f+372|0;c[g>>2]=((b[k>>1]&255)==0?12:8)+(c[g>>2]|0);l=c[f+156>>2]|0}else{k=f+372|0;c[k>>2]=(c[k>>2]|0)+10;l=l+m|0;k=f+156|0;c[k>>2]=l;if((l&1|0)!=0){Mj(f,l,0,0);i=h;return}g=f+164|0;b[f+162>>1]=b[g>>1]|0;m=l&16777215;l=m+1|0;if(l>>>0<(c[f+36>>2]|0)>>>0){r=c[f+32>>2]|0;l=(d[r+m>>0]<<8|d[r+l>>0])&65535}else{l=oc[c[f+12>>2]&31](c[f+4>>2]|0,m)|0}b[g>>1]=l;if((a[f+336>>0]|0)==0){l=(c[k>>2]|0)+2|0;c[k>>2]=l;c[j>>2]=(c[j>>2]|0)+2;break}Kj(f);i=h;return}}while(0);k=f+156|0;if((l&1|0)!=0){Mj(f,l,0,0);i=h;return}g=f+164|0;b[f+162>>1]=b[g>>1]|0;l=l&16777215;m=l+1|0;if(m>>>0<(c[f+36>>2]|0)>>>0){r=c[f+32>>2]|0;l=(d[r+l>>0]<<8|d[r+m>>0])&65535}else{l=oc[c[f+12>>2]&31](c[f+4>>2]|0,l)|0}b[g>>1]=l;if((a[f+336>>0]|0)==0){r=c[k>>2]|0;c[k>>2]=r+2;c[j>>2]=r+ -2;i=h;return}else{Kj(f);i=h;return}}function cn(e,f){e=e|0;f=f|0;var g=0,h=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;g=i;h=b[e+160>>1]&7;do{if((h|0)==2){h=e+156|0;k=c[h>>2]|0;if((k&1|0)!=0){Mj(e,k,0,0);i=g;return}j=e+164|0;b[e+162>>1]=b[j>>1]|0;k=k&16777215;l=k+1|0;if(l>>>0<(c[e+36>>2]|0)>>>0){p=c[e+32>>2]|0;k=(d[p+k>>0]<<8|d[p+l>>0])&65535}else{k=oc[c[e+12>>2]&31](c[e+4>>2]|0,k)|0}b[j>>1]=k;if((a[e+336>>0]|0)==0){k=(c[h>>2]|0)+2|0;c[h>>2]=k;p=e+152|0;c[p>>2]=(c[p>>2]|0)+2;break}Kj(e);i=g;return}else if((h|0)==3){j=e+156|0;k=c[j>>2]|0;if((k&1|0)!=0){Mj(e,k,0,0);i=g;return}h=e+164|0;l=e+162|0;b[l>>1]=b[h>>1]|0;n=k&16777215;m=n+1|0;k=e+36|0;if(m>>>0<(c[k>>2]|0)>>>0){o=c[e+32>>2]|0;o=(d[o+n>>0]<<8|d[o+m>>0])&65535}else{o=oc[c[e+12>>2]&31](c[e+4>>2]|0,n)|0}b[h>>1]=o;n=e+336|0;if((a[n>>0]|0)!=0){Kj(e);i=g;return}p=(c[j>>2]|0)+2|0;c[j>>2]=p;m=e+152|0;c[m>>2]=(c[m>>2]|0)+2;if((p&1|0)!=0){Mj(e,p,0,0);i=g;return}b[l>>1]=o;o=p&16777215;l=o+1|0;if(!(l>>>0<(c[k>>2]|0)>>>0)){o=oc[c[e+12>>2]&31](c[e+4>>2]|0,o)|0;p=(a[n>>0]|0)==0;b[h>>1]=o;if(!p){Kj(e);i=g;return}}else{p=c[e+32>>2]|0;b[h>>1]=d[p+o>>0]<<8|d[p+l>>0]}k=(c[j>>2]|0)+2|0;c[j>>2]=k;c[m>>2]=(c[m>>2]|0)+2}else if((h|0)==4){k=c[e+156>>2]|0}else{p=e+372|0;c[p>>2]=(c[p>>2]|0)+2;Nj(e);i=g;return}}while(0);h=e+156|0;if((k&1|0)!=0){Mj(e,k,0,0);i=g;return}j=e+164|0;b[e+162>>1]=b[j>>1]|0;k=k&16777215;l=k+1|0;if(l>>>0<(c[e+36>>2]|0)>>>0){p=c[e+32>>2]|0;k=(d[p+k>>0]<<8|d[p+l>>0])&65535}else{k=oc[c[e+12>>2]&31](c[e+4>>2]|0,k)|0}b[j>>1]=k;if((a[e+336>>0]|0)!=0){Kj(e);i=g;return}c[h>>2]=(c[h>>2]|0)+2;p=e+152|0;c[p>>2]=(c[p>>2]|0)+2;if((f|0)==0){p=e+372|0;c[p>>2]=(c[p>>2]|0)+4;i=g;return}else{Qj(e);i=g;return}}function dn(a){a=a|0;var b=0,d=0,e=0;b=i;ak(a);d=0;do{e=c[41928+(d<<2)>>2]|0;if((e|0)!=0){c[a+(d<<2)+400>>2]=e}d=d+1|0}while((d|0)!=1024);c[a+4496>>2]=236;i=b;return}function en(e){e=e|0;var f=0,g=0,h=0,j=0,k=0,l=0,m=0,n=0;g=i;f=e+((b[e+160>>1]&7)<<2)+88|0;h=c[f>>2]|0;j=(h&128|0)!=0?h|-256:h&255;k=e+372|0;c[k>>2]=(c[k>>2]|0)+4;eo(e,15,j);k=e+156|0;l=c[k>>2]|0;if(
|
||
|
|
||
|
|
||
|
|
||
|
function kw(b,d,e){b=b|0;d=d|0;e=e|0;var f=0,g=0,h=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,I=0,J=0,K=0,L=0,M=0,N=0,O=0,P=0,Q=0,R=0,S=0,T=0,U=0,V=0,W=0,X=0,Y=0,Z=0,_=0,$=0,aa=0,ba=0,ca=0,da=0,ea=0,fa=0,ga=0,ha=0,ia=0,ja=0,ka=0,la=0,ma=0,na=0,oa=0,pa=0,qa=0,ra=0,sa=0,ta=0,ua=0,va=0,wa=0,xa=0,ya=0,za=0,Aa=0,Ba=0,Ca=0,Da=0,Ea=0,Fa=0,Ga=0,Ha=0,Ia=0,Ja=0,Ka=0,La=0,Ma=0,Na=0,Oa=0,Pa=0,Qa=0,Ra=0,Sa=0,Ta=0,Ua=0,Va=0,Wa=0,Xa=0,Ya=0,Za=0,_a=0,$a=0,ab=0,bb=0,cb=0,db=0,eb=0,fb=0,gb=0,hb=0;z=i;i=i+416|0;h=z+404|0;j=z+396|0;k=z+372|0;r=z+356|0;A=z+12|0;q=z+168|0;w=z+180|0;y=z+176|0;E=z+16|0;M=z+20|0;H=z+24|0;G=z+28|0;L=z+32|0;O=z+36|0;Q=z+40|0;S=z+344|0;V=z+44|0;Z=z+48|0;$=z+52|0;aa=z+56|0;ha=z+60|0;ja=z+64|0;ga=z+68|0;ea=z+72|0;Y=z+76|0;la=z+80|0;pa=z+84|0;ma=z+88|0;qa=z+92|0;sa=z+96|0;ta=z+100|0;wa=z+340|0;za=z+104|0;Aa=z+108|0;Ca=z+112|0;Da=z+116|0;Ia=z+120|0;Ga=z+124|0;Ja=z+128|0;La=z+132|0;Oa=z+136|0;Ta=z+140|0;Va=z+144|0;Qa=z+148|0;Xa=z+152|0;_a=z+156|0;Ya=z+368|0;bb=z+376|0;db=z+384|0;t=z+392|0;l=z+400|0;m=z+408|0;p=z+184|0;u=z+188|0;J=z+192|0;I=z+196|0;R=z+200|0;U=z+204|0;W=z+208|0;_=z+212|0;ca=z+216|0;ia=z+220|0;ka=z+224|0;oa=z+336|0;ua=z+228|0;ya=z+232|0;Na=z+236|0;Ba=z+240|0;Fa=z+244|0;Ha=z+248|0;Sa=z+252|0;Ua=z+256|0;Za=z+260|0;cb=z+264|0;s=z+268|0;o=z+272|0;f=z+276|0;K=z+280|0;T=z+284|0;ba=z+288|0;da=z+292|0;na=z+296|0;xa=z+300|0;Ea=z+304|0;Ma=z+308|0;Ra=z+312|0;ab=z+316|0;n=z+320|0;x=z+324|0;P=z+328|0;fa=z+332|0;va=z+348|0;Ka=z+352|0;$a=z+4|0;v=z;N=z+8|0;ra=z+360|0;Wa=z+160|0;D=z+364|0;X=z+164|0;Pa=z+380|0;C=z+172|0;B=z+388|0;F=c[b>>2]|0;if((lw(b,d,e)|0)==0){hb=0;i=z;return hb|0}a:while(1){fb=c[b>>2]|0;while(1){hb=a[b+fb+4>>0]|0;if(!(hb<<24>>24==10|hb<<24>>24==9|hb<<24>>24==32|hb<<24>>24==13)){break}fb=fb+1|0}c[b>>2]=fb;gb=55328;hb=61;eb=fb;while(1){if(!((a[b+eb+4>>0]|0)==hb<<24>>24)){g=8;break}eb=eb+1|0;gb=gb+1|0;hb=a[gb>>0]|0;if(hb<<24>>24==0){fb=1;break}}if((g|0)==8){while(1){g=0;hb=a[b+fb+4>>0]|0;if(!(hb<<24>>24==10|hb<<24>>24==9|hb<<24>>24==32|hb<<24>>24==13)){break}fb=fb+1|0;g=8}c[b>>2]=fb;gb=55336;hb=33;eb=fb;while(1){if(!((a[b+eb+4>>0]|0)==hb<<24>>24)){break a}eb=eb+1|0;gb=gb+1|0;hb=a[gb>>0]|0;if(hb<<24>>24==0){fb=2;break}}}c[b>>2]=eb;if((lw(b,db,e)|0)==0){g=15;break}if((fb|0)==1){c[d>>2]=(c[d>>2]|0)==(c[db>>2]|0);continue}else if((fb|0)==2){c[d>>2]=(c[d>>2]|0)!=(c[db>>2]|0);continue}else{continue}}if((g|0)==15){c[b>>2]=F;hb=0;i=z;return hb|0}b:while(1){eb=fb;while(1){hb=a[b+eb+4>>0]|0;if(!(hb<<24>>24==10|hb<<24>>24==9|hb<<24>>24==32|hb<<24>>24==13)){break}eb=eb+1|0}c[b>>2]=eb;gb=55320;hb=38;db=eb;while(1){if(!((a[b+db+4>>0]|0)==hb<<24>>24)){fb=eb;break}gb=gb+1|0;hb=a[gb>>0]|0;if(hb<<24>>24==0){g=25;break b}else{db=db+1|0}}while(1){hb=a[b+fb+4>>0]|0;if(!(hb<<24>>24==10|hb<<24>>24==9|hb<<24>>24==32|hb<<24>>24==13)){break}fb=fb+1|0}c[b>>2]=fb;if((a[b+fb+4>>0]|0)!=38){break}db=fb+1|0;c[b>>2]=db;if((lw(b,cb,e)|0)==0){g=47;break}c:while(1){fb=c[b>>2]|0;while(1){hb=a[b+fb+4>>0]|0;if(!(hb<<24>>24==10|hb<<24>>24==9|hb<<24>>24==32|hb<<24>>24==13)){break}fb=fb+1|0}c[b>>2]=fb;gb=55328;hb=61;eb=fb;while(1){if(!((a[b+eb+4>>0]|0)==hb<<24>>24)){g=37;break}eb=eb+1|0;gb=gb+1|0;hb=a[gb>>0]|0;if(hb<<24>>24==0){fb=1;break}}if((g|0)==37){while(1){g=0;hb=a[b+fb+4>>0]|0;if(!(hb<<24>>24==10|hb<<24>>24==9|hb<<24>>24==32|hb<<24>>24==13)){break}fb=fb+1|0;g=37}c[b>>2]=fb;gb=55336;hb=33;eb=fb;while(1){if(!((a[b+eb+4>>0]|0)==hb<<24>>24)){break c}eb=eb+1|0;gb=gb+1|0;hb=a[gb>>0]|0;if(hb<<24>>24==0){fb=2;break}}}c[b>>2]=eb;if((lw(b,h,e)|0)==0){g=43;break b}if((fb|0)==1){c[cb>>2]=(c[cb>>2]|0)==(c[h>>2]|0);continue}else if((fb|0)==2){c[cb>>2]=(c[cb>>2]|0)!=(c[h>>2]|0);continue}else{continue}}c[d>>2]=c[cb>>2]&c[d>>2]}if((g|0)==25){c[b>>2]=fb}else if((g|0)==43){c[b>>2]=db;g=47}if((g|0)==47){c[b>>2]=F;hb=0;i=z;return hb|0}d:while(1){hb=a[b+fb+4>>0]|0;if(hb<<24>>24==10|hb<<24>>24==9|hb<<24>>24==32|hb<<24>>24==13){fb=fb+1|0;continue}c[b>>2]=fb;if((a[b+fb+4>>0]|0)!=94){g=52;break}cb=fb+1|0;c[b>>2]=cb;if((lw(b,ab,e)|0)==0){break}e:while(1){db=c[b>>2]|0;while(1){hb=a[b+db+4>>0]|0;if(!(hb<<24>>2
|
||
|
|
||
|
|
||
|
|
||
|
function Kk(f){f=f|0;var g=0,h=0,j=0,k=0,l=0,m=0;g=i;i=i+16|0;j=g;h=f+160|0;l=b[h>>1]&63;if((nc[c[46024+(l<<2)>>2]&63](f,l,4095,16)|0)!=0){i=g;return}if((Ko(f,j)|0)!=0){i=g;return}j=e[j>>1]|0;c[f+(((e[h>>1]|0)>>>9&7)<<2)+120>>2]=(j&32768|0)!=0?j|-65536:j;h=f+372|0;c[h>>2]=(c[h>>2]|0)+4;h=f+156|0;k=c[h>>2]|0;if((k&1|0)!=0){Mj(f,k,0,0);i=g;return}j=f+164|0;b[f+162>>1]=b[j>>1]|0;k=k&16777215;l=k+1|0;if(l>>>0<(c[f+36>>2]|0)>>>0){m=c[f+32>>2]|0;k=(d[m+k>>0]<<8|d[m+l>>0])&65535}else{k=oc[c[f+12>>2]&31](c[f+4>>2]|0,k)|0}b[j>>1]=k;if((a[f+336>>0]|0)==0){c[h>>2]=(c[h>>2]|0)+2;m=f+152|0;c[m>>2]=(c[m>>2]|0)+2;i=g;return}else{Kj(f);i=g;return}}function Lk(e){e=e|0;var f=0,g=0,h=0,j=0,k=0,l=0,m=0;f=i;i=i+16|0;g=f;l=b[e+160>>1]&63;if((nc[c[46024+(l<<2)>>2]&63](e,l,509,8)|0)!=0){i=f;return}if((Jo(e,g)|0)!=0){i=f;return}j=d[g>>0]|0;h=e+166|0;l=b[h>>1]|0;k=l&65535;g=0-((k>>>4&1)+j)|0;if((g&255|0)!=0){l=k&65531;b[h>>1]=l}k=e+372|0;c[k>>2]=(c[k>>2]|0)+8;k=g&128;l=l&65535;l=(k|0)==0?l&65527:l|8;k=(k&j|0)==0?l&65533:l|2;b[h>>1]=((j|g)&128|0)==0?k&65518:k|17;h=e+156|0;k=c[h>>2]|0;if((k&1|0)!=0){Mj(e,k,0,0);i=f;return}j=e+164|0;b[e+162>>1]=b[j>>1]|0;k=k&16777215;l=k+1|0;if(l>>>0<(c[e+36>>2]|0)>>>0){m=c[e+32>>2]|0;k=(d[m+k>>0]<<8|d[m+l>>0])&65535}else{k=oc[c[e+12>>2]&31](c[e+4>>2]|0,k)|0}b[j>>1]=k;if((a[e+336>>0]|0)==0){c[h>>2]=(c[h>>2]|0)+2;m=e+152|0;c[m>>2]=(c[m>>2]|0)+2;Mo(e,g&255)|0;i=f;return}else{Kj(e);i=f;return}}function Mk(f){f=f|0;var g=0,h=0,j=0,k=0,l=0,m=0,n=0;g=i;i=i+16|0;h=g;m=b[f+160>>1]&63;if((nc[c[46024+(m<<2)>>2]&63](f,m,509,16)|0)!=0){i=g;return}if((Ko(f,h)|0)!=0){i=g;return}k=e[h>>1]|0;j=f+166|0;m=b[j>>1]|0;l=m&65535;h=0-((l>>>4&1)+k)|0;if((h&65535|0)!=0){m=l&65531;b[j>>1]=m}l=f+372|0;c[l>>2]=(c[l>>2]|0)+8;l=h&32768;m=m&65535;m=(l|0)==0?m&65527:m|8;l=(l&k|0)==0?m&65533:m|2;b[j>>1]=((k|h)&32768|0)==0?l&65518:l|17;j=f+156|0;l=c[j>>2]|0;if((l&1|0)!=0){Mj(f,l,0,0);i=g;return}k=f+164|0;b[f+162>>1]=b[k>>1]|0;l=l&16777215;m=l+1|0;if(m>>>0<(c[f+36>>2]|0)>>>0){n=c[f+32>>2]|0;l=(d[n+l>>0]<<8|d[n+m>>0])&65535}else{l=oc[c[f+12>>2]&31](c[f+4>>2]|0,l)|0}b[k>>1]=l;if((a[f+336>>0]|0)==0){c[j>>2]=(c[j>>2]|0)+2;n=f+152|0;c[n>>2]=(c[n>>2]|0)+2;No(f,h&65535)|0;i=g;return}else{Kj(f);i=g;return}}function Nk(e){e=e|0;var f=0,g=0,h=0,j=0,k=0,l=0,m=0,n=0;f=i;i=i+16|0;g=f;l=b[e+160>>1]&63;if((nc[c[46024+(l<<2)>>2]&63](e,l,509,32)|0)!=0){i=f;return}if((Lo(e,g)|0)!=0){i=f;return}j=c[g>>2]|0;m=0-j|0;h=e+166|0;l=b[h>>1]|0;k=l&65535;n=k>>>4&1;g=m-n|0;if((n|0)!=(m|0)){l=k&65531;b[h>>1]=l}k=e+372|0;c[k>>2]=(c[k>>2]|0)+10;k=l&65535;k=(g|0)<0?k|8:k&65527;k=(j&g|0)<0?k|2:k&65533;b[h>>1]=(j|g|0)<0?k|17:k&65518;h=e+156|0;k=c[h>>2]|0;if((k&1|0)!=0){Mj(e,k,0,0);i=f;return}j=e+164|0;b[e+162>>1]=b[j>>1]|0;l=k&16777215;k=l+1|0;if(k>>>0<(c[e+36>>2]|0)>>>0){n=c[e+32>>2]|0;k=(d[n+l>>0]<<8|d[n+k>>0])&65535}else{k=oc[c[e+12>>2]&31](c[e+4>>2]|0,l)|0}b[j>>1]=k;if((a[e+336>>0]|0)==0){c[h>>2]=(c[h>>2]|0)+2;n=e+152|0;c[n>>2]=(c[n>>2]|0)+2;Oo(e,g)|0;i=f;return}else{Kj(e);i=f;return}}function Ok(e){e=e|0;var f=0,g=0,h=0,j=0,k=0,l=0,m=0;f=i;i=i+16|0;g=f;if((c[e>>2]&2|0)!=0?(a[e+334>>0]|0)==0:0){Rj(e);i=f;return}l=b[e+160>>1]&63;if((nc[c[46024+(l<<2)>>2]&63](e,l,509,16)|0)!=0){i=f;return}if((Ko(e,g)|0)!=0){i=f;return}b[g>>1]=b[e+166>>1]&42783;h=e+372|0;c[h>>2]=(c[h>>2]|0)+4;h=e+156|0;k=c[h>>2]|0;if((k&1|0)!=0){Mj(e,k,0,0);i=f;return}j=e+164|0;b[e+162>>1]=b[j>>1]|0;l=k&16777215;k=l+1|0;if(k>>>0<(c[e+36>>2]|0)>>>0){m=c[e+32>>2]|0;k=(d[m+l>>0]<<8|d[m+k>>0])&65535}else{k=oc[c[e+12>>2]&31](c[e+4>>2]|0,l)|0}b[j>>1]=k;if((a[e+336>>0]|0)==0){c[h>>2]=(c[h>>2]|0)+2;m=e+152|0;c[m>>2]=(c[m>>2]|0)+2;No(e,b[g>>1]|0)|0;i=f;return}else{Kj(e);i=f;return}}function Pk(f){f=f|0;var g=0,h=0,j=0,k=0,l=0,m=0;g=i;i=i+16|0;h=g;j=f+160|0;l=b[j>>1]&63;if((nc[c[46024+(l<<2)>>2]&63](f,l,4093,16)|0)!=0){i=g;return}if((Ko(f,h)|0)!=0){i=g;return}j=c[f+(((e[j>>1]|0)>>>9&7)<<2)+88>>2]|0;do{if((j&32768|0)==0){l=e[h>>1]|0;if((l&32768|0)!=0|(j&65535)>>>0>l>>>0){l=f+166|0;b[l>>1]=b[l>>1]&65527;l=f+372|0;c[l>>2]=(c[l>>2]|0)+14;break}h=f+372|0;c[h>>2]=(c[h>>2]|0)+14;h=f+156|0;k=c[h>>2]|0;if((k&1|0)!=0){Mj(f,k,0,0);i=g;
|
||
|
|
||
|
|
||
|
|
||
|
function vs(b,e){b=b|0;e=e|0;var f=0,g=0,h=0,j=0,k=0,l=0,m=0,n=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,I=0,J=0,K=0,L=0;f=i;i=i+1072|0;g=f;j=f+536|0;h=f+12|0;p=Et(e)|0;if((p|0)==0){K=0;i=f;return K|0}Ls(b,0);l=b+16|0;if((a[l>>0]|0)!=0){K=p;i=f;return K|0}m=b+12|0;e=h+1|0;n=h+2|0;q=j+524|0;r=j+525|0;s=j+526|0;u=h+12|0;t=c[o>>2]|0;z=0;v=0;while(1){Ms(b,g,8)|0;A=c[g>>2]|0;if((A&128|0)==0){w=8;do{Ms(b,g,1)|0;K=A<<1;A=c[g>>2]&1|K;w=w+1|0}while((K&128|0)==0&w>>>0<64);A=w>>>0>63?0:A}w=A&255;x=c[m>>2]|0;y=a[l>>0]|0;if(z<<24>>24==-43&v<<24>>24==-86?(A&255|0)==150:0){Ms(b,g,8)|0;A=c[g>>2]|0;if((A&128|0)==0){z=8;do{Ms(b,g,1)|0;K=A<<1;A=c[g>>2]&1|K;z=z+1|0}while((K&128|0)==0&z>>>0<64);A=z>>>0>63?0:A}E=a[47232+(A&255)>>0]|0;A=E&255;Ms(b,g,8)|0;B=c[g>>2]|0;if((B&128|0)==0){z=8;do{Ms(b,g,1)|0;K=B<<1;B=c[g>>2]&1|K;z=z+1|0}while((K&128|0)==0&z>>>0<64);B=z>>>0>63?0:B}D=a[47232+(B&255)>>0]|0;z=D&255;Ms(b,g,8)|0;C=c[g>>2]|0;if((C&128|0)==0){B=8;do{Ms(b,g,1)|0;K=C<<1;C=c[g>>2]&1|K;B=B+1|0}while((K&128|0)==0&B>>>0<64);C=B>>>0>63?0:C}F=a[47232+(C&255)>>0]|0;B=F&255;Ms(b,g,8)|0;G=c[g>>2]|0;if((G&128|0)==0){C=8;do{Ms(b,g,1)|0;K=G<<1;G=c[g>>2]&1|K;C=C+1|0}while((K&128|0)==0&C>>>0<64);G=C>>>0>63?0:G}G=a[47232+(G&255)>>0]|0;Ms(b,g,8)|0;H=c[g>>2]|0;if((H&128|0)==0){C=8;do{Ms(b,g,1)|0;K=H<<1;H=c[g>>2]&1|K;C=C+1|0}while((K&128|0)==0&C>>>0<64);H=C>>>0>63?0:H}H=a[47232+(H&255)>>0]|0;A=B<<6&1984|A&63;B=B>>>5&3;C=kt(A,B,z,512)|0;if((C|0)!=0){tt(C,3);st(C,8,1);At(C,G);if(!(H<<24>>24==(D^E^F^G)<<24>>24)){st(C,1,1)}a[h>>0]=0;a[e>>0]=0;a[n>>0]=0;F=0;H=0;E=0;while(1){a[h>>0]=F;a[e>>0]=H;Ms(b,g,8)|0;H=c[g>>2]|0;if((H&128|0)==0){G=8;do{Ms(b,g,1)|0;K=H<<1;H=c[g>>2]&1|K;G=G+1|0}while((K&128|0)==0&G>>>0<64);F=a[h>>0]|0;I=G>>>0>63?0:H}else{I=H}H=I&255;a[n>>0]=H;if(F<<24>>24==-43?(a[e>>0]|0)==-86:0){k=33;break}G=E+1|0;if(!(G>>>0<64)){break}F=a[e>>0]|0;E=G}if((k|0)==33?(k=0,(I&255|0)==173):0){Ms(b,g,8)|0;G=c[g>>2]|0;if((G&128|0)==0){F=8;do{Ms(b,g,1)|0;K=G<<1;G=c[g>>2]&1|K;F=F+1|0}while((K&128|0)==0&F>>>0<64);G=F>>>0>63?0:G}K=a[47232+(G&255)>>0]|0;a[n>>0]=K;if(!(K<<24>>24!=D<<24>>24|E>>>0>63)){st(C,8,0);E=0;D=0;while(1){if(((D>>>0)%3|0|0)==0){Ms(b,g,8)|0;F=c[g>>2]|0;if((F&128|0)==0){E=8;do{Ms(b,g,1)|0;K=F<<1;F=c[g>>2]&1|K;E=E+1|0}while((K&128|0)==0&E>>>0<64);F=E>>>0>63?0:F}E=d[47232+(F&255)>>0]<<2}Ms(b,g,8)|0;G=c[g>>2]|0;if((G&128|0)==0){F=8;do{Ms(b,g,1)|0;K=G<<1;G=c[g>>2]&1|K;F=F+1|0}while((K&128|0)==0&F>>>0<64);G=F>>>0>63?0:G}a[j+D>>0]=a[47232+(G&255)>>0]&63|E&192;D=D+1|0;if((D|0)==524){break}else{E=E<<2&1020}}Ms(b,g,8)|0;E=c[g>>2]|0;if((E&128|0)==0){D=8;do{Ms(b,g,1)|0;K=E<<1;E=c[g>>2]&1|K;D=D+1|0}while((K&128|0)==0&D>>>0<64);E=D>>>0>63?0:E}E=d[47232+(E&255)>>0]|0;D=E<<2;Ms(b,g,8)|0;G=c[g>>2]|0;if((G&128|0)==0){F=8;do{Ms(b,g,1)|0;K=G<<1;G=c[g>>2]&1|K;F=F+1|0}while((K&128|0)==0&F>>>0<64);G=F>>>0>63?0:G}D=(a[47232+(G&255)>>0]&63|D&192)&255;a[q>>0]=D;Ms(b,g,8)|0;G=c[g>>2]|0;if((G&128|0)==0){F=8;do{Ms(b,g,1)|0;K=G<<1;G=c[g>>2]&1|K;F=F+1|0}while((K&128|0)==0&F>>>0<64);G=F>>>0>63?0:G}F=(a[47232+(G&255)>>0]&63|E<<4&192)&255;a[r>>0]=F;Ms(b,g,8)|0;H=c[g>>2]|0;if((H&128|0)==0){G=8;do{Ms(b,g,1)|0;K=H<<1;H=c[g>>2]&1|K;G=G+1|0}while((K&128|0)==0&G>>>0<64);H=G>>>0>63?0:H}J=a[47232+(H&255)>>0]&63|E<<6;a[s>>0]=J;E=0;I=0;G=0;H=0;while(1){if(((H>>>0)%3|0|0)==0){K=E<<1&510|E>>>7&1}else{K=E}L=d[j+H>>0]^K;E=(K>>>8&1)+G+(L&255)|0;a[h+H>>0]=L;H=H+1|0;if((H|0)==524){break}else{G=I;I=K&255}}if(!((D<<24>>24==(K&255)<<24>>24?F<<24>>24==(E&255)<<24>>24:0)?(J&255|0)==(I|0):0)){c[g>>2]=A;c[g+4>>2]=B;c[g+8>>2]=z;hb(t|0,47200,g|0)|0;st(C,2,1)}Mz(c[C+24>>2]|0,u|0,512)|0;Ct(C,h,12)|0}}Gt(p,C)|0}c[m>>2]=x;a[l>>0]=y}if(y<<24>>24==0){z=v;v=w}else{break}}i=f;return p|0}function ws(a){a=a|0;var d=0,e=0,f=0,g=0,h=0,j=0,k=0,l=0,m=0,n=0;e=i;f=Kt()|0;if((f|0)==0){n=0;i=e;return n|0}l=c[a>>2]|0;if((l|0)==0){n=f;i=e;return n|0}h=a+4|0;j=0;a:while(1){k=c[(c[h>>2]|0)+(j<<2)>>2]|0;if((k|0)!=0?(c[k>>2]|0)!=0:0){l=k+4|0;m=0;do{n=c[(c[l>>2]|0)+(m<<2)>>2]|0;if((n|0)==0){n=Et(m)|0}else{n=vs(n,m)|0}if((b[n+2>>1]|0)==0?(g=m+1|0,(g|0)==(c[k>>2]|0)):0){Ft(n);m=g}else{if((n|0)==0){break
|
||
|
|
||
|
|
||
|
|
||
|
function xu(b,f,g,h){b=b|0;f=f|0;g=g|0;h=h|0;var j=0,k=0,l=0,m=0,n=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,I=0,J=0;j=i;i=i+560|0;m=j;l=j+528|0;v=j+520|0;k=j+264|0;n=j+256|0;$u(n,0,g);$u(n,4,h);if((c[12626]|0)==0){g=0;do{p=g<<25;G=(g&128|0)!=0?p^517762881:p;p=G<<1;G=(G|0)<0?p^517762881:p;p=G<<1;G=(G|0)<0?p^517762881:p;p=G<<1;G=(G|0)<0?p^517762881:p;p=G<<1;G=(G|0)<0?p^517762881:p;p=G<<1;G=(G|0)<0?p^517762881:p;p=G<<1;G=(G|0)<0?p^517762881:p;p=G<<1;c[50512+(g<<2)>>2]=(G|0)<0?p^517762881:p;g=g+1|0}while((g|0)!=256);c[12626]=1}p=n+1|0;w=c[50512+(d[n>>0]<<2)>>2]|0;q=n+2|0;w=c[50512+((d[p>>0]^w>>>24)<<2)>>2]^w<<8;r=n+3|0;w=c[50512+((d[q>>0]^w>>>24)<<2)>>2]^w<<8;s=n+4|0;w=c[50512+((d[r>>0]^w>>>24)<<2)>>2]^w<<8;t=n+5|0;w=c[50512+((d[s>>0]^w>>>24)<<2)>>2]^w<<8;u=n+6|0;w=c[50512+((d[t>>0]^w>>>24)<<2)>>2]^w<<8;g=n+7|0;w=c[50512+((d[u>>0]^w>>>24)<<2)>>2]^w<<8;w=c[50512+((d[g>>0]^w>>>24)<<2)>>2]^w<<8;if(h>>>0<4){G=1;i=j;return G|0}if((ta(v|0,1,4,b|0)|0)!=4){G=1;i=j;return G|0}if((c[12626]|0)==0){x=0;do{y=x<<25;G=(x&128|0)!=0?y^517762881:y;y=G<<1;G=(G|0)<0?y^517762881:y;y=G<<1;G=(G|0)<0?y^517762881:y;y=G<<1;G=(G|0)<0?y^517762881:y;y=G<<1;G=(G|0)<0?y^517762881:y;y=G<<1;G=(G|0)<0?y^517762881:y;y=G<<1;G=(G|0)<0?y^517762881:y;y=G<<1;c[50512+(x<<2)>>2]=(G|0)<0?y^517762881:y;x=x+1|0}while((x|0)!=256);c[12626]=1}w=c[50512+((d[v>>0]^w>>>24)<<2)>>2]^w<<8;w=c[50512+((d[v+1>>0]^w>>>24)<<2)>>2]^w<<8;w=c[50512+((d[v+2>>0]^w>>>24)<<2)>>2]^w<<8;w=c[50512+((d[v+3>>0]^w>>>24)<<2)>>2]^w<<8;v=Zu(v,0)|0;if((v|0)!=262144){G=c[o>>2]|0;c[m>>2]=v;hb(G|0,50472,m|0)|0;G=1;i=j;return G|0}v=h+ -4|0;a:do{if((v|0)!=0){while(1){h=v>>>0<256?v:256;if((ta(k|0,1,h|0,b|0)|0)!=(h|0)){b=1;break}if((c[12626]|0)==0){x=0;do{y=x<<25;G=(x&128|0)!=0?y^517762881:y;y=G<<1;G=(G|0)<0?y^517762881:y;y=G<<1;G=(G|0)<0?y^517762881:y;y=G<<1;G=(G|0)<0?y^517762881:y;y=G<<1;G=(G|0)<0?y^517762881:y;y=G<<1;G=(G|0)<0?y^517762881:y;y=G<<1;G=(G|0)<0?y^517762881:y;y=G<<1;c[50512+(x<<2)>>2]=(G|0)<0?y^517762881:y;x=x+1|0}while((x|0)!=256);c[12626]=1}if((h|0)!=0){x=h;y=k;while(1){w=c[50512+((d[y>>0]^w>>>24)<<2)>>2]^w<<8;x=x+ -1|0;if((x|0)==0){break}else{y=y+1|0}}}if((v|0)==(h|0)){break a}else{v=v-h|0}}i=j;return b|0}}while(0);if((ta(k|0,1,4,b|0)|0)!=4){G=1;i=j;return G|0}if((Zu(k,0)|0)!=(w|0)){fb(50408,16,1,c[o>>2]|0)|0;G=1;i=j;return G|0}h=c[o>>2]|0;w=l+12|0;v=l+13|0;y=0;b:while(1){if((ta(n|0,1,8,b|0)|0)!=8){b=1;l=145;break}x=(y|0)==0;z=y+10|0;A=y+24|0;c:while(1){if((c[12626]|0)==0){B=0;do{C=B<<25;G=(B&128|0)!=0?C^517762881:C;C=G<<1;G=(G|0)<0?C^517762881:C;C=G<<1;G=(G|0)<0?C^517762881:C;C=G<<1;G=(G|0)<0?C^517762881:C;C=G<<1;G=(G|0)<0?C^517762881:C;C=G<<1;G=(G|0)<0?C^517762881:C;C=G<<1;G=(G|0)<0?C^517762881:C;C=G<<1;c[50512+(B<<2)>>2]=(G|0)<0?C^517762881:C;B=B+1|0}while((B|0)!=256);c[12626]=1}C=c[50512+(d[n>>0]<<2)>>2]|0;C=c[50512+((d[p>>0]^C>>>24)<<2)>>2]^C<<8;C=c[50512+((d[q>>0]^C>>>24)<<2)>>2]^C<<8;C=c[50512+((d[r>>0]^C>>>24)<<2)>>2]^C<<8;C=c[50512+((d[s>>0]^C>>>24)<<2)>>2]^C<<8;C=c[50512+((d[t>>0]^C>>>24)<<2)>>2]^C<<8;C=c[50512+((d[u>>0]^C>>>24)<<2)>>2]^C<<8;C=c[50512+((d[g>>0]^C>>>24)<<2)>>2]^C<<8;D=Zu(n,0)|0;B=Zu(n,4)|0;do{if((D|0)==1162757152){l=27;break b}else if((D|0)==1413564243){if(x){b=1;l=145;break b}D=B>>>0<256?B:256;if((ta(m|0,1,D|0,b|0)|0)!=(D|0)){b=1;l=145;break b}if((c[12626]|0)==0){E=0;do{F=E<<25;G=(E&128|0)!=0?F^517762881:F;F=G<<1;G=(G|0)<0?F^517762881:F;F=G<<1;G=(G|0)<0?F^517762881:F;F=G<<1;G=(G|0)<0?F^517762881:F;F=G<<1;G=(G|0)<0?F^517762881:F;F=G<<1;G=(G|0)<0?F^517762881:F;F=G<<1;G=(G|0)<0?F^517762881:F;F=G<<1;c[50512+(E<<2)>>2]=(G|0)<0?F^517762881:F;E=E+1|0}while((E|0)!=256);c[12626]=1}if((D|0)!=0){F=D;E=m;while(1){C=c[50512+((d[E>>0]^C>>>24)<<2)>>2]^C<<8;F=F+ -1|0;if((F|0)==0){break}else{E=E+1|0}}}Ct(y,m,D)|0;if((D|0)!=(B|0)){B=B-D|0;while(1){D=B>>>0<256?B:256;if((ta(k|0,1,D|0,b|0)|0)!=(D|0)){b=1;l=145;break b}if((c[12626]|0)==0){E=0;do{F=E<<25;G=(E&128|0)!=0?F^517762881:F;F=G<<1;G=(G|0)<0?F^517762881:F;F=G<<1;G=(G|0)<0?F^517762881:F;F=G<<1;G=(G|0)<0?F^517762881:F;F=G<<1;G=(G|0)<0?F^517762881:F;F=G<<1;G=(G|0)<0?F^517762881:F;F=G<<1;G=(G|
|
||
|
|
||
|
|
||
|
|
||
|
function Dz(b,c,d){b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0;e=i;a:do{if((d|0)==0){b=0}else{while(1){g=a[b>>0]|0;f=a[c>>0]|0;if(!(g<<24>>24==f<<24>>24)){break}d=d+ -1|0;if((d|0)==0){b=0;break a}else{b=b+1|0;c=c+1|0}}b=(g&255)-(f&255)|0}}while(0);i=e;return b|0}function Ez(b,c){b=b|0;c=c|0;var e=0,f=0,g=0,h=0;e=i;g=a[b>>0]|0;a:do{if(g<<24>>24==0){f=0}else{f=g;g=g&255;while(1){h=a[c>>0]|0;if(h<<24>>24==0){break a}if(!(f<<24>>24==h<<24>>24)?(h=Qz(g|0)|0,(h|0)!=(Qz(d[c>>0]|0|0)|0)):0){break}b=b+1|0;c=c+1|0;g=a[b>>0]|0;if(g<<24>>24==0){f=0;break a}else{f=g;g=g&255}}f=a[b>>0]|0}}while(0);h=Qz(f&255|0)|0;h=h-(Qz(d[c>>0]|0|0)|0)|0;i=e;return h|0}function Fz(b,c){b=b|0;c=c|0;var d=0,e=0,f=0;d=i;f=a[b>>0]|0;e=a[c>>0]|0;if(f<<24>>24!=e<<24>>24|f<<24>>24==0|e<<24>>24==0){b=f;f=e;b=b&255;f=f&255;f=b-f|0;i=d;return f|0}do{b=b+1|0;c=c+1|0;f=a[b>>0]|0;e=a[c>>0]|0}while(!(f<<24>>24!=e<<24>>24|f<<24>>24==0|e<<24>>24==0));b=f&255;f=e&255;f=b-f|0;i=d;return f|0}function Gz(b,c,e){b=b|0;c=c|0;e=e|0;var f=0,g=0,h=0;f=i;if((e|0)==0){b=0;i=f;return b|0}g=a[b>>0]|0;a:do{if(g<<24>>24==0){g=0}else{while(1){e=e+ -1|0;h=a[c>>0]|0;if(!((e|0)!=0&h<<24>>24!=0&g<<24>>24==h<<24>>24)){break a}b=b+1|0;c=c+1|0;g=a[b>>0]|0;if(g<<24>>24==0){g=0;break}}}}while(0);h=(g&255)-(d[c>>0]|0)|0;i=f;return h|0}function Hz(){}function Iz(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;b=b-d-(c>>>0>a>>>0|0)>>>0;return(G=b,a-c>>>0|0)|0}function Jz(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;c=a+c>>>0;return(G=b+d+(c>>>0<a>>>0|0)>>>0,c|0)|0}function Kz(b){b=b|0;var c=0;c=b;while(a[c>>0]|0){c=c+1|0}return c-b|0}function Lz(a,b,c){a=a|0;b=b|0;c=c|0;if((c|0)<32){G=b>>>c;return a>>>c|(b&(1<<c)-1)<<32-c}G=0;return b>>>c-32|0}function Mz(b,d,e){b=b|0;d=d|0;e=e|0;var f=0;if((e|0)>=4096)return Da(b|0,d|0,e|0)|0;f=b|0;if((b&3)==(d&3)){while(b&3){if((e|0)==0)return f|0;a[b>>0]=a[d>>0]|0;b=b+1|0;d=d+1|0;e=e-1|0}while((e|0)>=4){c[b>>2]=c[d>>2];b=b+4|0;d=d+4|0;e=e-4|0}}while((e|0)>0){a[b>>0]=a[d>>0]|0;b=b+1|0;d=d+1|0;e=e-1|0}return f|0}function Nz(a,b,c){a=a|0;b=b|0;c=c|0;if((c|0)<32){G=b<<c|(a&(1<<c)-1<<32-c)>>>32-c;return a<<c}G=a<<c-32;return 0}function Oz(b,d,e){b=b|0;d=d|0;e=e|0;var f=0,g=0,h=0,i=0;f=b+e|0;if((e|0)>=20){d=d&255;i=b&3;h=d|d<<8|d<<16|d<<24;g=f&~3;if(i){i=b+4-i|0;while((b|0)<(i|0)){a[b>>0]=d;b=b+1|0}}while((b|0)<(g|0)){c[b>>2]=h;b=b+4|0}}while((b|0)<(f|0)){a[b>>0]=d;b=b+1|0}return b-e|0}function Pz(b,c){b=b|0;c=c|0;var d=0,e=0;d=b+(Kz(b)|0)|0;do{a[d+e>>0]=a[c+e>>0];e=e+1|0}while(a[c+(e-1)>>0]|0);return b|0}function Qz(a){a=a|0;if((a|0)<65)return a|0;if((a|0)>90)return a|0;return a-65+97|0}function Rz(b,c){b=b|0;c=c|0;var d=0;do{a[b+d>>0]=a[c+d>>0];d=d+1|0}while(a[c+(d-1)>>0]|0);return b|0}function Sz(a,b,c){a=a|0;b=b|0;c=c|0;if((c|0)<32){G=b>>c;return a>>>c|(b&(1<<c)-1)<<32-c}G=(b|0)<0?-1:0;return b>>c-32|0}function Tz(b){b=b|0;var c=0;c=a[n+(b>>>24)>>0]|0;if((c|0)<8)return c|0;c=a[n+(b>>16&255)>>0]|0;if((c|0)<8)return c+8|0;c=a[n+(b>>8&255)>>0]|0;if((c|0)<8)return c+16|0;return(a[n+(b&255)>>0]|0)+24|0}function Uz(b){b=b|0;var c=0;c=a[m+(b&255)>>0]|0;if((c|0)<8)return c|0;c=a[m+(b>>8&255)>>0]|0;if((c|0)<8)return c+8|0;c=a[m+(b>>16&255)>>0]|0;if((c|0)<8)return c+16|0;return(a[m+(b>>>24)>>0]|0)+24|0}function Vz(a,b){a=a|0;b=b|0;var c=0,d=0,e=0,f=0;f=a&65535;d=b&65535;c=ca(d,f)|0;e=a>>>16;d=(c>>>16)+(ca(d,e)|0)|0;b=b>>>16;a=ca(b,f)|0;return(G=(d>>>16)+(ca(b,e)|0)+(((d&65535)+a|0)>>>16)|0,d+a<<16|c&65535|0)|0}function Wz(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0,g=0,h=0;e=b>>31|((b|0)<0?-1:0)<<1;f=((b|0)<0?-1:0)>>31|((b|0)<0?-1:0)<<1;g=d>>31|((d|0)<0?-1:0)<<1;h=((d|0)<0?-1:0)>>31|((d|0)<0?-1:0)<<1;a=Iz(e^a,f^b,e,f)|0;b=G;e=g^e;f=h^f;g=Iz(($z(a,b,Iz(g^c,h^d,g,h)|0,G,0)|0)^e,G^f,e,f)|0;return g|0}function Xz(a,b,d,e){a=a|0;b=b|0;d=d|0;e=e|0;var f=0,g=0,h=0,j=0,k=0,l=0;g=i;i=i+8|0;f=g|0;h=b>>31|((b|0)<0?-1:0)<<1;j=((b|0)<0?-1:0)>>31|((b|0)<0?-1:0)<<1;k=e>>31|((e|0)<0?-1:0)<<1;l=((e|0)<0?-1:0)>>31|((e|0)<0?-1:0)<<1;a=Iz(h^a,j^b,h,j)|0;b=G;$z(a,b,Iz(k^d,l^e,k,l)|0,G,f)|0;k=Iz(c[f>>2]^h,c[f+4>>2]^j,h,j)|0;j=G;i=g;return(G=j,k)|0}function Yz(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;var e=0,f=0;e=a;f=c;a=Vz(e,f)|0;c
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// EMSCRIPTEN_END_FUNCS
|
||
|
var gc=[lA,Ge,He,Ie,Je,Ke,Le,Me,Ne,Oe,Pe,Qe,Re,Se,Te,Ue,Ve,We,Xe,Ye,Ze,_e,$e,Bc,Uc,ad,Fe,we,xe,Cq,ur,Er,Yr,Zr,es,fs,ls,ms,ps,qs,ts,us,vv,zv,Nv,Tv,Qv,zy,Oy,Qy,pz,rz,lA,lA,lA,lA,lA,lA,lA,lA,lA,lA,lA,lA];var hc=[mA,Uf];var ic=[nA,dk,ek,fk,gk,hk,ik,jk,kk,lk,mk,nk,ok,pk,qk,rk,sk,tk,uk,vk,wk,xk,yk,zk,Ak,Bk,Ck,Dk,Ek,Fk,Gk,Hk,Ik,Jk,Kk,Lk,Mk,Nk,Ok,Pk,ck,Qk,Rk,Sk,Tk,Uk,Vk,Wk,Xk,Yk,Zk,_k,$k,al,bl,cl,dl,el,fl,gl,hl,il,jl,kl,ll,ml,nl,ol,pl,ql,rl,sl,tl,ul,vl,wl,xl,yl,zl,Al,Bl,Cl,Dl,El,Fl,Gl,Hl,Il,Jl,Kl,Ll,Ml,Nl,Ol,Pl,Ql,Rl,Sl,Tl,Ul,Vl,Wl,Xl,Yl,Zl,_l,$l,am,bm,cm,dm,em,fm,gm,hm,im,jm,km,lm,mm,nm,om,pm,qm,rm,sm,tm,um,vm,wm,xm,ym,zm,Am,Bm,Cm,Dm,Em,Fm,Gm,Hm,Im,Jm,Km,Lm,Mm,Nm,Om,Pm,Qm,Rm,Sm,Tm,Um,Vm,Wm,Xm,Ym,Zm,_m,$m,an,fn,gn,hn,jn,kn,ln,mn,nn,on,pn,qn,rn,sn,tn,un,vn,wn,xn,yn,zn,An,Bn,Cn,Dn,En,Fn,Gn,Hn,In,Jn,Kn,Ln,Mn,Nn,On,Pn,Qn,Rn,Sn,Tn,Un,Vn,Wn,Xn,Yn,Zn,zc,Ac,Rc,Sc,Tc,Zc,_c,$c,qe,re,se,vf,wf,xf,yf,zf,Af,Bf,Cf,Df,Ef,Ff,Gf,Hf,If,Mf,Jf,bk,en,zq,kr,qr,yr,Kr,Xr,ds,ks,os,ss,uv,yv,Mv,Sv,Pv,vy,Cy,Gy,Ny,Ry,Sy,oz,sz,tz,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA,nA];var jc=[oA,Bg,Cg,Dg,Eg,Fg,Gg,Hg,Ig,Jg,Kg,Lg,Mg,Ng,Og,Pg,Qg,Rg,Sg,Tg,Ug,Vg,Wg,Xg,Yg,Zg,_g,$g,ah,bh,ch,dh,eh,fh,gh,hh,ih,jh,kh,lh,mh,nh,oh,ph,qh,rh,sh,th,uh,vh,wh,xh,yh,zh,Ah,Bh,Ch,Dh,Eh,Fh,Gh,Hh,Ih,Jh,Kh,Lh,Mh,Nh,Oh,Ph,Qh,Rh,Sh,Th,Uh,Vh,Wh,Xh,Yh,Zh,_h,$h,ai,bi,ci,di,ei,fi,gi,hi,ii,ji,ki,li,mi,ni,oi,pi,qi,ri,si,ti,ui,vi,wi,xi,yi,zi,Ai,Bi,Ci,Di,Ei,Fi,Gi,Hi,Ii,Ji,Ki,Li,Mi,Ni,Oi,Pi,Qi,Ri,Si,Ti,Ui,Vi,Wi,Xi,Yi,Zi,_i,$i,aj,bj,cj,dj,ej,fj,gj,hj,ij,Cc,Vc,bd,ld,md,pe,me,ne,oe,je,ie,Ud,ap,Qd,Rd,Xo,he,ge,ce,Rf,Sf,Tf,Ov,Uv,Rv,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA,oA];var kc=[pA,Wr,cs,js,ns,rs,tv,xv,Wo,Py,qz,pA,pA,pA,pA,pA];var lc=[qA,id,Ce,De,Ee,oq,pq,qq,ep,fp,gp,le,Td,sf,tf,ee,Sp,Tp,Up,Bv,nq,qA,qA,qA,qA,qA,qA,qA,qA,qA,qA,qA];var mc=[rA,hd,ve,rA];var nc=[sA,uo,vo,wo,xo,yo,zo,Ao,Bo,Co,Do,Eo,Fo,Go,Ho,Io,Aq,Bq,lr,mr,rr,sr,tr,zr,Ar,Dr,Lr,Mr,wv,Av,wy,xy,yy,Dy,Ey,Hy,Iy,sA,sA,sA,sA,sA,sA,sA,sA,sA,sA,sA,sA,sA,sA,sA,sA,sA,sA,sA,sA,sA,sA,sA,sA,sA,sA,sA];var oc=[tA,ze,Ae,Be,kq,lq,mq,od,bp,cp,dp,ke,qf,rf,jd,Pp,Qp,Rp,_r,$r,gs,hs,tA,tA,tA,tA,tA,tA,tA,tA,tA,tA];var pc=[uA,as,is,uA];var qc=[vA,Dc,Wc,fe];return{_i64Subtract:Iz,_strcat:Pz,_free:zz,_main:ue,_realloc:Az,_i64Add:Jz,_tolower:Qz,_strlen:Kz,_memset:Oz,_malloc:yz,_memcpy:Mz,_bitshift64Lshr:Lz,_strcpy:Rz,_bitshift64Shl:Nz,runPostSets:Hz,stackAlloc:rc,stackSave:sc,stackRestore:tc,setThrew:uc,setTempRet0:xc,getTempRet0:yc,dynCall_iiii:aA,dynCall_viiiii:bA,dynCall_vi:cA,dynCall_vii:dA,dynCall_ii:eA,dynCall_viii:fA,dynCall_v:gA,dynCall_iiiii:hA,dynCall_iii:iA,dynCall_iiiiii:jA,dynCall_viiii:kA}})
|
||
|
|
||
|
|
||
|
// EMSCRIPTEN_END_ASM
|
||
|
({ "Math": Math, "Int8Array": Int8Array, "Int16Array": Int16Array, "Int32Array": Int32Array, "Uint8Array": Uint8Array, "Uint16Array": Uint16Array, "Uint32Array": Uint32Array, "Float32Array": Float32Array, "Float64Array": Float64Array }, { "abort": abort, "assert": assert, "asmPrintInt": asmPrintInt, "asmPrintFloat": asmPrintFloat, "min": Math_min, "invoke_iiii": invoke_iiii, "invoke_viiiii": invoke_viiiii, "invoke_vi": invoke_vi, "invoke_vii": invoke_vii, "invoke_ii": invoke_ii, "invoke_viii": invoke_viii, "invoke_v": invoke_v, "invoke_iiiii": invoke_iiiii, "invoke_iii": invoke_iii, "invoke_iiiiii": invoke_iiiiii, "invoke_viiii": invoke_viiii, "_fread": _fread, "_SDL_PauseAudio": _SDL_PauseAudio, "_atexit": _atexit, "_truncate": _truncate, "_fsync": _fsync, "_SDL_GetError": _SDL_GetError, "_signal": _signal, "_sbrk": _sbrk, "_SDL_OpenAudio": _SDL_OpenAudio, "_SDL_FreeSurface": _SDL_FreeSurface, "_emscripten_memcpy_big": _emscripten_memcpy_big, "_tcgetattr": _tcgetattr, "_sysconf": _sysconf, "_close": _close, "_SDL_InitSubSystem": _SDL_InitSubSystem, "_posix_openpt": _posix_openpt, "_puts": _puts, "_write": _write, "_ftell": _ftell, "_gmtime_r": _gmtime_r, "_SDL_WM_SetCaption": _SDL_WM_SetCaption, "_SDL_WasInit": _SDL_WasInit, "_send": _send, "_SDL_CreateRGBSurfaceFrom": _SDL_CreateRGBSurfaceFrom, "_SDL_GetTicks": _SDL_GetTicks, "_fcntl": _fcntl, "_SDL_LockAudio": _SDL_LockAudio, "_SDL_LockSurface": _SDL_LockSurface, "_strtol": _strtol, "___setErrNo": ___setErrNo, "_grantpt": _grantpt, "_unlink": _unlink, "_nanosleep": _nanosleep, "_gmtime": _gmtime, "_printf": _printf, "_sprintf": _sprintf, "_poll": _poll, "_localtime": _localtime, "_read": _read, "_SDL_SetVideoMode": _SDL_SetVideoMode, "_fwrite": _fwrite, "_time": _time, "_fprintf": _fprintf, "_gettimeofday": _gettimeofday, "_ptsname": _ptsname, "_exit": _exit, "_SDL_ShowCursor": _SDL_ShowCursor, "_lseek": _lseek, "_vfprintf": _vfprintf, "_pwrite": _pwrite, "_unlockpt": _unlockpt, "_localtime_r": _localtime_r, "_tzset": _tzset, "_open": _open, "_SDL_Init": _SDL_Init, "_SDL_WM_GrabInput": _SDL_WM_GrabInput, "_snprintf": _snprintf, "_ftruncate": _ftruncate, "_fseek": _fseek, "_SDL_GetMouseState": _SDL_GetMouseState, "_fclose": _fclose, "__parseInt": __parseInt, "_recv": _recv, "_tan": _tan, "_symlink": _symlink, "_abort": _abort, "_SDL_Flip": _SDL_Flip, "_isspace": _isspace, "_strtoul": _strtoul, "_fopen": _fopen, "_SDL_UnlockAudio": _SDL_UnlockAudio, "_tcflush": _tcflush, "_SDL_CloseAudio": _SDL_CloseAudio, "_usleep": _usleep, "_fflush": _fflush, "_SDL_GetVideoInfo": _SDL_GetVideoInfo, "__reallyNegative": __reallyNegative, "_SDL_PollEvent": _SDL_PollEvent, "_fileno": _fileno, "__exit": __exit, "_tcsetattr": _tcsetattr, "_fputs": _fputs, "_SDL_EventState": _SDL_EventState, "_pread": _pread, "_mkport": _mkport, "_emscripten_set_main_loop": _emscripten_set_main_loop, "___errno_location": ___errno_location, "_fgetc": _fgetc, "_fputc": _fputc, "_emscripten_cancel_main_loop": _emscripten_cancel_main_loop, "__formatString": __formatString, "_SDL_WM_ToggleFullScreen": _SDL_WM_ToggleFullScreen, "_SDL_UpperBlit": _SDL_UpperBlit, "_SDL_EnableKeyRepeat": _SDL_EnableKeyRepeat, "STACKTOP": STACKTOP, "STACK_MAX": STACK_MAX, "tempDoublePtr": tempDoublePtr, "ABORT": ABORT, "cttz_i8": cttz_i8, "ctlz_i8": ctlz_i8, "NaN": NaN, "Infinity": Infinity, "_stderr": _stderr, "_stdin": _stdin, "_stdout": _stdout }, buffer);
|
||
|
var _i64Subtract = Module["_i64Subtract"] = asm["_i64Subtract"];
|
||
|
var _strcat = Module["_strcat"] = asm["_strcat"];
|
||
|
var _free = Module["_free"] = asm["_free"];
|
||
|
var _main = Module["_main"] = asm["_main"];
|
||
|
var _realloc = Module["_realloc"] = asm["_realloc"];
|
||
|
var _i64Add = Module["_i64Add"] = asm["_i64Add"];
|
||
|
var _tolower = Module["_tolower"] = asm["_tolower"];
|
||
|
var _strlen = Module["_strlen"] = asm["_strlen"];
|
||
|
var _memset = Module["_memset"] = asm["_memset"];
|
||
|
var _malloc = Module["_malloc"] = asm["_malloc"];
|
||
|
var _memcpy = Module["_memcpy"] = asm["_memcpy"];
|
||
|
var _bitshift64Lshr = Module["_bitshift64Lshr"] = asm["_bitshift64Lshr"];
|
||
|
var _strcpy = Module["_strcpy"] = asm["_strcpy"];
|
||
|
var _bitshift64Shl = Module["_bitshift64Shl"] = asm["_bitshift64Shl"];
|
||
|
var runPostSets = Module["runPostSets"] = asm["runPostSets"];
|
||
|
var dynCall_iiii = Module["dynCall_iiii"] = asm["dynCall_iiii"];
|
||
|
var dynCall_viiiii = Module["dynCall_viiiii"] = asm["dynCall_viiiii"];
|
||
|
var dynCall_vi = Module["dynCall_vi"] = asm["dynCall_vi"];
|
||
|
var dynCall_vii = Module["dynCall_vii"] = asm["dynCall_vii"];
|
||
|
var dynCall_ii = Module["dynCall_ii"] = asm["dynCall_ii"];
|
||
|
var dynCall_viii = Module["dynCall_viii"] = asm["dynCall_viii"];
|
||
|
var dynCall_v = Module["dynCall_v"] = asm["dynCall_v"];
|
||
|
var dynCall_iiiii = Module["dynCall_iiiii"] = asm["dynCall_iiiii"];
|
||
|
var dynCall_iii = Module["dynCall_iii"] = asm["dynCall_iii"];
|
||
|
var dynCall_iiiiii = Module["dynCall_iiiiii"] = asm["dynCall_iiiiii"];
|
||
|
var dynCall_viiii = Module["dynCall_viiii"] = asm["dynCall_viiii"];
|
||
|
|
||
|
Runtime.stackAlloc = asm['stackAlloc'];
|
||
|
Runtime.stackSave = asm['stackSave'];
|
||
|
Runtime.stackRestore = asm['stackRestore'];
|
||
|
Runtime.setTempRet0 = asm['setTempRet0'];
|
||
|
Runtime.getTempRet0 = asm['getTempRet0'];
|
||
|
|
||
|
|
||
|
// TODO: strip out parts of this we do not need
|
||
|
|
||
|
//======= begin closure i64 code =======
|
||
|
|
||
|
// Copyright 2009 The Closure Library Authors. All Rights Reserved.
|
||
|
//
|
||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
// you may not use this file except in compliance with the License.
|
||
|
// You may obtain a copy of the License at
|
||
|
//
|
||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||
|
//
|
||
|
// Unless required by applicable law or agreed to in writing, software
|
||
|
// distributed under the License is distributed on an "AS-IS" BASIS,
|
||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
// See the License for the specific language governing permissions and
|
||
|
// limitations under the License.
|
||
|
|
||
|
/**
|
||
|
* @fileoverview Defines a Long class for representing a 64-bit two's-complement
|
||
|
* integer value, which faithfully simulates the behavior of a Java "long". This
|
||
|
* implementation is derived from LongLib in GWT.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
var i64Math = (function() { // Emscripten wrapper
|
||
|
var goog = { math: {} };
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Constructs a 64-bit two's-complement integer, given its low and high 32-bit
|
||
|
* values as *signed* integers. See the from* functions below for more
|
||
|
* convenient ways of constructing Longs.
|
||
|
*
|
||
|
* The internal representation of a long is the two given signed, 32-bit values.
|
||
|
* We use 32-bit pieces because these are the size of integers on which
|
||
|
* Javascript performs bit-operations. For operations like addition and
|
||
|
* multiplication, we split each number into 16-bit pieces, which can easily be
|
||
|
* multiplied within Javascript's floating-point representation without overflow
|
||
|
* or change in sign.
|
||
|
*
|
||
|
* In the algorithms below, we frequently reduce the negative case to the
|
||
|
* positive case by negating the input(s) and then post-processing the result.
|
||
|
* Note that we must ALWAYS check specially whether those values are MIN_VALUE
|
||
|
* (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as
|
||
|
* a positive number, it overflows back into a negative). Not handling this
|
||
|
* case would often result in infinite recursion.
|
||
|
*
|
||
|
* @param {number} low The low (signed) 32 bits of the long.
|
||
|
* @param {number} high The high (signed) 32 bits of the long.
|
||
|
* @constructor
|
||
|
*/
|
||
|
goog.math.Long = function(low, high) {
|
||
|
/**
|
||
|
* @type {number}
|
||
|
* @private
|
||
|
*/
|
||
|
this.low_ = low | 0; // force into 32 signed bits.
|
||
|
|
||
|
/**
|
||
|
* @type {number}
|
||
|
* @private
|
||
|
*/
|
||
|
this.high_ = high | 0; // force into 32 signed bits.
|
||
|
};
|
||
|
|
||
|
|
||
|
// NOTE: Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the
|
||
|
// from* methods on which they depend.
|
||
|
|
||
|
|
||
|
/**
|
||
|
* A cache of the Long representations of small integer values.
|
||
|
* @type {!Object}
|
||
|
* @private
|
||
|
*/
|
||
|
goog.math.Long.IntCache_ = {};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Returns a Long representing the given (32-bit) integer value.
|
||
|
* @param {number} value The 32-bit integer in question.
|
||
|
* @return {!goog.math.Long} The corresponding Long value.
|
||
|
*/
|
||
|
goog.math.Long.fromInt = function(value) {
|
||
|
if (-128 <= value && value < 128) {
|
||
|
var cachedObj = goog.math.Long.IntCache_[value];
|
||
|
if (cachedObj) {
|
||
|
return cachedObj;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var obj = new goog.math.Long(value | 0, value < 0 ? -1 : 0);
|
||
|
if (-128 <= value && value < 128) {
|
||
|
goog.math.Long.IntCache_[value] = obj;
|
||
|
}
|
||
|
return obj;
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Returns a Long representing the given value, provided that it is a finite
|
||
|
* number. Otherwise, zero is returned.
|
||
|
* @param {number} value The number in question.
|
||
|
* @return {!goog.math.Long} The corresponding Long value.
|
||
|
*/
|
||
|
goog.math.Long.fromNumber = function(value) {
|
||
|
if (isNaN(value) || !isFinite(value)) {
|
||
|
return goog.math.Long.ZERO;
|
||
|
} else if (value <= -goog.math.Long.TWO_PWR_63_DBL_) {
|
||
|
return goog.math.Long.MIN_VALUE;
|
||
|
} else if (value + 1 >= goog.math.Long.TWO_PWR_63_DBL_) {
|
||
|
return goog.math.Long.MAX_VALUE;
|
||
|
} else if (value < 0) {
|
||
|
return goog.math.Long.fromNumber(-value).negate();
|
||
|
} else {
|
||
|
return new goog.math.Long(
|
||
|
(value % goog.math.Long.TWO_PWR_32_DBL_) | 0,
|
||
|
(value / goog.math.Long.TWO_PWR_32_DBL_) | 0);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Returns a Long representing the 64-bit integer that comes by concatenating
|
||
|
* the given high and low bits. Each is assumed to use 32 bits.
|
||
|
* @param {number} lowBits The low 32-bits.
|
||
|
* @param {number} highBits The high 32-bits.
|
||
|
* @return {!goog.math.Long} The corresponding Long value.
|
||
|
*/
|
||
|
goog.math.Long.fromBits = function(lowBits, highBits) {
|
||
|
return new goog.math.Long(lowBits, highBits);
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Returns a Long representation of the given string, written using the given
|
||
|
* radix.
|
||
|
* @param {string} str The textual representation of the Long.
|
||
|
* @param {number=} opt_radix The radix in which the text is written.
|
||
|
* @return {!goog.math.Long} The corresponding Long value.
|
||
|
*/
|
||
|
goog.math.Long.fromString = function(str, opt_radix) {
|
||
|
if (str.length == 0) {
|
||
|
throw Error('number format error: empty string');
|
||
|
}
|
||
|
|
||
|
var radix = opt_radix || 10;
|
||
|
if (radix < 2 || 36 < radix) {
|
||
|
throw Error('radix out of range: ' + radix);
|
||
|
}
|
||
|
|
||
|
if (str.charAt(0) == '-') {
|
||
|
return goog.math.Long.fromString(str.substring(1), radix).negate();
|
||
|
} else if (str.indexOf('-') >= 0) {
|
||
|
throw Error('number format error: interior "-" character: ' + str);
|
||
|
}
|
||
|
|
||
|
// Do several (8) digits each time through the loop, so as to
|
||
|
// minimize the calls to the very expensive emulated div.
|
||
|
var radixToPower = goog.math.Long.fromNumber(Math.pow(radix, 8));
|
||
|
|
||
|
var result = goog.math.Long.ZERO;
|
||
|
for (var i = 0; i < str.length; i += 8) {
|
||
|
var size = Math.min(8, str.length - i);
|
||
|
var value = parseInt(str.substring(i, i + size), radix);
|
||
|
if (size < 8) {
|
||
|
var power = goog.math.Long.fromNumber(Math.pow(radix, size));
|
||
|
result = result.multiply(power).add(goog.math.Long.fromNumber(value));
|
||
|
} else {
|
||
|
result = result.multiply(radixToPower);
|
||
|
result = result.add(goog.math.Long.fromNumber(value));
|
||
|
}
|
||
|
}
|
||
|
return result;
|
||
|
};
|
||
|
|
||
|
|
||
|
// NOTE: the compiler should inline these constant values below and then remove
|
||
|
// these variables, so there should be no runtime penalty for these.
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Number used repeated below in calculations. This must appear before the
|
||
|
* first call to any from* function below.
|
||
|
* @type {number}
|
||
|
* @private
|
||
|
*/
|
||
|
goog.math.Long.TWO_PWR_16_DBL_ = 1 << 16;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @type {number}
|
||
|
* @private
|
||
|
*/
|
||
|
goog.math.Long.TWO_PWR_24_DBL_ = 1 << 24;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @type {number}
|
||
|
* @private
|
||
|
*/
|
||
|
goog.math.Long.TWO_PWR_32_DBL_ =
|
||
|
goog.math.Long.TWO_PWR_16_DBL_ * goog.math.Long.TWO_PWR_16_DBL_;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @type {number}
|
||
|
* @private
|
||
|
*/
|
||
|
goog.math.Long.TWO_PWR_31_DBL_ =
|
||
|
goog.math.Long.TWO_PWR_32_DBL_ / 2;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @type {number}
|
||
|
* @private
|
||
|
*/
|
||
|
goog.math.Long.TWO_PWR_48_DBL_ =
|
||
|
goog.math.Long.TWO_PWR_32_DBL_ * goog.math.Long.TWO_PWR_16_DBL_;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @type {number}
|
||
|
* @private
|
||
|
*/
|
||
|
goog.math.Long.TWO_PWR_64_DBL_ =
|
||
|
goog.math.Long.TWO_PWR_32_DBL_ * goog.math.Long.TWO_PWR_32_DBL_;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @type {number}
|
||
|
* @private
|
||
|
*/
|
||
|
goog.math.Long.TWO_PWR_63_DBL_ =
|
||
|
goog.math.Long.TWO_PWR_64_DBL_ / 2;
|
||
|
|
||
|
|
||
|
/** @type {!goog.math.Long} */
|
||
|
goog.math.Long.ZERO = goog.math.Long.fromInt(0);
|
||
|
|
||
|
|
||
|
/** @type {!goog.math.Long} */
|
||
|
goog.math.Long.ONE = goog.math.Long.fromInt(1);
|
||
|
|
||
|
|
||
|
/** @type {!goog.math.Long} */
|
||
|
goog.math.Long.NEG_ONE = goog.math.Long.fromInt(-1);
|
||
|
|
||
|
|
||
|
/** @type {!goog.math.Long} */
|
||
|
goog.math.Long.MAX_VALUE =
|
||
|
goog.math.Long.fromBits(0xFFFFFFFF | 0, 0x7FFFFFFF | 0);
|
||
|
|
||
|
|
||
|
/** @type {!goog.math.Long} */
|
||
|
goog.math.Long.MIN_VALUE = goog.math.Long.fromBits(0, 0x80000000 | 0);
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @type {!goog.math.Long}
|
||
|
* @private
|
||
|
*/
|
||
|
goog.math.Long.TWO_PWR_24_ = goog.math.Long.fromInt(1 << 24);
|
||
|
|
||
|
|
||
|
/** @return {number} The value, assuming it is a 32-bit integer. */
|
||
|
goog.math.Long.prototype.toInt = function() {
|
||
|
return this.low_;
|
||
|
};
|
||
|
|
||
|
|
||
|
/** @return {number} The closest floating-point representation to this value. */
|
||
|
goog.math.Long.prototype.toNumber = function() {
|
||
|
return this.high_ * goog.math.Long.TWO_PWR_32_DBL_ +
|
||
|
this.getLowBitsUnsigned();
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @param {number=} opt_radix The radix in which the text should be written.
|
||
|
* @return {string} The textual representation of this value.
|
||
|
*/
|
||
|
goog.math.Long.prototype.toString = function(opt_radix) {
|
||
|
var radix = opt_radix || 10;
|
||
|
if (radix < 2 || 36 < radix) {
|
||
|
throw Error('radix out of range: ' + radix);
|
||
|
}
|
||
|
|
||
|
if (this.isZero()) {
|
||
|
return '0';
|
||
|
}
|
||
|
|
||
|
if (this.isNegative()) {
|
||
|
if (this.equals(goog.math.Long.MIN_VALUE)) {
|
||
|
// We need to change the Long value before it can be negated, so we remove
|
||
|
// the bottom-most digit in this base and then recurse to do the rest.
|
||
|
var radixLong = goog.math.Long.fromNumber(radix);
|
||
|
var div = this.div(radixLong);
|
||
|
var rem = div.multiply(radixLong).subtract(this);
|
||
|
return div.toString(radix) + rem.toInt().toString(radix);
|
||
|
} else {
|
||
|
return '-' + this.negate().toString(radix);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Do several (6) digits each time through the loop, so as to
|
||
|
// minimize the calls to the very expensive emulated div.
|
||
|
var radixToPower = goog.math.Long.fromNumber(Math.pow(radix, 6));
|
||
|
|
||
|
var rem = this;
|
||
|
var result = '';
|
||
|
while (true) {
|
||
|
var remDiv = rem.div(radixToPower);
|
||
|
var intval = rem.subtract(remDiv.multiply(radixToPower)).toInt();
|
||
|
var digits = intval.toString(radix);
|
||
|
|
||
|
rem = remDiv;
|
||
|
if (rem.isZero()) {
|
||
|
return digits + result;
|
||
|
} else {
|
||
|
while (digits.length < 6) {
|
||
|
digits = '0' + digits;
|
||
|
}
|
||
|
result = '' + digits + result;
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
|
||
|
/** @return {number} The high 32-bits as a signed value. */
|
||
|
goog.math.Long.prototype.getHighBits = function() {
|
||
|
return this.high_;
|
||
|
};
|
||
|
|
||
|
|
||
|
/** @return {number} The low 32-bits as a signed value. */
|
||
|
goog.math.Long.prototype.getLowBits = function() {
|
||
|
return this.low_;
|
||
|
};
|
||
|
|
||
|
|
||
|
/** @return {number} The low 32-bits as an unsigned value. */
|
||
|
goog.math.Long.prototype.getLowBitsUnsigned = function() {
|
||
|
return (this.low_ >= 0) ?
|
||
|
this.low_ : goog.math.Long.TWO_PWR_32_DBL_ + this.low_;
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @return {number} Returns the number of bits needed to represent the absolute
|
||
|
* value of this Long.
|
||
|
*/
|
||
|
goog.math.Long.prototype.getNumBitsAbs = function() {
|
||
|
if (this.isNegative()) {
|
||
|
if (this.equals(goog.math.Long.MIN_VALUE)) {
|
||
|
return 64;
|
||
|
} else {
|
||
|
return this.negate().getNumBitsAbs();
|
||
|
}
|
||
|
} else {
|
||
|
var val = this.high_ != 0 ? this.high_ : this.low_;
|
||
|
for (var bit = 31; bit > 0; bit--) {
|
||
|
if ((val & (1 << bit)) != 0) {
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
return this.high_ != 0 ? bit + 33 : bit + 1;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
|
||
|
/** @return {boolean} Whether this value is zero. */
|
||
|
goog.math.Long.prototype.isZero = function() {
|
||
|
return this.high_ == 0 && this.low_ == 0;
|
||
|
};
|
||
|
|
||
|
|
||
|
/** @return {boolean} Whether this value is negative. */
|
||
|
goog.math.Long.prototype.isNegative = function() {
|
||
|
return this.high_ < 0;
|
||
|
};
|
||
|
|
||
|
|
||
|
/** @return {boolean} Whether this value is odd. */
|
||
|
goog.math.Long.prototype.isOdd = function() {
|
||
|
return (this.low_ & 1) == 1;
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @param {goog.math.Long} other Long to compare against.
|
||
|
* @return {boolean} Whether this Long equals the other.
|
||
|
*/
|
||
|
goog.math.Long.prototype.equals = function(other) {
|
||
|
return (this.high_ == other.high_) && (this.low_ == other.low_);
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @param {goog.math.Long} other Long to compare against.
|
||
|
* @return {boolean} Whether this Long does not equal the other.
|
||
|
*/
|
||
|
goog.math.Long.prototype.notEquals = function(other) {
|
||
|
return (this.high_ != other.high_) || (this.low_ != other.low_);
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @param {goog.math.Long} other Long to compare against.
|
||
|
* @return {boolean} Whether this Long is less than the other.
|
||
|
*/
|
||
|
goog.math.Long.prototype.lessThan = function(other) {
|
||
|
return this.compare(other) < 0;
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @param {goog.math.Long} other Long to compare against.
|
||
|
* @return {boolean} Whether this Long is less than or equal to the other.
|
||
|
*/
|
||
|
goog.math.Long.prototype.lessThanOrEqual = function(other) {
|
||
|
return this.compare(other) <= 0;
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @param {goog.math.Long} other Long to compare against.
|
||
|
* @return {boolean} Whether this Long is greater than the other.
|
||
|
*/
|
||
|
goog.math.Long.prototype.greaterThan = function(other) {
|
||
|
return this.compare(other) > 0;
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @param {goog.math.Long} other Long to compare against.
|
||
|
* @return {boolean} Whether this Long is greater than or equal to the other.
|
||
|
*/
|
||
|
goog.math.Long.prototype.greaterThanOrEqual = function(other) {
|
||
|
return this.compare(other) >= 0;
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Compares this Long with the given one.
|
||
|
* @param {goog.math.Long} other Long to compare against.
|
||
|
* @return {number} 0 if they are the same, 1 if the this is greater, and -1
|
||
|
* if the given one is greater.
|
||
|
*/
|
||
|
goog.math.Long.prototype.compare = function(other) {
|
||
|
if (this.equals(other)) {
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
var thisNeg = this.isNegative();
|
||
|
var otherNeg = other.isNegative();
|
||
|
if (thisNeg && !otherNeg) {
|
||
|
return -1;
|
||
|
}
|
||
|
if (!thisNeg && otherNeg) {
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
// at this point, the signs are the same, so subtraction will not overflow
|
||
|
if (this.subtract(other).isNegative()) {
|
||
|
return -1;
|
||
|
} else {
|
||
|
return 1;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
|
||
|
/** @return {!goog.math.Long} The negation of this value. */
|
||
|
goog.math.Long.prototype.negate = function() {
|
||
|
if (this.equals(goog.math.Long.MIN_VALUE)) {
|
||
|
return goog.math.Long.MIN_VALUE;
|
||
|
} else {
|
||
|
return this.not().add(goog.math.Long.ONE);
|
||
|
}
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Returns the sum of this and the given Long.
|
||
|
* @param {goog.math.Long} other Long to add to this one.
|
||
|
* @return {!goog.math.Long} The sum of this and the given Long.
|
||
|
*/
|
||
|
goog.math.Long.prototype.add = function(other) {
|
||
|
// Divide each number into 4 chunks of 16 bits, and then sum the chunks.
|
||
|
|
||
|
var a48 = this.high_ >>> 16;
|
||
|
var a32 = this.high_ & 0xFFFF;
|
||
|
var a16 = this.low_ >>> 16;
|
||
|
var a00 = this.low_ & 0xFFFF;
|
||
|
|
||
|
var b48 = other.high_ >>> 16;
|
||
|
var b32 = other.high_ & 0xFFFF;
|
||
|
var b16 = other.low_ >>> 16;
|
||
|
var b00 = other.low_ & 0xFFFF;
|
||
|
|
||
|
var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
|
||
|
c00 += a00 + b00;
|
||
|
c16 += c00 >>> 16;
|
||
|
c00 &= 0xFFFF;
|
||
|
c16 += a16 + b16;
|
||
|
c32 += c16 >>> 16;
|
||
|
c16 &= 0xFFFF;
|
||
|
c32 += a32 + b32;
|
||
|
c48 += c32 >>> 16;
|
||
|
c32 &= 0xFFFF;
|
||
|
c48 += a48 + b48;
|
||
|
c48 &= 0xFFFF;
|
||
|
return goog.math.Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32);
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Returns the difference of this and the given Long.
|
||
|
* @param {goog.math.Long} other Long to subtract from this.
|
||
|
* @return {!goog.math.Long} The difference of this and the given Long.
|
||
|
*/
|
||
|
goog.math.Long.prototype.subtract = function(other) {
|
||
|
return this.add(other.negate());
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Returns the product of this and the given long.
|
||
|
* @param {goog.math.Long} other Long to multiply with this.
|
||
|
* @return {!goog.math.Long} The product of this and the other.
|
||
|
*/
|
||
|
goog.math.Long.prototype.multiply = function(other) {
|
||
|
if (this.isZero()) {
|
||
|
return goog.math.Long.ZERO;
|
||
|
} else if (other.isZero()) {
|
||
|
return goog.math.Long.ZERO;
|
||
|
}
|
||
|
|
||
|
if (this.equals(goog.math.Long.MIN_VALUE)) {
|
||
|
return other.isOdd() ? goog.math.Long.MIN_VALUE : goog.math.Long.ZERO;
|
||
|
} else if (other.equals(goog.math.Long.MIN_VALUE)) {
|
||
|
return this.isOdd() ? goog.math.Long.MIN_VALUE : goog.math.Long.ZERO;
|
||
|
}
|
||
|
|
||
|
if (this.isNegative()) {
|
||
|
if (other.isNegative()) {
|
||
|
return this.negate().multiply(other.negate());
|
||
|
} else {
|
||
|
return this.negate().multiply(other).negate();
|
||
|
}
|
||
|
} else if (other.isNegative()) {
|
||
|
return this.multiply(other.negate()).negate();
|
||
|
}
|
||
|
|
||
|
// If both longs are small, use float multiplication
|
||
|
if (this.lessThan(goog.math.Long.TWO_PWR_24_) &&
|
||
|
other.lessThan(goog.math.Long.TWO_PWR_24_)) {
|
||
|
return goog.math.Long.fromNumber(this.toNumber() * other.toNumber());
|
||
|
}
|
||
|
|
||
|
// Divide each long into 4 chunks of 16 bits, and then add up 4x4 products.
|
||
|
// We can skip products that would overflow.
|
||
|
|
||
|
var a48 = this.high_ >>> 16;
|
||
|
var a32 = this.high_ & 0xFFFF;
|
||
|
var a16 = this.low_ >>> 16;
|
||
|
var a00 = this.low_ & 0xFFFF;
|
||
|
|
||
|
var b48 = other.high_ >>> 16;
|
||
|
var b32 = other.high_ & 0xFFFF;
|
||
|
var b16 = other.low_ >>> 16;
|
||
|
var b00 = other.low_ & 0xFFFF;
|
||
|
|
||
|
var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
|
||
|
c00 += a00 * b00;
|
||
|
c16 += c00 >>> 16;
|
||
|
c00 &= 0xFFFF;
|
||
|
c16 += a16 * b00;
|
||
|
c32 += c16 >>> 16;
|
||
|
c16 &= 0xFFFF;
|
||
|
c16 += a00 * b16;
|
||
|
c32 += c16 >>> 16;
|
||
|
c16 &= 0xFFFF;
|
||
|
c32 += a32 * b00;
|
||
|
c48 += c32 >>> 16;
|
||
|
c32 &= 0xFFFF;
|
||
|
c32 += a16 * b16;
|
||
|
c48 += c32 >>> 16;
|
||
|
c32 &= 0xFFFF;
|
||
|
c32 += a00 * b32;
|
||
|
c48 += c32 >>> 16;
|
||
|
c32 &= 0xFFFF;
|
||
|
c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
|
||
|
c48 &= 0xFFFF;
|
||
|
return goog.math.Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32);
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Returns this Long divided by the given one.
|
||
|
* @param {goog.math.Long} other Long by which to divide.
|
||
|
* @return {!goog.math.Long} This Long divided by the given one.
|
||
|
*/
|
||
|
goog.math.Long.prototype.div = function(other) {
|
||
|
if (other.isZero()) {
|
||
|
throw Error('division by zero');
|
||
|
} else if (this.isZero()) {
|
||
|
return goog.math.Long.ZERO;
|
||
|
}
|
||
|
|
||
|
if (this.equals(goog.math.Long.MIN_VALUE)) {
|
||
|
if (other.equals(goog.math.Long.ONE) ||
|
||
|
other.equals(goog.math.Long.NEG_ONE)) {
|
||
|
return goog.math.Long.MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE
|
||
|
} else if (other.equals(goog.math.Long.MIN_VALUE)) {
|
||
|
return goog.math.Long.ONE;
|
||
|
} else {
|
||
|
// At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|.
|
||
|
var halfThis = this.shiftRight(1);
|
||
|
var approx = halfThis.div(other).shiftLeft(1);
|
||
|
if (approx.equals(goog.math.Long.ZERO)) {
|
||
|
return other.isNegative() ? goog.math.Long.ONE : goog.math.Long.NEG_ONE;
|
||
|
} else {
|
||
|
var rem = this.subtract(other.multiply(approx));
|
||
|
var result = approx.add(rem.div(other));
|
||
|
return result;
|
||
|
}
|
||
|
}
|
||
|
} else if (other.equals(goog.math.Long.MIN_VALUE)) {
|
||
|
return goog.math.Long.ZERO;
|
||
|
}
|
||
|
|
||
|
if (this.isNegative()) {
|
||
|
if (other.isNegative()) {
|
||
|
return this.negate().div(other.negate());
|
||
|
} else {
|
||
|
return this.negate().div(other).negate();
|
||
|
}
|
||
|
} else if (other.isNegative()) {
|
||
|
return this.div(other.negate()).negate();
|
||
|
}
|
||
|
|
||
|
// Repeat the following until the remainder is less than other: find a
|
||
|
// floating-point that approximates remainder / other *from below*, add this
|
||
|
// into the result, and subtract it from the remainder. It is critical that
|
||
|
// the approximate value is less than or equal to the real value so that the
|
||
|
// remainder never becomes negative.
|
||
|
var res = goog.math.Long.ZERO;
|
||
|
var rem = this;
|
||
|
while (rem.greaterThanOrEqual(other)) {
|
||
|
// Approximate the result of division. This may be a little greater or
|
||
|
// smaller than the actual value.
|
||
|
var approx = Math.max(1, Math.floor(rem.toNumber() / other.toNumber()));
|
||
|
|
||
|
// We will tweak the approximate result by changing it in the 48-th digit or
|
||
|
// the smallest non-fractional digit, whichever is larger.
|
||
|
var log2 = Math.ceil(Math.log(approx) / Math.LN2);
|
||
|
var delta = (log2 <= 48) ? 1 : Math.pow(2, log2 - 48);
|
||
|
|
||
|
// Decrease the approximation until it is smaller than the remainder. Note
|
||
|
// that if it is too large, the product overflows and is negative.
|
||
|
var approxRes = goog.math.Long.fromNumber(approx);
|
||
|
var approxRem = approxRes.multiply(other);
|
||
|
while (approxRem.isNegative() || approxRem.greaterThan(rem)) {
|
||
|
approx -= delta;
|
||
|
approxRes = goog.math.Long.fromNumber(approx);
|
||
|
approxRem = approxRes.multiply(other);
|
||
|
}
|
||
|
|
||
|
// We know the answer can't be zero... and actually, zero would cause
|
||
|
// infinite recursion since we would make no progress.
|
||
|
if (approxRes.isZero()) {
|
||
|
approxRes = goog.math.Long.ONE;
|
||
|
}
|
||
|
|
||
|
res = res.add(approxRes);
|
||
|
rem = rem.subtract(approxRem);
|
||
|
}
|
||
|
return res;
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Returns this Long modulo the given one.
|
||
|
* @param {goog.math.Long} other Long by which to mod.
|
||
|
* @return {!goog.math.Long} This Long modulo the given one.
|
||
|
*/
|
||
|
goog.math.Long.prototype.modulo = function(other) {
|
||
|
return this.subtract(this.div(other).multiply(other));
|
||
|
};
|
||
|
|
||
|
|
||
|
/** @return {!goog.math.Long} The bitwise-NOT of this value. */
|
||
|
goog.math.Long.prototype.not = function() {
|
||
|
return goog.math.Long.fromBits(~this.low_, ~this.high_);
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Returns the bitwise-AND of this Long and the given one.
|
||
|
* @param {goog.math.Long} other The Long with which to AND.
|
||
|
* @return {!goog.math.Long} The bitwise-AND of this and the other.
|
||
|
*/
|
||
|
goog.math.Long.prototype.and = function(other) {
|
||
|
return goog.math.Long.fromBits(this.low_ & other.low_,
|
||
|
this.high_ & other.high_);
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Returns the bitwise-OR of this Long and the given one.
|
||
|
* @param {goog.math.Long} other The Long with which to OR.
|
||
|
* @return {!goog.math.Long} The bitwise-OR of this and the other.
|
||
|
*/
|
||
|
goog.math.Long.prototype.or = function(other) {
|
||
|
return goog.math.Long.fromBits(this.low_ | other.low_,
|
||
|
this.high_ | other.high_);
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Returns the bitwise-XOR of this Long and the given one.
|
||
|
* @param {goog.math.Long} other The Long with which to XOR.
|
||
|
* @return {!goog.math.Long} The bitwise-XOR of this and the other.
|
||
|
*/
|
||
|
goog.math.Long.prototype.xor = function(other) {
|
||
|
return goog.math.Long.fromBits(this.low_ ^ other.low_,
|
||
|
this.high_ ^ other.high_);
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Returns this Long with bits shifted to the left by the given amount.
|
||
|
* @param {number} numBits The number of bits by which to shift.
|
||
|
* @return {!goog.math.Long} This shifted to the left by the given amount.
|
||
|
*/
|
||
|
goog.math.Long.prototype.shiftLeft = function(numBits) {
|
||
|
numBits &= 63;
|
||
|
if (numBits == 0) {
|
||
|
return this;
|
||
|
} else {
|
||
|
var low = this.low_;
|
||
|
if (numBits < 32) {
|
||
|
var high = this.high_;
|
||
|
return goog.math.Long.fromBits(
|
||
|
low << numBits,
|
||
|
(high << numBits) | (low >>> (32 - numBits)));
|
||
|
} else {
|
||
|
return goog.math.Long.fromBits(0, low << (numBits - 32));
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Returns this Long with bits shifted to the right by the given amount.
|
||
|
* @param {number} numBits The number of bits by which to shift.
|
||
|
* @return {!goog.math.Long} This shifted to the right by the given amount.
|
||
|
*/
|
||
|
goog.math.Long.prototype.shiftRight = function(numBits) {
|
||
|
numBits &= 63;
|
||
|
if (numBits == 0) {
|
||
|
return this;
|
||
|
} else {
|
||
|
var high = this.high_;
|
||
|
if (numBits < 32) {
|
||
|
var low = this.low_;
|
||
|
return goog.math.Long.fromBits(
|
||
|
(low >>> numBits) | (high << (32 - numBits)),
|
||
|
high >> numBits);
|
||
|
} else {
|
||
|
return goog.math.Long.fromBits(
|
||
|
high >> (numBits - 32),
|
||
|
high >= 0 ? 0 : -1);
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Returns this Long with bits shifted to the right by the given amount, with
|
||
|
* the new top bits matching the current sign bit.
|
||
|
* @param {number} numBits The number of bits by which to shift.
|
||
|
* @return {!goog.math.Long} This shifted to the right by the given amount, with
|
||
|
* zeros placed into the new leading bits.
|
||
|
*/
|
||
|
goog.math.Long.prototype.shiftRightUnsigned = function(numBits) {
|
||
|
numBits &= 63;
|
||
|
if (numBits == 0) {
|
||
|
return this;
|
||
|
} else {
|
||
|
var high = this.high_;
|
||
|
if (numBits < 32) {
|
||
|
var low = this.low_;
|
||
|
return goog.math.Long.fromBits(
|
||
|
(low >>> numBits) | (high << (32 - numBits)),
|
||
|
high >>> numBits);
|
||
|
} else if (numBits == 32) {
|
||
|
return goog.math.Long.fromBits(high, 0);
|
||
|
} else {
|
||
|
return goog.math.Long.fromBits(high >>> (numBits - 32), 0);
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
//======= begin jsbn =======
|
||
|
|
||
|
var navigator = { appName: 'Modern Browser' }; // polyfill a little
|
||
|
|
||
|
// Copyright (c) 2005 Tom Wu
|
||
|
// All Rights Reserved.
|
||
|
// http://www-cs-students.stanford.edu/~tjw/jsbn/
|
||
|
|
||
|
/*
|
||
|
* Copyright (c) 2003-2005 Tom Wu
|
||
|
* All Rights Reserved.
|
||
|
*
|
||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||
|
* a copy of this software and associated documentation files (the
|
||
|
* "Software"), to deal in the Software without restriction, including
|
||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||
|
* the following conditions:
|
||
|
*
|
||
|
* The above copyright notice and this permission notice shall be
|
||
|
* included in all copies or substantial portions of the Software.
|
||
|
*
|
||
|
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||
|
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||
|
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||
|
*
|
||
|
* IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
|
||
|
* INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
|
||
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF
|
||
|
* THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT
|
||
|
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||
|
*
|
||
|
* In addition, the following condition applies:
|
||
|
*
|
||
|
* All redistributions must retain an intact copy of this copyright notice
|
||
|
* and disclaimer.
|
||
|
*/
|
||
|
|
||
|
// Basic JavaScript BN library - subset useful for RSA encryption.
|
||
|
|
||
|
// Bits per digit
|
||
|
var dbits;
|
||
|
|
||
|
// JavaScript engine analysis
|
||
|
var canary = 0xdeadbeefcafe;
|
||
|
var j_lm = ((canary&0xffffff)==0xefcafe);
|
||
|
|
||
|
// (public) Constructor
|
||
|
function BigInteger(a,b,c) {
|
||
|
if(a != null)
|
||
|
if("number" == typeof a) this.fromNumber(a,b,c);
|
||
|
else if(b == null && "string" != typeof a) this.fromString(a,256);
|
||
|
else this.fromString(a,b);
|
||
|
}
|
||
|
|
||
|
// return new, unset BigInteger
|
||
|
function nbi() { return new BigInteger(null); }
|
||
|
|
||
|
// am: Compute w_j += (x*this_i), propagate carries,
|
||
|
// c is initial carry, returns final carry.
|
||
|
// c < 3*dvalue, x < 2*dvalue, this_i < dvalue
|
||
|
// We need to select the fastest one that works in this environment.
|
||
|
|
||
|
// am1: use a single mult and divide to get the high bits,
|
||
|
// max digit bits should be 26 because
|
||
|
// max internal value = 2*dvalue^2-2*dvalue (< 2^53)
|
||
|
function am1(i,x,w,j,c,n) {
|
||
|
while(--n >= 0) {
|
||
|
var v = x*this[i++]+w[j]+c;
|
||
|
c = Math.floor(v/0x4000000);
|
||
|
w[j++] = v&0x3ffffff;
|
||
|
}
|
||
|
return c;
|
||
|
}
|
||
|
// am2 avoids a big mult-and-extract completely.
|
||
|
// Max digit bits should be <= 30 because we do bitwise ops
|
||
|
// on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
|
||
|
function am2(i,x,w,j,c,n) {
|
||
|
var xl = x&0x7fff, xh = x>>15;
|
||
|
while(--n >= 0) {
|
||
|
var l = this[i]&0x7fff;
|
||
|
var h = this[i++]>>15;
|
||
|
var m = xh*l+h*xl;
|
||
|
l = xl*l+((m&0x7fff)<<15)+w[j]+(c&0x3fffffff);
|
||
|
c = (l>>>30)+(m>>>15)+xh*h+(c>>>30);
|
||
|
w[j++] = l&0x3fffffff;
|
||
|
}
|
||
|
return c;
|
||
|
}
|
||
|
// Alternately, set max digit bits to 28 since some
|
||
|
// browsers slow down when dealing with 32-bit numbers.
|
||
|
function am3(i,x,w,j,c,n) {
|
||
|
var xl = x&0x3fff, xh = x>>14;
|
||
|
while(--n >= 0) {
|
||
|
var l = this[i]&0x3fff;
|
||
|
var h = this[i++]>>14;
|
||
|
var m = xh*l+h*xl;
|
||
|
l = xl*l+((m&0x3fff)<<14)+w[j]+c;
|
||
|
c = (l>>28)+(m>>14)+xh*h;
|
||
|
w[j++] = l&0xfffffff;
|
||
|
}
|
||
|
return c;
|
||
|
}
|
||
|
if(j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
|
||
|
BigInteger.prototype.am = am2;
|
||
|
dbits = 30;
|
||
|
}
|
||
|
else if(j_lm && (navigator.appName != "Netscape")) {
|
||
|
BigInteger.prototype.am = am1;
|
||
|
dbits = 26;
|
||
|
}
|
||
|
else { // Mozilla/Netscape seems to prefer am3
|
||
|
BigInteger.prototype.am = am3;
|
||
|
dbits = 28;
|
||
|
}
|
||
|
|
||
|
BigInteger.prototype.DB = dbits;
|
||
|
BigInteger.prototype.DM = ((1<<dbits)-1);
|
||
|
BigInteger.prototype.DV = (1<<dbits);
|
||
|
|
||
|
var BI_FP = 52;
|
||
|
BigInteger.prototype.FV = Math.pow(2,BI_FP);
|
||
|
BigInteger.prototype.F1 = BI_FP-dbits;
|
||
|
BigInteger.prototype.F2 = 2*dbits-BI_FP;
|
||
|
|
||
|
// Digit conversions
|
||
|
var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||
|
var BI_RC = new Array();
|
||
|
var rr,vv;
|
||
|
rr = "0".charCodeAt(0);
|
||
|
for(vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv;
|
||
|
rr = "a".charCodeAt(0);
|
||
|
for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
|
||
|
rr = "A".charCodeAt(0);
|
||
|
for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
|
||
|
|
||
|
function int2char(n) { return BI_RM.charAt(n); }
|
||
|
function intAt(s,i) {
|
||
|
var c = BI_RC[s.charCodeAt(i)];
|
||
|
return (c==null)?-1:c;
|
||
|
}
|
||
|
|
||
|
// (protected) copy this to r
|
||
|
function bnpCopyTo(r) {
|
||
|
for(var i = this.t-1; i >= 0; --i) r[i] = this[i];
|
||
|
r.t = this.t;
|
||
|
r.s = this.s;
|
||
|
}
|
||
|
|
||
|
// (protected) set from integer value x, -DV <= x < DV
|
||
|
function bnpFromInt(x) {
|
||
|
this.t = 1;
|
||
|
this.s = (x<0)?-1:0;
|
||
|
if(x > 0) this[0] = x;
|
||
|
else if(x < -1) this[0] = x+DV;
|
||
|
else this.t = 0;
|
||
|
}
|
||
|
|
||
|
// return bigint initialized to value
|
||
|
function nbv(i) { var r = nbi(); r.fromInt(i); return r; }
|
||
|
|
||
|
// (protected) set from string and radix
|
||
|
function bnpFromString(s,b) {
|
||
|
var k;
|
||
|
if(b == 16) k = 4;
|
||
|
else if(b == 8) k = 3;
|
||
|
else if(b == 256) k = 8; // byte array
|
||
|
else if(b == 2) k = 1;
|
||
|
else if(b == 32) k = 5;
|
||
|
else if(b == 4) k = 2;
|
||
|
else { this.fromRadix(s,b); return; }
|
||
|
this.t = 0;
|
||
|
this.s = 0;
|
||
|
var i = s.length, mi = false, sh = 0;
|
||
|
while(--i >= 0) {
|
||
|
var x = (k==8)?s[i]&0xff:intAt(s,i);
|
||
|
if(x < 0) {
|
||
|
if(s.charAt(i) == "-") mi = true;
|
||
|
continue;
|
||
|
}
|
||
|
mi = false;
|
||
|
if(sh == 0)
|
||
|
this[this.t++] = x;
|
||
|
else if(sh+k > this.DB) {
|
||
|
this[this.t-1] |= (x&((1<<(this.DB-sh))-1))<<sh;
|
||
|
this[this.t++] = (x>>(this.DB-sh));
|
||
|
}
|
||
|
else
|
||
|
this[this.t-1] |= x<<sh;
|
||
|
sh += k;
|
||
|
if(sh >= this.DB) sh -= this.DB;
|
||
|
}
|
||
|
if(k == 8 && (s[0]&0x80) != 0) {
|
||
|
this.s = -1;
|
||
|
if(sh > 0) this[this.t-1] |= ((1<<(this.DB-sh))-1)<<sh;
|
||
|
}
|
||
|
this.clamp();
|
||
|
if(mi) BigInteger.ZERO.subTo(this,this);
|
||
|
}
|
||
|
|
||
|
// (protected) clamp off excess high words
|
||
|
function bnpClamp() {
|
||
|
var c = this.s&this.DM;
|
||
|
while(this.t > 0 && this[this.t-1] == c) --this.t;
|
||
|
}
|
||
|
|
||
|
// (public) return string representation in given radix
|
||
|
function bnToString(b) {
|
||
|
if(this.s < 0) return "-"+this.negate().toString(b);
|
||
|
var k;
|
||
|
if(b == 16) k = 4;
|
||
|
else if(b == 8) k = 3;
|
||
|
else if(b == 2) k = 1;
|
||
|
else if(b == 32) k = 5;
|
||
|
else if(b == 4) k = 2;
|
||
|
else return this.toRadix(b);
|
||
|
var km = (1<<k)-1, d, m = false, r = "", i = this.t;
|
||
|
var p = this.DB-(i*this.DB)%k;
|
||
|
if(i-- > 0) {
|
||
|
if(p < this.DB && (d = this[i]>>p) > 0) { m = true; r = int2char(d); }
|
||
|
while(i >= 0) {
|
||
|
if(p < k) {
|
||
|
d = (this[i]&((1<<p)-1))<<(k-p);
|
||
|
d |= this[--i]>>(p+=this.DB-k);
|
||
|
}
|
||
|
else {
|
||
|
d = (this[i]>>(p-=k))&km;
|
||
|
if(p <= 0) { p += this.DB; --i; }
|
||
|
}
|
||
|
if(d > 0) m = true;
|
||
|
if(m) r += int2char(d);
|
||
|
}
|
||
|
}
|
||
|
return m?r:"0";
|
||
|
}
|
||
|
|
||
|
// (public) -this
|
||
|
function bnNegate() { var r = nbi(); BigInteger.ZERO.subTo(this,r); return r; }
|
||
|
|
||
|
// (public) |this|
|
||
|
function bnAbs() { return (this.s<0)?this.negate():this; }
|
||
|
|
||
|
// (public) return + if this > a, - if this < a, 0 if equal
|
||
|
function bnCompareTo(a) {
|
||
|
var r = this.s-a.s;
|
||
|
if(r != 0) return r;
|
||
|
var i = this.t;
|
||
|
r = i-a.t;
|
||
|
if(r != 0) return (this.s<0)?-r:r;
|
||
|
while(--i >= 0) if((r=this[i]-a[i]) != 0) return r;
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
// returns bit length of the integer x
|
||
|
function nbits(x) {
|
||
|
var r = 1, t;
|
||
|
if((t=x>>>16) != 0) { x = t; r += 16; }
|
||
|
if((t=x>>8) != 0) { x = t; r += 8; }
|
||
|
if((t=x>>4) != 0) { x = t; r += 4; }
|
||
|
if((t=x>>2) != 0) { x = t; r += 2; }
|
||
|
if((t=x>>1) != 0) { x = t; r += 1; }
|
||
|
return r;
|
||
|
}
|
||
|
|
||
|
// (public) return the number of bits in "this"
|
||
|
function bnBitLength() {
|
||
|
if(this.t <= 0) return 0;
|
||
|
return this.DB*(this.t-1)+nbits(this[this.t-1]^(this.s&this.DM));
|
||
|
}
|
||
|
|
||
|
// (protected) r = this << n*DB
|
||
|
function bnpDLShiftTo(n,r) {
|
||
|
var i;
|
||
|
for(i = this.t-1; i >= 0; --i) r[i+n] = this[i];
|
||
|
for(i = n-1; i >= 0; --i) r[i] = 0;
|
||
|
r.t = this.t+n;
|
||
|
r.s = this.s;
|
||
|
}
|
||
|
|
||
|
// (protected) r = this >> n*DB
|
||
|
function bnpDRShiftTo(n,r) {
|
||
|
for(var i = n; i < this.t; ++i) r[i-n] = this[i];
|
||
|
r.t = Math.max(this.t-n,0);
|
||
|
r.s = this.s;
|
||
|
}
|
||
|
|
||
|
// (protected) r = this << n
|
||
|
function bnpLShiftTo(n,r) {
|
||
|
var bs = n%this.DB;
|
||
|
var cbs = this.DB-bs;
|
||
|
var bm = (1<<cbs)-1;
|
||
|
var ds = Math.floor(n/this.DB), c = (this.s<<bs)&this.DM, i;
|
||
|
for(i = this.t-1; i >= 0; --i) {
|
||
|
r[i+ds+1] = (this[i]>>cbs)|c;
|
||
|
c = (this[i]&bm)<<bs;
|
||
|
}
|
||
|
for(i = ds-1; i >= 0; --i) r[i] = 0;
|
||
|
r[ds] = c;
|
||
|
r.t = this.t+ds+1;
|
||
|
r.s = this.s;
|
||
|
r.clamp();
|
||
|
}
|
||
|
|
||
|
// (protected) r = this >> n
|
||
|
function bnpRShiftTo(n,r) {
|
||
|
r.s = this.s;
|
||
|
var ds = Math.floor(n/this.DB);
|
||
|
if(ds >= this.t) { r.t = 0; return; }
|
||
|
var bs = n%this.DB;
|
||
|
var cbs = this.DB-bs;
|
||
|
var bm = (1<<bs)-1;
|
||
|
r[0] = this[ds]>>bs;
|
||
|
for(var i = ds+1; i < this.t; ++i) {
|
||
|
r[i-ds-1] |= (this[i]&bm)<<cbs;
|
||
|
r[i-ds] = this[i]>>bs;
|
||
|
}
|
||
|
if(bs > 0) r[this.t-ds-1] |= (this.s&bm)<<cbs;
|
||
|
r.t = this.t-ds;
|
||
|
r.clamp();
|
||
|
}
|
||
|
|
||
|
// (protected) r = this - a
|
||
|
function bnpSubTo(a,r) {
|
||
|
var i = 0, c = 0, m = Math.min(a.t,this.t);
|
||
|
while(i < m) {
|
||
|
c += this[i]-a[i];
|
||
|
r[i++] = c&this.DM;
|
||
|
c >>= this.DB;
|
||
|
}
|
||
|
if(a.t < this.t) {
|
||
|
c -= a.s;
|
||
|
while(i < this.t) {
|
||
|
c += this[i];
|
||
|
r[i++] = c&this.DM;
|
||
|
c >>= this.DB;
|
||
|
}
|
||
|
c += this.s;
|
||
|
}
|
||
|
else {
|
||
|
c += this.s;
|
||
|
while(i < a.t) {
|
||
|
c -= a[i];
|
||
|
r[i++] = c&this.DM;
|
||
|
c >>= this.DB;
|
||
|
}
|
||
|
c -= a.s;
|
||
|
}
|
||
|
r.s = (c<0)?-1:0;
|
||
|
if(c < -1) r[i++] = this.DV+c;
|
||
|
else if(c > 0) r[i++] = c;
|
||
|
r.t = i;
|
||
|
r.clamp();
|
||
|
}
|
||
|
|
||
|
// (protected) r = this * a, r != this,a (HAC 14.12)
|
||
|
// "this" should be the larger one if appropriate.
|
||
|
function bnpMultiplyTo(a,r) {
|
||
|
var x = this.abs(), y = a.abs();
|
||
|
var i = x.t;
|
||
|
r.t = i+y.t;
|
||
|
while(--i >= 0) r[i] = 0;
|
||
|
for(i = 0; i < y.t; ++i) r[i+x.t] = x.am(0,y[i],r,i,0,x.t);
|
||
|
r.s = 0;
|
||
|
r.clamp();
|
||
|
if(this.s != a.s) BigInteger.ZERO.subTo(r,r);
|
||
|
}
|
||
|
|
||
|
// (protected) r = this^2, r != this (HAC 14.16)
|
||
|
function bnpSquareTo(r) {
|
||
|
var x = this.abs();
|
||
|
var i = r.t = 2*x.t;
|
||
|
while(--i >= 0) r[i] = 0;
|
||
|
for(i = 0; i < x.t-1; ++i) {
|
||
|
var c = x.am(i,x[i],r,2*i,0,1);
|
||
|
if((r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1)) >= x.DV) {
|
||
|
r[i+x.t] -= x.DV;
|
||
|
r[i+x.t+1] = 1;
|
||
|
}
|
||
|
}
|
||
|
if(r.t > 0) r[r.t-1] += x.am(i,x[i],r,2*i,0,1);
|
||
|
r.s = 0;
|
||
|
r.clamp();
|
||
|
}
|
||
|
|
||
|
// (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
|
||
|
// r != q, this != m. q or r may be null.
|
||
|
function bnpDivRemTo(m,q,r) {
|
||
|
var pm = m.abs();
|
||
|
if(pm.t <= 0) return;
|
||
|
var pt = this.abs();
|
||
|
if(pt.t < pm.t) {
|
||
|
if(q != null) q.fromInt(0);
|
||
|
if(r != null) this.copyTo(r);
|
||
|
return;
|
||
|
}
|
||
|
if(r == null) r = nbi();
|
||
|
var y = nbi(), ts = this.s, ms = m.s;
|
||
|
var nsh = this.DB-nbits(pm[pm.t-1]); // normalize modulus
|
||
|
if(nsh > 0) { pm.lShiftTo(nsh,y); pt.lShiftTo(nsh,r); }
|
||
|
else { pm.copyTo(y); pt.copyTo(r); }
|
||
|
var ys = y.t;
|
||
|
var y0 = y[ys-1];
|
||
|
if(y0 == 0) return;
|
||
|
var yt = y0*(1<<this.F1)+((ys>1)?y[ys-2]>>this.F2:0);
|
||
|
var d1 = this.FV/yt, d2 = (1<<this.F1)/yt, e = 1<<this.F2;
|
||
|
var i = r.t, j = i-ys, t = (q==null)?nbi():q;
|
||
|
y.dlShiftTo(j,t);
|
||
|
if(r.compareTo(t) >= 0) {
|
||
|
r[r.t++] = 1;
|
||
|
r.subTo(t,r);
|
||
|
}
|
||
|
BigInteger.ONE.dlShiftTo(ys,t);
|
||
|
t.subTo(y,y); // "negative" y so we can replace sub with am later
|
||
|
while(y.t < ys) y[y.t++] = 0;
|
||
|
while(--j >= 0) {
|
||
|
// Estimate quotient digit
|
||
|
var qd = (r[--i]==y0)?this.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2);
|
||
|
if((r[i]+=y.am(0,qd,r,j,0,ys)) < qd) { // Try it out
|
||
|
y.dlShiftTo(j,t);
|
||
|
r.subTo(t,r);
|
||
|
while(r[i] < --qd) r.subTo(t,r);
|
||
|
}
|
||
|
}
|
||
|
if(q != null) {
|
||
|
r.drShiftTo(ys,q);
|
||
|
if(ts != ms) BigInteger.ZERO.subTo(q,q);
|
||
|
}
|
||
|
r.t = ys;
|
||
|
r.clamp();
|
||
|
if(nsh > 0) r.rShiftTo(nsh,r); // Denormalize remainder
|
||
|
if(ts < 0) BigInteger.ZERO.subTo(r,r);
|
||
|
}
|
||
|
|
||
|
// (public) this mod a
|
||
|
function bnMod(a) {
|
||
|
var r = nbi();
|
||
|
this.abs().divRemTo(a,null,r);
|
||
|
if(this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r,r);
|
||
|
return r;
|
||
|
}
|
||
|
|
||
|
// Modular reduction using "classic" algorithm
|
||
|
function Classic(m) { this.m = m; }
|
||
|
function cConvert(x) {
|
||
|
if(x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m);
|
||
|
else return x;
|
||
|
}
|
||
|
function cRevert(x) { return x; }
|
||
|
function cReduce(x) { x.divRemTo(this.m,null,x); }
|
||
|
function cMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
|
||
|
function cSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
|
||
|
|
||
|
Classic.prototype.convert = cConvert;
|
||
|
Classic.prototype.revert = cRevert;
|
||
|
Classic.prototype.reduce = cReduce;
|
||
|
Classic.prototype.mulTo = cMulTo;
|
||
|
Classic.prototype.sqrTo = cSqrTo;
|
||
|
|
||
|
// (protected) return "-1/this % 2^DB"; useful for Mont. reduction
|
||
|
// justification:
|
||
|
// xy == 1 (mod m)
|
||
|
// xy = 1+km
|
||
|
// xy(2-xy) = (1+km)(1-km)
|
||
|
// x[y(2-xy)] = 1-k^2m^2
|
||
|
// x[y(2-xy)] == 1 (mod m^2)
|
||
|
// if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
|
||
|
// should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
|
||
|
// JS multiply "overflows" differently from C/C++, so care is needed here.
|
||
|
function bnpInvDigit() {
|
||
|
if(this.t < 1) return 0;
|
||
|
var x = this[0];
|
||
|
if((x&1) == 0) return 0;
|
||
|
var y = x&3; // y == 1/x mod 2^2
|
||
|
y = (y*(2-(x&0xf)*y))&0xf; // y == 1/x mod 2^4
|
||
|
y = (y*(2-(x&0xff)*y))&0xff; // y == 1/x mod 2^8
|
||
|
y = (y*(2-(((x&0xffff)*y)&0xffff)))&0xffff; // y == 1/x mod 2^16
|
||
|
// last step - calculate inverse mod DV directly;
|
||
|
// assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
|
||
|
y = (y*(2-x*y%this.DV))%this.DV; // y == 1/x mod 2^dbits
|
||
|
// we really want the negative inverse, and -DV < y < DV
|
||
|
return (y>0)?this.DV-y:-y;
|
||
|
}
|
||
|
|
||
|
// Montgomery reduction
|
||
|
function Montgomery(m) {
|
||
|
this.m = m;
|
||
|
this.mp = m.invDigit();
|
||
|
this.mpl = this.mp&0x7fff;
|
||
|
this.mph = this.mp>>15;
|
||
|
this.um = (1<<(m.DB-15))-1;
|
||
|
this.mt2 = 2*m.t;
|
||
|
}
|
||
|
|
||
|
// xR mod m
|
||
|
function montConvert(x) {
|
||
|
var r = nbi();
|
||
|
x.abs().dlShiftTo(this.m.t,r);
|
||
|
r.divRemTo(this.m,null,r);
|
||
|
if(x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r,r);
|
||
|
return r;
|
||
|
}
|
||
|
|
||
|
// x/R mod m
|
||
|
function montRevert(x) {
|
||
|
var r = nbi();
|
||
|
x.copyTo(r);
|
||
|
this.reduce(r);
|
||
|
return r;
|
||
|
}
|
||
|
|
||
|
// x = x/R mod m (HAC 14.32)
|
||
|
function montReduce(x) {
|
||
|
while(x.t <= this.mt2) // pad x so am has enough room later
|
||
|
x[x.t++] = 0;
|
||
|
for(var i = 0; i < this.m.t; ++i) {
|
||
|
// faster way of calculating u0 = x[i]*mp mod DV
|
||
|
var j = x[i]&0x7fff;
|
||
|
var u0 = (j*this.mpl+(((j*this.mph+(x[i]>>15)*this.mpl)&this.um)<<15))&x.DM;
|
||
|
// use am to combine the multiply-shift-add into one call
|
||
|
j = i+this.m.t;
|
||
|
x[j] += this.m.am(0,u0,x,i,0,this.m.t);
|
||
|
// propagate carry
|
||
|
while(x[j] >= x.DV) { x[j] -= x.DV; x[++j]++; }
|
||
|
}
|
||
|
x.clamp();
|
||
|
x.drShiftTo(this.m.t,x);
|
||
|
if(x.compareTo(this.m) >= 0) x.subTo(this.m,x);
|
||
|
}
|
||
|
|
||
|
// r = "x^2/R mod m"; x != r
|
||
|
function montSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
|
||
|
|
||
|
// r = "xy/R mod m"; x,y != r
|
||
|
function montMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
|
||
|
|
||
|
Montgomery.prototype.convert = montConvert;
|
||
|
Montgomery.prototype.revert = montRevert;
|
||
|
Montgomery.prototype.reduce = montReduce;
|
||
|
Montgomery.prototype.mulTo = montMulTo;
|
||
|
Montgomery.prototype.sqrTo = montSqrTo;
|
||
|
|
||
|
// (protected) true iff this is even
|
||
|
function bnpIsEven() { return ((this.t>0)?(this[0]&1):this.s) == 0; }
|
||
|
|
||
|
// (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
|
||
|
function bnpExp(e,z) {
|
||
|
if(e > 0xffffffff || e < 1) return BigInteger.ONE;
|
||
|
var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e)-1;
|
||
|
g.copyTo(r);
|
||
|
while(--i >= 0) {
|
||
|
z.sqrTo(r,r2);
|
||
|
if((e&(1<<i)) > 0) z.mulTo(r2,g,r);
|
||
|
else { var t = r; r = r2; r2 = t; }
|
||
|
}
|
||
|
return z.revert(r);
|
||
|
}
|
||
|
|
||
|
// (public) this^e % m, 0 <= e < 2^32
|
||
|
function bnModPowInt(e,m) {
|
||
|
var z;
|
||
|
if(e < 256 || m.isEven()) z = new Classic(m); else z = new Montgomery(m);
|
||
|
return this.exp(e,z);
|
||
|
}
|
||
|
|
||
|
// protected
|
||
|
BigInteger.prototype.copyTo = bnpCopyTo;
|
||
|
BigInteger.prototype.fromInt = bnpFromInt;
|
||
|
BigInteger.prototype.fromString = bnpFromString;
|
||
|
BigInteger.prototype.clamp = bnpClamp;
|
||
|
BigInteger.prototype.dlShiftTo = bnpDLShiftTo;
|
||
|
BigInteger.prototype.drShiftTo = bnpDRShiftTo;
|
||
|
BigInteger.prototype.lShiftTo = bnpLShiftTo;
|
||
|
BigInteger.prototype.rShiftTo = bnpRShiftTo;
|
||
|
BigInteger.prototype.subTo = bnpSubTo;
|
||
|
BigInteger.prototype.multiplyTo = bnpMultiplyTo;
|
||
|
BigInteger.prototype.squareTo = bnpSquareTo;
|
||
|
BigInteger.prototype.divRemTo = bnpDivRemTo;
|
||
|
BigInteger.prototype.invDigit = bnpInvDigit;
|
||
|
BigInteger.prototype.isEven = bnpIsEven;
|
||
|
BigInteger.prototype.exp = bnpExp;
|
||
|
|
||
|
// public
|
||
|
BigInteger.prototype.toString = bnToString;
|
||
|
BigInteger.prototype.negate = bnNegate;
|
||
|
BigInteger.prototype.abs = bnAbs;
|
||
|
BigInteger.prototype.compareTo = bnCompareTo;
|
||
|
BigInteger.prototype.bitLength = bnBitLength;
|
||
|
BigInteger.prototype.mod = bnMod;
|
||
|
BigInteger.prototype.modPowInt = bnModPowInt;
|
||
|
|
||
|
// "constants"
|
||
|
BigInteger.ZERO = nbv(0);
|
||
|
BigInteger.ONE = nbv(1);
|
||
|
|
||
|
// jsbn2 stuff
|
||
|
|
||
|
// (protected) convert from radix string
|
||
|
function bnpFromRadix(s,b) {
|
||
|
this.fromInt(0);
|
||
|
if(b == null) b = 10;
|
||
|
var cs = this.chunkSize(b);
|
||
|
var d = Math.pow(b,cs), mi = false, j = 0, w = 0;
|
||
|
for(var i = 0; i < s.length; ++i) {
|
||
|
var x = intAt(s,i);
|
||
|
if(x < 0) {
|
||
|
if(s.charAt(i) == "-" && this.signum() == 0) mi = true;
|
||
|
continue;
|
||
|
}
|
||
|
w = b*w+x;
|
||
|
if(++j >= cs) {
|
||
|
this.dMultiply(d);
|
||
|
this.dAddOffset(w,0);
|
||
|
j = 0;
|
||
|
w = 0;
|
||
|
}
|
||
|
}
|
||
|
if(j > 0) {
|
||
|
this.dMultiply(Math.pow(b,j));
|
||
|
this.dAddOffset(w,0);
|
||
|
}
|
||
|
if(mi) BigInteger.ZERO.subTo(this,this);
|
||
|
}
|
||
|
|
||
|
// (protected) return x s.t. r^x < DV
|
||
|
function bnpChunkSize(r) { return Math.floor(Math.LN2*this.DB/Math.log(r)); }
|
||
|
|
||
|
// (public) 0 if this == 0, 1 if this > 0
|
||
|
function bnSigNum() {
|
||
|
if(this.s < 0) return -1;
|
||
|
else if(this.t <= 0 || (this.t == 1 && this[0] <= 0)) return 0;
|
||
|
else return 1;
|
||
|
}
|
||
|
|
||
|
// (protected) this *= n, this >= 0, 1 < n < DV
|
||
|
function bnpDMultiply(n) {
|
||
|
this[this.t] = this.am(0,n-1,this,0,0,this.t);
|
||
|
++this.t;
|
||
|
this.clamp();
|
||
|
}
|
||
|
|
||
|
// (protected) this += n << w words, this >= 0
|
||
|
function bnpDAddOffset(n,w) {
|
||
|
if(n == 0) return;
|
||
|
while(this.t <= w) this[this.t++] = 0;
|
||
|
this[w] += n;
|
||
|
while(this[w] >= this.DV) {
|
||
|
this[w] -= this.DV;
|
||
|
if(++w >= this.t) this[this.t++] = 0;
|
||
|
++this[w];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// (protected) convert to radix string
|
||
|
function bnpToRadix(b) {
|
||
|
if(b == null) b = 10;
|
||
|
if(this.signum() == 0 || b < 2 || b > 36) return "0";
|
||
|
var cs = this.chunkSize(b);
|
||
|
var a = Math.pow(b,cs);
|
||
|
var d = nbv(a), y = nbi(), z = nbi(), r = "";
|
||
|
this.divRemTo(d,y,z);
|
||
|
while(y.signum() > 0) {
|
||
|
r = (a+z.intValue()).toString(b).substr(1) + r;
|
||
|
y.divRemTo(d,y,z);
|
||
|
}
|
||
|
return z.intValue().toString(b) + r;
|
||
|
}
|
||
|
|
||
|
// (public) return value as integer
|
||
|
function bnIntValue() {
|
||
|
if(this.s < 0) {
|
||
|
if(this.t == 1) return this[0]-this.DV;
|
||
|
else if(this.t == 0) return -1;
|
||
|
}
|
||
|
else if(this.t == 1) return this[0];
|
||
|
else if(this.t == 0) return 0;
|
||
|
// assumes 16 < DB < 32
|
||
|
return ((this[1]&((1<<(32-this.DB))-1))<<this.DB)|this[0];
|
||
|
}
|
||
|
|
||
|
// (protected) r = this + a
|
||
|
function bnpAddTo(a,r) {
|
||
|
var i = 0, c = 0, m = Math.min(a.t,this.t);
|
||
|
while(i < m) {
|
||
|
c += this[i]+a[i];
|
||
|
r[i++] = c&this.DM;
|
||
|
c >>= this.DB;
|
||
|
}
|
||
|
if(a.t < this.t) {
|
||
|
c += a.s;
|
||
|
while(i < this.t) {
|
||
|
c += this[i];
|
||
|
r[i++] = c&this.DM;
|
||
|
c >>= this.DB;
|
||
|
}
|
||
|
c += this.s;
|
||
|
}
|
||
|
else {
|
||
|
c += this.s;
|
||
|
while(i < a.t) {
|
||
|
c += a[i];
|
||
|
r[i++] = c&this.DM;
|
||
|
c >>= this.DB;
|
||
|
}
|
||
|
c += a.s;
|
||
|
}
|
||
|
r.s = (c<0)?-1:0;
|
||
|
if(c > 0) r[i++] = c;
|
||
|
else if(c < -1) r[i++] = this.DV+c;
|
||
|
r.t = i;
|
||
|
r.clamp();
|
||
|
}
|
||
|
|
||
|
BigInteger.prototype.fromRadix = bnpFromRadix;
|
||
|
BigInteger.prototype.chunkSize = bnpChunkSize;
|
||
|
BigInteger.prototype.signum = bnSigNum;
|
||
|
BigInteger.prototype.dMultiply = bnpDMultiply;
|
||
|
BigInteger.prototype.dAddOffset = bnpDAddOffset;
|
||
|
BigInteger.prototype.toRadix = bnpToRadix;
|
||
|
BigInteger.prototype.intValue = bnIntValue;
|
||
|
BigInteger.prototype.addTo = bnpAddTo;
|
||
|
|
||
|
//======= end jsbn =======
|
||
|
|
||
|
// Emscripten wrapper
|
||
|
var Wrapper = {
|
||
|
abs: function(l, h) {
|
||
|
var x = new goog.math.Long(l, h);
|
||
|
var ret;
|
||
|
if (x.isNegative()) {
|
||
|
ret = x.negate();
|
||
|
} else {
|
||
|
ret = x;
|
||
|
}
|
||
|
HEAP32[tempDoublePtr>>2] = ret.low_;
|
||
|
HEAP32[tempDoublePtr+4>>2] = ret.high_;
|
||
|
},
|
||
|
ensureTemps: function() {
|
||
|
if (Wrapper.ensuredTemps) return;
|
||
|
Wrapper.ensuredTemps = true;
|
||
|
Wrapper.two32 = new BigInteger();
|
||
|
Wrapper.two32.fromString('4294967296', 10);
|
||
|
Wrapper.two64 = new BigInteger();
|
||
|
Wrapper.two64.fromString('18446744073709551616', 10);
|
||
|
Wrapper.temp1 = new BigInteger();
|
||
|
Wrapper.temp2 = new BigInteger();
|
||
|
},
|
||
|
lh2bignum: function(l, h) {
|
||
|
var a = new BigInteger();
|
||
|
a.fromString(h.toString(), 10);
|
||
|
var b = new BigInteger();
|
||
|
a.multiplyTo(Wrapper.two32, b);
|
||
|
var c = new BigInteger();
|
||
|
c.fromString(l.toString(), 10);
|
||
|
var d = new BigInteger();
|
||
|
c.addTo(b, d);
|
||
|
return d;
|
||
|
},
|
||
|
stringify: function(l, h, unsigned) {
|
||
|
var ret = new goog.math.Long(l, h).toString();
|
||
|
if (unsigned && ret[0] == '-') {
|
||
|
// unsign slowly using jsbn bignums
|
||
|
Wrapper.ensureTemps();
|
||
|
var bignum = new BigInteger();
|
||
|
bignum.fromString(ret, 10);
|
||
|
ret = new BigInteger();
|
||
|
Wrapper.two64.addTo(bignum, ret);
|
||
|
ret = ret.toString(10);
|
||
|
}
|
||
|
return ret;
|
||
|
},
|
||
|
fromString: function(str, base, min, max, unsigned) {
|
||
|
Wrapper.ensureTemps();
|
||
|
var bignum = new BigInteger();
|
||
|
bignum.fromString(str, base);
|
||
|
var bigmin = new BigInteger();
|
||
|
bigmin.fromString(min, 10);
|
||
|
var bigmax = new BigInteger();
|
||
|
bigmax.fromString(max, 10);
|
||
|
if (unsigned && bignum.compareTo(BigInteger.ZERO) < 0) {
|
||
|
var temp = new BigInteger();
|
||
|
bignum.addTo(Wrapper.two64, temp);
|
||
|
bignum = temp;
|
||
|
}
|
||
|
var error = false;
|
||
|
if (bignum.compareTo(bigmin) < 0) {
|
||
|
bignum = bigmin;
|
||
|
error = true;
|
||
|
} else if (bignum.compareTo(bigmax) > 0) {
|
||
|
bignum = bigmax;
|
||
|
error = true;
|
||
|
}
|
||
|
var ret = goog.math.Long.fromString(bignum.toString()); // min-max checks should have clamped this to a range goog.math.Long can handle well
|
||
|
HEAP32[tempDoublePtr>>2] = ret.low_;
|
||
|
HEAP32[tempDoublePtr+4>>2] = ret.high_;
|
||
|
if (error) throw 'range error';
|
||
|
}
|
||
|
};
|
||
|
return Wrapper;
|
||
|
})();
|
||
|
|
||
|
//======= end closure i64 code =======
|
||
|
|
||
|
|
||
|
|
||
|
// === Auto-generated postamble setup entry stuff ===
|
||
|
|
||
|
if (memoryInitializer) {
|
||
|
if (ENVIRONMENT_IS_NODE || ENVIRONMENT_IS_SHELL) {
|
||
|
var data = Module['readBinary'](memoryInitializer);
|
||
|
HEAPU8.set(data, STATIC_BASE);
|
||
|
} else {
|
||
|
addRunDependency('memory initializer');
|
||
|
Browser.asyncLoad(memoryInitializer, function(data) {
|
||
|
HEAPU8.set(data, STATIC_BASE);
|
||
|
removeRunDependency('memory initializer');
|
||
|
}, function(data) {
|
||
|
throw 'could not load memory initializer ' + memoryInitializer;
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function ExitStatus(status) {
|
||
|
this.name = "ExitStatus";
|
||
|
this.message = "Program terminated with exit(" + status + ")";
|
||
|
this.status = status;
|
||
|
};
|
||
|
ExitStatus.prototype = new Error();
|
||
|
ExitStatus.prototype.constructor = ExitStatus;
|
||
|
|
||
|
var initialStackTop;
|
||
|
var preloadStartTime = null;
|
||
|
var calledMain = false;
|
||
|
|
||
|
dependenciesFulfilled = function runCaller() {
|
||
|
// If run has never been called, and we should call run (INVOKE_RUN is true, and Module.noInitialRun is not false)
|
||
|
if (!Module['calledRun'] && shouldRunNow) run();
|
||
|
if (!Module['calledRun']) dependenciesFulfilled = runCaller; // try this again later, after new deps are fulfilled
|
||
|
}
|
||
|
|
||
|
Module['callMain'] = Module.callMain = function callMain(args) {
|
||
|
assert(runDependencies == 0, 'cannot call main when async dependencies remain! (listen on __ATMAIN__)');
|
||
|
assert(__ATPRERUN__.length == 0, 'cannot call main when preRun functions remain to be called');
|
||
|
|
||
|
args = args || [];
|
||
|
|
||
|
ensureInitRuntime();
|
||
|
|
||
|
var argc = args.length+1;
|
||
|
function pad() {
|
||
|
for (var i = 0; i < 4-1; i++) {
|
||
|
argv.push(0);
|
||
|
}
|
||
|
}
|
||
|
var argv = [allocate(intArrayFromString("/bin/this.program"), 'i8', ALLOC_NORMAL) ];
|
||
|
pad();
|
||
|
for (var i = 0; i < argc-1; i = i + 1) {
|
||
|
argv.push(allocate(intArrayFromString(args[i]), 'i8', ALLOC_NORMAL));
|
||
|
pad();
|
||
|
}
|
||
|
argv.push(0);
|
||
|
argv = allocate(argv, 'i32', ALLOC_NORMAL);
|
||
|
|
||
|
initialStackTop = STACKTOP;
|
||
|
|
||
|
try {
|
||
|
|
||
|
var ret = Module['_main'](argc, argv, 0);
|
||
|
|
||
|
|
||
|
// if we're not running an evented main loop, it's time to exit
|
||
|
if (!Module['noExitRuntime']) {
|
||
|
exit(ret);
|
||
|
}
|
||
|
}
|
||
|
catch(e) {
|
||
|
if (e instanceof ExitStatus) {
|
||
|
// exit() throws this once it's done to make sure execution
|
||
|
// has been stopped completely
|
||
|
return;
|
||
|
} else if (e == 'SimulateInfiniteLoop') {
|
||
|
// running an evented main loop, don't immediately exit
|
||
|
Module['noExitRuntime'] = true;
|
||
|
return;
|
||
|
} else {
|
||
|
if (e && typeof e === 'object' && e.stack) Module.printErr('exception thrown: ' + [e, e.stack]);
|
||
|
throw e;
|
||
|
}
|
||
|
} finally {
|
||
|
calledMain = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
function run(args) {
|
||
|
args = args || Module['arguments'];
|
||
|
|
||
|
if (preloadStartTime === null) preloadStartTime = Date.now();
|
||
|
|
||
|
if (runDependencies > 0) {
|
||
|
Module.printErr('run() called, but dependencies remain, so not running');
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
preRun();
|
||
|
|
||
|
if (runDependencies > 0) return; // a preRun added a dependency, run will be called later
|
||
|
if (Module['calledRun']) return; // run may have just been called through dependencies being fulfilled just in this very frame
|
||
|
|
||
|
function doRun() {
|
||
|
if (Module['calledRun']) return; // run may have just been called while the async setStatus time below was happening
|
||
|
Module['calledRun'] = true;
|
||
|
|
||
|
ensureInitRuntime();
|
||
|
|
||
|
preMain();
|
||
|
|
||
|
if (ENVIRONMENT_IS_WEB && preloadStartTime !== null) {
|
||
|
Module.printErr('pre-main prep time: ' + (Date.now() - preloadStartTime) + ' ms');
|
||
|
}
|
||
|
|
||
|
if (Module['_main'] && shouldRunNow) {
|
||
|
Module['callMain'](args);
|
||
|
}
|
||
|
|
||
|
postRun();
|
||
|
}
|
||
|
|
||
|
if (Module['setStatus']) {
|
||
|
Module['setStatus']('Running...');
|
||
|
setTimeout(function() {
|
||
|
setTimeout(function() {
|
||
|
Module['setStatus']('');
|
||
|
}, 1);
|
||
|
if (!ABORT) doRun();
|
||
|
}, 1);
|
||
|
} else {
|
||
|
doRun();
|
||
|
}
|
||
|
}
|
||
|
Module['run'] = Module.run = run;
|
||
|
|
||
|
function exit(status) {
|
||
|
ABORT = true;
|
||
|
EXITSTATUS = status;
|
||
|
STACKTOP = initialStackTop;
|
||
|
|
||
|
// exit the runtime
|
||
|
exitRuntime();
|
||
|
|
||
|
// TODO We should handle this differently based on environment.
|
||
|
// In the browser, the best we can do is throw an exception
|
||
|
// to halt execution, but in node we could process.exit and
|
||
|
// I'd imagine SM shell would have something equivalent.
|
||
|
// This would let us set a proper exit status (which
|
||
|
// would be great for checking test exit statuses).
|
||
|
// https://github.com/kripken/emscripten/issues/1371
|
||
|
|
||
|
// throw an exception to halt the current execution
|
||
|
throw new ExitStatus(status);
|
||
|
}
|
||
|
Module['exit'] = Module.exit = exit;
|
||
|
|
||
|
function abort(text) {
|
||
|
if (text) {
|
||
|
Module.print(text);
|
||
|
Module.printErr(text);
|
||
|
}
|
||
|
|
||
|
ABORT = true;
|
||
|
EXITSTATUS = 1;
|
||
|
|
||
|
var extra = '\nIf this abort() is unexpected, build with -s ASSERTIONS=1 which can give more information.';
|
||
|
|
||
|
throw 'abort() at ' + stackTrace() + extra;
|
||
|
}
|
||
|
Module['abort'] = Module.abort = abort;
|
||
|
|
||
|
// {{PRE_RUN_ADDITIONS}}
|
||
|
|
||
|
if (Module['preInit']) {
|
||
|
if (typeof Module['preInit'] == 'function') Module['preInit'] = [Module['preInit']];
|
||
|
while (Module['preInit'].length > 0) {
|
||
|
Module['preInit'].pop()();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// shouldRunNow refers to calling main(), not run().
|
||
|
var shouldRunNow = true;
|
||
|
if (Module['noInitialRun']) {
|
||
|
shouldRunNow = false;
|
||
|
}
|
||
|
|
||
|
|
||
|
run();
|
||
|
|
||
|
// {{POST_RUN_ADDITIONS}}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// {{MODULE_ADDITIONS}}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// expose apis
|
||
|
|
||
|
Module.FS = FS
|
||
|
Module.IDBFS = IDBFS
|
||
|
Module.NODEFS = NODEFS
|
||
|
Module.PATH = PATH
|
||
|
Module.ERRNO_CODES = ERRNO_CODES
|
||
|
Module.ERRNO_MESSAGES = ERRNO_MESSAGES
|
||
|
|
||
|
return Module;
|
||
|
}
|
||
|
},{}],3:[function(require,module,exports){
|
||
|
module.exports = extend
|
||
|
|
||
|
function extend() {
|
||
|
var target = {}
|
||
|
|
||
|
for (var i = 0; i < arguments.length; i++) {
|
||
|
var source = arguments[i]
|
||
|
|
||
|
for (var key in source) {
|
||
|
if (source.hasOwnProperty(key)) {
|
||
|
target[key] = source[key]
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return target
|
||
|
}
|
||
|
|
||
|
},{}],4:[function(require,module,exports){
|
||
|
module.exports = {
|
||
|
loadingStatus: loadingStatus,
|
||
|
}
|
||
|
|
||
|
function setElAttrs(el, attrs) {
|
||
|
Object.keys(attrs).forEach(function(key) {
|
||
|
el.setAttribute(key, attrs[key])
|
||
|
})
|
||
|
return el
|
||
|
}
|
||
|
|
||
|
function emptyEl(el) {
|
||
|
while (el.firstChild) el.removeChild(el.firstChild)
|
||
|
return el
|
||
|
}
|
||
|
|
||
|
function loadingStatus(loadingStatusEl) {
|
||
|
var initialStatus = loadingStatusEl.innerText
|
||
|
|
||
|
emptyEl(loadingStatusEl)
|
||
|
|
||
|
var statusEl = setElAttrs(document.createElement("div"), {innerHTML: initialStatus})
|
||
|
|
||
|
var progressEl = setElAttrs(document.createElement("progress"), {
|
||
|
value: 0,
|
||
|
max: 100,
|
||
|
hidden: true,
|
||
|
})
|
||
|
|
||
|
progressEl.style.display = 'inline'
|
||
|
|
||
|
loadingStatusEl.appendChild(statusEl)
|
||
|
loadingStatusEl.appendChild(progressEl)
|
||
|
|
||
|
return {
|
||
|
totalDependencies: 0,
|
||
|
update: function(remainingDependencies) {
|
||
|
this.totalDependencies = Math.max(this.totalDependencies, remainingDependencies)
|
||
|
this.setStatus(remainingDependencies)
|
||
|
},
|
||
|
|
||
|
setStatus: function (remainingDependencies) {
|
||
|
if (this.setStatus.interval) clearInterval(this.setStatus.interval)
|
||
|
|
||
|
var loadedDependiences = this.totalDependencies - remainingDependencies
|
||
|
|
||
|
if (remainingDependencies) {
|
||
|
statusEl.innerHTML = 'Loading... ('+loadedDependiences+'/'+this.totalDependencies+')'
|
||
|
setElAttrs(progressEl, {
|
||
|
value: loadedDependiences*100,
|
||
|
max: this.totalDependencies*100,
|
||
|
hidden: false,
|
||
|
})
|
||
|
} else {
|
||
|
// close progress element
|
||
|
setElAttrs(progressEl, {
|
||
|
value: 0,
|
||
|
max: 0,
|
||
|
hidden: true,
|
||
|
})
|
||
|
loadingStatusEl.style.display = 'none'
|
||
|
}
|
||
|
},
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
},{}],5:[function(require,module,exports){
|
||
|
'use strict';
|
||
|
|
||
|
angular.module('hybridApps', ['ngAnimate', 'ui.router', 'ngMaterial', 'cfp.hotkeys'])
|
||
|
.config(function ($stateProvider, $urlRouterProvider) {
|
||
|
$stateProvider
|
||
|
.state('slides', {
|
||
|
url: '/slides',
|
||
|
templateUrl: 'app/main/main.html',
|
||
|
controller: 'MainCtrl'
|
||
|
})
|
||
|
.state('slides.slide', {
|
||
|
url: '/:slideId',
|
||
|
templateUrl: function(params) {
|
||
|
return 'app/main/slide_' + params.slideId + '.html';
|
||
|
},
|
||
|
controller: 'slideCtrl'
|
||
|
});
|
||
|
|
||
|
$urlRouterProvider.otherwise('/slides/1');
|
||
|
})
|
||
|
.run(function(){
|
||
|
|
||
|
var macplus = require('pcejs-macplus')
|
||
|
var utils = require('pcejs-util')
|
||
|
|
||
|
angular.element(document).ready(function(){
|
||
|
// add a loading progress bar. not required, but good ux
|
||
|
var loadingStatus = utils.loadingStatus(document.querySelector('.pcejs-loading-status'))
|
||
|
|
||
|
macplus({
|
||
|
'arguments': ['-c','pce-config.cfg','-r'],
|
||
|
autoloadFiles: [
|
||
|
'macplus-pcex.rom',
|
||
|
'mac-plus.rom',
|
||
|
'hd1.qed',
|
||
|
'pce-config.cfg',
|
||
|
],
|
||
|
print: console.log.bind(console),
|
||
|
printErr: console.warn.bind(console),
|
||
|
canvas: document.querySelector('.pcejs-canvas'),
|
||
|
monitorRunDependencies: function (remainingDependencies) {
|
||
|
loadingStatus.update(remainingDependencies)
|
||
|
},
|
||
|
})
|
||
|
})
|
||
|
})
|
||
|
;
|
||
|
|
||
|
},{"pcejs-macplus":1,"pcejs-util":4}]},{},[5])
|