!function(e){var o={};function i(a){if(o[a])return o[a].exports;var r=o[a]={i:a,l:!1,exports:{}};return e[a].call(r.exports,r,r.exports,i),r.l=!0,r.exports}i.m=e,i.c=o,i.d=function(e,o,a){i.o(e,o)||Object.defineProperty(e,o,{configurable:!1,enumerable:!0,get:a})},i.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},i.n=function(e){var o=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(o,"a",o),o},i.o=function(e,o){return Object.prototype.hasOwnProperty.call(e,o)},i.p="",i(i.s=15)}([function(e,o,i){!function(){"use strict";var o=i(8);e.exports=function(e){return o[e]?escapeHtml(o[e][0]):"Unknown Game"}}()},,,,,,function(e,o,i){!function(){"use strict";function o(e){this.el=e,this.currentlyBinding=!1,this.initialHTML=e.innerHTML,this.el.addEventListener("keydown",this.onKeyDown.bind(this)),this.paused=!1}o.prototype=Object.create(Object.prototype),o.prototype.constructor=o,o.prototype.setPausedState=function(e){this.paused=e,this.el.querySelector(".load-rom-section").style.display=e?"none":"",this.el.querySelector(".paused-section").style.display=e?"":"none"},o.prototype.reset=function(){var e;this.el.innerHTML=this.initialHTML,this.currentlyBinding=!1;var o=this.el.querySelector(".saves-list"),a="
",r=window.vbaSaves.listSaves();for(e=0;e["+r[e].romCode+"] "+i(0)(r[e].romCode)+" | Export | Delete | ";r.length||(a+="None |
"),window.isShittyLocalstorage&&(a+="Saving will not be possible because the 'LocalStorage' feature of your browser is disabled. |
"),a+="
",o.innerHTML=a;var s=this.el.querySelector(".keyboard-bindings"),n="",t=window.vbaInput.listBindings();function m(e){return e.join(", ").replace(/Key/im,"Key ").replace(/Arrow/im,"Arrow ").replace(/Digit/im,"Digit ").replace(/Numpad/im,"Numpad ").replace(/Left/im," Left").replace(/Right/im," Right")}for(e=0;e"+t[e].friendlyName+" | "+m(t[e].codes)+" | Rebind | ","PAUSE"===t[e].name&&(this.el.querySelector(".unpause-key-prompt").innerText=m(t[e].codes));n+="
",s.innerHTML=n,this.setPausedState(this.paused)},o.prototype.export=function(){vbaSaves.exportSave()},o.prototype.onKeyDown=function(e){if(this.currentlyBinding){var o=vbaInput.bindings[this.currentlyBinding].codes.join();vbaInput.setBinding(this.currentlyBinding,e.code,e.keyCode);var i=vbaInput.bindings[this.currentlyBinding].codes.join();gtag("event","rebind_key_1",{event_label:"Change "+this.currentlyBinding+" from "+o+" to "+i}),this.reset()}},o.prototype.startRebinding=function(e,o){this.currentlyBinding=o,this.el.querySelectorAll(".rebind-key-button").forEach(function(e){e.innerText="Rebind"}),e.innerText="Rebinding..."},o.prototype.resetBindings=function(){gtag("event","reset_bindings_1",{}),vbaInput.resetBindings(),this.reset()},o.prototype.exportSave=function(e){vbaSaves.exportSave(e),this.reset(),gtag("event","export_save_1",{event_label:e+" "+i(0)(e)})},o.prototype.deleteSave=function(e){var o=modal("Are you sure you want to delete your save for ["+e+"] "+i(0)(e)+"?",{title:"Confirm Deletion",leftButtonText:"Delete",leftButtonFn:function(){vbaSaves.deleteSave(e),this.reset(),gtag("event","delete_save_1",{event_label:e+" "+i(0)(e)})}.bind(this),rightButtonText:"Cancel",rightButtonFn:function(){o.hideModal()}})},e.exports=o}()},function(e,o){!function(){"use strict";var o={};function i(){this.downCodes={},this.downKeyCodes={},window.addEventListener("keydown",function(e){var o=this.isKeyDown(this.bindings.PERF_STATS),i=this.isKeyDown(this.bindings.PAUSE);this.downCodes[e.code]=1,this.downKeyCodes[e.keyCode]=1;var a=this.isKeyDown(this.bindings.PERF_STATS);!o&&a&&window.doPerfCalc();var r=this.isKeyDown(this.bindings.PAUSE);return!i&&r&&window.togglePause(),!1}.bind(this)),window.addEventListener("keyup",function(e){var o=this.isKeyDown(this.bindings.PERF_STATS);this.downCodes[e.code]=0,this.downKeyCodes[e.keyCode]=0;var i=this.isKeyDown(this.bindings.PERF_STATS);return o&&!i&&window.doPerfCalc(),!1}.bind(this)),this.bindings=null,this.loadBindings(),null===this.bindings&&this.resetBindings()}o.KEY_BUTTON_A={friendlyName:"A",codes:["KeyZ"],keyCodes:[90]},o.KEY_BUTTON_B={friendlyName:"B",codes:["KeyX"],keyCodes:[88]},o.KEY_BUTTON_SELECT={friendlyName:"Select",codes:["Backspace"],keyCodes:[8]},o.KEY_BUTTON_START={friendlyName:"Start",codes:["Enter"],keyCodes:[13]},o.KEY_RIGHT={friendlyName:"Right",codes:["ArrowRight"],keyCodes:[39]},o.KEY_LEFT={friendlyName:"Left",codes:["ArrowLeft"],keyCodes:[37]},o.KEY_UP={friendlyName:"Up",codes:["ArrowUp"],keyCodes:[38]},o.KEY_DOWN={friendlyName:"Down",codes:["ArrowDown"],keyCodes:[40]},o.KEY_BUTTON_R={friendlyName:"R",codes:["Control"],keyCodes:[17]},o.KEY_BUTTON_L={friendlyName:"L",codes:["Shift"],keyCodes:[16]},o.PERF_STATS={friendlyName:"Performance Stats",codes:["Backquote"],keyCodes:[192]},o.PAUSE={friendlyName:"Pause",codes:["Escape"],keyCodes:[27]},i.prototype=Object.create(Object.prototype),i.prototype.constructor=i,i.prototype.listBindings=function(){return Object.keys(this.bindings).map(function(e){return{name:e,friendlyName:this.bindings[e].friendlyName,codes:this.bindings[e].codes}}.bind(this))},i.prototype.setBinding=function(e,o,i){this.bindings[e].codes=[o],this.bindings[e].keyCodes=[i],this.saveBindings()},i.prototype.loadBindings=function(e){if(this.bindings=JSON.parse(localStorage.VBABindings||"null")||o,Object.keys(this.bindings).sort().join()!==Object.keys(o).sort().join()){if(e)return;this.resetBindings(!0)}},i.prototype.saveBindings=function(){localStorage.VBABindings=JSON.stringify(this.bindings)},i.prototype.resetBindings=function(e){this.bindings=o,this.saveBindings(),this.loadBindings(e)},i.prototype.isKeyDown=function(e){var o;for(o=0;o=0?e:e+this.audioSpareSamplesRingBuffer.length},o.prototype.resetSound=function(){},o.prototype.writeSound=function(e,o){if(e%2!=1)if(o%2==0){var i,a=e>>1,r=this.emscriptenModule.HEAP16;for(i=0;i=this.audioSpareSamplesRingBuffer.length&&(this.audioSpareWritePtr=0)}else console.error("Number of audio samples must be even.");else console.error("Audio pointer must be 16 bit aligned.")},o.prototype.handleAudioEvent=function(e){if(hasEmuModule()&&VBAInterface.VBA_get_emulating()){var o,i,a=[],r=e.outputBuffer.numberOfChannels,s=e.outputBuffer.length,n=1;for(o=0;o=this.audioSpareSamplesRingBuffer.length&&(this.audioSpareReadPtr-=this.audioSpareSamplesRingBuffer.length));this.spareSamplesAtLastEvent=this.getNumExtraSamples(),vbaPerf.spareAudioSamplesThisSecond.push(this.spareSamplesAtLastEvent),vbaPerf.audioDeadlineResultsThisSecond.push(n);var t=window.frameNum;setTimeout(function(){window.doTimestep(t+1)},0)}},i.prototype=Object.create(Object.prototype),i.prototype.constructor=i,i.prototype.getSampleRate=function(){return 44100},i.prototype.currentAudioTime=function(){return Date.now()/1e3},i.prototype.getNumExtraSamples=function(){return 0},i.prototype.resetSound=function(){},i.prototype.writeSound=function(){},i.prototype.handleAudioEvent=function(){},window.AudioContext?e.exports=o:e.exports=i}()},function(e,o){!function(){"use strict";var o={compileShader:function(e,o,i){var a=e.createShader(i);if(e.shaderSource(a,o),e.compileShader(a),!e.getShaderParameter(a,e.COMPILE_STATUS))throw new Error("could not compile shader:"+e.getShaderInfoLog(a));return a},createProgram:function(e,o,i){var a=e.createProgram();if(e.attachShader(a,o),e.attachShader(a,i),e.linkProgram(a),!e.getProgramParameter(a,e.LINK_STATUS))throw new Error("program filed to link:"+e.getProgramInfoLog(a));return a},createShaderFromScript:function(e,o,i){var a=document.getElementById(o),r=a.text;if(!i)if("x-shader/x-vertex"===a.type)i=e.VERTEX_SHADER;else{if("x-shader/x-fragment"!==a.type)throw new Error("Unreachable");i=e.FRAGMENT_SHADER}return this.compileShader(e,r,i)},createProgramFromScripts:function(e,o,i){var a=this.createShaderFromScript(e,o),r=this.createShaderFromScript(e,i);return this.createProgram(e,a,r)},createTexture:function(e,o){var i=e.createTexture();e.bindTexture(e.TEXTURE_2D,i);var a=new Uint16Array(o*o);return e.texImage2D(e.TEXTURE_2D,0,e.RGBA,o,o,0,e.RGBA,e.UNSIGNED_SHORT_5_5_5_1,a),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),i},updateTexture:function(e,o,i,a,r){e.bindTexture(e.TEXTURE_2D,o),e.texSubImage2D(e.TEXTURE_2D,0,0,0,i,a,e.RGBA,e.UNSIGNED_SHORT_5_5_5_1,r)},createFullscreenQuad:function(e,o,i){var a=e.createBuffer();return e.bindBuffer(e.ARRAY_BUFFER,a),e.bufferData(e.ARRAY_BUFFER,new Float32Array([o,o,i,o,o,i,o,i,i,o,i,i]),e.STATIC_DRAW),a}},i=240,a=160;function r(e,o){this.emscriptenModule=e,this.canvas=o,this.totalFrames=0,this.lastFrameTime=window.performance.now(),this.gl=null,this.fullscreenQuadBuffer=null,this.texture=null,this.shaderProgram=null,this.positionLocation=null,this.textureSamplerLocation=null,this.pixels=new Uint16Array(i*a)}r.prototype=Object.create(Object.prototype),r.prototype.constructor=r,r.prototype.initScreen=function(){return this.gl=this.canvas.getContext("webgl",{alpha:!1})||this.canvas.getContext("experimental-webgl",{alpha:!1}),!!this.gl&&(this.shaderProgram=o.createProgramFromScripts(this.gl,"2d-vertex-shader","2d-fragment-shader"),this.texture=o.createTexture(this.gl,256),this.fullscreenQuadBuffer=o.createFullscreenQuad(this.gl,0,1),this.positionLocation=this.gl.getAttribLocation(this.shaderProgram,"a_position"),this.textureSamplerLocation=this.gl.getUniformLocation(this.shaderProgram,"u_sampler"),!0)},r.prototype.drawGBAFrame=function(e){window.performance.now(),this.lastFrameTime;vbaPerf.renderDeadlineResultsThisSecond.push(window.hasRequestedFrameButNotRendered),window.hasRequestedFrameButNotRendered=!1,this.lastFrameTime=window.performance.now();for(var r=e/2,s=this.emscriptenModule.HEAP16,n=0;n',window.vbaGraphics=new a(window.gbaninja,document.querySelector("canvas")),!window.vbaGraphics.initScreen())return window.vbaGraphics=null,document.querySelector(".pixels").innerHTML="You need to enable WebGL
",void gtag("event","webgl_disabled_at_init_1",{});window.vbaGraphics.drawFrame(),window.vbaSound=new r(window.gbaninja),window.vbaSaves=new s(window.gbaninja),window.vbaInput=new n(window.gbaninja),window.vbaUI=new t(document.querySelector(".ui")),document.querySelector(".pixels").style.display="none",qs.exclusive||(document.querySelector(".ui").style.display="block"),vbaUI.reset(),window.doPerfCalc()},window.start=function(){if(window.isRunning)throw new Error("Already started");if(window.vbaGraphics){document.querySelector(".pixels").style.display="block",document.querySelector(".ui").style.display="none";var e=window.vbaGraphics.onResize.bind(window.vbaGraphics,window.innerWidth,window.innerHeight);window.onresize=e,e(),VBAInterface.VBA_start(),gtag("event","run_rom_1",{event_label:window.vbaSaves.getRomCode()+" "+i(0)(window.vbaSaves.getRomCode())}),m=!0,window.focusCheck(),window.doTimestep(window.frameNum+1)}else gtag("event","webgl_disabled_at_start_1",{})};window.lastFrameTime=window.performance.now(),window.frameTimeout=null,window.animationFrameRequest=null,window.frameNum=1,window.lastFocusTime=0,window.vbaPerf={},vbaPerf.deltaTimesThisSecond=[],vbaPerf.cyclesThisSecond=[],vbaPerf.renderDeadlineResultsThisSecond=[],vbaPerf.spareAudioSamplesThisSecond=[],vbaPerf.audioDeadlineResultsThisSecond=[],window.doTimestep=function(e,o){if(hasEmuModule()&&e===window.frameNum+1){window.frameNum=e;var i=window.performance.now(),a=i-lastFrameTime,r=Math.min(50,a);if(i-window.lastFocusTime>100||a<.1)window.animationFrameRequest=window.requestAnimationFrame(function(){window.doTimestep(e+1)});else if(lastFrameTime=i,m){vbaSaves.checkSaves();var s=Math.floor(16777216/(1e3/r));vbaSound.spareSamplesAtLastEvent>1e3&&(s-=Math.floor(Math.min(.03*s,1677.7216))),vbaSound.spareSamplesAtLastEvent<700&&(s+=Math.floor(Math.min(.03*s,1677.7216))),u||VBAInterface.VBA_do_cycles(s),vbaPerf.deltaTimesThisSecond.push(a),vbaPerf.cyclesThisSecond.push(s),clearTimeout(window.frameTimeout),window.frameTimeout=setTimeout(function(){window.doTimestep(e+1)},2),cancelAnimationFrame(window.animationFrameRequest),window.animationFrameRequest=window.requestAnimationFrame(function(){window.doTimestep(e+1)})}else VBAInterface.VBA_get_emulating()&&(VBAInterface.VBA_stop(),document.querySelector(".pixels").style.display="none",document.querySelector(".ui").style.display="block")}},window.hasRequestedFrameButNotRendered=!1,window.focusCheck=function(){window.lastFocusTime=window.performance.now(),window.hasRequestedFrameButNotRendered=!0,window.requestAnimationFrame(window.focusCheck)},window.perfTimer=null,window.lastPerfTime=performance.now(),window.doPerfCalc=function(){clearTimeout(window.perfTimer);var e=window.performance.now(),o=e-lastPerfTime;if(window.lastPerfTime=e,hasEmuModule()&&window.vbaInput.isKeyDown(vbaInput.bindings.PERF_STATS)){function a(e){return Math.floor(e/window.vbaSound.getSampleRate()*1e3)+"ms"}document.querySelector(".perf").style.display="block";var r=window.vbaSaves.getRomCode(),s=vbaPerf.cyclesThisSecond.reduce(function(e,o){return e+o},0),n=vbaPerf.spareAudioSamplesThisSecond.reduce(function(e,o){return Math.max(e,o)},0),t=vbaPerf.spareAudioSamplesThisSecond.reduce(function(e,o){return Math.min(e,o)},1/0);t===1/0&&(t=0);var m=vbaPerf.audioDeadlineResultsThisSecond.reduce(function(e,o){return o?e.hit++:e.miss++,e},{hit:0,miss:0}),u=vbaPerf.renderDeadlineResultsThisSecond.reduce(function(e,o){return o?e.hit++:e.miss++,e},{hit:0,miss:0});document.querySelector(".perf-game").innerText=(r?r+" ":"")+i(0)(r),document.querySelector(".perf-timesteps").innerText=Math.round(vbaPerf.cyclesThisSecond.length/(o/1e3)),document.querySelector(".perf-percentage").innerText=(s/(o/1e3*16777216)*100).toFixed(1)+"%",document.querySelector(".perf-audio-lag").innerText=a(t)+" - "+a(n),document.querySelector(".perf-audio-deadlines").innerText=m.hit+" / "+(m.hit+m.miss),document.querySelector(".perf-render-deadlines").innerText=u.hit+" / "+(u.hit+u.miss)}else document.querySelector(".perf").style.display="none";vbaPerf.cyclesThisSecond.length=0,vbaPerf.deltaTimesThisSecond.length=0,vbaPerf.renderDeadlineResultsThisSecond.length=0,vbaPerf.spareAudioSamplesThisSecond.length=0,vbaPerf.audioDeadlineResultsThisSecond.length=0,window.perfTimer=setTimeout(window.doPerfCalc,1e3)},window.togglePause=function(){m&&(u=!u,document.querySelector(".ui").style.display=u?"block":"none",window.vbaUI.setPausedState(u))},window.scheduleStop=function(){m=!1}}]);