react-gbajs
Version:
GBA emulator and wrapper for React
11 lines • 218 kB
JavaScript
module.exports=function(t){var e={};function i(s){if(e[s])return e[s].exports;var r=e[s]={i:s,l:!1,exports:{}};return t[s].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,s){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:s})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var s=Object.create(null);if(i.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(s,r,function(e){return t[e]}.bind(null,r));return s},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=29)}([function(t,e,i){(function(t,i){var s="[object Arguments]",r="[object Function]",n="[object GeneratorFunction]",o="[object Map]",a="[object Set]",h=/\w*$/,c=/^\[object .+?Constructor\]$/,u=/^(?:0|[1-9]\d*)$/,p={};p[s]=p["[object Array]"]=p["[object ArrayBuffer]"]=p["[object DataView]"]=p["[object Boolean]"]=p["[object Date]"]=p["[object Float32Array]"]=p["[object Float64Array]"]=p["[object Int8Array]"]=p["[object Int16Array]"]=p["[object Int32Array]"]=p[o]=p["[object Number]"]=p["[object Object]"]=p["[object RegExp]"]=p[a]=p["[object String]"]=p["[object Symbol]"]=p["[object Uint8Array]"]=p["[object Uint8ClampedArray]"]=p["[object Uint16Array]"]=p["[object Uint32Array]"]=!0,p["[object Error]"]=p[r]=p["[object WeakMap]"]=!1;var d="object"==typeof t&&t&&t.Object===Object&&t,l="object"==typeof self&&self&&self.Object===Object&&self,f=d||l||Function("return this")(),m=e&&!e.nodeType&&e,A=m&&"object"==typeof i&&i&&!i.nodeType&&i,y=A&&A.exports===m;function b(t,e){return t.set(e[0],e[1]),t}function R(t,e){return t.add(e),t}function v(t,e,i,s){var r=-1,n=t?t.length:0;for(s&&n&&(i=t[++r]);++r<n;)i=e(i,t[r],r,t);return i}function C(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}function S(t){var e=-1,i=Array(t.size);return t.forEach((function(t,s){i[++e]=[s,t]})),i}function w(t,e){return function(i){return t(e(i))}}function g(t){var e=-1,i=Array(t.size);return t.forEach((function(t){i[++e]=t})),i}var _,M=Array.prototype,I=Function.prototype,E=Object.prototype,O=f["__core-js_shared__"],T=(_=/[^.]+$/.exec(O&&O.keys&&O.keys.IE_PROTO||""))?"Symbol(src)_1."+_:"",P=I.toString,B=E.hasOwnProperty,D=E.toString,N=RegExp("^"+P.call(B).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),k=y?f.Buffer:void 0,L=f.Symbol,G=f.Uint8Array,U=w(Object.getPrototypeOf,Object),x=Object.create,H=E.propertyIsEnumerable,F=M.splice,V=Object.getOwnPropertySymbols,W=k?k.isBuffer:void 0,j=w(Object.keys,Object),Y=At(f,"DataView"),K=At(f,"Map"),q=At(f,"Promise"),Q=At(f,"Set"),Z=At(f,"WeakMap"),z=At(Object,"create"),X=Ct(Y),J=Ct(K),$=Ct(q),tt=Ct(Q),et=Ct(Z),it=L?L.prototype:void 0,st=it?it.valueOf:void 0;function rt(t){var e=-1,i=t?t.length:0;for(this.clear();++e<i;){var s=t[e];this.set(s[0],s[1])}}function nt(t){var e=-1,i=t?t.length:0;for(this.clear();++e<i;){var s=t[e];this.set(s[0],s[1])}}function ot(t){var e=-1,i=t?t.length:0;for(this.clear();++e<i;){var s=t[e];this.set(s[0],s[1])}}function at(t){this.__data__=new nt(t)}function ht(t,e){var i=wt(t)||function(t){return function(t){return function(t){return!!t&&"object"==typeof t}(t)&>(t)}(t)&&B.call(t,"callee")&&(!H.call(t,"callee")||D.call(t)==s)}(t)?function(t,e){for(var i=-1,s=Array(t);++i<t;)s[i]=e(i);return s}(t.length,String):[],r=i.length,n=!!r;for(var o in t)!e&&!B.call(t,o)||n&&("length"==o||Rt(o,r))||i.push(o);return i}function ct(t,e,i){var s=t[e];B.call(t,e)&&St(s,i)&&(void 0!==i||e in t)||(t[e]=i)}function ut(t,e){for(var i=t.length;i--;)if(St(t[i][0],e))return i;return-1}function pt(t,e,i,c,u,d,l){var f;if(c&&(f=d?c(t,u,d,l):c(t)),void 0!==f)return f;if(!It(t))return t;var m=wt(t);if(m){if(f=function(t){var e=t.length,i=t.constructor(e);e&&"string"==typeof t[0]&&B.call(t,"index")&&(i.index=t.index,i.input=t.input);return i}(t),!e)return function(t,e){var i=-1,s=t.length;e||(e=Array(s));for(;++i<s;)e[i]=t[i];return e}(t,f)}else{var A=bt(t),y=A==r||A==n;if(_t(t))return function(t,e){if(e)return t.slice();var i=new t.constructor(t.length);return t.copy(i),i}(t,e);if("[object Object]"==A||A==s||y&&!d){if(C(t))return d?t:{};if(f=function(t){return"function"!=typeof t.constructor||vt(t)?{}:(e=U(t),It(e)?x(e):{});var e}(y?{}:t),!e)return function(t,e){return ft(t,yt(t),e)}(t,function(t,e){return t&&ft(e,Et(e),t)}(f,t))}else{if(!p[A])return d?t:{};f=function(t,e,i,s){var r=t.constructor;switch(e){case"[object ArrayBuffer]":return lt(t);case"[object Boolean]":case"[object Date]":return new r(+t);case"[object DataView]":return function(t,e){var i=e?lt(t.buffer):t.buffer;return new t.constructor(i,t.byteOffset,t.byteLength)}(t,s);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return function(t,e){var i=e?lt(t.buffer):t.buffer;return new t.constructor(i,t.byteOffset,t.length)}(t,s);case o:return function(t,e,i){return v(e?i(S(t),!0):S(t),b,new t.constructor)}(t,s,i);case"[object Number]":case"[object String]":return new r(t);case"[object RegExp]":return function(t){var e=new t.constructor(t.source,h.exec(t));return e.lastIndex=t.lastIndex,e}(t);case a:return function(t,e,i){return v(e?i(g(t),!0):g(t),R,new t.constructor)}(t,s,i);case"[object Symbol]":return n=t,st?Object(st.call(n)):{}}var n}(t,A,pt,e)}}l||(l=new at);var w=l.get(t);if(w)return w;if(l.set(t,f),!m)var _=i?function(t){return function(t,e,i){var s=e(t);return wt(t)?s:function(t,e){for(var i=-1,s=e.length,r=t.length;++i<s;)t[r+i]=e[i];return t}(s,i(t))}(t,Et,yt)}(t):Et(t);return function(t,e){for(var i=-1,s=t?t.length:0;++i<s&&!1!==e(t[i],i,t););}(_||t,(function(s,r){_&&(s=t[r=s]),ct(f,r,pt(s,e,i,c,r,t,l))})),f}function dt(t){return!(!It(t)||(e=t,T&&T in e))&&(Mt(t)||C(t)?N:c).test(Ct(t));var e}function lt(t){var e=new t.constructor(t.byteLength);return new G(e).set(new G(t)),e}function ft(t,e,i,s){i||(i={});for(var r=-1,n=e.length;++r<n;){var o=e[r],a=s?s(i[o],t[o],o,i,t):void 0;ct(i,o,void 0===a?t[o]:a)}return i}function mt(t,e){var i,s,r=t.__data__;return("string"==(s=typeof(i=e))||"number"==s||"symbol"==s||"boolean"==s?"__proto__"!==i:null===i)?r["string"==typeof e?"string":"hash"]:r.map}function At(t,e){var i=function(t,e){return null==t?void 0:t[e]}(t,e);return dt(i)?i:void 0}rt.prototype.clear=function(){this.__data__=z?z(null):{}},rt.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},rt.prototype.get=function(t){var e=this.__data__;if(z){var i=e[t];return"__lodash_hash_undefined__"===i?void 0:i}return B.call(e,t)?e[t]:void 0},rt.prototype.has=function(t){var e=this.__data__;return z?void 0!==e[t]:B.call(e,t)},rt.prototype.set=function(t,e){return this.__data__[t]=z&&void 0===e?"__lodash_hash_undefined__":e,this},nt.prototype.clear=function(){this.__data__=[]},nt.prototype.delete=function(t){var e=this.__data__,i=ut(e,t);return!(i<0)&&(i==e.length-1?e.pop():F.call(e,i,1),!0)},nt.prototype.get=function(t){var e=this.__data__,i=ut(e,t);return i<0?void 0:e[i][1]},nt.prototype.has=function(t){return ut(this.__data__,t)>-1},nt.prototype.set=function(t,e){var i=this.__data__,s=ut(i,t);return s<0?i.push([t,e]):i[s][1]=e,this},ot.prototype.clear=function(){this.__data__={hash:new rt,map:new(K||nt),string:new rt}},ot.prototype.delete=function(t){return mt(this,t).delete(t)},ot.prototype.get=function(t){return mt(this,t).get(t)},ot.prototype.has=function(t){return mt(this,t).has(t)},ot.prototype.set=function(t,e){return mt(this,t).set(t,e),this},at.prototype.clear=function(){this.__data__=new nt},at.prototype.delete=function(t){return this.__data__.delete(t)},at.prototype.get=function(t){return this.__data__.get(t)},at.prototype.has=function(t){return this.__data__.has(t)},at.prototype.set=function(t,e){var i=this.__data__;if(i instanceof nt){var s=i.__data__;if(!K||s.length<199)return s.push([t,e]),this;i=this.__data__=new ot(s)}return i.set(t,e),this};var yt=V?w(V,Object):function(){return[]},bt=function(t){return D.call(t)};function Rt(t,e){return!!(e=null==e?9007199254740991:e)&&("number"==typeof t||u.test(t))&&t>-1&&t%1==0&&t<e}function vt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||E)}function Ct(t){if(null!=t){try{return P.call(t)}catch(t){}try{return t+""}catch(t){}}return""}function St(t,e){return t===e||t!=t&&e!=e}(Y&&"[object DataView]"!=bt(new Y(new ArrayBuffer(1)))||K&&bt(new K)!=o||q&&"[object Promise]"!=bt(q.resolve())||Q&&bt(new Q)!=a||Z&&"[object WeakMap]"!=bt(new Z))&&(bt=function(t){var e=D.call(t),i="[object Object]"==e?t.constructor:void 0,s=i?Ct(i):void 0;if(s)switch(s){case X:return"[object DataView]";case J:return o;case $:return"[object Promise]";case tt:return a;case et:return"[object WeakMap]"}return e});var wt=Array.isArray;function gt(t){return null!=t&&function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991}(t.length)&&!Mt(t)}var _t=W||function(){return!1};function Mt(t){var e=It(t)?D.call(t):"";return e==r||e==n}function It(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function Et(t){return gt(t)?ht(t):function(t){if(!vt(t))return j(t);var e=[];for(var i in Object(t))B.call(t,i)&&"constructor"!=i&&e.push(i);return e}(t)}i.exports=function(t){return pt(t,!0,!0)}}).call(this,i(5),i(13)(t))},function(t,e){t.exports=require("react")},function(t,e,i){var s=i(7),r=i(8),n=i(9);t.exports=function(t){return s(t)||r(t)||n()}},function(t,e,i){var s=i(10),r=i(11),n=i(12);t.exports=function(t,e){return s(t)||r(t,e)||n()}},function(t,e){function i(t){return(i="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})(t)}function s(e){return"function"==typeof Symbol&&"symbol"===i(Symbol.iterator)?t.exports=s=function(t){return i(t)}:t.exports=s=function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":i(t)},s(e)}t.exports=s},function(t,e){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(t){"object"==typeof window&&(i=window)}t.exports=i},function(t,e,i){t.exports=i(24)("BgAA6v7//+oFAADq/v//6v7//+oAAKDhDAAA6v7//+oC86DjAABd4wHToAMg0E0CAEAt6QIAXuUEAFDjCQAACwUAUOMHAAALAEC96A7wsOEPUC3pAQOg4wDgj+IE8BDlD1C96ATwXuIQQC3pBNBN4rAQzeEBQ6DjAkyE4rAA1OGyAM3hsBDd4QEAgOGwAMThAUOg4x8AoOMA8CnhAACg4wEDxOXTAKDjAPAp4bgAVOGwEN3hABAR4AAQIRC4EEQR8///CgFDoOMCTITisgDd4bAAxOEE0I3iEIC96A==")},function(t,e){t.exports=function(t){if(Array.isArray(t)){for(var e=0,i=new Array(t.length);e<t.length;e++)i[e]=t[e];return i}}},function(t,e){t.exports=function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}},function(t,e){t.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}},function(t,e){t.exports=function(t){if(Array.isArray(t))return t}},function(t,e){t.exports=function(t,e){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t)){var i=[],s=!0,r=!1,n=void 0;try{for(var o,a=t[Symbol.iterator]();!(s=(o=a.next()).done)&&(i.push(o.value),!e||i.length!==e);s=!0);}catch(t){r=!0,n=t}finally{try{s||null==a.return||a.return()}finally{if(r)throw n}}return i}}},function(t,e){t.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}},function(t,e){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),t.webpackPolyfill=1),t}},function(t,e){window.ARMCore=function(){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)},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,s=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?(s.wait32(e),s.waitPrefetch32(e)):(s.wait(e),s.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 s=this.mmu.load32(t)>>>0;return(e=this.compileArm(s)).next=null,e.page=this.page,e.address=t,e.opcode=s,this.page.arm[i]=e,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 s=this.mmu.load16(t);return(e=this.compileThumb(s)).next=null,e.page=this.page,e.address=t,e.opcode=s,this.page.thumb[i]=e,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,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 s=(i==this.BANK_FIQ)+0,r=(e==this.BANK_FIQ)+0;this.bankedRegisters[s][2]=this.gprs[8],this.bankedRegisters[s][3]=this.gprs[9],this.bankedRegisters[s][4]=this.gprs[10],this.bankedRegisters[s][5]=this.gprs[11],this.bankedRegisters[s][6]=this.gprs[12],this.gprs[8]=this.bankedRegisters[r][2],this.gprs[9]=this.bankedRegisters[r][3],this.gprs[10]=this.bankedRegisters[r][4],this.gprs[11]=this.bankedRegisters[r][5],this.gprs[12]=this.bankedRegisters[r][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 s=this,r=this.gprs,n=this.badOp;switch(t){case 0:n=e?function(){s.shifterOperand=r[i]<<e,s.shifterCarryOut=r[i]&1<<32-e}:function(){s.shifterOperand=r[i],s.shifterCarryOut=s.cpsrC};break;case 32:n=e?function(){s.shifterOperand=r[i]>>>e,s.shifterCarryOut=r[i]&1<<e-1}:function(){s.shifterOperand=0,s.shifterCarryOut=2147483648&r[i]};break;case 64:n=e?function(){s.shifterOperand=r[i]>>e,s.shifterCarryOut=r[i]&1<<e-1}:function(){s.shifterCarryOut=2147483648&r[i],s.shifterCarryOut?s.shifterOperand=4294967295:s.shifterOperand=0};break;case 96:n=e?function(){s.shifterOperand=r[i]>>>e|r[i]<<32-e,s.shifterCarryOut=r[i]&1<<e-1}:function(){s.shifterOperand=!!s.cpsrC<<31|r[i]>>>1,s.shifterCarryOut=1&r[i]}}return n},ARMCore.prototype.compileArm=function(t){var e=this.badOp(t),i=234881024&t,s=(this.gprs,this.conds[(4026531840&t)>>>28]);if(19922704==(268435440&t)){var r=15&t;(e=this.armCompiler.constructBX(r,s)).writesPC=!0,e.fixedJump=!1}else if(201326592&t||33554432!=i&&144==(144&t))if(16777360==(263196656&t)){r=15&t,v=t>>12&15,R=t>>16&15;(e=4194304&t?this.armCompiler.constructSWPB(v,R,r,s):this.armCompiler.constructSWP(v,R,r,s)).writesPC=v==this.PC}else switch(i){case 0:if(144==(16777456&t)){v=(983040&t)>>16,R=(61440&t)>>12,_=(3840&t)>>8,r=15&t;switch(15728640&t){case 0:e=this.armCompiler.constructMUL(v,_,r,s);break;case 1048576:e=this.armCompiler.constructMULS(v,_,r,s);break;case 2097152:e=this.armCompiler.constructMLA(v,R,_,r,s);break;case 3145728:e=this.armCompiler.constructMLAS(v,R,_,r,s);break;case 8388608:e=this.armCompiler.constructUMULL(v,R,_,r,s);break;case 9437184:e=this.armCompiler.constructUMULLS(v,R,_,r,s);break;case 10485760:e=this.armCompiler.constructUMLAL(v,R,_,r,s);break;case 11534336:e=this.armCompiler.constructUMLALS(v,R,_,r,s);break;case 12582912:e=this.armCompiler.constructSMULL(v,R,_,r,s);break;case 13631488:e=this.armCompiler.constructSMULLS(v,R,_,r,s);break;case 14680064:e=this.armCompiler.constructSMLAL(v,R,_,r,s);break;case 15728640:e=this.armCompiler.constructSMLALS(v,R,_,r,s)}e.writesPC=v==this.PC}else{var n=1048576&t,o=(v=(61440&t)>>12,r=15&t),a=32&t,h=(b=64&t,2097152&t);if(i=4194304&t){w=o|(3840&t)>>4;u=this.armCompiler.constructAddressingMode23Immediate(t,w,s)}else u=this.armCompiler.constructAddressingMode23Register(t,r,s);u.writesPC=!!h&&R==this.PC,144==(144&t)&&(n?a?e=b?this.armCompiler.constructLDRSH(v,u,s):this.armCompiler.constructLDRH(v,u,s):b&&(e=this.armCompiler.constructLDRSB(v,u,s)):!b&&a&&(e=this.armCompiler.constructSTRH(v,u,s))),e.writesPC=v==this.PC||u.writesPC}break;case 67108864:case 100663296:v=(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){r=15&t;var p=(3968&t)>>7;if((C=96&t)||p){S=this.barrelShiftImmediate(C,p,r);u=this.armCompiler.constructAddressingMode2RegisterShifted(t,S,s)}else u=this.armCompiler.constructAddressingMode23Register(t,r,s)}else{var d=4095&t;u=this.armCompiler.constructAddressingMode23Immediate(t,d,s)}(e=n?c?this.armCompiler.constructLDRB(v,u,s):this.armCompiler.constructLDR(v,u,s):c?this.armCompiler.constructSTRB(v,u,s):this.armCompiler.constructSTR(v,u,s)).writesPC=v==this.PC||u.writesPC;break;case 134217728:n=1048576&t,h=2097152&t;var l=4194304&t,f=16777216&t,m=(_=65535&t,R=(983040&t)>>16,w=0,d=0,!1);if(8388608&t){f&&(w=4);var A=1;for(i=0;i<16;A<<=1,++i)_&A&&(h&&i==R&&!d&&(_&=~A,w+=4,m=!0),d+=4)}else{f||(w=4);for(A=1,i=0;i<16;A<<=1,++i)_&A&&(h&&i==R&&!d&&(_&=~A,w+=4,m=!0),w-=4,d-=4)}u=h?this.armCompiler.constructAddressingMode4Writeback(w,d,R,m):this.armCompiler.constructAddressingMode4(w,R),n?(e=l?this.armCompiler.constructLDMS(_,u,s):this.armCompiler.constructLDM(_,u,s)).writesPC=!!(32768&_):(e=l?this.armCompiler.constructSTMS(_,u,s):this.armCompiler.constructSTM(_,u,s)).writesPC=!1;break;case 167772160:8388608&(w=16777215&t)&&(w|=4278190080),w<<=2,(e=16777216&t?this.armCompiler.constructBL(w,s):this.armCompiler.constructB(w,s)).writesPC=!0,e.fixedJump=!0;break;case 201326592:break;case 234881024:if(251658240==(251658240&t)){w=16777215&t;(e=this.armCompiler.constructSWI(w,s)).writesPC=!1}break;default:throw"Bad opcode: 0x"+t.toString(16)}else{var y=31457280&t,b=1048576&t;if(16777216!=(25165824&y)||b){var R=(983040&t)>>16,v=(61440&t)>>12,C=96&t,r=15&t,S=function(){throw"BUG: invalid barrel shifter"};if(33554432&t){var w=255&t,g=(3840&t)>>7;S=g?this.armCompiler.constructAddressingMode1ImmediateRotate(w,g):this.armCompiler.constructAddressingMode1Immediate(w)}else if(16&t){var _=(3840&t)>>8;switch(!0,C){case 0:S=this.armCompiler.constructAddressingMode1LSL(_,r);break;case 32:S=this.armCompiler.constructAddressingMode1LSR(_,r);break;case 64:S=this.armCompiler.constructAddressingMode1ASR(_,r);break;case 96:S=this.armCompiler.constructAddressingMode1ROR(_,r)}}else{var w=(3968&t)>>7;S=this.barrelShiftImmediate(C,w,r)}switch(y){case 0:e=b?this.armCompiler.constructANDS(v,R,S,s):this.armCompiler.constructAND(v,R,S,s);break;case 2097152:e=b?this.armCompiler.constructEORS(v,R,S,s):this.armCompiler.constructEOR(v,R,S,s);break;case 4194304:e=b?this.armCompiler.constructSUBS(v,R,S,s):this.armCompiler.constructSUB(v,R,S,s);break;case 6291456:e=b?this.armCompiler.constructRSBS(v,R,S,s):this.armCompiler.constructRSB(v,R,S,s);break;case 8388608:e=b?this.armCompiler.constructADDS(v,R,S,s):this.armCompiler.constructADD(v,R,S,s);break;case 10485760:e=b?this.armCompiler.constructADCS(v,R,S,s):this.armCompiler.constructADC(v,R,S,s);break;case 12582912:e=b?this.armCompiler.constructSBCS(v,R,S,s):this.armCompiler.constructSBC(v,R,S,s);break;case 14680064:e=b?this.armCompiler.constructRSCS(v,R,S,s):this.armCompiler.constructRSC(v,R,S,s);break;case 16777216:e=this.armCompiler.constructTST(v,R,S,s);break;case 18874368:e=this.armCompiler.constructTEQ(v,R,S,s);break;case 20971520:e=this.armCompiler.constructCMP(v,R,S,s);break;case 23068672:e=this.armCompiler.constructCMN(v,R,S,s);break;case 25165824:e=b?this.armCompiler.constructORRS(v,R,S,s):this.armCompiler.constructORR(v,R,S,s);break;case 27262976:e=b?this.armCompiler.constructMOVS(v,R,S,s):this.armCompiler.constructMOV(v,R,S,s);break;case 29360128:e=b?this.armCompiler.constructBICS(v,R,S,s):this.armCompiler.constructBIC(v,R,S,s);break;case 31457280:e=b?this.armCompiler.constructMVNS(v,R,S,s):this.armCompiler.constructMVN(v,R,S,s)}e.writesPC=v==this.PC}else{var M=4194304&t;if(2158592==(11595776&t)){var r=15&t,I=(3840&t)>>7;w=(w=255&t)>>>I|w<<32-I,(e=this.armCompiler.constructMSR(r,M,t,w,s)).writesPC=!1}else if(983040==(12517376&t)){var v=(61440&t)>>12;(e=this.armCompiler.constructMRS(v,M,s)).writesPC=v==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,s=7&t;switch(960&t){case 0:e=this.thumbCompiler.constructAND(s,i);break;case 64:e=this.thumbCompiler.constructEOR(s,i);break;case 128:e=this.thumbCompiler.constructLSL2(s,i);break;case 192:e=this.thumbCompiler.constructLSR2(s,i);break;case 256:e=this.thumbCompiler.constructASR2(s,i);break;case 320:e=this.thumbCompiler.constructADC(s,i);break;case 384:e=this.thumbCompiler.constructSBC(s,i);break;case 448:e=this.thumbCompiler.constructROR(s,i);break;case 512:e=this.thumbCompiler.constructTST(s,i);break;case 576:e=this.thumbCompiler.constructNEG(s,i);break;case 640:e=this.thumbCompiler.constructCMP2(s,i);break;case 704:e=this.thumbCompiler.constructCMN(s,i);break;case 768:e=this.thumbCompiler.constructORR(s,i);break;case 832:e=this.thumbCompiler.constructMUL(s,i);break;case 896:e=this.thumbCompiler.constructBIC(s,i);break;case 960:e=this.thumbCompiler.constructMVN(s,i)}e.writesPC=!1}else if(17408==(64512&t)){i=(120&t)>>3,s=(r=7&t)|(128&t)>>4;switch(768&t){case 0:(e=this.thumbCompiler.constructADD4(s,i)).writesPC=s==this.PC;break;case 256:(e=this.thumbCompiler.constructCMP3(s,i)).writesPC=!1;break;case 512:(e=this.thumbCompiler.constructMOV3(s,i)).writesPC=s==this.PC;break;case 768:(e=this.thumbCompiler.constructBX(s,i)).writesPC=!0,e.fixedJump=!1}}else if(6144==(63488&t)){i=(448&t)>>6;var r=(56&t)>>3;s=7&t;switch(1536&t){case 0:e=this.thumbCompiler.constructADD3(s,r,i);break;case 512:e=this.thumbCompiler.constructSUB3(s,r,i);break;case 1024:e=(n=(448&t)>>6)?this.thumbCompiler.constructADD1(s,r,n):this.thumbCompiler.constructMOV2(s,r,i);break;case 1536:var n=(448&t)>>6;e=this.thumbCompiler.constructSUB1(s,r,n)}e.writesPC=!1}else if(57344&t)if(8192==(57344&t)){n=255&t,r=(1792&t)>>8;switch(6144&t){case 0:e=this.thumbCompiler.constructMOV1(r,n);break;case 2048:e=this.thumbCompiler.constructCMP1(r,n);break;case 4096:e=this.thumbCompiler.constructADD2(r,n);break;case 6144:e=this.thumbCompiler.constructSUB2(r,n)}e.writesPC=!1}else if(18432==(63488&t)){s=(1792&t)>>8,n=(255&t)<<2;(e=this.thumbCompiler.constructLDR3(s,n)).writesPC=!1}else if(20480==(61440&t)){s=7&t,r=(56&t)>>3,i=(448&t)>>6;switch(3584&t){case 0:e=this.thumbCompiler.constructSTR2(s,r,i);break;case 512:e=this.thumbCompiler.constructSTRH2(s,r,i);break;case 1024:e=this.thumbCompiler.constructSTRB2(s,r,i);break;case 1536:e=this.thumbCompiler.constructLDRSB(s,r,i);break;case 2048:e=this.thumbCompiler.constructLDR2(s,r,i);break;case 2560:e=this.thumbCompiler.constructLDRH2(s,r,i);break;case 3072:e=this.thumbCompiler.constructLDRB2(s,r,i);break;case 3584:e=this.thumbCompiler.constructLDRSH(s,r,i)}e.writesPC=!1}else if(24576==(57344&t)){s=7&t,r=(56&t)>>3,n=(1984&t)>>4;(h=4096&t)&&(n>>=2),(e=2048&t?h?this.thumbCompiler.constructLDRB1(s,r,n):this.thumbCompiler.constructLDR1(s,r,n):h?this.thumbCompiler.constructSTRB1(s,r,n):this.thumbCompiler.constructSTR1(s,r,n)).writesPC=!1}else if(46080==(62976&t)){var o=!!(256&t),a=255&t;2048&t?((e=this.thumbCompiler.constructPOP(a,o)).writesPC=o,e.fixedJump=!1):(e=this.thumbCompiler.constructPUSH(a,o)).writesPC=!1}else{if(!(32768&t))throw"Bad opcode: 0x"+t.toString(16);switch(28672&t){case 0:s=7&t,r=(56&t)>>3,n=(1984&t)>>5;(e=2048&t?this.thumbCompiler.constructLDRH1(s,r,n):this.thumbCompiler.constructSTRH1(s,r,n)).writesPC=!1;break;case 4096:s=(1792&t)>>8,n=(255&t)<<2;(e=2048&t?this.thumbCompiler.constructLDR4(s,n):this.thumbCompiler.constructSTR3(s,n)).writesPC=!1;break;case 8192:s=(1792&t)>>8,n=(255&t)<<2;(e=2048&t?this.thumbCompiler.constructADD6(s,n):this.thumbCompiler.constructADD5(s,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:r=(1792&t)>>8,a=255&t;(e=2048&t?this.thumbCompiler.constructLDMIA(r,a):this.thumbCompiler.constructSTMIA(r,a)).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 s=7&t,i=(56&t)>>3,n=(1984&t)>>6;switch(6144&t){case 0:e=this.thumbCompiler.constructLSL1(s,i,n);break;case 2048:e=this.thumbCompiler.constructLSR1(s,i,n);break;case 4096:e=this.thumbCompiler.constructASR1(s,i,n)}e.writesPC=!1}return e.execMode=this.MODE_THUMB,e.fixedJump=e.fixedJump||!1,e}},function(t,e){ARMCoreArm=function(t){this.cpu=t,this.addressingMode23Immediate=[function(e,i,s){var r=t.gprs,n=function(){var t=r[e];return s&&!s()||(r[e]-=i),t};return n.writesPC=e==t.PC,n},null,null,null,function(e,i,s){var r=t.gprs,n=function(){var t=r[e];return s&&!s()||(r[e]+=i),t};return n.writesPC=e==t.PC,n},null,null,null,function(e,i,s){var r=t.gprs,n=function(){return addr=r[e]-i};return n.writesPC=!1,n},function(e,i,s){var r=t.gprs,n=function(){var t=r[e]-i;return s&&!s()||(r[e]=t),t};return n.writesPC=e==t.PC,n},null,null,function(e,i,s){var r=t.gprs,n=function(){return addr=r[e]+i};return n.writesPC=!1,n},function(e,i,s){var r=t.gprs,n=function(){var t=r[e]+i;return s&&!s()||(r[e]=t),t};return n.writesPC=e==t.PC,n},null,null],this.addressingMode23Register=[function(e,i,s){var r=t.gprs,n=function(){var t=r[e];return s&&!s()||(r[e]-=r[i]),t};return n.writesPC=e==t.PC,n},null,null,null,function(e,i,s){var r=t.gprs,n=function(){var t=r[e];return s&&!s()||(r[e]+=r[i]),t};return n.writesPC=e==t.PC,n},null,null,null,function(e,i,s){var r=t.gprs,n=function(){return r[e]-r[i]};return n.writesPC=!1,n},function(e,i,s){var r=t.gprs,n=function(){var t=r[e]-r[i];return s&&!s()||(r[e]=t),t};return n.writesPC=e==t.PC,n},null,null,function(e,i,s){var r=t.gprs,n=function(){return r[e]+r[i]};return n.writesPC=!1,n},function(e,i,s){var r=t.gprs,n=function(){var t=r[e]+r[i];return s&&!s()||(r[e]=t),t};return n.writesPC=e==t.PC,n},null,null],this.addressingMode2RegisterShifted=[function(e,i,s){var r=t.gprs,n=function(){var n=r[e];return s&&!s()||(i(),r[e]-=t.shifterOperand),n};return n.writesPC=e==t.PC,n},null,null,null,function(e,i,s){var r=t.gprs,n=function(){var n=r[e];return s&&!s()||(i(),r[e]+=t.shifterOperand),n};return n.writesPC=e==t.PC,n},null,null,null,function(e,i,s){var r=t.gprs,n=function(){return i(),r[e]-t.shifterOperand};return n.writesPC=!1,n},function(e,i,s){var r=t.gprs,n=function(){i();var n=r[e]-t.shifterOperand;return s&&!s()||(r[e]=n),n};return n.writesPC=e==t.PC,n},null,null,function(e,i,s){var r=t.gprs,n=function(){return i(),r[e]+t.shifterOperand};return n.writesPC=!1,n},function(e,i,s){var r=t.gprs,n=function(){i();var n=r[e]+t.shifterOperand;return s&&!s()||(r[e]=n),n};return n.writePC=e==t.PC,n},null,null]},ARMCoreArm.prototype.constructAddressingMode1ASR=function(t,e){var i=this.cpu,s=i.gprs;return function(){++i.cycles;var r=s[t];t==i.PC&&(r+=4),r&=255;var n=s[e];e==i.PC&&(n+=4),0==r?(i.shifterOperand=n,i.shifterCarryOut=i.cpsrC):r<32?(i.shifterOperand=n>>r,i.shifterCarryOut=n&1<<r-1):s[e]>>31?(i.shifterOperand=4294967295,i.shifterCarryOut=2147483648):(i.shifterOperand=0,i.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(t,e){var i=this.cpu,s=i.gprs;return function(){++i.cycles;var r=s[t];t==i.PC&&(r+=4),r&=255;var n=s[e];e==i.PC&&(n+=4),0==r?(i.shifterOperand=n,i.shifterCarryOut=i.cpsrC):r<32?(i.shifterOperand=n<<r,i.shifterCarryOut=n&1<<32-r):32==r?(i.shifterOperand=0,i.shifterCarryOut=1&n):(i.shifterOperand=0,i.shifterCarryOut=0)}},ARMCoreArm.prototype.constructAddressingMode1LSR=function(t,e){var i=this.cpu,s=i.gprs;return function(){++i.cycles;var r=s[t];t==i.PC&&(r+=4),r&=255;var n=s[e];e==i.PC&&(n+=4),0==r?(i.shifterOperand=n,i.shifterCarryOut=i.cpsrC):r<32?(i.shifterOperand=n>>>r,i.shifterCarryOut=n&1<<r-1):32==r?(i.shifterOperand=0,i.shifterCarryOut=n>>31):(i.shifterOperand=0,i.shifterCarryOut=0)}},ARMCoreArm.prototype.constructAddressingMode1ROR=function(t,e){var i=this.cpu,s=i.gprs;return function(){++i.cycles;var r=s[t];t==i.PC&&(r+=4),r&=255;var n=s[e];e==i.PC&&(n+=4);var o=31&r;0==r?(i.shifterOperand=n,i.shifterCarryOut=i.cpsrC):o?(i.shifterOperand=s[e]>>>o|s[e]<<32-o,i.shifterCarryOut=n&1<<o-1):(i.shifterOperand=n,i.shifterCarryOut=n>>31)}},ARMCoreArm.prototype.constructAddressingMode23Immediate=function(t,e,i){var s=(983040&t)>>16;return this.addressingMode23Immediate[(27262976&t)>>21](s,e,i)},ARMCoreArm.prototype.constructAddressingMode23Register=function(t,e,i){var s=(983040&t)>>16;return this.addressingMode23Register[(27262976&t)>>21](s,e,i)},ARMCoreArm.prototype.constructAddressingMode2RegisterShifted=function(t,e,i){var s=(983040&t)>>16;return this.addressingMode2RegisterShifted[(27262976&t)>>21](s,e,i)},ARMCoreArm.prototype.constructAddressingMode4=function(t,e){var i=this.cpu.gprs;return function(){return i[e]+t}},ARMCoreArm.prototype.constructAddressingMode4Writeback=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(o){var a=n[i]+t;return o&&s&&r.mmu.store32(n[i]+t-4,n[i]),n[i]+=e,a}},ARMCoreArm.prototype.constructADC=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){if(r.mmu.waitPrefetch32(n[r.PC]),!s||s()){i();var o=(r.shifterOperand>>>0)+!!r.cpsrC;n[t]=(n[e]>>>0)+o}}},ARMCoreArm.prototype.constructADCS=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){if(r.mmu.waitPrefetch32(n[r.PC]),!s||s()){i();var o=(r.shifterOperand>>>0)+!!r.cpsrC,a=(n[e]>>>0)+o;t==r.PC&&r.hasSPSR()?r.unpackCPSR(r.spsr):(r.cpsrN=a>>31,r.cpsrZ=!(4294967295&a),r.cpsrC=a>4294967295,r.cpsrV=n[e]>>31==o>>31&&n[e]>>31!=a>>31&&o>>31!=a>>31),n[t]=a}}},ARMCoreArm.prototype.constructADD=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){r.mmu.waitPrefetch32(n[r.PC]),s&&!s()||(i(),n[t]=(n[e]>>>0)+(r.shifterOperand>>>0))}},ARMCoreArm.prototype.constructADDS=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){if(r.mmu.waitPrefetch32(n[r.PC]),!s||s()){i();var o=(n[e]>>>0)+(r.shifterOperand>>>0);t==r.PC&&r.hasSPSR()?r.unpackCPSR(r.spsr):(r.cpsrN=o>>31,r.cpsrZ=!(4294967295&o),r.cpsrC=o>4294967295,r.cpsrV=n[e]>>31==r.shifterOperand>>31&&n[e]>>31!=o>>31&&r.shifterOperand>>31!=o>>31),n[t]=o}}},ARMCoreArm.prototype.constructAND=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){r.mmu.waitPrefetch32(n[r.PC]),s&&!s()||(i(),n[t]=n[e]&r.shifterOperand)}},ARMCoreArm.prototype.constructANDS=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){r.mmu.waitPrefetch32(n[r.PC]),s&&!s()||(i(),n[t]=n[e]&r.shifterOperand,t==r.PC&&r.hasSPSR()?r.unpackCPSR(r.spsr):(r.cpsrN=n[t]>>31,r.cpsrZ=!(4294967295&n[t]),r.cpsrC=r.shifterCarryOut))}},ARMCoreArm.prototype.constructB=function(t,e){var i=this.cpu,s=i.gprs;return function(){!e||e()?(i.mmu.waitPrefetch32(s[i.PC]),s[i.PC]+=t):i.mmu.waitPrefetch32(s[i.PC])}},ARMCoreArm.prototype.constructBIC=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){r.mmu.waitPrefetch32(n[r.PC]),s&&!s()||(i(),n[t]=n[e]&~r.shifterOperand)}},ARMCoreArm.prototype.constructBICS=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){r.mmu.waitPrefetch32(n[r.PC]),s&&!s()||(i(),n[t]=n[e]&~r.shifterOperand,t==r.PC&&r.hasSPSR()?r.unpackCPSR(r.spsr):(r.cpsrN=n[t]>>31,r.cpsrZ=!(4294967295&n[t]),r.cpsrC=r.shifterCarryOut))}},ARMCoreArm.prototype.constructBL=function(t,e){var i=this.cpu,s=i.gprs;return function(){!e||e()?(i.mmu.waitPrefetch32(s[i.PC]),s[i.LR]=s[i.PC]-4,s[i.PC]+=t):i.mmu.waitPrefetch32(s[i.PC])}},ARMCoreArm.prototype.constructBX=function(t,e){var i=this.cpu,s=i.gprs;return function(){!e||e()?(i.mmu.waitPrefetch32(s[i.PC]),i.switchExecMode(1&s[t]),s[i.PC]=4294967294&s[t]):i.mmu.waitPrefetch32(s[i.PC])}},ARMCoreArm.prototype.constructCMN=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){if(r.mmu.waitPrefetch32(n[r.PC]),!s||s()){i();var t=(n[e]>>>0)+(r.shifterOperand>>>0);r.cpsrN=t>>31,r.cpsrZ=!(4294967295&t),r.cpsrC=t>4294967295,r.cpsrV=n[e]>>31==r.shifterOperand>>31&&n[e]>>31!=t>>31&&r.shifterOperand>>31!=t>>31}}},ARMCoreArm.prototype.constructCMP=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){if(r.mmu.waitPrefetch32(n[r.PC]),!s||s()){i();var t=n[e]-r.shifterOperand;r.cpsrN=t>>31,r.cpsrZ=!(4294967295&t),r.cpsrC=n[e]>>>0>=r.shifterOperand>>>0,r.cpsrV=n[e]>>31!=r.shifterOperand>>31&&n[e]>>31!=t>>31}}},ARMCoreArm.prototype.constructEOR=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){r.mmu.waitPrefetch32(n[r.PC]),s&&!s()||(i(),n[t]=n[e]^r.shifterOperand)}},ARMCoreArm.prototype.constructEORS=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){r.mmu.waitPrefetch32(n[r.PC]),s&&!s()||(i(),n[t]=n[e]^r.shifterOperand,t==r.PC&&r.hasSPSR()?r.unpackCPSR(r.spsr):(r.cpsrN=n[t]>>31,r.cpsrZ=!(4294967295&n[t]),r.cpsrC=r.shifterCarryOut))}},ARMCoreArm.prototype.constructLDM=function(t,e,i){var s=this.cpu,r=s.gprs,n=s.mmu;return function(){if(n.waitPrefetch32(r[s.PC]),!i||i()){var o,a,h=e(!1),c=0;for(o=t,a=0;o;o>>=1,++a)1&o&&(r[a]=n.load32(4294967292&h),h+=4,++c);n.waitMulti32(h,c),++s.cycles}}},ARMCoreArm.prototype.constructLDMS=function(t,e,i){var s=this.cpu,r=s.gprs,n=s.mmu;return function(){if(n.waitPrefetch32(r[s.PC]),!i||i()){var o,a,h=e(!1),c=0,u=s.mode;for(s.switchMode(s.MODE_SYSTEM),o=t,a=0;o;o>>=1,++a)1&o&&(r[a]=n.load32(4294967292&h),h+=4,++c);s.switchMode(u),n.waitMulti32(h,c),++s.cycles}}},ARMCoreArm.prototype.constructLDR=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){if(s.mmu.waitPrefetch32(r[s.PC]),!i||i()){var n=e();r[t]=s.mmu.load32(n),s.mmu.wait32(n),++s.cycles}}},ARMCoreArm.prototype.constructLDRB=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){if(s.mmu.waitPrefetch32(r[s.PC]),!i||i()){var n=e();r[t]=s.mmu.loadU8(n),s.mmu.wait(n),++s.cycles}}},ARMCoreArm.prototype.constructLDRH=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){if(s.mmu.waitPrefetch32(r[s.PC]),!i||i()){var n=e();r[t]=s.mmu.loadU16(n),s.mmu.wait(n),++s.cycles}}},ARMCoreArm.prototype.constructLDRSB=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){if(s.mmu.waitPrefetch32(r[s.PC]),!i||i()){var n=e();r[t]=s.mmu.load8(n),s.mmu.wait(n),++s.cycles}}},ARMCoreArm.prototype.constructLDRSH=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){if(s.mmu.waitPrefetch32(r[s.PC]),!i||i()){var n=e();r[t]=s.mmu.load16(n),s.mmu.wait(n),++s.cycles}}},ARMCoreArm.prototype.constructMLA=function(t,e,i,s,r){var n=this.cpu,o=n.gprs;return function(){if(n.mmu.waitPrefetch32(o[n.PC]),!r||r())if(++n.cycles,n.mmu.waitMul(i),4294901760&o[s]&&4294901760&o[i]){var a=(4294901760&o[s])*o[i]&4294967295,h=(65535&o[s])*o[i]&4294967295;o[t]=a+h+o[e]&4294967295}else o[t]=o[s]*o[i]+o[e]}},ARMCoreArm.prototype.constructMLAS=function(t,e,i,s,r){var n=this.cpu,o=n.gprs;return function(){if(n.mmu.waitPrefetch32(o[n.PC]),!r||r()){if(++n.cycles,n.mmu.waitMul(i),4294901760&o[s]&&4294901760&o[i]){var a=(4294901760&o[s])*o[i]&4294967295,h=(65535&o[s])*o[i]&4294967295;o[t]=a+h+o[e]&4294967295}else o[t]=o[s]*o[i]+o[e];n.cpsrN=o[t]>>31,n.cpsrZ=!(4294967295&o[t])}}},ARMCoreArm.prototype.constructMOV=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){r.mmu.waitPrefetch32(n[r.PC]),s&&!s()||(i(),n[t]=r.shifterOperand)}},ARMCoreArm.prototype.constructMOVS=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){r.mmu.waitPrefetch32(n[r.PC]),s&&!s()||(i(),n[t]=r.shifterOperand,t==r.PC&&r.hasSPSR()?r.unpackCPSR(r.spsr):(r.cpsrN=n[t]>>31,r.cpsrZ=!(4294967295&n[t]),r.cpsrC=r.shifterCarryOut))}},ARMCoreArm.prototype.constructMRS=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){s.mmu.waitPrefetch32(r[s.PC]),i&&!i()||(r[t]=e?s.spsr:s.packCPSR())}},ARMCoreArm.prototype.constructMSR=function(t,e,i,s,r){var n=this.cpu,o=n.gprs,a=65536&i,h=524288&i;return function(){if(n.mmu.waitPrefetch32(o[n.PC]),!r||r()){var c;c=33554432&i?s:o[t];var u=(a?255:0)|(h?4278190080:0);e?(u&=n.USER_MASK|n.PRIV_MASK|n.STATE_MASK,n.spsr=n.spsr&~u|c&u):(u&n.USER_MASK&&(n.cpsrN=c>>31,n.cpsrZ=1073741824&c,n.cpsrC=536870912&c,n.cpsrV=268435456&c),n.mode!=n.MODE_USER&&u&n.PRIV_MASK&&(n.switchMode(15&c|16),n.cpsrI=128&c,n.cpsrF=64&c))}}},ARMCoreArm.prototype.constructMUL=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){if(r.mmu.waitPrefetch32(n[r.PC]),!s||s())if(r.mmu.waitMul(n[e]),4294901760&n[i]&&4294901760&n[e]){var o=(4294901760&n[i])*n[e]|0,a=(65535&n[i])*n[e]|0;n[t]=o+a}else n[t]=n[i]*n[e]}},ARMCoreArm.prototype.constructMULS=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){if(r.mmu.waitPrefetch32(n[r.PC]),!s||s()){if(r.mmu.waitMul(n[e]),4294901760&n[i]&&4294901760&n[e]){var o=(4294901760&n[i])*n[e]|0,a=(65535&n[i])*n[e]|0;n[t]=o+a}else n[t]=n[i]*n[e];r.cpsrN=n[t]>>31,r.cpsrZ=!(4294967295&n[t])}}},ARMCoreArm.prototype.constructMVN=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){r.mmu.waitPrefetch32(n[r.PC]),s&&!s()||(i(),n[t]=~r.shifterOperand)}},ARMCoreArm.prototype.constructMVNS=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){r.mmu.waitPrefetch32(n[r.PC]),s&&!s()||(i(),n[t]=~r.shifterOperand,t==r.PC&&r.hasSPSR()?r.unpackCPSR(r.spsr):(r.cpsrN=n[t]>>31,r.cpsrZ=!(4294967295&n[t]),r.cpsrC=r.shifterCarryOut))}},ARMCoreArm.prototype.constructORR=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){r.mmu.waitPrefetch32(n[r.PC]),s&&!s()||(i(),n[t]=n[e]|r.shifterOperand)}},ARMCoreArm.prototype.constructORRS=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){r.mmu.waitPrefetch32(n[r.PC]),s&&!s()||(i(),n[t]=n[e]|r.shifterOperand,t==r.PC&&r.hasSPSR()?r.unpackCPSR(r.spsr):(r.cpsrN=n[t]>>31,r.cpsrZ=!(4294967295&n[t]),r.cpsrC=r.shifterCarryOut))}},ARMCoreArm.prototype.constructRSB=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){r.mmu.waitPrefetch32(n[r.PC]),s&&!s()||(i(),n[t]=r.shifterOperand-n[e])}},ARMCoreArm.prototype.constructRSBS=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){if(r.mmu.waitPrefetch32(n[r.PC]),!s||s()){i();var o=r.shifterOperand-n[e];t==r.PC&&r.hasSPSR()?r.unpackCPSR(r.spsr):(r.cpsrN=o>>31,r.cpsrZ=!(4294967295&o),r.cpsrC=r.shifterOperand>>>0>=n[e]>>>0,r.cpsrV=r.shifterOperand>>31!=n[e]>>31&&r.shifterOperand>>31!=o>>31),n[t]=o}}},ARMCoreArm.prototype.constructRSC=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){if(r.mmu.waitPrefetch32(n[r.PC]),!s||s()){i();var o=(n[e]>>>0)+!r.cpsrC;n[t]=(r.shifterOperand>>>0)-o}}},ARMCoreArm.prototype.constructRSCS=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){if(r.mmu.waitPrefetch32(n[r.PC]),!s||s()){i();var o=(n[e]>>>0)+!r.cpsrC,a=(r.shifterOperand>>>0)-o;t==r.PC&&r.hasSPSR()?r.unpackCPSR(r.spsr):(r.cpsrN=a>>31,r.cpsrZ=!(4294967295&a),r.cpsrC=r.shifterOperand>>>0>=a>>>0,r.cpsrV=r.shifterOperand>>31!=o>>31&&r.shifterOperand>>31!=a>>31),n[t]=a}}},ARMCoreArm.prototype.constructSBC=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){if(r.mmu.waitPrefetch32(n[r.PC]),!s||s()){i();var o=(r.shifterOperand>>>0)+!r.cpsrC;n[t]=(n[e]>>>0)-o}}},ARMCoreArm.prototype.constructSBCS=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){if(r.mmu.waitPrefetch32(n[r.PC]),!s||s()){i();var o=(r.shifterOperand>>>0)+!r.cpsrC,a=(n[e]>>>0)-o;t==r.PC&&r.hasSPSR()?r.unpackCPSR(r.spsr):(r.cpsrN=a>>31,r.cpsrZ=!(4294967295&a),r.cpsrC=n[e]>>>0>=a>>>0,r.cpsrV=n[e]>>31!=o>>31&&n[e]>>31!=a>>31),n[t]=a}}},ARMCoreArm.prototype.constructSMLAL=function(t,e,i,s,r){var n=this.cpu,o=n.gprs;return function(){if(n.mmu.waitPrefetch32(o[n.PC]),!r||r()){n.cycles+=2,n.mmu.waitMul(i);var a=(4294901760&o[s])*o[i],h=(65535&o[s])*o[i],c=(o[e]>>>0)+a+h;o[e]=c,o[t]+=Math.floor(c*(1/4294967296))}}},ARMCoreArm.prototype.constructSMLALS=function(t,e,i,s,r){var n=this.cpu,o=n.gprs;return function(){if(n.mmu.waitPrefetch32(o[n.PC]),!r||r()){n.cycles+=2,n.mmu.waitMul(i);var a=(4294901760&o[s])*o[i],h=(65535&o[s])*o[i],c=(o[e]>>>0)+a+h;o[e]=c,o[t]+=Math.floor(c*(1/4294967296)),n.cpsrN=o[t]>>31,n.cpsrZ=!(4294967295&o[t]||4294967295&o[e])}}},ARMCoreArm.prototype.constructSMULL=function(t,e,i,s,r){var n=this.cpu,o=n.gprs;return function(){if(n.mmu.waitPrefetch32(o[n.PC]),!r||r()){++n.cycles,n.mmu.waitMul(o[i]);var a=((4294901760&o[s])>>0)*(o[i]>>0),h=((65535&o[s])>>0)*(o[i]>>0);o[e]=(4294967295&a)+(4294967295&h)&4294967295,o[t]=Math.floor(a*(1/4294967296)+h*(1/4294967296))}}},ARMCoreArm.prototype.constructSMULLS=function(t,e,i,s,r){var n=this.cpu,o=n.gprs;return function(){if(n.mmu.waitPrefetch32(o[n.PC]),!r||r()){++n.cycles,n.mmu.waitMul(o[i]);var a=((4294901760&o[s])>>0)*(o[i]>>0),h=((65535&o[s])>>0)*(o[i]>>0);o[e]=(4294967295&a)+(4294967295&h)&4294967295,o[t]=Math.floor(a*(1/4294967296)+h*(1/4294967296)),n.cpsrN=o[t]>>31,n.cpsrZ=!(4294967295&o[t]||4294967295&o[e])}}},ARMCoreArm.prototype.constructSTM=function(t,e,i){var s=this.cpu,r=s.gprs,n=s.mmu;return function(){if(!i||i()){n.wait32(r[s.PC]);var o,a,h=e(!0),c=0;for(o=t,a=0;o;o>>=1,++a)1&o&&(n.store32(h,r[a]),h+=4,++c);n.waitMulti32(h,c)}else n.waitPrefetch32(r[s.PC])}},ARMCoreArm.prototype.constructSTMS=function(t,e,i){var s=this.cpu,r=s.gprs,n=s.mmu;return function(){if(!i||i()){n.wait32(r[s.PC]);var o,a,h=s.mode,c=e(!0),u=0;for(s.switchMode(s.MODE_SYSTEM),o=t,a=0;o;o>>=1,++a)1&o&&(n.store32(c,r[a]),c+=4,++u);s.switchMode(h),n.waitMulti32(c,u)}else n.waitPrefetch32(r[s.PC])}},ARMCoreArm.prototype.constructSTR=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){if(!i||i()){var n=e();s.mmu.store32(n,r[t]),s.mmu.wait32(n),s.mmu.wait32(r[s.PC])}else s.mmu.waitPrefetch32(r[s.PC])}},ARMCoreArm.prototype.constructSTRB=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){if(!i||i()){var n=e();s.mmu.store8(n,r[t]),s.mmu.wait(n),s.mmu.wait32(r[s.PC])}else s.mmu.waitPrefetch32(r[s.PC])}},ARMCoreArm.prototype.constructSTRH=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){if(!i||i()){var n=e();s.mmu.store16(n,r[t]),s.mmu.wait(n),s.mmu.wait32(r[s.PC])}else s.mmu.waitPrefetch32(r[s.PC])}},ARMCoreArm.prototype.constructSUB=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){r.mmu.waitPrefetch32(n[r.PC]),s&&!s()||(i(),n[t]=n[e]-r.shifterOperand)}},ARMCoreArm.prototype.constructSUBS=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){if(r.mmu.waitPrefetch32(n[r.PC]),!s||s()){i();var o=n[e]-r.shifterOperand;t==r.PC&&r.hasSPSR()?r.unpackCPSR(r.spsr):(r.cpsrN=o>>31,r.cpsrZ=!(4294967295&o),r.cpsrC=n[e]>>>0>=r.shifterOperand>>>0,r.cpsrV=n[e]>>31!=r.shifterOperand>>31&&n[e]>>31!=o>>31),n[t]=o}}},ARMCoreArm.prototype.constructSWI=function(t,e){var i=this.cpu,s=i.gprs;return function(){!e||e()?(i.irq.swi32(t),i.mmu.waitPrefetch32(s[i.PC])):i.mmu.waitPrefetch32(s[i.PC])}},ARMCoreArm.prototype.constructSWP=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){if(r.mmu.waitPrefetch32(n[r.PC]),!s||s()){r.mmu.wait32(n[e]),r.mmu.wait32(n[e]);var o=r.mmu.load32(n[e]);r.mmu.store32(n[e],n[i]),n[t]=o,++r.cycles}}},ARMCoreArm.prototype.constructSWPB=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){if(r.mmu.waitPrefetch32(n[r.PC]),!s||s()){r.mmu.wait(n[e]),r.mmu.wait(n[e]);var o=r.mmu.load8(n[e]);r.mmu.store8(n[e],n[i]),n[t]=o,++r.cycles}}},ARMCoreArm.prototype.constructTEQ=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){if(r.mmu.waitPrefetch32(n[r.PC]),!s||s()){i();var t=n[e]^r.shifterOperand;r.cpsrN=t>>31,r.cpsrZ=!(4294967295&t),r.cpsrC=r.shifterCarryOut}}},ARMCoreArm.prototype.constructTST=function(t,e,i,s){var r=this.cpu,n=r.gprs;return function(){if(r.mmu.waitPrefetch32(n[r.PC]),!s||s()){i();var t=n[e]&r.shifterOperand;r.cpsrN=t>>31,r.cpsrZ=!(4294967295&t),r.cpsrC=r.shifterCarryOut}}},ARMCoreArm.prototype.constructUMLAL=function(t,e,i,s,r){var n=this.cpu,o=n.gprs;return function(){if(n.mmu.waitPrefetch32(o[n.PC]),!r||r()){n.cycles+=2,n.mmu.waitMul(i);var a=((4294901760&o[s])>>>0)*(o[i]>>>0),h=(65535&o[s])*(o[i]>>>0),c=(o[e]>>>0)+a+h;o[e]=c,o[t]+=c*(1/4294967296)}}},ARMCoreArm.prototype.constructUMLALS=function(t,e,i,s,r){var n=this.cpu,o=n.gprs;return function(){if(n.mmu.waitPrefetch32(o[n.PC]),!r||r()){n.cycles+=2,n.mmu.waitMul(i);var a=((4294901760&o[s])>>>0)*(o[i]>>>0),h=(65535&o[s])*(o[i]>>>0),c=(o[e]>>>0)+a+h;o[e]=c,o[t]+=c*(1/4294967296),n.cpsrN=o[t]>>31,n.cpsrZ=!(4294967295&o[t]||4294967295&o[e])}}},ARMCoreArm.prototype.constructUMULL=function(t,e,i,s,r){var n=this.cpu,o=n.gprs;return function(){if(n.mmu.waitPrefetch32(o[n.PC]),!r||r()){++n.cycles,n.mmu.waitMul(o[i]);var a=((4294901760&o[s])>>>0)*(o[i]>>>0),h=((65535&o[s])>>>0)*(o[i]>>>0);o[e]=(4294967295&a)+(4294967295&h)&4294967295,o[t]=a*(1/4294967296)+h*(1/4294967296)>>>0}}},ARMCoreArm.prototype.constructUMULLS=function(t,e,i,s,r){var n=this.cpu,o=n.gprs;return function(){if(n.mmu.waitPrefetch32(o[n.PC]),!r||r()){++n.cycles,n.mmu.waitMul(o[i]);var a=((4294901760&o[s])>>>0)*(o[i]>>>0),h=((65535&o[s])>>>0)*(o[i]>>>0);o[e]=(4294967295&a)+(4294967295&h)&4294967295,o[t]=a*(1/4294967296)+h*(1/4294967296)>>>0,n.cpsrN=o[t]>>31,n.cpsrZ=!(4294967295&o[t]||4294967295&o[e])}}}},function(t,e){window.ARMCoreThumb=ARMCoreThumb=function(t){this.cpu=t},ARMCoreThumb.prototype.constructADC=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]);var r=(s[e]>>>0)+!!i.cpsrC,n=s[t],o=(n>>>0)+r,a=n>>31,h=o>>31,c=r>>31;i.cpsrN=h,i.cpsrZ=!(4294967295&o),i.cpsrC=o>4294967295,i.cpsrV=a==c&&a!=h&&c!=h,s[t]=o}},ARMCoreThumb.prototype.constructADD1=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){s.mmu.waitPrefetch(r[s.PC]);var n=(r[e]>>>0)+i;s.cpsrN=n>>31,s.cpsrZ=!(4294967295&n),s.cpsrC=n>4294967295,s.cpsrV=!(r[e]>>31)&&(r[e]>>31^n)>>31&&n>>31,r[t]=n}},ARMCoreThumb.prototype.constructADD2=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]);var r=(s[t]>>>0)+e;i.cpsrN=r>>31,i.cpsrZ=!(4294967295&r),i.cpsrC=r>4294967295,i.cpsrV=!(s[t]>>31)&&(s[t]^r)>>31&&(e^r)>>31,s[t]=r}},ARMCoreThumb.prototype.constructADD3=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){s.mmu.waitPrefetch(r[s.PC]);var n=(r[e]>>>0)+(r[i]>>>0);s.cpsrN=n>>31,s.cpsrZ=!(4294967295&n),s.cpsrC=n>4294967295,s.cpsrV=!((r[e]^r[i])>>31)&&(r[e]^n)>>31&&(r[i]^n)>>31,r[t]=n}},ARMCoreThumb.prototype.constructADD4=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]),s[t]+=s[e]}},ARMCoreThumb.prototype.constructADD5=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]),s[t]=(4294967292&s[i.PC])+e}},ARMCoreThumb.prototype.constructADD6=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]),s[t]=s[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,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]),s[t]=s[t]&s[e],i.cpsrN=s[t]>>31,i.cpsrZ=!(4294967295&s[t])}},ARMCoreThumb.prototype.constructASR1=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){s.mmu.waitPrefetch(r[s.PC]),0==i?(s.cpsrC=r[e]>>31,s.cpsrC?r[t]=4294967295:r[t]=0):(s.cpsrC=r[e]&1<<i-1,r[t]=r[e]>>i),s.cpsrN=r[t]>>31,s.cpsrZ=!(4294967295&r[t])}},ARMCoreThumb.prototype.constructASR2=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]);var r=255&s[e];r&&(r<32?(i.cpsrC=s[t]&1<<r-1,s[t]>>=r):(i.cpsrC=s[t]>>31,i.cpsrC?s[t]=4294967295:s[t]=0)),i.cpsrN=s[t]>>31,i.cpsrZ=!(4294967295&s[t])}},ARMCoreThumb.prototype.constructB1=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]),e()&&(s[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,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]),s[t]=s[t]&~s[e],i.cpsrN=s[t]>>31,i.cpsrZ=!(4294967295&s[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(t){var e=this.cpu,i=e.gprs;return function(){e.mmu.waitPrefetch(i[e.PC]);var s=i[e.PC];i[e.PC]=i[e.LR]+(t<<1),i[e.LR]=s-1}},ARMCoreThumb.prototype.constructBX=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]),i.switchExecMode(1&s[e]);var t=0;15==e&&(t=2&s[e]),s[i.PC]=s[e]&4294967294-t}},ARMCoreThumb.prototype.constructCMN=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]);var r=(s[t]>>>0)+(s[e]>>>0);i.cpsrN=r>>31,i.cpsrZ=!(4294967295&r),i.cpsrC=r>4294967295,i.cpsrV=s[t]>>31==s[e]>>31&&s[t]>>31!=r>>31&&s[e]>>31!=r>>31}},ARMCoreThumb.prototype.constructCMP1=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]);var r=s[t]-e;i.cpsrN=r>>31,i.cpsrZ=!(4294967295&r),i.cpsrC=s[t]>>>0>=e,i.cpsrV=s[t]>>31&&(s[t]^r)>>31}},ARMCoreThumb.prototype.constructCMP2=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]);var r=s[t],n=s[e],o=r-n,a=o>>31,h=r>>31;i.cpsrN=a,i.cpsrZ=!(4294967295&o),i.cpsrC=r>>>0>=n>>>0,i.cpsrV=h!=n>>31&&h!=a}},ARMCoreThumb.prototype.constructCMP3=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]);var r=s[t]-s[e];i.cpsrN=r>>31,i.cpsrZ=!(4294967295&r),i.cpsrC=s[t]>>>0>=s[e]>>>0,i.cpsrV=(s[t]^s[e])>>31&&(s[t]^r)>>31}},ARMCoreThumb.prototype.constructEOR=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]),s[t]=s[t]^s[e],i.cpsrN=s[t]>>31,i.cpsrZ=!(4294967295&s[t])}},ARMCoreThumb.prototype.constructLDMIA=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]);var r,n,o=s[t],a=0;for(r=1,n=0;n<8;r<<=1,++n)e&r&&(s[n]=i.mmu.load32(o),o+=4,++a);i.mmu.waitMulti32(o,a),1<<t&e||(s[t]=o)}},ARMCoreThumb.prototype.constructLDR1=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){s.mmu.waitPrefetch(r[s.PC]);var n=r[e]+i;r[t]=s.mmu.load32(n),s.mmu.wait32(n),++s.cycles}},ARMCoreThumb.prototype.constructLDR2=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){s.mmu.waitPrefetch(r[s.PC]),r[t]=s.mmu.load32(r[e]+r[i]),s.mmu.wait32(r[e]+r[i]),++s.cycles}},ARMCoreThumb.prototype.constructLDR3=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]),s[t]=i.mmu.load32((4294967292&s[i.PC])+e),i.mmu.wait32(s[i.PC]),++i.cycles}},ARMCoreThumb.prototype.constructLDR4=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]),s[t]=i.mmu.load32(s[i.SP]+e),i.mmu.wait32(s[i.SP]+e),++i.cycles}},ARMCoreThumb.prototype.constructLDRB1=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){var n=r[e]+i;s.mmu.waitPrefetch(r[s.PC]),r[t]=s.mmu.loadU8(n),s.mmu.wait(n),++s.cycles}},ARMCoreThumb.prototype.constructLDRB2=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){s.mmu.waitPrefetch(r[s.PC]),r[t]=s.mmu.loadU8(r[e]+r[i]),s.mmu.wait(r[e]+r[i]),++s.cycles}},ARMCoreThumb.prototype.constructLDRH1=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){var n=r[e]+i;s.mmu.waitPrefetch(r[s.PC]),r[t]=s.mmu.loadU16(n),s.mmu.wait(n),++s.cycles}},ARMCoreThumb.prototype.constructLDRH2=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){s.mmu.waitPrefetch(r[s.PC]),r[t]=s.mmu.loadU16(r[e]+r[i]),s.mmu.wait(r[e]+r[i]),++s.cycles}},ARMCoreThumb.prototype.constructLDRSB=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){s.mmu.waitPrefetch(r[s.PC]),r[t]=s.mmu.load8(r[e]+r[i]),s.mmu.wait(r[e]+r[i]),++s.cycles}},ARMCoreThumb.prototype.constructLDRSH=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){s.mmu.waitPrefetch(r[s.PC]),r[t]=s.mmu.load16(r[e]+r[i]),s.mmu.wait(r[e]+r[i]),++s.cycles}},ARMCoreThumb.prototype.constructLSL1=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){s.mmu.waitPrefetch(r[s.PC]),0==i?r[t]=r[e]:(s.cpsrC=r[e]&1<<32-i,r[t]=r[e]<<i),s.cpsrN=r[t]>>31,s.cpsrZ=!(4294967295&r[t])}},ARMCoreThumb.prototype.constructLSL2=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]);var r=255&s[e];r&&(r<32?(i.cpsrC=s[t]&1<<32-r,s[t]<<=r):(i.cpsrC=r>32?0:1&s[t],s[t]=0)),i.cpsrN=s[t]>>31,i.cpsrZ=!(4294967295&s[t])}},ARMCoreThumb.prototype.constructLSR1=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){s.mmu.waitPrefetch(r[s.PC]),0==i?(s.cpsrC=r[e]>>31,r[t]=0):(s.cpsrC=r[e]&1<<i-1,r[t]=r[e]>>>i),s.cpsrN=0,s.cpsrZ=!(4294967295&r[t])}},ARMCoreThumb.prototype.constructLSR2=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]);var r=255&s[e];r&&(r<32?(i.cpsrC=s[t]&1<<r-1,s[t]>>>=r):(i.cpsrC=r>32?0:s[t]>>31,s[t]=0)),i.cpsrN=s[t]>>31,i.cpsrZ=!(4294967295&s[t])}},ARMCoreThumb.prototype.constructMOV1=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]),s[t]=e,i.cpsrN=e>>31,i.cpsrZ=!(4294967295&e)}},ARMCoreThumb.prototype.constructMOV2=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){s.mmu.waitPrefetch(r[s.PC]);var i=r[e];s.cpsrN=i>>31,s.cpsrZ=!(4294967295&i),s.cpsrC=0,s.cpsrV=0,r[t]=i}},ARMCoreThumb.prototype.constructMOV3=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]),s[t]=s[e]}},ARMCoreThumb.prototype.constructMUL=function(t,e){var i=this.cpu,s=i.gprs;return function(){if(i.mmu.waitPrefetch(s[i.PC]),i.mmu.waitMul(s[e]),4294901760&s[e]&&4294901760&s[t]){var r=(4294901760&s[t])*s[e]&4294967295,n=(65535&s[t])*s[e]&4294967295;s[t]=r+n&4294967295}else s[t]*=s[e];i.cpsrN=s[t]>>31,i.cpsrZ=!(4294967295&s[t])}},ARMCoreThumb.prototype.constructMVN=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]),s[t]=~s[e],i.cpsrN=s[t]>>31,i.cpsrZ=!(4294967295&s[t])}},ARMCoreThumb.prototype.constructNEG=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]);var r=-s[e];i.cpsrN=r>>31,i.cpsrZ=!(4294967295&r),i.cpsrC=0>=r>>>0,i.cpsrV=s[e]>>31&&r>>31,s[t]=r}},ARMCoreThumb.prototype.constructORR=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]),s[t]=s[t]|s[e],i.cpsrN=s[t]>>31,i.cpsrZ=!(4294967295&s[t])}},ARMCoreThumb.prototype.constructPOP=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]),++i.cycles;var r,n,o=s[i.SP],a=0;for(r=1,n=0;n<8;r<<=1,++n)t&r&&(i.mmu.waitSeq32(o),s[n]=i.mmu.load32(o),o+=4,++a);e&&(s[i.PC]=4294967294&i.mmu.load32(o),o+=4,++a),i.mmu.waitMulti32(o,a),s[i.SP]=o}},ARMCoreThumb.prototype.constructPUSH=function(t,e){var i=this.cpu,s=i.gprs;return function(){var r,n,o=s[i.SP]-4,a=0;for(i.mmu.waitPrefetch(s[i.PC]),e&&(i.mmu.store32(o,s[i.LR]),o-=4,++a),r=128,n=7;r;r>>=1,--n)if(t&r){i.mmu.store32(o,s[n]),o-=4,++a;break}for(r>>=1,--n;r;r>>=1,--n)t&r&&(i.mmu.store32(o,s[n]),o-=4,++a);i.mmu.waitMulti32(o,a),s[i.SP]=o+4}},ARMCoreThumb.prototype.constructROR=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]);var r=255&s[e];if(r){var n=31&r;n>0?(i.cpsrC=s[t]&1<<n-1,s[t]=s[t]>>>n|s[t]<<32-n):i.cpsrC=s[t]>>31}i.cpsrN=s[t]>>31,i.cpsrZ=!(4294967295&s[t])}},ARMCoreThumb.prototype.constructSBC=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]);var r=(s[e]>>>0)+!i.cpsrC,n=(s[t]>>>0)-r;i.cpsrN=n>>31,i.cpsrZ=!(4294967295&n),i.cpsrC=s[t]>>>0>=n>>>0,i.cpsrV=(s[t]^r)>>31&&(s[t]^n)>>31,s[t]=n}},ARMCoreThumb.prototype.constructSTMIA=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.wait(s[i.PC]);var r,n,o=s[t],a=0;for(r=1,n=0;n<8;r<<=1,++n)if(e&r){i.mmu.store32(o,s[n]),o+=4,++a;break}for(r<<=1,++n;n<8;r<<=1,++n)e&r&&(i.mmu.store32(o,s[n]),o+=4,++a);i.mmu.waitMulti32(o,a),s[t]=o}},ARMCoreThumb.prototype.constructSTR1=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){var n=r[e]+i;s.mmu.store32(n,r[t]),s.mmu.wait(r[s.PC]),s.mmu.wait32(n)}},ARMCoreThumb.prototype.constructSTR2=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){s.mmu.store32(r[e]+r[i],r[t]),s.mmu.wait(r[s.PC]),s.mmu.wait32(r[e]+r[i])}},ARMCoreThumb.prototype.constructSTR3=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.store32(s[i.SP]+e,s[t]),i.mmu.wait(s[i.PC]),i.mmu.wait32(s[i.SP]+e)}},ARMCoreThumb.prototype.constructSTRB1=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){var n=r[e]+i;s.mmu.store8(n,r[t]),s.mmu.wait(r[s.PC]),s.mmu.wait(n)}},ARMCoreThumb.prototype.constructSTRB2=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){s.mmu.store8(r[e]+r[i],r[t]),s.mmu.wait(r[s.PC]),s.mmu.wait(r[e]+r[i])}},ARMCoreThumb.prototype.constructSTRH1=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){var n=r[e]+i;s.mmu.store16(n,r[t]),s.mmu.wait(r[s.PC]),s.mmu.wait(n)}},ARMCoreThumb.prototype.constructSTRH2=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){s.mmu.store16(r[e]+r[i],r[t]),s.mmu.wait(r[s.PC]),s.mmu.wait(r[e]+r[i])}},ARMCoreThumb.prototype.constructSUB1=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){s.mmu.waitPrefetch(r[s.PC]);var n=r[e]-i;s.cpsrN=n>>31,s.cpsrZ=!(4294967295&n),s.cpsrC=r[e]>>>0>=i,s.cpsrV=r[e]>>31&&(r[e]^n)>>31,r[t]=n}},ARMCoreThumb.prototype.constructSUB2=function(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]);var r=s[t]-e;i.cpsrN=r>>31,i.cpsrZ=!(4294967295&r),i.cpsrC=s[t]>>>0>=e,i.cpsrV=s[t]>>31&&(s[t]^r)>>31,s[t]=r}},ARMCoreThumb.prototype.constructSUB3=function(t,e,i){var s=this.cpu,r=s.gprs;return function(){s.mmu.waitPrefetch(r[s.PC]);var n=r[e]-r[i];s.cpsrN=n>>31,s.cpsrZ=!(4294967295&n),s.cpsrC=r[e]>>>0>=r[i]>>>0,s.cpsrV=r[e]>>31!=r[i]>>31&&r[e]>>31!=n>>31,r[t]=n}},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(t,e){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[i.PC]);var r=s[t]&s[e];i.cpsrN=r>>31,i.cpsrZ=!(4294967295&r)}}},function(t,e){window.GameBoyAdvanceAudio=function(){if(window.AudioContext=window.AudioContext||window.webkitAudioContext,window.AudioContext){var t=this;this.context=new AudioContext,this.bufferSize=0,this.bufferSize=4096,this.maxSamples=this.bufferSize<<2,this.buffers=[new Float32Array(this.maxSamples),new Float32Array(this.maxSamples)],this.sampleMask=this.maxSamples-1,this.context.createScriptProcessor?this.jsAudio=this.context.createScriptProcessor(this.bufferSize):this.jsAudio=this.context.createJavaScriptNode(this.bufferSize),this.jsAudio.onaudioprocess=function(e){t.audioProcess(e)}}else this.context=null;this.masterEnable=!0,this.masterVolume=1,this.SOUND_MAX=1024,this.FIFO_MAX=512,this.PSG_MAX=128},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&&this.channel3Pointer>=64?this.channel3Pointer-=64:(!this.channel3Bank&&this.channel3Pointer>=32||this.channel3Pointer>=64)&&(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)if(t)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],s=2047&e;i.frequency=s,i.interval=this.cpuFrequency*(2048-s)/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(t.frequency>2047)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,s=this.cpuFrequency*(e*(2<<i))/524288;s!=this.channel4.interval&&(this.channel4.interval=s,this.resetChannel4());var r=8&t?7:15;r!=this.channel4.width&&(this.channel4.width=r,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,t.volume>1?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;this.fifoA.length>28&&(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;this.fifoB.length>28&&(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,s=0;(e=this.squareChannels[0]).playing&&(t=e.sample*this.soundRatio*this.PSG_MAX,1&this.enabledLeft&&(i+=t),1&this.enabledRight&&(s+=t)),(e=this.squareChannels[1]).playing&&(t=e.sample*this.soundRatio*this.PSG_MAX,2&this.enabledLeft&&(i+=t),2&this.enabledRight&&(s+=t)),this.playingChannel3&&(t=this.channel3Sample*this.soundRatio*this.channel3Volume*this.PSG_MAX,4&this.enabledLeft&&(i+=t),4&this.enabledRight&&(s+=t)),this.playingChannel4&&(t=this.channel4.sample*this.soundRatio*this.PSG_MAX,8&this.enabledLeft&&(i+=t),8&this.enabledRight&&(s+=t)),this.enableChannelA&&(t=this.fifoASample*this.FIFO_MAX*this.ratioChannelA,this.enableLeftChannelA&&(i+=t),this.enableRightChannelA&&(s+=t)),this.enableChannelB&&(t=this.fifoBSample*this.FIFO_MAX*this.ratioChannelB,this.enableLeftChannelB&&(i+=t),this.enableRightChannelB&&(s+=t));var r=this.samplePointer;i*=this.masterVolume/this.SOUND_MAX,i=Math.max(Math.min(i,1),-1),s*=this.masterVolume/this.SOUND_MAX,s=Math.max(Math.min(s,1),-1),this.buffers&&(this.buffers[0][r]=i,this.buffers[1][r]=s),this.samplePointer=r+1&this.sampleMask},GameBoyAdvanceAudio.prototype.audioProcess=function(t){var e=t.outputBuffer.getChannelData(0),i=t.outputBuffer.getChannelData(1);if(this.masterEnable){var s,r=this.outputPointer;for(s=0;s<this.bufferSize;++s,r+=this.resampleRatio){if(r>=this.maxSamples&&(r-=this.maxSamples),(0|r)==this.samplePointer){++this.backup;break}e[s]=this.buffers[0][0|r],i[s]=this.buffers[1][0|r]}for(;s<this.bufferSize;++s)e[s]=0,i[s]=0;this.outputPointer=r,++this.totalSamples}else for(s=0;s<this.bufferSize;++s)e[s]=0,i[s]=0}},function(t,e){window.GameBoyAdvanceVideo=function(){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(){}},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()}},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()}},function(t,e){function i(t,e,i){if(this.owner=t,this.blocks=[],this.blockSize=i,this.mask=(1<<i)-1,this.size=e,i)for(var s=0;s<e>>i;++s)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 s(){this.worker=new Worker("js/video/worker.js"),this.currentFrame=0,this.delay=0,this.skipFrame=!1,this.dirty=null;var t=this,e={finish:function(e){t.backing=e.backing,t.caller.finishDraw(t.backing),--t.delay}};this.worker.onmessage=function(t){e[t.data.type](t.data)}}i.prototype.combine=function(){if(this.blocks.length>1){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},i.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))},i.prototype.load8=function(t){return this.blocks[t>>this.blockSize].load8(t&this.mask)},i.prototype.load16=function(t){return this.blocks[t>>this.blockSize].load16(t&this.mask)},i.prototype.loadU8=function(t){return this.blocks[t>>this.blockSize].loadU8(t&this.mask)},i.prototype.loadU16=function(t){return this.blocks[t>>this.blockSize].loadU16(t&this.mask)},i.prototype.load32=function(t){return this.blocks[t>>this.blockSize].load32(t&this.mask)},i.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))},i.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)},i.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)},i.prototype.invalidatePage=function(t){},s.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)},s.prototype.clear=function(t){this.palette=new i(this,t.SIZE_PALETTE_RAM,0),this.vram=new i(this,t.SIZE_VRAM,13),this.oam=new i(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})},s.prototype.freeze=function(t){return{palette:Serializer.prefix(this.palette.combine()),vram:Serializer.prefix(this.vram.combine()),oam:Serializer.prefix(this.oam.combine())}},s.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)},s.prototype.writeDisplayControl=function(t){this.dirty=this.dirty||{},this.dirty.DISPCNT=t},s.prototype.writeBackgroundControl=function(t,e){this.dirty=this.dirty||{},this.dirty.BGCNT=this.dirty.BGCNT||[],this.dirty.BGCNT[t]=e},s.prototype.writeBackgroundHOffset=function(t,e){this.dirty=this.dirty||{},this.dirty.BGHOFS=this.dirty.BGHOFS||[],this.dirty.BGHOFS[t]=e},s.prototype.writeBackgroundVOffset=function(t,e){this.dirty=this.dirty||{},this.dirty.BGVOFS=this.dirty.BGVOFS||[],this.dirty.BGVOFS[t]=e},s.prototype.writeBackgroundRefX=function(t,e){this.dirty=this.dirty||{},this.dirty.BGX=this.dirty.BGX||[],this.dirty.BGX[t]=e},s.prototype.writeBackgroundRefY=function(t,e){this.dirty=this.dirty||{},this.dirty.BGY=this.dirty.BGY||[],this.dirty.BGY[t]=e},s.prototype.writeBackgroundParamA=function(t,e){this.dirty=this.dirty||{},this.dirty.BGPA=this.dirty.BGPA||[],this.dirty.BGPA[t]=e},s.prototype.writeBackgroundParamB=function(t,e){this.dirty=this.dirty||{},this.dirty.BGPB=this.dirty.BGPB||[],this.dirty.BGPB[t]=e},s.prototype.writeBackgroundParamC=function(t,e){this.dirty=this.dirty||{},this.dirty.BGPC=this.dirty.BGPC||[],this.dirty.BGPC[t]=e},s.prototype.writeBackgroundParamD=function(t,e){this.dirty=this.dirty||{},this.dirty.BGPD=this.dirty.BGPD||[],this.dirty.BGPD[t]=e},s.prototype.writeWin0H=function(t){this.dirty=this.dirty||{},this.dirty.WIN0H=t},s.prototype.writeWin1H=function(t){this.dirty=this.dirty||{},this.dirty.WIN1H=t},s.prototype.writeWin0V=function(t){this.dirty=this.dirty||{},this.dirty.WIN0V=t},s.prototype.writeWin1V=function(t){this.dirty=this.dirty||{},this.dirty.WIN1V=t},s.prototype.writeWinIn=function(t){this.dirty=this.dirty||{},this.dirty.WININ=t},s.prototype.writeWinOut=function(t){this.dirty=this.dirty||{},this.dirty.WINOUT=t},s.prototype.writeBlendControl=function(t){this.dirty=this.dirty||{},this.dirty.BLDCNT=t},s.prototype.writeBlendAlpha=function(t){this.dirty=this.dirty||{},this.dirty.BLDALPHA=t},s.prototype.writeBlendY=function(t){this.dirty=this.dirty||{},this.dirty.BLDY=t},s.prototype.writeMosaic=function(t){this.dirty=this.dirty||{},this.dirty.MOSAIC=t},s.prototype.clearSubsets=function(t,e){if(this.dirty=this.dirty||{},4&e&&(this.palette=new i(this,t.SIZE_PALETTE_RAM,0),t.mmap(t.REGION_PALETTE_RAM,this.palette),this.memoryDirtied(this.palette,0)),8&e){this.vram=new i(this,t.SIZE_VRAM,13),t.mmap(t.REGION_VRAM,this.vram);for(var s=0;s<this.vram.blocks.length;++s)this.memoryDirtied(this.vram,s)}16&e&&(this.oam=new i(this,t.SIZE_OAM,0),t.mmap(t.REGION_OAM,this.oam),this.memoryDirtied(this.oam,0))},s.prototype.setBacking=function(t){this.backing=t,this.worker.postMessage({type:"start",backing:this.backing})},s.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}},s.prototype.startDraw=function(){++this.currentFrame,this.delay<=0&&(this.skipFrame=!1),this.skipFrame||++this.delay},s.prototype.finishDraw=function(t){this.caller=t,this.skipFrame||(this.worker.postMessage({type:"finish",scanlines:this.scanlineQueue,frame:this.currentFrame}),this.scanlineQueue=[],this.delay>2&&(this.skipFrame=!0))}},function(t,e){window.GameBoyAdvanceInterruptHandler=function(){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},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&&this.audio.dmaA>=0&&this.audio.sampleFifoA(),this.audio.enableChannelB&&!this.audio.soundTimerB&&this.audio.dmaB>=0&&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&&this.audio.dmaA>=0&&this.audio.sampleFifoA(),this.audio.enableChannelB&&this.audio.soundTimerB&&this.audio.dmaB>=0&&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),s=32256;s<32768;s+=4)e.store32(s,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 r=this.cpu.gprs[0];if(1&r&&(this.core.mmu.memory[this.core.mmu.REGION_WORKING_RAM]=new MemoryBlock(this.core.mmu.SIZE_WORKING_RAM,9)),2&r)for(s=0;s<this.core.mmu.SIZE_WORKING_IRAM-512;s+=4)this.core.mmu.memory[this.core.mmu.REGION_WORKING_IRAM].store32(s,0);28&r&&this.video.renderPath.clearSubsets(this.core.mmu,r),224&r&&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]),o=(0|this.cpu.gprs[0])%(0|this.cpu.gprs[1]);this.cpu.gprs[0]=0|n,this.cpu.gprs[1]=0|o,this.cpu.gprs[3]=Math.abs(0|n);break;case 7:n=(0|this.cpu.gprs[1])/(0|this.cpu.gprs[0]),o=(0|this.cpu.gprs[1])%(0|this.cpu.gprs[0]);this.cpu.gprs[0]=0|n,this.cpu.gprs[1]=0|o,this.cpu.gprs[3]=Math.abs(0|n);break;case 8:var a=Math.sqrt(this.cpu.gprs[0]);this.cpu.gprs[0]=0|a;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],p=this.cpu.gprs[1],d=1048575&(m=this.cpu.gprs[2]),l=67108864&m?4:2;if(16777216&m)if(4==l){u&=4294967292,p&=4294967292;var f=this.cpu.mmu.load32(u);for(s=0;s<d;++s)this.cpu.mmu.store32(p+(s<<2),f)}else{u&=4294967294,p&=4294967294;for(f=this.cpu.mmu.load16(u),s=0;s<d;++s)this.cpu.mmu.store16(p+(s<<1),f)}else if(4==l){u&=4294967292,p&=4294967292;for(s=0;s<d;++s){f=this.cpu.mmu.load32(u+(s<<2));this.cpu.mmu.store32(p+(s<<2),f)}}else{u&=4294967294,p&=4294967294;for(s=0;s<d;++s){f=this.cpu.mmu.load16(u+(s<<1));this.cpu.mmu.store16(p+(s<<1),f)}}return;case 12:var m;u=4294967292&this.cpu.gprs[0],p=4294967292&this.cpu.gprs[1];if(d=(d=1048575&(m=this.cpu.gprs[2]))+7>>3<<3,16777216&m)for(f=this.cpu.mmu.load32(u),s=0;s<d;++s)this.cpu.mmu.store32(p+(s<<2),f);else for(s=0;s<d;++s){f=this.cpu.mmu.load32(u+(s<<2));this.cpu.mmu.store32(p+(s<<2),f)}return;case 14:s=this.cpu.gprs[2];for(var A,y,b,R,v,C,S=this.cpu.gprs[0],w=this.cpu.gprs[1];s--;)A=this.core.mmu.load32(S)/256,y=this.core.mmu.load32(S+4)/256,b=this.core.mmu.load16(S+8),R=this.core.mmu.load16(S+10),g=this.core.mmu.load16(S+12)/256,_=this.core.mmu.load16(S+14)/256,M=(this.core.mmu.loadU16(S+16)>>8)/128*Math.PI,S+=20,I=T=Math.cos(M),E=O=Math.sin(M),v=A-((I*=g)*b+(E*=-g)*R),C=y-((O*=_)*b+(T*=_)*R),this.core.mmu.store16(w,256*I|0),this.core.mmu.store16(w+2,256*E|0),this.core.mmu.store16(w+4,256*O|0),this.core.mmu.store16(w+6,256*T|0),this.core.mmu.store32(w+8,256*v|0),this.core.mmu.store32(w+12,256*C|0),w+=16;break;case 15:s=this.cpu.gprs[2],S=this.cpu.gprs[0],w=this.cpu.gprs[1];for(var g,_,M,I,E,O,T,P=this.cpu.gprs[3];s--;)g=this.core.mmu.load16(S)/256,_=this.core.mmu.load16(S+2)/256,M=(this.core.mmu.loadU16(S+4)>>8)/128*Math.PI,S+=6,I=T=Math.cos(M),E=O=Math.sin(M),I*=g,E*=-g,O*=_,T*=_,this.core.mmu.store16(w,256*I|0),this.core.mmu.store16(w+P,256*E|0),this.core.mmu.store16(w+2*P,256*O|0),this.core.mmu.store16(w+3*P,256*T|0),w+=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 s=this.dma[0];t=s.nextIRQ,s.enable&&s.doIrq&&t&&(!e||t<e)&&(e=t),t=(s=this.dma[1]).nextIRQ,s.enable&&s.doIrq&&t&&(!e||t<e)&&(e=t),t=(s=this.dma[2]).nextIRQ,s.enable&&s.doIrq&&t&&(!e||t<e)&&(e=t),t=(s=this.dma[3]).nextIRQ,s.enable&&s.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],s=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"),!s&&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],s=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 r=i.enable;i.enable=!!((128&e)>>7<<t),!r&&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):r&&!i.enable?(i.countUp||(this.io.registers[this.io.TM0CNT_LO+(t<<2)>>1]=i.oldReload+(this.cpu.cycles-i.lastEvent)>>s),--this.timersEnabled):i.prescaleBits==s||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 s,r,n,o,a,h=(4294967040&this.cpu.mmu.load32(t))>>8,c=t+4,u=e,p=0,d=0;h>0;)if(p){if(128&s)for(r=this.cpu.mmu.loadU8(c)|this.cpu.mmu.loadU8(c+1)<<8,c+=2,n=u-((15&r)<<8|(65280&r)>>8)-1,o=3+((240&r)>>4);o--&&h;)a=this.cpu.mmu.loadU8(n++),2==i?(d>>=8,d|=a<<8,1&u&&this.cpu.mmu.store16(u-1,d)):this.cpu.mmu.store8(u,a),--h,++u;else a=this.cpu.mmu.loadU8(c++),2==i?(d>>=8,d|=a<<8,1&u&&this.cpu.mmu.store16(u-1,d)):this.cpu.mmu.store8(u,a),--h,++u;s<<=1,--p}else s=this.cpu.mmu.loadU8(c++),p=8},GameBoyAdvanceInterruptHandler.prototype.huffman=function(t,e){t&=4294967292;var i=this.cpu.mmu.load32(t),s=i>>8,r=15&i;if(32%r)throw"Unimplemented unaligned Huffman";var n=4-s&3;s&=4294967292;var o,a,h,c=[],u=1+(this.cpu.mmu.loadU8(t+4)<<1),p=t+5+u,d=4294967292&e;for(a=0;a<u;++a)c.push(this.cpu.mmu.loadU8(t+5+a));var l,f,m=0,A=0;for(h=c[0];s>0;){var y=this.cpu.mmu.load32(p);for(p+=4,l=32;l>0;--l,y<<=1){if("number"==typeof h){var b=(m-1|1)+((63&h)<<1)+2;h={l:b,r:b+1,lTerm:128&h,rTerm:64&h},c[m]=h}if(2147483648&y){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]}o|=(f&(1<<r)-1)<<A,A+=r,m=0,h=c[0],32==A&&(A=0,this.cpu.mmu.store32(d,o),d+=4,s-=4,o=0)}}n&&this.cpu.mmu.store32(d,o)},GameBoyAdvanceInterruptHandler.prototype.rl=function(t,e,i){t&=4294967292;for(var s,r,n=(4294967040&this.cpu.mmu.load32(t))>>8,o=4-n&3,a=t+4,h=e,c=0;n>0;)if(128&(s=this.cpu.mmu.loadU8(a++)))for(s&=127,s+=3,r=this.cpu.mmu.loadU8(a++);s--&&n;)--n,2==i?(c>>=8,c|=r<<8,1&h&&this.cpu.mmu.store16(h-1,c)):this.cpu.mmu.store8(h,r),++h;else for(s++;s--&&n;)--n,r=this.cpu.mmu.loadU8(a++),2==i?(c>>=8,c|=r<<8,1&h&&this.cpu.mmu.store16(h-1,c)):this.cpu.mmu.store8(h,r),++h;for(;o--;)this.cpu.mmu.store8(h++,0)}},function(t,e){window.GameBoyAdvanceKeypad=function(){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=[]},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,"keydown"==t.type?this.currentDown&=~e: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(t){this.gamepads=self.gamepads.filter((function(e){return e!=t}))},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]);this.gamepads.length>0&&this.gamepadHandler(this.gamepads[0])},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)}},function(t,e){window.GameBoyAdvanceSIO=function(){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]},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}},function(t,e){function i(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]}window.GameBoyAdvanceGPIO=function(t,e){this.core=t,this.rom=e,this.readWrite=0,this.direction=0,this.device=new i(this)},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)}},i.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},i.prototype.setDirection=function(t){this.direction=t},i.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)},i.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},i.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),t.getHours()>=12&&(this.time[4]|=128)),this.time[5]=this.bcd(t.getMinutes()),this.time[6]=this.bcd(t.getSeconds())},i.prototype.bcd=function(t){var e=t%10;return e+=(t/=10)%10<<4}},function(t,e,i){"use strict";(function(e){t.exports=function(t){for(var i="undefined"!=typeof window&&"function"==typeof window.atob?window.atob(t):e.from(t,"base64").toString("binary"),s=new Uint8Array(i.length),r=0;r<i.length;++r)s[r]=i.charCodeAt(r);return s.buffer}}).call(this,i(25).Buffer)},function(t,e,i){"use strict";(function(t){
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <http://feross.org>
* @license MIT
*/
var s=i(26),r=i(27),n=i(28);function o(){return h.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(t,e){if(o()<e)throw new RangeError("Invalid typed array length");return h.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=h.prototype:(null===t&&(t=new h(e)),t.length=e),t}function h(t,e,i){if(!(h.TYPED_ARRAY_SUPPORT||this instanceof h))return new h(t,e,i);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return p(this,t)}return c(this,t,e,i)}function c(t,e,i,s){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,i,s){if(e.byteLength,i<0||e.byteLength<i)throw new RangeError("'offset' is out of bounds");if(e.byteLength<i+(s||0))throw new RangeError("'length' is out of bounds");e=void 0===i&&void 0===s?new Uint8Array(e):void 0===s?new Uint8Array(e,i):new Uint8Array(e,i,s);h.TYPED_ARRAY_SUPPORT?(t=e).__proto__=h.prototype:t=d(t,e);return t}(t,e,i,s):"string"==typeof e?function(t,e,i){"string"==typeof i&&""!==i||(i="utf8");if(!h.isEncoding(i))throw new TypeError('"encoding" must be a valid string encoding');var s=0|f(e,i),r=(t=a(t,s)).write(e,i);r!==s&&(t=t.slice(0,r));return t}(t,e,i):function(t,e){if(h.isBuffer(e)){var i=0|l(e.length);return 0===(t=a(t,i)).length||e.copy(t,0,0,i),t}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||(s=e.length)!=s?a(t,0):d(t,e);if("Buffer"===e.type&&n(e.data))return d(t,e.data)}var s;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function u(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function p(t,e){if(u(e),t=a(t,e<0?0:0|l(e)),!h.TYPED_ARRAY_SUPPORT)for(var i=0;i<e;++i)t[i]=0;return t}function d(t,e){var i=e.length<0?0:0|l(e.length);t=a(t,i);for(var s=0;s<i;s+=1)t[s]=255&e[s];return t}function l(t){if(t>=o())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o().toString(16)+" bytes");return 0|t}function f(t,e){if(h.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var i=t.length;if(0===i)return 0;for(var s=!1;;)switch(e){case"ascii":case"latin1":case"binary":return i;case"utf8":case"utf-8":case void 0:return H(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*i;case"hex":return i>>>1;case"base64":return F(t).length;default:if(s)return H(t).length;e=(""+e).toLowerCase(),s=!0}}function m(t,e,i){var s=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===i||i>this.length)&&(i=this.length),i<=0)return"";if((i>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return O(this,e,i);case"utf8":case"utf-8":return M(this,e,i);case"ascii":return I(this,e,i);case"latin1":case"binary":return E(this,e,i);case"base64":return _(this,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,e,i);default:if(s)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),s=!0}}function A(t,e,i){var s=t[e];t[e]=t[i],t[i]=s}function y(t,e,i,s,r){if(0===t.length)return-1;if("string"==typeof i?(s=i,i=0):i>2147483647?i=2147483647:i<-2147483648&&(i=-2147483648),i=+i,isNaN(i)&&(i=r?0:t.length-1),i<0&&(i=t.length+i),i>=t.length){if(r)return-1;i=t.length-1}else if(i<0){if(!r)return-1;i=0}if("string"==typeof e&&(e=h.from(e,s)),h.isBuffer(e))return 0===e.length?-1:b(t,e,i,s,r);if("number"==typeof e)return e&=255,h.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?r?Uint8Array.prototype.indexOf.call(t,e,i):Uint8Array.prototype.lastIndexOf.call(t,e,i):b(t,[e],i,s,r);throw new TypeError("val must be string, number or Buffer")}function b(t,e,i,s,r){var n,o=1,a=t.length,h=e.length;if(void 0!==s&&("ucs2"===(s=String(s).toLowerCase())||"ucs-2"===s||"utf16le"===s||"utf-16le"===s)){if(t.length<2||e.length<2)return-1;o=2,a/=2,h/=2,i/=2}function c(t,e){return 1===o?t[e]:t.readUInt16BE(e*o)}if(r){var u=-1;for(n=i;n<a;n++)if(c(t,n)===c(e,-1===u?0:n-u)){if(-1===u&&(u=n),n-u+1===h)return u*o}else-1!==u&&(n-=n-u),u=-1}else for(i+h>a&&(i=a-h),n=i;n>=0;n--){for(var p=!0,d=0;d<h;d++)if(c(t,n+d)!==c(e,d)){p=!1;break}if(p)return n}return-1}function R(t,e,i,s){i=Number(i)||0;var r=t.length-i;s?(s=Number(s))>r&&(s=r):s=r;var n=e.length;if(n%2!=0)throw new TypeError("Invalid hex string");s>n/2&&(s=n/2);for(var o=0;o<s;++o){var a=parseInt(e.substr(2*o,2),16);if(isNaN(a))return o;t[i+o]=a}return o}function v(t,e,i,s){return V(H(e,t.length-i),t,i,s)}function C(t,e,i,s){return V(function(t){for(var e=[],i=0;i<t.length;++i)e.push(255&t.charCodeAt(i));return e}(e),t,i,s)}function S(t,e,i,s){return C(t,e,i,s)}function w(t,e,i,s){return V(F(e),t,i,s)}function g(t,e,i,s){return V(function(t,e){for(var i,s,r,n=[],o=0;o<t.length&&!((e-=2)<0);++o)i=t.charCodeAt(o),s=i>>8,r=i%256,n.push(r),n.push(s);return n}(e,t.length-i),t,i,s)}function _(t,e,i){return 0===e&&i===t.length?s.fromByteArray(t):s.fromByteArray(t.slice(e,i))}function M(t,e,i){i=Math.min(t.length,i);for(var s=[],r=e;r<i;){var n,o,a,h,c=t[r],u=null,p=c>239?4:c>223?3:c>191?2:1;if(r+p<=i)switch(p){case 1:c<128&&(u=c);break;case 2:128==(192&(n=t[r+1]))&&(h=(31&c)<<6|63&n)>127&&(u=h);break;case 3:n=t[r+1],o=t[r+2],128==(192&n)&&128==(192&o)&&(h=(15&c)<<12|(63&n)<<6|63&o)>2047&&(h<55296||h>57343)&&(u=h);break;case 4:n=t[r+1],o=t[r+2],a=t[r+3],128==(192&n)&&128==(192&o)&&128==(192&a)&&(h=(15&c)<<18|(63&n)<<12|(63&o)<<6|63&a)>65535&&h<1114112&&(u=h)}null===u?(u=65533,p=1):u>65535&&(u-=65536,s.push(u>>>10&1023|55296),u=56320|1023&u),s.push(u),r+=p}return function(t){var e=t.length;if(e<=4096)return String.fromCharCode.apply(String,t);var i="",s=0;for(;s<e;)i+=String.fromCharCode.apply(String,t.slice(s,s+=4096));return i}(s)}e.Buffer=h,e.SlowBuffer=function(t){+t!=t&&(t=0);return h.alloc(+t)},e.INSPECT_MAX_BYTES=50,h.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(t){return!1}}(),e.kMaxLength=o(),h.poolSize=8192,h._augment=function(t){return t.__proto__=h.prototype,t},h.from=function(t,e,i){return c(null,t,e,i)},h.TYPED_ARRAY_SUPPORT&&(h.prototype.__proto__=Uint8Array.prototype,h.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&h[Symbol.species]===h&&Object.defineProperty(h,Symbol.species,{value:null,configurable:!0})),h.alloc=function(t,e,i){return function(t,e,i,s){return u(e),e<=0?a(t,e):void 0!==i?"string"==typeof s?a(t,e).fill(i,s):a(t,e).fill(i):a(t,e)}(null,t,e,i)},h.allocUnsafe=function(t){return p(null,t)},h.allocUnsafeSlow=function(t){return p(null,t)},h.isBuffer=function(t){return!(null==t||!t._isBuffer)},h.compare=function(t,e){if(!h.isBuffer(t)||!h.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var i=t.length,s=e.length,r=0,n=Math.min(i,s);r<n;++r)if(t[r]!==e[r]){i=t[r],s=e[r];break}return i<s?-1:s<i?1:0},h.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},h.concat=function(t,e){if(!n(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return h.alloc(0);var i;if(void 0===e)for(e=0,i=0;i<t.length;++i)e+=t[i].length;var s=h.allocUnsafe(e),r=0;for(i=0;i<t.length;++i){var o=t[i];if(!h.isBuffer(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(s,r),r+=o.length}return s},h.byteLength=f,h.prototype._isBuffer=!0,h.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)A(this,e,e+1);return this},h.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)A(this,e,e+3),A(this,e+1,e+2);return this},h.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)A(this,e,e+7),A(this,e+1,e+6),A(this,e+2,e+5),A(this,e+3,e+4);return this},h.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?M(this,0,t):m.apply(this,arguments)},h.prototype.equals=function(t){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===h.compare(this,t)},h.prototype.inspect=function(){var t="",i=e.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,i).match(/.{2}/g).join(" "),this.length>i&&(t+=" ... ")),"<Buffer "+t+">"},h.prototype.compare=function(t,e,i,s,r){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===i&&(i=t?t.length:0),void 0===s&&(s=0),void 0===r&&(r=this.length),e<0||i>t.length||s<0||r>this.length)throw new RangeError("out of range index");if(s>=r&&e>=i)return 0;if(s>=r)return-1;if(e>=i)return 1;if(this===t)return 0;for(var n=(r>>>=0)-(s>>>=0),o=(i>>>=0)-(e>>>=0),a=Math.min(n,o),c=this.slice(s,r),u=t.slice(e,i),p=0;p<a;++p)if(c[p]!==u[p]){n=c[p],o=u[p];break}return n<o?-1:o<n?1:0},h.prototype.includes=function(t,e,i){return-1!==this.indexOf(t,e,i)},h.prototype.indexOf=function(t,e,i){return y(this,t,e,i,!0)},h.prototype.lastIndexOf=function(t,e,i){return y(this,t,e,i,!1)},h.prototype.write=function(t,e,i,s){if(void 0===e)s="utf8",i=this.length,e=0;else if(void 0===i&&"string"==typeof e)s=e,i=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(i)?(i|=0,void 0===s&&(s="utf8")):(s=i,i=void 0)}var r=this.length-e;if((void 0===i||i>r)&&(i=r),t.length>0&&(i<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");s||(s="utf8");for(var n=!1;;)switch(s){case"hex":return R(this,t,e,i);case"utf8":case"utf-8":return v(this,t,e,i);case"ascii":return C(this,t,e,i);case"latin1":case"binary":return S(this,t,e,i);case"base64":return w(this,t,e,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return g(this,t,e,i);default:if(n)throw new TypeError("Unknown encoding: "+s);s=(""+s).toLowerCase(),n=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function I(t,e,i){var s="";i=Math.min(t.length,i);for(var r=e;r<i;++r)s+=String.fromCharCode(127&t[r]);return s}function E(t,e,i){var s="";i=Math.min(t.length,i);for(var r=e;r<i;++r)s+=String.fromCharCode(t[r]);return s}function O(t,e,i){var s=t.length;(!e||e<0)&&(e=0),(!i||i<0||i>s)&&(i=s);for(var r="",n=e;n<i;++n)r+=x(t[n]);return r}function T(t,e,i){for(var s=t.slice(e,i),r="",n=0;n<s.length;n+=2)r+=String.fromCharCode(s[n]+256*s[n+1]);return r}function P(t,e,i){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>i)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,i,s,r,n){if(!h.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>r||e<n)throw new RangeError('"value" argument is out of bounds');if(i+s>t.length)throw new RangeError("Index out of range")}function D(t,e,i,s){e<0&&(e=65535+e+1);for(var r=0,n=Math.min(t.length-i,2);r<n;++r)t[i+r]=(e&255<<8*(s?r:1-r))>>>8*(s?r:1-r)}function N(t,e,i,s){e<0&&(e=4294967295+e+1);for(var r=0,n=Math.min(t.length-i,4);r<n;++r)t[i+r]=e>>>8*(s?r:3-r)&255}function k(t,e,i,s,r,n){if(i+s>t.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("Index out of range")}function L(t,e,i,s,n){return n||k(t,0,i,4),r.write(t,e,i,s,23,4),i+4}function G(t,e,i,s,n){return n||k(t,0,i,8),r.write(t,e,i,s,52,8),i+8}h.prototype.slice=function(t,e){var i,s=this.length;if((t=~~t)<0?(t+=s)<0&&(t=0):t>s&&(t=s),(e=void 0===e?s:~~e)<0?(e+=s)<0&&(e=0):e>s&&(e=s),e<t&&(e=t),h.TYPED_ARRAY_SUPPORT)(i=this.subarray(t,e)).__proto__=h.prototype;else{var r=e-t;i=new h(r,void 0);for(var n=0;n<r;++n)i[n]=this[n+t]}return i},h.prototype.readUIntLE=function(t,e,i){t|=0,e|=0,i||P(t,e,this.length);for(var s=this[t],r=1,n=0;++n<e&&(r*=256);)s+=this[t+n]*r;return s},h.prototype.readUIntBE=function(t,e,i){t|=0,e|=0,i||P(t,e,this.length);for(var s=this[t+--e],r=1;e>0&&(r*=256);)s+=this[t+--e]*r;return s},h.prototype.readUInt8=function(t,e){return e||P(t,1,this.length),this[t]},h.prototype.readUInt16LE=function(t,e){return e||P(t,2,this.length),this[t]|this[t+1]<<8},h.prototype.readUInt16BE=function(t,e){return e||P(t,2,this.length),this[t]<<8|this[t+1]},h.prototype.readUInt32LE=function(t,e){return e||P(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},h.prototype.readUInt32BE=function(t,e){return e||P(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},h.prototype.readIntLE=function(t,e,i){t|=0,e|=0,i||P(t,e,this.length);for(var s=this[t],r=1,n=0;++n<e&&(r*=256);)s+=this[t+n]*r;return s>=(r*=128)&&(s-=Math.pow(2,8*e)),s},h.prototype.readIntBE=function(t,e,i){t|=0,e|=0,i||P(t,e,this.length);for(var s=e,r=1,n=this[t+--s];s>0&&(r*=256);)n+=this[t+--s]*r;return n>=(r*=128)&&(n-=Math.pow(2,8*e)),n},h.prototype.readInt8=function(t,e){return e||P(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},h.prototype.readInt16LE=function(t,e){e||P(t,2,this.length);var i=this[t]|this[t+1]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt16BE=function(t,e){e||P(t,2,this.length);var i=this[t+1]|this[t]<<8;return 32768&i?4294901760|i:i},h.prototype.readInt32LE=function(t,e){return e||P(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},h.prototype.readInt32BE=function(t,e){return e||P(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},h.prototype.readFloatLE=function(t,e){return e||P(t,4,this.length),r.read(this,t,!0,23,4)},h.prototype.readFloatBE=function(t,e){return e||P(t,4,this.length),r.read(this,t,!1,23,4)},h.prototype.readDoubleLE=function(t,e){return e||P(t,8,this.length),r.read(this,t,!0,52,8)},h.prototype.readDoubleBE=function(t,e){return e||P(t,8,this.length),r.read(this,t,!1,52,8)},h.prototype.writeUIntLE=function(t,e,i,s){(t=+t,e|=0,i|=0,s)||B(this,t,e,i,Math.pow(2,8*i)-1,0);var r=1,n=0;for(this[e]=255&t;++n<i&&(r*=256);)this[e+n]=t/r&255;return e+i},h.prototype.writeUIntBE=function(t,e,i,s){(t=+t,e|=0,i|=0,s)||B(this,t,e,i,Math.pow(2,8*i)-1,0);var r=i-1,n=1;for(this[e+r]=255&t;--r>=0&&(n*=256);)this[e+r]=t/n&255;return e+i},h.prototype.writeUInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,255,0),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},h.prototype.writeUInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):D(this,t,e,!0),e+2},h.prototype.writeUInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):D(this,t,e,!1),e+2},h.prototype.writeUInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):N(this,t,e,!0),e+4},h.prototype.writeUInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):N(this,t,e,!1),e+4},h.prototype.writeIntLE=function(t,e,i,s){if(t=+t,e|=0,!s){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var n=0,o=1,a=0;for(this[e]=255&t;++n<i&&(o*=256);)t<0&&0===a&&0!==this[e+n-1]&&(a=1),this[e+n]=(t/o>>0)-a&255;return e+i},h.prototype.writeIntBE=function(t,e,i,s){if(t=+t,e|=0,!s){var r=Math.pow(2,8*i-1);B(this,t,e,i,r-1,-r)}var n=i-1,o=1,a=0;for(this[e+n]=255&t;--n>=0&&(o*=256);)t<0&&0===a&&0!==this[e+n+1]&&(a=1),this[e+n]=(t/o>>0)-a&255;return e+i},h.prototype.writeInt8=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,1,127,-128),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},h.prototype.writeInt16LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):D(this,t,e,!0),e+2},h.prototype.writeInt16BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):D(this,t,e,!1),e+2},h.prototype.writeInt32LE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):N(this,t,e,!0),e+4},h.prototype.writeInt32BE=function(t,e,i){return t=+t,e|=0,i||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):N(this,t,e,!1),e+4},h.prototype.writeFloatLE=function(t,e,i){return L(this,t,e,!0,i)},h.prototype.writeFloatBE=function(t,e,i){return L(this,t,e,!1,i)},h.prototype.writeDoubleLE=function(t,e,i){return G(this,t,e,!0,i)},h.prototype.writeDoubleBE=function(t,e,i){return G(this,t,e,!1,i)},h.prototype.copy=function(t,e,i,s){if(i||(i=0),s||0===s||(s=this.length),e>=t.length&&(e=t.length),e||(e=0),s>0&&s<i&&(s=i),s===i)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("sourceStart out of bounds");if(s<0)throw new RangeError("sourceEnd out of bounds");s>this.length&&(s=this.length),t.length-e<s-i&&(s=t.length-e+i);var r,n=s-i;if(this===t&&i<e&&e<s)for(r=n-1;r>=0;--r)t[r+e]=this[r+i];else if(n<1e3||!h.TYPED_ARRAY_SUPPORT)for(r=0;r<n;++r)t[r+e]=this[r+i];else Uint8Array.prototype.set.call(t,this.subarray(i,i+n),e);return n},h.prototype.fill=function(t,e,i,s){if("string"==typeof t){if("string"==typeof e?(s=e,e=0,i=this.length):"string"==typeof i&&(s=i,i=this.length),1===t.length){var r=t.charCodeAt(0);r<256&&(t=r)}if(void 0!==s&&"string"!=typeof s)throw new TypeError("encoding must be a string");if("string"==typeof s&&!h.isEncoding(s))throw new TypeError("Unknown encoding: "+s)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<i)throw new RangeError("Out of range index");if(i<=e)return this;var n;if(e>>>=0,i=void 0===i?this.length:i>>>0,t||(t=0),"number"==typeof t)for(n=e;n<i;++n)this[n]=t;else{var o=h.isBuffer(t)?t:H(new h(t,s).toString()),a=o.length;for(n=0;n<i-e;++n)this[n+e]=o[n%a]}return this};var U=/[^+\/0-9A-Za-z-_]/g;function x(t){return t<16?"0"+t.toString(16):t.toString(16)}function H(t,e){var i;e=e||1/0;for(var s=t.length,r=null,n=[],o=0;o<s;++o){if((i=t.charCodeAt(o))>55295&&i<57344){if(!r){if(i>56319){(e-=3)>-1&&n.push(239,191,189);continue}if(o+1===s){(e-=3)>-1&&n.push(239,191,189);continue}r=i;continue}if(i<56320){(e-=3)>-1&&n.push(239,191,189),r=i;continue}i=65536+(r-55296<<10|i-56320)}else r&&(e-=3)>-1&&n.push(239,191,189);if(r=null,i<128){if((e-=1)<0)break;n.push(i)}else if(i<2048){if((e-=2)<0)break;n.push(i>>6|192,63&i|128)}else if(i<65536){if((e-=3)<0)break;n.push(i>>12|224,i>>6&63|128,63&i|128)}else{if(!(i<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;n.push(i>>18|240,i>>12&63|128,i>>6&63|128,63&i|128)}}return n}function F(t){return s.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(U,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function V(t,e,i,s){for(var r=0;r<s&&!(r+i>=e.length||r>=t.length);++r)e[r+i]=t[r];return r}}).call(this,i(5))},function(t,e,i){"use strict";e.byteLength=function(t){var e=c(t),i=e[0],s=e[1];return 3*(i+s)/4-s},e.toByteArray=function(t){var e,i,s=c(t),o=s[0],a=s[1],h=new n(function(t,e,i){return 3*(e+i)/4-i}(0,o,a)),u=0,p=a>0?o-4:o;for(i=0;i<p;i+=4)e=r[t.charCodeAt(i)]<<18|r[t.charCodeAt(i+1)]<<12|r[t.charCodeAt(i+2)]<<6|r[t.charCodeAt(i+3)],h[u++]=e>>16&255,h[u++]=e>>8&255,h[u++]=255&e;2===a&&(e=r[t.charCodeAt(i)]<<2|r[t.charCodeAt(i+1)]>>4,h[u++]=255&e);1===a&&(e=r[t.charCodeAt(i)]<<10|r[t.charCodeAt(i+1)]<<4|r[t.charCodeAt(i+2)]>>2,h[u++]=e>>8&255,h[u++]=255&e);return h},e.fromByteArray=function(t){for(var e,i=t.length,r=i%3,n=[],o=0,a=i-r;o<a;o+=16383)n.push(u(t,o,o+16383>a?a:o+16383));1===r?(e=t[i-1],n.push(s[e>>2]+s[e<<4&63]+"==")):2===r&&(e=(t[i-2]<<8)+t[i-1],n.push(s[e>>10]+s[e>>4&63]+s[e<<2&63]+"="));return n.join("")};for(var s=[],r=[],n="undefined"!=typeof Uint8Array?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,h=o.length;a<h;++a)s[a]=o[a],r[o.charCodeAt(a)]=a;function c(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var i=t.indexOf("=");return-1===i&&(i=e),[i,i===e?0:4-i%4]}function u(t,e,i){for(var r,n,o=[],a=e;a<i;a+=3)r=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(255&t[a+2]),o.push(s[(n=r)>>18&63]+s[n>>12&63]+s[n>>6&63]+s[63&n]);return o.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},function(t,e){
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
e.read=function(t,e,i,s,r){var n,o,a=8*r-s-1,h=(1<<a)-1,c=h>>1,u=-7,p=i?r-1:0,d=i?-1:1,l=t[e+p];for(p+=d,n=l&(1<<-u)-1,l>>=-u,u+=a;u>0;n=256*n+t[e+p],p+=d,u-=8);for(o=n&(1<<-u)-1,n>>=-u,u+=s;u>0;o=256*o+t[e+p],p+=d,u-=8);if(0===n)n=1-c;else{if(n===h)return o?NaN:1/0*(l?-1:1);o+=Math.pow(2,s),n-=c}return(l?-1:1)*o*Math.pow(2,n-s)},e.write=function(t,e,i,s,r,n){var o,a,h,c=8*n-r-1,u=(1<<c)-1,p=u>>1,d=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,l=s?0:n-1,f=s?1:-1,m=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,o=u):(o=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-o))<1&&(o--,h*=2),(e+=o+p>=1?d/h:d*Math.pow(2,1-p))*h>=2&&(o++,h/=2),o+p>=u?(a=0,o=u):o+p>=1?(a=(e*h-1)*Math.pow(2,r),o+=p):(a=e*Math.pow(2,p-1)*Math.pow(2,r),o=0));r>=8;t[i+l]=255&a,l+=f,a/=256,r-=8);for(o=o<<r|a,c+=r;c>0;t[i+l]=255&o,l+=f,o/=256,c-=8);t[i+l-f]|=128*m}},function(t,e){var i={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==i.call(t)}},function(t,e,s){"use strict";s.r(e);var r,n=s(1),o=s.n(n),a=function(t,e){return t.audio.masterVolume=Math.pow(2,e)-1},h={gba:void 0,clearGbaInstance:function(){},setFpsCallback:function(){},canvasRef:void 0,play:function(){},saveState:function(){},frozenAddresses:{},addFreezeAddress:function(){},removeFreezeAddress:function(){}},c=o.a.createContext(h);!function(t){t.error="error",t.warn="warn",t.stub="stub",t.info="info"}(r||(r={}));var u=function(t,e,i){return function(s,n){s===r.error&&t.pause(),!1!==e[s]&&void 0!==e[s]&&i(s,n)}},p=function(t){var e=t.onFpsReported,i=t.volume,s=void 0===i?0:i,r=t.watchLogLevels,h=void 0===r?{error:!0}:r,p=t.onLogReceived,d=void 0===p?function(){}:p,l=t.scale,f=void 0===l?1:l,m=Object(n.useContext)(c),A=m.gba,y=m.clearGbaInstance,b=m.setFpsCallback,R=m.canvasRef;return Object(n.useEffect)((function(){b(e)}),[e,b]),Object(n.useEffect)((function(){null==A||A.setLogger(u(A,h,d))}),[A,JSON.stringify(h),d]),Object(n.useEffect)((function(){return function(){return y()}}),[]),Object(n.useEffect)((function(){void 0!==A&&a(A,s)}),[A,s]),o.a.createElement("div",{style:{width:240*f,height:160*f}},o.a.createElement("canvas",{ref:R,width:240,height:160,style:{transform:"scale(".concat(f,")"),transformOrigin:"left top"}}))},d=s(2),l=s.n(d),f=s(3),m=s.n(f),A=s(0),y=s.n(A),b=function(t,e,i){var s=document.getElementById(t),r=document.getElementById(e);if(s){var n=function t(){i?s.parentElement.removeChild(s):(s.setAttribute("class","dead"),s.removeEventListener("webkitTransitionEnd",t),s.removeEventListener("oTransitionEnd",t),s.removeEventListener("transitionend",t)),r&&(r.setAttribute("class","hidden"),setTimeout((function(){return r.removeAttribute("class")}),0))};s.addEventListener("webkitTransitionEnd",n,!1),s.addEventListener("oTransitionEnd",n,!1),s.addEventListener("transitionend",n,!1),s.setAttribute("class","hidden")}},R=s(4),v=s.n(R);var C={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([C.pack(t.size||t.length||t.byteLength),t],{type:C.TYPE})},serialize:function(t){var e=[],s=4;for(i in t)if(t.hasOwnProperty(i)){var r,n,o=C.prefix(i);switch(v()(t[i])){case"number":r=C.TAG_INT,n=C.pack(t[i]);break;case"string":r=C.TAG_STRING,n=C.prefix(t[i]);break;case"object":t[i].type==C.TYPE?(r=C.TAG_BLOB,n=t[i]):(r=C.TAG_STRUCT,n=C.serialize(t[i]));break;case"boolean":r=C.TAG_BOOLEAN,n=C.pack8(t[i]);break;default:console.log(t[i])}s+=1+o.size+(n.size||n.byteLength||n.length),e.push(C.pack8(r)),e.push(o),e.push(n)}return e.unshift(C.pack(s)),new Blob(e)},deserialize:function(t,e){var i=new FileReader;i.onload=function(t){e(C.deserealizeStream(new DataView(t.target.result),new C.pointer))},i.readAsArrayBuffer(t)},deserealizeStream:function(t,e){e.push();for(var i={},s=t.getUint32(e.advance(4),!0);e.mark()<s;){var r,n=t.getUint8(e.advance(1)),o=e.readString(t);switch(n){case C.TAG_INT:r=t.getUint32(e.advance(4),!0);break;case C.TAG_STRING:r=e.readString(t);break;case C.TAG_STRUCT:r=C.deserealizeStream(t,e);break;case C.TAG_BLOB:var a=t.getUint32(e.advance(4),!0);r=t.buffer.slice(e.advance(a),e.advance(0));break;case C.TAG_BOOLEAN:r=!!t.getUint8(e.advance(1))}i[o]=r}if(e.mark()>s)throw"Size of serialized data exceeded";return e.pop(),i},serializePNG:function(t,e,i){for(var s=document.createElement("canvas"),r=s.getContext("2d"),n=e.getContext("2d").getImageData(0,0,e.width,e.height),o=0,a=0;a<e.height;++a)for(var h=0;h<e.width;++h)n.data[4*(h+a*e.width)+3]||++o;for(var c=3*o+(e.width*e.height-o),u=1;c*u*u<t.size;++u);var p=c*u*u-t.size,d=Math.ceil(p/(e.width*u));s.setAttribute("width",e.width*u),s.setAttribute("height",e.height*u+d);var l=new FileReader;return l.onload=function(t){for(var o=new Uint8Array(t.target.result),a=0,h=0,c=r.createImageData(s.width,s.height+d),p=0;p<s.height;++p)for(var l=0;l<s.width;++l){var f=p/u|0,m=l/u|0;if(f>e.height||!n.data[4*(m+f*e.width)+3])c.data[h++]=o[a++],c.data[h++]=o[a++],c.data[h++]=o[a++],c.data[h++]=0;else{var A=o[a++];c.data[h++]=n.data[4*(m+f*e.width)+0]|7&A,c.data[h++]=n.data[4*(m+f*e.width)+1]|A>>3&7,c.data[h++]=n.data[4*(m+f*e.width)+2]|A>>6&7,c.data[h++]=n.data[4*(m+f*e.width)+3]}}r.putImageData(c,0,0),i(s.toDataURL("image/png"))},l.readAsArrayBuffer(t),s},deserializePNG:function(t,e){var i=new FileReader;i.onload=function(t){var i=document.createElement("img");i.setAttribute("src",t.target.result);var s=document.createElement("canvas");s.setAttribute("height",i.height),s.setAttribute("width",i.width);var r=s.getContext("2d");r.drawImage(i,0,0);for(var n=r.getImageData(0,0,s.width,s.height),o=(t=[],0);o<s.height;++o)for(var a=0;a<s.width;++a)if(n.data[4*(a+o*s.width)+3]){var h=0;h|=7&n.data[4*(a+o*s.width)+0],h|=(7&n.data[4*(a+o*s.width)+1])<<3,h|=(7&n.data[4*(a+o*s.width)+2])<<6,t.push(h)}else t.push(n.data[4*(a+o*s.width)+0]),t.push(n.data[4*(a+o*s.width)+1]),t.push(n.data[4*(a+o*s.width)+2]);newBlob=new Blob(t.map((function(t){var e=new Uint8Array(1);return e[0]=t,e})),{type:C.TYPE}),C.deserialize(newBlob,e)},i.readAsDataURL(t)}};C.pointer.prototype.advance=function(t){var e=this.index;return this.index+=t,e},C.pointer.prototype.mark=function(){return this.index-this.top},C.pointer.prototype.push=function(){this.stack.push(this.top),this.top=this.index},C.pointer.prototype.pop=function(){this.top=this.stack.pop()},C.pointer.prototype.readString=function(t){for(var e=t.getUint32(this.advance(4),!0),i=[],s=0;s<e;++s)i.push(String.fromCharCode(t.getUint8(this.advance(1))));return i.join("")};s(14),s(15),s(16);function S(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 w(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 g(t,e){this.cpu=e,this.mmu=t}window.MemoryView=function(t,e){this.buffer=t,this.view=new DataView(this.buffer,"number"==typeof e?e:0),this.mask=t.byteLength-1,this.resetMask()},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))},window.MemoryBlock=function(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)},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)},S.prototype=Object.create(MemoryView.prototype),S.prototype.store8=function(t,e){},S.prototype.store16=function(t,e){t<202&&t>=196&&(this.gpio||(this.gpio=this.mmu.allocGPIO(this)),this.gpio.store16(t,e))},S.prototype.store32=function(t,e){t<202&&t>=196&&(this.gpio||(this.gpio=this.mmu.allocGPIO(this)),this.gpio.store32(t,e))},w.prototype=Object.create(MemoryView.prototype),w.prototype.load8=function(t){return t>=this.buffer.byteLength?-1:this.view.getInt8(t)},w.prototype.load16=function(t){return t>=this.buffer.byteLength?-1:this.view.getInt16(t,!0)},w.prototype.loadU8=function(t){return t>=this.buffer.byteLength?-1:this.view.getUint8(t)},w.prototype.loadU16=function(t){return t>=this.buffer.byteLength?-1:this.view.getUint16(t,!0)},w.prototype.load32=function(t){return t>=this.buffer.byteLength?-1:this.view.getInt32(t,!0)},w.prototype.store8=function(t,e){},w.prototype.store16=function(t,e){},w.prototype.store32=function(t,e){},g.prototype.load8=function(t){return this.mmu.load8(this.cpu.gprs[this.cpu.PC]-this.cpu.instructionWidth+(3&t))},g.prototype.load16=function(t){return this.mmu.load16(this.cpu.gprs[this.cpu.PC]-this.cpu.instructionWidth+(2&t))},g.prototype.loadU8=function(t){return this.mmu.loadU8(this.cpu.gprs[this.cpu.PC]-this.cpu.instructionWidth+(3&t))},g.prototype.loadU16=function(t){return this.mmu.loadU16(this.cpu.gprs[this.cpu.PC]-this.cpu.instructionWidth+(2&t))},g.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},g.prototype.store8=function(t,e){},g.prototype.store16=function(t,e){},g.prototype.store32=function(t,e){},g.prototype.invalidatePage=function(t){},window.GameBoyAdvanceMMU=function(){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},GameBoyAdvanceMMU.prototype.mmap=function(t,e){this.memory[t]=e},GameBoyAdvanceMMU.prototype.clear=function(){this.badMemory=new g(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:l()(new Uint16Array(y()(this.memory[this.REGION_WORKING_RAM].buffer))),iram:l()(new Uint16Array(y()(this.memory[this.REGION_WORKING_IRAM].buffer)))}},GameBoyAdvanceMMU.prototype.defrost=function(t){this.memory[this.REGION_WORKING_RAM].replaceData(new Uint16Array(t.ram).buffer),this.memory[this.REGION_WORKING_IRAM].replaceData(new Uint16Array(t.iram).buffer)},GameBoyAdvanceMMU.prototype.loadBios=function(t,e){this.bios=new w(t),this.bios.real=!!e},GameBoyAdvanceMMU.prototype.loadRom=function(t,e){var i={title:null,code:null,maker:null,memory:t,saveType:null},s=new S(t);if(150!=s.view.getUint8(178))return null;if(s.mmu=this,this.memory[this.REGION_CART0]=s,this.memory[this.REGION_CART1]=s,this.memory[this.REGION_CART2]=s,t.byteLength>16777216){var r=new S(t,16777216);this.memory[this.REGION_CART0+1]=r,this.memory[this.REGION_CART1+1]=r,this.memory[this.REGION_CART2+1]=r}if(e){for(var n="",o=0;o<12;++o){if(!(c=s.loadU8(o+160)))break;n+=String.fromCharCode(c)}i.title=n;var a="";for(o=0;o<4;++o){if(!(c=s.loadU8(o+172)))break;a+=String.fromCharCode(c)}i.code=a;var h="";for(o=0;o<2;++o){var c;if(!(c=s.loadU8(o+176)))break;h+=String.fromCharCode(c)}i.maker=h;var u,p="",d=!1;for(o=228;o<t.byteLength&&!d;++o)switch(p+=u=String.fromCharCode(s.loadU8(o))){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":d=!0;break;default:p=u}if(d)switch(i.saveType=p,p){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,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,s=this.memory[t>>>this.BASE_OFFSET];s.store8(i,e),s.invalidatePage(i)},GameBoyAdvanceMMU.prototype.store16=function(t,e){var i=16777214&t,s=this.memory[t>>>this.BASE_OFFSET];s.store16(i,e),s.invalidatePage(i)},GameBoyAdvanceMMU.prototype.store32=function(t,e){var i=16777212&t,s=this.memory[t>>>this.BASE_OFFSET];s.store32(i,e),s.invalidatePage(i),s.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],s=i.icache[e];return s&&!s.invalid||(s={thumb:new Array(1<<i.ICACHE_PAGE_BITS),arm:new Array(1<<i.ICACHE_PAGE_BITS-1),invalid:!1},i.icache[e]=s),s},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,s=e.width,r=this.DMA_OFFSET[e.srcControl]*s,n=this.DMA_OFFSET[e.dstControl]*s,o=e.nextCount,a=e.nextSource&this.OFFSET_MASK,h=e.nextDest&this.OFFSET_MASK,c=e.nextSource>>>this.BASE_OFFSET,u=e.nextDest>>>this.BASE_OFFSET,p=this.memory[c],d=this.memory[u],l=null,f=null,m=4294967295,A=4294967295;if(d.ICACHE_PAGE_BITS)for(var y=h+o*s>>d.ICACHE_PAGE_BITS,b=h>>d.ICACHE_PAGE_BITS;b<=y;++b)d.invalidatePage(b<<d.ICACHE_PAGE_BITS);if(u!=this.REGION_WORKING_RAM&&u!=this.REGION_WORKING_IRAM||(f=d.view,A=d.mask),c!=this.REGION_WORKING_RAM&&c!=this.REGION_WORKING_IRAM&&c!=this.REGION_CART0&&c!=this.REGION_CART1||(l=p.view,m=p.mask),p&&d)if(l&&f)if(4==s)for(a&=4294967292,h&=4294967292;o--;)i=l.getInt32(a&m),f.setInt32(h&A,i),a+=r,h+=n;else for(;o--;)i=l.getUint16(a&m),f.setUint16(h&A,i),a+=r,h+=n;else if(l)if(4==s)for(a&=4294967292,h&=4294967292;o--;)i=l.getInt32(a&m,!0),d.store32(h,i),a+=r,h+=n;else for(;o--;)i=l.getUint16(a&m,!0),d.store16(h,i),a+=r,h+=n;else if(4==s)for(a&=4294967292,h&=4294967292;o--;)i=p.load32(a),d.store32(h,i),a+=r,h+=n;else for(;o--;)i=p.loadU16(a),d.store16(h,i),a+=r,h+=n;else this.core.WARN("Invalid DMA");if(e.doIrq&&(e.nextIRQ=this.cpu.cycles+2,e.nextIRQ+=4==s?this.waitstates32[c]+this.waitstates32[u]:this.waitstates[c]+this.waitstates[u],e.nextIRQ+=(e.count-1)*(4==s?this.waitstatesSeq32[c]+this.waitstatesSeq32[u]:this.waitstatesSeq[c]+this.waitstatesSeq[u])),e.nextSource=a|c<<this.BASE_OFFSET,e.nextDest=h|u<<this.BASE_OFFSET,e.nextCount=o,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,s=(16&t)>>4,r=(96&t)>>5,n=(128&t)>>7,o=(768&t)>>8,a=(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[r],this.waitstates[this.REGION_CART2]=this.waitstates[this.REGION_CART2+1]=this.ROM_WS[o],this.waitstatesSeq[this.REGION_CART0]=this.waitstatesSeq[this.REGION_CART0+1]=this.ROM_WS_SEQ[0][s],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][a],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)},window.GameBoyAdvanceIO=function(){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},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:l()(y()(this.registers)),cpuExecMode:this.cpu.execMode}},GameBoyAdvanceIO.prototype.defrost=function(t){this.registers=new Uint16Array(t.registers),this.cpu.switchExecMode(t.cpuExecMode)},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))};s(17),s(18),s(19);var _=function(t){if(null===t)return!0;var e=v()(t);return"number"===e||"string"===e||"boolean"===e||"undefined"===e},M=function(t){return Object.keys(t).reduce((function(e,i){var s=t[i];return _(s)&&(e[i]=s),e}),{})},I=function(t,e){Object.keys(e).forEach((function(i){t[i]=e[i]}))};function E(t){this.buffer=new Uint16Array(t>>1)}function O(t){this.bg=!0,this.priority=-1,this.index=t.LAYER_BACKDROP,this.enabled=!0,this.drawScanline=function(e,i,s,r){for(var n=s;n<r;++n)e.stencil[n]&t.WRITTEN_MASK?e.stencil[n]&t.TARGET1_MASK&&(e.color[n]=t.palette.mix(t.blendB,t.palette.accessColor(this.index,0),t.blendA,e.color[n]),e.stencil[n]=t.WRITTEN_MASK):(e.color[n]=t.palette.accessColor(this.index,0),e.stencil[n]=t.WRITTEN_MASK)}}function T(t){E.call(this,t),this.vram=this.buffer}function P(t){E.call(this,t),this.oam=this.buffer,this.objs=new Array(128);for(var e=0;e<128;++e)this.objs[e]=new D(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 B(){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 D(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 N(t,e){this.video=t,this.bg=!1,this.index=t.LAYER_OBJ,this.priority=e,this.enabled=!1,this.objwin=0}E.prototype.load8=function(t){return this.loadU8(t)<<24>>24},E.prototype.load16=function(t){return this.loadU16(t)<<16>>16},E.prototype.loadU8=function(t){var e=t>>1;return 1&t?(65280&this.buffer[e])>>>8:255&this.buffer[e]},E.prototype.loadU16=function(t){return this.buffer[t>>1]},E.prototype.load32=function(t){return this.buffer[t>>1&-2]|this.buffer[t>>1|1]<<16},E.prototype.store8=function(t,e){this.store16(t,e<<8|e)},E.prototype.store16=function(t,e){this.buffer[t>>1]=e},E.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)},E.prototype.insert=function(t,e){this.buffer.set(e,t)},E.prototype.invalidatePage=function(t){},T.prototype=Object.create(E.prototype),T.prototype.freeze=function(){return{buffer:l()(new Uint16Array(y()(this.buffer)))}},T.prototype.defrost=function(t){this.buffer=this.vram=new Uint16Array(t.buffer)},P.prototype=Object.create(E.prototype),P.prototype.freeze=function(){return{buffer:l()(new Uint16Array(y()(this.buffer))),objs:y()(this.objs).map((function(t){return t.oam=void 0,t})),scalerot:y()(this.scalerot)}},P.prototype.defrost=function(t){var e=this;this.buffer=this.oam=new Uint16Array(t.buffer).buffer,this.objs=t.objs.map((function(t,i){var s=new D(e,i);return s.x=t.x,s.y=t.y,s.scalerot=t.scalerot,s.doublesize=t.doublesize,s.disable=t.disable,s.mode=t.mode,s.mosaic=t.mosaic,s.multipalette=t.multipalette,s.shape=t.shape,s.scalerotParam=t.scalerotParam,s.hflip=t.hflip,s.vflip=t.vflip,s.tileBase=t.tileBase,s.priority=t.priority,s.palette=t.palette,s.cachedWidth=t.cachedWidth,s.cachedHeight=t.cachedHeight,s})),this.scalerot=t.scalerot},P.prototype.overwrite=function(t){for(var e=0;e<this.buffer.byteLength>>1;++e)this.store16(e<<1,t[e])},P.prototype.store16=function(t,e){var i=(1016&t)>>3,s=this.objs[i],r=this.scalerot[i>>2];s.priority,s.disable,s.y;switch(6&t){case 0:s.y=255&e;var n=s.scalerot;s.scalerot=256&e,s.scalerot?(s.scalerotOam=this.scalerot[s.scalerotParam],s.doublesize=!!(512&e),s.disable=0,s.hflip=0,s.vflip=0):(s.doublesize=!1,s.disable=512&e,n&&(s.hflip=8&s.scalerotParam,s.vflip=16&s.scalerotParam)),s.mode=(3072&e)>>6,s.mosaic=4096&e,s.multipalette=8192&e,s.shape=(49152&e)>>14,s.recalcSize();break;case 2:s.x=511&e,s.scalerot?(s.scalerotParam=(15872&e)>>9,s.scalerotOam=this.scalerot[s.scalerotParam],s.hflip=0,s.vflip=0,s.drawScanline=s.drawScanlineAffine):(s.hflip=4096&e,s.vflip=8192&e,s.drawScanline=s.drawScanlineNormal),s.size=(49152&e)>>14,s.recalcSize();break;case 4:s.tileBase=1023&e,s.priority=(3072&e)>>10,s.palette=(61440&e)>>8;break;case 6:switch(3&i){case 0:r.a=(e<<16)/16777216;break;case 1:r.b=(e<<16)/16777216;break;case 2:r.c=(e<<16)/16777216;break;case 3:r.d=(e<<16)/16777216}}E.prototype.store16.call(this,t,e)},B.prototype.freeze=function(){return{colors:y()(this.colors),adjustedColors:y()(this.adjustedColors),passthroughColors:y()(this.passthroughColors),blendY:y()(this.blendY)}},B.prototype.defrost=function(t){this.colors=t.colors,this.adjustedColors=t.adjustedColors,this.passthroughColors=t.passthroughColors,this.blendY=t.blendY},B.prototype.overwrite=function(t){for(var e=0;e<512;++e)this.store16(e<<1,t[e])},B.prototype.loadU8=function(t){return this.loadU16(t)>>8*(1&t)&255},B.prototype.loadU16=function(t){return this.colors[(512&t)>>9][(511&t)>>1]},B.prototype.load16=function(t){return this.loadU16(t)<<16>>16},B.prototype.load32=function(t){return this.loadU16(t)|this.loadU16(t+2)<<16},B.prototype.store16=function(t,e){var i=(512&t)>>9,s=(511&t)>>1;this.colors[i][s]=e,this.adjustedColors[i][s]=this.adjustColor(e)},B.prototype.store32=function(t,e){this.store16(t,65535&e),this.store16(t+2,e>>16)},B.prototype.invalidatePage=function(t){},B.prototype.convert16To32=function(t,e){var i=(31&t)<<3,s=(992&t)>>2,r=(31744&t)>>7;e[0]=i,e[1]=s,e[2]=r},B.prototype.mix=function(t,e,i,s){var r=31&e,n=(992&e)>>5,o=(31744&e)>>10,a=31&s,h=(992&s)>>5,c=(31744&s)>>10;return Math.min(t*r+i*a,31)|Math.min(t*n+i*h,31)<<5|Math.min(t*o+i*c,31)<<10},B.prototype.makeDarkPalettes=function(t){this.adjustColor!=this.adjustColorDark&&(this.adjustColor=this.adjustColorDark,this.resetPalettes()),this.resetPaletteLayers(t)},B.prototype.makeBrightPalettes=function(t){this.adjustColor!=this.adjustColorBright&&(this.adjustColor=this.adjustColorBright,this.resetPalettes()),this.resetPaletteLayers(t)},B.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]},B.prototype.makeSpecialPalette=function(t){this.passthroughColors[t]=this.adjustedColors[4==t?1:0]},B.prototype.makeNormalPalette=function(t){this.passthroughColors[t]=this.colors[4==t?1:0]},B.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]},B.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])},B.prototype.accessColor=function(t,e){return this.passthroughColors[t][e]},B.prototype.adjustColorDark=function(t){var e=31&t,i=(992&t)>>5,s=(31744&t)>>10;return(e-=e*this.blendY)|(i-=i*this.blendY)<<5|(s-=s*this.blendY)<<10},B.prototype.adjustColorBright=function(t){var e=31&t,i=(992&t)>>5,s=(31744&t)>>10;return(e+=(31-e)*this.blendY)|(i+=(31-i)*this.blendY)<<5|(s+=(31-s)*this.blendY)<<10},B.prototype.adjustColor=B.prototype.adjustColorBright,B.prototype.setBlendY=function(t){this.blendY!=t&&(this.blendY=t,this.resetPalettes())},D.prototype.drawScanlineNormal=function(t,e,i,s,r){var n,o,a,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,p,d=this.cachedWidth;this.x<h.HORIZONTAL_PIXELS?(this.x<s?(o=s-this.x,a=s):(o=0,a=this.x),r<this.cachedWidth+this.x&&(d=r-this.x)):(o=s+512-this.x,a=s,r<this.cachedWidth-o&&(d=r));var l,f,m=7&(p=this.vflip?this.cachedHeight-e+i-1:e-i),A=this.multipalette?1:0;f=h.objCharacterMapping?(504&p)*this.cachedWidth>>6:(504&p)<<2-A,this.mosaic&&(a+=l=h.objMosaicX-1-(h.objMosaicX+a-1)%h.objMosaicX,o+=l),u=this.hflip?this.cachedWidth-o-1:o;var y=h.accessTile(this.TILE_OFFSET+(4&n)*A,this.tileBase+(f<<A)+((504&u)>>3-A),m<<A);for(n=o;n<d;++n)l=this.mosaic?a%h.objMosaicX:0,u=this.hflip?this.cachedWidth-(n-l)-1:n-l,A?3&n&&(!this.mosaic||l)||(y=h.accessTile(this.TILE_OFFSET+(4&u),this.tileBase+(f<<1)+((504&u)>>2),m<<1)):7&n&&(!this.mosaic||l)||(y=h.accessTile(this.TILE_OFFSET,this.tileBase+f+(u>>3),m)),this.pushPixel(h.LAYER_OBJ,this,h,y,7&u,a,t,c,!1),a++},D.prototype.drawScanlineAffine=function(t,e,i,s,r){var n,o,a,h,c,u=this.oam.video,p=this.mode|u.target2[u.LAYER_OBJ]|this.priority<<1;16==this.mode&&(p|=u.TARGET1_MASK),1==u.blendMode&&u.alphaEnabled&&(p|=u.target1[u.LAYER_OBJ]);var d,l=e-i,f=this.multipalette?1:0,m=this.cachedWidth<<this.doublesize,A=this.cachedHeight<<this.doublesize,y=m;for(y>u.HORIZONTAL_PIXELS&&(m=u.HORIZONTAL_PIXELS),this.x<u.HORIZONTAL_PIXELS?(this.x<s?(o=s-this.x,a=s):(o=0,a=this.x),r<y+this.x&&(y=r-this.x)):(a=s,r<y-(o=s+512-this.x)&&(y=r)),n=o;n<y;++n)if(h=this.scalerotOam.a*(n-(m>>1))+this.scalerotOam.b*(l-(A>>1))+(this.cachedWidth>>1),c=this.scalerotOam.c*(n-(m>>1))+this.scalerotOam.d*(l-(A>>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)a++;else{d=u.objCharacterMapping?(504&c)*this.cachedWidth>>6:(504&c)<<2-f;var b=u.accessTile(this.TILE_OFFSET+(4&h)*f,this.tileBase+(d<<f)+((504&h)>>3-f),(7&c)<<f);this.pushPixel(u.LAYER_OBJ,this,u,b,7&h,a,t,p,!1),a++}},D.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}}},N.prototype.drawScanline=function(t,e,i,s){var r,n,o,a=this.video.vcount;if(!(i>=s))for(var h=this.video.oam.objs,c=0;c<h.length;++c){var u;if(!(o=h[c]).disable)if((o.mode&this.video.OBJWIN_MASK)==this.objwin)if(o.mode&this.video.OBJWIN_MASK||this.priority==o.priority)r=o.y<this.video.VERTICAL_PIXELS?o.y:o.y-256,u=o.scalerot?o.cachedHeight<<o.doublesize:o.cachedHeight,n=o.mosaic?a-a%this.video.objMosaicY:a,r<=a&&r+u>a&&o.drawScanline(t,n,r,i,s)}},N.prototype.objComparator=function(t,e){return t.index-e.index},window.GameBoyAdvanceSoftwareRenderer=function(){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=O.bind(this)},GameBoyAdvanceSoftwareRenderer.prototype.clear=function(t){this.palette=new B,this.vram=new T(t.SIZE_VRAM),this.oam=new P(t.SIZE_OAM),this.oam.video=this,this.objLayers=[new N(this,0),new N(this,1),new N(this,2),new N(this,3)],this.objwinLayer=new N(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],this.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.freezeBg=function(){return this.bg.map((function(t){return M(t)}))},GameBoyAdvanceSoftwareRenderer.prototype.defrostBg=function(t){var e=this;this.bg.forEach((function(i,s){I(i,t[s]),i.video=e,i.vram=e.vram,i.pushPixel=GameBoyAdvanceSoftwareRenderer.pushPixel,i.drawScanline=e.drawScanlineBGMode0}))},GameBoyAdvanceSoftwareRenderer.prototype.freezeObjLayers=function(){return{objLayers:this.objLayers.map((function(t){return M(t)})),objwinLayer:M(this.objwinLayer)}},GameBoyAdvanceSoftwareRenderer.prototype.defrostObjLayers=function(t){this.objLayers.forEach((function(e,i){I(e,t.objLayers[i])})),I(this.objwinLayer,t.objwinLayer)},GameBoyAdvanceSoftwareRenderer.prototype.freezeDrawBackdrop=function(){return M(this.drawBackdrop)},GameBoyAdvanceSoftwareRenderer.prototype.defrostDrawBackdrop=function(t){this.drawBackdrop=O.bind(this),I(this.drawBackdrop,t)},GameBoyAdvanceSoftwareRenderer.prototype.freeze=function(t){return{primitives:M(this),palette:this.palette.freeze(),vram:this.vram.freeze(),oam:this.oam.freeze(),windows:y()(this.windows),target1:y()(this.target1),target2:y()(this.target2),scanline:{color:l()(this.scanline.color),stencil:l()(this.scanline.stencil)},sharedColor:y()(this.sharedColor),sharedMap:y()(this.sharedMap),bg:this.freezeBg(),objLayers:this.freezeObjLayers(),drawBackdrop:this.freezeDrawBackdrop()}},GameBoyAdvanceSoftwareRenderer.prototype.defrost=function(t){I(this,t.primitives),this.palette.defrost(t.palette),this.vram.defrost(t.vram),this.oam.defrost(t.oam),this.windows=t.windows,this.target1=t.target1,this.target2=t.target2,this.scanline={color:new Uint16Array(t.scanline.color),stencil:new Uint16Array(t.scanline.stencil)},this.sharedColor=t.sharedColor,this.sharedMap=t.sharedMap,this.defrostBg(t.bg),this.defrostObjLayers(t.objLayers),this.defrostDrawBackdrop(t.drawBackdrop),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],this.resetLayers()},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,this.backgroundMode>0&&(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,this.blendA>1&&(this.blendA=1),this.blendB=((7936&t)>>8)/16,this.blendB>1&&(this.blendB=1)},GameBoyAdvanceSoftwareRenderer.prototype.writeBlendY=function(t){this.blendY=t,this.palette.setBlendY(t>=16?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(){this.backgroundMode>1&&(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,s,r){var n=t+(i>>2&62)+s;1&e&&(n+=(256&i)<<3);var o=this.vram.loadU16(n);r.tile=1023&o,r.hflip=1024&o,r.vflip=2048&o,r.palette=(61440&o)>>8},GameBoyAdvanceSoftwareRenderer.prototype.accessMapMode1=function(t,e,i,s,r){var n=t+(i>>3)+s;r.tile=this.vram.loadU8(n)},GameBoyAdvanceSoftwareRenderer.prototype.accessTile=function(t,e,i){var s=t+(e<<5);return s|=i<<2,this.vram.load32(s)},GameBoyAdvanceSoftwareRenderer.pushPixel=function(t,e,i,s,r,n,o,a,h){var c;if(!h){if(!(c=this.multipalette?s>>(r<<3)&255:s>>(r<<2)&15))return;this.multipalette||(c|=e.palette)}var u=i.WRITTEN_MASK,p=o.stencil[n],d=i.blendMode;if(i.objwinActive)if(p&i.OBJWIN_MASK){if(!i.windows[3].enabled[t])return;i.setBlendEnabled(t,i.windows[3].special&&i.target1[t],d),i.windows[3].special&&i.alphaEnabled&&(a|=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],d),i.windows[2].special&&i.alphaEnabled&&(a|=i.target1[t])}a&i.TARGET1_MASK&&p&i.TARGET2_MASK&&i.setBlendEnabled(t,!0,1);var l=h?s:i.palette.accessColor(t,c);a&i.TARGET1_MASK&&i.setBlendEnabled(t,!!d,d);var f=(a&i.PRIORITY_MASK)<(p&i.PRIORITY_MASK);if((a&i.PRIORITY_MASK)==(p&i.PRIORITY_MASK)&&(f=a&i.BACKGROUND_MASK),p&i.WRITTEN_MASK)if(f)a&i.TARGET1_MASK&&p&i.TARGET2_MASK&&(l=i.palette.mix(i.blendA,l,i.blendB,o.color[n])),u|=a&~i.TARGET1_MASK;else{if(!((a&i.PRIORITY_MASK)>(p&i.PRIORITY_MASK)))return;if(u=p&~(i.TARGET1_MASK|i.TARGET2_MASK),!(a&i.TARGET2_MASK&&p&i.TARGET1_MASK))return;l=i.palette.mix(i.blendB,l,i.blendA,o.color[n])}else u|=a;a&i.OBJWIN_MASK?o.stencil[n]|=i.OBJWIN_MASK:(o.color[n]=l,o.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,s){var r,n,o,a=this.video,h=a.vcount,c=i,u=e.x,p=h+e.y;this.mosaic&&(p-=h%a.bgMosaicY);var d,l=7&p,f=e.screenBase,m=e.charBase,A=e.size,y=e.index,b=a.sharedMap,R=e.multipalette?1:0,v=a.target2[y]|e.priority<<1|a.BACKGROUND_MASK;1==a.blendMode&&a.alphaEnabled&&(v|=a.target1[y]);var C,S=p<<3&1984;2==A?S+=p<<3&2048:3==A&&(S+=p<<4&4096),C=1&A?511:255,a.accessMapMode0(f,A,i+u&C,S,b);var w=a.accessTile(m,b.tile<<R,(b.vflip?7-l:l)<<R);for(r=i;r<s;++r){if(n=r+u&C,o=7&(n-=d=this.mosaic?c%a.bgMosaicX:0),R){if((!o||this.mosaic&&!d)&&a.accessMapMode0(f,A,n,S,b),(!(3&o)||this.mosaic&&!d)&&!((w=a.accessTile(m+(!!(4&n)==!b.hflip?4:0),b.tile<<1,(b.vflip?7-l:l)<<1))||3&o)){r+=3,c+=4;continue}}else if((!o||this.mosaic&&!d)&&(a.accessMapMode0(f,A,n,S,b),!(w=a.accessTile(m,b.tile,b.vflip?7-l:l))&&!o)){r+=7,c+=8;continue}b.hflip&&(o=7-o),e.pushPixel(y,b,a,w,o,c,t,v,!1),c++}},GameBoyAdvanceSoftwareRenderer.prototype.drawScanlineBGMode2=function(t,e,i,s){var r,n,o,a,h,c=this.video,u=c.vcount,p=i,d=e.screenBase,l=e.charBase,f=e.size,m=128<<f,A=e.index,y=c.sharedMap,b=c.target2[A]|e.priority<<1|c.BACKGROUND_MASK;for(1==c.blendMode&&c.alphaEnabled&&(b|=c.target1[A]),r=i;r<s;++r){if(n=e.dx*r+e.sx,o=e.dy*r+e.sy,this.mosaic&&(n-=r%c.bgMosaicX*e.dx+u%c.bgMosaicY*e.dmx,o-=r%c.bgMosaicX*e.dy+u%c.bgMosaicY*e.dmy),e.overflow)(n&=m-1)<0&&(n+=m),(o&=m-1)<0&&(o+=m);else if(n<0||o<0||n>=m||o>=m){p++;continue}h=(o<<1&2032)<<f,c.accessMapMode1(d,f,n,h,y),a=this.vram.loadU8(l+(y.tile<<6)+((7&o)<<3)+(7&n)),e.pushPixel(A,y,c,a,0,p,t,b,!1),p++}},GameBoyAdvanceSoftwareRenderer.prototype.drawScanlineBGMode3=function(t,e,i,s){var r,n,o,a,h=this.video,c=h.vcount,u=i,p=e.index,d=h.sharedMap,l=h.target2[p]|e.priority<<1|h.BACKGROUND_MASK;for(1==h.blendMode&&h.alphaEnabled&&(l|=h.target1[p]),r=i;r<s;++r)n=e.dx*r+e.sx,o=e.dy*r+e.sy,this.mosaic&&(n-=r%h.bgMosaicX*e.dx+c%h.bgMosaicY*e.dmx,o-=r%h.bgMosaicX*e.dy+c%h.bgMosaicY*e.dmy),n<0||o<0||n>=h.HORIZONTAL_PIXELS||o>=h.VERTICAL_PIXELS||(a=this.vram.loadU16(o*h.HORIZONTAL_PIXELS+n<<1),e.pushPixel(p,d,h,a,0,u,t,l,!0)),u++},GameBoyAdvanceSoftwareRenderer.prototype.drawScanlineBGMode4=function(t,e,i,s){var r,n,o,a=this.video,h=a.vcount,c=i,u=0;a.displayFrameSelect&&(u+=40960);e.size;var p,d=e.index,l=a.sharedMap,f=a.target2[d]|e.priority<<1|a.BACKGROUND_MASK;for(1==a.blendMode&&a.alphaEnabled&&(f|=a.target1[d]),r=i;r<s;++r)n=e.dx*r+e.sx,o=0|e.dy*r+e.sy,this.mosaic&&(n-=r%a.bgMosaicX*e.dx+h%a.bgMosaicY*e.dmx,o-=r%a.bgMosaicX*e.dy+h%a.bgMosaicY*e.dmy),o<<2&2016,n<0||o<0||n>=a.HORIZONTAL_PIXELS||o>=a.VERTICAL_PIXELS||(p=this.vram.loadU8(u+o*a.HORIZONTAL_PIXELS+n),e.pushPixel(d,l,a,p,0,c,t,f,!1)),c++},GameBoyAdvanceSoftwareRenderer.prototype.drawScanlineBGMode5=function(t,e,i,s){var r,n,o,a=this.video,h=a.vcount,c=i,u=0;a.displayFrameSelect&&(u+=40960);var p,d=e.index,l=a.sharedMap,f=a.target2[d]|e.priority<<1|a.BACKGROUND_MASK;for(1==a.blendMode&&a.alphaEnabled&&(f|=a.target1[d]),r=i;r<s;++r)n=e.dx*r+e.sx,o=e.dy*r+e.sy,this.mosaic&&(n-=r%a.bgMosaicX*e.dx+h%a.bgMosaicY*e.dmx,o-=r%a.bgMosaicX*e.dy+h%a.bgMosaicY*e.dmy),n<0||o<0||n>=160||o>=128||(p=this.vram.loadU16(u+(160*o+n)<<1),e.pushPixel(d,l,a,p,0,c,t,f,!0)),c++},GameBoyAdvanceSoftwareRenderer.prototype.drawScanline=function(t){var e=this.scanline;if(this.forcedBlank)this.drawScanlineBlank(e);else{var i,s,r,n,o;this.prepareScanline(e),this.vcount=t;for(var a=0;a<this.drawLayers.length;++a)(i=this.drawLayers[a]).enabled&&(this.objwinActive=!1,this.win0||this.win1||this.objwin?(s=0,r=this.HORIZONTAL_PIXELS,n=0,o=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)),s=Math.max(s,this.win0Left),r=Math.min(r,this.win0Left),n=Math.max(n,this.win0Right),o=Math.min(o,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<s||this.win1Right<n)?(i.drawScanline(e,i,this.win1Left,s),i.drawScanline(e,i,o,this.win1Right)):i.drawScanline(e,i,this.win1Left,this.win1Right)),s=Math.max(s,this.win1Left),r=Math.min(r,this.win1Left),n=Math.max(n,this.win1Right),o=Math.min(o,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),r>n?i.drawScanline(e,i,0,this.HORIZONTAL_PIXELS):(r&&i.drawScanline(e,i,0,r),n<this.HORIZONTAL_PIXELS&&i.drawScanline(e,i,n,this.HORIZONTAL_PIXELS),o<s&&i.drawScanline(e,i,o,s))),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),s=this.vcount*this.HORIZONTAL_PIXELS*4,r=this.target2[this.LAYER_BACKDROP],n=0;n<this.HORIZONTAL_PIXELS;++n)t.stencil[n]&this.WRITTEN_MASK?(e=t.color[n],r&&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[s++]=this.sharedColor[0],this.pixelData.data[s++]=this.sharedColor[1],this.pixelData.data[s++]=this.sharedColor[2],s++},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)};s(20),s(21),s(22);function k(t){MemoryView.call(this,new ArrayBuffer(t),0),this.writePending=!1}function L(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),t>65536?(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}k.prototype=Object.create(MemoryView.prototype),k.prototype.store8=function(t,e){this.view.setInt8(t,e),this.writePending=!0},k.prototype.store16=function(t,e){this.view.setInt16(t,e,!0),this.writePending=!0},k.prototype.store32=function(t,e){this.view.setInt32(t,e,!0),this.writePending=!0},L.prototype=Object.create(MemoryView.prototype),L.prototype.load8=function(t){return this.idMode&&t<2?this.id>>(t<<3)&255:t<65536?this.bank.getInt8(t):0},L.prototype.load16=function(t){return 255&this.load8(t)|this.load8(t+1)<<8},L.prototype.load32=function(t){return 255&this.load8(t)|this.load8(t+1)<<8|this.load8(t+2)<<16|this.load8(t+3)<<24},L.prototype.loadU8=function(t){return 255&this.load8(t)},L.prototype.loadU16=function(t){return 255&this.loadU8(t)|this.loadU8(t+1)<<8},L.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}},L.prototype.store16=function(t,e){throw new Error("Unaligned save to flash!")},L.prototype.store32=function(t,e){throw new Error("Unaligned save to flash!")},L.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),t.byteLength>65536?this.bank1=new DataView(this.buffer,65536):this.bank1=null,this.bank=e?this.bank1:this.bank0},window.EEPROMSavedata=function(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},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(--this.commandBitsRemaining>64)this.writeAddress<<=1,this.writeAddress|=(1&e)<<6;else if(this.commandBitsRemaining<=0)this.command=this.COMMAND_NULL,this.writePending=!0;else{var s=this.view.getUint8(this.writeAddress>>3);s&=~(1<<7-(7&this.writeAddress)),s|=(1&e)<<7-(7&this.writeAddress),this.view.setUint8(this.writeAddress>>3,s),++this.writeAddress}break;case this.COMMAND_READ_PENDING:--this.commandBitsRemaining>0?(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)};s(23);function G(){this.SYS_ID="com.endrift.gbajs",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.frozenAddresses={},this.cpu.mmu=this.mmu,this.cpu.irq=this.irq,this.mmu.cpu=this.cpu,this.mmu.core=this,this.irq.cpu=this.cpu,this.irq.io=this.io,this.irq.audio=this.audio,this.irq.video=this.video,this.irq.core=this,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,this.audio.cpu=this.cpu,this.audio.core=this,this.video.cpu=this.cpu,this.video.core=this,this.keypad.core=this,this.sio.core=this,this.keypad.registerHandlers(),this.doStep=this.waitFrame,this.paused=!1,this.seenFrame=!1,this.seenSave=!1,this.lastVblank=0,this.reportFPS=null;var t=this;window.URL=window.URL||window.webkitURL,this.video.vblankCallback=function(){t.seenFrame=!0}}window.GameBoyAdvance=G,G.prototype.addFreezeAddress=function(t){var e=t.address,i=t.size,s=t.value;this.frozenAddresses[e]={size:i,value:s}},G.prototype.removeFreezeAddress=function(t){delete this.frozenAddresses[t]},G.prototype.requestFrame=function(t){this.requestFrameTimeoutId=setTimeout(t,16)},G.prototype.setCanvas=function(t){this.context=t.getContext("2d"),this.video.setBacking(this.context)},G.prototype.setBios=function(t,e){this.mmu.loadBios(t,e)},G.prototype.setRom=function(t){return this.reset(),this.rom=this.mmu.loadRom(t,!0),!!this.rom&&(this.retrieveSavedata(),!0)},G.prototype.hasRom=function(){return!!this.rom},G.prototype.loadRomFromFile=function(t,e){this.setRom(t.buffer),e&&e(t.buffer)},G.prototype.reset=function(){this.requestFrameTimeoutId&&(window.clearTimeout(this.requestFrameTimeoutId),delete this.requestFrameTimeoutId),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)},G.prototype.step=function(){for(var t=this.mmu.memory[this.mmu.REGION_WORKING_IRAM];this.doStep();)for(var e in this.cpu.step(),this.frozenAddresses){var i=this.frozenAddresses[e],s=i.size,r=i.value;switch(s){case 8:t.store8(e,r);break;case 16:t.store16(e,r);break;case 16:t.store32(e,r)}}},G.prototype.waitFrame=function(){var t=this.seenFrame;return this.seenFrame=!1,!t},G.prototype.pause=function(){this.paused=!0,this.audio.pause(!0)},G.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())},G.prototype.runStable=function(){var t=this,e=0,i=0,s=Date.now();function r(){t.reportFPS?function(){try{if(e+=Date.now()-s,t.paused)return;t.requestFrame(r),s=Date.now(),t.advanceFrame(),60==++i&&(t.reportFPS(1e3*i/e),i=0,e=0)}catch(e){throw t.ERROR(e),e.stack&&t.logStackTrace(e.stack.split("\n")),e}}():function(){try{if(t.paused)return;t.requestFrame(r),t.advanceFrame()}catch(e){throw t.ERROR(e),e.stack&&t.logStackTrace(e.stack.split("\n")),e}}()}this.paused=!1,this.audio.pause(!1),t.requestFrame(r)},G.prototype.setSavedata=function(t){this.mmu.loadSavedata(t)},G.prototype.loadSavedataFromFile=function(t){var e=new FileReader,i=this;e.onload=function(t){i.setSavedata(t.target.result)},e.readAsArrayBuffer(t)},G.prototype.decodeSavedata=function(t){this.setSavedata(this.decodeBase64(t))},G.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),s=new Uint8Array(i),r=t.match(/..../g),n=0;n+2<e;n+=3){var o=atob(r.shift());s[n]=o.charCodeAt(0),s[n+1]=o.charCodeAt(1),s[n+2]=o.charCodeAt(2)}if(n<e){o=atob(r.shift());s[n++]=o.charCodeAt(0),o.length>1&&(s[n++]=o.charCodeAt(1))}return i},G.prototype.encodeBase64=function(t){for(var e,i,s=[],r=[],n=0;n<t.byteLength;++n)for(e=t.getUint8(n,!0),r.push(String.fromCharCode(e));r.length>=3;)i=r.splice(0,3),s.push(btoa(i.join("")));return r.length&&s.push(btoa(r.join(""))),s.join("")},G.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")}},G.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)}},G.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},G.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()}},G.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)},G.prototype.log=function(t,e){},G.prototype.setLogger=function(t){this.log=t},G.prototype.logStackTrace=function(t){var e=t.length-32;e>0&&this.log(-1,"> (Too many frames)");for(var i=Math.max(e,0);i<t.length;++i)this.log(-1,"> "+t[i])},G.prototype.ERROR=function(t){this.log(r.error,t)},G.prototype.WARN=function(t){this.log(r.warn,t)},G.prototype.STUB=function(t){this.log(r.stub,t)},G.prototype.INFO=function(t){this.log(r.info,t)},G.prototype.ASSERT_UNREACHED=function(t){throw new Error("Should be unreached: "+t)},G.prototype.ASSERT=function(t,e){if(!t)throw new Error("Assertion failed: "+e)};var U=s(6),x=s.n(U),H=function(t,e){var i,s,r=[];try{(i=new GameBoyAdvance).keypad.eatInput=!0,i.setLogger(u(i,{error:!0},(function(){})))}catch(t){i=null}return i.setCanvas(e),i.setBios(x.a),s=t,i.loadRomFromFile(s,(function(t){if(t){for(var e=0;e<r.length;++e)r[e]();r=[],b("preload","ingame"),b("instructions",null,!0),i.runStable()}else setTimeout((function(){load.onclick=function(){document.getElementById("loader").click()}}),3e3)})),i},F=function(t){var e=t.children,i=Object(n.useState)(),s=m()(i,2),r=s[0],a=s[1],h=Object(n.useRef)(null),u=Object(n.useState)(),p=m()(u,2),d=p[0],f=p[1],A=Object(n.useState)(),b=m()(A,2),R=b[0],v=b[1],C=Object(n.useState)({}),S=m()(C,2),w=S[0],g=S[1],_=function(){return g(y()(r.frozenAddresses))};return o.a.createElement(c.Provider,{value:{gba:r,clearGbaInstance:function(){return a(void 0)},canvasRef:h,setFpsCallback:function(t){f(t),r&&(r.reportFPS=t)},play:function(t){var e=t.newRomBuffer,i=t.restoreState;if(void 0===e&&void 0===R)return console.error("Error: There is no ROM buffer to can play the emulator"),!1;var s=void 0===r?H(e,h.current):r;if(s.reportFPS=d,a(s),void 0!==e){var n=new Uint8Array(l()(e));v(n),s.setRom(n.buffer)}else s.setRom(R.buffer);return void 0!==i&&s.defrost(y()(i)),s.runStable(),!0},saveState:function(){return r.freeze()},frozenAddresses:w,addFreezeAddress:r&&function(t){r.addFreezeAddress(t),_()},removeFreezeAddress:r&&function(t){r.removeFreezeAddress(t),_()}}},e)};s.d(e,"LogLevel",(function(){return r})),s.d(e,"GbaContext",(function(){return c})),s.d(e,"GbaProvider",(function(){return F}));e.default=p}]);
//# sourceMappingURL=react-gbajs.js.map