diff --git a/gba/dist/gbajs.min.js b/gba/dist/gbajs.min.js index 2a9e9c0..8d78d13 100755 --- a/gba/dist/gbajs.min.js +++ b/gba/dist/gbajs.min.js @@ -1,7658 +1,7694 @@ -var Zepto = function() { - function h(t) { - return null == t ? String(t) : H[F.call(t)] || "object" - } - - function a(t) { - return "function" == h(t) - } - - function n(t) { - return null != t && t == t.window - } - - function o(t) { - return null != t && t.nodeType == t.DOCUMENT_NODE - } - - function s(t) { - return "object" == h(t) - } - - function c(t) { - return s(t) && !n(t) && Object.getPrototypeOf(t) == Object.prototype - } - - function u(t) { - return "number" == typeof t.length - } - - function d(t) { - return t.replace(/::/g, "/").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").replace(/([a-z\d])([A-Z])/g, "$1_$2").replace(/_/g, "-").toLowerCase() - } - - function i(t) { - return t in e ? e[t] : e[t] = new RegExp("(^|\\s)" + t + "(\\s|$)") - } - - function p(t, e) { - return "number" != typeof e || O[d(t)] ? e : e + "px" - } - - function r(t) { - return "children" in t ? M.call(t.children) : g.map(t.childNodes, function(t) { - return 1 == t.nodeType ? t : void 0 - }) - } - - function l(t, e) { - return null == e ? g(t) : g(t).filter(e) - } - - function f(t, e, i, r) { - return a(e) ? e.call(t, i, r) : e - } - - function m(t, e, i) { - null == i ? t.removeAttribute(e) : t.setAttribute(e, i) - } - - function y(t, e) { - var i = t.className || "", - r = i && i.baseVal !== A; - return e === A ? r ? i.baseVal : i : void(r ? i.baseVal = e : t.className = e) - } - - function v(e) { - try { - return e ? "true" == e || "false" != e && ("null" == e ? null : +e + "" == e ? +e : /^[\[\{]/.test(e) ? g.parseJSON(e) : e) : e - } catch (t) { - return e - } - } - var A, b, g, S, R, C, w = [], - M = w.slice, - _ = w.filter, - I = window.document, - E = {}, - e = {}, - O = { - "column-count": 1, - columns: 1, - "font-weight": 1, - "line-height": 1, - opacity: 1, - "z-index": 1, - zoom: 1 - }, - T = /^\s*<(\w+|!)[^>]*>/, - P = /^<(\w+)\s*\/?>(?:<\/\1>|)$/, - B = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi, - N = /^(?:body|html)$/i, - k = /([A-Z])/g, - D = ["val", "css", "html", "text", "data", "width", "height", "offset"], - t = I.createElement("table"), - G = I.createElement("tr"), - L = { - tr: I.createElement("tbody"), - tbody: t, - thead: t, - tfoot: t, - td: G, - th: G, - "*": I.createElement("div") - }, - x = /complete|loaded|interactive/, - U = /^[\w-]*$/, - H = {}, - F = H.toString, - W = {}, - V = I.createElement("div"), - z = { - tabindex: "tabIndex", - readonly: "readOnly", - for: "htmlFor", - class: "className", - maxlength: "maxLength", - cellspacing: "cellSpacing", - cellpadding: "cellPadding", - rowspan: "rowSpan", - colspan: "colSpan", - usemap: "useMap", - frameborder: "frameBorder", - contenteditable: "contentEditable" - }, - q = Array.isArray || function(t) { - return t instanceof Array - }; - return W.matches = function(t, e) { - if (!e || !t || 1 !== t.nodeType) return !1; - var i = t.webkitMatchesSelector || t.mozMatchesSelector || t.oMatchesSelector || t.matchesSelector; - if (i) return i.call(t, e); - var r, s = t.parentNode, - n = !s; - return n && (s = V).appendChild(t), r = ~W.qsa(s, e).indexOf(t), n && V.removeChild(t), r - }, R = function(t) { - return t.replace(/-+(.)?/g, function(t, e) { - return e ? e.toUpperCase() : "" - }) - }, C = function(i) { - return _.call(i, function(t, e) { - return i.indexOf(t) == e - }) - }, W.fragment = function(t, e, i) { - var r, s, n; - return P.test(t) && (r = g(I.createElement(RegExp.$1))), r || (t.replace && (t = t.replace(B, "<$1>")), e === A && (e = T.test(t) && RegExp.$1), e in L || (e = "*"), (n = L[e]).innerHTML = "" + t, r = g.each(M.call(n.childNodes), function() { - n.removeChild(this) - })), c(i) && (s = g(r), g.each(i, function(t, e) { - -1 < D.indexOf(t) ? s[t](e) : s.attr(t, e) - })), r - }, W.Z = function(t, e) { - return (t = t || []).__proto__ = g.fn, t.selector = e || "", t - }, W.isZ = function(t) { - return t instanceof W.Z - }, W.init = function(t, e) { - var i, r; - if (!t) return W.Z(); - if ("string" == typeof t) - if ("<" == (t = t.trim())[0] && T.test(t)) i = W.fragment(t, RegExp.$1, e), t = null; - else { - if (e !== A) return g(e).find(t); - i = W.qsa(I, t) - } else { - if (a(t)) return g(I).ready(t); - if (W.isZ(t)) return t; - if (q(t)) r = t, i = _.call(r, function(t) { - return null != t - }); - else if (s(t)) i = [t], t = null; - else if (T.test(t)) i = W.fragment(t.trim(), RegExp.$1, e), t = null; - else { - if (e !== A) return g(e).find(t); - i = W.qsa(I, t) - } - } - return W.Z(i, t) - }, (g = function(t, e) { - return W.init(t, e) - }).extend = function(e) { - var i, t = M.call(arguments, 1); - return "boolean" == typeof e && (i = e, e = t.shift()), t.forEach(function(t) { - ! function t(e, i, r) { - for (b in i) r && (c(i[b]) || q(i[b])) ? (c(i[b]) && !c(e[b]) && (e[b] = {}), q(i[b]) && !q(e[b]) && (e[b] = []), t(e[b], i[b], r)) : i[b] !== A && (e[b] = i[b]) - }(e, t, i) - }), e - }, W.qsa = function(t, e) { - var i, r = "#" == e[0], - s = !r && "." == e[0], - n = r || s ? e.slice(1) : e, - a = U.test(n); - return o(t) && a && r ? (i = t.getElementById(n)) ? [i] : [] : 1 !== t.nodeType && 9 !== t.nodeType ? [] : M.call(a && !r ? s ? t.getElementsByClassName(n) : t.getElementsByTagName(e) : t.querySelectorAll(e)) - }, g.contains = I.documentElement.contains ? function(t, e) { - return t !== e && t.contains(e) - } : function(t, e) { - for (; e && (e = e.parentNode);) - if (e === t) return !0; - return !1 - }, g.type = h, g.isFunction = a, g.isWindow = n, g.isArray = q, g.isPlainObject = c, g.isEmptyObject = function(t) { - var e; - for (e in t) return !1; - return !0 - }, g.inArray = function(t, e, i) { - return w.indexOf.call(e, t, i) - }, g.camelCase = R, g.trim = function(t) { - return null == t ? "" : String.prototype.trim.call(t) - }, g.uuid = 0, g.support = {}, g.expr = {}, g.map = function(t, e) { - var i, r, s, n, a = []; - if (u(t)) - for (r = 0; r < t.length; r++) null != (i = e(t[r], r)) && a.push(i); - else - for (s in t) null != (i = e(t[s], s)) && a.push(i); - return 0 < (n = a).length ? g.fn.concat.apply([], n) : n - }, g.each = function(t, e) { - var i, r; - if (u(t)) { - for (i = 0; i < t.length; i++) - if (!1 === e.call(t[i], i, t[i])) return t - } else - for (r in t) - if (!1 === e.call(t[r], r, t[r])) return t; return t - }, g.grep = function(t, e) { - return _.call(t, e) - }, window.JSON && (g.parseJSON = JSON.parse), g.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(t, e) { - H["[object " + e + "]"] = e.toLowerCase() - }), g.fn = { - forEach: w.forEach, - reduce: w.reduce, - push: w.push, - sort: w.sort, - indexOf: w.indexOf, - concat: w.concat, - map: function(i) { - return g(g.map(this, function(t, e) { - return i.call(t, e, t) - })) - }, - slice: function() { - return g(M.apply(this, arguments)) - }, - ready: function(t) { - return x.test(I.readyState) && I.body ? t(g) : I.addEventListener("DOMContentLoaded", function() { - t(g) - }, !1), this - }, - get: function(t) { - return t === A ? M.call(this) : this[0 <= t ? t : t + this.length] - }, - toArray: function() { - return this.get() - }, - size: function() { - return this.length - }, - remove: function() { - return this.each(function() { - null != this.parentNode && this.parentNode.removeChild(this) - }) - }, - each: function(i) { - return w.every.call(this, function(t, e) { - return !1 !== i.call(t, e, t) - }), this - }, - filter: function(e) { - return a(e) ? this.not(this.not(e)) : g(_.call(this, function(t) { - return W.matches(t, e) - })) - }, - add: function(t, e) { - return g(C(this.concat(g(t, e)))) - }, - is: function(t) { - return 0 < this.length && W.matches(this[0], t) - }, - not: function(e) { - var i = []; - if (a(e) && e.call !== A) this.each(function(t) { - e.call(this, t) || i.push(this) - }); - else { - var r = "string" == typeof e ? this.filter(e) : u(e) && a(e.item) ? M.call(e) : g(e); - this.forEach(function(t) { - r.indexOf(t) < 0 && i.push(t) - }) - } - return g(i) - }, - has: function(t) { - return this.filter(function() { - return s(t) ? g.contains(this, t) : g(this).find(t).size() - }) - }, - eq: function(t) { - return -1 === t ? this.slice(t) : this.slice(t, +t + 1) - }, - first: function() { - var t = this[0]; - return t && !s(t) ? t : g(t) - }, - last: function() { - var t = this[this.length - 1]; - return t && !s(t) ? t : g(t) - }, - find: function(t) { - var i = this; - return t ? "object" == typeof t ? g(t).filter(function() { - var e = this; - return w.some.call(i, function(t) { - return g.contains(t, e) - }) - }) : 1 == this.length ? g(W.qsa(this[0], t)) : this.map(function() { - return W.qsa(this, t) - }) : g() - }, - closest: function(t, e) { - var i = this[0], - r = !1; - for ("object" == typeof t && (r = g(t)); i && !(r ? 0 <= r.indexOf(i) : W.matches(i, t));) i = i !== e && !o(i) && i.parentNode; - return g(i) - }, - parents: function(t) { - for (var e = [], i = this; 0 < i.length;) i = g.map(i, function(t) { - return (t = t.parentNode) && !o(t) && e.indexOf(t) < 0 ? (e.push(t), t) : void 0 - }); - return l(e, t) - }, - parent: function(t) { - return l(C(this.pluck("parentNode")), t) - }, - children: function(t) { - return l(this.map(function() { - return r(this) - }), t) - }, - contents: function() { - return this.map(function() { - return M.call(this.childNodes) - }) - }, - siblings: function(t) { - return l(this.map(function(t, e) { - return _.call(r(e.parentNode), function(t) { - return t !== e - }) - }), t) - }, - empty: function() { - return this.each(function() { - this.innerHTML = "" - }) - }, - pluck: function(e) { - return g.map(this, function(t) { - return t[e] - }) - }, - show: function() { - return this.each(function() { - var t, e, i; - "none" == this.style.display && (this.style.display = ""), "none" == getComputedStyle(this, "").getPropertyValue("display") && (this.style.display = (t = this.nodeName, E[t] || (e = I.createElement(t), I.body.appendChild(e), i = getComputedStyle(e, "").getPropertyValue("display"), e.parentNode.removeChild(e), "none" == i && (i = "block"), E[t] = i), E[t])) - }) - }, - replaceWith: function(t) { - return this.before(t).remove() - }, - wrap: function(e) { - var i = a(e); - if (this[0] && !i) var r = g(e).get(0), - s = r.parentNode || 1 < this.length; - return this.each(function(t) { - g(this).wrapAll(i ? e.call(this, t) : s ? r.cloneNode(!0) : r) - }) - }, - wrapAll: function(t) { - if (this[0]) { - g(this[0]).before(t = g(t)); - for (var e; - (e = t.children()).length;) t = e.first(); - g(t).append(this) - } - return this - }, - wrapInner: function(s) { - var n = a(s); - return this.each(function(t) { - var e = g(this), - i = e.contents(), - r = n ? s.call(this, t) : s; - i.length ? i.wrapAll(r) : e.append(r) - }) - }, - unwrap: function() { - return this.parent().each(function() { - g(this).replaceWith(g(this).children()) - }), this - }, - clone: function() { - return this.map(function() { - return this.cloneNode(!0) - }) - }, - hide: function() { - return this.css("display", "none") - }, - toggle: function(e) { - return this.each(function() { - var t = g(this); - (e === A ? "none" == t.css("display") : e) ? t.show(): t.hide() - }) - }, - prev: function(t) { - return g(this.pluck("previousElementSibling")).filter(t || "*") - }, - next: function(t) { - return g(this.pluck("nextElementSibling")).filter(t || "*") - }, - html: function(i) { - return 0 in arguments ? this.each(function(t) { - var e = this.innerHTML; - g(this).empty().append(f(this, i, t, e)) - }) : 0 in this ? this[0].innerHTML : null - }, - text: function(i) { - return 0 in arguments ? this.each(function(t) { - var e = f(this, i, t, this.textContent); - this.textContent = null == e ? "" : "" + e - }) : 0 in this ? this[0].textContent : null - }, - attr: function(e, i) { - var t; - return "string" != typeof e || 1 in arguments ? this.each(function(t) { - if (1 === this.nodeType) - if (s(e)) - for (b in e) m(this, b, e[b]); - else m(this, e, f(this, i, t, this.getAttribute(e))) - }) : this.length && 1 === this[0].nodeType ? !(t = this[0].getAttribute(e)) && e in this[0] ? this[0][e] : t : A - }, - removeAttr: function(t) { - return this.each(function() { - 1 === this.nodeType && t.split(" ").forEach(function(t) { - m(this, t) - }, this) - }) - }, - prop: function(e, i) { - return e = z[e] || e, 1 in arguments ? this.each(function(t) { - this[e] = f(this, i, t, this[e]) - }) : this[0] && this[0][e] - }, - data: function(t, e) { - var i = "data-" + t.replace(k, "-$1").toLowerCase(), - r = 1 in arguments ? this.attr(i, e) : this.attr(i); - return null !== r ? v(r) : A - }, - val: function(e) { - return 0 in arguments ? this.each(function(t) { - this.value = f(this, e, t, this.value) - }) : this[0] && (this[0].multiple ? g(this[0]).find("option").filter(function() { - return this.selected - }).pluck("value") : this[0].value) - }, - offset: function(n) { - if (n) return this.each(function(t) { - var e = g(this), - i = f(this, n, t, e.offset()), - r = e.offsetParent().offset(), - s = { - top: i.top - r.top, - left: i.left - r.left - }; - "static" == e.css("position") && (s.position = "relative"), e.css(s) - }); - if (!this.length) return null; - var t = this[0].getBoundingClientRect(); - return { - left: t.left + window.pageXOffset, - top: t.top + window.pageYOffset, - width: Math.round(t.width), - height: Math.round(t.height) - } - }, - css: function(t, e) { - if (arguments.length < 2) { - var i, r = this[0]; - if (!r) return; - if (i = getComputedStyle(r, ""), "string" == typeof t) return r.style[R(t)] || i.getPropertyValue(t); - if (q(t)) { - var s = {}; - return g.each(t, function(t, e) { - s[e] = r.style[R(e)] || i.getPropertyValue(e) - }), s - } - } - var n = ""; - if ("string" == h(t)) e || 0 === e ? n = d(t) + ":" + p(t, e) : this.each(function() { - this.style.removeProperty(d(t)) - }); - else - for (b in t) t[b] || 0 === t[b] ? n += d(b) + ":" + p(b, t[b]) + ";" : this.each(function() { - this.style.removeProperty(d(b)) - }); - return this.each(function() { - this.style.cssText += ";" + n - }) - }, - index: function(t) { - return t ? this.indexOf(g(t)[0]) : this.parent().children().indexOf(this[0]) - }, - hasClass: function(t) { - return !!t && w.some.call(this, function(t) { - return this.test(y(t)) - }, i(t)) - }, - addClass: function(i) { - return i ? this.each(function(t) { - if ("className" in this) { - S = []; - var e = y(this); - f(this, i, t, e).split(/\s+/g).forEach(function(t) { - g(this).hasClass(t) || S.push(t) - }, this), S.length && y(this, e + (e ? " " : "") + S.join(" ")) - } - }) : this - }, - removeClass: function(e) { - return this.each(function(t) { - if ("className" in this) { - if (e === A) return y(this, ""); - S = y(this), f(this, e, t, S).split(/\s+/g).forEach(function(t) { - S = S.replace(i(t), " ") - }), y(this, S.trim()) - } - }) - }, - toggleClass: function(i, r) { - return i ? this.each(function(t) { - var e = g(this); - f(this, i, t, y(this)).split(/\s+/g).forEach(function(t) { - (r === A ? !e.hasClass(t) : r) ? e.addClass(t): e.removeClass(t) - }) - }) : this - }, - scrollTop: function(t) { - if (this.length) { - var e = "scrollTop" in this[0]; - return t === A ? e ? this[0].scrollTop : this[0].pageYOffset : this.each(e ? function() { - this.scrollTop = t - } : function() { - this.scrollTo(this.scrollX, t) - }) - } - }, - scrollLeft: function(t) { - if (this.length) { - var e = "scrollLeft" in this[0]; - return t === A ? e ? this[0].scrollLeft : this[0].pageXOffset : this.each(e ? function() { - this.scrollLeft = t - } : function() { - this.scrollTo(t, this.scrollY) - }) - } - }, - position: function() { - if (this.length) { - var t = this[0], - e = this.offsetParent(), - i = this.offset(), - r = N.test(e[0].nodeName) ? { - top: 0, - left: 0 - } : e.offset(); - return i.top -= parseFloat(g(t).css("margin-top")) || 0, i.left -= parseFloat(g(t).css("margin-left")) || 0, r.top += parseFloat(g(e[0]).css("border-top-width")) || 0, r.left += parseFloat(g(e[0]).css("border-left-width")) || 0, { - top: i.top - r.top, - left: i.left - r.left - } - } - }, - offsetParent: function() { - return this.map(function() { - for (var t = this.offsetParent || I.body; t && !N.test(t.nodeName) && "static" == g(t).css("position");) t = t.offsetParent; - return t - }) - } - }, g.fn.detach = g.fn.remove, ["width", "height"].forEach(function(r) { - var s = r.replace(/./, function(t) { - return t[0].toUpperCase() - }); - g.fn[r] = function(e) { - var t, i = this[0]; - return e === A ? n(i) ? i["inner" + s] : o(i) ? i.documentElement["scroll" + s] : (t = this.offset()) && t[r] : this.each(function(t) { - (i = g(this)).css(r, f(this, e, t, i[r]())) - }) - } - }), ["after", "prepend", "before", "append"].forEach(function(e, a) { - var o = a % 2; - g.fn[e] = function() { - var e, r, s = g.map(arguments, function(t) { - return "object" == (e = h(t)) || "array" == e || null == t ? t : W.fragment(t) - }), - n = 1 < this.length; - return s.length < 1 ? this : this.each(function(t, e) { - r = o ? e : e.parentNode, e = 0 == a ? e.nextSibling : 1 == a ? e.firstChild : 2 == a ? e : null; - var i = g.contains(I.documentElement, r); - s.forEach(function(t) { - if (n) t = t.cloneNode(!0); - else if (!r) return g(t).remove(); - r.insertBefore(t, e), i && function t(e, i) { - i(e); - for (var r = 0, s = e.childNodes.length; r < s; r++) t(e.childNodes[r], i) - }(t, function(t) { - null == t.nodeName || "SCRIPT" !== t.nodeName.toUpperCase() || t.type && "text/javascript" !== t.type || t.src || window.eval.call(window, t.innerHTML) - }) - }) - }) - }, g.fn[o ? e + "To" : "insert" + (a ? "Before" : "After")] = function(t) { - return g(t)[e](this), this - } - }), W.Z.prototype = g.fn, W.uniq = C, W.deserializeValue = v, g.zepto = W, g -}(); - -function layerLandscape(t) { - $("#layui-m-layer" + t + " .layui-m-layersection").css({ - transform: "rotate(90deg)" - }) -} - -function hex(t, e, i) { - void 0 === i && (i = !0), void 0 === e && (e = 8); - var r = (t >>> 0).toString(16).toUpperCase(); - return (e -= r.length) < 0 ? r : (i ? "0x" : "") + new Array(e + 1).join("0") + r -} - -function ARMCore() { - this.inherit(), this.SP = 13, this.LR = 14, this.PC = 15, this.MODE_ARM = 0, this.MODE_THUMB = 1, this.MODE_USER = 16, this.MODE_FIQ = 17, this.MODE_IRQ = 18, this.MODE_SUPERVISOR = 19, this.MODE_ABORT = 23, this.MODE_UNDEFINED = 27, this.MODE_SYSTEM = 31, this.BANK_NONE = 0, this.BANK_FIQ = 1, this.BANK_IRQ = 2, this.BANK_SUPERVISOR = 3, this.BANK_ABORT = 4, this.BANK_UNDEFINED = 5, this.UNALLOC_MASK = 268435200, this.USER_MASK = 4026531840, this.PRIV_MASK = 207, this.STATE_MASK = 32, this.WORD_SIZE_ARM = 4, this.WORD_SIZE_THUMB = 2, this.BASE_RESET = 0, this.BASE_UNDEF = 4, this.BASE_SWI = 8, this.BASE_PABT = 12, this.BASE_DABT = 16, this.BASE_IRQ = 24, this.BASE_FIQ = 28, this.armCompiler = new ARMCoreArm(this), this.thumbCompiler = new ARMCoreThumb(this), this.generateConds(), this.gprs = new Int32Array(16) -} -window.Zepto = Zepto, void 0 === window.$ && (window.$ = Zepto), - function(u) { - function d(t) { - return t._zid || (t._zid = e++) - } - - function a(t, e, i, r) { - if ((e = p(e)).ns) var s = (n = e.ns, new RegExp("(?:^| )" + n.replace(" ", " .* ?") + "(?: |$)")); - var n; - return (R[d(t)] || []).filter(function(t) { - return !(!t || e.e && t.e != e.e || e.ns && !s.test(t.ns) || i && d(t.fn) !== d(i) || r && t.sel != r) - }) - } - - function p(t) { - var e = ("" + t).split("."); - return { - e: e[0], - ns: e.slice(1).sort().join(" ") - } - } - - function l(t, e) { - return t.del && !i && t.e in r || !!e - } - - function f(t) { - return C[t] || i && r[t] || t - } - - function c(s, t, e, n, a, o, h) { - var i = d(s), - c = R[i] || (R[i] = []); - t.split(/\s/).forEach(function(t) { - if ("ready" == t) return u(document).ready(e); - var i = p(t); - i.fn = e, i.sel = a, i.e in C && (e = function(t) { - var e = t.relatedTarget; - return !e || e !== this && !u.contains(this, e) ? i.fn.apply(this, arguments) : void 0 - }); - var r = (i.del = o) || e; - i.proxy = function(t) { - if (!(t = y(t)).isImmediatePropagationStopped()) { - t.data = n; - var e = r.apply(s, t._args == A ? [t] : [t].concat(t._args)); - return !1 === e && (t.preventDefault(), t.stopPropagation()), e - } - }, i.i = c.length, c.push(i), "addEventListener" in s && s.addEventListener(f(i.e), i.proxy, l(i, h)) - }) - } - - function m(e, t, i, r, s) { - var n = d(e); - (t || "").split(/\s/).forEach(function(t) { - a(e, t, i, r).forEach(function(t) { - delete R[n][t.i], "removeEventListener" in e && e.removeEventListener(f(t.e), t.proxy, l(t, s)) - }) - }) - } - - function y(r, s) { - return (s || !r.isDefaultPrevented) && (s || (s = r), u.each(t, function(t, e) { - var i = s[t]; - r[t] = function() { - return this[e] = o, i && i.apply(s, arguments) - }, r[e] = w - }), (s.defaultPrevented !== A ? s.defaultPrevented : "returnValue" in s ? !1 === s.returnValue : s.getPreventDefault && s.getPreventDefault()) && (r.isDefaultPrevented = o)), r - } - - function v(t) { - var e, i = { - originalEvent: t - }; - for (e in t) s.test(e) || t[e] === A || (i[e] = t[e]); - return y(i, t) - } - var A, e = 1, - b = Array.prototype.slice, - g = u.isFunction, - S = function(t) { - return "string" == typeof t - }, - R = {}, - n = {}, - i = "onfocusin" in window, - r = { - focus: "focusin", - blur: "focusout" - }, - C = { - mouseenter: "mouseover", - mouseleave: "mouseout" - }; - n.click = n.mousedown = n.mouseup = n.mousemove = "MouseEvents", u.event = { - add: c, - remove: m - }, u.proxy = function(t, e) { - var i = 2 in arguments && b.call(arguments, 2); - if (g(t)) { - var r = function() { - return t.apply(e, i ? i.concat(b.call(arguments)) : arguments) - }; - return r._zid = d(t), r - } - if (S(e)) return i ? (i.unshift(t[e], t), u.proxy.apply(null, i)) : u.proxy(t[e], t); - throw new TypeError("expected function") - }, u.fn.bind = function(t, e, i) { - return this.on(t, e, i) - }, u.fn.unbind = function(t, e) { - return this.off(t, e) - }, u.fn.one = function(t, e, i, r) { - return this.on(t, e, i, r, 1) - }; - var o = function() { - return !0 - }, - w = function() { - return !1 - }, - s = /^([A-Z]|returnValue$|layer[XY]$)/, - t = { - preventDefault: "isDefaultPrevented", - stopImmediatePropagation: "isImmediatePropagationStopped", - stopPropagation: "isPropagationStopped" - }; - u.fn.delegate = function(t, e, i) { - return this.on(e, t, i) - }, u.fn.undelegate = function(t, e, i) { - return this.off(e, t, i) - }, u.fn.live = function(t, e) { - return u(document.body).delegate(this.selector, t, e), this - }, u.fn.die = function(t, e) { - return u(document.body).undelegate(this.selector, t, e), this - }, u.fn.on = function(e, s, i, n, a) { - var o, h, r = this; - return e && !S(e) ? (u.each(e, function(t, e) { - r.on(t, s, i, e, a) - }), r) : (S(s) || g(n) || !1 === n || (n = i, i = s, s = A), (g(i) || !1 === i) && (n = i, i = A), !1 === n && (n = w), r.each(function(t, r) { - a && (o = function(t) { - return m(r, t.type, n), n.apply(this, arguments) - }), s && (h = function(t) { - var e, i = u(t.target).closest(s, r).get(0); - return i && i !== r ? (e = u.extend(v(t), { - currentTarget: i, - liveFired: r - }), (o || n).apply(i, [e].concat(b.call(arguments, 1)))) : void 0 - }), c(r, e, n, i, s, h || o) - })) - }, u.fn.off = function(t, i, e) { - var r = this; - return t && !S(t) ? (u.each(t, function(t, e) { - r.off(t, i, e) - }), r) : (S(i) || g(e) || !1 === e || (e = i, i = A), !1 === e && (e = w), r.each(function() { - m(this, t, e, i) - })) - }, u.fn.trigger = function(t, e) { - return (t = S(t) || u.isPlainObject(t) ? u.Event(t) : y(t))._args = e, this.each(function() { - t.type in r && "function" == typeof this[t.type] ? this[t.type]() : "dispatchEvent" in this ? this.dispatchEvent(t) : u(this).triggerHandler(t, e) - }) - }, u.fn.triggerHandler = function(i, r) { - var s, n; - return this.each(function(t, e) { - (s = v(S(i) ? u.Event(i) : i))._args = r, s.target = e, u.each(a(e, i.type || i), function(t, e) { - return n = e.proxy(s), !s.isImmediatePropagationStopped() && void 0 - }) - }), n - }, "focusin focusout focus blur load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select keydown keypress keyup error".split(" ").forEach(function(e) { - u.fn[e] = function(t) { - return 0 in arguments ? this.bind(e, t) : this.trigger(e) - } - }), u.Event = function(t, e) { - S(t) || (t = (e = t).type); - var i = document.createEvent(n[t] || "Events"), - r = !0; - if (e) - for (var s in e) "bubbles" == s ? r = !!e[s] : i[s] = e[s]; - return i.initEvent(t, r, !0), y(i) - } - }(Zepto), - function(fh) { - function hh(t, e, i, r) { - return t.global ? (s = e || xh, n = i, a = r, o = fh.Event(n), fh(s).trigger(o, a), !o.isDefaultPrevented()) : void 0; - var s, n, a, o - } - - function kh(t, e) { - var i = e.context; - return !1 !== e.beforeSend.call(i, t, e) && !1 !== hh(e, i, "ajaxBeforeSend", [t, e]) && void hh(e, i, "ajaxSend", [t, e]) - } - - function lh(t, e, i, r) { - var s = i.context, - n = "success"; - i.success.call(s, t, n, e), r && r.resolveWith(s, [t, n, e]), hh(i, s, "ajaxSuccess", [e, i, t]), nh(n, e, i) - } - - function mh(t, e, i, r, s) { - var n = r.context; - r.error.call(n, i, e, t), s && s.rejectWith(n, [i, e, t]), hh(r, n, "ajaxError", [i, r, t || e]), nh(e, i, r) - } - - function nh(t, e, i) { - var r, s = i.context; - i.complete.call(s, e, t), hh(i, s, "ajaxComplete", [e, i]), (r = i).global && !--fh.active && hh(r, null, "ajaxStop") - } - - function oh() {} - - function qh(t, e) { - return "" == e ? t : (t + "&" + e).replace(/[&?]{1,2}/, "?") - } - - function sh(t, e, i, r) { - return fh.isFunction(e) && (r = i, i = e, e = void 0), fh.isFunction(i) || (r = i, i = void 0), { - url: t, - data: e, - success: i, - dataType: r - } - } - var uh, vh, wh = 0, - xh = window.document, - yh = /)<[^<]*)*<\/script>/gi, - zh = /^(?:text|application)\/javascript/i, - Ah = /^(?:text|application)\/xml/i, - Bh = "application/json", - Ch = "text/html", - Dh = /^\s*$/, - Eh = xh.createElement("a"); - Eh.href = window.location.href, fh.active = 0, fh.ajaxJSONP = function(i, r) { - if (!("type" in i)) return fh.ajax(i); - var s, n, t = i.jsonpCallback, - a = (fh.isFunction(t) ? t() : t) || "jsonp" + ++wh, - o = xh.createElement("script"), - h = window[a], - e = function(t) { - fh(o).triggerHandler("error", t || "abort") - }, - c = { - abort: e - }; - return r && r.promise(c), fh(o).on("load error", function(t, e) { - clearTimeout(n), fh(o).off().remove(), "error" != t.type && s ? lh(s[0], c, i, r) : mh(null, e || "error", c, i, r), window[a] = h, s && fh.isFunction(h) && h(s[0]), h = s = void 0 - }), !1 === kh(c, i) ? e("abort") : (window[a] = function() { - s = arguments - }, o.src = i.url.replace(/\?(.+)=\?/, "?$1=" + a), xh.head.appendChild(o), 0 < i.timeout && (n = setTimeout(function() { - e("timeout") - }, i.timeout))), c - }, fh.ajaxSettings = { - type: "GET", - beforeSend: oh, - success: oh, - error: oh, - complete: oh, - context: null, - global: !0, - xhr: function() { - return new window.XMLHttpRequest - }, - accepts: { - script: "text/javascript, application/javascript, application/x-javascript", - json: Bh, - xml: "application/xml, text/xml", - html: Ch, - text: "text/plain" - }, - crossDomain: !1, - timeout: 0, - processData: !0, - cache: !0 - }, fh.ajax = function(Li) { - var Mi, ki, Oh, Ni = fh.extend({}, Li || {}), - Oi = fh.Deferred && fh.Deferred(); - for (uh in fh.ajaxSettings) void 0 === Ni[uh] && (Ni[uh] = fh.ajaxSettings[uh]); - (Oh = Ni).global && 0 == fh.active++ && hh(Oh, null, "ajaxStart"), Ni.crossDomain || ((Mi = xh.createElement("a")).href = Ni.url, Mi.href = Mi.href, Ni.crossDomain = Eh.protocol + "//" + Eh.host != Mi.protocol + "//" + Mi.host), Ni.url || (Ni.url = window.location.toString()), (ki = Ni).processData && ki.data && "string" != fh.type(ki.data) && (ki.data = fh.param(ki.data, ki.traditional)), !ki.data || ki.type && "GET" != ki.type.toUpperCase() || (ki.url = qh(ki.url, ki.data), ki.data = void 0); - var Pi = Ni.dataType, - Qi = /\?.+=\?/.test(Ni.url); - if (Qi && (Pi = "jsonp"), !1 !== Ni.cache && (Li && !0 === Li.cache || "script" != Pi && "jsonp" != Pi) || (Ni.url = qh(Ni.url, "_=" + Date.now())), "jsonp" == Pi) return Qi || (Ni.url = qh(Ni.url, Ni.jsonp ? Ni.jsonp + "=?" : !1 === Ni.jsonp ? "" : "callback=?")), fh.ajaxJSONP(Ni, Oi); - var Ri, Si = Ni.accepts[Pi], - Ti = {}, - Ui = function(t, e) { - Ti[t.toLowerCase()] = [t, e] - }, - Vi = /^([\w-]+:)\/\//.test(Ni.url) ? RegExp.$1 : window.location.protocol, - Wi = Ni.xhr(), - Xi = Wi.setRequestHeader; - if (Oi && Oi.promise(Wi), Ni.crossDomain || Ui("X-Requested-With", "XMLHttpRequest"), Ui("Accept", Si || "*/*"), (Si = Ni.mimeType || Si) && (-1 < Si.indexOf(",") && (Si = Si.split(",", 2)[0]), Wi.overrideMimeType && Wi.overrideMimeType(Si)), (Ni.contentType || !1 !== Ni.contentType && Ni.data && "GET" != Ni.type.toUpperCase()) && Ui("Content-Type", Ni.contentType || "application/x-www-form-urlencoded"), Ni.headers) - for (vh in Ni.headers) Ui(vh, Ni.headers[vh]); - if (Wi.setRequestHeader = Ui, !(Wi.onreadystatechange = function() { - if (4 == Wi.readyState) { - Wi.onreadystatechange = oh, clearTimeout(Ri); - var _i, aj = !1; - if (200 <= Wi.status && Wi.status < 300 || 304 == Wi.status || 0 == Wi.status && "file:" == Vi) { - Pi = Pi || ((hi = Ni.mimeType || Wi.getResponseHeader("content-type")) && (hi = hi.split(";", 2)[0]), hi && (hi == Ch ? "html" : hi == Bh ? "json" : zh.test(hi) ? "script" : Ah.test(hi) && "xml") || "text"), _i = Wi.responseText; - try { - "script" == Pi ? eval(_i) : "xml" == Pi ? _i = Wi.responseXML : "json" == Pi && (_i = Dh.test(_i) ? null : fh.parseJSON(_i)) - } catch (t) { - aj = t - } - aj ? mh(aj, "parsererror", Wi, Ni, Oi) : lh(_i, Wi, Ni, Oi) - } else mh(Wi.statusText || null, Wi.status ? "error" : "abort", Wi, Ni, Oi) - } - var hi - }) === kh(Wi, Ni)) return Wi.abort(), mh(null, "abort", Wi, Ni, Oi), Wi; - if (Ni.xhrFields) - for (vh in Ni.xhrFields) Wi[vh] = Ni.xhrFields[vh]; - var Yi = !("async" in Ni) || Ni.async; - for (vh in Wi.open(Ni.type, Ni.url, Yi, Ni.username, Ni.password), Ti) Xi.apply(Wi, Ti[vh]); - return 0 < Ni.timeout && (Ri = setTimeout(function() { - Wi.onreadystatechange = oh, Wi.abort(), mh(null, "timeout", Wi, Ni, Oi) - }, Ni.timeout)), Wi.send(Ni.data ? Ni.data : null), Wi - }, fh.get = function() { - return fh.ajax(sh.apply(null, arguments)) - }, fh.post = function() { - var t = sh.apply(null, arguments); - return t.type = "POST", fh.ajax(t) - }, fh.getJSON = function() { - var t = sh.apply(null, arguments); - return t.dataType = "json", fh.ajax(t) - }, fh.fn.load = function(t, e, i) { - if (!this.length) return this; - var r, s = this, - n = t.split(/\s/), - a = sh(t, e, i), - o = a.success; - return 1 < n.length && (a.url = n[0], r = n[1]), a.success = function(t) { - s.html(r ? fh("
").html(t.replace(yh, "")).find(r) : t), o && o.apply(s, arguments) - }, fh.ajax(a), this - }; - var Fh = encodeURIComponent; - fh.param = function(t, e) { - var i = []; - return i.add = function(t, e) { - fh.isFunction(e) && (e = e()), null == e && (e = ""), this.push(Fh(t) + "=" + Fh(e)) - }, - function i(r, t, s, n) { - var a, o = fh.isArray(t), - h = fh.isPlainObject(t); - fh.each(t, function(t, e) { - a = fh.type(e), n && (t = s ? n : n + "[" + (h || "object" == a || "array" == a ? t : "") + "]"), !n && o ? r.add(e.name, e.value) : "array" == a || !s && "object" == a ? i(r, e, s, t) : r.add(t, e) - }) - }(i, t, e), i.join("&").replace(/%20/g, "+") - } - }(Zepto), - function(n) { - n.fn.serializeArray = function() { - var i, r, e = [], - s = function(t) { - return t.forEach ? t.forEach(s) : void e.push({ - name: i, - value: t - }) - }; - return this[0] && n.each(this[0].elements, function(t, e) { - r = e.type, (i = e.name) && "fieldset" != e.nodeName.toLowerCase() && !e.disabled && "submit" != r && "reset" != r && "button" != r && "file" != r && ("radio" != r && "checkbox" != r || e.checked) && s(n(e).val()) - }), e - }, n.fn.serialize = function() { - var e = []; - return this.serializeArray().forEach(function(t) { - e.push(encodeURIComponent(t.name) + "=" + encodeURIComponent(t.value)) - }), e.join("&") - }, n.fn.submit = function(t) { - if (0 in arguments) this.bind("submit", t); - else if (this.length) { - var e = n.Event("submit"); - this.eq(0).trigger(e), e.isDefaultPrevented() || this.get(0).submit() - } - return this - } - }(Zepto), - function(i) { - "__proto__" in {} || i.extend(i.zepto, { - Z: function(t, e) { - return t = t || [], i.extend(t, i.fn), t.selector = e || "", t.__Z = !0, t - }, - isZ: function(t) { - return "array" === i.type(t) && "__Z" in t - } - }); - try { - getComputedStyle(void 0) - } catch (t) { - var e = getComputedStyle; - window.getComputedStyle = function(t) { - try { - return e(t) - } catch (t) { - return null - } - } - } - }(Zepto), - function(R) { - "use strict"; - var n, C = "File format is not recognized.", - a = "File contains encrypted entry.", - o = "File is using Zip64 (4gb+ file size).", - p = "Error while reading zip file.", - r = "Error while reading file data.", - A = 524288, - h = "text/plain"; - try { - n = 0 === new Blob([new DataView(new ArrayBuffer(0))]).size - } catch (t) {} - - function i() { - this.crc = -1 - } - - function d() {} - - function w(t, e) { - var i, r; - return i = new ArrayBuffer(t), r = new Uint8Array(i), e && r.set(e, 0), { - buffer: i, - array: r, - view: new DataView(i) - } - } - - function t() {} - - function e(r) { - var s, n = this; - n.size = 0, n.init = function(t, e) { - var i = new Blob([r], { - type: h - }); - (s = new c(i)).init(function() { - n.size = s.size, t() - }, e) - }, n.readUint8Array = function(t, e, i, r) { - s.readUint8Array(t, e, i, r) - } - } - - function s(c) { - var u, i = this; - i.size = 0, i.init = function(t) { - for (var e = c.length; - "=" == c.charAt(e - 1);) e--; - u = c.indexOf(",") + 1, i.size = Math.floor(.75 * (e - u)), t() - }, i.readUint8Array = function(t, e, i) { - var r, s = w(e), - n = 4 * Math.floor(t / 3), - a = 4 * Math.ceil((t + e) / 3), - o = R.atob(c.substring(n + u, a + u)), - h = t - 3 * Math.floor(n / 4); - for (r = h; r < h + e; r++) s.array[r - h] = o.charCodeAt(r); - i(s.array) - } - } - - function c(n) { - var e = this; - e.size = 0, e.init = function(t) { - e.size = n.size, t() - }, e.readUint8Array = function(t, e, i, r) { - var s = new FileReader; - s.onload = function(t) { - i(new Uint8Array(t.target.result)) - }, s.onerror = r; - try { - s.readAsArrayBuffer(function(t, e, i) { - if (e < 0 || i < 0 || e + i > t.size) throw new RangeError("offset:" + e + ", length:" + i + ", size:" + t.size); - return t.slice ? t.slice(e, e + i) : t.webkitSlice ? t.webkitSlice(e, e + i) : t.mozSlice ? t.mozSlice(e, e + i) : t.msSlice ? t.msSlice(e, e + i) : void 0 - }(n, t, e)) - } catch (t) { - r(t) - } - } - } - - function u() {} - - function l(r) { - var s; - this.init = function(t) { - s = new Blob([], { - type: h - }), t() - }, this.writeUint8Array = function(t, e) { - s = new Blob([s, n ? t : t.buffer], { - type: h - }), e() - }, this.getData = function(e, t) { - var i = new FileReader; - i.onload = function(t) { - e(t.target.result) - }, i.onerror = t, i.readAsText(s, r) - } - } - - function f(e) { - var n = "", - a = ""; - this.init = function(t) { - n += "data:" + (e || "") + ";base64,", t() - }, this.writeUint8Array = function(t, e) { - var i, r = a.length, - s = a; - for (a = "", i = 0; i < 3 * Math.floor((r + t.length) / 3) - r; i++) s += String.fromCharCode(t[i]); - for (; i < t.length; i++) a += String.fromCharCode(t[i]); - 2 < s.length ? n += R.btoa(s) : a = s, e() - }, this.getData = function(t) { - t(n + R.btoa(a)) - } - } - - function m(i) { - var r; - this.init = function(t) { - r = new Blob([], { - type: i - }), t() - }, this.writeUint8Array = function(t, e) { - r = new Blob([r, n ? t : t.buffer], { - type: i - }), e() - }, this.getData = function(t) { - t(r) - } - } - - function M(s, i, t, n, e, a, o, r, h, c) { - var u, d, p, l = 0, - f = i.sn; - - function m() { - s.removeEventListener("message", y, !1), r(d, p) - } - - function y(t) { - var e = t.data, - i = e.data, - r = e.error; - if (r) return r.toString = function() { - return "Error: " + this.message - }, void h(r); - if (e.sn === f) switch ("number" == typeof e.codecTime && (s.codecTime += e.codecTime), "number" == typeof e.crcTime && (s.crcTime += e.crcTime), e.type) { - case "append": - i ? (d += i.length, n.writeUint8Array(i, function() { - v() - }, c)) : v(); - break; - case "flush": - p = e.crc, i ? (d += i.length, n.writeUint8Array(i, function() { - m() - }, c)) : m(); - break; - case "progress": - o && o(u + e.loaded, a); - break; - case "importScripts": - case "newTask": - case "echo": - break; - default: - console.warn("zip.js:launchWorkerProcess: unknown message: ", e) - } - } - - function v() { - (u = l * A) <= a ? t.readUint8Array(e + u, Math.min(A, a - u), function(t) { - o && o(u, a); - var e = 0 === u ? i : { - sn: f - }; - e.type = "append", e.data = t; - try { - s.postMessage(e, [t.buffer]) - } catch (t) { - s.postMessage(e) - } - l++ - }, h) : s.postMessage({ - sn: f, - type: "flush" - }) - } - d = 0, s.addEventListener("message", y, !1), v() - } - - function _(r, e, s, n, a, t, o, h, c, u) { - var d, p = 0, - l = 0, - f = "input" === t, - m = "output" === t, - y = new i; - ! function i() { - var t; - if ((d = p * A) < a) e.readUint8Array(n + d, Math.min(A, a - d), function(t) { - var e; - try { - e = r.append(t, function(t) { - o && o(d + t, a) - }) - } catch (t) { - return void c(t) - } - e ? (l += e.length, s.writeUint8Array(e, function() { - p++, setTimeout(i, 1) - }, u), m && y.append(e)) : (p++, setTimeout(i, 1)), f && y.append(t), o && o(d, a) - }, c); - else { - try { - t = r.flush() - } catch (t) { - return void c(t) - } - t ? (m && y.append(t), l += t.length, s.writeUint8Array(t, function() { - h(l, y.get()) - }, u)) : h(l, y.get()) - } - }() - } - - function I(t, e, i, r, s, n, a, o, h, c, u) { - R.zip.useWebWorkers && a ? M(t, { - sn: e, - codecClass: "NOOP", - crcType: "input" - }, i, r, s, n, h, o, c, u) : _(new d, i, r, s, n, "input", h, o, c, u) - } - - function y(t) { - var e, i, r = "", - s = ["Ç", "ü", "é", "â", "ä", "à", "å", "ç", "ê", "ë", "è", "ï", "î", "ì", "Ä", "Å", "É", "æ", "Æ", "ô", "ö", "ò", "û", "ù", "ÿ", "Ö", "Ü", "ø", "£", "Ø", "×", "ƒ", "á", "í", "ó", "ú", "ñ", "Ñ", "ª", "º", "¿", "®", "¬", "½", "¼", "¡", "«", "»", "_", "_", "_", "¦", "¦", "Á", "Â", "À", "©", "¦", "¦", "+", "+", "¢", "¥", "+", "+", "-", "-", "+", "-", "+", "ã", "Ã", "+", "+", "-", "-", "¦", "-", "+", "¤", "ð", "Ð", "Ê", "Ë", "È", "i", "Í", "Î", "Ï", "+", "+", "_", "_", "¦", "Ì", "_", "Ó", "ß", "Ô", "Ò", "õ", "Õ", "µ", "þ", "Þ", "Ú", "Û", "Ù", "ý", "Ý", "¯", "´", "­", "±", "_", "¾", "¶", "§", "÷", "¸", "°", "¨", "·", "¹", "³", "²", "_", " "]; - for (e = 0; e < t.length; e++) r += 127 < (i = 255 & t.charCodeAt(e)) ? s[i - 128] : String.fromCharCode(i); - return r - } - - function v(t) { - return decodeURIComponent(escape(t)) - } - - function E(t) { - var e, i = ""; - for (e = 0; e < t.length; e++) i += String.fromCharCode(t[e]); - return i - } - - function O(t, e, i, r, s) { - t.version = e.view.getUint16(i, !0), t.bitFlag = e.view.getUint16(i + 2, !0), t.compressionMethod = e.view.getUint16(i + 4, !0), t.lastModDateRaw = e.view.getUint32(i + 6, !0), t.lastModDate = function(t) { - var e = (4294901760 & t) >> 16, - i = 65535 & t; - try { - return new Date(1980 + ((65024 & e) >> 9), ((480 & e) >> 5) - 1, 31 & e, (63488 & i) >> 11, (2016 & i) >> 5, 2 * (31 & i), 0) - } catch (t) {} - }(t.lastModDateRaw), 1 != (1 & t.bitFlag) ? ((r || 8 != (8 & t.bitFlag)) && (t.crc32 = e.view.getUint32(i + 10, !0), t.compressedSize = e.view.getUint32(i + 14, !0), t.uncompressedSize = e.view.getUint32(i + 18, !0)), 4294967295 !== t.compressedSize && 4294967295 !== t.uncompressedSize ? (t.filenameLength = e.view.getUint16(i + 22, !0), t.extraFieldLength = e.view.getUint16(i + 24, !0)) : s(o)) : s(a) - } - - function b(b, e, g) { - var S = 0; - - function d() {} - d.prototype.getData = function(p, s, l, f) { - var m = this; - - function y(t, e) { - var i, r; - f && (i = e, (r = w(4)).view.setUint32(0, i), m.crc32 != r.view.getUint32(0)) ? g("CRC failed.") : p.getData(function(t) { - s(t) - }) - } - - function v(t) { - g(t || r) - } - - function A(t) { - g(t || "Error while writing file data.") - } - b.readUint8Array(m.offset, 30, function(t) { - var d, e = w(t.length, t); - 1347093252 == e.view.getUint32(0) ? (O(m, e, 4, !1, g), d = m.offset + 30 + m.filenameLength + m.extraFieldLength, p.init(function() { - var t, e, i, r, s, n, a, o, h, c, u; - 0 === m.compressionMethod ? I(m._worker, S++, b, p, d, m.compressedSize, f, y, l, v, A) : (t = m._worker, e = S++, i = b, r = p, s = d, n = m.compressedSize, a = y, o = l, h = v, c = A, u = f ? "output" : "none", R.zip.useWebWorkers ? M(t, { - sn: e, - codecClass: "Inflater", - crcType: u - }, i, r, s, n, o, a, h, c) : _(new R.zip.Inflater, i, r, s, n, u, o, a, h, c)) - }, A)) : g(C) - }, v) - }; - var i = { - getEntries: function(c) { - var u = this._worker; - ! function(r) { - var s = 22; - if (b.size < s) g(C); - else { - var t = s + 65536; - e(s, function() { - e(Math.min(t, b.size), function() { - g(C) - }) - }) - } - - function e(t, i) { - b.readUint8Array(b.size - t, t, function(t) { - for (var e = t.length - s; 0 <= e; e--) - if (80 === t[e] && 75 === t[e + 1] && 5 === t[e + 2] && 6 === t[e + 3]) return void r(new DataView(t.buffer, e, s)); - i() - }, function() { - g(p) - }) - } - }(function(t) { - var e, h; - e = t.getUint32(16, !0), h = t.getUint16(8, !0), e < 0 || e >= b.size ? g(C) : b.readUint8Array(e, b.size - e, function(t) { - var e, i, r, s, n = 0, - a = [], - o = w(t.length, t); - for (e = 0; e < h; e++) { - if ((i = new d)._worker = u, 1347092738 != o.view.getUint32(n)) return void g(C); - O(i, o, n + 6, !0, g), i.commentLength = o.view.getUint16(n + 32, !0), i.directory = 16 == (16 & o.view.getUint8(n + 38)), i.offset = o.view.getUint32(n + 42, !0), r = E(o.array.subarray(n + 46, n + 46 + i.filenameLength)), i.filename = 2048 == (2048 & i.bitFlag) ? v(r) : y(r), i.directory || "/" != i.filename.charAt(i.filename.length - 1) || (i.directory = !0), s = E(o.array.subarray(n + 46 + i.filenameLength + i.extraFieldLength, n + 46 + i.filenameLength + i.extraFieldLength + i.commentLength)), i.comment = 2048 == (2048 & i.bitFlag) ? v(s) : y(s), a.push(i), n += 46 + i.filenameLength + i.extraFieldLength + i.commentLength - } - c(a) - }, function() { - g(p) - }) - }) - }, - close: function(t) { - this._worker && (this._worker.terminate(), this._worker = null), t && t() - }, - _worker: null - }; - R.zip.useWebWorkers ? B("inflater", function(t) { - i._worker = t, e(i) - }, function(t) { - g(t) - }) : e(i) - } - - function S(t) { - return unescape(encodeURIComponent(t)) - } - - function T(t) { - var e, i = []; - for (e = 0; e < t.length; e++) i.push(t.charCodeAt(e)); - return i - } - - function g(f, e, o, m) { - var h = {}, - y = [], - v = 0, - A = 0; - - function b(t) { - o(t || "Error while writing zip file.") - } - - function g(t) { - o(t || r) - } - var i = { - add: function(i, c, r, u, d) { - var s, n, a, p = this._worker; - - function l(t, e) { - var i = w(16); - v += t || 0, i.view.setUint32(0, 1347094280), void 0 !== e && (s.view.setUint32(10, e, !0), i.view.setUint32(4, e, !0)), c && (i.view.setUint32(8, t, !0), s.view.setUint32(14, t, !0), i.view.setUint32(12, c.size, !0), s.view.setUint32(18, c.size, !0)), f.writeUint8Array(i.array, function() { - v += 16, r() - }, b) - } - - function t() { - var t, e; - (d = d || {}, i = i.trim(), d.directory && "/" != i.charAt(i.length - 1) && (i += "/"), h.hasOwnProperty(i)) ? o("File already exists."): (n = T(S(i)), y.push(i), t = function() { - var t, e, i, r, s, n, a, o, h; - c ? m || 0 === d.level ? I(p, A++, c, f, 0, c.size, !0, l, u, g, b) : (t = p, e = A++, i = c, r = f, s = d.level, n = l, a = u, o = g, h = b, R.zip.useWebWorkers ? M(t, { - sn: e, - options: { - level: s - }, - codecClass: "Deflater", - crcType: "input" - }, i, r, 0, i.size, a, n, o, h) : _(new R.zip.Deflater, i, r, 0, i.size, "input", a, n, o, h)) : l() - }, a = d.lastModDate || new Date, s = w(26), h[i] = { - headerArray: s.array, - directory: d.directory, - filename: n, - offset: v, - comment: T(S(d.comment || "")) - }, s.view.setUint32(0, 335546376), d.version && s.view.setUint8(0, d.version), m || 0 === d.level || d.directory || s.view.setUint16(4, 2048), s.view.setUint16(6, (a.getHours() << 6 | a.getMinutes()) << 5 | a.getSeconds() / 2, !0), s.view.setUint16(8, (a.getFullYear() - 1980 << 4 | a.getMonth() + 1) << 5 | a.getDate(), !0), s.view.setUint16(22, n.length, !0), (e = w(30 + n.length)).view.setUint32(0, 1347093252), e.array.set(s.array, 4), e.array.set(n, 30), v += e.array.length, f.writeUint8Array(e.array, t, b)) - } - c ? c.init(t, g) : t() - }, - close: function(t) { - this._worker && (this._worker.terminate(), this._worker = null); - var e, i, r, s = 0, - n = 0; - for (i = 0; i < y.length; i++) s += 46 + (r = h[y[i]]).filename.length + r.comment.length; - for (e = w(s + 22), i = 0; i < y.length; i++) r = h[y[i]], e.view.setUint32(n, 1347092738), e.view.setUint16(n + 4, 5120), e.array.set(r.headerArray, n + 6), e.view.setUint16(n + 32, r.comment.length, !0), r.directory && e.view.setUint8(n + 38, 16), e.view.setUint32(n + 42, r.offset, !0), e.array.set(r.filename, n + 46), e.array.set(r.comment, n + 46 + r.filename.length), n += 46 + r.filename.length + r.comment.length; - e.view.setUint32(n, 1347093766), e.view.setUint16(n + 8, y.length, !0), e.view.setUint16(n + 10, y.length, !0), e.view.setUint32(n + 12, s, !0), e.view.setUint32(n + 16, v, !0), f.writeUint8Array(e.array, function() { - f.getData(t) - }, b) - }, - _worker: null - }; - R.zip.useWebWorkers ? B("deflater", function(t) { - i._worker = t, e(i) - }, function(t) { - o(t) - }) : e(i) - } - i.prototype.append = function(t) { - for (var e = 0 | this.crc, i = this.table, r = 0, s = 0 | t.length; r < s; r++) e = e >>> 8 ^ i[255 & (e ^ t[r])]; - this.crc = e - }, i.prototype.get = function() { - return ~this.crc - }, i.prototype.table = function() { - var t, e, i, r = []; - for (t = 0; t < 256; t++) { - for (i = t, e = 0; e < 8; e++) 1 & i ? i = i >>> 1 ^ 3988292384 : i >>>= 1; - r[t] = i - } - return r - }(), d.prototype.append = function(t, e) { - return t - }, d.prototype.flush = function() {}, (e.prototype = new t).constructor = e, (s.prototype = new t).constructor = s, (c.prototype = new t).constructor = c, u.prototype.getData = function(t) { - t(this.data) - }, (l.prototype = new u).constructor = l, (f.prototype = new u).constructor = f, (m.prototype = new u).constructor = m; - var P = { - deflater: ["z-worker.js", "deflate.js"], - inflater: ["z-worker.js", "inflate.js"] - }; - - function B(t, r, s) { - if (null === R.zip.workerScripts || null === R.zip.workerScriptsPath) { - var e, i, n; - if (R.zip.workerScripts) { - if (e = R.zip.workerScripts[t], !Array.isArray(e)) return void s(new Error("zip.workerScripts." + t + " is not an array!")); - i = e, n = document.createElement("a"), e = i.map(function(t) { - return n.href = t, n.href - }) - } else(e = P[t].slice(0))[0] = (R.zip.workerScriptsPath || "") + e[0]; - var a = new Worker(e[0]); - a.codecTime = a.crcTime = 0, a.postMessage({ - type: "importScripts", - scripts: e.slice(1) - }), a.addEventListener("message", function t(e) { - var i = e.data; - if (i.error) return a.terminate(), void s(i.error); - "importScripts" === i.type && (a.removeEventListener("message", t), a.removeEventListener("error", o), r(a)) - }), a.addEventListener("error", o) - } else s(new Error("Either zip.workerScripts or zip.workerScriptsPath may be set, not both.")); - - function o(t) { - a.terminate(), s(t) - } - } - - function N(t) { - console.error(t) - } - R.zip = { - Reader: t, - Writer: u, - BlobReader: c, - Data64URIReader: s, - TextReader: e, - BlobWriter: m, - Data64URIWriter: f, - TextWriter: l, - createReader: function(t, e, i) { - i = i || N, t.init(function() { - b(t, e, i) - }, i) - }, - createWriter: function(t, e, i, r) { - i = i || N, r = !!r, t.init(function() { - g(t, e, i, r) - }, i) - }, - useWebWorkers: !0, - workerScriptsPath: null, - workerScripts: null - } - }(this), - function() { - "use strict"; - var s, a, t = zip.Reader, - e = zip.Writer; - try { - a = 0 === new Blob([new DataView(new ArrayBuffer(0))]).size - } catch (t) {} - - function n(n, r) { - var a = this; - - function o(t, e) { - var i; - a.data ? t() : ((i = new XMLHttpRequest).addEventListener("load", function() { - a.size || (a.size = Number(i.getResponseHeader("Content-Length")) || Number(i.response.byteLength)), a.data = new Uint8Array(i.response), t() - }, !1), i.addEventListener("error", e, !1), i.open("GET", n), i.responseType = "arraybuffer", i.onprogress = r, i.send()) - } - a.size = 0, a.init = function(t, e) { - if (i = n, (r = document.createElement("a")).href = i, "http:" === r.protocol || "https:" === r.protocol) { - var i, r, s = new XMLHttpRequest; - s.addEventListener("load", function() { - a.size = Number(s.getResponseHeader("Content-Length")), a.size ? t() : o(t, e) - }, !1), s.addEventListener("error", e, !1), s.open("HEAD", n), s.send() - } else o(t, e) - }, a.readUint8Array = function(t, e, i, r) { - o(function() { - i(new Uint8Array(a.data.subarray(t, t + e))) - }, r) - } - } - - function o(c) { - var r = this; - r.size = 0, r.init = function(t, e) { - var i = new XMLHttpRequest; - i.addEventListener("load", function() { - r.size = Number(i.getResponseHeader("Content-Length")), "bytes" == i.getResponseHeader("Accept-Ranges") ? t() : e("HTTP Range not supported.") - }, !1), i.addEventListener("error", e, !1), i.open("HEAD", c), i.send() - }, r.readUint8Array = function(t, e, i, r) { - var s, n, a, o, h; - s = t, n = e, a = function(t) { - i(new Uint8Array(t)) - }, o = r, (h = new XMLHttpRequest).open("GET", c), h.responseType = "arraybuffer", h.setRequestHeader("Range", "bytes=" + s + "-" + (s + n - 1)), h.addEventListener("load", function() { - a(h.response) - }, !1), h.addEventListener("error", o, !1), h.send() - } - } - - function i(s) { - var i = this; - i.size = 0, i.init = function(t, e) { - i.size = s.byteLength, t() - }, i.readUint8Array = function(t, e, i, r) { - i(new Uint8Array(s.slice(t, t + e))) - } - } - - function r() { - var s; - this.init = function(t, e) { - s = new Uint8Array, t() - }, this.writeUint8Array = function(t, e, i) { - var r = new Uint8Array(s.length + t.length); - r.set(s), r.set(t, s.length), s = r, e() - }, this.getData = function(t) { - t(s.buffer) - } - } - - function h(i, s) { - var n; - this.init = function(e, t) { - i.createWriter(function(t) { - n = t, e() - }, t) - }, this.writeUint8Array = function(t, e, i) { - var r = new Blob([a ? t : t.buffer], { - type: s - }); - n.onwrite = function() { - n.onwrite = null, e() - }, n.onerror = i, n.write(r) - }, this.getData = function(t) { - i.file(t) - } - }(n.prototype = new t).constructor = n, (o.prototype = new t).constructor = o, (i.prototype = new t).constructor = i, (r.prototype = new e).constructor = r, (h.prototype = new e).constructor = h, zip.FileWriter = h, zip.HttpReader = n, zip.HttpRangeReader = o, zip.ArrayBufferReader = i, zip.ArrayBufferWriter = r, zip.fs && ((s = zip.fs.ZipDirectoryEntry).prototype.addHttpContent = function(t, e, i) { - return function(t, e, i, r) { - if (t.directory) return r ? new s(t.fs, e, i, t) : new zip.fs.ZipFileEntry(t.fs, e, i, t); - throw "Parent entry is not a directory." - }(this, t, { - data: e, - Reader: i ? o : n - }) - }, s.prototype.importHttpContent = function(t, e, i, r) { - this.importZip(e ? new o(t) : new n(t), i, r) - }, zip.fs.FS.prototype.importHttpContent = function(t, e, i, r) { - this.entries = [], this.root = new s(this), this.root.importHttpContent(t, e, i, r) - }) - }(), - function(t) { - if ("object" == typeof exports && "undefined" != typeof module) module.exports = t(); - else if ("function" == typeof define && define.amd) define([], t); - else { - ("undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof self ? self : this).localforage = t() - } - }(function() { - return function n(a, o, h) { - function c(e, t) { - if (!o[e]) { - if (!a[e]) { - var i = "function" == typeof require && require; - if (!t && i) return i(e, !0); - if (u) return u(e, !0); - var r = new Error("Cannot find module '" + e + "'"); - throw r.code = "MODULE_NOT_FOUND", r - } - var s = o[e] = { - exports: {} - }; - a[e][0].call(s.exports, function(t) { - return c(a[e][1][t] || t) - }, s, s.exports, n, a, o, h) - } - return o[e].exports - } - for (var u = "function" == typeof require && require, t = 0; t < h.length; t++) c(h[t]); - return c - }({ - 1: [ - function(t, e, i) { - "use strict"; - - function a(e, i) { - e = e || [], i = i || {}; - try { - return new Blob(e, i) - } catch (t) { - if ("TypeError" !== t.name) throw t; - for (var r = new("undefined" != typeof BlobBuilder ? BlobBuilder : "undefined" != typeof MSBlobBuilder ? MSBlobBuilder : "undefined" != typeof MozBlobBuilder ? MozBlobBuilder : WebKitBlobBuilder), s = 0; s < e.length; s += 1) r.append(e[s]); - return r.getBlob(i.type) - } - } - - function d(t, e) { - e && t.then(function(t) { - e(null, t) - }, function(t) { - e(t) - }) - } - - function h(t, e, i) { - "function" == typeof e && t.then(e), "function" == typeof i && t.catch(i) - } - - function p(t) { - return "string" != typeof t && (console.warn(t + " used as a key, but it is not a string."), t = String(t)), t - } - - function n() { - if (arguments.length && "function" == typeof arguments[arguments.length - 1]) return arguments[arguments.length - 1] - } - - function r(t) { - return "boolean" == typeof B ? T.resolve(B) : (r = t, new T(function(i) { - var t = r.transaction(P, G), - e = a([""]); - t.objectStore(P).put(e, "key"), t.onabort = function(t) { - t.preventDefault(), t.stopPropagation(), i(!1) - }, t.oncomplete = function() { - var t = navigator.userAgent.match(/Chrome\/(\d+)/), - e = navigator.userAgent.match(/Edge\//); - i(e || !t || 43 <= parseInt(t[1], 10)) - } - }).catch(function() { - return !1 - })).then(function(t) { - return B = t - }); - var r - } - - function o(t) { - var e = N[t.name], - i = {}; - i.promise = new T(function(t, e) { - i.resolve = t, i.reject = e - }), e.deferredOperations.push(i), e.dbReady ? e.dbReady = e.dbReady.then(function() { - return i.promise - }) : e.dbReady = i.promise - } - - function c(t) { - var e = N[t.name].deferredOperations.pop(); - if (e) return e.resolve(), e.promise - } - - function u(t, e) { - var i = N[t.name].deferredOperations.pop(); - if (i) return i.reject(e), i.promise - } - - function s(s, n) { - return new T(function(t, e) { - if (N[s.name] = N[s.name] || { - forages: [], - db: null, - dbReady: null, - deferredOperations: [] - }, s.db) { - if (!n) return t(s.db); - o(s), s.db.close() - } - var i = [s.name]; - n && i.push(s.version); - var r = O.open.apply(O, i); - n && (r.onupgradeneeded = function(t) { - var e = r.result; - try { - e.createObjectStore(s.storeName), t.oldVersion <= 1 && e.createObjectStore(P) - } catch (e) { - if ("ConstraintError" !== e.name) throw e; - console.warn('The database "' + s.name + '" has been upgraded from version ' + t.oldVersion + " to version " + t.newVersion + ', but the storage "' + s.storeName + '" already exists.') - } - }), r.onerror = function(t) { - t.preventDefault(), e(r.error) - }, r.onsuccess = function() { - t(r.result), c(s) - } - }) - } - - function l(t) { - return s(t, !1) - } - - function f(t) { - return s(t, !0) - } - - function m(t, e) { - if (!t.db) return !0; - var i = !t.db.objectStoreNames.contains(t.storeName), - r = t.version < t.db.version, - s = t.version > t.db.version; - if (r && (t.version !== e && console.warn('The database "' + t.name + "\" can't be downgraded from version " + t.db.version + " to version " + t.version + "."), t.version = t.db.version), s || i) { - if (i) { - var n = t.db.version + 1; - n > t.version && (t.version = n) - } - return !0 - } - return !1 - } - - function y(t) { - return a([ - function(t) { - for (var e = t.length, i = new ArrayBuffer(e), r = new Uint8Array(i), s = 0; s < e; s++) r[s] = t.charCodeAt(s); - return i - }(atob(t.data)) - ], { - type: t.type - }) - } - - function v(t) { - return t && t.__local_forage_encoded_blob - } - - function A(t) { - var e = this, - i = e._initReady().then(function() { - var t = N[e._dbInfo.name]; - if (t && t.dbReady) return t.dbReady - }); - return h(i, t, t), i - } - - function b(t, e, i, r) { - void 0 === r && (r = 1); - try { - var s = t.db.transaction(t.storeName, e); - i(null, s) - } catch (s) { - if (0 < r && (!t.db || "InvalidStateError" === s.name || "NotFoundError" === s.name)) return T.resolve().then(function() { - if (!t.db || "NotFoundError" === s.name && !t.db.objectStoreNames.contains(t.storeName) && t.version <= t.db.version) return t.db && (t.version = t.db.version + 1), f(t) - }).then(function() { - return function(i) { - o(i); - for (var r = N[i.name], s = r.forages, t = 0; t < s.length; t++) { - var e = s[t]; - e._dbInfo.db && (e._dbInfo.db.close(), e._dbInfo.db = null) - } - return i.db = null, l(i).then(function(t) { - return i.db = t, m(i) ? f(i) : t - }).then(function(t) { - i.db = r.db = t; - for (var e = 0; e < s.length; e++) s[e]._dbInfo.db = t - }).catch(function(t) { - throw u(i, t), t - }) - }(t).then(function() { - b(t, e, i, r - 1) - }) - }).catch(i); - i(s) - } - } - - function g(t) { - var e, i, r, s, n, a = .75 * t.length, - o = t.length, - h = 0; - "=" === t[t.length - 1] && (a--, "=" === t[t.length - 2] && a--); - var c = new ArrayBuffer(a), - u = new Uint8Array(c); - for (e = 0; e < o; e += 4) i = x.indexOf(t[e]), r = x.indexOf(t[e + 1]), s = x.indexOf(t[e + 2]), n = x.indexOf(t[e + 3]), u[h++] = i << 2 | r >> 4, u[h++] = (15 & r) << 4 | s >> 2, u[h++] = (3 & s) << 6 | 63 & n; - return c - } - - function S(t) { - var e, i = new Uint8Array(t), - r = ""; - for (e = 0; e < i.length; e += 3) r += x[i[e] >> 2], r += x[(3 & i[e]) << 4 | i[e + 1] >> 4], r += x[(15 & i[e + 1]) << 2 | i[e + 2] >> 6], r += x[63 & i[e + 2]]; - return i.length % 3 == 2 ? r = r.substring(0, r.length - 1) + "=" : i.length % 3 == 1 && (r = r.substring(0, r.length - 2) + "=="), r - } - - function R(t, e, i, r) { - t.executeSql("CREATE TABLE IF NOT EXISTS " + e.storeName + " (id INTEGER PRIMARY KEY, key unique, value)", [], i, r) - } - - function C(t, r, s, n, a, o) { - t.executeSql(s, n, a, function(t, i) { - i.code === i.SYNTAX_ERR ? t.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name = ?", [r.storeName], function(t, e) { - e.rows.length ? o(t, i) : R(t, r, function() { - t.executeSql(s, n, a, o) - }, o) - }, o) : o(t, i) - }, o) - } - - function w(t, e) { - var i = t.name + "/"; - return t.storeName !== e.storeName && (i += t.storeName + "/"), i - } - - function M() { - return ! function() { - var t = "_localforage_support_test"; - try { - return localStorage.setItem(t, !0), localStorage.removeItem(t), !1 - } catch (t) { - return !0 - } - }() || 0 < localStorage.length - } - - function _(e, i) { - e[i] = function() { - var t = arguments; - return e.ready().then(function() { - return e[i].apply(e, t) - }) - } - } - - function I() { - for (var t = 1; t < arguments.length; t++) { - var e = arguments[t]; - if (e) - for (var i in e) e.hasOwnProperty(i) && (Z(e[i]) ? arguments[0][i] = e[i].slice() : arguments[0][i] = e[i]) - } - return arguments[0] - } - var E = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) { - return typeof t - } : function(t) { - return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t - }, - O = function() { - try { - if ("undefined" != typeof indexedDB) return indexedDB; - if ("undefined" != typeof webkitIndexedDB) return webkitIndexedDB; - if ("undefined" != typeof mozIndexedDB) return mozIndexedDB; - if ("undefined" != typeof OIndexedDB) return OIndexedDB; - if ("undefined" != typeof msIndexedDB) return msIndexedDB - } catch (t) { - return - } - }(); - "undefined" == typeof Promise && t("lie/polyfill"); - var T = Promise, - P = "local-forage-detect-blob-support", - B = void 0, - N = {}, - k = Object.prototype.toString, - D = "readonly", - G = "readwrite", - L = { - _driver: "asyncStorage", - _initStorage: function(t) { - function e() { - return T.resolve() - } - var r = this, - s = { - db: null - }; - if (t) - for (var i in t) s[i] = t[i]; - var n = N[s.name]; - n || (n = { - forages: [], - db: null, - dbReady: null, - deferredOperations: [] - }, N[s.name] = n), n.forages.push(r), r._initReady || (r._initReady = r.ready, r.ready = A); - for (var a = [], o = 0; o < n.forages.length; o++) { - var h = n.forages[o]; - h !== r && a.push(h._initReady().catch(e)) - } - var c = n.forages.slice(0); - return T.all(a).then(function() { - return s.db = n.db, l(s) - }).then(function(t) { - return s.db = t, m(s, r._defaultConfig.version) ? f(s) : t - }).then(function(t) { - s.db = n.db = t, r._dbInfo = s; - for (var e = 0; e < c.length; e++) { - var i = c[e]; - i !== r && (i._dbInfo.db = s.db, i._dbInfo.version = s.version) - } - }) - }, - _support: function() { - try { - if (!O) return !1; - var t = "undefined" != typeof openDatabase && /(Safari|iPhone|iPad|iPod)/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent) && !/BlackBerry/.test(navigator.platform), - e = "function" == typeof fetch && -1 !== fetch.toString().indexOf("[native code"); - return (!t || e) && "undefined" != typeof indexedDB && "undefined" != typeof IDBKeyRange - } catch (t) { - return !1 - } - }(), - iterate: function(a, t) { - var o = this, - e = new T(function(n, i) { - o.ready().then(function() { - b(o._dbInfo, D, function(t, e) { - if (t) return i(t); - try { - var r = e.objectStore(o._dbInfo.storeName).openCursor(), - s = 1; - r.onsuccess = function() { - var t = r.result; - if (t) { - var e = t.value; - v(e) && (e = y(e)); - var i = a(e, t.key, s++); - void 0 !== i ? n(i) : t.continue() - } else n() - }, r.onerror = function() { - i(r.error) - } - } catch (t) { - i(t) - } - }) - }).catch(i) - }); - return d(e, t), e - }, - getItem: function(n, t) { - var a = this; - n = p(n); - var e = new T(function(r, s) { - a.ready().then(function() { - b(a._dbInfo, D, function(t, e) { - if (t) return s(t); - try { - var i = e.objectStore(a._dbInfo.storeName).get(n); - i.onsuccess = function() { - var t = i.result; - void 0 === t && (t = null), v(t) && (t = y(t)), r(t) - }, i.onerror = function() { - s(i.error) - } - } catch (t) { - s(t) - } - }) - }).catch(s) - }); - return d(e, t), e - }, - setItem: function(o, e, t) { - var h = this; - o = p(o); - var i = new T(function(n, a) { - var t; - h.ready().then(function() { - return t = h._dbInfo, "[object Blob]" === k.call(e) ? r(t.db).then(function(t) { - return t ? e : (r = e, new T(function(i, t) { - var e = new FileReader; - e.onerror = t, e.onloadend = function(t) { - var e = btoa(t.target.result || ""); - i({ - __local_forage_encoded_blob: !0, - data: e, - type: r.type - }) - }, e.readAsBinaryString(r) - })); - var r - }) : e - }).then(function(s) { - b(h._dbInfo, G, function(t, e) { - if (t) return a(t); - try { - var i = e.objectStore(h._dbInfo.storeName); - null === s && (s = void 0); - var r = i.put(s, o); - e.oncomplete = function() { - void 0 === s && (s = null), n(s) - }, e.onabort = e.onerror = function() { - var t = r.error ? r.error : r.transaction.error; - a(t) - } - } catch (t) { - a(t) - } - }) - }).catch(a) - }); - return d(i, t), i - }, - removeItem: function(n, t) { - var a = this; - n = p(n); - var e = new T(function(r, s) { - a.ready().then(function() { - b(a._dbInfo, G, function(t, e) { - if (t) return s(t); - try { - var i = e.objectStore(a._dbInfo.storeName).delete(n); - e.oncomplete = function() { - r() - }, e.onerror = function() { - s(i.error) - }, e.onabort = function() { - var t = i.error ? i.error : i.transaction.error; - s(t) - } - } catch (t) { - s(t) - } - }) - }).catch(s) - }); - return d(e, t), e - }, - clear: function(t) { - var n = this, - e = new T(function(r, s) { - n.ready().then(function() { - b(n._dbInfo, G, function(t, e) { - if (t) return s(t); - try { - var i = e.objectStore(n._dbInfo.storeName).clear(); - e.oncomplete = function() { - r() - }, e.onabort = e.onerror = function() { - var t = i.error ? i.error : i.transaction.error; - s(t) - } - } catch (t) { - s(t) - } - }) - }).catch(s) - }); - return d(e, t), e - }, - length: function(t) { - var n = this, - e = new T(function(r, s) { - n.ready().then(function() { - b(n._dbInfo, D, function(t, e) { - if (t) return s(t); - try { - var i = e.objectStore(n._dbInfo.storeName).count(); - i.onsuccess = function() { - r(i.result) - }, i.onerror = function() { - s(i.error) - } - } catch (t) { - s(t) - } - }) - }).catch(s) - }); - return d(e, t), e - }, - key: function(o, t) { - var h = this, - e = new T(function(n, a) { - o < 0 ? n(null) : h.ready().then(function() { - b(h._dbInfo, D, function(t, e) { - if (t) return a(t); - try { - var i = e.objectStore(h._dbInfo.storeName), - r = !1, - s = i.openCursor(); - s.onsuccess = function() { - var t = s.result; - t ? 0 === o ? n(t.key) : r ? n(t.key) : (r = !0, t.advance(o)) : n(null) - }, s.onerror = function() { - a(s.error) - } - } catch (t) { - a(t) - } - }) - }).catch(a) - }); - return d(e, t), e - }, - keys: function(t) { - var a = this, - e = new T(function(s, n) { - a.ready().then(function() { - b(a._dbInfo, D, function(t, e) { - if (t) return n(t); - try { - var i = e.objectStore(a._dbInfo.storeName).openCursor(), - r = []; - i.onsuccess = function() { - var t = i.result; - t ? (r.push(t.key), t.continue()) : s(r) - }, i.onerror = function() { - n(i.error) - } - } catch (t) { - n(t) - } - }) - }).catch(n) - }); - return d(e, t), e - }, - dropInstance: function(a, t) { - t = n.apply(this, arguments); - var e, i = this.config(); - if ((a = "function" != typeof a && a || {}).name || (a.name = a.name || i.name, a.storeName = a.storeName || i.storeName), a.name) { - var r = a.name === i.name && this._dbInfo.db ? T.resolve(this._dbInfo.db) : l(a).then(function(t) { - var e = N[a.name], - i = e.forages; - e.db = t; - for (var r = 0; r < i.length; r++) i[r]._dbInfo.db = t; - return t - }); - e = a.storeName ? r.then(function(t) { - if (t.objectStoreNames.contains(a.storeName)) { - var s = t.version + 1; - o(a); - var r = N[a.name], - n = r.forages; - t.close(); - for (var e = 0; e < n.length; e++) { - var i = n[e]; - i._dbInfo.db = null, i._dbInfo.version = s - } - return new T(function(e, i) { - var r = O.open(a.name, s); - r.onerror = function(t) { - r.result.close(), i(t) - }, r.onupgradeneeded = function() { - r.result.deleteObjectStore(a.storeName) - }, r.onsuccess = function() { - var t = r.result; - t.close(), e(t) - } - }).then(function(t) { - r.db = t; - for (var e = 0; e < n.length; e++) { - var i = n[e]; - i._dbInfo.db = t, c(i._dbInfo) - } - }).catch(function(t) { - throw (u(a, t) || T.resolve()).catch(function() {}), t - }) - } - }) : r.then(function(t) { - o(a); - var i = N[a.name], - r = i.forages; - t.close(); - for (var e = 0; e < r.length; e++) r[e]._dbInfo.db = null; - return new T(function(e, i) { - var r = O.deleteDatabase(a.name); - r.onerror = r.onblocked = function(t) { - var e = r.result; - e && e.close(), i(t) - }, r.onsuccess = function() { - var t = r.result; - t && t.close(), e(t) - } - }).then(function(t) { - i.db = t; - for (var e = 0; e < r.length; e++) c(r[e]._dbInfo) - }).catch(function(t) { - throw (u(a, t) || T.resolve()).catch(function() {}), t - }) - }) - } else e = T.reject("Invalid arguments"); - return d(e, t), e - } - }, - x = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", - U = /^~~local_forage_type~([^~]+)~/, - H = "__lfsc__:", - F = H.length, - W = "arbf", - V = "blob", - z = F + W.length, - q = Object.prototype.toString, - K = { - serialize: function(e, i) { - var t = ""; - if (e && (t = q.call(e)), e && ("[object ArrayBuffer]" === t || e.buffer && "[object ArrayBuffer]" === q.call(e.buffer))) { - var r, s = H; - e instanceof ArrayBuffer ? (r = e, s += W) : (r = e.buffer, "[object Int8Array]" === t ? s += "si08" : "[object Uint8Array]" === t ? s += "ui08" : "[object Uint8ClampedArray]" === t ? s += "uic8" : "[object Int16Array]" === t ? s += "si16" : "[object Uint16Array]" === t ? s += "ur16" : "[object Int32Array]" === t ? s += "si32" : "[object Uint32Array]" === t ? s += "ui32" : "[object Float32Array]" === t ? s += "fl32" : "[object Float64Array]" === t ? s += "fl64" : i(new Error("Failed to get type for BinaryArray"))), i(s + S(r)) - } else if ("[object Blob]" === t) { - var n = new FileReader; - n.onload = function() { - var t = "~~local_forage_type~" + e.type + "~" + S(this.result); - i(H + V + t) - }, n.readAsArrayBuffer(e) - } else try { - i(JSON.stringify(e)) - } catch (t) { - console.error("Couldn't convert value into a JSON string: ", e), i(null, t) - } - }, - deserialize: function(t) { - if (t.substring(0, F) !== H) return JSON.parse(t); - var e, i = t.substring(z), - r = t.substring(F, z); - if (r === V && U.test(i)) { - var s = i.match(U); - e = s[1], i = i.substring(s[0].length) - } - var n = g(i); - switch (r) { - case W: - return n; - case V: - return a([n], { - type: e - }); - case "si08": - return new Int8Array(n); - case "ui08": - return new Uint8Array(n); - case "uic8": - return new Uint8ClampedArray(n); - case "si16": - return new Int16Array(n); - case "ur16": - return new Uint16Array(n); - case "si32": - return new Int32Array(n); - case "ui32": - return new Uint32Array(n); - case "fl32": - return new Float32Array(n); - case "fl64": - return new Float64Array(n); - default: - throw new Error("Unkown type: " + r) - } - }, - stringToBuffer: g, - bufferToString: S - }, - j = { - _driver: "webSQLStorage", - _initStorage: function(t) { - var r = this, - s = { - db: null - }; - if (t) - for (var e in t) s[e] = "string" != typeof t[e] ? t[e].toString() : t[e]; - var i = new T(function(e, i) { - try { - s.db = openDatabase(s.name, String(s.version), s.description, s.size) - } catch (e) { - return i(e) - } - s.db.transaction(function(t) { - R(t, s, function() { - r._dbInfo = s, e() - }, function(t, e) { - i(e) - }) - }, i) - }); - return s.serializer = K, i - }, - _support: "function" == typeof openDatabase, - iterate: function(c, t) { - var e = this, - i = new T(function(h, i) { - e.ready().then(function() { - var o = e._dbInfo; - o.db.transaction(function(t) { - C(t, o, "SELECT * FROM " + o.storeName, [], function(t, e) { - for (var i = e.rows, r = i.length, s = 0; s < r; s++) { - var n = i.item(s), - a = n.value; - if (a && (a = o.serializer.deserialize(a)), void 0 !== (a = c(a, n.key, s + 1))) return void h(a) - } - h() - }, function(t, e) { - i(e) - }) - }) - }).catch(i) - }); - return d(i, t), i - }, - getItem: function(e, t) { - var n = this; - e = p(e); - var i = new T(function(s, i) { - n.ready().then(function() { - var r = n._dbInfo; - r.db.transaction(function(t) { - C(t, r, "SELECT * FROM " + r.storeName + " WHERE key = ? LIMIT 1", [e], function(t, e) { - var i = e.rows.length ? e.rows.item(0).value : null; - i && (i = r.serializer.deserialize(i)), s(i) - }, function(t, e) { - i(e) - }) - }) - }).catch(i) - }); - return d(i, t), i - }, - setItem: function(t, e, i) { - return function a(o, t, h, c) { - var u = this; - o = p(o); - var e = new T(function(s, n) { - u.ready().then(function() { - void 0 === t && (t = null); - var i = t, - r = u._dbInfo; - r.serializer.serialize(t, function(e, t) { - t ? n(t) : r.db.transaction(function(t) { - C(t, r, "INSERT OR REPLACE INTO " + r.storeName + " (key, value) VALUES (?, ?)", [o, e], function() { - s(i) - }, function(t, e) { - n(e) - }) - }, function(t) { - if (t.code === t.QUOTA_ERR) { - if (0 < c) return void s(a.apply(u, [o, i, h, c - 1])); - n(t) - } - }) - }) - }).catch(n) - }); - return d(e, h), e - }.apply(this, [t, e, i, 1]) - }, - removeItem: function(s, t) { - var n = this; - s = p(s); - var e = new T(function(i, r) { - n.ready().then(function() { - var e = n._dbInfo; - e.db.transaction(function(t) { - C(t, e, "DELETE FROM " + e.storeName + " WHERE key = ?", [s], function() { - i() - }, function(t, e) { - r(e) - }) - }) - }).catch(r) - }); - return d(e, t), e - }, - clear: function(t) { - var s = this, - e = new T(function(i, r) { - s.ready().then(function() { - var e = s._dbInfo; - e.db.transaction(function(t) { - C(t, e, "DELETE FROM " + e.storeName, [], function() { - i() - }, function(t, e) { - r(e) - }) - }) - }).catch(r) - }); - return d(e, t), e - }, - length: function(t) { - var s = this, - e = new T(function(r, i) { - s.ready().then(function() { - var e = s._dbInfo; - e.db.transaction(function(t) { - C(t, e, "SELECT COUNT(key) as c FROM " + e.storeName, [], function(t, e) { - var i = e.rows.item(0).c; - r(i) - }, function(t, e) { - i(e) - }) - }) - }).catch(i) - }); - return d(e, t), e - }, - key: function(s, t) { - var n = this, - e = new T(function(r, i) { - n.ready().then(function() { - var e = n._dbInfo; - e.db.transaction(function(t) { - C(t, e, "SELECT key FROM " + e.storeName + " WHERE id = ? LIMIT 1", [s + 1], function(t, e) { - var i = e.rows.length ? e.rows.item(0).key : null; - r(i) - }, function(t, e) { - i(e) - }) - }) - }).catch(i) - }); - return d(e, t), e - }, - keys: function(t) { - var r = this, - e = new T(function(s, i) { - r.ready().then(function() { - var e = r._dbInfo; - e.db.transaction(function(t) { - C(t, e, "SELECT key FROM " + e.storeName, [], function(t, e) { - for (var i = [], r = 0; r < e.rows.length; r++) i.push(e.rows.item(r).key); - s(i) - }, function(t, e) { - i(e) - }) - }) - }).catch(i) - }); - return d(e, t), e - }, - dropInstance: function(i, t) { - t = n.apply(this, arguments); - var r = this.config(); - (i = "function" != typeof i && i || {}).name || (i.name = i.name || r.name, i.storeName = i.storeName || r.storeName); - var e, s = this; - return d(e = i.name ? new T(function(t) { - var e, n; - e = i.name === r.name ? s._dbInfo.db : openDatabase(i.name, "", "", 0), t(i.storeName ? { - db: e, - storeNames: [i.storeName] - } : (n = e, new T(function(s, i) { - n.transaction(function(t) { - t.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name <> '__WebKitDatabaseInfoTable__'", [], function(t, e) { - for (var i = [], r = 0; r < e.rows.length; r++) i.push(e.rows.item(r).name); - s({ - db: n, - storeNames: i - }) - }, function(t, e) { - i(e) - }) - }, function(t) { - i(t) - }) - }))) - }).then(function(o) { - return new T(function(n, a) { - o.db.transaction(function(r) { - function t(e) { - return new T(function(t, i) { - r.executeSql("DROP TABLE IF EXISTS " + e, [], function() { - t() - }, function(t, e) { - i(e) - }) - }) - } - for (var e = [], i = 0, s = o.storeNames.length; i < s; i++) e.push(t(o.storeNames[i])); - T.all(e).then(function() { - n() - }).catch(function(t) { - a(t) - }) - }, function(t) { - a(t) - }) - }) - }) : T.reject("Invalid arguments"), t), e - } - }, - Q = { - _driver: "localStorageWrapper", - _initStorage: function(t) { - var e = {}; - if (t) - for (var i in t) e[i] = t[i]; - return e.keyPrefix = w(t, this._defaultConfig), M() ? ((this._dbInfo = e).serializer = K, T.resolve()) : T.reject() - }, - _support: function() { - try { - return "undefined" != typeof localStorage && "setItem" in localStorage && !!localStorage.setItem - } catch (t) { - return !1 - } - }(), - iterate: function(h, t) { - var c = this, - e = c.ready().then(function() { - for (var t = c._dbInfo, e = t.keyPrefix, i = e.length, r = localStorage.length, s = 1, n = 0; n < r; n++) { - var a = localStorage.key(n); - if (0 === a.indexOf(e)) { - var o = localStorage.getItem(a); - if (o && (o = t.serializer.deserialize(o)), void 0 !== (o = h(o, a.substring(i), s++))) return o - } - } - }); - return d(e, t), e - }, - getItem: function(i, t) { - var r = this; - i = p(i); - var e = r.ready().then(function() { - var t = r._dbInfo, - e = localStorage.getItem(t.keyPrefix + i); - return e && (e = t.serializer.deserialize(e)), e - }); - return d(e, t), e - }, - setItem: function(a, t, e) { - var o = this; - a = p(a); - var i = o.ready().then(function() { - void 0 === t && (t = null); - var n = t; - return new T(function(i, r) { - var s = o._dbInfo; - s.serializer.serialize(t, function(t, e) { - if (e) r(e); - else try { - localStorage.setItem(s.keyPrefix + a, t), i(n) - } catch (t) { - "QuotaExceededError" !== t.name && "NS_ERROR_DOM_QUOTA_REACHED" !== t.name || r(t), r(t) - } - }) - }) - }); - return d(i, e), i - }, - removeItem: function(e, t) { - var i = this; - e = p(e); - var r = i.ready().then(function() { - var t = i._dbInfo; - localStorage.removeItem(t.keyPrefix + e) - }); - return d(r, t), r - }, - clear: function(t) { - var r = this, - e = r.ready().then(function() { - for (var t = r._dbInfo.keyPrefix, e = localStorage.length - 1; 0 <= e; e--) { - var i = localStorage.key(e); - 0 === i.indexOf(t) && localStorage.removeItem(i) - } - }); - return d(e, t), e - }, - length: function(t) { - var e = this.keys().then(function(t) { - return t.length - }); - return d(e, t), e - }, - key: function(i, t) { - var r = this, - e = r.ready().then(function() { - var e, t = r._dbInfo; - try { - e = localStorage.key(i) - } catch (t) { - e = null - } - return e && (e = e.substring(t.keyPrefix.length)), e - }); - return d(e, t), e - }, - keys: function(t) { - var n = this, - e = n.ready().then(function() { - for (var t = n._dbInfo, e = localStorage.length, i = [], r = 0; r < e; r++) { - var s = localStorage.key(r); - 0 === s.indexOf(t.keyPrefix) && i.push(s.substring(t.keyPrefix.length)) - } - return i - }); - return d(e, t), e - }, - dropInstance: function(e, t) { - if (t = n.apply(this, arguments), !(e = "function" != typeof e && e || {}).name) { - var i = this.config(); - e.name = e.name || i.name, e.storeName = e.storeName || i.storeName - } - var r, s = this; - return d(r = e.name ? new T(function(t) { - t(e.storeName ? w(e, s._defaultConfig) : e.name + "/") - }).then(function(t) { - for (var e = localStorage.length - 1; 0 <= e; e--) { - var i = localStorage.key(e); - 0 === i.indexOf(t) && localStorage.removeItem(i) - } - }) : T.reject("Invalid arguments"), t), r - } - }, - Y = function(t, e) { - for (var i = t.length, r = 0; r < i;) { - if ((s = t[r]) === (n = e) || "number" == typeof s && "number" == typeof n && isNaN(s) && isNaN(n)) return !0; - r++ - } - var s, n; - return !1 - }, - Z = Array.isArray || function(t) { - return "[object Array]" === Object.prototype.toString.call(t) - }, - X = {}, - J = {}, - $ = { - INDEXEDDB: L, - WEBSQL: j, - LOCALSTORAGE: Q - }, - tt = [$.INDEXEDDB._driver, $.WEBSQL._driver, $.LOCALSTORAGE._driver], - et = ["dropInstance"], - it = ["clear", "getItem", "iterate", "key", "keys", "length", "removeItem", "setItem"].concat(et), - rt = { - description: "", - driver: tt.slice(), - name: "localforage", - size: 4980736, - storeName: "keyvaluepairs", - version: 1 - }, - st = new(function() { - function s(t) { - for (var e in function(t, e) { - if (!(t instanceof e)) throw new TypeError("Cannot call a class as a function") - }(this, s), $) - if ($.hasOwnProperty(e)) { - var i = $[e], - r = i._driver; - this[e] = r, X[r] || this.defineDriver(i) - } - this._defaultConfig = I({}, rt), this._config = I({}, this._defaultConfig, t), this._driverSet = null, this._initDriver = null, this._ready = !1, this._dbInfo = null, this._wrapLibraryMethodsWithReady(), this.setDriver(this._config.driver).catch(function() {}) - } - return s.prototype.config = function(t) { - if ("object" === (void 0 === t ? "undefined" : E(t))) { - if (this._ready) return new Error("Can't call config() after localforage has been used."); - for (var e in t) { - if ("storeName" === e && (t[e] = t[e].replace(/\W/g, "_")), "version" === e && "number" != typeof t[e]) return new Error("Database version must be a number."); - this._config[e] = t[e] - } - return !("driver" in t && t.driver) || this.setDriver(this._config.driver) - } - return "string" == typeof t ? this._config[t] : this._config - }, s.prototype.defineDriver = function(c, t, e) { - var i = new T(function(e, i) { - try { - var r = c._driver, - t = new Error("Custom driver not compliant; see https://mozilla.github.io/localForage/#definedriver"); - if (!c._driver) return void i(t); - for (var s = it.concat("_initStorage"), n = 0, a = s.length; n < a; n++) { - var o = s[n]; - if ((!Y(et, o) || c[o]) && "function" != typeof c[o]) return void i(t) - }! function() { - for (var t = function(i) { - return function() { - var t = new Error("Method " + i + " is not implemented by the current driver"), - e = T.reject(t); - return d(e, arguments[arguments.length - 1]), e - } - }, e = 0, i = et.length; e < i; e++) { - var r = et[e]; - c[r] || (c[r] = t(r)) - } - }(); - var h = function(t) { - X[r] && console.info("Redefining LocalForage driver: " + r), X[r] = c, J[r] = t, e() - }; - "_support" in c ? c._support && "function" == typeof c._support ? c._support().then(h, i) : h(!!c._support) : h(!0) - } catch (t) { - i(t) - } - }); - return h(i, t, e), i - }, s.prototype.driver = function() { - return this._driver || null - }, s.prototype.getDriver = function(t, e, i) { - var r = X[t] ? T.resolve(X[t]) : T.reject(new Error("Driver not found.")); - return h(r, e, i), r - }, s.prototype.getSerializer = function(t) { - var e = T.resolve(K); - return h(e, t), e - }, s.prototype.ready = function(t) { - var e = this, - i = e._driverSet.then(function() { - return null === e._ready && (e._ready = e._initDriver()), e._ready - }); - return h(i, t, t), i - }, s.prototype.setDriver = function(t, e, i) { - function n() { - o._config.driver = o.driver() - } - - function a(t) { - return o._extend(t), n(), o._ready = o._initStorage(o._config), o._ready - } - var o = this; - Z(t) || (t = [t]); - var r = this._getSupportedDrivers(t), - s = null !== this._driverSet ? this._driverSet.catch(function() { - return T.resolve() - }) : T.resolve(); - return this._driverSet = s.then(function() { - var t = r[0]; - return o._dbInfo = null, o._ready = null, o.getDriver(t).then(function(t) { - var s; - o._driver = t._driver, n(), o._wrapLibraryMethodsWithReady(), o._initDriver = (s = r, function() { - var r = 0; - return function t() { - for (; r < s.length;) { - var e = s[r]; - return r++, o._dbInfo = null, o._ready = null, o.getDriver(e).then(a).catch(t) - } - n(); - var i = new Error("No available storage method found."); - return o._driverSet = T.reject(i), o._driverSet - }() - }) - }) - }).catch(function() { - n(); - var t = new Error("No available storage method found."); - return o._driverSet = T.reject(t), o._driverSet - }), h(this._driverSet, e, i), this._driverSet - }, s.prototype.supports = function(t) { - return !!J[t] - }, s.prototype._extend = function(t) { - I(this, t) - }, s.prototype._getSupportedDrivers = function(t) { - for (var e = [], i = 0, r = t.length; i < r; i++) { - var s = t[i]; - this.supports(s) && e.push(s) - } - return e - }, s.prototype._wrapLibraryMethodsWithReady = function() { - for (var t = 0, e = it.length; t < e; t++) _(this, it[t]) - }, s.prototype.createInstance = function(t) { - return new s(t) - }, s - }()); - e.exports = st - }, { - undefined: void 0 - } - ] - }, {}, [1])(1) - }), - function(t) { - "use strict"; - var h, c, e, i, r, s, u = document, - d = function() { - return u.getElementById("app_wrap") || u.getElementsByTagName("body")[0] - }, - p = "getElementsByClassName", - l = function(t) { - return u.querySelectorAll(t) - }, - n = { - type: 0, - shade: !0, - shadeClose: !0, - fixed: !0, - anim: "scale" - }, - f = { - extend: function(t) { - var e, i = JSON.parse(JSON.stringify(n)); - for (e in t) i[e] = t[e]; - return i - }, - timer: {}, - end: {} - }; - f.touch = function(t, e) { - t.addEventListener("click", function(t) { - e.call(this, t) - }, !1) - }, h = 0, c = ["layui-m-layer"], (e = function(t) { - this.config = f.extend(t), this.view() - }).prototype.view = function() { - var t, e, i, r, s, n = this, - a = n.config, - o = u.createElement("div"); - n.id = o.id = c[0] + h, o.setAttribute("class", c[0] + " " + c[0] + (a.type || 0)), o.setAttribute("index", h), s = "object" == typeof a.title, t = a.title ? '

' + (s ? a.title[0] : a.title) + "

" : "", e = function() { - "string" == typeof a.btn && (a.btn = [a.btn]); - var t, e = (a.btn || []).length; - return 0 !== e && a.btn ? (t = '' + a.btn[0] + "", 2 === e && (t = '' + a.btn[1] + "" + t), '
' + t + "
") : "" - }(), a.fixed || (a.top = a.hasOwnProperty("top") ? a.top : 100, a.style = a.style || "", a.style += " top:" + (u.body.scrollTop + a.top) + "px"), 2 === a.type && (a.content = '

' + (a.content || "") + "

"), a.skin && (a.anim = "scale"), "msg" === a.skin && (a.shade = !1), o.innerHTML = (a.shade ? "
' : "") + '
" + t + '
' + a.content + "
" + e + "
", a.type && 2 !== a.type || 1 <= (i = u[p](c[0] + a.type)).length && layer.close(i[0].getAttribute("index")), d().appendChild(o), r = n.elem = l("#" + n.id)[0], a.success && a.success(r), n.index = h++, n.action(a, r) - }, e.prototype.action = function(t, e) { - var i, r, s, n, a, o = this; - if (t.time && (f.timer[o.index] = setTimeout(function() { - layer.close(o.index) - }, 1e3 * t.time)), i = function() { - 0 == this.getAttribute("type") ? (t.no && t.no(), layer.close(o.index)) : t.yes ? t.yes(o.index) : layer.close(o.index) - }, t.btn) - for (s = (r = e[p]("layui-m-layerbtn")[0].children).length, n = 0; n < s; n++) f.touch(r[n], i); - t.shade && t.shadeClose && (a = e[p]("layui-m-layershade")[0], f.touch(a, function() { - layer.close(o.index, t.end) - })), t.end && (f.end[o.index] = t.end) - }, t.layer = { - v: "2.0", - index: h, - open: function(t) { - return new e(t || {}).index - }, - close: function(t) { - var e = l("#" + c[0] + t)[0]; - e && (e.innerHTML = "", d().removeChild(e), clearTimeout(f.timer[t]), delete f.timer[t], "function" == typeof f.end[t] && f.end[t](), delete f.end[t]) - }, - closeAll: function() { - for (var t = u[p](c[0]), e = 0, i = t.length; e < i; e++) layer.close(0 | t[0].getAttribute("index")) - } - }, "function" == typeof define ? define(function() { - return layer - }) : (i = document.scripts, r = i[i.length - 1], (s = r.src).substring(0, s.lastIndexOf("/") + 1), r.getAttribute("merge") || document.head.appendChild(u.createElement("link"))) - }(window), window.Utils = function() {}, Utils.g = function() {}, Utils.g.isLandscape = !1, Utils.request = { - getParameter: function(t) { - var e = window.location.search, - i = new RegExp(t + "=([^&?]*)", "ig"); - return e.match(i) ? e.match(i)[0].substr(t.length + 1) : null - } - }, Utils.msg = function(t) { - var e = layer.open({ - content: t, - skin: "msg", - anim: "scale", - time: 2 - }); - Utils.g.isLandscape && layerLandscape(e) - }, Utils.loading = function(t) { - var e = layer.open({ - type: 2, - shade: "background-color: rgba(0,0,0,0)", - shadeClose: !1, - content: t || "加载中..." - }); - return Utils.g.isLandscape && layerLandscape(e), { - close: function() { - var t; - t = e, layer.close(t) - } - } - }, Utils.confirm = function(t, e, i, r, s) { - var n = layer.open({ - title: t, - content: e, - shadeClose: !1, - btn: [r || "确定", s || "取消"], - yes: function(t) { - i && i(!0), layer.close(t) - }, - no: function() { - i && i(!1) - } - }); - Utils.g.isLandscape && layerLandscape(n) - }, Utils.alert = function(t, e, i, r) { - var s = layer.open({ - title: e, - content: t, - shadeClose: !1, - btn: r || "确定", - yes: function(t) { - i && i(), layer.close(t) - } - }); - Utils.g.isLandscape && layerLandscape(s) - }, Object.prototype.inherit = function() { - for (var t in this) this[t] = this[t] - }, Serializer = { - TAG_INT: 1, - TAG_STRING: 2, - TAG_STRUCT: 3, - TAG_BLOB: 4, - TAG_BOOLEAN: 5, - TYPE: "application/octet-stream", - pointer: function() { - this.index = 0, this.top = 0, this.stack = [] - }, - pack: function(t) { - var e = new DataView(new ArrayBuffer(4)); - return e.setUint32(0, t, !0), e.buffer - }, - pack8: function(t) { - var e = new DataView(new ArrayBuffer(1)); - return e.setUint8(0, t, !0), e.buffer - }, - prefix: function(t) { - return new Blob([Serializer.pack(t.size || t.length || t.byteLength), t], { - type: Serializer.TYPE - }) - }, - serialize: function(t) { - var e = [], - r = 4; - for (i in t) - if (t.hasOwnProperty(i)) { - var s, n, a = Serializer.prefix(i); - switch (typeof t[i]) { - case "number": - s = Serializer.TAG_INT, n = Serializer.pack(t[i]); - break; - case "string": - s = Serializer.TAG_STRING, n = Serializer.prefix(t[i]); - break; - case "object": - t[i].type == Serializer.TYPE ? (s = Serializer.TAG_BLOB, n = t[i]) : (s = Serializer.TAG_STRUCT, n = Serializer.serialize(t[i])); - break; - case "boolean": - s = Serializer.TAG_BOOLEAN, n = Serializer.pack8(t[i]); - break; - default: - console.log(t[i]) - } - r += 1 + a.size + (n.size || n.byteLength || n.length), e.push(Serializer.pack8(s)), e.push(a), e.push(n) - } - return e.unshift(Serializer.pack(r)), new Blob(e) - }, - deserialize: function(t, e) { - var i = new FileReader; - i.onload = function(t) { - e(Serializer.deserealizeStream(new DataView(t.target.result), new Serializer.pointer)) - }, i.readAsArrayBuffer(t) - }, - deserealizeStream: function(t, e) { - e.push(); - for (var i = {}, r = t.getUint32(e.advance(4), !0); e.mark() < r;) { - var s, n = t.getUint8(e.advance(1)), - a = e.readString(t); - switch (n) { - case Serializer.TAG_INT: - s = t.getUint32(e.advance(4), !0); - break; - case Serializer.TAG_STRING: - s = e.readString(t); - break; - case Serializer.TAG_STRUCT: - s = Serializer.deserealizeStream(t, e); - break; - case Serializer.TAG_BLOB: - var o = t.getUint32(e.advance(4), !0); - s = t.buffer.slice(e.advance(o), e.advance(0)); - break; - case Serializer.TAG_BOOLEAN: - s = !!t.getUint8(e.advance(1)) - } - i[a] = s - } - if (e.mark() > r) throw "Size of serialized data exceeded"; - return e.pop(), i - }, - serializePNG: function(t, u, d) { - for (var p = document.createElement("canvas"), l = p.getContext("2d"), f = u.getContext("2d").getImageData(0, 0, u.width, u.height), e = 0, i = 0; i < u.height; ++i) - for (var r = 0; r < u.width; ++r) f.data[4 * (r + i * u.width) + 3] || ++e; - for (var s = 3 * e + (u.width * u.height - e), m = 1; s * m * m < t.size; ++m); - var n = s * m * m - t.size, - y = Math.ceil(n / (u.width * m)); - p.setAttribute("width", u.width * m), p.setAttribute("height", u.height * m + y); - var a = new FileReader; - return a.onload = function(t) { - for (var e = new Uint8Array(t.target.result), i = 0, r = 0, s = l.createImageData(p.width, p.height + y), n = 0; n < p.height; ++n) - for (var a = 0; a < p.width; ++a) { - var o = n / m | 0, - h = a / m | 0; - if (o > u.height || !f.data[4 * (h + o * u.width) + 3]) s.data[r++] = e[i++], s.data[r++] = e[i++], s.data[r++] = e[i++], s.data[r++] = 0; - else { - var c = e[i++]; - s.data[r++] = f.data[4 * (h + o * u.width) + 0] | 7 & c, s.data[r++] = f.data[4 * (h + o * u.width) + 1] | c >> 3 & 7, s.data[r++] = f.data[4 * (h + o * u.width) + 2] | c >> 6 & 7, s.data[r++] = f.data[4 * (h + o * u.width) + 3] - } - } - l.putImageData(s, 0, 0), d(p.toDataURL("image/png")) - }, a.readAsArrayBuffer(t), p - }, - deserializePNG: function(t, h) { - var e = new FileReader; - e.onload = function(t) { - var e = document.createElement("img"); - e.setAttribute("src", t.target.result); - var i = document.createElement("canvas"); - i.setAttribute("height", e.height), i.setAttribute("width", e.width); - var r = i.getContext("2d"); - r.drawImage(e, 0, 0); - for (var s = r.getImageData(0, 0, i.width, i.height), n = (t = [], 0); n < i.height; ++n) - for (var a = 0; a < i.width; ++a) - if (s.data[4 * (a + n * i.width) + 3]) { - var o = 0; - o |= 7 & s.data[4 * (a + n * i.width) + 0], o |= (7 & s.data[4 * (a + n * i.width) + 1]) << 3, o |= (7 & s.data[4 * (a + n * i.width) + 2]) << 6, t.push(o) - } else t.push(s.data[4 * (a + n * i.width) + 0]), t.push(s.data[4 * (a + n * i.width) + 1]), t.push(s.data[4 * (a + n * i.width) + 2]); - newBlob = new Blob(t.map(function(t) { - var e = new Uint8Array(1); - return e[0] = t, e - }), { - type: Serializer.TYPE - }), Serializer.deserialize(newBlob, h) - }, e.readAsDataURL(t) - } - }, Serializer.pointer.prototype.advance = function(t) { - var e = this.index; - return this.index += t, e - }, Serializer.pointer.prototype.mark = function() { - return this.index - this.top - }, Serializer.pointer.prototype.push = function() { - this.stack.push(this.top), this.top = this.index - }, Serializer.pointer.prototype.pop = function() { - this.top = this.stack.pop() - }, Serializer.pointer.prototype.readString = function(t) { - for (var e = t.getUint32(this.advance(4), !0), i = [], r = 0; r < e; ++r) i.push(String.fromCharCode(t.getUint8(this.advance(1)))); - return i.join("") - }, ARMCore.prototype.resetCPU = function(t) { - for (var e = 0; e < this.PC; ++e) this.gprs[e] = 0; - this.gprs[this.PC] = t + this.WORD_SIZE_ARM, this.loadInstruction = this.loadInstructionArm, this.execMode = this.MODE_ARM, this.instructionWidth = this.WORD_SIZE_ARM, this.mode = this.MODE_SYSTEM, this.cpsrI = !1, this.cpsrF = !1, this.cpsrV = !1, this.cpsrC = !1, this.cpsrZ = !1, this.cpsrN = !1, this.bankedRegisters = [new Int32Array(7), new Int32Array(7), new Int32Array(2), new Int32Array(2), new Int32Array(2), new Int32Array(2)], this.spsr = 0, this.bankedSPSRs = new Int32Array(6), this.cycles = 0, this.shifterOperand = 0, this.shifterCarryOut = 0, this.page = null, this.pageId = 0, this.pageRegion = -1, this.instruction = null, this.irq.clear(); - var i = this.gprs, - r = this.mmu; - this.step = function() { - var t = this.instruction || (this.instruction = this.loadInstruction(i[this.PC] - this.instructionWidth)); - if (i[this.PC] += this.instructionWidth, this.conditionPassed = !0, t(), t.writesPC) - if (this.conditionPassed) { - var e = i[this.PC] &= 4294967294; - this.execMode == this.MODE_ARM ? (r.wait32(e), r.waitPrefetch32(e)) : (r.wait(e), r.waitPrefetch(e)), i[this.PC] += this.instructionWidth, t.fixedJump ? null != this.instruction && ((null == t.next || t.next.page.invalid) && (t.next = this.loadInstruction(i[this.PC] - this.instructionWidth)), this.instruction = t.next) : this.instruction = null - } else this.instruction = null; - else null != this.instruction && ((null == t.next || t.next.page.invalid) && (t.next = this.loadInstruction(i[this.PC] - this.instructionWidth)), this.instruction = t.next); - this.irq.updateTimers() - } - }, ARMCore.prototype.freeze = function() { - return { - gprs: [this.gprs[0], this.gprs[1], this.gprs[2], this.gprs[3], this.gprs[4], this.gprs[5], this.gprs[6], this.gprs[7], this.gprs[8], this.gprs[9], this.gprs[10], this.gprs[11], this.gprs[12], this.gprs[13], this.gprs[14], this.gprs[15]], - mode: this.mode, - cpsrI: this.cpsrI, - cpsrF: this.cpsrF, - cpsrV: this.cpsrV, - cpsrC: this.cpsrC, - cpsrZ: this.cpsrZ, - cpsrN: this.cpsrN, - bankedRegisters: [ - [this.bankedRegisters[0][0], this.bankedRegisters[0][1], this.bankedRegisters[0][2], this.bankedRegisters[0][3], this.bankedRegisters[0][4], this.bankedRegisters[0][5], this.bankedRegisters[0][6]], - [this.bankedRegisters[1][0], this.bankedRegisters[1][1], this.bankedRegisters[1][2], this.bankedRegisters[1][3], this.bankedRegisters[1][4], this.bankedRegisters[1][5], this.bankedRegisters[1][6]], - [this.bankedRegisters[2][0], this.bankedRegisters[2][1]], - [this.bankedRegisters[3][0], this.bankedRegisters[3][1]], - [this.bankedRegisters[4][0], this.bankedRegisters[4][1]], - [this.bankedRegisters[5][0], this.bankedRegisters[5][1]] - ], - spsr: this.spsr, - bankedSPSRs: [this.bankedSPSRs[0], this.bankedSPSRs[1], this.bankedSPSRs[2], this.bankedSPSRs[3], this.bankedSPSRs[4], this.bankedSPSRs[5]], - cycles: this.cycles - } - }, ARMCore.prototype.defrost = function(t) { - this.instruction = null, this.page = null, this.pageId = 0, this.pageRegion = -1, this.gprs[0] = t.gprs[0], this.gprs[1] = t.gprs[1], this.gprs[2] = t.gprs[2], this.gprs[3] = t.gprs[3], this.gprs[4] = t.gprs[4], this.gprs[5] = t.gprs[5], this.gprs[6] = t.gprs[6], this.gprs[7] = t.gprs[7], this.gprs[8] = t.gprs[8], this.gprs[9] = t.gprs[9], this.gprs[10] = t.gprs[10], this.gprs[11] = t.gprs[11], this.gprs[12] = t.gprs[12], this.gprs[13] = t.gprs[13], this.gprs[14] = t.gprs[14], this.gprs[15] = t.gprs[15], this.mode = t.mode, this.cpsrI = t.cpsrI, this.cpsrF = t.cpsrF, this.cpsrV = t.cpsrV, this.cpsrC = t.cpsrC, this.cpsrZ = t.cpsrZ, this.cpsrN = t.cpsrN, this.bankedRegisters[0][0] = t.bankedRegisters[0][0], this.bankedRegisters[0][1] = t.bankedRegisters[0][1], this.bankedRegisters[0][2] = t.bankedRegisters[0][2], this.bankedRegisters[0][3] = t.bankedRegisters[0][3], this.bankedRegisters[0][4] = t.bankedRegisters[0][4], this.bankedRegisters[0][5] = t.bankedRegisters[0][5], this.bankedRegisters[0][6] = t.bankedRegisters[0][6], this.bankedRegisters[1][0] = t.bankedRegisters[1][0], this.bankedRegisters[1][1] = t.bankedRegisters[1][1], this.bankedRegisters[1][2] = t.bankedRegisters[1][2], this.bankedRegisters[1][3] = t.bankedRegisters[1][3], this.bankedRegisters[1][4] = t.bankedRegisters[1][4], this.bankedRegisters[1][5] = t.bankedRegisters[1][5], this.bankedRegisters[1][6] = t.bankedRegisters[1][6], this.bankedRegisters[2][0] = t.bankedRegisters[2][0], this.bankedRegisters[2][1] = t.bankedRegisters[2][1], this.bankedRegisters[3][0] = t.bankedRegisters[3][0], this.bankedRegisters[3][1] = t.bankedRegisters[3][1], this.bankedRegisters[4][0] = t.bankedRegisters[4][0], this.bankedRegisters[4][1] = t.bankedRegisters[4][1], this.bankedRegisters[5][0] = t.bankedRegisters[5][0], this.bankedRegisters[5][1] = t.bankedRegisters[5][1], this.spsr = t.spsr, this.bankedSPSRs[0] = t.bankedSPSRs[0], this.bankedSPSRs[1] = t.bankedSPSRs[1], this.bankedSPSRs[2] = t.bankedSPSRs[2], this.bankedSPSRs[3] = t.bankedSPSRs[3], this.bankedSPSRs[4] = t.bankedSPSRs[4], this.bankedSPSRs[5] = t.bankedSPSRs[5], this.cycles = t.cycles - }, ARMCore.prototype.fetchPage = function(t) { - var e = t >> this.mmu.BASE_OFFSET, - i = this.mmu.addressToPage(e, t & this.mmu.OFFSET_MASK); - if (e == this.pageRegion) { - if (i == this.pageId && !this.page.invalid) return; - this.pageId = i - } else this.pageMask = this.mmu.memory[e].PAGE_MASK, this.pageRegion = e, this.pageId = i; - this.page = this.mmu.accessPage(e, i) - }, ARMCore.prototype.loadInstructionArm = function(t) { - var e = null; - this.fetchPage(t); - var i = (t & this.pageMask) >> 2; - if (e = this.page.arm[i]) return e; - var r = this.mmu.load32(t) >>> 0; - return (e = this.compileArm(r)).next = null, e.page = this.page, e.address = t, e.opcode = r, this.page.arm[i] = e - }, ARMCore.prototype.loadInstructionThumb = function(t) { - var e = null; - this.fetchPage(t); - var i = (t & this.pageMask) >> 1; - if (e = this.page.thumb[i]) return e; - var r = this.mmu.load16(t); - return (e = this.compileThumb(r)).next = null, e.page = this.page, e.address = t, e.opcode = r, this.page.thumb[i] = e - }, ARMCore.prototype.selectBank = function(t) { - switch (t) { - case this.MODE_USER: - case this.MODE_SYSTEM: - return this.BANK_NONE; - case this.MODE_FIQ: - return this.BANK_FIQ; - case this.MODE_IRQ: - return this.BANK_IRQ; - case this.MODE_SUPERVISOR: - return this.BANK_SUPERVISOR; - case this.MODE_ABORT: - return this.BANK_ABORT; - case this.MODE_UNDEFINED: - return this.BANK_UNDEFINED; - default: - throw "Invalid user mode passed to selectBank" - } - }, ARMCore.prototype.switchExecMode = function(t) { - this.execMode != t && ((this.execMode = t) == this.MODE_ARM ? (this.instructionWidth = this.WORD_SIZE_ARM, this.loadInstruction = this.loadInstructionArm) : (this.instructionWidth = this.WORD_SIZE_THUMB, this.loadInstruction = this.loadInstructionThumb)) - }, ARMCore.prototype.switchMode = function(t) { - if (t != this.mode) { - if (t != this.MODE_USER || t != this.MODE_SYSTEM) { - var e = this.selectBank(t), - i = this.selectBank(this.mode); - if (e != i) { - if (t == this.MODE_FIQ || this.mode == this.MODE_FIQ) { - var r = (i == this.BANK_FIQ) + 0, - s = (e == this.BANK_FIQ) + 0; - this.bankedRegisters[r][2] = this.gprs[8], this.bankedRegisters[r][3] = this.gprs[9], this.bankedRegisters[r][4] = this.gprs[10], this.bankedRegisters[r][5] = this.gprs[11], this.bankedRegisters[r][6] = this.gprs[12], this.gprs[8] = this.bankedRegisters[s][2], this.gprs[9] = this.bankedRegisters[s][3], this.gprs[10] = this.bankedRegisters[s][4], this.gprs[11] = this.bankedRegisters[s][5], this.gprs[12] = this.bankedRegisters[s][6] - } - this.bankedRegisters[i][0] = this.gprs[this.SP], this.bankedRegisters[i][1] = this.gprs[this.LR], this.gprs[this.SP] = this.bankedRegisters[e][0], this.gprs[this.LR] = this.bankedRegisters[e][1], this.bankedSPSRs[i] = this.spsr, this.spsr = this.bankedSPSRs[e] - } - } - this.mode = t - } - }, ARMCore.prototype.packCPSR = function() { - return this.mode | !!this.execMode << 5 | !!this.cpsrF << 6 | !!this.cpsrI << 7 | !!this.cpsrN << 31 | !!this.cpsrZ << 30 | !!this.cpsrC << 29 | !!this.cpsrV << 28 - }, ARMCore.prototype.unpackCPSR = function(t) { - this.switchMode(31 & t), this.switchExecMode(!!(32 & t)), this.cpsrF = 64 & t, this.cpsrI = 128 & t, this.cpsrN = 2147483648 & t, this.cpsrZ = 1073741824 & t, this.cpsrC = 536870912 & t, this.cpsrV = 268435456 & t, this.irq.testIRQ() - }, ARMCore.prototype.hasSPSR = function() { - return this.mode != this.MODE_SYSTEM && this.mode != this.MODE_USER - }, ARMCore.prototype.raiseIRQ = function() { - if (!this.cpsrI) { - var t = this.packCPSR(), - e = this.instructionWidth; - this.switchMode(this.MODE_IRQ), this.spsr = t, this.gprs[this.LR] = this.gprs[this.PC] - e + 4, this.gprs[this.PC] = this.BASE_IRQ + this.WORD_SIZE_ARM, this.instruction = null, this.switchExecMode(this.MODE_ARM), this.cpsrI = !0 - } - }, ARMCore.prototype.raiseTrap = function() { - var t = this.packCPSR(), - e = this.instructionWidth; - this.switchMode(this.MODE_SUPERVISOR), this.spsr = t, this.gprs[this.LR] = this.gprs[this.PC] - e, this.gprs[this.PC] = this.BASE_SWI + this.WORD_SIZE_ARM, this.instruction = null, this.switchExecMode(this.MODE_ARM), this.cpsrI = !0 - }, ARMCore.prototype.badOp = function(t) { - var e = function() { - throw "Illegal instruction: 0x" + t.toString(16) - }; - return e.writesPC = !0, e.fixedJump = !1, e - }, ARMCore.prototype.generateConds = function() { - var t = this; - this.conds = [ - function() { - return t.conditionPassed = t.cpsrZ - }, - function() { - return t.conditionPassed = !t.cpsrZ - }, - function() { - return t.conditionPassed = t.cpsrC - }, - function() { - return t.conditionPassed = !t.cpsrC - }, - function() { - return t.conditionPassed = t.cpsrN - }, - function() { - return t.conditionPassed = !t.cpsrN - }, - function() { - return t.conditionPassed = t.cpsrV - }, - function() { - return t.conditionPassed = !t.cpsrV - }, - function() { - return t.conditionPassed = t.cpsrC && !t.cpsrZ - }, - function() { - return t.conditionPassed = !t.cpsrC || t.cpsrZ - }, - function() { - return t.conditionPassed = !t.cpsrN == !t.cpsrV - }, - function() { - return t.conditionPassed = !t.cpsrN != !t.cpsrV - }, - function() { - return t.conditionPassed = !t.cpsrZ && !t.cpsrN == !t.cpsrV - }, - function() { - return t.conditionPassed = t.cpsrZ || !t.cpsrN != !t.cpsrV - }, - null, null - ] - }, ARMCore.prototype.barrelShiftImmediate = function(t, e, i) { - var r = this, - s = this.gprs, - n = this.badOp; - switch (t) { - case 0: - n = e ? function() { - r.shifterOperand = s[i] << e, r.shifterCarryOut = s[i] & 1 << 32 - e - } : function() { - r.shifterOperand = s[i], r.shifterCarryOut = r.cpsrC - }; - break; - case 32: - n = e ? function() { - r.shifterOperand = s[i] >>> e, r.shifterCarryOut = s[i] & 1 << e - 1 - } : function() { - r.shifterOperand = 0, r.shifterCarryOut = 2147483648 & s[i] - }; - break; - case 64: - n = e ? function() { - r.shifterOperand = s[i] >> e, r.shifterCarryOut = s[i] & 1 << e - 1 - } : function() { - r.shifterCarryOut = 2147483648 & s[i], r.shifterCarryOut ? r.shifterOperand = 4294967295 : r.shifterOperand = 0 - }; - break; - case 96: - n = e ? function() { - r.shifterOperand = s[i] >>> e | s[i] << 32 - e, r.shifterCarryOut = s[i] & 1 << e - 1 - } : function() { - r.shifterOperand = !!r.cpsrC << 31 | s[i] >>> 1, r.shifterCarryOut = 1 & s[i] - } - } - return n - }, ARMCore.prototype.compileArm = function(t) { - var e = this.badOp(t), - i = 234881024 & t, - r = (this.gprs, this.conds[(4026531840 & t) >>> 28]); - if (19922704 == (268435440 & t)) { - var s = 15 & t; - (e = this.armCompiler.constructBX(s, r)).writesPC = !0, e.fixedJump = !1 - } else if (201326592 & t || 33554432 != i && 144 == (144 & t)) - if (16777360 == (263196656 & t)) { - s = 15 & t, g = t >> 12 & 15, b = t >> 16 & 15; - (e = 4194304 & t ? this.armCompiler.constructSWPB(g, b, s, r) : this.armCompiler.constructSWP(g, b, s, r)).writesPC = g == this.PC - } else switch (i) { - case 0: - if (144 == (16777456 & t)) { - g = (983040 & t) >> 16, b = (61440 & t) >> 12, M = (3840 & t) >> 8, s = 15 & t; - switch (15728640 & t) { - case 0: - e = this.armCompiler.constructMUL(g, M, s, r); - break; - case 1048576: - e = this.armCompiler.constructMULS(g, M, s, r); - break; - case 2097152: - e = this.armCompiler.constructMLA(g, b, M, s, r); - break; - case 3145728: - e = this.armCompiler.constructMLAS(g, b, M, s, r); - break; - case 8388608: - e = this.armCompiler.constructUMULL(g, b, M, s, r); - break; - case 9437184: - e = this.armCompiler.constructUMULLS(g, b, M, s, r); - break; - case 10485760: - e = this.armCompiler.constructUMLAL(g, b, M, s, r); - break; - case 11534336: - e = this.armCompiler.constructUMLALS(g, b, M, s, r); - break; - case 12582912: - e = this.armCompiler.constructSMULL(g, b, M, s, r); - break; - case 13631488: - e = this.armCompiler.constructSMULLS(g, b, M, s, r); - break; - case 14680064: - e = this.armCompiler.constructSMLAL(g, b, M, s, r); - break; - case 15728640: - e = this.armCompiler.constructSMLALS(g, b, M, s, r) - } - e.writesPC = g == this.PC - } else { - var n = 1048576 & t, - a = (g = (61440 & t) >> 12, s = 15 & t), - o = 32 & t, - h = (A = 64 & t, 2097152 & t); - if (i = 4194304 & t) { - C = a | (3840 & t) >> 4; - u = this.armCompiler.constructAddressingMode23Immediate(t, C, r) - } else u = this.armCompiler.constructAddressingMode23Register(t, s, r); - u.writesPC = !!h && b == this.PC, 144 == (144 & t) && (n ? o ? e = A ? this.armCompiler.constructLDRSH(g, u, r) : this.armCompiler.constructLDRH(g, u, r) : A && (e = this.armCompiler.constructLDRSB(g, u, r)) : !A && o && (e = this.armCompiler.constructSTRH(g, u, r))), e.writesPC = g == this.PC || u.writesPC - } - break; - case 67108864: - case 100663296: - g = (61440 & t) >> 12, n = 1048576 & t; - var c = 4194304 & t, - u = (i = 33554432 & t, function() { - throw "Unimplemented memory access: 0x" + t.toString(16) - }); - if (16777216 & ~t && (t &= 4292870143), i) { - s = 15 & t; - var d = (3968 & t) >> 7; - if ((S = 96 & t) || d) { - R = this.barrelShiftImmediate(S, d, s); - u = this.armCompiler.constructAddressingMode2RegisterShifted(t, R, r) - } else u = this.armCompiler.constructAddressingMode23Register(t, s, r) - } else { - var p = 4095 & t; - u = this.armCompiler.constructAddressingMode23Immediate(t, p, r) - }(e = n ? c ? this.armCompiler.constructLDRB(g, u, r) : this.armCompiler.constructLDR(g, u, r) : c ? this.armCompiler.constructSTRB(g, u, r) : this.armCompiler.constructSTR(g, u, r)).writesPC = g == this.PC || u.writesPC; - break; - case 134217728: - n = 1048576 & t, h = 2097152 & t; - var l = 4194304 & t, - f = 16777216 & t, - m = (M = 65535 & t, b = (983040 & t) >> 16, C = 0, p = 0, !1); - if (8388608 & t) { - f && (C = 4); - var y = 1; - for (i = 0; i < 16; y <<= 1, ++i) M & y && (h && i == b && !p && (M &= ~y, C += 4, m = !0), p += 4) - } else { - f || (C = 4); - for (y = 1, i = 0; i < 16; y <<= 1, ++i) M & y && (h && i == b && !p && (M &= ~y, C += 4, m = !0), C -= 4, p -= 4) - } - u = h ? this.armCompiler.constructAddressingMode4Writeback(C, p, b, m) : this.armCompiler.constructAddressingMode4(C, b), n ? (e = l ? this.armCompiler.constructLDMS(M, u, r) : this.armCompiler.constructLDM(M, u, r)).writesPC = !!(32768 & M) : (e = l ? this.armCompiler.constructSTMS(M, u, r) : this.armCompiler.constructSTM(M, u, r)).writesPC = !1; - break; - case 167772160: - 8388608 & (C = 16777215 & t) && (C |= 4278190080), C <<= 2, (e = 16777216 & t ? this.armCompiler.constructBL(C, r) : this.armCompiler.constructB(C, r)).writesPC = !0, e.fixedJump = !0; - break; - case 201326592: - break; - case 234881024: - if (251658240 == (251658240 & t)) { - C = 16777215 & t; - (e = this.armCompiler.constructSWI(C, r)).writesPC = !1 - } - break; - default: - throw "Bad opcode: 0x" + t.toString(16) - } else { - var v = 31457280 & t, - A = 1048576 & t; - if (16777216 != (25165824 & v) || A) { - var b = (983040 & t) >> 16, - g = (61440 & t) >> 12, - S = 96 & t, - s = 15 & t, - R = function() { - throw "BUG: invalid barrel shifter" - }; - if (33554432 & t) { - var C = 255 & t, - w = (3840 & t) >> 7; - R = w ? this.armCompiler.constructAddressingMode1ImmediateRotate(C, w) : this.armCompiler.constructAddressingMode1Immediate(C) - } else if (16 & t) { - var M = (3840 & t) >> 8; - switch (!0, S) { - case 0: - R = this.armCompiler.constructAddressingMode1LSL(M, s); - break; - case 32: - R = this.armCompiler.constructAddressingMode1LSR(M, s); - break; - case 64: - R = this.armCompiler.constructAddressingMode1ASR(M, s); - break; - case 96: - R = this.armCompiler.constructAddressingMode1ROR(M, s) - } - } else { - var C = (3968 & t) >> 7; - R = this.barrelShiftImmediate(S, C, s) - } - switch (v) { - case 0: - e = A ? this.armCompiler.constructANDS(g, b, R, r) : this.armCompiler.constructAND(g, b, R, r); - break; - case 2097152: - e = A ? this.armCompiler.constructEORS(g, b, R, r) : this.armCompiler.constructEOR(g, b, R, r); - break; - case 4194304: - e = A ? this.armCompiler.constructSUBS(g, b, R, r) : this.armCompiler.constructSUB(g, b, R, r); - break; - case 6291456: - e = A ? this.armCompiler.constructRSBS(g, b, R, r) : this.armCompiler.constructRSB(g, b, R, r); - break; - case 8388608: - e = A ? this.armCompiler.constructADDS(g, b, R, r) : this.armCompiler.constructADD(g, b, R, r); - break; - case 10485760: - e = A ? this.armCompiler.constructADCS(g, b, R, r) : this.armCompiler.constructADC(g, b, R, r); - break; - case 12582912: - e = A ? this.armCompiler.constructSBCS(g, b, R, r) : this.armCompiler.constructSBC(g, b, R, r); - break; - case 14680064: - e = A ? this.armCompiler.constructRSCS(g, b, R, r) : this.armCompiler.constructRSC(g, b, R, r); - break; - case 16777216: - e = this.armCompiler.constructTST(g, b, R, r); - break; - case 18874368: - e = this.armCompiler.constructTEQ(g, b, R, r); - break; - case 20971520: - e = this.armCompiler.constructCMP(g, b, R, r); - break; - case 23068672: - e = this.armCompiler.constructCMN(g, b, R, r); - break; - case 25165824: - e = A ? this.armCompiler.constructORRS(g, b, R, r) : this.armCompiler.constructORR(g, b, R, r); - break; - case 27262976: - e = A ? this.armCompiler.constructMOVS(g, b, R, r) : this.armCompiler.constructMOV(g, b, R, r); - break; - case 29360128: - e = A ? this.armCompiler.constructBICS(g, b, R, r) : this.armCompiler.constructBIC(g, b, R, r); - break; - case 31457280: - e = A ? this.armCompiler.constructMVNS(g, b, R, r) : this.armCompiler.constructMVN(g, b, R, r) - } - e.writesPC = g == this.PC - } else { - var _ = 4194304 & t; - if (2158592 == (11595776 & t)) { - var s = 15 & t, - I = (3840 & t) >> 7; - C = (C = 255 & t) >>> I | C << 32 - I, (e = this.armCompiler.constructMSR(s, _, t, C, r)).writesPC = !1 - } else if (983040 == (12517376 & t)) { - var g = (61440 & t) >> 12; - (e = this.armCompiler.constructMRS(g, _, r)).writesPC = g == this.PC - } - } - } - return e.execMode = this.MODE_ARM, e.fixedJump = e.fixedJump || !1, e - }, ARMCore.prototype.compileThumb = function(t) { - var e = this.badOp(65535 & t); - this.gprs; - if (16384 == (64512 & t)) { - var i = (56 & t) >> 3, - r = 7 & t; - switch (960 & t) { - case 0: - e = this.thumbCompiler.constructAND(r, i); - break; - case 64: - e = this.thumbCompiler.constructEOR(r, i); - break; - case 128: - e = this.thumbCompiler.constructLSL2(r, i); - break; - case 192: - e = this.thumbCompiler.constructLSR2(r, i); - break; - case 256: - e = this.thumbCompiler.constructASR2(r, i); - break; - case 320: - e = this.thumbCompiler.constructADC(r, i); - break; - case 384: - e = this.thumbCompiler.constructSBC(r, i); - break; - case 448: - e = this.thumbCompiler.constructROR(r, i); - break; - case 512: - e = this.thumbCompiler.constructTST(r, i); - break; - case 576: - e = this.thumbCompiler.constructNEG(r, i); - break; - case 640: - e = this.thumbCompiler.constructCMP2(r, i); - break; - case 704: - e = this.thumbCompiler.constructCMN(r, i); - break; - case 768: - e = this.thumbCompiler.constructORR(r, i); - break; - case 832: - e = this.thumbCompiler.constructMUL(r, i); - break; - case 896: - e = this.thumbCompiler.constructBIC(r, i); - break; - case 960: - e = this.thumbCompiler.constructMVN(r, i) - } - e.writesPC = !1 - } else if (17408 == (64512 & t)) { - i = (120 & t) >> 3, r = (s = 7 & t) | (128 & t) >> 4; - switch (768 & t) { - case 0: - (e = this.thumbCompiler.constructADD4(r, i)).writesPC = r == this.PC; - break; - case 256: - (e = this.thumbCompiler.constructCMP3(r, i)).writesPC = !1; - break; - case 512: - (e = this.thumbCompiler.constructMOV3(r, i)).writesPC = r == this.PC; - break; - case 768: - (e = this.thumbCompiler.constructBX(r, i)).writesPC = !0, e.fixedJump = !1 - } - } else if (6144 == (63488 & t)) { - i = (448 & t) >> 6; - var s = (56 & t) >> 3; - r = 7 & t; - switch (1536 & t) { - case 0: - e = this.thumbCompiler.constructADD3(r, s, i); - break; - case 512: - e = this.thumbCompiler.constructSUB3(r, s, i); - break; - case 1024: - e = (n = (448 & t) >> 6) ? this.thumbCompiler.constructADD1(r, s, n) : this.thumbCompiler.constructMOV2(r, s, i); - break; - case 1536: - var n = (448 & t) >> 6; - e = this.thumbCompiler.constructSUB1(r, s, n) - } - e.writesPC = !1 - } else if (57344 & t) - if (8192 == (57344 & t)) { - n = 255 & t, s = (1792 & t) >> 8; - switch (6144 & t) { - case 0: - e = this.thumbCompiler.constructMOV1(s, n); - break; - case 2048: - e = this.thumbCompiler.constructCMP1(s, n); - break; - case 4096: - e = this.thumbCompiler.constructADD2(s, n); - break; - case 6144: - e = this.thumbCompiler.constructSUB2(s, n) - } - e.writesPC = !1 - } else if (18432 == (63488 & t)) { - r = (1792 & t) >> 8, n = (255 & t) << 2; - (e = this.thumbCompiler.constructLDR3(r, n)).writesPC = !1 - } else if (20480 == (61440 & t)) { - r = 7 & t, s = (56 & t) >> 3, i = (448 & t) >> 6; - switch (3584 & t) { - case 0: - e = this.thumbCompiler.constructSTR2(r, s, i); - break; - case 512: - e = this.thumbCompiler.constructSTRH2(r, s, i); - break; - case 1024: - e = this.thumbCompiler.constructSTRB2(r, s, i); - break; - case 1536: - e = this.thumbCompiler.constructLDRSB(r, s, i); - break; - case 2048: - e = this.thumbCompiler.constructLDR2(r, s, i); - break; - case 2560: - e = this.thumbCompiler.constructLDRH2(r, s, i); - break; - case 3072: - e = this.thumbCompiler.constructLDRB2(r, s, i); - break; - case 3584: - e = this.thumbCompiler.constructLDRSH(r, s, i) - } - e.writesPC = !1 - } else if (24576 == (57344 & t)) { - r = 7 & t, s = (56 & t) >> 3, n = (1984 & t) >> 4; - (h = 4096 & t) && (n >>= 2), (e = 2048 & t ? h ? this.thumbCompiler.constructLDRB1(r, s, n) : this.thumbCompiler.constructLDR1(r, s, n) : h ? this.thumbCompiler.constructSTRB1(r, s, n) : this.thumbCompiler.constructSTR1(r, s, n)).writesPC = !1 - } else if (46080 == (62976 & t)) { - var a = !!(256 & t), - o = 255 & t; - 2048 & t ? ((e = this.thumbCompiler.constructPOP(o, a)).writesPC = a, e.fixedJump = !1) : (e = this.thumbCompiler.constructPUSH(o, a)).writesPC = !1 - } else { - if (!(32768 & t)) throw "Bad opcode: 0x" + t.toString(16); - switch (28672 & t) { - case 0: - r = 7 & t, s = (56 & t) >> 3, n = (1984 & t) >> 5; - (e = 2048 & t ? this.thumbCompiler.constructLDRH1(r, s, n) : this.thumbCompiler.constructSTRH1(r, s, n)).writesPC = !1; - break; - case 4096: - r = (1792 & t) >> 8, n = (255 & t) << 2; - (e = 2048 & t ? this.thumbCompiler.constructLDR4(r, n) : this.thumbCompiler.constructSTR3(r, n)).writesPC = !1; - break; - case 8192: - r = (1792 & t) >> 8, n = (255 & t) << 2; - (e = 2048 & t ? this.thumbCompiler.constructADD6(r, n) : this.thumbCompiler.constructADD5(r, n)).writesPC = !1; - break; - case 12288: - if (!(3840 & t)) { - var h; - n = (127 & t) << 2; - (h = 128 & t) && (n = -n), (e = this.thumbCompiler.constructADD7(n)).writesPC = !1 - } - break; - case 16384: - s = (1792 & t) >> 8, o = 255 & t; - (e = 2048 & t ? this.thumbCompiler.constructLDMIA(s, o) : this.thumbCompiler.constructSTMIA(s, o)).writesPC = !1; - break; - case 20480: - var c = (3840 & t) >> 8; - n = 255 & t; - if (15 == c)(e = this.thumbCompiler.constructSWI(n)).writesPC = !1; - else { - 128 & t && (n |= 4294967040), n <<= 1; - var u = this.conds[c]; - (e = this.thumbCompiler.constructB1(n, u)).writesPC = !0, e.fixedJump = !0 - } - break; - case 24576: - case 28672: - n = 2047 & t; - switch (6144 & t) { - case 0: - 1024 & n && (n |= 4294965248), n <<= 1, (e = this.thumbCompiler.constructB2(n)).writesPC = !0, e.fixedJump = !0; - break; - case 2048: - break; - case 4096: - 1024 & n && (n |= 4294966272), n <<= 12, (e = this.thumbCompiler.constructBL1(n)).writesPC = !1; - break; - case 6144: - (e = this.thumbCompiler.constructBL2(n)).writesPC = !0, e.fixedJump = !1 - } - break; - default: - this.WARN("Undefined instruction: 0x" + t.toString(16)) - } - } else { - var r = 7 & t, - i = (56 & t) >> 3, - n = (1984 & t) >> 6; - switch (6144 & t) { - case 0: - e = this.thumbCompiler.constructLSL1(r, i, n); - break; - case 2048: - e = this.thumbCompiler.constructLSR1(r, i, n); - break; - case 4096: - e = this.thumbCompiler.constructASR1(r, i, n) - } - e.writesPC = !1 - } - return e.execMode = this.MODE_THUMB, e.fixedJump = e.fixedJump || !1, e - }; -var ARMCoreArm = function(n) { - this.cpu = n, this.addressingMode23Immediate = [ - function(e, i, r) { - var s = n.gprs, - t = function() { - var t = s[e]; - return r && !r() || (s[e] -= i), t - }; - return t.writesPC = e == n.PC, t - }, - null, null, null, - function(e, i, r) { - var s = n.gprs, - t = function() { - var t = s[e]; - return r && !r() || (s[e] += i), t - }; - return t.writesPC = e == n.PC, t - }, - null, null, null, - function(t, e, i) { - var r = n.gprs, - s = function() { - return addr = r[t] - e - }; - return s.writesPC = !1, s - }, - function(e, i, r) { - var s = n.gprs, - t = function() { - var t = s[e] - i; - return r && !r() || (s[e] = t), t - }; - return t.writesPC = e == n.PC, t - }, - null, null, - function(t, e, i) { - var r = n.gprs, - s = function() { - return addr = r[t] + e - }; - return s.writesPC = !1, s - }, - function(e, i, r) { - var s = n.gprs, - t = function() { - var t = s[e] + i; - return r && !r() || (s[e] = t), t - }; - return t.writesPC = e == n.PC, t - }, - null, null - ], this.addressingMode23Register = [ - function(e, i, r) { - var s = n.gprs, - t = function() { - var t = s[e]; - return r && !r() || (s[e] -= s[i]), t - }; - return t.writesPC = e == n.PC, t - }, - null, null, null, - function(e, i, r) { - var s = n.gprs, - t = function() { - var t = s[e]; - return r && !r() || (s[e] += s[i]), t - }; - return t.writesPC = e == n.PC, t - }, - null, null, null, - function(t, e, i) { - var r = n.gprs, - s = function() { - return r[t] - r[e] - }; - return s.writesPC = !1, s - }, - function(e, i, r) { - var s = n.gprs, - t = function() { - var t = s[e] - s[i]; - return r && !r() || (s[e] = t), t - }; - return t.writesPC = e == n.PC, t - }, - null, null, - function(t, e, i) { - var r = n.gprs, - s = function() { - return r[t] + r[e] - }; - return s.writesPC = !1, s - }, - function(e, i, r) { - var s = n.gprs, - t = function() { - var t = s[e] + s[i]; - return r && !r() || (s[e] = t), t - }; - return t.writesPC = e == n.PC, t - }, - null, null - ], this.addressingMode2RegisterShifted = [ - function(e, i, r) { - var s = n.gprs, - t = function() { - var t = s[e]; - return r && !r() || (i(), s[e] -= n.shifterOperand), t - }; - return t.writesPC = e == n.PC, t - }, - null, null, null, - function(e, i, r) { - var s = n.gprs, - t = function() { - var t = s[e]; - return r && !r() || (i(), s[e] += n.shifterOperand), t - }; - return t.writesPC = e == n.PC, t - }, - null, null, null, - function(t, e, i) { - var r = n.gprs, - s = function() { - return e(), r[t] - n.shifterOperand - }; - return s.writesPC = !1, s - }, - function(e, i, r) { - var s = n.gprs, - t = function() { - i(); - var t = s[e] - n.shifterOperand; - return r && !r() || (s[e] = t), t - }; - return t.writesPC = e == n.PC, t - }, - null, null, - function(t, e, i) { - var r = n.gprs, - s = function() { - return e(), r[t] + n.shifterOperand - }; - return s.writesPC = !1, s - }, - function(e, i, r) { - var s = n.gprs, - t = function() { - i(); - var t = s[e] + n.shifterOperand; - return r && !r() || (s[e] = t), t - }; - return t.writePC = e == n.PC, t - }, - null, null - ] -}; - -function MemoryView(t, e) { - this.inherit(), this.buffer = t, this.view = new DataView(this.buffer, "number" == typeof e ? e : 0), this.mask = t.byteLength - 1, this.resetMask() -} - -function MemoryBlock(t, e) { - MemoryView.call(this, new ArrayBuffer(t)), this.ICACHE_PAGE_BITS = e, this.PAGE_MASK = (2 << this.ICACHE_PAGE_BITS) - 1, this.icache = new Array(t >> this.ICACHE_PAGE_BITS + 1) -} - -function ROMView(t, e) { - MemoryView.call(this, t, e), this.ICACHE_PAGE_BITS = 10, this.PAGE_MASK = (2 << this.ICACHE_PAGE_BITS) - 1, this.icache = new Array(t.byteLength >> this.ICACHE_PAGE_BITS + 1), this.mask = 33554431, this.resetMask() -} - -function BIOSView(t, e) { - MemoryView.call(this, t, e), this.ICACHE_PAGE_BITS = 16, this.PAGE_MASK = (2 << this.ICACHE_PAGE_BITS) - 1, this.icache = new Array(1) -} - -function BadMemory(t, e) { - this.inherit(), this.cpu = e, this.mmu = t -} - -function GameBoyAdvanceMMU() { - this.inherit(), this.REGION_BIOS = 0, this.REGION_WORKING_RAM = 2, this.REGION_WORKING_IRAM = 3, this.REGION_IO = 4, this.REGION_PALETTE_RAM = 5, this.REGION_VRAM = 6, this.REGION_OAM = 7, this.REGION_CART0 = 8, this.REGION_CART1 = 10, this.REGION_CART2 = 12, this.REGION_CART_SRAM = 14, this.BASE_BIOS = 0, this.BASE_WORKING_RAM = 33554432, this.BASE_WORKING_IRAM = 50331648, this.BASE_IO = 67108864, this.BASE_PALETTE_RAM = 83886080, this.BASE_VRAM = 100663296, this.BASE_OAM = 117440512, this.BASE_CART0 = 134217728, this.BASE_CART1 = 167772160, this.BASE_CART2 = 201326592, this.BASE_CART_SRAM = 234881024, this.BASE_MASK = 251658240, this.BASE_OFFSET = 24, this.OFFSET_MASK = 16777215, this.SIZE_BIOS = 16384, this.SIZE_WORKING_RAM = 262144, this.SIZE_WORKING_IRAM = 32768, this.SIZE_IO = 1024, this.SIZE_PALETTE_RAM = 1024, this.SIZE_VRAM = 98304, this.SIZE_OAM = 1024, this.SIZE_CART0 = 33554432, this.SIZE_CART1 = 33554432, this.SIZE_CART2 = 33554432, this.SIZE_CART_SRAM = 32768, this.SIZE_CART_FLASH512 = 65536, this.SIZE_CART_FLASH1M = 131072, this.SIZE_CART_EEPROM = 8192, this.DMA_TIMING_NOW = 0, this.DMA_TIMING_VBLANK = 1, this.DMA_TIMING_HBLANK = 2, this.DMA_TIMING_CUSTOM = 3, this.DMA_INCREMENT = 0, this.DMA_DECREMENT = 1, this.DMA_FIXED = 2, this.DMA_INCREMENT_RELOAD = 3, this.DMA_OFFSET = [1, -1, 0, 1], this.WAITSTATES = [0, 0, 2, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4], this.WAITSTATES_32 = [0, 0, 5, 0, 0, 1, 0, 1, 7, 7, 9, 9, 13, 13, 8], this.WAITSTATES_SEQ = [0, 0, 2, 0, 0, 0, 0, 0, 2, 2, 4, 4, 8, 8, 4], this.WAITSTATES_SEQ_32 = [0, 0, 5, 0, 0, 1, 0, 1, 5, 5, 9, 9, 17, 17, 8], this.NULLWAIT = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - for (var t = 15; t < 256; ++t) this.WAITSTATES[t] = 0, this.WAITSTATES_32[t] = 0, this.WAITSTATES_SEQ[t] = 0, this.WAITSTATES_SEQ_32[t] = 0, this.NULLWAIT[t] = 0; - this.ROM_WS = [4, 3, 2, 8], this.ROM_WS_SEQ = [ - [2, 1], - [4, 1], - [8, 1] - ], this.ICACHE_PAGE_BITS = 8, this.PAGE_MASK = (2 << this.ICACHE_PAGE_BITS) - 1, this.bios = null -} - -function GameBoyAdvanceIO() { - this.DISPCNT = 0, this.GREENSWP = 2, this.DISPSTAT = 4, this.VCOUNT = 6, this.BG0CNT = 8, this.BG1CNT = 10, this.BG2CNT = 12, this.BG3CNT = 14, this.BG0HOFS = 16, this.BG0VOFS = 18, this.BG1HOFS = 20, this.BG1VOFS = 22, this.BG2HOFS = 24, this.BG2VOFS = 26, this.BG3HOFS = 28, this.BG3VOFS = 30, this.BG2PA = 32, this.BG2PB = 34, this.BG2PC = 36, this.BG2PD = 38, this.BG2X_LO = 40, this.BG2X_HI = 42, this.BG2Y_LO = 44, this.BG2Y_HI = 46, this.BG3PA = 48, this.BG3PB = 50, this.BG3PC = 52, this.BG3PD = 54, this.BG3X_LO = 56, this.BG3X_HI = 58, this.BG3Y_LO = 60, this.BG3Y_HI = 62, this.WIN0H = 64, this.WIN1H = 66, this.WIN0V = 68, this.WIN1V = 70, this.WININ = 72, this.WINOUT = 74, this.MOSAIC = 76, this.BLDCNT = 80, this.BLDALPHA = 82, this.BLDY = 84, this.SOUND1CNT_LO = 96, this.SOUND1CNT_HI = 98, this.SOUND1CNT_X = 100, this.SOUND2CNT_LO = 104, this.SOUND2CNT_HI = 108, this.SOUND3CNT_LO = 112, this.SOUND3CNT_HI = 114, this.SOUND3CNT_X = 116, this.SOUND4CNT_LO = 120, this.SOUND4CNT_HI = 124, this.SOUNDCNT_LO = 128, this.SOUNDCNT_HI = 130, this.SOUNDCNT_X = 132, this.SOUNDBIAS = 136, this.WAVE_RAM0_LO = 144, this.WAVE_RAM0_HI = 146, this.WAVE_RAM1_LO = 148, this.WAVE_RAM1_HI = 150, this.WAVE_RAM2_LO = 152, this.WAVE_RAM2_HI = 154, this.WAVE_RAM3_LO = 156, this.WAVE_RAM3_HI = 158, this.FIFO_A_LO = 160, this.FIFO_A_HI = 162, this.FIFO_B_LO = 164, this.FIFO_B_HI = 166, this.DMA0SAD_LO = 176, this.DMA0SAD_HI = 178, this.DMA0DAD_LO = 180, this.DMA0DAD_HI = 182, this.DMA0CNT_LO = 184, this.DMA0CNT_HI = 186, this.DMA1SAD_LO = 188, this.DMA1SAD_HI = 190, this.DMA1DAD_LO = 192, this.DMA1DAD_HI = 194, this.DMA1CNT_LO = 196, this.DMA1CNT_HI = 198, this.DMA2SAD_LO = 200, this.DMA2SAD_HI = 202, this.DMA2DAD_LO = 204, this.DMA2DAD_HI = 206, this.DMA2CNT_LO = 208, this.DMA2CNT_HI = 210, this.DMA3SAD_LO = 212, this.DMA3SAD_HI = 214, this.DMA3DAD_LO = 216, this.DMA3DAD_HI = 218, this.DMA3CNT_LO = 220, this.DMA3CNT_HI = 222, this.TM0CNT_LO = 256, this.TM0CNT_HI = 258, this.TM1CNT_LO = 260, this.TM1CNT_HI = 262, this.TM2CNT_LO = 264, this.TM2CNT_HI = 266, this.TM3CNT_LO = 268, this.TM3CNT_HI = 270, this.SIODATA32_LO = 288, this.SIOMULTI0 = 288, this.SIODATA32_HI = 290, this.SIOMULTI1 = 290, this.SIOMULTI2 = 292, this.SIOMULTI3 = 294, this.SIOCNT = 296, this.SIOMLT_SEND = 298, this.SIODATA8 = 298, this.RCNT = 308, this.JOYCNT = 320, this.JOY_RECV = 336, this.JOY_TRANS = 340, this.JOYSTAT = 344, this.KEYINPUT = 304, this.KEYCNT = 306, this.IE = 512, this.IF = 514, this.WAITCNT = 516, this.IME = 520, this.POSTFLG = 768, this.HALTCNT = 769, this.DEFAULT_DISPCNT = 128, this.DEFAULT_SOUNDBIAS = 512, this.DEFAULT_BGPA = 1, this.DEFAULT_BGPD = 1, this.DEFAULT_RCNT = 32768 -} - -function GameBoyAdvanceAudio() { - this.bufferSize = 4096, this.maxSamples = this.bufferSize << 2, this.buffers = [new Float32Array(this.maxSamples), new Float32Array(this.maxSamples)], this.sampleMask = this.maxSamples - 1, this.masterEnable = !0, this.masterVolume = 1, this.SOUND_MAX = 1024, this.FIFO_MAX = 512, this.PSG_MAX = 128, this.isInit = !1, this.isInit2 = !1, window.AudioContext = window.AudioContext || window.webkitAudioContext, this.context = new AudioContext -} - -function GameBoyAdvanceVideo() { - this.renderPath = new GameBoyAdvanceSoftwareRenderer, this.CYCLES_PER_PIXEL = 4, this.HORIZONTAL_PIXELS = 240, this.HBLANK_PIXELS = 68, this.HDRAW_LENGTH = 1006, this.HBLANK_LENGTH = 226, this.HORIZONTAL_LENGTH = 1232, this.VERTICAL_PIXELS = 160, this.VBLANK_PIXELS = 68, this.VERTICAL_TOTAL_PIXELS = 228, this.TOTAL_LENGTH = 280896, this.drawCallback = function() {}, this.vblankCallback = function() {} -} - -function MemoryProxy(t, e, i) { - if (this.owner = t, this.blocks = [], this.blockSize = i, this.mask = (1 << i) - 1, this.size = e, i) - for (var r = 0; r < e >> i; ++r) this.blocks.push(new MemoryView(new ArrayBuffer(1 << i))); - else this.blockSize = 31, this.mask = -1, this.blocks[0] = new MemoryView(new ArrayBuffer(e)) -} - -function GameBoyAdvanceRenderProxy() { - this.worker = new Worker("js/video/worker.js"), this.currentFrame = 0, this.delay = 0, this.skipFrame = !1, this.dirty = null; - var e = this, - i = { - finish: function(t) { - e.backing = t.backing, e.caller.finishDraw(e.backing), --e.delay - } - }; - this.worker.onmessage = function(t) { - i[t.data.type](t.data) - } -} - -function MemoryAligned16(t) { - this.buffer = new Uint16Array(t >> 1) -} - -function GameBoyAdvanceVRAM(t) { - MemoryAligned16.call(this, t), this.vram = this.buffer -} - -function GameBoyAdvanceOAM(t) { - MemoryAligned16.call(this, t), this.oam = this.buffer, this.objs = new Array(128); - for (var e = 0; e < 128; ++e) this.objs[e] = new GameBoyAdvanceOBJ(this, e); - this.scalerot = new Array(32); - for (e = 0; e < 32; ++e) this.scalerot[e] = { - a: 1, - b: 0, - c: 0, - d: 1 - } -} - -function GameBoyAdvancePalette() { - this.colors = [new Array(256), new Array(256)], this.adjustedColors = [new Array(256), new Array(256)], this.passthroughColors = [this.colors[0], this.colors[0], this.colors[0], this.colors[0], this.colors[1], this.colors[0]], this.blendY = 1 -} - -function GameBoyAdvanceOBJ(t, e) { - this.TILE_OFFSET = 65536, this.oam = t, this.index = e, this.x = 0, this.y = 0, this.scalerot = 0, this.doublesize = !1, this.disable = 1, this.mode = 0, this.mosaic = !1, this.multipalette = !1, this.shape = 0, this.scalerotParam = 0, this.hflip = 0, this.vflip = 0, this.tileBase = 0, this.priority = 0, this.palette = 0, this.drawScanline = this.drawScanlineNormal, this.pushPixel = GameBoyAdvanceSoftwareRenderer.pushPixel, this.cachedWidth = 8, this.cachedHeight = 8 -} - -function GameBoyAdvanceOBJLayer(t, e) { - this.video = t, this.bg = !1, this.index = t.LAYER_OBJ, this.priority = e, this.enabled = !1, this.objwin = 0 -} - -function GameBoyAdvanceSoftwareRenderer() { - this.LAYER_BG0 = 0, this.LAYER_BG1 = 1, this.LAYER_BG2 = 2, this.LAYER_BG3 = 3, this.LAYER_OBJ = 4, this.LAYER_BACKDROP = 5, this.HORIZONTAL_PIXELS = 240, this.VERTICAL_PIXELS = 160, this.LAYER_MASK = 6, this.BACKGROUND_MASK = 1, this.TARGET2_MASK = 8, this.TARGET1_MASK = 16, this.OBJWIN_MASK = 32, this.WRITTEN_MASK = 128, this.PRIORITY_MASK = this.LAYER_MASK | this.BACKGROUND_MASK, this.drawBackdrop = new function(n) { - this.bg = !0, this.priority = -1, this.index = n.LAYER_BACKDROP, this.enabled = !0, this.drawScanline = function(t, e, i, r) { - for (var s = i; s < r; ++s) t.stencil[s] & n.WRITTEN_MASK ? t.stencil[s] & n.TARGET1_MASK && (t.color[s] = n.palette.mix(n.blendB, n.palette.accessColor(this.index, 0), n.blendA, t.color[s]), t.stencil[s] = n.WRITTEN_MASK) : (t.color[s] = n.palette.accessColor(this.index, 0), t.stencil[s] = n.WRITTEN_MASK) - } - }(this) -} - -function GameBoyAdvanceInterruptHandler() { - this.inherit(), this.FREQUENCY = 16777216, this.cpu = null, this.enable = !1, this.IRQ_VBLANK = 0, this.IRQ_HBLANK = 1, this.IRQ_VCOUNTER = 2, this.IRQ_TIMER0 = 3, this.IRQ_TIMER1 = 4, this.IRQ_TIMER2 = 5, this.IRQ_TIMER3 = 6, this.IRQ_SIO = 7, this.IRQ_DMA0 = 8, this.IRQ_DMA1 = 9, this.IRQ_DMA2 = 10, this.IRQ_DMA3 = 11, this.IRQ_KEYPAD = 12, this.IRQ_GAMEPAK = 13, this.MASK_VBLANK = 1, this.MASK_HBLANK = 2, this.MASK_VCOUNTER = 4, this.MASK_TIMER0 = 8, this.MASK_TIMER1 = 16, this.MASK_TIMER2 = 32, this.MASK_TIMER3 = 64, this.MASK_SIO = 128, this.MASK_DMA0 = 256, this.MASK_DMA1 = 512, this.MASK_DMA2 = 1024, this.MASK_DMA3 = 2048, this.MASK_KEYPAD = 4096, this.MASK_GAMEPAK = 8192 -} - -function GameBoyAdvanceKeypad() { - this.KEYCODE_LEFT = 37, this.KEYCODE_UP = 38, this.KEYCODE_RIGHT = 39, this.KEYCODE_DOWN = 40, this.KEYCODE_START = 13, this.KEYCODE_SELECT = 220, this.KEYCODE_A = 90, this.KEYCODE_B = 88, this.KEYCODE_L = 65, this.KEYCODE_R = 83, this.GAMEPAD_LEFT = 14, this.GAMEPAD_UP = 12, this.GAMEPAD_RIGHT = 15, this.GAMEPAD_DOWN = 13, this.GAMEPAD_START = 9, this.GAMEPAD_SELECT = 8, this.GAMEPAD_A = 1, this.GAMEPAD_B = 0, this.GAMEPAD_L = 4, this.GAMEPAD_R = 5, this.GAMEPAD_THRESHOLD = .2, this.A = 0, this.B = 1, this.SELECT = 2, this.START = 3, this.RIGHT = 4, this.LEFT = 5, this.UP = 6, this.DOWN = 7, this.R = 8, this.L = 9, this.currentDown = 1023, this.eatInput = !1, this.gamepads = [] -} - -function GameBoyAdvanceSIO() { - this.SIO_NORMAL_8 = 0, this.SIO_NORMAL_32 = 1, this.SIO_MULTI = 2, this.SIO_UART = 3, this.SIO_GPIO = 8, this.SIO_JOYBUS = 12, this.BAUD = [9600, 38400, 57600, 115200] -} - -function SRAMSavedata(t) { - MemoryView.call(this, new ArrayBuffer(t), 0), this.writePending = !1 -} - -function FlashSavedata(t) { - MemoryView.call(this, new ArrayBuffer(t), 0), this.COMMAND_WIPE = 16, this.COMMAND_ERASE_SECTOR = 48, this.COMMAND_ERASE = 128, this.COMMAND_ID = 144, this.COMMAND_WRITE = 160, this.COMMAND_SWITCH_BANK = 176, this.COMMAND_TERMINATE_ID = 240, this.ID_PANASONIC = 6962, this.ID_SANYO = 4962, this.bank0 = new DataView(this.buffer, 0, 65536), 65536 < t ? (this.id = this.ID_SANYO, this.bank1 = new DataView(this.buffer, 65536)) : (this.id = this.ID_PANASONIC, this.bank1 = null), this.bank = this.bank0, this.idMode = !1, this.writePending = !1, this.first = 0, this.second = 0, this.command = 0, this.pendingCommand = 0 -} - -function EEPROMSavedata(t, e) { - MemoryView.call(this, new ArrayBuffer(t), 0), this.writeAddress = 0, this.readBitsRemaining = 0, this.readAddress = 0, this.command = 0, this.commandBitsRemaining = 0, this.realSize = 0, this.addressBits = 0, this.writePending = !1, this.dma = e.core.irq.dma[3], this.COMMAND_NULL = 0, this.COMMAND_PENDING = 1, this.COMMAND_WRITE = 2, this.COMMAND_READ_PENDING = 3, this.COMMAND_READ = 4 -} - -function GameBoyAdvanceGPIO(t, e) { - this.core = t, this.rom = e, this.readWrite = 0, this.direction = 0, this.device = new GameBoyAdvanceRTC(this) -} - -function GameBoyAdvanceRTC(t) { - this.gpio = t, this.pins = 0, this.direction = 0, this.totalBytes = [0, 0, 7, 0, 1, 0, 3, 0], this.bytesRemaining = 0, this.transferStep = 0, this.reading = 0, this.bitsRead = 0, this.bits = 0, this.command = -1, this.control = 64, this.time = [0, 0, 0, 0, 0, 0, 0] -} - -function GameBoyAdvance() { - this.LOG_ERROR = 1, this.LOG_WARN = 2, this.LOG_STUB = 4, this.LOG_INFO = 8, this.LOG_DEBUG = 16, this.SYS_ID = "com.endrift.gbajs", this.logLevel = this.LOG_ERROR | this.LOG_WARN, this.rom = null, this.cpu = new ARMCore, this.mmu = new GameBoyAdvanceMMU, this.irq = new GameBoyAdvanceInterruptHandler, this.io = new GameBoyAdvanceIO, this.audio = new GameBoyAdvanceAudio, this.video = new GameBoyAdvanceVideo, this.keypad = new GameBoyAdvanceKeypad, this.sio = new GameBoyAdvanceSIO, this.cpu.mmu = this.mmu, this.cpu.irq = this.irq, this.mmu.cpu = this.cpu, (this.mmu.core = this).irq.cpu = this.cpu, this.irq.io = this.io, this.irq.audio = this.audio, this.irq.video = this.video, (this.irq.core = this).io.cpu = this.cpu, this.io.audio = this.audio, this.io.video = this.video, this.io.keypad = this.keypad, this.io.sio = this.sio, (this.io.core = this).audio.cpu = this.cpu, (this.audio.core = this).video.cpu = this.cpu, (((this.video.core = this).keypad.core = this).sio.core = this).keypad.registerHandlers(), this.doStep = this.waitFrame, this.paused = !1, this.seenFrame = !1, this.seenSave = !1, this.lastVblank = 0, this.queue = null, this.reportFPS = null, this.throttle = 16; - var e = this; - window.queueFrame = function(t) { - e.queue = window.setTimeout(t, e.throttle) - }, window.URL = window.URL || window.webkitURL, this.video.vblankCallback = function() { - e.seenFrame = !0 - } -} -ARMCoreArm.prototype.constructAddressingMode1ASR = function(i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - ++s.cycles; - var t = n[i]; - i == s.PC && (t += 4), t &= 255; - var e = n[r]; - r == s.PC && (e += 4), 0 == t ? (s.shifterOperand = e, s.shifterCarryOut = s.cpsrC) : t < 32 ? (s.shifterOperand = e >> t, s.shifterCarryOut = e & 1 << t - 1) : n[r] >> 31 ? (s.shifterOperand = 4294967295, s.shifterCarryOut = 2147483648) : (s.shifterOperand = 0, s.shifterCarryOut = 0) - } -}, ARMCoreArm.prototype.constructAddressingMode1Immediate = function(t) { - var e = this.cpu; - return function() { - e.shifterOperand = t, e.shifterCarryOut = e.cpsrC - } -}, ARMCoreArm.prototype.constructAddressingMode1ImmediateRotate = function(t, e) { - var i = this.cpu; - return function() { - i.shifterOperand = t >>> e | t << 32 - e, i.shifterCarryOut = i.shifterOperand >> 31 - } -}, ARMCoreArm.prototype.constructAddressingMode1LSL = function(i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - ++s.cycles; - var t = n[i]; - i == s.PC && (t += 4), t &= 255; - var e = n[r]; - r == s.PC && (e += 4), 0 == t ? (s.shifterOperand = e, s.shifterCarryOut = s.cpsrC) : t < 32 ? (s.shifterOperand = e << t, s.shifterCarryOut = e & 1 << 32 - t) : 32 == t ? (s.shifterOperand = 0, s.shifterCarryOut = 1 & e) : (s.shifterOperand = 0, s.shifterCarryOut = 0) - } -}, ARMCoreArm.prototype.constructAddressingMode1LSR = function(i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - ++s.cycles; - var t = n[i]; - i == s.PC && (t += 4), t &= 255; - var e = n[r]; - r == s.PC && (e += 4), 0 == t ? (s.shifterOperand = e, s.shifterCarryOut = s.cpsrC) : t < 32 ? (s.shifterOperand = e >>> t, s.shifterCarryOut = e & 1 << t - 1) : 32 == t ? (s.shifterOperand = 0, s.shifterCarryOut = e >> 31) : (s.shifterOperand = 0, s.shifterCarryOut = 0) - } -}, ARMCoreArm.prototype.constructAddressingMode1ROR = function(r, s) { - var n = this.cpu, - a = n.gprs; - return function() { - ++n.cycles; - var t = a[r]; - r == n.PC && (t += 4), t &= 255; - var e = a[s]; - s == n.PC && (e += 4); - var i = 31 & t; - 0 == t ? (n.shifterOperand = e, n.shifterCarryOut = n.cpsrC) : i ? (n.shifterOperand = a[s] >>> i | a[s] << 32 - i, n.shifterCarryOut = e & 1 << i - 1) : (n.shifterOperand = e, n.shifterCarryOut = e >> 31) - } -}, ARMCoreArm.prototype.constructAddressingMode23Immediate = function(t, e, i) { - var r = (983040 & t) >> 16; - return this.addressingMode23Immediate[(27262976 & t) >> 21](r, e, i) -}, ARMCoreArm.prototype.constructAddressingMode23Register = function(t, e, i) { - var r = (983040 & t) >> 16; - return this.addressingMode23Register[(27262976 & t) >> 21](r, e, i) -}, ARMCoreArm.prototype.constructAddressingMode2RegisterShifted = function(t, e, i) { - var r = (983040 & t) >> 16; - return this.addressingMode2RegisterShifted[(27262976 & t) >> 21](r, e, i) -}, ARMCoreArm.prototype.constructAddressingMode4 = function(t, e) { - var i = this.cpu.gprs; - return function() { - return i[e] + t - } -}, ARMCoreArm.prototype.constructAddressingMode4Writeback = function(i, r, s, n) { - var a = this.cpu, - o = a.gprs; - return function(t) { - var e = o[s] + i; - return t && n && a.mmu.store32(o[s] + i - 4, o[s]), o[s] += r, e - } -}, ARMCoreArm.prototype.constructADC = function(e, i, r, s) { - var n = this.cpu, - a = n.gprs; - return function() { - if (n.mmu.waitPrefetch32(a[n.PC]), !s || s()) { - r(); - var t = (n.shifterOperand >>> 0) + !!n.cpsrC; - a[e] = (a[i] >>> 0) + t - } - } -}, ARMCoreArm.prototype.constructADCS = function(i, r, s, n) { - var a = this.cpu, - o = a.gprs; - return function() { - if (a.mmu.waitPrefetch32(o[a.PC]), !n || n()) { - s(); - var t = (a.shifterOperand >>> 0) + !!a.cpsrC, - e = (o[r] >>> 0) + t; - i == a.PC && a.hasSPSR() ? a.unpackCPSR(a.spsr) : (a.cpsrN = e >> 31, a.cpsrZ = !(4294967295 & e), a.cpsrC = 4294967295 < e, a.cpsrV = o[r] >> 31 == t >> 31 && o[r] >> 31 != e >> 31 && t >> 31 != e >> 31), o[i] = e - } - } -}, ARMCoreArm.prototype.constructADD = function(t, e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = (n[e] >>> 0) + (s.shifterOperand >>> 0)) - } -}, ARMCoreArm.prototype.constructADDS = function(e, i, r, s) { - var n = this.cpu, - a = n.gprs; - return function() { - if (n.mmu.waitPrefetch32(a[n.PC]), !s || s()) { - r(); - var t = (a[i] >>> 0) + (n.shifterOperand >>> 0); - e == n.PC && n.hasSPSR() ? n.unpackCPSR(n.spsr) : (n.cpsrN = t >> 31, n.cpsrZ = !(4294967295 & t), n.cpsrC = 4294967295 < t, n.cpsrV = a[i] >> 31 == n.shifterOperand >> 31 && a[i] >> 31 != t >> 31 && n.shifterOperand >> 31 != t >> 31), a[e] = t - } - } -}, ARMCoreArm.prototype.constructAND = function(t, e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = n[e] & s.shifterOperand) - } -}, ARMCoreArm.prototype.constructANDS = function(t, e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = n[e] & s.shifterOperand, t == s.PC && s.hasSPSR() ? s.unpackCPSR(s.spsr) : (s.cpsrN = n[t] >> 31, s.cpsrZ = !(4294967295 & n[t]), s.cpsrC = s.shifterCarryOut)) - } -}, ARMCoreArm.prototype.constructB = function(t, e) { - var i = this.cpu, - r = i.gprs; - return function() { - !e || e() ? (i.mmu.waitPrefetch32(r[i.PC]), r[i.PC] += t) : i.mmu.waitPrefetch32(r[i.PC]) - } -}, ARMCoreArm.prototype.constructBIC = function(t, e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = n[e] & ~s.shifterOperand) - } -}, ARMCoreArm.prototype.constructBICS = function(t, e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = n[e] & ~s.shifterOperand, t == s.PC && s.hasSPSR() ? s.unpackCPSR(s.spsr) : (s.cpsrN = n[t] >> 31, s.cpsrZ = !(4294967295 & n[t]), s.cpsrC = s.shifterCarryOut)) - } -}, ARMCoreArm.prototype.constructBL = function(t, e) { - var i = this.cpu, - r = i.gprs; - return function() { - !e || e() ? (i.mmu.waitPrefetch32(r[i.PC]), r[i.LR] = r[i.PC] - 4, r[i.PC] += t) : i.mmu.waitPrefetch32(r[i.PC]) - } -}, ARMCoreArm.prototype.constructBX = function(t, e) { - var i = this.cpu, - r = i.gprs; - return function() { - !e || e() ? (i.mmu.waitPrefetch32(r[i.PC]), i.switchExecMode(1 & r[t]), r[i.PC] = 4294967294 & r[t]) : i.mmu.waitPrefetch32(r[i.PC]) - } -}, ARMCoreArm.prototype.constructCMN = function(t, e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - if (s.mmu.waitPrefetch32(n[s.PC]), !r || r()) { - i(); - var t = (n[e] >>> 0) + (s.shifterOperand >>> 0); - s.cpsrN = t >> 31, s.cpsrZ = !(4294967295 & t), s.cpsrC = 4294967295 < t, s.cpsrV = n[e] >> 31 == s.shifterOperand >> 31 && n[e] >> 31 != t >> 31 && s.shifterOperand >> 31 != t >> 31 - } - } -}, ARMCoreArm.prototype.constructCMP = function(t, e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - if (s.mmu.waitPrefetch32(n[s.PC]), !r || r()) { - i(); - var t = n[e] - s.shifterOperand; - s.cpsrN = t >> 31, s.cpsrZ = !(4294967295 & t), s.cpsrC = n[e] >>> 0 >= s.shifterOperand >>> 0, s.cpsrV = n[e] >> 31 != s.shifterOperand >> 31 && n[e] >> 31 != t >> 31 - } - } -}, ARMCoreArm.prototype.constructEOR = function(t, e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = n[e] ^ s.shifterOperand) - } -}, ARMCoreArm.prototype.constructEORS = function(t, e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = n[e] ^ s.shifterOperand, t == s.PC && s.hasSPSR() ? s.unpackCPSR(s.spsr) : (s.cpsrN = n[t] >> 31, s.cpsrZ = !(4294967295 & n[t]), s.cpsrC = s.shifterCarryOut)) - } -}, ARMCoreArm.prototype.constructLDM = function(s, n, a) { - var o = this.cpu, - h = o.gprs, - c = o.mmu; - return function() { - if (c.waitPrefetch32(h[o.PC]), !a || a()) { - var t, e, i = n(!1), - r = 0; - for (t = s, e = 0; t; t >>= 1, ++e) 1 & t && (h[e] = c.load32(4294967292 & i), i += 4, ++r); - c.waitMulti32(i, r), ++o.cycles - } - } -}, ARMCoreArm.prototype.constructLDMS = function(n, a, o) { - var h = this.cpu, - c = h.gprs, - u = h.mmu; - return function() { - if (u.waitPrefetch32(c[h.PC]), !o || o()) { - var t, e, i = a(!1), - r = 0, - s = h.mode; - for (h.switchMode(h.MODE_SYSTEM), t = n, e = 0; t; t >>= 1, ++e) 1 & t && (c[e] = u.load32(4294967292 & i), i += 4, ++r); - h.switchMode(s), u.waitMulti32(i, r), ++h.cycles - } - } -}, ARMCoreArm.prototype.constructLDR = function(e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - if (s.mmu.waitPrefetch32(n[s.PC]), !r || r()) { - var t = i(); - n[e] = s.mmu.load32(t), s.mmu.wait32(t), ++s.cycles - } - } -}, ARMCoreArm.prototype.constructLDRB = function(e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - if (s.mmu.waitPrefetch32(n[s.PC]), !r || r()) { - var t = i(); - n[e] = s.mmu.loadU8(t), s.mmu.wait(t), ++s.cycles - } - } -}, ARMCoreArm.prototype.constructLDRH = function(e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - if (s.mmu.waitPrefetch32(n[s.PC]), !r || r()) { - var t = i(); - n[e] = s.mmu.loadU16(t), s.mmu.wait(t), ++s.cycles - } - } -}, ARMCoreArm.prototype.constructLDRSB = function(e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - if (s.mmu.waitPrefetch32(n[s.PC]), !r || r()) { - var t = i(); - n[e] = s.mmu.load8(t), s.mmu.wait(t), ++s.cycles - } - } -}, ARMCoreArm.prototype.constructLDRSH = function(e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - if (s.mmu.waitPrefetch32(n[s.PC]), !r || r()) { - var t = i(); - n[e] = s.mmu.load16(t), s.mmu.wait(t), ++s.cycles - } - } -}, ARMCoreArm.prototype.constructMLA = function(i, r, s, n, a) { - var o = this.cpu, - h = o.gprs; - return function() { - if (o.mmu.waitPrefetch32(h[o.PC]), !a || a()) - if (++o.cycles, o.mmu.waitMul(s), 4294901760 & h[n] && 4294901760 & h[s]) { - var t = (4294901760 & h[n]) * h[s] & 4294967295, - e = (65535 & h[n]) * h[s] & 4294967295; - h[i] = t + e + h[r] & 4294967295 - } else h[i] = h[n] * h[s] + h[r] - } -}, ARMCoreArm.prototype.constructMLAS = function(i, r, s, n, a) { - var o = this.cpu, - h = o.gprs; - return function() { - if (o.mmu.waitPrefetch32(h[o.PC]), !a || a()) { - if (++o.cycles, o.mmu.waitMul(s), 4294901760 & h[n] && 4294901760 & h[s]) { - var t = (4294901760 & h[n]) * h[s] & 4294967295, - e = (65535 & h[n]) * h[s] & 4294967295; - h[i] = t + e + h[r] & 4294967295 - } else h[i] = h[n] * h[s] + h[r]; - o.cpsrN = h[i] >> 31, o.cpsrZ = !(4294967295 & h[i]) - } - } -}, ARMCoreArm.prototype.constructMOV = function(t, e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = s.shifterOperand) - } -}, ARMCoreArm.prototype.constructMOVS = function(t, e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = s.shifterOperand, t == s.PC && s.hasSPSR() ? s.unpackCPSR(s.spsr) : (s.cpsrN = n[t] >> 31, s.cpsrZ = !(4294967295 & n[t]), s.cpsrC = s.shifterCarryOut)) - } -}, ARMCoreArm.prototype.constructMRS = function(t, e, i) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.waitPrefetch32(s[r.PC]), i && !i() || (s[t] = e ? r.spsr : r.packCPSR()) - } -}, ARMCoreArm.prototype.constructMSR = function(i, r, s, n, a) { - var o = this.cpu, - h = o.gprs, - c = 65536 & s, - u = 524288 & s; - return function() { - if (o.mmu.waitPrefetch32(h[o.PC]), !a || a()) { - var t; - t = 33554432 & s ? n : h[i]; - var e = (c ? 255 : 0) | (u ? 4278190080 : 0); - r ? (e &= o.USER_MASK | o.PRIV_MASK | o.STATE_MASK, o.spsr = o.spsr & ~e | t & e) : (e & o.USER_MASK && (o.cpsrN = t >> 31, o.cpsrZ = 1073741824 & t, o.cpsrC = 536870912 & t, o.cpsrV = 268435456 & t), o.mode != o.MODE_USER && e & o.PRIV_MASK && (o.switchMode(15 & t | 16), o.cpsrI = 128 & t, o.cpsrF = 64 & t)) - } - } -}, ARMCoreArm.prototype.constructMUL = function(i, r, s, n) { - var a = this.cpu, - o = a.gprs; - return function() { - if (a.mmu.waitPrefetch32(o[a.PC]), !n || n()) - if (a.mmu.waitMul(o[r]), 4294901760 & o[s] && 4294901760 & o[r]) { - var t = (4294901760 & o[s]) * o[r] | 0, - e = (65535 & o[s]) * o[r] | 0; - o[i] = t + e - } else o[i] = o[s] * o[r] - } -}, ARMCoreArm.prototype.constructMULS = function(i, r, s, n) { - var a = this.cpu, - o = a.gprs; - return function() { - if (a.mmu.waitPrefetch32(o[a.PC]), !n || n()) { - if (a.mmu.waitMul(o[r]), 4294901760 & o[s] && 4294901760 & o[r]) { - var t = (4294901760 & o[s]) * o[r] | 0, - e = (65535 & o[s]) * o[r] | 0; - o[i] = t + e - } else o[i] = o[s] * o[r]; - a.cpsrN = o[i] >> 31, a.cpsrZ = !(4294967295 & o[i]) - } - } -}, ARMCoreArm.prototype.constructMVN = function(t, e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = ~s.shifterOperand) - } -}, ARMCoreArm.prototype.constructMVNS = function(t, e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = ~s.shifterOperand, t == s.PC && s.hasSPSR() ? s.unpackCPSR(s.spsr) : (s.cpsrN = n[t] >> 31, s.cpsrZ = !(4294967295 & n[t]), s.cpsrC = s.shifterCarryOut)) - } -}, ARMCoreArm.prototype.constructORR = function(t, e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = n[e] | s.shifterOperand) - } -}, ARMCoreArm.prototype.constructORRS = function(t, e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = n[e] | s.shifterOperand, t == s.PC && s.hasSPSR() ? s.unpackCPSR(s.spsr) : (s.cpsrN = n[t] >> 31, s.cpsrZ = !(4294967295 & n[t]), s.cpsrC = s.shifterCarryOut)) - } -}, ARMCoreArm.prototype.constructRSB = function(t, e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = s.shifterOperand - n[e]) - } -}, ARMCoreArm.prototype.constructRSBS = function(e, i, r, s) { - var n = this.cpu, - a = n.gprs; - return function() { - if (n.mmu.waitPrefetch32(a[n.PC]), !s || s()) { - r(); - var t = n.shifterOperand - a[i]; - e == n.PC && n.hasSPSR() ? n.unpackCPSR(n.spsr) : (n.cpsrN = t >> 31, n.cpsrZ = !(4294967295 & t), n.cpsrC = n.shifterOperand >>> 0 >= a[i] >>> 0, n.cpsrV = n.shifterOperand >> 31 != a[i] >> 31 && n.shifterOperand >> 31 != t >> 31), a[e] = t - } - } -}, ARMCoreArm.prototype.constructRSC = function(e, i, r, s) { - var n = this.cpu, - a = n.gprs; - return function() { - if (n.mmu.waitPrefetch32(a[n.PC]), !s || s()) { - r(); - var t = (a[i] >>> 0) + !n.cpsrC; - a[e] = (n.shifterOperand >>> 0) - t - } - } -}, ARMCoreArm.prototype.constructRSCS = function(i, r, s, n) { - var a = this.cpu, - o = a.gprs; - return function() { - if (a.mmu.waitPrefetch32(o[a.PC]), !n || n()) { - s(); - var t = (o[r] >>> 0) + !a.cpsrC, - e = (a.shifterOperand >>> 0) - t; - i == a.PC && a.hasSPSR() ? a.unpackCPSR(a.spsr) : (a.cpsrN = e >> 31, a.cpsrZ = !(4294967295 & e), a.cpsrC = a.shifterOperand >>> 0 >= e >>> 0, a.cpsrV = a.shifterOperand >> 31 != t >> 31 && a.shifterOperand >> 31 != e >> 31), o[i] = e - } - } -}, ARMCoreArm.prototype.constructSBC = function(e, i, r, s) { - var n = this.cpu, - a = n.gprs; - return function() { - if (n.mmu.waitPrefetch32(a[n.PC]), !s || s()) { - r(); - var t = (n.shifterOperand >>> 0) + !n.cpsrC; - a[e] = (a[i] >>> 0) - t - } - } -}, ARMCoreArm.prototype.constructSBCS = function(i, r, s, n) { - var a = this.cpu, - o = a.gprs; - return function() { - if (a.mmu.waitPrefetch32(o[a.PC]), !n || n()) { - s(); - var t = (a.shifterOperand >>> 0) + !a.cpsrC, - e = (o[r] >>> 0) - t; - i == a.PC && a.hasSPSR() ? a.unpackCPSR(a.spsr) : (a.cpsrN = e >> 31, a.cpsrZ = !(4294967295 & e), a.cpsrC = o[r] >>> 0 >= e >>> 0, a.cpsrV = o[r] >> 31 != t >> 31 && o[r] >> 31 != e >> 31), o[i] = e - } - } -}, ARMCoreArm.prototype.constructSMLAL = function(r, s, n, a, o) { - var h = this.cpu, - c = h.gprs; - return function() { - if (h.mmu.waitPrefetch32(c[h.PC]), !o || o()) { - h.cycles += 2, h.mmu.waitMul(n); - var t = (4294901760 & c[a]) * c[n], - e = (65535 & c[a]) * c[n], - i = (c[s] >>> 0) + t + e; - c[s] = i, c[r] += Math.floor(i * (1 / 4294967296)) - } - } -}, ARMCoreArm.prototype.constructSMLALS = function(r, s, n, a, o) { - var h = this.cpu, - c = h.gprs; - return function() { - if (h.mmu.waitPrefetch32(c[h.PC]), !o || o()) { - h.cycles += 2, h.mmu.waitMul(n); - var t = (4294901760 & c[a]) * c[n], - e = (65535 & c[a]) * c[n], - i = (c[s] >>> 0) + t + e; - c[s] = i, c[r] += Math.floor(i * (1 / 4294967296)), h.cpsrN = c[r] >> 31, h.cpsrZ = !(4294967295 & c[r] || 4294967295 & c[s]) - } - } -}, ARMCoreArm.prototype.constructSMULL = function(i, r, s, n, a) { - var o = this.cpu, - h = 1 / 4294967296, - c = o.gprs; - return function() { - if (o.mmu.waitPrefetch32(c[o.PC]), !a || a()) { - ++o.cycles, o.mmu.waitMul(c[s]); - var t = ((4294901760 & c[n]) >> 0) * (c[s] >> 0), - e = ((65535 & c[n]) >> 0) * (c[s] >> 0); - c[r] = (4294967295 & t) + (4294967295 & e) & 4294967295, c[i] = Math.floor(t * h + e * h) - } - } -}, ARMCoreArm.prototype.constructSMULLS = function(i, r, s, n, a) { - var o = this.cpu, - h = 1 / 4294967296, - c = o.gprs; - return function() { - if (o.mmu.waitPrefetch32(c[o.PC]), !a || a()) { - ++o.cycles, o.mmu.waitMul(c[s]); - var t = ((4294901760 & c[n]) >> 0) * (c[s] >> 0), - e = ((65535 & c[n]) >> 0) * (c[s] >> 0); - c[r] = (4294967295 & t) + (4294967295 & e) & 4294967295, c[i] = Math.floor(t * h + e * h), o.cpsrN = c[i] >> 31, o.cpsrZ = !(4294967295 & c[i] || 4294967295 & c[r]) - } - } -}, ARMCoreArm.prototype.constructSTM = function(s, n, a) { - var o = this.cpu, - h = o.gprs, - c = o.mmu; - return function() { - if (!a || a()) { - c.wait32(h[o.PC]); - var t, e, i = n(!0), - r = 0; - for (t = s, e = 0; t; t >>= 1, ++e) 1 & t && (c.store32(i, h[e]), i += 4, ++r); - c.waitMulti32(i, r) - } else c.waitPrefetch32(h[o.PC]) - } -}, ARMCoreArm.prototype.constructSTMS = function(n, a, o) { - var h = this.cpu, - c = h.gprs, - u = h.mmu; - return function() { - if (!o || o()) { - u.wait32(c[h.PC]); - var t, e, i = h.mode, - r = a(!0), - s = 0; - for (h.switchMode(h.MODE_SYSTEM), t = n, e = 0; t; t >>= 1, ++e) 1 & t && (u.store32(r, c[e]), r += 4, ++s); - h.switchMode(i), u.waitMulti32(r, s) - } else u.waitPrefetch32(c[h.PC]) - } -}, ARMCoreArm.prototype.constructSTR = function(e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - if (!r || r()) { - var t = i(); - s.mmu.store32(t, n[e]), s.mmu.wait32(t), s.mmu.wait32(n[s.PC]) - } else s.mmu.waitPrefetch32(n[s.PC]) - } -}, ARMCoreArm.prototype.constructSTRB = function(e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - if (!r || r()) { - var t = i(); - s.mmu.store8(t, n[e]), s.mmu.wait(t), s.mmu.wait32(n[s.PC]) - } else s.mmu.waitPrefetch32(n[s.PC]) - } -}, ARMCoreArm.prototype.constructSTRH = function(e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - if (!r || r()) { - var t = i(); - s.mmu.store16(t, n[e]), s.mmu.wait(t), s.mmu.wait32(n[s.PC]) - } else s.mmu.waitPrefetch32(n[s.PC]) - } -}, ARMCoreArm.prototype.constructSUB = function(t, e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = n[e] - s.shifterOperand) - } -}, ARMCoreArm.prototype.constructSUBS = function(e, i, r, s) { - var n = this.cpu, - a = n.gprs; - return function() { - if (n.mmu.waitPrefetch32(a[n.PC]), !s || s()) { - r(); - var t = a[i] - n.shifterOperand; - e == n.PC && n.hasSPSR() ? n.unpackCPSR(n.spsr) : (n.cpsrN = t >> 31, n.cpsrZ = !(4294967295 & t), n.cpsrC = a[i] >>> 0 >= n.shifterOperand >>> 0, n.cpsrV = a[i] >> 31 != n.shifterOperand >> 31 && a[i] >> 31 != t >> 31), a[e] = t - } - } -}, ARMCoreArm.prototype.constructSWI = function(t, e) { - var i = this.cpu, - r = i.gprs; - return function() { - (!e || e()) && i.irq.swi32(t), i.mmu.waitPrefetch32(r[i.PC]) - } -}, ARMCoreArm.prototype.constructSWP = function(e, i, r, s) { - var n = this.cpu, - a = n.gprs; - return function() { - if (n.mmu.waitPrefetch32(a[n.PC]), !s || s()) { - n.mmu.wait32(a[i]), n.mmu.wait32(a[i]); - var t = n.mmu.load32(a[i]); - n.mmu.store32(a[i], a[r]), a[e] = t, ++n.cycles - } - } -}, ARMCoreArm.prototype.constructSWPB = function(e, i, r, s) { - var n = this.cpu, - a = n.gprs; - return function() { - if (n.mmu.waitPrefetch32(a[n.PC]), !s || s()) { - n.mmu.wait(a[i]), n.mmu.wait(a[i]); - var t = n.mmu.load8(a[i]); - n.mmu.store8(a[i], a[r]), a[e] = t, ++n.cycles - } - } -}, ARMCoreArm.prototype.constructTEQ = function(t, e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - if (s.mmu.waitPrefetch32(n[s.PC]), !r || r()) { - i(); - var t = n[e] ^ s.shifterOperand; - s.cpsrN = t >> 31, s.cpsrZ = !(4294967295 & t), s.cpsrC = s.shifterCarryOut - } - } -}, ARMCoreArm.prototype.constructTST = function(t, e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - if (s.mmu.waitPrefetch32(n[s.PC]), !r || r()) { - i(); - var t = n[e] & s.shifterOperand; - s.cpsrN = t >> 31, s.cpsrZ = !(4294967295 & t), s.cpsrC = s.shifterCarryOut - } - } -}, ARMCoreArm.prototype.constructUMLAL = function(r, s, n, a, o) { - var h = this.cpu, - c = h.gprs; - return function() { - if (h.mmu.waitPrefetch32(c[h.PC]), !o || o()) { - h.cycles += 2, h.mmu.waitMul(n); - var t = ((4294901760 & c[a]) >>> 0) * (c[n] >>> 0), - e = (65535 & c[a]) * (c[n] >>> 0), - i = (c[s] >>> 0) + t + e; - c[s] = i, c[r] += i * (1 / 4294967296) - } - } -}, ARMCoreArm.prototype.constructUMLALS = function(r, s, n, a, o) { - var h = this.cpu, - c = h.gprs; - return function() { - if (h.mmu.waitPrefetch32(c[h.PC]), !o || o()) { - h.cycles += 2, h.mmu.waitMul(n); - var t = ((4294901760 & c[a]) >>> 0) * (c[n] >>> 0), - e = (65535 & c[a]) * (c[n] >>> 0), - i = (c[s] >>> 0) + t + e; - c[s] = i, c[r] += i * (1 / 4294967296), h.cpsrN = c[r] >> 31, h.cpsrZ = !(4294967295 & c[r] || 4294967295 & c[s]) - } - } -}, ARMCoreArm.prototype.constructUMULL = function(i, r, s, n, a) { - var o = this.cpu, - h = 1 / 4294967296, - c = o.gprs; - return function() { - if (o.mmu.waitPrefetch32(c[o.PC]), !a || a()) { - ++o.cycles, o.mmu.waitMul(c[s]); - var t = ((4294901760 & c[n]) >>> 0) * (c[s] >>> 0), - e = ((65535 & c[n]) >>> 0) * (c[s] >>> 0); - c[r] = (4294967295 & t) + (4294967295 & e) & 4294967295, c[i] = t * h + e * h >>> 0 - } - } -}, ARMCoreArm.prototype.constructUMULLS = function(i, r, s, n, a) { - var o = this.cpu, - h = 1 / 4294967296, - c = o.gprs; - return function() { - if (o.mmu.waitPrefetch32(c[o.PC]), !a || a()) { - ++o.cycles, o.mmu.waitMul(c[s]); - var t = ((4294901760 & c[n]) >>> 0) * (c[s] >>> 0), - e = ((65535 & c[n]) >>> 0) * (c[s] >>> 0); - c[r] = (4294967295 & t) + (4294967295 & e) & 4294967295, c[i] = t * h + e * h >>> 0, o.cpsrN = c[i] >> 31, o.cpsrZ = !(4294967295 & c[i] || 4294967295 & c[r]) - } - } -}, ARMCoreThumb = function(t) { - this.cpu = t -}, ARMCoreThumb.prototype.constructADC = function(a, o) { - var h = this.cpu, - c = h.gprs; - return function() { - h.mmu.waitPrefetch(c[h.PC]); - var t = (c[o] >>> 0) + !!h.cpsrC, - e = c[a], - i = (e >>> 0) + t, - r = e >> 31, - s = i >> 31, - n = t >> 31; - h.cpsrN = s, h.cpsrZ = !(4294967295 & i), h.cpsrC = 4294967295 < i, h.cpsrV = r == n && r != s && n != s, c[a] = i - } -}, ARMCoreThumb.prototype.constructADD1 = function(e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - s.mmu.waitPrefetch(n[s.PC]); - var t = (n[i] >>> 0) + r; - s.cpsrN = t >> 31, s.cpsrZ = !(4294967295 & t), s.cpsrC = 4294967295 < t, s.cpsrV = !(n[i] >> 31) && (n[i] >> 31 ^ t) >> 31 && t >> 31, n[e] = t - } -}, ARMCoreThumb.prototype.constructADD2 = function(e, i) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.waitPrefetch(s[r.PC]); - var t = (s[e] >>> 0) + i; - r.cpsrN = t >> 31, r.cpsrZ = !(4294967295 & t), r.cpsrC = 4294967295 < t, r.cpsrV = !(s[e] >> 31) && (s[e] ^ t) >> 31 && (i ^ t) >> 31, s[e] = t - } -}, ARMCoreThumb.prototype.constructADD3 = function(e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - s.mmu.waitPrefetch(n[s.PC]); - var t = (n[i] >>> 0) + (n[r] >>> 0); - s.cpsrN = t >> 31, s.cpsrZ = !(4294967295 & t), s.cpsrC = 4294967295 < t, s.cpsrV = !((n[i] ^ n[r]) >> 31) && (n[i] ^ t) >> 31 && (n[r] ^ t) >> 31, n[e] = t - } -}, ARMCoreThumb.prototype.constructADD4 = function(t, e) { - var i = this.cpu, - r = i.gprs; - return function() { - i.mmu.waitPrefetch(r[i.PC]), r[t] += r[e] - } -}, ARMCoreThumb.prototype.constructADD5 = function(t, e) { - var i = this.cpu, - r = i.gprs; - return function() { - i.mmu.waitPrefetch(r[i.PC]), r[t] = (4294967292 & r[i.PC]) + e - } -}, ARMCoreThumb.prototype.constructADD6 = function(t, e) { - var i = this.cpu, - r = i.gprs; - return function() { - i.mmu.waitPrefetch(r[i.PC]), r[t] = r[i.SP] + e - } -}, ARMCoreThumb.prototype.constructADD7 = function(t) { - var e = this.cpu, - i = e.gprs; - return function() { - e.mmu.waitPrefetch(i[e.PC]), i[e.SP] += t - } -}, ARMCoreThumb.prototype.constructAND = function(t, e) { - var i = this.cpu, - r = i.gprs; - return function() { - i.mmu.waitPrefetch(r[i.PC]), r[t] = r[t] & r[e], i.cpsrN = r[t] >> 31, i.cpsrZ = !(4294967295 & r[t]) - } -}, ARMCoreThumb.prototype.constructASR1 = function(t, e, i) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.waitPrefetch(s[r.PC]), 0 == i ? (r.cpsrC = s[e] >> 31, r.cpsrC ? s[t] = 4294967295 : s[t] = 0) : (r.cpsrC = s[e] & 1 << i - 1, s[t] = s[e] >> i), r.cpsrN = s[t] >> 31, r.cpsrZ = !(4294967295 & s[t]) - } -}, ARMCoreThumb.prototype.constructASR2 = function(e, i) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.waitPrefetch(s[r.PC]); - var t = 255 & s[i]; - t && (t < 32 ? (r.cpsrC = s[e] & 1 << t - 1, s[e] >>= t) : (r.cpsrC = s[e] >> 31, r.cpsrC ? s[e] = 4294967295 : s[e] = 0)), r.cpsrN = s[e] >> 31, r.cpsrZ = !(4294967295 & s[e]) - } -}, ARMCoreThumb.prototype.constructB1 = function(t, e) { - var i = this.cpu, - r = i.gprs; - return function() { - i.mmu.waitPrefetch(r[i.PC]), e() && (r[i.PC] += t) - } -}, ARMCoreThumb.prototype.constructB2 = function(t) { - var e = this.cpu, - i = e.gprs; - return function() { - e.mmu.waitPrefetch(i[e.PC]), i[e.PC] += t - } -}, ARMCoreThumb.prototype.constructBIC = function(t, e) { - var i = this.cpu, - r = i.gprs; - return function() { - i.mmu.waitPrefetch(r[i.PC]), r[t] = r[t] & ~r[e], i.cpsrN = r[t] >> 31, i.cpsrZ = !(4294967295 & r[t]) - } -}, ARMCoreThumb.prototype.constructBL1 = function(t) { - var e = this.cpu, - i = e.gprs; - return function() { - e.mmu.waitPrefetch(i[e.PC]), i[e.LR] = i[e.PC] + t - } -}, ARMCoreThumb.prototype.constructBL2 = function(e) { - var i = this.cpu, - r = i.gprs; - return function() { - i.mmu.waitPrefetch(r[i.PC]); - var t = r[i.PC]; - r[i.PC] = r[i.LR] + (e << 1), r[i.LR] = t - 1 - } -}, ARMCoreThumb.prototype.constructBX = function(t, e) { - var i = this.cpu, - r = i.gprs; - return function() { - i.mmu.waitPrefetch(r[i.PC]), i.switchExecMode(1 & r[e]); - var t = 0; - 15 == e && (t = 2 & r[e]), r[i.PC] = r[e] & 4294967294 - t - } -}, ARMCoreThumb.prototype.constructCMN = function(e, i) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.waitPrefetch(s[r.PC]); - var t = (s[e] >>> 0) + (s[i] >>> 0); - r.cpsrN = t >> 31, r.cpsrZ = !(4294967295 & t), r.cpsrC = 4294967295 < t, r.cpsrV = s[e] >> 31 == s[i] >> 31 && s[e] >> 31 != t >> 31 && s[i] >> 31 != t >> 31 - } -}, ARMCoreThumb.prototype.constructCMP1 = function(e, i) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.waitPrefetch(s[r.PC]); - var t = s[e] - i; - r.cpsrN = t >> 31, r.cpsrZ = !(4294967295 & t), r.cpsrC = s[e] >>> 0 >= i, r.cpsrV = s[e] >> 31 && (s[e] ^ t) >> 31 - } -}, ARMCoreThumb.prototype.constructCMP2 = function(n, a) { - var o = this.cpu, - h = o.gprs; - return function() { - o.mmu.waitPrefetch(h[o.PC]); - var t = h[n], - e = h[a], - i = t - e, - r = i >> 31, - s = t >> 31; - o.cpsrN = r, o.cpsrZ = !(4294967295 & i), o.cpsrC = e >>> 0 <= t >>> 0, o.cpsrV = s != e >> 31 && s != r - } -}, ARMCoreThumb.prototype.constructCMP3 = function(e, i) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.waitPrefetch(s[r.PC]); - var t = s[e] - s[i]; - r.cpsrN = t >> 31, r.cpsrZ = !(4294967295 & t), r.cpsrC = s[e] >>> 0 >= s[i] >>> 0, r.cpsrV = (s[e] ^ s[i]) >> 31 && (s[e] ^ t) >> 31 - } -}, ARMCoreThumb.prototype.constructEOR = function(t, e) { - var i = this.cpu, - r = i.gprs; - return function() { - i.mmu.waitPrefetch(r[i.PC]), r[t] = r[t] ^ r[e], i.cpsrN = r[t] >> 31, i.cpsrZ = !(4294967295 & r[t]) - } -}, ARMCoreThumb.prototype.constructLDMIA = function(s, n) { - var a = this.cpu, - o = a.gprs; - return function() { - a.mmu.waitPrefetch(o[a.PC]); - var t, e, i = o[s], - r = 0; - for (t = 1, e = 0; e < 8; t <<= 1, ++e) n & t && (o[e] = a.mmu.load32(i), i += 4, ++r); - a.mmu.waitMulti32(i, r), 1 << s & n || (o[s] = i) - } -}, ARMCoreThumb.prototype.constructLDR1 = function(e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - s.mmu.waitPrefetch(n[s.PC]); - var t = n[i] + r; - n[e] = s.mmu.load32(t), s.mmu.wait32(t), ++s.cycles - } -}, ARMCoreThumb.prototype.constructLDR2 = function(t, e, i) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.waitPrefetch(s[r.PC]), s[t] = r.mmu.load32(s[e] + s[i]), r.mmu.wait32(s[e] + s[i]), ++r.cycles - } -}, ARMCoreThumb.prototype.constructLDR3 = function(t, e) { - var i = this.cpu, - r = i.gprs; - return function() { - i.mmu.waitPrefetch(r[i.PC]), r[t] = i.mmu.load32((4294967292 & r[i.PC]) + e), i.mmu.wait32(r[i.PC]), ++i.cycles - } -}, ARMCoreThumb.prototype.constructLDR4 = function(t, e) { - var i = this.cpu, - r = i.gprs; - return function() { - i.mmu.waitPrefetch(r[i.PC]), r[t] = i.mmu.load32(r[i.SP] + e), i.mmu.wait32(r[i.SP] + e), ++i.cycles - } -}, ARMCoreThumb.prototype.constructLDRB1 = function(e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - var t = n[i] + r; - s.mmu.waitPrefetch(n[s.PC]), n[e] = s.mmu.loadU8(t), s.mmu.wait(t), ++s.cycles - } -}, ARMCoreThumb.prototype.constructLDRB2 = function(t, e, i) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.waitPrefetch(s[r.PC]), s[t] = r.mmu.loadU8(s[e] + s[i]), r.mmu.wait(s[e] + s[i]), ++r.cycles - } -}, ARMCoreThumb.prototype.constructLDRH1 = function(e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - var t = n[i] + r; - s.mmu.waitPrefetch(n[s.PC]), n[e] = s.mmu.loadU16(t), s.mmu.wait(t), ++s.cycles - } -}, ARMCoreThumb.prototype.constructLDRH2 = function(t, e, i) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.waitPrefetch(s[r.PC]), s[t] = r.mmu.loadU16(s[e] + s[i]), r.mmu.wait(s[e] + s[i]), ++r.cycles - } -}, ARMCoreThumb.prototype.constructLDRSB = function(t, e, i) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.waitPrefetch(s[r.PC]), s[t] = r.mmu.load8(s[e] + s[i]), r.mmu.wait(s[e] + s[i]), ++r.cycles - } -}, ARMCoreThumb.prototype.constructLDRSH = function(t, e, i) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.waitPrefetch(s[r.PC]), s[t] = r.mmu.load16(s[e] + s[i]), r.mmu.wait(s[e] + s[i]), ++r.cycles - } -}, ARMCoreThumb.prototype.constructLSL1 = function(t, e, i) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.waitPrefetch(s[r.PC]), 0 == i ? s[t] = s[e] : (r.cpsrC = s[e] & 1 << 32 - i, s[t] = s[e] << i), r.cpsrN = s[t] >> 31, r.cpsrZ = !(4294967295 & s[t]) - } -}, ARMCoreThumb.prototype.constructLSL2 = function(e, i) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.waitPrefetch(s[r.PC]); - var t = 255 & s[i]; - t && (t < 32 ? (r.cpsrC = s[e] & 1 << 32 - t, s[e] <<= t) : (r.cpsrC = 32 < t ? 0 : 1 & s[e], s[e] = 0)), r.cpsrN = s[e] >> 31, r.cpsrZ = !(4294967295 & s[e]) - } -}, ARMCoreThumb.prototype.constructLSR1 = function(t, e, i) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.waitPrefetch(s[r.PC]), 0 == i ? (r.cpsrC = s[e] >> 31, s[t] = 0) : (r.cpsrC = s[e] & 1 << i - 1, s[t] = s[e] >>> i), r.cpsrN = 0, r.cpsrZ = !(4294967295 & s[t]) - } -}, ARMCoreThumb.prototype.constructLSR2 = function(e, i) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.waitPrefetch(s[r.PC]); - var t = 255 & s[i]; - t && (t < 32 ? (r.cpsrC = s[e] & 1 << t - 1, s[e] >>>= t) : (r.cpsrC = 32 < t ? 0 : s[e] >> 31, s[e] = 0)), r.cpsrN = s[e] >> 31, r.cpsrZ = !(4294967295 & s[e]) - } -}, ARMCoreThumb.prototype.constructMOV1 = function(t, e) { - var i = this.cpu, - r = i.gprs; - return function() { - i.mmu.waitPrefetch(r[i.PC]), r[t] = e, i.cpsrN = e >> 31, i.cpsrZ = !(4294967295 & e) - } -}, ARMCoreThumb.prototype.constructMOV2 = function(e, i, t) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.waitPrefetch(s[r.PC]); - var t = s[i]; - r.cpsrN = t >> 31, r.cpsrZ = !(4294967295 & t), r.cpsrC = 0, r.cpsrV = 0, s[e] = t - } -}, ARMCoreThumb.prototype.constructMOV3 = function(t, e) { - var i = this.cpu, - r = i.gprs; - return function() { - i.mmu.waitPrefetch(r[i.PC]), r[t] = r[e] - } -}, ARMCoreThumb.prototype.constructMUL = function(i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - if (s.mmu.waitPrefetch(n[s.PC]), s.mmu.waitMul(n[r]), 4294901760 & n[r] && 4294901760 & n[i]) { - var t = (4294901760 & n[i]) * n[r] & 4294967295, - e = (65535 & n[i]) * n[r] & 4294967295; - n[i] = t + e & 4294967295 - } else n[i] *= n[r]; - s.cpsrN = n[i] >> 31, s.cpsrZ = !(4294967295 & n[i]) - } -}, ARMCoreThumb.prototype.constructMVN = function(t, e) { - var i = this.cpu, - r = i.gprs; - return function() { - i.mmu.waitPrefetch(r[i.PC]), r[t] = ~r[e], i.cpsrN = r[t] >> 31, i.cpsrZ = !(4294967295 & r[t]) - } -}, ARMCoreThumb.prototype.constructNEG = function(e, i) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.waitPrefetch(s[r.PC]); - var t = -s[i]; - r.cpsrN = t >> 31, r.cpsrZ = !(4294967295 & t), r.cpsrC = t >>> 0 <= 0, r.cpsrV = s[i] >> 31 && t >> 31, s[e] = t - } -}, ARMCoreThumb.prototype.constructORR = function(t, e) { - var i = this.cpu, - r = i.gprs; - return function() { - i.mmu.waitPrefetch(r[i.PC]), r[t] = r[t] | r[e], i.cpsrN = r[t] >> 31, i.cpsrZ = !(4294967295 & r[t]) - } -}, ARMCoreThumb.prototype.constructPOP = function(s, n) { - var a = this.cpu, - o = a.gprs; - return function() { - a.mmu.waitPrefetch(o[a.PC]), ++a.cycles; - var t, e, i = o[a.SP], - r = 0; - for (t = 1, e = 0; e < 8; t <<= 1, ++e) s & t && (a.mmu.waitSeq32(i), o[e] = a.mmu.load32(i), i += 4, ++r); - n && (o[a.PC] = 4294967294 & a.mmu.load32(i), i += 4, ++r), a.mmu.waitMulti32(i, r), o[a.SP] = i - } -}, ARMCoreThumb.prototype.constructPUSH = function(s, n) { - var a = this.cpu, - o = a.gprs; - return function() { - var t, e, i = o[a.SP] - 4, - r = 0; - for (a.mmu.waitPrefetch(o[a.PC]), n && (a.mmu.store32(i, o[a.LR]), i -= 4, ++r), t = 128, e = 7; t; t >>= 1, --e) - if (s & t) { - a.mmu.store32(i, o[e]), i -= 4, ++r; - break - } - for (t >>= 1, --e; t; t >>= 1, --e) s & t && (a.mmu.store32(i, o[e]), i -= 4, ++r); - a.mmu.waitMulti32(i, r), o[a.SP] = i + 4 - } -}, ARMCoreThumb.prototype.constructROR = function(i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - s.mmu.waitPrefetch(n[s.PC]); - var t = 255 & n[r]; - if (t) { - var e = 31 & t; - 0 < e ? (s.cpsrC = n[i] & 1 << e - 1, n[i] = n[i] >>> e | n[i] << 32 - e) : s.cpsrC = n[i] >> 31 - } - s.cpsrN = n[i] >> 31, s.cpsrZ = !(4294967295 & n[i]) - } -}, ARMCoreThumb.prototype.constructSBC = function(i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - s.mmu.waitPrefetch(n[s.PC]); - var t = (n[r] >>> 0) + !s.cpsrC, - e = (n[i] >>> 0) - t; - s.cpsrN = e >> 31, s.cpsrZ = !(4294967295 & e), s.cpsrC = n[i] >>> 0 >= e >>> 0, s.cpsrV = (n[i] ^ t) >> 31 && (n[i] ^ e) >> 31, n[i] = e - } -}, ARMCoreThumb.prototype.constructSTMIA = function(s, n) { - var a = this.cpu, - o = a.gprs; - return function() { - a.mmu.wait(o[a.PC]); - var t, e, i = o[s], - r = 0; - for (t = 1, e = 0; e < 8; t <<= 1, ++e) - if (n & t) { - a.mmu.store32(i, o[e]), i += 4, ++r; - break - } - for (t <<= 1, ++e; e < 8; t <<= 1, ++e) n & t && (a.mmu.store32(i, o[e]), i += 4, ++r); - a.mmu.waitMulti32(i, r), o[s] = i - } -}, ARMCoreThumb.prototype.constructSTR1 = function(e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - var t = n[i] + r; - s.mmu.store32(t, n[e]), s.mmu.wait(n[s.PC]), s.mmu.wait32(t) - } -}, ARMCoreThumb.prototype.constructSTR2 = function(t, e, i) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.store32(s[e] + s[i], s[t]), r.mmu.wait(s[r.PC]), r.mmu.wait32(s[e] + s[i]) - } -}, ARMCoreThumb.prototype.constructSTR3 = function(t, e) { - var i = this.cpu, - r = i.gprs; - return function() { - i.mmu.store32(r[i.SP] + e, r[t]), i.mmu.wait(r[i.PC]), i.mmu.wait32(r[i.SP] + e) - } -}, ARMCoreThumb.prototype.constructSTRB1 = function(e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - var t = n[i] + r; - s.mmu.store8(t, n[e]), s.mmu.wait(n[s.PC]), s.mmu.wait(t) - } -}, ARMCoreThumb.prototype.constructSTRB2 = function(t, e, i) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.store8(s[e] + s[i], s[t]), r.mmu.wait(s[r.PC]), r.mmu.wait(s[e] + s[i]) - } -}, ARMCoreThumb.prototype.constructSTRH1 = function(e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - var t = n[i] + r; - s.mmu.store16(t, n[e]), s.mmu.wait(n[s.PC]), s.mmu.wait(t) - } -}, ARMCoreThumb.prototype.constructSTRH2 = function(t, e, i) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.store16(s[e] + s[i], s[t]), r.mmu.wait(s[r.PC]), r.mmu.wait(s[e] + s[i]) - } -}, ARMCoreThumb.prototype.constructSUB1 = function(e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - s.mmu.waitPrefetch(n[s.PC]); - var t = n[i] - r; - s.cpsrN = t >> 31, s.cpsrZ = !(4294967295 & t), s.cpsrC = n[i] >>> 0 >= r, s.cpsrV = n[i] >> 31 && (n[i] ^ t) >> 31, n[e] = t - } -}, ARMCoreThumb.prototype.constructSUB2 = function(e, i) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.waitPrefetch(s[r.PC]); - var t = s[e] - i; - r.cpsrN = t >> 31, r.cpsrZ = !(4294967295 & t), r.cpsrC = s[e] >>> 0 >= i, r.cpsrV = s[e] >> 31 && (s[e] ^ t) >> 31, s[e] = t - } -}, ARMCoreThumb.prototype.constructSUB3 = function(e, i, r) { - var s = this.cpu, - n = s.gprs; - return function() { - s.mmu.waitPrefetch(n[s.PC]); - var t = n[i] - n[r]; - s.cpsrN = t >> 31, s.cpsrZ = !(4294967295 & t), s.cpsrC = n[i] >>> 0 >= n[r] >>> 0, s.cpsrV = n[i] >> 31 != n[r] >> 31 && n[i] >> 31 != t >> 31, n[e] = t - } -}, ARMCoreThumb.prototype.constructSWI = function(t) { - var e = this.cpu, - i = e.gprs; - return function() { - e.irq.swi(t), e.mmu.waitPrefetch(i[e.PC]) - } -}, ARMCoreThumb.prototype.constructTST = function(e, i) { - var r = this.cpu, - s = r.gprs; - return function() { - r.mmu.waitPrefetch(s[r.PC]); - var t = s[e] & s[i]; - r.cpsrN = t >> 31, r.cpsrZ = !(4294967295 & t) - } -}, MemoryView.prototype.resetMask = function() { - this.mask8 = 4294967295 & this.mask, this.mask16 = 4294967294 & this.mask, this.mask32 = 4294967292 & this.mask -}, MemoryView.prototype.load8 = function(t) { - return this.view.getInt8(t & this.mask8) -}, MemoryView.prototype.load16 = function(t) { - return this.view.getInt16(t & this.mask, !0) -}, MemoryView.prototype.loadU8 = function(t) { - return this.view.getUint8(t & this.mask8) -}, MemoryView.prototype.loadU16 = function(t) { - return this.view.getUint16(t & this.mask, !0) -}, MemoryView.prototype.load32 = function(t) { - var e = (3 & t) << 3, - i = this.view.getInt32(t & this.mask32, !0); - return i >>> e | i << 32 - e -}, MemoryView.prototype.store8 = function(t, e) { - this.view.setInt8(t & this.mask8, e) -}, MemoryView.prototype.store16 = function(t, e) { - this.view.setInt16(t & this.mask16, e, !0) -}, MemoryView.prototype.store32 = function(t, e) { - this.view.setInt32(t & this.mask32, e, !0) -}, MemoryView.prototype.invalidatePage = function(t) {}, MemoryView.prototype.replaceData = function(t, e) { - this.buffer = t, this.view = new DataView(this.buffer, "number" == typeof e ? e : 0), this.icache && (this.icache = new Array(this.icache.length)) -}, MemoryBlock.prototype = Object.create(MemoryView.prototype), MemoryBlock.prototype.invalidatePage = function(t) { - var e = this.icache[(t & this.mask) >> this.ICACHE_PAGE_BITS]; - e && (e.invalid = !0) -}, ROMView.prototype = Object.create(MemoryView.prototype), ROMView.prototype.store8 = function(t, e) {}, ROMView.prototype.store16 = function(t, e) { - t < 202 && 196 <= t && (this.gpio || (this.gpio = this.mmu.allocGPIO(this)), this.gpio.store16(t, e)) -}, ROMView.prototype.store32 = function(t, e) { - t < 202 && 196 <= t && (this.gpio || (this.gpio = this.mmu.allocGPIO(this)), this.gpio.store32(t, e)) -}, BIOSView.prototype = Object.create(MemoryView.prototype), BIOSView.prototype.load8 = function(t) { - return t >= this.buffer.byteLength ? -1 : this.view.getInt8(t) -}, BIOSView.prototype.load16 = function(t) { - return t >= this.buffer.byteLength ? -1 : this.view.getInt16(t, !0) -}, BIOSView.prototype.loadU8 = function(t) { - return t >= this.buffer.byteLength ? -1 : this.view.getUint8(t) -}, BIOSView.prototype.loadU16 = function(t) { - return t >= this.buffer.byteLength ? -1 : this.view.getUint16(t, !0) -}, BIOSView.prototype.load32 = function(t) { - return t >= this.buffer.byteLength ? -1 : this.view.getInt32(t, !0) -}, BIOSView.prototype.store8 = function(t, e) {}, BIOSView.prototype.store16 = function(t, e) {}, BIOSView.prototype.store32 = function(t, e) {}, BadMemory.prototype.load8 = function(t) { - return this.mmu.load8(this.cpu.gprs[this.cpu.PC] - this.cpu.instructionWidth + (3 & t)) -}, BadMemory.prototype.load16 = function(t) { - return this.mmu.load16(this.cpu.gprs[this.cpu.PC] - this.cpu.instructionWidth + (2 & t)) -}, BadMemory.prototype.loadU8 = function(t) { - return this.mmu.loadU8(this.cpu.gprs[this.cpu.PC] - this.cpu.instructionWidth + (3 & t)) -}, BadMemory.prototype.loadU16 = function(t) { - return this.mmu.loadU16(this.cpu.gprs[this.cpu.PC] - this.cpu.instructionWidth + (2 & t)) -}, BadMemory.prototype.load32 = function(t) { - if (this.cpu.execMode == this.cpu.MODE_ARM) return this.mmu.load32(this.cpu.gprs[this.cpu.gprs.PC] - this.cpu.instructionWidth); - var e = this.mmu.loadU16(this.cpu.gprs[this.cpu.PC] - this.cpu.instructionWidth); - return e | e << 16 -}, BadMemory.prototype.store8 = function(t, e) {}, BadMemory.prototype.store16 = function(t, e) {}, BadMemory.prototype.store32 = function(t, e) {}, BadMemory.prototype.invalidatePage = function(t) {}, GameBoyAdvanceMMU.prototype.mmap = function(t, e) { - this.memory[t] = e -}, GameBoyAdvanceMMU.prototype.clear = function() { - this.badMemory = new BadMemory(this, this.cpu), this.memory = [this.bios, this.badMemory, new MemoryBlock(this.SIZE_WORKING_RAM, 9), new MemoryBlock(this.SIZE_WORKING_IRAM, 7), null, null, null, null, this.badMemory, this.badMemory, this.badMemory, this.badMemory, this.badMemory, this.badMemory, this.badMemory, this.badMemory]; - for (var t = 16; t < 256; ++t) this.memory[t] = this.badMemory; - this.waitstates = this.WAITSTATES.slice(0), this.waitstatesSeq = this.WAITSTATES_SEQ.slice(0), this.waitstates32 = this.WAITSTATES_32.slice(0), this.waitstatesSeq32 = this.WAITSTATES_SEQ_32.slice(0), this.waitstatesPrefetch = this.WAITSTATES_SEQ.slice(0), this.waitstatesPrefetch32 = this.WAITSTATES_SEQ_32.slice(0), this.cart = null, this.save = null, this.DMA_REGISTER = [this.core.io.DMA0CNT_HI >> 1, this.core.io.DMA1CNT_HI >> 1, this.core.io.DMA2CNT_HI >> 1, this.core.io.DMA3CNT_HI >> 1] -}, GameBoyAdvanceMMU.prototype.freeze = function() { - return { - ram: Serializer.prefix(this.memory[this.REGION_WORKING_RAM].buffer), - iram: Serializer.prefix(this.memory[this.REGION_WORKING_IRAM].buffer) - } -}, GameBoyAdvanceMMU.prototype.defrost = function(t) { - this.memory[this.REGION_WORKING_RAM].replaceData(t.ram), this.memory[this.REGION_WORKING_IRAM].replaceData(t.iram) -}, GameBoyAdvanceMMU.prototype.loadBios = function(t, e) { - this.bios = new BIOSView(t), this.bios.real = !!e -}, GameBoyAdvanceMMU.prototype.loadRom = function(t, e) { - var i = { - title: null, - code: null, - maker: null, - memory: t, - saveType: null - }, - r = new ROMView(t); - if (150 != r.view.getUint8(178)) return null; - if ((r.mmu = this).memory[this.REGION_CART0] = r, this.memory[this.REGION_CART1] = r, this.memory[this.REGION_CART2] = r, 16777216 < t.byteLength) { - var s = new ROMView(t, 16777216); - this.memory[this.REGION_CART0 + 1] = s, this.memory[this.REGION_CART1 + 1] = s, this.memory[this.REGION_CART2 + 1] = s - } - if (e) { - for (var n = "", a = 0; a < 12; ++a) { - if (!(c = r.loadU8(a + 160))) break; - n += String.fromCharCode(c) - } - i.title = n; - var o = ""; - for (a = 0; a < 4; ++a) { - if (!(c = r.loadU8(a + 172))) break; - o += String.fromCharCode(c) - } - i.code = o; - var h = ""; - for (a = 0; a < 2; ++a) { - var c; - if (!(c = r.loadU8(a + 176))) break; - h += String.fromCharCode(c) - } - i.maker = h; - var u, d = "", - p = !1; - for (a = 228; a < t.byteLength && !p; ++a) switch (d += u = String.fromCharCode(r.loadU8(a))) { - case "F": - case "FL": - case "FLA": - case "FLAS": - case "FLASH": - case "FLASH_": - case "FLASH5": - case "FLASH51": - case "FLASH512": - case "FLASH512_": - case "FLASH1": - case "FLASH1M": - case "FLASH1M_": - case "S": - case "SR": - case "SRA": - case "SRAM": - case "SRAM_": - case "E": - case "EE": - case "EEP": - case "EEPR": - case "EEPRO": - case "EEPROM": - case "EEPROM_": - break; - case "FLASH_V": - case "FLASH512_V": - case "FLASH1M_V": - case "SRAM_V": - case "EEPROM_V": - p = !0; - break; - default: - d = u - } - if (p) switch (i.saveType = d) { - case "FLASH_V": - case "FLASH512_V": - this.save = this.memory[this.REGION_CART_SRAM] = new FlashSavedata(this.SIZE_CART_FLASH512); - break; - case "FLASH1M_V": - this.save = this.memory[this.REGION_CART_SRAM] = new FlashSavedata(this.SIZE_CART_FLASH1M); - break; - case "SRAM_V": - this.save = this.memory[this.REGION_CART_SRAM] = new SRAMSavedata(this.SIZE_CART_SRAM); - break; - case "EEPROM_V": - this.save = this.memory[this.REGION_CART2 + 1] = new EEPROMSavedata(this.SIZE_CART_EEPROM, this) - } - this.save || (this.save = this.memory[this.REGION_CART_SRAM] = new SRAMSavedata(this.SIZE_CART_SRAM)) - } - return this.cart = i -}, GameBoyAdvanceMMU.prototype.loadSavedata = function(t) { - this.save.replaceData(t) -}, GameBoyAdvanceMMU.prototype.load8 = function(t) { - return this.memory[t >>> this.BASE_OFFSET].load8(16777215 & t) -}, GameBoyAdvanceMMU.prototype.load16 = function(t) { - return this.memory[t >>> this.BASE_OFFSET].load16(16777215 & t) -}, GameBoyAdvanceMMU.prototype.load32 = function(t) { - return this.memory[t >>> this.BASE_OFFSET].load32(16777215 & t) -}, GameBoyAdvanceMMU.prototype.loadU8 = function(t) { - return this.memory[t >>> this.BASE_OFFSET].loadU8(16777215 & t) -}, GameBoyAdvanceMMU.prototype.loadU16 = function(t) { - return this.memory[t >>> this.BASE_OFFSET].loadU16(16777215 & t) -}, GameBoyAdvanceMMU.prototype.store8 = function(t, e) { - var i = 16777215 & t, - r = this.memory[t >>> this.BASE_OFFSET]; - r.store8(i, e), r.invalidatePage(i) -}, GameBoyAdvanceMMU.prototype.store16 = function(t, e) { - var i = 16777214 & t, - r = this.memory[t >>> this.BASE_OFFSET]; - r.store16(i, e), r.invalidatePage(i) -}, GameBoyAdvanceMMU.prototype.store32 = function(t, e) { - var i = 16777212 & t, - r = this.memory[t >>> this.BASE_OFFSET]; - r.store32(i, e), r.invalidatePage(i), r.invalidatePage(i + 2) -}, GameBoyAdvanceMMU.prototype.waitPrefetch = function(t) { - this.cpu.cycles += 1 + this.waitstatesPrefetch[t >>> this.BASE_OFFSET] -}, GameBoyAdvanceMMU.prototype.waitPrefetch32 = function(t) { - this.cpu.cycles += 1 + this.waitstatesPrefetch32[t >>> this.BASE_OFFSET] -}, GameBoyAdvanceMMU.prototype.wait = function(t) { - this.cpu.cycles += 1 + this.waitstates[t >>> this.BASE_OFFSET] -}, GameBoyAdvanceMMU.prototype.wait32 = function(t) { - this.cpu.cycles += 1 + this.waitstates32[t >>> this.BASE_OFFSET] -}, GameBoyAdvanceMMU.prototype.waitSeq = function(t) { - this.cpu.cycles += 1 + this.waitstatesSeq[t >>> this.BASE_OFFSET] -}, GameBoyAdvanceMMU.prototype.waitSeq32 = function(t) { - this.cpu.cycles += 1 + this.waitstatesSeq32[t >>> this.BASE_OFFSET] -}, GameBoyAdvanceMMU.prototype.waitMul = function(t) { - this.cpu.cycles += !0 & t || !(4294967040 & t) ? 1 : !0 & t || !(4294901760 & t) ? 2 : !0 & t || !(4278190080 & t) ? 3 : 4 -}, GameBoyAdvanceMMU.prototype.waitMulti32 = function(t, e) { - this.cpu.cycles += 1 + this.waitstates32[t >>> this.BASE_OFFSET], this.cpu.cycles += (1 + this.waitstatesSeq32[t >>> this.BASE_OFFSET]) * (e - 1) -}, GameBoyAdvanceMMU.prototype.addressToPage = function(t, e) { - return e >> this.memory[t].ICACHE_PAGE_BITS -}, GameBoyAdvanceMMU.prototype.accessPage = function(t, e) { - var i = this.memory[t], - r = i.icache[e]; - return r && !r.invalid || (r = { - thumb: new Array(1 << i.ICACHE_PAGE_BITS), - arm: new Array(1 << i.ICACHE_PAGE_BITS - 1), - invalid: !1 - }, i.icache[e] = r), r -}, GameBoyAdvanceMMU.prototype.scheduleDma = function(t, e) { - switch (e.timing) { - case this.DMA_TIMING_NOW: - this.serviceDma(t, e); - break; - case this.DMA_TIMING_HBLANK: - case this.DMA_TIMING_VBLANK: - break; - case this.DMA_TIMING_CUSTOM: - switch (t) { - case 0: - this.core.WARN("Discarding invalid DMA0 scheduling"); - break; - case 1: - case 2: - this.cpu.irq.audio.scheduleFIFODma(t, e); - break; - case 3: - this.cpu.irq.video.scheduleVCaptureDma(dma, e) - } - } -}, GameBoyAdvanceMMU.prototype.runHblankDmas = function() { - for (var t, e = 0; e < this.cpu.irq.dma.length; ++e)(t = this.cpu.irq.dma[e]).enable && t.timing == this.DMA_TIMING_HBLANK && this.serviceDma(e, t) -}, GameBoyAdvanceMMU.prototype.runVblankDmas = function() { - for (var t, e = 0; e < this.cpu.irq.dma.length; ++e)(t = this.cpu.irq.dma[e]).enable && t.timing == this.DMA_TIMING_VBLANK && this.serviceDma(e, t) -}, GameBoyAdvanceMMU.prototype.serviceDma = function(t, e) { - if (e.enable) { - var i, r = e.width, - s = this.DMA_OFFSET[e.srcControl] * r, - n = this.DMA_OFFSET[e.dstControl] * r, - a = e.nextCount, - o = e.nextSource & this.OFFSET_MASK, - h = e.nextDest & this.OFFSET_MASK, - c = e.nextSource >>> this.BASE_OFFSET, - u = e.nextDest >>> this.BASE_OFFSET, - d = this.memory[c], - p = this.memory[u], - l = null, - f = null, - m = 4294967295, - y = 4294967295; - if (p.ICACHE_PAGE_BITS) - for (var v = h + a * r >> p.ICACHE_PAGE_BITS, A = h >> p.ICACHE_PAGE_BITS; A <= v; ++A) p.invalidatePage(A << p.ICACHE_PAGE_BITS); - if (u != this.REGION_WORKING_RAM && u != this.REGION_WORKING_IRAM || (f = p.view, y = p.mask), c != this.REGION_WORKING_RAM && c != this.REGION_WORKING_IRAM && c != this.REGION_CART0 && c != this.REGION_CART1 || (l = d.view, m = d.mask), d && p) - if (l && f) - if (4 == r) - for (o &= 4294967292, h &= 4294967292; a--;) i = l.getInt32(o & m), f.setInt32(h & y, i), o += s, h += n; - else - for (; a--;) i = l.getUint16(o & m), f.setUint16(h & y, i), o += s, h += n; - else if (l) - if (4 == r) - for (o &= 4294967292, h &= 4294967292; a--;) i = l.getInt32(o & m, !0), p.store32(h, i), o += s, h += n; - else - for (; a--;) i = l.getUint16(o & m, !0), p.store16(h, i), o += s, h += n; - else if (4 == r) - for (o &= 4294967292, h &= 4294967292; a--;) i = d.load32(o), p.store32(h, i), o += s, h += n; - else - for (; a--;) i = d.loadU16(o), p.store16(h, i), o += s, h += n; - else this.core.WARN("Invalid DMA"); if (e.doIrq && (e.nextIRQ = this.cpu.cycles + 2, e.nextIRQ += 4 == r ? this.waitstates32[c] + this.waitstates32[u] : this.waitstates[c] + this.waitstates[u], e.nextIRQ += (e.count - 1) * (4 == r ? this.waitstatesSeq32[c] + this.waitstatesSeq32[u] : this.waitstatesSeq[c] + this.waitstatesSeq[u])), e.nextSource = o | c << this.BASE_OFFSET, e.nextDest = h | u << this.BASE_OFFSET, e.nextCount = a, e.repeat) e.nextCount = e.count, e.dstControl == this.DMA_INCREMENT_RELOAD && (e.nextDest = e.dest), this.scheduleDma(t, e); - else e.enable = !1, this.memory[this.REGION_IO].registers[this.DMA_REGISTER[t]] &= 32736 - } -}, GameBoyAdvanceMMU.prototype.adjustTimings = function(t) { - var e = 3 & t, - i = (12 & t) >> 2, - r = (16 & t) >> 4, - s = (96 & t) >> 5, - n = (128 & t) >> 7, - a = (768 & t) >> 8, - o = (1024 & t) >> 10, - h = 16384 & t; - this.waitstates[this.REGION_CART_SRAM] = this.ROM_WS[e], this.waitstatesSeq[this.REGION_CART_SRAM] = this.ROM_WS[e], this.waitstates32[this.REGION_CART_SRAM] = this.ROM_WS[e], this.waitstatesSeq32[this.REGION_CART_SRAM] = this.ROM_WS[e], this.waitstates[this.REGION_CART0] = this.waitstates[this.REGION_CART0 + 1] = this.ROM_WS[i], this.waitstates[this.REGION_CART1] = this.waitstates[this.REGION_CART1 + 1] = this.ROM_WS[s], this.waitstates[this.REGION_CART2] = this.waitstates[this.REGION_CART2 + 1] = this.ROM_WS[a], this.waitstatesSeq[this.REGION_CART0] = this.waitstatesSeq[this.REGION_CART0 + 1] = this.ROM_WS_SEQ[0][r], this.waitstatesSeq[this.REGION_CART1] = this.waitstatesSeq[this.REGION_CART1 + 1] = this.ROM_WS_SEQ[1][n], this.waitstatesSeq[this.REGION_CART2] = this.waitstatesSeq[this.REGION_CART2 + 1] = this.ROM_WS_SEQ[2][o], this.waitstates32[this.REGION_CART0] = this.waitstates32[this.REGION_CART0 + 1] = this.waitstates[this.REGION_CART0] + 1 + this.waitstatesSeq[this.REGION_CART0], this.waitstates32[this.REGION_CART1] = this.waitstates32[this.REGION_CART1 + 1] = this.waitstates[this.REGION_CART1] + 1 + this.waitstatesSeq[this.REGION_CART1], this.waitstates32[this.REGION_CART2] = this.waitstates32[this.REGION_CART2 + 1] = this.waitstates[this.REGION_CART2] + 1 + this.waitstatesSeq[this.REGION_CART2], this.waitstatesSeq32[this.REGION_CART0] = this.waitstatesSeq32[this.REGION_CART0 + 1] = 2 * this.waitstatesSeq[this.REGION_CART0] + 1, this.waitstatesSeq32[this.REGION_CART1] = this.waitstatesSeq32[this.REGION_CART1 + 1] = 2 * this.waitstatesSeq[this.REGION_CART1] + 1, this.waitstatesSeq32[this.REGION_CART2] = this.waitstatesSeq32[this.REGION_CART2 + 1] = 2 * this.waitstatesSeq[this.REGION_CART2] + 1, h ? (this.waitstatesPrefetch[this.REGION_CART0] = this.waitstatesPrefetch[this.REGION_CART0 + 1] = 0, this.waitstatesPrefetch[this.REGION_CART1] = this.waitstatesPrefetch[this.REGION_CART1 + 1] = 0, this.waitstatesPrefetch[this.REGION_CART2] = this.waitstatesPrefetch[this.REGION_CART2 + 1] = 0, this.waitstatesPrefetch32[this.REGION_CART0] = this.waitstatesPrefetch32[this.REGION_CART0 + 1] = 0, this.waitstatesPrefetch32[this.REGION_CART1] = this.waitstatesPrefetch32[this.REGION_CART1 + 1] = 0, this.waitstatesPrefetch32[this.REGION_CART2] = this.waitstatesPrefetch32[this.REGION_CART2 + 1] = 0) : (this.waitstatesPrefetch[this.REGION_CART0] = this.waitstatesPrefetch[this.REGION_CART0 + 1] = this.waitstatesSeq[this.REGION_CART0], this.waitstatesPrefetch[this.REGION_CART1] = this.waitstatesPrefetch[this.REGION_CART1 + 1] = this.waitstatesSeq[this.REGION_CART1], this.waitstatesPrefetch[this.REGION_CART2] = this.waitstatesPrefetch[this.REGION_CART2 + 1] = this.waitstatesSeq[this.REGION_CART2], this.waitstatesPrefetch32[this.REGION_CART0] = this.waitstatesPrefetch32[this.REGION_CART0 + 1] = this.waitstatesSeq32[this.REGION_CART0], this.waitstatesPrefetch32[this.REGION_CART1] = this.waitstatesPrefetch32[this.REGION_CART1 + 1] = this.waitstatesSeq32[this.REGION_CART1], this.waitstatesPrefetch32[this.REGION_CART2] = this.waitstatesPrefetch32[this.REGION_CART2 + 1] = this.waitstatesSeq32[this.REGION_CART2]) -}, GameBoyAdvanceMMU.prototype.saveNeedsFlush = function() { - return this.save.writePending -}, GameBoyAdvanceMMU.prototype.flushSave = function() { - this.save.writePending = !1 -}, GameBoyAdvanceMMU.prototype.allocGPIO = function(t) { - return new GameBoyAdvanceGPIO(this.core, t) -}, GameBoyAdvanceIO.prototype.clear = function() { - this.registers = new Uint16Array(this.cpu.mmu.SIZE_IO), this.registers[this.DISPCNT >> 1] = this.DEFAULT_DISPCNT, this.registers[this.SOUNDBIAS >> 1] = this.DEFAULT_SOUNDBIAS, this.registers[this.BG2PA >> 1] = this.DEFAULT_BGPA, this.registers[this.BG2PD >> 1] = this.DEFAULT_BGPD, this.registers[this.BG3PA >> 1] = this.DEFAULT_BGPA, this.registers[this.BG3PD >> 1] = this.DEFAULT_BGPD, this.registers[this.RCNT >> 1] = this.DEFAULT_RCNT -}, GameBoyAdvanceIO.prototype.freeze = function() { - return { - registers: Serializer.prefix(this.registers.buffer) - } -}, GameBoyAdvanceIO.prototype.defrost = function(t) { - this.registers = new Uint16Array(t.registers); - for (var e = 0; e <= this.BLDY; e += 2) this.store16(this.registers[e >> 1]) -}, GameBoyAdvanceIO.prototype.load8 = function(t) { - throw "Unimplmeneted unaligned I/O access" -}, GameBoyAdvanceIO.prototype.load16 = function(t) { - return this.loadU16(t) << 16 >> 16 -}, GameBoyAdvanceIO.prototype.load32 = function(t) { - switch (t &= 4294967292) { - case this.DMA0CNT_LO: - case this.DMA1CNT_LO: - case this.DMA2CNT_LO: - case this.DMA3CNT_LO: - return this.loadU16(2 | t) << 16; - case this.IME: - return 65535 & this.loadU16(t); - case this.JOY_RECV: - case this.JOY_TRANS: - return this.core.STUB("Unimplemented JOY register read: 0x" + t.toString(16)), 0 - } - return this.loadU16(t) | this.loadU16(2 | t) << 16 -}, GameBoyAdvanceIO.prototype.loadU8 = function(t) { - var e = 1 & t; - return this.loadU16(65534 & t) >>> (e << 3) & 255 -}, GameBoyAdvanceIO.prototype.loadU16 = function(t) { - switch (t) { - case this.DISPCNT: - case this.BG0CNT: - case this.BG1CNT: - case this.BG2CNT: - case this.BG3CNT: - case this.WININ: - case this.WINOUT: - case this.SOUND1CNT_LO: - case this.SOUND3CNT_LO: - case this.SOUNDCNT_LO: - case this.SOUNDCNT_HI: - case this.SOUNDBIAS: - case this.BLDCNT: - case this.BLDALPHA: - case this.TM0CNT_HI: - case this.TM1CNT_HI: - case this.TM2CNT_HI: - case this.TM3CNT_HI: - case this.DMA0CNT_HI: - case this.DMA1CNT_HI: - case this.DMA2CNT_HI: - case this.DMA3CNT_HI: - case this.RCNT: - case this.WAITCNT: - case this.IE: - case this.IF: - case this.IME: - case this.POSTFLG: - break; - case this.DISPSTAT: - return this.registers[t >> 1] | this.video.readDisplayStat(); - case this.VCOUNT: - return this.video.vcount; - case this.SOUND1CNT_HI: - case this.SOUND2CNT_LO: - return 65472 & this.registers[t >> 1]; - case this.SOUND1CNT_X: - case this.SOUND2CNT_HI: - case this.SOUND3CNT_X: - return 16384 & this.registers[t >> 1]; - case this.SOUND3CNT_HI: - return 57344 & this.registers[t >> 1]; - case this.SOUND4CNT_LO: - return 65280 & this.registers[t >> 1]; - case this.SOUND4CNT_HI: - return 16639 & this.registers[t >> 1]; - case this.SOUNDCNT_X: - return this.core.STUB("Unimplemented sound register read: SOUNDCNT_X"), 0 | this.registers[t >> 1]; - case this.TM0CNT_LO: - return this.cpu.irq.timerRead(0); - case this.TM1CNT_LO: - return this.cpu.irq.timerRead(1); - case this.TM2CNT_LO: - return this.cpu.irq.timerRead(2); - case this.TM3CNT_LO: - return this.cpu.irq.timerRead(3); - case this.SIOCNT: - return this.sio.readSIOCNT(); - case this.KEYINPUT: - return this.keypad.pollGamepads(), this.keypad.currentDown; - case this.KEYCNT: - return this.core.STUB("Unimplemented I/O register read: KEYCNT"), 0; - case this.BG0HOFS: - case this.BG0VOFS: - case this.BG1HOFS: - case this.BG1VOFS: - case this.BG2HOFS: - case this.BG2VOFS: - case this.BG3HOFS: - case this.BG3VOFS: - case this.BG2PA: - case this.BG2PB: - case this.BG2PC: - case this.BG2PD: - case this.BG3PA: - case this.BG3PB: - case this.BG3PC: - case this.BG3PD: - case this.BG2X_LO: - case this.BG2X_HI: - case this.BG2Y_LO: - case this.BG2Y_HI: - case this.BG3X_LO: - case this.BG3X_HI: - case this.BG3Y_LO: - case this.BG3Y_HI: - case this.WIN0H: - case this.WIN1H: - case this.WIN0V: - case this.WIN1V: - case this.BLDY: - case this.DMA0SAD_LO: - case this.DMA0SAD_HI: - case this.DMA0DAD_LO: - case this.DMA0DAD_HI: - case this.DMA0CNT_LO: - case this.DMA1SAD_LO: - case this.DMA1SAD_HI: - case this.DMA1DAD_LO: - case this.DMA1DAD_HI: - case this.DMA1CNT_LO: - case this.DMA2SAD_LO: - case this.DMA2SAD_HI: - case this.DMA2DAD_LO: - case this.DMA2DAD_HI: - case this.DMA2CNT_LO: - case this.DMA3SAD_LO: - case this.DMA3SAD_HI: - case this.DMA3DAD_LO: - case this.DMA3DAD_HI: - case this.DMA3CNT_LO: - case this.FIFO_A_LO: - case this.FIFO_A_HI: - case this.FIFO_B_LO: - case this.FIFO_B_HI: - return this.core.WARN("Read for write-only register: 0x" + t.toString(16)), this.core.mmu.badMemory.loadU16(0); - case this.MOSAIC: - return this.core.WARN("Read for write-only register: 0x" + t.toString(16)), 0; - case this.SIOMULTI0: - case this.SIOMULTI1: - case this.SIOMULTI2: - case this.SIOMULTI3: - return this.sio.read(t - this.SIOMULTI0 >> 1); - case this.SIODATA8: - return this.core.STUB("Unimplemented SIO register read: 0x" + t.toString(16)), 0; - case this.JOYCNT: - case this.JOYSTAT: - return this.core.STUB("Unimplemented JOY register read: 0x" + t.toString(16)), 0; - default: - return this.core.WARN("Bad I/O register read: 0x" + t.toString(16)), this.core.mmu.badMemory.loadU16(0) - } - return this.registers[t >> 1] -}, GameBoyAdvanceIO.prototype.store8 = function(t, e) { - switch (t) { - case this.WININ: - case 1 | this.WININ: - case this.WINOUT: - case 1 | this.WINOUT: - this.value; - break; - case this.SOUND1CNT_LO: - case 1 | this.SOUND1CNT_LO: - case this.SOUND1CNT_HI: - case 1 | this.SOUND1CNT_HI: - case this.SOUND1CNT_X: - case 1 | this.SOUND1CNT_X: - case this.SOUND2CNT_LO: - case 1 | this.SOUND2CNT_LO: - case this.SOUND2CNT_HI: - case 1 | this.SOUND2CNT_HI: - case this.SOUND3CNT_LO: - case 1 | this.SOUND3CNT_LO: - case this.SOUND3CNT_HI: - case 1 | this.SOUND3CNT_HI: - case this.SOUND3CNT_X: - case 1 | this.SOUND3CNT_X: - case this.SOUND4CNT_LO: - case 1 | this.SOUND4CNT_LO: - case this.SOUND4CNT_HI: - case 1 | this.SOUND4CNT_HI: - case this.SOUNDCNT_LO: - case 1 | this.SOUNDCNT_LO: - case this.SOUNDCNT_X: - case this.IF: - case this.IME: - break; - case 1 | this.SOUNDBIAS: - this.STUB_REG("sound", t); - break; - case this.HALTCNT: - return void((e &= 128) ? this.core.STUB("Stop") : this.core.irq.halt()); - default: - this.STUB_REG("8-bit I/O", t) - } - 1 & t ? (e <<= 8, e |= 255 & this.registers[t >> 1]) : (e &= 255, e |= 65280 & this.registers[t >> 1]), this.store16(268435454 & t, e) -}, GameBoyAdvanceIO.prototype.store16 = function(t, e) { - switch (t) { - case this.DISPCNT: - this.video.renderPath.writeDisplayControl(e); - break; - case this.DISPSTAT: - e &= this.video.DISPSTAT_MASK, this.video.writeDisplayStat(e); - break; - case this.BG0CNT: - this.video.renderPath.writeBackgroundControl(0, e); - break; - case this.BG1CNT: - this.video.renderPath.writeBackgroundControl(1, e); - break; - case this.BG2CNT: - this.video.renderPath.writeBackgroundControl(2, e); - break; - case this.BG3CNT: - this.video.renderPath.writeBackgroundControl(3, e); - break; - case this.BG0HOFS: - this.video.renderPath.writeBackgroundHOffset(0, e); - break; - case this.BG0VOFS: - this.video.renderPath.writeBackgroundVOffset(0, e); - break; - case this.BG1HOFS: - this.video.renderPath.writeBackgroundHOffset(1, e); - break; - case this.BG1VOFS: - this.video.renderPath.writeBackgroundVOffset(1, e); - break; - case this.BG2HOFS: - this.video.renderPath.writeBackgroundHOffset(2, e); - break; - case this.BG2VOFS: - this.video.renderPath.writeBackgroundVOffset(2, e); - break; - case this.BG3HOFS: - this.video.renderPath.writeBackgroundHOffset(3, e); - break; - case this.BG3VOFS: - this.video.renderPath.writeBackgroundVOffset(3, e); - break; - case this.BG2X_LO: - this.video.renderPath.writeBackgroundRefX(2, this.registers[t >> 1 | 1] << 16 | e); - break; - case this.BG2X_HI: - this.video.renderPath.writeBackgroundRefX(2, this.registers[t >> 1 ^ 1] | e << 16); - break; - case this.BG2Y_LO: - this.video.renderPath.writeBackgroundRefY(2, this.registers[t >> 1 | 1] << 16 | e); - break; - case this.BG2Y_HI: - this.video.renderPath.writeBackgroundRefY(2, this.registers[t >> 1 ^ 1] | e << 16); - break; - case this.BG2PA: - this.video.renderPath.writeBackgroundParamA(2, e); - break; - case this.BG2PB: - this.video.renderPath.writeBackgroundParamB(2, e); - break; - case this.BG2PC: - this.video.renderPath.writeBackgroundParamC(2, e); - break; - case this.BG2PD: - this.video.renderPath.writeBackgroundParamD(2, e); - break; - case this.BG3X_LO: - this.video.renderPath.writeBackgroundRefX(3, this.registers[t >> 1 | 1] << 16 | e); - break; - case this.BG3X_HI: - this.video.renderPath.writeBackgroundRefX(3, this.registers[t >> 1 ^ 1] | e << 16); - break; - case this.BG3Y_LO: - this.video.renderPath.writeBackgroundRefY(3, this.registers[t >> 1 | 1] << 16 | e); - break; - case this.BG3Y_HI: - this.video.renderPath.writeBackgroundRefY(3, this.registers[t >> 1 ^ 1] | e << 16); - break; - case this.BG3PA: - this.video.renderPath.writeBackgroundParamA(3, e); - break; - case this.BG3PB: - this.video.renderPath.writeBackgroundParamB(3, e); - break; - case this.BG3PC: - this.video.renderPath.writeBackgroundParamC(3, e); - break; - case this.BG3PD: - this.video.renderPath.writeBackgroundParamD(3, e); - break; - case this.WIN0H: - this.video.renderPath.writeWin0H(e); - break; - case this.WIN1H: - this.video.renderPath.writeWin1H(e); - break; - case this.WIN0V: - this.video.renderPath.writeWin0V(e); - break; - case this.WIN1V: - this.video.renderPath.writeWin1V(e); - break; - case this.WININ: - e &= 16191, this.video.renderPath.writeWinIn(e); - break; - case this.WINOUT: - e &= 16191, this.video.renderPath.writeWinOut(e); - break; - case this.BLDCNT: - e &= 32767, this.video.renderPath.writeBlendControl(e); - break; - case this.BLDALPHA: - e &= 7967, this.video.renderPath.writeBlendAlpha(e); - break; - case this.BLDY: - e &= 31, this.video.renderPath.writeBlendY(e); - break; - case this.MOSAIC: - this.video.renderPath.writeMosaic(e); - break; - case this.SOUND1CNT_LO: - e &= 127, this.audio.writeSquareChannelSweep(0, e); - break; - case this.SOUND1CNT_HI: - this.audio.writeSquareChannelDLE(0, e); - break; - case this.SOUND1CNT_X: - e &= 51199, this.audio.writeSquareChannelFC(0, e), e &= -32769; - break; - case this.SOUND2CNT_LO: - this.audio.writeSquareChannelDLE(1, e); - break; - case this.SOUND2CNT_HI: - e &= 51199, this.audio.writeSquareChannelFC(1, e), e &= -32769; - break; - case this.SOUND3CNT_LO: - e &= 224, this.audio.writeChannel3Lo(e); - break; - case this.SOUND3CNT_HI: - e &= 57599, this.audio.writeChannel3Hi(e); - break; - case this.SOUND3CNT_X: - e &= 51199, this.audio.writeChannel3X(e), e &= -32769; - break; - case this.SOUND4CNT_LO: - e &= 65343, this.audio.writeChannel4LE(e); - break; - case this.SOUND4CNT_HI: - e &= 49407, this.audio.writeChannel4FC(e), e &= -32769; - break; - case this.SOUNDCNT_LO: - e &= 65399, this.audio.writeSoundControlLo(e); - break; - case this.SOUNDCNT_HI: - e &= 65295, this.audio.writeSoundControlHi(e); - break; - case this.SOUNDCNT_X: - e &= 128, this.audio.writeEnable(e); - break; - case this.WAVE_RAM0_LO: - case this.WAVE_RAM0_HI: - case this.WAVE_RAM1_LO: - case this.WAVE_RAM1_HI: - case this.WAVE_RAM2_LO: - case this.WAVE_RAM2_HI: - case this.WAVE_RAM3_LO: - case this.WAVE_RAM3_HI: - this.audio.writeWaveData(t - this.WAVE_RAM0_LO, e, 2); - break; - case this.DMA0SAD_LO: - case this.DMA0DAD_LO: - case this.DMA1SAD_LO: - case this.DMA1DAD_LO: - case this.DMA2SAD_LO: - case this.DMA2DAD_LO: - case this.DMA3SAD_LO: - case this.DMA3DAD_LO: - return void this.store32(t, this.registers[1 + (t >> 1)] << 16 | e); - case this.DMA0SAD_HI: - case this.DMA0DAD_HI: - case this.DMA1SAD_HI: - case this.DMA1DAD_HI: - case this.DMA2SAD_HI: - case this.DMA2DAD_HI: - case this.DMA3SAD_HI: - case this.DMA3DAD_HI: - return void this.store32(t - 2, this.registers[(t >> 1) - 1] | e << 16); - case this.DMA0CNT_LO: - this.cpu.irq.dmaSetWordCount(0, e); - break; - case this.DMA0CNT_HI: - return this.registers[t >> 1] = 65504 & e, void this.cpu.irq.dmaWriteControl(0, e); - case this.DMA1CNT_LO: - this.cpu.irq.dmaSetWordCount(1, e); - break; - case this.DMA1CNT_HI: - return this.registers[t >> 1] = 65504 & e, void this.cpu.irq.dmaWriteControl(1, e); - case this.DMA2CNT_LO: - this.cpu.irq.dmaSetWordCount(2, e); - break; - case this.DMA2CNT_HI: - return this.registers[t >> 1] = 65504 & e, void this.cpu.irq.dmaWriteControl(2, e); - case this.DMA3CNT_LO: - this.cpu.irq.dmaSetWordCount(3, e); - break; - case this.DMA3CNT_HI: - return this.registers[t >> 1] = 65504 & e, void this.cpu.irq.dmaWriteControl(3, e); - case this.TM0CNT_LO: - return void this.cpu.irq.timerSetReload(0, e); - case this.TM1CNT_LO: - return void this.cpu.irq.timerSetReload(1, e); - case this.TM2CNT_LO: - return void this.cpu.irq.timerSetReload(2, e); - case this.TM3CNT_LO: - return void this.cpu.irq.timerSetReload(3, e); - case this.TM0CNT_HI: - e &= 199, this.cpu.irq.timerWriteControl(0, e); - break; - case this.TM1CNT_HI: - e &= 199, this.cpu.irq.timerWriteControl(1, e); - break; - case this.TM2CNT_HI: - e &= 199, this.cpu.irq.timerWriteControl(2, e); - break; - case this.TM3CNT_HI: - e &= 199, this.cpu.irq.timerWriteControl(3, e); - break; - case this.SIOMULTI0: - case this.SIOMULTI1: - case this.SIOMULTI2: - case this.SIOMULTI3: - case this.SIODATA8: - this.STUB_REG("SIO", t); - break; - case this.RCNT: - this.sio.setMode(e >> 12 & 12 | this.registers[this.SIOCNT >> 1] >> 12 & 3), this.sio.writeRCNT(e); - break; - case this.SIOCNT: - return this.sio.setMode(e >> 12 & 3 | this.registers[this.RCNT >> 1] >> 12 & 12), void this.sio.writeSIOCNT(e); - case this.JOYCNT: - case this.JOYSTAT: - this.STUB_REG("JOY", t); - break; - case this.IE: - e &= 16383, this.cpu.irq.setInterruptsEnabled(e); - break; - case this.IF: - return void this.cpu.irq.dismissIRQs(e); - case this.WAITCNT: - e &= 57343, this.cpu.mmu.adjustTimings(e); - break; - case this.IME: - e &= 1, this.cpu.irq.masterEnable(e); - break; - default: - this.STUB_REG("I/O", t) - } - this.registers[t >> 1] = e -}, GameBoyAdvanceIO.prototype.store32 = function(t, e) { - switch (t) { - case this.BG2X_LO: - e &= 268435455, this.video.renderPath.writeBackgroundRefX(2, e); - break; - case this.BG2Y_LO: - e &= 268435455, this.video.renderPath.writeBackgroundRefY(2, e); - break; - case this.BG3X_LO: - e &= 268435455, this.video.renderPath.writeBackgroundRefX(3, e); - break; - case this.BG3Y_LO: - e &= 268435455, this.video.renderPath.writeBackgroundRefY(3, e); - break; - case this.DMA0SAD_LO: - this.cpu.irq.dmaSetSourceAddress(0, e); - break; - case this.DMA0DAD_LO: - this.cpu.irq.dmaSetDestAddress(0, e); - break; - case this.DMA1SAD_LO: - this.cpu.irq.dmaSetSourceAddress(1, e); - break; - case this.DMA1DAD_LO: - this.cpu.irq.dmaSetDestAddress(1, e); - break; - case this.DMA2SAD_LO: - this.cpu.irq.dmaSetSourceAddress(2, e); - break; - case this.DMA2DAD_LO: - this.cpu.irq.dmaSetDestAddress(2, e); - break; - case this.DMA3SAD_LO: - this.cpu.irq.dmaSetSourceAddress(3, e); - break; - case this.DMA3DAD_LO: - this.cpu.irq.dmaSetDestAddress(3, e); - break; - case this.FIFO_A_LO: - return void this.audio.appendToFifoA(e); - case this.FIFO_B_LO: - return void this.audio.appendToFifoB(e); - case this.IME: - return void this.store16(t, 65535 & e); - case this.JOY_RECV: - case this.JOY_TRANS: - return void this.STUB_REG("JOY", t); - default: - return this.store16(t, 65535 & e), void this.store16(2 | t, e >>> 16) - } - this.registers[t >> 1] = 65535 & e, this.registers[1 + (t >> 1)] = e >>> 16 -}, GameBoyAdvanceIO.prototype.invalidatePage = function(t) {}, GameBoyAdvanceIO.prototype.STUB_REG = function(t, e) { - this.core.STUB("Unimplemented " + t + " register write: " + e.toString(16)) -}, GameBoyAdvanceAudio.prototype.initAudio = function() { - var e = this; - return e.isInit && e.context && (e.jsAudio = this.context.createScriptProcessor(e.bufferSize), e.jsAudio.onaudioprocess = function(t) { - e.audioProcess(t) - }, e.jsAudio.connect(e.context.destination)), !!e.jsAudio -}, GameBoyAdvanceAudio.prototype.clear = function() { - if (this.fifoA = [], this.fifoB = [], this.fifoASample = 0, this.fifoBSample = 0, this.enabled = !1, this.context) try { - this.jsAudio.disconnect(this.context.destination) - } catch (t) {} - this.enableChannel3 = !1, this.enableChannel4 = !1, this.enableChannelA = !1, this.enableChannelB = !1, this.enableRightChannelA = !1, this.enableLeftChannelA = !1, this.enableRightChannelB = !1, this.enableLeftChannelB = !1, this.playingChannel3 = !1, this.playingChannel4 = !1, this.volumeLeft = 0, this.volumeRight = 0, this.ratioChannelA = 1, this.ratioChannelB = 1, this.enabledLeft = 0, this.enabledRight = 0, this.dmaA = -1, this.dmaB = -1, this.soundTimerA = 0, this.soundTimerB = 0, this.soundRatio = 1, this.soundBias = 512, this.squareChannels = new Array; - for (var t = 0; t < 2; ++t) this.squareChannels[t] = { - enabled: !1, - playing: !1, - sample: 0, - duty: .5, - increment: 0, - step: 0, - initialVolume: 0, - volume: 0, - frequency: 0, - interval: 0, - sweepSteps: 0, - sweepIncrement: 0, - sweepInterval: 0, - doSweep: !1, - raise: 0, - lower: 0, - nextStep: 0, - timed: !1, - length: 0, - end: 0 - }; - this.waveData = new Uint8Array(32), this.channel3Dimension = 0, this.channel3Bank = 0, this.channel3Volume = 0, this.channel3Interval = 0, this.channel3Next = 0, this.channel3Length = 0, this.channel3Timed = !1, this.channel3End = 0, this.channel3Pointer = 0, this.channel3Sample = 0, this.cpuFrequency = this.core.irq.FREQUENCY, this.channel4 = { - sample: 0, - lfsr: 0, - width: 15, - interval: this.cpuFrequency / 524288, - increment: 0, - step: 0, - initialVolume: 0, - volume: 0, - nextStep: 0, - timed: !1, - length: 0, - end: 0 - }, this.nextEvent = 0, this.nextSample = 0, this.outputPointer = 0, this.samplePointer = 0, this.backup = 0, this.totalSamples = 0, this.sampleRate = 32768, this.sampleInterval = this.cpuFrequency / this.sampleRate, this.resampleRatio = 1, this.context && (this.resampleRatio = this.sampleRate / this.context.sampleRate), this.writeSquareChannelFC(0, 0), this.writeSquareChannelFC(1, 0), this.writeChannel4FC(0) -}, GameBoyAdvanceAudio.prototype.freeze = function() { - return { - nextSample: this.nextSample - } -}, GameBoyAdvanceAudio.prototype.defrost = function(t) { - this.nextSample = t.nextSample -}, GameBoyAdvanceAudio.prototype.pause = function(t) { - if (this.context) - if (t) try { - this.jsAudio.disconnect(this.context.destination) - } catch (t) {} else this.enabled && this.jsAudio.connect(this.context.destination) -}, GameBoyAdvanceAudio.prototype.updateTimers = function() { - var t = this.cpu.cycles; - if (this.enabled && !(t < this.nextEvent && t < this.nextSample)) { - if (t >= this.nextEvent) { - var e = this.squareChannels[0]; - if (this.nextEvent = 1 / 0, e.playing && this.updateSquareChannel(e, t), (e = this.squareChannels[1]).playing && this.updateSquareChannel(e, t), this.enableChannel3 && this.playingChannel3) { - if (t >= this.channel3Next) { - if (this.channel3Write) { - var i = this.waveData[this.channel3Pointer >> 1]; - this.channel3Sample = ((i >> ((1 & this.channel3Pointer) << 2) & 15) - 8) / 8, this.channel3Pointer = this.channel3Pointer + 1, this.channel3Dimension && 64 <= this.channel3Pointer ? this.channel3Pointer -= 64 : !this.channel3Bank && 32 <= this.channel3Pointer ? this.channel3Pointer -= 32 : 64 <= this.channel3Pointer && (this.channel3Pointer -= 32) - } - this.channel3Next += this.channel3Interval, this.channel3Interval && this.nextEvent > this.channel3Next && (this.nextEvent = this.channel3Next) - } - this.channel3Timed && t >= this.channel3End && (this.playingChannel3 = !1) - } - if (this.enableChannel4 && this.playingChannel4) - if (this.channel4.timed && t >= this.channel4.end) this.playingChannel4 = !1; - else { - if (t >= this.channel4.next) { - this.channel4.lfsr >>= 1; - i = 1 & this.channel4.lfsr; - this.channel4.lfsr |= (this.channel4.lfsr >> 1 & 1 ^ i) << this.channel4.width - 1, this.channel4.next += this.channel4.interval, this.channel4.sample = 2 * (i - .5) * this.channel4.volume - } - this.updateEnvelope(this.channel4, t), this.nextEvent > this.channel4.next && (this.nextEvent = this.channel4.next), this.channel4.timed && this.nextEvent > this.channel4.end && (this.nextEvent = this.channel4.end) - } - } - t >= this.nextSample && (this.sample(), this.nextSample += this.sampleInterval), this.nextEvent = Math.ceil(this.nextEvent), (this.nextEvent < t || this.nextSample < t) && this.updateTimers() - } -}, GameBoyAdvanceAudio.prototype.writeEnable = function(t) { - if (this.enabled = !!t, this.nextEvent = this.cpu.cycles, this.nextSample = this.nextEvent, this.updateTimers(), this.core.irq.pollNextEvent(), this.context && this.isInit) - if (t&&this.jsAudio) this.jsAudio.connect(this.context.destination); - else try { - this.jsAudio.disconnect(this.context.destination) - } catch (t) {} -}, GameBoyAdvanceAudio.prototype.writeSoundControlLo = function(t) { - this.masterVolumeLeft = 7 & t, this.masterVolumeRight = t >> 4 & 7, this.enabledLeft = t >> 8 & 15, this.enabledRight = t >> 12 & 15, this.setSquareChannelEnabled(this.squareChannels[0], 1 & (this.enabledLeft | this.enabledRight)), this.setSquareChannelEnabled(this.squareChannels[1], 2 & (this.enabledLeft | this.enabledRight)), this.enableChannel3 = 4 & (this.enabledLeft | this.enabledRight), this.setChannel4Enabled(8 & (this.enabledLeft | this.enabledRight)), this.updateTimers(), this.core.irq.pollNextEvent() -}, GameBoyAdvanceAudio.prototype.writeSoundControlHi = function(t) { - switch (3 & t) { - case 0: - this.soundRatio = .25; - break; - case 1: - this.soundRatio = .5; - break; - case 2: - this.soundRatio = 1 - } - this.ratioChannelA = .5 * (1 + ((4 & t) >> 2)), this.ratioChannelB = .5 * (1 + ((8 & t) >> 3)), this.enableRightChannelA = 256 & t, this.enableLeftChannelA = 512 & t, this.enableChannelA = 768 & t, this.soundTimerA = 1024 & t, 2048 & t && (this.fifoA = []), this.enableRightChannelB = 4096 & t, this.enableLeftChannelB = 8192 & t, this.enableChannelB = 12288 & t, this.soundTimerB = 16384 & t, 32768 & t && (this.fifoB = []) -}, GameBoyAdvanceAudio.prototype.resetSquareChannel = function(t) { - t.step && (t.nextStep = this.cpu.cycles + t.step), t.enabled && !t.playing && (t.raise = this.cpu.cycles, t.lower = t.raise + t.duty * t.interval, t.end = this.cpu.cycles + t.length, this.nextEvent = this.cpu.cycles), t.playing = t.enabled, this.updateTimers(), this.core.irq.pollNextEvent() -}, GameBoyAdvanceAudio.prototype.setSquareChannelEnabled = function(t, e) { - t.enabled && t.playing || !e ? t.enabled = !!e : (t.enabled = !!e, this.updateTimers(), this.core.irq.pollNextEvent()) -}, GameBoyAdvanceAudio.prototype.writeSquareChannelSweep = function(t, e) { - var i = this.squareChannels[t]; - i.sweepSteps = 7 & e, i.sweepIncrement = 8 & e ? -1 : 1, i.sweepInterval = (e >> 4 & 7) * this.cpuFrequency / 128, i.doSweep = !!i.sweepInterval, i.nextSweep = this.cpu.cycles + i.sweepInterval, this.resetSquareChannel(i) -}, GameBoyAdvanceAudio.prototype.writeSquareChannelDLE = function(t, e) { - var i = this.squareChannels[t]; - switch (e >> 6 & 3) { - case 0: - i.duty = .125; - break; - case 1: - i.duty = .25; - break; - case 2: - i.duty = .5; - break; - case 3: - i.duty = .75 - } - this.writeChannelLE(i, e), this.resetSquareChannel(i) -}, GameBoyAdvanceAudio.prototype.writeSquareChannelFC = function(t, e) { - var i = this.squareChannels[t], - r = 2047 & e; - i.frequency = r, i.interval = this.cpuFrequency * (2048 - r) / 131072, i.timed = !!(16384 & e), 32768 & e && (this.resetSquareChannel(i), i.volume = i.initialVolume) -}, GameBoyAdvanceAudio.prototype.updateSquareChannel = function(t, e) { - if (t.timed && e >= t.end) t.playing = !1; - else { - if (t.doSweep && e >= t.nextSweep) { - if (t.frequency += t.sweepIncrement * (t.frequency >> t.sweepSteps), t.frequency < 0) t.frequency = 0; - else if (2047 < t.frequency) return t.frequency = 2047, void(t.playing = !1); - t.interval = this.cpuFrequency * (2048 - t.frequency) / 131072, t.nextSweep += t.sweepInterval - } - e >= t.raise ? (t.sample = t.volume, t.lower = t.raise + t.duty * t.interval, t.raise += t.interval) : e >= t.lower && (t.sample = -t.volume, t.lower += t.interval), this.updateEnvelope(t, e), this.nextEvent > t.raise && (this.nextEvent = t.raise), this.nextEvent > t.lower && (this.nextEvent = t.lower), t.timed && this.nextEvent > t.end && (this.nextEvent = t.end), t.doSweep && this.nextEvent > t.nextSweep && (this.nextEvent = t.nextSweep) - } -}, GameBoyAdvanceAudio.prototype.writeChannel3Lo = function(t) { - this.channel3Dimension = 32 & t, this.channel3Bank = 64 & t; - var e = 128 & t; - !this.channel3Write && e ? (this.channel3Write = e, this.resetChannel3()) : this.channel3Write = e -}, GameBoyAdvanceAudio.prototype.writeChannel3Hi = function(t) { - switch (this.channel3Length = this.cpuFrequency * (256 - (255 & t)) / 256, t >> 13 & 7) { - case 0: - this.channel3Volume = 0; - break; - case 1: - this.channel3Volume = 1; - break; - case 2: - this.channel3Volume = .5; - break; - case 3: - this.channel3Volume = .25; - break; - default: - this.channel3Volume = .75 - } -}, GameBoyAdvanceAudio.prototype.writeChannel3X = function(t) { - this.channel3Interval = this.cpuFrequency * (2048 - (2047 & t)) / 2097152, this.channel3Timed = !!(16384 & t), this.channel3Write && this.resetChannel3() -}, GameBoyAdvanceAudio.prototype.resetChannel3 = function() { - this.channel3Next = this.cpu.cycles, this.nextEvent = this.channel3Next, this.channel3End = this.cpu.cycles + this.channel3Length, this.playingChannel3 = this.channel3Write, this.updateTimers(), this.core.irq.pollNextEvent() -}, GameBoyAdvanceAudio.prototype.writeWaveData = function(t, e, i) { - this.channel3Bank || (t += 16), 2 == i && (this.waveData[t] = 255 & e, e >>= 8, ++t), this.waveData[t] = 255 & e -}, GameBoyAdvanceAudio.prototype.setChannel4Enabled = function(t) { - !this.enableChannel4 && t ? (this.channel4.next = this.cpu.cycles, this.channel4.end = this.cpu.cycles + this.channel4.length, this.enableChannel4 = !0, this.playingChannel4 = !0, this.nextEvent = this.cpu.cycles, this.updateEnvelope(this.channel4), this.updateTimers(), this.core.irq.pollNextEvent()) : this.enableChannel4 = t -}, GameBoyAdvanceAudio.prototype.writeChannel4LE = function(t) { - this.writeChannelLE(this.channel4, t), this.resetChannel4() -}, GameBoyAdvanceAudio.prototype.writeChannel4FC = function(t) { - this.channel4.timed = !!(16384 & t); - var e = 7 & t; - e || (e = .5); - var i = t >> 4 & 15, - r = this.cpuFrequency * (e * (2 << i)) / 524288; - r != this.channel4.interval && (this.channel4.interval = r, this.resetChannel4()); - var s = 8 & t ? 7 : 15; - s != this.channel4.width && (this.channel4.width = s, this.resetChannel4()), 32768 & t && this.resetChannel4() -}, GameBoyAdvanceAudio.prototype.resetChannel4 = function() { - 15 == this.channel4.width ? this.channel4.lfsr = 16384 : this.channel4.lfsr = 64, this.channel4.volume = this.channel4.initialVolume, this.channel4.step && (this.channel4.nextStep = this.cpu.cycles + this.channel4.step), this.channel4.end = this.cpu.cycles + this.channel4.length, this.channel4.next = this.cpu.cycles, this.nextEvent = this.channel4.next, this.playingChannel4 = this.enableChannel4, this.updateTimers(), this.core.irq.pollNextEvent() -}, GameBoyAdvanceAudio.prototype.writeChannelLE = function(t, e) { - t.length = this.cpuFrequency * ((64 - (63 & e)) / 256), t.increment = 2048 & e ? 1 / 16 : -1 / 16, t.initialVolume = (e >> 12 & 15) / 16, t.step = this.cpuFrequency * ((e >> 8 & 7) / 64) -}, GameBoyAdvanceAudio.prototype.updateEnvelope = function(t, e) { - t.step && (e >= t.nextStep && (t.volume += t.increment, 1 < t.volume ? t.volume = 1 : t.volume < 0 && (t.volume = 0), t.nextStep += t.step), this.nextEvent > t.nextStep && (this.nextEvent = t.nextStep)) -}, GameBoyAdvanceAudio.prototype.appendToFifoA = function(t) { - var e; - 28 < this.fifoA.length && (this.fifoA = this.fifoA.slice(-28)); - for (var i = 0; i < 4; ++i) e = (255 & t) << 24, t >>= 8, this.fifoA.push(e / 2147483648) -}, GameBoyAdvanceAudio.prototype.appendToFifoB = function(t) { - var e; - 28 < this.fifoB.length && (this.fifoB = this.fifoB.slice(-28)); - for (var i = 0; i < 4; ++i) e = (255 & t) << 24, t >>= 8, this.fifoB.push(e / 2147483648) -}, GameBoyAdvanceAudio.prototype.sampleFifoA = function() { - if (this.fifoA.length <= 16) { - var t = this.core.irq.dma[this.dmaA]; - t.nextCount = 4, this.core.mmu.serviceDma(this.dmaA, t) - } - this.fifoASample = this.fifoA.shift() -}, GameBoyAdvanceAudio.prototype.sampleFifoB = function() { - if (this.fifoB.length <= 16) { - var t = this.core.irq.dma[this.dmaB]; - t.nextCount = 4, this.core.mmu.serviceDma(this.dmaB, t) - } - this.fifoBSample = this.fifoB.shift() -}, GameBoyAdvanceAudio.prototype.scheduleFIFODma = function(t, e) { - switch (e.dest) { - case this.cpu.mmu.BASE_IO | this.cpu.irq.io.FIFO_A_LO: - e.dstControl = 2, this.dmaA = t; - break; - case this.cpu.mmu.BASE_IO | this.cpu.irq.io.FIFO_B_LO: - e.dstControl = 2, this.dmaB = t; - break; - default: - this.core.WARN("Tried to schedule FIFO DMA for non-FIFO destination") - } -}, GameBoyAdvanceAudio.prototype.sample = function() { - var t, e, i = 0, - r = 0; - (e = this.squareChannels[0]).playing && (t = e.sample * this.soundRatio * this.PSG_MAX, 1 & this.enabledLeft && (i += t), 1 & this.enabledRight && (r += t)), (e = this.squareChannels[1]).playing && (t = e.sample * this.soundRatio * this.PSG_MAX, 2 & this.enabledLeft && (i += t), 2 & this.enabledRight && (r += t)), this.playingChannel3 && (t = this.channel3Sample * this.soundRatio * this.channel3Volume * this.PSG_MAX, 4 & this.enabledLeft && (i += t), 4 & this.enabledRight && (r += t)), this.playingChannel4 && (t = this.channel4.sample * this.soundRatio * this.PSG_MAX, 8 & this.enabledLeft && (i += t), 8 & this.enabledRight && (r += t)), this.enableChannelA && (t = this.fifoASample * this.FIFO_MAX * this.ratioChannelA, this.enableLeftChannelA && (i += t), this.enableRightChannelA && (r += t)), this.enableChannelB && (t = this.fifoBSample * this.FIFO_MAX * this.ratioChannelB, this.enableLeftChannelB && (i += t), this.enableRightChannelB && (r += t)); - var s = this.samplePointer; - if (i *= this.masterVolume / this.SOUND_MAX, i = Math.max(Math.min(i, 1), -1), r *= this.masterVolume / this.SOUND_MAX, r = Math.max(Math.min(r, 1), -1), !this.isInit2 && i && r) { - this.isInit2 = !0; - var n = this; - setTimeout(function() { - n.isInit = !0 - }, 1e3) - } - this.buffers && (this.buffers[0][s] = i, this.buffers[1][s] = r), this.samplePointer = s + 1 & this.sampleMask -}, GameBoyAdvanceAudio.prototype.audioProcess = function(t) { - var e = t.outputBuffer.getChannelData(0), - i = t.outputBuffer.getChannelData(1); - if (this.masterEnable) { - var r, s = this.outputPointer; - for (r = 0; r < this.bufferSize; ++r, s += this.resampleRatio) { - if (s >= this.maxSamples && (s -= this.maxSamples), (0 | s) == this.samplePointer) { - ++this.backup; - break - } - e[r] = this.buffers[0][0 | s], i[r] = this.buffers[1][0 | s] - } - for (; r < this.bufferSize; ++r) e[r] = 0, i[r] = 0; - this.outputPointer = s, ++this.totalSamples - } else - for (r = 0; r < this.bufferSize; ++r) e[r] = 0, i[r] = 0 -}, GameBoyAdvanceVideo.prototype.clear = function() { - this.renderPath.clear(this.cpu.mmu), this.DISPSTAT_MASK = 65336, this.inHblank = !1, this.inVblank = !1, this.vcounter = 0, this.vblankIRQ = 0, this.hblankIRQ = 0, this.vcounterIRQ = 0, this.vcountSetting = 0, this.vcount = -1, this.lastHblank = 0, this.nextHblank = this.HDRAW_LENGTH, this.nextEvent = this.nextHblank, this.nextHblankIRQ = 0, this.nextVblankIRQ = 0, this.nextVcounterIRQ = 0 -}, GameBoyAdvanceVideo.prototype.freeze = function() { - return { - inHblank: this.inHblank, - inVblank: this.inVblank, - vcounter: this.vcounter, - vblankIRQ: this.vblankIRQ, - hblankIRQ: this.hblankIRQ, - vcounterIRQ: this.vcounterIRQ, - vcountSetting: this.vcountSetting, - vcount: this.vcount, - lastHblank: this.lastHblank, - nextHblank: this.nextHblank, - nextEvent: this.nextEvent, - nextHblankIRQ: this.nextHblankIRQ, - nextVblankIRQ: this.nextVblankIRQ, - nextVcounterIRQ: this.nextVcounterIRQ, - renderPath: this.renderPath.freeze(this.core.encodeBase64) - } -}, GameBoyAdvanceVideo.prototype.defrost = function(t) { - this.inHblank = t.inHblank, this.inVblank = t.inVblank, this.vcounter = t.vcounter, this.vblankIRQ = t.vblankIRQ, this.hblankIRQ = t.hblankIRQ, this.vcounterIRQ = t.vcounterIRQ, this.vcountSetting = t.vcountSetting, this.vcount = t.vcount, this.lastHblank = t.lastHblank, this.nextHblank = t.nextHblank, this.nextEvent = t.nextEvent, this.nextHblankIRQ = t.nextHblankIRQ, this.nextVblankIRQ = t.nextVblankIRQ, this.nextVcounterIRQ = t.nextVcounterIRQ, this.renderPath.defrost(t.renderPath, this.core.decodeBase64) -}, GameBoyAdvanceVideo.prototype.setBacking = function(t) { - var e = t.createImageData(this.HORIZONTAL_PIXELS, this.VERTICAL_PIXELS); - this.context = t; - for (var i = 0; i < this.HORIZONTAL_PIXELS * this.VERTICAL_PIXELS * 4;) e.data[i++] = 255, e.data[i++] = 255, e.data[i++] = 255, e.data[i++] = 255; - this.renderPath.setBacking(e) -}, GameBoyAdvanceVideo.prototype.updateTimers = function(t) { - var e = t.cycles; - if (this.nextEvent <= e) - if (this.inHblank) { - switch (this.inHblank = !1, this.nextEvent = this.nextHblank, ++this.vcount, this.vcount) { - case this.VERTICAL_PIXELS: - this.inVblank = !0, this.renderPath.finishDraw(this), this.nextVblankIRQ = this.nextEvent + this.TOTAL_LENGTH, this.cpu.mmu.runVblankDmas(), this.vblankIRQ && this.cpu.irq.raiseIRQ(this.cpu.irq.IRQ_VBLANK), this.vblankCallback(); - break; - case this.VERTICAL_TOTAL_PIXELS - 1: - this.inVblank = !1; - break; - case this.VERTICAL_TOTAL_PIXELS: - this.vcount = 0, this.renderPath.startDraw() - } - this.vcounter = this.vcount == this.vcountSetting, this.vcounter && this.vcounterIRQ && (this.cpu.irq.raiseIRQ(this.cpu.irq.IRQ_VCOUNTER), this.nextVcounterIRQ += this.TOTAL_LENGTH), this.vcount < this.VERTICAL_PIXELS && this.renderPath.drawScanline(this.vcount) - } else this.inHblank = !0, this.lastHblank = this.nextHblank, this.nextEvent = this.lastHblank + this.HBLANK_LENGTH, this.nextHblank = this.nextEvent + this.HDRAW_LENGTH, this.nextHblankIRQ = this.nextHblank, this.vcount < this.VERTICAL_PIXELS && this.cpu.mmu.runHblankDmas(), this.hblankIRQ && this.cpu.irq.raiseIRQ(this.cpu.irq.IRQ_HBLANK) -}, GameBoyAdvanceVideo.prototype.writeDisplayStat = function(t) { - this.vblankIRQ = 8 & t, this.hblankIRQ = 16 & t, this.vcounterIRQ = 32 & t, this.vcountSetting = (65280 & t) >> 8, this.vcounterIRQ && (this.nextVcounterIRQ = this.nextHblank + this.HBLANK_LENGTH + (this.vcountSetting - this.vcount) * this.HORIZONTAL_LENGTH, this.nextVcounterIRQ < this.nextEvent && (this.nextVcounterIRQ += this.TOTAL_LENGTH)) -}, GameBoyAdvanceVideo.prototype.readDisplayStat = function() { - return this.inVblank | this.inHblank << 1 | this.vcounter << 2 -}, GameBoyAdvanceVideo.prototype.finishDraw = function(t) { - this.context.putImageData(t, 0, 0), this.drawCallback() -}, MemoryProxy.prototype.combine = function() { - if (1 < this.blocks.length) { - for (var t = new Uint8Array(this.size), e = 0; e < this.blocks.length; ++e) t.set(new Uint8Array(this.blocks[e].buffer), e << this.blockSize); - return t.buffer - } - return this.blocks[0].buffer -}, MemoryProxy.prototype.replace = function(t) { - for (var e = 0; e < this.blocks.length; ++e) this.blocks[e] = new MemoryView(t.slice(e << this.blockSize, (e << this.blockSize) + this.blocks[e].buffer.byteLength)) -}, MemoryProxy.prototype.load8 = function(t) { - return this.blocks[t >> this.blockSize].load8(t & this.mask) -}, MemoryProxy.prototype.load16 = function(t) { - return this.blocks[t >> this.blockSize].load16(t & this.mask) -}, MemoryProxy.prototype.loadU8 = function(t) { - return this.blocks[t >> this.blockSize].loadU8(t & this.mask) -}, MemoryProxy.prototype.loadU16 = function(t) { - return this.blocks[t >> this.blockSize].loadU16(t & this.mask) -}, MemoryProxy.prototype.load32 = function(t) { - return this.blocks[t >> this.blockSize].load32(t & this.mask) -}, MemoryProxy.prototype.store8 = function(t, e) { - t >= this.size || (this.owner.memoryDirtied(this, t >> this.blockSize), this.blocks[t >> this.blockSize].store8(t & this.mask, e), this.blocks[t >> this.blockSize].store8(t & this.mask ^ 1, e)) -}, MemoryProxy.prototype.store16 = function(t, e) { - if (!(t >= this.size)) return this.owner.memoryDirtied(this, t >> this.blockSize), this.blocks[t >> this.blockSize].store16(t & this.mask, e) -}, MemoryProxy.prototype.store32 = function(t, e) { - if (!(t >= this.size)) return this.owner.memoryDirtied(this, t >> this.blockSize), this.blocks[t >> this.blockSize].store32(t & this.mask, e) -}, MemoryProxy.prototype.invalidatePage = function(t) {}, GameBoyAdvanceRenderProxy.prototype.memoryDirtied = function(t, e) { - this.dirty = this.dirty || {}, this.dirty.memory = this.dirty.memory || {}, t === this.palette && (this.dirty.memory.palette = t.blocks[0].buffer), t === this.oam && (this.dirty.memory.oam = t.blocks[0].buffer), t === this.vram && (this.dirty.memory.vram = this.dirty.memory.vram || [], this.dirty.memory.vram[e] = t.blocks[e].buffer) -}, GameBoyAdvanceRenderProxy.prototype.clear = function(t) { - this.palette = new MemoryProxy(this, t.SIZE_PALETTE_RAM, 0), this.vram = new MemoryProxy(this, t.SIZE_VRAM, 13), this.oam = new MemoryProxy(this, t.SIZE_OAM, 0), this.dirty = null, this.scanlineQueue = [], this.worker.postMessage({ - type: "clear", - SIZE_VRAM: t.SIZE_VRAM, - SIZE_OAM: t.SIZE_OAM - }) -}, GameBoyAdvanceRenderProxy.prototype.freeze = function(t) { - return { - palette: Serializer.prefix(this.palette.combine()), - vram: Serializer.prefix(this.vram.combine()), - oam: Serializer.prefix(this.oam.combine()) - } -}, GameBoyAdvanceRenderProxy.prototype.defrost = function(t, e) { - this.palette.replace(t.palette), this.memoryDirtied(this.palette, 0), this.vram.replace(t.vram); - for (var i = 0; i < this.vram.blocks.length; ++i) this.memoryDirtied(this.vram, i); - this.oam.replace(t.oam), this.memoryDirtied(this.oam, 0) -}, GameBoyAdvanceRenderProxy.prototype.writeDisplayControl = function(t) { - this.dirty = this.dirty || {}, this.dirty.DISPCNT = t -}, GameBoyAdvanceRenderProxy.prototype.writeBackgroundControl = function(t, e) { - this.dirty = this.dirty || {}, this.dirty.BGCNT = this.dirty.BGCNT || [], this.dirty.BGCNT[t] = e -}, GameBoyAdvanceRenderProxy.prototype.writeBackgroundHOffset = function(t, e) { - this.dirty = this.dirty || {}, this.dirty.BGHOFS = this.dirty.BGHOFS || [], this.dirty.BGHOFS[t] = e -}, GameBoyAdvanceRenderProxy.prototype.writeBackgroundVOffset = function(t, e) { - this.dirty = this.dirty || {}, this.dirty.BGVOFS = this.dirty.BGVOFS || [], this.dirty.BGVOFS[t] = e -}, GameBoyAdvanceRenderProxy.prototype.writeBackgroundRefX = function(t, e) { - this.dirty = this.dirty || {}, this.dirty.BGX = this.dirty.BGX || [], this.dirty.BGX[t] = e -}, GameBoyAdvanceRenderProxy.prototype.writeBackgroundRefY = function(t, e) { - this.dirty = this.dirty || {}, this.dirty.BGY = this.dirty.BGY || [], this.dirty.BGY[t] = e -}, GameBoyAdvanceRenderProxy.prototype.writeBackgroundParamA = function(t, e) { - this.dirty = this.dirty || {}, this.dirty.BGPA = this.dirty.BGPA || [], this.dirty.BGPA[t] = e -}, GameBoyAdvanceRenderProxy.prototype.writeBackgroundParamB = function(t, e) { - this.dirty = this.dirty || {}, this.dirty.BGPB = this.dirty.BGPB || [], this.dirty.BGPB[t] = e -}, GameBoyAdvanceRenderProxy.prototype.writeBackgroundParamC = function(t, e) { - this.dirty = this.dirty || {}, this.dirty.BGPC = this.dirty.BGPC || [], this.dirty.BGPC[t] = e -}, GameBoyAdvanceRenderProxy.prototype.writeBackgroundParamD = function(t, e) { - this.dirty = this.dirty || {}, this.dirty.BGPD = this.dirty.BGPD || [], this.dirty.BGPD[t] = e -}, GameBoyAdvanceRenderProxy.prototype.writeWin0H = function(t) { - this.dirty = this.dirty || {}, this.dirty.WIN0H = t -}, GameBoyAdvanceRenderProxy.prototype.writeWin1H = function(t) { - this.dirty = this.dirty || {}, this.dirty.WIN1H = t -}, GameBoyAdvanceRenderProxy.prototype.writeWin0V = function(t) { - this.dirty = this.dirty || {}, this.dirty.WIN0V = t -}, GameBoyAdvanceRenderProxy.prototype.writeWin1V = function(t) { - this.dirty = this.dirty || {}, this.dirty.WIN1V = t -}, GameBoyAdvanceRenderProxy.prototype.writeWinIn = function(t) { - this.dirty = this.dirty || {}, this.dirty.WININ = t -}, GameBoyAdvanceRenderProxy.prototype.writeWinOut = function(t) { - this.dirty = this.dirty || {}, this.dirty.WINOUT = t -}, GameBoyAdvanceRenderProxy.prototype.writeBlendControl = function(t) { - this.dirty = this.dirty || {}, this.dirty.BLDCNT = t -}, GameBoyAdvanceRenderProxy.prototype.writeBlendAlpha = function(t) { - this.dirty = this.dirty || {}, this.dirty.BLDALPHA = t -}, GameBoyAdvanceRenderProxy.prototype.writeBlendY = function(t) { - this.dirty = this.dirty || {}, this.dirty.BLDY = t -}, GameBoyAdvanceRenderProxy.prototype.writeMosaic = function(t) { - this.dirty = this.dirty || {}, this.dirty.MOSAIC = t -}, GameBoyAdvanceRenderProxy.prototype.clearSubsets = function(t, e) { - if (this.dirty = this.dirty || {}, 4 & e && (this.palette = new MemoryProxy(this, t.SIZE_PALETTE_RAM, 0), t.mmap(t.REGION_PALETTE_RAM, this.palette), this.memoryDirtied(this.palette, 0)), 8 & e) { - this.vram = new MemoryProxy(this, t.SIZE_VRAM, 13), t.mmap(t.REGION_VRAM, this.vram); - for (var i = 0; i < this.vram.blocks.length; ++i) this.memoryDirtied(this.vram, i) - } - 16 & e && (this.oam = new MemoryProxy(this, t.SIZE_OAM, 0), t.mmap(t.REGION_OAM, this.oam), this.memoryDirtied(this.oam, 0)) -}, GameBoyAdvanceRenderProxy.prototype.setBacking = function(t) { - this.backing = t, this.worker.postMessage({ - type: "start", - backing: this.backing - }) -}, GameBoyAdvanceRenderProxy.prototype.drawScanline = function(t) { - if (!this.skipFrame && this.dirty) { - if (this.dirty.memory && (this.dirty.memory.palette && (this.dirty.memory.palette = this.dirty.memory.palette.slice(0)), this.dirty.memory.oam && (this.dirty.memory.oam = this.dirty.memory.oam.slice(0)), this.dirty.memory.vram)) - for (var e = 0; e < 12; ++e) this.dirty.memory.vram[e] && (this.dirty.memory.vram[e] = this.dirty.memory.vram[e].slice(0)); - this.scanlineQueue.push({ - y: t, - dirty: this.dirty - }), this.dirty = null - } -}, GameBoyAdvanceRenderProxy.prototype.startDraw = function() { - ++this.currentFrame, this.delay <= 0 && (this.skipFrame = !1), this.skipFrame || ++this.delay -}, GameBoyAdvanceRenderProxy.prototype.finishDraw = function(t) { - this.caller = t, this.skipFrame || (this.worker.postMessage({ - type: "finish", - scanlines: this.scanlineQueue, - frame: this.currentFrame - }), this.scanlineQueue = [], 2 < this.delay && (this.skipFrame = !0)) -}, MemoryAligned16.prototype.load8 = function(t) { - return this.loadU8(t) << 24 >> 24 -}, MemoryAligned16.prototype.load16 = function(t) { - return this.loadU16(t) << 16 >> 16 -}, MemoryAligned16.prototype.loadU8 = function(t) { - var e = t >> 1; - return 1 & t ? (65280 & this.buffer[e]) >>> 8 : 255 & this.buffer[e] -}, MemoryAligned16.prototype.loadU16 = function(t) { - return this.buffer[t >> 1] -}, MemoryAligned16.prototype.load32 = function(t) { - return this.buffer[t >> 1 & -2] | this.buffer[t >> 1 | 1] << 16 -}, MemoryAligned16.prototype.store8 = function(t, e) { - this.store16(t, e << 8 | e) -}, MemoryAligned16.prototype.store16 = function(t, e) { - this.buffer[t >> 1] = e -}, MemoryAligned16.prototype.store32 = function(t, e) { - var i = t >> 1; - this.store16(t, this.buffer[i] = 65535 & e), this.store16(t + 2, this.buffer[i + 1] = e >>> 16) -}, MemoryAligned16.prototype.insert = function(t, e) { - this.buffer.set(e, t) -}, MemoryAligned16.prototype.invalidatePage = function(t) {}, GameBoyAdvanceVRAM.prototype = Object.create(MemoryAligned16.prototype), GameBoyAdvanceOAM.prototype = Object.create(MemoryAligned16.prototype), GameBoyAdvanceOAM.prototype.overwrite = function(t) { - for (var e = 0; e < this.buffer.byteLength >> 1; ++e) this.store16(e << 1, t[e]) -}, GameBoyAdvanceOAM.prototype.store16 = function(t, e) { - var i = (1016 & t) >> 3, - r = this.objs[i], - s = this.scalerot[i >> 2]; - r.priority, r.disable, r.y; - switch (6 & t) { - case 0: - r.y = 255 & e; - var n = r.scalerot; - r.scalerot = 256 & e, r.scalerot ? (r.scalerotOam = this.scalerot[r.scalerotParam], r.doublesize = !!(512 & e), r.disable = 0, r.hflip = 0, r.vflip = 0) : (r.doublesize = !1, r.disable = 512 & e, n && (r.hflip = 8 & r.scalerotParam, r.vflip = 16 & r.scalerotParam)), r.mode = (3072 & e) >> 6, r.mosaic = 4096 & e, r.multipalette = 8192 & e, r.shape = (49152 & e) >> 14, r.recalcSize(); - break; - case 2: - r.x = 511 & e, r.scalerot ? (r.scalerotParam = (15872 & e) >> 9, r.scalerotOam = this.scalerot[r.scalerotParam], r.hflip = 0, r.vflip = 0, r.drawScanline = r.drawScanlineAffine) : (r.hflip = 4096 & e, r.vflip = 8192 & e, r.drawScanline = r.drawScanlineNormal), r.size = (49152 & e) >> 14, r.recalcSize(); - break; - case 4: - r.tileBase = 1023 & e, r.priority = (3072 & e) >> 10, r.palette = (61440 & e) >> 8; - break; - case 6: - switch (3 & i) { - case 0: - s.a = (e << 16) / 16777216; - break; - case 1: - s.b = (e << 16) / 16777216; - break; - case 2: - s.c = (e << 16) / 16777216; - break; - case 3: - s.d = (e << 16) / 16777216 - } - } - MemoryAligned16.prototype.store16.call(this, t, e) -}, GameBoyAdvancePalette.prototype.overwrite = function(t) { - for (var e = 0; e < 512; ++e) this.store16(e << 1, t[e]) -}, GameBoyAdvancePalette.prototype.loadU8 = function(t) { - return this.loadU16(t) >> 8 * (1 & t) & 255 -}, GameBoyAdvancePalette.prototype.loadU16 = function(t) { - return this.colors[(512 & t) >> 9][(511 & t) >> 1] -}, GameBoyAdvancePalette.prototype.load16 = function(t) { - return this.loadU16(t) << 16 >> 16 -}, GameBoyAdvancePalette.prototype.load32 = function(t) { - return this.loadU16(t) | this.loadU16(t + 2) << 16 -}, GameBoyAdvancePalette.prototype.store16 = function(t, e) { - var i = (512 & t) >> 9, - r = (511 & t) >> 1; - this.colors[i][r] = e, this.adjustedColors[i][r] = this.adjustColor(e) -}, GameBoyAdvancePalette.prototype.store32 = function(t, e) { - this.store16(t, 65535 & e), this.store16(t + 2, e >> 16) -}, GameBoyAdvancePalette.prototype.invalidatePage = function(t) {}, GameBoyAdvancePalette.prototype.convert16To32 = function(t, e) { - var i = (31 & t) << 3, - r = (992 & t) >> 2, - s = (31744 & t) >> 7; - e[0] = i, e[1] = r, e[2] = s -}, GameBoyAdvancePalette.prototype.mix = function(t, e, i, r) { - var s = 31 & e, - n = (992 & e) >> 5, - a = (31744 & e) >> 10, - o = 31 & r, - h = (992 & r) >> 5, - c = (31744 & r) >> 10; - return Math.min(t * s + i * o, 31) | Math.min(t * n + i * h, 31) << 5 | Math.min(t * a + i * c, 31) << 10 -}, GameBoyAdvancePalette.prototype.makeDarkPalettes = function(t) { - this.adjustColor != this.adjustColorDark && (this.adjustColor = this.adjustColorDark, this.resetPalettes()), this.resetPaletteLayers(t) -}, GameBoyAdvancePalette.prototype.makeBrightPalettes = function(t) { - this.adjustColor != this.adjustColorBright && (this.adjustColor = this.adjustColorBright, this.resetPalettes()), this.resetPaletteLayers(t) -}, GameBoyAdvancePalette.prototype.makeNormalPalettes = function() { - this.passthroughColors[0] = this.colors[0], this.passthroughColors[1] = this.colors[0], this.passthroughColors[2] = this.colors[0], this.passthroughColors[3] = this.colors[0], this.passthroughColors[4] = this.colors[1], this.passthroughColors[5] = this.colors[0] -}, GameBoyAdvancePalette.prototype.makeSpecialPalette = function(t) { - this.passthroughColors[t] = this.adjustedColors[4 == t ? 1 : 0] -}, GameBoyAdvancePalette.prototype.makeNormalPalette = function(t) { - this.passthroughColors[t] = this.colors[4 == t ? 1 : 0] -}, GameBoyAdvancePalette.prototype.resetPaletteLayers = function(t) { - this.passthroughColors[0] = 1 & t ? this.adjustedColors[0] : this.colors[0], this.passthroughColors[1] = 2 & t ? this.adjustedColors[0] : this.colors[0], this.passthroughColors[2] = 4 & t ? this.adjustedColors[0] : this.colors[0], this.passthroughColors[3] = 8 & t ? this.adjustedColors[0] : this.colors[0], this.passthroughColors[4] = 16 & t ? this.adjustedColors[1] : this.colors[1], this.passthroughColors[5] = 32 & t ? this.adjustedColors[0] : this.colors[0] -}, GameBoyAdvancePalette.prototype.resetPalettes = function() { - var t, e = this.adjustedColors[0], - i = this.colors[0]; - for (t = 0; t < 256; ++t) e[t] = this.adjustColor(i[t]); - for (e = this.adjustedColors[1], i = this.colors[1], t = 0; t < 256; ++t) e[t] = this.adjustColor(i[t]) -}, GameBoyAdvancePalette.prototype.accessColor = function(t, e) { - return this.passthroughColors[t][e] -}, GameBoyAdvancePalette.prototype.adjustColorDark = function(t) { - var e = 31 & t, - i = (992 & t) >> 5, - r = (31744 & t) >> 10; - return (e -= e * this.blendY) | (i -= i * this.blendY) << 5 | (r -= r * this.blendY) << 10 -}, GameBoyAdvancePalette.prototype.adjustColorBright = function(t) { - var e = 31 & t, - i = (992 & t) >> 5, - r = (31744 & t) >> 10; - return (e += (31 - e) * this.blendY) | (i += (31 - i) * this.blendY) << 5 | (r += (31 - r) * this.blendY) << 10 -}, GameBoyAdvancePalette.prototype.adjustColor = GameBoyAdvancePalette.prototype.adjustColorBright, GameBoyAdvancePalette.prototype.setBlendY = function(t) { - this.blendY != t && (this.blendY = t, this.resetPalettes()) -}, GameBoyAdvanceOBJ.prototype.drawScanlineNormal = function(t, e, i, r, s) { - var n, a, o, h = this.oam.video, - c = this.mode | h.target2[h.LAYER_OBJ] | this.priority << 1; - 16 == this.mode && (c |= h.TARGET1_MASK), 1 == h.blendMode && h.alphaEnabled && (c |= h.target1[h.LAYER_OBJ]); - var u, d, p = this.cachedWidth; - this.x < h.HORIZONTAL_PIXELS ? (this.x < r ? (a = r - this.x, o = r) : (a = 0, o = this.x), s < this.cachedWidth + this.x && (p = s - this.x)) : (a = r + 512 - this.x, o = r, s < this.cachedWidth - a && (p = s)); - var l, f, m = 7 & (d = this.vflip ? this.cachedHeight - e + i - 1 : e - i), - y = this.multipalette ? 1 : 0; - f = h.objCharacterMapping ? (504 & d) * this.cachedWidth >> 6 : (504 & d) << 2 - y, this.mosaic && (o += l = h.objMosaicX - 1 - (h.objMosaicX + o - 1) % h.objMosaicX, a += l), u = this.hflip ? this.cachedWidth - a - 1 : a; - var v = h.accessTile(this.TILE_OFFSET + (4 & n) * y, this.tileBase + (f << y) + ((504 & u) >> 3 - y), m << y); - for (n = a; n < p; ++n) l = this.mosaic ? o % h.objMosaicX : 0, u = this.hflip ? this.cachedWidth - (n - l) - 1 : n - l, y ? 3 & n && (!this.mosaic || l) || (v = h.accessTile(this.TILE_OFFSET + (4 & u), this.tileBase + (f << 1) + ((504 & u) >> 2), m << 1)) : 7 & n && (!this.mosaic || l) || (v = h.accessTile(this.TILE_OFFSET, this.tileBase + f + (u >> 3), m)), this.pushPixel(h.LAYER_OBJ, this, h, v, 7 & u, o, t, c, !1), o++ -}, GameBoyAdvanceOBJ.prototype.drawScanlineAffine = function(t, e, i, r, s) { - var n, a, o, h, c, u = this.oam.video, - d = this.mode | u.target2[u.LAYER_OBJ] | this.priority << 1; - 16 == this.mode && (d |= u.TARGET1_MASK), 1 == u.blendMode && u.alphaEnabled && (d |= u.target1[u.LAYER_OBJ]); - var p, l = e - i, - f = this.multipalette ? 1 : 0, - m = this.cachedWidth << this.doublesize, - y = this.cachedHeight << this.doublesize, - v = m; - for (v > u.HORIZONTAL_PIXELS && (m = u.HORIZONTAL_PIXELS), this.x < u.HORIZONTAL_PIXELS ? (this.x < r ? (a = r - this.x, o = r) : (a = 0, o = this.x), s < v + this.x && (v = s - this.x)) : s < v - (a = (o = r) + 512 - this.x) && (v = s), n = a; n < v; ++n) h = this.scalerotOam.a * (n - (m >> 1)) + this.scalerotOam.b * (l - (y >> 1)) + (this.cachedWidth >> 1), c = this.scalerotOam.c * (n - (m >> 1)) + this.scalerotOam.d * (l - (y >> 1)) + (this.cachedHeight >> 1), this.mosaic && (h -= n % u.objMosaicX * this.scalerotOam.a + e % u.objMosaicY * this.scalerotOam.b, c -= n % u.objMosaicX * this.scalerotOam.c + e % u.objMosaicY * this.scalerotOam.d), h < 0 || h >= this.cachedWidth || c < 0 || c >= this.cachedHeight || (p = u.objCharacterMapping ? (504 & c) * this.cachedWidth >> 6 : (504 & c) << 2 - f, tileRow = u.accessTile(this.TILE_OFFSET + (4 & h) * f, this.tileBase + (p << f) + ((504 & h) >> 3 - f), (7 & c) << f), this.pushPixel(u.LAYER_OBJ, this, u, tileRow, 7 & h, o, t, d, !1)), o++ -}, GameBoyAdvanceOBJ.prototype.recalcSize = function() { - switch (this.shape) { - case 0: - this.cachedHeight = this.cachedWidth = 8 << this.size; - break; - case 1: - switch (this.size) { - case 0: - this.cachedHeight = 8, this.cachedWidth = 16; - break; - case 1: - this.cachedHeight = 8, this.cachedWidth = 32; - break; - case 2: - this.cachedHeight = 16, this.cachedWidth = 32; - break; - case 3: - this.cachedHeight = 32, this.cachedWidth = 64 - } - break; - case 2: - switch (this.size) { - case 0: - this.cachedHeight = 16, this.cachedWidth = 8; - break; - case 1: - this.cachedHeight = 32, this.cachedWidth = 8; - break; - case 2: - this.cachedHeight = 32, this.cachedWidth = 16; - break; - case 3: - this.cachedHeight = 64, this.cachedWidth = 32 - } - } -}, GameBoyAdvanceOBJLayer.prototype.drawScanline = function(t, e, i, r) { - var s, n, a, o = this.video.vcount; - if (!(r <= i)) - for (var h = this.video.oam.objs, c = 0; c < h.length; ++c) { - var u; - if (!(a = h[c]).disable) - if ((a.mode & this.video.OBJWIN_MASK) == this.objwin) - if (a.mode & this.video.OBJWIN_MASK || this.priority == a.priority) s = a.y < this.video.VERTICAL_PIXELS ? a.y : a.y - 256, u = a.scalerot ? a.cachedHeight << a.doublesize : a.cachedHeight, n = a.mosaic ? o - o % this.video.objMosaicY : o, s <= o && o < s + u && a.drawScanline(t, n, s, i, r) - } -}, GameBoyAdvanceOBJLayer.prototype.objComparator = function(t, e) { - return t.index - e.index -}, GameBoyAdvanceSoftwareRenderer.prototype.clear = function(t) { - this.palette = new GameBoyAdvancePalette, this.vram = new GameBoyAdvanceVRAM(t.SIZE_VRAM), this.oam = new GameBoyAdvanceOAM(t.SIZE_OAM), (this.oam.video = this).objLayers = [new GameBoyAdvanceOBJLayer(this, 0), new GameBoyAdvanceOBJLayer(this, 1), new GameBoyAdvanceOBJLayer(this, 2), new GameBoyAdvanceOBJLayer(this, 3)], this.objwinLayer = new GameBoyAdvanceOBJLayer(this, 4), this.objwinLayer.objwin = this.OBJWIN_MASK, this.backgroundMode = 0, this.displayFrameSelect = 0, this.hblankIntervalFree = 0, this.objCharacterMapping = 0, this.forcedBlank = 1, this.win0 = 0, this.win1 = 0, this.objwin = 0, this.vcount = -1, this.win0Left = 0, this.win0Right = 240, this.win1Left = 0, this.win1Right = 240, this.win0Top = 0, this.win0Bottom = 160, this.win1Top = 0, this.win1Bottom = 160, this.windows = new Array; - for (var e = 0; e < 4; ++e) this.windows.push({ - enabled: [!1, !1, !1, !1, !1, !0], - special: 0 - }); - this.target1 = new Array(5), this.target2 = new Array(5), this.blendMode = 0, this.blendA = 0, this.blendB = 0, this.blendY = 0, this.bgMosaicX = 1, this.bgMosaicY = 1, this.objMosaicX = 1, this.objMosaicY = 1, this.lastHblank = 0, this.nextHblank = this.HDRAW_LENGTH, this.nextEvent = this.nextHblank, this.nextHblankIRQ = 0, this.nextVblankIRQ = 0, this.nextVcounterIRQ = 0, this.bg = new Array; - for (e = 0; e < 4; ++e) this.bg.push({ - bg: !0, - index: e, - enabled: !1, - video: this, - vram: this.vram, - priority: 0, - charBase: 0, - mosaic: !1, - multipalette: !1, - screenBase: 0, - overflow: 0, - size: 0, - x: 0, - y: 0, - refx: 0, - refy: 0, - dx: 1, - dmx: 0, - dy: 0, - dmy: 1, - sx: 0, - sy: 0, - pushPixel: GameBoyAdvanceSoftwareRenderer.pushPixel, - drawScanline: this.drawScanlineBGMode0 - }); - this.bgModes = [this.drawScanlineBGMode0, this.drawScanlineBGMode2, this.drawScanlineBGMode2, this.drawScanlineBGMode3, this.drawScanlineBGMode4, this.drawScanlineBGMode5], this.drawLayers = [this.bg[0], this.bg[1], this.bg[2], this.bg[3], this.objLayers[0], this.objLayers[1], this.objLayers[2], this.objLayers[3], this.objwinLayer, this.drawBackdrop], objwinActive = !1, this.alphaEnabled = !1, this.scanline = { - color: new Uint16Array(this.HORIZONTAL_PIXELS), - stencil: new Uint8Array(this.HORIZONTAL_PIXELS) - }, this.sharedColor = [0, 0, 0], this.sharedMap = { - tile: 0, - hflip: !1, - vflip: !1, - palette: 0 - } -}, GameBoyAdvanceSoftwareRenderer.prototype.clearSubsets = function(t, e) { - 4 & e && this.palette.overwrite(new Uint16Array(t.SIZE_PALETTE >> 1)), 8 & e && this.vram.insert(0, new Uint16Array(t.SIZE_VRAM >> 1)), 16 & e && (this.oam.overwrite(new Uint16Array(t.SIZE_OAM >> 1)), this.oam.video = this) -}, GameBoyAdvanceSoftwareRenderer.prototype.freeze = function() {}, GameBoyAdvanceSoftwareRenderer.prototype.defrost = function(t) {}, GameBoyAdvanceSoftwareRenderer.prototype.setBacking = function(t) { - this.pixelData = t; - for (var e = 0; e < this.HORIZONTAL_PIXELS * this.VERTICAL_PIXELS * 4;) this.pixelData.data[e++] = 255, this.pixelData.data[e++] = 255, this.pixelData.data[e++] = 255, this.pixelData.data[e++] = 255 -}, GameBoyAdvanceSoftwareRenderer.prototype.writeDisplayControl = function(t) { - this.backgroundMode = 7 & t, this.displayFrameSelect = 16 & t, this.hblankIntervalFree = 32 & t, this.objCharacterMapping = 64 & t, this.forcedBlank = 128 & t, this.bg[0].enabled = 256 & t, this.bg[1].enabled = 512 & t, this.bg[2].enabled = 1024 & t, this.bg[3].enabled = 2048 & t, this.objLayers[0].enabled = 4096 & t, this.objLayers[1].enabled = 4096 & t, this.objLayers[2].enabled = 4096 & t, this.objLayers[3].enabled = 4096 & t, this.win0 = 8192 & t, this.win1 = 16384 & t, this.objwin = 32768 & t, this.objwinLayer.enabled = 4096 & t && 32768 & t, this.bg[2].multipalette &= -2, this.bg[3].multipalette &= -2, 0 < this.backgroundMode && (this.bg[2].multipalette |= 1), 2 == this.backgroundMode && (this.bg[3].multipalette |= 1), this.resetLayers() -}, GameBoyAdvanceSoftwareRenderer.prototype.writeBackgroundControl = function(t, e) { - var i = this.bg[t]; - i.priority = 3 & e, i.charBase = (12 & e) << 12, i.mosaic = 64 & e, i.multipalette &= -129, (t < 2 || 0 == this.backgroundMode) && (i.multipalette |= 128 & e), i.screenBase = (7936 & e) << 3, i.overflow = 8192 & e, i.size = (49152 & e) >> 14, this.drawLayers.sort(this.layerComparator) -}, GameBoyAdvanceSoftwareRenderer.prototype.writeBackgroundHOffset = function(t, e) { - this.bg[t].x = 511 & e -}, GameBoyAdvanceSoftwareRenderer.prototype.writeBackgroundVOffset = function(t, e) { - this.bg[t].y = 511 & e -}, GameBoyAdvanceSoftwareRenderer.prototype.writeBackgroundRefX = function(t, e) { - this.bg[t].refx = (e << 4) / 4096, this.bg[t].sx = this.bg[t].refx -}, GameBoyAdvanceSoftwareRenderer.prototype.writeBackgroundRefY = function(t, e) { - this.bg[t].refy = (e << 4) / 4096, this.bg[t].sy = this.bg[t].refy -}, GameBoyAdvanceSoftwareRenderer.prototype.writeBackgroundParamA = function(t, e) { - this.bg[t].dx = (e << 16) / 16777216 -}, GameBoyAdvanceSoftwareRenderer.prototype.writeBackgroundParamB = function(t, e) { - this.bg[t].dmx = (e << 16) / 16777216 -}, GameBoyAdvanceSoftwareRenderer.prototype.writeBackgroundParamC = function(t, e) { - this.bg[t].dy = (e << 16) / 16777216 -}, GameBoyAdvanceSoftwareRenderer.prototype.writeBackgroundParamD = function(t, e) { - this.bg[t].dmy = (e << 16) / 16777216 -}, GameBoyAdvanceSoftwareRenderer.prototype.writeWin0H = function(t) { - this.win0Left = (65280 & t) >> 8, this.win0Right = Math.min(this.HORIZONTAL_PIXELS, 255 & t), this.win0Left > this.win0Right && (this.win0Right = this.HORIZONTAL_PIXELS) -}, GameBoyAdvanceSoftwareRenderer.prototype.writeWin1H = function(t) { - this.win1Left = (65280 & t) >> 8, this.win1Right = Math.min(this.HORIZONTAL_PIXELS, 255 & t), this.win1Left > this.win1Right && (this.win1Right = this.HORIZONTAL_PIXELS) -}, GameBoyAdvanceSoftwareRenderer.prototype.writeWin0V = function(t) { - this.win0Top = (65280 & t) >> 8, this.win0Bottom = Math.min(this.VERTICAL_PIXELS, 255 & t), this.win0Top > this.win0Bottom && (this.win0Bottom = this.VERTICAL_PIXELS) -}, GameBoyAdvanceSoftwareRenderer.prototype.writeWin1V = function(t) { - this.win1Top = (65280 & t) >> 8, this.win1Bottom = Math.min(this.VERTICAL_PIXELS, 255 & t), this.win1Top > this.win1Bottom && (this.win1Bottom = this.VERTICAL_PIXELS) -}, GameBoyAdvanceSoftwareRenderer.prototype.writeWindow = function(t, e) { - var i = this.windows[t]; - i.enabled[0] = 1 & e, i.enabled[1] = 2 & e, i.enabled[2] = 4 & e, i.enabled[3] = 8 & e, i.enabled[4] = 16 & e, i.special = 32 & e -}, GameBoyAdvanceSoftwareRenderer.prototype.writeWinIn = function(t) { - this.writeWindow(0, t), this.writeWindow(1, t >> 8) -}, GameBoyAdvanceSoftwareRenderer.prototype.writeWinOut = function(t) { - this.writeWindow(2, t), this.writeWindow(3, t >> 8) -}, GameBoyAdvanceSoftwareRenderer.prototype.writeBlendControl = function(t) { - switch (this.target1[0] = !!(1 & t) * this.TARGET1_MASK, this.target1[1] = !!(2 & t) * this.TARGET1_MASK, this.target1[2] = !!(4 & t) * this.TARGET1_MASK, this.target1[3] = !!(8 & t) * this.TARGET1_MASK, this.target1[4] = !!(16 & t) * this.TARGET1_MASK, this.target1[5] = !!(32 & t) * this.TARGET1_MASK, this.target2[0] = !!(256 & t) * this.TARGET2_MASK, this.target2[1] = !!(512 & t) * this.TARGET2_MASK, this.target2[2] = !!(1024 & t) * this.TARGET2_MASK, this.target2[3] = !!(2048 & t) * this.TARGET2_MASK, this.target2[4] = !!(4096 & t) * this.TARGET2_MASK, this.target2[5] = !!(8192 & t) * this.TARGET2_MASK, this.blendMode = (192 & t) >> 6, this.blendMode) { - case 1: - case 0: - this.palette.makeNormalPalettes(); - break; - case 2: - this.palette.makeBrightPalettes(63 & t); - break; - case 3: - this.palette.makeDarkPalettes(63 & t) - } -}, GameBoyAdvanceSoftwareRenderer.prototype.setBlendEnabled = function(t, e, i) { - if (this.alphaEnabled = e && 1 == i, e) switch (i) { - case 1: - case 0: - this.palette.makeNormalPalette(t); - break; - case 2: - case 3: - this.palette.makeSpecialPalette(t) - } else this.palette.makeNormalPalette(t) -}, GameBoyAdvanceSoftwareRenderer.prototype.writeBlendAlpha = function(t) { - this.blendA = (31 & t) / 16, 1 < this.blendA && (this.blendA = 1), this.blendB = ((7936 & t) >> 8) / 16, 1 < this.blendB && (this.blendB = 1) -}, GameBoyAdvanceSoftwareRenderer.prototype.writeBlendY = function(t) { - this.blendY = t, this.palette.setBlendY(16 <= t ? 1 : t / 16) -}, GameBoyAdvanceSoftwareRenderer.prototype.writeMosaic = function(t) { - this.bgMosaicX = 1 + (15 & t), this.bgMosaicY = 1 + (t >> 4 & 15), this.objMosaicX = 1 + (t >> 8 & 15), this.objMosaicY = 1 + (t >> 12 & 15) -}, GameBoyAdvanceSoftwareRenderer.prototype.resetLayers = function() { - 1 < this.backgroundMode && (this.bg[0].enabled = !1, this.bg[1].enabled = !1), this.bg[2].enabled && (this.bg[2].drawScanline = this.bgModes[this.backgroundMode]), 0 == this.backgroundMode || 2 == this.backgroundMode ? this.bg[3].enabled && (this.bg[3].drawScanline = this.bgModes[this.backgroundMode]) : this.bg[3].enabled = !1, this.drawLayers.sort(this.layerComparator) -}, GameBoyAdvanceSoftwareRenderer.prototype.layerComparator = function(t, e) { - var i = e.priority - t.priority; - return i || (t.bg && !e.bg ? -1 : !t.bg && e.bg ? 1 : e.index - t.index) -}, GameBoyAdvanceSoftwareRenderer.prototype.accessMapMode0 = function(t, e, i, r, s) { - var n = t + (i >> 2 & 62) + r; - 1 & e && (n += (256 & i) << 3); - var a = this.vram.loadU16(n); - s.tile = 1023 & a, s.hflip = 1024 & a, s.vflip = 2048 & a, s.palette = (61440 & a) >> 8 -}, GameBoyAdvanceSoftwareRenderer.prototype.accessMapMode1 = function(t, e, i, r, s) { - var n = t + (i >> 3) + r; - s.tile = this.vram.loadU8(n) -}, GameBoyAdvanceSoftwareRenderer.prototype.accessTile = function(t, e, i) { - var r = t + (e << 5); - return r |= i << 2, this.vram.load32(r) -}, GameBoyAdvanceSoftwareRenderer.pushPixel = function(t, e, i, r, s, n, a, o, h) { - var c; - if (!h) { - if (!(c = this.multipalette ? r >> (s << 3) & 255 : r >> (s << 2) & 15)) return; - this.multipalette || (c |= e.palette) - } - var u = i.WRITTEN_MASK, - d = a.stencil[n], - p = i.blendMode; - if (i.objwinActive) - if (d & i.OBJWIN_MASK) { - if (!i.windows[3].enabled[t]) return; - i.setBlendEnabled(t, i.windows[3].special && i.target1[t], p), i.windows[3].special && i.alphaEnabled && (o |= i.target1[t]), u |= i.OBJWIN_MASK - } else { - if (!i.windows[2].enabled[t]) return; - i.setBlendEnabled(t, i.windows[2].special && i.target1[t], p), i.windows[2].special && i.alphaEnabled && (o |= i.target1[t]) - } - o & i.TARGET1_MASK && d & i.TARGET2_MASK && i.setBlendEnabled(t, !0, 1); - var l = h ? r : i.palette.accessColor(t, c); - o & i.TARGET1_MASK && i.setBlendEnabled(t, !!p, p); - var f = (o & i.PRIORITY_MASK) < (d & i.PRIORITY_MASK); - if ((o & i.PRIORITY_MASK) == (d & i.PRIORITY_MASK) && (f = o & i.BACKGROUND_MASK), d & i.WRITTEN_MASK) - if (f) o & i.TARGET1_MASK && d & i.TARGET2_MASK && (l = i.palette.mix(i.blendA, l, i.blendB, a.color[n])), u |= o & ~i.TARGET1_MASK; - else { - if (!((o & i.PRIORITY_MASK) > (d & i.PRIORITY_MASK))) return; - if (u = d & ~(i.TARGET1_MASK | i.TARGET2_MASK), !(o & i.TARGET2_MASK && d & i.TARGET1_MASK)) return; - l = i.palette.mix(i.blendB, l, i.blendA, a.color[n]) - } else u |= o; - o & i.OBJWIN_MASK ? a.stencil[n] |= i.OBJWIN_MASK : (a.color[n] = l, a.stencil[n] = u) -}, GameBoyAdvanceSoftwareRenderer.prototype.identity = function(t) { - return t -}, GameBoyAdvanceSoftwareRenderer.prototype.drawScanlineBlank = function(t) { - for (var e = 0; e < this.HORIZONTAL_PIXELS; ++e) t.color[e] = 65535, t.stencil[e] = 0 -}, GameBoyAdvanceSoftwareRenderer.prototype.prepareScanline = function(t) { - for (var e = 0; e < this.HORIZONTAL_PIXELS; ++e) t.stencil[e] = this.target2[this.LAYER_BACKDROP] -}, GameBoyAdvanceSoftwareRenderer.prototype.drawScanlineBGMode0 = function(t, e, i, r) { - var s, n, a, o = this.video, - h = o.vcount, - c = i, - u = e.x, - d = h + e.y; - this.mosaic && (d -= h % o.bgMosaicY); - var p, l = 7 & d, - f = e.screenBase, - m = e.charBase, - y = e.size, - v = e.index, - A = o.sharedMap, - b = e.multipalette ? 1 : 0, - g = o.target2[v] | e.priority << 1 | o.BACKGROUND_MASK; - 1 == o.blendMode && o.alphaEnabled && (g |= o.target1[v]); - var S, R = d << 3 & 1984; - 2 == y ? R += d << 3 & 2048 : 3 == y && (R += d << 4 & 4096), S = 1 & y ? 511 : 255, o.accessMapMode0(f, y, i + u & S, R, A); - var C = o.accessTile(m, A.tile << b, (A.vflip ? 7 - l : l) << b); - for (s = i; s < r; ++s) { - if (n = s + u & S, a = 7 & (n -= p = this.mosaic ? c % o.bgMosaicX : 0), b) { - if ((!a || this.mosaic && !p) && o.accessMapMode0(f, y, n, R, A), (!(3 & a) || this.mosaic && !p) && !((C = o.accessTile(m + (!!(4 & n) == !A.hflip ? 4 : 0), A.tile << 1, (A.vflip ? 7 - l : l) << 1)) || 3 & a)) { - s += 3, c += 4; - continue - } - } else if ((!a || this.mosaic && !p) && (o.accessMapMode0(f, y, n, R, A), !(C = o.accessTile(m, A.tile, A.vflip ? 7 - l : l)) && !a)) { - s += 7, c += 8; - continue - } - A.hflip && (a = 7 - a), e.pushPixel(v, A, o, C, a, c, t, g, !1), c++ - } -}, GameBoyAdvanceSoftwareRenderer.prototype.drawScanlineBGMode2 = function(t, e, i, r) { - var s, n, a, o, h, c = this.video, - u = c.vcount, - d = i, - p = e.screenBase, - l = e.charBase, - f = e.size, - m = 128 << f, - y = e.index, - v = c.sharedMap, - A = c.target2[y] | e.priority << 1 | c.BACKGROUND_MASK; - for (1 == c.blendMode && c.alphaEnabled && (A |= c.target1[y]), s = i; s < r; ++s) { - if (n = e.dx * s + e.sx, a = e.dy * s + e.sy, this.mosaic && (n -= s % c.bgMosaicX * e.dx + u % c.bgMosaicY * e.dmx, a -= s % c.bgMosaicX * e.dy + u % c.bgMosaicY * e.dmy), e.overflow)(n &= m - 1) < 0 && (n += m), (a &= m - 1) < 0 && (a += m); - else if (n < 0 || a < 0 || m <= n || m <= a) { - d++; - continue - } - h = (a << 1 & 2032) << f, c.accessMapMode1(p, f, n, h, v), o = this.vram.loadU8(l + (v.tile << 6) + ((7 & a) << 3) + (7 & n)), e.pushPixel(y, v, c, o, 0, d, t, A, !1), d++ - } -}, GameBoyAdvanceSoftwareRenderer.prototype.drawScanlineBGMode3 = function(t, e, i, r) { - var s, n, a, o, h = this.video, - c = h.vcount, - u = i, - d = e.index, - p = h.sharedMap, - l = h.target2[d] | e.priority << 1 | h.BACKGROUND_MASK; - for (1 == h.blendMode && h.alphaEnabled && (l |= h.target1[d]), s = i; s < r; ++s) n = e.dx * s + e.sx, a = e.dy * s + e.sy, this.mosaic && (n -= s % h.bgMosaicX * e.dx + c % h.bgMosaicY * e.dmx, a -= s % h.bgMosaicX * e.dy + c % h.bgMosaicY * e.dmy), n < 0 || a < 0 || n >= h.HORIZONTAL_PIXELS || a >= h.VERTICAL_PIXELS || (o = this.vram.loadU16(a * h.HORIZONTAL_PIXELS + n << 1), e.pushPixel(d, p, h, o, 0, u, t, l, !0)), u++ -}, GameBoyAdvanceSoftwareRenderer.prototype.drawScanlineBGMode4 = function(t, e, i, r) { - var s, n, a, o = this.video, - h = o.vcount, - c = i, - u = 0; - o.displayFrameSelect && (u += 40960); - e.size; - var d, p = e.index, - l = o.sharedMap, - f = o.target2[p] | e.priority << 1 | o.BACKGROUND_MASK; - for (1 == o.blendMode && o.alphaEnabled && (f |= o.target1[p]), s = i; s < r; ++s) n = e.dx * s + e.sx, a = 0 | e.dy * s + e.sy, this.mosaic && (n -= s % o.bgMosaicX * e.dx + h % o.bgMosaicY * e.dmx, a -= s % o.bgMosaicX * e.dy + h % o.bgMosaicY * e.dmy), a << 2 & 2016, n < 0 || a < 0 || n >= o.HORIZONTAL_PIXELS || a >= o.VERTICAL_PIXELS || (d = this.vram.loadU8(u + a * o.HORIZONTAL_PIXELS + n), e.pushPixel(p, l, o, d, 0, c, t, f, !1)), c++ -}, GameBoyAdvanceSoftwareRenderer.prototype.drawScanlineBGMode5 = function(t, e, i, r) { - var s, n, a, o = this.video, - h = o.vcount, - c = i, - u = 0; - o.displayFrameSelect && (u += 40960); - var d, p = e.index, - l = o.sharedMap, - f = o.target2[p] | e.priority << 1 | o.BACKGROUND_MASK; - for (1 == o.blendMode && o.alphaEnabled && (f |= o.target1[p]), s = i; s < r; ++s) n = e.dx * s + e.sx, a = e.dy * s + e.sy, this.mosaic && (n -= s % o.bgMosaicX * e.dx + h % o.bgMosaicY * e.dmx, a -= s % o.bgMosaicX * e.dy + h % o.bgMosaicY * e.dmy), n < 0 || a < 0 || 160 <= n || 128 <= a || (d = this.vram.loadU16(u + (160 * a + n) << 1), e.pushPixel(p, l, o, d, 0, c, t, f, !0)), c++ -}, GameBoyAdvanceSoftwareRenderer.prototype.drawScanline = function(t) { - var e = this.scanline; - if (this.forcedBlank) this.drawScanlineBlank(e); - else { - var i, r, s, n, a; - this.prepareScanline(e), this.vcount = t; - for (var o = 0; o < this.drawLayers.length; ++o)(i = this.drawLayers[o]).enabled && (this.objwinActive = !1, this.win0 || this.win1 || this.objwin ? (r = 0, s = this.HORIZONTAL_PIXELS, n = 0, a = this.HORIZONTAL_PIXELS, this.win0 && t >= this.win0Top && t < this.win0Bottom && (this.windows[0].enabled[i.index] && (this.setBlendEnabled(i.index, this.windows[0].special && this.target1[i.index], this.blendMode), i.drawScanline(e, i, this.win0Left, this.win0Right)), r = Math.max(r, this.win0Left), s = Math.min(s, this.win0Left), n = Math.max(n, this.win0Right), a = Math.min(a, this.win0Right)), this.win1 && t >= this.win1Top && t < this.win1Bottom && (this.windows[1].enabled[i.index] && (this.setBlendEnabled(i.index, this.windows[1].special && this.target1[i.index], this.blendMode), !this.windows[0].enabled[i.index] && (this.win1Left < r || this.win1Right < n) ? (i.drawScanline(e, i, this.win1Left, r), i.drawScanline(e, i, a, this.win1Right)) : i.drawScanline(e, i, this.win1Left, this.win1Right)), r = Math.max(r, this.win1Left), s = Math.min(s, this.win1Left), n = Math.max(n, this.win1Right), a = Math.min(a, this.win1Right)), (this.windows[2].enabled[i.index] || this.objwin && this.windows[3].enabled[i.index]) && (this.objwinActive = this.objwin, this.setBlendEnabled(i.index, this.windows[2].special && this.target1[i.index], this.blendMode), n < s ? i.drawScanline(e, i, 0, this.HORIZONTAL_PIXELS) : (s && i.drawScanline(e, i, 0, s), n < this.HORIZONTAL_PIXELS && i.drawScanline(e, i, n, this.HORIZONTAL_PIXELS), a < r && i.drawScanline(e, i, a, r))), this.setBlendEnabled(this.LAYER_BACKDROP, this.target1[this.LAYER_BACKDROP] && this.windows[2].special, this.blendMode)) : (this.setBlendEnabled(i.index, this.target1[i.index], this.blendMode), i.drawScanline(e, i, 0, this.HORIZONTAL_PIXELS)), i.bg && (i.sx += i.dmx, i.sy += i.dmy)); - this.finishScanline(e) - } -}, GameBoyAdvanceSoftwareRenderer.prototype.finishScanline = function(t) { - for (var e, i = this.palette.accessColor(this.LAYER_BACKDROP, 0), r = this.vcount * this.HORIZONTAL_PIXELS * 4, s = this.target2[this.LAYER_BACKDROP], n = 0; n < this.HORIZONTAL_PIXELS; ++n) t.stencil[n] & this.WRITTEN_MASK ? (e = t.color[n], s && t.stencil[n] & this.TARGET1_MASK && (e = this.palette.mix(this.blendA, e, this.blendB, i)), this.palette.convert16To32(e, this.sharedColor)) : this.palette.convert16To32(i, this.sharedColor), this.pixelData.data[r++] = this.sharedColor[0], this.pixelData.data[r++] = this.sharedColor[1], this.pixelData.data[r++] = this.sharedColor[2], r++ -}, GameBoyAdvanceSoftwareRenderer.prototype.startDraw = function() {}, GameBoyAdvanceSoftwareRenderer.prototype.finishDraw = function(t) { - this.bg[2].sx = this.bg[2].refx, this.bg[2].sy = this.bg[2].refy, this.bg[3].sx = this.bg[3].refx, this.bg[3].sy = this.bg[3].refy, t.finishDraw(this.pixelData) -}, GameBoyAdvanceInterruptHandler.prototype.clear = function() { - this.enable = !1, this.enabledIRQs = 0, this.interruptFlags = 0, this.dma = new Array; - for (var t = 0; t < 4; ++t) this.dma.push({ - source: 0, - dest: 0, - count: 0, - nextSource: 0, - nextDest: 0, - nextCount: 0, - srcControl: 0, - dstControl: 0, - repeat: !1, - width: 0, - drq: !1, - timing: 0, - doIrq: !1, - enable: !1, - nextIRQ: 0 - }); - this.timersEnabled = 0, this.timers = new Array; - for (t = 0; t < 4; ++t) this.timers.push({ - reload: 0, - oldReload: 0, - prescaleBits: 0, - countUp: !1, - doIrq: !1, - enable: !1, - lastEvent: 0, - nextEvent: 0, - overflowInterval: 1 - }); - this.nextEvent = 0, this.springIRQ = !1, this.resetSP() -}, GameBoyAdvanceInterruptHandler.prototype.freeze = function() { - return { - enable: this.enable, - enabledIRQs: this.enabledIRQs, - interruptFlags: this.interruptFlags, - dma: this.dma, - timers: this.timers, - nextEvent: this.nextEvent, - springIRQ: this.springIRQ - } -}, GameBoyAdvanceInterruptHandler.prototype.defrost = function(t) { - this.enable = t.enable, this.enabledIRQs = t.enabledIRQs, this.interruptFlags = t.interruptFlags, this.dma = t.dma, this.timers = t.timers, this.timersEnabled = 0, this.timers[0].enable && ++this.timersEnabled, this.timers[1].enable && ++this.timersEnabled, this.timers[2].enable && ++this.timersEnabled, this.timers[3].enable && ++this.timersEnabled, this.nextEvent = t.nextEvent, this.springIRQ = t.springIRQ -}, GameBoyAdvanceInterruptHandler.prototype.updateTimers = function() { - if (!(this.nextEvent > this.cpu.cycles)) { - if (this.springIRQ && (this.cpu.raiseIRQ(), this.springIRQ = !1), this.video.updateTimers(this.cpu), this.audio.updateTimers(), this.timersEnabled) { - var t = this.timers[0]; - t.enable && this.cpu.cycles >= t.nextEvent && (t.lastEvent = t.nextEvent, t.nextEvent += t.overflowInterval, this.io.registers[this.io.TM0CNT_LO >> 1] = t.reload, t.oldReload = t.reload, t.doIrq && this.raiseIRQ(this.IRQ_TIMER0), this.audio.enabled && (this.audio.enableChannelA && !this.audio.soundTimerA && 0 <= this.audio.dmaA && this.audio.sampleFifoA(), this.audio.enableChannelB && !this.audio.soundTimerB && 0 <= this.audio.dmaB && this.audio.sampleFifoB()), (t = this.timers[1]).countUp && 65536 == ++this.io.registers[this.io.TM1CNT_LO >> 1] && (t.nextEvent = this.cpu.cycles)), (t = this.timers[1]).enable && this.cpu.cycles >= t.nextEvent && (t.lastEvent = t.nextEvent, t.nextEvent += t.overflowInterval, t.countUp && 65536 != this.io.registers[this.io.TM1CNT_LO >> 1] || (this.io.registers[this.io.TM1CNT_LO >> 1] = t.reload), t.oldReload = t.reload, t.doIrq && this.raiseIRQ(this.IRQ_TIMER1), t.countUp && (t.nextEvent = 0), this.audio.enabled && (this.audio.enableChannelA && this.audio.soundTimerA && 0 <= this.audio.dmaA && this.audio.sampleFifoA(), this.audio.enableChannelB && this.audio.soundTimerB && 0 <= this.audio.dmaB && this.audio.sampleFifoB()), (t = this.timers[2]).countUp && 65536 == ++this.io.registers[this.io.TM2CNT_LO >> 1] && (t.nextEvent = this.cpu.cycles)), (t = this.timers[2]).enable && this.cpu.cycles >= t.nextEvent && (t.lastEvent = t.nextEvent, t.nextEvent += t.overflowInterval, t.countUp && 65536 != this.io.registers[this.io.TM2CNT_LO >> 1] || (this.io.registers[this.io.TM2CNT_LO >> 1] = t.reload), t.oldReload = t.reload, t.doIrq && this.raiseIRQ(this.IRQ_TIMER2), t.countUp && (t.nextEvent = 0), (t = this.timers[3]).countUp && 65536 == ++this.io.registers[this.io.TM3CNT_LO >> 1] && (t.nextEvent = this.cpu.cycles)), (t = this.timers[3]).enable && this.cpu.cycles >= t.nextEvent && (t.lastEvent = t.nextEvent, t.nextEvent += t.overflowInterval, t.countUp && 65536 != this.io.registers[this.io.TM3CNT_LO >> 1] || (this.io.registers[this.io.TM3CNT_LO >> 1] = t.reload), t.oldReload = t.reload, t.doIrq && this.raiseIRQ(this.IRQ_TIMER3), t.countUp && (t.nextEvent = 0)) - } - var e = this.dma[0]; - e.enable && e.doIrq && e.nextIRQ && this.cpu.cycles >= e.nextIRQ && (e.nextIRQ = 0, this.raiseIRQ(this.IRQ_DMA0)), (e = this.dma[1]).enable && e.doIrq && e.nextIRQ && this.cpu.cycles >= e.nextIRQ && (e.nextIRQ = 0, this.raiseIRQ(this.IRQ_DMA1)), (e = this.dma[2]).enable && e.doIrq && e.nextIRQ && this.cpu.cycles >= e.nextIRQ && (e.nextIRQ = 0, this.raiseIRQ(this.IRQ_DMA2)), (e = this.dma[3]).enable && e.doIrq && e.nextIRQ && this.cpu.cycles >= e.nextIRQ && (e.nextIRQ = 0, this.raiseIRQ(this.IRQ_DMA3)), this.pollNextEvent() - } -}, GameBoyAdvanceInterruptHandler.prototype.resetSP = function() { - this.cpu.switchMode(this.cpu.MODE_SUPERVISOR), this.cpu.gprs[this.cpu.SP] = 50364384, this.cpu.switchMode(this.cpu.MODE_IRQ), this.cpu.gprs[this.cpu.SP] = 50364320, this.cpu.switchMode(this.cpu.MODE_SYSTEM), this.cpu.gprs[this.cpu.SP] = 50364160 -}, GameBoyAdvanceInterruptHandler.prototype.swi32 = function(t) { - this.swi(t >> 16) -}, GameBoyAdvanceInterruptHandler.prototype.swi = function(t) { - if (this.core.mmu.bios.real) this.cpu.raiseTrap(); - else switch (t) { - case 0: - for (var e = this.core.mmu.memory[this.core.mmu.REGION_WORKING_IRAM], i = e.loadU8(32762), r = 32256; r < 32768; r += 4) e.store32(r, 0); - this.resetSP(), this.cpu.gprs[this.cpu.LR] = i ? 33554432 : 134217728, this.cpu.switchExecMode(this.cpu.MODE_ARM), this.cpu.instruction.writesPC = !0, this.cpu.gprs[this.cpu.PC] = this.cpu.gprs[this.cpu.LR]; - break; - case 1: - var s = this.cpu.gprs[0]; - if (1 & s && (this.core.mmu.memory[this.core.mmu.REGION_WORKING_RAM] = new MemoryBlock(this.core.mmu.SIZE_WORKING_RAM, 9)), 2 & s) - for (r = 0; r < this.core.mmu.SIZE_WORKING_IRAM - 512; r += 4) this.core.mmu.memory[this.core.mmu.REGION_WORKING_IRAM].store32(r, 0); - 28 & s && this.video.renderPath.clearSubsets(this.core.mmu, s), 224 & s && this.core.STUB("Unimplemented RegisterRamReset"); - break; - case 2: - this.halt(); - break; - case 5: - this.cpu.gprs[0] = 1, this.cpu.gprs[1] = 1; - case 4: - if (this.enable || this.io.store16(this.io.IME, 1), !this.cpu.gprs[0] && this.interruptFlags & this.cpu.gprs[1]) return; - this.dismissIRQs(4294967295), this.cpu.raiseTrap(); - break; - case 6: - var n = (0 | this.cpu.gprs[0]) / (0 | this.cpu.gprs[1]), - a = (0 | this.cpu.gprs[0]) % (0 | this.cpu.gprs[1]); - this.cpu.gprs[0] = 0 | n, this.cpu.gprs[1] = 0 | a, this.cpu.gprs[3] = Math.abs(0 | n); - break; - case 7: - n = (0 | this.cpu.gprs[1]) / (0 | this.cpu.gprs[0]), a = (0 | this.cpu.gprs[1]) % (0 | this.cpu.gprs[0]); - this.cpu.gprs[0] = 0 | n, this.cpu.gprs[1] = 0 | a, this.cpu.gprs[3] = Math.abs(0 | n); - break; - case 8: - var o = Math.sqrt(this.cpu.gprs[0]); - this.cpu.gprs[0] = 0 | o; - break; - case 10: - var h = this.cpu.gprs[0] / 16384, - c = this.cpu.gprs[1] / 16384; - this.cpu.gprs[0] = Math.atan2(c, h) / (2 * Math.PI) * 65536; - break; - case 11: - var u = this.cpu.gprs[0], - d = this.cpu.gprs[1], - p = 1048575 & (m = this.cpu.gprs[2]), - l = 67108864 & m ? 4 : 2; - if (16777216 & m) - if (4 == l) { - u &= 4294967292, d &= 4294967292; - var f = this.cpu.mmu.load32(u); - for (r = 0; r < p; ++r) this.cpu.mmu.store32(d + (r << 2), f) - } else { - u &= 4294967294, d &= 4294967294; - for (f = this.cpu.mmu.load16(u), r = 0; r < p; ++r) this.cpu.mmu.store16(d + (r << 1), f) - } else if (4 == l) { - u &= 4294967292, d &= 4294967292; - for (r = 0; r < p; ++r) { - f = this.cpu.mmu.load32(u + (r << 2)); - this.cpu.mmu.store32(d + (r << 2), f) - } - } else { - u &= 4294967294, d &= 4294967294; - for (r = 0; r < p; ++r) { - f = this.cpu.mmu.load16(u + (r << 1)); - this.cpu.mmu.store16(d + (r << 1), f) - } - } - return; - case 12: - var m; - u = 4294967292 & this.cpu.gprs[0], d = 4294967292 & this.cpu.gprs[1]; - if (p = (p = 1048575 & (m = this.cpu.gprs[2])) + 7 >> 3 << 3, 16777216 & m) - for (f = this.cpu.mmu.load32(u), r = 0; r < p; ++r) this.cpu.mmu.store32(d + (r << 2), f); - else - for (r = 0; r < p; ++r) { - f = this.cpu.mmu.load32(u + (r << 2)); - this.cpu.mmu.store32(d + (r << 2), f) - } - return; - case 14: - r = this.cpu.gprs[2]; - for (var y, v, A, b, g, S, R = this.cpu.gprs[0], C = this.cpu.gprs[1]; r--;) y = this.core.mmu.load32(R) / 256, v = this.core.mmu.load32(R + 4) / 256, A = this.core.mmu.load16(R + 8), b = this.core.mmu.load16(R + 10), w = this.core.mmu.load16(R + 12) / 256, M = this.core.mmu.load16(R + 14) / 256, _ = (this.core.mmu.loadU16(R + 16) >> 8) / 128 * Math.PI, R += 20, I = T = Math.cos(_), E = O = Math.sin(_), g = y - ((I *= w) * A + (E *= -w) * b), S = v - ((O *= M) * A + (T *= M) * b), this.core.mmu.store16(C, 256 * I | 0), this.core.mmu.store16(C + 2, 256 * E | 0), this.core.mmu.store16(C + 4, 256 * O | 0), this.core.mmu.store16(C + 6, 256 * T | 0), this.core.mmu.store32(C + 8, 256 * g | 0), this.core.mmu.store32(C + 12, 256 * S | 0), C += 16; - break; - case 15: - r = this.cpu.gprs[2], R = this.cpu.gprs[0], C = this.cpu.gprs[1]; - for (var w, M, _, I, E, O, T, P = this.cpu.gprs[3]; r--;) w = this.core.mmu.load16(R) / 256, M = this.core.mmu.load16(R + 2) / 256, _ = (this.core.mmu.loadU16(R + 4) >> 8) / 128 * Math.PI, R += 6, I = T = Math.cos(_), E = O = Math.sin(_), I *= w, E *= -w, O *= M, T *= M, this.core.mmu.store16(C, 256 * I | 0), this.core.mmu.store16(C + P, 256 * E | 0), this.core.mmu.store16(C + 2 * P, 256 * O | 0), this.core.mmu.store16(C + 3 * P, 256 * T | 0), C += 4 * P; - break; - case 17: - this.lz77(this.cpu.gprs[0], this.cpu.gprs[1], 1); - break; - case 18: - this.lz77(this.cpu.gprs[0], this.cpu.gprs[1], 2); - break; - case 19: - this.huffman(this.cpu.gprs[0], this.cpu.gprs[1]); - break; - case 20: - this.rl(this.cpu.gprs[0], this.cpu.gprs[1], 1); - break; - case 21: - this.rl(this.cpu.gprs[0], this.cpu.gprs[1], 2); - break; - case 31: - var B = this.cpu.mmu.load32(this.cpu.gprs[0] + 4); - this.cpu.gprs[0] = B / Math.pow(2, (180 - this.cpu.gprs[1] - this.cpu.gprs[2] / 256) / 12) >>> 0; - break; - default: - throw "Unimplemented software interrupt: 0x" + t.toString(16) - } -}, GameBoyAdvanceInterruptHandler.prototype.masterEnable = function(t) { - this.enable = t, this.enable && this.enabledIRQs & this.interruptFlags && this.cpu.raiseIRQ() -}, GameBoyAdvanceInterruptHandler.prototype.setInterruptsEnabled = function(t) { - this.enabledIRQs = t, this.enabledIRQs & this.MASK_SIO && this.core.STUB("Serial I/O interrupts not implemented"), this.enabledIRQs & this.MASK_KEYPAD && this.core.STUB("Keypad interrupts not implemented"), this.enable && this.enabledIRQs & this.interruptFlags && this.cpu.raiseIRQ() -}, GameBoyAdvanceInterruptHandler.prototype.pollNextEvent = function() { - var t, e = this.video.nextEvent; - if (this.audio.enabled && (t = this.audio.nextEvent, (!e || t < e) && (e = t)), this.timersEnabled) { - var i = this.timers[0]; - t = i.nextEvent, i.enable && t && (!e || t < e) && (e = t), t = (i = this.timers[1]).nextEvent, i.enable && t && (!e || t < e) && (e = t), t = (i = this.timers[2]).nextEvent, i.enable && t && (!e || t < e) && (e = t), t = (i = this.timers[3]).nextEvent, i.enable && t && (!e || t < e) && (e = t) - } - var r = this.dma[0]; - t = r.nextIRQ, r.enable && r.doIrq && t && (!e || t < e) && (e = t), t = (r = this.dma[1]).nextIRQ, r.enable && r.doIrq && t && (!e || t < e) && (e = t), t = (r = this.dma[2]).nextIRQ, r.enable && r.doIrq && t && (!e || t < e) && (e = t), t = (r = this.dma[3]).nextIRQ, r.enable && r.doIrq && t && (!e || t < e) && (e = t), this.core.ASSERT(e >= this.cpu.cycles, "Next event is before present"), this.nextEvent = e -}, GameBoyAdvanceInterruptHandler.prototype.waitForIRQ = function() { - var t, e = this.testIRQ() || this.video.hblankIRQ || this.video.vblankIRQ || this.video.vcounterIRQ; - if (this.timersEnabled && (t = this.timers[0], e = e || t.doIrq, t = this.timers[1], e = e || t.doIrq, t = this.timers[2], e = e || t.doIrq, t = this.timers[3], e = e || t.doIrq), !e) return !1; - for (;;) { - if (this.pollNextEvent(), !this.nextEvent) return !1; - if (this.cpu.cycles = this.nextEvent, this.updateTimers(), this.interruptFlags) return !0 - } -}, GameBoyAdvanceInterruptHandler.prototype.testIRQ = function() { - return !!(this.enable && this.enabledIRQs & this.interruptFlags) && (this.springIRQ = !0, this.nextEvent = this.cpu.cycles, !0) -}, GameBoyAdvanceInterruptHandler.prototype.raiseIRQ = function(t) { - this.interruptFlags |= 1 << t, this.io.registers[this.io.IF >> 1] = this.interruptFlags, this.enable && this.enabledIRQs & 1 << t && this.cpu.raiseIRQ() -}, GameBoyAdvanceInterruptHandler.prototype.dismissIRQs = function(t) { - this.interruptFlags &= ~t, this.io.registers[this.io.IF >> 1] = this.interruptFlags -}, GameBoyAdvanceInterruptHandler.prototype.dmaSetSourceAddress = function(t, e) { - this.dma[t].source = 4294967294 & e -}, GameBoyAdvanceInterruptHandler.prototype.dmaSetDestAddress = function(t, e) { - this.dma[t].dest = 4294967294 & e -}, GameBoyAdvanceInterruptHandler.prototype.dmaSetWordCount = function(t, e) { - this.dma[t].count = e || (3 == t ? 65536 : 16384) -}, GameBoyAdvanceInterruptHandler.prototype.dmaWriteControl = function(t, e) { - var i = this.dma[t], - r = i.enable; - i.dstControl = (96 & e) >> 5, i.srcControl = (384 & e) >> 7, i.repeat = !!(512 & e), i.width = 1024 & e ? 4 : 2, i.drq = !!(2048 & e), i.timing = (12288 & e) >> 12, i.doIrq = !!(16384 & e), i.enable = !!(32768 & e), i.nextIRQ = 0, i.drq && this.core.WARN("DRQ not implemented"), !r && i.enable && (i.nextSource = i.source, i.nextDest = i.dest, i.nextCount = i.count, this.cpu.mmu.scheduleDma(t, i)) -}, GameBoyAdvanceInterruptHandler.prototype.timerSetReload = function(t, e) { - this.timers[t].reload = 65535 & e -}, GameBoyAdvanceInterruptHandler.prototype.timerWriteControl = function(t, e) { - var i = this.timers[t], - r = i.prescaleBits; - switch (3 & e) { - case 0: - i.prescaleBits = 0; - break; - case 1: - i.prescaleBits = 6; - break; - case 2: - i.prescaleBits = 8; - break; - case 3: - i.prescaleBits = 10 - } - i.countUp = !!(4 & e), i.doIrq = !!(64 & e), i.overflowInterval = 65536 - i.reload << i.prescaleBits; - var s = i.enable; - i.enable = !!((128 & e) >> 7 << t), !s && i.enable ? (i.countUp ? i.nextEvent = 0 : (i.lastEvent = this.cpu.cycles, i.nextEvent = this.cpu.cycles + i.overflowInterval), this.io.registers[this.io.TM0CNT_LO + (t << 2) >> 1] = i.reload, i.oldReload = i.reload, ++this.timersEnabled) : s && !i.enable ? (i.countUp || (this.io.registers[this.io.TM0CNT_LO + (t << 2) >> 1] = i.oldReload + (this.cpu.cycles - i.lastEvent) >> r), --this.timersEnabled) : i.prescaleBits == r || i.countUp || (i.nextEvent = i.lastEvent + i.overflowInterval), this.pollNextEvent() -}, GameBoyAdvanceInterruptHandler.prototype.timerRead = function(t) { - var e = this.timers[t]; - return e.enable && !e.countUp ? e.oldReload + (this.cpu.cycles - e.lastEvent) >> e.prescaleBits : this.io.registers[this.io.TM0CNT_LO + (t << 2) >> 1] -}, GameBoyAdvanceInterruptHandler.prototype.halt = function() { - if (!this.enable) throw "Requested HALT when interrupts were disabled!"; - if (!this.waitForIRQ()) throw "Waiting on interrupt forever." -}, GameBoyAdvanceInterruptHandler.prototype.lz77 = function(t, e, i) { - for (var r, s, n, a, o, h = (4294967040 & this.cpu.mmu.load32(t)) >> 8, c = t + 4, u = e, d = 0, p = 0; 0 < h;) - if (d) { - if (128 & r) - for (s = this.cpu.mmu.loadU8(c) | this.cpu.mmu.loadU8(c + 1) << 8, c += 2, n = u - ((15 & s) << 8 | (65280 & s) >> 8) - 1, a = 3 + ((240 & s) >> 4); a-- && h;) o = this.cpu.mmu.loadU8(n++), 2 == i ? (p >>= 8, p |= o << 8, 1 & u && this.cpu.mmu.store16(u - 1, p)) : this.cpu.mmu.store8(u, o), --h, ++u; - else o = this.cpu.mmu.loadU8(c++), 2 == i ? (p >>= 8, p |= o << 8, 1 & u && this.cpu.mmu.store16(u - 1, p)) : this.cpu.mmu.store8(u, o), --h, ++u; - r <<= 1, --d - } else r = this.cpu.mmu.loadU8(c++), d = 8 -}, GameBoyAdvanceInterruptHandler.prototype.huffman = function(t, e) { - t &= 4294967292; - var i = this.cpu.mmu.load32(t), - r = i >> 8, - s = 15 & i; - if (32 % s) throw "Unimplemented unaligned Huffman"; - var n = 4 - r & 3; - r &= 4294967292; - var a, o, h, c = [], - u = 1 + (this.cpu.mmu.loadU8(t + 4) << 1), - d = t + 5 + u, - p = 4294967292 & e; - for (o = 0; o < u; ++o) c.push(this.cpu.mmu.loadU8(t + 5 + o)); - var l, f, m = 0, - y = 0; - for (h = c[0]; 0 < r;) { - var v = this.cpu.mmu.load32(d); - for (d += 4, l = 32; 0 < l; --l, v <<= 1) { - if ("number" == typeof h) { - var A = (m - 1 | 1) + ((63 & h) << 1) + 2; - h = { - l: A, - r: A + 1, - lTerm: 128 & h, - rTerm: 64 & h - }, c[m] = h - } - if (2147483648 & v) { - if (!h.rTerm) { - m = h.r, h = c[h.r]; - continue - } - f = c[h.r] - } else { - if (!h.lTerm) { - h = c[m = h.l]; - continue - } - f = c[h.l] - } - a |= (f & (1 << s) - 1) << y, y += s, h = c[m = 0], 32 == y && (y = 0, this.cpu.mmu.store32(p, a), p += 4, r -= 4, a = 0) - } - } - n && this.cpu.mmu.store32(p, a) -}, GameBoyAdvanceInterruptHandler.prototype.rl = function(t, e, i) { - t &= 4294967292; - for (var r, s, n = (4294967040 & this.cpu.mmu.load32(t)) >> 8, a = 4 - n & 3, o = t + 4, h = e, c = 0; 0 < n;) - if (128 & (r = this.cpu.mmu.loadU8(o++))) - for (r &= 127, r += 3, s = this.cpu.mmu.loadU8(o++); r-- && n;)--n, 2 == i ? (c >>= 8, c |= s << 8, 1 & h && this.cpu.mmu.store16(h - 1, c)) : this.cpu.mmu.store8(h, s), ++h; - else - for (r++; r-- && n;)--n, s = this.cpu.mmu.loadU8(o++), 2 == i ? (c >>= 8, c |= s << 8, 1 & h && this.cpu.mmu.store16(h - 1, c)) : this.cpu.mmu.store8(h, s), ++h; - for (; a--;) this.cpu.mmu.store8(h++, 0) -}, GameBoyAdvanceKeypad.prototype.keyboardHandler = function(t) { - var e = 0; - switch (t.keyCode) { - case this.KEYCODE_START: - e = this.START; - break; - case this.KEYCODE_SELECT: - e = this.SELECT; - break; - case this.KEYCODE_A: - e = this.A; - break; - case this.KEYCODE_B: - e = this.B; - break; - case this.KEYCODE_L: - e = this.L; - break; - case this.KEYCODE_R: - e = this.R; - break; - case this.KEYCODE_UP: - e = this.UP; - break; - case this.KEYCODE_RIGHT: - e = this.RIGHT; - break; - case this.KEYCODE_DOWN: - e = this.DOWN; - break; - case this.KEYCODE_LEFT: - e = this.LEFT; - break; - default: - return - } - e = 1 << e, this.currentDown |= e, "keydown" == t.type && (this.currentDown &= ~e), this.eatInput && t.preventDefault() -}, GameBoyAdvanceKeypad.prototype.gamepadHandler = function(t) { - var e = 0; - t.buttons[this.GAMEPAD_LEFT] > this.GAMEPAD_THRESHOLD && (e |= 1 << this.LEFT), t.buttons[this.GAMEPAD_UP] > this.GAMEPAD_THRESHOLD && (e |= 1 << this.UP), t.buttons[this.GAMEPAD_RIGHT] > this.GAMEPAD_THRESHOLD && (e |= 1 << this.RIGHT), t.buttons[this.GAMEPAD_DOWN] > this.GAMEPAD_THRESHOLD && (e |= 1 << this.DOWN), t.buttons[this.GAMEPAD_START] > this.GAMEPAD_THRESHOLD && (e |= 1 << this.START), t.buttons[this.GAMEPAD_SELECT] > this.GAMEPAD_THRESHOLD && (e |= 1 << this.SELECT), t.buttons[this.GAMEPAD_A] > this.GAMEPAD_THRESHOLD && (e |= 1 << this.A), t.buttons[this.GAMEPAD_B] > this.GAMEPAD_THRESHOLD && (e |= 1 << this.B), t.buttons[this.GAMEPAD_L] > this.GAMEPAD_THRESHOLD && (e |= 1 << this.L), t.buttons[this.GAMEPAD_R] > this.GAMEPAD_THRESHOLD && (e |= 1 << this.R), this.currentDown = 1023 & ~e -}, GameBoyAdvanceKeypad.prototype.gamepadConnectHandler = function(t) { - this.gamepads.push(t) -}, GameBoyAdvanceKeypad.prototype.gamepadDisconnectHandler = function(e) { - this.gamepads = self.gamepads.filter(function(t) { - return t != e - }) -}, GameBoyAdvanceKeypad.prototype.pollGamepads = function() { - var t = []; - navigator.webkitGetGamepads ? t = navigator.webkitGetGamepads() : navigator.getGamepads && (t = navigator.getGamepads()), t.length && (this.gamepads = []); - for (var e = 0; e < t.length; ++e) t[e] && this.gamepads.push(t[e]); - 0 < this.gamepads.length && this.gamepadHandler(this.gamepads[0]) -}, GameBoyAdvanceKeypad.prototype.joypadHander = function(t) { - var e = 1 << parseInt(t.target.value); - this.currentDown |= e, "mousedown" !== t.type && "touchstart" !== t.type || (this.currentDown &= ~e), this.eatInput && t.preventDefault() -}, GameBoyAdvanceKeypad.prototype.registerHandlers = function() { - window.addEventListener("keydown", this.keyboardHandler.bind(this), !0), window.addEventListener("keyup", this.keyboardHandler.bind(this), !0), window.addEventListener("gamepadconnected", this.gamepadConnectHandler.bind(this), !0), window.addEventListener("mozgamepadconnected", this.gamepadConnectHandler.bind(this), !0), window.addEventListener("webkitgamepadconnected", this.gamepadConnectHandler.bind(this), !0), window.addEventListener("gamepaddisconnected", this.gamepadDisconnectHandler.bind(this), !0), window.addEventListener("mozgamepaddisconnected", this.gamepadDisconnectHandler.bind(this), !0), window.addEventListener("webkitgamepaddisconnected", this.gamepadDisconnectHandler.bind(this), !0) -}, GameBoyAdvanceSIO.prototype.clear = function() { - this.mode = this.SIO_GPIO, this.sd = !1, this.irq = !1, this.multiplayer = { - baud: 0, - si: 0, - id: 0, - error: 0, - busy: 0, - states: [65535, 65535, 65535, 65535] - }, this.linkLayer = null -}, GameBoyAdvanceSIO.prototype.setMode = function(t) { - t &= 8 & t ? 12 : 3, this.mode = t, this.core.INFO("Setting SIO mode to " + hex(t, 1)) -}, GameBoyAdvanceSIO.prototype.writeRCNT = function(t) { - this.mode == this.SIO_GPIO && this.core.STUB("General purpose serial not supported") -}, GameBoyAdvanceSIO.prototype.writeSIOCNT = function(t) { - switch (this.mode) { - case this.SIO_NORMAL_8: - this.core.STUB("8-bit transfer unsupported"); - break; - case this.SIO_NORMAL_32: - this.core.STUB("32-bit transfer unsupported"); - break; - case this.SIO_MULTI: - this.multiplayer.baud = 3 & t, this.linkLayer && this.linkLayer.setBaud(this.BAUD[this.multiplayer.baud]), this.multiplayer.si || (this.multiplayer.busy = 128 & t, this.linkLayer && this.multiplayer.busy && this.linkLayer.startMultiplayerTransfer()), this.irq = 16384 & t; - break; - case this.SIO_UART: - this.core.STUB("UART unsupported"); - break; - case this.SIO_GPIO: - break; - case this.SIO_JOYBUS: - this.core.STUB("JOY BUS unsupported") - } -}, GameBoyAdvanceSIO.prototype.readSIOCNT = function() { - var t = this.mode << 12 & 65535; - switch (this.mode) { - case this.SIO_NORMAL_8: - this.core.STUB("8-bit transfer unsupported"); - break; - case this.SIO_NORMAL_32: - this.core.STUB("32-bit transfer unsupported"); - break; - case this.SIO_MULTI: - t |= this.multiplayer.baud, t |= this.multiplayer.si, t |= !!this.sd << 3, t |= this.multiplayer.id << 4, t |= this.multiplayer.error, t |= this.multiplayer.busy, t |= !!this.multiplayer.irq << 14; - break; - case this.SIO_UART: - this.core.STUB("UART unsupported"); - break; - case this.SIO_GPIO: - break; - case this.SIO_JOYBUS: - this.core.STUB("JOY BUS unsupported") - } - return t -}, GameBoyAdvanceSIO.prototype.read = function(t) { - switch (this.mode) { - case this.SIO_NORMAL_32: - this.core.STUB("32-bit transfer unsupported"); - break; - case this.SIO_MULTI: - return this.multiplayer.states[t]; - case this.SIO_UART: - this.core.STUB("UART unsupported"); - break; - default: - this.core.WARN("Reading from transfer register in unsupported mode") - } - return 0 -}, SRAMSavedata.prototype = Object.create(MemoryView.prototype), SRAMSavedata.prototype.store8 = function(t, e) { - this.view.setInt8(t, e), this.writePending = !0 -}, SRAMSavedata.prototype.store16 = function(t, e) { - this.view.setInt16(t, e, !0), this.writePending = !0 -}, SRAMSavedata.prototype.store32 = function(t, e) { - this.view.setInt32(t, e, !0), this.writePending = !0 -}, FlashSavedata.prototype = Object.create(MemoryView.prototype), FlashSavedata.prototype.load8 = function(t) { - return this.idMode && t < 2 ? this.id >> (t << 3) & 255 : t < 65536 ? this.bank.getInt8(t) : 0 -}, FlashSavedata.prototype.load16 = function(t) { - return 255 & this.load8(t) | this.load8(t + 1) << 8 -}, FlashSavedata.prototype.load32 = function(t) { - return 255 & this.load8(t) | this.load8(t + 1) << 8 | this.load8(t + 2) << 16 | this.load8(t + 3) << 24 -}, FlashSavedata.prototype.loadU8 = function(t) { - return 255 & this.load8(t) -}, FlashSavedata.prototype.loadU16 = function(t) { - return 255 & this.loadU8(t) | this.loadU8(t + 1) << 8 -}, FlashSavedata.prototype.store8 = function(t, e) { - switch (this.command) { - case 0: - if (21845 == t) - if (85 == this.second) { - switch (e) { - case this.COMMAND_ERASE: - this.pendingCommand = e; - break; - case this.COMMAND_ID: - this.idMode = !0; - break; - case this.COMMAND_TERMINATE_ID: - this.idMode = !1; - break; - default: - this.command = e - } - this.second = 0, this.first = 0 - } else this.command = 0, this.first = e, this.idMode = !1; - else 10922 == t && 170 == this.first && (this.first = 0, this.pendingCommand ? this.command = this.pendingCommand : this.second = e); - break; - case this.COMMAND_ERASE: - switch (e) { - case this.COMMAND_WIPE: - if (21845 == t) - for (var i = 0; i < this.view.byteLength; i += 4) this.view.setInt32(i, -1); - break; - case this.COMMAND_ERASE_SECTOR: - if (0 == (4095 & t)) - for (i = t; i < t + 4096; i += 4) this.bank.setInt32(i, -1) - } - this.pendingCommand = 0, this.command = 0; - break; - case this.COMMAND_WRITE: - this.bank.setInt8(t, e), this.command = 0, this.writePending = !0; - break; - case this.COMMAND_SWITCH_BANK: - this.bank1 && 0 == t && (this.bank = 1 == e ? this.bank1 : this.bank0), this.command = 0 - } -}, FlashSavedata.prototype.store16 = function(t, e) { - throw new Error("Unaligned save to flash!") -}, FlashSavedata.prototype.store32 = function(t, e) { - throw new Error("Unaligned save to flash!") -}, FlashSavedata.prototype.replaceData = function(t) { - var e = this.view === this.bank1; - MemoryView.prototype.replaceData.call(this, t, 0), this.bank0 = new DataView(this.buffer, 0, 65536), 65536 < t.byteLength ? this.bank1 = new DataView(this.buffer, 65536) : this.bank1 = null, this.bank = e ? this.bank1 : this.bank0 -}, EEPROMSavedata.prototype = Object.create(MemoryView.prototype), EEPROMSavedata.prototype.load8 = function(t) { - throw new Error("Unsupported 8-bit access!") -}, EEPROMSavedata.prototype.load16 = function(t) { - return this.loadU16(t) -}, EEPROMSavedata.prototype.loadU8 = function(t) { - throw new Error("Unsupported 8-bit access!") -}, EEPROMSavedata.prototype.loadU16 = function(t) { - if (this.command != this.COMMAND_READ || !this.dma.enable) return 1; - if (--this.readBitsRemaining, this.readBitsRemaining < 64) { - var e = 63 - this.readBitsRemaining, - i = this.view.getUint8(this.readAddress + e >> 3, !1) >> 7 - (7 & e); - return this.readBitsRemaining || (this.command = this.COMMAND_NULL), 1 & i - } - return 0 -}, EEPROMSavedata.prototype.load32 = function(t) { - throw new Error("Unsupported 32-bit access!") -}, EEPROMSavedata.prototype.store8 = function(t, e) { - throw new Error("Unsupported 8-bit access!") -}, EEPROMSavedata.prototype.store16 = function(t, e) { - switch (this.command) { - case this.COMMAND_NULL: - default: - this.command = 1 & e; - break; - case this.COMMAND_PENDING: - if (this.command <<= 1, this.command |= 1 & e, this.command == this.COMMAND_WRITE) { - if (!this.realSize) { - var i = this.dma.count - 67; - this.realSize = 8 << i, this.addressBits = i - } - this.commandBitsRemaining = this.addressBits + 64 + 1, this.writeAddress = 0 - } else { - if (!this.realSize) { - i = this.dma.count - 3; - this.realSize = 8 << i, this.addressBits = i - } - this.commandBitsRemaining = this.addressBits + 1, this.readAddress = 0 - } - break; - case this.COMMAND_WRITE: - if (64 < --this.commandBitsRemaining) this.writeAddress <<= 1, this.writeAddress |= (1 & e) << 6; - else if (this.commandBitsRemaining <= 0) this.command = this.COMMAND_NULL, this.writePending = !0; - else { - var r = this.view.getUint8(this.writeAddress >> 3); - r &= ~(1 << 7 - (7 & this.writeAddress)), r |= (1 & e) << 7 - (7 & this.writeAddress), this.view.setUint8(this.writeAddress >> 3, r), ++this.writeAddress - } - break; - case this.COMMAND_READ_PENDING: - 0 < --this.commandBitsRemaining ? (this.readAddress <<= 1, 1 & e && (this.readAddress |= 64)) : (this.readBitsRemaining = 68, this.command = this.COMMAND_READ) - } -}, EEPROMSavedata.prototype.store32 = function(t, e) { - throw new Error("Unsupported 32-bit access!") -}, EEPROMSavedata.prototype.replaceData = function(t) { - MemoryView.prototype.replaceData.call(this, t, 0) -}, GameBoyAdvanceGPIO.prototype.store16 = function(t, e) { - switch (t) { - case 196: - this.device.setPins(15 & e); - break; - case 198: - this.direction = 15 & e, this.device.setDirection(this.direction); - break; - case 200: - this.readWrite = 1 & e; - break; - default: - throw new Error("BUG: Bad offset passed to GPIO: " + t.toString(16)) - } - if (this.readWrite) { - var i = this.rom.view.getUint16(t, !0); - i &= ~this.direction, this.rom.view.setUint16(t, i | e & this.direction, !0) - } -}, GameBoyAdvanceGPIO.prototype.outputPins = function(t) { - if (this.readWrite) { - var e = this.rom.view.getUint16(196, !0); - e &= this.direction, this.rom.view.setUint16(196, e | t & ~this.direction & 15, !0) - } -}, GameBoyAdvanceRTC.prototype.setPins = function(t) { - switch (this.transferStep) { - case 0: - 1 == (5 & t) && (this.transferStep = 1); - break; - case 1: - 4 & t && (this.transferStep = 2); - break; - case 2: - 1 & t ? 4 & t ? 2 & this.direction && !this.read ? (++this.bitsRead, 8 == this.bitsRead && this.processByte()) : (this.gpio.outputPins(5 | this.sioOutputPin() << 1), ++this.bitsRead, 8 == this.bitsRead && (--this.bytesRemaining, this.bytesRemaining <= 0 && (this.command = -1), this.bitsRead = 0)) : (this.bitsRead = 0, this.bytesRemaining = 0, this.command = -1, this.transferStep = 0) : (this.bits &= ~(1 << this.bitsRead), this.bits |= (2 & t) >> 1 << this.bitsRead) - } - this.pins = 7 & t -}, GameBoyAdvanceRTC.prototype.setDirection = function(t) { - this.direction = t -}, GameBoyAdvanceRTC.prototype.processByte = function() { - switch (--this.bytesRemaining, this.command) { - case -1: - if (6 == (15 & this.bits)) switch (this.command = this.bits >> 4 & 7, this.reading = 128 & this.bits, this.bytesRemaining = this.totalBytes[this.command], this.command) { - case 0: - this.control = 0; - break; - case 2: - case 6: - this.updateClock() - } else this.gpio.core.WARN("Invalid RTC command byte: " + this.bits.toString(16)); - break; - case 4: - this.control = 64 & this.bits - } - this.bits = 0, this.bitsRead = 0, this.bytesRemaining || (this.command = -1) -}, GameBoyAdvanceRTC.prototype.sioOutputPin = function() { - var t = 0; - switch (this.command) { - case 4: - t = this.control; - break; - case 2: - case 6: - t = this.time[7 - this.bytesRemaining] - } - return t >> this.bitsRead & 1 -}, GameBoyAdvanceRTC.prototype.updateClock = function() { - var t = new Date; - this.time[0] = this.bcd(t.getFullYear()), this.time[1] = this.bcd(t.getMonth() + 1), this.time[2] = this.bcd(t.getDate()), this.time[3] = t.getDay() - 1, this.time[3] < 0 && (this.time[3] = 6), 64 & this.control ? this.time[4] = this.bcd(t.getHours()) : (this.time[4] = this.bcd(t.getHours() % 2), 12 <= t.getHours() && (this.time[4] |= 128)), this.time[5] = this.bcd(t.getMinutes()), this.time[6] = this.bcd(t.getSeconds()) -}, GameBoyAdvanceRTC.prototype.bcd = function(t) { - var e = t % 10; - return e += (t /= 10) % 10 << 4 -}, GameBoyAdvance.prototype.setCanvas = function(t) { - var e = this; - if (240 != t.offsetWidth || 160 != t.offsetHeight) { - this.indirectCanvas = document.createElement("canvas"), this.indirectCanvas.setAttribute("height", "160"), this.indirectCanvas.setAttribute("width", "240"), this.targetCanvas = t, this.setCanvasDirect(this.indirectCanvas); - var i = t.getContext("2d"); - this.video.drawCallback = function() { - i.drawImage(e.indirectCanvas, 0, 0, t.offsetWidth, t.offsetHeight) - } - } else { - this.setCanvasDirect(t); - e = this - } -}, GameBoyAdvance.prototype.setCanvasDirect = function(t) { - this.context = t.getContext("2d"), this.video.setBacking(this.context) -}, GameBoyAdvance.prototype.setBios = function(t, e) { - this.mmu.loadBios(t, e) -}, GameBoyAdvance.prototype.setRom = function(t) { - return this.reset(), this.rom = this.mmu.loadRom(t, !0), !!this.rom && (this.retrieveSavedata(), !0) -}, GameBoyAdvance.prototype.hasRom = function() { - return !!this.rom -}, GameBoyAdvance.prototype.loadRomFromFile = function(t, n) { - var a = this, - e = new JSZip; - if (t.size) - if ("application/zip" === t.type) e.loadAsync(t).then(function(t) { - t.forEach(function(t, e) { - if (e.name.slice(-4).includes(".gb")) { - console.log(e); - var i = e._data.uncompressedSize, - r = new Uint8Array(i).buffer; - console.log(r); - var s = a.setRom(r); - console.log(s), n && n(s) - } - }) - }, function(t) {}); - else { - var i = new FileReader; - i.onload = function(t) { - var e = t.target.result; - console.log(e); - var i = a.setRom(e); - n && n(i) - }, i.readAsArrayBuffer(t) - } else { - var r = new XMLHttpRequest; - r.open("GET", t), r.responseType = "arraybuffer", r.onload = function() { - var t = r.response, - e = a.setRom(t); - n && n(e) - }, r.send() - } -}, GameBoyAdvance.prototype.reset = function() { - this.audio.pause(!0), this.mmu.clear(), this.io.clear(), this.audio.clear(), this.video.clear(), this.sio.clear(), this.mmu.mmap(this.mmu.REGION_IO, this.io), this.mmu.mmap(this.mmu.REGION_PALETTE_RAM, this.video.renderPath.palette), this.mmu.mmap(this.mmu.REGION_VRAM, this.video.renderPath.vram), this.mmu.mmap(this.mmu.REGION_OAM, this.video.renderPath.oam), this.cpu.resetCPU(0) -}, GameBoyAdvance.prototype.step = function() { - for (; this.doStep();) this.cpu.step() -}, GameBoyAdvance.prototype.waitFrame = function() { - var t = this.seenFrame; - return this.seenFrame = !1, !t -}, GameBoyAdvance.prototype.pause = function() { - this.paused = !0, this.audio.pause(!0), this.queue && (clearTimeout(this.queue), this.queue = null) -}, GameBoyAdvance.prototype.advanceFrame = function() { - this.step(), this.seenSave ? this.mmu.saveNeedsFlush() ? this.mmu.flushSave() : (this.storeSavedata(), this.seenSave = !1) : this.mmu.saveNeedsFlush() && (this.seenSave = !0, this.mmu.flushSave()) -}, GameBoyAdvance.prototype.runStable = function() { - if (!this.interval) { - var t, e = this, - i = 0, - r = 0, - s = Date.now(); - this.paused = !1, this.audio.pause(!1), t = this.reportFPS ? function() { - try { - if (i += Date.now() - s, e.paused) return; - queueFrame(t), s = Date.now(), e.advanceFrame(), 60 == ++r && (e.reportFPS(1e3 * r / i), i = r = 0) - } catch (t) { - throw e.ERROR(t), t.stack && e.logStackTrace(t.stack.split("\n")), t - } - } : function() { - try { - if (e.paused) return; - queueFrame(t), e.advanceFrame() - } catch (t) { - throw e.ERROR(t), t.stack && e.logStackTrace(t.stack.split("\n")), t - } - }, queueFrame(t) - } -}, GameBoyAdvance.prototype.setSavedata = function(t) { - this.mmu.loadSavedata(t) -}, GameBoyAdvance.prototype.loadSavedataFromFile = function(t) { - var e = new FileReader, - i = this; - e.onload = function(t) { - i.setSavedata(t.target.result) - }, e.readAsArrayBuffer(t) -}, GameBoyAdvance.prototype.decodeSavedata = function(t) { - this.setSavedata(this.decodeBase64(t)) -}, GameBoyAdvance.prototype.decodeBase64 = function(t) { - var e = 3 * t.length / 4; - "=" == t[t.length - 2] ? e -= 2 : "=" == t[t.length - 1] && (e -= 1); - for (var i = new ArrayBuffer(e), r = new Uint8Array(i), s = t.match(/..../g), n = 0; n + 2 < e; n += 3) { - var a = atob(s.shift()); - r[n] = a.charCodeAt(0), r[n + 1] = a.charCodeAt(1), r[n + 2] = a.charCodeAt(2) - } - if (n < e) { - a = atob(s.shift()); - r[n++] = a.charCodeAt(0), 1 < a.length && (r[n++] = a.charCodeAt(1)) - } - return i -}, GameBoyAdvance.prototype.encodeBase64 = function(t) { - for (var e, i, r = [], s = [], n = 0; n < t.byteLength; ++n) - for (e = t.getUint8(n, !0), s.push(String.fromCharCode(e)); 3 <= s.length;) i = s.splice(0, 3), r.push(btoa(i.join(""))); - return s.length && r.push(btoa(s.join(""))), r.join("") -}, GameBoyAdvance.prototype.downloadSavedata = function() { - var t = this.mmu.save; - if (!t) return this.WARN("No save data available"), null; - if (window.URL) { - var e = window.URL.createObjectURL(new Blob([t.buffer], { - type: "application/octet-stream" - })); - window.open(e) - } else { - var i = this.encodeBase64(t.view); - window.open("data:application/octet-stream;base64," + i, this.rom.code + ".sav") - } -}, GameBoyAdvance.prototype.storeSavedata = function() { - var t = this.mmu.save; - try { - window.localStorage[this.SYS_ID + "." + this.mmu.cart.code] = this.encodeBase64(t.view) - } catch (t) { - this.WARN("Could not store savedata! " + t) - } -}, GameBoyAdvance.prototype.retrieveSavedata = function() { - try { - var t = window.localStorage[this.SYS_ID + "." + this.mmu.cart.code]; - if (t) return this.decodeSavedata(t), !0 - } catch (t) { - this.WARN("Could not retrieve savedata! " + t) - } - return !1 -}, GameBoyAdvance.prototype.freeze = function() { - return { - cpu: this.cpu.freeze(), - mmu: this.mmu.freeze(), - irq: this.irq.freeze(), - io: this.io.freeze(), - audio: this.audio.freeze(), - video: this.video.freeze() - } -}, GameBoyAdvance.prototype.defrost = function(t) { - this.cpu.defrost(t.cpu), this.mmu.defrost(t.mmu), this.audio.defrost(t.audio), this.video.defrost(t.video), this.irq.defrost(t.irq), this.io.defrost(t.io) -}, GameBoyAdvance.prototype.log = function(t, e) {}, GameBoyAdvance.prototype.setLogger = function(t) { - this.log = t -}, GameBoyAdvance.prototype.logStackTrace = function(t) { - var e = t.length - 32; - this.ERROR("Stack trace follows:"), 0 < e && this.log(-1, "> (Too many frames)"); - for (var i = Math.max(e, 0); i < t.length; ++i) this.log(-1, "> " + t[i]) -}, GameBoyAdvance.prototype.ERROR = function(t) { - this.logLevel & this.LOG_ERROR && this.log(this.LOG_ERROR, t) -}, GameBoyAdvance.prototype.WARN = function(t) { - this.logLevel & this.LOG_WARN && this.log(this.LOG_WARN, t) -}, GameBoyAdvance.prototype.STUB = function(t) { - this.logLevel & this.LOG_STUB && this.log(this.LOG_STUB, t) -}, GameBoyAdvance.prototype.INFO = function(t) { - this.logLevel & this.LOG_INFO && this.log(this.LOG_INFO, t) -}, GameBoyAdvance.prototype.DEBUG = function(t) { - this.logLevel & this.LOG_DEBUG && this.log(this.LOG_DEBUG, t) -}, GameBoyAdvance.prototype.ASSERT_UNREACHED = function(t) { - throw new Error("Should be unreached: " + t) -}, GameBoyAdvance.prototype.ASSERT = function(t, e) { - if (!t) throw new Error("Assertion failed: " + e) -}, zip.workerScriptsPath = "js/libs/zip/worker/", Utils.g.isLandscape = !0, window.gba = null; -var runCommands = [], - gameId = Utils.request.getParameter("id"); - -function loadRom(t, e) { - var i = new XMLHttpRequest; - i.open("GET", t), i.responseType = "arraybuffer", i.onload = function() { - e(i.response) - }, i.send() -} - -function initGBA() { - gba = new GameBoyAdvance, gba.keypad.eatInput = !0, gba.setLogger(function(t, e) { - console.log(e), gba.pause(), "dead" != document.getElementById("screen").getAttribute("class") ? Utils.alert("游戏奔溃了...", null, function() { - location.reload(!0) - }) : console.log("We appear to have crashed multiple times without reseting.") - }); - var t = document.getElementById("screen"); - gba.setCanvas(t), gba.logLevel = gba.LOG_ERROR, loadRom("resources/bios.bin", function(t) { - gba.setBios(t) - }), vm.initCtrl(), run() -} - -function initAudioEvent() { - gba && gba.audio && gba.audio.initAudio() && $(".key-btn").unbind("touchstart", initAudioEvent) -} - -function loadRomByZipUrl(i, r) { - // var s = (/192.168./.test(location.href) ? "http://192.168.42.80:8088/gba/" : "https://pub.hoh8.cn/files/game/gba/") + gameId + "/" + gameId + ".zip", - //var s = "http://192.168.100.84/gba/roms/" + gameId + ".zip", - var s = "http://h5games-al.kingsome.cn/emulator-static/roms/" + gameId + ".zip", - n = "GBA_ROM_" + s; - localforage.getItem(n, function(t, e) { - e ? i(e) : zip.createReader(new zip.HttpReader(s, r), function(e) { - e.getEntries(function(t) { - t.length && t[0].getData(new zip.ArrayBufferWriter, function(t) { - localforage.setItem(n, t), i(t), e.close(function() {}) - }, function(t, e) {}) - }) - }, function(t) {}) - }) -} - -function run() { - var i = Utils.loading("加载中..."); - loadRomByZipUrl(function(t) { - if (gba.setRom(t)) { - for (var e = 0; e < runCommands.length; ++e) runCommands[e](); - runCommands = [], gba.runStable() - } - i.close() - }, function(t) { - if (t.lengthComputable) { - var e = parseInt(t.loaded / t.total * 100); - $("#ld_p").html(e + "%") - } - }) -} -window.onload = function() { - initGBA(), $(".key-btn").bind("touchstart", initAudioEvent) -}; -var KEY_MAP = { - ST: 13, - SE: 220, - A: 90, - B: 88, - Y: 65, - X: 83, - AB: [90, 88], - UP: 38, - DOWN: 40, - LEFT: 37, - RIGHT: 39, - L_D: [37, 40], - L_U: [37, 38], - R_D: [39, 40], - R_U: [39, 38] -}; -window.vm = { - oldDire: null, - keyEvent: function(t, e, i) { - var r = KEY_MAP[t]; - Array.isArray(r) ? (vm.simulateKeyPress(r[0], e), vm.simulateKeyPress(r[1], e)) : vm.simulateKeyPress(r, e) - }, - initCtrl: function() { - var s; - vm.initGameDireCtrl(function(t, e) { - var i = -1 == t ? s : ["DOWN", "L_D", "LEFT", "L_U", "UP", "R_U", "RIGHT", "R_D"][t], - r = -1 == t; - s && (s != i || r) && vm.keyEvent(s, "keyup", e), s = i, !r && vm.keyEvent(i, "keydown", e) - }), vm.initGameKeyCtrl(), $(".ctrl-wrap").on("click contextmenu touchstart touchmove touchend touchcancel tap", function(t) { - return t.stopPropagation(), t.preventDefault(), !1 - }) - }, - initGameDireCtrl: function(u) { - var d = this, - t = $(".dire-wrap"), - p = $(".dc-centre"), - e = $(".dire-ctrl"), - l = $(".dc-dire"), - i = e.offset(), - n = i.top, - a = i.left, - f = p.width() / 2, - m = e.width() / 2, - r = function() { - p.css({ - transform: "translate3d(83px,83px,0)" - }), p.css("opacity", "1"), l.css("opacity", "0") - }, - y = function(t, e) { - var i = t[e]; - if (!i) return { - x: 160, - y: 500 - }; - var r = i.pageX - a, - s = i.pageY - n; - return 600 < s ? y(t, e + 1) : { - x: r, - y: s - } - }; - r(), t.on("touchstart touchmove", function(t) { - var e, i, r = y(t.touches, 0), - s = r.x, - n = r.y, - a = Math.atan2(n - m, s - m) / (Math.PI / 180); - if (l.css("transform", "rotate(" + a + "deg)"), d.onCtrlDire(a, u), (e = m - s, i = m - n, Math.sqrt(e * e + i * i)) <= 86) { - var o = s - f, - h = n - f; - p.css("transform", "translate3d(" + o + "px," + h + "px,0)") - } else { - var c = a * Math.PI / 180; - o = m + 86 * Math.cos(c) - f, h = m + 86 * Math.sin(c) - f; - p.css("transform", "translate3d(" + o + "px," + h + "px,0)") - } - "touchstart" === t.type && (p.css("opacity", "0.8"), l.css("opacity", "0.6")) - }).on("touchend", function() { - r(), u(-1, 0), d.oldDire = -1 - }) - }, - initGameKeyCtrl: function() { - var s = this; - $(".key-btn").bind("touchstart touchend", function(t) { - var e = $(t.target), - i = e.attr("data-key"), - r = "touchstart" === t.type; - s.keyEvent(i, r ? "keydown" : "keyup", 0), e[r ? "addClass" : "removeClass"]("btn-on") - }) - }, - onCtrlDire: function(t, e) { - this.onCtrlDire; - var i = Math.round((t + 180) / 45) % 8; - this.oldDire != i && (e(i, t), this.oldDire = i) - }, - simulateKeyPress: function(t, e) { - var i = $.Event(e); - i.keyCode = t, i.which = i.keyCode, $(window).trigger(i) - } -}; +var Zepto = function() { + function h(t) { + return null == t ? String(t) : H[F.call(t)] || "object" + } + + function a(t) { + return "function" == h(t) + } + + function n(t) { + return null != t && t == t.window + } + + function o(t) { + return null != t && t.nodeType == t.DOCUMENT_NODE + } + + function s(t) { + return "object" == h(t) + } + + function c(t) { + return s(t) && !n(t) && Object.getPrototypeOf(t) == Object.prototype + } + + function u(t) { + return "number" == typeof t.length + } + + function d(t) { + return t.replace(/::/g, "/").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").replace(/([a-z\d])([A-Z])/g, "$1_$2").replace(/_/g, "-").toLowerCase() + } + + function i(t) { + return t in e ? e[t] : e[t] = new RegExp("(^|\\s)" + t + "(\\s|$)") + } + + function p(t, e) { + return "number" != typeof e || O[d(t)] ? e : e + "px" + } + + function r(t) { + return "children" in t ? M.call(t.children) : g.map(t.childNodes, function(t) { + return 1 == t.nodeType ? t : void 0 + }) + } + + function l(t, e) { + return null == e ? g(t) : g(t).filter(e) + } + + function f(t, e, i, r) { + return a(e) ? e.call(t, i, r) : e + } + + function m(t, e, i) { + null == i ? t.removeAttribute(e) : t.setAttribute(e, i) + } + + function y(t, e) { + var i = t.className || "", + r = i && i.baseVal !== A; + return e === A ? r ? i.baseVal : i : void(r ? i.baseVal = e : t.className = e) + } + + function v(e) { + try { + return e ? "true" == e || "false" != e && ("null" == e ? null : +e + "" == e ? +e : /^[\[\{]/.test(e) ? g.parseJSON(e) : e) : e + } catch (t) { + return e + } + } + var A, b, g, S, R, C, w = [], + M = w.slice, + _ = w.filter, + I = window.document, + E = {}, + e = {}, + O = { + "column-count": 1, + columns: 1, + "font-weight": 1, + "line-height": 1, + opacity: 1, + "z-index": 1, + zoom: 1 + }, + T = /^\s*<(\w+|!)[^>]*>/, + P = /^<(\w+)\s*\/?>(?:<\/\1>|)$/, + B = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi, + N = /^(?:body|html)$/i, + k = /([A-Z])/g, + D = ["val", "css", "html", "text", "data", "width", "height", "offset"], + t = I.createElement("table"), + G = I.createElement("tr"), + L = { + tr: I.createElement("tbody"), + tbody: t, + thead: t, + tfoot: t, + td: G, + th: G, + "*": I.createElement("div") + }, + x = /complete|loaded|interactive/, + U = /^[\w-]*$/, + H = {}, + F = H.toString, + W = {}, + V = I.createElement("div"), + z = { + tabindex: "tabIndex", + readonly: "readOnly", + for: "htmlFor", + class: "className", + maxlength: "maxLength", + cellspacing: "cellSpacing", + cellpadding: "cellPadding", + rowspan: "rowSpan", + colspan: "colSpan", + usemap: "useMap", + frameborder: "frameBorder", + contenteditable: "contentEditable" + }, + q = Array.isArray || function(t) { + return t instanceof Array + }; + return W.matches = function(t, e) { + if (!e || !t || 1 !== t.nodeType) return !1; + var i = t.webkitMatchesSelector || t.mozMatchesSelector || t.oMatchesSelector || t.matchesSelector; + if (i) return i.call(t, e); + var r, s = t.parentNode, + n = !s; + return n && (s = V).appendChild(t), r = ~W.qsa(s, e).indexOf(t), n && V.removeChild(t), r + }, R = function(t) { + return t.replace(/-+(.)?/g, function(t, e) { + return e ? e.toUpperCase() : "" + }) + }, C = function(i) { + return _.call(i, function(t, e) { + return i.indexOf(t) == e + }) + }, W.fragment = function(t, e, i) { + var r, s, n; + return P.test(t) && (r = g(I.createElement(RegExp.$1))), r || (t.replace && (t = t.replace(B, "<$1>")), e === A && (e = T.test(t) && RegExp.$1), e in L || (e = "*"), (n = L[e]).innerHTML = "" + t, r = g.each(M.call(n.childNodes), function() { + n.removeChild(this) + })), c(i) && (s = g(r), g.each(i, function(t, e) { + -1 < D.indexOf(t) ? s[t](e) : s.attr(t, e) + })), r + }, W.Z = function(t, e) { + return (t = t || []).__proto__ = g.fn, t.selector = e || "", t + }, W.isZ = function(t) { + return t instanceof W.Z + }, W.init = function(t, e) { + var i, r; + if (!t) return W.Z(); + if ("string" == typeof t) + if ("<" == (t = t.trim())[0] && T.test(t)) i = W.fragment(t, RegExp.$1, e), t = null; + else { + if (e !== A) return g(e).find(t); + i = W.qsa(I, t) + } else { + if (a(t)) return g(I).ready(t); + if (W.isZ(t)) return t; + if (q(t)) r = t, i = _.call(r, function(t) { + return null != t + }); + else if (s(t)) i = [t], t = null; + else if (T.test(t)) i = W.fragment(t.trim(), RegExp.$1, e), t = null; + else { + if (e !== A) return g(e).find(t); + i = W.qsa(I, t) + } + } + return W.Z(i, t) + }, (g = function(t, e) { + return W.init(t, e) + }).extend = function(e) { + var i, t = M.call(arguments, 1); + return "boolean" == typeof e && (i = e, e = t.shift()), t.forEach(function(t) { + ! function t(e, i, r) { + for (b in i) r && (c(i[b]) || q(i[b])) ? (c(i[b]) && !c(e[b]) && (e[b] = {}), q(i[b]) && !q(e[b]) && (e[b] = []), t(e[b], i[b], r)) : i[b] !== A && (e[b] = i[b]) + }(e, t, i) + }), e + }, W.qsa = function(t, e) { + var i, r = "#" == e[0], + s = !r && "." == e[0], + n = r || s ? e.slice(1) : e, + a = U.test(n); + return o(t) && a && r ? (i = t.getElementById(n)) ? [i] : [] : 1 !== t.nodeType && 9 !== t.nodeType ? [] : M.call(a && !r ? s ? t.getElementsByClassName(n) : t.getElementsByTagName(e) : t.querySelectorAll(e)) + }, g.contains = I.documentElement.contains ? function(t, e) { + return t !== e && t.contains(e) + } : function(t, e) { + for (; e && (e = e.parentNode);) + if (e === t) return !0; + return !1 + }, g.type = h, g.isFunction = a, g.isWindow = n, g.isArray = q, g.isPlainObject = c, g.isEmptyObject = function(t) { + var e; + for (e in t) return !1; + return !0 + }, g.inArray = function(t, e, i) { + return w.indexOf.call(e, t, i) + }, g.camelCase = R, g.trim = function(t) { + return null == t ? "" : String.prototype.trim.call(t) + }, g.uuid = 0, g.support = {}, g.expr = {}, g.map = function(t, e) { + var i, r, s, n, a = []; + if (u(t)) + for (r = 0; r < t.length; r++) null != (i = e(t[r], r)) && a.push(i); + else + for (s in t) null != (i = e(t[s], s)) && a.push(i); + return 0 < (n = a).length ? g.fn.concat.apply([], n) : n + }, g.each = function(t, e) { + var i, r; + if (u(t)) { + for (i = 0; i < t.length; i++) + if (!1 === e.call(t[i], i, t[i])) return t + } else + for (r in t) + if (!1 === e.call(t[r], r, t[r])) return t; return t + }, g.grep = function(t, e) { + return _.call(t, e) + }, window.JSON && (g.parseJSON = JSON.parse), g.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(t, e) { + H["[object " + e + "]"] = e.toLowerCase() + }), g.fn = { + forEach: w.forEach, + reduce: w.reduce, + push: w.push, + sort: w.sort, + indexOf: w.indexOf, + concat: w.concat, + map: function(i) { + return g(g.map(this, function(t, e) { + return i.call(t, e, t) + })) + }, + slice: function() { + return g(M.apply(this, arguments)) + }, + ready: function(t) { + return x.test(I.readyState) && I.body ? t(g) : I.addEventListener("DOMContentLoaded", function() { + t(g) + }, !1), this + }, + get: function(t) { + return t === A ? M.call(this) : this[0 <= t ? t : t + this.length] + }, + toArray: function() { + return this.get() + }, + size: function() { + return this.length + }, + remove: function() { + return this.each(function() { + null != this.parentNode && this.parentNode.removeChild(this) + }) + }, + each: function(i) { + return w.every.call(this, function(t, e) { + return !1 !== i.call(t, e, t) + }), this + }, + filter: function(e) { + return a(e) ? this.not(this.not(e)) : g(_.call(this, function(t) { + return W.matches(t, e) + })) + }, + add: function(t, e) { + return g(C(this.concat(g(t, e)))) + }, + is: function(t) { + return 0 < this.length && W.matches(this[0], t) + }, + not: function(e) { + var i = []; + if (a(e) && e.call !== A) this.each(function(t) { + e.call(this, t) || i.push(this) + }); + else { + var r = "string" == typeof e ? this.filter(e) : u(e) && a(e.item) ? M.call(e) : g(e); + this.forEach(function(t) { + r.indexOf(t) < 0 && i.push(t) + }) + } + return g(i) + }, + has: function(t) { + return this.filter(function() { + return s(t) ? g.contains(this, t) : g(this).find(t).size() + }) + }, + eq: function(t) { + return -1 === t ? this.slice(t) : this.slice(t, +t + 1) + }, + first: function() { + var t = this[0]; + return t && !s(t) ? t : g(t) + }, + last: function() { + var t = this[this.length - 1]; + return t && !s(t) ? t : g(t) + }, + find: function(t) { + var i = this; + return t ? "object" == typeof t ? g(t).filter(function() { + var e = this; + return w.some.call(i, function(t) { + return g.contains(t, e) + }) + }) : 1 == this.length ? g(W.qsa(this[0], t)) : this.map(function() { + return W.qsa(this, t) + }) : g() + }, + closest: function(t, e) { + var i = this[0], + r = !1; + for ("object" == typeof t && (r = g(t)); i && !(r ? 0 <= r.indexOf(i) : W.matches(i, t));) i = i !== e && !o(i) && i.parentNode; + return g(i) + }, + parents: function(t) { + for (var e = [], i = this; 0 < i.length;) i = g.map(i, function(t) { + return (t = t.parentNode) && !o(t) && e.indexOf(t) < 0 ? (e.push(t), t) : void 0 + }); + return l(e, t) + }, + parent: function(t) { + return l(C(this.pluck("parentNode")), t) + }, + children: function(t) { + return l(this.map(function() { + return r(this) + }), t) + }, + contents: function() { + return this.map(function() { + return M.call(this.childNodes) + }) + }, + siblings: function(t) { + return l(this.map(function(t, e) { + return _.call(r(e.parentNode), function(t) { + return t !== e + }) + }), t) + }, + empty: function() { + return this.each(function() { + this.innerHTML = "" + }) + }, + pluck: function(e) { + return g.map(this, function(t) { + return t[e] + }) + }, + show: function() { + return this.each(function() { + var t, e, i; + "none" == this.style.display && (this.style.display = ""), "none" == getComputedStyle(this, "").getPropertyValue("display") && (this.style.display = (t = this.nodeName, E[t] || (e = I.createElement(t), I.body.appendChild(e), i = getComputedStyle(e, "").getPropertyValue("display"), e.parentNode.removeChild(e), "none" == i && (i = "block"), E[t] = i), E[t])) + }) + }, + replaceWith: function(t) { + return this.before(t).remove() + }, + wrap: function(e) { + var i = a(e); + if (this[0] && !i) var r = g(e).get(0), + s = r.parentNode || 1 < this.length; + return this.each(function(t) { + g(this).wrapAll(i ? e.call(this, t) : s ? r.cloneNode(!0) : r) + }) + }, + wrapAll: function(t) { + if (this[0]) { + g(this[0]).before(t = g(t)); + for (var e; + (e = t.children()).length;) t = e.first(); + g(t).append(this) + } + return this + }, + wrapInner: function(s) { + var n = a(s); + return this.each(function(t) { + var e = g(this), + i = e.contents(), + r = n ? s.call(this, t) : s; + i.length ? i.wrapAll(r) : e.append(r) + }) + }, + unwrap: function() { + return this.parent().each(function() { + g(this).replaceWith(g(this).children()) + }), this + }, + clone: function() { + return this.map(function() { + return this.cloneNode(!0) + }) + }, + hide: function() { + return this.css("display", "none") + }, + toggle: function(e) { + return this.each(function() { + var t = g(this); + (e === A ? "none" == t.css("display") : e) ? t.show(): t.hide() + }) + }, + prev: function(t) { + return g(this.pluck("previousElementSibling")).filter(t || "*") + }, + next: function(t) { + return g(this.pluck("nextElementSibling")).filter(t || "*") + }, + html: function(i) { + return 0 in arguments ? this.each(function(t) { + var e = this.innerHTML; + g(this).empty().append(f(this, i, t, e)) + }) : 0 in this ? this[0].innerHTML : null + }, + text: function(i) { + return 0 in arguments ? this.each(function(t) { + var e = f(this, i, t, this.textContent); + this.textContent = null == e ? "" : "" + e + }) : 0 in this ? this[0].textContent : null + }, + attr: function(e, i) { + var t; + return "string" != typeof e || 1 in arguments ? this.each(function(t) { + if (1 === this.nodeType) + if (s(e)) + for (b in e) m(this, b, e[b]); + else m(this, e, f(this, i, t, this.getAttribute(e))) + }) : this.length && 1 === this[0].nodeType ? !(t = this[0].getAttribute(e)) && e in this[0] ? this[0][e] : t : A + }, + removeAttr: function(t) { + return this.each(function() { + 1 === this.nodeType && t.split(" ").forEach(function(t) { + m(this, t) + }, this) + }) + }, + prop: function(e, i) { + return e = z[e] || e, 1 in arguments ? this.each(function(t) { + this[e] = f(this, i, t, this[e]) + }) : this[0] && this[0][e] + }, + data: function(t, e) { + var i = "data-" + t.replace(k, "-$1").toLowerCase(), + r = 1 in arguments ? this.attr(i, e) : this.attr(i); + return null !== r ? v(r) : A + }, + val: function(e) { + return 0 in arguments ? this.each(function(t) { + this.value = f(this, e, t, this.value) + }) : this[0] && (this[0].multiple ? g(this[0]).find("option").filter(function() { + return this.selected + }).pluck("value") : this[0].value) + }, + offset: function(n) { + if (n) return this.each(function(t) { + var e = g(this), + i = f(this, n, t, e.offset()), + r = e.offsetParent().offset(), + s = { + top: i.top - r.top, + left: i.left - r.left + }; + "static" == e.css("position") && (s.position = "relative"), e.css(s) + }); + if (!this.length) return null; + var t = this[0].getBoundingClientRect(); + return { + left: t.left + window.pageXOffset, + top: t.top + window.pageYOffset, + width: Math.round(t.width), + height: Math.round(t.height) + } + }, + css: function(t, e) { + if (arguments.length < 2) { + var i, r = this[0]; + if (!r) return; + if (i = getComputedStyle(r, ""), "string" == typeof t) return r.style[R(t)] || i.getPropertyValue(t); + if (q(t)) { + var s = {}; + return g.each(t, function(t, e) { + s[e] = r.style[R(e)] || i.getPropertyValue(e) + }), s + } + } + var n = ""; + if ("string" == h(t)) e || 0 === e ? n = d(t) + ":" + p(t, e) : this.each(function() { + this.style.removeProperty(d(t)) + }); + else + for (b in t) t[b] || 0 === t[b] ? n += d(b) + ":" + p(b, t[b]) + ";" : this.each(function() { + this.style.removeProperty(d(b)) + }); + return this.each(function() { + this.style.cssText += ";" + n + }) + }, + index: function(t) { + return t ? this.indexOf(g(t)[0]) : this.parent().children().indexOf(this[0]) + }, + hasClass: function(t) { + return !!t && w.some.call(this, function(t) { + return this.test(y(t)) + }, i(t)) + }, + addClass: function(i) { + return i ? this.each(function(t) { + if ("className" in this) { + S = []; + var e = y(this); + f(this, i, t, e).split(/\s+/g).forEach(function(t) { + g(this).hasClass(t) || S.push(t) + }, this), S.length && y(this, e + (e ? " " : "") + S.join(" ")) + } + }) : this + }, + removeClass: function(e) { + return this.each(function(t) { + if ("className" in this) { + if (e === A) return y(this, ""); + S = y(this), f(this, e, t, S).split(/\s+/g).forEach(function(t) { + S = S.replace(i(t), " ") + }), y(this, S.trim()) + } + }) + }, + toggleClass: function(i, r) { + return i ? this.each(function(t) { + var e = g(this); + f(this, i, t, y(this)).split(/\s+/g).forEach(function(t) { + (r === A ? !e.hasClass(t) : r) ? e.addClass(t): e.removeClass(t) + }) + }) : this + }, + scrollTop: function(t) { + if (this.length) { + var e = "scrollTop" in this[0]; + return t === A ? e ? this[0].scrollTop : this[0].pageYOffset : this.each(e ? function() { + this.scrollTop = t + } : function() { + this.scrollTo(this.scrollX, t) + }) + } + }, + scrollLeft: function(t) { + if (this.length) { + var e = "scrollLeft" in this[0]; + return t === A ? e ? this[0].scrollLeft : this[0].pageXOffset : this.each(e ? function() { + this.scrollLeft = t + } : function() { + this.scrollTo(t, this.scrollY) + }) + } + }, + position: function() { + if (this.length) { + var t = this[0], + e = this.offsetParent(), + i = this.offset(), + r = N.test(e[0].nodeName) ? { + top: 0, + left: 0 + } : e.offset(); + return i.top -= parseFloat(g(t).css("margin-top")) || 0, i.left -= parseFloat(g(t).css("margin-left")) || 0, r.top += parseFloat(g(e[0]).css("border-top-width")) || 0, r.left += parseFloat(g(e[0]).css("border-left-width")) || 0, { + top: i.top - r.top, + left: i.left - r.left + } + } + }, + offsetParent: function() { + return this.map(function() { + for (var t = this.offsetParent || I.body; t && !N.test(t.nodeName) && "static" == g(t).css("position");) t = t.offsetParent; + return t + }) + } + }, g.fn.detach = g.fn.remove, ["width", "height"].forEach(function(r) { + var s = r.replace(/./, function(t) { + return t[0].toUpperCase() + }); + g.fn[r] = function(e) { + var t, i = this[0]; + return e === A ? n(i) ? i["inner" + s] : o(i) ? i.documentElement["scroll" + s] : (t = this.offset()) && t[r] : this.each(function(t) { + (i = g(this)).css(r, f(this, e, t, i[r]())) + }) + } + }), ["after", "prepend", "before", "append"].forEach(function(e, a) { + var o = a % 2; + g.fn[e] = function() { + var e, r, s = g.map(arguments, function(t) { + return "object" == (e = h(t)) || "array" == e || null == t ? t : W.fragment(t) + }), + n = 1 < this.length; + return s.length < 1 ? this : this.each(function(t, e) { + r = o ? e : e.parentNode, e = 0 == a ? e.nextSibling : 1 == a ? e.firstChild : 2 == a ? e : null; + var i = g.contains(I.documentElement, r); + s.forEach(function(t) { + if (n) t = t.cloneNode(!0); + else if (!r) return g(t).remove(); + r.insertBefore(t, e), i && function t(e, i) { + i(e); + for (var r = 0, s = e.childNodes.length; r < s; r++) t(e.childNodes[r], i) + }(t, function(t) { + null == t.nodeName || "SCRIPT" !== t.nodeName.toUpperCase() || t.type && "text/javascript" !== t.type || t.src || window.eval.call(window, t.innerHTML) + }) + }) + }) + }, g.fn[o ? e + "To" : "insert" + (a ? "Before" : "After")] = function(t) { + return g(t)[e](this), this + } + }), W.Z.prototype = g.fn, W.uniq = C, W.deserializeValue = v, g.zepto = W, g +}(); + +function layerLandscape(t) { + $("#layui-m-layer" + t + " .layui-m-layersection").css({ + transform: "rotate(90deg)" + }) +} + +function hex(t, e, i) { + void 0 === i && (i = !0), void 0 === e && (e = 8); + var r = (t >>> 0).toString(16).toUpperCase(); + return (e -= r.length) < 0 ? r : (i ? "0x" : "") + new Array(e + 1).join("0") + r +} + +function ARMCore() { + this.inherit(), this.SP = 13, this.LR = 14, this.PC = 15, this.MODE_ARM = 0, this.MODE_THUMB = 1, this.MODE_USER = 16, this.MODE_FIQ = 17, this.MODE_IRQ = 18, this.MODE_SUPERVISOR = 19, this.MODE_ABORT = 23, this.MODE_UNDEFINED = 27, this.MODE_SYSTEM = 31, this.BANK_NONE = 0, this.BANK_FIQ = 1, this.BANK_IRQ = 2, this.BANK_SUPERVISOR = 3, this.BANK_ABORT = 4, this.BANK_UNDEFINED = 5, this.UNALLOC_MASK = 268435200, this.USER_MASK = 4026531840, this.PRIV_MASK = 207, this.STATE_MASK = 32, this.WORD_SIZE_ARM = 4, this.WORD_SIZE_THUMB = 2, this.BASE_RESET = 0, this.BASE_UNDEF = 4, this.BASE_SWI = 8, this.BASE_PABT = 12, this.BASE_DABT = 16, this.BASE_IRQ = 24, this.BASE_FIQ = 28, this.armCompiler = new ARMCoreArm(this), this.thumbCompiler = new ARMCoreThumb(this), this.generateConds(), this.gprs = new Int32Array(16) +} +window.Zepto = Zepto, void 0 === window.$ && (window.$ = Zepto), + function(u) { + function d(t) { + return t._zid || (t._zid = e++) + } + + function a(t, e, i, r) { + if ((e = p(e)).ns) var s = (n = e.ns, new RegExp("(?:^| )" + n.replace(" ", " .* ?") + "(?: |$)")); + var n; + return (R[d(t)] || []).filter(function(t) { + return !(!t || e.e && t.e != e.e || e.ns && !s.test(t.ns) || i && d(t.fn) !== d(i) || r && t.sel != r) + }) + } + + function p(t) { + var e = ("" + t).split("."); + return { + e: e[0], + ns: e.slice(1).sort().join(" ") + } + } + + function l(t, e) { + return t.del && !i && t.e in r || !!e + } + + function f(t) { + return C[t] || i && r[t] || t + } + + function c(s, t, e, n, a, o, h) { + var i = d(s), + c = R[i] || (R[i] = []); + t.split(/\s/).forEach(function(t) { + if ("ready" == t) return u(document).ready(e); + var i = p(t); + i.fn = e, i.sel = a, i.e in C && (e = function(t) { + var e = t.relatedTarget; + return !e || e !== this && !u.contains(this, e) ? i.fn.apply(this, arguments) : void 0 + }); + var r = (i.del = o) || e; + i.proxy = function(t) { + if (!(t = y(t)).isImmediatePropagationStopped()) { + t.data = n; + var e = r.apply(s, t._args == A ? [t] : [t].concat(t._args)); + return !1 === e && (t.preventDefault(), t.stopPropagation()), e + } + }, i.i = c.length, c.push(i), "addEventListener" in s && s.addEventListener(f(i.e), i.proxy, l(i, h)) + }) + } + + function m(e, t, i, r, s) { + var n = d(e); + (t || "").split(/\s/).forEach(function(t) { + a(e, t, i, r).forEach(function(t) { + delete R[n][t.i], "removeEventListener" in e && e.removeEventListener(f(t.e), t.proxy, l(t, s)) + }) + }) + } + + function y(r, s) { + return (s || !r.isDefaultPrevented) && (s || (s = r), u.each(t, function(t, e) { + var i = s[t]; + r[t] = function() { + return this[e] = o, i && i.apply(s, arguments) + }, r[e] = w + }), (s.defaultPrevented !== A ? s.defaultPrevented : "returnValue" in s ? !1 === s.returnValue : s.getPreventDefault && s.getPreventDefault()) && (r.isDefaultPrevented = o)), r + } + + function v(t) { + var e, i = { + originalEvent: t + }; + for (e in t) s.test(e) || t[e] === A || (i[e] = t[e]); + return y(i, t) + } + var A, e = 1, + b = Array.prototype.slice, + g = u.isFunction, + S = function(t) { + return "string" == typeof t + }, + R = {}, + n = {}, + i = "onfocusin" in window, + r = { + focus: "focusin", + blur: "focusout" + }, + C = { + mouseenter: "mouseover", + mouseleave: "mouseout" + }; + n.click = n.mousedown = n.mouseup = n.mousemove = "MouseEvents", u.event = { + add: c, + remove: m + }, u.proxy = function(t, e) { + var i = 2 in arguments && b.call(arguments, 2); + if (g(t)) { + var r = function() { + return t.apply(e, i ? i.concat(b.call(arguments)) : arguments) + }; + return r._zid = d(t), r + } + if (S(e)) return i ? (i.unshift(t[e], t), u.proxy.apply(null, i)) : u.proxy(t[e], t); + throw new TypeError("expected function") + }, u.fn.bind = function(t, e, i) { + return this.on(t, e, i) + }, u.fn.unbind = function(t, e) { + return this.off(t, e) + }, u.fn.one = function(t, e, i, r) { + return this.on(t, e, i, r, 1) + }; + var o = function() { + return !0 + }, + w = function() { + return !1 + }, + s = /^([A-Z]|returnValue$|layer[XY]$)/, + t = { + preventDefault: "isDefaultPrevented", + stopImmediatePropagation: "isImmediatePropagationStopped", + stopPropagation: "isPropagationStopped" + }; + u.fn.delegate = function(t, e, i) { + return this.on(e, t, i) + }, u.fn.undelegate = function(t, e, i) { + return this.off(e, t, i) + }, u.fn.live = function(t, e) { + return u(document.body).delegate(this.selector, t, e), this + }, u.fn.die = function(t, e) { + return u(document.body).undelegate(this.selector, t, e), this + }, u.fn.on = function(e, s, i, n, a) { + var o, h, r = this; + return e && !S(e) ? (u.each(e, function(t, e) { + r.on(t, s, i, e, a) + }), r) : (S(s) || g(n) || !1 === n || (n = i, i = s, s = A), (g(i) || !1 === i) && (n = i, i = A), !1 === n && (n = w), r.each(function(t, r) { + a && (o = function(t) { + return m(r, t.type, n), n.apply(this, arguments) + }), s && (h = function(t) { + var e, i = u(t.target).closest(s, r).get(0); + return i && i !== r ? (e = u.extend(v(t), { + currentTarget: i, + liveFired: r + }), (o || n).apply(i, [e].concat(b.call(arguments, 1)))) : void 0 + }), c(r, e, n, i, s, h || o) + })) + }, u.fn.off = function(t, i, e) { + var r = this; + return t && !S(t) ? (u.each(t, function(t, e) { + r.off(t, i, e) + }), r) : (S(i) || g(e) || !1 === e || (e = i, i = A), !1 === e && (e = w), r.each(function() { + m(this, t, e, i) + })) + }, u.fn.trigger = function(t, e) { + return (t = S(t) || u.isPlainObject(t) ? u.Event(t) : y(t))._args = e, this.each(function() { + t.type in r && "function" == typeof this[t.type] ? this[t.type]() : "dispatchEvent" in this ? this.dispatchEvent(t) : u(this).triggerHandler(t, e) + }) + }, u.fn.triggerHandler = function(i, r) { + var s, n; + return this.each(function(t, e) { + (s = v(S(i) ? u.Event(i) : i))._args = r, s.target = e, u.each(a(e, i.type || i), function(t, e) { + return n = e.proxy(s), !s.isImmediatePropagationStopped() && void 0 + }) + }), n + }, "focusin focusout focus blur load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select keydown keypress keyup error".split(" ").forEach(function(e) { + u.fn[e] = function(t) { + return 0 in arguments ? this.bind(e, t) : this.trigger(e) + } + }), u.Event = function(t, e) { + S(t) || (t = (e = t).type); + var i = document.createEvent(n[t] || "Events"), + r = !0; + if (e) + for (var s in e) "bubbles" == s ? r = !!e[s] : i[s] = e[s]; + return i.initEvent(t, r, !0), y(i) + } + }(Zepto), + function(fh) { + function hh(t, e, i, r) { + return t.global ? (s = e || xh, n = i, a = r, o = fh.Event(n), fh(s).trigger(o, a), !o.isDefaultPrevented()) : void 0; + var s, n, a, o + } + + function kh(t, e) { + var i = e.context; + return !1 !== e.beforeSend.call(i, t, e) && !1 !== hh(e, i, "ajaxBeforeSend", [t, e]) && void hh(e, i, "ajaxSend", [t, e]) + } + + function lh(t, e, i, r) { + var s = i.context, + n = "success"; + i.success.call(s, t, n, e), r && r.resolveWith(s, [t, n, e]), hh(i, s, "ajaxSuccess", [e, i, t]), nh(n, e, i) + } + + function mh(t, e, i, r, s) { + var n = r.context; + r.error.call(n, i, e, t), s && s.rejectWith(n, [i, e, t]), hh(r, n, "ajaxError", [i, r, t || e]), nh(e, i, r) + } + + function nh(t, e, i) { + var r, s = i.context; + i.complete.call(s, e, t), hh(i, s, "ajaxComplete", [e, i]), (r = i).global && !--fh.active && hh(r, null, "ajaxStop") + } + + function oh() {} + + function qh(t, e) { + return "" == e ? t : (t + "&" + e).replace(/[&?]{1,2}/, "?") + } + + function sh(t, e, i, r) { + return fh.isFunction(e) && (r = i, i = e, e = void 0), fh.isFunction(i) || (r = i, i = void 0), { + url: t, + data: e, + success: i, + dataType: r + } + } + var uh, vh, wh = 0, + xh = window.document, + yh = /)<[^<]*)*<\/script>/gi, + zh = /^(?:text|application)\/javascript/i, + Ah = /^(?:text|application)\/xml/i, + Bh = "application/json", + Ch = "text/html", + Dh = /^\s*$/, + Eh = xh.createElement("a"); + Eh.href = window.location.href, fh.active = 0, fh.ajaxJSONP = function(i, r) { + if (!("type" in i)) return fh.ajax(i); + var s, n, t = i.jsonpCallback, + a = (fh.isFunction(t) ? t() : t) || "jsonp" + ++wh, + o = xh.createElement("script"), + h = window[a], + e = function(t) { + fh(o).triggerHandler("error", t || "abort") + }, + c = { + abort: e + }; + return r && r.promise(c), fh(o).on("load error", function(t, e) { + clearTimeout(n), fh(o).off().remove(), "error" != t.type && s ? lh(s[0], c, i, r) : mh(null, e || "error", c, i, r), window[a] = h, s && fh.isFunction(h) && h(s[0]), h = s = void 0 + }), !1 === kh(c, i) ? e("abort") : (window[a] = function() { + s = arguments + }, o.src = i.url.replace(/\?(.+)=\?/, "?$1=" + a), xh.head.appendChild(o), 0 < i.timeout && (n = setTimeout(function() { + e("timeout") + }, i.timeout))), c + }, fh.ajaxSettings = { + type: "GET", + beforeSend: oh, + success: oh, + error: oh, + complete: oh, + context: null, + global: !0, + xhr: function() { + return new window.XMLHttpRequest + }, + accepts: { + script: "text/javascript, application/javascript, application/x-javascript", + json: Bh, + xml: "application/xml, text/xml", + html: Ch, + text: "text/plain" + }, + crossDomain: !1, + timeout: 0, + processData: !0, + cache: !0 + }, fh.ajax = function(Li) { + var Mi, ki, Oh, Ni = fh.extend({}, Li || {}), + Oi = fh.Deferred && fh.Deferred(); + for (uh in fh.ajaxSettings) void 0 === Ni[uh] && (Ni[uh] = fh.ajaxSettings[uh]); + (Oh = Ni).global && 0 == fh.active++ && hh(Oh, null, "ajaxStart"), Ni.crossDomain || ((Mi = xh.createElement("a")).href = Ni.url, Mi.href = Mi.href, Ni.crossDomain = Eh.protocol + "//" + Eh.host != Mi.protocol + "//" + Mi.host), Ni.url || (Ni.url = window.location.toString()), (ki = Ni).processData && ki.data && "string" != fh.type(ki.data) && (ki.data = fh.param(ki.data, ki.traditional)), !ki.data || ki.type && "GET" != ki.type.toUpperCase() || (ki.url = qh(ki.url, ki.data), ki.data = void 0); + var Pi = Ni.dataType, + Qi = /\?.+=\?/.test(Ni.url); + if (Qi && (Pi = "jsonp"), !1 !== Ni.cache && (Li && !0 === Li.cache || "script" != Pi && "jsonp" != Pi) || (Ni.url = qh(Ni.url, "_=" + Date.now())), "jsonp" == Pi) return Qi || (Ni.url = qh(Ni.url, Ni.jsonp ? Ni.jsonp + "=?" : !1 === Ni.jsonp ? "" : "callback=?")), fh.ajaxJSONP(Ni, Oi); + var Ri, Si = Ni.accepts[Pi], + Ti = {}, + Ui = function(t, e) { + Ti[t.toLowerCase()] = [t, e] + }, + Vi = /^([\w-]+:)\/\//.test(Ni.url) ? RegExp.$1 : window.location.protocol, + Wi = Ni.xhr(), + Xi = Wi.setRequestHeader; + if (Oi && Oi.promise(Wi), Ni.crossDomain || Ui("X-Requested-With", "XMLHttpRequest"), Ui("Accept", Si || "*/*"), (Si = Ni.mimeType || Si) && (-1 < Si.indexOf(",") && (Si = Si.split(",", 2)[0]), Wi.overrideMimeType && Wi.overrideMimeType(Si)), (Ni.contentType || !1 !== Ni.contentType && Ni.data && "GET" != Ni.type.toUpperCase()) && Ui("Content-Type", Ni.contentType || "application/x-www-form-urlencoded"), Ni.headers) + for (vh in Ni.headers) Ui(vh, Ni.headers[vh]); + if (Wi.setRequestHeader = Ui, !(Wi.onreadystatechange = function() { + if (4 == Wi.readyState) { + Wi.onreadystatechange = oh, clearTimeout(Ri); + var _i, aj = !1; + if (200 <= Wi.status && Wi.status < 300 || 304 == Wi.status || 0 == Wi.status && "file:" == Vi) { + Pi = Pi || ((hi = Ni.mimeType || Wi.getResponseHeader("content-type")) && (hi = hi.split(";", 2)[0]), hi && (hi == Ch ? "html" : hi == Bh ? "json" : zh.test(hi) ? "script" : Ah.test(hi) && "xml") || "text"), _i = Wi.responseText; + try { + "script" == Pi ? eval(_i) : "xml" == Pi ? _i = Wi.responseXML : "json" == Pi && (_i = Dh.test(_i) ? null : fh.parseJSON(_i)) + } catch (t) { + aj = t + } + aj ? mh(aj, "parsererror", Wi, Ni, Oi) : lh(_i, Wi, Ni, Oi) + } else mh(Wi.statusText || null, Wi.status ? "error" : "abort", Wi, Ni, Oi) + } + var hi + }) === kh(Wi, Ni)) return Wi.abort(), mh(null, "abort", Wi, Ni, Oi), Wi; + if (Ni.xhrFields) + for (vh in Ni.xhrFields) Wi[vh] = Ni.xhrFields[vh]; + var Yi = !("async" in Ni) || Ni.async; + for (vh in Wi.open(Ni.type, Ni.url, Yi, Ni.username, Ni.password), Ti) Xi.apply(Wi, Ti[vh]); + return 0 < Ni.timeout && (Ri = setTimeout(function() { + Wi.onreadystatechange = oh, Wi.abort(), mh(null, "timeout", Wi, Ni, Oi) + }, Ni.timeout)), Wi.send(Ni.data ? Ni.data : null), Wi + }, fh.get = function() { + return fh.ajax(sh.apply(null, arguments)) + }, fh.post = function() { + var t = sh.apply(null, arguments); + return t.type = "POST", fh.ajax(t) + }, fh.getJSON = function() { + var t = sh.apply(null, arguments); + return t.dataType = "json", fh.ajax(t) + }, fh.fn.load = function(t, e, i) { + if (!this.length) return this; + var r, s = this, + n = t.split(/\s/), + a = sh(t, e, i), + o = a.success; + return 1 < n.length && (a.url = n[0], r = n[1]), a.success = function(t) { + s.html(r ? fh("
").html(t.replace(yh, "")).find(r) : t), o && o.apply(s, arguments) + }, fh.ajax(a), this + }; + var Fh = encodeURIComponent; + fh.param = function(t, e) { + var i = []; + return i.add = function(t, e) { + fh.isFunction(e) && (e = e()), null == e && (e = ""), this.push(Fh(t) + "=" + Fh(e)) + }, + function i(r, t, s, n) { + var a, o = fh.isArray(t), + h = fh.isPlainObject(t); + fh.each(t, function(t, e) { + a = fh.type(e), n && (t = s ? n : n + "[" + (h || "object" == a || "array" == a ? t : "") + "]"), !n && o ? r.add(e.name, e.value) : "array" == a || !s && "object" == a ? i(r, e, s, t) : r.add(t, e) + }) + }(i, t, e), i.join("&").replace(/%20/g, "+") + } + }(Zepto), + function(n) { + n.fn.serializeArray = function() { + var i, r, e = [], + s = function(t) { + return t.forEach ? t.forEach(s) : void e.push({ + name: i, + value: t + }) + }; + return this[0] && n.each(this[0].elements, function(t, e) { + r = e.type, (i = e.name) && "fieldset" != e.nodeName.toLowerCase() && !e.disabled && "submit" != r && "reset" != r && "button" != r && "file" != r && ("radio" != r && "checkbox" != r || e.checked) && s(n(e).val()) + }), e + }, n.fn.serialize = function() { + var e = []; + return this.serializeArray().forEach(function(t) { + e.push(encodeURIComponent(t.name) + "=" + encodeURIComponent(t.value)) + }), e.join("&") + }, n.fn.submit = function(t) { + if (0 in arguments) this.bind("submit", t); + else if (this.length) { + var e = n.Event("submit"); + this.eq(0).trigger(e), e.isDefaultPrevented() || this.get(0).submit() + } + return this + } + }(Zepto), + function(i) { + "__proto__" in {} || i.extend(i.zepto, { + Z: function(t, e) { + return t = t || [], i.extend(t, i.fn), t.selector = e || "", t.__Z = !0, t + }, + isZ: function(t) { + return "array" === i.type(t) && "__Z" in t + } + }); + try { + getComputedStyle(void 0) + } catch (t) { + var e = getComputedStyle; + window.getComputedStyle = function(t) { + try { + return e(t) + } catch (t) { + return null + } + } + } + }(Zepto), + function(R) { + "use strict"; + var n, C = "File format is not recognized.", + a = "File contains encrypted entry.", + o = "File is using Zip64 (4gb+ file size).", + p = "Error while reading zip file.", + r = "Error while reading file data.", + A = 524288, + h = "text/plain"; + try { + n = 0 === new Blob([new DataView(new ArrayBuffer(0))]).size + } catch (t) {} + + function i() { + this.crc = -1 + } + + function d() {} + + function w(t, e) { + var i, r; + return i = new ArrayBuffer(t), r = new Uint8Array(i), e && r.set(e, 0), { + buffer: i, + array: r, + view: new DataView(i) + } + } + + function t() {} + + function e(r) { + var s, n = this; + n.size = 0, n.init = function(t, e) { + var i = new Blob([r], { + type: h + }); + (s = new c(i)).init(function() { + n.size = s.size, t() + }, e) + }, n.readUint8Array = function(t, e, i, r) { + s.readUint8Array(t, e, i, r) + } + } + + function s(c) { + var u, i = this; + i.size = 0, i.init = function(t) { + for (var e = c.length; + "=" == c.charAt(e - 1);) e--; + u = c.indexOf(",") + 1, i.size = Math.floor(.75 * (e - u)), t() + }, i.readUint8Array = function(t, e, i) { + var r, s = w(e), + n = 4 * Math.floor(t / 3), + a = 4 * Math.ceil((t + e) / 3), + o = R.atob(c.substring(n + u, a + u)), + h = t - 3 * Math.floor(n / 4); + for (r = h; r < h + e; r++) s.array[r - h] = o.charCodeAt(r); + i(s.array) + } + } + + function c(n) { + var e = this; + e.size = 0, e.init = function(t) { + e.size = n.size, t() + }, e.readUint8Array = function(t, e, i, r) { + var s = new FileReader; + s.onload = function(t) { + i(new Uint8Array(t.target.result)) + }, s.onerror = r; + try { + s.readAsArrayBuffer(function(t, e, i) { + if (e < 0 || i < 0 || e + i > t.size) throw new RangeError("offset:" + e + ", length:" + i + ", size:" + t.size); + return t.slice ? t.slice(e, e + i) : t.webkitSlice ? t.webkitSlice(e, e + i) : t.mozSlice ? t.mozSlice(e, e + i) : t.msSlice ? t.msSlice(e, e + i) : void 0 + }(n, t, e)) + } catch (t) { + r(t) + } + } + } + + function u() {} + + function l(r) { + var s; + this.init = function(t) { + s = new Blob([], { + type: h + }), t() + }, this.writeUint8Array = function(t, e) { + s = new Blob([s, n ? t : t.buffer], { + type: h + }), e() + }, this.getData = function(e, t) { + var i = new FileReader; + i.onload = function(t) { + e(t.target.result) + }, i.onerror = t, i.readAsText(s, r) + } + } + + function f(e) { + var n = "", + a = ""; + this.init = function(t) { + n += "data:" + (e || "") + ";base64,", t() + }, this.writeUint8Array = function(t, e) { + var i, r = a.length, + s = a; + for (a = "", i = 0; i < 3 * Math.floor((r + t.length) / 3) - r; i++) s += String.fromCharCode(t[i]); + for (; i < t.length; i++) a += String.fromCharCode(t[i]); + 2 < s.length ? n += R.btoa(s) : a = s, e() + }, this.getData = function(t) { + t(n + R.btoa(a)) + } + } + + function m(i) { + var r; + this.init = function(t) { + r = new Blob([], { + type: i + }), t() + }, this.writeUint8Array = function(t, e) { + r = new Blob([r, n ? t : t.buffer], { + type: i + }), e() + }, this.getData = function(t) { + t(r) + } + } + + function M(s, i, t, n, e, a, o, r, h, c) { + var u, d, p, l = 0, + f = i.sn; + + function m() { + s.removeEventListener("message", y, !1), r(d, p) + } + + function y(t) { + var e = t.data, + i = e.data, + r = e.error; + if (r) return r.toString = function() { + return "Error: " + this.message + }, void h(r); + if (e.sn === f) switch ("number" == typeof e.codecTime && (s.codecTime += e.codecTime), "number" == typeof e.crcTime && (s.crcTime += e.crcTime), e.type) { + case "append": + i ? (d += i.length, n.writeUint8Array(i, function() { + v() + }, c)) : v(); + break; + case "flush": + p = e.crc, i ? (d += i.length, n.writeUint8Array(i, function() { + m() + }, c)) : m(); + break; + case "progress": + o && o(u + e.loaded, a); + break; + case "importScripts": + case "newTask": + case "echo": + break; + default: + console.warn("zip.js:launchWorkerProcess: unknown message: ", e) + } + } + + function v() { + (u = l * A) <= a ? t.readUint8Array(e + u, Math.min(A, a - u), function(t) { + o && o(u, a); + var e = 0 === u ? i : { + sn: f + }; + e.type = "append", e.data = t; + try { + s.postMessage(e, [t.buffer]) + } catch (t) { + s.postMessage(e) + } + l++ + }, h) : s.postMessage({ + sn: f, + type: "flush" + }) + } + d = 0, s.addEventListener("message", y, !1), v() + } + + function _(r, e, s, n, a, t, o, h, c, u) { + var d, p = 0, + l = 0, + f = "input" === t, + m = "output" === t, + y = new i; + ! function i() { + var t; + if ((d = p * A) < a) e.readUint8Array(n + d, Math.min(A, a - d), function(t) { + var e; + try { + e = r.append(t, function(t) { + o && o(d + t, a) + }) + } catch (t) { + return void c(t) + } + e ? (l += e.length, s.writeUint8Array(e, function() { + p++, setTimeout(i, 1) + }, u), m && y.append(e)) : (p++, setTimeout(i, 1)), f && y.append(t), o && o(d, a) + }, c); + else { + try { + t = r.flush() + } catch (t) { + return void c(t) + } + t ? (m && y.append(t), l += t.length, s.writeUint8Array(t, function() { + h(l, y.get()) + }, u)) : h(l, y.get()) + } + }() + } + + function I(t, e, i, r, s, n, a, o, h, c, u) { + R.zip.useWebWorkers && a ? M(t, { + sn: e, + codecClass: "NOOP", + crcType: "input" + }, i, r, s, n, h, o, c, u) : _(new d, i, r, s, n, "input", h, o, c, u) + } + + function y(t) { + var e, i, r = "", + s = ["Ç", "ü", "é", "â", "ä", "à", "å", "ç", "ê", "ë", "è", "ï", "î", "ì", "Ä", "Å", "É", "æ", "Æ", "ô", "ö", "ò", "û", "ù", "ÿ", "Ö", "Ü", "ø", "£", "Ø", "×", "ƒ", "á", "í", "ó", "ú", "ñ", "Ñ", "ª", "º", "¿", "®", "¬", "½", "¼", "¡", "«", "»", "_", "_", "_", "¦", "¦", "Á", "Â", "À", "©", "¦", "¦", "+", "+", "¢", "¥", "+", "+", "-", "-", "+", "-", "+", "ã", "Ã", "+", "+", "-", "-", "¦", "-", "+", "¤", "ð", "Ð", "Ê", "Ë", "È", "i", "Í", "Î", "Ï", "+", "+", "_", "_", "¦", "Ì", "_", "Ó", "ß", "Ô", "Ò", "õ", "Õ", "µ", "þ", "Þ", "Ú", "Û", "Ù", "ý", "Ý", "¯", "´", "­", "±", "_", "¾", "¶", "§", "÷", "¸", "°", "¨", "·", "¹", "³", "²", "_", " "]; + for (e = 0; e < t.length; e++) r += 127 < (i = 255 & t.charCodeAt(e)) ? s[i - 128] : String.fromCharCode(i); + return r + } + + function v(t) { + return decodeURIComponent(escape(t)) + } + + function E(t) { + var e, i = ""; + for (e = 0; e < t.length; e++) i += String.fromCharCode(t[e]); + return i + } + + function O(t, e, i, r, s) { + t.version = e.view.getUint16(i, !0), t.bitFlag = e.view.getUint16(i + 2, !0), t.compressionMethod = e.view.getUint16(i + 4, !0), t.lastModDateRaw = e.view.getUint32(i + 6, !0), t.lastModDate = function(t) { + var e = (4294901760 & t) >> 16, + i = 65535 & t; + try { + return new Date(1980 + ((65024 & e) >> 9), ((480 & e) >> 5) - 1, 31 & e, (63488 & i) >> 11, (2016 & i) >> 5, 2 * (31 & i), 0) + } catch (t) {} + }(t.lastModDateRaw), 1 != (1 & t.bitFlag) ? ((r || 8 != (8 & t.bitFlag)) && (t.crc32 = e.view.getUint32(i + 10, !0), t.compressedSize = e.view.getUint32(i + 14, !0), t.uncompressedSize = e.view.getUint32(i + 18, !0)), 4294967295 !== t.compressedSize && 4294967295 !== t.uncompressedSize ? (t.filenameLength = e.view.getUint16(i + 22, !0), t.extraFieldLength = e.view.getUint16(i + 24, !0)) : s(o)) : s(a) + } + + function b(b, e, g) { + var S = 0; + + function d() {} + d.prototype.getData = function(p, s, l, f) { + var m = this; + + function y(t, e) { + var i, r; + f && (i = e, (r = w(4)).view.setUint32(0, i), m.crc32 != r.view.getUint32(0)) ? g("CRC failed.") : p.getData(function(t) { + s(t) + }) + } + + function v(t) { + g(t || r) + } + + function A(t) { + g(t || "Error while writing file data.") + } + b.readUint8Array(m.offset, 30, function(t) { + var d, e = w(t.length, t); + 1347093252 == e.view.getUint32(0) ? (O(m, e, 4, !1, g), d = m.offset + 30 + m.filenameLength + m.extraFieldLength, p.init(function() { + var t, e, i, r, s, n, a, o, h, c, u; + 0 === m.compressionMethod ? I(m._worker, S++, b, p, d, m.compressedSize, f, y, l, v, A) : (t = m._worker, e = S++, i = b, r = p, s = d, n = m.compressedSize, a = y, o = l, h = v, c = A, u = f ? "output" : "none", R.zip.useWebWorkers ? M(t, { + sn: e, + codecClass: "Inflater", + crcType: u + }, i, r, s, n, o, a, h, c) : _(new R.zip.Inflater, i, r, s, n, u, o, a, h, c)) + }, A)) : g(C) + }, v) + }; + var i = { + getEntries: function(c) { + var u = this._worker; + ! function(r) { + var s = 22; + if (b.size < s) g(C); + else { + var t = s + 65536; + e(s, function() { + e(Math.min(t, b.size), function() { + g(C) + }) + }) + } + + function e(t, i) { + b.readUint8Array(b.size - t, t, function(t) { + for (var e = t.length - s; 0 <= e; e--) + if (80 === t[e] && 75 === t[e + 1] && 5 === t[e + 2] && 6 === t[e + 3]) return void r(new DataView(t.buffer, e, s)); + i() + }, function() { + g(p) + }) + } + }(function(t) { + var e, h; + e = t.getUint32(16, !0), h = t.getUint16(8, !0), e < 0 || e >= b.size ? g(C) : b.readUint8Array(e, b.size - e, function(t) { + var e, i, r, s, n = 0, + a = [], + o = w(t.length, t); + for (e = 0; e < h; e++) { + if ((i = new d)._worker = u, 1347092738 != o.view.getUint32(n)) return void g(C); + O(i, o, n + 6, !0, g), i.commentLength = o.view.getUint16(n + 32, !0), i.directory = 16 == (16 & o.view.getUint8(n + 38)), i.offset = o.view.getUint32(n + 42, !0), r = E(o.array.subarray(n + 46, n + 46 + i.filenameLength)), i.filename = 2048 == (2048 & i.bitFlag) ? v(r) : y(r), i.directory || "/" != i.filename.charAt(i.filename.length - 1) || (i.directory = !0), s = E(o.array.subarray(n + 46 + i.filenameLength + i.extraFieldLength, n + 46 + i.filenameLength + i.extraFieldLength + i.commentLength)), i.comment = 2048 == (2048 & i.bitFlag) ? v(s) : y(s), a.push(i), n += 46 + i.filenameLength + i.extraFieldLength + i.commentLength + } + c(a) + }, function() { + g(p) + }) + }) + }, + close: function(t) { + this._worker && (this._worker.terminate(), this._worker = null), t && t() + }, + _worker: null + }; + R.zip.useWebWorkers ? B("inflater", function(t) { + i._worker = t, e(i) + }, function(t) { + g(t) + }) : e(i) + } + + function S(t) { + return unescape(encodeURIComponent(t)) + } + + function T(t) { + var e, i = []; + for (e = 0; e < t.length; e++) i.push(t.charCodeAt(e)); + return i + } + + function g(f, e, o, m) { + var h = {}, + y = [], + v = 0, + A = 0; + + function b(t) { + o(t || "Error while writing zip file.") + } + + function g(t) { + o(t || r) + } + var i = { + add: function(i, c, r, u, d) { + var s, n, a, p = this._worker; + + function l(t, e) { + var i = w(16); + v += t || 0, i.view.setUint32(0, 1347094280), void 0 !== e && (s.view.setUint32(10, e, !0), i.view.setUint32(4, e, !0)), c && (i.view.setUint32(8, t, !0), s.view.setUint32(14, t, !0), i.view.setUint32(12, c.size, !0), s.view.setUint32(18, c.size, !0)), f.writeUint8Array(i.array, function() { + v += 16, r() + }, b) + } + + function t() { + var t, e; + (d = d || {}, i = i.trim(), d.directory && "/" != i.charAt(i.length - 1) && (i += "/"), h.hasOwnProperty(i)) ? o("File already exists."): (n = T(S(i)), y.push(i), t = function() { + var t, e, i, r, s, n, a, o, h; + c ? m || 0 === d.level ? I(p, A++, c, f, 0, c.size, !0, l, u, g, b) : (t = p, e = A++, i = c, r = f, s = d.level, n = l, a = u, o = g, h = b, R.zip.useWebWorkers ? M(t, { + sn: e, + options: { + level: s + }, + codecClass: "Deflater", + crcType: "input" + }, i, r, 0, i.size, a, n, o, h) : _(new R.zip.Deflater, i, r, 0, i.size, "input", a, n, o, h)) : l() + }, a = d.lastModDate || new Date, s = w(26), h[i] = { + headerArray: s.array, + directory: d.directory, + filename: n, + offset: v, + comment: T(S(d.comment || "")) + }, s.view.setUint32(0, 335546376), d.version && s.view.setUint8(0, d.version), m || 0 === d.level || d.directory || s.view.setUint16(4, 2048), s.view.setUint16(6, (a.getHours() << 6 | a.getMinutes()) << 5 | a.getSeconds() / 2, !0), s.view.setUint16(8, (a.getFullYear() - 1980 << 4 | a.getMonth() + 1) << 5 | a.getDate(), !0), s.view.setUint16(22, n.length, !0), (e = w(30 + n.length)).view.setUint32(0, 1347093252), e.array.set(s.array, 4), e.array.set(n, 30), v += e.array.length, f.writeUint8Array(e.array, t, b)) + } + c ? c.init(t, g) : t() + }, + close: function(t) { + this._worker && (this._worker.terminate(), this._worker = null); + var e, i, r, s = 0, + n = 0; + for (i = 0; i < y.length; i++) s += 46 + (r = h[y[i]]).filename.length + r.comment.length; + for (e = w(s + 22), i = 0; i < y.length; i++) r = h[y[i]], e.view.setUint32(n, 1347092738), e.view.setUint16(n + 4, 5120), e.array.set(r.headerArray, n + 6), e.view.setUint16(n + 32, r.comment.length, !0), r.directory && e.view.setUint8(n + 38, 16), e.view.setUint32(n + 42, r.offset, !0), e.array.set(r.filename, n + 46), e.array.set(r.comment, n + 46 + r.filename.length), n += 46 + r.filename.length + r.comment.length; + e.view.setUint32(n, 1347093766), e.view.setUint16(n + 8, y.length, !0), e.view.setUint16(n + 10, y.length, !0), e.view.setUint32(n + 12, s, !0), e.view.setUint32(n + 16, v, !0), f.writeUint8Array(e.array, function() { + f.getData(t) + }, b) + }, + _worker: null + }; + R.zip.useWebWorkers ? B("deflater", function(t) { + i._worker = t, e(i) + }, function(t) { + o(t) + }) : e(i) + } + i.prototype.append = function(t) { + for (var e = 0 | this.crc, i = this.table, r = 0, s = 0 | t.length; r < s; r++) e = e >>> 8 ^ i[255 & (e ^ t[r])]; + this.crc = e + }, i.prototype.get = function() { + return ~this.crc + }, i.prototype.table = function() { + var t, e, i, r = []; + for (t = 0; t < 256; t++) { + for (i = t, e = 0; e < 8; e++) 1 & i ? i = i >>> 1 ^ 3988292384 : i >>>= 1; + r[t] = i + } + return r + }(), d.prototype.append = function(t, e) { + return t + }, d.prototype.flush = function() {}, (e.prototype = new t).constructor = e, (s.prototype = new t).constructor = s, (c.prototype = new t).constructor = c, u.prototype.getData = function(t) { + t(this.data) + }, (l.prototype = new u).constructor = l, (f.prototype = new u).constructor = f, (m.prototype = new u).constructor = m; + var P = { + deflater: ["z-worker.js", "deflate.js"], + inflater: ["z-worker.js", "inflate.js"] + }; + + function B(t, r, s) { + if (null === R.zip.workerScripts || null === R.zip.workerScriptsPath) { + var e, i, n; + if (R.zip.workerScripts) { + if (e = R.zip.workerScripts[t], !Array.isArray(e)) return void s(new Error("zip.workerScripts." + t + " is not an array!")); + i = e, n = document.createElement("a"), e = i.map(function(t) { + return n.href = t, n.href + }) + } else(e = P[t].slice(0))[0] = (R.zip.workerScriptsPath || "") + e[0]; + var a = new Worker(e[0]); + a.codecTime = a.crcTime = 0, a.postMessage({ + type: "importScripts", + scripts: e.slice(1) + }), a.addEventListener("message", function t(e) { + var i = e.data; + if (i.error) return a.terminate(), void s(i.error); + "importScripts" === i.type && (a.removeEventListener("message", t), a.removeEventListener("error", o), r(a)) + }), a.addEventListener("error", o) + } else s(new Error("Either zip.workerScripts or zip.workerScriptsPath may be set, not both.")); + + function o(t) { + a.terminate(), s(t) + } + } + + function N(t) { + console.error(t) + } + R.zip = { + Reader: t, + Writer: u, + BlobReader: c, + Data64URIReader: s, + TextReader: e, + BlobWriter: m, + Data64URIWriter: f, + TextWriter: l, + createReader: function(t, e, i) { + i = i || N, t.init(function() { + b(t, e, i) + }, i) + }, + createWriter: function(t, e, i, r) { + i = i || N, r = !!r, t.init(function() { + g(t, e, i, r) + }, i) + }, + useWebWorkers: !0, + workerScriptsPath: null, + workerScripts: null + } + }(this), + function() { + "use strict"; + var s, a, t = zip.Reader, + e = zip.Writer; + try { + a = 0 === new Blob([new DataView(new ArrayBuffer(0))]).size + } catch (t) {} + + function n(n, r) { + var a = this; + + function o(t, e) { + var i; + a.data ? t() : ((i = new XMLHttpRequest).addEventListener("load", function() { + a.size || (a.size = Number(i.getResponseHeader("Content-Length")) || Number(i.response.byteLength)), a.data = new Uint8Array(i.response), t() + }, !1), i.addEventListener("error", e, !1), i.open("GET", n), i.responseType = "arraybuffer", i.onprogress = r, i.send()) + } + a.size = 0, a.init = function(t, e) { + if (i = n, (r = document.createElement("a")).href = i, "http:" === r.protocol || "https:" === r.protocol) { + var i, r, s = new XMLHttpRequest; + s.addEventListener("load", function() { + a.size = Number(s.getResponseHeader("Content-Length")), a.size ? t() : o(t, e) + }, !1), s.addEventListener("error", e, !1), s.open("HEAD", n), s.send() + } else o(t, e) + }, a.readUint8Array = function(t, e, i, r) { + o(function() { + i(new Uint8Array(a.data.subarray(t, t + e))) + }, r) + } + } + + function o(c) { + var r = this; + r.size = 0, r.init = function(t, e) { + var i = new XMLHttpRequest; + i.addEventListener("load", function() { + r.size = Number(i.getResponseHeader("Content-Length")), "bytes" == i.getResponseHeader("Accept-Ranges") ? t() : e("HTTP Range not supported.") + }, !1), i.addEventListener("error", e, !1), i.open("HEAD", c), i.send() + }, r.readUint8Array = function(t, e, i, r) { + var s, n, a, o, h; + s = t, n = e, a = function(t) { + i(new Uint8Array(t)) + }, o = r, (h = new XMLHttpRequest).open("GET", c), h.responseType = "arraybuffer", h.setRequestHeader("Range", "bytes=" + s + "-" + (s + n - 1)), h.addEventListener("load", function() { + a(h.response) + }, !1), h.addEventListener("error", o, !1), h.send() + } + } + + function i(s) { + var i = this; + i.size = 0, i.init = function(t, e) { + i.size = s.byteLength, t() + }, i.readUint8Array = function(t, e, i, r) { + i(new Uint8Array(s.slice(t, t + e))) + } + } + + function r() { + var s; + this.init = function(t, e) { + s = new Uint8Array, t() + }, this.writeUint8Array = function(t, e, i) { + var r = new Uint8Array(s.length + t.length); + r.set(s), r.set(t, s.length), s = r, e() + }, this.getData = function(t) { + t(s.buffer) + } + } + + function h(i, s) { + var n; + this.init = function(e, t) { + i.createWriter(function(t) { + n = t, e() + }, t) + }, this.writeUint8Array = function(t, e, i) { + var r = new Blob([a ? t : t.buffer], { + type: s + }); + n.onwrite = function() { + n.onwrite = null, e() + }, n.onerror = i, n.write(r) + }, this.getData = function(t) { + i.file(t) + } + }(n.prototype = new t).constructor = n, (o.prototype = new t).constructor = o, (i.prototype = new t).constructor = i, (r.prototype = new e).constructor = r, (h.prototype = new e).constructor = h, zip.FileWriter = h, zip.HttpReader = n, zip.HttpRangeReader = o, zip.ArrayBufferReader = i, zip.ArrayBufferWriter = r, zip.fs && ((s = zip.fs.ZipDirectoryEntry).prototype.addHttpContent = function(t, e, i) { + return function(t, e, i, r) { + if (t.directory) return r ? new s(t.fs, e, i, t) : new zip.fs.ZipFileEntry(t.fs, e, i, t); + throw "Parent entry is not a directory." + }(this, t, { + data: e, + Reader: i ? o : n + }) + }, s.prototype.importHttpContent = function(t, e, i, r) { + this.importZip(e ? new o(t) : new n(t), i, r) + }, zip.fs.FS.prototype.importHttpContent = function(t, e, i, r) { + this.entries = [], this.root = new s(this), this.root.importHttpContent(t, e, i, r) + }) + }(), + function(t) { + if ("object" == typeof exports && "undefined" != typeof module) module.exports = t(); + else if ("function" == typeof define && define.amd) define([], t); + else { + ("undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof self ? self : this).localforage = t() + } + }(function() { + return function n(a, o, h) { + function c(e, t) { + if (!o[e]) { + if (!a[e]) { + var i = "function" == typeof require && require; + if (!t && i) return i(e, !0); + if (u) return u(e, !0); + var r = new Error("Cannot find module '" + e + "'"); + throw r.code = "MODULE_NOT_FOUND", r + } + var s = o[e] = { + exports: {} + }; + a[e][0].call(s.exports, function(t) { + return c(a[e][1][t] || t) + }, s, s.exports, n, a, o, h) + } + return o[e].exports + } + for (var u = "function" == typeof require && require, t = 0; t < h.length; t++) c(h[t]); + return c + }({ + 1: [ + function(t, e, i) { + "use strict"; + + function a(e, i) { + e = e || [], i = i || {}; + try { + return new Blob(e, i) + } catch (t) { + if ("TypeError" !== t.name) throw t; + for (var r = new("undefined" != typeof BlobBuilder ? BlobBuilder : "undefined" != typeof MSBlobBuilder ? MSBlobBuilder : "undefined" != typeof MozBlobBuilder ? MozBlobBuilder : WebKitBlobBuilder), s = 0; s < e.length; s += 1) r.append(e[s]); + return r.getBlob(i.type) + } + } + + function d(t, e) { + e && t.then(function(t) { + e(null, t) + }, function(t) { + e(t) + }) + } + + function h(t, e, i) { + "function" == typeof e && t.then(e), "function" == typeof i && t.catch(i) + } + + function p(t) { + return "string" != typeof t && (console.warn(t + " used as a key, but it is not a string."), t = String(t)), t + } + + function n() { + if (arguments.length && "function" == typeof arguments[arguments.length - 1]) return arguments[arguments.length - 1] + } + + function r(t) { + return "boolean" == typeof B ? T.resolve(B) : (r = t, new T(function(i) { + var t = r.transaction(P, G), + e = a([""]); + t.objectStore(P).put(e, "key"), t.onabort = function(t) { + t.preventDefault(), t.stopPropagation(), i(!1) + }, t.oncomplete = function() { + var t = navigator.userAgent.match(/Chrome\/(\d+)/), + e = navigator.userAgent.match(/Edge\//); + i(e || !t || 43 <= parseInt(t[1], 10)) + } + }).catch(function() { + return !1 + })).then(function(t) { + return B = t + }); + var r + } + + function o(t) { + var e = N[t.name], + i = {}; + i.promise = new T(function(t, e) { + i.resolve = t, i.reject = e + }), e.deferredOperations.push(i), e.dbReady ? e.dbReady = e.dbReady.then(function() { + return i.promise + }) : e.dbReady = i.promise + } + + function c(t) { + var e = N[t.name].deferredOperations.pop(); + if (e) return e.resolve(), e.promise + } + + function u(t, e) { + var i = N[t.name].deferredOperations.pop(); + if (i) return i.reject(e), i.promise + } + + function s(s, n) { + return new T(function(t, e) { + if (N[s.name] = N[s.name] || { + forages: [], + db: null, + dbReady: null, + deferredOperations: [] + }, s.db) { + if (!n) return t(s.db); + o(s), s.db.close() + } + var i = [s.name]; + n && i.push(s.version); + var r = O.open.apply(O, i); + n && (r.onupgradeneeded = function(t) { + var e = r.result; + try { + e.createObjectStore(s.storeName), t.oldVersion <= 1 && e.createObjectStore(P) + } catch (e) { + if ("ConstraintError" !== e.name) throw e; + console.warn('The database "' + s.name + '" has been upgraded from version ' + t.oldVersion + " to version " + t.newVersion + ', but the storage "' + s.storeName + '" already exists.') + } + }), r.onerror = function(t) { + t.preventDefault(), e(r.error) + }, r.onsuccess = function() { + t(r.result), c(s) + } + }) + } + + function l(t) { + return s(t, !1) + } + + function f(t) { + return s(t, !0) + } + + function m(t, e) { + if (!t.db) return !0; + var i = !t.db.objectStoreNames.contains(t.storeName), + r = t.version < t.db.version, + s = t.version > t.db.version; + if (r && (t.version !== e && console.warn('The database "' + t.name + "\" can't be downgraded from version " + t.db.version + " to version " + t.version + "."), t.version = t.db.version), s || i) { + if (i) { + var n = t.db.version + 1; + n > t.version && (t.version = n) + } + return !0 + } + return !1 + } + + function y(t) { + return a([ + function(t) { + for (var e = t.length, i = new ArrayBuffer(e), r = new Uint8Array(i), s = 0; s < e; s++) r[s] = t.charCodeAt(s); + return i + }(atob(t.data)) + ], { + type: t.type + }) + } + + function v(t) { + return t && t.__local_forage_encoded_blob + } + + function A(t) { + var e = this, + i = e._initReady().then(function() { + var t = N[e._dbInfo.name]; + if (t && t.dbReady) return t.dbReady + }); + return h(i, t, t), i + } + + function b(t, e, i, r) { + void 0 === r && (r = 1); + try { + var s = t.db.transaction(t.storeName, e); + i(null, s) + } catch (s) { + if (0 < r && (!t.db || "InvalidStateError" === s.name || "NotFoundError" === s.name)) return T.resolve().then(function() { + if (!t.db || "NotFoundError" === s.name && !t.db.objectStoreNames.contains(t.storeName) && t.version <= t.db.version) return t.db && (t.version = t.db.version + 1), f(t) + }).then(function() { + return function(i) { + o(i); + for (var r = N[i.name], s = r.forages, t = 0; t < s.length; t++) { + var e = s[t]; + e._dbInfo.db && (e._dbInfo.db.close(), e._dbInfo.db = null) + } + return i.db = null, l(i).then(function(t) { + return i.db = t, m(i) ? f(i) : t + }).then(function(t) { + i.db = r.db = t; + for (var e = 0; e < s.length; e++) s[e]._dbInfo.db = t + }).catch(function(t) { + throw u(i, t), t + }) + }(t).then(function() { + b(t, e, i, r - 1) + }) + }).catch(i); + i(s) + } + } + + function g(t) { + var e, i, r, s, n, a = .75 * t.length, + o = t.length, + h = 0; + "=" === t[t.length - 1] && (a--, "=" === t[t.length - 2] && a--); + var c = new ArrayBuffer(a), + u = new Uint8Array(c); + for (e = 0; e < o; e += 4) i = x.indexOf(t[e]), r = x.indexOf(t[e + 1]), s = x.indexOf(t[e + 2]), n = x.indexOf(t[e + 3]), u[h++] = i << 2 | r >> 4, u[h++] = (15 & r) << 4 | s >> 2, u[h++] = (3 & s) << 6 | 63 & n; + return c + } + + function S(t) { + var e, i = new Uint8Array(t), + r = ""; + for (e = 0; e < i.length; e += 3) r += x[i[e] >> 2], r += x[(3 & i[e]) << 4 | i[e + 1] >> 4], r += x[(15 & i[e + 1]) << 2 | i[e + 2] >> 6], r += x[63 & i[e + 2]]; + return i.length % 3 == 2 ? r = r.substring(0, r.length - 1) + "=" : i.length % 3 == 1 && (r = r.substring(0, r.length - 2) + "=="), r + } + + function R(t, e, i, r) { + t.executeSql("CREATE TABLE IF NOT EXISTS " + e.storeName + " (id INTEGER PRIMARY KEY, key unique, value)", [], i, r) + } + + function C(t, r, s, n, a, o) { + t.executeSql(s, n, a, function(t, i) { + i.code === i.SYNTAX_ERR ? t.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name = ?", [r.storeName], function(t, e) { + e.rows.length ? o(t, i) : R(t, r, function() { + t.executeSql(s, n, a, o) + }, o) + }, o) : o(t, i) + }, o) + } + + function w(t, e) { + var i = t.name + "/"; + return t.storeName !== e.storeName && (i += t.storeName + "/"), i + } + + function M() { + return ! function() { + var t = "_localforage_support_test"; + try { + return localStorage.setItem(t, !0), localStorage.removeItem(t), !1 + } catch (t) { + return !0 + } + }() || 0 < localStorage.length + } + + function _(e, i) { + e[i] = function() { + var t = arguments; + return e.ready().then(function() { + return e[i].apply(e, t) + }) + } + } + + function I() { + for (var t = 1; t < arguments.length; t++) { + var e = arguments[t]; + if (e) + for (var i in e) e.hasOwnProperty(i) && (Z(e[i]) ? arguments[0][i] = e[i].slice() : arguments[0][i] = e[i]) + } + return arguments[0] + } + var E = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) { + return typeof t + } : function(t) { + return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t + }, + O = function() { + try { + if ("undefined" != typeof indexedDB) return indexedDB; + if ("undefined" != typeof webkitIndexedDB) return webkitIndexedDB; + if ("undefined" != typeof mozIndexedDB) return mozIndexedDB; + if ("undefined" != typeof OIndexedDB) return OIndexedDB; + if ("undefined" != typeof msIndexedDB) return msIndexedDB + } catch (t) { + return + } + }(); + "undefined" == typeof Promise && t("lie/polyfill"); + var T = Promise, + P = "local-forage-detect-blob-support", + B = void 0, + N = {}, + k = Object.prototype.toString, + D = "readonly", + G = "readwrite", + L = { + _driver: "asyncStorage", + _initStorage: function(t) { + function e() { + return T.resolve() + } + var r = this, + s = { + db: null + }; + if (t) + for (var i in t) s[i] = t[i]; + var n = N[s.name]; + n || (n = { + forages: [], + db: null, + dbReady: null, + deferredOperations: [] + }, N[s.name] = n), n.forages.push(r), r._initReady || (r._initReady = r.ready, r.ready = A); + for (var a = [], o = 0; o < n.forages.length; o++) { + var h = n.forages[o]; + h !== r && a.push(h._initReady().catch(e)) + } + var c = n.forages.slice(0); + return T.all(a).then(function() { + return s.db = n.db, l(s) + }).then(function(t) { + return s.db = t, m(s, r._defaultConfig.version) ? f(s) : t + }).then(function(t) { + s.db = n.db = t, r._dbInfo = s; + for (var e = 0; e < c.length; e++) { + var i = c[e]; + i !== r && (i._dbInfo.db = s.db, i._dbInfo.version = s.version) + } + }) + }, + _support: function() { + try { + if (!O) return !1; + var t = "undefined" != typeof openDatabase && /(Safari|iPhone|iPad|iPod)/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent) && !/BlackBerry/.test(navigator.platform), + e = "function" == typeof fetch && -1 !== fetch.toString().indexOf("[native code"); + return (!t || e) && "undefined" != typeof indexedDB && "undefined" != typeof IDBKeyRange + } catch (t) { + return !1 + } + }(), + iterate: function(a, t) { + var o = this, + e = new T(function(n, i) { + o.ready().then(function() { + b(o._dbInfo, D, function(t, e) { + if (t) return i(t); + try { + var r = e.objectStore(o._dbInfo.storeName).openCursor(), + s = 1; + r.onsuccess = function() { + var t = r.result; + if (t) { + var e = t.value; + v(e) && (e = y(e)); + var i = a(e, t.key, s++); + void 0 !== i ? n(i) : t.continue() + } else n() + }, r.onerror = function() { + i(r.error) + } + } catch (t) { + i(t) + } + }) + }).catch(i) + }); + return d(e, t), e + }, + getItem: function(n, t) { + var a = this; + n = p(n); + var e = new T(function(r, s) { + a.ready().then(function() { + b(a._dbInfo, D, function(t, e) { + if (t) return s(t); + try { + var i = e.objectStore(a._dbInfo.storeName).get(n); + i.onsuccess = function() { + var t = i.result; + void 0 === t && (t = null), v(t) && (t = y(t)), r(t) + }, i.onerror = function() { + s(i.error) + } + } catch (t) { + s(t) + } + }) + }).catch(s) + }); + return d(e, t), e + }, + setItem: function(o, e, t) { + var h = this; + o = p(o); + var i = new T(function(n, a) { + var t; + h.ready().then(function() { + return t = h._dbInfo, "[object Blob]" === k.call(e) ? r(t.db).then(function(t) { + return t ? e : (r = e, new T(function(i, t) { + var e = new FileReader; + e.onerror = t, e.onloadend = function(t) { + var e = btoa(t.target.result || ""); + i({ + __local_forage_encoded_blob: !0, + data: e, + type: r.type + }) + }, e.readAsBinaryString(r) + })); + var r + }) : e + }).then(function(s) { + b(h._dbInfo, G, function(t, e) { + if (t) return a(t); + try { + var i = e.objectStore(h._dbInfo.storeName); + null === s && (s = void 0); + var r = i.put(s, o); + e.oncomplete = function() { + void 0 === s && (s = null), n(s) + }, e.onabort = e.onerror = function() { + var t = r.error ? r.error : r.transaction.error; + a(t) + } + } catch (t) { + a(t) + } + }) + }).catch(a) + }); + return d(i, t), i + }, + removeItem: function(n, t) { + var a = this; + n = p(n); + var e = new T(function(r, s) { + a.ready().then(function() { + b(a._dbInfo, G, function(t, e) { + if (t) return s(t); + try { + var i = e.objectStore(a._dbInfo.storeName).delete(n); + e.oncomplete = function() { + r() + }, e.onerror = function() { + s(i.error) + }, e.onabort = function() { + var t = i.error ? i.error : i.transaction.error; + s(t) + } + } catch (t) { + s(t) + } + }) + }).catch(s) + }); + return d(e, t), e + }, + clear: function(t) { + var n = this, + e = new T(function(r, s) { + n.ready().then(function() { + b(n._dbInfo, G, function(t, e) { + if (t) return s(t); + try { + var i = e.objectStore(n._dbInfo.storeName).clear(); + e.oncomplete = function() { + r() + }, e.onabort = e.onerror = function() { + var t = i.error ? i.error : i.transaction.error; + s(t) + } + } catch (t) { + s(t) + } + }) + }).catch(s) + }); + return d(e, t), e + }, + length: function(t) { + var n = this, + e = new T(function(r, s) { + n.ready().then(function() { + b(n._dbInfo, D, function(t, e) { + if (t) return s(t); + try { + var i = e.objectStore(n._dbInfo.storeName).count(); + i.onsuccess = function() { + r(i.result) + }, i.onerror = function() { + s(i.error) + } + } catch (t) { + s(t) + } + }) + }).catch(s) + }); + return d(e, t), e + }, + key: function(o, t) { + var h = this, + e = new T(function(n, a) { + o < 0 ? n(null) : h.ready().then(function() { + b(h._dbInfo, D, function(t, e) { + if (t) return a(t); + try { + var i = e.objectStore(h._dbInfo.storeName), + r = !1, + s = i.openCursor(); + s.onsuccess = function() { + var t = s.result; + t ? 0 === o ? n(t.key) : r ? n(t.key) : (r = !0, t.advance(o)) : n(null) + }, s.onerror = function() { + a(s.error) + } + } catch (t) { + a(t) + } + }) + }).catch(a) + }); + return d(e, t), e + }, + keys: function(t) { + var a = this, + e = new T(function(s, n) { + a.ready().then(function() { + b(a._dbInfo, D, function(t, e) { + if (t) return n(t); + try { + var i = e.objectStore(a._dbInfo.storeName).openCursor(), + r = []; + i.onsuccess = function() { + var t = i.result; + t ? (r.push(t.key), t.continue()) : s(r) + }, i.onerror = function() { + n(i.error) + } + } catch (t) { + n(t) + } + }) + }).catch(n) + }); + return d(e, t), e + }, + dropInstance: function(a, t) { + t = n.apply(this, arguments); + var e, i = this.config(); + if ((a = "function" != typeof a && a || {}).name || (a.name = a.name || i.name, a.storeName = a.storeName || i.storeName), a.name) { + var r = a.name === i.name && this._dbInfo.db ? T.resolve(this._dbInfo.db) : l(a).then(function(t) { + var e = N[a.name], + i = e.forages; + e.db = t; + for (var r = 0; r < i.length; r++) i[r]._dbInfo.db = t; + return t + }); + e = a.storeName ? r.then(function(t) { + if (t.objectStoreNames.contains(a.storeName)) { + var s = t.version + 1; + o(a); + var r = N[a.name], + n = r.forages; + t.close(); + for (var e = 0; e < n.length; e++) { + var i = n[e]; + i._dbInfo.db = null, i._dbInfo.version = s + } + return new T(function(e, i) { + var r = O.open(a.name, s); + r.onerror = function(t) { + r.result.close(), i(t) + }, r.onupgradeneeded = function() { + r.result.deleteObjectStore(a.storeName) + }, r.onsuccess = function() { + var t = r.result; + t.close(), e(t) + } + }).then(function(t) { + r.db = t; + for (var e = 0; e < n.length; e++) { + var i = n[e]; + i._dbInfo.db = t, c(i._dbInfo) + } + }).catch(function(t) { + throw (u(a, t) || T.resolve()).catch(function() {}), t + }) + } + }) : r.then(function(t) { + o(a); + var i = N[a.name], + r = i.forages; + t.close(); + for (var e = 0; e < r.length; e++) r[e]._dbInfo.db = null; + return new T(function(e, i) { + var r = O.deleteDatabase(a.name); + r.onerror = r.onblocked = function(t) { + var e = r.result; + e && e.close(), i(t) + }, r.onsuccess = function() { + var t = r.result; + t && t.close(), e(t) + } + }).then(function(t) { + i.db = t; + for (var e = 0; e < r.length; e++) c(r[e]._dbInfo) + }).catch(function(t) { + throw (u(a, t) || T.resolve()).catch(function() {}), t + }) + }) + } else e = T.reject("Invalid arguments"); + return d(e, t), e + } + }, + x = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", + U = /^~~local_forage_type~([^~]+)~/, + H = "__lfsc__:", + F = H.length, + W = "arbf", + V = "blob", + z = F + W.length, + q = Object.prototype.toString, + K = { + serialize: function(e, i) { + var t = ""; + if (e && (t = q.call(e)), e && ("[object ArrayBuffer]" === t || e.buffer && "[object ArrayBuffer]" === q.call(e.buffer))) { + var r, s = H; + e instanceof ArrayBuffer ? (r = e, s += W) : (r = e.buffer, "[object Int8Array]" === t ? s += "si08" : "[object Uint8Array]" === t ? s += "ui08" : "[object Uint8ClampedArray]" === t ? s += "uic8" : "[object Int16Array]" === t ? s += "si16" : "[object Uint16Array]" === t ? s += "ur16" : "[object Int32Array]" === t ? s += "si32" : "[object Uint32Array]" === t ? s += "ui32" : "[object Float32Array]" === t ? s += "fl32" : "[object Float64Array]" === t ? s += "fl64" : i(new Error("Failed to get type for BinaryArray"))), i(s + S(r)) + } else if ("[object Blob]" === t) { + var n = new FileReader; + n.onload = function() { + var t = "~~local_forage_type~" + e.type + "~" + S(this.result); + i(H + V + t) + }, n.readAsArrayBuffer(e) + } else try { + i(JSON.stringify(e)) + } catch (t) { + console.error("Couldn't convert value into a JSON string: ", e), i(null, t) + } + }, + deserialize: function(t) { + if (t.substring(0, F) !== H) return JSON.parse(t); + var e, i = t.substring(z), + r = t.substring(F, z); + if (r === V && U.test(i)) { + var s = i.match(U); + e = s[1], i = i.substring(s[0].length) + } + var n = g(i); + switch (r) { + case W: + return n; + case V: + return a([n], { + type: e + }); + case "si08": + return new Int8Array(n); + case "ui08": + return new Uint8Array(n); + case "uic8": + return new Uint8ClampedArray(n); + case "si16": + return new Int16Array(n); + case "ur16": + return new Uint16Array(n); + case "si32": + return new Int32Array(n); + case "ui32": + return new Uint32Array(n); + case "fl32": + return new Float32Array(n); + case "fl64": + return new Float64Array(n); + default: + throw new Error("Unkown type: " + r) + } + }, + stringToBuffer: g, + bufferToString: S + }, + j = { + _driver: "webSQLStorage", + _initStorage: function(t) { + var r = this, + s = { + db: null + }; + if (t) + for (var e in t) s[e] = "string" != typeof t[e] ? t[e].toString() : t[e]; + var i = new T(function(e, i) { + try { + s.db = openDatabase(s.name, String(s.version), s.description, s.size) + } catch (e) { + return i(e) + } + s.db.transaction(function(t) { + R(t, s, function() { + r._dbInfo = s, e() + }, function(t, e) { + i(e) + }) + }, i) + }); + return s.serializer = K, i + }, + _support: "function" == typeof openDatabase, + iterate: function(c, t) { + var e = this, + i = new T(function(h, i) { + e.ready().then(function() { + var o = e._dbInfo; + o.db.transaction(function(t) { + C(t, o, "SELECT * FROM " + o.storeName, [], function(t, e) { + for (var i = e.rows, r = i.length, s = 0; s < r; s++) { + var n = i.item(s), + a = n.value; + if (a && (a = o.serializer.deserialize(a)), void 0 !== (a = c(a, n.key, s + 1))) return void h(a) + } + h() + }, function(t, e) { + i(e) + }) + }) + }).catch(i) + }); + return d(i, t), i + }, + getItem: function(e, t) { + var n = this; + e = p(e); + var i = new T(function(s, i) { + n.ready().then(function() { + var r = n._dbInfo; + r.db.transaction(function(t) { + C(t, r, "SELECT * FROM " + r.storeName + " WHERE key = ? LIMIT 1", [e], function(t, e) { + var i = e.rows.length ? e.rows.item(0).value : null; + i && (i = r.serializer.deserialize(i)), s(i) + }, function(t, e) { + i(e) + }) + }) + }).catch(i) + }); + return d(i, t), i + }, + setItem: function(t, e, i) { + return function a(o, t, h, c) { + var u = this; + o = p(o); + var e = new T(function(s, n) { + u.ready().then(function() { + void 0 === t && (t = null); + var i = t, + r = u._dbInfo; + r.serializer.serialize(t, function(e, t) { + t ? n(t) : r.db.transaction(function(t) { + C(t, r, "INSERT OR REPLACE INTO " + r.storeName + " (key, value) VALUES (?, ?)", [o, e], function() { + s(i) + }, function(t, e) { + n(e) + }) + }, function(t) { + if (t.code === t.QUOTA_ERR) { + if (0 < c) return void s(a.apply(u, [o, i, h, c - 1])); + n(t) + } + }) + }) + }).catch(n) + }); + return d(e, h), e + }.apply(this, [t, e, i, 1]) + }, + removeItem: function(s, t) { + var n = this; + s = p(s); + var e = new T(function(i, r) { + n.ready().then(function() { + var e = n._dbInfo; + e.db.transaction(function(t) { + C(t, e, "DELETE FROM " + e.storeName + " WHERE key = ?", [s], function() { + i() + }, function(t, e) { + r(e) + }) + }) + }).catch(r) + }); + return d(e, t), e + }, + clear: function(t) { + var s = this, + e = new T(function(i, r) { + s.ready().then(function() { + var e = s._dbInfo; + e.db.transaction(function(t) { + C(t, e, "DELETE FROM " + e.storeName, [], function() { + i() + }, function(t, e) { + r(e) + }) + }) + }).catch(r) + }); + return d(e, t), e + }, + length: function(t) { + var s = this, + e = new T(function(r, i) { + s.ready().then(function() { + var e = s._dbInfo; + e.db.transaction(function(t) { + C(t, e, "SELECT COUNT(key) as c FROM " + e.storeName, [], function(t, e) { + var i = e.rows.item(0).c; + r(i) + }, function(t, e) { + i(e) + }) + }) + }).catch(i) + }); + return d(e, t), e + }, + key: function(s, t) { + var n = this, + e = new T(function(r, i) { + n.ready().then(function() { + var e = n._dbInfo; + e.db.transaction(function(t) { + C(t, e, "SELECT key FROM " + e.storeName + " WHERE id = ? LIMIT 1", [s + 1], function(t, e) { + var i = e.rows.length ? e.rows.item(0).key : null; + r(i) + }, function(t, e) { + i(e) + }) + }) + }).catch(i) + }); + return d(e, t), e + }, + keys: function(t) { + var r = this, + e = new T(function(s, i) { + r.ready().then(function() { + var e = r._dbInfo; + e.db.transaction(function(t) { + C(t, e, "SELECT key FROM " + e.storeName, [], function(t, e) { + for (var i = [], r = 0; r < e.rows.length; r++) i.push(e.rows.item(r).key); + s(i) + }, function(t, e) { + i(e) + }) + }) + }).catch(i) + }); + return d(e, t), e + }, + dropInstance: function(i, t) { + t = n.apply(this, arguments); + var r = this.config(); + (i = "function" != typeof i && i || {}).name || (i.name = i.name || r.name, i.storeName = i.storeName || r.storeName); + var e, s = this; + return d(e = i.name ? new T(function(t) { + var e, n; + e = i.name === r.name ? s._dbInfo.db : openDatabase(i.name, "", "", 0), t(i.storeName ? { + db: e, + storeNames: [i.storeName] + } : (n = e, new T(function(s, i) { + n.transaction(function(t) { + t.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name <> '__WebKitDatabaseInfoTable__'", [], function(t, e) { + for (var i = [], r = 0; r < e.rows.length; r++) i.push(e.rows.item(r).name); + s({ + db: n, + storeNames: i + }) + }, function(t, e) { + i(e) + }) + }, function(t) { + i(t) + }) + }))) + }).then(function(o) { + return new T(function(n, a) { + o.db.transaction(function(r) { + function t(e) { + return new T(function(t, i) { + r.executeSql("DROP TABLE IF EXISTS " + e, [], function() { + t() + }, function(t, e) { + i(e) + }) + }) + } + for (var e = [], i = 0, s = o.storeNames.length; i < s; i++) e.push(t(o.storeNames[i])); + T.all(e).then(function() { + n() + }).catch(function(t) { + a(t) + }) + }, function(t) { + a(t) + }) + }) + }) : T.reject("Invalid arguments"), t), e + } + }, + Q = { + _driver: "localStorageWrapper", + _initStorage: function(t) { + var e = {}; + if (t) + for (var i in t) e[i] = t[i]; + return e.keyPrefix = w(t, this._defaultConfig), M() ? ((this._dbInfo = e).serializer = K, T.resolve()) : T.reject() + }, + _support: function() { + try { + return "undefined" != typeof localStorage && "setItem" in localStorage && !!localStorage.setItem + } catch (t) { + return !1 + } + }(), + iterate: function(h, t) { + var c = this, + e = c.ready().then(function() { + for (var t = c._dbInfo, e = t.keyPrefix, i = e.length, r = localStorage.length, s = 1, n = 0; n < r; n++) { + var a = localStorage.key(n); + if (0 === a.indexOf(e)) { + var o = localStorage.getItem(a); + if (o && (o = t.serializer.deserialize(o)), void 0 !== (o = h(o, a.substring(i), s++))) return o + } + } + }); + return d(e, t), e + }, + getItem: function(i, t) { + var r = this; + i = p(i); + var e = r.ready().then(function() { + var t = r._dbInfo, + e = localStorage.getItem(t.keyPrefix + i); + return e && (e = t.serializer.deserialize(e)), e + }); + return d(e, t), e + }, + setItem: function(a, t, e) { + var o = this; + a = p(a); + var i = o.ready().then(function() { + void 0 === t && (t = null); + var n = t; + return new T(function(i, r) { + var s = o._dbInfo; + s.serializer.serialize(t, function(t, e) { + if (e) r(e); + else try { + localStorage.setItem(s.keyPrefix + a, t), i(n) + } catch (t) { + "QuotaExceededError" !== t.name && "NS_ERROR_DOM_QUOTA_REACHED" !== t.name || r(t), r(t) + } + }) + }) + }); + return d(i, e), i + }, + removeItem: function(e, t) { + var i = this; + e = p(e); + var r = i.ready().then(function() { + var t = i._dbInfo; + localStorage.removeItem(t.keyPrefix + e) + }); + return d(r, t), r + }, + clear: function(t) { + var r = this, + e = r.ready().then(function() { + for (var t = r._dbInfo.keyPrefix, e = localStorage.length - 1; 0 <= e; e--) { + var i = localStorage.key(e); + 0 === i.indexOf(t) && localStorage.removeItem(i) + } + }); + return d(e, t), e + }, + length: function(t) { + var e = this.keys().then(function(t) { + return t.length + }); + return d(e, t), e + }, + key: function(i, t) { + var r = this, + e = r.ready().then(function() { + var e, t = r._dbInfo; + try { + e = localStorage.key(i) + } catch (t) { + e = null + } + return e && (e = e.substring(t.keyPrefix.length)), e + }); + return d(e, t), e + }, + keys: function(t) { + var n = this, + e = n.ready().then(function() { + for (var t = n._dbInfo, e = localStorage.length, i = [], r = 0; r < e; r++) { + var s = localStorage.key(r); + 0 === s.indexOf(t.keyPrefix) && i.push(s.substring(t.keyPrefix.length)) + } + return i + }); + return d(e, t), e + }, + dropInstance: function(e, t) { + if (t = n.apply(this, arguments), !(e = "function" != typeof e && e || {}).name) { + var i = this.config(); + e.name = e.name || i.name, e.storeName = e.storeName || i.storeName + } + var r, s = this; + return d(r = e.name ? new T(function(t) { + t(e.storeName ? w(e, s._defaultConfig) : e.name + "/") + }).then(function(t) { + for (var e = localStorage.length - 1; 0 <= e; e--) { + var i = localStorage.key(e); + 0 === i.indexOf(t) && localStorage.removeItem(i) + } + }) : T.reject("Invalid arguments"), t), r + } + }, + Y = function(t, e) { + for (var i = t.length, r = 0; r < i;) { + if ((s = t[r]) === (n = e) || "number" == typeof s && "number" == typeof n && isNaN(s) && isNaN(n)) return !0; + r++ + } + var s, n; + return !1 + }, + Z = Array.isArray || function(t) { + return "[object Array]" === Object.prototype.toString.call(t) + }, + X = {}, + J = {}, + $ = { + INDEXEDDB: L, + WEBSQL: j, + LOCALSTORAGE: Q + }, + tt = [$.INDEXEDDB._driver, $.WEBSQL._driver, $.LOCALSTORAGE._driver], + et = ["dropInstance"], + it = ["clear", "getItem", "iterate", "key", "keys", "length", "removeItem", "setItem"].concat(et), + rt = { + description: "", + driver: tt.slice(), + name: "localforage", + size: 4980736, + storeName: "keyvaluepairs", + version: 1 + }, + st = new(function() { + function s(t) { + for (var e in function(t, e) { + if (!(t instanceof e)) throw new TypeError("Cannot call a class as a function") + }(this, s), $) + if ($.hasOwnProperty(e)) { + var i = $[e], + r = i._driver; + this[e] = r, X[r] || this.defineDriver(i) + } + this._defaultConfig = I({}, rt), this._config = I({}, this._defaultConfig, t), this._driverSet = null, this._initDriver = null, this._ready = !1, this._dbInfo = null, this._wrapLibraryMethodsWithReady(), this.setDriver(this._config.driver).catch(function() {}) + } + return s.prototype.config = function(t) { + if ("object" === (void 0 === t ? "undefined" : E(t))) { + if (this._ready) return new Error("Can't call config() after localforage has been used."); + for (var e in t) { + if ("storeName" === e && (t[e] = t[e].replace(/\W/g, "_")), "version" === e && "number" != typeof t[e]) return new Error("Database version must be a number."); + this._config[e] = t[e] + } + return !("driver" in t && t.driver) || this.setDriver(this._config.driver) + } + return "string" == typeof t ? this._config[t] : this._config + }, s.prototype.defineDriver = function(c, t, e) { + var i = new T(function(e, i) { + try { + var r = c._driver, + t = new Error("Custom driver not compliant; see https://mozilla.github.io/localForage/#definedriver"); + if (!c._driver) return void i(t); + for (var s = it.concat("_initStorage"), n = 0, a = s.length; n < a; n++) { + var o = s[n]; + if ((!Y(et, o) || c[o]) && "function" != typeof c[o]) return void i(t) + }! function() { + for (var t = function(i) { + return function() { + var t = new Error("Method " + i + " is not implemented by the current driver"), + e = T.reject(t); + return d(e, arguments[arguments.length - 1]), e + } + }, e = 0, i = et.length; e < i; e++) { + var r = et[e]; + c[r] || (c[r] = t(r)) + } + }(); + var h = function(t) { + X[r] && console.info("Redefining LocalForage driver: " + r), X[r] = c, J[r] = t, e() + }; + "_support" in c ? c._support && "function" == typeof c._support ? c._support().then(h, i) : h(!!c._support) : h(!0) + } catch (t) { + i(t) + } + }); + return h(i, t, e), i + }, s.prototype.driver = function() { + return this._driver || null + }, s.prototype.getDriver = function(t, e, i) { + var r = X[t] ? T.resolve(X[t]) : T.reject(new Error("Driver not found.")); + return h(r, e, i), r + }, s.prototype.getSerializer = function(t) { + var e = T.resolve(K); + return h(e, t), e + }, s.prototype.ready = function(t) { + var e = this, + i = e._driverSet.then(function() { + return null === e._ready && (e._ready = e._initDriver()), e._ready + }); + return h(i, t, t), i + }, s.prototype.setDriver = function(t, e, i) { + function n() { + o._config.driver = o.driver() + } + + function a(t) { + return o._extend(t), n(), o._ready = o._initStorage(o._config), o._ready + } + var o = this; + Z(t) || (t = [t]); + var r = this._getSupportedDrivers(t), + s = null !== this._driverSet ? this._driverSet.catch(function() { + return T.resolve() + }) : T.resolve(); + return this._driverSet = s.then(function() { + var t = r[0]; + return o._dbInfo = null, o._ready = null, o.getDriver(t).then(function(t) { + var s; + o._driver = t._driver, n(), o._wrapLibraryMethodsWithReady(), o._initDriver = (s = r, function() { + var r = 0; + return function t() { + for (; r < s.length;) { + var e = s[r]; + return r++, o._dbInfo = null, o._ready = null, o.getDriver(e).then(a).catch(t) + } + n(); + var i = new Error("No available storage method found."); + return o._driverSet = T.reject(i), o._driverSet + }() + }) + }) + }).catch(function() { + n(); + var t = new Error("No available storage method found."); + return o._driverSet = T.reject(t), o._driverSet + }), h(this._driverSet, e, i), this._driverSet + }, s.prototype.supports = function(t) { + return !!J[t] + }, s.prototype._extend = function(t) { + I(this, t) + }, s.prototype._getSupportedDrivers = function(t) { + for (var e = [], i = 0, r = t.length; i < r; i++) { + var s = t[i]; + this.supports(s) && e.push(s) + } + return e + }, s.prototype._wrapLibraryMethodsWithReady = function() { + for (var t = 0, e = it.length; t < e; t++) _(this, it[t]) + }, s.prototype.createInstance = function(t) { + return new s(t) + }, s + }()); + e.exports = st + }, { + undefined: void 0 + } + ] + }, {}, [1])(1) + }), + function(t) { + "use strict"; + var h, c, e, i, r, s, u = document, + d = function() { + return u.getElementById("app_wrap") || u.getElementsByTagName("body")[0] + }, + p = "getElementsByClassName", + l = function(t) { + return u.querySelectorAll(t) + }, + n = { + type: 0, + shade: !0, + shadeClose: !0, + fixed: !0, + anim: "scale" + }, + f = { + extend: function(t) { + var e, i = JSON.parse(JSON.stringify(n)); + for (e in t) i[e] = t[e]; + return i + }, + timer: {}, + end: {} + }; + f.touch = function(t, e) { + t.addEventListener("click", function(t) { + e.call(this, t) + }, !1) + }, h = 0, c = ["layui-m-layer"], (e = function(t) { + this.config = f.extend(t), this.view() + }).prototype.view = function() { + var t, e, i, r, s, n = this, + a = n.config, + o = u.createElement("div"); + n.id = o.id = c[0] + h, o.setAttribute("class", c[0] + " " + c[0] + (a.type || 0)), o.setAttribute("index", h), s = "object" == typeof a.title, t = a.title ? '

' + (s ? a.title[0] : a.title) + "

" : "", e = function() { + "string" == typeof a.btn && (a.btn = [a.btn]); + var t, e = (a.btn || []).length; + return 0 !== e && a.btn ? (t = '' + a.btn[0] + "", 2 === e && (t = '' + a.btn[1] + "" + t), '
' + t + "
") : "" + }(), a.fixed || (a.top = a.hasOwnProperty("top") ? a.top : 100, a.style = a.style || "", a.style += " top:" + (u.body.scrollTop + a.top) + "px"), 2 === a.type && (a.content = '

' + (a.content || "") + "

"), a.skin && (a.anim = "scale"), "msg" === a.skin && (a.shade = !1), o.innerHTML = (a.shade ? "
' : "") + '
" + t + '
' + a.content + "
" + e + "
", a.type && 2 !== a.type || 1 <= (i = u[p](c[0] + a.type)).length && layer.close(i[0].getAttribute("index")), d().appendChild(o), r = n.elem = l("#" + n.id)[0], a.success && a.success(r), n.index = h++, n.action(a, r) + }, e.prototype.action = function(t, e) { + var i, r, s, n, a, o = this; + if (t.time && (f.timer[o.index] = setTimeout(function() { + layer.close(o.index) + }, 1e3 * t.time)), i = function() { + 0 == this.getAttribute("type") ? (t.no && t.no(), layer.close(o.index)) : t.yes ? t.yes(o.index) : layer.close(o.index) + }, t.btn) + for (s = (r = e[p]("layui-m-layerbtn")[0].children).length, n = 0; n < s; n++) f.touch(r[n], i); + t.shade && t.shadeClose && (a = e[p]("layui-m-layershade")[0], f.touch(a, function() { + layer.close(o.index, t.end) + })), t.end && (f.end[o.index] = t.end) + }, t.layer = { + v: "2.0", + index: h, + open: function(t) { + return new e(t || {}).index + }, + close: function(t) { + var e = l("#" + c[0] + t)[0]; + e && (e.innerHTML = "", d().removeChild(e), clearTimeout(f.timer[t]), delete f.timer[t], "function" == typeof f.end[t] && f.end[t](), delete f.end[t]) + }, + closeAll: function() { + for (var t = u[p](c[0]), e = 0, i = t.length; e < i; e++) layer.close(0 | t[0].getAttribute("index")) + } + }, "function" == typeof define ? define(function() { + return layer + }) : (i = document.scripts, r = i[i.length - 1], (s = r.src).substring(0, s.lastIndexOf("/") + 1), r.getAttribute("merge") || document.head.appendChild(u.createElement("link"))) + }(window), window.Utils = function() {}, Utils.g = function() {}, Utils.g.isLandscape = !1, Utils.request = { + getParameter: function(t) { + var e = window.location.search, + i = new RegExp(t + "=([^&?]*)", "ig"); + return e.match(i) ? e.match(i)[0].substr(t.length + 1) : null + } + }, Utils.msg = function(t) { + var e = layer.open({ + content: t, + skin: "msg", + anim: "scale", + time: 2 + }); + Utils.g.isLandscape && layerLandscape(e) + }, Utils.loading = function(t) { + var e = layer.open({ + type: 2, + shade: "background-color: rgba(0,0,0,0)", + shadeClose: !1, + content: t || "加载中..." + }); + return Utils.g.isLandscape && layerLandscape(e), { + close: function() { + var t; + t = e, layer.close(t) + } + } + }, Utils.confirm = function(t, e, i, r, s) { + var n = layer.open({ + title: t, + content: e, + shadeClose: !1, + btn: [r || "确定", s || "取消"], + yes: function(t) { + i && i(!0), layer.close(t) + }, + no: function() { + i && i(!1) + } + }); + Utils.g.isLandscape && layerLandscape(n) + }, Utils.alert = function(t, e, i, r) { + var s = layer.open({ + title: e, + content: t, + shadeClose: !1, + btn: r || "确定", + yes: function(t) { + i && i(), layer.close(t) + } + }); + Utils.g.isLandscape && layerLandscape(s) + }, Object.prototype.inherit = function() { + for (var t in this) this[t] = this[t] + }, Serializer = { + TAG_INT: 1, + TAG_STRING: 2, + TAG_STRUCT: 3, + TAG_BLOB: 4, + TAG_BOOLEAN: 5, + TYPE: "application/octet-stream", + pointer: function() { + this.index = 0, this.top = 0, this.stack = [] + }, + pack: function(t) { + var e = new DataView(new ArrayBuffer(4)); + return e.setUint32(0, t, !0), e.buffer + }, + pack8: function(t) { + var e = new DataView(new ArrayBuffer(1)); + return e.setUint8(0, t, !0), e.buffer + }, + prefix: function(t) { + return new Blob([Serializer.pack(t.size || t.length || t.byteLength), t], { + type: Serializer.TYPE + }) + }, + serialize: function(t) { + var e = [], + r = 4; + for (i in t) + if (t.hasOwnProperty(i)) { + var s, n, a = Serializer.prefix(i); + switch (typeof t[i]) { + case "number": + s = Serializer.TAG_INT, n = Serializer.pack(t[i]); + break; + case "string": + s = Serializer.TAG_STRING, n = Serializer.prefix(t[i]); + break; + case "object": + t[i].type == Serializer.TYPE ? (s = Serializer.TAG_BLOB, n = t[i]) : (s = Serializer.TAG_STRUCT, n = Serializer.serialize(t[i])); + break; + case "boolean": + s = Serializer.TAG_BOOLEAN, n = Serializer.pack8(t[i]); + break; + default: + console.log(t[i]) + } + r += 1 + a.size + (n.size || n.byteLength || n.length), e.push(Serializer.pack8(s)), e.push(a), e.push(n) + } + return e.unshift(Serializer.pack(r)), new Blob(e) + }, + deserialize: function(t, e) { + var i = new FileReader; + i.onload = function(t) { + e(Serializer.deserealizeStream(new DataView(t.target.result), new Serializer.pointer)) + }, i.readAsArrayBuffer(t) + }, + deserealizeStream: function(t, e) { + e.push(); + for (var i = {}, r = t.getUint32(e.advance(4), !0); e.mark() < r;) { + var s, n = t.getUint8(e.advance(1)), + a = e.readString(t); + switch (n) { + case Serializer.TAG_INT: + s = t.getUint32(e.advance(4), !0); + break; + case Serializer.TAG_STRING: + s = e.readString(t); + break; + case Serializer.TAG_STRUCT: + s = Serializer.deserealizeStream(t, e); + break; + case Serializer.TAG_BLOB: + var o = t.getUint32(e.advance(4), !0); + s = t.buffer.slice(e.advance(o), e.advance(0)); + break; + case Serializer.TAG_BOOLEAN: + s = !!t.getUint8(e.advance(1)) + } + i[a] = s + } + if (e.mark() > r) throw "Size of serialized data exceeded"; + return e.pop(), i + }, + serializePNG: function(t, u, d) { + for (var p = document.createElement("canvas"), l = p.getContext("2d"), f = u.getContext("2d").getImageData(0, 0, u.width, u.height), e = 0, i = 0; i < u.height; ++i) + for (var r = 0; r < u.width; ++r) f.data[4 * (r + i * u.width) + 3] || ++e; + for (var s = 3 * e + (u.width * u.height - e), m = 1; s * m * m < t.size; ++m); + var n = s * m * m - t.size, + y = Math.ceil(n / (u.width * m)); + p.setAttribute("width", u.width * m), p.setAttribute("height", u.height * m + y); + var a = new FileReader; + return a.onload = function(t) { + for (var e = new Uint8Array(t.target.result), i = 0, r = 0, s = l.createImageData(p.width, p.height + y), n = 0; n < p.height; ++n) + for (var a = 0; a < p.width; ++a) { + var o = n / m | 0, + h = a / m | 0; + if (o > u.height || !f.data[4 * (h + o * u.width) + 3]) s.data[r++] = e[i++], s.data[r++] = e[i++], s.data[r++] = e[i++], s.data[r++] = 0; + else { + var c = e[i++]; + s.data[r++] = f.data[4 * (h + o * u.width) + 0] | 7 & c, s.data[r++] = f.data[4 * (h + o * u.width) + 1] | c >> 3 & 7, s.data[r++] = f.data[4 * (h + o * u.width) + 2] | c >> 6 & 7, s.data[r++] = f.data[4 * (h + o * u.width) + 3] + } + } + l.putImageData(s, 0, 0), d(p.toDataURL("image/png")) + }, a.readAsArrayBuffer(t), p + }, + deserializePNG: function(t, h) { + var e = new FileReader; + e.onload = function(t) { + var e = document.createElement("img"); + e.setAttribute("src", t.target.result); + var i = document.createElement("canvas"); + i.setAttribute("height", e.height), i.setAttribute("width", e.width); + var r = i.getContext("2d"); + r.drawImage(e, 0, 0); + for (var s = r.getImageData(0, 0, i.width, i.height), n = (t = [], 0); n < i.height; ++n) + for (var a = 0; a < i.width; ++a) + if (s.data[4 * (a + n * i.width) + 3]) { + var o = 0; + o |= 7 & s.data[4 * (a + n * i.width) + 0], o |= (7 & s.data[4 * (a + n * i.width) + 1]) << 3, o |= (7 & s.data[4 * (a + n * i.width) + 2]) << 6, t.push(o) + } else t.push(s.data[4 * (a + n * i.width) + 0]), t.push(s.data[4 * (a + n * i.width) + 1]), t.push(s.data[4 * (a + n * i.width) + 2]); + newBlob = new Blob(t.map(function(t) { + var e = new Uint8Array(1); + return e[0] = t, e + }), { + type: Serializer.TYPE + }), Serializer.deserialize(newBlob, h) + }, e.readAsDataURL(t) + } + }, Serializer.pointer.prototype.advance = function(t) { + var e = this.index; + return this.index += t, e + }, Serializer.pointer.prototype.mark = function() { + return this.index - this.top + }, Serializer.pointer.prototype.push = function() { + this.stack.push(this.top), this.top = this.index + }, Serializer.pointer.prototype.pop = function() { + this.top = this.stack.pop() + }, Serializer.pointer.prototype.readString = function(t) { + for (var e = t.getUint32(this.advance(4), !0), i = [], r = 0; r < e; ++r) i.push(String.fromCharCode(t.getUint8(this.advance(1)))); + return i.join("") + }, ARMCore.prototype.resetCPU = function(t) { + for (var e = 0; e < this.PC; ++e) this.gprs[e] = 0; + this.gprs[this.PC] = t + this.WORD_SIZE_ARM, this.loadInstruction = this.loadInstructionArm, this.execMode = this.MODE_ARM, this.instructionWidth = this.WORD_SIZE_ARM, this.mode = this.MODE_SYSTEM, this.cpsrI = !1, this.cpsrF = !1, this.cpsrV = !1, this.cpsrC = !1, this.cpsrZ = !1, this.cpsrN = !1, this.bankedRegisters = [new Int32Array(7), new Int32Array(7), new Int32Array(2), new Int32Array(2), new Int32Array(2), new Int32Array(2)], this.spsr = 0, this.bankedSPSRs = new Int32Array(6), this.cycles = 0, this.shifterOperand = 0, this.shifterCarryOut = 0, this.page = null, this.pageId = 0, this.pageRegion = -1, this.instruction = null, this.irq.clear(); + var i = this.gprs, + r = this.mmu; + this.step = function() { + var t = this.instruction || (this.instruction = this.loadInstruction(i[this.PC] - this.instructionWidth)); + if (i[this.PC] += this.instructionWidth, this.conditionPassed = !0, t(), t.writesPC) + if (this.conditionPassed) { + var e = i[this.PC] &= 4294967294; + this.execMode == this.MODE_ARM ? (r.wait32(e), r.waitPrefetch32(e)) : (r.wait(e), r.waitPrefetch(e)), i[this.PC] += this.instructionWidth, t.fixedJump ? null != this.instruction && ((null == t.next || t.next.page.invalid) && (t.next = this.loadInstruction(i[this.PC] - this.instructionWidth)), this.instruction = t.next) : this.instruction = null + } else this.instruction = null; + else null != this.instruction && ((null == t.next || t.next.page.invalid) && (t.next = this.loadInstruction(i[this.PC] - this.instructionWidth)), this.instruction = t.next); + this.irq.updateTimers() + } + }, ARMCore.prototype.freeze = function() { + return { + gprs: [this.gprs[0], this.gprs[1], this.gprs[2], this.gprs[3], this.gprs[4], this.gprs[5], this.gprs[6], this.gprs[7], this.gprs[8], this.gprs[9], this.gprs[10], this.gprs[11], this.gprs[12], this.gprs[13], this.gprs[14], this.gprs[15]], + mode: this.mode, + cpsrI: this.cpsrI, + cpsrF: this.cpsrF, + cpsrV: this.cpsrV, + cpsrC: this.cpsrC, + cpsrZ: this.cpsrZ, + cpsrN: this.cpsrN, + bankedRegisters: [ + [this.bankedRegisters[0][0], this.bankedRegisters[0][1], this.bankedRegisters[0][2], this.bankedRegisters[0][3], this.bankedRegisters[0][4], this.bankedRegisters[0][5], this.bankedRegisters[0][6]], + [this.bankedRegisters[1][0], this.bankedRegisters[1][1], this.bankedRegisters[1][2], this.bankedRegisters[1][3], this.bankedRegisters[1][4], this.bankedRegisters[1][5], this.bankedRegisters[1][6]], + [this.bankedRegisters[2][0], this.bankedRegisters[2][1]], + [this.bankedRegisters[3][0], this.bankedRegisters[3][1]], + [this.bankedRegisters[4][0], this.bankedRegisters[4][1]], + [this.bankedRegisters[5][0], this.bankedRegisters[5][1]] + ], + spsr: this.spsr, + bankedSPSRs: [this.bankedSPSRs[0], this.bankedSPSRs[1], this.bankedSPSRs[2], this.bankedSPSRs[3], this.bankedSPSRs[4], this.bankedSPSRs[5]], + cycles: this.cycles + } + }, ARMCore.prototype.defrost = function(t) { + this.instruction = null, this.page = null, this.pageId = 0, this.pageRegion = -1, this.gprs[0] = t.gprs[0], this.gprs[1] = t.gprs[1], this.gprs[2] = t.gprs[2], this.gprs[3] = t.gprs[3], this.gprs[4] = t.gprs[4], this.gprs[5] = t.gprs[5], this.gprs[6] = t.gprs[6], this.gprs[7] = t.gprs[7], this.gprs[8] = t.gprs[8], this.gprs[9] = t.gprs[9], this.gprs[10] = t.gprs[10], this.gprs[11] = t.gprs[11], this.gprs[12] = t.gprs[12], this.gprs[13] = t.gprs[13], this.gprs[14] = t.gprs[14], this.gprs[15] = t.gprs[15], this.mode = t.mode, this.cpsrI = t.cpsrI, this.cpsrF = t.cpsrF, this.cpsrV = t.cpsrV, this.cpsrC = t.cpsrC, this.cpsrZ = t.cpsrZ, this.cpsrN = t.cpsrN, this.bankedRegisters[0][0] = t.bankedRegisters[0][0], this.bankedRegisters[0][1] = t.bankedRegisters[0][1], this.bankedRegisters[0][2] = t.bankedRegisters[0][2], this.bankedRegisters[0][3] = t.bankedRegisters[0][3], this.bankedRegisters[0][4] = t.bankedRegisters[0][4], this.bankedRegisters[0][5] = t.bankedRegisters[0][5], this.bankedRegisters[0][6] = t.bankedRegisters[0][6], this.bankedRegisters[1][0] = t.bankedRegisters[1][0], this.bankedRegisters[1][1] = t.bankedRegisters[1][1], this.bankedRegisters[1][2] = t.bankedRegisters[1][2], this.bankedRegisters[1][3] = t.bankedRegisters[1][3], this.bankedRegisters[1][4] = t.bankedRegisters[1][4], this.bankedRegisters[1][5] = t.bankedRegisters[1][5], this.bankedRegisters[1][6] = t.bankedRegisters[1][6], this.bankedRegisters[2][0] = t.bankedRegisters[2][0], this.bankedRegisters[2][1] = t.bankedRegisters[2][1], this.bankedRegisters[3][0] = t.bankedRegisters[3][0], this.bankedRegisters[3][1] = t.bankedRegisters[3][1], this.bankedRegisters[4][0] = t.bankedRegisters[4][0], this.bankedRegisters[4][1] = t.bankedRegisters[4][1], this.bankedRegisters[5][0] = t.bankedRegisters[5][0], this.bankedRegisters[5][1] = t.bankedRegisters[5][1], this.spsr = t.spsr, this.bankedSPSRs[0] = t.bankedSPSRs[0], this.bankedSPSRs[1] = t.bankedSPSRs[1], this.bankedSPSRs[2] = t.bankedSPSRs[2], this.bankedSPSRs[3] = t.bankedSPSRs[3], this.bankedSPSRs[4] = t.bankedSPSRs[4], this.bankedSPSRs[5] = t.bankedSPSRs[5], this.cycles = t.cycles + }, ARMCore.prototype.fetchPage = function(t) { + var e = t >> this.mmu.BASE_OFFSET, + i = this.mmu.addressToPage(e, t & this.mmu.OFFSET_MASK); + if (e == this.pageRegion) { + if (i == this.pageId && !this.page.invalid) return; + this.pageId = i + } else this.pageMask = this.mmu.memory[e].PAGE_MASK, this.pageRegion = e, this.pageId = i; + this.page = this.mmu.accessPage(e, i) + }, ARMCore.prototype.loadInstructionArm = function(t) { + var e = null; + this.fetchPage(t); + var i = (t & this.pageMask) >> 2; + if (e = this.page.arm[i]) return e; + var r = this.mmu.load32(t) >>> 0; + return (e = this.compileArm(r)).next = null, e.page = this.page, e.address = t, e.opcode = r, this.page.arm[i] = e + }, ARMCore.prototype.loadInstructionThumb = function(t) { + var e = null; + this.fetchPage(t); + var i = (t & this.pageMask) >> 1; + if (e = this.page.thumb[i]) return e; + var r = this.mmu.load16(t); + return (e = this.compileThumb(r)).next = null, e.page = this.page, e.address = t, e.opcode = r, this.page.thumb[i] = e + }, ARMCore.prototype.selectBank = function(t) { + switch (t) { + case this.MODE_USER: + case this.MODE_SYSTEM: + return this.BANK_NONE; + case this.MODE_FIQ: + return this.BANK_FIQ; + case this.MODE_IRQ: + return this.BANK_IRQ; + case this.MODE_SUPERVISOR: + return this.BANK_SUPERVISOR; + case this.MODE_ABORT: + return this.BANK_ABORT; + case this.MODE_UNDEFINED: + return this.BANK_UNDEFINED; + default: + throw "Invalid user mode passed to selectBank" + } + }, ARMCore.prototype.switchExecMode = function(t) { + this.execMode != t && ((this.execMode = t) == this.MODE_ARM ? (this.instructionWidth = this.WORD_SIZE_ARM, this.loadInstruction = this.loadInstructionArm) : (this.instructionWidth = this.WORD_SIZE_THUMB, this.loadInstruction = this.loadInstructionThumb)) + }, ARMCore.prototype.switchMode = function(t) { + if (t != this.mode) { + if (t != this.MODE_USER || t != this.MODE_SYSTEM) { + var e = this.selectBank(t), + i = this.selectBank(this.mode); + if (e != i) { + if (t == this.MODE_FIQ || this.mode == this.MODE_FIQ) { + var r = (i == this.BANK_FIQ) + 0, + s = (e == this.BANK_FIQ) + 0; + this.bankedRegisters[r][2] = this.gprs[8], this.bankedRegisters[r][3] = this.gprs[9], this.bankedRegisters[r][4] = this.gprs[10], this.bankedRegisters[r][5] = this.gprs[11], this.bankedRegisters[r][6] = this.gprs[12], this.gprs[8] = this.bankedRegisters[s][2], this.gprs[9] = this.bankedRegisters[s][3], this.gprs[10] = this.bankedRegisters[s][4], this.gprs[11] = this.bankedRegisters[s][5], this.gprs[12] = this.bankedRegisters[s][6] + } + this.bankedRegisters[i][0] = this.gprs[this.SP], this.bankedRegisters[i][1] = this.gprs[this.LR], this.gprs[this.SP] = this.bankedRegisters[e][0], this.gprs[this.LR] = this.bankedRegisters[e][1], this.bankedSPSRs[i] = this.spsr, this.spsr = this.bankedSPSRs[e] + } + } + this.mode = t + } + }, ARMCore.prototype.packCPSR = function() { + return this.mode | !!this.execMode << 5 | !!this.cpsrF << 6 | !!this.cpsrI << 7 | !!this.cpsrN << 31 | !!this.cpsrZ << 30 | !!this.cpsrC << 29 | !!this.cpsrV << 28 + }, ARMCore.prototype.unpackCPSR = function(t) { + this.switchMode(31 & t), this.switchExecMode(!!(32 & t)), this.cpsrF = 64 & t, this.cpsrI = 128 & t, this.cpsrN = 2147483648 & t, this.cpsrZ = 1073741824 & t, this.cpsrC = 536870912 & t, this.cpsrV = 268435456 & t, this.irq.testIRQ() + }, ARMCore.prototype.hasSPSR = function() { + return this.mode != this.MODE_SYSTEM && this.mode != this.MODE_USER + }, ARMCore.prototype.raiseIRQ = function() { + if (!this.cpsrI) { + var t = this.packCPSR(), + e = this.instructionWidth; + this.switchMode(this.MODE_IRQ), this.spsr = t, this.gprs[this.LR] = this.gprs[this.PC] - e + 4, this.gprs[this.PC] = this.BASE_IRQ + this.WORD_SIZE_ARM, this.instruction = null, this.switchExecMode(this.MODE_ARM), this.cpsrI = !0 + } + }, ARMCore.prototype.raiseTrap = function() { + var t = this.packCPSR(), + e = this.instructionWidth; + this.switchMode(this.MODE_SUPERVISOR), this.spsr = t, this.gprs[this.LR] = this.gprs[this.PC] - e, this.gprs[this.PC] = this.BASE_SWI + this.WORD_SIZE_ARM, this.instruction = null, this.switchExecMode(this.MODE_ARM), this.cpsrI = !0 + }, ARMCore.prototype.badOp = function(t) { + var e = function() { + throw "Illegal instruction: 0x" + t.toString(16) + }; + return e.writesPC = !0, e.fixedJump = !1, e + }, ARMCore.prototype.generateConds = function() { + var t = this; + this.conds = [ + function() { + return t.conditionPassed = t.cpsrZ + }, + function() { + return t.conditionPassed = !t.cpsrZ + }, + function() { + return t.conditionPassed = t.cpsrC + }, + function() { + return t.conditionPassed = !t.cpsrC + }, + function() { + return t.conditionPassed = t.cpsrN + }, + function() { + return t.conditionPassed = !t.cpsrN + }, + function() { + return t.conditionPassed = t.cpsrV + }, + function() { + return t.conditionPassed = !t.cpsrV + }, + function() { + return t.conditionPassed = t.cpsrC && !t.cpsrZ + }, + function() { + return t.conditionPassed = !t.cpsrC || t.cpsrZ + }, + function() { + return t.conditionPassed = !t.cpsrN == !t.cpsrV + }, + function() { + return t.conditionPassed = !t.cpsrN != !t.cpsrV + }, + function() { + return t.conditionPassed = !t.cpsrZ && !t.cpsrN == !t.cpsrV + }, + function() { + return t.conditionPassed = t.cpsrZ || !t.cpsrN != !t.cpsrV + }, + null, null + ] + }, ARMCore.prototype.barrelShiftImmediate = function(t, e, i) { + var r = this, + s = this.gprs, + n = this.badOp; + switch (t) { + case 0: + n = e ? function() { + r.shifterOperand = s[i] << e, r.shifterCarryOut = s[i] & 1 << 32 - e + } : function() { + r.shifterOperand = s[i], r.shifterCarryOut = r.cpsrC + }; + break; + case 32: + n = e ? function() { + r.shifterOperand = s[i] >>> e, r.shifterCarryOut = s[i] & 1 << e - 1 + } : function() { + r.shifterOperand = 0, r.shifterCarryOut = 2147483648 & s[i] + }; + break; + case 64: + n = e ? function() { + r.shifterOperand = s[i] >> e, r.shifterCarryOut = s[i] & 1 << e - 1 + } : function() { + r.shifterCarryOut = 2147483648 & s[i], r.shifterCarryOut ? r.shifterOperand = 4294967295 : r.shifterOperand = 0 + }; + break; + case 96: + n = e ? function() { + r.shifterOperand = s[i] >>> e | s[i] << 32 - e, r.shifterCarryOut = s[i] & 1 << e - 1 + } : function() { + r.shifterOperand = !!r.cpsrC << 31 | s[i] >>> 1, r.shifterCarryOut = 1 & s[i] + } + } + return n + }, ARMCore.prototype.compileArm = function(t) { + var e = this.badOp(t), + i = 234881024 & t, + r = (this.gprs, this.conds[(4026531840 & t) >>> 28]); + if (19922704 == (268435440 & t)) { + var s = 15 & t; + (e = this.armCompiler.constructBX(s, r)).writesPC = !0, e.fixedJump = !1 + } else if (201326592 & t || 33554432 != i && 144 == (144 & t)) + if (16777360 == (263196656 & t)) { + s = 15 & t, g = t >> 12 & 15, b = t >> 16 & 15; + (e = 4194304 & t ? this.armCompiler.constructSWPB(g, b, s, r) : this.armCompiler.constructSWP(g, b, s, r)).writesPC = g == this.PC + } else switch (i) { + case 0: + if (144 == (16777456 & t)) { + g = (983040 & t) >> 16, b = (61440 & t) >> 12, M = (3840 & t) >> 8, s = 15 & t; + switch (15728640 & t) { + case 0: + e = this.armCompiler.constructMUL(g, M, s, r); + break; + case 1048576: + e = this.armCompiler.constructMULS(g, M, s, r); + break; + case 2097152: + e = this.armCompiler.constructMLA(g, b, M, s, r); + break; + case 3145728: + e = this.armCompiler.constructMLAS(g, b, M, s, r); + break; + case 8388608: + e = this.armCompiler.constructUMULL(g, b, M, s, r); + break; + case 9437184: + e = this.armCompiler.constructUMULLS(g, b, M, s, r); + break; + case 10485760: + e = this.armCompiler.constructUMLAL(g, b, M, s, r); + break; + case 11534336: + e = this.armCompiler.constructUMLALS(g, b, M, s, r); + break; + case 12582912: + e = this.armCompiler.constructSMULL(g, b, M, s, r); + break; + case 13631488: + e = this.armCompiler.constructSMULLS(g, b, M, s, r); + break; + case 14680064: + e = this.armCompiler.constructSMLAL(g, b, M, s, r); + break; + case 15728640: + e = this.armCompiler.constructSMLALS(g, b, M, s, r) + } + e.writesPC = g == this.PC + } else { + var n = 1048576 & t, + a = (g = (61440 & t) >> 12, s = 15 & t), + o = 32 & t, + h = (A = 64 & t, 2097152 & t); + if (i = 4194304 & t) { + C = a | (3840 & t) >> 4; + u = this.armCompiler.constructAddressingMode23Immediate(t, C, r) + } else u = this.armCompiler.constructAddressingMode23Register(t, s, r); + u.writesPC = !!h && b == this.PC, 144 == (144 & t) && (n ? o ? e = A ? this.armCompiler.constructLDRSH(g, u, r) : this.armCompiler.constructLDRH(g, u, r) : A && (e = this.armCompiler.constructLDRSB(g, u, r)) : !A && o && (e = this.armCompiler.constructSTRH(g, u, r))), e.writesPC = g == this.PC || u.writesPC + } + break; + case 67108864: + case 100663296: + g = (61440 & t) >> 12, n = 1048576 & t; + var c = 4194304 & t, + u = (i = 33554432 & t, function() { + throw "Unimplemented memory access: 0x" + t.toString(16) + }); + if (16777216 & ~t && (t &= 4292870143), i) { + s = 15 & t; + var d = (3968 & t) >> 7; + if ((S = 96 & t) || d) { + R = this.barrelShiftImmediate(S, d, s); + u = this.armCompiler.constructAddressingMode2RegisterShifted(t, R, r) + } else u = this.armCompiler.constructAddressingMode23Register(t, s, r) + } else { + var p = 4095 & t; + u = this.armCompiler.constructAddressingMode23Immediate(t, p, r) + }(e = n ? c ? this.armCompiler.constructLDRB(g, u, r) : this.armCompiler.constructLDR(g, u, r) : c ? this.armCompiler.constructSTRB(g, u, r) : this.armCompiler.constructSTR(g, u, r)).writesPC = g == this.PC || u.writesPC; + break; + case 134217728: + n = 1048576 & t, h = 2097152 & t; + var l = 4194304 & t, + f = 16777216 & t, + m = (M = 65535 & t, b = (983040 & t) >> 16, C = 0, p = 0, !1); + if (8388608 & t) { + f && (C = 4); + var y = 1; + for (i = 0; i < 16; y <<= 1, ++i) M & y && (h && i == b && !p && (M &= ~y, C += 4, m = !0), p += 4) + } else { + f || (C = 4); + for (y = 1, i = 0; i < 16; y <<= 1, ++i) M & y && (h && i == b && !p && (M &= ~y, C += 4, m = !0), C -= 4, p -= 4) + } + u = h ? this.armCompiler.constructAddressingMode4Writeback(C, p, b, m) : this.armCompiler.constructAddressingMode4(C, b), n ? (e = l ? this.armCompiler.constructLDMS(M, u, r) : this.armCompiler.constructLDM(M, u, r)).writesPC = !!(32768 & M) : (e = l ? this.armCompiler.constructSTMS(M, u, r) : this.armCompiler.constructSTM(M, u, r)).writesPC = !1; + break; + case 167772160: + 8388608 & (C = 16777215 & t) && (C |= 4278190080), C <<= 2, (e = 16777216 & t ? this.armCompiler.constructBL(C, r) : this.armCompiler.constructB(C, r)).writesPC = !0, e.fixedJump = !0; + break; + case 201326592: + break; + case 234881024: + if (251658240 == (251658240 & t)) { + C = 16777215 & t; + (e = this.armCompiler.constructSWI(C, r)).writesPC = !1 + } + break; + default: + throw "Bad opcode: 0x" + t.toString(16) + } else { + var v = 31457280 & t, + A = 1048576 & t; + if (16777216 != (25165824 & v) || A) { + var b = (983040 & t) >> 16, + g = (61440 & t) >> 12, + S = 96 & t, + s = 15 & t, + R = function() { + throw "BUG: invalid barrel shifter" + }; + if (33554432 & t) { + var C = 255 & t, + w = (3840 & t) >> 7; + R = w ? this.armCompiler.constructAddressingMode1ImmediateRotate(C, w) : this.armCompiler.constructAddressingMode1Immediate(C) + } else if (16 & t) { + var M = (3840 & t) >> 8; + switch (!0, S) { + case 0: + R = this.armCompiler.constructAddressingMode1LSL(M, s); + break; + case 32: + R = this.armCompiler.constructAddressingMode1LSR(M, s); + break; + case 64: + R = this.armCompiler.constructAddressingMode1ASR(M, s); + break; + case 96: + R = this.armCompiler.constructAddressingMode1ROR(M, s) + } + } else { + var C = (3968 & t) >> 7; + R = this.barrelShiftImmediate(S, C, s) + } + switch (v) { + case 0: + e = A ? this.armCompiler.constructANDS(g, b, R, r) : this.armCompiler.constructAND(g, b, R, r); + break; + case 2097152: + e = A ? this.armCompiler.constructEORS(g, b, R, r) : this.armCompiler.constructEOR(g, b, R, r); + break; + case 4194304: + e = A ? this.armCompiler.constructSUBS(g, b, R, r) : this.armCompiler.constructSUB(g, b, R, r); + break; + case 6291456: + e = A ? this.armCompiler.constructRSBS(g, b, R, r) : this.armCompiler.constructRSB(g, b, R, r); + break; + case 8388608: + e = A ? this.armCompiler.constructADDS(g, b, R, r) : this.armCompiler.constructADD(g, b, R, r); + break; + case 10485760: + e = A ? this.armCompiler.constructADCS(g, b, R, r) : this.armCompiler.constructADC(g, b, R, r); + break; + case 12582912: + e = A ? this.armCompiler.constructSBCS(g, b, R, r) : this.armCompiler.constructSBC(g, b, R, r); + break; + case 14680064: + e = A ? this.armCompiler.constructRSCS(g, b, R, r) : this.armCompiler.constructRSC(g, b, R, r); + break; + case 16777216: + e = this.armCompiler.constructTST(g, b, R, r); + break; + case 18874368: + e = this.armCompiler.constructTEQ(g, b, R, r); + break; + case 20971520: + e = this.armCompiler.constructCMP(g, b, R, r); + break; + case 23068672: + e = this.armCompiler.constructCMN(g, b, R, r); + break; + case 25165824: + e = A ? this.armCompiler.constructORRS(g, b, R, r) : this.armCompiler.constructORR(g, b, R, r); + break; + case 27262976: + e = A ? this.armCompiler.constructMOVS(g, b, R, r) : this.armCompiler.constructMOV(g, b, R, r); + break; + case 29360128: + e = A ? this.armCompiler.constructBICS(g, b, R, r) : this.armCompiler.constructBIC(g, b, R, r); + break; + case 31457280: + e = A ? this.armCompiler.constructMVNS(g, b, R, r) : this.armCompiler.constructMVN(g, b, R, r) + } + e.writesPC = g == this.PC + } else { + var _ = 4194304 & t; + if (2158592 == (11595776 & t)) { + var s = 15 & t, + I = (3840 & t) >> 7; + C = (C = 255 & t) >>> I | C << 32 - I, (e = this.armCompiler.constructMSR(s, _, t, C, r)).writesPC = !1 + } else if (983040 == (12517376 & t)) { + var g = (61440 & t) >> 12; + (e = this.armCompiler.constructMRS(g, _, r)).writesPC = g == this.PC + } + } + } + return e.execMode = this.MODE_ARM, e.fixedJump = e.fixedJump || !1, e + }, ARMCore.prototype.compileThumb = function(t) { + var e = this.badOp(65535 & t); + this.gprs; + if (16384 == (64512 & t)) { + var i = (56 & t) >> 3, + r = 7 & t; + switch (960 & t) { + case 0: + e = this.thumbCompiler.constructAND(r, i); + break; + case 64: + e = this.thumbCompiler.constructEOR(r, i); + break; + case 128: + e = this.thumbCompiler.constructLSL2(r, i); + break; + case 192: + e = this.thumbCompiler.constructLSR2(r, i); + break; + case 256: + e = this.thumbCompiler.constructASR2(r, i); + break; + case 320: + e = this.thumbCompiler.constructADC(r, i); + break; + case 384: + e = this.thumbCompiler.constructSBC(r, i); + break; + case 448: + e = this.thumbCompiler.constructROR(r, i); + break; + case 512: + e = this.thumbCompiler.constructTST(r, i); + break; + case 576: + e = this.thumbCompiler.constructNEG(r, i); + break; + case 640: + e = this.thumbCompiler.constructCMP2(r, i); + break; + case 704: + e = this.thumbCompiler.constructCMN(r, i); + break; + case 768: + e = this.thumbCompiler.constructORR(r, i); + break; + case 832: + e = this.thumbCompiler.constructMUL(r, i); + break; + case 896: + e = this.thumbCompiler.constructBIC(r, i); + break; + case 960: + e = this.thumbCompiler.constructMVN(r, i) + } + e.writesPC = !1 + } else if (17408 == (64512 & t)) { + i = (120 & t) >> 3, r = (s = 7 & t) | (128 & t) >> 4; + switch (768 & t) { + case 0: + (e = this.thumbCompiler.constructADD4(r, i)).writesPC = r == this.PC; + break; + case 256: + (e = this.thumbCompiler.constructCMP3(r, i)).writesPC = !1; + break; + case 512: + (e = this.thumbCompiler.constructMOV3(r, i)).writesPC = r == this.PC; + break; + case 768: + (e = this.thumbCompiler.constructBX(r, i)).writesPC = !0, e.fixedJump = !1 + } + } else if (6144 == (63488 & t)) { + i = (448 & t) >> 6; + var s = (56 & t) >> 3; + r = 7 & t; + switch (1536 & t) { + case 0: + e = this.thumbCompiler.constructADD3(r, s, i); + break; + case 512: + e = this.thumbCompiler.constructSUB3(r, s, i); + break; + case 1024: + e = (n = (448 & t) >> 6) ? this.thumbCompiler.constructADD1(r, s, n) : this.thumbCompiler.constructMOV2(r, s, i); + break; + case 1536: + var n = (448 & t) >> 6; + e = this.thumbCompiler.constructSUB1(r, s, n) + } + e.writesPC = !1 + } else if (57344 & t) + if (8192 == (57344 & t)) { + n = 255 & t, s = (1792 & t) >> 8; + switch (6144 & t) { + case 0: + e = this.thumbCompiler.constructMOV1(s, n); + break; + case 2048: + e = this.thumbCompiler.constructCMP1(s, n); + break; + case 4096: + e = this.thumbCompiler.constructADD2(s, n); + break; + case 6144: + e = this.thumbCompiler.constructSUB2(s, n) + } + e.writesPC = !1 + } else if (18432 == (63488 & t)) { + r = (1792 & t) >> 8, n = (255 & t) << 2; + (e = this.thumbCompiler.constructLDR3(r, n)).writesPC = !1 + } else if (20480 == (61440 & t)) { + r = 7 & t, s = (56 & t) >> 3, i = (448 & t) >> 6; + switch (3584 & t) { + case 0: + e = this.thumbCompiler.constructSTR2(r, s, i); + break; + case 512: + e = this.thumbCompiler.constructSTRH2(r, s, i); + break; + case 1024: + e = this.thumbCompiler.constructSTRB2(r, s, i); + break; + case 1536: + e = this.thumbCompiler.constructLDRSB(r, s, i); + break; + case 2048: + e = this.thumbCompiler.constructLDR2(r, s, i); + break; + case 2560: + e = this.thumbCompiler.constructLDRH2(r, s, i); + break; + case 3072: + e = this.thumbCompiler.constructLDRB2(r, s, i); + break; + case 3584: + e = this.thumbCompiler.constructLDRSH(r, s, i) + } + e.writesPC = !1 + } else if (24576 == (57344 & t)) { + r = 7 & t, s = (56 & t) >> 3, n = (1984 & t) >> 4; + (h = 4096 & t) && (n >>= 2), (e = 2048 & t ? h ? this.thumbCompiler.constructLDRB1(r, s, n) : this.thumbCompiler.constructLDR1(r, s, n) : h ? this.thumbCompiler.constructSTRB1(r, s, n) : this.thumbCompiler.constructSTR1(r, s, n)).writesPC = !1 + } else if (46080 == (62976 & t)) { + var a = !!(256 & t), + o = 255 & t; + 2048 & t ? ((e = this.thumbCompiler.constructPOP(o, a)).writesPC = a, e.fixedJump = !1) : (e = this.thumbCompiler.constructPUSH(o, a)).writesPC = !1 + } else { + if (!(32768 & t)) throw "Bad opcode: 0x" + t.toString(16); + switch (28672 & t) { + case 0: + r = 7 & t, s = (56 & t) >> 3, n = (1984 & t) >> 5; + (e = 2048 & t ? this.thumbCompiler.constructLDRH1(r, s, n) : this.thumbCompiler.constructSTRH1(r, s, n)).writesPC = !1; + break; + case 4096: + r = (1792 & t) >> 8, n = (255 & t) << 2; + (e = 2048 & t ? this.thumbCompiler.constructLDR4(r, n) : this.thumbCompiler.constructSTR3(r, n)).writesPC = !1; + break; + case 8192: + r = (1792 & t) >> 8, n = (255 & t) << 2; + (e = 2048 & t ? this.thumbCompiler.constructADD6(r, n) : this.thumbCompiler.constructADD5(r, n)).writesPC = !1; + break; + case 12288: + if (!(3840 & t)) { + var h; + n = (127 & t) << 2; + (h = 128 & t) && (n = -n), (e = this.thumbCompiler.constructADD7(n)).writesPC = !1 + } + break; + case 16384: + s = (1792 & t) >> 8, o = 255 & t; + (e = 2048 & t ? this.thumbCompiler.constructLDMIA(s, o) : this.thumbCompiler.constructSTMIA(s, o)).writesPC = !1; + break; + case 20480: + var c = (3840 & t) >> 8; + n = 255 & t; + if (15 == c)(e = this.thumbCompiler.constructSWI(n)).writesPC = !1; + else { + 128 & t && (n |= 4294967040), n <<= 1; + var u = this.conds[c]; + (e = this.thumbCompiler.constructB1(n, u)).writesPC = !0, e.fixedJump = !0 + } + break; + case 24576: + case 28672: + n = 2047 & t; + switch (6144 & t) { + case 0: + 1024 & n && (n |= 4294965248), n <<= 1, (e = this.thumbCompiler.constructB2(n)).writesPC = !0, e.fixedJump = !0; + break; + case 2048: + break; + case 4096: + 1024 & n && (n |= 4294966272), n <<= 12, (e = this.thumbCompiler.constructBL1(n)).writesPC = !1; + break; + case 6144: + (e = this.thumbCompiler.constructBL2(n)).writesPC = !0, e.fixedJump = !1 + } + break; + default: + this.WARN("Undefined instruction: 0x" + t.toString(16)) + } + } else { + var r = 7 & t, + i = (56 & t) >> 3, + n = (1984 & t) >> 6; + switch (6144 & t) { + case 0: + e = this.thumbCompiler.constructLSL1(r, i, n); + break; + case 2048: + e = this.thumbCompiler.constructLSR1(r, i, n); + break; + case 4096: + e = this.thumbCompiler.constructASR1(r, i, n) + } + e.writesPC = !1 + } + return e.execMode = this.MODE_THUMB, e.fixedJump = e.fixedJump || !1, e + }; +var ARMCoreArm = function(n) { + this.cpu = n, this.addressingMode23Immediate = [ + function(e, i, r) { + var s = n.gprs, + t = function() { + var t = s[e]; + return r && !r() || (s[e] -= i), t + }; + return t.writesPC = e == n.PC, t + }, + null, null, null, + function(e, i, r) { + var s = n.gprs, + t = function() { + var t = s[e]; + return r && !r() || (s[e] += i), t + }; + return t.writesPC = e == n.PC, t + }, + null, null, null, + function(t, e, i) { + var r = n.gprs, + s = function() { + return addr = r[t] - e + }; + return s.writesPC = !1, s + }, + function(e, i, r) { + var s = n.gprs, + t = function() { + var t = s[e] - i; + return r && !r() || (s[e] = t), t + }; + return t.writesPC = e == n.PC, t + }, + null, null, + function(t, e, i) { + var r = n.gprs, + s = function() { + return addr = r[t] + e + }; + return s.writesPC = !1, s + }, + function(e, i, r) { + var s = n.gprs, + t = function() { + var t = s[e] + i; + return r && !r() || (s[e] = t), t + }; + return t.writesPC = e == n.PC, t + }, + null, null + ], this.addressingMode23Register = [ + function(e, i, r) { + var s = n.gprs, + t = function() { + var t = s[e]; + return r && !r() || (s[e] -= s[i]), t + }; + return t.writesPC = e == n.PC, t + }, + null, null, null, + function(e, i, r) { + var s = n.gprs, + t = function() { + var t = s[e]; + return r && !r() || (s[e] += s[i]), t + }; + return t.writesPC = e == n.PC, t + }, + null, null, null, + function(t, e, i) { + var r = n.gprs, + s = function() { + return r[t] - r[e] + }; + return s.writesPC = !1, s + }, + function(e, i, r) { + var s = n.gprs, + t = function() { + var t = s[e] - s[i]; + return r && !r() || (s[e] = t), t + }; + return t.writesPC = e == n.PC, t + }, + null, null, + function(t, e, i) { + var r = n.gprs, + s = function() { + return r[t] + r[e] + }; + return s.writesPC = !1, s + }, + function(e, i, r) { + var s = n.gprs, + t = function() { + var t = s[e] + s[i]; + return r && !r() || (s[e] = t), t + }; + return t.writesPC = e == n.PC, t + }, + null, null + ], this.addressingMode2RegisterShifted = [ + function(e, i, r) { + var s = n.gprs, + t = function() { + var t = s[e]; + return r && !r() || (i(), s[e] -= n.shifterOperand), t + }; + return t.writesPC = e == n.PC, t + }, + null, null, null, + function(e, i, r) { + var s = n.gprs, + t = function() { + var t = s[e]; + return r && !r() || (i(), s[e] += n.shifterOperand), t + }; + return t.writesPC = e == n.PC, t + }, + null, null, null, + function(t, e, i) { + var r = n.gprs, + s = function() { + return e(), r[t] - n.shifterOperand + }; + return s.writesPC = !1, s + }, + function(e, i, r) { + var s = n.gprs, + t = function() { + i(); + var t = s[e] - n.shifterOperand; + return r && !r() || (s[e] = t), t + }; + return t.writesPC = e == n.PC, t + }, + null, null, + function(t, e, i) { + var r = n.gprs, + s = function() { + return e(), r[t] + n.shifterOperand + }; + return s.writesPC = !1, s + }, + function(e, i, r) { + var s = n.gprs, + t = function() { + i(); + var t = s[e] + n.shifterOperand; + return r && !r() || (s[e] = t), t + }; + return t.writePC = e == n.PC, t + }, + null, null + ] +}; + +function MemoryView(t, e) { + this.inherit(), this.buffer = t, this.view = new DataView(this.buffer, "number" == typeof e ? e : 0), this.mask = t.byteLength - 1, this.resetMask() +} + +function MemoryBlock(t, e) { + MemoryView.call(this, new ArrayBuffer(t)), this.ICACHE_PAGE_BITS = e, this.PAGE_MASK = (2 << this.ICACHE_PAGE_BITS) - 1, this.icache = new Array(t >> this.ICACHE_PAGE_BITS + 1) +} + +function ROMView(t, e) { + MemoryView.call(this, t, e), this.ICACHE_PAGE_BITS = 10, this.PAGE_MASK = (2 << this.ICACHE_PAGE_BITS) - 1, this.icache = new Array(t.byteLength >> this.ICACHE_PAGE_BITS + 1), this.mask = 33554431, this.resetMask() +} + +function BIOSView(t, e) { + MemoryView.call(this, t, e), this.ICACHE_PAGE_BITS = 16, this.PAGE_MASK = (2 << this.ICACHE_PAGE_BITS) - 1, this.icache = new Array(1) +} + +function BadMemory(t, e) { + this.inherit(), this.cpu = e, this.mmu = t +} + +function GameBoyAdvanceMMU() { + this.inherit(), this.REGION_BIOS = 0, this.REGION_WORKING_RAM = 2, this.REGION_WORKING_IRAM = 3, this.REGION_IO = 4, this.REGION_PALETTE_RAM = 5, this.REGION_VRAM = 6, this.REGION_OAM = 7, this.REGION_CART0 = 8, this.REGION_CART1 = 10, this.REGION_CART2 = 12, this.REGION_CART_SRAM = 14, this.BASE_BIOS = 0, this.BASE_WORKING_RAM = 33554432, this.BASE_WORKING_IRAM = 50331648, this.BASE_IO = 67108864, this.BASE_PALETTE_RAM = 83886080, this.BASE_VRAM = 100663296, this.BASE_OAM = 117440512, this.BASE_CART0 = 134217728, this.BASE_CART1 = 167772160, this.BASE_CART2 = 201326592, this.BASE_CART_SRAM = 234881024, this.BASE_MASK = 251658240, this.BASE_OFFSET = 24, this.OFFSET_MASK = 16777215, this.SIZE_BIOS = 16384, this.SIZE_WORKING_RAM = 262144, this.SIZE_WORKING_IRAM = 32768, this.SIZE_IO = 1024, this.SIZE_PALETTE_RAM = 1024, this.SIZE_VRAM = 98304, this.SIZE_OAM = 1024, this.SIZE_CART0 = 33554432, this.SIZE_CART1 = 33554432, this.SIZE_CART2 = 33554432, this.SIZE_CART_SRAM = 32768, this.SIZE_CART_FLASH512 = 65536, this.SIZE_CART_FLASH1M = 131072, this.SIZE_CART_EEPROM = 8192, this.DMA_TIMING_NOW = 0, this.DMA_TIMING_VBLANK = 1, this.DMA_TIMING_HBLANK = 2, this.DMA_TIMING_CUSTOM = 3, this.DMA_INCREMENT = 0, this.DMA_DECREMENT = 1, this.DMA_FIXED = 2, this.DMA_INCREMENT_RELOAD = 3, this.DMA_OFFSET = [1, -1, 0, 1], this.WAITSTATES = [0, 0, 2, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4], this.WAITSTATES_32 = [0, 0, 5, 0, 0, 1, 0, 1, 7, 7, 9, 9, 13, 13, 8], this.WAITSTATES_SEQ = [0, 0, 2, 0, 0, 0, 0, 0, 2, 2, 4, 4, 8, 8, 4], this.WAITSTATES_SEQ_32 = [0, 0, 5, 0, 0, 1, 0, 1, 5, 5, 9, 9, 17, 17, 8], this.NULLWAIT = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + for (var t = 15; t < 256; ++t) this.WAITSTATES[t] = 0, this.WAITSTATES_32[t] = 0, this.WAITSTATES_SEQ[t] = 0, this.WAITSTATES_SEQ_32[t] = 0, this.NULLWAIT[t] = 0; + this.ROM_WS = [4, 3, 2, 8], this.ROM_WS_SEQ = [ + [2, 1], + [4, 1], + [8, 1] + ], this.ICACHE_PAGE_BITS = 8, this.PAGE_MASK = (2 << this.ICACHE_PAGE_BITS) - 1, this.bios = null +} + +function GameBoyAdvanceIO() { + this.DISPCNT = 0, this.GREENSWP = 2, this.DISPSTAT = 4, this.VCOUNT = 6, this.BG0CNT = 8, this.BG1CNT = 10, this.BG2CNT = 12, this.BG3CNT = 14, this.BG0HOFS = 16, this.BG0VOFS = 18, this.BG1HOFS = 20, this.BG1VOFS = 22, this.BG2HOFS = 24, this.BG2VOFS = 26, this.BG3HOFS = 28, this.BG3VOFS = 30, this.BG2PA = 32, this.BG2PB = 34, this.BG2PC = 36, this.BG2PD = 38, this.BG2X_LO = 40, this.BG2X_HI = 42, this.BG2Y_LO = 44, this.BG2Y_HI = 46, this.BG3PA = 48, this.BG3PB = 50, this.BG3PC = 52, this.BG3PD = 54, this.BG3X_LO = 56, this.BG3X_HI = 58, this.BG3Y_LO = 60, this.BG3Y_HI = 62, this.WIN0H = 64, this.WIN1H = 66, this.WIN0V = 68, this.WIN1V = 70, this.WININ = 72, this.WINOUT = 74, this.MOSAIC = 76, this.BLDCNT = 80, this.BLDALPHA = 82, this.BLDY = 84, this.SOUND1CNT_LO = 96, this.SOUND1CNT_HI = 98, this.SOUND1CNT_X = 100, this.SOUND2CNT_LO = 104, this.SOUND2CNT_HI = 108, this.SOUND3CNT_LO = 112, this.SOUND3CNT_HI = 114, this.SOUND3CNT_X = 116, this.SOUND4CNT_LO = 120, this.SOUND4CNT_HI = 124, this.SOUNDCNT_LO = 128, this.SOUNDCNT_HI = 130, this.SOUNDCNT_X = 132, this.SOUNDBIAS = 136, this.WAVE_RAM0_LO = 144, this.WAVE_RAM0_HI = 146, this.WAVE_RAM1_LO = 148, this.WAVE_RAM1_HI = 150, this.WAVE_RAM2_LO = 152, this.WAVE_RAM2_HI = 154, this.WAVE_RAM3_LO = 156, this.WAVE_RAM3_HI = 158, this.FIFO_A_LO = 160, this.FIFO_A_HI = 162, this.FIFO_B_LO = 164, this.FIFO_B_HI = 166, this.DMA0SAD_LO = 176, this.DMA0SAD_HI = 178, this.DMA0DAD_LO = 180, this.DMA0DAD_HI = 182, this.DMA0CNT_LO = 184, this.DMA0CNT_HI = 186, this.DMA1SAD_LO = 188, this.DMA1SAD_HI = 190, this.DMA1DAD_LO = 192, this.DMA1DAD_HI = 194, this.DMA1CNT_LO = 196, this.DMA1CNT_HI = 198, this.DMA2SAD_LO = 200, this.DMA2SAD_HI = 202, this.DMA2DAD_LO = 204, this.DMA2DAD_HI = 206, this.DMA2CNT_LO = 208, this.DMA2CNT_HI = 210, this.DMA3SAD_LO = 212, this.DMA3SAD_HI = 214, this.DMA3DAD_LO = 216, this.DMA3DAD_HI = 218, this.DMA3CNT_LO = 220, this.DMA3CNT_HI = 222, this.TM0CNT_LO = 256, this.TM0CNT_HI = 258, this.TM1CNT_LO = 260, this.TM1CNT_HI = 262, this.TM2CNT_LO = 264, this.TM2CNT_HI = 266, this.TM3CNT_LO = 268, this.TM3CNT_HI = 270, this.SIODATA32_LO = 288, this.SIOMULTI0 = 288, this.SIODATA32_HI = 290, this.SIOMULTI1 = 290, this.SIOMULTI2 = 292, this.SIOMULTI3 = 294, this.SIOCNT = 296, this.SIOMLT_SEND = 298, this.SIODATA8 = 298, this.RCNT = 308, this.JOYCNT = 320, this.JOY_RECV = 336, this.JOY_TRANS = 340, this.JOYSTAT = 344, this.KEYINPUT = 304, this.KEYCNT = 306, this.IE = 512, this.IF = 514, this.WAITCNT = 516, this.IME = 520, this.POSTFLG = 768, this.HALTCNT = 769, this.DEFAULT_DISPCNT = 128, this.DEFAULT_SOUNDBIAS = 512, this.DEFAULT_BGPA = 1, this.DEFAULT_BGPD = 1, this.DEFAULT_RCNT = 32768 +} + +function GameBoyAdvanceAudio() { + this.bufferSize = 4096, this.maxSamples = this.bufferSize << 2, this.buffers = [new Float32Array(this.maxSamples), new Float32Array(this.maxSamples)], this.sampleMask = this.maxSamples - 1, this.masterEnable = !0, this.masterVolume = 1, this.SOUND_MAX = 1024, this.FIFO_MAX = 512, this.PSG_MAX = 128, this.isInit = !1, this.isInit2 = !1, window.AudioContext = window.AudioContext || window.webkitAudioContext, this.context = new AudioContext +} + +function GameBoyAdvanceVideo() { + this.renderPath = new GameBoyAdvanceSoftwareRenderer, this.CYCLES_PER_PIXEL = 4, this.HORIZONTAL_PIXELS = 240, this.HBLANK_PIXELS = 68, this.HDRAW_LENGTH = 1006, this.HBLANK_LENGTH = 226, this.HORIZONTAL_LENGTH = 1232, this.VERTICAL_PIXELS = 160, this.VBLANK_PIXELS = 68, this.VERTICAL_TOTAL_PIXELS = 228, this.TOTAL_LENGTH = 280896, this.drawCallback = function() {}, this.vblankCallback = function() {} +} + +function MemoryProxy(t, e, i) { + if (this.owner = t, this.blocks = [], this.blockSize = i, this.mask = (1 << i) - 1, this.size = e, i) + for (var r = 0; r < e >> i; ++r) this.blocks.push(new MemoryView(new ArrayBuffer(1 << i))); + else this.blockSize = 31, this.mask = -1, this.blocks[0] = new MemoryView(new ArrayBuffer(e)) +} + +function GameBoyAdvanceRenderProxy() { + this.worker = new Worker("js/video/worker.js"), this.currentFrame = 0, this.delay = 0, this.skipFrame = !1, this.dirty = null; + var e = this, + i = { + finish: function(t) { + e.backing = t.backing, e.caller.finishDraw(e.backing), --e.delay + } + }; + this.worker.onmessage = function(t) { + i[t.data.type](t.data) + } +} + +function MemoryAligned16(t) { + this.buffer = new Uint16Array(t >> 1) +} + +function GameBoyAdvanceVRAM(t) { + MemoryAligned16.call(this, t), this.vram = this.buffer +} + +function GameBoyAdvanceOAM(t) { + MemoryAligned16.call(this, t), this.oam = this.buffer, this.objs = new Array(128); + for (var e = 0; e < 128; ++e) this.objs[e] = new GameBoyAdvanceOBJ(this, e); + this.scalerot = new Array(32); + for (e = 0; e < 32; ++e) this.scalerot[e] = { + a: 1, + b: 0, + c: 0, + d: 1 + } +} + +function GameBoyAdvancePalette() { + this.colors = [new Array(256), new Array(256)], this.adjustedColors = [new Array(256), new Array(256)], this.passthroughColors = [this.colors[0], this.colors[0], this.colors[0], this.colors[0], this.colors[1], this.colors[0]], this.blendY = 1 +} + +function GameBoyAdvanceOBJ(t, e) { + this.TILE_OFFSET = 65536, this.oam = t, this.index = e, this.x = 0, this.y = 0, this.scalerot = 0, this.doublesize = !1, this.disable = 1, this.mode = 0, this.mosaic = !1, this.multipalette = !1, this.shape = 0, this.scalerotParam = 0, this.hflip = 0, this.vflip = 0, this.tileBase = 0, this.priority = 0, this.palette = 0, this.drawScanline = this.drawScanlineNormal, this.pushPixel = GameBoyAdvanceSoftwareRenderer.pushPixel, this.cachedWidth = 8, this.cachedHeight = 8 +} + +function GameBoyAdvanceOBJLayer(t, e) { + this.video = t, this.bg = !1, this.index = t.LAYER_OBJ, this.priority = e, this.enabled = !1, this.objwin = 0 +} + +function GameBoyAdvanceSoftwareRenderer() { + this.LAYER_BG0 = 0, this.LAYER_BG1 = 1, this.LAYER_BG2 = 2, this.LAYER_BG3 = 3, this.LAYER_OBJ = 4, this.LAYER_BACKDROP = 5, this.HORIZONTAL_PIXELS = 240, this.VERTICAL_PIXELS = 160, this.LAYER_MASK = 6, this.BACKGROUND_MASK = 1, this.TARGET2_MASK = 8, this.TARGET1_MASK = 16, this.OBJWIN_MASK = 32, this.WRITTEN_MASK = 128, this.PRIORITY_MASK = this.LAYER_MASK | this.BACKGROUND_MASK, this.drawBackdrop = new function(n) { + this.bg = !0, this.priority = -1, this.index = n.LAYER_BACKDROP, this.enabled = !0, this.drawScanline = function(t, e, i, r) { + for (var s = i; s < r; ++s) t.stencil[s] & n.WRITTEN_MASK ? t.stencil[s] & n.TARGET1_MASK && (t.color[s] = n.palette.mix(n.blendB, n.palette.accessColor(this.index, 0), n.blendA, t.color[s]), t.stencil[s] = n.WRITTEN_MASK) : (t.color[s] = n.palette.accessColor(this.index, 0), t.stencil[s] = n.WRITTEN_MASK) + } + }(this) +} + +function GameBoyAdvanceInterruptHandler() { + this.inherit(), this.FREQUENCY = 16777216, this.cpu = null, this.enable = !1, this.IRQ_VBLANK = 0, this.IRQ_HBLANK = 1, this.IRQ_VCOUNTER = 2, this.IRQ_TIMER0 = 3, this.IRQ_TIMER1 = 4, this.IRQ_TIMER2 = 5, this.IRQ_TIMER3 = 6, this.IRQ_SIO = 7, this.IRQ_DMA0 = 8, this.IRQ_DMA1 = 9, this.IRQ_DMA2 = 10, this.IRQ_DMA3 = 11, this.IRQ_KEYPAD = 12, this.IRQ_GAMEPAK = 13, this.MASK_VBLANK = 1, this.MASK_HBLANK = 2, this.MASK_VCOUNTER = 4, this.MASK_TIMER0 = 8, this.MASK_TIMER1 = 16, this.MASK_TIMER2 = 32, this.MASK_TIMER3 = 64, this.MASK_SIO = 128, this.MASK_DMA0 = 256, this.MASK_DMA1 = 512, this.MASK_DMA2 = 1024, this.MASK_DMA3 = 2048, this.MASK_KEYPAD = 4096, this.MASK_GAMEPAK = 8192 +} + +function GameBoyAdvanceKeypad() { + this.KEYCODE_LEFT = 37, this.KEYCODE_UP = 38, this.KEYCODE_RIGHT = 39, this.KEYCODE_DOWN = 40, this.KEYCODE_START = 13, this.KEYCODE_SELECT = 220, this.KEYCODE_A = 90, this.KEYCODE_B = 88, this.KEYCODE_L = 65, this.KEYCODE_R = 83, this.GAMEPAD_LEFT = 14, this.GAMEPAD_UP = 12, this.GAMEPAD_RIGHT = 15, this.GAMEPAD_DOWN = 13, this.GAMEPAD_START = 9, this.GAMEPAD_SELECT = 8, this.GAMEPAD_A = 1, this.GAMEPAD_B = 0, this.GAMEPAD_L = 4, this.GAMEPAD_R = 5, this.GAMEPAD_THRESHOLD = .2, this.A = 0, this.B = 1, this.SELECT = 2, this.START = 3, this.RIGHT = 4, this.LEFT = 5, this.UP = 6, this.DOWN = 7, this.R = 8, this.L = 9, this.currentDown = 1023, this.eatInput = !1, this.gamepads = [] +} + +function GameBoyAdvanceSIO() { + this.SIO_NORMAL_8 = 0, this.SIO_NORMAL_32 = 1, this.SIO_MULTI = 2, this.SIO_UART = 3, this.SIO_GPIO = 8, this.SIO_JOYBUS = 12, this.BAUD = [9600, 38400, 57600, 115200] +} + +function SRAMSavedata(t) { + MemoryView.call(this, new ArrayBuffer(t), 0), this.writePending = !1 +} + +function FlashSavedata(t) { + MemoryView.call(this, new ArrayBuffer(t), 0), this.COMMAND_WIPE = 16, this.COMMAND_ERASE_SECTOR = 48, this.COMMAND_ERASE = 128, this.COMMAND_ID = 144, this.COMMAND_WRITE = 160, this.COMMAND_SWITCH_BANK = 176, this.COMMAND_TERMINATE_ID = 240, this.ID_PANASONIC = 6962, this.ID_SANYO = 4962, this.bank0 = new DataView(this.buffer, 0, 65536), 65536 < t ? (this.id = this.ID_SANYO, this.bank1 = new DataView(this.buffer, 65536)) : (this.id = this.ID_PANASONIC, this.bank1 = null), this.bank = this.bank0, this.idMode = !1, this.writePending = !1, this.first = 0, this.second = 0, this.command = 0, this.pendingCommand = 0 +} + +function EEPROMSavedata(t, e) { + MemoryView.call(this, new ArrayBuffer(t), 0), this.writeAddress = 0, this.readBitsRemaining = 0, this.readAddress = 0, this.command = 0, this.commandBitsRemaining = 0, this.realSize = 0, this.addressBits = 0, this.writePending = !1, this.dma = e.core.irq.dma[3], this.COMMAND_NULL = 0, this.COMMAND_PENDING = 1, this.COMMAND_WRITE = 2, this.COMMAND_READ_PENDING = 3, this.COMMAND_READ = 4 +} + +function GameBoyAdvanceGPIO(t, e) { + this.core = t, this.rom = e, this.readWrite = 0, this.direction = 0, this.device = new GameBoyAdvanceRTC(this) +} + +function GameBoyAdvanceRTC(t) { + this.gpio = t, this.pins = 0, this.direction = 0, this.totalBytes = [0, 0, 7, 0, 1, 0, 3, 0], this.bytesRemaining = 0, this.transferStep = 0, this.reading = 0, this.bitsRead = 0, this.bits = 0, this.command = -1, this.control = 64, this.time = [0, 0, 0, 0, 0, 0, 0] +} + +function GameBoyAdvance() { + this.LOG_ERROR = 1, this.LOG_WARN = 2, this.LOG_STUB = 4, this.LOG_INFO = 8, this.LOG_DEBUG = 16, this.SYS_ID = "com.endrift.gbajs", this.logLevel = this.LOG_ERROR | this.LOG_WARN, this.rom = null, this.cpu = new ARMCore, this.mmu = new GameBoyAdvanceMMU, this.irq = new GameBoyAdvanceInterruptHandler, this.io = new GameBoyAdvanceIO, this.audio = new GameBoyAdvanceAudio, this.video = new GameBoyAdvanceVideo, this.keypad = new GameBoyAdvanceKeypad, this.sio = new GameBoyAdvanceSIO, this.cpu.mmu = this.mmu, this.cpu.irq = this.irq, this.mmu.cpu = this.cpu, (this.mmu.core = this).irq.cpu = this.cpu, this.irq.io = this.io, this.irq.audio = this.audio, this.irq.video = this.video, (this.irq.core = this).io.cpu = this.cpu, this.io.audio = this.audio, this.io.video = this.video, this.io.keypad = this.keypad, this.io.sio = this.sio, (this.io.core = this).audio.cpu = this.cpu, (this.audio.core = this).video.cpu = this.cpu, (((this.video.core = this).keypad.core = this).sio.core = this).keypad.registerHandlers(), this.doStep = this.waitFrame, this.paused = !1, this.seenFrame = !1, this.seenSave = !1, this.lastVblank = 0, this.queue = null, this.reportFPS = null, this.throttle = 16; + var e = this; + window.queueFrame = function(t) { + e.queue = window.setTimeout(t, e.throttle) + }, window.URL = window.URL || window.webkitURL, this.video.vblankCallback = function() { + e.seenFrame = !0 + } +} +ARMCoreArm.prototype.constructAddressingMode1ASR = function(i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + ++s.cycles; + var t = n[i]; + i == s.PC && (t += 4), t &= 255; + var e = n[r]; + r == s.PC && (e += 4), 0 == t ? (s.shifterOperand = e, s.shifterCarryOut = s.cpsrC) : t < 32 ? (s.shifterOperand = e >> t, s.shifterCarryOut = e & 1 << t - 1) : n[r] >> 31 ? (s.shifterOperand = 4294967295, s.shifterCarryOut = 2147483648) : (s.shifterOperand = 0, s.shifterCarryOut = 0) + } +}, ARMCoreArm.prototype.constructAddressingMode1Immediate = function(t) { + var e = this.cpu; + return function() { + e.shifterOperand = t, e.shifterCarryOut = e.cpsrC + } +}, ARMCoreArm.prototype.constructAddressingMode1ImmediateRotate = function(t, e) { + var i = this.cpu; + return function() { + i.shifterOperand = t >>> e | t << 32 - e, i.shifterCarryOut = i.shifterOperand >> 31 + } +}, ARMCoreArm.prototype.constructAddressingMode1LSL = function(i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + ++s.cycles; + var t = n[i]; + i == s.PC && (t += 4), t &= 255; + var e = n[r]; + r == s.PC && (e += 4), 0 == t ? (s.shifterOperand = e, s.shifterCarryOut = s.cpsrC) : t < 32 ? (s.shifterOperand = e << t, s.shifterCarryOut = e & 1 << 32 - t) : 32 == t ? (s.shifterOperand = 0, s.shifterCarryOut = 1 & e) : (s.shifterOperand = 0, s.shifterCarryOut = 0) + } +}, ARMCoreArm.prototype.constructAddressingMode1LSR = function(i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + ++s.cycles; + var t = n[i]; + i == s.PC && (t += 4), t &= 255; + var e = n[r]; + r == s.PC && (e += 4), 0 == t ? (s.shifterOperand = e, s.shifterCarryOut = s.cpsrC) : t < 32 ? (s.shifterOperand = e >>> t, s.shifterCarryOut = e & 1 << t - 1) : 32 == t ? (s.shifterOperand = 0, s.shifterCarryOut = e >> 31) : (s.shifterOperand = 0, s.shifterCarryOut = 0) + } +}, ARMCoreArm.prototype.constructAddressingMode1ROR = function(r, s) { + var n = this.cpu, + a = n.gprs; + return function() { + ++n.cycles; + var t = a[r]; + r == n.PC && (t += 4), t &= 255; + var e = a[s]; + s == n.PC && (e += 4); + var i = 31 & t; + 0 == t ? (n.shifterOperand = e, n.shifterCarryOut = n.cpsrC) : i ? (n.shifterOperand = a[s] >>> i | a[s] << 32 - i, n.shifterCarryOut = e & 1 << i - 1) : (n.shifterOperand = e, n.shifterCarryOut = e >> 31) + } +}, ARMCoreArm.prototype.constructAddressingMode23Immediate = function(t, e, i) { + var r = (983040 & t) >> 16; + return this.addressingMode23Immediate[(27262976 & t) >> 21](r, e, i) +}, ARMCoreArm.prototype.constructAddressingMode23Register = function(t, e, i) { + var r = (983040 & t) >> 16; + return this.addressingMode23Register[(27262976 & t) >> 21](r, e, i) +}, ARMCoreArm.prototype.constructAddressingMode2RegisterShifted = function(t, e, i) { + var r = (983040 & t) >> 16; + return this.addressingMode2RegisterShifted[(27262976 & t) >> 21](r, e, i) +}, ARMCoreArm.prototype.constructAddressingMode4 = function(t, e) { + var i = this.cpu.gprs; + return function() { + return i[e] + t + } +}, ARMCoreArm.prototype.constructAddressingMode4Writeback = function(i, r, s, n) { + var a = this.cpu, + o = a.gprs; + return function(t) { + var e = o[s] + i; + return t && n && a.mmu.store32(o[s] + i - 4, o[s]), o[s] += r, e + } +}, ARMCoreArm.prototype.constructADC = function(e, i, r, s) { + var n = this.cpu, + a = n.gprs; + return function() { + if (n.mmu.waitPrefetch32(a[n.PC]), !s || s()) { + r(); + var t = (n.shifterOperand >>> 0) + !!n.cpsrC; + a[e] = (a[i] >>> 0) + t + } + } +}, ARMCoreArm.prototype.constructADCS = function(i, r, s, n) { + var a = this.cpu, + o = a.gprs; + return function() { + if (a.mmu.waitPrefetch32(o[a.PC]), !n || n()) { + s(); + var t = (a.shifterOperand >>> 0) + !!a.cpsrC, + e = (o[r] >>> 0) + t; + i == a.PC && a.hasSPSR() ? a.unpackCPSR(a.spsr) : (a.cpsrN = e >> 31, a.cpsrZ = !(4294967295 & e), a.cpsrC = 4294967295 < e, a.cpsrV = o[r] >> 31 == t >> 31 && o[r] >> 31 != e >> 31 && t >> 31 != e >> 31), o[i] = e + } + } +}, ARMCoreArm.prototype.constructADD = function(t, e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = (n[e] >>> 0) + (s.shifterOperand >>> 0)) + } +}, ARMCoreArm.prototype.constructADDS = function(e, i, r, s) { + var n = this.cpu, + a = n.gprs; + return function() { + if (n.mmu.waitPrefetch32(a[n.PC]), !s || s()) { + r(); + var t = (a[i] >>> 0) + (n.shifterOperand >>> 0); + e == n.PC && n.hasSPSR() ? n.unpackCPSR(n.spsr) : (n.cpsrN = t >> 31, n.cpsrZ = !(4294967295 & t), n.cpsrC = 4294967295 < t, n.cpsrV = a[i] >> 31 == n.shifterOperand >> 31 && a[i] >> 31 != t >> 31 && n.shifterOperand >> 31 != t >> 31), a[e] = t + } + } +}, ARMCoreArm.prototype.constructAND = function(t, e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = n[e] & s.shifterOperand) + } +}, ARMCoreArm.prototype.constructANDS = function(t, e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = n[e] & s.shifterOperand, t == s.PC && s.hasSPSR() ? s.unpackCPSR(s.spsr) : (s.cpsrN = n[t] >> 31, s.cpsrZ = !(4294967295 & n[t]), s.cpsrC = s.shifterCarryOut)) + } +}, ARMCoreArm.prototype.constructB = function(t, e) { + var i = this.cpu, + r = i.gprs; + return function() { + !e || e() ? (i.mmu.waitPrefetch32(r[i.PC]), r[i.PC] += t) : i.mmu.waitPrefetch32(r[i.PC]) + } +}, ARMCoreArm.prototype.constructBIC = function(t, e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = n[e] & ~s.shifterOperand) + } +}, ARMCoreArm.prototype.constructBICS = function(t, e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = n[e] & ~s.shifterOperand, t == s.PC && s.hasSPSR() ? s.unpackCPSR(s.spsr) : (s.cpsrN = n[t] >> 31, s.cpsrZ = !(4294967295 & n[t]), s.cpsrC = s.shifterCarryOut)) + } +}, ARMCoreArm.prototype.constructBL = function(t, e) { + var i = this.cpu, + r = i.gprs; + return function() { + !e || e() ? (i.mmu.waitPrefetch32(r[i.PC]), r[i.LR] = r[i.PC] - 4, r[i.PC] += t) : i.mmu.waitPrefetch32(r[i.PC]) + } +}, ARMCoreArm.prototype.constructBX = function(t, e) { + var i = this.cpu, + r = i.gprs; + return function() { + !e || e() ? (i.mmu.waitPrefetch32(r[i.PC]), i.switchExecMode(1 & r[t]), r[i.PC] = 4294967294 & r[t]) : i.mmu.waitPrefetch32(r[i.PC]) + } +}, ARMCoreArm.prototype.constructCMN = function(t, e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + if (s.mmu.waitPrefetch32(n[s.PC]), !r || r()) { + i(); + var t = (n[e] >>> 0) + (s.shifterOperand >>> 0); + s.cpsrN = t >> 31, s.cpsrZ = !(4294967295 & t), s.cpsrC = 4294967295 < t, s.cpsrV = n[e] >> 31 == s.shifterOperand >> 31 && n[e] >> 31 != t >> 31 && s.shifterOperand >> 31 != t >> 31 + } + } +}, ARMCoreArm.prototype.constructCMP = function(t, e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + if (s.mmu.waitPrefetch32(n[s.PC]), !r || r()) { + i(); + var t = n[e] - s.shifterOperand; + s.cpsrN = t >> 31, s.cpsrZ = !(4294967295 & t), s.cpsrC = n[e] >>> 0 >= s.shifterOperand >>> 0, s.cpsrV = n[e] >> 31 != s.shifterOperand >> 31 && n[e] >> 31 != t >> 31 + } + } +}, ARMCoreArm.prototype.constructEOR = function(t, e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = n[e] ^ s.shifterOperand) + } +}, ARMCoreArm.prototype.constructEORS = function(t, e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = n[e] ^ s.shifterOperand, t == s.PC && s.hasSPSR() ? s.unpackCPSR(s.spsr) : (s.cpsrN = n[t] >> 31, s.cpsrZ = !(4294967295 & n[t]), s.cpsrC = s.shifterCarryOut)) + } +}, ARMCoreArm.prototype.constructLDM = function(s, n, a) { + var o = this.cpu, + h = o.gprs, + c = o.mmu; + return function() { + if (c.waitPrefetch32(h[o.PC]), !a || a()) { + var t, e, i = n(!1), + r = 0; + for (t = s, e = 0; t; t >>= 1, ++e) 1 & t && (h[e] = c.load32(4294967292 & i), i += 4, ++r); + c.waitMulti32(i, r), ++o.cycles + } + } +}, ARMCoreArm.prototype.constructLDMS = function(n, a, o) { + var h = this.cpu, + c = h.gprs, + u = h.mmu; + return function() { + if (u.waitPrefetch32(c[h.PC]), !o || o()) { + var t, e, i = a(!1), + r = 0, + s = h.mode; + for (h.switchMode(h.MODE_SYSTEM), t = n, e = 0; t; t >>= 1, ++e) 1 & t && (c[e] = u.load32(4294967292 & i), i += 4, ++r); + h.switchMode(s), u.waitMulti32(i, r), ++h.cycles + } + } +}, ARMCoreArm.prototype.constructLDR = function(e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + if (s.mmu.waitPrefetch32(n[s.PC]), !r || r()) { + var t = i(); + n[e] = s.mmu.load32(t), s.mmu.wait32(t), ++s.cycles + } + } +}, ARMCoreArm.prototype.constructLDRB = function(e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + if (s.mmu.waitPrefetch32(n[s.PC]), !r || r()) { + var t = i(); + n[e] = s.mmu.loadU8(t), s.mmu.wait(t), ++s.cycles + } + } +}, ARMCoreArm.prototype.constructLDRH = function(e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + if (s.mmu.waitPrefetch32(n[s.PC]), !r || r()) { + var t = i(); + n[e] = s.mmu.loadU16(t), s.mmu.wait(t), ++s.cycles + } + } +}, ARMCoreArm.prototype.constructLDRSB = function(e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + if (s.mmu.waitPrefetch32(n[s.PC]), !r || r()) { + var t = i(); + n[e] = s.mmu.load8(t), s.mmu.wait(t), ++s.cycles + } + } +}, ARMCoreArm.prototype.constructLDRSH = function(e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + if (s.mmu.waitPrefetch32(n[s.PC]), !r || r()) { + var t = i(); + n[e] = s.mmu.load16(t), s.mmu.wait(t), ++s.cycles + } + } +}, ARMCoreArm.prototype.constructMLA = function(i, r, s, n, a) { + var o = this.cpu, + h = o.gprs; + return function() { + if (o.mmu.waitPrefetch32(h[o.PC]), !a || a()) + if (++o.cycles, o.mmu.waitMul(s), 4294901760 & h[n] && 4294901760 & h[s]) { + var t = (4294901760 & h[n]) * h[s] & 4294967295, + e = (65535 & h[n]) * h[s] & 4294967295; + h[i] = t + e + h[r] & 4294967295 + } else h[i] = h[n] * h[s] + h[r] + } +}, ARMCoreArm.prototype.constructMLAS = function(i, r, s, n, a) { + var o = this.cpu, + h = o.gprs; + return function() { + if (o.mmu.waitPrefetch32(h[o.PC]), !a || a()) { + if (++o.cycles, o.mmu.waitMul(s), 4294901760 & h[n] && 4294901760 & h[s]) { + var t = (4294901760 & h[n]) * h[s] & 4294967295, + e = (65535 & h[n]) * h[s] & 4294967295; + h[i] = t + e + h[r] & 4294967295 + } else h[i] = h[n] * h[s] + h[r]; + o.cpsrN = h[i] >> 31, o.cpsrZ = !(4294967295 & h[i]) + } + } +}, ARMCoreArm.prototype.constructMOV = function(t, e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = s.shifterOperand) + } +}, ARMCoreArm.prototype.constructMOVS = function(t, e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = s.shifterOperand, t == s.PC && s.hasSPSR() ? s.unpackCPSR(s.spsr) : (s.cpsrN = n[t] >> 31, s.cpsrZ = !(4294967295 & n[t]), s.cpsrC = s.shifterCarryOut)) + } +}, ARMCoreArm.prototype.constructMRS = function(t, e, i) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.waitPrefetch32(s[r.PC]), i && !i() || (s[t] = e ? r.spsr : r.packCPSR()) + } +}, ARMCoreArm.prototype.constructMSR = function(i, r, s, n, a) { + var o = this.cpu, + h = o.gprs, + c = 65536 & s, + u = 524288 & s; + return function() { + if (o.mmu.waitPrefetch32(h[o.PC]), !a || a()) { + var t; + t = 33554432 & s ? n : h[i]; + var e = (c ? 255 : 0) | (u ? 4278190080 : 0); + r ? (e &= o.USER_MASK | o.PRIV_MASK | o.STATE_MASK, o.spsr = o.spsr & ~e | t & e) : (e & o.USER_MASK && (o.cpsrN = t >> 31, o.cpsrZ = 1073741824 & t, o.cpsrC = 536870912 & t, o.cpsrV = 268435456 & t), o.mode != o.MODE_USER && e & o.PRIV_MASK && (o.switchMode(15 & t | 16), o.cpsrI = 128 & t, o.cpsrF = 64 & t)) + } + } +}, ARMCoreArm.prototype.constructMUL = function(i, r, s, n) { + var a = this.cpu, + o = a.gprs; + return function() { + if (a.mmu.waitPrefetch32(o[a.PC]), !n || n()) + if (a.mmu.waitMul(o[r]), 4294901760 & o[s] && 4294901760 & o[r]) { + var t = (4294901760 & o[s]) * o[r] | 0, + e = (65535 & o[s]) * o[r] | 0; + o[i] = t + e + } else o[i] = o[s] * o[r] + } +}, ARMCoreArm.prototype.constructMULS = function(i, r, s, n) { + var a = this.cpu, + o = a.gprs; + return function() { + if (a.mmu.waitPrefetch32(o[a.PC]), !n || n()) { + if (a.mmu.waitMul(o[r]), 4294901760 & o[s] && 4294901760 & o[r]) { + var t = (4294901760 & o[s]) * o[r] | 0, + e = (65535 & o[s]) * o[r] | 0; + o[i] = t + e + } else o[i] = o[s] * o[r]; + a.cpsrN = o[i] >> 31, a.cpsrZ = !(4294967295 & o[i]) + } + } +}, ARMCoreArm.prototype.constructMVN = function(t, e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = ~s.shifterOperand) + } +}, ARMCoreArm.prototype.constructMVNS = function(t, e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = ~s.shifterOperand, t == s.PC && s.hasSPSR() ? s.unpackCPSR(s.spsr) : (s.cpsrN = n[t] >> 31, s.cpsrZ = !(4294967295 & n[t]), s.cpsrC = s.shifterCarryOut)) + } +}, ARMCoreArm.prototype.constructORR = function(t, e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = n[e] | s.shifterOperand) + } +}, ARMCoreArm.prototype.constructORRS = function(t, e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = n[e] | s.shifterOperand, t == s.PC && s.hasSPSR() ? s.unpackCPSR(s.spsr) : (s.cpsrN = n[t] >> 31, s.cpsrZ = !(4294967295 & n[t]), s.cpsrC = s.shifterCarryOut)) + } +}, ARMCoreArm.prototype.constructRSB = function(t, e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = s.shifterOperand - n[e]) + } +}, ARMCoreArm.prototype.constructRSBS = function(e, i, r, s) { + var n = this.cpu, + a = n.gprs; + return function() { + if (n.mmu.waitPrefetch32(a[n.PC]), !s || s()) { + r(); + var t = n.shifterOperand - a[i]; + e == n.PC && n.hasSPSR() ? n.unpackCPSR(n.spsr) : (n.cpsrN = t >> 31, n.cpsrZ = !(4294967295 & t), n.cpsrC = n.shifterOperand >>> 0 >= a[i] >>> 0, n.cpsrV = n.shifterOperand >> 31 != a[i] >> 31 && n.shifterOperand >> 31 != t >> 31), a[e] = t + } + } +}, ARMCoreArm.prototype.constructRSC = function(e, i, r, s) { + var n = this.cpu, + a = n.gprs; + return function() { + if (n.mmu.waitPrefetch32(a[n.PC]), !s || s()) { + r(); + var t = (a[i] >>> 0) + !n.cpsrC; + a[e] = (n.shifterOperand >>> 0) - t + } + } +}, ARMCoreArm.prototype.constructRSCS = function(i, r, s, n) { + var a = this.cpu, + o = a.gprs; + return function() { + if (a.mmu.waitPrefetch32(o[a.PC]), !n || n()) { + s(); + var t = (o[r] >>> 0) + !a.cpsrC, + e = (a.shifterOperand >>> 0) - t; + i == a.PC && a.hasSPSR() ? a.unpackCPSR(a.spsr) : (a.cpsrN = e >> 31, a.cpsrZ = !(4294967295 & e), a.cpsrC = a.shifterOperand >>> 0 >= e >>> 0, a.cpsrV = a.shifterOperand >> 31 != t >> 31 && a.shifterOperand >> 31 != e >> 31), o[i] = e + } + } +}, ARMCoreArm.prototype.constructSBC = function(e, i, r, s) { + var n = this.cpu, + a = n.gprs; + return function() { + if (n.mmu.waitPrefetch32(a[n.PC]), !s || s()) { + r(); + var t = (n.shifterOperand >>> 0) + !n.cpsrC; + a[e] = (a[i] >>> 0) - t + } + } +}, ARMCoreArm.prototype.constructSBCS = function(i, r, s, n) { + var a = this.cpu, + o = a.gprs; + return function() { + if (a.mmu.waitPrefetch32(o[a.PC]), !n || n()) { + s(); + var t = (a.shifterOperand >>> 0) + !a.cpsrC, + e = (o[r] >>> 0) - t; + i == a.PC && a.hasSPSR() ? a.unpackCPSR(a.spsr) : (a.cpsrN = e >> 31, a.cpsrZ = !(4294967295 & e), a.cpsrC = o[r] >>> 0 >= e >>> 0, a.cpsrV = o[r] >> 31 != t >> 31 && o[r] >> 31 != e >> 31), o[i] = e + } + } +}, ARMCoreArm.prototype.constructSMLAL = function(r, s, n, a, o) { + var h = this.cpu, + c = h.gprs; + return function() { + if (h.mmu.waitPrefetch32(c[h.PC]), !o || o()) { + h.cycles += 2, h.mmu.waitMul(n); + var t = (4294901760 & c[a]) * c[n], + e = (65535 & c[a]) * c[n], + i = (c[s] >>> 0) + t + e; + c[s] = i, c[r] += Math.floor(i * (1 / 4294967296)) + } + } +}, ARMCoreArm.prototype.constructSMLALS = function(r, s, n, a, o) { + var h = this.cpu, + c = h.gprs; + return function() { + if (h.mmu.waitPrefetch32(c[h.PC]), !o || o()) { + h.cycles += 2, h.mmu.waitMul(n); + var t = (4294901760 & c[a]) * c[n], + e = (65535 & c[a]) * c[n], + i = (c[s] >>> 0) + t + e; + c[s] = i, c[r] += Math.floor(i * (1 / 4294967296)), h.cpsrN = c[r] >> 31, h.cpsrZ = !(4294967295 & c[r] || 4294967295 & c[s]) + } + } +}, ARMCoreArm.prototype.constructSMULL = function(i, r, s, n, a) { + var o = this.cpu, + h = 1 / 4294967296, + c = o.gprs; + return function() { + if (o.mmu.waitPrefetch32(c[o.PC]), !a || a()) { + ++o.cycles, o.mmu.waitMul(c[s]); + var t = ((4294901760 & c[n]) >> 0) * (c[s] >> 0), + e = ((65535 & c[n]) >> 0) * (c[s] >> 0); + c[r] = (4294967295 & t) + (4294967295 & e) & 4294967295, c[i] = Math.floor(t * h + e * h) + } + } +}, ARMCoreArm.prototype.constructSMULLS = function(i, r, s, n, a) { + var o = this.cpu, + h = 1 / 4294967296, + c = o.gprs; + return function() { + if (o.mmu.waitPrefetch32(c[o.PC]), !a || a()) { + ++o.cycles, o.mmu.waitMul(c[s]); + var t = ((4294901760 & c[n]) >> 0) * (c[s] >> 0), + e = ((65535 & c[n]) >> 0) * (c[s] >> 0); + c[r] = (4294967295 & t) + (4294967295 & e) & 4294967295, c[i] = Math.floor(t * h + e * h), o.cpsrN = c[i] >> 31, o.cpsrZ = !(4294967295 & c[i] || 4294967295 & c[r]) + } + } +}, ARMCoreArm.prototype.constructSTM = function(s, n, a) { + var o = this.cpu, + h = o.gprs, + c = o.mmu; + return function() { + if (!a || a()) { + c.wait32(h[o.PC]); + var t, e, i = n(!0), + r = 0; + for (t = s, e = 0; t; t >>= 1, ++e) 1 & t && (c.store32(i, h[e]), i += 4, ++r); + c.waitMulti32(i, r) + } else c.waitPrefetch32(h[o.PC]) + } +}, ARMCoreArm.prototype.constructSTMS = function(n, a, o) { + var h = this.cpu, + c = h.gprs, + u = h.mmu; + return function() { + if (!o || o()) { + u.wait32(c[h.PC]); + var t, e, i = h.mode, + r = a(!0), + s = 0; + for (h.switchMode(h.MODE_SYSTEM), t = n, e = 0; t; t >>= 1, ++e) 1 & t && (u.store32(r, c[e]), r += 4, ++s); + h.switchMode(i), u.waitMulti32(r, s) + } else u.waitPrefetch32(c[h.PC]) + } +}, ARMCoreArm.prototype.constructSTR = function(e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + if (!r || r()) { + var t = i(); + s.mmu.store32(t, n[e]), s.mmu.wait32(t), s.mmu.wait32(n[s.PC]) + } else s.mmu.waitPrefetch32(n[s.PC]) + } +}, ARMCoreArm.prototype.constructSTRB = function(e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + if (!r || r()) { + var t = i(); + s.mmu.store8(t, n[e]), s.mmu.wait(t), s.mmu.wait32(n[s.PC]) + } else s.mmu.waitPrefetch32(n[s.PC]) + } +}, ARMCoreArm.prototype.constructSTRH = function(e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + if (!r || r()) { + var t = i(); + s.mmu.store16(t, n[e]), s.mmu.wait(t), s.mmu.wait32(n[s.PC]) + } else s.mmu.waitPrefetch32(n[s.PC]) + } +}, ARMCoreArm.prototype.constructSUB = function(t, e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + s.mmu.waitPrefetch32(n[s.PC]), r && !r() || (i(), n[t] = n[e] - s.shifterOperand) + } +}, ARMCoreArm.prototype.constructSUBS = function(e, i, r, s) { + var n = this.cpu, + a = n.gprs; + return function() { + if (n.mmu.waitPrefetch32(a[n.PC]), !s || s()) { + r(); + var t = a[i] - n.shifterOperand; + e == n.PC && n.hasSPSR() ? n.unpackCPSR(n.spsr) : (n.cpsrN = t >> 31, n.cpsrZ = !(4294967295 & t), n.cpsrC = a[i] >>> 0 >= n.shifterOperand >>> 0, n.cpsrV = a[i] >> 31 != n.shifterOperand >> 31 && a[i] >> 31 != t >> 31), a[e] = t + } + } +}, ARMCoreArm.prototype.constructSWI = function(t, e) { + var i = this.cpu, + r = i.gprs; + return function() { + (!e || e()) && i.irq.swi32(t), i.mmu.waitPrefetch32(r[i.PC]) + } +}, ARMCoreArm.prototype.constructSWP = function(e, i, r, s) { + var n = this.cpu, + a = n.gprs; + return function() { + if (n.mmu.waitPrefetch32(a[n.PC]), !s || s()) { + n.mmu.wait32(a[i]), n.mmu.wait32(a[i]); + var t = n.mmu.load32(a[i]); + n.mmu.store32(a[i], a[r]), a[e] = t, ++n.cycles + } + } +}, ARMCoreArm.prototype.constructSWPB = function(e, i, r, s) { + var n = this.cpu, + a = n.gprs; + return function() { + if (n.mmu.waitPrefetch32(a[n.PC]), !s || s()) { + n.mmu.wait(a[i]), n.mmu.wait(a[i]); + var t = n.mmu.load8(a[i]); + n.mmu.store8(a[i], a[r]), a[e] = t, ++n.cycles + } + } +}, ARMCoreArm.prototype.constructTEQ = function(t, e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + if (s.mmu.waitPrefetch32(n[s.PC]), !r || r()) { + i(); + var t = n[e] ^ s.shifterOperand; + s.cpsrN = t >> 31, s.cpsrZ = !(4294967295 & t), s.cpsrC = s.shifterCarryOut + } + } +}, ARMCoreArm.prototype.constructTST = function(t, e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + if (s.mmu.waitPrefetch32(n[s.PC]), !r || r()) { + i(); + var t = n[e] & s.shifterOperand; + s.cpsrN = t >> 31, s.cpsrZ = !(4294967295 & t), s.cpsrC = s.shifterCarryOut + } + } +}, ARMCoreArm.prototype.constructUMLAL = function(r, s, n, a, o) { + var h = this.cpu, + c = h.gprs; + return function() { + if (h.mmu.waitPrefetch32(c[h.PC]), !o || o()) { + h.cycles += 2, h.mmu.waitMul(n); + var t = ((4294901760 & c[a]) >>> 0) * (c[n] >>> 0), + e = (65535 & c[a]) * (c[n] >>> 0), + i = (c[s] >>> 0) + t + e; + c[s] = i, c[r] += i * (1 / 4294967296) + } + } +}, ARMCoreArm.prototype.constructUMLALS = function(r, s, n, a, o) { + var h = this.cpu, + c = h.gprs; + return function() { + if (h.mmu.waitPrefetch32(c[h.PC]), !o || o()) { + h.cycles += 2, h.mmu.waitMul(n); + var t = ((4294901760 & c[a]) >>> 0) * (c[n] >>> 0), + e = (65535 & c[a]) * (c[n] >>> 0), + i = (c[s] >>> 0) + t + e; + c[s] = i, c[r] += i * (1 / 4294967296), h.cpsrN = c[r] >> 31, h.cpsrZ = !(4294967295 & c[r] || 4294967295 & c[s]) + } + } +}, ARMCoreArm.prototype.constructUMULL = function(i, r, s, n, a) { + var o = this.cpu, + h = 1 / 4294967296, + c = o.gprs; + return function() { + if (o.mmu.waitPrefetch32(c[o.PC]), !a || a()) { + ++o.cycles, o.mmu.waitMul(c[s]); + var t = ((4294901760 & c[n]) >>> 0) * (c[s] >>> 0), + e = ((65535 & c[n]) >>> 0) * (c[s] >>> 0); + c[r] = (4294967295 & t) + (4294967295 & e) & 4294967295, c[i] = t * h + e * h >>> 0 + } + } +}, ARMCoreArm.prototype.constructUMULLS = function(i, r, s, n, a) { + var o = this.cpu, + h = 1 / 4294967296, + c = o.gprs; + return function() { + if (o.mmu.waitPrefetch32(c[o.PC]), !a || a()) { + ++o.cycles, o.mmu.waitMul(c[s]); + var t = ((4294901760 & c[n]) >>> 0) * (c[s] >>> 0), + e = ((65535 & c[n]) >>> 0) * (c[s] >>> 0); + c[r] = (4294967295 & t) + (4294967295 & e) & 4294967295, c[i] = t * h + e * h >>> 0, o.cpsrN = c[i] >> 31, o.cpsrZ = !(4294967295 & c[i] || 4294967295 & c[r]) + } + } +}, ARMCoreThumb = function(t) { + this.cpu = t +}, ARMCoreThumb.prototype.constructADC = function(a, o) { + var h = this.cpu, + c = h.gprs; + return function() { + h.mmu.waitPrefetch(c[h.PC]); + var t = (c[o] >>> 0) + !!h.cpsrC, + e = c[a], + i = (e >>> 0) + t, + r = e >> 31, + s = i >> 31, + n = t >> 31; + h.cpsrN = s, h.cpsrZ = !(4294967295 & i), h.cpsrC = 4294967295 < i, h.cpsrV = r == n && r != s && n != s, c[a] = i + } +}, ARMCoreThumb.prototype.constructADD1 = function(e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + s.mmu.waitPrefetch(n[s.PC]); + var t = (n[i] >>> 0) + r; + s.cpsrN = t >> 31, s.cpsrZ = !(4294967295 & t), s.cpsrC = 4294967295 < t, s.cpsrV = !(n[i] >> 31) && (n[i] >> 31 ^ t) >> 31 && t >> 31, n[e] = t + } +}, ARMCoreThumb.prototype.constructADD2 = function(e, i) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.waitPrefetch(s[r.PC]); + var t = (s[e] >>> 0) + i; + r.cpsrN = t >> 31, r.cpsrZ = !(4294967295 & t), r.cpsrC = 4294967295 < t, r.cpsrV = !(s[e] >> 31) && (s[e] ^ t) >> 31 && (i ^ t) >> 31, s[e] = t + } +}, ARMCoreThumb.prototype.constructADD3 = function(e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + s.mmu.waitPrefetch(n[s.PC]); + var t = (n[i] >>> 0) + (n[r] >>> 0); + s.cpsrN = t >> 31, s.cpsrZ = !(4294967295 & t), s.cpsrC = 4294967295 < t, s.cpsrV = !((n[i] ^ n[r]) >> 31) && (n[i] ^ t) >> 31 && (n[r] ^ t) >> 31, n[e] = t + } +}, ARMCoreThumb.prototype.constructADD4 = function(t, e) { + var i = this.cpu, + r = i.gprs; + return function() { + i.mmu.waitPrefetch(r[i.PC]), r[t] += r[e] + } +}, ARMCoreThumb.prototype.constructADD5 = function(t, e) { + var i = this.cpu, + r = i.gprs; + return function() { + i.mmu.waitPrefetch(r[i.PC]), r[t] = (4294967292 & r[i.PC]) + e + } +}, ARMCoreThumb.prototype.constructADD6 = function(t, e) { + var i = this.cpu, + r = i.gprs; + return function() { + i.mmu.waitPrefetch(r[i.PC]), r[t] = r[i.SP] + e + } +}, ARMCoreThumb.prototype.constructADD7 = function(t) { + var e = this.cpu, + i = e.gprs; + return function() { + e.mmu.waitPrefetch(i[e.PC]), i[e.SP] += t + } +}, ARMCoreThumb.prototype.constructAND = function(t, e) { + var i = this.cpu, + r = i.gprs; + return function() { + i.mmu.waitPrefetch(r[i.PC]), r[t] = r[t] & r[e], i.cpsrN = r[t] >> 31, i.cpsrZ = !(4294967295 & r[t]) + } +}, ARMCoreThumb.prototype.constructASR1 = function(t, e, i) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.waitPrefetch(s[r.PC]), 0 == i ? (r.cpsrC = s[e] >> 31, r.cpsrC ? s[t] = 4294967295 : s[t] = 0) : (r.cpsrC = s[e] & 1 << i - 1, s[t] = s[e] >> i), r.cpsrN = s[t] >> 31, r.cpsrZ = !(4294967295 & s[t]) + } +}, ARMCoreThumb.prototype.constructASR2 = function(e, i) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.waitPrefetch(s[r.PC]); + var t = 255 & s[i]; + t && (t < 32 ? (r.cpsrC = s[e] & 1 << t - 1, s[e] >>= t) : (r.cpsrC = s[e] >> 31, r.cpsrC ? s[e] = 4294967295 : s[e] = 0)), r.cpsrN = s[e] >> 31, r.cpsrZ = !(4294967295 & s[e]) + } +}, ARMCoreThumb.prototype.constructB1 = function(t, e) { + var i = this.cpu, + r = i.gprs; + return function() { + i.mmu.waitPrefetch(r[i.PC]), e() && (r[i.PC] += t) + } +}, ARMCoreThumb.prototype.constructB2 = function(t) { + var e = this.cpu, + i = e.gprs; + return function() { + e.mmu.waitPrefetch(i[e.PC]), i[e.PC] += t + } +}, ARMCoreThumb.prototype.constructBIC = function(t, e) { + var i = this.cpu, + r = i.gprs; + return function() { + i.mmu.waitPrefetch(r[i.PC]), r[t] = r[t] & ~r[e], i.cpsrN = r[t] >> 31, i.cpsrZ = !(4294967295 & r[t]) + } +}, ARMCoreThumb.prototype.constructBL1 = function(t) { + var e = this.cpu, + i = e.gprs; + return function() { + e.mmu.waitPrefetch(i[e.PC]), i[e.LR] = i[e.PC] + t + } +}, ARMCoreThumb.prototype.constructBL2 = function(e) { + var i = this.cpu, + r = i.gprs; + return function() { + i.mmu.waitPrefetch(r[i.PC]); + var t = r[i.PC]; + r[i.PC] = r[i.LR] + (e << 1), r[i.LR] = t - 1 + } +}, ARMCoreThumb.prototype.constructBX = function(t, e) { + var i = this.cpu, + r = i.gprs; + return function() { + i.mmu.waitPrefetch(r[i.PC]), i.switchExecMode(1 & r[e]); + var t = 0; + 15 == e && (t = 2 & r[e]), r[i.PC] = r[e] & 4294967294 - t + } +}, ARMCoreThumb.prototype.constructCMN = function(e, i) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.waitPrefetch(s[r.PC]); + var t = (s[e] >>> 0) + (s[i] >>> 0); + r.cpsrN = t >> 31, r.cpsrZ = !(4294967295 & t), r.cpsrC = 4294967295 < t, r.cpsrV = s[e] >> 31 == s[i] >> 31 && s[e] >> 31 != t >> 31 && s[i] >> 31 != t >> 31 + } +}, ARMCoreThumb.prototype.constructCMP1 = function(e, i) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.waitPrefetch(s[r.PC]); + var t = s[e] - i; + r.cpsrN = t >> 31, r.cpsrZ = !(4294967295 & t), r.cpsrC = s[e] >>> 0 >= i, r.cpsrV = s[e] >> 31 && (s[e] ^ t) >> 31 + } +}, ARMCoreThumb.prototype.constructCMP2 = function(n, a) { + var o = this.cpu, + h = o.gprs; + return function() { + o.mmu.waitPrefetch(h[o.PC]); + var t = h[n], + e = h[a], + i = t - e, + r = i >> 31, + s = t >> 31; + o.cpsrN = r, o.cpsrZ = !(4294967295 & i), o.cpsrC = e >>> 0 <= t >>> 0, o.cpsrV = s != e >> 31 && s != r + } +}, ARMCoreThumb.prototype.constructCMP3 = function(e, i) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.waitPrefetch(s[r.PC]); + var t = s[e] - s[i]; + r.cpsrN = t >> 31, r.cpsrZ = !(4294967295 & t), r.cpsrC = s[e] >>> 0 >= s[i] >>> 0, r.cpsrV = (s[e] ^ s[i]) >> 31 && (s[e] ^ t) >> 31 + } +}, ARMCoreThumb.prototype.constructEOR = function(t, e) { + var i = this.cpu, + r = i.gprs; + return function() { + i.mmu.waitPrefetch(r[i.PC]), r[t] = r[t] ^ r[e], i.cpsrN = r[t] >> 31, i.cpsrZ = !(4294967295 & r[t]) + } +}, ARMCoreThumb.prototype.constructLDMIA = function(s, n) { + var a = this.cpu, + o = a.gprs; + return function() { + a.mmu.waitPrefetch(o[a.PC]); + var t, e, i = o[s], + r = 0; + for (t = 1, e = 0; e < 8; t <<= 1, ++e) n & t && (o[e] = a.mmu.load32(i), i += 4, ++r); + a.mmu.waitMulti32(i, r), 1 << s & n || (o[s] = i) + } +}, ARMCoreThumb.prototype.constructLDR1 = function(e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + s.mmu.waitPrefetch(n[s.PC]); + var t = n[i] + r; + n[e] = s.mmu.load32(t), s.mmu.wait32(t), ++s.cycles + } +}, ARMCoreThumb.prototype.constructLDR2 = function(t, e, i) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.waitPrefetch(s[r.PC]), s[t] = r.mmu.load32(s[e] + s[i]), r.mmu.wait32(s[e] + s[i]), ++r.cycles + } +}, ARMCoreThumb.prototype.constructLDR3 = function(t, e) { + var i = this.cpu, + r = i.gprs; + return function() { + i.mmu.waitPrefetch(r[i.PC]), r[t] = i.mmu.load32((4294967292 & r[i.PC]) + e), i.mmu.wait32(r[i.PC]), ++i.cycles + } +}, ARMCoreThumb.prototype.constructLDR4 = function(t, e) { + var i = this.cpu, + r = i.gprs; + return function() { + i.mmu.waitPrefetch(r[i.PC]), r[t] = i.mmu.load32(r[i.SP] + e), i.mmu.wait32(r[i.SP] + e), ++i.cycles + } +}, ARMCoreThumb.prototype.constructLDRB1 = function(e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + var t = n[i] + r; + s.mmu.waitPrefetch(n[s.PC]), n[e] = s.mmu.loadU8(t), s.mmu.wait(t), ++s.cycles + } +}, ARMCoreThumb.prototype.constructLDRB2 = function(t, e, i) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.waitPrefetch(s[r.PC]), s[t] = r.mmu.loadU8(s[e] + s[i]), r.mmu.wait(s[e] + s[i]), ++r.cycles + } +}, ARMCoreThumb.prototype.constructLDRH1 = function(e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + var t = n[i] + r; + s.mmu.waitPrefetch(n[s.PC]), n[e] = s.mmu.loadU16(t), s.mmu.wait(t), ++s.cycles + } +}, ARMCoreThumb.prototype.constructLDRH2 = function(t, e, i) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.waitPrefetch(s[r.PC]), s[t] = r.mmu.loadU16(s[e] + s[i]), r.mmu.wait(s[e] + s[i]), ++r.cycles + } +}, ARMCoreThumb.prototype.constructLDRSB = function(t, e, i) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.waitPrefetch(s[r.PC]), s[t] = r.mmu.load8(s[e] + s[i]), r.mmu.wait(s[e] + s[i]), ++r.cycles + } +}, ARMCoreThumb.prototype.constructLDRSH = function(t, e, i) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.waitPrefetch(s[r.PC]), s[t] = r.mmu.load16(s[e] + s[i]), r.mmu.wait(s[e] + s[i]), ++r.cycles + } +}, ARMCoreThumb.prototype.constructLSL1 = function(t, e, i) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.waitPrefetch(s[r.PC]), 0 == i ? s[t] = s[e] : (r.cpsrC = s[e] & 1 << 32 - i, s[t] = s[e] << i), r.cpsrN = s[t] >> 31, r.cpsrZ = !(4294967295 & s[t]) + } +}, ARMCoreThumb.prototype.constructLSL2 = function(e, i) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.waitPrefetch(s[r.PC]); + var t = 255 & s[i]; + t && (t < 32 ? (r.cpsrC = s[e] & 1 << 32 - t, s[e] <<= t) : (r.cpsrC = 32 < t ? 0 : 1 & s[e], s[e] = 0)), r.cpsrN = s[e] >> 31, r.cpsrZ = !(4294967295 & s[e]) + } +}, ARMCoreThumb.prototype.constructLSR1 = function(t, e, i) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.waitPrefetch(s[r.PC]), 0 == i ? (r.cpsrC = s[e] >> 31, s[t] = 0) : (r.cpsrC = s[e] & 1 << i - 1, s[t] = s[e] >>> i), r.cpsrN = 0, r.cpsrZ = !(4294967295 & s[t]) + } +}, ARMCoreThumb.prototype.constructLSR2 = function(e, i) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.waitPrefetch(s[r.PC]); + var t = 255 & s[i]; + t && (t < 32 ? (r.cpsrC = s[e] & 1 << t - 1, s[e] >>>= t) : (r.cpsrC = 32 < t ? 0 : s[e] >> 31, s[e] = 0)), r.cpsrN = s[e] >> 31, r.cpsrZ = !(4294967295 & s[e]) + } +}, ARMCoreThumb.prototype.constructMOV1 = function(t, e) { + var i = this.cpu, + r = i.gprs; + return function() { + i.mmu.waitPrefetch(r[i.PC]), r[t] = e, i.cpsrN = e >> 31, i.cpsrZ = !(4294967295 & e) + } +}, ARMCoreThumb.prototype.constructMOV2 = function(e, i, t) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.waitPrefetch(s[r.PC]); + var t = s[i]; + r.cpsrN = t >> 31, r.cpsrZ = !(4294967295 & t), r.cpsrC = 0, r.cpsrV = 0, s[e] = t + } +}, ARMCoreThumb.prototype.constructMOV3 = function(t, e) { + var i = this.cpu, + r = i.gprs; + return function() { + i.mmu.waitPrefetch(r[i.PC]), r[t] = r[e] + } +}, ARMCoreThumb.prototype.constructMUL = function(i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + if (s.mmu.waitPrefetch(n[s.PC]), s.mmu.waitMul(n[r]), 4294901760 & n[r] && 4294901760 & n[i]) { + var t = (4294901760 & n[i]) * n[r] & 4294967295, + e = (65535 & n[i]) * n[r] & 4294967295; + n[i] = t + e & 4294967295 + } else n[i] *= n[r]; + s.cpsrN = n[i] >> 31, s.cpsrZ = !(4294967295 & n[i]) + } +}, ARMCoreThumb.prototype.constructMVN = function(t, e) { + var i = this.cpu, + r = i.gprs; + return function() { + i.mmu.waitPrefetch(r[i.PC]), r[t] = ~r[e], i.cpsrN = r[t] >> 31, i.cpsrZ = !(4294967295 & r[t]) + } +}, ARMCoreThumb.prototype.constructNEG = function(e, i) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.waitPrefetch(s[r.PC]); + var t = -s[i]; + r.cpsrN = t >> 31, r.cpsrZ = !(4294967295 & t), r.cpsrC = t >>> 0 <= 0, r.cpsrV = s[i] >> 31 && t >> 31, s[e] = t + } +}, ARMCoreThumb.prototype.constructORR = function(t, e) { + var i = this.cpu, + r = i.gprs; + return function() { + i.mmu.waitPrefetch(r[i.PC]), r[t] = r[t] | r[e], i.cpsrN = r[t] >> 31, i.cpsrZ = !(4294967295 & r[t]) + } +}, ARMCoreThumb.prototype.constructPOP = function(s, n) { + var a = this.cpu, + o = a.gprs; + return function() { + a.mmu.waitPrefetch(o[a.PC]), ++a.cycles; + var t, e, i = o[a.SP], + r = 0; + for (t = 1, e = 0; e < 8; t <<= 1, ++e) s & t && (a.mmu.waitSeq32(i), o[e] = a.mmu.load32(i), i += 4, ++r); + n && (o[a.PC] = 4294967294 & a.mmu.load32(i), i += 4, ++r), a.mmu.waitMulti32(i, r), o[a.SP] = i + } +}, ARMCoreThumb.prototype.constructPUSH = function(s, n) { + var a = this.cpu, + o = a.gprs; + return function() { + var t, e, i = o[a.SP] - 4, + r = 0; + for (a.mmu.waitPrefetch(o[a.PC]), n && (a.mmu.store32(i, o[a.LR]), i -= 4, ++r), t = 128, e = 7; t; t >>= 1, --e) + if (s & t) { + a.mmu.store32(i, o[e]), i -= 4, ++r; + break + } + for (t >>= 1, --e; t; t >>= 1, --e) s & t && (a.mmu.store32(i, o[e]), i -= 4, ++r); + a.mmu.waitMulti32(i, r), o[a.SP] = i + 4 + } +}, ARMCoreThumb.prototype.constructROR = function(i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + s.mmu.waitPrefetch(n[s.PC]); + var t = 255 & n[r]; + if (t) { + var e = 31 & t; + 0 < e ? (s.cpsrC = n[i] & 1 << e - 1, n[i] = n[i] >>> e | n[i] << 32 - e) : s.cpsrC = n[i] >> 31 + } + s.cpsrN = n[i] >> 31, s.cpsrZ = !(4294967295 & n[i]) + } +}, ARMCoreThumb.prototype.constructSBC = function(i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + s.mmu.waitPrefetch(n[s.PC]); + var t = (n[r] >>> 0) + !s.cpsrC, + e = (n[i] >>> 0) - t; + s.cpsrN = e >> 31, s.cpsrZ = !(4294967295 & e), s.cpsrC = n[i] >>> 0 >= e >>> 0, s.cpsrV = (n[i] ^ t) >> 31 && (n[i] ^ e) >> 31, n[i] = e + } +}, ARMCoreThumb.prototype.constructSTMIA = function(s, n) { + var a = this.cpu, + o = a.gprs; + return function() { + a.mmu.wait(o[a.PC]); + var t, e, i = o[s], + r = 0; + for (t = 1, e = 0; e < 8; t <<= 1, ++e) + if (n & t) { + a.mmu.store32(i, o[e]), i += 4, ++r; + break + } + for (t <<= 1, ++e; e < 8; t <<= 1, ++e) n & t && (a.mmu.store32(i, o[e]), i += 4, ++r); + a.mmu.waitMulti32(i, r), o[s] = i + } +}, ARMCoreThumb.prototype.constructSTR1 = function(e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + var t = n[i] + r; + s.mmu.store32(t, n[e]), s.mmu.wait(n[s.PC]), s.mmu.wait32(t) + } +}, ARMCoreThumb.prototype.constructSTR2 = function(t, e, i) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.store32(s[e] + s[i], s[t]), r.mmu.wait(s[r.PC]), r.mmu.wait32(s[e] + s[i]) + } +}, ARMCoreThumb.prototype.constructSTR3 = function(t, e) { + var i = this.cpu, + r = i.gprs; + return function() { + i.mmu.store32(r[i.SP] + e, r[t]), i.mmu.wait(r[i.PC]), i.mmu.wait32(r[i.SP] + e) + } +}, ARMCoreThumb.prototype.constructSTRB1 = function(e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + var t = n[i] + r; + s.mmu.store8(t, n[e]), s.mmu.wait(n[s.PC]), s.mmu.wait(t) + } +}, ARMCoreThumb.prototype.constructSTRB2 = function(t, e, i) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.store8(s[e] + s[i], s[t]), r.mmu.wait(s[r.PC]), r.mmu.wait(s[e] + s[i]) + } +}, ARMCoreThumb.prototype.constructSTRH1 = function(e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + var t = n[i] + r; + s.mmu.store16(t, n[e]), s.mmu.wait(n[s.PC]), s.mmu.wait(t) + } +}, ARMCoreThumb.prototype.constructSTRH2 = function(t, e, i) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.store16(s[e] + s[i], s[t]), r.mmu.wait(s[r.PC]), r.mmu.wait(s[e] + s[i]) + } +}, ARMCoreThumb.prototype.constructSUB1 = function(e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + s.mmu.waitPrefetch(n[s.PC]); + var t = n[i] - r; + s.cpsrN = t >> 31, s.cpsrZ = !(4294967295 & t), s.cpsrC = n[i] >>> 0 >= r, s.cpsrV = n[i] >> 31 && (n[i] ^ t) >> 31, n[e] = t + } +}, ARMCoreThumb.prototype.constructSUB2 = function(e, i) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.waitPrefetch(s[r.PC]); + var t = s[e] - i; + r.cpsrN = t >> 31, r.cpsrZ = !(4294967295 & t), r.cpsrC = s[e] >>> 0 >= i, r.cpsrV = s[e] >> 31 && (s[e] ^ t) >> 31, s[e] = t + } +}, ARMCoreThumb.prototype.constructSUB3 = function(e, i, r) { + var s = this.cpu, + n = s.gprs; + return function() { + s.mmu.waitPrefetch(n[s.PC]); + var t = n[i] - n[r]; + s.cpsrN = t >> 31, s.cpsrZ = !(4294967295 & t), s.cpsrC = n[i] >>> 0 >= n[r] >>> 0, s.cpsrV = n[i] >> 31 != n[r] >> 31 && n[i] >> 31 != t >> 31, n[e] = t + } +}, ARMCoreThumb.prototype.constructSWI = function(t) { + var e = this.cpu, + i = e.gprs; + return function() { + e.irq.swi(t), e.mmu.waitPrefetch(i[e.PC]) + } +}, ARMCoreThumb.prototype.constructTST = function(e, i) { + var r = this.cpu, + s = r.gprs; + return function() { + r.mmu.waitPrefetch(s[r.PC]); + var t = s[e] & s[i]; + r.cpsrN = t >> 31, r.cpsrZ = !(4294967295 & t) + } +}, MemoryView.prototype.resetMask = function() { + this.mask8 = 4294967295 & this.mask, this.mask16 = 4294967294 & this.mask, this.mask32 = 4294967292 & this.mask +}, MemoryView.prototype.load8 = function(t) { + return this.view.getInt8(t & this.mask8) +}, MemoryView.prototype.load16 = function(t) { + return this.view.getInt16(t & this.mask, !0) +}, MemoryView.prototype.loadU8 = function(t) { + return this.view.getUint8(t & this.mask8) +}, MemoryView.prototype.loadU16 = function(t) { + return this.view.getUint16(t & this.mask, !0) +}, MemoryView.prototype.load32 = function(t) { + var e = (3 & t) << 3, + i = this.view.getInt32(t & this.mask32, !0); + return i >>> e | i << 32 - e +}, MemoryView.prototype.store8 = function(t, e) { + this.view.setInt8(t & this.mask8, e) +}, MemoryView.prototype.store16 = function(t, e) { + this.view.setInt16(t & this.mask16, e, !0) +}, MemoryView.prototype.store32 = function(t, e) { + this.view.setInt32(t & this.mask32, e, !0) +}, MemoryView.prototype.invalidatePage = function(t) {}, MemoryView.prototype.replaceData = function(t, e) { + this.buffer = t, this.view = new DataView(this.buffer, "number" == typeof e ? e : 0), this.icache && (this.icache = new Array(this.icache.length)) +}, MemoryBlock.prototype = Object.create(MemoryView.prototype), MemoryBlock.prototype.invalidatePage = function(t) { + var e = this.icache[(t & this.mask) >> this.ICACHE_PAGE_BITS]; + e && (e.invalid = !0) +}, ROMView.prototype = Object.create(MemoryView.prototype), ROMView.prototype.store8 = function(t, e) {}, ROMView.prototype.store16 = function(t, e) { + t < 202 && 196 <= t && (this.gpio || (this.gpio = this.mmu.allocGPIO(this)), this.gpio.store16(t, e)) +}, ROMView.prototype.store32 = function(t, e) { + t < 202 && 196 <= t && (this.gpio || (this.gpio = this.mmu.allocGPIO(this)), this.gpio.store32(t, e)) +}, BIOSView.prototype = Object.create(MemoryView.prototype), BIOSView.prototype.load8 = function(t) { + return t >= this.buffer.byteLength ? -1 : this.view.getInt8(t) +}, BIOSView.prototype.load16 = function(t) { + return t >= this.buffer.byteLength ? -1 : this.view.getInt16(t, !0) +}, BIOSView.prototype.loadU8 = function(t) { + return t >= this.buffer.byteLength ? -1 : this.view.getUint8(t) +}, BIOSView.prototype.loadU16 = function(t) { + return t >= this.buffer.byteLength ? -1 : this.view.getUint16(t, !0) +}, BIOSView.prototype.load32 = function(t) { + return t >= this.buffer.byteLength ? -1 : this.view.getInt32(t, !0) +}, BIOSView.prototype.store8 = function(t, e) {}, BIOSView.prototype.store16 = function(t, e) {}, BIOSView.prototype.store32 = function(t, e) {}, BadMemory.prototype.load8 = function(t) { + return this.mmu.load8(this.cpu.gprs[this.cpu.PC] - this.cpu.instructionWidth + (3 & t)) +}, BadMemory.prototype.load16 = function(t) { + return this.mmu.load16(this.cpu.gprs[this.cpu.PC] - this.cpu.instructionWidth + (2 & t)) +}, BadMemory.prototype.loadU8 = function(t) { + return this.mmu.loadU8(this.cpu.gprs[this.cpu.PC] - this.cpu.instructionWidth + (3 & t)) +}, BadMemory.prototype.loadU16 = function(t) { + return this.mmu.loadU16(this.cpu.gprs[this.cpu.PC] - this.cpu.instructionWidth + (2 & t)) +}, BadMemory.prototype.load32 = function(t) { + if (this.cpu.execMode == this.cpu.MODE_ARM) return this.mmu.load32(this.cpu.gprs[this.cpu.gprs.PC] - this.cpu.instructionWidth); + var e = this.mmu.loadU16(this.cpu.gprs[this.cpu.PC] - this.cpu.instructionWidth); + return e | e << 16 +}, BadMemory.prototype.store8 = function(t, e) {}, BadMemory.prototype.store16 = function(t, e) {}, BadMemory.prototype.store32 = function(t, e) {}, BadMemory.prototype.invalidatePage = function(t) {}, GameBoyAdvanceMMU.prototype.mmap = function(t, e) { + this.memory[t] = e +}, GameBoyAdvanceMMU.prototype.clear = function() { + this.badMemory = new BadMemory(this, this.cpu), this.memory = [this.bios, this.badMemory, new MemoryBlock(this.SIZE_WORKING_RAM, 9), new MemoryBlock(this.SIZE_WORKING_IRAM, 7), null, null, null, null, this.badMemory, this.badMemory, this.badMemory, this.badMemory, this.badMemory, this.badMemory, this.badMemory, this.badMemory]; + for (var t = 16; t < 256; ++t) this.memory[t] = this.badMemory; + this.waitstates = this.WAITSTATES.slice(0), this.waitstatesSeq = this.WAITSTATES_SEQ.slice(0), this.waitstates32 = this.WAITSTATES_32.slice(0), this.waitstatesSeq32 = this.WAITSTATES_SEQ_32.slice(0), this.waitstatesPrefetch = this.WAITSTATES_SEQ.slice(0), this.waitstatesPrefetch32 = this.WAITSTATES_SEQ_32.slice(0), this.cart = null, this.save = null, this.DMA_REGISTER = [this.core.io.DMA0CNT_HI >> 1, this.core.io.DMA1CNT_HI >> 1, this.core.io.DMA2CNT_HI >> 1, this.core.io.DMA3CNT_HI >> 1] +}, GameBoyAdvanceMMU.prototype.freeze = function() { + return { + ram: Serializer.prefix(this.memory[this.REGION_WORKING_RAM].buffer), + iram: Serializer.prefix(this.memory[this.REGION_WORKING_IRAM].buffer) + } +}, GameBoyAdvanceMMU.prototype.defrost = function(t) { + this.memory[this.REGION_WORKING_RAM].replaceData(t.ram), this.memory[this.REGION_WORKING_IRAM].replaceData(t.iram) +}, GameBoyAdvanceMMU.prototype.loadBios = function(t, e) { + this.bios = new BIOSView(t), this.bios.real = !!e +}, GameBoyAdvanceMMU.prototype.loadRom = function(t, e) { + var i = { + title: null, + code: null, + maker: null, + memory: t, + saveType: null + }, + r = new ROMView(t); + if (150 != r.view.getUint8(178)) return null; + if ((r.mmu = this).memory[this.REGION_CART0] = r, this.memory[this.REGION_CART1] = r, this.memory[this.REGION_CART2] = r, 16777216 < t.byteLength) { + var s = new ROMView(t, 16777216); + this.memory[this.REGION_CART0 + 1] = s, this.memory[this.REGION_CART1 + 1] = s, this.memory[this.REGION_CART2 + 1] = s + } + if (e) { + for (var n = "", a = 0; a < 12; ++a) { + if (!(c = r.loadU8(a + 160))) break; + n += String.fromCharCode(c) + } + i.title = n; + var o = ""; + for (a = 0; a < 4; ++a) { + if (!(c = r.loadU8(a + 172))) break; + o += String.fromCharCode(c) + } + i.code = o; + var h = ""; + for (a = 0; a < 2; ++a) { + var c; + if (!(c = r.loadU8(a + 176))) break; + h += String.fromCharCode(c) + } + i.maker = h; + var u, d = "", + p = !1; + for (a = 228; a < t.byteLength && !p; ++a) switch (d += u = String.fromCharCode(r.loadU8(a))) { + case "F": + case "FL": + case "FLA": + case "FLAS": + case "FLASH": + case "FLASH_": + case "FLASH5": + case "FLASH51": + case "FLASH512": + case "FLASH512_": + case "FLASH1": + case "FLASH1M": + case "FLASH1M_": + case "S": + case "SR": + case "SRA": + case "SRAM": + case "SRAM_": + case "E": + case "EE": + case "EEP": + case "EEPR": + case "EEPRO": + case "EEPROM": + case "EEPROM_": + break; + case "FLASH_V": + case "FLASH512_V": + case "FLASH1M_V": + case "SRAM_V": + case "EEPROM_V": + p = !0; + break; + default: + d = u + } + if (p) switch (i.saveType = d) { + case "FLASH_V": + case "FLASH512_V": + this.save = this.memory[this.REGION_CART_SRAM] = new FlashSavedata(this.SIZE_CART_FLASH512); + break; + case "FLASH1M_V": + this.save = this.memory[this.REGION_CART_SRAM] = new FlashSavedata(this.SIZE_CART_FLASH1M); + break; + case "SRAM_V": + this.save = this.memory[this.REGION_CART_SRAM] = new SRAMSavedata(this.SIZE_CART_SRAM); + break; + case "EEPROM_V": + this.save = this.memory[this.REGION_CART2 + 1] = new EEPROMSavedata(this.SIZE_CART_EEPROM, this) + } + this.save || (this.save = this.memory[this.REGION_CART_SRAM] = new SRAMSavedata(this.SIZE_CART_SRAM)) + } + return this.cart = i +}, GameBoyAdvanceMMU.prototype.loadSavedata = function(t) { + this.save.replaceData(t) +}, GameBoyAdvanceMMU.prototype.load8 = function(t) { + return this.memory[t >>> this.BASE_OFFSET].load8(16777215 & t) +}, GameBoyAdvanceMMU.prototype.load16 = function(t) { + return this.memory[t >>> this.BASE_OFFSET].load16(16777215 & t) +}, GameBoyAdvanceMMU.prototype.load32 = function(t) { + return this.memory[t >>> this.BASE_OFFSET].load32(16777215 & t) +}, GameBoyAdvanceMMU.prototype.loadU8 = function(t) { + return this.memory[t >>> this.BASE_OFFSET].loadU8(16777215 & t) +}, GameBoyAdvanceMMU.prototype.loadU16 = function(t) { + return this.memory[t >>> this.BASE_OFFSET].loadU16(16777215 & t) +}, GameBoyAdvanceMMU.prototype.store8 = function(t, e) { + var i = 16777215 & t, + r = this.memory[t >>> this.BASE_OFFSET]; + r.store8(i, e), r.invalidatePage(i) +}, GameBoyAdvanceMMU.prototype.store16 = function(t, e) { + var i = 16777214 & t, + r = this.memory[t >>> this.BASE_OFFSET]; + r.store16(i, e), r.invalidatePage(i) +}, GameBoyAdvanceMMU.prototype.store32 = function(t, e) { + var i = 16777212 & t, + r = this.memory[t >>> this.BASE_OFFSET]; + r.store32(i, e), r.invalidatePage(i), r.invalidatePage(i + 2) +}, GameBoyAdvanceMMU.prototype.waitPrefetch = function(t) { + this.cpu.cycles += 1 + this.waitstatesPrefetch[t >>> this.BASE_OFFSET] +}, GameBoyAdvanceMMU.prototype.waitPrefetch32 = function(t) { + this.cpu.cycles += 1 + this.waitstatesPrefetch32[t >>> this.BASE_OFFSET] +}, GameBoyAdvanceMMU.prototype.wait = function(t) { + this.cpu.cycles += 1 + this.waitstates[t >>> this.BASE_OFFSET] +}, GameBoyAdvanceMMU.prototype.wait32 = function(t) { + this.cpu.cycles += 1 + this.waitstates32[t >>> this.BASE_OFFSET] +}, GameBoyAdvanceMMU.prototype.waitSeq = function(t) { + this.cpu.cycles += 1 + this.waitstatesSeq[t >>> this.BASE_OFFSET] +}, GameBoyAdvanceMMU.prototype.waitSeq32 = function(t) { + this.cpu.cycles += 1 + this.waitstatesSeq32[t >>> this.BASE_OFFSET] +}, GameBoyAdvanceMMU.prototype.waitMul = function(t) { + this.cpu.cycles += !0 & t || !(4294967040 & t) ? 1 : !0 & t || !(4294901760 & t) ? 2 : !0 & t || !(4278190080 & t) ? 3 : 4 +}, GameBoyAdvanceMMU.prototype.waitMulti32 = function(t, e) { + this.cpu.cycles += 1 + this.waitstates32[t >>> this.BASE_OFFSET], this.cpu.cycles += (1 + this.waitstatesSeq32[t >>> this.BASE_OFFSET]) * (e - 1) +}, GameBoyAdvanceMMU.prototype.addressToPage = function(t, e) { + return e >> this.memory[t].ICACHE_PAGE_BITS +}, GameBoyAdvanceMMU.prototype.accessPage = function(t, e) { + var i = this.memory[t], + r = i.icache[e]; + return r && !r.invalid || (r = { + thumb: new Array(1 << i.ICACHE_PAGE_BITS), + arm: new Array(1 << i.ICACHE_PAGE_BITS - 1), + invalid: !1 + }, i.icache[e] = r), r +}, GameBoyAdvanceMMU.prototype.scheduleDma = function(t, e) { + switch (e.timing) { + case this.DMA_TIMING_NOW: + this.serviceDma(t, e); + break; + case this.DMA_TIMING_HBLANK: + case this.DMA_TIMING_VBLANK: + break; + case this.DMA_TIMING_CUSTOM: + switch (t) { + case 0: + this.core.WARN("Discarding invalid DMA0 scheduling"); + break; + case 1: + case 2: + this.cpu.irq.audio.scheduleFIFODma(t, e); + break; + case 3: + this.cpu.irq.video.scheduleVCaptureDma(dma, e) + } + } +}, GameBoyAdvanceMMU.prototype.runHblankDmas = function() { + for (var t, e = 0; e < this.cpu.irq.dma.length; ++e)(t = this.cpu.irq.dma[e]).enable && t.timing == this.DMA_TIMING_HBLANK && this.serviceDma(e, t) +}, GameBoyAdvanceMMU.prototype.runVblankDmas = function() { + for (var t, e = 0; e < this.cpu.irq.dma.length; ++e)(t = this.cpu.irq.dma[e]).enable && t.timing == this.DMA_TIMING_VBLANK && this.serviceDma(e, t) +}, GameBoyAdvanceMMU.prototype.serviceDma = function(t, e) { + if (e.enable) { + var i, r = e.width, + s = this.DMA_OFFSET[e.srcControl] * r, + n = this.DMA_OFFSET[e.dstControl] * r, + a = e.nextCount, + o = e.nextSource & this.OFFSET_MASK, + h = e.nextDest & this.OFFSET_MASK, + c = e.nextSource >>> this.BASE_OFFSET, + u = e.nextDest >>> this.BASE_OFFSET, + d = this.memory[c], + p = this.memory[u], + l = null, + f = null, + m = 4294967295, + y = 4294967295; + if (p.ICACHE_PAGE_BITS) + for (var v = h + a * r >> p.ICACHE_PAGE_BITS, A = h >> p.ICACHE_PAGE_BITS; A <= v; ++A) p.invalidatePage(A << p.ICACHE_PAGE_BITS); + if (u != this.REGION_WORKING_RAM && u != this.REGION_WORKING_IRAM || (f = p.view, y = p.mask), c != this.REGION_WORKING_RAM && c != this.REGION_WORKING_IRAM && c != this.REGION_CART0 && c != this.REGION_CART1 || (l = d.view, m = d.mask), d && p) + if (l && f) + if (4 == r) + for (o &= 4294967292, h &= 4294967292; a--;) i = l.getInt32(o & m), f.setInt32(h & y, i), o += s, h += n; + else + for (; a--;) i = l.getUint16(o & m), f.setUint16(h & y, i), o += s, h += n; + else if (l) + if (4 == r) + for (o &= 4294967292, h &= 4294967292; a--;) i = l.getInt32(o & m, !0), p.store32(h, i), o += s, h += n; + else + for (; a--;) i = l.getUint16(o & m, !0), p.store16(h, i), o += s, h += n; + else if (4 == r) + for (o &= 4294967292, h &= 4294967292; a--;) i = d.load32(o), p.store32(h, i), o += s, h += n; + else + for (; a--;) i = d.loadU16(o), p.store16(h, i), o += s, h += n; + else this.core.WARN("Invalid DMA"); if (e.doIrq && (e.nextIRQ = this.cpu.cycles + 2, e.nextIRQ += 4 == r ? this.waitstates32[c] + this.waitstates32[u] : this.waitstates[c] + this.waitstates[u], e.nextIRQ += (e.count - 1) * (4 == r ? this.waitstatesSeq32[c] + this.waitstatesSeq32[u] : this.waitstatesSeq[c] + this.waitstatesSeq[u])), e.nextSource = o | c << this.BASE_OFFSET, e.nextDest = h | u << this.BASE_OFFSET, e.nextCount = a, e.repeat) e.nextCount = e.count, e.dstControl == this.DMA_INCREMENT_RELOAD && (e.nextDest = e.dest), this.scheduleDma(t, e); + else e.enable = !1, this.memory[this.REGION_IO].registers[this.DMA_REGISTER[t]] &= 32736 + } +}, GameBoyAdvanceMMU.prototype.adjustTimings = function(t) { + var e = 3 & t, + i = (12 & t) >> 2, + r = (16 & t) >> 4, + s = (96 & t) >> 5, + n = (128 & t) >> 7, + a = (768 & t) >> 8, + o = (1024 & t) >> 10, + h = 16384 & t; + this.waitstates[this.REGION_CART_SRAM] = this.ROM_WS[e], this.waitstatesSeq[this.REGION_CART_SRAM] = this.ROM_WS[e], this.waitstates32[this.REGION_CART_SRAM] = this.ROM_WS[e], this.waitstatesSeq32[this.REGION_CART_SRAM] = this.ROM_WS[e], this.waitstates[this.REGION_CART0] = this.waitstates[this.REGION_CART0 + 1] = this.ROM_WS[i], this.waitstates[this.REGION_CART1] = this.waitstates[this.REGION_CART1 + 1] = this.ROM_WS[s], this.waitstates[this.REGION_CART2] = this.waitstates[this.REGION_CART2 + 1] = this.ROM_WS[a], this.waitstatesSeq[this.REGION_CART0] = this.waitstatesSeq[this.REGION_CART0 + 1] = this.ROM_WS_SEQ[0][r], this.waitstatesSeq[this.REGION_CART1] = this.waitstatesSeq[this.REGION_CART1 + 1] = this.ROM_WS_SEQ[1][n], this.waitstatesSeq[this.REGION_CART2] = this.waitstatesSeq[this.REGION_CART2 + 1] = this.ROM_WS_SEQ[2][o], this.waitstates32[this.REGION_CART0] = this.waitstates32[this.REGION_CART0 + 1] = this.waitstates[this.REGION_CART0] + 1 + this.waitstatesSeq[this.REGION_CART0], this.waitstates32[this.REGION_CART1] = this.waitstates32[this.REGION_CART1 + 1] = this.waitstates[this.REGION_CART1] + 1 + this.waitstatesSeq[this.REGION_CART1], this.waitstates32[this.REGION_CART2] = this.waitstates32[this.REGION_CART2 + 1] = this.waitstates[this.REGION_CART2] + 1 + this.waitstatesSeq[this.REGION_CART2], this.waitstatesSeq32[this.REGION_CART0] = this.waitstatesSeq32[this.REGION_CART0 + 1] = 2 * this.waitstatesSeq[this.REGION_CART0] + 1, this.waitstatesSeq32[this.REGION_CART1] = this.waitstatesSeq32[this.REGION_CART1 + 1] = 2 * this.waitstatesSeq[this.REGION_CART1] + 1, this.waitstatesSeq32[this.REGION_CART2] = this.waitstatesSeq32[this.REGION_CART2 + 1] = 2 * this.waitstatesSeq[this.REGION_CART2] + 1, h ? (this.waitstatesPrefetch[this.REGION_CART0] = this.waitstatesPrefetch[this.REGION_CART0 + 1] = 0, this.waitstatesPrefetch[this.REGION_CART1] = this.waitstatesPrefetch[this.REGION_CART1 + 1] = 0, this.waitstatesPrefetch[this.REGION_CART2] = this.waitstatesPrefetch[this.REGION_CART2 + 1] = 0, this.waitstatesPrefetch32[this.REGION_CART0] = this.waitstatesPrefetch32[this.REGION_CART0 + 1] = 0, this.waitstatesPrefetch32[this.REGION_CART1] = this.waitstatesPrefetch32[this.REGION_CART1 + 1] = 0, this.waitstatesPrefetch32[this.REGION_CART2] = this.waitstatesPrefetch32[this.REGION_CART2 + 1] = 0) : (this.waitstatesPrefetch[this.REGION_CART0] = this.waitstatesPrefetch[this.REGION_CART0 + 1] = this.waitstatesSeq[this.REGION_CART0], this.waitstatesPrefetch[this.REGION_CART1] = this.waitstatesPrefetch[this.REGION_CART1 + 1] = this.waitstatesSeq[this.REGION_CART1], this.waitstatesPrefetch[this.REGION_CART2] = this.waitstatesPrefetch[this.REGION_CART2 + 1] = this.waitstatesSeq[this.REGION_CART2], this.waitstatesPrefetch32[this.REGION_CART0] = this.waitstatesPrefetch32[this.REGION_CART0 + 1] = this.waitstatesSeq32[this.REGION_CART0], this.waitstatesPrefetch32[this.REGION_CART1] = this.waitstatesPrefetch32[this.REGION_CART1 + 1] = this.waitstatesSeq32[this.REGION_CART1], this.waitstatesPrefetch32[this.REGION_CART2] = this.waitstatesPrefetch32[this.REGION_CART2 + 1] = this.waitstatesSeq32[this.REGION_CART2]) +}, GameBoyAdvanceMMU.prototype.saveNeedsFlush = function() { + return this.save.writePending +}, GameBoyAdvanceMMU.prototype.flushSave = function() { + this.save.writePending = !1 +}, GameBoyAdvanceMMU.prototype.allocGPIO = function(t) { + return new GameBoyAdvanceGPIO(this.core, t) +}, GameBoyAdvanceIO.prototype.clear = function() { + this.registers = new Uint16Array(this.cpu.mmu.SIZE_IO), this.registers[this.DISPCNT >> 1] = this.DEFAULT_DISPCNT, this.registers[this.SOUNDBIAS >> 1] = this.DEFAULT_SOUNDBIAS, this.registers[this.BG2PA >> 1] = this.DEFAULT_BGPA, this.registers[this.BG2PD >> 1] = this.DEFAULT_BGPD, this.registers[this.BG3PA >> 1] = this.DEFAULT_BGPA, this.registers[this.BG3PD >> 1] = this.DEFAULT_BGPD, this.registers[this.RCNT >> 1] = this.DEFAULT_RCNT +}, GameBoyAdvanceIO.prototype.freeze = function() { + return { + registers: Serializer.prefix(this.registers.buffer) + } +}, GameBoyAdvanceIO.prototype.defrost = function(t) { + this.registers = new Uint16Array(t.registers); + for (var e = 0; e <= this.BLDY; e += 2) this.store16(this.registers[e >> 1]) +}, GameBoyAdvanceIO.prototype.load8 = function(t) { + throw "Unimplmeneted unaligned I/O access" +}, GameBoyAdvanceIO.prototype.load16 = function(t) { + return this.loadU16(t) << 16 >> 16 +}, GameBoyAdvanceIO.prototype.load32 = function(t) { + switch (t &= 4294967292) { + case this.DMA0CNT_LO: + case this.DMA1CNT_LO: + case this.DMA2CNT_LO: + case this.DMA3CNT_LO: + return this.loadU16(2 | t) << 16; + case this.IME: + return 65535 & this.loadU16(t); + case this.JOY_RECV: + case this.JOY_TRANS: + return this.core.STUB("Unimplemented JOY register read: 0x" + t.toString(16)), 0 + } + return this.loadU16(t) | this.loadU16(2 | t) << 16 +}, GameBoyAdvanceIO.prototype.loadU8 = function(t) { + var e = 1 & t; + return this.loadU16(65534 & t) >>> (e << 3) & 255 +}, GameBoyAdvanceIO.prototype.loadU16 = function(t) { + switch (t) { + case this.DISPCNT: + case this.BG0CNT: + case this.BG1CNT: + case this.BG2CNT: + case this.BG3CNT: + case this.WININ: + case this.WINOUT: + case this.SOUND1CNT_LO: + case this.SOUND3CNT_LO: + case this.SOUNDCNT_LO: + case this.SOUNDCNT_HI: + case this.SOUNDBIAS: + case this.BLDCNT: + case this.BLDALPHA: + case this.TM0CNT_HI: + case this.TM1CNT_HI: + case this.TM2CNT_HI: + case this.TM3CNT_HI: + case this.DMA0CNT_HI: + case this.DMA1CNT_HI: + case this.DMA2CNT_HI: + case this.DMA3CNT_HI: + case this.RCNT: + case this.WAITCNT: + case this.IE: + case this.IF: + case this.IME: + case this.POSTFLG: + break; + case this.DISPSTAT: + return this.registers[t >> 1] | this.video.readDisplayStat(); + case this.VCOUNT: + return this.video.vcount; + case this.SOUND1CNT_HI: + case this.SOUND2CNT_LO: + return 65472 & this.registers[t >> 1]; + case this.SOUND1CNT_X: + case this.SOUND2CNT_HI: + case this.SOUND3CNT_X: + return 16384 & this.registers[t >> 1]; + case this.SOUND3CNT_HI: + return 57344 & this.registers[t >> 1]; + case this.SOUND4CNT_LO: + return 65280 & this.registers[t >> 1]; + case this.SOUND4CNT_HI: + return 16639 & this.registers[t >> 1]; + case this.SOUNDCNT_X: + return this.core.STUB("Unimplemented sound register read: SOUNDCNT_X"), 0 | this.registers[t >> 1]; + case this.TM0CNT_LO: + return this.cpu.irq.timerRead(0); + case this.TM1CNT_LO: + return this.cpu.irq.timerRead(1); + case this.TM2CNT_LO: + return this.cpu.irq.timerRead(2); + case this.TM3CNT_LO: + return this.cpu.irq.timerRead(3); + case this.SIOCNT: + return this.sio.readSIOCNT(); + case this.KEYINPUT: + return this.keypad.pollGamepads(), this.keypad.currentDown; + case this.KEYCNT: + return this.core.STUB("Unimplemented I/O register read: KEYCNT"), 0; + case this.BG0HOFS: + case this.BG0VOFS: + case this.BG1HOFS: + case this.BG1VOFS: + case this.BG2HOFS: + case this.BG2VOFS: + case this.BG3HOFS: + case this.BG3VOFS: + case this.BG2PA: + case this.BG2PB: + case this.BG2PC: + case this.BG2PD: + case this.BG3PA: + case this.BG3PB: + case this.BG3PC: + case this.BG3PD: + case this.BG2X_LO: + case this.BG2X_HI: + case this.BG2Y_LO: + case this.BG2Y_HI: + case this.BG3X_LO: + case this.BG3X_HI: + case this.BG3Y_LO: + case this.BG3Y_HI: + case this.WIN0H: + case this.WIN1H: + case this.WIN0V: + case this.WIN1V: + case this.BLDY: + case this.DMA0SAD_LO: + case this.DMA0SAD_HI: + case this.DMA0DAD_LO: + case this.DMA0DAD_HI: + case this.DMA0CNT_LO: + case this.DMA1SAD_LO: + case this.DMA1SAD_HI: + case this.DMA1DAD_LO: + case this.DMA1DAD_HI: + case this.DMA1CNT_LO: + case this.DMA2SAD_LO: + case this.DMA2SAD_HI: + case this.DMA2DAD_LO: + case this.DMA2DAD_HI: + case this.DMA2CNT_LO: + case this.DMA3SAD_LO: + case this.DMA3SAD_HI: + case this.DMA3DAD_LO: + case this.DMA3DAD_HI: + case this.DMA3CNT_LO: + case this.FIFO_A_LO: + case this.FIFO_A_HI: + case this.FIFO_B_LO: + case this.FIFO_B_HI: + return this.core.WARN("Read for write-only register: 0x" + t.toString(16)), this.core.mmu.badMemory.loadU16(0); + case this.MOSAIC: + return this.core.WARN("Read for write-only register: 0x" + t.toString(16)), 0; + case this.SIOMULTI0: + case this.SIOMULTI1: + case this.SIOMULTI2: + case this.SIOMULTI3: + return this.sio.read(t - this.SIOMULTI0 >> 1); + case this.SIODATA8: + return this.core.STUB("Unimplemented SIO register read: 0x" + t.toString(16)), 0; + case this.JOYCNT: + case this.JOYSTAT: + return this.core.STUB("Unimplemented JOY register read: 0x" + t.toString(16)), 0; + default: + return this.core.WARN("Bad I/O register read: 0x" + t.toString(16)), this.core.mmu.badMemory.loadU16(0) + } + return this.registers[t >> 1] +}, GameBoyAdvanceIO.prototype.store8 = function(t, e) { + switch (t) { + case this.WININ: + case 1 | this.WININ: + case this.WINOUT: + case 1 | this.WINOUT: + this.value; + break; + case this.SOUND1CNT_LO: + case 1 | this.SOUND1CNT_LO: + case this.SOUND1CNT_HI: + case 1 | this.SOUND1CNT_HI: + case this.SOUND1CNT_X: + case 1 | this.SOUND1CNT_X: + case this.SOUND2CNT_LO: + case 1 | this.SOUND2CNT_LO: + case this.SOUND2CNT_HI: + case 1 | this.SOUND2CNT_HI: + case this.SOUND3CNT_LO: + case 1 | this.SOUND3CNT_LO: + case this.SOUND3CNT_HI: + case 1 | this.SOUND3CNT_HI: + case this.SOUND3CNT_X: + case 1 | this.SOUND3CNT_X: + case this.SOUND4CNT_LO: + case 1 | this.SOUND4CNT_LO: + case this.SOUND4CNT_HI: + case 1 | this.SOUND4CNT_HI: + case this.SOUNDCNT_LO: + case 1 | this.SOUNDCNT_LO: + case this.SOUNDCNT_X: + case this.IF: + case this.IME: + break; + case 1 | this.SOUNDBIAS: + this.STUB_REG("sound", t); + break; + case this.HALTCNT: + return void((e &= 128) ? this.core.STUB("Stop") : this.core.irq.halt()); + default: + this.STUB_REG("8-bit I/O", t) + } + 1 & t ? (e <<= 8, e |= 255 & this.registers[t >> 1]) : (e &= 255, e |= 65280 & this.registers[t >> 1]), this.store16(268435454 & t, e) +}, GameBoyAdvanceIO.prototype.store16 = function(t, e) { + switch (t) { + case this.DISPCNT: + this.video.renderPath.writeDisplayControl(e); + break; + case this.DISPSTAT: + e &= this.video.DISPSTAT_MASK, this.video.writeDisplayStat(e); + break; + case this.BG0CNT: + this.video.renderPath.writeBackgroundControl(0, e); + break; + case this.BG1CNT: + this.video.renderPath.writeBackgroundControl(1, e); + break; + case this.BG2CNT: + this.video.renderPath.writeBackgroundControl(2, e); + break; + case this.BG3CNT: + this.video.renderPath.writeBackgroundControl(3, e); + break; + case this.BG0HOFS: + this.video.renderPath.writeBackgroundHOffset(0, e); + break; + case this.BG0VOFS: + this.video.renderPath.writeBackgroundVOffset(0, e); + break; + case this.BG1HOFS: + this.video.renderPath.writeBackgroundHOffset(1, e); + break; + case this.BG1VOFS: + this.video.renderPath.writeBackgroundVOffset(1, e); + break; + case this.BG2HOFS: + this.video.renderPath.writeBackgroundHOffset(2, e); + break; + case this.BG2VOFS: + this.video.renderPath.writeBackgroundVOffset(2, e); + break; + case this.BG3HOFS: + this.video.renderPath.writeBackgroundHOffset(3, e); + break; + case this.BG3VOFS: + this.video.renderPath.writeBackgroundVOffset(3, e); + break; + case this.BG2X_LO: + this.video.renderPath.writeBackgroundRefX(2, this.registers[t >> 1 | 1] << 16 | e); + break; + case this.BG2X_HI: + this.video.renderPath.writeBackgroundRefX(2, this.registers[t >> 1 ^ 1] | e << 16); + break; + case this.BG2Y_LO: + this.video.renderPath.writeBackgroundRefY(2, this.registers[t >> 1 | 1] << 16 | e); + break; + case this.BG2Y_HI: + this.video.renderPath.writeBackgroundRefY(2, this.registers[t >> 1 ^ 1] | e << 16); + break; + case this.BG2PA: + this.video.renderPath.writeBackgroundParamA(2, e); + break; + case this.BG2PB: + this.video.renderPath.writeBackgroundParamB(2, e); + break; + case this.BG2PC: + this.video.renderPath.writeBackgroundParamC(2, e); + break; + case this.BG2PD: + this.video.renderPath.writeBackgroundParamD(2, e); + break; + case this.BG3X_LO: + this.video.renderPath.writeBackgroundRefX(3, this.registers[t >> 1 | 1] << 16 | e); + break; + case this.BG3X_HI: + this.video.renderPath.writeBackgroundRefX(3, this.registers[t >> 1 ^ 1] | e << 16); + break; + case this.BG3Y_LO: + this.video.renderPath.writeBackgroundRefY(3, this.registers[t >> 1 | 1] << 16 | e); + break; + case this.BG3Y_HI: + this.video.renderPath.writeBackgroundRefY(3, this.registers[t >> 1 ^ 1] | e << 16); + break; + case this.BG3PA: + this.video.renderPath.writeBackgroundParamA(3, e); + break; + case this.BG3PB: + this.video.renderPath.writeBackgroundParamB(3, e); + break; + case this.BG3PC: + this.video.renderPath.writeBackgroundParamC(3, e); + break; + case this.BG3PD: + this.video.renderPath.writeBackgroundParamD(3, e); + break; + case this.WIN0H: + this.video.renderPath.writeWin0H(e); + break; + case this.WIN1H: + this.video.renderPath.writeWin1H(e); + break; + case this.WIN0V: + this.video.renderPath.writeWin0V(e); + break; + case this.WIN1V: + this.video.renderPath.writeWin1V(e); + break; + case this.WININ: + e &= 16191, this.video.renderPath.writeWinIn(e); + break; + case this.WINOUT: + e &= 16191, this.video.renderPath.writeWinOut(e); + break; + case this.BLDCNT: + e &= 32767, this.video.renderPath.writeBlendControl(e); + break; + case this.BLDALPHA: + e &= 7967, this.video.renderPath.writeBlendAlpha(e); + break; + case this.BLDY: + e &= 31, this.video.renderPath.writeBlendY(e); + break; + case this.MOSAIC: + this.video.renderPath.writeMosaic(e); + break; + case this.SOUND1CNT_LO: + e &= 127, this.audio.writeSquareChannelSweep(0, e); + break; + case this.SOUND1CNT_HI: + this.audio.writeSquareChannelDLE(0, e); + break; + case this.SOUND1CNT_X: + e &= 51199, this.audio.writeSquareChannelFC(0, e), e &= -32769; + break; + case this.SOUND2CNT_LO: + this.audio.writeSquareChannelDLE(1, e); + break; + case this.SOUND2CNT_HI: + e &= 51199, this.audio.writeSquareChannelFC(1, e), e &= -32769; + break; + case this.SOUND3CNT_LO: + e &= 224, this.audio.writeChannel3Lo(e); + break; + case this.SOUND3CNT_HI: + e &= 57599, this.audio.writeChannel3Hi(e); + break; + case this.SOUND3CNT_X: + e &= 51199, this.audio.writeChannel3X(e), e &= -32769; + break; + case this.SOUND4CNT_LO: + e &= 65343, this.audio.writeChannel4LE(e); + break; + case this.SOUND4CNT_HI: + e &= 49407, this.audio.writeChannel4FC(e), e &= -32769; + break; + case this.SOUNDCNT_LO: + e &= 65399, this.audio.writeSoundControlLo(e); + break; + case this.SOUNDCNT_HI: + e &= 65295, this.audio.writeSoundControlHi(e); + break; + case this.SOUNDCNT_X: + e &= 128, this.audio.writeEnable(e); + break; + case this.WAVE_RAM0_LO: + case this.WAVE_RAM0_HI: + case this.WAVE_RAM1_LO: + case this.WAVE_RAM1_HI: + case this.WAVE_RAM2_LO: + case this.WAVE_RAM2_HI: + case this.WAVE_RAM3_LO: + case this.WAVE_RAM3_HI: + this.audio.writeWaveData(t - this.WAVE_RAM0_LO, e, 2); + break; + case this.DMA0SAD_LO: + case this.DMA0DAD_LO: + case this.DMA1SAD_LO: + case this.DMA1DAD_LO: + case this.DMA2SAD_LO: + case this.DMA2DAD_LO: + case this.DMA3SAD_LO: + case this.DMA3DAD_LO: + return void this.store32(t, this.registers[1 + (t >> 1)] << 16 | e); + case this.DMA0SAD_HI: + case this.DMA0DAD_HI: + case this.DMA1SAD_HI: + case this.DMA1DAD_HI: + case this.DMA2SAD_HI: + case this.DMA2DAD_HI: + case this.DMA3SAD_HI: + case this.DMA3DAD_HI: + return void this.store32(t - 2, this.registers[(t >> 1) - 1] | e << 16); + case this.DMA0CNT_LO: + this.cpu.irq.dmaSetWordCount(0, e); + break; + case this.DMA0CNT_HI: + return this.registers[t >> 1] = 65504 & e, void this.cpu.irq.dmaWriteControl(0, e); + case this.DMA1CNT_LO: + this.cpu.irq.dmaSetWordCount(1, e); + break; + case this.DMA1CNT_HI: + return this.registers[t >> 1] = 65504 & e, void this.cpu.irq.dmaWriteControl(1, e); + case this.DMA2CNT_LO: + this.cpu.irq.dmaSetWordCount(2, e); + break; + case this.DMA2CNT_HI: + return this.registers[t >> 1] = 65504 & e, void this.cpu.irq.dmaWriteControl(2, e); + case this.DMA3CNT_LO: + this.cpu.irq.dmaSetWordCount(3, e); + break; + case this.DMA3CNT_HI: + return this.registers[t >> 1] = 65504 & e, void this.cpu.irq.dmaWriteControl(3, e); + case this.TM0CNT_LO: + return void this.cpu.irq.timerSetReload(0, e); + case this.TM1CNT_LO: + return void this.cpu.irq.timerSetReload(1, e); + case this.TM2CNT_LO: + return void this.cpu.irq.timerSetReload(2, e); + case this.TM3CNT_LO: + return void this.cpu.irq.timerSetReload(3, e); + case this.TM0CNT_HI: + e &= 199, this.cpu.irq.timerWriteControl(0, e); + break; + case this.TM1CNT_HI: + e &= 199, this.cpu.irq.timerWriteControl(1, e); + break; + case this.TM2CNT_HI: + e &= 199, this.cpu.irq.timerWriteControl(2, e); + break; + case this.TM3CNT_HI: + e &= 199, this.cpu.irq.timerWriteControl(3, e); + break; + case this.SIOMULTI0: + case this.SIOMULTI1: + case this.SIOMULTI2: + case this.SIOMULTI3: + case this.SIODATA8: + this.STUB_REG("SIO", t); + break; + case this.RCNT: + this.sio.setMode(e >> 12 & 12 | this.registers[this.SIOCNT >> 1] >> 12 & 3), this.sio.writeRCNT(e); + break; + case this.SIOCNT: + return this.sio.setMode(e >> 12 & 3 | this.registers[this.RCNT >> 1] >> 12 & 12), void this.sio.writeSIOCNT(e); + case this.JOYCNT: + case this.JOYSTAT: + this.STUB_REG("JOY", t); + break; + case this.IE: + e &= 16383, this.cpu.irq.setInterruptsEnabled(e); + break; + case this.IF: + return void this.cpu.irq.dismissIRQs(e); + case this.WAITCNT: + e &= 57343, this.cpu.mmu.adjustTimings(e); + break; + case this.IME: + e &= 1, this.cpu.irq.masterEnable(e); + break; + default: + this.STUB_REG("I/O", t) + } + this.registers[t >> 1] = e +}, GameBoyAdvanceIO.prototype.store32 = function(t, e) { + switch (t) { + case this.BG2X_LO: + e &= 268435455, this.video.renderPath.writeBackgroundRefX(2, e); + break; + case this.BG2Y_LO: + e &= 268435455, this.video.renderPath.writeBackgroundRefY(2, e); + break; + case this.BG3X_LO: + e &= 268435455, this.video.renderPath.writeBackgroundRefX(3, e); + break; + case this.BG3Y_LO: + e &= 268435455, this.video.renderPath.writeBackgroundRefY(3, e); + break; + case this.DMA0SAD_LO: + this.cpu.irq.dmaSetSourceAddress(0, e); + break; + case this.DMA0DAD_LO: + this.cpu.irq.dmaSetDestAddress(0, e); + break; + case this.DMA1SAD_LO: + this.cpu.irq.dmaSetSourceAddress(1, e); + break; + case this.DMA1DAD_LO: + this.cpu.irq.dmaSetDestAddress(1, e); + break; + case this.DMA2SAD_LO: + this.cpu.irq.dmaSetSourceAddress(2, e); + break; + case this.DMA2DAD_LO: + this.cpu.irq.dmaSetDestAddress(2, e); + break; + case this.DMA3SAD_LO: + this.cpu.irq.dmaSetSourceAddress(3, e); + break; + case this.DMA3DAD_LO: + this.cpu.irq.dmaSetDestAddress(3, e); + break; + case this.FIFO_A_LO: + return void this.audio.appendToFifoA(e); + case this.FIFO_B_LO: + return void this.audio.appendToFifoB(e); + case this.IME: + return void this.store16(t, 65535 & e); + case this.JOY_RECV: + case this.JOY_TRANS: + return void this.STUB_REG("JOY", t); + default: + return this.store16(t, 65535 & e), void this.store16(2 | t, e >>> 16) + } + this.registers[t >> 1] = 65535 & e, this.registers[1 + (t >> 1)] = e >>> 16 +}, GameBoyAdvanceIO.prototype.invalidatePage = function(t) {}, GameBoyAdvanceIO.prototype.STUB_REG = function(t, e) { + this.core.STUB("Unimplemented " + t + " register write: " + e.toString(16)) +}, GameBoyAdvanceAudio.prototype.initAudio = function() { + var e = this; + return e.isInit && e.context && (e.jsAudio = this.context.createScriptProcessor(e.bufferSize), e.jsAudio.onaudioprocess = function(t) { + e.audioProcess(t) + }, e.jsAudio.connect(e.context.destination)), !!e.jsAudio +}, GameBoyAdvanceAudio.prototype.clear = function() { + if (this.fifoA = [], this.fifoB = [], this.fifoASample = 0, this.fifoBSample = 0, this.enabled = !1, this.context) try { + this.jsAudio.disconnect(this.context.destination) + } catch (t) {} + this.enableChannel3 = !1, this.enableChannel4 = !1, this.enableChannelA = !1, this.enableChannelB = !1, this.enableRightChannelA = !1, this.enableLeftChannelA = !1, this.enableRightChannelB = !1, this.enableLeftChannelB = !1, this.playingChannel3 = !1, this.playingChannel4 = !1, this.volumeLeft = 0, this.volumeRight = 0, this.ratioChannelA = 1, this.ratioChannelB = 1, this.enabledLeft = 0, this.enabledRight = 0, this.dmaA = -1, this.dmaB = -1, this.soundTimerA = 0, this.soundTimerB = 0, this.soundRatio = 1, this.soundBias = 512, this.squareChannels = new Array; + for (var t = 0; t < 2; ++t) this.squareChannels[t] = { + enabled: !1, + playing: !1, + sample: 0, + duty: .5, + increment: 0, + step: 0, + initialVolume: 0, + volume: 0, + frequency: 0, + interval: 0, + sweepSteps: 0, + sweepIncrement: 0, + sweepInterval: 0, + doSweep: !1, + raise: 0, + lower: 0, + nextStep: 0, + timed: !1, + length: 0, + end: 0 + }; + this.waveData = new Uint8Array(32), this.channel3Dimension = 0, this.channel3Bank = 0, this.channel3Volume = 0, this.channel3Interval = 0, this.channel3Next = 0, this.channel3Length = 0, this.channel3Timed = !1, this.channel3End = 0, this.channel3Pointer = 0, this.channel3Sample = 0, this.cpuFrequency = this.core.irq.FREQUENCY, this.channel4 = { + sample: 0, + lfsr: 0, + width: 15, + interval: this.cpuFrequency / 524288, + increment: 0, + step: 0, + initialVolume: 0, + volume: 0, + nextStep: 0, + timed: !1, + length: 0, + end: 0 + }, this.nextEvent = 0, this.nextSample = 0, this.outputPointer = 0, this.samplePointer = 0, this.backup = 0, this.totalSamples = 0, this.sampleRate = 32768, this.sampleInterval = this.cpuFrequency / this.sampleRate, this.resampleRatio = 1, this.context && (this.resampleRatio = this.sampleRate / this.context.sampleRate), this.writeSquareChannelFC(0, 0), this.writeSquareChannelFC(1, 0), this.writeChannel4FC(0) +}, GameBoyAdvanceAudio.prototype.freeze = function() { + return { + nextSample: this.nextSample + } +}, GameBoyAdvanceAudio.prototype.defrost = function(t) { + this.nextSample = t.nextSample +}, GameBoyAdvanceAudio.prototype.pause = function(t) { + if (this.context) + if (t) try { + this.jsAudio.disconnect(this.context.destination) + } catch (t) {} else this.enabled && this.jsAudio.connect(this.context.destination) +}, GameBoyAdvanceAudio.prototype.updateTimers = function() { + var t = this.cpu.cycles; + if (this.enabled && !(t < this.nextEvent && t < this.nextSample)) { + if (t >= this.nextEvent) { + var e = this.squareChannels[0]; + if (this.nextEvent = 1 / 0, e.playing && this.updateSquareChannel(e, t), (e = this.squareChannels[1]).playing && this.updateSquareChannel(e, t), this.enableChannel3 && this.playingChannel3) { + if (t >= this.channel3Next) { + if (this.channel3Write) { + var i = this.waveData[this.channel3Pointer >> 1]; + this.channel3Sample = ((i >> ((1 & this.channel3Pointer) << 2) & 15) - 8) / 8, this.channel3Pointer = this.channel3Pointer + 1, this.channel3Dimension && 64 <= this.channel3Pointer ? this.channel3Pointer -= 64 : !this.channel3Bank && 32 <= this.channel3Pointer ? this.channel3Pointer -= 32 : 64 <= this.channel3Pointer && (this.channel3Pointer -= 32) + } + this.channel3Next += this.channel3Interval, this.channel3Interval && this.nextEvent > this.channel3Next && (this.nextEvent = this.channel3Next) + } + this.channel3Timed && t >= this.channel3End && (this.playingChannel3 = !1) + } + if (this.enableChannel4 && this.playingChannel4) + if (this.channel4.timed && t >= this.channel4.end) this.playingChannel4 = !1; + else { + if (t >= this.channel4.next) { + this.channel4.lfsr >>= 1; + i = 1 & this.channel4.lfsr; + this.channel4.lfsr |= (this.channel4.lfsr >> 1 & 1 ^ i) << this.channel4.width - 1, this.channel4.next += this.channel4.interval, this.channel4.sample = 2 * (i - .5) * this.channel4.volume + } + this.updateEnvelope(this.channel4, t), this.nextEvent > this.channel4.next && (this.nextEvent = this.channel4.next), this.channel4.timed && this.nextEvent > this.channel4.end && (this.nextEvent = this.channel4.end) + } + } + t >= this.nextSample && (this.sample(), this.nextSample += this.sampleInterval), this.nextEvent = Math.ceil(this.nextEvent), (this.nextEvent < t || this.nextSample < t) && this.updateTimers() + } +}, GameBoyAdvanceAudio.prototype.writeEnable = function(t) { + if (this.enabled = !!t, this.nextEvent = this.cpu.cycles, this.nextSample = this.nextEvent, this.updateTimers(), this.core.irq.pollNextEvent(), this.context && this.isInit) + if (t&&this.jsAudio) this.jsAudio.connect(this.context.destination); + else try { + this.jsAudio.disconnect(this.context.destination) + } catch (t) {} +}, GameBoyAdvanceAudio.prototype.writeSoundControlLo = function(t) { + this.masterVolumeLeft = 7 & t, this.masterVolumeRight = t >> 4 & 7, this.enabledLeft = t >> 8 & 15, this.enabledRight = t >> 12 & 15, this.setSquareChannelEnabled(this.squareChannels[0], 1 & (this.enabledLeft | this.enabledRight)), this.setSquareChannelEnabled(this.squareChannels[1], 2 & (this.enabledLeft | this.enabledRight)), this.enableChannel3 = 4 & (this.enabledLeft | this.enabledRight), this.setChannel4Enabled(8 & (this.enabledLeft | this.enabledRight)), this.updateTimers(), this.core.irq.pollNextEvent() +}, GameBoyAdvanceAudio.prototype.writeSoundControlHi = function(t) { + switch (3 & t) { + case 0: + this.soundRatio = .25; + break; + case 1: + this.soundRatio = .5; + break; + case 2: + this.soundRatio = 1 + } + this.ratioChannelA = .5 * (1 + ((4 & t) >> 2)), this.ratioChannelB = .5 * (1 + ((8 & t) >> 3)), this.enableRightChannelA = 256 & t, this.enableLeftChannelA = 512 & t, this.enableChannelA = 768 & t, this.soundTimerA = 1024 & t, 2048 & t && (this.fifoA = []), this.enableRightChannelB = 4096 & t, this.enableLeftChannelB = 8192 & t, this.enableChannelB = 12288 & t, this.soundTimerB = 16384 & t, 32768 & t && (this.fifoB = []) +}, GameBoyAdvanceAudio.prototype.resetSquareChannel = function(t) { + t.step && (t.nextStep = this.cpu.cycles + t.step), t.enabled && !t.playing && (t.raise = this.cpu.cycles, t.lower = t.raise + t.duty * t.interval, t.end = this.cpu.cycles + t.length, this.nextEvent = this.cpu.cycles), t.playing = t.enabled, this.updateTimers(), this.core.irq.pollNextEvent() +}, GameBoyAdvanceAudio.prototype.setSquareChannelEnabled = function(t, e) { + t.enabled && t.playing || !e ? t.enabled = !!e : (t.enabled = !!e, this.updateTimers(), this.core.irq.pollNextEvent()) +}, GameBoyAdvanceAudio.prototype.writeSquareChannelSweep = function(t, e) { + var i = this.squareChannels[t]; + i.sweepSteps = 7 & e, i.sweepIncrement = 8 & e ? -1 : 1, i.sweepInterval = (e >> 4 & 7) * this.cpuFrequency / 128, i.doSweep = !!i.sweepInterval, i.nextSweep = this.cpu.cycles + i.sweepInterval, this.resetSquareChannel(i) +}, GameBoyAdvanceAudio.prototype.writeSquareChannelDLE = function(t, e) { + var i = this.squareChannels[t]; + switch (e >> 6 & 3) { + case 0: + i.duty = .125; + break; + case 1: + i.duty = .25; + break; + case 2: + i.duty = .5; + break; + case 3: + i.duty = .75 + } + this.writeChannelLE(i, e), this.resetSquareChannel(i) +}, GameBoyAdvanceAudio.prototype.writeSquareChannelFC = function(t, e) { + var i = this.squareChannels[t], + r = 2047 & e; + i.frequency = r, i.interval = this.cpuFrequency * (2048 - r) / 131072, i.timed = !!(16384 & e), 32768 & e && (this.resetSquareChannel(i), i.volume = i.initialVolume) +}, GameBoyAdvanceAudio.prototype.updateSquareChannel = function(t, e) { + if (t.timed && e >= t.end) t.playing = !1; + else { + if (t.doSweep && e >= t.nextSweep) { + if (t.frequency += t.sweepIncrement * (t.frequency >> t.sweepSteps), t.frequency < 0) t.frequency = 0; + else if (2047 < t.frequency) return t.frequency = 2047, void(t.playing = !1); + t.interval = this.cpuFrequency * (2048 - t.frequency) / 131072, t.nextSweep += t.sweepInterval + } + e >= t.raise ? (t.sample = t.volume, t.lower = t.raise + t.duty * t.interval, t.raise += t.interval) : e >= t.lower && (t.sample = -t.volume, t.lower += t.interval), this.updateEnvelope(t, e), this.nextEvent > t.raise && (this.nextEvent = t.raise), this.nextEvent > t.lower && (this.nextEvent = t.lower), t.timed && this.nextEvent > t.end && (this.nextEvent = t.end), t.doSweep && this.nextEvent > t.nextSweep && (this.nextEvent = t.nextSweep) + } +}, GameBoyAdvanceAudio.prototype.writeChannel3Lo = function(t) { + this.channel3Dimension = 32 & t, this.channel3Bank = 64 & t; + var e = 128 & t; + !this.channel3Write && e ? (this.channel3Write = e, this.resetChannel3()) : this.channel3Write = e +}, GameBoyAdvanceAudio.prototype.writeChannel3Hi = function(t) { + switch (this.channel3Length = this.cpuFrequency * (256 - (255 & t)) / 256, t >> 13 & 7) { + case 0: + this.channel3Volume = 0; + break; + case 1: + this.channel3Volume = 1; + break; + case 2: + this.channel3Volume = .5; + break; + case 3: + this.channel3Volume = .25; + break; + default: + this.channel3Volume = .75 + } +}, GameBoyAdvanceAudio.prototype.writeChannel3X = function(t) { + this.channel3Interval = this.cpuFrequency * (2048 - (2047 & t)) / 2097152, this.channel3Timed = !!(16384 & t), this.channel3Write && this.resetChannel3() +}, GameBoyAdvanceAudio.prototype.resetChannel3 = function() { + this.channel3Next = this.cpu.cycles, this.nextEvent = this.channel3Next, this.channel3End = this.cpu.cycles + this.channel3Length, this.playingChannel3 = this.channel3Write, this.updateTimers(), this.core.irq.pollNextEvent() +}, GameBoyAdvanceAudio.prototype.writeWaveData = function(t, e, i) { + this.channel3Bank || (t += 16), 2 == i && (this.waveData[t] = 255 & e, e >>= 8, ++t), this.waveData[t] = 255 & e +}, GameBoyAdvanceAudio.prototype.setChannel4Enabled = function(t) { + !this.enableChannel4 && t ? (this.channel4.next = this.cpu.cycles, this.channel4.end = this.cpu.cycles + this.channel4.length, this.enableChannel4 = !0, this.playingChannel4 = !0, this.nextEvent = this.cpu.cycles, this.updateEnvelope(this.channel4), this.updateTimers(), this.core.irq.pollNextEvent()) : this.enableChannel4 = t +}, GameBoyAdvanceAudio.prototype.writeChannel4LE = function(t) { + this.writeChannelLE(this.channel4, t), this.resetChannel4() +}, GameBoyAdvanceAudio.prototype.writeChannel4FC = function(t) { + this.channel4.timed = !!(16384 & t); + var e = 7 & t; + e || (e = .5); + var i = t >> 4 & 15, + r = this.cpuFrequency * (e * (2 << i)) / 524288; + r != this.channel4.interval && (this.channel4.interval = r, this.resetChannel4()); + var s = 8 & t ? 7 : 15; + s != this.channel4.width && (this.channel4.width = s, this.resetChannel4()), 32768 & t && this.resetChannel4() +}, GameBoyAdvanceAudio.prototype.resetChannel4 = function() { + 15 == this.channel4.width ? this.channel4.lfsr = 16384 : this.channel4.lfsr = 64, this.channel4.volume = this.channel4.initialVolume, this.channel4.step && (this.channel4.nextStep = this.cpu.cycles + this.channel4.step), this.channel4.end = this.cpu.cycles + this.channel4.length, this.channel4.next = this.cpu.cycles, this.nextEvent = this.channel4.next, this.playingChannel4 = this.enableChannel4, this.updateTimers(), this.core.irq.pollNextEvent() +}, GameBoyAdvanceAudio.prototype.writeChannelLE = function(t, e) { + t.length = this.cpuFrequency * ((64 - (63 & e)) / 256), t.increment = 2048 & e ? 1 / 16 : -1 / 16, t.initialVolume = (e >> 12 & 15) / 16, t.step = this.cpuFrequency * ((e >> 8 & 7) / 64) +}, GameBoyAdvanceAudio.prototype.updateEnvelope = function(t, e) { + t.step && (e >= t.nextStep && (t.volume += t.increment, 1 < t.volume ? t.volume = 1 : t.volume < 0 && (t.volume = 0), t.nextStep += t.step), this.nextEvent > t.nextStep && (this.nextEvent = t.nextStep)) +}, GameBoyAdvanceAudio.prototype.appendToFifoA = function(t) { + var e; + 28 < this.fifoA.length && (this.fifoA = this.fifoA.slice(-28)); + for (var i = 0; i < 4; ++i) e = (255 & t) << 24, t >>= 8, this.fifoA.push(e / 2147483648) +}, GameBoyAdvanceAudio.prototype.appendToFifoB = function(t) { + var e; + 28 < this.fifoB.length && (this.fifoB = this.fifoB.slice(-28)); + for (var i = 0; i < 4; ++i) e = (255 & t) << 24, t >>= 8, this.fifoB.push(e / 2147483648) +}, GameBoyAdvanceAudio.prototype.sampleFifoA = function() { + if (this.fifoA.length <= 16) { + var t = this.core.irq.dma[this.dmaA]; + t.nextCount = 4, this.core.mmu.serviceDma(this.dmaA, t) + } + this.fifoASample = this.fifoA.shift() +}, GameBoyAdvanceAudio.prototype.sampleFifoB = function() { + if (this.fifoB.length <= 16) { + var t = this.core.irq.dma[this.dmaB]; + t.nextCount = 4, this.core.mmu.serviceDma(this.dmaB, t) + } + this.fifoBSample = this.fifoB.shift() +}, GameBoyAdvanceAudio.prototype.scheduleFIFODma = function(t, e) { + switch (e.dest) { + case this.cpu.mmu.BASE_IO | this.cpu.irq.io.FIFO_A_LO: + e.dstControl = 2, this.dmaA = t; + break; + case this.cpu.mmu.BASE_IO | this.cpu.irq.io.FIFO_B_LO: + e.dstControl = 2, this.dmaB = t; + break; + default: + this.core.WARN("Tried to schedule FIFO DMA for non-FIFO destination") + } +}, GameBoyAdvanceAudio.prototype.sample = function() { + var t, e, i = 0, + r = 0; + (e = this.squareChannels[0]).playing && (t = e.sample * this.soundRatio * this.PSG_MAX, 1 & this.enabledLeft && (i += t), 1 & this.enabledRight && (r += t)), (e = this.squareChannels[1]).playing && (t = e.sample * this.soundRatio * this.PSG_MAX, 2 & this.enabledLeft && (i += t), 2 & this.enabledRight && (r += t)), this.playingChannel3 && (t = this.channel3Sample * this.soundRatio * this.channel3Volume * this.PSG_MAX, 4 & this.enabledLeft && (i += t), 4 & this.enabledRight && (r += t)), this.playingChannel4 && (t = this.channel4.sample * this.soundRatio * this.PSG_MAX, 8 & this.enabledLeft && (i += t), 8 & this.enabledRight && (r += t)), this.enableChannelA && (t = this.fifoASample * this.FIFO_MAX * this.ratioChannelA, this.enableLeftChannelA && (i += t), this.enableRightChannelA && (r += t)), this.enableChannelB && (t = this.fifoBSample * this.FIFO_MAX * this.ratioChannelB, this.enableLeftChannelB && (i += t), this.enableRightChannelB && (r += t)); + var s = this.samplePointer; + if (i *= this.masterVolume / this.SOUND_MAX, i = Math.max(Math.min(i, 1), -1), r *= this.masterVolume / this.SOUND_MAX, r = Math.max(Math.min(r, 1), -1), !this.isInit2 && i && r) { + this.isInit2 = !0; + var n = this; + setTimeout(function() { + n.isInit = !0 + }, 1e3) + } + this.buffers && (this.buffers[0][s] = i, this.buffers[1][s] = r), this.samplePointer = s + 1 & this.sampleMask +}, GameBoyAdvanceAudio.prototype.audioProcess = function(t) { + var e = t.outputBuffer.getChannelData(0), + i = t.outputBuffer.getChannelData(1); + if (this.masterEnable) { + var r, s = this.outputPointer; + for (r = 0; r < this.bufferSize; ++r, s += this.resampleRatio) { + if (s >= this.maxSamples && (s -= this.maxSamples), (0 | s) == this.samplePointer) { + ++this.backup; + break + } + e[r] = this.buffers[0][0 | s], i[r] = this.buffers[1][0 | s] + } + for (; r < this.bufferSize; ++r) e[r] = 0, i[r] = 0; + this.outputPointer = s, ++this.totalSamples + } else + for (r = 0; r < this.bufferSize; ++r) e[r] = 0, i[r] = 0 +}, GameBoyAdvanceVideo.prototype.clear = function() { + this.renderPath.clear(this.cpu.mmu), this.DISPSTAT_MASK = 65336, this.inHblank = !1, this.inVblank = !1, this.vcounter = 0, this.vblankIRQ = 0, this.hblankIRQ = 0, this.vcounterIRQ = 0, this.vcountSetting = 0, this.vcount = -1, this.lastHblank = 0, this.nextHblank = this.HDRAW_LENGTH, this.nextEvent = this.nextHblank, this.nextHblankIRQ = 0, this.nextVblankIRQ = 0, this.nextVcounterIRQ = 0 +}, GameBoyAdvanceVideo.prototype.freeze = function() { + return { + inHblank: this.inHblank, + inVblank: this.inVblank, + vcounter: this.vcounter, + vblankIRQ: this.vblankIRQ, + hblankIRQ: this.hblankIRQ, + vcounterIRQ: this.vcounterIRQ, + vcountSetting: this.vcountSetting, + vcount: this.vcount, + lastHblank: this.lastHblank, + nextHblank: this.nextHblank, + nextEvent: this.nextEvent, + nextHblankIRQ: this.nextHblankIRQ, + nextVblankIRQ: this.nextVblankIRQ, + nextVcounterIRQ: this.nextVcounterIRQ, + renderPath: this.renderPath.freeze(this.core.encodeBase64) + } +}, GameBoyAdvanceVideo.prototype.defrost = function(t) { + this.inHblank = t.inHblank, this.inVblank = t.inVblank, this.vcounter = t.vcounter, this.vblankIRQ = t.vblankIRQ, this.hblankIRQ = t.hblankIRQ, this.vcounterIRQ = t.vcounterIRQ, this.vcountSetting = t.vcountSetting, this.vcount = t.vcount, this.lastHblank = t.lastHblank, this.nextHblank = t.nextHblank, this.nextEvent = t.nextEvent, this.nextHblankIRQ = t.nextHblankIRQ, this.nextVblankIRQ = t.nextVblankIRQ, this.nextVcounterIRQ = t.nextVcounterIRQ, this.renderPath.defrost(t.renderPath, this.core.decodeBase64) +}, GameBoyAdvanceVideo.prototype.setBacking = function(t) { + var e = t.createImageData(this.HORIZONTAL_PIXELS, this.VERTICAL_PIXELS); + this.context = t; + for (var i = 0; i < this.HORIZONTAL_PIXELS * this.VERTICAL_PIXELS * 4;) e.data[i++] = 255, e.data[i++] = 255, e.data[i++] = 255, e.data[i++] = 255; + this.renderPath.setBacking(e) +}, GameBoyAdvanceVideo.prototype.updateTimers = function(t) { + var e = t.cycles; + if (this.nextEvent <= e) + if (this.inHblank) { + switch (this.inHblank = !1, this.nextEvent = this.nextHblank, ++this.vcount, this.vcount) { + case this.VERTICAL_PIXELS: + this.inVblank = !0, this.renderPath.finishDraw(this), this.nextVblankIRQ = this.nextEvent + this.TOTAL_LENGTH, this.cpu.mmu.runVblankDmas(), this.vblankIRQ && this.cpu.irq.raiseIRQ(this.cpu.irq.IRQ_VBLANK), this.vblankCallback(); + break; + case this.VERTICAL_TOTAL_PIXELS - 1: + this.inVblank = !1; + break; + case this.VERTICAL_TOTAL_PIXELS: + this.vcount = 0, this.renderPath.startDraw() + } + this.vcounter = this.vcount == this.vcountSetting, this.vcounter && this.vcounterIRQ && (this.cpu.irq.raiseIRQ(this.cpu.irq.IRQ_VCOUNTER), this.nextVcounterIRQ += this.TOTAL_LENGTH), this.vcount < this.VERTICAL_PIXELS && this.renderPath.drawScanline(this.vcount) + } else this.inHblank = !0, this.lastHblank = this.nextHblank, this.nextEvent = this.lastHblank + this.HBLANK_LENGTH, this.nextHblank = this.nextEvent + this.HDRAW_LENGTH, this.nextHblankIRQ = this.nextHblank, this.vcount < this.VERTICAL_PIXELS && this.cpu.mmu.runHblankDmas(), this.hblankIRQ && this.cpu.irq.raiseIRQ(this.cpu.irq.IRQ_HBLANK) +}, GameBoyAdvanceVideo.prototype.writeDisplayStat = function(t) { + this.vblankIRQ = 8 & t, this.hblankIRQ = 16 & t, this.vcounterIRQ = 32 & t, this.vcountSetting = (65280 & t) >> 8, this.vcounterIRQ && (this.nextVcounterIRQ = this.nextHblank + this.HBLANK_LENGTH + (this.vcountSetting - this.vcount) * this.HORIZONTAL_LENGTH, this.nextVcounterIRQ < this.nextEvent && (this.nextVcounterIRQ += this.TOTAL_LENGTH)) +}, GameBoyAdvanceVideo.prototype.readDisplayStat = function() { + return this.inVblank | this.inHblank << 1 | this.vcounter << 2 +}, GameBoyAdvanceVideo.prototype.finishDraw = function(t) { + this.context.putImageData(t, 0, 0), this.drawCallback() +}, MemoryProxy.prototype.combine = function() { + if (1 < this.blocks.length) { + for (var t = new Uint8Array(this.size), e = 0; e < this.blocks.length; ++e) t.set(new Uint8Array(this.blocks[e].buffer), e << this.blockSize); + return t.buffer + } + return this.blocks[0].buffer +}, MemoryProxy.prototype.replace = function(t) { + for (var e = 0; e < this.blocks.length; ++e) this.blocks[e] = new MemoryView(t.slice(e << this.blockSize, (e << this.blockSize) + this.blocks[e].buffer.byteLength)) +}, MemoryProxy.prototype.load8 = function(t) { + return this.blocks[t >> this.blockSize].load8(t & this.mask) +}, MemoryProxy.prototype.load16 = function(t) { + return this.blocks[t >> this.blockSize].load16(t & this.mask) +}, MemoryProxy.prototype.loadU8 = function(t) { + return this.blocks[t >> this.blockSize].loadU8(t & this.mask) +}, MemoryProxy.prototype.loadU16 = function(t) { + return this.blocks[t >> this.blockSize].loadU16(t & this.mask) +}, MemoryProxy.prototype.load32 = function(t) { + return this.blocks[t >> this.blockSize].load32(t & this.mask) +}, MemoryProxy.prototype.store8 = function(t, e) { + t >= this.size || (this.owner.memoryDirtied(this, t >> this.blockSize), this.blocks[t >> this.blockSize].store8(t & this.mask, e), this.blocks[t >> this.blockSize].store8(t & this.mask ^ 1, e)) +}, MemoryProxy.prototype.store16 = function(t, e) { + if (!(t >= this.size)) return this.owner.memoryDirtied(this, t >> this.blockSize), this.blocks[t >> this.blockSize].store16(t & this.mask, e) +}, MemoryProxy.prototype.store32 = function(t, e) { + if (!(t >= this.size)) return this.owner.memoryDirtied(this, t >> this.blockSize), this.blocks[t >> this.blockSize].store32(t & this.mask, e) +}, MemoryProxy.prototype.invalidatePage = function(t) {}, GameBoyAdvanceRenderProxy.prototype.memoryDirtied = function(t, e) { + this.dirty = this.dirty || {}, this.dirty.memory = this.dirty.memory || {}, t === this.palette && (this.dirty.memory.palette = t.blocks[0].buffer), t === this.oam && (this.dirty.memory.oam = t.blocks[0].buffer), t === this.vram && (this.dirty.memory.vram = this.dirty.memory.vram || [], this.dirty.memory.vram[e] = t.blocks[e].buffer) +}, GameBoyAdvanceRenderProxy.prototype.clear = function(t) { + this.palette = new MemoryProxy(this, t.SIZE_PALETTE_RAM, 0), this.vram = new MemoryProxy(this, t.SIZE_VRAM, 13), this.oam = new MemoryProxy(this, t.SIZE_OAM, 0), this.dirty = null, this.scanlineQueue = [], this.worker.postMessage({ + type: "clear", + SIZE_VRAM: t.SIZE_VRAM, + SIZE_OAM: t.SIZE_OAM + }) +}, GameBoyAdvanceRenderProxy.prototype.freeze = function(t) { + return { + palette: Serializer.prefix(this.palette.combine()), + vram: Serializer.prefix(this.vram.combine()), + oam: Serializer.prefix(this.oam.combine()) + } +}, GameBoyAdvanceRenderProxy.prototype.defrost = function(t, e) { + this.palette.replace(t.palette), this.memoryDirtied(this.palette, 0), this.vram.replace(t.vram); + for (var i = 0; i < this.vram.blocks.length; ++i) this.memoryDirtied(this.vram, i); + this.oam.replace(t.oam), this.memoryDirtied(this.oam, 0) +}, GameBoyAdvanceRenderProxy.prototype.writeDisplayControl = function(t) { + this.dirty = this.dirty || {}, this.dirty.DISPCNT = t +}, GameBoyAdvanceRenderProxy.prototype.writeBackgroundControl = function(t, e) { + this.dirty = this.dirty || {}, this.dirty.BGCNT = this.dirty.BGCNT || [], this.dirty.BGCNT[t] = e +}, GameBoyAdvanceRenderProxy.prototype.writeBackgroundHOffset = function(t, e) { + this.dirty = this.dirty || {}, this.dirty.BGHOFS = this.dirty.BGHOFS || [], this.dirty.BGHOFS[t] = e +}, GameBoyAdvanceRenderProxy.prototype.writeBackgroundVOffset = function(t, e) { + this.dirty = this.dirty || {}, this.dirty.BGVOFS = this.dirty.BGVOFS || [], this.dirty.BGVOFS[t] = e +}, GameBoyAdvanceRenderProxy.prototype.writeBackgroundRefX = function(t, e) { + this.dirty = this.dirty || {}, this.dirty.BGX = this.dirty.BGX || [], this.dirty.BGX[t] = e +}, GameBoyAdvanceRenderProxy.prototype.writeBackgroundRefY = function(t, e) { + this.dirty = this.dirty || {}, this.dirty.BGY = this.dirty.BGY || [], this.dirty.BGY[t] = e +}, GameBoyAdvanceRenderProxy.prototype.writeBackgroundParamA = function(t, e) { + this.dirty = this.dirty || {}, this.dirty.BGPA = this.dirty.BGPA || [], this.dirty.BGPA[t] = e +}, GameBoyAdvanceRenderProxy.prototype.writeBackgroundParamB = function(t, e) { + this.dirty = this.dirty || {}, this.dirty.BGPB = this.dirty.BGPB || [], this.dirty.BGPB[t] = e +}, GameBoyAdvanceRenderProxy.prototype.writeBackgroundParamC = function(t, e) { + this.dirty = this.dirty || {}, this.dirty.BGPC = this.dirty.BGPC || [], this.dirty.BGPC[t] = e +}, GameBoyAdvanceRenderProxy.prototype.writeBackgroundParamD = function(t, e) { + this.dirty = this.dirty || {}, this.dirty.BGPD = this.dirty.BGPD || [], this.dirty.BGPD[t] = e +}, GameBoyAdvanceRenderProxy.prototype.writeWin0H = function(t) { + this.dirty = this.dirty || {}, this.dirty.WIN0H = t +}, GameBoyAdvanceRenderProxy.prototype.writeWin1H = function(t) { + this.dirty = this.dirty || {}, this.dirty.WIN1H = t +}, GameBoyAdvanceRenderProxy.prototype.writeWin0V = function(t) { + this.dirty = this.dirty || {}, this.dirty.WIN0V = t +}, GameBoyAdvanceRenderProxy.prototype.writeWin1V = function(t) { + this.dirty = this.dirty || {}, this.dirty.WIN1V = t +}, GameBoyAdvanceRenderProxy.prototype.writeWinIn = function(t) { + this.dirty = this.dirty || {}, this.dirty.WININ = t +}, GameBoyAdvanceRenderProxy.prototype.writeWinOut = function(t) { + this.dirty = this.dirty || {}, this.dirty.WINOUT = t +}, GameBoyAdvanceRenderProxy.prototype.writeBlendControl = function(t) { + this.dirty = this.dirty || {}, this.dirty.BLDCNT = t +}, GameBoyAdvanceRenderProxy.prototype.writeBlendAlpha = function(t) { + this.dirty = this.dirty || {}, this.dirty.BLDALPHA = t +}, GameBoyAdvanceRenderProxy.prototype.writeBlendY = function(t) { + this.dirty = this.dirty || {}, this.dirty.BLDY = t +}, GameBoyAdvanceRenderProxy.prototype.writeMosaic = function(t) { + this.dirty = this.dirty || {}, this.dirty.MOSAIC = t +}, GameBoyAdvanceRenderProxy.prototype.clearSubsets = function(t, e) { + if (this.dirty = this.dirty || {}, 4 & e && (this.palette = new MemoryProxy(this, t.SIZE_PALETTE_RAM, 0), t.mmap(t.REGION_PALETTE_RAM, this.palette), this.memoryDirtied(this.palette, 0)), 8 & e) { + this.vram = new MemoryProxy(this, t.SIZE_VRAM, 13), t.mmap(t.REGION_VRAM, this.vram); + for (var i = 0; i < this.vram.blocks.length; ++i) this.memoryDirtied(this.vram, i) + } + 16 & e && (this.oam = new MemoryProxy(this, t.SIZE_OAM, 0), t.mmap(t.REGION_OAM, this.oam), this.memoryDirtied(this.oam, 0)) +}, GameBoyAdvanceRenderProxy.prototype.setBacking = function(t) { + this.backing = t, this.worker.postMessage({ + type: "start", + backing: this.backing + }) +}, GameBoyAdvanceRenderProxy.prototype.drawScanline = function(t) { + if (!this.skipFrame && this.dirty) { + if (this.dirty.memory && (this.dirty.memory.palette && (this.dirty.memory.palette = this.dirty.memory.palette.slice(0)), this.dirty.memory.oam && (this.dirty.memory.oam = this.dirty.memory.oam.slice(0)), this.dirty.memory.vram)) + for (var e = 0; e < 12; ++e) this.dirty.memory.vram[e] && (this.dirty.memory.vram[e] = this.dirty.memory.vram[e].slice(0)); + this.scanlineQueue.push({ + y: t, + dirty: this.dirty + }), this.dirty = null + } +}, GameBoyAdvanceRenderProxy.prototype.startDraw = function() { + ++this.currentFrame, this.delay <= 0 && (this.skipFrame = !1), this.skipFrame || ++this.delay +}, GameBoyAdvanceRenderProxy.prototype.finishDraw = function(t) { + this.caller = t, this.skipFrame || (this.worker.postMessage({ + type: "finish", + scanlines: this.scanlineQueue, + frame: this.currentFrame + }), this.scanlineQueue = [], 2 < this.delay && (this.skipFrame = !0)) +}, MemoryAligned16.prototype.load8 = function(t) { + return this.loadU8(t) << 24 >> 24 +}, MemoryAligned16.prototype.load16 = function(t) { + return this.loadU16(t) << 16 >> 16 +}, MemoryAligned16.prototype.loadU8 = function(t) { + var e = t >> 1; + return 1 & t ? (65280 & this.buffer[e]) >>> 8 : 255 & this.buffer[e] +}, MemoryAligned16.prototype.loadU16 = function(t) { + return this.buffer[t >> 1] +}, MemoryAligned16.prototype.load32 = function(t) { + return this.buffer[t >> 1 & -2] | this.buffer[t >> 1 | 1] << 16 +}, MemoryAligned16.prototype.store8 = function(t, e) { + this.store16(t, e << 8 | e) +}, MemoryAligned16.prototype.store16 = function(t, e) { + this.buffer[t >> 1] = e +}, MemoryAligned16.prototype.store32 = function(t, e) { + var i = t >> 1; + this.store16(t, this.buffer[i] = 65535 & e), this.store16(t + 2, this.buffer[i + 1] = e >>> 16) +}, MemoryAligned16.prototype.insert = function(t, e) { + this.buffer.set(e, t) +}, MemoryAligned16.prototype.invalidatePage = function(t) {}, GameBoyAdvanceVRAM.prototype = Object.create(MemoryAligned16.prototype), GameBoyAdvanceOAM.prototype = Object.create(MemoryAligned16.prototype), GameBoyAdvanceOAM.prototype.overwrite = function(t) { + for (var e = 0; e < this.buffer.byteLength >> 1; ++e) this.store16(e << 1, t[e]) +}, GameBoyAdvanceOAM.prototype.store16 = function(t, e) { + var i = (1016 & t) >> 3, + r = this.objs[i], + s = this.scalerot[i >> 2]; + r.priority, r.disable, r.y; + switch (6 & t) { + case 0: + r.y = 255 & e; + var n = r.scalerot; + r.scalerot = 256 & e, r.scalerot ? (r.scalerotOam = this.scalerot[r.scalerotParam], r.doublesize = !!(512 & e), r.disable = 0, r.hflip = 0, r.vflip = 0) : (r.doublesize = !1, r.disable = 512 & e, n && (r.hflip = 8 & r.scalerotParam, r.vflip = 16 & r.scalerotParam)), r.mode = (3072 & e) >> 6, r.mosaic = 4096 & e, r.multipalette = 8192 & e, r.shape = (49152 & e) >> 14, r.recalcSize(); + break; + case 2: + r.x = 511 & e, r.scalerot ? (r.scalerotParam = (15872 & e) >> 9, r.scalerotOam = this.scalerot[r.scalerotParam], r.hflip = 0, r.vflip = 0, r.drawScanline = r.drawScanlineAffine) : (r.hflip = 4096 & e, r.vflip = 8192 & e, r.drawScanline = r.drawScanlineNormal), r.size = (49152 & e) >> 14, r.recalcSize(); + break; + case 4: + r.tileBase = 1023 & e, r.priority = (3072 & e) >> 10, r.palette = (61440 & e) >> 8; + break; + case 6: + switch (3 & i) { + case 0: + s.a = (e << 16) / 16777216; + break; + case 1: + s.b = (e << 16) / 16777216; + break; + case 2: + s.c = (e << 16) / 16777216; + break; + case 3: + s.d = (e << 16) / 16777216 + } + } + MemoryAligned16.prototype.store16.call(this, t, e) +}, GameBoyAdvancePalette.prototype.overwrite = function(t) { + for (var e = 0; e < 512; ++e) this.store16(e << 1, t[e]) +}, GameBoyAdvancePalette.prototype.loadU8 = function(t) { + return this.loadU16(t) >> 8 * (1 & t) & 255 +}, GameBoyAdvancePalette.prototype.loadU16 = function(t) { + return this.colors[(512 & t) >> 9][(511 & t) >> 1] +}, GameBoyAdvancePalette.prototype.load16 = function(t) { + return this.loadU16(t) << 16 >> 16 +}, GameBoyAdvancePalette.prototype.load32 = function(t) { + return this.loadU16(t) | this.loadU16(t + 2) << 16 +}, GameBoyAdvancePalette.prototype.store16 = function(t, e) { + var i = (512 & t) >> 9, + r = (511 & t) >> 1; + this.colors[i][r] = e, this.adjustedColors[i][r] = this.adjustColor(e) +}, GameBoyAdvancePalette.prototype.store32 = function(t, e) { + this.store16(t, 65535 & e), this.store16(t + 2, e >> 16) +}, GameBoyAdvancePalette.prototype.invalidatePage = function(t) {}, GameBoyAdvancePalette.prototype.convert16To32 = function(t, e) { + var i = (31 & t) << 3, + r = (992 & t) >> 2, + s = (31744 & t) >> 7; + e[0] = i, e[1] = r, e[2] = s +}, GameBoyAdvancePalette.prototype.mix = function(t, e, i, r) { + var s = 31 & e, + n = (992 & e) >> 5, + a = (31744 & e) >> 10, + o = 31 & r, + h = (992 & r) >> 5, + c = (31744 & r) >> 10; + return Math.min(t * s + i * o, 31) | Math.min(t * n + i * h, 31) << 5 | Math.min(t * a + i * c, 31) << 10 +}, GameBoyAdvancePalette.prototype.makeDarkPalettes = function(t) { + this.adjustColor != this.adjustColorDark && (this.adjustColor = this.adjustColorDark, this.resetPalettes()), this.resetPaletteLayers(t) +}, GameBoyAdvancePalette.prototype.makeBrightPalettes = function(t) { + this.adjustColor != this.adjustColorBright && (this.adjustColor = this.adjustColorBright, this.resetPalettes()), this.resetPaletteLayers(t) +}, GameBoyAdvancePalette.prototype.makeNormalPalettes = function() { + this.passthroughColors[0] = this.colors[0], this.passthroughColors[1] = this.colors[0], this.passthroughColors[2] = this.colors[0], this.passthroughColors[3] = this.colors[0], this.passthroughColors[4] = this.colors[1], this.passthroughColors[5] = this.colors[0] +}, GameBoyAdvancePalette.prototype.makeSpecialPalette = function(t) { + this.passthroughColors[t] = this.adjustedColors[4 == t ? 1 : 0] +}, GameBoyAdvancePalette.prototype.makeNormalPalette = function(t) { + this.passthroughColors[t] = this.colors[4 == t ? 1 : 0] +}, GameBoyAdvancePalette.prototype.resetPaletteLayers = function(t) { + this.passthroughColors[0] = 1 & t ? this.adjustedColors[0] : this.colors[0], this.passthroughColors[1] = 2 & t ? this.adjustedColors[0] : this.colors[0], this.passthroughColors[2] = 4 & t ? this.adjustedColors[0] : this.colors[0], this.passthroughColors[3] = 8 & t ? this.adjustedColors[0] : this.colors[0], this.passthroughColors[4] = 16 & t ? this.adjustedColors[1] : this.colors[1], this.passthroughColors[5] = 32 & t ? this.adjustedColors[0] : this.colors[0] +}, GameBoyAdvancePalette.prototype.resetPalettes = function() { + var t, e = this.adjustedColors[0], + i = this.colors[0]; + for (t = 0; t < 256; ++t) e[t] = this.adjustColor(i[t]); + for (e = this.adjustedColors[1], i = this.colors[1], t = 0; t < 256; ++t) e[t] = this.adjustColor(i[t]) +}, GameBoyAdvancePalette.prototype.accessColor = function(t, e) { + return this.passthroughColors[t][e] +}, GameBoyAdvancePalette.prototype.adjustColorDark = function(t) { + var e = 31 & t, + i = (992 & t) >> 5, + r = (31744 & t) >> 10; + return (e -= e * this.blendY) | (i -= i * this.blendY) << 5 | (r -= r * this.blendY) << 10 +}, GameBoyAdvancePalette.prototype.adjustColorBright = function(t) { + var e = 31 & t, + i = (992 & t) >> 5, + r = (31744 & t) >> 10; + return (e += (31 - e) * this.blendY) | (i += (31 - i) * this.blendY) << 5 | (r += (31 - r) * this.blendY) << 10 +}, GameBoyAdvancePalette.prototype.adjustColor = GameBoyAdvancePalette.prototype.adjustColorBright, GameBoyAdvancePalette.prototype.setBlendY = function(t) { + this.blendY != t && (this.blendY = t, this.resetPalettes()) +}, GameBoyAdvanceOBJ.prototype.drawScanlineNormal = function(t, e, i, r, s) { + var n, a, o, h = this.oam.video, + c = this.mode | h.target2[h.LAYER_OBJ] | this.priority << 1; + 16 == this.mode && (c |= h.TARGET1_MASK), 1 == h.blendMode && h.alphaEnabled && (c |= h.target1[h.LAYER_OBJ]); + var u, d, p = this.cachedWidth; + this.x < h.HORIZONTAL_PIXELS ? (this.x < r ? (a = r - this.x, o = r) : (a = 0, o = this.x), s < this.cachedWidth + this.x && (p = s - this.x)) : (a = r + 512 - this.x, o = r, s < this.cachedWidth - a && (p = s)); + var l, f, m = 7 & (d = this.vflip ? this.cachedHeight - e + i - 1 : e - i), + y = this.multipalette ? 1 : 0; + f = h.objCharacterMapping ? (504 & d) * this.cachedWidth >> 6 : (504 & d) << 2 - y, this.mosaic && (o += l = h.objMosaicX - 1 - (h.objMosaicX + o - 1) % h.objMosaicX, a += l), u = this.hflip ? this.cachedWidth - a - 1 : a; + var v = h.accessTile(this.TILE_OFFSET + (4 & n) * y, this.tileBase + (f << y) + ((504 & u) >> 3 - y), m << y); + for (n = a; n < p; ++n) l = this.mosaic ? o % h.objMosaicX : 0, u = this.hflip ? this.cachedWidth - (n - l) - 1 : n - l, y ? 3 & n && (!this.mosaic || l) || (v = h.accessTile(this.TILE_OFFSET + (4 & u), this.tileBase + (f << 1) + ((504 & u) >> 2), m << 1)) : 7 & n && (!this.mosaic || l) || (v = h.accessTile(this.TILE_OFFSET, this.tileBase + f + (u >> 3), m)), this.pushPixel(h.LAYER_OBJ, this, h, v, 7 & u, o, t, c, !1), o++ +}, GameBoyAdvanceOBJ.prototype.drawScanlineAffine = function(t, e, i, r, s) { + var n, a, o, h, c, u = this.oam.video, + d = this.mode | u.target2[u.LAYER_OBJ] | this.priority << 1; + 16 == this.mode && (d |= u.TARGET1_MASK), 1 == u.blendMode && u.alphaEnabled && (d |= u.target1[u.LAYER_OBJ]); + var p, l = e - i, + f = this.multipalette ? 1 : 0, + m = this.cachedWidth << this.doublesize, + y = this.cachedHeight << this.doublesize, + v = m; + for (v > u.HORIZONTAL_PIXELS && (m = u.HORIZONTAL_PIXELS), this.x < u.HORIZONTAL_PIXELS ? (this.x < r ? (a = r - this.x, o = r) : (a = 0, o = this.x), s < v + this.x && (v = s - this.x)) : s < v - (a = (o = r) + 512 - this.x) && (v = s), n = a; n < v; ++n) h = this.scalerotOam.a * (n - (m >> 1)) + this.scalerotOam.b * (l - (y >> 1)) + (this.cachedWidth >> 1), c = this.scalerotOam.c * (n - (m >> 1)) + this.scalerotOam.d * (l - (y >> 1)) + (this.cachedHeight >> 1), this.mosaic && (h -= n % u.objMosaicX * this.scalerotOam.a + e % u.objMosaicY * this.scalerotOam.b, c -= n % u.objMosaicX * this.scalerotOam.c + e % u.objMosaicY * this.scalerotOam.d), h < 0 || h >= this.cachedWidth || c < 0 || c >= this.cachedHeight || (p = u.objCharacterMapping ? (504 & c) * this.cachedWidth >> 6 : (504 & c) << 2 - f, tileRow = u.accessTile(this.TILE_OFFSET + (4 & h) * f, this.tileBase + (p << f) + ((504 & h) >> 3 - f), (7 & c) << f), this.pushPixel(u.LAYER_OBJ, this, u, tileRow, 7 & h, o, t, d, !1)), o++ +}, GameBoyAdvanceOBJ.prototype.recalcSize = function() { + switch (this.shape) { + case 0: + this.cachedHeight = this.cachedWidth = 8 << this.size; + break; + case 1: + switch (this.size) { + case 0: + this.cachedHeight = 8, this.cachedWidth = 16; + break; + case 1: + this.cachedHeight = 8, this.cachedWidth = 32; + break; + case 2: + this.cachedHeight = 16, this.cachedWidth = 32; + break; + case 3: + this.cachedHeight = 32, this.cachedWidth = 64 + } + break; + case 2: + switch (this.size) { + case 0: + this.cachedHeight = 16, this.cachedWidth = 8; + break; + case 1: + this.cachedHeight = 32, this.cachedWidth = 8; + break; + case 2: + this.cachedHeight = 32, this.cachedWidth = 16; + break; + case 3: + this.cachedHeight = 64, this.cachedWidth = 32 + } + } +}, GameBoyAdvanceOBJLayer.prototype.drawScanline = function(t, e, i, r) { + var s, n, a, o = this.video.vcount; + if (!(r <= i)) + for (var h = this.video.oam.objs, c = 0; c < h.length; ++c) { + var u; + if (!(a = h[c]).disable) + if ((a.mode & this.video.OBJWIN_MASK) == this.objwin) + if (a.mode & this.video.OBJWIN_MASK || this.priority == a.priority) s = a.y < this.video.VERTICAL_PIXELS ? a.y : a.y - 256, u = a.scalerot ? a.cachedHeight << a.doublesize : a.cachedHeight, n = a.mosaic ? o - o % this.video.objMosaicY : o, s <= o && o < s + u && a.drawScanline(t, n, s, i, r) + } +}, GameBoyAdvanceOBJLayer.prototype.objComparator = function(t, e) { + return t.index - e.index +}, GameBoyAdvanceSoftwareRenderer.prototype.clear = function(t) { + this.palette = new GameBoyAdvancePalette, this.vram = new GameBoyAdvanceVRAM(t.SIZE_VRAM), this.oam = new GameBoyAdvanceOAM(t.SIZE_OAM), (this.oam.video = this).objLayers = [new GameBoyAdvanceOBJLayer(this, 0), new GameBoyAdvanceOBJLayer(this, 1), new GameBoyAdvanceOBJLayer(this, 2), new GameBoyAdvanceOBJLayer(this, 3)], this.objwinLayer = new GameBoyAdvanceOBJLayer(this, 4), this.objwinLayer.objwin = this.OBJWIN_MASK, this.backgroundMode = 0, this.displayFrameSelect = 0, this.hblankIntervalFree = 0, this.objCharacterMapping = 0, this.forcedBlank = 1, this.win0 = 0, this.win1 = 0, this.objwin = 0, this.vcount = -1, this.win0Left = 0, this.win0Right = 240, this.win1Left = 0, this.win1Right = 240, this.win0Top = 0, this.win0Bottom = 160, this.win1Top = 0, this.win1Bottom = 160, this.windows = new Array; + for (var e = 0; e < 4; ++e) this.windows.push({ + enabled: [!1, !1, !1, !1, !1, !0], + special: 0 + }); + this.target1 = new Array(5), this.target2 = new Array(5), this.blendMode = 0, this.blendA = 0, this.blendB = 0, this.blendY = 0, this.bgMosaicX = 1, this.bgMosaicY = 1, this.objMosaicX = 1, this.objMosaicY = 1, this.lastHblank = 0, this.nextHblank = this.HDRAW_LENGTH, this.nextEvent = this.nextHblank, this.nextHblankIRQ = 0, this.nextVblankIRQ = 0, this.nextVcounterIRQ = 0, this.bg = new Array; + for (e = 0; e < 4; ++e) this.bg.push({ + bg: !0, + index: e, + enabled: !1, + video: this, + vram: this.vram, + priority: 0, + charBase: 0, + mosaic: !1, + multipalette: !1, + screenBase: 0, + overflow: 0, + size: 0, + x: 0, + y: 0, + refx: 0, + refy: 0, + dx: 1, + dmx: 0, + dy: 0, + dmy: 1, + sx: 0, + sy: 0, + pushPixel: GameBoyAdvanceSoftwareRenderer.pushPixel, + drawScanline: this.drawScanlineBGMode0 + }); + this.bgModes = [this.drawScanlineBGMode0, this.drawScanlineBGMode2, this.drawScanlineBGMode2, this.drawScanlineBGMode3, this.drawScanlineBGMode4, this.drawScanlineBGMode5], this.drawLayers = [this.bg[0], this.bg[1], this.bg[2], this.bg[3], this.objLayers[0], this.objLayers[1], this.objLayers[2], this.objLayers[3], this.objwinLayer, this.drawBackdrop], objwinActive = !1, this.alphaEnabled = !1, this.scanline = { + color: new Uint16Array(this.HORIZONTAL_PIXELS), + stencil: new Uint8Array(this.HORIZONTAL_PIXELS) + }, this.sharedColor = [0, 0, 0], this.sharedMap = { + tile: 0, + hflip: !1, + vflip: !1, + palette: 0 + } +}, GameBoyAdvanceSoftwareRenderer.prototype.clearSubsets = function(t, e) { + 4 & e && this.palette.overwrite(new Uint16Array(t.SIZE_PALETTE >> 1)), 8 & e && this.vram.insert(0, new Uint16Array(t.SIZE_VRAM >> 1)), 16 & e && (this.oam.overwrite(new Uint16Array(t.SIZE_OAM >> 1)), this.oam.video = this) +}, GameBoyAdvanceSoftwareRenderer.prototype.freeze = function() {}, GameBoyAdvanceSoftwareRenderer.prototype.defrost = function(t) {}, GameBoyAdvanceSoftwareRenderer.prototype.setBacking = function(t) { + this.pixelData = t; + for (var e = 0; e < this.HORIZONTAL_PIXELS * this.VERTICAL_PIXELS * 4;) this.pixelData.data[e++] = 255, this.pixelData.data[e++] = 255, this.pixelData.data[e++] = 255, this.pixelData.data[e++] = 255 +}, GameBoyAdvanceSoftwareRenderer.prototype.writeDisplayControl = function(t) { + this.backgroundMode = 7 & t, this.displayFrameSelect = 16 & t, this.hblankIntervalFree = 32 & t, this.objCharacterMapping = 64 & t, this.forcedBlank = 128 & t, this.bg[0].enabled = 256 & t, this.bg[1].enabled = 512 & t, this.bg[2].enabled = 1024 & t, this.bg[3].enabled = 2048 & t, this.objLayers[0].enabled = 4096 & t, this.objLayers[1].enabled = 4096 & t, this.objLayers[2].enabled = 4096 & t, this.objLayers[3].enabled = 4096 & t, this.win0 = 8192 & t, this.win1 = 16384 & t, this.objwin = 32768 & t, this.objwinLayer.enabled = 4096 & t && 32768 & t, this.bg[2].multipalette &= -2, this.bg[3].multipalette &= -2, 0 < this.backgroundMode && (this.bg[2].multipalette |= 1), 2 == this.backgroundMode && (this.bg[3].multipalette |= 1), this.resetLayers() +}, GameBoyAdvanceSoftwareRenderer.prototype.writeBackgroundControl = function(t, e) { + var i = this.bg[t]; + i.priority = 3 & e, i.charBase = (12 & e) << 12, i.mosaic = 64 & e, i.multipalette &= -129, (t < 2 || 0 == this.backgroundMode) && (i.multipalette |= 128 & e), i.screenBase = (7936 & e) << 3, i.overflow = 8192 & e, i.size = (49152 & e) >> 14, this.drawLayers.sort(this.layerComparator) +}, GameBoyAdvanceSoftwareRenderer.prototype.writeBackgroundHOffset = function(t, e) { + this.bg[t].x = 511 & e +}, GameBoyAdvanceSoftwareRenderer.prototype.writeBackgroundVOffset = function(t, e) { + this.bg[t].y = 511 & e +}, GameBoyAdvanceSoftwareRenderer.prototype.writeBackgroundRefX = function(t, e) { + this.bg[t].refx = (e << 4) / 4096, this.bg[t].sx = this.bg[t].refx +}, GameBoyAdvanceSoftwareRenderer.prototype.writeBackgroundRefY = function(t, e) { + this.bg[t].refy = (e << 4) / 4096, this.bg[t].sy = this.bg[t].refy +}, GameBoyAdvanceSoftwareRenderer.prototype.writeBackgroundParamA = function(t, e) { + this.bg[t].dx = (e << 16) / 16777216 +}, GameBoyAdvanceSoftwareRenderer.prototype.writeBackgroundParamB = function(t, e) { + this.bg[t].dmx = (e << 16) / 16777216 +}, GameBoyAdvanceSoftwareRenderer.prototype.writeBackgroundParamC = function(t, e) { + this.bg[t].dy = (e << 16) / 16777216 +}, GameBoyAdvanceSoftwareRenderer.prototype.writeBackgroundParamD = function(t, e) { + this.bg[t].dmy = (e << 16) / 16777216 +}, GameBoyAdvanceSoftwareRenderer.prototype.writeWin0H = function(t) { + this.win0Left = (65280 & t) >> 8, this.win0Right = Math.min(this.HORIZONTAL_PIXELS, 255 & t), this.win0Left > this.win0Right && (this.win0Right = this.HORIZONTAL_PIXELS) +}, GameBoyAdvanceSoftwareRenderer.prototype.writeWin1H = function(t) { + this.win1Left = (65280 & t) >> 8, this.win1Right = Math.min(this.HORIZONTAL_PIXELS, 255 & t), this.win1Left > this.win1Right && (this.win1Right = this.HORIZONTAL_PIXELS) +}, GameBoyAdvanceSoftwareRenderer.prototype.writeWin0V = function(t) { + this.win0Top = (65280 & t) >> 8, this.win0Bottom = Math.min(this.VERTICAL_PIXELS, 255 & t), this.win0Top > this.win0Bottom && (this.win0Bottom = this.VERTICAL_PIXELS) +}, GameBoyAdvanceSoftwareRenderer.prototype.writeWin1V = function(t) { + this.win1Top = (65280 & t) >> 8, this.win1Bottom = Math.min(this.VERTICAL_PIXELS, 255 & t), this.win1Top > this.win1Bottom && (this.win1Bottom = this.VERTICAL_PIXELS) +}, GameBoyAdvanceSoftwareRenderer.prototype.writeWindow = function(t, e) { + var i = this.windows[t]; + i.enabled[0] = 1 & e, i.enabled[1] = 2 & e, i.enabled[2] = 4 & e, i.enabled[3] = 8 & e, i.enabled[4] = 16 & e, i.special = 32 & e +}, GameBoyAdvanceSoftwareRenderer.prototype.writeWinIn = function(t) { + this.writeWindow(0, t), this.writeWindow(1, t >> 8) +}, GameBoyAdvanceSoftwareRenderer.prototype.writeWinOut = function(t) { + this.writeWindow(2, t), this.writeWindow(3, t >> 8) +}, GameBoyAdvanceSoftwareRenderer.prototype.writeBlendControl = function(t) { + switch (this.target1[0] = !!(1 & t) * this.TARGET1_MASK, this.target1[1] = !!(2 & t) * this.TARGET1_MASK, this.target1[2] = !!(4 & t) * this.TARGET1_MASK, this.target1[3] = !!(8 & t) * this.TARGET1_MASK, this.target1[4] = !!(16 & t) * this.TARGET1_MASK, this.target1[5] = !!(32 & t) * this.TARGET1_MASK, this.target2[0] = !!(256 & t) * this.TARGET2_MASK, this.target2[1] = !!(512 & t) * this.TARGET2_MASK, this.target2[2] = !!(1024 & t) * this.TARGET2_MASK, this.target2[3] = !!(2048 & t) * this.TARGET2_MASK, this.target2[4] = !!(4096 & t) * this.TARGET2_MASK, this.target2[5] = !!(8192 & t) * this.TARGET2_MASK, this.blendMode = (192 & t) >> 6, this.blendMode) { + case 1: + case 0: + this.palette.makeNormalPalettes(); + break; + case 2: + this.palette.makeBrightPalettes(63 & t); + break; + case 3: + this.palette.makeDarkPalettes(63 & t) + } +}, GameBoyAdvanceSoftwareRenderer.prototype.setBlendEnabled = function(t, e, i) { + if (this.alphaEnabled = e && 1 == i, e) switch (i) { + case 1: + case 0: + this.palette.makeNormalPalette(t); + break; + case 2: + case 3: + this.palette.makeSpecialPalette(t) + } else this.palette.makeNormalPalette(t) +}, GameBoyAdvanceSoftwareRenderer.prototype.writeBlendAlpha = function(t) { + this.blendA = (31 & t) / 16, 1 < this.blendA && (this.blendA = 1), this.blendB = ((7936 & t) >> 8) / 16, 1 < this.blendB && (this.blendB = 1) +}, GameBoyAdvanceSoftwareRenderer.prototype.writeBlendY = function(t) { + this.blendY = t, this.palette.setBlendY(16 <= t ? 1 : t / 16) +}, GameBoyAdvanceSoftwareRenderer.prototype.writeMosaic = function(t) { + this.bgMosaicX = 1 + (15 & t), this.bgMosaicY = 1 + (t >> 4 & 15), this.objMosaicX = 1 + (t >> 8 & 15), this.objMosaicY = 1 + (t >> 12 & 15) +}, GameBoyAdvanceSoftwareRenderer.prototype.resetLayers = function() { + 1 < this.backgroundMode && (this.bg[0].enabled = !1, this.bg[1].enabled = !1), this.bg[2].enabled && (this.bg[2].drawScanline = this.bgModes[this.backgroundMode]), 0 == this.backgroundMode || 2 == this.backgroundMode ? this.bg[3].enabled && (this.bg[3].drawScanline = this.bgModes[this.backgroundMode]) : this.bg[3].enabled = !1, this.drawLayers.sort(this.layerComparator) +}, GameBoyAdvanceSoftwareRenderer.prototype.layerComparator = function(t, e) { + var i = e.priority - t.priority; + return i || (t.bg && !e.bg ? -1 : !t.bg && e.bg ? 1 : e.index - t.index) +}, GameBoyAdvanceSoftwareRenderer.prototype.accessMapMode0 = function(t, e, i, r, s) { + var n = t + (i >> 2 & 62) + r; + 1 & e && (n += (256 & i) << 3); + var a = this.vram.loadU16(n); + s.tile = 1023 & a, s.hflip = 1024 & a, s.vflip = 2048 & a, s.palette = (61440 & a) >> 8 +}, GameBoyAdvanceSoftwareRenderer.prototype.accessMapMode1 = function(t, e, i, r, s) { + var n = t + (i >> 3) + r; + s.tile = this.vram.loadU8(n) +}, GameBoyAdvanceSoftwareRenderer.prototype.accessTile = function(t, e, i) { + var r = t + (e << 5); + return r |= i << 2, this.vram.load32(r) +}, GameBoyAdvanceSoftwareRenderer.pushPixel = function(t, e, i, r, s, n, a, o, h) { + var c; + if (!h) { + if (!(c = this.multipalette ? r >> (s << 3) & 255 : r >> (s << 2) & 15)) return; + this.multipalette || (c |= e.palette) + } + var u = i.WRITTEN_MASK, + d = a.stencil[n], + p = i.blendMode; + if (i.objwinActive) + if (d & i.OBJWIN_MASK) { + if (!i.windows[3].enabled[t]) return; + i.setBlendEnabled(t, i.windows[3].special && i.target1[t], p), i.windows[3].special && i.alphaEnabled && (o |= i.target1[t]), u |= i.OBJWIN_MASK + } else { + if (!i.windows[2].enabled[t]) return; + i.setBlendEnabled(t, i.windows[2].special && i.target1[t], p), i.windows[2].special && i.alphaEnabled && (o |= i.target1[t]) + } + o & i.TARGET1_MASK && d & i.TARGET2_MASK && i.setBlendEnabled(t, !0, 1); + var l = h ? r : i.palette.accessColor(t, c); + o & i.TARGET1_MASK && i.setBlendEnabled(t, !!p, p); + var f = (o & i.PRIORITY_MASK) < (d & i.PRIORITY_MASK); + if ((o & i.PRIORITY_MASK) == (d & i.PRIORITY_MASK) && (f = o & i.BACKGROUND_MASK), d & i.WRITTEN_MASK) + if (f) o & i.TARGET1_MASK && d & i.TARGET2_MASK && (l = i.palette.mix(i.blendA, l, i.blendB, a.color[n])), u |= o & ~i.TARGET1_MASK; + else { + if (!((o & i.PRIORITY_MASK) > (d & i.PRIORITY_MASK))) return; + if (u = d & ~(i.TARGET1_MASK | i.TARGET2_MASK), !(o & i.TARGET2_MASK && d & i.TARGET1_MASK)) return; + l = i.palette.mix(i.blendB, l, i.blendA, a.color[n]) + } else u |= o; + o & i.OBJWIN_MASK ? a.stencil[n] |= i.OBJWIN_MASK : (a.color[n] = l, a.stencil[n] = u) +}, GameBoyAdvanceSoftwareRenderer.prototype.identity = function(t) { + return t +}, GameBoyAdvanceSoftwareRenderer.prototype.drawScanlineBlank = function(t) { + for (var e = 0; e < this.HORIZONTAL_PIXELS; ++e) t.color[e] = 65535, t.stencil[e] = 0 +}, GameBoyAdvanceSoftwareRenderer.prototype.prepareScanline = function(t) { + for (var e = 0; e < this.HORIZONTAL_PIXELS; ++e) t.stencil[e] = this.target2[this.LAYER_BACKDROP] +}, GameBoyAdvanceSoftwareRenderer.prototype.drawScanlineBGMode0 = function(t, e, i, r) { + var s, n, a, o = this.video, + h = o.vcount, + c = i, + u = e.x, + d = h + e.y; + this.mosaic && (d -= h % o.bgMosaicY); + var p, l = 7 & d, + f = e.screenBase, + m = e.charBase, + y = e.size, + v = e.index, + A = o.sharedMap, + b = e.multipalette ? 1 : 0, + g = o.target2[v] | e.priority << 1 | o.BACKGROUND_MASK; + 1 == o.blendMode && o.alphaEnabled && (g |= o.target1[v]); + var S, R = d << 3 & 1984; + 2 == y ? R += d << 3 & 2048 : 3 == y && (R += d << 4 & 4096), S = 1 & y ? 511 : 255, o.accessMapMode0(f, y, i + u & S, R, A); + var C = o.accessTile(m, A.tile << b, (A.vflip ? 7 - l : l) << b); + for (s = i; s < r; ++s) { + if (n = s + u & S, a = 7 & (n -= p = this.mosaic ? c % o.bgMosaicX : 0), b) { + if ((!a || this.mosaic && !p) && o.accessMapMode0(f, y, n, R, A), (!(3 & a) || this.mosaic && !p) && !((C = o.accessTile(m + (!!(4 & n) == !A.hflip ? 4 : 0), A.tile << 1, (A.vflip ? 7 - l : l) << 1)) || 3 & a)) { + s += 3, c += 4; + continue + } + } else if ((!a || this.mosaic && !p) && (o.accessMapMode0(f, y, n, R, A), !(C = o.accessTile(m, A.tile, A.vflip ? 7 - l : l)) && !a)) { + s += 7, c += 8; + continue + } + A.hflip && (a = 7 - a), e.pushPixel(v, A, o, C, a, c, t, g, !1), c++ + } +}, GameBoyAdvanceSoftwareRenderer.prototype.drawScanlineBGMode2 = function(t, e, i, r) { + var s, n, a, o, h, c = this.video, + u = c.vcount, + d = i, + p = e.screenBase, + l = e.charBase, + f = e.size, + m = 128 << f, + y = e.index, + v = c.sharedMap, + A = c.target2[y] | e.priority << 1 | c.BACKGROUND_MASK; + for (1 == c.blendMode && c.alphaEnabled && (A |= c.target1[y]), s = i; s < r; ++s) { + if (n = e.dx * s + e.sx, a = e.dy * s + e.sy, this.mosaic && (n -= s % c.bgMosaicX * e.dx + u % c.bgMosaicY * e.dmx, a -= s % c.bgMosaicX * e.dy + u % c.bgMosaicY * e.dmy), e.overflow)(n &= m - 1) < 0 && (n += m), (a &= m - 1) < 0 && (a += m); + else if (n < 0 || a < 0 || m <= n || m <= a) { + d++; + continue + } + h = (a << 1 & 2032) << f, c.accessMapMode1(p, f, n, h, v), o = this.vram.loadU8(l + (v.tile << 6) + ((7 & a) << 3) + (7 & n)), e.pushPixel(y, v, c, o, 0, d, t, A, !1), d++ + } +}, GameBoyAdvanceSoftwareRenderer.prototype.drawScanlineBGMode3 = function(t, e, i, r) { + var s, n, a, o, h = this.video, + c = h.vcount, + u = i, + d = e.index, + p = h.sharedMap, + l = h.target2[d] | e.priority << 1 | h.BACKGROUND_MASK; + for (1 == h.blendMode && h.alphaEnabled && (l |= h.target1[d]), s = i; s < r; ++s) n = e.dx * s + e.sx, a = e.dy * s + e.sy, this.mosaic && (n -= s % h.bgMosaicX * e.dx + c % h.bgMosaicY * e.dmx, a -= s % h.bgMosaicX * e.dy + c % h.bgMosaicY * e.dmy), n < 0 || a < 0 || n >= h.HORIZONTAL_PIXELS || a >= h.VERTICAL_PIXELS || (o = this.vram.loadU16(a * h.HORIZONTAL_PIXELS + n << 1), e.pushPixel(d, p, h, o, 0, u, t, l, !0)), u++ +}, GameBoyAdvanceSoftwareRenderer.prototype.drawScanlineBGMode4 = function(t, e, i, r) { + var s, n, a, o = this.video, + h = o.vcount, + c = i, + u = 0; + o.displayFrameSelect && (u += 40960); + e.size; + var d, p = e.index, + l = o.sharedMap, + f = o.target2[p] | e.priority << 1 | o.BACKGROUND_MASK; + for (1 == o.blendMode && o.alphaEnabled && (f |= o.target1[p]), s = i; s < r; ++s) n = e.dx * s + e.sx, a = 0 | e.dy * s + e.sy, this.mosaic && (n -= s % o.bgMosaicX * e.dx + h % o.bgMosaicY * e.dmx, a -= s % o.bgMosaicX * e.dy + h % o.bgMosaicY * e.dmy), a << 2 & 2016, n < 0 || a < 0 || n >= o.HORIZONTAL_PIXELS || a >= o.VERTICAL_PIXELS || (d = this.vram.loadU8(u + a * o.HORIZONTAL_PIXELS + n), e.pushPixel(p, l, o, d, 0, c, t, f, !1)), c++ +}, GameBoyAdvanceSoftwareRenderer.prototype.drawScanlineBGMode5 = function(t, e, i, r) { + var s, n, a, o = this.video, + h = o.vcount, + c = i, + u = 0; + o.displayFrameSelect && (u += 40960); + var d, p = e.index, + l = o.sharedMap, + f = o.target2[p] | e.priority << 1 | o.BACKGROUND_MASK; + for (1 == o.blendMode && o.alphaEnabled && (f |= o.target1[p]), s = i; s < r; ++s) n = e.dx * s + e.sx, a = e.dy * s + e.sy, this.mosaic && (n -= s % o.bgMosaicX * e.dx + h % o.bgMosaicY * e.dmx, a -= s % o.bgMosaicX * e.dy + h % o.bgMosaicY * e.dmy), n < 0 || a < 0 || 160 <= n || 128 <= a || (d = this.vram.loadU16(u + (160 * a + n) << 1), e.pushPixel(p, l, o, d, 0, c, t, f, !0)), c++ +}, GameBoyAdvanceSoftwareRenderer.prototype.drawScanline = function(t) { + var e = this.scanline; + if (this.forcedBlank) this.drawScanlineBlank(e); + else { + var i, r, s, n, a; + this.prepareScanline(e), this.vcount = t; + for (var o = 0; o < this.drawLayers.length; ++o)(i = this.drawLayers[o]).enabled && (this.objwinActive = !1, this.win0 || this.win1 || this.objwin ? (r = 0, s = this.HORIZONTAL_PIXELS, n = 0, a = this.HORIZONTAL_PIXELS, this.win0 && t >= this.win0Top && t < this.win0Bottom && (this.windows[0].enabled[i.index] && (this.setBlendEnabled(i.index, this.windows[0].special && this.target1[i.index], this.blendMode), i.drawScanline(e, i, this.win0Left, this.win0Right)), r = Math.max(r, this.win0Left), s = Math.min(s, this.win0Left), n = Math.max(n, this.win0Right), a = Math.min(a, this.win0Right)), this.win1 && t >= this.win1Top && t < this.win1Bottom && (this.windows[1].enabled[i.index] && (this.setBlendEnabled(i.index, this.windows[1].special && this.target1[i.index], this.blendMode), !this.windows[0].enabled[i.index] && (this.win1Left < r || this.win1Right < n) ? (i.drawScanline(e, i, this.win1Left, r), i.drawScanline(e, i, a, this.win1Right)) : i.drawScanline(e, i, this.win1Left, this.win1Right)), r = Math.max(r, this.win1Left), s = Math.min(s, this.win1Left), n = Math.max(n, this.win1Right), a = Math.min(a, this.win1Right)), (this.windows[2].enabled[i.index] || this.objwin && this.windows[3].enabled[i.index]) && (this.objwinActive = this.objwin, this.setBlendEnabled(i.index, this.windows[2].special && this.target1[i.index], this.blendMode), n < s ? i.drawScanline(e, i, 0, this.HORIZONTAL_PIXELS) : (s && i.drawScanline(e, i, 0, s), n < this.HORIZONTAL_PIXELS && i.drawScanline(e, i, n, this.HORIZONTAL_PIXELS), a < r && i.drawScanline(e, i, a, r))), this.setBlendEnabled(this.LAYER_BACKDROP, this.target1[this.LAYER_BACKDROP] && this.windows[2].special, this.blendMode)) : (this.setBlendEnabled(i.index, this.target1[i.index], this.blendMode), i.drawScanline(e, i, 0, this.HORIZONTAL_PIXELS)), i.bg && (i.sx += i.dmx, i.sy += i.dmy)); + this.finishScanline(e) + } +}, GameBoyAdvanceSoftwareRenderer.prototype.finishScanline = function(t) { + for (var e, i = this.palette.accessColor(this.LAYER_BACKDROP, 0), r = this.vcount * this.HORIZONTAL_PIXELS * 4, s = this.target2[this.LAYER_BACKDROP], n = 0; n < this.HORIZONTAL_PIXELS; ++n) t.stencil[n] & this.WRITTEN_MASK ? (e = t.color[n], s && t.stencil[n] & this.TARGET1_MASK && (e = this.palette.mix(this.blendA, e, this.blendB, i)), this.palette.convert16To32(e, this.sharedColor)) : this.palette.convert16To32(i, this.sharedColor), this.pixelData.data[r++] = this.sharedColor[0], this.pixelData.data[r++] = this.sharedColor[1], this.pixelData.data[r++] = this.sharedColor[2], r++ +}, GameBoyAdvanceSoftwareRenderer.prototype.startDraw = function() {}, GameBoyAdvanceSoftwareRenderer.prototype.finishDraw = function(t) { + this.bg[2].sx = this.bg[2].refx, this.bg[2].sy = this.bg[2].refy, this.bg[3].sx = this.bg[3].refx, this.bg[3].sy = this.bg[3].refy, t.finishDraw(this.pixelData) +}, GameBoyAdvanceInterruptHandler.prototype.clear = function() { + this.enable = !1, this.enabledIRQs = 0, this.interruptFlags = 0, this.dma = new Array; + for (var t = 0; t < 4; ++t) this.dma.push({ + source: 0, + dest: 0, + count: 0, + nextSource: 0, + nextDest: 0, + nextCount: 0, + srcControl: 0, + dstControl: 0, + repeat: !1, + width: 0, + drq: !1, + timing: 0, + doIrq: !1, + enable: !1, + nextIRQ: 0 + }); + this.timersEnabled = 0, this.timers = new Array; + for (t = 0; t < 4; ++t) this.timers.push({ + reload: 0, + oldReload: 0, + prescaleBits: 0, + countUp: !1, + doIrq: !1, + enable: !1, + lastEvent: 0, + nextEvent: 0, + overflowInterval: 1 + }); + this.nextEvent = 0, this.springIRQ = !1, this.resetSP() +}, GameBoyAdvanceInterruptHandler.prototype.freeze = function() { + return { + enable: this.enable, + enabledIRQs: this.enabledIRQs, + interruptFlags: this.interruptFlags, + dma: this.dma, + timers: this.timers, + nextEvent: this.nextEvent, + springIRQ: this.springIRQ + } +}, GameBoyAdvanceInterruptHandler.prototype.defrost = function(t) { + this.enable = t.enable, this.enabledIRQs = t.enabledIRQs, this.interruptFlags = t.interruptFlags, this.dma = t.dma, this.timers = t.timers, this.timersEnabled = 0, this.timers[0].enable && ++this.timersEnabled, this.timers[1].enable && ++this.timersEnabled, this.timers[2].enable && ++this.timersEnabled, this.timers[3].enable && ++this.timersEnabled, this.nextEvent = t.nextEvent, this.springIRQ = t.springIRQ +}, GameBoyAdvanceInterruptHandler.prototype.updateTimers = function() { + if (!(this.nextEvent > this.cpu.cycles)) { + if (this.springIRQ && (this.cpu.raiseIRQ(), this.springIRQ = !1), this.video.updateTimers(this.cpu), this.audio.updateTimers(), this.timersEnabled) { + var t = this.timers[0]; + t.enable && this.cpu.cycles >= t.nextEvent && (t.lastEvent = t.nextEvent, t.nextEvent += t.overflowInterval, this.io.registers[this.io.TM0CNT_LO >> 1] = t.reload, t.oldReload = t.reload, t.doIrq && this.raiseIRQ(this.IRQ_TIMER0), this.audio.enabled && (this.audio.enableChannelA && !this.audio.soundTimerA && 0 <= this.audio.dmaA && this.audio.sampleFifoA(), this.audio.enableChannelB && !this.audio.soundTimerB && 0 <= this.audio.dmaB && this.audio.sampleFifoB()), (t = this.timers[1]).countUp && 65536 == ++this.io.registers[this.io.TM1CNT_LO >> 1] && (t.nextEvent = this.cpu.cycles)), (t = this.timers[1]).enable && this.cpu.cycles >= t.nextEvent && (t.lastEvent = t.nextEvent, t.nextEvent += t.overflowInterval, t.countUp && 65536 != this.io.registers[this.io.TM1CNT_LO >> 1] || (this.io.registers[this.io.TM1CNT_LO >> 1] = t.reload), t.oldReload = t.reload, t.doIrq && this.raiseIRQ(this.IRQ_TIMER1), t.countUp && (t.nextEvent = 0), this.audio.enabled && (this.audio.enableChannelA && this.audio.soundTimerA && 0 <= this.audio.dmaA && this.audio.sampleFifoA(), this.audio.enableChannelB && this.audio.soundTimerB && 0 <= this.audio.dmaB && this.audio.sampleFifoB()), (t = this.timers[2]).countUp && 65536 == ++this.io.registers[this.io.TM2CNT_LO >> 1] && (t.nextEvent = this.cpu.cycles)), (t = this.timers[2]).enable && this.cpu.cycles >= t.nextEvent && (t.lastEvent = t.nextEvent, t.nextEvent += t.overflowInterval, t.countUp && 65536 != this.io.registers[this.io.TM2CNT_LO >> 1] || (this.io.registers[this.io.TM2CNT_LO >> 1] = t.reload), t.oldReload = t.reload, t.doIrq && this.raiseIRQ(this.IRQ_TIMER2), t.countUp && (t.nextEvent = 0), (t = this.timers[3]).countUp && 65536 == ++this.io.registers[this.io.TM3CNT_LO >> 1] && (t.nextEvent = this.cpu.cycles)), (t = this.timers[3]).enable && this.cpu.cycles >= t.nextEvent && (t.lastEvent = t.nextEvent, t.nextEvent += t.overflowInterval, t.countUp && 65536 != this.io.registers[this.io.TM3CNT_LO >> 1] || (this.io.registers[this.io.TM3CNT_LO >> 1] = t.reload), t.oldReload = t.reload, t.doIrq && this.raiseIRQ(this.IRQ_TIMER3), t.countUp && (t.nextEvent = 0)) + } + var e = this.dma[0]; + e.enable && e.doIrq && e.nextIRQ && this.cpu.cycles >= e.nextIRQ && (e.nextIRQ = 0, this.raiseIRQ(this.IRQ_DMA0)), (e = this.dma[1]).enable && e.doIrq && e.nextIRQ && this.cpu.cycles >= e.nextIRQ && (e.nextIRQ = 0, this.raiseIRQ(this.IRQ_DMA1)), (e = this.dma[2]).enable && e.doIrq && e.nextIRQ && this.cpu.cycles >= e.nextIRQ && (e.nextIRQ = 0, this.raiseIRQ(this.IRQ_DMA2)), (e = this.dma[3]).enable && e.doIrq && e.nextIRQ && this.cpu.cycles >= e.nextIRQ && (e.nextIRQ = 0, this.raiseIRQ(this.IRQ_DMA3)), this.pollNextEvent() + } +}, GameBoyAdvanceInterruptHandler.prototype.resetSP = function() { + this.cpu.switchMode(this.cpu.MODE_SUPERVISOR), this.cpu.gprs[this.cpu.SP] = 50364384, this.cpu.switchMode(this.cpu.MODE_IRQ), this.cpu.gprs[this.cpu.SP] = 50364320, this.cpu.switchMode(this.cpu.MODE_SYSTEM), this.cpu.gprs[this.cpu.SP] = 50364160 +}, GameBoyAdvanceInterruptHandler.prototype.swi32 = function(t) { + this.swi(t >> 16) +}, GameBoyAdvanceInterruptHandler.prototype.swi = function(t) { + if (this.core.mmu.bios.real) this.cpu.raiseTrap(); + else switch (t) { + case 0: + for (var e = this.core.mmu.memory[this.core.mmu.REGION_WORKING_IRAM], i = e.loadU8(32762), r = 32256; r < 32768; r += 4) e.store32(r, 0); + this.resetSP(), this.cpu.gprs[this.cpu.LR] = i ? 33554432 : 134217728, this.cpu.switchExecMode(this.cpu.MODE_ARM), this.cpu.instruction.writesPC = !0, this.cpu.gprs[this.cpu.PC] = this.cpu.gprs[this.cpu.LR]; + break; + case 1: + var s = this.cpu.gprs[0]; + if (1 & s && (this.core.mmu.memory[this.core.mmu.REGION_WORKING_RAM] = new MemoryBlock(this.core.mmu.SIZE_WORKING_RAM, 9)), 2 & s) + for (r = 0; r < this.core.mmu.SIZE_WORKING_IRAM - 512; r += 4) this.core.mmu.memory[this.core.mmu.REGION_WORKING_IRAM].store32(r, 0); + 28 & s && this.video.renderPath.clearSubsets(this.core.mmu, s), 224 & s && this.core.STUB("Unimplemented RegisterRamReset"); + break; + case 2: + this.halt(); + break; + case 5: + this.cpu.gprs[0] = 1, this.cpu.gprs[1] = 1; + case 4: + if (this.enable || this.io.store16(this.io.IME, 1), !this.cpu.gprs[0] && this.interruptFlags & this.cpu.gprs[1]) return; + this.dismissIRQs(4294967295), this.cpu.raiseTrap(); + break; + case 6: + var n = (0 | this.cpu.gprs[0]) / (0 | this.cpu.gprs[1]), + a = (0 | this.cpu.gprs[0]) % (0 | this.cpu.gprs[1]); + this.cpu.gprs[0] = 0 | n, this.cpu.gprs[1] = 0 | a, this.cpu.gprs[3] = Math.abs(0 | n); + break; + case 7: + n = (0 | this.cpu.gprs[1]) / (0 | this.cpu.gprs[0]), a = (0 | this.cpu.gprs[1]) % (0 | this.cpu.gprs[0]); + this.cpu.gprs[0] = 0 | n, this.cpu.gprs[1] = 0 | a, this.cpu.gprs[3] = Math.abs(0 | n); + break; + case 8: + var o = Math.sqrt(this.cpu.gprs[0]); + this.cpu.gprs[0] = 0 | o; + break; + case 10: + var h = this.cpu.gprs[0] / 16384, + c = this.cpu.gprs[1] / 16384; + this.cpu.gprs[0] = Math.atan2(c, h) / (2 * Math.PI) * 65536; + break; + case 11: + var u = this.cpu.gprs[0], + d = this.cpu.gprs[1], + p = 1048575 & (m = this.cpu.gprs[2]), + l = 67108864 & m ? 4 : 2; + if (16777216 & m) + if (4 == l) { + u &= 4294967292, d &= 4294967292; + var f = this.cpu.mmu.load32(u); + for (r = 0; r < p; ++r) this.cpu.mmu.store32(d + (r << 2), f) + } else { + u &= 4294967294, d &= 4294967294; + for (f = this.cpu.mmu.load16(u), r = 0; r < p; ++r) this.cpu.mmu.store16(d + (r << 1), f) + } else if (4 == l) { + u &= 4294967292, d &= 4294967292; + for (r = 0; r < p; ++r) { + f = this.cpu.mmu.load32(u + (r << 2)); + this.cpu.mmu.store32(d + (r << 2), f) + } + } else { + u &= 4294967294, d &= 4294967294; + for (r = 0; r < p; ++r) { + f = this.cpu.mmu.load16(u + (r << 1)); + this.cpu.mmu.store16(d + (r << 1), f) + } + } + return; + case 12: + var m; + u = 4294967292 & this.cpu.gprs[0], d = 4294967292 & this.cpu.gprs[1]; + if (p = (p = 1048575 & (m = this.cpu.gprs[2])) + 7 >> 3 << 3, 16777216 & m) + for (f = this.cpu.mmu.load32(u), r = 0; r < p; ++r) this.cpu.mmu.store32(d + (r << 2), f); + else + for (r = 0; r < p; ++r) { + f = this.cpu.mmu.load32(u + (r << 2)); + this.cpu.mmu.store32(d + (r << 2), f) + } + return; + case 14: + r = this.cpu.gprs[2]; + for (var y, v, A, b, g, S, R = this.cpu.gprs[0], C = this.cpu.gprs[1]; r--;) y = this.core.mmu.load32(R) / 256, v = this.core.mmu.load32(R + 4) / 256, A = this.core.mmu.load16(R + 8), b = this.core.mmu.load16(R + 10), w = this.core.mmu.load16(R + 12) / 256, M = this.core.mmu.load16(R + 14) / 256, _ = (this.core.mmu.loadU16(R + 16) >> 8) / 128 * Math.PI, R += 20, I = T = Math.cos(_), E = O = Math.sin(_), g = y - ((I *= w) * A + (E *= -w) * b), S = v - ((O *= M) * A + (T *= M) * b), this.core.mmu.store16(C, 256 * I | 0), this.core.mmu.store16(C + 2, 256 * E | 0), this.core.mmu.store16(C + 4, 256 * O | 0), this.core.mmu.store16(C + 6, 256 * T | 0), this.core.mmu.store32(C + 8, 256 * g | 0), this.core.mmu.store32(C + 12, 256 * S | 0), C += 16; + break; + case 15: + r = this.cpu.gprs[2], R = this.cpu.gprs[0], C = this.cpu.gprs[1]; + for (var w, M, _, I, E, O, T, P = this.cpu.gprs[3]; r--;) w = this.core.mmu.load16(R) / 256, M = this.core.mmu.load16(R + 2) / 256, _ = (this.core.mmu.loadU16(R + 4) >> 8) / 128 * Math.PI, R += 6, I = T = Math.cos(_), E = O = Math.sin(_), I *= w, E *= -w, O *= M, T *= M, this.core.mmu.store16(C, 256 * I | 0), this.core.mmu.store16(C + P, 256 * E | 0), this.core.mmu.store16(C + 2 * P, 256 * O | 0), this.core.mmu.store16(C + 3 * P, 256 * T | 0), C += 4 * P; + break; + case 17: + this.lz77(this.cpu.gprs[0], this.cpu.gprs[1], 1); + break; + case 18: + this.lz77(this.cpu.gprs[0], this.cpu.gprs[1], 2); + break; + case 19: + this.huffman(this.cpu.gprs[0], this.cpu.gprs[1]); + break; + case 20: + this.rl(this.cpu.gprs[0], this.cpu.gprs[1], 1); + break; + case 21: + this.rl(this.cpu.gprs[0], this.cpu.gprs[1], 2); + break; + case 31: + var B = this.cpu.mmu.load32(this.cpu.gprs[0] + 4); + this.cpu.gprs[0] = B / Math.pow(2, (180 - this.cpu.gprs[1] - this.cpu.gprs[2] / 256) / 12) >>> 0; + break; + default: + throw "Unimplemented software interrupt: 0x" + t.toString(16) + } +}, GameBoyAdvanceInterruptHandler.prototype.masterEnable = function(t) { + this.enable = t, this.enable && this.enabledIRQs & this.interruptFlags && this.cpu.raiseIRQ() +}, GameBoyAdvanceInterruptHandler.prototype.setInterruptsEnabled = function(t) { + this.enabledIRQs = t, this.enabledIRQs & this.MASK_SIO && this.core.STUB("Serial I/O interrupts not implemented"), this.enabledIRQs & this.MASK_KEYPAD && this.core.STUB("Keypad interrupts not implemented"), this.enable && this.enabledIRQs & this.interruptFlags && this.cpu.raiseIRQ() +}, GameBoyAdvanceInterruptHandler.prototype.pollNextEvent = function() { + var t, e = this.video.nextEvent; + if (this.audio.enabled && (t = this.audio.nextEvent, (!e || t < e) && (e = t)), this.timersEnabled) { + var i = this.timers[0]; + t = i.nextEvent, i.enable && t && (!e || t < e) && (e = t), t = (i = this.timers[1]).nextEvent, i.enable && t && (!e || t < e) && (e = t), t = (i = this.timers[2]).nextEvent, i.enable && t && (!e || t < e) && (e = t), t = (i = this.timers[3]).nextEvent, i.enable && t && (!e || t < e) && (e = t) + } + var r = this.dma[0]; + t = r.nextIRQ, r.enable && r.doIrq && t && (!e || t < e) && (e = t), t = (r = this.dma[1]).nextIRQ, r.enable && r.doIrq && t && (!e || t < e) && (e = t), t = (r = this.dma[2]).nextIRQ, r.enable && r.doIrq && t && (!e || t < e) && (e = t), t = (r = this.dma[3]).nextIRQ, r.enable && r.doIrq && t && (!e || t < e) && (e = t), this.core.ASSERT(e >= this.cpu.cycles, "Next event is before present"), this.nextEvent = e +}, GameBoyAdvanceInterruptHandler.prototype.waitForIRQ = function() { + var t, e = this.testIRQ() || this.video.hblankIRQ || this.video.vblankIRQ || this.video.vcounterIRQ; + if (this.timersEnabled && (t = this.timers[0], e = e || t.doIrq, t = this.timers[1], e = e || t.doIrq, t = this.timers[2], e = e || t.doIrq, t = this.timers[3], e = e || t.doIrq), !e) return !1; + for (;;) { + if (this.pollNextEvent(), !this.nextEvent) return !1; + if (this.cpu.cycles = this.nextEvent, this.updateTimers(), this.interruptFlags) return !0 + } +}, GameBoyAdvanceInterruptHandler.prototype.testIRQ = function() { + return !!(this.enable && this.enabledIRQs & this.interruptFlags) && (this.springIRQ = !0, this.nextEvent = this.cpu.cycles, !0) +}, GameBoyAdvanceInterruptHandler.prototype.raiseIRQ = function(t) { + this.interruptFlags |= 1 << t, this.io.registers[this.io.IF >> 1] = this.interruptFlags, this.enable && this.enabledIRQs & 1 << t && this.cpu.raiseIRQ() +}, GameBoyAdvanceInterruptHandler.prototype.dismissIRQs = function(t) { + this.interruptFlags &= ~t, this.io.registers[this.io.IF >> 1] = this.interruptFlags +}, GameBoyAdvanceInterruptHandler.prototype.dmaSetSourceAddress = function(t, e) { + this.dma[t].source = 4294967294 & e +}, GameBoyAdvanceInterruptHandler.prototype.dmaSetDestAddress = function(t, e) { + this.dma[t].dest = 4294967294 & e +}, GameBoyAdvanceInterruptHandler.prototype.dmaSetWordCount = function(t, e) { + this.dma[t].count = e || (3 == t ? 65536 : 16384) +}, GameBoyAdvanceInterruptHandler.prototype.dmaWriteControl = function(t, e) { + var i = this.dma[t], + r = i.enable; + i.dstControl = (96 & e) >> 5, i.srcControl = (384 & e) >> 7, i.repeat = !!(512 & e), i.width = 1024 & e ? 4 : 2, i.drq = !!(2048 & e), i.timing = (12288 & e) >> 12, i.doIrq = !!(16384 & e), i.enable = !!(32768 & e), i.nextIRQ = 0, i.drq && this.core.WARN("DRQ not implemented"), !r && i.enable && (i.nextSource = i.source, i.nextDest = i.dest, i.nextCount = i.count, this.cpu.mmu.scheduleDma(t, i)) +}, GameBoyAdvanceInterruptHandler.prototype.timerSetReload = function(t, e) { + this.timers[t].reload = 65535 & e +}, GameBoyAdvanceInterruptHandler.prototype.timerWriteControl = function(t, e) { + var i = this.timers[t], + r = i.prescaleBits; + switch (3 & e) { + case 0: + i.prescaleBits = 0; + break; + case 1: + i.prescaleBits = 6; + break; + case 2: + i.prescaleBits = 8; + break; + case 3: + i.prescaleBits = 10 + } + i.countUp = !!(4 & e), i.doIrq = !!(64 & e), i.overflowInterval = 65536 - i.reload << i.prescaleBits; + var s = i.enable; + i.enable = !!((128 & e) >> 7 << t), !s && i.enable ? (i.countUp ? i.nextEvent = 0 : (i.lastEvent = this.cpu.cycles, i.nextEvent = this.cpu.cycles + i.overflowInterval), this.io.registers[this.io.TM0CNT_LO + (t << 2) >> 1] = i.reload, i.oldReload = i.reload, ++this.timersEnabled) : s && !i.enable ? (i.countUp || (this.io.registers[this.io.TM0CNT_LO + (t << 2) >> 1] = i.oldReload + (this.cpu.cycles - i.lastEvent) >> r), --this.timersEnabled) : i.prescaleBits == r || i.countUp || (i.nextEvent = i.lastEvent + i.overflowInterval), this.pollNextEvent() +}, GameBoyAdvanceInterruptHandler.prototype.timerRead = function(t) { + var e = this.timers[t]; + return e.enable && !e.countUp ? e.oldReload + (this.cpu.cycles - e.lastEvent) >> e.prescaleBits : this.io.registers[this.io.TM0CNT_LO + (t << 2) >> 1] +}, GameBoyAdvanceInterruptHandler.prototype.halt = function() { + if (!this.enable) throw "Requested HALT when interrupts were disabled!"; + if (!this.waitForIRQ()) throw "Waiting on interrupt forever." +}, GameBoyAdvanceInterruptHandler.prototype.lz77 = function(t, e, i) { + for (var r, s, n, a, o, h = (4294967040 & this.cpu.mmu.load32(t)) >> 8, c = t + 4, u = e, d = 0, p = 0; 0 < h;) + if (d) { + if (128 & r) + for (s = this.cpu.mmu.loadU8(c) | this.cpu.mmu.loadU8(c + 1) << 8, c += 2, n = u - ((15 & s) << 8 | (65280 & s) >> 8) - 1, a = 3 + ((240 & s) >> 4); a-- && h;) o = this.cpu.mmu.loadU8(n++), 2 == i ? (p >>= 8, p |= o << 8, 1 & u && this.cpu.mmu.store16(u - 1, p)) : this.cpu.mmu.store8(u, o), --h, ++u; + else o = this.cpu.mmu.loadU8(c++), 2 == i ? (p >>= 8, p |= o << 8, 1 & u && this.cpu.mmu.store16(u - 1, p)) : this.cpu.mmu.store8(u, o), --h, ++u; + r <<= 1, --d + } else r = this.cpu.mmu.loadU8(c++), d = 8 +}, GameBoyAdvanceInterruptHandler.prototype.huffman = function(t, e) { + t &= 4294967292; + var i = this.cpu.mmu.load32(t), + r = i >> 8, + s = 15 & i; + if (32 % s) throw "Unimplemented unaligned Huffman"; + var n = 4 - r & 3; + r &= 4294967292; + var a, o, h, c = [], + u = 1 + (this.cpu.mmu.loadU8(t + 4) << 1), + d = t + 5 + u, + p = 4294967292 & e; + for (o = 0; o < u; ++o) c.push(this.cpu.mmu.loadU8(t + 5 + o)); + var l, f, m = 0, + y = 0; + for (h = c[0]; 0 < r;) { + var v = this.cpu.mmu.load32(d); + for (d += 4, l = 32; 0 < l; --l, v <<= 1) { + if ("number" == typeof h) { + var A = (m - 1 | 1) + ((63 & h) << 1) + 2; + h = { + l: A, + r: A + 1, + lTerm: 128 & h, + rTerm: 64 & h + }, c[m] = h + } + if (2147483648 & v) { + if (!h.rTerm) { + m = h.r, h = c[h.r]; + continue + } + f = c[h.r] + } else { + if (!h.lTerm) { + h = c[m = h.l]; + continue + } + f = c[h.l] + } + a |= (f & (1 << s) - 1) << y, y += s, h = c[m = 0], 32 == y && (y = 0, this.cpu.mmu.store32(p, a), p += 4, r -= 4, a = 0) + } + } + n && this.cpu.mmu.store32(p, a) +}, GameBoyAdvanceInterruptHandler.prototype.rl = function(t, e, i) { + t &= 4294967292; + for (var r, s, n = (4294967040 & this.cpu.mmu.load32(t)) >> 8, a = 4 - n & 3, o = t + 4, h = e, c = 0; 0 < n;) + if (128 & (r = this.cpu.mmu.loadU8(o++))) + for (r &= 127, r += 3, s = this.cpu.mmu.loadU8(o++); r-- && n;)--n, 2 == i ? (c >>= 8, c |= s << 8, 1 & h && this.cpu.mmu.store16(h - 1, c)) : this.cpu.mmu.store8(h, s), ++h; + else + for (r++; r-- && n;)--n, s = this.cpu.mmu.loadU8(o++), 2 == i ? (c >>= 8, c |= s << 8, 1 & h && this.cpu.mmu.store16(h - 1, c)) : this.cpu.mmu.store8(h, s), ++h; + for (; a--;) this.cpu.mmu.store8(h++, 0) +}, GameBoyAdvanceKeypad.prototype.keyboardHandler = function(t) { + var e = 0; + switch (t.keyCode) { + case this.KEYCODE_START: + e = this.START; + break; + case this.KEYCODE_SELECT: + e = this.SELECT; + break; + case this.KEYCODE_A: + e = this.A; + break; + case this.KEYCODE_B: + e = this.B; + break; + case this.KEYCODE_L: + e = this.L; + break; + case this.KEYCODE_R: + e = this.R; + break; + case this.KEYCODE_UP: + e = this.UP; + break; + case this.KEYCODE_RIGHT: + e = this.RIGHT; + break; + case this.KEYCODE_DOWN: + e = this.DOWN; + break; + case this.KEYCODE_LEFT: + e = this.LEFT; + break; + default: + return + } + e = 1 << e, this.currentDown |= e, "keydown" == t.type && (this.currentDown &= ~e), this.eatInput && t.preventDefault() +}, GameBoyAdvanceKeypad.prototype.gamepadHandler = function(t) { + var e = 0; + t.buttons[this.GAMEPAD_LEFT] > this.GAMEPAD_THRESHOLD && (e |= 1 << this.LEFT), t.buttons[this.GAMEPAD_UP] > this.GAMEPAD_THRESHOLD && (e |= 1 << this.UP), t.buttons[this.GAMEPAD_RIGHT] > this.GAMEPAD_THRESHOLD && (e |= 1 << this.RIGHT), t.buttons[this.GAMEPAD_DOWN] > this.GAMEPAD_THRESHOLD && (e |= 1 << this.DOWN), t.buttons[this.GAMEPAD_START] > this.GAMEPAD_THRESHOLD && (e |= 1 << this.START), t.buttons[this.GAMEPAD_SELECT] > this.GAMEPAD_THRESHOLD && (e |= 1 << this.SELECT), t.buttons[this.GAMEPAD_A] > this.GAMEPAD_THRESHOLD && (e |= 1 << this.A), t.buttons[this.GAMEPAD_B] > this.GAMEPAD_THRESHOLD && (e |= 1 << this.B), t.buttons[this.GAMEPAD_L] > this.GAMEPAD_THRESHOLD && (e |= 1 << this.L), t.buttons[this.GAMEPAD_R] > this.GAMEPAD_THRESHOLD && (e |= 1 << this.R), this.currentDown = 1023 & ~e +}, GameBoyAdvanceKeypad.prototype.gamepadConnectHandler = function(t) { + this.gamepads.push(t) +}, GameBoyAdvanceKeypad.prototype.gamepadDisconnectHandler = function(e) { + this.gamepads = self.gamepads.filter(function(t) { + return t != e + }) +}, GameBoyAdvanceKeypad.prototype.pollGamepads = function() { + var t = []; + navigator.webkitGetGamepads ? t = navigator.webkitGetGamepads() : navigator.getGamepads && (t = navigator.getGamepads()), t.length && (this.gamepads = []); + for (var e = 0; e < t.length; ++e) t[e] && this.gamepads.push(t[e]); + 0 < this.gamepads.length && this.gamepadHandler(this.gamepads[0]) +}, GameBoyAdvanceKeypad.prototype.joypadHander = function(t) { + var e = 1 << parseInt(t.target.value); + this.currentDown |= e, "mousedown" !== t.type && "touchstart" !== t.type || (this.currentDown &= ~e), this.eatInput && t.preventDefault() +}, GameBoyAdvanceKeypad.prototype.registerHandlers = function() { + window.addEventListener("keydown", this.keyboardHandler.bind(this), !0), window.addEventListener("keyup", this.keyboardHandler.bind(this), !0), window.addEventListener("gamepadconnected", this.gamepadConnectHandler.bind(this), !0), window.addEventListener("mozgamepadconnected", this.gamepadConnectHandler.bind(this), !0), window.addEventListener("webkitgamepadconnected", this.gamepadConnectHandler.bind(this), !0), window.addEventListener("gamepaddisconnected", this.gamepadDisconnectHandler.bind(this), !0), window.addEventListener("mozgamepaddisconnected", this.gamepadDisconnectHandler.bind(this), !0), window.addEventListener("webkitgamepaddisconnected", this.gamepadDisconnectHandler.bind(this), !0) +}, GameBoyAdvanceSIO.prototype.clear = function() { + this.mode = this.SIO_GPIO, this.sd = !1, this.irq = !1, this.multiplayer = { + baud: 0, + si: 0, + id: 0, + error: 0, + busy: 0, + states: [65535, 65535, 65535, 65535] + }, this.linkLayer = null +}, GameBoyAdvanceSIO.prototype.setMode = function(t) { + t &= 8 & t ? 12 : 3, this.mode = t, this.core.INFO("Setting SIO mode to " + hex(t, 1)) +}, GameBoyAdvanceSIO.prototype.writeRCNT = function(t) { + this.mode == this.SIO_GPIO && this.core.STUB("General purpose serial not supported") +}, GameBoyAdvanceSIO.prototype.writeSIOCNT = function(t) { + switch (this.mode) { + case this.SIO_NORMAL_8: + this.core.STUB("8-bit transfer unsupported"); + break; + case this.SIO_NORMAL_32: + this.core.STUB("32-bit transfer unsupported"); + break; + case this.SIO_MULTI: + this.multiplayer.baud = 3 & t, this.linkLayer && this.linkLayer.setBaud(this.BAUD[this.multiplayer.baud]), this.multiplayer.si || (this.multiplayer.busy = 128 & t, this.linkLayer && this.multiplayer.busy && this.linkLayer.startMultiplayerTransfer()), this.irq = 16384 & t; + break; + case this.SIO_UART: + this.core.STUB("UART unsupported"); + break; + case this.SIO_GPIO: + break; + case this.SIO_JOYBUS: + this.core.STUB("JOY BUS unsupported") + } +}, GameBoyAdvanceSIO.prototype.readSIOCNT = function() { + var t = this.mode << 12 & 65535; + switch (this.mode) { + case this.SIO_NORMAL_8: + this.core.STUB("8-bit transfer unsupported"); + break; + case this.SIO_NORMAL_32: + this.core.STUB("32-bit transfer unsupported"); + break; + case this.SIO_MULTI: + t |= this.multiplayer.baud, t |= this.multiplayer.si, t |= !!this.sd << 3, t |= this.multiplayer.id << 4, t |= this.multiplayer.error, t |= this.multiplayer.busy, t |= !!this.multiplayer.irq << 14; + break; + case this.SIO_UART: + this.core.STUB("UART unsupported"); + break; + case this.SIO_GPIO: + break; + case this.SIO_JOYBUS: + this.core.STUB("JOY BUS unsupported") + } + return t +}, GameBoyAdvanceSIO.prototype.read = function(t) { + switch (this.mode) { + case this.SIO_NORMAL_32: + this.core.STUB("32-bit transfer unsupported"); + break; + case this.SIO_MULTI: + return this.multiplayer.states[t]; + case this.SIO_UART: + this.core.STUB("UART unsupported"); + break; + default: + this.core.WARN("Reading from transfer register in unsupported mode") + } + return 0 +}, SRAMSavedata.prototype = Object.create(MemoryView.prototype), SRAMSavedata.prototype.store8 = function(t, e) { + this.view.setInt8(t, e), this.writePending = !0 +}, SRAMSavedata.prototype.store16 = function(t, e) { + this.view.setInt16(t, e, !0), this.writePending = !0 +}, SRAMSavedata.prototype.store32 = function(t, e) { + this.view.setInt32(t, e, !0), this.writePending = !0 +}, FlashSavedata.prototype = Object.create(MemoryView.prototype), FlashSavedata.prototype.load8 = function(t) { + return this.idMode && t < 2 ? this.id >> (t << 3) & 255 : t < 65536 ? this.bank.getInt8(t) : 0 +}, FlashSavedata.prototype.load16 = function(t) { + return 255 & this.load8(t) | this.load8(t + 1) << 8 +}, FlashSavedata.prototype.load32 = function(t) { + return 255 & this.load8(t) | this.load8(t + 1) << 8 | this.load8(t + 2) << 16 | this.load8(t + 3) << 24 +}, FlashSavedata.prototype.loadU8 = function(t) { + return 255 & this.load8(t) +}, FlashSavedata.prototype.loadU16 = function(t) { + return 255 & this.loadU8(t) | this.loadU8(t + 1) << 8 +}, FlashSavedata.prototype.store8 = function(t, e) { + switch (this.command) { + case 0: + if (21845 == t) + if (85 == this.second) { + switch (e) { + case this.COMMAND_ERASE: + this.pendingCommand = e; + break; + case this.COMMAND_ID: + this.idMode = !0; + break; + case this.COMMAND_TERMINATE_ID: + this.idMode = !1; + break; + default: + this.command = e + } + this.second = 0, this.first = 0 + } else this.command = 0, this.first = e, this.idMode = !1; + else 10922 == t && 170 == this.first && (this.first = 0, this.pendingCommand ? this.command = this.pendingCommand : this.second = e); + break; + case this.COMMAND_ERASE: + switch (e) { + case this.COMMAND_WIPE: + if (21845 == t) + for (var i = 0; i < this.view.byteLength; i += 4) this.view.setInt32(i, -1); + break; + case this.COMMAND_ERASE_SECTOR: + if (0 == (4095 & t)) + for (i = t; i < t + 4096; i += 4) this.bank.setInt32(i, -1) + } + this.pendingCommand = 0, this.command = 0; + break; + case this.COMMAND_WRITE: + this.bank.setInt8(t, e), this.command = 0, this.writePending = !0; + break; + case this.COMMAND_SWITCH_BANK: + this.bank1 && 0 == t && (this.bank = 1 == e ? this.bank1 : this.bank0), this.command = 0 + } +}, FlashSavedata.prototype.store16 = function(t, e) { + throw new Error("Unaligned save to flash!") +}, FlashSavedata.prototype.store32 = function(t, e) { + throw new Error("Unaligned save to flash!") +}, FlashSavedata.prototype.replaceData = function(t) { + var e = this.view === this.bank1; + MemoryView.prototype.replaceData.call(this, t, 0), this.bank0 = new DataView(this.buffer, 0, 65536), 65536 < t.byteLength ? this.bank1 = new DataView(this.buffer, 65536) : this.bank1 = null, this.bank = e ? this.bank1 : this.bank0 +}, EEPROMSavedata.prototype = Object.create(MemoryView.prototype), EEPROMSavedata.prototype.load8 = function(t) { + throw new Error("Unsupported 8-bit access!") +}, EEPROMSavedata.prototype.load16 = function(t) { + return this.loadU16(t) +}, EEPROMSavedata.prototype.loadU8 = function(t) { + throw new Error("Unsupported 8-bit access!") +}, EEPROMSavedata.prototype.loadU16 = function(t) { + if (this.command != this.COMMAND_READ || !this.dma.enable) return 1; + if (--this.readBitsRemaining, this.readBitsRemaining < 64) { + var e = 63 - this.readBitsRemaining, + i = this.view.getUint8(this.readAddress + e >> 3, !1) >> 7 - (7 & e); + return this.readBitsRemaining || (this.command = this.COMMAND_NULL), 1 & i + } + return 0 +}, EEPROMSavedata.prototype.load32 = function(t) { + throw new Error("Unsupported 32-bit access!") +}, EEPROMSavedata.prototype.store8 = function(t, e) { + throw new Error("Unsupported 8-bit access!") +}, EEPROMSavedata.prototype.store16 = function(t, e) { + switch (this.command) { + case this.COMMAND_NULL: + default: + this.command = 1 & e; + break; + case this.COMMAND_PENDING: + if (this.command <<= 1, this.command |= 1 & e, this.command == this.COMMAND_WRITE) { + if (!this.realSize) { + var i = this.dma.count - 67; + this.realSize = 8 << i, this.addressBits = i + } + this.commandBitsRemaining = this.addressBits + 64 + 1, this.writeAddress = 0 + } else { + if (!this.realSize) { + i = this.dma.count - 3; + this.realSize = 8 << i, this.addressBits = i + } + this.commandBitsRemaining = this.addressBits + 1, this.readAddress = 0 + } + break; + case this.COMMAND_WRITE: + if (64 < --this.commandBitsRemaining) this.writeAddress <<= 1, this.writeAddress |= (1 & e) << 6; + else if (this.commandBitsRemaining <= 0) this.command = this.COMMAND_NULL, this.writePending = !0; + else { + var r = this.view.getUint8(this.writeAddress >> 3); + r &= ~(1 << 7 - (7 & this.writeAddress)), r |= (1 & e) << 7 - (7 & this.writeAddress), this.view.setUint8(this.writeAddress >> 3, r), ++this.writeAddress + } + break; + case this.COMMAND_READ_PENDING: + 0 < --this.commandBitsRemaining ? (this.readAddress <<= 1, 1 & e && (this.readAddress |= 64)) : (this.readBitsRemaining = 68, this.command = this.COMMAND_READ) + } +}, EEPROMSavedata.prototype.store32 = function(t, e) { + throw new Error("Unsupported 32-bit access!") +}, EEPROMSavedata.prototype.replaceData = function(t) { + MemoryView.prototype.replaceData.call(this, t, 0) +}, GameBoyAdvanceGPIO.prototype.store16 = function(t, e) { + switch (t) { + case 196: + this.device.setPins(15 & e); + break; + case 198: + this.direction = 15 & e, this.device.setDirection(this.direction); + break; + case 200: + this.readWrite = 1 & e; + break; + default: + throw new Error("BUG: Bad offset passed to GPIO: " + t.toString(16)) + } + if (this.readWrite) { + var i = this.rom.view.getUint16(t, !0); + i &= ~this.direction, this.rom.view.setUint16(t, i | e & this.direction, !0) + } +}, GameBoyAdvanceGPIO.prototype.outputPins = function(t) { + if (this.readWrite) { + var e = this.rom.view.getUint16(196, !0); + e &= this.direction, this.rom.view.setUint16(196, e | t & ~this.direction & 15, !0) + } +}, GameBoyAdvanceRTC.prototype.setPins = function(t) { + switch (this.transferStep) { + case 0: + 1 == (5 & t) && (this.transferStep = 1); + break; + case 1: + 4 & t && (this.transferStep = 2); + break; + case 2: + 1 & t ? 4 & t ? 2 & this.direction && !this.read ? (++this.bitsRead, 8 == this.bitsRead && this.processByte()) : (this.gpio.outputPins(5 | this.sioOutputPin() << 1), ++this.bitsRead, 8 == this.bitsRead && (--this.bytesRemaining, this.bytesRemaining <= 0 && (this.command = -1), this.bitsRead = 0)) : (this.bitsRead = 0, this.bytesRemaining = 0, this.command = -1, this.transferStep = 0) : (this.bits &= ~(1 << this.bitsRead), this.bits |= (2 & t) >> 1 << this.bitsRead) + } + this.pins = 7 & t +}, GameBoyAdvanceRTC.prototype.setDirection = function(t) { + this.direction = t +}, GameBoyAdvanceRTC.prototype.processByte = function() { + switch (--this.bytesRemaining, this.command) { + case -1: + if (6 == (15 & this.bits)) switch (this.command = this.bits >> 4 & 7, this.reading = 128 & this.bits, this.bytesRemaining = this.totalBytes[this.command], this.command) { + case 0: + this.control = 0; + break; + case 2: + case 6: + this.updateClock() + } else this.gpio.core.WARN("Invalid RTC command byte: " + this.bits.toString(16)); + break; + case 4: + this.control = 64 & this.bits + } + this.bits = 0, this.bitsRead = 0, this.bytesRemaining || (this.command = -1) +}, GameBoyAdvanceRTC.prototype.sioOutputPin = function() { + var t = 0; + switch (this.command) { + case 4: + t = this.control; + break; + case 2: + case 6: + t = this.time[7 - this.bytesRemaining] + } + return t >> this.bitsRead & 1 +}, GameBoyAdvanceRTC.prototype.updateClock = function() { + var t = new Date; + this.time[0] = this.bcd(t.getFullYear()), this.time[1] = this.bcd(t.getMonth() + 1), this.time[2] = this.bcd(t.getDate()), this.time[3] = t.getDay() - 1, this.time[3] < 0 && (this.time[3] = 6), 64 & this.control ? this.time[4] = this.bcd(t.getHours()) : (this.time[4] = this.bcd(t.getHours() % 2), 12 <= t.getHours() && (this.time[4] |= 128)), this.time[5] = this.bcd(t.getMinutes()), this.time[6] = this.bcd(t.getSeconds()) +}, GameBoyAdvanceRTC.prototype.bcd = function(t) { + var e = t % 10; + return e += (t /= 10) % 10 << 4 +}, GameBoyAdvance.prototype.setCanvas = function(t) { + var e = this; + if (240 != t.offsetWidth || 160 != t.offsetHeight) { + this.indirectCanvas = document.createElement("canvas"), this.indirectCanvas.setAttribute("height", "160"), this.indirectCanvas.setAttribute("width", "240"), this.targetCanvas = t, this.setCanvasDirect(this.indirectCanvas); + var i = t.getContext("2d"); + this.video.drawCallback = function() { + i.drawImage(e.indirectCanvas, 0, 0, t.offsetWidth, t.offsetHeight) + } + } else { + this.setCanvasDirect(t); + e = this + } +}, GameBoyAdvance.prototype.setCanvasDirect = function(t) { + this.context = t.getContext("2d"), this.video.setBacking(this.context) +}, GameBoyAdvance.prototype.setBios = function(t, e) { + this.mmu.loadBios(t, e) +}, GameBoyAdvance.prototype.setRom = function(t) { + return this.reset(), this.rom = this.mmu.loadRom(t, !0), !!this.rom && (this.retrieveSavedata(), !0) +}, GameBoyAdvance.prototype.hasRom = function() { + return !!this.rom +}, GameBoyAdvance.prototype.loadRomFromFile = function(t, n) { + var a = this, + e = new JSZip; + if (t.size) + if ("application/zip" === t.type) e.loadAsync(t).then(function(t) { + t.forEach(function(t, e) { + if (e.name.slice(-4).includes(".gb")) { + console.log(e); + var i = e._data.uncompressedSize, + r = new Uint8Array(i).buffer; + console.log(r); + var s = a.setRom(r); + console.log(s), n && n(s) + } + }) + }, function(t) {}); + else { + var i = new FileReader; + i.onload = function(t) { + var e = t.target.result; + console.log(e); + var i = a.setRom(e); + n && n(i) + }, i.readAsArrayBuffer(t) + } else { + var r = new XMLHttpRequest; + r.open("GET", t), r.responseType = "arraybuffer", r.onload = function() { + var t = r.response, + e = a.setRom(t); + n && n(e) + }, r.send() + } +}, GameBoyAdvance.prototype.reset = function() { + this.audio.pause(!0), this.mmu.clear(), this.io.clear(), this.audio.clear(), this.video.clear(), this.sio.clear(), this.mmu.mmap(this.mmu.REGION_IO, this.io), this.mmu.mmap(this.mmu.REGION_PALETTE_RAM, this.video.renderPath.palette), this.mmu.mmap(this.mmu.REGION_VRAM, this.video.renderPath.vram), this.mmu.mmap(this.mmu.REGION_OAM, this.video.renderPath.oam), this.cpu.resetCPU(0) +}, GameBoyAdvance.prototype.step = function() { + for (; this.doStep();) this.cpu.step() +}, GameBoyAdvance.prototype.waitFrame = function() { + var t = this.seenFrame; + return this.seenFrame = !1, !t +}, GameBoyAdvance.prototype.pause = function() { + this.paused = !0, this.audio.pause(!0), this.queue && (clearTimeout(this.queue), this.queue = null) +}, GameBoyAdvance.prototype.advanceFrame = function() { + this.step(), this.seenSave ? this.mmu.saveNeedsFlush() ? this.mmu.flushSave() : (this.storeSavedata(), this.seenSave = !1) : this.mmu.saveNeedsFlush() && (this.seenSave = !0, this.mmu.flushSave()) +}, GameBoyAdvance.prototype.runStable = function() { + if (!this.interval) { + var t, e = this, + i = 0, + r = 0, + s = Date.now(); + this.paused = !1, this.audio.pause(!1), t = this.reportFPS ? function() { + try { + if (i += Date.now() - s, e.paused) return; + queueFrame(t), s = Date.now(), e.advanceFrame(), 60 == ++r && (e.reportFPS(1e3 * r / i), i = r = 0) + } catch (t) { + throw e.ERROR(t), t.stack && e.logStackTrace(t.stack.split("\n")), t + } + } : function() { + try { + if (e.paused) return; + queueFrame(t), e.advanceFrame() + } catch (t) { + throw e.ERROR(t), t.stack && e.logStackTrace(t.stack.split("\n")), t + } + }, queueFrame(t) + } +}, GameBoyAdvance.prototype.setSavedata = function(t) { + this.mmu.loadSavedata(t) +}, GameBoyAdvance.prototype.loadSavedataFromFile = function(t) { + var e = new FileReader, + i = this; + e.onload = function(t) { + i.setSavedata(t.target.result) + }, e.readAsArrayBuffer(t) +}, GameBoyAdvance.prototype.decodeSavedata = function(t) { + this.setSavedata(this.decodeBase64(t)) +}, GameBoyAdvance.prototype.decodeBase64 = function(t) { + var e = 3 * t.length / 4; + "=" == t[t.length - 2] ? e -= 2 : "=" == t[t.length - 1] && (e -= 1); + for (var i = new ArrayBuffer(e), r = new Uint8Array(i), s = t.match(/..../g), n = 0; n + 2 < e; n += 3) { + var a = atob(s.shift()); + r[n] = a.charCodeAt(0), r[n + 1] = a.charCodeAt(1), r[n + 2] = a.charCodeAt(2) + } + if (n < e) { + a = atob(s.shift()); + r[n++] = a.charCodeAt(0), 1 < a.length && (r[n++] = a.charCodeAt(1)) + } + return i +}, GameBoyAdvance.prototype.encodeBase64 = function(t) { + for (var e, i, r = [], s = [], n = 0; n < t.byteLength; ++n) + for (e = t.getUint8(n, !0), s.push(String.fromCharCode(e)); 3 <= s.length;) i = s.splice(0, 3), r.push(btoa(i.join(""))); + return s.length && r.push(btoa(s.join(""))), r.join("") +}, GameBoyAdvance.prototype.downloadSavedata = function() { + var t = this.mmu.save; + if (!t) return this.WARN("No save data available"), null; + if (window.URL) { + var e = window.URL.createObjectURL(new Blob([t.buffer], { + type: "application/octet-stream" + })); + window.open(e) + } else { + var i = this.encodeBase64(t.view); + window.open("data:application/octet-stream;base64," + i, this.rom.code + ".sav") + } +}, GameBoyAdvance.prototype.storeSavedata = function() { + var t = this.mmu.save; + try { + window.localStorage[this.SYS_ID + "." + this.mmu.cart.code] = this.encodeBase64(t.view) + } catch (t) { + this.WARN("Could not store savedata! " + t) + } +}, GameBoyAdvance.prototype.retrieveSavedata = function() { + try { + var t = window.localStorage[this.SYS_ID + "." + this.mmu.cart.code]; + if (t) return this.decodeSavedata(t), !0 + } catch (t) { + this.WARN("Could not retrieve savedata! " + t) + } + return !1 +}, GameBoyAdvance.prototype.freeze = function() { + return { + cpu: this.cpu.freeze(), + mmu: this.mmu.freeze(), + irq: this.irq.freeze(), + io: this.io.freeze(), + audio: this.audio.freeze(), + video: this.video.freeze() + } +}, GameBoyAdvance.prototype.defrost = function(t) { + this.cpu.defrost(t.cpu), this.mmu.defrost(t.mmu), this.audio.defrost(t.audio), this.video.defrost(t.video), this.irq.defrost(t.irq), this.io.defrost(t.io) +}, GameBoyAdvance.prototype.log = function(t, e) {}, GameBoyAdvance.prototype.setLogger = function(t) { + this.log = t +}, GameBoyAdvance.prototype.logStackTrace = function(t) { + var e = t.length - 32; + this.ERROR("Stack trace follows:"), 0 < e && this.log(-1, "> (Too many frames)"); + for (var i = Math.max(e, 0); i < t.length; ++i) this.log(-1, "> " + t[i]) +}, GameBoyAdvance.prototype.ERROR = function(t) { + this.logLevel & this.LOG_ERROR && this.log(this.LOG_ERROR, t) +}, GameBoyAdvance.prototype.WARN = function(t) { + this.logLevel & this.LOG_WARN && this.log(this.LOG_WARN, t) +}, GameBoyAdvance.prototype.STUB = function(t) { + this.logLevel & this.LOG_STUB && this.log(this.LOG_STUB, t) +}, GameBoyAdvance.prototype.INFO = function(t) { + this.logLevel & this.LOG_INFO && this.log(this.LOG_INFO, t) +}, GameBoyAdvance.prototype.DEBUG = function(t) { + this.logLevel & this.LOG_DEBUG && this.log(this.LOG_DEBUG, t) +}, GameBoyAdvance.prototype.ASSERT_UNREACHED = function(t) { + throw new Error("Should be unreached: " + t) +}, GameBoyAdvance.prototype.ASSERT = function(t, e) { + if (!t) throw new Error("Assertion failed: " + e) +}, zip.workerScriptsPath = "js/libs/zip/worker/", Utils.g.isLandscape = !0, window.gba = null; +var runCommands = [], + gameId = Utils.request.getParameter("id"); + +function loadRom(t, e) { + var i = new XMLHttpRequest; + i.open("GET", t), i.responseType = "arraybuffer", i.onload = function() { + e(i.response) + }, i.send() +} + +function initGBA() { + gba = new GameBoyAdvance, gba.keypad.eatInput = !0, gba.setLogger(function(t, e) { + console.log(e), gba.pause(), "dead" != document.getElementById("screen").getAttribute("class") ? Utils.alert("游戏奔溃了...", null, function() { + location.reload(!0) + }) : console.log("We appear to have crashed multiple times without reseting.") + }); + var t = document.getElementById("screen"); + gba.setCanvas(t), gba.logLevel = gba.LOG_ERROR, loadRom("resources/bios.bin", function(t) { + gba.setBios(t) + }), vm.initCtrl(), run() +} + +function initAudioEvent() { + gba && gba.audio && gba.audio.initAudio() && $(".key-btn").unbind("touchstart", initAudioEvent) +} + +function loadRomByZipUrl(i, r) { + // var s = (/192.168./.test(location.href) ? "http://192.168.42.80:8088/gba/" : "https://pub.hoh8.cn/files/game/gba/") + gameId + "/" + gameId + ".zip", + //var s = "http://192.168.100.84/gba/roms/" + gameId + ".zip", + var s = "http://h5games-al.kingsome.cn/emulator-static/roms/" + gameId + ".zip", + n = "GBA_ROM_" + s; + localforage.getItem(n, function(t, e) { + e ? i(e) : zip.createReader(new zip.HttpReader(s, r), function(e) { + e.getEntries(function(t) { + t.length && t[0].getData(new zip.ArrayBufferWriter, function(t) { + localforage.setItem(n, t), i(t), e.close(function() {}) + }, function(t, e) {}) + }) + }, function(t) {}) + }) +} + +function run() { + var i = Utils.loading("加载中..."); + loadRomByZipUrl(function(t) { + if (gba.setRom(t)) { + for (var e = 0; e < runCommands.length; ++e) runCommands[e](); + runCommands = [], gba.runStable() + } + i.close() + }, function(t) { + if (t.lengthComputable) { + var e = parseInt(t.loaded / t.total * 100); + $("#ld_p").html(e + "%") + } + }) +} + +function startGame(){ + initGBA(), $(".key-btn").bind("touchstart", initAudioEvent) +} +function checkSession_id(res){ + try{ + if(JSON.parse(res.target.response).errcode==0){ + startGame(); + } + }catch(e){} +} +window.onload = function(){ + var account_id = getParameter("account_id") + var session_id = getParameter("session_id") + var url; + if(getParameter("version")==="product"){ + url = "https://login.kingsome.cn/webapp/index.php?c=Login&a=sessionAuth" + } + else{ + url = "https://login-test.kingsome.cn/webapp/index.php?c=Login&a=sessionAuth" + } + url += "&account_id="; + url += account_id; + url += "&session_id="; + url += session_id; + + var ajax = new XMLHttpRequest(); + ajax.onload = checkSession_id; + ajax.open("GET", url, true); + ajax.send(null); + +} + + + + +// window.onload = function() { +// initGBA(), $(".key-btn").bind("touchstart", initAudioEvent) +// }; +var KEY_MAP = { + ST: 13, + SE: 220, + A: 90, + B: 88, + Y: 65, + X: 83, + AB: [90, 88], + UP: 38, + DOWN: 40, + LEFT: 37, + RIGHT: 39, + L_D: [37, 40], + L_U: [37, 38], + R_D: [39, 40], + R_U: [39, 38] +}; +window.vm = { + oldDire: null, + keyEvent: function(t, e, i) { + var r = KEY_MAP[t]; + Array.isArray(r) ? (vm.simulateKeyPress(r[0], e), vm.simulateKeyPress(r[1], e)) : vm.simulateKeyPress(r, e) + }, + initCtrl: function() { + var s; + vm.initGameDireCtrl(function(t, e) { + var i = -1 == t ? s : ["DOWN", "L_D", "LEFT", "L_U", "UP", "R_U", "RIGHT", "R_D"][t], + r = -1 == t; + s && (s != i || r) && vm.keyEvent(s, "keyup", e), s = i, !r && vm.keyEvent(i, "keydown", e) + }), vm.initGameKeyCtrl(), $(".ctrl-wrap").on("click contextmenu touchstart touchmove touchend touchcancel tap", function(t) { + return t.stopPropagation(), t.preventDefault(), !1 + }) + }, + initGameDireCtrl: function(u) { + var d = this, + t = $(".dire-wrap"), + p = $(".dc-centre"), + e = $(".dire-ctrl"), + l = $(".dc-dire"), + i = e.offset(), + n = i.top, + a = i.left, + f = p.width() / 2, + m = e.width() / 2, + r = function() { + p.css({ + transform: "translate3d(83px,83px,0)" + }), p.css("opacity", "1"), l.css("opacity", "0") + }, + y = function(t, e) { + var i = t[e]; + if (!i) return { + x: 160, + y: 500 + }; + var r = i.pageX - a, + s = i.pageY - n; + return 600 < s ? y(t, e + 1) : { + x: r, + y: s + } + }; + r(), t.on("touchstart touchmove", function(t) { + var e, i, r = y(t.touches, 0), + s = r.x, + n = r.y, + a = Math.atan2(n - m, s - m) / (Math.PI / 180); + if (l.css("transform", "rotate(" + a + "deg)"), d.onCtrlDire(a, u), (e = m - s, i = m - n, Math.sqrt(e * e + i * i)) <= 86) { + var o = s - f, + h = n - f; + p.css("transform", "translate3d(" + o + "px," + h + "px,0)") + } else { + var c = a * Math.PI / 180; + o = m + 86 * Math.cos(c) - f, h = m + 86 * Math.sin(c) - f; + p.css("transform", "translate3d(" + o + "px," + h + "px,0)") + } + "touchstart" === t.type && (p.css("opacity", "0.8"), l.css("opacity", "0.6")) + }).on("touchend", function() { + r(), u(-1, 0), d.oldDire = -1 + }) + }, + initGameKeyCtrl: function() { + var s = this; + $(".key-btn").bind("touchstart touchend", function(t) { + var e = $(t.target), + i = e.attr("data-key"), + r = "touchstart" === t.type; + s.keyEvent(i, r ? "keydown" : "keyup", 0), e[r ? "addClass" : "removeClass"]("btn-on") + }) + }, + onCtrlDire: function(t, e) { + this.onCtrlDire; + var i = Math.round((t + 180) / 45) % 8; + this.oldDire != i && (e(i, t), this.oldDire = i) + }, + simulateKeyPress: function(t, e) { + var i = $.Event(e); + i.keyCode = t, i.which = i.keyCode, $(window).trigger(i) + } +};