├── .gitattributes ├── static ├── image │ ├── bg.jpeg │ ├── icon.png │ ├── nes1.png │ ├── nes2.png │ ├── nes3.png │ ├── nes4.png │ ├── nes5.png │ └── fileicon.png ├── config.js ├── main.js ├── OnEvent.js ├── nes-embed.js ├── page.html ├── jquery.min.js └── jsnes.min.js ├── tmp ├── Screenshot_20200920_012131_org.mozilla.firefox.jpg └── key.html ├── app.php ├── README.md └── package.json /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /static/image/bg.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cngege/KodNES/HEAD/static/image/bg.jpeg -------------------------------------------------------------------------------- /static/image/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cngege/KodNES/HEAD/static/image/icon.png -------------------------------------------------------------------------------- /static/image/nes1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cngege/KodNES/HEAD/static/image/nes1.png -------------------------------------------------------------------------------- /static/image/nes2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cngege/KodNES/HEAD/static/image/nes2.png -------------------------------------------------------------------------------- /static/image/nes3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cngege/KodNES/HEAD/static/image/nes3.png -------------------------------------------------------------------------------- /static/image/nes4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cngege/KodNES/HEAD/static/image/nes4.png -------------------------------------------------------------------------------- /static/image/nes5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cngege/KodNES/HEAD/static/image/nes5.png -------------------------------------------------------------------------------- /static/image/fileicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cngege/KodNES/HEAD/static/image/fileicon.png -------------------------------------------------------------------------------- /tmp/Screenshot_20200920_012131_org.mozilla.firefox.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cngege/KodNES/HEAD/tmp/Screenshot_20200920_012131_org.mozilla.firefox.jpg -------------------------------------------------------------------------------- /static/config.js: -------------------------------------------------------------------------------- 1 | let KB = {//默认按键设置 会被管理员插件配置参数覆盖 2 | "P1":{ 3 | UP:87,//W 4 | DOWN:83,//S 5 | LEFT:65,//A 6 | RIGHT:68,//D 7 | SELECT:86,//V 8 | START:66,//B 9 | B:74,//J 10 | A:75,//K 11 | BB:85,//U 12 | AA:73,//I 13 | }, 14 | "P2":{ 15 | UP:38,//up 16 | DOWN:40,//S 17 | LEFT:37,//A 18 | RIGHT:39,//D 19 | SELECT:96,//V 20 | START:110,//B 21 | B:98,//J 22 | A:99,//K 23 | BB:101,//U 24 | AA:102,//I 25 | } 26 | } 27 | 28 | let P1Down_AA,P1Down_BB,P2Down_AA,P2Down_BB; -------------------------------------------------------------------------------- /app.php: -------------------------------------------------------------------------------- 1 | hookRegist(array( 9 | 'user.commonJs.insert' => 'KodNESPlugin.echoJs', 10 | )); 11 | } 12 | public function echoJs() { 13 | $this->echoFile('static/main.js'); //通过文件输出;支持模板变量 14 | // $this->echoFile('static/config.js'); //通过文件输出;支持模板变量 15 | } 16 | public function index() { 17 | $key=$this->getconfig(); 18 | include($this->pluginPath.'static/page.html'); 19 | } 20 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # KodNES 2 | KodBox插件:在可道云KodBox上在线玩库中的NES游戏 3 | 4 | 插件使用https://github.com/bfirsh/jsnes 开源代码,支持在浏览器运行NES游戏 5 | 请在KodBox中将此插件文件夹导入到KodBox根目录下的plugins文件夹。 6 | 7 | 在KodBox插件管理页面,启用插件(如果没有显示插件,请按Ctrl+F5刷新页面) 8 | ![此处输入图片的描述][1] 9 | 10 | 启用插件后,进入到KodBox文件管理页面,双击后缀为.nes的文件开始游玩 11 | 默认支持双人游戏(键盘控制) 12 | 13 | 默认键位: 14 | --- 15 | 键位修改请在Kodbox 配置插件-插件菜单中修改 16 | 17 | | 手柄键 | 玩家1 | 玩家2 | 18 | | ---- | ---- | ---- | 19 | | 上 | W | 方向键UP | 20 | | 下 | S | 方向键DOWN | 21 | | 左 | A | 方向键LEFT | 22 | | 右 | D | 方向键RIGHT | 23 | | SELECT | V | 0 | 24 | | START | B | . | 25 | | A | K | 3 | 26 | | B | J | 2 | 27 | | 连发A | I | 6 | 28 | | 连发B | U | 5 | 29 | 30 | ![此处输入图片的描述][2] 31 | 32 | (将)支持直接在插件安装面板修改游戏按键映射 33 | ![此处输入图片的描述][3] 34 | 35 | 移动设备支持 36 | -------- 37 | 38 | 1.6版本开始支持移动设备上触摸操作 39 | ![移动设备支持][4] 40 | 41 | 42 | [1]: https://s1.ax1x.com/2020/08/27/d4eSjH.png 43 | [2]: https://raw.githubusercontent.com/cngege/KodNES/master/static/image/nes1.png 44 | [3]: https://raw.githubusercontent.com/cngege/KodNES/master/static/image/nes4.png 45 | [4]: https://raw.githubusercontent.com/cngege/KodNES/master/static/image/nes5.png 46 | -------------------------------------------------------------------------------- /static/main.js: -------------------------------------------------------------------------------- 1 | //var nesromurl=""; 2 | kodReady.push(function(){ 3 | Events.bind('explorer.kodApp.before',function(appList){ 4 | appList.push({ 5 | name:"KodNES", 6 | title:LNG['admin.plugin.defaultKodNES'], 7 | icon:'{{pluginHost}}static/image/icon.png', 8 | ext:"{{config.fileExt}}", 9 | sort:"{{config.fileSort}}", 10 | callback:function(path,ext,name){ 11 | //var url = '{{pluginHost}}static/page.html?nes='+core.path2url(path,true); 12 | var url = '{{pluginApi}}&nespath='+window.btoa(core.path2url(path,true)); 13 | //console.log("KodNES:"+encodeURI(url)); 14 | if('window' == "{{config.openWith}}" && !core.isFileView()){ 15 | window.open(url); 16 | }else{ 17 | 18 | core.openDialog(url,core.icon('{{pluginHost}}static/image/icon.png'),"KodNES:"+name); 19 | //core.openDialog('{{pluginHost}}static/page.php?nes='+encodeURI(url),core.icon('{{pluginHost}}static/icons.png'),name); 20 | } 21 | }, 22 | }); 23 | }); 24 | if(!$.hasKey('plugin.KodNES.style')){ //只有首次处理,避免重复调用 25 | $.addStyle( 26 | ".x-item-icon.x-nes,.x-item-icon.x-NES,.x-item-icon.x-Nes{\ 27 | background-image:url('{{pluginHost}}static/image/fileicon.png');\ 28 | }"); 29 | } 30 | }); 31 | -------------------------------------------------------------------------------- /tmp/key.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 29 | KEY检测: 30 | 0 31 | 41 |
42 |
43 | -------------------------------------------------------------------------------- /static/OnEvent.js: -------------------------------------------------------------------------------- 1 | //跳转到GITHUB 2 | $(".github").click(function(){ 3 | window.open("https://github.com/cngege/KodNES.git"); 4 | }) 5 | 6 | //重新开始 7 | $(".restart").click(function(){ 8 | nes.reloadROM(); 9 | }) 10 | 11 | 12 | //处理全屏信息 13 | $(".fullS").click(function(e){ 14 | fullS(e); 15 | }) 16 | 17 | //去像素化 默认最开始就是像素化 画面较为清晰 18 | $(".UnPixel").click(function(e){ 19 | if(localStorage.getItem("KodNES_Unpixel") == "1"){ 20 | localStorage.setItem("KodNES_Unpixel","0"); 21 | $(".gameCanvas").css("image-rendering","optimizespeed"); 22 | $(".UnPixel path").attr("fill","#fbc531"); 23 | $(this).parent().attr("title","去像素化") 24 | }else{ 25 | $(".gameCanvas").css("image-rendering","auto"); 26 | localStorage.setItem("KodNES_Unpixel","1"); 27 | $(".UnPixel path").attr("fill","#1296db"); 28 | $(this).parent().attr("title","像素化") 29 | } 30 | }) 31 | 32 | function fullS(e){ 33 | // 设置全屏 34 | var element = document.documentElement; // 返回 html dom 中的root 节点 35 | var isFullscreen = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen; 36 | if(!isFullscreen) { 37 | // 判断浏览器设备类型 38 | if(element.requestFullscreen) { 39 | element.requestFullscreen(); 40 | } else if (element.mozRequestFullScreen){ // 兼容火狐 41 | element.mozRequestFullScreen(); 42 | } else if(element.webkitRequestFullscreen) { // 兼容谷歌 43 | element.webkitRequestFullscreen(); 44 | } else if (element.msRequestFullscreen) { // 兼容IE 45 | element.msRequestFullscreen(); 46 | } 47 | } else { // 退出全屏 48 | //console.log(document); 49 | // 退出全屏 50 | if(document.exitFullscreen) { 51 | document.exitFullscreen(); 52 | } else if (document.mozCancelFullScreen) { 53 | document.mozCancelFullScreen(); 54 | } else if (document.webkitCancelFullScreen) { 55 | document.webkitCancelFullScreen(); 56 | } else if (document.msExitFullscreen) { 57 | document.msExitFullscreen(); 58 | } 59 | } 60 | } 61 | 62 | 63 | //固定导航按钮 64 | $(".fixed").click(function(e){ 65 | if($(".btns").hasClass("btnfixed")){ 66 | $(".btns").removeClass("btnfixed"); 67 | }else{ 68 | $(".btns").addClass("btnfixed"); 69 | } 70 | }) 71 | 72 | //触摸按键 监听 73 | //Down 74 | $('.BTNL .U').on('touchstart',function(){ 75 |   keyboard(nes.buttonDown, {keyCode:KB.P1.UP},"D"); 76 | }); 77 | $('.BTNL .D').on('touchstart',function(){ 78 |   keyboard(nes.buttonDown, {keyCode:KB.P1.DOWN},"D"); 79 | }); 80 | $('.BTNL .L').on('touchstart',function(){ 81 |   keyboard(nes.buttonDown, {keyCode:KB.P1.LEFT},"D"); 82 | }); 83 | $('.BTNL .R').on('touchstart',function(){ 84 |   keyboard(nes.buttonDown, {keyCode:KB.P1.RIGHT},"D"); 85 | }); 86 | $('.BTNL .SE').on('touchstart',function(){ 87 |   keyboard(nes.buttonDown, {keyCode:KB.P1.SELECT},"D"); 88 | }); 89 | 90 | $('.BTNR .A').on('touchstart',function(){ 91 |   keyboard(nes.buttonDown, {keyCode:KB.P1.A},"D"); 92 | }); 93 | $('.BTNR .B').on('touchstart',function(){ 94 |   keyboard(nes.buttonDown, {keyCode:KB.P1.B},"D"); 95 | }); 96 | $('.BTNR .X').on('touchstart',function(){ 97 |   keyboard(nes.buttonDown, {keyCode:KB.P1.AA,preventDefault:()=>{}},"D"); 98 | }); 99 | $('.BTNR .Y').on('touchstart',function(){ 100 |   keyboard(nes.buttonDown, {keyCode:KB.P1.BB,preventDefault:()=>{}},"D"); 101 | }); 102 | $('.BTNR .AB').on('touchstart',function(){ 103 |   ABDown(1); 104 | }); 105 | $('.BTNR .ST').on('touchstart',function(){ 106 |   keyboard(nes.buttonDown, {keyCode:KB.P1.START},"D"); 107 | }); 108 | 109 | //UP 110 | $('.BTNL .U').on('touchend',function(){ 111 |   keyboard(nes.buttonUp, {keyCode:KB.P1.UP},"U"); 112 | }); 113 | $('.BTNL .D').on('touchend',function(){ 114 |   keyboard(nes.buttonUp, {keyCode:KB.P1.DOWN},"U"); 115 | }); 116 | $('.BTNL .L').on('touchend',function(){ 117 |   keyboard(nes.buttonUp, {keyCode:KB.P1.LEFT},"U"); 118 | }); 119 | $('.BTNL .R').on('touchend',function(){ 120 |   keyboard(nes.buttonUp, {keyCode:KB.P1.RIGHT},"U"); 121 | }); 122 | $('.BTNL .SE').on('touchend',function(){ 123 |   keyboard(nes.buttonUp, {keyCode:KB.P1.SELECT},"U"); 124 | }); 125 | 126 | $('.BTNR .A').on('touchend',function(){ 127 |   keyboard(nes.buttonUp, {keyCode:KB.P1.A},"U"); 128 | }); 129 | $('.BTNR .B').on('touchend',function(){ 130 |   keyboard(nes.buttonUp, {keyCode:KB.P1.B},"U"); 131 | }); 132 | $('.BTNR .X').on('touchend',function(){ 133 |   keyboard(nes.buttonUp, {keyCode:KB.P1.AA,preventDefault:()=>{}},"U"); 134 | }); 135 | $('.BTNR .Y').on('touchend',function(){ 136 |   keyboard(nes.buttonUp, {keyCode:KB.P1.BB,preventDefault:()=>{}},"U"); 137 | }); 138 | $('.BTNR .AB').on('touchend',function(){ 139 |   ABUp(1); 140 | }); 141 | $('.BTNR .ST').on('touchend',function(){ 142 |   keyboard(nes.buttonUp, {keyCode:KB.P1.START},"U"); 143 | }); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "id":"KodNES", 3 | "name":"NES Emulator", 4 | "title":"NES模拟器", 5 | "version":"1.8", 6 | "source":{ 7 | "icon":"{{pluginHost}}static/image/icon.png", 8 | "screenshoot":[ 9 | "{{pluginHost}}static/image/nes1.png", 10 | "{{pluginHost}}static/image/nes2.png", 11 | "{{pluginHost}}static/image/nes3.png", 12 | "{{pluginHost}}static/image/nes4.png", 13 | "{{pluginHost}}static/image/nes5.png" 14 | ] 15 | }, 16 | "category":"media,file", 17 | "description":"NES Rom文件支持系统模拟器、FC模拟器", 18 | "keywords":"nes,fc,模拟器,游戏", 19 | "auther":{ 20 | "copyright":"CNGEGE", 21 | "homePage":"https://cngege.github.io/" 22 | }, 23 | "configItem":{ 24 | "formStyle": { 25 | "className": "form-box-title-left", 26 | "tabs": { 27 | "取键盘键值":"KeySelect", 28 | "P1按键映射": "P1Title,P1Up,P1Down,P1Left,P1Right,P1Select,P1Start,P1A,P1B,P1AA,P1BB", 29 | "P2按键映射": "P2Title,P2Up,P2Down,P2Left,P2Right,P2Select,P2Start,P2A,P2B,P2AA,P2BB" 30 | } 31 | }, 32 | "PluginTitle":{"type":"html","display":"

插件设置

"}, 33 | "pluginAuth":{ 34 | "type":"userSelect", 35 | "value":{"all":1}, 36 | "display":"{{LNG['admin.plugin.auth']}}", 37 | "desc":"{{LNG['admin.plugin.authDesc']}}", 38 | "require":1 39 | }, 40 | "fileExt":{ 41 | "type":"tags", 42 | "display":"{{LNG['admin.plugin.fileExt']}}", 43 | "desc":"{{LNG['admin.plugin.fileExtDesc']}}", 44 | "value":"nes" 45 | }, 46 | "fileSort":{ 47 | "type":"number", 48 | "display":"{{LNG['admin.plugin.fileSort']}}", 49 | "desc":"{{LNG['admin.plugin.fileSortDesc']}}", 50 | "value":10 51 | }, 52 | "KeySelect":{ 53 | "type":"html", 54 | "display":"
KEY检测: 0
" 55 | }, 56 | "P1Title":{"type":"html","display":"

Player1

"}, 57 | "P1Up":{ 58 | "type":"number", 59 | "value":87, 60 | "display":"方向键:上", 61 | "desc":"整数型键值", 62 | "require":1 63 | }, 64 | "P1Down":{ 65 | "type":"number", 66 | "value":83, 67 | "display":"方向键:下", 68 | "desc":"整数型键值", 69 | "require":1 70 | }, 71 | "P1Left":{ 72 | "type":"number", 73 | "value":65, 74 | "display":"方向键:左", 75 | "desc":"整数型键值", 76 | "require":1 77 | }, 78 | "P1Right":{ 79 | "type":"number", 80 | "value":68, 81 | "display":"方向键:右", 82 | "desc":"整数型键值", 83 | "require":1 84 | }, 85 | "P1Select":{ 86 | "type":"number", 87 | "value":86, 88 | "display":"功能键:Select", 89 | "desc":"整数型键值", 90 | "require":1 91 | }, 92 | "P1Start":{ 93 | "type":"number", 94 | "value":66, 95 | "display":"功能键:Start", 96 | "desc":"整数型键值", 97 | "require":1 98 | }, 99 | "P1A":{ 100 | "type":"number", 101 | "value":75, 102 | "display":"功能键:A", 103 | "desc":"整数型键值", 104 | "require":1 105 | }, 106 | "P1B":{ 107 | "type":"number", 108 | "value":74, 109 | "display":"功能键:B", 110 | "desc":"整数型键值", 111 | "require":1 112 | }, 113 | "P1AA":{ 114 | "type":"number", 115 | "value":73, 116 | "display":"功能键:连A", 117 | "desc":"整数型键值", 118 | "require":1 119 | }, 120 | "P1BB":{ 121 | "type":"number", 122 | "value":85, 123 | "display":"功能键:连B", 124 | "desc":"整数型键值", 125 | "require":1 126 | }, 127 | "P2Title":{"type":"html","display":"

Player2

"}, 128 | "P2Up":{ 129 | "type":"number", 130 | "value":38, 131 | "display":"方向键:上", 132 | "desc":"整数型键值", 133 | "require":1 134 | }, 135 | "P2Down":{ 136 | "type":"number", 137 | "value":40, 138 | "display":"方向键:下", 139 | "desc":"整数型键值", 140 | "require":1 141 | }, 142 | "P2Left":{ 143 | "type":"number", 144 | "value":37, 145 | "display":"方向键:左", 146 | "desc":"整数型键值", 147 | "require":1 148 | }, 149 | "P2Right":{ 150 | "type":"number", 151 | "value":39, 152 | "display":"方向键:右", 153 | "desc":"整数型键值", 154 | "require":1 155 | }, 156 | "P2Select":{ 157 | "type":"number", 158 | "value":96, 159 | "display":"功能键:Select", 160 | "desc":"整数型键值", 161 | "require":1 162 | }, 163 | "P2Start":{ 164 | "type":"number", 165 | "value":110, 166 | "display":"功能键:Start", 167 | "desc":"整数型键值", 168 | "require":1 169 | }, 170 | "P2A":{ 171 | "type":"number", 172 | "value":99, 173 | "display":"功能键:A", 174 | "desc":"整数型键值", 175 | "require":1 176 | }, 177 | "P2B":{ 178 | "type":"number", 179 | "value":98, 180 | "display":"功能键:B", 181 | "desc":"整数型键值", 182 | "require":1 183 | }, 184 | "P2AA":{ 185 | "type":"number", 186 | "value":102, 187 | "display":"功能键:连A", 188 | "desc":"整数型键值", 189 | "require":1 190 | }, 191 | "P2BB":{ 192 | "type":"number", 193 | "value":101, 194 | "display":"功能键:连B", 195 | "desc":"整数型键值", 196 | "require":1 197 | } 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /static/nes-embed.js: -------------------------------------------------------------------------------- 1 | var SCREEN_WIDTH = 256; //宽像素 2 | var SCREEN_HEIGHT = 240; //高像素 3 | var FRAMEBUFFER_SIZE = SCREEN_WIDTH*SCREEN_HEIGHT; 4 | 5 | var canvas_ctx, image; 6 | var framebuffer_u8, framebuffer_u32; 7 | 8 | var AUDIO_BUFFERING = 512; 9 | var SAMPLE_COUNT = 4*1024; 10 | var SAMPLE_MASK = SAMPLE_COUNT - 1; 11 | var audio_samples_L = new Float32Array(SAMPLE_COUNT); 12 | var audio_samples_R = new Float32Array(SAMPLE_COUNT); 13 | var audio_write_cursor = 0, audio_read_cursor = 0; 14 | 15 | var netload = 0; 16 | 17 | var nes = new jsnes.NES({ 18 | onFrame: function(framebuffer_24){ 19 | for(var i = 0; i < FRAMEBUFFER_SIZE; i++) framebuffer_u32[i] = 0xFF000000 | framebuffer_24[i]; 20 | }, 21 | onAudioSample: function(l, r){ 22 | audio_samples_L[audio_write_cursor] = l; 23 | audio_samples_R[audio_write_cursor] = r; 24 | audio_write_cursor = (audio_write_cursor + 1) & SAMPLE_MASK; 25 | }, 26 | }); 27 | 28 | // requestAnimationFrame 让浏览器下次渲染页面的时候(60fps),调用回调函数,使用递归达到每次每一帧调用一次 29 | function onAnimationFrame(){ 30 | window.requestAnimationFrame(onAnimationFrame); 31 | 32 | image.data.set(framebuffer_u8); 33 | canvas_ctx.putImageData(image, 0, 0); 34 | } 35 | 36 | function audio_remain(){ 37 | return (audio_write_cursor - audio_read_cursor) & SAMPLE_MASK; 38 | } 39 | 40 | function audio_callback(event){ 41 | var dst = event.outputBuffer; 42 | var len = dst.length; 43 | 44 | // Attempt to avoid buffer underruns. 45 | if(audio_remain() < AUDIO_BUFFERING && netload == 200) nes.frame(); 46 | 47 | var dst_l = dst.getChannelData(0); 48 | var dst_r = dst.getChannelData(1); 49 | for(var i = 0; i < len; i++){ 50 | var src_idx = (audio_read_cursor + i) & SAMPLE_MASK; 51 | dst_l[i] = audio_samples_L[src_idx]; 52 | dst_r[i] = audio_samples_R[src_idx]; 53 | } 54 | 55 | audio_read_cursor = (audio_read_cursor + len) & SAMPLE_MASK; 56 | } 57 | 58 | function keyboard(callback, event,UD){ 59 | var player1 = 1; 60 | var player2 = 2; 61 | switch(event.keyCode){ 62 | case KB.P1.UP://W 63 | callback(player1, jsnes.Controller.BUTTON_UP); break; 64 | case KB.P1.DOWN://S 65 | callback(player1, jsnes.Controller.BUTTON_DOWN); break; 66 | case KB.P1.LEFT://A 67 | callback(player1, jsnes.Controller.BUTTON_LEFT); break; 68 | case KB.P1.RIGHT://D 69 | callback(player1, jsnes.Controller.BUTTON_RIGHT); break; 70 | case KB.P1.SELECT://V 71 | callback(player1, jsnes.Controller.BUTTON_SELECT); break; 72 | case KB.P1.START://B 73 | callback(player1, jsnes.Controller.BUTTON_START); break; 74 | case KB.P1.B://J 75 | callback(player1, jsnes.Controller.BUTTON_B); break; 76 | case KB.P1.A://K 77 | callback(player1, jsnes.Controller.BUTTON_A); break; 78 | case KB.P1.BB://U 79 | event.preventDefault(); 80 | if(UD=="D"){ //按下 81 | P1Down_BB = true; 82 | ClickP1B(); 83 | }else{ 84 | P1Down_BB = false; 85 | } 86 | break; 87 | case KB.P1.AA://I 88 | event.preventDefault(); 89 | if(UD=="D"){ //按下 90 | P1Down_AA = true; 91 | ClickP1A(); 92 | }else{ 93 | P1Down_AA = false; 94 | } 95 | break; 96 | 97 | //player2 键位 98 | case KB.P2.UP://W 99 | callback(player2, jsnes.Controller.BUTTON_UP); break; 100 | case KB.P2.DOWN://S 101 | callback(player2, jsnes.Controller.BUTTON_DOWN); break; 102 | case KB.P2.LEFT://A 103 | callback(player2, jsnes.Controller.BUTTON_LEFT); break; 104 | case KB.P2.RIGHT://D 105 | callback(player2, jsnes.Controller.BUTTON_RIGHT); break; 106 | case KB.P2.SELECT://V 107 | callback(player2, jsnes.Controller.BUTTON_SELECT); break; 108 | case KB.P2.START://B 109 | callback(player2, jsnes.Controller.BUTTON_START); break; 110 | case KB.P2.B://J 111 | callback(player2, jsnes.Controller.BUTTON_B); break; 112 | case KB.P2.A://K 113 | callback(player2, jsnes.Controller.BUTTON_A); break; 114 | case KB.P2.BB://U 115 | event.preventDefault(); 116 | if(UD=="D"){ //按下 117 | P2Down_BB = true; 118 | ClickP2B(); 119 | }else{ 120 | P2Down_BB = false; 121 | } 122 | break; 123 | case KB.P2.AA://I 124 | event.preventDefault(); 125 | if(UD=="D"){ //按下 126 | P2Down_AA = true; 127 | ClickP2A(); 128 | }else{ 129 | P2Down_AA = false; 130 | } 131 | break; 132 | 133 | default: break; 134 | } 135 | nes.frame(); 136 | } 137 | 138 | function ABDown(player){ 139 | nes.buttonDown(player,jsnes.Controller.BUTTON_A); 140 | nes.buttonDown(player,jsnes.Controller.BUTTON_B); 141 | } 142 | 143 | function ABUp(player){ 144 | nes.buttonUp(player,jsnes.Controller.BUTTON_A); 145 | nes.buttonUp(player,jsnes.Controller.BUTTON_B); 146 | } 147 | 148 | 149 | //Player1 150 | function ClickP1B(){ 151 | if(P1Down_BB){ 152 | nes.buttonDown(1,jsnes.Controller.BUTTON_B);//按下B键 153 | setTimeout(function(){ 154 | nes.buttonUp(1,jsnes.Controller.BUTTON_B);//放开B键 155 | setTimeout(function(){ 156 | if(!P1Down_BB)return; 157 | ClickP1B(); 158 | },50); 159 | },50) 160 | } 161 | } 162 | 163 | function ClickP1A(){ 164 | if(P1Down_AA){ 165 | nes.buttonDown(1,jsnes.Controller.BUTTON_A);//按下B键 166 | setTimeout(function(){ 167 | nes.buttonUp(1,jsnes.Controller.BUTTON_A);//放开B键 168 | setTimeout(function(){ 169 | if(!P1Down_AA)return; 170 | ClickP1A(); 171 | },50); 172 | },50) 173 | } 174 | } 175 | 176 | //Player2 177 | function ClickP2B(){ 178 | if(P2Down_BB){ 179 | nes.buttonDown(2,jsnes.Controller.BUTTON_B);//按下B键 180 | setTimeout(function(){ 181 | nes.buttonUp(2,jsnes.Controller.BUTTON_B);//放开B键 182 | setTimeout(function(){ 183 | if(!P2Down_BB)return; 184 | ClickP2B(); 185 | },33); 186 | },33) 187 | } 188 | } 189 | 190 | function ClickP2A(){ 191 | if(P2Down_AA){ 192 | nes.buttonDown(2,jsnes.Controller.BUTTON_A);//按下B键 193 | setTimeout(function(){ 194 | nes.buttonUp(2,jsnes.Controller.BUTTON_A);//放开B键 195 | setTimeout(function(){ 196 | if(!P2Down_AA)return; 197 | ClickP2A(); 198 | },33); 199 | },33) 200 | } 201 | } 202 | 203 | 204 | function nes_init(canvas_id){ 205 | var canvas = document.getElementById(canvas_id); 206 | canvas_ctx = canvas.getContext("2d"); 207 | image = canvas_ctx.getImageData(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); 208 | 209 | canvas_ctx.fillStyle = "black"; 210 | canvas_ctx.fillRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); 211 | 212 | // Allocate framebuffer array. 213 | var buffer = new ArrayBuffer(image.data.length); 214 | framebuffer_u8 = new Uint8ClampedArray(buffer); 215 | framebuffer_u32 = new Uint32Array(buffer); 216 | 217 | // Setup audio. 218 | //var audio_ctx = new window.AudioContext(); 219 | var contextClass =(window.AudioContext || window.webkitAudioContext || window.mozAudioContext || window.oAudioContext || window.msAudioContext); 220 | var audio_ctx = new contextClass(); 221 | var script_processor = audio_ctx.createScriptProcessor(AUDIO_BUFFERING, 0, 2); 222 | script_processor.onaudioprocess = audio_callback; 223 | script_processor.connect(audio_ctx.destination); 224 | } 225 | 226 | function nes_boot(rom_data){ 227 | nes.loadROM(rom_data); 228 | window.requestAnimationFrame(onAnimationFrame); 229 | } 230 | 231 | function nes_load_data(canvas_id, rom_data){ 232 | nes_init(canvas_id); 233 | nes_boot(rom_data); 234 | nes.ppu.clipToTvSize=false; //去除画布周边黑框 235 | } 236 | 237 | function nes_load_url(canvas_id, path){ 238 | nes_init(canvas_id); 239 | nes.ppu.clipToTvSize=false; //去除画布周边黑框 240 | var req = new XMLHttpRequest(); 241 | req.open("GET", path); 242 | req.overrideMimeType("text/plain; charset=x-user-defined"); 243 | req.onerror = () => console.log(`Error loading ${path}: ${req.statusText}`); 244 | req.onload = function() { 245 | netload = this.status; 246 | if (this.status === 200) { 247 | nes_boot(this.responseText); 248 | // nes.loopfps = setInterval(function(){ 249 | // if(this.mmap) 250 | // nes.frame(); 251 | // },16) 252 | } else if (this.status === 0) { 253 | // Aborted, so ignore error 254 | } else { 255 | req.onerror(); 256 | } 257 | }; 258 | 259 | req.send(); 260 | } 261 | 262 | document.addEventListener('keydown', (event) => {keyboard(nes.buttonDown, event,"D")}); 263 | document.addEventListener('keyup', (event) => {keyboard(nes.buttonUp, event,"U")}); 264 | 265 | 266 | -------------------------------------------------------------------------------- /static/page.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | KodNES 6 | 7 | 126 | link('static/jquery.min.js');?> 127 | link('static/jsnes/jsnes.js');?> 128 | link('static/config.js');?> 129 | 156 | link('static/nes-embed.js');?> 157 | 208 | 209 | 210 | 211 |
212 | SE 213 | 214 | U 215 | D 216 | L 217 | R 218 |
219 | 220 |
221 |
222 | GitHub stars 223 | 224 | 225 | 226 | 227 | 228 | 229 |
230 | 231 |
232 | 233 |
234 | ST 235 | AB 236 | 237 | A 238 | B 239 | X 240 | Y 241 |
242 | link('static/OnEvent.js');?> 243 | 244 | 245 | -------------------------------------------------------------------------------- /static/jquery.min.js: -------------------------------------------------------------------------------- 1 | /*! jQuery v3.5.1 | (c) JS Foundation and other contributors | jquery.org/license */ 2 | !function(e,t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(C,e){"use strict";var t=[],r=Object.getPrototypeOf,s=t.slice,g=t.flat?function(e){return t.flat.call(e)}:function(e){return t.concat.apply([],e)},u=t.push,i=t.indexOf,n={},o=n.toString,v=n.hasOwnProperty,a=v.toString,l=a.call(Object),y={},m=function(e){return"function"==typeof e&&"number"!=typeof e.nodeType},x=function(e){return null!=e&&e===e.window},E=C.document,c={type:!0,src:!0,nonce:!0,noModule:!0};function b(e,t,n){var r,i,o=(n=n||E).createElement("script");if(o.text=e,t)for(r in c)(i=t[r]||t.getAttribute&&t.getAttribute(r))&&o.setAttribute(r,i);n.head.appendChild(o).parentNode.removeChild(o)}function w(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?n[o.call(e)]||"object":typeof e}var f="3.5.1",S=function(e,t){return new S.fn.init(e,t)};function p(e){var t=!!e&&"length"in e&&e.length,n=w(e);return!m(e)&&!x(e)&&("array"===n||0===t||"number"==typeof t&&0+~]|"+M+")"+M+"*"),U=new RegExp(M+"|>"),X=new RegExp(F),V=new RegExp("^"+I+"$"),G={ID:new RegExp("^#("+I+")"),CLASS:new RegExp("^\\.("+I+")"),TAG:new RegExp("^("+I+"|[*])"),ATTR:new RegExp("^"+W),PSEUDO:new RegExp("^"+F),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:new RegExp("^(?:"+R+")$","i"),needsContext:new RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},Y=/HTML$/i,Q=/^(?:input|select|textarea|button)$/i,J=/^h\d$/i,K=/^[^{]+\{\s*\[native \w/,Z=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,ee=/[+~]/,te=new RegExp("\\\\[\\da-fA-F]{1,6}"+M+"?|\\\\([^\\r\\n\\f])","g"),ne=function(e,t){var n="0x"+e.slice(1)-65536;return t||(n<0?String.fromCharCode(n+65536):String.fromCharCode(n>>10|55296,1023&n|56320))},re=/([\0-\x1f\x7f]|^-?\d)|^-$|[^\0-\x1f\x7f-\uFFFF\w-]/g,ie=function(e,t){return t?"\0"===e?"\ufffd":e.slice(0,-1)+"\\"+e.charCodeAt(e.length-1).toString(16)+" ":"\\"+e},oe=function(){T()},ae=be(function(e){return!0===e.disabled&&"fieldset"===e.nodeName.toLowerCase()},{dir:"parentNode",next:"legend"});try{H.apply(t=O.call(p.childNodes),p.childNodes),t[p.childNodes.length].nodeType}catch(e){H={apply:t.length?function(e,t){L.apply(e,O.call(t))}:function(e,t){var n=e.length,r=0;while(e[n++]=t[r++]);e.length=n-1}}}function se(t,e,n,r){var i,o,a,s,u,l,c,f=e&&e.ownerDocument,p=e?e.nodeType:9;if(n=n||[],"string"!=typeof t||!t||1!==p&&9!==p&&11!==p)return n;if(!r&&(T(e),e=e||C,E)){if(11!==p&&(u=Z.exec(t)))if(i=u[1]){if(9===p){if(!(a=e.getElementById(i)))return n;if(a.id===i)return n.push(a),n}else if(f&&(a=f.getElementById(i))&&y(e,a)&&a.id===i)return n.push(a),n}else{if(u[2])return H.apply(n,e.getElementsByTagName(t)),n;if((i=u[3])&&d.getElementsByClassName&&e.getElementsByClassName)return H.apply(n,e.getElementsByClassName(i)),n}if(d.qsa&&!N[t+" "]&&(!v||!v.test(t))&&(1!==p||"object"!==e.nodeName.toLowerCase())){if(c=t,f=e,1===p&&(U.test(t)||z.test(t))){(f=ee.test(t)&&ye(e.parentNode)||e)===e&&d.scope||((s=e.getAttribute("id"))?s=s.replace(re,ie):e.setAttribute("id",s=S)),o=(l=h(t)).length;while(o--)l[o]=(s?"#"+s:":scope")+" "+xe(l[o]);c=l.join(",")}try{return H.apply(n,f.querySelectorAll(c)),n}catch(e){N(t,!0)}finally{s===S&&e.removeAttribute("id")}}}return g(t.replace($,"$1"),e,n,r)}function ue(){var r=[];return function e(t,n){return r.push(t+" ")>b.cacheLength&&delete e[r.shift()],e[t+" "]=n}}function le(e){return e[S]=!0,e}function ce(e){var t=C.createElement("fieldset");try{return!!e(t)}catch(e){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function fe(e,t){var n=e.split("|"),r=n.length;while(r--)b.attrHandle[n[r]]=t}function pe(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&e.sourceIndex-t.sourceIndex;if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function de(t){return function(e){return"input"===e.nodeName.toLowerCase()&&e.type===t}}function he(n){return function(e){var t=e.nodeName.toLowerCase();return("input"===t||"button"===t)&&e.type===n}}function ge(t){return function(e){return"form"in e?e.parentNode&&!1===e.disabled?"label"in e?"label"in e.parentNode?e.parentNode.disabled===t:e.disabled===t:e.isDisabled===t||e.isDisabled!==!t&&ae(e)===t:e.disabled===t:"label"in e&&e.disabled===t}}function ve(a){return le(function(o){return o=+o,le(function(e,t){var n,r=a([],e.length,o),i=r.length;while(i--)e[n=r[i]]&&(e[n]=!(t[n]=e[n]))})})}function ye(e){return e&&"undefined"!=typeof e.getElementsByTagName&&e}for(e in d=se.support={},i=se.isXML=function(e){var t=e.namespaceURI,n=(e.ownerDocument||e).documentElement;return!Y.test(t||n&&n.nodeName||"HTML")},T=se.setDocument=function(e){var t,n,r=e?e.ownerDocument||e:p;return r!=C&&9===r.nodeType&&r.documentElement&&(a=(C=r).documentElement,E=!i(C),p!=C&&(n=C.defaultView)&&n.top!==n&&(n.addEventListener?n.addEventListener("unload",oe,!1):n.attachEvent&&n.attachEvent("onunload",oe)),d.scope=ce(function(e){return a.appendChild(e).appendChild(C.createElement("div")),"undefined"!=typeof e.querySelectorAll&&!e.querySelectorAll(":scope fieldset div").length}),d.attributes=ce(function(e){return e.className="i",!e.getAttribute("className")}),d.getElementsByTagName=ce(function(e){return e.appendChild(C.createComment("")),!e.getElementsByTagName("*").length}),d.getElementsByClassName=K.test(C.getElementsByClassName),d.getById=ce(function(e){return a.appendChild(e).id=S,!C.getElementsByName||!C.getElementsByName(S).length}),d.getById?(b.filter.ID=function(e){var t=e.replace(te,ne);return function(e){return e.getAttribute("id")===t}},b.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&E){var n=t.getElementById(e);return n?[n]:[]}}):(b.filter.ID=function(e){var n=e.replace(te,ne);return function(e){var t="undefined"!=typeof e.getAttributeNode&&e.getAttributeNode("id");return t&&t.value===n}},b.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&E){var n,r,i,o=t.getElementById(e);if(o){if((n=o.getAttributeNode("id"))&&n.value===e)return[o];i=t.getElementsByName(e),r=0;while(o=i[r++])if((n=o.getAttributeNode("id"))&&n.value===e)return[o]}return[]}}),b.find.TAG=d.getElementsByTagName?function(e,t){return"undefined"!=typeof t.getElementsByTagName?t.getElementsByTagName(e):d.qsa?t.querySelectorAll(e):void 0}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},b.find.CLASS=d.getElementsByClassName&&function(e,t){if("undefined"!=typeof t.getElementsByClassName&&E)return t.getElementsByClassName(e)},s=[],v=[],(d.qsa=K.test(C.querySelectorAll))&&(ce(function(e){var t;a.appendChild(e).innerHTML="",e.querySelectorAll("[msallowcapture^='']").length&&v.push("[*^$]="+M+"*(?:''|\"\")"),e.querySelectorAll("[selected]").length||v.push("\\["+M+"*(?:value|"+R+")"),e.querySelectorAll("[id~="+S+"-]").length||v.push("~="),(t=C.createElement("input")).setAttribute("name",""),e.appendChild(t),e.querySelectorAll("[name='']").length||v.push("\\["+M+"*name"+M+"*="+M+"*(?:''|\"\")"),e.querySelectorAll(":checked").length||v.push(":checked"),e.querySelectorAll("a#"+S+"+*").length||v.push(".#.+[+~]"),e.querySelectorAll("\\\f"),v.push("[\\r\\n\\f]")}),ce(function(e){e.innerHTML="";var t=C.createElement("input");t.setAttribute("type","hidden"),e.appendChild(t).setAttribute("name","D"),e.querySelectorAll("[name=d]").length&&v.push("name"+M+"*[*^$|!~]?="),2!==e.querySelectorAll(":enabled").length&&v.push(":enabled",":disabled"),a.appendChild(e).disabled=!0,2!==e.querySelectorAll(":disabled").length&&v.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),v.push(",.*:")})),(d.matchesSelector=K.test(c=a.matches||a.webkitMatchesSelector||a.mozMatchesSelector||a.oMatchesSelector||a.msMatchesSelector))&&ce(function(e){d.disconnectedMatch=c.call(e,"*"),c.call(e,"[s!='']:x"),s.push("!=",F)}),v=v.length&&new RegExp(v.join("|")),s=s.length&&new RegExp(s.join("|")),t=K.test(a.compareDocumentPosition),y=t||K.test(a.contains)?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},D=t?function(e,t){if(e===t)return l=!0,0;var n=!e.compareDocumentPosition-!t.compareDocumentPosition;return n||(1&(n=(e.ownerDocument||e)==(t.ownerDocument||t)?e.compareDocumentPosition(t):1)||!d.sortDetached&&t.compareDocumentPosition(e)===n?e==C||e.ownerDocument==p&&y(p,e)?-1:t==C||t.ownerDocument==p&&y(p,t)?1:u?P(u,e)-P(u,t):0:4&n?-1:1)}:function(e,t){if(e===t)return l=!0,0;var n,r=0,i=e.parentNode,o=t.parentNode,a=[e],s=[t];if(!i||!o)return e==C?-1:t==C?1:i?-1:o?1:u?P(u,e)-P(u,t):0;if(i===o)return pe(e,t);n=e;while(n=n.parentNode)a.unshift(n);n=t;while(n=n.parentNode)s.unshift(n);while(a[r]===s[r])r++;return r?pe(a[r],s[r]):a[r]==p?-1:s[r]==p?1:0}),C},se.matches=function(e,t){return se(e,null,null,t)},se.matchesSelector=function(e,t){if(T(e),d.matchesSelector&&E&&!N[t+" "]&&(!s||!s.test(t))&&(!v||!v.test(t)))try{var n=c.call(e,t);if(n||d.disconnectedMatch||e.document&&11!==e.document.nodeType)return n}catch(e){N(t,!0)}return 0":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(te,ne),e[3]=(e[3]||e[4]||e[5]||"").replace(te,ne),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||se.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&se.error(e[0]),e},PSEUDO:function(e){var t,n=!e[6]&&e[2];return G.CHILD.test(e[0])?null:(e[3]?e[2]=e[4]||e[5]||"":n&&X.test(n)&&(t=h(n,!0))&&(t=n.indexOf(")",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(te,ne).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=m[e+" "];return t||(t=new RegExp("(^|"+M+")"+e+"("+M+"|$)"))&&m(e,function(e){return t.test("string"==typeof e.className&&e.className||"undefined"!=typeof e.getAttribute&&e.getAttribute("class")||"")})},ATTR:function(n,r,i){return function(e){var t=se.attr(e,n);return null==t?"!="===r:!r||(t+="","="===r?t===i:"!="===r?t!==i:"^="===r?i&&0===t.indexOf(i):"*="===r?i&&-1:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i;function D(e,n,r){return m(n)?S.grep(e,function(e,t){return!!n.call(e,t,e)!==r}):n.nodeType?S.grep(e,function(e){return e===n!==r}):"string"!=typeof n?S.grep(e,function(e){return-1)[^>]*|#([\w-]+))$/;(S.fn.init=function(e,t,n){var r,i;if(!e)return this;if(n=n||j,"string"==typeof e){if(!(r="<"===e[0]&&">"===e[e.length-1]&&3<=e.length?[null,e,null]:q.exec(e))||!r[1]&&t)return!t||t.jquery?(t||n).find(e):this.constructor(t).find(e);if(r[1]){if(t=t instanceof S?t[0]:t,S.merge(this,S.parseHTML(r[1],t&&t.nodeType?t.ownerDocument||t:E,!0)),N.test(r[1])&&S.isPlainObject(t))for(r in t)m(this[r])?this[r](t[r]):this.attr(r,t[r]);return this}return(i=E.getElementById(r[2]))&&(this[0]=i,this.length=1),this}return e.nodeType?(this[0]=e,this.length=1,this):m(e)?void 0!==n.ready?n.ready(e):e(S):S.makeArray(e,this)}).prototype=S.fn,j=S(E);var L=/^(?:parents|prev(?:Until|All))/,H={children:!0,contents:!0,next:!0,prev:!0};function O(e,t){while((e=e[t])&&1!==e.nodeType);return e}S.fn.extend({has:function(e){var t=S(e,this),n=t.length;return this.filter(function(){for(var e=0;e\x20\t\r\n\f]*)/i,he=/^$|^module$|\/(?:java|ecma)script/i;ce=E.createDocumentFragment().appendChild(E.createElement("div")),(fe=E.createElement("input")).setAttribute("type","radio"),fe.setAttribute("checked","checked"),fe.setAttribute("name","t"),ce.appendChild(fe),y.checkClone=ce.cloneNode(!0).cloneNode(!0).lastChild.checked,ce.innerHTML="",y.noCloneChecked=!!ce.cloneNode(!0).lastChild.defaultValue,ce.innerHTML="",y.option=!!ce.lastChild;var ge={thead:[1,"","
"],col:[2,"","
"],tr:[2,"","
"],td:[3,"","
"],_default:[0,"",""]};function ve(e,t){var n;return n="undefined"!=typeof e.getElementsByTagName?e.getElementsByTagName(t||"*"):"undefined"!=typeof e.querySelectorAll?e.querySelectorAll(t||"*"):[],void 0===t||t&&A(e,t)?S.merge([e],n):n}function ye(e,t){for(var n=0,r=e.length;n",""]);var me=/<|&#?\w+;/;function xe(e,t,n,r,i){for(var o,a,s,u,l,c,f=t.createDocumentFragment(),p=[],d=0,h=e.length;d\s*$/g;function qe(e,t){return A(e,"table")&&A(11!==t.nodeType?t:t.firstChild,"tr")&&S(e).children("tbody")[0]||e}function Le(e){return e.type=(null!==e.getAttribute("type"))+"/"+e.type,e}function He(e){return"true/"===(e.type||"").slice(0,5)?e.type=e.type.slice(5):e.removeAttribute("type"),e}function Oe(e,t){var n,r,i,o,a,s;if(1===t.nodeType){if(Y.hasData(e)&&(s=Y.get(e).events))for(i in Y.remove(t,"handle events"),s)for(n=0,r=s[i].length;n").attr(n.scriptAttrs||{}).prop({charset:n.scriptCharset,src:n.url}).on("load error",i=function(e){r.remove(),i=null,e&&t("error"===e.type?404:200,e.type)}),E.head.appendChild(r[0])},abort:function(){i&&i()}}});var Ut,Xt=[],Vt=/(=)\?(?=&|$)|\?\?/;S.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var e=Xt.pop()||S.expando+"_"+Ct.guid++;return this[e]=!0,e}}),S.ajaxPrefilter("json jsonp",function(e,t,n){var r,i,o,a=!1!==e.jsonp&&(Vt.test(e.url)?"url":"string"==typeof e.data&&0===(e.contentType||"").indexOf("application/x-www-form-urlencoded")&&Vt.test(e.data)&&"data");if(a||"jsonp"===e.dataTypes[0])return r=e.jsonpCallback=m(e.jsonpCallback)?e.jsonpCallback():e.jsonpCallback,a?e[a]=e[a].replace(Vt,"$1"+r):!1!==e.jsonp&&(e.url+=(Et.test(e.url)?"&":"?")+e.jsonp+"="+r),e.converters["script json"]=function(){return o||S.error(r+" was not called"),o[0]},e.dataTypes[0]="json",i=C[r],C[r]=function(){o=arguments},n.always(function(){void 0===i?S(C).removeProp(r):C[r]=i,e[r]&&(e.jsonpCallback=t.jsonpCallback,Xt.push(r)),o&&m(i)&&i(o[0]),o=i=void 0}),"script"}),y.createHTMLDocument=((Ut=E.implementation.createHTMLDocument("").body).innerHTML="
",2===Ut.childNodes.length),S.parseHTML=function(e,t,n){return"string"!=typeof e?[]:("boolean"==typeof t&&(n=t,t=!1),t||(y.createHTMLDocument?((r=(t=E.implementation.createHTMLDocument("")).createElement("base")).href=E.location.href,t.head.appendChild(r)):t=E),o=!n&&[],(i=N.exec(e))?[t.createElement(i[1])]:(i=xe([e],t,o),o&&o.length&&S(o).remove(),S.merge([],i.childNodes)));var r,i,o},S.fn.load=function(e,t,n){var r,i,o,a=this,s=e.indexOf(" ");return-1").append(S.parseHTML(e)).find(r):e)}).always(n&&function(e,t){a.each(function(){n.apply(this,o||[e.responseText,t,e])})}),this},S.expr.pseudos.animated=function(t){return S.grep(S.timers,function(e){return t===e.elem}).length},S.offset={setOffset:function(e,t,n){var r,i,o,a,s,u,l=S.css(e,"position"),c=S(e),f={};"static"===l&&(e.style.position="relative"),s=c.offset(),o=S.css(e,"top"),u=S.css(e,"left"),("absolute"===l||"fixed"===l)&&-1<(o+u).indexOf("auto")?(a=(r=c.position()).top,i=r.left):(a=parseFloat(o)||0,i=parseFloat(u)||0),m(t)&&(t=t.call(e,n,S.extend({},s))),null!=t.top&&(f.top=t.top-s.top+a),null!=t.left&&(f.left=t.left-s.left+i),"using"in t?t.using.call(e,f):("number"==typeof f.top&&(f.top+="px"),"number"==typeof f.left&&(f.left+="px"),c.css(f))}},S.fn.extend({offset:function(t){if(arguments.length)return void 0===t?this:this.each(function(e){S.offset.setOffset(this,t,e)});var e,n,r=this[0];return r?r.getClientRects().length?(e=r.getBoundingClientRect(),n=r.ownerDocument.defaultView,{top:e.top+n.pageYOffset,left:e.left+n.pageXOffset}):{top:0,left:0}:void 0},position:function(){if(this[0]){var e,t,n,r=this[0],i={top:0,left:0};if("fixed"===S.css(r,"position"))t=r.getBoundingClientRect();else{t=this.offset(),n=r.ownerDocument,e=r.offsetParent||n.documentElement;while(e&&(e===n.body||e===n.documentElement)&&"static"===S.css(e,"position"))e=e.parentNode;e&&e!==r&&1===e.nodeType&&((i=S(e).offset()).top+=S.css(e,"borderTopWidth",!0),i.left+=S.css(e,"borderLeftWidth",!0))}return{top:t.top-i.top-S.css(r,"marginTop",!0),left:t.left-i.left-S.css(r,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){var e=this.offsetParent;while(e&&"static"===S.css(e,"position"))e=e.offsetParent;return e||re})}}),S.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(t,i){var o="pageYOffset"===i;S.fn[t]=function(e){return $(this,function(e,t,n){var r;if(x(e)?r=e:9===e.nodeType&&(r=e.defaultView),void 0===n)return r?r[i]:e[t];r?r.scrollTo(o?r.pageXOffset:n,o?n:r.pageYOffset):e[t]=n},t,e,arguments.length)}}),S.each(["top","left"],function(e,n){S.cssHooks[n]=$e(y.pixelPosition,function(e,t){if(t)return t=Be(e,n),Me.test(t)?S(e).position()[n]+"px":t})}),S.each({Height:"height",Width:"width"},function(a,s){S.each({padding:"inner"+a,content:s,"":"outer"+a},function(r,o){S.fn[o]=function(e,t){var n=arguments.length&&(r||"boolean"!=typeof e),i=r||(!0===e||!0===t?"margin":"border");return $(this,function(e,t,n){var r;return x(e)?0===o.indexOf("outer")?e["inner"+a]:e.document.documentElement["client"+a]:9===e.nodeType?(r=e.documentElement,Math.max(e.body["scroll"+a],r["scroll"+a],e.body["offset"+a],r["offset"+a],r["client"+a])):void 0===n?S.css(e,t,i):S.style(e,t,n,i)},s,n?e:void 0,n)}})}),S.each(["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],function(e,t){S.fn[t]=function(e){return this.on(t,e)}}),S.fn.extend({bind:function(e,t,n){return this.on(e,null,t,n)},unbind:function(e,t){return this.off(e,null,t)},delegate:function(e,t,n,r){return this.on(t,e,n,r)},undelegate:function(e,t,n){return 1===arguments.length?this.off(e,"**"):this.off(t,e||"**",n)},hover:function(e,t){return this.mouseenter(e).mouseleave(t||e)}}),S.each("blur focus focusin focusout resize scroll click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup contextmenu".split(" "),function(e,n){S.fn[n]=function(e,t){return 0>7-this.x&1)+((i>>7-this.x&1)<<1),0===this.pix[this.tIndex+this.x]&&(this.opaque[t]=!1)},render:function(t,s,i,e,h,r,n,a,o,l,p,u,m){if(!(r<-7||r>=256||n<-7||n>=240))if(this.w=e-s,this.h=h-i,r<0&&(s-=r),r+e>=256&&(e=256-r),n<0&&(i-=n),n+h>=240&&(h=240-n),l||p)if(l&&!p)for(this.fbIndex=(n<<8)+r,this.tIndex=7,this.y=0;this.y<8;this.y++){for(this.x=0;this.x<8;this.x++)this.x>=s&&this.x=i&&this.y=s&&this.x=i&&this.y=s&&this.x=i&&this.y=s&&this.x=i&&this.y8?(t=24,s&&h.clockFrameCounter(8),i.cyclesToHalt-=8):(t=3*i.cyclesToHalt,s&&h.clockFrameCounter(i.cyclesToHalt),i.cyclesToHalt=0);t>0;t--){if(e.curX===e.spr0HitX&&1===e.f_spVisibility&&e.scanline-21===e.spr0HitY&&e.setStatusFlag(e.STATUS_SPRITE0HIT,!0),e.requestEndFrame&&0===--e.nmiCounter){e.requestEndFrame=!1,e.startVBlank();break t}e.curX++,341===e.curX&&(e.curX=0,e.endScanline())}this.fpsFrameCount++},buttonDown:function(t,s){this.controllers[t].buttonDown(s)},buttonUp:function(t,s){this.controllers[t].buttonUp(s)},zapperMove:function(t,s){this.mmap&&(this.mmap.zapperX=t,this.mmap.zapperY=s)},zapperFireDown:function(){this.mmap&&(this.mmap.zapperFired=!0)},zapperFireUp:function(){this.mmap&&(this.mmap.zapperFired=!1)},getFPS:function(){var t=+new Date,s=null;return this.lastFpsTime&&(s=this.fpsFrameCount/((t-this.lastFpsTime)/1e3)),this.fpsFrameCount=0,this.lastFpsTime=t,s},reloadROM:function(){null!==this.romData&&this.loadROM(this.romData)},loadROM:function(t){this.rom=new a(this),this.rom.load(t),this.reset(),this.mmap=this.rom.createMapper(),this.mmap.loadROM(),this.ppu.setMirroring(this.rom.getMirroringType()),this.romData=t},setFramerate:function(t){this.opts.preferredFrameRate=t,this.frameTime=1e3/t,this.papu.setSampleRate(this.opts.sampleRate,!1)},toJSON:function(){return{romData:this.romData,cpu:this.cpu.toJSON(),mmap:this.mmap.toJSON(),ppu:this.ppu.toJSON()}},fromJSON:function(t){this.loadROM(t.romData),this.cpu.fromJSON(t.cpu),this.mmap.fromJSON(t.mmap),this.ppu.fromJSON(t.ppu)}},t.exports=o},function(t,s,i){var e=i(0),h=function(t){this.nes=t,this.mem=null,this.REG_ACC=null,this.REG_X=null,this.REG_Y=null,this.REG_SP=null,this.REG_PC=null,this.REG_PC_NEW=null,this.REG_STATUS=null,this.F_CARRY=null,this.F_DECIMAL=null,this.F_INTERRUPT=null,this.F_INTERRUPT_NEW=null,this.F_OVERFLOW=null,this.F_SIGN=null,this.F_ZERO=null,this.F_NOTUSED=null,this.F_NOTUSED_NEW=null,this.F_BRK=null,this.F_BRK_NEW=null,this.opdata=null,this.cyclesToHalt=null,this.crash=null,this.irqRequested=null,this.irqType=null,this.reset()};h.prototype={IRQ_NORMAL:0,IRQ_NMI:1,IRQ_RESET:2,reset:function(){this.mem=new Array(65536);for(var t=0;t<8192;t++)this.mem[t]=255;for(var s=0;s<4;s++){var i=2048*s;this.mem[i+8]=247,this.mem[i+9]=239,this.mem[i+10]=223,this.mem[i+15]=191}for(var e=8193;e>24,h=0,r=i>>8&255,n=this.REG_PC;this.REG_PC+=i>>16&255;var a=0;switch(r){case 0:a=this.load(n+2);break;case 1:a=this.load(n+2),a+=a<128?this.REG_PC:this.REG_PC-256;break;case 2:break;case 3:a=this.load16bit(n+2);break;case 4:a=this.REG_ACC;break;case 5:a=this.REG_PC;break;case 6:a=this.load(n+2)+this.REG_X&255;break;case 7:a=this.load(n+2)+this.REG_Y&255;break;case 8:a=this.load16bit(n+2),(65280&a)!=(a+this.REG_X&65280)&&(h=1),a+=this.REG_X;break;case 9:a=this.load16bit(n+2),(65280&a)!=(a+this.REG_Y&65280)&&(h=1),a+=this.REG_Y;break;case 10:a=this.load(n+2),(65280&a)!=(a+this.REG_X&65280)&&(h=1),a+=this.REG_X,a&=255,a=this.load16bit(a);break;case 11:a=this.load16bit(this.load(n+2)),(65280&a)!=(a+this.REG_Y&65280)&&(h=1),a+=this.REG_Y;break;case 12:a=this.load16bit(n+2),a=a<8191?this.mem[a]+(this.mem[65280&a|1+(255&a)&255]<<8):this.nes.mmap.load(a)+(this.nes.mmap.load(65280&a|1+(255&a)&255)<<8)}switch(a&=65535,255&i){case 0:t=this.REG_ACC+this.load(a)+this.F_CARRY,0==(128&(this.REG_ACC^this.load(a)))&&0!=(128&(this.REG_ACC^t))?this.F_OVERFLOW=1:this.F_OVERFLOW=0,this.F_CARRY=t>255?1:0,this.F_SIGN=t>>7&1,this.F_ZERO=255&t,this.REG_ACC=255&t,e+=h;break;case 1:this.REG_ACC=this.REG_ACC&this.load(a),this.F_SIGN=this.REG_ACC>>7&1,this.F_ZERO=this.REG_ACC,11!==r&&(e+=h);break;case 2:4===r?(this.F_CARRY=this.REG_ACC>>7&1,this.REG_ACC=this.REG_ACC<<1&255,this.F_SIGN=this.REG_ACC>>7&1,this.F_ZERO=this.REG_ACC):(t=this.load(a),this.F_CARRY=t>>7&1,t=t<<1&255,this.F_SIGN=t>>7&1,this.F_ZERO=t,this.write(a,t));break;case 3:0===this.F_CARRY&&(e+=(65280&n)!=(65280&a)?2:1,this.REG_PC=a);break;case 4:1===this.F_CARRY&&(e+=(65280&n)!=(65280&a)?2:1,this.REG_PC=a);break;case 5:0===this.F_ZERO&&(e+=(65280&n)!=(65280&a)?2:1,this.REG_PC=a);break;case 6:t=this.load(a),this.F_SIGN=t>>7&1,this.F_OVERFLOW=t>>6&1,t&=this.REG_ACC,this.F_ZERO=t;break;case 7:1===this.F_SIGN&&(e++,this.REG_PC=a);break;case 8:0!==this.F_ZERO&&(e+=(65280&n)!=(65280&a)?2:1,this.REG_PC=a);break;case 9:0===this.F_SIGN&&(e+=(65280&n)!=(65280&a)?2:1,this.REG_PC=a);break;case 10:this.REG_PC+=2,this.push(this.REG_PC>>8&255),this.push(255&this.REG_PC),this.F_BRK=1,this.push(this.F_CARRY|(0===this.F_ZERO?1:0)<<1|this.F_INTERRUPT<<2|this.F_DECIMAL<<3|this.F_BRK<<4|this.F_NOTUSED<<5|this.F_OVERFLOW<<6|this.F_SIGN<<7),this.F_INTERRUPT=1,this.REG_PC=this.load16bit(65534),this.REG_PC--;break;case 11:0===this.F_OVERFLOW&&(e+=(65280&n)!=(65280&a)?2:1,this.REG_PC=a);break;case 12:1===this.F_OVERFLOW&&(e+=(65280&n)!=(65280&a)?2:1,this.REG_PC=a);break;case 13:this.F_CARRY=0;break;case 14:this.F_DECIMAL=0;break;case 15:this.F_INTERRUPT=0;break;case 16:this.F_OVERFLOW=0;break;case 17:t=this.REG_ACC-this.load(a),this.F_CARRY=t>=0?1:0,this.F_SIGN=t>>7&1,this.F_ZERO=255&t,e+=h;break;case 18:t=this.REG_X-this.load(a),this.F_CARRY=t>=0?1:0,this.F_SIGN=t>>7&1,this.F_ZERO=255&t;break;case 19:t=this.REG_Y-this.load(a),this.F_CARRY=t>=0?1:0,this.F_SIGN=t>>7&1,this.F_ZERO=255&t;break;case 20:t=this.load(a)-1&255,this.F_SIGN=t>>7&1,this.F_ZERO=t,this.write(a,t);break;case 21:this.REG_X=this.REG_X-1&255,this.F_SIGN=this.REG_X>>7&1,this.F_ZERO=this.REG_X;break;case 22:this.REG_Y=this.REG_Y-1&255,this.F_SIGN=this.REG_Y>>7&1,this.F_ZERO=this.REG_Y;break;case 23:this.REG_ACC=255&(this.load(a)^this.REG_ACC),this.F_SIGN=this.REG_ACC>>7&1,this.F_ZERO=this.REG_ACC,e+=h;break;case 24:t=this.load(a)+1&255,this.F_SIGN=t>>7&1,this.F_ZERO=t,this.write(a,255&t);break;case 25:this.REG_X=this.REG_X+1&255,this.F_SIGN=this.REG_X>>7&1,this.F_ZERO=this.REG_X;break;case 26:this.REG_Y++,this.REG_Y&=255,this.F_SIGN=this.REG_Y>>7&1,this.F_ZERO=this.REG_Y;break;case 27:this.REG_PC=a-1;break;case 28:this.push(this.REG_PC>>8&255),this.push(255&this.REG_PC),this.REG_PC=a-1;break;case 29:this.REG_ACC=this.load(a),this.F_SIGN=this.REG_ACC>>7&1,this.F_ZERO=this.REG_ACC,e+=h;break;case 30:this.REG_X=this.load(a),this.F_SIGN=this.REG_X>>7&1,this.F_ZERO=this.REG_X,e+=h;break;case 31:this.REG_Y=this.load(a),this.F_SIGN=this.REG_Y>>7&1,this.F_ZERO=this.REG_Y,e+=h;break;case 32:4===r?(t=255&this.REG_ACC,this.F_CARRY=1&t,t>>=1,this.REG_ACC=t):(t=255&this.load(a),this.F_CARRY=1&t,t>>=1,this.write(a,t)),this.F_SIGN=0,this.F_ZERO=t;break;case 33:break;case 34:t=255&(this.load(a)|this.REG_ACC),this.F_SIGN=t>>7&1,this.F_ZERO=t,this.REG_ACC=t,11!==r&&(e+=h);break;case 35:this.push(this.REG_ACC);break;case 36:this.F_BRK=1,this.push(this.F_CARRY|(0===this.F_ZERO?1:0)<<1|this.F_INTERRUPT<<2|this.F_DECIMAL<<3|this.F_BRK<<4|this.F_NOTUSED<<5|this.F_OVERFLOW<<6|this.F_SIGN<<7);break;case 37:this.REG_ACC=this.pull(),this.F_SIGN=this.REG_ACC>>7&1,this.F_ZERO=this.REG_ACC;break;case 38:t=this.pull(),this.F_CARRY=1&t,this.F_ZERO=1==(t>>1&1)?0:1,this.F_INTERRUPT=t>>2&1,this.F_DECIMAL=t>>3&1,this.F_BRK=t>>4&1,this.F_NOTUSED=t>>5&1,this.F_OVERFLOW=t>>6&1,this.F_SIGN=t>>7&1,this.F_NOTUSED=1;break;case 39:4===r?(t=this.REG_ACC,s=this.F_CARRY,this.F_CARRY=t>>7&1,t=(t<<1&255)+s,this.REG_ACC=t):(t=this.load(a),s=this.F_CARRY,this.F_CARRY=t>>7&1,t=(t<<1&255)+s,this.write(a,t)),this.F_SIGN=t>>7&1,this.F_ZERO=t;break;case 40:4===r?(s=this.F_CARRY<<7,this.F_CARRY=1&this.REG_ACC,t=(this.REG_ACC>>1)+s,this.REG_ACC=t):(t=this.load(a),s=this.F_CARRY<<7,this.F_CARRY=1&t,t=(t>>1)+s,this.write(a,t)),this.F_SIGN=t>>7&1,this.F_ZERO=t;break;case 41:if(t=this.pull(),this.F_CARRY=1&t,this.F_ZERO=0==(t>>1&1)?1:0,this.F_INTERRUPT=t>>2&1,this.F_DECIMAL=t>>3&1,this.F_BRK=t>>4&1,this.F_NOTUSED=t>>5&1,this.F_OVERFLOW=t>>6&1,this.F_SIGN=t>>7&1,this.REG_PC=this.pull(),this.REG_PC+=this.pull()<<8,65535===this.REG_PC)return;this.REG_PC--,this.F_NOTUSED=1;break;case 42:if(this.REG_PC=this.pull(),this.REG_PC+=this.pull()<<8,65535===this.REG_PC)return;break;case 43:t=this.REG_ACC-this.load(a)-(1-this.F_CARRY),this.F_SIGN=t>>7&1,this.F_ZERO=255&t,0!=(128&(this.REG_ACC^t))&&0!=(128&(this.REG_ACC^this.load(a)))?this.F_OVERFLOW=1:this.F_OVERFLOW=0,this.F_CARRY=t<0?0:1,this.REG_ACC=255&t,11!==r&&(e+=h);break;case 44:this.F_CARRY=1;break;case 45:this.F_DECIMAL=1;break;case 46:this.F_INTERRUPT=1;break;case 47:this.write(a,this.REG_ACC);break;case 48:this.write(a,this.REG_X);break;case 49:this.write(a,this.REG_Y);break;case 50:this.REG_X=this.REG_ACC,this.F_SIGN=this.REG_ACC>>7&1,this.F_ZERO=this.REG_ACC;break;case 51:this.REG_Y=this.REG_ACC,this.F_SIGN=this.REG_ACC>>7&1,this.F_ZERO=this.REG_ACC;break;case 52:this.REG_X=this.REG_SP-256,this.F_SIGN=this.REG_SP>>7&1,this.F_ZERO=this.REG_X;break;case 53:this.REG_ACC=this.REG_X,this.F_SIGN=this.REG_X>>7&1,this.F_ZERO=this.REG_X;break;case 54:this.REG_SP=this.REG_X+256,this.stackWrap();break;case 55:this.REG_ACC=this.REG_Y,this.F_SIGN=this.REG_Y>>7&1,this.F_ZERO=this.REG_Y;break;case 56:t=this.REG_ACC&this.load(a),this.F_CARRY=1&t,this.REG_ACC=this.F_ZERO=t>>1,this.F_SIGN=0;break;case 57:this.REG_ACC=this.F_ZERO=this.REG_ACC&this.load(a),this.F_CARRY=this.F_SIGN=this.REG_ACC>>7&1;break;case 58:t=this.REG_ACC&this.load(a),this.REG_ACC=this.F_ZERO=(t>>1)+(this.F_CARRY<<7),this.F_SIGN=this.F_CARRY,this.F_CARRY=t>>7&1,this.F_OVERFLOW=1&(t>>7^t>>6);break;case 59:t=(this.REG_X&this.REG_ACC)-this.load(a),this.F_SIGN=t>>7&1,this.F_ZERO=255&t,0!=(128&(this.REG_X^t))&&0!=(128&(this.REG_X^this.load(a)))?this.F_OVERFLOW=1:this.F_OVERFLOW=0,this.F_CARRY=t<0?0:1,this.REG_X=255&t;break;case 60:this.REG_ACC=this.REG_X=this.F_ZERO=this.load(a),this.F_SIGN=this.REG_ACC>>7&1,e+=h;break;case 61:this.write(a,this.REG_ACC&this.REG_X);break;case 62:t=this.load(a)-1&255,this.write(a,t),t=this.REG_ACC-t,this.F_CARRY=t>=0?1:0,this.F_SIGN=t>>7&1,this.F_ZERO=255&t,11!==r&&(e+=h);break;case 63:t=this.load(a)+1&255,this.write(a,t),t=this.REG_ACC-t-(1-this.F_CARRY),this.F_SIGN=t>>7&1,this.F_ZERO=255&t,0!=(128&(this.REG_ACC^t))&&0!=(128&(this.REG_ACC^this.load(a)))?this.F_OVERFLOW=1:this.F_OVERFLOW=0,this.F_CARRY=t<0?0:1,this.REG_ACC=255&t,11!==r&&(e+=h);break;case 64:t=this.load(a),s=this.F_CARRY,this.F_CARRY=t>>7&1,t=(t<<1&255)+s,this.write(a,t),this.REG_ACC=this.REG_ACC&t,this.F_SIGN=this.REG_ACC>>7&1,this.F_ZERO=this.REG_ACC,11!==r&&(e+=h);break;case 65:t=this.load(a),s=this.F_CARRY<<7,this.F_CARRY=1&t,t=(t>>1)+s,this.write(a,t),t=this.REG_ACC+this.load(a)+this.F_CARRY,0==(128&(this.REG_ACC^this.load(a)))&&0!=(128&(this.REG_ACC^t))?this.F_OVERFLOW=1:this.F_OVERFLOW=0,this.F_CARRY=t>255?1:0,this.F_SIGN=t>>7&1,this.F_ZERO=255&t,this.REG_ACC=255&t,11!==r&&(e+=h);break;case 66:t=this.load(a),this.F_CARRY=t>>7&1,t=t<<1&255,this.write(a,t),this.REG_ACC=this.REG_ACC|t,this.F_SIGN=this.REG_ACC>>7&1,this.F_ZERO=this.REG_ACC,11!==r&&(e+=h);break;case 67:t=255&this.load(a),this.F_CARRY=1&t,t>>=1,this.write(a,t),this.REG_ACC=this.REG_ACC^t,this.F_SIGN=this.REG_ACC>>7&1,this.F_ZERO=this.REG_ACC,11!==r&&(e+=h);break;case 68:break;case 69:this.load(a),11!==r&&(e+=h);break;default:this.nes.stop(),this.nes.crashMessage="Game crashed, invalid opcode at address $"+n.toString(16)}return e},load:function(t){return t<8192?this.mem[2047&t]:this.nes.mmap.load(t)},load16bit:function(t){return t<8191?this.mem[2047&t]|this.mem[t+1&2047]<<8:this.nes.mmap.load(t)|this.nes.mmap.load(t+1)<<8},write:function(t,s){t<8192?this.mem[2047&t]=s:this.nes.mmap.write(t,s)},requestIrq:function(t){this.irqRequested&&t===this.IRQ_NORMAL||(this.irqRequested=!0,this.irqType=t)},push:function(t){this.nes.mmap.write(this.REG_SP,t),this.REG_SP--,this.REG_SP=256|255&this.REG_SP},stackWrap:function(){this.REG_SP=256|255&this.REG_SP},pull:function(){return this.REG_SP++,this.REG_SP=256|255&this.REG_SP,this.nes.mmap.load(this.REG_SP)},pageCrossed:function(t,s){return(65280&t)!=(65280&s)},haltCycles:function(t){this.cyclesToHalt+=t},doNonMaskableInterrupt:function(t){0!=(128&this.nes.mmap.load(8192))&&(this.REG_PC_NEW++,this.push(this.REG_PC_NEW>>8&255),this.push(255&this.REG_PC_NEW),this.push(t),this.REG_PC_NEW=this.nes.mmap.load(65530)|this.nes.mmap.load(65531)<<8,this.REG_PC_NEW--)},doResetInterrupt:function(){this.REG_PC_NEW=this.nes.mmap.load(65532)|this.nes.mmap.load(65533)<<8,this.REG_PC_NEW--},doIrq:function(t){this.REG_PC_NEW++,this.push(this.REG_PC_NEW>>8&255),this.push(255&this.REG_PC_NEW),this.push(t),this.F_INTERRUPT_NEW=1,this.F_BRK_NEW=0,this.REG_PC_NEW=this.nes.mmap.load(65534)|this.nes.mmap.load(65535)<<8,this.REG_PC_NEW--},getStatus:function(){return this.F_CARRY|this.F_ZERO<<1|this.F_INTERRUPT<<2|this.F_DECIMAL<<3|this.F_BRK<<4|this.F_NOTUSED<<5|this.F_OVERFLOW<<6|this.F_SIGN<<7},setStatus:function(t){this.F_CARRY=1&t,this.F_ZERO=t>>1&1,this.F_INTERRUPT=t>>2&1,this.F_DECIMAL=t>>3&1,this.F_BRK=t>>4&1,this.F_NOTUSED=t>>5&1,this.F_OVERFLOW=t>>6&1,this.F_SIGN=t>>7&1},JSON_PROPERTIES:["mem","cyclesToHalt","irqRequested","irqType","REG_ACC","REG_X","REG_Y","REG_SP","REG_PC","REG_PC_NEW","REG_STATUS","F_CARRY","F_DECIMAL","F_INTERRUPT","F_INTERRUPT_NEW","F_OVERFLOW","F_SIGN","F_ZERO","F_NOTUSED","F_NOTUSED_NEW","F_BRK","F_BRK_NEW"],toJSON:function(){return e.toJSON(this)},fromJSON:function(t){e.fromJSON(this,t)}};var r=function(){this.opdata=new Array(256);for(var t=0;t<256;t++)this.opdata[t]=255;this.setOp(this.INS_ADC,105,this.ADDR_IMM,2,2),this.setOp(this.INS_ADC,101,this.ADDR_ZP,2,3),this.setOp(this.INS_ADC,117,this.ADDR_ZPX,2,4),this.setOp(this.INS_ADC,109,this.ADDR_ABS,3,4),this.setOp(this.INS_ADC,125,this.ADDR_ABSX,3,4),this.setOp(this.INS_ADC,121,this.ADDR_ABSY,3,4),this.setOp(this.INS_ADC,97,this.ADDR_PREIDXIND,2,6),this.setOp(this.INS_ADC,113,this.ADDR_POSTIDXIND,2,5),this.setOp(this.INS_AND,41,this.ADDR_IMM,2,2),this.setOp(this.INS_AND,37,this.ADDR_ZP,2,3),this.setOp(this.INS_AND,53,this.ADDR_ZPX,2,4),this.setOp(this.INS_AND,45,this.ADDR_ABS,3,4),this.setOp(this.INS_AND,61,this.ADDR_ABSX,3,4),this.setOp(this.INS_AND,57,this.ADDR_ABSY,3,4),this.setOp(this.INS_AND,33,this.ADDR_PREIDXIND,2,6),this.setOp(this.INS_AND,49,this.ADDR_POSTIDXIND,2,5),this.setOp(this.INS_ASL,10,this.ADDR_ACC,1,2),this.setOp(this.INS_ASL,6,this.ADDR_ZP,2,5),this.setOp(this.INS_ASL,22,this.ADDR_ZPX,2,6),this.setOp(this.INS_ASL,14,this.ADDR_ABS,3,6),this.setOp(this.INS_ASL,30,this.ADDR_ABSX,3,7),this.setOp(this.INS_BCC,144,this.ADDR_REL,2,2),this.setOp(this.INS_BCS,176,this.ADDR_REL,2,2),this.setOp(this.INS_BEQ,240,this.ADDR_REL,2,2),this.setOp(this.INS_BIT,36,this.ADDR_ZP,2,3),this.setOp(this.INS_BIT,44,this.ADDR_ABS,3,4),this.setOp(this.INS_BMI,48,this.ADDR_REL,2,2),this.setOp(this.INS_BNE,208,this.ADDR_REL,2,2),this.setOp(this.INS_BPL,16,this.ADDR_REL,2,2),this.setOp(this.INS_BRK,0,this.ADDR_IMP,1,7),this.setOp(this.INS_BVC,80,this.ADDR_REL,2,2),this.setOp(this.INS_BVS,112,this.ADDR_REL,2,2),this.setOp(this.INS_CLC,24,this.ADDR_IMP,1,2),this.setOp(this.INS_CLD,216,this.ADDR_IMP,1,2),this.setOp(this.INS_CLI,88,this.ADDR_IMP,1,2),this.setOp(this.INS_CLV,184,this.ADDR_IMP,1,2),this.setOp(this.INS_CMP,201,this.ADDR_IMM,2,2),this.setOp(this.INS_CMP,197,this.ADDR_ZP,2,3),this.setOp(this.INS_CMP,213,this.ADDR_ZPX,2,4),this.setOp(this.INS_CMP,205,this.ADDR_ABS,3,4),this.setOp(this.INS_CMP,221,this.ADDR_ABSX,3,4),this.setOp(this.INS_CMP,217,this.ADDR_ABSY,3,4),this.setOp(this.INS_CMP,193,this.ADDR_PREIDXIND,2,6),this.setOp(this.INS_CMP,209,this.ADDR_POSTIDXIND,2,5),this.setOp(this.INS_CPX,224,this.ADDR_IMM,2,2),this.setOp(this.INS_CPX,228,this.ADDR_ZP,2,3),this.setOp(this.INS_CPX,236,this.ADDR_ABS,3,4),this.setOp(this.INS_CPY,192,this.ADDR_IMM,2,2),this.setOp(this.INS_CPY,196,this.ADDR_ZP,2,3),this.setOp(this.INS_CPY,204,this.ADDR_ABS,3,4),this.setOp(this.INS_DEC,198,this.ADDR_ZP,2,5),this.setOp(this.INS_DEC,214,this.ADDR_ZPX,2,6),this.setOp(this.INS_DEC,206,this.ADDR_ABS,3,6),this.setOp(this.INS_DEC,222,this.ADDR_ABSX,3,7),this.setOp(this.INS_DEX,202,this.ADDR_IMP,1,2),this.setOp(this.INS_DEY,136,this.ADDR_IMP,1,2),this.setOp(this.INS_EOR,73,this.ADDR_IMM,2,2),this.setOp(this.INS_EOR,69,this.ADDR_ZP,2,3),this.setOp(this.INS_EOR,85,this.ADDR_ZPX,2,4),this.setOp(this.INS_EOR,77,this.ADDR_ABS,3,4),this.setOp(this.INS_EOR,93,this.ADDR_ABSX,3,4),this.setOp(this.INS_EOR,89,this.ADDR_ABSY,3,4),this.setOp(this.INS_EOR,65,this.ADDR_PREIDXIND,2,6),this.setOp(this.INS_EOR,81,this.ADDR_POSTIDXIND,2,5),this.setOp(this.INS_INC,230,this.ADDR_ZP,2,5),this.setOp(this.INS_INC,246,this.ADDR_ZPX,2,6),this.setOp(this.INS_INC,238,this.ADDR_ABS,3,6),this.setOp(this.INS_INC,254,this.ADDR_ABSX,3,7),this.setOp(this.INS_INX,232,this.ADDR_IMP,1,2),this.setOp(this.INS_INY,200,this.ADDR_IMP,1,2),this.setOp(this.INS_JMP,76,this.ADDR_ABS,3,3),this.setOp(this.INS_JMP,108,this.ADDR_INDABS,3,5),this.setOp(this.INS_JSR,32,this.ADDR_ABS,3,6),this.setOp(this.INS_LDA,169,this.ADDR_IMM,2,2),this.setOp(this.INS_LDA,165,this.ADDR_ZP,2,3),this.setOp(this.INS_LDA,181,this.ADDR_ZPX,2,4),this.setOp(this.INS_LDA,173,this.ADDR_ABS,3,4),this.setOp(this.INS_LDA,189,this.ADDR_ABSX,3,4),this.setOp(this.INS_LDA,185,this.ADDR_ABSY,3,4),this.setOp(this.INS_LDA,161,this.ADDR_PREIDXIND,2,6),this.setOp(this.INS_LDA,177,this.ADDR_POSTIDXIND,2,5),this.setOp(this.INS_LDX,162,this.ADDR_IMM,2,2),this.setOp(this.INS_LDX,166,this.ADDR_ZP,2,3),this.setOp(this.INS_LDX,182,this.ADDR_ZPY,2,4),this.setOp(this.INS_LDX,174,this.ADDR_ABS,3,4),this.setOp(this.INS_LDX,190,this.ADDR_ABSY,3,4),this.setOp(this.INS_LDY,160,this.ADDR_IMM,2,2),this.setOp(this.INS_LDY,164,this.ADDR_ZP,2,3),this.setOp(this.INS_LDY,180,this.ADDR_ZPX,2,4),this.setOp(this.INS_LDY,172,this.ADDR_ABS,3,4),this.setOp(this.INS_LDY,188,this.ADDR_ABSX,3,4),this.setOp(this.INS_LSR,74,this.ADDR_ACC,1,2),this.setOp(this.INS_LSR,70,this.ADDR_ZP,2,5),this.setOp(this.INS_LSR,86,this.ADDR_ZPX,2,6),this.setOp(this.INS_LSR,78,this.ADDR_ABS,3,6),this.setOp(this.INS_LSR,94,this.ADDR_ABSX,3,7),this.setOp(this.INS_NOP,26,this.ADDR_IMP,1,2),this.setOp(this.INS_NOP,58,this.ADDR_IMP,1,2),this.setOp(this.INS_NOP,90,this.ADDR_IMP,1,2),this.setOp(this.INS_NOP,122,this.ADDR_IMP,1,2),this.setOp(this.INS_NOP,218,this.ADDR_IMP,1,2),this.setOp(this.INS_NOP,234,this.ADDR_IMP,1,2),this.setOp(this.INS_NOP,250,this.ADDR_IMP,1,2),this.setOp(this.INS_ORA,9,this.ADDR_IMM,2,2),this.setOp(this.INS_ORA,5,this.ADDR_ZP,2,3),this.setOp(this.INS_ORA,21,this.ADDR_ZPX,2,4),this.setOp(this.INS_ORA,13,this.ADDR_ABS,3,4),this.setOp(this.INS_ORA,29,this.ADDR_ABSX,3,4),this.setOp(this.INS_ORA,25,this.ADDR_ABSY,3,4),this.setOp(this.INS_ORA,1,this.ADDR_PREIDXIND,2,6),this.setOp(this.INS_ORA,17,this.ADDR_POSTIDXIND,2,5),this.setOp(this.INS_PHA,72,this.ADDR_IMP,1,3),this.setOp(this.INS_PHP,8,this.ADDR_IMP,1,3),this.setOp(this.INS_PLA,104,this.ADDR_IMP,1,4),this.setOp(this.INS_PLP,40,this.ADDR_IMP,1,4),this.setOp(this.INS_ROL,42,this.ADDR_ACC,1,2),this.setOp(this.INS_ROL,38,this.ADDR_ZP,2,5),this.setOp(this.INS_ROL,54,this.ADDR_ZPX,2,6),this.setOp(this.INS_ROL,46,this.ADDR_ABS,3,6),this.setOp(this.INS_ROL,62,this.ADDR_ABSX,3,7),this.setOp(this.INS_ROR,106,this.ADDR_ACC,1,2),this.setOp(this.INS_ROR,102,this.ADDR_ZP,2,5),this.setOp(this.INS_ROR,118,this.ADDR_ZPX,2,6),this.setOp(this.INS_ROR,110,this.ADDR_ABS,3,6),this.setOp(this.INS_ROR,126,this.ADDR_ABSX,3,7),this.setOp(this.INS_RTI,64,this.ADDR_IMP,1,6),this.setOp(this.INS_RTS,96,this.ADDR_IMP,1,6),this.setOp(this.INS_SBC,233,this.ADDR_IMM,2,2),this.setOp(this.INS_SBC,229,this.ADDR_ZP,2,3),this.setOp(this.INS_SBC,245,this.ADDR_ZPX,2,4),this.setOp(this.INS_SBC,237,this.ADDR_ABS,3,4),this.setOp(this.INS_SBC,253,this.ADDR_ABSX,3,4),this.setOp(this.INS_SBC,249,this.ADDR_ABSY,3,4),this.setOp(this.INS_SBC,225,this.ADDR_PREIDXIND,2,6),this.setOp(this.INS_SBC,241,this.ADDR_POSTIDXIND,2,5),this.setOp(this.INS_SEC,56,this.ADDR_IMP,1,2),this.setOp(this.INS_SED,248,this.ADDR_IMP,1,2),this.setOp(this.INS_SEI,120,this.ADDR_IMP,1,2),this.setOp(this.INS_STA,133,this.ADDR_ZP,2,3),this.setOp(this.INS_STA,149,this.ADDR_ZPX,2,4),this.setOp(this.INS_STA,141,this.ADDR_ABS,3,4),this.setOp(this.INS_STA,157,this.ADDR_ABSX,3,5),this.setOp(this.INS_STA,153,this.ADDR_ABSY,3,5),this.setOp(this.INS_STA,129,this.ADDR_PREIDXIND,2,6),this.setOp(this.INS_STA,145,this.ADDR_POSTIDXIND,2,6),this.setOp(this.INS_STX,134,this.ADDR_ZP,2,3),this.setOp(this.INS_STX,150,this.ADDR_ZPY,2,4),this.setOp(this.INS_STX,142,this.ADDR_ABS,3,4),this.setOp(this.INS_STY,132,this.ADDR_ZP,2,3),this.setOp(this.INS_STY,148,this.ADDR_ZPX,2,4),this.setOp(this.INS_STY,140,this.ADDR_ABS,3,4),this.setOp(this.INS_TAX,170,this.ADDR_IMP,1,2),this.setOp(this.INS_TAY,168,this.ADDR_IMP,1,2),this.setOp(this.INS_TSX,186,this.ADDR_IMP,1,2),this.setOp(this.INS_TXA,138,this.ADDR_IMP,1,2),this.setOp(this.INS_TXS,154,this.ADDR_IMP,1,2),this.setOp(this.INS_TYA,152,this.ADDR_IMP,1,2),this.setOp(this.INS_ALR,75,this.ADDR_IMM,2,2),this.setOp(this.INS_ANC,11,this.ADDR_IMM,2,2),this.setOp(this.INS_ANC,43,this.ADDR_IMM,2,2),this.setOp(this.INS_ARR,107,this.ADDR_IMM,2,2),this.setOp(this.INS_AXS,203,this.ADDR_IMM,2,2),this.setOp(this.INS_LAX,163,this.ADDR_PREIDXIND,2,6),this.setOp(this.INS_LAX,167,this.ADDR_ZP,2,3),this.setOp(this.INS_LAX,175,this.ADDR_ABS,3,4),this.setOp(this.INS_LAX,179,this.ADDR_POSTIDXIND,2,5),this.setOp(this.INS_LAX,183,this.ADDR_ZPY,2,4),this.setOp(this.INS_LAX,191,this.ADDR_ABSY,3,4),this.setOp(this.INS_SAX,131,this.ADDR_PREIDXIND,2,6),this.setOp(this.INS_SAX,135,this.ADDR_ZP,2,3),this.setOp(this.INS_SAX,143,this.ADDR_ABS,3,4),this.setOp(this.INS_SAX,151,this.ADDR_ZPY,2,4),this.setOp(this.INS_DCP,195,this.ADDR_PREIDXIND,2,8),this.setOp(this.INS_DCP,199,this.ADDR_ZP,2,5),this.setOp(this.INS_DCP,207,this.ADDR_ABS,3,6),this.setOp(this.INS_DCP,211,this.ADDR_POSTIDXIND,2,8),this.setOp(this.INS_DCP,215,this.ADDR_ZPX,2,6),this.setOp(this.INS_DCP,219,this.ADDR_ABSY,3,7),this.setOp(this.INS_DCP,223,this.ADDR_ABSX,3,7),this.setOp(this.INS_ISC,227,this.ADDR_PREIDXIND,2,8),this.setOp(this.INS_ISC,231,this.ADDR_ZP,2,5),this.setOp(this.INS_ISC,239,this.ADDR_ABS,3,6),this.setOp(this.INS_ISC,243,this.ADDR_POSTIDXIND,2,8),this.setOp(this.INS_ISC,247,this.ADDR_ZPX,2,6),this.setOp(this.INS_ISC,251,this.ADDR_ABSY,3,7),this.setOp(this.INS_ISC,255,this.ADDR_ABSX,3,7),this.setOp(this.INS_RLA,35,this.ADDR_PREIDXIND,2,8),this.setOp(this.INS_RLA,39,this.ADDR_ZP,2,5),this.setOp(this.INS_RLA,47,this.ADDR_ABS,3,6),this.setOp(this.INS_RLA,51,this.ADDR_POSTIDXIND,2,8),this.setOp(this.INS_RLA,55,this.ADDR_ZPX,2,6),this.setOp(this.INS_RLA,59,this.ADDR_ABSY,3,7),this.setOp(this.INS_RLA,63,this.ADDR_ABSX,3,7),this.setOp(this.INS_RRA,99,this.ADDR_PREIDXIND,2,8),this.setOp(this.INS_RRA,103,this.ADDR_ZP,2,5),this.setOp(this.INS_RRA,111,this.ADDR_ABS,3,6),this.setOp(this.INS_RRA,115,this.ADDR_POSTIDXIND,2,8),this.setOp(this.INS_RRA,119,this.ADDR_ZPX,2,6),this.setOp(this.INS_RRA,123,this.ADDR_ABSY,3,7),this.setOp(this.INS_RRA,127,this.ADDR_ABSX,3,7);this.setOp(this.INS_SLO,3,this.ADDR_PREIDXIND,2,8),this.setOp(this.INS_SLO,7,this.ADDR_ZP,2,5),this.setOp(this.INS_SLO,15,this.ADDR_ABS,3,6),this.setOp(this.INS_SLO,19,this.ADDR_POSTIDXIND,2,8),this.setOp(this.INS_SLO,23,this.ADDR_ZPX,2,6),this.setOp(this.INS_SLO,27,this.ADDR_ABSY,3,7),this.setOp(this.INS_SLO,31,this.ADDR_ABSX,3,7),this.setOp(this.INS_SRE,67,this.ADDR_PREIDXIND,2,8),this.setOp(this.INS_SRE,71,this.ADDR_ZP,2,5),this.setOp(this.INS_SRE,79,this.ADDR_ABS,3,6),this.setOp(this.INS_SRE,83,this.ADDR_POSTIDXIND,2,8),this.setOp(this.INS_SRE,87,this.ADDR_ZPX,2,6),this.setOp(this.INS_SRE,91,this.ADDR_ABSY,3,7),this.setOp(this.INS_SRE,95,this.ADDR_ABSX,3,7),this.setOp(this.INS_SKB,128,this.ADDR_IMM,2,2),this.setOp(this.INS_SKB,130,this.ADDR_IMM,2,2),this.setOp(this.INS_SKB,137,this.ADDR_IMM,2,2),this.setOp(this.INS_SKB,194,this.ADDR_IMM,2,2),this.setOp(this.INS_SKB,226,this.ADDR_IMM,2,2),this.setOp(this.INS_IGN,12,this.ADDR_ABS,3,4),this.setOp(this.INS_IGN,28,this.ADDR_ABSX,3,4),this.setOp(this.INS_IGN,60,this.ADDR_ABSX,3,4),this.setOp(this.INS_IGN,92,this.ADDR_ABSX,3,4),this.setOp(this.INS_IGN,124,this.ADDR_ABSX,3,4),this.setOp(this.INS_IGN,220,this.ADDR_ABSX,3,4),this.setOp(this.INS_IGN,252,this.ADDR_ABSX,3,4),this.setOp(this.INS_IGN,4,this.ADDR_ZP,2,3),this.setOp(this.INS_IGN,68,this.ADDR_ZP,2,3),this.setOp(this.INS_IGN,100,this.ADDR_ZP,2,3),this.setOp(this.INS_IGN,20,this.ADDR_ZPX,2,4),this.setOp(this.INS_IGN,52,this.ADDR_ZPX,2,4),this.setOp(this.INS_IGN,84,this.ADDR_ZPX,2,4),this.setOp(this.INS_IGN,116,this.ADDR_ZPX,2,4),this.setOp(this.INS_IGN,212,this.ADDR_ZPX,2,4),this.setOp(this.INS_IGN,244,this.ADDR_ZPX,2,4),this.cycTable=new Array(7,6,2,8,3,3,5,5,3,2,2,2,4,4,6,6,2,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,6,6,2,8,3,3,5,5,4,2,2,2,4,4,6,6,2,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,6,6,2,8,3,3,5,5,3,2,2,2,3,4,6,6,2,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,6,6,2,8,3,3,5,5,4,2,2,2,5,4,6,6,2,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,2,6,2,6,3,3,3,3,2,2,2,2,4,4,4,4,2,6,2,6,4,4,4,4,2,5,2,5,5,5,5,5,2,6,2,6,3,3,3,3,2,2,2,2,4,4,4,4,2,5,2,5,4,4,4,4,2,4,2,4,4,4,4,4,2,6,2,8,3,3,5,5,2,2,2,2,4,4,6,6,2,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7,2,6,3,8,3,3,5,5,2,2,2,2,4,4,6,6,2,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7),this.instname=new Array(70),this.instname[0]="ADC",this.instname[1]="AND",this.instname[2]="ASL",this.instname[3]="BCC",this.instname[4]="BCS",this.instname[5]="BEQ",this.instname[6]="BIT",this.instname[7]="BMI",this.instname[8]="BNE",this.instname[9]="BPL",this.instname[10]="BRK",this.instname[11]="BVC",this.instname[12]="BVS",this.instname[13]="CLC",this.instname[14]="CLD",this.instname[15]="CLI",this.instname[16]="CLV",this.instname[17]="CMP",this.instname[18]="CPX",this.instname[19]="CPY",this.instname[20]="DEC",this.instname[21]="DEX",this.instname[22]="DEY",this.instname[23]="EOR",this.instname[24]="INC",this.instname[25]="INX",this.instname[26]="INY",this.instname[27]="JMP",this.instname[28]="JSR",this.instname[29]="LDA",this.instname[30]="LDX",this.instname[31]="LDY",this.instname[32]="LSR",this.instname[33]="NOP",this.instname[34]="ORA",this.instname[35]="PHA",this.instname[36]="PHP",this.instname[37]="PLA",this.instname[38]="PLP",this.instname[39]="ROL",this.instname[40]="ROR",this.instname[41]="RTI",this.instname[42]="RTS",this.instname[43]="SBC",this.instname[44]="SEC",this.instname[45]="SED",this.instname[46]="SEI",this.instname[47]="STA",this.instname[48]="STX",this.instname[49]="STY",this.instname[50]="TAX",this.instname[51]="TAY",this.instname[52]="TSX",this.instname[53]="TXA",this.instname[54]="TXS",this.instname[55]="TYA",this.instname[56]="ALR",this.instname[57]="ANC",this.instname[58]="ARR",this.instname[59]="AXS",this.instname[60]="LAX",this.instname[61]="SAX",this.instname[62]="DCP",this.instname[63]="ISC",this.instname[64]="RLA",this.instname[65]="RRA",this.instname[66]="SLO",this.instname[67]="SRE",this.instname[68]="SKB",this.instname[69]="IGN",this.addrDesc=new Array("Zero Page ","Relative ","Implied ","Absolute ","Accumulator ","Immediate ","Zero Page,X ","Zero Page,Y ","Absolute,X ","Absolute,Y ","Preindexed Indirect ","Postindexed Indirect","Indirect Absolute ")};r.prototype={INS_ADC:0,INS_AND:1,INS_ASL:2,INS_BCC:3,INS_BCS:4,INS_BEQ:5,INS_BIT:6,INS_BMI:7,INS_BNE:8,INS_BPL:9,INS_BRK:10,INS_BVC:11,INS_BVS:12,INS_CLC:13,INS_CLD:14,INS_CLI:15,INS_CLV:16,INS_CMP:17,INS_CPX:18,INS_CPY:19,INS_DEC:20,INS_DEX:21,INS_DEY:22,INS_EOR:23,INS_INC:24,INS_INX:25,INS_INY:26,INS_JMP:27,INS_JSR:28,INS_LDA:29,INS_LDX:30,INS_LDY:31,INS_LSR:32,INS_NOP:33,INS_ORA:34,INS_PHA:35,INS_PHP:36,INS_PLA:37,INS_PLP:38,INS_ROL:39,INS_ROR:40,INS_RTI:41,INS_RTS:42,INS_SBC:43,INS_SEC:44,INS_SED:45,INS_SEI:46,INS_STA:47,INS_STX:48,INS_STY:49,INS_TAX:50,INS_TAY:51,INS_TSX:52,INS_TXA:53,INS_TXS:54,INS_TYA:55,INS_ALR:56,INS_ANC:57,INS_ARR:58,INS_AXS:59,INS_LAX:60,INS_SAX:61,INS_DCP:62,INS_ISC:63,INS_RLA:64,INS_RRA:65,INS_SLO:66,INS_SRE:67,INS_SKB:68,INS_IGN:69,INS_DUMMY:70,ADDR_ZP:0,ADDR_REL:1,ADDR_IMP:2,ADDR_ABS:3,ADDR_ACC:4,ADDR_IMM:5,ADDR_ZPX:6,ADDR_ZPY:7,ADDR_ABSX:8,ADDR_ABSY:9,ADDR_PREIDXIND:10,ADDR_POSTIDXIND:11,ADDR_INDABS:12,setOp:function(t,s,i,e,h){this.opdata[s]=255&t|(255&i)<<8|(255&e)<<16|(255&h)<<24}},t.exports=h},function(t,s,i){var e=i(2),h=i(0),r=function(t){this.nes=t,this.vramMem=null,this.spriteMem=null,this.vramAddress=null,this.vramTmpAddress=null,this.vramBufferedReadValue=null,this.firstWrite=null,this.sramAddress=null,this.currentMirroring=null,this.requestEndFrame=null,this.nmiOk=null,this.dummyCycleToggle=null,this.validTileData=null,this.nmiCounter=null,this.scanlineAlreadyRendered=null,this.f_nmiOnVblank=null,this.f_spriteSize=null,this.f_bgPatternTable=null,this.f_spPatternTable=null,this.f_addrInc=null,this.f_nTblAddress=null,this.f_color=null,this.f_spVisibility=null,this.f_bgVisibility=null,this.f_spClipping=null,this.f_bgClipping=null,this.f_dispType=null,this.cntFV=null,this.cntV=null,this.cntH=null,this.cntVT=null,this.cntHT=null,this.regFV=null,this.regV=null,this.regH=null,this.regVT=null,this.regHT=null,this.regFH=null,this.regS=null,this.curNt=null,this.attrib=null,this.buffer=null,this.bgbuffer=null,this.pixrendered=null,this.validTileData=null,this.scantile=null,this.scanline=null,this.lastRenderedScanline=null,this.curX=null,this.sprX=null,this.sprY=null,this.sprTile=null,this.sprCol=null,this.vertFlip=null,this.horiFlip=null,this.bgPriority=null,this.spr0HitX=null,this.spr0HitY=null,this.hitSpr0=null,this.sprPalette=null,this.imgPalette=null,this.ptTile=null,this.ntable1=null,this.currentMirroring=null,this.nameTable=null,this.vramMirrorTable=null,this.palTable=null,this.showSpr0Hit=!1,this.clipToTvSize=!0,this.reset()};r.prototype={STATUS_VRAMWRITE:4,STATUS_SLSPRITECOUNT:5,STATUS_SPRITE0HIT:6,STATUS_VBLANK:7,reset:function(){var t;for(this.vramMem=new Array(32768),this.spriteMem=new Array(256),t=0;t=21&&this.scanline<=260&&(1===this.f_bgVisibility&&(this.scanlineAlreadyRendered||(this.cntHT=this.regHT,this.cntH=this.regH,this.renderBgScanline(!0,this.scanline+1-21)),this.scanlineAlreadyRendered=!1,this.hitSpr0||1!==this.f_spVisibility||this.sprX[0]>=-7&&this.sprX[0]<256&&this.sprY[0]+1<=this.scanline-20&&this.sprY[0]+1+(0===this.f_spriteSize?8:16)>=this.scanline-20&&this.checkSprite0(this.scanline-20)&&(this.hitSpr0=!0)),1!==this.f_bgVisibility&&1!==this.f_spVisibility||this.nes.mmap.clockIrqCounter())}this.scanline++,this.regsToAddress(),this.cntsToAddress()},startFrame:function(){var t=0;if(0===this.f_dispType)t=this.imgPalette[0];else switch(this.f_color){case 0:t=0;break;case 1:t=65280;break;case 2:t=16711680;break;case 3:t=0;break;case 4:t=255;break;default:t=0}var s,i=this.buffer;for(s=0;s<61440;s++)i[s]=t;var e=this.pixrendered;for(s=0;s=0&&this.sprX[0]<256&&this.sprY[0]>=0&&this.sprY[0]<240){for(t=0;t<256;t++)e[(this.sprY[0]<<8)+t]=16733525;for(t=0;t<240;t++)e[(t<<8)+this.sprX[0]]=16733525}if(this.spr0HitX>=0&&this.spr0HitX<256&&this.spr0HitY>=0&&this.spr0HitY<240){for(t=0;t<256;t++)e[(this.spr0HitY<<8)+t]=5635925;for(t=0;t<240;t++)e[(t<<8)+this.spr0HitX]=5635925}}if(this.clipToTvSize||0===this.f_bgClipping||0===this.f_spClipping)for(i=0;i<240;i++)for(s=0;s<8;s++)e[(i<<8)+s]=0;if(this.clipToTvSize)for(i=0;i<240;i++)for(s=0;s<8;s++)e[255+(i<<8)-s]=0;if(this.clipToTvSize)for(i=0;i<8;i++)for(s=0;s<256;s++)e[(i<<8)+s]=0,e[(239-i<<8)+s]=0;this.nes.ui.writeFrame(e)},updateControlReg1:function(t){this.triggerRendering(),this.f_nmiOnVblank=t>>7&1,this.f_spriteSize=t>>5&1,this.f_bgPatternTable=t>>4&1,this.f_spPatternTable=t>>3&1,this.f_addrInc=t>>2&1,this.f_nTblAddress=3&t,this.regV=t>>1&1,this.regH=1&t,this.regS=t>>4&1},updateControlReg2:function(t){this.triggerRendering(),this.f_color=t>>5&7,this.f_spVisibility=t>>4&1,this.f_bgVisibility=t>>3&1,this.f_spClipping=t>>2&1,this.f_bgClipping=t>>1&1,this.f_dispType=1&t,0===this.f_dispType&&this.palTable.setEmphasis(this.f_color),this.updatePalettes()},setStatusFlag:function(t,s){var i=1<>3&31,this.regFH=7&t):(this.regFV=7&t,this.regVT=t>>3&31),this.firstWrite=!this.firstWrite},writeVRAMAddress:function(t){this.firstWrite?(this.regFV=t>>4&3,this.regV=t>>3&1,this.regH=t>>2&1,this.regVT=7&this.regVT|(3&t)<<3):(this.triggerRendering(),this.regVT=24&this.regVT|t>>5&7,this.regHT=31&t,this.cntFV=this.regFV,this.cntV=this.regV,this.cntH=this.regH,this.cntVT=this.regVT,this.cntHT=this.regHT,this.checkSprite0(this.scanline-20)),this.firstWrite=!this.firstWrite,this.cntsToAddress(),this.vramAddress<8192&&this.nes.mmap.latchAccess(this.vramAddress)},vramLoad:function(){var t;return this.cntsToAddress(),this.regsToAddress(),this.vramAddress<=16127?(t=this.vramBufferedReadValue,this.vramAddress<8192?this.vramBufferedReadValue=this.vramMem[this.vramAddress]:this.vramBufferedReadValue=this.mirroredLoad(this.vramAddress),this.vramAddress<8192&&this.nes.mmap.latchAccess(this.vramAddress),this.vramAddress+=1===this.f_addrInc?32:1,this.cntsFromAddress(),this.regsFromAddress(),t):(t=this.mirroredLoad(this.vramAddress),this.vramAddress+=1===this.f_addrInc?32:1,this.cntsFromAddress(),this.regsFromAddress(),t)},vramWrite:function(t){this.triggerRendering(),this.cntsToAddress(),this.regsToAddress(),this.vramAddress>=8192?this.mirroredWrite(this.vramAddress,t):(this.writeMem(this.vramAddress,t),this.nes.mmap.latchAccess(this.vramAddress)),this.vramAddress+=1===this.f_addrInc?32:1,this.regsFromAddress(),this.cntsFromAddress()},sramDMA:function(t){for(var s,i=256*t,e=this.sramAddress;e<256;e++)s=this.nes.cpu.mem[i+e],this.spriteMem[e]=s,this.spriteRamWriteUpdate(e,s);this.nes.cpu.haltCycles(513)},regsFromAddress:function(){var t=this.vramTmpAddress>>8&255;this.regFV=t>>4&7,this.regV=t>>3&1,this.regH=t>>2&1,this.regVT=7&this.regVT|(3&t)<<3,t=255&this.vramTmpAddress,this.regVT=24&this.regVT|t>>5&7,this.regHT=31&t},cntsFromAddress:function(){var t=this.vramAddress>>8&255;this.cntFV=t>>4&3,this.cntV=t>>3&1,this.cntH=t>>2&1,this.cntVT=7&this.cntVT|(3&t)<<3,t=255&this.vramAddress,this.cntVT=24&this.cntVT|t>>5&7,this.cntHT=31&t},regsToAddress:function(){var t=(7&this.regFV)<<4;t|=(1&this.regV)<<3,t|=(1&this.regH)<<2,t|=this.regVT>>3&3;var s=(7&this.regVT)<<5;s|=31&this.regHT,this.vramTmpAddress=32767&(t<<8|s)},cntsToAddress:function(){var t=(7&this.cntFV)<<4;t|=(1&this.cntV)<<3,t|=(1&this.cntH)<<2,t|=this.cntVT>>3&3;var s=(7&this.cntVT)<<5;s|=31&this.cntHT,this.vramAddress=32767&(t<<8|s)},incTileCounter:function(t){for(var s=t;0!==s;s--)32===++this.cntHT&&(this.cntHT=0,++this.cntVT>=30&&2===++this.cntH&&(this.cntH=0,2===++this.cntV&&(this.cntV=0,this.cntFV++,this.cntFV&=7)))},mirroredLoad:function(t){return this.vramMem[this.vramMirrorTable[t]]},mirroredWrite:function(t,s){if(t>=16128&&t<16160)16128===t||16144===t?(this.writeMem(16128,s),this.writeMem(16144,s)):16132===t||16148===t?(this.writeMem(16132,s),this.writeMem(16148,s)):16136===t||16152===t?(this.writeMem(16136,s),this.writeMem(16152,s)):16140===t||16156===t?(this.writeMem(16140,s),this.writeMem(16156,s)):this.writeMem(t,s);else{if(!(t=21&&this.scanline<=260&&(this.renderFramePartially(this.lastRenderedScanline+1,this.scanline-21-this.lastRenderedScanline),this.lastRenderedScanline=this.scanline-21)},renderFramePartially:function(t,s){if(1===this.f_spVisibility&&this.renderSpritesPartially(t,s,!0),1===this.f_bgVisibility){var i=t<<8,e=t+s<<8;e>61440&&(e=61440);for(var h=this.buffer,r=this.bgbuffer,n=this.pixrendered,a=i;a255&&(h[a]=r[a])}1===this.f_spVisibility&&this.renderSpritesPartially(t,s,!1),this.validTileData=!1},renderBgScanline:function(t,s){var i=0===this.regS?0:256,e=(s<<8)-this.regFH;if(this.curNt=this.ntable1[this.cntV+this.cntV+this.cntH],this.cntHT=this.regHT,this.cntH=this.regH,this.curNt=this.ntable1[this.cntV+this.cntV+this.cntH],s<240&&s-this.cntFV>=0){for(var h,r,n,a,o=this.cntFV<<3,l=this.scantile,p=this.attrib,u=this.ptTile,m=this.nameTable,R=this.imgPalette,c=this.pixrendered,_=t?this.bgbuffer:this.buffer,d=0;d<32;d++){if(s>=0){if(this.validTileData){if(void 0===(h=l[d]))continue;r=h.pix,n=p[d]}else{if(void 0===(h=u[i+m[this.curNt].getTileIndex(this.cntHT,this.cntVT)]))continue;r=h.pix,n=m[this.curNt].getAttrib(this.cntHT,this.cntVT),l[d]=h,p[d]=n}var S=0,A=(d<<3)-this.regFH;if(A>-8)if(A<0&&(e-=A,S=-A),h.opaque[this.cntFV])for(;S<8;S++)_[e]=R[r[o+S]+n],c[e]|=256,e++;else for(;S<8;S++)a=r[o+S],0!==a&&(_[e]=R[a+n],c[e]|=256),e++}32==++this.cntHT&&(this.cntHT=0,this.cntH++,this.cntH%=2,this.curNt=this.ntable1[(this.cntV<<1)+this.cntH])}this.validTileData=!0}8===++this.cntFV&&(this.cntFV=0,this.cntVT++,30===this.cntVT?(this.cntVT=0,this.cntV++,this.cntV%=2,this.curNt=this.ntable1[(this.cntV<<1)+this.cntH]):32===this.cntVT&&(this.cntVT=0),this.validTileData=!1)},renderSpritesPartially:function(t,s,i){if(1===this.f_spVisibility)for(var e=0;e<64;e++)if(this.bgPriority[e]===i&&this.sprX[e]>=0&&this.sprX[e]<256&&this.sprY[e]+8>=t&&this.sprY[e]t+s&&(this.srcy2=t+s-this.sprY[e]+1),0===this.f_spPatternTable?this.ptTile[this.sprTile[e]].render(this.buffer,0,this.srcy1,8,this.srcy2,this.sprX[e],this.sprY[e]+1,this.sprCol[e],this.sprPalette,this.horiFlip[e],this.vertFlip[e],e,this.pixrendered):this.ptTile[this.sprTile[e]+256].render(this.buffer,0,this.srcy1,8,this.srcy2,this.sprX[e],this.sprY[e]+1,this.sprCol[e],this.sprPalette,this.horiFlip[e],this.vertFlip[e],e,this.pixrendered);else{var h=this.sprTile[e];0!=(1&h)&&(h=this.sprTile[e]-1+256);var r=0,n=8;this.sprY[e]t+s&&(n=t+s-this.sprY[e]),this.ptTile[h+(this.vertFlip[e]?1:0)].render(this.buffer,0,r,8,n,this.sprX[e],this.sprY[e]+1,this.sprCol[e],this.sprPalette,this.horiFlip[e],this.vertFlip[e],e,this.pixrendered),r=0,n=8,this.sprY[e]+8t+s&&(n=t+s-(this.sprY[e]+8)),this.ptTile[h+(this.vertFlip[e]?0:1)].render(this.buffer,0,r,8,n,this.sprX[e],this.sprY[e]+1+8,this.sprCol[e],this.sprPalette,this.horiFlip[e],this.vertFlip[e],e,this.pixrendered)}},checkSprite0:function(t){this.spr0HitX=-1,this.spr0HitY=-1;var s,i,e,h,r,n,a=0===this.f_spPatternTable?0:256;if(i=this.sprX[0],e=this.sprY[0]+1,0===this.f_spriteSize){if(e<=t&&e+8>t&&i>=-7&&i<256)if(h=this.ptTile[this.sprTile[0]+a],s=this.vertFlip[0]?7-(t-e):t-e,s*=8,n=256*t+i,this.horiFlip[0])for(r=7;r>=0;r--){if(i>=0&&i<256&&n>=0&&n<61440&&0!==this.pixrendered[n]&&0!==h.pix[s+r])return this.spr0HitX=n%256,this.spr0HitY=t,!0;i++,n++}else for(r=0;r<8;r++){if(i>=0&&i<256&&n>=0&&n<61440&&0!==this.pixrendered[n]&&0!==h.pix[s+r])return this.spr0HitX=n%256,this.spr0HitY=t,!0;i++,n++}}else if(e<=t&&e+16>t&&i>=-7&&i<256)if(s=this.vertFlip[0]?15-(t-e):t-e,s<8?h=this.ptTile[this.sprTile[0]+(this.vertFlip[0]?1:0)+(0!=(1&this.sprTile[0])?255:0)]:(h=this.ptTile[this.sprTile[0]+(this.vertFlip[0]?0:1)+(0!=(1&this.sprTile[0])?255:0)],this.vertFlip[0]?s=15-s:s-=8),s*=8,n=256*t+i,this.horiFlip[0])for(r=7;r>=0;r--){if(i>=0&&i<256&&n>=0&&n<61440&&0!==this.pixrendered[n]&&0!==h.pix[s+r])return this.spr0HitX=n%256,this.spr0HitY=t,!0;i++,n++}else for(r=0;r<8;r++){if(i>=0&&i<256&&n>=0&&n<61440&&0!==this.pixrendered[n]&&0!==h.pix[s+r])return this.spr0HitX=n%256,this.spr0HitY=t,!0;i++,n++}return!1},writeMem:function(t,s){this.vramMem[t]=s,t<8192?(this.vramMem[t]=s,this.patternWrite(t,s)):t>=8192&&t<9152?this.nameTableWrite(this.ntable1[0],t-8192,s):t>=9152&&t<9216?this.attribTableWrite(this.ntable1[0],t-9152,s):t>=9216&&t<10176?this.nameTableWrite(this.ntable1[1],t-9216,s):t>=10176&&t<10240?this.attribTableWrite(this.ntable1[1],t-10176,s):t>=10240&&t<11200?this.nameTableWrite(this.ntable1[2],t-10240,s):t>=11200&&t<11264?this.attribTableWrite(this.ntable1[2],t-11200,s):t>=11264&&t<12224?this.nameTableWrite(this.ntable1[3],t-11264,s):t>=12224&&t<12288?this.attribTableWrite(this.ntable1[3],t-12224,s):t>=16128&&t<16160&&this.updatePalettes()},updatePalettes:function(){var t;for(t=0;t<16;t++)0===this.f_dispType?this.imgPalette[t]=this.palTable.getEntry(63&this.vramMem[16128+t]):this.imgPalette[t]=this.palTable.getEntry(32&this.vramMem[16128+t]);for(t=0;t<16;t++)0===this.f_dispType?this.sprPalette[t]=this.palTable.getEntry(63&this.vramMem[16144+t]):this.sprPalette[t]=this.palTable.getEntry(32&this.vramMem[16144+t])},patternWrite:function(t,s){var i=Math.floor(t/16),e=t%16;e<8?this.ptTile[i].setScanline(e,s,this.vramMem[t+8]):this.ptTile[i].setScanline(e-8,this.vramMem[t-8],s)},nameTableWrite:function(t,s,i){this.nameTable[t].tile[s]=i,this.checkSprite0(this.scanline-20)},attribTableWrite:function(t,s,i){this.nameTable[t].writeAttrib(s,i)},spriteRamWriteUpdate:function(t,s){var i=Math.floor(t/4);0===i&&this.checkSprite0(this.scanline-20),t%4==0?this.sprY[i]=s:t%4==1?this.sprTile[i]=s:t%4==2?(this.vertFlip[i]=0!=(128&s),this.horiFlip[i]=0!=(64&s),this.bgPriority[i]=0!=(32&s),this.sprCol[i]=(3&s)<<2):t%4==3&&(this.sprX[i]=s)},doNMI:function(){this.setStatusFlag(this.STATUS_VBLANK,!0),this.nes.cpu.requestIrq(this.nes.cpu.IRQ_NMI)},isPixelWhite:function(t,s){return this.triggerRendering(),16777215===this.nes.ppu.buffer[(s<<8)+t]},JSON_PROPERTIES:["vramMem","spriteMem","cntFV","cntV","cntH","cntVT","cntHT","regFV","regV","regH","regVT","regHT","regFH","regS","vramAddress","vramTmpAddress","f_nmiOnVblank","f_spriteSize","f_bgPatternTable","f_spPatternTable","f_addrInc","f_nTblAddress","f_color","f_spVisibility","f_bgVisibility","f_spClipping","f_bgClipping","f_dispType","vramBufferedReadValue","firstWrite","currentMirroring","vramMirrorTable","ntable1","sramAddress","hitSpr0","sprPalette","imgPalette","curX","scanline","lastRenderedScanline","curNt","scantile","attrib","buffer","bgbuffer","pixrendered","requestEndFrame","nmiOk","dummyCycleToggle","nmiCounter","validTileData","scanlineAlreadyRendered"],toJSON:function(){var t,s=h.toJSON(this);for(s.nameTable=[],t=0;t>2*(2*o+l)&3;for(var p=0;p<2;p++)for(var u=0;u<2;u++)e=n+2*l+u,h=a+2*o+p,r=h*this.width+e,this.attrib[r]=i<<2&12}},toJSON:function(){return{tile:this.tile,attrib:this.attrib}},fromJSON:function(t){this.tile=t.tile,this.attrib=t.attrib}};var a=function(){this.curTable=new Array(64),this.emphTable=new Array(8),this.currentEmph=-1};a.prototype={reset:function(){this.setEmphasis(0)},loadNTSCPalette:function(){this.curTable=[5395026,11796480,10485760,11599933,7602281,91,95,6208,12048,543240,26368,1196544,7153664,0,0,0,12899815,16728064,14421538,16729963,14090399,6818519,6588,21681,27227,35843,43776,2918400,10777088,0,0,0,16316664,16755516,16742785,16735173,16730354,14633471,4681215,46327,57599,58229,259115,7911470,15065624,7895160,0,0,16777215,16773822,16300216,16300248,16758527,16761855,13095423,10148607,8973816,8650717,12122296,16119980,16777136,16308472,0,0],this.makeTables(),this.setEmphasis(0)},loadPALPalette:function(){this.curTable=[5395026,11796480,10485760,11599933,7602281,91,95,6208,12048,543240,26368,1196544,7153664,0,0,0,12899815,16728064,14421538,16729963,14090399,6818519,6588,21681,27227,35843,43776,2918400,10777088,0,0,0,16316664,16755516,16742785,16735173,16730354,14633471,4681215,46327,57599,58229,259115,7911470,15065624,7895160,0,0,16777215,16773822,16300216,16300248,16758527,16761855,13095423,10148607,8973816,8650717,12122296,16119980,16777136,16308472,0,0],this.makeTables(),this.setEmphasis(0)},makeTables:function(){for(var t,s,i,e,h,r,n,a,o=0;o<8;o++)for(r=1,n=1,a=1,0!=(1&o)&&(r=.75,a=.75),0!=(2&o)&&(r=.75,n=.75),0!=(4&o)&&(n=.75,a=.75),this.emphTable[o]=new Array(64),h=0;h<64;h++)e=this.curTable[h],t=Math.floor(this.getRed(e)*r),s=Math.floor(this.getGreen(e)*n),i=Math.floor(this.getBlue(e)*a),this.emphTable[o][h]=this.getRgb(t,s,i)},setEmphasis:function(t){if(t!==this.currentEmph){this.currentEmph=t;for(var s=0;s<64;s++)this.curTable[s]=this.emphTable[t][s]}},getEntry:function(t){return this.curTable[t]},getRed:function(t){return t>>16&255},getGreen:function(t){return t>>8&255},getBlue:function(t){return 255&t},getRgb:function(t,s,i){return t<<16|s<<8|i},loadDefaultPalette:function(){this.curTable[0]=this.getRgb(117,117,117),this.curTable[1]=this.getRgb(39,27,143),this.curTable[2]=this.getRgb(0,0,171),this.curTable[3]=this.getRgb(71,0,159),this.curTable[4]=this.getRgb(143,0,119),this.curTable[5]=this.getRgb(171,0,19),this.curTable[6]=this.getRgb(167,0,0),this.curTable[7]=this.getRgb(127,11,0),this.curTable[8]=this.getRgb(67,47,0),this.curTable[9]=this.getRgb(0,71,0),this.curTable[10]=this.getRgb(0,81,0),this.curTable[11]=this.getRgb(0,63,23),this.curTable[12]=this.getRgb(27,63,95),this.curTable[13]=this.getRgb(0,0,0),this.curTable[14]=this.getRgb(0,0,0),this.curTable[15]=this.getRgb(0,0,0),this.curTable[16]=this.getRgb(188,188,188),this.curTable[17]=this.getRgb(0,115,239),this.curTable[18]=this.getRgb(35,59,239),this.curTable[19]=this.getRgb(131,0,243),this.curTable[20]=this.getRgb(191,0,191),this.curTable[21]=this.getRgb(231,0,91),this.curTable[22]=this.getRgb(219,43,0),this.curTable[23]=this.getRgb(203,79,15),this.curTable[24]=this.getRgb(139,115,0),this.curTable[25]=this.getRgb(0,151,0),this.curTable[26]=this.getRgb(0,171,0),this.curTable[27]=this.getRgb(0,147,59),this.curTable[28]=this.getRgb(0,131,139),this.curTable[29]=this.getRgb(0,0,0),this.curTable[30]=this.getRgb(0,0,0),this.curTable[31]=this.getRgb(0,0,0),this.curTable[32]=this.getRgb(255,255,255),this.curTable[33]=this.getRgb(63,191,255),this.curTable[34]=this.getRgb(95,151,255),this.curTable[35]=this.getRgb(167,139,253),this.curTable[36]=this.getRgb(247,123,255),this.curTable[37]=this.getRgb(255,119,183),this.curTable[38]=this.getRgb(255,119,99),this.curTable[39]=this.getRgb(255,155,59),this.curTable[40]=this.getRgb(243,191,63),this.curTable[41]=this.getRgb(131,211,19),this.curTable[42]=this.getRgb(79,223,75),this.curTable[43]=this.getRgb(88,248,152),this.curTable[44]=this.getRgb(0,235,219),this.curTable[45]=this.getRgb(0,0,0),this.curTable[46]=this.getRgb(0,0,0),this.curTable[47]=this.getRgb(0,0,0),this.curTable[48]=this.getRgb(255,255,255),this.curTable[49]=this.getRgb(171,231,255),this.curTable[50]=this.getRgb(199,215,255),this.curTable[51]=this.getRgb(215,203,255),this.curTable[52]=this.getRgb(255,199,255),this.curTable[53]=this.getRgb(255,199,219),this.curTable[54]=this.getRgb(255,191,179),this.curTable[55]=this.getRgb(255,219,171),this.curTable[56]=this.getRgb(255,231,163),this.curTable[57]=this.getRgb(227,255,163),this.curTable[58]=this.getRgb(171,243,191),this.curTable[59]=this.getRgb(179,255,207),this.curTable[60]=this.getRgb(159,255,243),this.curTable[61]=this.getRgb(0,0,0),this.curTable[62]=this.getRgb(0,0,0),this.curTable[63]=this.getRgb(0,0,0),this.makeTables(),this.setEmphasis(0)}},t.exports=r},function(t,s){var i=function(t){this.nes=t,this.square1=new r(this,!0),this.square2=new r(this,!1),this.triangle=new n(this),this.noise=new h(this),this.dmc=new e(this),this.frameIrqCounter=null,this.frameIrqCounterMax=4,this.initCounter=2048,this.channelEnableValue=null,this.sampleRate=44100,this.lengthLookup=null,this.dmcFreqLookup=null,this.noiseWavelengthLookup=null,this.square_table=null,this.tnd_table=null,this.frameIrqEnabled=!1,this.frameIrqActive=null,this.frameClockNow=null,this.startedPlaying=!1,this.recordOutput=!1,this.initingHardware=!1,this.masterFrameCounter=null,this.derivedFrameCounter=null,this.countSequence=null,this.sampleTimer=null,this.frameTime=null,this.sampleTimerMax=null,this.sampleCount=null,this.triValue=0,this.smpSquare1=null,this.smpSquare2=null,this.smpTriangle=null,this.smpDmc=null,this.accCount=null,this.prevSampleL=0,this.prevSampleR=0,this.smpAccumL=0,this.smpAccumR=0,this.dacRange=0,this.dcValue=0,this.masterVolume=256,this.stereoPosLSquare1=null,this.stereoPosLSquare2=null,this.stereoPosLTriangle=null,this.stereoPosLNoise=null,this.stereoPosLDMC=null,this.stereoPosRSquare1=null,this.stereoPosRSquare2=null,this.stereoPosRTriangle=null,this.stereoPosRNoise=null,this.stereoPosRDMC=null,this.extraCycles=null,this.maxSample=null,this.minSample=null,this.panning=[80,170,100,150,128],this.setPanning(this.panning),this.initLengthLookup(),this.initDmcFrequencyLookup(),this.initNoiseWavelengthLookup(),this.initDACtables();for(var s=0;s<20;s++)16===s?this.writeReg(16400,16):this.writeReg(16384+s,0);this.reset()};i.prototype={reset:function(){this.sampleRate=this.nes.opts.sampleRate,this.sampleTimerMax=Math.floor(1832727040*this.nes.opts.preferredFrameRate/(60*this.sampleRate)),this.frameTime=Math.floor(14915*this.nes.opts.preferredFrameRate/60),this.sampleTimer=0,this.updateChannelEnable(0),this.masterFrameCounter=0,this.derivedFrameCounter=0,this.countSequence=0,this.sampleCount=0,this.initCounter=2048,this.frameIrqEnabled=!1,this.initingHardware=!1,this.resetCounter(),this.square1.reset(),this.square2.reset(),this.triangle.reset(),this.noise.reset(),this.dmc.reset(),this.accCount=0,this.smpSquare1=0,this.smpSquare2=0,this.smpTriangle=0,this.smpDmc=0,this.frameIrqEnabled=!1,this.frameIrqCounterMax=4,this.channelEnableValue=255,this.startedPlaying=!1,this.prevSampleL=0,this.prevSampleR=0,this.smpAccumL=0,this.smpAccumR=0,this.maxSample=-5e5,this.minSample=5e5},readReg:function(t){var s=0;return s|=this.square1.getLengthStatus(),s|=this.square2.getLengthStatus()<<1,s|=this.triangle.getLengthStatus()<<2,s|=this.noise.getLengthStatus()<<3,s|=this.dmc.getLengthStatus()<<4,s|=(this.frameIrqActive&&this.frameIrqEnabled?1:0)<<6,s|=this.dmc.getIrqStatus()<<7,this.frameIrqActive=!1,this.dmc.irqGenerated=!1,65535&s},writeReg:function(t,s){t>=16384&&t<16388?this.square1.writeReg(t,s):t>=16388&&t<16392?this.square2.writeReg(t,s):t>=16392&&t<16396?this.triangle.writeReg(t,s):t>=16396&&t<=16399?this.noise.writeReg(t,s):16400===t?this.dmc.writeReg(t,s):16401===t?this.dmc.writeReg(t,s):16402===t?this.dmc.writeReg(t,s):16403===t?this.dmc.writeReg(t,s):16405===t?(this.updateChannelEnable(s),0!==s&&this.initCounter>0&&(this.initingHardware=!0),this.dmc.writeReg(t,s)):16407===t&&(this.countSequence=s>>7&1,this.masterFrameCounter=0,this.frameIrqActive=!1,this.frameIrqEnabled=0==(s>>6&1),0===this.countSequence?(this.frameIrqCounterMax=4,this.derivedFrameCounter=4):(this.frameIrqCounterMax=5,this.derivedFrameCounter=0,this.frameCounterTick()))},resetCounter:function(){0===this.countSequence?this.derivedFrameCounter=4:this.derivedFrameCounter=0},updateChannelEnable:function(t){this.channelEnableValue=65535&t,this.square1.setEnabled(0!=(1&t)),this.square2.setEnabled(0!=(2&t)),this.triangle.setEnabled(0!=(4&t)),this.noise.setEnabled(0!=(8&t)),this.dmc.setEnabled(0!=(16&t))},clockFrameCounter:function(t){if(this.initCounter>0&&this.initingHardware)return this.initCounter-=t,void(this.initCounter<=0&&(this.initingHardware=!1));t+=this.extraCycles;var s=this.sampleTimerMax-this.sampleTimer;t<<10>s?(this.extraCycles=(t<<10)-s>>10,t-=this.extraCycles):this.extraCycles=0;var i=this.dmc,e=this.triangle,h=this.square1,r=this.square2,n=this.noise;if(i.isEnabled)for(i.shiftCounter-=t<<3;i.shiftCounter<=0&&i.dmaFrequency>0;)i.shiftCounter+=i.dmaFrequency,i.clockDmc();if(e.progTimerMax>0)for(e.progTimerCount-=t;e.progTimerCount<=0;)e.progTimerCount+=e.progTimerMax+1,e.linearCounter>0&&e.lengthCounter>0&&(e.triangleCounter++,e.triangleCounter&=31,e.isEnabled&&(e.triangleCounter>=16?e.sampleValue=15&e.triangleCounter:e.sampleValue=15-(15&e.triangleCounter),e.sampleValue<<=4));h.progTimerCount-=t,h.progTimerCount<=0&&(h.progTimerCount+=h.progTimerMax+1<<1,h.squareCounter++,h.squareCounter&=7,h.updateSampleValue()),r.progTimerCount-=t,r.progTimerCount<=0&&(r.progTimerCount+=r.progTimerMax+1<<1,r.squareCounter++,r.squareCounter&=7,r.updateSampleValue());var a=t;if(n.progTimerCount-a>0)n.progTimerCount-=a,n.accCount+=a,n.accValue+=a*n.sampleValue;else for(;a-- >0;)--n.progTimerCount<=0&&n.progTimerMax>0&&(n.shiftReg<<=1,n.tmp=32768&(n.shiftReg<<(0===n.randomMode?1:6)^n.shiftReg),0!==n.tmp?(n.shiftReg|=1,n.randomBit=0,n.sampleValue=0):(n.randomBit=1,n.isEnabled&&n.lengthCounter>0?n.sampleValue=n.masterVolume:n.sampleValue=0),n.progTimerCount+=n.progTimerMax),n.accValue+=n.sampleValue,n.accCount++;this.frameIrqEnabled&&this.frameIrqActive&&this.nes.cpu.requestIrq(this.nes.cpu.IRQ_NORMAL),this.masterFrameCounter+=t<<1,this.masterFrameCounter>=this.frameTime&&(this.masterFrameCounter-=this.frameTime,this.frameCounterTick()),this.accSample(t),this.sampleTimer+=t<<10,this.sampleTimer>=this.sampleTimerMax&&(this.sample(),this.sampleTimer-=this.sampleTimerMax)},accSample:function(t){this.triangle.sampleCondition&&(this.triValue=Math.floor((this.triangle.progTimerCount<<4)/(this.triangle.progTimerMax+1)),this.triValue>16&&(this.triValue=16),this.triangle.triangleCounter>=16&&(this.triValue=16-this.triValue),this.triValue+=this.triangle.sampleValue),2===t?(this.smpTriangle+=this.triValue<<1,this.smpDmc+=this.dmc.sample<<1,this.smpSquare1+=this.square1.sampleValue<<1,this.smpSquare2+=this.square2.sampleValue<<1,this.accCount+=2):4===t?(this.smpTriangle+=this.triValue<<2,this.smpDmc+=this.dmc.sample<<2,this.smpSquare1+=this.square1.sampleValue<<2,this.smpSquare2+=this.square2.sampleValue<<2,this.accCount+=4):(this.smpTriangle+=t*this.triValue,this.smpDmc+=t*this.dmc.sample,this.smpSquare1+=t*this.square1.sampleValue,this.smpSquare2+=t*this.square2.sampleValue,this.accCount+=t)},frameCounterTick:function(){this.derivedFrameCounter++,this.derivedFrameCounter>=this.frameIrqCounterMax&&(this.derivedFrameCounter=0),1!==this.derivedFrameCounter&&3!==this.derivedFrameCounter||(this.triangle.clockLengthCounter(),this.square1.clockLengthCounter(),this.square2.clockLengthCounter(),this.noise.clockLengthCounter(),this.square1.clockSweep(),this.square2.clockSweep()),this.derivedFrameCounter>=0&&this.derivedFrameCounter<4&&(this.square1.clockEnvDecay(),this.square2.clockEnvDecay(),this.noise.clockEnvDecay(),this.triangle.clockLinearCounter()),3===this.derivedFrameCounter&&0===this.countSequence&&(this.frameIrqActive=!0)},sample:function(){var t,s;this.accCount>0?(this.smpSquare1<<=4,this.smpSquare1=Math.floor(this.smpSquare1/this.accCount),this.smpSquare2<<=4,this.smpSquare2=Math.floor(this.smpSquare2/this.accCount),this.smpTriangle=Math.floor(this.smpTriangle/this.accCount),this.smpDmc<<=4,this.smpDmc=Math.floor(this.smpDmc/this.accCount),this.accCount=0):(this.smpSquare1=this.square1.sampleValue<<4,this.smpSquare2=this.square2.sampleValue<<4,this.smpTriangle=this.triangle.sampleValue,this.smpDmc=this.dmc.sample<<4);var i=Math.floor((this.noise.accValue<<4)/this.noise.accCount);this.noise.accValue=i>>4,this.noise.accCount=1,t=this.smpSquare1*this.stereoPosLSquare1+this.smpSquare2*this.stereoPosLSquare2>>8,s=3*this.smpTriangle*this.stereoPosLTriangle+(i<<1)*this.stereoPosLNoise+this.smpDmc*this.stereoPosLDMC>>8,t>=this.square_table.length&&(t=this.square_table.length-1),s>=this.tnd_table.length&&(s=this.tnd_table.length-1);var e=this.square_table[t]+this.tnd_table[s]-this.dcValue;t=this.smpSquare1*this.stereoPosRSquare1+this.smpSquare2*this.stereoPosRSquare2>>8,s=3*this.smpTriangle*this.stereoPosRTriangle+(i<<1)*this.stereoPosRNoise+this.smpDmc*this.stereoPosRDMC>>8,t>=this.square_table.length&&(t=this.square_table.length-1),s>=this.tnd_table.length&&(s=this.tnd_table.length-1);var h=this.square_table[t]+this.tnd_table[s]-this.dcValue,r=e-this.prevSampleL;this.prevSampleL+=r,this.smpAccumL+=r-(this.smpAccumL>>10),e=this.smpAccumL;var n=h-this.prevSampleR;this.prevSampleR+=n,this.smpAccumR+=n-(this.smpAccumR>>10),h=this.smpAccumR,e>this.maxSample&&(this.maxSample=e),e>3]},getDmcFrequency:function(t){return t>=0&&t<16?this.dmcFreqLookup[t]:0},getNoiseWaveLength:function(t){return t>=0&&t<16?this.noiseWavelengthLookup[t]:0},setPanning:function(t){for(var s=0;s<5;s++)this.panning[s]=t[s];this.updateStereoPos()},setMasterVolume:function(t){t<0&&(t=0),t>256&&(t=256),this.masterVolume=t,this.updateStereoPos()},updateStereoPos:function(){this.stereoPosLSquare1=this.panning[0]*this.masterVolume>>8,this.stereoPosLSquare2=this.panning[1]*this.masterVolume>>8,this.stereoPosLTriangle=this.panning[2]*this.masterVolume>>8,this.stereoPosLNoise=this.panning[3]*this.masterVolume>>8,this.stereoPosLDMC=this.panning[4]*this.masterVolume>>8,this.stereoPosRSquare1=this.masterVolume-this.stereoPosLSquare1,this.stereoPosRSquare2=this.masterVolume-this.stereoPosLSquare2,this.stereoPosRTriangle=this.masterVolume-this.stereoPosLTriangle,this.stereoPosRNoise=this.masterVolume-this.stereoPosLNoise,this.stereoPosRDMC=this.masterVolume-this.stereoPosLDMC},initLengthLookup:function(){this.lengthLookup=[10,254,20,2,40,4,80,6,160,8,60,10,14,12,26,14,12,16,24,18,48,20,96,22,192,24,72,26,16,28,32,30]},initDmcFrequencyLookup:function(){this.dmcFreqLookup=new Array(16),this.dmcFreqLookup[0]=3424,this.dmcFreqLookup[1]=3040,this.dmcFreqLookup[2]=2720,this.dmcFreqLookup[3]=2560,this.dmcFreqLookup[4]=2288,this.dmcFreqLookup[5]=2032,this.dmcFreqLookup[6]=1808,this.dmcFreqLookup[7]=1712,this.dmcFreqLookup[8]=1520,this.dmcFreqLookup[9]=1280,this.dmcFreqLookup[10]=1136,this.dmcFreqLookup[11]=1024,this.dmcFreqLookup[12]=848,this.dmcFreqLookup[13]=672,this.dmcFreqLookup[14]=576,this.dmcFreqLookup[15]=432},initNoiseWavelengthLookup:function(){this.noiseWavelengthLookup=new Array(16),this.noiseWavelengthLookup[0]=4,this.noiseWavelengthLookup[1]=8,this.noiseWavelengthLookup[2]=16,this.noiseWavelengthLookup[3]=32,this.noiseWavelengthLookup[4]=64,this.noiseWavelengthLookup[5]=96,this.noiseWavelengthLookup[6]=128,this.noiseWavelengthLookup[7]=160,this.noiseWavelengthLookup[8]=202,this.noiseWavelengthLookup[9]=254,this.noiseWavelengthLookup[10]=380,this.noiseWavelengthLookup[11]=508,this.noiseWavelengthLookup[12]=762,this.noiseWavelengthLookup[13]=1016,this.noiseWavelengthLookup[14]=2034,this.noiseWavelengthLookup[15]=4068},initDACtables:function(){var t,s,i,e=0,h=0;for(this.square_table=new Array(512),this.tnd_table=new Array(3264),i=0;i<512;i++)t=95.52/(8128/(i/16)+100),t*=.98411,t*=5e4,s=Math.floor(t),this.square_table[i]=s,s>e&&(e=s);for(i=0;i<3264;i++)t=163.67/(24329/(i/16)+100),t*=.98411,t*=5e4,s=Math.floor(t),this.tnd_table[i]=s,s>h&&(h=s);this.dacRange=e+h,this.dcValue=this.dacRange/2}};var e=function(t){this.papu=t,this.MODE_NORMAL=0,this.MODE_LOOP=1,this.MODE_IRQ=2,this.isEnabled=null,this.hasSample=null,this.irqGenerated=!1,this.playMode=null,this.dmaFrequency=null,this.dmaCounter=null,this.deltaCounter=null,this.playStartAddress=null,this.playAddress=null,this.playLength=null,this.playLengthCounter=null,this.shiftCounter=null,this.reg4012=null,this.reg4013=null,this.sample=null,this.dacLsb=null,this.data=null,this.reset()};e.prototype={clockDmc:function(){this.hasSample&&(0==(1&this.data)?this.deltaCounter>0&&this.deltaCounter--:this.deltaCounter<63&&this.deltaCounter++,this.sample=this.isEnabled?(this.deltaCounter<<1)+this.dacLsb:0,this.data>>=1),this.dmaCounter--,this.dmaCounter<=0&&(this.hasSample=!1,this.endOfSample(),this.dmaCounter=8),this.irqGenerated&&this.papu.nes.cpu.requestIrq(this.papu.nes.cpu.IRQ_NORMAL)},endOfSample:function(){0===this.playLengthCounter&&this.playMode===this.MODE_LOOP&&(this.playAddress=this.playStartAddress,this.playLengthCounter=this.playLength),this.playLengthCounter>0&&(this.nextSample(),0===this.playLengthCounter&&this.playMode===this.MODE_IRQ&&(this.irqGenerated=!0))},nextSample:function(){this.data=this.papu.nes.mmap.load(this.playAddress),this.papu.nes.cpu.haltCycles(4),this.playLengthCounter--,this.playAddress++,this.playAddress>65535&&(this.playAddress=32768),this.hasSample=!0},writeReg:function(t,s){16400===t?(s>>6==0?this.playMode=this.MODE_NORMAL:1==(s>>6&1)?this.playMode=this.MODE_LOOP:s>>6==2&&(this.playMode=this.MODE_IRQ),0==(128&s)&&(this.irqGenerated=!1),this.dmaFrequency=this.papu.getDmcFrequency(15&s)):16401===t?(this.deltaCounter=s>>1&63,this.dacLsb=1&s,this.sample=(this.deltaCounter<<1)+this.dacLsb):16402===t?(this.playStartAddress=s<<6|49152,this.playAddress=this.playStartAddress,this.reg4012=s):16403===t?(this.playLength=1+(s<<4),this.playLengthCounter=this.playLength,this.reg4013=s):16405===t&&(0==(s>>4&1)?this.playLengthCounter=0:(this.playAddress=this.playStartAddress,this.playLengthCounter=this.playLength),this.irqGenerated=!1)},setEnabled:function(t){!this.isEnabled&&t&&(this.playLengthCounter=this.playLength),this.isEnabled=t},getLengthStatus:function(){return 0!==this.playLengthCounter&&this.isEnabled?1:0},getIrqStatus:function(){return this.irqGenerated?1:0},reset:function(){this.isEnabled=!1,this.irqGenerated=!1,this.playMode=this.MODE_NORMAL,this.dmaFrequency=0,this.dmaCounter=0,this.deltaCounter=0,this.playStartAddress=0,this.playAddress=0,this.playLength=0,this.playLengthCounter=0,this.sample=0,this.dacLsb=0,this.shiftCounter=0,this.reg4012=0,this.reg4013=0,this.data=0}};var h=function(t){this.papu=t,this.isEnabled=null,this.envDecayDisable=null,this.envDecayLoopEnable=null,this.lengthCounterEnable=null,this.envReset=null,this.shiftNow=null,this.lengthCounter=null,this.progTimerCount=null,this.progTimerMax=null,this.envDecayRate=null,this.envDecayCounter=null,this.envVolume=null,this.masterVolume=null,this.shiftReg=16384,this.randomBit=null,this.randomMode=null,this.sampleValue=null,this.accValue=0,this.accCount=1,this.tmp=null,this.reset()};h.prototype={reset:function(){this.progTimerCount=0,this.progTimerMax=0,this.isEnabled=!1,this.lengthCounter=0,this.lengthCounterEnable=!1,this.envDecayDisable=!1,this.envDecayLoopEnable=!1,this.shiftNow=!1,this.envDecayRate=0,this.envDecayCounter=0,this.envVolume=0,this.masterVolume=0,this.shiftReg=1,this.randomBit=0,this.randomMode=0,this.sampleValue=0,this.tmp=0},clockLengthCounter:function(){this.lengthCounterEnable&&this.lengthCounter>0&&0===--this.lengthCounter&&this.updateSampleValue()},clockEnvDecay:function(){this.envReset?(this.envReset=!1,this.envDecayCounter=this.envDecayRate+1,this.envVolume=15):--this.envDecayCounter<=0&&(this.envDecayCounter=this.envDecayRate+1,this.envVolume>0?this.envVolume--:this.envVolume=this.envDecayLoopEnable?15:0),this.envDecayDisable?this.masterVolume=this.envDecayRate:this.masterVolume=this.envVolume,this.updateSampleValue()},updateSampleValue:function(){this.isEnabled&&this.lengthCounter>0&&(this.sampleValue=this.randomBit*this.masterVolume)},writeReg:function(t,s){16396===t?(this.envDecayDisable=0!=(16&s),this.envDecayRate=15&s,this.envDecayLoopEnable=0!=(32&s),this.lengthCounterEnable=0==(32&s),this.envDecayDisable?this.masterVolume=this.envDecayRate:this.masterVolume=this.envVolume):16398===t?(this.progTimerMax=this.papu.getNoiseWaveLength(15&s),this.randomMode=s>>7):16399===t&&(this.lengthCounter=this.papu.getLengthMax(248&s),this.envReset=!0)},setEnabled:function(t){this.isEnabled=t,t||(this.lengthCounter=0),this.updateSampleValue()},getLengthStatus:function(){return 0!==this.lengthCounter&&this.isEnabled?1:0}};var r=function(t,s){this.papu=t,this.dutyLookup=[0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,1,0,0,0,1,0,0,1,1,1,1,1],this.impLookup=[1,-1,0,0,0,0,0,0,1,0,-1,0,0,0,0,0,1,0,0,0,-1,0,0,0,-1,0,1,0,0,0,0,0],this.sqr1=s,this.isEnabled=null,this.lengthCounterEnable=null,this.sweepActive=null,this.envDecayDisable=null,this.envDecayLoopEnable=null,this.envReset=null,this.sweepCarry=null,this.updateSweepPeriod=null,this.progTimerCount=null,this.progTimerMax=null,this.lengthCounter=null,this.squareCounter=null,this.sweepCounter=null,this.sweepCounterMax=null,this.sweepMode=null,this.sweepShiftAmount=null,this.envDecayRate=null,this.envDecayCounter=null,this.envVolume=null,this.masterVolume=null,this.dutyMode=null,this.sweepResult=null,this.sampleValue=null,this.vol=null,this.reset()};r.prototype={reset:function(){this.progTimerCount=0,this.progTimerMax=0,this.lengthCounter=0,this.squareCounter=0,this.sweepCounter=0,this.sweepCounterMax=0,this.sweepMode=0,this.sweepShiftAmount=0,this.envDecayRate=0,this.envDecayCounter=0,this.envVolume=0,this.masterVolume=0,this.dutyMode=0,this.vol=0,this.isEnabled=!1,this.lengthCounterEnable=!1,this.sweepActive=!1,this.sweepCarry=!1,this.envDecayDisable=!1,this.envDecayLoopEnable=!1},clockLengthCounter:function(){this.lengthCounterEnable&&this.lengthCounter>0&&0===--this.lengthCounter&&this.updateSampleValue()},clockEnvDecay:function(){this.envReset?(this.envReset=!1,this.envDecayCounter=this.envDecayRate+1,this.envVolume=15):--this.envDecayCounter<=0&&(this.envDecayCounter=this.envDecayRate+1,this.envVolume>0?this.envVolume--:this.envVolume=this.envDecayLoopEnable?15:0),this.envDecayDisable?this.masterVolume=this.envDecayRate:this.masterVolume=this.envVolume,this.updateSampleValue()},clockSweep:function(){--this.sweepCounter<=0&&(this.sweepCounter=this.sweepCounterMax+1,this.sweepActive&&this.sweepShiftAmount>0&&this.progTimerMax>7&&(this.sweepCarry=!1,0===this.sweepMode?(this.progTimerMax+=this.progTimerMax>>this.sweepShiftAmount,this.progTimerMax>4095&&(this.progTimerMax=4095,this.sweepCarry=!0)):this.progTimerMax=this.progTimerMax-((this.progTimerMax>>this.sweepShiftAmount)-(this.sqr1?1:0)))),this.updateSweepPeriod&&(this.updateSweepPeriod=!1,this.sweepCounter=this.sweepCounterMax+1)},updateSampleValue:function(){this.isEnabled&&this.lengthCounter>0&&this.progTimerMax>7?0===this.sweepMode&&this.progTimerMax+(this.progTimerMax>>this.sweepShiftAmount)>4095?this.sampleValue=0:this.sampleValue=this.masterVolume*this.dutyLookup[(this.dutyMode<<3)+this.squareCounter]:this.sampleValue=0},writeReg:function(t,s){var i=this.sqr1?0:4;t===16384+i?(this.envDecayDisable=0!=(16&s),this.envDecayRate=15&s,this.envDecayLoopEnable=0!=(32&s),this.dutyMode=s>>6&3,this.lengthCounterEnable=0==(32&s),this.envDecayDisable?this.masterVolume=this.envDecayRate:this.masterVolume=this.envVolume,this.updateSampleValue()):t===16385+i?(this.sweepActive=0!=(128&s),this.sweepCounterMax=s>>4&7,this.sweepMode=s>>3&1,this.sweepShiftAmount=7&s,this.updateSweepPeriod=!0):t===16386+i?(this.progTimerMax&=1792,this.progTimerMax|=s):t===16387+i&&(this.progTimerMax&=255,this.progTimerMax|=(7&s)<<8,this.isEnabled&&(this.lengthCounter=this.papu.getLengthMax(248&s)),this.envReset=!0)},setEnabled:function(t){this.isEnabled=t,t||(this.lengthCounter=0),this.updateSampleValue()},getLengthStatus:function(){return 0!==this.lengthCounter&&this.isEnabled?1:0}};var n=function(t){this.papu=t,this.isEnabled=null,this.sampleCondition=null,this.lengthCounterEnable=null,this.lcHalt=null,this.lcControl=null,this.progTimerCount=null,this.progTimerMax=null,this.triangleCounter=null,this.lengthCounter=null,this.linearCounter=null,this.lcLoadValue=null,this.sampleValue=null,this.tmp=null,this.reset()};n.prototype={reset:function(){this.progTimerCount=0,this.progTimerMax=0,this.triangleCounter=0,this.isEnabled=!1,this.sampleCondition=!1,this.lengthCounter=0,this.lengthCounterEnable=!1,this.linearCounter=0,this.lcLoadValue=0,this.lcHalt=!0,this.lcControl=!1,this.tmp=0,this.sampleValue=15},clockLengthCounter:function(){this.lengthCounterEnable&&this.lengthCounter>0&&0===--this.lengthCounter&&this.updateSampleCondition()},clockLinearCounter:function(){this.lcHalt?(this.linearCounter=this.lcLoadValue,this.updateSampleCondition()):this.linearCounter>0&&(this.linearCounter--,this.updateSampleCondition()),this.lcControl||(this.lcHalt=!1)},getLengthStatus:function(){return 0!==this.lengthCounter&&this.isEnabled?1:0},readReg:function(t){return 0},writeReg:function(t,s){16392===t?(this.lcControl=0!=(128&s),this.lcLoadValue=127&s,this.lengthCounterEnable=!this.lcControl):16394===t?(this.progTimerMax&=1792,this.progTimerMax|=s):16395===t&&(this.progTimerMax&=255,this.progTimerMax|=(7&s)<<8,this.lengthCounter=this.papu.getLengthMax(248&s),this.lcHalt=!0),this.updateSampleCondition()},clockProgrammableTimer:function(t){if(this.progTimerMax>0)for(this.progTimerCount+=t;this.progTimerMax>0&&this.progTimerCount>=this.progTimerMax;)this.progTimerCount-=this.progTimerMax,this.isEnabled&&this.lengthCounter>0&&this.linearCounter>0&&this.clockTriangleGenerator()},clockTriangleGenerator:function(){this.triangleCounter++,this.triangleCounter&=31},setEnabled:function(t){this.isEnabled=t,t||(this.lengthCounter=0),this.updateSampleCondition()},updateSampleCondition:function(){this.sampleCondition=this.isEnabled&&this.progTimerMax>7&&this.linearCounter>0&&this.lengthCounter>0}},t.exports=i},function(t,s,i){var e=i(9),h=i(2),r=function(t){this.nes=t,this.mapperName=new Array(92);for(var s=0;s<92;s++)this.mapperName[s]="Unknown Mapper";this.mapperName[0]="Direct Access",this.mapperName[1]="Nintendo MMC1",this.mapperName[2]="UNROM",this.mapperName[3]="CNROM",this.mapperName[4]="Nintendo MMC3",this.mapperName[5]="Nintendo MMC5",this.mapperName[6]="FFE F4xxx",this.mapperName[7]="AOROM",this.mapperName[8]="FFE F3xxx",this.mapperName[9]="Nintendo MMC2",this.mapperName[10]="Nintendo MMC4",this.mapperName[11]="Color Dreams Chip",this.mapperName[12]="FFE F6xxx",this.mapperName[15]="100-in-1 switch",this.mapperName[16]="Bandai chip",this.mapperName[17]="FFE F8xxx",this.mapperName[18]="Jaleco SS8806 chip",this.mapperName[19]="Namcot 106 chip",this.mapperName[20]="Famicom Disk System",this.mapperName[21]="Konami VRC4a",this.mapperName[22]="Konami VRC2a",this.mapperName[23]="Konami VRC2a",this.mapperName[24]="Konami VRC6",this.mapperName[25]="Konami VRC4b",this.mapperName[32]="Irem G-101 chip",this.mapperName[33]="Taito TC0190/TC0350",this.mapperName[34]="32kB ROM switch",this.mapperName[64]="Tengen RAMBO-1 chip",this.mapperName[65]="Irem H-3001 chip",this.mapperName[66]="GNROM switch",this.mapperName[67]="SunSoft3 chip",this.mapperName[68]="SunSoft4 chip",this.mapperName[69]="SunSoft5 FME-7 chip",this.mapperName[71]="Camerica chip",this.mapperName[78]="Irem 74HC161/32-based",this.mapperName[91]="Pirate HK-SF3 chip"};r.prototype={VERTICAL_MIRRORING:0,HORIZONTAL_MIRRORING:1,FOURSCREEN_MIRRORING:2,SINGLESCREEN_MIRRORING:3,SINGLESCREEN_MIRRORING2:4,SINGLESCREEN_MIRRORING3:5,SINGLESCREEN_MIRRORING4:6,CHRROM_MIRRORING:7,header:null,rom:null,vrom:null,vromTile:null,romCount:null,vromCount:null,mirroring:null,batteryRam:null,trainer:null,fourScreen:null,mapperType:null,valid:!1,load:function(t){var s,i,e;if(-1===t.indexOf("NES"))throw new Error("Not a valid NES ROM.");for(this.header=new Array(16),s=0;s<16;s++)this.header[s]=255&t.charCodeAt(s);this.romCount=this.header[4],this.vromCount=2*this.header[5],this.mirroring=0!=(1&this.header[6])?1:0,this.batteryRam=0!=(2&this.header[6]),this.trainer=0!=(4&this.header[6]),this.fourScreen=0!=(8&this.header[6]),this.mapperType=this.header[6]>>4|240&this.header[7];var r=!1;for(s=8;s<16;s++)if(0!==this.header[s]){r=!0;break}r&&(this.mapperType&=15),this.rom=new Array(this.romCount);var n=16;for(s=0;s=t.length);i++)this.rom[s][i]=255&t.charCodeAt(n+i);n+=16384}for(this.vrom=new Array(this.vromCount),s=0;s=t.length);i++)this.vrom[s][i]=255&t.charCodeAt(n+i);n+=4096}for(this.vromTile=new Array(this.vromCount),s=0;s>4,o=s%16,o<8?this.vromTile[e][a].setScanline(o,this.vrom[e][s],this.vrom[e][s+8]):this.vromTile[e][a].setScanline(o-8,this.vrom[e][s-8],this.vrom[e][s]);this.valid=!0},getMirroringType:function(){return this.fourScreen?this.FOURSCREEN_MIRRORING:0===this.mirroring?this.HORIZONTAL_MIRRORING:this.VERTICAL_MIRRORING},getMapperName:function(){return this.mapperType>=0&&this.mapperType16407?(this.nes.cpu.mem[t]=s,t>=24576&&t<32768&&this.nes.opts.onBatteryRamWrite(t,s)):t>8199&&t<16384?this.regWrite(8192+(7&t),s):this.regWrite(t,s)},writelow:function(t,s){t<8192?this.nes.cpu.mem[2047&t]=s:t>16407?this.nes.cpu.mem[t]=s:t>8199&&t<16384?this.regWrite(8192+(7&t),s):this.regWrite(t,s)},load:function(t){return t&=65535,t>16407?this.nes.cpu.mem[t]:t>=8192?this.regLoad(t):this.nes.cpu.mem[2047&t]},regLoad:function(t){switch(t>>12){case 0:case 1:break;case 2:case 3:switch(7&t){case 0:return this.nes.cpu.mem[8192];case 1:return this.nes.cpu.mem[8193];case 2:return this.nes.ppu.readStatusRegister();case 3:return 0;case 4:return this.nes.ppu.sramLoad();case 5:case 6:return 0;case 7:return this.nes.ppu.vramLoad()}break;case 4:switch(t-16405){case 0:return this.nes.papu.readReg(t);case 1:return this.joy1Read();case 2:var s;return s=null!==this.zapperX&&null!==this.zapperY&&this.nes.ppu.isPixelWhite(this.zapperX,this.zapperY)?0:8,this.zapperFired&&(s|=16),65535&(this.joy2Read()|s)}}return 0},regWrite:function(t,s){switch(t){case 8192:this.nes.cpu.mem[t]=s,this.nes.ppu.updateControlReg1(s);break;case 8193:this.nes.cpu.mem[t]=s,this.nes.ppu.updateControlReg2(s);break;case 8195:this.nes.ppu.writeSRAMAddress(s);break;case 8196:this.nes.ppu.sramWrite(s);break;case 8197:this.nes.ppu.scrollWrite(s);break;case 8198:this.nes.ppu.writeVRAMAddress(s);break;case 8199:this.nes.ppu.vramWrite(s);break;case 16404:this.nes.ppu.sramDMA(s);break;case 16405:this.nes.papu.writeReg(t,s);break;case 16406:0==(1&s)&&1==(1&this.joypadLastWrite)&&(this.joy1StrobeState=0,this.joy2StrobeState=0),this.joypadLastWrite=s;break;case 16407:this.nes.papu.writeReg(t,s);break;default:t>=16384&&t<=16407&&this.nes.papu.writeReg(t,s)}},joy1Read:function(){var t;switch(this.joy1StrobeState){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:t=this.nes.controllers[1].state[this.joy1StrobeState];break;case 8:case 9:case 10:case 11:case 12:case 13:case 14:case 15:case 16:case 17:case 18:t=0;break;case 19:t=1;break;default:t=0}return this.joy1StrobeState++,24===this.joy1StrobeState&&(this.joy1StrobeState=0),t},joy2Read:function(){var t;switch(this.joy2StrobeState){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:t=this.nes.controllers[2].state[this.joy2StrobeState];break;case 8:case 9:case 10:case 11:case 12:case 13:case 14:case 15:case 16:case 17:case 18:t=0;break;case 19:t=1;break;default:t=0}return this.joy2StrobeState++,24===this.joy2StrobeState&&(this.joy2StrobeState=0),t},loadROM:function(){if(!this.nes.rom.valid||this.nes.rom.romCount<1)throw new Error("NoMapper: Invalid ROM! Unable to load.");this.loadPRGROM(),this.loadCHRROM(),this.loadBatteryRam(),this.nes.cpu.requestIrq(this.nes.cpu.IRQ_RESET)},loadPRGROM:function(){this.nes.rom.romCount>1?(this.loadRomBank(0,32768),this.loadRomBank(1,49152)):(this.loadRomBank(0,32768),this.loadRomBank(0,49152))},loadCHRROM:function(){this.nes.rom.vromCount>0&&(1===this.nes.rom.vromCount?(this.loadVromBank(0,0),this.loadVromBank(0,4096)):(this.loadVromBank(0,0),this.loadVromBank(1,4096)))},loadBatteryRam:function(){if(this.nes.rom.batteryRam){var t=this.nes.rom.batteryRam;null!==t&&8192===t.length&&e.copyArrayElements(t,0,this.nes.cpu.mem,24576,8192)}},loadRomBank:function(t,s){t%=this.nes.rom.romCount,e.copyArrayElements(this.nes.rom.rom[t],0,this.nes.cpu.mem,s,16384)},loadVromBank:function(t,s){if(0!==this.nes.rom.vromCount){this.nes.ppu.triggerRendering(),e.copyArrayElements(this.nes.rom.vrom[t%this.nes.rom.vromCount],0,this.nes.ppu.vramMem,s,4096);var i=this.nes.rom.vromTile[t%this.nes.rom.vromCount];e.copyArrayElements(i,0,this.nes.ppu.ptTile,s>>4,256)}},load32kRomBank:function(t,s){this.loadRomBank(2*t%this.nes.rom.romCount,s),this.loadRomBank((2*t+1)%this.nes.rom.romCount,s+16384)},load8kVromBank:function(t,s){0!==this.nes.rom.vromCount&&(this.nes.ppu.triggerRendering(),this.loadVromBank(t%this.nes.rom.vromCount,s),this.loadVromBank((t+1)%this.nes.rom.vromCount,s+4096))},load1kVromBank:function(t,s){if(0!==this.nes.rom.vromCount){this.nes.ppu.triggerRendering();var i=Math.floor(t/4)%this.nes.rom.vromCount,h=t%4*1024;e.copyArrayElements(this.nes.rom.vrom[i],h,this.nes.ppu.vramMem,s,1024);for(var r=this.nes.rom.vromTile[i],n=s>>4,a=0;a<64;a++)this.nes.ppu.ptTile[n+a]=r[(t%4<<6)+a]}},load2kVromBank:function(t,s){if(0!==this.nes.rom.vromCount){this.nes.ppu.triggerRendering();var i=Math.floor(t/2)%this.nes.rom.vromCount,h=t%2*2048;e.copyArrayElements(this.nes.rom.vrom[i],h,this.nes.ppu.vramMem,s,2048);for(var r=this.nes.rom.vromTile[i],n=s>>4,a=0;a<128;a++)this.nes.ppu.ptTile[n+a]=r[(t%2<<7)+a]}},load8kRomBank:function(t,s){var i=Math.floor(t/2)%this.nes.rom.romCount,h=t%2*8192;e.copyArrayElements(this.nes.rom.rom[i],h,this.nes.cpu.mem,s,8192)},clockIrqCounter:function(){},latchAccess:function(t){},toJSON:function(){return{joy1StrobeState:this.joy1StrobeState,joy2StrobeState:this.joy2StrobeState,joypadLastWrite:this.joypadLastWrite}},fromJSON:function(t){this.joy1StrobeState=t.joy1StrobeState,this.joy2StrobeState=t.joy2StrobeState,this.joypadLastWrite=t.joypadLastWrite}},h[1]=function(t){this.nes=t},h[1].prototype=new h[0],h[1].prototype.reset=function(){h[0].prototype.reset.apply(this),this.regBuffer=0,this.regBufferCounter=0,this.mirroring=0,this.oneScreenMirroring=0,this.prgSwitchingArea=1,this.prgSwitchingSize=1,this.vromSwitchingSize=0,this.romSelectionReg0=0,this.romSelectionReg1=0,this.romBankSelect=0},h[1].prototype.write=function(t,s){if(t<32768)return void h[0].prototype.write.apply(this,arguments);0!=(128&s)?(this.regBufferCounter=0,this.regBuffer=0,0===this.getRegNumber(t)&&(this.prgSwitchingArea=1,this.prgSwitchingSize=1)):(this.regBuffer=this.regBuffer&255-(1<>2&1,this.prgSwitchingSize=s>>3&1,this.vromSwitchingSize=s>>4&1;break;case 1:this.romSelectionReg0=s>>4&1,this.nes.rom.vromCount>0&&(0===this.vromSwitchingSize?0===this.romSelectionReg0?this.load8kVromBank(15&s,0):this.load8kVromBank(Math.floor(this.nes.rom.vromCount/2)+(15&s),0):0===this.romSelectionReg0?this.loadVromBank(15&s,0):this.loadVromBank(Math.floor(this.nes.rom.vromCount/2)+(15&s),0));break;case 2:this.romSelectionReg1=s>>4&1,this.nes.rom.vromCount>0&&1===this.vromSwitchingSize&&(0===this.romSelectionReg1?this.loadVromBank(15&s,4096):this.loadVromBank(Math.floor(this.nes.rom.vromCount/2)+(15&s),4096));break;default:i=15&s;var e,h=0;this.nes.rom.romCount>=32?0===this.vromSwitchingSize?1===this.romSelectionReg0&&(h=16):h=(this.romSelectionReg0|this.romSelectionReg1<<1)<<3:this.nes.rom.romCount>=16&&1===this.romSelectionReg0&&(h=8),0===this.prgSwitchingSize?(e=h+(15&s),this.load32kRomBank(e,32768)):(e=2*h+(15&s),0===this.prgSwitchingArea?this.loadRomBank(e,49152):this.loadRomBank(e,32768))}},h[1].prototype.getRegNumber=function(t){return t>=32768&&t<=40959?0:t>=40960&&t<=49151?1:t>=49152&&t<=57343?2:3},h[1].prototype.loadROM=function(){if(!this.nes.rom.valid)throw new Error("MMC1: Invalid ROM! Unable to load.");this.loadRomBank(0,32768),this.loadRomBank(this.nes.rom.romCount-1,49152),this.loadCHRROM(),this.loadBatteryRam(),this.nes.cpu.requestIrq(this.nes.cpu.IRQ_RESET)},h[1].prototype.switchLowHighPrgRom=function(t){},h[1].prototype.switch16to32=function(){},h[1].prototype.switch32to16=function(){},h[1].prototype.toJSON=function(){var t=h[0].prototype.toJSON.apply(this);return t.mirroring=this.mirroring,t.oneScreenMirroring=this.oneScreenMirroring,t.prgSwitchingArea=this.prgSwitchingArea,t.prgSwitchingSize=this.prgSwitchingSize,t.vromSwitchingSize=this.vromSwitchingSize,t.romSelectionReg0=this.romSelectionReg0,t.romSelectionReg1=this.romSelectionReg1,t.romBankSelect=this.romBankSelect,t.regBuffer=this.regBuffer,t.regBufferCounter=this.regBufferCounter,t},h[1].prototype.fromJSON=function(t){h[0].prototype.fromJSON.apply(this,arguments),this.mirroring=t.mirroring,this.oneScreenMirroring=t.oneScreenMirroring,this.prgSwitchingArea=t.prgSwitchingArea,this.prgSwitchingSize=t.prgSwitchingSize,this.vromSwitchingSize=t.vromSwitchingSize,this.romSelectionReg0=t.romSelectionReg0,this.romSelectionReg1=t.romSelectionReg1,this.romBankSelect=t.romBankSelect,this.regBuffer=t.regBuffer,this.regBufferCounter=t.regBufferCounter},h[2]=function(t){this.nes=t},h[2].prototype=new h[0],h[2].prototype.write=function(t,s){if(t<32768)return void h[0].prototype.write.apply(this,arguments);this.loadRomBank(s,32768)},h[2].prototype.loadROM=function(){if(!this.nes.rom.valid)throw new Error("UNROM: Invalid ROM! Unable to load.");this.loadRomBank(0,32768),this.loadRomBank(this.nes.rom.romCount-1,49152),this.loadCHRROM(),this.nes.cpu.requestIrq(this.nes.cpu.IRQ_RESET)},h[3]=function(t){this.nes=t},h[3].prototype=new h[0],h[3].prototype.write=function(t,s){if(t<32768)return void h[0].prototype.write.apply(this,arguments);var i=s%(this.nes.rom.vromCount/2)*2;this.loadVromBank(i,0),this.loadVromBank(i+1,4096),this.load8kVromBank(2*s,0)},h[4]=function(t){this.nes=t,this.CMD_SEL_2_1K_VROM_0000=0,this.CMD_SEL_2_1K_VROM_0800=1,this.CMD_SEL_1K_VROM_1000=2,this.CMD_SEL_1K_VROM_1400=3,this.CMD_SEL_1K_VROM_1800=4,this.CMD_SEL_1K_VROM_1C00=5,this.CMD_SEL_ROM_PAGE1=6,this.CMD_SEL_ROM_PAGE2=7,this.command=null,this.prgAddressSelect=null,this.chrAddressSelect=null,this.pageNumber=null,this.irqCounter=null,this.irqLatchValue=null,this.irqEnable=null,this.prgAddressChanged=!1},h[4].prototype=new h[0],h[4].prototype.write=function(t,s){if(t<32768)return void h[0].prototype.write.apply(this,arguments);switch(t){case 32768:this.command=7&s;var i=s>>6&1;i!==this.prgAddressSelect&&(this.prgAddressChanged=!0),this.prgAddressSelect=i,this.chrAddressSelect=s>>7&1;break;case 32769:this.executeCommand(this.command,s);break;case 40960:0!=(1&s)?this.nes.ppu.setMirroring(this.nes.rom.HORIZONTAL_MIRRORING):this.nes.ppu.setMirroring(this.nes.rom.VERTICAL_MIRRORING);break;case 40961:break;case 49152:this.irqCounter=s;break;case 49153:this.irqLatchValue=s;break;case 57344:this.irqEnable=0;break;case 57345:this.irqEnable=1}},h[4].prototype.executeCommand=function(t,s){switch(t){case this.CMD_SEL_2_1K_VROM_0000:0===this.chrAddressSelect?(this.load1kVromBank(s,0),this.load1kVromBank(s+1,1024)):(this.load1kVromBank(s,4096),this.load1kVromBank(s+1,5120));break;case this.CMD_SEL_2_1K_VROM_0800:0===this.chrAddressSelect?(this.load1kVromBank(s,2048),this.load1kVromBank(s+1,3072)):(this.load1kVromBank(s,6144),this.load1kVromBank(s+1,7168));break;case this.CMD_SEL_1K_VROM_1000:0===this.chrAddressSelect?this.load1kVromBank(s,4096):this.load1kVromBank(s,0);break;case this.CMD_SEL_1K_VROM_1400:0===this.chrAddressSelect?this.load1kVromBank(s,5120):this.load1kVromBank(s,1024);break;case this.CMD_SEL_1K_VROM_1800:0===this.chrAddressSelect?this.load1kVromBank(s,6144):this.load1kVromBank(s,2048);break;case this.CMD_SEL_1K_VROM_1C00:0===this.chrAddressSelect?this.load1kVromBank(s,7168):this.load1kVromBank(s,3072);break;case this.CMD_SEL_ROM_PAGE1:this.prgAddressChanged&&(0===this.prgAddressSelect?this.load8kRomBank(2*(this.nes.rom.romCount-1),49152):this.load8kRomBank(2*(this.nes.rom.romCount-1),32768),this.prgAddressChanged=!1),0===this.prgAddressSelect?this.load8kRomBank(s,32768):this.load8kRomBank(s,49152);break;case this.CMD_SEL_ROM_PAGE2:this.load8kRomBank(s,40960),this.prgAddressChanged&&(0===this.prgAddressSelect?this.load8kRomBank(2*(this.nes.rom.romCount-1),49152):this.load8kRomBank(2*(this.nes.rom.romCount-1),32768),this.prgAddressChanged=!1)}},h[4].prototype.loadROM=function(){if(!this.nes.rom.valid)throw new Error("MMC3: Invalid ROM! Unable to load.");this.load8kRomBank(2*(this.nes.rom.romCount-1),49152),this.load8kRomBank(2*(this.nes.rom.romCount-1)+1,57344),this.load8kRomBank(0,32768),this.load8kRomBank(1,40960),this.loadCHRROM(),this.loadBatteryRam(),this.nes.cpu.requestIrq(this.nes.cpu.IRQ_RESET)},h[4].prototype.clockIrqCounter=function(){1===this.irqEnable&&--this.irqCounter<0&&(this.nes.cpu.requestIrq(this.nes.cpu.IRQ_NORMAL),this.irqCounter=this.irqLatchValue)},h[4].prototype.toJSON=function(){var t=h[0].prototype.toJSON.apply(this);return t.command=this.command,t.prgAddressSelect=this.prgAddressSelect,t.chrAddressSelect=this.chrAddressSelect,t.pageNumber=this.pageNumber,t.irqCounter=this.irqCounter,t.irqLatchValue=this.irqLatchValue,t.irqEnable=this.irqEnable,t.prgAddressChanged=this.prgAddressChanged,t},h[4].prototype.fromJSON=function(t){h[0].prototype.fromJSON.apply(this,arguments),this.command=t.command,this.prgAddressSelect=t.prgAddressSelect,this.chrAddressSelect=t.chrAddressSelect,this.pageNumber=t.pageNumber,this.irqCounter=t.irqCounter,this.irqLatchValue=t.irqLatchValue,this.irqEnable=t.irqEnable,this.prgAddressChanged=t.prgAddressChanged},h[5]=function(t){this.nes=t},h[5].prototype=new h[0],h[5].prototype.write=function(t,s){t<32768?h[0].prototype.write.apply(this,arguments):this.load8kVromBank(s,0)},h[5].prototype.write=function(t,s){if(t<20480)return void h[0].prototype.write.apply(this,arguments);switch(t){case 20736:this.prg_size=3&s;break;case 20737:this.chr_size=3&s;break;case 20738:this.sram_we_a=3&s;break;case 20739:this.sram_we_b=3&s;break;case 20740:this.graphic_mode=3&s;break;case 20741:this.nametable_mode=s,this.nametable_type[0]=3&s,this.load1kVromBank(3&s,8192),s>>=2,this.nametable_type[1]=3&s,this.load1kVromBank(3&s,9216),s>>=2,this.nametable_type[2]=3&s,this.load1kVromBank(3&s,10240),s>>=2,this.nametable_type[3]=3&s,this.load1kVromBank(3&s,11264);break;case 20742:this.fill_chr=s;break;case 20743:this.fill_pal=3&s;break;case 20755:this.SetBank_SRAM(3,3&s);break;case 20756:case 20757:case 20758:case 20759:this.SetBank_CPU(t,s);break;case 20768:case 20769:case 20770:case 20771:case 20772:case 20773:case 20774:case 20775:this.chr_mode=0,this.chr_page[0][7&t]=s,this.SetBank_PPU();break;case 20776:case 20777:case 20778:case 20779:this.chr_mode=1,this.chr_page[1][0+(3&t)]=s,this.chr_page[1][4+(3&t)]=s,this.SetBank_PPU();break;case 20992:this.split_control=s;break;case 20993:this.split_scroll=s;break;case 20994:this.split_page=63&s;break;case 20995:this.irq_line=s,this.nes.cpu.ClearIRQ();break;case 20996:this.irq_enable=s,this.nes.cpu.ClearIRQ();break;case 20997:this.mult_a=s;break;case 20998:this.mult_b=s;break;default:t>=20480&&t<=20501?this.nes.papu.exWrite(t,s):t>=23552&&t<=24575?2===this.graphic_mode||3!==this.graphic_mode&&this.irq_status:t>=24576&&t<=32767&&2===this.sram_we_a&&this.sram_we_b}},h[5].prototype.loadROM=function(){if(!this.nes.rom.valid)throw new Error("UNROM: Invalid ROM! Unable to load.");this.load8kRomBank(2*this.nes.rom.romCount-1,32768),this.load8kRomBank(2*this.nes.rom.romCount-1,40960),this.load8kRomBank(2*this.nes.rom.romCount-1,49152),this.load8kRomBank(2*this.nes.rom.romCount-1,57344),this.loadCHRROM(),this.nes.cpu.requestIrq(this.nes.cpu.IRQ_RESET)},h[7]=function(t){this.nes=t},h[7].prototype=new h[0],h[7].prototype.write=function(t,s){t<32768?h[0].prototype.write.apply(this,arguments):(this.load32kRomBank(7&s,32768),16&s?this.nes.ppu.setMirroring(this.nes.rom.SINGLESCREEN_MIRRORING2):this.nes.ppu.setMirroring(this.nes.rom.SINGLESCREEN_MIRRORING))},h[7].prototype.loadROM=function(){if(!this.nes.rom.valid)throw new Error("AOROM: Invalid ROM! Unable to load.");this.loadPRGROM(),this.loadCHRROM(),this.nes.cpu.requestIrq(this.nes.cpu.IRQ_RESET)},h[11]=function(t){this.nes=t},h[11].prototype=new h[0],h[11].prototype.write=function(t,s){if(t<32768)return void h[0].prototype.write.apply(this,arguments);var i=2*(15&s)%this.nes.rom.romCount,e=(2*(15&s)+1)%this.nes.rom.romCount;if(this.loadRomBank(i,32768),this.loadRomBank(e,49152),this.nes.rom.vromCount>0){var r=2*(s>>4)%this.nes.rom.vromCount;this.loadVromBank(r,0),this.loadVromBank(r+1,4096)}},h[34]=function(t){this.nes=t},h[34].prototype=new h[0],h[34].prototype.write=function(t,s){if(t<32768)return void h[0].prototype.write.apply(this,arguments);this.load32kRomBank(s,32768)},h[38]=function(t){this.nes=t},h[38].prototype=new h[0],h[38].prototype.write=function(t,s){if(t<28672||t>32767)return void h[0].prototype.write.apply(this,arguments);this.load32kRomBank(3&s,32768),this.load8kVromBank(2*(s>>2&3),0)},h[66]=function(t){this.nes=t},h[66].prototype=new h[0],h[66].prototype.write=function(t,s){if(t<32768)return void h[0].prototype.write.apply(this,arguments);this.load32kRomBank(s>>4&3,32768),this.load8kVromBank(2*(3&s),0)},h[94]=function(t){this.nes=t},h[94].prototype=new h[0],h[94].prototype.write=function(t,s){if(t<32768)return void h[0].prototype.write.apply(this,arguments);this.loadRomBank(s>>2,32768)},h[94].prototype.loadROM=function(){if(!this.nes.rom.valid)throw new Error("UN1ROM: Invalid ROM! Unable to load.");this.loadRomBank(0,32768),this.loadRomBank(this.nes.rom.romCount-1,49152),this.loadCHRROM(),this.nes.cpu.requestIrq(this.nes.cpu.IRQ_RESET)},h[140]=function(t){this.nes=t},h[140].prototype=new h[0],h[140].prototype.write=function(t,s){if(t<24576||t>32767)return void h[0].prototype.write.apply(this,arguments);this.load32kRomBank(s>>4&3,32768),this.load8kVromBank(2*(15&s),0)},h[180]=function(t){this.nes=t},h[180].prototype=new h[0],h[180].prototype.write=function(t,s){if(t<32768)return void h[0].prototype.write.apply(this,arguments);this.loadRomBank(s,49152)},h[180].prototype.loadROM=function(){if(!this.nes.rom.valid)throw new Error("Mapper 180: Invalid ROM! Unable to load.");this.loadRomBank(0,32768),this.loadRomBank(this.nes.rom.romCount-1,49152),this.loadCHRROM(),this.nes.cpu.requestIrq(this.nes.cpu.IRQ_RESET)},t.exports=h}])}); 2 | //# sourceMappingURL=jsnes.min.js.map --------------------------------------------------------------------------------