1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-22 14:33:51 +00:00
8bitworkshop/lib/stellerator/stellerator.min.js
2021-09-15 14:41:25 -05:00

32 lines
311 KiB
JavaScript

!function(){"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function e(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function s(t,e,s){return t(s={path:e,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&s.path)}},s.exports),s.exports}var i=s((function(t,e){Object.defineProperty(e,"__esModule",{value:!0});var s=[];function i(t){return s[t]||(s[t]=function(t){for(var e="return function dispatcher"+t+"(payload) {\n",s=[],i=[],r=0;r<t;r++)s.push("cb"+r),i.push("ctx"+r),e+=" cb"+r+"(payload, ctx"+r+");\n";return e+="};",new(Function.bind.apply(Function,[void 0].concat(s.concat(i),[e])))}(t)),s[t]}s[0]=function(){return function(){}},s[1]=function(t,e){return void 0===e?t:function(s){t(s,e)}};var r=function(){function t(){this.hasHandlers=!1,this._handlers=[],this._contexts=[],this._createDispatcher()}return t.prototype.addHandler=function(t,e){return this.isHandlerAttached(t,e)||(this._handlers.push(t),this._contexts.push(e),this._createDispatcher(),this._updateHasHandlers()),this},t.prototype.removeHandler=function(t,e){var s=this._getHandlerIndex(t,e);return void 0!==s&&(this._handlers.splice(s,1),this._contexts.splice(s,1),this._createDispatcher(),this._updateHasHandlers()),this},t.prototype.isHandlerAttached=function(t,e){return void 0!==this._getHandlerIndex(t,e)},t.prototype._updateHasHandlers=function(){this.hasHandlers=!!this._handlers.length},t.prototype._getHandlerIndex=function(t,e){var s,i=this._handlers.length;for(s=0;s<i&&(this._handlers[s]!==t||this._contexts[s]!==e);s++);return s<i?s:void 0},t.prototype._createDispatcher=function(){this.dispatch=i(this._handlers.length).apply(this,this._handlers.concat(this._contexts))},t}();e.default=r}));e(i);var r=s((function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.Event=i.default}));e(r);var n=r.Event,a=s((function(t,e){Object.defineProperty(e,"__esModule",{value:!0});var s="resolve_transaction",i="reject_transaction",n="error",a=function(){function t(t,e){void 0===e&&(e=0),this._dispatch=t,this._rpcTimeout=e,this.error=new r.Event,this._rpcHandlers={},this._signalHandlers={},this._pendingTransactions={},this._nextTransactionId=0}return t.prototype.dispatch=function(e){var s=e;switch(s.type){case t.MessageType.signal:return this._handleSignal(s);case t.MessageType.rpc:return this._handeRpc(s);case t.MessageType.internal:return this._handleInternal(s);default:this._raiseError("invalid message type "+s.type)}},t.prototype.rpc=function(e,s,i){var r=this,n=this._nextTransactionId++;return this._dispatch({type:t.MessageType.rpc,transactionId:n,id:e,payload:s},i||void 0),new Promise((function(t,e){var s=r._pendingTransactions[n]={id:n,resolve:t,reject:e};r._rpcTimeout>0&&(r._pendingTransactions[n].timeoutHandle=setTimeout((function(){return r._transactionTimeout(s)}),r._rpcTimeout))}))},t.prototype.signal=function(e,s,i){return this._dispatch({type:t.MessageType.signal,id:e,payload:s},i||void 0),this},t.prototype.registerRpcHandler=function(t,e){if(this._rpcHandlers[t])throw new Error("rpc handler for "+t+" already registered");return this._rpcHandlers[t]=e,this},t.prototype.registerSignalHandler=function(t,e){return this._signalHandlers[t]||(this._signalHandlers[t]=[]),this._signalHandlers[t].push(e),this},t.prototype.deregisterRpcHandler=function(t,e){return this._rpcHandlers[t]&&delete this._rpcHandlers[t],this},t.prototype.deregisterSignalHandler=function(t,e){return this._signalHandlers[t]&&(this._signalHandlers[t]=this._signalHandlers[t].filter((function(t){return e!==t}))),this},t.prototype._raiseError=function(e){this.error.dispatch(new Error(e)),this._dispatch({type:t.MessageType.internal,id:n,payload:e})},t.prototype._handleSignal=function(t){if(!this._signalHandlers[t.id])return this._raiseError("invalid signal "+t.id);this._signalHandlers[t.id].forEach((function(e){return e(t.payload)}))},t.prototype._handeRpc=function(e){var r=this;if(!this._rpcHandlers[e.id])return this._raiseError("invalid rpc "+e.id);Promise.resolve(this._rpcHandlers[e.id](e.payload)).then((function(i){return r._dispatch({type:t.MessageType.internal,id:s,transactionId:e.transactionId,payload:i})}),(function(s){return r._dispatch({type:t.MessageType.internal,id:i,transactionId:e.transactionId,payload:s})}))},t.prototype._handleInternal=function(t){var e=void 0!==t.transactionId?this._pendingTransactions[t.transactionId]:void 0;switch(t.id){case s:if(!e||void 0===t.transactionId)return this._raiseError("no pending transaction with id "+t.transactionId);e.resolve(t.payload),this._clearTransaction(this._pendingTransactions[t.transactionId]);break;case i:if(!e||void 0===t.transactionId)return this._raiseError("no pending transaction with id "+t.transactionId);this._pendingTransactions[t.transactionId].reject(t.payload),this._clearTransaction(this._pendingTransactions[t.transactionId]);break;case n:this.error.dispatch(new Error("remote error: "+t.payload));break;default:this._raiseError("unhandled internal message "+t.id)}},t.prototype._transactionTimeout=function(t){t.reject("transaction timed out"),this._raiseError("transaction "+t.id+" timed out"),delete this._pendingTransactions[t.id]},t.prototype._clearTransaction=function(t){void 0!==t.timeoutHandle&&clearTimeout(t.timeoutHandle),delete this._pendingTransactions[t.id]},t}();!function(t){!function(t){t[t.signal=0]="signal",t[t.rpc=1]="rpc",t[t.internal=2]="internal"}(t.MessageType||(t.MessageType={}))}(a||(a={})),e.default=a}));e(a);var h=s((function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.RpcProvider=a.default}));e(h);var o=h.RpcProvider;let c=null,u=null,l=null;
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function _(t,e,s,i){var r,n=arguments.length,a=n<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,s,i);else for(var h=t.length-1;h>=0;h--)(r=t[h])&&(a=(n<3?r(a):n>3?r(e,s,a):r(e,s))||a);return n>3&&a&&Object.defineProperty(e,s,a),a}function d(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}function f(t,e,s,i){return new(s||(s=Promise))((function(r,n){function a(t){try{o(i.next(t))}catch(t){n(t)}}function h(t){try{o(i.throw(t))}catch(t){n(t)}}function o(t){var e;t.done?r(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(a,h)}o((i=i.apply(t,e||[])).next())}))}function p(t,e){var s,i,r,n,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return n={next:h(0),throw:h(1),return:h(2)},"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function h(n){return function(h){return function(n){if(s)throw new TypeError("Generator is already executing.");for(;a;)try{if(s=1,i&&(r=2&n[0]?i.return:n[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,n[1])).done)return r;switch(i=0,r&&(n=[2&n[0],r.value]),n[0]){case 0:case 1:r=n;break;case 4:return a.label++,{value:n[1],done:!1};case 5:a.label++,i=n[1],n=[0];continue;case 7:n=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==n[0]&&2!==n[0])){a=0;continue}if(3===n[0]&&(!r||n[1]>r[0]&&n[1]<r[3])){a.label=n[1];break}if(6===n[0]&&a.label<r[1]){a.label=r[1],r=n;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(n);break}r[2]&&a.ops.pop(),a.trys.pop();continue}n=e.call(t,a)}catch(t){n=[6,t],i=0}finally{s=r=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,h])}}}var g,b,A;c=new o((function(t,e){u?u.postMessage(t,e):postMessage(t,e),l&&(u=l,u.onmessage=t=>c.dispatch(t.data)),l=null})),c.error.addHandler(t=>{console.log(t?t.message:"unknown rpc error")}),onmessage=t=>u||c.dispatch(t.data),c.registerRpcHandler("/use-port",t=>u||l?Promise.reject("RPC already switched to message port"):(l=t,Promise.resolve())),function(t){let e;!function(t){t.stopped="stopped",t.running="running",t.paused="paused",t.error="error"}(e=t.State||(t.State={}))}(g||(g={}));class m{constructor(t,e,s){this._value=t,this._releaseCB=e,this._disposeCB=s,this._isAvailable=!1,this._isDisposed=!1}adopt(t){this._value=t}get(){return this._value}release(){this._releaseCB(this)}dispose(){this._disposeCB(this)}}class k{constructor(t){this._factory=t,this.event={release:new n,dispose:new n},this._pool=[],this._poolSize=0}get(){let t;if(0===this._poolSize){const e=this._factory();t=new m(e,t=>this._releaseMember(t),t=>this._disposeMember(t))}else t=this._pool[--this._poolSize],t._isAvailable=!1;return t}_releaseMember(t){if(t._isAvailable)throw new Error("Trying to release an already released pool member");if(t._isDisposed)throw new Error("Trying to release an already disposed pool member");const e=this._poolSize++;this._pool[e]=t,t._isAvailable=!0,t._poolPosition=e,this.event.release.dispatch(t.get())}_disposeMember(t){if(t._isDisposed)throw new Error("Trying to dispose of an already disposed pool member");t._isAvailable&&(this._poolSize>1&&(this._pool[t._poolPosition]=this._pool[this._poolSize-1]),this._poolSize--),t._isDisposed=!0,this.event.dispose.dispatch(t.get())}}class y{constructor(){this._height=0,this._width=0,this._buffer=null}static createFromArrayBuffer(t,e,s){return(new y).replaceUnderlyingBuffer(t,e,s)}replaceUnderlyingBuffer(t,e,s){if(t*e*4!==s.byteLength)throw new Error("surface size mismatch");return this._width=t,this._height=e,this._underlyingBuffer=s,this._buffer=new Uint32Array(this._underlyingBuffer),this}getUnderlyingBuffer(){return this._underlyingBuffer}resetUnderlyingBuffer(){return this._width=this._height=0,this._underlyingBuffer=this._buffer=null,this}getWidth(){return this._width}getHeight(){return this._height}getBuffer(){return this._buffer}getByteOrder(){return 0}fill(t){for(let e=0;e<this._buffer.length;e++)this._buffer[e]=t;return this}}class w{constructor(t){this._video=t,this.newFrame=new n,this._poolMembers=new WeakMap,this._surfaces=new WeakMap,this._pool=new k(()=>new ImageData(this._video.getWidth(),this._video.getHeight())),this._video.setSurfaceFactory(()=>{const t=this._pool.get(),e=t.get();if(!this._surfaces.has(e)){const t=y.createFromArrayBuffer(e.width,e.height,e.data.buffer);this._surfaces.set(e,t.fill(4278190080))}const s=this._surfaces.get(e);return this._poolMembers.set(s,t),s}),this._video.newFrame.addHandler(t=>this.newFrame.dispatch(this._poolMembers.get(t)))}getWidth(){return this._video.getWidth()}getHeight(){return this._video.getHeight()}}class v{constructor(t,e,s){this._value=t,this._mapper=e,this._adopter=s}adopt(t){this._adopter(this._value,t)}get(){return this._mapper(this._value.get())}release(){this._value.release()}dispose(){this._value.dispose()}}class C{constructor(t,e=(()=>{throw new Error("adopt is not supported")})){this._mapper=t,this._adopter=e,this._map=new WeakMap}get(t){return this._map.has(t)||this._map.set(t,new v(t,this._mapper,this._adopter)),this._map.get(t)}}class B{constructor(t,e){this._content=t,this._sampleRate=e}getLength(){return this._content.length}getContent(){return this._content}getSampleRate(){return this._sampleRate}replaceUnderlyingBuffer(t){this._content=t}}class x{constructor(t){this._output=t,this.newFrame=new n,this.togglePause=new n,this._audioBufferPool=new k(()=>new B(new Float32Array(this.getFrameSize()),this.getSampleRate())),this._audioBufferMap=new WeakMap,this._pcmDataPool=new C(t=>t.getContent(),(t,e)=>t.get().replaceUnderlyingBuffer(e)),this._output.newFrame.addHandler(t=>this.newFrame.dispatch(this._pcmDataPool.get(this._audioBufferMap.get(t)))),this._output.togglePause.addHandler(t=>this.togglePause.dispatch(t)),this._output.setFrameBufferFactory(()=>{const t=this._audioBufferPool.get();return this._audioBufferMap.has(t.get())||this._audioBufferMap.set(t.get(),t),t.get()})}getSampleRate(){return this._output.getSampleRate()}getFrameSize(){return this._output.getFrameSize()}isPaused(){return this._output.isPaused()}}class S{constructor(t,e){this._board=t,this._asyncIO=e,this._videoEndpoint=null,this._audioEndpoint=null}getConfig(){return this._board.getConfig()}getVideo(){return this._videoEndpoint||(this._videoEndpoint=new w(this._board.getVideoOutput())),this._videoEndpoint}getJoystick(t){switch(t){case 0:return this._board.getJoystick0();case 1:return this._board.getJoystick1();default:throw new Error("invalid joystick index "+t)}}getControlPanel(){return this._board.getControlPanel()}getPaddle(t){if(t>=0&&t<4)return this._board.getPaddle(t);throw new Error("invalid paddle index "+t)}getWaveformChannels(){return this._board.getWaveformChannels()}getPCMChannel(){return this._audioEndpoint||(this._audioEndpoint=new x(this._board.getPCMChannel())),this._audioEndpoint}getRawVideo(){if(this._videoEndpoint)throw new Error("video endpoint already initialized; raw video unavailable");return this._board.getVideoOutput()}getAsyncIO(){return this._asyncIO}}!function(t){t.TrapPayload=class{constructor(t,e,s){this.reason=t,this.board=e,this.message=s}}}(b||(b={}));class P{constructor(){this.event={trap:new n,read:new n,write:new n},this._tia=null,this._pia=null,this._cartridge=null,this._lastDataBusValue=0,this._lastAddressBusValue=0}setTia(t){return t.trap.addHandler(t=>this.triggerTrap(0,"TIA: "+(t.message||""))),this._tia=t,this}setPia(t){return t.trap.addHandler(t=>this.triggerTrap(1,"PIA: "+(t.message||""))),this._pia=t,this}setCartridge(t){return t.trap.addHandler(t=>this.triggerTrap(2,"CARTRIDGE: "+(t.message||""))),this._cartridge=t,this}readWord(t){return this.read(t)|this.read(t+1&65535)<<8}read(t){return this._lastAddressBusValue=t,4096&(t&=8191)?(this._lastDataBusValue=this._cartridge.read(t),this.event.read.dispatch(2)):128&t?(this._lastDataBusValue=this._pia.read(t),this.event.read.dispatch(1)):(this._lastDataBusValue=this._tia.read(t),this.event.read.dispatch(0)),this._lastDataBusValue}write(t,e){this._lastDataBusValue=e,this._lastAddressBusValue=t,4096&(t&=8191)?(this._cartridge.write(t,e),this.event.write.dispatch(2)):128&t?(this._pia.write(t,e),this.event.write.dispatch(1)):(this._tia.write(t,e),this.event.write.dispatch(0))}peek(t){return 4096&(t&=8191)?this._cartridge.peek(t):128&t?this._pia.peek(t):this._tia.peek(t)}poke(t,e){}getLastDataBusValue(){return this._lastDataBusValue}setDataBusValue(t){this._lastDataBusValue=t}getLastAddresBusValue(){return this._lastAddressBusValue}triggerTrap(t,e){if(!this.event.trap.hasHandlers)throw new Error(e);this.event.trap.dispatch(new P.TrapPayload(t,this,e))}}!function(t){t.TrapPayload=class{constructor(t,e,s){this.reason=t,this.bus=e,this.message=s}}}(P||(P={}));class T{constructor(t,e,s,i){this._controlPanel=t,this._joystick0=e,this._joystick1=s,this._rng=i,this.trap=new n,this.ram=new Uint8Array(128),this._bus=null,this._timerValue=255,this._subTimer=0,this._timerDivide=1024,this._interruptFlag=0,this._timerWrapped=!1,this._flagSetDuringThisCycle=!1,this.reset()}reset(){for(let t=0;t<128;t++)this.ram[t]=this._rng?this._rng.int(255):0;this._interruptFlag=0,this._flagSetDuringThisCycle=!1,this._timerDivide=1024,this._subTimer=0,this._rng.int(255),this._timerValue=0,this._timerWrapped=!1}read(t){return 512&t?4&t?this._readTimer(t):this._readIo(t):this.ram[127&t]}peek(t){return 512&t?4&t?this._peekTimer(t):this._readIo(t):this.ram[127&t]}write(t,e){if(512&t)return 4&t?this._writeTimer(t,e):this._writeIo(t,e);this.ram[127&t]=e}cycle(){this._cycleTimer()}getDebugState(){return`divider: ${this._timerDivide} raw timer: INTIM: ${this._timerValue}`}setBus(t){return this._bus=t,this}_writeIo(t,e){}_writeTimer(t,e){switch(this._interruptFlag=0,663&t){case 663:return this._setTimer(1024,e);case 662:return this._setTimer(64,e);case 661:return this._setTimer(8,e);case 660:return this._setTimer(1,e)}}_setTimer(t,e){this._timerDivide=t,this._timerValue=e,this._subTimer=0,this._timerWrapped=!1}_readIo(t){switch(643&t){case 640:return(this._joystick1.getUp().read()?0:1)|(this._joystick1.getDown().read()?0:2)|(this._joystick1.getLeft().read()?0:4)|(this._joystick1.getRight().read()?0:8)|(this._joystick0.getUp().read()?0:16)|(this._joystick0.getDown().read()?0:32)|(this._joystick0.getLeft().read()?0:64)|(this._joystick0.getRight().read()?0:128);case 642:return(this._controlPanel.getResetButton().read()?0:1)|(this._controlPanel.getSelectSwitch().read()?0:2)|(this._controlPanel.getColorSwitch().read()?0:8)|(this._controlPanel.getDifficultySwitchP0().read()?0:64)|(this._controlPanel.getDifficultySwitchP1().read()?0:128)}return this._bus.getLastDataBusValue()}_readTimer(t){if(1&t){return 128&this._interruptFlag}return this._flagSetDuringThisCycle||(this._interruptFlag=0,this._timerWrapped=!1),this._timerValue}_peekTimer(t){return 1&t?128&this._interruptFlag:this._timerValue}_cycleTimer(){this._flagSetDuringThisCycle=!1,this._timerWrapped?this._timerValue=this._timerValue+255&255:0===this._subTimer&&--this._timerValue<0&&(this._timerValue=255,this._flagSetDuringThisCycle=!0,this._interruptFlag=255,this._timerWrapped=!0),++this._subTimer===this._timerDivide&&(this._subTimer=0)}}!function(t){t.TrapPayload=class{constructor(t,e,s){this.reason=t,this.pia=e,this.message=s}}}(T||(T={})),function(t){t.State=class{constructor(){this.a=0,this.x=0,this.y=0,this.s=0,this.p=0,this.flags=0,this.irq=!1,this.nmi=!1}}}(A||(A={}));class E{constructor(){this.cycleType=0,this.address=0,this.value=0,this.pollInterrupts=!1,this.nextStep=null}read(t,e){return this.cycleType=0,this.address=e,this.nextStep=t,this}write(t,e,s){return this.cycleType=1,this.address=e,this.value=s,this.nextStep=t,this}poll(t){return this.pollInterrupts=t,this}}const I=Symbol("immutable properties");function R(t){const e=t[I];if(e)for(const s of e)Object.defineProperty(t,s,{writable:!1,configurable:!1})}function M(t,e){t[I]||Object.defineProperty(t,I,{value:[],writable:!1,enumerable:!1}),t[I].push(e)}class F{constructor(t){this.reset=()=>this._result.read(this._pre1Step,255),this._pre1Step=()=>this._result.read(this._pre2Step,255),this._pre2Step=()=>this._result.read(this._stack1Step,256),this._stack1Step=()=>this._result.read(this._stack2Step,511),this._stack2Step=()=>(this._state.s=253,this._result.read(this._stack3Step,510)),this._stack3Step=()=>this._result.read(this._readTargetLoStep,65532),this._readTargetLoStep=t=>(this._targetAddress=t,this._result.read(this._readTargetHiStep,65533)),this._readTargetHiStep=t=>(this._targetAddress|=t<<8,this._state.p=this._targetAddress,null),this._targetAddress=0,this._result=new E,this._state=t,R(this)}}_([M,d("design:type",Object)],F.prototype,"reset",void 0),_([M,d("design:type",Object)],F.prototype,"_pre1Step",void 0),_([M,d("design:type",Object)],F.prototype,"_pre2Step",void 0),_([M,d("design:type",Object)],F.prototype,"_stack1Step",void 0),_([M,d("design:type",Object)],F.prototype,"_stack2Step",void 0),_([M,d("design:type",Object)],F.prototype,"_stack3Step",void 0),_([M,d("design:type",Object)],F.prototype,"_readTargetLoStep",void 0),_([M,d("design:type",Object)],F.prototype,"_readTargetHiStep",void 0),_([M,d("design:type",Object)],F.prototype,"_result",void 0),_([M,d("design:type",A.State)],F.prototype,"_state",void 0);class O{constructor(t,e,s){this.reset=()=>this._result.read(this._dummyRead,this._state.p),this._dummyRead=()=>(this._isBrk&&(this._state.p=this._state.p+1&65535),this._result.write(this._pushPch,256+this._state.s,this._state.p>>>8)),this._pushPch=()=>(this._state.s=this._state.s-1&255,this._result.write(this._pushPcl,256+this._state.s,255&this._state.p).poll(!0)),this._pushPcl=()=>(this._state.s=this._state.s-1&255,this._vector=this._state.nmi?65530:this._defaultVector,this._result.write(this._pushFlags,256+this._state.s,this._isBrk?16|this._state.flags:-17&this._state.flags)),this._pushFlags=()=>(this._state.s=this._state.s-1&255,this._result.read(this._fetchPcl,this._vector)),this._fetchPcl=t=>(this._state.flags|=4,this._state.p=t,this._result.read(this._fetchPch,++this._vector)),this._fetchPch=t=>(this._state.p=this._state.p|t<<8,this._state.nmi=this._state.irq=!1,null),this._vector=0,this._result=new E,this._state=t,this._defaultVector=e,this._isBrk=s,R(this)}}_([M,d("design:type",Object)],O.prototype,"reset",void 0),_([M,d("design:type",Object)],O.prototype,"_dummyRead",void 0),_([M,d("design:type",Object)],O.prototype,"_pushPch",void 0),_([M,d("design:type",Object)],O.prototype,"_pushPcl",void 0),_([M,d("design:type",Object)],O.prototype,"_pushFlags",void 0),_([M,d("design:type",Object)],O.prototype,"_fetchPcl",void 0),_([M,d("design:type",Object)],O.prototype,"_fetchPch",void 0),_([M,d("design:type",Object)],O.prototype,"_result",void 0),_([M,d("design:type",A.State)],O.prototype,"_state",void 0),_([M,d("design:type",Number)],O.prototype,"_defaultVector",void 0),_([M,d("design:type",Boolean)],O.prototype,"_isBrk",void 0);class H{constructor(t,e,s=e){this.operation=t,this.addressingMode=e,this.effectiveAddressingMode=s}getSize(){switch(this.effectiveAddressingMode){case 1:case 2:case 6:case 9:case 8:case 11:case 5:return 2;case 3:case 7:case 10:case 4:return 3;default:return 1}}}!function(t){let e;!function(t){t[t.adc=0]="adc",t[t.and=1]="and",t[t.asl=2]="asl",t[t.bcc=3]="bcc",t[t.bcs=4]="bcs",t[t.beq=5]="beq",t[t.bit=6]="bit",t[t.bmi=7]="bmi",t[t.bne=8]="bne",t[t.bpl=9]="bpl",t[t.brk=10]="brk",t[t.bvc=11]="bvc",t[t.bvs=12]="bvs",t[t.clc=13]="clc",t[t.cld=14]="cld",t[t.cli=15]="cli",t[t.clv=16]="clv",t[t.cmp=17]="cmp",t[t.cpx=18]="cpx",t[t.cpy=19]="cpy",t[t.dec=20]="dec",t[t.dex=21]="dex",t[t.dey=22]="dey",t[t.eor=23]="eor",t[t.inc=24]="inc",t[t.inx=25]="inx",t[t.iny=26]="iny",t[t.jmp=27]="jmp",t[t.jsr=28]="jsr",t[t.lda=29]="lda",t[t.ldx=30]="ldx",t[t.ldy=31]="ldy",t[t.lsr=32]="lsr",t[t.nop=33]="nop",t[t.ora=34]="ora",t[t.pha=35]="pha",t[t.php=36]="php",t[t.pla=37]="pla",t[t.plp=38]="plp",t[t.rol=39]="rol",t[t.ror=40]="ror",t[t.rti=41]="rti",t[t.rts=42]="rts",t[t.sbc=43]="sbc",t[t.sec=44]="sec",t[t.sed=45]="sed",t[t.sei=46]="sei",t[t.sta=47]="sta",t[t.stx=48]="stx",t[t.sty=49]="sty",t[t.tax=50]="tax",t[t.tay=51]="tay",t[t.tsx=52]="tsx",t[t.txa=53]="txa",t[t.txs=54]="txs",t[t.tya=55]="tya",t[t.dop=56]="dop",t[t.top=57]="top",t[t.alr=58]="alr",t[t.axs=59]="axs",t[t.dcp=60]="dcp",t[t.lax=61]="lax",t[t.arr=62]="arr",t[t.slo=63]="slo",t[t.aax=64]="aax",t[t.lar=65]="lar",t[t.isc=66]="isc",t[t.aac=67]="aac",t[t.atx=68]="atx",t[t.rra=69]="rra",t[t.rla=70]="rla",t[t.invalid=71]="invalid"}(e=t.OperationMap||(t.OperationMap={})),t.opcodes=new Array(256)}(H||(H={})),function(t){let e;!function(e){for(let e=0;e<256;e++)t.opcodes[e]=new t(71,12);let s,i,r;for(let e=0;e<8;e++){switch(e){case 0:s=34;break;case 1:s=1;break;case 2:s=23;break;case 3:s=0;break;case 4:s=47;break;case 5:s=29;break;case 6:s=17;break;case 7:s=43}for(let n=0;n<8;n++){switch(n){case 0:i=8;break;case 1:i=2;break;case 2:i=1;break;case 3:i=3;break;case 4:i=11;break;case 5:i=6;break;case 6:i=10;break;case 7:i=7}47===s&&1===i&&(i=12),71!==s&&12!==i&&(r=e<<5|n<<2|1,t.opcodes[r]=new t(s,i))}}function n(e,s,i,r){if(71!==t.opcodes[e].operation)throw new Error("entry for opcode "+e+" already exists");t.opcodes[e]=new t(s,i,r)}n(6,2,2),n(10,2,0),n(14,2,3),n(22,2,6),n(30,2,7),n(38,39,2),n(42,39,0),n(46,39,3),n(54,39,6),n(62,39,7),n(70,32,2),n(74,32,0),n(78,32,3),n(86,32,6),n(94,32,7),n(102,40,2),n(106,40,0),n(110,40,3),n(118,40,6),n(126,40,7),n(134,48,2),n(142,48,3),n(150,48,9),n(162,30,1),n(166,30,2),n(174,30,3),n(182,30,9),n(190,30,10),n(198,20,2),n(206,20,3),n(214,20,6),n(222,20,7),n(230,24,2),n(238,24,3),n(246,24,6),n(254,24,7),n(36,6,2),n(44,6,3),n(76,27,3),n(108,27,4),n(132,49,2),n(140,49,3),n(148,49,6),n(160,31,1),n(164,31,2),n(172,31,3),n(180,31,6),n(188,31,7),n(192,19,1),n(196,19,2),n(204,19,3),n(224,18,1),n(228,18,2),n(236,18,3),n(16,9,5),n(48,7,5),n(80,11,5),n(112,12,5),n(144,3,5),n(176,4,5),n(208,8,5),n(240,5,5),n(0,10,0),n(32,28,0,3),n(64,41,0),n(96,42,0),n(8,36,0),n(40,38,0),n(72,35,0),n(104,37,0),n(136,22,0),n(168,51,0),n(200,26,0),n(232,25,0),n(24,13,0),n(56,44,0),n(88,15,0),n(120,46,0),n(152,55,0),n(184,16,0),n(216,14,0),n(248,45,0),n(138,53,0),n(154,54,0),n(170,50,0),n(186,52,0),n(202,21,0),n(234,33,0),n(26,33,0),n(58,33,0),n(90,33,0),n(122,33,0),n(218,33,0),n(250,33,0),n(4,56,2),n(20,56,6),n(52,56,6),n(68,56,2),n(84,56,6),n(100,56,2),n(116,56,6),n(128,56,1),n(130,56,1),n(137,56,1),n(194,56,1),n(212,56,6),n(226,56,1),n(244,56,6),n(12,57,3),n(28,57,7),n(60,57,7),n(92,57,7),n(124,57,7),n(220,57,7),n(252,57,7),n(235,43,1),n(75,58,1),n(203,59,1),n(199,60,2),n(215,60,6),n(207,60,3),n(223,60,7),n(219,60,10),n(195,60,8),n(211,60,11),n(167,61,2),n(183,61,9),n(175,61,3),n(191,61,10),n(163,61,8),n(179,61,11),n(107,62,1),n(7,63,2),n(23,63,6),n(15,63,3),n(31,63,7),n(27,63,10),n(3,63,8),n(19,63,11),n(135,64,2),n(151,64,9),n(131,64,8),n(143,64,3),n(187,65,10),n(231,66,2),n(247,66,6),n(239,66,3),n(255,66,7),n(251,66,10),n(227,66,8),n(243,66,11),n(11,67,1),n(43,67,1),n(171,68,1),n(103,69,2),n(119,69,6),n(111,69,3),n(127,69,7),n(123,69,10),n(99,69,8),n(115,69,11),n(39,70,2),n(55,70,6),n(47,70,3),n(63,70,7),n(59,70,10),n(35,70,8),n(51,70,11)}(e=t.__init||(t.__init={}))}(H||(H={}));class L{constructor(t,e=(()=>null)){this.reset=()=>this._result.read(this._fetchLo,this._state.p),this._fetchLo=t=>(this._operand=t,this._state.p=this._state.p+1&65535,this._result.read(this._fetchHi,this._state.p)),this._fetchHi=t=>(this._operand|=t<<8,this._state.p=this._state.p+1&65535,this._next(this._operand,this._state)),this._operand=0,this._result=new E,this._state=t,this._next=e,R(this)}}_([M,d("design:type",Object)],L.prototype,"reset",void 0),_([M,d("design:type",Object)],L.prototype,"_fetchLo",void 0),_([M,d("design:type",Object)],L.prototype,"_fetchHi",void 0),_([M,d("design:type",Object)],L.prototype,"_result",void 0),_([M,d("design:type",A.State)],L.prototype,"_state",void 0),_([M,d("design:type",Function)],L.prototype,"_next",void 0);class D{constructor(t,e,s=(()=>null),i=!1){this.reset=()=>this._result.read(this._fetchLo,this._state.p),this._fetchLo=t=>(this._operand=t,this._state.p=this._state.p+1&65535,this._result.read(this._fetchHi,this._state.p)),this._fetchHi=t=>{this._operand|=t<<8,this._state.p=this._state.p+1&65535;const e=this._indexExtractor(this._state);return this._carry=(255&this._operand)+e>255,this._operand=65280&this._operand|this._operand+e&255,this._carry||this._writeOp?this._result.read(this._dereferenceAndCarry,this._operand):this._next(this._operand,this._state)},this._dereferenceAndCarry=t=>(this._carry&&(this._operand=this._operand+256&65535),this._next(this._operand,this._state)),this._operand=0,this._carry=!1,this._result=new E,this._state=t,this._indexExtractor=e,this._next=s,this._writeOp=i,R(this)}static absoluteX(t,e,s){return new D(t,t=>t.x,e,s)}static absoluteY(t,e,s){return new D(t,t=>t.y,e,s)}}_([M,d("design:type",Object)],D.prototype,"reset",void 0),_([M,d("design:type",Object)],D.prototype,"_fetchLo",void 0),_([M,d("design:type",Object)],D.prototype,"_fetchHi",void 0),_([M,d("design:type",Object)],D.prototype,"_dereferenceAndCarry",void 0),_([M,d("design:type",Object)],D.prototype,"_result",void 0),_([M,d("design:type",A.State)],D.prototype,"_state",void 0),_([M,d("design:type",Function)],D.prototype,"_indexExtractor",void 0),_([M,d("design:type",Function)],D.prototype,"_next",void 0),_([M,d("design:type",Boolean)],D.prototype,"_writeOp",void 0),_([M,d("design:type",Function),d("design:paramtypes",[A.State,Function,Boolean]),d("design:returntype",D)],D,"absoluteX",null),_([M,d("design:type",Function),d("design:paramtypes",[A.State,Function,Boolean]),d("design:returntype",D)],D,"absoluteY",null);class U{constructor(t,e=(()=>null)){this.reset=t=>this._result.read(this._dereference,t),this._dereference=t=>this._next(t,this._state),this._result=new E,this._next=e,this._state=t,R(this)}}_([M,d("design:type",Object)],U.prototype,"reset",void 0),_([M,d("design:type",Object)],U.prototype,"_dereference",void 0),_([M,d("design:type",Object)],U.prototype,"_result",void 0),_([M,d("design:type",A.State)],U.prototype,"_state",void 0),_([M,d("design:type",Function)],U.prototype,"_next",void 0);class j{constructor(t,e=(()=>null)){this.reset=()=>this._result.read(this._fetchOperand,this._state.p),this._fetchOperand=t=>(this._operand=t,this._state.p=this._state.p+1&65535,this._next(this._operand,this._state)),this._operand=0,this._result=new E,this._state=t,this._next=e,R(this)}}_([M,d("design:type",Object)],j.prototype,"reset",void 0),_([M,d("design:type",Object)],j.prototype,"_fetchOperand",void 0),_([M,d("design:type",Object)],j.prototype,"_result",void 0),_([M,d("design:type",A.State)],j.prototype,"_state",void 0),_([M,d("design:type",Function)],j.prototype,"_next",void 0);class V{constructor(t,e=(()=>null)){this.reset=()=>this._result.read(this._fetchAddress,this._state.p),this._fetchAddress=t=>(this._address=t,this._state.p=this._state.p+1&65535,this._result.read(this._addIndex,this._address)),this._addIndex=t=>(this._address=this._address+this._state.x&255,this._result.read(this._fetchLo,this._address)),this._fetchLo=t=>(this._operand=t,this._address=this._address+1&255,this._result.read(this._fetchHi,this._address)),this._fetchHi=t=>(this._operand|=t<<8,this._next(this._operand,this._state)),this._operand=0,this._address=0,this._result=new E,this._state=t,this._next=e,R(this)}}_([M,d("design:type",Object)],V.prototype,"reset",void 0),_([M,d("design:type",Object)],V.prototype,"_fetchAddress",void 0),_([M,d("design:type",Object)],V.prototype,"_addIndex",void 0),_([M,d("design:type",Object)],V.prototype,"_fetchLo",void 0),_([M,d("design:type",Object)],V.prototype,"_fetchHi",void 0),_([M,d("design:type",Object)],V.prototype,"_result",void 0),_([M,d("design:type",A.State)],V.prototype,"_state",void 0),_([M,d("design:type",Function)],V.prototype,"_next",void 0);class Q{constructor(t,e=(()=>null),s){this.reset=()=>this._result.read(this._fetchAddress,this._state.p),this._fetchAddress=t=>(this._address=t,this._state.p=this._state.p+1&65535,this._result.read(this._fetchLo,this._address)),this._fetchLo=t=>(this._operand=t,this._address=this._address+1&255,this._result.read(this._fetchHi,this._address)),this._fetchHi=t=>(this._operand|=t<<8,this._carry=(255&this._operand)+this._state.y>255,this._operand=65280&this._operand|this._operand+this._state.y&255,this._carry||this._writeOp?this._result.read(this._dereferenceAndCarry,this._operand):this._next(this._operand,this._state)),this._dereferenceAndCarry=t=>(this._carry&&(this._operand=this._operand+256&65535),this._next(this._operand,this._state)),this._operand=0,this._address=0,this._carry=!1,this._result=new E,this._state=t,this._next=e,this._writeOp=s,R(this)}}_([M,d("design:type",Object)],Q.prototype,"reset",void 0),_([M,d("design:type",Object)],Q.prototype,"_fetchAddress",void 0),_([M,d("design:type",Object)],Q.prototype,"_fetchLo",void 0),_([M,d("design:type",Object)],Q.prototype,"_fetchHi",void 0),_([M,d("design:type",Object)],Q.prototype,"_dereferenceAndCarry",void 0),_([M,d("design:type",Object)],Q.prototype,"_result",void 0),_([M,d("design:type",A.State)],Q.prototype,"_state",void 0),_([M,d("design:type",Function)],Q.prototype,"_next",void 0),_([M,d("design:type",Boolean)],Q.prototype,"_writeOp",void 0);class W{constructor(t,e=(()=>null)){this.reset=()=>this._result.read(this._fetchAddress,this._state.p),this._fetchAddress=t=>(this._operand=t,this._state.p=this._state.p+1&65535,this._next(this._operand,this._state)),this._operand=0,this._result=new E,this._state=t,this._next=e,R(this)}}_([M,d("design:type",Object)],W.prototype,"reset",void 0),_([M,d("design:type",Object)],W.prototype,"_fetchAddress",void 0),_([M,d("design:type",Object)],W.prototype,"_result",void 0),_([M,d("design:type",A.State)],W.prototype,"_state",void 0),_([M,d("design:type",Function)],W.prototype,"_next",void 0);class z{constructor(t,e,s){this.reset=()=>this._result.read(this._fetchAddress,this._state.p),this._fetchAddress=t=>(this._operand=t,this._state.p=this._state.p+1&65535,this._result.read(this._addIndex,this._operand)),this._addIndex=t=>(this._operand=this._operand+this._indexExtractor(this._state)&255,this._next(this._operand,this._state)),this._operand=0,this._result=new E,this._state=t,this._indexExtractor=e,this._next=s,R(this)}static zeroPageX(t,e=(()=>null)){return new z(t,t=>t.x,e)}static zeroPageY(t,e=(()=>null)){return new z(t,t=>t.y,e)}}_([M,d("design:type",Object)],z.prototype,"reset",void 0),_([M,d("design:type",Object)],z.prototype,"_fetchAddress",void 0),_([M,d("design:type",Object)],z.prototype,"_addIndex",void 0),_([M,d("design:type",Object)],z.prototype,"_result",void 0),_([M,d("design:type",A.State)],z.prototype,"_state",void 0),_([M,d("design:type",Function)],z.prototype,"_next",void 0),_([M,d("design:type",Function)],z.prototype,"_indexExtractor",void 0);class J{constructor(t,e){this.reset=()=>this._result.read(this._fetchTarget,this._state.p).poll(!0),this._fetchTarget=t=>(this._operand=t,this._state.p=this._state.p+1&65535,this._predicate(this._state.flags)?this._result.read(this._firstDummyRead,this._state.p):null),this._firstDummyRead=t=>(this._target=this._state.p+(128&this._operand?this._operand-256:this._operand)&65535,(65280&this._target)==(65280&this._state.p)?(this._state.p=this._target,null):this._result.read(this._secondDummyRead,65280&this._state.p|255&this._target).poll(!0)),this._secondDummyRead=t=>(this._state.p=this._target,null),this._target=0,this._operand=0,this._result=new E,this._state=t,this._predicate=e,R(this)}}_([M,d("design:type",Object)],J.prototype,"reset",void 0),_([M,d("design:type",Object)],J.prototype,"_fetchTarget",void 0),_([M,d("design:type",Object)],J.prototype,"_firstDummyRead",void 0),_([M,d("design:type",Object)],J.prototype,"_secondDummyRead",void 0),_([M,d("design:type",Object)],J.prototype,"_result",void 0),_([M,d("design:type",A.State)],J.prototype,"_state",void 0),_([M,d("design:type",Function)],J.prototype,"_predicate",void 0);const Y=(t,e)=>new J(t,e);class q{constructor(t){this.reset=()=>this._result.read(this._fetchPcl,this._state.p),this._fetchPcl=t=>(this._addressLo=t,this._state.p=this._state.p+1&65535,this._result.read(this._dummyStackRead,256+this._state.s)),this._dummyStackRead=()=>this._result.write(this._pushPch,256+this._state.s,this._state.p>>>8),this._pushPch=()=>(this._state.s=this._state.s-1&255,this._result.write(this._pushPcl,256+this._state.s,255&this._state.p)),this._pushPcl=()=>(this._state.s=this._state.s-1&255,this._result.read(this._fetchPch,this._state.p)),this._fetchPch=t=>(this._state.p=this._addressLo|t<<8,null),this._addressLo=0,this._result=new E,this._state=t,R(this)}}_([M,d("design:type",Object)],q.prototype,"_fetchPcl",void 0),_([M,d("design:type",Object)],q.prototype,"_dummyStackRead",void 0),_([M,d("design:type",Object)],q.prototype,"_pushPch",void 0),_([M,d("design:type",Object)],q.prototype,"_pushPcl",void 0),_([M,d("design:type",Object)],q.prototype,"_fetchPch",void 0),_([M,d("design:type",Object)],q.prototype,"_result",void 0),_([M,d("design:type",A.State)],q.prototype,"_state",void 0);class N{constructor(t,e){this.reset=t=>(this._address=t,this._result.read(this._read,t)),this._read=t=>(this._operand=t,this._result.write(this._dummyWrite,this._address,this._operand)),this._dummyWrite=t=>this._result.write(this._write,this._address,this._operation(this._operand,this._state)),this._write=()=>null,this._result=new E,this._state=t,this._operation=e,R(this)}}_([M,d("design:type",Object)],N.prototype,"reset",void 0),_([M,d("design:type",Object)],N.prototype,"_read",void 0),_([M,d("design:type",Object)],N.prototype,"_dummyWrite",void 0),_([M,d("design:type",Object)],N.prototype,"_write",void 0),_([M,d("design:type",Object)],N.prototype,"_result",void 0),_([M,d("design:type",A.State)],N.prototype,"_state",void 0),_([M,d("design:type",Function)],N.prototype,"_operation",void 0);const X=(t,e)=>new N(t,e);class G{constructor(t){this.reset=()=>this._result.read(this._dummyOperandRead,this._state.p),this._dummyOperandRead=()=>this._result.read(this._dummyStackRead,256+this._state.s),this._dummyStackRead=()=>(this._state.s=this._state.s+1&255,this._result.read(this._popPcl,256+this._state.s)),this._popPcl=t=>(this._state.p=65280&this._state.p|t,this._state.s=this._state.s+1&255,this._result.read(this._popPch,256+this._state.s)),this._popPch=t=>(this._state.p=255&this._state.p|t<<8,this._result.read(this._incrementP,this._state.p)),this._incrementP=()=>(this._state.p=this._state.p+1&65535,null),this._result=new E,this._state=t,R(this)}}_([M,d("design:type",Object)],G.prototype,"reset",void 0),_([M,d("design:type",Object)],G.prototype,"_dummyOperandRead",void 0),_([M,d("design:type",Object)],G.prototype,"_dummyStackRead",void 0),_([M,d("design:type",Object)],G.prototype,"_popPcl",void 0),_([M,d("design:type",Object)],G.prototype,"_popPch",void 0),_([M,d("design:type",Object)],G.prototype,"_incrementP",void 0),_([M,d("design:type",Object)],G.prototype,"_result",void 0),_([M,d("design:type",A.State)],G.prototype,"_state",void 0);class K{constructor(t,e){this.reset=()=>this._result.read(this._executeOperation,this._state.p).poll(!0),this._executeOperation=()=>(this._operation(this._state),null),this._result=new E,this._state=t,this._operation=e,R(this)}}_([M,d("design:type",Object)],K.prototype,"reset",void 0),_([M,d("design:type",Object)],K.prototype,"_executeOperation",void 0),_([M,d("design:type",Object)],K.prototype,"_result",void 0),_([M,d("design:type",A.State)],K.prototype,"_state",void 0),_([M,d("design:type",Function)],K.prototype,"_operation",void 0);const Z=(t,e)=>new K(t,e);class ${constructor(t,e){this.reset=()=>this._result.read(this._dummyRead,this._state.p).poll(!0),this._dummyRead=()=>this._result.read(this._incrementS,256+this._state.s),this._incrementS=()=>(this._state.s=this._state.s+1&255,this._result.read(this._pull,256+this._state.s)),this._pull=t=>(this._operation(this._state,t),null),this._result=new E,this._state=t,this._operation=e,R(this)}}_([M,d("design:type",Object)],$.prototype,"reset",void 0),_([M,d("design:type",Object)],$.prototype,"_dummyRead",void 0),_([M,d("design:type",Object)],$.prototype,"_incrementS",void 0),_([M,d("design:type",Object)],$.prototype,"_pull",void 0),_([M,d("design:type",Object)],$.prototype,"_result",void 0),_([M,d("design:type",A.State)],$.prototype,"_state",void 0),_([M,d("design:type",Function)],$.prototype,"_operation",void 0);const tt=(t,e)=>new $(t,e);class et{constructor(t,e){this.reset=()=>this._result.read(this._dummyRead,this._state.p),this._dummyRead=()=>this._result.write(this._push,256+this._state.s,this._operation(this._state)),this._push=()=>(this._state.s=this._state.s-1&255,null),this._result=new E,this._state=t,this._operation=e,R(this)}}_([M,d("design:type",Object)],et.prototype,"reset",void 0),_([M,d("design:type",Object)],et.prototype,"_dummyRead",void 0),_([M,d("design:type",Object)],et.prototype,"_push",void 0),_([M,d("design:type",Object)],et.prototype,"_result",void 0),_([M,d("design:type",A.State)],et.prototype,"_state",void 0),_([M,d("design:type",Function)],et.prototype,"_operation",void 0);const st=(t,e)=>new et(t,e);class it{constructor(t){this.reset=()=>this._result.read(this._dummyOperandRead,this._state.p),this._dummyOperandRead=()=>this._result.read(this._dummyStackRead,256+this._state.s),this._dummyStackRead=()=>(this._state.s=this._state.s+1&255,this._result.read(this._popP,256+this._state.s)),this._popP=t=>(this._state.flags=-17&(32|t),this._state.s=this._state.s+1&255,this._result.read(this._popPcl,256+this._state.s)),this._popPcl=t=>(this._state.p=65280&this._state.p|t,this._state.s=this._state.s+1&255,this._result.read(this._popPch,256+this._state.s)),this._popPch=t=>(this._state.p=255&this._state.p|t<<8,null),this._result=new E,this._state=t,R(this)}}_([M,d("design:type",Object)],it.prototype,"reset",void 0),_([M,d("design:type",Object)],it.prototype,"_dummyOperandRead",void 0),_([M,d("design:type",Object)],it.prototype,"_dummyStackRead",void 0),_([M,d("design:type",Object)],it.prototype,"_popP",void 0),_([M,d("design:type",Object)],it.prototype,"_popPcl",void 0),_([M,d("design:type",Object)],it.prototype,"_popPch",void 0),_([M,d("design:type",Object)],it.prototype,"_result",void 0),_([M,d("design:type",A.State)],it.prototype,"_state",void 0);class rt{constructor(t,e){this.reset=t=>this._result.write(()=>null,t,this._operation(this._state)),this._result=new E,this._state=t,this._operation=e,R(this)}}_([M,d("design:type",Object)],rt.prototype,"reset",void 0),_([M,d("design:type",Object)],rt.prototype,"_result",void 0),_([M,d("design:type",A.State)],rt.prototype,"_state",void 0),_([M,d("design:type",Function)],rt.prototype,"_operation",void 0);const nt=(t,e)=>new rt(t,e);function at(t,e){e.flags=-131&e.flags|128&t|(t?0:2)}function ht(t,e,s){const i=s(t);return at(i,e),i}function ot(t,e){at(e(t),t)}function ct(t,e,s){return at(s(t,e),e),null}function ut(t,e){if(8&e.flags){const s=(15&t)+(15&e.a)+(1&e.flags),i=(t>>>4)+(e.a>>>4)+(s>9?1:0);e.a=s%10|i%10<<4,e.flags=-132&e.flags|128&e.a|(e.a?0:2)|(i>9?1:0)}else{const s=e.a+t+(1&e.flags),i=255&s;e.flags=-196&e.flags|128&i|(i?0:2)|s>>>8|(~(t^e.a)&(i^t)&128)>>>1,e.a=i}return null}function lt(t){const e=t.a;t.a=t.a<<1&255,t.flags=-132&t.flags|128&t.a|(t.a?0:2)|e>>>7}function _t(t,e){const s=t<<1&255;return e.flags=-132&e.flags|128&s|(s?0:2)|t>>>7,s}function dt(t,e){return e.flags=-195&e.flags|192&t|(t&e.a?0:2),null}function ft(t,e,s){const i=s(e)+(255&~t)+1;e.flags=-132&e.flags|128&i|(255&i?0:2)|i>>>8}function pt(t,e){if(8&e.flags){const s=(15&e.a)-(15&t)-(1&~e.flags),i=(e.a>>>4)-(t>>>4)-(s<0?1:0);e.a=(s<0?10+s:s)|(i<0?10+i:i)<<4,e.flags=-132&e.flags|128&e.a|(e.a?0:2)|(i<0?0:1)}else{t=255&~t;const s=e.a+t+(1&e.flags),i=255&s;e.flags=-196&e.flags|128&i|(i?0:2)|s>>>8|(~(t^e.a)&(i^t)&128)>>>1,e.a=i}return null}function gt(t){const e=t.a;t.a=t.a>>>1,t.flags=-132&t.flags|128&t.a|(t.a?0:2)|1&e}function bt(t,e){const s=t>>>1;return e.flags=-132&e.flags|128&s|(s?0:2)|1&t,s}function At(t){const e=t.a;t.a=t.a<<1&255|1&t.flags,t.flags=-132&t.flags|128&t.a|(t.a?0:2)|e>>>7}function mt(t,e){const s=t<<1&255|1&e.flags;return e.flags=-132&e.flags|128&s|(s?0:2)|t>>>7,s}function kt(t){const e=t.a;t.a=t.a>>>1|(1&t.flags)<<7,t.flags=-132&t.flags|128&t.a|(t.a?0:2)|1&e}function yt(t,e){const s=t>>>1|(1&e.flags)<<7;return e.flags=-132&e.flags|128&s|(s?0:2)|1&t,s}function wt(t,e){const s=e.a&t;return e.a=s>>>1,e.flags=-132&e.flags|128&e.a|(e.a?0:2)|1&s,null}function vt(t,e){const s=t+255&255,i=e.a+(255&~s)+1;return e.flags=-132&e.flags|128&i|(255&i?0:2)|i>>>8,s}function Ct(t,e){const s=(e.a&e.x)+(255&~t)+1;return e.x=255&s,e.flags=-132&e.flags|128&e.x|(255&e.x?0:2)|s>>>8,null}function Bt(t,e){const s=t>>>1|(1&e.flags)<<7;return e.flags=-2&e.flags|1&t,ut(s,e),s}function xt(t,e){const s=t<<1&255|1&e.flags;return e.flags=-2&e.flags|t>>>7,at(e.a&=s,e),s}function St(t,e){e.flags=-2&e.flags|t>>>7;const s=t<<1&255;return e.a=e.a|s,at(e.a,e),s}function Pt(t){const e=t.a&t.x;return at(e,t),e}function Tt(t,e){const s=t+1&255;return pt(s,e),s}function Et(t,e){return e.a&=t,at(e.a,e),e.flags=-2&e.flags|(128&e.a)>>>7,null}class It{constructor(t,e=(()=>null)){this.reset=()=>this._result.read(this._fetchAddressLo,this._state.p),this._fetchAddressLo=t=>(this._address=t,this._state.p=this._state.p+1&65535,this._result.read(this._fetchAddressHi,this._state.p)),this._fetchAddressHi=t=>(this._address|=t<<8,this._state.p=this._state.p+1&65535,this._result.read(this._fetchLo,this._address)),this._fetchLo=t=>(this._operand=t,255==(255&this._address)?this._address&=65280:this._address=this._address+1&65535,this._result.read(this._fetchHi,this._address)),this._fetchHi=t=>(this._operand|=t<<8,this._next(this._operand,this._state)),this._operand=0,this._address=0,this._result=new E,this._state=t,this._next=e,R(this)}}_([M,d("design:type",Object)],It.prototype,"reset",void 0),_([M,d("design:type",Object)],It.prototype,"_fetchAddressLo",void 0),_([M,d("design:type",Object)],It.prototype,"_fetchAddressHi",void 0),_([M,d("design:type",Object)],It.prototype,"_fetchLo",void 0),_([M,d("design:type",Object)],It.prototype,"_fetchHi",void 0),_([M,d("design:type",Object)],It.prototype,"_result",void 0),_([M,d("design:type",A.State)],It.prototype,"_state",void 0),_([M,d("design:type",Function)],It.prototype,"_next",void 0);class Rt{constructor(t){this._state=t}compile(t){const e=H.opcodes[t];switch(e.operation){case 0:return this._createAddressing(e.addressingMode,ut,{deref:!0});case 1:return this._createAddressing(e.addressingMode,(t,e)=>ct(t,e,(t,e)=>e.a=e.a&t),{deref:!0});case 2:return 0===e.addressingMode?Z(this._state,lt):this._createAddressing(e.addressingMode,X(this._state,_t).reset,{writeOp:!0});case 6:return this._createAddressing(e.addressingMode,dt,{deref:!0});case 10:return s=this._state,new O(s,65534,!0);case 17:return this._createAddressing(e.addressingMode,(t,e)=>(ft(t,e,t=>t.a),null),{deref:!0});case 18:return this._createAddressing(e.addressingMode,(t,e)=>(ft(t,e,t=>t.x),null),{deref:!0});case 19:return this._createAddressing(e.addressingMode,(t,e)=>(ft(t,e,t=>t.y),null),{deref:!0});case 20:return this._createAddressing(e.addressingMode,X(this._state,(t,e)=>ht(t,e,t=>t-1&255)).reset,{writeOp:!0});case 21:return Z(this._state,t=>ot(t,t=>t.x=t.x-1&255));case 22:return Z(this._state,t=>ot(t,t=>t.y=t.y-1&255));case 24:return this._createAddressing(e.addressingMode,X(this._state,(t,e)=>ht(t,e,t=>t+1&255)).reset,{writeOp:!0});case 25:return Z(this._state,t=>ot(t,t=>t.x=t.x+1&255));case 26:return Z(this._state,t=>ot(t,t=>t.y=t.y+1&255));case 23:return this._createAddressing(e.addressingMode,(t,e)=>ct(t,e,(t,e)=>e.a=e.a^t),{deref:!0});case 27:return this._createAddressing(e.addressingMode,(t,e)=>(e.p=t,null));case 28:return(t=>new q(t))(this._state);case 29:return this._createAddressing(e.addressingMode,(t,e)=>ct(t,e,(t,e)=>e.a=t),{deref:!0});case 30:return this._createAddressing(e.addressingMode,(t,e)=>ct(t,e,(t,e)=>e.x=t),{deref:!0});case 31:return this._createAddressing(e.addressingMode,(t,e)=>ct(t,e,(t,e)=>e.y=t),{deref:!0});case 32:return 0===e.addressingMode?Z(this._state,gt):this._createAddressing(e.addressingMode,X(this._state,bt).reset,{writeOp:!0});case 33:return Z(this._state,()=>{});case 34:return this._createAddressing(e.addressingMode,(t,e)=>ct(t,e,(t,e)=>e.a|=t),{deref:!0});case 35:return st(this._state,t=>t.a);case 36:return st(this._state,t=>16|t.flags);case 37:return tt(this._state,(t,e)=>ot(t,t=>t.a=e));case 38:return tt(this._state,(t,e)=>t.flags=-17&(32|e));case 39:return 0===e.addressingMode?Z(this._state,At):this._createAddressing(e.addressingMode,X(this._state,mt).reset,{writeOp:!0});case 40:return 0===e.addressingMode?Z(this._state,kt):this._createAddressing(e.addressingMode,X(this._state,yt).reset,{writeOp:!0});case 41:return(t=>new it(t))(this._state);case 42:return(t=>new G(t))(this._state);case 43:return this._createAddressing(e.addressingMode,pt,{deref:!0});case 48:return this._createAddressing(e.addressingMode,nt(this._state,t=>t.x).reset,{writeOp:!0});case 49:return this._createAddressing(e.addressingMode,nt(this._state,t=>t.y).reset,{writeOp:!0});case 50:return Z(this._state,t=>ot(t,t=>t.x=t.a));case 51:return Z(this._state,t=>ot(t,t=>t.y=t.a));case 52:return Z(this._state,t=>ot(t,t=>t.x=t.s));case 53:return Z(this._state,t=>ot(t,t=>t.a=t.x));case 54:return Z(this._state,t=>t.s=t.x);case 55:return Z(this._state,t=>ot(t,t=>t.a=t.y));case 3:return Y(this._state,t=>0==(1&t));case 4:return Y(this._state,t=>(1&t)>0);case 8:return Y(this._state,t=>0==(2&t));case 5:return Y(this._state,t=>(2&t)>0);case 9:return Y(this._state,t=>0==(128&t));case 7:return Y(this._state,t=>(128&t)>0);case 11:return Y(this._state,t=>0==(64&t));case 12:return Y(this._state,t=>(64&t)>0);case 44:return Z(this._state,t=>t.flags|=1);case 45:return Z(this._state,t=>t.flags|=8);case 46:return Z(this._state,t=>t.flags|=4);case 47:return this._createAddressing(e.addressingMode,nt(this._state,t=>t.a).reset,{writeOp:!0});case 13:return Z(this._state,t=>t.flags&=-2);case 14:return Z(this._state,t=>t.flags&=-9);case 15:return Z(this._state,t=>t.flags&=-5);case 16:return Z(this._state,t=>t.flags&=-65);case 56:case 57:return this._createAddressing(e.addressingMode,()=>null,{deref:!0});case 67:return this._createAddressing(e.addressingMode,Et);case 64:return this._createAddressing(e.addressingMode,nt(this._state,Pt).reset,{writeOp:!0});case 58:return this._createAddressing(e.addressingMode,wt,{deref:!0});case 62:return this._createAddressing(e.addressingMode,(t,e)=>(function(t,e){e.a=(e.a&t)>>>1|(1&e.flags?128:0),e.flags=-196&e.flags|(64&e.a)>>>6|(e.a?0:2)|128&e.a|64&e.a^(32&e.a)<<1}(t,e),null),{deref:!0});case 59:return this._createAddressing(e.addressingMode,Ct,{deref:!0});case 68:return this._createAddressing(e.addressingMode,(t,e)=>ct(t,e,(t,e)=>e.x=e.a=e.a&t),{deref:!0});case 60:return this._createAddressing(e.addressingMode,X(this._state,vt).reset,{writeOp:!0});case 66:return this._createAddressing(e.addressingMode,X(this._state,Tt).reset,{writeOp:!0});case 61:return this._createAddressing(e.addressingMode,(t,e)=>ct(t,e,(t,e)=>e.a=e.x=t),{deref:!0});case 65:return this._createAddressing(e.addressingMode,(t,e)=>ct(t,e,(t,e)=>e.s=e.x=e.a=e.s&t),{deref:!0});case 70:return this._createAddressing(e.addressingMode,X(this._state,xt).reset,{writeOp:!0});case 69:return this._createAddressing(e.addressingMode,X(this._state,Bt).reset,{writeOp:!0});case 63:return this._createAddressing(e.addressingMode,X(this._state,St).reset,{writeOp:!0});default:return null}var s}_createAddressing(t,e,{deref:s=!1,writeOp:i=!1}={}){switch(s&&1!==t&&(e=((t,e)=>new U(t,e))(this._state,e).reset),t){case 1:return((t,e)=>new j(t,e))(this._state,e);case 2:return((t,e)=>new W(t,e))(this._state,e);case 3:return((t,e)=>new L(t,e))(this._state,e);case 6:return((t,e)=>z.zeroPageX(t,e))(this._state,e);case 9:return((t,e)=>z.zeroPageY(t,e))(this._state,e);case 7:return((t,e,s)=>D.absoluteX(t,e,s))(this._state,e,i);case 10:return((t,e,s)=>D.absoluteY(t,e,s))(this._state,e,i);case 8:return((t,e)=>new V(t,e))(this._state,e);case 11:return((t,e,s)=>new Q(t,e,s))(this._state,e,i);case 4:return((t,e)=>new It(t,e))(this._state,e);default:throw new Error("invalid addressing mode "+t)}}}class Mt{constructor(t,e){var s;this._bus=t,this._rng=e,this.executionState=0,this.state=new A.State,this._invalidInstructionCallback=null,this._interruptPending=!1,this._nmiPending=!1,this._halt=!1,this._pollInterruptsAfterLastInstruction=!1,this._lastInstructionPointer=0,this._operations=new Array(255),this._opBoot=(s=this.state,new F(s)),this._opIrq=(t=>new O(t,65534,!1))(this.state),this._opNmi=(t=>new O(t,65530,!1))(this.state);const i=new Rt(this.state);for(let t=0;t<256;t++)this._operations[t]=i.compile(t);this.reset()}reset(){return this.state.a=this._rng?this._rng.int(255):0,this.state.x=this._rng?this._rng.int(255):0,this.state.y=this._rng?this._rng.int(255):0,this.state.s=253,this.state.p=this._rng?this._rng.int(65535):0,this.state.flags=52|(this._rng?this._rng.int(255):0),this.state.irq=!1,this.state.nmi=!1,this.executionState=0,this._interruptPending=!1,this._nmiPending=!1,this._halt=!1,this._lastResult=this._opBoot.reset(void 0),this._lastInstructionPointer=0,this}setInterrupt(t){return this._interruptPending=t,this}isInterrupt(){return this._interruptPending}nmi(){return this._nmiPending=!0,this}halt(){return this._halt=!0,this}resume(){return this._halt=!1,this}isHalt(){return this._halt}setInvalidInstructionCallback(t){return this._invalidInstructionCallback=t,this}getInvalidInstructionCallback(){return this._invalidInstructionCallback}getLastInstructionPointer(){return this._lastInstructionPointer}cycle(){if(this._halt&&(!this._lastResult||0===this._lastResult.cycleType))return this;if(1===this.executionState)return this._fetch(),this;let t;switch(this._lastResult.cycleType){case 0:t=this._bus.read(this._lastResult.address);break;case 1:t=this._lastResult.value,this._bus.write(this._lastResult.address,t);break;default:throw new Error("invalid cycle type")}return this._lastResult.pollInterrupts&&(this._pollInterrupts(),this._lastResult.pollInterrupts=!1,this._pollInterruptsAfterLastInstruction=!1),this._lastResult=this._lastResult.nextStep(t),null===this._lastResult&&(this.executionState=1),this}_fetch(){let t;this._pollInterruptsAfterLastInstruction&&this._pollInterrupts(),this._lastInstructionPointer=this.state.p;const e=this._bus.read(this.state.p);this.state.nmi?(t=this._opNmi,this._pollInterruptsAfterLastInstruction=!1):this.state.irq?(t=this._opIrq,this._pollInterruptsAfterLastInstruction=!1):(t=this._operations[e],this.state.p=this.state.p+1&65535,this._pollInterruptsAfterLastInstruction=!0),t?(this.executionState=2,this._lastResult=t.reset(void 0)):this._invalidInstructionCallback&&this._invalidInstructionCallback(this)}_pollInterrupts(){if(this.state.irq=!1,this._nmiPending)return this.state.nmi=!0,void(this._nmiPending=!1);!this._interruptPending||this.state.nmi||4&this.state.flags||(this.state.irq=!0)}}function Ft(t,e){t.s=t.s+1&255,t.flags=-17&(32|e.read(256+t.s))}function Ot(t,e){t.flags=-131&t.flags|128&e|(e?0:2)}function Ht(t,e,s){if(8&t.flags){const e=(15&s)+(15&t.a)+(1&t.flags),i=(s>>>4)+(t.a>>>4)+(e>9?1:0);t.a=e%10|i%10<<4,t.flags=-132&t.flags|128&t.a|(t.a?0:2)|(i>9?1:0)}else{const e=t.a+s+(1&t.flags),i=255&e;t.flags=-196&t.flags|128&i|(i?0:2)|e>>>8|(~(s^t.a)&(i^s)&128)>>>1,t.a=i}}function Lt(t,e,s){t.a&=s,Ot(t,t.a)}function Dt(t){const e=t.a;t.a=t.a<<1&255,t.flags=-132&t.flags|128&t.a|(t.a?0:2)|e>>>7}function Ut(t,e,s){const i=e.read(s),r=i<<1&255;e.write(s,r),t.flags=-132&t.flags|128&r|(r?0:2)|i>>>7}function jt(t,e,s){t.flags=-195&t.flags|192&s|(s&t.a?0:2)}function Vt(t,e){const s=t.p+1&65535;let i=65534;t.nmi&&(i=65530,t.nmi=!1),t.nmi=t.irq=!1,e.write(t.s+256,s>>>8&255),t.s=t.s+255&255,e.write(t.s+256,255&s),t.s=t.s+255&255,e.write(t.s+256,16|t.flags),t.s=t.s+255&255,t.flags|=4,t.p=e.readWord(i)}function Qt(t){t.flags&=-2}function Wt(t){t.flags&=-9}function zt(t){t.flags&=-5}function Jt(t){t.flags&=-65}function Yt(t,e,s){const i=t.a+(255&~s)+1;t.flags=-132&t.flags|128&i|(255&i?0:2)|i>>>8}function qt(t,e,s){const i=t.x+(255&~s)+1;t.flags=-132&t.flags|128&i|(255&i?0:2)|i>>>8}function Nt(t,e,s){const i=t.y+(255&~s)+1;t.flags=-132&t.flags|128&i|(255&i?0:2)|i>>>8}function Xt(t,e,s){const i=e.read(s)+255&255;e.write(s,i),Ot(t,i)}function Gt(t){t.x=t.x+255&255,Ot(t,t.x)}function Kt(t,e,s){t.a=t.a^s,Ot(t,t.a)}function Zt(t){t.y=t.y+255&255,Ot(t,t.y)}function $t(t,e,s){const i=e.read(s)+1&255;e.write(s,i),Ot(t,i)}function te(t){t.x=t.x+1&255,Ot(t,t.x)}function ee(t){t.y=t.y+1&255,Ot(t,t.y)}function se(t,e,s){t.p=s}function ie(t,e,s){const i=t.p+1&65535,r=e.read(t.p);e.read(256+t.s),e.write(256+t.s,i>>>8),t.s=t.s+255&255,e.write(256+t.s,255&i),t.s=t.s+255&255,t.p=r|e.read(t.p+1&65535)<<8}function re(t,e,s,i){t.a=1===i?s:e.read(s),Ot(t,t.a)}function ne(t,e,s,i){t.x=1===i?s:e.read(s),Ot(t,t.x)}function ae(t,e,s,i){t.y=1===i?s:e.read(s),Ot(t,t.y)}function he(t){const e=t.a;t.a=t.a>>>1,t.flags=-132&t.flags|128&t.a|(t.a?0:2)|1&e}function oe(t,e,s){const i=e.read(s),r=i>>>1;e.write(s,r),t.flags=-132&t.flags|128&r|(r?0:2)|1&i}function ce(){}function ue(t,e,s){t.a|=s,Ot(t,t.a)}function le(t,e){e.write(256+t.s,16|t.flags),t.s=t.s+255&255}function _e(t,e){Ft(t,e)}function de(t,e){e.write(256+t.s,t.a),t.s=t.s+255&255}function fe(t,e){t.s=t.s+1&255,t.a=e.read(256+t.s),Ot(t,t.a)}function pe(t){const e=t.a;t.a=t.a<<1&255|1&t.flags,t.flags=-132&t.flags|128&t.a|(t.a?0:2)|e>>>7}function ge(t,e,s){const i=e.read(s),r=i<<1&255|1&t.flags;e.write(s,r),t.flags=-132&t.flags|128&r|(r?0:2)|i>>>7}function be(t){const e=t.a;t.a=t.a>>>1|(1&t.flags)<<7,t.flags=-132&t.flags|128&t.a|(t.a?0:2)|1&e}function Ae(t,e,s){const i=e.read(s),r=i>>>1|(1&t.flags)<<7;e.write(s,r),t.flags=-132&t.flags|128&r|(r?0:2)|1&i}function me(t,e){let s;Ft(t,e),t.s=t.s+1&255,s=e.read(256+t.s),t.s=t.s+1&255,s|=e.read(256+t.s)<<8,t.p=s}function ke(t,e){let s;e.read(256+t.s),t.s=t.s+1&255,s=e.read(256+t.s),t.s=t.s+1&255,s+=e.read(256+t.s)<<8,t.p=s+1&65535}function ye(t,e,s){if(8&t.flags){const e=(15&t.a)-(15&s)-(1&~t.flags),i=(t.a>>>4)-(s>>>4)-(e<0?1:0);t.a=(e<0?10+e:e)|(i<0?10+i:i)<<4,t.flags=-132&t.flags|128&t.a|(t.a?0:2)|(i<0?0:1)}else{s=255&~s;const e=t.a+s+(1&t.flags),i=255&e;t.flags=-196&t.flags|128&i|(i?0:2)|e>>>8|(~(s^t.a)&(i^s)&128)>>>1,t.a=i}}function we(t){t.flags|=1}function ve(t){t.flags|=8}function Ce(t){t.flags|=4}function Be(t,e,s){e.write(s,t.a)}function xe(t,e,s){e.write(s,t.x)}function Se(t,e,s){e.write(s,t.y)}function Pe(t){t.x=t.a,Ot(t,t.a)}function Te(t){t.y=t.a,Ot(t,t.a)}function Ee(t){t.x=t.s,Ot(t,t.x)}function Ie(t){t.a=t.x,Ot(t,t.a)}function Re(t){t.s=t.x}function Me(t){t.a=t.y,Ot(t,t.a)}function Fe(t,e,s){const i=t.a&s;t.a=i>>>1,t.flags=-132&t.flags|128&t.a|(t.a?0:2)|1&i}function Oe(t,e,s){const i=(t.a&t.x)+(255&~s)+1;t.x=255&i,t.flags=-132&t.flags|128&t.x|(255&t.x?0:2)|i>>>8}function He(t,e,s){const i=e.read(s)+255&255;e.write(s,i);const r=t.a+(255&~i)+1;t.flags=-132&t.flags|128&r|(255&r?0:2)|r>>>8}function Le(t,e,s){t.a=s,t.x=s,Ot(t,s)}function De(t,e,s){t.a=(t.a&s)>>>1|(1&t.flags?128:0),t.flags=-196&t.flags|(64&t.a)>>>6|(t.a?0:2)|128&t.a|64&t.a^(32&t.a)<<1}function Ue(t,e,s){let i=e.read(s);t.flags=-2&t.flags|i>>>7,i=i<<1&255,e.write(s,i),t.a=t.a|i,Ot(t,t.a)}function je(t,e,s){const i=t.x&t.a;e.write(s,i),Ot(t,i)}function Ve(t,e,s){t.s=t.a=t.x=t.s&s,Ot(t,t.a)}function Qe(t,e,s){const i=e.read(s)+1&255;e.write(s,i),ye(t,0,i)}function We(t,e,s){t.a&=s,Ot(t,t.a),t.flags=-2&t.flags|(128&t.a)>>>7}function ze(t,e,s){t.a&=s,t.x=t.a,Ot(t,t.a)}function Je(t,e,s){const i=e.read(s),r=i>>>1|(1&t.flags)<<7;e.write(s,r),t.flags=-2&t.flags|1&i,Ht(t,0,r)}function Ye(t,e,s){const i=e.read(s),r=i<<1&255|1&t.flags;e.write(s,r),t.flags=-2&t.flags|i>>>7,Lt(t,0,r)}function qe(t,e){t.p=e.readWord(65532)}function Ne(t,e,s){const i=t.p;t.nmi&&(s=65530),t.nmi=t.irq=!1,e.write(t.s+256,i>>>8&255),t.s=t.s+255&255,e.write(t.s+256,255&i),t.s=t.s+255&255,e.write(t.s+256,-17&t.flags),t.s=t.s+255&255,t.flags|=4,t.p=e.readWord(s)}function Xe(t,e){Ne(t,e,65534)}function Ge(t,e){Ne(t,e,65530)}class Ke{constructor(t,e){this._bus=t,this._rng=e,this.executionState=0,this.state=new A.State,this._opCycles=0,this._instructionCallback=null,this._invalidInstructionCallback=null,this._interruptPending=!1,this._nmiPending=!1,this._interuptCheck=0,this._halted=!1,this._operand=0,this._lastInstructionPointer=0,this._currentAddressingMode=12,this._dereference=!1,this.reset()}setInterrupt(t){return this._interruptPending=t,this}isInterrupt(){return this._interruptPending}nmi(){return this._nmiPending=!0,this}halt(){return this._halted=!0,this}resume(){return this._halted=!1,this}isHalt(){return this._halted}setInvalidInstructionCallback(t){return this._invalidInstructionCallback=t,this}getInvalidInstructionCallback(){return this._invalidInstructionCallback}getLastInstructionPointer(){return this._lastInstructionPointer}reset(){return this.state.a=this._rng?this._rng.int(255):0,this.state.x=this._rng?this._rng.int(255):0,this.state.y=this._rng?this._rng.int(255):0,this.state.s=253,this.state.p=this._rng?this._rng.int(65535):0,this.state.flags=52|(this._rng?this._rng.int(255):0),this.state.irq=!1,this.state.nmi=!1,this.executionState=0,this._opCycles=7,this._interruptPending=!1,this._nmiPending=!1,this._instructionCallback=qe,this}cycle(){if(this._halted)return this;switch(this.executionState){case 0:case 2:0==--this._opCycles&&(this._dereference&&(this._operand=this._bus.read(this._operand)),1===this._interuptCheck&&this._checkForInterrupts(),this._instructionCallback(this.state,this._bus,this._operand,this._currentAddressingMode),this.executionState=1,0===this._interuptCheck&&this._checkForInterrupts());break;case 1:if(this.state.nmi)return this._instructionCallback=Ge,this._opCycles=6,this.state.nmi=this.state.irq=!1,this._interuptCheck=1,this.executionState=2,this;if(this.state.irq)return this._instructionCallback=Xe,this._opCycles=6,this.state.nmi=this.state.irq=!1,this._interuptCheck=1,this.executionState=2,this;this._fetch()}return this}_fetch(){const t=H.opcodes[this._bus.read(this.state.p)];let e,s,i=t.addressingMode,r=!1,n=!1;switch(this._lastInstructionPointer=this.state.p,this._currentAddressingMode=i,this._interuptCheck=0,t.operation){case 0:this._opCycles=0,this._instructionCallback=Ht,r=!0;break;case 1:this._opCycles=0,this._instructionCallback=Lt,r=!0;break;case 2:0===i?(this._opCycles=1,this._instructionCallback=Dt):(this._opCycles=3,this._instructionCallback=Ut,n=!0);break;case 3:1&this.state.flags?(i=0,this._instructionCallback=ce,this.state.p=this.state.p+1&65535,this._opCycles=1):(this._instructionCallback=se,this._opCycles=0);break;case 4:1&this.state.flags?(this._instructionCallback=se,this._opCycles=0):(i=0,this._instructionCallback=ce,this.state.p=this.state.p+1&65535,this._opCycles=1);break;case 5:2&this.state.flags?(this._instructionCallback=se,this._opCycles=0):(i=0,this._instructionCallback=ce,this.state.p=this.state.p+1&65535,this._opCycles=1);break;case 6:this._opCycles=0,this._instructionCallback=jt,r=!0;break;case 7:128&this.state.flags?(this._instructionCallback=se,this._opCycles=0):(i=0,this._instructionCallback=ce,this.state.p=this.state.p+1&65535,this._opCycles=1);break;case 8:2&this.state.flags?(i=0,this._instructionCallback=ce,this.state.p=this.state.p+1&65535,this._opCycles=1):(this._instructionCallback=se,this._opCycles=0);break;case 9:128&this.state.flags?(i=0,this._instructionCallback=ce,this.state.p=this.state.p+1&65535,this._opCycles=1):(this._instructionCallback=se,this._opCycles=0);break;case 11:64&this.state.flags?(i=0,this._instructionCallback=ce,this.state.p=this.state.p+1&65535,this._opCycles=1):(this._instructionCallback=se,this._opCycles=0);break;case 12:64&this.state.flags?(this._instructionCallback=se,this._opCycles=0):(i=0,this._instructionCallback=ce,this.state.p=this.state.p+1&65535,this._opCycles=1);break;case 10:this._opCycles=6,this._instructionCallback=Vt,this._interuptCheck=1;break;case 13:this._opCycles=1,this._instructionCallback=Qt;break;case 14:this._opCycles=1,this._instructionCallback=Wt;break;case 15:this._opCycles=1,this._instructionCallback=zt,this._interuptCheck=1;break;case 16:this._opCycles=1,this._instructionCallback=Jt;break;case 17:this._opCycles=0,this._instructionCallback=Yt,r=!0;break;case 18:this._opCycles=0,this._instructionCallback=qt,r=!0;break;case 19:this._opCycles=0,this._instructionCallback=Nt,r=!0;break;case 20:this._opCycles=3,this._instructionCallback=Xt,n=!0;break;case 21:this._opCycles=1,this._instructionCallback=Gt;break;case 22:this._opCycles=1,this._instructionCallback=Zt;break;case 23:this._opCycles=0,this._instructionCallback=Kt,r=!0;break;case 24:this._opCycles=3,this._instructionCallback=$t,n=!0;break;case 25:this._opCycles=1,this._instructionCallback=te;break;case 26:this._opCycles=1,this._instructionCallback=ee;break;case 27:this._opCycles=0,this._instructionCallback=se;break;case 28:this._opCycles=5,this._instructionCallback=ie;break;case 29:this._opCycles=1===i?0:1,this._instructionCallback=re;break;case 30:this._opCycles=1===i?0:1,this._instructionCallback=ne;break;case 31:this._opCycles=1===i?0:1,this._instructionCallback=ae;break;case 32:0===i?(this._opCycles=1,this._instructionCallback=he):(this._opCycles=3,this._instructionCallback=oe,n=!0);break;case 33:this._opCycles=1,this._instructionCallback=ce;break;case 56:case 57:this._opCycles=0,r=!0,this._instructionCallback=ce;break;case 34:this._opCycles=0,this._instructionCallback=ue,r=!0;break;case 36:this._opCycles=2,this._instructionCallback=le;break;case 35:this._opCycles=2,this._instructionCallback=de;break;case 37:this._opCycles=3,this._instructionCallback=fe;break;case 38:this._opCycles=3,this._instructionCallback=_e,this._interuptCheck=1;break;case 39:0===i?(this._opCycles=1,this._instructionCallback=pe):(this._opCycles=3,this._instructionCallback=ge,n=!0);break;case 40:0===i?(this._opCycles=1,this._instructionCallback=be):(this._opCycles=3,this._instructionCallback=Ae,n=!0);break;case 41:this._opCycles=5,this._instructionCallback=me;break;case 42:this._opCycles=5,this._instructionCallback=ke;break;case 43:this._opCycles=0,this._instructionCallback=ye,r=!0;break;case 44:this._opCycles=1,this._instructionCallback=we;break;case 45:this._opCycles=1,this._instructionCallback=ve;break;case 46:this._opCycles=1,this._instructionCallback=Ce,this._interuptCheck=1;break;case 47:this._opCycles=1,this._instructionCallback=Be,n=!0;break;case 48:this._opCycles=1,this._instructionCallback=xe,n=!0;break;case 49:this._opCycles=1,this._instructionCallback=Se,n=!0;break;case 50:this._opCycles=1,this._instructionCallback=Pe;break;case 51:this._opCycles=1,this._instructionCallback=Te;break;case 52:this._opCycles=1,this._instructionCallback=Ee;break;case 53:this._opCycles=1,this._instructionCallback=Ie;break;case 54:this._opCycles=1,this._instructionCallback=Re;break;case 55:this._opCycles=1,this._instructionCallback=Me;break;case 62:this._opCycles=0,this._instructionCallback=De;break;case 58:this._opCycles=0,this._instructionCallback=Fe;break;case 59:this._opCycles=0,this._instructionCallback=Oe;break;case 60:this._opCycles=3,this._instructionCallback=He,n=!0;break;case 61:this._opCycles=0,this._instructionCallback=Le,r=!0;break;case 63:this._opCycles=3,this._instructionCallback=Ue,n=!0,r=!1;break;case 64:this._opCycles=1,this._instructionCallback=je;break;case 65:this._opCycles=0,this._instructionCallback=Ve,r=!0;break;case 66:this._opCycles=3,this._instructionCallback=Qe,n=!0;break;case 67:this._opCycles=0,this._instructionCallback=We;break;case 68:this._opCycles=0,this._instructionCallback=ze;break;case 69:this._opCycles=3,r=!1,n=!0,this._instructionCallback=Je;break;case 70:this._opCycles=3,r=!1,n=!0,this._instructionCallback=Ye;break;default:return void(this._invalidInstructionCallback&&this._invalidInstructionCallback(this))}switch(this.state.p=this.state.p+1&65535,i){case 1:this._operand=this._bus.read(this.state.p),r=!1,this.state.p=this.state.p+1&65535,this._opCycles++;break;case 2:this._operand=this._bus.read(this.state.p),this.state.p=this.state.p+1&65535,this._opCycles++;break;case 3:this._operand=this._bus.readWord(this.state.p),this.state.p=this.state.p+2&65535,this._opCycles+=2;break;case 4:e=this._bus.readWord(this.state.p),this._operand=255==(255&e)?this._bus.read(e)+(this._bus.read(65280&e)<<8):this._bus.readWord(e),this.state.p=this.state.p+2&65535,this._opCycles+=4;break;case 5:e=this._bus.read(this.state.p),e=128&e?-(255&~(e-1)):e,this._operand=this.state.p+e+65537&65535,this.state.p=this.state.p+1&65535,this._opCycles+=(65280&this._operand)!=(65280&this.state.p)?3:2;break;case 6:s=this._bus.read(this.state.p),this._bus.read(s),this._operand=s+this.state.x&255,this.state.p=this.state.p+1&65535,this._opCycles+=2;break;case 7:e=this._bus.readWord(this.state.p),this._operand=e+this.state.x&65535,(65280&this._operand)!=(65280&e)&&this._bus.read(65280&e|255&this._operand),this._opCycles+=n||(65280&this._operand)!=(65280&e)?3:2,this.state.p=this.state.p+2&65535;break;case 9:s=this._bus.read(this.state.p),this._bus.read(s),this._operand=s+this.state.y&255,this.state.p=this.state.p+1&65535,this._opCycles+=2;break;case 10:e=this._bus.readWord(this.state.p),this._operand=e+this.state.y&65535,(65280&this._operand)!=(65280&e)&&this._bus.read(65280&e|255&this._operand),this._opCycles+=n||(65280&this._operand)!=(65280&e)?3:2,this.state.p=this.state.p+2&65535;break;case 8:s=this._bus.read(this.state.p),this._bus.read(s),e=s+this.state.x&255,this._operand=255===e?this._bus.read(255)+(this._bus.read(0)<<8):this._bus.readWord(e),this._opCycles+=4,this.state.p=this.state.p+1&65535;break;case 11:e=this._bus.read(this.state.p),e=255===e?this._bus.read(255)+(this._bus.read(0)<<8):this._bus.readWord(e),this._operand=e+this.state.y&65535,(65280&this._operand)!=(65280&e)&&this._bus.read(65280&e|255&this._operand),this._opCycles+=n||(65280&e)!=(65280&this._operand)?4:3,this.state.p=this.state.p+1&65535}this._dereference=r,r&&this._opCycles++,this.executionState=2}_checkForInterrupts(){this._nmiPending&&(this.state.irq=!1,this.state.nmi=!0,this._nmiPending=!1),!this._interruptPending||this.state.nmi||4&this.state.flags||(this.state.irq=!0)}}class Ze{constructor(t){this._type=t}create(t,e){switch(this._type){case Ze.Type.stateMachine:return new Mt(t,e);case Ze.Type.batchedAccess:return new Ke(t,e);default:throw new Error("invalid CPU type")}}}!function(t){let e;!function(t){t[t.stateMachine=0]="stateMachine",t[t.batchedAccess=1]="batchedAccess"}(e=t.Type||(t.Type={}))}(Ze||(Ze={}));var $e,ts=Ze;!function(t){t.create=function(t={}){return Object.assign({tvMode:0,enableAudio:!0,randomSeed:-1,emulatePaddles:!0,frameStart:-1,pcmAudio:!1,cpuType:ts.Type.stateMachine},t)},t.getClockHz=function(t){switch(t.tvMode){case 0:return 3584160;case 1:case 2:return 3556800}}}($e||($e={}));const es=new Uint8Array(256);function ss(t,e){const s=es[t.charCodeAt(e)];if(s>63)throw new Error('invalid base64 character "'+t[e]+'" at index '+e);return s}function is(t,e){return(ss(t,e)<<18)+(ss(t,e+1)<<12)+(ss(t,e+2)<<6)+ss(t,e+3)}function rs(t){if(t.length%4!=0)throw new Error("invalid base64 data --- char count mismatch");const e=t.length/4,s=3*e-function(t){let e=0,s=t.length-1;for(;s>=0&&"="===t[s--];)e++;return e}(t),i=new Uint8Array(s);let r=0;for(let n=0;n<e;n++){const e=is(t,4*n);for(let t=0;t<3&&r<s;t++)i[r++]=e>>>8*(2-t)&255}return i}!function(t){let e;for(e=0;e<256;e++)es[e]=255;for(e=0;e<64;e++)es["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(e)]=e;es["=".charCodeAt(0)]=0}();const ns=rs("AQEPAQEBAQEBAQEBAwMDAQ=="),as=new Int8Array([1]),hs=new Int8Array([1,1]),os=new Int8Array([16,15]),cs=rs("AQICAQEBBAM="),us=rs("AQIBAQICBQQCAQMBAQEBBA=="),ls=rs("AQQBAwIEAQIDAgEBAQEBAQIEAgEEAQECAgEDAgEDAQEBBAEBAQECAQECBgECAgECAQIBAQIBBgIBAgIBAQEBAgICAgcCAwICAQEBAwIBAQIBAQcBAQMBAQIDAwEBAQICAQECAgQDBQEDAQEFAgEBAQIBAgEDAQIFAQECAQEBBQEBAQEBAQEBBgEBAQIBAQEBBAIBAQMBAwYDAgMBAQIBAgQBAQEDAQEBAQMBAgEEAgIDBAEBBAECAQICAgEBBAMBBAQJBQQBBQMBAQMCAgIBBQECAQEBAgMBAgEBAwQCBQICAQIDAQEBAQECAQMDAwIBAgEBAQEBAwMBAgIDAQMBCA=="),_s=rs("BQYEBQoFAwcECgYDBgQJBg=="),ds=[as,cs,cs,rs("AgMCAQQBBgoCBAIBAQQFCQMDBAEBAQgFBQUEAQEBCAQCCAMDAQEHBAIHBQEDAQcEAQQIAgEDBAcBAwcDAgEGBgICBAUDAgYGAQMDAgUDBwMEAwICAgUJAwEFAwECAgsFAQUDAQECDAUBAgUCAQEMBgECBQECAQoGAwICBAECBgo="),hs,hs,os,us,ls,us,os,as,hs,hs,os,_s];class fs{constructor(t){this._config=t}setConfig(t){this._config=t}getKey(t,e){return ds[t]===hs&&ns[t]*(e+1)==1?0:t<<5|e}getBuffer(t){const e=t>>>5&15,s=31&t,i=ds[e];let r=0;for(let t=0;t<i.length;t++)r+=i[t];r=r*ns[e]*(s+1);const n=new Float32Array(r),a=$e.getClockHz(this._config)/114;let h=0,o=0,c=0,u=!0;for(let t=0;t<r;t++)h++,h===ns[e]*(s+1)&&(h=0,o++,o===i[c]&&(c++,o=0,i.length===c&&(c=0)),u=!(1&c)),n[t]=u?1:-1;return new B(n,a)}}class ps{constructor(t){this._config=t,this.bufferChanged=new n,this.volumeChanged=new n,this.stop=new n,this._volume=-1,this._tone=-1,this._frequency=-1,this._active=!1,this._toneGenerator=null,this._toneGenerator=new fs(this._config),this.reset()}reset(){this._volume=-1,this._tone=-1,this._frequency=-1}audc(t){(t&=15)!==this._tone&&(this._tone=t,this._dispatchBufferChanged())}audf(t){(t&=31)!==this._frequency&&(this._frequency=t,this._dispatchBufferChanged())}audv(t){(t&=15)!==this._volume&&(this._volume=t/15,this.volumeChanged.dispatch(this._volume))}setActive(t){this._active=t,t?this._dispatchBufferChanged():this.stop.dispatch(void 0)}getVolume(){return this._volume>=0?this._volume:0}getBuffer(t){return this._toneGenerator.getBuffer(t)}_getKey(){return this._toneGenerator.getKey(this._tone,this._frequency)}_dispatchBufferChanged(){this._active&&this.bufferChanged.hasHandlers&&this.bufferChanged.dispatch(this._getKey())}}class gs{constructor(){this._audv=0,this._audc=0,this._audf=0,this._clkEnable=!1,this._noiseFeedback=!1,this._noiseCounterBit4=!1,this._pulseCounterHold=!1,this._divCounter=0,this._noiseCounter=0,this._pulseCounter=0,this.reset()}reset(){this._audc=this._audf=this._audv=0,this._clkEnable=!1,this._noiseFeedback=!1,this._noiseCounterBit4=!1,this._pulseCounterHold=!1,this._divCounter=0,this._noiseCounter=0,this._pulseCounter=0}phase0(){if(this._clkEnable){switch(this._noiseCounterBit4=!!(1&this._noiseCounter),3&this._audc){case 0:case 1:this._pulseCounterHold=!1;break;case 2:this._pulseCounterHold=2!=(30&this._noiseCounter);break;case 3:this._pulseCounterHold=!this._noiseCounterBit4}switch(3&this._audc){case 0:this._noiseFeedback=!(!(1&(this._pulseCounter^this._noiseCounter))&&(0!==this._noiseCounter||10!==this._pulseCounter)&&12&this._audc);break;default:this._noiseFeedback=!!((4&this._noiseCounter?1:0)^1&this._noiseCounter)||0===this._noiseCounter}}this._clkEnable=this._divCounter===this._audf,this._divCounter===this._audf||31===this._divCounter?this._divCounter=0:this._divCounter++}phase1(){let t=!1;if(this._clkEnable){switch(this._audc>>>2){case 0:t=!!((2&this._pulseCounter?1:0)^1&this._pulseCounter)&&10!==this._pulseCounter&&!!(3&this._audc);break;case 1:t=!(8&this._pulseCounter);break;case 2:t=!this._noiseCounterBit4;break;case 3:t=!(2&this._pulseCounter||!(14&this._pulseCounter))}this._noiseCounter>>>=1,this._noiseFeedback&&(this._noiseCounter|=16),this._pulseCounterHold||(this._pulseCounter=7&~(this._pulseCounter>>>1),t&&(this._pulseCounter|=8))}return(1&this._pulseCounter)*this._audv}audc(t){this._audc=15&t}audf(t){this._audf=31&t}audv(t){this._audv=15&t}}const bs=new Float32Array(31);!function(t){for(let t=0;t<=30;t++)bs[t]=t/30*60/(30+1*t)}();class As{constructor(t){this._config=t,this.newFrame=new n,this.togglePause=new n,this._currentOutputBuffer=null,this._bufferIndex=0,this._sampleRate=0,this._counter=0,this._isActive=!1,this._channel0=new gs,this._channel1=new gs,this._sampleRate=2*(0===this._config.tvMode?15720:15600),this._frameSize=4*(0===this._config.tvMode?262:312),this.reset()}getChannels(){return[{audv:t=>this._channel0.audv(t),audc:t=>this._channel0.audc(t),audf:t=>this._channel0.audf(t),reset:()=>this.reset(),setActive:t=>this.setActive(t)},{audv:t=>this._channel1.audv(t),audc:t=>this._channel1.audc(t),audf:t=>this._channel1.audf(t),reset:()=>{},setActive:()=>{}}]}reset(){this._bufferIndex=0,this._counter=0,this._channel0.reset(),this._channel1.reset()}tick(){switch(this._counter){case 9:case 81:this._channel0.phase0(),this._channel1.phase0();break;case 37:case 149:this._currentOutputBuffer.getContent()[this._bufferIndex++]=bs[this._channel0.phase1()+this._channel1.phase1()],this._bufferIndex===this._currentOutputBuffer.getLength()&&this._dispatchBuffer()}228==++this._counter&&(this._counter=0)}isPaused(){return!this._isActive}setActive(t){t!==this._isActive&&(this._isActive=t,this.togglePause.dispatch(!t))}getSampleRate(){return this._sampleRate}getFrameSize(){return this._frameSize}setFrameBufferFactory(t){this._bufferFactory=t,!this._currentOutputBuffer&&t&&(this._currentOutputBuffer=t(),this._bufferIndex=0)}_dispatchBuffer(){this.newFrame.dispatch(this._currentOutputBuffer),this._currentOutputBuffer=this._bufferFactory?this._bufferFactory():null,this._bufferIndex=0}}const ms=new Uint8Array(160),ks=new Uint8Array(160),ys=new Uint8Array(160),ws=new Uint8Array(160),vs=new Uint8Array(160),Cs=new Uint8Array(160),Bs=[ms,ks,ys,ws,vs,ms,Cs,ms],xs=[ms,ks,ys,ws,vs,ms,Cs,ms];[ms,ks,ys,ws,vs,Cs].forEach(t=>{for(let e=0;e<160;e++)t[e]=0;t[156]=1}),ks[12]=1,ys[28]=1,ws[12]=ws[28]=1,vs[60]=1,Cs[28]=Cs[60]=1;class Ss{constructor(t,e){this._collisionMask=t,this._flushLineCache=e,this.color=4294967295,this.collision=0,this._enabled=!1,this._enam=!1,this._resmp=-1,this._hmmClocks=0,this._counter=0,this._moving=!1,this._width=1,this._effectiveWidth=0,this._lastMovementTick=0,this._rendering=!1,this._renderCounter=-4,this._widths=new Uint8Array([1,2,4,8]),this.reset()}reset(){this.color=4294967295,this._width=1,this._enabled=!1,this._counter=0,this._rendering=!1,this._renderCounter=-4,this._moving=!1,this._hmmClocks=0,this._decodes=Bs[0],this._resmp=0,this._enam=!1,this._effectiveWidth=0,this._lastMovementTick=0}enam(t){const e=(2&t)>0,s=e&&0===this._resmp;e===this._enam&&s===this._enabled||this._flushLineCache(),this._enam=e,this._enabled=s}hmm(t){this._hmmClocks=t>>>4^8}resm(t,e){if(this._counter=t,this._rendering)if(this._renderCounter<0)this._renderCounter=t-157-4;else switch(this._width){case 8:this._renderCounter=t-157+(this._renderCounter>=4?4:0);break;case 4:this._renderCounter=t-157;break;case 2:e?this._rendering=this._renderCounter>1:0===this._renderCounter&&this._renderCounter++;break;default:e&&(this._rendering=this._renderCounter>0)}}resmp(t,e){const s=2&t;s!==this._resmp&&(this._flushLineCache(),this._resmp=s,s?this._enabled=!1:(this._enabled=this._enam,this._counter=e.getRespClock()))}nusiz(t){this._width=this._widths[(48&t)>>>4],this._decodes=Bs[7&t],this._rendering&&this._renderCounter>=this._width&&(this._rendering=!1)}startMovement(){this._moving=!0}movementTick(t,e){return this._lastMovementTick=this._counter,t===this._hmmClocks&&(this._moving=!1),this._moving&&e&&this.tick(!1),this._moving}tick(t){this.collision=this._rendering&&this._renderCounter>=0&&this._enabled?0:this._collisionMask;const e=this._moving&&t;if(this._decodes[this._counter]&&!this._resmp){const t=(this._counter-this._lastMovementTick+160)%4;switch(this._rendering=!0,this._renderCounter=-4,e&&3===t&&this._width<4&&this._renderCounter++,t){case 3:this._effectiveWidth=1===this._width?2:this._width;break;case 2:this._effectiveWidth=0;break;default:this._effectiveWidth=this._width}}else this._rendering&&++this._renderCounter>=(e?this._effectiveWidth:this._width)&&(this._rendering=!1);++this._counter>=160&&(this._counter=0)}getPixel(t){return this.collision?t:this.color}setColor(t){t!==this.color&&this._enabled&&this._flushLineCache(),this.color=t}}class Ps{constructor(t,e){this._collisionMask=t,this._flushLineCache=e,this.collision=0,this._colorLeft=0,this._colorRight=0,this._color=0,this._colorP0=0,this._colorP1=0,this._colorMode=0,this._pattern=0,this._refp=!1,this._reflected=!1,this._pf0=0,this._pf1=0,this._pf2=0,this._x=0,this.reset()}reset(){this._pattern=0,this._reflected=!1,this._refp=!1,this._pf0=0,this._pf1=0,this._pf2=0,this._color=0,this._colorP0=0,this._colorP1=0,this._colorMode=0,this._applyColors()}pf0(t){this._pf0!==t>>>4&&(this._flushLineCache(),this._pf0=t>>>4,this._pattern=1048560&this._pattern|this._pf0)}pf1(t){this._pf1!==t&&(this._flushLineCache(),this._pf1=t,this._pattern=1044495&this._pattern|(128&t)>>>3|(64&t)>>>1|(32&t)<<1|(16&t)<<3|(8&t)<<5|(4&t)<<7|(2&t)<<9|(1&t)<<11)}pf2(t){this._pf2!==t&&(this._flushLineCache(),this._pf2=t,this._pattern=4095&this._pattern|(255&t)<<12)}ctrlpf(t){const e=(1&t)>0,s=2==(6&t)?1:0;e===this._reflected&&s===this._colorMode||(this._flushLineCache(),this._reflected=e,this._colorMode=s,this._applyColors())}setColor(t){t!==this._color&&0===this._colorMode&&this._flushLineCache(),this._color=t,this._applyColors()}setColorP0(t){t!==this._colorP0&&1===this._colorMode&&this._flushLineCache(),this._colorP0=t,this._applyColors()}setColorP1(t){t!==this._colorP1&&1===this._colorMode&&this._flushLineCache(),this._colorP1=t,this._applyColors()}tick(t){if(this._x=t,80!==t&&0!==t||(this._refp=this._reflected),3&t)return;let e;e=0===this._pattern?0:t<80?this._pattern&1<<(t>>>2):this._refp?this._pattern&1<<39-(t>>>2):this._pattern&1<<(t>>>2)-20,this.collision=e?0:this._collisionMask}getPixel(t){return this.collision?t:this._x<80?this._colorLeft:this._colorRight}_applyColors(){switch(this._colorMode){case 0:this._colorLeft=this._colorRight=this._color;break;case 1:this._colorLeft=this._colorP0,this._colorRight=this._colorP1}}}class Ts{constructor(t,e){this._collisionMask=t,this._flushLineCache=e,this.color=4294967295,this.collision=0,this._hmmClocks=0,this._counter=0,this._moving=!1,this._divider=1,this._dividerPending=1,this._dividerChangeCounter=-1,this._sampleCounter=0,this._rendering=!1,this._renderCounter=-5,this._renderCounterTripPoint=0,this._patternNew=0,this._patternOld=0,this._pattern=0,this._reflected=!1,this._delaying=!1,this.reset()}reset(){this.color=4294967295,this.collision=0,this._hmmClocks=0,this._counter=0,this._moving=!1,this._rendering=!1,this._renderCounter=-5,this._decodes=xs[0],this._patternNew=0,this._patternOld=0,this._pattern=0,this._reflected=!1,this._delaying=!1,this._sampleCounter=0,this._dividerPending=0,this._dividerChangeCounter=-1,this._setDivider(1)}grp(t){t!==this._patternNew&&(this._patternNew=t,this._delaying||(this._flushLineCache(),this._updatePattern()))}hmp(t){this._hmmClocks=t>>>4^8}nusiz(t,e){const s=7&t;switch(s){case 5:this._dividerPending=2;break;case 7:this._dividerPending=4;break;default:this._dividerPending=1}const i=this._decodes;if(this._decodes=xs[s],this._decodes!==i&&this._rendering&&this._renderCounter- -5<2&&!this._decodes[(this._counter-this._renderCounter-5+159)%160]&&(this._rendering=!1),this._dividerPending===this._divider)return;if(!this._rendering)return void this._setDivider(this._dividerPending);const r=this._renderCounter- -5;switch(this._divider<<4|this._dividerPending){case 18:case 20:e?r<4?this._setDivider(this._dividerPending):this._dividerChangeCounter=r<5?1:0:r<3?this._setDivider(this._dividerPending):this._dividerChangeCounter=1;break;case 33:case 65:r<(e?4:3)?this._setDivider(this._dividerPending):r<(e?6:5)?(this._setDivider(this._dividerPending),this._renderCounter--):this._dividerChangeCounter=e?0:1;break;case 66:case 36:this._renderCounter<1||e&&this._renderCounter%this._divider==1?this._setDivider(this._dividerPending):this._dividerChangeCounter=this._divider-(this._renderCounter-1)%this._divider;break;default:throw new Error("cannot happen")}}resp(t){this._counter=t,this._rendering&&this._renderCounter- -5<4&&(this._renderCounter=t-157-5)}refp(t){const e=this._reflected;this._reflected=(8&t)>0,this._reflected!==e&&(this._flushLineCache(),this._updatePattern())}vdelp(t){const e=this._delaying;this._delaying=(1&t)>0,this._delaying!==e&&(this._flushLineCache(),this._updatePattern())}startMovement(){this._moving=!0}movementTick(t,e){return t===this._hmmClocks&&(this._moving=!1),this._moving&&e&&this.tick(),this._moving}tick(){if(this.collision=this._rendering&&this._renderCounter>=this._renderCounterTripPoint&&this._pattern&1<<this._sampleCounter?0:this._collisionMask,this._decodes[this._counter])this._rendering=!0,this._renderCounter=-5,this._sampleCounter=0;else if(this._rendering){switch(this._renderCounter++,this._divider){case 1:this._renderCounter>0&&this._sampleCounter++,this._renderCounter>=0&&this._dividerChangeCounter>=0&&0==this._dividerChangeCounter--&&this._setDivider(this._dividerPending);break;default:this._renderCounter>1&&(this._renderCounter-1)%this._divider==0&&this._sampleCounter++,this._renderCounter>0&&this._dividerChangeCounter>=0&&0==this._dividerChangeCounter--&&this._setDivider(this._dividerPending)}this._sampleCounter>7&&(this._rendering=!1)}++this._counter>=160&&(this._counter=0)}getPixel(t){return this.collision?t:this.color}shufflePatterns(){const t=this._patternOld;this._patternOld=this._patternNew,this._delaying&&t!==this._patternOld&&(this._flushLineCache(),this._updatePattern())}getRespClock(){switch(this._divider){case 1:return(this._counter-5+160)%160;case 2:return(this._counter-9+160)%160;case 4:return(this._counter-12+160)%160;default:throw new Error("cannot happen: invalid divider "+this._divider)}}setColor(t){t!==this.color&&this._pattern&&this._flushLineCache(),this.color=t}_updatePattern(){this._pattern=this._delaying?this._patternOld:this._patternNew,this._reflected||(this._pattern=(1&this._pattern)<<7|(2&this._pattern)<<5|(4&this._pattern)<<3|(8&this._pattern)<<1|(16&this._pattern)>>>1|(32&this._pattern)>>>3|(64&this._pattern)>>>5|(128&this._pattern)>>>7)}_setDivider(t){this._divider=t,this._renderCounterTripPoint=1===t?0:1}}class Es{constructor(t,e){this._collisionMask=t,this._flushLineCache=e,this.color=4294967295,this.collision=0,this._enabledOld=!1,this._enabledNew=!1,this._enabled=!1,this._hmmClocks=0,this._counter=0,this._moving=!1,this._width=1,this._effectiveWidth=0,this._lastMovementTick=0,this._rendering=!1,this._renderCounter=-4,this._widths=new Uint8Array([1,2,4,8]),this._delaying=!1,this.reset()}reset(){this.color=4294967295,this.collision=0,this._width=1,this._enabledOld=!1,this._enabledNew=!1,this._enabled=!1,this._counter=0,this._rendering=!1,this._renderCounter=-4,this._moving=!1,this._hmmClocks=0,this._delaying=!1,this._effectiveWidth=0,this._lastMovementTick=0}enabl(t){const e=this._enabledNew;this._enabledNew=(2&t)>0,e===this._enabledNew||this._delaying||(this._flushLineCache(),this._updateEnabled())}hmbl(t){this._hmmClocks=t>>>4^8}resbl(t){this._counter=t,this._rendering=!0,this._renderCounter=t-157-4}ctrlpf(t){const e=this._widths[(48&t)>>>4];e!==this._width&&this._flushLineCache(),this._width=e}vdelbl(t){const e=this._delaying;this._delaying=(1&t)>0,e!==this._delaying&&(this._flushLineCache(),this._updateEnabled())}startMovement(){this._moving=!0}movementTick(t,e){return this._lastMovementTick=this._counter,t===this._hmmClocks&&(this._moving=!1),this._moving&&e&&this.tick(!1),this._moving}tick(t){this.collision=this._rendering&&this._renderCounter>=0&&this._enabled?0:this._collisionMask;const e=this._moving&&t;if(156===this._counter){const t=(this._counter-this._lastMovementTick+160)%4;switch(this._rendering=!0,this._renderCounter=-4,e&&3===t&&this._width<4&&this._renderCounter++,t){case 3:this._effectiveWidth=1===this._width?2:this._width;break;case 2:this._effectiveWidth=0;break;default:this._effectiveWidth=this._width}}else this._rendering&&++this._renderCounter>=(e?this._effectiveWidth:this._width)&&(this._rendering=!1);++this._counter>=160&&(this._counter=0)}getPixel(t){return this.collision?t:this.color}shuffleStatus(){const t=this._enabledOld;this._enabledOld=this._enabledNew,this._delaying&&this._enabledOld!==t&&(this._flushLineCache(),this._updateEnabled())}setColor(t){t!==this.color&&this._enabled&&this._flushLineCache(),this.color=t}_updateEnabled(){this._enabled=this._delaying?this._enabledOld:this._enabledNew}}class Is{constructor(t){this._switch=t,this._modeLatched=!1,this._latchedValue=0,this.reset()}reset(){this._modeLatched=!1,this._latchedValue=0}vblank(t){64&t?this._modeLatched=!0:(this._modeLatched=!1,this._latchedValue=128)}inpt(){let t=this._switch.read()?0:128;return this._modeLatched&&(this._latchedValue&=t,t=this._latchedValue),t}}const Rs=68e-9,Ms=1e6;class Fs{constructor(t,e){this._paddle=e,this._uThresh=0,this._u=0,this._dumped=!1,this._value=.5,this._timestamp=0,this._cpuTimeProvider=null,this._uThresh=5*(1-Math.exp(-86640/t/1001800/Rs)),this._paddle.valueChanged.addHandler(t=>{this._updateValue(),this._value=t}),this.reset()}setCpuTimeProvider(t){this._cpuTimeProvider=t,this._timestamp=this._cpuTimeProvider()}reset(){this._u=0,this._value=this._paddle.getValue(),this._dumped=!1,this._timestamp=this._cpuTimeProvider?this._cpuTimeProvider():0}vblank(t){const e=this._dumped;128&t?(this._dumped=!0,this._u=0):e&&(this._dumped=!1,this._timestamp=this._cpuTimeProvider())}inpt(){this._updateValue();return!this._dumped&&this._u>=this._uThresh?128:0}_updateValue(){if(this._dumped)return;const t=this._cpuTimeProvider();this._u=5*(1-(1-this._u/5)*Math.exp(-(t-this._timestamp)/(this._value*Ms+1800)/Rs)),this._timestamp=t}}class Os{constructor(t){switch(this._config=t,this.newFrame=new n,this.vblank=!1,this.surfaceBuffer=null,this._vblankLines=0,this._kernelLines=0,this._overscanLines=0,this._linesWithoutVsync=0,this._state=0,this._vsync=!1,this._lineInState=0,this._surfaceFactory=null,this._surface=null,this._frameStart=-1,this._config.tvMode){case 0:this._vblankLines=40,this._kernelLines=192,this._overscanLines=30;break;case 1:case 2:this._vblankLines=48,this._kernelLines=228,this._overscanLines=36;break;default:throw new Error("invalid tv mode "+this._config.tvMode)}this._frameStart=this._config.frameStart,this.reset()}reset(){this.vblank=!1,this.surfaceBuffer=null,this._linesWithoutVsync=0,this._state=0,this._vsync=!1,this._lineInState=0,this._surface=null}nextLine(){if(this._surfaceFactory)switch(this._lineInState++,this._state){case 0:case 1:++this._linesWithoutVsync>150&&this._setState(2);break;case 2:this._frameStart>=0?this._lineInState>this._frameStart&&this._startFrame():this._lineInState>=(this.vblank?this._vblankLines:this._vblankLines-10)&&this._startFrame();break;case 3:this._lineInState>=this._kernelLines+20&&this._finalizeFrame();break;case 4:this._lineInState>=this._overscanLines-20&&this._setState(0)}}isRendering(){return 3===this._state&&!!this._surface}setVblank(t){this._surfaceFactory&&(this.vblank=t)}setVsync(t){if(this._surfaceFactory&&t!==this._vsync)switch(this._vsync=t,this._state){case 0:this._linesWithoutVsync=0;case 2:case 4:t&&this._setState(1);break;case 1:t||this._setState(2);break;case 3:t&&this._finalizeFrame()}}getHeight(){return this._kernelLines+20}setSurfaceFactory(t){this._surfaceFactory=t}getCurrentLine(){return 3===this._state?this._lineInState:0}getDebugState(){return`${this._getReadableState()}, line = ${this._lineInState}, vblank = `+(this.vblank?"1":"0")}_getReadableState(){switch(this._state){case 0:return"wait for vsync start";case 1:return"wait for vsync end";case 2:return"wait for frame start";case 3:return"frame";case 4:return"overscan"}}_startFrame(){this._setState(3),this._surface=this._surfaceFactory(),this.surfaceBuffer=this._surface.getBuffer()}_finalizeFrame(){if(3!==this._state)throw new Error("finalize frame in invalid state "+this._state);this.newFrame.dispatch(this._surface),this._setState(4)}_setState(t){this._state=t,this._lineInState=0}}class Hs{constructor(t,e){this._length=t,this._nextIndex=0,this._indices=new Uint8Array(255),this._queue=new Array(this._length);for(let t=0;t<this._length;t++)this._queue[t]=new Ls(e)}reset(){for(let t=0;t<this._length;t++)this._queue[t].nextIndex=0}push(t,e,s){if(s>=this._length)throw new Error("delay exceeds queue length");const i=this._indices[t];i<this._length&&this._queue[i].remove(t);const r=(this._nextIndex+s)%this._length;return this._queue[r].push(t,e),this._indices[t]=r,this}execute(t,e){const s=this._queue[this._nextIndex];this._nextIndex=(this._nextIndex+1)%this._length;for(let i=0;i<s.nextIndex;i++)t(s.addresses[i],s.values[i],e),this._indices[s.addresses[i]]=255;s.nextIndex=0}}class Ls{constructor(t){this.size=t,this.nextIndex=0,this.addresses=new Uint8Array(t),this.values=new Uint8Array(t)}push(t,e){if(this.nextIndex>=this.size)throw new Error("delay queue overflow");this.addresses[this.nextIndex]=t,this.values[this.nextIndex]=e,this.nextIndex++}remove(t){let e;for(e=0;e<this.nextIndex&&this.addresses[e]!==t;e++);e<this.nextIndex&&(this.addresses[e]=this.addresses[this.nextIndex-1],this.values[e]=this.values[this.nextIndex-1],this.nextIndex--)}}const Ds=new Uint32Array([4278190080,4283058762,4285493103,4287532686,4289374890,4290822336,4292269782,4293717228,4278208584,4279200105,4280125062,4280984226,4281711547,4282438354,4283099368,4283759868,4278201468,4279322768,4280378018,4281367220,4282224835,4283081938,4283807711,4284532972,4278197392,4279581091,4280832949,4282019014,4283073237,4284061667,4284984048,4285840636,4278190228,4279900839,4281479864,4282927304,4284243158,4285493220,4286611696,4287664380,4284743812,4286192023,4287574184,4288825016,4289944006,4290997460,4291984608,4292906220,4286840912,4288289128,4289540221,4290791058,4291844516,4292897973,4293819589,4294741204,4287627284,4288879155,4290064974,4291184744,4292172927,4293095317,4293951657,4294742204,4287889408,4289141272,4290261549,4291315778,4292238420,4293160805,4293951605,4294742148,4287110144,4288494360,4289746733,4290933314,4291988052,4292976741,4293899637,4294756484,4284755968,4286599192,4288179501,4289759298,4291141716,4292458341,4293643381,4294762628,4281352192,4283327e3,4285104429,4286750274,4288264276,4289646949,4290963317,4292148356,4278207488,4279920154,4281500722,4282949704,4284267100,4285518447,4286638208,4287691920,4278205460,4279787317,4281171538,4282555502,4283742087,4284862622,4285917108,4286905544,4278204464,4279654736,4281038445,4282290824,4283411360,4284465847,4285454540,4286377184,4278201416,4279520617,4280707718,4281894562,4282884027,4283872978,4284730600,4285587708]),Us=new Uint32Array([4278190080,4281019179,4283585106,4285953654,4288124823,4290164406,4292006610,4293717228,4278190080,4281019179,4283585106,4285953654,4288124823,4290164406,4292006610,4293717228,4278212736,4279923094,4281501611,4282948798,4284264399,4285513951,4286632430,4287684860,4278213700,4279925086,4281504630,4282952844,4284269216,4285519795,4286638788,4287691988,4278203504,4279914889,4281494432,4282942646,4284259017,4285509596,4286628588,4287681788,4279526400,4281696282,4283602994,4285444168,4287087964,4288600431,4290046848,4291361936,4279500912,4281670281,4283576992,4285417654,4287061193,4288573404,4290019564,4291334396,4284242944,4285953562,4287532594,4288980040,4290295900,4291545967,4292664448,4293717136,4284219504,4285799044,4287181462,4288563368,4289748151,4290867142,4291920083,4292907232,4285545472,4287191577,4288705839,4290154052,4291405143,4292655720,4293709433,4294762632,4285530200,4287175278,4288688771,4290136214,4291386535,4292636599,4293689542,4294742228,4285538304,4287184665,4288698927,4290147396,4291398487,4292649320,4293703033,4294756488,4286578740,4288027210,4289409631,4290660466,4291779715,4292833171,4293820578,4294742192,4287102976,4288485914,4289737266,4290922568,4291976284,4292964207,4293886080,4294742160,4278190080,4281019179,4283585106,4285953654,4288124823,4290164406,4292006610,4293717228,4278190080,4281019179,4283585106,4285953654,4288124823,4290164406,4292006610,4293717228]),js=new Uint32Array([4278190080,4294910241,4286135536,4294922495,4278255487,4294967167,4282384383,4294967295,4278190080,4294910241,4286135536,4294922495,4278255487,4294967167,4282384383,4294967295,4278190080,4294910241,4286135536,4294922495,4278255487,4294967167,4282384383,4294967295,4278190080,4294910241,4286135536,4294922495,4278255487,4294967167,4282384383,4294967295,4278190080,4294910241,4286135536,4294922495,4278255487,4294967167,4282384383,4294967295,4278190080,4294910241,4286135536,4294922495,4278255487,4294967167,4282384383,4294967295,4278190080,4294910241,4286135536,4294922495,4278255487,4294967167,4282384383,4294967295,4278190080,4294910241,4286135536,4294922495,4278255487,4294967167,4282384383,4294967295,4278190080,4294910241,4286135536,4294922495,4278255487,4294967167,4282384383,4294967295,4278190080,4294910241,4286135536,4294922495,4278255487,4294967167,4282384383,4294967295,4278190080,4294910241,4286135536,4294922495,4278255487,4294967167,4282384383,4294967295,4278190080,4294910241,4286135536,4294922495,4278255487,4294967167,4282384383,4294967295,4278190080,4294910241,4286135536,4294922495,4278255487,4294967167,4282384383,4294967295,4278190080,4294910241,4286135536,4294922495,4278255487,4294967167,4282384383,4294967295,4278190080,4294910241,4286135536,4294922495,4278255487,4294967167,4282384383,4294967295,4278190080,4294910241,4286135536,4294922495,4278255487,4294967167,4282384383,4294967295]);class Vs{constructor(t,e,s,i){this._config=t,this.newFrame=new n,this.trap=new n,this._cpu=null,this._bus=null,this._delayQueue=new Hs(10,20),this._hstate=0,this._hctr=0,this._collisionUpdateRequired=!1,this._movementClock=0,this._movementInProgress=!1,this._extendedHblank=!1,this._xDelta=0,this._linesSinceChange=0,this._maxLinesTotal=0,this._colorBk=4278190080,this._priority=0,this._collisionMask=0,this._player0=new Ts(31744,()=>this._flushLineCache()),this._player1=new Ts(17344,()=>this._flushLineCache()),this._missile0=new Ss(8760,()=>this._flushLineCache()),this._missile1=new Ss(4390,()=>this._flushLineCache()),this._playfield=new Ps(1099,()=>this._flushLineCache()),this._ball=new Es(2197,()=>this._flushLineCache()),this._waveformAudio=new Array(2),this._pcmAudio=null,this._audio=new Array(2),this._frameManager=new Os(this._config),this._frameManager.newFrame.addHandler(Vs._onNewFrame,this),this._palette=this._getPalette(this._config),this._input0=new Is(e.getFire()),this._input1=new Is(s.getFire()),this._pcmAudio=new As(this._config);const r=this._pcmAudio.getChannels();for(let t=0;t<2;t++)this._waveformAudio[t]=new ps(this._config),this._audio[t]=this._config.pcmAudio?r[t]:this._waveformAudio[t];const a=this._getClockFreq(this._config);this._paddles=new Array(4);for(let t=0;t<4;t++)this._paddles[t]=new Fs(a,i[t]);this.reset()}reset(){this._hctr=0,this._movementInProgress=!1,this._extendedHblank=!1,this._movementClock=0,this._priority=0,this._hstate=0,this._collisionMask=0,this._colorBk=4278190080,this._linesSinceChange=0,this._collisionUpdateRequired=!1,this._maxLinesTotal=0,this._xDelta=0,this._delayQueue.reset(),this._frameManager.reset(),this._missile0.reset(),this._missile1.reset(),this._player0.reset(),this._player1.reset(),this._playfield.reset(),this._ball.reset(),this._audio[0].reset(),this._audio[1].reset(),this._input0.reset(),this._input1.reset();for(let t=0;t<4;t++)this._paddles[t].reset();this._cpu&&this._cpu.resume()}setCpu(t){return this._cpu=t,this}setCpuTimeProvider(t){for(let e=0;e<4;e++)this._paddles[e].setCpuTimeProvider(t);return this}getWidth(){return 160}getHeight(){return this._frameManager.getHeight()}setSurfaceFactory(t){return this._frameManager.setSurfaceFactory(t),this}getWaveformChannel(t){return this._waveformAudio[t]}getPCMChannel(){return this._pcmAudio}setAudioEnabled(t){this._audio[0].setActive(t&&this._config.enableAudio),this._audio[1].setActive(t&&this._config.enableAudio)}read(t){const e=this._bus.getLastDataBusValue();let s;switch(15&t){case 8:s=(this._config.emulatePaddles?this._paddles[0].inpt():0)|64&e;break;case 9:s=(this._config.emulatePaddles?this._paddles[1].inpt():0)|64&e;break;case 10:s=(this._config.emulatePaddles?this._paddles[2].inpt():0)|64&e;break;case 11:s=(this._config.emulatePaddles?this._paddles[3].inpt():0)|64&e;break;case 12:s=this._input0.inpt()|64&e;break;case 13:s=this._input1.inpt()|64&e;break;case 0:s=(8192&this._collisionMask?64:0)|(512&this._collisionMask?128:0);break;case 1:s=(256&this._collisionMask?64:0)|(4096&this._collisionMask?128:0);break;case 2:s=(2048&this._collisionMask?64:0)|(1024&this._collisionMask?128:0);break;case 3:s=(128&this._collisionMask?64:0)|(64&this._collisionMask?128:0);break;case 4:s=(16&this._collisionMask?64:0)|(8&this._collisionMask?128:0);break;case 5:s=(4&this._collisionMask?64:0)|(2&this._collisionMask?128:0);break;case 7:s=(32&this._collisionMask?64:0)|(16384&this._collisionMask?128:0);break;case 6:s=1&this._collisionMask?128:0;break;default:s=0}return 192&s|63&e}peek(t){return this.read(t)}write(t,e){let s=0;switch(63&t){case 2:this._cpu.halt();break;case 3:this._flushLineCache(),this._rsync();break;case 0:this._frameManager.setVsync((2&e)>0);break;case 1:this._input0.vblank(e),this._input1.vblank(e);for(let t=0;t<4;t++)this._paddles[t].vblank(e);this._delayQueue.push(1,e,1);break;case 29:this._delayQueue.push(29,e,1);break;case 30:this._delayQueue.push(30,e,1);break;case 34:this._delayQueue.push(34,e,2);break;case 35:this._delayQueue.push(35,e,2);break;case 18:this._flushLineCache(),this._missile0.resm(this._resxCounter(),0===this._hstate);break;case 19:this._flushLineCache(),this._missile1.resm(this._resxCounter(),0===this._hstate);break;case 40:this._missile0.resmp(e,this._player0);break;case 41:this._missile1.resmp(e,this._player1);break;case 43:this._delayQueue.push(43,e,2);break;case 4:this._flushLineCache(),this._missile0.nusiz(e),this._player0.nusiz(e,0===this._hstate);break;case 5:this._flushLineCache(),this._missile1.nusiz(e),this._player1.nusiz(e,0===this._hstate);break;case 42:this._delayQueue.push(42,e,6);break;case 9:this._flushLineCache(),this._colorBk=this._palette[(255&e)>>>1];break;case 6:s=this._palette[(255&e)>>>1],this._missile0.setColor(s),this._player0.setColor(s),this._playfield.setColorP0(s);break;case 7:s=this._palette[(255&e)>>>1],this._missile1.setColor(s),this._player1.setColor(s),this._playfield.setColorP1(s);break;case 13:this._delayQueue.push(13,e,2);break;case 14:this._delayQueue.push(14,e,2);break;case 15:this._delayQueue.push(15,e,2);break;case 10:this._setPriority(e),this._playfield.ctrlpf(e),this._ball.ctrlpf(e);break;case 8:this._flushLineCache(),s=this._palette[(255&e)>>>1],this._playfield.setColor(s),this._ball.color=s;break;case 27:this._delayQueue.push(27,e,1).push(241,0,1);break;case 28:this._delayQueue.push(28,e,1).push(240,0,1).push(242,0,1);break;case 16:this._flushLineCache(),this._player0.resp(this._resxCounter());break;case 17:this._flushLineCache(),this._player1.resp(this._resxCounter());break;case 11:this._delayQueue.push(11,e,1);break;case 12:this._delayQueue.push(12,e,1);break;case 32:this._delayQueue.push(32,e,2);break;case 33:this._delayQueue.push(33,e,2);break;case 37:this._player0.vdelp(e);break;case 38:this._player1.vdelp(e);break;case 31:this._delayQueue.push(31,e,1);break;case 36:this._delayQueue.push(36,e,2);break;case 20:this._flushLineCache(),this._ball.resbl(this._resxCounter());break;case 39:this._ball.vdelbl(e);break;case 44:this._flushLineCache(),this._collisionMask=0;break;case 21:this._audio[0].audc(e);break;case 22:this._audio[1].audc(e);break;case 23:this._audio[0].audf(e);break;case 24:this._audio[1].audf(e);break;case 25:this._audio[0].audv(e);break;case 26:this._audio[1].audv(e)}}getDebugState(){return`hclock: ${this._hctr} line: ${this._frameManager.getCurrentLine()}\n`+this._frameManager.getDebugState()}setBus(t){return this._bus=t,this}cycle(){this._delayQueue.execute(Vs._delayedWrite,this),this._collisionUpdateRequired=!1,this._linesSinceChange<2?(this._tickMovement(),0===this._hstate?this._tickHblank():this._tickHframe(),this._collisionUpdateRequired&&!this._frameManager.vblank&&this._updateCollision()):0===this._hctr&&this._cpu.resume(),++this._hctr>=228&&this._nextLine(),this._config.pcmAudio&&this._pcmAudio.tick()}static _delayedWrite(t,e,s){switch(t){case 1:s._flushLineCache(),s._frameManager.setVblank((2&e)>0);break;case 42:s._flushLineCache(),s._movementClock=0,s._movementInProgress=!0,s._extendedHblank||(s._clearHmoveComb(),s._extendedHblank=!0),s._missile0.startMovement(),s._missile1.startMovement(),s._player0.startMovement(),s._player1.startMovement(),s._ball.startMovement();break;case 13:s._playfield.pf0(e);break;case 14:s._playfield.pf1(e);break;case 15:s._playfield.pf2(e);break;case 27:s._player0.grp(e);break;case 28:s._player1.grp(e);break;case 240:s._player0.shufflePatterns();break;case 241:s._player1.shufflePatterns();break;case 32:s._player0.hmp(e);break;case 33:s._player1.hmp(e);break;case 34:s._missile0.hmm(e);break;case 35:s._missile1.hmm(e);break;case 36:s._ball.hmbl(e);break;case 43:s._missile0.hmm(0),s._missile1.hmm(0),s._player0.hmp(0),s._player1.hmp(0),s._ball.hmbl(0);break;case 11:s._player0.refp(e);break;case 12:s._player1.refp(e);break;case 242:s._ball.shuffleStatus();break;case 31:s._ball.enabl(e);break;case 29:s._missile0.enam(e);break;case 30:s._missile1.enam(e)}}static _onNewFrame(t,e){const s=e._frameManager.getCurrentLine();if(s>e._maxLinesTotal&&(e._maxLinesTotal=s),s<e._maxLinesTotal){const i=t.getBuffer(),r=160*s,n=160*e._maxLinesTotal;for(let t=r;t<n;t++)i[t]=4278190080}e.newFrame.dispatch(t)}_tickMovement(){if(this._movementInProgress&&0==(3&this._hctr)){const t=0===this._hstate;let e=!1;const s=this._movementClock>15?0:this._movementClock;e=this._missile0.movementTick(s,t)||e,e=this._missile1.movementTick(s,t)||e,e=this._player0.movementTick(s,t)||e,e=this._player1.movementTick(s,t)||e,e=this._ball.movementTick(s,t)||e,this._movementInProgress=e,this._collisionUpdateRequired=e,this._movementClock++}}_tickHblank(){switch(this._hctr){case 0:this._extendedHblank=!1,this._cpu.resume();break;case 67:this._extendedHblank||(this._hstate=1);break;case 75:this._extendedHblank&&(this._hstate=1)}this._extendedHblank&&this._hctr>67&&this._playfield.tick(this._hctr-68+this._xDelta)}_tickHframe(){const t=this._frameManager.getCurrentLine(),e=this._hctr-68+this._xDelta;this._collisionUpdateRequired=!0,this._playfield.tick(e),this._tickSprites(),this._frameManager.isRendering()&&this._renderPixel(e,t)}_tickSprites(){this._missile0.tick(!0),this._missile1.tick(!0),this._player0.tick(),this._player1.tick(),this._ball.tick(!0)}_nextLine(){this._linesSinceChange>=2&&this._cloneLastLine(),this._hctr=0,this._playfield.tick(0),this._movementInProgress||this._linesSinceChange++,this._hstate=0,this._xDelta=0,this._frameManager.nextLine(),this._frameManager.isRendering()&&0===this._frameManager.getCurrentLine()&&this._flushLineCache()}_cloneLastLine(){const t=this._frameManager.getCurrentLine();if(!this._frameManager.isRendering()||0===t)return;const e=160*t,s=160*(t-1);for(let t=0;t<160;t++)this._frameManager.surfaceBuffer[e+t]=this._frameManager.surfaceBuffer[s+t]}_getPalette(t){switch(t.tvMode){case 0:return Ds;case 1:return Us;case 2:return js;default:throw new Error("invalid TV mode")}}_getClockFreq(t){return 0===t.tvMode?3584160:3556800}_renderPixel(t,e){if(this._frameManager.vblank)return void(this._frameManager.surfaceBuffer[160*e+t]=4278190080);let s=this._colorBk;switch(this._priority){case 0:s=this._playfield.getPixel(s),s=this._ball.getPixel(s),s=this._missile1.getPixel(s),s=this._player1.getPixel(s),s=this._missile0.getPixel(s),s=this._player0.getPixel(s);break;case 1:s=this._missile1.getPixel(s),s=this._player1.getPixel(s),s=this._missile0.getPixel(s),s=this._player0.getPixel(s),s=this._playfield.getPixel(s),s=this._ball.getPixel(s);break;case 2:s=this._ball.getPixel(s),s=this._missile1.getPixel(s),s=this._player1.getPixel(s),s=this._playfield.getPixel(s),s=this._missile0.getPixel(s),s=this._player0.getPixel(s);break;default:throw new Error("invalid priority")}this._frameManager.surfaceBuffer[160*e+t]=s}_updateCollision(){this._collisionMask|=~this._player0.collision&~this._player1.collision&~this._missile0.collision&~this._missile1.collision&~this._ball.collision&~this._playfield.collision}_clearHmoveComb(){if(this._frameManager.isRendering()&&0===this._hstate){const t=160*this._frameManager.getCurrentLine();for(let e=0;e<8;e++)this._frameManager.surfaceBuffer[t+e]=4278190080}}_resxCounter(){return 0===this._hstate?this._hctr>=73?158:159:157}_rsync(){const t=this._hctr>68?this._hctr-68:0;if(this._xDelta=157-t,this._frameManager.isRendering()){const e=this._frameManager.getCurrentLine(),s=160*e+t,i=s+160*(e+1);for(let t=s;t<i;t++)this._frameManager.surfaceBuffer[t]=4278190080}this._hctr=225}_setPriority(t){const e=4&t?1:2&t?2:0;e!==this._priority&&(this._flushLineCache(),this._priority=e)}_flushLineCache(){const t=this._linesSinceChange>=2;if(this._linesSinceChange=0,t){const t=this._hctr;for(this._hctr=0;this._hctr<t;this._hctr++)0===this._hstate?this._tickHblank():this._tickHframe()}}}!function(t){t.TrapPayload=class{constructor(t,e,s){this.reason=t,this.tia=e,this.message=s}}}(Vs||(Vs={}));class Qs{constructor(t=!1){this._state=t,this.stateChanged=new n,this.beforeRead=new n}read(){return this.beforeRead.dispatch(this),this._state}peek(){return this._state}toggle(t){this._state!==t&&(this._state=t,this.stateChanged.dispatch(t))}}class Ws{constructor(){this._selectSwitch=new Qs,this._resetButton=new Qs,this._colorSwitch=new Qs,this._difficutlyP0=new Qs,this._difficutlyP1=new Qs}getSelectSwitch(){return this._selectSwitch}getResetButton(){return this._resetButton}getColorSwitch(){return this._colorSwitch}getDifficultySwitchP0(){return this._difficutlyP0}getDifficultySwitchP1(){return this._difficutlyP1}}class zs{constructor(){this._left=new Qs,this._right=new Qs,this._up=new Qs,this._down=new Qs,this._fire=new Qs}getLeft(){return this._left}getRight(){return this._right}getUp(){return this._up}getDown(){return this._down}getFire(){return this._fire}}class Js{constructor(){this.valueChanged=new n,this._fireSwitch=new Qs,this._value=.5}setValue(t){this._value=t,this.valueChanged.dispatch(t)}getValue(){return this._value}getFire(){return this._fireSwitch}}var Ys=s((function(t){!function(t,e,s){function i(t){var e,s=this,i=(e=4022871197,function(t){t=String(t);for(var s=0;s<t.length;s++){var i=.02519603282416938*(e+=t.charCodeAt(s));i-=e=i>>>0,e=(i*=e)>>>0,e+=4294967296*(i-=e)}return 2.3283064365386963e-10*(e>>>0)});s.next=function(){var t=2091639*s.s0+2.3283064365386963e-10*s.c;return s.s0=s.s1,s.s1=s.s2,s.s2=t-(s.c=0|t)},s.c=1,s.s0=i(" "),s.s1=i(" "),s.s2=i(" "),s.s0-=i(t),s.s0<0&&(s.s0+=1),s.s1-=i(t),s.s1<0&&(s.s1+=1),s.s2-=i(t),s.s2<0&&(s.s2+=1),i=null}function r(t,e){return e.c=t.c,e.s0=t.s0,e.s1=t.s1,e.s2=t.s2,e}function n(t,e){var s=new i(t),n=e&&e.state,a=s.next;return a.int32=function(){return 4294967296*s.next()|0},a.double=function(){return a()+11102230246251565e-32*(2097152*a()|0)},a.quick=a,n&&("object"==typeof n&&r(n,s),a.state=function(){return r(s,{})}),a}e&&e.exports?e.exports=n:s&&s.amd?s((function(){return n})):this.alea=n}(0,t,!1)})),qs=s((function(t){!function(t,e,s){function i(t){var e=this,s="";e.x=0,e.y=0,e.z=0,e.w=0,e.next=function(){var t=e.x^e.x<<11;return e.x=e.y,e.y=e.z,e.z=e.w,e.w^=e.w>>>19^t^t>>>8},t===(0|t)?e.x=t:s+=t;for(var i=0;i<s.length+64;i++)e.x^=0|s.charCodeAt(i),e.next()}function r(t,e){return e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w,e}function n(t,e){var s=new i(t),n=e&&e.state,a=function(){return(s.next()>>>0)/4294967296};return a.double=function(){do{var t=((s.next()>>>11)+(s.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},a.int32=s.next,a.quick=a,n&&("object"==typeof n&&r(n,s),a.state=function(){return r(s,{})}),a}e&&e.exports?e.exports=n:s&&s.amd?s((function(){return n})):this.xor128=n}(0,t,!1)})),Ns=s((function(t){!function(t,e,s){function i(t){var e=this,s="";e.next=function(){var t=e.x^e.x>>>2;return e.x=e.y,e.y=e.z,e.z=e.w,e.w=e.v,(e.d=e.d+362437|0)+(e.v=e.v^e.v<<4^t^t<<1)|0},e.x=0,e.y=0,e.z=0,e.w=0,e.v=0,t===(0|t)?e.x=t:s+=t;for(var i=0;i<s.length+64;i++)e.x^=0|s.charCodeAt(i),i==s.length&&(e.d=e.x<<10^e.x>>>4),e.next()}function r(t,e){return e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w,e.v=t.v,e.d=t.d,e}function n(t,e){var s=new i(t),n=e&&e.state,a=function(){return(s.next()>>>0)/4294967296};return a.double=function(){do{var t=((s.next()>>>11)+(s.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},a.int32=s.next,a.quick=a,n&&("object"==typeof n&&r(n,s),a.state=function(){return r(s,{})}),a}e&&e.exports?e.exports=n:s&&s.amd?s((function(){return n})):this.xorwow=n}(0,t,!1)})),Xs=s((function(t){!function(t,e,s){function i(t){var e=this;e.next=function(){var t,s,i=e.x,r=e.i;return t=i[r],s=(t^=t>>>7)^t<<24,s^=(t=i[r+1&7])^t>>>10,s^=(t=i[r+3&7])^t>>>3,s^=(t=i[r+4&7])^t<<7,t=i[r+7&7],s^=(t^=t<<13)^t<<9,i[r]=s,e.i=r+1&7,s},function(t,e){var s,i=[];if(e===(0|e))i[0]=e;else for(e=""+e,s=0;s<e.length;++s)i[7&s]=i[7&s]<<15^e.charCodeAt(s)+i[s+1&7]<<13;for(;i.length<8;)i.push(0);for(s=0;s<8&&0===i[s];++s);for(8==s?i[7]=-1:i[s],t.x=i,t.i=0,s=256;s>0;--s)t.next()}(e,t)}function r(t,e){return e.x=t.x.slice(),e.i=t.i,e}function n(t,e){null==t&&(t=+new Date);var s=new i(t),n=e&&e.state,a=function(){return(s.next()>>>0)/4294967296};return a.double=function(){do{var t=((s.next()>>>11)+(s.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},a.int32=s.next,a.quick=a,n&&(n.x&&r(n,s),a.state=function(){return r(s,{})}),a}e&&e.exports?e.exports=n:s&&s.amd?s((function(){return n})):this.xorshift7=n}(0,t,!1)})),Gs=s((function(t){!function(t,e,s){function i(t){var e=this;e.next=function(){var t,s,i=e.w,r=e.X,n=e.i;return e.w=i=i+1640531527|0,s=r[n+34&127],t=r[n=n+1&127],s^=s<<13,t^=t<<17,s^=s>>>15,t^=t>>>12,s=r[n]=s^t,e.i=n,s+(i^i>>>16)|0},function(t,e){var s,i,r,n,a,h=[],o=128;for(e===(0|e)?(i=e,e=null):(e+="\0",i=0,o=Math.max(o,e.length)),r=0,n=-32;n<o;++n)e&&(i^=e.charCodeAt((n+32)%e.length)),0===n&&(a=i),i^=i<<10,i^=i>>>15,i^=i<<4,i^=i>>>13,n>=0&&(a=a+1640531527|0,r=0==(s=h[127&n]^=i+a)?r+1:0);for(r>=128&&(h[127&(e&&e.length||0)]=-1),r=127,n=512;n>0;--n)i=h[r+34&127],s=h[r=r+1&127],i^=i<<13,s^=s<<17,i^=i>>>15,s^=s>>>12,h[r]=i^s;t.w=a,t.X=h,t.i=r}(e,t)}function r(t,e){return e.i=t.i,e.w=t.w,e.X=t.X.slice(),e}function n(t,e){null==t&&(t=+new Date);var s=new i(t),n=e&&e.state,a=function(){return(s.next()>>>0)/4294967296};return a.double=function(){do{var t=((s.next()>>>11)+(s.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},a.int32=s.next,a.quick=a,n&&(n.X&&r(n,s),a.state=function(){return r(s,{})}),a}e&&e.exports?e.exports=n:s&&s.amd?s((function(){return n})):this.xor4096=n}(0,t,!1)})),Ks=s((function(t){!function(t,e,s){function i(t){var e=this,s="";e.next=function(){var t=e.b,s=e.c,i=e.d,r=e.a;return t=t<<25^t>>>7^s,s=s-i|0,i=i<<24^i>>>8^r,r=r-t|0,e.b=t=t<<20^t>>>12^s,e.c=s=s-i|0,e.d=i<<16^s>>>16^r,e.a=r-t|0},e.a=0,e.b=0,e.c=-1640531527,e.d=1367130551,t===Math.floor(t)?(e.a=t/4294967296|0,e.b=0|t):s+=t;for(var i=0;i<s.length+20;i++)e.b^=0|s.charCodeAt(i),e.next()}function r(t,e){return e.a=t.a,e.b=t.b,e.c=t.c,e.d=t.d,e}function n(t,e){var s=new i(t),n=e&&e.state,a=function(){return(s.next()>>>0)/4294967296};return a.double=function(){do{var t=((s.next()>>>11)+(s.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},a.int32=s.next,a.quick=a,n&&("object"==typeof n&&r(n,s),a.state=function(){return r(s,{})}),a}e&&e.exports?e.exports=n:s&&s.amd?s((function(){return n})):this.tychei=n}(0,t,!1)})),Zs={},$s=s((function(e){!function(t,s,i){var r,n=256,a=i.pow(n,6),h=i.pow(2,52),o=2*h,c=255;function u(e,c,u){var g=[],b=f(d((c=1==c?{entropy:!0}:c||{}).entropy?[e,p(s)]:null==e?function(){try{var e;return r&&(e=r.randomBytes)?e=e(n):(e=new Uint8Array(n),(t.crypto||t.msCrypto).getRandomValues(e)),p(e)}catch(e){var i=t.navigator,a=i&&i.plugins;return[+new Date,t,a,t.screen,p(s)]}}():e,3),g),A=new l(g),m=function(){for(var t=A.g(6),e=a,s=0;t<h;)t=(t+s)*n,e*=n,s=A.g(1);for(;t>=o;)t/=2,e/=2,s>>>=1;return(t+s)/e};return m.int32=function(){return 0|A.g(4)},m.quick=function(){return A.g(4)/4294967296},m.double=m,f(p(A.S),s),(c.pass||u||function(t,e,s,r){return r&&(r.S&&_(r,A),t.state=function(){return _(A,{})}),s?(i.random=t,e):t})(m,b,"global"in c?c.global:this==i,c.state)}function l(t){var e,s=t.length,i=this,r=0,a=i.i=i.j=0,h=i.S=[];for(s||(t=[s++]);r<n;)h[r]=r++;for(r=0;r<n;r++)h[r]=h[a=c&a+t[r%s]+(e=h[r])],h[a]=e;(i.g=function(t){for(var e,s=0,r=i.i,a=i.j,h=i.S;t--;)e=h[r=c&r+1],s=s*n+h[c&(h[r]=h[a=c&a+e])+(h[a]=e)];return i.i=r,i.j=a,s})(n)}function _(t,e){return e.i=t.i,e.j=t.j,e.S=t.S.slice(),e}function d(t,e){var s,i=[],r=typeof t;if(e&&"object"==r)for(s in t)try{i.push(d(t[s],e-1))}catch(t){}return i.length?i:"string"==r?t:t+"\0"}function f(t,e){for(var s,i=t+"",r=0;r<i.length;)e[c&r]=c&(s^=19*e[c&r])+i.charCodeAt(r++);return p(e)}function p(t){return String.fromCharCode.apply(0,t)}if(f(i.random(),s),e.exports){e.exports=u;try{r=Zs}catch(t){}}else i.seedrandom=u}("undefined"!=typeof self?self:t,[],Math)}));$s.alea=Ys,$s.xor128=qs,$s.xorwow=Ns,$s.xorshift7=Xs,$s.xor4096=Gs,$s.tychei=Ks;var ti,ei,si=$s;class ii{constructor(t){this._rng=t}single(){return this._rng.quick()}double(){return this._rng.double()}int32(){return this._rng.int32()}int(t){return(this._rng.int32()>>>0)%(t+1)}saveState(){return this._rng.state()}}class ri{constructor(t,e,s){var i;this._config=t,this.trap=new n,this.clock=new n,this.cpuClock=new n,this.systemReset=new n,this._clockMode=1,this._cpuCycles=0,this._trap=!1,this._audioEnabled=!0,this._suspended=!0,this._subClock=0,this._clockHz=0,this._sliceSize=0,this._timer={tick:t=>this.tick(t),start:t=>this._start(t),stop:()=>this._stop(),isRunning:()=>!!this._runTask},this._rng=((i=t.randomSeed<0?Math.random():t.randomSeed)<0&&(i=Math.random()),new ii(si.alea(i,{state:!0}))),e.randomize(this._rng);const r=new P;void 0===s&&(s=(e,s)=>new ts(t.cpuType).create(e,s));const a=new Ws,h=new zs,o=new zs,c=new Array(4);for(let t=0;t<4;t++)c[t]=new Js;const u=s(r,this._rng),l=new T(a,h,o,this._rng),_=new Vs(t,h,o,c);u.setInvalidInstructionCallback(()=>this._onInvalidInstruction()),_.setCpu(u).setBus(r).setCpuTimeProvider(()=>this.getCpuTime()),e.setCpu(u).setBus(r).setCpuTimeProvider(()=>this.getCpuTime()).setRng(this._rng),l.setBus(r),r.setTia(_).setPia(l).setCartridge(e),this._bus=r,this._cpu=u,this._tia=_,this._pia=l,this._cartridge=e,this._controlPanel=a,this._joystick0=h,this._joystick1=o,this._paddles=c,this._bus.event.trap.addHandler(t=>this.triggerTrap(1,t.message)),this._clockHz=$e.getClockHz(t),this._sliceSize=228*(0===t.tvMode?262:312),this.reset()}getCpu(){return this._cpu}getBus(){return this._bus}getVideoOutput(){return this._tia}getWaveformChannels(){return[0,1].map(t=>this._tia.getWaveformChannel(t))}getPCMChannel(){return this._tia.getPCMChannel()}getTimer(){return this._timer}getConfig(){return this._config}reset(){return this._cpu.reset(),this._tia.reset(),this._pia.reset(),this._cartridge.reset(),this._controlPanel.getResetButton().toggle(!1),this._controlPanel.getSelectSwitch().toggle(!1),this._controlPanel.getColorSwitch().toggle(!1),this._controlPanel.getDifficultySwitchP0().toggle(!0),this._controlPanel.getDifficultySwitchP1().toggle(!0),this._subClock=0,this._cpuCycles=0,this.systemReset.dispatch(),this}boot(){let t=0,e=0;if(this.reset(),0!==this._cpu.executionState)throw new Error("Already booted!");for(;1!==this._cpu.executionState;)this._cycle(),t++,0===this._subClock&&e++;return this.cpuClock.dispatch(e),this.clock.dispatch(t),this}suspend(){this._suspended=!0,this._updateAudioState()}resume(){this._suspended=!1,this._updateAudioState()}setAudioEnabled(t){this._audioEnabled=t,this._updateAudioState()}triggerTrap(t,e){if(this._stop(),this._trap=!0,!this.trap.hasHandlers)throw new Error(e);return this.trap.dispatch(new b.TrapPayload(t,this,e)),this}getControlPanel(){return this._controlPanel}getJoystick0(){return this._joystick0}getJoystick1(){return this._joystick1}getBoardStateDebug(){const t="============";return"TIA:\n"+t+"\n"+this._tia.getDebugState()+"\n\nPIA:\n"+t+"\n"+this._pia.getDebugState()+"\n"}setClockMode(t){return this._clockMode=t,this}getClockMode(){return this._clockMode}getPaddle(t){return this._paddles[t]}getCpuTime(){return this._cpuCycles/$e.getClockHz(this._config)*3}tick(t){let e=0,s=0,i=0,r=this._cpu.executionState;for(this._trap=!1;e++<t&&!this._trap;)this._cycle(),s++,0===this._subClock&&(i++,this._cpuCycles++),r!==this._cpu.executionState&&(r=this._cpu.executionState,1===this._cpu.executionState&&(this._cartridge.notifyCpuCycleComplete(),0===this._clockMode&&i>0&&this.cpuClock.hasHandlers&&(this.cpuClock.dispatch(i),i=0)));return i>0&&this.cpuClock.hasHandlers&&this.cpuClock.dispatch(i),s>0&&this.clock.hasHandlers&&this.clock.dispatch(s),s}getSubclock(){return this._subClock}static _executeSlice(t,e){const s=e?Math.round(e*t._clockHz/1e3):t._sliceSize;return t.tick(s)/t._clockHz*1e3}_updateAudioState(){this._tia.setAudioEnabled(this._audioEnabled&&!this._suspended)}_cycle(){this._tia.cycle(),this._subClock++>=2&&(this._pia.cycle(),this._cpu.cycle(),this._subClock=0)}_start(t){this._runTask||(this._runTask=t.start(ri._executeSlice,this,1e3/(0===this._config.tvMode?60:50)))}_stop(){this._runTask&&(this._runTask.stop(),this._runTask=void 0)}_onInvalidInstruction(){this.triggerTrap(0,"invalid instruction")}}!function(t){t.TrapPayload=class{constructor(t,e,s){this.reason=t,this.cartridge=e,this.message=s}}}(ti||(ti={})),function(t){let e;!function(t){t.vanilla_2k="vanilla_2k",t.vanilla_4k="vanilla_4k",t.bankswitch_2k_cv="bankswitch_2k_cv",t.bankswitch_8k_F8="bankswitch_8k_F8",t.bankswitch_8k_E0="bankswitch_8k_E0",t.bankswitch_8k_3F="bankswitch_8k_3F",t.bankswitch_8k_FE="bankswitch_8k_FE",t.bankswitch_8k_UA="bankswitch_8k_UA",t.bankswitch_8k_DPC="bankswitch_8k_DPC",t.bankswitch_8k_econobanking="bankswitch_8k_econobanking",t.bankswitch_8k_pp="bankswitch_8k_pp",t.bankswitch_12k_FA="bankswitch_12k_FA",t.bankswitch_16k_F6="bankswitch_16k_F6",t.bankswitch_16k_E7="bankswitch_16k_E7",t.bankswitch_FA2="bankswitch_FA2",t.bankswitch_32k_F4="bankswitch_32k_F4",t.bankswitch_64k_F0="bankswitch_64k_F0",t.bankswitch_64k_EF="bankswitch_64k_EF",t.bankswitch_3E="bankswitch_3E",t.bankswitch_supercharger="bankswitch_supercharger",t.bankswitch_dpc_plus="bankswitch_dpc_plus",t.bankswitch_cdf="bankswitch_cdf",t.unknown="unknown"}(e=t.CartridgeType||(t.CartridgeType={})),t.getAllTypes=function(){return[e.vanilla_2k,e.vanilla_4k,e.bankswitch_2k_cv,e.bankswitch_8k_F8,e.bankswitch_8k_E0,e.bankswitch_8k_3F,e.bankswitch_8k_FE,e.bankswitch_8k_UA,e.bankswitch_8k_econobanking,e.bankswitch_8k_pp,e.bankswitch_12k_FA,e.bankswitch_8k_DPC,e.bankswitch_16k_F6,e.bankswitch_16k_E7,e.bankswitch_FA2,e.bankswitch_32k_F4,e.bankswitch_3E,e.bankswitch_64k_F0,e.bankswitch_64k_EF,e.bankswitch_supercharger,e.bankswitch_dpc_plus,e.bankswitch_cdf,e.unknown]},t.describeCartridgeType=function(t){switch(t){case e.vanilla_2k:return"plain 2k";case e.vanilla_4k:return"plain 4k";case e.bankswitch_2k_cv:return"2k CommaVideo scheme";case e.bankswitch_8k_F8:return"bankswitched 8k, F8 (Atari) scheme";case e.bankswitch_8k_E0:return"bankswitched 8k, E0 (Parker Bros.) scheme";case e.bankswitch_8k_3F:return"bankswitched 8k, 3F (Tigervision) scheme";case e.bankswitch_8k_FE:return"bankswitched 8k, FE (Activision) scheme";case e.bankswitch_8k_UA:return"bankswitched 8k, UA (Pleiades) scheme";case e.bankswitch_8k_pp:return"bankswitched 8k, Pink Panther scheme";case e.bankswitch_12k_FA:return"bankswitched 12k, FA (CBS) scheme";case e.bankswitch_8k_DPC:return"bankswitched 8k + DPC";case e.bankswitch_8k_econobanking:return"bankswitched 8k, econobanking scheme";case e.bankswitch_16k_F6:return"bankswitched 16k, F6 (Atari) scheme";case e.bankswitch_16k_E7:return"bankswitched 16k, E7 (M-Network) scheme";case e.bankswitch_FA2:return"bankswitched 28k/29k, FA2 (modified CBS) scheme";case e.bankswitch_32k_F4:return"bankswitched 32k, F4 (Atari) scheme";case e.bankswitch_3E:return"bankswitched 3E (Tigervision + RAM) scheme";case e.bankswitch_64k_F0:return"bankswitched 64k, F0 (Megaboy) scheme";case e.bankswitch_64k_EF:return"bankswitched 64k, EFSC (Homestar Runner) scheme";case e.bankswitch_supercharger:return"bankswitched supercharger";case e.bankswitch_dpc_plus:return"bankswitched DPC+";case e.bankswitch_cdf:return"bankswitched CDF";case e.unknown:return"unknown"}}}(ei||(ei={}));class ni{constructor(){this.trap=new n}init(){return f(this,void 0,void 0,(function*(){}))}reset(){}read(t){return 0}peek(t){return this.read(t)}write(t,e){}getType(){return ei.CartridgeType.unknown}setCpu(t){return this}setBus(t){return this}setRng(t){return this}setCpuTimeProvider(t){return this}notifyCpuCycleComplete(){}randomize(t){}triggerTrap(t,e){if(!this.trap.hasHandlers)throw new Error(e);this.trap.dispatch(new ti.TrapPayload(t,this,e))}}class ai extends ni{constructor(t){if(super(),this._rom=new Uint8Array(2048),t.length>2048)throw new Error("buffer is not a 2k cartridge image: wrong length "+t.length);const e=function(t){const e=function(t){let e=1;for(;e<t;)e*=2;return e}(t.length);if(e===t.length)return t;const s=new Uint8Array(e);for(let i=0;i<e;i++)s[e-i-1]=i<t.length?t[t.length-i-1]:0;return s}(t);for(let s=0;s<2048;s++)this._rom[s]=t[s%e.length]}read(t){return this._rom[2047&t]}getType(){return ei.CartridgeType.vanilla_2k}}class hi extends ni{constructor(t){super(),this._rom=new Uint8Array(4096),4096!==t.length&&console.warn(`buffer has invalid size for 4K image: ${t.length} bytes`);const e=Math.min(4096,t.length);for(let s=0;s<4096&&s<t.length;s++)this._rom[4095-s]=t[e-1-s]}read(t){return this._rom[4095&t]}getType(){return ei.CartridgeType.vanilla_4k}}function oi(t,e){const s=[],i=e.map(t=>0);for(let r=0;r<t.length;r++){for(let n=0;n<s.length;n++){const a=s[n],h=e[a.signature];t[r]===h[a.nextIndex]?++a.nextIndex===h.length&&(i[a.signature]++,s.splice(n,1),n--):(s.splice(n,1),n--)}for(let n=0;n<e.length;n++){const a=e[n];a.length>0&&t[r]===a[0]&&(1===a.length?i[n]++:s.push({signature:n,nextIndex:1}))}}return i}class ci extends ni{constructor(t){if(super(),this._rom=new Uint8Array(2048),this._ram=new Uint8Array(1024),2048!==t.length)throw new Error("buffer is not a 2k cartridge image: wrong length "+t.length);for(let e=0;e<2048;e++)this._rom[e]=t[e]}static matchesBuffer(t){const e=oi(t,[[157,255,243],[153,0,244]]);return e[0]>0||e[1]>0}setBus(t){return this._bus=t,this}randomize(t){for(let e=0;e<1024;e++)this._ram[e]=t.int(255)}read(t){return(t&=4095)<1024?this._ram[t]:t<2048?this._ram[1023&t]=this._bus.getLastDataBusValue():this._rom[2047&t]}write(t,e){(t&=4095)>=1024&&t<2048&&(this._ram[1023&t]=e)}peek(t){return(t&=4095)<1024?this._ram[t]:t<2048?0:this._rom[2047&t]}getType(){return ei.CartridgeType.bankswitch_2k_cv}}class ui extends ni{constructor(t,e=!0){if(super(),this._supportSC=e,this._bank=null,this._bank0=new Uint8Array(4096),this._bank1=new Uint8Array(4096),this._hasSC=!1,this._saraRAM=new Uint8Array(128),this._bus=null,8192!==t.length)throw new Error("buffer is not an 8k cartridge image: wrong length "+t.length);for(let e=0;e<4096;e++)this._bank0[e]=t[e],this._bank1[e]=t[4096+e];this.reset()}static matchesBuffer(t){return oi(t,[[141,249,31]])[0]>=2}reset(){this._bank=this._bank1,this._hasSC=!1}read(t){return this._access(4095&t,this._bus.getLastDataBusValue()),this.peek(t)}peek(t){return t&=4095,this._hasSC&&t>=128&&t<256?this._saraRAM[t-128]:this._bank[t]}write(t,e){(t&=4095)<128&&this._supportSC&&(this._hasSC=!0),this._access(t,e)}getType(){return ei.CartridgeType.bankswitch_8k_F8}randomize(t){for(let e=0;e<this._saraRAM.length;e++)this._saraRAM[e]=t.int(255)}setBus(t){return this._bus=t,this}_access(t,e){if(t<128&&this._hasSC)this._saraRAM[t]=255&e;else switch(t){case 4088:this._bank=this._bank0;break;case 4089:this._bank=this._bank1}}}class li extends ni{constructor(t,e=!0){if(super(),this._supportSC=e,this._bank=null,this._bank0=new Uint8Array(4096),this._bank1=new Uint8Array(4096),this._bank2=new Uint8Array(4096),this._bank3=new Uint8Array(4096),this._hasSC=!1,this._saraRAM=new Uint8Array(128),this._bus=null,16384!==t.length)throw new Error("buffer is not a 16k cartridge image: wrong length "+t.length);for(let e=0;e<4096;e++)this._bank0[e]=t[e],this._bank1[e]=t[4096+e],this._bank2[e]=t[8192+e],this._bank3[e]=t[12288+e];this.reset()}reset(){this._bank=this._bank0,this._hasSC=!1}read(t){return this._access(4095&t,this._bus.getLastDataBusValue()),this.peek(t)}peek(t){return t&=4095,this._hasSC&&t>=128&&t<256?this._saraRAM[t-128]:this._bank[t]}write(t,e){(t&=4095)<128&&this._supportSC&&(this._hasSC=!0),this._access(t,e)}getType(){return ei.CartridgeType.bankswitch_16k_F6}randomize(t){for(let e=0;e<this._saraRAM.length;e++)this._saraRAM[e]=t.int(255)}setBus(t){return this._bus=t,this}_access(t,e){if(t<128&&this._hasSC)this._saraRAM[t]=255&e;else switch(t){case 4086:this._bank=this._bank0;break;case 4087:this._bank=this._bank1;break;case 4088:this._bank=this._bank2;break;case 4089:this._bank=this._bank3}}}class _i extends ni{constructor(t){if(super(),this._banks=new Array(8),this._activeBanks=new Array(4),8192!==t.length)throw new Error("buffer is not an 8k cartridge image: invalid length "+t.length);for(let t=0;t<8;t++)this._banks[t]=new Uint8Array(1024);for(let e=0;e<1024;e++)for(let s=0;s<8;s++)this._banks[s][e]=t[1024*s+e];this.reset()}static matchesBuffer(t){const e=oi(t,[[141,224,31],[141,224,95],[141,233,255],[12,224,31],[173,224,31],[173,233,255],[173,237,255],[173,243,191]]);for(let t=0;t<e.length;t++)if(e[t]>0)return!0;return!1}reset(){for(let t=0;t<4;t++)this._activeBanks[t]=this._banks[7]}read(t){return(t&=4095)>=4064&&t<4088&&this._handleBankswitch(t),this._activeBanks[t>>10][1023&t]}peek(t){return t&=4095,this._activeBanks[t>>10][1023&t]}write(t,e){const s=4095&t;return s>=4064&&s<4088&&this._handleBankswitch(s),super.write(t,e)}getType(){return ei.CartridgeType.bankswitch_8k_E0}_handleBankswitch(t){t<4072?this._activeBanks[0]=this._banks[t-4064]:t<4080?this._activeBanks[1]=this._banks[t-4072]:this._activeBanks[2]=this._banks[t-4080]}}class di extends ni{constructor(t){if(super(),this._bank0=new Uint8Array(4096),this._bank1=new Uint8Array(4096),this._lastAccessWasFE=!1,this._lastAddressBusValue=-1,8192!==t.length)throw new Error("buffer is not an 8k cartridge image: wrong length "+t.length);for(let e=0;e<4096;e++)this._bank0[e]=t[e],this._bank1[e]=t[4096+e];this.reset()}static matchesBuffer(t){const e=oi(t,[[32,0,208,198,197],[32,195,248,165,130],[208,251,32,115,254],[32,0,240,132,214]]);for(let t=0;t<e.length;t++)if(e[t]>0)return!0;return!1}reset(){this._bank=this._bank0,this._lastAccessWasFE=!1,this._lastAddressBusValue=-1}read(t){return this._bank[4095&t]}write(t,e){super.write(t,e)}setBus(t){return this._bus=t,this._bus.event.read.addHandler(di._onBusAccess,this),this._bus.event.write.addHandler(di._onBusAccess,this),this}getType(){return ei.CartridgeType.bankswitch_8k_FE}static _onBusAccess(t,e){const s=e._lastAddressBusValue;if(e._lastAddressBusValue=8191&e._bus.getLastAddresBusValue(),e._lastAddressBusValue!==s){if(e._lastAccessWasFE){const t=224&e._bus.getLastDataBusValue();e._bank=0===t||(32&e._bus.getLastDataBusValue())>0?e._bank0:e._bank1}e._lastAccessWasFE=510===e._lastAddressBusValue}}}class fi extends ni{constructor(t){if(super(),this._banks=new Array(4),this._bus=null,8192!==t.length)throw new Error("buffer is not an 8k cartridge image: invalid length "+t.length);for(let t=0;t<4;t++)this._banks[t]=new Uint8Array(2048);this._bank1=this._banks[3],this._bank0=this._banks[0];for(let e=0;e<2048;e++)for(let s=0;s<4;s++)this._banks[s][e]=t[2048*s+e]}static matchesBuffer(t){return oi(t,[[133,63]])[0]>=2}reset(){this._bank0=this._banks[0]}setBus(t){return this._bus=t,this._bus.event.read.addHandler(fi._onBusAccess,this),this._bus.event.write.addHandler(fi._onBusAccess,this),this}read(t){return(t&=4095)<2048?this._bank0[t]:this._bank1[2047&t]}getType(){return ei.CartridgeType.bankswitch_8k_3F}static _onBusAccess(t,e){63===e._bus.getLastAddresBusValue()&&(e._bank0=e._banks[3&e._bus.getLastDataBusValue()])}}class pi extends ni{constructor(t){if(super(),this._banks=null,this._ramSelect=!1,this._ramBanks=new Array(256),this._bus=null,0!=(2047&t.length))throw new Error(`buffer length ${t.length} is not a multiple of 2k`);const e=t.length>>>11;if(e<2)throw new Error("image must have at least 2k");this._banks=new Array(e);for(let t=0;t<e;t++)this._banks[t]=new Uint8Array(2048);for(let t=0;t<=255;t++)this._ramBanks[t]=new Uint8Array(1024);this._ramBank=this._ramBanks[0],this._bank1=this._banks[e-1],this._bank0=this._banks[0];for(let s=0;s<2048;s++)for(let i=0;i<e;i++)this._banks[i][s]=t[2048*i+s]}static matchesBuffer(t){return oi(t,[[133,62,169,0]])[0]>=1}reset(){this._bank0=this._banks[0]}randomize(t){for(let e=0;e<this._ramBanks.length;e++)for(let s=0;s<1024;s++)this._ramBanks[e][s]=t.int(255)}setBus(t){return this._bus=t,this._bus.event.read.addHandler(pi._onBusAccess,this),this._bus.event.write.addHandler(pi._onBusAccess,this),this}read(t){return t&=4095,this._ramSelect?t<1024?this._ramBank[t]:t<2048?this._ramBank[1023&t]=this._bus.getLastDataBusValue():this._bank1[2047&t]:t<2048?this._bank0[t]:this._bank1[2047&t]}peek(t){return t&=4095,this._ramSelect?t<1024?this._ramBank[t]:t<2048?this._bus.getLastDataBusValue():this._bank1[2047&t]:t<2048?this._bank0[t]:this._bank1[2047&t]}write(t,e){this._ramSelect&&(t&=4095)>=1024&&t<2048&&(this._ramBank[1023&t]=e)}getType(){return ei.CartridgeType.bankswitch_3E}static _onBusAccess(t,e){switch(e._bus.getLastAddresBusValue()){case 63:e._ramSelect=!1,e._bank0=e._banks[e._bus.getLastDataBusValue()%e._banks.length];break;case 62:e._ramSelect=!0,e._ramBank=e._ramBanks[e._bus.getLastDataBusValue()%32]}}}class gi extends ni{constructor(t){if(super(),this._bus=null,this._bank=null,this._bank0=new Uint8Array(4096),this._bank1=new Uint8Array(4096),8192!==t.length)throw new Error("buffer is not an 8k cartridge image: wrong length "+t.length);for(let e=0;e<4096;e++)this._bank0[e]=t[e],this._bank1[e]=t[4096+e];this.reset()}static matchesBuffer(t){const e=oi(t,[[141,64,2],[173,64,2],[189,31,2]]);for(let t=0;t<e.length;t++)if(e[t]>0)return!0;return!1}reset(){this._bank=this._bank0}read(t){return this._bank[4095&t]}setBus(t){return this._bus=t,t.event.read.addHandler(gi._onBusAccess,this),t.event.write.addHandler(gi._onBusAccess,this),this}getType(){return ei.CartridgeType.bankswitch_8k_UA}static _onBusAccess(t,e){switch(e._bus.getLastAddresBusValue()){case 544:e._bank=e._bank0;break;case 576:e._bank=e._bank1}}}class bi extends ni{constructor(t){if(super(),this._bank0=new Uint8Array(4096),this._bank1=new Uint8Array(4096),this._bank2=new Uint8Array(4096),this._ram=new Uint8Array(256),12288!==t.length)throw new Error("buffer is not a 12k cartridge image: wrong length "+t.length);for(let e=0;e<4096;e++)this._bank0[e]=t[e],this._bank1[e]=t[4096+e],this._bank2[e]=t[8192+e];this.reset()}reset(){this._bank=this._bank0}randomize(t){for(let e=0;e<this._ram.length;e++)this._ram[e]=t.int(255)}read(t){return this._handleBankswitch(4095&t),this.peek(t)}peek(t){return(t&=4095)>=256&&t<512?this._ram[255&t]:this._bank[t]}write(t,e){t&=4095,this._handleBankswitch(t),t<256?this._ram[t]=255&e:super.write(t,e)}getType(){return ei.CartridgeType.bankswitch_12k_FA}_handleBankswitch(t){switch(t){case 4088:this._bank=this._bank0;break;case 4089:this._bank=this._bank1;break;case 4090:this._bank=this._bank2}}}class Ai extends ni{constructor(t){if(super(),this._banks=new Array(8),this._ram0=new Uint8Array(1024),this._ram1Banks=new Array(4),this._ram0Enabled=!1,16384!==t.length)throw new Error("buffer is not a 16k cartridge image: wrong length "+t.length);for(let t=0;t<8;t++)this._banks[t]=new Uint8Array(2048);for(let t=0;t<4;t++)this._ram1Banks[t]=new Uint8Array(256);for(let e=0;e<2048;e++)for(let s=0;s<8;s++)this._banks[s][e]=t[2048*s+e];this.reset()}static matchesBuffer(t){const e=oi(t,[[173,226,255],[173,229,255],[173,229,31],[173,231,31],[12,231,31],[141,231,255],[141,231,31]]);for(let t=0;t<e.length;t++)if(e[t]>0)return!0;return!1}reset(){this._bank0=this._banks[0],this._ram1=this._ram1Banks[0],this._ram0Enabled=!1}read(t){return this._handleBankswitch(4095&t),this.peek(t)}peek(t){return(t&=4095)<2048?this._ram0Enabled?t>=1024?this._ram0[t-1024]:0:this._bank0[t]:t<=2559?t>=2304?this._ram1[t-2304]:0:this._banks[7][2047-(4095-t)]}write(t,e){t&=4095,this._handleBankswitch(t),t<1024?this._ram0Enabled?this._ram0[t]=e:super.write(t,e):t<2048?super.write(t,e):t<2303?this._ram1[t-2048]=e:super.write(t,e)}getType(){return ei.CartridgeType.bankswitch_16k_E7}randomize(t){for(let e=0;e<4;e++)for(let s=0;s<this._ram1Banks[e].length;s++)this._ram1Banks[e][s]=t.int(255);for(let e=0;e<this._ram0.length;e++)this._ram0[e]=t.int(255)}_handleBankswitch(t){t<4064||(t<=4070?(this._bank0=this._banks[15&t],this._ram0Enabled=!1):4071===t?this._ram0Enabled=!0:t<=4075&&(this._ram1=this._ram1Banks[t-4072]))}}class mi extends ni{constructor(t){if(super(),this._banks=new Array(16),this._bankIdx=0,65536!==t.length)throw new Error("buffer is not a 64k cartridge image: wrong length "+t.length);for(let t=0;t<16;t++)this._banks[t]=new Uint8Array(4096);for(let e=0;e<4096;e++)for(let s=0;s<16;s++)this._banks[s][e]=t[4096*s+e];this.reset()}reset(){this._bankIdx=0,this._currentBank=this._banks[this._bankIdx]}read(t){return t&=4095,this._handleBankswitch(t),this._currentBank[t]}peek(t){return this._currentBank[4095&t]}write(t,e){t&=4095,this._handleBankswitch(t),super.write(t,e)}getType(){return ei.CartridgeType.bankswitch_64k_F0}_handleBankswitch(t){4080===t&&(this._bankIdx=this._bankIdx+1&15,this._currentBank=this._banks[this._bankIdx])}}class ki extends ni{constructor(t,e=!0){if(super(),this._supportSC=e,this._bus=null,this._banks=new Array(16),this._ram=new Uint8Array(128),this._hasSC=!1,65536!==t.length)throw new Error("buffer is not a 64k cartridge image: wrong length "+t.length);for(let t=0;t<16;t++)this._banks[t]=new Uint8Array(4096);for(let e=0;e<4096;e++)for(let s=0;s<16;s++)this._banks[s][e]=t[4096*s+e];this.reset()}static matchesBuffer(t){const e=e=>{const s=e.split("").map(t=>t.charCodeAt(0));for(let e=0;e<s.length;e++)if(s[e]!==t[65528+e])return!1;return!0};if(65536!==t.length)return!1;if(e("efef")||e("efsc"))return!0;const s=oi(t,[[12,224,255],[173,224,255],[12,224,31],[173,224,31]]);for(let t=0;t<4;t++)if(s[t]>0)return!0;return!1}reset(){this._bank=this._banks[15],this._hasSC=!1}getType(){return ei.CartridgeType.bankswitch_64k_EF}randomize(t){for(let e=0;e<this._ram.length;e++)this._ram[e]=t.int(255)}setBus(t){return this._bus=t,this}read(t){return this._access(4095&t,this._bus.getLastDataBusValue()),this.peek(t)}peek(t){return t&=4095,this._hasSC&&t>=128&&t<256?this._ram[t-128]:this._bank[t]}write(t,e){(t&=4095)<128&&this._supportSC&&(this._hasSC=!0),this._access(t,e)}_access(t,e){t<128&&this._hasSC?this._ram[t]=e:t>=4064&&t<=4079&&(this._bank=this._banks[t-4064])}}class yi extends ni{constructor(t,e=!0){if(super(),this._supportSC=e,this._bus=null,this._banks=new Array(8),this._ram=new Uint8Array(128),this._hasSC=!1,32768!==t.length)throw new Error("buffer is not a 32k cartridge image: wrong length "+t.length);for(let t=0;t<8;t++)this._banks[t]=new Uint8Array(4096);for(let e=0;e<4096;e++)for(let s=0;s<8;s++)this._banks[s][e]=t[4096*s+e];this.reset()}reset(){this._bank=this._banks[0],this._hasSC=!1}getType(){return ei.CartridgeType.bankswitch_32k_F4}randomize(t){for(let e=0;e<this._ram.length;e++)this._ram[e]=t.int(255)}setBus(t){return this._bus=t,this}read(t){return this._access(4095&t,this._bus.getLastDataBusValue()),this.peek(t)}peek(t){return t&=4095,this._hasSC&&t>=128&&t<256?this._ram[t-128]:this._bank[t]}write(t,e){(t&=4095)<128&&this._supportSC&&(this._hasSC=!0),this._access(t,e)}_access(t,e){t<128&&this._hasSC?this._ram[t]=e:t>=4084&&t<=4091&&(this._bank=this._banks[t-4084])}}class wi extends ni{constructor(t){if(super(),this._banks=new Array(7),this._ram=new Uint8Array(256),this._savedRam=new Uint8Array(256),this._accessCounter=0,this._accessCounterLimit=0,28672!==t.length&&29696!==t.length)throw new Error("buffer is not a 28k/29k cartridge image: wrong length "+t.length);for(let t=0;t<7;t++)this._banks[t]=new Uint8Array(4096);const e=28672===t.length?0:1024;for(let s=0;s<4096;s++)for(let i=0;i<7;i++)this._banks[i][s]=t[4096*i+s+e];this.reset()}static matchesBuffer(t){const e=oi(t,[[160,193,31,224],[0,128,2,224]]);return e[0]>0||e[1]>0}reset(){this._accessCounter=0,this._accessCounterLimit=0,this._bank=this._banks[0]}getType(){return ei.CartridgeType.bankswitch_FA2}randomize(t){for(let e=0;e<this._ram.length;e++)this._ram[e]=t.int(255)}setBus(t){return this._bus=t,this}read(t){return this.write(4095&t,this._bus.getLastDataBusValue()),this.peek(t)}peek(t){return(t&=4095)>=256&&t<512?this._ram[t-256]:4084===t?this._accessCounter>=this._accessCounterLimit?-65&this._bank[t]:64|this._bank[t]:this._bank[t]}write(t,e){if(t&=4095,this._accessCounter++,!(t<256))return 4084===t?this._handleIo():void(t>=4085&&t<=4091&&(this._bank=this._banks[t-4085]));this._ram[t]=e}_handleIo(){if(!(this._accessCounter<this._accessCounterLimit)){if(1===this._ram[255]){for(let t=0;t<256;t++)this._ram[t]=this._savedRam[t];this._accessCounterLimit=10}else{if(2!==this._ram[255])return;for(let t=0;t<256;t++)this._savedRam[t]=this._ram[t];this._accessCounterLimit=100}this._accessCounter=0,this._ram[255]=0}}}class vi{constructor(t){this.blockLocation=null,this.blockChecksum=null,this.startAddressLow=t[8192],this.startAddressHigh=t[8193],this.controlWord=t[8194],this.blockCount=t[8195],this.checksum=t[8196],this.multiloadId=t[8197],this.progressBarSpeedLow=t[8198],this.progressBarSpeedHigh=t[8199],this.blockLocation=new Uint8Array(this.blockCount),this.blockChecksum=new Uint8Array(this.blockCount);for(let e=0;e<this.blockCount;e++)this.blockLocation[e]=t[8208+e],this.blockChecksum[e]=t[8256+e]}verify(){return 85==(255&this.startAddressLow+this.startAddressHigh+this.controlWord+this.blockCount+this.checksum+this.multiloadId+this.progressBarSpeedLow+this.progressBarSpeedHigh)}}const Ci=rs("pfpMGPj//3jYqQCi/5qqqJUA6ND7TBj4ogKGAa4G8I74/6AAoiiUBMoQ+6KAoACUAOjQ+6ILvGj4lPDKEPhM8ACiBr1z+JXwyhD4rvD/hoC8APCt8f+u8v+G9K7z/4b1ov+gAJpM8ACN+f+t+//Q+0xB+I34/0wAAA==");class Bi extends ni{constructor(t){if(super(),this._loadCount=0,this._loads=null,this._headers=null,this._rom=new Uint8Array(2048),this._ramBanks=new Array(3),this._bank0=null,this._bank1=null,this._bank1Type=1,this._transitionCount=0,this._pendingWriteData=0,this._pendingWrite=!1,this._lastAddressBusValue=-1,this._writeRamEnabled=!1,this._loadInProgress=!1,this._loadTimestamp=0,this._cpuTimeProvider=null,t.length%8448!=0)throw new Error("not a supercharger image --- invalid size");this._loadCount=t.length/8448,this._loads=new Array(this._loadCount),this._headers=new Array(this._loadCount);for(let t=0;t<this._loadCount;t++)this._loads[t]=new Uint8Array(8448);for(let e=0;e<8448;e++)for(let s=0;s<this._loadCount;s++)this._loads[s][e]=t[8448*s+e];for(let t=0;t<this._loadCount;t++)this._headers[t]=new vi(this._loads[t]),this._headers[t].verify()||console.log(`load ${t} has invalid checksum`);for(let t=0;t<3;t++)this._ramBanks[t]=new Uint8Array(2048);this._setupRom(),this.reset()}reset(){this._setBankswitchMode(0),this._transitionCount=0,this._pendingWrite=!1,this._pendingWriteData=0,this._lastAddressBusValue=-1,this._writeRamEnabled=!1,this._loadInProgress=!1,this._loadTimestamp=0}setBus(t){return this._bus=t,this._bus.event.read.addHandler(Bi._onBusAccess,this),this._bus.event.write.addHandler(Bi._onBusAccess,this),this}setCpuTimeProvider(t){return this._cpuTimeProvider=t,this}setRng(t){return this._rng=t,this}read(t){return this._access(t,this._bus.getLastDataBusValue())}peek(t){return(t&=4095)<2048?this._bank0[t]:this._bank1[2047&t]}write(t,e){this._access(t,e)}getType(){return ei.CartridgeType.bankswitch_supercharger}static _onBusAccess(t,e){const s=e._bus.getLastAddresBusValue();s===e._lastAddressBusValue||e._loadInProgress||(e._transitionCount<=5&&e._transitionCount++,e._lastAddressBusValue=s)}_access(t,e){if(t&=4095,this._loadInProgress){if(!(this._cpuTimeProvider()-this._loadTimestamp>.001))return e;this._loadInProgress=!1}const s=t<2048?this._bank0[t]:this._bank1[2047&t];if(!(0!=(3840&t)||this._pendingWrite&&this._writeRamEnabled))return this._pendingWriteData=255&t,this._transitionCount=0,this._pendingWrite=!0,s;if(4088===t)return this._setBankswitchMode((28&this._pendingWriteData)>>>2),this._writeRamEnabled=(2&this._pendingWriteData)>0,this._pendingWrite=!1,s;if(4089===t&&1===this._bank1Type&&(8191&this._lastAddressBusValue)<255)return this._loadIntoRam(e),s;if(this._pendingWrite&&this._writeRamEnabled&&5===this._transitionCount){if(this._pendingWrite=!1,t<2048)this._bank0[t]=this._pendingWriteData;else{if(0!==this._bank1Type)return s;this._bank1[2047&t]=this._pendingWriteData}return this._pendingWriteData}return s}_setBankswitchMode(t){switch(t){case 0:return this._configureBanks(2,1);case 1:return this._configureBanks(0,1);case 2:return this._configureBanks(2,0,0);case 3:return this._configureBanks(0,0,2);case 4:return this._configureBanks(2,1);case 5:return this._configureBanks(1,1);case 6:return this._configureBanks(2,0,1);case 7:return this._configureBanks(1,0,2);default:throw new Error("invalid bankswitching mode")}}_configureBanks(t,e,s=0){this._bank0=this._ramBanks[t],this._bank1Type=e,this._bank1=0===e?this._ramBanks[s]:this._rom}_setupRom(){for(let t=0;t<2048;t++)this._rom[t]=0;for(let t=0;t<Ci.length;t++)this._rom[t]=Ci[t];this._rom[2047]=this._rom[2045]=248,this._rom[2046]=this._rom[2044]=7}_loadIntoRam(t){let e;for(e=0;e<this._loadCount&&(this._headers[e].multiloadId!==t&&1!==this._loadCount);e++);e>=this._loadCount&&console.log("no load with id "+t);const s=this._headers[e],i=this._loads[e];for(let t=0;t<s.blockCount;t++){const r=s.blockLocation[t];let n=3&r;n>2&&(n=0,console.log(`invalid bank for block ${t}, load ${e}`));const a=256*((28&r)>>>2);let h=r+s.blockChecksum[t];for(let e=0;e<256;e++)h+=i[256*t+e],this._ramBanks[n][a+e]=i[256*t+e];85!=(255&h)&&console.log(`load ${e}, block ${t}: invalid checksum`)}this._rom[2032]=s.controlWord,this._rom[2033]=this._rng.int(255),this._rom[2034]=s.startAddressLow,this._rom[2035]=s.startAddressHigh,this._loadInProgress=!0,this._loadTimestamp=this._cpuTimeProvider()}}const xi=new Uint8Array([0,4,5,9,6,10,11,15]);class Si extends ni{constructor(t){if(super(),this._bank0=new Uint8Array(4096),this._bank1=new Uint8Array(4096),this._fetcherData=new Uint8Array(2048),this._fetchers=new Array(8),this._rng=1,this._cpuTimeProvider=null,this._lastCpuTime=0,this._clockAccumulator=0,t.length<10240)throw new Error("buffer is not a DPC image: too small "+t.length);for(let t=0;t<8;t++)this._fetchers[t]=new Pi;for(let e=0;e<4096;e++)this._bank0[e]=t[e],this._bank1[e]=t[4096+e];for(let e=0;e<2048;e++)this._fetcherData[e]=t[8192+e];this.reset()}reset(){this._bank=this._bank1,this._rng=1,this._fetchers.forEach(t=>t.reset()),this._lastCpuTime=0,this._clockAccumulator=0}getType(){return ei.CartridgeType.bankswitch_8k_DPC}setBus(t){return this._bus=t,this}setCpuTimeProvider(t){return this._cpuTimeProvider=t,this}read(t){return this._access(t,this._bus.getLastDataBusValue())}peek(t){return this._bank[4095&t]}write(t,e){this._access(t,e)}_access(t,e){if((t&=4095)>127){switch(t){case 4088:this._bank=this._bank0;break;case 4089:this._bank=this._bank1}return this._bank[t]}if(t<8)return 4&t?(this._clockMusicFetchers(),xi[4&this._fetchers[5].mask|2&this._fetchers[6].mask|1&this._fetchers[7].mask]):this._randomNext();if(t<64){const e=this._fetchers[t-8&7],s=e.mask;let i=this._fetcherData[2047-e.pointer];switch(e.next(),t-8>>>3){case 0:return i;case 1:return i&s;case 2:return i&=s,255&(i<<4|i>>>4);case 3:return i&=s,(1&i)<<7|(2&i)<<5|(4&i)<<3|(8&i)<<1|(16&i)>>>1|(32&i)>>>3|(64&i)>>>5|(128&i)>>>7;case 4:return(i&s)>>>1;case 5:return i<<1&s;case 6:return s}}if(t<96){const s=this._fetchers[t-64&7];switch(t-64>>>3){case 0:this._clockMusicFetchers(),s.setStart(e);break;case 1:this._clockMusicFetchers(),s.setEnd(e);break;case 2:s.setLow(e);break;case 3:s.setHigh(e),t>92&&s.setMusicMode(e)}return this._bank[t]}return t>=112&&t<120?(this._rng=1,this._bank[t]):this._bank[t]}_randomNext(){const t=this._rng;return this._rng=255&(this._rng<<1|1&~(this._rng>>>7^this._rng>>>5^this._rng>>>4^this._rng>>>3)),t}_clockMusicFetchers(){const t=this._cpuTimeProvider();this._clockAccumulator+=2e4*(t-this._lastCpuTime),this._lastCpuTime=t;const e=Math.floor(this._clockAccumulator);if(this._clockAccumulator-=e,0!==e)for(let t=5;t<8;t++)this._fetchers[t].forwardClock(e)}}class Pi{constructor(){this.pointer=0,this.start=0,this.end=0,this.musicMode=!1,this.mask=0}contructor(){this.reset()}reset(){this.pointer=this.start=this.end=this.mask=0,this.musicMode=!1}next(){this.musicMode||(this.pointer=this.pointer+2047&2047,this._updateMask())}setStart(t){this.start=t,this.mask=0,this._updateMask()}setEnd(t){this.end=t,this._updateMask()}setLow(t){this.pointer=1792&this.pointer|t,this._updateMask()}setHigh(t){this.pointer=255&this.pointer|(7&t)<<8,this._updateMask()}setMusicMode(t){this.musicMode=0!=(16&t)}forwardClock(t){if(!this.musicMode)return;const e=this.start+1,s=((255&this.pointer)+e-t%e)%e,i=256+this.start-s&255,r=256+this.end-s&255;this.pointer=1792&this.pointer|s,this.mask=i>r?0:255}_updateMask(){(255&this.pointer)===this.start&&(this.mask=255),(255&this.pointer)===this.end&&(this.mask=0)}}
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var Ti=function(t,e){return(Ti=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var s in e)e.hasOwnProperty(s)&&(t[s]=e[s])})(t,e)};var Ei=function(){return(Ei=Object.assign||function(t){for(var e,s=1,i=arguments.length;s<i;s++)for(var r in e=arguments[s])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t}).apply(this,arguments)};function Ii(t){var e="function"==typeof Symbol&&Symbol.iterator,s=e&&t[e],i=0;if(s)return s.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function Ri(t,e){var s="function"==typeof Symbol&&t[Symbol.iterator];if(!s)return t;var i,r,n=s.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(i=n.next()).done;)a.push(i.value)}catch(t){r={error:t}}finally{try{i&&!i.done&&(s=n.return)&&s.call(n)}finally{if(r)throw r.error}}return a}function Mi(t){return this instanceof Mi?(this.v=t,this):new Mi(t)}var Fi=Object.freeze({__proto__:null,__extends:function(t,e){function s(){this.constructor=t}Ti(t,e),t.prototype=null===e?Object.create(e):(s.prototype=e.prototype,new s)},get __assign(){return Ei},__rest:function(t,e){var s={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(s[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(s[i[r]]=t[i[r]])}return s},__decorate:function(t,e,s,i){var r,n=arguments.length,a=n<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,s,i);else for(var h=t.length-1;h>=0;h--)(r=t[h])&&(a=(n<3?r(a):n>3?r(e,s,a):r(e,s))||a);return n>3&&a&&Object.defineProperty(e,s,a),a},__param:function(t,e){return function(s,i){e(s,i,t)}},__metadata:function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},__awaiter:function(t,e,s,i){return new(s||(s=Promise))((function(r,n){function a(t){try{o(i.next(t))}catch(t){n(t)}}function h(t){try{o(i.throw(t))}catch(t){n(t)}}function o(t){var e;t.done?r(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(a,h)}o((i=i.apply(t,e||[])).next())}))},__generator:function(t,e){var s,i,r,n,a={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return n={next:h(0),throw:h(1),return:h(2)},"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function h(n){return function(h){return function(n){if(s)throw new TypeError("Generator is already executing.");for(;a;)try{if(s=1,i&&(r=2&n[0]?i.return:n[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,n[1])).done)return r;switch(i=0,r&&(n=[2&n[0],r.value]),n[0]){case 0:case 1:r=n;break;case 4:return a.label++,{value:n[1],done:!1};case 5:a.label++,i=n[1],n=[0];continue;case 7:n=a.ops.pop(),a.trys.pop();continue;default:if(!(r=a.trys,(r=r.length>0&&r[r.length-1])||6!==n[0]&&2!==n[0])){a=0;continue}if(3===n[0]&&(!r||n[1]>r[0]&&n[1]<r[3])){a.label=n[1];break}if(6===n[0]&&a.label<r[1]){a.label=r[1],r=n;break}if(r&&a.label<r[2]){a.label=r[2],a.ops.push(n);break}r[2]&&a.ops.pop(),a.trys.pop();continue}n=e.call(t,a)}catch(t){n=[6,t],i=0}finally{s=r=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,h])}}},__createBinding:function(t,e,s,i){void 0===i&&(i=s),t[i]=e[s]},__exportStar:function(t,e){for(var s in t)"default"===s||e.hasOwnProperty(s)||(e[s]=t[s])},__values:Ii,__read:Ri,__spread:function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(Ri(arguments[e]));return t},__spreadArrays:function(){for(var t=0,e=0,s=arguments.length;e<s;e++)t+=arguments[e].length;var i=Array(t),r=0;for(e=0;e<s;e++)for(var n=arguments[e],a=0,h=n.length;a<h;a++,r++)i[r]=n[a];return i},__await:Mi,__asyncGenerator:function(t,e,s){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var i,r=s.apply(t,e||[]),n=[];return i={},a("next"),a("throw"),a("return"),i[Symbol.asyncIterator]=function(){return this},i;function a(t){r[t]&&(i[t]=function(e){return new Promise((function(s,i){n.push([t,e,s,i])>1||h(t,e)}))})}function h(t,e){try{(s=r[t](e)).value instanceof Mi?Promise.resolve(s.value.v).then(o,c):u(n[0][2],s)}catch(t){u(n[0][3],t)}var s}function o(t){h("next",t)}function c(t){h("throw",t)}function u(t,e){t(e),n.shift(),n.length&&h(n[0][0],n[0][1])}},__asyncDelegator:function(t){var e,s;return e={},i("next"),i("throw",(function(t){throw t})),i("return"),e[Symbol.iterator]=function(){return this},e;function i(i,r){e[i]=t[i]?function(e){return(s=!s)?{value:Mi(t[i](e)),done:"return"===i}:r?r(e):e}:r}},__asyncValues:function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,s=t[Symbol.asyncIterator];return s?s.call(t):(t=Ii(t),e={},i("next"),i("throw"),i("return"),e[Symbol.asyncIterator]=function(){return this},e);function i(s){e[s]=t[s]&&function(e){return new Promise((function(i,r){(function(t,e,s,i){Promise.resolve(i).then((function(e){t({value:e,done:s})}),e)})(i,r,(e=t[s](e)).done,e.value)}))}}},__makeTemplateObject:function(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t},__importStar:function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var s in t)Object.hasOwnProperty.call(t,s)&&(e[s]=t[s]);return e.default=t,e},__importDefault:function(t){return t&&t.__esModule?t:{default:t}},__classPrivateFieldGet:function(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)},__classPrivateFieldSet:function(t,e,s){if(!e.has(t))throw new TypeError("attempted to set private field on non-instance");return e.set(t,s),s}}),Oi="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function Hi(){throw new Error("setTimeout has not been defined")}function Li(){throw new Error("clearTimeout has not been defined")}var Di=Hi,Ui=Li;function ji(t){if(Di===setTimeout)return setTimeout(t,0);if((Di===Hi||!Di)&&setTimeout)return Di=setTimeout,setTimeout(t,0);try{return Di(t,0)}catch(e){try{return Di.call(null,t,0)}catch(e){return Di.call(this,t,0)}}}"function"==typeof Oi.setTimeout&&(Di=setTimeout),"function"==typeof Oi.clearTimeout&&(Ui=clearTimeout);var Vi,Qi=[],Wi=!1,zi=-1;function Ji(){Wi&&Vi&&(Wi=!1,Vi.length?Qi=Vi.concat(Qi):zi=-1,Qi.length&&Yi())}function Yi(){if(!Wi){var t=ji(Ji);Wi=!0;for(var e=Qi.length;e;){for(Vi=Qi,Qi=[];++zi<e;)Vi&&Vi[zi].run();zi=-1,e=Qi.length}Vi=null,Wi=!1,function(t){if(Ui===clearTimeout)return clearTimeout(t);if((Ui===Li||!Ui)&&clearTimeout)return Ui=clearTimeout,clearTimeout(t);try{Ui(t)}catch(e){try{return Ui.call(null,t)}catch(e){return Ui.call(this,t)}}}(t)}}function qi(t,e){this.fun=t,this.array=e}qi.prototype.run=function(){this.fun.apply(null,this.array)};function Ni(){}var Xi=Ni,Gi=Ni,Ki=Ni,Zi=Ni,$i=Ni,tr=Ni,er=Ni;var sr=Oi.performance||{},ir=sr.now||sr.mozNow||sr.msNow||sr.oNow||sr.webkitNow||function(){return(new Date).getTime()};var rr=new Date;var nr={nextTick:function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var s=1;s<arguments.length;s++)e[s-1]=arguments[s];Qi.push(new qi(t,e)),1!==Qi.length||Wi||ji(Yi)},title:"browser",browser:!0,env:{},argv:[],version:"",versions:{},on:Xi,addListener:Gi,once:Ki,off:Zi,removeListener:$i,removeAllListeners:tr,emit:er,binding:function(t){throw new Error("process.binding is not supported")},cwd:function(){return"/"},chdir:function(t){throw new Error("process.chdir is not supported")},umask:function(){return 0},hrtime:function(t){var e=.001*ir.call(sr),s=Math.floor(e),i=Math.floor(e%1*1e9);return t&&(s-=t[0],(i-=t[1])<0&&(s--,i+=1e9)),[s,i]},platform:"browser",release:{},config:{},uptime:function(){return(new Date-rr)/1e3}},ar="/Users/pestix/git/6502ts/6502.ts/node_modules/thumbulator.ts/lib/native",hr=[],or=[],cr="undefined"!=typeof Uint8Array?Uint8Array:Array,ur=!1;function lr(){ur=!0;for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=0,s=t.length;e<s;++e)hr[e]=t[e],or[t.charCodeAt(e)]=e;or["-".charCodeAt(0)]=62,or["_".charCodeAt(0)]=63}function _r(t,e,s){for(var i,r,n=[],a=e;a<s;a+=3)i=(t[a]<<16)+(t[a+1]<<8)+t[a+2],n.push(hr[(r=i)>>18&63]+hr[r>>12&63]+hr[r>>6&63]+hr[63&r]);return n.join("")}function dr(t){var e;ur||lr();for(var s=t.length,i=s%3,r="",n=[],a=16383,h=0,o=s-i;h<o;h+=a)n.push(_r(t,h,h+a>o?o:h+a));return 1===i?(e=t[s-1],r+=hr[e>>2],r+=hr[e<<4&63],r+="=="):2===i&&(e=(t[s-2]<<8)+t[s-1],r+=hr[e>>10],r+=hr[e>>4&63],r+=hr[e<<2&63],r+="="),n.push(r),n.join("")}function fr(t,e,s,i,r){var n,a,h=8*r-i-1,o=(1<<h)-1,c=o>>1,u=-7,l=s?r-1:0,_=s?-1:1,d=t[e+l];for(l+=_,n=d&(1<<-u)-1,d>>=-u,u+=h;u>0;n=256*n+t[e+l],l+=_,u-=8);for(a=n&(1<<-u)-1,n>>=-u,u+=i;u>0;a=256*a+t[e+l],l+=_,u-=8);if(0===n)n=1-c;else{if(n===o)return a?NaN:1/0*(d?-1:1);a+=Math.pow(2,i),n-=c}return(d?-1:1)*a*Math.pow(2,n-i)}function pr(t,e,s,i,r,n){var a,h,o,c=8*n-r-1,u=(1<<c)-1,l=u>>1,_=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,d=i?0:n-1,f=i?1:-1,p=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(h=isNaN(e)?1:0,a=u):(a=Math.floor(Math.log(e)/Math.LN2),e*(o=Math.pow(2,-a))<1&&(a--,o*=2),(e+=a+l>=1?_/o:_*Math.pow(2,1-l))*o>=2&&(a++,o/=2),a+l>=u?(h=0,a=u):a+l>=1?(h=(e*o-1)*Math.pow(2,r),a+=l):(h=e*Math.pow(2,l-1)*Math.pow(2,r),a=0));r>=8;t[s+d]=255&h,d+=f,h/=256,r-=8);for(a=a<<r|h,c+=r;c>0;t[s+d]=255&a,d+=f,a/=256,c-=8);t[s+d-f]|=128*p}var gr={}.toString,br=Array.isArray||function(t){return"[object Array]"==gr.call(t)};function Ar(){return kr.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function mr(t,e){if(Ar()<e)throw new RangeError("Invalid typed array length");return kr.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=kr.prototype:(null===t&&(t=new kr(e)),t.length=e),t}function kr(t,e,s){if(!(kr.TYPED_ARRAY_SUPPORT||this instanceof kr))return new kr(t,e,s);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return vr(this,t)}return yr(this,t,e,s)}function yr(t,e,s,i){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,s,i){if(e.byteLength,s<0||e.byteLength<s)throw new RangeError("'offset' is out of bounds");if(e.byteLength<s+(i||0))throw new RangeError("'length' is out of bounds");e=void 0===s&&void 0===i?new Uint8Array(e):void 0===i?new Uint8Array(e,s):new Uint8Array(e,s,i);kr.TYPED_ARRAY_SUPPORT?(t=e).__proto__=kr.prototype:t=Cr(t,e);return t}(t,e,s,i):"string"==typeof e?function(t,e,s){"string"==typeof s&&""!==s||(s="utf8");if(!kr.isEncoding(s))throw new TypeError('"encoding" must be a valid string encoding');var i=0|Sr(e,s),r=(t=mr(t,i)).write(e,s);r!==i&&(t=t.slice(0,r));return t}(t,e,s):function(t,e){if(xr(e)){var s=0|Br(e.length);return 0===(t=mr(t,s)).length||e.copy(t,0,0,s),t}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||(i=e.length)!=i?mr(t,0):Cr(t,e);if("Buffer"===e.type&&br(e.data))return Cr(t,e.data)}var i;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function wr(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 vr(t,e){if(wr(e),t=mr(t,e<0?0:0|Br(e)),!kr.TYPED_ARRAY_SUPPORT)for(var s=0;s<e;++s)t[s]=0;return t}function Cr(t,e){var s=e.length<0?0:0|Br(e.length);t=mr(t,s);for(var i=0;i<s;i+=1)t[i]=255&e[i];return t}function Br(t){if(t>=Ar())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Ar().toString(16)+" bytes");return 0|t}function xr(t){return!(null==t||!t._isBuffer)}function Sr(t,e){if(xr(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 s=t.length;if(0===s)return 0;for(var i=!1;;)switch(e){case"ascii":case"latin1":case"binary":return s;case"utf8":case"utf-8":case void 0:return tn(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*s;case"hex":return s>>>1;case"base64":return en(t).length;default:if(i)return tn(t).length;e=(""+e).toLowerCase(),i=!0}}function Pr(t,e,s){var i=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===s||s>this.length)&&(s=this.length),s<=0)return"";if((s>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return Wr(this,e,s);case"utf8":case"utf-8":return Ur(this,e,s);case"ascii":return Vr(this,e,s);case"latin1":case"binary":return Qr(this,e,s);case"base64":return Dr(this,e,s);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return zr(this,e,s);default:if(i)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),i=!0}}function Tr(t,e,s){var i=t[e];t[e]=t[s],t[s]=i}function Er(t,e,s,i,r){if(0===t.length)return-1;if("string"==typeof s?(i=s,s=0):s>2147483647?s=2147483647:s<-2147483648&&(s=-2147483648),s=+s,isNaN(s)&&(s=r?0:t.length-1),s<0&&(s=t.length+s),s>=t.length){if(r)return-1;s=t.length-1}else if(s<0){if(!r)return-1;s=0}if("string"==typeof e&&(e=kr.from(e,i)),xr(e))return 0===e.length?-1:Ir(t,e,s,i,r);if("number"==typeof e)return e&=255,kr.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?r?Uint8Array.prototype.indexOf.call(t,e,s):Uint8Array.prototype.lastIndexOf.call(t,e,s):Ir(t,[e],s,i,r);throw new TypeError("val must be string, number or Buffer")}function Ir(t,e,s,i,r){var n,a=1,h=t.length,o=e.length;if(void 0!==i&&("ucs2"===(i=String(i).toLowerCase())||"ucs-2"===i||"utf16le"===i||"utf-16le"===i)){if(t.length<2||e.length<2)return-1;a=2,h/=2,o/=2,s/=2}function c(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(r){var u=-1;for(n=s;n<h;n++)if(c(t,n)===c(e,-1===u?0:n-u)){if(-1===u&&(u=n),n-u+1===o)return u*a}else-1!==u&&(n-=n-u),u=-1}else for(s+o>h&&(s=h-o),n=s;n>=0;n--){for(var l=!0,_=0;_<o;_++)if(c(t,n+_)!==c(e,_)){l=!1;break}if(l)return n}return-1}function Rr(t,e,s,i){s=Number(s)||0;var r=t.length-s;i?(i=Number(i))>r&&(i=r):i=r;var n=e.length;if(n%2!=0)throw new TypeError("Invalid hex string");i>n/2&&(i=n/2);for(var a=0;a<i;++a){var h=parseInt(e.substr(2*a,2),16);if(isNaN(h))return a;t[s+a]=h}return a}function Mr(t,e,s,i){return sn(tn(e,t.length-s),t,s,i)}function Fr(t,e,s,i){return sn(function(t){for(var e=[],s=0;s<t.length;++s)e.push(255&t.charCodeAt(s));return e}(e),t,s,i)}function Or(t,e,s,i){return Fr(t,e,s,i)}function Hr(t,e,s,i){return sn(en(e),t,s,i)}function Lr(t,e,s,i){return sn(function(t,e){for(var s,i,r,n=[],a=0;a<t.length&&!((e-=2)<0);++a)i=(s=t.charCodeAt(a))>>8,r=s%256,n.push(r),n.push(i);return n}(e,t.length-s),t,s,i)}function Dr(t,e,s){return 0===e&&s===t.length?dr(t):dr(t.slice(e,s))}function Ur(t,e,s){s=Math.min(t.length,s);for(var i=[],r=e;r<s;){var n,a,h,o,c=t[r],u=null,l=c>239?4:c>223?3:c>191?2:1;if(r+l<=s)switch(l){case 1:c<128&&(u=c);break;case 2:128==(192&(n=t[r+1]))&&(o=(31&c)<<6|63&n)>127&&(u=o);break;case 3:n=t[r+1],a=t[r+2],128==(192&n)&&128==(192&a)&&(o=(15&c)<<12|(63&n)<<6|63&a)>2047&&(o<55296||o>57343)&&(u=o);break;case 4:n=t[r+1],a=t[r+2],h=t[r+3],128==(192&n)&&128==(192&a)&&128==(192&h)&&(o=(15&c)<<18|(63&n)<<12|(63&a)<<6|63&h)>65535&&o<1114112&&(u=o)}null===u?(u=65533,l=1):u>65535&&(u-=65536,i.push(u>>>10&1023|55296),u=56320|1023&u),i.push(u),r+=l}return function(t){var e=t.length;if(e<=jr)return String.fromCharCode.apply(String,t);var s="",i=0;for(;i<e;)s+=String.fromCharCode.apply(String,t.slice(i,i+=jr));return s}(i)}kr.TYPED_ARRAY_SUPPORT=void 0===Oi.TYPED_ARRAY_SUPPORT||Oi.TYPED_ARRAY_SUPPORT,kr.poolSize=8192,kr._augment=function(t){return t.__proto__=kr.prototype,t},kr.from=function(t,e,s){return yr(null,t,e,s)},kr.TYPED_ARRAY_SUPPORT&&(kr.prototype.__proto__=Uint8Array.prototype,kr.__proto__=Uint8Array),kr.alloc=function(t,e,s){return function(t,e,s,i){return wr(e),e<=0?mr(t,e):void 0!==s?"string"==typeof i?mr(t,e).fill(s,i):mr(t,e).fill(s):mr(t,e)}(null,t,e,s)},kr.allocUnsafe=function(t){return vr(null,t)},kr.allocUnsafeSlow=function(t){return vr(null,t)},kr.isBuffer=function(t){return null!=t&&(!!t._isBuffer||rn(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&rn(t.slice(0,0))}(t))},kr.compare=function(t,e){if(!xr(t)||!xr(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var s=t.length,i=e.length,r=0,n=Math.min(s,i);r<n;++r)if(t[r]!==e[r]){s=t[r],i=e[r];break}return s<i?-1:i<s?1:0},kr.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}},kr.concat=function(t,e){if(!br(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return kr.alloc(0);var s;if(void 0===e)for(e=0,s=0;s<t.length;++s)e+=t[s].length;var i=kr.allocUnsafe(e),r=0;for(s=0;s<t.length;++s){var n=t[s];if(!xr(n))throw new TypeError('"list" argument must be an Array of Buffers');n.copy(i,r),r+=n.length}return i},kr.byteLength=Sr,kr.prototype._isBuffer=!0,kr.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)Tr(this,e,e+1);return this},kr.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)Tr(this,e,e+3),Tr(this,e+1,e+2);return this},kr.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)Tr(this,e,e+7),Tr(this,e+1,e+6),Tr(this,e+2,e+5),Tr(this,e+3,e+4);return this},kr.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?Ur(this,0,t):Pr.apply(this,arguments)},kr.prototype.equals=function(t){if(!xr(t))throw new TypeError("Argument must be a Buffer");return this===t||0===kr.compare(this,t)},kr.prototype.inspect=function(){var t="";return this.length>0&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(t+=" ... ")),"<Buffer "+t+">"},kr.prototype.compare=function(t,e,s,i,r){if(!xr(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===s&&(s=t?t.length:0),void 0===i&&(i=0),void 0===r&&(r=this.length),e<0||s>t.length||i<0||r>this.length)throw new RangeError("out of range index");if(i>=r&&e>=s)return 0;if(i>=r)return-1;if(e>=s)return 1;if(this===t)return 0;for(var n=(r>>>=0)-(i>>>=0),a=(s>>>=0)-(e>>>=0),h=Math.min(n,a),o=this.slice(i,r),c=t.slice(e,s),u=0;u<h;++u)if(o[u]!==c[u]){n=o[u],a=c[u];break}return n<a?-1:a<n?1:0},kr.prototype.includes=function(t,e,s){return-1!==this.indexOf(t,e,s)},kr.prototype.indexOf=function(t,e,s){return Er(this,t,e,s,!0)},kr.prototype.lastIndexOf=function(t,e,s){return Er(this,t,e,s,!1)},kr.prototype.write=function(t,e,s,i){if(void 0===e)i="utf8",s=this.length,e=0;else if(void 0===s&&"string"==typeof e)i=e,s=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(s)?(s|=0,void 0===i&&(i="utf8")):(i=s,s=void 0)}var r=this.length-e;if((void 0===s||s>r)&&(s=r),t.length>0&&(s<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");for(var n=!1;;)switch(i){case"hex":return Rr(this,t,e,s);case"utf8":case"utf-8":return Mr(this,t,e,s);case"ascii":return Fr(this,t,e,s);case"latin1":case"binary":return Or(this,t,e,s);case"base64":return Hr(this,t,e,s);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Lr(this,t,e,s);default:if(n)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),n=!0}},kr.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var jr=4096;function Vr(t,e,s){var i="";s=Math.min(t.length,s);for(var r=e;r<s;++r)i+=String.fromCharCode(127&t[r]);return i}function Qr(t,e,s){var i="";s=Math.min(t.length,s);for(var r=e;r<s;++r)i+=String.fromCharCode(t[r]);return i}function Wr(t,e,s){var i=t.length;(!e||e<0)&&(e=0),(!s||s<0||s>i)&&(s=i);for(var r="",n=e;n<s;++n)r+=$r(t[n]);return r}function zr(t,e,s){for(var i=t.slice(e,s),r="",n=0;n<i.length;n+=2)r+=String.fromCharCode(i[n]+256*i[n+1]);return r}function Jr(t,e,s){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>s)throw new RangeError("Trying to access beyond buffer length")}function Yr(t,e,s,i,r,n){if(!xr(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(s+i>t.length)throw new RangeError("Index out of range")}function qr(t,e,s,i){e<0&&(e=65535+e+1);for(var r=0,n=Math.min(t.length-s,2);r<n;++r)t[s+r]=(e&255<<8*(i?r:1-r))>>>8*(i?r:1-r)}function Nr(t,e,s,i){e<0&&(e=4294967295+e+1);for(var r=0,n=Math.min(t.length-s,4);r<n;++r)t[s+r]=e>>>8*(i?r:3-r)&255}function Xr(t,e,s,i,r,n){if(s+i>t.length)throw new RangeError("Index out of range");if(s<0)throw new RangeError("Index out of range")}function Gr(t,e,s,i,r){return r||Xr(t,0,s,4),pr(t,e,s,i,23,4),s+4}function Kr(t,e,s,i,r){return r||Xr(t,0,s,8),pr(t,e,s,i,52,8),s+8}kr.prototype.slice=function(t,e){var s,i=this.length;if((t=~~t)<0?(t+=i)<0&&(t=0):t>i&&(t=i),(e=void 0===e?i:~~e)<0?(e+=i)<0&&(e=0):e>i&&(e=i),e<t&&(e=t),kr.TYPED_ARRAY_SUPPORT)(s=this.subarray(t,e)).__proto__=kr.prototype;else{var r=e-t;s=new kr(r,void 0);for(var n=0;n<r;++n)s[n]=this[n+t]}return s},kr.prototype.readUIntLE=function(t,e,s){t|=0,e|=0,s||Jr(t,e,this.length);for(var i=this[t],r=1,n=0;++n<e&&(r*=256);)i+=this[t+n]*r;return i},kr.prototype.readUIntBE=function(t,e,s){t|=0,e|=0,s||Jr(t,e,this.length);for(var i=this[t+--e],r=1;e>0&&(r*=256);)i+=this[t+--e]*r;return i},kr.prototype.readUInt8=function(t,e){return e||Jr(t,1,this.length),this[t]},kr.prototype.readUInt16LE=function(t,e){return e||Jr(t,2,this.length),this[t]|this[t+1]<<8},kr.prototype.readUInt16BE=function(t,e){return e||Jr(t,2,this.length),this[t]<<8|this[t+1]},kr.prototype.readUInt32LE=function(t,e){return e||Jr(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},kr.prototype.readUInt32BE=function(t,e){return e||Jr(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},kr.prototype.readIntLE=function(t,e,s){t|=0,e|=0,s||Jr(t,e,this.length);for(var i=this[t],r=1,n=0;++n<e&&(r*=256);)i+=this[t+n]*r;return i>=(r*=128)&&(i-=Math.pow(2,8*e)),i},kr.prototype.readIntBE=function(t,e,s){t|=0,e|=0,s||Jr(t,e,this.length);for(var i=e,r=1,n=this[t+--i];i>0&&(r*=256);)n+=this[t+--i]*r;return n>=(r*=128)&&(n-=Math.pow(2,8*e)),n},kr.prototype.readInt8=function(t,e){return e||Jr(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},kr.prototype.readInt16LE=function(t,e){e||Jr(t,2,this.length);var s=this[t]|this[t+1]<<8;return 32768&s?4294901760|s:s},kr.prototype.readInt16BE=function(t,e){e||Jr(t,2,this.length);var s=this[t+1]|this[t]<<8;return 32768&s?4294901760|s:s},kr.prototype.readInt32LE=function(t,e){return e||Jr(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},kr.prototype.readInt32BE=function(t,e){return e||Jr(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},kr.prototype.readFloatLE=function(t,e){return e||Jr(t,4,this.length),fr(this,t,!0,23,4)},kr.prototype.readFloatBE=function(t,e){return e||Jr(t,4,this.length),fr(this,t,!1,23,4)},kr.prototype.readDoubleLE=function(t,e){return e||Jr(t,8,this.length),fr(this,t,!0,52,8)},kr.prototype.readDoubleBE=function(t,e){return e||Jr(t,8,this.length),fr(this,t,!1,52,8)},kr.prototype.writeUIntLE=function(t,e,s,i){(t=+t,e|=0,s|=0,i)||Yr(this,t,e,s,Math.pow(2,8*s)-1,0);var r=1,n=0;for(this[e]=255&t;++n<s&&(r*=256);)this[e+n]=t/r&255;return e+s},kr.prototype.writeUIntBE=function(t,e,s,i){(t=+t,e|=0,s|=0,i)||Yr(this,t,e,s,Math.pow(2,8*s)-1,0);var r=s-1,n=1;for(this[e+r]=255&t;--r>=0&&(n*=256);)this[e+r]=t/n&255;return e+s},kr.prototype.writeUInt8=function(t,e,s){return t=+t,e|=0,s||Yr(this,t,e,1,255,0),kr.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},kr.prototype.writeUInt16LE=function(t,e,s){return t=+t,e|=0,s||Yr(this,t,e,2,65535,0),kr.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):qr(this,t,e,!0),e+2},kr.prototype.writeUInt16BE=function(t,e,s){return t=+t,e|=0,s||Yr(this,t,e,2,65535,0),kr.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):qr(this,t,e,!1),e+2},kr.prototype.writeUInt32LE=function(t,e,s){return t=+t,e|=0,s||Yr(this,t,e,4,4294967295,0),kr.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):Nr(this,t,e,!0),e+4},kr.prototype.writeUInt32BE=function(t,e,s){return t=+t,e|=0,s||Yr(this,t,e,4,4294967295,0),kr.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):Nr(this,t,e,!1),e+4},kr.prototype.writeIntLE=function(t,e,s,i){if(t=+t,e|=0,!i){var r=Math.pow(2,8*s-1);Yr(this,t,e,s,r-1,-r)}var n=0,a=1,h=0;for(this[e]=255&t;++n<s&&(a*=256);)t<0&&0===h&&0!==this[e+n-1]&&(h=1),this[e+n]=(t/a>>0)-h&255;return e+s},kr.prototype.writeIntBE=function(t,e,s,i){if(t=+t,e|=0,!i){var r=Math.pow(2,8*s-1);Yr(this,t,e,s,r-1,-r)}var n=s-1,a=1,h=0;for(this[e+n]=255&t;--n>=0&&(a*=256);)t<0&&0===h&&0!==this[e+n+1]&&(h=1),this[e+n]=(t/a>>0)-h&255;return e+s},kr.prototype.writeInt8=function(t,e,s){return t=+t,e|=0,s||Yr(this,t,e,1,127,-128),kr.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},kr.prototype.writeInt16LE=function(t,e,s){return t=+t,e|=0,s||Yr(this,t,e,2,32767,-32768),kr.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):qr(this,t,e,!0),e+2},kr.prototype.writeInt16BE=function(t,e,s){return t=+t,e|=0,s||Yr(this,t,e,2,32767,-32768),kr.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):qr(this,t,e,!1),e+2},kr.prototype.writeInt32LE=function(t,e,s){return t=+t,e|=0,s||Yr(this,t,e,4,2147483647,-2147483648),kr.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):Nr(this,t,e,!0),e+4},kr.prototype.writeInt32BE=function(t,e,s){return t=+t,e|=0,s||Yr(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),kr.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):Nr(this,t,e,!1),e+4},kr.prototype.writeFloatLE=function(t,e,s){return Gr(this,t,e,!0,s)},kr.prototype.writeFloatBE=function(t,e,s){return Gr(this,t,e,!1,s)},kr.prototype.writeDoubleLE=function(t,e,s){return Kr(this,t,e,!0,s)},kr.prototype.writeDoubleBE=function(t,e,s){return Kr(this,t,e,!1,s)},kr.prototype.copy=function(t,e,s,i){if(s||(s=0),i||0===i||(i=this.length),e>=t.length&&(e=t.length),e||(e=0),i>0&&i<s&&(i=s),i===s)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(s<0||s>=this.length)throw new RangeError("sourceStart out of bounds");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),t.length-e<i-s&&(i=t.length-e+s);var r,n=i-s;if(this===t&&s<e&&e<i)for(r=n-1;r>=0;--r)t[r+e]=this[r+s];else if(n<1e3||!kr.TYPED_ARRAY_SUPPORT)for(r=0;r<n;++r)t[r+e]=this[r+s];else Uint8Array.prototype.set.call(t,this.subarray(s,s+n),e);return n},kr.prototype.fill=function(t,e,s,i){if("string"==typeof t){if("string"==typeof e?(i=e,e=0,s=this.length):"string"==typeof s&&(i=s,s=this.length),1===t.length){var r=t.charCodeAt(0);r<256&&(t=r)}if(void 0!==i&&"string"!=typeof i)throw new TypeError("encoding must be a string");if("string"==typeof i&&!kr.isEncoding(i))throw new TypeError("Unknown encoding: "+i)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<s)throw new RangeError("Out of range index");if(s<=e)return this;var n;if(e>>>=0,s=void 0===s?this.length:s>>>0,t||(t=0),"number"==typeof t)for(n=e;n<s;++n)this[n]=t;else{var a=xr(t)?t:tn(new kr(t,i).toString()),h=a.length;for(n=0;n<s-e;++n)this[n+e]=a[n%h]}return this};var Zr=/[^+\/0-9A-Za-z-_]/g;function $r(t){return t<16?"0"+t.toString(16):t.toString(16)}function tn(t,e){var s;e=e||1/0;for(var i=t.length,r=null,n=[],a=0;a<i;++a){if((s=t.charCodeAt(a))>55295&&s<57344){if(!r){if(s>56319){(e-=3)>-1&&n.push(239,191,189);continue}if(a+1===i){(e-=3)>-1&&n.push(239,191,189);continue}r=s;continue}if(s<56320){(e-=3)>-1&&n.push(239,191,189),r=s;continue}s=65536+(r-55296<<10|s-56320)}else r&&(e-=3)>-1&&n.push(239,191,189);if(r=null,s<128){if((e-=1)<0)break;n.push(s)}else if(s<2048){if((e-=2)<0)break;n.push(s>>6|192,63&s|128)}else if(s<65536){if((e-=3)<0)break;n.push(s>>12|224,s>>6&63|128,63&s|128)}else{if(!(s<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;n.push(s>>18|240,s>>12&63|128,s>>6&63|128,63&s|128)}}return n}function en(t){return function(t){var e,s,i,r,n,a;ur||lr();var h=t.length;if(h%4>0)throw new Error("Invalid string. Length must be a multiple of 4");n="="===t[h-2]?2:"="===t[h-1]?1:0,a=new cr(3*h/4-n),i=n>0?h-4:h;var o=0;for(e=0,s=0;e<i;e+=4,s+=3)r=or[t.charCodeAt(e)]<<18|or[t.charCodeAt(e+1)]<<12|or[t.charCodeAt(e+2)]<<6|or[t.charCodeAt(e+3)],a[o++]=r>>16&255,a[o++]=r>>8&255,a[o++]=255&r;return 2===n?(r=or[t.charCodeAt(e)]<<2|or[t.charCodeAt(e+1)]>>4,a[o++]=255&r):1===n&&(r=or[t.charCodeAt(e)]<<10|or[t.charCodeAt(e+1)]<<4|or[t.charCodeAt(e+2)]>>2,a[o++]=r>>8&255,a[o++]=255&r),a}(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(Zr,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function sn(t,e,s,i){for(var r=0;r<i&&!(r+s>=e.length||r>=t.length);++r)e[r+s]=t[r];return r}function rn(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}function nn(t,e){for(var s=0,i=t.length-1;i>=0;i--){var r=t[i];"."===r?t.splice(i,1):".."===r?(t.splice(i,1),s++):s&&(t.splice(i,1),s--)}if(e)for(;s--;s)t.unshift("..");return t}var an=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,hn=function(t){return an.exec(t).slice(1)};function on(){for(var t="",e=!1,s=arguments.length-1;s>=-1&&!e;s--){var i=s>=0?arguments[s]:"/";if("string"!=typeof i)throw new TypeError("Arguments to path.resolve must be strings");i&&(t=i+"/"+t,e="/"===i.charAt(0))}return(e?"/":"")+(t=nn(_n(t.split("/"),(function(t){return!!t})),!e).join("/"))||"."}function cn(t){var e=un(t),s="/"===dn(t,-1);return(t=nn(_n(t.split("/"),(function(t){return!!t})),!e).join("/"))||e||(t="."),t&&s&&(t+="/"),(e?"/":"")+t}function un(t){return"/"===t.charAt(0)}var ln={extname:function(t){return hn(t)[3]},basename:function(t,e){var s=hn(t)[2];return e&&s.substr(-1*e.length)===e&&(s=s.substr(0,s.length-e.length)),s},dirname:function(t){var e=hn(t),s=e[0],i=e[1];return s||i?(i&&(i=i.substr(0,i.length-1)),s+i):"."},sep:"/",delimiter:":",relative:function(t,e){function s(t){for(var e=0;e<t.length&&""===t[e];e++);for(var s=t.length-1;s>=0&&""===t[s];s--);return e>s?[]:t.slice(e,s-e+1)}t=on(t).substr(1),e=on(e).substr(1);for(var i=s(t.split("/")),r=s(e.split("/")),n=Math.min(i.length,r.length),a=n,h=0;h<n;h++)if(i[h]!==r[h]){a=h;break}var o=[];for(h=a;h<i.length;h++)o.push("..");return(o=o.concat(r.slice(a))).join("/")},join:function(){var t=Array.prototype.slice.call(arguments,0);return cn(_n(t,(function(t,e){if("string"!=typeof t)throw new TypeError("Arguments to path.join must be strings");return t})).join("/"))},isAbsolute:un,normalize:cn,resolve:on};function _n(t,e){if(t.filter)return t.filter(e);for(var s=[],i=0;i<t.length;i++)e(t[i],i,t)&&s.push(t[i]);return s}var dn="b"==="ab".substr(-1)?function(t,e,s){return t.substr(e,s)}:function(t,e,s){return e<0&&(e=t.length+e),t.substr(e,s)},fn=s((function(t,e){var s,i=(s="undefined"!=typeof document&&document.currentScript?document.currentScript.src:void 0,function(t){t=void 0!==(t=t||{})?t:{};var e,i={};for(e in t)t.hasOwnProperty(e)&&(i[e]=t[e]);var r=function(t,e){throw e},n=!1,a=!1,h=!1,o=!1,c=!1;n="object"==typeof window,a="function"==typeof importScripts,o="object"==typeof nr&&"object"==typeof nr.versions&&"string"==typeof nr.versions.node,h=o&&!n&&!a,c=!n&&!h&&!a;var u,l,_,d,f,p="";function g(e){return t.locateFile?t.locateFile(e,p):p+e}h?(p=ar+"/",u=function(t,e){var s;return(s=Tt(t))||(d||(d=Zs),f||(f=ln),t=f.normalize(t),s=d.readFileSync(t)),e?s:s.toString()},_=function(t){var e=u(t,!0);return e.buffer||(e=new Uint8Array(e)),B(e.buffer),e},nr.argv.length>1&&nr.argv[1].replace(/\\/g,"/"),nr.argv.slice(2),nr.on("unhandledRejection",Jt),r=function(t){nr.exit(t)},t.inspect=function(){return"[Emscripten Module object]"}):c?("undefined"!=typeof read&&(u=function(t){var e=Tt(t);return e?xt(e):read(t)}),_=function(t){var e;return(e=Tt(t))?e:"function"==typeof readbuffer?new Uint8Array(readbuffer(t)):(B("object"==typeof(e=read(t,"binary"))),e)},"undefined"!=typeof scriptArgs&&scriptArgs,"function"==typeof quit&&(r=function(t){quit(t)}),"undefined"!=typeof print&&("undefined"==typeof console&&(console={}),console.log=print,console.warn=console.error="undefined"!=typeof printErr?printErr:print)):(n||a)&&(a?p=self.location.href:document.currentScript&&(p=document.currentScript.src),s&&(p=s),p=0!==p.indexOf("blob:")?p.substr(0,p.lastIndexOf("/")+1):"",u=function(t){try{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.send(null),e.responseText}catch(e){var s=Tt(t);if(s)return xt(s);throw e}},a&&(_=function(t){try{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.responseType="arraybuffer",e.send(null),new Uint8Array(e.response)}catch(e){var s=Tt(t);if(s)return s;throw e}}),l=function(t,e,s){var i=new XMLHttpRequest;i.open("GET",t,!0),i.responseType="arraybuffer",i.onload=function(){if(200==i.status||0==i.status&&i.response)e(i.response);else{var r=Tt(t);r?e(r.buffer):s()}},i.onerror=s,i.send(null)});var b=t.print||console.log.bind(console),A=t.printErr||console.warn.bind(console);for(e in i)i.hasOwnProperty(e)&&(t[e]=i[e]);i=null,t.arguments&&t.arguments,t.thisProgram&&t.thisProgram,t.quit&&(r=t.quit),new Array(0);var m,k=0,y=function(t){k=t},w=function(){return k},v=8;t.wasmBinary&&t.wasmBinary,t.noExitRuntime&&(m=t.noExitRuntime);var C=!1;function B(t,e){t||Jt("Assertion failed: "+e)}function x(e){var s=t["_"+e];return B(s,"Cannot call unknown function "+e+", make sure it is exported"),s}function S(t,e,s,i,r){var n={string:function(t){var e=0;if(null!=t&&0!==t){var s=1+(t.length<<2);H(t,e=Ft(s),s)}return e},array:function(t){var e=Ft(t.length);return L(t,e),e}},a=x(t),h=[],o=0;if(i)for(var c=0;c<i.length;c++){var u=n[s[c]];u?(0===o&&(o=Ht()),h[c]=u(i[c])):h[c]=i[c]}var l=a.apply(null,h);return l=function(t){return"string"===e?F(t):"boolean"===e?Boolean(t):t}(l),0!==o&&Ot(o),l}var P,T,E,I,R="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0;function M(t,e,s){for(var i=e+s,r=e;t[r]&&!(r>=i);)++r;if(r-e>16&&t.subarray&&R)return R.decode(t.subarray(e,r));for(var n="";e<r;){var a=t[e++];if(128&a){var h=63&t[e++];if(192!=(224&a)){var o=63&t[e++];if((a=224==(240&a)?(15&a)<<12|h<<6|o:(7&a)<<18|h<<12|o<<6|63&t[e++])<65536)n+=String.fromCharCode(a);else{var c=a-65536;n+=String.fromCharCode(55296|c>>10,56320|1023&c)}}else n+=String.fromCharCode((31&a)<<6|h)}else n+=String.fromCharCode(a)}return n}function F(t,e){return t?M(E,t,e):""}function O(t,e,s,i){if(!(i>0))return 0;for(var r=s,n=s+i-1,a=0;a<t.length;++a){var h=t.charCodeAt(a);if(h>=55296&&h<=57343&&(h=65536+((1023&h)<<10)|1023&t.charCodeAt(++a)),h<=127){if(s>=n)break;e[s++]=h}else if(h<=2047){if(s+1>=n)break;e[s++]=192|h>>6,e[s++]=128|63&h}else if(h<=65535){if(s+2>=n)break;e[s++]=224|h>>12,e[s++]=128|h>>6&63,e[s++]=128|63&h}else{if(s+3>=n)break;e[s++]=240|h>>18,e[s++]=128|h>>12&63,e[s++]=128|h>>6&63,e[s++]=128|63&h}}return e[s]=0,s-r}function H(t,e,s){return O(t,E,e,s)}function L(t,e){T.set(t,e)}function D(e){P=e,t.HEAP8=T=new Int8Array(e),t.HEAP16=new Int16Array(e),t.HEAP32=I=new Int32Array(e),t.HEAPU8=E=new Uint8Array(e),t.HEAPU16=new Uint16Array(e),t.HEAPU32=new Uint32Array(e),t.HEAPF32=new Float32Array(e),t.HEAPF64=new Float64Array(e)}"undefined"!=typeof TextDecoder&&new TextDecoder("utf-16le");var U=13920,j=3648,V=t.TOTAL_MEMORY||16777216;function Q(e){for(;e.length>0;){var s=e.shift();if("function"!=typeof s){var i=s.func;"number"==typeof i?void 0===s.arg?t.dynCall_v(i):t.dynCall_vi(i,s.arg):i(void 0===s.arg?null:s.arg)}else s()}}V=(P=t.buffer?t.buffer:new ArrayBuffer(V)).byteLength,D(P),I[j>>2]=U;var W=[],z=[],J=[],Y=[];function q(){if(t.preRun)for("function"==typeof t.preRun&&(t.preRun=[t.preRun]);t.preRun.length;)K(t.preRun.shift());Q(W)}function N(){Q(z)}function X(){Q(J)}function G(){if(t.postRun)for("function"==typeof t.postRun&&(t.postRun=[t.postRun]);t.postRun.length;)Z(t.postRun.shift());Q(Y)}function K(t){W.unshift(t)}function Z(t){Y.unshift(t)}var $=0,tt=null;function et(e){$++,t.monitorRunDependencies&&t.monitorRunDependencies($)}function st(e){if($--,t.monitorRunDependencies&&t.monitorRunDependencies($),0==$&&tt){var s=tt;tt=null,s()}}t.preloadedImages={},t.preloadedAudios={};var it=null,rt="data:application/octet-stream;base64,";function nt(t){return String.prototype.startsWith?t.startsWith(rt):0===t.indexOf(rt)}var at=[function(e){return t.trapOnInstructionFetch(e)},function(e){return t.busRead32(e)},function(e,s){t.busWrite32(e,s)},function(e){return t.busRead16(e)},function(e,s){return t.trapOnBx32(e,s)},function(e,s){t.busWrite16(e,s)}];function ht(t,e,s){return at[t](e,s)}function ot(t,e){return at[t](e)}it="data:application/octet-stream;base64,AAAAAAAAAAARAAoAERERAAAAAAUAAAAAAAAJAAAAAAsAAAAAAAAAABEADwoREREDCgcAARMJCwsAAAkGCwAACwAGEQAAABEREQAAAAAAAAAAAAAAAAAAAAALAAAAAAAAAAARAAoKERERAAoAAAIACQsAAAAJAAsAAAsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAADAAAAAAMAAAAAAkMAAAAAAAMAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4AAAAAAAAAAAAAAA0AAAAEDQAAAAAJDgAAAAAADgAADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAPAAAAAA8AAAAACRAAAAAAABAAABAAABIAAAASEhIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEgAAABISEgAAAAAAAAkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAsAAAAAAAAAAAAAAAoAAAAACgAAAAAJCwAAAAAACwAACwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAAMAAAAAAwAAAAACQwAAAAAAAwAAAwAADAxMjM0NTY3ODlBQkNERUYFAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAQAAAHkNAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAD//////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADwAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABkCwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHRodW1idWxhdG9yAHsgcmV0dXJuIE1vZHVsZS5idXNSZWFkMTYoJDApOyB9AHsgcmV0dXJuIE1vZHVsZS5idXNSZWFkMzIoJDApOyB9AHsgTW9kdWxlLmJ1c1dyaXRlMTYoJDAsICQxKTsgfQB7IE1vZHVsZS5idXNXcml0ZTMyKCQwLCAkMSk7IH0AcGMgaGFzIGxzYml0IHNldCAweCUwOFgKAHsgcmV0dXJuIE1vZHVsZS50cmFwT25JbnN0cnVjdGlvbkZldGNoKCQwKTsgfQAtLS0gMHglMDhYOiAweCUwNFggAGFkYyByJXUsciV1CgBhZGRzIHIldSxyJXUsIzB4JVgKAGFkZHMgciV1LCMweCUwMlgKAGFkZHMgciV1LHIldSxyJXUKAGFkZCByJXUsciV1CgBhZGQgcGMsLi4uIHByb2R1Y2VkIGFuIGFybSBhZGRyZXNzIDB4JTA4WCAweCUwOFgKAGFkZCByJXUsUEMsIzB4JTAyWAoAYWRkIHIldSxTUCwjMHglMDJYCgBhZGQgU1AsIzB4JTAyWAoAYW5kcyByJXUsciV1CgBhc3JzIHIldSxyJXUsIzB4JVgKAGFzcnMgciV1LHIldQoAYmVxIDB4JTA4WAoAYm5lIDB4JTA4WAoAYmNzIDB4JTA4WAoAYmNjIDB4JTA4WAoAYm1pIDB4JTA4WAoAYnBsIDB4JTA4WAoAYnZzIDB4JTA4WAoAYnZjIDB4JTA4WAoAYmhpIDB4JTA4WAoAYmxzIDB4JTA4WAoAYmdlIDB4JTA4WAoAYmx0IDB4JTA4WAoAYmd0IDB4JTA4WAoAYmxlIDB4JTA4WAoAQiAweCUwOFgKAGJpY3MgciV1LHIldQoAYmtwdCAweCUwMlgKAGJsIDB4JTA4WAoAYmx4IHIldQoAY2Fubm90IGJyYW5jaCB0byBhcm0gMHglMDhYIDB4JTA0WAoAYnggciV1CgB7IHJldHVybiBNb2R1bGUudHJhcE9uQngzMigkMCwgJDEpOyB9AGNtbnMgciV1LHIldQoAY21wIHIldSwjMHglMDJYCgBjbXBzIHIldSxyJXUKAGNwcyBUT0RPCgBjcHkgciV1LHIldQoAZW9ycyByJXUsciV1CgBsZG1pYSByJXUhLHsAciV1AH0KAGxkciByJXUsW3IldSwjMHglWF0KAGxkciByJXUsW3IldSxyJXVdCgBsZHIgciV1LFtQQysjMHglWF0KAGxkciByJXUsW1NQKyMweCVYXQoAbGRyYiByJXUsW3IldSwjMHglWF0KAGxkcmIgciV1LFtyJXUsciV1XQoAbGRyaCByJXUsW3IldSwjMHglWF0KAGxkcmggciV1LFtyJXUsciV1XQoAbGRyc2IgciV1LFtyJXUsciV1XQoAbGRyc2ggciV1LFtyJXUsciV1XQoAbHNscyByJXUsciV1LCMweCVYCgBsc2xzIHIldSxyJXUKAGxzcnMgciV1LHIldSwjMHglWAoAbHNycyByJXUsciV1CgBtb3ZzIHIldSwjMHglMDJYCgBtb3ZzIHIldSxyJXUKAG1vdiByJXUsciV1CgBtdWxzIHIldSxyJXUKAG12bnMgciV1LHIldQoAbmVncyByJXUsciV1CgBvcnJzIHIldSxyJXUKAHBvcCB7AHBjAHBvcCB7cmN9IHdpdGggYW4gQVJNIGFkZHJlc3MgcGMgMHglMDhYIHBvcHBlZCAweCUwOFgKAHB1c2ggewBscgBwdXNoIHtscn0gd2l0aCBhbiBBUk0gYWRkcmVzcyBwYyAweCUwOFggcG9wcGVkIDB4JTA4WAoAcmV2IHIldSxyJXUKAHJldjE2IHIldSxyJXUKAHJldnNoIHIldSxyJXUKAHJvcnMgciV1LHIldQoAc2JjIHIldSxyJXUKAHNldGVuZCBub3QgaW1wbGVtZW50ZWQKAHN0bWlhIHIldSEsewBzdHIgciV1LFtyJXUsIzB4JVhdCgBzdHIgciV1LFtyJXUsciV1XQoAc3RyIHIldSxbU1AsIzB4JVhdCgBzdHJiIHIldSxbciV1LCMweCVYXQoAc3RyYiByJXUsW3IldSxyJXVdCgBzdHJoIHIldSxbciV1LCMweCVYXQoAc3RyaCByJXUsW3IldSxyJXVdCgBzdWJzIHIldSxyJXUsIzB4JVgKAHN1YnMgciV1LCMweCUwMlgKAHN1YnMgciV1LHIldSxyJXUKAHN1YiBTUCwjMHglMDJYCgBzd2kgMHglMDJYCgAKCnN3aSAweCUwMlgKAHN4dGIgciV1LHIldQoAc3h0aCByJXUsciV1CgB0c3QgciV1LHIldQoAdXh0YiByJXUsciV1CgB1eHRoIHIldSxyJXUKAGludmFsaWQgaW5zdHJ1Y3Rpb24gMHglMDhYIDB4JTA0WAoALSsgICAwWDB4AChudWxsKQAtMFgrMFggMFgtMHgrMHggMHgAaW5mAElORgBuYW4ATkFOAC4=";var ct=3664;function ut(t){return t}function lt(t){return t.replace(/\b__Z[\w\d_]+/g,(function(t){return t==t?t:t+" ["+t+"]"}))}function _t(){var t=new Error;if(!t.stack){try{throw new Error(0)}catch(e){t=e}if(!t.stack)return"(no stack trace available)"}return t.stack.toString()}function dt(){var e=_t();return t.extraStackTrace&&(e+="\n"+t.extraStackTrace()),lt(e)}var ft={buffers:[null,[],[]],printChar:function(t,e){var s=ft.buffers[t];0===e||10===e?((1===t?b:A)(M(s,0)),s.length=0):s.push(e)},varargs:0,get:function(t){return ft.varargs+=4,I[ft.varargs-4>>2]},getStr:function(){return F(ft.get())},get64:function(){var t=ft.get();return ft.get(),t},getZero:function(){ft.get()}};function pt(t,e){ft.varargs=e;try{return ft.getStreamFromFD(),ft.get(),ft.get(),ft.get(),ft.get(),0}catch(t){return"undefined"!=typeof FS&&t instanceof FS.ErrnoError||Jt(t),-t.errno}}function gt(t,e){ft.varargs=e;try{return ft.getStreamFromFD(),0}catch(t){return"undefined"!=typeof FS&&t instanceof FS.ErrnoError||Jt(t),-t.errno}}function bt(){var e=t._fflush;e&&e(0);var s=ft.buffers;s[1].length&&ft.printChar(1,10),s[2].length&&ft.printChar(2,10)}function At(t,e,s,i){try{for(var r=0,n=0;n<s;n++){for(var a=I[e+8*n>>2],h=I[e+(8*n+4)>>2],o=0;o<h;o++)ft.printChar(t,E[a+o]);r+=h}return I[i>>2]=r,0}catch(t){return"undefined"!=typeof FS&&t instanceof FS.ErrnoError||Jt(t),-t.errno}}function mt(){return At.apply(null,arguments)}function kt(){return T.length}function yt(t){zt(t)}function wt(t,e,s){E.set(E.subarray(e,e+s),t)}function vt(e){return t.___errno_location&&(I[t.___errno_location()>>2]=e),e}function Ct(t){Jt("OOM")}function Bt(t){Ct()}function xt(t){for(var e=[],s=0;s<t.length;s++){var i=t[s];i>255&&(i&=255),e.push(String.fromCharCode(i))}return e.join("")}var St="function"==typeof atob?atob:function(t){var e,s,i,r,n,a,h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o="",c=0;t=t.replace(/[^A-Za-z0-9\+\/\=]/g,"");do{e=h.indexOf(t.charAt(c++))<<2|(r=h.indexOf(t.charAt(c++)))>>4,s=(15&r)<<4|(n=h.indexOf(t.charAt(c++)))>>2,i=(3&n)<<6|(a=h.indexOf(t.charAt(c++))),o+=String.fromCharCode(e),64!==n&&(o+=String.fromCharCode(s)),64!==a&&(o+=String.fromCharCode(i))}while(c<t.length);return o};function Pt(t){if("boolean"==typeof h&&h){var e;try{e=kr.from(t,"base64")}catch(s){e=new kr(t,"base64")}return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}try{for(var s=St(t),i=new Uint8Array(s.length),r=0;r<s.length;++r)i[r]=s.charCodeAt(r);return i}catch(t){throw new Error("Converting base64 string to bytes failed.")}}function Tt(t){if(nt(t))return Pt(t.slice(rt.length))}var Et,It={Math:Math,Int8Array:Int8Array,Int16Array:Int16Array,Int32Array:Int32Array,Uint8Array:Uint8Array,Uint16Array:Uint16Array,Float32Array:Float32Array,Float64Array:Float64Array},Rt={a:Jt,b:y,c:w,d:vt,e:pt,f:gt,g:mt,h:ot,i:ht,j:kt,k:wt,l:Bt,m:yt,n:At,o:Ct,p:ut,q:lt,r:bt,s:_t,t:dt,u:ct,v:j},Mt=function(t,e,s){"use asm";var i=new t.Int8Array(s),r=new t.Int16Array(s),n=new t.Int32Array(s),a=new t.Uint8Array(s),h=new t.Uint16Array(s),o=new t.Float32Array(s),c=new t.Float64Array(s),u=e.u|0,l=e.v|0,_=0,d=0,f=0,p=0,g=0,b=0,A=0,m=0.0,k=t.Math.imul,y=t.Math.clz32,w=e.a,v=e.b,C=e.c,B=e.d,x=e.e,S=e.f,P=e.g,T=e.h,E=e.i,I=e.j,R=e.k,M=e.l,F=e.m,O=e.n,H=e.o,L=e.p,D=e.q,U=e.r,j=e.s,V=e.t,Q=3680,W=13920,z=0.0;function J(t){t=t|0;var e=0;e=Q;Q=Q+t|0;Q=Q+15&-16;return e|0}function Y(){return Q|0}function q(t){t=t|0;Q=t}function N(t,e){t=t|0;e=e|0;Q=t;W=e}function X(t){t=t|0;n[712]=t;return}function G(){return 888}function K(t){t=t|0;var e=0,s=0,i=0,r=0,a=0;n[713]=0;if(!t){r=0;return r|0}e=0;s=0;while(1){a=it()|0;i=(n[713]|0)!=0;s=(a|0)==0?s:a;e=e+1|0;if(i|(a|0)==0^1)break;if(e>>>0>=t>>>0){e=0;r=6;break}}if((r|0)==6)return e|0;a=i?10:s;return a|0}function Z(){n[713]=1;return}function $(t){t=t|0;i[3440]=t;return}function tt(t){t=t|0;var e=0,s=0;s=Q;Q=Q+16|0;e=n[2784+((t&15)<<2)>>2]|0;if((t&15|0)!=15){Q=s;return e|0}if(e&1|0){t=n[160]|0;n[s>>2]=e;mt(t,1028,s)|0}e=e&-2;Q=s;return e|0}function et(t,e){t=t|0;e=e|0;n[2784+((t&15)<<2)>>2]=(t&15|0)==15?e&-2:e;return}function st(){n[714]=4;n[715]=0;n[716]=0;n[717]=0;n[718]=0;return 0}function it(){var t=0,e=0,s=0,r=0,a=0,h=0,o=0,c=0,u=0,l=0,_=0,d=0,f=0;f=Q;Q=Q+1232|0;e=n[711]|0;if(e&1|0){d=n[160]|0;n[f>>2]=e;mt(d,1028,f)|0}t=n[712]|0;if(!t){t=T(0,(e&-2)+-2|0)|0;if(t|0){d=t;Q=f;return d|0}}else if(((e&-2)+-2|0)==(t|0)){d=20;Q=f;return d|0}if((e&-2)>>>0>4026531839&(n[717]|0)!=0){n[717]=0;d=n[709]|0;n[696]=T(1,d|0)|0;n[697]=T(1,d+4|0)|0;n[698]=T(1,d+8|0)|0;n[699]=T(1,d+12|0)|0;n[708]=T(1,d+16|0)|0;n[710]=T(1,d+20|0)|0;s=T(1,d+24|0)|0;n[718]=T(1,d+28|0)|0;n[709]=d+32}else s=e&-2;t=n[714]|0;do{if(t&1){e=n[716]|0;if(!e){n[716]=n[715];n[714]=t|65536;t=t|65536;break}else{n[716]=e+-1;break}}}while(0);if((t&3|0)==3?(t&65536|0)!=0&(n[717]|0)==0:0){r=n[709]|0;e=n[718]|0;t:do{if((r+-4&-268435456|0)==-536870912)switch((r+536813548|0)>>>2|r+536813548<<30|0){case 0:{n[714]=e&65543;if((t&1|0)!=0|(e&1|0)==0)break t;n[716]=n[715];break t}case 1:{n[715]=e&16777215;break t}case 2:{n[716]=e&16777215;break t}case 3:break t;default:break t}else E(2,r+-4|0,e|0)|0}while(0);t:do{if((r+-8&-268435456|0)==-536870912)switch((r+536813544|0)>>>2|r+536813544<<30|0){case 0:{d=n[714]|0;n[714]=s&65543;if((s&1|0)==0|(d&1|0)!=0)break t;n[716]=n[715];break t}case 1:{n[715]=s&16777215;break t}case 2:{n[716]=s&16777215;break t}case 3:break t;default:break t}else E(2,r+-8|0,s|0)|0}while(0);t=n[710]|0;t:do{if((r+-12&-268435456|0)==-536870912)switch((r+536813540|0)>>>2|r+536813540<<30|0){case 0:{d=n[714]|0;n[714]=t&65543;if((t&1|0)==0|(d&1|0)!=0)break t;n[716]=n[715];break t}case 1:{n[715]=t&16777215;break t}case 2:{n[716]=t&16777215;break t}case 3:break t;default:break t}else E(2,r+-12|0,t|0)|0}while(0);t=n[708]|0;t:do{if((r+-16&-268435456|0)==-536870912)switch((r+536813536|0)>>>2|r+536813536<<30|0){case 0:{d=n[714]|0;n[714]=t&65543;if((t&1|0)==0|(d&1|0)!=0)break t;n[716]=n[715];break t}case 1:{n[715]=t&16777215;break t}case 2:{n[716]=t&16777215;break t}case 3:break t;default:break t}else E(2,r+-16|0,t|0)|0}while(0);t=n[699]|0;t:do{if((r+-20&-268435456|0)==-536870912)switch((r+536813532|0)>>>2|r+536813532<<30|0){case 0:{d=n[714]|0;n[714]=t&65543;if((t&1|0)==0|(d&1|0)!=0)break t;n[716]=n[715];break t}case 1:{n[715]=t&16777215;break t}case 2:{n[716]=t&16777215;break t}case 3:break t;default:break t}else E(2,r+-20|0,t|0)|0}while(0);t=n[698]|0;t:do{if((r+-24&-268435456|0)==-536870912)switch((r+536813528|0)>>>2|r+536813528<<30|0){case 0:{d=n[714]|0;n[714]=t&65543;if((t&1|0)==0|(d&1|0)!=0)break t;n[716]=n[715];break t}case 1:{n[715]=t&16777215;break t}case 2:{n[716]=t&16777215;break t}case 3:break t;default:break t}else E(2,r+-24|0,t|0)|0}while(0);t=n[697]|0;t:do{if((r+-28&-268435456|0)==-536870912)switch((r+536813524|0)>>>2|r+536813524<<30|0){case 0:{d=n[714]|0;n[714]=t&65543;if((t&1|0)==0|(d&1|0)!=0)break t;n[716]=n[715];break t}case 1:{n[715]=t&16777215;break t}case 2:{n[716]=t&16777215;break t}case 3:break t;default:break t}else E(2,r+-28|0,t|0)|0}while(0);t=n[696]|0;t:do{if((r+-32&-268435456|0)==-536870912)switch((r+536813520|0)>>>2|r+536813520<<30|0){case 0:{d=n[714]|0;n[714]=t&65543;if((t&1|0)==0|(d&1|0)!=0)break t;n[716]=n[715];break t}case 1:{n[715]=t&16777215;break t}case 2:{n[716]=t&16777215;break t}case 3:break t;default:break t}else E(2,r+-32|0,t|0)|0}while(0);n[709]=r+-32;s=(T(1,60)|0)+2|0;n[710]=-7;n[717]=1}a=s+-2|0;d=T(3,a|0)|0;_=s+2|0;n[711]=_&-2;if(i[3440]|0){l=n[160]|0;n[f+8>>2]=a;n[f+8+4>>2]=d;mt(l,1099,f+8|0)|0}if((d&65472|0)==16704){if(i[3440]|0){_=n[160]|0;n[f+16>>2]=d&7;n[f+16+4>>2]=d>>>3&7;mt(_,1119,f+16|0)|0}e=n[2784+((d&7)<<2)>>2]|0;s=n[2784+((d>>>3&7)<<2)>>2]|0;_=n[718]|0;n[2784+((d&7)<<2)>>2]=s+e+(_>>>29&1);t=(s+e+(_>>>29&1)|0)<0?_|-2147483648:_&2147483647;t=(s+e+(_>>>29&1)|0)==0?t|1073741824:t&-1073741825;n[718]=t;if(!(t&536870912)){d=((s>>>31)+(e>>>31)+(((s&2147483647)+(e&2147483647)|0)>>>31)&2|0)==0?t&-536870913:t|536870912;n[718]=(((s&2147483647)+(e&2147483647)|0)>>>31|0)==(((s>>>31)+(e>>>31)+(((s&2147483647)+(e&2147483647)|0)>>>31)|0)>>>1&1|0)?d&-268435457:d|268435456;d=0;Q=f;return d|0}else{_=(s>>>31)+(e>>>31)+(((s&2147483647)+(e&2147483647)+1|0)>>>31)|0;d=(_&2|0)==0?t&-536870913:t|536870912;n[718]=(((s&2147483647)+(e&2147483647)+1|0)>>>31|0)==(_>>>1&1|0)?d&-268435457:d|268435456;d=0;Q=f;return d|0}}if((d&65024|0)==7168?d>>>6&7|0:0){if(i[3440]|0){_=n[160]|0;n[f+24>>2]=d&7;n[f+24+4>>2]=d>>>3&7;n[f+24+8>>2]=d>>>6&7;mt(_,1132,f+24|0)|0}l=n[2784+((d>>>3&7)<<2)>>2]|0;n[2784+((d&7)<<2)>>2]=l+(d>>>6&7);_=n[718]|0;_=(l+(d>>>6&7)|0)<0?_|-2147483648:_&2147483647;_=(l+(d>>>6&7)|0)==0?_|1073741824:_&-1073741825;_=((((l&2147483647)+(d>>>6&7)|0)>>>31)+(l>>>31)&2|0)==0?_&-536870913:_|536870912;n[718]=(((l&2147483647)+(d>>>6&7)|0)>>>31|0)==(((((l&2147483647)+(d>>>6&7)|0)>>>31)+(l>>>31)|0)>>>1|0)?_&-268435457:_|268435456;d=0;Q=f;return d|0}if((d&63488|0)==12288){if(i[3440]|0){_=n[160]|0;n[f+40>>2]=d>>>8&7;n[f+40+4>>2]=d&255;mt(_,1152,f+40|0)|0}l=n[2784+((d>>>8&7)<<2)>>2]|0;n[2784+((d>>>8&7)<<2)>>2]=l+(d&255);_=n[718]|0;_=(l+(d&255)|0)<0?_|-2147483648:_&2147483647;_=(l+(d&255)|0)==0?_|1073741824:_&-1073741825;_=((((l&2147483647)+(d&255)|0)>>>31)+(l>>>31)&2|0)==0?_&-536870913:_|536870912;n[718]=(((l&2147483647)+(d&255)|0)>>>31|0)==(((((l&2147483647)+(d&255)|0)>>>31)+(l>>>31)|0)>>>1|0)?_&-268435457:_|268435456;d=0;Q=f;return d|0}if((d&65024|0)==6144){if(i[3440]|0){_=n[160]|0;n[f+48>>2]=d&7;n[f+48+4>>2]=d>>>3&7;n[f+48+8>>2]=d>>>6&7;mt(_,1170,f+48|0)|0}_=n[2784+((d>>>3&7)<<2)>>2]|0;l=n[2784+((d>>>6&7)<<2)>>2]|0;n[2784+((d&7)<<2)>>2]=l+_;d=n[718]|0;d=(l+_|0)<0?d|-2147483648:d&2147483647;d=(l+_|0)==0?d|1073741824:d&-1073741825;d=((l>>>31)+(_>>>31)+(((l&2147483647)+(_&2147483647)|0)>>>31)&2|0)==0?d&-536870913:d|536870912;n[718]=(((l&2147483647)+(_&2147483647)|0)>>>31|0)==(((l>>>31)+(_>>>31)+(((l&2147483647)+(_&2147483647)|0)>>>31)|0)>>>1&1|0)?d&-268435457:d|268435456;d=0;Q=f;return d|0}if((d&65280|0)==17408){if(i[3440]|0){l=n[160]|0;n[f+64>>2]=d>>>4&8|d&7;n[f+64+4>>2]=d>>>3&15;mt(l,1188,f+64|0)|0}t=n[2784+((d>>>4&8|d&7)<<2)>>2]|0;if((d>>>4&8|d&7|0)==15){if(t&1|0){l=n[160]|0;n[f+72>>2]=t;mt(l,1028,f+72|0)|0}t=t&-2}e=n[2784+((d>>>3&15)<<2)>>2]|0;if((d>>>3&15|0)==15){if(e&1|0){l=n[160]|0;n[f+80>>2]=e;mt(l,1028,f+80|0)|0}e=e&-2}t=e+t|0;if((d>>>4&8|d&7|0)!=15){n[2784+((d>>>4&8|d&7)<<2)>>2]=t;d=0;Q=f;return d|0}if(!(t&1)){d=n[160]|0;n[f+88>>2]=_;n[f+88+4>>2]=t;mt(d,1201,f+88|0)|0;F(1)}n[711]=t+2&-2;d=0;Q=f;return d|0}e=d&63488;switch(e<<16>>16){case-24576:{if(i[3440]|0){_=n[160]|0;n[f+96>>2]=d>>>8&7;n[f+96+4>>2]=d<<2&1020;mt(_,1251,f+96|0)|0}t=n[711]|0;if(t&1|0){_=n[160]|0;n[f+104>>2]=t;mt(_,1028,f+104|0)|0}n[2784+((d>>>8&7)<<2)>>2]=(t&-4)+(d<<2&1020);d=0;Q=f;return d|0}case-22528:{if(i[3440]|0){_=n[160]|0;n[f+112>>2]=d>>>8&7;n[f+112+4>>2]=d<<2&1020;mt(_,1271,f+112|0)|0}n[2784+((d>>>8&7)<<2)>>2]=(n[709]|0)+(d<<2&1020);d=0;Q=f;return d|0}default:{if((d&65408|0)==45056){if(i[3440]|0){_=n[160]|0;n[f+120>>2]=d<<2&508;mt(_,1291,f+120|0)|0}n[709]=(n[709]|0)+(d<<2&508);d=0;Q=f;return d|0}if((d&65472|0)==16384){if(i[3440]|0){_=n[160]|0;n[f+128>>2]=d&7;n[f+128+4>>2]=d>>>3&7;mt(_,1307,f+128|0)|0}_=n[2784+((d>>>3&7)<<2)>>2]&n[2784+((d&7)<<2)>>2];n[2784+((d&7)<<2)>>2]=_;d=n[718]|0;d=(_|0)<0?d|-2147483648:d&2147483647;n[718]=(_|0)==0?d|1073741824:d&-1073741825;d=0;Q=f;return d|0}if((d&63488|0)==4096){if(i[3440]|0){_=n[160]|0;n[f+136>>2]=d&7;n[f+136+4>>2]=d>>>3&7;n[f+136+8>>2]=d>>>6&31;mt(_,1321,f+136|0)|0}e=n[2784+((d>>>3&7)<<2)>>2]|0;do{if(!(d>>>6&31)){t=n[718]|0;if((e|0)<0){n[718]=t|536870912;n[2784+((d&7)<<2)>>2]=-1;t=t|536870912;h=141;break}else{n[718]=t&-536870913;n[2784+((d&7)<<2)>>2]=0;t=t&1610612735;h=143;break}}else{t=n[718]|0;t=(e&1<<(d>>>6&31)+-1|0)==0?t&-536870913:t|536870912;n[718]=t;e=((e|0)<0?-1<<32-(d>>>6&31):0)|e>>>(d>>>6&31);n[2784+((d&7)<<2)>>2]=e;if((e|0)>=0)if(!e){t=t&1073741823;h=143}else t=t&1073741823;else h=141}}while(0);if((h|0)==141)t=t&1073741823|-2147483648;else if((h|0)==143)t=t|1073741824;n[718]=t;d=0;Q=f;return d|0}if((d&65472|0)==16640){if(i[3440]|0){_=n[160]|0;n[f+152>>2]=d&7;n[f+152+4>>2]=d>>>3&7;mt(_,1341,f+152|0)|0}e=n[2784+((d&7)<<2)>>2]|0;t=n[2784+((d>>>3&7)<<2)>>2]&255;do{if(t){if(t>>>0<32){h=n[718]|0;h=(1<<t+-1&e|0)==0?h&-536870913:h|536870912;n[718]=h;t=((e|0)<0?-1<<32-t:0)|e>>>t;e=h;h=155;break}t=n[718]|0;if((e|0)<0){n[718]=t|536870912;n[2784+((d&7)<<2)>>2]=-1;t=t|-1610612736;h=156;break}else{n[718]=t&-536870913;n[2784+((d&7)<<2)>>2]=0;t=t&536870911;h=158;break}}else{t=e;e=n[718]|0;h=155}}while(0);do{if((h|0)==155){n[2784+((d&7)<<2)>>2]=t;if((t|0)<0){t=e|-2147483648;h=156;break}if(!t){t=e&2147483647;h=158}else t=e&1073741823}}while(0);if((h|0)==156)t=t&-1073741825;else if((h|0)==158)t=t|1073741824;n[718]=t;d=0;Q=f;return d|0}t:do{if((d&61440|0)==53248){r=(((d&128|0)==0?d&255:d|-256)<<1)+_|0;do{switch(d>>>8&15){case 0:{if(i[3440]|0){d=n[160]|0;n[f+160>>2]=r+-1;mt(d,1355,f+160|0)|0}if(!(n[718]&1073741824)){d=0;Q=f;return d|0}n[711]=r+2&-2;d=0;Q=f;return d|0}case 1:{if(i[3440]|0){d=n[160]|0;n[f+168>>2]=r+-1;mt(d,1367,f+168|0)|0}if(n[718]&1073741824|0){d=0;Q=f;return d|0}n[711]=r+2&-2;d=0;Q=f;return d|0}case 2:{if(i[3440]|0){d=n[160]|0;n[f+176>>2]=r+-1;mt(d,1379,f+176|0)|0}if(!(n[718]&536870912)){d=0;Q=f;return d|0}n[711]=r+2&-2;d=0;Q=f;return d|0}case 3:{if(i[3440]|0){d=n[160]|0;n[f+184>>2]=r+-1;mt(d,1391,f+184|0)|0}if(n[718]&536870912|0){d=0;Q=f;return d|0}n[711]=r+2&-2;d=0;Q=f;return d|0}case 4:{if(i[3440]|0){d=n[160]|0;n[f+192>>2]=r+-1;mt(d,1403,f+192|0)|0}if((n[718]|0)>=0){d=0;Q=f;return d|0}n[711]=r+2&-2;d=0;Q=f;return d|0}case 5:{if(i[3440]|0){d=n[160]|0;n[f+200>>2]=r+-1;mt(d,1415,f+200|0)|0}if((n[718]|0)<0){d=0;Q=f;return d|0}n[711]=r+2&-2;d=0;Q=f;return d|0}case 6:{if(i[3440]|0){d=n[160]|0;n[f+208>>2]=r+-1;mt(d,1427,f+208|0)|0}if(!(n[718]&268435456)){d=0;Q=f;return d|0}n[711]=r+2&-2;d=0;Q=f;return d|0}case 7:{if(i[3440]|0){d=n[160]|0;n[f+216>>2]=r+-1;mt(d,1439,f+216|0)|0}if(n[718]&268435456|0){d=0;Q=f;return d|0}n[711]=r+2&-2;d=0;Q=f;return d|0}case 8:{if(i[3440]|0){d=n[160]|0;n[f+224>>2]=r+-1;mt(d,1451,f+224|0)|0}if((n[718]&1610612736|0)!=536870912){d=0;Q=f;return d|0}n[711]=r+2&-2;d=0;Q=f;return d|0}case 9:{if(i[3440]|0){d=n[160]|0;n[f+232>>2]=r+-1;mt(d,1463,f+232|0)|0}if((n[718]&1610612736|0)==536870912){d=0;Q=f;return d|0}n[711]=r+2&-2;d=0;Q=f;return d|0}case 10:{if(i[3440]|0){d=n[160]|0;n[f+240>>2]=r+-1;mt(d,1475,f+240|0)|0}t=n[718]&-1879048192;e:do{if((t|0)<0){switch(t|0){case-1879048192:break e;default:t=0}Q=f;return t|0}else{switch(t|0){case 0:break e;default:t=0}Q=f;return t|0}}while(0);n[711]=r+2&-2;d=0;Q=f;return d|0}case 11:{if(i[3440]|0){d=n[160]|0;n[f+248>>2]=r+-1;mt(d,1487,f+248|0)|0}t=n[718]&-1879048192;e:do{if((t|0)<268435456){switch(t|0){case-2147483648:break e;default:t=0}Q=f;return t|0}else{switch(t|0){case 268435456:break e;default:t=0}Q=f;return t|0}}while(0);n[711]=r+2&-2;d=0;Q=f;return d|0}case 12:{if(i[3440]|0){d=n[160]|0;n[f+256>>2]=r+-1;mt(d,1499,f+256|0)|0}d=n[718]|0;if(d&1073741824|0?1:(((d&-1879048192|0)==0?(d&-1879048192|0)==-1879048192?2:1:(d&-1879048192|0)==-1879048192&1)|0)==0){d=0;Q=f;return d|0}n[711]=r+2&-2;d=0;Q=f;return d|0}case 13:{if(i[3440]|0){d=n[160]|0;n[f+264>>2]=r+-1;mt(d,1511,f+264|0)|0}d=n[718]|0;if((((d&-1879048192|0)==-2147483648?(d&-1879048192|0)==268435456?2:1:(d&-1879048192|0)==268435456&1)|0)==(0-(d>>>30&1)|0)){d=0;Q=f;return d|0}n[711]=r+2&-2;d=0;Q=f;return d|0}default:break t}}while(0)}}while(0);if((d&63488|0)==57344){t=(((d&1024|0)==0?d&2047:d|-2048)<<1)+_|0;if(i[3440]|0){d=n[160]|0;n[f+272>>2]=t+-1;mt(d,1523,f+272|0)|0}n[711]=t+2&-2;d=0;Q=f;return d|0}if((d&65472|0)==17280){if(i[3440]|0){_=n[160]|0;n[f+280>>2]=d&7;n[f+280+4>>2]=d>>>3&7;mt(_,1533,f+280|0)|0}_=n[2784+((d&7)<<2)>>2]&~n[2784+((d>>>3&7)<<2)>>2];n[2784+((d&7)<<2)>>2]=_;d=n[718]|0;d=(_|0)<0?d|-2147483648:d&2147483647;n[718]=(_|0)==0?d|1073741824:d&-1073741825;d=0;Q=f;return d|0}if((d&65280|0)==48640){_=n[160]|0;n[f+288>>2]=d&255;mt(_,1547,f+288|0)|0;d=1;Q=f;return d|0}t:do{if((d&57344|0)==57344){if((d&6144)<4096){switch(d&6144){case 2048:break;default:break t}t=(n[710]|0)+(d<<1&4094)&-4|2;if(i[3440]|0){d=n[160]|0;n[f+304>>2]=t+-3;mt(d,1560,f+304|0)|0}n[710]=s|1;n[711]=t;d=0;Q=f;return d|0}switch(d&6144){case 4096:{if(i[3440]|0)Lt(10,n[160]|0)|0;n[710]=(((d&1024|0)==0?d&2047:d|1046528)<<12)+_;d=0;Q=f;return d|0}case 6144:{t=(n[710]|0)+(d<<1&4094)|0;if(i[3440]|0){d=n[160]|0;n[f+296>>2]=t+-1;mt(d,1560,f+296|0)|0}n[710]=s|1;n[711]=t+2&-2;d=0;Q=f;return d|0}default:break t}}}while(0);switch((d&65415)<<16>>16){case 18304:{if(i[3440]|0){l=n[160]|0;n[f+312>>2]=d>>>3&15;mt(l,1571,f+312|0)|0}t=n[2784+((d>>>3&15)<<2)>>2]|0;if((d>>>3&15|0)==15){if(t&1|0){l=n[160]|0;n[f+320>>2]=t;mt(l,1028,f+320|0)|0}t=t&-2}t=t+2|0;if(!(t&1)){l=n[160]|0;n[f+328>>2]=_;n[f+328+4>>2]=d;mt(l,1580,f+328|0)|0;d=2;Q=f;return d|0}else{n[710]=s|1;n[711]=t&-2;d=0;Q=f;return d|0}}case 18176:{if(i[3440]|0){_=n[160]|0;n[f+336>>2]=d>>>3&15;mt(_,1616,f+336|0)|0}t=n[2784+((d>>>3&15)<<2)>>2]|0;if((d>>>3&15|0)==15){if(t&1|0){d=n[160]|0;n[f+344>>2]=t;mt(d,1028,f+344|0)|0}t=t&-2}t=t+2|0;if(t&1|0){n[711]=t&-2;d=0;Q=f;return d|0}t=E(4,a|0,t|0)|0;if(t|0){d=t;Q=f;return d|0}n[711]=(n[710]|0)+2&-2;d=0;Q=f;return d|0}default:{if((d&65472|0)==17088){if(i[3440]|0){_=n[160]|0;n[f+352>>2]=d&7;n[f+352+4>>2]=d>>>3&7;mt(_,1662,f+352|0)|0}_=n[2784+((d&7)<<2)>>2]|0;l=n[2784+((d>>>3&7)<<2)>>2]|0;d=n[718]|0;d=(l+_|0)<0?d|-2147483648:d&2147483647;d=(l+_|0)==0?d|1073741824:d&-1073741825;d=((l>>>31)+(_>>>31)+(((l&2147483647)+(_&2147483647)|0)>>>31)&2|0)==0?d&-536870913:d|536870912;n[718]=(((l&2147483647)+(_&2147483647)|0)>>>31|0)==(((l>>>31)+(_>>>31)+(((l&2147483647)+(_&2147483647)|0)>>>31)|0)>>>1&1|0)?d&-268435457:d|268435456;d=0;Q=f;return d|0}if((d&63488|0)==10240){if(i[3440]|0){_=n[160]|0;n[f+360>>2]=d>>>8&7;n[f+360+4>>2]=d&255;mt(_,1676,f+360|0)|0}u=n[2784+((d>>>8&7)<<2)>>2]|0;_=n[718]|0;_=(u-(d&255)|0)<0?_|-2147483648:_&2147483647;_=(u-(d&255)|0)==0?_|1073741824:_&-1073741825;l=(u>>>31)+1+((-2147483648-(d&255)+(u&2147483647)|0)>>>31)|0;_=(l&2|0)==0?_&-536870913:_|536870912;n[718]=((-2147483648-(d&255)+(u&2147483647)|0)>>>31|0)==(l>>>1&1|0)?_&-268435457:_|268435456;d=0;Q=f;return d|0}if((d&65472|0)==17024){if(i[3440]|0){_=n[160]|0;n[f+368>>2]=d&7;n[f+368+4>>2]=d>>>3&7;mt(_,1693,f+368|0)|0}u=n[2784+((d&7)<<2)>>2]|0;l=n[2784+((d>>>3&7)<<2)>>2]|0;d=n[718]|0;d=(u-l|0)<0?d|-2147483648:d&2147483647;d=(u-l|0)==0?d|1073741824:d&-1073741825;_=(~l>>>31)+(u>>>31)+(((u&2147483647)+1+(~l&2147483647)|0)>>>31)|0;d=(_&2|0)==0?d&-536870913:d|536870912;n[718]=(((u&2147483647)+1+(~l&2147483647)|0)>>>31|0)==(_>>>1&1|0)?d&-268435457:d|268435456;d=0;Q=f;return d|0}if((d&65280|0)==17664){if(i[3440]|0){_=n[160]|0;n[f+376>>2]=d>>>4&8|d&7;n[f+376+4>>2]=d>>>3&15;mt(_,1693,f+376|0)|0}t=n[2784+((d>>>4&8|d&7)<<2)>>2]|0;if((d>>>4&8|d&7|0)==15){if(t&1|0){_=n[160]|0;n[f+384>>2]=t;mt(_,1028,f+384|0)|0}e=t&-2}else e=t;t=n[2784+((d>>>3&15)<<2)>>2]|0;if((d>>>3&15|0)==15){if(t&1|0){d=n[160]|0;n[f+392>>2]=t;mt(d,1028,f+392|0)|0}t=t&-2}_=e-t|0;d=n[718]|0;d=(_|0)<0?d|-2147483648:d&2147483647;d=(_|0)==0?d|1073741824:d&-1073741825;_=~t;l=((e&2147483647)+1+(_&2147483647)|0)>>>31;_=(_>>>31)+(e>>>31)+l|0;d=(_&2|0)==0?d&-536870913:d|536870912;n[718]=(l|0)==(_>>>1&1|0)?d&-268435457:d|268435456;d=0;Q=f;return d|0}if((d&65512|0)==46688&(i[3440]|0)!=0)_t(1707,9,1,n[160]|0)|0;t=d&65472;switch(t<<16>>16){case 17920:{if(i[3440]|0){_=n[160]|0;n[f+400>>2]=d&7;n[f+400+4>>2]=d>>>3&7;mt(_,1717,f+400|0)|0}n[2784+((d&7)<<2)>>2]=n[2784+((d>>>3&7)<<2)>>2];d=0;Q=f;return d|0}case 16448:{if(i[3440]|0){_=n[160]|0;n[f+408>>2]=d&7;n[f+408+4>>2]=d>>>3&7;mt(_,1730,f+408|0)|0}_=n[2784+((d>>>3&7)<<2)>>2]^n[2784+((d&7)<<2)>>2];n[2784+((d&7)<<2)>>2]=_;d=n[718]|0;d=(_|0)<0?d|-2147483648:d&2147483647;n[718]=(_|0)==0?d|1073741824:d&-1073741825;d=0;Q=f;return d|0}default:{t:do{if(e<<16>>16<26624){switch(e<<16>>16){case-14336:break;default:break t}if(!(i[3440]|0))e=d&1;else{e=n[160]|0;n[f+416>>2]=d>>>8&7;mt(e,1744,f+416|0)|0;if(!(d&1))t=0;else{n[f+424>>2]=0;mt(e,1757,f+424|0)|0;t=1}if(d&2){if(t|0)Lt(44,e)|0;n[f+1168>>2]=1;mt(e,1757,f+1168|0)|0;t=t+1|0}if(d&4){if(t|0)Lt(44,e)|0;n[f+1176>>2]=2;mt(e,1757,f+1176|0)|0;t=t+1|0}if(d&8){if(t|0)Lt(44,e)|0;n[f+1184>>2]=3;mt(e,1757,f+1184|0)|0;t=t+1|0}if(d&16){if(t|0)Lt(44,e)|0;n[f+1192>>2]=4;mt(e,1757,f+1192|0)|0;t=t+1|0}if(d&32){if(t|0)Lt(44,e)|0;n[f+1200>>2]=5;mt(e,1757,f+1200|0)|0;t=t+1|0}if(d&64){if(t|0)Lt(44,e)|0;n[f+1208>>2]=6;mt(e,1757,f+1208|0)|0;t=t+1|0}if(d&128|0){if(t|0)Lt(44,e)|0;n[f+1216>>2]=7;mt(e,1757,f+1216|0)|0}_t(1761,2,1,e)|0;e=d&1}t=n[2784+((d>>>8&7)<<2)>>2]|0;if(e){n[696]=T(1,t|0)|0;t=t+4|0}if(d&2){n[697]=T(1,t|0)|0;t=t+4|0}if(d&4){n[698]=T(1,t|0)|0;t=t+4|0}if(d&8){n[699]=T(1,t|0)|0;t=t+4|0}if(d&16){n[700]=T(1,t|0)|0;t=t+4|0}if(d&32){n[701]=T(1,t|0)|0;t=t+4|0}if(d&64){n[702]=T(1,t|0)|0;t=t+4|0}if(d&128){n[703]=T(1,t|0)|0;t=t+4|0}if(1<<(d>>>8&7)&d|0){d=0;Q=f;return d|0}n[2784+((d>>>8&7)<<2)>>2]=t;d=0;Q=f;return d|0}else{switch(e<<16>>16){case 26624:break;default:break t}if(i[3440]|0){_=n[160]|0;n[f+432>>2]=d&7;n[f+432+4>>2]=d>>>3&7;n[f+432+8>>2]=d>>>4&124;mt(_,1764,f+432|0)|0}n[2784+((d&7)<<2)>>2]=T(1,(n[2784+((d>>>3&7)<<2)>>2]|0)+(d>>>4&124)|0)|0;d=0;Q=f;return d|0}}while(0);if((d&65024|0)==22528){if(i[3440]|0){_=n[160]|0;n[f+448>>2]=d&7;n[f+448+4>>2]=d>>>3&7;n[f+448+8>>2]=d>>>6&7;mt(_,1785,f+448|0)|0}n[2784+((d&7)<<2)>>2]=T(1,(n[2784+((d>>>6&7)<<2)>>2]|0)+(n[2784+((d>>>3&7)<<2)>>2]|0)|0)|0;d=0;Q=f;return d|0}t:do{if(e<<16>>16<18432){switch(e<<16>>16){case-26624:break;default:break t}if(i[3440]|0){_=n[160]|0;n[f+480>>2]=d>>>8&7;n[f+480+4>>2]=d<<2&1020;mt(_,1824,f+480|0)|0}n[2784+((d>>>8&7)<<2)>>2]=T(1,(n[709]|0)+(d<<2&1020)|0)|0;d=0;Q=f;return d|0}else{if(e<<16>>16>=30720){switch(e<<16>>16){case 30720:break;default:break t}if(i[3440]|0){_=n[160]|0;n[f+488>>2]=d&7;n[f+488+4>>2]=d>>>3&7;n[f+488+8>>2]=d>>>6&31;mt(_,1844,f+488|0)|0}l=(n[2784+((d>>>3&7)<<2)>>2]|0)+(d>>>6&31)|0;_=T(3,l&-2|0)|0;n[2784+((d&7)<<2)>>2]=((l&1|0)==0?_:_>>>8)&255;d=0;Q=f;return d|0}switch(e<<16>>16){case 18432:break;default:break t}if(i[3440]|0){_=n[160]|0;n[f+464>>2]=d>>>8&7;n[f+464+4>>2]=d<<2&1020;mt(_,1804,f+464|0)|0}t=n[711]|0;if(t&1|0){_=n[160]|0;n[f+472>>2]=t;mt(_,1028,f+472|0)|0}n[2784+((d>>>8&7)<<2)>>2]=T(1,(t&-4)+(d<<2&1020)|0)|0;d=0;Q=f;return d|0}}while(0);if((d&65024|0)==23552){if(i[3440]|0){_=n[160]|0;n[f+504>>2]=d&7;n[f+504+4>>2]=d>>>3&7;n[f+504+8>>2]=d>>>6&7;mt(_,1866,f+504|0)|0}l=(n[2784+((d>>>6&7)<<2)>>2]|0)+(n[2784+((d>>>3&7)<<2)>>2]|0)|0;_=T(3,l&-2|0)|0;n[2784+((d&7)<<2)>>2]=((l&1|0)==0?_:_>>>8)&255;d=0;Q=f;return d|0}if((d&63488|0)==34816){if(i[3440]|0){_=n[160]|0;n[f+520>>2]=d&7;n[f+520+4>>2]=d>>>3&7;n[f+520+8>>2]=d>>>5&62;mt(_,1886,f+520|0)|0}n[2784+((d&7)<<2)>>2]=(T(3,(n[2784+((d>>>3&7)<<2)>>2]|0)+(d>>>5&62)|0)|0)&65535;d=0;Q=f;return d|0}switch((d&65024)<<16>>16){case 23040:{if(i[3440]|0){_=n[160]|0;n[f+536>>2]=d&7;n[f+536+4>>2]=d>>>3&7;n[f+536+8>>2]=d>>>6&7;mt(_,1908,f+536|0)|0}n[2784+((d&7)<<2)>>2]=(T(3,(n[2784+((d>>>6&7)<<2)>>2]|0)+(n[2784+((d>>>3&7)<<2)>>2]|0)|0)|0)&65535;d=0;Q=f;return d|0}case 22016:{if(i[3440]|0){_=n[160]|0;n[f+552>>2]=d&7;n[f+552+4>>2]=d>>>3&7;n[f+552+8>>2]=d>>>6&7;mt(_,1928,f+552|0)|0}l=(n[2784+((d>>>6&7)<<2)>>2]|0)+(n[2784+((d>>>3&7)<<2)>>2]|0)|0;_=T(3,l&-2|0)|0;_=(l&1|0)==0?_:_>>>8;n[2784+((d&7)<<2)>>2]=(_&128|0)==0?_&255:_|-256;d=0;Q=f;return d|0}case 24064:{if(i[3440]|0){_=n[160]|0;n[f+568>>2]=d&7;n[f+568+4>>2]=d>>>3&7;n[f+568+8>>2]=d>>>6&7;mt(_,1949,f+568|0)|0}_=T(3,(n[2784+((d>>>6&7)<<2)>>2]|0)+(n[2784+((d>>>3&7)<<2)>>2]|0)|0)|0;n[2784+((d&7)<<2)>>2]=(_&32768|0)==0?_&65535:_|-65536;d=0;Q=f;return d|0}default:{if(!(d&63488)){if(i[3440]|0){_=n[160]|0;n[f+584>>2]=d&7;n[f+584+4>>2]=d>>>3&7;n[f+584+8>>2]=d>>>6&31;mt(_,1970,f+584|0)|0}t=n[2784+((d>>>3&7)<<2)>>2]|0;if(!(d>>>6&31))e=n[718]|0;else{e=n[718]|0;e=(t&1<<32-(d>>>6&31)|0)==0?e&-536870913:e|536870912;n[718]=e;t=t<<(d>>>6&31)}n[2784+((d&7)<<2)>>2]=t;d=(t|0)<0?e|-2147483648:e&2147483647;n[718]=(t|0)==0?d|1073741824:d&-1073741825;d=0;Q=f;return d|0}if((d&65472|0)==16512){if(i[3440]|0){_=n[160]|0;n[f+600>>2]=d&7;n[f+600+4>>2]=d>>>3&7;mt(_,1990,f+600|0)|0}t=n[2784+((d&7)<<2)>>2]|0;e=n[2784+((d>>>3&7)<<2)>>2]&255;do{if(!e){e=n[718]|0;h=357}else{if(e>>>0<32){h=n[718]|0;h=(1<<32-e&t|0)==0?h&-536870913:h|536870912;n[718]=h;t=t<<e;e=h;h=357;break}if((e|0)==32){_=n[718]|0;t=(t&1|0)==0?_&-536870913:_|536870912}else t=n[718]&-536870913;n[718]=t;n[2784+((d&7)<<2)>>2]=0;t=t&1073741823;h=360}}while(0);do{if((h|0)==357){n[2784+((d&7)<<2)>>2]=t;if((t|0)>=0)if(!t){t=e&2147483647;h=360;break}else{t=e&1073741823;break}else{t=e&1073741823|-2147483648;break}}}while(0);if((h|0)==360)t=t|1073741824;n[718]=t;d=0;Q=f;return d|0}if((d&63488|0)==2048){if(i[3440]|0){_=n[160]|0;n[f+608>>2]=d&7;n[f+608+4>>2]=d>>>3&7;n[f+608+8>>2]=d>>>6&31;mt(_,2004,f+608|0)|0}t=n[2784+((d>>>3&7)<<2)>>2]|0;do{if(d>>>6&31){e=n[718]|0;e=(t&1<<(d>>>6&31)+-1|0)==0?e&-536870913:e|536870912;n[718]=e;n[2784+((d&7)<<2)>>2]=t>>>(d>>>6&31);if((t>>>(d>>>6&31)|0)>=0)if(!(t>>>(d>>>6&31))){t=e&1073741823;h=370;break}else{t=e&1073741823;break}else{t=e&1073741823|-2147483648;break}}else{h=n[718]|0;t=(t|0)>-1?h&-536870913:h|536870912;n[718]=t;n[2784+((d&7)<<2)>>2]=0;t=t&2147483647;h=370}}while(0);if((h|0)==370)t=t|1073741824;n[718]=t;d=0;Q=f;return d|0}if((d&65472|0)==16576){if(i[3440]|0){_=n[160]|0;n[f+624>>2]=d&7;n[f+624+4>>2]=d>>>3&7;mt(_,2024,f+624|0)|0}t=n[2784+((d&7)<<2)>>2]|0;e=n[2784+((d>>>3&7)<<2)>>2]&255;do{if(!e){e=n[718]|0;h=383}else{if(e>>>0<32){h=n[718]|0;h=(1<<e+-1&t|0)==0?h&-536870913:h|536870912;n[718]=h;t=t>>>e;e=h;h=383;break}if((e|0)==32){_=n[718]|0;t=(t|0)>-1?_&-536870913:_|536870912}else t=n[718]&-536870913;n[718]=t;n[2784+((d&7)<<2)>>2]=0;t=t&1073741823;h=386}}while(0);do{if((h|0)==383){n[2784+((d&7)<<2)>>2]=t;if((t|0)>=0)if(!t){t=e&2147483647;h=386;break}else{t=e&1073741823;break}else{t=e&1073741823|-2147483648;break}}}while(0);if((h|0)==386)t=t|1073741824;n[718]=t;d=0;Q=f;return d|0}if((d&63488|0)==8192){if(i[3440]|0){_=n[160]|0;n[f+632>>2]=d>>>8&7;n[f+632+4>>2]=d&255;mt(_,2038,f+632|0)|0}n[2784+((d>>>8&7)<<2)>>2]=d&255;_=n[718]&1073741823;n[718]=(d&255|0)==0?_|1073741824:_;d=0;Q=f;return d|0}if((d&65472|0)==7168){if(i[3440]|0){_=n[160]|0;n[f+640>>2]=d&7;n[f+640+4>>2]=d>>>3&7;mt(_,2056,f+640|0)|0}_=n[2784+((d>>>3&7)<<2)>>2]|0;n[2784+((d&7)<<2)>>2]=_;d=n[718]|0;d=(_|0)<0?d|-2147483648:d&2147483647;n[718]=((_|0)==0?d|1073741824:d&-1879048193)&-805306369;d=0;Q=f;return d|0}if((d&65280|0)==17920){if(i[3440]|0){_=n[160]|0;n[f+648>>2]=d>>>4&8|d&7;n[f+648+4>>2]=d>>>3&15;mt(_,2070,f+648|0)|0}t=n[2784+((d>>>3&15)<<2)>>2]|0;if((d>>>3&15|0)==15){if(t&1|0){_=n[160]|0;n[f+656>>2]=t;mt(_,1028,f+656|0)|0}t=t&-2}if((d>>>4&8|d&7|0)==15){n[711]=t+2&-2;d=0;Q=f;return d|0}else{n[2784+((d>>>4&8|d&7)<<2)>>2]=t;d=0;Q=f;return d|0}}switch(((d&65472)+-16960|0)>>>6&67108863|0){case 4:{if(i[3440]|0){_=n[160]|0;n[f+664>>2]=d&7;n[f+664+4>>2]=d>>>3&7;mt(_,2083,f+664|0)|0}_=k(n[2784+((d>>>3&7)<<2)>>2]|0,n[2784+((d&7)<<2)>>2]|0)|0;n[2784+((d&7)<<2)>>2]=_;d=n[718]|0;d=(_|0)<0?d|-2147483648:d&2147483647;n[718]=(_|0)==0?d|1073741824:d&-1073741825;d=0;Q=f;return d|0}case 6:{if(i[3440]|0){_=n[160]|0;n[f+672>>2]=d&7;n[f+672+4>>2]=d>>>3&7;mt(_,2097,f+672|0)|0}_=n[2784+((d>>>3&7)<<2)>>2]|0;n[2784+((d&7)<<2)>>2]=~_;d=n[718]|0;d=(_|0)>-1?d|-2147483648:d&2147483647;n[718]=(_|0)==-1?d|1073741824:d&-1073741825;d=0;Q=f;return d|0}case 0:{if(i[3440]|0){_=n[160]|0;n[f+680>>2]=d&7;n[f+680+4>>2]=d>>>3&7;mt(_,2111,f+680|0)|0}l=n[2784+((d>>>3&7)<<2)>>2]|0;n[2784+((d&7)<<2)>>2]=0-l;d=n[718]|0;d=(0-l|0)<0?d|-2147483648:d&2147483647;d=(l|0)==0?d|1073741824:d&-1073741825;_=(((~l&2147483647)+1|0)>>>31)+(~l>>>31)|0;d=(_&2|0)==0?d&-536870913:d|536870912;n[718]=(((~l&2147483647)+1|0)>>>31|0)==(_>>>1|0)?d&-268435457:d|268435456;d=0;Q=f;return d|0}case 3:{if(i[3440]|0){_=n[160]|0;n[f+688>>2]=d&7;n[f+688+4>>2]=d>>>3&7;mt(_,2125,f+688|0)|0}_=n[2784+((d>>>3&7)<<2)>>2]|n[2784+((d&7)<<2)>>2];n[2784+((d&7)<<2)>>2]=_;d=n[718]|0;d=(_|0)<0?d|-2147483648:d&2147483647;n[718]=(_|0)==0?d|1073741824:d&-1073741825;d=0;Q=f;return d|0}default:switch((d&65024)<<16>>16){case-17408:{if(!(i[3440]|0))e=d&1;else{e=n[160]|0;_t(2139,5,1,e)|0;if(!(d&1))t=0;else{n[f+696>>2]=0;mt(e,1757,f+696|0)|0;t=1}if(d&2){if(t|0)Lt(44,e)|0;n[f+1056>>2]=1;mt(e,1757,f+1056|0)|0;t=t+1|0}if(d&4){if(t|0)Lt(44,e)|0;n[f+1064>>2]=2;mt(e,1757,f+1064|0)|0;t=t+1|0}if(d&8){if(t|0)Lt(44,e)|0;n[f+1072>>2]=3;mt(e,1757,f+1072|0)|0;t=t+1|0}if(d&16){if(t|0)Lt(44,e)|0;n[f+1080>>2]=4;mt(e,1757,f+1080|0)|0;t=t+1|0}if(d&32){if(t|0)Lt(44,e)|0;n[f+1088>>2]=5;mt(e,1757,f+1088|0)|0;t=t+1|0}if(d&64){if(t|0)Lt(44,e)|0;n[f+1096>>2]=6;mt(e,1757,f+1096|0)|0;t=t+1|0}if(d&128){if(t|0)Lt(44,e)|0;n[f+1104>>2]=7;mt(e,1757,f+1104|0)|0;t=t+1|0}if(d&256|0){if(t|0)Lt(44,e)|0;_t(2145,2,1,e)|0}_t(1761,2,1,e)|0;e=d&1}t=n[709]|0;if(e){n[696]=T(1,t|0)|0;t=t+4|0}if(d&2){n[697]=T(1,t|0)|0;t=t+4|0}if(d&4){n[698]=T(1,t|0)|0;t=t+4|0}if(d&8){n[699]=T(1,t|0)|0;t=t+4|0}if(d&16){n[700]=T(1,t|0)|0;t=t+4|0}if(d&32){n[701]=T(1,t|0)|0;t=t+4|0}if(d&64){n[702]=T(1,t|0)|0;t=t+4|0}if(d&128){n[703]=T(1,t|0)|0;t=t+4|0}if(d&256){e=T(1,t|0)|0;if(!(e&1)){d=n[160]|0;n[f+704>>2]=_;n[f+704+4>>2]=e;mt(d,2148,f+704|0)|0;e=e&-2}n[711]=e+2&-2;t=t+4|0}n[709]=t;d=0;Q=f;return d|0}case-19456:{l=n[160]|0;if(!(i[3440]|0)){t=d&2;e=d&4;s=d&8;r=d&16;a=d&32;h=d&64;o=d&128;u=d&256;c=d&1}else{_t(2202,6,1,l)|0;if(!(d&1))t=0;else{n[f+712>>2]=0;mt(l,1757,f+712|0)|0;t=1}if(d&2){if(t|0)Lt(44,l)|0;n[f+1112>>2]=1;mt(l,1757,f+1112|0)|0;t=t+1|0}if(d&4){if(t|0)Lt(44,l)|0;n[f+1120>>2]=2;mt(l,1757,f+1120|0)|0;t=t+1|0}if(d&8){if(t|0)Lt(44,l)|0;n[f+1128>>2]=3;mt(l,1757,f+1128|0)|0;t=t+1|0}if(d&16){if(t|0)Lt(44,l)|0;n[f+1136>>2]=4;mt(l,1757,f+1136|0)|0;t=t+1|0}if(d&32){if(t|0)Lt(44,l)|0;n[f+1144>>2]=5;mt(l,1757,f+1144|0)|0;t=t+1|0}if(d&64){if(t|0)Lt(44,l)|0;n[f+1152>>2]=6;mt(l,1757,f+1152|0)|0;t=t+1|0}if(d&128){if(t|0)Lt(44,l)|0;n[f+1160>>2]=7;mt(l,1757,f+1160|0)|0;t=t+1|0}if(d&256|0){if(t|0)Lt(44,l)|0;_t(2209,2,1,l)|0}_t(1761,2,1,l)|0;t=d&2;e=d&4;s=d&8;r=d&16;a=d&32;h=d&64;o=d&128;u=d&256;c=d&1}a=(n[709]|0)-(c+(t>>>1)+(e>>>2)+(s>>>3)+(r>>>4)+(a>>>5)+(h>>>6)+(o>>>7)+(u>>>8)<<2)|0;t=a;s=0;r=1;while(1){if(!(r&d))e=t;else{e=n[2784+(s<<2)>>2]|0;t:do{if((t&-268435456|0)==-536870912){c=t+536813552|0;switch(c>>>2|c<<30|0){case 0:{c=n[714]|0;n[714]=e&65543;if((e&1|0)==0|(c&1|0)!=0)break t;n[716]=n[715];break t}case 1:{n[715]=e&16777215;break t}case 2:{n[716]=e&16777215;break t}case 3:break t;default:break t}}else E(2,t|0,e|0)|0}while(0);e=t+4|0}s=s+1|0;if((s|0)==8)break;else{t=e;r=r<<1&254}}do{if(u|0){t=n[710]|0;t:do{if((e&-268435456|0)==-536870912){d=e+536813552|0;switch(d>>>2|d<<30|0){case 0:{d=n[714]|0;n[714]=t&65543;if((t&1|0)==0|(d&1|0)!=0)break t;n[716]=n[715];break t}case 1:{n[715]=t&16777215;break t}case 2:{n[716]=t&16777215;break t}case 3:break t;default:break t}}else E(2,e|0,t|0)|0}while(0);if(t&1|0)break;n[f+720>>2]=_;n[f+720+4>>2]=t;mt(l,2212,f+720|0)|0}}while(0);n[709]=a;d=0;Q=f;return d|0}default:{t:do{if(t<<16>>16<-17728)switch(t<<16>>16){case-17920:{if(i[3440]|0){_=n[160]|0;n[f+728>>2]=d&7;n[f+728+4>>2]=d>>>3&7;mt(_,2267,f+728|0)|0}n[2784+((d&7)<<2)>>2]=Xt(n[2784+((d>>>3&7)<<2)>>2]|0)|0;d=0;Q=f;return d|0}case-17856:{if(i[3440]|0){_=n[160]|0;n[f+736>>2]=d&7;n[f+736+4>>2]=d>>>3&7;mt(_,2280,f+736|0)|0}_=n[2784+((d>>>3&7)<<2)>>2]|0;n[2784+((d&7)<<2)>>2]=_<<8&65280|_>>>8&255|_>>>16<<24|_>>>24<<16;d=0;Q=f;return d|0}default:break t}else{if(t<<16>>16<16768){switch(t<<16>>16){case-17728:break;default:break t}if(i[3440]|0){_=n[160]|0;n[f+744>>2]=d&7;n[f+744+4>>2]=d>>>3&7;mt(_,2295,f+744|0)|0}_=n[2784+((d>>>3&7)<<2)>>2]|0;n[2784+((d&7)<<2)>>2]=(_&128|0)==0?_<<8&65280|_>>>8&255:_<<8&65280|_>>>8&255|-65536;d=0;Q=f;return d|0}switch(t<<16>>16){case 16832:break;case 16768:{if(i[3440]|0){_=n[160]|0;n[f+760>>2]=d&7;n[f+760+4>>2]=d>>>3&7;mt(_,2324,f+760|0)|0}e=n[2784+((d&7)<<2)>>2]|0;s=n[2784+((d>>>3&7)<<2)>>2]|0;_=n[718]|0;n[2784+((d&7)<<2)>>2]=e-s+-1+(_>>>29&1);t=(e-s+-1+(_>>>29&1)|0)<0?_|-2147483648:_&2147483647;t=(e-s+-1+(_>>>29&1)|0)==0?t|1073741824:t&-1073741825;n[718]=t;if(!(t&536870912)){_=(~s>>>31)+(e>>>31)+(((~s&2147483647)+(e&2147483647)|0)>>>31)|0;d=(_&2|0)==0?t&-536870913:t|536870912;n[718]=(((~s&2147483647)+(e&2147483647)|0)>>>31|0)==(_>>>1&1|0)?d&-268435457:d|268435456;d=0;Q=f;return d|0}else{_=(~s>>>31)+(e>>>31)+(((~s&2147483647)+(e&2147483647)+1|0)>>>31)|0;d=(_&2|0)==0?t&-536870913:t|536870912;n[718]=(((~s&2147483647)+(e&2147483647)+1|0)>>>31|0)==(_>>>1&1|0)?d&-268435457:d|268435456;d=0;Q=f;return d|0}}default:break t}if(i[3440]|0){_=n[160]|0;n[f+752>>2]=d&7;n[f+752+4>>2]=d>>>3&7;mt(_,2310,f+752|0)|0}t=n[2784+((d&7)<<2)>>2]|0;e=n[2784+((d>>>3&7)<<2)>>2]|0;do{if(e&255)if(!(e&31)){e=n[718]|0;e=(t|0)>-1?e&-536870913:e|536870912;n[718]=e;break}else{_=n[718]|0;_=(1<<(e&31)+-1&t|0)==0?_&-536870913:_|536870912;n[718]=_;t=t<<32-(e&31)|t>>>(e&31);e=_;break}else e=n[718]|0}while(0);n[2784+((d&7)<<2)>>2]=t;d=(t|0)<0?e|-2147483648:e&2147483647;n[718]=(t|0)==0?d|1073741824:d&-1073741825;d=0;Q=f;return d|0}}while(0);if((d&65527|0)==46672){_t(2337,23,1,n[160]|0)|0;d=1;Q=f;return d|0}t:do{if(e<<16>>16<24576){switch(e<<16>>16){case-16384:break;default:break t}if(i[3440]|0){e=n[160]|0;n[f+768>>2]=d>>>8&7;mt(e,2361,f+768|0)|0;if(!(d&1))t=0;else{n[f+776>>2]=0;mt(e,1757,f+776|0)|0;t=1}if(d&2){if(t|0)Lt(44,e)|0;n[f+1e3>>2]=1;mt(e,1757,f+1e3|0)|0;t=t+1|0}if(d&4){if(t|0)Lt(44,e)|0;n[f+1008>>2]=2;mt(e,1757,f+1008|0)|0;t=t+1|0}if(d&8){if(t|0)Lt(44,e)|0;n[f+1016>>2]=3;mt(e,1757,f+1016|0)|0;t=t+1|0}if(d&16){if(t|0)Lt(44,e)|0;n[f+1024>>2]=4;mt(e,1757,f+1024|0)|0;t=t+1|0}if(d&32){if(t|0)Lt(44,e)|0;n[f+1032>>2]=5;mt(e,1757,f+1032|0)|0;t=t+1|0}if(d&64){if(t|0)Lt(44,e)|0;n[f+1040>>2]=6;mt(e,1757,f+1040|0)|0;t=t+1|0}if(d&128|0){if(t|0)Lt(44,e)|0;n[f+1048>>2]=7;mt(e,1757,f+1048|0)|0}_t(1761,2,1,e)|0}s=1;r=0;t=n[2784+((d>>>8&7)<<2)>>2]|0;while(1){if(s&d){e=n[2784+(r<<2)>>2]|0;e:do{if((t&-268435456|0)==-536870912){_=t+536813552|0;switch(_>>>2|_<<30|0){case 0:{_=n[714]|0;n[714]=e&65543;if((e&1|0)==0|(_&1|0)!=0)break e;n[716]=n[715];break e}case 1:{n[715]=e&16777215;break e}case 2:{n[716]=e&16777215;break e}case 3:break e;default:break e}}else E(2,t|0,e|0)|0}while(0);t=t+4|0}r=r+1|0;if((r|0)==8)break;else s=s<<1&254}n[2784+((d>>>8&7)<<2)>>2]=t;d=0;Q=f;return d|0}else{switch(e<<16>>16){case 24576:break;default:break t}if(i[3440]|0){_=n[160]|0;n[f+784>>2]=d&7;n[f+784+4>>2]=d>>>3&7;n[f+784+8>>2]=d>>>4&124;mt(_,2374,f+784|0)|0}e=(n[2784+((d>>>3&7)<<2)>>2]|0)+(d>>>4&124)|0;t=n[2784+((d&7)<<2)>>2]|0;if((e&-268435456|0)!=-536870912){E(2,e|0,t|0)|0;d=0;Q=f;return d|0}switch((e+536813552|0)>>>2|e+536813552<<30|0){case 0:{d=n[714]|0;n[714]=t&65543;if((t&1|0)==0|(d&1|0)!=0){d=0;Q=f;return d|0}n[716]=n[715];d=0;Q=f;return d|0}case 1:{n[715]=t&16777215;d=0;Q=f;return d|0}case 2:{n[716]=t&16777215;d=0;Q=f;return d|0}case 3:{d=0;Q=f;return d|0}default:{d=0;Q=f;return d|0}}}}while(0);if((d&65024|0)==20480){if(i[3440]|0){_=n[160]|0;n[f+800>>2]=d&7;n[f+800+4>>2]=d>>>3&7;n[f+800+8>>2]=d>>>6&7;mt(_,2395,f+800|0)|0}e=(n[2784+((d>>>6&7)<<2)>>2]|0)+(n[2784+((d>>>3&7)<<2)>>2]|0)|0;t=n[2784+((d&7)<<2)>>2]|0;if((e&-268435456|0)!=-536870912){E(2,e|0,t|0)|0;d=0;Q=f;return d|0}switch((e+536813552|0)>>>2|e+536813552<<30|0){case 0:{d=n[714]|0;n[714]=t&65543;if((t&1|0)==0|(d&1|0)!=0){d=0;Q=f;return d|0}n[716]=n[715];d=0;Q=f;return d|0}case 1:{n[715]=t&16777215;d=0;Q=f;return d|0}case 2:{n[716]=t&16777215;d=0;Q=f;return d|0}case 3:{d=0;Q=f;return d|0}default:{d=0;Q=f;return d|0}}}t:do{if(e<<16>>16<28672){switch(e<<16>>16){case-28672:break;default:break t}if(i[3440]|0){_=n[160]|0;n[f+816>>2]=d>>>8&7;n[f+816+4>>2]=d<<2&1020;mt(_,2414,f+816|0)|0}e=(n[709]|0)+(d<<2&1020)|0;t=n[2784+((d>>>8&7)<<2)>>2]|0;if((e&-268435456|0)!=-536870912){E(2,e|0,t|0)|0;d=0;Q=f;return d|0}switch((e+536813552|0)>>>2|e+536813552<<30|0){case 0:{d=n[714]|0;n[714]=t&65543;if((t&1|0)==0|(d&1|0)!=0){d=0;Q=f;return d|0}n[716]=n[715];d=0;Q=f;return d|0}case 1:{n[715]=t&16777215;d=0;Q=f;return d|0}case 2:{n[716]=t&16777215;d=0;Q=f;return d|0}case 3:{d=0;Q=f;return d|0}default:{d=0;Q=f;return d|0}}}else{switch(e<<16>>16){case 28672:break;default:break t}if(i[3440]|0){_=n[160]|0;n[f+824>>2]=d&7;n[f+824+4>>2]=d>>>3&7;n[f+824+8>>2]=d>>>6&31;mt(_,2434,f+824|0)|0}s=(n[2784+((d>>>3&7)<<2)>>2]|0)+(d>>>6&31)|0;t=n[2784+((d&7)<<2)>>2]|0;e=T(3,s&-2|0)|0;if(!(s&1))t=e&65280|t&255;else t=e&255|t<<8;E(5,s&-2|0,t&65535|0)|0;d=0;Q=f;return d|0}}while(0);if((d&65024|0)==21504){if(i[3440]|0){_=n[160]|0;n[f+840>>2]=d&7;n[f+840+4>>2]=d>>>3&7;n[f+840+8>>2]=d>>>6&7;mt(_,2456,f+840|0)|0}s=(n[2784+((d>>>6&7)<<2)>>2]|0)+(n[2784+((d>>>3&7)<<2)>>2]|0)|0;t=n[2784+((d&7)<<2)>>2]|0;e=T(3,s&-2|0)|0;if(!(s&1))t=e&65280|t&255;else t=e&255|t<<8;E(5,s&-2|0,t&65535|0)|0;d=0;Q=f;return d|0}if((d&63488|0)==32768){if(i[3440]|0){_=n[160]|0;n[f+856>>2]=d&7;n[f+856+4>>2]=d>>>3&7;n[f+856+8>>2]=d>>>5&62;mt(_,2476,f+856|0)|0}E(5,(n[2784+((d>>>3&7)<<2)>>2]|0)+(d>>>5&62)|0,n[2784+((d&7)<<2)>>2]&65535|0)|0;d=0;Q=f;return d|0}t:do{if((d&65024)<<16>>16<20992){switch((d&65024)<<16>>16){case 7680:break;default:break t}if(i[3440]|0){_=n[160]|0;n[f+888>>2]=d&7;n[f+888+4>>2]=d>>>3&7;n[f+888+8>>2]=d>>>6&7;mt(_,2518,f+888|0)|0}u=n[2784+((d>>>3&7)<<2)>>2]|0;n[2784+((d&7)<<2)>>2]=u-(d>>>6&7);_=n[718]|0;_=(u-(d>>>6&7)|0)<0?_|-2147483648:_&2147483647;_=(u-(d>>>6&7)|0)==0?_|1073741824:_&-1073741825;l=(u>>>31)+1+((-2147483648-(d>>>6&7)+(u&2147483647)|0)>>>31)|0;_=(l&2|0)==0?_&-536870913:_|536870912;n[718]=((-2147483648-(d>>>6&7)+(u&2147483647)|0)>>>31|0)==(l>>>1&1|0)?_&-268435457:_|268435456;d=0;Q=f;return d|0}else{switch((d&65024)<<16>>16){case 20992:break;default:break t}if(i[3440]|0){_=n[160]|0;n[f+872>>2]=d&7;n[f+872+4>>2]=d>>>3&7;n[f+872+8>>2]=d>>>6&7;mt(_,2498,f+872|0)|0}E(5,(n[2784+((d>>>6&7)<<2)>>2]|0)+(n[2784+((d>>>3&7)<<2)>>2]|0)|0,n[2784+((d&7)<<2)>>2]&65535|0)|0;d=0;Q=f;return d|0}}while(0);if((d&63488|0)==14336){if(i[3440]|0){_=n[160]|0;n[f+904>>2]=d>>>8&7;n[f+904+4>>2]=d&255;mt(_,2538,f+904|0)|0}u=n[2784+((d>>>8&7)<<2)>>2]|0;n[2784+((d>>>8&7)<<2)>>2]=u-(d&255);_=n[718]|0;_=(u-(d&255)|0)<0?_|-2147483648:_&2147483647;_=(u-(d&255)|0)==0?_|1073741824:_&-1073741825;l=(u>>>31)+1+((-2147483648-(d&255)+(u&2147483647)|0)>>>31)|0;_=(l&2|0)==0?_&-536870913:_|536870912;n[718]=((-2147483648-(d&255)+(u&2147483647)|0)>>>31|0)==(l>>>1&1|0)?_&-268435457:_|268435456;d=0;Q=f;return d|0}if((d&65024|0)==6656){if(i[3440]|0){_=n[160]|0;n[f+912>>2]=d&7;n[f+912+4>>2]=d>>>3&7;n[f+912+8>>2]=d>>>6&7;mt(_,2556,f+912|0)|0}u=n[2784+((d>>>3&7)<<2)>>2]|0;l=n[2784+((d>>>6&7)<<2)>>2]|0;n[2784+((d&7)<<2)>>2]=u-l;d=n[718]|0;d=(u-l|0)<0?d|-2147483648:d&2147483647;d=(u-l|0)==0?d|1073741824:d&-1073741825;_=(~l>>>31)+(u>>>31)+(((u&2147483647)+1+(~l&2147483647)|0)>>>31)|0;d=(_&2|0)==0?d&-536870913:d|536870912;n[718]=(((u&2147483647)+1+(~l&2147483647)|0)>>>31|0)==(_>>>1&1|0)?d&-268435457:d|268435456;d=0;Q=f;return d|0}if((d&65408|0)==45184){if(i[3440]|0){_=n[160]|0;n[f+928>>2]=d<<2&508;mt(_,2574,f+928|0)|0}n[709]=(n[709]|0)-(d<<2&508);d=0;Q=f;return d|0}if((d&65280|0)==57088){if(i[3440]|0){_=n[160]|0;n[f+936>>2]=d&255;mt(_,2590,f+936|0)|0}if((d&255|0)==204){n[696]=n[718];d=0;Q=f;return d|0}else{_=n[160]|0;n[f+944>>2]=d&255;mt(_,2602,f+944|0)|0;d=1;Q=f;return d|0}}t:do{if(t<<16>>16>=-19840){if(t<<16>>16<-19776){switch(t<<16>>16){case-19840:break;default:break t}if(i[3440]|0){_=n[160]|0;n[f+984>>2]=d&7;n[f+984+4>>2]=d>>>3&7;mt(_,2671,f+984|0)|0}n[2784+((d&7)<<2)>>2]=n[2784+((d>>>3&7)<<2)>>2]&65535;d=0;Q=f;return d|0}if(t<<16>>16<16896){switch(t<<16>>16){case-19776:break;default:break t}if(i[3440]|0){_=n[160]|0;n[f+976>>2]=d&7;n[f+976+4>>2]=d>>>3&7;mt(_,2657,f+976|0)|0}n[2784+((d&7)<<2)>>2]=n[2784+((d>>>3&7)<<2)>>2]&255;d=0;Q=f;return d|0}else{switch(t<<16>>16){case 16896:break;default:break t}if(i[3440]|0){_=n[160]|0;n[f+968>>2]=d&7;n[f+968+4>>2]=d>>>3&7;mt(_,2644,f+968|0)|0}_=n[2784+((d>>>3&7)<<2)>>2]&n[2784+((d&7)<<2)>>2];d=n[718]|0;d=(_|0)<0?d|-2147483648:d&2147483647;n[718]=(_|0)==0?d|1073741824:d&-1073741825;d=0;Q=f;return d|0}}else switch(t<<16>>16){case-19904:{if(i[3440]|0){_=n[160]|0;n[f+952>>2]=d&7;n[f+952+4>>2]=d>>>3&7;mt(_,2616,f+952|0)|0}_=n[2784+((d>>>3&7)<<2)>>2]|0;n[2784+((d&7)<<2)>>2]=(_&128|0)==0?_&255:_|-256;d=0;Q=f;return d|0}case-19968:{if(i[3440]|0){_=n[160]|0;n[f+960>>2]=d&7;n[f+960+4>>2]=d>>>3&7;mt(_,2630,f+960|0)|0}_=n[2784+((d>>>3&7)<<2)>>2]|0;n[2784+((d&7)<<2)>>2]=(_&32768|0)==0?_&65535:_|-65536;d=0;Q=f;return d|0}default:break t}}while(0);_=n[160]|0;n[f+992>>2]=a;n[f+992+4>>2]=d;mt(_,2685,f+992|0)|0;d=1;Q=f;return d|0}}}}}}}}}}}return 0}function rt(t){t=t|0;var e=0;e=Q;Q=Q+16|0;n[e>>2]=ct(n[t+60>>2]|0)|0;t=ht(S(6,e|0)|0)|0;Q=e;return t|0}function nt(t,e,s){t=t|0;e=e|0;s=s|0;var i=0,r=0,a=0,h=0,o=0,c=0,u=0;h=Q;Q=Q+32|0;a=n[t+28>>2]|0;n[h>>2]=a;a=(n[t+20>>2]|0)-a|0;n[h+4>>2]=a;n[h+8>>2]=e;n[h+12>>2]=s;r=2;e=a+s|0;a=h;while(1){if(!((P(n[t+60>>2]|0,a|0,r|0,h+16|0)|0)<<16>>16))i=n[h+16>>2]|0;else{n[h+16>>2]=-1;i=-1}if((e|0)==(i|0)){e=6;break}if((i|0)<0){e=8;break}u=n[a+4>>2]|0;c=i>>>0>u>>>0;o=c?a+8|0:a;u=i-(c?u:0)|0;n[o>>2]=(n[o>>2]|0)+u;n[o+4>>2]=(n[o+4>>2]|0)-u;r=r+(c<<31>>31)|0;e=e-i|0;a=o}if((e|0)==6){u=n[t+44>>2]|0;n[t+16>>2]=u+(n[t+48>>2]|0);n[t+28>>2]=u;n[t+20>>2]=u}else if((e|0)==8){n[t+16>>2]=0;n[t+28>>2]=0;n[t+20>>2]=0;n[t>>2]=n[t>>2]|32;if((r|0)==2)s=0;else s=s-(n[a+4>>2]|0)|0}Q=h;return s|0}function at(t,e,s,i){t=t|0;e=e|0;s=s|0;i=i|0;var r=0;r=Q;Q=Q+32|0;n[r+8>>2]=n[t+60>>2];n[r+8+4>>2]=s;n[r+8+8>>2]=e;n[r+8+12>>2]=r;n[r+8+16>>2]=i;if((ht(x(140,r+8|0)|0)|0)<0){n[r>>2]=-1;n[r+4>>2]=-1;t=-1;e=-1}else{t=n[r+4>>2]|0;e=n[r>>2]|0}v(t|0);Q=r;return e|0}function ht(t){t=t|0;if(t>>>0>4294963200){n[(ot()|0)>>2]=0-t;t=-1}return t|0}function ot(){return 2940}function ct(t){t=t|0;return t|0}function ut(t){t=t|0;return(t+-48|0)>>>0<10|0}function lt(){return 644}function _t(t,e,s,i){t=t|0;e=e|0;s=s|0;i=i|0;var r=0,a=0;r=k(s,e)|0;s=(e|0)==0?0:s;if((n[i+76>>2]|0)>-1){a=(ft(i)|0)==0;t=bt(t,r,i)|0;if(!a)dt(i)}else t=bt(t,r,i)|0;if((t|0)!=(r|0))s=(t>>>0)/(e>>>0)|0;return s|0}function dt(t){t=t|0;return}function ft(t){t=t|0;return 1}function pt(t,e){t=t|0;e=e|0;var s=0,r=0,h=0,o=0;o=Q;Q=Q+16|0;i[o>>0]=e;s=n[t+16>>2]|0;if(!s)if(!(gt(t)|0)){r=n[t+16>>2]|0;h=4}else s=-1;else{r=s;h=4}do{if((h|0)==4){s=n[t+20>>2]|0;if(s>>>0<r>>>0?(e&255|0)!=(i[t+75>>0]|0):0){n[t+20>>2]=s+1;i[s>>0]=e;s=e&255;break}if((le[n[t+36>>2]&1](t,o,1)|0)==1)s=a[o>>0]|0;else s=-1}}while(0);Q=o;return s|0}function gt(t){t=t|0;var e=0;e=i[t+74>>0]|0;i[t+74>>0]=e+255|e;e=n[t>>2]|0;if(!(e&8)){n[t+8>>2]=0;n[t+4>>2]=0;e=n[t+44>>2]|0;n[t+28>>2]=e;n[t+20>>2]=e;n[t+16>>2]=e+(n[t+48>>2]|0);t=0}else{n[t>>2]=e|32;t=-1}return t|0}function bt(t,e,s){t=t|0;e=e|0;s=s|0;var r=0,a=0,h=0,o=0;r=n[s+16>>2]|0;if(!r)if(!(gt(s)|0)){a=n[s+16>>2]|0;h=5}else r=0;else{a=r;h=5}t:do{if((h|0)==5){r=n[s+20>>2]|0;if((a-r|0)>>>0<e>>>0){r=le[n[s+36>>2]&1](s,t,e)|0;break}e:do{if((i[s+75>>0]|0)<0|(e|0)==0){o=0;a=t}else{h=e;while(1){a=h+-1|0;if((i[t+a>>0]|0)==10)break;if(!a){o=0;a=t;break e}else h=a}r=le[n[s+36>>2]&1](s,t,h)|0;if(r>>>0<h>>>0)break t;o=h;a=t+h|0;e=e-h|0;r=n[s+20>>2]|0}}while(0);Gt(r|0,a|0,e|0)|0;n[s+20>>2]=(n[s+20>>2]|0)+e;r=o+e|0}}while(0);return r|0}function At(t,e,s){t=t|0;e=e|0;s=s|0;var r=0,a=0,h=0;t:do{if((s|0)!=0&(t&3|0)!=0){r=s;while(1){if((i[t>>0]|0)==(e&255)<<24>>24){a=6;break t}t=t+1|0;s=r+-1|0;if((s|0)!=0&(t&3|0)!=0)r=s;else{r=s;s=(s|0)!=0;a=5;break}}}else{r=s;s=(s|0)!=0;a=5}}while(0);if((a|0)==5)if(s)a=6;else a=16;t:do{if((a|0)==6){if((i[t>>0]|0)==(e&255)<<24>>24)if(!r){a=16;break}else break;s=k(e&255,16843009)|0;e:do{if(r>>>0>3)while(1){h=n[t>>2]^s;if((h&-2139062144^-2139062144)&h+-16843009|0)break e;t=t+4|0;r=r+-4|0;if(r>>>0<=3){a=11;break}}else a=11}while(0);if((a|0)==11)if(!r){a=16;break}while(1){if((i[t>>0]|0)==(e&255)<<24>>24)break t;r=r+-1|0;if(!r){a=16;break}else t=t+1|0}}}while(0);if((a|0)==16)t=0;return t|0}function mt(t,e,s){t=t|0;e=e|0;s=s|0;var i=0;i=Q;Q=Q+16|0;n[i>>2]=s;s=kt(t,e,i)|0;Q=i;return s|0}function kt(t,e,s){t=t|0;e=e|0;s=s|0;return vt(t,e,s,1,1)|0}function yt(t,e,s,r,h,o){t=t|0;e=+e;s=s|0;r=r|0;h=h|0;o=o|0;var c=0,u=0,l=0,_=0,d=0.0,f=0,p=0,g=0,b=0,A=0,m=0,y=0,w=0,v=0,B=0,x=0,S=0;S=Q;Q=Q+560|0;n[S+536>>2]=0;x=S+540+12|0;Ot(e)|0;c=C()|0;if((c|0)<0){Ot(-e)|0;e=-e;B=1;w=2737;c=C()|0}else{B=(h&2049|0)!=0&1;w=(h&2048|0)==0?(h&1|0)==0?2738:2743:2740}do{if(0==0&(c&2146435072|0)==2146435072){c=B+3|0;It(t,32,s,c,h&-65537);Bt(t,w,B);Bt(t,e!=e|0.0!=0.0?o&32|0?2764:2768:o&32|0?2756:2760,3);It(t,32,s,c,h^8192)}else{d=+Ht(e,S+536|0)*2.0;if(d!=0.0)n[S+536>>2]=(n[S+536>>2]|0)+-1;if((o|32|0)==97){p=(o&32|0)==0?w:w+9|0;f=B|2;do{if(!(r>>>0>11|(12-r|0)==0)){e=8.0;c=12-r|0;do{c=c+-1|0;e=e*16.0}while((c|0)!=0);if((i[p>>0]|0)==45){e=-(e+(-d-e));break}else{e=d+e-e;break}}else e=d}while(0);u=n[S+536>>2]|0;c=(u|0)<0?0-u|0:u;c=Et(c,((c|0)<0)<<31>>31,x)|0;if((c|0)==(x|0)){i[S+540+11>>0]=48;c=S+540+11|0}i[c+-1>>0]=(u>>31&2)+43;_=c+-2|0;i[_>>0]=o+15;c=S;do{B=~~e;u=c+1|0;i[c>>0]=o&32|a[480+B>>0];e=(e-+(B|0))*16.0;if((u-S|0)==1?!((h&8|0)==0&((r|0)<1&e==0.0)):0){i[u>>0]=46;c=c+2|0}else c=u}while(e!=0.0);l=c;if((r|0)!=0?(-2-S+l|0)<(r|0):0){r=r+2+x-_|0;c=x;u=_}else{r=x-S-_+l|0;c=x;u=_}x=r+f|0;It(t,32,s,x,h);Bt(t,p,f);It(t,48,s,x,h^65536);Bt(t,S,l-S|0);c=c-u|0;It(t,48,r-(l-S+c)|0,0,0);Bt(t,_,c);It(t,32,s,x,h^8192);c=x;break}u=(r|0)<0?6:r;if(d!=0.0){c=(n[S+536>>2]|0)+-28|0;n[S+536>>2]=c;e=d*268435456.0}else{e=d;c=n[S+536>>2]|0}v=(c|0)<0?S+32|0:S+32+288|0;r=v;do{m=~~e>>>0;n[r>>2]=m;r=r+4|0;e=(e-+(m>>>0))*1.0e9}while(e!=0.0);if((c|0)>0){f=v;while(1){_=(c|0)<29?c:29;c=r+-4|0;if(c>>>0>=f>>>0){l=0;do{b=Nt(n[c>>2]|0,0,_|0)|0;b=Qt(b|0,C()|0,l|0,0)|0;A=C()|0;l=Yt(b|0,A|0,1e9,0)|0;m=Vt(l|0,C()|0,1e9,0)|0;m=Wt(b|0,A|0,m|0,C()|0)|0;C()|0;n[c>>2]=m;c=c+-4|0}while(c>>>0>=f>>>0);if(l){m=f+-4|0;n[m>>2]=l;l=m}else l=f}else l=f;t:do{if(r>>>0>l>>>0){c=r;while(1){r=c+-4|0;if(n[r>>2]|0){r=c;break t}if(r>>>0>l>>>0)c=r;else break}}}while(0);c=(n[S+536>>2]|0)-_|0;n[S+536>>2]=c;if((c|0)>0)f=l;else break}}else l=v;if((c|0)<0){do{f=0-c|0;f=(f|0)<9?f:9;if(l>>>0<r>>>0){_=0;c=l;do{m=n[c>>2]|0;n[c>>2]=(m>>>f)+_;_=k(m&(1<<f)+-1,1e9>>>f)|0;c=c+4|0}while(c>>>0<r>>>0);c=(n[l>>2]|0)==0?l+4|0:l;if(!_)l=c;else{n[r>>2]=_;r=r+4|0;l=c}}else l=(n[l>>2]|0)==0?l+4|0:l;c=(o|32|0)==102?v:l;r=(r-c>>2|0)>(((u+25|0)/9|0)+1|0)?c+(((u+25|0)/9|0)+1<<2)|0:r;c=(n[S+536>>2]|0)+f|0;n[S+536>>2]=c}while((c|0)<0);c=l}else c=l;if(c>>>0<r>>>0){l=(v-c>>2)*9|0;f=n[c>>2]|0;if(f>>>0>=10){_=10;do{_=_*10|0;l=l+1|0}while(f>>>0>=_>>>0)}}else l=0;_=u-((o|32|0)==102?0:l)+(((u|0)!=0&(o|32|0)==103)<<31>>31)|0;if((_|0)<(((r-v>>2)*9|0)+-9|0)){p=v+4+(((_+9216|0)/9|0)+-1024<<2)|0;_=_+9216-(((_+9216|0)/9|0)*9|0)|0;if((_|0)<8){f=10;while(1){f=f*10|0;if((_|0)<7)_=_+1|0;else break}}else f=10;b=n[p>>2]|0;_=(b>>>0)/(f>>>0)|0;A=b-(k(_,f)|0)|0;g=(p+4|0)==(r|0);if(!(g&(A|0)==0)){e=(_&1|0)==0?9007199254740992.0:9007199254740994.0;m=f>>>1;d=A>>>0<m>>>0?.5:g&(A|0)==(m|0)?1.0:1.5;if(B){m=(i[w>>0]|0)==45;d=m?-d:d;e=m?-e:e}n[p>>2]=b-A;if(e+d!=e){m=b-A+f|0;n[p>>2]=m;if(m>>>0>999999999){_=p;while(1){l=_+-4|0;n[_>>2]=0;if(l>>>0<c>>>0){c=c+-4|0;n[c>>2]=0}m=(n[l>>2]|0)+1|0;n[l>>2]=m;if(m>>>0>999999999)_=l;else{p=l;break}}}l=(v-c>>2)*9|0;f=n[c>>2]|0;if(f>>>0<10)_=p;else{_=10;do{_=_*10|0;l=l+1|0}while(f>>>0>=_>>>0);_=p}}else _=p}else _=p;A=_+4|0;r=r>>>0>A>>>0?A:r;A=c}else A=c;p=0-l|0;t:do{if(r>>>0>A>>>0)while(1){c=r+-4|0;if(n[c>>2]|0){m=r;b=1;break t}if(c>>>0>A>>>0)r=c;else{m=c;b=0;break}}else{m=r;b=0}}while(0);do{if((o|32|0)==103){if((l|0)>-5?(u+(((u|0)!=0^1)&1)|0)>(l|0):0){_=o+-1|0;u=u+(((u|0)!=0^1)&1)+-1-l|0}else{_=o+-2|0;u=u+(((u|0)!=0^1)&1)+-1|0}if(!(h&8)){if(b?(y=n[m+-4>>2]|0,(y|0)!=0):0)if(!((y>>>0)%10|0)){c=0;r=10;do{r=r*10|0;c=c+1|0}while(!((y>>>0)%(r>>>0)|0|0))}else c=0;else c=9;r=((m-v>>2)*9|0)+-9|0;if((_|32|0)==102){o=r-c|0;o=(o|0)>0?o:0;u=(u|0)<(o|0)?u:o;break}else{o=r+l-c|0;o=(o|0)>0?o:0;u=(u|0)<(o|0)?u:o;break}}}else _=o}while(0);g=(u|0)!=0;r=g?1:h>>>3&1;f=(_|32|0)==102;if(f){p=0;c=(l|0)>0?l:0}else{c=(l|0)<0?p:l;c=Et(c,((c|0)<0)<<31>>31,x)|0;if((x-c|0)<2)do{c=c+-1|0;i[c>>0]=48}while((x-c|0)<2);i[c+-1>>0]=(l>>31&2)+43;c=c+-2|0;i[c>>0]=_;p=c;c=x-c|0}c=B+1+u+r+c|0;It(t,32,s,c,h);Bt(t,w,B);It(t,48,s,c,h^65536);if(f){_=A>>>0>v>>>0?v:A;l=_;do{r=Et(n[l>>2]|0,0,S+9|0)|0;if((l|0)==(_|0)){if((r|0)==(S+9|0)){i[S+8>>0]=48;r=S+8|0}}else if(r>>>0>S>>>0){Kt(S|0,48,r-S|0)|0;do{r=r+-1|0}while(r>>>0>S>>>0)}Bt(t,r,S+9-r|0);l=l+4|0}while(l>>>0<=v>>>0);if(!((h&8|0)==0&(g^1)))Bt(t,2772,1);if(l>>>0<m>>>0&(u|0)>0)while(1){r=Et(n[l>>2]|0,0,S+9|0)|0;if(r>>>0>S>>>0){Kt(S|0,48,r-S|0)|0;do{r=r+-1|0}while(r>>>0>S>>>0)}Bt(t,r,(u|0)<9?u:9);l=l+4|0;r=u+-9|0;if(!(l>>>0<m>>>0&(u|0)>9)){u=r;break}else u=r}It(t,48,u+9|0,9,0)}else{f=b?m:A+4|0;if(A>>>0<f>>>0&(u|0)>-1){_=A;do{r=Et(n[_>>2]|0,0,S+9|0)|0;if((r|0)==(S+9|0)){i[S+8>>0]=48;r=S+8|0}do{if((_|0)==(A|0)){l=r+1|0;Bt(t,r,1);if((h&8|0)==0&(u|0)<1){r=l;break}Bt(t,2772,1);r=l}else{if(r>>>0<=S>>>0)break;Kt(S|0,48,r+(0-S)|0)|0;do{r=r+-1|0}while(r>>>0>S>>>0)}}while(0);B=S+9-r|0;Bt(t,r,(u|0)>(B|0)?B:u);u=u-B|0;_=_+4|0}while(_>>>0<f>>>0&(u|0)>-1)}It(t,48,u+18|0,18,0);Bt(t,p,x-p|0)}It(t,32,s,c,h^8192)}}while(0);Q=S;return((c|0)<(s|0)?s:c)|0}function wt(t,e){t=t|0;e=e|0;var s=0.0,i=0;i=(n[e>>2]|0)+(8-1)&~(8-1);s=+c[i>>3];n[e>>2]=i+8;c[t>>3]=s;return}function vt(t,e,s,r,a){t=t|0;e=e|0;s=s|0;r=r|0;a=a|0;var h=0,o=0,c=0,u=0;u=Q;Q=Q+224|0;h=u+160|0;o=h+40|0;do{n[h>>2]=0;h=h+4|0}while((h|0)<(o|0));n[u+208>>2]=n[s>>2];if((Ct(0,e,u+208|0,u+80|0,u+160|0,r,a)|0)<0)s=-1;else{if((n[t+76>>2]|0)>-1)c=ft(t)|0;else c=0;o=n[t>>2]|0;if((i[t+74>>0]|0)<1)n[t>>2]=o&-33;if(!(n[t+48>>2]|0)){h=n[t+44>>2]|0;n[t+44>>2]=u;n[t+28>>2]=u;n[t+20>>2]=u;n[t+48>>2]=80;n[t+16>>2]=u+80;s=Ct(t,e,u+208|0,u+80|0,u+160|0,r,a)|0;if(h){le[n[t+36>>2]&1](t,0,0)|0;s=(n[t+20>>2]|0)==0?-1:s;n[t+44>>2]=h;n[t+48>>2]=0;n[t+16>>2]=0;n[t+28>>2]=0;n[t+20>>2]=0}}else s=Ct(t,e,u+208|0,u+80|0,u+160|0,r,a)|0;h=n[t>>2]|0;n[t>>2]=h|o&32;if(c|0)dt(t);s=(h&32|0)==0?s:-1}Q=u;return s|0}function Ct(t,e,s,a,h,o,u){t=t|0;e=e|0;s=s|0;a=a|0;h=h|0;o=o|0;u=u|0;var l=0,_=0,d=0,f=0,p=0,g=0,b=0,A=0,m=0,k=0,y=0,w=0,v=0,B=0,x=0,S=0;x=Q;Q=Q+64|0;n[x+56>>2]=e;w=x+40|0;l=0;e=0;d=0;t:while(1){do{do{if((e|0)>-1)if((l|0)>(2147483647-e|0)){n[(ot()|0)>>2]=75;e=-1;break}else{e=l+e|0;break}}while(0);b=n[x+56>>2]|0;l=i[b>>0]|0;if(!(l<<24>>24)){y=92;break t}_=b;e:while(1){switch(l<<24>>24){case 37:{y=10;break e}case 0:{l=_;break e}default:{}}k=_+1|0;n[x+56>>2]=k;l=i[k>>0]|0;_=k}e:do{if((y|0)==10){y=0;l=_;do{if((i[_+1>>0]|0)!=37)break e;l=l+1|0;_=_+2|0;n[x+56>>2]=_}while((i[_>>0]|0)==37)}}while(0);l=l-b|0;if(t|0)Bt(t,b,l)}while((l|0)!=0);k=(ut(i[(n[x+56>>2]|0)+1>>0]|0)|0)==0;_=n[x+56>>2]|0;if(!k?(i[_+2>>0]|0)==36:0){A=(i[_+1>>0]|0)+-48|0;p=1;l=3}else{A=-1;p=d;l=1}l=_+l|0;n[x+56>>2]=l;_=i[l>>0]|0;if(((_<<24>>24)+-32|0)>>>0>31|(1<<(_<<24>>24)+-32&75913|0)==0)f=0;else{d=0;f=(_<<24>>24)+-32|0;do{d=1<<f|d;l=l+1|0;n[x+56>>2]=l;_=i[l>>0]|0;f=(_<<24>>24)+-32|0}while(!(f>>>0>31|(1<<f&75913|0)==0));f=d}if(_<<24>>24==42){if((ut(i[l+1>>0]|0)|0)!=0?(B=n[x+56>>2]|0,(i[B+2>>0]|0)==36):0){n[h+((i[B+1>>0]|0)+-48<<2)>>2]=10;l=n[a+((i[B+1>>0]|0)+-48<<3)>>2]|0;d=1;_=B+3|0}else{if(p|0){e=-1;break}if(t|0){k=(n[s>>2]|0)+(4-1)&~(4-1);l=n[k>>2]|0;n[s>>2]=k+4}else l=0;d=0;_=(n[x+56>>2]|0)+1|0}n[x+56>>2]=_;g=(l|0)<0;m=g?0-l|0:l;g=g?f|8192:f;k=d}else{l=xt(x+56|0)|0;if((l|0)<0){e=-1;break}m=l;g=f;k=p;_=n[x+56>>2]|0}do{if((i[_>>0]|0)==46){l=_+1|0;if((i[l>>0]|0)!=42){n[x+56>>2]=l;l=xt(x+56|0)|0;_=n[x+56>>2]|0;break}if(ut(i[_+2>>0]|0)|0?(v=n[x+56>>2]|0,(i[v+3>>0]|0)==36):0){n[h+((i[v+2>>0]|0)+-48<<2)>>2]=10;l=n[a+((i[v+2>>0]|0)+-48<<3)>>2]|0;n[x+56>>2]=v+4;_=v+4|0;break}if(k|0){e=-1;break t}if(t|0){p=(n[s>>2]|0)+(4-1)&~(4-1);l=n[p>>2]|0;n[s>>2]=p+4}else l=0;_=(n[x+56>>2]|0)+2|0;n[x+56>>2]=_}else l=-1}while(0);p=0;while(1){if(((i[_>>0]|0)+-65|0)>>>0>57){e=-1;break t}d=_;_=_+1|0;n[x+56>>2]=_;d=i[(i[d>>0]|0)+-65+(16+(p*58|0))>>0]|0;if(((d&255)+-1|0)>>>0>=8)break;else p=d&255}if(!(d<<24>>24)){e=-1;break}f=(A|0)>-1;do{if(d<<24>>24==19)if(f){e=-1;break t}else y=54;else{if(f){n[h+(A<<2)>>2]=d&255;A=a+(A<<3)|0;y=n[A+4>>2]|0;n[x+40>>2]=n[A>>2];n[x+40+4>>2]=y;y=54;break}if(!t){e=0;break t}St(x+40|0,d&255,s,u);_=n[x+56>>2]|0;y=55}}while(0);if((y|0)==54){y=0;if(t|0)y=55;else l=0}e:do{if((y|0)==55){y=0;_=i[_+-1>>0]|0;_=(p|0)!=0&(_&15|0)==3?_&-33:_;d=g&-65537;A=(g&8192|0)==0?g:d;s:do{switch(_|0){case 110:switch((p&255)<<24>>24){case 0:{n[n[x+40>>2]>>2]=e;l=0;break e}case 1:{n[n[x+40>>2]>>2]=e;l=0;break e}case 2:{l=n[x+40>>2]|0;n[l>>2]=e;n[l+4>>2]=((e|0)<0)<<31>>31;l=0;break e}case 3:{r[n[x+40>>2]>>1]=e;l=0;break e}case 4:{i[n[x+40>>2]>>0]=e;l=0;break e}case 6:{n[n[x+40>>2]>>2]=e;l=0;break e}case 7:{l=n[x+40>>2]|0;n[l>>2]=e;n[l+4>>2]=((e|0)<0)<<31>>31;l=0;break e}default:{l=0;break e}}case 112:{_=120;l=l>>>0>8?l:8;d=A|8;y=67;break}case 88:case 120:{d=A;y=67;break}case 111:{d=Tt(n[x+40>>2]|0,n[x+40+4>>2]|0,x+40|0)|0;g=d;f=0;p=2720;l=(A&8|0)==0|(l|0)>(w-d|0)?l:w-d+1|0;d=A;y=73;break}case 105:case 100:{_=n[x+40>>2]|0;d=n[x+40+4>>2]|0;if((d|0)<0){_=Wt(0,0,_|0,d|0)|0;d=C()|0;n[x+40>>2]=_;n[x+40+4>>2]=d;f=1;p=2720;y=72;break s}else{f=(A&2049|0)!=0&1;p=(A&2048|0)==0?(A&1|0)==0?2720:2722:2721;y=72;break s}}case 117:{f=0;p=2720;_=n[x+40>>2]|0;d=n[x+40+4>>2]|0;y=72;break}case 99:{i[x+39>>0]=n[x+40>>2];b=x+39|0;f=0;p=2720;g=1;_=d;l=w;break}case 115:{S=n[x+40>>2]|0;S=(S|0)==0?2730:S;A=At(S,0,l)|0;b=S;f=0;p=2720;g=(A|0)==0?l:A-S|0;_=d;l=(A|0)==0?S+l|0:A;break}case 67:{n[x+48>>2]=n[x+40>>2];n[x+48+4>>2]=0;n[x+40>>2]=x+48;f=-1;y=79;break}case 83:{if(!l){It(t,32,m,0,A);l=0;y=89}else{f=l;y=79}break}case 65:case 71:case 70:case 69:case 97:case 103:case 102:case 101:{l=ue[o&1](t,+c[x+40>>3],m,l,A,_)|0;break e}default:{f=0;p=2720;g=l;_=A;l=w}}}while(0);s:do{if((y|0)==67){g=Pt(n[x+40>>2]|0,n[x+40+4>>2]|0,x+40|0,_&32)|0;p=(d&8|0)==0|((n[x+40>>2]|0)==0?(n[x+40+4>>2]|0)==0:0);f=p?0:2;p=p?2720:2720+(_>>>4)|0;y=73}else if((y|0)==72){g=Et(_,d,x+40|0)|0;d=A;y=73}else if((y|0)==79){y=0;d=n[x+40>>2]|0;l=0;while(1){_=n[d>>2]|0;if(!_)break;_=Rt(x+60|0,_)|0;if((_|0)<0|_>>>0>(f-l|0)>>>0){y=83;break}l=_+l|0;if(f>>>0>l>>>0)d=d+4|0;else break}if((y|0)==83){y=0;if((_|0)<0){e=-1;break t}}It(t,32,m,l,A);if(!l){l=0;y=89}else{d=n[x+40>>2]|0;f=0;while(1){_=n[d>>2]|0;if(!_){y=89;break s}_=Rt(x+60|0,_)|0;f=_+f|0;if((f|0)>(l|0)){y=89;break s}Bt(t,x+60|0,_);if(f>>>0>=l>>>0){y=89;break}else d=d+4|0}}}}while(0);if((y|0)==73){y=0;_=n[x+40>>2]|0?1:(n[x+40+4>>2]|0)!=0;S=(l|0)!=0|_;_=w-g+((_^1)&1)|0;b=S?g:x+40|0;g=S?(l|0)>(_|0)?l:_:0;_=(l|0)>-1?d&-65537:d;l=w}else if((y|0)==89){y=0;It(t,32,m,l,A^8192);l=(m|0)>(l|0)?m:l;break}A=l-b|0;g=(g|0)<(A|0)?A:g;S=g+f|0;l=(m|0)<(S|0)?S:m;It(t,32,l,S,_);Bt(t,p,f);It(t,48,l,S,_^65536);It(t,48,g,A,0);Bt(t,b,A);It(t,32,l,S,_^8192)}}while(0);d=k}t:do{if((y|0)==92)if(!t)if(!d)e=0;else{e=1;while(1){l=n[h+(e<<2)>>2]|0;if(!l)break;St(a+(e<<3)|0,l,s,u);e=e+1|0;if(e>>>0>=10){e=1;break t}}while(1){if(n[h+(e<<2)>>2]|0){e=-1;break t}e=e+1|0;if(e>>>0>=10){e=1;break}}}}while(0);Q=x;return e|0}function Bt(t,e,s){t=t|0;e=e|0;s=s|0;if(!(n[t>>2]&32))bt(e,s,t)|0;return}function xt(t){t=t|0;var e=0,s=0;if(!(ut(i[n[t>>2]>>0]|0)|0))e=0;else{e=0;do{s=n[t>>2]|0;e=(e*10|0)+-48+(i[s>>0]|0)|0;n[t>>2]=s+1}while((ut(i[s+1>>0]|0)|0)!=0)}return e|0}function St(t,e,s,i){t=t|0;e=e|0;s=s|0;i=i|0;var r=0,a=0.0;t:do{if(e>>>0<=20)do{switch(e|0){case 9:{e=(n[s>>2]|0)+(4-1)&~(4-1);i=n[e>>2]|0;n[s>>2]=e+4;n[t>>2]=i;break t}case 10:{e=(n[s>>2]|0)+(4-1)&~(4-1);i=n[e>>2]|0;n[s>>2]=e+4;n[t>>2]=i;n[t+4>>2]=((i|0)<0)<<31>>31;break t}case 11:{e=(n[s>>2]|0)+(4-1)&~(4-1);i=n[e>>2]|0;n[s>>2]=e+4;n[t>>2]=i;n[t+4>>2]=0;break t}case 12:{r=(n[s>>2]|0)+(8-1)&~(8-1);e=n[r>>2]|0;i=n[r+4>>2]|0;n[s>>2]=r+8;n[t>>2]=e;n[t+4>>2]=i;break t}case 13:{i=(n[s>>2]|0)+(4-1)&~(4-1);r=n[i>>2]|0;n[s>>2]=i+4;n[t>>2]=(r&65535)<<16>>16;n[t+4>>2]=(((r&65535)<<16>>16|0)<0)<<31>>31;break t}case 14:{i=(n[s>>2]|0)+(4-1)&~(4-1);r=n[i>>2]|0;n[s>>2]=i+4;n[t>>2]=r&65535;n[t+4>>2]=0;break t}case 15:{i=(n[s>>2]|0)+(4-1)&~(4-1);r=n[i>>2]|0;n[s>>2]=i+4;n[t>>2]=(r&255)<<24>>24;n[t+4>>2]=(((r&255)<<24>>24|0)<0)<<31>>31;break t}case 16:{i=(n[s>>2]|0)+(4-1)&~(4-1);r=n[i>>2]|0;n[s>>2]=i+4;n[t>>2]=r&255;n[t+4>>2]=0;break t}case 17:{r=(n[s>>2]|0)+(8-1)&~(8-1);a=+c[r>>3];n[s>>2]=r+8;c[t>>3]=a;break t}case 18:{de[i&1](t,s);break t}default:break t}}while(0)}while(0);return}function Pt(t,e,s,r){t=t|0;e=e|0;s=s|0;r=r|0;if(!((t|0)==0&(e|0)==0))do{s=s+-1|0;i[s>>0]=a[480+(t&15)>>0]|0|r;t=qt(t|0,e|0,4)|0;e=C()|0}while(!((t|0)==0&(e|0)==0));return s|0}function Tt(t,e,s){t=t|0;e=e|0;s=s|0;if(!((t|0)==0&(e|0)==0))do{s=s+-1|0;i[s>>0]=t&7|48;t=qt(t|0,e|0,3)|0;e=C()|0}while(!((t|0)==0&(e|0)==0));return s|0}function Et(t,e,s){t=t|0;e=e|0;s=s|0;var r=0,n=0,a=0;if(e>>>0>0|(e|0)==0&t>>>0>4294967295){do{r=t;t=Yt(t|0,e|0,10,0)|0;n=e;e=C()|0;a=Vt(t|0,e|0,10,0)|0;a=Wt(r|0,n|0,a|0,C()|0)|0;C()|0;s=s+-1|0;i[s>>0]=a&255|48}while(n>>>0>9|(n|0)==9&r>>>0>4294967295);e=t}else e=t;if(e)do{a=e;e=(e>>>0)/10|0;s=s+-1|0;i[s>>0]=a-(e*10|0)|48}while(a>>>0>=10);return s|0}function It(t,e,s,i,r){t=t|0;e=e|0;s=s|0;i=i|0;r=r|0;var n=0;n=Q;Q=Q+256|0;if((s|0)>(i|0)&(r&73728|0)==0){Kt(n|0,e<<24>>24|0,((s-i|0)>>>0<256?s-i|0:256)|0)|0;if((s-i|0)>>>0>255){e=s-i|0;do{Bt(t,n,256);e=e+-256|0}while(e>>>0>255);e=s-i&255}else e=s-i|0;Bt(t,n,e)}Q=n;return}function Rt(t,e){t=t|0;e=e|0;if(!t)t=0;else t=Mt(t,e,0)|0;return t|0}function Mt(t,e,s){t=t|0;e=e|0;s=s|0;do{if(t){if(e>>>0<128){i[t>>0]=e;t=1;break}if(!(n[n[(Ft()|0)+188>>2]>>2]|0))if((e&-128|0)==57216){i[t>>0]=e;t=1;break}else{n[(ot()|0)>>2]=84;t=-1;break}if(e>>>0<2048){i[t>>0]=e>>>6|192;i[t+1>>0]=e&63|128;t=2;break}if(e>>>0<55296|(e&-8192|0)==57344){i[t>>0]=e>>>12|224;i[t+1>>0]=e>>>6&63|128;i[t+2>>0]=e&63|128;t=3;break}if((e+-65536|0)>>>0<1048576){i[t>>0]=e>>>18|240;i[t+1>>0]=e>>>12&63|128;i[t+2>>0]=e>>>6&63|128;i[t+3>>0]=e&63|128;t=4;break}else{n[(ot()|0)>>2]=84;t=-1;break}}else t=1}while(0);return t|0}function Ft(){return lt()|0}function Ot(t){t=+t;var e=0;c[u>>3]=t;e=n[u>>2]|0;v(n[u+4>>2]|0);return e|0}function Ht(t,e){t=+t;e=e|0;var s=0,i=0,r=0;c[u>>3]=t;s=n[u>>2]|0;i=n[u+4>>2]|0;r=qt(s|0,i|0,52)|0;C()|0;switch(r&2047){case 0:{if(t!=0.0){t=+Ht(t*18446744073709551616.0,e);s=(n[e>>2]|0)+-64|0}else s=0;n[e>>2]=s;break}case 2047:break;default:{n[e>>2]=(r&2047)+-1022;n[u>>2]=s;n[u+4>>2]=i&-2146435073|1071644672;t=+c[u>>3]}}return+t}function Lt(t,e){t=t|0;e=e|0;var s=0,r=0,a=0;if((n[e+76>>2]|0)>=0?(ft(e)|0)!=0:0){if((t&255|0)!=(i[e+75>>0]|0)?(r=n[e+20>>2]|0,r>>>0<(n[e+16>>2]|0)>>>0):0){n[e+20>>2]=r+1;i[r>>0]=t;t=t&255}else t=pt(e,t)|0;dt(e)}else a=3;do{if((a|0)==3){if((t&255|0)!=(i[e+75>>0]|0)?(s=n[e+20>>2]|0,s>>>0<(n[e+16>>2]|0)>>>0):0){n[e+20>>2]=s+1;i[s>>0]=t;t=t&255;break}t=pt(e,t)|0}}while(0);return t|0}function Dt(t){t=t|0;var e=0,s=0,i=0,r=0,a=0,h=0,o=0,c=0,u=0,l=0,_=0,d=0,f=0,p=0,g=0,b=0,A=0,m=0,k=0,y=0;y=Q;Q=Q+16|0;do{if(t>>>0<245){_=t>>>0<11?16:t+11&-8;u=n[736]|0;if(u>>>(_>>>3)&3|0){t=2984+((u>>>(_>>>3)&1^1)+(_>>>3)<<1<<2)|0;e=n[t+8>>2]|0;s=n[e+8>>2]|0;if((s|0)==(t|0))n[736]=u&~(1<<(u>>>(_>>>3)&1^1)+(_>>>3));else{n[s+12>>2]=t;n[t+8>>2]=s}k=(u>>>(_>>>3)&1^1)+(_>>>3)<<3;n[e+4>>2]=k|3;n[e+k+4>>2]=n[e+k+4>>2]|1;k=e+8|0;Q=y;return k|0}l=n[738]|0;if(_>>>0>l>>>0){if(u>>>(_>>>3)|0){t=u>>>(_>>>3)<<(_>>>3)&(2<<(_>>>3)|0-(2<<(_>>>3)));r=((t&0-t)+-1|0)>>>(((t&0-t)+-1|0)>>>12&16);i=r>>>(r>>>5&8)>>>(r>>>(r>>>5&8)>>>2&4);i=(r>>>5&8|((t&0-t)+-1|0)>>>12&16|r>>>(r>>>5&8)>>>2&4|i>>>1&2|i>>>(i>>>1&2)>>>1&1)+(i>>>(i>>>1&2)>>>(i>>>(i>>>1&2)>>>1&1))|0;r=n[2984+(i<<1<<2)+8>>2]|0;t=n[r+8>>2]|0;if((t|0)==(2984+(i<<1<<2)|0)){n[736]=u&~(1<<i);t=u&~(1<<i)}else{n[t+12>>2]=2984+(i<<1<<2);n[2984+(i<<1<<2)+8>>2]=t;t=u}n[r+4>>2]=_|3;n[r+_+4>>2]=(i<<3)-_|1;n[r+(i<<3)>>2]=(i<<3)-_;if(l|0){s=n[741]|0;if(!(t&1<<(l>>>3))){n[736]=t|1<<(l>>>3);t=2984+(l>>>3<<1<<2)|0;e=2984+(l>>>3<<1<<2)+8|0}else{t=n[2984+(l>>>3<<1<<2)+8>>2]|0;e=2984+(l>>>3<<1<<2)+8|0}n[e>>2]=s;n[t+12>>2]=s;n[s+8>>2]=t;n[s+12>>2]=2984+(l>>>3<<1<<2)}n[738]=(i<<3)-_;n[741]=r+_;k=r+8|0;Q=y;return k|0}a=n[737]|0;if(a){e=((a&0-a)+-1|0)>>>(((a&0-a)+-1|0)>>>12&16);c=e>>>(e>>>5&8)>>>(e>>>(e>>>5&8)>>>2&4);c=n[3248+((e>>>5&8|((a&0-a)+-1|0)>>>12&16|e>>>(e>>>5&8)>>>2&4|c>>>1&2|c>>>(c>>>1&2)>>>1&1)+(c>>>(c>>>1&2)>>>(c>>>(c>>>1&2)>>>1&1))<<2)>>2]|0;e=c;o=c;c=(n[c+4>>2]&-8)-_|0;while(1){t=n[e+16>>2]|0;if(!t){t=n[e+20>>2]|0;if(!t)break}h=(n[t+4>>2]&-8)-_|0;r=h>>>0<c>>>0;e=t;o=r?t:o;c=r?h:c}h=o+_|0;if(h>>>0>o>>>0){r=n[o+24>>2]|0;t=n[o+12>>2]|0;do{if((t|0)==(o|0)){e=o+20|0;t=n[e>>2]|0;if(!t){e=o+16|0;t=n[e>>2]|0;if(!t){e=0;break}}while(1){i=t+20|0;s=n[i>>2]|0;if(!s){i=t+16|0;s=n[i>>2]|0;if(!s)break;else{t=s;e=i}}else{t=s;e=i}}n[e>>2]=0;e=t}else{e=n[o+8>>2]|0;n[e+12>>2]=t;n[t+8>>2]=e;e=t}}while(0);do{if(r|0){t=n[o+28>>2]|0;if((o|0)==(n[3248+(t<<2)>>2]|0)){n[3248+(t<<2)>>2]=e;if(!e){n[737]=a&~(1<<t);break}}else{n[((n[r+16>>2]|0)==(o|0)?r+16|0:r+20|0)>>2]=e;if(!e)break}n[e+24>>2]=r;t=n[o+16>>2]|0;if(t|0){n[e+16>>2]=t;n[t+24>>2]=e}t=n[o+20>>2]|0;if(t|0){n[e+20>>2]=t;n[t+24>>2]=e}}}while(0);if(c>>>0<16){k=c+_|0;n[o+4>>2]=k|3;k=o+k+4|0;n[k>>2]=n[k>>2]|1}else{n[o+4>>2]=_|3;n[h+4>>2]=c|1;n[h+c>>2]=c;if(l|0){s=n[741]|0;if(!(1<<(l>>>3)&u)){n[736]=1<<(l>>>3)|u;t=2984+(l>>>3<<1<<2)|0;e=2984+(l>>>3<<1<<2)+8|0}else{t=n[2984+(l>>>3<<1<<2)+8>>2]|0;e=2984+(l>>>3<<1<<2)+8|0}n[e>>2]=s;n[t+12>>2]=s;n[s+8>>2]=t;n[s+12>>2]=2984+(l>>>3<<1<<2)}n[738]=c;n[741]=h}k=o+8|0;Q=y;return k|0}}}}else if(t>>>0<=4294967231){_=t+11&-8;i=n[737]|0;if(i){if((t+11|0)>>>8)if(_>>>0>16777215)o=31;else{o=(t+11|0)>>>8<<((((t+11|0)>>>8)+1048320|0)>>>16&8);o=14-((o+520192|0)>>>16&4|(((t+11|0)>>>8)+1048320|0)>>>16&8|((o<<((o+520192|0)>>>16&4))+245760|0)>>>16&2)+(o<<((o+520192|0)>>>16&4)<<(((o<<((o+520192|0)>>>16&4))+245760|0)>>>16&2)>>>15)|0;o=_>>>(o+7|0)&1|o<<1}else o=0;t=n[3248+(o<<2)>>2]|0;t:do{if(!t){s=0;t=0;e=0-_|0;p=61}else{a=0;e=0-_|0;h=_<<((o|0)==31?0:25-(o>>>1)|0);s=0;while(1){r=(n[t+4>>2]&-8)-_|0;if(r>>>0<e>>>0)if(!r){r=t;e=0;s=t;p=65;break t}else{a=t;e=r}p=n[t+20>>2]|0;t=n[t+16+(h>>>31<<2)>>2]|0;s=(p|0)==0|(p|0)==(t|0)?s:p;if(!t){t=a;p=61;break}else h=h<<1}}}while(0);if((p|0)==61){if((s|0)==0&(t|0)==0){t=2<<o;if(!((t|0-t)&i))break;u=((t|0-t)&i&0-((t|0-t)&i))+-1|0;l=u>>>(u>>>12&16)>>>(u>>>(u>>>12&16)>>>5&8);s=l>>>(l>>>2&4)>>>(l>>>(l>>>2&4)>>>1&2);t=0;s=n[3248+((u>>>(u>>>12&16)>>>5&8|u>>>12&16|l>>>2&4|l>>>(l>>>2&4)>>>1&2|s>>>1&1)+(s>>>(s>>>1&1))<<2)>>2]|0}if(!s){o=t;h=e}else{r=t;p=65}}if((p|0)==65)while(1){l=(n[s+4>>2]&-8)-_|0;t=l>>>0<e>>>0;e=t?l:e;r=t?s:r;t=n[s+16>>2]|0;if(!t)t=n[s+20>>2]|0;if(!t){o=r;h=e;break}else s=t}if(((o|0)!=0?h>>>0<((n[738]|0)-_|0)>>>0:0)?(c=o+_|0,c>>>0>o>>>0):0){a=n[o+24>>2]|0;t=n[o+12>>2]|0;do{if((t|0)==(o|0)){e=o+20|0;t=n[e>>2]|0;if(!t){e=o+16|0;t=n[e>>2]|0;if(!t){t=0;break}}while(1){r=t+20|0;s=n[r>>2]|0;if(!s){r=t+16|0;s=n[r>>2]|0;if(!s)break;else{t=s;e=r}}else{t=s;e=r}}n[e>>2]=0}else{k=n[o+8>>2]|0;n[k+12>>2]=t;n[t+8>>2]=k}}while(0);do{if(a){e=n[o+28>>2]|0;if((o|0)==(n[3248+(e<<2)>>2]|0)){n[3248+(e<<2)>>2]=t;if(!t){n[737]=i&~(1<<e);i=i&~(1<<e);break}}else{n[((n[a+16>>2]|0)==(o|0)?a+16|0:a+20|0)>>2]=t;if(!t)break}n[t+24>>2]=a;e=n[o+16>>2]|0;if(e|0){n[t+16>>2]=e;n[e+24>>2]=t}e=n[o+20>>2]|0;if(e){n[t+20>>2]=e;n[e+24>>2]=t}}}while(0);t:do{if(h>>>0<16){k=h+_|0;n[o+4>>2]=k|3;k=o+k+4|0;n[k>>2]=n[k>>2]|1}else{n[o+4>>2]=_|3;n[c+4>>2]=h|1;n[c+h>>2]=h;s=h>>>3;if(h>>>0<256){t=n[736]|0;if(!(t&1<<s)){n[736]=t|1<<s;t=2984+(s<<1<<2)|0;e=2984+(s<<1<<2)+8|0}else{t=n[2984+(s<<1<<2)+8>>2]|0;e=2984+(s<<1<<2)+8|0}n[e>>2]=c;n[t+12>>2]=c;n[c+8>>2]=t;n[c+12>>2]=2984+(s<<1<<2);break}t=h>>>8;if(t)if(h>>>0>16777215)s=31;else{s=t<<((t+1048320|0)>>>16&8)<<(((t<<((t+1048320|0)>>>16&8))+520192|0)>>>16&4);s=14-(((t<<((t+1048320|0)>>>16&8))+520192|0)>>>16&4|(t+1048320|0)>>>16&8|(s+245760|0)>>>16&2)+(s<<((s+245760|0)>>>16&2)>>>15)|0;s=h>>>(s+7|0)&1|s<<1}else s=0;t=3248+(s<<2)|0;n[c+28>>2]=s;n[c+16+4>>2]=0;n[c+16>>2]=0;e=1<<s;if(!(i&e)){n[737]=i|e;n[t>>2]=c;n[c+24>>2]=t;n[c+12>>2]=c;n[c+8>>2]=c;break}t=n[t>>2]|0;e:do{if((n[t+4>>2]&-8|0)!=(h|0)){i=h<<((s|0)==31?0:25-(s>>>1)|0);while(1){s=t+16+(i>>>31<<2)|0;e=n[s>>2]|0;if(!e)break;if((n[e+4>>2]&-8|0)==(h|0)){t=e;break e}else{i=i<<1;t=e}}n[s>>2]=c;n[c+24>>2]=t;n[c+12>>2]=c;n[c+8>>2]=c;break t}}while(0);m=t+8|0;k=n[m>>2]|0;n[k+12>>2]=c;n[m>>2]=c;n[c+8>>2]=k;n[c+12>>2]=t;n[c+24>>2]=0}}while(0);k=o+8|0;Q=y;return k|0}}}else _=-1}while(0);s=n[738]|0;if(s>>>0>=_>>>0){t=s-_|0;e=n[741]|0;if(t>>>0>15){k=e+_|0;n[741]=k;n[738]=t;n[k+4>>2]=t|1;n[e+s>>2]=t;n[e+4>>2]=_|3}else{n[738]=0;n[741]=0;n[e+4>>2]=s|3;n[e+s+4>>2]=n[e+s+4>>2]|1}k=e+8|0;Q=y;return k|0}r=n[739]|0;if(r>>>0>_>>>0){A=r-_|0;n[739]=A;k=n[742]|0;m=k+_|0;n[742]=m;n[m+4>>2]=A|1;n[k+4>>2]=_|3;k=k+8|0;Q=y;return k|0}if(!(n[854]|0)){n[856]=4096;n[855]=4096;n[857]=-1;n[858]=-1;n[859]=0;n[847]=0;n[854]=y&-16^1431655768;t=4096}else t=n[856]|0;a=_+48|0;h=_+47|0;c=t+h|0;o=0-t|0;if((c&o)>>>0<=_>>>0){k=0;Q=y;return k|0}t=n[846]|0;if(t|0?(l=n[844]|0,(l+(c&o)|0)>>>0<=l>>>0?1:(l+(c&o)|0)>>>0>t>>>0):0){k=0;Q=y;return k|0}t:do{if(!(n[847]&4)){s=n[742]|0;e:do{if(s){e=3392;while(1){l=n[e>>2]|0;if(l>>>0<=s>>>0?(l+(n[e+4>>2]|0)|0)>>>0>s>>>0:0)break;t=n[e+8>>2]|0;if(!t){p=128;break e}else e=t}if((c-r&o)>>>0<2147483647){t=Zt(c-r&o|0)|0;if((t|0)==((n[e>>2]|0)+(n[e+4>>2]|0)|0))if((t|0)==(-1|0))t=c-r&o;else{h=c-r&o;r=t;p=145;break t}else{i=t;s=c-r&o;p=136}}else t=0}else p=128}while(0);do{if((p|0)==128){e=Zt(0)|0;if((e|0)!=(-1|0)?(f=n[855]|0,f=((f+-1&e|0)==0?0:(f+-1+e&0-f)-e|0)+(c&o)|0,d=n[844]|0,f>>>0>_>>>0&f>>>0<2147483647):0){l=n[846]|0;if(l|0?(f+d|0)>>>0<=d>>>0|(f+d|0)>>>0>l>>>0:0){t=0;break}t=Zt(f|0)|0;if((t|0)==(e|0)){h=f;r=e;p=145;break t}else{i=t;s=f;p=136}}else t=0}}while(0);do{if((p|0)==136){e=0-s|0;if(!(a>>>0>s>>>0&(s>>>0<2147483647&(i|0)!=(-1|0))))if((i|0)==(-1|0)){t=0;break}else{h=s;r=i;p=145;break t}t=n[856]|0;t=h-s+t&0-t;if(t>>>0>=2147483647){h=s;r=i;p=145;break t}if((Zt(t|0)|0)==(-1|0)){Zt(e|0)|0;t=0;break}else{h=t+s|0;r=i;p=145;break t}}}while(0);n[847]=n[847]|4;p=143}else{t=0;p=143}}while(0);if(((p|0)==143?(c&o)>>>0<2147483647:0)?(A=Zt(c&o|0)|0,g=Zt(0)|0,b=(g-A|0)>>>0>(_+40|0)>>>0,!((A|0)==(-1|0)|b^1|A>>>0<g>>>0&((A|0)!=(-1|0)&(g|0)!=(-1|0))^1)):0){h=b?g-A|0:t;r=A;p=145}if((p|0)==145){t=(n[844]|0)+h|0;n[844]=t;if(t>>>0>(n[845]|0)>>>0)n[845]=t;c=n[742]|0;t:do{if(c){t=3392;while(1){e=n[t>>2]|0;s=n[t+4>>2]|0;if((r|0)==(e+s|0)){p=154;break}i=n[t+8>>2]|0;if(!i)break;else t=i}if(((p|0)==154?(m=t+4|0,(n[t+12>>2]&8|0)==0):0)?r>>>0>c>>>0&e>>>0<=c>>>0:0){n[m>>2]=s+h;k=(n[739]|0)+h|0;m=(c+8&7|0)==0?0:0-(c+8)&7;n[742]=c+m;n[739]=k-m;n[c+m+4>>2]=k-m|1;n[c+k+4>>2]=40;n[743]=n[858];break}if(r>>>0<(n[740]|0)>>>0)n[740]=r;s=r+h|0;t=3392;while(1){if((n[t>>2]|0)==(s|0)){p=162;break}e=n[t+8>>2]|0;if(!e)break;else t=e}if((p|0)==162?(n[t+12>>2]&8|0)==0:0){n[t>>2]=r;l=t+4|0;n[l>>2]=(n[l>>2]|0)+h;l=r+8|0;l=r+((l&7|0)==0?0:0-l&7)|0;t=s+((s+8&7|0)==0?0:0-(s+8)&7)|0;u=l+_|0;o=t-l-_|0;n[l+4>>2]=_|3;e:do{if((c|0)==(t|0)){k=(n[739]|0)+o|0;n[739]=k;n[742]=u;n[u+4>>2]=k|1}else{if((n[741]|0)==(t|0)){k=(n[738]|0)+o|0;n[738]=k;n[741]=u;n[u+4>>2]=k|1;n[u+k>>2]=k;break}h=n[t+4>>2]|0;if((h&3|0)==1){s:do{if(h>>>0<256){e=n[t+8>>2]|0;s=n[t+12>>2]|0;if((s|0)==(e|0)){n[736]=n[736]&~(1<<(h>>>3));break}else{n[e+12>>2]=s;n[s+8>>2]=e;break}}else{a=n[t+24>>2]|0;e=n[t+12>>2]|0;do{if((e|0)==(t|0)){e=n[t+16+4>>2]|0;if(!e){e=n[t+16>>2]|0;if(!e){e=0;break}else s=t+16|0}else s=t+16+4|0;while(1){r=e+20|0;i=n[r>>2]|0;if(!i){r=e+16|0;i=n[r>>2]|0;if(!i)break;else{e=i;s=r}}else{e=i;s=r}}n[s>>2]=0}else{k=n[t+8>>2]|0;n[k+12>>2]=e;n[e+8>>2]=k}}while(0);if(!a)break;s=n[t+28>>2]|0;do{if((n[3248+(s<<2)>>2]|0)!=(t|0)){n[((n[a+16>>2]|0)==(t|0)?a+16|0:a+20|0)>>2]=e;if(!e)break s}else{n[3248+(s<<2)>>2]=e;if(e|0)break;n[737]=n[737]&~(1<<s);break s}}while(0);n[e+24>>2]=a;s=n[t+16>>2]|0;if(s|0){n[e+16>>2]=s;n[s+24>>2]=e}s=n[t+16+4>>2]|0;if(!s)break;n[e+20>>2]=s;n[s+24>>2]=e}}while(0);t=t+(h&-8)|0;r=(h&-8)+o|0}else r=o;s=t+4|0;n[s>>2]=n[s>>2]&-2;n[u+4>>2]=r|1;n[u+r>>2]=r;s=r>>>3;if(r>>>0<256){t=n[736]|0;if(!(t&1<<s)){n[736]=t|1<<s;t=2984+(s<<1<<2)|0;e=2984+(s<<1<<2)+8|0}else{t=n[2984+(s<<1<<2)+8>>2]|0;e=2984+(s<<1<<2)+8|0}n[e>>2]=u;n[t+12>>2]=u;n[u+8>>2]=t;n[u+12>>2]=2984+(s<<1<<2);break}t=r>>>8;do{if(!t)i=0;else{if(r>>>0>16777215){i=31;break}i=t<<((t+1048320|0)>>>16&8)<<(((t<<((t+1048320|0)>>>16&8))+520192|0)>>>16&4);i=14-(((t<<((t+1048320|0)>>>16&8))+520192|0)>>>16&4|(t+1048320|0)>>>16&8|(i+245760|0)>>>16&2)+(i<<((i+245760|0)>>>16&2)>>>15)|0;i=r>>>(i+7|0)&1|i<<1}}while(0);t=3248+(i<<2)|0;n[u+28>>2]=i;n[u+16+4>>2]=0;n[u+16>>2]=0;e=n[737]|0;s=1<<i;if(!(e&s)){n[737]=e|s;n[t>>2]=u;n[u+24>>2]=t;n[u+12>>2]=u;n[u+8>>2]=u;break}t=n[t>>2]|0;s:do{if((n[t+4>>2]&-8|0)!=(r|0)){i=r<<((i|0)==31?0:25-(i>>>1)|0);while(1){s=t+16+(i>>>31<<2)|0;e=n[s>>2]|0;if(!e)break;if((n[e+4>>2]&-8|0)==(r|0)){t=e;break s}else{i=i<<1;t=e}}n[s>>2]=u;n[u+24>>2]=t;n[u+12>>2]=u;n[u+8>>2]=u;break e}}while(0);m=t+8|0;k=n[m>>2]|0;n[k+12>>2]=u;n[m>>2]=u;n[u+8>>2]=k;n[u+12>>2]=t;n[u+24>>2]=0}}while(0);k=l+8|0;Q=y;return k|0}t=3392;while(1){e=n[t>>2]|0;if(e>>>0<=c>>>0?(k=e+(n[t+4>>2]|0)|0,k>>>0>c>>>0):0)break;t=n[t+8>>2]|0}a=k+-47+((k+-47+8&7|0)==0?0:0-(k+-47+8)&7)|0;a=a>>>0<(c+16|0)>>>0?c:a;t=h+-40|0;A=r+8|0;A=(A&7|0)==0?0:0-A&7;m=r+A|0;n[742]=m;n[739]=t-A;n[m+4>>2]=t-A|1;n[r+t+4>>2]=40;n[743]=n[858];n[a+4>>2]=27;n[a+8>>2]=n[848];n[a+8+4>>2]=n[849];n[a+8+8>>2]=n[850];n[a+8+12>>2]=n[851];n[848]=r;n[849]=h;n[851]=0;n[850]=a+8;t=a+24|0;do{m=t;t=t+4|0;n[t>>2]=7}while((m+8|0)>>>0<k>>>0);if((a|0)!=(c|0)){n[a+4>>2]=n[a+4>>2]&-2;n[c+4>>2]=a-c|1;n[a>>2]=a-c;if((a-c|0)>>>0<256){s=2984+((a-c|0)>>>3<<1<<2)|0;t=n[736]|0;if(!(t&1<<((a-c|0)>>>3))){n[736]=t|1<<((a-c|0)>>>3);t=s;e=s+8|0}else{t=n[s+8>>2]|0;e=s+8|0}n[e>>2]=c;n[t+12>>2]=c;n[c+8>>2]=t;n[c+12>>2]=s;break}if((a-c|0)>>>8)if((a-c|0)>>>0>16777215)i=31;else{i=(a-c|0)>>>8<<((((a-c|0)>>>8)+1048320|0)>>>16&8);i=14-((i+520192|0)>>>16&4|(((a-c|0)>>>8)+1048320|0)>>>16&8|((i<<((i+520192|0)>>>16&4))+245760|0)>>>16&2)+(i<<((i+520192|0)>>>16&4)<<(((i<<((i+520192|0)>>>16&4))+245760|0)>>>16&2)>>>15)|0;i=(a-c|0)>>>(i+7|0)&1|i<<1}else i=0;t=3248+(i<<2)|0;n[c+28>>2]=i;n[c+20>>2]=0;n[c+16>>2]=0;e=n[737]|0;s=1<<i;if(!(e&s)){n[737]=e|s;n[t>>2]=c;n[c+24>>2]=t;n[c+12>>2]=c;n[c+8>>2]=c;break}t=n[t>>2]|0;e:do{if((n[t+4>>2]&-8|0)!=(a-c|0)){i=a-c<<((i|0)==31?0:25-(i>>>1)|0);while(1){s=t+16+(i>>>31<<2)|0;e=n[s>>2]|0;if(!e)break;if((n[e+4>>2]&-8|0)==(a-c|0)){t=e;break e}else{i=i<<1;t=e}}n[s>>2]=c;n[c+24>>2]=t;n[c+12>>2]=c;n[c+8>>2]=c;break t}}while(0);m=t+8|0;k=n[m>>2]|0;n[k+12>>2]=c;n[m>>2]=c;n[c+8>>2]=k;n[c+12>>2]=t;n[c+24>>2]=0}}else{k=n[740]|0;if((k|0)==0|r>>>0<k>>>0)n[740]=r;n[848]=r;n[849]=h;n[851]=0;n[745]=n[854];n[744]=-1;n[749]=2984;n[748]=2984;n[751]=2992;n[750]=2992;n[753]=3e3;n[752]=3e3;n[755]=3008;n[754]=3008;n[757]=3016;n[756]=3016;n[759]=3024;n[758]=3024;n[761]=3032;n[760]=3032;n[763]=3040;n[762]=3040;n[765]=3048;n[764]=3048;n[767]=3056;n[766]=3056;n[769]=3064;n[768]=3064;n[771]=3072;n[770]=3072;n[773]=3080;n[772]=3080;n[775]=3088;n[774]=3088;n[777]=3096;n[776]=3096;n[779]=3104;n[778]=3104;n[781]=3112;n[780]=3112;n[783]=3120;n[782]=3120;n[785]=3128;n[784]=3128;n[787]=3136;n[786]=3136;n[789]=3144;n[788]=3144;n[791]=3152;n[790]=3152;n[793]=3160;n[792]=3160;n[795]=3168;n[794]=3168;n[797]=3176;n[796]=3176;n[799]=3184;n[798]=3184;n[801]=3192;n[800]=3192;n[803]=3200;n[802]=3200;n[805]=3208;n[804]=3208;n[807]=3216;n[806]=3216;n[809]=3224;n[808]=3224;n[811]=3232;n[810]=3232;k=h+-40|0;A=r+8|0;A=(A&7|0)==0?0:0-A&7;m=r+A|0;n[742]=m;n[739]=k-A;n[m+4>>2]=k-A|1;n[r+k+4>>2]=40;n[743]=n[858]}}while(0);t=n[739]|0;if(t>>>0>_>>>0){A=t-_|0;n[739]=A;k=n[742]|0;m=k+_|0;n[742]=m;n[m+4>>2]=A|1;n[k+4>>2]=_|3;k=k+8|0;Q=y;return k|0}}n[(ot()|0)>>2]=12;k=0;Q=y;return k|0}function Ut(t){t=t|0;var e=0,s=0,i=0,r=0,a=0,h=0,o=0,c=0;if(!t)return;e=n[740]|0;s=n[t+-4>>2]|0;c=t+-8+(s&-8)|0;do{if(!(s&1)){i=n[t+-8>>2]|0;if(!(s&3))return;h=t+-8+(0-i)|0;a=i+(s&-8)|0;if(h>>>0<e>>>0)return;if((n[741]|0)==(h|0)){e=n[c+4>>2]|0;if((e&3|0)!=3){o=h;e=a;break}n[738]=a;n[c+4>>2]=e&-2;n[h+4>>2]=a|1;n[h+a>>2]=a;return}if(i>>>0<256){e=n[h+8>>2]|0;t=n[h+12>>2]|0;if((t|0)==(e|0)){n[736]=n[736]&~(1<<(i>>>3));o=h;e=a;break}else{n[e+12>>2]=t;n[t+8>>2]=e;o=h;e=a;break}}r=n[h+24>>2]|0;e=n[h+12>>2]|0;do{if((e|0)==(h|0)){e=n[h+16+4>>2]|0;if(!e){e=n[h+16>>2]|0;if(!e){e=0;break}else t=h+16|0}else t=h+16+4|0;while(1){i=e+20|0;s=n[i>>2]|0;if(!s){i=e+16|0;s=n[i>>2]|0;if(!s)break;else{e=s;t=i}}else{e=s;t=i}}n[t>>2]=0}else{o=n[h+8>>2]|0;n[o+12>>2]=e;n[e+8>>2]=o}}while(0);if(r){t=n[h+28>>2]|0;if((n[3248+(t<<2)>>2]|0)==(h|0)){n[3248+(t<<2)>>2]=e;if(!e){n[737]=n[737]&~(1<<t);o=h;e=a;break}}else{n[((n[r+16>>2]|0)==(h|0)?r+16|0:r+20|0)>>2]=e;if(!e){o=h;e=a;break}}n[e+24>>2]=r;t=n[h+16>>2]|0;if(t|0){n[e+16>>2]=t;n[t+24>>2]=e}t=n[h+16+4>>2]|0;if(t){n[e+20>>2]=t;n[t+24>>2]=e;o=h;e=a}else{o=h;e=a}}else{o=h;e=a}}else{o=t+-8|0;e=s&-8;h=t+-8|0}}while(0);if(h>>>0>=c>>>0)return;s=n[c+4>>2]|0;if(!(s&1))return;if(!(s&2)){if((n[742]|0)==(c|0)){c=(n[739]|0)+e|0;n[739]=c;n[742]=o;n[o+4>>2]=c|1;if((o|0)!=(n[741]|0))return;n[741]=0;n[738]=0;return}if((n[741]|0)==(c|0)){c=(n[738]|0)+e|0;n[738]=c;n[741]=h;n[o+4>>2]=c|1;n[h+c>>2]=c;return}r=(s&-8)+e|0;do{if(s>>>0<256){t=n[c+8>>2]|0;e=n[c+12>>2]|0;if((e|0)==(t|0)){n[736]=n[736]&~(1<<(s>>>3));break}else{n[t+12>>2]=e;n[e+8>>2]=t;break}}else{a=n[c+24>>2]|0;e=n[c+12>>2]|0;do{if((e|0)==(c|0)){e=n[c+16+4>>2]|0;if(!e){e=n[c+16>>2]|0;if(!e){t=0;break}else t=c+16|0}else t=c+16+4|0;while(1){i=e+20|0;s=n[i>>2]|0;if(!s){i=e+16|0;s=n[i>>2]|0;if(!s)break;else{e=s;t=i}}else{e=s;t=i}}n[t>>2]=0;t=e}else{t=n[c+8>>2]|0;n[t+12>>2]=e;n[e+8>>2]=t;t=e}}while(0);if(a|0){e=n[c+28>>2]|0;if((n[3248+(e<<2)>>2]|0)==(c|0)){n[3248+(e<<2)>>2]=t;if(!t){n[737]=n[737]&~(1<<e);break}}else{n[((n[a+16>>2]|0)==(c|0)?a+16|0:a+20|0)>>2]=t;if(!t)break}n[t+24>>2]=a;e=n[c+16>>2]|0;if(e|0){n[t+16>>2]=e;n[e+24>>2]=t}e=n[c+16+4>>2]|0;if(e|0){n[t+20>>2]=e;n[e+24>>2]=t}}}}while(0);n[o+4>>2]=r|1;n[h+r>>2]=r;if((o|0)==(n[741]|0)){n[738]=r;return}}else{n[c+4>>2]=s&-2;n[o+4>>2]=e|1;n[h+e>>2]=e;r=e}s=r>>>3;if(r>>>0<256){e=n[736]|0;if(!(e&1<<s)){n[736]=e|1<<s;e=2984+(s<<1<<2)|0;t=2984+(s<<1<<2)+8|0}else{e=n[2984+(s<<1<<2)+8>>2]|0;t=2984+(s<<1<<2)+8|0}n[t>>2]=o;n[e+12>>2]=o;n[o+8>>2]=e;n[o+12>>2]=2984+(s<<1<<2);return}e=r>>>8;if(e)if(r>>>0>16777215)i=31;else{i=e<<((e+1048320|0)>>>16&8)<<(((e<<((e+1048320|0)>>>16&8))+520192|0)>>>16&4);i=14-(((e<<((e+1048320|0)>>>16&8))+520192|0)>>>16&4|(e+1048320|0)>>>16&8|(i+245760|0)>>>16&2)+(i<<((i+245760|0)>>>16&2)>>>15)|0;i=r>>>(i+7|0)&1|i<<1}else i=0;e=3248+(i<<2)|0;n[o+28>>2]=i;n[o+20>>2]=0;n[o+16>>2]=0;t=n[737]|0;s=1<<i;t:do{if(!(t&s)){n[737]=t|s;n[e>>2]=o;n[o+24>>2]=e;n[o+12>>2]=o;n[o+8>>2]=o}else{e=n[e>>2]|0;e:do{if((n[e+4>>2]&-8|0)!=(r|0)){i=r<<((i|0)==31?0:25-(i>>>1)|0);while(1){s=e+16+(i>>>31<<2)|0;t=n[s>>2]|0;if(!t)break;if((n[t+4>>2]&-8|0)==(r|0)){e=t;break e}else{i=i<<1;e=t}}n[s>>2]=o;n[o+24>>2]=e;n[o+12>>2]=o;n[o+8>>2]=o;break t}}while(0);h=e+8|0;c=n[h>>2]|0;n[c+12>>2]=o;n[h>>2]=o;n[o+8>>2]=c;n[o+12>>2]=e;n[o+24>>2]=0}}while(0);c=(n[744]|0)+-1|0;n[744]=c;if(c|0)return;e=3400;while(1){e=n[e>>2]|0;if(!e)break;else e=e+8|0}n[744]=-1;return}function jt(t,e){t=t|0;e=e|0;var s=0,i=0,r=0;s=k(e&65535,t&65535)|0;r=(s>>>16)+(k(e&65535,t>>>16)|0)|0;i=k(e>>>16,t&65535)|0;return(v((r>>>16)+(k(e>>>16,t>>>16)|0)+(((r&65535)+i|0)>>>16)|0),r+i<<16|s&65535|0)|0}function Vt(t,e,s,i){t=t|0;e=e|0;s=s|0;i=i|0;var r=0,n=0;r=jt(t,s)|0;n=C()|0;return(v((k(e,s)|0)+(k(i,t)|0)+n|n&0|0),r|0|0)|0}function Qt(t,e,s,i){t=t|0;e=e|0;s=s|0;i=i|0;return(v(e+i+(t+s>>>0>>>0<t>>>0|0)>>>0|0),t+s>>>0|0)|0}function Wt(t,e,s,i){t=t|0;e=e|0;s=s|0;i=i|0;i=e-i-(s>>>0>t>>>0|0)>>>0;return(v(i|0),t-s>>>0|0)|0}function zt(t){t=t|0;return(t?31-(y(t^t-1)|0)|0:32)|0}function Jt(t,e,s,i,r){t=t|0;e=e|0;s=s|0;i=i|0;r=r|0;var a=0,h=0,o=0,c=0,u=0,l=0,_=0,d=0,f=0,p=0;if(!e)if(!i){if(r|0){n[r>>2]=(t>>>0)%(s>>>0);n[r+4>>2]=0}i=0;r=(t>>>0)/(s>>>0)>>>0;return(v(i|0),r)|0}else{if(!r){i=0;r=0;return(v(i|0),r)|0}n[r>>2]=t|0;n[r+4>>2]=e&0;i=0;r=0;return(v(i|0),r)|0}do{if(s){if(i|0){h=(y(i|0)|0)-(y(e|0)|0)|0;if(h>>>0<=31){d=h+1|0;o=t>>>((h+1|0)>>>0)&h-31>>31|e<<31-h;_=e>>>((h+1|0)>>>0)&h-31>>31;a=0;h=t<<31-h;break}if(!r){i=0;r=0;return(v(i|0),r)|0}n[r>>2]=t|0;n[r+4>>2]=e|e&0;i=0;r=0;return(v(i|0),r)|0}if(s-1&s|0){h=(y(s|0)|0)+33-(y(e|0)|0)|0;d=h;o=32-h-1>>31&e>>>((h-32|0)>>>0)|(e<<32-h|t>>>(h>>>0))&h-32>>31;_=h-32>>31&e>>>(h>>>0);a=t<<64-h&32-h>>31;h=(e<<64-h|t>>>((h-32|0)>>>0))&32-h>>31|t<<32-h&h-33>>31;break}if(r|0){n[r>>2]=s-1&t;n[r+4>>2]=0}if((s|0)==1){i=e|e&0;r=t|0|0;return(v(i|0),r)|0}else{r=zt(s|0)|0;i=e>>>(r>>>0)|0;r=e<<32-r|t>>>(r>>>0)|0;return(v(i|0),r)|0}}else{if(!i){if(r|0){n[r>>2]=(e>>>0)%(s>>>0);n[r+4>>2]=0}i=0;r=(e>>>0)/(s>>>0)>>>0;return(v(i|0),r)|0}if(!t){if(r|0){n[r>>2]=0;n[r+4>>2]=(e>>>0)%(i>>>0)}s=0;r=(e>>>0)/(i>>>0)>>>0;return(v(s|0),r)|0}if(!(i-1&i)){if(r|0){n[r>>2]=t|0;n[r+4>>2]=i-1&e|e&0}s=0;r=e>>>((zt(i|0)|0)>>>0);return(v(s|0),r)|0}h=(y(i|0)|0)-(y(e|0)|0)|0;if(h>>>0<=30){d=h+1|0;o=e<<31-h|t>>>((h+1|0)>>>0);_=e>>>((h+1|0)>>>0);a=0;h=t<<31-h;break}if(!r){i=0;r=0;return(v(i|0),r)|0}n[r>>2]=t|0;n[r+4>>2]=e|e&0;i=0;r=0;return(v(i|0),r)|0}}while(0);if(!d){c=h;e=_;t=0;h=0}else{u=Qt(s|0|0,i|i&0|0,-1,-1)|0;l=C()|0;c=h;e=_;t=d;h=0;do{p=c;c=a>>>31|c<<1;a=h|a<<1;p=o<<1|p>>>31|0;f=o>>>31|e<<1|0;Wt(u|0,l|0,p|0,f|0)|0;d=C()|0;_=d>>31|((d|0)<0?-1:0)<<1;h=_&1;o=Wt(p|0,f|0,_&(s|0)|0,(((d|0)<0?-1:0)>>31|((d|0)<0?-1:0)<<1)&(i|i&0)|0)|0;e=C()|0;t=t-1|0}while((t|0)!=0);t=0}if(r|0){n[r>>2]=o;n[r+4>>2]=e}f=(a|0)>>>31|c<<1|(0<<1|a>>>31)&0|t;p=(a<<1|0>>>31)&-2|h;return(v(f|0),p)|0}function Yt(t,e,s,i){t=t|0;e=e|0;s=s|0;i=i|0;return Jt(t,e,s,i,0)|0}function qt(t,e,s){t=t|0;e=e|0;s=s|0;if((s|0)<32){v(e>>>s|0);return t>>>s|(e&(1<<s)-1)<<32-s}v(0);return e>>>s-32|0}function Nt(t,e,s){t=t|0;e=e|0;s=s|0;if((s|0)<32){v(e<<s|(t&(1<<s)-1<<32-s)>>>32-s|0);return t<<s}v(t<<s-32|0);return 0}function Xt(t){t=t|0;return(t&255)<<24|(t>>8&255)<<16|(t>>16&255)<<8|t>>>24|0}function Gt(t,e,s){t=t|0;e=e|0;s=s|0;var r=0,a=0,h=0;if((s|0)>=8192){R(t|0,e|0,s|0)|0;return t|0}h=t|0;a=t+s|0;if((t&3)==(e&3)){while(t&3){if(!s)return h|0;i[t>>0]=i[e>>0]|0;t=t+1|0;e=e+1|0;s=s-1|0}s=a&-4|0;r=s-64|0;while((t|0)<=(r|0)){n[t>>2]=n[e>>2];n[t+4>>2]=n[e+4>>2];n[t+8>>2]=n[e+8>>2];n[t+12>>2]=n[e+12>>2];n[t+16>>2]=n[e+16>>2];n[t+20>>2]=n[e+20>>2];n[t+24>>2]=n[e+24>>2];n[t+28>>2]=n[e+28>>2];n[t+32>>2]=n[e+32>>2];n[t+36>>2]=n[e+36>>2];n[t+40>>2]=n[e+40>>2];n[t+44>>2]=n[e+44>>2];n[t+48>>2]=n[e+48>>2];n[t+52>>2]=n[e+52>>2];n[t+56>>2]=n[e+56>>2];n[t+60>>2]=n[e+60>>2];t=t+64|0;e=e+64|0}while((t|0)<(s|0)){n[t>>2]=n[e>>2];t=t+4|0;e=e+4|0}}else{s=a-4|0;while((t|0)<(s|0)){i[t>>0]=i[e>>0]|0;i[t+1>>0]=i[e+1>>0]|0;i[t+2>>0]=i[e+2>>0]|0;i[t+3>>0]=i[e+3>>0]|0;t=t+4|0;e=e+4|0}}while((t|0)<(a|0)){i[t>>0]=i[e>>0]|0;t=t+1|0;e=e+1|0}return h|0}function Kt(t,e,s){t=t|0;e=e|0;s=s|0;var r=0,a=0;r=t+s|0;e=e&255;if((s|0)>=67){while(t&3){i[t>>0]=e;t=t+1|0}a=e|e<<8|e<<16|e<<24;while((t|0)<=((r&-4)-64|0)){n[t>>2]=a;n[t+4>>2]=a;n[t+8>>2]=a;n[t+12>>2]=a;n[t+16>>2]=a;n[t+20>>2]=a;n[t+24>>2]=a;n[t+28>>2]=a;n[t+32>>2]=a;n[t+36>>2]=a;n[t+40>>2]=a;n[t+44>>2]=a;n[t+48>>2]=a;n[t+52>>2]=a;n[t+56>>2]=a;n[t+60>>2]=a;t=t+64|0}while((t|0)<(r&-4|0)){n[t>>2]=a;t=t+4|0}}while((t|0)<(r|0)){i[t>>0]=e;t=t+1|0}return r-s|0}function Zt(t){t=t|0;var e=0,s=0;s=I()|0;e=n[l>>2]|0;if((t|0)>0&(e+t|0)<(e|0)|(e+t|0)<0){H(e+t|0)|0;B(12);return-1}if((e+t|0)>(s|0))if(!(M(e+t|0)|0)){B(12);return-1}n[l>>2]=e+t;return e|0}function $t(t,e){t=t|0;e=e|0;return ce[t&1](e|0)|0}function te(t,e,s,i,r,n,a){t=t|0;e=e|0;s=+s;i=i|0;r=r|0;n=n|0;a=a|0;return ue[t&1](e|0,+s,i|0,r|0,n|0,a|0)|0}function ee(t,e,s,i){t=t|0;e=e|0;s=s|0;i=i|0;return le[t&1](e|0,s|0,i|0)|0}function se(t,e,s,i,r){t=t|0;e=e|0;s=s|0;i=i|0;r=r|0;return _e[t&1](e|0,s|0,i|0,r|0)|0}function ie(t,e,s){t=t|0;e=e|0;s=s|0;de[t&1](e|0,s|0)}function re(t){t=t|0;w(0);return 0}function ne(t,e,s,i,r,n){t=t|0;e=+e;s=s|0;i=i|0;r=r|0;n=n|0;w(1);return 0}function ae(t,e,s){t=t|0;e=e|0;s=s|0;w(2);return 0}function he(t,e,s,i){t=t|0;e=e|0;s=s|0;i=i|0;w(3);return 0}function oe(t,e){t=t|0;e=e|0;w(4)}var ce=[re,rt];var ue=[ne,yt];var le=[ae,nt];var _e=[he,at];var de=[oe,wt];return{___errno_location:ot,___muldi3:Vt,___udivdi3:Yt,_abort_run:Z,_bitshift64Lshr:qt,_bitshift64Shl:Nt,_enable_debug:$,_free:Ut,_i64Add:Qt,_i64Subtract:Wt,_llvm_bswap_i32:Xt,_malloc:Dt,_memcpy:Gt,_memset:Kt,_ping:G,_read_register:tt,_reset:st,_run:K,_sbrk:Zt,_set_stop_address:X,_write_register:et,dynCall_ii:$t,dynCall_iidiiii:te,dynCall_iiii:ee,dynCall_iiiii:se,dynCall_vii:ie,establishStackSpace:N,stackAlloc:J,stackRestore:q,stackSave:Y}}(It,Rt,P),Ft=(t.___errno_location=Mt.___errno_location,t.___muldi3=Mt.___muldi3,t.___udivdi3=Mt.___udivdi3,t._abort_run=Mt._abort_run,t._bitshift64Lshr=Mt._bitshift64Lshr,t._bitshift64Shl=Mt._bitshift64Shl,t._enable_debug=Mt._enable_debug,t._free=Mt._free,t._i64Add=Mt._i64Add,t._i64Subtract=Mt._i64Subtract,t._llvm_bswap_i32=Mt._llvm_bswap_i32,t._malloc=Mt._malloc,t._memcpy=Mt._memcpy,t._memset=Mt._memset,t._ping=Mt._ping,t._read_register=Mt._read_register,t._reset=Mt._reset,t._run=Mt._run,t._sbrk=Mt._sbrk,t._set_stop_address=Mt._set_stop_address,t._write_register=Mt._write_register,t.establishStackSpace=Mt.establishStackSpace,t.stackAlloc=Mt.stackAlloc),Ot=t.stackRestore=Mt.stackRestore,Ht=t.stackSave=Mt.stackSave;if(t.dynCall_ii=Mt.dynCall_ii,t.dynCall_iidiiii=Mt.dynCall_iidiiii,t.dynCall_iiii=Mt.dynCall_iiii,t.dynCall_iiiii=Mt.dynCall_iiiii,t.dynCall_vii=Mt.dynCall_vii,t.asm=Mt,t.ccall=S,it)if(nt(it)||(it=g(it)),h||c){var Lt=_(it);E.set(Lt,v)}else{et();var Dt=function(e){e.byteLength&&(e=new Uint8Array(e)),E.set(e,v),t.memoryInitializerRequest&&delete t.memoryInitializerRequest.response,st()},Ut=function(){l(it,Dt,(function(){throw"could not load memory initializer "+it}))},jt=Tt(it);if(jt)Dt(jt.buffer);else if(t.memoryInitializerRequest){var Vt=function(){var e=t.memoryInitializerRequest,s=e.response;if(200!==e.status&&0!==e.status){var i=Tt(t.memoryInitializerRequestURL);if(!i)return console.warn("a problem seems to have happened with Module.memoryInitializerRequest, status: "+e.status+", retrying "+it),void Ut();s=i.buffer}Dt(s)};t.memoryInitializerRequest.response?setTimeout(Vt,0):t.memoryInitializerRequest.addEventListener("load",Vt)}else Ut()}function Qt(t){this.name="ExitStatus",this.message="Program terminated with exit("+t+")",this.status=t}function Wt(e){function s(){Et||(Et=!0,C||(N(),X(),t.onRuntimeInitialized&&t.onRuntimeInitialized(),G()))}$>0||(q(),$>0||(t.setStatus?(t.setStatus("Running..."),setTimeout((function(){setTimeout((function(){t.setStatus("")}),1),s()}),1)):s()))}function zt(e,s){s&&m&&0===e||(m||(C=!0,t.onExit&&t.onExit(e)),r(e,new Qt(e)))}function Jt(e){throw t.onAbort&&t.onAbort(e),b(e+=""),A(e),C=!0,"abort("+e+"). Build with -s ASSERTIONS=1 for more info."}if(t.then=function(e){if(Et)e(t);else{var s=t.onRuntimeInitialized;t.onRuntimeInitialized=function(){s&&s(),e(t)}}return t},tt=function t(){Et||Wt(),Et||(tt=t)},t.run=Wt,t.abort=Jt,t.preInit)for("function"==typeof t.preInit&&(t.preInit=[t.preInit]);t.preInit.length>0;)t.preInit.pop()();return m=!0,Wt(),t});t.exports=i,t.exports=i})),pn=e(s((function(t,e){Object.defineProperty(e,"__esModule",{value:!0});var s=function(){function t(t,e){void 0===e&&(e={}),this._module=null,this._options=null,this._options=Fi.__assign({stopAddress:0},e),this._module=fn(this._getApi(t,this._options)),this.enableDebug(!1)}return t.prototype.init=function(){return Fi.__awaiter(this,void 0,void 0,(function(){return Fi.__generator(this,(function(t){return this._module._set_stop_address(this._options.stopAddress),[2]}))}))},t.prototype.ping=function(){return this._module.ccall("ping","string",[],[])},t.prototype.run=function(t){return this._module._run(t)},t.prototype.abort=function(){this._module._abort_run()},t.prototype.enableDebug=function(t){this._module._enable_debug(t?1:0)},t.prototype.reset=function(){this._module._reset()},t.prototype.readRegister=function(t){if(t<0||t>15)throw new Error("illegal thumb register "+t);return this._module._read_register(t)},t.prototype.writeRegister=function(t,e){if(t<0||t>15)throw new Error("illegal thumb register "+t);this._module._write_register(t,e)},t.prototype._getApi=function(t,e){var s=e.printer||function(t){return console.log("thumbulator: "+t)};return{print:s,printErr:s,trapOnInstructionFetch:e.trapOnInstructionFetch||function(){return 0},trapOnBx32:e.trapOnBx32||function(){return 3},busRead16:t.read16,busRead32:t.read32||function(e){return 65535&t.read16(e)|t.read16(e+2)<<16},busWrite16:t.write16,busWrite32:t.write32||function(e,s){return t.write16(e,65535&s),t.write16(e+2,s>>>16)}}},t}();e.default=s})));function gn(t,e,s=!0,i=""){if(!s&&t<0)return gn(t>>>16,e&&e>8?e-4:4,!1,i)+gn(65535&t,4);let r=Math.abs(t).toString(16).toUpperCase();if(void 0!==e)for(;r.length<e;)r="0"+r;return(t<0?"-":"")+i+r}function bn(t,e,s=!0){return gn(t,e,s,"$")}class An{constructor(t=(()=>3)){this.trap=new n,this._thumbulatorBus={read16:t=>{if(1&t)return this._triggerTrap("unaligned 16 bit ARM read from "+bn(t,8,!1)),0;const e=268435455&t;switch(t>>>28){case 0:if(e<32768)return this.getRom16(e);break;case 4:if(e<8192)return this.getRam16(e);break;case 14:switch(e){case 2080768:return this._armMamcr}}this._triggerTrap("invalid 16 bit ARM read from "+bn(t,8,!1))},read32:t=>{if(3&t)return this._triggerTrap("unaligned 32 bit ARM read from "+bn(t,8,!1)),0;const e=268435455&t;switch(t>>>28){case 0:if(e<32768)return this.getRom32(e);break;case 4:if(e<8192)return this.getRam32(e);break;case 14:switch(e){case 32772:case 32776:return 0}}this._triggerTrap("invalid 32 bit ARM read from "+bn(t,8,!1))},write16:(t,e)=>{if(1&t)return void this._triggerTrap(`unaligned 16 bit ARM write: ${bn(e,4)} -> ${bn(t,8,!1)}`);const s=268435455&t;switch(t>>>28){case 4:if(s<8192)return void this.setRam16(s,65535&e);break;case 14:switch(s){case 2080768:return void(this._armMamcr=e)}}this._triggerTrap(`invalid 16 bit ARM write: ${bn(e,4)} -> ${bn(t,8,!1)}`)},write32:(t,e)=>{if(3&t)return void this._triggerTrap(`unaligned 32 bit ARM write: ${bn(e,8,!1)} -> ${bn(t,8,!1)}`);const s=268435455&t;switch(t>>>28){case 4:if(s<8192)return void this.setRam32(s,e);case 14:switch(s){case 32772:case 32776:return}}this._triggerTrap(`invalid 32 bit ARM write: ${bn(e,8,!1)} -> ${bn(t,8,!1)}`)}},this._romBuffer=new ArrayBuffer(32768),this._ramBuffer=new ArrayBuffer(8192),this._armMamcr=0,this._thumbulator=null,!function(){const t=new Uint8Array([1,2,3,4]);return 67305985===new Uint32Array(t.buffer)[0]}()?(this.getRom16=t=>this._rom8[t]|this._rom8[t+1]<<8,this.getRom32=t=>this._rom8[t]|this._rom8[t+1]<<8|this._rom8[t+2]<<16|this._rom8[t+3]<<24,this.getRam16=t=>this._ram8[t]|this._ram8[t+1]<<8,this.getRam32=t=>this._ram8[t]|this._ram8[t+1]<<8|this._ram8[t+2]<<16|this._ram8[t+3]<<24,this.setRam16=(t,e)=>{this._ram8[t]=255&e,this._ram8[t+1]=e>>>8&255},this.setRam32=(t,e)=>{this._ram8[t]=255&e,this._ram8[t+1]=e>>>8&255,this._ram8[t+2]=e>>>16&255,this._ram8[t+3]=e>>>24&255}):(this.getRom16=t=>this._rom16[t>>>1],this.getRom32=t=>this._rom32[t>>>2],this.getRam16=t=>this._ram16[t>>>1],this.getRam32=t=>this._ram32[t>>>2],this.setRam16=(t,e)=>this._ram16[t>>>1]=e,this.setRam32=(t,e)=>this._ram32[t>>>2]=e),this._rom8=new Uint8Array(this._romBuffer),this._rom16=new Uint16Array(this._romBuffer),this._rom32=new Uint32Array(this._romBuffer),this._ram8=new Uint8Array(this._ramBuffer),this._ram16=new Uint16Array(this._ramBuffer),this._ram32=new Uint32Array(this._ramBuffer),this._thumbulator=new pn(this._thumbulatorBus,{stopAddress:32772,trapOnBx32:t}),this.reset()}init(){return this._thumbulator.init()}reset(){}getRom(){return this._rom8}getRam(){return this._ram8}run(t){this._thumbulator.reset(),this._thumbulator.enableDebug(!1);for(let t=0;t<=12;t++)this._thumbulator.writeRegister(t,0);this._thumbulator.writeRegister(13,1073749940),this._thumbulator.writeRegister(14,32773),this._thumbulator.writeRegister(15,t),this._armMamcr=0;const e=this._thumbulator.run(5e5);20!==e&&10!==e&&this._triggerTrap("ARM execution trapped: "+e)}getThumbulator(){return this._thumbulator}_triggerTrap(t){this._thumbulator.abort(),this.trap.dispatch(t)}}class mn extends ni{constructor(t){if(super(),this._banks=new Array(6),this._fetchers=new Array(8),this._fractionalFetchers=new Array(8),this._musicFetchers=new Array(3),this._parameters=new Uint8Array(8),this._parameterIndex=0,this._rng=0,this._clockAccumulator=0,this._lastCpuTime=0,this._fastFetch=!1,this._ldaPending=!1,this._cpuTimeProvider=null,this._soc=new An,t.length<28672||t.length>32768)throw new Error("not a DPC+ image: invalid lenght "+t.length);this._rom=this._soc.getRom();for(let t=0;t<6;t++)this._banks[t]=new Uint8Array(this._rom.buffer,3072+4096*t,4096);this._ram=this._soc.getRam(),this._imageRam=new Uint8Array(this._ram.buffer,3072,4096);const e=32768-t.length;for(let s=0;s<t.length;s++)this._rom[e+s]=t[s];for(let t=0;t<8;t++)this._fetchers[t]=new kn,this._fractionalFetchers[t]=new yn;for(let t=0;t<3;t++)this._musicFetchers[t]=new wn;this._soc.trap.addHandler(t=>this.triggerTrap(2,t)),this.reset()}static matchesBuffer(t){return 2===oi(t,["DPC+".split("").map(t=>t.charCodeAt(0))])[0]}init(){return this._soc.init()}reset(){this._soc.reset(),this._currentBank=this._banks[5];for(let t=0;t<768;t++)this._soc.setRam32(t<<2,this._soc.getRom32(t<<2));for(let t=6912;t<8192;t++)this._soc.setRam32(768+t-6912<<2,this._soc.getRom32(t<<2));this._currentBank=this._banks[5];for(let t=0;t<8;t++)this._parameters[t]=0;for(let t=0;t<8;t++)this._fetchers[t].reset(),this._fractionalFetchers[t].reset();for(let t=0;t<3;t++)this._musicFetchers[t].reset();this._parameterIndex=0,this._fastFetch=this._ldaPending=!1,this._rng=725831748,this._lastCpuTime=0,this._clockAccumulator=0}getType(){return ei.CartridgeType.bankswitch_dpc_plus}setBus(t){return this._bus=t,this}setCpuTimeProvider(t){return this._cpuTimeProvider=t,this}read(t){return this._access(t,this._bus.getLastDataBusValue())}peek(t){return this._currentBank[4095&t]}write(t,e){this._access(t,e)}triggerTrap(t,e){super.triggerTrap(t,e)}_access(t,e){t&=4095;const s=this._currentBank[t];if(this._fastFetch&&this._ldaPending&&t>127&&t<4086&&s<40&&(t=s),this._ldaPending=!1,t<40){const e=7&t,s=this._fetchers[e],i=this._fractionalFetchers[e];let r=0;switch(t>>>3&7){case 0:switch(e){case 0:return this._advanceRng(),255&this._rng;case 1:return this._rewindRng(),255&this._rng;case 2:return this._rng>>>8&255;case 3:return this._rng>>>16&255;case 4:return this._rng>>>24&255;case 5:{this._clockMusicFetchers();let t=0;for(let e=0;e<3;e++)t+=this._imageRam[(this._musicFetchers[e].waveform<<5)+this._musicFetchers[e].waveformSample()];return 255&t}}return 0;case 1:return r=this._imageRam[s.pointer],s.increment(),r;case 2:return r=this._imageRam[s.pointer]&s.mask(),s.increment(),r;case 3:return r=this._imageRam[i.pointer>>>8],i.increment(),r;case 4:return e<4?s.mask():0;default:return 0}}else if(t<128){const s=7&t,i=this._fetchers[s],r=this._fractionalFetchers[s];switch(t-40>>>3&15){case 0:r.setPointerLo(e);break;case 1:r.setPointerHi(e);break;case 2:r.setFraction(e);break;case 3:i.top=e;break;case 4:i.bottom=e;break;case 5:i.setPointerLo(e);break;case 6:switch(s){case 0:this._fastFetch=0===e;break;case 1:this._parameterIndex<8&&(this._parameters[this._parameterIndex++]=e);break;case 2:this._dispatchFunction(e);break;case 5:case 6:case 7:this._musicFetchers[s-5].waveform=127&e}break;case 7:i.decrement(),this._imageRam[i.pointer]=e;break;case 8:i.setPointerHi(e);break;case 9:switch(s){case 0:this._rng=725831748;break;case 1:this._rng=4294967040&this._rng|e;break;case 2:this._rng=4294902015&this._rng|e<<8;break;case 3:this._rng=4278255615&this._rng|e<<16;break;case 4:this._rng=16777215&this._rng|e<<24;break;case 5:case 6:case 7:this._musicFetchers[s-5].frequency=this._soc.getRam32(7168+(e<<2))}break;case 10:this._imageRam[i.pointer]=e,i.increment()}}else t>4085&&t<4092&&(this._currentBank=this._banks[t-4086]);return this._fastFetch&&t>127&&t<4086&&(this._ldaPending=169===s),s}_clockMusicFetchers(){const t=this._cpuTimeProvider();this._clockAccumulator+=2e4*(t-this._lastCpuTime),this._lastCpuTime=t;const e=Math.floor(this._clockAccumulator);if(this._clockAccumulator-=e,0!==e)for(let t=0;t<3;t++)this._musicFetchers[t].increment(e)}_dispatchFunction(t){const e=this._parameters[0]+(this._parameters[1]<<8);switch(t){case 0:this._parameterIndex=0;break;case 1:for(let t=0;t<this._parameters[3];t++)this._ram[3072+(this._fetchers[7&this._parameters[2]].pointer+t&4095)]=this._rom[3072+(e+t)%29696];this._parameterIndex=0;break;case 2:for(let t=0;t<this._parameters[3];t++)this._ram[3072+(this._fetchers[7&this._parameters[2]].pointer+t&4095)]=this._parameters[0];this._parameterIndex=0;break;case 254:case 255:this._soc.run(3083)}}_advanceRng(){this._rng=(1024&this._rng?279816990:0)^(this._rng>>>11|this._rng<<21)}_rewindRng(){this._rng=this._rng&1<<31?(279816990^this._rng)<<11|(279816990^this._rng)>>>21:this._rng<<11|this._rng>>>21}}class kn{constructor(){this.pointer=0,this.top=0,this.bottom=0}contructor(){this.reset()}reset(){this.pointer=this.top=this.bottom=0}setPointerHi(t){this.pointer=255&this.pointer|(15&t)<<8}setPointerLo(t){this.pointer=3840&this.pointer|255&t}increment(){this.pointer=this.pointer+1&4095}decrement(){this.pointer=this.pointer+4095&4095}mask(){return(this.top-(255&this.pointer)&255)>(this.top-this.bottom&255)?255:0}}class yn{constructor(){this.pointer=0,this.fraction=0}contructor(){this.reset()}reset(){this.pointer=this.fraction=0}setPointerHi(t){this.pointer=65535&this.pointer|(15&t)<<16}setPointerLo(t){this.pointer=983295&this.pointer|(255&t)<<8}setFraction(t){this.fraction=t,this.pointer&=1048320}increment(){this.pointer=this.pointer+this.fraction&1048575}}class wn{constructor(){this.frequency=-1,this.counter=-1,this.waveform=0,this.reset()}reset(){this.frequency=0,this.waveform=0,this.counter=0}increment(t){this.counter=this.counter+t*this.frequency|0}waveformSample(){return this.counter>>>27}}class vn extends ni{constructor(t){super(),this._handleBxCDF0=t=>{const e=this._soc.getThumbulator(),s=e.readRegister(2),i=e.readRegister(3);switch(t){case 1762:return this._musicStreams[s%3].frequency=i,0;case 1766:return this._musicStreams[s%3].counter=0,0;case 1770:return e.writeRegister(2,this._musicStreams[s%3].counter),0;case 1774:return this._musicStreams[s%3].waveformSize=i,0}return 3},this._handleBxCDF1=t=>{const e=this._soc.getThumbulator(),s=e.readRegister(2),i=e.readRegister(3);switch(t){case 1874:return this._musicStreams[s%3].frequency=i,0;case 1878:return this._musicStreams[s%3].counter=0,0;case 1882:return e.writeRegister(2,this._musicStreams[s%3].counter),0;case 1886:return this._musicStreams[s%3].waveformSize=i,0}return 3},this._banks=new Array(7),this._currentBank=null,this._rom=null,this._ram=null,this._displayRam=null,this._musicStreams=new Array(3),this._clockAccumulator=0,this._lastCpuTime=0,this._soc=null,this._fastFetch=!1,this._digitalAudio=!1,this._fastJumpCountdown=0,this._fastFetchPending=!1,this._jmpOperandAddress=0,this._ldaOperandAddress=0,this._datastreamBase=0,this._datastreamIncrementBase=0,this._waveformBase=0,this._jumpstream=0,this._jumpstreamMask=0,this._amplitudeStream=0,this._bus=null,this._cpuTimeProvider=null;const e=vn.getVersion(t);switch(e){case 0:this._jumpstreamMask=255,this._amplitudeStream=34,this._datastreamBase=1760,this._datastreamIncrementBase=1896,this._waveformBase=2032;break;case 1:this._jumpstreamMask=255,this._amplitudeStream=34,this._datastreamBase=160,this._datastreamIncrementBase=296,this._waveformBase=432;break;case 2:this._jumpstreamMask=254,this._amplitudeStream=35,this._datastreamBase=152,this._datastreamIncrementBase=292,this._waveformBase=432;break;default:throw new Error("not a CDF image: missing signature")}if(32768!==t.length)throw new Error("not a CDF image: invalid lenght "+t.length);this._soc=new An(0===e?this._handleBxCDF0:this._handleBxCDF1),this._soc.trap.addHandler(t=>this.triggerTrap(2,t)),this._rom=this._soc.getRom();for(let e=0;e<32768;e++)this._rom[e]=t[e];for(let t=0;t<7;t++)this._banks[t]=new Uint8Array(this._rom.buffer,4096*(t+1),4096);this._ram=this._soc.getRam(),this._displayRam=new Uint8Array(this._soc.getRam().buffer,2048,4096);for(let t=0;t<3;t++)this._musicStreams[t]=new Cn;this.reset()}static getVersion(t){const e="CDF".split("").map(t=>t.charCodeAt(0)),s=function(t,e){for(let s=0;s<t.length;s++){let i;for(i=0;i<e.length&&(t[s+i]===e[i]||e[i]<0);i++);if(i===e.length)return s}return-1}(t,[...e,-1,...e,-1,...e]);if(s<0)return 3;switch(t[s+3]){case 0:return 0;case 1:return 1;case"J".charCodeAt(0):return 2;default:return 3}}static matchesBuffer(t){return 3!==vn.getVersion(t)}init(){return this._soc.init()}reset(){for(let t=0;t<512;t++)this._soc.setRam32(t<<2,this._soc.getRom32(t<<2));this._fastFetch=!1,this._digitalAudio=!1,this._fastJumpCountdown=0,this._fastFetchPending=!1,this._jmpOperandAddress=0,this._ldaOperandAddress=0,this._currentBank=this._banks[6];for(let t=0;t<3;t++)this._musicStreams[t].reset();this._lastCpuTime=0,this._clockAccumulator=0}getType(){return ei.CartridgeType.bankswitch_cdf}setBus(t){return this._bus=t,this}setCpuTimeProvider(t){return this._cpuTimeProvider=t,this}read(t){return this._access(t,this._bus.getLastDataBusValue())}peek(t){return this._currentBank[4095&t]}write(t,e){this._access(t,e)}_access(t,e){t&=4095;const s=this._currentBank[t];if(this._fastJumpCountdown-- >0&&t===this._jmpOperandAddress)return this._jmpOperandAddress++,this._datastreamReadWithIncrement(this._jumpstream,256);if(this._fastFetch&&76===s&&0==(this._currentBank[t+1&4095]&this._jumpstreamMask)&&0===this._currentBank[t+2&4095])return this._fastJumpCountdown=2,this._jmpOperandAddress=t+1&4095,this._jumpstream=33+this._currentBank[t+1&4095],s;if(this._fastJumpCountdown=0,this._fastFetch&&this._fastFetchPending&&this._ldaOperandAddress===t&&s<=this._amplitudeStream){if(this._fastFetchPending=!1,s===this._amplitudeStream){if(this._clockMusicStreams(),this._digitalAudio){const t=this._musicStreams[0].counter,e=this._soc.getRam32(this._waveformBase)+(t>>>21);let s=0;return e<32768&&(s=this._rom[e]),e>1073741824&&e<1073750016&&(s=this._ram[e-1073741824]),0==(1048576&t)&&(s>>>=4),15&s}{let t=0;for(let e=0;e<3;e++)t+=this._displayRam[this._getWaveform(e)+(this._musicStreams[e].counter>>>this._musicStreams[e].waveformSize)&4095];return t}}return this._datastreamRead(s)}if(this._fastFetchPending=!1,t>=4080){switch(t){case 4080:this._datastreamWriteWithIncrement(32,e,256);break;case 4081:{let t=this._getDatastreamPointer(32);t<<=8,t&=4026531840,t|=e<<20,this._setDatastreamPointer(32,t);break}case 4082:this._fastFetch=0==(15&e),this._digitalAudio=0==(240&e);break;case 4083:switch(e){case 254:case 255:this._soc.run(2059)}}t>4084&&t<4092&&(this._currentBank=this._banks[t-4085])}return this._fastFetch&&169===s&&(this._fastFetchPending=!0,this._ldaOperandAddress=t+1&4095),s}_clockMusicStreams(){const t=this._cpuTimeProvider();this._clockAccumulator+=2e4*(t-this._lastCpuTime),this._lastCpuTime=t;const e=Math.floor(this._clockAccumulator);if(this._clockAccumulator-=e,0!==e)for(let t=0;t<3;t++)this._musicStreams[t].increment(e)}_getDatastreamPointer(t){return this._soc.getRam32(this._datastreamBase+4*t)}_setDatastreamPointer(t,e){this._soc.setRam32(this._datastreamBase+4*t,e)}_getDatastreamIncrement(t){return this._soc.getRam32(this._datastreamIncrementBase+4*t)}_datastreamRead(t){const e=this._getDatastreamPointer(t),s=this._displayRam[e>>>20];return this._setDatastreamPointer(t,e+(this._getDatastreamIncrement(t)<<12)|0),s}_datastreamReadWithIncrement(t,e){const s=this._getDatastreamPointer(t),i=this._displayRam[s>>>20];return this._setDatastreamPointer(t,s+(e<<12)|0),i}_datastreamWriteWithIncrement(t,e,s){const i=this._getDatastreamPointer(t);this._displayRam[i>>>20]=e,this._setDatastreamPointer(t,i+(s<<12)|0)}_getWaveform(t){return this._soc.getRam32(this._waveformBase+4*t)-1073741824-2048&4095}}class Cn{constructor(){this.counter=0,this.frequency=0,this.waveformSize=27}reset(){this.counter=this.frequency=0,this.waveformSize=27}increment(t){this.counter=this.counter+t*this.frequency|0}}class Bn extends ni{constructor(t){if(super(),this._bank=null,this._bank0=new Uint8Array(4096),this._bank1=new Uint8Array(4096),this._bus=null,8192!==t.length)throw new Error("buffer is not an 8k cartridge image: wrong length "+t.length);for(let e=0;e<4096;e++)this._bank0[e]=t[e],this._bank1[e]=t[4096+e];this.reset()}static matchesBuffer(t){const e=oi(t,[[173,0,8],[173,64,8],[44,0,8],[12,0,8,76],[12,255,15,76]]);for(const t of e)if(t>=2)return!0;return!1}reset(){this._bank=this._bank0}read(t){return this.peek(t)}peek(t){return t&=4095,this._bank[t]}getType(){return ei.CartridgeType.bankswitch_8k_econobanking}setBus(t){return this._bus=t,this._bus.event.read.addHandler(this._onBusAccess,this),this._bus.event.write.addHandler(this._onBusAccess,this),this}_onBusAccess(t,e){switch(6208&e._bus.getLastAddresBusValue()){case 2048:e._bank=e._bank0;break;case 2112:e._bank=e._bank1}}}class xn extends ni{constructor(t){if(super(),this._banks=new Array(8),this._segments=new Array(4),this._ram=new Uint8Array(64),this._bankSwitchPending=!1,this._pendingBank=0,this._accessCounter=0,this._previousAddressBusValue=0,8192!==t.length&&8195!==t.length)throw new Error(`buffer is not a PP cartridge image; wrong length ${t.length} bytes`);for(let e=0;e<8;e++){this._banks[e]=new Uint8Array(1024);for(let s=0;s<1024;s++)this._banks[e][s]=t[1024*e+s]}this.reset()}getType(){return ei.CartridgeType.bankswitch_8k_pp}reset(){this._switchLayout(0),this._bankSwitchPending=!1}randomize(t){for(let e=0;e<64;e++)this._ram[e]=t.int(255)}setBus(t){return this._bus=t,t.event.read.addHandler(xn._onBusAccess,this),t.event.write.addHandler(xn._onBusAccess,this),this}read(t){return t&=4095,this._access(t,this._bus.getLastDataBusValue()),t<64?this._ram[t]:t<128?this._bus.getLastDataBusValue():this._segments[t>>>10][1023&t]}write(t,e){this._access(4095&t,e)}peek(t){return(t&=4095)<64?this._ram[t]:t<128?this._bus.getLastDataBusValue():this._segments[t>>>10][1023&t]}static _onBusAccess(t,e){let s=e._bus.getLastAddresBusValue();e._bankSwitchPending&&s!==e._previousAddressBusValue&&0==--e._accessCounter&&(e._switchLayout(e._pendingBank),e._bankSwitchPending=!1),4096&s||(s&=255,s>=48&&s<=63&&(e._pendingBank=15&s,e._accessCounter=3,e._bankSwitchPending=!0))}_access(t,e){t>=64&&t<128&&(this._ram[t-64]=e)}_switchLayout(t){switch(t){case 0:case 8:return this._configureSegments(0,0,1,2);case 1:case 9:return this._configureSegments(0,1,3,2);case 2:case 10:return this._configureSegments(4,5,6,7);case 3:case 11:return this._configureSegments(7,4,3,2);case 4:case 12:return this._configureSegments(0,0,6,7);case 5:case 13:return this._configureSegments(0,1,7,6);case 6:case 14:return this._configureSegments(3,2,4,5);case 7:case 15:return this._configureSegments(6,0,5,1);default:throw new Error("illegal layout index")}}_configureSegments(t,e,s,i){this._segments[0]=this._banks[t],this._segments[1]=this._banks[e],this._segments[2]=this._banks[s],this._segments[3]=this._banks[i]}}class Sn{detectCartridgeType(t){if(t.length%8448==0)return ei.CartridgeType.bankswitch_supercharger;if(t.length<2048)return ei.CartridgeType.vanilla_2k;if(t.length>=10240&&t.length<=10496)return ei.CartridgeType.bankswitch_8k_DPC;switch(t.length){case 2048:return this._detect2k(t);case 4096:return ei.CartridgeType.vanilla_4k;case 8192:return this._detect8k(t);case 8195:return ei.CartridgeType.bankswitch_8k_pp;case 12288:return ei.CartridgeType.bankswitch_12k_FA;case 16384:return this._detect16k(t);case 28672:return ei.CartridgeType.bankswitch_FA2;case 29696:return this._detect29k(t);case 32768:return this._detect32k(t);case 65536:return this._detect64k(t);default:return ei.CartridgeType.unknown}}_detect2k(t){return ci.matchesBuffer(t)?ei.CartridgeType.bankswitch_2k_cv:ei.CartridgeType.vanilla_2k}_detect8k(t){const e=ui.matchesBuffer(t);return _i.matchesBuffer(t)?ei.CartridgeType.bankswitch_8k_E0:fi.matchesBuffer(t)?ei.CartridgeType.bankswitch_8k_3F:gi.matchesBuffer(t)?ei.CartridgeType.bankswitch_8k_UA:!e&&di.matchesBuffer(t)?ei.CartridgeType.bankswitch_8k_FE:Bn.matchesBuffer(t)?ei.CartridgeType.bankswitch_8k_econobanking:ei.CartridgeType.bankswitch_8k_F8}_detect16k(t){return Ai.matchesBuffer(t)?ei.CartridgeType.bankswitch_16k_E7:ei.CartridgeType.bankswitch_16k_F6}_detect29k(t){return wi.matchesBuffer(t)?ei.CartridgeType.bankswitch_FA2:ei.CartridgeType.bankswitch_dpc_plus}_detect32k(t){return pi.matchesBuffer(t)?ei.CartridgeType.bankswitch_3E:mn.matchesBuffer(t)?ei.CartridgeType.bankswitch_dpc_plus:vn.matchesBuffer(t)?ei.CartridgeType.bankswitch_cdf:ei.CartridgeType.bankswitch_32k_F4}_detect64k(t){return ki.matchesBuffer(t)?ei.CartridgeType.bankswitch_64k_EF:ei.CartridgeType.bankswitch_64k_F0}}class Pn{createCartridge(t,e){return f(this,void 0,void 0,(function*(){const s=this._createCartridge(t,e);return yield s.init(),s}))}_createCartridge(t,e){if(void 0===e){e=(new Sn).detectCartridgeType(t)}switch(e){case ei.CartridgeType.vanilla_2k:return new ai(t);case ei.CartridgeType.vanilla_4k:return new hi(t);case ei.CartridgeType.bankswitch_2k_cv:return new ci(t);case ei.CartridgeType.bankswitch_8k_F8:return new ui(t);case ei.CartridgeType.bankswitch_8k_E0:return new _i(t);case ei.CartridgeType.bankswitch_8k_3F:return new fi(t);case ei.CartridgeType.bankswitch_8k_FE:return new di(t);case ei.CartridgeType.bankswitch_8k_UA:return new gi(t);case ei.CartridgeType.bankswitch_8k_DPC:return new Si(t);case ei.CartridgeType.bankswitch_8k_econobanking:return new Bn(t);case ei.CartridgeType.bankswitch_8k_pp:return new xn(t);case ei.CartridgeType.bankswitch_12k_FA:return new bi(t);case ei.CartridgeType.bankswitch_16k_F6:return new li(t);case ei.CartridgeType.bankswitch_16k_E7:return new Ai(t);case ei.CartridgeType.bankswitch_FA2:return new wi(t);case ei.CartridgeType.bankswitch_32k_F4:return new yi(t);case ei.CartridgeType.bankswitch_64k_F0:return new mi(t);case ei.CartridgeType.bankswitch_64k_EF:return new ki(t);case ei.CartridgeType.bankswitch_3E:return new pi(t);case ei.CartridgeType.bankswitch_supercharger:return new Bi(t);case ei.CartridgeType.bankswitch_dpc_plus:return new mn(t);case ei.CartridgeType.bankswitch_cdf:return new vn(t);default:throw new Error("invalid or unsupported cartridge image")}}}class Tn{constructor(t){this._board=t,this.message=new n,this._bufferOut=new Uint8Array(256),this._bufferIn=new Uint8Array(256),this._indexBufferOut=0,this._indexBufferIn=-1,this._bus=null,this._bus=this._board.getBus(),this._board.systemReset.addHandler(Tn._onReset,this),this._bus.event.write.addHandler(Tn._onWrite,this),this._bus.event.read.addHandler(Tn._onRead,this),this.reset()}reset(){for(let t=0;t<this._bufferOut.length;t++)this._bufferOut[t]=0;return this._indexBufferOut=0,this}send(t){this._indexBufferIn=t.length>256?255:t.length-1;for(let e=0;e<=this._indexBufferIn;e++)this._bufferIn[e]=t[e]}static _onWrite(t,e){if(0===t)switch(e._bus.getLastAddresBusValue()){case 48:e._bufferOut[e._indexBufferOut]=e._bus.getLastDataBusValue(),e._indexBufferOut=(e._indexBufferOut+1)%e._bufferOut.length;break;case 49:{const t=e._bus.getLastDataBusValue(),s=new Uint8Array(t);for(let i=0;i<t;i++){const r=(e._indexBufferOut-1+e._bufferOut.length)%e._bufferOut.length;s[t-i-1]=e._bufferOut[r],e._indexBufferOut=r}e.message.dispatch(s);break}}}static _onRead(t,e){if(0===t)switch(e._bus.getLastAddresBusValue()){case 48:e._bus.setDataBusValue(e._indexBufferIn>=0?e._bufferIn[e._indexBufferIn--]:0);break;case 49:e._bus.setDataBusValue(e._indexBufferIn>=0?e._indexBufferIn+1:0)}}static _onReset(t,e){e.reset()}}class En{constructor(t){this._period=t}setPeriod(t){return this._period=t,this}getPeriod(){return this._period}start(t,e){let s=!1;const i=()=>{s||(t(e),setTimeout(i,this._period))};return setTimeout(i,this._period),{stop:()=>s=!0}}}var In=s((function(t,e){t.exports=function(){var t=function(){return this||(0,eval)("this")}(),e=!(t.navigator&&/Trident|Edge/.test(t.navigator.userAgent)),s=1,i=!1,r={};function n(t){var e=Array.prototype.slice.call(arguments,1),s=e.length;return s?1===s?function(){return t.call(void 0,e[0])}:2===s?function(){return t.call(void 0,e[0],e[1])}:3===s?function(){return t.call(void 0,e[0],e[1],e[2])}:function(){return t.apply(void 0,e)}:function(){return t.call(void 0)}}function a(t){return r[s]=n.apply(void 0,t),s++}function h(t){delete r[t]}function o(e){if(i)t.setTimeout(n(o,e),0);else{var s=r[e];if(s){i=!0;try{s()}finally{h(e),i=!1}}}}function c(){var e=function(){var e=a(arguments);return t.setTimeout(n(o,e),0),e};return e.usePolifill="setTimeout",e}function u(){return"setTimeout"in t}var l=Object.freeze({init:c,canUse:u});function _(){var e=function(){var e=a(arguments);return t.process.nextTick(n(o,e)),e};return e.usePolifill="nextTick",e}function d(){return"[object process]"===Object.prototype.toString.call(t.process)}var f=Object.freeze({init:_,canUse:d});function p(){var e="setImmediate$"+Math.random()+"$",s=function(s){s.source===t&&"string"==typeof s.data&&0===s.data.indexOf(e)&&o(Number(s.data.slice(e.length)))};t.addEventListener?t.addEventListener("message",s,!1):t.attachEvent("onmessage",s);var i=function(){var s=a(arguments);return t.postMessage(e+s,"*"),s};return i.usePolifill="postMessage",i}function g(){if(t.importScripts||!t.postMessage)return!1;if(t.navigator&&/Chrome/.test(t.navigator.userAgent))return!1;var e=!0,s=t.onmessage;return t.onmessage=function(){e=!1},t.postMessage("","*"),t.onmessage=s,e}var b=Object.freeze({init:p,canUse:g});function A(){var e=new t.MessageChannel;e.port1.onmessage=function(t){o(Number(t.data))};var s=function(){var t=a(arguments);return e.port2.postMessage(t),t};return s.usePolifill="messageChannel",s}function m(){return Boolean(t.MessageChannel)}var k=Object.freeze({init:A,canUse:m});function y(){var e=t.document.documentElement,s=function(){var s=a(arguments),i=t.document.createElement("script");return i.onreadystatechange=function(){o(s),i.onreadystatechange=null,e.removeChild(i),i=null},e.appendChild(i),s};return s.usePolifill="readyStateChange",s}function w(){return t.document&&"onreadystatechange"in t.document.createElement("script")}var v=Object.freeze({init:y,canUse:w}),C=[f,b,k,v],B=e?t.setImmediate||t.msSetImmediate||P(C,l):c(),x=e&&(t.clearImmediate||t.msClearImmediate)||h;function S(){t.setImmediate!==B&&(t.setImmediate=B,t.msSetImmediate=B,t.clearImmediate=x,t.msClearImmediate=x)}function P(t,e){for(var s=0;s<t.length;s++){var i=t[s];if(i.canUse())return i.init()}return e.init()}return{setImmediate:B,clearImmediate:x,polifill:S}}()}));let Rn=0;function Mn(t){0===Rn?setTimeout(t,0):In.setImmediate(t),Rn=(Rn+1)%10}class Fn{start(t,e){let s=!1;return Mn((function i(){s||(t(e),Mn(i))})),{stop:()=>s=!0}}}const On=self.performance&&self.performance.now?()=>self.performance.now():()=>Date.now();class Hn{start(t,e,s){const i=s||50;let r=!0;return Mn((function s(){if(!r)return;const n=On();let a=0,h=0;for(;On()-n<i;){do{h=On()-n-a}while(h<1);a+=t(e,h)}h=On()-n-a,h>0&&(a+=t(e,h)),r&&Mn(s)})),{stop:()=>r=!1}}}const Ln=100;class Dn{start(t,e){let s=!1,i=-1,r=0,n=0;return Mn((function a(){if(s)return;const h=On();let o=(t(e)||0)-On()+h;i>=0&&(n+=i-h+r),n>Ln?n=Ln:n<-100&&(n=-100),Math.abs(n)>3&&(o+=n,n=0),o<0&&(o=0,n=o),o>0?setTimeout(a,Math.round(o)):Mn(a),i=o,r=On()})),{stop:()=>s=!0}}}class Un{start(t,e,s){const i=s||100;let r=On(),n=0,a=!0;return Mn((function s(){if(!a)return;const h=On();let o=h-r-n;o>3*i&&(o=3*i,r=h-o,n=0),n+=t(e,o);const c=i-On()+h;c>0?setTimeout(s,c):Mn(s)})),{stop:()=>a=!1}}}class jn{createPeriodicScheduler(t){return new En(t)}createImmediateScheduler(){return new Fn}createLimitingScheduler(t=1){switch(t){case 0:return new Hn;case 1:return new Dn;case 2:return new Un;default:throw new Error("invalud limiting scheduling strategy")}}getLimitingSchedulingStrategies(){return[0,1,2]}describeLimitingSchedulingStrategy(t){switch(t){case 0:return"Busy wait, constant timeslice length";case 1:return"Constant cycle count";case 2:return"Constant timeslice length";default:throw new Error("invalid limiting scheduling strategy")}}}class Vn{constructor(t){this._scheduler=t,this.frequencyUpdate=new n,this._counter=0,this._frequency=0}attach(t){return this._clock&&this.detach(),this._clock=t,t.addHandler(this._clockHandler,this),this}start(){return this._measurementTask||(this._timestamp=Date.now(),this._counter=0,this._measurementTask=this._scheduler.start(this._updateMeasurement,this)),this}detach(){return this._clock?(this._clock.removeHandler(this._clockHandler,this),this._clock=void 0,this):this}stop(){return this._measurementTask?(this._measurementTask.stop(),this._measurementTask=void 0,this):this}getFrequency(){return this._frequency}_updateMeasurement(t){const e=Date.now();t._frequency=t._counter/(e-t._timestamp)*1e3,t._counter=0,t._timestamp=e,t.frequencyUpdate.dispatch(t._frequency)}_clockHandler(t,e){e._counter+=t}}var Qn=function(){function t(t){if(this._maxConcurrency=t,this._queue=[],t<=0)throw new Error("semaphore must be initialized to a positive value");this._value=t}return t.prototype.acquire=function(){var t=this,e=this.isLocked(),s=new Promise((function(e){return t._queue.push(e)}));return e||this._dispatch(),s},t.prototype.runExclusive=function(t){return f(this,void 0,void 0,(function(){var e,s,i;return p(this,(function(r){switch(r.label){case 0:return[4,this.acquire()];case 1:e=r.sent(),s=e[0],i=e[1],r.label=2;case 2:return r.trys.push([2,,4,5]),[4,t(s)];case 3:return[2,r.sent()];case 4:return i(),[7];case 5:return[2]}}))}))},t.prototype.isLocked=function(){return this._value<=0},t.prototype.release=function(){if(this._maxConcurrency>1)throw new Error("this method is unavailabel on semaphores with concurrency > 1; use the scoped release returned by acquire instead");this._currentReleaser&&(this._currentReleaser(),this._currentReleaser=void 0)},t.prototype._dispatch=function(){var t=this,e=this._queue.shift();if(e){var s=!1;this._currentReleaser=function(){s||(s=!0,t._value++,t._dispatch())},e([this._value--,this._currentReleaser])}},t}(),Wn=function(){function t(){this._semaphore=new Qn(1)}return t.prototype.acquire=function(){return f(this,void 0,void 0,(function(){var t;return p(this,(function(e){switch(e.label){case 0:return[4,this._semaphore.acquire()];case 1:return t=e.sent(),[2,t[1]]}}))}))},t.prototype.runExclusive=function(t){return this._semaphore.runExclusive((function(){return t()}))},t.prototype.isLocked=function(){return this._semaphore.isLocked()},t.prototype.release=function(){this._semaphore.release()},t}();class zn{constructor(){this.stateChanged=new n,this.emulationError=new n,this._enforceRateLimit=!0,this._state=g.State.stopped,this._lastError=null,this._scheduler=null,this._clockProbe=new Vn(new En(2e3)),this._mutex=new Wn,this._schedulerFactory=new jn,this._limitingStrategy=1,this.frequencyUpdate=this._clockProbe.frequencyUpdate,this._updateScheduler()}init(){return Promise.resolve()}start(t,e,s){const i=new Pn;return this._mutex.runExclusive(()=>f(this,void 0,void 0,(function*(){try{if(this._stop(),this._limitingStrategy=e.pcmAudio?2:1,this._updateScheduler(),this._state===g.State.error)return this._state;const r=yield i.createCartridge(t,s),n=new ri(e,r);this._board=n,this._board.trap.addHandler(zn._trapHandler,this),e.asyncIO&&(this._asyncIO=new Tn(n)),this._context=new S(n,this._asyncIO),this._clockProbe.attach(this._board.clock),this._setState(g.State.paused)}catch(t){this._setError(t)}return this._state})))}stop(){return this._mutex.runExclusive(()=>this._stop())}pause(){return this._mutex.runExclusive(()=>{try{this._state===g.State.running&&(this._board.getTimer().stop(),this._board.suspend(),this._setState(g.State.paused),this._clockProbe.stop())}catch(t){this._setError(t)}return this._state})}resume(){return this._mutex.runExclusive(()=>{if(this._state===g.State.paused)try{this._tryToResume()}catch(t){this._setError(t)}return this._state})}reset(){return this._mutex.runExclusive(()=>{try{switch(this._state){case g.State.running:case g.State.paused:this._board.reset();break;case g.State.error:this._board.reset(),this._tryToResume()}}catch(t){this._setError(t)}return this._state})}getState(){return this._state}getEmulationContext(){switch(this._state){case g.State.running:case g.State.paused:return this._context;default:return null}}getLastError(){return this._lastError}getFrequency(){return this._clockProbe.getFrequency()}getRateLimit(){return this._enforceRateLimit}setRateLimit(t){return this._enforceRateLimit===t?Promise.resolve(void 0):this._mutex.runExclusive(()=>{this._state===g.State.running&&this._board.getTimer().stop(),this._enforceRateLimit=t,this._updateScheduler(),this._state===g.State.running&&this._board.getTimer().start(this._scheduler)})}static _trapHandler(t,e){e._setError(new Error("TRAP: "+t.message)),e.emulationError.dispatch(e._lastError)}_stop(){try{this._state===g.State.running&&(this._board.getTimer().stop(),this._board.suspend(),this._board.trap.removeHandler(zn._trapHandler,this),this._clockProbe.stop().detach()),this._board=null,this._context=null,this._asyncIO=void 0,this._setState(g.State.stopped)}catch(t){this._setError(t)}return this._state}_tryToResume(){this._state!==g.State.running&&(this._board.getTimer().start(this._scheduler),this._board.resume(),this._setState(g.State.running),this._clockProbe.start())}_setError(t){this._lastError=t,this._setState(g.State.error)}_setState(t){return t!==this._state&&(this._state=t,this.stateChanged.dispatch(t)),this._state}_updateScheduler(){this._scheduler=this._enforceRateLimit?this._schedulerFactory.createLimitingScheduler(this._limitingStrategy):this._schedulerFactory.createImmediateScheduler()}}class Jn{constructor(){this._drivers=new Map,this._driversBound=!1}bind(t){return this._driversBound||(this._emulationService=t,this._shouldBindDrivers()&&this._bindDrivers(),this._emulationService.stateChanged.addHandler(Jn._onEmuStateChange,this)),this}unbind(){return this._emulationService?(this._unbindDrivers(),this._emulationService.stateChanged.removeHandler(Jn._onEmuStateChange,this),this._emulationService=null,this):this}addDriver(t,e){return this._drivers.set(t,new Jn.DriverContext(t,e)),this._driversBound&&e(this._emulationService.getEmulationContext(),t),this}removeDriver(t){return this._drivers.get(t)?(t.unbind(),this._drivers.delete(t),this):this}static _onEmuStateChange(t,e){e._shouldBindDrivers(t)?e._bindDrivers():e._unbindDrivers()}_shouldBindDrivers(t=(this._emulationService?this._emulationService.getState():void 0)){return this._emulationService&&(t===g.State.running||t===g.State.paused)}_bindDrivers(){this._driversBound||(this._drivers.forEach(t=>t.binder(this._emulationService.getEmulationContext(),t.driver)),this._driversBound=!0)}_unbindDrivers(){this._driversBound&&(this._drivers.forEach(t=>t.driver.unbind()),this._driversBound=!1)}}!function(t){t.DriverContext=class{constructor(t,e){this.driver=t,this.binder=e}}}(Jn||(Jn={}));const Yn={emulationPause:"emulation/pause",emulationReset:"emulation/reset",emulationResume:"emulation/resume",emulationSetRateLimit:"emulation/setRateLimit",emulationStart:"emulation/start",emulationStop:"emulation/stop",emulationFetchLastError:"emulation/fetchLastError",getVideoParameters:"video/getParameters",getWaveformAudioParameters:t=>"audio/waveform/getParameters/"+t,getPCMAudioParameters:t=>"audio/pcm/getParameters/"+t,setup:"/setup"};Object.freeze(Yn);const qn={emulationError:"emulation/error",emulationFrequencyUpdate:"emulation/frequencyUpdate",videoNewFrame:"video/newFrame",videoReturnSurface:"video/returnSurface",controlStateUpdate:"control/stateUpdate",waveformAudioVolumeChange:"audio/waveform/volumeChange",waveformAudioBufferChange:"audio/waveform/bufferChange",pcmAudioNewFrame:t=>"audio/pcm/newFrame/"+t,pcmAudioTogglePause:t=>"audio/pcm/togglePause/"+t,pcmAudioReturnFrame:t=>"audio/pcm/returnFrame/"+t,audioStop:"audio/stop",messageFromAsyncIO:"asyncIO/messageFrom",messageToAsyncIO:"asyncIO/messageTo"};Object.freeze(qn);class Nn{constructor(t){this._rpc=t,this._active=!1,this._video=null,this._mutex=new Wn,this._surfacePool=null,this._managedSurfacesById=null,this._ids=null,this._width=0,this._height=0,this._nextId=0}init(){this._rpc.registerSignalHandler(qn.videoReturnSurface,this._onReturnSurfaceFromHost.bind(this)).registerRpcHandler(Yn.getVideoParameters,this._onGetVideoParameters.bind(this))}bind(t){this._mutex.runExclusive(()=>this._bind(t))}unbind(){this._mutex.runExclusive(()=>this._unbind())}static _onNewFrame(t,e){if(!e._active)return void console.warn("new frame passed to inactive driver");if(!e._managedSurfaces.has(t))return void console.warn("surface not registered");const s=t.getUnderlyingBuffer(),i=e._ids.get(e._managedSurfaces.get(t));e._rpc.signal(qn.videoNewFrame,{id:i,width:e._width,height:e._height,buffer:s},[s])}_bind(t){return f(this,void 0,void 0,(function*(){this._active||(this._width=t.getWidth(),this._height=t.getHeight(),this._video=t,this._surfacePool=new k(()=>y.createFromArrayBuffer(this._width,this._height,new ArrayBuffer(4*this._width*this._height))),this._managedSurfacesById=new Map,this._managedSurfaces=new WeakMap,this._ids=new WeakMap,this._video.setSurfaceFactory(()=>{const t=this._surfacePool.get(),e=t.get();if(!this._ids.has(t)){const s=this._nextId++;this._ids.set(t,s),this._managedSurfacesById.set(s,t),this._managedSurfaces.set(e,t),e.fill(4278190080)}return t.get()}),this._video.newFrame.addHandler(Nn._onNewFrame,this),this._active=!0)}))}_unbind(){return f(this,void 0,void 0,(function*(){this._active&&(this._active=!1,this._video.setSurfaceFactory(null),this._video.newFrame.removeHandler(Nn._onNewFrame,this),this._video=null,this._surfacePool=null,this._managedSurfacesById=null,this._ids=null)}))}_onReturnSurfaceFromHost(t){if(!this._active)return void console.warn("surface returned from host to inactive driver");const e=this._managedSurfacesById.get(t.id);e?(e.get().replaceUnderlyingBuffer(this._width,this._height,t.buffer),e.release()):console.warn("invalid member ID "+t.id)}_onGetVideoParameters(){return{width:this._width,height:this._height}}}class Xn{constructor(t){this._rpc=t,this._active=!1,this._emulationContext=null}init(){this._rpc.registerSignalHandler(qn.controlStateUpdate,this._onControlStateUpdate.bind(this))}bind(t){this._active||(this._active=!0,this._emulationContext=t)}unbind(){this._active&&(this._active=!1,this._emulationContext=null)}_onControlStateUpdate(t){if(this._active){for(let e=0;e<2;e++)this._applyJoystickState(t.joystickState[e],this._emulationContext.getJoystick(e));for(let e=0;e<4;e++)this._applyPaddleState(t.paddleState[e],this._emulationContext.getPaddle(e));this._applyControlPanelState(t.controlPanelState,this._emulationContext.getControlPanel())}}_applyJoystickState(t,e){e.getUp().toggle(t.up),e.getDown().toggle(t.down),e.getLeft().toggle(t.left),e.getRight().toggle(t.right),e.getFire().toggle(t.fire)}_applyPaddleState(t,e){e.setValue(t.value),e.getFire().toggle(t.fire)}_applyControlPanelState(t,e){e.getDifficultySwitchP0().toggle(t.difficulty0),e.getDifficultySwitchP1().toggle(t.difficulty1),e.getResetButton().toggle(t.reset),e.getColorSwitch().toggle(t.color),e.getSelectSwitch().toggle(t.select)}}class Gn{constructor(t,e){this._index=t,this._rpc=e,this._audio=null,this._rpc.registerRpcHandler(Yn.getWaveformAudioParameters(this._index),this._onGetWaveformAudioParameters.bind(this))}bind(t){this._audio||(this._audio=t,this._audio.bufferChanged.addHandler(Gn._onBufferChanged,this),this._audio.volumeChanged.addHandler(Gn._onVolumeChanged,this),this._audio.stop.addHandler(Gn._onStop,this))}unbind(){this._audio&&(this._audio.bufferChanged.removeHandler(Gn._onBufferChanged,this),this._audio.volumeChanged.removeHandler(Gn._onVolumeChanged,this),this._audio.stop.removeHandler(Gn._onStop,this),this._audio=null)}static _onBufferChanged(t,e){e._rpc.signal(qn.waveformAudioBufferChange,{index:e._index,key:t})}static _onVolumeChanged(t,e){e._rpc.signal(qn.waveformAudioVolumeChange,{index:e._index,value:t})}static _onStop(t,e){e._rpc.signal(qn.audioStop,e._index)}_onGetWaveformAudioParameters(){return{volume:this._audio.getVolume()}}}class Kn{constructor(t,e){this._rpc=e,this._enabled=!1,this._sampleRate=0,this._frameSize=0,this._pendingFrames=new Map,this._nextId=0,this._paused=!1,this._signalNewFrame="",this._signalTogglePause="",this._rpc.registerRpcHandler(Yn.getPCMAudioParameters(t),this._onGetPCMAudioParameters.bind(this)).registerSignalHandler(qn.pcmAudioReturnFrame(t),this._onReturnFrame.bind(this)),this._signalNewFrame=qn.pcmAudioNewFrame(t),this._signalTogglePause=qn.pcmAudioTogglePause(t)}bind(t){this._enabled&&this.unbind(),this._endpoint=t,this._endpoint.newFrame.addHandler(Kn._onNewFrame,this),this._endpoint.togglePause.addHandler(Kn._onTogglePause,this),this._sampleRate=this._endpoint.getSampleRate(),this._frameSize=this._endpoint.getFrameSize(),this._enabled=!0}unbind(){this._enabled&&(this._endpoint.newFrame.removeHandler(Kn._onNewFrame,this),this._endpoint.togglePause.removeHandler(Kn._onTogglePause,this),this._endpoint=null,this._pendingFrames.clear(),this._sampleRate=this._frameSize=0,this._enabled=!1)}static _onNewFrame(t,e){if(!e._enabled)return void t.dispose();const s=e._nextId++,i=t.get();e._pendingFrames.set(s,t),e._rpc.signal(e._signalNewFrame,{id:s,buffer:i.buffer},[i.buffer])}static _onTogglePause(t,e){e._paused=t,e._rpc.signal(e._signalTogglePause,{paused:t})}_onGetPCMAudioParameters(){return{sampleRate:this._sampleRate,frameSize:this._frameSize,paused:this._paused}}_onReturnFrame(t){if(!this._enabled||!this._pendingFrames.has(t.id))return;const e=this._pendingFrames.get(t.id);this._pendingFrames.delete(t.id),e.adopt(new Float32Array(t.buffer)),e.release()}}class Zn{constructor(){this.message=new n,this._io=null}bind(t){this._io||(t&&t.message.addHandler(Zn._onAsyncIOMessage,this),this._io=t)}unbind(){this._io&&(this._io.message.removeHandler(Zn._onAsyncIOMessage,this),this._io=null)}send(t){this._io&&this._io.send(t)}static _onAsyncIOMessage(t,e){e.message.dispatch(t)}}class $n{constructor(t){this._rpc=t,this._videoDriver=null,this._service=new zn}startup(){const t=new Jn,e=new Nn(this._rpc),s=new Xn(this._rpc),i=[0,1].map(t=>new Gn(t,this._rpc)),r=new Kn(0,this._rpc),n=new Zn;this._rpc.registerRpcHandler(Yn.setup,this._onSetup.bind(this)).registerRpcHandler(Yn.emulationFetchLastError,this._onFetchLastError.bind(this)).registerRpcHandler(Yn.emulationPause,this._onEmulationPause.bind(this)).registerRpcHandler(Yn.emulationReset,this._onEmulationReset.bind(this)).registerRpcHandler(Yn.emulationResume,this._onEmulationResume.bind(this)).registerRpcHandler(Yn.emulationSetRateLimit,this._onEmulationSetRateLimit.bind(this)).registerRpcHandler(Yn.emulationStart,this._onEmulationStart.bind(this)).registerRpcHandler(Yn.emulationStop,this._onEmulationStop.bind(this)).registerSignalHandler(qn.messageToAsyncIO,t=>n.send(t)),n.message.addHandler(t=>this._rpc.signal(qn.messageFromAsyncIO,t)),this._service.frequencyUpdate.addHandler($n._onFrequencyUpdate,this),this._service.emulationError.addHandler($n._onEmulationError,this),this._videoDriver=e,e.init(),s.init(),t.addDriver(e,(t,e)=>e.bind(t.getRawVideo())).addDriver(s,(t,e)=>e.bind(t)).addDriver(r,(t,e)=>e.bind(t.getPCMChannel())).addDriver(n,(t,e)=>e.bind(t.getAsyncIO())).bind(this._service);for(let e=0;e<2;e++)t.addDriver(i[e],(t,s)=>s.bind(t.getWaveformChannels()[e]))}static _onFrequencyUpdate(t,e){e._rpc.signal(qn.emulationFrequencyUpdate,t)}static _onEmulationError(t,e){e._rpc.signal(qn.emulationError,t?t.message:null)}_onSetup(t){this._videoDriver.init()}_onFetchLastError(){const t=this._service.getLastError();return t?t.message:null}_onEmulationPause(){return this._service.pause()}_onEmulationReset(){return this._service.reset()}_onEmulationResume(){return this._service.resume()}_onEmulationStart(t){return this._service.start(t.buffer,t.config,t.cartridgeType)}_onEmulationStop(){return this._service.stop()}_onEmulationSetRateLimit(t){return this._service.setRateLimit(t)}}new $n(c).startup()}();
//# sourceMappingURL=stellerator.min.js.map