diff --git a/css/ui.css b/css/ui.css index c7117392..01a1585d 100644 --- a/css/ui.css +++ b/css/ui.css @@ -1006,4 +1006,117 @@ div.scripting-cell button.scripting-enabled { } .dialog-help { color: #6666ff; -} \ No newline at end of file +} +/* breakpoints window */ +.bp-view { + background-color: #333; + color: #ddd; + padding: 0.6em; + font-size: 0.9em; + min-height: 100%; + box-sizing: border-box; +} +.bp-form { + display: grid; + grid-template-columns: 1fr 1fr auto auto; + gap: 0.4em; + margin-bottom: 0.8em; +} +.bp-input { + width: 100%; + box-sizing: border-box; + background-color: #222; + color: #eee; + border: 1px solid #555; + border-radius: 3px; + padding: 0.3em 0.5em; + font-family: "Andale Mono", "Menlo", "Lucida Console", monospace; +} +.bp-input:focus { + outline: none; + border-color: #7ec7ff; +} +.bp-input::placeholder { + color: #888; +} +.bp-submit { + min-width: 3.5em; +} +.bp-row { + display: flex; + gap: 0.6em; + align-items: center; + padding: 0.3em 0.4em; + border-radius: 3px; + border-bottom: 1px solid #3d3d3d; +} +.bp-row:hover { + background: rgba(255, 255, 255, 0.06); +} +.bp-row.bp-current { + background: #7e2a70; /* matches the editor's current-PC line highlight */ +} +.bp-row.bp-current:hover { + background: #8f3282; +} +.bp-row.bp-disabled .bp-loc, +.bp-row.bp-disabled .bp-addr, +.bp-row.bp-disabled .bp-cond { + opacity: 0.5; +} +.bp-chk { + margin: 0; + cursor: pointer; + flex: 0 0 auto; +} +.bp-loc { + cursor: pointer; + font-weight: bold; + white-space: nowrap; + flex: 0 0 auto; + min-width: 8em; +} +.bp-loc:hover { + text-decoration: underline; + color: #7ec7ff; +} +.bp-addr { + color: #7ec7ff; + white-space: nowrap; + flex: 0 0 auto; + min-width: 4.5em; + font-family: "Andale Mono", "Menlo", "Lucida Console", monospace; +} +.bp-addr.bp-error { + color: #ff6a6a; + font-family: inherit; +} +.bp-cond { + color: #9c9cff; + flex: 1 1 auto; + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + font-family: "Andale Mono", "Menlo", "Lucida Console", monospace; +} +.bp-btn { + background: none; + border: none; + cursor: pointer; + color: #999; + padding: 0.1em 0.35em; + font-size: 0.9em; + flex: 0 0 auto; + border-radius: 3px; +} +.bp-btn:hover { + color: #fff; + background: rgba(255, 255, 255, 0.12); +} +.bp-hint { + color: #888; + font-size: 0.85em; + margin-top: 0.8em; + line-height: 1.4; +} diff --git a/gen/apple2-VXIPT7OL.js b/gen/apple2-3KOIXQGR.js similarity index 99% rename from gen/apple2-VXIPT7OL.js rename to gen/apple2-3KOIXQGR.js index 4c440628..0f7fe942 100644 --- a/gen/apple2-VXIPT7OL.js +++ b/gen/apple2-3KOIXQGR.js @@ -1,4 +1,4 @@ -import{a as i0}from"./chunk-ULIQADK2.js";import{A as r0,J as s0,m as e0,r as t0,x as O}from"./chunk-G4HBIXG4.js";import{K as U,g as W,i as X,l as $,m as x0,s as a0,u as d}from"./chunk-TYDI7JZQ.js";import"./chunk-KT7KMEQC.js";var P=class extends t0{constructor(){super();this.cpuFrequency=1022727;this.sampleRate=this.cpuFrequency;this.cpuCyclesPerLine=65;this.cpuCyclesPerFrame=this.cpuCyclesPerLine*262;this.canvasWidth=280;this.numVisibleScanlines=192;this.numTotalScanlines=262;this.defaultROMSize=77824;this.cpuCyclesPaddleUnit=11;this.cpuCyclesPaddleMax=255*this.cpuCyclesPaddleUnit;this.LOAD_BASE=0;this.HDR_SIZE=0;this.ram=new Uint8Array(77824);this.cpu=new e0;this.grdirty=new Array(384);this.grparams={dirty:this.grdirty,grswitch:E,mem:this.ram};this.kbdlatch=0;this.soundstate=0;this.auxRAMselected=!1;this.auxRAMbank=1;this.writeinhibit=!0;this.bank2rdoffset=0;this.bank2wroffset=0;this.paddleValues=[0,0,0,0];this.paddleButtons=[!1,!1,!1];this.paddleLastTriggered=0;this.slots=new Array(8);this.fakeDrive={readROM:x=>{var a=this.cpu.getPC();if(a>=50688&&a<50944)switch(x){case 0:return 0;case 1:return this.LOAD_BASE&255;case 2:return this.LOAD_BASE>>8&255;default:return 0}else switch(x){case 0:return this.rom&&this.loadRAMWithProgram(),76;case 1:return 32;case 3:return 0;case 5:return 3;case 7:return 60;default:return 0}},readConst:x=>0,read:x=>this.floatbus(),write:(x,a)=>{}};this.loadBIOS(new $().decode(x0(atob(u0)))),this.connectCPUMemoryBus(this),this.bios[54170-(65536-this.bios.length)]=96}saveState(){return{c:this.cpu.saveState(),ram:this.ram.slice(),kbdlatch:this.kbdlatch,soundstate:this.soundstate,grswitch:this.grparams.grswitch,auxRAMselected:this.auxRAMselected,auxRAMbank:this.auxRAMbank,writeinhibit:this.writeinhibit,slots:this.slots.map(x=>x&&x.saveState&&x.saveState()),paddleValues:this.paddleValues.slice(),paddleButtons:this.paddleButtons.slice(),inputs:this.ram.slice(0,0)}}loadState(x){this.cpu.loadState(x.c),this.ram.set(x.ram),this.kbdlatch=x.kbdlatch,this.soundstate=x.soundstate,this.grparams.grswitch=x.grswitch,this.auxRAMselected=x.auxRAMselected,this.auxRAMbank=x.auxRAMbank,this.writeinhibit=x.writeinhibit,this.setupLanguageCardConstants();for(var a=0;a>8!=198);x++);for(var x=0;x<2e6&&(this.cpu.advanceClock(),!(this.cpu.getPC()>>8<198));x++);}readConst(x){if(x<49152)return this.ram[x];if(x>=53248)return this.auxRAMselected?x>=57344?this.ram[x]:this.ram[x+this.bank2rdoffset]:this.bios[x-(65536-this.bios.length)];if(x>=49408&&x<51200){var a=x>>8&7;return(this.slots[a]&&this.slots[a].readConst(x&255))|0}else return 0}read(x){if(x&=65535,x<49152||x>=53248)return this.readConst(x);if(x<49408){this.probe.logIORead(x,0);var a=x>>4&15;switch(a){case 0:return this.kbdlatch;case 1:this.kbdlatch&=127;break;case 3:this.soundstate=this.soundstate^1;break;case 5:(x&15)<8&&((x&1)!=0?this.grparams.grswitch|=1<<(x>>1&7):this.grparams.grswitch&=~(1<<(x>>1&7)));break;case 6:switch(x&7){case 1:case 2:case 3:var r=(x&7)-1;return this.paddleButtons[r]?this.floatbus()|128:this.floatbus()&127;case 4:case 5:case 6:case 7:var t=(x&15)-4,c=this.frameCycles-this.paddleLastTriggered;return c=49408&&x<51200){var a=x>>8&7;return(this.slots[a]&&this.slots[a].readROM(x&255))|0}return this.floatbus()}write(x,a){if(x&=65535,a&=255,x<49152)this.ram[x]=a,this.grdirty[x>>7]=1;else if(x<49296)this.read(x);else if(x<49408){var r=x>>4&15;this.slots[r-8]&&this.slots[r-8].write(x&15,a),this.probe.logIOWrite(x,a)}else x>=53248&&!this.writeinhibit&&(x>=57344?this.ram[x]=a:this.ram[x+this.bank2wroffset]=a)}floatbus(){var x=this.frameCycles,a=Math.floor(x/65),r=Math.floor(x%65),t=this.ap2disp.getAddressForScanline(a);return this.readConst(t+r)}connectVideo(x){super.connectVideo(x),this.ap2disp=this.pixels&&new l0(this.pixels,this.grparams)}startScanline(){}drawScanline(){}advanceFrame(x){var a=super.advanceFrame(x);return this.ap2disp&&this.ap2disp.updateScreen(),a}postFrame(){this.paddleLastTriggered-=this.frameCycles,this.paddleLastTriggered<-this.cpuCyclesPaddleMax&&(this.paddleLastTriggered=-this.cpuCyclesPaddleMax)}advanceCPU(){return this.audio.feedSample(this.soundstate,1),super.advanceCPU()}setKeyInput(x,a,r){if(console.log(`setKeyInput: ${x} ${a} ${r}`),r&1){switch(a=0,x){case 16:case 17:case 18:case 91:return;case 8:if(a=8,r&2){this.cpu.reset();return}break;case 13:a=13;break;case 27:a=27;break;case 37:a=8;break;case 39:a=21;break;case 38:a=11;break;case 40:a=10;break;case 48:a=r&2?41:48;break;case 49:a=r&2?33:49;break;case 50:a=r&2?64:50;break;case 51:a=r&2?35:51;break;case 52:a=r&2?36:52;break;case 53:a=r&2?37:53;break;case 54:a=r&2?94:54;break;case 55:a=r&2?38:55;break;case 56:a=r&2?42:56;break;case 57:a=r&2?40:57;break;case 61:a=r&2?95:45;break;case 173:a=r&2?43:61;break;case 59:a=r&2?58:59;break;case 186:a=r&2?58:59;break;case 187:a=r&2?43:61;break;case 188:a=r&2?60:44;break;case 189:a=r&2?95:45;break;case 190:a=r&2?62:46;break;case 191:a=r&2?63:47;break;case 222:a=r&2?34:39;break;default:a=x,a>=97&&a<=122&&(a-=32),a>=65&&a<91&&r&4&&(a-=64)}a&&(this.kbdlatch=(a|128)&255)}}setPaddleInput(x,a){x>=0&&x=0&&x{var a=this.cpu.getPC();if(a>=50688&&a<50944)switch(x){case 0:return 0;case 1:return this.LOAD_BASE&255;case 2:return this.LOAD_BASE>>8&255;default:return 0}else switch(x){case 0:return this.rom&&this.loadRAMWithProgram(),76;case 1:return 32;case 3:return 0;case 5:return 3;case 7:return 60;default:return 0}},readConst:x=>0,read:x=>this.floatbus(),write:(x,a)=>{}};this.loadBIOS(new $().decode(x0(atob(u0)))),this.connectCPUMemoryBus(this),this.bios[54170-(65536-this.bios.length)]=96}saveState(){return{c:this.cpu.saveState(),ram:this.ram.slice(),kbdlatch:this.kbdlatch,soundstate:this.soundstate,grswitch:this.grparams.grswitch,auxRAMselected:this.auxRAMselected,auxRAMbank:this.auxRAMbank,writeinhibit:this.writeinhibit,slots:this.slots.map(x=>x&&x.saveState&&x.saveState()),paddleValues:this.paddleValues.slice(),paddleButtons:this.paddleButtons.slice(),inputs:this.ram.slice(0,0)}}loadState(x){this.cpu.loadState(x.c),this.ram.set(x.ram),this.kbdlatch=x.kbdlatch,this.soundstate=x.soundstate,this.grparams.grswitch=x.grswitch,this.auxRAMselected=x.auxRAMselected,this.auxRAMbank=x.auxRAMbank,this.writeinhibit=x.writeinhibit,this.setupLanguageCardConstants();for(var a=0;a>8!=198);x++);for(var x=0;x<2e6&&(this.cpu.advanceClock(),!(this.cpu.getPC()>>8<198));x++);}readConst(x){if(x<49152)return this.ram[x];if(x>=53248)return this.auxRAMselected?x>=57344?this.ram[x]:this.ram[x+this.bank2rdoffset]:this.bios[x-(65536-this.bios.length)];if(x>=49408&&x<51200){var a=x>>8&7;return(this.slots[a]&&this.slots[a].readConst(x&255))|0}else return 0}read(x){if(x&=65535,x<49152||x>=53248)return this.readConst(x);if(x<49408){this.probe.logIORead(x,0);var a=x>>4&15;switch(a){case 0:return this.kbdlatch;case 1:this.kbdlatch&=127;break;case 3:this.soundstate=this.soundstate^1;break;case 5:(x&15)<8&&((x&1)!=0?this.grparams.grswitch|=1<<(x>>1&7):this.grparams.grswitch&=~(1<<(x>>1&7)));break;case 6:switch(x&7){case 1:case 2:case 3:var r=(x&7)-1;return this.paddleButtons[r]?this.floatbus()|128:this.floatbus()&127;case 4:case 5:case 6:case 7:var t=(x&15)-4,c=this.frameCycles-this.paddleLastTriggered;return c=49408&&x<51200){var a=x>>8&7;return(this.slots[a]&&this.slots[a].readROM(x&255))|0}return this.floatbus()}write(x,a){if(x&=65535,a&=255,x<49152)this.ram[x]=a,this.grdirty[x>>7]=1;else if(x<49296)this.read(x);else if(x<49408){var r=x>>4&15;this.slots[r-8]&&this.slots[r-8].write(x&15,a),this.probe.logIOWrite(x,a)}else x>=53248&&!this.writeinhibit&&(x>=57344?this.ram[x]=a:this.ram[x+this.bank2wroffset]=a)}floatbus(){var x=this.frameCycles,a=Math.floor(x/65),r=Math.floor(x%65),t=this.ap2disp.getAddressForScanline(a);return this.readConst(t+r)}connectVideo(x){super.connectVideo(x),this.ap2disp=this.pixels&&new l0(this.pixels,this.grparams)}startScanline(){}drawScanline(){}advanceFrame(x){var a=super.advanceFrame(x);return this.ap2disp&&this.ap2disp.updateScreen(),a}postFrame(){this.paddleLastTriggered-=this.frameCycles,this.paddleLastTriggered<-this.cpuCyclesPaddleMax&&(this.paddleLastTriggered=-this.cpuCyclesPaddleMax)}advanceCPU(){return this.audio.feedSample(this.soundstate,1),super.advanceCPU()}setKeyInput(x,a,r){if(console.log(`setKeyInput: ${x} ${a} ${r}`),r&1){switch(a=0,x){case 16:case 17:case 18:case 91:return;case 8:if(a=8,r&2){this.cpu.reset();return}break;case 13:a=13;break;case 27:a=27;break;case 37:a=8;break;case 39:a=21;break;case 38:a=11;break;case 40:a=10;break;case 48:a=r&2?41:48;break;case 49:a=r&2?33:49;break;case 50:a=r&2?64:50;break;case 51:a=r&2?35:51;break;case 52:a=r&2?36:52;break;case 53:a=r&2?37:53;break;case 54:a=r&2?94:54;break;case 55:a=r&2?38:55;break;case 56:a=r&2?42:56;break;case 57:a=r&2?40:57;break;case 61:a=r&2?95:45;break;case 173:a=r&2?43:61;break;case 59:a=r&2?58:59;break;case 186:a=r&2?58:59;break;case 187:a=r&2?43:61;break;case 188:a=r&2?60:44;break;case 189:a=r&2?95:45;break;case 190:a=r&2?62:46;break;case 191:a=r&2?63:47;break;case 222:a=r&2?34:39;break;default:a=x,a>=97&&a<=122&&(a-=32),a>=65&&a<91&&r&4&&(a-=64)}a&&(this.kbdlatch=(a|128)&255)}}setPaddleInput(x,a){x>=0&&x=0&&x>1&3,a==(t-1&3)?t>0&&t--:a==(t+1&3)&&t>1],console.log("track",t/2)):this.track_data=null,this.track=t;break;case 8:this.motor=!1;break;case 9:this.motor=!0;break;case 10:break;case 11:break;case 15:this.read_mode=!1;case 12:if(this.read_mode)return this.read_latch();break;case 14:this.read_mode=!0;case 13:return x>=0&&!this.read_mode&&!this.write_protect&&this.write_latch(x),this.write_protect?128:0}return this.emu.floatbus()}},G=[150,151,154,155,157,158,159,166,167,171,172,173,174,175,178,179,180,181,182,183,185,186,187,188,189,190,191,203,205,206,207,211,214,215,217,218,219,220,221,222,223,229,230,231,233,234,235,236,237,238,239,242,243,244,245,246,247,249,250,251,252,253,254,255],m0=[0,7,14,6,13,5,12,4,11,3,10,2,9,1,8,15];function g0(n,e,x,a,r,t,c){var f,g,C,u,m=new Uint8Array(258);for(u=0,f=0;f<14;f++)t[c++]=255;for(t[c++]=213,t[c++]=170,t[c++]=150,t[c++]=n>>1|170,t[c++]=n|170,g=n,t[c++]=e>>1|170,t[c++]=e|170,g^=e,t[c++]=x>>1|170,t[c++]=x|170,g^=x,t[c++]=g>>1|170,t[c++]=g|170,t[c++]=222,t[c++]=170,t[c++]=235,f=0;f<6;f++)t[c++]=255;for(t[c++]=213,t[c++]=170,t[c++]=173,f=0;f<256;f++)m[f]=a[f+r]&255;for(m[256]=0,m[257]=0,C=0,f=0;f<86;f++)u=(m[f]&1)<<1,u|=(m[f]&2)>>1,u|=(m[f+86]&1)<<3,u|=(m[f+86]&2)<<1,u|=(m[f+172]&1)<<5,u|=(m[f+172]&2)<<3,t[c++]=G[u^C],C=u;for(f=0;f<256;f++)u=m[f]>>2,t[c++]=G[u^C],C=u;t[c++]=G[u],t[c++]=222,t[c++]=170,t[c++]=235}function p0(n,e,x){for(var a=new Uint8Array(F),r=0,t=0;t<16;t++)g0(n,e,t,x,m0[t]<<8,a,r),r+=A0;for(;rx.endsWith(".lnk")?"merlin32":O(x)}newMachine(){return new P}getPresets(){return n0}getDefaultExtensions(){return[...super.getDefaultExtensions(),".lnk"]}readAddress(x){return this.machine.readConst(x)}getROMExtension(x){return x&&x.length==560*256?".dsk":".bin"}};U["apple2.mame"]=T;U.apple2=Z; -//# sourceMappingURL=apple2-VXIPT7OL.js.map +//# sourceMappingURL=apple2-3KOIXQGR.js.map diff --git a/gen/apple2-VXIPT7OL.js.map b/gen/apple2-3KOIXQGR.js.map similarity index 100% rename from gen/apple2-VXIPT7OL.js.map rename to gen/apple2-3KOIXQGR.js.map diff --git a/gen/arm32-DPNHXLE7.js b/gen/arm32-JOUZ3MAF.js similarity index 99% rename from gen/arm32-DPNHXLE7.js rename to gen/arm32-JOUZ3MAF.js index e91dda3a..6c4141ad 100644 --- a/gen/arm32-DPNHXLE7.js +++ b/gen/arm32-JOUZ3MAF.js @@ -1,4 +1,4 @@ -import{F as Rr,I as gr,r as mr}from"./chunk-G4HBIXG4.js";import{E as or,K as Fr,T as N,W as T,X as hr,Z as fr,a as Q,aa as er,g as E}from"./chunk-TYDI7JZQ.js";import{a as pr,b as nr}from"./chunk-KT7KMEQC.js";var Cr=4026531840,lr=223,Tr=32;function n(r){this.cpu=r,this.addressingMode23Immediate=[function(t,i,s){var e=r.gprs,a=function(){var c=e[t];return(!s||s())&&(e[t]-=i),c};return a.writesPC=t==15,a},null,null,null,function(t,i,s){var e=r.gprs,a=function(){var c=e[t];return(!s||s())&&(e[t]+=i),c};return a.writesPC=t==15,a},null,null,null,function(t,i,s){var e=r.gprs,a=function(){return e[t]-i};return a.writesPC=!1,a},function(t,i,s){var e=r.gprs,a=function(){var c=e[t]-i;return(!s||s())&&(e[t]=c),c};return a.writesPC=t==15,a},null,null,function(t,i,s){var e=r.gprs,a=function(){return e[t]+i};return a.writesPC=!1,a},function(t,i,s){var e=r.gprs,a=function(){var c=e[t]+i;return(!s||s())&&(e[t]=c),c};return a.writesPC=t==15,a},null,null],this.addressingMode23Register=[function(t,i,s){var e=r.gprs,a=function(){var c=e[t];return(!s||s())&&(e[t]-=e[i]),c};return a.writesPC=t==15,a},null,null,null,function(t,i,s){var e=r.gprs,a=function(){var c=e[t];return(!s||s())&&(e[t]+=e[i]),c};return a.writesPC=t==15,a},null,null,null,function(t,i,s){var e=r.gprs,a=function(){return e[t]-e[i]};return a.writesPC=!1,a},function(t,i,s){var e=r.gprs,a=function(){var c=e[t]-e[i];return(!s||s())&&(e[t]=c),c};return a.writesPC=t==15,a},null,null,function(t,i,s){var e=r.gprs,a=function(){var c=e[t]+e[i];return c};return a.writesPC=!1,a},function(t,i,s){var e=r.gprs,a=function(){var c=e[t]+e[i];return(!s||s())&&(e[t]=c),c};return a.writesPC=t==15,a},null,null],this.addressingMode2RegisterShifted=[function(t,i,s){var e=r.gprs,a=function(){var c=e[t];return(!s||s())&&(i(),e[t]-=r.shifterOperand),c};return a.writesPC=t==15,a},null,null,null,function(t,i,s){var e=r.gprs,a=function(){var c=e[t];return(!s||s())&&(i(),e[t]+=r.shifterOperand),c};return a.writesPC=t==15,a},null,null,null,function(t,i,s){var e=r.gprs,a=function(){return i(),e[t]-r.shifterOperand};return a.writesPC=!1,a},function(t,i,s){var e=r.gprs,a=function(){i();var c=e[t]-r.shifterOperand;return(!s||s())&&(e[t]=c),c};return a.writesPC=t==15,a},null,null,function(t,i,s){var e=r.gprs,a=function(){return i(),e[t]+r.shifterOperand};return a.writesPC=!1,a},function(t,i,s){var e=r.gprs,a=function(){i();var c=e[t]+r.shifterOperand;return(!s||s())&&(e[t]=c),c};return a.writesPC=t==15,a},null,null]}n.prototype.constructAddressingMode1ASR=function(r,t){var i=this.cpu,s=i.gprs;return function(){++i.cycles;var e=s[r];r==15&&(e+=4),e&=255;var a=s[t];t==15&&(a+=4),e==0?(i.shifterOperand=a,i.shifterCarryOut=i.cpsrC):e<32?(i.shifterOperand=a>>e,i.shifterCarryOut=a&1<>31?(i.shifterOperand=4294967295,i.shifterCarryOut=2147483648):(i.shifterOperand=0,i.shifterCarryOut=0)}};n.prototype.constructAddressingMode1Immediate=function(r){var t=this.cpu;return function(){t.shifterOperand=r,t.shifterCarryOut=t.cpsrC}};n.prototype.constructAddressingMode1ImmediateRotate=function(r,t){var i=this.cpu;return function(){i.shifterOperand=r>>>t|r<<32-t,i.shifterCarryOut=i.shifterOperand>>31}};n.prototype.constructAddressingMode1LSL=function(r,t){var i=this.cpu,s=i.gprs;return function(){++i.cycles;var e=s[r];r==15&&(e+=4),e&=255;var a=s[t];t==15&&(a+=4),e==0?(i.shifterOperand=a,i.shifterCarryOut=i.cpsrC):e<32?(i.shifterOperand=a<>>e,i.shifterCarryOut=a&1<>31):(i.shifterOperand=0,i.shifterCarryOut=0)}};n.prototype.constructAddressingMode1ROR=function(r,t){var i=this.cpu,s=i.gprs;return function(){++i.cycles;var e=s[r];r==15&&(e+=4),e&=255;var a=s[t];t==15&&(a+=4);var c=e&31;e==0?(i.shifterOperand=a,i.shifterCarryOut=i.cpsrC):c?(i.shifterOperand=s[t]>>>c|s[t]<<32-c,i.shifterCarryOut=a&1<>31)}};n.prototype.constructAddressingMode23Immediate=function(r,t,i){var s=(r&983040)>>16;return this.addressingMode23Immediate[(r&27262976)>>21](s,t,i)};n.prototype.constructAddressingMode23Register=function(r,t,i){var s=(r&983040)>>16;return this.addressingMode23Register[(r&27262976)>>21](s,t,i)};n.prototype.constructAddressingMode2RegisterShifted=function(r,t,i){var s=(r&983040)>>16;return this.addressingMode2RegisterShifted[(r&27262976)>>21](s,t,i)};n.prototype.constructAddressingMode4=function(r,t){var i=this.cpu,s=i.gprs;return function(){var e=s[t]+r;return e}};n.prototype.constructAddressingMode4Writeback=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(c){var u=a[i]+r;return c&&s&&e.mmu.store32(a[i]+r-4,a[i]),a[i]+=t,u}};n.prototype.constructNOP=function(){return this.writesPC=!1,function(){}};n.prototype.constructADC=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=(e.shifterOperand>>>0)+(e.cpsrC?1:0);a[r]=(a[t]>>>0)+c}}};n.prototype.constructADCS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=(e.shifterOperand>>>0)+(e.cpsrC?1:0),u=(a[t]>>>0)+c;r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=u>>31,e.cpsrZ=!(u&4294967295),e.cpsrC=u>4294967295,e.cpsrV=a[t]>>31==c>>31&&a[t]>>31!=u>>31&&c>>31!=u>>31),a[r]=u}}};n.prototype.constructADD=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=(a[t]>>>0)+(e.shifterOperand>>>0))}};n.prototype.constructADDS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=(a[t]>>>0)+(e.shifterOperand>>>0);r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=c>>31,e.cpsrZ=!(c&4294967295),e.cpsrC=c>4294967295,e.cpsrV=a[t]>>31==e.shifterOperand>>31&&a[t]>>31!=c>>31&&e.shifterOperand>>31!=c>>31),a[r]=c}}};n.prototype.constructAND=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=a[t]&e.shifterOperand)}};n.prototype.constructANDS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=a[t]&e.shifterOperand,r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=a[r]>>31,e.cpsrZ=!(a[r]&4294967295),e.cpsrC=e.shifterCarryOut))}};n.prototype.constructB=function(r,t){var i=this.cpu,s=i.gprs;return function(){if(t&&!t()){i.mmu.waitPrefetch32(s[15]);return}i.mmu.waitPrefetch32(s[15]),s[15]+=r}};n.prototype.constructBIC=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=a[t]&~e.shifterOperand)}};n.prototype.constructBICS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=a[t]&~e.shifterOperand,r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=a[r]>>31,e.cpsrZ=!(a[r]&4294967295),e.cpsrC=e.shifterCarryOut))}};n.prototype.constructBL=function(r,t){var i=this.cpu,s=i.gprs;return function(){if(t&&!t()){i.mmu.waitPrefetch32(s[15]);return}i.mmu.waitPrefetch32(s[15]),s[14]=s[15]-4,s[15]+=r}};n.prototype.constructBX=function(r,t){var i=this.cpu,s=i.gprs;return function(){if(t&&!t()){i.mmu.waitPrefetch32(s[15]);return}i.mmu.waitPrefetch32(s[15]),i.switchExecMode(s[r]&1),s[15]=s[r]&4294967294}};n.prototype.constructCMN=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=(a[t]>>>0)+(e.shifterOperand>>>0);e.cpsrN=c>>31,e.cpsrZ=!(c&4294967295),e.cpsrC=c>4294967295,e.cpsrV=a[t]>>31==e.shifterOperand>>31&&a[t]>>31!=c>>31&&e.shifterOperand>>31!=c>>31}}};n.prototype.constructCMP=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=a[t]-e.shifterOperand;e.cpsrN=c>>31,e.cpsrZ=!(c&4294967295),e.cpsrC=a[t]>>>0>=e.shifterOperand>>>0,e.cpsrV=a[t]>>31!=e.shifterOperand>>31&&a[t]>>31!=c>>31}}};n.prototype.constructEOR=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=a[t]^e.shifterOperand)}};n.prototype.constructEORS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=a[t]^e.shifterOperand,r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=a[r]>>31,e.cpsrZ=!(a[r]&4294967295),e.cpsrC=e.shifterCarryOut))}};n.prototype.constructLDM=function(r,t,i){var s=this.cpu,e=s.gprs,a=s.mmu;return function(){if(a.waitPrefetch32(e[15]),!(i&&!i())){var c=t(!1),u=0,p,F;for(p=r,F=0;p;p>>=1,++F)p&1&&(e[F]=a.load32(c&4294967292),c+=4,++u);a.waitMulti32(c,u),++s.cycles}}};n.prototype.constructLDMS=function(r,t,i){var s=this.cpu,e=s.gprs,a=s.mmu;return function(){if(a.waitPrefetch32(e[15]),!(i&&!i())){var c=t(!1),u=0,p=s.mode;s.switchMode(31);var F,R;for(F=r,R=0;F;F>>=1,++R)F&1&&(e[R]=a.load32(c&4294967292),c+=4,++u);s.switchMode(p),a.waitMulti32(c,u),++s.cycles}}};n.prototype.constructLDR=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){if(s.mmu.waitPrefetch32(e[15]),!(i&&!i())){var a=t();e[r]=s.mmu.load32(a),s.mmu.wait32(a),++s.cycles}}};n.prototype.constructLDRB=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){if(s.mmu.waitPrefetch32(e[15]),!(i&&!i())){var a=t();e[r]=s.mmu.loadU8(a),s.mmu.wait(a),++s.cycles}}};n.prototype.constructLDRH=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){if(s.mmu.waitPrefetch32(e[15]),!(i&&!i())){var a=t();e[r]=s.mmu.loadU16(a),s.mmu.wait(a),++s.cycles}}};n.prototype.constructLDRSB=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){if(s.mmu.waitPrefetch32(e[15]),!(i&&!i())){var a=t();e[r]=s.mmu.load8(a),s.mmu.wait(a),++s.cycles}}};n.prototype.constructLDRSH=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){if(s.mmu.waitPrefetch32(e[15]),!(i&&!i())){var a=t();e[r]=s.mmu.load16(a),s.mmu.wait(a),++s.cycles}}};n.prototype.constructMLA=function(r,t,i,s,e){var a=this.cpu,c=a.gprs;return function(){if(a.mmu.waitPrefetch32(c[15]),!(e&&!e()))if(++a.cycles,a.mmu.waitMul(i),c[s]&4294901760&&c[i]&4294901760){var u=(c[s]&4294901760)*c[i]&4294967295,p=(c[s]&65535)*c[i]&4294967295;c[r]=u+p+c[t]&4294967295}else c[r]=c[s]*c[i]+c[t]}};n.prototype.constructMLAS=function(r,t,i,s,e){var a=this.cpu,c=a.gprs;return function(){if(a.mmu.waitPrefetch32(c[15]),!(e&&!e())){if(++a.cycles,a.mmu.waitMul(i),c[s]&4294901760&&c[i]&4294901760){var u=(c[s]&4294901760)*c[i]&4294967295,p=(c[s]&65535)*c[i]&4294967295;c[r]=u+p+c[t]&4294967295}else c[r]=c[s]*c[i]+c[t];a.cpsrN=c[r]>>31,a.cpsrZ=!(c[r]&4294967295)}}};n.prototype.constructMOV=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=e.shifterOperand)}};n.prototype.constructMOVS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=e.shifterOperand,r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=a[r]>>31,e.cpsrZ=!(a[r]&4294967295),e.cpsrC=e.shifterCarryOut))}};n.prototype.constructMRS=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){s.mmu.waitPrefetch32(e[15]),!(i&&!i())&&(t?e[r]=s.spsr:e[r]=s.packCPSR())}};n.prototype.constructMSR=function(r,t,i,s,e){var a=this.cpu,c=a.gprs,u=i&65536,p=i&524288;return function(){if(a.mmu.waitPrefetch32(c[15]),!(e&&!e())){var F;i&33554432?F=s:F=c[r];var R=(u?255:0)|(p?4278190080:0);t?(R&=Cr|lr|Tr,a.spsr=a.spsr&~R|F&R):(R&Cr&&(a.cpsrN=F>>31,a.cpsrZ=F&1073741824,a.cpsrC=F&536870912,a.cpsrV=F&268435456),a.mode!=16&&R&lr&&(a.switchMode(F&15|16),a.cpsrI=F&128,a.cpsrF=F&64))}}};n.prototype.constructMUL=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s()))if(e.mmu.waitMul(a[t]),a[i]&4294901760&&a[t]&4294901760){var c=(a[i]&4294901760)*a[t]|0,u=(a[i]&65535)*a[t]|0;a[r]=c+u}else a[r]=a[i]*a[t]}};n.prototype.constructMULS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){if(e.mmu.waitMul(a[t]),a[i]&4294901760&&a[t]&4294901760){var c=(a[i]&4294901760)*a[t]|0,u=(a[i]&65535)*a[t]|0;a[r]=c+u}else a[r]=a[i]*a[t];e.cpsrN=a[r]>>31,e.cpsrZ=!(a[r]&4294967295)}}};n.prototype.constructMVN=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=~e.shifterOperand)}};n.prototype.constructMVNS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=~e.shifterOperand,r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=a[r]>>31,e.cpsrZ=!(a[r]&4294967295),e.cpsrC=e.shifterCarryOut))}};n.prototype.constructORR=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=a[t]|e.shifterOperand)}};n.prototype.constructORRS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=a[t]|e.shifterOperand,r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=a[r]>>31,e.cpsrZ=!(a[r]&4294967295),e.cpsrC=e.shifterCarryOut))}};n.prototype.constructRSB=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=e.shifterOperand-a[t])}};n.prototype.constructRSBS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=e.shifterOperand-a[t];r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=c>>31,e.cpsrZ=!(c&4294967295),e.cpsrC=e.shifterOperand>>>0>=a[t]>>>0,e.cpsrV=e.shifterOperand>>31!=a[t]>>31&&e.shifterOperand>>31!=c>>31),a[r]=c}}};n.prototype.constructRSC=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=(a[t]>>>0)+(e.cpsrC?0:1);a[r]=(e.shifterOperand>>>0)-c}}};n.prototype.constructRSCS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=(a[t]>>>0)+(e.cpsrC?0:1),u=(e.shifterOperand>>>0)-c;r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=u>>31,e.cpsrZ=!(u&4294967295),e.cpsrC=e.shifterOperand>>>0>=u>>>0,e.cpsrV=e.shifterOperand>>31!=c>>31&&e.shifterOperand>>31!=u>>31),a[r]=u}}};n.prototype.constructSBC=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=(e.shifterOperand>>>0)+(e.cpsrC?0:1);a[r]=(a[t]>>>0)-c}}};n.prototype.constructSBCS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=(e.shifterOperand>>>0)+(e.cpsrC?0:1),u=(a[t]>>>0)-c;r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=u>>31,e.cpsrZ=!(u&4294967295),e.cpsrC=a[t]>>>0>=u>>>0,e.cpsrV=a[t]>>31!=c>>31&&a[t]>>31!=u>>31),a[r]=u}}};n.prototype.constructSMLAL=function(r,t,i,s,e){var a=this.cpu,c=1/4294967296,u=a.gprs;return function(){if(a.mmu.waitPrefetch32(u[15]),!(e&&!e())){a.cycles+=2,a.mmu.waitMul(i);var p=(u[s]&4294901760)*u[i],F=(u[s]&65535)*u[i],R=(u[t]>>>0)+p+F;u[t]=R,u[r]+=Math.floor(R*c)}}};n.prototype.constructSMLALS=function(r,t,i,s,e){var a=this.cpu,c=1/4294967296,u=a.gprs;return function(){if(a.mmu.waitPrefetch32(u[15]),!(e&&!e())){a.cycles+=2,a.mmu.waitMul(i);var p=(u[s]&4294901760)*u[i],F=(u[s]&65535)*u[i],R=(u[t]>>>0)+p+F;u[t]=R,u[r]+=Math.floor(R*c),a.cpsrN=u[r]>>31,a.cpsrZ=!(u[r]&4294967295||u[t]&4294967295)}}};n.prototype.constructSMULL=function(r,t,i,s,e){var a=this.cpu,c=1/4294967296,u=a.gprs;return function(){if(a.mmu.waitPrefetch32(u[15]),!(e&&!e())){++a.cycles,a.mmu.waitMul(u[i]);var p=((u[s]&4294901760)>>0)*(u[i]>>0),F=((u[s]&65535)>>0)*(u[i]>>0);u[t]=(p&4294967295)+(F&4294967295)&4294967295,u[r]=Math.floor(p*c+F*c)}}};n.prototype.constructSMULLS=function(r,t,i,s,e){var a=this.cpu,c=1/4294967296,u=a.gprs;return function(){if(a.mmu.waitPrefetch32(u[15]),!(e&&!e())){++a.cycles,a.mmu.waitMul(u[i]);var p=((u[s]&4294901760)>>0)*(u[i]>>0),F=((u[s]&65535)>>0)*(u[i]>>0);u[t]=(p&4294967295)+(F&4294967295)&4294967295,u[r]=Math.floor(p*c+F*c),a.cpsrN=u[r]>>31,a.cpsrZ=!(u[r]&4294967295||u[t]&4294967295)}}};n.prototype.constructSTM=function(r,t,i){var s=this.cpu,e=s.gprs,a=s.mmu;return function(){if(i&&!i()){a.waitPrefetch32(e[15]);return}a.wait32(e[15]);var c=t(!0),u=0,p,F;for(p=r,F=0;p;p>>=1,++F)p&1&&(a.store32(c,e[F]),c+=4,++u);a.waitMulti32(c,u)}};n.prototype.constructSTMS=function(r,t,i){var s=this.cpu,e=s.gprs,a=s.mmu;return function(){if(i&&!i()){a.waitPrefetch32(e[15]);return}a.wait32(e[15]);var c=s.mode,u=t(!0),p=0,F,R;for(s.switchMode(31),F=r,R=0;F;F>>=1,++R)F&1&&(a.store32(u,e[R]),u+=4,++p);s.switchMode(c),a.waitMulti32(u,p)}};n.prototype.constructSTR=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){if(i&&!i()){s.mmu.waitPrefetch32(e[15]);return}var a=t();s.mmu.store32(a,e[r]),s.mmu.wait32(a),s.mmu.wait32(e[15])}};n.prototype.constructSTRB=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){if(i&&!i()){s.mmu.waitPrefetch32(e[15]);return}var a=t();s.mmu.store8(a,e[r]),s.mmu.wait(a),s.mmu.wait32(e[15])}};n.prototype.constructSTRH=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){if(i&&!i()){s.mmu.waitPrefetch32(e[15]);return}var a=t();s.mmu.store16(a,e[r]),s.mmu.wait(a),s.mmu.wait32(e[15])}};n.prototype.constructSUB=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=a[t]-e.shifterOperand)}};n.prototype.constructSUBS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=a[t]-e.shifterOperand;r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=c>>31,e.cpsrZ=!(c&4294967295),e.cpsrC=a[t]>>>0>=e.shifterOperand>>>0,e.cpsrV=a[t]>>31!=e.shifterOperand>>31&&a[t]>>31!=c>>31),a[r]=c}}};n.prototype.constructSWI=function(r,t){var i=this.cpu,s=i.gprs;return function(){if(t&&!t()){i.mmu.waitPrefetch32(s[15]);return}i.irq.swi32(r),i.mmu.waitPrefetch32(s[15])}};n.prototype.constructSWP=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){e.mmu.wait32(a[t]),e.mmu.wait32(a[t]);var c=e.mmu.load32(a[t]);e.mmu.store32(a[t],a[i]),a[r]=c,++e.cycles}}};n.prototype.constructSWPB=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){e.mmu.wait(a[t]),e.mmu.wait(a[t]);var c=e.mmu.loadU8(a[t]);e.mmu.store8(a[t],a[i]),a[r]=c,++e.cycles}}};n.prototype.constructTEQ=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=a[t]^e.shifterOperand;e.cpsrN=c>>31,e.cpsrZ=!(c&4294967295),e.cpsrC=e.shifterCarryOut}}};n.prototype.constructTST=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=a[t]&e.shifterOperand;e.cpsrN=c>>31,e.cpsrZ=!(c&4294967295),e.cpsrC=e.shifterCarryOut}}};n.prototype.constructUMLAL=function(r,t,i,s,e){var a=this.cpu,c=1/4294967296,u=a.gprs;return function(){if(a.mmu.waitPrefetch32(u[15]),!(e&&!e())){a.cycles+=2,a.mmu.waitMul(i);var p=((u[s]&4294901760)>>>0)*(u[i]>>>0),F=(u[s]&65535)*(u[i]>>>0),R=(u[t]>>>0)+p+F;u[t]=R,u[r]+=R*c}}};n.prototype.constructUMLALS=function(r,t,i,s,e){var a=this.cpu,c=1/4294967296,u=a.gprs;return function(){if(a.mmu.waitPrefetch32(u[15]),!(e&&!e())){a.cycles+=2,a.mmu.waitMul(i);var p=((u[s]&4294901760)>>>0)*(u[i]>>>0),F=(u[s]&65535)*(u[i]>>>0),R=(u[t]>>>0)+p+F;u[t]=R,u[r]+=R*c,a.cpsrN=u[r]>>31,a.cpsrZ=!(u[r]&4294967295||u[t]&4294967295)}}};n.prototype.constructUMULL=function(r,t,i,s,e){var a=this.cpu,c=1/4294967296,u=a.gprs;return function(){if(a.mmu.waitPrefetch32(u[15]),!(e&&!e())){++a.cycles,a.mmu.waitMul(u[i]);var p=((u[s]&4294901760)>>>0)*(u[i]>>>0),F=((u[s]&65535)>>>0)*(u[i]>>>0);u[t]=(p&4294967295)+(F&4294967295)&4294967295,u[r]=p*c+F*c>>>0}}};n.prototype.constructUMULLS=function(r,t,i,s,e){var a=this.cpu,c=1/4294967296,u=a.gprs;return function(){if(a.mmu.waitPrefetch32(u[15]),!(e&&!e())){++a.cycles,a.mmu.waitMul(u[i]);var p=((u[s]&4294901760)>>>0)*(u[i]>>>0),F=((u[s]&65535)>>>0)*(u[i]>>>0);u[t]=(p&4294967295)+(F&4294967295)&4294967295,u[r]=p*c+F*c>>>0,a.cpsrN=u[r]>>31,a.cpsrZ=!(u[r]&4294967295||u[t]&4294967295)}}};n.prototype.constructVFP3Register=function(r,t,i,s,e,a,c){var u=this.cpu,p=e?u.dfprs:u.sfprs;return function(){if(u.mmu.waitPrefetch32(u.gprs[15]),!(r&&!r())){switch(t){case 2:switch(a){case 0:p[s]=p[i]*p[c];return}break;case 3:switch(a){case 0:p[s]=p[i]+p[c];return;case 2:p[s]=p[i]-p[c];return}break;case 8:switch(a){case 0:p[s]=p[i]/p[c];return}break}console.log("Unsupported instruction: "+E(t)+" "+E(a))}}};n.prototype.constructVCVT=function(r,t,i,s,e,a,c,u){var p=this.cpu,F=p.sfprs,R=p.dfprs,m=p.ifprs;return function(){if(p.mmu.waitPrefetch32(p.gprs[15]),!(r&&!r())){var v,o;s&&e?v=R[i]:s?v=F[i]:v=m[i],s?o=c?Math.floor(v):Math.round(v):o=v,s?m[t]=o:e?R[t]=o:F[t]=o}}};n.prototype.constructVCVTF=function(r,t,i,s){var e=this.cpu,a=e.sfprs,c=e.dfprs;return function(){if(e.mmu.waitPrefetch32(e.gprs[15]),!(r&&!r())){var u=s?c[i]:a[i];s?a[t]=u:c[t]=u}}};n.prototype.constructVLDR=function(r,t,i,s){var e=this.cpu,a=e.ifprs;return function(){if(e.mmu.waitPrefetch32(e.gprs[15]),r&&!r())return;let c=i();s?a[t]=e.mmu.load32(c):(a[t]=e.mmu.load32(c),a[t+1]=e.mmu.load32(c+4)),e.mmu.wait32(c),e.mmu.wait32(e.gprs[15])}};n.prototype.constructVSTR=function(r,t,i,s){var e=this.cpu,a=e.ifprs;return function(){if(e.mmu.waitPrefetch32(e.gprs[15]),r&&!r())return;let c=i();s?e.mmu.store32(c,a[t]):(e.mmu.store32(c,a[t]),e.mmu.store32(c+4,a[t+1])),e.mmu.wait32(c),e.mmu.wait32(e.gprs[15])}};n.prototype.constructVPUSH=function(r,t,i,s){var e=this.cpu,a=e.ifprs;return function(){if(e.mmu.waitPrefetch32(e.gprs[15]),r&&!r())return;let c=e.gprs[13]-i*4;e.gprs[13]=c;for(let u=0;u>>0)+(i.cpsrC?1:0),a=s[r],c=(a>>>0)+e,u=a>>31,p=c>>31,F=e>>31;i.cpsrN=p,i.cpsrZ=!(c&4294967295),i.cpsrC=c>4294967295,i.cpsrV=u==F&&u!=p&&F!=p,s[r]=c}};h.prototype.constructADD1=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){s.mmu.waitPrefetch(e[15]);var a=(e[t]>>>0)+i;s.cpsrN=a>>31,s.cpsrZ=!(a&4294967295),s.cpsrC=a>4294967295,s.cpsrV=!(e[t]>>31)&&(e[t]>>31^a)>>31&&a>>31,e[r]=a}};h.prototype.constructADD2=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=(s[r]>>>0)+t;i.cpsrN=e>>31,i.cpsrZ=!(e&4294967295),i.cpsrC=e>4294967295,i.cpsrV=!(s[r]>>31)&&(s[r]^e)>>31&&(t^e)>>31,s[r]=e}};h.prototype.constructADD3=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){s.mmu.waitPrefetch(e[15]);var a=(e[t]>>>0)+(e[i]>>>0);s.cpsrN=a>>31,s.cpsrZ=!(a&4294967295),s.cpsrC=a>4294967295,s.cpsrV=!((e[t]^e[i])>>31)&&(e[t]^a)>>31&&(e[i]^a)>>31,e[r]=a}};h.prototype.constructADD4=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),s[r]+=s[t]}};h.prototype.constructADD5=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),s[r]=(s[15]&4294967292)+t}};h.prototype.constructADD6=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),s[r]=s[13]+t}};h.prototype.constructADD7=function(r){var t=this.cpu,i=t.gprs;return function(){t.mmu.waitPrefetch(i[15]),i[13]+=r}};h.prototype.constructAND=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),s[r]=s[r]&s[t],i.cpsrN=s[r]>>31,i.cpsrZ=!(s[r]&4294967295)}};h.prototype.constructASR1=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){s.mmu.waitPrefetch(e[15]),i==0?(s.cpsrC=e[t]>>31,s.cpsrC?e[r]=4294967295:e[r]=0):(s.cpsrC=e[t]&1<>i),s.cpsrN=e[r]>>31,s.cpsrZ=!(e[r]&4294967295)}};h.prototype.constructASR2=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=s[t]&255;e&&(e<32?(i.cpsrC=s[r]&1<>=e):(i.cpsrC=s[r]>>31,i.cpsrC?s[r]=4294967295:s[r]=0)),i.cpsrN=s[r]>>31,i.cpsrZ=!(s[r]&4294967295)}};h.prototype.constructB1=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),t()&&(s[15]+=r)}};h.prototype.constructB2=function(r){var t=this.cpu,i=t.gprs;return function(){t.mmu.waitPrefetch(i[15]),i[15]+=r}};h.prototype.constructBIC=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),s[r]=s[r]&~s[t],i.cpsrN=s[r]>>31,i.cpsrZ=!(s[r]&4294967295)}};h.prototype.constructBL1=function(r){var t=this.cpu,i=t.gprs;return function(){t.mmu.waitPrefetch(i[15]),i[14]=i[15]+r}};h.prototype.constructBL2=function(r){var t=this.cpu,i=t.gprs;return function(){t.mmu.waitPrefetch(i[15]);var s=i[15];i[15]=i[14]+(r<<1),i[14]=s-1}};h.prototype.constructBX=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),i.switchExecMode(s[t]&1);var e=0;t==15&&(e=s[t]&2),s[15]=s[t]&4294967294-e}};h.prototype.constructCMN=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=(s[r]>>>0)+(s[t]>>>0);i.cpsrN=e>>31,i.cpsrZ=!(e&4294967295),i.cpsrC=e>4294967295,i.cpsrV=s[r]>>31==s[t]>>31&&s[r]>>31!=e>>31&&s[t]>>31!=e>>31}};h.prototype.constructCMP1=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=s[r]-t;i.cpsrN=e>>31,i.cpsrZ=!(e&4294967295),i.cpsrC=s[r]>>>0>=t,i.cpsrV=s[r]>>31&&(s[r]^e)>>31}};h.prototype.constructCMP2=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=s[r],a=s[t],c=e-a,u=c>>31,p=e>>31;i.cpsrN=u,i.cpsrZ=!(c&4294967295),i.cpsrC=e>>>0>=a>>>0,i.cpsrV=p!=a>>31&&p!=u}};h.prototype.constructCMP3=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=s[r]-s[t];i.cpsrN=e>>31,i.cpsrZ=!(e&4294967295),i.cpsrC=s[r]>>>0>=s[t]>>>0,i.cpsrV=(s[r]^s[t])>>31&&(s[r]^e)>>31}};h.prototype.constructEOR=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),s[r]=s[r]^s[t],i.cpsrN=s[r]>>31,i.cpsrZ=!(s[r]&4294967295)}};h.prototype.constructLDMIA=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=s[r],a=0,c,u;for(c=1,u=0;u<8;c<<=1,++u)t&c&&(s[u]=i.mmu.load32(e),e+=4,++a);i.mmu.waitMulti32(e,a),1<>31,s.cpsrZ=!(e[r]&4294967295)}};h.prototype.constructLSL2=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=s[t]&255;e&&(e<32?(i.cpsrC=s[r]&1<<32-e,s[r]<<=e):(e>32?i.cpsrC=0:i.cpsrC=s[r]&1,s[r]=0)),i.cpsrN=s[r]>>31,i.cpsrZ=!(s[r]&4294967295)}};h.prototype.constructLSR1=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){s.mmu.waitPrefetch(e[15]),i==0?(s.cpsrC=e[t]>>31,e[r]=0):(s.cpsrC=e[t]&1<>>i),s.cpsrN=0,s.cpsrZ=!(e[r]&4294967295)}};h.prototype.constructLSR2=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=s[t]&255;e&&(e<32?(i.cpsrC=s[r]&1<>>=e):(e>32?i.cpsrC=0:i.cpsrC=s[r]>>31,s[r]=0)),i.cpsrN=s[r]>>31,i.cpsrZ=!(s[r]&4294967295)}};h.prototype.constructMOV1=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),s[r]=t,i.cpsrN=t>>31,i.cpsrZ=!(t&4294967295)}};h.prototype.constructMOV2=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){s.mmu.waitPrefetch(e[15]);var a=e[t];s.cpsrN=a>>31,s.cpsrZ=!(a&4294967295),s.cpsrC=0,s.cpsrV=0,e[r]=a}};h.prototype.constructMOV3=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),s[r]=s[t]}};h.prototype.constructMUL=function(r,t){var i=this.cpu,s=i.gprs;return function(){if(i.mmu.waitPrefetch(s[15]),i.mmu.waitMul(s[t]),s[t]&4294901760&&s[r]&4294901760){var e=(s[r]&4294901760)*s[t]&4294967295,a=(s[r]&65535)*s[t]&4294967295;s[r]=e+a&4294967295}else s[r]*=s[t];i.cpsrN=s[r]>>31,i.cpsrZ=!(s[r]&4294967295)}};h.prototype.constructMVN=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),s[r]=~s[t],i.cpsrN=s[r]>>31,i.cpsrZ=!(s[r]&4294967295)}};h.prototype.constructNEG=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=-s[t];i.cpsrN=e>>31,i.cpsrZ=!(e&4294967295),i.cpsrC=0>=e>>>0,i.cpsrV=s[t]>>31&&e>>31,s[r]=e}};h.prototype.constructORR=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),s[r]=s[r]|s[t],i.cpsrN=s[r]>>31,i.cpsrZ=!(s[r]&4294967295)}};h.prototype.constructPOP=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),++i.cycles;var e=s[13],a=0,c,u;for(c=1,u=0;u<8;c<<=1,++u)r&c&&(i.mmu.waitSeq32(e),s[u]=i.mmu.load32(e),e+=4,++a);t&&(s[15]=i.mmu.load32(e)&4294967294,e+=4,++a),i.mmu.waitMulti32(e,a),s[13]=e}};h.prototype.constructPUSH=function(r,t){var i=this.cpu,s=i.gprs;return function(){var e=s[13]-4,a=0;i.mmu.waitPrefetch(s[15]),t&&(i.mmu.store32(e,s[14]),e-=4,++a);var c,u;for(c=128,u=7;c;c>>=1,--u)if(r&c){i.mmu.store32(e,s[u]),e-=4,++a;break}for(c>>=1,--u;c;c>>=1,--u)r&c&&(i.mmu.store32(e,s[u]),e-=4,++a);i.mmu.waitMulti32(e,a),s[13]=e+4}};h.prototype.constructROR=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=s[t]&255;if(e){var a=e&31;a>0?(i.cpsrC=s[r]&1<>>a|s[r]<<32-a):i.cpsrC=s[r]>>31}i.cpsrN=s[r]>>31,i.cpsrZ=!(s[r]&4294967295)}};h.prototype.constructSBC=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=(s[t]>>>0)+(i.cpsrC?0:1),a=(s[r]>>>0)-e;i.cpsrN=a>>31,i.cpsrZ=!(a&4294967295),i.cpsrC=s[r]>>>0>=a>>>0,i.cpsrV=(s[r]^e)>>31&&(s[r]^a)>>31,s[r]=a}};h.prototype.constructSTMIA=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.wait(s[15]);var e=s[r],a=0,c,u;for(c=1,u=0;u<8;c<<=1,++u)if(t&c){i.mmu.store32(e,s[u]),e+=4,++a;break}for(c<<=1,++u;u<8;c<<=1,++u)t&c&&(i.mmu.store32(e,s[u]),e+=4,++a);i.mmu.waitMulti32(e,a),s[r]=e}};h.prototype.constructSTR1=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){var a=e[t]+i;s.mmu.store32(a,e[r]),s.mmu.wait(e[15]),s.mmu.wait32(a)}};h.prototype.constructSTR2=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){s.mmu.store32(e[t]+e[i],e[r]),s.mmu.wait(e[15]),s.mmu.wait32(e[t]+e[i])}};h.prototype.constructSTR3=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.store32(s[13]+t,s[r]),i.mmu.wait(s[15]),i.mmu.wait32(s[13]+t)}};h.prototype.constructSTRB1=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){var a=e[t]+i;s.mmu.store8(a,e[r]),s.mmu.wait(e[15]),s.mmu.wait(a)}};h.prototype.constructSTRB2=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){s.mmu.store8(e[t]+e[i],e[r]),s.mmu.wait(e[15]),s.mmu.wait(e[t]+e[i])}};h.prototype.constructSTRH1=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){var a=e[t]+i;s.mmu.store16(a,e[r]),s.mmu.wait(e[15]),s.mmu.wait(a)}};h.prototype.constructSTRH2=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){s.mmu.store16(e[t]+e[i],e[r]),s.mmu.wait(e[15]),s.mmu.wait(e[t]+e[i])}};h.prototype.constructSUB1=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){s.mmu.waitPrefetch(e[15]);var a=e[t]-i;s.cpsrN=a>>31,s.cpsrZ=!(a&4294967295),s.cpsrC=e[t]>>>0>=i,s.cpsrV=e[t]>>31&&(e[t]^a)>>31,e[r]=a}};h.prototype.constructSUB2=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=s[r]-t;i.cpsrN=e>>31,i.cpsrZ=!(e&4294967295),i.cpsrC=s[r]>>>0>=t,i.cpsrV=s[r]>>31&&(s[r]^e)>>31,s[r]=e}};h.prototype.constructSUB3=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){s.mmu.waitPrefetch(e[15]);var a=e[t]-e[i];s.cpsrN=a>>31,s.cpsrZ=!(a&4294967295),s.cpsrC=e[t]>>>0>=e[i]>>>0,s.cpsrV=e[t]>>31!=e[i]>>31&&e[t]>>31!=a>>31,e[r]=a}};h.prototype.constructSWI=function(r){var t=this.cpu,i=t.gprs;return function(){t.irq.swi(r),t.mmu.waitPrefetch(i[15])}};h.prototype.constructTST=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=s[r]&s[t];i.cpsrN=e>>31,i.cpsrZ=!(e&4294967295)}};function A(){this.SP=13,this.LR=14,this.PC=15,this.MODE_ARM=0,this.MODE_THUMB=1,this.MODE_USER=16,this.MODE_FIQ=17,this.MODE_IRQ=18,this.MODE_SUPERVISOR=19,this.MODE_ABORT=23,this.MODE_UNDEFINED=27,this.MODE_SYSTEM=31,this.BANK_NONE=0,this.BANK_FIQ=1,this.BANK_IRQ=2,this.BANK_SUPERVISOR=3,this.BANK_ABORT=4,this.BANK_UNDEFINED=5,this.WORD_SIZE_ARM=4,this.WORD_SIZE_THUMB=2,this.BASE_RESET=0,this.BASE_UNDEF=4,this.BASE_SWI=8,this.BASE_PABT=12,this.BASE_DABT=16,this.BASE_IRQ=24,this.BASE_FIQ=28,this.armCompiler=new n(this),this.thumbCompiler=new h(this),this.generateConds(),this.gprs=new Int32Array(16),this.dfprs=new Float64Array(16),this.sfprs=new Float32Array(this.dfprs.buffer),this.ifprs=new Int32Array(this.dfprs.buffer)}A.prototype.resetCPU=function(r){for(var t=0;t<15;++t)this.gprs[t]=0;this.gprs[15]=r+4,this.dfprs.set(0),this.loadInstruction=this.loadInstructionArm,this.execMode=0,this.instructionWidth=4,this.mode=31,this.cpsrI=!1,this.cpsrF=!1,this.cpsrV=!1,this.cpsrC=!1,this.cpsrZ=!1,this.cpsrN=!1,this.bankedRegisters=[new Int32Array(7),new Int32Array(7),new Int32Array(2),new Int32Array(2),new Int32Array(2),new Int32Array(2)],this.spsr=0,this.bankedSPSRs=new Int32Array(6),this.cycles=0,this.shifterOperand=0,this.shifterCarryOut=0,this.page=null,this.pageId=0,this.pageRegion=-1,this.instruction=null,this.irq.clear();var i=this.gprs,s=this.mmu;this.step=function(){var e=this.instruction||(this.instruction=this.loadInstruction(i[15]-this.instructionWidth));if(i[15]+=this.instructionWidth,this.conditionPassed=!0,e(),!e.writesPC)this.instruction!=null&&((e.next==null||e.next.page.invalid)&&(e.next=this.loadInstruction(i[15]-this.instructionWidth)),this.instruction=e.next);else if(this.conditionPassed){var a=i[15]&=4294967294;this.execMode==0?(s.wait32(a),s.waitPrefetch32(a)):(s.wait(a),s.waitPrefetch(a)),i[15]+=this.instructionWidth,e.fixedJump?this.instruction!=null&&((e.next==null||e.next.page.invalid)&&(e.next=this.loadInstruction(i[15]-this.instructionWidth)),this.instruction=e.next):this.instruction=null}else this.instruction=null;this.irq.updateTimers()}};A.prototype.freeze=function(){return{PC:this.gprs[15]-this.instructionWidth,SP:this.gprs[13],gprs:[this.gprs[0],this.gprs[1],this.gprs[2],this.gprs[3],this.gprs[4],this.gprs[5],this.gprs[6],this.gprs[7],this.gprs[8],this.gprs[9],this.gprs[10],this.gprs[11],this.gprs[12],this.gprs[13],this.gprs[14],this.gprs[15]],sfprs:this.sfprs.slice(),dfprs:this.dfprs.slice(),ifprs:this.ifprs.slice(),mode:this.mode,cpsrI:this.cpsrI,cpsrF:this.cpsrF,cpsrV:this.cpsrV,cpsrC:this.cpsrC,cpsrZ:this.cpsrZ,cpsrN:this.cpsrN,bankedRegisters:[[this.bankedRegisters[0][0],this.bankedRegisters[0][1],this.bankedRegisters[0][2],this.bankedRegisters[0][3],this.bankedRegisters[0][4],this.bankedRegisters[0][5],this.bankedRegisters[0][6]],[this.bankedRegisters[1][0],this.bankedRegisters[1][1],this.bankedRegisters[1][2],this.bankedRegisters[1][3],this.bankedRegisters[1][4],this.bankedRegisters[1][5],this.bankedRegisters[1][6]],[this.bankedRegisters[2][0],this.bankedRegisters[2][1]],[this.bankedRegisters[3][0],this.bankedRegisters[3][1]],[this.bankedRegisters[4][0],this.bankedRegisters[4][1]],[this.bankedRegisters[5][0],this.bankedRegisters[5][1]]],spsr:this.spsr,bankedSPSRs:[this.bankedSPSRs[0],this.bankedSPSRs[1],this.bankedSPSRs[2],this.bankedSPSRs[3],this.bankedSPSRs[4],this.bankedSPSRs[5]],cycles:this.cycles,instructionWidth:this.instructionWidth}};A.prototype.defrost=function(r){this.instruction=null,this.page=null,this.pageId=0,this.pageRegion=-1,this.gprs[0]=r.gprs[0],this.gprs[1]=r.gprs[1],this.gprs[2]=r.gprs[2],this.gprs[3]=r.gprs[3],this.gprs[4]=r.gprs[4],this.gprs[5]=r.gprs[5],this.gprs[6]=r.gprs[6],this.gprs[7]=r.gprs[7],this.gprs[8]=r.gprs[8],this.gprs[9]=r.gprs[9],this.gprs[10]=r.gprs[10],this.gprs[11]=r.gprs[11],this.gprs[12]=r.gprs[12],this.gprs[13]=r.gprs[13],this.gprs[14]=r.gprs[14],this.gprs[15]=r.gprs[15],this.ifprs.set(r.ifprs),this.mode=r.mode,this.cpsrI=r.cpsrI,this.cpsrF=r.cpsrF,this.cpsrV=r.cpsrV,this.cpsrC=r.cpsrC,this.cpsrZ=r.cpsrZ,this.cpsrN=r.cpsrN,this.bankedRegisters[0][0]=r.bankedRegisters[0][0],this.bankedRegisters[0][1]=r.bankedRegisters[0][1],this.bankedRegisters[0][2]=r.bankedRegisters[0][2],this.bankedRegisters[0][3]=r.bankedRegisters[0][3],this.bankedRegisters[0][4]=r.bankedRegisters[0][4],this.bankedRegisters[0][5]=r.bankedRegisters[0][5],this.bankedRegisters[0][6]=r.bankedRegisters[0][6],this.bankedRegisters[1][0]=r.bankedRegisters[1][0],this.bankedRegisters[1][1]=r.bankedRegisters[1][1],this.bankedRegisters[1][2]=r.bankedRegisters[1][2],this.bankedRegisters[1][3]=r.bankedRegisters[1][3],this.bankedRegisters[1][4]=r.bankedRegisters[1][4],this.bankedRegisters[1][5]=r.bankedRegisters[1][5],this.bankedRegisters[1][6]=r.bankedRegisters[1][6],this.bankedRegisters[2][0]=r.bankedRegisters[2][0],this.bankedRegisters[2][1]=r.bankedRegisters[2][1],this.bankedRegisters[3][0]=r.bankedRegisters[3][0],this.bankedRegisters[3][1]=r.bankedRegisters[3][1],this.bankedRegisters[4][0]=r.bankedRegisters[4][0],this.bankedRegisters[4][1]=r.bankedRegisters[4][1],this.bankedRegisters[5][0]=r.bankedRegisters[5][0],this.bankedRegisters[5][1]=r.bankedRegisters[5][1],this.spsr=r.spsr,this.bankedSPSRs[0]=r.bankedSPSRs[0],this.bankedSPSRs[1]=r.bankedSPSRs[1],this.bankedSPSRs[2]=r.bankedSPSRs[2],this.bankedSPSRs[3]=r.bankedSPSRs[3],this.bankedSPSRs[4]=r.bankedSPSRs[4],this.bankedSPSRs[5]=r.bankedSPSRs[5],this.cycles=r.cycles,this.instructionWidth=r.instructionWidth,this.loadInstruction=r.instructionWidth==2?this.loadInstructionThumb:this.loadInstructionArm,this.execMode=r.instructionWidth==2?1:0};A.prototype.fetchPage=function(r){var t=this.mmu,i=r>>>t.BASE_OFFSET,s=t.addressToPage(i,r&t.OFFSET_MASK);if(i==this.pageRegion){if(s==this.pageId&&!this.page.invalid)return;this.pageId=s}else this.pageMask=t.memory[i].PAGE_MASK,this.pageRegion=i,this.pageId=s;this.page=t.accessPage(i,s)};A.prototype.loadInstructionArm=function(r){var t=null;this.fetchPage(r);var i=(r&this.pageMask)>>2;if(t=this.page.arm[i],t)return t;var s=this.mmu.load32(r)>>>0;return t=this.compileArm(s),t.next=null,t.page=this.page,t.address=r,t.opcode=s,this.page.arm[i]=t,t};A.prototype.loadInstructionThumb=function(r){var t=null;this.fetchPage(r);var i=(r&this.pageMask)>>1;if(t=this.page.thumb[i],t)return t;var s=this.mmu.load16(r);return t=this.compileThumb(s),t.next=null,t.page=this.page,t.address=r,t.opcode=s,this.page.thumb[i]=t,t};A.prototype.selectBank=function(r){switch(r){case 16:case 31:return 0;case 17:return 1;case 18:return 2;case 19:return 3;case 23:return 4;case 27:return 5;default:throw new N("Invalid user mode "+r+" passed to selectBank")}};A.prototype.switchExecMode=function(r){this.execMode!=r&&(this.execMode=r,r==0?(this.instructionWidth=4,this.loadInstruction=this.loadInstructionArm):(this.instructionWidth=2,this.loadInstruction=this.loadInstructionThumb))};A.prototype.switchMode=function(r){if(r!=this.mode){if(r!=16||r!=31){var t=this.selectBank(r),i=this.selectBank(this.mode);if(t!=i){if(r==17||this.mode==17){var s=i==1?1:0,e=t==1?1:0;this.bankedRegisters[s][2]=this.gprs[8],this.bankedRegisters[s][3]=this.gprs[9],this.bankedRegisters[s][4]=this.gprs[10],this.bankedRegisters[s][5]=this.gprs[11],this.bankedRegisters[s][6]=this.gprs[12],this.gprs[8]=this.bankedRegisters[e][2],this.gprs[9]=this.bankedRegisters[e][3],this.gprs[10]=this.bankedRegisters[e][4],this.gprs[11]=this.bankedRegisters[e][5],this.gprs[12]=this.bankedRegisters[e][6]}this.bankedRegisters[i][0]=this.gprs[13],this.bankedRegisters[i][1]=this.gprs[14],this.gprs[13]=this.bankedRegisters[t][0],this.gprs[14]=this.bankedRegisters[t][1],this.bankedSPSRs[i]=this.spsr,this.spsr=this.bankedSPSRs[t]}}this.mode=r}};A.prototype.packCPSR=function(){return this.mode|this.execMode<<5|this.cpsrF<<6|this.cpsrI<<7|this.cpsrN<<31|this.cpsrZ<<30|this.cpsrC<<29|this.cpsrV<<28};A.prototype.unpackCPSR=function(r){this.switchMode(r&31),this.switchExecMode(!!(r&32)),this.cpsrF=r&64,this.cpsrI=r&128,this.cpsrN=r&2147483648,this.cpsrZ=r&1073741824,this.cpsrC=r&536870912,this.cpsrV=r&268435456,this.irq.testIRQ()};A.prototype.hasSPSR=function(){return this.mode!=31&&this.mode!=16};A.prototype.raiseIRQ=function(){if(!this.cpsrI){var r=this.packCPSR(),t=this.instructionWidth;this.switchMode(18),this.spsr=r,this.gprs[14]=this.gprs[15]-t+4,this.gprs[15]=this.BASE_IRQ+4,this.instruction=null,this.switchExecMode(0),this.cpsrI=!0}};A.prototype.raiseTrap=function(){var r=this.packCPSR(),t=this.instructionWidth;this.switchMode(19),this.spsr=r,this.gprs[14]=this.gprs[15]-t,this.gprs[15]=this.BASE_SWI+4,this.instruction=null,this.switchExecMode(0),this.cpsrI=!0};A.prototype.badOp=function(r){var t=function(){throw new N("Illegal instruction: 0x"+r.toString(16))};return t.writesPC=!0,t.fixedJump=!1,t};A.prototype.generateConds=function(){var r=this;this.conds=[function(){return r.conditionPassed=r.cpsrZ},function(){return r.conditionPassed=!r.cpsrZ},function(){return r.conditionPassed=r.cpsrC},function(){return r.conditionPassed=!r.cpsrC},function(){return r.conditionPassed=r.cpsrN},function(){return r.conditionPassed=!r.cpsrN},function(){return r.conditionPassed=r.cpsrV},function(){return r.conditionPassed=!r.cpsrV},function(){return r.conditionPassed=r.cpsrC&&!r.cpsrZ},function(){return r.conditionPassed=!r.cpsrC||r.cpsrZ},function(){return r.conditionPassed=!r.cpsrN==!r.cpsrV},function(){return r.conditionPassed=!r.cpsrN!=!r.cpsrV},function(){return r.conditionPassed=!r.cpsrZ&&!r.cpsrN==!r.cpsrV},function(){return r.conditionPassed=r.cpsrZ||!r.cpsrN!=!r.cpsrV},null,null]};A.prototype.barrelShiftImmediate=function(r,t,i){var s=this,e=this.gprs,a=this.badOp;switch(r){case 0:t?a=function(){s.shifterOperand=e[i]<>>t,s.shifterCarryOut=e[i]&1<>t,s.shifterCarryOut=e[i]&1<>>t|e[i]<<32-t,s.shifterCarryOut=e[i]&1<>>1,s.shifterCarryOut=e[i]&1};break}return a};A.prototype.compileArm=function(r){var t=this.badOp(r),i=r&234881024,s=this,e=this.gprs,a=this.conds[(r&4026531840)>>>28];if((r&268435440)==19922704){var c=r&15;t=this.armCompiler.constructBX(c,a),t.writesPC=!0,t.fixedJump=!1}else if(!(r&201326592)&&(i==33554432||(r&144)!=144)){var u=r&31457280,p=r&1048576,F=!1;if((u&25165824)==16777216&&!p){var R=r&4194304;if((r&11595776)==2158592){var c=r&15,m=r&255,v=(r&3840)>>7;m=m>>>v|m<<32-v,t=this.armCompiler.constructMSR(c,R,r,m,a),t.writesPC=!1}else if((r&12517376)==983040){var o=(r&61440)>>12;t=this.armCompiler.constructMRS(o,R,a),t.writesPC=o==15}}else{var f=(r&983040)>>16,o=(r&61440)>>12,U=r&96,c=r&15,g=function(){throw new N("BUG: invalid barrel shifter")};if(r&33554432){var m=r&255,ir=(r&3840)>>7;ir?g=this.armCompiler.constructAddressingMode1ImmediateRotate(m,ir):g=this.armCompiler.constructAddressingMode1Immediate(m)}else if(r&16){var l=(r&3840)>>8;switch(F=!0,U){case 0:g=this.armCompiler.constructAddressingMode1LSL(l,c);break;case 32:g=this.armCompiler.constructAddressingMode1LSR(l,c);break;case 64:g=this.armCompiler.constructAddressingMode1ASR(l,c);break;case 96:g=this.armCompiler.constructAddressingMode1ROR(l,c);break}}else{var m=(r&3968)>>7;g=this.barrelShiftImmediate(U,m,c)}switch(u){case 0:p?t=this.armCompiler.constructANDS(o,f,g,a):t=this.armCompiler.constructAND(o,f,g,a);break;case 2097152:p?t=this.armCompiler.constructEORS(o,f,g,a):t=this.armCompiler.constructEOR(o,f,g,a);break;case 4194304:p?t=this.armCompiler.constructSUBS(o,f,g,a):t=this.armCompiler.constructSUB(o,f,g,a);break;case 6291456:p?t=this.armCompiler.constructRSBS(o,f,g,a):t=this.armCompiler.constructRSB(o,f,g,a);break;case 8388608:p?t=this.armCompiler.constructADDS(o,f,g,a):t=this.armCompiler.constructADD(o,f,g,a);break;case 10485760:p?t=this.armCompiler.constructADCS(o,f,g,a):t=this.armCompiler.constructADC(o,f,g,a);break;case 12582912:p?t=this.armCompiler.constructSBCS(o,f,g,a):t=this.armCompiler.constructSBC(o,f,g,a);break;case 14680064:p?t=this.armCompiler.constructRSCS(o,f,g,a):t=this.armCompiler.constructRSC(o,f,g,a);break;case 16777216:t=this.armCompiler.constructTST(o,f,g,a);break;case 18874368:t=this.armCompiler.constructTEQ(o,f,g,a);break;case 20971520:t=this.armCompiler.constructCMP(o,f,g,a);break;case 23068672:t=this.armCompiler.constructCMN(o,f,g,a);break;case 25165824:p?t=this.armCompiler.constructORRS(o,f,g,a):t=this.armCompiler.constructORR(o,f,g,a);break;case 27262976:p?t=this.armCompiler.constructMOVS(o,f,g,a):t=this.armCompiler.constructMOV(o,f,g,a);break;case 29360128:p?t=this.armCompiler.constructBICS(o,f,g,a):t=this.armCompiler.constructBIC(o,f,g,a);break;case 31457280:p?t=this.armCompiler.constructMVNS(o,f,g,a):t=this.armCompiler.constructMVN(o,f,g,a);break}t.writesPC=o==15}}else if((r&263196656)==16777360){var c=r&15,o=r>>12&15,f=r>>16&15;r&4194304?t=this.armCompiler.constructSWPB(o,f,c,a):t=this.armCompiler.constructSWP(o,f,c,a),t.writesPC=o==15}else switch(i){case 0:if((r&16777456)==144){var o=(r&983040)>>16,f=(r&61440)>>12,l=(r&3840)>>8,c=r&15;switch(r&15728640){case 0:t=this.armCompiler.constructMUL(o,l,c,a);break;case 1048576:t=this.armCompiler.constructMULS(o,l,c,a);break;case 2097152:t=this.armCompiler.constructMLA(o,f,l,c,a);break;case 3145728:t=this.armCompiler.constructMLAS(o,f,l,c,a);break;case 8388608:t=this.armCompiler.constructUMULL(o,f,l,c,a);break;case 9437184:t=this.armCompiler.constructUMULLS(o,f,l,c,a);break;case 10485760:t=this.armCompiler.constructUMLAL(o,f,l,c,a);break;case 11534336:t=this.armCompiler.constructUMLALS(o,f,l,c,a);break;case 12582912:t=this.armCompiler.constructSMULL(o,f,l,c,a);break;case 13631488:t=this.armCompiler.constructSMULLS(o,f,l,c,a);break;case 14680064:t=this.armCompiler.constructSMLAL(o,f,l,c,a);break;case 15728640:t=this.armCompiler.constructSMLALS(o,f,l,c,a);break}t.writesPC=o==15}else{var _=r&1048576,o=(r&61440)>>12,dr=(r&3840)>>4,Pr=c=r&15,ar=r&32,p=r&64,L=r&2097152,i=r&4194304,C;if(i){var m=Pr|dr;C=this.armCompiler.constructAddressingMode23Immediate(r,m,a)}else C=this.armCompiler.constructAddressingMode23Register(r,c,a);C.writesPC=!!L&&f==15,(r&144)==144&&(_?ar?p?t=this.armCompiler.constructLDRSH(o,C,a):t=this.armCompiler.constructLDRH(o,C,a):p&&(t=this.armCompiler.constructLDRSB(o,C,a)):!p&&ar&&(t=this.armCompiler.constructSTRH(o,C,a))),t.writesPC=o==15||C.writesPC}break;case 67108864:case 100663296:var o=(r&61440)>>12,_=r&1048576,cr=r&4194304,i=r&33554432;if((r&4293918960)==-403701520){var m=r&15;throw new N("Program exited ("+m+")")}var C=function(){throw new N("Unimplemented memory access: 0x"+r.toString(16))};if(~r&16777216&&(r&=4292870143),i){var c=r&15,U=r&96,ur=(r&3968)>>7;U||ur?(g=this.barrelShiftImmediate(U,ur,c),C=this.armCompiler.constructAddressingMode2RegisterShifted(r,g,a)):C=this.armCompiler.constructAddressingMode23Register(r,c,a)}else{var O=r&4095;C=this.armCompiler.constructAddressingMode23Immediate(r,O,a)}_?cr?t=this.armCompiler.constructLDRB(o,C,a):t=this.armCompiler.constructLDR(o,C,a):cr?t=this.armCompiler.constructSTRB(o,C,a):t=this.armCompiler.constructSTR(o,C,a),t.writesPC=_&&(o==15||C.writesPC);break;case 134217728:var _=r&1048576,L=r&2097152,B=r&4194304,J=r&8388608,j=r&16777216,l=r&65535,f=(r&983040)>>16,C,m=0,O=0,Z=!1;if(J){j&&(m=4);for(var H=1,i=0;i<16;H<<=1,++i)l&H&&(L&&i==f&&!O&&(l&=~H,m+=4,Z=!0),O+=4)}else{j||(m=4);for(var H=1,i=0;i<16;H<<=1,++i)l&H&&(L&&i==f&&!O&&(l&=~H,m+=4,Z=!0),m-=4,O-=4)}L?C=this.armCompiler.constructAddressingMode4Writeback(m,O,f,Z):C=this.armCompiler.constructAddressingMode4(m,f),_?(B?t=this.armCompiler.constructLDMS(l,C,a):t=this.armCompiler.constructLDM(l,C,a),t.writesPC=!!(l&32768)):(B?t=this.armCompiler.constructSTMS(l,C,a):t=this.armCompiler.constructSTM(l,C,a),t.writesPC=!1);break;case 167772160:var m=r&16777215;m&8388608&&(m|=4278190080),m<<=2;var br=r&16777216;br?t=this.armCompiler.constructBL(m,a):t=this.armCompiler.constructB(m,a),t.writesPC=!0,t.fixedJump=!0;break;case 201326592:var _=r&1048576,L=r&2097152,B=r&4194304,J=r&8388608,j=r&16777216,f=(r&983040)>>16,W=(r&61440)>>12,Or=(r&3840)>>8,m=r&255,yr=r>>28&15,a=this.conds[yr];if((r&264179456)==221055488)t=this.armCompiler.constructVPUSH(a,W<<1|(B?1:0),m,!0);else if((r&264179456)==221055744)t=this.armCompiler.constructVPUSH(a,((B?16:0)|W)*2,m,!1);else if((r&264179456)==213715456)t=this.armCompiler.constructVPOP(a,W<<1|(B?1:0),m,!0);else if((r&264179456)==213715712)t=this.armCompiler.constructVPOP(a,((B?16:0)|W)*2,m,!1);else if((r&253759232)==218106368){m*=4,J||(m=-m);var Z=!1,K=W<<1|(B?1:0),C;L?C=this.armCompiler.constructAddressingMode4Writeback(m,O,f,Z):C=this.armCompiler.constructAddressingMode4(m,f),_?t=this.armCompiler.constructVLDR(a,K,C,!0):t=this.armCompiler.constructVSTR(a,K,C,!0)}else if((r&253759232)==218106624){m*=4,J||(m=-m);var Z=!1,K=((B?16:0)|W)*2,C;L?C=this.armCompiler.constructAddressingMode4Writeback(m,O,f,Z):C=this.armCompiler.constructAddressingMode4(m,f),_?t=this.armCompiler.constructVLDR(a,K,C,!1):t=this.armCompiler.constructVSTR(a,K,C,!1)}break;case 234881024:if((r&251658240)==251658240){var m=r&16777215;t=this.armCompiler.constructSWI(m,a),t.writesPC=!1}else if((r&263720528)==246942272){let k=r>>28&15,d=r>>22&1,x=r>>16&7,M=r>>12&15,P=r>>8&1,y=r>>7&1,b=r>>5&1,S=r&15,w=x&4,V=P!=0,G=w?x&1:0,$=y!=0,rr=!1,Sr=P?(d?16:0)|M:M<<1|(d?1:0),wr=P?(b?16:0)|S:S<<1|(b?1:0);t=this.armCompiler.constructVCVT(a,Sr,wr,w,V,G,$,rr),t.writesPC=!1}else if((r&264179408)==246876864){let k=r>>28&15,d=r>>22&1,x=r>>12&15,M=r>>8&1,P=r>>5&1,y=r&15,b=M!=0,S=M?(d?16:0)|x:x<<1|(d?1:0),w=M?(P?16:0)|y:y<<1|(P?1:0);t=this.armCompiler.constructVCVTF(a,S,w,b),t.writesPC=!1}else if((r&262147600)==236980736){let k=r>>28&15,d=r>>22&1,x=r>>7&1,M=r>>5&1,P=(r&15728640)>>20,y=(r&983040)>>16,b=(r&61440)>>12,S=(r&224)>>5,w=r&15,V=r>>8&1,G=V?(d?16:0)|b:b<<1|(d?1:0),$=V?(M?16:0)|w:w<<1|(M?1:0),rr=V?(x?16:0)|y:y<<1|(x?1:0);var a=this.conds[k];t=this.armCompiler.constructVFP3Register(a,P,rr,G,V,S,$),t.writesPC=!1}else if((r&263195728)==243271680){let k=r>>28&15,d=r>>22&1,x=r>>16&15,M=r>>12&15,P=r>>8&3,y=r>>7&1,b=r>>5&1,S=r&15,w=P==3?(d?16:0)|M:M<<1|(d?1:0),V=P==3?(b?16:0)|S:S<<1|(b?1:0),G=P==3?(y?16:0)|x:x<<1|(y?1:0);t=this.armCompiler.constructVFP3Register(a,8,G,w,P==3,0,V),t.writesPC=!1}else if((r&264179280)==246680128){let k=r>>28&15,d=r>>22&1,x=r>>12&15,M=r>>8&1,P=r>>7&1,y=r>>5&1,b=r&15,S=M?(d?16:0)|x:x<<1|(d?1:0),w=M?(y?16:0)|b:b<<1|(y?1:0);var a=this.conds[k];t=this.armCompiler.constructVCMP(a,S,x,M,P,w,b),t.writesPC=!1}else if((r&264179455)==246745664){let k=r>>28&15,d=r>>22&1,x=r>>12&15,M=r>>8&1,P=r>>7&1,y=r>>5&1,b=r&15,S=M?(d?16:0)|x:x<<1|(d?1:0),w=M?(y?16:0)|b:b<<1|(y?1:0);var a=this.conds[k];t=this.armCompiler.constructVCMP0(a,S,x,M,P,w,b),t.writesPC=!1}else if(r==4008835600)t=this.armCompiler.constructNOP();else if((r&266342160)==234883600){let k=r>>28&15,d=r>>20&1,x=r>>16&15,M=r>>12&15,P=r>>7&1;var a=this.conds[k];t=this.armCompiler.constructVMOV(a,d,x<<1|(P?1:0),M)}else r==3992980240?t=this.armCompiler.constructVMOV(a,!1,0,0):r==3995081488&&(t=this.armCompiler.constructVMOV(a,!1,1,1));break;default:throw new N("Bad opcode: 0x"+r.toString(16))}return t.execMode=0,t.fixedJump=t.fixedJump||!1,t};A.prototype.compileThumb=function(r){var t=this.badOp(r&65535),i=this,s=this.gprs;if((r&64512)==16384){var e=(r&56)>>3,a=r&7;switch(r&960){case 0:t=this.thumbCompiler.constructAND(a,e);break;case 64:t=this.thumbCompiler.constructEOR(a,e);break;case 128:t=this.thumbCompiler.constructLSL2(a,e);break;case 192:t=this.thumbCompiler.constructLSR2(a,e);break;case 256:t=this.thumbCompiler.constructASR2(a,e);break;case 320:t=this.thumbCompiler.constructADC(a,e);break;case 384:t=this.thumbCompiler.constructSBC(a,e);break;case 448:t=this.thumbCompiler.constructROR(a,e);break;case 512:t=this.thumbCompiler.constructTST(a,e);break;case 576:t=this.thumbCompiler.constructNEG(a,e);break;case 640:t=this.thumbCompiler.constructCMP2(a,e);break;case 704:t=this.thumbCompiler.constructCMN(a,e);break;case 768:t=this.thumbCompiler.constructORR(a,e);break;case 832:t=this.thumbCompiler.constructMUL(a,e);break;case 896:t=this.thumbCompiler.constructBIC(a,e);break;case 960:t=this.thumbCompiler.constructMVN(a,e);break}t.writesPC=!1}else if((r&64512)==17408){var e=(r&120)>>3,c=r&7,u=r&128,a=c|u>>4;switch(r&768){case 0:t=this.thumbCompiler.constructADD4(a,e),t.writesPC=a==15;break;case 256:t=this.thumbCompiler.constructCMP3(a,e),t.writesPC=!1;break;case 512:t=this.thumbCompiler.constructMOV3(a,e),t.writesPC=a==15;break;case 768:t=this.thumbCompiler.constructBX(a,e),t.writesPC=!0,t.fixedJump=!1;break}}else if((r&63488)==6144){var e=(r&448)>>6,c=(r&56)>>3,a=r&7;switch(r&1536){case 0:t=this.thumbCompiler.constructADD3(a,c,e);break;case 512:t=this.thumbCompiler.constructSUB3(a,c,e);break;case 1024:var p=(r&448)>>6;p?t=this.thumbCompiler.constructADD1(a,c,p):t=this.thumbCompiler.constructMOV2(a,c,e);break;case 1536:var p=(r&448)>>6;t=this.thumbCompiler.constructSUB1(a,c,p);break}t.writesPC=!1}else if(r&57344)if((r&57344)==8192){var p=r&255,c=(r&1792)>>8;switch(r&6144){case 0:t=this.thumbCompiler.constructMOV1(c,p);break;case 2048:t=this.thumbCompiler.constructCMP1(c,p);break;case 4096:t=this.thumbCompiler.constructADD2(c,p);break;case 6144:t=this.thumbCompiler.constructSUB2(c,p);break}t.writesPC=!1}else if((r&63488)==18432){var a=(r&1792)>>8,p=(r&255)<<2;t=this.thumbCompiler.constructLDR3(a,p),t.writesPC=!1}else if((r&61440)==20480){var a=r&7,c=(r&56)>>3,e=(r&448)>>6,F=r&3584;switch(F){case 0:t=this.thumbCompiler.constructSTR2(a,c,e);break;case 512:t=this.thumbCompiler.constructSTRH2(a,c,e);break;case 1024:t=this.thumbCompiler.constructSTRB2(a,c,e);break;case 1536:t=this.thumbCompiler.constructLDRSB(a,c,e);break;case 2048:t=this.thumbCompiler.constructLDR2(a,c,e);break;case 2560:t=this.thumbCompiler.constructLDRH2(a,c,e);break;case 3072:t=this.thumbCompiler.constructLDRB2(a,c,e);break;case 3584:t=this.thumbCompiler.constructLDRSH(a,c,e);break}t.writesPC=!1}else if((r&57344)==24576){var a=r&7,c=(r&56)>>3,p=(r&1984)>>4,R=r&4096;R&&(p>>=2);var m=r&2048;m?R?t=this.thumbCompiler.constructLDRB1(a,c,p):t=this.thumbCompiler.constructLDR1(a,c,p):R?t=this.thumbCompiler.constructSTRB1(a,c,p):t=this.thumbCompiler.constructSTR1(a,c,p),t.writesPC=!1}else if((r&62976)==46080){var v=!!(r&256),o=r&255;r&2048?(t=this.thumbCompiler.constructPOP(o,v),t.writesPC=v,t.fixedJump=!1):(t=this.thumbCompiler.constructPUSH(o,v),t.writesPC=!1)}else if(r&32768)switch(r&28672){case 0:var a=r&7,c=(r&56)>>3,p=(r&1984)>>5;r&2048?t=this.thumbCompiler.constructLDRH1(a,c,p):t=this.thumbCompiler.constructSTRH1(a,c,p),t.writesPC=!1;break;case 4096:var a=(r&1792)>>8,p=(r&255)<<2,m=r&2048;m?t=this.thumbCompiler.constructLDR4(a,p):t=this.thumbCompiler.constructSTR3(a,p),t.writesPC=!1;break;case 8192:var a=(r&1792)>>8,p=(r&255)<<2;r&2048?t=this.thumbCompiler.constructADD6(a,p):t=this.thumbCompiler.constructADD5(a,p),t.writesPC=!1;break;case 12288:if(!(r&3840)){var R=r&128,p=(r&127)<<2;R&&(p=-p),t=this.thumbCompiler.constructADD7(p),t.writesPC=!1}break;case 16384:var c=(r&1792)>>8,o=r&255;r&2048?t=this.thumbCompiler.constructLDMIA(c,o):t=this.thumbCompiler.constructSTMIA(c,o),t.writesPC=!1;break;case 20480:var f=(r&3840)>>8,p=r&255;if(f==15)t=this.thumbCompiler.constructSWI(p),t.writesPC=!1;else{r&128&&(p|=4294967040),p<<=1;var U=this.conds[f];t=this.thumbCompiler.constructB1(p,U),t.writesPC=!0,t.fixedJump=!0}break;case 24576:case 28672:var p=r&2047,g=r&6144;switch(g){case 0:p&1024&&(p|=4294965248),p<<=1,t=this.thumbCompiler.constructB2(p),t.writesPC=!0,t.fixedJump=!0;break;case 2048:break;case 4096:p&1024&&(p|=4294966272),p<<=12,t=this.thumbCompiler.constructBL1(p),t.writesPC=!1;break;case 6144:t=this.thumbCompiler.constructBL2(p),t.writesPC=!0,t.fixedJump=!1;break}break;default:throw new N("Undefined instruction: 0x"+r.toString(16))}else throw new N("Bad opcode: 0x"+r.toString(16));else{var a=r&7,e=(r&56)>>3,p=(r&1984)>>6;switch(r&6144){case 0:t=this.thumbCompiler.constructLSL1(a,e,p);break;case 2048:t=this.thumbCompiler.constructLSR1(a,e,p);break;case 4096:t=this.thumbCompiler.constructASR1(a,e,p);break;case 6144:break}t.writesPC=!1}return t.execMode=1,t.fixedJump=t.fixedJump||!1,t};var Y=class{constructor(){this.f64arr=new Float64Array(1);this.f32arr=new Float32Array(this.f64arr.buffer);this.i32arr=new Int32Array(this.f64arr.buffer);this.BASE_OFFSET=24;this.OFFSET_MASK=16777215;this.core=new A,this.core.irq=this,this.core.mmu=this,this.resetMemory()}resetMemory(){this.memory=[];for(var t=0;t<256;t++)this.memory[t]={PAGE_MASK:2047,ICACHE_PAGE_BITS:10,icache:new Array}}advanceInsn(){var t=this.core.cycles;return this.core.step(),t-=this.core.cycles,t>0?t:1}getPC(){return this.core.gprs[15]-this.core.instructionWidth}getSP(){return this.core.gprs[13]}isStable(){return!0}connectMemoryBus(t){this.bus=t}reset(){this.resetMemory();let t=this.load32(0);this.core.resetCPU(t)}saveState(){return this.core.freeze()}loadState(t){this.core.defrost(t)}load8(t){return this.bus.read(t)<<24>>24}loadU8(t){return this.bus.read(t)&255}load16(t){return this.loadU16(t)<<16>>16}loadU16(t){return this.bus.read(t)|this.bus.read(t+1)<<8}load32(t){var i=this.bus.read32(t);return i}store8(t,i){this.bus.write(t,i&255)}store16(t,i){this.bus.write(t,i&255),this.bus.write(t+1,i>>8&255)}store32(t,i){this.bus.write32(t,i)}wait(t){++this.core.cycles}wait32(t){++this.core.cycles}waitSeq32(t){++this.core.cycles}waitMul(t){(t&4294967040)==4294967040||!(t&4294967040)?this.core.cycles+=1:(t&4294901760)==4294901760||!(t&4294901760)?this.core.cycles+=2:(t&4278190080)==4278190080||!(t&4278190080)?this.core.cycles+=3:this.core.cycles+=4}waitMulti32(t,i){this.core.cycles+=2}waitPrefetch(t){++this.core.cycles}waitPrefetch32(t){++this.core.cycles}addressToPage(t,i){return i>>this.memory[t].ICACHE_PAGE_BITS}accessPage(t,i){var s=this.memory[t],e=s.icache[i];return(!e||e.invalid)&&(e={thumb:new Array(1<>16)}clear(){}updateTimers(){}testIRQ(){}isThumb(){return this.core.instructionWidth==2}getDebugTree(){return{state:this.saveState(),mmu:this.core.mmu}}};var kr=fr([[T.A,0,1],[T.B,0,2],[T.GP_A,0,1],[T.GP_B,0,2],[T.SELECT,0,4],[T.START,0,8],[T.RIGHT,0,16],[T.LEFT,0,32],[T.UP,0,64],[T.DOWN,0,128]]),D=0,I=1048576,Mr=0,X=67108864,z=256,Er=1e6,xr=4e6,Ar=3991793133,q=class extends mr{constructor(){super();this.cpuFrequency=xr;this.canvasWidth=160;this.numTotalScanlines=256;this.numVisibleScanlines=128;this.cpuCyclesPerLine=Math.floor(xr/(256*60));this.defaultROMSize=I-Mr;this.sampleRate=1;this.cpu=new Y;this.ram=new Uint8Array(I);this.ram16=new Uint16Array(this.ram.buffer);this.ram32=new Uint32Array(this.ram.buffer);this.rombase=Mr;this.brightness=255;this.ioregs=new Uint8Array(z);this.ioregs32=new Uint32Array(this.ioregs.buffer);this.read=er([[D,D+I-1,I-1,i=>this.ram[i]],[X,X+z-1,z-1,(i,s)=>this.readIO(i)]],{defaultval:Ar&255});this.write=er([[D,D+I-1,I-1,(i,s)=>{this.ram[i]=s}],[X,X+z-1,z-1,(i,s)=>{this.writeIO(i,s)}]]);this.read32=i=>i>=D&&i>2]:this.read(i)|this.read(i+1)<<8|this.read(i+2)<<16|this.read(i+3)<<24;this.write32=(i,s)=>{i>=D&&i>2]=s:(this.write(i,s&255),this.write(i+1,s>>8&255),this.write(i+2,s>>16&255),this.write(i+3,s>>24&255))};this.connectCPUMemoryBus(this),this.handler=hr(this.inputs,kr)}connectVideo(i){super.connectVideo(i),this.pixels32=i,this.pixels8=new Uint8Array(i.buffer)}connectSerialIO(i){this.serial=i}loadROM(i){super.loadROM(i)}reset(){this.ram.fill(0),this.rom&&this.ram.set(this.rom,this.rombase),super.reset(),this.serialOut=[],this.serialIn=[]}readAddress(i){return i>=D&&i>8;case 36:return this.getRasterX();case 37:return this.getRasterX()>>8;case 64:return(this.serial.byteAvailable()?128:0)|(this.serial.clearToSend()?64:0);case 68:let s=this.serialIn.shift();return s!=null?(this.serialOut.push(s),s.value):0;default:return 0}}writeIO(i,s){switch(this.ioregs[i]=s,i){case 72:this.serialOut.length>1&1048575,a=this.brightness<<24,c=0;c>5&31)<<11|(u>>10&31)<<19}}getDebugCategories(){return["CPU","Stack","FPU"]}getDebugInfo(i,s){switch(i){case"Stack":for(var u="",p=s.c,e=p.gprs[13],a=p.gprs[11],c=0;c<16&&(u+=E(e,8)+" "+E(this.ram32[e-D>>2],8),e==a&&(u+=" FP"),u+=` +import{F as Rr,I as gr,r as mr}from"./chunk-4676AC7I.js";import{E as or,K as Fr,T as N,W as T,X as hr,Z as fr,a as Q,aa as er,g as E}from"./chunk-TYDI7JZQ.js";import{a as pr,b as nr}from"./chunk-KT7KMEQC.js";var Cr=4026531840,lr=223,Tr=32;function n(r){this.cpu=r,this.addressingMode23Immediate=[function(t,i,s){var e=r.gprs,a=function(){var c=e[t];return(!s||s())&&(e[t]-=i),c};return a.writesPC=t==15,a},null,null,null,function(t,i,s){var e=r.gprs,a=function(){var c=e[t];return(!s||s())&&(e[t]+=i),c};return a.writesPC=t==15,a},null,null,null,function(t,i,s){var e=r.gprs,a=function(){return e[t]-i};return a.writesPC=!1,a},function(t,i,s){var e=r.gprs,a=function(){var c=e[t]-i;return(!s||s())&&(e[t]=c),c};return a.writesPC=t==15,a},null,null,function(t,i,s){var e=r.gprs,a=function(){return e[t]+i};return a.writesPC=!1,a},function(t,i,s){var e=r.gprs,a=function(){var c=e[t]+i;return(!s||s())&&(e[t]=c),c};return a.writesPC=t==15,a},null,null],this.addressingMode23Register=[function(t,i,s){var e=r.gprs,a=function(){var c=e[t];return(!s||s())&&(e[t]-=e[i]),c};return a.writesPC=t==15,a},null,null,null,function(t,i,s){var e=r.gprs,a=function(){var c=e[t];return(!s||s())&&(e[t]+=e[i]),c};return a.writesPC=t==15,a},null,null,null,function(t,i,s){var e=r.gprs,a=function(){return e[t]-e[i]};return a.writesPC=!1,a},function(t,i,s){var e=r.gprs,a=function(){var c=e[t]-e[i];return(!s||s())&&(e[t]=c),c};return a.writesPC=t==15,a},null,null,function(t,i,s){var e=r.gprs,a=function(){var c=e[t]+e[i];return c};return a.writesPC=!1,a},function(t,i,s){var e=r.gprs,a=function(){var c=e[t]+e[i];return(!s||s())&&(e[t]=c),c};return a.writesPC=t==15,a},null,null],this.addressingMode2RegisterShifted=[function(t,i,s){var e=r.gprs,a=function(){var c=e[t];return(!s||s())&&(i(),e[t]-=r.shifterOperand),c};return a.writesPC=t==15,a},null,null,null,function(t,i,s){var e=r.gprs,a=function(){var c=e[t];return(!s||s())&&(i(),e[t]+=r.shifterOperand),c};return a.writesPC=t==15,a},null,null,null,function(t,i,s){var e=r.gprs,a=function(){return i(),e[t]-r.shifterOperand};return a.writesPC=!1,a},function(t,i,s){var e=r.gprs,a=function(){i();var c=e[t]-r.shifterOperand;return(!s||s())&&(e[t]=c),c};return a.writesPC=t==15,a},null,null,function(t,i,s){var e=r.gprs,a=function(){return i(),e[t]+r.shifterOperand};return a.writesPC=!1,a},function(t,i,s){var e=r.gprs,a=function(){i();var c=e[t]+r.shifterOperand;return(!s||s())&&(e[t]=c),c};return a.writesPC=t==15,a},null,null]}n.prototype.constructAddressingMode1ASR=function(r,t){var i=this.cpu,s=i.gprs;return function(){++i.cycles;var e=s[r];r==15&&(e+=4),e&=255;var a=s[t];t==15&&(a+=4),e==0?(i.shifterOperand=a,i.shifterCarryOut=i.cpsrC):e<32?(i.shifterOperand=a>>e,i.shifterCarryOut=a&1<>31?(i.shifterOperand=4294967295,i.shifterCarryOut=2147483648):(i.shifterOperand=0,i.shifterCarryOut=0)}};n.prototype.constructAddressingMode1Immediate=function(r){var t=this.cpu;return function(){t.shifterOperand=r,t.shifterCarryOut=t.cpsrC}};n.prototype.constructAddressingMode1ImmediateRotate=function(r,t){var i=this.cpu;return function(){i.shifterOperand=r>>>t|r<<32-t,i.shifterCarryOut=i.shifterOperand>>31}};n.prototype.constructAddressingMode1LSL=function(r,t){var i=this.cpu,s=i.gprs;return function(){++i.cycles;var e=s[r];r==15&&(e+=4),e&=255;var a=s[t];t==15&&(a+=4),e==0?(i.shifterOperand=a,i.shifterCarryOut=i.cpsrC):e<32?(i.shifterOperand=a<>>e,i.shifterCarryOut=a&1<>31):(i.shifterOperand=0,i.shifterCarryOut=0)}};n.prototype.constructAddressingMode1ROR=function(r,t){var i=this.cpu,s=i.gprs;return function(){++i.cycles;var e=s[r];r==15&&(e+=4),e&=255;var a=s[t];t==15&&(a+=4);var c=e&31;e==0?(i.shifterOperand=a,i.shifterCarryOut=i.cpsrC):c?(i.shifterOperand=s[t]>>>c|s[t]<<32-c,i.shifterCarryOut=a&1<>31)}};n.prototype.constructAddressingMode23Immediate=function(r,t,i){var s=(r&983040)>>16;return this.addressingMode23Immediate[(r&27262976)>>21](s,t,i)};n.prototype.constructAddressingMode23Register=function(r,t,i){var s=(r&983040)>>16;return this.addressingMode23Register[(r&27262976)>>21](s,t,i)};n.prototype.constructAddressingMode2RegisterShifted=function(r,t,i){var s=(r&983040)>>16;return this.addressingMode2RegisterShifted[(r&27262976)>>21](s,t,i)};n.prototype.constructAddressingMode4=function(r,t){var i=this.cpu,s=i.gprs;return function(){var e=s[t]+r;return e}};n.prototype.constructAddressingMode4Writeback=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(c){var u=a[i]+r;return c&&s&&e.mmu.store32(a[i]+r-4,a[i]),a[i]+=t,u}};n.prototype.constructNOP=function(){return this.writesPC=!1,function(){}};n.prototype.constructADC=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=(e.shifterOperand>>>0)+(e.cpsrC?1:0);a[r]=(a[t]>>>0)+c}}};n.prototype.constructADCS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=(e.shifterOperand>>>0)+(e.cpsrC?1:0),u=(a[t]>>>0)+c;r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=u>>31,e.cpsrZ=!(u&4294967295),e.cpsrC=u>4294967295,e.cpsrV=a[t]>>31==c>>31&&a[t]>>31!=u>>31&&c>>31!=u>>31),a[r]=u}}};n.prototype.constructADD=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=(a[t]>>>0)+(e.shifterOperand>>>0))}};n.prototype.constructADDS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=(a[t]>>>0)+(e.shifterOperand>>>0);r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=c>>31,e.cpsrZ=!(c&4294967295),e.cpsrC=c>4294967295,e.cpsrV=a[t]>>31==e.shifterOperand>>31&&a[t]>>31!=c>>31&&e.shifterOperand>>31!=c>>31),a[r]=c}}};n.prototype.constructAND=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=a[t]&e.shifterOperand)}};n.prototype.constructANDS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=a[t]&e.shifterOperand,r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=a[r]>>31,e.cpsrZ=!(a[r]&4294967295),e.cpsrC=e.shifterCarryOut))}};n.prototype.constructB=function(r,t){var i=this.cpu,s=i.gprs;return function(){if(t&&!t()){i.mmu.waitPrefetch32(s[15]);return}i.mmu.waitPrefetch32(s[15]),s[15]+=r}};n.prototype.constructBIC=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=a[t]&~e.shifterOperand)}};n.prototype.constructBICS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=a[t]&~e.shifterOperand,r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=a[r]>>31,e.cpsrZ=!(a[r]&4294967295),e.cpsrC=e.shifterCarryOut))}};n.prototype.constructBL=function(r,t){var i=this.cpu,s=i.gprs;return function(){if(t&&!t()){i.mmu.waitPrefetch32(s[15]);return}i.mmu.waitPrefetch32(s[15]),s[14]=s[15]-4,s[15]+=r}};n.prototype.constructBX=function(r,t){var i=this.cpu,s=i.gprs;return function(){if(t&&!t()){i.mmu.waitPrefetch32(s[15]);return}i.mmu.waitPrefetch32(s[15]),i.switchExecMode(s[r]&1),s[15]=s[r]&4294967294}};n.prototype.constructCMN=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=(a[t]>>>0)+(e.shifterOperand>>>0);e.cpsrN=c>>31,e.cpsrZ=!(c&4294967295),e.cpsrC=c>4294967295,e.cpsrV=a[t]>>31==e.shifterOperand>>31&&a[t]>>31!=c>>31&&e.shifterOperand>>31!=c>>31}}};n.prototype.constructCMP=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=a[t]-e.shifterOperand;e.cpsrN=c>>31,e.cpsrZ=!(c&4294967295),e.cpsrC=a[t]>>>0>=e.shifterOperand>>>0,e.cpsrV=a[t]>>31!=e.shifterOperand>>31&&a[t]>>31!=c>>31}}};n.prototype.constructEOR=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=a[t]^e.shifterOperand)}};n.prototype.constructEORS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=a[t]^e.shifterOperand,r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=a[r]>>31,e.cpsrZ=!(a[r]&4294967295),e.cpsrC=e.shifterCarryOut))}};n.prototype.constructLDM=function(r,t,i){var s=this.cpu,e=s.gprs,a=s.mmu;return function(){if(a.waitPrefetch32(e[15]),!(i&&!i())){var c=t(!1),u=0,p,F;for(p=r,F=0;p;p>>=1,++F)p&1&&(e[F]=a.load32(c&4294967292),c+=4,++u);a.waitMulti32(c,u),++s.cycles}}};n.prototype.constructLDMS=function(r,t,i){var s=this.cpu,e=s.gprs,a=s.mmu;return function(){if(a.waitPrefetch32(e[15]),!(i&&!i())){var c=t(!1),u=0,p=s.mode;s.switchMode(31);var F,R;for(F=r,R=0;F;F>>=1,++R)F&1&&(e[R]=a.load32(c&4294967292),c+=4,++u);s.switchMode(p),a.waitMulti32(c,u),++s.cycles}}};n.prototype.constructLDR=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){if(s.mmu.waitPrefetch32(e[15]),!(i&&!i())){var a=t();e[r]=s.mmu.load32(a),s.mmu.wait32(a),++s.cycles}}};n.prototype.constructLDRB=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){if(s.mmu.waitPrefetch32(e[15]),!(i&&!i())){var a=t();e[r]=s.mmu.loadU8(a),s.mmu.wait(a),++s.cycles}}};n.prototype.constructLDRH=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){if(s.mmu.waitPrefetch32(e[15]),!(i&&!i())){var a=t();e[r]=s.mmu.loadU16(a),s.mmu.wait(a),++s.cycles}}};n.prototype.constructLDRSB=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){if(s.mmu.waitPrefetch32(e[15]),!(i&&!i())){var a=t();e[r]=s.mmu.load8(a),s.mmu.wait(a),++s.cycles}}};n.prototype.constructLDRSH=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){if(s.mmu.waitPrefetch32(e[15]),!(i&&!i())){var a=t();e[r]=s.mmu.load16(a),s.mmu.wait(a),++s.cycles}}};n.prototype.constructMLA=function(r,t,i,s,e){var a=this.cpu,c=a.gprs;return function(){if(a.mmu.waitPrefetch32(c[15]),!(e&&!e()))if(++a.cycles,a.mmu.waitMul(i),c[s]&4294901760&&c[i]&4294901760){var u=(c[s]&4294901760)*c[i]&4294967295,p=(c[s]&65535)*c[i]&4294967295;c[r]=u+p+c[t]&4294967295}else c[r]=c[s]*c[i]+c[t]}};n.prototype.constructMLAS=function(r,t,i,s,e){var a=this.cpu,c=a.gprs;return function(){if(a.mmu.waitPrefetch32(c[15]),!(e&&!e())){if(++a.cycles,a.mmu.waitMul(i),c[s]&4294901760&&c[i]&4294901760){var u=(c[s]&4294901760)*c[i]&4294967295,p=(c[s]&65535)*c[i]&4294967295;c[r]=u+p+c[t]&4294967295}else c[r]=c[s]*c[i]+c[t];a.cpsrN=c[r]>>31,a.cpsrZ=!(c[r]&4294967295)}}};n.prototype.constructMOV=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=e.shifterOperand)}};n.prototype.constructMOVS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=e.shifterOperand,r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=a[r]>>31,e.cpsrZ=!(a[r]&4294967295),e.cpsrC=e.shifterCarryOut))}};n.prototype.constructMRS=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){s.mmu.waitPrefetch32(e[15]),!(i&&!i())&&(t?e[r]=s.spsr:e[r]=s.packCPSR())}};n.prototype.constructMSR=function(r,t,i,s,e){var a=this.cpu,c=a.gprs,u=i&65536,p=i&524288;return function(){if(a.mmu.waitPrefetch32(c[15]),!(e&&!e())){var F;i&33554432?F=s:F=c[r];var R=(u?255:0)|(p?4278190080:0);t?(R&=Cr|lr|Tr,a.spsr=a.spsr&~R|F&R):(R&Cr&&(a.cpsrN=F>>31,a.cpsrZ=F&1073741824,a.cpsrC=F&536870912,a.cpsrV=F&268435456),a.mode!=16&&R&lr&&(a.switchMode(F&15|16),a.cpsrI=F&128,a.cpsrF=F&64))}}};n.prototype.constructMUL=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s()))if(e.mmu.waitMul(a[t]),a[i]&4294901760&&a[t]&4294901760){var c=(a[i]&4294901760)*a[t]|0,u=(a[i]&65535)*a[t]|0;a[r]=c+u}else a[r]=a[i]*a[t]}};n.prototype.constructMULS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){if(e.mmu.waitMul(a[t]),a[i]&4294901760&&a[t]&4294901760){var c=(a[i]&4294901760)*a[t]|0,u=(a[i]&65535)*a[t]|0;a[r]=c+u}else a[r]=a[i]*a[t];e.cpsrN=a[r]>>31,e.cpsrZ=!(a[r]&4294967295)}}};n.prototype.constructMVN=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=~e.shifterOperand)}};n.prototype.constructMVNS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=~e.shifterOperand,r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=a[r]>>31,e.cpsrZ=!(a[r]&4294967295),e.cpsrC=e.shifterCarryOut))}};n.prototype.constructORR=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=a[t]|e.shifterOperand)}};n.prototype.constructORRS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=a[t]|e.shifterOperand,r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=a[r]>>31,e.cpsrZ=!(a[r]&4294967295),e.cpsrC=e.shifterCarryOut))}};n.prototype.constructRSB=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=e.shifterOperand-a[t])}};n.prototype.constructRSBS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=e.shifterOperand-a[t];r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=c>>31,e.cpsrZ=!(c&4294967295),e.cpsrC=e.shifterOperand>>>0>=a[t]>>>0,e.cpsrV=e.shifterOperand>>31!=a[t]>>31&&e.shifterOperand>>31!=c>>31),a[r]=c}}};n.prototype.constructRSC=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=(a[t]>>>0)+(e.cpsrC?0:1);a[r]=(e.shifterOperand>>>0)-c}}};n.prototype.constructRSCS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=(a[t]>>>0)+(e.cpsrC?0:1),u=(e.shifterOperand>>>0)-c;r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=u>>31,e.cpsrZ=!(u&4294967295),e.cpsrC=e.shifterOperand>>>0>=u>>>0,e.cpsrV=e.shifterOperand>>31!=c>>31&&e.shifterOperand>>31!=u>>31),a[r]=u}}};n.prototype.constructSBC=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=(e.shifterOperand>>>0)+(e.cpsrC?0:1);a[r]=(a[t]>>>0)-c}}};n.prototype.constructSBCS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=(e.shifterOperand>>>0)+(e.cpsrC?0:1),u=(a[t]>>>0)-c;r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=u>>31,e.cpsrZ=!(u&4294967295),e.cpsrC=a[t]>>>0>=u>>>0,e.cpsrV=a[t]>>31!=c>>31&&a[t]>>31!=u>>31),a[r]=u}}};n.prototype.constructSMLAL=function(r,t,i,s,e){var a=this.cpu,c=1/4294967296,u=a.gprs;return function(){if(a.mmu.waitPrefetch32(u[15]),!(e&&!e())){a.cycles+=2,a.mmu.waitMul(i);var p=(u[s]&4294901760)*u[i],F=(u[s]&65535)*u[i],R=(u[t]>>>0)+p+F;u[t]=R,u[r]+=Math.floor(R*c)}}};n.prototype.constructSMLALS=function(r,t,i,s,e){var a=this.cpu,c=1/4294967296,u=a.gprs;return function(){if(a.mmu.waitPrefetch32(u[15]),!(e&&!e())){a.cycles+=2,a.mmu.waitMul(i);var p=(u[s]&4294901760)*u[i],F=(u[s]&65535)*u[i],R=(u[t]>>>0)+p+F;u[t]=R,u[r]+=Math.floor(R*c),a.cpsrN=u[r]>>31,a.cpsrZ=!(u[r]&4294967295||u[t]&4294967295)}}};n.prototype.constructSMULL=function(r,t,i,s,e){var a=this.cpu,c=1/4294967296,u=a.gprs;return function(){if(a.mmu.waitPrefetch32(u[15]),!(e&&!e())){++a.cycles,a.mmu.waitMul(u[i]);var p=((u[s]&4294901760)>>0)*(u[i]>>0),F=((u[s]&65535)>>0)*(u[i]>>0);u[t]=(p&4294967295)+(F&4294967295)&4294967295,u[r]=Math.floor(p*c+F*c)}}};n.prototype.constructSMULLS=function(r,t,i,s,e){var a=this.cpu,c=1/4294967296,u=a.gprs;return function(){if(a.mmu.waitPrefetch32(u[15]),!(e&&!e())){++a.cycles,a.mmu.waitMul(u[i]);var p=((u[s]&4294901760)>>0)*(u[i]>>0),F=((u[s]&65535)>>0)*(u[i]>>0);u[t]=(p&4294967295)+(F&4294967295)&4294967295,u[r]=Math.floor(p*c+F*c),a.cpsrN=u[r]>>31,a.cpsrZ=!(u[r]&4294967295||u[t]&4294967295)}}};n.prototype.constructSTM=function(r,t,i){var s=this.cpu,e=s.gprs,a=s.mmu;return function(){if(i&&!i()){a.waitPrefetch32(e[15]);return}a.wait32(e[15]);var c=t(!0),u=0,p,F;for(p=r,F=0;p;p>>=1,++F)p&1&&(a.store32(c,e[F]),c+=4,++u);a.waitMulti32(c,u)}};n.prototype.constructSTMS=function(r,t,i){var s=this.cpu,e=s.gprs,a=s.mmu;return function(){if(i&&!i()){a.waitPrefetch32(e[15]);return}a.wait32(e[15]);var c=s.mode,u=t(!0),p=0,F,R;for(s.switchMode(31),F=r,R=0;F;F>>=1,++R)F&1&&(a.store32(u,e[R]),u+=4,++p);s.switchMode(c),a.waitMulti32(u,p)}};n.prototype.constructSTR=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){if(i&&!i()){s.mmu.waitPrefetch32(e[15]);return}var a=t();s.mmu.store32(a,e[r]),s.mmu.wait32(a),s.mmu.wait32(e[15])}};n.prototype.constructSTRB=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){if(i&&!i()){s.mmu.waitPrefetch32(e[15]);return}var a=t();s.mmu.store8(a,e[r]),s.mmu.wait(a),s.mmu.wait32(e[15])}};n.prototype.constructSTRH=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){if(i&&!i()){s.mmu.waitPrefetch32(e[15]);return}var a=t();s.mmu.store16(a,e[r]),s.mmu.wait(a),s.mmu.wait32(e[15])}};n.prototype.constructSUB=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){e.mmu.waitPrefetch32(a[15]),!(s&&!s())&&(i(),a[r]=a[t]-e.shifterOperand)}};n.prototype.constructSUBS=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=a[t]-e.shifterOperand;r==15&&e.hasSPSR()?e.unpackCPSR(e.spsr):(e.cpsrN=c>>31,e.cpsrZ=!(c&4294967295),e.cpsrC=a[t]>>>0>=e.shifterOperand>>>0,e.cpsrV=a[t]>>31!=e.shifterOperand>>31&&a[t]>>31!=c>>31),a[r]=c}}};n.prototype.constructSWI=function(r,t){var i=this.cpu,s=i.gprs;return function(){if(t&&!t()){i.mmu.waitPrefetch32(s[15]);return}i.irq.swi32(r),i.mmu.waitPrefetch32(s[15])}};n.prototype.constructSWP=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){e.mmu.wait32(a[t]),e.mmu.wait32(a[t]);var c=e.mmu.load32(a[t]);e.mmu.store32(a[t],a[i]),a[r]=c,++e.cycles}}};n.prototype.constructSWPB=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){e.mmu.wait(a[t]),e.mmu.wait(a[t]);var c=e.mmu.loadU8(a[t]);e.mmu.store8(a[t],a[i]),a[r]=c,++e.cycles}}};n.prototype.constructTEQ=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=a[t]^e.shifterOperand;e.cpsrN=c>>31,e.cpsrZ=!(c&4294967295),e.cpsrC=e.shifterCarryOut}}};n.prototype.constructTST=function(r,t,i,s){var e=this.cpu,a=e.gprs;return function(){if(e.mmu.waitPrefetch32(a[15]),!(s&&!s())){i();var c=a[t]&e.shifterOperand;e.cpsrN=c>>31,e.cpsrZ=!(c&4294967295),e.cpsrC=e.shifterCarryOut}}};n.prototype.constructUMLAL=function(r,t,i,s,e){var a=this.cpu,c=1/4294967296,u=a.gprs;return function(){if(a.mmu.waitPrefetch32(u[15]),!(e&&!e())){a.cycles+=2,a.mmu.waitMul(i);var p=((u[s]&4294901760)>>>0)*(u[i]>>>0),F=(u[s]&65535)*(u[i]>>>0),R=(u[t]>>>0)+p+F;u[t]=R,u[r]+=R*c}}};n.prototype.constructUMLALS=function(r,t,i,s,e){var a=this.cpu,c=1/4294967296,u=a.gprs;return function(){if(a.mmu.waitPrefetch32(u[15]),!(e&&!e())){a.cycles+=2,a.mmu.waitMul(i);var p=((u[s]&4294901760)>>>0)*(u[i]>>>0),F=(u[s]&65535)*(u[i]>>>0),R=(u[t]>>>0)+p+F;u[t]=R,u[r]+=R*c,a.cpsrN=u[r]>>31,a.cpsrZ=!(u[r]&4294967295||u[t]&4294967295)}}};n.prototype.constructUMULL=function(r,t,i,s,e){var a=this.cpu,c=1/4294967296,u=a.gprs;return function(){if(a.mmu.waitPrefetch32(u[15]),!(e&&!e())){++a.cycles,a.mmu.waitMul(u[i]);var p=((u[s]&4294901760)>>>0)*(u[i]>>>0),F=((u[s]&65535)>>>0)*(u[i]>>>0);u[t]=(p&4294967295)+(F&4294967295)&4294967295,u[r]=p*c+F*c>>>0}}};n.prototype.constructUMULLS=function(r,t,i,s,e){var a=this.cpu,c=1/4294967296,u=a.gprs;return function(){if(a.mmu.waitPrefetch32(u[15]),!(e&&!e())){++a.cycles,a.mmu.waitMul(u[i]);var p=((u[s]&4294901760)>>>0)*(u[i]>>>0),F=((u[s]&65535)>>>0)*(u[i]>>>0);u[t]=(p&4294967295)+(F&4294967295)&4294967295,u[r]=p*c+F*c>>>0,a.cpsrN=u[r]>>31,a.cpsrZ=!(u[r]&4294967295||u[t]&4294967295)}}};n.prototype.constructVFP3Register=function(r,t,i,s,e,a,c){var u=this.cpu,p=e?u.dfprs:u.sfprs;return function(){if(u.mmu.waitPrefetch32(u.gprs[15]),!(r&&!r())){switch(t){case 2:switch(a){case 0:p[s]=p[i]*p[c];return}break;case 3:switch(a){case 0:p[s]=p[i]+p[c];return;case 2:p[s]=p[i]-p[c];return}break;case 8:switch(a){case 0:p[s]=p[i]/p[c];return}break}console.log("Unsupported instruction: "+E(t)+" "+E(a))}}};n.prototype.constructVCVT=function(r,t,i,s,e,a,c,u){var p=this.cpu,F=p.sfprs,R=p.dfprs,m=p.ifprs;return function(){if(p.mmu.waitPrefetch32(p.gprs[15]),!(r&&!r())){var v,o;s&&e?v=R[i]:s?v=F[i]:v=m[i],s?o=c?Math.floor(v):Math.round(v):o=v,s?m[t]=o:e?R[t]=o:F[t]=o}}};n.prototype.constructVCVTF=function(r,t,i,s){var e=this.cpu,a=e.sfprs,c=e.dfprs;return function(){if(e.mmu.waitPrefetch32(e.gprs[15]),!(r&&!r())){var u=s?c[i]:a[i];s?a[t]=u:c[t]=u}}};n.prototype.constructVLDR=function(r,t,i,s){var e=this.cpu,a=e.ifprs;return function(){if(e.mmu.waitPrefetch32(e.gprs[15]),r&&!r())return;let c=i();s?a[t]=e.mmu.load32(c):(a[t]=e.mmu.load32(c),a[t+1]=e.mmu.load32(c+4)),e.mmu.wait32(c),e.mmu.wait32(e.gprs[15])}};n.prototype.constructVSTR=function(r,t,i,s){var e=this.cpu,a=e.ifprs;return function(){if(e.mmu.waitPrefetch32(e.gprs[15]),r&&!r())return;let c=i();s?e.mmu.store32(c,a[t]):(e.mmu.store32(c,a[t]),e.mmu.store32(c+4,a[t+1])),e.mmu.wait32(c),e.mmu.wait32(e.gprs[15])}};n.prototype.constructVPUSH=function(r,t,i,s){var e=this.cpu,a=e.ifprs;return function(){if(e.mmu.waitPrefetch32(e.gprs[15]),r&&!r())return;let c=e.gprs[13]-i*4;e.gprs[13]=c;for(let u=0;u>>0)+(i.cpsrC?1:0),a=s[r],c=(a>>>0)+e,u=a>>31,p=c>>31,F=e>>31;i.cpsrN=p,i.cpsrZ=!(c&4294967295),i.cpsrC=c>4294967295,i.cpsrV=u==F&&u!=p&&F!=p,s[r]=c}};h.prototype.constructADD1=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){s.mmu.waitPrefetch(e[15]);var a=(e[t]>>>0)+i;s.cpsrN=a>>31,s.cpsrZ=!(a&4294967295),s.cpsrC=a>4294967295,s.cpsrV=!(e[t]>>31)&&(e[t]>>31^a)>>31&&a>>31,e[r]=a}};h.prototype.constructADD2=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=(s[r]>>>0)+t;i.cpsrN=e>>31,i.cpsrZ=!(e&4294967295),i.cpsrC=e>4294967295,i.cpsrV=!(s[r]>>31)&&(s[r]^e)>>31&&(t^e)>>31,s[r]=e}};h.prototype.constructADD3=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){s.mmu.waitPrefetch(e[15]);var a=(e[t]>>>0)+(e[i]>>>0);s.cpsrN=a>>31,s.cpsrZ=!(a&4294967295),s.cpsrC=a>4294967295,s.cpsrV=!((e[t]^e[i])>>31)&&(e[t]^a)>>31&&(e[i]^a)>>31,e[r]=a}};h.prototype.constructADD4=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),s[r]+=s[t]}};h.prototype.constructADD5=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),s[r]=(s[15]&4294967292)+t}};h.prototype.constructADD6=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),s[r]=s[13]+t}};h.prototype.constructADD7=function(r){var t=this.cpu,i=t.gprs;return function(){t.mmu.waitPrefetch(i[15]),i[13]+=r}};h.prototype.constructAND=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),s[r]=s[r]&s[t],i.cpsrN=s[r]>>31,i.cpsrZ=!(s[r]&4294967295)}};h.prototype.constructASR1=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){s.mmu.waitPrefetch(e[15]),i==0?(s.cpsrC=e[t]>>31,s.cpsrC?e[r]=4294967295:e[r]=0):(s.cpsrC=e[t]&1<>i),s.cpsrN=e[r]>>31,s.cpsrZ=!(e[r]&4294967295)}};h.prototype.constructASR2=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=s[t]&255;e&&(e<32?(i.cpsrC=s[r]&1<>=e):(i.cpsrC=s[r]>>31,i.cpsrC?s[r]=4294967295:s[r]=0)),i.cpsrN=s[r]>>31,i.cpsrZ=!(s[r]&4294967295)}};h.prototype.constructB1=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),t()&&(s[15]+=r)}};h.prototype.constructB2=function(r){var t=this.cpu,i=t.gprs;return function(){t.mmu.waitPrefetch(i[15]),i[15]+=r}};h.prototype.constructBIC=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),s[r]=s[r]&~s[t],i.cpsrN=s[r]>>31,i.cpsrZ=!(s[r]&4294967295)}};h.prototype.constructBL1=function(r){var t=this.cpu,i=t.gprs;return function(){t.mmu.waitPrefetch(i[15]),i[14]=i[15]+r}};h.prototype.constructBL2=function(r){var t=this.cpu,i=t.gprs;return function(){t.mmu.waitPrefetch(i[15]);var s=i[15];i[15]=i[14]+(r<<1),i[14]=s-1}};h.prototype.constructBX=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),i.switchExecMode(s[t]&1);var e=0;t==15&&(e=s[t]&2),s[15]=s[t]&4294967294-e}};h.prototype.constructCMN=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=(s[r]>>>0)+(s[t]>>>0);i.cpsrN=e>>31,i.cpsrZ=!(e&4294967295),i.cpsrC=e>4294967295,i.cpsrV=s[r]>>31==s[t]>>31&&s[r]>>31!=e>>31&&s[t]>>31!=e>>31}};h.prototype.constructCMP1=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=s[r]-t;i.cpsrN=e>>31,i.cpsrZ=!(e&4294967295),i.cpsrC=s[r]>>>0>=t,i.cpsrV=s[r]>>31&&(s[r]^e)>>31}};h.prototype.constructCMP2=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=s[r],a=s[t],c=e-a,u=c>>31,p=e>>31;i.cpsrN=u,i.cpsrZ=!(c&4294967295),i.cpsrC=e>>>0>=a>>>0,i.cpsrV=p!=a>>31&&p!=u}};h.prototype.constructCMP3=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=s[r]-s[t];i.cpsrN=e>>31,i.cpsrZ=!(e&4294967295),i.cpsrC=s[r]>>>0>=s[t]>>>0,i.cpsrV=(s[r]^s[t])>>31&&(s[r]^e)>>31}};h.prototype.constructEOR=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),s[r]=s[r]^s[t],i.cpsrN=s[r]>>31,i.cpsrZ=!(s[r]&4294967295)}};h.prototype.constructLDMIA=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=s[r],a=0,c,u;for(c=1,u=0;u<8;c<<=1,++u)t&c&&(s[u]=i.mmu.load32(e),e+=4,++a);i.mmu.waitMulti32(e,a),1<>31,s.cpsrZ=!(e[r]&4294967295)}};h.prototype.constructLSL2=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=s[t]&255;e&&(e<32?(i.cpsrC=s[r]&1<<32-e,s[r]<<=e):(e>32?i.cpsrC=0:i.cpsrC=s[r]&1,s[r]=0)),i.cpsrN=s[r]>>31,i.cpsrZ=!(s[r]&4294967295)}};h.prototype.constructLSR1=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){s.mmu.waitPrefetch(e[15]),i==0?(s.cpsrC=e[t]>>31,e[r]=0):(s.cpsrC=e[t]&1<>>i),s.cpsrN=0,s.cpsrZ=!(e[r]&4294967295)}};h.prototype.constructLSR2=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=s[t]&255;e&&(e<32?(i.cpsrC=s[r]&1<>>=e):(e>32?i.cpsrC=0:i.cpsrC=s[r]>>31,s[r]=0)),i.cpsrN=s[r]>>31,i.cpsrZ=!(s[r]&4294967295)}};h.prototype.constructMOV1=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),s[r]=t,i.cpsrN=t>>31,i.cpsrZ=!(t&4294967295)}};h.prototype.constructMOV2=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){s.mmu.waitPrefetch(e[15]);var a=e[t];s.cpsrN=a>>31,s.cpsrZ=!(a&4294967295),s.cpsrC=0,s.cpsrV=0,e[r]=a}};h.prototype.constructMOV3=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),s[r]=s[t]}};h.prototype.constructMUL=function(r,t){var i=this.cpu,s=i.gprs;return function(){if(i.mmu.waitPrefetch(s[15]),i.mmu.waitMul(s[t]),s[t]&4294901760&&s[r]&4294901760){var e=(s[r]&4294901760)*s[t]&4294967295,a=(s[r]&65535)*s[t]&4294967295;s[r]=e+a&4294967295}else s[r]*=s[t];i.cpsrN=s[r]>>31,i.cpsrZ=!(s[r]&4294967295)}};h.prototype.constructMVN=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),s[r]=~s[t],i.cpsrN=s[r]>>31,i.cpsrZ=!(s[r]&4294967295)}};h.prototype.constructNEG=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=-s[t];i.cpsrN=e>>31,i.cpsrZ=!(e&4294967295),i.cpsrC=0>=e>>>0,i.cpsrV=s[t]>>31&&e>>31,s[r]=e}};h.prototype.constructORR=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),s[r]=s[r]|s[t],i.cpsrN=s[r]>>31,i.cpsrZ=!(s[r]&4294967295)}};h.prototype.constructPOP=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]),++i.cycles;var e=s[13],a=0,c,u;for(c=1,u=0;u<8;c<<=1,++u)r&c&&(i.mmu.waitSeq32(e),s[u]=i.mmu.load32(e),e+=4,++a);t&&(s[15]=i.mmu.load32(e)&4294967294,e+=4,++a),i.mmu.waitMulti32(e,a),s[13]=e}};h.prototype.constructPUSH=function(r,t){var i=this.cpu,s=i.gprs;return function(){var e=s[13]-4,a=0;i.mmu.waitPrefetch(s[15]),t&&(i.mmu.store32(e,s[14]),e-=4,++a);var c,u;for(c=128,u=7;c;c>>=1,--u)if(r&c){i.mmu.store32(e,s[u]),e-=4,++a;break}for(c>>=1,--u;c;c>>=1,--u)r&c&&(i.mmu.store32(e,s[u]),e-=4,++a);i.mmu.waitMulti32(e,a),s[13]=e+4}};h.prototype.constructROR=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=s[t]&255;if(e){var a=e&31;a>0?(i.cpsrC=s[r]&1<>>a|s[r]<<32-a):i.cpsrC=s[r]>>31}i.cpsrN=s[r]>>31,i.cpsrZ=!(s[r]&4294967295)}};h.prototype.constructSBC=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=(s[t]>>>0)+(i.cpsrC?0:1),a=(s[r]>>>0)-e;i.cpsrN=a>>31,i.cpsrZ=!(a&4294967295),i.cpsrC=s[r]>>>0>=a>>>0,i.cpsrV=(s[r]^e)>>31&&(s[r]^a)>>31,s[r]=a}};h.prototype.constructSTMIA=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.wait(s[15]);var e=s[r],a=0,c,u;for(c=1,u=0;u<8;c<<=1,++u)if(t&c){i.mmu.store32(e,s[u]),e+=4,++a;break}for(c<<=1,++u;u<8;c<<=1,++u)t&c&&(i.mmu.store32(e,s[u]),e+=4,++a);i.mmu.waitMulti32(e,a),s[r]=e}};h.prototype.constructSTR1=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){var a=e[t]+i;s.mmu.store32(a,e[r]),s.mmu.wait(e[15]),s.mmu.wait32(a)}};h.prototype.constructSTR2=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){s.mmu.store32(e[t]+e[i],e[r]),s.mmu.wait(e[15]),s.mmu.wait32(e[t]+e[i])}};h.prototype.constructSTR3=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.store32(s[13]+t,s[r]),i.mmu.wait(s[15]),i.mmu.wait32(s[13]+t)}};h.prototype.constructSTRB1=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){var a=e[t]+i;s.mmu.store8(a,e[r]),s.mmu.wait(e[15]),s.mmu.wait(a)}};h.prototype.constructSTRB2=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){s.mmu.store8(e[t]+e[i],e[r]),s.mmu.wait(e[15]),s.mmu.wait(e[t]+e[i])}};h.prototype.constructSTRH1=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){var a=e[t]+i;s.mmu.store16(a,e[r]),s.mmu.wait(e[15]),s.mmu.wait(a)}};h.prototype.constructSTRH2=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){s.mmu.store16(e[t]+e[i],e[r]),s.mmu.wait(e[15]),s.mmu.wait(e[t]+e[i])}};h.prototype.constructSUB1=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){s.mmu.waitPrefetch(e[15]);var a=e[t]-i;s.cpsrN=a>>31,s.cpsrZ=!(a&4294967295),s.cpsrC=e[t]>>>0>=i,s.cpsrV=e[t]>>31&&(e[t]^a)>>31,e[r]=a}};h.prototype.constructSUB2=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=s[r]-t;i.cpsrN=e>>31,i.cpsrZ=!(e&4294967295),i.cpsrC=s[r]>>>0>=t,i.cpsrV=s[r]>>31&&(s[r]^e)>>31,s[r]=e}};h.prototype.constructSUB3=function(r,t,i){var s=this.cpu,e=s.gprs;return function(){s.mmu.waitPrefetch(e[15]);var a=e[t]-e[i];s.cpsrN=a>>31,s.cpsrZ=!(a&4294967295),s.cpsrC=e[t]>>>0>=e[i]>>>0,s.cpsrV=e[t]>>31!=e[i]>>31&&e[t]>>31!=a>>31,e[r]=a}};h.prototype.constructSWI=function(r){var t=this.cpu,i=t.gprs;return function(){t.irq.swi(r),t.mmu.waitPrefetch(i[15])}};h.prototype.constructTST=function(r,t){var i=this.cpu,s=i.gprs;return function(){i.mmu.waitPrefetch(s[15]);var e=s[r]&s[t];i.cpsrN=e>>31,i.cpsrZ=!(e&4294967295)}};function A(){this.SP=13,this.LR=14,this.PC=15,this.MODE_ARM=0,this.MODE_THUMB=1,this.MODE_USER=16,this.MODE_FIQ=17,this.MODE_IRQ=18,this.MODE_SUPERVISOR=19,this.MODE_ABORT=23,this.MODE_UNDEFINED=27,this.MODE_SYSTEM=31,this.BANK_NONE=0,this.BANK_FIQ=1,this.BANK_IRQ=2,this.BANK_SUPERVISOR=3,this.BANK_ABORT=4,this.BANK_UNDEFINED=5,this.WORD_SIZE_ARM=4,this.WORD_SIZE_THUMB=2,this.BASE_RESET=0,this.BASE_UNDEF=4,this.BASE_SWI=8,this.BASE_PABT=12,this.BASE_DABT=16,this.BASE_IRQ=24,this.BASE_FIQ=28,this.armCompiler=new n(this),this.thumbCompiler=new h(this),this.generateConds(),this.gprs=new Int32Array(16),this.dfprs=new Float64Array(16),this.sfprs=new Float32Array(this.dfprs.buffer),this.ifprs=new Int32Array(this.dfprs.buffer)}A.prototype.resetCPU=function(r){for(var t=0;t<15;++t)this.gprs[t]=0;this.gprs[15]=r+4,this.dfprs.set(0),this.loadInstruction=this.loadInstructionArm,this.execMode=0,this.instructionWidth=4,this.mode=31,this.cpsrI=!1,this.cpsrF=!1,this.cpsrV=!1,this.cpsrC=!1,this.cpsrZ=!1,this.cpsrN=!1,this.bankedRegisters=[new Int32Array(7),new Int32Array(7),new Int32Array(2),new Int32Array(2),new Int32Array(2),new Int32Array(2)],this.spsr=0,this.bankedSPSRs=new Int32Array(6),this.cycles=0,this.shifterOperand=0,this.shifterCarryOut=0,this.page=null,this.pageId=0,this.pageRegion=-1,this.instruction=null,this.irq.clear();var i=this.gprs,s=this.mmu;this.step=function(){var e=this.instruction||(this.instruction=this.loadInstruction(i[15]-this.instructionWidth));if(i[15]+=this.instructionWidth,this.conditionPassed=!0,e(),!e.writesPC)this.instruction!=null&&((e.next==null||e.next.page.invalid)&&(e.next=this.loadInstruction(i[15]-this.instructionWidth)),this.instruction=e.next);else if(this.conditionPassed){var a=i[15]&=4294967294;this.execMode==0?(s.wait32(a),s.waitPrefetch32(a)):(s.wait(a),s.waitPrefetch(a)),i[15]+=this.instructionWidth,e.fixedJump?this.instruction!=null&&((e.next==null||e.next.page.invalid)&&(e.next=this.loadInstruction(i[15]-this.instructionWidth)),this.instruction=e.next):this.instruction=null}else this.instruction=null;this.irq.updateTimers()}};A.prototype.freeze=function(){return{PC:this.gprs[15]-this.instructionWidth,SP:this.gprs[13],gprs:[this.gprs[0],this.gprs[1],this.gprs[2],this.gprs[3],this.gprs[4],this.gprs[5],this.gprs[6],this.gprs[7],this.gprs[8],this.gprs[9],this.gprs[10],this.gprs[11],this.gprs[12],this.gprs[13],this.gprs[14],this.gprs[15]],sfprs:this.sfprs.slice(),dfprs:this.dfprs.slice(),ifprs:this.ifprs.slice(),mode:this.mode,cpsrI:this.cpsrI,cpsrF:this.cpsrF,cpsrV:this.cpsrV,cpsrC:this.cpsrC,cpsrZ:this.cpsrZ,cpsrN:this.cpsrN,bankedRegisters:[[this.bankedRegisters[0][0],this.bankedRegisters[0][1],this.bankedRegisters[0][2],this.bankedRegisters[0][3],this.bankedRegisters[0][4],this.bankedRegisters[0][5],this.bankedRegisters[0][6]],[this.bankedRegisters[1][0],this.bankedRegisters[1][1],this.bankedRegisters[1][2],this.bankedRegisters[1][3],this.bankedRegisters[1][4],this.bankedRegisters[1][5],this.bankedRegisters[1][6]],[this.bankedRegisters[2][0],this.bankedRegisters[2][1]],[this.bankedRegisters[3][0],this.bankedRegisters[3][1]],[this.bankedRegisters[4][0],this.bankedRegisters[4][1]],[this.bankedRegisters[5][0],this.bankedRegisters[5][1]]],spsr:this.spsr,bankedSPSRs:[this.bankedSPSRs[0],this.bankedSPSRs[1],this.bankedSPSRs[2],this.bankedSPSRs[3],this.bankedSPSRs[4],this.bankedSPSRs[5]],cycles:this.cycles,instructionWidth:this.instructionWidth}};A.prototype.defrost=function(r){this.instruction=null,this.page=null,this.pageId=0,this.pageRegion=-1,this.gprs[0]=r.gprs[0],this.gprs[1]=r.gprs[1],this.gprs[2]=r.gprs[2],this.gprs[3]=r.gprs[3],this.gprs[4]=r.gprs[4],this.gprs[5]=r.gprs[5],this.gprs[6]=r.gprs[6],this.gprs[7]=r.gprs[7],this.gprs[8]=r.gprs[8],this.gprs[9]=r.gprs[9],this.gprs[10]=r.gprs[10],this.gprs[11]=r.gprs[11],this.gprs[12]=r.gprs[12],this.gprs[13]=r.gprs[13],this.gprs[14]=r.gprs[14],this.gprs[15]=r.gprs[15],this.ifprs.set(r.ifprs),this.mode=r.mode,this.cpsrI=r.cpsrI,this.cpsrF=r.cpsrF,this.cpsrV=r.cpsrV,this.cpsrC=r.cpsrC,this.cpsrZ=r.cpsrZ,this.cpsrN=r.cpsrN,this.bankedRegisters[0][0]=r.bankedRegisters[0][0],this.bankedRegisters[0][1]=r.bankedRegisters[0][1],this.bankedRegisters[0][2]=r.bankedRegisters[0][2],this.bankedRegisters[0][3]=r.bankedRegisters[0][3],this.bankedRegisters[0][4]=r.bankedRegisters[0][4],this.bankedRegisters[0][5]=r.bankedRegisters[0][5],this.bankedRegisters[0][6]=r.bankedRegisters[0][6],this.bankedRegisters[1][0]=r.bankedRegisters[1][0],this.bankedRegisters[1][1]=r.bankedRegisters[1][1],this.bankedRegisters[1][2]=r.bankedRegisters[1][2],this.bankedRegisters[1][3]=r.bankedRegisters[1][3],this.bankedRegisters[1][4]=r.bankedRegisters[1][4],this.bankedRegisters[1][5]=r.bankedRegisters[1][5],this.bankedRegisters[1][6]=r.bankedRegisters[1][6],this.bankedRegisters[2][0]=r.bankedRegisters[2][0],this.bankedRegisters[2][1]=r.bankedRegisters[2][1],this.bankedRegisters[3][0]=r.bankedRegisters[3][0],this.bankedRegisters[3][1]=r.bankedRegisters[3][1],this.bankedRegisters[4][0]=r.bankedRegisters[4][0],this.bankedRegisters[4][1]=r.bankedRegisters[4][1],this.bankedRegisters[5][0]=r.bankedRegisters[5][0],this.bankedRegisters[5][1]=r.bankedRegisters[5][1],this.spsr=r.spsr,this.bankedSPSRs[0]=r.bankedSPSRs[0],this.bankedSPSRs[1]=r.bankedSPSRs[1],this.bankedSPSRs[2]=r.bankedSPSRs[2],this.bankedSPSRs[3]=r.bankedSPSRs[3],this.bankedSPSRs[4]=r.bankedSPSRs[4],this.bankedSPSRs[5]=r.bankedSPSRs[5],this.cycles=r.cycles,this.instructionWidth=r.instructionWidth,this.loadInstruction=r.instructionWidth==2?this.loadInstructionThumb:this.loadInstructionArm,this.execMode=r.instructionWidth==2?1:0};A.prototype.fetchPage=function(r){var t=this.mmu,i=r>>>t.BASE_OFFSET,s=t.addressToPage(i,r&t.OFFSET_MASK);if(i==this.pageRegion){if(s==this.pageId&&!this.page.invalid)return;this.pageId=s}else this.pageMask=t.memory[i].PAGE_MASK,this.pageRegion=i,this.pageId=s;this.page=t.accessPage(i,s)};A.prototype.loadInstructionArm=function(r){var t=null;this.fetchPage(r);var i=(r&this.pageMask)>>2;if(t=this.page.arm[i],t)return t;var s=this.mmu.load32(r)>>>0;return t=this.compileArm(s),t.next=null,t.page=this.page,t.address=r,t.opcode=s,this.page.arm[i]=t,t};A.prototype.loadInstructionThumb=function(r){var t=null;this.fetchPage(r);var i=(r&this.pageMask)>>1;if(t=this.page.thumb[i],t)return t;var s=this.mmu.load16(r);return t=this.compileThumb(s),t.next=null,t.page=this.page,t.address=r,t.opcode=s,this.page.thumb[i]=t,t};A.prototype.selectBank=function(r){switch(r){case 16:case 31:return 0;case 17:return 1;case 18:return 2;case 19:return 3;case 23:return 4;case 27:return 5;default:throw new N("Invalid user mode "+r+" passed to selectBank")}};A.prototype.switchExecMode=function(r){this.execMode!=r&&(this.execMode=r,r==0?(this.instructionWidth=4,this.loadInstruction=this.loadInstructionArm):(this.instructionWidth=2,this.loadInstruction=this.loadInstructionThumb))};A.prototype.switchMode=function(r){if(r!=this.mode){if(r!=16||r!=31){var t=this.selectBank(r),i=this.selectBank(this.mode);if(t!=i){if(r==17||this.mode==17){var s=i==1?1:0,e=t==1?1:0;this.bankedRegisters[s][2]=this.gprs[8],this.bankedRegisters[s][3]=this.gprs[9],this.bankedRegisters[s][4]=this.gprs[10],this.bankedRegisters[s][5]=this.gprs[11],this.bankedRegisters[s][6]=this.gprs[12],this.gprs[8]=this.bankedRegisters[e][2],this.gprs[9]=this.bankedRegisters[e][3],this.gprs[10]=this.bankedRegisters[e][4],this.gprs[11]=this.bankedRegisters[e][5],this.gprs[12]=this.bankedRegisters[e][6]}this.bankedRegisters[i][0]=this.gprs[13],this.bankedRegisters[i][1]=this.gprs[14],this.gprs[13]=this.bankedRegisters[t][0],this.gprs[14]=this.bankedRegisters[t][1],this.bankedSPSRs[i]=this.spsr,this.spsr=this.bankedSPSRs[t]}}this.mode=r}};A.prototype.packCPSR=function(){return this.mode|this.execMode<<5|this.cpsrF<<6|this.cpsrI<<7|this.cpsrN<<31|this.cpsrZ<<30|this.cpsrC<<29|this.cpsrV<<28};A.prototype.unpackCPSR=function(r){this.switchMode(r&31),this.switchExecMode(!!(r&32)),this.cpsrF=r&64,this.cpsrI=r&128,this.cpsrN=r&2147483648,this.cpsrZ=r&1073741824,this.cpsrC=r&536870912,this.cpsrV=r&268435456,this.irq.testIRQ()};A.prototype.hasSPSR=function(){return this.mode!=31&&this.mode!=16};A.prototype.raiseIRQ=function(){if(!this.cpsrI){var r=this.packCPSR(),t=this.instructionWidth;this.switchMode(18),this.spsr=r,this.gprs[14]=this.gprs[15]-t+4,this.gprs[15]=this.BASE_IRQ+4,this.instruction=null,this.switchExecMode(0),this.cpsrI=!0}};A.prototype.raiseTrap=function(){var r=this.packCPSR(),t=this.instructionWidth;this.switchMode(19),this.spsr=r,this.gprs[14]=this.gprs[15]-t,this.gprs[15]=this.BASE_SWI+4,this.instruction=null,this.switchExecMode(0),this.cpsrI=!0};A.prototype.badOp=function(r){var t=function(){throw new N("Illegal instruction: 0x"+r.toString(16))};return t.writesPC=!0,t.fixedJump=!1,t};A.prototype.generateConds=function(){var r=this;this.conds=[function(){return r.conditionPassed=r.cpsrZ},function(){return r.conditionPassed=!r.cpsrZ},function(){return r.conditionPassed=r.cpsrC},function(){return r.conditionPassed=!r.cpsrC},function(){return r.conditionPassed=r.cpsrN},function(){return r.conditionPassed=!r.cpsrN},function(){return r.conditionPassed=r.cpsrV},function(){return r.conditionPassed=!r.cpsrV},function(){return r.conditionPassed=r.cpsrC&&!r.cpsrZ},function(){return r.conditionPassed=!r.cpsrC||r.cpsrZ},function(){return r.conditionPassed=!r.cpsrN==!r.cpsrV},function(){return r.conditionPassed=!r.cpsrN!=!r.cpsrV},function(){return r.conditionPassed=!r.cpsrZ&&!r.cpsrN==!r.cpsrV},function(){return r.conditionPassed=r.cpsrZ||!r.cpsrN!=!r.cpsrV},null,null]};A.prototype.barrelShiftImmediate=function(r,t,i){var s=this,e=this.gprs,a=this.badOp;switch(r){case 0:t?a=function(){s.shifterOperand=e[i]<>>t,s.shifterCarryOut=e[i]&1<>t,s.shifterCarryOut=e[i]&1<>>t|e[i]<<32-t,s.shifterCarryOut=e[i]&1<>>1,s.shifterCarryOut=e[i]&1};break}return a};A.prototype.compileArm=function(r){var t=this.badOp(r),i=r&234881024,s=this,e=this.gprs,a=this.conds[(r&4026531840)>>>28];if((r&268435440)==19922704){var c=r&15;t=this.armCompiler.constructBX(c,a),t.writesPC=!0,t.fixedJump=!1}else if(!(r&201326592)&&(i==33554432||(r&144)!=144)){var u=r&31457280,p=r&1048576,F=!1;if((u&25165824)==16777216&&!p){var R=r&4194304;if((r&11595776)==2158592){var c=r&15,m=r&255,v=(r&3840)>>7;m=m>>>v|m<<32-v,t=this.armCompiler.constructMSR(c,R,r,m,a),t.writesPC=!1}else if((r&12517376)==983040){var o=(r&61440)>>12;t=this.armCompiler.constructMRS(o,R,a),t.writesPC=o==15}}else{var f=(r&983040)>>16,o=(r&61440)>>12,U=r&96,c=r&15,g=function(){throw new N("BUG: invalid barrel shifter")};if(r&33554432){var m=r&255,ir=(r&3840)>>7;ir?g=this.armCompiler.constructAddressingMode1ImmediateRotate(m,ir):g=this.armCompiler.constructAddressingMode1Immediate(m)}else if(r&16){var l=(r&3840)>>8;switch(F=!0,U){case 0:g=this.armCompiler.constructAddressingMode1LSL(l,c);break;case 32:g=this.armCompiler.constructAddressingMode1LSR(l,c);break;case 64:g=this.armCompiler.constructAddressingMode1ASR(l,c);break;case 96:g=this.armCompiler.constructAddressingMode1ROR(l,c);break}}else{var m=(r&3968)>>7;g=this.barrelShiftImmediate(U,m,c)}switch(u){case 0:p?t=this.armCompiler.constructANDS(o,f,g,a):t=this.armCompiler.constructAND(o,f,g,a);break;case 2097152:p?t=this.armCompiler.constructEORS(o,f,g,a):t=this.armCompiler.constructEOR(o,f,g,a);break;case 4194304:p?t=this.armCompiler.constructSUBS(o,f,g,a):t=this.armCompiler.constructSUB(o,f,g,a);break;case 6291456:p?t=this.armCompiler.constructRSBS(o,f,g,a):t=this.armCompiler.constructRSB(o,f,g,a);break;case 8388608:p?t=this.armCompiler.constructADDS(o,f,g,a):t=this.armCompiler.constructADD(o,f,g,a);break;case 10485760:p?t=this.armCompiler.constructADCS(o,f,g,a):t=this.armCompiler.constructADC(o,f,g,a);break;case 12582912:p?t=this.armCompiler.constructSBCS(o,f,g,a):t=this.armCompiler.constructSBC(o,f,g,a);break;case 14680064:p?t=this.armCompiler.constructRSCS(o,f,g,a):t=this.armCompiler.constructRSC(o,f,g,a);break;case 16777216:t=this.armCompiler.constructTST(o,f,g,a);break;case 18874368:t=this.armCompiler.constructTEQ(o,f,g,a);break;case 20971520:t=this.armCompiler.constructCMP(o,f,g,a);break;case 23068672:t=this.armCompiler.constructCMN(o,f,g,a);break;case 25165824:p?t=this.armCompiler.constructORRS(o,f,g,a):t=this.armCompiler.constructORR(o,f,g,a);break;case 27262976:p?t=this.armCompiler.constructMOVS(o,f,g,a):t=this.armCompiler.constructMOV(o,f,g,a);break;case 29360128:p?t=this.armCompiler.constructBICS(o,f,g,a):t=this.armCompiler.constructBIC(o,f,g,a);break;case 31457280:p?t=this.armCompiler.constructMVNS(o,f,g,a):t=this.armCompiler.constructMVN(o,f,g,a);break}t.writesPC=o==15}}else if((r&263196656)==16777360){var c=r&15,o=r>>12&15,f=r>>16&15;r&4194304?t=this.armCompiler.constructSWPB(o,f,c,a):t=this.armCompiler.constructSWP(o,f,c,a),t.writesPC=o==15}else switch(i){case 0:if((r&16777456)==144){var o=(r&983040)>>16,f=(r&61440)>>12,l=(r&3840)>>8,c=r&15;switch(r&15728640){case 0:t=this.armCompiler.constructMUL(o,l,c,a);break;case 1048576:t=this.armCompiler.constructMULS(o,l,c,a);break;case 2097152:t=this.armCompiler.constructMLA(o,f,l,c,a);break;case 3145728:t=this.armCompiler.constructMLAS(o,f,l,c,a);break;case 8388608:t=this.armCompiler.constructUMULL(o,f,l,c,a);break;case 9437184:t=this.armCompiler.constructUMULLS(o,f,l,c,a);break;case 10485760:t=this.armCompiler.constructUMLAL(o,f,l,c,a);break;case 11534336:t=this.armCompiler.constructUMLALS(o,f,l,c,a);break;case 12582912:t=this.armCompiler.constructSMULL(o,f,l,c,a);break;case 13631488:t=this.armCompiler.constructSMULLS(o,f,l,c,a);break;case 14680064:t=this.armCompiler.constructSMLAL(o,f,l,c,a);break;case 15728640:t=this.armCompiler.constructSMLALS(o,f,l,c,a);break}t.writesPC=o==15}else{var _=r&1048576,o=(r&61440)>>12,dr=(r&3840)>>4,Pr=c=r&15,ar=r&32,p=r&64,L=r&2097152,i=r&4194304,C;if(i){var m=Pr|dr;C=this.armCompiler.constructAddressingMode23Immediate(r,m,a)}else C=this.armCompiler.constructAddressingMode23Register(r,c,a);C.writesPC=!!L&&f==15,(r&144)==144&&(_?ar?p?t=this.armCompiler.constructLDRSH(o,C,a):t=this.armCompiler.constructLDRH(o,C,a):p&&(t=this.armCompiler.constructLDRSB(o,C,a)):!p&&ar&&(t=this.armCompiler.constructSTRH(o,C,a))),t.writesPC=o==15||C.writesPC}break;case 67108864:case 100663296:var o=(r&61440)>>12,_=r&1048576,cr=r&4194304,i=r&33554432;if((r&4293918960)==-403701520){var m=r&15;throw new N("Program exited ("+m+")")}var C=function(){throw new N("Unimplemented memory access: 0x"+r.toString(16))};if(~r&16777216&&(r&=4292870143),i){var c=r&15,U=r&96,ur=(r&3968)>>7;U||ur?(g=this.barrelShiftImmediate(U,ur,c),C=this.armCompiler.constructAddressingMode2RegisterShifted(r,g,a)):C=this.armCompiler.constructAddressingMode23Register(r,c,a)}else{var O=r&4095;C=this.armCompiler.constructAddressingMode23Immediate(r,O,a)}_?cr?t=this.armCompiler.constructLDRB(o,C,a):t=this.armCompiler.constructLDR(o,C,a):cr?t=this.armCompiler.constructSTRB(o,C,a):t=this.armCompiler.constructSTR(o,C,a),t.writesPC=_&&(o==15||C.writesPC);break;case 134217728:var _=r&1048576,L=r&2097152,B=r&4194304,J=r&8388608,j=r&16777216,l=r&65535,f=(r&983040)>>16,C,m=0,O=0,Z=!1;if(J){j&&(m=4);for(var H=1,i=0;i<16;H<<=1,++i)l&H&&(L&&i==f&&!O&&(l&=~H,m+=4,Z=!0),O+=4)}else{j||(m=4);for(var H=1,i=0;i<16;H<<=1,++i)l&H&&(L&&i==f&&!O&&(l&=~H,m+=4,Z=!0),m-=4,O-=4)}L?C=this.armCompiler.constructAddressingMode4Writeback(m,O,f,Z):C=this.armCompiler.constructAddressingMode4(m,f),_?(B?t=this.armCompiler.constructLDMS(l,C,a):t=this.armCompiler.constructLDM(l,C,a),t.writesPC=!!(l&32768)):(B?t=this.armCompiler.constructSTMS(l,C,a):t=this.armCompiler.constructSTM(l,C,a),t.writesPC=!1);break;case 167772160:var m=r&16777215;m&8388608&&(m|=4278190080),m<<=2;var br=r&16777216;br?t=this.armCompiler.constructBL(m,a):t=this.armCompiler.constructB(m,a),t.writesPC=!0,t.fixedJump=!0;break;case 201326592:var _=r&1048576,L=r&2097152,B=r&4194304,J=r&8388608,j=r&16777216,f=(r&983040)>>16,W=(r&61440)>>12,Or=(r&3840)>>8,m=r&255,yr=r>>28&15,a=this.conds[yr];if((r&264179456)==221055488)t=this.armCompiler.constructVPUSH(a,W<<1|(B?1:0),m,!0);else if((r&264179456)==221055744)t=this.armCompiler.constructVPUSH(a,((B?16:0)|W)*2,m,!1);else if((r&264179456)==213715456)t=this.armCompiler.constructVPOP(a,W<<1|(B?1:0),m,!0);else if((r&264179456)==213715712)t=this.armCompiler.constructVPOP(a,((B?16:0)|W)*2,m,!1);else if((r&253759232)==218106368){m*=4,J||(m=-m);var Z=!1,K=W<<1|(B?1:0),C;L?C=this.armCompiler.constructAddressingMode4Writeback(m,O,f,Z):C=this.armCompiler.constructAddressingMode4(m,f),_?t=this.armCompiler.constructVLDR(a,K,C,!0):t=this.armCompiler.constructVSTR(a,K,C,!0)}else if((r&253759232)==218106624){m*=4,J||(m=-m);var Z=!1,K=((B?16:0)|W)*2,C;L?C=this.armCompiler.constructAddressingMode4Writeback(m,O,f,Z):C=this.armCompiler.constructAddressingMode4(m,f),_?t=this.armCompiler.constructVLDR(a,K,C,!1):t=this.armCompiler.constructVSTR(a,K,C,!1)}break;case 234881024:if((r&251658240)==251658240){var m=r&16777215;t=this.armCompiler.constructSWI(m,a),t.writesPC=!1}else if((r&263720528)==246942272){let k=r>>28&15,d=r>>22&1,x=r>>16&7,M=r>>12&15,P=r>>8&1,y=r>>7&1,b=r>>5&1,S=r&15,w=x&4,V=P!=0,G=w?x&1:0,$=y!=0,rr=!1,Sr=P?(d?16:0)|M:M<<1|(d?1:0),wr=P?(b?16:0)|S:S<<1|(b?1:0);t=this.armCompiler.constructVCVT(a,Sr,wr,w,V,G,$,rr),t.writesPC=!1}else if((r&264179408)==246876864){let k=r>>28&15,d=r>>22&1,x=r>>12&15,M=r>>8&1,P=r>>5&1,y=r&15,b=M!=0,S=M?(d?16:0)|x:x<<1|(d?1:0),w=M?(P?16:0)|y:y<<1|(P?1:0);t=this.armCompiler.constructVCVTF(a,S,w,b),t.writesPC=!1}else if((r&262147600)==236980736){let k=r>>28&15,d=r>>22&1,x=r>>7&1,M=r>>5&1,P=(r&15728640)>>20,y=(r&983040)>>16,b=(r&61440)>>12,S=(r&224)>>5,w=r&15,V=r>>8&1,G=V?(d?16:0)|b:b<<1|(d?1:0),$=V?(M?16:0)|w:w<<1|(M?1:0),rr=V?(x?16:0)|y:y<<1|(x?1:0);var a=this.conds[k];t=this.armCompiler.constructVFP3Register(a,P,rr,G,V,S,$),t.writesPC=!1}else if((r&263195728)==243271680){let k=r>>28&15,d=r>>22&1,x=r>>16&15,M=r>>12&15,P=r>>8&3,y=r>>7&1,b=r>>5&1,S=r&15,w=P==3?(d?16:0)|M:M<<1|(d?1:0),V=P==3?(b?16:0)|S:S<<1|(b?1:0),G=P==3?(y?16:0)|x:x<<1|(y?1:0);t=this.armCompiler.constructVFP3Register(a,8,G,w,P==3,0,V),t.writesPC=!1}else if((r&264179280)==246680128){let k=r>>28&15,d=r>>22&1,x=r>>12&15,M=r>>8&1,P=r>>7&1,y=r>>5&1,b=r&15,S=M?(d?16:0)|x:x<<1|(d?1:0),w=M?(y?16:0)|b:b<<1|(y?1:0);var a=this.conds[k];t=this.armCompiler.constructVCMP(a,S,x,M,P,w,b),t.writesPC=!1}else if((r&264179455)==246745664){let k=r>>28&15,d=r>>22&1,x=r>>12&15,M=r>>8&1,P=r>>7&1,y=r>>5&1,b=r&15,S=M?(d?16:0)|x:x<<1|(d?1:0),w=M?(y?16:0)|b:b<<1|(y?1:0);var a=this.conds[k];t=this.armCompiler.constructVCMP0(a,S,x,M,P,w,b),t.writesPC=!1}else if(r==4008835600)t=this.armCompiler.constructNOP();else if((r&266342160)==234883600){let k=r>>28&15,d=r>>20&1,x=r>>16&15,M=r>>12&15,P=r>>7&1;var a=this.conds[k];t=this.armCompiler.constructVMOV(a,d,x<<1|(P?1:0),M)}else r==3992980240?t=this.armCompiler.constructVMOV(a,!1,0,0):r==3995081488&&(t=this.armCompiler.constructVMOV(a,!1,1,1));break;default:throw new N("Bad opcode: 0x"+r.toString(16))}return t.execMode=0,t.fixedJump=t.fixedJump||!1,t};A.prototype.compileThumb=function(r){var t=this.badOp(r&65535),i=this,s=this.gprs;if((r&64512)==16384){var e=(r&56)>>3,a=r&7;switch(r&960){case 0:t=this.thumbCompiler.constructAND(a,e);break;case 64:t=this.thumbCompiler.constructEOR(a,e);break;case 128:t=this.thumbCompiler.constructLSL2(a,e);break;case 192:t=this.thumbCompiler.constructLSR2(a,e);break;case 256:t=this.thumbCompiler.constructASR2(a,e);break;case 320:t=this.thumbCompiler.constructADC(a,e);break;case 384:t=this.thumbCompiler.constructSBC(a,e);break;case 448:t=this.thumbCompiler.constructROR(a,e);break;case 512:t=this.thumbCompiler.constructTST(a,e);break;case 576:t=this.thumbCompiler.constructNEG(a,e);break;case 640:t=this.thumbCompiler.constructCMP2(a,e);break;case 704:t=this.thumbCompiler.constructCMN(a,e);break;case 768:t=this.thumbCompiler.constructORR(a,e);break;case 832:t=this.thumbCompiler.constructMUL(a,e);break;case 896:t=this.thumbCompiler.constructBIC(a,e);break;case 960:t=this.thumbCompiler.constructMVN(a,e);break}t.writesPC=!1}else if((r&64512)==17408){var e=(r&120)>>3,c=r&7,u=r&128,a=c|u>>4;switch(r&768){case 0:t=this.thumbCompiler.constructADD4(a,e),t.writesPC=a==15;break;case 256:t=this.thumbCompiler.constructCMP3(a,e),t.writesPC=!1;break;case 512:t=this.thumbCompiler.constructMOV3(a,e),t.writesPC=a==15;break;case 768:t=this.thumbCompiler.constructBX(a,e),t.writesPC=!0,t.fixedJump=!1;break}}else if((r&63488)==6144){var e=(r&448)>>6,c=(r&56)>>3,a=r&7;switch(r&1536){case 0:t=this.thumbCompiler.constructADD3(a,c,e);break;case 512:t=this.thumbCompiler.constructSUB3(a,c,e);break;case 1024:var p=(r&448)>>6;p?t=this.thumbCompiler.constructADD1(a,c,p):t=this.thumbCompiler.constructMOV2(a,c,e);break;case 1536:var p=(r&448)>>6;t=this.thumbCompiler.constructSUB1(a,c,p);break}t.writesPC=!1}else if(r&57344)if((r&57344)==8192){var p=r&255,c=(r&1792)>>8;switch(r&6144){case 0:t=this.thumbCompiler.constructMOV1(c,p);break;case 2048:t=this.thumbCompiler.constructCMP1(c,p);break;case 4096:t=this.thumbCompiler.constructADD2(c,p);break;case 6144:t=this.thumbCompiler.constructSUB2(c,p);break}t.writesPC=!1}else if((r&63488)==18432){var a=(r&1792)>>8,p=(r&255)<<2;t=this.thumbCompiler.constructLDR3(a,p),t.writesPC=!1}else if((r&61440)==20480){var a=r&7,c=(r&56)>>3,e=(r&448)>>6,F=r&3584;switch(F){case 0:t=this.thumbCompiler.constructSTR2(a,c,e);break;case 512:t=this.thumbCompiler.constructSTRH2(a,c,e);break;case 1024:t=this.thumbCompiler.constructSTRB2(a,c,e);break;case 1536:t=this.thumbCompiler.constructLDRSB(a,c,e);break;case 2048:t=this.thumbCompiler.constructLDR2(a,c,e);break;case 2560:t=this.thumbCompiler.constructLDRH2(a,c,e);break;case 3072:t=this.thumbCompiler.constructLDRB2(a,c,e);break;case 3584:t=this.thumbCompiler.constructLDRSH(a,c,e);break}t.writesPC=!1}else if((r&57344)==24576){var a=r&7,c=(r&56)>>3,p=(r&1984)>>4,R=r&4096;R&&(p>>=2);var m=r&2048;m?R?t=this.thumbCompiler.constructLDRB1(a,c,p):t=this.thumbCompiler.constructLDR1(a,c,p):R?t=this.thumbCompiler.constructSTRB1(a,c,p):t=this.thumbCompiler.constructSTR1(a,c,p),t.writesPC=!1}else if((r&62976)==46080){var v=!!(r&256),o=r&255;r&2048?(t=this.thumbCompiler.constructPOP(o,v),t.writesPC=v,t.fixedJump=!1):(t=this.thumbCompiler.constructPUSH(o,v),t.writesPC=!1)}else if(r&32768)switch(r&28672){case 0:var a=r&7,c=(r&56)>>3,p=(r&1984)>>5;r&2048?t=this.thumbCompiler.constructLDRH1(a,c,p):t=this.thumbCompiler.constructSTRH1(a,c,p),t.writesPC=!1;break;case 4096:var a=(r&1792)>>8,p=(r&255)<<2,m=r&2048;m?t=this.thumbCompiler.constructLDR4(a,p):t=this.thumbCompiler.constructSTR3(a,p),t.writesPC=!1;break;case 8192:var a=(r&1792)>>8,p=(r&255)<<2;r&2048?t=this.thumbCompiler.constructADD6(a,p):t=this.thumbCompiler.constructADD5(a,p),t.writesPC=!1;break;case 12288:if(!(r&3840)){var R=r&128,p=(r&127)<<2;R&&(p=-p),t=this.thumbCompiler.constructADD7(p),t.writesPC=!1}break;case 16384:var c=(r&1792)>>8,o=r&255;r&2048?t=this.thumbCompiler.constructLDMIA(c,o):t=this.thumbCompiler.constructSTMIA(c,o),t.writesPC=!1;break;case 20480:var f=(r&3840)>>8,p=r&255;if(f==15)t=this.thumbCompiler.constructSWI(p),t.writesPC=!1;else{r&128&&(p|=4294967040),p<<=1;var U=this.conds[f];t=this.thumbCompiler.constructB1(p,U),t.writesPC=!0,t.fixedJump=!0}break;case 24576:case 28672:var p=r&2047,g=r&6144;switch(g){case 0:p&1024&&(p|=4294965248),p<<=1,t=this.thumbCompiler.constructB2(p),t.writesPC=!0,t.fixedJump=!0;break;case 2048:break;case 4096:p&1024&&(p|=4294966272),p<<=12,t=this.thumbCompiler.constructBL1(p),t.writesPC=!1;break;case 6144:t=this.thumbCompiler.constructBL2(p),t.writesPC=!0,t.fixedJump=!1;break}break;default:throw new N("Undefined instruction: 0x"+r.toString(16))}else throw new N("Bad opcode: 0x"+r.toString(16));else{var a=r&7,e=(r&56)>>3,p=(r&1984)>>6;switch(r&6144){case 0:t=this.thumbCompiler.constructLSL1(a,e,p);break;case 2048:t=this.thumbCompiler.constructLSR1(a,e,p);break;case 4096:t=this.thumbCompiler.constructASR1(a,e,p);break;case 6144:break}t.writesPC=!1}return t.execMode=1,t.fixedJump=t.fixedJump||!1,t};var Y=class{constructor(){this.f64arr=new Float64Array(1);this.f32arr=new Float32Array(this.f64arr.buffer);this.i32arr=new Int32Array(this.f64arr.buffer);this.BASE_OFFSET=24;this.OFFSET_MASK=16777215;this.core=new A,this.core.irq=this,this.core.mmu=this,this.resetMemory()}resetMemory(){this.memory=[];for(var t=0;t<256;t++)this.memory[t]={PAGE_MASK:2047,ICACHE_PAGE_BITS:10,icache:new Array}}advanceInsn(){var t=this.core.cycles;return this.core.step(),t-=this.core.cycles,t>0?t:1}getPC(){return this.core.gprs[15]-this.core.instructionWidth}getSP(){return this.core.gprs[13]}isStable(){return!0}connectMemoryBus(t){this.bus=t}reset(){this.resetMemory();let t=this.load32(0);this.core.resetCPU(t)}saveState(){return this.core.freeze()}loadState(t){this.core.defrost(t)}load8(t){return this.bus.read(t)<<24>>24}loadU8(t){return this.bus.read(t)&255}load16(t){return this.loadU16(t)<<16>>16}loadU16(t){return this.bus.read(t)|this.bus.read(t+1)<<8}load32(t){var i=this.bus.read32(t);return i}store8(t,i){this.bus.write(t,i&255)}store16(t,i){this.bus.write(t,i&255),this.bus.write(t+1,i>>8&255)}store32(t,i){this.bus.write32(t,i)}wait(t){++this.core.cycles}wait32(t){++this.core.cycles}waitSeq32(t){++this.core.cycles}waitMul(t){(t&4294967040)==4294967040||!(t&4294967040)?this.core.cycles+=1:(t&4294901760)==4294901760||!(t&4294901760)?this.core.cycles+=2:(t&4278190080)==4278190080||!(t&4278190080)?this.core.cycles+=3:this.core.cycles+=4}waitMulti32(t,i){this.core.cycles+=2}waitPrefetch(t){++this.core.cycles}waitPrefetch32(t){++this.core.cycles}addressToPage(t,i){return i>>this.memory[t].ICACHE_PAGE_BITS}accessPage(t,i){var s=this.memory[t],e=s.icache[i];return(!e||e.invalid)&&(e={thumb:new Array(1<>16)}clear(){}updateTimers(){}testIRQ(){}isThumb(){return this.core.instructionWidth==2}getDebugTree(){return{state:this.saveState(),mmu:this.core.mmu}}};var kr=fr([[T.A,0,1],[T.B,0,2],[T.GP_A,0,1],[T.GP_B,0,2],[T.SELECT,0,4],[T.START,0,8],[T.RIGHT,0,16],[T.LEFT,0,32],[T.UP,0,64],[T.DOWN,0,128]]),D=0,I=1048576,Mr=0,X=67108864,z=256,Er=1e6,xr=4e6,Ar=3991793133,q=class extends mr{constructor(){super();this.cpuFrequency=xr;this.canvasWidth=160;this.numTotalScanlines=256;this.numVisibleScanlines=128;this.cpuCyclesPerLine=Math.floor(xr/(256*60));this.defaultROMSize=I-Mr;this.sampleRate=1;this.cpu=new Y;this.ram=new Uint8Array(I);this.ram16=new Uint16Array(this.ram.buffer);this.ram32=new Uint32Array(this.ram.buffer);this.rombase=Mr;this.brightness=255;this.ioregs=new Uint8Array(z);this.ioregs32=new Uint32Array(this.ioregs.buffer);this.read=er([[D,D+I-1,I-1,i=>this.ram[i]],[X,X+z-1,z-1,(i,s)=>this.readIO(i)]],{defaultval:Ar&255});this.write=er([[D,D+I-1,I-1,(i,s)=>{this.ram[i]=s}],[X,X+z-1,z-1,(i,s)=>{this.writeIO(i,s)}]]);this.read32=i=>i>=D&&i>2]:this.read(i)|this.read(i+1)<<8|this.read(i+2)<<16|this.read(i+3)<<24;this.write32=(i,s)=>{i>=D&&i>2]=s:(this.write(i,s&255),this.write(i+1,s>>8&255),this.write(i+2,s>>16&255),this.write(i+3,s>>24&255))};this.connectCPUMemoryBus(this),this.handler=hr(this.inputs,kr)}connectVideo(i){super.connectVideo(i),this.pixels32=i,this.pixels8=new Uint8Array(i.buffer)}connectSerialIO(i){this.serial=i}loadROM(i){super.loadROM(i)}reset(){this.ram.fill(0),this.rom&&this.ram.set(this.rom,this.rombase),super.reset(),this.serialOut=[],this.serialIn=[]}readAddress(i){return i>=D&&i>8;case 36:return this.getRasterX();case 37:return this.getRasterX()>>8;case 64:return(this.serial.byteAvailable()?128:0)|(this.serial.clearToSend()?64:0);case 68:let s=this.serialIn.shift();return s!=null?(this.serialOut.push(s),s.value):0;default:return 0}}writeIO(i,s){switch(this.ioregs[i]=s,i){case 72:this.serialOut.length>1&1048575,a=this.brightness<<24,c=0;c>5&31)<<11|(u>>10&31)<<19}}getDebugCategories(){return["CPU","Stack","FPU"]}getDebugInfo(i,s){switch(i){case"Stack":for(var u="",p=s.c,e=p.gprs[13],a=p.gprs[11],c=0;c<16&&(u+=E(e,8)+" "+E(this.ram32[e-D>>2],8),e==a&&(u+=" FP"),u+=` `,e+=4,!(e>=D+I));c++);return u;case"CPU":var u="",p=s.c;let F={2:"Thumb",4:"ARM"},R={15:"PC",14:"LR",13:"SP",12:"IP",11:"FP",9:"SB"};for(var c=0;c<8;c++){let v=c+8;u+=Q("r"+c,5)+" "+E(p.gprs[c],8)+" ",u+=Q("r"+v,5)+" "+E(p.gprs[v],8)+Q(R[v]||"",3)+` `}return u+="Flags ",u+=p.cpsrN?" N":" -",u+=p.cpsrV?" V":" -",u+=p.cpsrF?" F":" -",u+=p.cpsrZ?" Z":" -",u+=p.cpsrC?" C":" -",u+=p.cpsrI?" I":" -",u+=` `,u+="MODE "+F[p.instructionWidth]+" "+Dr[p.mode]+` @@ -6,4 +6,4 @@ import{F as Rr,I as gr,r as mr}from"./chunk-G4HBIXG4.js";import{E as or,K as Fr, `,u+="cycl "+p.cycles+` `,u;case"FPU":for(var u="",p=s.c,c=0;c<16;c++)u+=Q("s"+c,5)+" "+E(p.ifprs[c],8)+" "+p.sfprs[c].toPrecision(6),c&1&&(u+=Q("d"+(c>>1),5)+" "+p.dfprs[c>>1].toPrecision(12)),u+=` `;return u}}saveState(){var i=super.saveState();return i.serial={sin:this.serialIn.slice(0),sout:this.serialOut.slice(0)},i}loadState(i){super.loadState(i),this.serialIn=i.serial.sin,this.serialOut=i.serial.sout}},Dr={16:"USER",17:"FIQ",18:"IRQ",19:"SUPERVISOR",23:"ABORT",27:"UNDEFINED",31:"SYSTEM"};var Ir=[{id:"vidfill.c",name:"Video Memory Fill"}],tr=class extends gr{constructor(){super(...arguments);this.getToolForFilename=Rr}getPresets(){return Ir}getDefaultExtensions(){return[".c",".armips",".vasm"]}},sr=class extends tr{constructor(){super(...arguments);this.getMemoryMap=function(){return{main:[{name:"ROM",start:0,size:1048576,type:"ram"},{name:"I/O",start:67108864,size:256,type:"io"}]}}}async start(){super.start(),console.log("Loading Capstone"),await or("./lib/capstone-arm.min.js"),this.capstone_arm=new cs.Capstone(cs.ARCH_ARM,cs.MODE_ARM),this.capstone_thumb=new cs.Capstone(cs.ARCH_ARM,cs.MODE_THUMB)}newMachine(){return new q}readAddress(i){return this.machine.read(i)}getPlatformName(){return"ARM7"}getDebugTree(){return nr(pr({},this.machine.cpu.getDebugTree()),{dwarf:this.debugSymbols.debuginfo})}disassemble(i,s){for(var e=this.machine.cpu.isThumb(),a=e?this.capstone_thumb:this.capstone_arm,c=[],u=0;u<4;u++)c[u]=s(i+u);var p=a.disasm(c,i,4),F=p&&p[0];return F?{nbytes:F.size,line:F.mnemonic+" "+F.op_str,isaddr:F.address>0,iscall:F.mnemonic=="bl"||F.mnemonic=="blx"}:{nbytes:4,line:"???",isaddr:!1}}};Fr.arm32=sr;export{tr as BaseARMMachinePlatform}; -//# sourceMappingURL=arm32-DPNHXLE7.js.map +//# sourceMappingURL=arm32-JOUZ3MAF.js.map diff --git a/gen/arm32-DPNHXLE7.js.map b/gen/arm32-JOUZ3MAF.js.map similarity index 100% rename from gen/arm32-DPNHXLE7.js.map rename to gen/arm32-JOUZ3MAF.js.map diff --git a/gen/astrocade-K3HTJCX2.js b/gen/astrocade-JYCWWO6Z.js similarity index 99% rename from gen/astrocade-K3HTJCX2.js rename to gen/astrocade-JYCWWO6Z.js index b9627327..74b6c2fe 100644 --- a/gen/astrocade-K3HTJCX2.js +++ b/gen/astrocade-JYCWWO6Z.js @@ -1,4 +1,4 @@ -import{K as D0,c as l0,d as m0,e as u0,k as h0,r as E0}from"./chunk-G4HBIXG4.js";import{$ as x0,K as k,W as A,X as C0,Z as X0,aa as N,g,l as c0,m as B0,t as g0}from"./chunk-TYDI7JZQ.js";import"./chunk-KT7KMEQC.js";var I0=X0([[A.UP,16,1],[A.DOWN,16,2],[A.LEFT,16,4],[A.RIGHT,16,8],[A.A,16,16],[A.P2_UP,17,1],[A.P2_DOWN,17,2],[A.P2_LEFT,17,4],[A.P2_RIGHT,17,8],[A.P2_A,17,16],[A.VK_P,20,1],[A.VK_SLASH,20,2],[A.VK_X,20,4],[A.VK_MINUS,20,8],[A.VK_COMMA,20,16],[A.VK_EQUALS,20,32],[A.VK_O,21,1],[A.VK_L,21,2],[A.VK_9,21,4],[A.VK_6,21,8],[A.VK_3,21,16],[A.VK_PERIOD,21,32],[A.VK_I,22,1],[A.VK_K,22,2],[A.VK_8,22,4],[A.VK_5,22,8],[A.VK_2,22,16],[A.VK_0,22,32],[A.VK_U,23,1],[A.VK_J,23,2],[A.VK_7,23,4],[A.VK_4,23,8],[A.VK_1,23,16],[A.VK_BACK_SLASH,23,32]]),P0=2,R0=function(d){var f,t,i,o,U,X,W,i0,J;let G=d?320:160,K=d?204:102,s0=G>>2,b0=d?16383:4095,H0=256,v0=4293848814,y0=4278190080,p0=d?3:1,w0=.7;var n0=0,j=new Uint8Array(32),c=0,D=0,m=!1,Y=0,b=0,p=0,V=0,w=0,Q=K,T=new Uint32Array(8),H=new Uint8Array(8),Z=0,v=new Uint8Array(d?262:131),u=new Uint8Array(4),h=0,S=0,l=0,L=0,B=new Uint8Array(8),M=0;function Q0(){return f.scanline=(b&63)?0:4;i0[s--]=T[E+(x&3)],x>>=2}}function a0(e){for(var x=e*G/4,s=0;s>=4);for(var n=0;n<4;n++){var E=x&1?D>>2&3:D&3;s|=E<>=1}x=s,m=!m}if(c&4){if(h&4){var a=2*(~h&3);x=(u[3]>>a&3)<<6|(u[2]>>a&3)<<4|(u[1]>>a&3)<<2|(u[0]>>a&3)<<0}else u[h&3]=x;h++}else{var a=(c&3)<<1,s=x>>a|Y;Y=x<<8-a&255,x=s}if(c&64&&(x=(x&3)<<6|(x&12)<<2|(x&48)>>2|(x&192)>>6),c&48){var F=i[e],r=0;F&192&&x&192&&(r|=1),F&48&&x&48&&(r|=2),F&12&&x&12&&(r|=4),F&3&&x&3&&(r|=8),c&16&&(x|=F),c&32&&(x^=F),S=S&240|r|r<<4}y(e,x)}function _(e,x){H[e&7]=x&255,T[e&7]=F0[x&255],O()}function M0(){var e=b>>6}function O(){Z=K}function V0(){let e=B[0]|B[1]<<8,x=B[2]&63,s=B[3],n=M&255|B[4]<<8,E=B[5],a=B[6]+1,F,r=0,C=0,N0=l;r=0,(x&2)===0&&(r=1);function f0(){r&&(x&4)!==0&&(F!==0||(x&8)===0)&&e++,(x&2)!==0&&(r^=1)}function o0(){F!==0&&((x&32)!==0?n++:n--)}for(;a>=0;){let q;for(F=E;F>=0;){let $,e0;$=(x&1)===0?e:n,F===0&&(x&8)!==0?e0=0:e0=o.read(e),(x&1)===0?f0():o0(),$=(x&1)!==0?e:n,y($,e0),(x&1)===0?o0():f0(),C+=4,F--}q=(n&255)+s&256,n=n&65280|n+s&255,(x&16)===0?n+=q:n-=q^256,a--}l=N0+C}this.drawScanline=e=>{e==V&&p&8&&(t.retryInterrupts=!(p&4),this.probe&&this.probe.logInterrupt(w),t.interrupt(w)),e0?(v[e]=0,a0(e),Z--):v[e]&&(v[e]=0,a0(e))},this.init=(e,x,s,n,E)=>{f=e,n0=e.cpuCyclesPerLine*w0,t=x,i=s,j=n,J=E,d?o={read:N([[16384,32767,16383,function(F){return z(),i[F]}],[53248,57343,4095,function(F){return i[F+16384]}],[0,16383,16383,function(F){return X?X[F]:0}],[32768,49151,16383,function(F){return X?X[F+16384]:0}]]),write:N([[16384,32767,16383,y],[0,16383,16383,d0],[53248,57343,4095,function(F,r){i[F+16384]=r}]])}:(W=x0(new c0().decode(B0(atob(G0))),8192),o={read:N([[0,8191,8191,function(F){return W[F]}],[8192,16383,8191,function(F){return X?X[F]:0}],[16384,20479,4095,function(F){return z(),i[F]}]]),write:N([[16384,20479,4095,y],[0,16383,4095,d0]])}),U={read:function(F){F&=31;var r;switch(F){case 8:r=S,S=0;break;default:r=j[F];break}return r},write:function(F,r){if(F!=42331){if(F&=255,F>120&&F<128){B[F&7]=r,F==114&&(M=0),F==116&&(M=M+B[3]&255),F==126&&V0();return}switch(F&=31,r&=255,F){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:_(F,r);break;case 9:b=r,M0(),O();break;case 10:Q=d?r:r>>1,O();break;case 11:var C=t.saveState();_((C.BC>>8)-1,o.read(C.HL));break;case 12:c=r,Y=0,h=0,m=!1;break;case 13:w=r;break;case 14:p=r;break;case 15:V=d?r:r>>1;break;case 16:case 17:case 18:case 19:case 20:case 21:case 22:case 23:J.setACRegister(F,r);break;case 24:var C=t.saveState();J.setACRegister((C.BC>>8)-1,o.read(C.HL));break;case 25:D=r;break;case 26:case 27:case 28:case 29:case 30:break;default:break}}}},e.connectCPUMemoryBus(o),e.connectCPUIOBus(U),this.membus=o,this.iobus=U;for(var a=0;a<8;a++)_(a,a)},this.resetWaitStates=function(){var e=l;return l=0,e},this.peek=function(e){var x=l,s=o.read(e);return l=x,s},this.loadState=e=>{t.loadState(e.c),i.set(e.ram),T.set(e.palette),H.set(e.palinds),c=e.magicop,D=e.xpand,m=e.xplower,Y=e.shift2,b=e.horcb,p=e.inmod,V=e.inlin,w=e.infbk,Q=e.verbl,h=e.rotcount,u.set(e.rotdata),S=e.intst,L=e.slotphase|0,j.set(e.inputs),B.set(e.patboard),M=e.patdest,O()},this.saveState=()=>({c:t.saveState(),ram:i.slice(0),inputs:j.slice(0),palette:T.slice(0),palinds:H.slice(0),magicop:c,xpand:D,xplower:m,shift2:Y,horcb:b,inmod:p,inlin:V,infbk:w,verbl:Q,rotcount:h,rotdata:u.slice(0),intst:S,slotphase:L,patboard:B.slice(0),patdest:M}),this.reset=()=>{c=D=p=V=w=Y=b=0,Q=K,m=!1},this.toLongString=e=>{var x="";x+=` +import{K as D0,c as l0,d as m0,e as u0,k as h0,r as E0}from"./chunk-4676AC7I.js";import{$ as x0,K as k,W as A,X as C0,Z as X0,aa as N,g,l as c0,m as B0,t as g0}from"./chunk-TYDI7JZQ.js";import"./chunk-KT7KMEQC.js";var I0=X0([[A.UP,16,1],[A.DOWN,16,2],[A.LEFT,16,4],[A.RIGHT,16,8],[A.A,16,16],[A.P2_UP,17,1],[A.P2_DOWN,17,2],[A.P2_LEFT,17,4],[A.P2_RIGHT,17,8],[A.P2_A,17,16],[A.VK_P,20,1],[A.VK_SLASH,20,2],[A.VK_X,20,4],[A.VK_MINUS,20,8],[A.VK_COMMA,20,16],[A.VK_EQUALS,20,32],[A.VK_O,21,1],[A.VK_L,21,2],[A.VK_9,21,4],[A.VK_6,21,8],[A.VK_3,21,16],[A.VK_PERIOD,21,32],[A.VK_I,22,1],[A.VK_K,22,2],[A.VK_8,22,4],[A.VK_5,22,8],[A.VK_2,22,16],[A.VK_0,22,32],[A.VK_U,23,1],[A.VK_J,23,2],[A.VK_7,23,4],[A.VK_4,23,8],[A.VK_1,23,16],[A.VK_BACK_SLASH,23,32]]),P0=2,R0=function(d){var f,t,i,o,U,X,W,i0,J;let G=d?320:160,K=d?204:102,s0=G>>2,b0=d?16383:4095,H0=256,v0=4293848814,y0=4278190080,p0=d?3:1,w0=.7;var n0=0,j=new Uint8Array(32),c=0,D=0,m=!1,Y=0,b=0,p=0,V=0,w=0,Q=K,T=new Uint32Array(8),H=new Uint8Array(8),Z=0,v=new Uint8Array(d?262:131),u=new Uint8Array(4),h=0,S=0,l=0,L=0,B=new Uint8Array(8),M=0;function Q0(){return f.scanline=(b&63)?0:4;i0[s--]=T[E+(x&3)],x>>=2}}function a0(e){for(var x=e*G/4,s=0;s>=4);for(var n=0;n<4;n++){var E=x&1?D>>2&3:D&3;s|=E<>=1}x=s,m=!m}if(c&4){if(h&4){var a=2*(~h&3);x=(u[3]>>a&3)<<6|(u[2]>>a&3)<<4|(u[1]>>a&3)<<2|(u[0]>>a&3)<<0}else u[h&3]=x;h++}else{var a=(c&3)<<1,s=x>>a|Y;Y=x<<8-a&255,x=s}if(c&64&&(x=(x&3)<<6|(x&12)<<2|(x&48)>>2|(x&192)>>6),c&48){var F=i[e],r=0;F&192&&x&192&&(r|=1),F&48&&x&48&&(r|=2),F&12&&x&12&&(r|=4),F&3&&x&3&&(r|=8),c&16&&(x|=F),c&32&&(x^=F),S=S&240|r|r<<4}y(e,x)}function _(e,x){H[e&7]=x&255,T[e&7]=F0[x&255],O()}function M0(){var e=b>>6}function O(){Z=K}function V0(){let e=B[0]|B[1]<<8,x=B[2]&63,s=B[3],n=M&255|B[4]<<8,E=B[5],a=B[6]+1,F,r=0,C=0,N0=l;r=0,(x&2)===0&&(r=1);function f0(){r&&(x&4)!==0&&(F!==0||(x&8)===0)&&e++,(x&2)!==0&&(r^=1)}function o0(){F!==0&&((x&32)!==0?n++:n--)}for(;a>=0;){let q;for(F=E;F>=0;){let $,e0;$=(x&1)===0?e:n,F===0&&(x&8)!==0?e0=0:e0=o.read(e),(x&1)===0?f0():o0(),$=(x&1)!==0?e:n,y($,e0),(x&1)===0?o0():f0(),C+=4,F--}q=(n&255)+s&256,n=n&65280|n+s&255,(x&16)===0?n+=q:n-=q^256,a--}l=N0+C}this.drawScanline=e=>{e==V&&p&8&&(t.retryInterrupts=!(p&4),this.probe&&this.probe.logInterrupt(w),t.interrupt(w)),e0?(v[e]=0,a0(e),Z--):v[e]&&(v[e]=0,a0(e))},this.init=(e,x,s,n,E)=>{f=e,n0=e.cpuCyclesPerLine*w0,t=x,i=s,j=n,J=E,d?o={read:N([[16384,32767,16383,function(F){return z(),i[F]}],[53248,57343,4095,function(F){return i[F+16384]}],[0,16383,16383,function(F){return X?X[F]:0}],[32768,49151,16383,function(F){return X?X[F+16384]:0}]]),write:N([[16384,32767,16383,y],[0,16383,16383,d0],[53248,57343,4095,function(F,r){i[F+16384]=r}]])}:(W=x0(new c0().decode(B0(atob(G0))),8192),o={read:N([[0,8191,8191,function(F){return W[F]}],[8192,16383,8191,function(F){return X?X[F]:0}],[16384,20479,4095,function(F){return z(),i[F]}]]),write:N([[16384,20479,4095,y],[0,16383,4095,d0]])}),U={read:function(F){F&=31;var r;switch(F){case 8:r=S,S=0;break;default:r=j[F];break}return r},write:function(F,r){if(F!=42331){if(F&=255,F>120&&F<128){B[F&7]=r,F==114&&(M=0),F==116&&(M=M+B[3]&255),F==126&&V0();return}switch(F&=31,r&=255,F){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:_(F,r);break;case 9:b=r,M0(),O();break;case 10:Q=d?r:r>>1,O();break;case 11:var C=t.saveState();_((C.BC>>8)-1,o.read(C.HL));break;case 12:c=r,Y=0,h=0,m=!1;break;case 13:w=r;break;case 14:p=r;break;case 15:V=d?r:r>>1;break;case 16:case 17:case 18:case 19:case 20:case 21:case 22:case 23:J.setACRegister(F,r);break;case 24:var C=t.saveState();J.setACRegister((C.BC>>8)-1,o.read(C.HL));break;case 25:D=r;break;case 26:case 27:case 28:case 29:case 30:break;default:break}}}},e.connectCPUMemoryBus(o),e.connectCPUIOBus(U),this.membus=o,this.iobus=U;for(var a=0;a<8;a++)_(a,a)},this.resetWaitStates=function(){var e=l;return l=0,e},this.peek=function(e){var x=l,s=o.read(e);return l=x,s},this.loadState=e=>{t.loadState(e.c),i.set(e.ram),T.set(e.palette),H.set(e.palinds),c=e.magicop,D=e.xpand,m=e.xplower,Y=e.shift2,b=e.horcb,p=e.inmod,V=e.inlin,w=e.infbk,Q=e.verbl,h=e.rotcount,u.set(e.rotdata),S=e.intst,L=e.slotphase|0,j.set(e.inputs),B.set(e.patboard),M=e.patdest,O()},this.saveState=()=>({c:t.saveState(),ram:i.slice(0),inputs:j.slice(0),palette:T.slice(0),palinds:H.slice(0),magicop:c,xpand:D,xplower:m,shift2:Y,horcb:b,inmod:p,inlin:V,infbk:w,verbl:Q,rotcount:h,rotdata:u.slice(0),intst:S,slotphase:L,patboard:B.slice(0),patdest:M}),this.reset=()=>{c=D=p=V=w=Y=b=0,Q=K,m=!1},this.toLongString=e=>{var x="";x+=` INLIN: `+e.inlin,x+=` VERBL: `+e.verbl,x+=` MAGICOP: $`+g(e.magicop),x+=` @@ -11,4 +11,4 @@ XPLOWER: `+e.xplower,x+=` INTST: $`+g(e.intst),x+=` Palette: `;for(var s=0;s<8;s++)x+=g(H[s]);return x+=` `,x},this.connectVideo=function(e){i0=e},this.loadROM=function(e){X=e},this.loadBIOS=function(e){W=e},this.getVisiblePixelWords=function(){return Q*G}},P=class extends E0{constructor(t){super();this.cpuFrequency=1789e3;this.arcade=t,this.cpu=new l0,this.psg=new t0(new m0),this.numTotalScanlines=t?262:131;var i=P0*(t?1:2);this.sampleRate=60*this.numTotalScanlines*i,this.audioadapter=new h0(this.psg.psg,i,this.sampleRate),this.handler=C0(this.inputs,I0),this.defaultROMSize=t?45056:8192,this.ram=new Uint8Array(t?20480:4096),this.numVisibleScanlines=t?204:102,this.canvasWidth=t?320:160,this.cpuCyclesPerLine=this.cpuFrequency/(60*this.numVisibleScanlines*1.286)|0,this.m=new R0(t),this.m.init(this,this.cpu,this.ram,this.inputs,this.psg),t&&(this.inputs[16]=255,this.inputs[17]=255,this.inputs[18]=0,this.inputs[19]=8)}read(t){return this.m.peek(t)}write(t,i){this.m.membus.write(t,i)}connectVideo(t){super.connectVideo(t),this.frontbuffer=t,this.backbuffer=new Uint32Array(t.length),this.m.connectVideo(this.backbuffer)}preFrame(){this.m.resetWaitStates()}postFrame(){var t=this.m.getVisiblePixelWords();this.frontbuffer.set(this.backbuffer.slice(0,t),0),this.frontbuffer.fill(0,t)}setPaddleInput(t,i){switch(t){case 0:this.inputs[28]=i&255;break;case 1:this.inputs[29]=i&255;break}}startScanline(){this.audio&&this.audioadapter.generate(this.audio)}drawScanline(){var t=this.scanline;this.m.drawScanline(t)}advanceCPU(){var t=super.advanceCPU(),i=this.m.resetWaitStates();return i&&(t+=i,this.probe.logClocks(i)),t}loadROM(t){super.loadROM(t),this.m.loadROM(this.rom),this.reset()}loadBIOS(t){this.m.loadBIOS(x0(t,8192)),this.reset()}reset(){super.reset(),this.m.reset()}loadState(t){this.m.loadState(t)}saveState(){return this.m.saveState()}getDebugCategories(){return["CPU","Stack","Astro"]}getDebugInfo(t,i){switch(t){case"Astro":return this.m.toLongString(i)}}getRasterCanvasPosition(){return{x:this.getRasterX(),y:this.getRasterY()}}getVideoParams(){return this.arcade?{width:320,height:204,rotate:180}:{width:160,height:102}}},t0=class extends u0{setACRegister(f,t){switch(f&=7,t&=255,f){case 0:this.psg.setClock(1789e3*16/(t+1)),this.psg.writeRegisterAY(7,248);break;case 1:case 2:case 3:var i=(f-1)*2,o=t*2+1;this.psg.writeRegisterAY(i,o&255),this.psg.writeRegisterAY(i+1,o>>8&255);break;case 5:this.psg.writeRegisterAY(10,t&15);break;case 6:this.psg.writeRegisterAY(8,t&15),this.psg.writeRegisterAY(9,t>>4&15);break}}},F0=[0,2368548,4737096,7171437,9539985,11974326,14342874,16777215,2425019,4784352,7213567,9582079,12016383,14384895,16753663,16762879,4784304,7143637,9568761,11937279,14306047,16740095,16749311,16758783,6946975,9306307,11731175,14096639,16465151,16736767,16745983,16755199,8847495,11206827,13631696,15994612,16724735,16733951,16743423,16752639,10420330,12779662,15138995,16713687,16723195,16732415,16741631,16751103,11534409,13959277,16318610,16713142,16722394,16731647,16741119,16750335,12255269,14680137,16711790,16713362,16722615,16732123,16741375,16750847,12517376,14876708,16711752,16714605,16724113,16733366,16742874,16752127,12255232,14680064,16711715,16716871,16726380,16735632,16745141,16754393,11534336,13959168,16318464,16720164,16729416,16738924,16748177,16757685,10420224,12779520,15141888,16723971,16733479,16742731,16752240,16761492,8847360,11206656,13639168,16007680,16738058,16747310,16756563,16766071,6946816,9309440,11743488,14112256,16480768,16752151,16761659,16770911,4784128,7151872,9585920,11954688,14323200,16757509,16766761,16776270,2429184,4797696,7232e3,9600512,12034816,14403328,16771870,16777027,9472,2377984,4746496,7180800,9549312,11983616,14352155,16777023,14080,23296,2326528,4695040,7129344,9497856,11927326,14286659,18176,27648,36864,2405376,4774144,7142661,9568041,11927374,21760,30976,40192,246272,2614784,4980503,7405371,9764703,24320,33536,43008,52224,716810,3079982,5504851,7864183,25856,35328,44544,53763,63271,1572683,3932016,6291348,26624,35840,45312,54564,63816,393068,2752401,5177269,26112,35584,44835,54343,63596,65424,2031541,4456409,24832,34084,43592,52845,62353,65462,1834970,4194302,22565,31817,41326,50578,60087,65499,2031615,4456447,19273,28781,38034,47542,56794,393215,2752511,5177343,15466,24718,34227,43479,52987,1569535,3932159,6291455,10887,20395,29648,38900,703743,3072255,5505023,7864319,6047,15299,24807,230655,2599167,4967935,7401983,9764863,688,10197,19449,2388223,4756735,7125503,9559551,11927551,187,5088,2308095,4676607,7110911,9479423,11913727,14282239];for(I=0;I<256;I++)Y0=F0[I],F0[I]=g0(Y0)|4278190080;var Y0,I;var G0="TFpHAAAgAAAAFHUyA4UHAUpdY2XzIQAgfv5Vyg0AwwAgMc5PzR4JIQUgfiNmb+kAZRrl9cXV3eX95SEAADnlzc4H4f3h3eHRwfHhyUztacnd5d1jEd053X4Gyw8mAN1+BN2OBSdvyxTd4ckBCwjts8kAQ15cJVJTOy83ODkqNDU2LTEyMysmMC49XRtuZR9lH2UeZQjD4ALD4QIgCAgBB2IToAQGAQU+FT9lAfv1xdXl/eUB1U8KPAIB1mWj12Wj2GWi/SHrT/00AP1+ANY8ICL9NgAAIexPNP0h40/9ywD+/SHtXQgWBCHuTzQ61E+3KBL9IepPYw23KAX9NQAYA82VCf3hXUIt7U1dRikOXUIktyhG3csERig5EdVPaSYAGX63KC4+1YFfPk/OAFch1U8GAAl+3YYFErcgF0H1HgHxBBgCyyMQ/P0h+l0CVrP9dwBjNz4MGLTd4cllASEP/+XNhwLxycnB4eXFEQYAGUY+//UzxTNjjV0GcvXdTgTdRgUhDAAJ4+HlXiNWGm8+ApUwCcXFzc4H8cEY6xNL4eVxI3Ld+V0CTl0DQgoAGU4jZmnDqhxdEj1pYGNZXiNW4eVzI3JdBEvWCChdB0ntXQRCXWgkXgTdVmNzGU1E610FM3sCA3oCYx5dB1j1XQge3XX+3XT/3W7+3Wb/TiNG3csGbigi1f3h/SP9IwpvAzMzxf11AF0FCP0j4eVuwcUDYwpjIE4oC/0hBAD9GQoDXSMkBlZjSQVdCQleY0kGXQkJZmNJB10JCXZjSQldCQl+KB79IQpjSV0GdP0hC2MH4eVeXQJxcwBdBKJxI3BdA/DRwcXVxf3h/VYH1TPFzaYD8TPJAaYEeO1H7V77PsjTDz6m0w0+CNMOzeICw+MCGAJjaGlgEQUAGX7TCmMBB2NBCWMBCWNBDl0siXIAXSdNXSOIYx8EXSNI1f3hYwQGY4RpYAEJAAlu/eXBJgDV5cXNqxwhBgA5XQKUIetPTjrrT5Eo+l0olV0k0AcACV5TFXJ7tygHxc0UBV0ivV0olV0kk2tiAQQACU4jRl0ic24K/WYL5f3h610FbNX95cXN1l0HYV0nzztdFjRdJN1jR34H3Xf9HgDdVv3dNf16tyglXSRIVt00/iAD3TT/CmfFe/Uz5TPVM81WAPEzwVx9AgMY0V0jZF0HX/0h70/9RgD9XgH9VgIOAPE+BcsgyxPLEj0g9/1+AKn9dwD9fgGo/XcB/X4Cq/13Av1+A6r9dwP1/U4C/UYDEQAA8cs4yxldGyP9TgD9RgH9XgL9VgNdAlghyxBdBFr1XRovXSVXCQAJTUQKtyAGYyQCGBtfFgAhAADF5dUq8U/lKu9P5c0lHfFlAcF9XWoMY/RdQ3QJ/V4A/VYBXQVAbyYAGV1Cf3QBfl0bKAFpYMVdQgPBbiYAKV0FKgNlAV1xeF0loF0jiAbdd/9rYgEKXSOp3W7/yz0mYwMhCQAZ3cv/RigJeQdlAeYPGAN55g93M11PIGNhTURdAkJeByF4ABYAGV0Dnl1F4GMVfjLUT12EPH79Ic5P/XcAI379dwFpYCNl4SHQXQcJIepPNgDJIdRlol1JSX4E3Xf+3X4F3Xf/3X7+xgxv3X7/zgBn5U4jRuFZUBNzI3IK3Xf9T8s53cv9figbKvtdok9eBgBdIqr9Kv1P/Qn9bgD9ZgEYFQYAaWApCRFeCBlNRCMjXmlgfiNmb2MuRigR5Xv1M91O/t1G/11kvOFdBgWqHF1DcgEDADYDADcDgEYDgIADAIIDgHgEEIsEAO0CCJAH4MgHAKgEVMgEgNcEXqsPXoEDoC8cxvAbxj0Z3oEDZUEmgQOWgQOegQOGZaG8F06bF47mF2MHRmVDqGMoawcAaAsGPw6AyQ6AgQMAY6KYYyUfBRCBAw6BA4AmB4hloeoGwLoGwEMFYzQAfQWWY6JlVOQFQGOBwF0DQ44h8v85+SHOTwYZr3cjdyMQ+SEAAOXNiwTxPsDTCj4p0wldgptKBAD7aAvxIQ4AOfnJKs5PTl0jqTQAIAP9NAFpyV0jpl0FBipjAyECAP05/X4Ad8ljBk5lYSsi0E9pye1L0E8Kxv8Cb11IZ81SCd11/33WgNJRCt1+/zLqTyHUT07LQSgIxWMTwX3TF8tJXQcEFMtRKA4qzk9+0xO3KAU600/TFctZKAxdCoTLYSgNY5oStyAEee4QT8tpXQ0ZcV0FGRFjmUBPy3ldDxkIOtJP5g9HGAIGAMthKAdjRvAYAj4AsNMWw2QL3X7/1ogwH10Csn7/BgDGkE94zv9BDgAmAH2xb3ywZ81SAF0GHiAnT3nWCNJkC10DuVkGAD4Xk18+AJhXYySzb3yyZ2MQAMEMGNpjJubwT9aQKB15/qAoJf6wKDD+wChC/tAoYv7gKHHW8MpXC8NkC2M+/SHUT/11XQVaxmFHxTPNZAkzXQYU0mNUY4LTY0IYZs2LCX23KAxdIqsjRu1Dzk8YUyHOT37GAncjfs4Ad81+CRhCXQJ1D09jT4FjzhgvYwvW4SAo0xU+ANMWYzV+MupPXSYdEv00ARgNYxFjlV1jj11q9SHr/zn53TbwAN0272Vh8l2C2jnddfnddPrdbvndZvrbEHfdfvnGAd139d1++s4A3Xf23W713Wb22xFjkQLdd/ddBRH43W733Wb42xJjkQPdd/NdBRH03W7z3Wb02xN33TbxAGMV3Ybxb2OUZ37dd/vdfvHG5N13/D4Azk/dd/3dbvzdZv3dfvuWKDpjE4fGFd138F0THH7drvvLZygD3TRjGF0MTe/dNPFjLNYEOJAR5E9dBMMBBADtsGPD2xR3XQW+FWMBXQOuFmMBXQOeF3ddg6X8XYOl/d1+/F2Dsf3dd/8OXQK0gV9dA11XGke3KC1dxO0jZQF+I2aBb3xdAnWgErcoFEEEGm+3KAoEZQF9yz8SGPHdcPIMedYEOL3dfvK3KB5KAwKTfgDdlvIoEmMK/XcAZaFdAq828BMYKWNcICNdBRy3KBn9ywB+KAZjFBEYBGWhEl0ipWMVNgBdBcYcXQbGHV0Gxh5dBsYfdw5dBR4GAAlGEd9KAwK6XniTKAl5xhxdIlFw710DkNtdIjpdAuH63Xf/Yx9dBNJdIyv9Id5dBIAzZaHdd+8GB93L734oHnjGCWM59Q5KBALqIRD8XQUhXeJPGGNcJgUY1UoFAv5dHDVj4V0LNd1+8NYSOAUh7E82/91+/MYJT91+/c4AR2MQAmNIB10HCO8CSgsAUyH5XULPXeS+CgAJSgoClF4jVjMzXcbM3Xf70dUab911/X3WwDBG3X795j9dI/P73Zb8IC7h5SNjJ2PwcyNyY1fAKAr+QCgG1oAoCRgWxc03A/EYD8XNRmXBCBMTEzMz1RiwXQuCSggAQ+vFXeKfBxLFzT8O8UoMAz1+BA8PXQRxTgXLOcs53V4GFgBrYikpGSkpKREAQBndXvwWSgcDW34E5gNfIacPYwpG3X78kSAEPgEYAa/dd/23XUJFBV0HFn4vX3ijR10F73gvV3uiX3jdpgezY8p33X79tyAw3V7+3Vb/E91G/AR4kTAH3X4HEhMY9BpPXQNBxqdvPg/OAGdGeaBPeC9jNLESXQPW/z8PA10nZF3CjV0F3wVdImT43XT53W743Wb5fl2CFXH+3XD/3XH83XD93XH63XD73XH13XD2XQca9N138t028wBdRLsRBwAZTgYA4eUJ3X73BgCVeJziGBDugPJVEF0Erl0ir05dZPcRBF0C+W763Wb7SgMCyHiDV3n1M2Mv9TPVM8UzzesO8fHdNPcYlV1ME9ddAqddYtrsXWPa7d1u7N1m7REFABlOI0ZdI3Jjym4mAHuVX3qcV91+7MZKBAC27V2Cxl1FQGMXxeXVzZAc8fHBCd115d105gEAAN1eCF0osgndTgddIsdZXSO08N108d1+B+YDy99P3X4J5jCx3XfkY0HAY4cPR3m3ygQTIQVdonj03XT13X70xgBf3X71zsDdc9rdd9tjHgdjN/XdNtkB8TwYBN3L2SY9IPljYAFdQ631XQKX/WMf5oDdd+djEN13+mMOXaNbYwT4Y4RjKPxdor1dgsr3edbAXUc2791w7t1+5d136t1+5t1369022EoFBR3dftiW0kQTPgjTDD4M0xndftpdAmno3X7bXQJp6d1u6t1m607dNOogA900691u2t1m23HdbujdZulx3X7ntyhF3W703Wb1ft1312N1A10i6mP1891O2t1G2wMDXaXKAt1u8t1m83dj/d1+12MCXQJAY4J+77fKohJdDERdYvvbXWP72sYGX2OEV11EDF2ijRICY1AFXQkcBF0HHF1Cd2PbXQV7A91e2t1W2xMT3W723Wb3Y1JdE37u0xkOAHndltkwT91+5NMMHgB7Y0UjXQSRXWOObvDdZvFwZcQjcCNdJPUcGNfdbtkmACk+KJVfPgBdQlHwg13E1Irdd/EMGKvdNNjDjxF40xndTuXdRuYeXSV4VnuSMCoKVwNdA2ZdBE1yZcQjciM2ACN9xiVjP3xdIkjxHBjLXUS3I25dRShH9V2jWyUQ/F1jAEoFCWEgZQFloVBQY4ZI/EhIZWEgeIBwCPAgAEgQIECQAGCQYKCokGhgYGMhYyNAZQIgQGNxIEAAqHD4cKhjf/hdAkBlAWBjDQAA8F0FVwBgYAAIYz6AAHCIiKiIiHAgYGNwcHCICDBAgPhlwXAIiHAQMFCQ+BAQ+ICAY0ZwiIDwYyL4iBBjo2MDZUFlYXhjFAAAYGUhZQFlwSBAXQJRQCAQAAD4ZSEAYwJdAmNwCAgwIABjMLiokIBjcPiIiIjwZURwiICAgIhwYwNjTPiAgPCAgPhlxIBjFLBdA2RjqXBdA9hwCGUBY02QoMCgkGN1ZQH4iNioY7nIqKiYY+ZloV0CV2O+iKiokGhjRpCQYzFdA8r4XQNFIGOhXQNaiIhQY4ao2GODUGPKZQH4XSMl+HBdI11wAF0C1ggAcBBlAnAgcKhdJKVA+EBlwiAgqHAgACAQ+BBjBmO+Yw0A+GVhZQNAQABAAKCgYwJg8PBgAEDg4EAAkF0iyMCw4NBjPV0kxCAAQF0iv0DgQGMiZaFdJLsAAOBj/ABjFUAA4KCgoODAQEBjPCDggGWBYCBjC+AgY0Ug4GWBoGMMY1egY0JjEeBjMkBjd2AgACBdAqXgZSEAQCBAAGM0AEDwkBDQ8GBjJQDAYyYAYICA4ADAoKDAAODAYwJlgYBjDGMRoGNb4EBAYxsgY0fAwKAAgGNl4OBjUaCgZYNjB6DggGWC8GWBYxvggGBjDEBAXQL3Y77AgACgYysAoEBjKqBjEgDgIF0CTUBAYABAQCAgAGAgXQKPXSIkZQLwgF0E/2M0XQLTYwKA4EoHCbNd459KEwIP3V4G3VYHGkcTeLcgE2MRxgRKBwCPCALDWxd41iAwJCEGAk1E1d1mCt1uCeXdVggeINXFzVoQ8fHx0WMfhd13CBi9eNZkMCNdBxx+CPUzxTNjMOVdDSCVeNaAOJBKBgJzfiNmb+X94V0NL/1dDS3DuhZKEQCPxf3h/V4GaWAjZQFWY0VmBUoFCa3dbgbdZgflxc2SFiEHSgwKFkoHCrxKBAwM1cXNYBfxSgsAyWWhOetdCFp+CRJrYiM2AGOiXeyESgMAM10iT/tdI0/83W773Wb8XeLRfl3ComPGBWOG+l0FBgZjhvhdBQYHY4b35j9dw8v35kDdd/+3KAshDQLddf3ddP4YCSEGXQUDXSOl9N1+/koDBMNjHgQegBgCHgDdc/NjcoBdwo1dBE1KAwuwRt1e9hYAe8b/3Xf9es5lof7dbv3dZv7dy/5+KAJrYsssyx0JXQVSXvZLHXm3KGhj2n7LQygJSgQJZk8YEGWBY88rY+V5tyAKSgMD/AQOEBgESgMFaysZBgAJTnndhvNH1d1m+N1u+uXdfvldIr9dxEtdKMT5hd13+RiSXSM9MDEyMzQ1Njc4OSorLC0uLyBdR6Mh510iT0oLChPoSgYLrOljQU4Ea2JdIuxKBQvSCXnmA7Xdd+dKBg3fXSIKcvRYSgoCewAZ3XXu3XTv3X7nXSJc+3lKBAKp8N1++7coBz4n3ZbwGAPdfvDdd+1jWwhjk+5dYyfvXWInNusA3X7r3Zbp0usbYxnTDN1+7V0igDb2YxDwt8r5Gt1+80oDBkNKAwChNuwA3W7oJgAp3X7sXSJyNv9jH/6V3X7/nOInGu6A8l8bSgQE4X7dd+rdNPcgA900+F0DhFzdfvXdlv7dd/Hdfvbdnv9dIs5+/N2G8V1CSH793Y7yXUND+d1m+t1+6nfdfvFdItpjE/JdItxjDGMk+V0GJPpdCyQYUl0CVIb+Y5b23Y5dCijxXQYo8t1u8d1m8mNo3TT5XQKQXRtM3TTsZUHDChpKAwBK6DBt3XH53Tb6AN1e891W9BNKBAW9Rl0D0iFdA9L5b10D0Ppn3X78hWME/YxnXSSncBgfY1mGY9mO+md93Yb8b3zdjv1dBhkMGJzdfvdKAweP+F1iAk7sXQZlXQJXLl0EV10mMV0Dw10lMV0E1fJdB9U2ABgsXQRkXSYDXQPNXRXfNgBjEsYoXUME/UoEApo068PbGV2LAkoGEKIKSgYQ50oDD+gJGm8TSgMPsgddBwRKAxC2xc09XQ03O0oXBeVKAxBTCUoDBnX9Yzvdfv2V/XcASgMQWF0PDkoHBeLFzfAbXQNZ8cHR1cX1r2+wBhAgBAYIeSnLERcwARkQ98npSgwNON1OCN1GCWlgC3y1KAfdfgYSExjy3W4E3WYFSg4F413IPGPxXWKX/t1dYpT/XQo9E10EhX5KBg9JEhMY5uHlXQvuAWWBfgsHOEDdywgm3csJFt3LCmVhCxZdAl6WCF0CXp4JXQJYngpdAlieCzASYxY+Yx4eYyZlYQgeGAQESBi6XRYoOCRdBRJ3BF0FFXddA6hjGHcGY9vddwddDkxBDXi3IKxdBfVd4xRKCAJvZR9lH2UfZR9lG2UB";var K0=[{id:"01-helloworlds.asm",name:"Hello World (ASM)"},{id:"02-telephone.asm",name:"Telephone (ASM)"},{id:"03-horcbpal.asm",name:"Paddle Demo (ASM)"},{id:"hello.c",name:"Hello Graphics"},{id:"lines.c",name:"Lines"},{id:"sprites.c",name:"Sprites"},{id:"vsync.c",name:"Sprites w/ VSYNC"},{id:"fastsprites.c",name:"Fast Sprites"},{id:"music.c",name:"Music"},{id:"rotate.c",name:"Rotate Op"},{id:"rainbow.c",name:"Rainbow"},{id:"cosmic.c",name:"Cosmic Impalas Game"},{id:"racing.c",name:"Pseudo 3-D Racing Game"}],j0=[{id:"bios.c",name:"BIOS"}],T0=[{id:"hello.c",name:"Hello Graphics"}],R=class extends D0{constructor(){super(...arguments);this.getMemoryMap=function(){return{main:[{name:"BIOS",start:0,size:8192,type:"rom"},{name:"Screen RAM",start:16384,size:4096,type:"ram"},{name:"BIOS Variables",start:20430,size:50,type:"ram"}]}}}newMachine(){return new P(!1)}getPresets(){return K0}readAddress(t){return this.machine.read(t)}showHelp(){return"https://8bitworkshop.com/docs/platforms/astrocade/"}},A0=class extends R{getPresets(){return j0}loadROM(f,t){this.machine.loadBIOS(t)}},r0=class extends R{constructor(){super(...arguments);this.getMemoryMap=function(){return{main:[{name:"ROM",start:0,size:16384,type:"rom"},{name:"Magic RAM",start:0,size:16384,type:"ram"},{name:"Screen RAM",start:16384,size:16384,type:"ram"},{name:"ROM",start:32768,size:16384,type:"rom"}]}}}newMachine(){return new P(!0)}getPresets(){return T0}};k.astrocade=R;k["astrocade-bios"]=A0;k["astrocade-arcade"]=r0; -//# sourceMappingURL=astrocade-K3HTJCX2.js.map +//# sourceMappingURL=astrocade-JYCWWO6Z.js.map diff --git a/gen/astrocade-K3HTJCX2.js.map b/gen/astrocade-JYCWWO6Z.js.map similarity index 100% rename from gen/astrocade-K3HTJCX2.js.map rename to gen/astrocade-JYCWWO6Z.js.map diff --git a/gen/atari7800-4C6PMPB3.js b/gen/atari7800-N44NNLWK.js similarity index 99% rename from gen/atari7800-4C6PMPB3.js rename to gen/atari7800-N44NNLWK.js index d5944549..7f7973f5 100644 --- a/gen/atari7800-4C6PMPB3.js +++ b/gen/atari7800-N44NNLWK.js @@ -1,7 +1,7 @@ -import{a as j}from"./chunk-DYRHT6BM.js";import{J as $,h as H,k as z,m as Y,q as K,x as V}from"./chunk-G4HBIXG4.js";import{$ as N,K as O,V as R,W as o,X as E,Z as W,aa as _,g as S}from"./chunk-TYDI7JZQ.js";import"./chunk-KT7KMEQC.js";var b=0,U=2,v=8,Z=W([[o.A,v+0,128],[o.B,v+1,128],[o.GP_A,v+0,128],[o.GP_B,v+1,128],[o.SELECT,U,-2],[o.START,U,-1],[o.UP,b,-16],[o.DOWN,b,-32],[o.LEFT,b,-64],[o.RIGHT,b,-128],[o.P2_A,v+2,128],[o.P2_B,v+3,128],[o.P2_UP,b,-1],[o.P2_DOWN,b,-2],[o.P2_LEFT,b,-4],[o.P2_RIGHT,b,-8]]);var M=263,G=242,C=451,tt=28,et=16,rt=24,q=2,X=M*60*q,I=class{constructor(){this.regs=new Uint8Array(32)}reset(){this.regs.fill(0)}read(r){return this.regs[r]|0}write(r,t){this.regs[r]=t}saveState(){return{regs:this.regs.slice(0)}}loadState(r){for(let t=0;t<32;t++)this.write(t,r.regs[t])}static stateToLongString(r){let t="";return t+=R(r.regs,0,32),t}},L=class{constructor(){this.cycles=0;this.regs=new Uint8Array(32);this.offset=-1;this.dll=0;this.dlstart=0;this.dli=!1;this.h16=!1;this.h8=!1;this.writemode=0;this.indirect=!1;this.pixels=new Uint8Array(320);this.WSYNC=0}reset(){this.regs.fill(0)}read(r){return this.regs[r]|0}write(r,t){this.regs[r]=t,r==4&&this.WSYNC++}saveState(){return{regs:this.regs.slice(0),offset:this.offset,dll:this.dll,dlstart:this.dlstart,dli:this.dli,h16:this.h16,h8:this.h8,indirect:this.indirect,writemode:this.writemode}}loadState(r){for(let t=0;t<32;t++)this.write(t,r.regs[t]|0);this.offset=r.offset|0,this.dll=r.dll|0,this.dlstart=r.dlstart|0,this.dli=!!r.dli,this.h16=!!r.h16,this.h8=!!r.h8,this.indirect=!!r.indirect,this.writemode=r.writemode|0}isDMAEnabled(){return(this.regs[28]&96)==64}getDLLStart(){return(this.regs[12]<<8)+this.regs[16]}getCharBaseAddress(){return(this.regs[20]<<8)+this.offset}setVBLANK(r){r?(this.regs[8]|=128,this.offset=-1,this.dll=this.getDLLStart(),this.dli=this.bus&&(this.bus.read(this.dll)&128)!=0):this.regs[8]&=-129}readDLLEntry(r){if(this.dll>=16384)return;let t=r.read(this.dll);this.offset=t&15,this.h16=(t&64)!=0,this.h8=(t&32)!=0,this.dlstart=(r.read(this.dll+1)<<8)+r.read(this.dll+2),this.dll=this.dll+3&65535,this.dli=(r.read(this.dll)&128)!=0}isHoley(r){return this.indirect?!1:!!(r&32768&&(this.h16&&r&4096||this.h8&&r&2048))}readDMA(r){return this.isHoley(r)?0:(this.cycles+=3,this.bus.read(r))}doDMA(r){this.bus=r,this.cycles=0;let t=this.pixels;if(t.fill(this.regs[0]),this.isDMAEnabled()){this.cycles+=this.offset==0?rt:et,this.offset<0&&this.readDLLEntry(r);let u=this.dlstart&65280,c=this.dlstart&255;do{let x=r.read(u+(c+0&511)),d=r.read(u+(c+1&511));if(d==0||u>=16384)break;let l=r.read(u+(c+2&511)),p=r.read(u+(c+3&511)),g=!1;if((d&31)==0){var e=p>>5,n=32-(p&31),i=r.read(u+(c+4&511));g=(d&32)!=0,c+=5,this.cycles+=10,this.writemode=d&128}else{var i=p,e=d>>5,n=32-(d&31);c+=4,this.cycles+=8}this.indirect=g;let y=x+((l+(g?0:this.offset)&255)<<8);i*=2;let m=this.regs[28],k=(m&3)+(this.writemode?4:0),A=(m&4)!=0,w=g&&(m&16)!=0;w&&(n*=2);for(var s=0;s>1):y+s);if(g){let P=(this.regs[20]+this.offset<<8)+h;w&&s&1&&(P++,this.cycles-=3),h=this.readDMA(P)}switch(k){case 0:for(let a=0;a<4;a++){let f=h>>6&3;(f||A)&&(t[i]=t[i+1]=this.regs[(e<<2)+f]),h<<=2,i=i+2&511}break;case 3:for(let a=0;a<8;a++){let f=(h&128)>>6;(f||A)&&(t[i]=this.regs[(e<<2)+f]),h<<=1,i=i+1&511}break;case 4:for(let a=0;a<2;a++){let f=(h>>6&3)+(h&12);(f&3||A)&&(t[i]=t[i+1]=t[i+2]=t[i+3]=this.regs[((e&4)<<2)+f]),h<<=2,i=i+2&511}break;case 6:for(let a=0;a<4;a++){let f=(h&128)>>6|(h&8)>>3;(f||A)&&(t[i]=this.regs[(e<<2)+f]),h<<=1,i=i+1&511}break;case 2:for(let a=0;a<8;a++){let f=(h&128)>>6;f+=a&1?e&1:e>>1&1,(f||A)&&(t[i]=this.regs[(e<<2)+f]),h<<=1,i=i+1&511}break;case 7:let P=h;for(let a=0;a<4;a++){a==2&&(P<<=2);let f=(h&128)>>6,Q=e&4|P>>2&3;(f||A)&&(t[i]=this.regs[(Q<<2)+f]),h<<=1,i=i+1&511}break}}}while(this.cycles=16384)return;let t=r.read(this.dll);this.offset=t&15,this.h16=(t&64)!=0,this.h8=(t&32)!=0,this.dlstart=(r.read(this.dll+1)<<8)+r.read(this.dll+2),this.dll=this.dll+3&65535,this.dli=(r.read(this.dll)&128)!=0}isHoley(r){return this.indirect?!1:!!(r&32768&&(this.h16&&r&4096||this.h8&&r&2048))}readDMA(r){return this.isHoley(r)?0:(this.cycles+=3,this.bus.read(r))}doDMA(r){this.bus=r,this.cycles=0;let t=this.pixels;if(t.fill(this.regs[0]),this.isDMAEnabled()){this.cycles+=this.offset==0?rt:et,this.offset<0&&this.readDLLEntry(r);let u=this.dlstart&65280,c=this.dlstart&255;do{let x=r.read(u+(c+0&511)),d=r.read(u+(c+1&511));if(d==0||u>=16384)break;let l=r.read(u+(c+2&511)),p=r.read(u+(c+3&511)),g=!1;if((d&31)==0){var e=p>>5,n=32-(p&31),i=r.read(u+(c+4&511));g=(d&32)!=0,c+=5,this.cycles+=10,this.writemode=d&128}else{var i=p,e=d>>5,n=32-(d&31);c+=4,this.cycles+=8}this.indirect=g;let y=x+((l+(g?0:this.offset)&255)<<8);i*=2;let m=this.regs[28],k=(m&3)+(this.writemode?4:0),A=(m&4)!=0,w=g&&(m&16)!=0;w&&(n*=2);for(var s=0;s>1):y+s);if(g){let P=(this.regs[20]+this.offset<<8)+h;w&&s&1&&(P++,this.cycles-=3),h=this.readDMA(P)}switch(k){case 0:for(let a=0;a<4;a++){let f=h>>6&3;(f||A)&&(t[i]=t[i+1]=this.regs[(e<<2)+f]),h<<=2,i=i+2&511}break;case 3:for(let a=0;a<8;a++){let f=(h&128)>>6;(f||A)&&(t[i]=this.regs[(e<<2)+f]),h<<=1,i=i+1&511}break;case 4:for(let a=0;a<2;a++){let f=(h>>6&3)+(h&12);(f&3||A)&&(t[i]=t[i+1]=t[i+2]=t[i+3]=this.regs[((e&4)<<2)+f]),h<<=2,i=i+2&511}break;case 6:for(let a=0;a<4;a++){let f=(h&128)>>6|(h&8)>>3;(f||A)&&(t[i]=this.regs[(e<<2)+f]),h<<=1,i=i+1&511}break;case 2:for(let a=0;a<8;a++){let f=(h&128)>>6;f+=a&1?e&1:e>>1&1,(f||A)&&(t[i]=this.regs[(e<<2)+f]),h<<=1,i=i+1&511}break;case 7:let P=h;for(let a=0;a<4;a++){a==2&&(P<<=2);let f=(h&128)>>6,Q=e&4|P>>2&3;(f||A)&&(t[i]=this.regs[(Q<<2)+f]),h<<=1,i=i+1&511}break}}}while(this.cycles(this.xtracyc++,this.readInput(t))],[0,31,31,t=>(this.xtracyc++,this.tia.read(t))],[32,63,31,t=>this.maria.read(t)],[64,255,255,t=>this.ram[t+2048]],[256,319,255,t=>this.read(t)],[320,511,511,t=>this.ram[t+2048]],[640,767,127,t=>(this.xtracyc++,this.readPIA(t))],[6144,10239,65535,t=>this.ram[t-6144]],[10240,16383,2047,t=>this.read(t|8192)],[16384,65535,65535,t=>this.rom?this.rom[t-16384]:0],[0,65535,65535,t=>this.probe&&this.probe.logIllegal(t)]]),this.write=_([[21,26,31,(t,e)=>{this.xtracyc++,this.pokey1.setTIARegister(t,e)}],[0,31,31,(t,e)=>{this.xtracyc++,this.tia.write(t,e)}],[32,63,31,(t,e)=>{this.maria.write(t,e)}],[64,255,255,(t,e)=>{this.ram[t+2048]=e}],[256,319,255,(t,e)=>{this.write(t,e)}],[320,511,511,(t,e)=>{this.ram[t+2048]=e}],[640,767,127,(t,e)=>{this.xtracyc++,this.writePIA(t,e)}],[6144,10239,65535,(t,e)=>{this.ram[t-6144]=e}],[10240,16383,2047,(t,e)=>{this.write(t|8192,e)}],[49151,49151,65535,(t,e)=>{}],[0,65535,65535,(t,e)=>{this.probe&&this.probe.logIllegal(t)}]]),this.connectCPUMemoryBus(this),this.dmaBus=this.probeDMABus(this),this.handler=E(this.inputs,Z),this.pokey1=new H,this.audioadapter=new z(this.pokey1,q,X)}readConst(t){let e=this.probe;this.probe=null;let n=this.read(t);return this.probe=e,n}readInput(t){switch(t){case 12:return~this.inputs[8]&128;case 13:return~this.inputs[9]&128;default:return this.inputs[t]|0}}readPIA(t){switch(t){case 0:case 2:return this.inputs[t];case 1:case 3:return this.regs6532[t];case 4:return this.getPIATimerValue();default:return 0}}writePIA(t,e){switch(t){case 0:case 1:case 2:case 3:this.regs6532[t]=e;return;case 20:this.setPIATimer(e,0);return;case 21:this.setPIATimer(e,3);return;case 22:this.setPIATimer(e,6);return;case 23:this.setPIATimer(e,10);return;case 24:this.setPIATimer(e,6);return}}setPIATimer(t,e){this.piatimer=t+1<0?t>>this.timerinterval:t&255}advanceCPU(){var t=super.advanceCPU();return this.tickPIATimer(t),this.xtracyc&&(t+=this.xtracyc,this.tickClocks(this.xtracyc),this.xtracyc=0),t}tickClocks(t){this.probe.logClocks(t),this.tickPIATimer(t)}tickPIATimer(t){this.piatimer=Math.max(-256,this.piatimer-t)}advanceFrame(t){var e=this.pixels,n=0,i,s=0,u=0,c=0;this.lastFrameCycles=-1,this.probe.logNewFrame();for(var x=0;x>2),s+=p,e){let m=(this.maria.regs[28]&128)!=0?15:255;for(var l=0;l<320;l++)e[n++]=J[this.maria.pixels[l]&m]}}for((d||x==M-1)&&this.maria.doInterrupt()&&(this.probe.logInterrupt(0),this.cpu.NMI());s>2),s=C;break}if(t&&t()){t=null,x=999,this.lastFrameCycles=s;break}s+=this.advanceCPU()<<2,c++}this.audio&&this.audioadapter.generate(this.audio),s-=C,u+=s,this.probe.logNewScanline()}return c}getRasterX(){return(this.lastFrameCycles+C)%C}getRasterY(){return this.scanline}getRasterCanvasPosition(){return{x:this.getRasterX(),y:this.getRasterY()}}loadROM(t){t.length==49280&&(t=t.slice(128)),this.rom=N(t,this.defaultROMSize,!0)}reset(){super.reset(),this.tia.reset(),this.maria.reset(),this.inputs.fill(0),this.inputs[b]=255,this.inputs[U]=11,this.setPIATimer(0,0)}readAddress(t){return this.read(t)|0}loadState(t){this.cpu.loadState(t.c),this.ram.set(t.ram),this.tia.loadState(t.tia),this.maria.loadState(t.maria),this.regs6532.set(t.regs6532),this.piatimer=t.pia.timer,this.timerinterval=t.pia.interval,this.loadControlsState(t)}saveState(){return{c:this.cpu.saveState(),ram:this.ram.slice(0),tia:this.tia.saveState(),maria:this.maria.saveState(),regs6532:this.regs6532.slice(0),inputs:this.inputs.slice(0),pia:{timer:this.piatimer,interval:this.timerinterval}}}loadControlsState(t){this.inputs.set(t.inputs)}saveControlsState(){return{inputs:this.inputs.slice(0)}}getDebugCategories(){return["CPU","Stack","TIA","MARIA"]}getDebugInfo(t,e){switch(t){case"TIA":return I.stateToLongString(e.tia);case"MARIA":return L.stateToLongString(e.maria)+` Scanline: `+this.scanline}}getDebugDisplayLists(){let t={},e=this.maria.getDLLStart(),n=0;for(;n<240;){let i=this.readConst(e),s=i&15,u=(i&64)!=0,c=(i&32)!=0,x=(this.readConst(e+1)<<8)+this.readConst(e+2);e=e+3&65535;let d=(this.readConst(e)&128)!=0,l="DL $"+S(x,4)+" "+n+"-"+(n+s);u&&(l+=" H16"),c&&(l+=" H8"),d&&(l+=" DLI"),t[l]={$$:this._readDebugDisplayList(x)},n+=s+1}return t}_readDebugDisplayList(t){return()=>this.readDebugDisplayList(t)}readDebugDisplayList(t){let e=[],n=t&65280,i=t&255;do{let x=this.maria.regs[28],d=this.readConst(n+(i+0&511)),l=this.readConst(n+(i+1&511));if(l==0)break;let p=this.readConst(n+(i+2&511)),g=this.readConst(n+(i+3&511)),y=!1,m="",k,A=(x&3)+(l&128?4:0);if((l&31)==0){var s=g>>5,u=32-(g&31),c=this.readConst(n+(i+4&511));y=(l&32)!=0,k=l&128,i+=5}else{var c=g,s=l>>5,u=32-(l&31);i+=4}m+="X="+c+" W="+u+" P="+s,k&&(m+=" WM=1"),y&&(m+=" CHR=$"+S(this.maria.regs[20]+this.maria.offset&255)+"xx");let w=d+((p+(y?0:this.maria.offset)&255)<<8);m=" $"+S(w,4)+" "+m,m=["160A","?","320D","320A","160B","?","320B","320C"][A]+" "+m,e.push(m)}while(i<512);return e}},J=new Uint32Array(256);for(D=0;D<256;D++)J[D]=j(D);var D;var it=[{id:"sprites.dasm",name:"Sprites (ASM)",category:"Assembler"},{id:"wsync.c",name:"WSYNC",category:"CC65"},{id:"sprites.c",name:"Double Buffering"},{id:"scroll.c",name:"Scrolling"},{id:"test_conio.c78",name:"Conio Test",category:"cc7800"},{id:"example_small_sprites.c78",name:"Small Sprites"},{id:"example_vertical_scrolling.c78",name:"Vertical Scrolling"}],F=class extends ${constructor(){super(...arguments);this.getMemoryMap=function(){return{main:[{name:"TIA",start:0,size:32,type:"io"},{name:"MARIA",start:32,size:32,type:"io"},{name:"RAM (6166 Block 0)",start:64,size:192,type:"ram"},{name:"RAM (6166 Block 1)",start:320,size:192,type:"ram"},{name:"PIA",start:640,size:24,type:"io"},{name:"RAM",start:6144,size:4096,type:"ram"},{name:"Cartridge ROM",start:16384,size:49146,type:"rom"},{name:"CPU Vectors",start:65530,size:6,type:"rom"}]}}}newMachine(){return new T}getPresets(){return it}getDefaultExtensions(){return[...super.getDefaultExtensions(),".cc7800"]}readAddress(t){return this.machine.readConst(t)}getROMExtension(){return".a78"}getDebugTree(){let t=super.getDebugTree();return t.display_list=this.machine.getDebugDisplayLists(),t}getToolForFilename(t){return t.endsWith(".cc7800")||t.endsWith(".c78")?"cc7800":V(t)}};O.atari7800=F; -//# sourceMappingURL=atari7800-4C6PMPB3.js.map +//# sourceMappingURL=atari7800-N44NNLWK.js.map diff --git a/gen/atari7800-4C6PMPB3.js.map b/gen/atari7800-N44NNLWK.js.map similarity index 100% rename from gen/atari7800-4C6PMPB3.js.map rename to gen/atari7800-N44NNLWK.js.map diff --git a/gen/atari8-FYXJ46MZ.js b/gen/atari8-CRLCJ4WS.js similarity index 99% rename from gen/atari8-FYXJ46MZ.js rename to gen/atari8-CRLCJ4WS.js index b1ca677b..d2802e30 100644 --- a/gen/atari8-FYXJ46MZ.js +++ b/gen/atari8-CRLCJ4WS.js @@ -1,7 +1,7 @@ -import{a as nt}from"./chunk-ULIQADK2.js";import{b as ht,c as ot,d as Y}from"./chunk-DYRHT6BM.js";import{A as rt,J as at,g as $,k as tt,m as et,r as st,x as it}from"./chunk-G4HBIXG4.js";import{K as S,V as O,W as i,X as Z,Z as J,a as F,aa as T,g as m,r as A}from"./chunk-TYDI7JZQ.js";import"./chunk-KT7KMEQC.js";var Dt=[0,25,17,9],Ot=[0,89,97,105],b=0,Tt=1,B=2,H=3,Mt=4,kt=5,vt=7,Ct=9,C=10,Lt=11,Pt=12,Kt=13,lt=14,Vt=15,L=15;var wt=13,Nt=106,Ut=105,Q=[0,0,8,10,8,16,8,16,8,4,4,2,1,2,1,1],Ft=[0,0,2,2,2,2,4,4,8,4,4,4,4,2,2,2],Yt=[0,0,0,0,0,1,0,1,0,0,2,1,0,0,0,0],ct=[0,0,1,1,2,2,2,2,8,4,4,2,2,2,2,1],M=class{constructor(e,t){this.regs=new Uint8Array(16);this.left=-1;this.right=-1;this.dma_enabled=!1;this.dliop=0;this.mode=0;this.jmp=!1;this.lms=!1;this.dlarg_lo=0;this.dlarg_hi=0;this.period=0;this.scanaddr=0;this.startaddr=0;this.pfbyte=0;this.ch=0;this.linesleft=0;this.yofs=0;this.isfirstline=!1;this.v=0;this.h=0;this.linebuf=new Uint8Array(48);this.dmaclock=0;this.dmaidx=0;this.output=0;this.dramrefresh=!1;this.in_vscroll=0;this.read=e,this.nmi=t}reset(){this.regs.fill(0),this.regs[lt]=0,this.regs[L]=127,this.regs[Pt]=0,this.regs[Kt]=255,this.setReg(b,0),this.h=this.v=0,this.startaddr=this.scanaddr=0,this.dmaclock=0}saveState(){return A(0,{},this)}loadState(e){A(0,this,e),this.setReg(b,e.regs[b])}static stateToLongString(e){let t="";return t+="H: "+F(e.h,3)+" V: "+F(e.v,3)+` +import{a as nt}from"./chunk-OJEFOAZC.js";import{b as ht,c as ot,d as Y}from"./chunk-DYRHT6BM.js";import{A as rt,J as at,g as $,k as tt,m as et,r as st,x as it}from"./chunk-4676AC7I.js";import{K as S,V as O,W as i,X as Z,Z as J,a as F,aa as T,g as m,r as A}from"./chunk-TYDI7JZQ.js";import"./chunk-KT7KMEQC.js";var Dt=[0,25,17,9],Ot=[0,89,97,105],b=0,Tt=1,B=2,H=3,Mt=4,kt=5,vt=7,Ct=9,C=10,Lt=11,Pt=12,Kt=13,lt=14,Vt=15,L=15;var wt=13,Nt=106,Ut=105,Q=[0,0,8,10,8,16,8,16,8,4,4,2,1,2,1,1],Ft=[0,0,2,2,2,2,4,4,8,4,4,4,4,2,2,2],Yt=[0,0,0,0,0,1,0,1,0,0,2,1,0,0,0,0],ct=[0,0,1,1,2,2,2,2,8,4,4,2,2,2,2,1],M=class{constructor(e,t){this.regs=new Uint8Array(16);this.left=-1;this.right=-1;this.dma_enabled=!1;this.dliop=0;this.mode=0;this.jmp=!1;this.lms=!1;this.dlarg_lo=0;this.dlarg_hi=0;this.period=0;this.scanaddr=0;this.startaddr=0;this.pfbyte=0;this.ch=0;this.linesleft=0;this.yofs=0;this.isfirstline=!1;this.v=0;this.h=0;this.linebuf=new Uint8Array(48);this.dmaclock=0;this.dmaidx=0;this.output=0;this.dramrefresh=!1;this.in_vscroll=0;this.read=e,this.nmi=t}reset(){this.regs.fill(0),this.regs[lt]=0,this.regs[L]=127,this.regs[Pt]=0,this.regs[Kt]=255,this.setReg(b,0),this.h=this.v=0,this.startaddr=this.scanaddr=0,this.dmaclock=0}saveState(){return A(0,{},this)}loadState(e){A(0,this,e),this.setReg(b,e.regs[b])}static stateToLongString(e){let t="";return t+="H: "+F(e.h,3)+" V: "+F(e.v,3)+` `,t+="DLIOp: "+m(e.dliop,2)+" Lines: "+e.yofs+"/"+e.linesleft,t+=" DMA "+(e.dma_enabled?"ON ":"off"),e.dma_enabled&&(t+=" idx "+e.dmaidx+" clk "+m(e.dmaclock)),t+=` `,t+="Addr: "+m(e.scanaddr,4)+` `,t+=O(e.regs,0,16).replace("$00","Regs"),t}setReg(e,t){switch(e){case C:this.regs[C]=255;return;case Vt:this.regs[L]=31;return}this.regs[e]=t}readReg(e){switch(e){case L:return this.regs[e];case Lt:return this.v>>1;default:return 255}}processDLIEntry(){if(this.mode==0)this.linesleft=(this.dliop>>4&7)+1,this.dmaclock=0;else{this.linesleft=Q[this.mode],this.period=Ft[this.mode],this.jmp?(this.regs[B]=this.dlarg_lo,this.regs[H]=this.dlarg_hi,this.mode=this.period=0,this.dliop&64&&(this.linesleft=1,this.dma_enabled=!1),this.dmaclock=0):this.lms&&(this.scanaddr=this.dlarg_lo+(this.dlarg_hi<<8)),this.startaddr=this.scanaddr;let e=this.regs[b]&3,t=this.dliop&16?(this.regs[Mt]&15)>>1:0;this.dliop&16&&e<3&&e++,this.left=Dt[e]+t,this.right=Ot[e]+t;let s=this.regs[kt]&15;this.dliop&32^this.in_vscroll&&(this.in_vscroll?this.linesleft=s+1:(this.linesleft-=s,this.yofs+=s),this.linesleft&=15,this.in_vscroll^=32)}}nextLine(){this.linesleft>0&&(this.linesleft--,this.yofs++,this.isfirstline=!1,this.mode>=8&&this.linesleft&&(this.scanaddr=this.startaddr))}triggerNMI(e){this.regs[L]=e|31,this.regs[lt]&e&&this.nmi()}getDlistAddr(){return this.regs[B]+(this.regs[H]<<8)}nextInsn(){let e=this.getDlistAddr(),t=this.read(e);return e=e+1&1023|e&-1024,this.regs[B]=e&255,this.regs[H]=e>>8,t}nextScreen(){let e=this.read(this.scanaddr);return this.incScanAddr(),e}incScanAddr(){this.scanaddr=this.scanaddr+1&4095|this.scanaddr&-4096}dlDMAEnabled(){return this.regs[b]&32}isVisibleScanline(){return this.v>=8&&this.v<248}isPlayfieldDMAEnabled(){return this.dma_enabled&&!this.linesleft}isPlayerDMAEnabled(){return this.regs[b]&8}isMissileDMAEnabled(){return this.regs[b]&12}isWSYNC(){return this.regs[C]!=0}clockPulse(){let e=this.isWSYNC();if(!this.isVisibleScanline())this.doVBlank();else{switch(this.h){case 0:this.isMissileDMAEnabled()&&(this.doPlayerMissileDMA(3),e=!0);break;case 1:if(this.isPlayfieldDMAEnabled()){let t=this.nextInsn();this.jmp=(t&-65)==1,this.lms=(t&64)!=0&&(t&15)!=0,this.mode=t&15,this.dliop=t,this.yofs=0,this.isfirstline=!0,e=!0}break;case 2:case 3:case 4:case 5:this.isPlayerDMAEnabled()&&(this.doPlayerMissileDMA(this.h+2),e=!0);break;case 6:case 7:this.isPlayfieldDMAEnabled()&&this.isfirstline&&(this.jmp||this.lms)&&(this.h==6&&(this.dlarg_lo=this.nextInsn()),this.h==7&&(this.dlarg_hi=this.nextInsn()),e=!0);break;case 8:this.isfirstline&&this.processDLIEntry(),this.dliop&128&&this.linesleft==1&&this.triggerNMI(128);break;case 9:break;case 111:this.dma_enabled&&this.nextLine(),++this.v;break}if(this.output=0,this.mode>=2&&this.period){let t=this.h<=Ut;this.dmaclock=this.dmaclock<<1&511,this.dmaclock&1<=8&&this.incScanAddr(),e=t),this.output=this.h>=this.left+3&&this.h<=this.right+2?4:0}}return(this.hNt)&&(this.output=2),this.incHorizCounter(),!e&&this.dramrefresh&&(this.read(0),this.dramrefresh=!1,e=!0),e}incHorizCounter(){switch(this.h){case 25:case 29:case 33:case 37:case 41:case 45:case 49:case 53:case 57:this.dramrefresh=!0;break;case 102:this.regs[C]=0;break;case 113:this.h=0;return}++this.h}doVBlank(){this.linesleft=this.mode=this.period=0,this.h==111&&this.v++,this.v==248&&this.h==0&&this.triggerNMI(64),this.v==262&&this.h==112&&(this.v=0),this.v==7&&this.h==113&&(this.dma_enabled=this.dlDMAEnabled()!=0),this.output=2,this.dmaclock=0}doPlayerMissileDMA(e){let t=this.regs[b]&16,s=this.regs[vt]<<8;t?(s&=63488,s|=e<<8,s|=this.v&255):(s&=64512,s|=e<<7,s|=this.v>>1),this.read(s)}readBitmapData(){let e=this.mode;if(e<8){let t=this.ch,s=this.yofs>>Yt[this.mode],r=s&7,n=this.regs[Ct];(e&14)==6?(t&=63,n&=254):(t&=127,n&=252);let h=(t<<3)+(n<<8);if((e&14)==2){let f=this.regs[Tt],l=e==3&&(t&96)==96;f&4?this.pfbyte=this.read(h+(r^7)):this.pfbyte=this.read(h+r),l&&s<2&&(this.pfbyte=0),!l&&s>7&&(this.pfbyte=0),this.ch&128&&(f&1&&(this.pfbyte=0),f&2&&(this.pfbyte^=255))}else this.pfbyte=this.read(h+r)}else this.pfbyte=this.nextScreen()}shiftout(){if(this.output==4)switch(this.mode){case 2:case 3:case 15:{let e=this.pfbyte>>7&1;return this.pfbyte<<=1,e?8:6}case 6:case 7:{let e=this.pfbyte>>7&1;return this.pfbyte<<=1,e?(this.ch>>6)+4:0}case 9:case 11:case 12:{let e=this.pfbyte>>7&1;return this.pfbyte<<=1,e?4:0}case 4:case 5:{let e=this.pfbyte>>6&3;return this.pfbyte<<=2,this.ch&128?[0,4,5,7][e]:[0,4,5,6][e]}case 8:case 10:case 13:case 14:{let e=this.pfbyte>>6&3;return this.pfbyte<<=2,[0,4,5,6][e]}}return this.output}};var o=0;var Bt=2;var ft=4;var dt=6;var g=8,Ht=9,Qt=10,zt=11,Xt=13,z=14,E=15;var qt=8,Wt=9,Gt=10,jt=13,I=14,P=15;var xt=128,ut=64,Zt=32,mt=16,gt=8;var Jt=1,_t=28,$t=114;var pt=511,bt=131071,x=0,u=1,_=2,c=3,y=114,te=15;var ee=8;var X,K;function se(){X=new Uint8Array(511),K=new Uint8Array(16385);let a=511;for(let e=0;e<511;e++)a=(((a>>5^a)&1)<<8)+(a>>1),X[e]=a;a=131071;for(let e=0;e<16385;e++)a=(((a>>5^a)&255)<<9)+(a>>8),K[e]=a>>1}var k=class{constructor(e,t){this.irq=e;this.antic_xpos=t;this.regs=new Uint8Array(16);this.readregs=new Uint8Array(16);this.divnirq=new Uint32Array(4);this.divnmax=new Uint32Array(4);this.pot_inputs=new Uint8Array(8);this.basemult=0;this.pot_scanline=0;this.random_scanline_counter=0;this.kbcode=0;this.DELAYED_SERIN_IRQ=0;this.DELAYED_SEROUT_IRQ=0;this.DELAYED_XMTDONE_IRQ=0;this.init()}saveState(){return A(0,{},this)}loadState(e){A(0,this,e)}init(){this.readregs.fill(255),this.readregs[P]=239,this.basemult=_t,this.pot_inputs.fill(128),se()}read(e){let t=this.readregs[e];switch(e&=15,e){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:return t=this.pot_inputs[e],t>3;s&=7,t=(K[r]>>s)+(K[r+1]<<8-s)}}break}return t&255}write(e,t){switch(e&=15,this.regs[e]=t,e){case g:t&Jt?this.basemult=$t:this.basemult=_t,this.update_counter(1<=3?(this.readregs[I]|=8,this.DELAYED_XMTDONE_IRQ=2*this.DELAYED_SEROUT_IRQ-2):(this.DELAYED_SEROUT_IRQ=0,this.DELAYED_XMTDONE_IRQ=0));break;case Ht:this.divnirq[x]=this.divnmax[x],this.divnirq[u]=this.divnmax[u],this.divnirq[_]=this.divnmax[_],this.divnirq[c]=this.divnmax[c];break;case E:t&4&&(this.pot_scanline=228),(t&3)==0&&(this.DELAYED_SERIN_IRQ=0,this.DELAYED_SEROUT_IRQ=0,this.DELAYED_XMTDONE_IRQ=0);break}this.snd_update(e)}update_counter(e){e&1<0&&--this.DELAYED_SERIN_IRQ==0&&(this.readregs[jt]=this.SIO_GetByte(),this.generateIRQ(32)),this.DELAYED_SEROUT_IRQ>0&&--this.DELAYED_SEROUT_IRQ==0&&this.generateIRQ(16),this.DELAYED_XMTDONE_IRQ>0&&--this.DELAYED_XMTDONE_IRQ==0&&this.generateIRQ(8),this.advanceIRQTimer(x,1),this.advanceIRQTimer(u,2),this.advanceIRQTimer(c,4))}advanceIRQTimer(e,t){(this.divnirq[e]-=y)<0&&(this.divnirq[e]+=this.divnmax[e],this.generateIRQ(t))}generateIRQ(e){this.regs[z]&e&&(this.irq(),this.readregs[I]&=~e)}static stateToLongString(e){let t="";return t+=`Write Registers: `,t+=O(e.regs,0,16),t+=`Read Registers: `,t+=O(e.readregs,0,16),t}CASSETTE_IOLineStatus(){return 0}siocheck(){return((this.regs[o+_]==40||this.regs[o+_]==16||this.regs[o+_]==8||this.regs[o+_]==10)&&this.regs[o+c]==0||(this.regs[E]&120)==40)&&(this.regs[g]&40)==40}SIO_PutByte(e){console.log("SIO put byte",e)}SIO_GetByte(){return 0}};var ie=[i.VK_L,i.VK_J,i.VK_SEMICOLON,i.VK_F4,i.VK_F5,i.VK_K,i.VK_BACK_SLASH,i.VK_TILDE,i.VK_O,null,i.VK_P,i.VK_U,i.VK_ENTER,i.VK_I,i.VK_MINUS2,i.VK_EQUALS2,i.VK_V,i.VK_F7,i.VK_C,i.VK_F6,i.VK_F4,i.VK_B,i.VK_X,i.VK_Z,i.VK_4,null,i.VK_3,i.VK_6,i.VK_ESCAPE,i.VK_5,i.VK_2,i.VK_1,i.VK_COMMA,i.VK_SPACE,i.VK_PERIOD,i.VK_N,null,i.VK_M,i.VK_SLASH,null,i.VK_R,null,i.VK_E,i.VK_Y,i.VK_TAB,i.VK_T,i.VK_W,i.VK_Q,i.VK_9,null,i.VK_0,i.VK_7,i.VK_BACK_SPACE,i.VK_8,null,null,i.VK_F,i.VK_H,i.VK_D,null,i.VK_CAPS_LOCK,i.VK_G,i.VK_S,i.VK_A],re=J([[i.UP,0,1],[i.DOWN,0,2],[i.LEFT,0,4],[i.RIGHT,0,8],[{c:16,n:"Shift",plyr:0,button:0},2,1],[i.VK_F1,3,1],[i.VK_F2,3,2],[i.VK_F3,3,4]]),v=class extends st{constructor(){super();this.cpuFrequency=1789773;this.numTotalScanlines=262;this.cpuCyclesPerLine=114;this.canvasWidth=336;this.numVisibleScanlines=224;this.aspectRatio=this.canvasWidth/this.numVisibleScanlines*.857;this.firstVisibleScanline=16;this.firstVisibleClock=76;this.defaultROMSize=32768;this.overscan=!0;this.audioOversample=2;this.sampleRate=this.numTotalScanlines*60*this.audioOversample;this.run_address=-1;this.inputs=new Uint8Array(4);this.linergb=new Uint32Array(this.canvasWidth);this.lastdmabyte=0;this.keycode=0;this.cart_80=!1;this.cart_a0=!1;this.xexdata=null;this.keyboard_active=!0;this.d500=new Uint8Array(256);this.cpu=new et,this.ram=new Uint8Array(65536),this.bios=new Uint8Array(10240),this.bus=this.newBus(),this.connectCPUMemoryBus(this.bus),this.antic=new M(this.readDMA.bind(this),this.antic_nmi.bind(this)),this.gtia=new Y,this.irq_pokey=new k(this.pokey_irq.bind(this),()=>this.antic.h),this.audio_pokey=$(1),this.audioadapter=new tt(this.audio_pokey.pokey1,this.audioOversample,this.sampleRate),this.handler=Z(this.inputs,re,this.getKeyboardFunction(),!0)}newBus(){return{read:T([[0,32767,65535,t=>this.ram[t]],[32768,40959,65535,t=>this.cart_80?this.rom[t-32768]:this.ram[t]],[40960,49151,65535,t=>this.cart_a0?this.rom[t-32768]:this.ram[t]],[53248,53503,31,t=>this.gtia.readReg(t)],[53760,54015,15,t=>this.readPokey(t)],[54016,54271,15,t=>this.readPIA(t)],[54272,54527,15,t=>this.antic.readReg(t)],[54528,54783,255,t=>this.d500[t]],[55296,65535,65535,t=>this.bios[t-55296]]]),write:T([[0,49146,65535,(t,s)=>{this.ram[t]=s}],[49147,49151,65535,(t,s)=>{this.ram[t]=s,this.initCartA()}],[53248,53503,31,(t,s)=>{this.gtia.setReg(t,s)}],[53760,54015,15,(t,s)=>{this.writePokey(t,s)}],[54272,54527,15,(t,s)=>{this.antic.setReg(t,s)}],[54528,54783,255,(t,s)=>{this.writeMapper(t,s)}]])}}loadBIOS(t){this.bios.set(t)}reset(){super.reset(),this.antic.reset(),this.gtia.reset(),this.keycode=0}read(t){return this.bus.read(t)}readDMA(t){let s=this.bus.read(t);return this.probe.logDMARead(t,s),this.lastdmabyte=s,s}readConst(t){return t<53248||t>=54528?this.bus.read(t):255}write(t,s){this.bus.write(t,s)}readPokey(t){switch(t&15){case 9:return this.keycode&255;case 15:return~this.keycode>>6&4|~this.keycode>>3&8|18;default:return this.irq_pokey.read(t)}}readPIA(t){if(t==0||t==1)return~this.inputs[t]}writePokey(t,s){this.audio_pokey.pokey1.setRegister(t,s),this.irq_pokey.write(t,s)}startScanline(){this.gtia.sync();for(let t=0;t<4;t++)this.gtia.readregs[ht+t]=~this.inputs[2]>>t&1;this.gtia.readregs[ot]=~this.inputs[3]&7,this.audio&&this.audioadapter.generate(this.audio),this.irq_pokey.advanceScanline()}drawScanline(){let t=this.antic.v-this.firstVisibleScanline;t>=0&&t{this.gtia.clockPulse1(),this.linergb[t++]=this.gtia.rgb},r=()=>{this.gtia.clockPulse2(),this.linergb[t++]=this.gtia.rgb};this.gtia.clockPulse4(),this.antic.dliop&16&&this.antic.regs[4]&1?(t+=2,this.gtia.setBias(-1)):this.gtia.setBias(0);let n=ct[this.antic.mode],h=this.antic.h&1;return(n<8||h)&&(this.gtia.an=this.antic.shiftout()),s(),n==1&&(this.gtia.an=this.antic.shiftout()),r(),n<=2&&(this.gtia.an=this.antic.shiftout()),s(),n==1&&(this.gtia.an=this.antic.shiftout()),r(),1}loadState(t){this.loadControlsState(t),this.cpu.loadState(t.c),this.ram.set(t.ram),this.antic.loadState(t.antic),this.gtia.loadState(t.gtia),this.irq_pokey.loadState(t.pokey),this.lastdmabyte=t.lastdmabyte,this.cart_80=t.cart_80,this.cart_a0=t.cart_a0}saveState(){return{c:this.cpu.saveState(),ram:this.ram.slice(0),antic:this.antic.saveState(),gtia:this.gtia.saveState(),pokey:this.irq_pokey.saveState(),inputs:this.inputs.slice(0),lastdmabyte:this.lastdmabyte,keycode:this.keycode,cart_80:this.cart_80,cart_a0:this.cart_a0}}loadControlsState(t){this.inputs.set(t.inputs),this.keycode=t.keycode}saveControlsState(){return{inputs:this.inputs.slice(0),keycode:this.keycode}}getRasterY(){return this.antic.v}getRasterX(){return this.antic.h}getRasterCanvasPosition(){return{x:this.antic.h*4-this.firstVisibleClock,y:this.antic.v-this.firstVisibleScanline}}getDebugCategories(){return["CPU","Stack","ANTIC","GTIA","POKEY"]}getDebugInfo(t,s){switch(t){case"ANTIC":return M.stateToLongString(s.antic);case"GTIA":return Y.stateToLongString(s.gtia);case"POKEY":return k.stateToLongString(s.pokey)}}getKeyboardFunction(){return(t,s,r,n)=>{if(!this.keyboard_active)return!1;if(n&65){var h=ie;if(s==i.VK_F9.c)return this.irq_pokey.generateIRQ(128),!0;for(var f=0;f>8}if(s>t.length)throw new Error("Bad .XEX file format")}h>=0&&(r[n++]=169,r[n++]=160,r[n++]=141,r[n++]=255,r[n++]=213,r[n++]=76,r[n++]=h&255,r[n++]=h>>8,this.ram[10]=0,this.ram[11]=213,this.run_address=54528)}initCartA(){this.cpu.getPC()==61823&&this.xexdata&&this.loadXEX(this.xexdata)}setPaddleInput(t,s){this.irq_pokey.pot_inputs[t]=255-s}getDebugDisplayList(){let t=this.antic.getDlistAddr(),s=()=>{let h=this.read(t);return t=t+1&1023|t&-1024,h},r=[],n=0;for(let h=0;h<256&&n<240;h++){let f=t,l=s(),p=l&15,d="",R=!1,D;if(p==0)D=(l>>4&7)+1,d+=" blank="+D;else{D=Q[p],d+=" mode="+m(p),d+=" lines="+D,R=(l&-65)==1;let j=(l&64)!=0&&(l&15)!=0;if(l&16&&(d+=" HSCROL"),l&32&&(d+=" VSCROL"),l&128&&(d+=" DLI"),R&&l&64?d+=" JVB":R?d+=" JMP":j&&(d+=" LMS"),R||j){let It=s(),Rt=s();d+=" $"+m(Rt)+m(It)}}if(r.push("$"+m(f)+" y="+n+" "+d),R)break;n+=D}return r}},V=class extends v{newBus(){return{read:T([[0,16383,65535,e=>this.ram[e]],[16384,49151,65535,e=>this.rom?this.rom[e-16384]:0],[49152,53247,31,e=>this.gtia.readReg(e)],[54272,54527,15,e=>this.antic.readReg(e)],[59392,61439,15,e=>this.readPokey(e)],[63488,65535,2047,e=>this.bios[e]]]),write:T([[0,16383,65535,(e,t)=>{this.ram[e]=t}],[49152,53247,31,(e,t)=>{this.gtia.setReg(e,t)}],[54272,54527,15,(e,t)=>{this.antic.setReg(e,t)}],[59392,61439,15,(e,t)=>{this.writePokey(e,t)}]])}}};var G=[{id:"hello.dasm",name:"Hello World (ASM)"},{id:"hellopm.dasm",name:"Hello Sprites (ASM)"},{id:"helloconio.c",name:"Text Mode (C)"},{id:"siegegame.c",name:"Siege Game (C)"},{id:"hellodlist.c",name:"Display List (C)"}],yt=G.concat([{id:"testmusic.c",name:"POKEY Music (C)"},{id:"sieve.bas",name:"Benchmark (FastBasic)",category:"FastBasic"},{id:"pmtest.bas",name:"Sprites Test (FastBasic)"},{id:"dli.bas",name:"DLI Test (FastBasic)"},{id:"joyas.bas",name:"Match-3 Game (FastBasic)"}]),Et={main:[{name:"RAM",start:0,size:49152,type:"ram"},{name:"Left Cartridge ROM",start:40960,size:8192,type:"rom"},{name:"GTIA",start:53248,size:32,type:"io"},{name:"POKEY",start:53760,size:16,type:"io"},{name:"PIA",start:54016,size:4,type:"io"},{name:"ANTIC",start:54272,size:16,type:"io"},{name:"Cartridge Control Line",start:54784,size:256,type:"io"},{name:"ROM",start:55296,size:2048,type:"rom"},{name:"Character Set",start:57344,size:1024,type:"rom"},{name:"ROM",start:58368,size:7168,type:"rom"}]};function At(a){return a.endsWith(".bas")||a.endsWith(".fb")||a.endsWith(".fbi")?"fastbasic":it(a)}var w=class extends at{constructor(){super(...arguments);this.getToolForFilename=At;this.showHelp=St;this.getROMExtension=ae;this.biosPath="res/altirra/kernel.rom"}newMachine(){return new v}getPresets(){return yt}getDefaultExtensions(){return[...super.getDefaultExtensions(),".bas"]}readAddress(t){return this.machine.readConst(t)}getMemoryMap(){return Et}async start(){let t=await this.loadKernel();await super.start(),this.machine.loadBIOS(t)}async loadKernel(){var t=await fetch(this.biosPath);if(t.status==200||t.size){var s=await t.arrayBuffer();return new Uint8Array(s)}else throw new Error("could not load BIOS file")}getDebugTree(){let t=super.getDebugTree();return t.display_list=this.machine.getDebugDisplayList(),t}},q=class extends w{constructor(){super(...arguments);this.biosPath="res/altirra/superkernel.rom"}getPresets(){return G}newMachine(){return new V}},N=class extends nt{constructor(){super(...arguments);this.getToolForFilename=At;this.getOpcodeMetadata=rt;this.showHelp=St}getPresets(){return G}getDefaultExtensions(){return[".c",".bas",".cpp",".acme",".xa",".ca65",".dasm",".ecs",".wiz"]}},U=class extends N{constructor(){super(...arguments);this.getMemoryMap=function(){return Et}}getPresets(){return yt}loadROM(t,s){this.started?(this.loadROMFile(s),this.loadRegion(":cartleft:cart:rom",s)):this.startModule(this.mainElement,{jsfile:"mame8bitws.js",biosfile:"a800xl.zip",cfgfile:"a800xl.cfg",driver:"a800xl",width:336*2,height:450,romfn:"/emulator/cart.rom",romdata:new Uint8Array(s),romsize:8192,preInit:function(r){}})}start(){}},W=class extends N{constructor(){super(...arguments);this.getMemoryMap=function(){return{main:[{name:"RAM",start:0,size:16384,type:"ram"},{name:"Cartridge ROM",start:16384,size:32768,type:"rom"},{name:"GTIA",start:49152,size:32,type:"io"},{name:"ANTIC",start:54272,size:16,type:"io"},{name:"POKEY",start:59392,size:16,type:"io"},{name:"ATARI Character Set",start:63488,size:1024,type:"rom"},{name:"ROM",start:64512,size:1024,type:"rom"}]}}}loadROM(t,s){this.started?(this.loadROMFile(s),this.loadRegion(":cartleft:cart:rom",s)):this.startModule(this.mainElement,{jsfile:"mame8bitws.js",biosfile:"a5200/5200.rom",cfgfile:"a5200.cfg",driver:"a5200",width:336*2,height:450,romfn:"/emulator/cart.rom",romdata:new Uint8Array(s),romsize:32768,preInit:function(r){}})}start(){}};function ae(a){return a==null?".bin":a[0]==255&&a[1]==255?".xex":".rom"}function St(){return"https://8bitworkshop.com/docs/platforms/atari8/"}S["atari8-800.xlmame"]=U;S["atari8-800xl.mame"]=U;S["atari8-5200.mame"]=W;S["atari8-800"]=w;S["atari8-5200"]=q; -//# sourceMappingURL=atari8-FYXJ46MZ.js.map +//# sourceMappingURL=atari8-CRLCJ4WS.js.map diff --git a/gen/atari8-FYXJ46MZ.js.map b/gen/atari8-CRLCJ4WS.js.map similarity index 100% rename from gen/atari8-FYXJ46MZ.js.map rename to gen/atari8-CRLCJ4WS.js.map diff --git a/gen/basic-7UKD4ULU.js b/gen/basic-VCWOI5LB.js similarity index 98% rename from gen/basic-7UKD4ULU.js rename to gen/basic-VCWOI5LB.js index e952f02d..5d624676 100644 --- a/gen/basic-7UKD4ULU.js +++ b/gen/basic-VCWOI5LB.js @@ -1,4 +1,4 @@ -import{b as S}from"./chunk-3FIVEUG2.js";import{u as E}from"./chunk-3GET2PUK.js";import"./chunk-UG4IOEUD.js";import"./chunk-LNOKARBD.js";import"./chunk-A7SWO6EA.js";import"./chunk-OCVBA66T.js";import"./chunk-G4HBIXG4.js";import{B as c,K as f,T as d,U as v,a as g}from"./chunk-TYDI7JZQ.js";import"./chunk-KT7KMEQC.js";function k(u){return u.value!=null}function y(u){return u.name!=null}function O(u){return u.op!=null&&u.left!=null&&u.right!=null}function N(u){return u.op!=null&&u.expr!=null}var m=class{randomize(){this.seed(Math.random()*2147483647,Math.random()*2147483647,Math.random()*2147483647,Math.random()*2147483647)}constructor(){(()=>{var r,e,i,n;this.seed=function(s,a,h,o){r=s,e=a,i=h,n=o},this.seedfloat=function(s){this.seed(s,s*4294,s*429496,s*4294967296),this.next(),this.next(),this.next()},this.next=function(){r>>>=0,e>>>=0,i>>>=0,n>>>=0;var s=r+e|0;return r=e^e>>>9,e=i+(i<<3)|0,i=i<<21|i>>>11,n=n+1|0,s=s+n|0,i=i+s|0,(s>>>0)/4294967296}})(),this.seedfloat(-1)}},I=1024*1024,l=class u{constructor(){this.margin=80;this.running=!1;this.exited=!0;this.trace=!1}load(t){let r=null,e=0;if(this.pc2label!=null){let s=this.curpc;for(;s>0&&(r=this.pc2label.get(s))==null;)s--;e=this.curpc-s,console.log("oldpc=",this.curpc,"restart @ label",r,"+",e)}this.program=t,this.opts=t.opts,this.opts.maxArrayElements||(this.opts.maxArrayElements=I),this.allstmts=t.stmts,this.label2pc=t.labels,this.label2dataptr={},this.pc2label=new Map,this.datums=[],this.subroutines={},this.builtins=this.getBuiltinFunctions();for(var i in t.labels){var n=t.labels[i];this.pc2label.set(n,i)}return this.allstmts.forEach((s,a)=>{this.curpc=a+1,this.compileStatement(s),s.command=="DATA"&&(this.label2dataptr[s.$loc.label]=this.datums.length,s.datums.forEach(h=>{this.curpc=s.$loc.offset,this.datums.push(h)}))}),this.label2pc[r]!=null?(this.curpc=this.label2pc[r]+e,!0):(this.curpc=0,!1)}reset(){this.curpc=0,this.dataptr=0,this.clearVars(),this.returnStack=[],this.column=0,this.running=!0,this.exited=!1}clearVars(){this.globals=this.vars={},this.arrays={},this.defs={},this.forLoops={},this.forLoopStack=[],this.whileLoops=[],this.rng=new m,this.opts&&this.opts.staticArrays&&this.allstmts.filter(t=>t.command=="DIM").forEach(t=>{t.args.forEach(r=>this.compileJS(this._DIM(r))())})}saveState(){return $.extend(!0,{},this)}loadState(t){$.extend(!0,this,t)}getBuiltinFunctions(){var t=this.program&&this.opts.validFunctions;t||(t=Object.getOwnPropertyNames(u.prototype).filter(i=>/^[A-Z]{3,}[$]?$/.test(i)));var r={};for(var e of t)this.supportsFunction(e)&&(r[e]=this[e].bind(this));return r}supportsFunction(t){return typeof this[t]=="function"}runtimeError(t){throw this.curpc--,new d(t,this.getCurrentSourceLocation())}dialectError(t){this.runtimeError(`I can't ${t} in this dialect of BASIC.`)}getLineForPC(t){var r=this.allstmts[t];return r&&r.$loc&&r.$loc.line}getLabelForPC(t){var r=this.allstmts[t];return r&&r.$loc&&r.$loc.label}getCurrentSourceLocation(){var t=this.getStatement();return t&&t.$loc}getCurrentLabel(){var t=this.getCurrentSourceLocation();return t&&t.label}getStatement(){return this.allstmts[this.curpc]}step(){if(!this.running)return!1;var t=this.getStatement();return t?(this.trace&&console.log(this.curpc,t,this.vars,Object.keys(this.arrays)),this.curpc++,this.executeStatement(t),this.running):(this.running=!1,this.exited=!0,!1)}compileStatement(t){if(t.$run==null)try{var r=this["do__"+t.command];r==null&&this.runtimeError(`I don't know how to "${t.command}".`);var e=r.bind(this)(t);this.trace&&console.log(e),t.$run=this.compileJS(e)}catch(i){throw e&&console.log(e),i}}compileJS(t){return new Function(t).bind(this)}executeStatement(t){this.compileStatement(t),t.$run()}skipToEOL(){do this.curpc++;while(this.curpc=0?this.curpc=r:this.runtimeError(`I tried to go to the label "${t}" but couldn't find it.`)}newLocalScope(){this.vars=Object.create(this.vars)}popLocalScope(){this.vars!==this.globals&&(this.vars=Object.getPrototypeOf(this.vars))}gosubLabel(t){this.returnStack.length>32767&&this.runtimeError("I did too many GOSUBs without a RETURN."),this.returnStack.push(this.curpc),this.gotoLabel(t)}returnFromGosub(){this.returnStack.length==0&&this.runtimeError("I tried to RETURN, but there wasn't a corresponding GOSUB.");var t=this.returnStack.pop();this.curpc=t,this.popLocalScope()}popReturnStack(){this.returnStack.length==0&&this.runtimeError("I tried to POP, but there wasn't a corresponding GOSUB."),this.returnStack.pop()}valueToString(t,r){var e;if(typeof t=="number"){var i=this.float2str(t,this.opts.printZoneLength-4);return r?i.startsWith("-")?`${i} `:` ${i} `:i}else if(t==` +import{b as S}from"./chunk-3FIVEUG2.js";import{w as E}from"./chunk-KW4IDSDB.js";import"./chunk-UG4IOEUD.js";import"./chunk-LNOKARBD.js";import"./chunk-A7SWO6EA.js";import"./chunk-YLE5X5XS.js";import"./chunk-4676AC7I.js";import{B as c,K as f,T as d,U as v,a as g}from"./chunk-TYDI7JZQ.js";import"./chunk-KT7KMEQC.js";function k(u){return u.value!=null}function y(u){return u.name!=null}function O(u){return u.op!=null&&u.left!=null&&u.right!=null}function N(u){return u.op!=null&&u.expr!=null}var m=class{randomize(){this.seed(Math.random()*2147483647,Math.random()*2147483647,Math.random()*2147483647,Math.random()*2147483647)}constructor(){(()=>{var r,e,i,n;this.seed=function(s,a,h,o){r=s,e=a,i=h,n=o},this.seedfloat=function(s){this.seed(s,s*4294,s*429496,s*4294967296),this.next(),this.next(),this.next()},this.next=function(){r>>>=0,e>>>=0,i>>>=0,n>>>=0;var s=r+e|0;return r=e^e>>>9,e=i+(i<<3)|0,i=i<<21|i>>>11,n=n+1|0,s=s+n|0,i=i+s|0,(s>>>0)/4294967296}})(),this.seedfloat(-1)}},I=1024*1024,l=class u{constructor(){this.margin=80;this.running=!1;this.exited=!0;this.trace=!1}load(t){let r=null,e=0;if(this.pc2label!=null){let s=this.curpc;for(;s>0&&(r=this.pc2label.get(s))==null;)s--;e=this.curpc-s,console.log("oldpc=",this.curpc,"restart @ label",r,"+",e)}this.program=t,this.opts=t.opts,this.opts.maxArrayElements||(this.opts.maxArrayElements=I),this.allstmts=t.stmts,this.label2pc=t.labels,this.label2dataptr={},this.pc2label=new Map,this.datums=[],this.subroutines={},this.builtins=this.getBuiltinFunctions();for(var i in t.labels){var n=t.labels[i];this.pc2label.set(n,i)}return this.allstmts.forEach((s,a)=>{this.curpc=a+1,this.compileStatement(s),s.command=="DATA"&&(this.label2dataptr[s.$loc.label]=this.datums.length,s.datums.forEach(h=>{this.curpc=s.$loc.offset,this.datums.push(h)}))}),this.label2pc[r]!=null?(this.curpc=this.label2pc[r]+e,!0):(this.curpc=0,!1)}reset(){this.curpc=0,this.dataptr=0,this.clearVars(),this.returnStack=[],this.column=0,this.running=!0,this.exited=!1}clearVars(){this.globals=this.vars={},this.arrays={},this.defs={},this.forLoops={},this.forLoopStack=[],this.whileLoops=[],this.rng=new m,this.opts&&this.opts.staticArrays&&this.allstmts.filter(t=>t.command=="DIM").forEach(t=>{t.args.forEach(r=>this.compileJS(this._DIM(r))())})}saveState(){return $.extend(!0,{},this)}loadState(t){$.extend(!0,this,t)}getBuiltinFunctions(){var t=this.program&&this.opts.validFunctions;t||(t=Object.getOwnPropertyNames(u.prototype).filter(i=>/^[A-Z]{3,}[$]?$/.test(i)));var r={};for(var e of t)this.supportsFunction(e)&&(r[e]=this[e].bind(this));return r}supportsFunction(t){return typeof this[t]=="function"}runtimeError(t){throw this.curpc--,new d(t,this.getCurrentSourceLocation())}dialectError(t){this.runtimeError(`I can't ${t} in this dialect of BASIC.`)}getLineForPC(t){var r=this.allstmts[t];return r&&r.$loc&&r.$loc.line}getLabelForPC(t){var r=this.allstmts[t];return r&&r.$loc&&r.$loc.label}getCurrentSourceLocation(){var t=this.getStatement();return t&&t.$loc}getCurrentLabel(){var t=this.getCurrentSourceLocation();return t&&t.label}getStatement(){return this.allstmts[this.curpc]}step(){if(!this.running)return!1;var t=this.getStatement();return t?(this.trace&&console.log(this.curpc,t,this.vars,Object.keys(this.arrays)),this.curpc++,this.executeStatement(t),this.running):(this.running=!1,this.exited=!0,!1)}compileStatement(t){if(t.$run==null)try{var r=this["do__"+t.command];r==null&&this.runtimeError(`I don't know how to "${t.command}".`);var e=r.bind(this)(t);this.trace&&console.log(e),t.$run=this.compileJS(e)}catch(i){throw e&&console.log(e),i}}compileJS(t){return new Function(t).bind(this)}executeStatement(t){this.compileStatement(t),t.$run()}skipToEOL(){do this.curpc++;while(this.curpc=0?this.curpc=r:this.runtimeError(`I tried to go to the label "${t}" but couldn't find it.`)}newLocalScope(){this.vars=Object.create(this.vars)}popLocalScope(){this.vars!==this.globals&&(this.vars=Object.getPrototypeOf(this.vars))}gosubLabel(t){this.returnStack.length>32767&&this.runtimeError("I did too many GOSUBs without a RETURN."),this.returnStack.push(this.curpc),this.gotoLabel(t)}returnFromGosub(){this.returnStack.length==0&&this.runtimeError("I tried to RETURN, but there wasn't a corresponding GOSUB.");var t=this.returnStack.pop();this.curpc=t,this.popLocalScope()}popReturnStack(){this.returnStack.length==0&&this.runtimeError("I tried to POP, but there wasn't a corresponding GOSUB."),this.returnStack.pop()}valueToString(t,r){var e;if(typeof t=="number"){var i=this.float2str(t,this.opts.printZoneLength-4);return r?i.startsWith("-")?`${i} `:` ${i} `:i}else if(t==` `)this.column=0,e=t;else if(t==" "){var n=this.opts.printZoneLength,s=Math.floor(this.column/n),a=(s+1)*this.opts.printZoneLength;a+n>this.margin?(this.column=0,e=` `):e=this.TAB(a)}else e=`${t}`;return e}float2str(t,r){var e=t.toString().toUpperCase();if(r>0){for(var i=r;e.length>r;)e=t.toPrecision(i--);e.startsWith("0.")?e=e.substr(1):e.startsWith("-0.")&&(e="-"+e.substr(2))}return e}printExpr(t){var r=this.valueToString(t,this.opts.numericPadding);this.column+=r.length,this.print(r)}print(t){console.log(t)}async input(t,r){return{line:"",vals:[]}}resume(){}expr2js(t,r){if(r||(r={}),k(t))return JSON.stringify(t.value);if(y(t)){if(!t.args&&r.locals&&r.locals.indexOf(t.name)>=0)return t.name;{r.isconst&&this.runtimeError("I expected a constant value here.");var e="",i=JSON.stringify(t.name);let h=t.args?t.args.map(o=>this.expr2js(o,r)).join(", "):[];return t.name.startsWith("FN")?e+=`this.getDef(${i})(${h})`:this.builtins[t.name]?(this.checkFuncArgs(t,this.builtins[t.name]),e+=`this.builtins.${t.name}(${h})`):t.args?this.opts.arraysContainChars&&t.name.endsWith("$")?e+=`this.getStringSlice(this.vars.${t.name}, ${h})`:e+=`this.arrayGet(${i}, ${h})`:e+=`this.vars.${t.name}`,r.novalid?e:`this.checkValue(${e}, ${i})`}}else if(O(t)){var n=this.expr2js(t.left,r),s=this.expr2js(t.right,r);return`this.${t.op}(${n}, ${s})`}else if(N(t)){var a=this.expr2js(t.expr,r);return`this.${t.op}(${a})`}}assign2js(t,r){r||(r={});var e="";return(t.name.startsWith("FN")||this.builtins[t.name])&&this.runtimeError("I can't call a function here."),t.args?this.opts.arraysContainChars&&t.name.endsWith("$")?this.runtimeError("I can't set array slices via this command yet."):e+=this.array2js(t,r):e=`this.globals.${t.name}`,e}array2js(t,r){var e=JSON.stringify(t.name),i=t.args||[];return this.expr2js(t,{novalid:!0})+`;this.getArray(${e}, ${i.length})`+i.map(n=>"[this.ROUND("+this.expr2js(n,r)+")]").join("")}checkFuncArgs(t,r){var e=t.args?t.args.length:0;t.name=="RND"&&e==0||t.name=="MID$"&&e==2||t.name=="INSTR"&&e==2||r.length!=e&&this.runtimeError(`I expected ${r.length} arguments for the ${t.name} function, but I got ${e}.`)}startForLoop(t,r,e,i,n){var s=this.curpc-1,a=this.pc2label.get(s);i||(i=1),this.vars[t]=r,this.trace&&console.log(`FOR ${t} = ${r} TO ${e} STEP ${i}`);var h=()=>i>=0?this.vars[t]>e:this.vars[t]o==t)),this.forLoopStack.push(t),this.forLoops[t]={$next:o=>{o&&t!=o&&this.runtimeError(`I executed NEXT "${o}", but the last FOR was for "${t}".`),this.vars[t]+=i;var b=h();b?(this.forLoopStack.pop(),delete this.forLoops[t]):this.curpc=(a!=null&&this.label2pc[a]||s)+1,this.trace&&console.log(`NEXT ${t}: ${this.vars[t]} TO ${e} STEP ${i} DONE=${b}`)}}}nextForLoop(t){var r=this.forLoops[t||this.opts.optionalNextVar&&this.forLoopStack[this.forLoopStack.length-1]];r||this.runtimeError("I couldn't find a matching FOR for this NEXT."),r.$next(t)}whileLoop(t){t?this.whileLoops.push(this.curpc-1):this.skipToAfterWend()}nextWhileLoop(){var t=this.whileLoops.pop();t==null?this.runtimeError("I couldn't find a matching WHILE for this WEND."):this.curpc=t}assign(t,r,e){return e&&t.endsWith("$")?this.checkValue(this.convert(t,r),t):t.endsWith("$")?this.convertToString(r,t):this.convertToNumber(r,t)}convert(t,r){return t.endsWith("$")?r==null?"":r.toString():typeof r=="number"?r:parseFloat(r+"")}convertToString(t,r){if(typeof t!="string")this.runtimeError(`I can't convert ${t} to a string.`);else return t}convertToNumber(t,r){if(typeof t!="number")this.runtimeError(`I can't convert ${t} to a number.`);else return this.checkNum(t)}dimArray(t,...r){if(r=r.map(Math.round),this.arrays[t]!=null){if(this.opts.staticArrays)return;this.runtimeError(`I already dimensioned this array (${t}) earlier.`)}var e=this.getTotalArrayLength(r);e>this.opts.maxArrayElements&&this.runtimeError("I can't create an array with this many elements.");var i=t.endsWith("$"),n=i?Array:Float64Array;if(r.length==1)this.arrays[t]=new n(r[0]+1);else if(r.length==2){this.arrays[t]=new Array(r[0]+1);for(var s=0;s=i.length&&this.runtimeError(`I tried to lookup ${t}(${r}) but it exceeded the dimensions of the array.`),i=i[r[n]]}return c(i)&&this.runtimeError(`I tried to lookup ${t}(${r}) but used too few dimensions.`),i}modifyStringSlice(t,r,e,i){return t=t||"",this.checkString(t),this.checkString(r),i||(i=e),e=this.ROUND(e),i=this.ROUND(i),e<1&&this.dialectError("accept a string slice index less than 1"),ir.length)&&this.runtimeError(`I needed a number between 1 and ${r.length}, but I got ${t}.`),t<1||t>r.length?0:t}onGotoLabel(t,...r){t=this.checkOnGoto(t,r),t&&this.gotoLabel(r[t-1])}onGosubLabel(t,...r){t=this.checkOnGoto(t,r),t&&this.gosubLabel(r[t-1])}nextDatum(){return this.dataptr>=this.datums.length&&this.runtimeError("I tried to READ, but ran out of data."),this.datums[this.dataptr++].value}do__PRINT(t){var r="";for(var e of t.args){var i=this.expr2js(e),n=i.name;r+=`this.printExpr(this.checkValue(${i}, ${JSON.stringify(n)}));`}return r}preInput(){this.running=!1,this.curpc--}postInput(t){t&&this.curpc++,this.running=!0,this.resume()}do__INPUT(t){var r=t.prompt!=null?this.expr2js(t.prompt):'""',e=t.elapsed!=null?this.assign2js(t.elapsed):"let ___",i="";return t.args.forEach((n,s)=>{var a=this.assign2js(n);i+=` var value = this.convert(${JSON.stringify(n.name)}, response.vals[${s}]); @@ -34,4 +34,4 @@ import{b as S}from"./chunk-3FIVEUG2.js";import{u as E}from"./chunk-3GET2PUK.js"; `),this.tty.addtext("*** END OF PROGRAM ***",1),this.tty.showPrintHead(!1)}loadROM(t,r){var e=this.runtime.exited;this.program=r;var i=this.runtime.load(r);this.tty.uppercaseOnly=!0,(!this.hotReload||e||!i)&&this.reset()}getROMExtension(){return".json"}reset(){this.tty.clear(),this.runtime.reset(),this.clock=0,this.transcript=[]}pause(){this.timer.stop()}resume(){this.isBlocked()||(this.animcount=0,this.timer.start())}isBlocked(){return this.tty.waitingfor!=null||this.runtime.exited}isRunning(){return this.timer.isRunning()}getDefaultExtensions(){return[".bas"]}getToolForFilename(){return"basic"}getPresets(){return L}getPC(){return this.runtime.curpc}getSP(){return 4096-this.runtime.returnStack.length}isStable(){return!0}getCPUState(){return{PC:this.getPC(),SP:this.getSP()}}saveState(){return{c:this.getCPUState(),rt:this.runtime.saveState()}}loadState(t){this.runtime.loadState(t)}getDebugTree(){return{CurrentLine:this.runtime.getCurrentLabel(),Variables:this.runtime.vars,Arrays:this.runtime.arrays,Functions:this.runtime.defs,ForLoops:this.runtime.forLoops,WhileLoops:this.runtime.whileLoops,ReturnStack:this.runtime.returnStack,NextDatum:this.runtime.datums[this.runtime.dataptr],Clock:this.clock,Options:this.runtime.opts,Internals:this.runtime}}inspect(t){let r=this.runtime.vars[t];if(r!=null)return`${t} = ${r}`}showHelp(){return"https://8bitworkshop.com/docs/platforms/basic/"}getDebugCategories(){return["Variables"]}getDebugInfo(t,r){switch(t){case"Variables":return this.varsToLongString()}}varsToLongString(){var t="",r=Object.keys(this.runtime.vars);r.sort();for(var e of r){var i=this.runtime.vars[e],n=JSON.stringify(i);n.length>24&&(n=`${n.substr(0,24)}...(${n.length})`),t+=g(e,3)+" = "+n+` `}return t}setupDebug(t){this.onBreakpointHit=t}clearDebug(){this.onBreakpointHit=null,this.debugTrap=null}checkDebugTrap(){return this.debugTrap&&this.debugTrap()?(this.pause(),this.break(),!0):!1}break(){this.onBreakpointHit&&this.onBreakpointHit(this.saveState())}step(){var t=this.clock;this.debugTrap=()=>this.clock>t,this.resume()}stepOver(){var t=this.runtime.getStatement();if(t&&(t.command=="GOSUB"||t.command=="ONGOSUB")){var r=this.getPC()+1;this.runEval(()=>this.getPC()==r)}else this.step()}hasCustomStepOver(){return!0}runUntilReturn(){var t=this.getSP();this.runEval(()=>this.getSP()>t)}runEval(t){this.debugTrap=()=>t(this.getCPUState()),this.resume()}restartAtPC(t){return t=Math.round(t),t>=0&&t9?1:0;r=(s>>4)+(e>>4)+t;let i=r>9?1:0;this.clrOZCS();let x=this.doAdd(s,e);this.setSZ(x);let c=0;return i&&(c|=160),t&&(c|=10),c&&(this.clrOZCS(),x=this.doAdd(x,c),this.setSZ(x)),x}getScratchpadIndex(s){if(s<12)return s;if(s===12)return this.IS&63;if(s===13){let e=this.IS&63;return this.IS=this.IS&56|this.IS+1&7,e}if(s===14){let e=this.IS&63;return this.IS=this.IS&56|this.IS-1&7,e}return 0}advanceInsn(){if(this.irqRequest&&this.W&u)return this.irqRequest=!1,this.PC1=this.PC0,this.PC0=this.bus.read(4094)<<8|this.bus.read(4095),this.W&=~u,6;let s=this.fetchPC0();this.o=s,this.stable=!0;let e=4,r,t;switch(s){case 0:this.A=this.R[12];break;case 1:this.A=this.R[13];break;case 2:this.A=this.R[14];break;case 3:this.A=this.R[15];break;case 4:this.R[12]=this.A;break;case 5:this.R[13]=this.A;break;case 6:this.R[14]=this.A;break;case 7:this.R[15]=this.A;break;case 8:this.R[12]=this.PC1>>8&255,this.R[13]=this.PC1&255,e=8;break;case 9:this.PC1=this.R[12]<<8|this.R[13],e=8;break;case 10:this.A=this.IS&63;break;case 11:this.IS=this.A&63;break;case 12:this.PC1=this.PC0,this.PC0=this.R[12]<<8|this.R[13],e=8;break;case 13:this.PC0=this.R[14]<<8|this.R[15],e=8;break;case 14:this.R[14]=this.DC0>>8&255,this.R[15]=this.DC0&255,e=8;break;case 15:this.DC0=this.R[14]<<8|this.R[15],e=8;break;case 16:this.DC0=this.R[10]<<8|this.R[11],e=8;break;case 17:this.R[10]=this.DC0>>8&255,this.R[11]=this.DC0&255,e=8;break;case 18:this.A=this.A>>1&255,this.clrOZCS(),this.setSZ(this.A);break;case 19:this.A=this.A<<1&255,this.clrOZCS(),this.setSZ(this.A);break;case 20:this.A=this.A>>4&255,this.clrOZCS(),this.setSZ(this.A);break;case 21:this.A=this.A<<4&255,this.clrOZCS(),this.setSZ(this.A);break;case 22:this.A=this.fetchDC0(),e=6;break;case 23:this.storeDC0(this.A),e=6;break;case 24:this.A=~this.A&255,this.clrOZCS(),this.setSZ(this.A);break;case 25:r=this.W&d?1:0,this.clrOZCS(),this.A=this.doAdd(this.A,r),this.setSZ(this.A);break;case 26:this.W&=~u;break;case 27:this.W|=u;break;case 28:this.PC0=this.PC1;break;case 29:this.W=this.R[9]&31;break;case 30:this.R[9]=this.W&31;break;case 31:this.clrOZCS(),this.A=this.doAdd(this.A,1),this.setSZ(this.A);break;case 32:this.A=this.fetchPC0(),e=6;break;case 33:r=this.fetchPC0(),this.A=this.A&r,this.clrOZCS(),this.setSZ(this.A),e=6;break;case 34:r=this.fetchPC0(),this.A=this.A|r,this.clrOZCS(),this.setSZ(this.A),e=6;break;case 35:r=this.fetchPC0(),this.A=this.A^r,this.clrOZCS(),this.setSZ(this.A),e=6;break;case 36:r=this.fetchPC0(),this.clrOZCS(),this.A=this.doAdd(this.A,r),this.setSZ(this.A),e=6;break;case 37:r=this.fetchPC0(),this.clrOZCS(),this.doAdd(~this.A&255,r,1),this.setSZ(this.doAdd(~this.A&255,r,1)),e=6;break;case 38:r=this.fetchPC0(),this.A=this.iobus.read(r)&255,this.clrOZCS(),this.setSZ(this.A),e=8;break;case 39:r=this.fetchPC0(),this.iobus.write(r,this.A),e=8;break;case 40:{let i=this.fetchPC0(),x=this.fetchPC0();this.PC1=this.PC0,this.PC0=i<<8|x,e=12;break}case 41:{let i=this.fetchPC0(),x=this.fetchPC0();this.PC0=i<<8|x,e=10;break}case 42:{let i=this.fetchPC0(),x=this.fetchPC0();this.DC0=i<<8|x,e=10;break}case 43:break;case 44:r=this.DC0,this.DC0=this.DC1,this.DC1=r;break;case 45:case 46:case 47:break;case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:case 58:case 59:case 60:case 61:case 62:t=this.getScratchpadIndex(s&15),this.clrOZCS(),this.R[t]=this.doAdd(this.R[t],255),this.setSZ(this.R[t]),e=6;break;case 63:break;case 64:case 65:case 66:case 67:case 68:case 69:case 70:case 71:case 72:case 73:case 74:case 75:case 76:case 77:case 78:t=this.getScratchpadIndex(s&15),this.A=this.R[t];break;case 79:break;case 80:case 81:case 82:case 83:case 84:case 85:case 86:case 87:case 88:case 89:case 90:case 91:case 92:case 93:case 94:t=this.getScratchpadIndex(s&15),this.R[t]=this.A;break;case 95:break;case 96:case 97:case 98:case 99:case 100:case 101:case 102:case 103:this.IS=this.IS&7|(s&7)<<3;break;case 104:case 105:case 106:case 107:case 108:case 109:case 110:case 111:this.IS=this.IS&56|s&7;break;case 112:case 113:case 114:case 115:case 116:case 117:case 118:case 119:case 120:case 121:case 122:case 123:case 124:case 125:case 126:case 127:this.A=s&15;break;case 128:case 129:case 130:case 131:case 132:case 133:case 134:case 135:{let i=s&7,x=this.fetchPC0();this.W&i&&(this.PC0=this.PC0+(x&128?x-256:x)&65535),e=6;break}case 136:r=this.fetchDC0(),this.clrOZCS(),this.A=this.doAdd(this.A,r),this.setSZ(this.A),e=6;break;case 137:r=this.fetchDC0(),this.A=this.doAddDecimal(this.A,r),e=6;break;case 138:r=this.fetchDC0(),this.A=this.A&r,this.clrOZCS(),this.setSZ(this.A),e=6;break;case 139:r=this.fetchDC0(),this.A=this.A|r,this.clrOZCS(),this.setSZ(this.A),e=6;break;case 140:r=this.fetchDC0(),this.A=this.A^r,this.clrOZCS(),this.setSZ(this.A),e=6;break;case 141:r=this.fetchDC0(),this.clrOZCS();{let i=this.doAdd(~this.A&255,r,1);this.setSZ(i)}e=6;break;case 142:this.DC0=this.DC0+(this.A&128?this.A-256:this.A)&65535,e=6;break;case 143:{let i=this.fetchPC0();(this.IS&7)!==7&&(this.PC0=this.PC0+(i&128?i-256:i)&65535),e=6;break}case 144:case 145:case 146:case 147:case 148:case 149:case 150:case 151:case 152:case 153:case 154:case 155:case 156:case 157:case 158:case 159:{let i=s&15,x=this.fetchPC0();(i===0||!(this.W&i))&&(this.PC0=this.PC0+(x&128?x-256:x)&65535),e=6;break}case 160:case 161:this.A=this.iobus.read(s&1)&255,this.clrOZCS(),this.setSZ(this.A);break;case 162:case 163:break;case 164:case 165:case 166:case 167:case 168:case 169:case 170:case 171:case 172:case 173:case 174:case 175:this.A=this.iobus.read(s&15)&255,this.clrOZCS(),this.setSZ(this.A),e=8;break;case 176:case 177:this.iobus.write(s&1,this.A);break;case 178:case 179:break;case 180:case 181:case 182:case 183:case 184:case 185:case 186:case 187:case 188:case 189:case 190:case 191:this.iobus.write(s&15,this.A),e=8;break;case 192:case 193:case 194:case 195:case 196:case 197:case 198:case 199:case 200:case 201:case 202:case 203:case 204:case 205:case 206:t=this.getScratchpadIndex(s&15),this.clrOZCS(),this.A=this.doAdd(this.A,this.R[t]),this.setSZ(this.A);break;case 207:break;case 208:case 209:case 210:case 211:case 212:case 213:case 214:case 215:case 216:case 217:case 218:case 219:case 220:case 221:case 222:t=this.getScratchpadIndex(s&15),this.A=this.doAddDecimal(this.A,this.R[t]),e=8;break;case 223:break;case 224:case 225:case 226:case 227:case 228:case 229:case 230:case 231:case 232:case 233:case 234:case 235:case 236:case 237:case 238:t=this.getScratchpadIndex(s&15),this.A=(this.A^this.R[t])&255,this.clrOZCS(),this.setSZ(this.A);break;case 239:break;case 240:case 241:case 242:case 243:case 244:case 245:case 246:case 247:case 248:case 249:case 250:case 251:case 252:case 253:case 254:t=this.getScratchpadIndex(s&15),this.A=this.A&this.R[t]&255,this.clrOZCS(),this.setSZ(this.A);break;case 255:break}return e}};var M=[4282927176,4283498320,4283453695,4286611584,4294922320,4283498320,4283453695,4286611584,4282927176,4294922320,4283453695,4286611584,4282927176,4283498320,4294922320,4286611584],B=1,E=2,O=4,Z=8,g=16,v=32,_=64,L=128,C=class extends D{constructor(){super();this.cpuFrequency=1789773;this.defaultROMSize=65536;this.canvasWidth=128;this.numVisibleScanlines=64;this.numTotalScanlines=64;this.cpuCyclesPerLine=this.cpuFrequency/60/64;this.sampleRate=this.cpuFrequency/2;this.cpu=new l;this.ram=new Uint8Array(65536);this.vram=new Uint8Array(8192);this.port0=0;this.port1=0;this.port4=0;this.port5=0;this.row_reg=0;this.col_reg=0;this.color=0;this.soundMode=0;this.soundCounter=0;this.soundEnvelope=0;this.soundOnTime=0;this.read=A([[0,2047,2047,e=>this.bios[e]],[2048,65535,65535,e=>this.rom&&this.rom[e-2048]||0]],{gmask:65535});this.write=A([[10240,12287,2047,(e,r)=>{this.rom&&(this.rom[e-2048]=r)}]],{gmask:65535});this.bios=new Uint8Array(2048),this.connectCPUMemoryBus(this),this.cpu.connectIOBus(this.newIOBus())}newIOBus(){return this.probeIOBus({read:e=>this.readPort(e),write:(e,r)=>{this.writePort(e,r)}})}readPort(e){switch(e&255){case 0:return~this.inputs[0]&255;case 1:return~this.inputs[1]&255;case 4:return~this.inputs[2]&255;default:return 255}}writePort(e,r){switch(e&255){case 0:this.port0=r;break;case 1:this.port1=r,this.col_reg=r;break;case 4:this.port4=r;break;case 5:this.port5=r,this.soundMode=r>>6&3,this.soundMode>0&&(this.soundEnvelope=1023,this.soundOnTime=60),this.row_reg=r&63,this.writePixel();break}}writePixel(){let e=this.row_reg,r=this.col_reg&127;if(e<64&&r<128){let t=this.port1>>6&3,i=e*128+r;this.vram[i]=t}}readConst(e){return e<2048?this.bios[e]:this.rom&&this.rom[e-2048]||0}loadROM(e){this.rom||(this.rom=new Uint8Array(this.defaultROMSize)),this.rom.set(e),this.reset()}loadBIOS(e){this.bios=P(e,2048),this.reset()}reset(){super.reset(),this.vram.fill(0),this.port0=0,this.port1=0,this.port4=0,this.port5=0,this.row_reg=0,this.col_reg=0,this.soundMode=0,this.soundCounter=0,this.soundEnvelope=0}advanceFrame(e){var r=0,t=this.cpuFrequency/60;for(this.probe.logNewFrame();r>1)*4;for(let x=0;x<128;x++){let c=this.vram[e*128+x]&3,o=M[r+c];this.pixels[e*128+x]=o}}}generateAudio(e){if(!this.audio)return;let r=Math.floor(this.sampleRate/60);for(let t=0;t0&&this.soundEnvelope>0){let x;switch(this.soundMode){case 1:x=1e3;break;case 2:x=500;break;case 3:x=120;break;default:x=0}if(x>0){let c=Math.floor(this.sampleRate/x);this.soundCounter=(this.soundCounter+1)%c,i=this.soundCounter0?this.soundOnTime--:(this.soundEnvelope-=2,this.soundEnvelope<0&&(this.soundEnvelope=0))}this.audio.feedSample(i,1)}}setKeyInput(e,r,t){let i=!!(t&1),x=!!(t&64);e===n.VK_1.c&&(i?this.inputs[0]|=1:x&&(this.inputs[0]&=-2)),e===n.VK_2.c&&(i?this.inputs[0]|=2:x&&(this.inputs[0]&=-3)),e===n.VK_3.c&&(i?this.inputs[0]|=4:x&&(this.inputs[0]&=-5)),e===n.VK_4.c&&(i?this.inputs[0]|=8:x&&(this.inputs[0]&=-9)),(e===n.VK_UP.c||e===n.VK_W.c)&&(i?this.inputs[1]|=Z:x&&(this.inputs[1]&=~Z)),(e===n.VK_DOWN.c||e===n.VK_S.c)&&(i?this.inputs[1]|=O:x&&(this.inputs[1]&=~O)),(e===n.VK_LEFT.c||e===n.VK_A.c)&&(i?this.inputs[1]|=E:x&&(this.inputs[1]&=~E)),(e===n.VK_RIGHT.c||e===n.VK_D.c)&&(i?this.inputs[1]|=B:x&&(this.inputs[1]&=~B)),e===n.VK_Q.c&&(i?this.inputs[1]|=g:x&&(this.inputs[1]&=~g)),e===n.VK_E.c&&(i?this.inputs[1]|=v:x&&(this.inputs[1]&=~v)),e===n.VK_R.c&&(i?this.inputs[1]|=L:x&&(this.inputs[1]&=~L)),e===n.VK_F.c&&(i?this.inputs[1]|=_:x&&(this.inputs[1]&=~_))}saveState(){return{c:this.cpu.saveState(),ram:this.ram.slice(0),inputs:this.inputs.slice(0),vram:this.vram.slice(0),port0:this.port0,port1:this.port1,port4:this.port4,port5:this.port5,row_reg:this.row_reg,col_reg:this.col_reg,soundMode:this.soundMode,soundCounter:this.soundCounter,soundEnvelope:this.soundEnvelope}}loadState(e){this.cpu.loadState(e.c),this.ram.set(e.ram),this.inputs.set(e.inputs),this.vram.set(e.vram),this.port0=e.port0,this.port1=e.port1,this.port4=e.port4,this.port5=e.port5,this.row_reg=e.row_reg,this.col_reg=e.col_reg,this.soundMode=e.soundMode,this.soundCounter=e.soundCounter,this.soundEnvelope=e.soundEnvelope}};function F(a){return a<9?"r"+a:a===9?"J":a===10?"HU":a===11?"HL":a===12?"S":a===13?"I":a===14?"D":"?"}function w(a,s,e,r){let t="",i="",x=1,c=!1;if(s<=7){let o=["KU","KL","QU","QL"];s<4?(t="LR",i="A,"+o[s]):(t="LR",i=o[s-4]+",A")}else if(s===8)t="LR",i="K,P";else if(s===9)t="LR",i="P,K";else if(s===10)t="LR",i="A,IS";else if(s===11)t="LR",i="IS,A";else if(s===12)t="PK";else if(s===13)t="LR",i="P0,Q";else if(s===14)t="LR",i="Q,DC";else if(s===15)t="LR",i="DC,Q";else if(s===16)t="LR",i="DC,H";else if(s===17)t="LR",i="H,DC";else if(s===18)t="SR",i="1";else if(s===19)t="SL",i="1";else if(s===20)t="SR",i="4";else if(s===21)t="SL",i="4";else if(s===22)t="LM";else if(s===23)t="ST";else if(s===24)t="COM";else if(s===25)t="LNK";else if(s===26)t="DI";else if(s===27)t="EI";else if(s===28)t="POP";else if(s===29)t="LR",i="W,J";else if(s===30)t="LR",i="J,W";else if(s===31)t="INC";else if(s===32)t="LI",i="$"+h(e,2),x=2;else if(s===33)t="NI",i="$"+h(e,2),x=2;else if(s===34)t="OI",i="$"+h(e,2),x=2;else if(s===35)t="XI",i="$"+h(e,2),x=2;else if(s===36)t="AI",i="$"+h(e,2),x=2;else if(s===37)t="CI",i="$"+h(e,2),x=2;else if(s===38)t="IN",i="$"+h(e,2),x=2;else if(s===39)t="OUT",i="$"+h(e,2),x=2;else if(s===40)t="PI",i="$"+h(e<<8|r,4),x=3,c=!0;else if(s===41)t="JMP",i="$"+h(e<<8|r,4),x=3,c=!0;else if(s===42)t="DCI",i="$"+h(e<<8|r,4),x=3,c=!0;else if(s===43)t="NOP";else if(s===44)t="XDC";else if(s<=47)t="???";else if(s>=48&&s<=62)t="DS",i=F(s&15),x=1;else if(s===63)t="???";else if(s>=64&&s<=78)t="LR",i="A,"+F(s&15);else if(s===79)t="???";else if(s>=80&&s<=94)t="LR",i=F(s&15)+",A";else if(s===95)t="???";else if(s>=96&&s<=103)t="LISU",i=""+(s&7);else if(s>=104&&s<=111)t="LISL",i=""+(s&7);else if(s>=112&&s<=127)t="LIS",i=""+(s&15);else if(s>=128&&s<=135){let o=e&128?a+2+e-256:a+2+e;t="BT",i=""+(s&7)+",$"+h(o&65535,4),x=2,c=!0}else if(s===136)t="AM";else if(s===137)t="AMD";else if(s===138)t="NM";else if(s===139)t="OM";else if(s===140)t="XM";else if(s===141)t="CM";else if(s===142)t="ADC";else if(s===143){let o=e&128?a+2+e-256:a+2+e;t="BR7",i="$"+h(o&65535,4),x=2,c=!0}else if(s>=144&&s<=159){let o=e&128?a+2+e-256:a+2+e,f=s&15;f===0?t="BR":t="BF",f!==0&&(i=""+f+","),i+="$"+h(o&65535,4),x=2,c=!0}else s>=160&&s<=161?(t="INS",i=""+(s&15)):s>=162&&s<=163?t="???":s>=164&&s<=175?(t="INS",i=""+(s&15)):s>=176&&s<=177?(t="OUTS",i=""+(s&15)):s>=178&&s<=179?t="???":s>=180&&s<=191?(t="OUTS",i=""+(s&15)):s>=192&&s<=206?(t="AS",i=F(s&15)):s===207?t="???":s>=208&&s<=222?(t="ASD",i=F(s&15)):s===223?t="???":s>=224&&s<=238?(t="XS",i=F(s&15)):s===239?t="???":s>=240&&s<=254?(t="NS",i=F(s&15)):t="???";return{line:t+(i?" "+i:""),nbytes:x,isaddr:c}}var W=[{id:"hello.dasm",name:"Hello World (ASM)"}];function U(a){return"PC0 = "+h(a.PC0,4)+" PC1 = "+h(a.PC1,4)+` +import{I as R,q as D}from"./chunk-4676AC7I.js";import{$ as P,K as S,W as n,aa as A,g as h,s as p}from"./chunk-TYDI7JZQ.js";import"./chunk-KT7KMEQC.js";var I=1,d=2,k=4,b=8,u=16,l=class{constructor(){this.PC0=0;this.PC1=0;this.DC0=0;this.DC1=0;this.A=0;this.W=0;this.IS=0;this.R=new Uint8Array(64);this.o=0;this.stable=!0;this.irqRequest=!1}connectMemoryBus(s){this.bus=s}connectIOBus(s){this.iobus=s}reset(){this.PC0=0,this.PC1=0,this.DC0=0,this.DC1=0,this.A=0,this.W=0,this.IS=0,this.R.fill(0),this.irqRequest=!1}interrupt(s){this.irqRequest=!0}getPC(){return this.PC0}getSP(){return this.PC1}isStable(){return this.stable}saveState(){return{PC:this.PC0,PC0:this.PC0,PC1:this.PC1,DC0:this.DC0,DC1:this.DC1,A:this.A,W:this.W,IS:this.IS,R:Array.from(this.R),o:this.o,irq:this.irqRequest}}loadState(s){var e;this.PC0=(e=s.PC0)!=null?e:s.PC,this.PC1=s.PC1,this.DC0=s.DC0,this.DC1=s.DC1,this.A=s.A,this.W=s.W,this.IS=s.IS;for(let r=0;r<64;r++)this.R[r]=s.R[r];this.o=s.o,this.irqRequest=s.irq}fetchPC0(){let s=this.bus.read(this.PC0);return this.PC0=this.PC0+1&65535,s}fetchDC0(){let s=this.bus.read(this.DC0);return this.DC0=this.DC0+1&65535,s}storeDC0(s){this.bus.write(this.DC0,s),this.DC0=this.DC0+1&65535}clrOZCS(){this.W&=~(b|k|d|I)}setSZ(s){(s&255)===0&&(this.W|=k),(s&128)===0&&(this.W|=I)}doAdd(s,e,r=0){let t=(s&255)+(e&255)+(r&1);return t&256&&(this.W|=d),((s^t)&(e^t)&128)!==0&&(this.W|=b),t&255}doAddDecimal(s,e){let r=(s&15)+(e&15),t=r>9?1:0;r=(s>>4)+(e>>4)+t;let i=r>9?1:0;this.clrOZCS();let x=this.doAdd(s,e);this.setSZ(x);let c=0;return i&&(c|=160),t&&(c|=10),c&&(this.clrOZCS(),x=this.doAdd(x,c),this.setSZ(x)),x}getScratchpadIndex(s){if(s<12)return s;if(s===12)return this.IS&63;if(s===13){let e=this.IS&63;return this.IS=this.IS&56|this.IS+1&7,e}if(s===14){let e=this.IS&63;return this.IS=this.IS&56|this.IS-1&7,e}return 0}advanceInsn(){if(this.irqRequest&&this.W&u)return this.irqRequest=!1,this.PC1=this.PC0,this.PC0=this.bus.read(4094)<<8|this.bus.read(4095),this.W&=~u,6;let s=this.fetchPC0();this.o=s,this.stable=!0;let e=4,r,t;switch(s){case 0:this.A=this.R[12];break;case 1:this.A=this.R[13];break;case 2:this.A=this.R[14];break;case 3:this.A=this.R[15];break;case 4:this.R[12]=this.A;break;case 5:this.R[13]=this.A;break;case 6:this.R[14]=this.A;break;case 7:this.R[15]=this.A;break;case 8:this.R[12]=this.PC1>>8&255,this.R[13]=this.PC1&255,e=8;break;case 9:this.PC1=this.R[12]<<8|this.R[13],e=8;break;case 10:this.A=this.IS&63;break;case 11:this.IS=this.A&63;break;case 12:this.PC1=this.PC0,this.PC0=this.R[12]<<8|this.R[13],e=8;break;case 13:this.PC0=this.R[14]<<8|this.R[15],e=8;break;case 14:this.R[14]=this.DC0>>8&255,this.R[15]=this.DC0&255,e=8;break;case 15:this.DC0=this.R[14]<<8|this.R[15],e=8;break;case 16:this.DC0=this.R[10]<<8|this.R[11],e=8;break;case 17:this.R[10]=this.DC0>>8&255,this.R[11]=this.DC0&255,e=8;break;case 18:this.A=this.A>>1&255,this.clrOZCS(),this.setSZ(this.A);break;case 19:this.A=this.A<<1&255,this.clrOZCS(),this.setSZ(this.A);break;case 20:this.A=this.A>>4&255,this.clrOZCS(),this.setSZ(this.A);break;case 21:this.A=this.A<<4&255,this.clrOZCS(),this.setSZ(this.A);break;case 22:this.A=this.fetchDC0(),e=6;break;case 23:this.storeDC0(this.A),e=6;break;case 24:this.A=~this.A&255,this.clrOZCS(),this.setSZ(this.A);break;case 25:r=this.W&d?1:0,this.clrOZCS(),this.A=this.doAdd(this.A,r),this.setSZ(this.A);break;case 26:this.W&=~u;break;case 27:this.W|=u;break;case 28:this.PC0=this.PC1;break;case 29:this.W=this.R[9]&31;break;case 30:this.R[9]=this.W&31;break;case 31:this.clrOZCS(),this.A=this.doAdd(this.A,1),this.setSZ(this.A);break;case 32:this.A=this.fetchPC0(),e=6;break;case 33:r=this.fetchPC0(),this.A=this.A&r,this.clrOZCS(),this.setSZ(this.A),e=6;break;case 34:r=this.fetchPC0(),this.A=this.A|r,this.clrOZCS(),this.setSZ(this.A),e=6;break;case 35:r=this.fetchPC0(),this.A=this.A^r,this.clrOZCS(),this.setSZ(this.A),e=6;break;case 36:r=this.fetchPC0(),this.clrOZCS(),this.A=this.doAdd(this.A,r),this.setSZ(this.A),e=6;break;case 37:r=this.fetchPC0(),this.clrOZCS(),this.doAdd(~this.A&255,r,1),this.setSZ(this.doAdd(~this.A&255,r,1)),e=6;break;case 38:r=this.fetchPC0(),this.A=this.iobus.read(r)&255,this.clrOZCS(),this.setSZ(this.A),e=8;break;case 39:r=this.fetchPC0(),this.iobus.write(r,this.A),e=8;break;case 40:{let i=this.fetchPC0(),x=this.fetchPC0();this.PC1=this.PC0,this.PC0=i<<8|x,e=12;break}case 41:{let i=this.fetchPC0(),x=this.fetchPC0();this.PC0=i<<8|x,e=10;break}case 42:{let i=this.fetchPC0(),x=this.fetchPC0();this.DC0=i<<8|x,e=10;break}case 43:break;case 44:r=this.DC0,this.DC0=this.DC1,this.DC1=r;break;case 45:case 46:case 47:break;case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:case 58:case 59:case 60:case 61:case 62:t=this.getScratchpadIndex(s&15),this.clrOZCS(),this.R[t]=this.doAdd(this.R[t],255),this.setSZ(this.R[t]),e=6;break;case 63:break;case 64:case 65:case 66:case 67:case 68:case 69:case 70:case 71:case 72:case 73:case 74:case 75:case 76:case 77:case 78:t=this.getScratchpadIndex(s&15),this.A=this.R[t];break;case 79:break;case 80:case 81:case 82:case 83:case 84:case 85:case 86:case 87:case 88:case 89:case 90:case 91:case 92:case 93:case 94:t=this.getScratchpadIndex(s&15),this.R[t]=this.A;break;case 95:break;case 96:case 97:case 98:case 99:case 100:case 101:case 102:case 103:this.IS=this.IS&7|(s&7)<<3;break;case 104:case 105:case 106:case 107:case 108:case 109:case 110:case 111:this.IS=this.IS&56|s&7;break;case 112:case 113:case 114:case 115:case 116:case 117:case 118:case 119:case 120:case 121:case 122:case 123:case 124:case 125:case 126:case 127:this.A=s&15;break;case 128:case 129:case 130:case 131:case 132:case 133:case 134:case 135:{let i=s&7,x=this.fetchPC0();this.W&i&&(this.PC0=this.PC0+(x&128?x-256:x)&65535),e=6;break}case 136:r=this.fetchDC0(),this.clrOZCS(),this.A=this.doAdd(this.A,r),this.setSZ(this.A),e=6;break;case 137:r=this.fetchDC0(),this.A=this.doAddDecimal(this.A,r),e=6;break;case 138:r=this.fetchDC0(),this.A=this.A&r,this.clrOZCS(),this.setSZ(this.A),e=6;break;case 139:r=this.fetchDC0(),this.A=this.A|r,this.clrOZCS(),this.setSZ(this.A),e=6;break;case 140:r=this.fetchDC0(),this.A=this.A^r,this.clrOZCS(),this.setSZ(this.A),e=6;break;case 141:r=this.fetchDC0(),this.clrOZCS();{let i=this.doAdd(~this.A&255,r,1);this.setSZ(i)}e=6;break;case 142:this.DC0=this.DC0+(this.A&128?this.A-256:this.A)&65535,e=6;break;case 143:{let i=this.fetchPC0();(this.IS&7)!==7&&(this.PC0=this.PC0+(i&128?i-256:i)&65535),e=6;break}case 144:case 145:case 146:case 147:case 148:case 149:case 150:case 151:case 152:case 153:case 154:case 155:case 156:case 157:case 158:case 159:{let i=s&15,x=this.fetchPC0();(i===0||!(this.W&i))&&(this.PC0=this.PC0+(x&128?x-256:x)&65535),e=6;break}case 160:case 161:this.A=this.iobus.read(s&1)&255,this.clrOZCS(),this.setSZ(this.A);break;case 162:case 163:break;case 164:case 165:case 166:case 167:case 168:case 169:case 170:case 171:case 172:case 173:case 174:case 175:this.A=this.iobus.read(s&15)&255,this.clrOZCS(),this.setSZ(this.A),e=8;break;case 176:case 177:this.iobus.write(s&1,this.A);break;case 178:case 179:break;case 180:case 181:case 182:case 183:case 184:case 185:case 186:case 187:case 188:case 189:case 190:case 191:this.iobus.write(s&15,this.A),e=8;break;case 192:case 193:case 194:case 195:case 196:case 197:case 198:case 199:case 200:case 201:case 202:case 203:case 204:case 205:case 206:t=this.getScratchpadIndex(s&15),this.clrOZCS(),this.A=this.doAdd(this.A,this.R[t]),this.setSZ(this.A);break;case 207:break;case 208:case 209:case 210:case 211:case 212:case 213:case 214:case 215:case 216:case 217:case 218:case 219:case 220:case 221:case 222:t=this.getScratchpadIndex(s&15),this.A=this.doAddDecimal(this.A,this.R[t]),e=8;break;case 223:break;case 224:case 225:case 226:case 227:case 228:case 229:case 230:case 231:case 232:case 233:case 234:case 235:case 236:case 237:case 238:t=this.getScratchpadIndex(s&15),this.A=(this.A^this.R[t])&255,this.clrOZCS(),this.setSZ(this.A);break;case 239:break;case 240:case 241:case 242:case 243:case 244:case 245:case 246:case 247:case 248:case 249:case 250:case 251:case 252:case 253:case 254:t=this.getScratchpadIndex(s&15),this.A=this.A&this.R[t]&255,this.clrOZCS(),this.setSZ(this.A);break;case 255:break}return e}};var M=[4282927176,4283498320,4283453695,4286611584,4294922320,4283498320,4283453695,4286611584,4282927176,4294922320,4283453695,4286611584,4282927176,4283498320,4294922320,4286611584],B=1,E=2,O=4,Z=8,g=16,v=32,_=64,L=128,C=class extends D{constructor(){super();this.cpuFrequency=1789773;this.defaultROMSize=65536;this.canvasWidth=128;this.numVisibleScanlines=64;this.numTotalScanlines=64;this.cpuCyclesPerLine=this.cpuFrequency/60/64;this.sampleRate=this.cpuFrequency/2;this.cpu=new l;this.ram=new Uint8Array(65536);this.vram=new Uint8Array(8192);this.port0=0;this.port1=0;this.port4=0;this.port5=0;this.row_reg=0;this.col_reg=0;this.color=0;this.soundMode=0;this.soundCounter=0;this.soundEnvelope=0;this.soundOnTime=0;this.read=A([[0,2047,2047,e=>this.bios[e]],[2048,65535,65535,e=>this.rom&&this.rom[e-2048]||0]],{gmask:65535});this.write=A([[10240,12287,2047,(e,r)=>{this.rom&&(this.rom[e-2048]=r)}]],{gmask:65535});this.bios=new Uint8Array(2048),this.connectCPUMemoryBus(this),this.cpu.connectIOBus(this.newIOBus())}newIOBus(){return this.probeIOBus({read:e=>this.readPort(e),write:(e,r)=>{this.writePort(e,r)}})}readPort(e){switch(e&255){case 0:return~this.inputs[0]&255;case 1:return~this.inputs[1]&255;case 4:return~this.inputs[2]&255;default:return 255}}writePort(e,r){switch(e&255){case 0:this.port0=r;break;case 1:this.port1=r,this.col_reg=r;break;case 4:this.port4=r;break;case 5:this.port5=r,this.soundMode=r>>6&3,this.soundMode>0&&(this.soundEnvelope=1023,this.soundOnTime=60),this.row_reg=r&63,this.writePixel();break}}writePixel(){let e=this.row_reg,r=this.col_reg&127;if(e<64&&r<128){let t=this.port1>>6&3,i=e*128+r;this.vram[i]=t}}readConst(e){return e<2048?this.bios[e]:this.rom&&this.rom[e-2048]||0}loadROM(e){this.rom||(this.rom=new Uint8Array(this.defaultROMSize)),this.rom.set(e),this.reset()}loadBIOS(e){this.bios=P(e,2048),this.reset()}reset(){super.reset(),this.vram.fill(0),this.port0=0,this.port1=0,this.port4=0,this.port5=0,this.row_reg=0,this.col_reg=0,this.soundMode=0,this.soundCounter=0,this.soundEnvelope=0}advanceFrame(e){var r=0,t=this.cpuFrequency/60;for(this.probe.logNewFrame();r>1)*4;for(let x=0;x<128;x++){let c=this.vram[e*128+x]&3,o=M[r+c];this.pixels[e*128+x]=o}}}generateAudio(e){if(!this.audio)return;let r=Math.floor(this.sampleRate/60);for(let t=0;t0&&this.soundEnvelope>0){let x;switch(this.soundMode){case 1:x=1e3;break;case 2:x=500;break;case 3:x=120;break;default:x=0}if(x>0){let c=Math.floor(this.sampleRate/x);this.soundCounter=(this.soundCounter+1)%c,i=this.soundCounter0?this.soundOnTime--:(this.soundEnvelope-=2,this.soundEnvelope<0&&(this.soundEnvelope=0))}this.audio.feedSample(i,1)}}setKeyInput(e,r,t){let i=!!(t&1),x=!!(t&64);e===n.VK_1.c&&(i?this.inputs[0]|=1:x&&(this.inputs[0]&=-2)),e===n.VK_2.c&&(i?this.inputs[0]|=2:x&&(this.inputs[0]&=-3)),e===n.VK_3.c&&(i?this.inputs[0]|=4:x&&(this.inputs[0]&=-5)),e===n.VK_4.c&&(i?this.inputs[0]|=8:x&&(this.inputs[0]&=-9)),(e===n.VK_UP.c||e===n.VK_W.c)&&(i?this.inputs[1]|=Z:x&&(this.inputs[1]&=~Z)),(e===n.VK_DOWN.c||e===n.VK_S.c)&&(i?this.inputs[1]|=O:x&&(this.inputs[1]&=~O)),(e===n.VK_LEFT.c||e===n.VK_A.c)&&(i?this.inputs[1]|=E:x&&(this.inputs[1]&=~E)),(e===n.VK_RIGHT.c||e===n.VK_D.c)&&(i?this.inputs[1]|=B:x&&(this.inputs[1]&=~B)),e===n.VK_Q.c&&(i?this.inputs[1]|=g:x&&(this.inputs[1]&=~g)),e===n.VK_E.c&&(i?this.inputs[1]|=v:x&&(this.inputs[1]&=~v)),e===n.VK_R.c&&(i?this.inputs[1]|=L:x&&(this.inputs[1]&=~L)),e===n.VK_F.c&&(i?this.inputs[1]|=_:x&&(this.inputs[1]&=~_))}saveState(){return{c:this.cpu.saveState(),ram:this.ram.slice(0),inputs:this.inputs.slice(0),vram:this.vram.slice(0),port0:this.port0,port1:this.port1,port4:this.port4,port5:this.port5,row_reg:this.row_reg,col_reg:this.col_reg,soundMode:this.soundMode,soundCounter:this.soundCounter,soundEnvelope:this.soundEnvelope}}loadState(e){this.cpu.loadState(e.c),this.ram.set(e.ram),this.inputs.set(e.inputs),this.vram.set(e.vram),this.port0=e.port0,this.port1=e.port1,this.port4=e.port4,this.port5=e.port5,this.row_reg=e.row_reg,this.col_reg=e.col_reg,this.soundMode=e.soundMode,this.soundCounter=e.soundCounter,this.soundEnvelope=e.soundEnvelope}};function F(a){return a<9?"r"+a:a===9?"J":a===10?"HU":a===11?"HL":a===12?"S":a===13?"I":a===14?"D":"?"}function w(a,s,e,r){let t="",i="",x=1,c=!1;if(s<=7){let o=["KU","KL","QU","QL"];s<4?(t="LR",i="A,"+o[s]):(t="LR",i=o[s-4]+",A")}else if(s===8)t="LR",i="K,P";else if(s===9)t="LR",i="P,K";else if(s===10)t="LR",i="A,IS";else if(s===11)t="LR",i="IS,A";else if(s===12)t="PK";else if(s===13)t="LR",i="P0,Q";else if(s===14)t="LR",i="Q,DC";else if(s===15)t="LR",i="DC,Q";else if(s===16)t="LR",i="DC,H";else if(s===17)t="LR",i="H,DC";else if(s===18)t="SR",i="1";else if(s===19)t="SL",i="1";else if(s===20)t="SR",i="4";else if(s===21)t="SL",i="4";else if(s===22)t="LM";else if(s===23)t="ST";else if(s===24)t="COM";else if(s===25)t="LNK";else if(s===26)t="DI";else if(s===27)t="EI";else if(s===28)t="POP";else if(s===29)t="LR",i="W,J";else if(s===30)t="LR",i="J,W";else if(s===31)t="INC";else if(s===32)t="LI",i="$"+h(e,2),x=2;else if(s===33)t="NI",i="$"+h(e,2),x=2;else if(s===34)t="OI",i="$"+h(e,2),x=2;else if(s===35)t="XI",i="$"+h(e,2),x=2;else if(s===36)t="AI",i="$"+h(e,2),x=2;else if(s===37)t="CI",i="$"+h(e,2),x=2;else if(s===38)t="IN",i="$"+h(e,2),x=2;else if(s===39)t="OUT",i="$"+h(e,2),x=2;else if(s===40)t="PI",i="$"+h(e<<8|r,4),x=3,c=!0;else if(s===41)t="JMP",i="$"+h(e<<8|r,4),x=3,c=!0;else if(s===42)t="DCI",i="$"+h(e<<8|r,4),x=3,c=!0;else if(s===43)t="NOP";else if(s===44)t="XDC";else if(s<=47)t="???";else if(s>=48&&s<=62)t="DS",i=F(s&15),x=1;else if(s===63)t="???";else if(s>=64&&s<=78)t="LR",i="A,"+F(s&15);else if(s===79)t="???";else if(s>=80&&s<=94)t="LR",i=F(s&15)+",A";else if(s===95)t="???";else if(s>=96&&s<=103)t="LISU",i=""+(s&7);else if(s>=104&&s<=111)t="LISL",i=""+(s&7);else if(s>=112&&s<=127)t="LIS",i=""+(s&15);else if(s>=128&&s<=135){let o=e&128?a+2+e-256:a+2+e;t="BT",i=""+(s&7)+",$"+h(o&65535,4),x=2,c=!0}else if(s===136)t="AM";else if(s===137)t="AMD";else if(s===138)t="NM";else if(s===139)t="OM";else if(s===140)t="XM";else if(s===141)t="CM";else if(s===142)t="ADC";else if(s===143){let o=e&128?a+2+e-256:a+2+e;t="BR7",i="$"+h(o&65535,4),x=2,c=!0}else if(s>=144&&s<=159){let o=e&128?a+2+e-256:a+2+e,f=s&15;f===0?t="BR":t="BF",f!==0&&(i=""+f+","),i+="$"+h(o&65535,4),x=2,c=!0}else s>=160&&s<=161?(t="INS",i=""+(s&15)):s>=162&&s<=163?t="???":s>=164&&s<=175?(t="INS",i=""+(s&15)):s>=176&&s<=177?(t="OUTS",i=""+(s&15)):s>=178&&s<=179?t="???":s>=180&&s<=191?(t="OUTS",i=""+(s&15)):s>=192&&s<=206?(t="AS",i=F(s&15)):s===207?t="???":s>=208&&s<=222?(t="ASD",i=F(s&15)):s===223?t="???":s>=224&&s<=238?(t="XS",i=F(s&15)):s===239?t="???":s>=240&&s<=254?(t="NS",i=F(s&15)):t="???";return{line:t+(i?" "+i:""),nbytes:x,isaddr:c}}var W=[{id:"hello.dasm",name:"Hello World (ASM)"}];function U(a){return"PC0 = "+h(a.PC0,4)+" PC1 = "+h(a.PC1,4)+` DC0 = `+h(a.DC0,4)+" DC1 = "+h(a.DC1,4)+` A = `+h(a.A,2)+" W = "+h(a.W,2)+` IS = `+h(a.IS,2)+` @@ -14,4 +14,4 @@ Port 5: `+h(e.port5||0,2)+` Row: `+h(e.row_reg||0,2)+` Col: `+h(e.col_reg||0,2)+` `;case"VRAM":return"";default:return""}}getMemoryMap(){return{main:[{name:"BIOS",start:0,size:2048,type:"rom"},{name:"Cart ROM",start:2048,size:30720,type:"rom"}]}}};S.channelf=m; -//# sourceMappingURL=channelf-BJMZSFKB.js.map +//# sourceMappingURL=channelf-AQGDMKUF.js.map diff --git a/gen/channelf-BJMZSFKB.js.map b/gen/channelf-AQGDMKUF.js.map similarity index 100% rename from gen/channelf-BJMZSFKB.js.map rename to gen/channelf-AQGDMKUF.js.map diff --git a/gen/chunk-3GET2PUK.js.map b/gen/chunk-3GET2PUK.js.map deleted file mode 100644 index 2c4e6daa..00000000 --- a/gen/chunk-3GET2PUK.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../node_modules/localforage/dist/localforage.js", "../node_modules/dompurify/src/utils.ts", "../node_modules/dompurify/src/tags.ts", "../node_modules/dompurify/src/attrs.ts", "../node_modules/dompurify/src/regexp.ts", "../node_modules/dompurify/src/purify.ts", "../src/ide/ui.ts", "../src/common/toolmeta.ts", "../src/ide/errorreport.ts", "../src/ide/dialogs.ts", "../node_modules/@marijn/find-cluster-break/src/index.js", "../node_modules/@codemirror/state/dist/index.js", "../node_modules/style-mod/src/style-mod.js", "../node_modules/w3c-keyname/index.js", "../node_modules/crelt/index.js", "../node_modules/@codemirror/view/dist/index.js", "../node_modules/@lezer/common/dist/index.js", "../node_modules/@lezer/highlight/dist/index.js", "../node_modules/@codemirror/language/dist/index.js", "../node_modules/@codemirror/autocomplete/dist/index.js", "../src/ide/views/debug.ts", "../node_modules/@codemirror/commands/dist/index.js", "../src/ide/views/tabs.ts", "../src/ide/settings.ts", "../src/ide/storage.ts", "../src/ide/project.ts", "../src/common/workertypes.ts", "../src/ide/services.ts", "../src/common/audio/CommodoreTape.ts", "../src/ide/shareexport.ts", "../src/ide/sync.ts", "../src/ide/search/symbolindex.ts", "../src/common/symbols/index.ts", "../src/ide/search/projectsource.ts", "../src/ide/search/toolchainsource.ts", "../src/ide/search/docssource.ts", "../src/ide/search/service.ts", "../node_modules/@lezer/lr/dist/index.js", "../node_modules/@lezer/cpp/dist/index.js", "../node_modules/@codemirror/lang-cpp/dist/index.js", "../node_modules/@codemirror/search/dist/index.js", "../src/parser/tokens-6502.ts", "parser/lang-6502.grammar.js", "../src/parser/lang-6502.ts", "../src/parser/tokens-z80.ts", "parser/lang-z80.grammar.js", "../src/parser/lang-z80.ts", "../src/parser/lang-wiz.ts", "../src/parser/lang-verilog.ts", "../src/parser/lang-inform6.ts", "../src/parser/lang-dialog.ts", "../src/parser/lang-basic.ts", "../src/parser/lang-fastbasic.ts", "../src/parser/lang-bataribasic.ts", "../node_modules/@lezer/markdown/dist/index.js", "../node_modules/@lezer/html/dist/index.js", "../node_modules/@lezer/css/dist/index.js", "../node_modules/@codemirror/lang-css/dist/index.js", "../node_modules/@lezer/javascript/dist/index.js", "../node_modules/@codemirror/lang-javascript/dist/index.js", "../node_modules/@codemirror/lang-html/dist/index.js", "../node_modules/@codemirror/lang-markdown/dist/index.js", "../src/parser/registry.ts", "../src/themes/cobalt.ts", "../src/themes/disassemblyTheme.ts", "../src/themes/editorTheme.ts", "../src/themes/mbo.ts", "../src/ide/views/assetdecorations.ts", "../src/ide/views/includedecorations.ts", "../src/ide/views/baseviews.ts", "../src/ide/views/filters.ts", "../src/ide/views/gutter.ts", "../src/ide/views/visuals.ts", "../src/ide/views/editors.ts", "../src/common/vtextscroller.ts", "../src/ide/views/debugviews.ts", "../src/ide/search/debuggerhit.ts", "../src/ide/search/searchview.ts", "../src/ide/pixeleditor.ts", "../src/ide/views/asseteditor.ts", "../src/ide/views/treeviews.ts", "../src/ide/windows.ts"], - "sourcesContent": ["/*!\n localForage -- Offline Storage, Improved\n Version 1.10.0\n https://localforage.github.io/localForage\n (c) 2013-2017 Mozilla, Apache License 2.0\n*/\n(function(f){if(typeof exports===\"object\"&&typeof module!==\"undefined\"){module.exports=f()}else if(typeof define===\"function\"&&define.amd){define([],f)}else{var g;if(typeof window!==\"undefined\"){g=window}else if(typeof global!==\"undefined\"){g=global}else if(typeof self!==\"undefined\"){g=self}else{g=this}g.localforage = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw (f.code=\"MODULE_NOT_FOUND\", f)}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"&&require;for(var o=0;o element; its readystatechange event will be fired asynchronously once it is inserted\n // into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.\n var scriptEl = global.document.createElement('script');\n scriptEl.onreadystatechange = function () {\n nextTick();\n\n scriptEl.onreadystatechange = null;\n scriptEl.parentNode.removeChild(scriptEl);\n scriptEl = null;\n };\n global.document.documentElement.appendChild(scriptEl);\n };\n } else {\n scheduleDrain = function () {\n setTimeout(nextTick, 0);\n };\n }\n}\n\nvar draining;\nvar queue = [];\n//named nextTick for less confusing stack traces\nfunction nextTick() {\n draining = true;\n var i, oldQueue;\n var len = queue.length;\n while (len) {\n oldQueue = queue;\n queue = [];\n i = -1;\n while (++i < len) {\n oldQueue[i]();\n }\n len = queue.length;\n }\n draining = false;\n}\n\nmodule.exports = immediate;\nfunction immediate(task) {\n if (queue.push(task) === 1 && !draining) {\n scheduleDrain();\n }\n}\n\n}).call(this,typeof global !== \"undefined\" ? global : typeof self !== \"undefined\" ? self : typeof window !== \"undefined\" ? window : {})\n},{}],2:[function(_dereq_,module,exports){\n'use strict';\nvar immediate = _dereq_(1);\n\n/* istanbul ignore next */\nfunction INTERNAL() {}\n\nvar handlers = {};\n\nvar REJECTED = ['REJECTED'];\nvar FULFILLED = ['FULFILLED'];\nvar PENDING = ['PENDING'];\n\nmodule.exports = Promise;\n\nfunction Promise(resolver) {\n if (typeof resolver !== 'function') {\n throw new TypeError('resolver must be a function');\n }\n this.state = PENDING;\n this.queue = [];\n this.outcome = void 0;\n if (resolver !== INTERNAL) {\n safelyResolveThenable(this, resolver);\n }\n}\n\nPromise.prototype[\"catch\"] = function (onRejected) {\n return this.then(null, onRejected);\n};\nPromise.prototype.then = function (onFulfilled, onRejected) {\n if (typeof onFulfilled !== 'function' && this.state === FULFILLED ||\n typeof onRejected !== 'function' && this.state === REJECTED) {\n return this;\n }\n var promise = new this.constructor(INTERNAL);\n if (this.state !== PENDING) {\n var resolver = this.state === FULFILLED ? onFulfilled : onRejected;\n unwrap(promise, resolver, this.outcome);\n } else {\n this.queue.push(new QueueItem(promise, onFulfilled, onRejected));\n }\n\n return promise;\n};\nfunction QueueItem(promise, onFulfilled, onRejected) {\n this.promise = promise;\n if (typeof onFulfilled === 'function') {\n this.onFulfilled = onFulfilled;\n this.callFulfilled = this.otherCallFulfilled;\n }\n if (typeof onRejected === 'function') {\n this.onRejected = onRejected;\n this.callRejected = this.otherCallRejected;\n }\n}\nQueueItem.prototype.callFulfilled = function (value) {\n handlers.resolve(this.promise, value);\n};\nQueueItem.prototype.otherCallFulfilled = function (value) {\n unwrap(this.promise, this.onFulfilled, value);\n};\nQueueItem.prototype.callRejected = function (value) {\n handlers.reject(this.promise, value);\n};\nQueueItem.prototype.otherCallRejected = function (value) {\n unwrap(this.promise, this.onRejected, value);\n};\n\nfunction unwrap(promise, func, value) {\n immediate(function () {\n var returnValue;\n try {\n returnValue = func(value);\n } catch (e) {\n return handlers.reject(promise, e);\n }\n if (returnValue === promise) {\n handlers.reject(promise, new TypeError('Cannot resolve promise with itself'));\n } else {\n handlers.resolve(promise, returnValue);\n }\n });\n}\n\nhandlers.resolve = function (self, value) {\n var result = tryCatch(getThen, value);\n if (result.status === 'error') {\n return handlers.reject(self, result.value);\n }\n var thenable = result.value;\n\n if (thenable) {\n safelyResolveThenable(self, thenable);\n } else {\n self.state = FULFILLED;\n self.outcome = value;\n var i = -1;\n var len = self.queue.length;\n while (++i < len) {\n self.queue[i].callFulfilled(value);\n }\n }\n return self;\n};\nhandlers.reject = function (self, error) {\n self.state = REJECTED;\n self.outcome = error;\n var i = -1;\n var len = self.queue.length;\n while (++i < len) {\n self.queue[i].callRejected(error);\n }\n return self;\n};\n\nfunction getThen(obj) {\n // Make sure we only access the accessor once as required by the spec\n var then = obj && obj.then;\n if (obj && (typeof obj === 'object' || typeof obj === 'function') && typeof then === 'function') {\n return function appyThen() {\n then.apply(obj, arguments);\n };\n }\n}\n\nfunction safelyResolveThenable(self, thenable) {\n // Either fulfill, reject or reject with error\n var called = false;\n function onError(value) {\n if (called) {\n return;\n }\n called = true;\n handlers.reject(self, value);\n }\n\n function onSuccess(value) {\n if (called) {\n return;\n }\n called = true;\n handlers.resolve(self, value);\n }\n\n function tryToUnwrap() {\n thenable(onSuccess, onError);\n }\n\n var result = tryCatch(tryToUnwrap);\n if (result.status === 'error') {\n onError(result.value);\n }\n}\n\nfunction tryCatch(func, value) {\n var out = {};\n try {\n out.value = func(value);\n out.status = 'success';\n } catch (e) {\n out.status = 'error';\n out.value = e;\n }\n return out;\n}\n\nPromise.resolve = resolve;\nfunction resolve(value) {\n if (value instanceof this) {\n return value;\n }\n return handlers.resolve(new this(INTERNAL), value);\n}\n\nPromise.reject = reject;\nfunction reject(reason) {\n var promise = new this(INTERNAL);\n return handlers.reject(promise, reason);\n}\n\nPromise.all = all;\nfunction all(iterable) {\n var self = this;\n if (Object.prototype.toString.call(iterable) !== '[object Array]') {\n return this.reject(new TypeError('must be an array'));\n }\n\n var len = iterable.length;\n var called = false;\n if (!len) {\n return this.resolve([]);\n }\n\n var values = new Array(len);\n var resolved = 0;\n var i = -1;\n var promise = new this(INTERNAL);\n\n while (++i < len) {\n allResolver(iterable[i], i);\n }\n return promise;\n function allResolver(value, i) {\n self.resolve(value).then(resolveFromAll, function (error) {\n if (!called) {\n called = true;\n handlers.reject(promise, error);\n }\n });\n function resolveFromAll(outValue) {\n values[i] = outValue;\n if (++resolved === len && !called) {\n called = true;\n handlers.resolve(promise, values);\n }\n }\n }\n}\n\nPromise.race = race;\nfunction race(iterable) {\n var self = this;\n if (Object.prototype.toString.call(iterable) !== '[object Array]') {\n return this.reject(new TypeError('must be an array'));\n }\n\n var len = iterable.length;\n var called = false;\n if (!len) {\n return this.resolve([]);\n }\n\n var i = -1;\n var promise = new this(INTERNAL);\n\n while (++i < len) {\n resolver(iterable[i]);\n }\n return promise;\n function resolver(value) {\n self.resolve(value).then(function (response) {\n if (!called) {\n called = true;\n handlers.resolve(promise, response);\n }\n }, function (error) {\n if (!called) {\n called = true;\n handlers.reject(promise, error);\n }\n });\n }\n}\n\n},{\"1\":1}],3:[function(_dereq_,module,exports){\n(function (global){\n'use strict';\nif (typeof global.Promise !== 'function') {\n global.Promise = _dereq_(2);\n}\n\n}).call(this,typeof global !== \"undefined\" ? global : typeof self !== \"undefined\" ? self : typeof window !== \"undefined\" ? window : {})\n},{\"2\":2}],4:[function(_dereq_,module,exports){\n'use strict';\n\nvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; };\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction getIDB() {\n /* global indexedDB,webkitIndexedDB,mozIndexedDB,OIndexedDB,msIndexedDB */\n try {\n if (typeof indexedDB !== 'undefined') {\n return indexedDB;\n }\n if (typeof webkitIndexedDB !== 'undefined') {\n return webkitIndexedDB;\n }\n if (typeof mozIndexedDB !== 'undefined') {\n return mozIndexedDB;\n }\n if (typeof OIndexedDB !== 'undefined') {\n return OIndexedDB;\n }\n if (typeof msIndexedDB !== 'undefined') {\n return msIndexedDB;\n }\n } catch (e) {\n return;\n }\n}\n\nvar idb = getIDB();\n\nfunction isIndexedDBValid() {\n try {\n // Initialize IndexedDB; fall back to vendor-prefixed versions\n // if needed.\n if (!idb || !idb.open) {\n return false;\n }\n // We mimic PouchDB here;\n //\n // We test for openDatabase because IE Mobile identifies itself\n // as Safari. Oh the lulz...\n var isSafari = typeof openDatabase !== 'undefined' && /(Safari|iPhone|iPad|iPod)/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent) && !/BlackBerry/.test(navigator.platform);\n\n var hasFetch = typeof fetch === 'function' && fetch.toString().indexOf('[native code') !== -1;\n\n // Safari <10.1 does not meet our requirements for IDB support\n // (see: https://github.com/pouchdb/pouchdb/issues/5572).\n // Safari 10.1 shipped with fetch, we can use that to detect it.\n // Note: this creates issues with `window.fetch` polyfills and\n // overrides; see:\n // https://github.com/localForage/localForage/issues/856\n return (!isSafari || hasFetch) && typeof indexedDB !== 'undefined' &&\n // some outdated implementations of IDB that appear on Samsung\n // and HTC Android devices <4.4 are missing IDBKeyRange\n // See: https://github.com/mozilla/localForage/issues/128\n // See: https://github.com/mozilla/localForage/issues/272\n typeof IDBKeyRange !== 'undefined';\n } catch (e) {\n return false;\n }\n}\n\n// Abstracts constructing a Blob object, so it also works in older\n// browsers that don't support the native Blob constructor. (i.e.\n// old QtWebKit versions, at least).\n// Abstracts constructing a Blob object, so it also works in older\n// browsers that don't support the native Blob constructor. (i.e.\n// old QtWebKit versions, at least).\nfunction createBlob(parts, properties) {\n /* global BlobBuilder,MSBlobBuilder,MozBlobBuilder,WebKitBlobBuilder */\n parts = parts || [];\n properties = properties || {};\n try {\n return new Blob(parts, properties);\n } catch (e) {\n if (e.name !== 'TypeError') {\n throw e;\n }\n var Builder = typeof BlobBuilder !== 'undefined' ? BlobBuilder : typeof MSBlobBuilder !== 'undefined' ? MSBlobBuilder : typeof MozBlobBuilder !== 'undefined' ? MozBlobBuilder : WebKitBlobBuilder;\n var builder = new Builder();\n for (var i = 0; i < parts.length; i += 1) {\n builder.append(parts[i]);\n }\n return builder.getBlob(properties.type);\n }\n}\n\n// This is CommonJS because lie is an external dependency, so Rollup\n// can just ignore it.\nif (typeof Promise === 'undefined') {\n // In the \"nopromises\" build this will just throw if you don't have\n // a global promise object, but it would throw anyway later.\n _dereq_(3);\n}\nvar Promise$1 = Promise;\n\nfunction executeCallback(promise, callback) {\n if (callback) {\n promise.then(function (result) {\n callback(null, result);\n }, function (error) {\n callback(error);\n });\n }\n}\n\nfunction executeTwoCallbacks(promise, callback, errorCallback) {\n if (typeof callback === 'function') {\n promise.then(callback);\n }\n\n if (typeof errorCallback === 'function') {\n promise[\"catch\"](errorCallback);\n }\n}\n\nfunction normalizeKey(key) {\n // Cast the key to a string, as that's all we can set as a key.\n if (typeof key !== 'string') {\n console.warn(key + ' used as a key, but it is not a string.');\n key = String(key);\n }\n\n return key;\n}\n\nfunction getCallback() {\n if (arguments.length && typeof arguments[arguments.length - 1] === 'function') {\n return arguments[arguments.length - 1];\n }\n}\n\n// Some code originally from async_storage.js in\n// [Gaia](https://github.com/mozilla-b2g/gaia).\n\nvar DETECT_BLOB_SUPPORT_STORE = 'local-forage-detect-blob-support';\nvar supportsBlobs = void 0;\nvar dbContexts = {};\nvar toString = Object.prototype.toString;\n\n// Transaction Modes\nvar READ_ONLY = 'readonly';\nvar READ_WRITE = 'readwrite';\n\n// Transform a binary string to an array buffer, because otherwise\n// weird stuff happens when you try to work with the binary string directly.\n// It is known.\n// From http://stackoverflow.com/questions/14967647/ (continues on next line)\n// encode-decode-image-with-base64-breaks-image (2013-04-21)\nfunction _binStringToArrayBuffer(bin) {\n var length = bin.length;\n var buf = new ArrayBuffer(length);\n var arr = new Uint8Array(buf);\n for (var i = 0; i < length; i++) {\n arr[i] = bin.charCodeAt(i);\n }\n return buf;\n}\n\n//\n// Blobs are not supported in all versions of IndexedDB, notably\n// Chrome <37 and Android <5. In those versions, storing a blob will throw.\n//\n// Various other blob bugs exist in Chrome v37-42 (inclusive).\n// Detecting them is expensive and confusing to users, and Chrome 37-42\n// is at very low usage worldwide, so we do a hacky userAgent check instead.\n//\n// content-type bug: https://code.google.com/p/chromium/issues/detail?id=408120\n// 404 bug: https://code.google.com/p/chromium/issues/detail?id=447916\n// FileReader bug: https://code.google.com/p/chromium/issues/detail?id=447836\n//\n// Code borrowed from PouchDB. See:\n// https://github.com/pouchdb/pouchdb/blob/master/packages/node_modules/pouchdb-adapter-idb/src/blobSupport.js\n//\nfunction _checkBlobSupportWithoutCaching(idb) {\n return new Promise$1(function (resolve) {\n var txn = idb.transaction(DETECT_BLOB_SUPPORT_STORE, READ_WRITE);\n var blob = createBlob(['']);\n txn.objectStore(DETECT_BLOB_SUPPORT_STORE).put(blob, 'key');\n\n txn.onabort = function (e) {\n // If the transaction aborts now its due to not being able to\n // write to the database, likely due to the disk being full\n e.preventDefault();\n e.stopPropagation();\n resolve(false);\n };\n\n txn.oncomplete = function () {\n var matchedChrome = navigator.userAgent.match(/Chrome\\/(\\d+)/);\n var matchedEdge = navigator.userAgent.match(/Edge\\//);\n // MS Edge pretends to be Chrome 42:\n // https://msdn.microsoft.com/en-us/library/hh869301%28v=vs.85%29.aspx\n resolve(matchedEdge || !matchedChrome || parseInt(matchedChrome[1], 10) >= 43);\n };\n })[\"catch\"](function () {\n return false; // error, so assume unsupported\n });\n}\n\nfunction _checkBlobSupport(idb) {\n if (typeof supportsBlobs === 'boolean') {\n return Promise$1.resolve(supportsBlobs);\n }\n return _checkBlobSupportWithoutCaching(idb).then(function (value) {\n supportsBlobs = value;\n return supportsBlobs;\n });\n}\n\nfunction _deferReadiness(dbInfo) {\n var dbContext = dbContexts[dbInfo.name];\n\n // Create a deferred object representing the current database operation.\n var deferredOperation = {};\n\n deferredOperation.promise = new Promise$1(function (resolve, reject) {\n deferredOperation.resolve = resolve;\n deferredOperation.reject = reject;\n });\n\n // Enqueue the deferred operation.\n dbContext.deferredOperations.push(deferredOperation);\n\n // Chain its promise to the database readiness.\n if (!dbContext.dbReady) {\n dbContext.dbReady = deferredOperation.promise;\n } else {\n dbContext.dbReady = dbContext.dbReady.then(function () {\n return deferredOperation.promise;\n });\n }\n}\n\nfunction _advanceReadiness(dbInfo) {\n var dbContext = dbContexts[dbInfo.name];\n\n // Dequeue a deferred operation.\n var deferredOperation = dbContext.deferredOperations.pop();\n\n // Resolve its promise (which is part of the database readiness\n // chain of promises).\n if (deferredOperation) {\n deferredOperation.resolve();\n return deferredOperation.promise;\n }\n}\n\nfunction _rejectReadiness(dbInfo, err) {\n var dbContext = dbContexts[dbInfo.name];\n\n // Dequeue a deferred operation.\n var deferredOperation = dbContext.deferredOperations.pop();\n\n // Reject its promise (which is part of the database readiness\n // chain of promises).\n if (deferredOperation) {\n deferredOperation.reject(err);\n return deferredOperation.promise;\n }\n}\n\nfunction _getConnection(dbInfo, upgradeNeeded) {\n return new Promise$1(function (resolve, reject) {\n dbContexts[dbInfo.name] = dbContexts[dbInfo.name] || createDbContext();\n\n if (dbInfo.db) {\n if (upgradeNeeded) {\n _deferReadiness(dbInfo);\n dbInfo.db.close();\n } else {\n return resolve(dbInfo.db);\n }\n }\n\n var dbArgs = [dbInfo.name];\n\n if (upgradeNeeded) {\n dbArgs.push(dbInfo.version);\n }\n\n var openreq = idb.open.apply(idb, dbArgs);\n\n if (upgradeNeeded) {\n openreq.onupgradeneeded = function (e) {\n var db = openreq.result;\n try {\n db.createObjectStore(dbInfo.storeName);\n if (e.oldVersion <= 1) {\n // Added when support for blob shims was added\n db.createObjectStore(DETECT_BLOB_SUPPORT_STORE);\n }\n } catch (ex) {\n if (ex.name === 'ConstraintError') {\n console.warn('The database \"' + dbInfo.name + '\"' + ' has been upgraded from version ' + e.oldVersion + ' to version ' + e.newVersion + ', but the storage \"' + dbInfo.storeName + '\" already exists.');\n } else {\n throw ex;\n }\n }\n };\n }\n\n openreq.onerror = function (e) {\n e.preventDefault();\n reject(openreq.error);\n };\n\n openreq.onsuccess = function () {\n var db = openreq.result;\n db.onversionchange = function (e) {\n // Triggered when the database is modified (e.g. adding an objectStore) or\n // deleted (even when initiated by other sessions in different tabs).\n // Closing the connection here prevents those operations from being blocked.\n // If the database is accessed again later by this instance, the connection\n // will be reopened or the database recreated as needed.\n e.target.close();\n };\n resolve(db);\n _advanceReadiness(dbInfo);\n };\n });\n}\n\nfunction _getOriginalConnection(dbInfo) {\n return _getConnection(dbInfo, false);\n}\n\nfunction _getUpgradedConnection(dbInfo) {\n return _getConnection(dbInfo, true);\n}\n\nfunction _isUpgradeNeeded(dbInfo, defaultVersion) {\n if (!dbInfo.db) {\n return true;\n }\n\n var isNewStore = !dbInfo.db.objectStoreNames.contains(dbInfo.storeName);\n var isDowngrade = dbInfo.version < dbInfo.db.version;\n var isUpgrade = dbInfo.version > dbInfo.db.version;\n\n if (isDowngrade) {\n // If the version is not the default one\n // then warn for impossible downgrade.\n if (dbInfo.version !== defaultVersion) {\n console.warn('The database \"' + dbInfo.name + '\"' + \" can't be downgraded from version \" + dbInfo.db.version + ' to version ' + dbInfo.version + '.');\n }\n // Align the versions to prevent errors.\n dbInfo.version = dbInfo.db.version;\n }\n\n if (isUpgrade || isNewStore) {\n // If the store is new then increment the version (if needed).\n // This will trigger an \"upgradeneeded\" event which is required\n // for creating a store.\n if (isNewStore) {\n var incVersion = dbInfo.db.version + 1;\n if (incVersion > dbInfo.version) {\n dbInfo.version = incVersion;\n }\n }\n\n return true;\n }\n\n return false;\n}\n\n// encode a blob for indexeddb engines that don't support blobs\nfunction _encodeBlob(blob) {\n return new Promise$1(function (resolve, reject) {\n var reader = new FileReader();\n reader.onerror = reject;\n reader.onloadend = function (e) {\n var base64 = btoa(e.target.result || '');\n resolve({\n __local_forage_encoded_blob: true,\n data: base64,\n type: blob.type\n });\n };\n reader.readAsBinaryString(blob);\n });\n}\n\n// decode an encoded blob\nfunction _decodeBlob(encodedBlob) {\n var arrayBuff = _binStringToArrayBuffer(atob(encodedBlob.data));\n return createBlob([arrayBuff], { type: encodedBlob.type });\n}\n\n// is this one of our fancy encoded blobs?\nfunction _isEncodedBlob(value) {\n return value && value.__local_forage_encoded_blob;\n}\n\n// Specialize the default `ready()` function by making it dependent\n// on the current database operations. Thus, the driver will be actually\n// ready when it's been initialized (default) *and* there are no pending\n// operations on the database (initiated by some other instances).\nfunction _fullyReady(callback) {\n var self = this;\n\n var promise = self._initReady().then(function () {\n var dbContext = dbContexts[self._dbInfo.name];\n\n if (dbContext && dbContext.dbReady) {\n return dbContext.dbReady;\n }\n });\n\n executeTwoCallbacks(promise, callback, callback);\n return promise;\n}\n\n// Try to establish a new db connection to replace the\n// current one which is broken (i.e. experiencing\n// InvalidStateError while creating a transaction).\nfunction _tryReconnect(dbInfo) {\n _deferReadiness(dbInfo);\n\n var dbContext = dbContexts[dbInfo.name];\n var forages = dbContext.forages;\n\n for (var i = 0; i < forages.length; i++) {\n var forage = forages[i];\n if (forage._dbInfo.db) {\n forage._dbInfo.db.close();\n forage._dbInfo.db = null;\n }\n }\n dbInfo.db = null;\n\n return _getOriginalConnection(dbInfo).then(function (db) {\n dbInfo.db = db;\n if (_isUpgradeNeeded(dbInfo)) {\n // Reopen the database for upgrading.\n return _getUpgradedConnection(dbInfo);\n }\n return db;\n }).then(function (db) {\n // store the latest db reference\n // in case the db was upgraded\n dbInfo.db = dbContext.db = db;\n for (var i = 0; i < forages.length; i++) {\n forages[i]._dbInfo.db = db;\n }\n })[\"catch\"](function (err) {\n _rejectReadiness(dbInfo, err);\n throw err;\n });\n}\n\n// FF doesn't like Promises (micro-tasks) and IDDB store operations,\n// so we have to do it with callbacks\nfunction createTransaction(dbInfo, mode, callback, retries) {\n if (retries === undefined) {\n retries = 1;\n }\n\n try {\n var tx = dbInfo.db.transaction(dbInfo.storeName, mode);\n callback(null, tx);\n } catch (err) {\n if (retries > 0 && (!dbInfo.db || err.name === 'InvalidStateError' || err.name === 'NotFoundError')) {\n return Promise$1.resolve().then(function () {\n if (!dbInfo.db || err.name === 'NotFoundError' && !dbInfo.db.objectStoreNames.contains(dbInfo.storeName) && dbInfo.version <= dbInfo.db.version) {\n // increase the db version, to create the new ObjectStore\n if (dbInfo.db) {\n dbInfo.version = dbInfo.db.version + 1;\n }\n // Reopen the database for upgrading.\n return _getUpgradedConnection(dbInfo);\n }\n }).then(function () {\n return _tryReconnect(dbInfo).then(function () {\n createTransaction(dbInfo, mode, callback, retries - 1);\n });\n })[\"catch\"](callback);\n }\n\n callback(err);\n }\n}\n\nfunction createDbContext() {\n return {\n // Running localForages sharing a database.\n forages: [],\n // Shared database.\n db: null,\n // Database readiness (promise).\n dbReady: null,\n // Deferred operations on the database.\n deferredOperations: []\n };\n}\n\n// Open the IndexedDB database (automatically creates one if one didn't\n// previously exist), using any options set in the config.\nfunction _initStorage(options) {\n var self = this;\n var dbInfo = {\n db: null\n };\n\n if (options) {\n for (var i in options) {\n dbInfo[i] = options[i];\n }\n }\n\n // Get the current context of the database;\n var dbContext = dbContexts[dbInfo.name];\n\n // ...or create a new context.\n if (!dbContext) {\n dbContext = createDbContext();\n // Register the new context in the global container.\n dbContexts[dbInfo.name] = dbContext;\n }\n\n // Register itself as a running localForage in the current context.\n dbContext.forages.push(self);\n\n // Replace the default `ready()` function with the specialized one.\n if (!self._initReady) {\n self._initReady = self.ready;\n self.ready = _fullyReady;\n }\n\n // Create an array of initialization states of the related localForages.\n var initPromises = [];\n\n function ignoreErrors() {\n // Don't handle errors here,\n // just makes sure related localForages aren't pending.\n return Promise$1.resolve();\n }\n\n for (var j = 0; j < dbContext.forages.length; j++) {\n var forage = dbContext.forages[j];\n if (forage !== self) {\n // Don't wait for itself...\n initPromises.push(forage._initReady()[\"catch\"](ignoreErrors));\n }\n }\n\n // Take a snapshot of the related localForages.\n var forages = dbContext.forages.slice(0);\n\n // Initialize the connection process only when\n // all the related localForages aren't pending.\n return Promise$1.all(initPromises).then(function () {\n dbInfo.db = dbContext.db;\n // Get the connection or open a new one without upgrade.\n return _getOriginalConnection(dbInfo);\n }).then(function (db) {\n dbInfo.db = db;\n if (_isUpgradeNeeded(dbInfo, self._defaultConfig.version)) {\n // Reopen the database for upgrading.\n return _getUpgradedConnection(dbInfo);\n }\n return db;\n }).then(function (db) {\n dbInfo.db = dbContext.db = db;\n self._dbInfo = dbInfo;\n // Share the final connection amongst related localForages.\n for (var k = 0; k < forages.length; k++) {\n var forage = forages[k];\n if (forage !== self) {\n // Self is already up-to-date.\n forage._dbInfo.db = dbInfo.db;\n forage._dbInfo.version = dbInfo.version;\n }\n }\n });\n}\n\nfunction getItem(key, callback) {\n var self = this;\n\n key = normalizeKey(key);\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n createTransaction(self._dbInfo, READ_ONLY, function (err, transaction) {\n if (err) {\n return reject(err);\n }\n\n try {\n var store = transaction.objectStore(self._dbInfo.storeName);\n var req = store.get(key);\n\n req.onsuccess = function () {\n var value = req.result;\n if (value === undefined) {\n value = null;\n }\n if (_isEncodedBlob(value)) {\n value = _decodeBlob(value);\n }\n resolve(value);\n };\n\n req.onerror = function () {\n reject(req.error);\n };\n } catch (e) {\n reject(e);\n }\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\n// Iterate over all items stored in database.\nfunction iterate(iterator, callback) {\n var self = this;\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n createTransaction(self._dbInfo, READ_ONLY, function (err, transaction) {\n if (err) {\n return reject(err);\n }\n\n try {\n var store = transaction.objectStore(self._dbInfo.storeName);\n var req = store.openCursor();\n var iterationNumber = 1;\n\n req.onsuccess = function () {\n var cursor = req.result;\n\n if (cursor) {\n var value = cursor.value;\n if (_isEncodedBlob(value)) {\n value = _decodeBlob(value);\n }\n var result = iterator(value, cursor.key, iterationNumber++);\n\n // when the iterator callback returns any\n // (non-`undefined`) value, then we stop\n // the iteration immediately\n if (result !== void 0) {\n resolve(result);\n } else {\n cursor[\"continue\"]();\n }\n } else {\n resolve();\n }\n };\n\n req.onerror = function () {\n reject(req.error);\n };\n } catch (e) {\n reject(e);\n }\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n\n return promise;\n}\n\nfunction setItem(key, value, callback) {\n var self = this;\n\n key = normalizeKey(key);\n\n var promise = new Promise$1(function (resolve, reject) {\n var dbInfo;\n self.ready().then(function () {\n dbInfo = self._dbInfo;\n if (toString.call(value) === '[object Blob]') {\n return _checkBlobSupport(dbInfo.db).then(function (blobSupport) {\n if (blobSupport) {\n return value;\n }\n return _encodeBlob(value);\n });\n }\n return value;\n }).then(function (value) {\n createTransaction(self._dbInfo, READ_WRITE, function (err, transaction) {\n if (err) {\n return reject(err);\n }\n\n try {\n var store = transaction.objectStore(self._dbInfo.storeName);\n\n // The reason we don't _save_ null is because IE 10 does\n // not support saving the `null` type in IndexedDB. How\n // ironic, given the bug below!\n // See: https://github.com/mozilla/localForage/issues/161\n if (value === null) {\n value = undefined;\n }\n\n var req = store.put(value, key);\n\n transaction.oncomplete = function () {\n // Cast to undefined so the value passed to\n // callback/promise is the same as what one would get out\n // of `getItem()` later. This leads to some weirdness\n // (setItem('foo', undefined) will return `null`), but\n // it's not my fault localStorage is our baseline and that\n // it's weird.\n if (value === undefined) {\n value = null;\n }\n\n resolve(value);\n };\n transaction.onabort = transaction.onerror = function () {\n var err = req.error ? req.error : req.transaction.error;\n reject(err);\n };\n } catch (e) {\n reject(e);\n }\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction removeItem(key, callback) {\n var self = this;\n\n key = normalizeKey(key);\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n createTransaction(self._dbInfo, READ_WRITE, function (err, transaction) {\n if (err) {\n return reject(err);\n }\n\n try {\n var store = transaction.objectStore(self._dbInfo.storeName);\n // We use a Grunt task to make this safe for IE and some\n // versions of Android (including those used by Cordova).\n // Normally IE won't like `.delete()` and will insist on\n // using `['delete']()`, but we have a build step that\n // fixes this for us now.\n var req = store[\"delete\"](key);\n transaction.oncomplete = function () {\n resolve();\n };\n\n transaction.onerror = function () {\n reject(req.error);\n };\n\n // The request will be also be aborted if we've exceeded our storage\n // space.\n transaction.onabort = function () {\n var err = req.error ? req.error : req.transaction.error;\n reject(err);\n };\n } catch (e) {\n reject(e);\n }\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction clear(callback) {\n var self = this;\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n createTransaction(self._dbInfo, READ_WRITE, function (err, transaction) {\n if (err) {\n return reject(err);\n }\n\n try {\n var store = transaction.objectStore(self._dbInfo.storeName);\n var req = store.clear();\n\n transaction.oncomplete = function () {\n resolve();\n };\n\n transaction.onabort = transaction.onerror = function () {\n var err = req.error ? req.error : req.transaction.error;\n reject(err);\n };\n } catch (e) {\n reject(e);\n }\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction length(callback) {\n var self = this;\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n createTransaction(self._dbInfo, READ_ONLY, function (err, transaction) {\n if (err) {\n return reject(err);\n }\n\n try {\n var store = transaction.objectStore(self._dbInfo.storeName);\n var req = store.count();\n\n req.onsuccess = function () {\n resolve(req.result);\n };\n\n req.onerror = function () {\n reject(req.error);\n };\n } catch (e) {\n reject(e);\n }\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction key(n, callback) {\n var self = this;\n\n var promise = new Promise$1(function (resolve, reject) {\n if (n < 0) {\n resolve(null);\n\n return;\n }\n\n self.ready().then(function () {\n createTransaction(self._dbInfo, READ_ONLY, function (err, transaction) {\n if (err) {\n return reject(err);\n }\n\n try {\n var store = transaction.objectStore(self._dbInfo.storeName);\n var advanced = false;\n var req = store.openKeyCursor();\n\n req.onsuccess = function () {\n var cursor = req.result;\n if (!cursor) {\n // this means there weren't enough keys\n resolve(null);\n\n return;\n }\n\n if (n === 0) {\n // We have the first key, return it if that's what they\n // wanted.\n resolve(cursor.key);\n } else {\n if (!advanced) {\n // Otherwise, ask the cursor to skip ahead n\n // records.\n advanced = true;\n cursor.advance(n);\n } else {\n // When we get here, we've got the nth key.\n resolve(cursor.key);\n }\n }\n };\n\n req.onerror = function () {\n reject(req.error);\n };\n } catch (e) {\n reject(e);\n }\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction keys(callback) {\n var self = this;\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n createTransaction(self._dbInfo, READ_ONLY, function (err, transaction) {\n if (err) {\n return reject(err);\n }\n\n try {\n var store = transaction.objectStore(self._dbInfo.storeName);\n var req = store.openKeyCursor();\n var keys = [];\n\n req.onsuccess = function () {\n var cursor = req.result;\n\n if (!cursor) {\n resolve(keys);\n return;\n }\n\n keys.push(cursor.key);\n cursor[\"continue\"]();\n };\n\n req.onerror = function () {\n reject(req.error);\n };\n } catch (e) {\n reject(e);\n }\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction dropInstance(options, callback) {\n callback = getCallback.apply(this, arguments);\n\n var currentConfig = this.config();\n options = typeof options !== 'function' && options || {};\n if (!options.name) {\n options.name = options.name || currentConfig.name;\n options.storeName = options.storeName || currentConfig.storeName;\n }\n\n var self = this;\n var promise;\n if (!options.name) {\n promise = Promise$1.reject('Invalid arguments');\n } else {\n var isCurrentDb = options.name === currentConfig.name && self._dbInfo.db;\n\n var dbPromise = isCurrentDb ? Promise$1.resolve(self._dbInfo.db) : _getOriginalConnection(options).then(function (db) {\n var dbContext = dbContexts[options.name];\n var forages = dbContext.forages;\n dbContext.db = db;\n for (var i = 0; i < forages.length; i++) {\n forages[i]._dbInfo.db = db;\n }\n return db;\n });\n\n if (!options.storeName) {\n promise = dbPromise.then(function (db) {\n _deferReadiness(options);\n\n var dbContext = dbContexts[options.name];\n var forages = dbContext.forages;\n\n db.close();\n for (var i = 0; i < forages.length; i++) {\n var forage = forages[i];\n forage._dbInfo.db = null;\n }\n\n var dropDBPromise = new Promise$1(function (resolve, reject) {\n var req = idb.deleteDatabase(options.name);\n\n req.onerror = function () {\n var db = req.result;\n if (db) {\n db.close();\n }\n reject(req.error);\n };\n\n req.onblocked = function () {\n // Closing all open connections in onversionchange handler should prevent this situation, but if\n // we do get here, it just means the request remains pending - eventually it will succeed or error\n console.warn('dropInstance blocked for database \"' + options.name + '\" until all open connections are closed');\n };\n\n req.onsuccess = function () {\n var db = req.result;\n if (db) {\n db.close();\n }\n resolve(db);\n };\n });\n\n return dropDBPromise.then(function (db) {\n dbContext.db = db;\n for (var i = 0; i < forages.length; i++) {\n var _forage = forages[i];\n _advanceReadiness(_forage._dbInfo);\n }\n })[\"catch\"](function (err) {\n (_rejectReadiness(options, err) || Promise$1.resolve())[\"catch\"](function () {});\n throw err;\n });\n });\n } else {\n promise = dbPromise.then(function (db) {\n if (!db.objectStoreNames.contains(options.storeName)) {\n return;\n }\n\n var newVersion = db.version + 1;\n\n _deferReadiness(options);\n\n var dbContext = dbContexts[options.name];\n var forages = dbContext.forages;\n\n db.close();\n for (var i = 0; i < forages.length; i++) {\n var forage = forages[i];\n forage._dbInfo.db = null;\n forage._dbInfo.version = newVersion;\n }\n\n var dropObjectPromise = new Promise$1(function (resolve, reject) {\n var req = idb.open(options.name, newVersion);\n\n req.onerror = function (err) {\n var db = req.result;\n db.close();\n reject(err);\n };\n\n req.onupgradeneeded = function () {\n var db = req.result;\n db.deleteObjectStore(options.storeName);\n };\n\n req.onsuccess = function () {\n var db = req.result;\n db.close();\n resolve(db);\n };\n });\n\n return dropObjectPromise.then(function (db) {\n dbContext.db = db;\n for (var j = 0; j < forages.length; j++) {\n var _forage2 = forages[j];\n _forage2._dbInfo.db = db;\n _advanceReadiness(_forage2._dbInfo);\n }\n })[\"catch\"](function (err) {\n (_rejectReadiness(options, err) || Promise$1.resolve())[\"catch\"](function () {});\n throw err;\n });\n });\n }\n }\n\n executeCallback(promise, callback);\n return promise;\n}\n\nvar asyncStorage = {\n _driver: 'asyncStorage',\n _initStorage: _initStorage,\n _support: isIndexedDBValid(),\n iterate: iterate,\n getItem: getItem,\n setItem: setItem,\n removeItem: removeItem,\n clear: clear,\n length: length,\n key: key,\n keys: keys,\n dropInstance: dropInstance\n};\n\nfunction isWebSQLValid() {\n return typeof openDatabase === 'function';\n}\n\n// Sadly, the best way to save binary data in WebSQL/localStorage is serializing\n// it to Base64, so this is how we store it to prevent very strange errors with less\n// verbose ways of binary <-> string data storage.\nvar BASE_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n\nvar BLOB_TYPE_PREFIX = '~~local_forage_type~';\nvar BLOB_TYPE_PREFIX_REGEX = /^~~local_forage_type~([^~]+)~/;\n\nvar SERIALIZED_MARKER = '__lfsc__:';\nvar SERIALIZED_MARKER_LENGTH = SERIALIZED_MARKER.length;\n\n// OMG the serializations!\nvar TYPE_ARRAYBUFFER = 'arbf';\nvar TYPE_BLOB = 'blob';\nvar TYPE_INT8ARRAY = 'si08';\nvar TYPE_UINT8ARRAY = 'ui08';\nvar TYPE_UINT8CLAMPEDARRAY = 'uic8';\nvar TYPE_INT16ARRAY = 'si16';\nvar TYPE_INT32ARRAY = 'si32';\nvar TYPE_UINT16ARRAY = 'ur16';\nvar TYPE_UINT32ARRAY = 'ui32';\nvar TYPE_FLOAT32ARRAY = 'fl32';\nvar TYPE_FLOAT64ARRAY = 'fl64';\nvar TYPE_SERIALIZED_MARKER_LENGTH = SERIALIZED_MARKER_LENGTH + TYPE_ARRAYBUFFER.length;\n\nvar toString$1 = Object.prototype.toString;\n\nfunction stringToBuffer(serializedString) {\n // Fill the string into a ArrayBuffer.\n var bufferLength = serializedString.length * 0.75;\n var len = serializedString.length;\n var i;\n var p = 0;\n var encoded1, encoded2, encoded3, encoded4;\n\n if (serializedString[serializedString.length - 1] === '=') {\n bufferLength--;\n if (serializedString[serializedString.length - 2] === '=') {\n bufferLength--;\n }\n }\n\n var buffer = new ArrayBuffer(bufferLength);\n var bytes = new Uint8Array(buffer);\n\n for (i = 0; i < len; i += 4) {\n encoded1 = BASE_CHARS.indexOf(serializedString[i]);\n encoded2 = BASE_CHARS.indexOf(serializedString[i + 1]);\n encoded3 = BASE_CHARS.indexOf(serializedString[i + 2]);\n encoded4 = BASE_CHARS.indexOf(serializedString[i + 3]);\n\n /*jslint bitwise: true */\n bytes[p++] = encoded1 << 2 | encoded2 >> 4;\n bytes[p++] = (encoded2 & 15) << 4 | encoded3 >> 2;\n bytes[p++] = (encoded3 & 3) << 6 | encoded4 & 63;\n }\n return buffer;\n}\n\n// Converts a buffer to a string to store, serialized, in the backend\n// storage library.\nfunction bufferToString(buffer) {\n // base64-arraybuffer\n var bytes = new Uint8Array(buffer);\n var base64String = '';\n var i;\n\n for (i = 0; i < bytes.length; i += 3) {\n /*jslint bitwise: true */\n base64String += BASE_CHARS[bytes[i] >> 2];\n base64String += BASE_CHARS[(bytes[i] & 3) << 4 | bytes[i + 1] >> 4];\n base64String += BASE_CHARS[(bytes[i + 1] & 15) << 2 | bytes[i + 2] >> 6];\n base64String += BASE_CHARS[bytes[i + 2] & 63];\n }\n\n if (bytes.length % 3 === 2) {\n base64String = base64String.substring(0, base64String.length - 1) + '=';\n } else if (bytes.length % 3 === 1) {\n base64String = base64String.substring(0, base64String.length - 2) + '==';\n }\n\n return base64String;\n}\n\n// Serialize a value, afterwards executing a callback (which usually\n// instructs the `setItem()` callback/promise to be executed). This is how\n// we store binary data with localStorage.\nfunction serialize(value, callback) {\n var valueType = '';\n if (value) {\n valueType = toString$1.call(value);\n }\n\n // Cannot use `value instanceof ArrayBuffer` or such here, as these\n // checks fail when running the tests using casper.js...\n //\n // TODO: See why those tests fail and use a better solution.\n if (value && (valueType === '[object ArrayBuffer]' || value.buffer && toString$1.call(value.buffer) === '[object ArrayBuffer]')) {\n // Convert binary arrays to a string and prefix the string with\n // a special marker.\n var buffer;\n var marker = SERIALIZED_MARKER;\n\n if (value instanceof ArrayBuffer) {\n buffer = value;\n marker += TYPE_ARRAYBUFFER;\n } else {\n buffer = value.buffer;\n\n if (valueType === '[object Int8Array]') {\n marker += TYPE_INT8ARRAY;\n } else if (valueType === '[object Uint8Array]') {\n marker += TYPE_UINT8ARRAY;\n } else if (valueType === '[object Uint8ClampedArray]') {\n marker += TYPE_UINT8CLAMPEDARRAY;\n } else if (valueType === '[object Int16Array]') {\n marker += TYPE_INT16ARRAY;\n } else if (valueType === '[object Uint16Array]') {\n marker += TYPE_UINT16ARRAY;\n } else if (valueType === '[object Int32Array]') {\n marker += TYPE_INT32ARRAY;\n } else if (valueType === '[object Uint32Array]') {\n marker += TYPE_UINT32ARRAY;\n } else if (valueType === '[object Float32Array]') {\n marker += TYPE_FLOAT32ARRAY;\n } else if (valueType === '[object Float64Array]') {\n marker += TYPE_FLOAT64ARRAY;\n } else {\n callback(new Error('Failed to get type for BinaryArray'));\n }\n }\n\n callback(marker + bufferToString(buffer));\n } else if (valueType === '[object Blob]') {\n // Conver the blob to a binaryArray and then to a string.\n var fileReader = new FileReader();\n\n fileReader.onload = function () {\n // Backwards-compatible prefix for the blob type.\n var str = BLOB_TYPE_PREFIX + value.type + '~' + bufferToString(this.result);\n\n callback(SERIALIZED_MARKER + TYPE_BLOB + str);\n };\n\n fileReader.readAsArrayBuffer(value);\n } else {\n try {\n callback(JSON.stringify(value));\n } catch (e) {\n console.error(\"Couldn't convert value into a JSON string: \", value);\n\n callback(null, e);\n }\n }\n}\n\n// Deserialize data we've inserted into a value column/field. We place\n// special markers into our strings to mark them as encoded; this isn't\n// as nice as a meta field, but it's the only sane thing we can do whilst\n// keeping localStorage support intact.\n//\n// Oftentimes this will just deserialize JSON content, but if we have a\n// special marker (SERIALIZED_MARKER, defined above), we will extract\n// some kind of arraybuffer/binary data/typed array out of the string.\nfunction deserialize(value) {\n // If we haven't marked this string as being specially serialized (i.e.\n // something other than serialized JSON), we can just return it and be\n // done with it.\n if (value.substring(0, SERIALIZED_MARKER_LENGTH) !== SERIALIZED_MARKER) {\n return JSON.parse(value);\n }\n\n // The following code deals with deserializing some kind of Blob or\n // TypedArray. First we separate out the type of data we're dealing\n // with from the data itself.\n var serializedString = value.substring(TYPE_SERIALIZED_MARKER_LENGTH);\n var type = value.substring(SERIALIZED_MARKER_LENGTH, TYPE_SERIALIZED_MARKER_LENGTH);\n\n var blobType;\n // Backwards-compatible blob type serialization strategy.\n // DBs created with older versions of localForage will simply not have the blob type.\n if (type === TYPE_BLOB && BLOB_TYPE_PREFIX_REGEX.test(serializedString)) {\n var matcher = serializedString.match(BLOB_TYPE_PREFIX_REGEX);\n blobType = matcher[1];\n serializedString = serializedString.substring(matcher[0].length);\n }\n var buffer = stringToBuffer(serializedString);\n\n // Return the right type based on the code/type set during\n // serialization.\n switch (type) {\n case TYPE_ARRAYBUFFER:\n return buffer;\n case TYPE_BLOB:\n return createBlob([buffer], { type: blobType });\n case TYPE_INT8ARRAY:\n return new Int8Array(buffer);\n case TYPE_UINT8ARRAY:\n return new Uint8Array(buffer);\n case TYPE_UINT8CLAMPEDARRAY:\n return new Uint8ClampedArray(buffer);\n case TYPE_INT16ARRAY:\n return new Int16Array(buffer);\n case TYPE_UINT16ARRAY:\n return new Uint16Array(buffer);\n case TYPE_INT32ARRAY:\n return new Int32Array(buffer);\n case TYPE_UINT32ARRAY:\n return new Uint32Array(buffer);\n case TYPE_FLOAT32ARRAY:\n return new Float32Array(buffer);\n case TYPE_FLOAT64ARRAY:\n return new Float64Array(buffer);\n default:\n throw new Error('Unkown type: ' + type);\n }\n}\n\nvar localforageSerializer = {\n serialize: serialize,\n deserialize: deserialize,\n stringToBuffer: stringToBuffer,\n bufferToString: bufferToString\n};\n\n/*\n * Includes code from:\n *\n * base64-arraybuffer\n * https://github.com/niklasvh/base64-arraybuffer\n *\n * Copyright (c) 2012 Niklas von Hertzen\n * Licensed under the MIT license.\n */\n\nfunction createDbTable(t, dbInfo, callback, errorCallback) {\n t.executeSql('CREATE TABLE IF NOT EXISTS ' + dbInfo.storeName + ' ' + '(id INTEGER PRIMARY KEY, key unique, value)', [], callback, errorCallback);\n}\n\n// Open the WebSQL database (automatically creates one if one didn't\n// previously exist), using any options set in the config.\nfunction _initStorage$1(options) {\n var self = this;\n var dbInfo = {\n db: null\n };\n\n if (options) {\n for (var i in options) {\n dbInfo[i] = typeof options[i] !== 'string' ? options[i].toString() : options[i];\n }\n }\n\n var dbInfoPromise = new Promise$1(function (resolve, reject) {\n // Open the database; the openDatabase API will automatically\n // create it for us if it doesn't exist.\n try {\n dbInfo.db = openDatabase(dbInfo.name, String(dbInfo.version), dbInfo.description, dbInfo.size);\n } catch (e) {\n return reject(e);\n }\n\n // Create our key/value table if it doesn't exist.\n dbInfo.db.transaction(function (t) {\n createDbTable(t, dbInfo, function () {\n self._dbInfo = dbInfo;\n resolve();\n }, function (t, error) {\n reject(error);\n });\n }, reject);\n });\n\n dbInfo.serializer = localforageSerializer;\n return dbInfoPromise;\n}\n\nfunction tryExecuteSql(t, dbInfo, sqlStatement, args, callback, errorCallback) {\n t.executeSql(sqlStatement, args, callback, function (t, error) {\n if (error.code === error.SYNTAX_ERR) {\n t.executeSql('SELECT name FROM sqlite_master ' + \"WHERE type='table' AND name = ?\", [dbInfo.storeName], function (t, results) {\n if (!results.rows.length) {\n // if the table is missing (was deleted)\n // re-create it table and retry\n createDbTable(t, dbInfo, function () {\n t.executeSql(sqlStatement, args, callback, errorCallback);\n }, errorCallback);\n } else {\n errorCallback(t, error);\n }\n }, errorCallback);\n } else {\n errorCallback(t, error);\n }\n }, errorCallback);\n}\n\nfunction getItem$1(key, callback) {\n var self = this;\n\n key = normalizeKey(key);\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n var dbInfo = self._dbInfo;\n dbInfo.db.transaction(function (t) {\n tryExecuteSql(t, dbInfo, 'SELECT * FROM ' + dbInfo.storeName + ' WHERE key = ? LIMIT 1', [key], function (t, results) {\n var result = results.rows.length ? results.rows.item(0).value : null;\n\n // Check to see if this is serialized content we need to\n // unpack.\n if (result) {\n result = dbInfo.serializer.deserialize(result);\n }\n\n resolve(result);\n }, function (t, error) {\n reject(error);\n });\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction iterate$1(iterator, callback) {\n var self = this;\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n var dbInfo = self._dbInfo;\n\n dbInfo.db.transaction(function (t) {\n tryExecuteSql(t, dbInfo, 'SELECT * FROM ' + dbInfo.storeName, [], function (t, results) {\n var rows = results.rows;\n var length = rows.length;\n\n for (var i = 0; i < length; i++) {\n var item = rows.item(i);\n var result = item.value;\n\n // Check to see if this is serialized content\n // we need to unpack.\n if (result) {\n result = dbInfo.serializer.deserialize(result);\n }\n\n result = iterator(result, item.key, i + 1);\n\n // void(0) prevents problems with redefinition\n // of `undefined`.\n if (result !== void 0) {\n resolve(result);\n return;\n }\n }\n\n resolve();\n }, function (t, error) {\n reject(error);\n });\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction _setItem(key, value, callback, retriesLeft) {\n var self = this;\n\n key = normalizeKey(key);\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n // The localStorage API doesn't return undefined values in an\n // \"expected\" way, so undefined is always cast to null in all\n // drivers. See: https://github.com/mozilla/localForage/pull/42\n if (value === undefined) {\n value = null;\n }\n\n // Save the original value to pass to the callback.\n var originalValue = value;\n\n var dbInfo = self._dbInfo;\n dbInfo.serializer.serialize(value, function (value, error) {\n if (error) {\n reject(error);\n } else {\n dbInfo.db.transaction(function (t) {\n tryExecuteSql(t, dbInfo, 'INSERT OR REPLACE INTO ' + dbInfo.storeName + ' ' + '(key, value) VALUES (?, ?)', [key, value], function () {\n resolve(originalValue);\n }, function (t, error) {\n reject(error);\n });\n }, function (sqlError) {\n // The transaction failed; check\n // to see if it's a quota error.\n if (sqlError.code === sqlError.QUOTA_ERR) {\n // We reject the callback outright for now, but\n // it's worth trying to re-run the transaction.\n // Even if the user accepts the prompt to use\n // more storage on Safari, this error will\n // be called.\n //\n // Try to re-run the transaction.\n if (retriesLeft > 0) {\n resolve(_setItem.apply(self, [key, originalValue, callback, retriesLeft - 1]));\n return;\n }\n reject(sqlError);\n }\n });\n }\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction setItem$1(key, value, callback) {\n return _setItem.apply(this, [key, value, callback, 1]);\n}\n\nfunction removeItem$1(key, callback) {\n var self = this;\n\n key = normalizeKey(key);\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n var dbInfo = self._dbInfo;\n dbInfo.db.transaction(function (t) {\n tryExecuteSql(t, dbInfo, 'DELETE FROM ' + dbInfo.storeName + ' WHERE key = ?', [key], function () {\n resolve();\n }, function (t, error) {\n reject(error);\n });\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\n// Deletes every item in the table.\n// TODO: Find out if this resets the AUTO_INCREMENT number.\nfunction clear$1(callback) {\n var self = this;\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n var dbInfo = self._dbInfo;\n dbInfo.db.transaction(function (t) {\n tryExecuteSql(t, dbInfo, 'DELETE FROM ' + dbInfo.storeName, [], function () {\n resolve();\n }, function (t, error) {\n reject(error);\n });\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\n// Does a simple `COUNT(key)` to get the number of items stored in\n// localForage.\nfunction length$1(callback) {\n var self = this;\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n var dbInfo = self._dbInfo;\n dbInfo.db.transaction(function (t) {\n // Ahhh, SQL makes this one soooooo easy.\n tryExecuteSql(t, dbInfo, 'SELECT COUNT(key) as c FROM ' + dbInfo.storeName, [], function (t, results) {\n var result = results.rows.item(0).c;\n resolve(result);\n }, function (t, error) {\n reject(error);\n });\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\n// Return the key located at key index X; essentially gets the key from a\n// `WHERE id = ?`. This is the most efficient way I can think to implement\n// this rarely-used (in my experience) part of the API, but it can seem\n// inconsistent, because we do `INSERT OR REPLACE INTO` on `setItem()`, so\n// the ID of each key will change every time it's updated. Perhaps a stored\n// procedure for the `setItem()` SQL would solve this problem?\n// TODO: Don't change ID on `setItem()`.\nfunction key$1(n, callback) {\n var self = this;\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n var dbInfo = self._dbInfo;\n dbInfo.db.transaction(function (t) {\n tryExecuteSql(t, dbInfo, 'SELECT key FROM ' + dbInfo.storeName + ' WHERE id = ? LIMIT 1', [n + 1], function (t, results) {\n var result = results.rows.length ? results.rows.item(0).key : null;\n resolve(result);\n }, function (t, error) {\n reject(error);\n });\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction keys$1(callback) {\n var self = this;\n\n var promise = new Promise$1(function (resolve, reject) {\n self.ready().then(function () {\n var dbInfo = self._dbInfo;\n dbInfo.db.transaction(function (t) {\n tryExecuteSql(t, dbInfo, 'SELECT key FROM ' + dbInfo.storeName, [], function (t, results) {\n var keys = [];\n\n for (var i = 0; i < results.rows.length; i++) {\n keys.push(results.rows.item(i).key);\n }\n\n resolve(keys);\n }, function (t, error) {\n reject(error);\n });\n });\n })[\"catch\"](reject);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\n// https://www.w3.org/TR/webdatabase/#databases\n// > There is no way to enumerate or delete the databases available for an origin from this API.\nfunction getAllStoreNames(db) {\n return new Promise$1(function (resolve, reject) {\n db.transaction(function (t) {\n t.executeSql('SELECT name FROM sqlite_master ' + \"WHERE type='table' AND name <> '__WebKitDatabaseInfoTable__'\", [], function (t, results) {\n var storeNames = [];\n\n for (var i = 0; i < results.rows.length; i++) {\n storeNames.push(results.rows.item(i).name);\n }\n\n resolve({\n db: db,\n storeNames: storeNames\n });\n }, function (t, error) {\n reject(error);\n });\n }, function (sqlError) {\n reject(sqlError);\n });\n });\n}\n\nfunction dropInstance$1(options, callback) {\n callback = getCallback.apply(this, arguments);\n\n var currentConfig = this.config();\n options = typeof options !== 'function' && options || {};\n if (!options.name) {\n options.name = options.name || currentConfig.name;\n options.storeName = options.storeName || currentConfig.storeName;\n }\n\n var self = this;\n var promise;\n if (!options.name) {\n promise = Promise$1.reject('Invalid arguments');\n } else {\n promise = new Promise$1(function (resolve) {\n var db;\n if (options.name === currentConfig.name) {\n // use the db reference of the current instance\n db = self._dbInfo.db;\n } else {\n db = openDatabase(options.name, '', '', 0);\n }\n\n if (!options.storeName) {\n // drop all database tables\n resolve(getAllStoreNames(db));\n } else {\n resolve({\n db: db,\n storeNames: [options.storeName]\n });\n }\n }).then(function (operationInfo) {\n return new Promise$1(function (resolve, reject) {\n operationInfo.db.transaction(function (t) {\n function dropTable(storeName) {\n return new Promise$1(function (resolve, reject) {\n t.executeSql('DROP TABLE IF EXISTS ' + storeName, [], function () {\n resolve();\n }, function (t, error) {\n reject(error);\n });\n });\n }\n\n var operations = [];\n for (var i = 0, len = operationInfo.storeNames.length; i < len; i++) {\n operations.push(dropTable(operationInfo.storeNames[i]));\n }\n\n Promise$1.all(operations).then(function () {\n resolve();\n })[\"catch\"](function (e) {\n reject(e);\n });\n }, function (sqlError) {\n reject(sqlError);\n });\n });\n });\n }\n\n executeCallback(promise, callback);\n return promise;\n}\n\nvar webSQLStorage = {\n _driver: 'webSQLStorage',\n _initStorage: _initStorage$1,\n _support: isWebSQLValid(),\n iterate: iterate$1,\n getItem: getItem$1,\n setItem: setItem$1,\n removeItem: removeItem$1,\n clear: clear$1,\n length: length$1,\n key: key$1,\n keys: keys$1,\n dropInstance: dropInstance$1\n};\n\nfunction isLocalStorageValid() {\n try {\n return typeof localStorage !== 'undefined' && 'setItem' in localStorage &&\n // in IE8 typeof localStorage.setItem === 'object'\n !!localStorage.setItem;\n } catch (e) {\n return false;\n }\n}\n\nfunction _getKeyPrefix(options, defaultConfig) {\n var keyPrefix = options.name + '/';\n\n if (options.storeName !== defaultConfig.storeName) {\n keyPrefix += options.storeName + '/';\n }\n return keyPrefix;\n}\n\n// Check if localStorage throws when saving an item\nfunction checkIfLocalStorageThrows() {\n var localStorageTestKey = '_localforage_support_test';\n\n try {\n localStorage.setItem(localStorageTestKey, true);\n localStorage.removeItem(localStorageTestKey);\n\n return false;\n } catch (e) {\n return true;\n }\n}\n\n// Check if localStorage is usable and allows to save an item\n// This method checks if localStorage is usable in Safari Private Browsing\n// mode, or in any other case where the available quota for localStorage\n// is 0 and there wasn't any saved items yet.\nfunction _isLocalStorageUsable() {\n return !checkIfLocalStorageThrows() || localStorage.length > 0;\n}\n\n// Config the localStorage backend, using options set in the config.\nfunction _initStorage$2(options) {\n var self = this;\n var dbInfo = {};\n if (options) {\n for (var i in options) {\n dbInfo[i] = options[i];\n }\n }\n\n dbInfo.keyPrefix = _getKeyPrefix(options, self._defaultConfig);\n\n if (!_isLocalStorageUsable()) {\n return Promise$1.reject();\n }\n\n self._dbInfo = dbInfo;\n dbInfo.serializer = localforageSerializer;\n\n return Promise$1.resolve();\n}\n\n// Remove all keys from the datastore, effectively destroying all data in\n// the app's key/value store!\nfunction clear$2(callback) {\n var self = this;\n var promise = self.ready().then(function () {\n var keyPrefix = self._dbInfo.keyPrefix;\n\n for (var i = localStorage.length - 1; i >= 0; i--) {\n var key = localStorage.key(i);\n\n if (key.indexOf(keyPrefix) === 0) {\n localStorage.removeItem(key);\n }\n }\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\n// Retrieve an item from the store. Unlike the original async_storage\n// library in Gaia, we don't modify return values at all. If a key's value\n// is `undefined`, we pass that value to the callback function.\nfunction getItem$2(key, callback) {\n var self = this;\n\n key = normalizeKey(key);\n\n var promise = self.ready().then(function () {\n var dbInfo = self._dbInfo;\n var result = localStorage.getItem(dbInfo.keyPrefix + key);\n\n // If a result was found, parse it from the serialized\n // string into a JS object. If result isn't truthy, the key\n // is likely undefined and we'll pass it straight to the\n // callback.\n if (result) {\n result = dbInfo.serializer.deserialize(result);\n }\n\n return result;\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\n// Iterate over all items in the store.\nfunction iterate$2(iterator, callback) {\n var self = this;\n\n var promise = self.ready().then(function () {\n var dbInfo = self._dbInfo;\n var keyPrefix = dbInfo.keyPrefix;\n var keyPrefixLength = keyPrefix.length;\n var length = localStorage.length;\n\n // We use a dedicated iterator instead of the `i` variable below\n // so other keys we fetch in localStorage aren't counted in\n // the `iterationNumber` argument passed to the `iterate()`\n // callback.\n //\n // See: github.com/mozilla/localForage/pull/435#discussion_r38061530\n var iterationNumber = 1;\n\n for (var i = 0; i < length; i++) {\n var key = localStorage.key(i);\n if (key.indexOf(keyPrefix) !== 0) {\n continue;\n }\n var value = localStorage.getItem(key);\n\n // If a result was found, parse it from the serialized\n // string into a JS object. If result isn't truthy, the\n // key is likely undefined and we'll pass it straight\n // to the iterator.\n if (value) {\n value = dbInfo.serializer.deserialize(value);\n }\n\n value = iterator(value, key.substring(keyPrefixLength), iterationNumber++);\n\n if (value !== void 0) {\n return value;\n }\n }\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\n// Same as localStorage's key() method, except takes a callback.\nfunction key$2(n, callback) {\n var self = this;\n var promise = self.ready().then(function () {\n var dbInfo = self._dbInfo;\n var result;\n try {\n result = localStorage.key(n);\n } catch (error) {\n result = null;\n }\n\n // Remove the prefix from the key, if a key is found.\n if (result) {\n result = result.substring(dbInfo.keyPrefix.length);\n }\n\n return result;\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction keys$2(callback) {\n var self = this;\n var promise = self.ready().then(function () {\n var dbInfo = self._dbInfo;\n var length = localStorage.length;\n var keys = [];\n\n for (var i = 0; i < length; i++) {\n var itemKey = localStorage.key(i);\n if (itemKey.indexOf(dbInfo.keyPrefix) === 0) {\n keys.push(itemKey.substring(dbInfo.keyPrefix.length));\n }\n }\n\n return keys;\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\n// Supply the number of keys in the datastore to the callback function.\nfunction length$2(callback) {\n var self = this;\n var promise = self.keys().then(function (keys) {\n return keys.length;\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\n// Remove an item from the store, nice and simple.\nfunction removeItem$2(key, callback) {\n var self = this;\n\n key = normalizeKey(key);\n\n var promise = self.ready().then(function () {\n var dbInfo = self._dbInfo;\n localStorage.removeItem(dbInfo.keyPrefix + key);\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\n// Set a key's value and run an optional callback once the value is set.\n// Unlike Gaia's implementation, the callback function is passed the value,\n// in case you want to operate on that value only after you're sure it\n// saved, or something like that.\nfunction setItem$2(key, value, callback) {\n var self = this;\n\n key = normalizeKey(key);\n\n var promise = self.ready().then(function () {\n // Convert undefined values to null.\n // https://github.com/mozilla/localForage/pull/42\n if (value === undefined) {\n value = null;\n }\n\n // Save the original value to pass to the callback.\n var originalValue = value;\n\n return new Promise$1(function (resolve, reject) {\n var dbInfo = self._dbInfo;\n dbInfo.serializer.serialize(value, function (value, error) {\n if (error) {\n reject(error);\n } else {\n try {\n localStorage.setItem(dbInfo.keyPrefix + key, value);\n resolve(originalValue);\n } catch (e) {\n // localStorage capacity exceeded.\n // TODO: Make this a specific error/event.\n if (e.name === 'QuotaExceededError' || e.name === 'NS_ERROR_DOM_QUOTA_REACHED') {\n reject(e);\n }\n reject(e);\n }\n }\n });\n });\n });\n\n executeCallback(promise, callback);\n return promise;\n}\n\nfunction dropInstance$2(options, callback) {\n callback = getCallback.apply(this, arguments);\n\n options = typeof options !== 'function' && options || {};\n if (!options.name) {\n var currentConfig = this.config();\n options.name = options.name || currentConfig.name;\n options.storeName = options.storeName || currentConfig.storeName;\n }\n\n var self = this;\n var promise;\n if (!options.name) {\n promise = Promise$1.reject('Invalid arguments');\n } else {\n promise = new Promise$1(function (resolve) {\n if (!options.storeName) {\n resolve(options.name + '/');\n } else {\n resolve(_getKeyPrefix(options, self._defaultConfig));\n }\n }).then(function (keyPrefix) {\n for (var i = localStorage.length - 1; i >= 0; i--) {\n var key = localStorage.key(i);\n\n if (key.indexOf(keyPrefix) === 0) {\n localStorage.removeItem(key);\n }\n }\n });\n }\n\n executeCallback(promise, callback);\n return promise;\n}\n\nvar localStorageWrapper = {\n _driver: 'localStorageWrapper',\n _initStorage: _initStorage$2,\n _support: isLocalStorageValid(),\n iterate: iterate$2,\n getItem: getItem$2,\n setItem: setItem$2,\n removeItem: removeItem$2,\n clear: clear$2,\n length: length$2,\n key: key$2,\n keys: keys$2,\n dropInstance: dropInstance$2\n};\n\nvar sameValue = function sameValue(x, y) {\n return x === y || typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y);\n};\n\nvar includes = function includes(array, searchElement) {\n var len = array.length;\n var i = 0;\n while (i < len) {\n if (sameValue(array[i], searchElement)) {\n return true;\n }\n i++;\n }\n\n return false;\n};\n\nvar isArray = Array.isArray || function (arg) {\n return Object.prototype.toString.call(arg) === '[object Array]';\n};\n\n// Drivers are stored here when `defineDriver()` is called.\n// They are shared across all instances of localForage.\nvar DefinedDrivers = {};\n\nvar DriverSupport = {};\n\nvar DefaultDrivers = {\n INDEXEDDB: asyncStorage,\n WEBSQL: webSQLStorage,\n LOCALSTORAGE: localStorageWrapper\n};\n\nvar DefaultDriverOrder = [DefaultDrivers.INDEXEDDB._driver, DefaultDrivers.WEBSQL._driver, DefaultDrivers.LOCALSTORAGE._driver];\n\nvar OptionalDriverMethods = ['dropInstance'];\n\nvar LibraryMethods = ['clear', 'getItem', 'iterate', 'key', 'keys', 'length', 'removeItem', 'setItem'].concat(OptionalDriverMethods);\n\nvar DefaultConfig = {\n description: '',\n driver: DefaultDriverOrder.slice(),\n name: 'localforage',\n // Default DB size is _JUST UNDER_ 5MB, as it's the highest size\n // we can use without a prompt.\n size: 4980736,\n storeName: 'keyvaluepairs',\n version: 1.0\n};\n\nfunction callWhenReady(localForageInstance, libraryMethod) {\n localForageInstance[libraryMethod] = function () {\n var _args = arguments;\n return localForageInstance.ready().then(function () {\n return localForageInstance[libraryMethod].apply(localForageInstance, _args);\n });\n };\n}\n\nfunction extend() {\n for (var i = 1; i < arguments.length; i++) {\n var arg = arguments[i];\n\n if (arg) {\n for (var _key in arg) {\n if (arg.hasOwnProperty(_key)) {\n if (isArray(arg[_key])) {\n arguments[0][_key] = arg[_key].slice();\n } else {\n arguments[0][_key] = arg[_key];\n }\n }\n }\n }\n }\n\n return arguments[0];\n}\n\nvar LocalForage = function () {\n function LocalForage(options) {\n _classCallCheck(this, LocalForage);\n\n for (var driverTypeKey in DefaultDrivers) {\n if (DefaultDrivers.hasOwnProperty(driverTypeKey)) {\n var driver = DefaultDrivers[driverTypeKey];\n var driverName = driver._driver;\n this[driverTypeKey] = driverName;\n\n if (!DefinedDrivers[driverName]) {\n // we don't need to wait for the promise,\n // since the default drivers can be defined\n // in a blocking manner\n this.defineDriver(driver);\n }\n }\n }\n\n this._defaultConfig = extend({}, DefaultConfig);\n this._config = extend({}, this._defaultConfig, options);\n this._driverSet = null;\n this._initDriver = null;\n this._ready = false;\n this._dbInfo = null;\n\n this._wrapLibraryMethodsWithReady();\n this.setDriver(this._config.driver)[\"catch\"](function () {});\n }\n\n // Set any config values for localForage; can be called anytime before\n // the first API call (e.g. `getItem`, `setItem`).\n // We loop through options so we don't overwrite existing config\n // values.\n\n\n LocalForage.prototype.config = function config(options) {\n // If the options argument is an object, we use it to set values.\n // Otherwise, we return either a specified config value or all\n // config values.\n if ((typeof options === 'undefined' ? 'undefined' : _typeof(options)) === 'object') {\n // If localforage is ready and fully initialized, we can't set\n // any new configuration values. Instead, we return an error.\n if (this._ready) {\n return new Error(\"Can't call config() after localforage \" + 'has been used.');\n }\n\n for (var i in options) {\n if (i === 'storeName') {\n options[i] = options[i].replace(/\\W/g, '_');\n }\n\n if (i === 'version' && typeof options[i] !== 'number') {\n return new Error('Database version must be a number.');\n }\n\n this._config[i] = options[i];\n }\n\n // after all config options are set and\n // the driver option is used, try setting it\n if ('driver' in options && options.driver) {\n return this.setDriver(this._config.driver);\n }\n\n return true;\n } else if (typeof options === 'string') {\n return this._config[options];\n } else {\n return this._config;\n }\n };\n\n // Used to define a custom driver, shared across all instances of\n // localForage.\n\n\n LocalForage.prototype.defineDriver = function defineDriver(driverObject, callback, errorCallback) {\n var promise = new Promise$1(function (resolve, reject) {\n try {\n var driverName = driverObject._driver;\n var complianceError = new Error('Custom driver not compliant; see ' + 'https://mozilla.github.io/localForage/#definedriver');\n\n // A driver name should be defined and not overlap with the\n // library-defined, default drivers.\n if (!driverObject._driver) {\n reject(complianceError);\n return;\n }\n\n var driverMethods = LibraryMethods.concat('_initStorage');\n for (var i = 0, len = driverMethods.length; i < len; i++) {\n var driverMethodName = driverMethods[i];\n\n // when the property is there,\n // it should be a method even when optional\n var isRequired = !includes(OptionalDriverMethods, driverMethodName);\n if ((isRequired || driverObject[driverMethodName]) && typeof driverObject[driverMethodName] !== 'function') {\n reject(complianceError);\n return;\n }\n }\n\n var configureMissingMethods = function configureMissingMethods() {\n var methodNotImplementedFactory = function methodNotImplementedFactory(methodName) {\n return function () {\n var error = new Error('Method ' + methodName + ' is not implemented by the current driver');\n var promise = Promise$1.reject(error);\n executeCallback(promise, arguments[arguments.length - 1]);\n return promise;\n };\n };\n\n for (var _i = 0, _len = OptionalDriverMethods.length; _i < _len; _i++) {\n var optionalDriverMethod = OptionalDriverMethods[_i];\n if (!driverObject[optionalDriverMethod]) {\n driverObject[optionalDriverMethod] = methodNotImplementedFactory(optionalDriverMethod);\n }\n }\n };\n\n configureMissingMethods();\n\n var setDriverSupport = function setDriverSupport(support) {\n if (DefinedDrivers[driverName]) {\n console.info('Redefining LocalForage driver: ' + driverName);\n }\n DefinedDrivers[driverName] = driverObject;\n DriverSupport[driverName] = support;\n // don't use a then, so that we can define\n // drivers that have simple _support methods\n // in a blocking manner\n resolve();\n };\n\n if ('_support' in driverObject) {\n if (driverObject._support && typeof driverObject._support === 'function') {\n driverObject._support().then(setDriverSupport, reject);\n } else {\n setDriverSupport(!!driverObject._support);\n }\n } else {\n setDriverSupport(true);\n }\n } catch (e) {\n reject(e);\n }\n });\n\n executeTwoCallbacks(promise, callback, errorCallback);\n return promise;\n };\n\n LocalForage.prototype.driver = function driver() {\n return this._driver || null;\n };\n\n LocalForage.prototype.getDriver = function getDriver(driverName, callback, errorCallback) {\n var getDriverPromise = DefinedDrivers[driverName] ? Promise$1.resolve(DefinedDrivers[driverName]) : Promise$1.reject(new Error('Driver not found.'));\n\n executeTwoCallbacks(getDriverPromise, callback, errorCallback);\n return getDriverPromise;\n };\n\n LocalForage.prototype.getSerializer = function getSerializer(callback) {\n var serializerPromise = Promise$1.resolve(localforageSerializer);\n executeTwoCallbacks(serializerPromise, callback);\n return serializerPromise;\n };\n\n LocalForage.prototype.ready = function ready(callback) {\n var self = this;\n\n var promise = self._driverSet.then(function () {\n if (self._ready === null) {\n self._ready = self._initDriver();\n }\n\n return self._ready;\n });\n\n executeTwoCallbacks(promise, callback, callback);\n return promise;\n };\n\n LocalForage.prototype.setDriver = function setDriver(drivers, callback, errorCallback) {\n var self = this;\n\n if (!isArray(drivers)) {\n drivers = [drivers];\n }\n\n var supportedDrivers = this._getSupportedDrivers(drivers);\n\n function setDriverToConfig() {\n self._config.driver = self.driver();\n }\n\n function extendSelfWithDriver(driver) {\n self._extend(driver);\n setDriverToConfig();\n\n self._ready = self._initStorage(self._config);\n return self._ready;\n }\n\n function initDriver(supportedDrivers) {\n return function () {\n var currentDriverIndex = 0;\n\n function driverPromiseLoop() {\n while (currentDriverIndex < supportedDrivers.length) {\n var driverName = supportedDrivers[currentDriverIndex];\n currentDriverIndex++;\n\n self._dbInfo = null;\n self._ready = null;\n\n return self.getDriver(driverName).then(extendSelfWithDriver)[\"catch\"](driverPromiseLoop);\n }\n\n setDriverToConfig();\n var error = new Error('No available storage method found.');\n self._driverSet = Promise$1.reject(error);\n return self._driverSet;\n }\n\n return driverPromiseLoop();\n };\n }\n\n // There might be a driver initialization in progress\n // so wait for it to finish in order to avoid a possible\n // race condition to set _dbInfo\n var oldDriverSetDone = this._driverSet !== null ? this._driverSet[\"catch\"](function () {\n return Promise$1.resolve();\n }) : Promise$1.resolve();\n\n this._driverSet = oldDriverSetDone.then(function () {\n var driverName = supportedDrivers[0];\n self._dbInfo = null;\n self._ready = null;\n\n return self.getDriver(driverName).then(function (driver) {\n self._driver = driver._driver;\n setDriverToConfig();\n self._wrapLibraryMethodsWithReady();\n self._initDriver = initDriver(supportedDrivers);\n });\n })[\"catch\"](function () {\n setDriverToConfig();\n var error = new Error('No available storage method found.');\n self._driverSet = Promise$1.reject(error);\n return self._driverSet;\n });\n\n executeTwoCallbacks(this._driverSet, callback, errorCallback);\n return this._driverSet;\n };\n\n LocalForage.prototype.supports = function supports(driverName) {\n return !!DriverSupport[driverName];\n };\n\n LocalForage.prototype._extend = function _extend(libraryMethodsAndProperties) {\n extend(this, libraryMethodsAndProperties);\n };\n\n LocalForage.prototype._getSupportedDrivers = function _getSupportedDrivers(drivers) {\n var supportedDrivers = [];\n for (var i = 0, len = drivers.length; i < len; i++) {\n var driverName = drivers[i];\n if (this.supports(driverName)) {\n supportedDrivers.push(driverName);\n }\n }\n return supportedDrivers;\n };\n\n LocalForage.prototype._wrapLibraryMethodsWithReady = function _wrapLibraryMethodsWithReady() {\n // Add a stub for each driver API method that delays the call to the\n // corresponding driver method until localForage is ready. These stubs\n // will be replaced by the driver methods as soon as the driver is\n // loaded, so there is no performance impact.\n for (var i = 0, len = LibraryMethods.length; i < len; i++) {\n callWhenReady(this, LibraryMethods[i]);\n }\n };\n\n LocalForage.prototype.createInstance = function createInstance(options) {\n return new LocalForage(options);\n };\n\n return LocalForage;\n}();\n\n// The actual localForage object that we expose as a module or via a\n// global. It's extended by pulling in one of our other libraries.\n\n\nvar localforage_js = new LocalForage();\n\nmodule.exports = localforage_js;\n\n},{\"3\":3}]},{},[4])(4)\n});\n", "const {\n entries,\n setPrototypeOf,\n isFrozen,\n getPrototypeOf,\n getOwnPropertyDescriptor,\n} = Object;\n\nlet { freeze, seal, create } = Object; // eslint-disable-line import/no-mutable-exports\nlet { apply, construct } = typeof Reflect !== 'undefined' && Reflect;\n\nif (!freeze) {\n freeze = function (x: T): T {\n return x;\n };\n}\n\nif (!seal) {\n seal = function (x: T): T {\n return x;\n };\n}\n\nif (!apply) {\n apply = function (\n func: (thisArg: any, ...args: any[]) => T,\n thisArg: any,\n ...args: any[]\n ): T {\n return func.apply(thisArg, args);\n };\n}\n\nif (!construct) {\n construct = function (Func: new (...args: any[]) => T, ...args: any[]): T {\n return new Func(...args);\n };\n}\n\nconst arrayForEach = unapply(Array.prototype.forEach);\nconst arrayIndexOf = unapply(Array.prototype.indexOf);\nconst arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);\nconst arrayPop = unapply(Array.prototype.pop);\nconst arrayPush = unapply(Array.prototype.push);\nconst arraySlice = unapply(Array.prototype.slice);\nconst arraySplice = unapply(Array.prototype.splice);\nconst arrayIsArray = Array.isArray;\n\nconst stringToLowerCase = unapply(String.prototype.toLowerCase);\nconst stringToString = unapply(String.prototype.toString);\nconst stringMatch = unapply(String.prototype.match);\nconst stringReplace = unapply(String.prototype.replace);\nconst stringIndexOf = unapply(String.prototype.indexOf);\nconst stringTrim = unapply(String.prototype.trim);\n\nconst numberToString = unapply(Number.prototype.toString);\nconst booleanToString = unapply(Boolean.prototype.toString);\nconst bigintToString =\n typeof BigInt === 'undefined' ? null : unapply(BigInt.prototype.toString);\nconst symbolToString =\n typeof Symbol === 'undefined' ? null : unapply(Symbol.prototype.toString);\n\nconst objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);\nconst objectToString = unapply(Object.prototype.toString);\n\nconst regExpTest = unapply(RegExp.prototype.test);\n\nconst typeErrorCreate = unconstruct(TypeError);\n\n/**\n * Creates a new function that calls the given function with a specified thisArg and arguments.\n *\n * @param func - The function to be wrapped and called.\n * @returns A new function that calls the given function with a specified thisArg and arguments.\n */\nfunction unapply(\n func: (thisArg: any, ...args: any[]) => T\n): (thisArg: any, ...args: any[]) => T {\n return (thisArg: any, ...args: any[]): T => {\n if (thisArg instanceof RegExp) {\n thisArg.lastIndex = 0;\n }\n\n return apply(func, thisArg, args);\n };\n}\n\n/**\n * Creates a new function that constructs an instance of the given constructor function with the provided arguments.\n *\n * @param func - The constructor function to be wrapped and called.\n * @returns A new function that constructs an instance of the given constructor function with the provided arguments.\n */\nfunction unconstruct(\n Func: new (...args: any[]) => T\n): (...args: any[]) => T {\n return (...args: any[]): T => construct(Func, args);\n}\n\n/**\n * Add properties to a lookup table\n *\n * @param set - The set to which elements will be added.\n * @param array - The array containing elements to be added to the set.\n * @param transformCaseFunc - An optional function to transform the case of each element before adding to the set.\n * @returns The modified set with added elements.\n */\nfunction addToSet(\n set: Record,\n array: readonly unknown[],\n transformCaseFunc: ReturnType> = stringToLowerCase\n): Record {\n if (setPrototypeOf) {\n // Make 'in' and truthy checks like Boolean(set.constructor)\n // independent of any properties defined on Object.prototype.\n // Prevent prototype setters from intercepting set as a this value.\n setPrototypeOf(set, null);\n }\n\n if (!arrayIsArray(array)) {\n return set;\n }\n\n let l = array.length;\n while (l--) {\n let element = array[l];\n\n if (typeof element === 'string') {\n const lcElement = transformCaseFunc(element);\n\n if (lcElement !== element) {\n // Config presets (e.g. tags.js, attrs.js) are immutable.\n if (!isFrozen(array)) {\n (array as unknown[])[l] = lcElement;\n }\n\n element = lcElement;\n }\n }\n\n set[element as string] = true;\n }\n\n return set;\n}\n\n/**\n * Clean up an array to harden against CSPP\n *\n * @param array - The array to be cleaned.\n * @returns The cleaned version of the array\n */\nfunction cleanArray(array: T[]): Array {\n for (let index = 0; index < array.length; index++) {\n const isPropertyExist = objectHasOwnProperty(array, index);\n\n if (!isPropertyExist) {\n array[index] = null;\n }\n }\n\n return array;\n}\n\n/**\n * Shallow clone an object\n *\n * @param object - The object to be cloned.\n * @returns A new object that copies the original.\n */\nfunction clone>(object: T): T {\n const newObject = create(null);\n\n for (const [property, value] of entries(object)) {\n const isPropertyExist = objectHasOwnProperty(object, property);\n\n if (isPropertyExist) {\n if (arrayIsArray(value)) {\n newObject[property] = cleanArray(value);\n } else if (\n value &&\n typeof value === 'object' &&\n value.constructor === Object\n ) {\n newObject[property] = clone(value);\n } else {\n newObject[property] = value;\n }\n }\n }\n\n return newObject;\n}\n\n/**\n * Convert non-node values into strings without depending on direct property access.\n *\n * @param value - The value to stringify.\n * @returns A string representation of the provided value.\n */\nfunction stringifyValue(value: unknown): string {\n switch (typeof value) {\n case 'string': {\n return value;\n }\n\n case 'number': {\n return numberToString(value);\n }\n\n case 'boolean': {\n return booleanToString(value);\n }\n\n case 'bigint': {\n return bigintToString ? bigintToString(value) : '0';\n }\n\n case 'symbol': {\n return symbolToString ? symbolToString(value) : 'Symbol()';\n }\n\n case 'undefined': {\n return objectToString(value);\n }\n\n case 'function':\n case 'object': {\n if (value === null) {\n return objectToString(value);\n }\n\n const valueAsRecord = value as Record;\n const valueToString = lookupGetter(valueAsRecord, 'toString');\n\n if (typeof valueToString === 'function') {\n const stringified = valueToString(valueAsRecord);\n\n return typeof stringified === 'string'\n ? stringified\n : objectToString(stringified);\n }\n\n return objectToString(value);\n }\n\n default: {\n return objectToString(value);\n }\n }\n}\n\n/**\n * This method automatically checks if the prop is function or getter and behaves accordingly.\n *\n * @param object - The object to look up the getter function in its prototype chain.\n * @param prop - The property name for which to find the getter function.\n * @returns The getter function found in the prototype chain or a fallback function.\n */\nfunction lookupGetter>(\n object: T,\n prop: string\n): ReturnType> | (() => null) {\n while (object !== null) {\n const desc = getOwnPropertyDescriptor(object, prop);\n\n if (desc) {\n if (desc.get) {\n return unapply(desc.get);\n }\n\n if (typeof desc.value === 'function') {\n return unapply(desc.value);\n }\n }\n\n object = getPrototypeOf(object);\n }\n\n function fallbackValue(): null {\n return null;\n }\n\n return fallbackValue;\n}\n\nfunction isRegex(value: unknown): value is RegExp {\n try {\n regExpTest(value as RegExp, '');\n return true;\n } catch {\n return false;\n }\n}\n\nexport {\n // Array\n arrayForEach,\n arrayIndexOf,\n arrayIsArray,\n arrayLastIndexOf,\n arrayPop,\n arrayPush,\n arraySlice,\n arraySplice,\n // Object\n entries,\n freeze,\n getPrototypeOf,\n getOwnPropertyDescriptor,\n isFrozen,\n setPrototypeOf,\n seal,\n clone,\n create,\n objectHasOwnProperty,\n objectToString,\n // RegExp\n regExpTest,\n isRegex,\n // String\n stringIndexOf,\n stringMatch,\n stringReplace,\n stringToLowerCase,\n stringToString,\n stringTrim,\n // Other conversion\n stringifyValue,\n // Errors\n typeErrorCreate,\n // Other\n lookupGetter,\n addToSet,\n // Reflect\n unapply,\n unconstruct,\n};\n", "import { freeze } from './utils.js';\n\nexport const html = freeze([\n 'a',\n 'abbr',\n 'acronym',\n 'address',\n 'area',\n 'article',\n 'aside',\n 'audio',\n 'b',\n 'bdi',\n 'bdo',\n 'big',\n 'blink',\n 'blockquote',\n 'body',\n 'br',\n 'button',\n 'canvas',\n 'caption',\n 'center',\n 'cite',\n 'code',\n 'col',\n 'colgroup',\n 'content',\n 'data',\n 'datalist',\n 'dd',\n 'decorator',\n 'del',\n 'details',\n 'dfn',\n 'dialog',\n 'dir',\n 'div',\n 'dl',\n 'dt',\n 'element',\n 'em',\n 'fieldset',\n 'figcaption',\n 'figure',\n 'font',\n 'footer',\n 'form',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'head',\n 'header',\n 'hgroup',\n 'hr',\n 'html',\n 'i',\n 'img',\n 'input',\n 'ins',\n 'kbd',\n 'label',\n 'legend',\n 'li',\n 'main',\n 'map',\n 'mark',\n 'marquee',\n 'menu',\n 'menuitem',\n 'meter',\n 'nav',\n 'nobr',\n 'ol',\n 'optgroup',\n 'option',\n 'output',\n 'p',\n 'picture',\n 'pre',\n 'progress',\n 'q',\n 'rp',\n 'rt',\n 'ruby',\n 's',\n 'samp',\n 'search',\n 'section',\n 'select',\n 'shadow',\n 'slot',\n 'small',\n 'source',\n 'spacer',\n 'span',\n 'strike',\n 'strong',\n 'style',\n 'sub',\n 'summary',\n 'sup',\n 'table',\n 'tbody',\n 'td',\n 'template',\n 'textarea',\n 'tfoot',\n 'th',\n 'thead',\n 'time',\n 'tr',\n 'track',\n 'tt',\n 'u',\n 'ul',\n 'var',\n 'video',\n 'wbr',\n] as const);\n\nexport const svg = freeze([\n 'svg',\n 'a',\n 'altglyph',\n 'altglyphdef',\n 'altglyphitem',\n 'animatecolor',\n 'animatemotion',\n 'animatetransform',\n 'circle',\n 'clippath',\n 'defs',\n 'desc',\n 'ellipse',\n 'enterkeyhint',\n 'exportparts',\n 'filter',\n 'font',\n 'g',\n 'glyph',\n 'glyphref',\n 'hkern',\n 'image',\n 'inputmode',\n 'line',\n 'lineargradient',\n 'marker',\n 'mask',\n 'metadata',\n 'mpath',\n 'part',\n 'path',\n 'pattern',\n 'polygon',\n 'polyline',\n 'radialgradient',\n 'rect',\n 'stop',\n 'style',\n 'switch',\n 'symbol',\n 'text',\n 'textpath',\n 'title',\n 'tref',\n 'tspan',\n 'view',\n 'vkern',\n] as const);\n\nexport const svgFilters = freeze([\n 'feBlend',\n 'feColorMatrix',\n 'feComponentTransfer',\n 'feComposite',\n 'feConvolveMatrix',\n 'feDiffuseLighting',\n 'feDisplacementMap',\n 'feDistantLight',\n 'feDropShadow',\n 'feFlood',\n 'feFuncA',\n 'feFuncB',\n 'feFuncG',\n 'feFuncR',\n 'feGaussianBlur',\n 'feImage',\n 'feMerge',\n 'feMergeNode',\n 'feMorphology',\n 'feOffset',\n 'fePointLight',\n 'feSpecularLighting',\n 'feSpotLight',\n 'feTile',\n 'feTurbulence',\n] as const);\n\n// List of SVG elements that are disallowed by default.\n// We still need to know them so that we can do namespace\n// checks properly in case one wants to add them to\n// allow-list.\nexport const svgDisallowed = freeze([\n 'animate',\n 'color-profile',\n 'cursor',\n 'discard',\n 'font-face',\n 'font-face-format',\n 'font-face-name',\n 'font-face-src',\n 'font-face-uri',\n 'foreignobject',\n 'hatch',\n 'hatchpath',\n 'mesh',\n 'meshgradient',\n 'meshpatch',\n 'meshrow',\n 'missing-glyph',\n 'script',\n 'set',\n 'solidcolor',\n 'unknown',\n 'use',\n] as const);\n\nexport const mathMl = freeze([\n 'math',\n 'menclose',\n 'merror',\n 'mfenced',\n 'mfrac',\n 'mglyph',\n 'mi',\n 'mlabeledtr',\n 'mmultiscripts',\n 'mn',\n 'mo',\n 'mover',\n 'mpadded',\n 'mphantom',\n 'mroot',\n 'mrow',\n 'ms',\n 'mspace',\n 'msqrt',\n 'mstyle',\n 'msub',\n 'msup',\n 'msubsup',\n 'mtable',\n 'mtd',\n 'mtext',\n 'mtr',\n 'munder',\n 'munderover',\n 'mprescripts',\n] as const);\n\n// Similarly to SVG, we want to know all MathML elements,\n// even those that we disallow by default.\nexport const mathMlDisallowed = freeze([\n 'maction',\n 'maligngroup',\n 'malignmark',\n 'mlongdiv',\n 'mscarries',\n 'mscarry',\n 'msgroup',\n 'mstack',\n 'msline',\n 'msrow',\n 'semantics',\n 'annotation',\n 'annotation-xml',\n 'mprescripts',\n 'none',\n] as const);\n\nexport const text = freeze(['#text'] as const);\n", "import { freeze } from './utils.js';\n\nexport const html = freeze([\n 'accept',\n 'action',\n 'align',\n 'alt',\n 'autocapitalize',\n 'autocomplete',\n 'autopictureinpicture',\n 'autoplay',\n 'background',\n 'bgcolor',\n 'border',\n 'capture',\n 'cellpadding',\n 'cellspacing',\n 'checked',\n 'cite',\n 'class',\n 'clear',\n 'color',\n 'cols',\n 'colspan',\n 'command',\n 'commandfor',\n 'controls',\n 'controlslist',\n 'coords',\n 'crossorigin',\n 'datetime',\n 'decoding',\n 'default',\n 'dir',\n 'disabled',\n 'disablepictureinpicture',\n 'disableremoteplayback',\n 'download',\n 'draggable',\n 'enctype',\n 'enterkeyhint',\n 'exportparts',\n 'face',\n 'for',\n 'headers',\n 'height',\n 'hidden',\n 'high',\n 'href',\n 'hreflang',\n 'id',\n 'inert',\n 'inputmode',\n 'integrity',\n 'ismap',\n 'kind',\n 'label',\n 'lang',\n 'list',\n 'loading',\n 'loop',\n 'low',\n 'max',\n 'maxlength',\n 'media',\n 'method',\n 'min',\n 'minlength',\n 'multiple',\n 'muted',\n 'name',\n 'nonce',\n 'noshade',\n 'novalidate',\n 'nowrap',\n 'open',\n 'optimum',\n 'part',\n 'pattern',\n 'placeholder',\n 'playsinline',\n 'popover',\n 'popovertarget',\n 'popovertargetaction',\n 'poster',\n 'preload',\n 'pubdate',\n 'radiogroup',\n 'readonly',\n 'rel',\n 'required',\n 'rev',\n 'reversed',\n 'role',\n 'rows',\n 'rowspan',\n 'spellcheck',\n 'scope',\n 'selected',\n 'shape',\n 'size',\n 'sizes',\n 'slot',\n 'span',\n 'srclang',\n 'start',\n 'src',\n 'srcset',\n 'step',\n 'style',\n 'summary',\n 'tabindex',\n 'title',\n 'translate',\n 'type',\n 'usemap',\n 'valign',\n 'value',\n 'width',\n 'wrap',\n 'xmlns',\n] as const);\n\nexport const svg = freeze([\n 'accent-height',\n 'accumulate',\n 'additive',\n 'alignment-baseline',\n 'amplitude',\n 'ascent',\n 'attributename',\n 'attributetype',\n 'azimuth',\n 'basefrequency',\n 'baseline-shift',\n 'begin',\n 'bias',\n 'by',\n 'class',\n 'clip',\n 'clippathunits',\n 'clip-path',\n 'clip-rule',\n 'color',\n 'color-interpolation',\n 'color-interpolation-filters',\n 'color-profile',\n 'color-rendering',\n 'cx',\n 'cy',\n 'd',\n 'dx',\n 'dy',\n 'diffuseconstant',\n 'direction',\n 'display',\n 'divisor',\n 'dominant-baseline',\n 'dur',\n 'edgemode',\n 'elevation',\n 'end',\n 'exponent',\n 'fill',\n 'fill-opacity',\n 'fill-rule',\n 'filter',\n 'filterunits',\n 'flood-color',\n 'flood-opacity',\n 'font-family',\n 'font-size',\n 'font-size-adjust',\n 'font-stretch',\n 'font-style',\n 'font-variant',\n 'font-weight',\n 'fx',\n 'fy',\n 'g1',\n 'g2',\n 'glyph-name',\n 'glyphref',\n 'gradientunits',\n 'gradienttransform',\n 'height',\n 'href',\n 'id',\n 'image-rendering',\n 'in',\n 'in2',\n 'intercept',\n 'k',\n 'k1',\n 'k2',\n 'k3',\n 'k4',\n 'kerning',\n 'keypoints',\n 'keysplines',\n 'keytimes',\n 'lang',\n 'lengthadjust',\n 'letter-spacing',\n 'kernelmatrix',\n 'kernelunitlength',\n 'lighting-color',\n 'local',\n 'marker-end',\n 'marker-mid',\n 'marker-start',\n 'markerheight',\n 'markerunits',\n 'markerwidth',\n 'maskcontentunits',\n 'maskunits',\n 'max',\n 'mask',\n 'mask-type',\n 'media',\n 'method',\n 'mode',\n 'min',\n 'name',\n 'numoctaves',\n 'offset',\n 'operator',\n 'opacity',\n 'order',\n 'orient',\n 'orientation',\n 'origin',\n 'overflow',\n 'paint-order',\n 'path',\n 'pathlength',\n 'patterncontentunits',\n 'patterntransform',\n 'patternunits',\n 'points',\n 'preservealpha',\n 'preserveaspectratio',\n 'primitiveunits',\n 'r',\n 'rx',\n 'ry',\n 'radius',\n 'refx',\n 'refy',\n 'repeatcount',\n 'repeatdur',\n 'restart',\n 'result',\n 'rotate',\n 'scale',\n 'seed',\n 'shape-rendering',\n 'slope',\n 'specularconstant',\n 'specularexponent',\n 'spreadmethod',\n 'startoffset',\n 'stddeviation',\n 'stitchtiles',\n 'stop-color',\n 'stop-opacity',\n 'stroke-dasharray',\n 'stroke-dashoffset',\n 'stroke-linecap',\n 'stroke-linejoin',\n 'stroke-miterlimit',\n 'stroke-opacity',\n 'stroke',\n 'stroke-width',\n 'style',\n 'surfacescale',\n 'systemlanguage',\n 'tabindex',\n 'tablevalues',\n 'targetx',\n 'targety',\n 'transform',\n 'transform-origin',\n 'text-anchor',\n 'text-decoration',\n 'text-orientation',\n 'text-rendering',\n 'textlength',\n 'type',\n 'u1',\n 'u2',\n 'unicode',\n 'values',\n 'viewbox',\n 'visibility',\n 'version',\n 'vert-adv-y',\n 'vert-origin-x',\n 'vert-origin-y',\n 'width',\n 'word-spacing',\n 'wrap',\n 'writing-mode',\n 'xchannelselector',\n 'ychannelselector',\n 'x',\n 'x1',\n 'x2',\n 'xmlns',\n 'y',\n 'y1',\n 'y2',\n 'z',\n 'zoomandpan',\n] as const);\n\nexport const mathMl = freeze([\n 'accent',\n 'accentunder',\n 'align',\n 'bevelled',\n 'close',\n 'columnalign',\n 'columnlines',\n 'columnspacing',\n 'columnspan',\n 'denomalign',\n 'depth',\n 'dir',\n 'display',\n 'displaystyle',\n 'encoding',\n 'fence',\n 'frame',\n 'height',\n 'href',\n 'id',\n 'largeop',\n 'length',\n 'linethickness',\n 'lquote',\n 'lspace',\n 'mathbackground',\n 'mathcolor',\n 'mathsize',\n 'mathvariant',\n 'maxsize',\n 'minsize',\n 'movablelimits',\n 'notation',\n 'numalign',\n 'open',\n 'rowalign',\n 'rowlines',\n 'rowspacing',\n 'rowspan',\n 'rspace',\n 'rquote',\n 'scriptlevel',\n 'scriptminsize',\n 'scriptsizemultiplier',\n 'selection',\n 'separator',\n 'separators',\n 'stretchy',\n 'subscriptshift',\n 'supscriptshift',\n 'symmetric',\n 'voffset',\n 'width',\n 'xmlns',\n]);\n\nexport const xml = freeze([\n 'xlink:href',\n 'xml:id',\n 'xlink:title',\n 'xml:space',\n 'xmlns:xlink',\n] as const);\n", "import { seal } from './utils.js';\n\nexport const MUSTACHE_EXPR = seal(/{{[\\w\\W]*|^[\\w\\W]*}}/g);\nexport const ERB_EXPR = seal(/<%[\\w\\W]*|^[\\w\\W]*%>/g);\nexport const TMPLIT_EXPR = seal(/\\${[\\w\\W]*/g);\nexport const DATA_ATTR = seal(/^data-[\\-\\w.\\u00B7-\\uFFFF]+$/); // eslint-disable-line no-useless-escape\nexport const ARIA_ATTR = seal(/^aria-[\\-\\w]+$/); // eslint-disable-line no-useless-escape\nexport const IS_ALLOWED_URI = seal(\n /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\\-]+(?:[^a-z+.\\-:]|$))/i // eslint-disable-line no-useless-escape\n);\nexport const IS_SCRIPT_OR_DATA = seal(/^(?:\\w+script|data):/i);\nexport const ATTR_WHITESPACE = seal(\n /[\\u0000-\\u0020\\u00A0\\u1680\\u180E\\u2000-\\u2029\\u205F\\u3000]/g // eslint-disable-line no-control-regex\n);\nexport const DOCTYPE_NAME = seal(/^html$/i);\nexport const CUSTOM_ELEMENT = seal(/^[a-z][.\\w]*(-[.\\w]+)+$/i);\n\n// Markup-significant character probes used by _sanitizeElements.\n// Shared module-level instances are safe despite the sticky /g flags:\n// unapply() resets lastIndex for RegExp receivers before every call.\nexport const ELEMENT_MARKUP_PROBE = seal(/<[/\\w!]/g);\nexport const COMMENT_MARKUP_PROBE = seal(/<[/\\w]/g);\nexport const FALLBACK_TAG_CLOSE = seal(/<\\/no(script|embed|frames)/i);\nexport const SELF_CLOSING_TAG = seal(/\\/>/i);\n", "import type { Config, UseProfilesConfig } from './config';\nimport type { DOMPurify, HooksMap, HookFunction, WindowLike } from './types';\nimport * as TAGS from './tags.js';\nimport * as ATTRS from './attrs.js';\nimport * as EXPRESSIONS from './regexp.js';\nimport {\n addToSet,\n clone,\n entries,\n freeze,\n seal,\n arrayForEach,\n arrayIsArray,\n arrayLastIndexOf,\n arrayPop,\n arrayPush,\n arraySplice,\n stringMatch,\n stringReplace,\n stringToLowerCase,\n stringToString,\n stringIndexOf,\n stringTrim,\n regExpTest,\n isRegex,\n typeErrorCreate,\n lookupGetter,\n create,\n objectHasOwnProperty,\n stringifyValue,\n} from './utils.js';\n\nexport type { Config } from './config';\n\nexport type {\n DOMPurify,\n RemovedElement,\n RemovedAttribute,\n HookName,\n NodeHook,\n ElementHook,\n DocumentFragmentHook,\n UponSanitizeElementHook,\n UponSanitizeAttributeHook,\n UponSanitizeElementHookEvent,\n UponSanitizeAttributeHookEvent,\n WindowLike,\n} from './types';\n\ndeclare const VERSION: string;\n\n// https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType\nconst NODE_TYPE = {\n element: 1,\n attribute: 2,\n text: 3,\n cdataSection: 4,\n entityReference: 5, // Deprecated\n entityNode: 6, // Deprecated\n processingInstruction: 7,\n comment: 8,\n document: 9,\n documentType: 10,\n documentFragment: 11,\n notation: 12, // Deprecated\n};\n\nconst getGlobal = function (): WindowLike {\n return typeof window === 'undefined' ? null : window;\n};\n\n/**\n * Creates a no-op policy for internal use only.\n * Don't export this function outside this module!\n * @param trustedTypes The policy factory.\n * @param purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).\n * @return The policy created (or null, if Trusted Types\n * are not supported or creating the policy failed).\n */\nconst _createTrustedTypesPolicy = function (\n trustedTypes: TrustedTypePolicyFactory,\n purifyHostElement: HTMLScriptElement\n) {\n if (\n typeof trustedTypes !== 'object' ||\n typeof trustedTypes.createPolicy !== 'function'\n ) {\n return null;\n }\n\n // Allow the callers to control the unique policy name\n // by adding a data-tt-policy-suffix to the script element with the DOMPurify.\n // Policy creation with duplicate names throws in Trusted Types.\n let suffix = null;\n const ATTR_NAME = 'data-tt-policy-suffix';\n if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {\n suffix = purifyHostElement.getAttribute(ATTR_NAME);\n }\n\n const policyName = 'dompurify' + (suffix ? '#' + suffix : '');\n\n try {\n return trustedTypes.createPolicy(policyName, {\n createHTML(html) {\n return html;\n },\n createScriptURL(scriptUrl) {\n return scriptUrl;\n },\n });\n } catch (_) {\n // Policy creation failed (most likely another DOMPurify script has\n // already run). Skip creating the policy, as this will only cause errors\n // if TT are enforced.\n console.warn(\n 'TrustedTypes policy ' + policyName + ' could not be created.'\n );\n return null;\n }\n};\n\nconst _createHooksMap = function (): HooksMap {\n return {\n afterSanitizeAttributes: [],\n afterSanitizeElements: [],\n afterSanitizeShadowDOM: [],\n beforeSanitizeAttributes: [],\n beforeSanitizeElements: [],\n beforeSanitizeShadowDOM: [],\n uponSanitizeAttribute: [],\n uponSanitizeElement: [],\n uponSanitizeShadowNode: [],\n };\n};\n\n/**\n * Resolve a set-valued configuration option: a fresh set built from\n * cfg[key] when it is an own array property (seeded with a clone of\n * options.base when given, case-normalized via options.transform),\n * the fallback set otherwise.\n *\n * @param cfg the cloned, prototype-free configuration object\n * @param key the configuration property to read\n * @param fallback the set to use when the option is absent or not an array\n * @param options transform and optional base set to merge into\n * @returns the resolved set\n */\nconst _resolveSetOption = function (\n cfg: Config,\n key: keyof Config,\n fallback: Record,\n options: {\n transform: Parameters[2];\n base?: Record;\n }\n): Record {\n return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key])\n ? addToSet(\n options.base ? clone(options.base) : {},\n cfg[key] as readonly unknown[],\n options.transform\n )\n : fallback;\n};\n\nfunction createDOMPurify(window: WindowLike = getGlobal()): DOMPurify {\n const DOMPurify: DOMPurify = (root: WindowLike) => createDOMPurify(root);\n\n DOMPurify.version = VERSION;\n\n DOMPurify.removed = [];\n\n if (\n !window ||\n !window.document ||\n window.document.nodeType !== NODE_TYPE.document ||\n !window.Element\n ) {\n // Not running in a browser, provide a factory function\n // so that you can pass your own Window\n DOMPurify.isSupported = false;\n\n return DOMPurify;\n }\n\n let { document } = window;\n\n const originalDocument = document;\n const currentScript: HTMLScriptElement =\n originalDocument.currentScript as HTMLScriptElement;\n const {\n DocumentFragment,\n HTMLTemplateElement,\n Node,\n Element,\n NodeFilter,\n NamedNodeMap = window.NamedNodeMap || (window as any).MozNamedAttrMap,\n HTMLFormElement,\n DOMParser,\n trustedTypes,\n } = window;\n\n const ElementPrototype = Element.prototype;\n\n const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');\n const remove = lookupGetter(ElementPrototype, 'remove');\n const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');\n const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');\n const getParentNode = lookupGetter(ElementPrototype, 'parentNode');\n const getShadowRoot = lookupGetter(ElementPrototype, 'shadowRoot');\n const getAttributes = lookupGetter(ElementPrototype, 'attributes');\n const getNodeType =\n Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeType') : null;\n const getNodeName =\n Node && Node.prototype ? lookupGetter(Node.prototype, 'nodeName') : null;\n const getOwnerDocument =\n Node && Node.prototype\n ? lookupGetter(Node.prototype, 'ownerDocument')\n : null;\n\n // As per issue #47, the web-components registry is inherited by a\n // new document created via createHTMLDocument. As per the spec\n // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)\n // a new empty registry is used when creating a template contents owner\n // document, so we use that as our parent document to ensure nothing\n // is inherited.\n if (typeof HTMLTemplateElement === 'function') {\n const template = document.createElement('template');\n if (template.content && template.content.ownerDocument) {\n document = template.content.ownerDocument;\n }\n }\n\n let trustedTypesPolicy;\n let emptyHTML = '';\n\n // The instance's own internal Trusted Types policy. Unlike a caller-supplied\n // `TRUSTED_TYPES_POLICY`, this is created at most once \u2014 Trusted Types throws\n // on duplicate policy names \u2014 and is the only policy allowed to persist\n // across configurations and survive `clearConfig()`.\n let defaultTrustedTypesPolicy;\n let defaultTrustedTypesPolicyResolved = false;\n\n // Tracks whether we are already inside a call to the configured Trusted Types\n // policy (`createHTML` or `createScriptURL`). If a supplied policy callback\n // itself calls `DOMPurify.sanitize` (the cause of #1422), `sanitize` would\n // re-enter the policy and recurse until the stack overflows. We detect that\n // re-entry and throw a clear, actionable error instead. The guard is shared\n // across both callbacks, because either one re-entering `sanitize` triggers\n // the same unbounded recursion.\n let IN_TRUSTED_TYPES_POLICY = 0;\n const _assertNotInTrustedTypesPolicy = function (): void {\n if (IN_TRUSTED_TYPES_POLICY > 0) {\n throw typeErrorCreate(\n 'A configured TRUSTED_TYPES_POLICY callback (createHTML or ' +\n 'createScriptURL) must not call DOMPurify.sanitize, as that causes ' +\n 'infinite recursion. Do not pass a policy whose callbacks wrap ' +\n 'DOMPurify as TRUSTED_TYPES_POLICY; see the \"DOMPurify and Trusted ' +\n 'Types\" section of the README.'\n );\n }\n };\n\n const _createTrustedHTML = function (html: string): string {\n _assertNotInTrustedTypesPolicy();\n\n IN_TRUSTED_TYPES_POLICY++;\n try {\n return trustedTypesPolicy.createHTML(html);\n } finally {\n IN_TRUSTED_TYPES_POLICY--;\n }\n };\n\n const _createTrustedScriptURL = function (scriptUrl: string): string {\n _assertNotInTrustedTypesPolicy();\n\n IN_TRUSTED_TYPES_POLICY++;\n try {\n return trustedTypesPolicy.createScriptURL(scriptUrl);\n } finally {\n IN_TRUSTED_TYPES_POLICY--;\n }\n };\n\n // Lazily resolve (and cache) the instance's internal default policy.\n // Resolution is attempted at most once: a successful `createPolicy` cannot be\n // repeated (Trusted Types throws on duplicate names), and a failed or\n // unsupported attempt must not be retried on every parse.\n const _getDefaultTrustedTypesPolicy = function () {\n if (!defaultTrustedTypesPolicyResolved) {\n defaultTrustedTypesPolicy = _createTrustedTypesPolicy(\n trustedTypes,\n currentScript\n );\n defaultTrustedTypesPolicyResolved = true;\n }\n\n return defaultTrustedTypesPolicy;\n };\n\n const {\n implementation,\n createNodeIterator,\n createDocumentFragment,\n getElementsByTagName,\n } = document;\n const { importNode } = originalDocument;\n\n let hooks = _createHooksMap();\n\n /**\n * Expose whether this browser supports running the full DOMPurify.\n */\n DOMPurify.isSupported =\n typeof entries === 'function' &&\n typeof getParentNode === 'function' &&\n implementation &&\n implementation.createHTMLDocument !== undefined;\n\n const {\n MUSTACHE_EXPR,\n ERB_EXPR,\n TMPLIT_EXPR,\n DATA_ATTR,\n ARIA_ATTR,\n IS_SCRIPT_OR_DATA,\n ATTR_WHITESPACE,\n CUSTOM_ELEMENT,\n } = EXPRESSIONS;\n\n let { IS_ALLOWED_URI } = EXPRESSIONS;\n\n /**\n * We consider the elements and attributes below to be safe. Ideally\n * don't add any new ones but feel free to remove unwanted ones.\n */\n\n /* allowed element names */\n let ALLOWED_TAGS = null;\n const DEFAULT_ALLOWED_TAGS = addToSet({}, [\n ...TAGS.html,\n ...TAGS.svg,\n ...TAGS.svgFilters,\n ...TAGS.mathMl,\n ...TAGS.text,\n ]);\n\n /* Allowed attribute names */\n let ALLOWED_ATTR = null;\n const DEFAULT_ALLOWED_ATTR = addToSet({}, [\n ...ATTRS.html,\n ...ATTRS.svg,\n ...ATTRS.mathMl,\n ...ATTRS.xml,\n ]);\n\n /*\n * Configure how DOMPurify should handle custom elements and their attributes as well as customized built-in elements.\n * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)\n * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)\n * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.\n */\n let CUSTOM_ELEMENT_HANDLING = Object.seal(\n create(null, {\n tagNameCheck: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: null,\n },\n attributeNameCheck: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: null,\n },\n allowCustomizedBuiltInElements: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: false,\n },\n })\n );\n\n /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */\n let FORBID_TAGS = null;\n\n /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */\n let FORBID_ATTR = null;\n\n /* Config object to store ADD_TAGS/ADD_ATTR functions (when used as functions) */\n const EXTRA_ELEMENT_HANDLING = Object.seal(\n create(null, {\n tagCheck: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: null,\n },\n attributeCheck: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: null,\n },\n })\n );\n\n /* Decide if ARIA attributes are okay */\n let ALLOW_ARIA_ATTR = true;\n\n /* Decide if custom data attributes are okay */\n let ALLOW_DATA_ATTR = true;\n\n /* Decide if unknown protocols are okay */\n let ALLOW_UNKNOWN_PROTOCOLS = false;\n\n /* Decide if self-closing tags in attributes are allowed.\n * Usually removed due to a mXSS issue in jQuery 3.0 */\n let ALLOW_SELF_CLOSE_IN_ATTR = true;\n\n /* Output should be safe for common template engines.\n * This means, DOMPurify removes data attributes, mustaches and ERB\n */\n let SAFE_FOR_TEMPLATES = false;\n\n /* Output should be safe even for XML used within HTML and alike.\n * This means, DOMPurify removes comments when containing risky content.\n */\n let SAFE_FOR_XML = true;\n\n /* Decide if document with ... should be returned */\n let WHOLE_DOCUMENT = false;\n\n /* Track whether config is already set on this instance of DOMPurify. */\n let SET_CONFIG = false;\n\n /* Pristine allowlist bindings captured at setConfig() time. On the\n * persistent-config path sanitize() restores the sets from these before\n * the per-walk hook clone-guard, so a hook's in-call widening cannot\n * carry across calls. Null until setConfig() is called; reset by\n * clearConfig(). */\n let SET_CONFIG_ALLOWED_TAGS = null;\n let SET_CONFIG_ALLOWED_ATTR = null;\n\n /* Decide if all elements (e.g. style, script) must be children of\n * document.body. By default, browsers might move them to document.head */\n let FORCE_BODY = false;\n\n /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html\n * string (or a TrustedHTML object if Trusted Types are supported).\n * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead\n */\n let RETURN_DOM = false;\n\n /* Decide if a DOM `DocumentFragment` should be returned, instead of a html\n * string (or a TrustedHTML object if Trusted Types are supported) */\n let RETURN_DOM_FRAGMENT = false;\n\n /* Try to return a Trusted Type object instead of a string, return a string in\n * case Trusted Types are not supported */\n let RETURN_TRUSTED_TYPE = false;\n\n /* Output should be free from DOM clobbering attacks?\n * This sanitizes markups named with colliding, clobberable built-in DOM APIs.\n */\n let SANITIZE_DOM = true;\n\n /* Achieve full DOM Clobbering protection by isolating the namespace of named\n * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.\n *\n * HTML/DOM spec rules that enable DOM Clobbering:\n * - Named Access on Window (\u00A77.3.3)\n * - DOM Tree Accessors (\u00A73.1.5)\n * - Form Element Parent-Child Relations (\u00A74.10.3)\n * - Iframe srcdoc / Nested WindowProxies (\u00A74.8.5)\n * - HTMLCollection (\u00A74.2.10.2)\n *\n * Namespace isolation is implemented by prefixing `id` and `name` attributes\n * with a constant string, i.e., `user-content-`\n */\n let SANITIZE_NAMED_PROPS = false;\n const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';\n\n /* Keep element content when removing element? */\n let KEEP_CONTENT = true;\n\n /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead\n * of importing it into a new Document and returning a sanitized copy */\n let IN_PLACE = false;\n\n /* Allow usage of profiles like html, svg and mathMl */\n let USE_PROFILES: UseProfilesConfig | false = {};\n\n /* Tags to ignore content of when KEEP_CONTENT is true */\n let FORBID_CONTENTS = null;\n const DEFAULT_FORBID_CONTENTS = addToSet({}, [\n 'annotation-xml',\n 'audio',\n 'colgroup',\n 'desc',\n 'foreignobject',\n 'head',\n 'iframe',\n 'math',\n 'mi',\n 'mn',\n 'mo',\n 'ms',\n 'mtext',\n 'noembed',\n 'noframes',\n 'noscript',\n 'plaintext',\n 'script',\n // mirrors the selected