v86 0.5.66 → 0.5.120

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.
@@ -10,22 +10,22 @@ c.done(new Uint8Array(f))}else d=await a.readFile(b,{encoding:c.as_json?"utf-8":
10
10
  h=0;h<f.length;h++){var l=f[h];e.setRequestHeader(l,b.headers[l])}b.range&&(f=b.range.start,e.setRequestHeader("Range","bytes="+f+"-"+(f+b.range.length-1)),e.setRequestHeader("X-Accept-Encoding","identity"),e.onreadystatechange=function(){200===e.status&&(console.error("Server sent full file in response to ranged request, aborting",{filename:a}),e.abort())});e.onload=function(){if(4===e.readyState)if(200!==e.status&&206!==e.status)console.error("Loading the image "+a+" failed (status %d)",e.status),
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
- 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 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
- (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,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,
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,M=Va?Va.canvas:null;M&&M.width===x&&M.height===G||(M?(M.width=x,M.height=G):(M=new OffscreenCanvas(x,G),Va=M.getContext("2d")),Gb=Va.createImageData(x,G));const R=Gb.data;let Q=0,T;G=Hb?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};M=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+=M,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);Ib&&G(Jb&&192<=Ga&&223>=Ga&&Na&1?255:0)}bc[Z]=T?1:0}Va.putImageData(Gb,0,0)}function e(z,x,G,M){if(x&&G){z.style.width="";z.style.height="";M&&(z.style.transform="");var R=z.getBoundingClientRect();M?z.style.transform=
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"]=""),M=window.devicePixelRatio||1,0!==M%1&&(x/=M,G/=M));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,v=void 0!==a.scale?a.scale:1,y=1,A,u,B,w,F,L,pa,Va,Gb,bc=new Int8Array(2048),S,oa,Ib,Hb,Jb,Kb=0,Lb=0,sb,cc=0,tb,Mb,ub,Nb=[],ib=Nb,vb=0,Ob=!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===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
- 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,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
- 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));
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,M;256>G;G++)M=126<G?x[G-127]:32>G?z[G]:G,Nb.push(String.fromCharCode(M));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 M=G.getContext("2d");M.imageSmoothingEnabled=!1;M.font=window.getComputedStyle(p).font;M.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];M.fillStyle=c(B[T+2]);M.fillRect(Q*x[0],R*x[1],x[0],x[1]);M.fillStyle=c(ia);M.fillText(ib[la],Q*x[0],R*x[1])}"none"!==n.style.display&&q<F&&r<w&&(M.fillStyle=
20
+ n.style.backgroundColor,M.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,M,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]=M;B[x+2]=R;B[x+3]=Q;A[z]=1};this.timer=function(){vb=requestAnimationFrame(()=>this.update_screen())};this.update_screen=function(){Ob||(0===u?this.update_text():1===u?this.update_graphical():this.update_graphical_text());
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(L){var z=performance.now();if(266<z-cc){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}cc=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,Ga,Ma,Na;for(let xa=0;xa<R;xa+=oa,Z+=4){const dc=B[Z+0];var M=B[Z+1];const ec=B[Z+2],fc=B[Z+3],gc=M&2?Lb:Kb;M=(!(M&1)||sb)&&bc[(gc<<8)+dc];Ma!==ec&&(void 0!==Ma&&(L.fillStyle=c(Ma),L.fillRect(Na,ia,xa-Na,S)),Ma=ec,Na=xa);ta!==fc&&(void 0!==ta&&(pa.fillStyle=c(ta),pa.fillRect(Ga,0,xa-Ga,S)),ta=fc,Ga=xa);M&&pa.drawImage(z,dc*oa,gc*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";L.fillStyle=c(Ma);L.fillRect(Na,ia,R-Na,S);L.drawImage(x,0,0,R,S,0,ia,R,S)}T&&(sb&&ub&&A[q]&&(L.fillStyle=c(B[4*(q*w+r)+3]),L.fillRect(r*oa,q*S+tb,oa,Mb-tb+1)),A.fill(0));T&&l.drawImage(L.canvas,0,0)}};this.destroy=function(){vb&&(cancelAnimationFrame(vb),vb=0)};this.pause=function(){Ob=!0;n.classList.remove("blinking-cursor")};this.continue=function(){Ob=!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,M,R,Q){const T=G?16:x?9:8;if(S!==z||oa!==T||Ib!==x||Hb!==G||Jb!==M||Q)Q=oa!==T||S!==z,S=z,oa=T,Ib=x,Hb=G,Jb=M,2===u&&(d(R),A.fill(1),Q&&this.set_size_graphical_text())};this.set_font_page=function(z,x){if(Kb!==z||Lb!==x)Kb=z,Lb=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;L&&L.canvas.width===z&&L.canvas.height===x&&pa.canvas.height===G||(L?(L.canvas.width=z,L.canvas.height=x,pa.canvas.width=z,pa.canvas.height=G):(L=(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||Nb};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!==Mb||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,Mb=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 M=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
+ 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)}M.parentNode.replaceChild(R,M)};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&&
31
31
  (this.byteLength=await ua(this.filename));this.onload&&this.onload(Object.create(null))};za.prototype.get_from_cache=function(a,b){var c=b/256;a/=256;for(var d=0;d<c;d++)if(!this.block_cache.get(a+d))return;if(1===c)return this.block_cache.get(a);b=new Uint8Array(b);for(d=0;d<c;d++)b.set(this.block_cache.get(a+d),256*d);return b};za.prototype.get=function(a,b,c){k(a+b<=this.byteLength);k(0===a%256);k(0===b%256);k(b);var d=this.get_from_cache(a,b);if(d)c(d);else{var e=a,f=b;this.fixed_chunk_size&&
@@ -174,15 +174,15 @@ rb.prototype.handle_open=function(){for(var a=0;a<this.send_queue.length;a++)thi
174
174
  new WebSocket(this.url)}catch(b){console.error(b);return}this.socket.binaryType="arraybuffer";this.socket.onopen=this.handle_open.bind(this);this.socket.onmessage=this.handle_message.bind(this);this.socket.onclose=this.handle_close.bind(this);this.socket.onerror=this.handle_error.bind(this)}}};rb.prototype.send=function(a){this.socket&&1===this.socket.readyState?this.socket.send(a):(this.send_queue.push(a),this.send_queue.length>2*this.send_queue_limit&&(this.send_queue=this.send_queue.slice(-this.send_queue_limit)),
175
175
  this.connect())};rb.prototype.change_proxy=function(a){this.url=a;this.socket&&(this.socket.onclose=function(){},this.socket.onerror=function(){},this.socket.close(),this.socket=void 0)};const wb=(new Date("1970-01-01T00:00:00Z")).getTime(),xb=(new Date("1900-01-01T00:00:00Z")).getTime(),yb=wb-xb,zb=Math.pow(2,32),Ab=[118,56,54];function Bb(a){return[0,1,2,3,4,5].map(b=>a[b].toString(16)).map(b=>1===b.length?"0"+b:b).join(":")}function Cb(a){return a[0]<<24|a[1]<<16|a[2]<<8|a[3]}class Db{constructor(a,
176
176
  b){a=Math.min(a,16);this.maximum_capacity=b?Math.max(b,a):0;this.length=this.head=this.tail=0;this.buffer=new Uint8Array(a)}write(a){const b=a.length;var c=this.length+b;let d=this.buffer.length;if(d<c){for(k(0<d);d<c;)d*=2;if(this.maximum_capacity&&d>this.maximum_capacity)throw Error("stream capacity overflow in GrowableRingbuffer.write(), package dropped");c=new Uint8Array(d);this.peek(c);this.tail=0;this.head=this.length;this.buffer=c}c=this.buffer;const e=this.head+b;if(e>d){const f=d-this.head;
177
- c.set(a.subarray(0,f),this.head);c.set(a.subarray(f))}else c.set(a,this.head);this.head=e%d;this.length+=b}peek(a){const b=Math.min(this.length,a.length);if(b){const e=this.buffer;var c=e.length,d=this.tail+b;d>c?(d%=c,c-=this.tail,a.set(e.subarray(this.tail)),a.set(e.subarray(0,d),c)):a.set(e.subarray(this.tail,d))}return b}remove(a){a>this.length&&(a=this.length);a&&(this.tail=(this.tail+a)%this.buffer.length,this.length-=a);return a}}function Nb(){const a=new Uint8Array(1518),b=a.buffer,c=a.byteOffset;
178
- 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);
179
- 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);
180
- 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,
181
- 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,
182
- 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),
183
- 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])+
184
- (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,
185
- 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||
177
+ c.set(a.subarray(0,f),this.head);c.set(a.subarray(f))}else c.set(a,this.head);this.head=e%d;this.length+=b}peek(a){const b=Math.min(this.length,a.length);if(b){const e=this.buffer;var c=e.length,d=this.tail+b;d>c?(d%=c,c-=this.tail,a.set(e.subarray(this.tail)),a.set(e.subarray(0,d),c)):a.set(e.subarray(this.tail,d))}return b}remove(a){a>this.length&&(a=this.length);a&&(this.tail=(this.tail+a)%this.buffer.length,this.length-=a);return a}}function Eb(){const a=new Uint8Array(1518),b=a.buffer,c=a.byteOffset;
178
+ 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 Fb(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);
179
+ var c=a.eth_frame,d=c.subarray,e=a.eth_frame_view;Fb(0,b.eth.dest,e,a);Fb(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);Fb(8,b.arp.sha,f,a);Fb(14,b.arp.spa,f,a);Fb(18,b.arp.tha,f,a);Fb(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);
180
+ l.setUint8(1,b.icmp.code);l.setUint16(2,0);var p=4+Fb(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);Fb(28,
181
+ b.dhcp.chaddr,q,a);q.setUint32(236,1669485411);n=240;for(var r of b.dhcp.options)n+=Fb(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,
182
+ 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+=Fb(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),
183
+ 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+Fb(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])+
184
+ (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+=Fb(20,
185
+ 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);Fb(12,b.ipv4.src,f,a);Fb(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||
186
186
  "cloudflare-dns.com"}/dns-query`,{method:"POST",headers:[["content-type","application/dns-message"]],body:a.udp.data}).then(async c=>{c={eth:{ethertype:2048,src:b.router_mac,dest:a.eth.src},ipv4:{proto:17,src:b.router_ip,dest:a.ipv4.src},udp:{sport:53,dport:a.udp.sport,data:new Uint8Array(await c.arrayBuffer())}};b.receive(Qb(b.eth_encoder_buf,c))});return!0}function Sb(a,b){let c={};c.eth={ethertype:2048,src:b.router_mac,dest:a.eth.src};c.ipv4={proto:17,src:b.router_ip,dest:b.vm_ip};c.udp={sport:67,
187
187
  dport:68};c.dhcp={htype:1,hlen:6,hops:0,xid:a.dhcp.xid,secs:0,flags:0,ciaddr:0,yiaddr:Cb(b.vm_ip),siaddr:Cb(b.router_ip),giaddr:Cb(b.router_ip),chaddr:a.dhcp.chaddr};let d=[],e=a.dhcp.options.find(function(f){return 53===f[0]});e&&3===e[2]&&(a.dhcp.op=3);1===a.dhcp.op&&(c.dhcp.op=2,d.push(new Uint8Array([53,1,2])));3===a.dhcp.op&&(c.dhcp.op=2,d.push(new Uint8Array([53,1,5])),d.push(new Uint8Array([51,4,8,0,0,0])));a=[b.router_ip[0],b.router_ip[1],b.router_ip[2],b.router_ip[3]];d.push(new Uint8Array([1,
188
188
  4,255,255,255,0]));b.masquerade&&(d.push(new Uint8Array([3,4].concat(a))),d.push(new Uint8Array([6,4].concat(a))));d.push(new Uint8Array([54,4].concat(a)));d.push(new Uint8Array([60,3].concat(Ab)));d.push(new Uint8Array([255,0]));c.dhcp.options=d;b.receive(Qb(b.eth_encoder_buf,c))}function Tb(a,b){let c={};var d=(new DataView(a.buffer,a.byteOffset,a.byteLength)).getUint16(12),e={ethertype:d,dest:a.subarray(0,6),dest_s:Bb(a.subarray(0,6)),src:a.subarray(6,12),src_s:Bb(a.subarray(6,12))};c.eth=e;a=
@@ -209,25 +209,25 @@ a));return}}else if(0>b){C(`TCP[${this.tuple}]: ERROR: ack underflow (pkt=${a.tc
209
209
  a=this.packet_reply(a,{ack:!0}),this.net.receive(Qb(this.net.eth_encoder_buf,a))):a.tcp.ack&&0<a.tcp_data.length&&(this.ack+=a.tcp_data.length,b=this.ipv4_reply(),this.net.receive(Qb(this.net.eth_encoder_buf,b)),this.emit("data",a.tcp_data));this.pump()}};Wb.prototype.write=function(a){this.in_active_close||this.send_buffer.write(a);this.pump()};Wb.prototype.writev=function(a){if(!this.in_active_close)for(const b of a)this.send_buffer.write(b);this.pump()};Wb.prototype.close=function(){if(!this.in_active_close){this.in_active_close=
210
210
  !0;if("established"===this.state||"syn-received"===this.state)var a="fin-wait-1";else if("close-wait"===this.state)a="last-ack";else{"syn-sent"!==this.state&&C(`TCP[${this.tuple}]: active close in unexpected state "${this.state}"`,16777216);this.release();return}this.send_buffer.length||this.pending?(this.delayed_send_fin=!0,this.delayed_state=a):(this.state=a,a=this.ipv4_reply(),a.tcp.fin=!0,this.net.receive(Qb(this.net.eth_encoder_buf,a)))}this.pump()};Wb.prototype.on_shutdown=function(){this.emit("shutdown")};
211
211
  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||
212
- "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)=>
213
- 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,
214
- 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:");
212
+ "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=Eb();this.fetch=(...c)=>
213
+ 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",Zb);c.tuple=b;c.accept(a);this.tcp_conn[b]=c;return!0}return!1};Yb.prototype.connect=function(a){return Vb(a,
214
+ this)};Yb.prototype.tcp_probe=function(a){return Xb(a,this)};async function Zb(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:");
215
215
  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=
216
216
  "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=
217
217
  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=>
218
218
  {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"})},
219
219
  (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=
220
220
  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"+
221
- 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,
222
- 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://",
223
- "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=
221
+ this.id+"-receive",new Uint8Array(a))};function $b(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,
222
+ 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=Eb();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)}$b.prototype.register_ws=function(a){this.wispws=new WebSocket(a.replace("wisp://","ws://").replace("wisps://",
223
+ "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)}};$b.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})))};$b.prototype.process_incoming_wisp_frame=function(a){const b=
224
224
  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]&&
225
- 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]=
226
- {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=
227
- 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",
228
- 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)||
229
- !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"===
230
- 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=
225
+ 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)}};$b.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]=
226
+ {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)};$b.prototype.destroy=
227
+ function(){this.wispws&&(this.wispws.onmessage=null,this.wispws.onclose=null,this.wispws.close(),this.wispws=null)};$b.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",
228
+ 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};$b.prototype.send=function(a){Tb(a,this)};$b.prototype.receive=function(a){this.bus.send("net"+this.id+"-receive",new Uint8Array(a))};const ac="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)||
229
+ !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,L=0;L<w.length;L++)F=+w[L],n[F]&&l(F,!1);n={}}function f(w,F){if(v.bus&&b(w)){w.preventDefault&&w.preventDefault();if(ac&&(q&&(clearTimeout(t),w.getModifierState&&w.getModifierState("AltGraph")&&r===F&&"ControlLeft"===
230
+ 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 L=B[w.code];if(void 0!==L)break a}L=y[w.keyCode]}L?l(L,F,w.repeat):console.log("Missing char in map: keyCode="+(w.keyCode||-1).toString(16)+" code="+w.code)}function l(w,F,L){if(F)n[w]&&!L&&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=
231
231
  {},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,
232
232
  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,
233
233
  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,
@@ -247,9 +247,9 @@ this.update_timer=void 0),this.last_update=l,this.render())};this.render=functio
247
247
  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,
248
248
  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))?
249
249
  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)}})})};
250
- 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++]=
251
- 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=
252
- 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;
250
+ 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 J(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++]=
251
+ 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":J(["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 K(a,b,c){let d=c.offset;for(var e=[],f=0;f<a.length;f++)switch(a[f]){case "w":var h=
252
+ 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=K(["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;
253
253
  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=
254
254
  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=
255
255
  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;
@@ -282,8 +282,8 @@ k(0<=a&&a<this.inodes.length,"Filesystem GetInode: out of range idx:"+a);a=this.
282
282
  e=b.length;c.GetRecursiveList(this.inodes[a].foreign_id,b);for(a=e;a<b.length;a++)b[a].parentid=this.get_forwarder(d,b[a].parentid)}else for(const [c,d]of this.inodes[a].direntries)"."!==c&&".."!==c&&(b.push({parentid:a,name:c}),this.IsDirectory(d)&&this.GetRecursiveList(d,b))};N.prototype.RecursiveDelete=function(a){var b=[];a=this.SearchPath(a);if(-1!==a.id)for(this.GetRecursiveList(a.id,b),a=b.length-1;0<=a;a--){const c=this.Unlink(b[a].parentid,b[a].name);k(0===c,"Filesystem RecursiveDelete failed at parent="+
283
283
  b[a].parentid+", name='"+b[a].name+"' with error code: "+-c)}};N.prototype.DeleteNode=function(a){var b=this.SearchPath(a);-1!==b.id&&(32768===(this.inodes[b.id].mode&61440)?(a=this.Unlink(b.parentid,b.name),k(0===a,"Filesystem DeleteNode failed with error code: "+-a)):16384===(this.inodes[b.id].mode&61440)&&(this.RecursiveDelete(a),a=this.Unlink(b.parentid,b.name),k(0===a,"Filesystem DeleteNode failed with error code: "+-a)))};N.prototype.NotifyListeners=function(){};N.prototype.Check=function(){for(var a=
284
284
  1;a<this.inodes.length;a++)if(-1!==this.inodes[a].status){var b=this.GetInode(a);0>b.nlinks&&C("Error in filesystem: negative nlinks="+b.nlinks+" at id ="+a,4194304);if(this.IsDirectory(a)){b=this.GetInode(a);this.IsDirectory(a)&&0>this.GetParent(a)&&C("Error in filesystem: negative parent id "+a,4194304);for(const [c,d]of b.direntries){0===c.length&&C("Error in filesystem: inode with no name and id "+d,4194304);for(const e of c)32>e&&C("Error in filesystem: Unallowed char in filename",4194304)}}}};
285
- N.prototype.FillDirectory=function(a){var b=this.inodes[a];if(this.is_forwarder(b))this.follow_fs(b).FillDirectory(b.foreign_id);else{var c=0;for(const d of b.direntries.keys())c+=24+rc.encode(d).length;a=this.inodedata[a]=new Uint8Array(c);b.size=c;c=0;for(const [d,e]of b.direntries)b=this.GetInode(e),c+=K(["Q","d","b","s"],[b.qid,c+13+8+1+2+rc.encode(d).length,b.mode>>12,d],a,c)}};N.prototype.RoundToDirentry=function(a,b){const c=this.inodedata[a];k(c,`FS directory data for dirid=${a} should be generated`);
286
- k(c.length,"FS directory should have at least an entry");if(b>=c.length)return c.length;for(a=0;;){const d=M(["Q","d"],c,{offset:a})[1];if(d>b)break;a=d}return a};N.prototype.IsDirectory=function(a){a=this.inodes[a];return this.is_forwarder(a)?this.follow_fs(a).IsDirectory(a.foreign_id):16384===(a.mode&61440)};N.prototype.IsEmpty=function(a){a=this.inodes[a];if(this.is_forwarder(a))return this.follow_fs(a).IsDirectory(a.foreign_id);for(const b of a.direntries.keys())if("."!==b&&".."!==b)return!1;
285
+ N.prototype.FillDirectory=function(a){var b=this.inodes[a];if(this.is_forwarder(b))this.follow_fs(b).FillDirectory(b.foreign_id);else{var c=0;for(const d of b.direntries.keys())c+=24+rc.encode(d).length;a=this.inodedata[a]=new Uint8Array(c);b.size=c;c=0;for(const [d,e]of b.direntries)b=this.GetInode(e),c+=J(["Q","d","b","s"],[b.qid,c+13+8+1+2+rc.encode(d).length,b.mode>>12,d],a,c)}};N.prototype.RoundToDirentry=function(a,b){const c=this.inodedata[a];k(c,`FS directory data for dirid=${a} should be generated`);
286
+ k(c.length,"FS directory should have at least an entry");if(b>=c.length)return c.length;for(a=0;;){const d=K(["Q","d"],c,{offset:a})[1];if(d>b)break;a=d}return a};N.prototype.IsDirectory=function(a){a=this.inodes[a];return this.is_forwarder(a)?this.follow_fs(a).IsDirectory(a.foreign_id):16384===(a.mode&61440)};N.prototype.IsEmpty=function(a){a=this.inodes[a];if(this.is_forwarder(a))return this.follow_fs(a).IsDirectory(a.foreign_id);for(const b of a.direntries.keys())if("."!==b&&".."!==b)return!1;
287
287
  return!0};N.prototype.GetChildren=function(a){k(this.IsDirectory(a),"Filesystem: cannot get children of non-directory inode");a=this.inodes[a];if(this.is_forwarder(a))return this.follow_fs(a).GetChildren(a.foreign_id);const b=[];for(const c of a.direntries.keys())"."!==c&&".."!==c&&b.push(c);return b};N.prototype.GetParent=function(a){k(this.IsDirectory(a),"Filesystem: cannot get parent of non-directory inode");a=this.inodes[a];if(this.should_be_linked(a))return a.direntries.get("..");const b=this.follow_fs(a).GetParent(a.foreign_id);
288
288
  k(-1!==b,"Filesystem: should not have invalid parent ids");return this.get_forwarder(a.mount_id,b)};N.prototype.PrepareCAPs=function(a){a=this.GetInode(a);if(a.caps)return a.caps.length;a.caps=new Uint8Array(20);a.caps[0]=0;a.caps[1]=0;a.caps[2]=0;a.caps[3]=2;a.caps[4]=255;a.caps[5]=255;a.caps[6]=255;a.caps[7]=255;a.caps[8]=255;a.caps[9]=255;a.caps[10]=255;a.caps[11]=255;a.caps[12]=63;a.caps[13]=0;a.caps[14]=0;a.caps[15]=0;a.caps[16]=63;a.caps[17]=0;a.caps[18]=0;a.caps[19]=0;return a.caps.length};
289
289
  function uc(a){this.fs=a;this.backtrack=new Map}uc.prototype.get_state=function(){const a=[];a[0]=this.fs;a[1]=[...this.backtrack];return a};uc.prototype.set_state=function(a){this.fs=a[0];this.backtrack=new Map(a[1])};N.prototype.set_forwarder=function(a,b,c){const d=this.inodes[a];k(0===d.nlinks,"Filesystem: attempted to convert an inode into forwarder before unlinking the inode");this.is_forwarder(d)&&this.mounts[d.mount_id].backtrack.delete(d.foreign_id);d.status=5;d.mount_id=b;d.foreign_id=c;
@@ -306,7 +306,7 @@ v;break;case "fda":e.fda=this.disk_images.fda=v;break;case "fdb":e.fdb=this.disk
306
306
  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,
307
307
  "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()},
308
308
  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=
309
- 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,
309
+ 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 $b(f,this.bus,b.net_device):this.network_adapter=new rb(f,
310
310
  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&&
311
311
  (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'?");
312
312
  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,
@@ -319,15 +319,16 @@ new Worker(c);URL.revokeObjectURL(c);this.zstd_worker.postMessage(this.wasm_sour
319
319
  []).map(e=>"/"+e);a=(a.read_dir("/boot/")||[]).map(e=>"/boot/"+e);let c,d;for(const e of[].concat(b,a)){const f=/old/i.test(e)||/fallback/i.test(e),h=/vmlinuz/i.test(e)||/bzimage/i.test(e),l=/initrd/i.test(e)||/initramfs/i.test(e);!h||d&&f||(d=e);!l||c&&f||(c=e)}c&&d||(console.log("Failed to find bzimage or initrd in filesystem. Files:"),console.log(b.join(" ")),console.log(a.join(" ")));return{initrd_path:c,bzimage_path:d}};O.prototype.run=async function(){this.v86.run()};O.prototype.stop=async function(){this.cpu_is_running&&
320
320
  await new Promise(a=>{const b=()=>{this.remove_listener("emulator-stopped",b);a()};this.add_listener("emulator-stopped",b);this.v86.stop()})};O.prototype.destroy=async function(){await this.stop();this.v86.destroy();this.keyboard_adapter&&this.keyboard_adapter.destroy();this.network_adapter&&this.network_adapter.destroy();this.mouse_adapter&&this.mouse_adapter.destroy();this.screen_adapter&&this.screen_adapter.destroy();this.serial_adapter&&this.serial_adapter.destroy();this.speaker_adapter&&this.speaker_adapter.destroy()};
321
321
  O.prototype.restart=function(){this.v86.restart()};O.prototype.add_listener=function(a,b){this.bus.register(a,b,this)};O.prototype.remove_listener=function(a,b){this.bus.unregister(a,b)};O.prototype.restore_state=async function(a){k(1===arguments.length);this.v86.restore_state(a)};O.prototype.save_state=async function(){k(0===arguments.length);return this.v86.save_state()};O.prototype.get_instruction_counter=function(){return this.v86?this.v86.cpu.instruction_counter[0]>>>0:0};O.prototype.is_running=
322
- function(){return this.cpu_is_running};O.prototype.set_fda=async function(a){if(a.url&&!a.async)sa(a.url,{done:b=>{this.v86.cpu.devices.fdc.set_fda(new ya(b))}});else{const b=Da(a,this.zstd_decompress_worker.bind(this));b.onload=()=>{this.v86.cpu.devices.fdc.set_fda(b)};await b.load()}};O.prototype.eject_fda=function(){this.v86.cpu.devices.fdc.eject_fda()};O.prototype.keyboard_send_scancodes=function(a){for(var b=0;b<a.length;b++)this.bus.send("keyboard-code",a[b])};O.prototype.keyboard_send_keys=
323
- function(a){for(var b=0;b<a.length;b++)this.keyboard_adapter.simulate_press(a[b])};O.prototype.keyboard_send_text=function(a){for(var b=0;b<a.length;b++)this.keyboard_adapter.simulate_char(a[b])};O.prototype.screen_make_screenshot=function(){return this.screen_adapter?this.screen_adapter.make_screenshot():null};O.prototype.screen_set_scale=function(a,b){this.screen_adapter&&this.screen_adapter.set_scale(a,b)};O.prototype.screen_go_fullscreen=function(){if(this.screen_adapter){var a=document.getElementById("screen_container");
324
- if(a){var b=a.requestFullScreen||a.webkitRequestFullscreen||a.mozRequestFullScreen||a.msRequestFullScreen;b&&(b.call(a),(a=document.getElementsByClassName("phone_keyboard")[0])&&a.focus());try{navigator.keyboard.lock()}catch(c){}this.lock_mouse()}}};O.prototype.lock_mouse=function(){var a=document.body,b=a.requestPointerLock||a.mozRequestPointerLock||a.webkitRequestPointerLock;b&&b.call(a)};O.prototype.mouse_set_status=function(a){this.mouse_adapter&&(this.mouse_adapter.emu_enabled=a)};O.prototype.keyboard_set_status=
325
- function(a){this.keyboard_adapter&&(this.keyboard_adapter.emu_enabled=a)};O.prototype.serial0_send=function(a){for(var b=0;b<a.length;b++)this.bus.send("serial0-input",a.charCodeAt(b))};O.prototype.serial_send_bytes=function(a,b){for(var c=0;c<b.length;c++)this.bus.send("serial"+a+"-input",b[c])};O.prototype.serial_set_modem_status=function(a,b){this.bus.send("serial"+a+"-modem-status-input",b)};O.prototype.serial_set_carrier_detect=function(a,b){this.bus.send("serial"+a+"-carrier-detect-input",b)};
326
- O.prototype.serial_set_ring_indicator=function(a,b){this.bus.send("serial"+a+"-ring-indicator-input",b)};O.prototype.serial_set_data_set_ready=function(a,b){this.bus.send("serial"+a+"-data-set-ready-input",b)};O.prototype.serial_set_clear_to_send=function(a,b){this.bus.send("serial"+a+"-clear-to-send-input",b)};O.prototype.mount_fs=async function(a,b,c){var d=new nc;b&&(d=new oc(d,b));d=new N(d,this.fs9p.qidcounter);b&&(k("object"===typeof c,"Filesystem: basefs must be a JSON object"),d.load_from_json(c));
327
- a=this.fs9p.Mount(a,d);if(-2===a)throw new vc;if(-17===a)throw new wc;if(0>a)throw k(!1,"Unexpected error code: "+-a),Error("Failed to mount. Error number: "+-a);};O.prototype.create_file=async function(a,b){k(2===arguments.length);var c=this.fs9p;if(c){var d=a.split("/");d=d[d.length-1];var e=c.SearchPath(a).parentid;if(""!==d&&-1!==e)await c.CreateBinaryFile(d,e,b);else return Promise.reject(new vc)}};O.prototype.read_file=async function(a){k(1===arguments.length);var b=this.fs9p;if(b)return(b=
328
- await b.read_file(a))?b:Promise.reject(new vc)};O.prototype.automatically=function(a){const b=c=>{const d=c[0];if(d){var e=c.slice(1);d.sleep?setTimeout(()=>b(e),1E3*d.sleep):d.vga_text?this.wait_until_vga_screen_contains(d.vga_text).then(()=>b(e)):d.keyboard_send?(Array.isArray(d.keyboard_send)?this.keyboard_send_scancodes(d.keyboard_send):(k("string"===typeof d.keyboard_send),this.keyboard_send_text(d.keyboard_send)),b(e)):d.call?(d.call(),b(e)):k(!1,d)}};b(a)};O.prototype.wait_until_vga_screen_contains=
329
- function(a){return new Promise(b=>{function c(h){return"string"===typeof a?h.includes(a):a.test(h)}function d(h){[h]=h;e.add(h)}for(const h of this.screen_adapter.get_text_screen())if(c(h)){b(!0);return}const e=new Set,f=()=>{for(const h of e){const l=this.screen_adapter.get_text_row(h);if(c(l)){this.remove_listener("screen-put-char",d);b();return}}e.clear();setTimeout(f,100)};f();this.add_listener("screen-put-char",d)})};O.prototype.read_memory=function(a,b){return this.v86.cpu.read_blob(a,b)};O.prototype.write_memory=
330
- function(a,b){this.v86.cpu.write_blob(a,b)};O.prototype.set_serial_container_xtermjs=function(a){this.serial_adapter&&this.serial_adapter.destroy&&this.serial_adapter.destroy();this.serial_adapter=new lc(a,this.bus);this.serial_adapter.show()};O.prototype.get_instruction_stats=function(){var a=this.v86.cpu;var b="";var c="COMPILE COMPILE_SKIPPED_NO_NEW_ENTRY_POINTS COMPILE_WRONG_ADDRESS_SPACE COMPILE_CUT_OFF_AT_END_OF_PAGE COMPILE_WITH_LOOP_SAFETY COMPILE_PAGE COMPILE_PAGE/COMPILE COMPILE_BASIC_BLOCK COMPILE_DUPLICATED_BASIC_BLOCK COMPILE_WASM_BLOCK COMPILE_WASM_LOOP COMPILE_DISPATCHER COMPILE_ENTRY_POINT COMPILE_WASM_TOTAL_BYTES COMPILE_WASM_TOTAL_BYTES/COMPILE_PAGE RUN_INTERPRETED RUN_INTERPRETED_NEW_PAGE RUN_INTERPRETED_PAGE_HAS_CODE RUN_INTERPRETED_PAGE_HAS_ENTRY_AFTER_PAGE_WALK RUN_INTERPRETED_NEAR_END_OF_PAGE RUN_INTERPRETED_DIFFERENT_STATE RUN_INTERPRETED_DIFFERENT_STATE_CPL3 RUN_INTERPRETED_DIFFERENT_STATE_FLAT RUN_INTERPRETED_DIFFERENT_STATE_IS32 RUN_INTERPRETED_DIFFERENT_STATE_SS32 RUN_INTERPRETED_MISSED_COMPILED_ENTRY_RUN_INTERPRETED RUN_INTERPRETED_STEPS RUN_FROM_CACHE RUN_FROM_CACHE_STEPS RUN_FROM_CACHE_STEPS/RUN_FROM_CACHE RUN_FROM_CACHE_STEPS/RUN_INTERPRETED_STEPS DIRECT_EXIT INDIRECT_JUMP INDIRECT_JUMP_NO_ENTRY NORMAL_PAGE_CHANGE NORMAL_FALLTHRU NORMAL_FALLTHRU_WITH_TARGET_BLOCK NORMAL_BRANCH NORMAL_BRANCH_WITH_TARGET_BLOCK CONDITIONAL_JUMP CONDITIONAL_JUMP_PAGE_CHANGE CONDITIONAL_JUMP_EXIT CONDITIONAL_JUMP_FALLTHRU CONDITIONAL_JUMP_FALLTHRU_WITH_TARGET_BLOCK CONDITIONAL_JUMP_BRANCH CONDITIONAL_JUMP_BRANCH_WITH_TARGET_BLOCK DISPATCHER_SMALL DISPATCHER_LARGE LOOP LOOP_SAFETY CONDITION_OPTIMISED CONDITION_UNOPTIMISED CONDITION_UNOPTIMISED_PF CONDITION_UNOPTIMISED_UNHANDLED_L CONDITION_UNOPTIMISED_UNHANDLED_LE FAILED_PAGE_CHANGE SAFE_READ_FAST SAFE_READ_SLOW_PAGE_CROSSED SAFE_READ_SLOW_NOT_VALID SAFE_READ_SLOW_NOT_USER SAFE_READ_SLOW_IN_MAPPED_RANGE SAFE_WRITE_FAST SAFE_WRITE_SLOW_PAGE_CROSSED SAFE_WRITE_SLOW_NOT_VALID SAFE_WRITE_SLOW_NOT_USER SAFE_WRITE_SLOW_IN_MAPPED_RANGE SAFE_WRITE_SLOW_READ_ONLY SAFE_WRITE_SLOW_HAS_CODE SAFE_READ_WRITE_FAST SAFE_READ_WRITE_SLOW_PAGE_CROSSED SAFE_READ_WRITE_SLOW_NOT_VALID SAFE_READ_WRITE_SLOW_NOT_USER SAFE_READ_WRITE_SLOW_IN_MAPPED_RANGE SAFE_READ_WRITE_SLOW_READ_ONLY SAFE_READ_WRITE_SLOW_HAS_CODE PAGE_FAULT TLB_MISS MAIN_LOOP MAIN_LOOP_IDLE DO_MANY_CYCLES CYCLE_INTERNAL INVALIDATE_ALL_MODULES_NO_FREE_WASM_INDICES INVALIDATE_MODULE_WRITTEN_WHILE_COMPILED INVALIDATE_MODULE_UNUSED_AFTER_OVERWRITE INVALIDATE_MODULE_DIRTY_PAGE INVALIDATE_PAGE_HAD_CODE INVALIDATE_PAGE_HAD_ENTRY_POINTS DIRTY_PAGE_DID_NOT_HAVE_CODE RUN_FROM_CACHE_EXIT_SAME_PAGE RUN_FROM_CACHE_EXIT_NEAR_END_OF_PAGE RUN_FROM_CACHE_EXIT_DIFFERENT_PAGE CLEAR_TLB FULL_CLEAR_TLB TLB_FULL TLB_GLOBAL_FULL MODRM_SIMPLE_REG MODRM_SIMPLE_REG_WITH_OFFSET MODRM_SIMPLE_CONST_OFFSET MODRM_COMPLEX SEG_OFFSET_OPTIMISED SEG_OFFSET_NOT_OPTIMISED SEG_OFFSET_NOT_OPTIMISED_ES SEG_OFFSET_NOT_OPTIMISED_FS SEG_OFFSET_NOT_OPTIMISED_GS SEG_OFFSET_NOT_OPTIMISED_NOT_FLAT".split(" "),
322
+ function(){return this.cpu_is_running};O.prototype.set_fda=async function(a){if(a.url&&!a.async)sa(a.url,{done:b=>{this.v86.cpu.devices.fdc.set_fda(new ya(b))}});else{const b=Da(a,this.zstd_decompress_worker.bind(this));b.onload=()=>{this.v86.cpu.devices.fdc.set_fda(b)};await b.load()}};O.prototype.eject_fda=function(){this.v86.cpu.devices.fdc.eject_fda()};O.prototype.set_cdrom=async function(a){if(a.url&&!a.async)sa(a.url,{done:b=>{this.v86.cpu.devices.cdrom.set_cdrom(new ya(b))}});else{const b=
323
+ Da(a,this.zstd_decompress_worker.bind(this));b.onload=()=>{this.v86.cpu.devices.cdrom.set_cdrom(b)};await b.load()}};O.prototype.eject_cdrom=function(){this.v86.cpu.devices.cdrom.eject()};O.prototype.keyboard_send_scancodes=function(a){for(var b=0;b<a.length;b++)this.bus.send("keyboard-code",a[b])};O.prototype.keyboard_send_keys=function(a){for(var b=0;b<a.length;b++)this.keyboard_adapter.simulate_press(a[b])};O.prototype.keyboard_send_text=function(a){for(var b=0;b<a.length;b++)this.keyboard_adapter.simulate_char(a[b])};
324
+ O.prototype.screen_make_screenshot=function(){return this.screen_adapter?this.screen_adapter.make_screenshot():null};O.prototype.screen_set_scale=function(a,b){this.screen_adapter&&this.screen_adapter.set_scale(a,b)};O.prototype.screen_go_fullscreen=function(){if(this.screen_adapter){var a=document.getElementById("screen_container");if(a){var b=a.requestFullScreen||a.webkitRequestFullscreen||a.mozRequestFullScreen||a.msRequestFullScreen;b&&(b.call(a),(a=document.getElementsByClassName("phone_keyboard")[0])&&
325
+ a.focus());try{navigator.keyboard.lock()}catch(c){}this.lock_mouse()}}};O.prototype.lock_mouse=function(){var a=document.body,b=a.requestPointerLock||a.mozRequestPointerLock||a.webkitRequestPointerLock;b&&b.call(a)};O.prototype.mouse_set_status=function(a){this.mouse_adapter&&(this.mouse_adapter.emu_enabled=a)};O.prototype.keyboard_set_status=function(a){this.keyboard_adapter&&(this.keyboard_adapter.emu_enabled=a)};O.prototype.serial0_send=function(a){for(var b=0;b<a.length;b++)this.bus.send("serial0-input",
326
+ a.charCodeAt(b))};O.prototype.serial_send_bytes=function(a,b){for(var c=0;c<b.length;c++)this.bus.send("serial"+a+"-input",b[c])};O.prototype.serial_set_modem_status=function(a,b){this.bus.send("serial"+a+"-modem-status-input",b)};O.prototype.serial_set_carrier_detect=function(a,b){this.bus.send("serial"+a+"-carrier-detect-input",b)};O.prototype.serial_set_ring_indicator=function(a,b){this.bus.send("serial"+a+"-ring-indicator-input",b)};O.prototype.serial_set_data_set_ready=function(a,b){this.bus.send("serial"+
327
+ a+"-data-set-ready-input",b)};O.prototype.serial_set_clear_to_send=function(a,b){this.bus.send("serial"+a+"-clear-to-send-input",b)};O.prototype.mount_fs=async function(a,b,c){var d=new nc;b&&(d=new oc(d,b));d=new N(d,this.fs9p.qidcounter);b&&(k("object"===typeof c,"Filesystem: basefs must be a JSON object"),d.load_from_json(c));a=this.fs9p.Mount(a,d);if(-2===a)throw new vc;if(-17===a)throw new wc;if(0>a)throw k(!1,"Unexpected error code: "+-a),Error("Failed to mount. Error number: "+-a);};O.prototype.create_file=
328
+ async function(a,b){k(2===arguments.length);var c=this.fs9p;if(c){var d=a.split("/");d=d[d.length-1];var e=c.SearchPath(a).parentid;if(""!==d&&-1!==e)await c.CreateBinaryFile(d,e,b);else return Promise.reject(new vc)}};O.prototype.read_file=async function(a){k(1===arguments.length);var b=this.fs9p;if(b)return(b=await b.read_file(a))?b:Promise.reject(new vc)};O.prototype.automatically=function(a){const b=c=>{const d=c[0];if(d){var e=c.slice(1);d.sleep?setTimeout(()=>b(e),1E3*d.sleep):d.vga_text?this.wait_until_vga_screen_contains(d.vga_text).then(()=>
329
+ b(e)):d.keyboard_send?(Array.isArray(d.keyboard_send)?this.keyboard_send_scancodes(d.keyboard_send):(k("string"===typeof d.keyboard_send),this.keyboard_send_text(d.keyboard_send)),b(e)):d.call?(d.call(),b(e)):k(!1,d)}};b(a)};O.prototype.wait_until_vga_screen_contains=function(a){return new Promise(b=>{function c(h){return"string"===typeof a?h.includes(a):a.test(h)}function d(h){[h]=h;e.add(h)}for(const h of this.screen_adapter.get_text_screen())if(c(h)){b(!0);return}const e=new Set,f=()=>{for(const h of e){const l=
330
+ this.screen_adapter.get_text_row(h);if(c(l)){this.remove_listener("screen-put-char",d);b();return}}e.clear();setTimeout(f,100)};f();this.add_listener("screen-put-char",d)})};O.prototype.read_memory=function(a,b){return this.v86.cpu.read_blob(a,b)};O.prototype.write_memory=function(a,b){this.v86.cpu.write_blob(a,b)};O.prototype.set_serial_container_xtermjs=function(a){this.serial_adapter&&this.serial_adapter.destroy&&this.serial_adapter.destroy();this.serial_adapter=new lc(a,this.bus);this.serial_adapter.show()};
331
+ O.prototype.get_instruction_stats=function(){var a=this.v86.cpu;var b="";var c="COMPILE COMPILE_SKIPPED_NO_NEW_ENTRY_POINTS COMPILE_WRONG_ADDRESS_SPACE COMPILE_CUT_OFF_AT_END_OF_PAGE COMPILE_WITH_LOOP_SAFETY COMPILE_PAGE COMPILE_PAGE/COMPILE COMPILE_BASIC_BLOCK COMPILE_DUPLICATED_BASIC_BLOCK COMPILE_WASM_BLOCK COMPILE_WASM_LOOP COMPILE_DISPATCHER COMPILE_ENTRY_POINT COMPILE_WASM_TOTAL_BYTES COMPILE_WASM_TOTAL_BYTES/COMPILE_PAGE RUN_INTERPRETED RUN_INTERPRETED_NEW_PAGE RUN_INTERPRETED_PAGE_HAS_CODE RUN_INTERPRETED_PAGE_HAS_ENTRY_AFTER_PAGE_WALK RUN_INTERPRETED_NEAR_END_OF_PAGE RUN_INTERPRETED_DIFFERENT_STATE RUN_INTERPRETED_DIFFERENT_STATE_CPL3 RUN_INTERPRETED_DIFFERENT_STATE_FLAT RUN_INTERPRETED_DIFFERENT_STATE_IS32 RUN_INTERPRETED_DIFFERENT_STATE_SS32 RUN_INTERPRETED_MISSED_COMPILED_ENTRY_RUN_INTERPRETED RUN_INTERPRETED_STEPS RUN_FROM_CACHE RUN_FROM_CACHE_STEPS RUN_FROM_CACHE_STEPS/RUN_FROM_CACHE RUN_FROM_CACHE_STEPS/RUN_INTERPRETED_STEPS DIRECT_EXIT INDIRECT_JUMP INDIRECT_JUMP_NO_ENTRY NORMAL_PAGE_CHANGE NORMAL_FALLTHRU NORMAL_FALLTHRU_WITH_TARGET_BLOCK NORMAL_BRANCH NORMAL_BRANCH_WITH_TARGET_BLOCK CONDITIONAL_JUMP CONDITIONAL_JUMP_PAGE_CHANGE CONDITIONAL_JUMP_EXIT CONDITIONAL_JUMP_FALLTHRU CONDITIONAL_JUMP_FALLTHRU_WITH_TARGET_BLOCK CONDITIONAL_JUMP_BRANCH CONDITIONAL_JUMP_BRANCH_WITH_TARGET_BLOCK DISPATCHER_SMALL DISPATCHER_LARGE LOOP LOOP_SAFETY CONDITION_OPTIMISED CONDITION_UNOPTIMISED CONDITION_UNOPTIMISED_PF CONDITION_UNOPTIMISED_UNHANDLED_L CONDITION_UNOPTIMISED_UNHANDLED_LE FAILED_PAGE_CHANGE SAFE_READ_FAST SAFE_READ_SLOW_PAGE_CROSSED SAFE_READ_SLOW_NOT_VALID SAFE_READ_SLOW_NOT_USER SAFE_READ_SLOW_IN_MAPPED_RANGE SAFE_WRITE_FAST SAFE_WRITE_SLOW_PAGE_CROSSED SAFE_WRITE_SLOW_NOT_VALID SAFE_WRITE_SLOW_NOT_USER SAFE_WRITE_SLOW_IN_MAPPED_RANGE SAFE_WRITE_SLOW_READ_ONLY SAFE_WRITE_SLOW_HAS_CODE SAFE_READ_WRITE_FAST SAFE_READ_WRITE_SLOW_PAGE_CROSSED SAFE_READ_WRITE_SLOW_NOT_VALID SAFE_READ_WRITE_SLOW_NOT_USER SAFE_READ_WRITE_SLOW_IN_MAPPED_RANGE SAFE_READ_WRITE_SLOW_READ_ONLY SAFE_READ_WRITE_SLOW_HAS_CODE PAGE_FAULT TLB_MISS MAIN_LOOP MAIN_LOOP_IDLE DO_MANY_CYCLES CYCLE_INTERNAL INVALIDATE_ALL_MODULES_NO_FREE_WASM_INDICES INVALIDATE_MODULE_WRITTEN_WHILE_COMPILED INVALIDATE_MODULE_UNUSED_AFTER_OVERWRITE INVALIDATE_MODULE_DIRTY_PAGE INVALIDATE_PAGE_HAD_CODE INVALIDATE_PAGE_HAD_ENTRY_POINTS DIRTY_PAGE_DID_NOT_HAVE_CODE RUN_FROM_CACHE_EXIT_SAME_PAGE RUN_FROM_CACHE_EXIT_NEAR_END_OF_PAGE RUN_FROM_CACHE_EXIT_DIFFERENT_PAGE CLEAR_TLB FULL_CLEAR_TLB TLB_FULL TLB_GLOBAL_FULL MODRM_SIMPLE_REG MODRM_SIMPLE_REG_WITH_OFFSET MODRM_SIMPLE_CONST_OFFSET MODRM_COMPLEX SEG_OFFSET_OPTIMISED SEG_OFFSET_NOT_OPTIMISED SEG_OFFSET_NOT_OPTIMISED_ES SEG_OFFSET_NOT_OPTIMISED_FS SEG_OFFSET_NOT_OPTIMISED_GS SEG_OFFSET_NOT_OPTIMISED_NOT_FLAT".split(" "),
331
332
  d=0;const e={};for(let h=0;h<c.length;h++){const l=c[h];var f=void 0;if(l.includes("/")){d++;const [p,n]=l.split("/");f=e[p]/e[n]}else f=e[l]=a.wm.exports.profiler_stat_get(h-d),f=1E8<=f?Math.round(f/1E6)+"m":1E5<=f?Math.round(f/1E3)+"k":f;b+=l+"="+f+"\n"}b+="\n";c=a.wm.exports.get_valid_tlb_entries_count();d=a.wm.exports.get_valid_global_tlb_entries_count();b=b+("TLB_ENTRIES="+c+" ("+d+" global, "+(c-d)+" non-global)\nWASM_TABLE_FREE=")+(a.wm.exports.jit_get_wasm_table_index_free_list_count()+"\n");
332
333
  b+="JIT_CACHE_SIZE="+a.wm.exports.jit_get_cache_size()+"\n";b+="FLAT_SEGMENTS="+a.wm.exports.has_flat_segmentation()+"\n";b+="wasm memory size: "+(a.wasm_memory.buffer.byteLength>>20)+"m\n";b=b+"Config:\nJIT_DISABLED="+(a.wm.exports.get_jit_config(0)+"\n");b+="MAX_PAGES="+a.wm.exports.get_jit_config(1)+"\n";b+="JIT_USE_LOOP_SAFETY="+!!a.wm.exports.get_jit_config(2)+"\n";b+="MAX_EXTRA_BASIC_BLOCKS="+a.wm.exports.get_jit_config(3)+"\n";a=[gb(a,!1,!1,!1,!1),gb(a,!0,!1,!1,!1),gb(a,!1,!0,!1,!1),gb(a,!1,
333
334
  !1,!0,!1),gb(a,!1,!1,!1,!0)].join("\n\n");return b+a};function wc(a){this.message=a||"File already exists"}wc.prototype=Error.prototype;function vc(a){this.message=a||"File not found"}vc.prototype=Error.prototype;"undefined"!==typeof module&&"undefined"!==typeof module.exports?module.exports.V86=O:"undefined"!==typeof window?window.V86=O:"function"===typeof importScripts&&(self.V86=O);function I(a,b){this.stopping=this.running=!1;this.idle=!0;this.tick_counter=0;this.worker=null;this.cpu=new P(a,
@@ -382,30 +383,29 @@ c},function(c){this.pci_addr[2]=c},function(c){this.pci_addr[3]=c;this.pci_query
382
383
  d[4+e];if(f&1){var h=c.pci_bars[e];this.set_io_bars(h,h.original_bar&65534,f&65534)}}this.device_spaces[b].set(d)}else c&&C("Warning: While restoring PCI device: Device exists in current configuration but not in snapshot ("+c.name+")"),d&&C("Warning: While restoring PCI device: Device doesn't exist in current configuration but does in snapshot (device "+m(b,2)+")")}this.pci_addr.set(a[256]);this.pci_value.set(a[257]);this.pci_response.set(a[258]);this.pci_status.set(a[259])};Dc.prototype.pci_query=
383
384
  function(){var a=this.pci_addr[2]<<8|this.pci_addr[1],b=this.pci_addr[0]&252,c=a>>3&31;var d="query enabled="+(this.pci_addr[3]>>7)+(" bdf="+m(a,4));d+=" dev="+m(c,2);d+=" addr="+m(b,2);c=this.device_spaces[a];void 0!==c?(this.pci_status32[0]=-2147483648,this.pci_response32[0]=b<c.byteLength?c[b>>2]:0,d+=" "+m(this.pci_addr32[0]>>>0,8)+" -> "+m(this.pci_response32[0]>>>0,8),b>=c.byteLength&&(d+=" (undef)"),d+=" ("+this.devices[a].name+")",C(d,2048)):(this.pci_response32[0]=-1,this.pci_status32[0]=
384
385
  0)};Dc.prototype.pci_write8=function(a,b){var c=a>>8&65535;a&=255;var d=new Uint8Array(this.device_spaces[c].buffer),e=this.devices[c];d&&(k(!(16<=a&&44>a||48<=a&&52>a),"PCI: Expected 32-bit write, got 8-bit (addr: "+m(a)+")"),C("PCI write8 dev="+m(c>>3,2)+" ("+e.name+") addr="+m(a,4)+" value="+m(b,2),2048),d[a]=b)};Dc.prototype.pci_write16=function(a,b){k(0===(a&1));var c=a>>8&65535;a&=255;var d=new Uint16Array(this.device_spaces[c].buffer),e=this.devices[c];d&&(16<=a&&44>a?C("Warning: PCI: Expected 32-bit write, got 16-bit (addr: "+
385
- m(a)+")"):(k(!(48<=a&&52>a),"PCI: Expected 32-bit write, got 16-bit (addr: "+m(a)+")"),C("PCI writ16 dev="+m(c>>3,2)+" ("+e.name+") addr="+m(a,4)+" value="+m(b,4),2048),d[a>>>1]=b))};Dc.prototype.pci_write32=function(a,b){k(0===(a&3));var c=a>>8&65535;a&=255;var d=this.device_spaces[c],e=this.devices[c];if(d)if(16<=a&&40>a){var f=a-16>>2,h=e.pci_bars[f];C("BAR"+f+" exists="+(h?"y":"n")+" changed to "+m(b>>>0)+" dev="+m(c>>3,2)+" ("+e.name+") ",2048);h?(k(!(h.size&h.size-1),"bar size should be power of 2"),
386
+ m(a)+")"):(k(!(48<=a&&52>a),"PCI: Expected 32-bit write, got 16-bit (addr: "+m(a)+")"),C("PCI writ16 dev="+m(c>>3,2)+" ("+e.name+") addr="+m(a,4)+" value="+m(b,4),2048),d[a>>>1]=b))};Dc.prototype.pci_write32=function(a,b){k(0===(a&3));var c=a>>8&65535;a&=255;var d=this.device_spaces[c],e=this.devices[c];if(d)if(16<=a&&40>a){var f=a-16>>2,h=e.pci_bars[f];C("BAR"+f+" exists="+(h?"y":"n")+" changed from "+m(d[a>>2])+" to "+m(b>>>0)+" dev="+m(c>>3,2)+" ("+e.name+") ",2048);h?(k(!(h.size&h.size-1),"bar size should be power of 2"),
386
387
  c=a>>2,e=d[c]&1,-1===(b|3|h.size-1)?(b=~(h.size-1)|e,0===e&&(d[c]=b)):0===e&&(f=h.original_bar,(b&-16)!==(f&-16)&&C("Warning: Changing memory bar not supported, ignored",2048),d[c]=f),1===e&&(k(1===e),e=d[c]&65534,f=b&65534,C("io bar changed from "+m(e>>>0,8)+" to "+m(f>>>0,8)+" size="+h.size,2048),this.set_io_bars(h,e,f),d[c]=b|1)):d[a>>2]=0;C("BAR effective value: "+m(d[a>>2]>>>0),2048)}else 48===a?(C("PCI write rom address dev="+m(c>>3,2)+" ("+e.name+") value="+m(b>>>0,8),2048),d[a>>2]=e.pci_rom_size?
387
- -1===(b|2047)?-e.pci_rom_size|0:e.pci_rom_address|0:0):4===a?C("PCI write dev="+m(c>>3,2)+" ("+e.name+") addr="+m(a,4)+" value="+m(b>>>0,8),2048):(C("PCI write dev="+m(c>>3,2)+" ("+e.name+") addr="+m(a,4)+" value="+m(b>>>0,8),2048),d[a>>>2]=b)};Dc.prototype.register_device=function(a){k(void 0!==a.pci_id);k(void 0!==a.pci_space);k(void 0!==a.pci_bars);var b=a.pci_id;C("PCI register bdf="+m(b)+" ("+a.name+")",2048);k(!this.devices[b]);k(64<=a.pci_space.length);k(b<this.devices.length);var c=new Int32Array(64);
388
- c.set(new Int32Array((new Uint8Array(a.pci_space)).buffer));this.device_spaces[b]=c;this.devices[b]=a;b=c.slice(4,10);for(var d=0;d<a.pci_bars.length;d++){var e=a.pci_bars[d];if(e){var f=b[d],h=f&1;e.original_bar=f;e.entries=[];if(0!==h)for(k(1===h),f&=-2,h=0;h<e.size;h++)e.entries[h]=this.io.ports[f+h]}}return c};Dc.prototype.set_io_bars=function(a,b,c){var d=a.size;C("Move io bars: from="+m(b)+" to="+m(c)+" count="+d,2048);for(var e=this.io.ports,f=0;f<d;f++){var h=e[b+f];4096<=b+f&&(e[b+f]=this.io.create_empty_entry());
389
- h.read8===this.io.empty_port_read8&&h.read16===this.io.empty_port_read16&&h.read32===this.io.empty_port_read32&&h.write8===this.io.empty_port_write&&h.write16===this.io.empty_port_write&&h.write32===this.io.empty_port_write&&C("Warning: Bad IO bar: Source not mapped, port="+m(b+f,4),2048);h=a.entries[f];var l=e[c+f];k(h&&l);4096<=c+f&&(e[c+f]=h);l.read8!==this.io.empty_port_read8&&l.read16!==this.io.empty_port_read16&&l.read32!==this.io.empty_port_read32&&l.write8!==this.io.empty_port_write&&l.write16!==
390
- this.io.empty_port_write&&l.write32!==this.io.empty_port_write||C("Warning: Bad IO bar: Target already mapped, port="+m(c+f,4),2048)}};Dc.prototype.raise_irq=function(a){var b=this.device_spaces[a];k(b);this.cpu.device_raise_irq(this.isa_bridge_space8[96+((b[15]>>8&255)-1+((a>>3)-1&255)&3)])};Dc.prototype.lower_irq=function(a){var b=this.device_spaces[a];k(b);this.cpu.device_lower_irq(this.isa_bridge_space8[96+((b[15]>>8&255)+(a>>3&255)-2&3)])};function Ec(a,b,c){a[0]===b[0]&&a[1]===b[1]&&a[2]===
391
- b[2]&&a[3]===b[3]&&a[4]===b[4]&&a[5]===b[5]&&(C("Replace mac in eth destination field",1048576),a[0]=c[0],a[1]=c[1],a[2]=c[2],a[3]=c[3],a[4]=c[4],a[5]=c[5]);a[6]===b[0]&&a[7]===b[1]&&a[8]===b[2]&&a[9]===b[3]&&a[10]===b[4]&&a[11]===b[5]&&(C("Replace mac in eth source field",1048576),a[6]=c[0],a[7]=c[1],a[8]=c[2],a[9]=c[3],a[10]=c[4],a[11]=c[5]);var d=a[12]<<8|a[13];if(2048===d)if(a=a.subarray(14),d=a[0]>>4,4!==d)C("Expected ipv4.version==4 but got: "+d,1048576);else{if(k(5===(a[0]&15),"TODO: ihl!=5"),
392
- 17===a[9]){a=a.subarray(20);d=a[0]<<8|a[1];var e=a[2]<<8|a[3];C("udp srcport="+d+" dstport="+e+" checksum="+m(a[6]<<8|a[7],4),1048576);if(67===d||67===e)if(d=a.subarray(8),e=d[236]<<24|d[237]<<16|d[238]<<8|d[239],1669485411!==e)C("dhcp packet didn't match magic: "+m(e,8));else for(d[28]===b[0]&&d[29]===b[1]&&d[30]===b[2]&&d[31]===b[3]&&d[32]===b[4]&&d[33]===b[5]&&(C("Replace mac in dhcp.chaddr",1048576),d[28]=c[0],d[29]=c[1],d[30]=c[2],d[31]=c[3],d[32]=c[4],d[33]=c[5],a[6]=a[7]=0),e=240;e<d.length;){const f=
393
- d[e++];if(255===f)break;const h=d[e++];61===f&&1===d[e+0]&&d[e+1]===b[0]&&d[e+2]===b[1]&&d[e+3]===b[2]&&d[e+4]===b[3]&&d[e+5]===b[4]&&d[e+6]===b[5]&&(C("Replace mac in dhcp.clientidentifier",1048576),d[e+1]=c[0],d[e+2]=c[1],d[e+3]=c[2],d[e+4]=c[3],d[e+5]=c[4],d[e+6]=c[5],a[6]=a[7]=0);e+=h}}}else 2054===d&&(a=a.subarray(14),C("arp oper="+a[7]+" "+Fc(a.subarray(8,14))+" "+Fc(a.subarray(18,24)),1048576),a[8]===b[0]&&a[9]===b[1]&&a[10]===b[2]&&a[11]===b[3]&&a[12]===b[4]&&a[13]===b[5]&&(C("Replace mac in arp.sha",
394
- 1048576),a[8]=c[0],a[9]=c[1],a[10]=c[2],a[11]=c[3],a[12]=c[4],a[13]=c[5]))}function Fc(a){return[a[0].toString(16).padStart(2,"0"),a[1].toString(16).padStart(2,"0"),a[2].toString(16).padStart(2,"0"),a[3].toString(16).padStart(2,"0"),a[4].toString(16).padStart(2,"0"),a[5].toString(16).padStart(2,"0")].join(":")}function Gc(a,b,c,d,e){this.cpu=a;this.pci=a.devices.pci;this.id=e||0;this.preserve_mac_from_state_image=c;this.mac_address_translation=d;this.bus=b;this.bus.register("net"+this.id+"-receive",
395
- function(f){this.receive(f)},this);this.port=768+256*this.id;this.name="ne2k";this.pci_space=[236,16,41,128,3,1,0,0,0,0,0,2,0,0,0,0,this.port&255|1,this.port>>8,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,244,26,0,17,0,0,184,254,0,0,0,0,0,0,0,0,0,1,0,0];this.pci_id=(0===this.id?5:7+this.id)<<3;this.pci_bars=[{size:32}];this.imr=this.isr=0;this.cr=1;this.tpsr=this.tcnt=this.rcnt=this.dcfg=0;this.memory=new Uint8Array(32768);this.txcr=this.rxcr=0;this.tsr=1;this.mac=new Uint8Array([0,34,21,
396
- 255*Math.random()|0,255*Math.random()|0,255*Math.random()|0]);this.bus.send("net"+this.id+"-mac",Fc(this.mac));this.mar=Uint8Array.of(255,255,255,255,255,255,255,255);this.mac_address_in_state=null;for(b=0;6>b;b++)this.memory[b<<1]=this.memory[b<<1|1]=this.mac[b];this.memory[28]=this.memory[29]=87;this.memory[30]=this.memory[31]=87;C("Mac: "+Fc(this.mac),1048576);this.rsar=0;this.pstart=64;this.pstop=128;this.boundary=this.curpg=76;b=a.io;b.register_read(this.port|0,this,function(){C("Read cmd",1048576);
397
- return this.cr});b.register_write(this.port|0,this,function(f){this.cr=f;C("Write command: "+m(f,2)+" newpg="+(this.cr>>6)+" txcr="+m(this.txcr,2),1048576);this.cr&1||(f&24&&0===this.rcnt&&this.do_interrupt(64),f&4&&(f=this.tpsr<<8,f=this.memory.subarray(f,f+this.tcnt),this.mac_address_in_state&&(f=new Uint8Array(f),Ec(f,this.mac_address_in_state,this.mac)),this.bus.send("net"+this.id+"-send",f),this.bus.send("eth-transmit-end",[f.length]),this.cr&=-5,this.do_interrupt(2),C("Command: Transfer. length="+
398
- m(f.byteLength),1048576)))});b.register_read(this.port|13,this,function(){var f=this.get_page();if(1===f)return C("Read mar5",1048576),this.mar[5];C("Read counter0 pg="+f,1048576);return 0});b.register_read(this.port|14,this,function(){var f=this.get_page();if(1===f)return C("Read mar6",1048576),this.mar[6];C("Read8 counter1 pg="+f,1048576);return 0},function(){C("Read16 counter1 pg="+this.get_page(),1048576);return 0});b.register_read(this.port|15,this,function(){var f=this.get_page();if(1===f)return C("Read mar7",
399
- 1048576),this.mar[7];C("Read counter2 pg="+f,1048576);return 0});b.register_read(this.port|31,this,function(){this.get_page();C("Read reset",1048576);this.do_interrupt(128);return 0});b.register_write(this.port|31,this,function(f){this.get_page();C("Write reset: "+m(f,2),1048576)});b.register_read(this.port|1,this,function(){var f=this.get_page();if(0===f)return this.pstart;if(1===f)return C("Read pg1/01 (mac[0])",1048576),this.mac[0];if(2===f)return this.pstart;C("Read pg"+f+"/01");k(!1);return 0});
400
- b.register_write(this.port|1,this,function(f){var h=this.get_page();0===h?(C("start page: "+m(f,2),1048576),this.pstart=f):1===h?(C("mac[0] = "+m(f),1048576),this.mac[0]=f):3===h?C("Unimplemented: Write pg3/01 (9346CR): "+m(f),1048576):(C("Write pg"+h+"/01: "+m(f),1048576),k(!1))});b.register_read(this.port|2,this,function(){var f=this.get_page();if(0===f)return this.pstop;if(1===f)return C("Read pg1/02 (mac[1])",1048576),this.mac[1];if(2===f)return this.pstop;C("Read pg"+f+"/02",1048576);k(!1);return 0});
401
- b.register_write(this.port|2,this,function(f){var h=this.get_page();0===h?(C("stop page: "+m(f,2),1048576),f>this.memory.length>>8&&(f=this.memory.length>>8,C("XXX: Adjusting stop page to "+m(f),1048576)),this.pstop=f):1===h?(C("mac[1] = "+m(f),1048576),this.mac[1]=f):(C("Write pg"+h+"/02: "+m(f),1048576),k(!1))});b.register_read(this.port|7,this,function(){var f=this.get_page();if(0===f)return C("Read isr: "+m(this.isr,2),1048576),this.isr;if(1===f)return C("Read curpg: "+m(this.curpg,2),1048576),
402
- this.curpg;k(!1);return 0});b.register_write(this.port|7,this,function(f){var h=this.get_page();0===h?(C("Write isr: "+m(f,2),1048576),this.isr&=~f,this.update_irq()):1===h?(C("Write curpg: "+m(f,2),1048576),this.curpg=f):k(!1)});b.register_write(this.port|13,this,function(f){var h=this.get_page();0===h?(this.txcr=f,C("Write tx config: "+m(f,2),1048576)):C("Unimplemented: Write pg"+h+"/0d "+m(f,2),1048576)});b.register_write(this.port|14,this,function(f){var h=this.get_page();0===h?(C("Write data configuration: "+
403
- m(f,2),1048576),this.dcfg=f):C("Unimplemented: Write pg"+h+"/0e "+m(f,2),1048576)});b.register_read(this.port|10,this,function(){var f=this.get_page();if(0===f)return C("Read pg0/0a",1048576),80;if(1===f)return C("Read mar2",1048576),this.mar[2];k(!1,"TODO");return 0});b.register_write(this.port|10,this,function(f){var h=this.get_page();0===h?(C("Write remote byte count low: "+m(f,2),1048576),this.rcnt=this.rcnt&65280|f&255):C("Unimplemented: Write pg"+h+"/0a "+m(f,2),1048576)});b.register_read(this.port|
404
- 11,this,function(){var f=this.get_page();if(0===f)return C("Read pg0/0b",1048576),67;if(1===f)return C("Read mar3",1048576),this.mar[3];k(!1,"TODO");return 0});b.register_write(this.port|11,this,function(f){var h=this.get_page();0===h?(C("Write remote byte count high: "+m(f,2),1048576),this.rcnt=this.rcnt&255|f<<8&65280):C("Unimplemented: Write pg"+h+"/0b "+m(f,2),1048576)});b.register_read(this.port|8,this,function(){var f=this.get_page();if(0===f)return C("Read remote start address low",1048576),
405
- this.rsar&255;if(1===f)return C("Read mar0",1048576),this.mar[0];C("Unimplemented: Read pg"+f+"/08",1048576);k(!1);return 0});b.register_write(this.port|8,this,function(f){var h=this.get_page();0===h?(C("Write remote start address low: "+m(f,2),1048576),this.rsar=this.rsar&65280|f&255):C("Unimplemented: Write pg"+h+"/08 "+m(f,2),1048576)});b.register_read(this.port|9,this,function(){var f=this.get_page();if(0===f)return C("Read remote start address high",1048576),this.rsar>>8&255;if(1===f)return C("Read mar1",
406
- 1048576),this.mar[1];C("Unimplemented: Read pg"+f+"/09",1048576);k(!1);return 0});b.register_write(this.port|9,this,function(f){var h=this.get_page();0===h?(C("Write remote start address low: "+m(f,2),1048576),this.rsar=this.rsar&255|f<<8&65280):C("Unimplemented: Write pg"+h+"/09 "+m(f,2),1048576)});b.register_write(this.port|15,this,function(f){var h=this.get_page();0===h?(C("Write interrupt mask register: "+m(f,2)+" isr="+m(this.isr,2),1048576),this.imr=f,this.update_irq()):C("Unimplemented: Write pg"+
407
- h+"/0f "+m(f,2),1048576)});b.register_read(this.port|3,this,function(){var f=this.get_page();if(0===f)return C("Read boundary: "+m(this.boundary,2),1048576),this.boundary;if(1===f)return C("Read pg1/03 (mac[2])",1048576),this.mac[2];3===f?C("Unimplemented: Read pg3/03 (CONFIG0)",1048576):(C("Read pg"+f+"/03",1048576),k(!1));return 0});b.register_write(this.port|3,this,function(f){var h=this.get_page();0===h?(C("Write boundary: "+m(f,2),1048576),this.boundary=f):1===h?(C("mac[2] = "+m(f),1048576),
408
- this.mac[2]=f):(C("Write pg"+h+"/03: "+m(f),1048576),k(!1))});b.register_read(this.port|4,this,function(){var f=this.get_page();if(0===f)return this.tsr;if(1===f)return C("Read pg1/04 (mac[3])",1048576),this.mac[3];C("Read pg"+f+"/04",1048576);k(!1);return 0});b.register_write(this.port|4,this,function(f){var h=this.get_page();0===h?(C("Write tpsr: "+m(f,2),1048576),this.tpsr=f):1===h?(C("mac[3] = "+m(f),1048576),this.mac[3]=f):(C("Write pg"+h+"/04: "+m(f),1048576),k(!1))});b.register_read(this.port|
388
+ -1===(b|2047)?-e.pci_rom_size|0:e.pci_rom_address|0:0):4===a?C("PCI write dev="+m(c>>3,2)+" ("+e.name+") addr="+m(a,4)+" value="+m(b>>>0,8),2048):(C("PCI write dev="+m(c>>3,2)+" ("+e.name+") addr="+m(a,4)+" value="+m(b>>>0,8),2048),d[a>>>2]=b)};Dc.prototype.register_device=function(a){k(void 0!==a.pci_id);k(void 0!==a.pci_space);k(void 0!==a.pci_bars);var b=a.pci_id;C("PCI register bdf="+m(b)+" ("+a.name+")",2048);this.devices[b]&&C("warning: overwriting device "+this.devices[b].name+" with "+a.name,
389
+ 2048);k(64<=a.pci_space.length);k(b<this.devices.length);var c=new Int32Array(64);c.set(new Int32Array((new Uint8Array(a.pci_space)).buffer));this.device_spaces[b]=c;this.devices[b]=a;b=c.slice(4,10);for(var d=0;d<a.pci_bars.length;d++){var e=a.pci_bars[d];if(e){var f=b[d],h=f&1;C("device "+a.name+" register bar of size "+e.size+" at "+m(f),2048);e.original_bar=f;e.entries=[];if(0!==h)for(k(1===h),f&=-2,h=0;h<e.size;h++)e.entries[h]=this.io.ports[f+h]}}return c};Dc.prototype.set_io_bars=function(a,
390
+ b,c){var d=a.size;C("Move io bars: from="+m(b)+" to="+m(c)+" count="+d,2048);for(var e=this.io.ports,f=0;f<d;f++){4096<=b+f&&(e[b+f]=this.io.create_empty_entry());var h=a.entries[f],l=e[c+f];k(h&&l);4096<=c+f&&(e[c+f]=h)}};Dc.prototype.raise_irq=function(a){var b=this.device_spaces[a];k(b);this.cpu.device_raise_irq(this.isa_bridge_space8[96+((b[15]>>8&255)-1+((a>>3)-1&255)&3)])};Dc.prototype.lower_irq=function(a){var b=this.device_spaces[a];k(b);this.cpu.device_lower_irq(this.isa_bridge_space8[96+
391
+ ((b[15]>>8&255)+(a>>3&255)-2&3)])};function Ec(a,b,c){a[0]===b[0]&&a[1]===b[1]&&a[2]===b[2]&&a[3]===b[3]&&a[4]===b[4]&&a[5]===b[5]&&(C("Replace mac in eth destination field",1048576),a[0]=c[0],a[1]=c[1],a[2]=c[2],a[3]=c[3],a[4]=c[4],a[5]=c[5]);a[6]===b[0]&&a[7]===b[1]&&a[8]===b[2]&&a[9]===b[3]&&a[10]===b[4]&&a[11]===b[5]&&(C("Replace mac in eth source field",1048576),a[6]=c[0],a[7]=c[1],a[8]=c[2],a[9]=c[3],a[10]=c[4],a[11]=c[5]);var d=a[12]<<8|a[13];if(2048===d)if(a=a.subarray(14),d=a[0]>>4,4!==d)C("Expected ipv4.version==4 but got: "+
392
+ d,1048576);else{if(k(5===(a[0]&15),"TODO: ihl!=5"),17===a[9]){a=a.subarray(20);d=a[0]<<8|a[1];var e=a[2]<<8|a[3];C("udp srcport="+d+" dstport="+e+" checksum="+m(a[6]<<8|a[7],4),1048576);if(67===d||67===e)if(d=a.subarray(8),e=d[236]<<24|d[237]<<16|d[238]<<8|d[239],1669485411!==e)C("dhcp packet didn't match magic: "+m(e,8));else for(d[28]===b[0]&&d[29]===b[1]&&d[30]===b[2]&&d[31]===b[3]&&d[32]===b[4]&&d[33]===b[5]&&(C("Replace mac in dhcp.chaddr",1048576),d[28]=c[0],d[29]=c[1],d[30]=c[2],d[31]=c[3],
393
+ d[32]=c[4],d[33]=c[5],a[6]=a[7]=0),e=240;e<d.length;){const f=d[e++];if(255===f)break;const h=d[e++];61===f&&1===d[e+0]&&d[e+1]===b[0]&&d[e+2]===b[1]&&d[e+3]===b[2]&&d[e+4]===b[3]&&d[e+5]===b[4]&&d[e+6]===b[5]&&(C("Replace mac in dhcp.clientidentifier",1048576),d[e+1]=c[0],d[e+2]=c[1],d[e+3]=c[2],d[e+4]=c[3],d[e+5]=c[4],d[e+6]=c[5],a[6]=a[7]=0);e+=h}}}else 2054===d&&(a=a.subarray(14),C("arp oper="+a[7]+" "+Fc(a.subarray(8,14))+" "+Fc(a.subarray(18,24)),1048576),a[8]===b[0]&&a[9]===b[1]&&a[10]===b[2]&&
394
+ a[11]===b[3]&&a[12]===b[4]&&a[13]===b[5]&&(C("Replace mac in arp.sha",1048576),a[8]=c[0],a[9]=c[1],a[10]=c[2],a[11]=c[3],a[12]=c[4],a[13]=c[5]))}function Fc(a){return[a[0].toString(16).padStart(2,"0"),a[1].toString(16).padStart(2,"0"),a[2].toString(16).padStart(2,"0"),a[3].toString(16).padStart(2,"0"),a[4].toString(16).padStart(2,"0"),a[5].toString(16).padStart(2,"0")].join(":")}function Gc(a,b,c,d,e){this.cpu=a;this.pci=a.devices.pci;this.id=e||0;this.preserve_mac_from_state_image=c;this.mac_address_translation=
395
+ d;this.bus=b;this.bus.register("net"+this.id+"-receive",function(f){this.receive(f)},this);this.port=768+256*this.id;this.name="ne2k";this.pci_space=[236,16,41,128,3,1,0,0,0,0,0,2,0,0,0,0,this.port&255|1,this.port>>8,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,244,26,0,17,0,0,184,254,0,0,0,0,0,0,0,0,0,1,0,0];this.pci_id=(0===this.id?5:7+this.id)<<3;this.pci_bars=[{size:32}];this.imr=this.isr=0;this.cr=1;this.tpsr=this.tcnt=this.rcnt=this.dcfg=0;this.memory=new Uint8Array(32768);this.txcr=
396
+ this.rxcr=0;this.tsr=1;this.mac=new Uint8Array([0,34,21,255*Math.random()|0,255*Math.random()|0,255*Math.random()|0]);this.bus.send("net"+this.id+"-mac",Fc(this.mac));this.mar=Uint8Array.of(255,255,255,255,255,255,255,255);this.mac_address_in_state=null;for(b=0;6>b;b++)this.memory[b<<1]=this.memory[b<<1|1]=this.mac[b];this.memory[28]=this.memory[29]=87;this.memory[30]=this.memory[31]=87;C("Mac: "+Fc(this.mac),1048576);this.rsar=0;this.pstart=64;this.pstop=128;this.boundary=this.curpg=76;b=a.io;b.register_read(this.port|
397
+ 0,this,function(){C("Read cmd",1048576);return this.cr});b.register_write(this.port|0,this,function(f){this.cr=f;C("Write command: "+m(f,2)+" newpg="+(this.cr>>6)+" txcr="+m(this.txcr,2),1048576);this.cr&1||(f&24&&0===this.rcnt&&this.do_interrupt(64),f&4&&(f=this.tpsr<<8,f=this.memory.subarray(f,f+this.tcnt),this.mac_address_in_state&&(f=new Uint8Array(f),Ec(f,this.mac_address_in_state,this.mac)),this.bus.send("net"+this.id+"-send",f),this.bus.send("eth-transmit-end",[f.length]),this.cr&=-5,this.do_interrupt(2),
398
+ C("Command: Transfer. length="+m(f.byteLength),1048576)))});b.register_read(this.port|13,this,function(){var f=this.get_page();if(1===f)return C("Read mar5",1048576),this.mar[5];C("Read counter0 pg="+f,1048576);return 0});b.register_read(this.port|14,this,function(){var f=this.get_page();if(1===f)return C("Read mar6",1048576),this.mar[6];C("Read8 counter1 pg="+f,1048576);return 0},function(){C("Read16 counter1 pg="+this.get_page(),1048576);return 0});b.register_read(this.port|15,this,function(){var f=
399
+ this.get_page();if(1===f)return C("Read mar7",1048576),this.mar[7];C("Read counter2 pg="+f,1048576);return 0});b.register_read(this.port|31,this,function(){this.get_page();C("Read reset",1048576);this.do_interrupt(128);return 0});b.register_write(this.port|31,this,function(f){this.get_page();C("Write reset: "+m(f,2),1048576)});b.register_read(this.port|1,this,function(){var f=this.get_page();if(0===f)return this.pstart;if(1===f)return C("Read pg1/01 (mac[0])",1048576),this.mac[0];if(2===f)return this.pstart;
400
+ C("Read pg"+f+"/01");k(!1);return 0});b.register_write(this.port|1,this,function(f){var h=this.get_page();0===h?(C("start page: "+m(f,2),1048576),this.pstart=f):1===h?(C("mac[0] = "+m(f),1048576),this.mac[0]=f):3===h?C("Unimplemented: Write pg3/01 (9346CR): "+m(f),1048576):(C("Write pg"+h+"/01: "+m(f),1048576),k(!1))});b.register_read(this.port|2,this,function(){var f=this.get_page();if(0===f)return this.pstop;if(1===f)return C("Read pg1/02 (mac[1])",1048576),this.mac[1];if(2===f)return this.pstop;
401
+ C("Read pg"+f+"/02",1048576);k(!1);return 0});b.register_write(this.port|2,this,function(f){var h=this.get_page();0===h?(C("stop page: "+m(f,2),1048576),f>this.memory.length>>8&&(f=this.memory.length>>8,C("XXX: Adjusting stop page to "+m(f),1048576)),this.pstop=f):1===h?(C("mac[1] = "+m(f),1048576),this.mac[1]=f):(C("Write pg"+h+"/02: "+m(f),1048576),k(!1))});b.register_read(this.port|7,this,function(){var f=this.get_page();if(0===f)return C("Read isr: "+m(this.isr,2),1048576),this.isr;if(1===f)return C("Read curpg: "+
402
+ m(this.curpg,2),1048576),this.curpg;k(!1);return 0});b.register_write(this.port|7,this,function(f){var h=this.get_page();0===h?(C("Write isr: "+m(f,2),1048576),this.isr&=~f,this.update_irq()):1===h?(C("Write curpg: "+m(f,2),1048576),this.curpg=f):k(!1)});b.register_write(this.port|13,this,function(f){var h=this.get_page();0===h?(this.txcr=f,C("Write tx config: "+m(f,2),1048576)):C("Unimplemented: Write pg"+h+"/0d "+m(f,2),1048576)});b.register_write(this.port|14,this,function(f){var h=this.get_page();
403
+ 0===h?(C("Write data configuration: "+m(f,2),1048576),this.dcfg=f):C("Unimplemented: Write pg"+h+"/0e "+m(f,2),1048576)});b.register_read(this.port|10,this,function(){var f=this.get_page();if(0===f)return C("Read pg0/0a",1048576),80;if(1===f)return C("Read mar2",1048576),this.mar[2];k(!1,"TODO");return 0});b.register_write(this.port|10,this,function(f){var h=this.get_page();0===h?(C("Write remote byte count low: "+m(f,2),1048576),this.rcnt=this.rcnt&65280|f&255):C("Unimplemented: Write pg"+h+"/0a "+
404
+ m(f,2),1048576)});b.register_read(this.port|11,this,function(){var f=this.get_page();if(0===f)return C("Read pg0/0b",1048576),67;if(1===f)return C("Read mar3",1048576),this.mar[3];k(!1,"TODO");return 0});b.register_write(this.port|11,this,function(f){var h=this.get_page();0===h?(C("Write remote byte count high: "+m(f,2),1048576),this.rcnt=this.rcnt&255|f<<8&65280):C("Unimplemented: Write pg"+h+"/0b "+m(f,2),1048576)});b.register_read(this.port|8,this,function(){var f=this.get_page();if(0===f)return C("Read remote start address low",
405
+ 1048576),this.rsar&255;if(1===f)return C("Read mar0",1048576),this.mar[0];C("Unimplemented: Read pg"+f+"/08",1048576);k(!1);return 0});b.register_write(this.port|8,this,function(f){var h=this.get_page();0===h?(C("Write remote start address low: "+m(f,2),1048576),this.rsar=this.rsar&65280|f&255):C("Unimplemented: Write pg"+h+"/08 "+m(f,2),1048576)});b.register_read(this.port|9,this,function(){var f=this.get_page();if(0===f)return C("Read remote start address high",1048576),this.rsar>>8&255;if(1===
406
+ f)return C("Read mar1",1048576),this.mar[1];C("Unimplemented: Read pg"+f+"/09",1048576);k(!1);return 0});b.register_write(this.port|9,this,function(f){var h=this.get_page();0===h?(C("Write remote start address low: "+m(f,2),1048576),this.rsar=this.rsar&255|f<<8&65280):C("Unimplemented: Write pg"+h+"/09 "+m(f,2),1048576)});b.register_write(this.port|15,this,function(f){var h=this.get_page();0===h?(C("Write interrupt mask register: "+m(f,2)+" isr="+m(this.isr,2),1048576),this.imr=f,this.update_irq()):
407
+ C("Unimplemented: Write pg"+h+"/0f "+m(f,2),1048576)});b.register_read(this.port|3,this,function(){var f=this.get_page();if(0===f)return C("Read boundary: "+m(this.boundary,2),1048576),this.boundary;if(1===f)return C("Read pg1/03 (mac[2])",1048576),this.mac[2];3===f?C("Unimplemented: Read pg3/03 (CONFIG0)",1048576):(C("Read pg"+f+"/03",1048576),k(!1));return 0});b.register_write(this.port|3,this,function(f){var h=this.get_page();0===h?(C("Write boundary: "+m(f,2),1048576),this.boundary=f):1===h?(C("mac[2] = "+
408
+ m(f),1048576),this.mac[2]=f):(C("Write pg"+h+"/03: "+m(f),1048576),k(!1))});b.register_read(this.port|4,this,function(){var f=this.get_page();if(0===f)return this.tsr;if(1===f)return C("Read pg1/04 (mac[3])",1048576),this.mac[3];C("Read pg"+f+"/04",1048576);k(!1);return 0});b.register_write(this.port|4,this,function(f){var h=this.get_page();0===h?(C("Write tpsr: "+m(f,2),1048576),this.tpsr=f):1===h?(C("mac[3] = "+m(f),1048576),this.mac[3]=f):(C("Write pg"+h+"/04: "+m(f),1048576),k(!1))});b.register_read(this.port|
409
409
  5,this,function(){var f=this.get_page();if(0===f)return C("Unimplemented: Read pg0/05 (NCR: Number of Collisions Register)",1048576),0;if(1===f)return C("Read pg1/05 (mac[4])",1048576),this.mac[4];3===f?C("Unimplemented: Read pg3/05 (CONFIG2)",1048576):(C("Read pg"+f+"/05",1048576),k(!1));return 0});b.register_write(this.port|5,this,function(f){var h=this.get_page();0===h?(C("Write tcnt low: "+m(f,2),1048576),this.tcnt=this.tcnt&-256|f):1===h?(C("mac[4] = "+m(f),1048576),this.mac[4]=f):3===h?C("Unimplemented: Write pg3/05 (CONFIG2): "+
410
410
  m(f),1048576):(C("Write pg"+h+"/05: "+m(f),1048576),k(!1))});b.register_read(this.port|6,this,function(){var f=this.get_page();if(0===f)return k(!1,"TODO"),0;if(1===f)return C("Read pg1/06 (mac[5])",1048576),this.mac[5];3===f?C("Unimplemented: Read pg3/06 (CONFIG3)",1048576):(C("Read pg"+f+"/06",1048576),k(!1));return 0});b.register_write(this.port|6,this,function(f){var h=this.get_page();0===h?(C("Write tcnt high: "+m(f,2),1048576),this.tcnt=this.tcnt&255|f<<8):1===h?(C("mac[5] = "+m(f),1048576),
411
411
  this.mac[5]=f):3===h?C("Unimplemented: Write pg3/06 (CONFIG3): "+m(f),1048576):(C("Write pg"+h+"/06: "+m(f),1048576),k(!1))});b.register_read(this.port|12,this,function(){var f=this.get_page();if(0===f)return 9;if(1===f)return C("Read mar4",1048576),this.mar[4];C("Unimplemented: Read pg"+f+"/0c",1048576);k(!1);return 0});b.register_write(this.port|12,this,function(f){var h=this.get_page();0===h?(C("RX configuration reg write: "+m(f,2),1048576),this.rxcr=f):C("Unimplemented: Write pg"+h+"/0c: "+m(f),
@@ -418,11 +418,11 @@ this.rxcr&16||this.rxcr&4&&255===a[0]&&255===a[1]&&255===a[2]&&255===a[3]&&255==
418
418
  this.boundary-this.pstart;l<h&&0!==this.boundary?C("Buffer full, dropping packet pstart="+m(this.pstart)+" pstop="+m(this.pstop)+" curpg="+m(this.curpg)+" needed="+m(h)+" boundary="+m(this.boundary)+" available="+m(l),1048576):(f>this.pstop<<8?(k(60<=a.length),f=(this.pstop<<8)-d,k(0<=f),this.memory.set(a.subarray(0,f),d),this.memory.set(a.subarray(f),this.pstart<<8),C("rcv cut="+m(f),1048576)):(this.memory.set(a,d),60>a.length&&this.memory.fill(0,d+a.length,d+60)),e>=this.pstop&&(e+=this.pstart-
419
419
  this.pstop),this.memory[b]=1,this.memory[b+1]=e,this.memory[b+2]=c,this.memory[b+3]=c>>8,this.curpg=e,C("rcv offset="+m(b)+" len="+m(c)+" next="+m(e),1048576),this.do_interrupt(1))}};Gc.prototype.get_page=function(){return this.cr>>6&3};function Hc(a,b){this.bus=b;this.rows=25;this.cols=80;this.ports=4;b=[{size_supported:16,notify_offset:0},{size_supported:16,notify_offset:1},{size_supported:16,notify_offset:2},{size_supported:16,notify_offset:3}];for(let c=1;c<this.ports;++c)b.push({size_supported:16,
420
420
  notify_offset:0}),b.push({size_supported:8,notify_offset:1});this.virtio=new Ic(a,{name:"virtio-console",pci_id:96,device_id:4163,subsystem_device_id:3,common:{initial_port:47104,queues:b,features:[0,1,32],on_driver_ok:()=>{}},notification:{initial_port:47360,single_handler:!1,handlers:[()=>{},c=>{const d=this.virtio.queues[c],e=3<c?c-3>>1:0;for(;d.has_request();){const f=d.pop_request(),h=new Uint8Array(f.length_readable);f.get_next_blob(h);this.bus.send("virtio-console"+e+"-output-bytes",h);this.Ack(c,
421
- f)}},c=>{if(2!==c)k(!1,"VirtioConsole Notified for wrong queue: "+c+" (expected queue_id of 2)");else for(c=this.virtio.queues[c];c.count_requests()>c.size-2;)c.pop_request()},c=>{if(3!==c)k(!1,"VirtioConsole Notified for wrong queue: "+c+" (expected queue_id of 3)");else for(var d=this.virtio.queues[c];d.has_request();){var e=d.pop_request(),f=new Uint8Array(e.length_readable);e.get_next_blob(f);var h=M(["w","h","h"],f,{offset:0});f=h[0];h=h[1];this.Ack(c,e);switch(h){case 0:for(e=0;e<this.ports;++e)this.SendEvent(e,
421
+ f)}},c=>{if(2!==c)k(!1,"VirtioConsole Notified for wrong queue: "+c+" (expected queue_id of 2)");else for(c=this.virtio.queues[c];c.count_requests()>c.size-2;)c.pop_request()},c=>{if(3!==c)k(!1,"VirtioConsole Notified for wrong queue: "+c+" (expected queue_id of 3)");else for(var d=this.virtio.queues[c];d.has_request();){var e=d.pop_request(),f=new Uint8Array(e.length_readable);e.get_next_blob(f);var h=K(["w","h","h"],f,{offset:0});f=h[0];h=h[1];this.Ack(c,e);switch(h){case 0:for(e=0;e<this.ports;++e)this.SendEvent(e,
422
422
  1,0);break;case 3:this.Ack(c,e);this.SendEvent(f,4,1);this.SendName(f,"virtio-"+f);this.SendEvent(f,6,1);break;case 6:this.Ack(c,e);0===f&&this.SendWindowSize(f);break;default:k(!1," VirtioConsole received unknown event: "+h[1]);return}}}]},isr_status:{initial_port:46848},device_specific:{initial_port:46592,struct:[{bytes:2,name:"cols",read:()=>this.cols,write:()=>{}},{bytes:2,name:"rows",read:()=>this.rows,write:()=>{}},{bytes:4,name:"max_nr_ports",read:()=>this.ports,write:()=>{}},{bytes:4,name:"emerg_wr",
423
423
  read:()=>0,write:()=>{k(!1,"Emergency write!")}}]}});for(let c=0;c<this.ports;++c){const d=0===c?0:2*c+2;this.bus.register("virtio-console"+c+"-input-bytes",function(e){var f=this.virtio.queues[d];f.has_request()&&(f=f.pop_request(),this.Send(d,f,new Uint8Array(e)))},this);this.bus.register("virtio-console"+c+"-resize",function(e){0===c&&(this.cols=e[0],this.rows=e[1]);this.virtio.queues[2].is_configured()&&this.virtio.queues[2].has_request()&&this.SendWindowSize(c,e[0],e[1])},this)}}Hc.prototype.SendWindowSize=
424
- function(a,b,c){c=c||this.rows;b=b||this.cols;const d=this.virtio.queues[2].pop_request(),e=new Uint8Array(12);K(["w","h","h","h","h"],[a,5,0,c,b],e,0);this.Send(2,d,e)};Hc.prototype.SendName=function(a,b){const c=this.virtio.queues[2].pop_request();b=(new TextEncoder).encode(b);const d=new Uint8Array(8+b.length+1);K(["w","h","h"],[a,7,1],d,0);for(a=0;a<b.length;++a)d[a+8]=b[a];d[8+b.length]=0;this.Send(2,c,d)};Hc.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.rows;a[2]=this.cols;
425
- a[3]=this.ports;return a};Hc.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.rows=a[1];this.cols=a[2];this.ports=a[3]};Hc.prototype.reset=function(){this.virtio.reset()};Hc.prototype.SendEvent=function(a,b,c){const d=this.virtio.queues[2].pop_request(),e=new Uint8Array(8);K(["w","h","h"],[a,b,c],e,0);this.Send(2,d,e)};Hc.prototype.Send=function(a,b,c){b.set_next_blob(c);this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};Hc.prototype.Ack=function(a,b){b.set_next_blob(new Uint8Array(0));
424
+ function(a,b,c){c=c||this.rows;b=b||this.cols;const d=this.virtio.queues[2].pop_request(),e=new Uint8Array(12);J(["w","h","h","h","h"],[a,5,0,c,b],e,0);this.Send(2,d,e)};Hc.prototype.SendName=function(a,b){const c=this.virtio.queues[2].pop_request();b=(new TextEncoder).encode(b);const d=new Uint8Array(8+b.length+1);J(["w","h","h"],[a,7,1],d,0);for(a=0;a<b.length;++a)d[a+8]=b[a];d[8+b.length]=0;this.Send(2,c,d)};Hc.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.rows;a[2]=this.cols;
425
+ a[3]=this.ports;return a};Hc.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.rows=a[1];this.cols=a[2];this.ports=a[3]};Hc.prototype.reset=function(){this.virtio.reset()};Hc.prototype.SendEvent=function(a,b,c){const d=this.virtio.queues[2].pop_request(),e=new Uint8Array(8);J(["w","h","h"],[a,b,c],e,0);this.Send(2,d,e)};Hc.prototype.Send=function(a,b,c){b.set_next_blob(c);this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};Hc.prototype.Ack=function(a,b){b.set_next_blob(new Uint8Array(0));
426
426
  this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};function Jc(a,b){this.cpu=a;this.bus=b;this.reset();this.bus.register("keyboard-code",function(c){this.kbd_send_code(c)},this);this.bus.register("mouse-click",function(c){this.mouse_send_click(c[0],c[1],c[2])},this);this.bus.register("mouse-delta",function(c){this.mouse_send_delta(c[0],c[1])},this);this.bus.register("mouse-wheel",function(c){this.wheel_movement-=c[0];this.wheel_movement-=2*c[1];this.wheel_movement=Math.min(7,
427
427
  Math.max(-8,this.wheel_movement));this.send_mouse_packet(0,0)},this);a.io.register_read(96,this,this.port60_read);a.io.register_read(100,this,this.port64_read);a.io.register_write(96,this,this.port60_write);a.io.register_write(100,this,this.port64_write)}Jc.prototype.reset=function(){this.use_mouse=this.enable_mouse_stream=!1;this.have_mouse=!0;this.mouse_clicks=this.mouse_delta_y=this.mouse_delta_x=0;this.have_keyboard=!0;this.next_read_resolution=this.next_read_rate=this.next_handle_scan_code_set=
428
428
  this.next_read_led=this.next_read_sample=this.next_is_mouse_command=this.enable_keyboard_stream=!1;this.kbd_buffer=new ma(1024);this.last_port60_byte=0;this.sample_rate=100;this.mouse_id=this.mouse_detect_state=0;this.mouse_reset_workaround=!1;this.wheel_movement=0;this.resolution=4;this.scaling2=!1;this.last_mouse_packet=-1;this.mouse_buffer=new ma(1024);this.next_byte_is_aux=this.next_byte_is_ready=!1;this.command_register=5;this.controller_output_port=0;this.read_controller_output_port=this.read_command_register=
@@ -461,266 +461,272 @@ this.calibrate;this.bytes_expecting=1;break;case 8:this.check_interrupt_status()
461
461
  this.response_index=0;this.response_length=2;this.response_data[0]=this.status_reg0;this.response_data[1]=this.last_cylinder};V.prototype.do_sector=function(a,b){var c=b[2],d=b[1],e=b[3],f=128<<b[4],h=b[5]-b[3]+1,l=((c+this.number_of_heads*d)*this.sectors_per_track+e-1)*f;C("Floppy "+(a?"Write":"Read"),8192);C("from "+m(l)+" length "+m(h*f),8192);C(d+" / "+c+" / "+e,8192);b[4]||C("FDC: sector count is zero, use data length instead",8192);this.fda_image?(this.status_reg1=0,a?this.dma.do_write(this.fda_image,
462
462
  l,h*f,2,this.done.bind(this,b,d,c,e)):this.dma.do_read(this.fda_image,l,h*f,2,this.done.bind(this,b,d,c,e))):this.status_reg1=5};V.prototype.done=function(a,b,c,d,e){e?C("XXX: Unhandled floppy error",8192):(d++,d>this.sectors_per_track&&(d=1,c++,c>=this.number_of_heads&&(c=0,b++)),b!==this.last_cylinder&&(this.dir=0),this.status_reg0=32,this.last_cylinder=b,this.last_head=c,this.last_sector=d,this.response_index=0,this.response_length=7,this.response_data[0]=c<<2|32,this.response_data[1]=0,this.response_data[2]=
463
463
  0,this.response_data[3]=b,this.response_data[4]=c,this.response_data[5]=d,this.response_data[6]=a[4],this.raise_irq())};V.prototype.fix_drive_data=function(a){C("floppy fix drive data "+a.slice(0,this.bytes_expecting),8192)};V.prototype.configure=function(a){C("floppy configure "+a.slice(0,this.bytes_expecting),8192)};V.prototype.read_sector_id=function(a){C("floppy read sector id "+a,8192);this.response_index=0;this.response_length=7;this.response_data[0]=0;this.response_data[1]=0;this.response_data[2]=
464
- 0;this.response_data[3]=0;this.response_data[4]=0;this.response_data[5]=0;this.response_data[6]=0;this.raise_irq()};V.prototype.raise_irq=function(){this.dor&8&&this.cpu.device_raise_irq(6)};function Tc(a,b,c,d,e,f){this.master=new W(this,a,b,d,e,0,f);this.slave=new W(this,a,c,!1,e,1,f);this.current_interface=this.master;this.cpu=a;0===e?(this.ata_port=496,this.irq=14,this.pci_id=240):1===e?(this.ata_port=368,this.irq=15,this.pci_id=248):k(!1,"IDE device with nr "+e+" ignored",32768);this.ata_port_high=
465
- this.ata_port|516;this.master_port=46080;this.pci_space=[134,128,16,112,5,0,160,2,0,128,1,1,0,0,0,0,this.ata_port&255|1,this.ata_port>>8,0,0,this.ata_port_high&255|1,this.ata_port_high>>8,0,0,0,0,0,0,0,0,0,0,this.master_port&255|1,this.master_port>>8,0,0,0,0,0,0,0,0,0,0,67,16,212,130,0,0,0,0,0,0,0,0,0,0,0,0,this.irq,1,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,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,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,0,0,0,0,0,0,0,
466
- 0,0,0,0,0,0,0];this.pci_bars=[{size:8},{size:4},void 0,void 0,{size:16}];this.name="ide"+e;this.device_control=2;a.io.register_read(this.ata_port|7,this,function(){C("lower irq",32768);this.cpu.device_lower_irq(this.irq);return this.read_status()});a.io.register_read(this.ata_port_high|2,this,this.read_status);a.io.register_write(this.ata_port_high|2,this,this.write_control);a.io.register_read(this.ata_port|0,this,function(){return this.current_interface.read_data(1)},function(){return this.current_interface.read_data(2)},
467
- function(){return this.current_interface.read_data(4)});a.io.register_read(this.ata_port|1,this,function(){C("Read error: "+m(this.current_interface.error&255)+" slave="+(this.current_interface===this.slave),32768);return this.current_interface.error&255});a.io.register_read(this.ata_port|2,this,function(){C("Read bytecount: "+m(this.current_interface.bytecount&255),32768);return this.current_interface.bytecount&255});a.io.register_read(this.ata_port|3,this,function(){C("Read sector: "+m(this.current_interface.sector&
468
- 255),32768);return this.current_interface.sector&255});a.io.register_read(this.ata_port|4,this,function(){C("Read 1F4: "+m(this.current_interface.cylinder_low&255),32768);return this.current_interface.cylinder_low&255});a.io.register_read(this.ata_port|5,this,function(){C("Read 1F5: "+m(this.current_interface.cylinder_high&255),32768);return this.current_interface.cylinder_high&255});a.io.register_read(this.ata_port|6,this,function(){C("Read 1F6",32768);return this.current_interface.drive_head&255});
469
- a.io.register_write(this.ata_port|0,this,function(h){this.current_interface.write_data_port8(h)},function(h){this.current_interface.write_data_port16(h)},function(h){this.current_interface.write_data_port32(h)});a.io.register_write(this.ata_port|1,this,function(h){C("1F1/lba_count: "+m(h),32768);this.master.lba_count=(this.master.lba_count<<8|h)&65535;this.slave.lba_count=(this.slave.lba_count<<8|h)&65535});a.io.register_write(this.ata_port|2,this,function(h){C("1F2/bytecount: "+m(h),32768);this.master.bytecount=
470
- (this.master.bytecount<<8|h)&65535;this.slave.bytecount=(this.slave.bytecount<<8|h)&65535});a.io.register_write(this.ata_port|3,this,function(h){C("1F3/sector: "+m(h),32768);this.master.sector=(this.master.sector<<8|h)&65535;this.slave.sector=(this.slave.sector<<8|h)&65535});a.io.register_write(this.ata_port|4,this,function(h){C("1F4/sector low: "+m(h),32768);this.master.cylinder_low=(this.master.cylinder_low<<8|h)&65535;this.slave.cylinder_low=(this.slave.cylinder_low<<8|h)&65535});a.io.register_write(this.ata_port|
471
- 5,this,function(h){C("1F5/sector high: "+m(h),32768);this.master.cylinder_high=(this.master.cylinder_high<<8|h)&65535;this.slave.cylinder_high=(this.slave.cylinder_high<<8|h)&65535});a.io.register_write(this.ata_port|6,this,function(h){var l=h&16;C("1F6/drive: "+m(h,2),32768);l?(C("Slave",32768),this.current_interface=this.slave):this.current_interface=this.master;this.master.drive_head=h;this.slave.drive_head=h;this.master.is_lba=this.slave.is_lba=h>>6&1;this.master.head=this.slave.head=h&15});this.dma_command=
472
- this.dma_status=this.prdt_addr=0;a.io.register_write(this.ata_port|7,this,function(h){C("lower irq",32768);this.cpu.device_lower_irq(this.irq);this.current_interface.ata_command(h)});a.io.register_read(this.master_port|4,this,void 0,void 0,this.dma_read_addr);a.io.register_write(this.master_port|4,this,void 0,void 0,this.dma_set_addr);a.io.register_read(this.master_port,this,this.dma_read_command8,void 0,this.dma_read_command);a.io.register_write(this.master_port,this,this.dma_write_command8,void 0,
473
- this.dma_write_command);a.io.register_read(this.master_port|2,this,this.dma_read_status);a.io.register_write(this.master_port|2,this,this.dma_write_status);a.io.register_read(this.master_port|8,this,function(){C("DMA read 0x8",32768);return 0});a.io.register_read(this.master_port|10,this,function(){C("DMA read 0xA",32768);return 0});a.devices.pci.register_device(this);Object.seal(this)}Tc.prototype.read_status=function(){if(this.current_interface.buffer){var a=this.current_interface.status;C("ATA read status: "+
474
- m(a,2),32768);return a}return 0};Tc.prototype.write_control=function(a){C("set device control: "+m(a,2)+" interrupts "+(a&2?"disabled":"enabled"),32768);a&4&&(C("Reset via control port",32768),this.cpu.device_lower_irq(this.irq),this.master.device_reset(),this.slave.device_reset());this.device_control=a};Tc.prototype.dma_read_addr=function(){C("dma get address: "+m(this.prdt_addr,8),32768);return this.prdt_addr};Tc.prototype.dma_set_addr=function(a){C("dma set address: "+m(a,8),32768);this.prdt_addr=
475
- a};Tc.prototype.dma_read_status=function(){C("DMA read status: "+m(this.dma_status),32768);return this.dma_status};Tc.prototype.dma_write_status=function(a){C("DMA set status: "+m(a),32768);this.dma_status&=~(a&6)};Tc.prototype.dma_read_command=function(){return this.dma_read_command8()|this.dma_read_status()<<16};Tc.prototype.dma_read_command8=function(){C("DMA read command: "+m(this.dma_command),32768);return this.dma_command};Tc.prototype.dma_write_command=function(a){C("DMA write command: "+m(a),
476
- 32768);this.dma_write_command8(a&255);this.dma_write_status(a>>16&255)};Tc.prototype.dma_write_command8=function(a){C("DMA write command8: "+m(a),32768);const b=this.dma_command;this.dma_command=a&9;if((b&1)!==(a&1))if(0===(a&1))this.dma_status&=-2;else switch(this.dma_status|=1,this.current_interface.current_command){case 37:case 200:this.current_interface.do_ata_read_sectors_dma();break;case 202:case 53:this.current_interface.do_ata_write_sectors_dma();break;case 160:this.current_interface.do_atapi_dma();
477
- break;default:C("Spurious dma command write, current command: "+m(this.current_interface.current_command),32768),k(!1)}};Tc.prototype.push_irq=function(){0===(this.device_control&2)&&(C("push irq",32768),this.dma_status|=4,this.cpu.device_raise_irq(this.irq))};Tc.prototype.get_state=function(){var a=[];a[0]=this.master;a[1]=this.slave;a[2]=this.ata_port;a[3]=this.irq;a[4]=this.pci_id;a[5]=this.ata_port_high;a[6]=this.master_port;a[7]=this.name;a[8]=this.device_control;a[9]=this.prdt_addr;a[10]=this.dma_status;
478
- a[11]=this.current_interface===this.master;a[12]=this.dma_command;return a};Tc.prototype.set_state=function(a){this.master.set_state(a[0]);this.slave.set_state(a[1]);this.ata_port=a[2];this.irq=a[3];this.pci_id=a[4];this.ata_port_high=a[5];this.master_port=a[6];this.name=a[7];this.device_control=a[8];this.prdt_addr=a[9];this.dma_status=a[10];this.current_interface=a[11]?this.master:this.slave;this.dma_command=a[12]};function W(a,b,c,d,e,f,h){this.device=a;this.bus=h;this.nr=e;this.cpu=b;this.buffer=
479
- c;this.sector_size=d?2048:512;this.is_atapi=d;this.cylinder_count=this.sectors_per_track=this.head_count=this.sector_count=0;this.buffer&&(this.sector_count=this.buffer.byteLength/this.sector_size,this.sector_count!==(this.sector_count|0)&&(C("Warning: Disk size not aligned with sector size",32768),this.sector_count=Math.ceil(this.sector_count)),d?(this.head_count=1,this.sectors_per_track=0):(this.head_count=16,this.sectors_per_track=63),this.cylinder_count=this.sector_count/this.head_count/this.sectors_per_track,
480
- this.cylinder_count!==(this.cylinder_count|0)&&(C("Warning: Rounding up cylinder count. Choose different head number",32768),this.cylinder_count=Math.floor(this.cylinder_count)),a=b.devices.rtc,a.cmos_write(57,a.cmos_read(57)|1<<4*this.nr),a.cmos_write(18,a.cmos_read(18)&15|240),a.cmos_write(27,this.cylinder_count&255),a.cmos_write(28,this.cylinder_count>>8&255),a.cmos_write(29,this.head_count&255),a.cmos_write(30,255),a.cmos_write(31,255),a.cmos_write(32,200),a.cmos_write(33,this.cylinder_count&
481
- 255),a.cmos_write(34,this.cylinder_count>>8&255),a.cmos_write(35,this.sectors_per_track&255));this.buffer=c;this.drive_head=this.head=this.cylinder_high=this.cylinder_low=this.lba_count=this.sector=this.bytecount=this.is_lba=0;this.status=80;this.sectors_per_drq=128;this.data_pointer=this.error=0;this.data=new Uint8Array(65536);this.data16=new Uint16Array(this.data.buffer);this.data32=new Int32Array(this.data.buffer);this.data_end=this.data_length=0;this.current_atapi_command=this.current_command=
482
- -1;this.last_io_id=this.write_dest=0;this.in_progress_io_ids=new Set;this.cancelled_io_ids=new Set;Object.seal(this)}W.prototype.device_reset=function(){this.is_atapi?(this.status=0,this.sector=this.error=this.bytecount=1,this.cylinder_low=20,this.cylinder_high=235):(this.status=81,this.sector=this.error=this.bytecount=1,this.cylinder_high=this.cylinder_low=0);this.cancel_io_operations()};W.prototype.push_irq=function(){this.device.push_irq()};W.prototype.ata_command=function(a){C("ATA Command: "+
483
- m(a)+" slave="+(this.drive_head>>4&1),32768);if(this.buffer)switch(this.current_command=a,this.error=0,a){case 8:C("ATA device reset",32768);this.data_length=this.data_end=this.data_pointer=0;this.device_reset();this.push_irq();break;case 16:this.status=80;this.cylinder_low=0;this.push_irq();break;case 248:this.status=80;a=this.sector_count-1;this.sector=a&255;this.cylinder_low=a>>8&255;this.cylinder_high=a>>16&255;this.drive_head=this.drive_head&240|a>>24&15;this.push_irq();break;case 39:this.status=
484
- 80;a=this.sector_count-1;this.sector=a&255;this.cylinder_low=a>>8&255;this.cylinder_high=a>>16&255;this.sector|=a>>24<<8&65280;this.push_irq();break;case 32:case 36:case 41:case 196:this.ata_read_sectors(a);break;case 48:case 52:case 57:case 197:this.ata_write_sectors(a);break;case 144:this.push_irq();this.error=257;this.status=80;break;case 145:this.status=80;this.push_irq();break;case 160:this.is_atapi&&(this.status=88,this.data_allocate(12),this.data_end=12,this.bytecount=1,this.push_irq());break;
485
- case 161:C("ATA identify packet device",32768);this.is_atapi?(this.create_identify_packet(),this.status=88,this.cylinder_low=20,this.cylinder_high=235):this.status=65;this.push_irq();break;case 198:C("Logical sectors per DRQ Block: "+m(this.bytecount&255),32768);this.sectors_per_drq=this.bytecount&255;this.status=80;this.push_irq();break;case 37:case 200:this.ata_read_sectors_dma(a);break;case 53:case 202:this.ata_write_sectors_dma(a);break;case 64:C("read verify sectors",32768);this.status=80;this.push_irq();
486
- break;case 218:C("Unimplemented: get media status",32768);this.status=65;this.error=4;this.push_irq();break;case 224:C("ATA standby immediate",32768);this.status=80;this.push_irq();break;case 225:C("ATA idle immediate",32768);this.status=80;this.push_irq();break;case 231:C("ATA flush cache",32768);this.status=80;this.push_irq();break;case 236:C("ATA identify device",32768);if(this.is_atapi){this.status=65;this.error=4;this.push_irq();break}this.create_identify_packet();this.status=88;this.push_irq();
487
- break;case 234:C("flush cache ext",32768);this.status=80;this.push_irq();break;case 239:C("set features: "+m(this.bytecount&255),32768);this.status=80;this.push_irq();break;case 222:this.status=80;this.push_irq();break;case 245:C("security freeze lock",32768);this.status=80;this.push_irq();break;case 249:C("Unimplemented: set max address",32768);this.status=65;this.error=4;break;default:k(!1,"New ATA cmd on 1F7: "+m(a),32768),this.status=65,this.error=4}else C("abort: No buffer",32768),this.error=
488
- 4,this.status=65,this.push_irq()};W.prototype.atapi_handle=function(){C("ATAPI Command: "+m(this.data[0])+" slave="+(this.drive_head>>4&1),32768);this.data_pointer=0;this.current_atapi_command=this.data[0];switch(this.current_atapi_command){case 0:C("test unit ready",32768);this.data_allocate(0);this.data_end=this.data_length;this.status=80;break;case 3:this.data_allocate(this.data[4]);this.data_end=this.data_length;this.status=88;this.data[0]=240;this.data[2]=5;this.data[7]=8;break;case 18:var a=
489
- this.data[4];this.status=88;C("inquiry: "+m(this.data[1],2)+" length="+a,32768);this.data.set([5,128,1,49,31,0,0,0,83,79,78,89,32,32,32,32,67,68,45,82,79,77,32,67,68,85,45,49,48,48,48,32,49,46,49,97]);this.data_end=this.data_length=Math.min(36,a);break;case 26:this.data_allocate(this.data[4]);this.data_end=this.data_length;this.status=88;break;case 30:this.data_allocate(0);this.data_end=this.data_length;this.status=80;break;case 37:a=this.sector_count-1;this.data_set(new Uint8Array([a>>24&255,a>>
490
- 16&255,a>>8&255,a&255,0,0,this.sector_size>>8&255,this.sector_size&255]));this.data_end=this.data_length;this.status=88;break;case 40:this.lba_count&1?this.atapi_read_dma(this.data):this.atapi_read(this.data);break;case 66:a=this.data[8];this.data_allocate(Math.min(8,a));this.data_end=this.data_length;C("read q subcode: length="+a,32768);this.status=88;break;case 67:a=this.data[8]|this.data[7]<<8;var b=this.data[9]>>6;this.data_allocate(a);this.data_end=this.data_length;C("read toc: "+m(b,2)+" length="+
491
- a+" "+(this.data[1]&2)+" "+m(this.data[6]),32768);0===b?(a=this.sector_count,this.data.set(new Uint8Array([0,18,1,1,0,20,1,0,0,0,0,0,0,22,170,0,a>>24,a>>16&255,a>>8&255,a&255]))):1===b?this.data.set(new Uint8Array([0,10,1,1,0,0,0,0,0,0,0,0])):k(!1,"Unimplemented format: "+b);this.status=88;break;case 70:a=this.data[8]|this.data[7]<<8;a=Math.min(a,32);this.data_allocate(a);this.data_end=this.data_length;this.data[0]=a-4>>24&255;this.data[1]=a-4>>16&255;this.data[2]=a-4>>8&255;this.data[3]=a-4&255;
492
- this.data[6]=8;this.data[10]=3;this.status=88;break;case 81:this.data_allocate(0);this.data_end=this.data_length;this.status=80;break;case 82:C("Unimplemented ATAPI command: "+m(this.data[0]),32768);this.status=81;this.data_length=0;this.error=80;break;case 90:a=this.data[8]|this.data[7]<<8;b=this.data[2];C("mode sense: "+m(b)+" length="+a,32768);42===b&&this.data_allocate(Math.min(30,a));this.data_end=this.data_length;this.status=88;break;case 189:this.data_allocate(this.data[9]|this.data[8]<<8);
493
- this.data_end=this.data_length;this.data[5]=1;this.status=88;break;case 74:this.status=81;this.data_length=0;this.error=80;C("Unimplemented ATAPI command: "+m(this.data[0]),32768);break;case 190:C("Unimplemented ATAPI command: "+m(this.data[0]),32768);this.data_allocate(0);this.data_end=this.data_length;this.status=80;break;default:this.status=81,this.data_length=0,this.error=80,C("Unimplemented ATAPI command: "+m(this.data[0]),32768),k(!1)}this.bytecount=this.bytecount&-8|2;0===(this.status&128)&&
494
- this.push_irq();0===(this.status&128)&&0===this.data_length&&(this.bytecount|=1,this.status&=-9)};W.prototype.do_write=function(){this.status=80;k(this.data_length<=this.data.length);var a=this.data.subarray(0,this.data_length);k(0===this.data_length%512);this.ata_advance(this.current_command,this.data_length/512);this.push_irq();this.buffer.set(this.write_dest,a,function(){});this.report_write(this.data_length)};W.prototype.atapi_read=function(a){var b=a[2]<<24|a[3]<<16|a[4]<<8|a[5],c=a[7]<<8|a[8];
495
- a=a[1];var d=c*this.sector_size,e=b*this.sector_size;C("CD read lba="+m(b)+" lbacount="+m(c)+" bytecount="+m(d)+" flags="+m(a),32768);this.data_length=0;var f=this.cylinder_high<<8&65280|this.cylinder_low&255;C(m(this.cylinder_high,2)+" "+m(this.cylinder_low,2),32768);this.cylinder_low=this.cylinder_high=0;65535===f&&f--;f>d&&(f=d);e>=this.buffer.byteLength?(k(!1,"CD read: Outside of disk end="+m(e+d)+" size="+m(this.buffer.byteLength),32768),this.status=255,this.push_irq()):0===d?(this.status=80,
496
- this.data_pointer=0):(d=Math.min(d,this.buffer.byteLength-e),this.status=208,this.report_read_start(),this.read_buffer(e,d,h=>{C("cd read: data arrived",32768);this.data_set(h);this.status=88;this.bytecount=this.bytecount&-8|2;this.push_irq();this.data_end=f&=-4;this.data_end>this.data_length&&(this.data_end=this.data_length);this.cylinder_low=this.data_end&255;this.cylinder_high=this.data_end>>8&255;this.report_read_end(d)}))};W.prototype.atapi_read_dma=function(a){var b=a[2]<<24|a[3]<<16|a[4]<<
497
- 8|a[5],c=a[7]<<8|a[8];a=a[1];var d=c*this.sector_size,e=b*this.sector_size;C("CD read DMA lba="+m(b)+" lbacount="+m(c)+" bytecount="+m(d)+" flags="+m(a),32768);e>=this.buffer.byteLength?(k(!1,"CD read: Outside of disk end="+m(e+d)+" size="+m(this.buffer.byteLength),32768),this.status=255,this.push_irq()):(this.status=208,this.report_read_start(),this.read_buffer(e,d,f=>{C("atapi_read_dma: Data arrived");this.report_read_end(d);this.status=88;this.bytecount=this.bytecount&-8|2;this.data_set(f);this.do_atapi_dma()}))};
498
- W.prototype.do_atapi_dma=function(){if(0===(this.device.dma_status&1))C("do_atapi_dma: Status not set",32768);else if(0===(this.status&8))C("do_atapi_dma: DRQ not set",32768);else{C("atapi dma transfer len="+this.data_length,32768);var a=this.device.prdt_addr,b=0,c=this.data;do{var d=this.cpu.read32s(a),e=this.cpu.read16(a+4),f=this.cpu.read8(a+7)&128;e||(e=65536);C("dma read dest="+m(d)+" count="+m(e)+" datalen="+m(this.data_length),32768);this.cpu.write_blob(c.subarray(b,Math.min(b+e,this.data_length)),
499
- d);b+=e;a+=8;if(b>=this.data_length&&!f){C("leave early end="+ +f+" offset="+m(b)+" data_length="+m(this.data_length)+" cmd="+m(this.current_command),32768);break}}while(!f);C("end offset="+b,32768);this.status=80;this.device.dma_status&=-2;this.bytecount=this.bytecount&-8|3;this.push_irq()}};W.prototype.read_data=function(a){if(this.data_pointer<this.data_end){k(this.data_pointer+a-1<this.data_end);k(0===this.data_pointer%a,m(this.data_pointer)+" "+a);var b=1===a?this.data[this.data_pointer]:2===
500
- a?this.data16[this.data_pointer>>>1]:this.data32[this.data_pointer>>>2];this.data_pointer+=a;0===(this.data_pointer&(0===(this.data_end&4095)?4095:255))&&C("Read 1F0: "+m(this.data[this.data_pointer],2)+" cur="+m(this.data_pointer)+" cnt="+m(this.data_length),32768);this.data_pointer>=this.data_end&&this.read_end();return b}C("Read 1F0: empty",32768);this.data_pointer+=a;return 0};W.prototype.read_end=function(){C("read_end cmd="+m(this.current_command)+" data_pointer="+m(this.data_pointer)+" end="+
501
- m(this.data_end)+" length="+m(this.data_length),32768);if(160===this.current_command)if(this.data_end===this.data_length)this.status=80,this.bytecount=this.bytecount&-8|3,this.push_irq();else{this.status=88;this.bytecount=this.bytecount&-8|2;this.push_irq();var a=this.cylinder_high<<8&65280|this.cylinder_low&255;this.data_end+a>this.data_length?(this.cylinder_low=this.data_length-this.data_end&255,this.cylinder_high=this.data_length-this.data_end>>8&255,this.data_end=this.data_length):this.data_end+=
502
- a;C("data_end="+m(this.data_end),32768)}else this.error=0,this.data_pointer>=this.data_length?this.status=80:(196===this.current_command||41===this.current_command?(a=Math.min(this.sectors_per_drq,(this.data_length-this.data_end)/512),k(0===a%1)):(k(32===this.current_command||36===this.current_command),a=1),this.ata_advance(this.current_command,a),this.data_end+=512*a,this.status=88,this.push_irq())};W.prototype.write_data_port=function(a,b){k(0===this.data_pointer%b);this.data_pointer>=this.data_end?
503
- C("Redundant write to data port: "+m(a)+" count="+m(this.data_end)+" cur="+m(this.data_pointer),32768):((0===(this.data_pointer+b&(0===(this.data_end&4095)?4095:255))||20>this.data_end)&&C("Data port: "+m(a>>>0)+" count="+m(this.data_end)+" cur="+m(this.data_pointer),32768),1===b?this.data[this.data_pointer++]=a:2===b?(this.data16[this.data_pointer>>>1]=a,this.data_pointer+=2):(this.data32[this.data_pointer>>>2]=a,this.data_pointer+=4),k(this.data_pointer<=this.data_end),this.data_pointer===this.data_end&&
504
- this.write_end())};W.prototype.write_data_port8=function(a){this.write_data_port(a,1)};W.prototype.write_data_port16=function(a){this.write_data_port(a,2)};W.prototype.write_data_port32=function(a){this.write_data_port(a,4)};W.prototype.write_end=function(){160===this.current_command?this.atapi_handle():(C("write_end data_pointer="+m(this.data_pointer)+" data_length="+m(this.data_length),32768),this.data_pointer>=this.data_length?this.do_write():(k(48===this.current_command||52===this.current_command||
505
- 197===this.current_command,"Unexpected command: "+m(this.current_command)),this.status=88,this.data_end+=512,this.push_irq()))};W.prototype.ata_advance=function(a,b){C("Advance sectors="+b+" old_bytecount="+this.bytecount,32768);this.bytecount-=b;36===a||41===a||52===a||57===a||37===a||53===a?(a=b+this.get_lba48(),this.sector=a&255|a>>16&65280,this.cylinder_low=a>>8&255,this.cylinder_high=a>>16&255):this.is_lba?(a=b+this.get_lba28(),this.sector=a&255,this.cylinder_low=a>>8&255,this.cylinder_high=
506
- a>>16&255,this.head=this.head&-16|a&15):(a=b+this.get_chs(),b=a/(this.head_count*this.sectors_per_track)|0,this.cylinder_low=b&255,this.cylinder_high=b>>8&255,this.head=(a/this.sectors_per_track|0)%this.head_count&15,this.sector=a%this.sectors_per_track+1&255,k(a===this.get_chs()))};W.prototype.ata_read_sectors=function(a){var b=36===a||41===a,c=this.get_count(b);b=this.get_lba(b);var d=32===a||36===a,e=c*this.sector_size,f=b*this.sector_size;C("ATA read cmd="+m(a)+" mode="+(this.is_lba?"lba":"chs")+
507
- " lba="+m(b)+" lbacount="+m(c)+" bytecount="+m(e),32768);f+e>this.buffer.byteLength?(k(!1,"ATA read: Outside of disk",32768),this.status=255,this.push_irq()):(this.status=192,this.report_read_start(),this.read_buffer(f,e,h=>{C("ata_read: Data arrived",32768);this.data_set(h);this.status=88;this.data_end=d?512:Math.min(e,512*this.sectors_per_drq);this.ata_advance(a,d?1:Math.min(c,this.sectors_per_track));this.push_irq();this.report_read_end(e)}))};W.prototype.ata_read_sectors_dma=function(a){var b=
508
- 37===a;a=this.get_count(b);b=this.get_lba(b);var c=a*this.sector_size,d=b*this.sector_size;C("ATA DMA read lba="+m(b)+" lbacount="+m(a)+" bytecount="+m(c),32768);d+c>this.buffer.byteLength?(k(!1,"ATA read: Outside of disk",32768),this.status=255,this.push_irq()):(this.status=88,this.device.dma_status|=1)};W.prototype.do_ata_read_sectors_dma=function(){var a=37===this.current_command,b=this.get_count(a);a=this.get_lba(a);var c=b*this.sector_size,d=a*this.sector_size;k(a<this.buffer.byteLength);this.report_read_start();
509
- var e=this.device.prdt_addr;this.read_buffer(d,c,f=>{C("do_ata_read_sectors_dma: Data arrived",32768);var h=this.device.prdt_addr,l=0;k(e===h);do{var p=this.cpu.read32s(h),n=this.cpu.read16(h+4),q=this.cpu.read8(h+7)&128;n||(n=65536,C("dma: prd count was 0",32768));C("dma read transfer dest="+m(p)+" prd_count="+m(n),32768);this.cpu.write_blob(f.subarray(l,l+n),p);l+=n;h+=8}while(!q);k(l===c);this.ata_advance(this.current_command,b);this.status=80;this.device.dma_status&=-2;this.current_command=-1;
510
- this.push_irq();this.report_read_end(c)})};W.prototype.ata_write_sectors=function(a){var b=52===a||57===a,c=this.get_count(b);b=this.get_lba(b);a=48===a||52===a;var d=c*this.sector_size,e=b*this.sector_size;C("ATA write lba="+m(b)+" mode="+(this.is_lba?"lba":"chs")+" lbacount="+m(c)+" bytecount="+m(d),32768);e+d>this.buffer.byteLength?(k(!1,"ATA write: Outside of disk",32768),this.status=255,this.push_irq()):(this.status=88,this.data_allocate_noclear(d),this.data_end=a?512:Math.min(d,512*this.sectors_per_drq),
511
- this.write_dest=e)};W.prototype.ata_write_sectors_dma=function(a){var b=53===a;a=this.get_count(b);b=this.get_lba(b);var c=a*this.sector_size,d=b*this.sector_size;C("ATA DMA write lba="+m(b)+" lbacount="+m(a)+" bytecount="+m(c),32768);d+c>this.buffer.byteLength?(k(!1,"ATA DMA write: Outside of disk",32768),this.status=255,this.push_irq()):(this.status=88,this.device.dma_status|=1)};W.prototype.do_ata_write_sectors_dma=function(){var a=53===this.current_command,b=this.get_count(a),c=this.get_lba(a);
512
- a=b*this.sector_size;c*=this.sector_size;var d=this.device.prdt_addr,e=0;C("prdt addr: "+m(d,8),32768);const f=new Uint8Array(a);do{var h=this.cpu.read32s(d),l=this.cpu.read16(d+4),p=this.cpu.read8(d+7)&128;l||(l=65536,C("dma: prd count was 0",32768));C("dma write transfer dest="+m(h)+" prd_count="+m(l),32768);h=this.cpu.mem8.subarray(h,h+l);k(h.length===l);f.set(h,e);e+=l;d+=8}while(!p);k(e===f.length);this.buffer.set(c,f,()=>{C("dma write completed",32768);this.ata_advance(this.current_command,
513
- b);this.status=80;this.push_irq();this.device.dma_status&=-2;this.current_command=-1});this.report_write(a)};W.prototype.get_chs=function(){var a=this.cylinder_low&255|this.cylinder_high<<8&65280,b=this.head,c=this.sector&255;C("get_chs: c="+a+" h="+b+" s="+c,32768);return(a*this.head_count+b)*this.sectors_per_track+c-1};W.prototype.get_lba28=function(){return this.sector&255|this.cylinder_low<<8&65280|this.cylinder_high<<16&16711680|(this.head&15)<<24};W.prototype.get_lba48=function(){return(this.sector&
514
- 255|this.cylinder_low<<8&65280|this.cylinder_high<<16&16711680|this.sector>>8<<24&4278190080)>>>0};W.prototype.get_lba=function(a){return a?this.get_lba48():this.is_lba?this.get_lba28():this.get_chs()};W.prototype.get_count=function(a){a?(a=this.bytecount,0===a&&(a=65536)):(a=this.bytecount&255,0===a&&(a=256));return a};W.prototype.create_identify_packet=function(){if(this.drive_head&16)this.data_allocate(0);else{for(var a=0;512>a;a++)this.data[a]=0;a=Math.min(16383,this.cylinder_count);this.data_set([64,
515
- this.is_atapi?133:0,a,a>>8,0,0,this.head_count,this.head_count>>8,this.sectors_per_track/512,this.sectors_per_track/512>>8,0,2,this.sectors_per_track,this.sectors_per_track>>8,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,3,0,0,2,4,0,0,0,0,0,0,0,0,0,56,118,32,54,68,72,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,128,0,1,0,0,2,0,0,0,2,0,2,7,0,a,a>>8,this.head_count,this.head_count>>8,this.sectors_per_track,0,this.sector_count&255,this.sector_count>>
516
- 8&255,this.sector_count>>16&255,this.sector_count>>24&255,0,0,this.sector_count&255,this.sector_count>>8&255,this.sector_count>>16&255,this.sector_count>>24&255,0,0,160===this.current_command?0:7,160===this.current_command?0:4,0,0,30,0,30,0,30,0,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,126,0,0,0,0,0,0,116,0,64,0,64,0,116,0,64,0,0,0,0,0,0,0,0,0,0,1,96,0,0,0,0,0,0,0,0,0,0,0,0,this.sector_count&255,this.sector_count>>8&255,this.sector_count>>16&255,this.sector_count>>24&255]);this.data_end=this.data_length=
517
- 512}};W.prototype.data_allocate=function(a){this.data_allocate_noclear(a);for(var b=0;b<a+3>>2;b++)this.data32[b]=0};W.prototype.data_allocate_noclear=function(a){this.data.length<a&&(this.data=new Uint8Array(a+3&-4),this.data16=new Uint16Array(this.data.buffer),this.data32=new Int32Array(this.data.buffer));this.data_length=a;this.data_pointer=0};W.prototype.data_set=function(a){this.data_allocate_noclear(a.length);this.data.set(a)};W.prototype.report_read_start=function(){this.bus.send("ide-read-start")};
518
- W.prototype.report_read_end=function(a){this.bus.send("ide-read-end",[this.nr,a,a/this.sector_size|0])};W.prototype.report_write=function(a){this.bus.send("ide-write-end",[this.nr,a,a/this.sector_size|0])};W.prototype.read_buffer=function(a,b,c){const d=this.last_io_id++;this.in_progress_io_ids.add(d);this.buffer.get(a,b,e=>{if(this.cancelled_io_ids.delete(d))k(!this.in_progress_io_ids.has(d));else{var f=this.in_progress_io_ids.delete(d);k(f);c(e)}})};W.prototype.cancel_io_operations=function(){for(const a of this.in_progress_io_ids)this.cancelled_io_ids.add(a);
519
- this.in_progress_io_ids.clear()};W.prototype.get_state=function(){var a=[];a[0]=this.bytecount;a[1]=this.cylinder_count;a[2]=this.cylinder_high;a[3]=this.cylinder_low;a[4]=this.data_pointer;a[5]=0;a[6]=0;a[7]=0;a[8]=0;a[9]=this.drive_head;a[10]=this.error;a[11]=this.head;a[12]=this.head_count;a[13]=this.is_atapi;a[14]=this.is_lba;a[15]=this.lba_count;a[16]=this.data;a[17]=this.data_length;a[18]=this.sector;a[19]=this.sector_count;a[20]=this.sector_size;a[21]=this.sectors_per_drq;a[22]=this.sectors_per_track;
520
- a[23]=this.status;a[24]=this.write_dest;a[25]=this.current_command;a[26]=this.data_end;a[27]=this.current_atapi_command;a[28]=this.buffer;return a};W.prototype.set_state=function(a){this.bytecount=a[0];this.cylinder_count=a[1];this.cylinder_high=a[2];this.cylinder_low=a[3];this.data_pointer=a[4];this.drive_head=a[9];this.error=a[10];this.head=a[11];this.head_count=a[12];this.is_atapi=a[13];this.is_lba=a[14];this.lba_count=a[15];this.data=a[16];this.data_length=a[17];this.sector=a[18];this.sector_count=
521
- a[19];this.sector_size=a[20];this.sectors_per_drq=a[21];this.sectors_per_track=a[22];this.status=a[23];this.write_dest=a[24];this.current_command=a[25];this.data_end=a[26];this.current_atapi_command=a[27];this.data16=new Uint16Array(this.data.buffer);this.data32=new Int32Array(this.data.buffer);this.buffer&&this.buffer.set_state(a[28])};function Uc(a,b,c){this.bus=b;this.id=a.devices.net?1:0;this.status=this.pairs=1;this.preserve_mac_from_state_image=c;this.mac=new Uint8Array([0,34,21,255*Math.random()|
522
- 0,255*Math.random()|0,255*Math.random()|0]);this.bus.send("net"+this.id+"-mac",Fc(this.mac));b=[];for(c=0;c<this.pairs;++c)b.push({size_supported:1024,notify_offset:0}),b.push({size_supported:1024,notify_offset:1});b.push({size_supported:16,notify_offset:2});this.virtio=new Ic(a,{name:"virtio-net",pci_id:80,device_id:4161,subsystem_device_id:1,common:{initial_port:51200,queues:b,features:[5,16,22,3,17,23,32],on_driver_ok:()=>{}},notification:{initial_port:51456,single_handler:!1,handlers:[()=>{},
523
- d=>{const e=this.virtio.queues[d];for(;e.has_request();){const f=e.pop_request(),h=new Uint8Array(f.length_readable);f.get_next_blob(h);this.bus.send("net"+this.id+"-send",h.subarray(12));this.bus.send("eth-transmit-end",[h.length-12]);this.virtio.queues[d].push_reply(f)}this.virtio.queues[d].flush_replies()},d=>{if(d!==2*this.pairs)k(!1,"VirtioNet Notified for wrong queue: "+d+" (expected queue_id of 3)");else for(var e=this.virtio.queues[d];e.has_request();){const l=e.pop_request();var f=new Uint8Array(l.length_readable);
524
- l.get_next_blob(f);var h=M(["b","b"],f,{offset:0});const p=h[0];h=h[1];switch(p<<8|h){case 1024:f=M(["h"],f,{offset:2});k(1===f[0]);this.Send(d,l,new Uint8Array([0]));break;case 257:this.mac=f.subarray(2,8);this.Send(d,l,new Uint8Array([0]));this.bus.send("net"+this.id+"-mac",Fc(this.mac));break;default:k(!1," VirtioNet received unknown command: "+p+":"+h);this.Send(d,l,new Uint8Array([1]));return}}}]},isr_status:{initial_port:50944},device_specific:{initial_port:50688,struct:[0,1,2,3,4,5].map((d,
525
- e)=>({bytes:1,name:"mac_"+e,read:()=>this.mac[e],write:()=>{}})).concat([{bytes:2,name:"status",read:()=>this.status,write:()=>{}},{bytes:2,name:"max_pairs",read:()=>this.pairs,write:()=>{}},{bytes:2,name:"mtu",read:()=>1500,write:()=>{}}])}});this.bus.register("net"+this.id+"-receive",d=>{this.bus.send("eth-receive-end",[d.length]);const e=new Uint8Array(12+d.byteLength);(new DataView(e.buffer,e.byteOffset,e.byteLength)).setInt16(10,1);e.set(d,12);d=this.virtio.queues[0];d.has_request()?(d=d.pop_request(),
526
- d.set_next_blob(e),this.virtio.queues[0].push_reply(d),this.virtio.queues[0].flush_replies()):console.log("No buffer to write into!")},this)}Uc.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.id;a[2]=this.mac;return a};Uc.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.id=a[1];this.preserve_mac_from_state_image&&(this.mac=a[2],this.bus.send("net"+this.id+"-mac",Fc(this.mac)))};Uc.prototype.reset=function(){this.virtio.reset()};Uc.prototype.Send=function(a,b,c){b.set_next_blob(c);
527
- this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};Uc.prototype.Ack=function(a,b){this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};const Vc=Uint32Array.from([655360,655360,720896,753664]),Wc=Uint32Array.from([131072,65536,32768,32768]);function X(a,b,c,d){this.cpu=a;this.bus=b;this.screen=c;this.vga_memory_size=d;this.cursor_address=0;this.cursor_scanline_start=14;this.cursor_scanline_end=15;this.max_cols=80;this.max_rows=25;this.virtual_height=this.virtual_width=
528
- this.screen_height=this.screen_width=0;this.layers=[];this.start_address_latched=this.start_address=0;this.crtc=new Uint8Array(25);this.line_compare=this.offset_register=this.preset_row_scan=this.underline_location_register=this.vertical_blank_start=this.vertical_display_enable_end=this.horizontal_blank_start=this.horizontal_display_enable_end=this.crtc_mode=0;this.graphical_mode=!1;this.vga256_palette=new Int32Array(256);this.latch_dword=0;this.svga_version=45253;this.svga_height=this.svga_width=
529
- 0;this.svga_enabled=!1;this.svga_bpp=32;this.svga_offset_y=this.svga_offset_x=this.svga_offset=this.svga_bank_offset=0;this.vga_memory_size=void 0===this.vga_memory_size||262144>this.vga_memory_size?262144:268435456<this.vga_memory_size?268435456:ka(this.vga_memory_size);C("effective vga memory size: "+this.vga_memory_size,256);this.pci_space=[52,18,17,17,3,1,0,0,0,0,0,3,0,0,0,0,8,14680064,57344,224,0,0,0,0,0,0,191,254,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,244,26,0,17,0,0,190,254,0,0,0,0,0,0,0,0,0,0,0,
530
- 0];this.pci_id=144;this.pci_bars=[{size:this.vga_memory_size}];this.pci_rom_size=65536;this.pci_rom_address=4272947200;this.name="vga";this.dac_state=this.dac_color_index_read=this.dac_color_index_write=this.index_crtc=0;this.dac_mask=255;this.dac_map=new Uint8Array(16);this.attribute_controller_index=-1;this.palette_source=32;this.color_select=this.horizontal_panning=this.color_plane_enable=this.attribute_mode=0;this.sequencer_index=-1;this.plane_write_bm=15;this.clocking_mode=this.sequencer_memory_mode=
531
- 0;this.graphics_index=-1;this.planar_rotate_reg=this.planar_mode=this.plane_read=this.character_map_select=0;this.planar_bitmap=255;this.max_scan_line=this.color_dont_care=this.color_compare=this.miscellaneous_graphics_register=this.planar_setreset_enable=this.planar_setreset=0;this.port_3DA_value=this.miscellaneous_output_register=255;this.font_page_ab_enabled=!1;b=a.io;b.register_write(960,this,this.port3C0_write);b.register_read(960,this,this.port3C0_read,this.port3C0_read16);b.register_read(961,
532
- this,this.port3C1_read);b.register_write(962,this,this.port3C2_write);b.register_write_consecutive(964,this,this.port3C4_write,this.port3C5_write);b.register_read(964,this,this.port3C4_read);b.register_read(965,this,this.port3C5_read);b.register_write_consecutive(974,this,this.port3CE_write,this.port3CF_write);b.register_read(974,this,this.port3CE_read);b.register_read(975,this,this.port3CF_read);b.register_read(966,this,this.port3C6_read);b.register_write(966,this,this.port3C6_write);b.register_write(967,
533
- this,this.port3C7_write);b.register_read(967,this,this.port3C7_read);b.register_write(968,this,this.port3C8_write);b.register_read(968,this,this.port3C8_read);b.register_write(969,this,this.port3C9_write);b.register_read(969,this,this.port3C9_read);b.register_read(972,this,this.port3CC_read);b.register_write(980,this,this.port3D4_write,this.port3D4_write16);b.register_write(981,this,this.port3D5_write,this.port3D5_write16);b.register_read(980,this,this.port3D4_read);b.register_read(981,this,this.port3D5_read,
534
- this.port3D5_read16);b.register_write(948,this,this.port3D4_write,this.port3D4_write16);b.register_write(949,this,this.port3D5_write,this.port3D5_write16);b.register_read(948,this,this.port3D4_read);b.register_read(949,this,this.port3D5_read,this.port3D5_read16);b.register_read(970,this,function(){C("3CA read",256);return 0});b.register_read(986,this,this.port3DA_read);b.register_read(954,this,this.port3DA_read);this.dispi_index=-1;this.dispi_enable_value=0;b.register_write(462,this,void 0,this.port1CE_write);
535
- b.register_write(463,this,void 0,this.port1CF_write);b.register_read(463,this,void 0,this.port1CF_read);c=a.svga_allocate_memory(this.vga_memory_size)>>>0;this.svga_memory=g(Uint8Array,a.wasm_memory,c,this.vga_memory_size);this.diff_addr_min=this.vga_memory_size;this.diff_addr_max=0;this.diff_plot_min=this.vga_memory_size;this.diff_plot_max=0;this.image_data=null;this.vga_memory=new Uint8Array(262144);this.plane0=new Uint8Array(this.vga_memory.buffer,0,65536);this.plane1=new Uint8Array(this.vga_memory.buffer,
536
- 65536,65536);this.plane2=new Uint8Array(this.vga_memory.buffer,131072,65536);this.plane3=new Uint8Array(this.vga_memory.buffer,196608,65536);this.pixel_buffer=new Uint8Array(524288);b.mmap_register(655360,131072,e=>this.vga_memory_read(e),(e,f)=>this.vga_memory_write(e,f));a.devices.pci.register_device(this)}X.prototype.get_state=function(){var a=[];a[0]=this.vga_memory_size;a[1]=this.cursor_address;a[2]=this.cursor_scanline_start;a[3]=this.cursor_scanline_end;a[4]=this.max_cols;a[5]=this.max_rows;
537
- a[6]=this.vga_memory;a[7]=this.dac_state;a[8]=this.start_address;a[9]=this.graphical_mode;a[10]=this.vga256_palette;a[11]=this.latch_dword;a[12]=this.color_compare;a[13]=this.color_dont_care;a[14]=this.miscellaneous_graphics_register;a[15]=this.svga_width;a[16]=this.svga_height;a[17]=this.crtc_mode;a[18]=this.svga_enabled;a[19]=this.svga_bpp;a[20]=this.svga_bank_offset;a[21]=this.svga_offset;a[22]=this.index_crtc;a[23]=this.dac_color_index_write;a[24]=this.dac_color_index_read;a[25]=this.dac_map;
538
- a[26]=this.sequencer_index;a[27]=this.plane_write_bm;a[28]=this.sequencer_memory_mode;a[29]=this.graphics_index;a[30]=this.plane_read;a[31]=this.planar_mode;a[32]=this.planar_rotate_reg;a[33]=this.planar_bitmap;a[34]=this.max_scan_line;a[35]=this.miscellaneous_output_register;a[36]=this.port_3DA_value;a[37]=this.dispi_index;a[38]=this.dispi_enable_value;a[39]=this.svga_memory;a[41]=this.attribute_controller_index;a[42]=this.offset_register;a[43]=this.planar_setreset;a[44]=this.planar_setreset_enable;
539
- a[45]=this.start_address_latched;a[46]=this.crtc;a[47]=this.horizontal_display_enable_end;a[48]=this.horizontal_blank_start;a[49]=this.vertical_display_enable_end;a[50]=this.vertical_blank_start;a[51]=this.underline_location_register;a[52]=this.preset_row_scan;a[53]=this.offset_register;a[54]=this.palette_source;a[55]=this.attribute_mode;a[56]=this.color_plane_enable;a[57]=this.horizontal_panning;a[58]=this.color_select;a[59]=this.clocking_mode;a[60]=this.line_compare;a[61]=this.pixel_buffer;a[62]=
540
- this.dac_mask;a[63]=this.character_map_select;a[64]=this.font_page_ab_enabled;return a};X.prototype.set_state=function(a){this.vga_memory_size=a[0];this.cursor_address=a[1];this.cursor_scanline_start=a[2];this.cursor_scanline_end=a[3];this.max_cols=a[4];this.max_rows=a[5];a[6]&&this.vga_memory.set(a[6]);this.dac_state=a[7];this.start_address=a[8];this.graphical_mode=a[9];this.vga256_palette=a[10];this.latch_dword=a[11];this.color_compare=a[12];this.color_dont_care=a[13];this.miscellaneous_graphics_register=
541
- a[14];this.svga_width=a[15];this.svga_height=a[16];this.crtc_mode=a[17];this.svga_enabled=a[18];this.svga_bpp=a[19];this.svga_bank_offset=a[20];this.svga_offset=a[21];this.index_crtc=a[22];this.dac_color_index_write=a[23];this.dac_color_index_read=a[24];this.dac_map=a[25];this.sequencer_index=a[26];this.plane_write_bm=a[27];this.sequencer_memory_mode=a[28];this.graphics_index=a[29];this.plane_read=a[30];this.planar_mode=a[31];this.planar_rotate_reg=a[32];this.planar_bitmap=a[33];this.max_scan_line=
542
- a[34];this.miscellaneous_output_register=a[35];this.port_3DA_value=a[36];this.dispi_index=a[37];this.dispi_enable_value=a[38];this.svga_memory.set(a[39]);this.attribute_controller_index=a[41];this.offset_register=a[42];this.planar_setreset=a[43];this.planar_setreset_enable=a[44];this.start_address_latched=a[45];this.crtc.set(a[46]);this.horizontal_display_enable_end=a[47];this.horizontal_blank_start=a[48];this.vertical_display_enable_end=a[49];this.vertical_blank_start=a[50];this.underline_location_register=
543
- a[51];this.preset_row_scan=a[52];this.offset_register=a[53];this.palette_source=a[54];this.attribute_mode=a[55];this.color_plane_enable=a[56];this.horizontal_panning=a[57];this.color_select=a[58];this.clocking_mode=a[59];this.line_compare=a[60];a[61]&&this.pixel_buffer.set(a[61]);this.dac_mask=void 0===a[62]?255:a[62];this.character_map_select=void 0===a[63]?0:a[63];this.font_page_ab_enabled=void 0===a[64]?0:a[64];this.screen.set_mode(this.graphical_mode);this.graphical_mode?(this.screen_height=this.screen_width=
544
- 0,this.svga_enabled?(this.set_size_graphical(this.svga_width,this.svga_height,this.svga_width,this.svga_height,this.svga_bpp),this.update_layers()):(this.update_vga_size(),this.update_layers(),this.complete_replot())):(this.set_font_bitmap(!0),this.set_size_text(this.max_cols,this.max_rows),this.set_font_page(),this.update_cursor_scanline(),this.update_cursor());this.complete_redraw()};X.prototype.vga_memory_read=function(a){if(this.svga_enabled)return this.cpu.read8((a-655360|this.svga_bank_offset)+
545
- 3758096384|0);var b=this.miscellaneous_graphics_register>>2&3;a-=Vc[b];if(0>a||a>=Wc[b])return C("vga read outside memory space: addr:"+m(a),256),0;this.latch_dword=this.plane0[a];this.latch_dword|=this.plane1[a]<<8;this.latch_dword|=this.plane2[a]<<16;this.latch_dword|=this.plane3[a]<<24;if(this.planar_mode&8)return b=255,this.color_dont_care&1&&(b&=this.plane0[a]^~(this.color_compare&1?255:0)),this.color_dont_care&2&&(b&=this.plane1[a]^~(this.color_compare&2?255:0)),this.color_dont_care&4&&(b&=
546
- this.plane2[a]^~(this.color_compare&4?255:0)),this.color_dont_care&8&&(b&=this.plane3[a]^~(this.color_compare&8?255:0)),b;b=this.plane_read;this.graphical_mode?this.sequencer_memory_mode&8?(b=a&3,a&=-4):this.planar_mode&16&&(b=a&1,a&=-2):b&=3;return this.vga_memory[b<<16|a]};X.prototype.vga_memory_write=function(a,b){if(this.svga_enabled)this.cpu.write8((a-655360|this.svga_bank_offset)+3758096384|0,b);else{var c=this.miscellaneous_graphics_register>>2&3;a-=Vc[c];0>a||a>=Wc[c]?C("vga write outside memory space: addr:"+
547
- m(a)+", value:"+m(b),256):this.graphical_mode?this.vga_memory_write_graphical(a,b):this.plane_write_bm&3?this.vga_memory_write_text_mode(a,b):this.plane_write_bm&4&&(this.plane2[a]=b)}};X.prototype.vga_memory_write_graphical=function(a,b){var c=this.planar_mode&3,d=this.apply_feed(this.planar_bitmap),e=this.apply_expand(this.planar_setreset),f=this.apply_expand(this.planar_setreset_enable);switch(c){case 0:b=this.apply_rotate(b);var h=this.apply_feed(b);h=this.apply_setreset(h,f);h=this.apply_logical(h,
548
- this.latch_dword);h=this.apply_bitmask(h,d);break;case 1:h=this.latch_dword;break;case 2:h=this.apply_expand(b);h=this.apply_logical(h,this.latch_dword);h=this.apply_bitmask(h,d);break;case 3:b=this.apply_rotate(b),d&=this.apply_feed(b),h=this.apply_bitmask(e,d)}b=15;switch(this.sequencer_memory_mode&12){case 0:b=5<<(a&1);a&=-2;break;case 8:case 12:b=1<<(a&3),a&=-4}b&=this.plane_write_bm;b&1&&(this.plane0[a]=h>>0&255);b&2&&(this.plane1[a]=h>>8&255);b&4&&(this.plane2[a]=h>>16&255);b&8&&(this.plane3[a]=
549
- h>>24&255);a=this.vga_addr_to_pixel(a);this.partial_replot(a,a+7)};X.prototype.apply_feed=function(a){return a|a<<8|a<<16|a<<24};X.prototype.apply_expand=function(a){return(a&1?255:0)|(a&2?255:0)<<8|(a&4?255:0)<<16|(a&8?255:0)<<24};X.prototype.apply_rotate=function(a){return(a|a<<8)>>>(this.planar_rotate_reg&7)&255};X.prototype.apply_setreset=function(a,b){var c=this.apply_expand(this.planar_setreset);return(a|b&c)&(~b|c)};X.prototype.apply_logical=function(a,b){switch(this.planar_rotate_reg&24){case 8:return a&
550
- b;case 16:return a|b;case 24:return a^b}return a};X.prototype.apply_bitmask=function(a,b){return b&a|~b&this.latch_dword};X.prototype.text_mode_redraw=function(){const a=this.scan_line_to_screen_row(this.line_compare),b=Math.max(0,2*(2*this.offset_register-this.max_cols)),c=this.attribute_mode&8,d=this.font_page_ab_enabled?7:15,e=c?7:15,f=this.screen.FLAG_BLINKING,h=this.screen.FLAG_FONT_PAGE_B;let l=this.start_address<<1;for(let p=0;p<this.max_rows;p++){p===a&&(l=0);for(let n=0;n<this.max_cols;n++){const q=
551
- this.vga_memory[l],r=this.vga_memory[l|1],t=(c&&r&128?f:0)|(!this.font_page_ab_enabled||r&8?0:h);this.bus.send("screen-put-char",[p,n,q]);this.screen.put_char(p,n,q,t,this.vga256_palette[this.dac_mask&this.dac_map[r>>4&e]],this.vga256_palette[this.dac_mask&this.dac_map[r&d]]);l+=2}l+=b}};X.prototype.vga_memory_write_text_mode=function(a,b){this.vga_memory[a]=b;var c=Math.max(this.max_cols,2*this.offset_register);let d;if(a>>1>=this.start_address){var e=(a>>1)-this.start_address;d=e/c|0;c=e%c}else e=
552
- a>>1,d=(e/c|0)+this.scan_line_to_screen_row(this.line_compare),c=e%c;k(0<=d&&0<=c);if(!(c>=this.max_cols||d>=this.max_rows)){a&1?(e=b,b=this.vga_memory[a&-2]):e=this.vga_memory[a|1];var f=this.attribute_mode&8;a=(f&&e&128?this.screen.FLAG_BLINKING:0)|(!this.font_page_ab_enabled||e&8?0:this.screen.FLAG_FONT_PAGE_B);var h=this.font_page_ab_enabled?7:15;f=f?7:15;this.bus.send("screen-put-char",[d,c,b]);this.screen.put_char(d,c,b,a,this.vga256_palette[this.dac_mask&this.dac_map[e>>4&f]],this.vga256_palette[this.dac_mask&
553
- this.dac_map[e&h]])}};X.prototype.update_cursor=function(){var a=Math.max(this.max_cols,2*this.offset_register);let b;this.cursor_address>=this.start_address?(b=(this.cursor_address-this.start_address)/a|0,a=(this.cursor_address-this.start_address)%a):(b=(this.cursor_address/a|0)+this.scan_line_to_screen_row(this.line_compare),a=this.cursor_address%a);k(0<=b&&0<=a);this.screen.update_cursor(b,a)};X.prototype.complete_redraw=function(){C("complete redraw",256);this.graphical_mode?this.svga_enabled?
554
- this.cpu.svga_mark_dirty():(this.diff_addr_min=0,this.diff_addr_max=524288):this.text_mode_redraw()};X.prototype.complete_replot=function(){C("complete replot",256);this.graphical_mode&&!this.svga_enabled&&(this.diff_plot_min=0,this.diff_plot_max=524288,this.complete_redraw())};X.prototype.partial_redraw=function(a,b){a<this.diff_addr_min&&(this.diff_addr_min=a);b>this.diff_addr_max&&(this.diff_addr_max=b)};X.prototype.partial_replot=function(a,b){a<this.diff_plot_min&&(this.diff_plot_min=a);b>this.diff_plot_max&&
555
- (this.diff_plot_max=b);this.partial_redraw(a,b)};X.prototype.reset_diffs=function(){this.diff_addr_min=this.vga_memory_size;this.diff_addr_max=0;this.diff_plot_min=this.vga_memory_size;this.diff_plot_max=0};X.prototype.destroy=function(){};X.prototype.vga_bytes_per_line=function(){var a=this.offset_register<<2;this.underline_location_register&64?a<<=1:this.crtc_mode&64&&(a>>>=1);return a};X.prototype.vga_addr_shift_count=function(){var a=128+(~this.underline_location_register&this.crtc_mode&64);a-=
556
- this.underline_location_register&64;a-=this.attribute_mode&64;return a>>>6};X.prototype.vga_addr_to_pixel=function(a){var b=this.vga_addr_shift_count();if(~this.crtc_mode&3){var c=a-this.start_address;c&=this.crtc_mode<<13|-24577;c<<=b;var d=c/this.virtual_width|0;c%=this.virtual_width;switch(this.crtc_mode&3){case 2:d=d<<1|a>>13&1;break;case 1:d=d<<1|a>>14&1;break;case 0:d=d<<2|a>>13&3}return d*this.virtual_width+c+(this.start_address<<b)}return a<<b};X.prototype.scan_line_to_screen_row=function(a){this.max_scan_line&
557
- 128&&(a>>>=1);a=Math.ceil(a/(1+(this.max_scan_line&31)));this.crtc_mode&1||(a<<=1);this.crtc_mode&2||(a<<=1);return a};X.prototype.set_size_text=function(a,b){k(!this.graphical_mode);this.max_cols=a;this.max_rows=b;this.screen.set_size_text(a,b);this.bus.send("screen-set-size",[a,b,0])};X.prototype.set_size_graphical=function(a,b,c,d,e){k(this.graphical_mode);c=Math.max(c,1);d=Math.max(d,1);if(this.screen_width!==a||this.screen_height!==b||this.virtual_width!==c||this.virtual_height!==d){this.screen_width=
558
- a;this.screen_height=b;this.virtual_width=c;this.virtual_height=d;if("undefined"!==typeof ImageData){const f=c*d,h=this.cpu.svga_allocate_dest_buffer(f)>>>0;this.dest_buffet_offset=h;this.image_data=new ImageData(new Uint8ClampedArray(this.cpu.wasm_memory.buffer,h,4*f),c,d);this.cpu.svga_mark_dirty()}this.screen.set_size_graphical(a,b,c,d);this.bus.send("screen-set-size",[a,b,e])}};X.prototype.update_vga_size=function(){if(!this.svga_enabled){var a=Math.min(1+this.horizontal_display_enable_end,this.horizontal_blank_start),
559
- b=Math.min(1+this.vertical_display_enable_end,this.vertical_blank_start);if(a&&b)if(this.graphical_mode){a<<=3;var c=this.offset_register<<4,d=4;this.attribute_mode&64?(a>>>=1,c>>>=1,d=8):this.attribute_mode&2&&(d=1);b=this.scan_line_to_screen_row(b);var e=Wc[0];const f=this.vga_bytes_per_line();this.set_size_graphical(a,b,c,f?Math.ceil(e/f):b,d);this.update_vertical_retrace();this.update_layers()}else this.max_scan_line&128&&(b>>>=1),c=b/(1+(this.max_scan_line&31))|0,a&&c&&this.set_size_text(a,c)}};
560
- X.prototype.update_layers=function(){this.graphical_mode||this.text_mode_redraw();if(this.svga_enabled)this.layers=[];else if(this.virtual_width&&this.screen_width)if(!this.palette_source||this.clocking_mode&32)this.layers=[],this.screen.clear_screen();else{var a=this.start_address_latched,b=this.horizontal_panning;this.attribute_mode&64&&(b>>>=1);var c=this.preset_row_scan>>5&3,d=this.vga_addr_to_pixel(a+c);a=d/this.virtual_width|0;var e=d%this.virtual_width+b;d=this.scan_line_to_screen_row(1+this.line_compare);
561
- d=Math.min(d,this.screen_height);var f=this.screen_height-d;this.layers=[];e=-e;for(var h=0;e<this.screen_width;e+=this.virtual_width,h++)this.layers.push({image_data:this.image_data,screen_x:e,screen_y:0,buffer_x:0,buffer_y:a+h,buffer_width:this.virtual_width,buffer_height:d});a=0;this.attribute_mode&32||(a=this.vga_addr_to_pixel(c)+b);e=-a;for(h=0;e<this.screen_width;e+=this.virtual_width,h++)this.layers.push({image_data:this.image_data,screen_x:e,screen_y:d,buffer_x:0,buffer_y:h,buffer_width:this.virtual_width,
562
- buffer_height:f})}};X.prototype.update_vertical_retrace=function(){this.port_3DA_value|=8;this.start_address_latched!==this.start_address&&(this.start_address_latched=this.start_address,this.update_layers())};X.prototype.update_cursor_scanline=function(){var a=this.max_scan_line&31;const b=Math.min(a,this.cursor_scanline_start&31);a=Math.min(a,this.cursor_scanline_end&31);this.screen.update_cursor_scanline(b,a,!(this.cursor_scanline_start&32)&&b<a)};X.prototype.port3C0_write=function(a){if(-1===this.attribute_controller_index)C("attribute controller index register: "+
563
- m(a),256),this.attribute_controller_index=a&31,C("attribute actual index: "+m(this.attribute_controller_index),256),this.palette_source!==(a&32)&&(this.palette_source=a&32,this.update_layers());else{if(16>this.attribute_controller_index)C("internal palette: "+m(this.attribute_controller_index)+" -> "+m(a),256),this.dac_map[this.attribute_controller_index]=a,this.attribute_mode&64||this.complete_redraw();else switch(this.attribute_controller_index){case 16:C("3C0 / attribute mode control: "+m(a),256);
564
- if(this.attribute_mode!==a){var b=this.attribute_mode;this.attribute_mode=a;const c=0!==(a&1);this.svga_enabled||this.graphical_mode===c||(this.graphical_mode=c,this.screen.set_mode(this.graphical_mode));(b^a)&64&&this.complete_replot();this.update_vga_size();this.complete_redraw();this.set_font_bitmap(!1)}break;case 18:C("3C0 / color plane enable: "+m(a),256);this.color_plane_enable!==a&&(this.color_plane_enable=a,this.complete_redraw());break;case 19:C("3C0 / horizontal panning: "+m(a),256);this.horizontal_panning!==
565
- a&&(this.horizontal_panning=a&15,this.update_layers());break;case 20:C("3C0 / color select: "+m(a),256);this.color_select!==a&&(this.color_select=a,this.complete_redraw());break;default:C("3C0 / attribute controller write "+m(this.attribute_controller_index)+": "+m(a),256)}this.attribute_controller_index=-1}};X.prototype.port3C0_read=function(){C("3C0 read",256);return(this.attribute_controller_index|this.palette_source)&255};X.prototype.port3C0_read16=function(){C("3C0 read16",256);return this.port3C0_read()|
566
- this.port3C1_read()<<8&65280};X.prototype.port3C1_read=function(){if(16>this.attribute_controller_index)return C("3C1 / internal palette read: "+m(this.attribute_controller_index)+" -> "+m(this.dac_map[this.attribute_controller_index]),256),this.dac_map[this.attribute_controller_index]&255;switch(this.attribute_controller_index){case 16:return C("3C1 / attribute mode read: "+m(this.attribute_mode),256),this.attribute_mode;case 18:return C("3C1 / color plane enable read: "+m(this.color_plane_enable),
567
- 256),this.color_plane_enable;case 19:return C("3C1 / horizontal panning read: "+m(this.horizontal_panning),256),this.horizontal_panning;case 20:return C("3C1 / color select read: "+m(this.color_select),256),this.color_select;default:C("3C1 / attribute controller read "+m(this.attribute_controller_index),256)}return 255};X.prototype.port3C2_write=function(a){C("3C2 / miscellaneous output register = "+m(a),256);this.miscellaneous_output_register=a};X.prototype.port3C4_write=function(a){this.sequencer_index=
568
- a};X.prototype.port3C4_read=function(){return this.sequencer_index};X.prototype.port3C5_write=function(a){switch(this.sequencer_index){case 1:C("clocking mode: "+m(a),256);var b=this.clocking_mode;this.clocking_mode=a;(b^a)&32&&this.update_layers();this.set_font_bitmap(!1);break;case 2:C("plane write mask: "+m(a),256);b=this.plane_write_bm;this.plane_write_bm=a;this.graphical_mode||!(b&4)||this.plane_write_bm&4||this.set_font_bitmap(!0);break;case 3:C("character map select: "+m(a),256);b=this.character_map_select;
569
- this.character_map_select=a;this.graphical_mode||b===a||this.set_font_page();break;case 4:C("sequencer memory mode: "+m(a),256);this.sequencer_memory_mode=a;break;default:C("3C5 / sequencer write "+m(this.sequencer_index)+": "+m(a),256)}};X.prototype.port3C5_read=function(){C("3C5 / sequencer read "+m(this.sequencer_index),256);switch(this.sequencer_index){case 1:return this.clocking_mode;case 2:return this.plane_write_bm;case 3:return this.character_map_select;case 4:return this.sequencer_memory_mode;
570
- case 6:return 18}return 0};X.prototype.port3C6_write=function(a){this.dac_mask!==a&&(this.dac_mask=a,this.complete_redraw())};X.prototype.port3C6_read=function(){return this.dac_mask};X.prototype.port3C7_write=function(a){C("3C7 write: "+m(a),256);this.dac_color_index_read=3*a;this.dac_state&=0};X.prototype.port3C7_read=function(){return this.dac_state};X.prototype.port3C8_write=function(a){this.dac_color_index_write=3*a;this.dac_state|=3};X.prototype.port3C8_read=function(){return this.dac_color_index_write/
571
- 3&255};X.prototype.port3C9_write=function(a){var b=this.dac_color_index_write/3|0,c=this.dac_color_index_write%3,d=this.vga256_palette[b];if(0===(this.dispi_enable_value&32)){a&=63;const e=a&1;a=a<<2|e<<1|e}0===c?d=d&-16711681|a<<16:1===c?d=d&-65281|a<<8:(d=d&-256|a,C("dac set color, index="+m(b)+" value="+m(d),256));this.vga256_palette[b]!==d&&(this.vga256_palette[b]=d,this.complete_redraw());this.dac_color_index_write++};X.prototype.port3C9_read=function(){C("3C9 read",256);var a=this.vga256_palette[this.dac_color_index_read/
572
- 3|0]>>8*(2-this.dac_color_index_read%3)&255;this.dac_color_index_read++;return this.dispi_enable_value&32?a:a>>2};X.prototype.port3CC_read=function(){C("3CC read",256);return this.miscellaneous_output_register};X.prototype.port3CE_write=function(a){this.graphics_index=a};X.prototype.port3CE_read=function(){return this.graphics_index};X.prototype.port3CF_write=function(a){switch(this.graphics_index){case 0:this.planar_setreset=a;C("plane set/reset: "+m(a),256);break;case 1:this.planar_setreset_enable=
573
- a;C("plane set/reset enable: "+m(a),256);break;case 2:this.color_compare=a;C("color compare: "+m(a),256);break;case 3:this.planar_rotate_reg=a;C("plane rotate: "+m(a),256);break;case 4:this.plane_read=a;C("plane read: "+m(a),256);break;case 5:var b=this.planar_mode;this.planar_mode=a;C("planar mode: "+m(a),256);(b^a)&96&&this.complete_replot();break;case 6:C("miscellaneous graphics register: "+m(a),256);this.miscellaneous_graphics_register!==a&&(this.miscellaneous_graphics_register=a,this.update_vga_size());
574
- break;case 7:this.color_dont_care=a;C("color don't care: "+m(a),256);break;case 8:this.planar_bitmap=a;C("planar bitmap: "+m(a),256);break;default:C("3CF / graphics write "+m(this.graphics_index)+": "+m(a),256)}};X.prototype.port3CF_read=function(){C("3CF / graphics read "+m(this.graphics_index),256);switch(this.graphics_index){case 0:return this.planar_setreset;case 1:return this.planar_setreset_enable;case 2:return this.color_compare;case 3:return this.planar_rotate_reg;case 4:return this.plane_read;
575
- case 5:return this.planar_mode;case 6:return this.miscellaneous_graphics_register;case 7:return this.color_dont_care;case 8:return this.planar_bitmap}return 0};X.prototype.port3D4_write=function(a){C("3D4 / crtc index: "+a,256);this.index_crtc=a};X.prototype.port3D4_write16=function(a){this.port3D4_write(a&255);this.port3D5_write(a>>8&255)};X.prototype.port3D4_read=function(){C("3D4 read / crtc index: "+this.index_crtc,256);return this.index_crtc};X.prototype.port3D5_write=function(a){switch(this.index_crtc){case 1:C("3D5 / hdisp enable end write: "+
576
- m(a),256);this.horizontal_display_enable_end!==a&&(this.horizontal_display_enable_end=a,this.update_vga_size());break;case 2:this.horizontal_blank_start!==a&&(this.horizontal_blank_start=a,this.update_vga_size());break;case 7:C("3D5 / overflow register write: "+m(a),256);var b=this.vertical_display_enable_end;this.vertical_display_enable_end&=255;this.vertical_display_enable_end=this.vertical_display_enable_end|a<<3&512|a<<7&256;b!==this.vertical_display_enable_end&&this.update_vga_size();this.line_compare=
577
- this.line_compare&767|a<<4&256;b=this.vertical_blank_start;this.vertical_blank_start=this.vertical_blank_start&767|a<<5&256;b!==this.vertical_blank_start&&this.update_vga_size();this.update_layers();break;case 8:C("3D5 / preset row scan write: "+m(a),256);this.preset_row_scan=a;this.update_layers();break;case 9:C("3D5 / max scan line write: "+m(a),256);var c=this.max_scan_line;this.max_scan_line=a;this.line_compare=this.line_compare&511|a<<3&512;b=this.vertical_blank_start;this.vertical_blank_start=
578
- this.vertical_blank_start&511|a<<4&512;((c^this.max_scan_line)&159||b!==this.vertical_blank_start)&&this.update_vga_size();this.update_cursor_scanline();this.update_layers();this.set_font_bitmap(!1);break;case 10:C("3D5 / cursor scanline start write: "+m(a),256);this.cursor_scanline_start=a;this.update_cursor_scanline();break;case 11:C("3D5 / cursor scanline end write: "+m(a),256);this.cursor_scanline_end=a;this.update_cursor_scanline();break;case 12:(this.start_address>>8&255)!==a&&(this.start_address=
579
- this.start_address&255|a<<8,this.update_layers(),~this.crtc_mode&3&&this.complete_replot());C("3D5 / start addr hi write: "+m(a)+" -> "+m(this.start_address,4),256);break;case 13:(this.start_address&255)!==a&&(this.start_address=this.start_address&65280|a,this.update_layers(),~this.crtc_mode&3&&this.complete_replot());C("3D5 / start addr lo write: "+m(a)+" -> "+m(this.start_address,4),256);break;case 14:C("3D5 / cursor address hi write: "+m(a),256);this.cursor_address=this.cursor_address&255|a<<8;
580
- this.update_cursor();break;case 15:C("3D5 / cursor address lo write: "+m(a),256);this.cursor_address=this.cursor_address&65280|a;this.update_cursor();break;case 18:C("3D5 / vdisp enable end write: "+m(a),256);(this.vertical_display_enable_end&255)!==a&&(this.vertical_display_enable_end=this.vertical_display_enable_end&768|a,this.update_vga_size());break;case 19:C("3D5 / offset register write: "+m(a),256);this.offset_register!==a&&(this.offset_register=a,this.update_vga_size(),~this.crtc_mode&3&&this.complete_replot());
581
- break;case 20:C("3D5 / underline location write: "+m(a),256);this.underline_location_register!==a&&(b=this.underline_location_register,this.underline_location_register=a,this.update_vga_size(),(b^a)&64&&this.complete_replot());break;case 21:C("3D5 / vertical blank start write: "+m(a),256);(this.vertical_blank_start&255)!==a&&(this.vertical_blank_start=this.vertical_blank_start&768|a,this.update_vga_size());break;case 23:C("3D5 / crtc mode write: "+m(a),256);this.crtc_mode!==a&&(b=this.crtc_mode,this.crtc_mode=
582
- a,this.update_vga_size(),(b^a)&67&&this.complete_replot());break;case 24:C("3D5 / line compare write: "+m(a),256);this.line_compare=this.line_compare&768|a;this.update_layers();break;default:this.index_crtc<this.crtc.length&&(this.crtc[this.index_crtc]=a),C("3D5 / CRTC write "+m(this.index_crtc)+": "+m(a),256)}};X.prototype.port3D5_write16=function(a){C("16-bit write to 3D5: "+m(a,4),256);this.port3D5_write(a&255)};X.prototype.port3D5_read=function(){C("3D5 read "+m(this.index_crtc),256);switch(this.index_crtc){case 1:return this.horizontal_display_enable_end;
583
- case 2:return this.horizontal_blank_start;case 7:return this.vertical_display_enable_end>>7&2|this.vertical_blank_start>>5&8|this.line_compare>>4&16|this.vertical_display_enable_end>>3&64;case 8:return this.preset_row_scan;case 9:return this.max_scan_line;case 10:return this.cursor_scanline_start;case 11:return this.cursor_scanline_end;case 12:return this.start_address&255;case 13:return this.start_address>>8;case 14:return this.cursor_address>>8;case 15:return this.cursor_address&255;case 18:return this.vertical_display_enable_end&
584
- 255;case 19:return this.offset_register;case 20:return this.underline_location_register;case 21:return this.vertical_blank_start&255;case 23:return this.crtc_mode;case 24:return this.line_compare&255}return this.index_crtc<this.crtc.length?this.crtc[this.index_crtc]:0};X.prototype.port3D5_read16=function(){C("Warning: 16-bit read from 3D5",256);return this.port3D5_read()};X.prototype.port3DA_read=function(){C("3DA read - status 1 and clear attr index",256);var a=this.port_3DA_value;this.graphical_mode?
585
- (this.port_3DA_value^=1,this.port_3DA_value&=1):(this.port_3DA_value&1&&(this.port_3DA_value^=8),this.port_3DA_value^=1);this.attribute_controller_index=-1;return a};X.prototype.port1CE_write=function(a){this.dispi_index=a};X.prototype.port1CF_write=function(a){C("1CF / dispi write "+m(this.dispi_index)+": "+m(a),256);const b=this.svga_enabled;switch(this.dispi_index){case 0:45248<=a&&45253>=a?this.svga_version=a:C("Invalid version value: "+m(a),256);break;case 1:this.svga_width=a;2560<this.svga_width&&
586
- (C("svga_width reduced from "+this.svga_width+" to 2560",256),this.svga_width=2560);break;case 2:this.svga_height=a;1600<this.svga_height&&(C("svga_height reduced from "+this.svga_height+" to 1600",256),this.svga_height=1600);break;case 3:this.svga_bpp=a;break;case 4:(this.svga_enabled=1===(a&1))&&0===(a&128)&&this.svga_memory.fill(0);this.dispi_enable_value=a;break;case 5:C("SVGA bank offset: "+m(a<<16),256);this.svga_bank_offset=a<<16;break;case 8:C("SVGA X offset: "+m(a),256);this.svga_offset_x!==
587
- a&&(this.svga_offset_x=a,this.svga_offset=this.svga_offset_y*this.svga_width+this.svga_offset_x,this.complete_redraw());break;case 9:C("SVGA Y offset: "+m(a*this.svga_width)+" y="+m(a),256);this.svga_offset_y!==a&&(this.svga_offset_y=a,this.svga_offset=this.svga_offset_y*this.svga_width+this.svga_offset_x,this.complete_redraw());break;default:C("Unimplemented dispi write index: "+m(this.dispi_index),256)}!this.svga_enabled||this.svga_width&&this.svga_height||(C("SVGA: disabled because of invalid width/height: "+
588
- this.svga_width+"x"+this.svga_height,256),this.svga_enabled=!1);k(4!==this.svga_bpp,"unimplemented svga bpp: 4");k(4===this.svga_bpp||8===this.svga_bpp||15===this.svga_bpp||16===this.svga_bpp||24===this.svga_bpp||32===this.svga_bpp,"unexpected svga bpp: "+this.svga_bpp);this.svga_enabled?C("SVGA: enabled, "+this.svga_width+"x"+this.svga_height+"x"+this.svga_bpp,256):C("SVGA: disabled");this.svga_enabled&&!b&&(this.svga_offset_y=this.svga_offset_x=this.svga_offset=0,this.graphical_mode=!0,this.screen.set_mode(this.graphical_mode),
589
- this.set_size_graphical(this.svga_width,this.svga_height,this.svga_width,this.svga_height,this.svga_bpp));this.svga_enabled||(this.svga_bank_offset=0);this.update_layers()};X.prototype.port1CF_read=function(){C("1CF / dispi read "+m(this.dispi_index),256);return this.svga_register_read(this.dispi_index)};X.prototype.svga_register_read=function(a){switch(a){case 0:return this.svga_version;case 1:return this.dispi_enable_value&2?2560:this.svga_width;case 2:return this.dispi_enable_value&2?1600:this.svga_height;
590
- case 3:return this.dispi_enable_value&2?32:this.svga_bpp;case 4:return this.dispi_enable_value;case 5:return this.svga_bank_offset>>>16;case 6:return this.screen_width?this.screen_width:1;case 8:return this.svga_offset_x;case 9:return this.svga_offset_y;case 10:return this.vga_memory_size/65536|0;default:C("Unimplemented dispi read index: "+m(this.dispi_index),256)}return 255};X.prototype.vga_replot=function(){for(var a=this.diff_plot_min&-16,b=Math.min(this.diff_plot_max|15,524287),c=this.vga_addr_shift_count(),
591
- d=~this.crtc_mode&3,e=this.planar_mode&96,f=this.attribute_mode&64;a<=b;){var h=a>>>c;if(d){var l=a/this.virtual_width|0,p=a-this.virtual_width*l;switch(d){case 1:h=(l&1)<<13;l>>>=1;break;case 2:h=(l&1)<<14;l>>>=1;break;case 3:h=(l&3)<<13,l>>>=2}h|=(l*this.virtual_width+p>>>c)+this.start_address}l=this.plane0[h];p=this.plane1[h];var n=this.plane2[h],q=this.plane3[h];h=new Uint8Array(8);switch(e){case 0:l<<=0;p<<=1;n<<=2;q<<=3;for(var r=7;0<=r;r--)h[7-r]=l>>r&1|p>>r&2|n>>r&4|q>>r&8;break;case 32:h[0]=
592
- l>>6&3|n>>4&12;h[1]=l>>4&3|n>>2&12;h[2]=l>>2&3|n>>0&12;h[3]=l>>0&3|n<<2&12;h[4]=p>>6&3|q>>4&12;h[5]=p>>4&3|q>>2&12;h[6]=p>>2&3|q>>0&12;h[7]=p>>0&3|q<<2&12;break;case 64:case 96:h[0]=l>>4&15,h[1]=l>>0&15,h[2]=p>>4&15,h[3]=p>>0&15,h[4]=n>>4&15,h[5]=n>>0&15,h[6]=q>>4&15,h[7]=q>>0&15}if(f)for(l=r=0;4>r;r++,a++,l+=2)this.pixel_buffer[a]=h[l]<<4|h[l+1];else for(r=0;8>r;r++,a++)this.pixel_buffer[a]=h[r]}};X.prototype.vga_redraw=function(){var a=this.diff_addr_min,b=Math.min(this.diff_addr_max,524287);const c=
593
- new Int32Array(this.cpu.wasm_memory.buffer,this.dest_buffet_offset,this.virtual_width*this.virtual_height);var d=255,e=0;this.attribute_mode&128&&(d&=207,e|=this.color_select<<4&48);if(this.attribute_mode&64)for(;a<=b;a++){var f=this.pixel_buffer[a]&d|e;f=this.vga256_palette[f];c[a]=f&65280|f<<16|f>>16|4278190080}else for(d&=63,e|=this.color_select<<4&192;a<=b;a++)f=this.dac_map[this.pixel_buffer[a]&this.color_plane_enable]&d|e,f=this.vga256_palette[f],c[a]=f&65280|f<<16|f>>16|4278190080};X.prototype.screen_fill_buffer=
594
- function(){if(this.graphical_mode){if(0===this.image_data.data.byteLength){var a=new Uint8ClampedArray(this.cpu.wasm_memory.buffer,this.dest_buffet_offset,4*this.virtual_width*this.virtual_height);this.image_data=new ImageData(a,this.virtual_width,this.virtual_height);this.update_layers()}if(this.svga_enabled){a=0;let d=this.svga_height;if(8===this.svga_bpp){const e=new Int32Array(this.cpu.wasm_memory.buffer,this.dest_buffet_offset,this.screen_width*this.screen_height),f=new Uint8Array(this.cpu.wasm_memory.buffer,
595
- this.svga_memory.byteOffset,this.vga_memory_size);for(var b=0;b<e.length;b++){var c=this.vga256_palette[f[b]];e[b]=c&65280|c<<16|c>>16|4278190080}}else this.cpu.svga_fill_pixel_buffer(this.svga_bpp,this.svga_offset),b=15===this.svga_bpp?2:this.svga_bpp/8,a=((this.cpu.svga_dirty_bitmap_min_offset[0]/b|0)-this.svga_offset)/this.svga_width|0,d=(((this.cpu.svga_dirty_bitmap_max_offset[0]/b|0)-this.svga_offset)/this.svga_width|0)+1;a<d&&(a=Math.max(a,0),d=Math.min(d,this.svga_height),this.screen.update_buffer([{image_data:this.image_data,
596
- screen_x:0,screen_y:a,buffer_x:0,buffer_y:a,buffer_width:this.svga_width,buffer_height:d-a}]))}else this.vga_replot(),this.vga_redraw(),this.screen.update_buffer(this.layers);this.reset_diffs()}this.update_vertical_retrace()};X.prototype.set_font_bitmap=function(a){const b=this.max_scan_line&31;if(b&&!this.graphical_mode){const c=!!(this.clocking_mode&8);this.screen.set_font_bitmap(b+1,!c&&!(this.clocking_mode&1),c,!!(this.attribute_mode&4),this.plane2,a)}};X.prototype.set_font_page=function(){const a=
597
- [0,2,4,6,1,3,5,7],b=(this.character_map_select&12)>>2|(this.character_map_select&32)>>3,c=this.character_map_select&3|(this.character_map_select&16)>>2;this.font_page_ab_enabled=b!==c;this.screen.set_font_page(a[b],a[c]);this.complete_redraw()};const Xc="SWAP_IN SWAP_OUT MAJFLT MINFLT MEMFREE MEMTOT AVAIL CACHES HTLB_PGALLOC HTLB_PGFAIL".split(" ");function Yc(a,b){this.bus=b;this.zeroed=this.fp_cmd=this.actual=this.num_pages=0;this.virtio=new Ic(a,{name:"virtio-balloon",pci_id:88,device_id:4165,
598
- subsystem_device_id:5,common:{initial_port:55296,queues:[{size_supported:32,notify_offset:0},{size_supported:32,notify_offset:0},{size_supported:2,notify_offset:1},{size_supported:64,notify_offset:2}],features:[1,3,32],on_driver_ok:()=>{C("Balloon setup",2048)}},notification:{initial_port:55552,single_handler:!1,handlers:[c=>{const d=this.virtio.queues[c];for(;d.has_request();){var e=d.pop_request();const f=new Uint8Array(e.length_readable);e.get_next_blob(f);this.virtio.queues[c].push_reply(e);e=
599
- f.byteLength/4;this.actual+=0===c?e:-e}this.virtio.queues[c].flush_replies()},c=>{var d=this.virtio.queues[c];if(d.has_request()){d=d.pop_request();const e=new Uint8Array(d.length_readable);d.get_next_blob(e);let f={};for(let h=0;h<d.length_readable;h+=10){let [l,p]=M(["h","d"],e,{offset:h});f[Xc[l]]=p}this.virtio.queues[c].push_reply(d);this.stats_cb&&this.stats_cb(f)}},c=>{const d=this.virtio.queues[c];for(;d.has_request();){const f=d.pop_request();if(0<f.length_readable){var e=new Uint8Array(f.length_readable);
600
- 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",
601
- 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=
602
- [];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);
603
- 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="+
604
- 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));
605
- 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,
606
- 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=
607
- 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);
608
- this.sysenter_eip=g(Int32Array,b,644,1);this.prefixes=g(Int32Array,b,648,1);this.flags=g(Int32Array,b,120,1);this.flags_changed=g(Int32Array,b,100,1);this.last_op_size=g(Int32Array,b,96,1);this.last_op1=g(Int32Array,b,104,1);this.last_result=g(Int32Array,b,112,1);this.current_tsc=g(Uint32Array,b,960,2);this.devices={};this.instruction_pointer=g(Int32Array,b,556,1);this.previous_ip=g(Int32Array,b,560,1);this.apic_enabled=g(Uint8Array,b,548,1);this.acpi_enabled=g(Uint8Array,b,552,1);this.memory_map_read8=
609
- [];this.memory_map_write8=[];this.memory_map_read32=[];this.memory_map_write32=[];this.bios={main:null,vga:null};this.instruction_counter=g(Uint32Array,b,664,1);this.reg32=g(Int32Array,b,64,8);this.fpu_st=g(Int32Array,b,1152,32);this.fpu_stack_empty=g(Uint8Array,b,816,1);this.fpu_stack_empty[0]=255;this.fpu_stack_ptr=g(Uint8Array,b,1032,1);this.fpu_stack_ptr[0]=0;this.fpu_control_word=g(Uint16Array,b,1036,1);this.fpu_control_word[0]=895;this.fpu_status_word=g(Uint16Array,b,1040,1);this.fpu_status_word[0]=
610
- 0;this.fpu_ip=g(Int32Array,b,1048,1);this.fpu_ip[0]=0;this.fpu_ip_selector=g(Int32Array,b,1052,1);this.fpu_ip_selector[0]=0;this.fpu_opcode=g(Int32Array,b,1044,1);this.fpu_opcode[0]=0;this.fpu_dp=g(Int32Array,b,1056,1);this.fpu_dp[0]=0;this.fpu_dp_selector=g(Int32Array,b,1060,1);this.fpu_dp_selector[0]=0;this.reg_xmm32s=g(Int32Array,b,832,32);this.mxcsr=g(Int32Array,b,824,1);this.sreg=g(Uint16Array,b,668,8);this.dreg=g(Int32Array,b,684,8);this.reg_pdpte=g(Int32Array,b,968,8);this.svga_dirty_bitmap_min_offset=
611
- g(Uint32Array,b,716,1);this.svga_dirty_bitmap_max_offset=g(Uint32Array,b,720,1);this.fw_value=[];this.fw_pointer=0;this.option_roms=[];this.io=void 0;this.bus=a;this.set_tsc(0,0);this.debug_init();this.seen_code={};this.seen_code_uncompiled={}}P.prototype.mmap_read8=function(a){a=this.memory_map_read8[a>>>17](a);k(0<=a&&255>=a);return a};P.prototype.mmap_write8=function(a,b){k(0<=b&&255>=b);this.memory_map_write8[a>>>17](a,b)};P.prototype.mmap_read16=function(a){var b=this.memory_map_read8[a>>>17];
612
- a=b(a)|b(a+1|0)<<8;k(0<=a&&65535>=a);return a};P.prototype.mmap_write16=function(a,b){var c=this.memory_map_write8[a>>>17];k(0<=b&&65535>=b);c(a,b&255);c(a+1|0,b>>8)};P.prototype.mmap_read32=function(a){return this.memory_map_read32[a>>>17](a)};P.prototype.mmap_write32=function(a,b){this.memory_map_write32[a>>>17](a,b)};P.prototype.mmap_write64=function(a,b,c){var d=a>>>17;k(d===a+7>>>17);d=this.memory_map_write32[d];d(a,b);d(a+4,c)};P.prototype.mmap_write128=function(a,b,c,d,e){var f=a>>>17;k(f===
613
- a+12>>>17);f=this.memory_map_write32[f];f(a,b);f(a+4,c);f(a+8,d);f(a+12,e)};P.prototype.write_blob=function(a,b){k(a&&0<=a.length);a.length&&(k(!this.in_mapped_range(b)),k(!this.in_mapped_range(b+a.length-1)),this.jit_dirty_cache(b,b+a.length),this.mem8.set(a,b))};P.prototype.read_blob=function(a,b){b&&(k(!this.in_mapped_range(a)),k(!this.in_mapped_range(a+b-1)));return this.mem8.subarray(a,a+b)};P.prototype.clear_opstats=function(){(new Uint8Array(this.wasm_memory.buffer,32768,131072)).fill(0);this.wm.exports.profiler_init()};
614
- P.prototype.create_jit_imports=function(){const a=Object.create(null);a.m=this.wm.exports.memory;for(const b of Object.keys(this.wm.exports))b.startsWith("_")||b.startsWith("zstd")||b.endsWith("_js")||(a[b]=this.wm.exports[b]);this.jit_imports=a};P.prototype.wasm_patch=function(){const a=c=>this.wm.exports[c],b=c=>{const d=a(c);console.assert(d,"Missing import: "+c);return d};this.reset_cpu=b("reset_cpu");this.getiopl=b("getiopl");this.get_eflags=b("get_eflags");this.handle_irqs=b("handle_irqs");
615
- this.main_loop=b("main_loop");this.set_jit_config=b("set_jit_config");this.read8=b("read8");this.read16=b("read16");this.read32s=b("read32s");this.write8=b("write8");this.write16=b("write16");this.write32=b("write32");this.in_mapped_range=b("in_mapped_range");this.fpu_load_tag_word=b("fpu_load_tag_word");this.fpu_load_status_word=b("fpu_load_status_word");this.fpu_get_sti_f64=b("fpu_get_sti_f64");this.translate_address_system_read=b("translate_address_system_read_js");this.get_seg_cs=b("get_seg_cs");
616
- this.get_real_eip=b("get_real_eip");this.clear_tlb=b("clear_tlb");this.full_clear_tlb=b("full_clear_tlb");this.update_state_flags=b("update_state_flags");this.set_tsc=b("set_tsc");this.store_current_tsc=b("store_current_tsc");this.set_cpuid_level=b("set_cpuid_level");this.pic_set_irq=b("pic_set_irq");this.pic_clear_irq=b("pic_clear_irq");this.jit_force_generate_unsafe=a("jit_force_generate_unsafe");this.jit_clear_cache=b("jit_clear_cache_js");this.jit_dirty_cache=b("jit_dirty_cache");this.codegen_finalize_finished=
617
- b("codegen_finalize_finished");this.allocate_memory=b("allocate_memory");this.zero_memory=b("zero_memory");this.is_memory_zeroed=b("is_memory_zeroed");this.svga_allocate_memory=b("svga_allocate_memory");this.svga_allocate_dest_buffer=b("svga_allocate_dest_buffer");this.svga_fill_pixel_buffer=b("svga_fill_pixel_buffer");this.svga_mark_dirty=b("svga_mark_dirty");this.get_pic_addr_master=b("get_pic_addr_master");this.get_pic_addr_slave=b("get_pic_addr_slave");this.zstd_create_ctx=b("zstd_create_ctx");
618
- this.zstd_get_src_ptr=b("zstd_get_src_ptr");this.zstd_free_ctx=b("zstd_free_ctx");this.zstd_read=b("zstd_read");this.zstd_read_free=b("zstd_read_free");this.port20_read=b("port20_read");this.port21_read=b("port21_read");this.portA0_read=b("portA0_read");this.portA1_read=b("portA1_read");this.port20_write=b("port20_write");this.port21_write=b("port21_write");this.portA0_write=b("portA0_write");this.portA1_write=b("portA1_write");this.port4D0_read=b("port4D0_read");this.port4D1_read=b("port4D1_read");
619
- this.port4D0_write=b("port4D0_write");this.port4D1_write=b("port4D1_write")};P.prototype.jit_force_generate=function(a){this.jit_force_generate_unsafe?this.jit_force_generate_unsafe(a):k(!1,"Not supported in this wasm build: jit_force_generate_unsafe")};P.prototype.jit_clear_func=function(a){k(0<=a&&900>a);this.wm.wasm_table.set(a+1024,null)};P.prototype.jit_clear_all_funcs=function(){const a=this.wm.wasm_table;for(let b=0;900>b;b++)a.set(1024+b,null)};P.prototype.get_state=function(){var a=[];a[0]=
620
- this.memory_size[0];a[1]=new Uint8Array([...this.segment_is_null,...this.segment_access_bytes]);a[2]=this.segment_offsets;a[3]=this.segment_limits;a[4]=this.protected_mode[0];a[5]=this.idtr_offset[0];a[6]=this.idtr_size[0];a[7]=this.gdtr_offset[0];a[8]=this.gdtr_size[0];a[9]=this.page_fault[0];a[10]=this.cr;a[11]=this.cpl[0];a[13]=this.is_32[0];a[16]=this.stack_size_32[0];a[17]=this.in_hlt[0];a[18]=this.last_virt_eip[0];a[19]=this.eip_phys[0];a[22]=this.sysenter_cs[0];a[23]=this.sysenter_eip[0];a[24]=
621
- this.sysenter_esp[0];a[25]=this.prefixes[0];a[26]=this.flags[0];a[27]=this.flags_changed[0];a[28]=this.last_op1[0];a[30]=this.last_op_size[0];a[37]=this.instruction_pointer[0];a[38]=this.previous_ip[0];a[39]=this.reg32;a[40]=this.sreg;a[41]=this.dreg;a[42]=this.reg_pdpte;this.store_current_tsc();a[43]=this.current_tsc;a[45]=this.devices.virtio_9p;a[46]=this.devices.apic;a[47]=this.devices.rtc;a[48]=this.devices.pci;a[49]=this.devices.dma;a[50]=this.devices.acpi;a[52]=this.devices.vga;a[53]=this.devices.ps2;
622
- a[54]=this.devices.uart0;a[55]=this.devices.fdc;a[56]=this.devices.cdrom;a[57]=this.devices.hda;a[58]=this.devices.pit;a[59]=this.devices.net;a[60]=this.get_state_pic();a[61]=this.devices.sb16;a[62]=this.fw_value;a[63]=this.devices.ioapic;a[64]=this.tss_size_32[0];a[66]=this.reg_xmm32s;a[67]=this.fpu_st;a[68]=this.fpu_stack_empty[0];a[69]=this.fpu_stack_ptr[0];a[70]=this.fpu_control_word[0];a[71]=this.fpu_ip[0];a[72]=this.fpu_ip_selector[0];a[73]=this.fpu_dp[0];a[74]=this.fpu_dp_selector[0];a[75]=
623
- this.fpu_opcode[0];const {packed_memory:b,bitmap:c}=this.pack_memory();a[77]=b;a[78]=new Uint8Array(c.get_buffer());a[79]=this.devices.uart1;a[80]=this.devices.uart2;a[81]=this.devices.uart3;a[82]=this.devices.virtio_console;a[83]=this.devices.virtio_net;a[84]=this.devices.virtio_balloon;return a};P.prototype.get_state_pic=function(){const a=new Uint8Array(this.wasm_memory.buffer,this.get_pic_addr_master(),13),b=new Uint8Array(this.wasm_memory.buffer,this.get_pic_addr_slave(),13),c=[],d=[];c[0]=a[0];
624
- c[1]=a[1];c[2]=a[2];c[3]=a[3];c[4]=a[4];c[5]=d;c[6]=a[6];c[7]=a[7];c[8]=a[8];c[9]=a[9];c[10]=a[10];c[11]=a[11];c[12]=a[12];d[0]=b[0];d[1]=b[1];d[2]=b[2];d[3]=b[3];d[4]=b[4];d[5]=null;d[6]=b[6];d[7]=b[7];d[8]=b[8];d[9]=b[9];d[10]=b[10];d[11]=b[11];d[12]=b[12];return c};P.prototype.set_state=function(a){this.memory_size[0]=a[0];this.mem8.length!==this.memory_size[0]&&console.warn("Note: Memory size mismatch. we="+this.mem8.length+" state="+this.memory_size[0]);8===a[1].length?(this.segment_is_null.set(a[1]),
464
+ 0;this.response_data[3]=0;this.response_data[4]=0;this.response_data[5]=0;this.response_data[6]=0;this.raise_irq()};V.prototype.raise_irq=function(){this.dor&8&&this.cpu.device_raise_irq(6)};const Tc={[8]:"DEVICE RESET",[144]:"EXECUTE DEVICE DIAGNOSTIC",[231]:"FLUSH CACHE",[234]:"FLUSH CACHE EXT",[218]:"GET MEDIA STATUS",[236]:"IDENTIFY DEVICE",[161]:"IDENTIFY PACKET DEVICE",[225]:"IDLE IMMEDIATE",[145]:"INITIALIZE DEVICE PARAMETERS",[222]:"MEDIA LOCK",[0]:"NOP",[160]:"PACKET",[200]:"READ DMA",[37]:"READ DMA EXT",
465
+ [41]:"READ MULTIPLE",[196]:"READ MULTIPLE EXT",[248]:"READ NATIVE MAX ADDRESS",[39]:"READ NATIVE MAX ADDRESS EXT",[32]:"READ SECTORS",[36]:"READ SECTORS EXT",[64]:"READ VERIFY SECTORS",[245]:"SECURITY FREEZE LOCK",[239]:"SET FEATURES",[249]:"SET MAX",[198]:"SET MULTIPLE MODE",[224]:"STANDBY IMMEDIATE",[202]:"WRITE DMA",[53]:"WRITE DMA EXT",[57]:"WRITE MULTIPLE",[197]:"WRITE MULTIPLE EXT",[48]:"WRITE SECTORS",[52]:"WRITE SECTORS EXT",[16]:"<UNKWNON 10h>"},Uc={[70]:{name:"GET CONFIGURATION",flags:0},
466
+ [74]:{name:"GET EVENT STATUS NOTIFICATION",flags:0},[18]:{name:"INQUIRY",flags:0},[189]:{name:"MECHANISM STATUS",flags:0},[26]:{name:"MODE SENSE (6)",flags:0},[90]:{name:"MODE SENSE (10)",flags:0},[69]:{name:"PAUSE",flags:1},[30]:{name:"PREVENT ALLOW MEDIUM REMOVAL",flags:0},[40]:{name:"READ",flags:1},[37]:{name:"READ CAPACITY",flags:1},[190]:{name:"READ CD",flags:1},[81]:{name:"READ DISK INFORMATION",flags:1},[66]:{name:"READ SUBCHANNEL",flags:1},[67]:{name:"READ TOC PMA ATIP",flags:1},[82]:{name:"READ TRACK INFORMATION",
467
+ flags:1},[3]:{name:"REQUEST SENSE",flags:0},[27]:{name:"START STOP UNIT",flags:0},[0]:{name:"TEST UNIT READY",flags:1}};function Vc(a,b,c){this.cpu=a;this.bus=b;this.secondary=this.primary=void 0;b=c&&c[0][0];const d=c&&c[1][0];if(b||d){b&&(this.primary=new Wc(this,0,c[0],496,1014,14));d&&(this.secondary=new Wc(this,1,c[1],368,886,15));c=b?this.primary.command_base:0;const e=b?this.primary.control_base:0,f=d?this.secondary.command_base:0,h=d?this.secondary.control_base:0;this.name="ide";this.pci_id=
468
+ 240;this.pci_space=[134,128,16,112,5,0,160,2,0,128,1,1,0,0,0,0,c&255|1,c>>8,0,0,e&255|1,e>>8,0,0,f&255|1,f>>8,0,0,h&255|1,h>>8,0,0,1,180,0,0,0,0,0,0,0,0,0,0,67,16,212,130,0,0,0,0,0,0,0,0,0,0,0,0,0,1,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,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,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.pci_bars=[b?{size:8}:void 0,b?{size:1}:void 0,d?{size:8}:void 0,d?{size:1}:void 0,{size:16}];a.devices.pci.register_device(this)}Object.seal(this)}
469
+ Vc.prototype.get_state=function(){const a=[];a[0]=this.primary;a[1]=this.secondary;return a};Vc.prototype.set_state=function(a){this.primary&&this.primary.set_state(a[0]);this.secondary&&this.secondary.set_state(a[1])};function Wc(a,b,c,d,e,f){this.controller=a;this.channel_nr=b;this.cpu=a.cpu;this.bus=a.bus;this.command_base=d;this.control_base=e;this.irq=f;this.name="ide"+b;d=c?c[0]:void 0;c=c?c[1]:void 0;this.master=new W(this,0,d?.buffer,d?.is_cdrom);this.slave=new W(this,1,c?.buffer,c?.is_cdrom);
470
+ this.current_interface=this.master;this.device_control_reg=2;this.dma_command=this.dma_status=this.prdt_addr=0;a=a.cpu;a.io.register_read(this.command_base|0,this,function(){return this.current_interface.read_data(1)},function(){return this.current_interface.read_data(2)},function(){return this.current_interface.read_data(4)});a.io.register_read(this.command_base|1,this,function(){return this.current_interface.error_reg&255});a.io.register_read(this.command_base|2,this,function(){return this.current_interface.sector_count_reg&
471
+ 255});a.io.register_read(this.command_base|3,this,function(){return this.current_interface.lba_low_reg&255});a.io.register_read(this.command_base|4,this,function(){return this.current_interface.lba_mid_reg&255});a.io.register_read(this.command_base|5,this,function(){return this.current_interface.lba_high_reg&255});a.io.register_read(this.command_base|6,this,function(){return this.current_interface.device_reg&255});a.io.register_read(this.command_base|7,this,function(){const h=this.read_status();this.cpu.device_lower_irq(this.irq);
472
+ return h});a.io.register_write(this.command_base|0,this,function(h){this.current_interface.write_data_port8(h)},function(h){this.current_interface.write_data_port16(h)},function(h){this.current_interface.write_data_port32(h)});a.io.register_write(this.command_base|1,this,function(h){this.current_interface.features_reg=(this.current_interface.features_reg<<8|h)&65535});a.io.register_write(this.command_base|2,this,function(h){this.current_interface.sector_count_reg=(this.current_interface.sector_count_reg<<
473
+ 8|h)&65535});a.io.register_write(this.command_base|3,this,function(h){this.current_interface.lba_low_reg=(this.current_interface.lba_low_reg<<8|h)&65535});a.io.register_write(this.command_base|4,this,function(h){this.current_interface.lba_mid_reg=(this.current_interface.lba_mid_reg<<8|h)&65535});a.io.register_write(this.command_base|5,this,function(h){this.current_interface.lba_high_reg=(this.current_interface.lba_high_reg<<8|h)&65535});a.io.register_write(this.command_base|6,this,function(h){const l=
474
+ h&16;if(l&&this.current_interface===this.master||!l&&this.current_interface===this.slave)l?(C(`${this.current_interface.name}: select slave device (${this.channel_nr?"secondary":"primary"})`,32768),this.current_interface=this.slave):(C(`${this.current_interface.name}: select master device (${this.channel_nr?"secondary":"primary"})`,32768),this.current_interface=this.master);this.current_interface.device_reg=h;this.current_interface.is_lba=h>>6&1;this.current_interface.head=h&15});a.io.register_write(this.command_base|
475
+ 7,this,function(h){this.current_interface.status_reg&=-34;this.current_interface.ata_command(h);this.cpu.device_lower_irq(this.irq)});a.io.register_read(this.control_base|0,this,this.read_status);a.io.register_write(this.control_base|0,this,this.write_control);b=46080+8*b;a.io.register_read(b|0,this,this.dma_read_command8,void 0,this.dma_read_command);a.io.register_write(b|0,this,this.dma_write_command8,void 0,this.dma_write_command);a.io.register_read(b|2,this,this.dma_read_status);a.io.register_write(b|
476
+ 2,this,this.dma_write_status);a.io.register_read(b|4,this,void 0,void 0,this.dma_read_addr);a.io.register_write(b|4,this,void 0,void 0,this.dma_set_addr);Object.seal(this)}Wc.prototype.read_status=function(){return this.current_interface.drive_connected?this.current_interface.status_reg:0};Wc.prototype.write_control=function(a){a&4&&(C(`${this.current_interface.name}: soft reset via control port (lower IRQ ${this.irq})`,32768),this.cpu.device_lower_irq(this.irq),this.master.device_reset(),this.slave.device_reset());
477
+ this.device_control_reg=a};Wc.prototype.dma_read_addr=function(){return this.prdt_addr};Wc.prototype.dma_set_addr=function(a){this.prdt_addr=a};Wc.prototype.dma_read_status=function(){return this.dma_status};Wc.prototype.dma_write_status=function(a){this.dma_status&=~(a&6)};Wc.prototype.dma_read_command=function(){return this.dma_read_command8()|this.dma_read_status()<<16};Wc.prototype.dma_read_command8=function(){return this.dma_command};Wc.prototype.dma_write_command=function(a){this.dma_write_command8(a&
478
+ 255);this.dma_write_status(a>>16&255)};Wc.prototype.dma_write_command8=function(a){const b=this.dma_command;this.dma_command=a&9;if((b&1)!==(a&1))if(0===(a&1))this.dma_status&=-2;else switch(this.dma_status|=1,this.current_interface.current_command){case 200:case 37:this.current_interface.do_ata_read_sectors_dma();break;case 202:case 53:this.current_interface.do_ata_write_sectors_dma();break;case 160:this.current_interface.do_atapi_dma();break;default:C(this.current_interface.name+": spurious DMA command write, current command: "+
479
+ m(this.current_interface.current_command),32768),C(this.current_interface.name+": DMA clear status bit 1h, set status bit 2h",32768),this.dma_status&=-2,this.dma_status|=2,this.push_irq()}};Wc.prototype.push_irq=function(){0===(this.device_control_reg&2)&&(this.dma_status|=4,this.cpu.device_raise_irq(this.irq))};Wc.prototype.get_state=function(){var a=[];a[0]=this.master;a[1]=this.slave;a[2]=this.command_base;a[3]=this.irq;a[5]=this.control_base;a[7]=this.name;a[8]=this.device_control_reg;a[9]=this.prdt_addr;
480
+ a[10]=this.dma_status;a[11]=this.current_interface===this.master;a[12]=this.dma_command;return a};Wc.prototype.set_state=function(a){this.master.set_state(a[0]);this.slave.set_state(a[1]);this.command_base=a[2];this.irq=a[3];this.control_base=a[5];this.name=a[7];this.device_control_reg=a[8];this.prdt_addr=a[9];this.dma_status=a[10];this.current_interface=a[11]?this.master:this.slave;this.dma_command=a[12]};function W(a,b,c,d){this.channel=a;this.name=a.name+"."+b;this.bus=a.bus;this.channel_nr=a.channel_nr;
481
+ this.interface_nr=b;this.cpu=a.cpu;this.buffer=null;this.drive_connected=d||!!c;this.sector_size=d?2048:512;this.is_atapi=d;this.sector_count=0;this.head_count=this.is_atapi?1:0;this.device_reg=this.head=this.lba_high_reg=this.lba_mid_reg=this.features_reg=this.lba_low_reg=this.sector_count_reg=this.is_lba=this.cylinder_count=this.sectors_per_track=0;this.status_reg=80;this.sectors_per_drq=128;this.data_pointer=this.error_reg=0;this.data=new Uint8Array(65536);this.data16=new Uint16Array(this.data.buffer);
482
+ this.data32=new Int32Array(this.data.buffer);this.data_end=this.data_length=0;this.current_command=-1;this.last_io_id=this.write_dest=0;this.in_progress_io_ids=new Set;this.cancelled_io_ids=new Set;this.current_atapi_command=-1;this.atapi_add_sense=this.atapi_sense_key=0;this.medium_changed=!1;this.set_disk_buffer(c);this.drive_connected&&C(`${this.name}: ${this.is_atapi?"ATAPI CD-ROM":"ATA HD"} device ready`,32768);Object.seal(this)}W.prototype.has_disk=function(){return!!this.buffer};W.prototype.eject=
483
+ function(){this.is_atapi&&this.buffer&&(this.medium_changed=!0,this.buffer=null,this.status_reg=89,this.error_reg=96,this.push_irq())};W.prototype.set_cdrom=function(a){this.is_atapi&&a&&(this.set_disk_buffer(a),this.medium_changed=!0)};W.prototype.set_disk_buffer=function(a){if(a){this.buffer=a;this.is_atapi&&(this.status_reg=89,this.error_reg=96);this.sector_count=this.buffer.byteLength/this.sector_size;this.sector_count!==(this.sector_count|0)&&(C(this.name+": warning: disk size not aligned with sector size",
484
+ 32768),this.sector_count=Math.ceil(this.sector_count));this.is_atapi?(this.head_count=1,this.sectors_per_track=2048):(this.head_count=16,this.sectors_per_track=63);this.cylinder_count=this.sector_count/this.head_count/this.sectors_per_track;this.cylinder_count!==(this.cylinder_count|0)&&(C(this.name+": warning: rounding up cylinder count, choose different head number",32768),this.cylinder_count=Math.floor(this.cylinder_count));if(0===this.interface_nr){a=this.cpu.devices.rtc;a.cmos_write(57,a.cmos_read(57)|
485
+ 1<<4*this.channel_nr);a.cmos_write(18,a.cmos_read(18)&15|240);const b=0===this.channel_nr?27:36;a.cmos_write(b+0,this.cylinder_count&255);a.cmos_write(b+1,this.cylinder_count>>8&255);a.cmos_write(b+2,this.head_count&255);a.cmos_write(b+3,255);a.cmos_write(b+4,255);a.cmos_write(b+5,200);a.cmos_write(b+6,this.cylinder_count&255);a.cmos_write(b+7,this.cylinder_count>>8&255);a.cmos_write(b+8,this.sectors_per_track&255)}this.channel.cpu&&this.push_irq()}};W.prototype.device_reset=function(){this.is_atapi?
486
+ (this.status_reg=0,this.lba_low_reg=this.error_reg=this.sector_count_reg=1,this.lba_mid_reg=20,this.lba_high_reg=235):(this.status_reg=81,this.lba_low_reg=this.error_reg=this.sector_count_reg=1,this.lba_high_reg=this.lba_mid_reg=0);this.cancel_io_operations()};W.prototype.push_irq=function(){this.channel.push_irq()};W.prototype.ata_abort_command=function(){this.error_reg=4;this.status_reg=65;this.push_irq()};W.prototype.capture_regs=function(){return`ST=${m(this.status_reg&255)} ER=${m(this.error_reg&
487
+ 255)} `+`SC=${m(this.sector_count_reg&255)} LL=${m(this.lba_low_reg&255)} `+`LM=${m(this.lba_mid_reg&255)} LH=${m(this.lba_high_reg&255)} `+`FE=${m(this.features_reg&255)}`};W.prototype.ata_command=function(a){if(this.drive_connected||144===a){var b=this.capture_regs(),c=!0;this.current_command=a;this.error_reg=0;switch(a){case 8:this.data_length=this.data_end=this.data_pointer=0;this.device_reset();this.push_irq();break;case 16:this.lba_mid_reg=0;this.status_reg=80;this.push_irq();break;case 248:var d=
488
+ this.sector_count-1;this.lba_low_reg=d&255;this.lba_mid_reg=d>>8&255;this.lba_high_reg=d>>16&255;this.device_reg=this.device_reg&240|d>>24&15;this.status_reg=80;this.push_irq();break;case 39:d=this.sector_count-1;this.lba_low_reg=d&255;this.lba_mid_reg=d>>8&255;this.lba_high_reg=d>>16&255;this.lba_low_reg|=d>>24<<8&65280;this.status_reg=80;this.push_irq();break;case 32:c=!1;this.is_atapi?(this.lba_mid_reg=20,this.lba_high_reg=235,this.ata_abort_command()):this.ata_read_sectors(a);break;case 36:case 41:case 196:c=
489
+ !1;this.is_atapi?this.ata_abort_command():this.ata_read_sectors(a);break;case 48:case 52:case 57:case 197:c=!1;this.is_atapi?this.ata_abort_command():this.ata_write_sectors(a);break;case 144:this.channel.master.status_reg=80;this.channel.master.error_reg=1;this.channel.master.push_irq();this.channel.slave.drive_connected&&(this.channel.slave.status_reg=80,this.channel.slave.error_reg=1,this.channel.slave.push_irq());break;case 145:this.status_reg=80;this.push_irq();break;case 160:this.is_atapi?(c=
490
+ !1,this.data_allocate(12),this.data_end=12,this.sector_count_reg=1,this.status_reg=88,this.push_irq()):this.ata_abort_command();break;case 161:this.is_atapi?(this.create_identify_packet(),this.status_reg=88,this.push_irq()):this.ata_abort_command();break;case 198:C(this.name+": logical sectors per DRQ Block: "+m(this.sector_count_reg&255),32768);this.sectors_per_drq=this.sector_count_reg&255;this.status_reg=80;this.push_irq();break;case 200:case 37:c=!1;this.ata_read_sectors_dma(a);break;case 202:case 53:c=
491
+ !1;this.ata_write_sectors_dma(a);break;case 64:this.status_reg=80;this.push_irq();break;case 218:this.is_atapi&&(this.buffer||(this.error_reg|=2),this.medium_changed&&(this.error_reg|=32,this.medium_changed=!1),this.error_reg|=64);this.status_reg=80;this.push_irq();break;case 224:this.status_reg=80;this.push_irq();break;case 225:this.status_reg=80;this.push_irq();break;case 231:this.status_reg=80;this.push_irq();break;case 234:this.status_reg=80;this.push_irq();break;case 236:this.is_atapi?(this.lba_mid_reg=
492
+ 20,this.lba_high_reg=235,this.ata_abort_command()):(this.create_identify_packet(),this.status_reg=88,this.push_irq());break;case 239:this.status_reg=80;this.push_irq();break;case 222:this.status_reg=64;this.push_irq();break;case 245:this.status_reg=80;this.push_irq();break;case 249:this.ata_abort_command();break;case 0:this.ata_abort_command();break;default:k(!1,`${this.name}: error: unimplemented ATA command ${m(a)}: ABORT [${this.capture_regs()}]`,32768),this.ata_abort_command()}c&&(b=`[${b}] -> [${this.capture_regs()}]`,
493
+ c=this.status_reg&1?this.error_reg&4?"ABORT":"ERROR":"OK",C(`${this.name}: ATA command ${Tc[a]} (${m(a)}): ${c} ${b}`,32768))}else C(`${this.name}: ATA command ${Tc[a]} (${m(a)}) ignored: no slave drive connected`,32768)};W.prototype.atapi_handle=function(){const a=this.data[0],b=Uc[a]?Uc[a].name:"<undefined>";var c=Uc[a]?Uc[a].flags:0,d=this.capture_regs(),e=!0;let f;this.data_pointer=0;this.current_atapi_command=a;3!==a&&(this.atapi_add_sense=this.atapi_sense_key=0);if(!this.buffer&&c&1)this.atapi_check_condition_response(2,
494
+ 58),this.push_irq(),C(`${this.name}: ATAPI command ${b} (${m(a)}) without medium: ERROR [${d}]`,32768);else{switch(a){case 0:this.buffer?(this.data_allocate(0),this.data_end=this.data_length,this.status_reg=80):this.atapi_check_condition_response(2,58);break;case 3:this.data_allocate(this.data[4]);this.data_end=this.data_length;this.status_reg=88;this.data[0]=240;this.data[2]=this.atapi_sense_key;this.data[7]=8;this.data[12]=this.atapi_add_sense;this.atapi_add_sense=this.atapi_sense_key=0;break;case 18:c=
495
+ this.data[4];this.status_reg=88;f="lun="+m(this.data[1],2)+" length="+c;this.data.set([5,128,1,49,31,0,0,0,83,79,78,89,32,32,32,32,67,68,45,82,79,77,32,67,68,85,45,49,48,48,48,32,49,46,49,97]);this.data_end=this.data_length=Math.min(36,c);break;case 26:this.data_allocate(this.data[4]);this.data_end=this.data_length;this.status_reg=88;break;case 30:this.data_allocate(0);this.data_end=this.data_length;this.status_reg=80;break;case 37:c=this.sector_count-1;this.data_set(new Uint8Array([c>>24&255,c>>
496
+ 16&255,c>>8&255,c&255,0,0,this.sector_size>>8&255,this.sector_size&255]));this.data_end=this.data_length;this.status_reg=88;break;case 40:e=!1;this.features_reg&1?this.atapi_read_dma(this.data):this.atapi_read(this.data);break;case 66:c=this.data[8];f="length="+c;this.data_allocate(Math.min(8,c));this.data_end=this.data_length;this.status_reg=88;break;case 67:c=this.data[8]|this.data[7]<<8;var h=this.data[9]>>6;f=`${m(h,2)} length=${c} ${!!(this.data[1]&2)} ${m(this.data[6])}`;this.data_allocate(c);
497
+ this.data_end=this.data_length;0===h?(c=this.sector_count,this.data.set(new Uint8Array([0,18,1,1,0,20,1,0,0,0,0,0,0,22,170,0,c>>24,c>>16&255,c>>8&255,c&255]))):1===h?this.data.set(new Uint8Array([0,10,1,1,0,0,0,0,0,0,0,0])):k(!1,this.name+": error: unimplemented format: "+h);this.status_reg=88;break;case 70:c=Math.min(this.data[8]|this.data[7]<<8,32);f="length="+c;this.data_allocate(c);this.data_end=this.data_length;this.data[0]=c-4>>24&255;this.data[1]=c-4>>16&255;this.data[2]=c-4>>8&255;this.data[3]=
498
+ c-4&255;this.data[6]=8;this.data[10]=3;this.status_reg=88;break;case 81:this.data_allocate(0);this.data_end=this.data_length;this.status_reg=80;break;case 82:f="unimplemented";this.atapi_check_condition_response(5,36);break;case 90:c=this.data[8]|this.data[7]<<8;h=this.data[2];f="page_code="+m(h)+" length="+c;42===h&&this.data_allocate(Math.min(30,c));this.data_end=this.data_length;this.status_reg=88;break;case 189:this.data_allocate(this.data[9]|this.data[8]<<8);this.data_end=this.data_length;this.data[5]=
499
+ 1;this.status_reg=88;break;case 27:c=this.data[4]&3;f=`Immed=${m(this.data[1]&1)} LoEj/Start=${m(c)}`;this.buffer&&2===c&&(f+=": disk ejected",this.medium_changed=!0,this.buffer=null);this.status_reg=80;this.data_allocate(0);this.data_end=this.data_length;break;case 69:case 74:f="unimplemented";this.atapi_check_condition_response(5,36);break;case 190:f="unimplemented";this.data_allocate(0);this.data_end=this.data_length;this.status_reg=80;break;default:k(!1,`${this.name}: error: unimplemented ATAPI command ${m(this.data[0])}`,
500
+ 32768),this.atapi_check_condition_response(5,36)}this.sector_count_reg=this.sector_count_reg&-8|2;0===(this.status_reg&128)&&this.push_irq();0===(this.status_reg&128)&&0===this.data_length&&(this.sector_count_reg|=1,this.status_reg&=-9);e&&(d=`[${d}] -> [${this.capture_regs()}]`,e=this.status_reg&1?this.error_reg&4?"ABORT":"ERROR":"OK",f=f?` ${f}:`:"",C(`${this.name}: ATAPI command ${b} (${m(a)}):${f} ${e} ${d}`,32768))}};W.prototype.atapi_check_condition_response=function(a,b){this.data_allocate(0);
501
+ this.data_end=this.data_length;this.status_reg=65;this.error_reg=a<<4;this.sector_count_reg=this.sector_count_reg&-8|3;this.atapi_sense_key=a;this.atapi_add_sense=b};W.prototype.do_write=function(){this.status_reg=80;k(this.data_length<=this.data.length);var a=this.data.subarray(0,this.data_length);k(0===this.data_length%512);this.ata_advance(this.current_command,this.data_length/512);this.push_irq();this.buffer.set(this.write_dest,a,function(){});this.report_write(this.data_length)};W.prototype.atapi_read=
502
+ function(a){var b=(a[7]<<8|a[8])*this.sector_size;a=(a[2]<<24|a[3]<<16|a[4]<<8|a[5])*this.sector_size;this.data_length=0;var c=this.lba_high_reg<<8&65280|this.lba_mid_reg&255;this.lba_mid_reg=this.lba_high_reg=0;65535===c&&c--;c>b&&(c=b);this.buffer?a>=this.buffer.byteLength?(k(!1,this.name+": CD read: Outside of disk end="+m(a+b)+" size="+m(this.buffer.byteLength),32768),this.status_reg=255,this.push_irq()):0===b?(this.status_reg=80,this.data_pointer=0):(b=Math.min(b,this.buffer.byteLength-a),this.status_reg=
503
+ 208,this.report_read_start(),this.read_buffer(a,b,d=>{this.data_set(d);this.status_reg=88;this.sector_count_reg=this.sector_count_reg&-8|2;this.push_irq();this.data_end=c&=-4;this.data_end>this.data_length&&(this.data_end=this.data_length);this.lba_mid_reg=this.data_end&255;this.lba_high_reg=this.data_end>>8&255;this.report_read_end(b)})):(k(!1,this.name+": CD read: no buffer",32768),this.status_reg=255,this.error_reg=65,this.push_irq())};W.prototype.atapi_read_dma=function(a){var b=a[2]<<24|a[3]<<
504
+ 16|a[4]<<8|a[5],c=a[7]<<8|a[8];a=a[1];var d=c*this.sector_size,e=b*this.sector_size;C(this.name+": CD read DMA lba="+m(b)+" lbacount="+m(c)+" bytecount="+m(d)+" flags="+m(a),32768);e>=this.buffer.byteLength?(k(!1,this.name+": CD read: Outside of disk end="+m(e+d)+" size="+m(this.buffer.byteLength),32768),this.status_reg=255,this.push_irq()):(this.status_reg=208,this.report_read_start(),this.read_buffer(e,d,f=>{C(this.name+": atapi_read_dma: Data arrived");this.report_read_end(d);this.status_reg=
505
+ 88;this.sector_count_reg=this.sector_count_reg&-8|2;this.data_set(f);this.do_atapi_dma()}))};W.prototype.do_atapi_dma=function(){if(0===(this.channel.dma_status&1))C(this.name+": do_atapi_dma: Status not set",32768);else if(0===(this.status_reg&8))C(this.name+": do_atapi_dma: DRQ not set",32768);else{var a=this.channel.prdt_addr,b=0,c=this.data;do{var d=this.cpu.read32s(a),e=this.cpu.read16(a+4),f=this.cpu.read8(a+7)&128;e||(e=65536);this.cpu.write_blob(c.subarray(b,Math.min(b+e,this.data_length)),
506
+ d);b+=e;a+=8;if(b>=this.data_length&&!f)break}while(!f);this.status_reg=80;this.channel.dma_status&=-2;this.sector_count_reg=this.sector_count_reg&-8|3;this.push_irq()}};W.prototype.read_data=function(a){if(this.data_pointer<this.data_end){k(this.data_pointer+a-1<this.data_end);k(0===this.data_pointer%a,m(this.data_pointer)+" "+a);var b=1===a?this.data[this.data_pointer]:2===a?this.data16[this.data_pointer>>>1]:this.data32[this.data_pointer>>>2];this.data_pointer+=a;this.data_pointer>=this.data_end&&
507
+ this.read_end();return b}this.data_pointer+=a;return 0};W.prototype.read_end=function(){if(160===this.current_command)if(this.data_end===this.data_length)this.status_reg=80,this.sector_count_reg=this.sector_count_reg&-8|3,this.push_irq();else{this.status_reg=88;this.sector_count_reg=this.sector_count_reg&-8|2;this.push_irq();var a=this.lba_high_reg<<8&65280|this.lba_mid_reg&255;this.data_end+a>this.data_length?(this.lba_mid_reg=this.data_length-this.data_end&255,this.lba_high_reg=this.data_length-
508
+ this.data_end>>8&255,this.data_end=this.data_length):this.data_end+=a}else this.error_reg=0,this.data_pointer>=this.data_length?this.status_reg=80:(41===this.current_command||196===this.current_command?(a=Math.min(this.sectors_per_drq,(this.data_length-this.data_end)/512),k(0===a%1)):(k(32===this.current_command||36===this.current_command),a=1),this.ata_advance(this.current_command,a),this.data_end+=512*a,this.status_reg=88,this.push_irq())};W.prototype.write_data_port=function(a,b){k(0===this.data_pointer%
509
+ b);this.data_pointer>=this.data_end?C(this.name+": redundant write to data port: "+m(a)+" count="+m(this.data_end)+" cur="+m(this.data_pointer),32768):(1===b?this.data[this.data_pointer++]=a:2===b?(this.data16[this.data_pointer>>>1]=a,this.data_pointer+=2):(this.data32[this.data_pointer>>>2]=a,this.data_pointer+=4),k(this.data_pointer<=this.data_end),this.data_pointer===this.data_end&&this.write_end())};W.prototype.write_data_port8=function(a){this.write_data_port(a,1)};W.prototype.write_data_port16=
510
+ function(a){this.write_data_port(a,2)};W.prototype.write_data_port32=function(a){this.write_data_port(a,4)};W.prototype.write_end=function(){160===this.current_command?this.atapi_handle():this.data_pointer>=this.data_length?this.do_write():(k(48===this.current_command||52===this.current_command||197===this.current_command,"Unexpected command: "+m(this.current_command)),this.status_reg=88,this.data_end+=512,this.push_irq())};W.prototype.ata_advance=function(a,b){this.sector_count_reg-=b;36===a||41===
511
+ a||37===a||52===a||57===a||53===a?(a=b+this.get_lba48(),this.lba_low_reg=a&255|a>>16&65280,this.lba_mid_reg=a>>8&255,this.lba_high_reg=a>>16&255):this.is_lba?(a=b+this.get_lba28(),this.lba_low_reg=a&255,this.lba_mid_reg=a>>8&255,this.lba_high_reg=a>>16&255,this.head=this.head&-16|a&15):(a=b+this.get_chs(),b=a/(this.head_count*this.sectors_per_track)|0,this.lba_mid_reg=b&255,this.lba_high_reg=b>>8&255,this.head=(a/this.sectors_per_track|0)%this.head_count&15,this.lba_low_reg=a%this.sectors_per_track+
512
+ 1&255,k(a===this.get_chs()))};W.prototype.ata_read_sectors=function(a){var b=36===a||41===a,c=this.get_count(b);b=this.get_lba(b);var d=32===a||36===a,e=c*this.sector_size;b*=this.sector_size;b+e>this.buffer.byteLength?(k(!1,this.name+": ATA read: Outside of disk",32768),this.status_reg=255,this.push_irq()):(this.status_reg=192,this.report_read_start(),this.read_buffer(b,e,f=>{this.data_set(f);this.status_reg=88;this.data_end=d?512:Math.min(e,512*this.sectors_per_drq);this.ata_advance(a,d?1:Math.min(c,
513
+ this.sectors_per_track));this.push_irq();this.report_read_end(e)}))};W.prototype.ata_read_sectors_dma=function(a){a=37===a;var b=this.get_count(a);this.get_lba(a)*this.sector_size+b*this.sector_size>this.buffer.byteLength?(k(!1,this.name+": ATA read: Outside of disk",32768),this.status_reg=255,this.push_irq()):(this.status_reg=88,this.channel.dma_status|=1)};W.prototype.do_ata_read_sectors_dma=function(){var a=37===this.current_command,b=this.get_count(a);a=this.get_lba(a);var c=b*this.sector_size,
514
+ d=a*this.sector_size;k(a<this.buffer.byteLength);this.report_read_start();var e=this.channel.prdt_addr;this.read_buffer(d,c,f=>{var h=this.channel.prdt_addr,l=0;k(e===h);do{var p=this.cpu.read32s(h),n=this.cpu.read16(h+4),q=this.cpu.read8(h+7)&128;n||(n=65536);this.cpu.write_blob(f.subarray(l,l+n),p);l+=n;h+=8}while(!q);k(l===c);this.ata_advance(this.current_command,b);this.status_reg=80;this.channel.dma_status&=-2;this.current_command=-1;this.report_read_end(c);this.push_irq()})};W.prototype.ata_write_sectors=
515
+ function(a){var b=52===a||57===a,c=this.get_count(b);b=this.get_lba(b);a=48===a||52===a;c*=this.sector_size;b*=this.sector_size;b+c>this.buffer.byteLength?(k(!1,this.name+": ATA write: Outside of disk",32768),this.status_reg=255,this.push_irq()):(this.status_reg=88,this.data_allocate_noclear(c),this.data_end=a?512:Math.min(c,512*this.sectors_per_drq),this.write_dest=b)};W.prototype.ata_write_sectors_dma=function(a){a=53===a;var b=this.get_count(a);this.get_lba(a)*this.sector_size+b*this.sector_size>
516
+ this.buffer.byteLength?(k(!1,this.name+": ATA DMA write: Outside of disk",32768),this.status_reg=255,this.push_irq()):(this.status_reg=88,this.channel.dma_status|=1)};W.prototype.do_ata_write_sectors_dma=function(){var a=53===this.current_command,b=this.get_count(a),c=this.get_lba(a);a=b*this.sector_size;c*=this.sector_size;var d=this.channel.prdt_addr,e=0;const f=new Uint8Array(a);do{var h=this.cpu.read32s(d),l=this.cpu.read16(d+4),p=this.cpu.read8(d+7)&128;l||(l=65536,C(this.name+": DMA: prd count was 0",
517
+ 32768));h=this.cpu.mem8.subarray(h,h+l);k(h.length===l);f.set(h,e);e+=l;d+=8}while(!p);k(e===f.length);this.buffer.set(c,f,()=>{this.ata_advance(this.current_command,b);this.status_reg=80;this.push_irq();this.channel.dma_status&=-2;this.current_command=-1});this.report_write(a)};W.prototype.get_chs=function(){return((this.lba_mid_reg&255|this.lba_high_reg<<8&65280)*this.head_count+this.head)*this.sectors_per_track+(this.lba_low_reg&255)-1};W.prototype.get_lba28=function(){return this.lba_low_reg&
518
+ 255|this.lba_mid_reg<<8&65280|this.lba_high_reg<<16&16711680|(this.head&15)<<24};W.prototype.get_lba48=function(){return(this.lba_low_reg&255|this.lba_mid_reg<<8&65280|this.lba_high_reg<<16&16711680|this.lba_low_reg>>8<<24&4278190080)>>>0};W.prototype.get_lba=function(a){return a?this.get_lba48():this.is_lba?this.get_lba28():this.get_chs()};W.prototype.get_count=function(a){a?(a=this.sector_count_reg,0===a&&(a=65536)):(a=this.sector_count_reg&255,0===a&&(a=256));return a};W.prototype.create_identify_packet=
519
+ function(){const a=Math.min(16383,this.cylinder_count),b=(h,l,p,n)=>{l<<=1;var q=p<<1;p=l+q;h.fill(32,l,q);for(q=0;q<n.length&&l<p;q++)q&1?(h[l]=n.charCodeAt(q),l+=2):h[l+1]=n.charCodeAt(q)},c=this.is_atapi?34112:64,d=160===this.current_command?0:1031,e=this.is_atapi?16928:16384,f=this.is_atapi?20480:29696;this.data.fill(0,0,512);this.data_set([c&255,c>>8&255,a&255,a>>8&255,0,0,this.head_count&255,this.head_count>>8&255,this.sectors_per_track/512&255,this.sectors_per_track/512>>8&255,0,2,this.sectors_per_track&
520
+ 255,this.sectors_per_track>>8&255,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,3,0,0,2,4,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,1,0,0,2,0,0,0,2,0,2,7,0,a&255,a>>8&255,this.head_count&255,this.head_count>>8&255,this.sectors_per_track,0,this.sector_count&255,this.sector_count>>8&255,this.sector_count>>16&255,this.sector_count>>24&255,0,0,this.sector_count&255,this.sector_count>>8&255,this.sector_count>>16&255,this.sector_count>>
521
+ 24&255,0,0,d&255,d>>8&255,0,0,30,0,30,0,30,0,30,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,e&255,e>>8&255,f&255,f>>8&255,0,64,e&255,e>>8&255,f&255,f>>8&255,0,64,0,0,0,0,0,0,0,0,0,0,1,96,0,0,0,0,0,0,0,0,0,0,0,0,this.sector_count&255,this.sector_count>>8&255,this.sector_count>>16&255,this.sector_count>>24&255]);b(this.data,10,10,`8086-86${this.channel_nr}${this.interface_nr}`);b(this.data,23,4,"1.00");b(this.data,27,20,this.is_atapi?"v86 ATAPI CD-ROM":"v86 ATA HD");this.data_end=this.data_length=
522
+ 512};W.prototype.data_allocate=function(a){this.data_allocate_noclear(a);this.data32.fill(0,0,a+3>>2)};W.prototype.data_allocate_noclear=function(a){this.data.length<a&&(this.data=new Uint8Array(a+3&-4),this.data16=new Uint16Array(this.data.buffer),this.data32=new Int32Array(this.data.buffer));this.data_length=a;this.data_pointer=0};W.prototype.data_set=function(a){this.data_allocate_noclear(a.length);this.data.set(a)};W.prototype.report_read_start=function(){this.bus.send("ide-read-start")};W.prototype.report_read_end=
523
+ function(a){this.bus.send("ide-read-end",[this.channel_nr,a,a/this.sector_size|0])};W.prototype.report_write=function(a){this.bus.send("ide-write-end",[this.channel_nr,a,a/this.sector_size|0])};W.prototype.read_buffer=function(a,b,c){const d=this.last_io_id++;this.in_progress_io_ids.add(d);this.buffer.get(a,b,e=>{if(this.cancelled_io_ids.delete(d))k(!this.in_progress_io_ids.has(d));else{var f=this.in_progress_io_ids.delete(d);k(f);c(e)}})};W.prototype.cancel_io_operations=function(){for(const a of this.in_progress_io_ids)this.cancelled_io_ids.add(a);
524
+ this.in_progress_io_ids.clear()};W.prototype.get_state=function(){var a=[];a[0]=this.sector_count_reg;a[1]=this.cylinder_count;a[2]=this.lba_high_reg;a[3]=this.lba_mid_reg;a[4]=this.data_pointer;a[5]=0;a[6]=0;a[7]=0;a[8]=0;a[9]=this.device_reg;a[10]=this.error_reg;a[11]=this.head;a[12]=this.head_count;a[13]=this.is_atapi;a[14]=this.is_lba;a[15]=this.features_reg;a[16]=this.data;a[17]=this.data_length;a[18]=this.lba_low_reg;a[19]=this.sector_count;a[20]=this.sector_size;a[21]=this.sectors_per_drq;
525
+ a[22]=this.sectors_per_track;a[23]=this.status_reg;a[24]=this.write_dest;a[25]=this.current_command;a[26]=this.data_end;a[27]=this.current_atapi_command;a[28]=this.buffer;return a};W.prototype.set_state=function(a){this.sector_count_reg=a[0];this.cylinder_count=a[1];this.lba_high_reg=a[2];this.lba_mid_reg=a[3];this.data_pointer=a[4];this.device_reg=a[9];this.error_reg=a[10];this.head=a[11];this.head_count=a[12];this.is_atapi=a[13];this.is_lba=a[14];this.features_reg=a[15];this.data=a[16];this.data_length=
526
+ a[17];this.lba_low_reg=a[18];this.sector_count=a[19];this.sector_size=a[20];this.sectors_per_drq=a[21];this.sectors_per_track=a[22];this.status_reg=a[23];this.write_dest=a[24];this.current_command=a[25];this.data_end=a[26];this.current_atapi_command=a[27];this.data16=new Uint16Array(this.data.buffer);this.data32=new Int32Array(this.data.buffer);this.buffer&&this.buffer.set_state(a[28]);this.drive_connected=this.is_atapi||this.buffer;this.medium_changed=!1};function Xc(a,b,c){this.bus=b;this.id=a.devices.net?
527
+ 1:0;this.status=this.pairs=1;this.preserve_mac_from_state_image=c;this.mac=new Uint8Array([0,34,21,255*Math.random()|0,255*Math.random()|0,255*Math.random()|0]);this.bus.send("net"+this.id+"-mac",Fc(this.mac));b=[];for(c=0;c<this.pairs;++c)b.push({size_supported:1024,notify_offset:0}),b.push({size_supported:1024,notify_offset:1});b.push({size_supported:16,notify_offset:2});this.virtio=new Ic(a,{name:"virtio-net",pci_id:80,device_id:4161,subsystem_device_id:1,common:{initial_port:51200,queues:b,features:[5,
528
+ 16,22,3,17,23,32],on_driver_ok:()=>{}},notification:{initial_port:51456,single_handler:!1,handlers:[()=>{},d=>{const e=this.virtio.queues[d];for(;e.has_request();){const f=e.pop_request(),h=new Uint8Array(f.length_readable);f.get_next_blob(h);this.bus.send("net"+this.id+"-send",h.subarray(12));this.bus.send("eth-transmit-end",[h.length-12]);this.virtio.queues[d].push_reply(f)}this.virtio.queues[d].flush_replies()},d=>{if(d!==2*this.pairs)k(!1,"VirtioNet Notified for wrong queue: "+d+" (expected queue_id of 3)");
529
+ else for(var e=this.virtio.queues[d];e.has_request();){const l=e.pop_request();var f=new Uint8Array(l.length_readable);l.get_next_blob(f);var h=K(["b","b"],f,{offset:0});const p=h[0];h=h[1];switch(p<<8|h){case 1024:f=K(["h"],f,{offset:2});k(1===f[0]);this.Send(d,l,new Uint8Array([0]));break;case 257:this.mac=f.subarray(2,8);this.Send(d,l,new Uint8Array([0]));this.bus.send("net"+this.id+"-mac",Fc(this.mac));break;default:k(!1," VirtioNet received unknown command: "+p+":"+h);this.Send(d,l,new Uint8Array([1]));
530
+ return}}}]},isr_status:{initial_port:50944},device_specific:{initial_port:50688,struct:[0,1,2,3,4,5].map((d,e)=>({bytes:1,name:"mac_"+e,read:()=>this.mac[e],write:()=>{}})).concat([{bytes:2,name:"status",read:()=>this.status,write:()=>{}},{bytes:2,name:"max_pairs",read:()=>this.pairs,write:()=>{}},{bytes:2,name:"mtu",read:()=>1500,write:()=>{}}])}});this.bus.register("net"+this.id+"-receive",d=>{this.bus.send("eth-receive-end",[d.length]);const e=new Uint8Array(12+d.byteLength);(new DataView(e.buffer,
531
+ e.byteOffset,e.byteLength)).setInt16(10,1);e.set(d,12);d=this.virtio.queues[0];d.has_request()?(d=d.pop_request(),d.set_next_blob(e),this.virtio.queues[0].push_reply(d),this.virtio.queues[0].flush_replies()):console.log("No buffer to write into!")},this)}Xc.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.id;a[2]=this.mac;return a};Xc.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.id=a[1];this.preserve_mac_from_state_image&&(this.mac=a[2],this.bus.send("net"+
532
+ this.id+"-mac",Fc(this.mac)))};Xc.prototype.reset=function(){this.virtio.reset()};Xc.prototype.Send=function(a,b,c){b.set_next_blob(c);this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};Xc.prototype.Ack=function(a,b){this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};const Yc=Uint32Array.from([655360,655360,720896,753664]),Zc=Uint32Array.from([131072,65536,32768,32768]);function X(a,b,c,d){this.cpu=a;this.bus=b;this.screen=c;this.vga_memory_size=d;this.cursor_address=
533
+ 0;this.cursor_scanline_start=14;this.cursor_scanline_end=15;this.max_cols=80;this.max_rows=25;this.virtual_height=this.virtual_width=this.screen_height=this.screen_width=0;this.layers=[];this.start_address_latched=this.start_address=0;this.crtc=new Uint8Array(25);this.line_compare=this.offset_register=this.preset_row_scan=this.underline_location_register=this.vertical_blank_start=this.vertical_display_enable_end=this.horizontal_blank_start=this.horizontal_display_enable_end=this.crtc_mode=0;this.graphical_mode=
534
+ !1;this.vga256_palette=new Int32Array(256);this.latch_dword=0;this.svga_version=45253;this.svga_height=this.svga_width=0;this.svga_enabled=!1;this.svga_bpp=32;this.svga_offset_y=this.svga_offset_x=this.svga_offset=this.svga_bank_offset=0;this.vga_memory_size=void 0===this.vga_memory_size||262144>this.vga_memory_size?262144:268435456<this.vga_memory_size?268435456:ka(this.vga_memory_size);C("effective vga memory size: "+this.vga_memory_size,256);this.pci_space=[52,18,17,17,3,1,0,0,0,0,0,3,0,0,0,0,
535
+ 8,14680064,57344,224,0,0,0,0,0,0,191,254,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,244,26,0,17,0,0,190,254,0,0,0,0,0,0,0,0,0,0,0,0];this.pci_id=144;this.pci_bars=[{size:this.vga_memory_size}];this.pci_rom_size=65536;this.pci_rom_address=4272947200;this.name="vga";this.dac_state=this.dac_color_index_read=this.dac_color_index_write=this.index_crtc=0;this.dac_mask=255;this.dac_map=new Uint8Array(16);this.attribute_controller_index=-1;this.palette_source=32;this.color_select=this.horizontal_panning=this.color_plane_enable=
536
+ this.attribute_mode=0;this.sequencer_index=-1;this.plane_write_bm=15;this.clocking_mode=this.sequencer_memory_mode=0;this.graphics_index=-1;this.planar_rotate_reg=this.planar_mode=this.plane_read=this.character_map_select=0;this.planar_bitmap=255;this.max_scan_line=this.color_dont_care=this.color_compare=this.miscellaneous_graphics_register=this.planar_setreset_enable=this.planar_setreset=0;this.port_3DA_value=this.miscellaneous_output_register=255;this.font_page_ab_enabled=!1;b=a.io;b.register_write(960,
537
+ this,this.port3C0_write);b.register_read(960,this,this.port3C0_read,this.port3C0_read16);b.register_read(961,this,this.port3C1_read);b.register_write(962,this,this.port3C2_write);b.register_write_consecutive(964,this,this.port3C4_write,this.port3C5_write);b.register_read(964,this,this.port3C4_read);b.register_read(965,this,this.port3C5_read);b.register_write_consecutive(974,this,this.port3CE_write,this.port3CF_write);b.register_read(974,this,this.port3CE_read);b.register_read(975,this,this.port3CF_read);
538
+ b.register_read(966,this,this.port3C6_read);b.register_write(966,this,this.port3C6_write);b.register_write(967,this,this.port3C7_write);b.register_read(967,this,this.port3C7_read);b.register_write(968,this,this.port3C8_write);b.register_read(968,this,this.port3C8_read);b.register_write(969,this,this.port3C9_write);b.register_read(969,this,this.port3C9_read);b.register_read(972,this,this.port3CC_read);b.register_write(980,this,this.port3D4_write,this.port3D4_write16);b.register_write(981,this,this.port3D5_write,
539
+ this.port3D5_write16);b.register_read(980,this,this.port3D4_read);b.register_read(981,this,this.port3D5_read,this.port3D5_read16);b.register_write(948,this,this.port3D4_write,this.port3D4_write16);b.register_write(949,this,this.port3D5_write,this.port3D5_write16);b.register_read(948,this,this.port3D4_read);b.register_read(949,this,this.port3D5_read,this.port3D5_read16);b.register_read(970,this,function(){C("3CA read",256);return 0});b.register_read(986,this,this.port3DA_read);b.register_read(954,
540
+ this,this.port3DA_read);this.dispi_index=-1;this.dispi_enable_value=0;b.register_write(462,this,void 0,this.port1CE_write);b.register_write(463,this,void 0,this.port1CF_write);b.register_read(463,this,void 0,this.port1CF_read);c=a.svga_allocate_memory(this.vga_memory_size)>>>0;this.svga_memory=g(Uint8Array,a.wasm_memory,c,this.vga_memory_size);this.diff_addr_min=this.vga_memory_size;this.diff_addr_max=0;this.diff_plot_min=this.vga_memory_size;this.diff_plot_max=0;this.image_data=null;this.vga_memory=
541
+ new Uint8Array(262144);this.plane0=new Uint8Array(this.vga_memory.buffer,0,65536);this.plane1=new Uint8Array(this.vga_memory.buffer,65536,65536);this.plane2=new Uint8Array(this.vga_memory.buffer,131072,65536);this.plane3=new Uint8Array(this.vga_memory.buffer,196608,65536);this.pixel_buffer=new Uint8Array(524288);b.mmap_register(655360,131072,e=>this.vga_memory_read(e),(e,f)=>this.vga_memory_write(e,f));a.devices.pci.register_device(this)}X.prototype.get_state=function(){var a=[];a[0]=this.vga_memory_size;
542
+ a[1]=this.cursor_address;a[2]=this.cursor_scanline_start;a[3]=this.cursor_scanline_end;a[4]=this.max_cols;a[5]=this.max_rows;a[6]=this.vga_memory;a[7]=this.dac_state;a[8]=this.start_address;a[9]=this.graphical_mode;a[10]=this.vga256_palette;a[11]=this.latch_dword;a[12]=this.color_compare;a[13]=this.color_dont_care;a[14]=this.miscellaneous_graphics_register;a[15]=this.svga_width;a[16]=this.svga_height;a[17]=this.crtc_mode;a[18]=this.svga_enabled;a[19]=this.svga_bpp;a[20]=this.svga_bank_offset;a[21]=
543
+ this.svga_offset;a[22]=this.index_crtc;a[23]=this.dac_color_index_write;a[24]=this.dac_color_index_read;a[25]=this.dac_map;a[26]=this.sequencer_index;a[27]=this.plane_write_bm;a[28]=this.sequencer_memory_mode;a[29]=this.graphics_index;a[30]=this.plane_read;a[31]=this.planar_mode;a[32]=this.planar_rotate_reg;a[33]=this.planar_bitmap;a[34]=this.max_scan_line;a[35]=this.miscellaneous_output_register;a[36]=this.port_3DA_value;a[37]=this.dispi_index;a[38]=this.dispi_enable_value;a[39]=this.svga_memory;
544
+ a[41]=this.attribute_controller_index;a[42]=this.offset_register;a[43]=this.planar_setreset;a[44]=this.planar_setreset_enable;a[45]=this.start_address_latched;a[46]=this.crtc;a[47]=this.horizontal_display_enable_end;a[48]=this.horizontal_blank_start;a[49]=this.vertical_display_enable_end;a[50]=this.vertical_blank_start;a[51]=this.underline_location_register;a[52]=this.preset_row_scan;a[53]=this.offset_register;a[54]=this.palette_source;a[55]=this.attribute_mode;a[56]=this.color_plane_enable;a[57]=
545
+ this.horizontal_panning;a[58]=this.color_select;a[59]=this.clocking_mode;a[60]=this.line_compare;a[61]=this.pixel_buffer;a[62]=this.dac_mask;a[63]=this.character_map_select;a[64]=this.font_page_ab_enabled;return a};X.prototype.set_state=function(a){this.vga_memory_size=a[0];this.cursor_address=a[1];this.cursor_scanline_start=a[2];this.cursor_scanline_end=a[3];this.max_cols=a[4];this.max_rows=a[5];a[6]&&this.vga_memory.set(a[6]);this.dac_state=a[7];this.start_address=a[8];this.graphical_mode=a[9];
546
+ this.vga256_palette=a[10];this.latch_dword=a[11];this.color_compare=a[12];this.color_dont_care=a[13];this.miscellaneous_graphics_register=a[14];this.svga_width=a[15];this.svga_height=a[16];this.crtc_mode=a[17];this.svga_enabled=a[18];this.svga_bpp=a[19];this.svga_bank_offset=a[20];this.svga_offset=a[21];this.index_crtc=a[22];this.dac_color_index_write=a[23];this.dac_color_index_read=a[24];this.dac_map=a[25];this.sequencer_index=a[26];this.plane_write_bm=a[27];this.sequencer_memory_mode=a[28];this.graphics_index=
547
+ a[29];this.plane_read=a[30];this.planar_mode=a[31];this.planar_rotate_reg=a[32];this.planar_bitmap=a[33];this.max_scan_line=a[34];this.miscellaneous_output_register=a[35];this.port_3DA_value=a[36];this.dispi_index=a[37];this.dispi_enable_value=a[38];this.svga_memory.set(a[39]);this.attribute_controller_index=a[41];this.offset_register=a[42];this.planar_setreset=a[43];this.planar_setreset_enable=a[44];this.start_address_latched=a[45];this.crtc.set(a[46]);this.horizontal_display_enable_end=a[47];this.horizontal_blank_start=
548
+ a[48];this.vertical_display_enable_end=a[49];this.vertical_blank_start=a[50];this.underline_location_register=a[51];this.preset_row_scan=a[52];this.offset_register=a[53];this.palette_source=a[54];this.attribute_mode=a[55];this.color_plane_enable=a[56];this.horizontal_panning=a[57];this.color_select=a[58];this.clocking_mode=a[59];this.line_compare=a[60];a[61]&&this.pixel_buffer.set(a[61]);this.dac_mask=void 0===a[62]?255:a[62];this.character_map_select=void 0===a[63]?0:a[63];this.font_page_ab_enabled=
549
+ void 0===a[64]?0:a[64];this.screen.set_mode(this.graphical_mode);this.graphical_mode?(this.screen_height=this.screen_width=0,this.svga_enabled?(this.set_size_graphical(this.svga_width,this.svga_height,this.svga_width,this.svga_height,this.svga_bpp),this.update_layers()):(this.update_vga_size(),this.update_layers(),this.complete_replot())):(this.set_font_bitmap(!0),this.set_size_text(this.max_cols,this.max_rows),this.set_font_page(),this.update_cursor_scanline(),this.update_cursor());this.complete_redraw()};
550
+ X.prototype.vga_memory_read=function(a){if(this.svga_enabled)return this.cpu.read8((a-655360|this.svga_bank_offset)+3758096384|0);var b=this.miscellaneous_graphics_register>>2&3;a-=Yc[b];if(0>a||a>=Zc[b])return C("vga read outside memory space: addr:"+m(a),256),0;this.latch_dword=this.plane0[a];this.latch_dword|=this.plane1[a]<<8;this.latch_dword|=this.plane2[a]<<16;this.latch_dword|=this.plane3[a]<<24;if(this.planar_mode&8)return b=255,this.color_dont_care&1&&(b&=this.plane0[a]^~(this.color_compare&
551
+ 1?255:0)),this.color_dont_care&2&&(b&=this.plane1[a]^~(this.color_compare&2?255:0)),this.color_dont_care&4&&(b&=this.plane2[a]^~(this.color_compare&4?255:0)),this.color_dont_care&8&&(b&=this.plane3[a]^~(this.color_compare&8?255:0)),b;b=this.plane_read;this.graphical_mode?this.sequencer_memory_mode&8?(b=a&3,a&=-4):this.planar_mode&16&&(b=a&1,a&=-2):b&=3;return this.vga_memory[b<<16|a]};X.prototype.vga_memory_write=function(a,b){if(this.svga_enabled)this.cpu.write8((a-655360|this.svga_bank_offset)+
552
+ 3758096384|0,b);else{var c=this.miscellaneous_graphics_register>>2&3;a-=Yc[c];0>a||a>=Zc[c]?C("vga write outside memory space: addr:"+m(a)+", value:"+m(b),256):this.graphical_mode?this.vga_memory_write_graphical(a,b):this.plane_write_bm&3?this.vga_memory_write_text_mode(a,b):this.plane_write_bm&4&&(this.plane2[a]=b)}};X.prototype.vga_memory_write_graphical=function(a,b){var c=this.planar_mode&3,d=this.apply_feed(this.planar_bitmap),e=this.apply_expand(this.planar_setreset),f=this.apply_expand(this.planar_setreset_enable);
553
+ switch(c){case 0:b=this.apply_rotate(b);var h=this.apply_feed(b);h=this.apply_setreset(h,f);h=this.apply_logical(h,this.latch_dword);h=this.apply_bitmask(h,d);break;case 1:h=this.latch_dword;break;case 2:h=this.apply_expand(b);h=this.apply_logical(h,this.latch_dword);h=this.apply_bitmask(h,d);break;case 3:b=this.apply_rotate(b),d&=this.apply_feed(b),h=this.apply_bitmask(e,d)}b=15;switch(this.sequencer_memory_mode&12){case 0:b=5<<(a&1);a&=-2;break;case 8:case 12:b=1<<(a&3),a&=-4}b&=this.plane_write_bm;
554
+ b&1&&(this.plane0[a]=h>>0&255);b&2&&(this.plane1[a]=h>>8&255);b&4&&(this.plane2[a]=h>>16&255);b&8&&(this.plane3[a]=h>>24&255);a=this.vga_addr_to_pixel(a);this.partial_replot(a,a+7)};X.prototype.apply_feed=function(a){return a|a<<8|a<<16|a<<24};X.prototype.apply_expand=function(a){return(a&1?255:0)|(a&2?255:0)<<8|(a&4?255:0)<<16|(a&8?255:0)<<24};X.prototype.apply_rotate=function(a){return(a|a<<8)>>>(this.planar_rotate_reg&7)&255};X.prototype.apply_setreset=function(a,b){var c=this.apply_expand(this.planar_setreset);
555
+ return(a|b&c)&(~b|c)};X.prototype.apply_logical=function(a,b){switch(this.planar_rotate_reg&24){case 8:return a&b;case 16:return a|b;case 24:return a^b}return a};X.prototype.apply_bitmask=function(a,b){return b&a|~b&this.latch_dword};X.prototype.text_mode_redraw=function(){const a=this.scan_line_to_screen_row(this.line_compare),b=Math.max(0,2*(2*this.offset_register-this.max_cols)),c=this.attribute_mode&8,d=this.font_page_ab_enabled?7:15,e=c?7:15,f=this.screen.FLAG_BLINKING,h=this.screen.FLAG_FONT_PAGE_B;
556
+ let l=this.start_address<<1;for(let p=0;p<this.max_rows;p++){p===a&&(l=0);for(let n=0;n<this.max_cols;n++){const q=this.vga_memory[l],r=this.vga_memory[l|1],t=(c&&r&128?f:0)|(!this.font_page_ab_enabled||r&8?0:h);this.bus.send("screen-put-char",[p,n,q]);this.screen.put_char(p,n,q,t,this.vga256_palette[this.dac_mask&this.dac_map[r>>4&e]],this.vga256_palette[this.dac_mask&this.dac_map[r&d]]);l+=2}l+=b}};X.prototype.vga_memory_write_text_mode=function(a,b){this.vga_memory[a]=b;var c=Math.max(this.max_cols,
557
+ 2*this.offset_register);let d;if(a>>1>=this.start_address){var e=(a>>1)-this.start_address;d=e/c|0;c=e%c}else e=a>>1,d=(e/c|0)+this.scan_line_to_screen_row(this.line_compare),c=e%c;k(0<=d&&0<=c);if(!(c>=this.max_cols||d>=this.max_rows)){a&1?(e=b,b=this.vga_memory[a&-2]):e=this.vga_memory[a|1];var f=this.attribute_mode&8;a=(f&&e&128?this.screen.FLAG_BLINKING:0)|(!this.font_page_ab_enabled||e&8?0:this.screen.FLAG_FONT_PAGE_B);var h=this.font_page_ab_enabled?7:15;f=f?7:15;this.bus.send("screen-put-char",
558
+ [d,c,b]);this.screen.put_char(d,c,b,a,this.vga256_palette[this.dac_mask&this.dac_map[e>>4&f]],this.vga256_palette[this.dac_mask&this.dac_map[e&h]])}};X.prototype.update_cursor=function(){var a=Math.max(this.max_cols,2*this.offset_register);let b;this.cursor_address>=this.start_address?(b=(this.cursor_address-this.start_address)/a|0,a=(this.cursor_address-this.start_address)%a):(b=(this.cursor_address/a|0)+this.scan_line_to_screen_row(this.line_compare),a=this.cursor_address%a);k(0<=b&&0<=a);this.screen.update_cursor(b,
559
+ a)};X.prototype.complete_redraw=function(){C("complete redraw",256);this.graphical_mode?this.svga_enabled?this.cpu.svga_mark_dirty():(this.diff_addr_min=0,this.diff_addr_max=524288):this.text_mode_redraw()};X.prototype.complete_replot=function(){C("complete replot",256);this.graphical_mode&&!this.svga_enabled&&(this.diff_plot_min=0,this.diff_plot_max=524288,this.complete_redraw())};X.prototype.partial_redraw=function(a,b){a<this.diff_addr_min&&(this.diff_addr_min=a);b>this.diff_addr_max&&(this.diff_addr_max=
560
+ b)};X.prototype.partial_replot=function(a,b){a<this.diff_plot_min&&(this.diff_plot_min=a);b>this.diff_plot_max&&(this.diff_plot_max=b);this.partial_redraw(a,b)};X.prototype.reset_diffs=function(){this.diff_addr_min=this.vga_memory_size;this.diff_addr_max=0;this.diff_plot_min=this.vga_memory_size;this.diff_plot_max=0};X.prototype.destroy=function(){};X.prototype.vga_bytes_per_line=function(){var a=this.offset_register<<2;this.underline_location_register&64?a<<=1:this.crtc_mode&64&&(a>>>=1);return a};
561
+ X.prototype.vga_addr_shift_count=function(){var a=128+(~this.underline_location_register&this.crtc_mode&64);a-=this.underline_location_register&64;a-=this.attribute_mode&64;return a>>>6};X.prototype.vga_addr_to_pixel=function(a){var b=this.vga_addr_shift_count();if(~this.crtc_mode&3){var c=a-this.start_address;c&=this.crtc_mode<<13|-24577;c<<=b;var d=c/this.virtual_width|0;c%=this.virtual_width;switch(this.crtc_mode&3){case 2:d=d<<1|a>>13&1;break;case 1:d=d<<1|a>>14&1;break;case 0:d=d<<2|a>>13&3}return d*
562
+ this.virtual_width+c+(this.start_address<<b)}return a<<b};X.prototype.scan_line_to_screen_row=function(a){this.max_scan_line&128&&(a>>>=1);a=Math.ceil(a/(1+(this.max_scan_line&31)));this.crtc_mode&1||(a<<=1);this.crtc_mode&2||(a<<=1);return a};X.prototype.set_size_text=function(a,b){k(!this.graphical_mode);this.max_cols=a;this.max_rows=b;this.screen.set_size_text(a,b);this.bus.send("screen-set-size",[a,b,0])};X.prototype.set_size_graphical=function(a,b,c,d,e){k(this.graphical_mode);c=Math.max(c,1);
563
+ d=Math.max(d,1);if(this.screen_width!==a||this.screen_height!==b||this.virtual_width!==c||this.virtual_height!==d){this.screen_width=a;this.screen_height=b;this.virtual_width=c;this.virtual_height=d;if("undefined"!==typeof ImageData){const f=c*d,h=this.cpu.svga_allocate_dest_buffer(f)>>>0;this.dest_buffet_offset=h;this.image_data=new ImageData(new Uint8ClampedArray(this.cpu.wasm_memory.buffer,h,4*f),c,d);this.cpu.svga_mark_dirty()}this.screen.set_size_graphical(a,b,c,d);this.bus.send("screen-set-size",
564
+ [a,b,e])}};X.prototype.update_vga_size=function(){if(!this.svga_enabled){var a=Math.min(1+this.horizontal_display_enable_end,this.horizontal_blank_start),b=Math.min(1+this.vertical_display_enable_end,this.vertical_blank_start);if(a&&b)if(this.graphical_mode){a<<=3;var c=this.offset_register<<4,d=4;this.attribute_mode&64?(a>>>=1,c>>>=1,d=8):this.attribute_mode&2&&(d=1);b=this.scan_line_to_screen_row(b);var e=Zc[0];const f=this.vga_bytes_per_line();this.set_size_graphical(a,b,c,f?Math.ceil(e/f):b,d);
565
+ this.update_vertical_retrace();this.update_layers()}else this.max_scan_line&128&&(b>>>=1),c=b/(1+(this.max_scan_line&31))|0,a&&c&&this.set_size_text(a,c)}};X.prototype.update_layers=function(){this.graphical_mode||this.text_mode_redraw();if(this.svga_enabled)this.layers=[];else if(this.virtual_width&&this.screen_width)if(!this.palette_source||this.clocking_mode&32)this.layers=[],this.screen.clear_screen();else{var a=this.start_address_latched,b=this.horizontal_panning;this.attribute_mode&64&&(b>>>=
566
+ 1);var c=this.preset_row_scan>>5&3,d=this.vga_addr_to_pixel(a+c);a=d/this.virtual_width|0;var e=d%this.virtual_width+b;d=this.scan_line_to_screen_row(1+this.line_compare);d=Math.min(d,this.screen_height);var f=this.screen_height-d;this.layers=[];e=-e;for(var h=0;e<this.screen_width;e+=this.virtual_width,h++)this.layers.push({image_data:this.image_data,screen_x:e,screen_y:0,buffer_x:0,buffer_y:a+h,buffer_width:this.virtual_width,buffer_height:d});a=0;this.attribute_mode&32||(a=this.vga_addr_to_pixel(c)+
567
+ b);e=-a;for(h=0;e<this.screen_width;e+=this.virtual_width,h++)this.layers.push({image_data:this.image_data,screen_x:e,screen_y:d,buffer_x:0,buffer_y:h,buffer_width:this.virtual_width,buffer_height:f})}};X.prototype.update_vertical_retrace=function(){this.port_3DA_value|=8;this.start_address_latched!==this.start_address&&(this.start_address_latched=this.start_address,this.update_layers())};X.prototype.update_cursor_scanline=function(){var a=this.max_scan_line&31;const b=Math.min(a,this.cursor_scanline_start&
568
+ 31);a=Math.min(a,this.cursor_scanline_end&31);this.screen.update_cursor_scanline(b,a,!(this.cursor_scanline_start&32)&&b<a)};X.prototype.port3C0_write=function(a){if(-1===this.attribute_controller_index)C("attribute controller index register: "+m(a),256),this.attribute_controller_index=a&31,C("attribute actual index: "+m(this.attribute_controller_index),256),this.palette_source!==(a&32)&&(this.palette_source=a&32,this.update_layers());else{if(16>this.attribute_controller_index)C("internal palette: "+
569
+ m(this.attribute_controller_index)+" -> "+m(a),256),this.dac_map[this.attribute_controller_index]=a,this.attribute_mode&64||this.complete_redraw();else switch(this.attribute_controller_index){case 16:C("3C0 / attribute mode control: "+m(a),256);if(this.attribute_mode!==a){var b=this.attribute_mode;this.attribute_mode=a;const c=0!==(a&1);this.svga_enabled||this.graphical_mode===c||(this.graphical_mode=c,this.screen.set_mode(this.graphical_mode));(b^a)&64&&this.complete_replot();this.update_vga_size();
570
+ this.complete_redraw();this.set_font_bitmap(!1)}break;case 18:C("3C0 / color plane enable: "+m(a),256);this.color_plane_enable!==a&&(this.color_plane_enable=a,this.complete_redraw());break;case 19:C("3C0 / horizontal panning: "+m(a),256);this.horizontal_panning!==a&&(this.horizontal_panning=a&15,this.update_layers());break;case 20:C("3C0 / color select: "+m(a),256);this.color_select!==a&&(this.color_select=a,this.complete_redraw());break;default:C("3C0 / attribute controller write "+m(this.attribute_controller_index)+
571
+ ": "+m(a),256)}this.attribute_controller_index=-1}};X.prototype.port3C0_read=function(){C("3C0 read",256);return(this.attribute_controller_index|this.palette_source)&255};X.prototype.port3C0_read16=function(){C("3C0 read16",256);return this.port3C0_read()|this.port3C1_read()<<8&65280};X.prototype.port3C1_read=function(){if(16>this.attribute_controller_index)return C("3C1 / internal palette read: "+m(this.attribute_controller_index)+" -> "+m(this.dac_map[this.attribute_controller_index]),256),this.dac_map[this.attribute_controller_index]&
572
+ 255;switch(this.attribute_controller_index){case 16:return C("3C1 / attribute mode read: "+m(this.attribute_mode),256),this.attribute_mode;case 18:return C("3C1 / color plane enable read: "+m(this.color_plane_enable),256),this.color_plane_enable;case 19:return C("3C1 / horizontal panning read: "+m(this.horizontal_panning),256),this.horizontal_panning;case 20:return C("3C1 / color select read: "+m(this.color_select),256),this.color_select;default:C("3C1 / attribute controller read "+m(this.attribute_controller_index),
573
+ 256)}return 255};X.prototype.port3C2_write=function(a){C("3C2 / miscellaneous output register = "+m(a),256);this.miscellaneous_output_register=a};X.prototype.port3C4_write=function(a){this.sequencer_index=a};X.prototype.port3C4_read=function(){return this.sequencer_index};X.prototype.port3C5_write=function(a){switch(this.sequencer_index){case 1:C("clocking mode: "+m(a),256);var b=this.clocking_mode;this.clocking_mode=a;(b^a)&32&&this.update_layers();this.set_font_bitmap(!1);break;case 2:C("plane write mask: "+
574
+ m(a),256);b=this.plane_write_bm;this.plane_write_bm=a;this.graphical_mode||!(b&4)||this.plane_write_bm&4||this.set_font_bitmap(!0);break;case 3:C("character map select: "+m(a),256);b=this.character_map_select;this.character_map_select=a;this.graphical_mode||b===a||this.set_font_page();break;case 4:C("sequencer memory mode: "+m(a),256);this.sequencer_memory_mode=a;break;default:C("3C5 / sequencer write "+m(this.sequencer_index)+": "+m(a),256)}};X.prototype.port3C5_read=function(){C("3C5 / sequencer read "+
575
+ m(this.sequencer_index),256);switch(this.sequencer_index){case 1:return this.clocking_mode;case 2:return this.plane_write_bm;case 3:return this.character_map_select;case 4:return this.sequencer_memory_mode;case 6:return 18}return 0};X.prototype.port3C6_write=function(a){this.dac_mask!==a&&(this.dac_mask=a,this.complete_redraw())};X.prototype.port3C6_read=function(){return this.dac_mask};X.prototype.port3C7_write=function(a){C("3C7 write: "+m(a),256);this.dac_color_index_read=3*a;this.dac_state&=0};
576
+ X.prototype.port3C7_read=function(){return this.dac_state};X.prototype.port3C8_write=function(a){this.dac_color_index_write=3*a;this.dac_state|=3};X.prototype.port3C8_read=function(){return this.dac_color_index_write/3&255};X.prototype.port3C9_write=function(a){var b=this.dac_color_index_write/3|0,c=this.dac_color_index_write%3,d=this.vga256_palette[b];if(0===(this.dispi_enable_value&32)){a&=63;const e=a&1;a=a<<2|e<<1|e}0===c?d=d&-16711681|a<<16:1===c?d=d&-65281|a<<8:(d=d&-256|a,C("dac set color, index="+
577
+ m(b)+" value="+m(d),256));this.vga256_palette[b]!==d&&(this.vga256_palette[b]=d,this.complete_redraw());this.dac_color_index_write++};X.prototype.port3C9_read=function(){C("3C9 read",256);var a=this.vga256_palette[this.dac_color_index_read/3|0]>>8*(2-this.dac_color_index_read%3)&255;this.dac_color_index_read++;return this.dispi_enable_value&32?a:a>>2};X.prototype.port3CC_read=function(){C("3CC read",256);return this.miscellaneous_output_register};X.prototype.port3CE_write=function(a){this.graphics_index=
578
+ a};X.prototype.port3CE_read=function(){return this.graphics_index};X.prototype.port3CF_write=function(a){switch(this.graphics_index){case 0:this.planar_setreset=a;C("plane set/reset: "+m(a),256);break;case 1:this.planar_setreset_enable=a;C("plane set/reset enable: "+m(a),256);break;case 2:this.color_compare=a;C("color compare: "+m(a),256);break;case 3:this.planar_rotate_reg=a;C("plane rotate: "+m(a),256);break;case 4:this.plane_read=a;C("plane read: "+m(a),256);break;case 5:var b=this.planar_mode;
579
+ this.planar_mode=a;C("planar mode: "+m(a),256);(b^a)&96&&this.complete_replot();break;case 6:C("miscellaneous graphics register: "+m(a),256);this.miscellaneous_graphics_register!==a&&(this.miscellaneous_graphics_register=a,this.update_vga_size());break;case 7:this.color_dont_care=a;C("color don't care: "+m(a),256);break;case 8:this.planar_bitmap=a;C("planar bitmap: "+m(a),256);break;default:C("3CF / graphics write "+m(this.graphics_index)+": "+m(a),256)}};X.prototype.port3CF_read=function(){C("3CF / graphics read "+
580
+ m(this.graphics_index),256);switch(this.graphics_index){case 0:return this.planar_setreset;case 1:return this.planar_setreset_enable;case 2:return this.color_compare;case 3:return this.planar_rotate_reg;case 4:return this.plane_read;case 5:return this.planar_mode;case 6:return this.miscellaneous_graphics_register;case 7:return this.color_dont_care;case 8:return this.planar_bitmap}return 0};X.prototype.port3D4_write=function(a){C("3D4 / crtc index: "+a,256);this.index_crtc=a};X.prototype.port3D4_write16=
581
+ function(a){this.port3D4_write(a&255);this.port3D5_write(a>>8&255)};X.prototype.port3D4_read=function(){C("3D4 read / crtc index: "+this.index_crtc,256);return this.index_crtc};X.prototype.port3D5_write=function(a){switch(this.index_crtc){case 1:C("3D5 / hdisp enable end write: "+m(a),256);this.horizontal_display_enable_end!==a&&(this.horizontal_display_enable_end=a,this.update_vga_size());break;case 2:this.horizontal_blank_start!==a&&(this.horizontal_blank_start=a,this.update_vga_size());break;case 7:C("3D5 / overflow register write: "+
582
+ m(a),256);var b=this.vertical_display_enable_end;this.vertical_display_enable_end&=255;this.vertical_display_enable_end=this.vertical_display_enable_end|a<<3&512|a<<7&256;b!==this.vertical_display_enable_end&&this.update_vga_size();this.line_compare=this.line_compare&767|a<<4&256;b=this.vertical_blank_start;this.vertical_blank_start=this.vertical_blank_start&767|a<<5&256;b!==this.vertical_blank_start&&this.update_vga_size();this.update_layers();break;case 8:C("3D5 / preset row scan write: "+m(a),
583
+ 256);this.preset_row_scan=a;this.update_layers();break;case 9:C("3D5 / max scan line write: "+m(a),256);var c=this.max_scan_line;this.max_scan_line=a;this.line_compare=this.line_compare&511|a<<3&512;b=this.vertical_blank_start;this.vertical_blank_start=this.vertical_blank_start&511|a<<4&512;((c^this.max_scan_line)&159||b!==this.vertical_blank_start)&&this.update_vga_size();this.update_cursor_scanline();this.update_layers();this.set_font_bitmap(!1);break;case 10:C("3D5 / cursor scanline start write: "+
584
+ m(a),256);this.cursor_scanline_start=a;this.update_cursor_scanline();break;case 11:C("3D5 / cursor scanline end write: "+m(a),256);this.cursor_scanline_end=a;this.update_cursor_scanline();break;case 12:(this.start_address>>8&255)!==a&&(this.start_address=this.start_address&255|a<<8,this.update_layers(),~this.crtc_mode&3&&this.complete_replot());C("3D5 / start addr hi write: "+m(a)+" -> "+m(this.start_address,4),256);break;case 13:(this.start_address&255)!==a&&(this.start_address=this.start_address&
585
+ 65280|a,this.update_layers(),~this.crtc_mode&3&&this.complete_replot());C("3D5 / start addr lo write: "+m(a)+" -> "+m(this.start_address,4),256);break;case 14:C("3D5 / cursor address hi write: "+m(a),256);this.cursor_address=this.cursor_address&255|a<<8;this.update_cursor();break;case 15:C("3D5 / cursor address lo write: "+m(a),256);this.cursor_address=this.cursor_address&65280|a;this.update_cursor();break;case 18:C("3D5 / vdisp enable end write: "+m(a),256);(this.vertical_display_enable_end&255)!==
586
+ a&&(this.vertical_display_enable_end=this.vertical_display_enable_end&768|a,this.update_vga_size());break;case 19:C("3D5 / offset register write: "+m(a),256);this.offset_register!==a&&(this.offset_register=a,this.update_vga_size(),~this.crtc_mode&3&&this.complete_replot());break;case 20:C("3D5 / underline location write: "+m(a),256);this.underline_location_register!==a&&(b=this.underline_location_register,this.underline_location_register=a,this.update_vga_size(),(b^a)&64&&this.complete_replot());
587
+ break;case 21:C("3D5 / vertical blank start write: "+m(a),256);(this.vertical_blank_start&255)!==a&&(this.vertical_blank_start=this.vertical_blank_start&768|a,this.update_vga_size());break;case 23:C("3D5 / crtc mode write: "+m(a),256);this.crtc_mode!==a&&(b=this.crtc_mode,this.crtc_mode=a,this.update_vga_size(),(b^a)&67&&this.complete_replot());break;case 24:C("3D5 / line compare write: "+m(a),256);this.line_compare=this.line_compare&768|a;this.update_layers();break;default:this.index_crtc<this.crtc.length&&
588
+ (this.crtc[this.index_crtc]=a),C("3D5 / CRTC write "+m(this.index_crtc)+": "+m(a),256)}};X.prototype.port3D5_write16=function(a){C("16-bit write to 3D5: "+m(a,4),256);this.port3D5_write(a&255)};X.prototype.port3D5_read=function(){C("3D5 read "+m(this.index_crtc),256);switch(this.index_crtc){case 1:return this.horizontal_display_enable_end;case 2:return this.horizontal_blank_start;case 7:return this.vertical_display_enable_end>>7&2|this.vertical_blank_start>>5&8|this.line_compare>>4&16|this.vertical_display_enable_end>>
589
+ 3&64;case 8:return this.preset_row_scan;case 9:return this.max_scan_line;case 10:return this.cursor_scanline_start;case 11:return this.cursor_scanline_end;case 12:return this.start_address&255;case 13:return this.start_address>>8;case 14:return this.cursor_address>>8;case 15:return this.cursor_address&255;case 18:return this.vertical_display_enable_end&255;case 19:return this.offset_register;case 20:return this.underline_location_register;case 21:return this.vertical_blank_start&255;case 23:return this.crtc_mode;
590
+ case 24:return this.line_compare&255}return this.index_crtc<this.crtc.length?this.crtc[this.index_crtc]:0};X.prototype.port3D5_read16=function(){C("Warning: 16-bit read from 3D5",256);return this.port3D5_read()};X.prototype.port3DA_read=function(){C("3DA read - status 1 and clear attr index",256);var a=this.port_3DA_value;this.graphical_mode?(this.port_3DA_value^=1,this.port_3DA_value&=1):(this.port_3DA_value&1&&(this.port_3DA_value^=8),this.port_3DA_value^=1);this.attribute_controller_index=-1;return a};
591
+ X.prototype.port1CE_write=function(a){this.dispi_index=a};X.prototype.port1CF_write=function(a){C("1CF / dispi write "+m(this.dispi_index)+": "+m(a),256);const b=this.svga_enabled;switch(this.dispi_index){case 0:45248<=a&&45253>=a?this.svga_version=a:C("Invalid version value: "+m(a),256);break;case 1:this.svga_width=a;2560<this.svga_width&&(C("svga_width reduced from "+this.svga_width+" to 2560",256),this.svga_width=2560);break;case 2:this.svga_height=a;1600<this.svga_height&&(C("svga_height reduced from "+
592
+ this.svga_height+" to 1600",256),this.svga_height=1600);break;case 3:this.svga_bpp=a;break;case 4:(this.svga_enabled=1===(a&1))&&0===(a&128)&&this.svga_memory.fill(0);this.dispi_enable_value=a;break;case 5:C("SVGA bank offset: "+m(a<<16),256);this.svga_bank_offset=a<<16;break;case 8:C("SVGA X offset: "+m(a),256);this.svga_offset_x!==a&&(this.svga_offset_x=a,this.svga_offset=this.svga_offset_y*this.svga_width+this.svga_offset_x,this.complete_redraw());break;case 9:C("SVGA Y offset: "+m(a*this.svga_width)+
593
+ " y="+m(a),256);this.svga_offset_y!==a&&(this.svga_offset_y=a,this.svga_offset=this.svga_offset_y*this.svga_width+this.svga_offset_x,this.complete_redraw());break;default:C("Unimplemented dispi write index: "+m(this.dispi_index),256)}!this.svga_enabled||this.svga_width&&this.svga_height||(C("SVGA: disabled because of invalid width/height: "+this.svga_width+"x"+this.svga_height,256),this.svga_enabled=!1);k(4!==this.svga_bpp,"unimplemented svga bpp: 4");k(4===this.svga_bpp||8===this.svga_bpp||15===
594
+ this.svga_bpp||16===this.svga_bpp||24===this.svga_bpp||32===this.svga_bpp,"unexpected svga bpp: "+this.svga_bpp);this.svga_enabled?C("SVGA: enabled, "+this.svga_width+"x"+this.svga_height+"x"+this.svga_bpp,256):C("SVGA: disabled");this.svga_enabled&&!b&&(this.svga_offset_y=this.svga_offset_x=this.svga_offset=0,this.graphical_mode=!0,this.screen.set_mode(this.graphical_mode),this.set_size_graphical(this.svga_width,this.svga_height,this.svga_width,this.svga_height,this.svga_bpp));this.svga_enabled||
595
+ (this.svga_bank_offset=0);this.update_layers()};X.prototype.port1CF_read=function(){C("1CF / dispi read "+m(this.dispi_index),256);return this.svga_register_read(this.dispi_index)};X.prototype.svga_register_read=function(a){switch(a){case 0:return this.svga_version;case 1:return this.dispi_enable_value&2?2560:this.svga_width;case 2:return this.dispi_enable_value&2?1600:this.svga_height;case 3:return this.dispi_enable_value&2?32:this.svga_bpp;case 4:return this.dispi_enable_value;case 5:return this.svga_bank_offset>>>
596
+ 16;case 6:return this.screen_width?this.screen_width:1;case 8:return this.svga_offset_x;case 9:return this.svga_offset_y;case 10:return this.vga_memory_size/65536|0;default:C("Unimplemented dispi read index: "+m(this.dispi_index),256)}return 255};X.prototype.vga_replot=function(){for(var a=this.diff_plot_min&-16,b=Math.min(this.diff_plot_max|15,524287),c=this.vga_addr_shift_count(),d=~this.crtc_mode&3,e=this.planar_mode&96,f=this.attribute_mode&64;a<=b;){var h=a>>>c;if(d){var l=a/this.virtual_width|
597
+ 0,p=a-this.virtual_width*l;switch(d){case 1:h=(l&1)<<13;l>>>=1;break;case 2:h=(l&1)<<14;l>>>=1;break;case 3:h=(l&3)<<13,l>>>=2}h|=(l*this.virtual_width+p>>>c)+this.start_address}l=this.plane0[h];p=this.plane1[h];var n=this.plane2[h],q=this.plane3[h];h=new Uint8Array(8);switch(e){case 0:l<<=0;p<<=1;n<<=2;q<<=3;for(var r=7;0<=r;r--)h[7-r]=l>>r&1|p>>r&2|n>>r&4|q>>r&8;break;case 32:h[0]=l>>6&3|n>>4&12;h[1]=l>>4&3|n>>2&12;h[2]=l>>2&3|n>>0&12;h[3]=l>>0&3|n<<2&12;h[4]=p>>6&3|q>>4&12;h[5]=p>>4&3|q>>2&12;
598
+ h[6]=p>>2&3|q>>0&12;h[7]=p>>0&3|q<<2&12;break;case 64:case 96:h[0]=l>>4&15,h[1]=l>>0&15,h[2]=p>>4&15,h[3]=p>>0&15,h[4]=n>>4&15,h[5]=n>>0&15,h[6]=q>>4&15,h[7]=q>>0&15}if(f)for(l=r=0;4>r;r++,a++,l+=2)this.pixel_buffer[a]=h[l]<<4|h[l+1];else for(r=0;8>r;r++,a++)this.pixel_buffer[a]=h[r]}};X.prototype.vga_redraw=function(){var a=this.diff_addr_min,b=Math.min(this.diff_addr_max,524287);const c=new Int32Array(this.cpu.wasm_memory.buffer,this.dest_buffet_offset,this.virtual_width*this.virtual_height);var d=
599
+ 255,e=0;this.attribute_mode&128&&(d&=207,e|=this.color_select<<4&48);if(this.attribute_mode&64)for(;a<=b;a++){var f=this.pixel_buffer[a]&d|e;f=this.vga256_palette[f];c[a]=f&65280|f<<16|f>>16|4278190080}else for(d&=63,e|=this.color_select<<4&192;a<=b;a++)f=this.dac_map[this.pixel_buffer[a]&this.color_plane_enable]&d|e,f=this.vga256_palette[f],c[a]=f&65280|f<<16|f>>16|4278190080};X.prototype.screen_fill_buffer=function(){if(this.graphical_mode){if(0===this.image_data.data.byteLength){var a=new Uint8ClampedArray(this.cpu.wasm_memory.buffer,
600
+ this.dest_buffet_offset,4*this.virtual_width*this.virtual_height);this.image_data=new ImageData(a,this.virtual_width,this.virtual_height);this.update_layers()}if(this.svga_enabled){a=0;let d=this.svga_height;if(8===this.svga_bpp){const e=new Int32Array(this.cpu.wasm_memory.buffer,this.dest_buffet_offset,this.screen_width*this.screen_height),f=new Uint8Array(this.cpu.wasm_memory.buffer,this.svga_memory.byteOffset,this.vga_memory_size);for(var b=0;b<e.length;b++){var c=this.vga256_palette[f[b]];e[b]=
601
+ c&65280|c<<16|c>>16|4278190080}}else this.cpu.svga_fill_pixel_buffer(this.svga_bpp,this.svga_offset),b=15===this.svga_bpp?2:this.svga_bpp/8,a=((this.cpu.svga_dirty_bitmap_min_offset[0]/b|0)-this.svga_offset)/this.svga_width|0,d=(((this.cpu.svga_dirty_bitmap_max_offset[0]/b|0)-this.svga_offset)/this.svga_width|0)+1;a<d&&(a=Math.max(a,0),d=Math.min(d,this.svga_height),this.screen.update_buffer([{image_data:this.image_data,screen_x:0,screen_y:a,buffer_x:0,buffer_y:a,buffer_width:this.svga_width,buffer_height:d-
602
+ a}]))}else this.vga_replot(),this.vga_redraw(),this.screen.update_buffer(this.layers);this.reset_diffs()}this.update_vertical_retrace()};X.prototype.set_font_bitmap=function(a){const b=this.max_scan_line&31;if(b&&!this.graphical_mode){const c=!!(this.clocking_mode&8);this.screen.set_font_bitmap(b+1,!c&&!(this.clocking_mode&1),c,!!(this.attribute_mode&4),this.plane2,a)}};X.prototype.set_font_page=function(){const a=[0,2,4,6,1,3,5,7],b=(this.character_map_select&12)>>2|(this.character_map_select&32)>>
603
+ 3,c=this.character_map_select&3|(this.character_map_select&16)>>2;this.font_page_ab_enabled=b!==c;this.screen.set_font_page(a[b],a[c]);this.complete_redraw()};const $c="SWAP_IN SWAP_OUT MAJFLT MINFLT MEMFREE MEMTOT AVAIL CACHES HTLB_PGALLOC HTLB_PGFAIL".split(" ");function ad(a,b){this.bus=b;this.zeroed=this.fp_cmd=this.actual=this.num_pages=0;this.virtio=new Ic(a,{name:"virtio-balloon",pci_id:88,device_id:4165,subsystem_device_id:5,common:{initial_port:55296,queues:[{size_supported:32,notify_offset:0},
604
+ {size_supported:32,notify_offset:0},{size_supported:2,notify_offset:1},{size_supported:64,notify_offset:2}],features:[1,3,32],on_driver_ok:()=>{C("Balloon setup",2048)}},notification:{initial_port:55552,single_handler:!1,handlers:[c=>{const d=this.virtio.queues[c];for(;d.has_request();){var e=d.pop_request();const f=new Uint8Array(e.length_readable);e.get_next_blob(f);this.virtio.queues[c].push_reply(e);e=f.byteLength/4;this.actual+=0===c?e:-e}this.virtio.queues[c].flush_replies()},c=>{var d=this.virtio.queues[c];
605
+ if(d.has_request()){d=d.pop_request();const e=new Uint8Array(d.length_readable);d.get_next_blob(e);let f={};for(let h=0;h<d.length_readable;h+=10){let [l,p]=K(["h","d"],e,{offset:h});f[$c[l]]=p}this.virtio.queues[c].push_reply(d);this.stats_cb&&this.stats_cb(f)}},c=>{const d=this.virtio.queues[c];for(;d.has_request();){const f=d.pop_request();if(0<f.length_readable){var e=new Uint8Array(f.length_readable);f.get_next_blob(e);[e]=K(["w"],e,{offset:0});0===e&&(this.free_cb&&this.free_cb(this.zeroed),
606
+ 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",read:()=>this.num_pages,write:()=>{}},{bytes:4,name:"actual",read:()=>this.actual,write:()=>
607
+ {}},{bytes:4,name:"free_page_hint_cmd_id",read:()=>this.fp_cmd,write:()=>{}}]}})}ad.prototype.Inflate=function(a){this.num_pages+=a;this.virtio.notify_config_changes()};ad.prototype.Deflate=function(a){this.num_pages-=a;this.virtio.notify_config_changes()};ad.prototype.Cleanup=function(a){this.fp_cmd=2;this.free_cb=a;this.zeroed=0;this.virtio.notify_config_changes()};ad.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.num_pages;a[2]=this.actual;return a};ad.prototype.set_state=
608
+ function(a){this.virtio.set_state(a[0]);this.num_pages=a[1];this.actual=a[2]};ad.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()};ad.prototype.Reset=function(){};function bd(a,b,c,d){C("Trying to load kernel of size "+b.byteLength);var e=new Uint8Array(b);const f=new Uint16Array(b);var h=new Uint32Array(b),l=e[497]||4,p=f[255];if(43605!==p)C("Bad checksum1: "+
609
+ 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],L=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="+m(y));C("cmdline max="+m(A));C("payload offset="+m(u)+" size="+m(B));C("pref_address="+
610
+ m(F)+":"+m(w));C("init_size="+m(L));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));h[134]=l;h[135]=e;k(655360>524288+d.length);a.set(d,524288);a.set(b,1048576);a=new Uint8Array(512);
611
+ (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,b,c){this.stop_idling=c;this.wm=b;this.wasm_patch();this.create_jit_imports();this.wasm_memory=b=
612
+ 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=g(Int32Array,b,568,1);this.gdtr_size=g(Int32Array,b,572,1);this.gdtr_offset=g(Int32Array,b,576,
613
+ 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);this.sysenter_eip=g(Int32Array,b,644,1);this.prefixes=g(Int32Array,b,648,1);this.flags=g(Int32Array,
614
+ b,120,1);this.flags_changed=g(Int32Array,b,100,1);this.last_op_size=g(Int32Array,b,96,1);this.last_op1=g(Int32Array,b,104,1);this.last_result=g(Int32Array,b,112,1);this.current_tsc=g(Uint32Array,b,960,2);this.devices={};this.instruction_pointer=g(Int32Array,b,556,1);this.previous_ip=g(Int32Array,b,560,1);this.apic_enabled=g(Uint8Array,b,548,1);this.acpi_enabled=g(Uint8Array,b,552,1);this.memory_map_read8=[];this.memory_map_write8=[];this.memory_map_read32=[];this.memory_map_write32=[];this.bios={main:null,
615
+ vga:null};this.instruction_counter=g(Uint32Array,b,664,1);this.reg32=g(Int32Array,b,64,8);this.fpu_st=g(Int32Array,b,1152,32);this.fpu_stack_empty=g(Uint8Array,b,816,1);this.fpu_stack_empty[0]=255;this.fpu_stack_ptr=g(Uint8Array,b,1032,1);this.fpu_stack_ptr[0]=0;this.fpu_control_word=g(Uint16Array,b,1036,1);this.fpu_control_word[0]=895;this.fpu_status_word=g(Uint16Array,b,1040,1);this.fpu_status_word[0]=0;this.fpu_ip=g(Int32Array,b,1048,1);this.fpu_ip[0]=0;this.fpu_ip_selector=g(Int32Array,b,1052,
616
+ 1);this.fpu_ip_selector[0]=0;this.fpu_opcode=g(Int32Array,b,1044,1);this.fpu_opcode[0]=0;this.fpu_dp=g(Int32Array,b,1056,1);this.fpu_dp[0]=0;this.fpu_dp_selector=g(Int32Array,b,1060,1);this.fpu_dp_selector[0]=0;this.reg_xmm32s=g(Int32Array,b,832,32);this.mxcsr=g(Int32Array,b,824,1);this.sreg=g(Uint16Array,b,668,8);this.dreg=g(Int32Array,b,684,8);this.reg_pdpte=g(Int32Array,b,968,8);this.svga_dirty_bitmap_min_offset=g(Uint32Array,b,716,1);this.svga_dirty_bitmap_max_offset=g(Uint32Array,b,720,1);this.fw_value=
617
+ [];this.fw_pointer=0;this.option_roms=[];this.io=void 0;this.bus=a;this.set_tsc(0,0);this.debug_init();this.seen_code={};this.seen_code_uncompiled={}}P.prototype.mmap_read8=function(a){a=this.memory_map_read8[a>>>17](a);k(0<=a&&255>=a);return a};P.prototype.mmap_write8=function(a,b){k(0<=b&&255>=b);this.memory_map_write8[a>>>17](a,b)};P.prototype.mmap_read16=function(a){var b=this.memory_map_read8[a>>>17];a=b(a)|b(a+1|0)<<8;k(0<=a&&65535>=a);return a};P.prototype.mmap_write16=function(a,b){var c=
618
+ this.memory_map_write8[a>>>17];k(0<=b&&65535>=b);c(a,b&255);c(a+1|0,b>>8)};P.prototype.mmap_read32=function(a){return this.memory_map_read32[a>>>17](a)};P.prototype.mmap_write32=function(a,b){this.memory_map_write32[a>>>17](a,b)};P.prototype.mmap_write64=function(a,b,c){var d=a>>>17;k(d===a+7>>>17);d=this.memory_map_write32[d];d(a,b);d(a+4,c)};P.prototype.mmap_write128=function(a,b,c,d,e){var f=a>>>17;k(f===a+12>>>17);f=this.memory_map_write32[f];f(a,b);f(a+4,c);f(a+8,d);f(a+12,e)};P.prototype.write_blob=
619
+ function(a,b){k(a&&0<=a.length);a.length&&(k(!this.in_mapped_range(b)),k(!this.in_mapped_range(b+a.length-1)),this.jit_dirty_cache(b,b+a.length),this.mem8.set(a,b))};P.prototype.read_blob=function(a,b){b&&(k(!this.in_mapped_range(a)),k(!this.in_mapped_range(a+b-1)));return this.mem8.subarray(a,a+b)};P.prototype.clear_opstats=function(){(new Uint8Array(this.wasm_memory.buffer,32768,131072)).fill(0);this.wm.exports.profiler_init()};P.prototype.create_jit_imports=function(){const a=Object.create(null);
620
+ a.m=this.wm.exports.memory;for(const b of Object.keys(this.wm.exports))b.startsWith("_")||b.startsWith("zstd")||b.endsWith("_js")||(a[b]=this.wm.exports[b]);this.jit_imports=a};P.prototype.wasm_patch=function(){const a=c=>this.wm.exports[c],b=c=>{const d=a(c);console.assert(d,"Missing import: "+c);return d};this.reset_cpu=b("reset_cpu");this.getiopl=b("getiopl");this.get_eflags=b("get_eflags");this.handle_irqs=b("handle_irqs");this.main_loop=b("main_loop");this.set_jit_config=b("set_jit_config");
621
+ this.read8=b("read8");this.read16=b("read16");this.read32s=b("read32s");this.write8=b("write8");this.write16=b("write16");this.write32=b("write32");this.in_mapped_range=b("in_mapped_range");this.fpu_load_tag_word=b("fpu_load_tag_word");this.fpu_load_status_word=b("fpu_load_status_word");this.fpu_get_sti_f64=b("fpu_get_sti_f64");this.translate_address_system_read=b("translate_address_system_read_js");this.get_seg_cs=b("get_seg_cs");this.get_real_eip=b("get_real_eip");this.clear_tlb=b("clear_tlb");
622
+ this.full_clear_tlb=b("full_clear_tlb");this.update_state_flags=b("update_state_flags");this.set_tsc=b("set_tsc");this.store_current_tsc=b("store_current_tsc");this.set_cpuid_level=b("set_cpuid_level");this.pic_set_irq=b("pic_set_irq");this.pic_clear_irq=b("pic_clear_irq");this.jit_force_generate_unsafe=a("jit_force_generate_unsafe");this.jit_clear_cache=b("jit_clear_cache_js");this.jit_dirty_cache=b("jit_dirty_cache");this.codegen_finalize_finished=b("codegen_finalize_finished");this.allocate_memory=
623
+ b("allocate_memory");this.zero_memory=b("zero_memory");this.is_memory_zeroed=b("is_memory_zeroed");this.svga_allocate_memory=b("svga_allocate_memory");this.svga_allocate_dest_buffer=b("svga_allocate_dest_buffer");this.svga_fill_pixel_buffer=b("svga_fill_pixel_buffer");this.svga_mark_dirty=b("svga_mark_dirty");this.get_pic_addr_master=b("get_pic_addr_master");this.get_pic_addr_slave=b("get_pic_addr_slave");this.zstd_create_ctx=b("zstd_create_ctx");this.zstd_get_src_ptr=b("zstd_get_src_ptr");this.zstd_free_ctx=
624
+ b("zstd_free_ctx");this.zstd_read=b("zstd_read");this.zstd_read_free=b("zstd_read_free");this.port20_read=b("port20_read");this.port21_read=b("port21_read");this.portA0_read=b("portA0_read");this.portA1_read=b("portA1_read");this.port20_write=b("port20_write");this.port21_write=b("port21_write");this.portA0_write=b("portA0_write");this.portA1_write=b("portA1_write");this.port4D0_read=b("port4D0_read");this.port4D1_read=b("port4D1_read");this.port4D0_write=b("port4D0_write");this.port4D1_write=b("port4D1_write")};
625
+ P.prototype.jit_force_generate=function(a){this.jit_force_generate_unsafe?this.jit_force_generate_unsafe(a):k(!1,"Not supported in this wasm build: jit_force_generate_unsafe")};P.prototype.jit_clear_func=function(a){k(0<=a&&900>a);this.wm.wasm_table.set(a+1024,null)};P.prototype.jit_clear_all_funcs=function(){const a=this.wm.wasm_table;for(let b=0;900>b;b++)a.set(1024+b,null)};P.prototype.get_state=function(){var a=[];a[0]=this.memory_size[0];a[1]=new Uint8Array([...this.segment_is_null,...this.segment_access_bytes]);
626
+ a[2]=this.segment_offsets;a[3]=this.segment_limits;a[4]=this.protected_mode[0];a[5]=this.idtr_offset[0];a[6]=this.idtr_size[0];a[7]=this.gdtr_offset[0];a[8]=this.gdtr_size[0];a[9]=this.page_fault[0];a[10]=this.cr;a[11]=this.cpl[0];a[13]=this.is_32[0];a[16]=this.stack_size_32[0];a[17]=this.in_hlt[0];a[18]=this.last_virt_eip[0];a[19]=this.eip_phys[0];a[22]=this.sysenter_cs[0];a[23]=this.sysenter_eip[0];a[24]=this.sysenter_esp[0];a[25]=this.prefixes[0];a[26]=this.flags[0];a[27]=this.flags_changed[0];
627
+ a[28]=this.last_op1[0];a[30]=this.last_op_size[0];a[37]=this.instruction_pointer[0];a[38]=this.previous_ip[0];a[39]=this.reg32;a[40]=this.sreg;a[41]=this.dreg;a[42]=this.reg_pdpte;this.store_current_tsc();a[43]=this.current_tsc;a[45]=this.devices.virtio_9p;a[46]=this.devices.apic;a[47]=this.devices.rtc;a[48]=this.devices.pci;a[49]=this.devices.dma;a[50]=this.devices.acpi;a[52]=this.devices.vga;a[53]=this.devices.ps2;a[54]=this.devices.uart0;a[55]=this.devices.fdc;this.devices.ide.secondary?a[85]=
628
+ this.devices.ide:this.devices.ide.primary?.master.is_atapi?a[56]=this.devices.ide.primary:a[57]=this.devices.ide.primary;a[58]=this.devices.pit;a[59]=this.devices.net;a[60]=this.get_state_pic();a[61]=this.devices.sb16;a[62]=this.fw_value;a[63]=this.devices.ioapic;a[64]=this.tss_size_32[0];a[66]=this.reg_xmm32s;a[67]=this.fpu_st;a[68]=this.fpu_stack_empty[0];a[69]=this.fpu_stack_ptr[0];a[70]=this.fpu_control_word[0];a[71]=this.fpu_ip[0];a[72]=this.fpu_ip_selector[0];a[73]=this.fpu_dp[0];a[74]=this.fpu_dp_selector[0];
629
+ a[75]=this.fpu_opcode[0];const {packed_memory:b,bitmap:c}=this.pack_memory();a[77]=b;a[78]=new Uint8Array(c.get_buffer());a[79]=this.devices.uart1;a[80]=this.devices.uart2;a[81]=this.devices.uart3;a[82]=this.devices.virtio_console;a[83]=this.devices.virtio_net;a[84]=this.devices.virtio_balloon;return a};P.prototype.get_state_pic=function(){const a=new Uint8Array(this.wasm_memory.buffer,this.get_pic_addr_master(),13),b=new Uint8Array(this.wasm_memory.buffer,this.get_pic_addr_slave(),13),c=[],d=[];
630
+ c[0]=a[0];c[1]=a[1];c[2]=a[2];c[3]=a[3];c[4]=a[4];c[5]=d;c[6]=a[6];c[7]=a[7];c[8]=a[8];c[9]=a[9];c[10]=a[10];c[11]=a[11];c[12]=a[12];d[0]=b[0];d[1]=b[1];d[2]=b[2];d[3]=b[3];d[4]=b[4];d[5]=null;d[6]=b[6];d[7]=b[7];d[8]=b[8];d[9]=b[9];d[10]=b[10];d[11]=b[11];d[12]=b[12];return c};P.prototype.set_state=function(a){this.memory_size[0]=a[0];this.mem8.length!==this.memory_size[0]&&console.warn("Note: Memory size mismatch. we="+this.mem8.length+" state="+this.memory_size[0]);8===a[1].length?(this.segment_is_null.set(a[1]),
625
631
  this.segment_access_bytes.fill(242),this.segment_access_bytes[1]=250):16===a[1].length?(this.segment_is_null.set(a[1].subarray(0,8)),this.segment_access_bytes.set(a[1].subarray(8,16))):k("Unexpected cpu segment state length:"+a[1].length);this.segment_offsets.set(a[2]);this.segment_limits.set(a[3]);this.protected_mode[0]=a[4];this.idtr_offset[0]=a[5];this.idtr_size[0]=a[6];this.gdtr_offset[0]=a[7];this.gdtr_size[0]=a[8];this.page_fault[0]=a[9];this.cr.set(a[10]);this.cpl[0]=a[11];this.is_32[0]=a[13];
626
632
  this.stack_size_32[0]=a[16];this.in_hlt[0]=a[17];this.last_virt_eip[0]=a[18];this.eip_phys[0]=a[19];this.sysenter_cs[0]=a[22];this.sysenter_eip[0]=a[23];this.sysenter_esp[0]=a[24];this.prefixes[0]=a[25];this.flags[0]=a[26];this.flags_changed[0]=a[27];this.last_op1[0]=a[28];this.last_op_size[0]=a[30];this.instruction_pointer[0]=a[37];this.previous_ip[0]=a[38];this.reg32.set(a[39]);this.sreg.set(a[40]);this.dreg.set(a[41]);a[42]&&this.reg_pdpte.set(a[42]);this.set_tsc(a[43][0],a[43][1]);this.devices.virtio_9p&&
627
- this.devices.virtio_9p.set_state(a[45]);this.devices.apic&&this.devices.apic.set_state(a[46]);this.devices.rtc&&this.devices.rtc.set_state(a[47]);this.devices.pci&&this.devices.pci.set_state(a[48]);this.devices.dma&&this.devices.dma.set_state(a[49]);this.devices.acpi&&this.devices.acpi.set_state(a[50]);this.devices.vga&&this.devices.vga.set_state(a[52]);this.devices.ps2&&this.devices.ps2.set_state(a[53]);this.devices.uart0&&this.devices.uart0.set_state(a[54]);this.devices.fdc&&this.devices.fdc.set_state(a[55]);
628
- this.devices.cdrom&&this.devices.cdrom.set_state(a[56]);this.devices.hda&&this.devices.hda.set_state(a[57]);this.devices.pit&&this.devices.pit.set_state(a[58]);this.devices.net&&this.devices.net.set_state(a[59]);this.set_state_pic(a[60]);this.devices.sb16&&this.devices.sb16.set_state(a[61]);this.devices.uart1&&this.devices.uart1.set_state(a[79]);this.devices.uart2&&this.devices.uart2.set_state(a[80]);this.devices.uart3&&this.devices.uart3.set_state(a[81]);this.devices.virtio_console&&this.devices.virtio_console.set_state(a[82]);
629
- this.devices.virtio_net&&this.devices.virtio_net.set_state(a[83]);this.devices.virtio_balloon&&this.devices.virtio_balloon.set_state(a[84]);this.fw_value=a[62];this.devices.ioapic&&this.devices.ioapic.set_state(a[63]);this.tss_size_32[0]=a[64];this.reg_xmm32s.set(a[66]);this.fpu_st.set(a[67]);this.fpu_stack_empty[0]=a[68];this.fpu_stack_ptr[0]=a[69];this.fpu_control_word[0]=a[70];this.fpu_ip[0]=a[71];this.fpu_ip_selector[0]=a[72];this.fpu_dp[0]=a[73];this.fpu_dp_selector[0]=a[74];this.fpu_opcode[0]=
630
- a[75];const b=new ra(a[78].buffer);this.unpack_memory(b,a[77]);this.update_state_flags();this.full_clear_tlb();this.jit_clear_cache()};P.prototype.set_state_pic=function(a){const b=new Uint8Array(this.wasm_memory.buffer,this.get_pic_addr_master(),13),c=new Uint8Array(this.wasm_memory.buffer,this.get_pic_addr_slave(),13);b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];const d=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];b[9]=a[9];b[10]=a[10];b[11]=a[11];b[12]=a[12];c[0]=d[0];c[1]=d[1];c[2]=d[2];c[3]=d[3];
631
- c[4]=d[4];c[6]=d[6];c[7]=d[7];c[8]=d[8];c[9]=d[9];c[10]=d[10];c[11]=d[11];c[12]=d[12]};P.prototype.pack_memory=function(){k(0===(this.mem8.length&4095));var a=this.mem8.length>>12,b=[];for(var c=0;c<a;c++)this.is_memory_zeroed(c<<12,4096)||b.push(c);a=new ra(a);c=new Uint8Array(b.length<<12);for(const [d,e]of b.entries())a.set(e,1),b=e<<12,b=this.mem8.subarray(b,b+4096),c.set(b,d<<12);return{bitmap:a,packed_memory:c}};P.prototype.unpack_memory=function(a,b){this.zero_memory(0,this.memory_size[0]);
632
- const c=this.memory_size[0]>>12;let d=0;for(let f=0;f<c;f++)if(a.get(f)){var e=d<<12;e=b.subarray(e,e+4096);this.mem8.set(e,f<<12);d++}};P.prototype.reboot_internal=function(){this.reset_cpu();this.fw_value=[];this.devices.virtio_9p&&this.devices.virtio_9p.reset();this.devices.virtio_console&&this.devices.virtio_console.reset();this.devices.virtio_net&&this.devices.virtio_net.reset();this.devices.ps2&&this.devices.ps2.reset();this.load_bios()};P.prototype.reset_memory=function(){this.mem8.fill(0)};
633
- 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?
634
- 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=
635
- 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===
636
- 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=
637
- 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,
638
- 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=
639
- 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&&
640
- (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=
641
- 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))};
642
- 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,
643
- 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);
644
- 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);
645
- 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");
646
- 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),
647
- 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<
648
- 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 "+
649
- (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]=
650
- 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)}
651
- 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]-
652
- 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);
653
- 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=
654
- 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=
655
- 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)};
656
- 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))+
657
- " 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],
658
- 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 ":
659
- " ",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=
660
- 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))}};
661
- 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: "+
662
- 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)|
663
- 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=
664
- 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");
665
- 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");
666
- 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=
667
- 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);
668
- 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=
669
- [];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));
670
- e.push(this.create_notification_capability(b.notification));e.push(this.create_isr_capability(b.isr_status));b.device_specific&&e.push(this.create_device_specific_capability(b.device_specific));this.init_capabilities(e);a.devices.pci.register_device(this);this.reset()}Ic.prototype.create_common_capability=function(a){return{type:1,bar:0,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:[{bytes:4,name:"device_feature_select",read:()=>this.device_feature_select,write:b=>{this.device_feature_select=
671
- b}},{bytes:4,name:"device_feature",read:()=>this.device_feature[this.device_feature_select]||0,write:()=>{}},{bytes:4,name:"driver_feature_select",read:()=>this.driver_feature_select,write:b=>{this.driver_feature_select=b}},{bytes:4,name:"driver_feature",read:()=>this.driver_feature[this.driver_feature_select]||0,write:b=>{const c=this.device_feature[this.driver_feature_select];this.driver_feature_select<this.driver_feature.length&&(this.driver_feature[this.driver_feature_select]=b&c);this.features_ok=
672
- this.features_ok&&!(b&~c)}},{bytes:2,name:"msix_config",read:()=>{C("No msi-x capability supported.",2097152);return 65535},write:()=>{C("No msi-x capability supported.",2097152)}},{bytes:2,name:"num_queues",read:()=>this.queues.length,write:()=>{}},{bytes:1,name:"device_status",read:()=>this.device_status,write:b=>{0===b?(C("Reset device<"+this.name+">",2097152),this.reset()):b&128?C("Warning: Device<"+this.name+"> status failed",2097152):C("Device<"+this.name+"> status: "+(b&1?"ACKNOWLEDGE ":"")+
673
- (b&2?"DRIVER ":"")+(b&4?"DRIVER_OK":"")+(b&8?"FEATURES_OK ":"")+(b&64?"DEVICE_NEEDS_RESET":""),2097152);b&~this.device_status&4&&this.device_status&64&&this.notify_config_changes();this.features_ok||(b&8&&C("Removing FEATURES_OK",2097152),b&=-9);this.device_status=b;if(b&~this.device_status&4)a.on_driver_ok()}},{bytes:1,name:"config_generation",read:()=>this.config_generation,write:()=>{}},{bytes:2,name:"queue_select",read:()=>this.queue_select,write:b=>{this.queue_select=b;this.queue_selected=this.queue_select<
674
- this.queues.length?this.queues[this.queue_select]:null}},{bytes:2,name:"queue_size",read:()=>this.queue_selected?this.queue_selected.size:0,write:b=>{this.queue_selected&&(b&b-1&&(C("Warning: dev<"+this.name+"> Given queue size was not a power of 2. Rounding up to next power of 2.",2097152),b=1<<ea(b-1)+1),b>this.queue_selected.size_supported&&(C("Warning: dev<"+this.name+"> Trying to set queue size greater than supported. Clamping to supported size.",2097152),b=this.queue_selected.size_supported),
675
- this.queue_selected.set_size(b))}},{bytes:2,name:"queue_msix_vector",read:()=>{C("No msi-x capability supported.",2097152);return 65535},write:()=>{C("No msi-x capability supported.",2097152)}},{bytes:2,name:"queue_enable",read:()=>this.queue_selected?this.queue_selected.enabled|0:0,write:b=>{this.queue_selected&&(1===b?this.queue_selected.is_configured()?this.queue_selected.enable():C("Driver bug: tried enabling unconfigured queue",2097152):0===b&&C("Driver bug: tried writing 0 to queue_enable",
676
- 2097152))}},{bytes:2,name:"queue_notify_off",read:()=>this.queue_selected?this.queue_selected.notify_offset:0,write:()=>{}},{bytes:4,name:"queue_desc (low dword)",read:()=>this.queue_selected?this.queue_selected.desc_addr:0,write:b=>{this.queue_selected&&(this.queue_selected.desc_addr=b)}},{bytes:4,name:"queue_desc (high dword)",read:()=>0,write:b=>{0!==b&&C("Warning: High dword of 64 bit queue_desc ignored:"+b,2097152)}},{bytes:4,name:"queue_avail (low dword)",read:()=>this.queue_selected?this.queue_selected.avail_addr:
677
- 0,write:b=>{this.queue_selected&&(this.queue_selected.avail_addr=b)}},{bytes:4,name:"queue_avail (high dword)",read:()=>0,write:b=>{0!==b&&C("Warning: High dword of 64 bit queue_avail ignored:"+b,2097152)}},{bytes:4,name:"queue_used (low dword)",read:()=>this.queue_selected?this.queue_selected.used_addr:0,write:b=>{this.queue_selected&&(this.queue_selected.used_addr=b)}},{bytes:4,name:"queue_used (high dword)",read:()=>0,write:b=>{0!==b&&C("Warning: High dword of 64 bit queue_used ignored:"+b,2097152)}}]}};
678
- Ic.prototype.create_notification_capability=function(a){const b=[];let c;a.single_handler?(k(1===a.handlers.length,"VirtIO device<"+this.name+"> too many notify handlers specified: expected single handler"),c=0):c=2;for(const [d,e]of a.handlers.entries())b.push({bytes:2,name:"notify"+d,read:()=>65535,write:e||(()=>{})});return{type:2,bar:1,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array([c&255,c>>8&255,c>>16&255,c>>24]),struct:b}};Ic.prototype.create_isr_capability=function(a){return{type:3,
679
- bar:2,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:[{bytes:1,name:"isr_status",read:()=>{const b=this.isr_status;this.lower_irq();return b},write:()=>{}}]}};Ic.prototype.create_device_specific_capability=function(a){k(~a.offset&3,"VirtIO device<"+this.name+"> device specific cap offset must be 4-byte aligned");return{type:4,bar:3,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:a.struct}};Ic.prototype.init_capabilities=function(a){let b=this.pci_space[52]=
680
- 64;var c=b;for(const e of a){a=16+e.extra.length;c=b;b=c+a;k(256>=b,"VirtIO device<"+this.name+"> can't fit all capabilities into 256byte configspace");k(0<=e.bar&&6>e.bar,"VirtIO device<"+this.name+"> capability invalid bar number");var d=e.struct.reduce((f,h)=>f+h.bytes,0);d+=e.offset;d=16>d?16:1<<ea(d-1)+1;k(0===(e.port&d-1),"VirtIO device<"+this.name+"> capability port should be aligned to pci bar size");this.pci_bars[e.bar]={size:d};this.pci_space[c]=9;this.pci_space[c+1]=b;this.pci_space[c+
681
- 2]=a;this.pci_space[c+3]=e.type;this.pci_space[c+4]=e.bar;this.pci_space[c+5]=0;this.pci_space[c+6]=0;this.pci_space[c+7]=0;this.pci_space[c+8]=e.offset&255;this.pci_space[c+9]=e.offset>>>8&255;this.pci_space[c+10]=e.offset>>>16&255;this.pci_space[c+11]=e.offset>>>24;this.pci_space[c+12]=d&255;this.pci_space[c+13]=d>>>8&255;this.pci_space[c+14]=d>>>16&255;this.pci_space[c+15]=d>>>24;for(const [f,h]of e.extra.entries())this.pci_space[c+16+f]=h;c=16+4*e.bar;this.pci_space[c]=e.port&254|!e.use_mmio;
682
- this.pci_space[c+1]=e.port>>>8&255;this.pci_space[c+2]=e.port>>>16&255;this.pci_space[c+3]=e.port>>>24&255;c=e.port+e.offset;for(const f of e.struct){let h=f.read;a=f.write;h=()=>{const l=f.read();C("Device<"+this.name+"> cap["+e.type+"] read["+f.name+"] => "+m(l,8*f.bytes),2097152);return l};a=l=>{C("Device<"+this.name+"> cap["+e.type+"] write["+f.name+"] <= "+m(l,8*f.bytes),2097152);f.write(l)};if(e.use_mmio)k(!1,"VirtIO device <"+this.name+"> mmio capability not implemented.");else{d=function(p){C("Warning: 8-bit read from 16-bit virtio port",
683
- 2097152);return h(p&-2)>>((p&1)<<3)&255};const l=function(p){C("Warning: 8-bit read from 32-bit virtio port",2097152);return h(p&-4)>>((p&3)<<3)&255};switch(f.bytes){case 4:this.cpu.io.register_read(c,this,l,void 0,h);this.cpu.io.register_read(c+1,this,l);this.cpu.io.register_read(c+2,this,l);this.cpu.io.register_read(c+3,this,l);this.cpu.io.register_write(c,this,void 0,void 0,a);break;case 2:this.cpu.io.register_read(c,this,d,h);this.cpu.io.register_read(c+1,this,d);this.cpu.io.register_write(c,
684
- this,void 0,a);break;case 1:this.cpu.io.register_read(c,this,h);this.cpu.io.register_write(c,this,a);break;default:k(!1,"VirtIO device <"+this.name+"> invalid capability field width of "+f.bytes+" bytes")}}c+=f.bytes}}k(256>=b+20,"VirtIO device<"+this.name+"> can't fit all capabilities into 256byte configspace");this.pci_space[b]=9;this.pci_space[b+1]=0;this.pci_space[b+2]=20;this.pci_space[b+3]=5;this.pci_space[b+4]=0;this.pci_space[b+5]=0;this.pci_space[b+6]=0;this.pci_space[b+7]=0;this.pci_space[b+
685
- 8]=0;this.pci_space[b+9]=0;this.pci_space[b+10]=0;this.pci_space[b+11]=0;this.pci_space[b+12]=0;this.pci_space[b+13]=0;this.pci_space[b+14]=0;this.pci_space[b+15]=0;this.pci_space[b+16]=0;this.pci_space[b+17]=0;this.pci_space[b+18]=0;this.pci_space[b+19]=0};Ic.prototype.get_state=function(){let a=[];a[0]=this.device_feature_select;a[1]=this.driver_feature_select;a[2]=this.device_feature;a[3]=this.driver_feature;a[4]=this.features_ok;a[5]=this.device_status;a[6]=this.config_has_changed;a[7]=this.config_generation;
686
- a[8]=this.isr_status;a[9]=this.queue_select;return a=a.concat(this.queues)};Ic.prototype.set_state=function(a){this.device_feature_select=a[0];this.driver_feature_select=a[1];this.device_feature=a[2];this.driver_feature=a[3];this.features_ok=a[4];this.device_status=a[5];this.config_has_changed=a[6];this.config_generation=a[7];this.isr_status=a[8];this.queue_select=a[9];let b=0;for(const c of a.slice(10))this.queues[b].set_state(c),b++;this.queue_selected=this.queues[this.queue_select]||null};Ic.prototype.reset=
687
- function(){this.driver_feature_select=this.device_feature_select=0;this.driver_feature.set(this.device_feature);this.features_ok=!0;this.queue_select=this.device_status=0;this.queue_selected=this.queues[0];for(const a of this.queues)a.reset();this.config_has_changed=!1;this.config_generation=0;this.lower_irq()};Ic.prototype.notify_config_changes=function(){this.config_has_changed=!0;this.device_status&4?this.raise_irq(2):k(!1,"VirtIO device<"+this.name+"> attempted to notify driver before DRIVER_OK")};
688
- Ic.prototype.update_config_generation=function(){this.config_has_changed&&(this.config_generation++,this.config_generation&=255,this.config_has_changed=!1)};Ic.prototype.is_feature_negotiated=function(a){return 0<(this.driver_feature[a>>>5]&1<<(a&31))};Ic.prototype.needs_reset=function(){C("Device<"+this.name+"> experienced error - requires reset",2097152);this.device_status|=64;this.device_status&4&&this.notify_config_changes()};Ic.prototype.raise_irq=function(a){C("Raise irq "+m(a),2097152);this.isr_status|=
689
- a;this.pci.raise_irq(this.pci_id)};Ic.prototype.lower_irq=function(){C("Lower irq ",2097152);this.isr_status=0;this.pci.lower_irq(this.pci_id)};function Y(a,b,c){this.cpu=a;this.virtio=b;this.size_supported=this.size=c.size_supported;this.mask=this.size-1;this.enabled=!1;this.notify_offset=c.notify_offset;this.num_staged_replies=this.used_addr=this.avail_last_idx=this.avail_addr=this.desc_addr=0;this.reset()}Y.prototype.get_state=function(){const a=[];a[0]=this.size;a[1]=this.size_supported;a[2]=
690
- this.enabled;a[3]=this.notify_offset;a[4]=this.desc_addr;a[5]=this.avail_addr;a[6]=this.avail_last_idx;a[7]=this.used_addr;a[8]=this.num_staged_replies;a[9]=1;return a};Y.prototype.set_state=function(a){this.size=a[0];this.size_supported=a[1];this.enabled=a[2];this.notify_offset=a[3];this.desc_addr=a[4];this.avail_addr=a[5];this.avail_last_idx=a[6];this.used_addr=a[7];this.num_staged_replies=a[8];this.mask=this.size-1;this.fix_wrapping=1!==a[9]};Y.prototype.reset=function(){this.enabled=!1;this.num_staged_replies=
691
- this.used_addr=this.avail_last_idx=this.avail_addr=this.desc_addr=0;this.set_size(this.size_supported)};Y.prototype.is_configured=function(){return this.desc_addr&&this.avail_addr&&this.used_addr};Y.prototype.enable=function(){k(this.is_configured(),"VirtQueue must be configured before enabled");this.enabled=!0};Y.prototype.set_size=function(a){k(0===(a&a-1),"VirtQueue size must be power of 2 or zero");k(a<=this.size_supported,"VirtQueue size must be within supported size");this.size=a;this.mask=
692
- a-1};Y.prototype.count_requests=function(){k(this.avail_addr,"VirtQueue addresses must be configured before use");this.fix_wrapping&&(this.fix_wrapping=!1,this.avail_last_idx=(this.avail_get_idx()&~this.mask)+(this.avail_last_idx&this.mask));return this.avail_get_idx()-this.avail_last_idx&65535};Y.prototype.has_request=function(){k(this.avail_addr,"VirtQueue addresses must be configured before use");return 0!==this.count_requests()};Y.prototype.pop_request=function(){k(this.avail_addr,"VirtQueue addresses must be configured before use");
693
- k(this.has_request(),"VirtQueue must not pop nonexistent request");var a=this.avail_get_entry(this.avail_last_idx);C("Pop request: avail_last_idx="+this.avail_last_idx+" desc_idx="+a,2097152);a=new ad(this,a);this.avail_last_idx=this.avail_last_idx+1&65535;return a};Y.prototype.push_reply=function(a){k(this.used_addr,"VirtQueue addresses must be configured before use");k(this.num_staged_replies<this.size,"VirtQueue replies must not exceed queue size");const b=this.used_get_idx()+this.num_staged_replies&
694
- this.mask;C("Push reply: used_idx="+b+" desc_idx="+a.head_idx,2097152);this.used_set_entry(b,a.head_idx,a.length_written);this.num_staged_replies++};Y.prototype.flush_replies=function(){k(this.used_addr,"VirtQueue addresses must be configured before use");if(0===this.num_staged_replies)C("flush_replies: Nothing to flush",2097152);else{C("Flushing "+this.num_staged_replies+" replies",2097152);var a=this.used_get_idx()+this.num_staged_replies&65535;this.used_set_idx(a);this.num_staged_replies=0;this.virtio.is_feature_negotiated(29)?
695
- (this.avail_get_used_event(),this.virtio.raise_irq(1)):~this.avail_get_flags()&1&&this.virtio.raise_irq(1)}};Y.prototype.notify_me_after=function(a){k(0<=a,"Must skip a non-negative number of requests");a=this.avail_get_idx()+a&65535;this.used_set_avail_event(a)};Y.prototype.get_descriptor=function(a,b){return{addr_low:this.cpu.read32s(a+16*b),addr_high:this.cpu.read32s(a+16*b+4),len:this.cpu.read32s(a+16*b+8),flags:this.cpu.read16(a+16*b+12),next:this.cpu.read16(a+16*b+14)}};Y.prototype.avail_get_flags=
696
- function(){return this.cpu.read16(this.avail_addr)};Y.prototype.avail_get_idx=function(){return this.cpu.read16(this.avail_addr+2)};Y.prototype.avail_get_entry=function(a){return this.cpu.read16(this.avail_addr+4+2*(a&this.mask))};Y.prototype.avail_get_used_event=function(){return this.cpu.read16(this.avail_addr+4+2*this.size)};Y.prototype.used_get_flags=function(){return this.cpu.read16(this.used_addr)};Y.prototype.used_set_flags=function(a){this.cpu.write16(this.used_addr,a)};Y.prototype.used_get_idx=
697
- function(){return this.cpu.read16(this.used_addr+2)};Y.prototype.used_set_idx=function(a){this.cpu.write16(this.used_addr+2,a)};Y.prototype.used_set_entry=function(a,b,c){this.cpu.write32(this.used_addr+4+8*a,b);this.cpu.write32(this.used_addr+8+8*a,c)};Y.prototype.used_set_avail_event=function(a){this.cpu.write16(this.used_addr+4+8*this.size,a)};function ad(a,b){this.cpu=a.cpu;this.virtio=a.virtio;this.head_idx=b;this.read_buffers=[];this.length_readable=this.read_buffer_offset=this.read_buffer_idx=
698
- 0;this.write_buffers=[];this.length_writable=this.length_written=this.write_buffer_offset=this.write_buffer_idx=0;let c=a.desc_addr,d=0,e=a.size,f=!1;const h=this.virtio.is_feature_negotiated(28);C("<<< Descriptor chain start",2097152);do{const l=a.get_descriptor(c,b);C("descriptor: idx="+b+" addr="+m(l.addr_high,8)+":"+m(l.addr_low,8)+" len="+m(l.len,8)+" flags="+m(l.flags,4)+" next="+m(l.next,4),2097152);if(h&&l.flags&4)l.flags&1&&C("Driver bug: has set VIRTQ_DESC_F_NEXT flag in an indirect table descriptor",
699
- 2097152),c=l.addr_low,d=b=0,e=l.len/16,C("start indirect",2097152);else{if(l.flags&2)f=!0,this.write_buffers.push(l),this.length_writable+=l.len;else{if(f){C("Driver bug: readonly buffer after writeonly buffer within chain",2097152);break}this.read_buffers.push(l);this.length_readable+=l.len}d++;if(d>e){C("Driver bug: descriptor chain cycle detected",2097152);break}if(l.flags&1)b=l.next;else break}}while(1);C("Descriptor chain end >>>",2097152)}ad.prototype.get_next_blob=function(a){let b=0,c=a.length;
700
- for(;c;){if(this.read_buffer_idx===this.read_buffers.length){C("Device<"+this.virtio.name+"> Read more than device-readable buffers has",2097152);break}var d=this.read_buffers[this.read_buffer_idx];const e=d.addr_low+this.read_buffer_offset;d=d.len-this.read_buffer_offset;d>c?(d=c,this.read_buffer_offset+=c):(this.read_buffer_idx++,this.read_buffer_offset=0);a.set(this.cpu.read_blob(e,d),b);b+=d;c-=d}return b};ad.prototype.set_next_blob=function(a){let b=0,c=a.length;for(;c;){if(this.write_buffer_idx===
701
- this.write_buffers.length){C("Device<"+this.virtio.name+"> Write more than device-writable capacity",2097152);break}var d=this.write_buffers[this.write_buffer_idx];const e=d.addr_low+this.write_buffer_offset;d=d.len-this.write_buffer_offset;d>c?(d=c,this.write_buffer_offset+=c):(this.write_buffer_idx++,this.write_buffer_offset=0);this.cpu.write_blob(a.subarray(b,b+d),e);b+=d;c-=d}this.length_written+=b;return b};const bd=["shared","exclusive","unlock"];function $c(a,b,c){this.fs=a;this.bus=c;this.configspace_tagname=
702
- [104,111,115,116,57,112];this.configspace_taglen=this.configspace_tagname.length;this.VERSION="9P2000.L";this.msize=this.BLOCKSIZE=8192;this.replybuffer=new Uint8Array(2*this.msize);this.replybuffersize=0;this.fids=[];this.virtio=new Ic(b,{name:"virtio-9p",pci_id:48,device_id:4169,subsystem_device_id:9,common:{initial_port:43008,queues:[{size_supported:32,notify_offset:0}],features:[0,32,29,28],on_driver_ok:()=>{}},notification:{initial_port:43264,single_handler:!1,handlers:[d=>{if(0!==d)k(!1,"Virtio9P Notified for non-existent queue: "+
703
- d+" (expected queue_id of 0)");else{for(;this.virtqueue.has_request();)d=this.virtqueue.pop_request(),this.ReceiveRequest(d);this.virtqueue.notify_me_after(0)}}]},isr_status:{initial_port:42752},device_specific:{initial_port:42496,struct:[{bytes:2,name:"mount tag length",read:()=>this.configspace_taglen,write:()=>{}}].concat(Array.from(Array(254).keys()).map(d=>({bytes:1,name:"mount tag name "+d,read:()=>this.configspace_tagname[d]||0,write:()=>{}})))}});this.virtqueue=this.virtio.queues[0]}$c.prototype.get_state=
704
- function(){var a=[];a[0]=this.configspace_tagname;a[1]=this.configspace_taglen;a[2]=this.virtio;a[3]=this.VERSION;a[4]=this.BLOCKSIZE;a[5]=this.msize;a[6]=this.replybuffer;a[7]=this.replybuffersize;a[8]=this.fids.map(function(b){return[b.inodeid,b.type,b.uid,b.dbg_name]});a[9]=this.fs;return a};$c.prototype.set_state=function(a){this.configspace_tagname=a[0];this.configspace_taglen=a[1];this.virtio.set_state(a[2]);this.virtqueue=this.virtio.queues[0];this.VERSION=a[3];this.BLOCKSIZE=a[4];this.msize=
705
- a[5];this.replybuffer=a[6];this.replybuffersize=a[7];this.fids=a[8].map(function(b){return{inodeid:b[0],type:b[1],uid:b[2],dbg_name:b[3]}});this.fs.set_state(a[9])};$c.prototype.Createfid=function(a,b,c,d){return{inodeid:a,type:b,uid:c,dbg_name:d}};$c.prototype.update_dbg_name=function(a,b){for(const c of this.fids)c.inodeid===a&&(c.dbg_name=b)};$c.prototype.reset=function(){this.fids=[];this.virtio.reset()};$c.prototype.BuildReply=function(a,b,c){k(0<=c,"9P: Negative payload size");K(["w","b","h"],
706
- [c+7,a+1,b],this.replybuffer,0);c+7>=this.replybuffer.length&&C("Error in 9p: payloadsize exceeds maximum length",4194304);this.replybuffersize=c+7};$c.prototype.SendError=function(a,b,c){b=K(["w"],[c],this.replybuffer,7);this.BuildReply(6,a,b)};$c.prototype.SendReply=function(a){k(0<=this.replybuffersize,"9P: Negative replybuffersize");a.set_next_blob(this.replybuffer.subarray(0,this.replybuffersize));this.virtqueue.push_reply(a);this.virtqueue.flush_replies()};$c.prototype.ReceiveRequest=async function(a){var b=
707
- new Uint8Array(a.length_readable);a.get_next_blob(b);var c={offset:0},d=M(["w","b","h"],b,c),e=d[0],f=d[1],h=d[2];switch(f){case 8:e=this.fs.GetTotalSize();b=this.fs.GetSpace();d=[16914839];d[1]=this.BLOCKSIZE;d[2]=Math.floor(b/d[1]);d[3]=d[2]-Math.floor(e/d[1]);d[4]=d[2]-Math.floor(e/d[1]);d[5]=this.fs.CountUsedInodes();d[6]=this.fs.CountFreeInodes();d[7]=0;d[8]=256;e=K("wwddddddw".split(""),d,this.replybuffer,7);this.BuildReply(f,h,e);this.SendReply(a);break;case 112:case 12:d=M(["w","w"],b,c);
708
- var l=d[0];c=d[1];C("[open] fid="+l+", mode="+c,4194304);b=this.fids[l].inodeid;var p=this.fs.GetInode(b);C("file open "+this.fids[l].dbg_name,4194304);d=this.fs.OpenInode(b,c);this.fs.AddEvent(this.fids[l].inodeid,function(){C("file opened "+this.fids[l].dbg_name+" tag:"+h,4194304);var t=[];t[0]=p.qid;t[1]=this.msize-24;K(["Q","w"],t,this.replybuffer,7);this.BuildReply(f,h,17);this.SendReply(a)}.bind(this));break;case 70:d=M(["w","w","s"],b,c);b=d[0];l=d[1];e=d[2];C("[link] dfid="+b+", name="+e,
709
- 4194304);d=this.fs.Link(this.fids[b].inodeid,this.fids[l].inodeid,e);if(0>d){e="";-1===d?e="Operation not permitted":(e="Unknown error: "+-d,k(!1,"[link]: Unexpected error code: "+-d));this.SendError(h,e,-d);this.SendReply(a);break}this.BuildReply(f,h,0);this.SendReply(a);break;case 16:d=M(["w","s","s","w"],b,c);l=d[0];e=d[1];b=d[2];d=d[3];C("[symlink] fid="+l+", name="+e+", symgt="+b+", gid="+d,4194304);b=this.fs.CreateSymlink(e,this.fids[l].inodeid,b);p=this.fs.GetInode(b);p.uid=this.fids[l].uid;
710
- p.gid=d;K(["Q"],[p.qid],this.replybuffer,7);this.BuildReply(f,h,13);this.SendReply(a);break;case 18:d=M("wswwww".split(""),b,c);l=d[0];e=d[1];c=d[2];b=d[3];var n=d[4];d=d[5];C("[mknod] fid="+l+", name="+e+", major="+b+", minor="+n,4194304);b=this.fs.CreateNode(e,this.fids[l].inodeid,b,n);p=this.fs.GetInode(b);p.mode=c;p.uid=this.fids[l].uid;p.gid=d;K(["Q"],[p.qid],this.replybuffer,7);this.BuildReply(f,h,13);this.SendReply(a);break;case 22:d=M(["w"],b,c);l=d[0];p=this.fs.GetInode(this.fids[l].inodeid);
711
- C("[readlink] fid="+l+" name="+this.fids[l].dbg_name+" target="+p.symlink,4194304);e=K(["s"],[p.symlink],this.replybuffer,7);this.BuildReply(f,h,e);this.SendReply(a);break;case 72:d=M(["w","s","w","w"],b,c);l=d[0];e=d[1];c=d[2];d=d[3];C("[mkdir] fid="+l+", name="+e+", mode="+c+", gid="+d,4194304);b=this.fs.CreateDirectory(e,this.fids[l].inodeid);p=this.fs.GetInode(b);p.mode=c|16384;p.uid=this.fids[l].uid;p.gid=d;K(["Q"],[p.qid],this.replybuffer,7);this.BuildReply(f,h,13);this.SendReply(a);break;case 14:d=
712
- M(["w","s","w","w","w"],b,c);l=d[0];e=d[1];b=d[2];c=d[3];d=d[4];this.bus.send("9p-create",[e,this.fids[l].inodeid]);C("[create] fid="+l+", name="+e+", flags="+b+", mode="+c+", gid="+d,4194304);b=this.fs.CreateFile(e,this.fids[l].inodeid);this.fids[l].inodeid=b;this.fids[l].type=1;this.fids[l].dbg_name=e;p=this.fs.GetInode(b);p.uid=this.fids[l].uid;p.gid=d;p.mode=c|32768;K(["Q","w"],[p.qid,this.msize-24],this.replybuffer,7);this.BuildReply(f,h,17);this.SendReply(a);break;case 52:d=M("wbwddws".split(""),
713
- b,c);l=d[0];b=d[2];e=0===d[4]?Infinity:d[4];e=this.fs.DescribeLock(d[1],d[3],e,d[5],d[6]);C("[lock] fid="+l+", type="+bd[e.type]+", start="+e.start+", length="+e.length+", proc_id="+e.proc_id);d=this.fs.Lock(this.fids[l].inodeid,e,b);K(["b"],[d],this.replybuffer,7);this.BuildReply(f,h,1);this.SendReply(a);break;case 54:d=M("wbddws".split(""),b,c);l=d[0];e=0===d[3]?Infinity:d[3];e=this.fs.DescribeLock(d[1],d[2],e,d[4],d[5]);C("[getlock] fid="+l+", type="+bd[e.type]+", start="+e.start+", length="+e.length+
714
- ", proc_id="+e.proc_id);d=this.fs.GetLock(this.fids[l].inodeid,e);d||(d=e,d.type=2);e=K(["b","d","d","w","s"],[d.type,d.start,Infinity===d.length?0:d.length,d.proc_id,d.client_id],this.replybuffer,7);this.BuildReply(f,h,e);this.SendReply(a);break;case 24:d=M(["w","d"],b,c);l=d[0];p=this.fs.GetInode(this.fids[l].inodeid);C("[getattr]: fid="+l+" name="+this.fids[l].dbg_name+" request mask="+d[1],4194304);if(!p||4===p.status){C("getattr: unlinked",4194304);this.SendError(h,"No such file or directory",
715
- 2);this.SendReply(a);break}d[0]=d[1];d[1]=p.qid;d[2]=p.mode;d[3]=p.uid;d[4]=p.gid;d[5]=p.nlinks;d[6]=p.major<<8|p.minor;d[7]=p.size;d[8]=this.BLOCKSIZE;d[9]=Math.floor(p.size/512+1);d[10]=p.atime;d[11]=0;d[12]=p.mtime;d[13]=0;d[14]=p.ctime;d[15]=0;d[16]=0;d[17]=0;d[18]=0;d[19]=0;K("dQwwwddddddddddddddd".split(""),d,this.replybuffer,7);this.BuildReply(f,h,153);this.SendReply(a);break;case 26:d=M("wwwwwddddd".split(""),b,c);l=d[0];p=this.fs.GetInode(this.fids[l].inodeid);C("[setattr]: fid="+l+" request mask="+
716
- d[1]+" name="+this.fids[l].dbg_name,4194304);d[1]&1&&(p.mode=d[2]);d[1]&2&&(p.uid=d[3]);d[1]&4&&(p.gid=d[4]);d[1]&16&&(p.atime=Math.floor((new Date).getTime()/1E3));d[1]&32&&(p.mtime=Math.floor((new Date).getTime()/1E3));d[1]&64&&(p.ctime=Math.floor((new Date).getTime()/1E3));d[1]&128&&(p.atime=d[6]);d[1]&256&&(p.mtime=d[8]);d[1]&8&&await this.fs.ChangeSize(this.fids[l].inodeid,d[5]);this.BuildReply(f,h,0);this.SendReply(a);break;case 50:d=M(["w","d"],b,c);l=d[0];this.BuildReply(f,h,0);this.SendReply(a);
717
- break;case 40:case 116:d=M(["w","d","w"],b,c);l=d[0];e=d[1];n=d[2];p=this.fs.GetInode(this.fids[l].inodeid);40===f&&C("[treaddir]: fid="+l+" offset="+e+" count="+n,4194304);116===f&&C("[read]: fid="+l+" ("+this.fids[l].dbg_name+") offset="+e+" count="+n+" fidtype="+this.fids[l].type,4194304);if(!p||4===p.status){C("read/treaddir: unlinked",4194304);this.SendError(h,"No such file or directory",2);this.SendReply(a);break}if(2===this.fids[l].type)for(p.caps.length<e+n&&(n=p.caps.length-e),d=0;d<n;d++)this.replybuffer[11+
718
- d]=p.caps[e+d];else this.fs.OpenInode(this.fids[l].inodeid,void 0),d=this.fids[l].inodeid,n=Math.min(n,this.replybuffer.length-11),p.size<e+n?n=p.size-e:40===f&&(n=this.fs.RoundToDirentry(d,e+n)-e),e>p.size&&(n=0),this.bus.send("9p-read-start",[this.fids[l].dbg_name]),d=await this.fs.Read(d,e,n),this.bus.send("9p-read-end",[this.fids[l].dbg_name,n]),d&&this.replybuffer.set(d,11);K(["w"],[n],this.replybuffer,7);this.BuildReply(f,h,4+n);this.SendReply(a);break;case 118:d=M(["w","d","w"],b,c);l=d[0];
719
- e=d[1];n=d[2];d=this.fids[l].dbg_name;C("[write]: fid="+l+" ("+d+") offset="+e+" count="+n+" fidtype="+this.fids[l].type,4194304);if(2===this.fids[l].type){this.SendError(h,"Setxattr not supported",95);this.SendReply(a);break}else await this.fs.Write(this.fids[l].inodeid,e,n,b.subarray(c.offset));this.bus.send("9p-write-end",[d,n]);K(["w"],[n],this.replybuffer,7);this.BuildReply(f,h,4);this.SendReply(a);break;case 74:d=M(["w","s","w","s"],b,c);e=d[0];b=d[1];c=d[2];d=d[3];C("[renameat]: oldname="+
720
- b+" newname="+d,4194304);d=await this.fs.Rename(this.fids[e].inodeid,b,this.fids[c].inodeid,d);if(0>d){e="";-2===d?e="No such file or directory":-1===d?e="Operation not permitted":-39===d?e="Directory not empty":(e="Unknown error: "+-d,k(!1,"[renameat]: Unexpected error code: "+-d));this.SendError(h,e,-d);this.SendReply(a);break}this.BuildReply(f,h,0);this.SendReply(a);break;case 76:d=M(["w","s","w"],b,c);c=d[0];e=d[1];b=d[2];C("[unlink]: dirfd="+c+" name="+e+" flags="+b,4194304);l=this.fs.Search(this.fids[c].inodeid,
721
- e);if(-1===l){this.SendError(h,"No such file or directory",2);this.SendReply(a);break}d=this.fs.Unlink(this.fids[c].inodeid,e);if(0>d){e="";-39===d?e="Directory not empty":-1===d?e="Operation not permitted":(e="Unknown error: "+-d,k(!1,"[unlink]: Unexpected error code: "+-d));this.SendError(h,e,-d);this.SendReply(a);break}this.BuildReply(f,h,0);this.SendReply(a);break;case 100:d=M(["w","s"],b,c);C("[version]: msize="+d[0]+" version="+d[1],4194304);this.msize!==d[0]&&(this.msize=d[0],this.replybuffer=
722
- new Uint8Array(Math.min(16777216,2*this.msize)));e=K(["w","s"],[this.msize,this.VERSION],this.replybuffer,7);this.BuildReply(f,h,e);this.SendReply(a);break;case 104:d=M(["w","w","s","s","w"],b,c);l=d[0];e=d[4];C("[attach]: fid="+l+" afid="+m(d[1])+" uname="+d[2]+" aname="+d[3],4194304);this.fids[l]=this.Createfid(0,1,e,"");p=this.fs.GetInode(this.fids[l].inodeid);K(["Q"],[p.qid],this.replybuffer,7);this.BuildReply(f,h,13);this.SendReply(a);this.bus.send("9p-attach");break;case 108:d=M(["h"],b,c);
723
- C("[flush] "+h,4194304);this.BuildReply(f,h,0);this.SendReply(a);break;case 110:d=M(["w","w","h"],b,c);l=d[0];n=d[1];var q=d[2];C("[walk]: fid="+d[0]+" nwfid="+d[1]+" nwname="+q,4194304);if(0===q){this.fids[n]=this.Createfid(this.fids[l].inodeid,1,this.fids[l].uid,this.fids[l].dbg_name);K(["h"],[0],this.replybuffer,7);this.BuildReply(f,h,2);this.SendReply(a);break}e=[];for(d=0;d<q;d++)e.push("s");c=M(e,b,c);b=this.fids[l].inodeid;e=9;var r=0;C("walk in dir "+this.fids[l].dbg_name+" to: "+c.toString(),
724
- 4194304);for(d=0;d<q;d++){b=this.fs.Search(b,c[d]);if(-1===b){C("Could not find: "+c[d],4194304);break}e+=K(["Q"],[this.fs.GetInode(b).qid],this.replybuffer,e);r++;this.fids[n]=this.Createfid(b,1,this.fids[l].uid,c[d])}K(["h"],[r],this.replybuffer,7);this.BuildReply(f,h,e-7);this.SendReply(a);break;case 120:d=M(["w"],b,c);C("[clunk]: fid="+d[0],4194304);this.fids[d[0]]&&0<=this.fids[d[0]].inodeid&&(await this.fs.CloseInode(this.fids[d[0]].inodeid),this.fids[d[0]].inodeid=-1,this.fids[d[0]].type=-1);
725
- this.BuildReply(f,h,0);this.SendReply(a);break;case 32:d=M(["w","s","d","w"],b,c);l=d[0];e=d[1];c=d[2];b=d[3];C("[txattrcreate]: fid="+l+" name="+e+" attr_size="+c+" flags="+b,4194304);this.fids[l].type=2;this.BuildReply(f,h,0);this.SendReply(a);break;case 30:d=M(["w","w","s"],b,c);l=d[0];e=d[2];C("[xattrwalk]: fid="+d[0]+" newfid="+d[1]+" name="+d[2],4194304);this.SendError(h,"Setxattr not supported",95);this.SendReply(a);break;default:C("Error in Virtio9p: Unknown id "+f+" received",4194304),k(!1)}};
726
- export{};; export default module.exports.V86; export let {V86, CPU} = module.exports;
633
+ this.devices.virtio_9p.set_state(a[45]);this.devices.apic&&this.devices.apic.set_state(a[46]);this.devices.rtc&&this.devices.rtc.set_state(a[47]);this.devices.dma&&this.devices.dma.set_state(a[49]);this.devices.acpi&&this.devices.acpi.set_state(a[50]);this.devices.vga&&this.devices.vga.set_state(a[52]);this.devices.ps2&&this.devices.ps2.set_state(a[53]);this.devices.uart0&&this.devices.uart0.set_state(a[54]);this.devices.fdc&&this.devices.fdc.set_state(a[55]);if(a[56]||a[57]){var b=[[void 0,void 0],
634
+ [void 0,void 0]];b[0][0]=a[56]?{is_cdrom:!0,buffer:this.devices.cdrom.buffer}:{is_cdrom:!1,buffer:this.devices.ide.primary.master.buffer};this.devices.ide=new Vc(this,this.devices.ide.bus,b);this.devices.cdrom=a[56]?this.devices.ide.primary.master:void 0;this.devices.ide.primary.set_state(a[56]||a[57])}else a[85]&&this.devices.ide.set_state(a[85]);this.devices.pci&&this.devices.pci.set_state(a[48]);this.devices.pit&&this.devices.pit.set_state(a[58]);this.devices.net&&this.devices.net.set_state(a[59]);
635
+ this.set_state_pic(a[60]);this.devices.sb16&&this.devices.sb16.set_state(a[61]);this.devices.uart1&&this.devices.uart1.set_state(a[79]);this.devices.uart2&&this.devices.uart2.set_state(a[80]);this.devices.uart3&&this.devices.uart3.set_state(a[81]);this.devices.virtio_console&&this.devices.virtio_console.set_state(a[82]);this.devices.virtio_net&&this.devices.virtio_net.set_state(a[83]);this.devices.virtio_balloon&&this.devices.virtio_balloon.set_state(a[84]);this.fw_value=a[62];this.devices.ioapic&&
636
+ this.devices.ioapic.set_state(a[63]);this.tss_size_32[0]=a[64];this.reg_xmm32s.set(a[66]);this.fpu_st.set(a[67]);this.fpu_stack_empty[0]=a[68];this.fpu_stack_ptr[0]=a[69];this.fpu_control_word[0]=a[70];this.fpu_ip[0]=a[71];this.fpu_ip_selector[0]=a[72];this.fpu_dp[0]=a[73];this.fpu_dp_selector[0]=a[74];this.fpu_opcode[0]=a[75];b=new ra(a[78].buffer);this.unpack_memory(b,a[77]);this.update_state_flags();this.full_clear_tlb();this.jit_clear_cache()};P.prototype.set_state_pic=function(a){const b=new Uint8Array(this.wasm_memory.buffer,
637
+ this.get_pic_addr_master(),13),c=new Uint8Array(this.wasm_memory.buffer,this.get_pic_addr_slave(),13);b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];const d=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];b[9]=a[9];b[10]=a[10];b[11]=a[11];b[12]=a[12];c[0]=d[0];c[1]=d[1];c[2]=d[2];c[3]=d[3];c[4]=d[4];c[6]=d[6];c[7]=d[7];c[8]=d[8];c[9]=d[9];c[10]=d[10];c[11]=d[11];c[12]=d[12]};P.prototype.pack_memory=function(){k(0===(this.mem8.length&4095));var a=this.mem8.length>>12,b=[];for(var c=0;c<a;c++)this.is_memory_zeroed(c<<
638
+ 12,4096)||b.push(c);a=new ra(a);c=new Uint8Array(b.length<<12);for(const [d,e]of b.entries())a.set(e,1),b=e<<12,b=this.mem8.subarray(b,b+4096),c.set(b,d<<12);return{bitmap:a,packed_memory:c}};P.prototype.unpack_memory=function(a,b){this.zero_memory(0,this.memory_size[0]);const c=this.memory_size[0]>>12;let d=0;for(let f=0;f<c;f++)if(a.get(f)){var e=d<<12;e=b.subarray(e,e+4096);this.mem8.set(e,f<<12);d++}};P.prototype.reboot_internal=function(){this.reset_cpu();this.fw_value=[];this.devices.virtio_9p&&
639
+ this.devices.virtio_9p.reset();this.devices.virtio_console&&this.devices.virtio_console.reset();this.devices.virtio_net&&this.devices.virtio_net.reset();this.devices.ps2&&this.devices.ps2.reset();this.load_bios()};P.prototype.reset_memory=function(){this.mem8.fill(0)};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],
640
+ "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?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();
641
+ if(a.bzimage){const e=bd(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=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)}
642
+ 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===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);
643
+ 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=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});
644
+ 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,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,
645
+ 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=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=
646
+ 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=[[void 0,void 0],[void 0,void 0]],a.hda&&(c[0][0]={buffer:a.hda},c[0][1]={buffer:a.hdb}),c[1][0]={is_cdrom:!0,buffer:a.cdrom},this.devices.ide=new Vc(this,b,c),this.devices.cdrom=this.devices.ide.secondary.master,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):
647
+ "virtio"===a.net_device.type&&(this.devices.virtio_net=new Xc(this,b,a.preserve_mac_from_state_image)),a.fs9p&&(this.devices.virtio_9p=new cd(a.fs9p,this,b)),a.virtio_console&&(this.devices.virtio_console=new Hc(this,b)),a.virtio_balloon&&(this.devices.virtio_balloon=new ad(this,b)),this.devices.sb16=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)):
648
+ (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))};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=
649
+ 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,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,
650
+ 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);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];
651
+ 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);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");
652
+ 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");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*
653
+ 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),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),
654
+ 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<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=
655
+ 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 "+(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 "+
656
+ 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]=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});
657
+ 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)}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];
658
+ 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]-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,
659
+ 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);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|
660
+ 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=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);
661
+ 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=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),
662
+ 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)};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],
663
+ 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="",L=0;16>L;L++)w[1<<L]&&(F=r&1<<L?F+w[1<<L]:F+" ");return"mode="+q+"/"+u+" paging="+ +(0!==(e.cr[0]&-2147483648))+" pae="+ +(0!==(e.cr[4]&32))+" 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=
664
+ {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],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===
665
+ (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 ":" ",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);
666
+ var L=c(u,q,!1);L&&(u="",u+=L.cache_disable?"Cd ":" ",u+=L.user?"U ":" ",u+=L.read_write?"Rw ":" ",u+=L.global?"G ":" ",u+=L.accessed?"A ":" ",u+=L.dirty?"Di ":" ",C("# "+m(r+(A<<y|w<<12)>>>0,8)+" -> "+m(L.address,8)+" | "+u+" (at "+m(F,8)+")"))}}}}var e=this,f={};this.debug=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=
667
+ 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))}};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,
668
+ 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: "+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]),
669
+ 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)|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 = "+
670
+ 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=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=
671
+ 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");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+
672
+ " "+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");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");
673
+ 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=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>>
674
+ 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);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"),
675
+ 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=[];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?
676
+ 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));e.push(this.create_notification_capability(b.notification));e.push(this.create_isr_capability(b.isr_status));b.device_specific&&e.push(this.create_device_specific_capability(b.device_specific));this.init_capabilities(e);
677
+ a.devices.pci.register_device(this);this.reset()}Ic.prototype.create_common_capability=function(a){return{type:1,bar:0,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:[{bytes:4,name:"device_feature_select",read:()=>this.device_feature_select,write:b=>{this.device_feature_select=b}},{bytes:4,name:"device_feature",read:()=>this.device_feature[this.device_feature_select]||0,write:()=>{}},{bytes:4,name:"driver_feature_select",read:()=>this.driver_feature_select,write:b=>{this.driver_feature_select=
678
+ b}},{bytes:4,name:"driver_feature",read:()=>this.driver_feature[this.driver_feature_select]||0,write:b=>{const c=this.device_feature[this.driver_feature_select];this.driver_feature_select<this.driver_feature.length&&(this.driver_feature[this.driver_feature_select]=b&c);this.features_ok=this.features_ok&&!(b&~c)}},{bytes:2,name:"msix_config",read:()=>{C("No msi-x capability supported.",2097152);return 65535},write:()=>{C("No msi-x capability supported.",2097152)}},{bytes:2,name:"num_queues",read:()=>
679
+ this.queues.length,write:()=>{}},{bytes:1,name:"device_status",read:()=>this.device_status,write:b=>{0===b?(C("Reset device<"+this.name+">",2097152),this.reset()):b&128?C("Warning: Device<"+this.name+"> status failed",2097152):C("Device<"+this.name+"> status: "+(b&1?"ACKNOWLEDGE ":"")+(b&2?"DRIVER ":"")+(b&4?"DRIVER_OK":"")+(b&8?"FEATURES_OK ":"")+(b&64?"DEVICE_NEEDS_RESET":""),2097152);b&~this.device_status&4&&this.device_status&64&&this.notify_config_changes();this.features_ok||(b&8&&C("Removing FEATURES_OK",
680
+ 2097152),b&=-9);this.device_status=b;if(b&~this.device_status&4)a.on_driver_ok()}},{bytes:1,name:"config_generation",read:()=>this.config_generation,write:()=>{}},{bytes:2,name:"queue_select",read:()=>this.queue_select,write:b=>{this.queue_select=b;this.queue_selected=this.queue_select<this.queues.length?this.queues[this.queue_select]:null}},{bytes:2,name:"queue_size",read:()=>this.queue_selected?this.queue_selected.size:0,write:b=>{this.queue_selected&&(b&b-1&&(C("Warning: dev<"+this.name+"> Given queue size was not a power of 2. Rounding up to next power of 2.",
681
+ 2097152),b=1<<ea(b-1)+1),b>this.queue_selected.size_supported&&(C("Warning: dev<"+this.name+"> Trying to set queue size greater than supported. Clamping to supported size.",2097152),b=this.queue_selected.size_supported),this.queue_selected.set_size(b))}},{bytes:2,name:"queue_msix_vector",read:()=>{C("No msi-x capability supported.",2097152);return 65535},write:()=>{C("No msi-x capability supported.",2097152)}},{bytes:2,name:"queue_enable",read:()=>this.queue_selected?this.queue_selected.enabled|0:
682
+ 0,write:b=>{this.queue_selected&&(1===b?this.queue_selected.is_configured()?this.queue_selected.enable():C("Driver bug: tried enabling unconfigured queue",2097152):0===b&&C("Driver bug: tried writing 0 to queue_enable",2097152))}},{bytes:2,name:"queue_notify_off",read:()=>this.queue_selected?this.queue_selected.notify_offset:0,write:()=>{}},{bytes:4,name:"queue_desc (low dword)",read:()=>this.queue_selected?this.queue_selected.desc_addr:0,write:b=>{this.queue_selected&&(this.queue_selected.desc_addr=
683
+ b)}},{bytes:4,name:"queue_desc (high dword)",read:()=>0,write:b=>{0!==b&&C("Warning: High dword of 64 bit queue_desc ignored:"+b,2097152)}},{bytes:4,name:"queue_avail (low dword)",read:()=>this.queue_selected?this.queue_selected.avail_addr:0,write:b=>{this.queue_selected&&(this.queue_selected.avail_addr=b)}},{bytes:4,name:"queue_avail (high dword)",read:()=>0,write:b=>{0!==b&&C("Warning: High dword of 64 bit queue_avail ignored:"+b,2097152)}},{bytes:4,name:"queue_used (low dword)",read:()=>this.queue_selected?
684
+ this.queue_selected.used_addr:0,write:b=>{this.queue_selected&&(this.queue_selected.used_addr=b)}},{bytes:4,name:"queue_used (high dword)",read:()=>0,write:b=>{0!==b&&C("Warning: High dword of 64 bit queue_used ignored:"+b,2097152)}}]}};Ic.prototype.create_notification_capability=function(a){const b=[];let c;a.single_handler?(k(1===a.handlers.length,"VirtIO device<"+this.name+"> too many notify handlers specified: expected single handler"),c=0):c=2;for(const [d,e]of a.handlers.entries())b.push({bytes:2,
685
+ name:"notify"+d,read:()=>65535,write:e||(()=>{})});return{type:2,bar:1,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array([c&255,c>>8&255,c>>16&255,c>>24]),struct:b}};Ic.prototype.create_isr_capability=function(a){return{type:3,bar:2,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:[{bytes:1,name:"isr_status",read:()=>{const b=this.isr_status;this.lower_irq();return b},write:()=>{}}]}};Ic.prototype.create_device_specific_capability=function(a){k(~a.offset&3,"VirtIO device<"+
686
+ this.name+"> device specific cap offset must be 4-byte aligned");return{type:4,bar:3,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:a.struct}};Ic.prototype.init_capabilities=function(a){let b=this.pci_space[52]=64;var c=b;for(const e of a){a=16+e.extra.length;c=b;b=c+a;k(256>=b,"VirtIO device<"+this.name+"> can't fit all capabilities into 256byte configspace");k(0<=e.bar&&6>e.bar,"VirtIO device<"+this.name+"> capability invalid bar number");var d=e.struct.reduce((f,h)=>f+
687
+ h.bytes,0);d+=e.offset;d=16>d?16:1<<ea(d-1)+1;k(0===(e.port&d-1),"VirtIO device<"+this.name+"> capability port should be aligned to pci bar size");this.pci_bars[e.bar]={size:d};this.pci_space[c]=9;this.pci_space[c+1]=b;this.pci_space[c+2]=a;this.pci_space[c+3]=e.type;this.pci_space[c+4]=e.bar;this.pci_space[c+5]=0;this.pci_space[c+6]=0;this.pci_space[c+7]=0;this.pci_space[c+8]=e.offset&255;this.pci_space[c+9]=e.offset>>>8&255;this.pci_space[c+10]=e.offset>>>16&255;this.pci_space[c+11]=e.offset>>>
688
+ 24;this.pci_space[c+12]=d&255;this.pci_space[c+13]=d>>>8&255;this.pci_space[c+14]=d>>>16&255;this.pci_space[c+15]=d>>>24;for(const [f,h]of e.extra.entries())this.pci_space[c+16+f]=h;c=16+4*e.bar;this.pci_space[c]=e.port&254|!e.use_mmio;this.pci_space[c+1]=e.port>>>8&255;this.pci_space[c+2]=e.port>>>16&255;this.pci_space[c+3]=e.port>>>24&255;c=e.port+e.offset;for(const f of e.struct){let h=f.read;a=f.write;h=()=>{const l=f.read();C("Device<"+this.name+"> cap["+e.type+"] read["+f.name+"] => "+m(l,8*
689
+ f.bytes),2097152);return l};a=l=>{C("Device<"+this.name+"> cap["+e.type+"] write["+f.name+"] <= "+m(l,8*f.bytes),2097152);f.write(l)};if(e.use_mmio)k(!1,"VirtIO device <"+this.name+"> mmio capability not implemented.");else{d=function(p){C("Warning: 8-bit read from 16-bit virtio port",2097152);return h(p&-2)>>((p&1)<<3)&255};const l=function(p){C("Warning: 8-bit read from 32-bit virtio port",2097152);return h(p&-4)>>((p&3)<<3)&255};switch(f.bytes){case 4:this.cpu.io.register_read(c,this,l,void 0,
690
+ h);this.cpu.io.register_read(c+1,this,l);this.cpu.io.register_read(c+2,this,l);this.cpu.io.register_read(c+3,this,l);this.cpu.io.register_write(c,this,void 0,void 0,a);break;case 2:this.cpu.io.register_read(c,this,d,h);this.cpu.io.register_read(c+1,this,d);this.cpu.io.register_write(c,this,void 0,a);break;case 1:this.cpu.io.register_read(c,this,h);this.cpu.io.register_write(c,this,a);break;default:k(!1,"VirtIO device <"+this.name+"> invalid capability field width of "+f.bytes+" bytes")}}c+=f.bytes}}k(256>=
691
+ b+20,"VirtIO device<"+this.name+"> can't fit all capabilities into 256byte configspace");this.pci_space[b]=9;this.pci_space[b+1]=0;this.pci_space[b+2]=20;this.pci_space[b+3]=5;this.pci_space[b+4]=0;this.pci_space[b+5]=0;this.pci_space[b+6]=0;this.pci_space[b+7]=0;this.pci_space[b+8]=0;this.pci_space[b+9]=0;this.pci_space[b+10]=0;this.pci_space[b+11]=0;this.pci_space[b+12]=0;this.pci_space[b+13]=0;this.pci_space[b+14]=0;this.pci_space[b+15]=0;this.pci_space[b+16]=0;this.pci_space[b+17]=0;this.pci_space[b+
692
+ 18]=0;this.pci_space[b+19]=0};Ic.prototype.get_state=function(){let a=[];a[0]=this.device_feature_select;a[1]=this.driver_feature_select;a[2]=this.device_feature;a[3]=this.driver_feature;a[4]=this.features_ok;a[5]=this.device_status;a[6]=this.config_has_changed;a[7]=this.config_generation;a[8]=this.isr_status;a[9]=this.queue_select;return a=a.concat(this.queues)};Ic.prototype.set_state=function(a){this.device_feature_select=a[0];this.driver_feature_select=a[1];this.device_feature=a[2];this.driver_feature=
693
+ a[3];this.features_ok=a[4];this.device_status=a[5];this.config_has_changed=a[6];this.config_generation=a[7];this.isr_status=a[8];this.queue_select=a[9];let b=0;for(const c of a.slice(10))this.queues[b].set_state(c),b++;this.queue_selected=this.queues[this.queue_select]||null};Ic.prototype.reset=function(){this.driver_feature_select=this.device_feature_select=0;this.driver_feature.set(this.device_feature);this.features_ok=!0;this.queue_select=this.device_status=0;this.queue_selected=this.queues[0];
694
+ for(const a of this.queues)a.reset();this.config_has_changed=!1;this.config_generation=0;this.lower_irq()};Ic.prototype.notify_config_changes=function(){this.config_has_changed=!0;this.device_status&4?this.raise_irq(2):k(!1,"VirtIO device<"+this.name+"> attempted to notify driver before DRIVER_OK")};Ic.prototype.update_config_generation=function(){this.config_has_changed&&(this.config_generation++,this.config_generation&=255,this.config_has_changed=!1)};Ic.prototype.is_feature_negotiated=function(a){return 0<
695
+ (this.driver_feature[a>>>5]&1<<(a&31))};Ic.prototype.needs_reset=function(){C("Device<"+this.name+"> experienced error - requires reset",2097152);this.device_status|=64;this.device_status&4&&this.notify_config_changes()};Ic.prototype.raise_irq=function(a){C("Raise irq "+m(a),2097152);this.isr_status|=a;this.pci.raise_irq(this.pci_id)};Ic.prototype.lower_irq=function(){C("Lower irq ",2097152);this.isr_status=0;this.pci.lower_irq(this.pci_id)};function Y(a,b,c){this.cpu=a;this.virtio=b;this.size_supported=
696
+ this.size=c.size_supported;this.mask=this.size-1;this.enabled=!1;this.notify_offset=c.notify_offset;this.num_staged_replies=this.used_addr=this.avail_last_idx=this.avail_addr=this.desc_addr=0;this.reset()}Y.prototype.get_state=function(){const a=[];a[0]=this.size;a[1]=this.size_supported;a[2]=this.enabled;a[3]=this.notify_offset;a[4]=this.desc_addr;a[5]=this.avail_addr;a[6]=this.avail_last_idx;a[7]=this.used_addr;a[8]=this.num_staged_replies;a[9]=1;return a};Y.prototype.set_state=function(a){this.size=
697
+ a[0];this.size_supported=a[1];this.enabled=a[2];this.notify_offset=a[3];this.desc_addr=a[4];this.avail_addr=a[5];this.avail_last_idx=a[6];this.used_addr=a[7];this.num_staged_replies=a[8];this.mask=this.size-1;this.fix_wrapping=1!==a[9]};Y.prototype.reset=function(){this.enabled=!1;this.num_staged_replies=this.used_addr=this.avail_last_idx=this.avail_addr=this.desc_addr=0;this.set_size(this.size_supported)};Y.prototype.is_configured=function(){return this.desc_addr&&this.avail_addr&&this.used_addr};
698
+ Y.prototype.enable=function(){k(this.is_configured(),"VirtQueue must be configured before enabled");this.enabled=!0};Y.prototype.set_size=function(a){k(0===(a&a-1),"VirtQueue size must be power of 2 or zero");k(a<=this.size_supported,"VirtQueue size must be within supported size");this.size=a;this.mask=a-1};Y.prototype.count_requests=function(){k(this.avail_addr,"VirtQueue addresses must be configured before use");this.fix_wrapping&&(this.fix_wrapping=!1,this.avail_last_idx=(this.avail_get_idx()&
699
+ ~this.mask)+(this.avail_last_idx&this.mask));return this.avail_get_idx()-this.avail_last_idx&65535};Y.prototype.has_request=function(){k(this.avail_addr,"VirtQueue addresses must be configured before use");return 0!==this.count_requests()};Y.prototype.pop_request=function(){k(this.avail_addr,"VirtQueue addresses must be configured before use");k(this.has_request(),"VirtQueue must not pop nonexistent request");var a=this.avail_get_entry(this.avail_last_idx);C("Pop request: avail_last_idx="+this.avail_last_idx+
700
+ " desc_idx="+a,2097152);a=new dd(this,a);this.avail_last_idx=this.avail_last_idx+1&65535;return a};Y.prototype.push_reply=function(a){k(this.used_addr,"VirtQueue addresses must be configured before use");k(this.num_staged_replies<this.size,"VirtQueue replies must not exceed queue size");const b=this.used_get_idx()+this.num_staged_replies&this.mask;C("Push reply: used_idx="+b+" desc_idx="+a.head_idx,2097152);this.used_set_entry(b,a.head_idx,a.length_written);this.num_staged_replies++};Y.prototype.flush_replies=
701
+ function(){k(this.used_addr,"VirtQueue addresses must be configured before use");if(0===this.num_staged_replies)C("flush_replies: Nothing to flush",2097152);else{C("Flushing "+this.num_staged_replies+" replies",2097152);var a=this.used_get_idx()+this.num_staged_replies&65535;this.used_set_idx(a);this.num_staged_replies=0;this.virtio.is_feature_negotiated(29)?(this.avail_get_used_event(),this.virtio.raise_irq(1)):~this.avail_get_flags()&1&&this.virtio.raise_irq(1)}};Y.prototype.notify_me_after=function(a){k(0<=
702
+ a,"Must skip a non-negative number of requests");a=this.avail_get_idx()+a&65535;this.used_set_avail_event(a)};Y.prototype.get_descriptor=function(a,b){return{addr_low:this.cpu.read32s(a+16*b),addr_high:this.cpu.read32s(a+16*b+4),len:this.cpu.read32s(a+16*b+8),flags:this.cpu.read16(a+16*b+12),next:this.cpu.read16(a+16*b+14)}};Y.prototype.avail_get_flags=function(){return this.cpu.read16(this.avail_addr)};Y.prototype.avail_get_idx=function(){return this.cpu.read16(this.avail_addr+2)};Y.prototype.avail_get_entry=
703
+ function(a){return this.cpu.read16(this.avail_addr+4+2*(a&this.mask))};Y.prototype.avail_get_used_event=function(){return this.cpu.read16(this.avail_addr+4+2*this.size)};Y.prototype.used_get_flags=function(){return this.cpu.read16(this.used_addr)};Y.prototype.used_set_flags=function(a){this.cpu.write16(this.used_addr,a)};Y.prototype.used_get_idx=function(){return this.cpu.read16(this.used_addr+2)};Y.prototype.used_set_idx=function(a){this.cpu.write16(this.used_addr+2,a)};Y.prototype.used_set_entry=
704
+ function(a,b,c){this.cpu.write32(this.used_addr+4+8*a,b);this.cpu.write32(this.used_addr+8+8*a,c)};Y.prototype.used_set_avail_event=function(a){this.cpu.write16(this.used_addr+4+8*this.size,a)};function dd(a,b){this.cpu=a.cpu;this.virtio=a.virtio;this.head_idx=b;this.read_buffers=[];this.length_readable=this.read_buffer_offset=this.read_buffer_idx=0;this.write_buffers=[];this.length_writable=this.length_written=this.write_buffer_offset=this.write_buffer_idx=0;let c=a.desc_addr,d=0,e=a.size,f=!1;const h=
705
+ this.virtio.is_feature_negotiated(28);C("<<< Descriptor chain start",2097152);do{const l=a.get_descriptor(c,b);C("descriptor: idx="+b+" addr="+m(l.addr_high,8)+":"+m(l.addr_low,8)+" len="+m(l.len,8)+" flags="+m(l.flags,4)+" next="+m(l.next,4),2097152);if(h&&l.flags&4)l.flags&1&&C("Driver bug: has set VIRTQ_DESC_F_NEXT flag in an indirect table descriptor",2097152),c=l.addr_low,d=b=0,e=l.len/16,C("start indirect",2097152);else{if(l.flags&2)f=!0,this.write_buffers.push(l),this.length_writable+=l.len;
706
+ else{if(f){C("Driver bug: readonly buffer after writeonly buffer within chain",2097152);break}this.read_buffers.push(l);this.length_readable+=l.len}d++;if(d>e){C("Driver bug: descriptor chain cycle detected",2097152);break}if(l.flags&1)b=l.next;else break}}while(1);C("Descriptor chain end >>>",2097152)}dd.prototype.get_next_blob=function(a){let b=0,c=a.length;for(;c;){if(this.read_buffer_idx===this.read_buffers.length){C("Device<"+this.virtio.name+"> Read more than device-readable buffers has",2097152);
707
+ break}var d=this.read_buffers[this.read_buffer_idx];const e=d.addr_low+this.read_buffer_offset;d=d.len-this.read_buffer_offset;d>c?(d=c,this.read_buffer_offset+=c):(this.read_buffer_idx++,this.read_buffer_offset=0);a.set(this.cpu.read_blob(e,d),b);b+=d;c-=d}return b};dd.prototype.set_next_blob=function(a){let b=0,c=a.length;for(;c;){if(this.write_buffer_idx===this.write_buffers.length){C("Device<"+this.virtio.name+"> Write more than device-writable capacity",2097152);break}var d=this.write_buffers[this.write_buffer_idx];
708
+ const e=d.addr_low+this.write_buffer_offset;d=d.len-this.write_buffer_offset;d>c?(d=c,this.write_buffer_offset+=c):(this.write_buffer_idx++,this.write_buffer_offset=0);this.cpu.write_blob(a.subarray(b,b+d),e);b+=d;c-=d}this.length_written+=b;return b};const ed=["shared","exclusive","unlock"];function cd(a,b,c){this.fs=a;this.bus=c;this.configspace_tagname=[104,111,115,116,57,112];this.configspace_taglen=this.configspace_tagname.length;this.VERSION="9P2000.L";this.msize=this.BLOCKSIZE=8192;this.replybuffer=
709
+ new Uint8Array(2*this.msize);this.replybuffersize=0;this.fids=[];this.virtio=new Ic(b,{name:"virtio-9p",pci_id:48,device_id:4169,subsystem_device_id:9,common:{initial_port:43008,queues:[{size_supported:32,notify_offset:0}],features:[0,32,29,28],on_driver_ok:()=>{}},notification:{initial_port:43264,single_handler:!1,handlers:[d=>{if(0!==d)k(!1,"Virtio9P Notified for non-existent queue: "+d+" (expected queue_id of 0)");else{for(;this.virtqueue.has_request();)d=this.virtqueue.pop_request(),this.ReceiveRequest(d);
710
+ this.virtqueue.notify_me_after(0)}}]},isr_status:{initial_port:42752},device_specific:{initial_port:42496,struct:[{bytes:2,name:"mount tag length",read:()=>this.configspace_taglen,write:()=>{}}].concat(Array.from(Array(254).keys()).map(d=>({bytes:1,name:"mount tag name "+d,read:()=>this.configspace_tagname[d]||0,write:()=>{}})))}});this.virtqueue=this.virtio.queues[0]}cd.prototype.get_state=function(){var a=[];a[0]=this.configspace_tagname;a[1]=this.configspace_taglen;a[2]=this.virtio;a[3]=this.VERSION;
711
+ a[4]=this.BLOCKSIZE;a[5]=this.msize;a[6]=this.replybuffer;a[7]=this.replybuffersize;a[8]=this.fids.map(function(b){return[b.inodeid,b.type,b.uid,b.dbg_name]});a[9]=this.fs;return a};cd.prototype.set_state=function(a){this.configspace_tagname=a[0];this.configspace_taglen=a[1];this.virtio.set_state(a[2]);this.virtqueue=this.virtio.queues[0];this.VERSION=a[3];this.BLOCKSIZE=a[4];this.msize=a[5];this.replybuffer=a[6];this.replybuffersize=a[7];this.fids=a[8].map(function(b){return{inodeid:b[0],type:b[1],
712
+ uid:b[2],dbg_name:b[3]}});this.fs.set_state(a[9])};cd.prototype.Createfid=function(a,b,c,d){return{inodeid:a,type:b,uid:c,dbg_name:d}};cd.prototype.update_dbg_name=function(a,b){for(const c of this.fids)c.inodeid===a&&(c.dbg_name=b)};cd.prototype.reset=function(){this.fids=[];this.virtio.reset()};cd.prototype.BuildReply=function(a,b,c){k(0<=c,"9P: Negative payload size");J(["w","b","h"],[c+7,a+1,b],this.replybuffer,0);c+7>=this.replybuffer.length&&C("Error in 9p: payloadsize exceeds maximum length",
713
+ 4194304);this.replybuffersize=c+7};cd.prototype.SendError=function(a,b,c){b=J(["w"],[c],this.replybuffer,7);this.BuildReply(6,a,b)};cd.prototype.SendReply=function(a){k(0<=this.replybuffersize,"9P: Negative replybuffersize");a.set_next_blob(this.replybuffer.subarray(0,this.replybuffersize));this.virtqueue.push_reply(a);this.virtqueue.flush_replies()};cd.prototype.ReceiveRequest=async function(a){var b=new Uint8Array(a.length_readable);a.get_next_blob(b);var c={offset:0},d=K(["w","b","h"],b,c),e=d[0],
714
+ f=d[1],h=d[2];switch(f){case 8:e=this.fs.GetTotalSize();b=this.fs.GetSpace();d=[16914839];d[1]=this.BLOCKSIZE;d[2]=Math.floor(b/d[1]);d[3]=d[2]-Math.floor(e/d[1]);d[4]=d[2]-Math.floor(e/d[1]);d[5]=this.fs.CountUsedInodes();d[6]=this.fs.CountFreeInodes();d[7]=0;d[8]=256;e=J("wwddddddw".split(""),d,this.replybuffer,7);this.BuildReply(f,h,e);this.SendReply(a);break;case 112:case 12:d=K(["w","w"],b,c);var l=d[0];c=d[1];C("[open] fid="+l+", mode="+c,4194304);b=this.fids[l].inodeid;var p=this.fs.GetInode(b);
715
+ C("file open "+this.fids[l].dbg_name,4194304);d=this.fs.OpenInode(b,c);this.fs.AddEvent(this.fids[l].inodeid,function(){C("file opened "+this.fids[l].dbg_name+" tag:"+h,4194304);var t=[];t[0]=p.qid;t[1]=this.msize-24;J(["Q","w"],t,this.replybuffer,7);this.BuildReply(f,h,17);this.SendReply(a)}.bind(this));break;case 70:d=K(["w","w","s"],b,c);b=d[0];l=d[1];e=d[2];C("[link] dfid="+b+", name="+e,4194304);d=this.fs.Link(this.fids[b].inodeid,this.fids[l].inodeid,e);if(0>d){e="";-1===d?e="Operation not permitted":
716
+ (e="Unknown error: "+-d,k(!1,"[link]: Unexpected error code: "+-d));this.SendError(h,e,-d);this.SendReply(a);break}this.BuildReply(f,h,0);this.SendReply(a);break;case 16:d=K(["w","s","s","w"],b,c);l=d[0];e=d[1];b=d[2];d=d[3];C("[symlink] fid="+l+", name="+e+", symgt="+b+", gid="+d,4194304);b=this.fs.CreateSymlink(e,this.fids[l].inodeid,b);p=this.fs.GetInode(b);p.uid=this.fids[l].uid;p.gid=d;J(["Q"],[p.qid],this.replybuffer,7);this.BuildReply(f,h,13);this.SendReply(a);break;case 18:d=K("wswwww".split(""),
717
+ b,c);l=d[0];e=d[1];c=d[2];b=d[3];var n=d[4];d=d[5];C("[mknod] fid="+l+", name="+e+", major="+b+", minor="+n,4194304);b=this.fs.CreateNode(e,this.fids[l].inodeid,b,n);p=this.fs.GetInode(b);p.mode=c;p.uid=this.fids[l].uid;p.gid=d;J(["Q"],[p.qid],this.replybuffer,7);this.BuildReply(f,h,13);this.SendReply(a);break;case 22:d=K(["w"],b,c);l=d[0];p=this.fs.GetInode(this.fids[l].inodeid);C("[readlink] fid="+l+" name="+this.fids[l].dbg_name+" target="+p.symlink,4194304);e=J(["s"],[p.symlink],this.replybuffer,
718
+ 7);this.BuildReply(f,h,e);this.SendReply(a);break;case 72:d=K(["w","s","w","w"],b,c);l=d[0];e=d[1];c=d[2];d=d[3];C("[mkdir] fid="+l+", name="+e+", mode="+c+", gid="+d,4194304);b=this.fs.CreateDirectory(e,this.fids[l].inodeid);p=this.fs.GetInode(b);p.mode=c|16384;p.uid=this.fids[l].uid;p.gid=d;J(["Q"],[p.qid],this.replybuffer,7);this.BuildReply(f,h,13);this.SendReply(a);break;case 14:d=K(["w","s","w","w","w"],b,c);l=d[0];e=d[1];b=d[2];c=d[3];d=d[4];this.bus.send("9p-create",[e,this.fids[l].inodeid]);
719
+ C("[create] fid="+l+", name="+e+", flags="+b+", mode="+c+", gid="+d,4194304);b=this.fs.CreateFile(e,this.fids[l].inodeid);this.fids[l].inodeid=b;this.fids[l].type=1;this.fids[l].dbg_name=e;p=this.fs.GetInode(b);p.uid=this.fids[l].uid;p.gid=d;p.mode=c|32768;J(["Q","w"],[p.qid,this.msize-24],this.replybuffer,7);this.BuildReply(f,h,17);this.SendReply(a);break;case 52:d=K("wbwddws".split(""),b,c);l=d[0];b=d[2];e=0===d[4]?Infinity:d[4];e=this.fs.DescribeLock(d[1],d[3],e,d[5],d[6]);C("[lock] fid="+l+", type="+
720
+ ed[e.type]+", start="+e.start+", length="+e.length+", proc_id="+e.proc_id);d=this.fs.Lock(this.fids[l].inodeid,e,b);J(["b"],[d],this.replybuffer,7);this.BuildReply(f,h,1);this.SendReply(a);break;case 54:d=K("wbddws".split(""),b,c);l=d[0];e=0===d[3]?Infinity:d[3];e=this.fs.DescribeLock(d[1],d[2],e,d[4],d[5]);C("[getlock] fid="+l+", type="+ed[e.type]+", start="+e.start+", length="+e.length+", proc_id="+e.proc_id);d=this.fs.GetLock(this.fids[l].inodeid,e);d||(d=e,d.type=2);e=J(["b","d","d","w","s"],
721
+ [d.type,d.start,Infinity===d.length?0:d.length,d.proc_id,d.client_id],this.replybuffer,7);this.BuildReply(f,h,e);this.SendReply(a);break;case 24:d=K(["w","d"],b,c);l=d[0];p=this.fs.GetInode(this.fids[l].inodeid);C("[getattr]: fid="+l+" name="+this.fids[l].dbg_name+" request mask="+d[1],4194304);if(!p||4===p.status){C("getattr: unlinked",4194304);this.SendError(h,"No such file or directory",2);this.SendReply(a);break}d[0]=d[1];d[1]=p.qid;d[2]=p.mode;d[3]=p.uid;d[4]=p.gid;d[5]=p.nlinks;d[6]=p.major<<
722
+ 8|p.minor;d[7]=p.size;d[8]=this.BLOCKSIZE;d[9]=Math.floor(p.size/512+1);d[10]=p.atime;d[11]=0;d[12]=p.mtime;d[13]=0;d[14]=p.ctime;d[15]=0;d[16]=0;d[17]=0;d[18]=0;d[19]=0;J("dQwwwddddddddddddddd".split(""),d,this.replybuffer,7);this.BuildReply(f,h,153);this.SendReply(a);break;case 26:d=K("wwwwwddddd".split(""),b,c);l=d[0];p=this.fs.GetInode(this.fids[l].inodeid);C("[setattr]: fid="+l+" request mask="+d[1]+" name="+this.fids[l].dbg_name,4194304);d[1]&1&&(p.mode=d[2]);d[1]&2&&(p.uid=d[3]);d[1]&4&&(p.gid=
723
+ d[4]);d[1]&16&&(p.atime=Math.floor((new Date).getTime()/1E3));d[1]&32&&(p.mtime=Math.floor((new Date).getTime()/1E3));d[1]&64&&(p.ctime=Math.floor((new Date).getTime()/1E3));d[1]&128&&(p.atime=d[6]);d[1]&256&&(p.mtime=d[8]);d[1]&8&&await this.fs.ChangeSize(this.fids[l].inodeid,d[5]);this.BuildReply(f,h,0);this.SendReply(a);break;case 50:d=K(["w","d"],b,c);l=d[0];this.BuildReply(f,h,0);this.SendReply(a);break;case 40:case 116:d=K(["w","d","w"],b,c);l=d[0];e=d[1];n=d[2];p=this.fs.GetInode(this.fids[l].inodeid);
724
+ 40===f&&C("[treaddir]: fid="+l+" offset="+e+" count="+n,4194304);116===f&&C("[read]: fid="+l+" ("+this.fids[l].dbg_name+") offset="+e+" count="+n+" fidtype="+this.fids[l].type,4194304);if(!p||4===p.status){C("read/treaddir: unlinked",4194304);this.SendError(h,"No such file or directory",2);this.SendReply(a);break}if(2===this.fids[l].type)for(p.caps.length<e+n&&(n=p.caps.length-e),d=0;d<n;d++)this.replybuffer[11+d]=p.caps[e+d];else this.fs.OpenInode(this.fids[l].inodeid,void 0),d=this.fids[l].inodeid,
725
+ n=Math.min(n,this.replybuffer.length-11),p.size<e+n?n=p.size-e:40===f&&(n=this.fs.RoundToDirentry(d,e+n)-e),e>p.size&&(n=0),this.bus.send("9p-read-start",[this.fids[l].dbg_name]),d=await this.fs.Read(d,e,n),this.bus.send("9p-read-end",[this.fids[l].dbg_name,n]),d&&this.replybuffer.set(d,11);J(["w"],[n],this.replybuffer,7);this.BuildReply(f,h,4+n);this.SendReply(a);break;case 118:d=K(["w","d","w"],b,c);l=d[0];e=d[1];n=d[2];d=this.fids[l].dbg_name;C("[write]: fid="+l+" ("+d+") offset="+e+" count="+
726
+ n+" fidtype="+this.fids[l].type,4194304);if(2===this.fids[l].type){this.SendError(h,"Setxattr not supported",95);this.SendReply(a);break}else await this.fs.Write(this.fids[l].inodeid,e,n,b.subarray(c.offset));this.bus.send("9p-write-end",[d,n]);J(["w"],[n],this.replybuffer,7);this.BuildReply(f,h,4);this.SendReply(a);break;case 74:d=K(["w","s","w","s"],b,c);e=d[0];b=d[1];c=d[2];d=d[3];C("[renameat]: oldname="+b+" newname="+d,4194304);d=await this.fs.Rename(this.fids[e].inodeid,b,this.fids[c].inodeid,
727
+ d);if(0>d){e="";-2===d?e="No such file or directory":-1===d?e="Operation not permitted":-39===d?e="Directory not empty":(e="Unknown error: "+-d,k(!1,"[renameat]: Unexpected error code: "+-d));this.SendError(h,e,-d);this.SendReply(a);break}this.BuildReply(f,h,0);this.SendReply(a);break;case 76:d=K(["w","s","w"],b,c);c=d[0];e=d[1];b=d[2];C("[unlink]: dirfd="+c+" name="+e+" flags="+b,4194304);l=this.fs.Search(this.fids[c].inodeid,e);if(-1===l){this.SendError(h,"No such file or directory",2);this.SendReply(a);
728
+ break}d=this.fs.Unlink(this.fids[c].inodeid,e);if(0>d){e="";-39===d?e="Directory not empty":-1===d?e="Operation not permitted":(e="Unknown error: "+-d,k(!1,"[unlink]: Unexpected error code: "+-d));this.SendError(h,e,-d);this.SendReply(a);break}this.BuildReply(f,h,0);this.SendReply(a);break;case 100:d=K(["w","s"],b,c);C("[version]: msize="+d[0]+" version="+d[1],4194304);this.msize!==d[0]&&(this.msize=d[0],this.replybuffer=new Uint8Array(Math.min(16777216,2*this.msize)));e=J(["w","s"],[this.msize,this.VERSION],
729
+ this.replybuffer,7);this.BuildReply(f,h,e);this.SendReply(a);break;case 104:d=K(["w","w","s","s","w"],b,c);l=d[0];e=d[4];C("[attach]: fid="+l+" afid="+m(d[1])+" uname="+d[2]+" aname="+d[3],4194304);this.fids[l]=this.Createfid(0,1,e,"");p=this.fs.GetInode(this.fids[l].inodeid);J(["Q"],[p.qid],this.replybuffer,7);this.BuildReply(f,h,13);this.SendReply(a);this.bus.send("9p-attach");break;case 108:d=K(["h"],b,c);C("[flush] "+h,4194304);this.BuildReply(f,h,0);this.SendReply(a);break;case 110:d=K(["w",
730
+ "w","h"],b,c);l=d[0];n=d[1];var q=d[2];C("[walk]: fid="+d[0]+" nwfid="+d[1]+" nwname="+q,4194304);if(0===q){this.fids[n]=this.Createfid(this.fids[l].inodeid,1,this.fids[l].uid,this.fids[l].dbg_name);J(["h"],[0],this.replybuffer,7);this.BuildReply(f,h,2);this.SendReply(a);break}e=[];for(d=0;d<q;d++)e.push("s");c=K(e,b,c);b=this.fids[l].inodeid;e=9;var r=0;C("walk in dir "+this.fids[l].dbg_name+" to: "+c.toString(),4194304);for(d=0;d<q;d++){b=this.fs.Search(b,c[d]);if(-1===b){C("Could not find: "+c[d],
731
+ 4194304);break}e+=J(["Q"],[this.fs.GetInode(b).qid],this.replybuffer,e);r++;this.fids[n]=this.Createfid(b,1,this.fids[l].uid,c[d])}J(["h"],[r],this.replybuffer,7);this.BuildReply(f,h,e-7);this.SendReply(a);break;case 120:d=K(["w"],b,c);C("[clunk]: fid="+d[0],4194304);this.fids[d[0]]&&0<=this.fids[d[0]].inodeid&&(await this.fs.CloseInode(this.fids[d[0]].inodeid),this.fids[d[0]].inodeid=-1,this.fids[d[0]].type=-1);this.BuildReply(f,h,0);this.SendReply(a);break;case 32:d=K(["w","s","d","w"],b,c);l=d[0];
732
+ e=d[1];c=d[2];b=d[3];C("[txattrcreate]: fid="+l+" name="+e+" attr_size="+c+" flags="+b,4194304);this.fids[l].type=2;this.BuildReply(f,h,0);this.SendReply(a);break;case 30:d=K(["w","w","s"],b,c);l=d[0];e=d[2];C("[xattrwalk]: fid="+d[0]+" newfid="+d[1]+" name="+d[2],4194304);this.SendError(h,"Setxattr not supported",95);this.SendReply(a);break;default:C("Error in Virtio9p: Unknown id "+f+" received",4194304),k(!1)}};export{};; export default module.exports.V86; export let {V86, CPU} = module.exports;