v86 0.5.44 → 0.5.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,20 +11,20 @@ h=0;h<f.length;h++){var l=f[h];e.setRequestHeader(l,b.headers[l])}b.range&&(f=b.
11
11
  500<=e.status&&600>e.status&&d();else if(e.response){if(b.range){const p=e.getResponseHeader("Content-Encoding");p&&"identity"!==p&&console.error("Server sent Content-Encoding in response to ranged request",{filename:a,enc:p})}b.done&&b.done(e.response,e)}};e.onerror=function(p){console.error("Loading the image "+a+" failed",p);d()};b.progress&&(e.onprogress=function(p){b.progress(p)});e.send(null)},ua=async function(a){return new Promise((b,c)=>{sa(a,{done:(d,e)=>{d=e.getResponseHeader("Content-Range")||
12
12
  "";(e=d.match(/\/(\d+)\s*$/))?b(+e[1]):c(Error("`Range: bytes=...` header not supported (Got `"+d+"`)"))},headers:{Range:"bytes=0-0","X-Accept-Encoding":"identity"}})})};var va=-15786961;const C=function(){const a=aa.reduce(function(d,e){d[e[0]]=e[1];return d},{});var b="",c=0;return function(d,e){e=e||1;if(e&va){d="["+ba(a[e]||"",4)+"] "+d;if(d===b&&(c++,2048>c))return;e=new Date;e=ca(e.getHours(),2)+":"+ca(e.getMinutes(),2)+":"+ca(e.getSeconds(),2)+"+"+ca(e.getMilliseconds(),3)+" ";c&&(1===c?console.log(e+
13
13
  b):console.log("Previous message repeated "+c+" times"),c=0);console.log(e+d);b=d}}}();function k(a,b){if(!a){debugger;console.trace();if(b)throw"Assert failed: "+b;throw"Assert failed";}}function wa(a,b){function c(z){z=z.toString(16);return"#"+"0".repeat(6-z.length)+z}function d(z){var x=256*oa,G=8*S,L=Va?Va.canvas:null;L&&L.width===x&&L.height===G||(L?(L.width=x,L.height=G):(L=new OffscreenCanvas(x,G),Va=L.getContext("2d")),Eb=Va.createImageData(x,G));const R=Eb.data;let Q=0,T;G=Fb?function(Z){T=
14
- T||Z;R[Q+3]=Z;R[Q+7]=Z;Q+=8}:function(Z){T=T||Z;R[Q+3]=Z;Q+=4};L=32-S;const la=x*(S-1)*4;x=4*(oa-x*S);const ia=1020*oa;for(let Z=0,ta=0;2048>Z;++Z,ta+=L,Q+=x){const Fa=Z%256;Z&&!Fa&&(Q+=la);T=!1;for(let Ma=0;Ma<S;++Ma,++ta,Q+=ia){const Na=z[ta];for(let xa=128;0<xa;xa>>=1)G(Na&xa?255:0);Gb&&G(Hb&&192<=Fa&&223>=Fa&&Na&1?255:0)}Zb[Z]=T?1:0}Va.putImageData(Eb,0,0)}function e(z,x,G,L){if(x&&G){z.style.width="";z.style.height="";L&&(z.style.transform="");var R=z.getBoundingClientRect();L?z.style.transform=
14
+ T||Z;R[Q+3]=Z;R[Q+7]=Z;Q+=8}:function(Z){T=T||Z;R[Q+3]=Z;Q+=4};L=32-S;const la=x*(S-1)*4;x=4*(oa-x*S);const ia=1020*oa;for(let Z=0,ta=0;2048>Z;++Z,ta+=L,Q+=x){const Ga=Z%256;Z&&!Ga&&(Q+=la);T=!1;for(let Ma=0;Ma<S;++Ma,++ta,Q+=ia){const Na=z[ta];for(let xa=128;0<xa;xa>>=1)G(Na&xa?255:0);Gb&&G(Hb&&192<=Ga&&223>=Ga&&Na&1?255:0)}Zb[Z]=T?1:0}Va.putImageData(Eb,0,0)}function e(z,x,G,L){if(x&&G){z.style.width="";z.style.height="";L&&(z.style.transform="");var R=z.getBoundingClientRect();L?z.style.transform=
15
15
  (1===x?"":" scaleX("+x+")")+(1===G?"":" scaleY("+G+")"):(0===x%1&&0===G%1?(h.style.imageRendering="crisp-edges",h.style.imageRendering="pixelated",h.style["-ms-interpolation-mode"]="nearest-neighbor"):(h.style.imageRendering="",h.style["-ms-interpolation-mode"]=""),L=window.devicePixelRatio||1,0!==L%1&&(x/=L,G/=L));1!==x&&(z.style.width=R.width*x+"px");1!==G&&(z.style.height=R.height*G+"px")}}const f=a.container;this.screen_fill_buffer=b;console.assert(f,"options.container must be provided");this.FLAG_BLINKING=
16
- 1;this.FLAG_FONT_PAGE_B=2;var h=f.getElementsByTagName("canvas")[0],l=h.getContext("2d",{alpha:!1}),p=f.getElementsByTagName("div")[0],n=document.createElement("div"),q,r,t=void 0!==a.scale?a.scale:1,u=void 0!==a.scale?a.scale:1,y=1,A,v,B,w,F,J,pa,Va,Eb,Zb=new Int8Array(2048),S,oa,Gb,Fb,Hb,Ib=0,Jb=0,sb,$b=0,tb,Kb,ub,Lb=[],ib=Lb,vb=0,Mb=!1;this.init=function(){const z=new Uint16Array([32,9786,9787,9829,9830,9827,9824,8226,9688,9675,9689,9794,9792,9834,9835,9788,9658,9668,8597,8252,182,167,9644,8616,
16
+ 1;this.FLAG_FONT_PAGE_B=2;var h=f.getElementsByTagName("canvas")[0],l=h.getContext("2d",{alpha:!1}),p=f.getElementsByTagName("div")[0],n=document.createElement("div"),q,r,t=void 0!==a.scale?a.scale:1,v=void 0!==a.scale?a.scale:1,y=1,A,u,B,w,F,J,pa,Va,Eb,Zb=new Int8Array(2048),S,oa,Gb,Fb,Hb,Ib=0,Jb=0,sb,$b=0,tb,Kb,ub,Lb=[],ib=Lb,vb=0,Mb=!1;this.init=function(){const z=new Uint16Array([32,9786,9787,9829,9830,9827,9824,8226,9688,9675,9689,9794,9792,9834,9835,9788,9658,9668,8597,8252,182,167,9644,8616,
17
17
  8593,8595,8594,8592,8735,8596,9650,9660]),x=new Uint16Array([8962,199,252,233,226,228,224,229,231,234,235,232,239,238,236,196,197,201,230,198,244,246,242,251,249,255,214,220,162,163,165,8359,402,225,237,243,250,241,209,170,186,191,8976,172,189,188,161,171,187,9617,9618,9619,9474,9508,9569,9570,9558,9557,9571,9553,9559,9565,9564,9563,9488,9492,9524,9516,9500,9472,9532,9566,9567,9562,9556,9577,9574,9568,9552,9580,9575,9576,9572,9573,9561,9560,9554,9555,9579,9578,9496,9484,9608,9604,9612,9616,9600,945,
18
- 223,915,960,931,963,181,964,934,920,937,948,8734,966,949,8745,8801,177,8805,8804,8992,8993,247,8776,176,8729,183,8730,8319,178,9632,160]);for(var G=0,L;256>G;G++)L=126<G?x[G-127]:32>G?z[G]:G,Lb.push(String.fromCharCode(L));n.classList.add("cursor");n.style.position="absolute";n.style.backgroundColor="#ccc";n.style.width="7px";n.style.display="inline-block";this.set_mode(!1);this.set_size_text(80,25);2===v&&this.set_size_graphical(720,400,720,400);this.set_scale(t,u);this.timer()};this.make_screenshot=
19
- function(){const z=new Image;if(1===v||2===v)z.src=h.toDataURL("image/png");else{const x=[9,16],G=document.createElement("canvas");G.width=w*x[0];G.height=F*x[1];const L=G.getContext("2d");L.imageSmoothingEnabled=!1;L.font=window.getComputedStyle(p).font;L.textBaseline="top";for(let R=0;R<F;R++)for(let Q=0;Q<w;Q++){const T=4*(R*w+Q),la=B[T+0],ia=B[T+3];L.fillStyle=c(B[T+2]);L.fillRect(Q*x[0],R*x[1],x[0],x[1]);L.fillStyle=c(ia);L.fillText(ib[la],Q*x[0],R*x[1])}"none"!==n.style.display&&q<F&&r<w&&(L.fillStyle=
20
- n.style.backgroundColor,L.fillRect(r*x[0],q*x[1]+parseInt(n.style.marginTop,10),parseInt(n.style.width,10),parseInt(n.style.height,10)));z.src=G.toDataURL("image/png")}return z};this.put_char=function(z,x,G,L,R,Q){k(0<=z&&z<F);k(0<=x&&x<w);k(0<=G&&256>G);x=4*(z*w+x);B[x+0]=G;B[x+1]=L;B[x+2]=R;B[x+3]=Q;A[z]=1};this.timer=function(){vb=requestAnimationFrame(()=>this.update_screen())};this.update_screen=function(){Mb||(0===v?this.update_text():1===v?this.update_graphical():this.update_graphical_text());
18
+ 223,915,960,931,963,181,964,934,920,937,948,8734,966,949,8745,8801,177,8805,8804,8992,8993,247,8776,176,8729,183,8730,8319,178,9632,160]);for(var G=0,L;256>G;G++)L=126<G?x[G-127]:32>G?z[G]:G,Lb.push(String.fromCharCode(L));n.classList.add("cursor");n.style.position="absolute";n.style.backgroundColor="#ccc";n.style.width="7px";n.style.display="inline-block";this.set_mode(!1);this.set_size_text(80,25);2===u&&this.set_size_graphical(720,400,720,400);this.set_scale(t,v);this.timer()};this.make_screenshot=
19
+ function(){const z=new Image;if(1===u||2===u)z.src=h.toDataURL("image/png");else{const x=[9,16],G=document.createElement("canvas");G.width=w*x[0];G.height=F*x[1];const L=G.getContext("2d");L.imageSmoothingEnabled=!1;L.font=window.getComputedStyle(p).font;L.textBaseline="top";for(let R=0;R<F;R++)for(let Q=0;Q<w;Q++){const T=4*(R*w+Q),la=B[T+0],ia=B[T+3];L.fillStyle=c(B[T+2]);L.fillRect(Q*x[0],R*x[1],x[0],x[1]);L.fillStyle=c(ia);L.fillText(ib[la],Q*x[0],R*x[1])}"none"!==n.style.display&&q<F&&r<w&&(L.fillStyle=
20
+ n.style.backgroundColor,L.fillRect(r*x[0],q*x[1]+parseInt(n.style.marginTop,10),parseInt(n.style.width,10),parseInt(n.style.height,10)));z.src=G.toDataURL("image/png")}return z};this.put_char=function(z,x,G,L,R,Q){k(0<=z&&z<F);k(0<=x&&x<w);k(0<=G&&256>G);x=4*(z*w+x);B[x+0]=G;B[x+1]=L;B[x+2]=R;B[x+3]=Q;A[z]=1};this.timer=function(){vb=requestAnimationFrame(()=>this.update_screen())};this.update_screen=function(){Mb||(0===u?this.update_text():1===u?this.update_graphical():this.update_graphical_text());
21
21
  this.timer()};this.update_text=function(){for(var z=0;z<F;z++)A[z]&&(this.text_update_row(z),A[z]=0)};this.update_graphical=function(){this.screen_fill_buffer()};this.update_graphical_text=function(){if(J){var z=performance.now();if(266<z-$b){sb=!sb;ub&&(A[q]=1);var x=4*w;for(let la=0,ia=0;la<F;++la)if(A[la])ia+=x;else for(var G=0;G<w;++G,ia+=4)if(B[ia+1]&1){A[la]=1;ia+=x-4*G;break}$b=z}z=Va.canvas;x=pa.canvas;G=4*w;const R=w*oa,Q=S;let T=0;for(let la=0,ia=0,Z=0;la<F;++la,ia+=S){if(!A[la]){Z+=G;continue}++T;
22
- pa.clearRect(0,Q,R,S);let ta,Fa,Ma,Na;for(let xa=0;xa<R;xa+=oa,Z+=4){const ac=B[Z+0];var L=B[Z+1];const bc=B[Z+2],cc=B[Z+3],dc=L&2?Jb:Ib;L=(!(L&1)||sb)&&Zb[(dc<<8)+ac];Ma!==bc&&(void 0!==Ma&&(J.fillStyle=c(Ma),J.fillRect(Na,ia,xa-Na,S)),Ma=bc,Na=xa);ta!==cc&&(void 0!==ta&&(pa.fillStyle=c(ta),pa.fillRect(Fa,0,xa-Fa,S)),ta=cc,Fa=xa);L&&pa.drawImage(z,ac*oa,dc*S,oa,S,xa,Q,oa,S)}pa.fillStyle=c(ta);pa.fillRect(Fa,0,R-Fa,S);pa.globalCompositeOperation="destination-in";pa.drawImage(x,0,Q,R,S,0,0,R,S);pa.globalCompositeOperation=
23
- "source-over";J.fillStyle=c(Ma);J.fillRect(Na,ia,R-Na,S);J.drawImage(x,0,0,R,S,0,ia,R,S)}T&&(sb&&ub&&A[q]&&(J.fillStyle=c(B[4*(q*w+r)+3]),J.fillRect(r*oa,q*S+tb,oa,Kb-tb+1)),A.fill(0));T&&l.drawImage(J.canvas,0,0)}};this.destroy=function(){vb&&(cancelAnimationFrame(vb),vb=0)};this.pause=function(){Mb=!0;n.classList.remove("blinking-cursor")};this.continue=function(){Mb=!1;n.classList.add("blinking-cursor")};this.set_mode=function(z){v=z?1:a.use_graphical_text?2:0;0===v?(p.style.display="block",h.style.display=
24
- "none"):(p.style.display="none",h.style.display="block",2===v&&A&&A.fill(1))};this.set_font_bitmap=function(z,x,G,L,R,Q){const T=G?16:x?9:8;if(S!==z||oa!==T||Gb!==x||Fb!==G||Hb!==L||Q)Q=oa!==T||S!==z,S=z,oa=T,Gb=x,Fb=G,Hb=L,2===v&&(d(R),A.fill(1),Q&&this.set_size_graphical_text())};this.set_font_page=function(z,x){if(Ib!==z||Jb!==x)Ib=z,Jb=x,A.fill(1)};this.clear_screen=function(){l.fillStyle="#000";l.fillRect(0,0,h.width,h.height)};this.set_size_graphical_text=function(){if(Va){var z=oa*w,x=S*F,
25
- G=2*S;J&&J.canvas.width===z&&J.canvas.height===x&&pa.canvas.height===G||(J?(J.canvas.width=z,J.canvas.height=x,pa.canvas.width=z,pa.canvas.height=G):(J=(new OffscreenCanvas(z,x)).getContext("2d",{alpha:!1}),pa=(new OffscreenCanvas(z,G)).getContext("2d")),this.set_size_graphical(z,x,z,x),A.fill(1))}};this.set_size_text=function(z,x){if(z!==w||x!==F)if(A=new Int8Array(x),B=new Int32Array(z*x*4),w=z,F=x,0===v){for(;p.childNodes.length>x;)p.removeChild(p.firstChild);for(;p.childNodes.length<x;)p.appendChild(document.createElement("div"));
26
- for(z=0;z<x;z++)this.text_update_row(z);e(p,t,u,!0)}else 2===v&&this.set_size_graphical_text()};this.set_size_graphical=function(z,x){h.style.display="block";h.width=z;h.height=x;l.imageSmoothingEnabled=!1;y=640>=z&&2*z<window.innerWidth*window.devicePixelRatio&&2*x<window.innerHeight*window.devicePixelRatio?2:1;e(h,t*y,u*y,!1)};this.set_charmap=function(z){ib=z||Lb};this.set_scale=function(z,x){t=z;u=x;e(p,t,u,!0);e(h,t*y,u*y,!1)};this.update_cursor_scanline=function(z,x,G){if(z!==tb||x!==Kb||G!==
27
- ub)0===v?G?(n.style.display="inline",n.style.height=x-z+"px",n.style.marginTop=z+"px"):n.style.display="none":2===v&&q<F&&(A[q]=1),tb=z,Kb=x,ub=G};this.update_cursor=function(z,x){if(z!==q||x!==r)z<F&&(A[z]=1),q<F&&(A[q]=1),q=z,r=x};this.text_update_row=function(z){var x=4*z*w,G;var L=p.childNodes[z];var R=document.createElement("div");for(var Q=0;Q<w;){var T=document.createElement("span");var la=B[x+1]&1;var ia=B[x+2];var Z=B[x+3];la&&T.classList.add("blink");T.style.backgroundColor=c(ia);T.style.color=
22
+ pa.clearRect(0,Q,R,S);let ta,Ga,Ma,Na;for(let xa=0;xa<R;xa+=oa,Z+=4){const ac=B[Z+0];var L=B[Z+1];const bc=B[Z+2],cc=B[Z+3],dc=L&2?Jb:Ib;L=(!(L&1)||sb)&&Zb[(dc<<8)+ac];Ma!==bc&&(void 0!==Ma&&(J.fillStyle=c(Ma),J.fillRect(Na,ia,xa-Na,S)),Ma=bc,Na=xa);ta!==cc&&(void 0!==ta&&(pa.fillStyle=c(ta),pa.fillRect(Ga,0,xa-Ga,S)),ta=cc,Ga=xa);L&&pa.drawImage(z,ac*oa,dc*S,oa,S,xa,Q,oa,S)}pa.fillStyle=c(ta);pa.fillRect(Ga,0,R-Ga,S);pa.globalCompositeOperation="destination-in";pa.drawImage(x,0,Q,R,S,0,0,R,S);pa.globalCompositeOperation=
23
+ "source-over";J.fillStyle=c(Ma);J.fillRect(Na,ia,R-Na,S);J.drawImage(x,0,0,R,S,0,ia,R,S)}T&&(sb&&ub&&A[q]&&(J.fillStyle=c(B[4*(q*w+r)+3]),J.fillRect(r*oa,q*S+tb,oa,Kb-tb+1)),A.fill(0));T&&l.drawImage(J.canvas,0,0)}};this.destroy=function(){vb&&(cancelAnimationFrame(vb),vb=0)};this.pause=function(){Mb=!0;n.classList.remove("blinking-cursor")};this.continue=function(){Mb=!1;n.classList.add("blinking-cursor")};this.set_mode=function(z){u=z?1:a.use_graphical_text?2:0;0===u?(p.style.display="block",h.style.display=
24
+ "none"):(p.style.display="none",h.style.display="block",2===u&&A&&A.fill(1))};this.set_font_bitmap=function(z,x,G,L,R,Q){const T=G?16:x?9:8;if(S!==z||oa!==T||Gb!==x||Fb!==G||Hb!==L||Q)Q=oa!==T||S!==z,S=z,oa=T,Gb=x,Fb=G,Hb=L,2===u&&(d(R),A.fill(1),Q&&this.set_size_graphical_text())};this.set_font_page=function(z,x){if(Ib!==z||Jb!==x)Ib=z,Jb=x,A.fill(1)};this.clear_screen=function(){l.fillStyle="#000";l.fillRect(0,0,h.width,h.height)};this.set_size_graphical_text=function(){if(Va){var z=oa*w,x=S*F,
25
+ G=2*S;J&&J.canvas.width===z&&J.canvas.height===x&&pa.canvas.height===G||(J?(J.canvas.width=z,J.canvas.height=x,pa.canvas.width=z,pa.canvas.height=G):(J=(new OffscreenCanvas(z,x)).getContext("2d",{alpha:!1}),pa=(new OffscreenCanvas(z,G)).getContext("2d")),this.set_size_graphical(z,x,z,x),A.fill(1))}};this.set_size_text=function(z,x){if(z!==w||x!==F)if(A=new Int8Array(x),B=new Int32Array(z*x*4),w=z,F=x,0===u){for(;p.childNodes.length>x;)p.removeChild(p.firstChild);for(;p.childNodes.length<x;)p.appendChild(document.createElement("div"));
26
+ for(z=0;z<x;z++)this.text_update_row(z);e(p,t,v,!0)}else 2===u&&this.set_size_graphical_text()};this.set_size_graphical=function(z,x){h.style.display="block";h.width=z;h.height=x;l.imageSmoothingEnabled=!1;y=640>=z&&2*z<window.innerWidth*window.devicePixelRatio&&2*x<window.innerHeight*window.devicePixelRatio?2:1;e(h,t*y,v*y,!1)};this.set_charmap=function(z){ib=z||Lb};this.set_scale=function(z,x){t=z;v=x;e(p,t,v,!0);e(h,t*y,v*y,!1)};this.update_cursor_scanline=function(z,x,G){if(z!==tb||x!==Kb||G!==
27
+ ub)0===u?G?(n.style.display="inline",n.style.height=x-z+"px",n.style.marginTop=z+"px"):n.style.display="none":2===u&&q<F&&(A[q]=1),tb=z,Kb=x,ub=G};this.update_cursor=function(z,x){if(z!==q||x!==r)z<F&&(A[z]=1),q<F&&(A[q]=1),q=z,r=x};this.text_update_row=function(z){var x=4*z*w,G;var L=p.childNodes[z];var R=document.createElement("div");for(var Q=0;Q<w;){var T=document.createElement("span");var la=B[x+1]&1;var ia=B[x+2];var Z=B[x+3];la&&T.classList.add("blink");T.style.backgroundColor=c(ia);T.style.color=
28
28
  c(Z);for(G="";Q<w&&(B[x+1]&1)===la&&B[x+2]===ia&&B[x+3]===Z;){var ta=B[x+0];G+=ib[ta];k(ib[ta]);Q++;x+=4;if(z===q)if(Q===r)break;else if(Q===r+1){n.style.backgroundColor=T.style.color;R.appendChild(n);break}}T.textContent=G;R.appendChild(T)}L.parentNode.replaceChild(R,L)};this.update_buffer=function(z){for(const x of z)l.putImageData(x.image_data,x.screen_x-x.buffer_x,x.screen_y-x.buffer_y,x.buffer_x,x.buffer_y,x.buffer_width,x.buffer_height)};this.get_text_screen=function(){for(var z=[],x=0;x<F;x++)z.push(this.get_text_row(x));
29
29
  return z};this.get_text_row=function(z){let x="";for(let G=0;G<w;G++)x+=ib[B[4*(z*w+G)]];return x};this.init()}function ya(a){k(a instanceof ArrayBuffer);this.buffer=a;this.byteLength=a.byteLength;this.onprogress=this.onload=void 0}ya.prototype.load=function(){this.onload&&this.onload({buffer:this.buffer})};ya.prototype.get=function(a,b,c){k(a+b<=this.byteLength);c(new Uint8Array(this.buffer,a,b))};ya.prototype.set=function(a,b,c){k(a+b.byteLength<=this.byteLength);(new Uint8Array(this.buffer,a,b.byteLength)).set(b);
30
30
  c()};ya.prototype.get_buffer=function(a){a(this.buffer)};ya.prototype.get_state=function(){const a=[];a[0]=this.byteLength;a[1]=new Uint8Array(this.buffer);return a};ya.prototype.set_state=function(a){this.byteLength=a[0];this.buffer=a[1].slice().buffer};function za(a,b,c){this.filename=a;this.byteLength=b;this.block_cache=new Map;this.block_cache_is_write=new Set;this.fixed_chunk_size=c;this.cache_reads=!!c;this.onprogress=this.onload=void 0}za.prototype.load=async function(){void 0===this.byteLength&&
@@ -66,10 +66,10 @@ function(a,b,c,d,e,f){function h(n){c.call(this,n&255);d.call(this,n>>8&255)}fun
66
66
  this.cpu.memory_map_read8[a>>>17];return b(a)|b(a+1)<<8|b(a+2)<<16|b(a+3)<<24};Ea.prototype.mmap_write32_shim=function(a,b){var c=this.cpu.memory_map_write8[a>>>17];c(a,b&255);c(a+1,b>>8&255);c(a+2,b>>16&255);c(a+3,b>>>24)};Ea.prototype.mmap_register=function(a,b,c,d,e,f){C("mmap_register addr="+m(a>>>0,8)+" size="+m(b,8),32);k(0===(a&131071));k(b&&0===(b&131071));e||(e=this.mmap_read32_shim.bind(this));f||(f=this.mmap_write32_shim.bind(this));for(a>>>=17;0<b;a++)this.cpu.memory_map_read8[a]=c,this.cpu.memory_map_write8[a]=
67
67
  d,this.cpu.memory_map_read32[a]=e,this.cpu.memory_map_write32[a]=f,b-=131072};Ea.prototype.port_write8=function(a,b){var c=this.ports[a];c.write8===this.empty_port_write&&C("write8 port #"+m(a,4)+" <- "+m(b,2)+this.get_port_description(a),32);return c.write8.call(c.device,b)};Ea.prototype.port_write16=function(a,b){var c=this.ports[a];c.write16===this.empty_port_write&&C("write16 port #"+m(a,4)+" <- "+m(b,4)+this.get_port_description(a),32);return c.write16.call(c.device,b)};Ea.prototype.port_write32=
68
68
  function(a,b){var c=this.ports[a];c.write32===this.empty_port_write&&C("write32 port #"+m(a,4)+" <- "+m(b>>>0,8)+this.get_port_description(a),32);return c.write32.call(c.device,b)};Ea.prototype.port_read8=function(a){var b=this.ports[a];b.read8===this.empty_port_read8&&C("read8 port #"+m(a,4)+this.get_port_description(a),32);b=b.read8.call(b.device,a);k("number"===typeof b);k(256>b&&0<=b,"8 bit port returned large value: "+m(a));return b};Ea.prototype.port_read16=function(a){var b=this.ports[a];
69
- b.read16===this.empty_port_read16&&C("read16 port #"+m(a,4)+this.get_port_description(a),32);b=b.read16.call(b.device,a);k("number"===typeof b);k(65536>b&&0<=b,"16 bit port returned large value: "+m(a));return b};Ea.prototype.port_read32=function(a){var b=this.ports[a];b.read32===this.empty_port_read32&&C("read32 port #"+m(a,4)+this.get_port_description(a),32);a=b.read32.call(b.device,a);k((a|0)===a);return a};var Ga={4:"PORT_DMA_ADDR_2",5:"PORT_DMA_CNT_2",10:"PORT_DMA1_MASK_REG",11:"PORT_DMA1_MODE_REG",
69
+ b.read16===this.empty_port_read16&&C("read16 port #"+m(a,4)+this.get_port_description(a),32);b=b.read16.call(b.device,a);k("number"===typeof b);k(65536>b&&0<=b,"16 bit port returned large value: "+m(a));return b};Ea.prototype.port_read32=function(a){var b=this.ports[a];b.read32===this.empty_port_read32&&C("read32 port #"+m(a,4)+this.get_port_description(a),32);a=b.read32.call(b.device,a);k((a|0)===a);return a};var Fa={4:"PORT_DMA_ADDR_2",5:"PORT_DMA_CNT_2",10:"PORT_DMA1_MASK_REG",11:"PORT_DMA1_MODE_REG",
70
70
  12:"PORT_DMA1_CLEAR_FF_REG",13:"PORT_DMA1_MASTER_CLEAR",32:"PORT_PIC1_CMD",33:"PORT_PIC1_DATA",64:"PORT_PIT_COUNTER0",65:"PORT_PIT_COUNTER1",66:"PORT_PIT_COUNTER2",67:"PORT_PIT_MODE",96:"PORT_PS2_DATA",97:"PORT_PS2_CTRLB",100:"PORT_PS2_STATUS",112:"PORT_CMOS_INDEX",113:"PORT_CMOS_DATA",128:"PORT_DIAG",129:"PORT_DMA_PAGE_2",146:"PORT_A20",160:"PORT_PIC2_CMD",161:"PORT_PIC2_DATA",178:"PORT_SMI_CMD",179:"PORT_SMI_STATUS",212:"PORT_DMA2_MASK_REG",214:"PORT_DMA2_MODE_REG",218:"PORT_DMA2_MASTER_CLEAR",
71
71
  240:"PORT_MATH_CLEAR",368:"PORT_ATA2_CMD_BASE",496:"PORT_ATA1_CMD_BASE",632:"PORT_LPT2",744:"PORT_SERIAL4",760:"PORT_SERIAL2",884:"PORT_ATA2_CTRL_BASE",888:"PORT_LPT1",1E3:"PORT_SERIAL3",1008:"PORT_FD_BASE",1010:"PORT_FD_DOR",1012:"PORT_FD_STATUS",1013:"PORT_FD_DATA",1014:"PORT_HD_DATA",1015:"PORT_FD_DIR",1016:"PORT_SERIAL1",3320:"PORT_PCI_CMD",3321:"PORT_PCI_REBOOT",3324:"PORT_PCI_DATA",1026:"PORT_BIOS_DEBUG",1296:"PORT_QEMU_CFG_CTL",1297:"PORT_QEMU_CFG_DATA",45056:"PORT_ACPI_PM_BASE",45312:"PORT_SMB_BASE",
72
- 35072:"PORT_BIOS_APM"};Ea.prototype.get_port_description=function(a){return Ga[a]?" ("+Ga[a]+")":""};var Ha={};function Ia(){this.listeners={};this.pair=void 0}Ia.prototype.register=function(a,b,c){var d=this.listeners[a];void 0===d&&(d=this.listeners[a]=[]);d.push({fn:b,this_value:c})};Ia.prototype.unregister=function(a,b){var c=this.listeners[a];void 0!==c&&(this.listeners[a]=c.filter(function(d){return d.fn!==b}))};Ia.prototype.send=function(a,b){if(this.pair&&(a=this.pair.listeners[a],void 0!==
72
+ 35072:"PORT_BIOS_APM"};Ea.prototype.get_port_description=function(a){return Fa[a]?" ("+Fa[a]+")":""};var Ha={};function Ia(){this.listeners={};this.pair=void 0}Ia.prototype.register=function(a,b,c){var d=this.listeners[a];void 0===d&&(d=this.listeners[a]=[]);d.push({fn:b,this_value:c})};Ia.prototype.unregister=function(a,b){var c=this.listeners[a];void 0!==c&&(this.listeners[a]=c.filter(function(d){return d.fn!==b}))};Ia.prototype.send=function(a,b){if(this.pair&&(a=this.pair.listeners[a],void 0!==
73
73
  a))for(var c=0;c<a.length;c++){var d=a[c];d.fn.call(d.this_value,b)}};Ia.prototype.send_async=function(a,b){k(1===arguments.length||2===arguments.length);setTimeout(this.send.bind(this,a,b),0)};Ha.create=function(){var a=new Ia,b=new Ia;a.pair=b;b.pair=a;return[a,b]};var Ja=new Uint8Array(256),Ka=[],La=[],Oa=[],Pa=new Uint8Array(256),Qa=[];function E(a,b){this.cpu=a;this.bus=b;this.write_buffer=new ma(64);this.read_buffer=new ma(64);this.mixer_current_address=this.command_size=this.command=this.read_buffer_lastvalue=
74
74
  0;this.mixer_registers=new Uint8Array(256);this.mixer_reset();this.dummy_speaker_enabled=!1;this.test_register=0;this.dsp_signed=this.dsp_16bit=this.dsp_stereo=this.dsp_highspeed=!1;this.dac_buffers=[new na(65536),new na(65536)];this.dma=a.devices.dma;this.dma_channel=this.dma_irq=this.dma_bytes_block=this.dma_bytes_left=this.dma_bytes_count=this.dma_sample_count=0;this.dma_channel_8bit=1;this.dma_channel_16bit=5;this.dma_autoinit=!1;this.dma_buffer=new ArrayBuffer(65536);this.dma_buffer_int8=new Int8Array(this.dma_buffer);
75
75
  this.dma_buffer_uint8=new Uint8Array(this.dma_buffer);this.dma_buffer_int16=new Int16Array(this.dma_buffer);this.dma_buffer_uint16=new Uint16Array(this.dma_buffer);this.dma_syncbuffer=new ya(this.dma_buffer);this.dma_paused=this.dma_waiting_transfer=!1;this.sampling_rate=22050;b.send("dac-tell-sampling-rate",this.sampling_rate);this.bytes_per_sample=1;this.e2_value=170;this.e2_count=0;this.asp_registers=new Uint8Array(256);this.mpu_read_buffer=new ma(64);this.fm_current_address1=this.fm_current_address0=
@@ -115,12 +115,12 @@ this.dma_waiting_transfer&&(this.dma_waiting_transfer=!1,this.dma_bytes_left=thi
115
115
  this.dma_paused?this.dac_send():this.dma_transfer_next()};E.prototype.dac_send=function(){if(this.dac_buffers[0].length){var a=this.dac_buffers[0].shift_block(this.dac_buffers[0].length),b=this.dac_buffers[1].shift_block(this.dac_buffers[1].length);this.bus.send("dac-send-data",[a,b],[a.buffer,b.buffer])}};E.prototype.raise_irq=function(a){C("raise irq",8388608);this.irq_triggered[a]=1;this.cpu.device_raise_irq(this.irq)};E.prototype.lower_irq=function(a){C("lower irq",8388608);this.irq_triggered[a]=
116
116
  0;this.cpu.device_lower_irq(this.irq)};function Sa(a,b,c){return(a<b)*b+(a>c)*c+(b<=a&&a<=c)*a}function bb(a){this.message=a}bb.prototype=Error();const cb={Uint8Array,Int8Array,Uint16Array,Int16Array,Uint32Array,Int32Array,Float32Array,Float64Array};function db(a,b){if("object"!==typeof a||null===a)return k("function"!==typeof a),a;if(Array.isArray(a))return a.map(f=>db(f,b));a.constructor===Object&&(console.log(a),k(a.constructor!==Object,"Expected non-object"));if(a.BYTES_PER_ELEMENT){var c=new Uint8Array(a.buffer,
117
117
  a.byteOffset,a.length*a.BYTES_PER_ELEMENT);a=a.constructor.name.replace("bound ","");k(cb[a]);return{__state_type__:a,buffer_id:b.push(c)-1}}!a.get_state&&console.log("Object without get_state: ",a);c=a.get_state();a=[];for(var d=0;d<c.length;d++){var e=c[d];k("function"!==typeof e);a[d]=db(e,b)}return a}function eb(a,b){if("object"!==typeof a||null===a)return k("function"!==typeof a),a;if(Array.isArray(a)){for(var c=0;c<a.length;c++)a[c]=eb(a[c],b);return a}c=a.__state_type__;k(void 0!==c);const d=
118
- cb[c];k(d,"Unkown type: "+c);return new d(b[a.buffer_id])}function fb(a,b){function c(u,y){const A=u.length;if(16>A)throw new bb("Invalid length: "+A);u=new Int32Array(u.buffer,u.byteOffset,4);if(-2039052682!==u[0])throw new bb("Invalid header: "+m(u[0]>>>0));if(6!==u[1])throw new bb("Version mismatch: dump="+u[1]+" we=6");if(y&&u[2]!==A)throw new bb("Length doesn't match header: real="+A+" header="+u[2]);return u[3]}function d(u){u=(new TextDecoder).decode(u);return JSON.parse(u)}b=new Uint8Array(b);
118
+ cb[c];k(d,"Unkown type: "+c);return new d(b[a.buffer_id])}function fb(a,b){function c(v,y){const A=v.length;if(16>A)throw new bb("Invalid length: "+A);v=new Int32Array(v.buffer,v.byteOffset,4);if(-2039052682!==v[0])throw new bb("Invalid header: "+m(v[0]>>>0));if(6!==v[1])throw new bb("Version mismatch: dump="+v[1]+" we=6");if(y&&v[2]!==A)throw new bb("Length doesn't match header: real="+A+" header="+v[2]);return v[3]}function d(v){v=(new TextDecoder).decode(v);return JSON.parse(v)}b=new Uint8Array(b);
119
119
  if(4247762216===(new Uint32Array(b.buffer,0,1))[0]){var e=a.zstd_create_ctx(b.length);(new Uint8Array(a.wasm_memory.buffer,a.zstd_get_src_ptr(e),b.length)).set(b);var f=a.zstd_read(e,16),h=new Uint8Array(a.wasm_memory.buffer,f,16),l=c(h,!1);a.zstd_read_free(f,16);f=a.zstd_read(e,l);h=new Uint8Array(a.wasm_memory.buffer,f,l);h=d(h);a.zstd_read_free(f,l);f=h.state;var p=h.buffer_infos;h=[];l=16+l;for(var n of p){p=(l+3&-4)-l;if(1048576<n.length){var q=a.zstd_read(e,p);a.zstd_read_free(q,p);q=new Uint8Array(n.length);
120
- h.push(q.buffer);for(var r=0;r<n.length;){var t=n.length-r;k(0<=t);t=Math.min(t,1048576);const u=a.zstd_read(e,t);q.set(new Uint8Array(a.wasm_memory.buffer,u,t),r);a.zstd_read_free(u,t);r+=t}}else q=a.zstd_read(e,p+n.length),r=q+p,h.push(a.wasm_memory.buffer.slice(r,r+n.length)),a.zstd_read_free(q,p+n.length);l+=p+n.length}f=eb(f,h);a.set_state(f);a.zstd_free_ctx(e)}else{e=c(b,!0);if(0>e||e+12>=b.length)throw new bb("Invalid info block length: "+e);n=b.subarray(16,16+e);f=d(n);n=f.state;f=f.buffer_infos;
121
- let u=16+e;u=u+3&-4;e=f.map(y=>{const A=u+y.offset;return b.buffer.slice(A,A+y.length)});n=eb(n,e);a.set_state(n)}}function gb(a,b,c,d,e){let f="";var h=[],l=b?"compiled":c?"jit exit":d?"unguarded register":e?"wasm size":"executed";for(let q=0;256>q;q++)for(let r=0;8>r;r++)for(const t of[!1,!0]){var p=a.wm.exports.get_opstats_buffer(b,c,d,e,q,!1,t,r);h.push({opcode:q,count:p,is_mem:t,fixed_g:r});p=a.wm.exports.get_opstats_buffer(b,c,d,e,q,!0,t,r);h.push({opcode:3840|q,count:p,is_mem:t,fixed_g:r})}a=
120
+ h.push(q.buffer);for(var r=0;r<n.length;){var t=n.length-r;k(0<=t);t=Math.min(t,1048576);const v=a.zstd_read(e,t);q.set(new Uint8Array(a.wasm_memory.buffer,v,t),r);a.zstd_read_free(v,t);r+=t}}else q=a.zstd_read(e,p+n.length),r=q+p,h.push(a.wasm_memory.buffer.slice(r,r+n.length)),a.zstd_read_free(q,p+n.length);l+=p+n.length}f=eb(f,h);a.set_state(f);a.zstd_free_ctx(e)}else{e=c(b,!0);if(0>e||e+12>=b.length)throw new bb("Invalid info block length: "+e);n=b.subarray(16,16+e);f=d(n);n=f.state;f=f.buffer_infos;
121
+ let v=16+e;v=v+3&-4;e=f.map(y=>{const A=v+y.offset;return b.buffer.slice(A,A+y.length)});n=eb(n,e);a.set_state(n)}}function gb(a,b,c,d,e){let f="";var h=[],l=b?"compiled":c?"jit exit":d?"unguarded register":e?"wasm size":"executed";for(let q=0;256>q;q++)for(let r=0;8>r;r++)for(const t of[!1,!0]){var p=a.wm.exports.get_opstats_buffer(b,c,d,e,q,!1,t,r);h.push({opcode:q,count:p,is_mem:t,fixed_g:r});p=a.wm.exports.get_opstats_buffer(b,c,d,e,q,!0,t,r);h.push({opcode:3840|q,count:p,is_mem:t,fixed_g:r})}a=
122
122
  0;b=new Set([38,46,54,62,100,101,102,103,240,242,243]);for(const {count:q,opcode:r}of h)b.has(r)||(a+=q);if(0===a)return"";c=new Uint32Array(256);b=new Uint32Array(256);for(const {opcode:q,count:r}of h)3840===(q&65280)?b[q&255]+=r:c[q&255]+=r;f=f+"------------------\nTotal: "+(a+"\n");const n=1E7<a?1E3:1;d=Math.max.apply(Math,h.map(({count:q})=>Math.round(q/n)));d=String(d).length;f+=`Instruction counts ${l} (in ${n}):\n`;for(e=0;256>e;e++)f+=e.toString(16).padStart(2,"0")+":"+ba(Math.round(c[e]/
123
- n),d),f=15===e%16?f+"\n":f+" ";f=f+"\n"+`Instruction counts ${l} (0f, in ${n}):\n`;for(l=0;256>l;l++)f+=(l&255).toString(16).padStart(2,"0")+":"+ba(Math.round(b[l]/n),d),f=15===l%16?f+"\n":f+" ";f+="\n";h=h.filter(({count:q})=>q).sort(({count:q},{count:r})=>r-q);for(const {opcode:q,is_mem:r,fixed_g:t,count:u}of h.slice(0,200))h=q.toString(16)+"_"+t+(r?"_m":"_r"),f+=h+":"+(u/a*100).toFixed(2)+" ";return f+"\n"}function hb(a){this.cpu=a;this.cmos_index=0;this.cmos_data=new Uint8Array(128);this.last_update=
123
+ n),d),f=15===e%16?f+"\n":f+" ";f=f+"\n"+`Instruction counts ${l} (0f, in ${n}):\n`;for(l=0;256>l;l++)f+=(l&255).toString(16).padStart(2,"0")+":"+ba(Math.round(b[l]/n),d),f=15===l%16?f+"\n":f+" ";f+="\n";h=h.filter(({count:q})=>q).sort(({count:q},{count:r})=>r-q);for(const {opcode:q,is_mem:r,fixed_g:t,count:v}of h.slice(0,200))h=q.toString(16)+"_"+t+(r?"_m":"_r"),f+=h+":"+(v/a*100).toFixed(2)+" ";return f+"\n"}function hb(a){this.cpu=a;this.cmos_index=0;this.cmos_data=new Uint8Array(128);this.last_update=
124
124
  this.rtc_time=Date.now();this.next_interrupt_alarm=this.next_interrupt=0;this.periodic_interrupt=!1;this.periodic_interrupt_time=.9765625;this.cmos_a=38;this.cmos_b=2;this.nmi_disabled=this.cmos_c=0;a.io.register_write(112,this,function(b){this.cmos_index=b&127;this.nmi_disabled=b>>7});a.io.register_write(113,this,this.cmos_port_write);a.io.register_read(113,this,this.cmos_port_read)}hb.prototype.get_state=function(){var a=[];a[0]=this.cmos_index;a[1]=this.cmos_data;a[2]=this.rtc_time;a[3]=this.last_update;
125
125
  a[4]=this.next_interrupt;a[5]=this.next_interrupt_alarm;a[6]=this.periodic_interrupt;a[7]=this.periodic_interrupt_time;a[8]=this.cmos_a;a[9]=this.cmos_b;a[10]=this.cmos_c;a[11]=this.nmi_disabled;return a};hb.prototype.set_state=function(a){this.cmos_index=a[0];this.cmos_data=a[1];this.rtc_time=a[2];this.last_update=a[3];this.next_interrupt=a[4];this.next_interrupt_alarm=a[5];this.periodic_interrupt=a[6];this.periodic_interrupt_time=a[7];this.cmos_a=a[8];this.cmos_b=a[9];this.cmos_c=a[10];this.nmi_disabled=
126
126
  a[11]};hb.prototype.timer=function(a){a=Date.now();this.rtc_time+=a-this.last_update;this.last_update=a;this.periodic_interrupt&&this.next_interrupt<a?(this.cpu.device_raise_irq(8),this.cmos_c|=192,this.next_interrupt+=this.periodic_interrupt_time*Math.ceil((a-this.next_interrupt)/this.periodic_interrupt_time)):this.next_interrupt_alarm&&this.next_interrupt_alarm<a&&(this.cpu.device_raise_irq(8),this.cmos_c|=160,this.next_interrupt_alarm=0);let b=100;this.periodic_interrupt&&this.next_interrupt&&
@@ -153,10 +153,10 @@ this.audio_context.currentTime)};pb.prototype.connect=function(a){var b=!a||2===
153
153
  b);return}this.update()};pb.prototype.set_gain_hidden=function(a){this.gain_hidden=a};function ob(a,b,c){this.node_oscillator=b.createOscillator();this.node_oscillator.type="square";this.node_oscillator.frequency.setValueAtTime(440,b.currentTime);this.mixer_connection=c.add_source(this.node_oscillator,1);this.mixer_connection.disconnect();a.register("pcspeaker-enable",function(){c.connect_source(1)},this);a.register("pcspeaker-disable",function(){c.disconnect_source(1)},this);a.register("pcspeaker-update",
154
154
  function(d){var e=d[1],f=0;3===d[0]&&(f=Math.min(1193181.6665999999/e,this.node_oscillator.frequency.maxValue),f=Math.max(f,0));this.node_oscillator.frequency.setValueAtTime(f,b.currentTime)},this)}ob.prototype.start=function(){this.node_oscillator.start()};function lb(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=48E3;b=function(){function h(n){if(0===n)return 1;n*=Math.PI;return Math.sin(n)/n}function l(){var n=Reflect.construct(AudioWorkletProcessor,[],l);n.kernel_size=
155
155
  3;n.queue_data=Array(1024);n.queue_start=0;n.queue_end=0;n.queue_length=0;n.queue_size=n.queue_data.length;n.queued_samples=0;n.source_buffer_previous=p;n.source_buffer_current=p;n.source_samples_per_destination=1;n.source_block_start=0;n.source_time=0;n.source_offset=0;n.port.onmessage=q=>{switch(q.data.type){case "queue":n.queue_push(q.data.value);break;case "sampling-rate":n.source_samples_per_destination=q.data.value/sampleRate}};return n}var p=[new Float32Array(256),new Float32Array(256)];Reflect.setPrototypeOf(l.prototype,
156
- AudioWorkletProcessor.prototype);Reflect.setPrototypeOf(l,AudioWorkletProcessor);l.prototype.process=l.prototype.process=function(n,q){for(n=0;n<q[0][0].length;n++){for(var r=0,t=0,u=this.source_offset+this.kernel_size,y=this.source_offset-this.kernel_size+1;y<=u;y++){var A=this.source_block_start+y;r+=this.get_sample(A,0)*this.kernel(this.source_time-y);t+=this.get_sample(A,1)*this.kernel(this.source_time-y)}if(isNaN(r)||isNaN(t))r=t=0,this.dbg_log("ERROR: NaN values! Ignoring for now.");q[0][0][n]=
156
+ AudioWorkletProcessor.prototype);Reflect.setPrototypeOf(l,AudioWorkletProcessor);l.prototype.process=l.prototype.process=function(n,q){for(n=0;n<q[0][0].length;n++){for(var r=0,t=0,v=this.source_offset+this.kernel_size,y=this.source_offset-this.kernel_size+1;y<=v;y++){var A=this.source_block_start+y;r+=this.get_sample(A,0)*this.kernel(this.source_time-y);t+=this.get_sample(A,1)*this.kernel(this.source_time-y)}if(isNaN(r)||isNaN(t))r=t=0,this.dbg_log("ERROR: NaN values! Ignoring for now.");q[0][0][n]=
157
157
  r;q[0][1][n]=t;this.source_time+=this.source_samples_per_destination;this.source_offset=Math.floor(this.source_time)}q=this.source_offset;q+=this.kernel_size+2;this.source_time-=this.source_offset;this.source_block_start+=this.source_offset;this.source_offset=0;this.ensure_enough_data(q);return!0};l.prototype.kernel=function(n){return h(n)*h(n/this.kernel_size)};l.prototype.get_sample=function(n,q){return 0>n?(n+=this.source_buffer_previous[0].length,this.source_buffer_previous[q][n]):this.source_buffer_current[q][n]};
158
158
  l.prototype.ensure_enough_data=function(n){var q=this.source_buffer_current[0].length;q-this.source_block_start<n&&(this.prepare_next_buffer(),this.source_block_start-=q)};l.prototype.prepare_next_buffer=function(){256>this.queued_samples&&this.queue_length&&this.dbg_log("Not enough samples - should not happen during midway of playback");this.source_buffer_previous=this.source_buffer_current;this.source_buffer_current=this.queue_shift();var n=this.source_buffer_current[0].length;if(256>n){for(var q=
159
- this.queue_start,r=0;256>n&&r<this.queue_length;)n+=this.queue_data[q][0].length,q=q+1&this.queue_size-1,r++;n=Math.max(n,256);n=[new Float32Array(n),new Float32Array(n)];n[0].set(this.source_buffer_current[0]);n[1].set(this.source_buffer_current[1]);q=this.source_buffer_current[0].length;for(var t=0;t<r;t++){var u=this.queue_shift();n[0].set(u[0],q);n[1].set(u[1],q);q+=u[0].length}this.source_buffer_current=n}this.pump()};l.prototype.pump=function(){1024>this.queued_samples/this.source_samples_per_destination&&
159
+ this.queue_start,r=0;256>n&&r<this.queue_length;)n+=this.queue_data[q][0].length,q=q+1&this.queue_size-1,r++;n=Math.max(n,256);n=[new Float32Array(n),new Float32Array(n)];n[0].set(this.source_buffer_current[0]);n[1].set(this.source_buffer_current[1]);q=this.source_buffer_current[0].length;for(var t=0;t<r;t++){var v=this.queue_shift();n[0].set(v[0],q);n[1].set(v[1],q);q+=v[0].length}this.source_buffer_current=n}this.pump()};l.prototype.pump=function(){1024>this.queued_samples/this.source_samples_per_destination&&
160
160
  this.port.postMessage({type:"pump"})};l.prototype.queue_push=function(n){this.queue_length<this.queue_size&&(this.queue_data[this.queue_end]=n,this.queue_end=this.queue_end+1&this.queue_size-1,this.queue_length++,this.queued_samples+=n[0].length,this.pump())};l.prototype.queue_shift=function(){if(!this.queue_length)return p;var n=this.queue_data[this.queue_start];this.queue_data[this.queue_start]=null;this.queue_start=this.queue_start+1&this.queue_size-1;this.queue_length--;this.queued_samples-=n[0].length;
161
161
  return n};l.prototype.dbg_log=function(n){this.port.postMessage({type:"debug-log",value:n})};registerProcessor("dac-processor",l)}.toString();var d=b.indexOf("{")+1,e=b.lastIndexOf("}");b=b.substring(d,e);b=new Blob(["var DEBUG = true;\n"+b],{type:"application/javascript"});var f=URL.createObjectURL(b);this.node_processor=null;this.node_output=this.audio_context.createGain();this.audio_context.audioWorklet.addModule(f).then(()=>{URL.revokeObjectURL(f);this.node_processor=new AudioWorkletNode(this.audio_context,
162
162
  "dac-processor",{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[2],parameterData:{},processorOptions:{}});this.node_processor.port.postMessage({type:"sampling-rate",value:this.sampling_rate});this.node_processor.port.onmessage=h=>{switch(h.data.type){case "pump":this.pump();break;case "debug-log":C("SpeakerWorkletDAC - Worklet: "+h.data.value)}};this.node_processor.connect(this.node_output)});this.mixer_connection=c.add_source(this.node_output,2);this.mixer_connection.set_gain_hidden(3);a.register("dac-send-data",
@@ -177,8 +177,8 @@ c.set(a.subarray(0,f),this.head);c.set(a.subarray(f))}else c.set(a,this.head);th
177
177
  return{eth_frame:a,eth_frame_view:new DataView(b),eth_payload_view:new DataView(b,c+14,1500),ipv4_payload_view:new DataView(b,c+34,1480),udp_payload_view:new DataView(b,c+42,1472),text_encoder:new TextEncoder}}function Ob(a,b,c,d){d.eth_frame.set(b,c.byteOffset+a);return b.length}function Pb(a,b,c,d){const e=c.byteOffset+(a&-2);d=d.eth_frame;for(c=c.byteOffset;c<e;c+=2)b+=d[c]<<8|d[c+1];for(a&1&&(b+=d[e]<<8);b>>>16;)b=(b&65535)+(b>>>16);return~b&65535}function Qb(a,b){k(b.eth);a.eth_frame.fill(0);
178
178
  var c=a.eth_frame,d=c.subarray,e=a.eth_frame_view;Ob(0,b.eth.dest,e,a);Ob(6,b.eth.src,e,a);e.setUint16(12,b.eth.ethertype);e=14;if(b.arp){var f=a.eth_payload_view;f.setUint16(0,b.arp.htype);f.setUint16(2,b.arp.ptype);f.setUint8(4,b.arp.sha.length);f.setUint8(5,b.arp.spa.length);f.setUint16(6,b.arp.oper);Ob(8,b.arp.sha,f,a);Ob(14,b.arp.spa,f,a);Ob(18,b.arp.tha,f,a);Ob(24,b.arp.tpa,f,a);e+=28}else if(b.ipv4){f=a.eth_payload_view;var h=20;if(b.icmp){var l=a.ipv4_payload_view;l.setUint8(0,b.icmp.type);
179
179
  l.setUint8(1,b.icmp.code);l.setUint16(2,0);var p=4+Ob(4,b.icmp.data,l,a);l.setUint16(2,Pb(p,0,l,a));h+=p}else if(b.udp){l=a.ipv4_payload_view;var n=8;if(b.dhcp){p=n;var q=a.udp_payload_view;q.setUint8(0,b.dhcp.op);q.setUint8(1,b.dhcp.htype);q.setUint8(2,b.dhcp.hlen);q.setUint8(3,b.dhcp.hops);q.setUint32(4,b.dhcp.xid);q.setUint16(8,b.dhcp.secs);q.setUint16(10,b.dhcp.flags);q.setUint32(12,b.dhcp.ciaddr);q.setUint32(16,b.dhcp.yiaddr);q.setUint32(20,b.dhcp.siaddr);q.setUint32(24,b.dhcp.giaddr);Ob(28,
180
- b.dhcp.chaddr,q,a);q.setUint32(236,1669485411);n=240;for(var r of b.dhcp.options)n+=Ob(n,r,q,a);p+=n}else if(b.dns){r=n;n=a.udp_payload_view;n.setUint16(0,b.dns.id);n.setUint16(2,b.dns.flags);n.setUint16(4,b.dns.questions.length);n.setUint16(6,b.dns.answers.length);let y=12;for(var t=0;t<b.dns.questions.length;++t){var u=b.dns.questions[t];for(q of u.name){const A=a.text_encoder.encodeInto(q,a.eth_frame.subarray(n.byteOffset+(y+1))).written;n.setUint8(y,A);y+=1+A}n.setUint16(y,u.type);y+=2;n.setUint16(y,
181
- u.class);y+=2}for(t=0;t<b.dns.answers.length;++t){q=b.dns.answers[t];for(p of q.name)u=a.text_encoder.encodeInto(p,a.eth_frame.subarray(n.byteOffset+(y+1))).written,n.setUint8(y,u),y+=1+u;n.setUint16(y,q.type);y+=2;n.setUint16(y,q.class);y+=2;n.setUint32(y,q.ttl);y+=4;n.setUint16(y,q.data.length);y+=2;y+=Ob(y,q.data,n,a)}p=r+y}else b.ntp?(p=n,q=a.udp_payload_view,q.setUint8(0,b.ntp.flags),q.setUint8(1,b.ntp.stratum),q.setUint8(2,b.ntp.poll),q.setUint8(3,b.ntp.precision),q.setUint32(4,b.ntp.root_delay),
180
+ b.dhcp.chaddr,q,a);q.setUint32(236,1669485411);n=240;for(var r of b.dhcp.options)n+=Ob(n,r,q,a);p+=n}else if(b.dns){r=n;n=a.udp_payload_view;n.setUint16(0,b.dns.id);n.setUint16(2,b.dns.flags);n.setUint16(4,b.dns.questions.length);n.setUint16(6,b.dns.answers.length);let y=12;for(var t=0;t<b.dns.questions.length;++t){var v=b.dns.questions[t];for(q of v.name){const A=a.text_encoder.encodeInto(q,a.eth_frame.subarray(n.byteOffset+(y+1))).written;n.setUint8(y,A);y+=1+A}n.setUint16(y,v.type);y+=2;n.setUint16(y,
181
+ v.class);y+=2}for(t=0;t<b.dns.answers.length;++t){q=b.dns.answers[t];for(p of q.name)v=a.text_encoder.encodeInto(p,a.eth_frame.subarray(n.byteOffset+(y+1))).written,n.setUint8(y,v),y+=1+v;n.setUint16(y,q.type);y+=2;n.setUint16(y,q.class);y+=2;n.setUint32(y,q.ttl);y+=4;n.setUint16(y,q.data.length);y+=2;y+=Ob(y,q.data,n,a)}p=r+y}else b.ntp?(p=n,q=a.udp_payload_view,q.setUint8(0,b.ntp.flags),q.setUint8(1,b.ntp.stratum),q.setUint8(2,b.ntp.poll),q.setUint8(3,b.ntp.precision),q.setUint32(4,b.ntp.root_delay),
182
182
  q.setUint32(8,b.ntp.root_disp),q.setUint32(12,b.ntp.ref_id),q.setUint32(16,b.ntp.ref_ts_i),q.setUint32(20,b.ntp.ref_ts_f),q.setUint32(24,b.ntp.ori_ts_i),q.setUint32(28,b.ntp.ori_ts_f),q.setUint32(32,b.ntp.rec_ts_i),q.setUint32(36,b.ntp.rec_ts_f),q.setUint32(40,b.ntp.trans_ts_i),q.setUint32(44,b.ntp.trans_ts_f),p+=48):p=n+Ob(0,b.udp.data,a.udp_payload_view,a);n=p;l.setUint16(0,b.udp.sport);l.setUint16(2,b.udp.dport);l.setUint16(4,n);l.setUint16(6,0);l.setUint16(6,Pb(n,(b.ipv4.src[0]<<8|b.ipv4.src[1])+
183
183
  (b.ipv4.src[2]<<8|b.ipv4.src[3])+(b.ipv4.dest[0]<<8|b.ipv4.dest[1])+(b.ipv4.dest[2]<<8|b.ipv4.dest[3])+17+n,l,a));h+=n}else b.tcp&&(l=a.ipv4_payload_view,p=0,q=b.tcp,q.fin&&(p|=1),q.syn&&(p|=2),q.rst&&(p|=4),q.psh&&(p|=8),q.ack&&(p|=16),q.urg&&(p|=32),q.ece&&(p|=64),q.cwr&&(p|=128),l.setUint16(0,q.sport),l.setUint16(2,q.dport),l.setUint32(4,q.seq),l.setUint32(8,q.ackn),l.setUint8(12,80),l.setUint8(13,p),l.setUint16(14,q.winsize),l.setUint16(16,0),l.setUint16(18,q.urgent||0),p=20,b.tcp_data&&(p+=Ob(20,
184
184
  b.tcp_data,l,a)),l.setUint16(16,Pb(p,(b.ipv4.src[0]<<8|b.ipv4.src[1])+(b.ipv4.src[2]<<8|b.ipv4.src[3])+(b.ipv4.dest[0]<<8|b.ipv4.dest[1])+(b.ipv4.dest[2]<<8|b.ipv4.dest[3])+6+p,l,a)),h+=p);f.setUint8(0,69);f.setUint8(1,b.ipv4.tos||0);f.setUint16(2,h);f.setUint16(4,b.ipv4.id||0);f.setUint8(6,64);f.setUint8(8,b.ipv4.ttl||32);f.setUint8(9,b.ipv4.proto);f.setUint16(10,0);Ob(12,b.ipv4.src,f,a);Ob(16,b.ipv4.dest,f,a);f.setUint16(10,Pb(20,0,f,a));e+=h}return d.call(c,0,e)}function Rb(a,b){fetch(`https://${b.doh_server||
@@ -210,62 +210,63 @@ a=this.packet_reply(a,{ack:!0}),this.net.receive(Qb(this.net.eth_encoder_buf,a))
210
210
  Wb.prototype.on_close=function(){this.emit("close")};Wb.prototype.release=function(){this.net.tcp_conn[this.tuple]&&(this.state="closed",delete this.net.tcp_conn[this.tuple])};Wb.prototype.pump=function(){if(this.send_buffer.length&&!this.pending){const a=this.send_chunk_buf,b=this.send_buffer.peek(a),c=this.ipv4_reply();c.tcp.psh=!0;c.tcp_data=a.subarray(0,b);this.net.receive(Qb(this.net.eth_encoder_buf,c));this.pending=!0}};function Yb(a,b){b=b||{};this.bus=a;this.id=b.id||0;this.router_mac=new Uint8Array((b.router_mac||
211
211
  "52:54:0:1:2:3").split(":").map(function(c){return parseInt(c,16)}));this.router_ip=new Uint8Array((b.router_ip||"192.168.86.1").split(".").map(function(c){return parseInt(c,10)}));this.vm_ip=new Uint8Array((b.vm_ip||"192.168.86.100").split(".").map(function(c){return parseInt(c,10)}));this.masquerade=void 0===b.masquerade||!!b.masquerade;this.vm_mac=new Uint8Array(6);this.dns_method=b.dns_method||"static";this.doh_server=b.doh_server;this.tcp_conn={};this.eth_encoder_buf=Nb();this.fetch=(...c)=>
212
212
  fetch(...c);this.cors_proxy=b.cors_proxy;this.bus.register("net"+this.id+"-mac",function(c){this.vm_mac=new Uint8Array(c.split(":").map(function(d){return parseInt(d,16)}))},this);this.bus.register("net"+this.id+"-send",function(c){this.send(c)},this)}Yb.prototype.destroy=function(){};Yb.prototype.on_tcp_connection=function(a,b){if(80===a.tcp.dport){let c=new Wb;c.state="syn-received";c.net=this;c.on("data",ec);c.tuple=b;c.accept(a);this.tcp_conn[b]=c;return!0}return!1};Yb.prototype.connect=function(a){return Vb(a,
213
- this)};Yb.prototype.tcp_probe=function(a){return Xb(a,this)};async function ec(a){this.read=this.read||"";if((this.read+=(new TextDecoder).decode(a))&&-1!==this.read.indexOf("\r\n\r\n")){var b=this.read.indexOf("\r\n\r\n");a=this.read.substring(0,b).split(/\r\n/);b=this.read.substring(b+4);this.read="";let c=a[0].split(" "),d;d=/^https?:/.test(c[1])?new URL(c[1]):new URL("http://host"+c[1]);"undefined"!==typeof window&&"http:"===d.protocol&&"https:"===window.location.protocol&&(d.protocol="https:");
214
- let e=new Headers;for(let p=1;p<a.length;++p){const n=this.net.parse_http_header(a[p]);if(!n){console.warn('The request contains an invalid header: "%s"',a[p]);this.write((new TextEncoder).encode("HTTP/1.1 400 Bad Request\r\nContent-Length: 0"));return}"host"===n.key.toLowerCase()?d.host=n.value:e.append(n.key,n.value)}C("HTTP Dispatch: "+d.href,16777216);this.name=d.href;a={method:c[0],headers:e};-1!==["put","post"].indexOf(a.method.toLowerCase())&&(a.body=b);const f=this.net.cors_proxy?this.net.cors_proxy+
215
- encodeURIComponent(d.href):d.href,h=new TextEncoder;let l=!1;this.net.fetch(f,a).then(p=>{const n=[`HTTP/1.1 ${p.status} ${p.statusText}`,`x-was-fetch-redirected: ${!!p.redirected}`,`x-fetch-resp-url: ${p.url}`,"Connection: closed"];for(const [q,r]of p.headers.entries())["content-encoding","connection","content-length","transfer-encoding"].includes(q.toLowerCase())||n.push(`${q}: ${r}`);this.write(h.encode(n.join("\r\n")+"\r\n\r\n"));l=!0;if(p.body&&p.body.getReader){const q=p.body.getReader(),r=
216
- ({value:t,done:u})=>{t&&this.write(t);if(u)this.close();else return q.read().then(r)};q.read().then(r)}else p.arrayBuffer().then(q=>{this.write(new Uint8Array(q));this.close()})}).catch(p=>{console.warn("Fetch Failed: "+f+"\n"+p);l||(p=h.encode(`Fetch ${f} failed:\n\n${p.stack||p.message}`),this.writev([h.encode(["HTTP/1.1 502 Fetch Error","Content-Type: text/plain",`Content-Length: ${p.length}`,"Connection: closed"].join("\r\n")+"\r\n\r\n"),p]));this.close()})}}Yb.prototype.fetch=async function(a,
217
- b){this.cors_proxy&&(a=this.cors_proxy+encodeURIComponent(a));try{const c=await fetch(a,b),d=await c.arrayBuffer();return[c,d]}catch(c){return console.warn("Fetch Failed: "+a+"\n"+c),b=new Headers,b.set("Content-Type","text/plain"),[{status:502,statusText:"Fetch Error",headers:b},(new TextEncoder).encode(`Fetch ${a} failed:\n\n${c.stack}`).buffer]}};Yb.prototype.parse_http_header=function(a){var b=a.match(/^([^:]*):(.*)$/);if(b)if(a=b[1],b=b[2].trim(),0===a.length)C("Header key is empty, raw header",
218
- 16777216);else if(0===b.length)C("Header value is empty",16777216);else if(/^[\w-]+$/.test(a)){if(/^[\x20-\x7E]+$/.test(b))return{key:a,value:b};C("Header value contains forbidden characters",16777216)}else C("Header key contains forbidden characters",16777216);else C("Unable to parse HTTP header",16777216)};Yb.prototype.send=function(a){Tb(a,this)};Yb.prototype.receive=function(a){this.bus.send("net"+this.id+"-receive",new Uint8Array(a))};function fc(a,b,c){this.register_ws(a);this.last_stream=1;
219
- this.connections={0:{congestion:0}};this.congested_buffer=[];c=c||{};this.bus=b;this.id=c.id||0;this.router_mac=new Uint8Array((c.router_mac||"52:54:0:1:2:3").split(":").map(function(d){return parseInt(d,16)}));this.router_ip=new Uint8Array((c.router_ip||"192.168.86.1").split(".").map(function(d){return parseInt(d,10)}));this.vm_ip=new Uint8Array((c.vm_ip||"192.168.86.100").split(".").map(function(d){return parseInt(d,10)}));this.masquerade=void 0===c.masquerade||!!c.masquerade;this.vm_mac=new Uint8Array(6);
220
- this.dns_method=c.dns_method||"doh";this.doh_server=c.doh_server;this.tcp_conn={};this.eth_encoder_buf=Nb();this.bus.register("net"+this.id+"-mac",function(d){this.vm_mac=new Uint8Array(d.split(":").map(function(e){return parseInt(e,16)}))},this);this.bus.register("net"+this.id+"-send",function(d){this.send(d)},this)}fc.prototype.register_ws=function(a){this.wispws=new WebSocket(a.replace("wisp://","ws://").replace("wisps://","wss://"));this.wispws.binaryType="arraybuffer";this.wispws.onmessage=b=>
221
- {this.process_incoming_wisp_frame(new Uint8Array(b.data))};this.wispws.onclose=()=>{setTimeout(()=>{this.register_ws(a)},1E4)}};fc.prototype.send_packet=function(a,b,c){this.connections[c]&&(0<this.connections[c].congestion?("DATA"===b&&this.connections[c].congestion--,this.wispws.send(a)):(this.connections[c].congested=!0,this.congested_buffer.push({data:a,type:b})))};fc.prototype.process_incoming_wisp_frame=function(a){const b=new DataView(a.buffer),c=b.getUint32(1,!0);switch(a[0]){case 1:C("Server sent client-only packet CONNECT",
222
- 1048576);break;case 2:if(this.connections[c])this.connections[c].data_callback(a.slice(5));else throw Error("Got a DATA packet but stream not registered. ID: "+c);break;case 3:this.connections[c]&&(this.connections[c].congestion=b.getUint32(5,!0));if(this.connections[c].congested){for(const d of this.congested_buffer)this.send_packet(d.data,d.type,c);this.connections[c].congested=!1}break;case 4:this.connections[c]&&this.connections[c].close_callback(b.getUint8(5));delete this.connections[c];break;
223
- case 5:C("got a wisp V2 upgrade request, ignoring",1048576);break;default:C("Wisp server returned unknown packet: "+a[0],1048576)}};fc.prototype.send_wisp_frame=function(a){let b,c;switch(a.type){case "CONNECT":const d=(new TextEncoder).encode(a.hostname);b=new Uint8Array(8+d.length);c=new DataView(b.buffer);c.setUint8(0,1);c.setUint32(1,a.stream_id,!0);c.setUint8(5,1);c.setUint16(6,a.port,!0);b.set(d,8);this.connections[a.stream_id]={data_callback:a.data_callback,close_callback:a.close_callback,
224
- congestion:this.connections[0].congestion};break;case "DATA":b=new Uint8Array(5+a.data.length);c=new DataView(b.buffer);c.setUint8(0,2);c.setUint32(1,a.stream_id,!0);b.set(a.data,5);break;case "CLOSE":b=new Uint8Array(6);c=new DataView(b.buffer);c.setUint8(0,4);c.setUint32(1,a.stream_id,!0);c.setUint8(5,a.reason);break;default:C("Client tried to send unknown packet: "+a.type,1048576)}this.send_packet(b,a.type,a.stream_id)};fc.prototype.destroy=function(){this.wispws&&(this.wispws.onmessage=null,this.wispws.onclose=
225
- null,this.wispws.close(),this.wispws=null)};fc.prototype.on_tcp_connection=function(a,b){let c=new Wb;c.state="syn-received";c.net=this;c.tuple=b;c.stream_id=this.last_stream++;this.tcp_conn[b]=c;c.on("data",d=>{0!==d.length&&this.send_wisp_frame({type:"DATA",stream_id:c.stream_id,data:d})});c.on_close=()=>{this.send_wisp_frame({type:"CLOSE",stream_id:c.stream_id,reason:2})};c.on_shutdown=c.on_close;this.send_wisp_frame({type:"CONNECT",stream_id:c.stream_id,hostname:a.ipv4.dest.join("."),port:a.tcp.dport,
226
- data_callback:d=>{c.write(d)},close_callback:()=>{c.close()}});c.accept(a);return!0};fc.prototype.send=function(a){Tb(a,this)};fc.prototype.receive=function(a){this.bus.send("net"+this.id+"-receive",new Uint8Array(a))};const gc="undefined"!==typeof window&&0<=window.navigator.platform.toString().toLowerCase().search("win");function hc(a){function b(w){return w.shiftKey&&w.ctrlKey&&(73===w.keyCode||74===w.keyCode||75===w.keyCode)||!u.emu_enabled?!1:w.target?w.target.classList.contains("phone_keyboard")||
227
- "INPUT"!==w.target.nodeName&&"TEXTAREA"!==w.target.nodeName:!0}function c(w){!w.altKey&&n[56]&&l(56,!1);return f(w,!1)}function d(w){!w.altKey&&n[56]&&l(56,!1);return f(w,!0)}function e(){for(var w=Object.keys(n),F,J=0;J<w.length;J++)F=+w[J],n[F]&&l(F,!1);n={}}function f(w,F){if(u.bus&&b(w)){w.preventDefault&&w.preventDefault();if(gc&&(q&&(clearTimeout(t),w.getModifierState&&w.getModifierState("AltGraph")&&r===F&&"ControlLeft"===q.code&&"AltRight"===w.code||h(q,r),q=null),"ControlLeft"===w.code))return q=
228
- w,r=F,t=setTimeout(()=>{h(q,r);q=null},10),!1;h(w,F);return!1}}function h(w,F){a:{if(void 0!==w.code){var J=B[w.code];if(void 0!==J)break a}J=y[w.keyCode]}J?l(J,F,w.repeat):console.log("Missing char in map: keyCode="+(w.keyCode||-1).toString(16)+" code="+w.code)}function l(w,F,J){if(F)n[w]&&!J&&l(w,!1);else if(!n[w])return;(n[w]=F)||(w|=128);255<w?(p(w>>8),p(w&255)):p(w)}function p(w){u.bus.send("keyboard-code",w)}var n={},q=null,r=!1,t=0,u=this;this.emu_enabled=!0;const y=new Uint16Array([0,0,0,
229
- 0,0,0,0,0,14,15,0,0,0,28,0,0,42,29,56,0,58,0,0,0,0,0,0,1,0,0,0,0,57,57417,57425,57423,57415,57419,57416,57421,80,0,0,0,0,82,83,0,11,2,3,4,5,6,7,8,9,10,0,39,0,13,0,0,0,30,48,46,32,18,33,34,35,23,36,37,38,50,49,24,25,16,19,31,20,22,47,17,45,21,44,57435,57436,57437,0,0,82,79,80,81,75,76,77,71,72,73,0,0,0,0,0,0,59,60,61,62,63,64,65,66,67,68,87,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,39,13,51,12,52,53,41,0,0,0,0,0,
230
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,26,43,27,40,0,57435,57400,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),A={8:8,10:13,32:32,39:222,44:188,45:189,46:190,47:191,48:48,49:49,50:50,51:51,52:52,53:53,54:54,55:55,56:56,57:57,59:186,61:187,91:219,92:220,93:221,96:192,97:65,98:66,99:67,100:68,101:69,102:70,103:71,104:72,105:73,106:74,107:75,108:76,109:77,110:78,111:79,112:80,113:81,114:82,115:83,116:84,117:85,118:86,119:87,120:88,121:89,122:90},v={33:49,34:222,35:51,36:52,37:53,38:55,40:57,41:48,42:56,43:187,58:186,
231
- 60:188,62:190,63:191,64:50,65:65,66:66,67:67,68:68,69:69,70:70,71:71,72:72,73:73,74:74,75:75,76:76,77:77,78:78,79:79,80:80,81:81,82:82,83:83,84:84,85:85,86:86,87:87,88:88,89:89,90:90,94:54,95:189,123:219,124:220,125:221,126:192};var B={Escape:1,Digit1:2,Digit2:3,Digit3:4,Digit4:5,Digit5:6,Digit6:7,Digit7:8,Digit8:9,Digit9:10,Digit0:11,Minus:12,Equal:13,Backspace:14,Tab:15,KeyQ:16,KeyW:17,KeyE:18,KeyR:19,KeyT:20,KeyY:21,KeyU:22,KeyI:23,KeyO:24,KeyP:25,BracketLeft:26,BracketRight:27,Enter:28,ControlLeft:29,
232
- KeyA:30,KeyS:31,KeyD:32,KeyF:33,KeyG:34,KeyH:35,KeyJ:36,KeyK:37,KeyL:38,Semicolon:39,Quote:40,Backquote:41,ShiftLeft:42,Backslash:43,KeyZ:44,KeyX:45,KeyC:46,KeyV:47,KeyB:48,KeyN:49,KeyM:50,Comma:51,Period:52,Slash:53,IntlRo:53,ShiftRight:54,NumpadMultiply:55,AltLeft:56,Space:57,CapsLock:58,F1:59,F2:60,F3:61,F4:62,F5:63,F6:64,F7:65,F8:66,F9:67,F10:68,NumLock:69,ScrollLock:70,Numpad7:71,Numpad8:72,Numpad9:73,NumpadSubtract:74,Numpad4:75,Numpad5:76,Numpad6:77,NumpadAdd:78,Numpad1:79,Numpad2:80,Numpad3:81,
233
- Numpad0:82,NumpadDecimal:83,IntlBackslash:86,F11:87,F12:88,NumpadEnter:57372,ControlRight:57373,NumpadDivide:57397,AltRight:57400,Home:57415,ArrowUp:57416,PageUp:57417,ArrowLeft:57419,ArrowRight:57421,End:57423,ArrowDown:57424,PageDown:57425,Insert:57426,Delete:57427,OSLeft:57435,OSRight:57436,ContextMenu:57437};this.bus=a;this.destroy=function(){"undefined"!==typeof window&&(window.removeEventListener("keyup",c,!1),window.removeEventListener("keydown",d,!1),window.removeEventListener("blur",e,!1))};
234
- this.init=function(){"undefined"!==typeof window&&(this.destroy(),window.addEventListener("keyup",c,!1),window.addEventListener("keydown",d,!1),window.addEventListener("blur",e,!1))};this.init();this.simulate_press=function(w){w={keyCode:w};f(w,!0);f(w,!1)};this.simulate_char=function(w){var F=w.charCodeAt(0);F in A?this.simulate_press(A[F]):F in v?(p(42),this.simulate_press(v[F]),p(170)):console.log("ascii -> keyCode not found: ",F,w)}}function ic(a,b){function c(v){if(!A.enabled||!A.emu_enabled)return!1;
235
- var B=b||document.body,w;if(!(w=document.pointerLockElement))a:{for(v=v.target;v.parentNode;){if(v===B){w=!0;break a}v=v.parentNode}w=!1}return w}function d(v){c(v)&&(v=v.changedTouches)&&v.length&&(v=v[v.length-1],u=v.clientX,y=v.clientY)}function e(){if(q||t||r)A.bus.send("mouse-click",[!1,!1,!1]),q=t=r=!1}function f(v){if(A.bus&&c(v)&&A.is_running){var B=0,w=0,F=v.changedTouches;F?F.length&&(F=F[F.length-1],B=F.clientX-u,w=F.clientY-y,u=F.clientX,y=F.clientY,v.preventDefault()):"number"===typeof v.movementX?
236
- (B=v.movementX,w=v.movementY):"number"===typeof v.webkitMovementX?(B=v.webkitMovementX,w=v.webkitMovementY):"number"===typeof v.mozMovementX?(B=v.mozMovementX,w=v.mozMovementY):(B=v.clientX-u,w=v.clientY-y,u=v.clientX,y=v.clientY);A.bus.send("mouse-delta",[.15*B,-(.15*w)]);b&&A.bus.send("mouse-absolute",[v.pageX-b.offsetLeft,v.pageY-b.offsetTop,b.offsetWidth,b.offsetHeight])}}function h(v){c(v)&&p(v,!0)}function l(v){c(v)&&p(v,!1)}function p(v,B){A.bus&&(1===v.which?q=B:2===v.which?t=B:3===v.which?
237
- r=B:C("Unknown event.which: "+v.which),A.bus.send("mouse-click",[q,t,r]),v.preventDefault())}function n(v){if(c(v)){var B=v.wheelDelta||-v.detail;0>B?B=-1:0<B&&(B=1);A.bus.send("mouse-wheel",[B,0]);v.preventDefault()}}var q=!1,r=!1,t=!1,u=0,y=0,A=this;this.enabled=!1;this.emu_enabled=!0;this.bus=a;this.bus.register("mouse-enable",function(v){this.enabled=v},this);this.is_running=!1;this.bus.register("emulator-stopped",function(){this.is_running=!1},this);this.bus.register("emulator-started",function(){this.is_running=
238
- !0},this);this.destroy=function(){"undefined"!==typeof window&&(window.removeEventListener("touchstart",d,!1),window.removeEventListener("touchend",e,!1),window.removeEventListener("touchmove",f,!1),window.removeEventListener("mousemove",f,!1),window.removeEventListener("mousedown",h,!1),window.removeEventListener("mouseup",l,!1),window.removeEventListener("wheel",n,{passive:!1}))};this.init=function(){"undefined"!==typeof window&&(this.destroy(),window.addEventListener("touchstart",d,!1),window.addEventListener("touchend",
239
- e,!1),window.addEventListener("touchmove",f,!1),window.addEventListener("mousemove",f,!1),window.addEventListener("mousedown",h,!1),window.addEventListener("mouseup",l,!1),window.addEventListener("wheel",n,{passive:!1}))};this.init()}function jc(){var a,b=0,c=0;this.put_char=function(d,e,f){k(0<=d&&d<c);k(0<=e&&e<b);a[d*b+e]=f};this.destroy=function(){};this.pause=function(){};this.continue=function(){};this.set_mode=function(){};this.set_font_bitmap=function(){};this.set_font_page=function(){};this.clear_screen=
240
- function(){};this.set_size_text=function(d,e){if(d!==b||e!==c)a=new Uint8Array(d*e),b=d,c=e};this.set_size_graphical=function(){};this.set_scale=function(){};this.update_cursor_scanline=function(){};this.update_cursor=function(){};this.update_buffer=function(){};this.get_text_screen=function(){for(var d=[],e=0;e<c;e++)d.push(this.get_text_row(e));return d};this.get_text_row=function(d){d*=b;return String.fromCharCode.apply(String,a.subarray(d,d+b))};this.set_size_text(80,25)}function kc(a,b){function c(l){h.bus&&
241
- h.enabled&&(h.send_char(l.which),l.preventDefault())}function d(l){var p=l.which;8===p?(h.send_char(127),l.preventDefault()):9===p&&(h.send_char(9),l.preventDefault())}function e(l){if(h.enabled){for(var p=l.clipboardData.getData("text/plain"),n=0;n<p.length;n++)h.send_char(p.charCodeAt(n));l.preventDefault()}}function f(l){l.target!==a&&a.blur()}var h=this;this.enabled=!0;this.bus=b;this.text="";this.text_new_line=!1;this.last_update=0;this.bus.register("serial0-output-byte",function(l){l=String.fromCharCode(l);
242
- this.show_char(l)},this);this.destroy=function(){a.removeEventListener("keypress",c,!1);a.removeEventListener("keydown",d,!1);a.removeEventListener("paste",e,!1);window.removeEventListener("mousedown",f,!1)};this.init=function(){this.destroy();a.style.display="block";a.addEventListener("keypress",c,!1);a.addEventListener("keydown",d,!1);a.addEventListener("paste",e,!1);window.addEventListener("mousedown",f,!1)};this.init();this.show_char=function(l){"\b"===l?(this.text=this.text.slice(0,-1),this.update()):
243
- "\r"!==l&&(this.text+=l,"\n"===l&&(this.text_new_line=!0),this.update())};this.update=function(){var l=Date.now(),p=l-this.last_update;16>p?void 0===this.update_timer&&(this.update_timer=setTimeout(()=>{this.update_timer=void 0;var n=Date.now();k(15<=n-this.last_update);this.last_update=n;this.render()},16-p)):(void 0!==this.update_timer&&(clearTimeout(this.update_timer),this.update_timer=void 0),this.last_update=l,this.render())};this.render=function(){a.value=this.text;this.text_new_line&&(this.text_new_line=
244
- !1,a.scrollTop=1E9)};this.send_char=function(l){h.bus&&h.bus.send("serial0-input",l)}}function lc(a,b){this.element=a;if(window.Terminal){var c=this.term=new window.Terminal({logLevel:"off"});c.write("This is the serial console. Whatever you type or paste here will be sent to COM1");var d=c.onData(function(e){for(let f=0;f<e.length;f++)b.send("serial0-input",e.charCodeAt(f))});b.register("serial0-output-byte",function(e){c.write(Uint8Array.of(e))},this);this.destroy=function(){d.dispose();c.dispose()}}}
245
- lc.prototype.show=function(){this.term&&this.term.open(this.element)};function mc(a,b){b=b.id||0;this.bus=a;this.bus_send_msgid=`net${b}-send`;this.bus_recv_msgid=`net${b}-receive`;this.channel=new BroadcastChannel(`v86-inbrowser-${b}`);this.is_open=!0;this.nic_to_hub_fn=c=>{this.channel.postMessage(c)};this.bus.register(this.bus_send_msgid,this.nic_to_hub_fn,this);this.hub_to_nic_fn=c=>{this.bus.send(this.bus_recv_msgid,c.data)};this.channel.addEventListener("message",this.hub_to_nic_fn)}mc.prototype.destroy=
246
- function(){this.is_open&&(this.bus.unregister(this.bus_send_msgid,this.nic_to_hub_fn),this.channel.removeEventListener("message",this.hub_to_nic_fn),this.channel.close(),this.is_open=!1)};function nc(){this.filedata=new Map}nc.prototype.read=async function(a,b,c){k(a,"MemoryFileStorage read: sha256sum should be a non-empty string");return(a=this.filedata.get(a))?a.subarray(b,b+c):null};nc.prototype.cache=async function(a,b){k(a,"MemoryFileStorage cache: sha256sum should be a non-empty string");this.filedata.set(a,
247
- b)};nc.prototype.uncache=function(a){this.filedata.delete(a)};function oc(a,b){k(b,"ServerMemoryFileStorage: baseurl should not be empty");b.endsWith("/")||(b+="/");this.storage=a;this.baseurl=b}oc.prototype.load_from_server=function(a){return new Promise(b=>{sa(this.baseurl+a,{done:async c=>{c=new Uint8Array(c);await this.cache(a,c);b(c)}})})};oc.prototype.read=async function(a,b,c){const d=await this.storage.read(a,b,c);return d?d:(await this.load_from_server(a)).subarray(b,b+c)};oc.prototype.cache=
248
- async function(a,b){return await this.storage.cache(a,b)};oc.prototype.uncache=function(a){this.storage.uncache(a)};const pc=new TextDecoder,qc=new TextEncoder;function K(a,b,c,d){for(var e,f=0,h=0;h<a.length;h++)switch(e=b[h],a[h]){case "w":c[d++]=e&255;c[d++]=e>>8&255;c[d++]=e>>16&255;c[d++]=e>>24&255;f+=4;break;case "d":c[d++]=e&255;c[d++]=e>>8&255;c[d++]=e>>16&255;c[d++]=e>>24&255;c[d++]=0;c[d++]=0;c[d++]=0;c[d++]=0;f+=8;break;case "h":c[d++]=e&255;c[d++]=e>>8;f+=2;break;case "b":c[d++]=e;f+=
249
- 1;break;case "s":var l=d,p=0;c[d++]=0;c[d++]=0;f+=2;e=qc.encode(e);f+=e.byteLength;p+=e.byteLength;c.set(e,d);d+=e.byteLength;c[l+0]=p&255;c[l+1]=p>>8&255;break;case "Q":K(["b","w","d"],[e.type,e.version,e.path],c,d);d+=13;f+=13;break;default:C("Marshall: Unknown type="+a[h])}return f}function M(a,b,c){let d=c.offset;for(var e=[],f=0;f<a.length;f++)switch(a[f]){case "w":var h=b[d++];h+=b[d++]<<8;h+=b[d++]<<16;h+=b[d++]<<24>>>0;e.push(h);break;case "d":h=b[d++];h+=b[d++]<<8;h+=b[d++]<<16;h+=b[d++]<<
250
- 24>>>0;d+=4;e.push(h);break;case "h":h=b[d++];e.push(h+(b[d++]<<8));break;case "b":e.push(b[d++]);break;case "s":h=b[d++];h+=b[d++]<<8;var l=b.slice(d,d+h);d+=h;e.push(pc.decode(l));break;case "Q":c.offset=d;h=M(["b","w","d"],b,c);d=c.offset;e.push({type:h[0],version:h[1],path:h[2]});break;default:C("Error in Unmarshall: Unknown type="+a[f])}c.offset=d;return e}const rc=new TextEncoder;function N(a,b){this.inodes=[];this.events=[];this.storage=a;this.qidcounter=b||{last_qidnumber:0};this.inodedata=
251
- {};this.total_size=274877906944;this.used_size=0;this.mounts=[];this.CreateDirectory("",-1)}N.prototype.get_state=function(){let a=[];a[0]=this.inodes;a[1]=this.qidcounter.last_qidnumber;a[2]=[];for(const [b,c]of Object.entries(this.inodedata))0===(this.inodes[b].mode&16384)&&a[2].push([b,c]);a[3]=this.total_size;a[4]=this.used_size;return a=a.concat(this.mounts)};N.prototype.set_state=function(a){this.inodes=a[0].map(b=>{const c=new sc(0);c.set_state(b);return c});this.qidcounter.last_qidnumber=
252
- a[1];this.inodedata={};for(let [b,c]of a[2])c.buffer.byteLength!==c.byteLength&&(c=c.slice()),this.inodedata[b]=c;this.total_size=a[3];this.used_size=a[4];this.mounts=a.slice(5)};N.prototype.AddEvent=function(a,b){var c=this.inodes[a];0===c.status||2===c.status?b():this.is_forwarder(c)?this.follow_fs(c).AddEvent(c.foreign_id,b):this.events.push({id:a,OnEvent:b})};N.prototype.HandleEvent=function(a){var b=this.inodes[a];this.is_forwarder(b)&&this.follow_fs(b).HandleEvent(b.foreign_id);b=[];for(var c=
253
- 0;c<this.events.length;c++)this.events[c].id===a?this.events[c].OnEvent():b.push(this.events[c]);this.events=b};N.prototype.load_from_json=function(a){k(a,"Invalid fs passed to load_from_json");if(3!==a.version)throw"The filesystem JSON format has changed. Please update your fs2json (https://github.com/copy/fs2json) and recreate the filesystem JSON.";var b=a.fsroot;this.used_size=a.size;for(a=0;a<b.length;a++)this.LoadRecursive(b[a],0)};N.prototype.LoadRecursive=function(a,b){var c=this.CreateInode();
254
- const d=a[0];c.size=a[1];c.mtime=a[2];c.ctime=c.mtime;c.atime=c.mtime;c.mode=a[3];c.uid=a[4];c.gid=a[5];var e=c.mode&61440;16384===e?(this.PushInode(c,b,d),this.LoadDir(this.inodes.length-1,a[6])):32768===e?(c.status=2,c.sha256sum=a[6],k(c.sha256sum),this.PushInode(c,b,d)):40960===e?(c.symlink=a[6],this.PushInode(c,b,d)):49152!==e&&C("Unexpected ifmt: "+m(e)+" ("+d+")",4194304)};N.prototype.LoadDir=function(a,b){for(var c=0;c<b.length;c++)this.LoadRecursive(b[c],a)};N.prototype.should_be_linked=function(a){return!this.is_forwarder(a)||
255
- 0===a.foreign_id};N.prototype.link_under_dir=function(a,b,c){const d=this.inodes[b],e=this.inodes[a];k(!this.is_forwarder(e),"Filesystem: Shouldn't link under fowarder parents");k(this.IsDirectory(a),"Filesystem: Can't link under non-directories");k(this.should_be_linked(d),"Filesystem: Can't link across filesystems apart from their root");k(0<=d.nlinks,"Filesystem: Found negative nlinks value of "+d.nlinks);k(!e.direntries.has(c),"Filesystem: Name '"+c+"' is already taken");e.direntries.set(c,b);
256
- d.nlinks++;this.IsDirectory(b)&&(k(!d.direntries.has(".."),"Filesystem: Cannot link a directory twice"),d.direntries.has(".")||d.nlinks++,d.direntries.set(".",b),d.direntries.set("..",a),e.nlinks++)};N.prototype.unlink_from_dir=function(a,b){const c=this.Search(a,b),d=this.inodes[c],e=this.inodes[a];k(!this.is_forwarder(e),"Filesystem: Can't unlink from forwarders");k(this.IsDirectory(a),"Filesystem: Can't unlink from non-directories");e.direntries.delete(b)?(d.nlinks--,this.IsDirectory(c)&&(k(d.direntries.get("..")===
257
- a,"Filesystem: Found directory with bad parent id"),d.direntries.delete(".."),e.nlinks--),k(0<=d.nlinks,"Filesystem: Found negative nlinks value of "+d.nlinks)):k(!1,"Filesystem: Can't unlink non-existent file: "+b)};N.prototype.PushInode=function(a,b,c){-1!==b?(this.inodes.push(a),a.fid=this.inodes.length-1,this.link_under_dir(b,a.fid,c)):0===this.inodes.length?(this.inodes.push(a),a.direntries.set(".",0),a.direntries.set("..",0),a.nlinks=2):k(!1,"Error in Filesystem: Pushed inode with name = "+
258
- c+" has no parent")};function sc(a){this.direntries=new Map;this.minor=this.major=this.mtime=this.atime=this.ctime=this.fid=this.gid=this.uid=this.size=this.status=0;this.symlink="";this.mode=493;this.qid={type:0,version:0,path:a};this.caps=void 0;this.nlinks=0;this.sha256sum="";this.locks=[];this.foreign_id=this.mount_id=-1}sc.prototype.get_state=function(){const a=[];a[0]=this.mode;a[1]=16384===(this.mode&61440)?[...this.direntries]:32768===(this.mode&61440)?this.sha256sum:40960===(this.mode&61440)?
259
- this.symlink:49152===(this.mode&61440)?[this.minor,this.major]:null;a[2]=this.locks;a[3]=this.status;a[4]=this.size;a[5]=this.uid;a[6]=this.gid;a[7]=this.fid;a[8]=this.ctime;a[9]=this.atime;a[10]=this.mtime;a[11]=this.qid.version;a[12]=this.qid.path;a[13]=this.nlinks;return a};sc.prototype.set_state=function(a){this.mode=a[0];if(16384===(this.mode&61440)){this.direntries=new Map;for(const [b,c]of a[1])this.direntries.set(b,c)}else 32768===(this.mode&61440)?this.sha256sum=a[1]:40960===(this.mode&61440)?
260
- this.symlink=a[1]:49152===(this.mode&61440)&&([this.minor,this.major]=a[1]);this.locks=[];for(const b of a[2]){const c=new tc;c.set_state(b);this.locks.push(c)}this.status=a[3];this.size=a[4];this.uid=a[5];this.gid=a[6];this.fid=a[7];this.ctime=a[8];this.atime=a[9];this.mtime=a[10];this.qid.type=(this.mode&61440)>>8;this.qid.version=a[11];this.qid.path=a[12];this.nlinks=a[13]};N.prototype.divert=function(a,b){const c=this.Search(a,b),d=this.inodes[c],e=new sc(-1);k(d,"Filesystem divert: name ("+b+
261
- ") not found");k(this.IsDirectory(c)||1>=d.nlinks,"Filesystem: can't divert hardlinked file '"+b+"' with nlinks="+d.nlinks);Object.assign(e,d);const f=this.inodes.length;this.inodes.push(e);e.fid=f;this.is_forwarder(d)&&this.mounts[d.mount_id].backtrack.set(d.foreign_id,f);this.should_be_linked(d)&&(this.unlink_from_dir(a,b),this.link_under_dir(a,f,b));if(this.IsDirectory(c)&&!this.is_forwarder(d))for(const [h,l]of e.direntries)"."!==h&&".."!==h&&this.IsDirectory(l)&&this.inodes[l].direntries.set("..",
262
- f);this.inodedata[f]=this.inodedata[c];delete this.inodedata[c];d.direntries=new Map;d.nlinks=0;return f};N.prototype.copy_inode=function(a,b){Object.assign(b,a,{fid:b.fid,direntries:b.direntries,nlinks:b.nlinks})};N.prototype.CreateInode=function(){const a=Math.round(Date.now()/1E3),b=new sc(++this.qidcounter.last_qidnumber);b.atime=b.ctime=b.mtime=a;return b};N.prototype.CreateDirectory=function(a,b){var c=this.inodes[b];if(0<=b&&this.is_forwarder(c))return b=c.foreign_id,a=this.follow_fs(c).CreateDirectory(a,
263
- b),this.create_forwarder(c.mount_id,a);c=this.CreateInode();c.mode=16895;0<=b&&(c.uid=this.inodes[b].uid,c.gid=this.inodes[b].gid,c.mode=this.inodes[b].mode&511|16384);c.qid.type=64;this.PushInode(c,b,a);this.NotifyListeners(this.inodes.length-1,"newdir");return this.inodes.length-1};N.prototype.CreateFile=function(a,b){var c=this.inodes[b];if(this.is_forwarder(c))return b=c.foreign_id,a=this.follow_fs(c).CreateFile(a,b),this.create_forwarder(c.mount_id,a);c=this.CreateInode();c.uid=this.inodes[b].uid;
264
- c.gid=this.inodes[b].gid;c.qid.type=128;c.mode=this.inodes[b].mode&438|32768;this.PushInode(c,b,a);this.NotifyListeners(this.inodes.length-1,"newfile");return this.inodes.length-1};N.prototype.CreateNode=function(a,b,c,d){var e=this.inodes[b];if(this.is_forwarder(e))return b=e.foreign_id,a=this.follow_fs(e).CreateNode(a,b,c,d),this.create_forwarder(e.mount_id,a);e=this.CreateInode();e.major=c;e.minor=d;e.uid=this.inodes[b].uid;e.gid=this.inodes[b].gid;e.qid.type=192;e.mode=this.inodes[b].mode&438;
265
- this.PushInode(e,b,a);return this.inodes.length-1};N.prototype.CreateSymlink=function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,a=this.follow_fs(d).CreateSymlink(a,b,c),this.create_forwarder(d.mount_id,a);d=this.CreateInode();d.uid=this.inodes[b].uid;d.gid=this.inodes[b].gid;d.qid.type=160;d.symlink=c;d.mode=40960;this.PushInode(d,b,a);return this.inodes.length-1};N.prototype.CreateTextFile=async function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=
266
- d.foreign_id,c=await this.follow_fs(d).CreateTextFile(a,b,c),this.create_forwarder(d.mount_id,c);d=this.CreateFile(a,b);b=this.inodes[d];a=new Uint8Array(c.length);b.size=c.length;for(b=0;b<c.length;b++)a[b]=c.charCodeAt(b);await this.set_data(d,a);return d};N.prototype.CreateBinaryFile=async function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,c=await this.follow_fs(d).CreateBinaryFile(a,b,c),this.create_forwarder(d.mount_id,c);d=this.CreateFile(a,b);a=this.inodes[d];
267
- b=new Uint8Array(c.length);b.set(c);await this.set_data(d,b);a.size=c.length;return d};N.prototype.OpenInode=function(a,b){var c=this.inodes[a];if(this.is_forwarder(c))return this.follow_fs(c).OpenInode(c.foreign_id,b);16384===(c.mode&61440)&&this.FillDirectory(a);return!0};N.prototype.CloseInode=async function(a){var b=this.inodes[a];if(this.is_forwarder(b))return await this.follow_fs(b).CloseInode(b.foreign_id);2===b.status&&this.storage.uncache(b.sha256sum);4===b.status&&(b.status=-1,await this.DeleteData(a))};
268
- N.prototype.Rename=async function(a,b,c,d){if(a===c&&b===d)return 0;var e=this.Search(a,b);if(-1===e)return-2;var f=this.GetFullPath(a)+"/"+b;if(-1!==this.Search(c,d)){var h=this.Unlink(c,d);if(0>h)return h}var l=this.inodes[e],p=this.inodes[a];h=this.inodes[c];if(this.is_forwarder(p)||this.is_forwarder(h))if(this.is_forwarder(p)&&p.mount_id===h.mount_id){if(a=await this.follow_fs(p).Rename(p.foreign_id,b,h.foreign_id,d),0>a)return a}else{if(this.is_a_root(e))return C("XXX: Attempted to move mountpoint ("+
213
+ this)};Yb.prototype.tcp_probe=function(a){return Xb(a,this)};async function ec(a){this.read=this.read||"";if((this.read+=(new TextDecoder).decode(a))&&-1!==this.read.indexOf("\r\n\r\n")){a=this.read.indexOf("\r\n\r\n");var b=this.read.substring(0,a).split(/\r\n/);a=this.read.substring(a+4);this.read="";let c=b[0].split(" "),d;d=/^https?:/.test(c[1])?new URL(c[1]):new URL("http://host"+c[1]);"undefined"!==typeof window&&"http:"===d.protocol&&"https:"===window.location.protocol&&(d.protocol="https:");
214
+ let e=new Headers;for(let l=1;l<b.length;++l){const p=this.net.parse_http_header(b[l]);if(!p){console.warn('The request contains an invalid header: "%s"',b[l]);this.net.respond_text_and_close(this,400,"Bad Request",`Invalid header in request: ${b[l]}`);return}"host"===p.key.toLowerCase()?d.host=p.value:e.append(p.key,p.value)}if(!this.net.cors_proxy&&/^\d+\.external$/.test(d.hostname))if(C("Request to localhost: "+d.href,16777216),b=parseInt(d.hostname.split(".")[0],10),!isNaN(b)&&0<b&&65536>b)d.protocol=
215
+ "http:",d.hostname="localhost",d.port=b.toString(10);else{console.warn('Unknown port for localhost: "%s"',d.href);this.net.respond_text_and_close(this,400,"Bad Request",`Unknown port for localhost: ${d.href}`);return}C("HTTP Dispatch: "+d.href,16777216);this.name=d.href;b={method:c[0],headers:e};-1!==["put","post"].indexOf(b.method.toLowerCase())&&(b.body=a);const f=this.net.cors_proxy?this.net.cors_proxy+encodeURIComponent(d.href):d.href;new TextEncoder;let h=!1;this.net.fetch(f,b).then(l=>{let p=
216
+ new Headers(l.headers);p.delete("content-encoding");p.delete("keep-alive");p.delete("content-length");p.delete("transfer-encoding");p.set("x-was-fetch-redirected",`${!!l.redirected}`);p.set("x-fetch-resp-url",l.url);p.set("connection","close");this.write(this.net.form_response_head(l.status,l.statusText,p));h=!0;if(l.body&&l.body.getReader){const n=l.body.getReader(),q=({value:r,done:t})=>{r&&this.write(r);if(t)this.close();else return n.read().then(q)};n.read().then(q)}else l.arrayBuffer().then(n=>
217
+ {this.write(new Uint8Array(n));this.close()})}).catch(l=>{console.warn("Fetch Failed: "+f+"\n"+l);h||this.net.respond_text_and_close(this,502,"Fetch Error",`Fetch ${f} failed:\n\n${l.stack||l.message}`);this.close()})}}Yb.prototype.fetch=async function(a,b){this.cors_proxy&&(a=this.cors_proxy+encodeURIComponent(a));try{const c=await fetch(a,b),d=await c.arrayBuffer();return[c,d]}catch(c){return console.warn("Fetch Failed: "+a+"\n"+c),[{status:502,statusText:"Fetch Error",headers:new Headers({"Content-Type":"text/plain"})},
218
+ (new TextEncoder).encode(`Fetch ${a} failed:\n\n${c.stack}`).buffer]}};Yb.prototype.form_response_head=function(a,b,c){a=[`HTTP/1.1 ${a} ${b}`];for(const [d,e]of c.entries())a.push(`${d}: ${e}`);return(new TextEncoder).encode(a.join("\r\n")+"\r\n\r\n")};Yb.prototype.respond_text_and_close=function(a,b,c,d){const e=new Headers({"content-type":"text/plain","content-length":d.length.toString(10),connection:"close"});a.writev([this.form_response_head(b,c,e),(new TextEncoder).encode(d)]);a.close()};Yb.prototype.parse_http_header=
219
+ function(a){var b=a.match(/^([^:]*):(.*)$/);if(b)if(a=b[1],b=b[2].trim(),0===a.length)C("Header key is empty, raw header",16777216);else if(0===b.length)C("Header value is empty",16777216);else if(/^[\w-]+$/.test(a)){if(/^[\x20-\x7E]+$/.test(b))return{key:a,value:b};C("Header value contains forbidden characters",16777216)}else C("Header key contains forbidden characters",16777216);else C("Unable to parse HTTP header",16777216)};Yb.prototype.send=function(a){Tb(a,this)};Yb.prototype.receive=function(a){this.bus.send("net"+
220
+ this.id+"-receive",new Uint8Array(a))};function fc(a,b,c){this.register_ws(a);this.last_stream=1;this.connections={0:{congestion:0}};this.congested_buffer=[];c=c||{};this.bus=b;this.id=c.id||0;this.router_mac=new Uint8Array((c.router_mac||"52:54:0:1:2:3").split(":").map(function(d){return parseInt(d,16)}));this.router_ip=new Uint8Array((c.router_ip||"192.168.86.1").split(".").map(function(d){return parseInt(d,10)}));this.vm_ip=new Uint8Array((c.vm_ip||"192.168.86.100").split(".").map(function(d){return parseInt(d,
221
+ 10)}));this.masquerade=void 0===c.masquerade||!!c.masquerade;this.vm_mac=new Uint8Array(6);this.dns_method=c.dns_method||"doh";this.doh_server=c.doh_server;this.tcp_conn={};this.eth_encoder_buf=Nb();this.bus.register("net"+this.id+"-mac",function(d){this.vm_mac=new Uint8Array(d.split(":").map(function(e){return parseInt(e,16)}))},this);this.bus.register("net"+this.id+"-send",function(d){this.send(d)},this)}fc.prototype.register_ws=function(a){this.wispws=new WebSocket(a.replace("wisp://","ws://").replace("wisps://",
222
+ "wss://"));this.wispws.binaryType="arraybuffer";this.wispws.onmessage=b=>{this.process_incoming_wisp_frame(new Uint8Array(b.data))};this.wispws.onclose=()=>{setTimeout(()=>{this.register_ws(a)},1E4)}};fc.prototype.send_packet=function(a,b,c){this.connections[c]&&(0<this.connections[c].congestion?("DATA"===b&&this.connections[c].congestion--,this.wispws.send(a)):(this.connections[c].congested=!0,this.congested_buffer.push({data:a,type:b})))};fc.prototype.process_incoming_wisp_frame=function(a){const b=
223
+ new DataView(a.buffer),c=b.getUint32(1,!0);switch(a[0]){case 1:C("Server sent client-only packet CONNECT",1048576);break;case 2:if(this.connections[c])this.connections[c].data_callback(a.slice(5));else throw Error("Got a DATA packet but stream not registered. ID: "+c);break;case 3:this.connections[c]&&(this.connections[c].congestion=b.getUint32(5,!0));if(this.connections[c].congested){for(const d of this.congested_buffer)this.send_packet(d.data,d.type,c);this.connections[c].congested=!1}break;case 4:this.connections[c]&&
224
+ this.connections[c].close_callback(b.getUint8(5));delete this.connections[c];break;case 5:C("got a wisp V2 upgrade request, ignoring",1048576);break;default:C("Wisp server returned unknown packet: "+a[0],1048576)}};fc.prototype.send_wisp_frame=function(a){let b,c;switch(a.type){case "CONNECT":const d=(new TextEncoder).encode(a.hostname);b=new Uint8Array(8+d.length);c=new DataView(b.buffer);c.setUint8(0,1);c.setUint32(1,a.stream_id,!0);c.setUint8(5,1);c.setUint16(6,a.port,!0);b.set(d,8);this.connections[a.stream_id]=
225
+ {data_callback:a.data_callback,close_callback:a.close_callback,congestion:this.connections[0].congestion};break;case "DATA":b=new Uint8Array(5+a.data.length);c=new DataView(b.buffer);c.setUint8(0,2);c.setUint32(1,a.stream_id,!0);b.set(a.data,5);break;case "CLOSE":b=new Uint8Array(6);c=new DataView(b.buffer);c.setUint8(0,4);c.setUint32(1,a.stream_id,!0);c.setUint8(5,a.reason);break;default:C("Client tried to send unknown packet: "+a.type,1048576)}this.send_packet(b,a.type,a.stream_id)};fc.prototype.destroy=
226
+ function(){this.wispws&&(this.wispws.onmessage=null,this.wispws.onclose=null,this.wispws.close(),this.wispws=null)};fc.prototype.on_tcp_connection=function(a,b){let c=new Wb;c.state="syn-received";c.net=this;c.tuple=b;c.stream_id=this.last_stream++;this.tcp_conn[b]=c;c.on("data",d=>{0!==d.length&&this.send_wisp_frame({type:"DATA",stream_id:c.stream_id,data:d})});c.on_close=()=>{this.send_wisp_frame({type:"CLOSE",stream_id:c.stream_id,reason:2})};c.on_shutdown=c.on_close;this.send_wisp_frame({type:"CONNECT",
227
+ stream_id:c.stream_id,hostname:a.ipv4.dest.join("."),port:a.tcp.dport,data_callback:d=>{c.write(d)},close_callback:()=>{c.close()}});c.accept(a);return!0};fc.prototype.send=function(a){Tb(a,this)};fc.prototype.receive=function(a){this.bus.send("net"+this.id+"-receive",new Uint8Array(a))};const gc="undefined"!==typeof window&&0<=window.navigator.platform.toString().toLowerCase().search("win");function hc(a){function b(w){return w.shiftKey&&w.ctrlKey&&(73===w.keyCode||74===w.keyCode||75===w.keyCode)||
228
+ !v.emu_enabled?!1:w.target?w.target.classList.contains("phone_keyboard")||"INPUT"!==w.target.nodeName&&"TEXTAREA"!==w.target.nodeName:!0}function c(w){!w.altKey&&n[56]&&l(56,!1);return f(w,!1)}function d(w){!w.altKey&&n[56]&&l(56,!1);return f(w,!0)}function e(){for(var w=Object.keys(n),F,J=0;J<w.length;J++)F=+w[J],n[F]&&l(F,!1);n={}}function f(w,F){if(v.bus&&b(w)){w.preventDefault&&w.preventDefault();if(gc&&(q&&(clearTimeout(t),w.getModifierState&&w.getModifierState("AltGraph")&&r===F&&"ControlLeft"===
229
+ q.code&&"AltRight"===w.code||h(q,r),q=null),"ControlLeft"===w.code))return q=w,r=F,t=setTimeout(()=>{h(q,r);q=null},10),!1;h(w,F);return!1}}function h(w,F){a:{if(void 0!==w.code){var J=B[w.code];if(void 0!==J)break a}J=y[w.keyCode]}J?l(J,F,w.repeat):console.log("Missing char in map: keyCode="+(w.keyCode||-1).toString(16)+" code="+w.code)}function l(w,F,J){if(F)n[w]&&!J&&l(w,!1);else if(!n[w])return;(n[w]=F)||(w|=128);255<w?(p(w>>8),p(w&255)):p(w)}function p(w){v.bus.send("keyboard-code",w)}var n=
230
+ {},q=null,r=!1,t=0,v=this;this.emu_enabled=!0;const y=new Uint16Array([0,0,0,0,0,0,0,0,14,15,0,0,0,28,0,0,42,29,56,0,58,0,0,0,0,0,0,1,0,0,0,0,57,57417,57425,57423,57415,57419,57416,57421,80,0,0,0,0,82,83,0,11,2,3,4,5,6,7,8,9,10,0,39,0,13,0,0,0,30,48,46,32,18,33,34,35,23,36,37,38,50,49,24,25,16,19,31,20,22,47,17,45,21,44,57435,57436,57437,0,0,82,79,80,81,75,76,77,71,72,73,0,0,0,0,0,0,59,60,61,62,63,64,65,66,67,68,87,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
231
+ 0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,39,13,51,12,52,53,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,26,43,27,40,0,57435,57400,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),A={8:8,10:13,32:32,39:222,44:188,45:189,46:190,47:191,48:48,49:49,50:50,51:51,52:52,53:53,54:54,55:55,56:56,57:57,59:186,61:187,91:219,92:220,93:221,96:192,97:65,98:66,99:67,100:68,101:69,102:70,103:71,104:72,105:73,106:74,107:75,108:76,109:77,110:78,111:79,112:80,113:81,114:82,115:83,116:84,117:85,118:86,119:87,120:88,121:89,
232
+ 122:90},u={33:49,34:222,35:51,36:52,37:53,38:55,40:57,41:48,42:56,43:187,58:186,60:188,62:190,63:191,64:50,65:65,66:66,67:67,68:68,69:69,70:70,71:71,72:72,73:73,74:74,75:75,76:76,77:77,78:78,79:79,80:80,81:81,82:82,83:83,84:84,85:85,86:86,87:87,88:88,89:89,90:90,94:54,95:189,123:219,124:220,125:221,126:192};var B={Escape:1,Digit1:2,Digit2:3,Digit3:4,Digit4:5,Digit5:6,Digit6:7,Digit7:8,Digit8:9,Digit9:10,Digit0:11,Minus:12,Equal:13,Backspace:14,Tab:15,KeyQ:16,KeyW:17,KeyE:18,KeyR:19,KeyT:20,KeyY:21,
233
+ KeyU:22,KeyI:23,KeyO:24,KeyP:25,BracketLeft:26,BracketRight:27,Enter:28,ControlLeft:29,KeyA:30,KeyS:31,KeyD:32,KeyF:33,KeyG:34,KeyH:35,KeyJ:36,KeyK:37,KeyL:38,Semicolon:39,Quote:40,Backquote:41,ShiftLeft:42,Backslash:43,KeyZ:44,KeyX:45,KeyC:46,KeyV:47,KeyB:48,KeyN:49,KeyM:50,Comma:51,Period:52,Slash:53,IntlRo:53,ShiftRight:54,NumpadMultiply:55,AltLeft:56,Space:57,CapsLock:58,F1:59,F2:60,F3:61,F4:62,F5:63,F6:64,F7:65,F8:66,F9:67,F10:68,NumLock:69,ScrollLock:70,Numpad7:71,Numpad8:72,Numpad9:73,NumpadSubtract:74,
234
+ Numpad4:75,Numpad5:76,Numpad6:77,NumpadAdd:78,Numpad1:79,Numpad2:80,Numpad3:81,Numpad0:82,NumpadDecimal:83,IntlBackslash:86,F11:87,F12:88,NumpadEnter:57372,ControlRight:57373,NumpadDivide:57397,AltRight:57400,Home:57415,ArrowUp:57416,PageUp:57417,ArrowLeft:57419,ArrowRight:57421,End:57423,ArrowDown:57424,PageDown:57425,Insert:57426,Delete:57427,OSLeft:57435,OSRight:57436,ContextMenu:57437};this.bus=a;this.destroy=function(){"undefined"!==typeof window&&(window.removeEventListener("keyup",c,!1),window.removeEventListener("keydown",
235
+ d,!1),window.removeEventListener("blur",e,!1))};this.init=function(){"undefined"!==typeof window&&(this.destroy(),window.addEventListener("keyup",c,!1),window.addEventListener("keydown",d,!1),window.addEventListener("blur",e,!1))};this.init();this.simulate_press=function(w){w={keyCode:w};f(w,!0);f(w,!1)};this.simulate_char=function(w){var F=w.charCodeAt(0);F in A?this.simulate_press(A[F]):F in u?(p(42),this.simulate_press(u[F]),p(170)):console.log("ascii -> keyCode not found: ",F,w)}}function ic(a,
236
+ b){function c(u){if(!A.enabled||!A.emu_enabled)return!1;var B=b||document.body,w;if(!(w=document.pointerLockElement))a:{for(u=u.target;u.parentNode;){if(u===B){w=!0;break a}u=u.parentNode}w=!1}return w}function d(u){c(u)&&(u=u.changedTouches)&&u.length&&(u=u[u.length-1],v=u.clientX,y=u.clientY)}function e(){if(q||t||r)A.bus.send("mouse-click",[!1,!1,!1]),q=t=r=!1}function f(u){if(A.bus&&c(u)&&A.is_running){var B=0,w=0,F=u.changedTouches;F?F.length&&(F=F[F.length-1],B=F.clientX-v,w=F.clientY-y,v=F.clientX,
237
+ y=F.clientY,u.preventDefault()):"number"===typeof u.movementX?(B=u.movementX,w=u.movementY):"number"===typeof u.webkitMovementX?(B=u.webkitMovementX,w=u.webkitMovementY):"number"===typeof u.mozMovementX?(B=u.mozMovementX,w=u.mozMovementY):(B=u.clientX-v,w=u.clientY-y,v=u.clientX,y=u.clientY);A.bus.send("mouse-delta",[.15*B,-(.15*w)]);b&&A.bus.send("mouse-absolute",[u.pageX-b.offsetLeft,u.pageY-b.offsetTop,b.offsetWidth,b.offsetHeight])}}function h(u){c(u)&&p(u,!0)}function l(u){c(u)&&p(u,!1)}function p(u,
238
+ B){A.bus&&(1===u.which?q=B:2===u.which?t=B:3===u.which?r=B:C("Unknown event.which: "+u.which),A.bus.send("mouse-click",[q,t,r]),u.preventDefault())}function n(u){if(c(u)){var B=u.wheelDelta||-u.detail;0>B?B=-1:0<B&&(B=1);A.bus.send("mouse-wheel",[B,0]);u.preventDefault()}}var q=!1,r=!1,t=!1,v=0,y=0,A=this;this.enabled=!1;this.emu_enabled=!0;this.bus=a;this.bus.register("mouse-enable",function(u){this.enabled=u},this);this.is_running=!1;this.bus.register("emulator-stopped",function(){this.is_running=
239
+ !1},this);this.bus.register("emulator-started",function(){this.is_running=!0},this);this.destroy=function(){"undefined"!==typeof window&&(window.removeEventListener("touchstart",d,!1),window.removeEventListener("touchend",e,!1),window.removeEventListener("touchmove",f,!1),window.removeEventListener("mousemove",f,!1),window.removeEventListener("mousedown",h,!1),window.removeEventListener("mouseup",l,!1),window.removeEventListener("wheel",n,{passive:!1}))};this.init=function(){"undefined"!==typeof window&&
240
+ (this.destroy(),window.addEventListener("touchstart",d,!1),window.addEventListener("touchend",e,!1),window.addEventListener("touchmove",f,!1),window.addEventListener("mousemove",f,!1),window.addEventListener("mousedown",h,!1),window.addEventListener("mouseup",l,!1),window.addEventListener("wheel",n,{passive:!1}))};this.init()}function jc(){var a,b=0,c=0;this.put_char=function(d,e,f){k(0<=d&&d<c);k(0<=e&&e<b);a[d*b+e]=f};this.destroy=function(){};this.pause=function(){};this.continue=function(){};
241
+ this.set_mode=function(){};this.set_font_bitmap=function(){};this.set_font_page=function(){};this.clear_screen=function(){};this.set_size_text=function(d,e){if(d!==b||e!==c)a=new Uint8Array(d*e),b=d,c=e};this.set_size_graphical=function(){};this.set_scale=function(){};this.update_cursor_scanline=function(){};this.update_cursor=function(){};this.update_buffer=function(){};this.get_text_screen=function(){for(var d=[],e=0;e<c;e++)d.push(this.get_text_row(e));return d};this.get_text_row=function(d){d*=
242
+ b;return String.fromCharCode.apply(String,a.subarray(d,d+b))};this.set_size_text(80,25)}function kc(a,b){function c(l){h.bus&&h.enabled&&(h.send_char(l.which),l.preventDefault())}function d(l){var p=l.which;8===p?(h.send_char(127),l.preventDefault()):9===p&&(h.send_char(9),l.preventDefault())}function e(l){if(h.enabled){for(var p=l.clipboardData.getData("text/plain"),n=0;n<p.length;n++)h.send_char(p.charCodeAt(n));l.preventDefault()}}function f(l){l.target!==a&&a.blur()}var h=this;this.enabled=!0;
243
+ this.bus=b;this.text="";this.text_new_line=!1;this.last_update=0;this.bus.register("serial0-output-byte",function(l){l=String.fromCharCode(l);this.show_char(l)},this);this.destroy=function(){a.removeEventListener("keypress",c,!1);a.removeEventListener("keydown",d,!1);a.removeEventListener("paste",e,!1);window.removeEventListener("mousedown",f,!1)};this.init=function(){this.destroy();a.style.display="block";a.addEventListener("keypress",c,!1);a.addEventListener("keydown",d,!1);a.addEventListener("paste",
244
+ e,!1);window.addEventListener("mousedown",f,!1)};this.init();this.show_char=function(l){"\b"===l?(this.text=this.text.slice(0,-1),this.update()):"\r"!==l&&(this.text+=l,"\n"===l&&(this.text_new_line=!0),this.update())};this.update=function(){var l=Date.now(),p=l-this.last_update;16>p?void 0===this.update_timer&&(this.update_timer=setTimeout(()=>{this.update_timer=void 0;var n=Date.now();k(15<=n-this.last_update);this.last_update=n;this.render()},16-p)):(void 0!==this.update_timer&&(clearTimeout(this.update_timer),
245
+ this.update_timer=void 0),this.last_update=l,this.render())};this.render=function(){a.value=this.text;this.text_new_line&&(this.text_new_line=!1,a.scrollTop=1E9)};this.send_char=function(l){h.bus&&h.bus.send("serial0-input",l)}}function lc(a,b){this.element=a;if(window.Terminal){var c=this.term=new window.Terminal({logLevel:"off"});c.write("This is the serial console. Whatever you type or paste here will be sent to COM1");var d=c.onData(function(e){for(let f=0;f<e.length;f++)b.send("serial0-input",
246
+ e.charCodeAt(f))});b.register("serial0-output-byte",function(e){c.write(Uint8Array.of(e))},this);this.destroy=function(){d.dispose();c.dispose()}}}lc.prototype.show=function(){this.term&&this.term.open(this.element)};function mc(a,b){b=b.id||0;this.bus=a;this.bus_send_msgid=`net${b}-send`;this.bus_recv_msgid=`net${b}-receive`;this.channel=new BroadcastChannel(`v86-inbrowser-${b}`);this.is_open=!0;this.nic_to_hub_fn=c=>{this.channel.postMessage(c)};this.bus.register(this.bus_send_msgid,this.nic_to_hub_fn,
247
+ this);this.hub_to_nic_fn=c=>{this.bus.send(this.bus_recv_msgid,c.data)};this.channel.addEventListener("message",this.hub_to_nic_fn)}mc.prototype.destroy=function(){this.is_open&&(this.bus.unregister(this.bus_send_msgid,this.nic_to_hub_fn),this.channel.removeEventListener("message",this.hub_to_nic_fn),this.channel.close(),this.is_open=!1)};function nc(){this.filedata=new Map}nc.prototype.read=async function(a,b,c){k(a,"MemoryFileStorage read: sha256sum should be a non-empty string");return(a=this.filedata.get(a))?
248
+ a.subarray(b,b+c):null};nc.prototype.cache=async function(a,b){k(a,"MemoryFileStorage cache: sha256sum should be a non-empty string");this.filedata.set(a,b)};nc.prototype.uncache=function(a){this.filedata.delete(a)};function oc(a,b){k(b,"ServerMemoryFileStorage: baseurl should not be empty");b.endsWith("/")||(b+="/");this.storage=a;this.baseurl=b}oc.prototype.load_from_server=function(a){return new Promise(b=>{sa(this.baseurl+a,{done:async c=>{c=new Uint8Array(c);await this.cache(a,c);b(c)}})})};
249
+ oc.prototype.read=async function(a,b,c){const d=await this.storage.read(a,b,c);return d?d:(await this.load_from_server(a)).subarray(b,b+c)};oc.prototype.cache=async function(a,b){return await this.storage.cache(a,b)};oc.prototype.uncache=function(a){this.storage.uncache(a)};const pc=new TextDecoder,qc=new TextEncoder;function K(a,b,c,d){for(var e,f=0,h=0;h<a.length;h++)switch(e=b[h],a[h]){case "w":c[d++]=e&255;c[d++]=e>>8&255;c[d++]=e>>16&255;c[d++]=e>>24&255;f+=4;break;case "d":c[d++]=e&255;c[d++]=
250
+ e>>8&255;c[d++]=e>>16&255;c[d++]=e>>24&255;c[d++]=0;c[d++]=0;c[d++]=0;c[d++]=0;f+=8;break;case "h":c[d++]=e&255;c[d++]=e>>8;f+=2;break;case "b":c[d++]=e;f+=1;break;case "s":var l=d,p=0;c[d++]=0;c[d++]=0;f+=2;e=qc.encode(e);f+=e.byteLength;p+=e.byteLength;c.set(e,d);d+=e.byteLength;c[l+0]=p&255;c[l+1]=p>>8&255;break;case "Q":K(["b","w","d"],[e.type,e.version,e.path],c,d);d+=13;f+=13;break;default:C("Marshall: Unknown type="+a[h])}return f}function M(a,b,c){let d=c.offset;for(var e=[],f=0;f<a.length;f++)switch(a[f]){case "w":var h=
251
+ b[d++];h+=b[d++]<<8;h+=b[d++]<<16;h+=b[d++]<<24>>>0;e.push(h);break;case "d":h=b[d++];h+=b[d++]<<8;h+=b[d++]<<16;h+=b[d++]<<24>>>0;d+=4;e.push(h);break;case "h":h=b[d++];e.push(h+(b[d++]<<8));break;case "b":e.push(b[d++]);break;case "s":h=b[d++];h+=b[d++]<<8;var l=b.slice(d,d+h);d+=h;e.push(pc.decode(l));break;case "Q":c.offset=d;h=M(["b","w","d"],b,c);d=c.offset;e.push({type:h[0],version:h[1],path:h[2]});break;default:C("Error in Unmarshall: Unknown type="+a[f])}c.offset=d;return e}const rc=new TextEncoder;
252
+ function N(a,b){this.inodes=[];this.events=[];this.storage=a;this.qidcounter=b||{last_qidnumber:0};this.inodedata={};this.total_size=274877906944;this.used_size=0;this.mounts=[];this.CreateDirectory("",-1)}N.prototype.get_state=function(){let a=[];a[0]=this.inodes;a[1]=this.qidcounter.last_qidnumber;a[2]=[];for(const [b,c]of Object.entries(this.inodedata))0===(this.inodes[b].mode&16384)&&a[2].push([b,c]);a[3]=this.total_size;a[4]=this.used_size;return a=a.concat(this.mounts)};N.prototype.set_state=
253
+ function(a){this.inodes=a[0].map(b=>{const c=new sc(0);c.set_state(b);return c});this.qidcounter.last_qidnumber=a[1];this.inodedata={};for(let [b,c]of a[2])c.buffer.byteLength!==c.byteLength&&(c=c.slice()),this.inodedata[b]=c;this.total_size=a[3];this.used_size=a[4];this.mounts=a.slice(5)};N.prototype.AddEvent=function(a,b){var c=this.inodes[a];0===c.status||2===c.status?b():this.is_forwarder(c)?this.follow_fs(c).AddEvent(c.foreign_id,b):this.events.push({id:a,OnEvent:b})};N.prototype.HandleEvent=
254
+ function(a){var b=this.inodes[a];this.is_forwarder(b)&&this.follow_fs(b).HandleEvent(b.foreign_id);b=[];for(var c=0;c<this.events.length;c++)this.events[c].id===a?this.events[c].OnEvent():b.push(this.events[c]);this.events=b};N.prototype.load_from_json=function(a){k(a,"Invalid fs passed to load_from_json");if(3!==a.version)throw"The filesystem JSON format has changed. Please update your fs2json (https://github.com/copy/fs2json) and recreate the filesystem JSON.";var b=a.fsroot;this.used_size=a.size;
255
+ for(a=0;a<b.length;a++)this.LoadRecursive(b[a],0)};N.prototype.LoadRecursive=function(a,b){var c=this.CreateInode();const d=a[0];c.size=a[1];c.mtime=a[2];c.ctime=c.mtime;c.atime=c.mtime;c.mode=a[3];c.uid=a[4];c.gid=a[5];var e=c.mode&61440;16384===e?(this.PushInode(c,b,d),this.LoadDir(this.inodes.length-1,a[6])):32768===e?(c.status=2,c.sha256sum=a[6],k(c.sha256sum),this.PushInode(c,b,d)):40960===e?(c.symlink=a[6],this.PushInode(c,b,d)):49152!==e&&C("Unexpected ifmt: "+m(e)+" ("+d+")",4194304)};N.prototype.LoadDir=
256
+ function(a,b){for(var c=0;c<b.length;c++)this.LoadRecursive(b[c],a)};N.prototype.should_be_linked=function(a){return!this.is_forwarder(a)||0===a.foreign_id};N.prototype.link_under_dir=function(a,b,c){const d=this.inodes[b],e=this.inodes[a];k(!this.is_forwarder(e),"Filesystem: Shouldn't link under fowarder parents");k(this.IsDirectory(a),"Filesystem: Can't link under non-directories");k(this.should_be_linked(d),"Filesystem: Can't link across filesystems apart from their root");k(0<=d.nlinks,"Filesystem: Found negative nlinks value of "+
257
+ d.nlinks);k(!e.direntries.has(c),"Filesystem: Name '"+c+"' is already taken");e.direntries.set(c,b);d.nlinks++;this.IsDirectory(b)&&(k(!d.direntries.has(".."),"Filesystem: Cannot link a directory twice"),d.direntries.has(".")||d.nlinks++,d.direntries.set(".",b),d.direntries.set("..",a),e.nlinks++)};N.prototype.unlink_from_dir=function(a,b){const c=this.Search(a,b),d=this.inodes[c],e=this.inodes[a];k(!this.is_forwarder(e),"Filesystem: Can't unlink from forwarders");k(this.IsDirectory(a),"Filesystem: Can't unlink from non-directories");
258
+ e.direntries.delete(b)?(d.nlinks--,this.IsDirectory(c)&&(k(d.direntries.get("..")===a,"Filesystem: Found directory with bad parent id"),d.direntries.delete(".."),e.nlinks--),k(0<=d.nlinks,"Filesystem: Found negative nlinks value of "+d.nlinks)):k(!1,"Filesystem: Can't unlink non-existent file: "+b)};N.prototype.PushInode=function(a,b,c){-1!==b?(this.inodes.push(a),a.fid=this.inodes.length-1,this.link_under_dir(b,a.fid,c)):0===this.inodes.length?(this.inodes.push(a),a.direntries.set(".",0),a.direntries.set("..",
259
+ 0),a.nlinks=2):k(!1,"Error in Filesystem: Pushed inode with name = "+c+" has no parent")};function sc(a){this.direntries=new Map;this.minor=this.major=this.mtime=this.atime=this.ctime=this.fid=this.gid=this.uid=this.size=this.status=0;this.symlink="";this.mode=493;this.qid={type:0,version:0,path:a};this.caps=void 0;this.nlinks=0;this.sha256sum="";this.locks=[];this.foreign_id=this.mount_id=-1}sc.prototype.get_state=function(){const a=[];a[0]=this.mode;a[1]=16384===(this.mode&61440)?[...this.direntries]:
260
+ 32768===(this.mode&61440)?this.sha256sum:40960===(this.mode&61440)?this.symlink:49152===(this.mode&61440)?[this.minor,this.major]:null;a[2]=this.locks;a[3]=this.status;a[4]=this.size;a[5]=this.uid;a[6]=this.gid;a[7]=this.fid;a[8]=this.ctime;a[9]=this.atime;a[10]=this.mtime;a[11]=this.qid.version;a[12]=this.qid.path;a[13]=this.nlinks;return a};sc.prototype.set_state=function(a){this.mode=a[0];if(16384===(this.mode&61440)){this.direntries=new Map;for(const [b,c]of a[1])this.direntries.set(b,c)}else 32768===
261
+ (this.mode&61440)?this.sha256sum=a[1]:40960===(this.mode&61440)?this.symlink=a[1]:49152===(this.mode&61440)&&([this.minor,this.major]=a[1]);this.locks=[];for(const b of a[2]){const c=new tc;c.set_state(b);this.locks.push(c)}this.status=a[3];this.size=a[4];this.uid=a[5];this.gid=a[6];this.fid=a[7];this.ctime=a[8];this.atime=a[9];this.mtime=a[10];this.qid.type=(this.mode&61440)>>8;this.qid.version=a[11];this.qid.path=a[12];this.nlinks=a[13]};N.prototype.divert=function(a,b){const c=this.Search(a,b),
262
+ d=this.inodes[c],e=new sc(-1);k(d,"Filesystem divert: name ("+b+") not found");k(this.IsDirectory(c)||1>=d.nlinks,"Filesystem: can't divert hardlinked file '"+b+"' with nlinks="+d.nlinks);Object.assign(e,d);const f=this.inodes.length;this.inodes.push(e);e.fid=f;this.is_forwarder(d)&&this.mounts[d.mount_id].backtrack.set(d.foreign_id,f);this.should_be_linked(d)&&(this.unlink_from_dir(a,b),this.link_under_dir(a,f,b));if(this.IsDirectory(c)&&!this.is_forwarder(d))for(const [h,l]of e.direntries)"."!==
263
+ h&&".."!==h&&this.IsDirectory(l)&&this.inodes[l].direntries.set("..",f);this.inodedata[f]=this.inodedata[c];delete this.inodedata[c];d.direntries=new Map;d.nlinks=0;return f};N.prototype.copy_inode=function(a,b){Object.assign(b,a,{fid:b.fid,direntries:b.direntries,nlinks:b.nlinks})};N.prototype.CreateInode=function(){const a=Math.round(Date.now()/1E3),b=new sc(++this.qidcounter.last_qidnumber);b.atime=b.ctime=b.mtime=a;return b};N.prototype.CreateDirectory=function(a,b){var c=this.inodes[b];if(0<=
264
+ b&&this.is_forwarder(c))return b=c.foreign_id,a=this.follow_fs(c).CreateDirectory(a,b),this.create_forwarder(c.mount_id,a);c=this.CreateInode();c.mode=16895;0<=b&&(c.uid=this.inodes[b].uid,c.gid=this.inodes[b].gid,c.mode=this.inodes[b].mode&511|16384);c.qid.type=64;this.PushInode(c,b,a);this.NotifyListeners(this.inodes.length-1,"newdir");return this.inodes.length-1};N.prototype.CreateFile=function(a,b){var c=this.inodes[b];if(this.is_forwarder(c))return b=c.foreign_id,a=this.follow_fs(c).CreateFile(a,
265
+ b),this.create_forwarder(c.mount_id,a);c=this.CreateInode();c.uid=this.inodes[b].uid;c.gid=this.inodes[b].gid;c.qid.type=128;c.mode=this.inodes[b].mode&438|32768;this.PushInode(c,b,a);this.NotifyListeners(this.inodes.length-1,"newfile");return this.inodes.length-1};N.prototype.CreateNode=function(a,b,c,d){var e=this.inodes[b];if(this.is_forwarder(e))return b=e.foreign_id,a=this.follow_fs(e).CreateNode(a,b,c,d),this.create_forwarder(e.mount_id,a);e=this.CreateInode();e.major=c;e.minor=d;e.uid=this.inodes[b].uid;
266
+ e.gid=this.inodes[b].gid;e.qid.type=192;e.mode=this.inodes[b].mode&438;this.PushInode(e,b,a);return this.inodes.length-1};N.prototype.CreateSymlink=function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,a=this.follow_fs(d).CreateSymlink(a,b,c),this.create_forwarder(d.mount_id,a);d=this.CreateInode();d.uid=this.inodes[b].uid;d.gid=this.inodes[b].gid;d.qid.type=160;d.symlink=c;d.mode=40960;this.PushInode(d,b,a);return this.inodes.length-1};N.prototype.CreateTextFile=async function(a,
267
+ b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,c=await this.follow_fs(d).CreateTextFile(a,b,c),this.create_forwarder(d.mount_id,c);d=this.CreateFile(a,b);b=this.inodes[d];a=new Uint8Array(c.length);b.size=c.length;for(b=0;b<c.length;b++)a[b]=c.charCodeAt(b);await this.set_data(d,a);return d};N.prototype.CreateBinaryFile=async function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,c=await this.follow_fs(d).CreateBinaryFile(a,b,c),this.create_forwarder(d.mount_id,
268
+ c);d=this.CreateFile(a,b);a=this.inodes[d];b=new Uint8Array(c.length);b.set(c);await this.set_data(d,b);a.size=c.length;return d};N.prototype.OpenInode=function(a,b){var c=this.inodes[a];if(this.is_forwarder(c))return this.follow_fs(c).OpenInode(c.foreign_id,b);16384===(c.mode&61440)&&this.FillDirectory(a);return!0};N.prototype.CloseInode=async function(a){var b=this.inodes[a];if(this.is_forwarder(b))return await this.follow_fs(b).CloseInode(b.foreign_id);2===b.status&&this.storage.uncache(b.sha256sum);
269
+ 4===b.status&&(b.status=-1,await this.DeleteData(a))};N.prototype.Rename=async function(a,b,c,d){if(a===c&&b===d)return 0;var e=this.Search(a,b);if(-1===e)return-2;var f=this.GetFullPath(a)+"/"+b;if(-1!==this.Search(c,d)){var h=this.Unlink(c,d);if(0>h)return h}var l=this.inodes[e],p=this.inodes[a];h=this.inodes[c];if(this.is_forwarder(p)||this.is_forwarder(h))if(this.is_forwarder(p)&&p.mount_id===h.mount_id){if(a=await this.follow_fs(p).Rename(p.foreign_id,b,h.foreign_id,d),0>a)return a}else{if(this.is_a_root(e))return C("XXX: Attempted to move mountpoint ("+
269
270
  b+") - skipped",4194304),-1;if(!this.IsDirectory(e)&&1<this.GetInode(e).nlinks)return C("XXX: Attempted to move hardlinked file ("+b+") across filesystems - skipped",4194304),-1;p=this.divert(a,b);const n=this.GetInode(e),q=await this.Read(p,0,n.size);this.is_forwarder(h)?(c=this.follow_fs(h),d=this.IsDirectory(p)?c.CreateDirectory(d,h.foreign_id):c.CreateFile(d,h.foreign_id),c=c.GetInode(d),this.copy_inode(n,c),this.set_forwarder(e,h.mount_id,d)):(this.delete_forwarder(l),this.copy_inode(n,l),this.link_under_dir(c,
270
271
  e,d));await this.ChangeSize(e,n.size);q&&q.length&&await this.Write(e,0,q.length,q);if(this.IsDirectory(e))for(const r of this.GetChildren(p))if(h=await this.Rename(p,r,e,r),0>h)return h;await this.DeleteData(p);a=this.Unlink(a,b);if(0>a)return a}else this.unlink_from_dir(a,b),this.link_under_dir(c,e,d),l.qid.version++;this.NotifyListeners(e,"rename",{oldpath:f});return 0};N.prototype.Write=async function(a,b,c,d){this.NotifyListeners(a,"write");var e=this.inodes[a];if(this.is_forwarder(e))a=e.foreign_id,
271
272
  await this.follow_fs(e).Write(a,b,c,d);else{var f=await this.get_buffer(a);!f||f.length<b+c?(await this.ChangeSize(a,Math.floor(3*(b+c)/2)),e.size=b+c,f=await this.get_buffer(a)):e.size<b+c&&(e.size=b+c);d&&f.set(d.subarray(0,c),b);await this.set_data(a,f)}};N.prototype.Read=async function(a,b,c){const d=this.inodes[a];return this.is_forwarder(d)?(a=d.foreign_id,await this.follow_fs(d).Read(a,b,c)):await this.get_data(a,b,c)};N.prototype.Search=function(a,b){a=this.inodes[a];if(this.is_forwarder(a)){const c=
@@ -298,18 +299,18 @@ f&&(d.locks.splice(c,1),c--)}if(2!==b.type){c=b;a=!1;for(e=0;e<d.locks.length&&!
298
299
  l){return c.run_hardware_timers(h,l)},cpu_event_halt:()=>{this.emulator_bus.send("cpu-event-halt")},abort:function(){k(!1)},microtick:I.microtick,get_rand_int:function(){return da()},apic_acknowledge_irq:function(){return c.devices.apic.acknowledge_irq()},stop_idling:function(){return c.stop_idling()},io_port_read8:function(h){return c.io.port_read8(h)},io_port_read16:function(h){return c.io.port_read16(h)},io_port_read32:function(h){return c.io.port_read32(h)},io_port_write8:function(h,l){c.io.port_write8(h,
299
300
  l)},io_port_write16:function(h,l){c.io.port_write16(h,l)},io_port_write32:function(h,l){c.io.port_write32(h,l)},mmap_read8:function(h){return c.mmap_read8(h)},mmap_read16:function(h){return c.mmap_read16(h)},mmap_read32:function(h){return c.mmap_read32(h)},mmap_write8:function(h,l){c.mmap_write8(h,l)},mmap_write16:function(h,l){c.mmap_write16(h,l)},mmap_write32:function(h,l){c.mmap_write32(h,l)},mmap_write64:function(h,l,p){c.mmap_write64(h,l,p)},mmap_write128:function(h,l,p,n,q){c.mmap_write128(h,
300
301
  l,p,n,q)},log_from_wasm:function(h,l){h=String.fromCharCode(...(new Uint8Array(d.buffer,h>>>0,l>>>0)));C(h,2)},console_log_from_wasm:function(h,l){h=String.fromCharCode(...(new Uint8Array(d.buffer,h>>>0,l>>>0)));console.error(h)},dbg_trace_from_wasm:function(){C(Error().stack,2)},codegen_finalize:(h,l,p,n,q)=>{c.codegen_finalize(h,l,p,n,q)},jit_clear_func:h=>c.jit_clear_func(h),jit_clear_all_funcs:()=>c.jit_clear_all_funcs(),__indirect_function_table:e};let f=a.wasm_fn;f||(f=h=>new Promise(l=>{let p=
301
- "v86-debug.wasm",n="v86-fallback.wasm";a.wasm_path?(p=a.wasm_path,n=p.replace("v86.wasm","v86-fallback.wasm")):"undefined"===typeof window&&"string"===typeof __dirname?(p=__dirname+"/"+p,n=__dirname+"/"+n):(p="build/"+p,n="build/"+n);sa(p,{done:async q=>{try{const {instance:r}=await WebAssembly.instantiate(q,h);this.wasm_source=q;l(r.exports)}catch(r){sa(n,{done:async t=>{const {instance:u}=await WebAssembly.instantiate(t,h);this.wasm_source=t;l(u.exports)}})}},progress:q=>{this.emulator_bus.send("download-progress",
302
- {file_index:0,file_count:1,file_name:p,lengthComputable:q.lengthComputable,total:q.total,loaded:q.loaded})}})}));f({env:b}).then(h=>{d=h.memory;h.rust_init();h=this.v86=new I(this.emulator_bus,{exports:h,wasm_table:e});c=h.cpu;this.continue_init(h,a)});this.zstd_worker=null;this.zstd_worker_request_id=0}O.prototype.continue_init=async function(a,b){function c(t,u){switch(t){case "hda":e.hda=this.disk_images.hda=u;break;case "hdb":e.hdb=this.disk_images.hdb=u;break;case "cdrom":e.cdrom=this.disk_images.cdrom=
303
- u;break;case "fda":e.fda=this.disk_images.fda=u;break;case "fdb":e.fdb=this.disk_images.fdb=u;break;case "multiboot":e.multiboot=this.disk_images.multiboot=u.buffer;break;case "bzimage":e.bzimage=this.disk_images.bzimage=u.buffer;break;case "initrd":e.initrd=this.disk_images.initrd=u.buffer;break;case "bios":e.bios=u.buffer;break;case "vga_bios":e.vga_bios=u.buffer;break;case "initial_state":e.initial_state=u.buffer;break;case "fs9p_json":e.fs9p_json=u;break;default:k(!1,t)}}async function d(){if(e.fs9p&&
304
- e.fs9p_json)if(e.initial_state)C("Filesystem basefs ignored: Overridden by state image");else{if(e.fs9p.load_from_json(e.fs9p_json),b.bzimage_initrd_from_filesystem){const {bzimage_path:t,initrd_path:u}=this.get_bzimage_initrd_from_filesystem(e.fs9p);C("Found bzimage: "+t+" and initrd: "+u);const [y,A]=await Promise.all([e.fs9p.read_file(u),e.fs9p.read_file(t)]);c.call(this,"initrd",new ya(y.buffer));c.call(this,"bzimage",new ya(A.buffer))}}else k(!b.bzimage_initrd_from_filesystem||e.initial_state,
302
+ "v86-debug.wasm",n="v86-fallback.wasm";a.wasm_path?(p=a.wasm_path,n=p.replace("v86.wasm","v86-fallback.wasm")):"undefined"===typeof window&&"string"===typeof __dirname?(p=__dirname+"/"+p,n=__dirname+"/"+n):(p="build/"+p,n="build/"+n);sa(p,{done:async q=>{try{const {instance:r}=await WebAssembly.instantiate(q,h);this.wasm_source=q;l(r.exports)}catch(r){sa(n,{done:async t=>{const {instance:v}=await WebAssembly.instantiate(t,h);this.wasm_source=t;l(v.exports)}})}},progress:q=>{this.emulator_bus.send("download-progress",
303
+ {file_index:0,file_count:1,file_name:p,lengthComputable:q.lengthComputable,total:q.total,loaded:q.loaded})}})}));f({env:b}).then(h=>{d=h.memory;h.rust_init();h=this.v86=new I(this.emulator_bus,{exports:h,wasm_table:e});c=h.cpu;this.continue_init(h,a)});this.zstd_worker=null;this.zstd_worker_request_id=0}O.prototype.continue_init=async function(a,b){function c(t,v){switch(t){case "hda":e.hda=this.disk_images.hda=v;break;case "hdb":e.hdb=this.disk_images.hdb=v;break;case "cdrom":e.cdrom=this.disk_images.cdrom=
304
+ v;break;case "fda":e.fda=this.disk_images.fda=v;break;case "fdb":e.fdb=this.disk_images.fdb=v;break;case "multiboot":e.multiboot=this.disk_images.multiboot=v.buffer;break;case "bzimage":e.bzimage=this.disk_images.bzimage=v.buffer;break;case "initrd":e.initrd=this.disk_images.initrd=v.buffer;break;case "bios":e.bios=v.buffer;break;case "vga_bios":e.vga_bios=v.buffer;break;case "initial_state":e.initial_state=v.buffer;break;case "fs9p_json":e.fs9p_json=v;break;default:k(!1,t)}}async function d(){if(e.fs9p&&
305
+ e.fs9p_json)if(e.initial_state)C("Filesystem basefs ignored: Overridden by state image");else{if(e.fs9p.load_from_json(e.fs9p_json),b.bzimage_initrd_from_filesystem){const {bzimage_path:t,initrd_path:v}=this.get_bzimage_initrd_from_filesystem(e.fs9p);C("Found bzimage: "+t+" and initrd: "+v);const [y,A]=await Promise.all([e.fs9p.read_file(v),e.fs9p.read_file(t)]);c.call(this,"initrd",new ya(y.buffer));c.call(this,"bzimage",new ya(A.buffer))}}else k(!b.bzimage_initrd_from_filesystem||e.initial_state,
305
306
  "bzimage_initrd_from_filesystem: Requires a filesystem");this.serial_adapter&&this.serial_adapter.show&&this.serial_adapter.show();this.v86.init(e);e.initial_state&&(a.restore_state(e.initial_state),e.initial_state=void 0);b.autostart&&this.v86.run();this.emulator_bus.send("emulator-loaded")}this.bus.register("emulator-stopped",function(){this.cpu_is_running=!1;this.screen_adapter.pause()},this);this.bus.register("emulator-started",function(){this.cpu_is_running=!0;this.screen_adapter.continue()},
306
307
  this);var e={};this.disk_images={fda:void 0,fdb:void 0,hda:void 0,hdb:void 0,cdrom:void 0};var f=b.boot_order?b.boot_order:b.fda?801:b.hda?786:291;e.acpi=b.acpi;e.disable_jit=b.disable_jit;e.load_devices=!0;e.memory_size=b.memory_size||67108864;e.vga_memory_size=b.vga_memory_size||8388608;e.boot_order=f;e.fastboot=b.fastboot||!1;e.fda=void 0;e.fdb=void 0;e.uart1=b.uart1;e.uart2=b.uart2;e.uart3=b.uart3;e.cmdline=b.cmdline;e.preserve_mac_from_state_image=b.preserve_mac_from_state_image;e.mac_address_translation=
307
308
  b.mac_address_translation;e.cpuid_level=b.cpuid_level;e.virtio_balloon=b.virtio_balloon;e.virtio_console=b.virtio_console;e.virtio_net=b.virtio_net;e.screen_options=b.screen_options;if(f=b.network_relay_url||b.net_device&&b.net_device.relay_url)"fetch"===f?this.network_adapter=new Yb(this.bus,b.net_device):"inbrowser"===f?this.network_adapter=new mc(this.bus,b.net_device):f.startsWith("wisp://")||f.startsWith("wisps://")?this.network_adapter=new fc(f,this.bus,b.net_device):this.network_adapter=new rb(f,
308
309
  this.bus);e.net_device=b.net_device||{type:"ne2k"};f=b.screen||{};b.screen_container&&(f.container=b.screen_container);b.disable_keyboard||(this.keyboard_adapter=new hc(this.bus));b.disable_mouse||(this.mouse_adapter=new ic(this.bus,f.container));this.screen_adapter=f.container?new wa(f,()=>this.v86.cpu.devices.vga&&this.v86.cpu.devices.vga.screen_fill_buffer()):new jc;e.screen=this.screen_adapter;e.screen_options=f;b.serial_container&&(this.serial_adapter=new kc(b.serial_container,this.bus));b.serial_container_xtermjs&&
309
- (this.serial_adapter=new lc(b.serial_container_xtermjs,this.bus));b.disable_speaker||(this.speaker_adapter=new kb(this.bus));var h=[];f=(t,u)=>{if(u)if(u.get&&u.set&&u.load)h.push({name:t,loadable:u});else{if("bios"===t||"vga_bios"===t||"initial_state"===t||"multiboot"===t||"bzimage"===t||"initrd"===t)u.async=!1;if("fda"===t||"fdb"===t)u.async=!1;u.url&&!u.async?h.push({name:t,url:u.url,size:u.size}):h.push({name:t,loadable:Da(u,this.zstd_decompress_worker.bind(this))})}};b.state&&console.warn("Warning: Unknown option 'state'. Did you mean 'initial_state'?");
310
+ (this.serial_adapter=new lc(b.serial_container_xtermjs,this.bus));b.disable_speaker||(this.speaker_adapter=new kb(this.bus));var h=[];f=(t,v)=>{if(v)if(v.get&&v.set&&v.load)h.push({name:t,loadable:v});else{if("bios"===t||"vga_bios"===t||"initial_state"===t||"multiboot"===t||"bzimage"===t||"initrd"===t)v.async=!1;if("fda"===t||"fdb"===t)v.async=!1;v.url&&!v.async?h.push({name:t,url:v.url,size:v.size}):h.push({name:t,loadable:Da(v,this.zstd_decompress_worker.bind(this))})}};b.state&&console.warn("Warning: Unknown option 'state'. Did you mean 'initial_state'?");
310
311
  f("bios",b.bios);f("vga_bios",b.vga_bios);f("cdrom",b.cdrom);f("hda",b.hda);f("hdb",b.hdb);f("fda",b.fda);f("fdb",b.fdb);f("initial_state",b.initial_state);f("multiboot",b.multiboot);f("bzimage",b.bzimage);f("initrd",b.initrd);if(b.filesystem){f=b.filesystem.basefs;var l=b.filesystem.baseurl;let t=new nc;l&&(t=new oc(t,l));e.fs9p=this.fs9p=new N(t);if(f){k(l,"Filesystem: baseurl must be specified");if("object"===typeof f){var p=f.size;f=f.url}k("string"===typeof f);h.push({name:"fs9p_json",url:f,
311
- size:p,as_json:!0})}}var n=this,q=h.length,r=function(t){if(t===q)setTimeout(d.bind(this),0);else{var u=h[t];u.loadable?(u.loadable.onload=function(){c.call(this,u.name,u.loadable);r(t+1)}.bind(this),u.loadable.load()):sa(u.url,{done:function(y){u.url.endsWith(".zst")&&"initial_state"!==u.name&&(k(u.size,"A size must be provided for compressed images"),y=this.zstd_decompress(u.size,new Uint8Array(y)));c.call(this,u.name,u.as_json?y:new ya(y));r(t+1)}.bind(this),progress:function(y){200===y.target.status?
312
- n.emulator_bus.send("download-progress",{file_index:t,file_count:q,file_name:u.url,lengthComputable:y.lengthComputable,total:y.total||u.size,loaded:y.loaded}):n.emulator_bus.send("download-error",{file_index:t,file_count:q,file_name:u.url,request:y.target})},as_json:u.as_json})}}.bind(this);r(0)};O.prototype.zstd_decompress=function(a,b){const c=this.v86.cpu;k(!this.zstd_context);this.zstd_context=c.zstd_create_ctx(b.length);(new Uint8Array(c.wasm_memory.buffer)).set(b,c.zstd_get_src_ptr(this.zstd_context));
312
+ size:p,as_json:!0})}}var n=this,q=h.length,r=function(t){if(t===q)setTimeout(d.bind(this),0);else{var v=h[t];v.loadable?(v.loadable.onload=function(){c.call(this,v.name,v.loadable);r(t+1)}.bind(this),v.loadable.load()):sa(v.url,{done:function(y){v.url.endsWith(".zst")&&"initial_state"!==v.name&&(k(v.size,"A size must be provided for compressed images"),y=this.zstd_decompress(v.size,new Uint8Array(y)));c.call(this,v.name,v.as_json?y:new ya(y));r(t+1)}.bind(this),progress:function(y){200===y.target.status?
313
+ n.emulator_bus.send("download-progress",{file_index:t,file_count:q,file_name:v.url,lengthComputable:y.lengthComputable,total:y.total||v.size,loaded:y.loaded}):n.emulator_bus.send("download-error",{file_index:t,file_count:q,file_name:v.url,request:y.target})},as_json:v.as_json})}}.bind(this);r(0)};O.prototype.zstd_decompress=function(a,b){const c=this.v86.cpu;k(!this.zstd_context);this.zstd_context=c.zstd_create_ctx(b.length);(new Uint8Array(c.wasm_memory.buffer)).set(b,c.zstd_get_src_ptr(this.zstd_context));
313
314
  b=c.zstd_read(this.zstd_context,a);const d=c.wasm_memory.buffer.slice(b,b+a);c.zstd_read_free(b,a);c.zstd_free_ctx(this.zstd_context);this.zstd_context=null;return d};O.prototype.zstd_decompress_worker=async function(a,b){if(!this.zstd_worker){const c=URL.createObjectURL(new Blob(["("+function(){let d;globalThis.onmessage=function(e){if(d){var {src:f,decompressed_size:h,id:l}=e.data;e=d.exports;var p=e.zstd_create_ctx(f.length);(new Uint8Array(e.memory.buffer)).set(f,e.zstd_get_src_ptr(p));var n=
314
315
  e.zstd_read(p,h),q=e.memory.buffer.slice(n,n+h);e.zstd_read_free(n,h);e.zstd_free_ctx(p);postMessage({result:q,id:l},[q])}else p=Object.fromEntries("cpu_exception_hook run_hardware_timers cpu_event_halt microtick get_rand_int apic_acknowledge_irq stop_idling io_port_read8 io_port_read16 io_port_read32 io_port_write8 io_port_write16 io_port_write32 mmap_read8 mmap_read16 mmap_read32 mmap_write8 mmap_write16 mmap_write32 mmap_write64 mmap_write128 codegen_finalize jit_clear_func jit_clear_all_funcs".split(" ").map(r=>
315
316
  [r,()=>console.error("zstd worker unexpectedly called "+r)])),p.__indirect_function_table=new WebAssembly.Table({element:"anyfunc",initial:1024}),p.abort=()=>{throw Error("zstd worker aborted");},p.log_from_wasm=p.console_log_from_wasm=(r,t)=>{console.log(String.fromCharCode(...(new Uint8Array(d.exports.memory.buffer,r,t))))},p.dbg_trace_from_wasm=()=>console.trace(),d=new WebAssembly.Instance(new WebAssembly.Module(e.data),{env:p})}}.toString()+")()"],{type:"text/javascript"}));this.zstd_worker=
@@ -598,8 +599,8 @@ f.byteLength/4;this.actual+=0===c?e:-e}this.virtio.queues[c].flush_replies()},c=
598
599
  f.get_next_blob(e);[e]=M(["w"],e,{offset:0});0===e&&(this.free_cb&&this.free_cb(this.zeroed),1<this.fp_cmd&&(this.fp_cmd=1),this.virtio.notify_config_changes())}if(0<f.length_writable)for(new Uint8Array(0),e=0;e<f.write_buffers.length;++e){let h=f.write_buffers[e];this.zeroed+=h.len;this.virtio.cpu.zero_memory(h.addr_low,h.len)}this.virtio.queues[c].push_reply(f)}this.virtio.queues[c].flush_replies()}]},isr_status:{initial_port:55040},device_specific:{initial_port:54784,struct:[{bytes:4,name:"num_pages",
599
600
  read:()=>this.num_pages,write:()=>{}},{bytes:4,name:"actual",read:()=>this.actual,write:()=>{}},{bytes:4,name:"free_page_hint_cmd_id",read:()=>this.fp_cmd,write:()=>{}}]}})}Yc.prototype.Inflate=function(a){this.num_pages+=a;this.virtio.notify_config_changes()};Yc.prototype.Deflate=function(a){this.num_pages-=a;this.virtio.notify_config_changes()};Yc.prototype.Cleanup=function(a){this.fp_cmd=2;this.free_cb=a;this.zeroed=0;this.virtio.notify_config_changes()};Yc.prototype.get_state=function(){const a=
600
601
  [];a[0]=this.virtio;a[1]=this.num_pages;a[2]=this.actual;return a};Yc.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.num_pages=a[1];this.actual=a[2]};Yc.prototype.GetStats=function(a){this.stats_cb=a;for(a=this.virtio.queues[2];a.has_request();){const b=a.pop_request();this.virtio.queues[2].push_reply(b)}this.virtio.queues[2].flush_replies()};Yc.prototype.Reset=function(){};function Zc(a,b,c,d){C("Trying to load kernel of size "+b.byteLength);var e=new Uint8Array(b);const f=new Uint16Array(b);
601
- var h=new Uint32Array(b),l=e[497]||4,p=f[255];if(43605!==p)C("Bad checksum1: "+m(p));else if(p=f[257]|f[258]<<16,1400005704!==p)C("Bad checksum2: "+m(p));else{p=f[259];k(514<=p);var n=e[529];k(n&1);var q=f[283],r=h[139],t=h[140],u=e[564],y=e[565],A=518<=p?h[142]:255,v=h[146],B=h[147],w=h[150],F=h[151],J=h[152];C("kernel boot protocol version: "+m(p));C("flags="+m(n)+" xflags="+m(q));C("code32_start="+m(h[133]));C("initrd_addr_max="+m(r));C("kernel_alignment="+m(t));C("relocatable="+u);C("min_alignment="+
602
- m(y));C("cmdline max="+m(A));C("payload offset="+m(v)+" size="+m(B));C("pref_address="+m(F)+":"+m(w));C("init_size="+m(J));e[528]=255;e[529]=n&-97|128;f[274]=56832;f[253]=65535;C("heap_end_ptr="+m(56832));d+="\x00";k(d.length<A);C("cmd_line_ptr="+m(581632));h[138]=581632;for(e=0;e<d.length;e++)a[581632+e]=d.charCodeAt(e);l=512*(l+1);C("prot_mode_kernel_start="+m(l));d=new Uint8Array(b,0,l);b=new Uint8Array(b,l);e=l=0;c&&(l=67108864,e=c.byteLength,k(1048576+b.length<l),a.set(new Uint8Array(c),l));
602
+ var h=new Uint32Array(b),l=e[497]||4,p=f[255];if(43605!==p)C("Bad checksum1: "+m(p));else if(p=f[257]|f[258]<<16,1400005704!==p)C("Bad checksum2: "+m(p));else{p=f[259];k(514<=p);var n=e[529];k(n&1);var q=f[283],r=h[139],t=h[140],v=e[564],y=e[565],A=518<=p?h[142]:255,u=h[146],B=h[147],w=h[150],F=h[151],J=h[152];C("kernel boot protocol version: "+m(p));C("flags="+m(n)+" xflags="+m(q));C("code32_start="+m(h[133]));C("initrd_addr_max="+m(r));C("kernel_alignment="+m(t));C("relocatable="+v);C("min_alignment="+
603
+ m(y));C("cmdline max="+m(A));C("payload offset="+m(u)+" size="+m(B));C("pref_address="+m(F)+":"+m(w));C("init_size="+m(J));e[528]=255;e[529]=n&-97|128;f[274]=56832;f[253]=65535;C("heap_end_ptr="+m(56832));d+="\x00";k(d.length<A);C("cmd_line_ptr="+m(581632));h[138]=581632;for(e=0;e<d.length;e++)a[581632+e]=d.charCodeAt(e);l=512*(l+1);C("prot_mode_kernel_start="+m(l));d=new Uint8Array(b,0,l);b=new Uint8Array(b,l);e=l=0;c&&(l=67108864,e=c.byteLength,k(1048576+b.length<l),a.set(new Uint8Array(c),l));
603
604
  h[134]=l;h[135]=e;k(655360>524288+d.length);a.set(d,524288);a.set(b,1048576);a=new Uint8Array(512);(new Uint16Array(a.buffer))[0]=43605;a[2]=1;c=3;a[c++]=250;a[c++]=184;a[c++]=32768;a[c++]=128;a[c++]=142;a[c++]=192;a[c++]=142;a[c++]=216;a[c++]=142;a[c++]=224;a[c++]=142;a[c++]=232;a[c++]=142;a[c++]=208;a[c++]=188;a[c++]=57344;a[c++]=224;a[c++]=234;a[c++]=0;a[c++]=0;a[c++]=32800;a[c++]=128;k(512>c);h=a[c]=0;for(b=0;b<a.length;b++)h+=a[b];a[c]=-h;return{name:"genroms/kernel.bin",data:a}}}function P(a,
604
605
  b,c){this.stop_idling=c;this.wm=b;this.wasm_patch();this.create_jit_imports();this.wasm_memory=b=this.wm.exports.memory;this.memory_size=g(Uint32Array,b,812,1);this.mem8=new Uint8Array(0);this.mem32s=new Int32Array(this.mem8.buffer);this.segment_is_null=g(Uint8Array,b,724,8);this.segment_offsets=g(Int32Array,b,736,8);this.segment_limits=g(Uint32Array,b,768,8);this.segment_access_bytes=g(Uint8Array,b,512,8);this.protected_mode=g(Int32Array,b,800,1);this.idtr_size=g(Int32Array,b,564,1);this.idtr_offset=
605
606
  g(Int32Array,b,568,1);this.gdtr_size=g(Int32Array,b,572,1);this.gdtr_offset=g(Int32Array,b,576,1);this.tss_size_32=g(Int32Array,b,1128,1);this.page_fault=g(Uint32Array,b,540,8);this.cr=g(Int32Array,b,580,8);this.cpl=g(Uint8Array,b,612,1);this.is_32=g(Int32Array,b,804,1);this.stack_size_32=g(Int32Array,b,808,1);this.in_hlt=g(Uint8Array,b,616,1);this.last_virt_eip=g(Int32Array,b,620,1);this.eip_phys=g(Int32Array,b,624,1);this.sysenter_cs=g(Int32Array,b,636,1);this.sysenter_esp=g(Int32Array,b,640,1);
@@ -631,37 +632,37 @@ const c=this.memory_size[0]>>12;let d=0;for(let f=0;f<c;f++)if(a.get(f)){var e=d
631
632
  P.prototype.create_memory=function(a,b){a<b?(a=b,C("Rounding memory size up to "+a,2)):0>(a|0)&&(a=Math.pow(2,31)-131072,C("Rounding memory size down to "+a,2));a=(a-1|131071)+1|0;k(0<(a|0));k(0===(a&131071));console.assert(0===this.memory_size[0],"Expected uninitialised memory");this.memory_size[0]=a;b=this.allocate_memory(a);this.mem8=g(Uint8Array,this.wasm_memory,b,a);this.mem32s=g(Uint32Array,this.wasm_memory,b,a>>2)};P.prototype.init=function(a,b){this.create_memory(a.memory_size||67108864,a.initrd?
632
633
  67108864:1048576);a.disable_jit&&this.set_jit_config(0,1);a.cpuid_level&&this.set_cpuid_level(a.cpuid_level);this.acpi_enabled[0]=+a.acpi;this.reset_cpu();var c=new Ea(this);this.io=c;this.bios.main=a.bios;this.bios.vga=a.vga_bios;this.load_bios();if(a.bzimage){const e=Zc(this.mem8,a.bzimage,a.initrd,a.cmdline||"");e&&this.option_roms.push(e)}c.register_read(179,this,function(){C("port 0xB3 read");return 0});var d=0;c.register_read(146,this,function(){return d});c.register_write(146,this,function(e){d=
633
634
  e});c.register_read(1297,this,function(){if(this.fw_pointer<this.fw_value.length)return this.fw_value[this.fw_pointer++];k(!1,"config port: Read past value");return 0});c.register_write(1296,this,void 0,function(e){function f(p){return new Uint8Array(Int32Array.of(p).buffer)}function h(p){return p>>8|p<<8&65280}function l(p){return p<<24|p<<8&16711680|p>>8&65280|p>>>24}C("bios config port, index="+m(e));this.fw_pointer=0;if(0===e)this.fw_value=f(1431127377);else if(1===e)this.fw_value=f(0);else if(3===
634
- e)this.fw_value=f(this.memory_size[0]);else if(5===e)this.fw_value=f(1);else if(15===e)this.fw_value=f(1);else if(13===e)this.fw_value=new Uint8Array(16);else if(25===e){e=new Int32Array(4+64*this.option_roms.length);const p=new Uint8Array(e.buffer);e[0]=l(this.option_roms.length);for(let n=0;n<this.option_roms.length;n++){const {name:q,data:r}=this.option_roms[n],t=4+64*n;k(65536>49152+n);e[t+0>>2]=l(r.length);e[t+4>>2]=h(49152+n);k(56>q.length);for(let u=0;u<q.length;u++)p[t+8+u]=q.charCodeAt(u)}this.fw_value=
635
+ e)this.fw_value=f(this.memory_size[0]);else if(5===e)this.fw_value=f(1);else if(15===e)this.fw_value=f(1);else if(13===e)this.fw_value=new Uint8Array(16);else if(25===e){e=new Int32Array(4+64*this.option_roms.length);const p=new Uint8Array(e.buffer);e[0]=l(this.option_roms.length);for(let n=0;n<this.option_roms.length;n++){const {name:q,data:r}=this.option_roms[n],t=4+64*n;k(65536>49152+n);e[t+0>>2]=l(r.length);e[t+4>>2]=h(49152+n);k(56>q.length);for(let v=0;v<q.length;v++)p[t+8+v]=q.charCodeAt(v)}this.fw_value=
635
636
  p}else 32768<=e&&49152>e?this.fw_value=f(0):49152<=e&&e-49152<this.option_roms.length?this.fw_value=this.option_roms[e-49152].data:(C("Warning: Unimplemented fw index: "+m(e)),this.fw_value=f(0))});c.register_write(128,this,function(){});c.register_read(128,this,function(){return 255});c.register_write(233,this,function(){});c.register_read(32,this,this.port20_read);c.register_read(33,this,this.port21_read);c.register_read(160,this,this.portA0_read);c.register_read(161,this,this.portA1_read);c.register_write(32,
636
637
  this,this.port20_write);c.register_write(33,this,this.port21_write);c.register_write(160,this,this.portA0_write);c.register_write(161,this,this.portA1_write);c.register_read(1232,this,this.port4D0_read);c.register_read(1233,this,this.port4D1_read);c.register_write(1232,this,this.port4D0_write);c.register_write(1233,this,this.port4D1_write);this.devices={};a.load_devices&&(this.devices.pci=new Dc(this),this.acpi_enabled[0]&&(this.devices.ioapic=new Ac(this),this.devices.apic=new zc(this),this.devices.acpi=
637
638
  new Bc(this)),this.devices.rtc=new hb(this),this.fill_cmos(this.devices.rtc,a),this.devices.dma=new D(this),this.devices.vga=new X(this,b,a.screen,a.vga_memory_size||8388608),this.devices.ps2=new Jc(this,b),this.devices.uart0=new Cc(this,1016,b),a.uart1&&(this.devices.uart1=new Cc(this,760,b)),a.uart2&&(this.devices.uart2=new Cc(this,1E3,b)),a.uart3&&(this.devices.uart3=new Cc(this,744,b)),this.devices.fdc=new V(this,a.fda,a.fdb),c=0,a.hda&&(this.devices.hda=new Tc(this,a.hda,a.hdb,!1,c++,b)),a.cdrom&&
638
639
  (this.devices.cdrom=new Tc(this,a.cdrom,void 0,!0,c++,b)),this.devices.pit=new jb(this,b),"ne2k"===a.net_device.type?this.devices.net=new Gc(this,b,a.preserve_mac_from_state_image,a.mac_address_translation):"virtio"===a.net_device.type&&(this.devices.virtio_net=new Uc(this,b,a.preserve_mac_from_state_image)),a.fs9p&&(this.devices.virtio_9p=new $c(a.fs9p,this,b)),a.virtio_console&&(this.devices.virtio_console=new Hc(this,b)),a.virtio_balloon&&(this.devices.virtio_balloon=new Yc(this,b)),this.devices.sb16=
639
640
  new E(this,b));a.multiboot&&(C("loading multiboot",2),a=this.load_multiboot_option_rom(a.multiboot,a.initrd,a.cmdline))&&(this.bios.main?(C("adding option rom for multiboot",2),this.option_roms.push(a)):(C("loaded multiboot without bios",2),this.reg32[0]=this.io.port_read32(244)));this.debug.init()};P.prototype.load_multiboot=function(a){this.bios.main&&k(!1,"load_multiboot not supported with BIOS");this.load_multiboot_option_rom(a,void 0,"")&&(C("loaded multiboot",2),this.reg32[0]=this.io.port_read32(244))};
640
641
  P.prototype.load_multiboot_option_rom=function(a,b,c){C("Trying multiboot from buffer of size "+a.byteLength,2);if(8192>a.byteLength){var d=new Int32Array(2048);(new Uint8Array(d.buffer)).set(new Uint8Array(a))}else d=new Int32Array(a,0,2048);for(var e=0;8192>e;e+=4){if(464367618===d[e>>2]){var f=d[e+4>>2];if(464367618+f+d[e+8>>2]|0){C("Multiboot checksum check failed",2);continue}}else continue;C("Multiboot magic found, flags: "+m(f>>>0,8),2);k(0===(f&-65540),"TODO");var h=this;this.io.register_read(244,
641
- this,function(){return 0},function(){return 0},function(){var q=31860,r=0;if(c){r|=4;h.write32(31760,q);c+="\x00";var t=(new TextEncoder).encode(c);h.write_blob(t,q);q+=t.length}if(f&2){r|=64;t=0;h.write32(31788,0);h.write32(31792,q);var u=0;let w=!1;for(let F=0;4294967296>F;F+=131072)w&&void 0!==h.memory_map_read8[F>>>17]?(h.write32(q,20),h.write32(q+4,u),h.write32(q+8,0),h.write32(q+12,F-u),h.write32(q+16,0),h.write32(q+20,1),q+=24,t+=24,w=!1):w||void 0!==h.memory_map_read8[F>>>17]||(u=F,w=!0);
642
- k(!w,"top of 4GB shouldn't have memory");h.write32(31788,t)}h.write32(31744,r);t=r=0;if(f&65536){C("Multiboot specifies its own address table",2);var y=d[e+12>>2];var A=d[e+16>>2];var v=d[e+20>>2];var B=d[e+24>>2];r=d[e+28>>2];C("header="+m(y,8)+" load="+m(A,8)+" load_end="+m(v,8)+" bss_end="+m(B,8)+" entry="+m(r,8));k(A<=y);y=e-(y-A);0===v?t=void 0:(k(v>=A),t=v-A);y=new Uint8Array(a,y,t);h.write_blob(y,A);r|=0;t=Math.max(v,B)}else if(1179403647===d[0]){C("Multiboot image is in elf format",2);u=new DataView(a);
643
- const [w,F]=Rc(u,Oc);console.assert(52===F);for(y of Object.keys(w))C(y+": 0x"+(w[y].toString(16)>>>0));console.assert(1179403647===w.magic,"Bad magic");console.assert(1===w.class,"Unimplemented: 64 bit elf");console.assert(1===w.data,"Unimplemented: big endian");console.assert(1===w.version0,"Bad version0");console.assert(2===w.type,"Unimplemented type");console.assert(1===w.version1,"Bad version1");console.assert(52===w.ehsize,"Bad header size");console.assert(32===w.phentsize,"Bad program header size");
644
- console.assert(40===w.shentsize,"Bad section header size");[r]=Sc(new DataView(u.buffer,u.byteOffset+w.phoff,w.phentsize*w.phnum),Pc,w.phnum);[y]=Sc(new DataView(u.buffer,u.byteOffset+w.shoff,w.shentsize*w.shnum),Qc,w.shnum);if(va){console.log("%d program headers:",r.length);for(B of r)console.log("type=%s offset=%s vaddr=%s paddr=%s filesz=%s memsz=%s flags=%s align=%s",B.type.toString(16),B.offset.toString(16),B.vaddr.toString(16),B.paddr.toString(16),B.filesz.toString(16),B.memsz.toString(16),
645
- B.flags.toString(16),B.align.toString(16));console.log("%d section headers:",y.length);for(A of y)console.log("name=%s type=%s flags=%s addr=%s offset=%s size=%s link=%s info=%s addralign=%s entsize=%s",A.name.toString(16),A.type.toString(16),A.flags.toString(16),A.addr.toString(16),A.offset.toString(16),A.size.toString(16),A.link.toString(16),A.info.toString(16),A.addralign.toString(16),A.entsize.toString(16))}B=w;A=r;r=B.entry;for(v of A)0!==v.type&&(1===v.type?(k(v.filesz<=v.memsz),v.paddr+v.memsz<
646
- h.memory_size[0]?(v.filesz&&(A=new Uint8Array(a,v.offset,v.filesz),h.write_blob(A,v.paddr)),t=Math.max(t,v.paddr+v.memsz),C("prg load "+v.paddr+" to "+(v.paddr+v.memsz),2),r===B.entry&&v.vaddr<=r&&v.vaddr+v.memsz>r&&(r=r-v.vaddr+v.paddr)):C("Warning: Skipped loading section, paddr="+m(v.paddr)+" memsz="+v.memsz,2)):2===v.type||3===v.type||4===v.type||6===v.type||7===v.type||1685382480===v.type||1685382481===v.type||1685382482===v.type||1685382483===v.type?C("skip load type "+v.type+" "+v.paddr+" to "+
647
- (v.paddr+v.memsz),2):k(!1,"unimplemented elf section type: "+m(v.type)))}else k(!1,"Not a bootable multiboot format");b&&(h.write32(31764,1),h.write32(31768,q),v=t,0!==(v&4095)&&(v=(v&-4096)+4096),C("ramdisk address "+v),B=v+b.byteLength,h.write32(q,v),h.write32(q+4,B),h.write32(q+8,0),h.write32(q+12,0),k(B<h.memory_size[0]),h.write_blob(new Uint8Array(b),v));h.reg32[3]=31744;h.cr[0]=1;h.protected_mode[0]=1;h.flags[0]=2;h.is_32[0]=1;h.stack_size_32[0]=1;for(q=0;6>q;q++)h.segment_is_null[q]=0,h.segment_offsets[q]=
642
+ this,function(){return 0},function(){return 0},function(){var q=31860,r=0;if(c){r|=4;h.write32(31760,q);c+="\x00";var t=(new TextEncoder).encode(c);h.write_blob(t,q);q+=t.length}if(f&2){r|=64;t=0;h.write32(31788,0);h.write32(31792,q);var v=0;let w=!1;for(let F=0;4294967296>F;F+=131072)w&&void 0!==h.memory_map_read8[F>>>17]?(h.write32(q,20),h.write32(q+4,v),h.write32(q+8,0),h.write32(q+12,F-v),h.write32(q+16,0),h.write32(q+20,1),q+=24,t+=24,w=!1):w||void 0!==h.memory_map_read8[F>>>17]||(v=F,w=!0);
643
+ k(!w,"top of 4GB shouldn't have memory");h.write32(31788,t)}h.write32(31744,r);t=r=0;if(f&65536){C("Multiboot specifies its own address table",2);var y=d[e+12>>2];var A=d[e+16>>2];var u=d[e+20>>2];var B=d[e+24>>2];r=d[e+28>>2];C("header="+m(y,8)+" load="+m(A,8)+" load_end="+m(u,8)+" bss_end="+m(B,8)+" entry="+m(r,8));k(A<=y);y=e-(y-A);0===u?t=void 0:(k(u>=A),t=u-A);y=new Uint8Array(a,y,t);h.write_blob(y,A);r|=0;t=Math.max(u,B)}else if(1179403647===d[0]){C("Multiboot image is in elf format",2);v=new DataView(a);
644
+ const [w,F]=Rc(v,Oc);console.assert(52===F);for(y of Object.keys(w))C(y+": 0x"+(w[y].toString(16)>>>0));console.assert(1179403647===w.magic,"Bad magic");console.assert(1===w.class,"Unimplemented: 64 bit elf");console.assert(1===w.data,"Unimplemented: big endian");console.assert(1===w.version0,"Bad version0");console.assert(2===w.type,"Unimplemented type");console.assert(1===w.version1,"Bad version1");console.assert(52===w.ehsize,"Bad header size");console.assert(32===w.phentsize,"Bad program header size");
645
+ console.assert(40===w.shentsize,"Bad section header size");[r]=Sc(new DataView(v.buffer,v.byteOffset+w.phoff,w.phentsize*w.phnum),Pc,w.phnum);[y]=Sc(new DataView(v.buffer,v.byteOffset+w.shoff,w.shentsize*w.shnum),Qc,w.shnum);if(va){console.log("%d program headers:",r.length);for(B of r)console.log("type=%s offset=%s vaddr=%s paddr=%s filesz=%s memsz=%s flags=%s align=%s",B.type.toString(16),B.offset.toString(16),B.vaddr.toString(16),B.paddr.toString(16),B.filesz.toString(16),B.memsz.toString(16),
646
+ B.flags.toString(16),B.align.toString(16));console.log("%d section headers:",y.length);for(A of y)console.log("name=%s type=%s flags=%s addr=%s offset=%s size=%s link=%s info=%s addralign=%s entsize=%s",A.name.toString(16),A.type.toString(16),A.flags.toString(16),A.addr.toString(16),A.offset.toString(16),A.size.toString(16),A.link.toString(16),A.info.toString(16),A.addralign.toString(16),A.entsize.toString(16))}B=w;A=r;r=B.entry;for(u of A)0!==u.type&&(1===u.type?(k(u.filesz<=u.memsz),u.paddr+u.memsz<
647
+ h.memory_size[0]?(u.filesz&&(A=new Uint8Array(a,u.offset,u.filesz),h.write_blob(A,u.paddr)),t=Math.max(t,u.paddr+u.memsz),C("prg load "+u.paddr+" to "+(u.paddr+u.memsz),2),r===B.entry&&u.vaddr<=r&&u.vaddr+u.memsz>r&&(r=r-u.vaddr+u.paddr)):C("Warning: Skipped loading section, paddr="+m(u.paddr)+" memsz="+u.memsz,2)):2===u.type||3===u.type||4===u.type||6===u.type||7===u.type||1685382480===u.type||1685382481===u.type||1685382482===u.type||1685382483===u.type?C("skip load type "+u.type+" "+u.paddr+" to "+
648
+ (u.paddr+u.memsz),2):k(!1,"unimplemented elf section type: "+m(u.type)))}else k(!1,"Not a bootable multiboot format");b&&(h.write32(31764,1),h.write32(31768,q),u=t,0!==(u&4095)&&(u=(u&-4096)+4096),C("ramdisk address "+u),B=u+b.byteLength,h.write32(q,u),h.write32(q+4,B),h.write32(q+8,0),h.write32(q+12,0),k(B<h.memory_size[0]),h.write_blob(new Uint8Array(b),u));h.reg32[3]=31744;h.cr[0]=1;h.protected_mode[0]=1;h.flags[0]=2;h.is_32[0]=1;h.stack_size_32[0]=1;for(q=0;6>q;q++)h.segment_is_null[q]=0,h.segment_offsets[q]=
648
649
  0,h.segment_limits[q]=4294967295,h.sreg[q]=45058;h.instruction_pointer[0]=h.get_seg_cs()+r|0;h.update_state_flags();C("Starting multiboot kernel at:",2);h.debug.dump_state();h.debug.dump_regs();return 732803074});this.io.register_write_consecutive(244,this,function(q){console.log("Test exited with code "+m(q,2));throw"HALT";},function(){},function(){},function(){});for(let q=0;15>=q;q++){function r(t){C("kvm-unit-test: Set irq "+m(q)+" to "+m(t,2));t?this.device_raise_irq(q):this.device_lower_irq(q)}
649
650
  this.io.register_write(8192+q,this,r,r,r)}const p=new Uint8Array(512);(new Uint16Array(p.buffer))[0]=43605;p[2]=1;var l=3;p[l++]=102;p[l++]=229;p[l++]=244;k(512>l);let n=p[l]=0;for(let q=0;q<p.length;q++)n+=p[q];p[l]=-n;return{name:"genroms/multiboot.bin",data:p}}C("Multiboot header not found",2)};P.prototype.fill_cmos=function(a,b){var c=b.boot_order||291;a.cmos_write(56,1|c>>4&240);a.cmos_write(61,c&255);a.cmos_write(21,128);a.cmos_write(22,2);c=0;1048576<=this.memory_size[0]&&(c=this.memory_size[0]-
650
651
  1048576>>10,c=Math.min(c,65535));a.cmos_write(23,c&255);a.cmos_write(24,c>>8&255);a.cmos_write(48,c&255);a.cmos_write(49,c>>8&255);c=0;16777216<=this.memory_size[0]&&(c=this.memory_size[0]-16777216>>16,c=Math.min(c,65535));a.cmos_write(52,c&255);a.cmos_write(53,c>>8&255);a.cmos_write(91,0);a.cmos_write(92,0);a.cmos_write(93,0);a.cmos_write(20,47);a.cmos_write(95,0);b.fastboot&&a.cmos_write(63,1)};P.prototype.load_bios=function(){var a=this.bios.main,b=this.bios.vga;if(a){k(a instanceof ArrayBuffer);
651
652
  var c=new Uint8Array(a);this.write_blob(c,1048576-a.byteLength);if(b){k(b instanceof ArrayBuffer);var d=new Uint8Array(b);this.write_blob(d,786432);this.io.mmap_register(4272947200,1048576,function(e){e=e-4272947200|0;return e<d.length?d[e]:0},function(){k(!1,"Unexpected write to VGA rom")})}else C("Warning: No VGA BIOS");this.io.mmap_register(4293918720,1048576,function(e){return this.mem8[e&1048575]}.bind(this),function(e,f){this.mem8[e&1048575]=f}.bind(this))}else C("Warning: No BIOS")};P.prototype.codegen_finalize=
652
653
  function(a,b,c,d,e){d>>>=0;e>>>=0;k(0<=a&&900>a);const f=new Uint8Array(this.wasm_memory.buffer,d,e);this.seen_code[b]=(this.seen_code[b]||0)+1;this.test_hook_did_generate_wasm&&this.test_hook_did_generate_wasm(f);WebAssembly.instantiate(f,{e:this.jit_imports}).then(h=>{this.wm.wasm_table.set(a+1024,h.instance.exports.f);this.codegen_finalize_finished(a,b,c);this.test_hook_did_finalize_wasm&&this.test_hook_did_finalize_wasm(f)}).catch(h=>{console.log(h);debugger;throw h;})};P.prototype.log_uncompiled_code=
653
654
  function(){};P.prototype.dump_function_code=function(){};P.prototype.run_hardware_timers=function(a,b){const c=this.devices.pit.timer(b,!1),d=this.devices.rtc.timer(b,!1);let e=100,f=100;a&&(e=this.devices.acpi.timer(b),f=this.devices.apic.timer(b));return Math.min(c,d,e,f)};P.prototype.device_raise_irq=function(a){k(1===arguments.length);this.pic_set_irq(a);this.devices.ioapic&&this.devices.ioapic.set_irq(a)};P.prototype.device_lower_irq=function(a){this.pic_clear_irq(a);this.devices.ioapic&&this.devices.ioapic.clear_irq(a)};
654
- P.prototype.debug_init=function(){function a(n){for(var q=e.protected_mode[0]?"prot":"real",r=e.get_eflags(),t=e.getiopl(),u=e.cpl[0],y=m(e.sreg[1],4)+":"+m(e.get_real_eip()>>>0,8),A=m(e.sreg[2],4)+":"+m(e.reg32[0]>>>0,8),v=e.is_32[0]?"32":"16",B=e.flags[0]&512?1:0,w={[1]:"c",[4]:"p",[16]:"a",[64]:"z",[128]:"s",[256]:"t",[512]:"i",[1024]:"d",[2048]:"o"},F="",J=0;16>J;J++)w[1<<J]&&(F=r&1<<J?F+w[1<<J]:F+" ");return"mode="+q+"/"+v+" paging="+ +(0!==(e.cr[0]&-2147483648))+" pae="+ +(0!==(e.cr[4]&32))+
655
- " iopl="+t+" cpl="+u+" if="+B+" cs:eip="+y+" cs_off="+m(e.get_seg_cs()>>>0,8)+" flgs="+m(e.get_eflags()>>>0,6)+" ("+F+") ss:esp="+A+" ssize="+ +e.stack_size_32[0]+(n?" in "+n:"")}function b(){for(var n={eax:0,ecx:1,edx:2,ebx:3,esp:4,ebp:5,esi:6,edi:7},q="eax ecx edx ebx esp ebp esi edi".split(" "),r="",t="",u=0;4>u;u++)r+=q[u]+"="+m(e.reg32[n[q[u]]]>>>0,8)+" ",t+=q[u+4]+"="+m(e.reg32[n[q[u+4]]]>>>0,8)+" ";r+=" ds="+m(e.sreg[3],4)+" es="+m(e.sreg[0],4)+" fs="+m(e.sreg[4],4);t+=" gs="+m(e.sreg[5],
656
- 4)+" cs="+m(e.sreg[1],4)+" ss="+m(e.sreg[2],4);return[r,t]}function c(n,q,r){if(!(n&1))return!1;var t=128===(n&128);return{size:t,global:256===(n&256),accessed:32===(n&32),dirty:64===(n&64),cache_disable:16===(n&16),user:4===(n&4),read_write:2===(n&2),address:(t&&!r?n&(q?4292870144:4290772992):n&4294963200)>>>0}}function d(n,q,r){for(var t=q?512:1024,u=q?8:4,y=q?21:22,A=0;A<t;A++){var v=e.read32s(n+A*u),B=c(v,q,!0);if(B)if(v="",v+=B.size?"S ":" ",v+=B.accessed?"A ":" ",v+=B.cache_disable?"Cd ":
657
- " ",v+=B.user?"U ":" ",v+=B.read_write?"Rw ":" ",B.size)C("=== "+m(r+(A<<y)>>>0,8)+" -> "+m(B.address>>>0,8)+" | "+v);else{C("=== "+m(r+(A<<y)>>>0,8)+" | "+v);for(var w=0;w<t;w++){var F=B.address+w*u;v=e.read32s(F);var J=c(v,q,!1);J&&(v="",v+=J.cache_disable?"Cd ":" ",v+=J.user?"U ":" ",v+=J.read_write?"Rw ":" ",v+=J.global?"G ":" ",v+=J.accessed?"A ":" ",v+=J.dirty?"Di ":" ",C("# "+m(r+(A<<y|w<<12)>>>0,8)+" -> "+m(J.address,8)+" | "+v+" (at "+m(F,8)+")"))}}}}var e=this,f={};this.debug=
655
+ P.prototype.debug_init=function(){function a(n){for(var q=e.protected_mode[0]?"prot":"real",r=e.get_eflags(),t=e.getiopl(),v=e.cpl[0],y=m(e.sreg[1],4)+":"+m(e.get_real_eip()>>>0,8),A=m(e.sreg[2],4)+":"+m(e.reg32[0]>>>0,8),u=e.is_32[0]?"32":"16",B=e.flags[0]&512?1:0,w={[1]:"c",[4]:"p",[16]:"a",[64]:"z",[128]:"s",[256]:"t",[512]:"i",[1024]:"d",[2048]:"o"},F="",J=0;16>J;J++)w[1<<J]&&(F=r&1<<J?F+w[1<<J]:F+" ");return"mode="+q+"/"+u+" paging="+ +(0!==(e.cr[0]&-2147483648))+" pae="+ +(0!==(e.cr[4]&32))+
656
+ " iopl="+t+" cpl="+v+" if="+B+" cs:eip="+y+" cs_off="+m(e.get_seg_cs()>>>0,8)+" flgs="+m(e.get_eflags()>>>0,6)+" ("+F+") ss:esp="+A+" ssize="+ +e.stack_size_32[0]+(n?" in "+n:"")}function b(){for(var n={eax:0,ecx:1,edx:2,ebx:3,esp:4,ebp:5,esi:6,edi:7},q="eax ecx edx ebx esp ebp esi edi".split(" "),r="",t="",v=0;4>v;v++)r+=q[v]+"="+m(e.reg32[n[q[v]]]>>>0,8)+" ",t+=q[v+4]+"="+m(e.reg32[n[q[v+4]]]>>>0,8)+" ";r+=" ds="+m(e.sreg[3],4)+" es="+m(e.sreg[0],4)+" fs="+m(e.sreg[4],4);t+=" gs="+m(e.sreg[5],
657
+ 4)+" cs="+m(e.sreg[1],4)+" ss="+m(e.sreg[2],4);return[r,t]}function c(n,q,r){if(!(n&1))return!1;var t=128===(n&128);return{size:t,global:256===(n&256),accessed:32===(n&32),dirty:64===(n&64),cache_disable:16===(n&16),user:4===(n&4),read_write:2===(n&2),address:(t&&!r?n&(q?4292870144:4290772992):n&4294963200)>>>0}}function d(n,q,r){for(var t=q?512:1024,v=q?8:4,y=q?21:22,A=0;A<t;A++){var u=e.read32s(n+A*v),B=c(u,q,!0);if(B)if(u="",u+=B.size?"S ":" ",u+=B.accessed?"A ":" ",u+=B.cache_disable?"Cd ":
658
+ " ",u+=B.user?"U ":" ",u+=B.read_write?"Rw ":" ",B.size)C("=== "+m(r+(A<<y)>>>0,8)+" -> "+m(B.address>>>0,8)+" | "+u);else{C("=== "+m(r+(A<<y)>>>0,8)+" | "+u);for(var w=0;w<t;w++){var F=B.address+w*v;u=e.read32s(F);var J=c(u,q,!1);J&&(u="",u+=J.cache_disable?"Cd ":" ",u+=J.user?"U ":" ",u+=J.read_write?"Rw ":" ",u+=J.global?"G ":" ",u+=J.accessed?"A ":" ",u+=J.dirty?"Di ":" ",C("# "+m(r+(A<<y|w<<12)>>>0,8)+" -> "+m(J.address,8)+" | "+u+" (at "+m(F,8)+")"))}}}}var e=this,f={};this.debug=
658
659
  f;f.init=function(){function n(r){10===r?(C(q,4096),q=""):q+=String.fromCharCode(r)}if(e.io){var q="";e.io.register_write(1026,this,n);e.io.register_write(1280,this,n)}};f.get_regs_short=b;f.dump_regs=function(){var n=b();C(n[0],2);C(n[1],2)};f.get_state=a;f.dump_state=function(n){C(a(n),2)};f.dump_stack=function(n,q){var r=e.reg32[4];C("========= STACK ==========");if(q>=n||void 0===q)n=5,q=-5;for(;n>q;n--){var t=" ";n||(t="=> ");t+=m(n,2)+" | ";C(t+m(r+4*n,8)+" | "+m(e.read32s(r+4*n)>>>0))}};
659
- f.dump_page_structures=function(){if(e.cr[4]&32){C("PAE enabled");for(var n=0;4>n;n++){var q=e.read32s(e.cr[3]+8*n);q&1&&d(q&4294963200,!0,n<<30)}}else C("PAE disabled"),d(e.cr[3],!1,0)};f.dump_gdt_ldt=function(){function n(q,r){for(var t=0;t<r;t+=8,q+=8){var u=e.read16(q+2)|e.read8(q+4)<<16|e.read8(q+7)<<24,y=e.read16(q)|(e.read8(q+6)&15)<<16,A=e.read8(q+5),v=e.read8(q+6)>>4,B="",w=A>>5&3;B=A&128?B+" P ":B+"NP ";A&16?(B=v&4?B+"32b ":B+"16b ",A&8?(B+="X ",A&4&&(B+="C ")):B+="R ",B+="RW "):B+="sys: "+
660
- m(A&15);v&8&&(y=y<<12|4095);C(m(t&-8,4)+" "+m(u>>>0,8)+" ("+m(y>>>0,8)+" bytes) "+B+"; dpl = "+w+", a = "+A.toString(2)+", f = "+v.toString(2))}}C("gdt: (len = "+m(e.gdtr_size[0])+")");n(e.translate_address_system_read(e.gdtr_offset[0]),e.gdtr_size[0]);C("\nldt: (len = "+m(e.segment_limits[7])+")");n(e.translate_address_system_read(e.segment_offsets[7]),e.segment_limits[7])};f.dump_idt=function(){for(var n=0;n<e.idtr_size[0];n+=8){var q=e.translate_address_system_read(e.idtr_offset[0]+n),r=e.read16(q)|
661
- e.read16(q+6)<<16,t=e.read16(q+2);q=e.read8(q+5);var u=q>>5&3;var y=5===(q&31)?"task gate ":14===(q&31)?"intr gate ":15===(q&31)?"trap gate ":"invalid ";y=q&128?y+" P":y+"NP";C(m(n>>3,4)+" "+m(r>>>0,8)+", "+m(t,4)+"; "+y+"; dpl = "+u+", t = "+q.toString(2))}};f.get_memory_dump=function(n,q){void 0===n?(n=0,q=e.memory_size[0]):void 0===q&&(q=n,n=0);return e.mem8.slice(n,n+q).buffer};f.memory_hex_dump=function(n,q){q=q||64;for(var r,t,u=0;u<q>>4;u++){r=m(n+(u<<4),5)+" ";for(var y=0;16>y;y++)t=
662
- e.read8(n+(u<<4)+y),r+=m(t,2)+" ";r+=" ";for(y=0;16>y;y++)t=e.read8(n+(u<<4)+y),r+=33>t||126<t?".":String.fromCharCode(t);C(r)}};f.used_memory_dump=function(){for(var n=e.memory_size[0]/128/16|0,q,r=0;16>r;r++){q=m(128*r*n,8)+" | ";for(var t=0;128>t;t++)q+=0<e.mem32s[(128*r+t)*n]?"X":" ";C(q)}};f.debug_interrupt=function(){};let h,l;f.dump_code=function(n,q,r){if(!l){if(void 0===h&&(h="function"===typeof require?require("./capstone-x86.min.js"):window.cs,void 0===h)){C("Warning: Missing capstone library, disassembly not available");
663
- return}l=[new h.Capstone(h.ARCH_X86,h.MODE_16),new h.Capstone(h.ARCH_X86,h.MODE_32)]}try{l[n].disasm(q,r).forEach(function(t){C(m(t.address>>>0)+": "+ba(t.bytes.map(u=>m(u,2).slice(-2)).join(" "),20)+" "+t.mnemonic+" "+t.op_str)}),C("")}catch(t){C("Could not disassemble: "+Array.from(q).map(u=>m(u,2)).join(" "))}};let p;f.dump_wasm=function(n){if(void 0===p&&(p="function"===typeof require?require("./libwabt.cjs"):new window.WabtModule,void 0===p)){C("Warning: Missing libwabt, wasm dump not available");
664
- return}n=n.slice();try{var q=p.readWasm(n,{readDebugNames:!1});q.generateNames();q.applyNames();const u=q.toText({foldExprs:!0,inlineExport:!0});C(u)}catch(u){var r=new Blob([n]),t=document.createElement("a");t.download="failed.wasm";t.href=window.URL.createObjectURL(r);t.dataset.downloadurl=["application/octet-stream",t.download,t.href].join(":");t.click();window.URL.revokeObjectURL(t.src);console.log(u.toString())}finally{q&&q.destroy()}}};function Ic(a,b){this.cpu=a;this.pci=a.devices.pci;this.device_id=
660
+ f.dump_page_structures=function(){if(e.cr[4]&32){C("PAE enabled");for(var n=0;4>n;n++){var q=e.read32s(e.cr[3]+8*n);q&1&&d(q&4294963200,!0,n<<30)}}else C("PAE disabled"),d(e.cr[3],!1,0)};f.dump_gdt_ldt=function(){function n(q,r){for(var t=0;t<r;t+=8,q+=8){var v=e.read16(q+2)|e.read8(q+4)<<16|e.read8(q+7)<<24,y=e.read16(q)|(e.read8(q+6)&15)<<16,A=e.read8(q+5),u=e.read8(q+6)>>4,B="",w=A>>5&3;B=A&128?B+" P ":B+"NP ";A&16?(B=u&4?B+"32b ":B+"16b ",A&8?(B+="X ",A&4&&(B+="C ")):B+="R ",B+="RW "):B+="sys: "+
661
+ m(A&15);u&8&&(y=y<<12|4095);C(m(t&-8,4)+" "+m(v>>>0,8)+" ("+m(y>>>0,8)+" bytes) "+B+"; dpl = "+w+", a = "+A.toString(2)+", f = "+u.toString(2))}}C("gdt: (len = "+m(e.gdtr_size[0])+")");n(e.translate_address_system_read(e.gdtr_offset[0]),e.gdtr_size[0]);C("\nldt: (len = "+m(e.segment_limits[7])+")");n(e.translate_address_system_read(e.segment_offsets[7]),e.segment_limits[7])};f.dump_idt=function(){for(var n=0;n<e.idtr_size[0];n+=8){var q=e.translate_address_system_read(e.idtr_offset[0]+n),r=e.read16(q)|
662
+ e.read16(q+6)<<16,t=e.read16(q+2);q=e.read8(q+5);var v=q>>5&3;var y=5===(q&31)?"task gate ":14===(q&31)?"intr gate ":15===(q&31)?"trap gate ":"invalid ";y=q&128?y+" P":y+"NP";C(m(n>>3,4)+" "+m(r>>>0,8)+", "+m(t,4)+"; "+y+"; dpl = "+v+", t = "+q.toString(2))}};f.get_memory_dump=function(n,q){void 0===n?(n=0,q=e.memory_size[0]):void 0===q&&(q=n,n=0);return e.mem8.slice(n,n+q).buffer};f.memory_hex_dump=function(n,q){q=q||64;for(var r,t,v=0;v<q>>4;v++){r=m(n+(v<<4),5)+" ";for(var y=0;16>y;y++)t=
663
+ e.read8(n+(v<<4)+y),r+=m(t,2)+" ";r+=" ";for(y=0;16>y;y++)t=e.read8(n+(v<<4)+y),r+=33>t||126<t?".":String.fromCharCode(t);C(r)}};f.used_memory_dump=function(){for(var n=e.memory_size[0]/128/16|0,q,r=0;16>r;r++){q=m(128*r*n,8)+" | ";for(var t=0;128>t;t++)q+=0<e.mem32s[(128*r+t)*n]?"X":" ";C(q)}};f.debug_interrupt=function(){};let h,l;f.dump_code=function(n,q,r){if(!l){if(void 0===h&&(h="function"===typeof require?require("./capstone-x86.min.js"):window.cs,void 0===h)){C("Warning: Missing capstone library, disassembly not available");
664
+ return}l=[new h.Capstone(h.ARCH_X86,h.MODE_16),new h.Capstone(h.ARCH_X86,h.MODE_32)]}try{l[n].disasm(q,r).forEach(function(t){C(m(t.address>>>0)+": "+ba(t.bytes.map(v=>m(v,2).slice(-2)).join(" "),20)+" "+t.mnemonic+" "+t.op_str)}),C("")}catch(t){C("Could not disassemble: "+Array.from(q).map(v=>m(v,2)).join(" "))}};let p;f.dump_wasm=function(n){if(void 0===p&&(p="function"===typeof require?require("./libwabt.cjs"):new window.WabtModule,void 0===p)){C("Warning: Missing libwabt, wasm dump not available");
665
+ return}n=n.slice();try{var q=p.readWasm(n,{readDebugNames:!1});q.generateNames();q.applyNames();const v=q.toText({foldExprs:!0,inlineExport:!0});C(v)}catch(v){var r=new Blob([n]),t=document.createElement("a");t.download="failed.wasm";t.href=window.URL.createObjectURL(r);t.dataset.downloadurl=["application/octet-stream",t.download,t.href].join(":");t.click();window.URL.revokeObjectURL(t.src);console.log(v.toString())}finally{q&&q.destroy()}}};function Ic(a,b){this.cpu=a;this.pci=a.devices.pci;this.device_id=
665
666
  b.device_id;this.pci_space=[244,26,b.device_id&255,b.device_id>>8,7,5,16,0,1,0,2,0,0,0,0,0,1,168,0,0,0,16,191,254,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,244,26,b.subsystem_device_id&255,b.subsystem_device_id>>8,0,0,0,0,64,0,0,0,0,0,0,0,0,1,0,0];this.pci_space=this.pci_space.concat(Array(256-this.pci_space.length).fill(0));this.pci_id=b.pci_id;this.pci_bars=[];this.name=b.name;this.driver_feature_select=this.device_feature_select=0;this.device_feature=new Uint32Array(4);this.driver_feature=new Uint32Array(4);
666
667
  for(var c of b.common.features)k(0<=c,"VirtIO device<"+this.name+"> feature bit numbers must be non-negative"),k(128>c,"VirtIO device<"+this.name+"> feature bit numbers assumed less than 128 in implementation"),this.device_feature[c>>>5]|=1<<(c&31),this.driver_feature[c>>>5]|=1<<(c&31);k(b.common.features.includes(32),"VirtIO device<"+this.name+"> only non-transitional devices are supported");this.features_ok=!0;this.device_status=0;this.config_has_changed=!1;this.config_generation=0;this.queues=
667
668
  [];for(var d of b.common.queues)this.queues.push(new Y(a,this,d));this.queue_select=0;this.queue_selected=this.queues[0];this.isr_status=0;c=new Set;for(var e of this.queues.map(f=>f.notify_offset))d=b.notification.single_handler?0:e,c.add(d),k(b.notification.handlers[d],"VirtIO device<"+this.name+"> every queue's notifier must exist");for(const [f,h]of b.notification.handlers.entries())k(!h||c.has(f),"VirtIO device<"+this.name+"> no defined notify handler should be unused");e=[];e.push(this.create_common_capability(b.common));