v86 0.5.362 → 0.5.366

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.
package/build/libv86.mjs CHANGED
@@ -9,22 +9,22 @@ h=0;h<g.length;h++){var l=g[h];e.setRequestHeader(l,b.headers[l])}b.range&&(g=b.
9
9
  a+" failed (status %d)",e.status),500<=e.status&&600>e.status&&d();else if(e.response){if(b.range){const m=e.getResponseHeader("Content-Encoding");m&&"identity"!==m&&console.error("Server sent Content-Encoding in response to ranged request",{filename:a,enc:m})}b.done&&b.done(e.response,e)}};e.onerror=function(m){b.signal&&b.signal.removeEventListener("abort",f);console.error("Loading the image "+a+" failed",m);d()};b.progress&&(e.onprogress=function(m){b.progress(m)});e.send(null)},qa=async function(a){return new Promise((b,
10
10
  c)=>{pa(a,{done:(d,e)=>{d=e.getResponseHeader("Content-Range")||"";(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"}})})};function ra(a,b,c){return String.fromCharCode(...(new Uint8Array(a.buffer,b>>>0,c>>>0)))}const sa={cp437:" \u263a\u263b\u2665\u2666\u2663\u2660\u2022\u25d8\u25cb\u25d9\u2642\u2640\u266a\u266b\u263c\u25ba\u25c4\u2195\u203c\u00b6\u00a7\u25ac\u21a8\u2191\u2193\u2192\u2190\u221f\u2194\u25b2\u25bc !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u2302\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00a2\u00a3\u00a5\u20a7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u2310\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580\u03b1\u00df\u0393\u03c0\u03a3\u03c3\u00b5\u03c4\u03a6\u0398\u03a9\u03b4\u221e\u03c6\u03b5\u2229\u2261\u00b1\u2265\u2264\u2320\u2321\u00f7\u2248\u00b0\u2219\u00b7\u221a\u207f\u00b2\u25a0 ",
11
11
  cp858:"\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00f8\u00a3\u00d8\u00d7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u00ae\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u00c1\u00c2\u00c0\u00a9\u2563\u2551\u2557\u255d\u00a2\u00a5\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u00e3\u00c3\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u00a4\u00f0\u00d0\u00ca\u00cb\u00c8\u20ac\u00cd\u00ce\u00cf\u2518\u250c\u2588\u2584\u00a6\u00cc\u2580\u00d3\u00df\u00d4\u00d2\u00f5\u00d5\u00b5\u00fe\u00de\u00da\u00db\u00d9\u00fd\u00dd\u00af\u00b4\u00ad\u00b1\u2017\u00be\u00b6\u00a7\u00f7\u00b8\u00b0\u00a8\u00b7\u00b9\u00b3\u00b2\u25a0 "};
12
- sa.cp858=sa.cp437.slice(0,128)+sa.cp858;sa.ascii=sa.cp437.split("").map((a,b)=>31<b&&128>b?a:".").join("");function ta(a){return a&&sa[a]?sa[a]:sa.cp437}function va(){}function wa(){}function xa(a,b){function c(w){w=w.toString(16);return"#"+"0".repeat(6-w.length)+w}function d(w){var u=256*oa,H=8*S,K=Ua?Ua.canvas:null;K&&K.width===u&&K.height===H||(K?(K.width=u,K.height=H):(K=new OffscreenCanvas(u,H),Ua=K.getContext("2d")),Lb=Ua.createImageData(u,H));const Q=Lb.data;let P=0,T;H=Mb?function(aa){T=T||
13
- aa;Q[P+3]=aa;Q[P+7]=aa;P+=8}:function(aa){T=T||aa;Q[P+3]=aa;P+=4};K=32-S;const ka=u*(S-1)*4;u=4*(oa-u*S);const ha=1020*oa;for(let aa=0,Fa=0;2048>aa;++aa,Fa+=K,P+=u){const Ga=aa%256;aa&&!Ga&&(P+=ka);T=!1;for(let Ma=0;Ma<S;++Ma,++Fa,P+=ha){const Na=w[Fa];for(let ua=128;0<ua;ua>>=1)H(Na&ua?255:0);Nb&&H(Ob&&192<=Ga&&223>=Ga&&Na&1?255:0)}gc[aa]=T?1:0}Ua.putImageData(Lb,0,0)}function e(w,u,H,K){if(u&&H){w.style.width="";w.style.height="";K&&(w.style.transform="");var Q=w.getBoundingClientRect();K?w.style.transform=
14
- (1===u?"":" scaleX("+u+")")+(1===H?"":" scaleY("+H+")"):(0===u%1&&0===H%1?(g.style.imageRendering="crisp-edges",g.style.imageRendering="pixelated",g.style["-ms-interpolation-mode"]="nearest-neighbor"):(g.style.imageRendering="",g.style["-ms-interpolation-mode"]=""),K=window.devicePixelRatio||1,0!==K%1&&(u/=K,H/=K));1!==u&&(w.style.width=Q.width*u+"px");1!==H&&(w.style.height=Q.height*H+"px")}}const f=a.container;this.screen_fill_buffer=b;console.assert(f,"options.container must be provided");this.FLAG_BLINKING=
15
- 1;this.FLAG_FONT_PAGE_B=2;let g=f.getElementsByTagName("canvas")[0];g||(g=document.createElement("canvas"),f.appendChild(g));const h=g.getContext("2d",{alpha:!1});let l=f.getElementsByTagName("div")[0];l||(l=document.createElement("div"),f.appendChild(l));const m=document.createElement("div");var n,p,q=void 0!==a.scale?a.scale:1,r=void 0!==a.scale?a.scale:1,x=1,C,t,A,M,v,L,U,Ua,Lb,gc=new Int8Array(2048),S,oa,Nb,Mb,Ob,Pb=0,Qb=0,tb,hc=0,ub,Rb,vb,Sb=ta(a.encoding),wb=0,Tb=!1;this.init=function(){m.classList.add("cursor");
16
- m.style.position="absolute";m.style.backgroundColor="#ccc";m.style.width="7px";m.style.display="inline-block";this.set_mode(!1);this.set_size_text(80,25);2===t&&this.set_size_graphical(720,400,720,400);this.set_scale(q,r);this.timer()};this.make_screenshot=function(){const w=new Image;if(1===t||2===t)w.src=g.toDataURL("image/png");else{const u=[9,16],H=document.createElement("canvas");H.width=M*u[0];H.height=v*u[1];const K=H.getContext("2d");K.imageSmoothingEnabled=!1;K.font=window.getComputedStyle(l).font;
17
- K.textBaseline="top";for(let Q=0;Q<v;Q++)for(let P=0;P<M;P++){const T=4*(Q*M+P),ka=A[T+0],ha=A[T+3];K.fillStyle=c(A[T+2]);K.fillRect(P*u[0],Q*u[1],u[0],u[1]);K.fillStyle=c(ha);K.fillText(Sb[ka],P*u[0],Q*u[1])}"none"!==m.style.display&&n<v&&p<M&&(K.fillStyle=m.style.backgroundColor,K.fillRect(p*u[0],n*u[1]+parseInt(m.style.marginTop,10),parseInt(m.style.width,10),parseInt(m.style.height,10)));w.src=H.toDataURL("image/png")}return w};this.put_char=function(w,u,H,K,Q,P){u=4*(w*M+u);A[u+0]=H;A[u+1]=K;
18
- A[u+2]=Q;A[u+3]=P;C[w]=1};this.timer=function(){wb=requestAnimationFrame(()=>this.update_screen())};this.update_screen=function(){Tb||(0===t?this.update_text():1===t?this.update_graphical():this.update_graphical_text());this.timer()};this.update_text=function(){for(var w=0;w<v;w++)C[w]&&(this.text_update_row(w),C[w]=0)};this.update_graphical=function(){this.screen_fill_buffer()};this.update_graphical_text=function(){if(L){var w=performance.now();if(266<w-hc){tb=!tb;vb&&(C[n]=1);var u=4*M;for(let ka=
19
- 0,ha=0;ka<v;++ka)if(C[ka])ha+=u;else for(var H=0;H<M;++H,ha+=4)if(A[ha+1]&1){C[ka]=1;ha+=u-4*H;break}hc=w}w=Ua.canvas;u=U.canvas;H=4*M;const Q=M*oa,P=S;let T=0;for(let ka=0,ha=0,aa=0;ka<v;++ka,ha+=S){if(!C[ka]){aa+=H;continue}++T;U.clearRect(0,P,Q,S);let Fa,Ga,Ma,Na;for(let ua=0;ua<Q;ua+=oa,aa+=4){const ic=A[aa+0];var K=A[aa+1];const jc=A[aa+2],kc=A[aa+3],lc=K&2?Qb:Pb;K=(!(K&1)||tb)&&gc[(lc<<8)+ic];Ma!==jc&&(void 0!==Ma&&(L.fillStyle=c(Ma),L.fillRect(Na,ha,ua-Na,S)),Ma=jc,Na=ua);Fa!==kc&&(void 0!==
20
- Fa&&(U.fillStyle=c(Fa),U.fillRect(Ga,0,ua-Ga,S)),Fa=kc,Ga=ua);K&&U.drawImage(w,ic*oa,lc*S,oa,S,ua,P,oa,S)}U.fillStyle=c(Fa);U.fillRect(Ga,0,Q-Ga,S);U.globalCompositeOperation="destination-in";U.drawImage(u,0,P,Q,S,0,0,Q,S);U.globalCompositeOperation="source-over";L.fillStyle=c(Ma);L.fillRect(Na,ha,Q-Na,S);L.drawImage(u,0,0,Q,S,0,ha,Q,S)}T&&(tb&&vb&&C[n]&&(L.fillStyle=c(A[4*(n*M+p)+3]),L.fillRect(p*oa,n*S+ub,oa,Rb-ub+1)),C.fill(0));T&&h.drawImage(L.canvas,0,0)}};this.destroy=function(){wb&&(cancelAnimationFrame(wb),
21
- wb=0)};this.pause=function(){Tb=!0;m.classList.remove("blinking-cursor")};this.continue=function(){Tb=!1;m.classList.add("blinking-cursor")};this.set_mode=function(w){t=w?1:a.use_graphical_text?2:0;0===t?(l.style.display="block",g.style.display="none"):(l.style.display="none",g.style.display="block",2===t&&C&&C.fill(1))};this.set_font_bitmap=function(w,u,H,K,Q,P){const T=H?16:u?9:8;if(S!==w||oa!==T||Nb!==u||Mb!==H||Ob!==K||P)P=oa!==T||S!==w,S=w,oa=T,Nb=u,Mb=H,Ob=K,2===t&&(d(Q),C.fill(1),P&&this.set_size_graphical_text())};
22
- this.set_font_page=function(w,u){if(Pb!==w||Qb!==u)Pb=w,Qb=u,C.fill(1)};this.clear_screen=function(){h.fillStyle="#000";h.fillRect(0,0,g.width,g.height)};this.set_size_graphical_text=function(){if(Ua){var w=oa*M,u=S*v,H=2*S;L&&L.canvas.width===w&&L.canvas.height===u&&U.canvas.height===H||(L?(L.canvas.width=w,L.canvas.height=u,U.canvas.width=w,U.canvas.height=H):(L=(new OffscreenCanvas(w,u)).getContext("2d",{alpha:!1}),U=(new OffscreenCanvas(w,H)).getContext("2d")),this.set_size_graphical(w,u,w,u),
23
- C.fill(1))}};this.set_size_text=function(w,u){if(w!==M||u!==v)if(C=new Int8Array(u),A=new Int32Array(w*u*4),M=w,v=u,0===t){for(;l.childNodes.length>u;)l.removeChild(l.firstChild);for(;l.childNodes.length<u;)l.appendChild(document.createElement("div"));for(w=0;w<u;w++)this.text_update_row(w);e(l,q,r,!0)}else 2===t&&this.set_size_graphical_text()};this.set_size_graphical=function(w,u){g.style.display="block";g.width=w;g.height=u;h.imageSmoothingEnabled=!1;x=640>=w&&2*w<window.innerWidth*window.devicePixelRatio&&
24
- 2*u<window.innerHeight*window.devicePixelRatio?2:1;e(g,q*x,r*x,!1)};this.set_scale=function(w,u){q=w;r=u;e(l,q,r,!0);e(g,q*x,r*x,!1)};this.update_cursor_scanline=function(w,u,H){if(w!==ub||u!==Rb||H!==vb)0===t?H?(m.style.display="inline",m.style.height=u-w+"px",m.style.marginTop=w+"px"):m.style.display="none":2===t&&n<v&&(C[n]=1),ub=w,Rb=u,vb=H};this.update_cursor=function(w,u){if(w!==n||u!==p)w<v&&(C[w]=1),n<v&&(C[n]=1),n=w,p=u};this.text_update_row=function(w){var u=4*w*M,H;var K=l.childNodes[w];
25
- var Q=document.createElement("div");for(var P=0;P<M;){var T=document.createElement("span");var ka=A[u+1]&1;var ha=A[u+2];var aa=A[u+3];ka&&T.classList.add("blink");T.style.backgroundColor=c(ha);T.style.color=c(aa);for(H="";P<M&&(A[u+1]&1)===ka&&A[u+2]===ha&&A[u+3]===aa;)if(H+=Sb[A[u+0]],P++,u+=4,w===n)if(P===p)break;else if(P===p+1){m.style.backgroundColor=T.style.color;Q.appendChild(m);break}T.textContent=H;Q.appendChild(T)}K.parentNode.replaceChild(Q,K)};this.update_buffer=function(w){for(const u of w)h.putImageData(u.image_data,
26
- u.screen_x-u.buffer_x,u.screen_y-u.buffer_y,u.buffer_x,u.buffer_y,u.buffer_width,u.buffer_height)};this.get_text_screen=function(){for(var w=[],u=0;u<v;u++)w.push(this.get_text_row(u));return w};this.get_text_row=function(w){var u=w*M*4;w=u+4*M;let H="";for(;u<w;u+=4)H+=Sb[A[u]];return H};this.init()}function z(a){this.buffer=a;this.byteLength=a.byteLength;this.onprogress=this.onload=void 0}z.prototype.load=function(){this.onload&&this.onload({buffer:this.buffer})};z.prototype.get=function(a,b,c){c(new Uint8Array(this.buffer,
27
- a,b))};z.prototype.set=function(a,b,c){(new Uint8Array(this.buffer,a,b.byteLength)).set(b);c()};z.prototype.get_buffer=function(a){a(this.buffer)};z.prototype.get_state=function(){const a=[];a[0]=this.byteLength;a[1]=new Uint8Array(this.buffer);return a};z.prototype.set_state=function(a){this.byteLength=a[0];this.buffer=a[1].slice().buffer};function ya(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=
12
+ sa.cp858=sa.cp437.slice(0,128)+sa.cp858;sa.ascii=sa.cp437.split("").map((a,b)=>31<b&&128>b?a:".").join("");function ta(a){return a&&sa[a]?sa[a]:sa.cp437}function va(){}function wa(){}function xa(a,b){function c(w){w=w.toString(16);return"#"+"0".repeat(6-w.length)+w}function d(w){var t=256*oa,I=8*S,M=Ua?Ua.canvas:null;M&&M.width===t&&M.height===I||(M?(M.width=t,M.height=I):(M=new OffscreenCanvas(t,I),Ua=M.getContext("2d")),Mb=Ua.createImageData(t,I));const Q=Mb.data;let P=0,T;I=Nb?function(aa){T=T||
13
+ aa;Q[P+3]=aa;Q[P+7]=aa;P+=8}:function(aa){T=T||aa;Q[P+3]=aa;P+=4};M=32-S;const ka=t*(S-1)*4;t=4*(oa-t*S);const ha=1020*oa;for(let aa=0,Fa=0;2048>aa;++aa,Fa+=M,P+=t){const Ga=aa%256;aa&&!Ga&&(P+=ka);T=!1;for(let Ma=0;Ma<S;++Ma,++Fa,P+=ha){const Na=w[Fa];for(let ua=128;0<ua;ua>>=1)I(Na&ua?255:0);Ob&&I(Pb&&192<=Ga&&223>=Ga&&Na&1?255:0)}hc[aa]=T?1:0}Ua.putImageData(Mb,0,0)}function e(w,t,I,M){if(t&&I){w.style.width="";w.style.height="";M&&(w.style.transform="");var Q=w.getBoundingClientRect();M?w.style.transform=
14
+ (1===t?"":" scaleX("+t+")")+(1===I?"":" scaleY("+I+")"):(0===t%1&&0===I%1?(g.style.imageRendering="crisp-edges",g.style.imageRendering="pixelated",g.style["-ms-interpolation-mode"]="nearest-neighbor"):(g.style.imageRendering="",g.style["-ms-interpolation-mode"]=""),M=window.devicePixelRatio||1,0!==M%1&&(t/=M,I/=M));1!==t&&(w.style.width=Q.width*t+"px");1!==I&&(w.style.height=Q.height*I+"px")}}const f=a.container;this.screen_fill_buffer=b;console.assert(f,"options.container must be provided");this.FLAG_BLINKING=
15
+ 1;this.FLAG_FONT_PAGE_B=2;let g=f.getElementsByTagName("canvas")[0];g||(g=document.createElement("canvas"),f.appendChild(g));const h=g.getContext("2d",{alpha:!1});let l=f.getElementsByTagName("div")[0];l||(l=document.createElement("div"),f.appendChild(l));const m=document.createElement("div");var n,p,q=void 0!==a.scale?a.scale:1,r=void 0!==a.scale?a.scale:1,x=1,E,z,u,K,v,H,U,Ua,Mb,hc=new Int8Array(2048),S,oa,Ob,Nb,Pb,Qb=0,Rb=0,ub,ic=0,vb,Sb,wb,Tb=ta(a.encoding),xb=0,Ub=!1;this.init=function(){m.classList.add("cursor");
16
+ m.style.position="absolute";m.style.backgroundColor="#ccc";m.style.width="7px";m.style.display="inline-block";this.set_mode(!1);this.set_size_text(80,25);2===z&&this.set_size_graphical(720,400,720,400);this.set_scale(q,r);this.timer()};this.make_screenshot=function(){const w=new Image;if(1===z||2===z)w.src=g.toDataURL("image/png");else{const t=[9,16],I=document.createElement("canvas");I.width=K*t[0];I.height=v*t[1];const M=I.getContext("2d");M.imageSmoothingEnabled=!1;M.font=window.getComputedStyle(l).font;
17
+ M.textBaseline="top";for(let Q=0;Q<v;Q++)for(let P=0;P<K;P++){const T=4*(Q*K+P),ka=u[T+0],ha=u[T+3];M.fillStyle=c(u[T+2]);M.fillRect(P*t[0],Q*t[1],t[0],t[1]);M.fillStyle=c(ha);M.fillText(Tb[ka],P*t[0],Q*t[1])}"none"!==m.style.display&&n<v&&p<K&&(M.fillStyle=m.style.backgroundColor,M.fillRect(p*t[0],n*t[1]+parseInt(m.style.marginTop,10),parseInt(m.style.width,10),parseInt(m.style.height,10)));w.src=I.toDataURL("image/png")}return w};this.put_char=function(w,t,I,M,Q,P){t=4*(w*K+t);u[t+0]=I;u[t+1]=M;
18
+ u[t+2]=Q;u[t+3]=P;E[w]=1};this.timer=function(){xb=requestAnimationFrame(()=>this.update_screen())};this.update_screen=function(){Ub||(0===z?this.update_text():1===z?this.update_graphical():this.update_graphical_text());this.timer()};this.update_text=function(){for(var w=0;w<v;w++)E[w]&&(this.text_update_row(w),E[w]=0)};this.update_graphical=function(){this.screen_fill_buffer()};this.update_graphical_text=function(){if(H){var w=performance.now();if(266<w-ic){ub=!ub;wb&&(E[n]=1);var t=4*K;for(let ka=
19
+ 0,ha=0;ka<v;++ka)if(E[ka])ha+=t;else for(var I=0;I<K;++I,ha+=4)if(u[ha+1]&1){E[ka]=1;ha+=t-4*I;break}ic=w}w=Ua.canvas;t=U.canvas;I=4*K;const Q=K*oa,P=S;let T=0;for(let ka=0,ha=0,aa=0;ka<v;++ka,ha+=S){if(!E[ka]){aa+=I;continue}++T;U.clearRect(0,P,Q,S);let Fa,Ga,Ma,Na;for(let ua=0;ua<Q;ua+=oa,aa+=4){const jc=u[aa+0];var M=u[aa+1];const kc=u[aa+2],lc=u[aa+3],mc=M&2?Rb:Qb;M=(!(M&1)||ub)&&hc[(mc<<8)+jc];Ma!==kc&&(void 0!==Ma&&(H.fillStyle=c(Ma),H.fillRect(Na,ha,ua-Na,S)),Ma=kc,Na=ua);Fa!==lc&&(void 0!==
20
+ Fa&&(U.fillStyle=c(Fa),U.fillRect(Ga,0,ua-Ga,S)),Fa=lc,Ga=ua);M&&U.drawImage(w,jc*oa,mc*S,oa,S,ua,P,oa,S)}U.fillStyle=c(Fa);U.fillRect(Ga,0,Q-Ga,S);U.globalCompositeOperation="destination-in";U.drawImage(t,0,P,Q,S,0,0,Q,S);U.globalCompositeOperation="source-over";H.fillStyle=c(Ma);H.fillRect(Na,ha,Q-Na,S);H.drawImage(t,0,0,Q,S,0,ha,Q,S)}T&&(ub&&wb&&E[n]&&(H.fillStyle=c(u[4*(n*K+p)+3]),H.fillRect(p*oa,n*S+vb,oa,Sb-vb+1)),E.fill(0));T&&h.drawImage(H.canvas,0,0)}};this.destroy=function(){xb&&(cancelAnimationFrame(xb),
21
+ xb=0)};this.pause=function(){Ub=!0;m.classList.remove("blinking-cursor")};this.continue=function(){Ub=!1;m.classList.add("blinking-cursor")};this.set_mode=function(w){z=w?1:a.use_graphical_text?2:0;0===z?(l.style.display="block",g.style.display="none"):(l.style.display="none",g.style.display="block",2===z&&E&&E.fill(1))};this.set_font_bitmap=function(w,t,I,M,Q,P){const T=I?16:t?9:8;if(S!==w||oa!==T||Ob!==t||Nb!==I||Pb!==M||P)P=oa!==T||S!==w,S=w,oa=T,Ob=t,Nb=I,Pb=M,2===z&&(d(Q),E.fill(1),P&&this.set_size_graphical_text())};
22
+ this.set_font_page=function(w,t){if(Qb!==w||Rb!==t)Qb=w,Rb=t,E.fill(1)};this.clear_screen=function(){h.fillStyle="#000";h.fillRect(0,0,g.width,g.height)};this.set_size_graphical_text=function(){if(Ua){var w=oa*K,t=S*v,I=2*S;H&&H.canvas.width===w&&H.canvas.height===t&&U.canvas.height===I||(H?(H.canvas.width=w,H.canvas.height=t,U.canvas.width=w,U.canvas.height=I):(H=(new OffscreenCanvas(w,t)).getContext("2d",{alpha:!1}),U=(new OffscreenCanvas(w,I)).getContext("2d")),this.set_size_graphical(w,t,w,t),
23
+ E.fill(1))}};this.set_size_text=function(w,t){if(w!==K||t!==v)if(E=new Int8Array(t),u=new Int32Array(w*t*4),K=w,v=t,0===z){for(;l.childNodes.length>t;)l.removeChild(l.firstChild);for(;l.childNodes.length<t;)l.appendChild(document.createElement("div"));for(w=0;w<t;w++)this.text_update_row(w);e(l,q,r,!0)}else 2===z&&this.set_size_graphical_text()};this.set_size_graphical=function(w,t){g.style.display="block";g.width=w;g.height=t;h.imageSmoothingEnabled=!1;x=640>=w&&2*w<window.innerWidth*window.devicePixelRatio&&
24
+ 2*t<window.innerHeight*window.devicePixelRatio?2:1;e(g,q*x,r*x,!1)};this.set_scale=function(w,t){q=w;r=t;e(l,q,r,!0);e(g,q*x,r*x,!1)};this.update_cursor_scanline=function(w,t,I){if(w!==vb||t!==Sb||I!==wb)0===z?I?(m.style.display="inline",m.style.height=t-w+"px",m.style.marginTop=w+"px"):m.style.display="none":2===z&&n<v&&(E[n]=1),vb=w,Sb=t,wb=I};this.update_cursor=function(w,t){if(w!==n||t!==p)w<v&&(E[w]=1),n<v&&(E[n]=1),n=w,p=t};this.text_update_row=function(w){var t=4*w*K,I;var M=l.childNodes[w];
25
+ var Q=document.createElement("div");for(var P=0;P<K;){var T=document.createElement("span");var ka=u[t+1]&1;var ha=u[t+2];var aa=u[t+3];ka&&T.classList.add("blink");T.style.backgroundColor=c(ha);T.style.color=c(aa);for(I="";P<K&&(u[t+1]&1)===ka&&u[t+2]===ha&&u[t+3]===aa;)if(I+=Tb[u[t+0]],P++,t+=4,w===n)if(P===p)break;else if(P===p+1){m.style.backgroundColor=T.style.color;Q.appendChild(m);break}T.textContent=I;Q.appendChild(T)}M.parentNode.replaceChild(Q,M)};this.update_buffer=function(w){for(const t of w)h.putImageData(t.image_data,
26
+ t.screen_x-t.buffer_x,t.screen_y-t.buffer_y,t.buffer_x,t.buffer_y,t.buffer_width,t.buffer_height)};this.get_text_screen=function(){for(var w=[],t=0;t<v;t++)w.push(this.get_text_row(t));return w};this.get_text_row=function(w){var t=w*K*4;w=t+4*K;let I="";for(;t<w;t+=4)I+=Tb[u[t]];return I};this.init()}function A(a){this.buffer=a;this.byteLength=a.byteLength;this.onprogress=this.onload=void 0}A.prototype.load=function(){this.onload&&this.onload({buffer:this.buffer})};A.prototype.get=function(a,b,c){c(new Uint8Array(this.buffer,
27
+ a,b))};A.prototype.set=function(a,b,c){(new Uint8Array(this.buffer,a,b.byteLength)).set(b);c()};A.prototype.get_buffer=function(a){a(this.buffer)};A.prototype.get_state=function(){const a=[];a[0]=this.byteLength;a[1]=new Uint8Array(this.buffer);return a};A.prototype.set_state=function(a){this.byteLength=a[0];this.buffer=a[1].slice().buffer};function ya(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=
28
28
  this.onload=void 0}ya.prototype.load=async function(){void 0===this.byteLength&&(this.byteLength=await qa(this.filename));this.onload&&this.onload(Object.create(null))};ya.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};ya.prototype.get=function(a,b,c,d){var e=this.get_from_cache(a,b);if(e)c(e);else{var f=a,
29
29
  g=b;this.fixed_chunk_size&&(f=a-a%this.fixed_chunk_size,g=Math.ceil((a-f+b)/this.fixed_chunk_size)*this.fixed_chunk_size);pa(this.filename,{done:function(h){h=new Uint8Array(h);this.handle_read(f,g,h);f===a&&g===b?c(h):c(h.subarray(a-f,a-f+b))}.bind(this),range:{start:f,length:g},signal:d?.signal})}};ya.prototype.set=function(a,b,c){a/=256;for(var d=b.length/256,e=0;e<d;e++){var f=this.block_cache.get(a+e);if(void 0===f)f=b.slice(256*e,256*(e+1)),this.block_cache.set(a+e,f);else{const g=b.subarray(256*
30
30
  e,256*(e+1));f.set(g)}this.block_cache_is_write.add(a+e)}c()};ya.prototype.handle_read=function(a,b,c){a/=256;b/=256;for(var d=0;d<b;d++){const e=this.block_cache.get(a+d);e?c.set(e,256*d):this.cache_reads&&this.block_cache.set(a+d,c.slice(256*d,256*(d+1)))}};ya.prototype.get_buffer=function(a){a()};ya.prototype.get_state=function(){const a=[],b=[];for(const [c,d]of this.block_cache)isFinite(c),this.block_cache_is_write.has(c)&&b.push([c,d]);a[0]=b;return a};ya.prototype.set_state=function(a){a=a[0];
@@ -33,9 +33,9 @@ this.block_cache.clear();this.block_cache_is_write.clear();for(const [b,c]of a)i
33
33
  this.basename+(g+p+"").padStart(8,"0")+this.extension:this.basename+f+"-"+(f+this.fixed_chunk_size)+this.extension;(f=this.get_from_cache(f,this.fixed_chunk_size))?(m.set(f,p*this.fixed_chunk_size),n++,n===l&&c(m.subarray(h,h+b))):pa(e,{done:async function(q){q=new Uint8Array(q);this.is_zstd&&(q=await this.zstd_decompress(this.fixed_chunk_size,q),q=new Uint8Array(q));m.set(q,p*this.fixed_chunk_size);this.handle_read((g+p)*this.fixed_chunk_size,this.fixed_chunk_size|0,q);n++;n===l&&c(m.subarray(h,
34
34
  h+b))}.bind(this),signal:d?.signal})}}else pa(this.basename+a+"-"+(a+b)+this.extension,{done:function(g){g=new Uint8Array(g);this.handle_read(a,b,g);c(g)}.bind(this),signal:d?.signal})};za.prototype.get_from_cache=ya.prototype.get_from_cache;za.prototype.set=ya.prototype.set;za.prototype.handle_read=ya.prototype.handle_read;za.prototype.get_state=ya.prototype.get_state;za.prototype.set_state=ya.prototype.set_state;function Aa(a){this.file=a;this.byteLength=a.size;1073741824<a.size&&console.warn("SyncFileBuffer: Allocating buffer of "+
35
35
  (a.size>>20)+" MB ...");this.buffer=new ArrayBuffer(a.size);this.onprogress=this.onload=void 0}Aa.prototype.load=function(){this.load_next(0)};Aa.prototype.load_next=function(a){var b=new FileReader;b.onload=function(d){d=new Uint8Array(d.target.result);(new Uint8Array(this.buffer,a)).set(d);this.load_next(a+4194304)}.bind(this);if(this.onprogress)this.onprogress({loaded:a,total:this.byteLength,lengthComputable:!0});if(a<this.byteLength){var c=this.file.slice(a,Math.min(a+4194304,this.byteLength));
36
- b.readAsArrayBuffer(c)}else this.file=void 0,this.onload&&this.onload({buffer:this.buffer})};Aa.prototype.get=z.prototype.get;Aa.prototype.set=z.prototype.set;Aa.prototype.get_buffer=z.prototype.get_buffer;Aa.prototype.get_state=z.prototype.get_state;Aa.prototype.set_state=z.prototype.set_state;function Ba(a){this.file=a;this.byteLength=a.size;this.block_cache=new Map;this.block_cache_is_write=new Set;this.onprogress=this.onload=void 0}Ba.prototype.load=function(){this.onload&&this.onload(Object.create(null))};
36
+ b.readAsArrayBuffer(c)}else this.file=void 0,this.onload&&this.onload({buffer:this.buffer})};Aa.prototype.get=A.prototype.get;Aa.prototype.set=A.prototype.set;Aa.prototype.get_buffer=A.prototype.get_buffer;Aa.prototype.get_state=A.prototype.get_state;Aa.prototype.set_state=A.prototype.set_state;function Ba(a){this.file=a;this.byteLength=a.size;this.block_cache=new Map;this.block_cache_is_write=new Set;this.onprogress=this.onload=void 0}Ba.prototype.load=function(){this.onload&&this.onload(Object.create(null))};
37
37
  Ba.prototype.get=function(a,b,c){var d=this.get_from_cache(a,b);d?c(d):(d=new FileReader,d.onload=function(e){e=new Uint8Array(e.target.result);this.handle_read(a,b,e);c(e)}.bind(this),d.readAsArrayBuffer(this.file.slice(a,a+b)))};Ba.prototype.get_from_cache=ya.prototype.get_from_cache;Ba.prototype.set=ya.prototype.set;Ba.prototype.handle_read=ya.prototype.handle_read;Ba.prototype.get_state=ya.prototype.get_state;Ba.prototype.set_state=ya.prototype.set_state;Ba.prototype.get_buffer=function(a){a()};
38
- Ba.prototype.get_as_file=function(a){for(var b=[],c=Array.from(this.block_cache.keys()).sort(function(h,l){return h-l}),d=0,e=0;e<c.length;e++){var f=c[e],g=this.block_cache.get(f);f*=256;f!==d&&(b.push(this.file.slice(d,f)),d=f);b.push(g);d+=g.length}d!==this.file.size&&b.push(this.file.slice(d));return new File(b,a)};function Ca(a,b){if(a.buffer instanceof ArrayBuffer)return new z(a.buffer);if("undefined"!==typeof File&&a.buffer instanceof File)return b=a.async,void 0===b&&(b=268435456<=a.buffer.size),
38
+ Ba.prototype.get_as_file=function(a){for(var b=[],c=Array.from(this.block_cache.keys()).sort(function(h,l){return h-l}),d=0,e=0;e<c.length;e++){var f=c[e],g=this.block_cache.get(f);f*=256;f!==d&&(b.push(this.file.slice(d,f)),d=f);b.push(g);d+=g.length}d!==this.file.size&&b.push(this.file.slice(d));return new File(b,a)};function Ca(a,b){if(a.buffer instanceof ArrayBuffer)return new A(a.buffer);if("undefined"!==typeof File&&a.buffer instanceof File)return b=a.async,void 0===b&&(b=268435456<=a.buffer.size),
39
39
  b?new Ba(a.buffer):new Aa(a.buffer);if(a.url)return a.use_parts?new za(a.url,a.size,a.fixed_chunk_size,!1,b):new ya(a.url,a.size,a.fixed_chunk_size)}function B(a){this.cpu=a;this.channel_page=new Uint8Array(8);this.channel_pagehi=new Uint8Array(8);this.channel_addr=new Uint16Array(8);this.channel_addr_init=new Uint16Array(8);this.channel_count=new Uint16Array(8);this.channel_count_init=new Uint16Array(8);this.channel_mask=new Uint8Array(8);this.channel_mode=new Uint8Array(8);this.unmask_listeners=
40
40
  [];this.lsb_msb_flipflop=0;a=a.io;a.register_write(0,this,this.port_addr_write.bind(this,0));a.register_write(2,this,this.port_addr_write.bind(this,1));a.register_write(4,this,this.port_addr_write.bind(this,2));a.register_write(6,this,this.port_addr_write.bind(this,3));a.register_write(1,this,this.port_count_write.bind(this,0));a.register_write(3,this,this.port_count_write.bind(this,1));a.register_write(5,this,this.port_count_write.bind(this,2));a.register_write(7,this,this.port_count_write.bind(this,
41
41
  3));a.register_read(0,this,this.port_addr_read.bind(this,0));a.register_read(2,this,this.port_addr_read.bind(this,1));a.register_read(4,this,this.port_addr_read.bind(this,2));a.register_read(6,this,this.port_addr_read.bind(this,3));a.register_read(1,this,this.port_count_read.bind(this,0));a.register_read(3,this,this.port_count_read.bind(this,1));a.register_read(5,this,this.port_count_read.bind(this,2));a.register_read(7,this,this.port_count_read.bind(this,3));a.register_write(192,this,this.port_addr_write.bind(this,
@@ -63,44 +63,44 @@ b=b.read16.call(b.device,a);(0>b||65536<=b)&&y(a);return b};Da.prototype.port_re
63
63
  96:"PORT_PS2_DATA",97:"PORT_PS2_CTRLB",100:"PORT_PS2_STATUS",112:"PORT_CMOS_INDEX",113:"PORT_CMOS_DATA",128:"PORT_DIAG",129:"PORT_DMA_PAGE_2",146:"PORT_A20",160:"PORT_PIC2_CMD",161:"PORT_PIC2_DATA",178:"PORT_SMI_CMD",179:"PORT_SMI_STATUS",212:"PORT_DMA2_MASK_REG",214:"PORT_DMA2_MODE_REG",218:"PORT_DMA2_MASTER_CLEAR",240:"PORT_MATH_CLEAR",368:"PORT_ATA2_CMD_BASE",496:"PORT_ATA1_CMD_BASE",632:"PORT_LPT2",744:"PORT_SERIAL4",760:"PORT_SERIAL2",884:"PORT_ATA2_CTRL_BASE",888:"PORT_LPT1",1E3:"PORT_SERIAL3",
64
64
  1008:"PORT_FD_BASE",1010:"PORT_FD_DOR",1012:"PORT_FD_STATUS",1013:"PORT_FD_DATA",1014:"PORT_HD_DATA",1015:"PORT_FD_DIR",1016:"PORT_SERIAL1",3320:"PORT_PCI_CMD",3321:"PORT_PCI_REBOOT",3324:"PORT_PCI_DATA",1026:"PORT_BIOS_DEBUG",1296:"PORT_QEMU_CFG_CTL",1297:"PORT_QEMU_CFG_DATA",45056:"PORT_ACPI_PM_BASE",45312:"PORT_SMB_BASE",35072:"PORT_BIOS_APM"};Da.prototype.get_port_description=function(a){return Ea[a]?" ("+Ea[a]+")":""};var Ha={};function Ia(){this.listeners={};this.pair=void 0}Ia.prototype.register=
65
65
  function(a,b,c){var d=this.listeners[a];void 0===d&&(d=this.listeners[a]=[]);d.push({fn:b,this_value:c})};Ia.prototype.unregister=function(a,b){var c=this.listeners[a];void 0!==c&&(this.listeners[a]=c.filter(function(d){return d.fn!==b}))};Ia.prototype.send=function(a,b){if(this.pair&&(a=this.pair.listeners[a],void 0!==a))for(var c=0;c<a.length;c++){var d=a[c];d.fn.call(d.this_value,b)}};Ia.prototype.send_async=function(a,b){setTimeout(this.send.bind(this,a,b),0)};Ha.create=function(){var a=new Ia,
66
- b=new Ia;a.pair=b;b.pair=a;return[a,b]};var Ja=new Uint8Array(256),Ka=[],La=[],Oa=[],Pa=new Uint8Array(256),Qa=[];function D(a,b){this.cpu=a;this.bus=b;this.write_buffer=new la(64);this.read_buffer=new la(64);this.mixer_current_address=this.command_size=this.command=this.read_buffer_lastvalue=0;this.mixer_registers=new Uint8Array(256);this.mixer_reset();this.dummy_speaker_enabled=!1;this.test_register=0;this.dsp_signed=this.dsp_16bit=this.dsp_stereo=this.dsp_highspeed=!1;this.dac_buffers=[new ma(65536),
67
- new ma(65536)];this.dma=a.devices.dma;this.dma_channel=this.dma_irq=this.dma_bytes_block=this.dma_bytes_left=this.dma_bytes_count=this.dma_sample_count=0;this.dma_channel_8bit=1;this.dma_channel_16bit=5;this.dma_autoinit=!1;this.dma_buffer=new ArrayBuffer(65536);this.dma_buffer_int8=new Int8Array(this.dma_buffer);this.dma_buffer_uint8=new Uint8Array(this.dma_buffer);this.dma_buffer_int16=new Int16Array(this.dma_buffer);this.dma_buffer_uint16=new Uint16Array(this.dma_buffer);this.dma_syncbuffer=new z(this.dma_buffer);
66
+ b=new Ia;a.pair=b;b.pair=a;return[a,b]};var Ja=new Uint8Array(256),Ka=[],La=[],Oa=[],Pa=new Uint8Array(256),Qa=[];function C(a,b){this.cpu=a;this.bus=b;this.write_buffer=new la(64);this.read_buffer=new la(64);this.mixer_current_address=this.command_size=this.command=this.read_buffer_lastvalue=0;this.mixer_registers=new Uint8Array(256);this.mixer_reset();this.dummy_speaker_enabled=!1;this.test_register=0;this.dsp_signed=this.dsp_16bit=this.dsp_stereo=this.dsp_highspeed=!1;this.dac_buffers=[new ma(65536),
67
+ new ma(65536)];this.dma=a.devices.dma;this.dma_channel=this.dma_irq=this.dma_bytes_block=this.dma_bytes_left=this.dma_bytes_count=this.dma_sample_count=0;this.dma_channel_8bit=1;this.dma_channel_16bit=5;this.dma_autoinit=!1;this.dma_buffer=new ArrayBuffer(65536);this.dma_buffer_int8=new Int8Array(this.dma_buffer);this.dma_buffer_uint8=new Uint8Array(this.dma_buffer);this.dma_buffer_int16=new Int16Array(this.dma_buffer);this.dma_buffer_uint16=new Uint16Array(this.dma_buffer);this.dma_syncbuffer=new A(this.dma_buffer);
68
68
  this.dma_paused=this.dma_waiting_transfer=!1;this.sampling_rate=22050;b.send("dac-tell-sampling-rate",this.sampling_rate);this.bytes_per_sample=1;this.e2_value=170;this.e2_count=0;this.asp_registers=new Uint8Array(256);this.mpu_read_buffer=new la(64);this.fm_current_address1=this.fm_current_address0=this.mpu_read_buffer_lastvalue=0;this.fm_waveform_select_enable=!1;this.irq=5;this.irq_triggered=new Uint8Array(16);a.io.register_read_consecutive(544,this,this.port2x0_read,this.port2x1_read,this.port2x2_read,
69
69
  this.port2x3_read);a.io.register_read_consecutive(904,this,this.port2x0_read,this.port2x1_read);a.io.register_read_consecutive(548,this,this.port2x4_read,this.port2x5_read);a.io.register_read(550,this,this.port2x6_read);a.io.register_read(551,this,this.port2x7_read);a.io.register_read(552,this,this.port2x8_read);a.io.register_read(553,this,this.port2x9_read);a.io.register_read(554,this,this.port2xA_read);a.io.register_read(555,this,this.port2xB_read);a.io.register_read(556,this,this.port2xC_read);
70
70
  a.io.register_read(557,this,this.port2xD_read);a.io.register_read_consecutive(558,this,this.port2xE_read,this.port2xF_read);a.io.register_write_consecutive(544,this,this.port2x0_write,this.port2x1_write,this.port2x2_write,this.port2x3_write);a.io.register_write_consecutive(904,this,this.port2x0_write,this.port2x1_write);a.io.register_write_consecutive(548,this,this.port2x4_write,this.port2x5_write);a.io.register_write(550,this,this.port2x6_write);a.io.register_write(551,this,this.port2x7_write);a.io.register_write_consecutive(552,
71
71
  this,this.port2x8_write,this.port2x9_write);a.io.register_write(554,this,this.port2xA_write);a.io.register_write(555,this,this.port2xB_write);a.io.register_write(556,this,this.port2xC_write);a.io.register_write(557,this,this.port2xD_write);a.io.register_write(558,this,this.port2xE_write);a.io.register_write(559,this,this.port2xF_write);a.io.register_read_consecutive(816,this,this.port3x0_read,this.port3x1_read);a.io.register_write_consecutive(816,this,this.port3x0_write,this.port3x1_write);this.dma.on_unmask(this.dma_on_unmask,
72
- this);b.register("dac-request-data",function(){this.dac_handle_request()},this);b.register("speaker-has-initialized",function(){this.mixer_reset()},this);b.send("speaker-confirm-initialized");this.dsp_reset()}D.prototype.dsp_reset=function(){this.write_buffer.clear();this.read_buffer.clear();this.command_size=this.command=0;this.dummy_speaker_enabled=!1;this.test_register=0;this.dsp_signed=this.dsp_16bit=this.dsp_stereo=this.dsp_highspeed=!1;this.dac_buffers[0].clear();this.dac_buffers[1].clear();
73
- this.dma_channel=this.dma_irq=this.dma_bytes_block=this.dma_bytes_left=this.dma_bytes_count=this.dma_sample_count=0;this.dma_autoinit=!1;this.dma_buffer_uint8.fill(0);this.dma_paused=this.dma_waiting_transfer=!1;this.e2_value=170;this.e2_count=0;this.sampling_rate=22050;this.bytes_per_sample=1;this.lower_irq(1);this.irq_triggered.fill(0);this.asp_registers.fill(0);this.asp_registers[5]=1;this.asp_registers[9]=248};D.prototype.get_state=function(){var a=[];a[2]=this.read_buffer_lastvalue;a[3]=this.command;
72
+ this);b.register("dac-request-data",function(){this.dac_handle_request()},this);b.register("speaker-has-initialized",function(){this.mixer_reset()},this);b.send("speaker-confirm-initialized");this.dsp_reset()}C.prototype.dsp_reset=function(){this.write_buffer.clear();this.read_buffer.clear();this.command_size=this.command=0;this.dummy_speaker_enabled=!1;this.test_register=0;this.dsp_signed=this.dsp_16bit=this.dsp_stereo=this.dsp_highspeed=!1;this.dac_buffers[0].clear();this.dac_buffers[1].clear();
73
+ this.dma_channel=this.dma_irq=this.dma_bytes_block=this.dma_bytes_left=this.dma_bytes_count=this.dma_sample_count=0;this.dma_autoinit=!1;this.dma_buffer_uint8.fill(0);this.dma_paused=this.dma_waiting_transfer=!1;this.e2_value=170;this.e2_count=0;this.sampling_rate=22050;this.bytes_per_sample=1;this.lower_irq(1);this.irq_triggered.fill(0);this.asp_registers.fill(0);this.asp_registers[5]=1;this.asp_registers[9]=248};C.prototype.get_state=function(){var a=[];a[2]=this.read_buffer_lastvalue;a[3]=this.command;
74
74
  a[4]=this.command_size;a[5]=this.mixer_current_address;a[6]=this.mixer_registers;a[7]=this.dummy_speaker_enabled;a[8]=this.test_register;a[9]=this.dsp_highspeed;a[10]=this.dsp_stereo;a[11]=this.dsp_16bit;a[12]=this.dsp_signed;a[15]=this.dma_sample_count;a[16]=this.dma_bytes_count;a[17]=this.dma_bytes_left;a[18]=this.dma_bytes_block;a[19]=this.dma_irq;a[20]=this.dma_channel;a[21]=this.dma_channel_8bit;a[22]=this.dma_channel_16bit;a[23]=this.dma_autoinit;a[24]=this.dma_buffer_uint8;a[25]=this.dma_waiting_transfer;
75
- a[26]=this.dma_paused;a[27]=this.sampling_rate;a[28]=this.bytes_per_sample;a[29]=this.e2_value;a[30]=this.e2_count;a[31]=this.asp_registers;a[33]=this.mpu_read_buffer_last_value;a[34]=this.irq;a[35]=this.irq_triggered;return a};D.prototype.set_state=function(a){this.read_buffer_lastvalue=a[2];this.command=a[3];this.command_size=a[4];this.mixer_current_address=a[5];this.mixer_registers=a[6];this.mixer_full_update();this.dummy_speaker_enabled=a[7];this.test_register=a[8];this.dsp_highspeed=a[9];this.dsp_stereo=
75
+ a[26]=this.dma_paused;a[27]=this.sampling_rate;a[28]=this.bytes_per_sample;a[29]=this.e2_value;a[30]=this.e2_count;a[31]=this.asp_registers;a[33]=this.mpu_read_buffer_last_value;a[34]=this.irq;a[35]=this.irq_triggered;return a};C.prototype.set_state=function(a){this.read_buffer_lastvalue=a[2];this.command=a[3];this.command_size=a[4];this.mixer_current_address=a[5];this.mixer_registers=a[6];this.mixer_full_update();this.dummy_speaker_enabled=a[7];this.test_register=a[8];this.dsp_highspeed=a[9];this.dsp_stereo=
76
76
  a[10];this.dsp_16bit=a[11];this.dsp_signed=a[12];this.dma_sample_count=a[15];this.dma_bytes_count=a[16];this.dma_bytes_left=a[17];this.dma_bytes_block=a[18];this.dma_irq=a[19];this.dma_channel=a[20];this.dma_channel_8bit=a[21];this.dma_channel_16bit=a[22];this.dma_autoinit=a[23];this.dma_buffer_uint8=a[24];this.dma_waiting_transfer=a[25];this.dma_paused=a[26];this.sampling_rate=a[27];this.bytes_per_sample=a[28];this.e2_value=a[29];this.e2_count=a[30];this.asp_registers=a[31];this.mpu_read_buffer_last_value=
77
- a[33];this.irq=a[34];this.irq_triggered=a[35];this.dma_buffer=this.dma_buffer_uint8.buffer;this.dma_buffer_int8=new Int8Array(this.dma_buffer);this.dma_buffer_int16=new Int16Array(this.dma_buffer);this.dma_buffer_uint16=new Uint16Array(this.dma_buffer);this.dma_syncbuffer=new z(this.dma_buffer);this.dma_paused?this.bus.send("dac-disable"):this.bus.send("dac-enable")};D.prototype.port2x0_read=function(){return 255};D.prototype.port2x1_read=function(){return 255};D.prototype.port2x2_read=function(){return 255};
78
- D.prototype.port2x3_read=function(){return 255};D.prototype.port2x4_read=function(){return this.mixer_current_address};D.prototype.port2x5_read=function(){return this.mixer_read(this.mixer_current_address)};D.prototype.port2x6_read=function(){return 255};D.prototype.port2x7_read=function(){return 255};D.prototype.port2x8_read=function(){return 255};D.prototype.port2x9_read=function(){return 255};D.prototype.port2xA_read=function(){this.read_buffer.length&&(this.read_buffer_lastvalue=this.read_buffer.shift());
79
- y(this.read_buffer_lastvalue);String.fromCharCode(this.read_buffer_lastvalue);return this.read_buffer_lastvalue};D.prototype.port2xB_read=function(){return 255};D.prototype.port2xC_read=function(){return 127};D.prototype.port2xD_read=function(){return 255};D.prototype.port2xE_read=function(){this.irq_triggered[1]&&this.lower_irq(1);return(this.read_buffer.length&&!this.dsp_highspeed)<<7|127};D.prototype.port2xF_read=function(){this.lower_irq(2);return 0};D.prototype.port2x0_write=function(a){y(a);
80
- this.fm_current_address0=0};D.prototype.port2x1_write=function(a){y(a);var b=Qa[this.fm_current_address0];b||(b=this.fm_default_write);b.call(this,a,0,this.fm_current_address0)};D.prototype.port2x2_write=function(a){y(a);this.fm_current_address1=0};D.prototype.port2x3_write=function(a){y(a);var b=Qa[this.fm_current_address1];b||(b=this.fm_default_write);b.call(this,a,1,this.fm_current_address1)};D.prototype.port2x4_write=function(a){y(a);this.mixer_current_address=a};D.prototype.port2x5_write=function(a){y(a);
81
- this.mixer_write(this.mixer_current_address,a)};D.prototype.port2x6_write=function(a){y(a);this.dsp_highspeed?this.dsp_highspeed=!1:a&&this.dsp_reset();this.read_buffer.clear();this.read_buffer.push(170)};D.prototype.port2x7_write=function(){};D.prototype.port2x8_write=function(){};D.prototype.port2x9_write=function(){};D.prototype.port2xA_write=function(){};D.prototype.port2xB_write=function(){};D.prototype.port2xC_write=function(a){0===this.command?(y(a),this.command=a,this.write_buffer.clear(),
82
- this.command_size=Ja[a]):(y(a),this.write_buffer.push(a));this.write_buffer.length>=this.command_size&&this.command_do()};D.prototype.port2xD_write=function(){};D.prototype.port2xE_write=function(){};D.prototype.port2xF_write=function(){};D.prototype.port3x0_read=function(){this.mpu_read_buffer.length&&(this.mpu_read_buffer_lastvalue=this.mpu_read_buffer.shift());y(this.mpu_read_buffer_lastvalue);return this.mpu_read_buffer_lastvalue};D.prototype.port3x0_write=function(a){y(a)};D.prototype.port3x1_read=
83
- function(){return 0|128*!this.mpu_read_buffer.length};D.prototype.port3x1_write=function(a){y(a);255===a&&(this.mpu_read_buffer.clear(),this.mpu_read_buffer.push(254))};D.prototype.command_do=function(){var a=Ka[this.command];a||(a=this.dsp_default_handler);a.call(this);this.command_size=this.command=0;this.write_buffer.clear()};D.prototype.dsp_default_handler=function(){y(this.command)};function E(a,b,c){c||(c=D.prototype.dsp_default_handler);for(var d=0;d<a.length;d++)Ja[a[d]]=b,Ka[a[d]]=c}function Ra(a){for(var b=
84
- [],c=0;16>c;c++)b.push(a+c);return b}E([14],2,function(){this.asp_registers[this.write_buffer.shift()]=this.write_buffer.shift()});E([15],1,function(){this.read_buffer.clear();this.read_buffer.push(this.asp_registers[this.write_buffer.shift()])});E([16],1,function(){var a=this.write_buffer.shift();a=Sa(a/127.5+-1,-1,1);this.dac_buffers[0].push(a);this.dac_buffers[1].push(a);this.bus.send("dac-enable")});E([20,21],2,function(){this.dma_irq=1;this.dma_channel=this.dma_channel_8bit;this.dsp_highspeed=
85
- this.dsp_16bit=this.dsp_signed=this.dma_autoinit=!1;this.dma_transfer_size_set();this.dma_transfer_start()});E([22],2);E([23],2);E([28],0,function(){this.dma_irq=1;this.dma_channel=this.dma_channel_8bit;this.dma_autoinit=!0;this.dsp_highspeed=this.dsp_16bit=this.dsp_signed=!1;this.dma_transfer_start()});E([31],0);E([32],0,function(){this.read_buffer.clear();this.read_buffer.push(127)});E([36],2);E([44],0);E([48],0);E([49],0);E([52],0);E([53],0);E([54],0);E([55],0);E([56],0);E([64],1,function(){this.sampling_rate_change(1E6/
86
- (256-this.write_buffer.shift())/this.get_channel_count())});E([65,66],2,function(){this.sampling_rate_change(this.write_buffer.shift()<<8|this.write_buffer.shift())});E([72],2,function(){this.dma_transfer_size_set()});E([116],2);E([117],2);E([118],2);E([119],2);E([125],0);E([127],0);E([128],2);E([144],0,function(){this.dma_irq=1;this.dma_channel=this.dma_channel_8bit;this.dma_autoinit=!0;this.dsp_signed=!1;this.dsp_highspeed=!0;this.dsp_16bit=!1;this.dma_transfer_start()});E([145],0);E([152],0);E([153],
87
- 0);E([160],0);E([168],0);E(Ra(176),3,function(){if(this.command&8)this.dsp_default_handler();else{var a=this.write_buffer.shift();this.dma_irq=2;this.dma_channel=this.dma_channel_16bit;this.dma_autoinit=!!(this.command&4);this.dsp_signed=!!(a&16);this.dsp_stereo=!!(a&32);this.dsp_16bit=!0;this.dma_transfer_size_set();this.dma_transfer_start()}});E(Ra(192),3,function(){if(this.command&8)this.dsp_default_handler();else{var a=this.write_buffer.shift();this.dma_irq=1;this.dma_channel=this.dma_channel_8bit;
88
- this.dma_autoinit=!!(this.command&4);this.dsp_signed=!!(a&16);this.dsp_stereo=!!(a&32);this.dsp_16bit=!1;this.dma_transfer_size_set();this.dma_transfer_start()}});E([208],0,function(){this.dma_paused=!0;this.bus.send("dac-disable")});E([209],0,function(){this.dummy_speaker_enabled=!0});E([211],0,function(){this.dummy_speaker_enabled=!1});E([212],0,function(){this.dma_paused=!1;this.bus.send("dac-enable")});E([213],0,function(){this.dma_paused=!0;this.bus.send("dac-disable")});E([214],0,function(){this.dma_paused=
89
- !1;this.bus.send("dac-enable")});E([216],0,function(){this.read_buffer.clear();this.read_buffer.push(255*this.dummy_speaker_enabled)});E([217,218],0,function(){this.dma_autoinit=!1});E([224],1,function(){this.read_buffer.clear();this.read_buffer.push(~this.write_buffer.shift())});E([225],0,function(){this.read_buffer.clear();this.read_buffer.push(4);this.read_buffer.push(5)});E([226],1);E([227],0,function(){this.read_buffer.clear();for(var a=0;44>a;a++)this.read_buffer.push("COPYRIGHT (C) CREATIVE TECHNOLOGY LTD, 1992.".charCodeAt(a));
90
- this.read_buffer.push(0)});E([228],1,function(){this.test_register=this.write_buffer.shift()});E([232],0,function(){this.read_buffer.clear();this.read_buffer.push(this.test_register)});E([242],0,function(){this.raise_irq(1)});E([243],0,function(){this.raise_irq(2)});var Ta=new Uint8Array(256);Ta[14]=255;Ta[15]=7;Ta[55]=56;E([249],1,function(){var a=this.write_buffer.shift();this.read_buffer.clear();this.read_buffer.push(Ta[a])});D.prototype.mixer_read=function(a){var b=La[a];b?b=b.call(this):(b=this.mixer_registers[a],
91
- y(a),y(b));return b};D.prototype.mixer_write=function(a,b){var c=Oa[a];c?c.call(this,b):(y(a),y(b))};D.prototype.mixer_default_read=function(){y(this.mixer_current_address);return this.mixer_registers[this.mixer_current_address]};D.prototype.mixer_default_write=function(a){y(this.mixer_current_address);y(a);this.mixer_registers[this.mixer_current_address]=a};D.prototype.mixer_reset=function(){this.mixer_registers[4]=204;this.mixer_registers[34]=204;this.mixer_registers[38]=204;this.mixer_registers[40]=
77
+ a[33];this.irq=a[34];this.irq_triggered=a[35];this.dma_buffer=this.dma_buffer_uint8.buffer;this.dma_buffer_int8=new Int8Array(this.dma_buffer);this.dma_buffer_int16=new Int16Array(this.dma_buffer);this.dma_buffer_uint16=new Uint16Array(this.dma_buffer);this.dma_syncbuffer=new A(this.dma_buffer);this.dma_paused?this.bus.send("dac-disable"):this.bus.send("dac-enable")};C.prototype.port2x0_read=function(){return 255};C.prototype.port2x1_read=function(){return 255};C.prototype.port2x2_read=function(){return 255};
78
+ C.prototype.port2x3_read=function(){return 255};C.prototype.port2x4_read=function(){return this.mixer_current_address};C.prototype.port2x5_read=function(){return this.mixer_read(this.mixer_current_address)};C.prototype.port2x6_read=function(){return 255};C.prototype.port2x7_read=function(){return 255};C.prototype.port2x8_read=function(){return 255};C.prototype.port2x9_read=function(){return 255};C.prototype.port2xA_read=function(){this.read_buffer.length&&(this.read_buffer_lastvalue=this.read_buffer.shift());
79
+ y(this.read_buffer_lastvalue);String.fromCharCode(this.read_buffer_lastvalue);return this.read_buffer_lastvalue};C.prototype.port2xB_read=function(){return 255};C.prototype.port2xC_read=function(){return 127};C.prototype.port2xD_read=function(){return 255};C.prototype.port2xE_read=function(){this.irq_triggered[1]&&this.lower_irq(1);return(this.read_buffer.length&&!this.dsp_highspeed)<<7|127};C.prototype.port2xF_read=function(){this.lower_irq(2);return 0};C.prototype.port2x0_write=function(a){y(a);
80
+ this.fm_current_address0=0};C.prototype.port2x1_write=function(a){y(a);var b=Qa[this.fm_current_address0];b||(b=this.fm_default_write);b.call(this,a,0,this.fm_current_address0)};C.prototype.port2x2_write=function(a){y(a);this.fm_current_address1=0};C.prototype.port2x3_write=function(a){y(a);var b=Qa[this.fm_current_address1];b||(b=this.fm_default_write);b.call(this,a,1,this.fm_current_address1)};C.prototype.port2x4_write=function(a){y(a);this.mixer_current_address=a};C.prototype.port2x5_write=function(a){y(a);
81
+ this.mixer_write(this.mixer_current_address,a)};C.prototype.port2x6_write=function(a){y(a);this.dsp_highspeed?this.dsp_highspeed=!1:a&&this.dsp_reset();this.read_buffer.clear();this.read_buffer.push(170)};C.prototype.port2x7_write=function(){};C.prototype.port2x8_write=function(){};C.prototype.port2x9_write=function(){};C.prototype.port2xA_write=function(){};C.prototype.port2xB_write=function(){};C.prototype.port2xC_write=function(a){0===this.command?(y(a),this.command=a,this.write_buffer.clear(),
82
+ this.command_size=Ja[a]):(y(a),this.write_buffer.push(a));this.write_buffer.length>=this.command_size&&this.command_do()};C.prototype.port2xD_write=function(){};C.prototype.port2xE_write=function(){};C.prototype.port2xF_write=function(){};C.prototype.port3x0_read=function(){this.mpu_read_buffer.length&&(this.mpu_read_buffer_lastvalue=this.mpu_read_buffer.shift());y(this.mpu_read_buffer_lastvalue);return this.mpu_read_buffer_lastvalue};C.prototype.port3x0_write=function(a){y(a)};C.prototype.port3x1_read=
83
+ function(){return 0|128*!this.mpu_read_buffer.length};C.prototype.port3x1_write=function(a){y(a);255===a&&(this.mpu_read_buffer.clear(),this.mpu_read_buffer.push(254))};C.prototype.command_do=function(){var a=Ka[this.command];a||(a=this.dsp_default_handler);a.call(this);this.command_size=this.command=0;this.write_buffer.clear()};C.prototype.dsp_default_handler=function(){y(this.command)};function D(a,b,c){c||(c=C.prototype.dsp_default_handler);for(var d=0;d<a.length;d++)Ja[a[d]]=b,Ka[a[d]]=c}function Ra(a){for(var b=
84
+ [],c=0;16>c;c++)b.push(a+c);return b}D([14],2,function(){this.asp_registers[this.write_buffer.shift()]=this.write_buffer.shift()});D([15],1,function(){this.read_buffer.clear();this.read_buffer.push(this.asp_registers[this.write_buffer.shift()])});D([16],1,function(){var a=this.write_buffer.shift();a=Sa(a/127.5+-1,-1,1);this.dac_buffers[0].push(a);this.dac_buffers[1].push(a);this.bus.send("dac-enable")});D([20,21],2,function(){this.dma_irq=1;this.dma_channel=this.dma_channel_8bit;this.dsp_highspeed=
85
+ this.dsp_16bit=this.dsp_signed=this.dma_autoinit=!1;this.dma_transfer_size_set();this.dma_transfer_start()});D([22],2);D([23],2);D([28],0,function(){this.dma_irq=1;this.dma_channel=this.dma_channel_8bit;this.dma_autoinit=!0;this.dsp_highspeed=this.dsp_16bit=this.dsp_signed=!1;this.dma_transfer_start()});D([31],0);D([32],0,function(){this.read_buffer.clear();this.read_buffer.push(127)});D([36],2);D([44],0);D([48],0);D([49],0);D([52],0);D([53],0);D([54],0);D([55],0);D([56],0);D([64],1,function(){this.sampling_rate_change(1E6/
86
+ (256-this.write_buffer.shift())/this.get_channel_count())});D([65,66],2,function(){this.sampling_rate_change(this.write_buffer.shift()<<8|this.write_buffer.shift())});D([72],2,function(){this.dma_transfer_size_set()});D([116],2);D([117],2);D([118],2);D([119],2);D([125],0);D([127],0);D([128],2);D([144],0,function(){this.dma_irq=1;this.dma_channel=this.dma_channel_8bit;this.dma_autoinit=!0;this.dsp_signed=!1;this.dsp_highspeed=!0;this.dsp_16bit=!1;this.dma_transfer_start()});D([145],0);D([152],0);D([153],
87
+ 0);D([160],0);D([168],0);D(Ra(176),3,function(){if(this.command&8)this.dsp_default_handler();else{var a=this.write_buffer.shift();this.dma_irq=2;this.dma_channel=this.dma_channel_16bit;this.dma_autoinit=!!(this.command&4);this.dsp_signed=!!(a&16);this.dsp_stereo=!!(a&32);this.dsp_16bit=!0;this.dma_transfer_size_set();this.dma_transfer_start()}});D(Ra(192),3,function(){if(this.command&8)this.dsp_default_handler();else{var a=this.write_buffer.shift();this.dma_irq=1;this.dma_channel=this.dma_channel_8bit;
88
+ this.dma_autoinit=!!(this.command&4);this.dsp_signed=!!(a&16);this.dsp_stereo=!!(a&32);this.dsp_16bit=!1;this.dma_transfer_size_set();this.dma_transfer_start()}});D([208],0,function(){this.dma_paused=!0;this.bus.send("dac-disable")});D([209],0,function(){this.dummy_speaker_enabled=!0});D([211],0,function(){this.dummy_speaker_enabled=!1});D([212],0,function(){this.dma_paused=!1;this.bus.send("dac-enable")});D([213],0,function(){this.dma_paused=!0;this.bus.send("dac-disable")});D([214],0,function(){this.dma_paused=
89
+ !1;this.bus.send("dac-enable")});D([216],0,function(){this.read_buffer.clear();this.read_buffer.push(255*this.dummy_speaker_enabled)});D([217,218],0,function(){this.dma_autoinit=!1});D([224],1,function(){this.read_buffer.clear();this.read_buffer.push(~this.write_buffer.shift())});D([225],0,function(){this.read_buffer.clear();this.read_buffer.push(4);this.read_buffer.push(5)});D([226],1);D([227],0,function(){this.read_buffer.clear();for(var a=0;44>a;a++)this.read_buffer.push("COPYRIGHT (C) CREATIVE TECHNOLOGY LTD, 1992.".charCodeAt(a));
90
+ this.read_buffer.push(0)});D([228],1,function(){this.test_register=this.write_buffer.shift()});D([232],0,function(){this.read_buffer.clear();this.read_buffer.push(this.test_register)});D([242],0,function(){this.raise_irq(1)});D([243],0,function(){this.raise_irq(2)});var Ta=new Uint8Array(256);Ta[14]=255;Ta[15]=7;Ta[55]=56;D([249],1,function(){var a=this.write_buffer.shift();this.read_buffer.clear();this.read_buffer.push(Ta[a])});C.prototype.mixer_read=function(a){var b=La[a];b?b=b.call(this):(b=this.mixer_registers[a],
91
+ y(a),y(b));return b};C.prototype.mixer_write=function(a,b){var c=Oa[a];c?c.call(this,b):(y(a),y(b))};C.prototype.mixer_default_read=function(){y(this.mixer_current_address);return this.mixer_registers[this.mixer_current_address]};C.prototype.mixer_default_write=function(a){y(this.mixer_current_address);y(a);this.mixer_registers[this.mixer_current_address]=a};C.prototype.mixer_reset=function(){this.mixer_registers[4]=204;this.mixer_registers[34]=204;this.mixer_registers[38]=204;this.mixer_registers[40]=
92
92
  0;this.mixer_registers[46]=0;this.mixer_registers[10]=0;this.mixer_registers[48]=192;this.mixer_registers[49]=192;this.mixer_registers[50]=192;this.mixer_registers[51]=192;this.mixer_registers[52]=192;this.mixer_registers[53]=192;this.mixer_registers[54]=0;this.mixer_registers[55]=0;this.mixer_registers[56]=0;this.mixer_registers[57]=0;this.mixer_registers[59]=0;this.mixer_registers[60]=31;this.mixer_registers[61]=21;this.mixer_registers[62]=11;this.mixer_registers[63]=0;this.mixer_registers[64]=
93
- 0;this.mixer_registers[65]=0;this.mixer_registers[66]=0;this.mixer_registers[67]=0;this.mixer_registers[68]=128;this.mixer_registers[69]=128;this.mixer_registers[70]=128;this.mixer_registers[71]=128;this.mixer_full_update()};D.prototype.mixer_full_update=function(){for(var a=1;a<this.mixer_registers.length;a++)Pa[a]||this.mixer_write(a,this.mixer_registers[a])};function Va(a,b){b||(b=D.prototype.mixer_default_read);La[a]=b}function Wa(a,b){b||(b=D.prototype.mixer_default_write);Oa[a]=b}function Xa(a,
94
- b,c){Pa[a]=1;La[a]=function(){return this.mixer_registers[b]&240|this.mixer_registers[c]>>>4};Oa[a]=function(d){this.mixer_registers[a]=d;var e=d<<4&240|this.mixer_registers[c]&15;this.mixer_write(b,d&240|this.mixer_registers[b]&15);this.mixer_write(c,e)}}function Ya(a,b,c){La[a]=D.prototype.mixer_default_read;Oa[a]=function(d){this.mixer_registers[a]=d;this.bus.send("mixer-volume",[b,c,(d>>>2)-62])}}Va(0,function(){this.mixer_reset();return 0});Wa(0);Xa(4,50,51);Xa(34,48,49);Xa(38,52,53);Xa(40,54,
93
+ 0;this.mixer_registers[65]=0;this.mixer_registers[66]=0;this.mixer_registers[67]=0;this.mixer_registers[68]=128;this.mixer_registers[69]=128;this.mixer_registers[70]=128;this.mixer_registers[71]=128;this.mixer_full_update()};C.prototype.mixer_full_update=function(){for(var a=1;a<this.mixer_registers.length;a++)Pa[a]||this.mixer_write(a,this.mixer_registers[a])};function Va(a,b){b||(b=C.prototype.mixer_default_read);La[a]=b}function Wa(a,b){b||(b=C.prototype.mixer_default_write);Oa[a]=b}function Xa(a,
94
+ b,c){Pa[a]=1;La[a]=function(){return this.mixer_registers[b]&240|this.mixer_registers[c]>>>4};Oa[a]=function(d){this.mixer_registers[a]=d;var e=d<<4&240|this.mixer_registers[c]&15;this.mixer_write(b,d&240|this.mixer_registers[b]&15);this.mixer_write(c,e)}}function Ya(a,b,c){La[a]=C.prototype.mixer_default_read;Oa[a]=function(d){this.mixer_registers[a]=d;this.bus.send("mixer-volume",[b,c,(d>>>2)-62])}}Va(0,function(){this.mixer_reset();return 0});Wa(0);Xa(4,50,51);Xa(34,48,49);Xa(38,52,53);Xa(40,54,
95
95
  55);Xa(46,56,57);Ya(48,0,0);Ya(49,0,1);Ya(50,2,0);Ya(51,2,1);Va(59);Wa(59,function(a){this.mixer_registers[59]=a;this.bus.send("mixer-volume",[1,2,6*(a>>>6)-18])});Va(65);Wa(65,function(a){this.mixer_registers[65]=a;this.bus.send("mixer-gain-left",6*(a>>>6))});Va(66);Wa(66,function(a){this.mixer_registers[66]=a;this.bus.send("mixer-gain-right",6*(a>>>6))});Va(68);Wa(68,function(a){this.mixer_registers[68]=a;a>>>=3;this.bus.send("mixer-treble-left",a-(16>a?14:16))});Va(69);Wa(69,function(a){this.mixer_registers[69]=
96
96
  a;a>>>=3;this.bus.send("mixer-treble-right",a-(16>a?14:16))});Va(70);Wa(70,function(a){this.mixer_registers[70]=a;a>>>=3;this.bus.send("mixer-bass-right",a-(16>a?14:16))});Va(71);Wa(71,function(a){this.mixer_registers[71]=a;a>>>=3;this.bus.send("mixer-bass-right",a-(16>a?14:16))});Va(128,function(){switch(this.irq){case 2:return 1;case 5:return 2;case 7:return 4;case 10:return 8;default:return 0}});Wa(128,function(a){a&1&&(this.irq=2);a&2&&(this.irq=5);a&4&&(this.irq=7);a&8&&(this.irq=10)});Va(129,
97
- function(){var a=0;switch(this.dma_channel_8bit){case 0:a|=1;break;case 1:a|=2;break;case 3:a|=8}switch(this.dma_channel_16bit){case 5:a|=32;break;case 6:a|=64;break;case 7:a|=128}return a});Wa(129,function(a){a&1&&(this.dma_channel_8bit=0);a&2&&(this.dma_channel_8bit=1);a&8&&(this.dma_channel_8bit=3);a&32&&(this.dma_channel_16bit=5);a&64&&(this.dma_channel_16bit=6);a&128&&(this.dma_channel_16bit=7)});Va(130,function(){for(var a=32,b=0;16>b;b++)a|=b*this.irq_triggered[b];return a});D.prototype.fm_default_write=
98
- function(a,b,c){y(c);y(a)};function Za(a,b){b||(b=D.prototype.fm_default_write);for(var c=0;c<a.length;c++)Qa[a[c]]=b}function $a(a,b){for(var c=[];a<=b;a++)c.push(a);return c}const ab=new Uint8Array(32);ab[0]=0;ab[1]=1;ab[2]=2;ab[3]=3;ab[4]=4;ab[5]=5;ab[8]=6;ab[9]=7;ab[10]=8;ab[11]=9;ab[12]=10;ab[13]=11;ab[16]=12;ab[17]=13;ab[18]=14;ab[19]=15;ab[20]=16;ab[21]=17;Za([1],function(a,b){this.fm_waveform_select_enable[b]=a&1;this.fm_update_waveforms()});Za([2]);Za([3]);Za([4],function(){});Za([5],function(a,
99
- b,c){0===b&&this.fm_default_write(a,b,c)});Za([8],function(){});Za($a(32,53),function(){});Za($a(64,85),function(){});Za($a(96,117),function(){});Za($a(128,149),function(){});Za($a(160,168),function(){});Za($a(176,184),function(){});Za([189],function(){});Za($a(192,200),function(){});Za($a(224,245),function(){});D.prototype.fm_update_waveforms=function(){};D.prototype.sampling_rate_change=function(a){this.sampling_rate=a;this.bus.send("dac-tell-sampling-rate",a)};D.prototype.get_channel_count=function(){return this.dsp_stereo?
100
- 2:1};D.prototype.dma_transfer_size_set=function(){this.dma_sample_count=1+(this.write_buffer.shift()<<0)+(this.write_buffer.shift()<<8)};D.prototype.dma_transfer_start=function(){this.bytes_per_sample=1;this.dsp_16bit&&(this.bytes_per_sample*=2);this.dma_bytes_count=this.dma_sample_count*this.bytes_per_sample;this.dma_bytes_block=1024*this.bytes_per_sample;this.dma_bytes_block=Math.min(Math.max(this.dma_bytes_count>>2&-4,32),this.dma_bytes_block);this.dma_waiting_transfer=!0;this.dma.channel_mask[this.dma_channel]||
101
- this.dma_on_unmask(this.dma_channel)};D.prototype.dma_on_unmask=function(a){a===this.dma_channel&&this.dma_waiting_transfer&&(this.dma_waiting_transfer=!1,this.dma_bytes_left=this.dma_bytes_count,this.dma_paused=!1,this.bus.send("dac-enable"))};D.prototype.dma_transfer_next=function(){var a=Math.min(this.dma_bytes_left,this.dma_bytes_block),b=Math.floor(a/this.bytes_per_sample);this.dma.do_write(this.dma_syncbuffer,0,a,this.dma_channel,c=>{c||(this.dma_to_dac(b),this.dma_bytes_left-=a,this.dma_bytes_left||
102
- (this.raise_irq(this.dma_irq),this.dma_autoinit&&(this.dma_bytes_left=this.dma_bytes_count)))})};D.prototype.dma_to_dac=function(a){var b=this.dsp_16bit?32767.5:127.5,c=this.dsp_signed?0:-1,d=this.dsp_stereo?1:2;var e=this.dsp_16bit?this.dsp_signed?this.dma_buffer_int16:this.dma_buffer_uint16:this.dsp_signed?this.dma_buffer_int8:this.dma_buffer_uint8;for(var f=0,g=0;g<a;g++)for(var h=Sa(e[g]/b+c,-1,1),l=0;l<d;l++)this.dac_buffers[f].push(h),f^=1;this.dac_send()};D.prototype.dac_handle_request=function(){!this.dma_bytes_left||
103
- this.dma_paused?this.dac_send():this.dma_transfer_next()};D.prototype.dac_send=function(){if(this.dac_buffers[0].length){var a=this.dac_buffers[0].shift_block(this.dac_buffers[0].length),b=this.dac_buffers[1].shift_block(this.dac_buffers[1].length);this.bus.send("dac-send-data",[a,b],[a.buffer,b.buffer])}};D.prototype.raise_irq=function(a){this.irq_triggered[a]=1;this.cpu.device_raise_irq(this.irq)};D.prototype.lower_irq=function(a){this.irq_triggered[a]=0;this.cpu.device_lower_irq(this.irq)};function Sa(a,
97
+ function(){var a=0;switch(this.dma_channel_8bit){case 0:a|=1;break;case 1:a|=2;break;case 3:a|=8}switch(this.dma_channel_16bit){case 5:a|=32;break;case 6:a|=64;break;case 7:a|=128}return a});Wa(129,function(a){a&1&&(this.dma_channel_8bit=0);a&2&&(this.dma_channel_8bit=1);a&8&&(this.dma_channel_8bit=3);a&32&&(this.dma_channel_16bit=5);a&64&&(this.dma_channel_16bit=6);a&128&&(this.dma_channel_16bit=7)});Va(130,function(){for(var a=32,b=0;16>b;b++)a|=b*this.irq_triggered[b];return a});C.prototype.fm_default_write=
98
+ function(a,b,c){y(c);y(a)};function Za(a,b){b||(b=C.prototype.fm_default_write);for(var c=0;c<a.length;c++)Qa[a[c]]=b}function $a(a,b){for(var c=[];a<=b;a++)c.push(a);return c}const ab=new Uint8Array(32);ab[0]=0;ab[1]=1;ab[2]=2;ab[3]=3;ab[4]=4;ab[5]=5;ab[8]=6;ab[9]=7;ab[10]=8;ab[11]=9;ab[12]=10;ab[13]=11;ab[16]=12;ab[17]=13;ab[18]=14;ab[19]=15;ab[20]=16;ab[21]=17;Za([1],function(a,b){this.fm_waveform_select_enable[b]=a&1;this.fm_update_waveforms()});Za([2]);Za([3]);Za([4],function(){});Za([5],function(a,
99
+ b,c){0===b&&this.fm_default_write(a,b,c)});Za([8],function(){});Za($a(32,53),function(){});Za($a(64,85),function(){});Za($a(96,117),function(){});Za($a(128,149),function(){});Za($a(160,168),function(){});Za($a(176,184),function(){});Za([189],function(){});Za($a(192,200),function(){});Za($a(224,245),function(){});C.prototype.fm_update_waveforms=function(){};C.prototype.sampling_rate_change=function(a){this.sampling_rate=a;this.bus.send("dac-tell-sampling-rate",a)};C.prototype.get_channel_count=function(){return this.dsp_stereo?
100
+ 2:1};C.prototype.dma_transfer_size_set=function(){this.dma_sample_count=1+(this.write_buffer.shift()<<0)+(this.write_buffer.shift()<<8)};C.prototype.dma_transfer_start=function(){this.bytes_per_sample=1;this.dsp_16bit&&(this.bytes_per_sample*=2);this.dma_bytes_count=this.dma_sample_count*this.bytes_per_sample;this.dma_bytes_block=1024*this.bytes_per_sample;this.dma_bytes_block=Math.min(Math.max(this.dma_bytes_count>>2&-4,32),this.dma_bytes_block);this.dma_waiting_transfer=!0;this.dma.channel_mask[this.dma_channel]||
101
+ this.dma_on_unmask(this.dma_channel)};C.prototype.dma_on_unmask=function(a){a===this.dma_channel&&this.dma_waiting_transfer&&(this.dma_waiting_transfer=!1,this.dma_bytes_left=this.dma_bytes_count,this.dma_paused=!1,this.bus.send("dac-enable"))};C.prototype.dma_transfer_next=function(){var a=Math.min(this.dma_bytes_left,this.dma_bytes_block),b=Math.floor(a/this.bytes_per_sample);this.dma.do_write(this.dma_syncbuffer,0,a,this.dma_channel,c=>{c||(this.dma_to_dac(b),this.dma_bytes_left-=a,this.dma_bytes_left||
102
+ (this.raise_irq(this.dma_irq),this.dma_autoinit&&(this.dma_bytes_left=this.dma_bytes_count)))})};C.prototype.dma_to_dac=function(a){var b=this.dsp_16bit?32767.5:127.5,c=this.dsp_signed?0:-1,d=this.dsp_stereo?1:2;var e=this.dsp_16bit?this.dsp_signed?this.dma_buffer_int16:this.dma_buffer_uint16:this.dsp_signed?this.dma_buffer_int8:this.dma_buffer_uint8;for(var f=0,g=0;g<a;g++)for(var h=Sa(e[g]/b+c,-1,1),l=0;l<d;l++)this.dac_buffers[f].push(h),f^=1;this.dac_send()};C.prototype.dac_handle_request=function(){!this.dma_bytes_left||
103
+ this.dma_paused?this.dac_send():this.dma_transfer_next()};C.prototype.dac_send=function(){if(this.dac_buffers[0].length){var a=this.dac_buffers[0].shift_block(this.dac_buffers[0].length),b=this.dac_buffers[1].shift_block(this.dac_buffers[1].length);this.bus.send("dac-send-data",[a,b],[a.buffer,b.buffer])}};C.prototype.raise_irq=function(a){this.irq_triggered[a]=1;this.cpu.device_raise_irq(this.irq)};C.prototype.lower_irq=function(a){this.irq_triggered[a]=0;this.cpu.device_lower_irq(this.irq)};function Sa(a,
104
104
  b,c){return(a<b)*b+(a>c)*c+(b<=a&&a<=c)*a}function bb(a){this.message=a}bb.prototype=Error();const cb={Map,Uint8Array,Int8Array,Uint16Array,Int16Array,Uint32Array,Int32Array,Float32Array,Float64Array};function db(a,b){if("object"!==typeof a||null===a)return a;if(Array.isArray(a))return a.map(e=>db(e,b));if(a instanceof Map)return{__state_type__:"Map",args:Array.from(a.entries()).map(([e,f])=>[db(e,b),db(f,b)])};a.constructor===Object&&console.log(a);if(a.BYTES_PER_ELEMENT){var c=new Uint8Array(a.buffer,
105
105
  a.byteOffset,a.length*a.BYTES_PER_ELEMENT);return{__state_type__:a.constructor.name.replace("bound ",""),buffer_id:b.push(c)-1}}a=a.get_state();c=[];for(var d=0;d<a.length;d++)c[d]=db(a[d],b);return c}function eb(a,b){if("object"!==typeof a||null===a)return a;if(Array.isArray(a)){for(var c=0;c<a.length;c++)a[c]=eb(a[c],b);return a}c=cb[a.__state_type__];return void 0!==a.args?new c(a.args):new c(b[a.buffer_id])}function fb(a,b){function c(q,r){const x=q.length;if(16>x)throw new bb("Invalid length: "+
106
106
  x);q=new Int32Array(q.buffer,q.byteOffset,4);if(-2039052682!==q[0])throw new bb("Invalid header: "+y(q[0]>>>0));if(6!==q[1])throw new bb("Version mismatch: dump="+q[1]+" we=6");if(r&&q[2]!==x)throw new bb("Length doesn't match header: real="+x+" header="+q[2]);return q[3]}function d(q){q=(new TextDecoder).decode(q);return JSON.parse(q)}b=new Uint8Array(b);if(4247762216===(new Uint32Array(b.buffer,0,1))[0]){var e=a.zstd_create_ctx(b.length);(new Uint8Array(a.wasm_memory.buffer,a.zstd_get_src_ptr(e)>>>
@@ -139,7 +139,7 @@ this.audio_context.currentTime)};ob.prototype.connect=function(a){var b=!a||2===
139
139
  function(a){this.gain_hidden=a};function nb(a,b,c){this.node_oscillator=b.createOscillator();this.node_oscillator.type="square";this.node_oscillator.frequency.setValueAtTime(440,b.currentTime);this.mixer_connection=c.add_source(this.node_oscillator,1);this.mixer_connection.disconnect();a.register("pcspeaker-enable",function(){c.connect_source(1)},this);a.register("pcspeaker-disable",function(){c.disconnect_source(1)},this);a.register("pcspeaker-update",function(d){var e=d[1],f=0;3===d[0]&&(f=Math.min(1193181.6665999999/
140
140
  e,this.node_oscillator.frequency.maxValue),f=Math.max(f,0));this.node_oscillator.frequency.setValueAtTime(f,b.currentTime)},this)}nb.prototype.start=function(){this.node_oscillator.start()};function kb(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=48E3;b=function(){function g(m){if(0===m)return 1;m*=Math.PI;return Math.sin(m)/m}function h(){var m=Reflect.construct(AudioWorkletProcessor,[],h);m.kernel_size=3;m.queue_data=Array(1024);m.queue_start=0;m.queue_end=0;m.queue_length=
141
141
  0;m.queue_size=m.queue_data.length;m.queued_samples=0;m.source_buffer_previous=l;m.source_buffer_current=l;m.source_samples_per_destination=1;m.source_block_start=0;m.source_time=0;m.source_offset=0;m.port.onmessage=n=>{switch(n.data.type){case "queue":m.queue_push(n.data.value);break;case "sampling-rate":m.source_samples_per_destination=n.data.value/sampleRate}};return m}var l=[new Float32Array(256),new Float32Array(256)];Reflect.setPrototypeOf(h.prototype,AudioWorkletProcessor.prototype);Reflect.setPrototypeOf(h,
142
- AudioWorkletProcessor);h.prototype.process=h.prototype.process=function(m,n){for(m=0;m<n[0][0].length;m++){for(var p=0,q=0,r=this.source_offset+this.kernel_size,x=this.source_offset-this.kernel_size+1;x<=r;x++){var C=this.source_block_start+x;p+=this.get_sample(C,0)*this.kernel(this.source_time-x);q+=this.get_sample(C,1)*this.kernel(this.source_time-x)}if(isNaN(p)||isNaN(q))p=q=0,this.dbg_log("ERROR: NaN values! Ignoring for now.");n[0][0][m]=p;n[0][1][m]=q;this.source_time+=this.source_samples_per_destination;
142
+ AudioWorkletProcessor);h.prototype.process=h.prototype.process=function(m,n){for(m=0;m<n[0][0].length;m++){for(var p=0,q=0,r=this.source_offset+this.kernel_size,x=this.source_offset-this.kernel_size+1;x<=r;x++){var E=this.source_block_start+x;p+=this.get_sample(E,0)*this.kernel(this.source_time-x);q+=this.get_sample(E,1)*this.kernel(this.source_time-x)}if(isNaN(p)||isNaN(q))p=q=0,this.dbg_log("ERROR: NaN values! Ignoring for now.");n[0][0][m]=p;n[0][1][m]=q;this.source_time+=this.source_samples_per_destination;
143
143
  this.source_offset=Math.floor(this.source_time)}n=this.source_offset;n+=this.kernel_size+2;this.source_time-=this.source_offset;this.source_block_start+=this.source_offset;this.source_offset=0;this.ensure_enough_data(n);return!0};h.prototype.kernel=function(m){return g(m)*g(m/this.kernel_size)};h.prototype.get_sample=function(m,n){return 0>m?(m+=this.source_buffer_previous[0].length,this.source_buffer_previous[n][m]):this.source_buffer_current[n][m]};h.prototype.ensure_enough_data=function(m){var n=
144
144
  this.source_buffer_current[0].length;n-this.source_block_start<m&&(this.prepare_next_buffer(),this.source_block_start-=n)};h.prototype.prepare_next_buffer=function(){256>this.queued_samples&&this.queue_length&&this.dbg_log("Not enough samples - should not happen during midway of playback");this.source_buffer_previous=this.source_buffer_current;this.source_buffer_current=this.queue_shift();var m=this.source_buffer_current[0].length;if(256>m){for(var n=this.queue_start,p=0;256>m&&p<this.queue_length;)m+=
145
145
  this.queue_data[n][0].length,n=n+1&this.queue_size-1,p++;m=Math.max(m,256);m=[new Float32Array(m),new Float32Array(m)];m[0].set(this.source_buffer_current[0]);m[1].set(this.source_buffer_current[1]);n=this.source_buffer_current[0].length;for(var q=0;q<p;q++){var r=this.queue_shift();m[0].set(r[0],n);m[1].set(r[1],n);n+=r[0].length}this.source_buffer_current=m}this.pump()};h.prototype.pump=function(){1024>this.queued_samples/this.source_samples_per_destination&&this.port.postMessage({type:"pump"})};
@@ -153,14 +153,14 @@ Math.ceil(8E3/d);this.node_lowpass.frequency.setValueAtTime(d/2,this.audio_conte
153
153
  function(){this.enabled&&(.2<this.buffered_time-this.audio_context.currentTime||this.bus.send("dac-request-data"))};function pb(a,b,c){this.bus=b;this.socket=void 0;this.id=c||0;this.send_queue=[];this.url=a;this.reconnect_interval=1E4;this.last_connect_attempt=Date.now()-this.reconnect_interval;this.send_queue_limit=64;this.destroyed=!1;this.bus.register("net"+this.id+"-send",function(d){this.send(d)},this)}pb.prototype.handle_message=function(a){this.bus&&this.bus.send("net"+this.id+"-receive",
154
154
  new Uint8Array(a.data))};pb.prototype.handle_close=function(){this.destroyed||(this.connect(),setTimeout(this.connect.bind(this),this.reconnect_interval))};pb.prototype.handle_open=function(){for(var a=0;a<this.send_queue.length;a++)this.send(this.send_queue[a]);this.send_queue=[]};pb.prototype.handle_error=function(){};pb.prototype.destroy=function(){this.destroyed=!0;this.socket&&this.socket.close()};pb.prototype.connect=function(){if("undefined"!==typeof WebSocket){if(this.socket){var a=this.socket.readyState;
155
155
  if(0===a||1===a)return}a=Date.now();if(!(this.last_connect_attempt+this.reconnect_interval>a)){this.last_connect_attempt=Date.now();try{this.socket=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)}}};pb.prototype.send=function(a){this.socket&&1===this.socket.readyState?
156
- 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)),this.connect())};pb.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 qb=(new Date("1970-01-01T00:00:00Z")).getTime(),rb=(new Date("1900-01-01T00:00:00Z")).getTime(),sb=qb-rb,xb=Math.pow(2,32),yb=[118,56,54];function zb(a){return[0,
156
+ 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)),this.connect())};pb.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 qb=(new Date("1970-01-01T00:00:00Z")).getTime(),rb=(new Date("1900-01-01T00:00:00Z")).getTime(),sb=qb-rb,tb=Math.pow(2,32),yb=[118,56,54];function zb(a){return[0,
157
157
  1,2,3,4,5].map(b=>a[b].toString(16)).map(b=>1===b.length?"0"+b:b).join(":")}function Ab(a){return a[0]<<24|a[1]<<16|a[2]<<8|a[3]}class Bb{constructor(a,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(;d<c;)d*=2;if(this.maximum_capacity&&d>this.maximum_capacity)throw Error("stream capacity overflow in GrowableRingbuffer.write(), package dropped");
158
158
  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;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);
159
159
  a&&(this.tail=(this.tail+a)%this.buffer.length,this.length-=a);return a}}function Cb(a=1500){const b=a-20,c=b-8,d=new Uint8Array(14+a+4),e=d.buffer,f=d.byteOffset;return{eth_frame:d,eth_frame_view:new DataView(e),eth_payload_view:new DataView(e,f+14,a),ipv4_payload_view:new DataView(e,f+34,b),udp_payload_view:new DataView(e,f+42,c),text_encoder:new TextEncoder}}function Db(a,b,c,d){d.eth_frame.set(b,c.byteOffset+a);return b.length}function Eb(a,b,c,d){const e=c.byteOffset+(a&-2);d=d.eth_frame;for(c=
160
160
  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 Fb(a,b){a.eth_frame.fill(0);var c=a.eth_frame,d=c.subarray,e=a.eth_frame_view;Db(0,b.eth.dest,e,a);Db(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);Db(8,b.arp.sha,f,a);Db(14,b.arp.spa,f,a);Db(18,b.arp.tha,
161
161
  f,a);Db(24,b.arp.tpa,f,a);e+=28}else if(b.ipv4){f=a.eth_payload_view;var g=20;if(b.icmp){var h=a.ipv4_payload_view;h.setUint8(0,b.icmp.type);h.setUint8(1,b.icmp.code);h.setUint16(2,0);var l=4+Db(4,b.icmp.data,h,a);h.setUint16(2,Eb(l,0,h,a));g+=l}else if(b.udp){h=a.ipv4_payload_view;var m=8;if(b.dhcp){l=m;var n=a.udp_payload_view;n.setUint8(0,b.dhcp.op);n.setUint8(1,b.dhcp.htype);n.setUint8(2,b.dhcp.hlen);n.setUint8(3,b.dhcp.hops);n.setUint32(4,b.dhcp.xid);n.setUint16(8,b.dhcp.secs);n.setUint16(10,
162
- b.dhcp.flags);n.setUint32(12,b.dhcp.ciaddr);n.setUint32(16,b.dhcp.yiaddr);n.setUint32(20,b.dhcp.siaddr);n.setUint32(24,b.dhcp.giaddr);Db(28,b.dhcp.chaddr,n,a);n.setUint32(236,1669485411);m=240;for(var p of b.dhcp.options)m+=Db(m,p,n,a);l+=m}else if(b.dns){p=m;m=a.udp_payload_view;m.setUint16(0,b.dns.id);m.setUint16(2,b.dns.flags);m.setUint16(4,b.dns.questions.length);m.setUint16(6,b.dns.answers.length);let x=12;for(var q=0;q<b.dns.questions.length;++q){var r=b.dns.questions[q];for(n of r.name){const C=
163
- a.text_encoder.encodeInto(n,a.eth_frame.subarray(m.byteOffset+(x+1))).written;m.setUint8(x,C);x+=1+C}m.setUint16(x,r.type);x+=2;m.setUint16(x,r.class);x+=2}for(q=0;q<b.dns.answers.length;++q){n=b.dns.answers[q];for(l of n.name)r=a.text_encoder.encodeInto(l,a.eth_frame.subarray(m.byteOffset+(x+1))).written,m.setUint8(x,r),x+=1+r;m.setUint16(x,n.type);x+=2;m.setUint16(x,n.class);x+=2;m.setUint32(x,n.ttl);x+=4;m.setUint16(x,n.data.length);x+=2;x+=Db(x,n.data,m,a)}l=p+x}else b.ntp?(l=m,n=a.udp_payload_view,
162
+ b.dhcp.flags);n.setUint32(12,b.dhcp.ciaddr);n.setUint32(16,b.dhcp.yiaddr);n.setUint32(20,b.dhcp.siaddr);n.setUint32(24,b.dhcp.giaddr);Db(28,b.dhcp.chaddr,n,a);n.setUint32(236,1669485411);m=240;for(var p of b.dhcp.options)m+=Db(m,p,n,a);l+=m}else if(b.dns){p=m;m=a.udp_payload_view;m.setUint16(0,b.dns.id);m.setUint16(2,b.dns.flags);m.setUint16(4,b.dns.questions.length);m.setUint16(6,b.dns.answers.length);let x=12;for(var q=0;q<b.dns.questions.length;++q){var r=b.dns.questions[q];for(n of r.name){const E=
163
+ a.text_encoder.encodeInto(n,a.eth_frame.subarray(m.byteOffset+(x+1))).written;m.setUint8(x,E);x+=1+E}m.setUint16(x,r.type);x+=2;m.setUint16(x,r.class);x+=2}for(q=0;q<b.dns.answers.length;++q){n=b.dns.answers[q];for(l of n.name)r=a.text_encoder.encodeInto(l,a.eth_frame.subarray(m.byteOffset+(x+1))).written,m.setUint8(x,r),x+=1+r;m.setUint16(x,n.type);x+=2;m.setUint16(x,n.class);x+=2;m.setUint32(x,n.ttl);x+=4;m.setUint16(x,n.data.length);x+=2;x+=Db(x,n.data,m,a)}l=p+x}else b.ntp?(l=m,n=a.udp_payload_view,
164
164
  n.setUint8(0,b.ntp.flags),n.setUint8(1,b.ntp.stratum),n.setUint8(2,b.ntp.poll),n.setUint8(3,b.ntp.precision),n.setUint32(4,b.ntp.root_delay),n.setUint32(8,b.ntp.root_disp),n.setUint32(12,b.ntp.ref_id),n.setUint32(16,b.ntp.ref_ts_i),n.setUint32(20,b.ntp.ref_ts_f),n.setUint32(24,b.ntp.ori_ts_i),n.setUint32(28,b.ntp.ori_ts_f),n.setUint32(32,b.ntp.rec_ts_i),n.setUint32(36,b.ntp.rec_ts_f),n.setUint32(40,b.ntp.trans_ts_i),n.setUint32(44,b.ntp.trans_ts_f),l+=48):l=m+Db(0,b.udp.data,a.udp_payload_view,a);
165
165
  m=l;h.setUint16(0,b.udp.sport);h.setUint16(2,b.udp.dport);h.setUint16(4,m);h.setUint16(6,0);h.setUint16(6,Eb(m,(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])+17+m,h,a));g+=m}else b.tcp&&(h=a.ipv4_payload_view,l=0,n=b.tcp,n.fin&&(l|=1),n.syn&&(l|=2),n.rst&&(l|=4),n.psh&&(l|=8),n.ack&&(l|=16),n.urg&&(l|=32),n.ece&&(l|=64),n.cwr&&(l|=128),p=20,n.options&&n.options.mss&&(h.setUint8(p,2),h.setUint8(p+1,4),h.setUint16(p+
166
166
  2,n.options.mss),p+=4),m=4*Math.ceil(p/4),n.options&&0<m-p&&a.eth_frame.fill(0,h.byteOffset+p,h.byteOffset+p+(m-p)),h.setUint16(0,n.sport),h.setUint16(2,n.dport),h.setUint32(4,n.seq),h.setUint32(8,n.ackn),h.setUint8(12,m>>2<<4),h.setUint8(13,l),h.setUint16(14,n.winsize),h.setUint16(16,0),h.setUint16(18,n.urgent||0),b.tcp_data&&(m+=Db(20,b.tcp_data,h,a)),h.setUint16(16,Eb(m,(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])+
@@ -175,11 +175,11 @@ a.sport?Jb(e.subarray(8),c):123===a.dport&&(d=e.subarray(8),d=new DataView(d.buf
175
175
  d?(d=new DataView(a.buffer,a.byteOffset,a.byteLength),a={htype:d.getUint16(0),ptype:d.getUint16(2),oper:d.getUint16(6),sha:a.subarray(8,14),spa:a.subarray(14,18),tha:a.subarray(18,24),tpa:a.subarray(24,28)},c.arp=a):34525!==d&&y(d);if(c.ipv4)if(c.tcp)a:{a=`${c.ipv4.src.join(".")}:${c.tcp.sport}:${c.ipv4.dest.join(".")}:${c.tcp.dport}`;if(c.tcp.syn&&!c.tcp.ack){b.tcp_conn[a]&&delete b.tcp_conn[a];d=new Kb(b);d.state="syn-received";d.tuple=a;d.last=c;d.hsrc=new Uint8Array(c.eth.dest);d.psrc=new Uint8Array(c.ipv4.dest);
176
176
  d.sport=c.tcp.dport;d.hdest=new Uint8Array(c.eth.src);d.dport=c.tcp.sport;d.pdest=new Uint8Array(c.ipv4.src);b.bus.pair.send("tcp-connection",d);if(b.on_tcp_connection)b.on_tcp_connection(d,c);if(b.tcp_conn[a])break a}if(b.tcp_conn[a])b.tcp_conn[a].process(c);else{a=c.tcp.ackn;if(c.tcp.fin||c.tcp.syn)a+=1;d={};d.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src};d.ipv4={proto:6,src:c.ipv4.dest,dest:c.ipv4.src};d.tcp={sport:c.tcp.dport,dport:c.tcp.sport,seq:a,ackn:c.tcp.seq+(c.tcp.syn?1:0),winsize:c.tcp.winsize,
177
177
  rst:!0,ack:c.tcp.syn};b.receive(Fb(b.eth_encoder_buf,d))}}else if(c.udp)if(c.dns)if("static"===b.dns_method){a={};a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src};a.ipv4={proto:17,src:b.router_ip,dest:c.ipv4.src};a.udp={sport:53,dport:c.udp.sport};d=[];for(e=0;e<c.dns.questions.length;++e)switch(l=c.dns.questions[e],l.type){case 1:d.push({name:l.name,type:l.type,class:l.class,ttl:600,data:[192,168,87,1]})}a.dns={id:c.dns.id,flags:33152,questions:c.dns.questions,answers:d};b.receive(Fb(b.eth_encoder_buf,
178
- a))}else Gb(c,b);else c.dhcp?Hb(c,b):c.ntp?(a=Date.now()+sb,d=a%1E3/1E3*xb,e={},e.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},e.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},e.udp={sport:123,dport:c.udp.sport},e.ntp=Object.assign({},c.ntp),e.ntp.flags=36,e.ntp.poll=10,e.ntp.ori_ts_i=c.ntp.trans_ts_i,e.ntp.ori_ts_f=c.ntp.trans_ts_f,e.ntp.rec_ts_i=a/1E3,e.ntp.rec_ts_f=d,e.ntp.trans_ts_i=a/1E3,e.ntp.trans_ts_f=d,e.ntp.stratum=2,b.receive(Fb(b.eth_encoder_buf,e))):8===c.udp.dport&&(a={},a.eth=
178
+ a))}else Gb(c,b);else c.dhcp?Hb(c,b):c.ntp?(a=Date.now()+sb,d=a%1E3/1E3*tb,e={},e.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},e.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},e.udp={sport:123,dport:c.udp.sport},e.ntp=Object.assign({},c.ntp),e.ntp.flags=36,e.ntp.poll=10,e.ntp.ori_ts_i=c.ntp.trans_ts_i,e.ntp.ori_ts_f=c.ntp.trans_ts_f,e.ntp.rec_ts_i=a/1E3,e.ntp.rec_ts_f=d,e.ntp.trans_ts_i=a/1E3,e.ntp.trans_ts_f=d,e.ntp.stratum=2,b.receive(Fb(b.eth_encoder_buf,e))):8===c.udp.dport&&(a={},a.eth=
179
179
  {ethertype:2048,src:b.router_mac,dest:c.eth.src},a.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},a.udp={sport:c.udp.dport,dport:c.udp.sport,data:(new TextEncoder).encode(c.udp.data_s)},b.receive(Fb(b.eth_encoder_buf,a)));else c.icmp&&8===c.icmp.type&&(a={},a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},a.ipv4={proto:1,src:c.ipv4.dest,dest:c.ipv4.src},a.icmp={type:0,code:c.icmp.code,data:c.icmp.data},b.receive(Fb(b.eth_encoder_buf,a)));else c.arp&&1===c.arp.oper&&2048===c.arp.ptype&&(a=Ab(c.arp.tpa)&
180
180
  4294967040,d=Ab(b.router_ip)&4294967040,!b.masquerade&&a!==d||a===d&&99<c.arp.tpa[3]||(a={},a.eth={ethertype:2054,src:b.router_mac,dest:c.eth.src},a.arp={htype:1,ptype:2048,oper:2,sha:b.router_mac,spa:c.arp.tpa,tha:c.eth.src,tpa:c.arp.spa},b.receive(Fb(b.eth_encoder_buf,a))))}function Jb(a,b){function c(){let m=[],n;do n=d.getUint8(h),m.push((new TextDecoder).decode(a.subarray(h+1,h+1+n))),h+=n+1;while(0<n);return m}let d=new DataView(a.buffer,a.byteOffset,a.byteLength),e={id:d.getUint16(0),flags:d.getUint16(2),
181
- questions:[],answers:[]};var f=d.getUint16(4);let g=d.getUint16(6);d.getUint16(8);d.getUint16(10);let h=12;for(var l=0;l<f;l++)e.questions.push({name:c(),type:d.getInt16(h),class:d.getInt16(h+2)}),h+=4;for(f=0;f<g;f++){l={name:c(),type:d.getInt16(h),class:d.getUint16(h+2),ttl:d.getUint32(h+4)};h+=8;let m=d.getUint16(h);h+=2;l.data=a.subarray(h,h+m);h+=m;e.answers.push(l)}b.dns=e}function Ub(a,b){var c=b.vm_ip.join(".");const d=b.router_ip.join("."),e=16383*Math.random()|0;let f,g,h=0;do f=49152+(e+
182
- h)%16383,g=`${c}:${a}:${d}:${f}`;while(16383>++h&&b.tcp_conn[g]);if(b.tcp_conn[g])throw Error("pool of dynamic TCP port numbers exhausted, connection aborted");c=new Kb(b);c.tuple=g;c.hsrc=b.router_mac;c.psrc=b.router_ip;c.sport=f;c.hdest=b.vm_mac;c.dport=a;c.pdest=b.vm_ip;b.tcp_conn[g]=c;c.connect();return c}function Vb(a,b){return new Promise(c=>{let d=Ub(a,b);d.state="syn-probe";d.on("probe",c)})}function Kb(a){this.mtu=a.mtu||1500;const b=this.mtu-20-20;this.state="closed";this.net=a;this.send_buffer=
181
+ questions:[],answers:[]};var f=d.getUint16(4);let g=d.getUint16(6);d.getUint16(8);d.getUint16(10);let h=12;for(var l=0;l<f;l++)e.questions.push({name:c(),type:d.getInt16(h),class:d.getInt16(h+2)}),h+=4;for(f=0;f<g;f++){l={name:c(),type:d.getInt16(h),class:d.getUint16(h+2),ttl:d.getUint32(h+4)};h+=8;let m=d.getUint16(h);h+=2;l.data=a.subarray(h,h+m);h+=m;e.answers.push(l)}b.dns=e}function Lb(a,b){var c=b.vm_ip.join(".");const d=b.router_ip.join("."),e=16383*Math.random()|0;let f,g,h=0;do f=49152+(e+
182
+ h)%16383,g=`${c}:${a}:${d}:${f}`;while(16383>++h&&b.tcp_conn[g]);if(b.tcp_conn[g])throw Error("pool of dynamic TCP port numbers exhausted, connection aborted");c=new Kb(b);c.tuple=g;c.hsrc=b.router_mac;c.psrc=b.router_ip;c.sport=f;c.hdest=b.vm_mac;c.dport=a;c.pdest=b.vm_ip;b.tcp_conn[g]=c;c.connect();return c}function Vb(a,b){return new Promise(c=>{let d=Lb(a,b);d.state="syn-probe";d.on("probe",c)})}function Kb(a){this.mtu=a.mtu||1500;const b=this.mtu-20-20;this.state="closed";this.net=a;this.send_buffer=
183
183
  new Bb(2048,0);this.send_chunk_buf=new Uint8Array(b);this.delayed_send_fin=this.in_active_close=!1;this.delayed_state=void 0;this.events_handlers={}}Kb.prototype.on=function(a,b){this.events_handlers[a]=b};Kb.prototype.emit=function(a,...b){this.events_handlers[a]&&this.events_handlers[a].apply(this,b)};Kb.prototype.ipv4_reply=function(){let a={};a.eth={ethertype:2048,src:this.hsrc,dest:this.hdest};a.ipv4={proto:6,src:this.psrc,dest:this.pdest};a.tcp={sport:this.sport,dport:this.dport,winsize:this.winsize,
184
184
  ackn:this.ack,seq:this.seq,ack:!0};return a};Kb.prototype.packet_reply=function(a,b){a={sport:a.tcp.dport,dport:a.tcp.sport,winsize:a.tcp.winsize,ackn:this.ack,seq:this.seq};if(b)for(const c in b)a[c]=b[c];b=this.ipv4_reply();b.tcp=a;return b};Kb.prototype.connect=function(){this.seq=1338;this.ack=1;this.start_seq=0;this.winsize=64240;"syn-probe"!==this.state&&(this.state="syn-sent");let a=this.ipv4_reply();a.ipv4.id=2345;a.tcp={sport:this.sport,dport:this.dport,seq:1337,ackn:0,winsize:0,syn:!0};
185
185
  this.net.receive(Fb(this.net.eth_encoder_buf,a))};Kb.prototype.accept=function(a){a=a||this.last;this.net.tcp_conn[this.tuple]=this;this.seq=1338;this.ack=a.tcp.seq+1;this.start_seq=a.tcp.seq;this.winsize=a.tcp.winsize;let b=this.ipv4_reply();b.tcp={sport:this.sport,dport:this.dport,seq:1337,ackn:this.ack,winsize:a.tcp.winsize,syn:!0,ack:!0,options:{mss:this.mtu-20-20}};this.state="established";this.net.receive(Fb(this.net.eth_encoder_buf,b))};Kb.prototype.process=function(a){this.last=a;if("closed"===
@@ -191,7 +191,7 @@ Kb.prototype.write=function(a){this.in_active_close||this.send_buffer.write(a);t
191
191
  this.delayed_state=a):(this.state=a,a=this.ipv4_reply(),a.tcp.fin=!0,this.net.receive(Fb(this.net.eth_encoder_buf,a)))}this.pump()};Kb.prototype.on_shutdown=function(){this.emit("shutdown")};Kb.prototype.on_close=function(){this.emit("close")};Kb.prototype.release=function(){this.net.tcp_conn[this.tuple]&&(this.state="closed",delete this.net.tcp_conn[this.tuple])};Kb.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();
192
192
  c.tcp.psh=!0;c.tcp_data=a.subarray(0,b);this.net.receive(Fb(this.net.eth_encoder_buf,c));this.pending=!0}};function Wb(a,b){b=b||{};this.bus=a;this.id=b.id||0;this.router_mac=new Uint8Array((b.router_mac||"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=
193
193
  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.mtu=b.mtu;this.eth_encoder_buf=Cb(this.mtu);this.fetch=(...c)=>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);this.bus.register("tcp-connection",
194
- c=>{80===c.sport&&(c.on("data",Xb),c.accept())},this)}Wb.prototype.destroy=function(){};Wb.prototype.connect=function(a){return Ub(a,this)};Wb.prototype.tcp_probe=function(a){return Vb(a,this)};async function Xb(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"+
194
+ c=>{80===c.sport&&(c.on("data",Xb),c.accept())},this)}Wb.prototype.destroy=function(){};Wb.prototype.connect=function(a){return Lb(a,this)};Wb.prototype.tcp_probe=function(a){return Vb(a,this)};async function Xb(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"+
195
195
  c[1]);"undefined"!==typeof window&&"http:"===d.protocol&&"https:"===window.location.protocol&&(d.protocol="https:");let e=new Headers;for(let h=1;h<b.length;++h){const l=this.net.parse_http_header(b[h]);if(!l){console.warn('The request contains an invalid header: "%s"',b[h]);this.net.respond_text_and_close(this,400,"Bad Request",`Invalid header in request: ${b[h]}`);return}"host"===l.key.toLowerCase()?d.host=l.value:e.append(l.key,l.value)}if(!this.net.cors_proxy&&/^\d+\.external$/.test(d.hostname))if(b=
196
196
  parseInt(d.hostname.split(".")[0],10),!isNaN(b)&&0<b&&65536>b)d.protocol="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}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 g=
197
197
  !1;this.net.fetch(f,b).then(h=>{let l=new Headers(h.headers);l.delete("content-encoding");l.delete("keep-alive");l.delete("content-length");l.delete("transfer-encoding");l.set("x-was-fetch-redirected",`${!!h.redirected}`);l.set("x-fetch-resp-url",h.url);l.set("connection","close");this.write(this.net.form_response_head(h.status,h.statusText,l));g=!0;if(h.body&&h.body.getReader){const m=h.body.getReader(),n=({value:p,done:q})=>{p&&this.write(p);if(q)this.close();else return m.read().then(n)};m.read().then(n)}else h.arrayBuffer().then(m=>
@@ -205,125 +205,126 @@ c);break;case 3:this.connections[c]&&(this.connections[c].congestion=b.getUint32
205
205
  b=new Uint8Array(8+d.length);c=new DataView(b.buffer);c.setUint8(0,1);c.setUint32(1,a.stream_id,!0);c.setUint8(5,1);c.setUint16(6,a.port,!0);b.set(d,8);this.connections[a.stream_id]={data_callback:a.data_callback,close_callback:a.close_callback,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,
206
206
  4),c.setUint32(1,a.stream_id,!0),c.setUint8(5,a.reason)}this.send_packet(b,a.type,a.stream_id)};Yb.prototype.destroy=function(){this.wispws&&(this.wispws.onmessage=null,this.wispws.onclose=null,this.wispws.close(),this.wispws=null)};Yb.prototype.on_tcp_connection=function(a,b){a.stream_id=this.last_stream++;a.on("data",c=>{0!==c.length&&this.send_wisp_frame({type:"DATA",stream_id:a.stream_id,data:c})});a.on_close=()=>{this.send_wisp_frame({type:"CLOSE",stream_id:a.stream_id,reason:2})};a.on_shutdown=
207
207
  a.on_close;this.send_wisp_frame({type:"CONNECT",stream_id:a.stream_id,hostname:b.ipv4.dest.join("."),port:a.sport,data_callback:c=>{a.write(c)},close_callback:()=>{a.close()}});a.accept();return!0};Yb.prototype.send=function(a){Ib(a,this)};Yb.prototype.receive=function(a){this.bus.send("net"+this.id+"-receive",new Uint8Array(a))};const Zb="undefined"!==typeof window&&0<=window.navigator.platform.toString().toLowerCase().search("win");function $b(a){function b(v){return v.shiftKey&&v.ctrlKey&&(73===
208
- v.keyCode||74===v.keyCode||75===v.keyCode)||!x.emu_enabled?!1:v.target?v.target.classList.contains("phone_keyboard")||"INPUT"!==v.target.nodeName&&"TEXTAREA"!==v.target.nodeName:!0}function c(v){!v.altKey&&n[56]&&l(56,!1);return g(v,!1)}function d(v){!v.altKey&&n[56]&&l(56,!1);return g(v,!0)}function e(){for(var v=Object.keys(n),L,U=0;U<v.length;U++)L=+v[U],n[L]&&l(L,!1);n={}}function f(v){if(x.bus&&b(v))switch(v.inputType){case "insertText":for(var L=0;L<v.data.length;L++)x.simulate_char(v.data[L]);
209
- break;case "insertLineBreak":x.simulate_press(13);break;case "deleteContentBackward":x.simulate_press(8)}}function g(v,L){if(x.bus&&b(v)&&""!==v.code&&"Process"!==v.key&&"Unidentified"!==v.key&&229!==v.keyCode){v.preventDefault&&v.preventDefault();if(Zb&&(p&&(clearTimeout(r),v.getModifierState&&v.getModifierState("AltGraph")&&q===L&&"ControlLeft"===p.code&&"AltRight"===v.code||h(p,q),p=null),"ControlLeft"===v.code))return p=v,q=L,r=setTimeout(()=>{h(p,q);p=null},10),!1;h(v,L);return!1}}function h(v,
210
- L){a:{if(void 0!==v.code){var U=M[v.code];if(void 0!==U)break a}U=C[v.keyCode]}U?l(U,L,v.repeat):console.log("Missing char in map: keyCode="+(v.keyCode||-1).toString(16)+" code="+v.code)}function l(v,L,U){if(L)n[v]&&!U&&l(v,!1);else if(!n[v])return;(n[v]=L)||(v|=128);255<v?(m(v>>8),m(v&255)):m(v)}function m(v){x.bus.send("keyboard-code",v)}var n={},p=null,q=!1,r=0,x=this;this.emu_enabled=!0;const C=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,
208
+ v.keyCode||74===v.keyCode||75===v.keyCode)||!x.emu_enabled?!1:v.target?v.target.classList.contains("phone_keyboard")||"INPUT"!==v.target.nodeName&&"TEXTAREA"!==v.target.nodeName:!0}function c(v){!v.altKey&&n[56]&&l(56,!1);return g(v,!1)}function d(v){!v.altKey&&n[56]&&l(56,!1);return g(v,!0)}function e(){for(var v=Object.keys(n),H,U=0;U<v.length;U++)H=+v[U],n[H]&&l(H,!1);n={}}function f(v){if(x.bus&&b(v))switch(v.inputType){case "insertText":for(var H=0;H<v.data.length;H++)x.simulate_char(v.data[H]);
209
+ break;case "insertLineBreak":x.simulate_press(13);break;case "deleteContentBackward":x.simulate_press(8)}}function g(v,H){if(x.bus&&b(v)&&""!==v.code&&"Process"!==v.key&&"Unidentified"!==v.key&&229!==v.keyCode){v.preventDefault&&v.preventDefault();if(Zb&&(p&&(clearTimeout(r),v.getModifierState&&v.getModifierState("AltGraph")&&q===H&&"ControlLeft"===p.code&&"AltRight"===v.code||h(p,q),p=null),"ControlLeft"===v.code))return p=v,q=H,r=setTimeout(()=>{h(p,q);p=null},10),!1;h(v,H);return!1}}function h(v,
210
+ H){a:{if(void 0!==v.code){var U=K[v.code];if(void 0!==U)break a}U=E[v.keyCode]}U?l(U,H,v.repeat):console.log("Missing char in map: keyCode="+(v.keyCode||-1).toString(16)+" code="+v.code)}function l(v,H,U){if(H)n[v]&&!U&&l(v,!1);else if(!n[v])return;(n[v]=H)||(v|=128);255<v?(m(v>>8),m(v&255)):m(v)}function m(v){x.bus.send("keyboard-code",v)}var n={},p=null,q=!1,r=0,x=this;this.emu_enabled=!0;const E=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,
211
211
  57423,57415,57419,57416,57421,80,0,0,0,0,82,83,0,11,2,3,4,5,6,7,8,9,10,0,39,0,13,0,0,0,30,48,46,32,18,33,34,35,23,36,37,38,50,49,24,25,16,19,31,20,22,47,17,45,21,44,57435,57436,57437,0,0,82,79,80,81,75,76,77,71,72,73,0,0,0,0,0,0,59,60,61,62,63,64,65,66,67,68,87,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,39,13,51,12,52,53,41,0,0,0,0,0,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,
212
- 0,0,0,0,0,0,0,0]),t={8:8,10:13,32:32,39:222,44:188,45:189,46:190,47:191,48:48,49:49,50:50,51:51,52:52,53:53,54:54,55:55,56:56,57:57,59:186,61:187,91:219,92:220,93:221,96:192,97:65,98:66,99:67,100:68,101:69,102:70,103:71,104:72,105:73,106:74,107:75,108:76,109:77,110:78,111:79,112:80,113:81,114:82,115:83,116:84,117:85,118:86,119:87,120:88,121:89,122:90},A={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,
213
- 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 M={Escape:1,Digit1:2,Digit2:3,Digit3:4,Digit4:5,Digit5:6,Digit6:7,Digit7:8,Digit8:9,Digit9:10,Digit0:11,Minus:12,Equal:13,Backspace:14,Tab:15,KeyQ:16,KeyW:17,KeyE:18,KeyR:19,KeyT:20,KeyY:21,KeyU:22,KeyI:23,KeyO:24,KeyP:25,BracketLeft:26,BracketRight:27,Enter:28,ControlLeft:29,KeyA:30,KeyS:31,KeyD:32,KeyF:33,KeyG:34,KeyH:35,KeyJ:36,KeyK:37,KeyL:38,
212
+ 0,0,0,0,0,0,0,0]),z={8:8,10:13,32:32,39:222,44:188,45:189,46:190,47:191,48:48,49:49,50:50,51:51,52:52,53:53,54:54,55:55,56:56,57:57,59:186,61:187,91:219,92:220,93:221,96:192,97:65,98:66,99:67,100:68,101:69,102:70,103:71,104:72,105:73,106:74,107:75,108:76,109:77,110:78,111:79,112:80,113:81,114:82,115:83,116:84,117:85,118:86,119:87,120:88,121:89,122:90},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,
213
+ 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 K={Escape:1,Digit1:2,Digit2:3,Digit3:4,Digit4:5,Digit5:6,Digit6:7,Digit7:8,Digit8:9,Digit9:10,Digit0:11,Minus:12,Equal:13,Backspace:14,Tab:15,KeyQ:16,KeyW:17,KeyE:18,KeyR:19,KeyT:20,KeyY:21,KeyU:22,KeyI:23,KeyO:24,KeyP:25,BracketLeft:26,BracketRight:27,Enter:28,ControlLeft:29,KeyA:30,KeyS:31,KeyD:32,KeyF:33,KeyG:34,KeyH:35,KeyJ:36,KeyK:37,KeyL:38,
214
214
  Semicolon:39,Quote:40,Backquote:41,ShiftLeft:42,Backslash:43,KeyZ:44,KeyX:45,KeyC:46,KeyV:47,KeyB:48,KeyN:49,KeyM:50,Comma:51,Period:52,Slash:53,IntlRo:53,ShiftRight:54,NumpadMultiply:55,AltLeft:56,Space:57,CapsLock:58,F1:59,F2:60,F3:61,F4:62,F5:63,F6:64,F7:65,F8:66,F9:67,F10:68,NumLock:69,ScrollLock:70,Numpad7:71,Numpad8:72,Numpad9:73,NumpadSubtract:74,Numpad4:75,Numpad5:76,Numpad6:77,NumpadAdd:78,Numpad1:79,Numpad2:80,Numpad3:81,Numpad0:82,NumpadDecimal:83,IntlBackslash:86,F11:87,F12:88,NumpadEnter:57372,
215
215
  ControlRight:57373,NumpadDivide:57397,AltRight:57400,Home:57415,ArrowUp:57416,PageUp:57417,ArrowLeft:57419,ArrowRight:57421,End:57423,ArrowDown:57424,PageDown:57425,Insert:57426,Delete:57427,MetaLeft:57435,OSLeft:57435,MetaRight:57436,OSRight:57436,ContextMenu:57437};this.bus=a;this.destroy=function(){"undefined"!==typeof window&&(window.removeEventListener("keyup",c,!1),window.removeEventListener("keydown",d,!1),window.removeEventListener("blur",e,!1),window.removeEventListener("input",f,!1))};this.init=
216
- function(){"undefined"!==typeof window&&(this.destroy(),window.addEventListener("keyup",c,!1),window.addEventListener("keydown",d,!1),window.addEventListener("blur",e,!1),window.addEventListener("input",f,!1))};this.init();this.simulate_press=function(v){v={keyCode:v};g(v,!0);g(v,!1)};this.simulate_char=function(v){var L=v.charCodeAt(0);L in t?this.simulate_press(t[L]):L in A?(m(42),this.simulate_press(A[L]),m(170)):console.log("ascii -> keyCode not found: ",L,v)}}function ac(a,b){function c(t){if(!C.enabled||
217
- !C.emu_enabled)return!1;var A=b||document.body,M;if(!(M=document.pointerLockElement))a:{for(t=t.target;t.parentNode;){if(t===A){M=!0;break a}t=t.parentNode}M=!1}return M}function d(t){c(t)&&(t=t.changedTouches)&&t.length&&(t=t[t.length-1],r=t.clientX,x=t.clientY)}function e(){if(n||q||p)C.bus.send("mouse-click",[!1,!1,!1]),n=q=p=!1}function f(t){if(C.bus&&c(t)&&C.is_running){var A=0,M=0,v=t.changedTouches;v?v.length&&(v=v[v.length-1],A=v.clientX-r,M=v.clientY-x,r=v.clientX,x=v.clientY,t.preventDefault()):
218
- "number"===typeof t.movementX?(A=t.movementX,M=t.movementY):"number"===typeof t.webkitMovementX?(A=t.webkitMovementX,M=t.webkitMovementY):"number"===typeof t.mozMovementX?(A=t.mozMovementX,M=t.mozMovementY):(A=t.clientX-r,M=t.clientY-x,r=t.clientX,x=t.clientY);C.bus.send("mouse-delta",[1*A,-(1*M)]);b&&C.bus.send("mouse-absolute",[t.pageX-b.offsetLeft,t.pageY-b.offsetTop,b.offsetWidth,b.offsetHeight])}}function g(t){c(t)&&l(t,!0)}function h(t){c(t)&&l(t,!1)}function l(t,A){C.bus&&(1===t.which?n=A:
219
- 2===t.which?q=A:3===t.which&&(p=A),C.bus.send("mouse-click",[n,q,p]),t.preventDefault())}function m(t){if(c(t)){var A=t.wheelDelta||-t.detail;0>A?A=-1:0<A&&(A=1);C.bus.send("mouse-wheel",[A,0]);t.preventDefault()}}var n=!1,p=!1,q=!1,r=0,x=0,C=this;this.enabled=!1;this.emu_enabled=!0;this.bus=a;this.bus.register("mouse-enable",function(t){this.enabled=t},this);this.is_running=!1;this.bus.register("emulator-stopped",function(){this.is_running=!1},this);this.bus.register("emulator-started",function(){this.is_running=
220
- !0},this);this.destroy=function(){"undefined"!==typeof window&&(window.removeEventListener("touchstart",d,!1),window.removeEventListener("touchend",e,!1),window.removeEventListener("touchmove",f,!1),window.removeEventListener("mousemove",f,!1),window.removeEventListener("mousedown",g,!1),window.removeEventListener("mouseup",h,!1),window.removeEventListener("wheel",m,{passive:!1}))};this.init=function(){"undefined"!==typeof window&&(this.destroy(),window.addEventListener("touchstart",d,!1),window.addEventListener("touchend",
221
- e,!1),window.addEventListener("touchmove",f,!1),window.addEventListener("mousemove",f,!1),window.addEventListener("mousedown",g,!1),window.addEventListener("mouseup",h,!1),window.addEventListener("wheel",m,{passive:!1}))};this.init()}function bc(a){var b,c=0,d=0,e=ta(a?.encoding);this.put_char=function(f,g,h){b[f*c+g]=h};this.destroy=function(){};this.pause=function(){};this.continue=function(){};this.set_mode=function(){};this.set_font_bitmap=function(){};this.set_font_page=function(){};this.clear_screen=
222
- function(){};this.set_size_text=function(f,g){if(f!==c||g!==d)b=new Uint8Array(f*g),c=f,d=g};this.set_size_graphical=function(){};this.set_scale=function(){};this.update_cursor_scanline=function(){};this.update_cursor=function(){};this.update_buffer=function(){};this.get_text_screen=function(){for(var f=[],g=0;g<d;g++)f.push(this.get_text_row(g));return f};this.get_text_row=function(f){f*=c;return Array.from(b.subarray(f,f+c),g=>e[g]).join("")};this.set_size_text(80,25)}function cc(a){var b,c=0,d=
223
- 0,e=ta(a?.encoding);this.put_char=function(f,g,h,l,m,n){f=3*(f*c+g);b[f+0]=h;b[f+1]=m;b[f+2]=n};this.destroy=function(){};this.pause=function(){};this.continue=function(){};this.set_mode=function(){};this.set_font_bitmap=function(){};this.set_font_page=function(){};this.clear_screen=function(){};this.set_size_text=function(f,g){if(f!==c||g!==d)b=new Int32Array(f*g*3),c=f,d=g};this.set_size_graphical=function(){};this.set_scale=function(){};this.update_cursor_scanline=function(){};this.update_cursor=
224
- function(){};this.update_buffer=function(){};this.get_text_screen=function(){for(var f=[],g=0;g<d;g++)f.push(this.get_text_row(g));return f};this.get_text_row=function(f){var g=f*c*3;f=g+3*c;let h=null,l=null,m="";for(;g<f;g+=3){const n=e[b[g]],p=b[g+1],q=b[g+2];let r="";h!==p&&(r+=`\x1B[48;${`2;${(p&16711680)>>16};${(p&65280)>>8};${p&255}`}m`,h=p);l!==q&&(r+=`\x1B[38;${`2;${(q&16711680)>>16};${(q&65280)>>8};${q&255}`}m`,l=q);m+=r+n}return m+"\u001b[0m"};this.set_size_text(80,25)}function dc(a){function b(g){f.enabled&&
225
- (f.send_char(g.which),g.preventDefault())}function c(g){var h=g.which;8===h?(f.send_char(127),g.preventDefault()):9===h&&(f.send_char(9),g.preventDefault())}function d(g){if(f.enabled){for(var h=g.clipboardData.getData("text/plain"),l=0;l<h.length;l++)f.send_char(h.charCodeAt(l));g.preventDefault()}}function e(g){g.target!==a&&a.blur()}var f=this;this.enabled=!0;this.text="";this.text_new_line=!1;this.last_update=0;this.destroy=function(){this.enabled=!1;a.removeEventListener("keypress",b,!1);a.removeEventListener("keydown",
226
- c,!1);a.removeEventListener("paste",d,!1);window.removeEventListener("mousedown",e,!1)};this.init=function(){this.destroy();this.enabled=!0;a.style.display="block";a.addEventListener("keypress",b,!1);a.addEventListener("keydown",c,!1);a.addEventListener("paste",d,!1);window.addEventListener("mousedown",e,!1)};this.init();this.show_char=function(g){"\b"===g?(this.text=this.text.slice(0,-1),this.update()):"\r"!==g&&(this.text+=g,"\n"===g&&(this.text_new_line=!0),this.update())};this.update=function(){var g=
227
- Date.now(),h=g-this.last_update;16>h?void 0===this.update_timer&&(this.update_timer=setTimeout(()=>{this.update_timer=void 0;this.last_update=Date.now();this.render()},16-h)):(void 0!==this.update_timer&&(clearTimeout(this.update_timer),this.update_timer=void 0),this.last_update=g,this.render())};this.render=function(){a.value=this.text;this.text_new_line&&(this.text_new_line=!1,a.scrollTop=1E9)};this.send_char=function(){}}function ec(a,b){var c=Reflect.construct(dc,[a],ec);c.send_char=function(d){b.send("serial0-input",
228
- d)};b.register("serial0-output-byte",function(d){d=String.fromCharCode(d);c.show_char&&c.show_char(d)},c);return c}Reflect.setPrototypeOf(ec.prototype,dc.prototype);Reflect.setPrototypeOf(ec,dc);function fc(a,b){var c=Reflect.construct(dc,[a],fc);c.send_char=function(e){b.send("virtio-console0-input-bytes",new Uint8Array([e]))};const d=new TextDecoder;b.register("virtio-console0-output-bytes",function(e){for(const f of d.decode(e))c.show_char&&c.show_char(f)},c);return c}Reflect.setPrototypeOf(fc.prototype,
229
- dc.prototype);Reflect.setPrototypeOf(fc,dc);function mc(a,b){this.element=a;var c=this.term=new b({logLevel:"off",convertEol:"true"});this.destroy=function(){this.on_data_disposable&&this.on_data_disposable.dispose();c.dispose()}}mc.prototype.show=function(){this.term&&this.term.open(this.element)};function nc(a,b,c){if(c){var d=Reflect.construct(mc,[a,c],nc);b.register("serial0-output-byte",function(f){d.term.write(Uint8Array.of(f))},d);var e=new TextEncoder;d.on_data_disposable=d.term.onData(function(f){for(const g of e.encode(f))b.send("serial0-input",
230
- g)});return d}}Reflect.setPrototypeOf(nc.prototype,mc.prototype);Reflect.setPrototypeOf(nc,mc);function oc(a,b,c){if(c){var d=Reflect.construct(mc,[a,c],oc);b.register("virtio-console0-output-bytes",function(f){d.term.write(f)},d);var e=new TextEncoder;d.on_data_disposable=d.term.onData(function(f){b.send("virtio-console0-input-bytes",e.encode(f))});return d}}Reflect.setPrototypeOf(oc.prototype,mc.prototype);Reflect.setPrototypeOf(oc,mc);function pc(a,b){b=b.id||0;this.bus=a;this.bus_send_msgid=`net${b}-send`;
231
- this.bus_recv_msgid=`net${b}-receive`;this.channel=new BroadcastChannel(`v86-inbrowser-${b}`);this.is_open=!0;this.nic_to_hub_fn=c=>{this.channel.postMessage(c)};this.bus.register(this.bus_send_msgid,this.nic_to_hub_fn,this);this.hub_to_nic_fn=c=>{this.bus.send(this.bus_recv_msgid,c.data)};this.channel.addEventListener("message",this.hub_to_nic_fn)}pc.prototype.destroy=function(){this.is_open&&(this.bus.unregister(this.bus_send_msgid,this.nic_to_hub_fn),this.channel.removeEventListener("message",
232
- this.hub_to_nic_fn),this.channel.close(),this.is_open=!1)};const qc={A:[],D:"custom",E:[0,1,1],H:[0,0,0],I:[3,3],L:[0,3,1],M:[0,2,1],O:[0,0,0],P:[],Q:[0,1,0],S:[0,5],T:[],V:[0,1,0],X:[0,4,0],Z:[0,0,0],"&C":[0,1,1],"&D":[0,2,2],"&F":[0,0,0],"&K":[0,6,3]},rc={[0]:"OK",[1]:"CONNECT",[2]:"RING",[3]:"NO CARRIER",[4]:"ERROR"},sc=/^ws[s]?:\/\//i,tc=new TextEncoder,uc=new TextDecoder;function G(a,b){this.bus=a;this.uart=b.uart;this.cli_buffer=new Uint8Array(256);this.rts_state=this.dtr_state=this.destroyed=
233
- !1;this.sreg=new Uint8Array(6);this.in_data_mode=!1;this.data_mode_send_buffer=new Uint8Array(512);this.data_mode_send_cursor=0;this.data_mode_esc_timer=this.data_mode_send_timer=null;this.phonebook=b.phonebook||{};this.socket=null;this.reset();this.bus.register(`serial${this.uart}-data-terminal-ready-output`,this.uart_dtr_changed,this);this.bus.register(`serial${this.uart}-request-to-send-output`,this.uart_rts_changed,this);this.bus.register(`serial${this.uart}-output-byte`,this.uart_byte_received,
234
- this)}G.prototype.initialize=function(){this.uart_set_dsr(!0);this.uart_set_cts(!0);this.uart_set_ring(!1);this.uart_set_dcd(!1)};G.prototype.destroy=function(){this.destroyed=!0;this.bus.unregister(`serial${this.uart}-data-terminal-ready-output`,this.uart_dtr_changed);this.bus.unregister(`serial${this.uart}-request-to-send-output`,this.uart_rts_changed);this.bus.unregister(`serial${this.uart}-output-byte`,this.uart_byte_received);this.cancel_data_mode_send_timer();this.cancel_data_mode_esc_timer();
235
- this.socket&&this.socket.close()};G.prototype.cancel_data_mode_send_timer=function(){null!==this.data_mode_send_timer&&(clearTimeout(this.data_mode_send_timer),this.data_mode_send_timer=null)};G.prototype.cancel_data_mode_esc_timer=function(){null!==this.data_mode_esc_timer&&(clearTimeout(this.data_mode_esc_timer),this.data_mode_esc_timer=null)};G.prototype.reset=function(){this.do_echo=!0;this.cli_cursor=0;this.resp_suppress=this.cli_overflow=!1;this.use_rtscts_flowctrl=this.resp_verbose=!0;this.dcd_always_on=
236
- this.use_tone_dialling=!1;this.dtr_low_behaviour=2;this.data_mode_esc_count=this.uart_recv_tm=0;this.reset_on_disconnect=!1;this.sreg[0]=0;this.sreg[1]=0;this.sreg[2]=43;this.sreg[3]=13;this.sreg[4]=10;this.sreg[5]=8};G.prototype.uart_set_dcd=function(a){this.bus.send(`serial${this.uart}-carrier-detect-input`,a)};G.prototype.uart_set_ring=function(a){this.bus.send(`serial${this.uart}-ring-indicator-input`,a)};G.prototype.uart_set_dsr=function(a){this.bus.send(`serial${this.uart}-data-set-ready-input`,
237
- a)};G.prototype.uart_set_cts=function(a){this.bus.send(`serial${this.uart}-clear-to-send-input`,a)};G.prototype.uart_write_byte=function(a){this.bus.send(`serial${this.uart}-input`,a)};G.prototype.uart_write=function(a){for(const b of tc.encode(a))this.uart_write_byte(b)};G.prototype.uart_dtr_changed=function(a){a=!!a;this.dtr_state!==a&&(this.dtr_state=a,this.socket&&!a&&(1===this.dtr_low_behaviour?(this.enter_cli_mode(),this.cli_write_response_code(0)):2===this.dtr_low_behaviour&&this.socket.close()))};
238
- G.prototype.uart_rts_changed=function(a){a=!!a;this.rts_state!==a&&(this.rts_state=a)};G.prototype.uart_byte_received=function(a){this.cancel_data_mode_esc_timer();this.in_data_mode?this.data_mode_uart_recv(a):this.cli_mode_uart_recv(a)};G.prototype.enter_cli_mode=function(){this.in_data_mode&&(this.in_data_mode=!1,this.cancel_data_mode_esc_timer(),this.cancel_data_mode_send_timer(),this.data_mode_flush(),this.uart_set_dsr(!0),this.uart_set_cts(!0),this.uart_set_ring(!1),this.dcd_always_on||this.uart_set_dcd(null!==
239
- this.socket))};G.prototype.enter_data_mode=function(){this.in_data_mode||(this.in_data_mode=!0,this.data_mode_send_cursor=0,this.uart_set_ring(!1),this.dcd_always_on||this.uart_set_dcd(!0))};G.prototype.flush_escape_buffer=function(){for(;0<this.data_mode_esc_count;this.data_mode_esc_count--)this.in_data_mode?this.data_mode_send(this.sreg[2]):this.uart_write_byte(this.sreg[2])};G.prototype.data_mode_send=function(a){this.socket&&(this.cancel_data_mode_send_timer(),this.data_mode_send_buffer[this.data_mode_send_cursor++]=
240
- a,this.data_mode_send_cursor===this.data_mode_send_buffer.byteLength?this.data_mode_flush():this.data_mode_send_timer=setTimeout(()=>{this.data_mode_flush()},5))};G.prototype.data_mode_flush=function(){this.data_mode_send_cursor&&this.socket&&this.socket.readyState===WebSocket.OPEN&&(this.data_mode_send_cursor===this.data_mode_send_buffer.byteLength?this.socket.send(this.data_mode_send_buffer):this.socket.send(this.data_mode_send_buffer.subarray(0,this.data_mode_send_cursor)));this.data_mode_send_cursor=
241
- 0};G.prototype.data_mode_uart_recv=function(a){a===this.sreg[2]&&3>this.data_mode_esc_count&&(0<this.data_mode_esc_count||1E3<performance.now()-this.uart_recv_tm)?3>++this.data_mode_esc_count?this.data_mode_esc_timer=setTimeout(()=>{this.data_mode_esc_timer=null;this.flush_escape_buffer()},200):this.data_mode_esc_timer=setTimeout(()=>{this.data_mode_esc_timer=null;this.enter_cli_mode();this.flush_escape_buffer();this.cli_write_response_code(0)},1E3):(this.uart_recv_tm=performance.now(),this.flush_escape_buffer(),
242
- this.data_mode_send(a))};G.prototype.cli_mode_uart_recv=function(a){this.do_echo&&(this.uart_write_byte(a),a===this.sreg[5]&&(this.uart_write_byte(32),this.uart_write_byte(this.sreg[5])));switch(a){case this.sreg[5]:0<this.cli_cursor&&this.cli_cursor--;break;case this.sreg[3]:this.cli_overflow?(uc.decode(this.cli_buffer.buffer),this.cli_overflow=!1):this.cli_exec(uc.decode(this.cli_buffer.slice(0,this.cli_cursor)).replace(/\s/g,""));this.cli_cursor=0;break;case this.sreg[4]:break;default:this.cli_cursor<
243
- this.cli_buffer.length?this.cli_buffer[this.cli_cursor++]=a:(this.cli_overflow=!0,this.uart_write_byte(7))}};G.prototype.cli_decode_arg=function(a,b){if(void 0===b){if(a.length)return 2<a.length?a[2]:!1}else if(2>a.length||b<a[0]||b>a[1])return!1;return b};G.prototype.cli_translate_dial_address=function(a,b){let c;if(a in this.phonebook)c=this.phonebook[a];else if(a.length){const e=a.match(/(\d{1,3})[^\d]*(\d{1,3})[^\d]*(\d{1,3})[^\d]*(\d{1,3})[^\d]*(\d{0,5})/);if(e){var d=(m,n)=>{if(e[m].length)return m=
244
- Number(e[m]),m<n?m:-1};const f=d(1,256),g=d(2,256),h=d(3,256),l=d(4,256);d=d(5,65536);0<=f&&0<=g&&0<=h&&0<=l&&(void 0===d||0<=d)&&(c=void 0===d?`${f}.${g}.${h}.${l}`:`${f}.${g}.${h}.${l}:${d}`)}void 0===c&&(c=a);sc.test(c)||(c=(b?"wss://":"ws://")+c)}return c};G.prototype.cli_exec_dial=function(a,b){let c=!0,d=this.use_tone_dialling;var e=a.lastIndexOf(";");0<=e&&(c=!1,a=a.substring(0,e));b<a.length&&(e=a[b].toUpperCase(),"T"===e||"P"===e)&&(b++,d="T"===e);b<a.length&&'"'===a[b]&&(b++,e=a.indexOf('"',
245
- b),0<=e&&(a=a.substring(0,e)));a=a.substring(b);a=this.cli_translate_dial_address(a,d);if(void 0===a)this.cli_write_response_code(4);else{try{this.socket=new WebSocket(a)}catch(f){this.cli_write_response_code(4);return}this.socket.binaryType="arraybuffer";this.socket.addEventListener("open",()=>{c?(this.enter_data_mode(),this.cli_write_response_code(1)):this.cli_write_response_code(0)});this.socket.addEventListener("message",f=>{if(this.in_data_mode&&(!this.use_rtscts_flowctrl||this.rts_state)){const g=
246
- new Uint8Array(f.data);for(let h=0;h<f.data.byteLength;h++)this.uart_write_byte(g[h])}});this.socket.addEventListener("close",()=>{this.socket=null;this.destroyed||(this.enter_cli_mode(),this.reset_on_disconnect&&(this.reset(),this.reset_on_disconnect=!1),this.cli_write_response_code(3))})}};G.prototype.cli_exec=function(a){const b=a.length;if(0===b)this.socket&&this.socket.readyState===WebSocket.CONNECTING?this.socket.close():this.cli_write_response_code(0);else{var c=a.search(/(at|AT)/);if(!(0>
247
- c)){c+=2;for(var d=()=>{const g=c;let h=0;for(;c<b;){const l=a.charCodeAt(c)-48;if(0>l||9<l)break;else h=10*h+l,c++}return c===g?void 0:h},e=!0;c<b&&!0===e;){var f=a[c++].toUpperCase();c<b&&"&"===f&&(f+=a[c++].toUpperCase());if(!(f in qc)){e=4;break}const g=qc[f];let h;if("custom"!==g&&(h=this.cli_decode_arg(g,d()),!1===h)){e=4;break}switch(f){case "D":this.socket?e=4:(this.cli_exec_dial(a,c),e=!1);break;case "E":this.do_echo=1===h;break;case "H":this.socket?(this.socket.close(),e=!1):e=4;break;case "I":this.cli_write_info_text("V86 Modem Emulation");
248
- break;case "L":break;case "M":break;case "O":this.socket?(this.enter_data_mode(),e=1):e=4;break;case "P":this.use_tone_dialling=!1;break;case "Q":this.resp_suppress=1===h;break;case "S":c<b&&"?"===a[c]?(c++,this.cli_write_info_text(this.sreg[h].toString().padStart(3,"0"))):c<b&&"="===a[c]?(c++,f=d(),void 0!==f&&256>f?this.sreg[h]=f:e=4):e=4;break;case "T":this.use_tone_dialling=!0;break;case "V":this.resp_verbose=1===h;break;case "X":break;case "Z":case "&F":this.socket?(this.reset_on_disconnect=
249
- !0,this.socket.close(),e=!1):this.reset();break;case "&C":(this.dcd_always_on=0===h)?this.uart_set_dcd(!0):this.uart_set_dcd(null!==this.socket);break;case "&D":this.dtr_low_behaviour=h;break;case "&K":0===h||3===h?this.use_rtscts_flowctrl=3===h:e=4;break;default:e=4}}!0===e?this.cli_write_response_code(0):"number"===typeof e&&this.cli_write_response_code(e)}}};G.prototype.cli_write_info_text=function(a){this.resp_verbose&&(this.uart_write_byte(this.sreg[3]),this.uart_write_byte(this.sreg[4]));this.uart_write(a);
250
- this.uart_write_byte(this.sreg[3]);this.uart_write_byte(this.sreg[4])};G.prototype.cli_write_response_code=function(a){if(!this.resp_suppress){const b=rc[a in rc?a:4];this.resp_verbose?(this.uart_write_byte(this.sreg[3]),this.uart_write_byte(this.sreg[4]),this.uart_write(b),this.uart_write_byte(this.sreg[3]),this.uart_write_byte(this.sreg[4])):(this.uart_write(a.toString()),this.uart_write_byte(this.sreg[3]))}};function vc(){this.filedata=new Map}vc.prototype.read=async function(a,b,c){return(a=this.filedata.get(a))?
251
- a.subarray(b,b+c):null};vc.prototype.cache=async function(a,b){this.filedata.set(a,b)};vc.prototype.uncache=function(a){this.filedata.delete(a)};function wc(a,b,c){b.endsWith("/")||(b+="/");this.storage=a;this.baseurl=b;this.zstd_decompress=c}wc.prototype.load_from_server=function(a,b){return new Promise(c=>{pa(this.baseurl+a,{done:async d=>{d=new Uint8Array(d);a.endsWith(".zst")&&(d=new Uint8Array(this.zstd_decompress(b,d)));await this.cache(a,d);c(d)}})})};wc.prototype.read=async function(a,b,c,
252
- d){const e=await this.storage.read(a,b,c,d);return e?e:(await this.load_from_server(a,d)).subarray(b,b+c)};wc.prototype.cache=async function(a,b){return await this.storage.cache(a,b)};wc.prototype.uncache=function(a){this.storage.uncache(a)};const xc=new TextDecoder,yc=new TextEncoder;function I(a,b,c,d){for(var e,f=0,g=0;g<a.length;g++)switch(e=b[g],a[g]){case "w":c[d++]=e&255;c[d++]=e>>8&255;c[d++]=e>>16&255;c[d++]=e>>24&255;f+=4;break;case "d":c[d++]=e&255;c[d++]=e>>8&255;c[d++]=e>>16&255;c[d++]=
253
- 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 h=d,l=0;c[d++]=0;c[d++]=0;f+=2;e=yc.encode(e);f+=e.byteLength;l+=e.byteLength;c.set(e,d);d+=e.byteLength;c[h+0]=l&255;c[h+1]=l>>8&255;break;case "Q":I(["b","w","d"],[e.type,e.version,e.path],c,d),d+=13,f+=13}return f}function J(a,b,c){let d=c.offset;for(var e=[],f=0;f<a.length;f++)switch(a[f]){case "w":var g=b[d++];g+=b[d++]<<8;g+=b[d++]<<16;g+=b[d++]<<24>>>
254
- 0;e.push(g);break;case "d":g=b[d++];g+=b[d++]<<8;g+=b[d++]<<16;g+=b[d++]<<24>>>0;d+=4;e.push(g);break;case "h":g=b[d++];e.push(g+(b[d++]<<8));break;case "b":e.push(b[d++]);break;case "s":g=b[d++];g+=b[d++]<<8;var h=b.slice(d,d+g);d+=g;e.push(xc.decode(h));break;case "Q":c.offset=d,g=J(["b","w","d"],b,c),d=c.offset,e.push({type:g[0],version:g[1],path:g[2]})}c.offset=d;return e}const zc=new TextEncoder;function N(a,b){this.inodes=[];this.storage=a;this.qidcounter=b||{last_qidnumber:0};this.inodedata=
255
- {};this.total_size=274877906944;this.used_size=0;this.mounts=[];this.CreateDirectory("",-1)}N.prototype.get_state=function(){let a=[];a[0]=this.inodes;a[1]=this.qidcounter.last_qidnumber;a[2]=[];for(const [b,c]of Object.entries(this.inodedata))0===(this.inodes[b].mode&16384)&&a[2].push([b,c]);a[3]=this.total_size;a[4]=this.used_size;return a=a.concat(this.mounts)};N.prototype.set_state=function(a){this.inodes=a[0].map(b=>{const c=new Ac(0);c.set_state(b);return c});this.qidcounter.last_qidnumber=
256
- 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.load_from_json=function(a){if(3!==a.version)throw"The filesystem JSON format has changed. Please recreate the filesystem JSON.";var b=a.fsroot;this.used_size=a.size;for(a=0;a<b.length;a++)this.LoadRecursive(b[a],0)};N.prototype.LoadRecursive=function(a,b){var c=this.CreateInode();const d=a[0];c.size=a[1];c.mtime=
257
- a[2];c.ctime=c.mtime;c.atime=c.mtime;c.mode=a[3];c.uid=a[4];c.gid=a[5];var e=c.mode&61440;16384===e?(this.PushInode(c,b,d),this.LoadDir(this.inodes.length-1,a[6])):32768===e?(c.status=2,c.sha256sum=a[6],this.PushInode(c,b,d)):40960===e?(c.symlink=a[6],this.PushInode(c,b,d)):49152!==e&&y(e)};N.prototype.LoadDir=function(a,b){for(var c=0;c<b.length;c++)this.LoadRecursive(b[c],a)};N.prototype.should_be_linked=function(a){return!this.is_forwarder(a)||0===a.foreign_id};N.prototype.link_under_dir=function(a,
258
- b,c){const d=this.inodes[b],e=this.inodes[a];this.is_forwarder(e);this.IsDirectory(a);this.should_be_linked(d);e.direntries.has(c);e.direntries.set(c,b);d.nlinks++;this.IsDirectory(b)&&(d.direntries.has(".."),d.direntries.has(".")||d.nlinks++,d.direntries.set(".",b),d.direntries.set("..",a),e.nlinks++)};N.prototype.unlink_from_dir=function(a,b){const c=this.Search(a,b),d=this.inodes[c],e=this.inodes[a];this.is_forwarder(e);this.IsDirectory(a);e.direntries.delete(b)&&(d.nlinks--,this.IsDirectory(c)&&
259
- (d.direntries.get(".."),d.direntries.delete(".."),e.nlinks--))};N.prototype.PushInode=function(a,b,c){-1!==b?(this.inodes.push(a),a.fid=this.inodes.length-1,this.link_under_dir(b,a.fid,c)):0===this.inodes.length&&(this.inodes.push(a),a.direntries.set(".",0),a.direntries.set("..",0),a.nlinks=2)};function Ac(a){this.direntries=new Map;this.minor=this.major=this.mtime=this.atime=this.ctime=this.fid=this.gid=this.uid=this.size=this.status=0;this.symlink="";this.mode=493;this.qid={type:0,version:0,path:a};
260
- this.caps=void 0;this.nlinks=0;this.sha256sum="";this.locks=[];this.foreign_id=this.mount_id=-1}Ac.prototype.get_state=function(){const a=[];a[0]=this.mode;a[1]=16384===(this.mode&61440)?[...this.direntries]:32768===(this.mode&61440)?this.sha256sum:40960===(this.mode&61440)?this.symlink:49152===(this.mode&61440)?[this.minor,this.major]:null;a[2]=this.locks;a[3]=this.status;a[4]=this.size;a[5]=this.uid;a[6]=this.gid;a[7]=this.fid;a[8]=this.ctime;a[9]=this.atime;a[10]=this.mtime;a[11]=this.qid.version;
261
- a[12]=this.qid.path;a[13]=this.nlinks;return a};Ac.prototype.set_state=function(a){this.mode=a[0];if(16384===(this.mode&61440)){this.direntries=new Map;for(const [b,c]of a[1])this.direntries.set(b,c)}else 32768===(this.mode&61440)?this.sha256sum=a[1]:40960===(this.mode&61440)?this.symlink=a[1]:49152===(this.mode&61440)&&([this.minor,this.major]=a[1]);this.locks=[];for(const b of a[2]){const c=new Bc;c.set_state(b);this.locks.push(c)}this.status=a[3];this.size=a[4];this.uid=a[5];this.gid=a[6];this.fid=
262
- a[7];this.ctime=a[8];this.atime=a[9];this.mtime=a[10];this.qid.type=(this.mode&61440)>>8;this.qid.version=a[11];this.qid.path=a[12];this.nlinks=a[13]};N.prototype.divert=function(a,b){const c=this.Search(a,b),d=this.inodes[c],e=new Ac(-1);this.IsDirectory(c);Object.assign(e,d);const f=this.inodes.length;this.inodes.push(e);e.fid=f;this.is_forwarder(d)&&this.mounts[d.mount_id].backtrack.set(d.foreign_id,f);this.should_be_linked(d)&&(this.unlink_from_dir(a,b),this.link_under_dir(a,f,b));if(this.IsDirectory(c)&&
263
- !this.is_forwarder(d))for(const [g,h]of e.direntries)"."!==g&&".."!==g&&this.IsDirectory(h)&&this.inodes[h].direntries.set("..",f);this.inodedata[f]=this.inodedata[c];delete this.inodedata[c];d.direntries=new Map;d.nlinks=0;return f};N.prototype.copy_inode=function(a,b){Object.assign(b,a,{fid:b.fid,direntries:b.direntries,nlinks:b.nlinks})};N.prototype.CreateInode=function(){const a=Math.round(Date.now()/1E3),b=new Ac(++this.qidcounter.last_qidnumber);b.atime=b.ctime=b.mtime=a;return b};N.prototype.CreateDirectory=
264
- function(a,b){var c=this.inodes[b];if(0<=b&&this.is_forwarder(c))return b=c.foreign_id,a=this.follow_fs(c).CreateDirectory(a,b),this.create_forwarder(c.mount_id,a);c=this.CreateInode();c.mode=16895;0<=b&&(c.uid=this.inodes[b].uid,c.gid=this.inodes[b].gid,c.mode=this.inodes[b].mode&511|16384);c.qid.type=64;this.PushInode(c,b,a);this.NotifyListeners(this.inodes.length-1,"newdir");return this.inodes.length-1};N.prototype.CreateFile=function(a,b){var c=this.inodes[b];if(this.is_forwarder(c))return b=
265
- c.foreign_id,a=this.follow_fs(c).CreateFile(a,b),this.create_forwarder(c.mount_id,a);c=this.CreateInode();c.uid=this.inodes[b].uid;c.gid=this.inodes[b].gid;c.qid.type=128;c.mode=this.inodes[b].mode&438|32768;this.PushInode(c,b,a);this.NotifyListeners(this.inodes.length-1,"newfile");return this.inodes.length-1};N.prototype.CreateNode=function(a,b,c,d){var e=this.inodes[b];if(this.is_forwarder(e))return b=e.foreign_id,a=this.follow_fs(e).CreateNode(a,b,c,d),this.create_forwarder(e.mount_id,a);e=this.CreateInode();
266
- e.major=c;e.minor=d;e.uid=this.inodes[b].uid;e.gid=this.inodes[b].gid;e.qid.type=192;e.mode=this.inodes[b].mode&438;this.PushInode(e,b,a);return this.inodes.length-1};N.prototype.CreateSymlink=function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,a=this.follow_fs(d).CreateSymlink(a,b,c),this.create_forwarder(d.mount_id,a);d=this.CreateInode();d.uid=this.inodes[b].uid;d.gid=this.inodes[b].gid;d.qid.type=160;d.symlink=c;d.mode=40960;this.PushInode(d,b,a);return this.inodes.length-
267
- 1};N.prototype.CreateTextFile=async function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,c=await this.follow_fs(d).CreateTextFile(a,b,c),this.create_forwarder(d.mount_id,c);d=this.CreateFile(a,b);b=this.inodes[d];a=new Uint8Array(c.length);b.size=c.length;for(b=0;b<c.length;b++)a[b]=c.charCodeAt(b);await this.set_data(d,a);return d};N.prototype.CreateBinaryFile=async function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,c=await this.follow_fs(d).CreateBinaryFile(a,
268
- b,c),this.create_forwarder(d.mount_id,c);d=this.CreateFile(a,b);a=this.inodes[d];b=new Uint8Array(c.length);b.set(c);await this.set_data(d,b);a.size=c.length;return d};N.prototype.OpenInode=async function(a,b){var c=this.inodes[a];if(this.is_forwarder(c))return await this.follow_fs(c).OpenInode(c.foreign_id,b);16384===(c.mode&61440)&&this.FillDirectory(a)};N.prototype.CloseInode=async function(a){var b=this.inodes[a];if(this.is_forwarder(b))return await this.follow_fs(b).CloseInode(b.foreign_id);
269
- 2===b.status&&this.storage.uncache(b.sha256sum);4===b.status&&(b.status=-1,await this.DeleteData(a))};N.prototype.Rename=async function(a,b,c,d){if(a===c&&b===d)return 0;var e=this.Search(a,b);if(-1===e)return-2;var f=this.GetFullPath(a)+"/"+b;if(-1!==this.Search(c,d)){var g=this.Unlink(c,d);if(0>g)return g}var h=this.inodes[e],l=this.inodes[a];g=this.inodes[c];if(this.is_forwarder(l)||this.is_forwarder(g))if(this.is_forwarder(l)&&l.mount_id===g.mount_id){if(a=await this.follow_fs(l).Rename(l.foreign_id,
270
- b,g.foreign_id,d),0>a)return a}else{if(this.is_a_root(e)||!this.IsDirectory(e)&&1<this.GetInode(e).nlinks)return-1;l=this.divert(a,b);const m=this.GetInode(e),n=await this.Read(l,0,m.size);this.is_forwarder(g)?(c=this.follow_fs(g),d=this.IsDirectory(l)?c.CreateDirectory(d,g.foreign_id):c.CreateFile(d,g.foreign_id),c=c.GetInode(d),this.copy_inode(m,c),this.set_forwarder(e,g.mount_id,d)):(this.delete_forwarder(h),this.copy_inode(m,h),this.link_under_dir(c,e,d));await this.ChangeSize(e,m.size);n&&n.length&&
271
- await this.Write(e,0,n.length,n);if(this.IsDirectory(e))for(const p of this.GetChildren(l))if(g=await this.Rename(l,p,e,p),0>g)return g;await this.DeleteData(l);a=this.Unlink(a,b);if(0>a)return a}else this.unlink_from_dir(a,b),this.link_under_dir(c,e,d),h.qid.version++;this.NotifyListeners(e,"rename",{oldpath:f});return 0};N.prototype.Write=async function(a,b,c,d){this.NotifyListeners(a,"write");var e=this.inodes[a];if(this.is_forwarder(e))a=e.foreign_id,await this.follow_fs(e).Write(a,b,c,d);else{var f=
272
- await this.get_buffer(a);!f||f.length<b+c?(await this.ChangeSize(a,Math.floor(3*(b+c)/2)),e.size=b+c,f=await this.get_buffer(a)):e.size<b+c&&(e.size=b+c);d&&f.set(d.subarray(0,c),b);await this.set_data(a,f)}};N.prototype.Read=async function(a,b,c){const d=this.inodes[a];return this.is_forwarder(d)?(a=d.foreign_id,await this.follow_fs(d).Read(a,b,c)):await this.get_data(a,b,c)};N.prototype.Search=function(a,b){a=this.inodes[a];if(this.is_forwarder(a)){const c=a.foreign_id;b=this.follow_fs(a).Search(c,
273
- b);return-1===b?-1:this.get_forwarder(a.mount_id,b)}b=a.direntries.get(b);return void 0===b?-1:b};N.prototype.CountUsedInodes=function(){let a=this.inodes.length;for(const {fs:b,backtrack:c}of this.mounts)a+=b.CountUsedInodes(),a-=c.size;return a};N.prototype.CountFreeInodes=function(){let a=1048576;for(const {fs:b}of this.mounts)a+=b.CountFreeInodes();return a};N.prototype.GetTotalSize=function(){let a=this.used_size;for(const {fs:b}of this.mounts)a+=b.GetTotalSize();return a};N.prototype.GetSpace=
274
- function(){let a=this.total_size;for(const {fs:b}of this.mounts)a+=b.GetSpace();return this.total_size};N.prototype.GetDirectoryName=function(a){const b=this.inodes[this.GetParent(a)];if(this.is_forwarder(b))return this.follow_fs(b).GetDirectoryName(this.inodes[a].foreign_id);if(!b)return"";for(const [c,d]of b.direntries)if(d===a)return c;return""};N.prototype.GetFullPath=function(a){this.IsDirectory(a);for(var b="";0!==a;)b="/"+this.GetDirectoryName(a)+b,a=this.GetParent(a);return b.substring(1)};
275
- N.prototype.Link=function(a,b,c){if(this.IsDirectory(b))return-1;const d=this.inodes[a],e=this.inodes[b];if(this.is_forwarder(d))return this.is_forwarder(e)&&e.mount_id===d.mount_id?this.follow_fs(d).Link(d.foreign_id,e.foreign_id,c):-1;if(this.is_forwarder(e))return-1;this.link_under_dir(a,b,c);return 0};N.prototype.Unlink=function(a,b){if("."===b||".."===b)return-1;const c=this.Search(a,b),d=this.inodes[c],e=this.inodes[a];if(this.is_forwarder(e))return this.is_forwarder(d),a=e.foreign_id,this.follow_fs(e).Unlink(a,
276
- b);if(this.IsDirectory(c)&&!this.IsEmpty(c))return-39;this.unlink_from_dir(a,b);0===d.nlinks&&(d.status=4,this.NotifyListeners(c,"delete"));return 0};N.prototype.DeleteData=async function(a){const b=this.inodes[a];this.is_forwarder(b)?await this.follow_fs(b).DeleteData(b.foreign_id):(b.size=0,delete this.inodedata[a])};N.prototype.get_buffer=async function(a){const b=this.inodes[a];return this.inodedata[a]?this.inodedata[a]:2===b.status?await this.storage.read(b.sha256sum,0,b.size,b.size):null};N.prototype.get_data=
277
- async function(a,b,c){const d=this.inodes[a];return this.inodedata[a]?this.inodedata[a].subarray(b,b+c):2===d.status?await this.storage.read(d.sha256sum,b,c,d.size):null};N.prototype.set_data=async function(a,b){this.inodedata[a]=b;2===this.inodes[a].status&&(this.inodes[a].status=0,this.storage.uncache(this.inodes[a].sha256sum))};N.prototype.GetInode=function(a){isNaN(a);a=this.inodes[a];return this.is_forwarder(a)?this.follow_fs(a).GetInode(a.foreign_id):a};N.prototype.ChangeSize=async function(a,
278
- b){var c=this.GetInode(a),d=await this.get_data(a,0,c.size);if(b!==c.size){var e=new Uint8Array(b);c.size=b;d&&e.set(d.subarray(0,Math.min(d.length,c.size)),0);await this.set_data(a,e)}};N.prototype.SearchPath=function(a){a=a.replace("//","/");a=a.split("/");0<a.length&&0===a[a.length-1].length&&a.pop();0<a.length&&0===a[0].length&&a.shift();const b=a.length;var c=-1,d=0;let e=null;for(var f=0;f<b;f++)if(c=d,d=this.Search(c,a[f]),!e&&this.is_forwarder(this.inodes[c])&&(e="/"+a.slice(f).join("/")),
279
- -1===d)return f<b-1?{id:-1,parentid:-1,name:a[f],forward_path:e}:{id:-1,parentid:c,name:a[f],forward_path:e};return{id:d,parentid:c,name:a[f],forward_path:e}};N.prototype.GetRecursiveList=function(a,b){if(this.is_forwarder(this.inodes[a])){const c=this.follow_fs(this.inodes[a]),d=this.inodes[a].mount_id,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&&".."!==
280
- 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--)this.Unlink(b[a].parentid,b[a].name)};N.prototype.DeleteNode=function(a){var b=this.SearchPath(a);-1!==b.id&&(32768===(this.inodes[b.id].mode&61440)?this.Unlink(b.parentid,b.name):16384===(this.inodes[b.id].mode&61440)&&(this.RecursiveDelete(a),this.Unlink(b.parentid,b.name)))};N.prototype.NotifyListeners=
281
- function(){};N.prototype.Check=function(){for(var a=1;a<this.inodes.length;a++)if(-1!==this.inodes[a].status&&(this.GetInode(a),this.IsDirectory(a))){const b=this.GetInode(a);this.IsDirectory(a)&&this.GetParent(a);for(const [c]of b.direntries)for(const d of c);}};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+zc.encode(d).length;a=this.inodedata[a]=new Uint8Array(c);
282
- b.size=c;c=0;for(const [d,e]of b.direntries)b=this.GetInode(e),c+=I(["Q","d","b","s"],[b.qid,c+13+8+1+2+zc.encode(d).length,b.mode>>12,d],a,c)}};N.prototype.RoundToDirentry=function(a,b){a=this.inodedata[a];if(b>=a.length)return a.length;let c=0;for(;;){const d=J(["Q","d"],a,{offset:c})[1];if(d>b)break;c=d}return c};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=
283
- 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;return!0};N.prototype.GetChildren=function(a){this.IsDirectory(a);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){this.IsDirectory(a);a=this.inodes[a];if(this.should_be_linked(a))return a.direntries.get("..");
284
- const b=this.follow_fs(a).GetParent(a.foreign_id);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};function Cc(a){this.fs=
285
- a;this.backtrack=new Map}Cc.prototype.get_state=function(){const a=[];a[0]=this.fs;a[1]=[...this.backtrack];return a};Cc.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];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;this.mounts[b].backtrack.set(c,a)};N.prototype.create_forwarder=function(a,b){const c=this.CreateInode(),d=this.inodes.length;
286
- this.inodes.push(c);c.fid=d;this.set_forwarder(d,a,b);return d};N.prototype.is_forwarder=function(a){return 5===a.status};N.prototype.is_a_root=function(a){return 0===this.GetInode(a).fid};N.prototype.get_forwarder=function(a,b){const c=this.mounts[a].backtrack.get(b);return void 0===c?this.create_forwarder(a,b):c};N.prototype.delete_forwarder=function(a){this.is_forwarder(a);a.status=-1;this.mounts[a.mount_id].backtrack.delete(a.foreign_id)};N.prototype.follow_fs=function(a){const b=this.mounts[a.mount_id];
287
- this.is_forwarder(a);return b.fs};N.prototype.Mount=function(a,b){a=this.SearchPath(a);if(-1===a.parentid)return-2;if(-1!==a.id)return-17;if(a.forward_path){var c=this.inodes[a.parentid];b=this.follow_fs(c).Mount(a.forward_path,b);return 0>b?b:this.get_forwarder(c.mount_id,b)}c=this.mounts.length;this.mounts.push(new Cc(b));b=this.create_forwarder(c,0);this.link_under_dir(a.parentid,b,a.name);return b};function Bc(){this.type=2;this.start=0;this.length=Infinity;this.proc_id=-1;this.client_id=""}Bc.prototype.get_state=
288
- function(){const a=[];a[0]=this.type;a[1]=this.start;a[2]=Infinity===this.length?0:this.length;a[3]=this.proc_id;a[4]=this.client_id;return a};Bc.prototype.set_state=function(a){this.type=a[0];this.start=a[1];this.length=0===a[2]?Infinity:a[2];this.proc_id=a[3];this.client_id=a[4]};Bc.prototype.clone=function(){const a=new Bc;a.set_state(this.get_state());return a};Bc.prototype.conflicts_with=function(a){return this.proc_id===a.proc_id&&this.client_id===a.client_id||2===this.type||2===a.type||1!==
289
- this.type&&1!==a.type||this.start+this.length<=a.start||a.start+a.length<=this.start?!1:!0};Bc.prototype.is_alike=function(a){return a.proc_id===this.proc_id&&a.client_id===this.client_id&&a.type===this.type};Bc.prototype.may_merge_after=function(a){return this.is_alike(a)&&a.start+a.length===this.start};N.prototype.DescribeLock=function(a,b,c,d,e){const f=new Bc;f.type=a;f.start=b;f.length=c;f.proc_id=d;f.client_id=e;return f};N.prototype.GetLock=function(a,b){a=this.inodes[a];if(this.is_forwarder(a)){var c=
290
- a.foreign_id;return this.follow_fs(a).GetLock(c,b)}for(c of a.locks)if(b.conflicts_with(c))return c.clone();return null};N.prototype.Lock=function(a,b,c){const d=this.inodes[a];if(this.is_forwarder(d))return a=d.foreign_id,this.follow_fs(d).Lock(a,b,c);b=b.clone();if(2!==b.type&&this.GetLock(a,b))return 1;for(c=0;c<d.locks.length;c++){a=d.locks[c];if(a.start+a.length<=b.start)continue;if(b.start+b.length<=a.start)break;if(a.proc_id!==b.proc_id||a.client_id!==b.client_id){a.conflicts_with(b);continue}var e=
291
- b.start+b.length;const f=b.start-a.start,g=a.start+a.length-e;if(0<f&&0<g&&a.type===b.type)return 0;0<f&&(a.length=f);if(0>=f&&0<g)a.start=e,a.length=g;else if(0<g){for(;c<d.locks.length&&d.locks[c].start<e;)c++;d.locks.splice(c,0,this.DescribeLock(a.type,e,g,a.proc_id,a.client_id))}else 0>=f&&(d.locks.splice(c,1),c--)}if(2!==b.type){c=b;a=!1;for(e=0;e<d.locks.length&&!(c.may_merge_after(d.locks[e])&&(d.locks[e].length+=b.length,c=d.locks[e],a=!0),b.start<=d.locks[e].start);e++);a||(d.locks.splice(e,
292
- 0,c),e++);for(;e<d.locks.length;e++)if(d.locks[e].is_alike(c)){d.locks[e].may_merge_after(c)&&(c.length+=d.locks[e].length,d.locks.splice(e,1));break}}return 0};N.prototype.read_dir=function(a){a=this.SearchPath(a);if(-1!==a.id)return a=this.GetInode(a.id),Array.from(a.direntries.keys()).filter(b=>"."!==b&&".."!==b)};N.prototype.read_file=function(a){a=this.SearchPath(a);if(-1===a.id)return Promise.resolve(null);const b=this.GetInode(a.id);return this.Read(a.id,0,b.size)};function O(a){this.cpu_is_running=
293
- !1;this.cpu_exception_hook=function(){};var b=Ha.create();this.bus=b[0];this.emulator_bus=b[1];var c,d;const e=new WebAssembly.Table({element:"anyfunc",initial:1924});b={cpu_exception_hook:g=>this.cpu_exception_hook(g),run_hardware_timers:function(g,h){return c.run_hardware_timers(g,h)},cpu_event_halt:()=>{this.emulator_bus.send("cpu-event-halt")},abort:function(){},microtick:F.microtick,get_rand_int:function(){return ca()},stop_idling:function(){return c.stop_idling()},io_port_read8:function(g){return c.io.port_read8(g)},
294
- io_port_read16:function(g){return c.io.port_read16(g)},io_port_read32:function(g){return c.io.port_read32(g)},io_port_write8:function(g,h){c.io.port_write8(g,h)},io_port_write16:function(g,h){c.io.port_write16(g,h)},io_port_write32:function(g,h){c.io.port_write32(g,h)},mmap_read8:function(g){return c.mmap_read8(g)},mmap_read32:function(g){return c.mmap_read32(g)},mmap_write8:function(g,h){c.mmap_write8(g,h)},mmap_write16:function(g,h){c.mmap_write16(g,h)},mmap_write32:function(g,h){c.mmap_write32(g,
295
- h)},mmap_write64:function(g,h,l){c.mmap_write64(g,h,l)},mmap_write128:function(g,h,l,m,n){c.mmap_write128(g,h,l,m,n)},log_from_wasm:function(g,h){ra(d,g,h)},console_log_from_wasm:function(g,h){g=ra(d,g,h);console.error(g)},dbg_trace_from_wasm:function(){},codegen_finalize:(g,h,l,m,n)=>{c.codegen_finalize(g,h,l,m,n)},jit_clear_func:g=>c.jit_clear_func(g),jit_clear_all_funcs:()=>c.jit_clear_all_funcs(),__indirect_function_table:e};let f=a.wasm_fn;f||(f=g=>new Promise(h=>{let l="v86.wasm",m="v86-fallback.wasm";
296
- a.wasm_path?(l=a.wasm_path,m=l.replace("v86.wasm","v86-fallback.wasm")):"undefined"===typeof window&&"string"===typeof __dirname?(l=__dirname+"/"+l,m=__dirname+"/"+m):(l="build/"+l,m="build/"+m);pa(l,{done:async n=>{try{const {instance:p}=await WebAssembly.instantiate(n,g);this.wasm_source=n;h(p.exports)}catch(p){pa(m,{done:async q=>{const {instance:r}=await WebAssembly.instantiate(q,g);this.wasm_source=q;h(r.exports)}})}},progress:n=>{this.emulator_bus.send("download-progress",{file_index:0,file_count:1,
297
- file_name:l,lengthComputable:n.lengthComputable,total:n.total,loaded:n.loaded})}})}));f({env:b}).then(g=>{d=g.memory;g.rust_init();g=this.v86=new F(this.emulator_bus,{exports:g,wasm_table:e});c=g.cpu;this.continue_init(g,a)});this.zstd_worker=null;this.zstd_worker_request_id=0}O.prototype.continue_init=async function(a,b){function c(q,r){switch(q){case "hda":e.hda=r;break;case "hdb":e.hdb=r;break;case "cdrom":e.cdrom=r;break;case "fda":e.fda=r;break;case "fdb":e.fdb=r;break;case "multiboot":e.multiboot=
298
- r.buffer;break;case "bzimage":e.bzimage=r.buffer;break;case "initrd":e.initrd=r.buffer;break;case "bios":e.bios=r.buffer;break;case "vga_bios":e.vga_bios=r.buffer;break;case "initial_state":e.initial_state=r.buffer;break;case "fs9p_json":e.fs9p_json=r}}async function d(){if(e.fs9p&&e.fs9p_json&&!e.initial_state&&(e.fs9p.load_from_json(e.fs9p_json),b.bzimage_initrd_from_filesystem)){const {bzimage_path:q,initrd_path:r}=this.get_bzimage_initrd_from_filesystem(e.fs9p),[x,C]=await Promise.all([e.fs9p.read_file(r),
299
- e.fs9p.read_file(q)]);c.call(this,"initrd",new z(x.buffer));c.call(this,"bzimage",new z(C.buffer))}this.serial_adapter&&this.serial_adapter.show&&this.serial_adapter.show();this.virtio_console_adapter&&this.virtio_console_adapter.show&&this.virtio_console_adapter.show();this.v86.init(e);this.modem&&this.modem.initialize();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",
300
- 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()},this);var e={},f=b.boot_order?b.boot_order:b.fda?801:b.hda?786:291;if(b.modem)switch(e.modem=b.modem,b.modem.uart){case 1:b.uart1=!0;break;case 2:b.uart2=!0;break;case 3:b.uart3=!0}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=
301
- 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=b.mac_address_translation;e.cpuid_level=b.cpuid_level;e.virtio_balloon=b.virtio_balloon;e.virtio_console=!!b.virtio_console;if(f=b.network_relay_url||b.net_device&&b.net_device.relay_url)"fetch"===f?this.network_adapter=new Wb(this.bus,b.net_device):"inbrowser"===f?this.network_adapter=new pc(this.bus,
302
- b.net_device):f.startsWith("wisp://")||f.startsWith("wisps://")?this.network_adapter=new Yb(f,this.bus,b.net_device):this.network_adapter=new pb(f,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 $b(this.bus));b.disable_mouse||(this.mouse_adapter=new ac(this.bus,f.container));this.screen_adapter=f.container?new xa(f,()=>this.v86.cpu.devices.vga&&this.v86.cpu.devices.vga.screen_fill_buffer()):
303
- f.ansi?new cc(f):new bc(f);e.screen=this.screen_adapter;e.screen_options=f;e.serial_console=b.serial_console||{type:"none"};b.serial_container_xtermjs?(e.serial_console.type="xtermjs",e.serial_console.container=b.serial_container_xtermjs):b.serial_container&&(e.serial_console.type="textarea",e.serial_console.container=b.serial_container);"xtermjs"===e.serial_console?.type?this.serial_adapter=new nc(e.serial_console.container,this.bus,e.serial_console.xterm_lib||window.Terminal):"textarea"===e.serial_console?.type&&
304
- (this.serial_adapter=new ec(e.serial_console.container,this.bus));f=b.virtio_console&&"boolean"===typeof b.virtio_console?{type:"none"}:b.virtio_console;"xtermjs"===f?.type?this.virtio_console_adapter=new oc(f.container,this.bus,f.xterm_lib||window.Terminal):"textarea"===f?.type&&(this.virtio_console_adapter=new fc(f.container,this.bus));e.modem&&(this.modem=new G(this.bus,e.modem));b.disable_speaker||(this.speaker_adapter=new jb(this.bus));var g=[];f=(q,r)=>{if(r)if(r.get&&r.set&&r.load)g.push({name:q,
305
- loadable:r});else{if("bios"===q||"vga_bios"===q||"initial_state"===q||"multiboot"===q||"bzimage"===q||"initrd"===q)r.async=!1;if("fda"===q||"fdb"===q)r.async=!1;r.url&&!r.async?g.push({name:q,url:r.url,size:r.size}):g.push({name:q,loadable:Ca(r,this.zstd_decompress_worker.bind(this))})}};b.state&&console.warn("Warning: Unknown option 'state'. Did you mean 'initial_state'?");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",
306
- b.initial_state);f("multiboot",b.multiboot);f("bzimage",b.bzimage);f("initrd",b.initrd);if(b.filesystem&&b.filesystem.handle9p)e.handle9p=b.filesystem.handle9p;else if(b.filesystem&&b.filesystem.proxy_url)e.proxy9p=b.filesystem.proxy_url;else if(b.filesystem){f=b.filesystem.basefs;var h=b.filesystem.baseurl;let q=new vc;h&&(q=new wc(q,h,this.zstd_decompress.bind(this)));e.fs9p=this.fs9p=new N(q);if(f){if("object"===typeof f){var l=f.size;f=f.url}g.push({name:"fs9p_json",url:f,size:l,as_json:!0})}}var m=
307
- this,n=g.length,p=function(q){if(q===n)setTimeout(d.bind(this),0);else{var r=g[q];r.loadable?(r.loadable.onload=function(){c.call(this,r.name,r.loadable);p(q+1)}.bind(this),r.loadable.load()):pa(r.url,{done:function(x){r.url.endsWith(".zst")&&"initial_state"!==r.name&&(x=this.zstd_decompress(r.size,new Uint8Array(x)));c.call(this,r.name,r.as_json?x:new z(x));p(q+1)}.bind(this),progress:function(x){200===x.target.status?m.emulator_bus.send("download-progress",{file_index:q,file_count:n,file_name:r.url,
308
- lengthComputable:x.lengthComputable,total:x.total||r.size,loaded:x.loaded}):m.emulator_bus.send("download-error",{file_index:q,file_count:n,file_name:r.url,request:x.target})},as_json:r.as_json})}}.bind(this);p(0)};O.prototype.zstd_decompress=function(a,b){const c=this.v86.cpu;this.zstd_context=c.zstd_create_ctx(b.length);(new Uint8Array(c.wasm_memory.buffer)).set(b,c.zstd_get_src_ptr(this.zstd_context));b=c.zstd_read(this.zstd_context,a);const d=c.wasm_memory.buffer.slice(b,b+a);c.zstd_read_free(b,
309
- a);c.zstd_free_ctx(this.zstd_context);this.zstd_context=null;return d};O.prototype.zstd_decompress_worker=async function(a,b){if(!this.zstd_worker){const c=URL.createObjectURL(new Blob(["("+function(){let d;globalThis.onmessage=function(e){if(d){var {src:f,decompressed_size:g,id:h}=e.data;e=d.exports;var l=e.zstd_create_ctx(f.length);(new Uint8Array(e.memory.buffer)).set(f,e.zstd_get_src_ptr(l));var m=e.zstd_read(l,g),n=e.memory.buffer.slice(m,m+g);e.zstd_read_free(m,g);e.zstd_free_ctx(l);postMessage({result:n,
310
- id:h},[n])}else l=Object.fromEntries("cpu_exception_hook run_hardware_timers cpu_event_halt microtick get_rand_int stop_idling io_port_read8 io_port_read16 io_port_read32 io_port_write8 io_port_write16 io_port_write32 mmap_read8 mmap_read32 mmap_write8 mmap_write16 mmap_write32 mmap_write64 mmap_write128 codegen_finalize jit_clear_func jit_clear_all_funcs".split(" ").map(p=>[p,()=>console.error("zstd worker unexpectedly called "+p)])),l.__indirect_function_table=new WebAssembly.Table({element:"anyfunc",
311
- initial:1024}),l.abort=()=>{throw Error("zstd worker aborted");},l.log_from_wasm=l.console_log_from_wasm=(p,q)=>{console.log(ra(d.exports.memory.buffer,p,q))},l.dbg_trace_from_wasm=()=>console.trace(),d=new WebAssembly.Instance(new WebAssembly.Module(e.data),{env:l})}}.toString()+")()"],{type:"text/javascript"}));this.zstd_worker=new Worker(c);URL.revokeObjectURL(c);this.zstd_worker.postMessage(this.wasm_source,[this.wasm_source])}return new Promise(c=>{const d=this.zstd_worker_request_id++,e=async f=>
312
- {f.data.id===d&&(this.zstd_worker.removeEventListener("message",e),c(f.data.result))};this.zstd_worker.addEventListener("message",e);this.zstd_worker.postMessage({src:b,decompressed_size:a,id:d},[b.buffer])})};O.prototype.get_bzimage_initrd_from_filesystem=function(a){const b=(a.read_dir("/")||[]).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),g=/vmlinuz/i.test(e)||/bzimage/i.test(e),h=/initrd/i.test(e)||
313
- /initramfs/i.test(e);!g||d&&f||(d=e);!h||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&&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();
314
- 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();this.virtio_console_adapter&&this.virtio_console_adapter.destroy();this.modem&&this.modem.destroy()};O.prototype.restart=function(){this.v86.restart()};O.prototype.add_listener=
315
- 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){this.v86.restore_state(a)};O.prototype.save_state=async function(){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=function(){return this.cpu_is_running};O.prototype.set_fda=async function(a){const b=this.v86.cpu.devices.fdc.drives[0];
316
- if(a.url&&!a.async)await new Promise(c=>{pa(a.url,{done:d=>{b.insert_disk(new z(d));c()}})});else{const c=Ca(a,this.zstd_decompress_worker.bind(this));c.onload=()=>{b.insert_disk(c)};await c.load()}};O.prototype.set_fdb=async function(a){const b=this.v86.cpu.devices.fdc.drives[1];if(a.url&&!a.async)await new Promise(c=>{pa(a.url,{done:d=>{b.insert_disk(new z(d));c()}})});else{const c=Ca(a,this.zstd_decompress_worker.bind(this));c.onload=()=>{b.insert_disk(c)};await c.load()}};O.prototype.eject_fda=
317
- function(){this.v86.cpu.devices.fdc.drives[0].eject_disk()};O.prototype.eject_fdb=function(){this.v86.cpu.devices.fdc.drives[1].eject_disk()};O.prototype.get_disk_fda=function(){return this.v86.cpu.devices.fdc.drives[0].get_buffer()};O.prototype.get_disk_fdb=function(){return this.v86.cpu.devices.fdc.drives[1].get_buffer()};O.prototype.set_cdrom=async function(a){if(a.url&&!a.async)pa(a.url,{done:b=>{this.v86.cpu.devices.cdrom.set_cdrom(new z(b))}});else{const b=Ca(a,this.zstd_decompress_worker.bind(this));
318
- 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=async function(a,b){for(var c=0;c<a.length;c++)this.bus.send("keyboard-code",a[c]),b&&await new Promise(d=>setTimeout(d,b))};O.prototype.keyboard_send_keys=async function(a,b){for(var c=0;c<a.length;c++)this.keyboard_adapter.simulate_press(a[c]),b&&await new Promise(d=>setTimeout(d,b))};O.prototype.keyboard_send_text=async function(a,
319
- b){for(var c=0;c<a.length;c++)this.keyboard_adapter.simulate_char(a[c]),b&&await new Promise(d=>setTimeout(d,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");if(a){var b=a.requestFullScreen||a.webkitRequestFullscreen||
320
- 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=async function(){const a=document.body;try{await a.requestPointerLock({unadjustedMovement:!0})}catch(b){await a.requestPointerLock()}};O.prototype.mouse_set_enabled=function(a){this.mouse_adapter&&(this.mouse_adapter.emu_enabled=a)};O.prototype.mouse_set_status=O.prototype.mouse_set_enabled;
321
- O.prototype.keyboard_set_enabled=function(a){this.keyboard_adapter&&(this.keyboard_adapter.emu_enabled=a)};O.prototype.keyboard_set_status=O.prototype.keyboard_set_enabled;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_carrier_detect=function(a,b){this.bus.send("serial"+a+"-carrier-detect-input",b)};
322
- 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.create_file=async function(a,b){var c=this.fs9p;if(c){var d=a.split("/");d=d[d.length-1];a=c.SearchPath(a).parentid;if(""!==d&&-1!==a)await c.CreateBinaryFile(d,a,b);else return Promise.reject(new Dc)}};
323
- O.prototype.read_file=async function(a){var b=this.fs9p;if(b)return(a=await b.read_file(a))?a:Promise.reject(new Dc)};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):this.keyboard_send_text(d.keyboard_send),b(e)):d.call&&(d.call(),b(e))}};b(a)};O.prototype.wait_until_vga_screen_contains=
324
- async function(a,b){const c=Array.isArray(a);var d=b?.timeout_msec||0;const e=new Set;b=m=>e.add(m[0]);const f=(m,n)=>n.test?n.test(m):m.startsWith(n),g=[];this.add_listener("screen-put-char",b);for(var h of this.screen_adapter.get_text_screen())if(c)g.push(h.trimRight());else if(f(h,a))return this.remove_listener("screen-put-char",b),!0;h=!1;d=d?performance.now()+d:0;a:for(;!d||performance.now()<d;){if(c){for(var l=g.length;0<l&&""===g[l-1];)l--;l-=a.length;if(0<=l){let m=!0;for(let n=0;n<a.length&&
325
- m;n++)m=f(g[l+n],a[n]);if(m){h=!0;break}}}await new Promise(m=>setTimeout(m,100));for(const m of e)if(l=this.screen_adapter.get_text_row(m),c)g[m]=l.trimRight();else if(f(l,a)){h=!0;break a}e.clear()}this.remove_listener("screen-put-char",b);return h};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,b=window.Terminal){this.serial_adapter&&this.serial_adapter.destroy&&
326
- this.serial_adapter.destroy();this.serial_adapter=new nc(a,this.bus,b);this.serial_adapter.show()};O.prototype.set_virtio_console_container_xtermjs=function(a,b=window.Terminal){this.virtio_console_adapter&&this.virtio_console_adapter.destroy&&this.virtio_console_adapter.destroy();this.virtio_console_adapter=new oc(a,this.bus,b);this.virtio_console_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(" "),
216
+ function(){"undefined"!==typeof window&&(this.destroy(),window.addEventListener("keyup",c,!1),window.addEventListener("keydown",d,!1),window.addEventListener("blur",e,!1),window.addEventListener("input",f,!1))};this.init();this.simulate_press=function(v){v={keyCode:v};g(v,!0);g(v,!1)};this.simulate_char=function(v){var H=v.charCodeAt(0);H in z?this.simulate_press(z[H]):H in u?(m(42),this.simulate_press(u[H]),m(170)):console.log("ascii -> keyCode not found: ",H,v)}}function ac(a,b){function c(){z.bus.send("mouse-pointer-lock",
217
+ !!document.pointerLockElement)}function d(u){if(!z.enabled||!z.emu_enabled)return!1;var K=b||document.body,v;if(!(v=document.pointerLockElement))a:{for(u=u.target;u.parentNode;){if(u===K){v=!0;break a}u=u.parentNode}v=!1}return v}function e(u){d(u)&&(u=u.changedTouches)&&u.length&&(u=u[u.length-1],x=u.clientX,E=u.clientY)}function f(){if(p||r||q)z.bus.send("mouse-click",[!1,!1,!1]),p=r=q=!1}function g(u){if(z.bus&&d(u)&&z.is_running){var K=0,v=0,H=u.changedTouches;H?H.length&&(H=H[H.length-1],K=H.clientX-
218
+ x,v=H.clientY-E,x=H.clientX,E=H.clientY,u.preventDefault()):"number"===typeof u.movementX?(K=u.movementX,v=u.movementY):"number"===typeof u.webkitMovementX?(K=u.webkitMovementX,v=u.webkitMovementY):"number"===typeof u.mozMovementX?(K=u.mozMovementX,v=u.mozMovementY):(K=u.clientX-x,v=u.clientY-E,x=u.clientX,E=u.clientY);z.bus.send("mouse-delta",[1*K,-(1*v)]);b&&!document.pointerLockElement&&z.bus.send("mouse-absolute",[u.pageX-b.offsetLeft,u.pageY-b.offsetTop,b.offsetWidth,b.offsetHeight])}}function h(u){d(u)&&
219
+ m(u,!0)}function l(u){d(u)&&m(u,!1)}function m(u,K){z.bus&&(1===u.which?p=K:2===u.which?r=K:3===u.which&&(q=K),z.bus.send("mouse-click",[p,r,q]),u.preventDefault())}function n(u){if(d(u)){var K=u.wheelDelta||-u.detail;0>K?K=-1:0<K&&(K=1);z.bus.send("mouse-wheel",[K,0]);u.preventDefault()}}var p=!1,q=!1,r=!1,x=0,E=0,z=this;this.enabled=!1;this.emu_enabled=!0;this.bus=a;this.bus.register("mouse-enable",function(u){this.enabled=u},this);this.is_running=!1;this.bus.register("emulator-stopped",function(){this.is_running=
220
+ !1},this);this.bus.register("emulator-started",function(){this.is_running=!0},this);this.destroy=function(){"undefined"!==typeof window&&(window.removeEventListener("touchstart",e,!1),window.removeEventListener("touchend",f,!1),window.removeEventListener("touchmove",g,!1),window.removeEventListener("mousemove",g,!1),window.removeEventListener("mousedown",h,!1),window.removeEventListener("mouseup",l,!1),window.removeEventListener("wheel",n,{passive:!1}),document.removeEventListener("pointerlockchange",
221
+ c,!1))};this.init=function(){"undefined"!==typeof window&&(this.destroy(),window.addEventListener("touchstart",e,!1),window.addEventListener("touchend",f,!1),window.addEventListener("touchmove",g,!1),window.addEventListener("mousemove",g,!1),window.addEventListener("mousedown",h,!1),window.addEventListener("mouseup",l,!1),window.addEventListener("wheel",n,{passive:!1}),document.addEventListener("pointerlockchange",c,!1))};this.init()}function bc(a){var b,c=0,d=0,e=ta(a?.encoding);this.put_char=function(f,
222
+ g,h){b[f*c+g]=h};this.destroy=function(){};this.pause=function(){};this.continue=function(){};this.set_mode=function(){};this.set_font_bitmap=function(){};this.set_font_page=function(){};this.clear_screen=function(){};this.set_size_text=function(f,g){if(f!==c||g!==d)b=new Uint8Array(f*g),c=f,d=g};this.set_size_graphical=function(){};this.set_scale=function(){};this.update_cursor_scanline=function(){};this.update_cursor=function(){};this.update_buffer=function(){};this.get_text_screen=function(){for(var f=
223
+ [],g=0;g<d;g++)f.push(this.get_text_row(g));return f};this.get_text_row=function(f){f*=c;return Array.from(b.subarray(f,f+c),g=>e[g]).join("")};this.set_size_text(80,25)}function cc(a){var b,c=0,d=0,e=ta(a?.encoding);this.put_char=function(f,g,h,l,m,n){f=3*(f*c+g);b[f+0]=h;b[f+1]=m;b[f+2]=n};this.destroy=function(){};this.pause=function(){};this.continue=function(){};this.set_mode=function(){};this.set_font_bitmap=function(){};this.set_font_page=function(){};this.clear_screen=function(){};this.set_size_text=
224
+ function(f,g){if(f!==c||g!==d)b=new Int32Array(f*g*3),c=f,d=g};this.set_size_graphical=function(){};this.set_scale=function(){};this.update_cursor_scanline=function(){};this.update_cursor=function(){};this.update_buffer=function(){};this.get_text_screen=function(){for(var f=[],g=0;g<d;g++)f.push(this.get_text_row(g));return f};this.get_text_row=function(f){var g=f*c*3;f=g+3*c;let h=null,l=null,m="";for(;g<f;g+=3){const n=e[b[g]],p=b[g+1],q=b[g+2];let r="";h!==p&&(r+=`\x1B[48;${`2;${(p&16711680)>>
225
+ 16};${(p&65280)>>8};${p&255}`}m`,h=p);l!==q&&(r+=`\x1B[38;${`2;${(q&16711680)>>16};${(q&65280)>>8};${q&255}`}m`,l=q);m+=r+n}return m+"\u001b[0m"};this.set_size_text(80,25)}function dc(a){function b(g){f.enabled&&(f.send_char(g.which),g.preventDefault())}function c(g){var h=g.which;8===h?(f.send_char(127),g.preventDefault()):9===h&&(f.send_char(9),g.preventDefault())}function d(g){if(f.enabled){for(var h=g.clipboardData.getData("text/plain"),l=0;l<h.length;l++)f.send_char(h.charCodeAt(l));g.preventDefault()}}
226
+ function e(g){g.target!==a&&a.blur()}var f=this;this.enabled=!0;this.text="";this.text_new_line=!1;this.last_update=0;this.destroy=function(){this.enabled=!1;a.removeEventListener("keypress",b,!1);a.removeEventListener("keydown",c,!1);a.removeEventListener("paste",d,!1);window.removeEventListener("mousedown",e,!1)};this.init=function(){this.destroy();this.enabled=!0;a.style.display="block";a.addEventListener("keypress",b,!1);a.addEventListener("keydown",c,!1);a.addEventListener("paste",d,!1);window.addEventListener("mousedown",
227
+ e,!1)};this.init();this.show_char=function(g){"\b"===g?(this.text=this.text.slice(0,-1),this.update()):"\r"!==g&&(this.text+=g,"\n"===g&&(this.text_new_line=!0),this.update())};this.update=function(){var g=Date.now(),h=g-this.last_update;16>h?void 0===this.update_timer&&(this.update_timer=setTimeout(()=>{this.update_timer=void 0;this.last_update=Date.now();this.render()},16-h)):(void 0!==this.update_timer&&(clearTimeout(this.update_timer),this.update_timer=void 0),this.last_update=g,this.render())};
228
+ this.render=function(){a.value=this.text;this.text_new_line&&(this.text_new_line=!1,a.scrollTop=1E9)};this.send_char=function(){}}function ec(a,b){var c=Reflect.construct(dc,[a],ec);c.send_char=function(d){b.send("serial0-input",d)};b.register("serial0-output-byte",function(d){d=String.fromCharCode(d);c.show_char&&c.show_char(d)},c);return c}Reflect.setPrototypeOf(ec.prototype,dc.prototype);Reflect.setPrototypeOf(ec,dc);function fc(a,b){var c=Reflect.construct(dc,[a],fc);c.send_char=function(e){b.send("virtio-console0-input-bytes",
229
+ new Uint8Array([e]))};const d=new TextDecoder;b.register("virtio-console0-output-bytes",function(e){for(const f of d.decode(e))c.show_char&&c.show_char(f)},c);return c}Reflect.setPrototypeOf(fc.prototype,dc.prototype);Reflect.setPrototypeOf(fc,dc);function gc(a,b){this.element=a;var c=this.term=new b({logLevel:"off",convertEol:"true"});this.destroy=function(){this.on_data_disposable&&this.on_data_disposable.dispose();c.dispose()}}gc.prototype.show=function(){this.term&&this.term.open(this.element)};
230
+ function nc(a,b,c){if(c){var d=Reflect.construct(gc,[a,c],nc);b.register("serial0-output-byte",function(f){d.term.write(Uint8Array.of(f))},d);var e=new TextEncoder;d.on_data_disposable=d.term.onData(function(f){for(const g of e.encode(f))b.send("serial0-input",g)});return d}}Reflect.setPrototypeOf(nc.prototype,gc.prototype);Reflect.setPrototypeOf(nc,gc);function oc(a,b,c){if(c){var d=Reflect.construct(gc,[a,c],oc);b.register("virtio-console0-output-bytes",function(f){d.term.write(f)},d);var e=new TextEncoder;
231
+ d.on_data_disposable=d.term.onData(function(f){b.send("virtio-console0-input-bytes",e.encode(f))});return d}}Reflect.setPrototypeOf(oc.prototype,gc.prototype);Reflect.setPrototypeOf(oc,gc);function pc(a,b){b=b.id||0;this.bus=a;this.bus_send_msgid=`net${b}-send`;this.bus_recv_msgid=`net${b}-receive`;this.channel=new BroadcastChannel(`v86-inbrowser-${b}`);this.is_open=!0;this.nic_to_hub_fn=c=>{this.channel.postMessage(c)};this.bus.register(this.bus_send_msgid,this.nic_to_hub_fn,this);this.hub_to_nic_fn=
232
+ c=>{this.bus.send(this.bus_recv_msgid,c.data)};this.channel.addEventListener("message",this.hub_to_nic_fn)}pc.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)};const qc={A:[],D:"custom",E:[0,1,1],H:[0,0,0],I:[3,3],L:[0,3,1],M:[0,2,1],O:[0,0,0],P:[],Q:[0,1,0],S:[0,5],T:[],V:[0,1,0],X:[0,4,0],Z:[0,0,0],"&C":[0,1,1],"&D":[0,2,2],"&F":[0,0,0],"&K":[0,
233
+ 6,3]},rc={[0]:"OK",[1]:"CONNECT",[2]:"RING",[3]:"NO CARRIER",[4]:"ERROR"},sc=/^ws[s]?:\/\//i,tc=new TextEncoder,uc=new TextDecoder;function G(a,b){this.bus=a;this.uart=b.uart;this.cli_buffer=new Uint8Array(256);this.rts_state=this.dtr_state=this.destroyed=!1;this.sreg=new Uint8Array(6);this.in_data_mode=!1;this.data_mode_send_buffer=new Uint8Array(512);this.data_mode_send_cursor=0;this.data_mode_esc_timer=this.data_mode_send_timer=null;this.phonebook=b.phonebook||{};this.socket=null;this.reset();
234
+ this.bus.register(`serial${this.uart}-data-terminal-ready-output`,this.uart_dtr_changed,this);this.bus.register(`serial${this.uart}-request-to-send-output`,this.uart_rts_changed,this);this.bus.register(`serial${this.uart}-output-byte`,this.uart_byte_received,this)}G.prototype.initialize=function(){this.uart_set_dsr(!0);this.uart_set_cts(!0);this.uart_set_ring(!1);this.uart_set_dcd(!1)};G.prototype.destroy=function(){this.destroyed=!0;this.bus.unregister(`serial${this.uart}-data-terminal-ready-output`,
235
+ this.uart_dtr_changed);this.bus.unregister(`serial${this.uart}-request-to-send-output`,this.uart_rts_changed);this.bus.unregister(`serial${this.uart}-output-byte`,this.uart_byte_received);this.cancel_data_mode_send_timer();this.cancel_data_mode_esc_timer();this.socket&&this.socket.close()};G.prototype.cancel_data_mode_send_timer=function(){null!==this.data_mode_send_timer&&(clearTimeout(this.data_mode_send_timer),this.data_mode_send_timer=null)};G.prototype.cancel_data_mode_esc_timer=function(){null!==
236
+ this.data_mode_esc_timer&&(clearTimeout(this.data_mode_esc_timer),this.data_mode_esc_timer=null)};G.prototype.reset=function(){this.do_echo=!0;this.cli_cursor=0;this.resp_suppress=this.cli_overflow=!1;this.use_rtscts_flowctrl=this.resp_verbose=!0;this.dcd_always_on=this.use_tone_dialling=!1;this.dtr_low_behaviour=2;this.data_mode_esc_count=this.uart_recv_tm=0;this.reset_on_disconnect=!1;this.sreg[0]=0;this.sreg[1]=0;this.sreg[2]=43;this.sreg[3]=13;this.sreg[4]=10;this.sreg[5]=8};G.prototype.uart_set_dcd=
237
+ function(a){this.bus.send(`serial${this.uart}-carrier-detect-input`,a)};G.prototype.uart_set_ring=function(a){this.bus.send(`serial${this.uart}-ring-indicator-input`,a)};G.prototype.uart_set_dsr=function(a){this.bus.send(`serial${this.uart}-data-set-ready-input`,a)};G.prototype.uart_set_cts=function(a){this.bus.send(`serial${this.uart}-clear-to-send-input`,a)};G.prototype.uart_write_byte=function(a){this.bus.send(`serial${this.uart}-input`,a)};G.prototype.uart_write=function(a){for(const b of tc.encode(a))this.uart_write_byte(b)};
238
+ G.prototype.uart_dtr_changed=function(a){a=!!a;this.dtr_state!==a&&(this.dtr_state=a,this.socket&&!a&&(1===this.dtr_low_behaviour?(this.enter_cli_mode(),this.cli_write_response_code(0)):2===this.dtr_low_behaviour&&this.socket.close()))};G.prototype.uart_rts_changed=function(a){a=!!a;this.rts_state!==a&&(this.rts_state=a)};G.prototype.uart_byte_received=function(a){this.cancel_data_mode_esc_timer();this.in_data_mode?this.data_mode_uart_recv(a):this.cli_mode_uart_recv(a)};G.prototype.enter_cli_mode=
239
+ function(){this.in_data_mode&&(this.in_data_mode=!1,this.cancel_data_mode_esc_timer(),this.cancel_data_mode_send_timer(),this.data_mode_flush(),this.uart_set_dsr(!0),this.uart_set_cts(!0),this.uart_set_ring(!1),this.dcd_always_on||this.uart_set_dcd(null!==this.socket))};G.prototype.enter_data_mode=function(){this.in_data_mode||(this.in_data_mode=!0,this.data_mode_send_cursor=0,this.uart_set_ring(!1),this.dcd_always_on||this.uart_set_dcd(!0))};G.prototype.flush_escape_buffer=function(){for(;0<this.data_mode_esc_count;this.data_mode_esc_count--)this.in_data_mode?
240
+ this.data_mode_send(this.sreg[2]):this.uart_write_byte(this.sreg[2])};G.prototype.data_mode_send=function(a){this.socket&&(this.cancel_data_mode_send_timer(),this.data_mode_send_buffer[this.data_mode_send_cursor++]=a,this.data_mode_send_cursor===this.data_mode_send_buffer.byteLength?this.data_mode_flush():this.data_mode_send_timer=setTimeout(()=>{this.data_mode_flush()},5))};G.prototype.data_mode_flush=function(){this.data_mode_send_cursor&&this.socket&&this.socket.readyState===WebSocket.OPEN&&(this.data_mode_send_cursor===
241
+ this.data_mode_send_buffer.byteLength?this.socket.send(this.data_mode_send_buffer):this.socket.send(this.data_mode_send_buffer.subarray(0,this.data_mode_send_cursor)));this.data_mode_send_cursor=0};G.prototype.data_mode_uart_recv=function(a){a===this.sreg[2]&&3>this.data_mode_esc_count&&(0<this.data_mode_esc_count||1E3<performance.now()-this.uart_recv_tm)?3>++this.data_mode_esc_count?this.data_mode_esc_timer=setTimeout(()=>{this.data_mode_esc_timer=null;this.flush_escape_buffer()},200):this.data_mode_esc_timer=
242
+ setTimeout(()=>{this.data_mode_esc_timer=null;this.enter_cli_mode();this.flush_escape_buffer();this.cli_write_response_code(0)},1E3):(this.uart_recv_tm=performance.now(),this.flush_escape_buffer(),this.data_mode_send(a))};G.prototype.cli_mode_uart_recv=function(a){this.do_echo&&(this.uart_write_byte(a),a===this.sreg[5]&&(this.uart_write_byte(32),this.uart_write_byte(this.sreg[5])));switch(a){case this.sreg[5]:0<this.cli_cursor&&this.cli_cursor--;break;case this.sreg[3]:this.cli_overflow?(uc.decode(this.cli_buffer.buffer),
243
+ this.cli_overflow=!1):this.cli_exec(uc.decode(this.cli_buffer.slice(0,this.cli_cursor)).replace(/\s/g,""));this.cli_cursor=0;break;case this.sreg[4]:break;default:this.cli_cursor<this.cli_buffer.length?this.cli_buffer[this.cli_cursor++]=a:(this.cli_overflow=!0,this.uart_write_byte(7))}};G.prototype.cli_decode_arg=function(a,b){if(void 0===b){if(a.length)return 2<a.length?a[2]:!1}else if(2>a.length||b<a[0]||b>a[1])return!1;return b};G.prototype.cli_translate_dial_address=function(a,b){let c;if(a in
244
+ this.phonebook)c=this.phonebook[a];else if(a.length){const e=a.match(/(\d{1,3})[^\d]*(\d{1,3})[^\d]*(\d{1,3})[^\d]*(\d{1,3})[^\d]*(\d{0,5})/);if(e){var d=(m,n)=>{if(e[m].length)return m=Number(e[m]),m<n?m:-1};const f=d(1,256),g=d(2,256),h=d(3,256),l=d(4,256);d=d(5,65536);0<=f&&0<=g&&0<=h&&0<=l&&(void 0===d||0<=d)&&(c=void 0===d?`${f}.${g}.${h}.${l}`:`${f}.${g}.${h}.${l}:${d}`)}void 0===c&&(c=a);sc.test(c)||(c=(b?"wss://":"ws://")+c)}return c};G.prototype.cli_exec_dial=function(a,b){let c=!0,d=this.use_tone_dialling;
245
+ var e=a.lastIndexOf(";");0<=e&&(c=!1,a=a.substring(0,e));b<a.length&&(e=a[b].toUpperCase(),"T"===e||"P"===e)&&(b++,d="T"===e);b<a.length&&'"'===a[b]&&(b++,e=a.indexOf('"',b),0<=e&&(a=a.substring(0,e)));a=a.substring(b);a=this.cli_translate_dial_address(a,d);if(void 0===a)this.cli_write_response_code(4);else{try{this.socket=new WebSocket(a)}catch(f){this.cli_write_response_code(4);return}this.socket.binaryType="arraybuffer";this.socket.addEventListener("open",()=>{c?(this.enter_data_mode(),this.cli_write_response_code(1)):
246
+ this.cli_write_response_code(0)});this.socket.addEventListener("message",f=>{if(this.in_data_mode&&(!this.use_rtscts_flowctrl||this.rts_state)){const g=new Uint8Array(f.data);for(let h=0;h<f.data.byteLength;h++)this.uart_write_byte(g[h])}});this.socket.addEventListener("close",()=>{this.socket=null;this.destroyed||(this.enter_cli_mode(),this.reset_on_disconnect&&(this.reset(),this.reset_on_disconnect=!1),this.cli_write_response_code(3))})}};G.prototype.cli_exec=function(a){const b=a.length;if(0===
247
+ b)this.socket&&this.socket.readyState===WebSocket.CONNECTING?this.socket.close():this.cli_write_response_code(0);else{var c=a.search(/(at|AT)/);if(!(0>c)){c+=2;for(var d=()=>{const g=c;let h=0;for(;c<b;){const l=a.charCodeAt(c)-48;if(0>l||9<l)break;else h=10*h+l,c++}return c===g?void 0:h},e=!0;c<b&&!0===e;){var f=a[c++].toUpperCase();c<b&&"&"===f&&(f+=a[c++].toUpperCase());if(!(f in qc)){e=4;break}const g=qc[f];let h;if("custom"!==g&&(h=this.cli_decode_arg(g,d()),!1===h)){e=4;break}switch(f){case "D":this.socket?
248
+ e=4:(this.cli_exec_dial(a,c),e=!1);break;case "E":this.do_echo=1===h;break;case "H":this.socket?(this.socket.close(),e=!1):e=4;break;case "I":this.cli_write_info_text("V86 Modem Emulation");break;case "L":break;case "M":break;case "O":this.socket?(this.enter_data_mode(),e=1):e=4;break;case "P":this.use_tone_dialling=!1;break;case "Q":this.resp_suppress=1===h;break;case "S":c<b&&"?"===a[c]?(c++,this.cli_write_info_text(this.sreg[h].toString().padStart(3,"0"))):c<b&&"="===a[c]?(c++,f=d(),void 0!==f&&
249
+ 256>f?this.sreg[h]=f:e=4):e=4;break;case "T":this.use_tone_dialling=!0;break;case "V":this.resp_verbose=1===h;break;case "X":break;case "Z":case "&F":this.socket?(this.reset_on_disconnect=!0,this.socket.close(),e=!1):this.reset();break;case "&C":(this.dcd_always_on=0===h)?this.uart_set_dcd(!0):this.uart_set_dcd(null!==this.socket);break;case "&D":this.dtr_low_behaviour=h;break;case "&K":0===h||3===h?this.use_rtscts_flowctrl=3===h:e=4;break;default:e=4}}!0===e?this.cli_write_response_code(0):"number"===
250
+ typeof e&&this.cli_write_response_code(e)}}};G.prototype.cli_write_info_text=function(a){this.resp_verbose&&(this.uart_write_byte(this.sreg[3]),this.uart_write_byte(this.sreg[4]));this.uart_write(a);this.uart_write_byte(this.sreg[3]);this.uart_write_byte(this.sreg[4])};G.prototype.cli_write_response_code=function(a){if(!this.resp_suppress){const b=rc[a in rc?a:4];this.resp_verbose?(this.uart_write_byte(this.sreg[3]),this.uart_write_byte(this.sreg[4]),this.uart_write(b),this.uart_write_byte(this.sreg[3]),
251
+ this.uart_write_byte(this.sreg[4])):(this.uart_write(a.toString()),this.uart_write_byte(this.sreg[3]))}};function vc(){this.filedata=new Map}vc.prototype.read=async function(a,b,c){return(a=this.filedata.get(a))?a.subarray(b,b+c):null};vc.prototype.cache=async function(a,b){this.filedata.set(a,b)};vc.prototype.uncache=function(a){this.filedata.delete(a)};function wc(a,b,c){b.endsWith("/")||(b+="/");this.storage=a;this.baseurl=b;this.zstd_decompress=c}wc.prototype.load_from_server=function(a,b){return new Promise(c=>
252
+ {pa(this.baseurl+a,{done:async d=>{d=new Uint8Array(d);a.endsWith(".zst")&&(d=new Uint8Array(this.zstd_decompress(b,d)));await this.cache(a,d);c(d)}})})};wc.prototype.read=async function(a,b,c,d){const e=await this.storage.read(a,b,c,d);return e?e:(await this.load_from_server(a,d)).subarray(b,b+c)};wc.prototype.cache=async function(a,b){return await this.storage.cache(a,b)};wc.prototype.uncache=function(a){this.storage.uncache(a)};const xc=new TextDecoder,yc=new TextEncoder;function J(a,b,c,d){for(var e,
253
+ f=0,g=0;g<a.length;g++)switch(e=b[g],a[g]){case "w":c[d++]=e&255;c[d++]=e>>8&255;c[d++]=e>>16&255;c[d++]=e>>24&255;f+=4;break;case "d":c[d++]=e&255;c[d++]=e>>8&255;c[d++]=e>>16&255;c[d++]=e>>24&255;c[d++]=0;c[d++]=0;c[d++]=0;c[d++]=0;f+=8;break;case "h":c[d++]=e&255;c[d++]=e>>8;f+=2;break;case "b":c[d++]=e;f+=1;break;case "s":var h=d,l=0;c[d++]=0;c[d++]=0;f+=2;e=yc.encode(e);f+=e.byteLength;l+=e.byteLength;c.set(e,d);d+=e.byteLength;c[h+0]=l&255;c[h+1]=l>>8&255;break;case "Q":J(["b","w","d"],[e.type,
254
+ e.version,e.path],c,d),d+=13,f+=13}return f}function L(a,b,c){let d=c.offset;for(var e=[],f=0;f<a.length;f++)switch(a[f]){case "w":var g=b[d++];g+=b[d++]<<8;g+=b[d++]<<16;g+=b[d++]<<24>>>0;e.push(g);break;case "d":g=b[d++];g+=b[d++]<<8;g+=b[d++]<<16;g+=b[d++]<<24>>>0;d+=4;e.push(g);break;case "h":g=b[d++];e.push(g+(b[d++]<<8));break;case "b":e.push(b[d++]);break;case "s":g=b[d++];g+=b[d++]<<8;var h=b.slice(d,d+g);d+=g;e.push(xc.decode(h));break;case "Q":c.offset=d,g=L(["b","w","d"],b,c),d=c.offset,
255
+ e.push({type:g[0],version:g[1],path:g[2]})}c.offset=d;return e}const zc=new TextEncoder;function N(a,b){this.inodes=[];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;
256
+ a[4]=this.used_size;return a=a.concat(this.mounts)};N.prototype.set_state=function(a){this.inodes=a[0].map(b=>{const c=new Ac(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.load_from_json=function(a){if(3!==a.version)throw"The filesystem JSON format has changed. Please recreate the filesystem JSON.";
257
+ var b=a.fsroot;this.used_size=a.size;for(a=0;a<b.length;a++)this.LoadRecursive(b[a],0)};N.prototype.LoadRecursive=function(a,b){var c=this.CreateInode();const d=a[0];c.size=a[1];c.mtime=a[2];c.ctime=c.mtime;c.atime=c.mtime;c.mode=a[3];c.uid=a[4];c.gid=a[5];var e=c.mode&61440;16384===e?(this.PushInode(c,b,d),this.LoadDir(this.inodes.length-1,a[6])):32768===e?(c.status=2,c.sha256sum=a[6],this.PushInode(c,b,d)):40960===e?(c.symlink=a[6],this.PushInode(c,b,d)):49152!==e&&y(e)};N.prototype.LoadDir=function(a,
258
+ b){for(var c=0;c<b.length;c++)this.LoadRecursive(b[c],a)};N.prototype.should_be_linked=function(a){return!this.is_forwarder(a)||0===a.foreign_id};N.prototype.link_under_dir=function(a,b,c){const d=this.inodes[b],e=this.inodes[a];this.is_forwarder(e);this.IsDirectory(a);this.should_be_linked(d);e.direntries.has(c);e.direntries.set(c,b);d.nlinks++;this.IsDirectory(b)&&(d.direntries.has(".."),d.direntries.has(".")||d.nlinks++,d.direntries.set(".",b),d.direntries.set("..",a),e.nlinks++)};N.prototype.unlink_from_dir=
259
+ function(a,b){const c=this.Search(a,b),d=this.inodes[c],e=this.inodes[a];this.is_forwarder(e);this.IsDirectory(a);e.direntries.delete(b)&&(d.nlinks--,this.IsDirectory(c)&&(d.direntries.get(".."),d.direntries.delete(".."),e.nlinks--))};N.prototype.PushInode=function(a,b,c){-1!==b?(this.inodes.push(a),a.fid=this.inodes.length-1,this.link_under_dir(b,a.fid,c)):0===this.inodes.length&&(this.inodes.push(a),a.direntries.set(".",0),a.direntries.set("..",0),a.nlinks=2)};function Ac(a){this.direntries=new Map;
260
+ this.minor=this.major=this.mtime=this.atime=this.ctime=this.fid=this.gid=this.uid=this.size=this.status=0;this.symlink="";this.mode=493;this.qid={type:0,version:0,path:a};this.caps=void 0;this.nlinks=0;this.sha256sum="";this.locks=[];this.foreign_id=this.mount_id=-1}Ac.prototype.get_state=function(){const a=[];a[0]=this.mode;a[1]=16384===(this.mode&61440)?[...this.direntries]:32768===(this.mode&61440)?this.sha256sum:40960===(this.mode&61440)?this.symlink:49152===(this.mode&61440)?[this.minor,this.major]:
261
+ null;a[2]=this.locks;a[3]=this.status;a[4]=this.size;a[5]=this.uid;a[6]=this.gid;a[7]=this.fid;a[8]=this.ctime;a[9]=this.atime;a[10]=this.mtime;a[11]=this.qid.version;a[12]=this.qid.path;a[13]=this.nlinks;return a};Ac.prototype.set_state=function(a){this.mode=a[0];if(16384===(this.mode&61440)){this.direntries=new Map;for(const [b,c]of a[1])this.direntries.set(b,c)}else 32768===(this.mode&61440)?this.sha256sum=a[1]:40960===(this.mode&61440)?this.symlink=a[1]:49152===(this.mode&61440)&&([this.minor,
262
+ this.major]=a[1]);this.locks=[];for(const b of a[2]){const c=new Bc;c.set_state(b);this.locks.push(c)}this.status=a[3];this.size=a[4];this.uid=a[5];this.gid=a[6];this.fid=a[7];this.ctime=a[8];this.atime=a[9];this.mtime=a[10];this.qid.type=(this.mode&61440)>>8;this.qid.version=a[11];this.qid.path=a[12];this.nlinks=a[13]};N.prototype.divert=function(a,b){const c=this.Search(a,b),d=this.inodes[c],e=new Ac(-1);this.IsDirectory(c);Object.assign(e,d);const f=this.inodes.length;this.inodes.push(e);e.fid=
263
+ f;this.is_forwarder(d)&&this.mounts[d.mount_id].backtrack.set(d.foreign_id,f);this.should_be_linked(d)&&(this.unlink_from_dir(a,b),this.link_under_dir(a,f,b));if(this.IsDirectory(c)&&!this.is_forwarder(d))for(const [g,h]of e.direntries)"."!==g&&".."!==g&&this.IsDirectory(h)&&this.inodes[h].direntries.set("..",f);this.inodedata[f]=this.inodedata[c];delete this.inodedata[c];d.direntries=new Map;d.nlinks=0;return f};N.prototype.copy_inode=function(a,b){Object.assign(b,a,{fid:b.fid,direntries:b.direntries,
264
+ nlinks:b.nlinks})};N.prototype.CreateInode=function(){const a=Math.round(Date.now()/1E3),b=new Ac(++this.qidcounter.last_qidnumber);b.atime=b.ctime=b.mtime=a;return b};N.prototype.CreateDirectory=function(a,b){var c=this.inodes[b];if(0<=b&&this.is_forwarder(c))return b=c.foreign_id,a=this.follow_fs(c).CreateDirectory(a,b),this.create_forwarder(c.mount_id,a);c=this.CreateInode();c.mode=16895;0<=b&&(c.uid=this.inodes[b].uid,c.gid=this.inodes[b].gid,c.mode=this.inodes[b].mode&511|16384);c.qid.type=64;
265
+ this.PushInode(c,b,a);this.NotifyListeners(this.inodes.length-1,"newdir");return this.inodes.length-1};N.prototype.CreateFile=function(a,b){var c=this.inodes[b];if(this.is_forwarder(c))return b=c.foreign_id,a=this.follow_fs(c).CreateFile(a,b),this.create_forwarder(c.mount_id,a);c=this.CreateInode();c.uid=this.inodes[b].uid;c.gid=this.inodes[b].gid;c.qid.type=128;c.mode=this.inodes[b].mode&438|32768;this.PushInode(c,b,a);this.NotifyListeners(this.inodes.length-1,"newfile");return this.inodes.length-
266
+ 1};N.prototype.CreateNode=function(a,b,c,d){var e=this.inodes[b];if(this.is_forwarder(e))return b=e.foreign_id,a=this.follow_fs(e).CreateNode(a,b,c,d),this.create_forwarder(e.mount_id,a);e=this.CreateInode();e.major=c;e.minor=d;e.uid=this.inodes[b].uid;e.gid=this.inodes[b].gid;e.qid.type=192;e.mode=this.inodes[b].mode&438;this.PushInode(e,b,a);return this.inodes.length-1};N.prototype.CreateSymlink=function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,a=this.follow_fs(d).CreateSymlink(a,
267
+ b,c),this.create_forwarder(d.mount_id,a);d=this.CreateInode();d.uid=this.inodes[b].uid;d.gid=this.inodes[b].gid;d.qid.type=160;d.symlink=c;d.mode=40960;this.PushInode(d,b,a);return this.inodes.length-1};N.prototype.CreateTextFile=async function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,c=await this.follow_fs(d).CreateTextFile(a,b,c),this.create_forwarder(d.mount_id,c);d=this.CreateFile(a,b);b=this.inodes[d];a=new Uint8Array(c.length);b.size=c.length;for(b=0;b<c.length;b++)a[b]=
268
+ c.charCodeAt(b);await this.set_data(d,a);return d};N.prototype.CreateBinaryFile=async function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,c=await this.follow_fs(d).CreateBinaryFile(a,b,c),this.create_forwarder(d.mount_id,c);d=this.CreateFile(a,b);a=this.inodes[d];b=new Uint8Array(c.length);b.set(c);await this.set_data(d,b);a.size=c.length;return d};N.prototype.OpenInode=async function(a,b){var c=this.inodes[a];if(this.is_forwarder(c))return await this.follow_fs(c).OpenInode(c.foreign_id,
269
+ b);16384===(c.mode&61440)&&this.FillDirectory(a)};N.prototype.CloseInode=async function(a){var b=this.inodes[a];if(this.is_forwarder(b))return await this.follow_fs(b).CloseInode(b.foreign_id);2===b.status&&this.storage.uncache(b.sha256sum);4===b.status&&(b.status=-1,await this.DeleteData(a))};N.prototype.Rename=async function(a,b,c,d){if(a===c&&b===d)return 0;var e=this.Search(a,b);if(-1===e)return-2;var f=this.GetFullPath(a)+"/"+b;if(-1!==this.Search(c,d)){var g=this.Unlink(c,d);if(0>g)return g}var h=
270
+ this.inodes[e],l=this.inodes[a];g=this.inodes[c];if(this.is_forwarder(l)||this.is_forwarder(g))if(this.is_forwarder(l)&&l.mount_id===g.mount_id){if(a=await this.follow_fs(l).Rename(l.foreign_id,b,g.foreign_id,d),0>a)return a}else{if(this.is_a_root(e)||!this.IsDirectory(e)&&1<this.GetInode(e).nlinks)return-1;l=this.divert(a,b);const m=this.GetInode(e),n=await this.Read(l,0,m.size);this.is_forwarder(g)?(c=this.follow_fs(g),d=this.IsDirectory(l)?c.CreateDirectory(d,g.foreign_id):c.CreateFile(d,g.foreign_id),
271
+ c=c.GetInode(d),this.copy_inode(m,c),this.set_forwarder(e,g.mount_id,d)):(this.delete_forwarder(h),this.copy_inode(m,h),this.link_under_dir(c,e,d));await this.ChangeSize(e,m.size);n&&n.length&&await this.Write(e,0,n.length,n);if(this.IsDirectory(e))for(const p of this.GetChildren(l))if(g=await this.Rename(l,p,e,p),0>g)return g;await this.DeleteData(l);a=this.Unlink(a,b);if(0>a)return a}else this.unlink_from_dir(a,b),this.link_under_dir(c,e,d),h.qid.version++;this.NotifyListeners(e,"rename",{oldpath:f});
272
+ return 0};N.prototype.Write=async function(a,b,c,d){this.NotifyListeners(a,"write");var e=this.inodes[a];if(this.is_forwarder(e))a=e.foreign_id,await this.follow_fs(e).Write(a,b,c,d);else{var f=await this.get_buffer(a);!f||f.length<b+c?(await this.ChangeSize(a,Math.floor(3*(b+c)/2)),e.size=b+c,f=await this.get_buffer(a)):e.size<b+c&&(e.size=b+c);d&&f.set(d.subarray(0,c),b);await this.set_data(a,f)}};N.prototype.Read=async function(a,b,c){const d=this.inodes[a];return this.is_forwarder(d)?(a=d.foreign_id,
273
+ await this.follow_fs(d).Read(a,b,c)):await this.get_data(a,b,c)};N.prototype.Search=function(a,b){a=this.inodes[a];if(this.is_forwarder(a)){const c=a.foreign_id;b=this.follow_fs(a).Search(c,b);return-1===b?-1:this.get_forwarder(a.mount_id,b)}b=a.direntries.get(b);return void 0===b?-1:b};N.prototype.CountUsedInodes=function(){let a=this.inodes.length;for(const {fs:b,backtrack:c}of this.mounts)a+=b.CountUsedInodes(),a-=c.size;return a};N.prototype.CountFreeInodes=function(){let a=1048576;for(const {fs:b}of this.mounts)a+=
274
+ b.CountFreeInodes();return a};N.prototype.GetTotalSize=function(){let a=this.used_size;for(const {fs:b}of this.mounts)a+=b.GetTotalSize();return a};N.prototype.GetSpace=function(){let a=this.total_size;for(const {fs:b}of this.mounts)a+=b.GetSpace();return this.total_size};N.prototype.GetDirectoryName=function(a){const b=this.inodes[this.GetParent(a)];if(this.is_forwarder(b))return this.follow_fs(b).GetDirectoryName(this.inodes[a].foreign_id);if(!b)return"";for(const [c,d]of b.direntries)if(d===a)return c;
275
+ return""};N.prototype.GetFullPath=function(a){this.IsDirectory(a);for(var b="";0!==a;)b="/"+this.GetDirectoryName(a)+b,a=this.GetParent(a);return b.substring(1)};N.prototype.Link=function(a,b,c){if(this.IsDirectory(b))return-1;const d=this.inodes[a],e=this.inodes[b];if(this.is_forwarder(d))return this.is_forwarder(e)&&e.mount_id===d.mount_id?this.follow_fs(d).Link(d.foreign_id,e.foreign_id,c):-1;if(this.is_forwarder(e))return-1;this.link_under_dir(a,b,c);return 0};N.prototype.Unlink=function(a,b){if("."===
276
+ b||".."===b)return-1;const c=this.Search(a,b),d=this.inodes[c],e=this.inodes[a];if(this.is_forwarder(e))return this.is_forwarder(d),a=e.foreign_id,this.follow_fs(e).Unlink(a,b);if(this.IsDirectory(c)&&!this.IsEmpty(c))return-39;this.unlink_from_dir(a,b);0===d.nlinks&&(d.status=4,this.NotifyListeners(c,"delete"));return 0};N.prototype.DeleteData=async function(a){const b=this.inodes[a];this.is_forwarder(b)?await this.follow_fs(b).DeleteData(b.foreign_id):(b.size=0,delete this.inodedata[a])};N.prototype.get_buffer=
277
+ async function(a){const b=this.inodes[a];return this.inodedata[a]?this.inodedata[a]:2===b.status?await this.storage.read(b.sha256sum,0,b.size,b.size):null};N.prototype.get_data=async function(a,b,c){const d=this.inodes[a];return this.inodedata[a]?this.inodedata[a].subarray(b,b+c):2===d.status?await this.storage.read(d.sha256sum,b,c,d.size):null};N.prototype.set_data=async function(a,b){this.inodedata[a]=b;2===this.inodes[a].status&&(this.inodes[a].status=0,this.storage.uncache(this.inodes[a].sha256sum))};
278
+ N.prototype.GetInode=function(a){isNaN(a);a=this.inodes[a];return this.is_forwarder(a)?this.follow_fs(a).GetInode(a.foreign_id):a};N.prototype.ChangeSize=async function(a,b){var c=this.GetInode(a),d=await this.get_data(a,0,c.size);if(b!==c.size){var e=new Uint8Array(b);c.size=b;d&&e.set(d.subarray(0,Math.min(d.length,c.size)),0);await this.set_data(a,e)}};N.prototype.SearchPath=function(a){a=a.replace("//","/");a=a.split("/");0<a.length&&0===a[a.length-1].length&&a.pop();0<a.length&&0===a[0].length&&
279
+ a.shift();const b=a.length;var c=-1,d=0;let e=null;for(var f=0;f<b;f++)if(c=d,d=this.Search(c,a[f]),!e&&this.is_forwarder(this.inodes[c])&&(e="/"+a.slice(f).join("/")),-1===d)return f<b-1?{id:-1,parentid:-1,name:a[f],forward_path:e}:{id:-1,parentid:c,name:a[f],forward_path:e};return{id:d,parentid:c,name:a[f],forward_path:e}};N.prototype.GetRecursiveList=function(a,b){if(this.is_forwarder(this.inodes[a])){const c=this.follow_fs(this.inodes[a]),d=this.inodes[a].mount_id,e=b.length;c.GetRecursiveList(this.inodes[a].foreign_id,
280
+ 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--)this.Unlink(b[a].parentid,b[a].name)};N.prototype.DeleteNode=function(a){var b=this.SearchPath(a);-1!==b.id&&(32768===(this.inodes[b.id].mode&
281
+ 61440)?this.Unlink(b.parentid,b.name):16384===(this.inodes[b.id].mode&61440)&&(this.RecursiveDelete(a),this.Unlink(b.parentid,b.name)))};N.prototype.NotifyListeners=function(){};N.prototype.Check=function(){for(var a=1;a<this.inodes.length;a++)if(-1!==this.inodes[a].status&&(this.GetInode(a),this.IsDirectory(a))){const b=this.GetInode(a);this.IsDirectory(a)&&this.GetParent(a);for(const [c]of b.direntries)for(const d of c);}};N.prototype.FillDirectory=function(a){var b=this.inodes[a];if(this.is_forwarder(b))this.follow_fs(b).FillDirectory(b.foreign_id);
282
+ else{var c=0;for(const d of b.direntries.keys())c+=24+zc.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+zc.encode(d).length,b.mode>>12,d],a,c)}};N.prototype.RoundToDirentry=function(a,b){a=this.inodedata[a];if(b>=a.length)return a.length;let c=0;for(;;){const d=L(["Q","d"],a,{offset:c})[1];if(d>b)break;c=d}return c};N.prototype.IsDirectory=function(a){a=this.inodes[a];return this.is_forwarder(a)?
283
+ 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;return!0};N.prototype.GetChildren=function(a){this.IsDirectory(a);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=
284
+ function(a){this.IsDirectory(a);a=this.inodes[a];if(this.should_be_linked(a))return a.direntries.get("..");const b=this.follow_fs(a).GetParent(a.foreign_id);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]=
285
+ 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};function Cc(a){this.fs=a;this.backtrack=new Map}Cc.prototype.get_state=function(){const a=[];a[0]=this.fs;a[1]=[...this.backtrack];return a};Cc.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];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;this.mounts[b].backtrack.set(c,
286
+ a)};N.prototype.create_forwarder=function(a,b){const c=this.CreateInode(),d=this.inodes.length;this.inodes.push(c);c.fid=d;this.set_forwarder(d,a,b);return d};N.prototype.is_forwarder=function(a){return 5===a.status};N.prototype.is_a_root=function(a){return 0===this.GetInode(a).fid};N.prototype.get_forwarder=function(a,b){const c=this.mounts[a].backtrack.get(b);return void 0===c?this.create_forwarder(a,b):c};N.prototype.delete_forwarder=function(a){this.is_forwarder(a);a.status=-1;this.mounts[a.mount_id].backtrack.delete(a.foreign_id)};
287
+ N.prototype.follow_fs=function(a){const b=this.mounts[a.mount_id];this.is_forwarder(a);return b.fs};N.prototype.Mount=function(a,b){a=this.SearchPath(a);if(-1===a.parentid)return-2;if(-1!==a.id)return-17;if(a.forward_path){var c=this.inodes[a.parentid];b=this.follow_fs(c).Mount(a.forward_path,b);return 0>b?b:this.get_forwarder(c.mount_id,b)}c=this.mounts.length;this.mounts.push(new Cc(b));b=this.create_forwarder(c,0);this.link_under_dir(a.parentid,b,a.name);return b};function Bc(){this.type=2;this.start=
288
+ 0;this.length=Infinity;this.proc_id=-1;this.client_id=""}Bc.prototype.get_state=function(){const a=[];a[0]=this.type;a[1]=this.start;a[2]=Infinity===this.length?0:this.length;a[3]=this.proc_id;a[4]=this.client_id;return a};Bc.prototype.set_state=function(a){this.type=a[0];this.start=a[1];this.length=0===a[2]?Infinity:a[2];this.proc_id=a[3];this.client_id=a[4]};Bc.prototype.clone=function(){const a=new Bc;a.set_state(this.get_state());return a};Bc.prototype.conflicts_with=function(a){return this.proc_id===
289
+ a.proc_id&&this.client_id===a.client_id||2===this.type||2===a.type||1!==this.type&&1!==a.type||this.start+this.length<=a.start||a.start+a.length<=this.start?!1:!0};Bc.prototype.is_alike=function(a){return a.proc_id===this.proc_id&&a.client_id===this.client_id&&a.type===this.type};Bc.prototype.may_merge_after=function(a){return this.is_alike(a)&&a.start+a.length===this.start};N.prototype.DescribeLock=function(a,b,c,d,e){const f=new Bc;f.type=a;f.start=b;f.length=c;f.proc_id=d;f.client_id=e;return f};
290
+ N.prototype.GetLock=function(a,b){a=this.inodes[a];if(this.is_forwarder(a)){var c=a.foreign_id;return this.follow_fs(a).GetLock(c,b)}for(c of a.locks)if(b.conflicts_with(c))return c.clone();return null};N.prototype.Lock=function(a,b,c){const d=this.inodes[a];if(this.is_forwarder(d))return a=d.foreign_id,this.follow_fs(d).Lock(a,b,c);b=b.clone();if(2!==b.type&&this.GetLock(a,b))return 1;for(c=0;c<d.locks.length;c++){a=d.locks[c];if(a.start+a.length<=b.start)continue;if(b.start+b.length<=a.start)break;
291
+ if(a.proc_id!==b.proc_id||a.client_id!==b.client_id){a.conflicts_with(b);continue}var e=b.start+b.length;const f=b.start-a.start,g=a.start+a.length-e;if(0<f&&0<g&&a.type===b.type)return 0;0<f&&(a.length=f);if(0>=f&&0<g)a.start=e,a.length=g;else if(0<g){for(;c<d.locks.length&&d.locks[c].start<e;)c++;d.locks.splice(c,0,this.DescribeLock(a.type,e,g,a.proc_id,a.client_id))}else 0>=f&&(d.locks.splice(c,1),c--)}if(2!==b.type){c=b;a=!1;for(e=0;e<d.locks.length&&!(c.may_merge_after(d.locks[e])&&(d.locks[e].length+=
292
+ b.length,c=d.locks[e],a=!0),b.start<=d.locks[e].start);e++);a||(d.locks.splice(e,0,c),e++);for(;e<d.locks.length;e++)if(d.locks[e].is_alike(c)){d.locks[e].may_merge_after(c)&&(c.length+=d.locks[e].length,d.locks.splice(e,1));break}}return 0};N.prototype.read_dir=function(a){a=this.SearchPath(a);if(-1!==a.id)return a=this.GetInode(a.id),Array.from(a.direntries.keys()).filter(b=>"."!==b&&".."!==b)};N.prototype.read_file=function(a){a=this.SearchPath(a);if(-1===a.id)return Promise.resolve(null);const b=
293
+ this.GetInode(a.id);return this.Read(a.id,0,b.size)};function O(a){this.cpu_is_running=!1;this.cpu_exception_hook=function(){};var b=Ha.create();this.bus=b[0];this.emulator_bus=b[1];var c,d;const e=new WebAssembly.Table({element:"anyfunc",initial:1924});b={cpu_exception_hook:g=>this.cpu_exception_hook(g),run_hardware_timers:function(g,h){return c.run_hardware_timers(g,h)},cpu_event_halt:()=>{this.emulator_bus.send("cpu-event-halt")},abort:function(){},microtick:F.microtick,get_rand_int:function(){return ca()},
294
+ stop_idling:function(){return c.stop_idling()},io_port_read8:function(g){return c.io.port_read8(g)},io_port_read16:function(g){return c.io.port_read16(g)},io_port_read32:function(g){return c.io.port_read32(g)},io_port_write8:function(g,h){c.io.port_write8(g,h)},io_port_write16:function(g,h){c.io.port_write16(g,h)},io_port_write32:function(g,h){c.io.port_write32(g,h)},mmap_read8:function(g){return c.mmap_read8(g)},mmap_read32:function(g){return c.mmap_read32(g)},mmap_write8:function(g,h){c.mmap_write8(g,
295
+ h)},mmap_write16:function(g,h){c.mmap_write16(g,h)},mmap_write32:function(g,h){c.mmap_write32(g,h)},mmap_write64:function(g,h,l){c.mmap_write64(g,h,l)},mmap_write128:function(g,h,l,m,n){c.mmap_write128(g,h,l,m,n)},log_from_wasm:function(g,h){ra(d,g,h)},console_log_from_wasm:function(g,h){g=ra(d,g,h);console.error(g)},dbg_trace_from_wasm:function(){},codegen_finalize:(g,h,l,m,n)=>{c.codegen_finalize(g,h,l,m,n)},jit_clear_func:g=>c.jit_clear_func(g),jit_clear_all_funcs:()=>c.jit_clear_all_funcs(),__indirect_function_table:e};
296
+ let f=a.wasm_fn;f||(f=g=>new Promise(h=>{let l="v86.wasm",m="v86-fallback.wasm";a.wasm_path?(l=a.wasm_path,m=l.replace("v86.wasm","v86-fallback.wasm")):"undefined"===typeof window&&"string"===typeof __dirname?(l=__dirname+"/"+l,m=__dirname+"/"+m):(l="build/"+l,m="build/"+m);pa(l,{done:async n=>{try{const {instance:p}=await WebAssembly.instantiate(n,g);this.wasm_source=n;h(p.exports)}catch(p){pa(m,{done:async q=>{const {instance:r}=await WebAssembly.instantiate(q,g);this.wasm_source=q;h(r.exports)}})}},
297
+ progress:n=>{this.emulator_bus.send("download-progress",{file_index:0,file_count:1,file_name:l,lengthComputable:n.lengthComputable,total:n.total,loaded:n.loaded})}})}));f({env:b}).then(g=>{d=g.memory;g.rust_init();g=this.v86=new F(this.emulator_bus,{exports:g,wasm_table:e});c=g.cpu;this.continue_init(g,a)});this.zstd_worker=null;this.zstd_worker_request_id=0}O.prototype.continue_init=async function(a,b){function c(q,r){switch(q){case "hda":e.hda=r;break;case "hdb":e.hdb=r;break;case "cdrom":e.cdrom=
298
+ r;break;case "fda":e.fda=r;break;case "fdb":e.fdb=r;break;case "multiboot":e.multiboot=r.buffer;break;case "bzimage":e.bzimage=r.buffer;break;case "initrd":e.initrd=r.buffer;break;case "bios":e.bios=r.buffer;break;case "vga_bios":e.vga_bios=r.buffer;break;case "initial_state":e.initial_state=r.buffer;break;case "fs9p_json":e.fs9p_json=r}}async function d(){if(e.fs9p&&e.fs9p_json&&!e.initial_state&&(e.fs9p.load_from_json(e.fs9p_json),b.bzimage_initrd_from_filesystem)){const {bzimage_path:q,initrd_path:r}=
299
+ this.get_bzimage_initrd_from_filesystem(e.fs9p),[x,E]=await Promise.all([e.fs9p.read_file(r),e.fs9p.read_file(q)]);c.call(this,"initrd",new A(x.buffer));c.call(this,"bzimage",new A(E.buffer))}this.serial_adapter&&this.serial_adapter.show&&this.serial_adapter.show();this.virtio_console_adapter&&this.virtio_console_adapter.show&&this.virtio_console_adapter.show();this.v86.init(e);this.modem&&this.modem.initialize();e.initial_state&&(a.restore_state(e.initial_state),e.initial_state=void 0);b.autostart&&
300
+ 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()},this);var e={},f=b.boot_order?b.boot_order:b.fda?801:b.hda?786:291;if(b.modem)switch(e.modem=b.modem,b.modem.uart){case 1:b.uart1=!0;break;case 2:b.uart2=!0;break;case 3:b.uart3=!0}e.acpi=b.acpi;e.disable_jit=b.disable_jit;e.load_devices=
301
+ !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=b.mac_address_translation;e.cpuid_level=b.cpuid_level;e.virtio_balloon=b.virtio_balloon;e.virtio_console=!!b.virtio_console;if(f=b.network_relay_url||b.net_device&&b.net_device.relay_url)"fetch"===
302
+ f?this.network_adapter=new Wb(this.bus,b.net_device):"inbrowser"===f?this.network_adapter=new pc(this.bus,b.net_device):f.startsWith("wisp://")||f.startsWith("wisps://")?this.network_adapter=new Yb(f,this.bus,b.net_device):this.network_adapter=new pb(f,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 $b(this.bus));b.disable_mouse||(this.mouse_adapter=new ac(this.bus,f.container));this.absolute_pointer_enabled=
303
+ !1;this.bus.register("vmware-absolute-mouse",function(q){q&&!this.absolute_pointer_enabled&&"undefined"!==typeof document&&document.pointerLockElement&&document.exitPointerLock();this.absolute_pointer_enabled=q},this);this.screen_adapter=f.container?new xa(f,()=>this.v86.cpu.devices.vga&&this.v86.cpu.devices.vga.screen_fill_buffer()):f.ansi?new cc(f):new bc(f);e.screen=this.screen_adapter;e.screen_options=f;e.serial_console=b.serial_console||{type:"none"};b.serial_container_xtermjs?(e.serial_console.type=
304
+ "xtermjs",e.serial_console.container=b.serial_container_xtermjs):b.serial_container&&(e.serial_console.type="textarea",e.serial_console.container=b.serial_container);"xtermjs"===e.serial_console?.type?this.serial_adapter=new nc(e.serial_console.container,this.bus,e.serial_console.xterm_lib||window.Terminal):"textarea"===e.serial_console?.type&&(this.serial_adapter=new ec(e.serial_console.container,this.bus));f=b.virtio_console&&"boolean"===typeof b.virtio_console?{type:"none"}:b.virtio_console;"xtermjs"===
305
+ f?.type?this.virtio_console_adapter=new oc(f.container,this.bus,f.xterm_lib||window.Terminal):"textarea"===f?.type&&(this.virtio_console_adapter=new fc(f.container,this.bus));e.modem&&(this.modem=new G(this.bus,e.modem));b.disable_speaker||(this.speaker_adapter=new jb(this.bus));var g=[];f=(q,r)=>{if(r)if(r.get&&r.set&&r.load)g.push({name:q,loadable:r});else{if("bios"===q||"vga_bios"===q||"initial_state"===q||"multiboot"===q||"bzimage"===q||"initrd"===q)r.async=!1;if("fda"===q||"fdb"===q)r.async=
306
+ !1;r.url&&!r.async?g.push({name:q,url:r.url,size:r.size}):g.push({name:q,loadable:Ca(r,this.zstd_decompress_worker.bind(this))})}};b.state&&console.warn("Warning: Unknown option 'state'. Did you mean 'initial_state'?");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&&b.filesystem.handle9p)e.handle9p=b.filesystem.handle9p;
307
+ else if(b.filesystem&&b.filesystem.proxy_url)e.proxy9p=b.filesystem.proxy_url;else if(b.filesystem){f=b.filesystem.basefs;var h=b.filesystem.baseurl;let q=new vc;h&&(q=new wc(q,h,this.zstd_decompress.bind(this)));e.fs9p=this.fs9p=new N(q);if(f){if("object"===typeof f){var l=f.size;f=f.url}g.push({name:"fs9p_json",url:f,size:l,as_json:!0})}}var m=this,n=g.length,p=function(q){if(q===n)setTimeout(d.bind(this),0);else{var r=g[q];r.loadable?(r.loadable.onload=function(){c.call(this,r.name,r.loadable);
308
+ p(q+1)}.bind(this),r.loadable.load()):pa(r.url,{done:function(x){r.url.endsWith(".zst")&&"initial_state"!==r.name&&(x=this.zstd_decompress(r.size,new Uint8Array(x)));c.call(this,r.name,r.as_json?x:new A(x));p(q+1)}.bind(this),progress:function(x){200===x.target.status?m.emulator_bus.send("download-progress",{file_index:q,file_count:n,file_name:r.url,lengthComputable:x.lengthComputable,total:x.total||r.size,loaded:x.loaded}):m.emulator_bus.send("download-error",{file_index:q,file_count:n,file_name:r.url,
309
+ request:x.target})},as_json:r.as_json})}}.bind(this);p(0)};O.prototype.zstd_decompress=function(a,b){const c=this.v86.cpu;this.zstd_context=c.zstd_create_ctx(b.length);(new Uint8Array(c.wasm_memory.buffer)).set(b,c.zstd_get_src_ptr(this.zstd_context));b=c.zstd_read(this.zstd_context,a);const d=c.wasm_memory.buffer.slice(b,b+a);c.zstd_read_free(b,a);c.zstd_free_ctx(this.zstd_context);this.zstd_context=null;return d};O.prototype.zstd_decompress_worker=async function(a,b){if(!this.zstd_worker){const c=
310
+ URL.createObjectURL(new Blob(["("+function(){let d;globalThis.onmessage=function(e){if(d){var {src:f,decompressed_size:g,id:h}=e.data;e=d.exports;var l=e.zstd_create_ctx(f.length);(new Uint8Array(e.memory.buffer)).set(f,e.zstd_get_src_ptr(l));var m=e.zstd_read(l,g),n=e.memory.buffer.slice(m,m+g);e.zstd_read_free(m,g);e.zstd_free_ctx(l);postMessage({result:n,id:h},[n])}else l=Object.fromEntries("cpu_exception_hook run_hardware_timers cpu_event_halt microtick get_rand_int stop_idling io_port_read8 io_port_read16 io_port_read32 io_port_write8 io_port_write16 io_port_write32 mmap_read8 mmap_read32 mmap_write8 mmap_write16 mmap_write32 mmap_write64 mmap_write128 codegen_finalize jit_clear_func jit_clear_all_funcs".split(" ").map(p=>
311
+ [p,()=>console.error("zstd worker unexpectedly called "+p)])),l.__indirect_function_table=new WebAssembly.Table({element:"anyfunc",initial:1024}),l.abort=()=>{throw Error("zstd worker aborted");},l.log_from_wasm=l.console_log_from_wasm=(p,q)=>{console.log(ra(d.exports.memory.buffer,p,q))},l.dbg_trace_from_wasm=()=>console.trace(),d=new WebAssembly.Instance(new WebAssembly.Module(e.data),{env:l})}}.toString()+")()"],{type:"text/javascript"}));this.zstd_worker=new Worker(c);URL.revokeObjectURL(c);this.zstd_worker.postMessage(this.wasm_source,
312
+ [this.wasm_source])}return new Promise(c=>{const d=this.zstd_worker_request_id++,e=async f=>{f.data.id===d&&(this.zstd_worker.removeEventListener("message",e),c(f.data.result))};this.zstd_worker.addEventListener("message",e);this.zstd_worker.postMessage({src:b,decompressed_size:a,id:d},[b.buffer])})};O.prototype.get_bzimage_initrd_from_filesystem=function(a){const b=(a.read_dir("/")||[]).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)||
313
+ /fallback/i.test(e),g=/vmlinuz/i.test(e)||/bzimage/i.test(e),h=/initrd/i.test(e)||/initramfs/i.test(e);!g||d&&f||(d=e);!h||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&&await new Promise(a=>{const b=()=>{this.remove_listener("emulator-stopped",b);a()};this.add_listener("emulator-stopped",
314
+ 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();this.virtio_console_adapter&&this.virtio_console_adapter.destroy();this.modem&&this.modem.destroy()};
315
+ 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){this.v86.restore_state(a)};O.prototype.save_state=async function(){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=function(){return this.cpu_is_running};O.prototype.set_fda=
316
+ async function(a){const b=this.v86.cpu.devices.fdc.drives[0];if(a.url&&!a.async)await new Promise(c=>{pa(a.url,{done:d=>{b.insert_disk(new A(d));c()}})});else{const c=Ca(a,this.zstd_decompress_worker.bind(this));c.onload=()=>{b.insert_disk(c)};await c.load()}};O.prototype.set_fdb=async function(a){const b=this.v86.cpu.devices.fdc.drives[1];if(a.url&&!a.async)await new Promise(c=>{pa(a.url,{done:d=>{b.insert_disk(new A(d));c()}})});else{const c=Ca(a,this.zstd_decompress_worker.bind(this));c.onload=
317
+ ()=>{b.insert_disk(c)};await c.load()}};O.prototype.eject_fda=function(){this.v86.cpu.devices.fdc.drives[0].eject_disk()};O.prototype.eject_fdb=function(){this.v86.cpu.devices.fdc.drives[1].eject_disk()};O.prototype.get_disk_fda=function(){return this.v86.cpu.devices.fdc.drives[0].get_buffer()};O.prototype.get_disk_fdb=function(){return this.v86.cpu.devices.fdc.drives[1].get_buffer()};O.prototype.set_cdrom=async function(a){if(a.url&&!a.async)pa(a.url,{done:b=>{this.v86.cpu.devices.cdrom.set_cdrom(new A(b))}});
318
+ else{const b=Ca(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=async function(a,b){for(var c=0;c<a.length;c++)this.bus.send("keyboard-code",a[c]),b&&await new Promise(d=>setTimeout(d,b))};O.prototype.keyboard_send_keys=async function(a,b){for(var c=0;c<a.length;c++)this.keyboard_adapter.simulate_press(a[c]),b&&await new Promise(d=>
319
+ setTimeout(d,b))};O.prototype.keyboard_send_text=async function(a,b){for(var c=0;c<a.length;c++)this.keyboard_adapter.simulate_char(a[c]),b&&await new Promise(d=>setTimeout(d,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");
320
+ 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=async function(){const a=document.body;try{await a.requestPointerLock({unadjustedMovement:!0})}catch(b){await a.requestPointerLock()}};O.prototype.mouse_set_enabled=function(a){this.mouse_adapter&&(this.mouse_adapter.emu_enabled=
321
+ a)};O.prototype.mouse_set_status=O.prototype.mouse_set_enabled;O.prototype.keyboard_set_enabled=function(a){this.keyboard_adapter&&(this.keyboard_adapter.emu_enabled=a)};O.prototype.keyboard_set_status=O.prototype.keyboard_set_enabled;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_carrier_detect=function(a,
322
+ 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"+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.create_file=async function(a,b){var c=this.fs9p;if(c){var d=a.split("/");d=d[d.length-1];a=c.SearchPath(a).parentid;if(""!==
323
+ d&&-1!==a)await c.CreateBinaryFile(d,a,b);else return Promise.reject(new Dc)}};O.prototype.read_file=async function(a){var b=this.fs9p;if(b)return(a=await b.read_file(a))?a:Promise.reject(new Dc)};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):this.keyboard_send_text(d.keyboard_send),
324
+ b(e)):d.call&&(d.call(),b(e))}};b(a)};O.prototype.wait_until_vga_screen_contains=async function(a,b){const c=Array.isArray(a);var d=b?.timeout_msec||0;const e=new Set;b=m=>e.add(m[0]);const f=(m,n)=>n.test?n.test(m):m.startsWith(n),g=[];this.add_listener("screen-put-char",b);for(var h of this.screen_adapter.get_text_screen())if(c)g.push(h.trimRight());else if(f(h,a))return this.remove_listener("screen-put-char",b),!0;h=!1;d=d?performance.now()+d:0;a:for(;!d||performance.now()<d;){if(c){for(var l=
325
+ g.length;0<l&&""===g[l-1];)l--;l-=a.length;if(0<=l){let m=!0;for(let n=0;n<a.length&&m;n++)m=f(g[l+n],a[n]);if(m){h=!0;break}}}await new Promise(m=>setTimeout(m,100));for(const m of e)if(l=this.screen_adapter.get_text_row(m),c)g[m]=l.trimRight();else if(f(l,a)){h=!0;break a}e.clear()}this.remove_listener("screen-put-char",b);return h};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=
326
+ function(a,b=window.Terminal){this.serial_adapter&&this.serial_adapter.destroy&&this.serial_adapter.destroy();this.serial_adapter=new nc(a,this.bus,b);this.serial_adapter.show()};O.prototype.set_virtio_console_container_xtermjs=function(a,b=window.Terminal){this.virtio_console_adapter&&this.virtio_console_adapter.destroy&&this.virtio_console_adapter.destroy();this.virtio_console_adapter=new oc(a,this.bus,b);this.virtio_console_adapter.show()};O.prototype.get_instruction_stats=function(){var a=this.v86.cpu;
327
+ 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(" "),
327
328
  d=0;const e={};for(let g=0;g<c.length;g++){const h=c[g];var f=void 0;if(h.includes("/")){d++;const [l,m]=h.split("/");f=e[l]/e[m]}else f=e[h]=a.wm.exports.profiler_stat_get(g-d),f=1E8<=f?Math.round(f/1E6)+"m":1E5<=f?Math.round(f/1E3)+"k":f;b+=h+"="+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");
328
329
  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,
329
330
  !1,!0,!1),gb(a,!1,!1,!1,!0)].join("\n\n");return b+a};function Dc(a){this.message=a||"File not found"}Dc.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 F(a,b){this.stopping=this.running=!1;this.idle=!0;this.tick_counter=0;this.worker=null;this.cpu=new R(a,b,()=>{this.idle&&this.next_tick(0)});this.bus=a;this.register_yield()}F.prototype.run=
@@ -377,11 +378,11 @@ function(){return this.data_port_read16()&255};Jc.prototype.data_port_read16=fun
377
378
  a[4]&&255===a[5]||!(this.rxcr&8&&1===(a[0]&1)||a[0]!==this.mac[0]||a[1]!==this.mac[1]||a[2]!==this.mac[2]||a[3]!==this.mac[3]||a[4]!==this.mac[4]||a[5]!==this.mac[5]))){this.mac_address_in_state&&(a=new Uint8Array(a),Hc(a,this.mac,this.mac_address_in_state));var b=this.curpg<<8,c=Math.max(60,a.length)+4,d=b+4,e=this.curpg+1+(c>>8),f=b+c,g=1+(c>>8),h=this.boundary>this.curpg?this.boundary-this.curpg:this.pstop-this.curpg+this.boundary-this.pstart;h<g&&0!==this.boundary?(y(this.pstart),y(this.pstop),
378
379
  y(this.curpg),y(g),y(this.boundary),y(h)):(f>this.pstop<<8?(f=(this.pstop<<8)-d,this.memory.set(a.subarray(0,f),d),this.memory.set(a.subarray(f),this.pstart<<8),y(f)):(this.memory.set(a,d),60>a.length&&this.memory.fill(0,d+a.length,d+60)),e>=this.pstop&&(e+=this.pstart-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,y(b),y(c),y(e),this.do_interrupt(1))}};Jc.prototype.get_page=function(){return this.cr>>6&3};function Kc(a,b){this.bus=b;this.rows=
379
380
  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,notify_offset:0}),b.push({size_supported:8,notify_offset:1});this.virtio=new Lc(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,
380
- handlers:[()=>{},c=>{const d=this.virtio.queues[c],e=3<c?c-3>>1:0;for(;d.has_request();){const f=d.pop_request(),g=new Uint8Array(f.length_readable);f.get_next_blob(g);this.bus.send("virtio-console"+e+"-output-bytes",g);this.Ack(c,f)}},()=>{},c=>{if(3===c)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 g=J(["w","h","h"],f,{offset:0});f=g[0];g=g[1];this.Ack(c,e);switch(g){case 0:for(e=0;e<this.ports;++e)this.SendEvent(e,
381
+ handlers:[()=>{},c=>{const d=this.virtio.queues[c],e=3<c?c-3>>1:0;for(;d.has_request();){const f=d.pop_request(),g=new Uint8Array(f.length_readable);f.get_next_blob(g);this.bus.send("virtio-console"+e+"-output-bytes",g);this.Ack(c,f)}},()=>{},c=>{if(3===c)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 g=L(["w","h","h"],f,{offset:0});f=g[0];g=g[1];this.Ack(c,e);switch(g){case 0:for(e=0;e<this.ports;++e)this.SendEvent(e,
381
382
  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: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",read:()=>0,write:()=>{}}]}});for(let c=0;c<
382
383
  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)}}Kc.prototype.SendWindowSize=function(a,b,c){c=c||this.rows;b=b||this.cols;const d=
383
- this.virtio.queues[2].pop_request(),e=new Uint8Array(12);I(["w","h","h","h","h"],[a,5,0,c,b],e,0);this.Send(2,d,e)};Kc.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);I(["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)};Kc.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.rows;a[2]=this.cols;a[3]=this.ports;return a};Kc.prototype.set_state=
384
- function(a){this.virtio.set_state(a[0]);this.rows=a[1];this.cols=a[2];this.ports=a[3]};Kc.prototype.reset=function(){this.virtio.reset()};Kc.prototype.SendEvent=function(a,b,c){const d=this.virtio.queues[2].pop_request(),e=new Uint8Array(8);I(["w","h","h"],[a,b,c],e,0);this.Send(2,d,e)};Kc.prototype.Send=function(a,b,c){b.set_next_blob(c);this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};Kc.prototype.Ack=function(a,b){b.set_next_blob(new Uint8Array(0));this.virtio.queues[a].push_reply(b);
384
+ 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)};Kc.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)};Kc.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.rows;a[2]=this.cols;a[3]=this.ports;return a};Kc.prototype.set_state=
385
+ function(a){this.virtio.set_state(a[0]);this.rows=a[1];this.cols=a[2];this.ports=a[3]};Kc.prototype.reset=function(){this.virtio.reset()};Kc.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)};Kc.prototype.Send=function(a,b,c){b.set_next_blob(c);this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};Kc.prototype.Ack=function(a,b){b.set_next_blob(new Uint8Array(0));this.virtio.queues[a].push_reply(b);
385
386
  this.virtio.queues[a].flush_replies()};function Mc(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,Math.max(-8,this.wheel_movement));
386
387
  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)}Mc.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=this.next_read_led=this.next_read_sample=
387
388
  this.next_is_mouse_command=this.enable_keyboard_stream=!1;this.kbd_buffer=new la(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 la(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=this.read_output_register=
@@ -400,274 +401,279 @@ this.mouse_buffer.push(this.mouse_id);this.mouse_clicks=this.mouse_delta_x=this.
400
401
  this.use_mouse=!0;this.bus.send("mouse-enable",!0);this.enable_mouse_stream=!1;this.sample_rate=100;this.scaling2=!1;this.resolution=4;this.mouse_reset_workaround||(this.mouse_id=0);this.mouse_clicks=this.mouse_delta_x=this.mouse_delta_y=0;break;default:y(a)}this.mouse_irq()}}else if(this.read_controller_output_port)this.read_controller_output_port=!1,this.controller_output_port=a;else{y(a);this.mouse_buffer.clear();this.kbd_buffer.clear();this.kbd_buffer.push(250);switch(a){case 237:this.next_read_led=
401
402
  !0;break;case 240:this.next_handle_scan_code_set=!0;break;case 242:this.kbd_buffer.push(171);this.kbd_buffer.push(131);break;case 243:this.next_read_rate=!0;break;case 244:this.enable_keyboard_stream=!0;break;case 245:this.enable_keyboard_stream=!1;break;case 246:break;case 255:this.kbd_buffer.clear();this.kbd_buffer.push(250);this.kbd_buffer.push(170);this.kbd_buffer.push(0);break;default:y(a)}this.kbd_irq()}};Mc.prototype.port64_write=function(a){y(a);switch(a){case 32:this.kbd_buffer.clear();this.mouse_buffer.clear();
402
403
  this.kbd_buffer.push(this.command_register);this.kbd_irq();break;case 96:this.read_command_register=!0;break;case 209:this.read_controller_output_port=!0;break;case 211:this.read_output_register=!0;break;case 212:this.next_is_mouse_command=!0;break;case 167:this.command_register|=32;break;case 168:this.command_register&=-33;break;case 169:this.kbd_buffer.clear();this.mouse_buffer.clear();this.kbd_buffer.push(0);this.kbd_irq();break;case 170:this.kbd_buffer.clear();this.mouse_buffer.clear();this.kbd_buffer.push(85);
403
- this.kbd_irq();break;case 171:this.kbd_buffer.clear();this.mouse_buffer.clear();this.kbd_buffer.push(0);this.kbd_irq();break;case 173:this.command_register|=16;break;case 174:this.command_register&=-17;break;case 254:this.cpu.reboot_internal();break;default:y(a)}};const Nc=DataView.prototype,Oc={size:1,get:Nc.getUint8,set:Nc.setUint8},Pc={size:2,get:Nc.getUint16,set:Nc.setUint16},V={size:4,get:Nc.getUint32,set:Nc.setUint32},Rc=Qc([{magic:V},{class:Oc},{data:Oc},{version0:Oc},{osabi:Oc},{abiversion:Oc},
404
- {pad0:function(a){return{size:a,get:()=>-1}}(7)},{type:Pc},{machine:Pc},{version1:V},{entry:V},{phoff:V},{shoff:V},{flags:V},{ehsize:Pc},{phentsize:Pc},{phnum:Pc},{shentsize:Pc},{shnum:Pc},{shstrndx:Pc}]);console.assert(52===Rc.reduce((a,b)=>a+b.size,0));const Sc=Qc([{type:V},{offset:V},{vaddr:V},{paddr:V},{filesz:V},{memsz:V},{flags:V},{align:V}]);console.assert(32===Sc.reduce((a,b)=>a+b.size,0));const Tc=Qc([{name:V},{type:V},{flags:V},{addr:V},{offset:V},{size:V},{link:V},{info:V},{addralign:V},
405
- {entsize:V}]);console.assert(40===Tc.reduce((a,b)=>a+b.size,0));function Qc(a){return a.map(function(b){var c=Object.keys(b);console.assert(1===c.length);c=c[0];b=b[c];console.assert(0<b.size);return{name:c,type:b,size:b.size,get:b.get,set:b.set}})}function Uc(a,b){const c={};let d=0;for(const e of b)b=e.get.call(a,d,!0),console.assert(void 0===c[e.name]),c[e.name]=b,d+=e.size;return[c,d]}function Vc(a,b,c){const d=[];let e=0;for(var f=0;f<c;f++){const [g,h]=Uc(new DataView(a.buffer,a.byteOffset+
406
- e,void 0),b);d.push(g);e+=h}return[d,e]}const Wc={[0]:0,[1]:525,[2]:525,[3]:350,[4]:350,[5]:350};function W(a,b,c,d){this.io=a.io;this.cpu=a;this.dma=a.devices.dma;this.cmd_table=this.build_cmd_lookup_table();this.sra=0;this.srb=192;this.dor=12;this.tdr=0;this.msr=128;this.dsr=0;this.cmd_phase=1;this.cmd_flags=this.cmd_code=0;this.cmd_buffer=new Uint8Array(17);this.cmd_remaining=this.cmd_cursor=0;this.response_data=new Uint8Array(15);this.reset_sense_int_count=this.curr_drive_no=this.status1=this.status0=
407
- this.response_length=this.response_cursor=0;this.locked=!1;this.head_load_time=this.step_rate_interval=0;this.fdc_config=96;this.eot=this.precomp_trk=0;this.drives=[new Xc("fda",d?.fda,b,4),new Xc("fdb",d?.fdb,c,4)];Object.seal(this);this.cpu.devices.rtc.cmos_write(16,this.drives[0].drive_type<<4|this.drives[1].drive_type);this.io.register_read(1008,this,this.read_reg_sra);this.io.register_read(1009,this,this.read_reg_srb);this.io.register_read(1010,this,this.read_reg_dor);this.io.register_read(1011,
408
- this,this.read_reg_tdr);this.io.register_read(1012,this,this.read_reg_msr);this.io.register_read(1013,this,this.read_reg_fifo);this.io.register_read(1015,this,this.read_reg_dir);this.io.register_write(1010,this,this.write_reg_dor);this.io.register_write(1011,this,this.write_reg_tdr);this.io.register_write(1012,this,this.write_reg_dsr);this.io.register_write(1013,this,this.write_reg_fifo);this.io.register_write(1015,this,this.write_reg_ccr)}W.prototype.build_cmd_lookup_table=function(){const a=[{code:6,
409
- mask:31,argc:8,name:"READ",handler:this.exec_read},{code:5,mask:63,argc:8,name:"WRITE",handler:this.exec_write},{code:15,mask:255,argc:2,name:"SEEK",handler:this.exec_seek},{code:8,mask:255,argc:0,name:"SENSE INTERRUPT STATUS",handler:this.exec_sense_interrupt_status},{code:7,mask:255,argc:1,name:"RECALIBRATE",handler:this.exec_recalibrate},{code:13,mask:191,argc:5,name:"FORMAT TRACK",handler:this.exec_format_track},{code:2,mask:191,argc:8,name:"READ TRACK",handler:this.exec_unimplemented},{code:78,
410
- mask:255,argc:17,name:"RESTORE",handler:this.exec_unimplemented},{code:46,mask:255,argc:0,name:"SAVE",handler:this.exec_unimplemented},{code:12,mask:31,argc:8,name:"READ DELETED DATA",handler:this.exec_unimplemented},{code:17,mask:31,argc:8,name:"SCAN EQUAL",handler:this.exec_unimplemented},{code:22,mask:31,argc:8,name:"VERIFY",handler:this.exec_unimplemented},{code:25,mask:31,argc:8,name:"SCAN LOW OR EQUAL",handler:this.exec_unimplemented},{code:29,mask:31,argc:8,name:"SCAN HIGH OR EQUAL",handler:this.exec_unimplemented},
411
- {code:9,mask:63,argc:8,name:"WRITE DELETED DATA",handler:this.exec_unimplemented},{code:10,mask:191,argc:1,name:"READ ID",handler:this.exec_read_id},{code:3,mask:255,argc:2,name:"SPECIFY",handler:this.exec_specify},{code:4,mask:255,argc:1,name:"SENSE DRIVE STATUS",handler:this.exec_sense_drive_status},{code:18,mask:255,argc:1,name:"PERPENDICULAR MODE",handler:this.exec_perpendicular_mode},{code:19,mask:255,argc:3,name:"CONFIGURE",handler:this.exec_configure},{code:23,mask:255,argc:2,name:"POWERDOWN MODE",
412
- handler:this.exec_unimplemented},{code:51,mask:255,argc:1,name:"OPTION",handler:this.exec_unimplemented},{code:142,mask:255,argc:5,name:"DRIVE SPECIFICATION",handler:this.exec_unimplemented},{code:143,mask:255,argc:2,name:"RELATIVE SEEK OUT",handler:this.exec_unimplemented},{code:205,mask:255,argc:10,name:"FORMAT AND WRITE",handler:this.exec_unimplemented},{code:207,mask:255,argc:2,name:"RELATIVE SEEK IN",handler:this.exec_unimplemented},{code:20,mask:127,argc:0,name:"LOCK",handler:this.exec_lock},
413
- {code:14,mask:255,argc:0,name:"DUMP REGISTERS",handler:this.exec_dump_regs},{code:16,mask:255,argc:0,name:"VERSION",handler:this.exec_version},{code:24,mask:255,argc:0,name:"PART ID",handler:this.exec_part_id},{code:0,mask:0,argc:0,name:"UNKNOWN COMMAND",handler:this.exec_unimplemented}],b=Array(256);for(let c=a.length-1;0<=c;c--){const d=a[c];if(255===d.mask)b[d.code]=d;else for(let e=0;256>e;e++)(e&d.mask)===d.code&&(b[e]=d)}return b};W.prototype.raise_irq=function(){this.sra&128||(this.cpu.device_raise_irq(6),
414
- this.sra|=128);this.reset_sense_int_count=0};W.prototype.lower_irq=function(){this.status0=0;this.sra&128&&(this.cpu.device_lower_irq(6),this.sra&=-129)};W.prototype.set_curr_drive_no=function(a){this.curr_drive_no=a&1;return this.drives[this.curr_drive_no]};W.prototype.enter_command_phase=function(){this.cmd_phase=1;this.cmd_remaining=this.cmd_cursor=0;this.msr&=-81;this.msr|=128};W.prototype.enter_result_phase=function(a){this.cmd_phase=3;this.response_cursor=0;this.response_length=a;this.msr|=
415
- 208};W.prototype.reset_fdc=function(){this.lower_irq("controller reset");this.sra=0;this.srb=192;this.dor=12;this.msr=128;this.curr_drive_no=0;this.status0|=192;this.response_length=this.response_cursor=0;this.drives[0].seek(0,0,1);this.drives[1].seek(0,0,1);this.enter_command_phase();this.raise_irq("controller reset");this.reset_sense_int_count=4};W.prototype.read_reg_sra=function(){y(this.sra);return this.sra};W.prototype.read_reg_srb=function(){y(this.srb);return this.srb};W.prototype.read_reg_dor=
416
- function(){const a=this.dor&-4|this.curr_drive_no;y(a);return a};W.prototype.read_reg_tdr=function(){y(this.tdr);return this.tdr};W.prototype.read_reg_msr=function(){y(this.msr);this.dsr&=-65;this.dor|=4;return this.msr};W.prototype.read_reg_fifo=function(){this.dsr&=-65;if(!(this.msr&128&&this.msr&64)||3!==this.cmd_phase)return 0;if(this.response_cursor<this.response_length){const a=this.response_data[this.response_cursor++];this.response_cursor===this.response_length&&(this.msr&=-129,this.enter_command_phase(),
417
- this.lower_irq(""));return a}return 0};W.prototype.read_reg_dir=function(){const a=this.drives[this.curr_drive_no].media_changed?128:0;y(a);return a};W.prototype.write_reg_dor=function(a){this.srb=this.srb&-36|(a&16?1:0)|(a&32?2:0)|(a&1?32:0);!(this.dor&4)&&a&4&&(this.reset_fdc(),this.dsr&=-65);const b=a&3;y(a);y(a>>4);this.curr_drive_no=b&1;this.dor=a};W.prototype.write_reg_tdr=function(a){this.dor&4?(y(a),this.tdr=a&4):y(a)};W.prototype.write_reg_dsr=function(a){this.dor&4?(y(a),a&128&&(this.dor&=
418
- -5,this.reset_fdc(),this.dor|=4),a&64&&this.reset_fdc(),this.dsr=a):y(a)};W.prototype.write_reg_fifo=function(a){this.dsr&=-65;if(this.dor&4)if(!(this.msr&128)||this.msr&64)y(a);else if(1!==this.cmd_phase)y(a);else{if(0===this.cmd_remaining){var b=this.cmd_table[a];this.cmd_code=a;this.cmd_remaining=b.argc;this.cmd_flags=this.cmd_cursor=0;(6===b.code||5===b.code)&&this.cmd_code&128&&(this.cmd_flags|=1);this.cmd_remaining&&(this.msr|=128);this.msr|=16}else this.cmd_buffer[this.cmd_cursor++]=a,this.cmd_remaining--;
419
- 0===this.cmd_remaining&&(this.cmd_phase=2,a=this.cmd_table[this.cmd_code],b=this.cmd_buffer.slice(0,this.cmd_cursor),a.handler.call(this,b))}else y(a)};W.prototype.write_reg_ccr=function(a){this.dor&4?(y(a),this.dsr=this.dsr&-4|a&3):y(a)};W.prototype.exec_unimplemented=function(){y(this.cmd_code);this.status0=128;this.response_data[0]=this.status0;this.enter_result_phase(1)};W.prototype.exec_read=function(a){this.start_read_write(a,!1)};W.prototype.exec_write=function(a){this.start_read_write(a,!0)};
420
- W.prototype.exec_seek=function(a){const b=this.set_curr_drive_no(a[0]&1);a=a[1];this.enter_command_phase();b.seek(b.curr_head,a,b.curr_sect);this.status0|=32;this.raise_irq("SEEK command")};W.prototype.exec_sense_interrupt_status=function(){const a=this.drives[this.curr_drive_no];let b;if(0<this.reset_sense_int_count)b=192|4-this.reset_sense_int_count--;else if(this.sra&128)b=this.status0&-8|this.curr_drive_no;else{this.response_data[0]=128;this.enter_result_phase(1);return}this.response_data[0]=
421
- b;this.response_data[1]=a.curr_track;this.enter_result_phase(2);this.lower_irq("SENSE INTERRUPT command");this.status0=192};W.prototype.exec_recalibrate=function(a){this.set_curr_drive_no(a[0]&1).seek(0,0,1);this.enter_command_phase();this.status0|=32;this.raise_irq("RECALIBRATE command")};W.prototype.exec_format_track=function(a){let b=0,c=0;this.set_curr_drive_no(a[0]&1).read_only&&(b=96,c=2);this.end_read_write(b,c,0)};W.prototype.exec_read_id=function(a){const b=this.drives[this.curr_drive_no];
422
- b.curr_head=a[0]>>2&1;0!==b.max_sect&&(b.curr_sect=b.curr_sect%b.max_sect+1);this.end_read_write(0,0,0)};W.prototype.exec_specify=function(a){const b=a[1];this.step_rate_interval=a[0]>>4;this.head_load_time=b>>1;this.dor=b&1?this.dor&-9:this.dor|8;this.enter_command_phase()};W.prototype.exec_sense_drive_status=function(a){a=a[0];const b=this.set_curr_drive_no(a&1);b.curr_head=a>>2&1;this.response_data[0]=(b.read_only?64:0)|(0===b.curr_track?16:0)|b.curr_head<<2|this.curr_drive_no|40;this.enter_result_phase(1)};
423
- W.prototype.exec_perpendicular_mode=function(a){a=a[0];a&128&&(this.drives[this.curr_drive_no].perpendicular=a&7);this.enter_command_phase()};W.prototype.exec_configure=function(a){this.fdc_config=a[1];this.precomp_trk=a[2];this.enter_command_phase()};W.prototype.exec_lock=function(){this.cmd_code&128?(this.locked=!0,this.response_data[0]=16):(this.locked=!1,this.response_data[0]=0);this.enter_result_phase(1)};W.prototype.exec_dump_regs=function(){const a=this.drives[this.curr_drive_no];this.response_data[0]=
424
- this.drives[0].curr_track;this.response_data[1]=this.drives[1].curr_track;this.response_data[2]=0;this.response_data[3]=0;this.response_data[4]=this.step_rate_interval;this.response_data[5]=this.head_load_time<<1|(this.dor&8?1:0);this.response_data[6]=a.max_sect;this.response_data[7]=(this.locked?128:0)|a.perpendicular<<2;this.response_data[8]=this.fdc_config;this.response_data[9]=this.precomp_trk;this.enter_result_phase(10)};W.prototype.exec_version=function(){this.response_data[0]=144;this.enter_result_phase(1)};
425
- W.prototype.exec_part_id=function(){this.response_data[0]=65;this.enter_result_phase(1)};W.prototype.start_read_write=function(a,b){const c=this.set_curr_drive_no(a[0]&1),d=a[1],e=a[2],f=a[3];var g=a[4];const h=a[5];a=128>a[7]?a[7]:128;switch(c.seek(e,d,f)){case 2:this.end_read_write(64,0,0);this.response_data[3]=d;this.response_data[4]=e;this.response_data[5]=f;return;case 3:this.end_read_write(64,128,0);this.response_data[3]=d;this.response_data[4]=e;this.response_data[5]=f;return;case 1:this.status0|=
426
- 32}const l=128<<(7<g?7:g);g=c.chs2lba(d,e,f)*l;if(128!==l&&(a=this.cmd_flags&1?(2*h-f+1)*l:(h-f+1)*l,0>=a)){this.end_read_write(64,1,0);this.response_data[3]=d;this.response_data[4]=e;this.response_data[5]=f;return}this.eot=h;b&&c.read_only?(this.end_read_write(96,2,0),this.response_data[3]=d,this.response_data[4]=e,this.response_data[5]=f):this.dor&8&&(this.msr&=-129,(b?this.dma.do_write:this.dma.do_read).call(this.dma,c.buffer,g,a,2,m=>{m?this.end_read_write(64,0,0):(this.seek_next_sect(),this.end_read_write(0,
427
- 0,0))}))};W.prototype.end_read_write=function(a,b,c){const d=this.drives[this.curr_drive_no];this.status0&=-8;this.status0|=this.curr_drive_no;d.curr_head&&(this.status0|=4);this.status0|=a;this.msr|=192;this.msr&=-33;this.response_data[0]=this.status0;this.response_data[1]=b;this.response_data[2]=c;this.response_data[3]=d.curr_track;this.response_data[4]=d.curr_head;this.response_data[5]=d.curr_sect;this.response_data[6]=2;this.enter_result_phase(7);this.raise_irq(this.cmd_table[this.cmd_code].name+
428
- " command")};W.prototype.seek_next_sect=function(){const a=this.drives[this.curr_drive_no];let b=a.curr_track,c=a.curr_head,d=a.curr_sect,e=1;d>=a.max_sect||d===this.eot?(d=1,this.cmd_flags&1?0===c&&2===a.max_head?c=1:(c=0,b++,this.status0|=32,1===a.max_head&&(e=0)):(this.status0|=32,b++,e=0)):d++;a.seek(c,b,d);return e};W.prototype.get_state=function(){const a=[];a[19]=this.sra;a[20]=this.srb;a[21]=this.dor;a[22]=this.tdr;a[23]=this.msr;a[24]=this.dsr;a[25]=this.cmd_phase;a[26]=this.cmd_code;a[27]=
429
- this.cmd_flags;a[28]=this.cmd_buffer;a[29]=this.cmd_cursor;a[30]=this.cmd_remaining;a[31]=this.response_data;a[32]=this.response_cursor;a[33]=this.response_length;a[34]=this.status0;a[35]=this.status1;a[36]=this.curr_drive_no;a[37]=this.reset_sense_int_count;a[38]=this.locked;a[39]=this.step_rate_interval;a[40]=this.head_load_time;a[41]=this.fdc_config;a[42]=this.precomp_trk;a[43]=this.eot;a[44]=this.drives[0].get_state();a[45]=this.drives[1].get_state();return a};W.prototype.set_state=function(a){"undefined"!==
430
- typeof a[19]&&(this.sra=a[19],this.srb=a[20],this.dor=a[21],this.tdr=a[22],this.msr=a[23],this.dsr=a[24],this.cmd_phase=a[25],this.cmd_code=a[26],this.cmd_flags=a[27],this.cmd_buffer.set(a[28]),this.cmd_cursor=a[29],this.cmd_remaining=a[30],this.response_data.set(a[31]),this.response_cursor=a[32],this.response_length=a[33],this.status0=a[34],this.status1=a[35],this.curr_drive_no=a[36],this.reset_sense_int_count=a[37],this.locked=a[38],this.step_rate_interval=a[39],this.head_load_time=a[40],this.fdc_config=
431
- a[41],this.precomp_trk=a[42],this.eot=a[43],this.drives[0].set_state(a[44]),this.drives[1].set_state(a[45]))};const Yc=[{drive_type:4,sectors:18,tracks:80,heads:2},{drive_type:4,sectors:20,tracks:80,heads:2},{drive_type:4,sectors:21,tracks:80,heads:2},{drive_type:4,sectors:21,tracks:82,heads:2},{drive_type:4,sectors:21,tracks:83,heads:2},{drive_type:4,sectors:22,tracks:80,heads:2},{drive_type:4,sectors:23,tracks:80,heads:2},{drive_type:4,sectors:24,tracks:80,heads:2},{drive_type:5,sectors:36,tracks:80,
432
- heads:2},{drive_type:5,sectors:39,tracks:80,heads:2},{drive_type:5,sectors:40,tracks:80,heads:2},{drive_type:5,sectors:44,tracks:80,heads:2},{drive_type:5,sectors:48,tracks:80,heads:2},{drive_type:4,sectors:8,tracks:80,heads:2},{drive_type:4,sectors:9,tracks:80,heads:2},{drive_type:4,sectors:10,tracks:80,heads:2},{drive_type:4,sectors:10,tracks:82,heads:2},{drive_type:4,sectors:10,tracks:83,heads:2},{drive_type:4,sectors:13,tracks:80,heads:2},{drive_type:4,sectors:14,tracks:80,heads:2},{drive_type:2,
433
- sectors:15,tracks:80,heads:2},{drive_type:2,sectors:18,tracks:80,heads:2},{drive_type:2,sectors:18,tracks:82,heads:2},{drive_type:2,sectors:18,tracks:83,heads:2},{drive_type:2,sectors:20,tracks:80,heads:2},{drive_type:2,sectors:9,tracks:80,heads:2},{drive_type:2,sectors:11,tracks:80,heads:2},{drive_type:2,sectors:9,tracks:40,heads:2},{drive_type:2,sectors:9,tracks:40,heads:1},{drive_type:2,sectors:10,tracks:41,heads:2},{drive_type:2,sectors:10,tracks:42,heads:2},{drive_type:2,sectors:8,tracks:40,
434
- heads:2},{drive_type:2,sectors:8,tracks:40,heads:1},{drive_type:4,sectors:9,tracks:80,heads:1},{drive_type:1,sectors:10,tracks:40,heads:1},{drive_type:1,sectors:10,tracks:40,heads:2}];function Xc(a,b,c,d){this.name=a;this.curr_head=this.curr_track=this.max_sect=this.max_head=this.max_track=this.drive_type=0;this.curr_sect=1;this.perpendicular=0;this.read_only=!1;this.media_changed=!0;this.buffer=null;Object.seal(this);a=b?.drive_type;void 0!==a&&0<=a&&5>=a&&(this.drive_type=a);this.insert_disk(c,
435
- !!b?.read_only);0===this.drive_type&&void 0===a&&(this.drive_type=d)}Xc.prototype.insert_disk=function(a,b){if(!a)return!1;a instanceof Uint8Array&&(a=new z(a.buffer));const [c,d]=this.find_disk_format(a,this.drive_type);if(!c)return!1;this.max_track=d.tracks;this.max_head=d.heads;this.max_sect=d.sectors;this.read_only=!!b;this.media_changed=!0;this.buffer=c;0===this.drive_type&&(this.drive_type=d.drive_type);return!0};Xc.prototype.eject_disk=function(){this.max_sect=this.max_head=this.max_track=
436
- 0;this.media_changed=!0;this.buffer=null};Xc.prototype.get_buffer=function(){return this.buffer?new Uint8Array(this.buffer.buffer):null};Xc.prototype.chs2lba=function(a,b,c){return(a*this.max_head+b)*this.max_sect+c-1};Xc.prototype.find_disk_format=function(a,b){const c=0===b,d=a.byteLength;let e=-1,f=-1,g=-1,h=-1,l=-1;for(let m=0;m<Yc.length;m++){const n=Yc[m],p=n.sectors*n.tracks*n.heads*512;if(d===p)if(c||n.drive_type===b){e=m;break}else c||Wc[n.drive_type]!==Wc[b]?g=-1===g?m:g:f=-1===f?m:f;else d<
437
- p&&(-1===l||p<l)&&(h=m,l=p)}return-1!==e?[a,Yc[e]]:-1!==f?[a,Yc[f]]:-1!==g?[a,Yc[g]]:-1!==h?(b=new Uint8Array(l),b.set(new Uint8Array(a.buffer)),[new z(b.buffer),Yc[h]]):[null,null]};Xc.prototype.seek=function(a,b,c){if(b>this.max_track||0!==a&&1===this.max_head)return 2;if(c>this.max_sect)return 3;let d=0;const e=this.chs2lba(this.curr_track,this.curr_head,this.curr_sect),f=this.chs2lba(b,a,c);e!==f&&(this.curr_track!==b&&(this.buffer&&(this.media_changed=!1),d=1),this.curr_head=a,this.curr_track=
438
- b,this.curr_sect=c);this.buffer||(d=2);return d};Xc.prototype.get_state=function(){const a=[];a[0]=this.drive_type;a[1]=this.max_track;a[2]=this.max_head;a[3]=this.max_sect;a[4]=this.curr_track;a[5]=this.curr_head;a[6]=this.curr_sect;a[7]=this.perpendicular;a[8]=this.read_only;a[9]=this.media_changed;a[10]=this.buffer?this.buffer.get_state():null;return a};Xc.prototype.set_state=function(a){this.drive_type=a[0];this.max_track=a[1];this.max_head=a[2];this.max_sect=a[3];this.curr_track=a[4];this.curr_head=
439
- a[5];this.curr_sect=a[6];this.perpendicular=a[7];this.read_only=a[8];this.media_changed=a[9];a[10]?(this.buffer||(this.buffer=new z(new ArrayBuffer(0))),this.buffer.set_state(a[10])):this.buffer=null};const Zc={[70]:{name:"GET CONFIGURATION",flags:0},[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",
440
- flags:0},[40]:{name:"READ (10)",flags:1},[168]:{name:"READ (12)",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",flags:1},[3]:{name:"REQUEST SENSE",flags:0},[27]:{name:"START STOP UNIT",flags:0},[0]:{name:"TEST UNIT READY",flags:1}};function $c(a,b,c){this.cpu=a;this.bus=b;this.secondary=this.primary=void 0;b=c&&c[0][0];
441
- const d=c&&c[1][0];if(b||d){b&&(this.primary=new ad(this,0,c[0],496,1014,14));d&&(this.secondary=new ad(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,g=d?this.secondary.control_base:0;this.name="ide";this.pci_id=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,g&255|1,g>>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,
442
- 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)}$c.prototype.get_state=function(){const a=[];a[0]=this.primary;a[1]=this.secondary;return a};$c.prototype.set_state=function(a){this.primary&&this.primary.set_state(a[0]);
443
- this.secondary&&this.secondary.set_state(a[1])};function ad(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 X(this,0,d?.buffer,d?.is_cdrom);this.slave=new X(this,1,c?.buffer,c?.is_cdrom);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)},
444
- 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&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&
445
- 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 g=this.read_status();this.cpu.device_lower_irq(this.irq);return g});a.io.register_write(this.command_base|0,this,function(g){this.current_interface.write_data_port8(g)},function(g){this.current_interface.write_data_port16(g)},function(g){this.current_interface.write_data_port32(g)});
446
- a.io.register_write(this.command_base|1,this,function(g){this.master.features_reg=(this.master.features_reg<<8|g)&65535;this.slave.features_reg=(this.slave.features_reg<<8|g)&65535});a.io.register_write(this.command_base|2,this,function(g){this.master.sector_count_reg=(this.master.sector_count_reg<<8|g)&65535;this.slave.sector_count_reg=(this.slave.sector_count_reg<<8|g)&65535});a.io.register_write(this.command_base|3,this,function(g){this.master.lba_low_reg=(this.master.lba_low_reg<<8|g)&65535;this.slave.lba_low_reg=
447
- (this.slave.lba_low_reg<<8|g)&65535});a.io.register_write(this.command_base|4,this,function(g){this.master.lba_mid_reg=(this.master.lba_mid_reg<<8|g)&65535;this.slave.lba_mid_reg=(this.slave.lba_mid_reg<<8|g)&65535});a.io.register_write(this.command_base|5,this,function(g){this.master.lba_high_reg=(this.master.lba_high_reg<<8|g)&65535;this.slave.lba_high_reg=(this.slave.lba_high_reg<<8|g)&65535});a.io.register_write(this.command_base|6,this,function(g){const h=g&16;if(h&&this.current_interface===
448
- this.master||!h&&this.current_interface===this.slave)this.current_interface=h?this.slave:this.master;this.master.device_reg=g;this.slave.device_reg=g;this.master.is_lba=g>>6&1;this.slave.is_lba=g>>6&1;this.master.head=g&15;this.slave.head=g&15});a.io.register_write(this.command_base|7,this,function(g){this.current_interface.status_reg&=-34;this.current_interface.ata_command(g);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|
449
- 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|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)}ad.prototype.read_status=function(){return this.current_interface.drive_connected?
450
- this.current_interface.status_reg:0};ad.prototype.write_control=function(a){a&4&&(this.cpu.device_lower_irq(this.irq),this.master.device_reset(),this.slave.device_reset());this.device_control_reg=a};ad.prototype.dma_read_addr=function(){return this.prdt_addr};ad.prototype.dma_set_addr=function(a){this.prdt_addr=a};ad.prototype.dma_read_status=function(){return this.dma_status};ad.prototype.dma_write_status=function(a){this.dma_status&=~(a&6)};ad.prototype.dma_read_command=function(){return this.dma_read_command8()|
451
- this.dma_read_status()<<16};ad.prototype.dma_read_command8=function(){return this.dma_command};ad.prototype.dma_write_command=function(a){this.dma_write_command8(a&255);this.dma_write_status(a>>16&255)};ad.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();
452
- break;case 160:this.current_interface.do_atapi_dma();break;default:y(this.current_interface.current_command),this.dma_status&=-2,this.dma_status|=2,this.push_irq()}};ad.prototype.push_irq=function(){0===(this.device_control_reg&2)&&(this.dma_status|=4,this.cpu.device_raise_irq(this.irq))};ad.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;a[10]=this.dma_status;
453
- a[11]=this.current_interface===this.master;a[12]=this.dma_command;return a};ad.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 X(a,b,c,d){this.channel=a;this.name=a.name+"."+b;this.bus=a.bus;this.channel_nr=a.channel_nr;this.interface_nr=
454
- 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);this.data32=
455
- 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 Map;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);Object.seal(this)}X.prototype.has_disk=function(){return!!this.buffer};X.prototype.eject=function(){this.is_atapi&&this.buffer&&(this.medium_changed=!0,this.buffer=null,this.status_reg=89,this.error_reg=
456
- 96,this.push_irq())};X.prototype.set_cdrom=function(a){this.is_atapi&&a&&(this.set_disk_buffer(a),this.medium_changed=!0)};X.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)&&(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=
457
- this.sector_count/this.head_count/this.sectors_per_track;this.cylinder_count!==(this.cylinder_count|0)&&(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)|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);
458
- 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()}};X.prototype.device_reset=function(){this.is_atapi?(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()};
459
- X.prototype.push_irq=function(){this.channel.push_irq()};X.prototype.ata_abort_command=function(){this.error_reg=4;this.status_reg=65;this.push_irq()};X.prototype.capture_regs=function(){return`ST=${y(this.status_reg&255)} ER=${y(this.error_reg&255)} `+`SC=${y(this.sector_count_reg&255)} LL=${y(this.lba_low_reg&255)} `+`LM=${y(this.lba_mid_reg&255)} LH=${y(this.lba_high_reg&255)} `+`FE=${y(this.features_reg&255)}`};X.prototype.ata_command=function(a){if(this.drive_connected||144===a)switch(this.current_command=
460
- a,this.error_reg=0,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:a=this.sector_count-1;this.lba_low_reg=a&255;this.lba_mid_reg=a>>8&255;this.lba_high_reg=a>>16&255;this.device_reg=this.device_reg&240|a>>24&15;this.status_reg=80;this.push_irq();break;case 39:a=this.sector_count-1;this.lba_low_reg=a&255;this.lba_mid_reg=a>>8&255;this.lba_high_reg=a>>16&255;this.lba_low_reg|=
461
- a>>24<<8&65280;this.status_reg=80;this.push_irq();break;case 32: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:this.is_atapi?this.ata_abort_command():this.ata_read_sectors(a);break;case 48:case 52:case 57:case 197: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&&
462
- (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?(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:y(this.sector_count_reg&255);this.sectors_per_drq=this.sector_count_reg&
463
- 255;this.status_reg=80;this.push_irq();break;case 200:case 37:this.ata_read_sectors_dma(a);break;case 202:case 53: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=
464
- 80;this.push_irq();break;case 234:this.status_reg=80;this.push_irq();break;case 236:this.is_atapi?(this.lba_mid_reg=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;case 240:y(a);this.capture_regs();
465
- this.ata_abort_command();break;default:y(a),this.capture_regs(),this.ata_abort_command()}else y(a)};X.prototype.atapi_handle=function(){var a=this.data[0],b=Zc[a]?Zc[a].flags:0;this.data_pointer=0;this.current_atapi_command=a;3!==a&&(this.atapi_add_sense=this.atapi_sense_key=0);if(!this.buffer&&b&1)this.atapi_check_condition_response(2,58),this.push_irq();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,
466
- 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:a=this.data[4];this.status_reg=88;y(this.data[1],2);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]);
467
- 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:a=this.sector_count-1;this.data_set(new Uint8Array([a>>24&255,a>>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_reg=88;break;case 40:case 168:this.features_reg&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));
468
- this.data_end=this.data_length;this.status_reg=88;break;case 67:a=this.data[8]|this.data[7]<<8;b=this.data[9]>>6;y(b,2);y(this.data[6]);this.data_allocate(a);this.data_end=this.data_length;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]));this.status_reg=88;break;case 70:a=Math.min(this.data[8]|this.data[7]<<8,32);this.data_allocate(a);this.data_end=this.data_length;
469
- 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;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:this.atapi_check_condition_response(5,36);break;case 90:a=this.data[8]|this.data[7]<<8;b=this.data[2];y(b);42===b&&this.data_allocate(Math.min(30,a));this.data_end=this.data_length;this.status_reg=88;break;case 189:this.data_allocate(this.data[9]|this.data[8]<<
470
- 8);this.data_end=this.data_length;this.data[5]=1;this.status_reg=88;break;case 27:a=this.data[4]&3;y(this.data[1]&1);y(a);this.buffer&&2===a&&(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:this.atapi_check_condition_response(5,36);break;case 190:this.data_allocate(0);this.data_end=this.data_length;this.status_reg=80;break;default:y(this.data[0]),this.atapi_check_condition_response(5,36)}this.sector_count_reg=
471
- 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)}};X.prototype.atapi_check_condition_response=function(a,b){this.data_allocate(0);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};X.prototype.do_write=function(){this.status_reg=80;var a=this.data.subarray(0,this.data_length);
472
- 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)};X.prototype.atapi_read=function(a){var b=a[2]<<24|a[3]<<16|a[4]<<8|a[5];a=168===a[0]?a[6]<<24|a[7]<<16|a[8]<<8|a[9]:a[7]<<8|a[8];var c=(a>>>0)*this.sector_size;b*=this.sector_size;this.data_length=0;var d=this.lba_high_reg<<8&65280|this.lba_mid_reg&255;this.lba_mid_reg=this.lba_high_reg=0;65535===d&&d--;d>c&&(d=c);this.buffer?b>=this.buffer.byteLength?
473
- (wa(!1,this.name+": CD read: Outside of disk end="+y(b+c)+" size="+y(this.buffer.byteLength),32768),this.status_reg=255,this.push_irq()):0===c?(this.status_reg=80,this.data_pointer=0):(c=Math.min(c,this.buffer.byteLength-b),this.status_reg=208,this.report_read_start(),this.read_buffer(b,c,e=>{this.data_set(e);this.status_reg=88;this.sector_count_reg=this.sector_count_reg&-8|2;this.push_irq();this.data_end=d&=-4;this.data_end>this.data_length&&(this.data_end=this.data_length);this.lba_mid_reg=this.data_end&
474
- 255;this.lba_high_reg=this.data_end>>8&255;this.report_read_end(c)})):(this.status_reg=255,this.error_reg=65,this.push_irq())};X.prototype.atapi_read_dma=function(a){var b=a[2]<<24|a[3]<<16|a[4]<<8|a[5],c=168===a[0]?a[6]<<24|a[7]<<16|a[8]<<8|a[9]:a[7]<<8|a[8];c>>>=0;a=a[1];var d=c*this.sector_size,e=b*this.sector_size;va(this.name+": CD read DMA lba="+y(b)+" lbacount="+y(c)+" bytecount="+y(d)+" flags="+y(a),32768);e>=this.buffer.byteLength?(wa(!1,this.name+": CD read: Outside of disk end="+y(e+d)+
475
- " size="+y(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=>{this.report_read_end(d);this.status_reg=88;this.sector_count_reg=this.sector_count_reg&-8|2;this.data_set(f);this.do_atapi_dma()}))};X.prototype.do_atapi_dma=function(){if(0!==(this.channel.dma_status&1)&&0!==(this.status_reg&8)){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;
476
- e||(e=65536);this.cpu.write_blob(c.subarray(b,Math.min(b+e,this.data_length)),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()}};X.prototype.read_data=function(a){if(this.data_pointer<this.data_end){y(this.data_pointer);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&&
477
- this.read_end();return b}this.data_pointer+=a;return 0};X.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-
478
- 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:(a=41===this.current_command||196===this.current_command?Math.min(this.sectors_per_drq,(this.data_length-this.data_end)/512):1,this.ata_advance(this.current_command,a),this.data_end+=512*a,this.status_reg=88,this.push_irq())};X.prototype.write_data_port=function(a,b){this.data_pointer>=this.data_end?(y(a),y(this.data_end),y(this.data_pointer)):(1===b?this.data[this.data_pointer++]=
479
- 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),this.data_pointer===this.data_end&&this.write_end())};X.prototype.write_data_port8=function(a){this.write_data_port(a,1)};X.prototype.write_data_port16=function(a){this.write_data_port(a,2)};X.prototype.write_data_port32=function(a){this.write_data_port(a,4)};X.prototype.write_end=function(){160===this.current_command?this.atapi_handle():this.data_pointer>=this.data_length?
480
- this.do_write():(y(this.current_command),this.status_reg=88,this.data_end+=512,this.push_irq())};X.prototype.ata_advance=function(a,b){this.sector_count_reg-=b;36===a||41===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*
481
- 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+1&255,this.get_chs())};X.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?(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);
482
- 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,this.sectors_per_track));this.push_irq();this.report_read_end(e)}))};X.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?(this.status_reg=255,this.push_irq()):(this.status_reg=88,this.channel.dma_status|=1)};X.prototype.do_ata_read_sectors_dma=function(){var a=37===this.current_command,b=this.get_count(a);
483
- a=this.get_lba(a);var c=b*this.sector_size;a*=this.sector_size;this.report_read_start();this.read_buffer(a,c,d=>{var e=this.channel.prdt_addr,f=0;do{var g=this.cpu.read32s(e),h=this.cpu.read16(e+4),l=this.cpu.read8(e+7)&128;h||(h=65536);this.cpu.write_blob(d.subarray(f,f+h),g);f+=h;e+=8}while(!l);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()})};X.prototype.ata_write_sectors=function(a){var b=
484
- 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?(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)};X.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>this.buffer.byteLength?(this.status_reg=255,this.push_irq()):(this.status_reg=
485
- 88,this.channel.dma_status|=1)};X.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 g=this.cpu.read32s(d),h=this.cpu.read16(d+4),l=this.cpu.read8(d+7)&128;h||(h=65536);g=this.cpu.mem8.subarray(g,g+h);f.set(g,e);e+=h;d+=8}while(!l);this.buffer.set(c,f,()=>{this.ata_advance(this.current_command,b);this.status_reg=80;this.push_irq();
486
- this.channel.dma_status&=-2;this.current_command=-1});this.report_write(a)};X.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};X.prototype.get_lba28=function(){return this.lba_low_reg&255|this.lba_mid_reg<<8&65280|this.lba_high_reg<<16&16711680|(this.head&15)<<24};X.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>>
487
- 8<<24&4278190080)>>>0};X.prototype.get_lba=function(a){return a?this.get_lba48():this.is_lba?this.get_lba28():this.get_chs()};X.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};X.prototype.create_identify_packet=function(){const a=Math.min(16383,this.cylinder_count),b=(g,h,l,m)=>{h<<=1;var n=l<<1;l=h+n;g.fill(32,h,n);for(n=0;n<m.length&&h<l;n++)n&1?(g[h]=m.charCodeAt(n),h+=2):g[h+1]=m.charCodeAt(n)},c=this.is_atapi?
488
- 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&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,
489
- 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>>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,
490
- 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=512};X.prototype.data_allocate=function(a){this.data_allocate_noclear(a);this.data32.fill(0,0,a+3>>2)};X.prototype.data_allocate_noclear=function(a){this.data.length<a&&(this.data=new Uint8Array(a+
491
- 3&-4),this.data16=new Uint16Array(this.data.buffer),this.data32=new Int32Array(this.data.buffer));this.data_length=a;this.data_pointer=0};X.prototype.data_set=function(a){this.data_allocate_noclear(a.length);this.data.set(a)};X.prototype.report_read_start=function(){this.bus.send("ide-read-start")};X.prototype.report_read_end=function(a){this.bus.send("ide-read-end",[this.channel_nr,a,a/this.sector_size|0])};X.prototype.report_write=function(a){this.bus.send("ide-write-end",[this.channel_nr,a,a/this.sector_size|
492
- 0])};X.prototype.read_buffer=function(a,b,c){const d=this.last_io_id++,e=new AbortController;this.in_progress_io_ids.set(d,e);this.buffer.get(a,b,f=>{this.cancelled_io_ids.delete(d)?this.in_progress_io_ids.has(d):(this.in_progress_io_ids.delete(d),c(f))},{signal:e.signal})};X.prototype.cancel_io_operations=function(){for(const [a,b]of this.in_progress_io_ids)this.cancelled_io_ids.add(a),b.abort();this.in_progress_io_ids.clear()};X.prototype.get_state=function(){var a=[];a[0]=this.sector_count_reg;
493
- 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;a[22]=this.sectors_per_track;a[23]=this.status_reg;a[24]=this.write_dest;a[25]=this.current_command;a[26]=
494
- this.data_end;a[27]=this.current_atapi_command;a[28]=this.buffer;return a};X.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=a[17];this.lba_low_reg=a[18];this.sector_count=a[19];this.sector_size=a[20];this.sectors_per_drq=
495
- 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 bd(a,b,c,d=1500){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,
496
- 34,21,255*Math.random()|0,255*Math.random()|0,255*Math.random()|0]);this.bus.send("net"+this.id+"-mac",Ic(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 Lc(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,
497
- handlers:[()=>{},e=>{const f=this.virtio.queues[e];for(;f.has_request();){const g=f.pop_request(),h=new Uint8Array(g.length_readable);g.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[e].push_reply(g)}this.virtio.queues[e].flush_replies()},e=>{if(e===2*this.pairs)for(var f=this.virtio.queues[e];f.has_request();){const g=f.pop_request(),h=new Uint8Array(g.length_readable);g.get_next_blob(h);const l=J(["b","b"],
498
- h,{offset:0});switch(l[0]<<8|l[1]){case 1024:J(["h"],h,{offset:2});this.Send(e,g,new Uint8Array([0]));break;case 257:this.mac=h.subarray(2,8);this.Send(e,g,new Uint8Array([0]));this.bus.send("net"+this.id+"-mac",Ic(this.mac));break;default:this.Send(e,g,new Uint8Array([1]));return}}}]},isr_status:{initial_port:50944},device_specific:{initial_port:50688,struct:[0,1,2,3,4,5].map((e,f)=>({bytes:1,name:"mac_"+f,read:()=>this.mac[f],write:()=>{}})).concat([{bytes:2,name:"status",read:()=>this.status,write:()=>
499
- {}},{bytes:2,name:"max_pairs",read:()=>this.pairs,write:()=>{}},{bytes:2,name:"mtu",read:()=>d,write:()=>{}}])}});this.bus.register("net"+this.id+"-receive",e=>{this.bus.send("eth-receive-end",[e.length]);const f=new Uint8Array(12+e.byteLength);(new DataView(f.buffer,f.byteOffset,f.byteLength)).setInt16(10,1);f.set(e,12);e=this.virtio.queues[0];e.has_request()?(e=e.pop_request(),e.set_next_blob(f),this.virtio.queues[0].push_reply(e),this.virtio.queues[0].flush_replies()):console.log("No buffer to write into!")},
500
- this)}bd.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.id;a[2]=this.mac;return a};bd.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",Ic(this.mac)))};bd.prototype.reset=function(){this.virtio.reset()};bd.prototype.Send=function(a,b,c){b.set_next_blob(c);this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};bd.prototype.Ack=function(a,b){this.virtio.queues[a].push_reply(b);
501
- this.virtio.queues[a].flush_replies()};const cd=Uint32Array.from([655360,655360,720896,753664]),dd=Uint32Array.from([131072,65536,32768,32768]);function Y(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=this.screen_height=this.screen_width=0;this.layers=[];this.start_address_latched=this.start_address=0;this.crtc=new Uint8Array(25);
502
- 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=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=
503
- void 0===this.vga_memory_size||262144>this.vga_memory_size?262144:268435456<this.vga_memory_size?268435456:ja(this.vga_memory_size);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,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=
504
- 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=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=
505
- 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,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);
506
- 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,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,
507
- 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,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,
508
- this,this.port3D5_read,this.port3D5_read16);b.register_read(970,this,function(){return 0});b.register_read(986,this,this.port3DA_read);b.register_read(954,this,this.port3DA_read);this.dispi_enable_value=this.dispi_index=0;b.register_write(462,this,void 0,this.port1CE_write);b.register_read(462,this,void 0,this.port1CE_read);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=k(Uint8Array,
509
- 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,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);
510
- 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)}Y.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;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;
511
- 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;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]=
512
- 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;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;
513
- 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]=this.dac_mask;a[63]=this.character_map_select;a[64]=this.font_page_ab_enabled;return a};Y.prototype.set_state=function(a){this.vga_memory_size=a[0];this.cursor_address=a[1];this.cursor_scanline_start=
514
- 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=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];
515
- 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=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];
516
- 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=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=
517
- 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=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(),
518
- 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()};Y.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-=cd[b];if(0>a||a>=dd[b])return y(a>>>0),0;this.latch_dword=this.plane0[a];this.latch_dword|=this.plane1[a]<<8;this.latch_dword|=
519
- 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&=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&=
520
- -2):b&=3;return this.vga_memory[b<<16|a]};Y.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-=cd[c];0>a||a>=dd[c]?(y(a>>>0),y(b)):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)}};Y.prototype.vga_memory_write_graphical=function(a,b){var c=this.planar_mode&3,
521
- 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 g=this.apply_feed(b);g=this.apply_setreset(g,f);g=this.apply_logical(g,this.latch_dword);g=this.apply_bitmask(g,d);break;case 1:g=this.latch_dword;break;case 2:g=this.apply_expand(b);g=this.apply_logical(g,this.latch_dword);g=this.apply_bitmask(g,d);break;case 3:b=this.apply_rotate(b),d&=this.apply_feed(b),g=this.apply_bitmask(e,
522
- 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]=g>>0&255);b&2&&(this.plane1[a]=g>>8&255);b&4&&(this.plane2[a]=g>>16&255);b&8&&(this.plane3[a]=g>>24&255);a=this.vga_addr_to_pixel(a);this.partial_replot(a,a+7)};Y.prototype.apply_feed=function(a){return a|a<<8|a<<16|a<<24};Y.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};Y.prototype.apply_rotate=
523
- function(a){return(a|a<<8)>>>(this.planar_rotate_reg&7)&255};Y.prototype.apply_setreset=function(a,b){var c=this.apply_expand(this.planar_setreset);return(a|b&c)&(~b|c)};Y.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};Y.prototype.apply_bitmask=function(a,b){return b&a|~b&this.latch_dword};Y.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-
524
- 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,g=this.screen.FLAG_FONT_PAGE_B;let h=this.start_address<<1;for(let l=0;l<this.max_rows;l++){l===a&&(h=0);for(let m=0;m<this.max_cols;m++){const n=this.vga_memory[h],p=this.vga_memory[h|1],q=(c&&p&128?f:0)|(!this.font_page_ab_enabled||p&8?0:g);this.bus.send("screen-put-char",[l,m,n]);this.screen.put_char(l,m,n,q,this.vga256_palette[this.dac_mask&this.dac_map[p>>4&e]],this.vga256_palette[this.dac_mask&
525
- this.dac_map[p&d]]);h+=2}h+=b}};Y.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=a>>1,d=(e/c|0)+this.scan_line_to_screen_row(this.line_compare),c=e%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||
526
- e&8?0:this.screen.FLAG_FONT_PAGE_B);var g=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&this.dac_map[e&g]])}};Y.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/
527
- a|0)+this.scan_line_to_screen_row(this.line_compare),a=this.cursor_address%a);this.screen.update_cursor(b,a)};Y.prototype.complete_redraw=function(){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()};Y.prototype.complete_replot=function(){this.graphical_mode&&!this.svga_enabled&&(this.diff_plot_min=0,this.diff_plot_max=524288,this.complete_redraw())};Y.prototype.partial_redraw=function(a,b){a<this.diff_addr_min&&
528
- (this.diff_addr_min=a);b>this.diff_addr_max&&(this.diff_addr_max=b)};Y.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)};Y.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};Y.prototype.destroy=function(){};Y.prototype.vga_bytes_per_line=function(){var a=this.offset_register<<2;this.underline_location_register&
529
- 64?a<<=1:this.crtc_mode&64&&(a>>>=1);return a};Y.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};Y.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=
530
- 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};Y.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};Y.prototype.set_size_text=function(a,b){this.max_cols=a;this.max_rows=b;this.screen.set_size_text(a,b);this.bus.send("screen-set-size",[a,b,0])};Y.prototype.set_size_graphical=function(a,b,c,d,e){c=Math.max(c,
531
- 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=a;this.screen_height=b;this.virtual_width=c;this.virtual_height=d;if("undefined"!==typeof ImageData){const f=c*d,g=this.cpu.svga_allocate_dest_buffer(f)>>>0;this.dest_buffet_offset=g;this.image_data=new ImageData(new Uint8ClampedArray(this.cpu.wasm_memory.buffer,g,4*f),c,d);this.cpu.svga_mark_dirty()}this.screen.set_size_graphical(a,b,c,d);this.bus.send("screen-set-size",
532
- [a,b,e])}};Y.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=dd[0];const f=this.vga_bytes_per_line();this.set_size_graphical(a,b,c,f?Math.ceil(e/f):b,d);
533
- 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)}};Y.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>>>=
534
- 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 g=0;e<this.screen_width;e+=this.virtual_width,g++)this.layers.push({image_data:this.image_data,screen_x:e,screen_y:0,buffer_x:0,buffer_y:a+g,buffer_width:this.virtual_width,buffer_height:d});a=0;this.attribute_mode&32||(a=this.vga_addr_to_pixel(c)+
535
- b);e=-a;for(g=0;e<this.screen_width;e+=this.virtual_width,g++)this.layers.push({image_data:this.image_data,screen_x:e,screen_y:d,buffer_x:0,buffer_y:g,buffer_width:this.virtual_width,buffer_height:f})}};Y.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())};Y.prototype.update_cursor_scanline=function(){var a=this.max_scan_line&31;const b=Math.min(a,this.cursor_scanline_start&
536
- 31);a=Math.min(a,this.cursor_scanline_end&31);this.screen.update_cursor_scanline(b,a,!(this.cursor_scanline_start&32)&&b<a)};Y.prototype.port3C0_write=function(a){if(-1===this.attribute_controller_index)y(a),this.attribute_controller_index=a&31,y(this.attribute_controller_index),this.palette_source!==(a&32)&&(this.palette_source=a&32,this.update_layers());else{if(16>this.attribute_controller_index)y(this.attribute_controller_index),y(a),this.dac_map[this.attribute_controller_index]=a,this.attribute_mode&
537
- 64||this.complete_redraw();else switch(this.attribute_controller_index){case 16:y(a);if(this.attribute_mode!==a){var b=this.attribute_mode;this.attribute_mode=a;!this.svga_enabled||this.dispi_enable_value&1||(this.svga_enabled=!1,this.svga_bank_offset=0);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:y(a);
538
- this.color_plane_enable!==a&&(this.color_plane_enable=a,this.complete_redraw());break;case 19:y(a);this.horizontal_panning!==a&&(this.horizontal_panning=a&15,this.update_layers());break;case 20:y(a);this.color_select!==a&&(this.color_select=a,this.complete_redraw());break;default:y(this.attribute_controller_index),y(a)}this.attribute_controller_index=-1}};Y.prototype.port3C0_read=function(){return(this.attribute_controller_index|this.palette_source)&255};Y.prototype.port3C0_read16=function(){return this.port3C0_read()|
539
- this.port3C1_read()<<8&65280};Y.prototype.port3C1_read=function(){if(16>this.attribute_controller_index)return y(this.attribute_controller_index),y(this.dac_map[this.attribute_controller_index]),this.dac_map[this.attribute_controller_index]&255;switch(this.attribute_controller_index){case 16:return y(this.attribute_mode),this.attribute_mode;case 18:return y(this.color_plane_enable),this.color_plane_enable;case 19:return y(this.horizontal_panning),this.horizontal_panning;case 20:return y(this.color_select),
540
- this.color_select;default:y(this.attribute_controller_index)}return 255};Y.prototype.port3C2_write=function(a){y(a);this.miscellaneous_output_register=a};Y.prototype.port3C4_write=function(a){this.sequencer_index=a};Y.prototype.port3C4_read=function(){return this.sequencer_index};Y.prototype.port3C5_write=function(a){switch(this.sequencer_index){case 1:y(a);var b=this.clocking_mode;this.clocking_mode=a;(b^a)&32&&this.update_layers();this.set_font_bitmap(!1);break;case 2:y(a);b=this.plane_write_bm;
541
- this.plane_write_bm=a;this.graphical_mode||!(b&4)||this.plane_write_bm&4||this.set_font_bitmap(!0);break;case 3:y(a);b=this.character_map_select;this.character_map_select=a;this.graphical_mode||b===a||this.set_font_page();break;case 4:y(a);this.sequencer_memory_mode=a;break;default:y(this.sequencer_index),y(a)}};Y.prototype.port3C5_read=function(){y(this.sequencer_index);switch(this.sequencer_index){case 1:return this.clocking_mode;case 2:return this.plane_write_bm;case 3:return this.character_map_select;
542
- case 4:return this.sequencer_memory_mode;case 6:return 18}return 0};Y.prototype.port3C6_write=function(a){this.dac_mask!==a&&(this.dac_mask=a,this.complete_redraw())};Y.prototype.port3C6_read=function(){return this.dac_mask};Y.prototype.port3C7_write=function(a){y(a);this.dac_color_index_read=3*a;this.dac_state&=0};Y.prototype.port3C7_read=function(){return this.dac_state};Y.prototype.port3C8_write=function(a){this.dac_color_index_write=3*a;this.dac_state|=3};Y.prototype.port3C8_read=function(){return this.dac_color_index_write/
543
- 3&255};Y.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,y(b),y(d));this.vga256_palette[b]!==d&&(this.vga256_palette[b]=d,this.complete_redraw());this.dac_color_index_write++};Y.prototype.port3C9_read=function(){var a=this.vga256_palette[this.dac_color_index_read/3|0]>>8*(2-this.dac_color_index_read%
544
- 3)&255;this.dac_color_index_read++;return this.dispi_enable_value&32?a:a>>2};Y.prototype.port3CC_read=function(){return this.miscellaneous_output_register};Y.prototype.port3CE_write=function(a){this.graphics_index=a};Y.prototype.port3CE_read=function(){return this.graphics_index};Y.prototype.port3CF_write=function(a){switch(this.graphics_index){case 0:this.planar_setreset=a;y(a);break;case 1:this.planar_setreset_enable=a;y(a);break;case 2:this.color_compare=a;y(a);break;case 3:this.planar_rotate_reg=
545
- a;y(a);break;case 4:this.plane_read=a;y(a);break;case 5:var b=this.planar_mode;this.planar_mode=a;y(a);(b^a)&96&&this.complete_replot();break;case 6:y(a);this.miscellaneous_graphics_register!==a&&(this.miscellaneous_graphics_register=a,this.update_vga_size());break;case 7:this.color_dont_care=a;y(a);break;case 8:this.planar_bitmap=a;y(a);break;default:y(this.graphics_index),y(a)}};Y.prototype.port3CF_read=function(){y(this.graphics_index);switch(this.graphics_index){case 0:return this.planar_setreset;
546
- 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};Y.prototype.port3D4_write=function(a){this.index_crtc=a};Y.prototype.port3D4_write16=function(a){this.port3D4_write(a&255);this.port3D5_write(a>>8&255)};Y.prototype.port3D4_read=function(){return this.index_crtc};
547
- Y.prototype.port3D5_write=function(a){switch(this.index_crtc){case 1:y(a);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:y(a);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();
548
- 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:y(a);this.preset_row_scan=a;this.update_layers();break;case 9:y(a);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)&
549
- 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:y(a);this.cursor_scanline_start=a;this.update_cursor_scanline();break;case 11:y(a);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());y(a);y(this.start_address,4);break;case 13:(this.start_address&
550
- 255)!==a&&(this.start_address=this.start_address&65280|a,this.update_layers(),~this.crtc_mode&3&&this.complete_replot());y(a);y(this.start_address,4);break;case 14:y(a);this.cursor_address=this.cursor_address&255|a<<8;this.update_cursor();break;case 15:y(a);this.cursor_address=this.cursor_address&65280|a;this.update_cursor();break;case 18:y(a);(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:y(a);
551
- this.offset_register!==a&&(this.offset_register=a,this.update_vga_size(),~this.crtc_mode&3&&this.complete_replot());break;case 20:y(a);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:y(a);(this.vertical_blank_start&255)!==a&&(this.vertical_blank_start=this.vertical_blank_start&768|a,this.update_vga_size());break;case 23:y(a);this.crtc_mode!==a&&(b=this.crtc_mode,this.crtc_mode=
552
- a,this.update_vga_size(),(b^a)&67&&this.complete_replot());break;case 24:y(a);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),y(this.index_crtc),y(a)}};Y.prototype.port3D5_write16=function(a){y(a,4);this.port3D5_write(a&255)};Y.prototype.port3D5_read=function(){y(this.index_crtc);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>>
553
- 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&255;case 19:return this.offset_register;case 20:return this.underline_location_register;
554
- 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};Y.prototype.port3D5_read16=function(){return this.port3D5_read()};Y.prototype.port3DA_read=function(){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};Y.prototype.port1CE_read=
555
- function(){return this.dispi_index};Y.prototype.port1CE_write=function(a){this.dispi_index=a};Y.prototype.port1CF_write=function(a){y(this.dispi_index);y(a);const b=this.svga_enabled;switch(this.dispi_index){case 0:45248<=a&&45253>=a?this.svga_version=a:y(a);break;case 1:this.svga_width=a;2560<this.svga_width&&(this.svga_width=2560);break;case 2:this.svga_height=a;1600<this.svga_height&&(this.svga_height=1600);break;case 3:this.svga_bpp=a;break;case 4:this.dispi_enable_value=a;!(a&1)&&this.svga_enabled&&
556
- this.cpu.flags[0]&131072||(this.svga_enabled=1===(a&1))&&0===(a&128)&&this.svga_memory.fill(0);break;case 5:y(a<<16);this.svga_bank_offset=a<<16;break;case 8:y(a);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:y(a*this.svga_width);y(a);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:y(this.dispi_index)}!this.svga_enabled||
557
- this.svga_width&&this.svga_height||(this.svga_enabled=!1);this.svga_enabled&&4===this.dispi_index&&(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));b&&!this.svga_enabled&&(this.graphical_mode=a=0!==(this.attribute_mode&1),this.screen.set_mode(a),this.update_vga_size(),this.set_font_bitmap(!1),this.complete_redraw());
558
- this.svga_enabled||(this.svga_bank_offset=0);this.update_layers()};Y.prototype.port1CF_read=function(){y(this.dispi_index);return this.svga_register_read(this.dispi_index)};Y.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>>>
559
- 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:y(this.dispi_index)}return 255};Y.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 g=a>>>c;if(d){var h=a/this.virtual_width|0,l=a-this.virtual_width*h;switch(d){case 1:g=
560
- (h&1)<<13;h>>>=1;break;case 2:g=(h&1)<<14;h>>>=1;break;case 3:g=(h&3)<<13,h>>>=2}g|=(h*this.virtual_width+l>>>c)+this.start_address}h=this.plane0[g];l=this.plane1[g];var m=this.plane2[g],n=this.plane3[g];g=new Uint8Array(8);switch(e){case 0:h<<=0;l<<=1;m<<=2;n<<=3;for(var p=7;0<=p;p--)g[7-p]=h>>p&1|l>>p&2|m>>p&4|n>>p&8;break;case 32:g[0]=h>>6&3|m>>4&12;g[1]=h>>4&3|m>>2&12;g[2]=h>>2&3|m>>0&12;g[3]=h>>0&3|m<<2&12;g[4]=l>>6&3|n>>4&12;g[5]=l>>4&3|n>>2&12;g[6]=l>>2&3|n>>0&12;g[7]=l>>0&3|n<<2&12;break;
561
- case 64:case 96:g[0]=h>>4&15,g[1]=h>>0&15,g[2]=l>>4&15,g[3]=l>>0&15,g[4]=m>>4&15,g[5]=m>>0&15,g[6]=n>>4&15,g[7]=n>>0&15}if(f)for(h=p=0;4>p;p++,a++,h+=2)this.pixel_buffer[a]=g[h]<<4|g[h+1];else for(p=0;8>p;p++,a++)this.pixel_buffer[a]=g[p]}};Y.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=255,e=0;this.attribute_mode&128&&(d&=207,e|=
562
- 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};Y.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,this.dest_buffet_offset,
563
- 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]=c&65280|c<<16|c>>16|4278190080}}else this.cpu.svga_fill_pixel_buffer(this.svga_bpp,
564
- 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-a}]))}else this.vga_replot(),this.vga_redraw(),this.screen.update_buffer(this.layers);
565
- this.reset_diffs()}this.update_vertical_retrace()};Y.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)}};Y.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)>>3,c=this.character_map_select&3|(this.character_map_select&16)>>2;this.font_page_ab_enabled=
566
- b!==c;this.screen.set_font_page(a[b],a[c]);this.complete_redraw()};const ed="SWAP_IN SWAP_OUT MAJFLT MINFLT MEMFREE MEMTOT AVAIL CACHES HTLB_PGALLOC HTLB_PGFAIL".split(" ");function fd(a,b){this.bus=b;this.zeroed=this.fp_cmd=this.actual=this.num_pages=0;this.virtio=new Lc(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},{size_supported:32,notify_offset:0},{size_supported:2,notify_offset:1},{size_supported:64,
567
- notify_offset:2}],features:[1,3,32],on_driver_ok:()=>{}},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];if(d.has_request()){d=d.pop_request();const e=new Uint8Array(d.length_readable);d.get_next_blob(e);
568
- let f={};for(let g=0;g<d.length_readable;g+=10){let [h,l]=J(["h","d"],e,{offset:g});f[ed[h]]=l}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]=J(["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),
569
- e=0;e<f.write_buffers.length;++e){let g=f.write_buffers[e];this.zeroed+=g.len;this.virtio.cpu.zero_memory(g.addr_low,g.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:()=>{}},{bytes:4,name:"free_page_hint_cmd_id",read:()=>this.fp_cmd,write:()=>{}}]}})}fd.prototype.Inflate=function(a){this.num_pages+=
570
- a;this.virtio.notify_config_changes()};fd.prototype.Deflate=function(a){this.num_pages-=a;this.virtio.notify_config_changes()};fd.prototype.Cleanup=function(a){this.fp_cmd=2;this.free_cb=a;this.zeroed=0;this.virtio.notify_config_changes()};fd.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.num_pages;a[2]=this.actual;return a};fd.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.num_pages=a[1];this.actual=a[2]};fd.prototype.GetStats=function(a){this.stats_cb=a;for(a=
571
- 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()};fd.prototype.Reset=function(){};function gd(a,b,c,d){var e=new Uint8Array(b);const f=new Uint16Array(b);var g=new Uint32Array(b),h=e[497]||4,l=f[255];if(43605!==l)y(l);else if(l=f[257]|f[258]<<16,1400005704!==l)y(l);else{l=f[259];var m=e[529],n=f[283],p=g[139],q=g[140],r=e[565],x=518<=l?g[142]:255,C=g[146],t=g[147],A=g[150],M=g[151],v=g[152];y(l);y(m);y(n);y(g[133]);
572
- y(p);y(q);y(r);y(x);y(C);y(t);y(M);y(A);y(v);e[528]=255;e[529]=m&-97|128;f[274]=56832;f[253]=65535;y(56832);d+="\x00";y(581632);g[138]=581632;for(e=0;e<d.length;e++)a[581632+e]=d.charCodeAt(e);h=512*(h+1);y(h);d=new Uint8Array(b,0,h);b=new Uint8Array(b,h);e=h=0;c&&(h=67108864,e=c.byteLength,a.set(new Uint8Array(c),h));g[134]=h;g[135]=e;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++]=
573
- 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;g=a[c]=0;for(b=0;b<a.length;b++)g+=a[b];a[c]=-g;return{name:"genroms/kernel.bin",data:a}}}function R(a,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=k(Uint32Array,b,812,1);this.mem8=new Uint8Array(0);this.mem32s=new Int32Array(this.mem8.buffer);
574
- this.segment_is_null=k(Uint8Array,b,724,8);this.segment_offsets=k(Int32Array,b,736,8);this.segment_limits=k(Uint32Array,b,768,8);this.segment_access_bytes=k(Uint8Array,b,512,8);this.protected_mode=k(Int32Array,b,800,1);this.idtr_size=k(Int32Array,b,564,1);this.idtr_offset=k(Int32Array,b,568,1);this.gdtr_size=k(Int32Array,b,572,1);this.gdtr_offset=k(Int32Array,b,576,1);this.tss_size_32=k(Int32Array,b,1128,1);this.page_fault=k(Uint32Array,b,540,8);this.cr=k(Int32Array,b,580,8);this.cpl=k(Uint8Array,
575
- b,612,1);this.is_32=k(Int32Array,b,804,1);this.stack_size_32=k(Int32Array,b,808,1);this.in_hlt=k(Uint8Array,b,616,1);this.last_virt_eip=k(Int32Array,b,620,1);this.eip_phys=k(Int32Array,b,624,1);this.sysenter_cs=k(Int32Array,b,636,1);this.sysenter_esp=k(Int32Array,b,640,1);this.sysenter_eip=k(Int32Array,b,644,1);this.prefixes=k(Int32Array,b,648,1);this.flags=k(Int32Array,b,120,1);this.flags_changed=k(Int32Array,b,100,1);this.last_op_size=k(Int32Array,b,96,1);this.last_op1=k(Int32Array,b,104,1);this.last_result=
576
- k(Int32Array,b,112,1);this.current_tsc=k(Uint32Array,b,960,2);this.devices={};this.instruction_pointer=k(Int32Array,b,556,1);this.previous_ip=k(Int32Array,b,560,1);this.apic_enabled=k(Uint8Array,b,548,1);this.acpi_enabled=k(Uint8Array,b,552,1);this.memory_map_read8=[];this.memory_map_write8=[];this.memory_map_read32=[];this.memory_map_write32=[];this.bios={main:null,vga:null};this.instruction_counter=k(Uint32Array,b,664,1);this.reg32=k(Int32Array,b,64,8);this.fpu_st=k(Int32Array,b,1152,32);this.fpu_stack_empty=
577
- k(Uint8Array,b,816,1);this.fpu_stack_empty[0]=255;this.fpu_stack_ptr=k(Uint8Array,b,1032,1);this.fpu_stack_ptr[0]=0;this.fpu_control_word=k(Uint16Array,b,1036,1);this.fpu_control_word[0]=895;this.fpu_status_word=k(Uint16Array,b,1040,1);this.fpu_status_word[0]=0;this.fpu_ip=k(Int32Array,b,1048,1);this.fpu_ip[0]=0;this.fpu_ip_selector=k(Int32Array,b,1052,1);this.fpu_ip_selector[0]=0;this.fpu_opcode=k(Int32Array,b,1044,1);this.fpu_opcode[0]=0;this.fpu_dp=k(Int32Array,b,1056,1);this.fpu_dp[0]=0;this.fpu_dp_selector=
578
- k(Int32Array,b,1060,1);this.fpu_dp_selector[0]=0;this.reg_xmm32s=k(Int32Array,b,832,32);this.mxcsr=k(Int32Array,b,824,1);this.sreg=k(Uint16Array,b,668,8);this.dreg=k(Int32Array,b,684,8);this.reg_pdpte=k(Int32Array,b,968,8);this.svga_dirty_bitmap_min_offset=k(Uint32Array,b,716,1);this.svga_dirty_bitmap_max_offset=k(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)}R.prototype.mmap_read8=function(a){return this.memory_map_read8[a>>>
579
- 17](a)};R.prototype.mmap_write8=function(a,b){this.memory_map_write8[a>>>17](a,b)};R.prototype.mmap_write16=function(a,b){var c=this.memory_map_write8[a>>>17];c(a,b&255);c(a+1|0,b>>8)};R.prototype.mmap_read32=function(a){return this.memory_map_read32[a>>>17](a)};R.prototype.mmap_write32=function(a,b){this.memory_map_write32[a>>>17](a,b)};R.prototype.mmap_write64=function(a,b,c){var d=this.memory_map_write32[a>>>17];d(a,b);d(a+4,c)};R.prototype.mmap_write128=function(a,b,c,d,e){var f=this.memory_map_write32[a>>>
580
- 17];f(a,b);f(a+4,c);f(a+8,d);f(a+12,e)};R.prototype.write_blob=function(a,b){a.length&&(this.in_mapped_range(b),this.in_mapped_range(b+a.length-1),this.jit_dirty_cache(b,b+a.length),this.mem8.set(a,b))};R.prototype.read_blob=function(a,b){b&&(this.in_mapped_range(a),this.in_mapped_range(a+b-1));return this.mem8.subarray(a,a+b)};R.prototype.clear_opstats=function(){(new Uint8Array(this.wasm_memory.buffer,32768,131072)).fill(0);this.wm.exports.profiler_init()};R.prototype.create_jit_imports=function(){const a=
581
- 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};R.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=
582
- 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");this.get_real_eip=b("get_real_eip");this.clear_tlb=
583
- 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.device_raise_irq=b("device_raise_irq");this.device_lower_irq=b("device_lower_irq");this.apic_timer=b("apic_timer");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=
584
- 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.get_apic_addr=b("get_apic_addr");this.get_ioapic_addr=b("get_ioapic_addr");this.zstd_create_ctx=
585
- b("zstd_create_ctx");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")};R.prototype.jit_force_generate=function(a){this.jit_force_generate_unsafe&&this.jit_force_generate_unsafe(a)};R.prototype.jit_clear_func=function(a){this.wm.wasm_table.set(a+1024,null)};R.prototype.jit_clear_all_funcs=function(){const a=this.wm.wasm_table;for(let b=0;900>b;b++)a.set(1024+b,null)};R.prototype.get_state=function(){var a=
586
- [];a[0]=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];
587
- a[24]=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.get_state_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]=
588
- this.devices.ps2;a[54]=this.devices.uart0;a[55]=this.devices.fdc;this.devices.ide.secondary?a[85]=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.get_state_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];
589
- 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]=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;a[86]=this.last_result;a[87]=this.fpu_status_word;a[88]=this.mxcsr;return a};R.prototype.get_state_pic=function(){const a=
590
- 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];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};R.prototype.get_state_apic=function(){return new Uint8Array(this.wasm_memory.buffer,
591
- this.get_apic_addr(),184)};R.prototype.get_state_ioapic=function(){return new Uint8Array(this.wasm_memory.buffer,this.get_ioapic_addr(),208)};R.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]),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,
592
- 8)),this.segment_access_bytes.set(a[1].subarray(8,16)));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];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];
593
- 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&&this.devices.virtio_9p.set_state(a[45]);a[46]&&this.set_state_apic(a[46]);this.devices.rtc&&this.devices.rtc.set_state(a[47]);this.devices.dma&&this.devices.dma.set_state(a[49]);
594
- 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],[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 $c(this,this.devices.ide.bus,b);this.devices.cdrom=
595
- 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]);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&&
596
- 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];a[63]&&this.set_state_ioapic(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]=
597
- a[72];this.fpu_dp[0]=a[73];this.fpu_dp_selector[0]=a[74];this.fpu_opcode[0]=a[75];void 0!==a[86]&&(this.last_result=a[86]);void 0!==a[87]&&(this.fpu_status_word=a[87]);void 0!==a[88]&&(this.mxcsr=a[88]);b=new na(a[78].buffer);this.unpack_memory(b,a[77]);this.update_state_flags();this.full_clear_tlb();this.jit_clear_cache()};R.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(),
598
- 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]};R.prototype.set_state_apic=function(a){if(a instanceof Array){const b=new Int32Array(this.wasm_memory.buffer,this.get_apic_addr(),46);b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];b[8]=a[6];b[9]=a[7];b[10]=a[8];b[11]=a[9];b[12]=
599
- a[10];b[13]=a[11];b[14]=a[12];b[15]=a[13];b.set(a[15],16);b.set(a[15],24);b.set(a[16],32);b[40]=a[17];b[41]=a[18];b[42]=a[19];b[43]=a[20];b[44]=a[21];b[45]=a[22]||65536}else(new Uint8Array(this.wasm_memory.buffer,this.get_apic_addr(),184)).set(a)};R.prototype.set_state_ioapic=function(a){if(a instanceof Array){const b=new Int32Array(this.wasm_memory.buffer,this.get_ioapic_addr(),52);b.set(a[0],0);b.set(a[1],24);b[48]=a[2];b[49]=a[3];b[50]=a[4];b[51]=a[5]}else(new Uint8Array(this.wasm_memory.buffer,
600
- this.get_ioapic_addr(),208)).set(a)};R.prototype.pack_memory=function(){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 na(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}};R.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<<
601
- 12;e=b.subarray(e,e+4096);this.mem8.set(e,f<<12);d++}};R.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()};R.prototype.reset_memory=function(){this.mem8.fill(0)};R.prototype.create_memory=function(a,b){a<b?a=b:0>(a|0)&&(a=Math.pow(2,31)-131072);
602
- a=(a-1|131071)+1|0;console.assert(0===this.memory_size[0],"Expected uninitialised memory");this.memory_size[0]=a;b=this.allocate_memory(a);this.mem8=k(Uint8Array,this.wasm_memory,b,a);this.mem32s=k(Uint32Array,this.wasm_memory,b,a>>2)};R.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 Da(this);this.io=
603
- c;this.bios.main=a.bios;this.bios.vga=a.vga_bios;this.load_bios();if(a.bzimage){const e=gd(this.mem8,a.bzimage,a.initrd,a.cmdline||"");e&&this.option_roms.push(e)}c.register_read(179,this,function(){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(){return this.fw_pointer<this.fw_value.length?this.fw_value[this.fw_pointer++]:0});c.register_write(1296,this,void 0,function(e){function f(l){return new Uint8Array(Int32Array.of(l).buffer)}
604
- function g(l){return l>>8|l<<8&65280}function h(l){return l<<24|l<<8&16711680|l>>8&65280|l>>>24}va("bios config port, index="+y(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 l=new Uint8Array(e.buffer);e[0]=h(this.option_roms.length);
605
- for(let m=0;m<this.option_roms.length;m++){const {name:n,data:p}=this.option_roms[m],q=4+64*m;e[q+0>>2]=h(p.length);e[q+4>>2]=g(49152+m);for(let r=0;r<n.length;r++)l[q+8+r]=n.charCodeAt(r)}this.fw_value=l}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:(va("Warning: Unimplemented fw index: "+y(e)),this.fw_value=f(0))});this.devices={};a.load_devices&&(this.devices.pci=new Gc(this),this.acpi_enabled[0]&&(this.devices.acpi=
606
- new Ec(this)),this.devices.rtc=new hb(this),this.fill_cmos(this.devices.rtc,a),this.devices.dma=new B(this),this.devices.vga=new Y(this,b,a.screen,a.vga_memory_size||8388608),this.devices.ps2=new Mc(this,b),this.devices.uart0=new Fc(this,1016,b),a.uart1&&(this.devices.uart1=new Fc(this,760,b)),a.uart2&&(this.devices.uart2=new Fc(this,1E3,b)),a.uart3&&(this.devices.uart3=new Fc(this,744,b)),this.devices.fdc=new W(this,a.fda,a.fdb),c=[[void 0,void 0],[void 0,void 0]],a.hda&&(c[0][0]={buffer:a.hda},
607
- c[0][1]={buffer:a.hdb}),c[1][0]={is_cdrom:!0,buffer:a.cdrom},this.devices.ide=new $c(this,b,c),this.devices.cdrom=this.devices.ide.secondary.master,this.devices.pit=new ib(this,b),"ne2k"===a.net_device.type?this.devices.net=new Jc(this,b,a.preserve_mac_from_state_image,a.mac_address_translation):"virtio"===a.net_device.type&&(this.devices.virtio_net=new bd(this,b,a.preserve_mac_from_state_image,a.net_device.mtu)),a.fs9p?this.devices.virtio_9p=new hd(a.fs9p,this,b):a.handle9p?this.devices.virtio_9p=
608
- new id(a.handle9p,this):a.proxy9p&&(this.devices.virtio_9p=new jd(a.proxy9p,this)),a.virtio_console&&(this.devices.virtio_console=new Kc(this,b)),a.virtio_balloon&&(this.devices.virtio_balloon=new fd(this,b)),this.devices.sb16=new D(this,b));a.multiboot&&(a=this.load_multiboot_option_rom(a.multiboot,a.initrd,a.cmdline))&&(this.bios.main?this.option_roms.push(a):this.reg32[0]=this.io.port_read32(244));this.debug_init()};R.prototype.load_multiboot=function(a){this.load_multiboot_option_rom(a,void 0,
609
- "")&&(this.reg32[0]=this.io.port_read32(244))};R.prototype.load_multiboot_option_rom=function(a,b,c){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)continue}else continue;va("Multiboot magic found, flags: "+y(f>>>0,8),2);var g=this;this.io.register_read(244,this,function(){return 0},function(){return 0},function(){var n,p=31860;
610
- let q=0;if(c){q|=4;g.write32(31760,p);c+="\x00";var r=(new TextEncoder).encode(c);g.write_blob(r,p);p+=r.length}if(f&2){q|=64;r=0;g.write32(31788,0);g.write32(31792,p);var x=0;var C=!1;for(n=0;4294967296>n;n+=131072)C&&void 0!==g.memory_map_read8[n>>>17]?(g.write32(p,20),g.write32(p+4,x),g.write32(p+8,0),g.write32(p+12,n-x),g.write32(p+16,0),g.write32(p+20,1),p+=24,r+=24,C=!1):C||void 0!==g.memory_map_read8[n>>>17]||(x=n,C=!0);g.write32(31788,r)}x=r=0;if(f&65536){n=d[e+12>>2];r=d[e+16>>2];var t=d[e+
611
- 20>>2];x=d[e+24>>2];C=d[e+28>>2];y(n,8);y(r,8);y(t,8);y(x,8);y(C,8);n=new Uint8Array(a,e-(n-r),0===t?void 0:t-r);g.write_blob(n,r);r=C|0;x=Math.max(t,x)}else if(1179403647===d[0]){C=new DataView(a);const [A,M]=Uc(C,Rc);console.assert(52===M);console.assert(1179403647===A.magic,"Bad magic");console.assert(1===A.class,"Unimplemented: 64 bit elf");console.assert(1===A.data,"Unimplemented: big endian");console.assert(1===A.version0,"Bad version0");console.assert(2===A.type,"Unimplemented type");console.assert(1===
612
- A.version1,"Bad version1");console.assert(52===A.ehsize,"Bad header size");console.assert(32===A.phentsize,"Bad program header size");console.assert(40===A.shentsize,"Bad section header size");[r]=Vc(new DataView(C.buffer,C.byteOffset+A.phoff,A.phentsize*A.phnum),Sc,A.phnum);Vc(new DataView(C.buffer,C.byteOffset+A.shoff,A.shentsize*A.shnum),Tc,A.shnum);C=A;n=r;r=C.entry;for(t of n)0!==t.type&&(1===t.type?t.paddr+t.memsz<g.memory_size[0]?(t.filesz&&(n=new Uint8Array(a,t.offset,t.filesz),g.write_blob(n,
613
- t.paddr)),x=Math.max(x,t.paddr+t.memsz),r===C.entry&&t.vaddr<=r&&t.vaddr+t.memsz>r&&(r=r-t.vaddr+t.paddr)):y(t.paddr):2===t.type||3===t.type||4===t.type||6===t.type||7===t.type||1685382480===t.type||1685382481===t.type||1685382482===t.type||1685382483===t.type||y(t.type))}b&&(q|=8,g.write32(31764,1),g.write32(31768,p),t=x,0!==(t&4095)&&(t=(t&-4096)+4096),x=t+b.byteLength,g.write32(p,t),g.write32(p+4,x),g.write32(p+8,0),g.write32(p+12,0),g.write_blob(new Uint8Array(b),t));g.write32(31744,q);g.reg32[3]=
614
- 31744;g.cr[0]=1;g.protected_mode[0]=1;g.flags[0]=2;g.is_32[0]=1;g.stack_size_32[0]=1;for(p=0;6>p;p++)g.segment_is_null[p]=0,g.segment_offsets[p]=0,g.segment_limits[p]=4294967295,g.sreg[p]=45058;g.instruction_pointer[0]=g.get_seg_cs()+r|0;g.update_state_flags();g.dump_state();g.dump_regs_short();return 732803074});this.io.register_write_consecutive(244,this,function(n){console.log("Test exited with code "+y(n,2));throw"HALT";},function(){},function(){},function(){});for(let n=0;15>=n;n++){function p(q){y(n);
615
- y(q,2);q?this.device_raise_irq(n):this.device_lower_irq(n)}this.io.register_write(8192+n,this,p,p,p)}const l=new Uint8Array(512);(new Uint16Array(l.buffer))[0]=43605;l[2]=1;var h=3;l[h++]=102;l[h++]=229;l[h++]=244;let m=l[h]=0;for(let n=0;n<l.length;n++)m+=l[n];l[h]=-m;return{name:"genroms/multiboot.bin",data:l}}};R.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]&&
616
- (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,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)};R.prototype.load_bios=function(){var a=this.bios.main,b=this.bios.vga;if(a){var c=
617
- new Uint8Array(a);this.write_blob(c,1048576-a.byteLength);if(b){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(){})}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))}};R.prototype.codegen_finalize=function(a,b,c,d,e){const f=new Uint8Array(this.wasm_memory.buffer,d>>>0,e>>>0);WebAssembly.instantiate(f,
618
- {e:this.jit_imports}).then(g=>{this.wm.wasm_table.set(a+1024,g.instance.exports.f);this.codegen_finalize_finished(a,b,c);this.test_hook_did_finalize_wasm&&this.test_hook_did_finalize_wasm(f)})};R.prototype.log_uncompiled_code=function(){};R.prototype.dump_function_code=function(){};R.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.apic_timer(b));return Math.min(c,d,e,f)};R.prototype.debug_init=
619
- function(){};R.prototype.dump_stack=function(){};R.prototype.debug_get_state=function(){};R.prototype.dump_state=function(){};R.prototype.get_regs_short=function(){};R.prototype.dump_regs_short=function(){};R.prototype.dump_gdt_ldt=function(){};R.prototype.dump_idt=function(){};R.prototype.dump_page_structures=function(){if(this.cr[4]&32)for(var a=0;4>a;a++){var b=this.read32s(this.cr[3]+8*a);b&1&&this.dump_page_directory(b&4294963200,!0,a<<30)}else this.dump_page_directory(this.cr[3],!1,0)};R.prototype.dump_page_directory=
620
- function(){};R.prototype.get_memory_dump=function(){};R.prototype.memory_hex_dump=function(){};R.prototype.used_memory_dump=function(){};R.prototype.debug_interrupt=function(){};R.prototype.debug_dump_code=function(){};R.prototype.dump_wasm=function(){};function Lc(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&
621
- 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);for(var c of b.common.features)this.device_feature[c>>>5]|=1<<(c&31),this.driver_feature[c>>>5]|=1<<(c&31);b.common.features.includes(32);this.features_ok=!0;this.device_status=
622
- 0;this.config_has_changed=!1;this.config_generation=0;this.queues=[];for(const d of b.common.queues)this.queues.push(new Z(a,this,d));this.queue_select=0;this.queue_selected=this.queues[0];this.isr_status=0;c=[];c.push(this.create_common_capability(b.common));c.push(this.create_notification_capability(b.notification));c.push(this.create_isr_capability(b.isr_status));b.device_specific&&c.push(this.create_device_specific_capability(b.device_specific));this.init_capabilities(c);a.devices.pci.register_device(this);
623
- this.reset()}Lc.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=b}},{bytes:4,name:"driver_feature",
624
- 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:()=>65535,write:()=>{}},{bytes:2,name:"num_queues",read:()=>this.queues.length,write:()=>{}},{bytes:1,name:"device_status",read:()=>this.device_status,write:b=>{0===b&&this.reset();b&~this.device_status&
625
- 4&&this.device_status&64&&this.notify_config_changes();this.features_ok||(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=>
626
- {this.queue_selected&&(b&b-1&&(b=1<<da(b-1)+1),b>this.queue_selected.size_supported&&(b=this.queue_selected.size_supported),this.queue_selected.set_size(b))}},{bytes:2,name:"queue_msix_vector",read:()=>65535,write:()=>{}},{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()}},{bytes:2,name:"queue_notify_off",read:()=>this.queue_selected?this.queue_selected.notify_offset:
627
- 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:()=>{}},{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:()=>{}},{bytes:4,name:"queue_used (low dword)",
628
- 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:()=>{}}]}};Lc.prototype.create_notification_capability=function(a){const b=[];let c;c=a.single_handler?0: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&
629
- 255,c>>24]),struct:b}};Lc.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:()=>{}}]}};Lc.prototype.create_device_specific_capability=function(a){return{type:4,bar:3,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:a.struct}};Lc.prototype.init_capabilities=function(a){let b=this.pci_space[52]=64;
630
- var c=b;for(const e of a){a=16+e.extra.length;c=b;b=c+a;var d=e.struct.reduce((f,g)=>f+g.bytes,0);d+=e.offset;d=16>d?16:1<<da(d-1)+1;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>>>24;this.pci_space[c+
631
- 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,g]of e.extra.entries())this.pci_space[c+16+f]=g;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 g=f.read;a=f.write;if(!e.use_mmio){d=function(m){return g(m&-2)>>((m&1)<<3)&255};const h=function(m){return g(m&-4)>>((m&3)<<3)&255},
632
- l=function(m){return g(m)};switch(f.bytes){case 4:this.cpu.io.register_read(c,this,h,void 0,g);this.cpu.io.register_read(c+1,this,h);this.cpu.io.register_read(c+2,this,h);this.cpu.io.register_read(c+3,this,h);this.cpu.io.register_write(c,this,void 0,void 0,a);break;case 2:this.cpu.io.register_read(c,this,d,g,l);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,g),this.cpu.io.register_write(c,this,a)}}c+=f.bytes}}this.pci_space[b]=
633
- 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+18]=0;this.pci_space[b+19]=0};Lc.prototype.get_state=function(){let a=[];a[0]=this.device_feature_select;
634
- 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)};Lc.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=
635
- 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};Lc.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];for(const a of this.queues)a.reset();this.config_has_changed=!1;this.config_generation=0;this.lower_irq()};
636
- Lc.prototype.notify_config_changes=function(){this.config_has_changed=!0;this.device_status&4&&this.raise_irq(2)};Lc.prototype.update_config_generation=function(){this.config_has_changed&&(this.config_generation++,this.config_generation&=255,this.config_has_changed=!1)};Lc.prototype.is_feature_negotiated=function(a){return 0<(this.driver_feature[a>>>5]&1<<(a&31))};Lc.prototype.needs_reset=function(){this.device_status|=64;this.device_status&4&&this.notify_config_changes()};Lc.prototype.raise_irq=
637
- function(a){y(a);this.isr_status|=a;this.pci.raise_irq(this.pci_id)};Lc.prototype.lower_irq=function(){this.isr_status=0;this.pci.lower_irq(this.pci_id)};function Z(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()}Z.prototype.get_state=function(){const a=[];a[0]=this.size;a[1]=this.size_supported;
638
- 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};Z.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]};Z.prototype.reset=function(){this.enabled=!1;this.num_staged_replies=
639
- this.used_addr=this.avail_last_idx=this.avail_addr=this.desc_addr=0;this.set_size(this.size_supported)};Z.prototype.is_configured=function(){return this.desc_addr&&this.avail_addr&&this.used_addr};Z.prototype.enable=function(){this.is_configured();this.enabled=!0};Z.prototype.set_size=function(a){this.size=a;this.mask=a-1};Z.prototype.count_requests=function(){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()-
640
- this.avail_last_idx&65535};Z.prototype.has_request=function(){return 0!==this.count_requests()};Z.prototype.pop_request=function(){this.has_request();var a=this.avail_get_entry(this.avail_last_idx);a=new kd(this,a);this.avail_last_idx=this.avail_last_idx+1&65535;return a};Z.prototype.push_reply=function(a){const b=this.used_get_idx()+this.num_staged_replies&this.mask;this.used_set_entry(b,a.head_idx,a.length_written);this.num_staged_replies++};Z.prototype.flush_replies=function(){if(0!==this.num_staged_replies){var a=
641
- 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)}};Z.prototype.notify_me_after=function(a){a=this.avail_get_idx()+a&65535;this.used_set_avail_event(a)};Z.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+
642
- 16*b+12),next:this.cpu.read16(a+16*b+14)}};Z.prototype.avail_get_flags=function(){return this.cpu.read16(this.avail_addr)};Z.prototype.avail_get_idx=function(){return this.cpu.read16(this.avail_addr+2)};Z.prototype.avail_get_entry=function(a){return this.cpu.read16(this.avail_addr+4+2*(a&this.mask))};Z.prototype.avail_get_used_event=function(){return this.cpu.read16(this.avail_addr+4+2*this.size)};Z.prototype.used_get_flags=function(){return this.cpu.read16(this.used_addr)};Z.prototype.used_set_flags=
643
- function(a){this.cpu.write16(this.used_addr,a)};Z.prototype.used_get_idx=function(){return this.cpu.read16(this.used_addr+2)};Z.prototype.used_set_idx=function(a){this.cpu.write16(this.used_addr+2,a)};Z.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)};Z.prototype.used_set_avail_event=function(a){this.cpu.write16(this.used_addr+4+8*this.size,a)};function kd(a,b){this.cpu=a.cpu;this.virtio=a.virtio;this.head_idx=b;this.read_buffers=
644
- [];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 g=this.virtio.is_feature_negotiated(28);do{const h=a.get_descriptor(c,b);y(h.addr_high,8);y(h.addr_low,8);y(h.len,8);y(h.flags,4);y(h.next,4);if(g&&h.flags&4)c=h.addr_low,d=b=0,e=h.len/16;else{if(h.flags&2)f=!0,this.write_buffers.push(h),this.length_writable+=h.len;else{if(f)break;
645
- this.read_buffers.push(h);this.length_readable+=h.len}d++;if(d>e)break;if(h.flags&1)b=h.next;else break}}while(1)}kd.prototype.get_next_blob=function(a){let b=0,c=a.length;for(;c&&this.read_buffer_idx!==this.read_buffers.length;){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};kd.prototype.set_next_blob=
646
- function(a){let b=0,c=a.length;for(;c&&this.write_buffer_idx!==this.write_buffers.length;){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};function ld(a,b,c,d){const e=new Lc(a,{name:"virtio-9p",pci_id:48,device_id:4169,subsystem_device_id:9,common:{initial_port:43008,
647
- queues:[{size_supported:32,notify_offset:0}],features:[0,32,29,28],on_driver_ok:()=>{}},notification:{initial_port:43264,single_handler:!1,handlers:[f=>{if(0===f){for(f=e.queues[0];f.has_request();){const g=f.pop_request();d(g)}f.notify_me_after(0)}}]},isr_status:{initial_port:42752},device_specific:{initial_port:42496,struct:[{bytes:2,name:"mount tag length",read:()=>b,write:()=>{}}].concat(Array.from(Array(254).keys()).map(f=>({bytes:1,name:"mount tag name "+f,read:()=>c[f]||0,write:()=>{}})))}});
648
- return e}function hd(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.virtio=ld(b,this.configspace_taglen,this.configspace_tagname,this.ReceiveRequest.bind(this));this.virtqueue=this.virtio.queues[0];this.VERSION="9P2000.L";this.msize=this.BLOCKSIZE=8192;this.replybuffer=new Uint8Array(2*this.msize);this.replybuffersize=0;this.fids=[]}hd.prototype.get_state=function(){var a=[];a[0]=this.configspace_tagname;a[1]=
649
- 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};hd.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];
650
- 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])};hd.prototype.Createfid=function(a,b,c,d){return{inodeid:a,type:b,uid:c,dbg_name:d}};hd.prototype.update_dbg_name=function(a,b){for(const c of this.fids)c.inodeid===a&&(c.dbg_name=b)};hd.prototype.reset=function(){this.fids=[];this.virtio.reset()};hd.prototype.BuildReply=function(a,b,c){I(["w","b","h"],[c+7,a+1,b],this.replybuffer,0);this.replybuffersize=c+7};hd.prototype.SendError=function(a,
651
- b,c){b=I(["w"],[c],this.replybuffer,7);this.BuildReply(6,a,b)};hd.prototype.SendReply=function(a){a.set_next_blob(this.replybuffer.subarray(0,this.replybuffersize));this.virtqueue.push_reply(a);this.virtqueue.flush_replies()};hd.prototype.ReceiveRequest=async function(a){var b=new Uint8Array(a.length_readable);a.get_next_blob(b);var c={offset:0},d=J(["w","b","h"],b,c),e=d[1];d=d[2];switch(e){case 8:var f=this.fs.GetTotalSize();var g=this.fs.GetSpace(),h=[16914839];h[1]=this.BLOCKSIZE;h[2]=Math.floor(g/
652
- h[1]);h[3]=h[2]-Math.floor(f/h[1]);h[4]=h[2]-Math.floor(f/h[1]);h[5]=this.fs.CountUsedInodes();h[6]=this.fs.CountFreeInodes();h[7]=0;h[8]=256;f=I("wwddddddw".split(""),h,this.replybuffer,7);this.BuildReply(e,d,f);this.SendReply(a);break;case 112:case 12:h=J(["w","w"],b,c);f=h[0];var l=h[1];b=this.fids[f].inodeid;c=this.fs.GetInode(b);await this.fs.OpenInode(b,l);h=[];h[0]=c.qid;h[1]=this.msize-24;I(["Q","w"],h,this.replybuffer,7);this.BuildReply(e,d,17);this.SendReply(a);break;case 70:h=J(["w","w",
653
- "s"],b,c);b=h[0];f=h[1];g=h[2];f=this.fs.Link(this.fids[b].inodeid,this.fids[f].inodeid,g);if(0>f){this.SendError(d,-1===f?"Operation not permitted":"Unknown error: "+-f,-f);this.SendReply(a);break}this.BuildReply(e,d,0);this.SendReply(a);break;case 16:h=J(["w","s","s","w"],b,c);f=h[0];g=h[1];var m=h[3];b=this.fs.CreateSymlink(g,this.fids[f].inodeid,h[2]);c=this.fs.GetInode(b);c.uid=this.fids[f].uid;c.gid=m;I(["Q"],[c.qid],this.replybuffer,7);this.BuildReply(e,d,13);this.SendReply(a);break;case 18:h=
654
- J("wswwww".split(""),b,c);f=h[0];g=h[1];l=h[2];b=h[3];c=h[4];m=h[5];b=this.fs.CreateNode(g,this.fids[f].inodeid,b,c);c=this.fs.GetInode(b);c.mode=l;c.uid=this.fids[f].uid;c.gid=m;I(["Q"],[c.qid],this.replybuffer,7);this.BuildReply(e,d,13);this.SendReply(a);break;case 22:h=J(["w"],b,c);f=h[0];c=this.fs.GetInode(this.fids[f].inodeid);f=I(["s"],[c.symlink],this.replybuffer,7);this.BuildReply(e,d,f);this.SendReply(a);break;case 72:h=J(["w","s","w","w"],b,c);f=h[0];g=h[1];l=h[2];m=h[3];b=this.fs.CreateDirectory(g,
655
- this.fids[f].inodeid);c=this.fs.GetInode(b);c.mode=l|16384;c.uid=this.fids[f].uid;c.gid=m;I(["Q"],[c.qid],this.replybuffer,7);this.BuildReply(e,d,13);this.SendReply(a);break;case 14:h=J(["w","s","w","w","w"],b,c);f=h[0];g=h[1];l=h[3];m=h[4];this.bus.send("9p-create",[g,this.fids[f].inodeid]);b=this.fs.CreateFile(g,this.fids[f].inodeid);this.fids[f].inodeid=b;this.fids[f].type=1;this.fids[f].dbg_name=g;c=this.fs.GetInode(b);c.uid=this.fids[f].uid;c.gid=m;c.mode=l|32768;I(["Q","w"],[c.qid,this.msize-
656
- 24],this.replybuffer,7);this.BuildReply(e,d,17);this.SendReply(a);break;case 52:h=J("wbwddws".split(""),b,c);f=h[0];g=h[2];b=0===h[4]?Infinity:h[4];h=this.fs.DescribeLock(h[1],h[3],b,h[5],h[6]);f=this.fs.Lock(this.fids[f].inodeid,h,g);I(["b"],[f],this.replybuffer,7);this.BuildReply(e,d,1);this.SendReply(a);break;case 54:h=J("wbddws".split(""),b,c);f=h[0];b=0===h[3]?Infinity:h[3];h=this.fs.DescribeLock(h[1],h[2],b,h[4],h[5]);f=this.fs.GetLock(this.fids[f].inodeid,h);f||(f=h,f.type=2);f=I(["b","d",
657
- "d","w","s"],[f.type,f.start,Infinity===f.length?0:f.length,f.proc_id,f.client_id],this.replybuffer,7);this.BuildReply(e,d,f);this.SendReply(a);break;case 24:h=J(["w","d"],b,c);f=h[0];c=this.fs.GetInode(this.fids[f].inodeid);if(!c||4===c.status){this.SendError(d,"No such file or directory",2);this.SendReply(a);break}h[0]=h[1];h[1]=c.qid;h[2]=c.mode;h[3]=c.uid;h[4]=c.gid;h[5]=c.nlinks;h[6]=c.major<<8|c.minor;h[7]=c.size;h[8]=this.BLOCKSIZE;h[9]=Math.floor(c.size/512+1);h[10]=c.atime;h[11]=0;h[12]=
658
- c.mtime;h[13]=0;h[14]=c.ctime;h[15]=0;h[16]=0;h[17]=0;h[18]=0;h[19]=0;I("dQwwwddddddddddddddd".split(""),h,this.replybuffer,7);this.BuildReply(e,d,153);this.SendReply(a);break;case 26:h=J("wwwwwddddd".split(""),b,c);f=h[0];c=this.fs.GetInode(this.fids[f].inodeid);h[1]&1&&(c.mode=h[2]);h[1]&2&&(c.uid=h[3]);h[1]&4&&(c.gid=h[4]);h[1]&16&&(c.atime=Math.floor((new Date).getTime()/1E3));h[1]&32&&(c.mtime=Math.floor((new Date).getTime()/1E3));h[1]&64&&(c.ctime=Math.floor((new Date).getTime()/1E3));h[1]&
659
- 128&&(c.atime=h[6]);h[1]&256&&(c.mtime=h[8]);h[1]&8&&await this.fs.ChangeSize(this.fids[f].inodeid,h[5]);this.BuildReply(e,d,0);this.SendReply(a);break;case 50:J(["w","d"],b,c);this.BuildReply(e,d,0);this.SendReply(a);break;case 40:case 116:h=J(["w","d","w"],b,c);f=h[0];g=h[1];l=h[2];c=this.fs.GetInode(this.fids[f].inodeid);if(!c||4===c.status){this.SendError(d,"No such file or directory",2);this.SendReply(a);break}if(2===this.fids[f].type)for(c.caps.length<g+l&&(l=c.caps.length-g),h=0;h<l;h++)this.replybuffer[11+
660
- h]=c.caps[g+h];else await this.fs.OpenInode(this.fids[f].inodeid,void 0),h=this.fids[f].inodeid,l=Math.min(l,this.replybuffer.length-11),c.size<g+l?l=c.size-g:40===e&&(l=this.fs.RoundToDirentry(h,g+l)-g),g>c.size&&(l=0),this.bus.send("9p-read-start",[this.fids[f].dbg_name]),h=await this.fs.Read(h,g,l),this.bus.send("9p-read-end",[this.fids[f].dbg_name,l]),h&&this.replybuffer.set(h,11);I(["w"],[l],this.replybuffer,7);this.BuildReply(e,d,4+l);this.SendReply(a);break;case 118:h=J(["w","d","w"],b,c);
661
- f=h[0];g=h[1];l=h[2];h=this.fids[f].dbg_name;if(2===this.fids[f].type){this.SendError(d,"Setxattr not supported",95);this.SendReply(a);break}else await this.fs.Write(this.fids[f].inodeid,g,l,b.subarray(c.offset));this.bus.send("9p-write-end",[h,l]);I(["w"],[l],this.replybuffer,7);this.BuildReply(e,d,4);this.SendReply(a);break;case 74:h=J(["w","s","w","s"],b,c);f=await this.fs.Rename(this.fids[h[0]].inodeid,h[1],this.fids[h[2]].inodeid,h[3]);if(0>f){this.SendError(d,-2===f?"No such file or directory":
662
- -1===f?"Operation not permitted":-39===f?"Directory not empty":"Unknown error: "+-f,-f);this.SendReply(a);break}this.BuildReply(e,d,0);this.SendReply(a);break;case 76:h=J(["w","s","w"],b,c);b=h[0];g=h[1];f=this.fs.Search(this.fids[b].inodeid,g);if(-1===f){this.SendError(d,"No such file or directory",2);this.SendReply(a);break}f=this.fs.Unlink(this.fids[b].inodeid,g);if(0>f){this.SendError(d,-39===f?"Directory not empty":-1===f?"Operation not permitted":"Unknown error: "+-f,-f);this.SendReply(a);break}this.BuildReply(e,
663
- d,0);this.SendReply(a);break;case 100:f=J(["w","s"],b,c);this.msize!==f[0]&&(this.msize=f[0],this.replybuffer=new Uint8Array(Math.min(16777216,2*this.msize)));f=I(["w","s"],[this.msize,this.VERSION],this.replybuffer,7);this.BuildReply(e,d,f);this.SendReply(a);break;case 104:h=J(["w","w","s","s","w"],b,c);f=h[0];g=h[4];y(h[1]);this.fids[f]=this.Createfid(0,1,g,"");c=this.fs.GetInode(this.fids[f].inodeid);I(["Q"],[c.qid],this.replybuffer,7);this.BuildReply(e,d,13);this.SendReply(a);this.bus.send("9p-attach");
664
- break;case 108:J(["h"],b,c);this.BuildReply(e,d,0);this.SendReply(a);break;case 110:h=J(["w","w","h"],b,c);f=h[0];l=h[1];m=h[2];if(0===m){this.fids[l]=this.Createfid(this.fids[f].inodeid,1,this.fids[f].uid,this.fids[f].dbg_name);I(["h"],[0],this.replybuffer,7);this.BuildReply(e,d,2);this.SendReply(a);break}g=[];for(h=0;h<m;h++)g.push("s");c=J(g,b,c);b=this.fids[f].inodeid;g=9;var n=0;for(h=0;h<m;h++){b=this.fs.Search(b,c[h]);if(-1===b)break;g+=I(["Q"],[this.fs.GetInode(b).qid],this.replybuffer,g);
665
- n++;this.fids[l]=this.Createfid(b,1,this.fids[f].uid,c[h])}I(["h"],[n],this.replybuffer,7);this.BuildReply(e,d,g-7);this.SendReply(a);break;case 120:h=J(["w"],b,c);this.fids[h[0]]&&0<=this.fids[h[0]].inodeid&&(await this.fs.CloseInode(this.fids[h[0]].inodeid),this.fids[h[0]].inodeid=-1,this.fids[h[0]].type=-1);this.BuildReply(e,d,0);this.SendReply(a);break;case 32:h=J(["w","s","d","w"],b,c);f=h[0];this.fids[f].type=2;this.BuildReply(e,d,0);this.SendReply(a);break;case 30:J(["w","w","s"],b,c),this.SendError(d,
666
- "Setxattr not supported",95),this.SendReply(a)}};function id(a,b){this.handle_fn=a;this.tag_bufchain=new Map;this.configspace_tagname=[104,111,115,116,57,112];this.configspace_taglen=this.configspace_tagname.length;this.virtio=ld(b,this.configspace_taglen,this.configspace_tagname,async c=>{const d=new Uint8Array(c.length_readable);c.get_next_blob(d);var e=J(["w","b","h"],d,{offset:0})[2];this.tag_bufchain.set(e,c);this.handle_fn(d,f=>{var g=J(["w","b","h"],f,{offset:0})[2];const h=this.tag_bufchain.get(g);
667
- h?(h.set_next_blob(f),this.virtqueue.push_reply(h),this.virtqueue.flush_replies(),this.tag_bufchain.delete(g)):console.error("No bufchain found for tag: "+g)})});this.virtqueue=this.virtio.queues[0]}id.prototype.get_state=function(){var a=[];a[0]=this.configspace_tagname;a[1]=this.configspace_taglen;a[2]=this.virtio;a[3]=this.tag_bufchain;return a};id.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];
668
- this.tag_bufchain=a[3]};id.prototype.reset=function(){this.virtio.reset()};function jd(a,b){this.socket=void 0;this.cpu=b;this.send_queue=[];this.url=a;this.reconnect_interval=1E4;this.last_connect_attempt=Date.now()-this.reconnect_interval;this.send_queue_limit=64;this.destroyed=!1;this.tag_bufchain=new Map;this.configspace_tagname=[104,111,115,116,57,112];this.configspace_taglen=this.configspace_tagname.length;this.virtio=ld(b,this.configspace_taglen,this.configspace_tagname,async c=>{const d=new Uint8Array(c.length_readable);
669
- c.get_next_blob(d);const e=J(["w","b","h"],d,{offset:0})[2];this.tag_bufchain.set(e,c);this.send(d)});this.virtqueue=this.virtio.queues[0]}jd.prototype.get_state=function(){var a=[];a[0]=this.configspace_tagname;a[1]=this.configspace_taglen;a[2]=this.virtio;a[3]=this.tag_bufchain;return a};jd.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.tag_bufchain=a[3]};jd.prototype.reset=function(){this.virtio.reset()};
670
- jd.prototype.handle_message=function(a){a=new Uint8Array(a.data);const b=J(["w","b","h"],a,{offset:0})[2],c=this.tag_bufchain.get(b);c?(c.set_next_blob(a),this.virtqueue.push_reply(c),this.virtqueue.flush_replies(),this.tag_bufchain.delete(b)):console.error("Virtio9pProxy: No bufchain found for tag: "+b)};jd.prototype.handle_close=function(){this.destroyed||(this.connect(),setTimeout(this.connect.bind(this),this.reconnect_interval))};jd.prototype.handle_open=function(){for(var a=0;a<this.send_queue.length;a++)this.send(this.send_queue[a]);
671
- this.send_queue=[]};jd.prototype.handle_error=function(){};jd.prototype.destroy=function(){this.destroyed=!0;this.socket&&this.socket.close()};jd.prototype.connect=function(){if("undefined"!==typeof WebSocket){if(this.socket){var a=this.socket.readyState;if(0===a||1===a)return}a=Date.now();if(!(this.last_connect_attempt+this.reconnect_interval>a)){this.last_connect_attempt=Date.now();try{this.socket=new WebSocket(this.url)}catch(b){console.error(b);return}this.socket.binaryType="arraybuffer";this.socket.onopen=
672
- 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)}}};jd.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)),this.connect())};jd.prototype.change_proxy=function(a){this.url=a;this.socket&&(this.socket.onclose=
673
- function(){},this.socket.onerror=function(){},this.socket.close(),this.socket=void 0)};export{};; export default module.exports.V86; export let {V86, CPU} = module.exports;
404
+ this.kbd_irq();break;case 171:this.kbd_buffer.clear();this.mouse_buffer.clear();this.kbd_buffer.push(0);this.kbd_irq();break;case 173:this.command_register|=16;break;case 174:this.command_register&=-17;break;case 254:this.cpu.reboot_internal();break;default:y(a)}};function Nc(a,b){function c(){}this.cpu=a;this.bus=b;this.absolute=this.enabled=!1;this.queue=[];this.buttons=0;this.last_y=this.last_x=-1;this.host_pointer_locked=this.tail_is_move=!1;this.rel_dy=this.rel_dx=0;this.bus.register("mouse-absolute",
405
+ function(d){const e=Math.max(0,Math.min(65535,Math.round(d[0]/d[2]*65535)));d=Math.max(0,Math.min(65535,Math.round(d[1]/d[3]*65535)));if(e!==this.last_x||d!==this.last_y)this.last_x=e,this.last_y=d,this.push_absolute(0,!0)},this);this.bus.register("mouse-delta",function(d){if(this.host_pointer_locked){this.rel_dx+=d[0];this.rel_dy+=d[1];d=this.rel_dx|0;var e=this.rel_dy|0;if(d||e)this.rel_dx-=d,this.rel_dy-=e,this.push_relative(d,e,0,!0)}},this);this.bus.register("mouse-pointer-lock",function(d){this.host_pointer_locked=
406
+ d;this.rel_dy=this.rel_dx=0},this);this.bus.register("mouse-click",function(d){this.buttons=(d[0]?32:0)|(d[1]?8:0)|(d[2]?16:0);this.host_pointer_locked?this.push_relative(0,0,0,!1):this.push_absolute(0,!1)},this);this.bus.register("mouse-wheel",function(d){this.host_pointer_locked?this.push_relative(0,0,-d[0]|0,!1):this.push_absolute(-d[0]|0,!1)},this);a.io.register_read(22104,this,function(){return 255},function(){return 65535},this.port_read32);a.io.register_write(22104,this,c,c,c)}Nc.prototype.push_absolute=
407
+ function(a,b){!this.enabled||!this.absolute||0>this.last_x||(b&&this.tail_is_move&&4<=this.queue.length&&!(this.queue[this.queue.length-4]&65536)?(this.queue[this.queue.length-3]=this.last_x,this.queue[this.queue.length-2]=this.last_y):this.push_packet(this.buttons,this.last_x,this.last_y,a,b))};Nc.prototype.push_relative=function(a,b,c,d){this.enabled&&(d&&this.tail_is_move&&4<=this.queue.length&&this.queue[this.queue.length-4]&65536?(this.queue[this.queue.length-3]+=a,this.queue[this.queue.length-
408
+ 2]+=b):this.push_packet(this.buttons|65536,a,b,c,d))};Nc.prototype.push_packet=function(a,b,c,d,e){1024<this.queue.length+4?(this.enabled=!1,this.queue.length=0):(this.queue.push(a,b,c,d),this.tail_is_move=e)};Nc.prototype.port_read32=function(){const a=this.cpu.reg32;if(1447909480!==a[0])return-1;switch(a[1]&65535){case 10:return a[3]=1447909480,6;case 40:return this.enabled?this.queue.length:-65536;case 39:const b=Math.min(a[3]>>>0,4,this.queue.length),c=[0,0,0,0];for(let d=0;d<b;d++)c[d]=this.queue.shift();
409
+ a[3]=c[1];a[1]=c[2];a[2]=c[3];return c[0];case 41:switch(a[3]){case 1161905490:this.enabled=!0;this.queue.length=0;this.tail_is_move=!1;this.queue.push(876762442);break;case 245:this.absolute=this.enabled=!1;this.queue.length=0;this.bus.send("vmware-absolute-mouse",!1);break;case 1396851026:this.absolute=!0;this.bus.send("vmware-absolute-mouse",!0);break;case 1279611474:this.absolute=!1,this.bus.send("vmware-absolute-mouse",!1)}return 0}return-1};Nc.prototype.get_state=function(){return[this.enabled,
410
+ this.absolute]};Nc.prototype.set_state=function(a){this.enabled=a[0];this.absolute=a[1];this.bus.send("vmware-absolute-mouse",this.absolute)};const Oc=DataView.prototype,Pc={size:1,get:Oc.getUint8,set:Oc.setUint8},Qc={size:2,get:Oc.getUint16,set:Oc.setUint16},V={size:4,get:Oc.getUint32,set:Oc.setUint32},Sc=Rc([{magic:V},{class:Pc},{data:Pc},{version0:Pc},{osabi:Pc},{abiversion:Pc},{pad0:function(a){return{size:a,get:()=>-1}}(7)},{type:Qc},{machine:Qc},{version1:V},{entry:V},{phoff:V},{shoff:V},{flags:V},
411
+ {ehsize:Qc},{phentsize:Qc},{phnum:Qc},{shentsize:Qc},{shnum:Qc},{shstrndx:Qc}]);console.assert(52===Sc.reduce((a,b)=>a+b.size,0));const Tc=Rc([{type:V},{offset:V},{vaddr:V},{paddr:V},{filesz:V},{memsz:V},{flags:V},{align:V}]);console.assert(32===Tc.reduce((a,b)=>a+b.size,0));const Uc=Rc([{name:V},{type:V},{flags:V},{addr:V},{offset:V},{size:V},{link:V},{info:V},{addralign:V},{entsize:V}]);console.assert(40===Uc.reduce((a,b)=>a+b.size,0));function Rc(a){return a.map(function(b){var c=Object.keys(b);
412
+ console.assert(1===c.length);c=c[0];b=b[c];console.assert(0<b.size);return{name:c,type:b,size:b.size,get:b.get,set:b.set}})}function Vc(a,b){const c={};let d=0;for(const e of b)b=e.get.call(a,d,!0),console.assert(void 0===c[e.name]),c[e.name]=b,d+=e.size;return[c,d]}function Wc(a,b,c){const d=[];let e=0;for(var f=0;f<c;f++){const [g,h]=Vc(new DataView(a.buffer,a.byteOffset+e,void 0),b);d.push(g);e+=h}return[d,e]}const Xc={[0]:0,[1]:525,[2]:525,[3]:350,[4]:350,[5]:350};function W(a,b,c,d){this.io=
413
+ a.io;this.cpu=a;this.dma=a.devices.dma;this.cmd_table=this.build_cmd_lookup_table();this.sra=0;this.srb=192;this.dor=12;this.tdr=0;this.msr=128;this.dsr=0;this.cmd_phase=1;this.cmd_flags=this.cmd_code=0;this.cmd_buffer=new Uint8Array(17);this.cmd_remaining=this.cmd_cursor=0;this.response_data=new Uint8Array(15);this.reset_sense_int_count=this.curr_drive_no=this.status1=this.status0=this.response_length=this.response_cursor=0;this.locked=!1;this.head_load_time=this.step_rate_interval=0;this.fdc_config=
414
+ 96;this.eot=this.precomp_trk=0;this.drives=[new Yc("fda",d?.fda,b,4),new Yc("fdb",d?.fdb,c,4)];Object.seal(this);this.cpu.devices.rtc.cmos_write(16,this.drives[0].drive_type<<4|this.drives[1].drive_type);this.io.register_read(1008,this,this.read_reg_sra);this.io.register_read(1009,this,this.read_reg_srb);this.io.register_read(1010,this,this.read_reg_dor);this.io.register_read(1011,this,this.read_reg_tdr);this.io.register_read(1012,this,this.read_reg_msr);this.io.register_read(1013,this,this.read_reg_fifo);
415
+ this.io.register_read(1015,this,this.read_reg_dir);this.io.register_write(1010,this,this.write_reg_dor);this.io.register_write(1011,this,this.write_reg_tdr);this.io.register_write(1012,this,this.write_reg_dsr);this.io.register_write(1013,this,this.write_reg_fifo);this.io.register_write(1015,this,this.write_reg_ccr)}W.prototype.build_cmd_lookup_table=function(){const a=[{code:6,mask:31,argc:8,name:"READ",handler:this.exec_read},{code:5,mask:63,argc:8,name:"WRITE",handler:this.exec_write},{code:15,
416
+ mask:255,argc:2,name:"SEEK",handler:this.exec_seek},{code:8,mask:255,argc:0,name:"SENSE INTERRUPT STATUS",handler:this.exec_sense_interrupt_status},{code:7,mask:255,argc:1,name:"RECALIBRATE",handler:this.exec_recalibrate},{code:13,mask:191,argc:5,name:"FORMAT TRACK",handler:this.exec_format_track},{code:2,mask:191,argc:8,name:"READ TRACK",handler:this.exec_unimplemented},{code:78,mask:255,argc:17,name:"RESTORE",handler:this.exec_unimplemented},{code:46,mask:255,argc:0,name:"SAVE",handler:this.exec_unimplemented},
417
+ {code:12,mask:31,argc:8,name:"READ DELETED DATA",handler:this.exec_unimplemented},{code:17,mask:31,argc:8,name:"SCAN EQUAL",handler:this.exec_unimplemented},{code:22,mask:31,argc:8,name:"VERIFY",handler:this.exec_unimplemented},{code:25,mask:31,argc:8,name:"SCAN LOW OR EQUAL",handler:this.exec_unimplemented},{code:29,mask:31,argc:8,name:"SCAN HIGH OR EQUAL",handler:this.exec_unimplemented},{code:9,mask:63,argc:8,name:"WRITE DELETED DATA",handler:this.exec_unimplemented},{code:10,mask:191,argc:1,name:"READ ID",
418
+ handler:this.exec_read_id},{code:3,mask:255,argc:2,name:"SPECIFY",handler:this.exec_specify},{code:4,mask:255,argc:1,name:"SENSE DRIVE STATUS",handler:this.exec_sense_drive_status},{code:18,mask:255,argc:1,name:"PERPENDICULAR MODE",handler:this.exec_perpendicular_mode},{code:19,mask:255,argc:3,name:"CONFIGURE",handler:this.exec_configure},{code:23,mask:255,argc:2,name:"POWERDOWN MODE",handler:this.exec_unimplemented},{code:51,mask:255,argc:1,name:"OPTION",handler:this.exec_unimplemented},{code:142,
419
+ mask:255,argc:5,name:"DRIVE SPECIFICATION",handler:this.exec_unimplemented},{code:143,mask:255,argc:2,name:"RELATIVE SEEK OUT",handler:this.exec_unimplemented},{code:205,mask:255,argc:10,name:"FORMAT AND WRITE",handler:this.exec_unimplemented},{code:207,mask:255,argc:2,name:"RELATIVE SEEK IN",handler:this.exec_unimplemented},{code:20,mask:127,argc:0,name:"LOCK",handler:this.exec_lock},{code:14,mask:255,argc:0,name:"DUMP REGISTERS",handler:this.exec_dump_regs},{code:16,mask:255,argc:0,name:"VERSION",
420
+ handler:this.exec_version},{code:24,mask:255,argc:0,name:"PART ID",handler:this.exec_part_id},{code:0,mask:0,argc:0,name:"UNKNOWN COMMAND",handler:this.exec_unimplemented}],b=Array(256);for(let c=a.length-1;0<=c;c--){const d=a[c];if(255===d.mask)b[d.code]=d;else for(let e=0;256>e;e++)(e&d.mask)===d.code&&(b[e]=d)}return b};W.prototype.raise_irq=function(){this.sra&128||(this.cpu.device_raise_irq(6),this.sra|=128);this.reset_sense_int_count=0};W.prototype.lower_irq=function(){this.status0=0;this.sra&
421
+ 128&&(this.cpu.device_lower_irq(6),this.sra&=-129)};W.prototype.set_curr_drive_no=function(a){this.curr_drive_no=a&1;return this.drives[this.curr_drive_no]};W.prototype.enter_command_phase=function(){this.cmd_phase=1;this.cmd_remaining=this.cmd_cursor=0;this.msr&=-81;this.msr|=128};W.prototype.enter_result_phase=function(a){this.cmd_phase=3;this.response_cursor=0;this.response_length=a;this.msr|=208};W.prototype.reset_fdc=function(){this.lower_irq("controller reset");this.sra=0;this.srb=192;this.dor=
422
+ 12;this.msr=128;this.curr_drive_no=0;this.status0|=192;this.response_length=this.response_cursor=0;this.drives[0].seek(0,0,1);this.drives[1].seek(0,0,1);this.enter_command_phase();this.raise_irq("controller reset");this.reset_sense_int_count=4};W.prototype.read_reg_sra=function(){y(this.sra);return this.sra};W.prototype.read_reg_srb=function(){y(this.srb);return this.srb};W.prototype.read_reg_dor=function(){const a=this.dor&-4|this.curr_drive_no;y(a);return a};W.prototype.read_reg_tdr=function(){y(this.tdr);
423
+ return this.tdr};W.prototype.read_reg_msr=function(){y(this.msr);this.dsr&=-65;this.dor|=4;return this.msr};W.prototype.read_reg_fifo=function(){this.dsr&=-65;if(!(this.msr&128&&this.msr&64)||3!==this.cmd_phase)return 0;if(this.response_cursor<this.response_length){const a=this.response_data[this.response_cursor++];this.response_cursor===this.response_length&&(this.msr&=-129,this.enter_command_phase(),this.lower_irq(""));return a}return 0};W.prototype.read_reg_dir=function(){const a=this.drives[this.curr_drive_no].media_changed?
424
+ 128:0;y(a);return a};W.prototype.write_reg_dor=function(a){this.srb=this.srb&-36|(a&16?1:0)|(a&32?2:0)|(a&1?32:0);!(this.dor&4)&&a&4&&(this.reset_fdc(),this.dsr&=-65);const b=a&3;y(a);y(a>>4);this.curr_drive_no=b&1;this.dor=a};W.prototype.write_reg_tdr=function(a){this.dor&4?(y(a),this.tdr=a&4):y(a)};W.prototype.write_reg_dsr=function(a){this.dor&4?(y(a),a&128&&(this.dor&=-5,this.reset_fdc(),this.dor|=4),a&64&&this.reset_fdc(),this.dsr=a):y(a)};W.prototype.write_reg_fifo=function(a){this.dsr&=-65;
425
+ if(this.dor&4)if(!(this.msr&128)||this.msr&64)y(a);else if(1!==this.cmd_phase)y(a);else{if(0===this.cmd_remaining){var b=this.cmd_table[a];this.cmd_code=a;this.cmd_remaining=b.argc;this.cmd_flags=this.cmd_cursor=0;(6===b.code||5===b.code)&&this.cmd_code&128&&(this.cmd_flags|=1);this.cmd_remaining&&(this.msr|=128);this.msr|=16}else this.cmd_buffer[this.cmd_cursor++]=a,this.cmd_remaining--;0===this.cmd_remaining&&(this.cmd_phase=2,a=this.cmd_table[this.cmd_code],b=this.cmd_buffer.slice(0,this.cmd_cursor),
426
+ a.handler.call(this,b))}else y(a)};W.prototype.write_reg_ccr=function(a){this.dor&4?(y(a),this.dsr=this.dsr&-4|a&3):y(a)};W.prototype.exec_unimplemented=function(){y(this.cmd_code);this.status0=128;this.response_data[0]=this.status0;this.enter_result_phase(1)};W.prototype.exec_read=function(a){this.start_read_write(a,!1)};W.prototype.exec_write=function(a){this.start_read_write(a,!0)};W.prototype.exec_seek=function(a){const b=this.set_curr_drive_no(a[0]&1);a=a[1];this.enter_command_phase();b.seek(b.curr_head,
427
+ a,b.curr_sect);this.status0|=32;this.raise_irq("SEEK command")};W.prototype.exec_sense_interrupt_status=function(){const a=this.drives[this.curr_drive_no];let b;if(0<this.reset_sense_int_count)b=192|4-this.reset_sense_int_count--;else if(this.sra&128)b=this.status0&-8|this.curr_drive_no;else{this.response_data[0]=128;this.enter_result_phase(1);return}this.response_data[0]=b;this.response_data[1]=a.curr_track;this.enter_result_phase(2);this.lower_irq("SENSE INTERRUPT command");this.status0=192};W.prototype.exec_recalibrate=
428
+ function(a){this.set_curr_drive_no(a[0]&1).seek(0,0,1);this.enter_command_phase();this.status0|=32;this.raise_irq("RECALIBRATE command")};W.prototype.exec_format_track=function(a){let b=0,c=0;this.set_curr_drive_no(a[0]&1).read_only&&(b=96,c=2);this.end_read_write(b,c,0)};W.prototype.exec_read_id=function(a){const b=this.drives[this.curr_drive_no];b.curr_head=a[0]>>2&1;0!==b.max_sect&&(b.curr_sect=b.curr_sect%b.max_sect+1);this.end_read_write(0,0,0)};W.prototype.exec_specify=function(a){const b=a[1];
429
+ this.step_rate_interval=a[0]>>4;this.head_load_time=b>>1;this.dor=b&1?this.dor&-9:this.dor|8;this.enter_command_phase()};W.prototype.exec_sense_drive_status=function(a){a=a[0];const b=this.set_curr_drive_no(a&1);b.curr_head=a>>2&1;this.response_data[0]=(b.read_only?64:0)|(0===b.curr_track?16:0)|b.curr_head<<2|this.curr_drive_no|40;this.enter_result_phase(1)};W.prototype.exec_perpendicular_mode=function(a){a=a[0];a&128&&(this.drives[this.curr_drive_no].perpendicular=a&7);this.enter_command_phase()};
430
+ W.prototype.exec_configure=function(a){this.fdc_config=a[1];this.precomp_trk=a[2];this.enter_command_phase()};W.prototype.exec_lock=function(){this.cmd_code&128?(this.locked=!0,this.response_data[0]=16):(this.locked=!1,this.response_data[0]=0);this.enter_result_phase(1)};W.prototype.exec_dump_regs=function(){const a=this.drives[this.curr_drive_no];this.response_data[0]=this.drives[0].curr_track;this.response_data[1]=this.drives[1].curr_track;this.response_data[2]=0;this.response_data[3]=0;this.response_data[4]=
431
+ this.step_rate_interval;this.response_data[5]=this.head_load_time<<1|(this.dor&8?1:0);this.response_data[6]=a.max_sect;this.response_data[7]=(this.locked?128:0)|a.perpendicular<<2;this.response_data[8]=this.fdc_config;this.response_data[9]=this.precomp_trk;this.enter_result_phase(10)};W.prototype.exec_version=function(){this.response_data[0]=144;this.enter_result_phase(1)};W.prototype.exec_part_id=function(){this.response_data[0]=65;this.enter_result_phase(1)};W.prototype.start_read_write=function(a,
432
+ b){const c=this.set_curr_drive_no(a[0]&1),d=a[1],e=a[2],f=a[3];var g=a[4];const h=a[5];a=128>a[7]?a[7]:128;switch(c.seek(e,d,f)){case 2:this.end_read_write(64,0,0);this.response_data[3]=d;this.response_data[4]=e;this.response_data[5]=f;return;case 3:this.end_read_write(64,128,0);this.response_data[3]=d;this.response_data[4]=e;this.response_data[5]=f;return;case 1:this.status0|=32}const l=128<<(7<g?7:g);g=c.chs2lba(d,e,f)*l;if(128!==l&&(a=this.cmd_flags&1?(2*h-f+1)*l:(h-f+1)*l,0>=a)){this.end_read_write(64,
433
+ 1,0);this.response_data[3]=d;this.response_data[4]=e;this.response_data[5]=f;return}this.eot=h;b&&c.read_only?(this.end_read_write(96,2,0),this.response_data[3]=d,this.response_data[4]=e,this.response_data[5]=f):this.dor&8&&(this.msr&=-129,(b?this.dma.do_write:this.dma.do_read).call(this.dma,c.buffer,g,a,2,m=>{m?this.end_read_write(64,0,0):(this.seek_next_sect(),this.end_read_write(0,0,0))}))};W.prototype.end_read_write=function(a,b,c){const d=this.drives[this.curr_drive_no];this.status0&=-8;this.status0|=
434
+ this.curr_drive_no;d.curr_head&&(this.status0|=4);this.status0|=a;this.msr|=192;this.msr&=-33;this.response_data[0]=this.status0;this.response_data[1]=b;this.response_data[2]=c;this.response_data[3]=d.curr_track;this.response_data[4]=d.curr_head;this.response_data[5]=d.curr_sect;this.response_data[6]=2;this.enter_result_phase(7);this.raise_irq(this.cmd_table[this.cmd_code].name+" command")};W.prototype.seek_next_sect=function(){const a=this.drives[this.curr_drive_no];let b=a.curr_track,c=a.curr_head,
435
+ d=a.curr_sect,e=1;d>=a.max_sect||d===this.eot?(d=1,this.cmd_flags&1?0===c&&2===a.max_head?c=1:(c=0,b++,this.status0|=32,1===a.max_head&&(e=0)):(this.status0|=32,b++,e=0)):d++;a.seek(c,b,d);return e};W.prototype.get_state=function(){const a=[];a[19]=this.sra;a[20]=this.srb;a[21]=this.dor;a[22]=this.tdr;a[23]=this.msr;a[24]=this.dsr;a[25]=this.cmd_phase;a[26]=this.cmd_code;a[27]=this.cmd_flags;a[28]=this.cmd_buffer;a[29]=this.cmd_cursor;a[30]=this.cmd_remaining;a[31]=this.response_data;a[32]=this.response_cursor;
436
+ a[33]=this.response_length;a[34]=this.status0;a[35]=this.status1;a[36]=this.curr_drive_no;a[37]=this.reset_sense_int_count;a[38]=this.locked;a[39]=this.step_rate_interval;a[40]=this.head_load_time;a[41]=this.fdc_config;a[42]=this.precomp_trk;a[43]=this.eot;a[44]=this.drives[0].get_state();a[45]=this.drives[1].get_state();return a};W.prototype.set_state=function(a){"undefined"!==typeof a[19]&&(this.sra=a[19],this.srb=a[20],this.dor=a[21],this.tdr=a[22],this.msr=a[23],this.dsr=a[24],this.cmd_phase=
437
+ a[25],this.cmd_code=a[26],this.cmd_flags=a[27],this.cmd_buffer.set(a[28]),this.cmd_cursor=a[29],this.cmd_remaining=a[30],this.response_data.set(a[31]),this.response_cursor=a[32],this.response_length=a[33],this.status0=a[34],this.status1=a[35],this.curr_drive_no=a[36],this.reset_sense_int_count=a[37],this.locked=a[38],this.step_rate_interval=a[39],this.head_load_time=a[40],this.fdc_config=a[41],this.precomp_trk=a[42],this.eot=a[43],this.drives[0].set_state(a[44]),this.drives[1].set_state(a[45]))};
438
+ const Zc=[{drive_type:4,sectors:18,tracks:80,heads:2},{drive_type:4,sectors:20,tracks:80,heads:2},{drive_type:4,sectors:21,tracks:80,heads:2},{drive_type:4,sectors:21,tracks:82,heads:2},{drive_type:4,sectors:21,tracks:83,heads:2},{drive_type:4,sectors:22,tracks:80,heads:2},{drive_type:4,sectors:23,tracks:80,heads:2},{drive_type:4,sectors:24,tracks:80,heads:2},{drive_type:5,sectors:36,tracks:80,heads:2},{drive_type:5,sectors:39,tracks:80,heads:2},{drive_type:5,sectors:40,tracks:80,heads:2},{drive_type:5,
439
+ sectors:44,tracks:80,heads:2},{drive_type:5,sectors:48,tracks:80,heads:2},{drive_type:4,sectors:8,tracks:80,heads:2},{drive_type:4,sectors:9,tracks:80,heads:2},{drive_type:4,sectors:10,tracks:80,heads:2},{drive_type:4,sectors:10,tracks:82,heads:2},{drive_type:4,sectors:10,tracks:83,heads:2},{drive_type:4,sectors:13,tracks:80,heads:2},{drive_type:4,sectors:14,tracks:80,heads:2},{drive_type:2,sectors:15,tracks:80,heads:2},{drive_type:2,sectors:18,tracks:80,heads:2},{drive_type:2,sectors:18,tracks:82,
440
+ heads:2},{drive_type:2,sectors:18,tracks:83,heads:2},{drive_type:2,sectors:20,tracks:80,heads:2},{drive_type:2,sectors:9,tracks:80,heads:2},{drive_type:2,sectors:11,tracks:80,heads:2},{drive_type:2,sectors:9,tracks:40,heads:2},{drive_type:2,sectors:9,tracks:40,heads:1},{drive_type:2,sectors:10,tracks:41,heads:2},{drive_type:2,sectors:10,tracks:42,heads:2},{drive_type:2,sectors:8,tracks:40,heads:2},{drive_type:2,sectors:8,tracks:40,heads:1},{drive_type:4,sectors:9,tracks:80,heads:1},{drive_type:1,
441
+ sectors:10,tracks:40,heads:1},{drive_type:1,sectors:10,tracks:40,heads:2}];function Yc(a,b,c,d){this.name=a;this.curr_head=this.curr_track=this.max_sect=this.max_head=this.max_track=this.drive_type=0;this.curr_sect=1;this.perpendicular=0;this.read_only=!1;this.media_changed=!0;this.buffer=null;Object.seal(this);a=b?.drive_type;void 0!==a&&0<=a&&5>=a&&(this.drive_type=a);this.insert_disk(c,!!b?.read_only);0===this.drive_type&&void 0===a&&(this.drive_type=d)}Yc.prototype.insert_disk=function(a,b){if(!a)return!1;
442
+ a instanceof Uint8Array&&(a=new A(a.buffer));const [c,d]=this.find_disk_format(a,this.drive_type);if(!c)return!1;this.max_track=d.tracks;this.max_head=d.heads;this.max_sect=d.sectors;this.read_only=!!b;this.media_changed=!0;this.buffer=c;0===this.drive_type&&(this.drive_type=d.drive_type);return!0};Yc.prototype.eject_disk=function(){this.max_sect=this.max_head=this.max_track=0;this.media_changed=!0;this.buffer=null};Yc.prototype.get_buffer=function(){return this.buffer?new Uint8Array(this.buffer.buffer):
443
+ null};Yc.prototype.chs2lba=function(a,b,c){return(a*this.max_head+b)*this.max_sect+c-1};Yc.prototype.find_disk_format=function(a,b){const c=0===b,d=a.byteLength;let e=-1,f=-1,g=-1,h=-1,l=-1;for(let m=0;m<Zc.length;m++){const n=Zc[m],p=n.sectors*n.tracks*n.heads*512;if(d===p)if(c||n.drive_type===b){e=m;break}else c||Xc[n.drive_type]!==Xc[b]?g=-1===g?m:g:f=-1===f?m:f;else d<p&&(-1===l||p<l)&&(h=m,l=p)}return-1!==e?[a,Zc[e]]:-1!==f?[a,Zc[f]]:-1!==g?[a,Zc[g]]:-1!==h?(b=new Uint8Array(l),b.set(new Uint8Array(a.buffer)),
444
+ [new A(b.buffer),Zc[h]]):[null,null]};Yc.prototype.seek=function(a,b,c){if(b>this.max_track||0!==a&&1===this.max_head)return 2;if(c>this.max_sect)return 3;let d=0;const e=this.chs2lba(this.curr_track,this.curr_head,this.curr_sect),f=this.chs2lba(b,a,c);e!==f&&(this.curr_track!==b&&(this.buffer&&(this.media_changed=!1),d=1),this.curr_head=a,this.curr_track=b,this.curr_sect=c);this.buffer||(d=2);return d};Yc.prototype.get_state=function(){const a=[];a[0]=this.drive_type;a[1]=this.max_track;a[2]=this.max_head;
445
+ a[3]=this.max_sect;a[4]=this.curr_track;a[5]=this.curr_head;a[6]=this.curr_sect;a[7]=this.perpendicular;a[8]=this.read_only;a[9]=this.media_changed;a[10]=this.buffer?this.buffer.get_state():null;return a};Yc.prototype.set_state=function(a){this.drive_type=a[0];this.max_track=a[1];this.max_head=a[2];this.max_sect=a[3];this.curr_track=a[4];this.curr_head=a[5];this.curr_sect=a[6];this.perpendicular=a[7];this.read_only=a[8];this.media_changed=a[9];a[10]?(this.buffer||(this.buffer=new A(new ArrayBuffer(0))),
446
+ this.buffer.set_state(a[10])):this.buffer=null};const $c={[70]:{name:"GET CONFIGURATION",flags:0},[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 (10)",flags:1},[168]:{name:"READ (12)",flags:1},[37]:{name:"READ CAPACITY",flags:1},[190]:{name:"READ CD",flags:1},
447
+ [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",flags:1},[3]:{name:"REQUEST SENSE",flags:0},[27]:{name:"START STOP UNIT",flags:0},[0]:{name:"TEST UNIT READY",flags:1}};function ad(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 bd(this,0,c[0],496,1014,14));d&&(this.secondary=new bd(this,1,c[1],368,886,15));c=b?this.primary.command_base:
448
+ 0;const e=b?this.primary.control_base:0,f=d?this.secondary.command_base:0,g=d?this.secondary.control_base:0;this.name="ide";this.pci_id=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,g&255|1,g>>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,
449
+ 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)}ad.prototype.get_state=function(){const a=[];a[0]=this.primary;a[1]=this.secondary;return a};ad.prototype.set_state=function(a){this.primary&&this.primary.set_state(a[0]);this.secondary&&this.secondary.set_state(a[1])};function bd(a,b,c,d,e,f){this.controller=a;this.channel_nr=b;this.cpu=a.cpu;this.bus=a.bus;this.command_base=
450
+ 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 X(this,0,d?.buffer,d?.is_cdrom);this.slave=new X(this,1,c?.buffer,c?.is_cdrom);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)});
451
+ 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&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&
452
+ 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 g=this.read_status();this.cpu.device_lower_irq(this.irq);return g});a.io.register_write(this.command_base|0,this,function(g){this.current_interface.write_data_port8(g)},function(g){this.current_interface.write_data_port16(g)},function(g){this.current_interface.write_data_port32(g)});a.io.register_write(this.command_base|1,this,function(g){this.master.features_reg=
453
+ (this.master.features_reg<<8|g)&65535;this.slave.features_reg=(this.slave.features_reg<<8|g)&65535});a.io.register_write(this.command_base|2,this,function(g){this.master.sector_count_reg=(this.master.sector_count_reg<<8|g)&65535;this.slave.sector_count_reg=(this.slave.sector_count_reg<<8|g)&65535});a.io.register_write(this.command_base|3,this,function(g){this.master.lba_low_reg=(this.master.lba_low_reg<<8|g)&65535;this.slave.lba_low_reg=(this.slave.lba_low_reg<<8|g)&65535});a.io.register_write(this.command_base|
454
+ 4,this,function(g){this.master.lba_mid_reg=(this.master.lba_mid_reg<<8|g)&65535;this.slave.lba_mid_reg=(this.slave.lba_mid_reg<<8|g)&65535});a.io.register_write(this.command_base|5,this,function(g){this.master.lba_high_reg=(this.master.lba_high_reg<<8|g)&65535;this.slave.lba_high_reg=(this.slave.lba_high_reg<<8|g)&65535});a.io.register_write(this.command_base|6,this,function(g){const h=g&16;if(h&&this.current_interface===this.master||!h&&this.current_interface===this.slave)this.current_interface=
455
+ h?this.slave:this.master;this.master.device_reg=g;this.slave.device_reg=g;this.master.is_lba=g>>6&1;this.slave.is_lba=g>>6&1;this.master.head=g&15;this.slave.head=g&15});a.io.register_write(this.command_base|7,this,function(g){this.current_interface.status_reg&=-34;this.current_interface.ata_command(g);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|
456
+ 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|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)}bd.prototype.read_status=function(){return this.current_interface.drive_connected?this.current_interface.status_reg:0};bd.prototype.write_control=
457
+ function(a){a&4&&(this.cpu.device_lower_irq(this.irq),this.master.device_reset(),this.slave.device_reset());this.device_control_reg=a};bd.prototype.dma_read_addr=function(){return this.prdt_addr};bd.prototype.dma_set_addr=function(a){this.prdt_addr=a};bd.prototype.dma_read_status=function(){return this.dma_status};bd.prototype.dma_write_status=function(a){this.dma_status&=~(a&6)};bd.prototype.dma_read_command=function(){return this.dma_read_command8()|this.dma_read_status()<<16};bd.prototype.dma_read_command8=
458
+ function(){return this.dma_command};bd.prototype.dma_write_command=function(a){this.dma_write_command8(a&255);this.dma_write_status(a>>16&255)};bd.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();
459
+ break;default:y(this.current_interface.current_command),this.dma_status&=-2,this.dma_status|=2,this.push_irq()}};bd.prototype.push_irq=function(){0===(this.device_control_reg&2)&&(this.dma_status|=4,this.cpu.device_raise_irq(this.irq))};bd.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;a[10]=this.dma_status;a[11]=this.current_interface===this.master;
460
+ a[12]=this.dma_command;return a};bd.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 X(a,b,c,d){this.channel=a;this.name=a.name+"."+b;this.bus=a.bus;this.channel_nr=a.channel_nr;this.interface_nr=b;this.cpu=a.cpu;this.buffer=null;this.drive_connected=
461
+ 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);this.data32=new Int32Array(this.data.buffer);this.data_end=this.data_length=
462
+ 0;this.current_command=-1;this.last_io_id=this.write_dest=0;this.in_progress_io_ids=new Map;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);Object.seal(this)}X.prototype.has_disk=function(){return!!this.buffer};X.prototype.eject=function(){this.is_atapi&&this.buffer&&(this.medium_changed=!0,this.buffer=null,this.status_reg=89,this.error_reg=96,this.push_irq())};X.prototype.set_cdrom=function(a){this.is_atapi&&
463
+ a&&(this.set_disk_buffer(a),this.medium_changed=!0)};X.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)&&(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;
464
+ this.cylinder_count!==(this.cylinder_count|0)&&(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)|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&
465
+ 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()}};X.prototype.device_reset=function(){this.is_atapi?(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()};X.prototype.push_irq=function(){this.channel.push_irq()};X.prototype.ata_abort_command=
466
+ function(){this.error_reg=4;this.status_reg=65;this.push_irq()};X.prototype.capture_regs=function(){return`ST=${y(this.status_reg&255)} ER=${y(this.error_reg&255)} `+`SC=${y(this.sector_count_reg&255)} LL=${y(this.lba_low_reg&255)} `+`LM=${y(this.lba_mid_reg&255)} LH=${y(this.lba_high_reg&255)} `+`FE=${y(this.features_reg&255)}`};X.prototype.ata_command=function(a){if(this.drive_connected||144===a)switch(this.current_command=a,this.error_reg=0,a){case 8:this.data_length=this.data_end=this.data_pointer=
467
+ 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:a=this.sector_count-1;this.lba_low_reg=a&255;this.lba_mid_reg=a>>8&255;this.lba_high_reg=a>>16&255;this.device_reg=this.device_reg&240|a>>24&15;this.status_reg=80;this.push_irq();break;case 39:a=this.sector_count-1;this.lba_low_reg=a&255;this.lba_mid_reg=a>>8&255;this.lba_high_reg=a>>16&255;this.lba_low_reg|=a>>24<<8&65280;this.status_reg=80;this.push_irq();break;case 32:this.is_atapi?
468
+ (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:this.is_atapi?this.ata_abort_command():this.ata_read_sectors(a);break;case 48:case 52:case 57:case 197: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=
469
+ 1,this.channel.slave.push_irq());break;case 145:this.status_reg=80;this.push_irq();break;case 160:this.is_atapi?(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:y(this.sector_count_reg&255);this.sectors_per_drq=this.sector_count_reg&255;this.status_reg=80;this.push_irq();break;case 200:case 37:this.ata_read_sectors_dma(a);
470
+ break;case 202:case 53: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?
471
+ (this.lba_mid_reg=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;case 240:y(a);this.capture_regs();this.ata_abort_command();break;default:y(a),this.capture_regs(),this.ata_abort_command()}else y(a)};
472
+ X.prototype.atapi_handle=function(){var a=this.data[0],b=$c[a]?$c[a].flags:0;this.data_pointer=0;this.current_atapi_command=a;3!==a&&(this.atapi_add_sense=this.atapi_sense_key=0);if(!this.buffer&&b&1)this.atapi_check_condition_response(2,58),this.push_irq();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=
473
+ 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:a=this.data[4];this.status_reg=88;y(this.data[1],2);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_reg=88;break;case 30:this.data_allocate(0);
474
+ this.data_end=this.data_length;this.status_reg=80;break;case 37:a=this.sector_count-1;this.data_set(new Uint8Array([a>>24&255,a>>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_reg=88;break;case 40:case 168:this.features_reg&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;this.status_reg=88;break;case 67:a=this.data[8]|this.data[7]<<
475
+ 8;b=this.data[9]>>6;y(b,2);y(this.data[6]);this.data_allocate(a);this.data_end=this.data_length;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]));this.status_reg=88;break;case 70:a=Math.min(this.data[8]|this.data[7]<<8,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]=
476
+ a-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:this.atapi_check_condition_response(5,36);break;case 90:a=this.data[8]|this.data[7]<<8;b=this.data[2];y(b);42===b&&this.data_allocate(Math.min(30,a));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]=1;this.status_reg=88;break;case 27:a=
477
+ this.data[4]&3;y(this.data[1]&1);y(a);this.buffer&&2===a&&(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:this.atapi_check_condition_response(5,36);break;case 190:this.data_allocate(0);this.data_end=this.data_length;this.status_reg=80;break;default:y(this.data[0]),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&
478
+ 128)&&0===this.data_length&&(this.sector_count_reg|=1,this.status_reg&=-9)}};X.prototype.atapi_check_condition_response=function(a,b){this.data_allocate(0);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};X.prototype.do_write=function(){this.status_reg=80;var a=this.data.subarray(0,this.data_length);this.ata_advance(this.current_command,this.data_length/512);this.push_irq();this.buffer.set(this.write_dest,
479
+ a,function(){});this.report_write(this.data_length)};X.prototype.atapi_read=function(a){var b=a[2]<<24|a[3]<<16|a[4]<<8|a[5];a=168===a[0]?a[6]<<24|a[7]<<16|a[8]<<8|a[9]:a[7]<<8|a[8];var c=(a>>>0)*this.sector_size;b*=this.sector_size;this.data_length=0;var d=this.lba_high_reg<<8&65280|this.lba_mid_reg&255;this.lba_mid_reg=this.lba_high_reg=0;65535===d&&d--;d>c&&(d=c);this.buffer?b>=this.buffer.byteLength?(wa(!1,this.name+": CD read: Outside of disk end="+y(b+c)+" size="+y(this.buffer.byteLength),
480
+ 32768),this.status_reg=255,this.push_irq()):0===c?(this.status_reg=80,this.data_pointer=0):(c=Math.min(c,this.buffer.byteLength-b),this.status_reg=208,this.report_read_start(),this.read_buffer(b,c,e=>{this.data_set(e);this.status_reg=88;this.sector_count_reg=this.sector_count_reg&-8|2;this.push_irq();this.data_end=d&=-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(c)})):(this.status_reg=
481
+ 255,this.error_reg=65,this.push_irq())};X.prototype.atapi_read_dma=function(a){var b=a[2]<<24|a[3]<<16|a[4]<<8|a[5],c=168===a[0]?a[6]<<24|a[7]<<16|a[8]<<8|a[9]:a[7]<<8|a[8];c>>>=0;a=a[1];var d=c*this.sector_size,e=b*this.sector_size;va(this.name+": CD read DMA lba="+y(b)+" lbacount="+y(c)+" bytecount="+y(d)+" flags="+y(a),32768);e>=this.buffer.byteLength?(wa(!1,this.name+": CD read: Outside of disk end="+y(e+d)+" size="+y(this.buffer.byteLength),32768),this.status_reg=255,this.push_irq()):(this.status_reg=
482
+ 208,this.report_read_start(),this.read_buffer(e,d,f=>{this.report_read_end(d);this.status_reg=88;this.sector_count_reg=this.sector_count_reg&-8|2;this.data_set(f);this.do_atapi_dma()}))};X.prototype.do_atapi_dma=function(){if(0!==(this.channel.dma_status&1)&&0!==(this.status_reg&8)){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)),d);b+=e;a+=8;if(b>=
483
+ 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()}};X.prototype.read_data=function(a){if(this.data_pointer<this.data_end){y(this.data_pointer);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&&this.read_end();return b}this.data_pointer+=a;return 0};X.prototype.read_end=function(){if(160===
484
+ 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-this.data_end>>8&255,this.data_end=this.data_length):this.data_end+=a}else this.error_reg=0,this.data_pointer>=
485
+ this.data_length?this.status_reg=80:(a=41===this.current_command||196===this.current_command?Math.min(this.sectors_per_drq,(this.data_length-this.data_end)/512):1,this.ata_advance(this.current_command,a),this.data_end+=512*a,this.status_reg=88,this.push_irq())};X.prototype.write_data_port=function(a,b){this.data_pointer>=this.data_end?(y(a),y(this.data_end),y(this.data_pointer)):(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>>>
486
+ 2]=a,this.data_pointer+=4),this.data_pointer===this.data_end&&this.write_end())};X.prototype.write_data_port8=function(a){this.write_data_port(a,1)};X.prototype.write_data_port16=function(a){this.write_data_port(a,2)};X.prototype.write_data_port32=function(a){this.write_data_port(a,4)};X.prototype.write_end=function(){160===this.current_command?this.atapi_handle():this.data_pointer>=this.data_length?this.do_write():(y(this.current_command),this.status_reg=88,this.data_end+=512,this.push_irq())};X.prototype.ata_advance=
487
+ function(a,b){this.sector_count_reg-=b;36===a||41===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&
488
+ 15,this.lba_low_reg=a%this.sectors_per_track+1&255,this.get_chs())};X.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?(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,this.sectors_per_track));
489
+ this.push_irq();this.report_read_end(e)}))};X.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?(this.status_reg=255,this.push_irq()):(this.status_reg=88,this.channel.dma_status|=1)};X.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;a*=this.sector_size;this.report_read_start();this.read_buffer(a,c,d=>{var e=
490
+ this.channel.prdt_addr,f=0;do{var g=this.cpu.read32s(e),h=this.cpu.read16(e+4),l=this.cpu.read8(e+7)&128;h||(h=65536);this.cpu.write_blob(d.subarray(f,f+h),g);f+=h;e+=8}while(!l);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()})};X.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;c*=this.sector_size;b*=this.sector_size;b+c>this.buffer.byteLength?
491
+ (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)};X.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>this.buffer.byteLength?(this.status_reg=255,this.push_irq()):(this.status_reg=88,this.channel.dma_status|=1)};X.prototype.do_ata_write_sectors_dma=function(){var a=53===this.current_command,b=this.get_count(a),
492
+ 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 g=this.cpu.read32s(d),h=this.cpu.read16(d+4),l=this.cpu.read8(d+7)&128;h||(h=65536);g=this.cpu.mem8.subarray(g,g+h);f.set(g,e);e+=h;d+=8}while(!l);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)};X.prototype.get_chs=function(){return((this.lba_mid_reg&
493
+ 255|this.lba_high_reg<<8&65280)*this.head_count+this.head)*this.sectors_per_track+(this.lba_low_reg&255)-1};X.prototype.get_lba28=function(){return this.lba_low_reg&255|this.lba_mid_reg<<8&65280|this.lba_high_reg<<16&16711680|(this.head&15)<<24};X.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};X.prototype.get_lba=function(a){return a?this.get_lba48():this.is_lba?this.get_lba28():this.get_chs()};
494
+ X.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};X.prototype.create_identify_packet=function(){const a=Math.min(16383,this.cylinder_count),b=(g,h,l,m)=>{h<<=1;var n=l<<1;l=h+n;g.fill(32,h,n);for(n=0;n<m.length&&h<l;n++)n&1?(g[h]=m.charCodeAt(n),h+=2):g[h+1]=m.charCodeAt(n)},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);
495
+ 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&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&
496
+ 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>>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,
497
+ 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=512};X.prototype.data_allocate=function(a){this.data_allocate_noclear(a);this.data32.fill(0,0,a+3>>2)};X.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=
498
+ 0};X.prototype.data_set=function(a){this.data_allocate_noclear(a.length);this.data.set(a)};X.prototype.report_read_start=function(){this.bus.send("ide-read-start")};X.prototype.report_read_end=function(a){this.bus.send("ide-read-end",[this.channel_nr,a,a/this.sector_size|0])};X.prototype.report_write=function(a){this.bus.send("ide-write-end",[this.channel_nr,a,a/this.sector_size|0])};X.prototype.read_buffer=function(a,b,c){const d=this.last_io_id++,e=new AbortController;this.in_progress_io_ids.set(d,
499
+ e);this.buffer.get(a,b,f=>{this.cancelled_io_ids.delete(d)?this.in_progress_io_ids.has(d):(this.in_progress_io_ids.delete(d),c(f))},{signal:e.signal})};X.prototype.cancel_io_operations=function(){for(const [a,b]of this.in_progress_io_ids)this.cancelled_io_ids.add(a),b.abort();this.in_progress_io_ids.clear()};X.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]=
500
+ 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;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};X.prototype.set_state=function(a){this.sector_count_reg=
501
+ 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=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=
502
+ 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 cd(a,b,c,d=1500){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()|0,255*Math.random()|0,255*Math.random()|0]);this.bus.send("net"+this.id+"-mac",Ic(this.mac));b=[];for(c=0;c<this.pairs;++c)b.push({size_supported:1024,
503
+ notify_offset:0}),b.push({size_supported:1024,notify_offset:1});b.push({size_supported:16,notify_offset:2});this.virtio=new Lc(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:[()=>{},e=>{const f=this.virtio.queues[e];for(;f.has_request();){const g=f.pop_request(),h=new Uint8Array(g.length_readable);g.get_next_blob(h);this.bus.send("net"+
504
+ this.id+"-send",h.subarray(12));this.bus.send("eth-transmit-end",[h.length-12]);this.virtio.queues[e].push_reply(g)}this.virtio.queues[e].flush_replies()},e=>{if(e===2*this.pairs)for(var f=this.virtio.queues[e];f.has_request();){const g=f.pop_request(),h=new Uint8Array(g.length_readable);g.get_next_blob(h);const l=L(["b","b"],h,{offset:0});switch(l[0]<<8|l[1]){case 1024:L(["h"],h,{offset:2});this.Send(e,g,new Uint8Array([0]));break;case 257:this.mac=h.subarray(2,8);this.Send(e,g,new Uint8Array([0]));
505
+ this.bus.send("net"+this.id+"-mac",Ic(this.mac));break;default:this.Send(e,g,new Uint8Array([1]));return}}}]},isr_status:{initial_port:50944},device_specific:{initial_port:50688,struct:[0,1,2,3,4,5].map((e,f)=>({bytes:1,name:"mac_"+f,read:()=>this.mac[f],write:()=>{}})).concat([{bytes:2,name:"status",read:()=>this.status,write:()=>{}},{bytes:2,name:"max_pairs",read:()=>this.pairs,write:()=>{}},{bytes:2,name:"mtu",read:()=>d,write:()=>{}}])}});this.bus.register("net"+this.id+"-receive",e=>{this.bus.send("eth-receive-end",
506
+ [e.length]);const f=new Uint8Array(12+e.byteLength);(new DataView(f.buffer,f.byteOffset,f.byteLength)).setInt16(10,1);f.set(e,12);e=this.virtio.queues[0];e.has_request()?(e=e.pop_request(),e.set_next_blob(f),this.virtio.queues[0].push_reply(e),this.virtio.queues[0].flush_replies()):console.log("No buffer to write into!")},this)}cd.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.id;a[2]=this.mac;return a};cd.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.id=a[1];
507
+ this.preserve_mac_from_state_image&&(this.mac=a[2],this.bus.send("net"+this.id+"-mac",Ic(this.mac)))};cd.prototype.reset=function(){this.virtio.reset()};cd.prototype.Send=function(a,b,c){b.set_next_blob(c);this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};cd.prototype.Ack=function(a,b){this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};const dd=Uint32Array.from([655360,655360,720896,753664]),ed=Uint32Array.from([131072,65536,32768,32768]);function Y(a,
508
+ 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=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=
509
+ 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=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:ja(this.vga_memory_size);this.pci_space=
510
+ [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,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=
511
+ 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=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;
512
+ 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,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,
513
+ 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,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,
514
+ 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,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(){return 0});b.register_read(986,
515
+ this,this.port3DA_read);b.register_read(954,this,this.port3DA_read);this.dispi_enable_value=this.dispi_index=0;b.register_write(462,this,void 0,this.port1CE_write);b.register_read(462,this,void 0,this.port1CE_read);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=k(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=
516
+ 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,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)}
517
+ Y.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;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;
518
+ 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;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;
519
+ 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;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;
520
+ 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]=this.dac_mask;a[63]=this.character_map_select;a[64]=this.font_page_ab_enabled;return a};Y.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=
521
+ 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=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=
522
+ 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=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=
523
+ 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=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]?
524
+ 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=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());
525
+ this.complete_redraw()};Y.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-=dd[b];if(0>a||a>=ed[b])return y(a>>>0),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&
526
+ 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]};Y.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>>
527
+ 2&3;a-=dd[c];0>a||a>=ed[c]?(y(a>>>0),y(b)):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)}};Y.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 g=this.apply_feed(b);g=this.apply_setreset(g,f);
528
+ g=this.apply_logical(g,this.latch_dword);g=this.apply_bitmask(g,d);break;case 1:g=this.latch_dword;break;case 2:g=this.apply_expand(b);g=this.apply_logical(g,this.latch_dword);g=this.apply_bitmask(g,d);break;case 3:b=this.apply_rotate(b),d&=this.apply_feed(b),g=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]=g>>0&255);b&2&&(this.plane1[a]=g>>8&255);b&4&&(this.plane2[a]=g>>16&
529
+ 255);b&8&&(this.plane3[a]=g>>24&255);a=this.vga_addr_to_pixel(a);this.partial_replot(a,a+7)};Y.prototype.apply_feed=function(a){return a|a<<8|a<<16|a<<24};Y.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};Y.prototype.apply_rotate=function(a){return(a|a<<8)>>>(this.planar_rotate_reg&7)&255};Y.prototype.apply_setreset=function(a,b){var c=this.apply_expand(this.planar_setreset);return(a|b&c)&(~b|c)};Y.prototype.apply_logical=function(a,b){switch(this.planar_rotate_reg&
530
+ 24){case 8:return a&b;case 16:return a|b;case 24:return a^b}return a};Y.prototype.apply_bitmask=function(a,b){return b&a|~b&this.latch_dword};Y.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,g=this.screen.FLAG_FONT_PAGE_B;let h=this.start_address<<1;for(let l=0;l<this.max_rows;l++){l===a&&(h=0);for(let m=
531
+ 0;m<this.max_cols;m++){const n=this.vga_memory[h],p=this.vga_memory[h|1],q=(c&&p&128?f:0)|(!this.font_page_ab_enabled||p&8?0:g);this.bus.send("screen-put-char",[l,m,n]);this.screen.put_char(l,m,n,q,this.vga256_palette[this.dac_mask&this.dac_map[p>>4&e]],this.vga256_palette[this.dac_mask&this.dac_map[p&d]]);h+=2}h+=b}};Y.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;
532
+ 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;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 g=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&
533
+ this.dac_map[e&g]])}};Y.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);this.screen.update_cursor(b,a)};Y.prototype.complete_redraw=function(){this.graphical_mode?this.svga_enabled?this.cpu.svga_mark_dirty():(this.diff_addr_min=
534
+ 0,this.diff_addr_max=524288):this.text_mode_redraw()};Y.prototype.complete_replot=function(){this.graphical_mode&&!this.svga_enabled&&(this.diff_plot_min=0,this.diff_plot_max=524288,this.complete_redraw())};Y.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)};Y.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)};Y.prototype.reset_diffs=
535
+ 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};Y.prototype.destroy=function(){};Y.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};Y.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>>>
536
+ 6};Y.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};Y.prototype.scan_line_to_screen_row=function(a){this.max_scan_line&128&&(a>>>=1);a=Math.ceil(a/(1+(this.max_scan_line&
537
+ 31)));this.crtc_mode&1||(a<<=1);this.crtc_mode&2||(a<<=1);return a};Y.prototype.set_size_text=function(a,b){this.max_cols=a;this.max_rows=b;this.screen.set_size_text(a,b);this.bus.send("screen-set-size",[a,b,0])};Y.prototype.set_size_graphical=function(a,b,c,d,e){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=a;this.screen_height=b;this.virtual_width=c;this.virtual_height=d;if("undefined"!==typeof ImageData){const f=
538
+ c*d,g=this.cpu.svga_allocate_dest_buffer(f)>>>0;this.dest_buffet_offset=g;this.image_data=new ImageData(new Uint8ClampedArray(this.cpu.wasm_memory.buffer,g,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])}};Y.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<<=
539
+ 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=ed[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)}};Y.prototype.update_layers=function(){this.graphical_mode||this.text_mode_redraw();if(this.svga_enabled)this.layers=
540
+ [];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);d=Math.min(d,this.screen_height);var f=this.screen_height-d;this.layers=[];e=-e;for(var g=0;e<this.screen_width;e+=
541
+ this.virtual_width,g++)this.layers.push({image_data:this.image_data,screen_x:e,screen_y:0,buffer_x:0,buffer_y:a+g,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(g=0;e<this.screen_width;e+=this.virtual_width,g++)this.layers.push({image_data:this.image_data,screen_x:e,screen_y:d,buffer_x:0,buffer_y:g,buffer_width:this.virtual_width,buffer_height:f})}};Y.prototype.update_vertical_retrace=function(){this.port_3DA_value|=8;this.start_address_latched!==
542
+ this.start_address&&(this.start_address_latched=this.start_address,this.update_layers())};Y.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)};Y.prototype.port3C0_write=function(a){if(-1===this.attribute_controller_index)y(a),this.attribute_controller_index=a&31,y(this.attribute_controller_index),this.palette_source!==
543
+ (a&32)&&(this.palette_source=a&32,this.update_layers());else{if(16>this.attribute_controller_index)y(this.attribute_controller_index),y(a),this.dac_map[this.attribute_controller_index]=a,this.attribute_mode&64||this.complete_redraw();else switch(this.attribute_controller_index){case 16:y(a);if(this.attribute_mode!==a){var b=this.attribute_mode;this.attribute_mode=a;!this.svga_enabled||this.dispi_enable_value&1||(this.svga_enabled=!1,this.svga_bank_offset=0);const c=0!==(a&1);this.svga_enabled||this.graphical_mode===
544
+ 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:y(a);this.color_plane_enable!==a&&(this.color_plane_enable=a,this.complete_redraw());break;case 19:y(a);this.horizontal_panning!==a&&(this.horizontal_panning=a&15,this.update_layers());break;case 20:y(a);this.color_select!==a&&(this.color_select=a,this.complete_redraw());break;default:y(this.attribute_controller_index),
545
+ y(a)}this.attribute_controller_index=-1}};Y.prototype.port3C0_read=function(){return(this.attribute_controller_index|this.palette_source)&255};Y.prototype.port3C0_read16=function(){return this.port3C0_read()|this.port3C1_read()<<8&65280};Y.prototype.port3C1_read=function(){if(16>this.attribute_controller_index)return y(this.attribute_controller_index),y(this.dac_map[this.attribute_controller_index]),this.dac_map[this.attribute_controller_index]&255;switch(this.attribute_controller_index){case 16:return y(this.attribute_mode),
546
+ this.attribute_mode;case 18:return y(this.color_plane_enable),this.color_plane_enable;case 19:return y(this.horizontal_panning),this.horizontal_panning;case 20:return y(this.color_select),this.color_select;default:y(this.attribute_controller_index)}return 255};Y.prototype.port3C2_write=function(a){y(a);this.miscellaneous_output_register=a};Y.prototype.port3C4_write=function(a){this.sequencer_index=a};Y.prototype.port3C4_read=function(){return this.sequencer_index};Y.prototype.port3C5_write=function(a){switch(this.sequencer_index){case 1:y(a);
547
+ var b=this.clocking_mode;this.clocking_mode=a;(b^a)&32&&this.update_layers();this.set_font_bitmap(!1);break;case 2:y(a);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:y(a);b=this.character_map_select;this.character_map_select=a;this.graphical_mode||b===a||this.set_font_page();break;case 4:y(a);this.sequencer_memory_mode=a;break;default:y(this.sequencer_index),y(a)}};Y.prototype.port3C5_read=function(){y(this.sequencer_index);
548
+ 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};Y.prototype.port3C6_write=function(a){this.dac_mask!==a&&(this.dac_mask=a,this.complete_redraw())};Y.prototype.port3C6_read=function(){return this.dac_mask};Y.prototype.port3C7_write=function(a){y(a);this.dac_color_index_read=3*a;this.dac_state&=0};Y.prototype.port3C7_read=function(){return this.dac_state};
549
+ Y.prototype.port3C8_write=function(a){this.dac_color_index_write=3*a;this.dac_state|=3};Y.prototype.port3C8_read=function(){return this.dac_color_index_write/3&255};Y.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,y(b),y(d));this.vga256_palette[b]!==d&&(this.vga256_palette[b]=d,this.complete_redraw());
550
+ this.dac_color_index_write++};Y.prototype.port3C9_read=function(){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};Y.prototype.port3CC_read=function(){return this.miscellaneous_output_register};Y.prototype.port3CE_write=function(a){this.graphics_index=a};Y.prototype.port3CE_read=function(){return this.graphics_index};Y.prototype.port3CF_write=function(a){switch(this.graphics_index){case 0:this.planar_setreset=
551
+ a;y(a);break;case 1:this.planar_setreset_enable=a;y(a);break;case 2:this.color_compare=a;y(a);break;case 3:this.planar_rotate_reg=a;y(a);break;case 4:this.plane_read=a;y(a);break;case 5:var b=this.planar_mode;this.planar_mode=a;y(a);(b^a)&96&&this.complete_replot();break;case 6:y(a);this.miscellaneous_graphics_register!==a&&(this.miscellaneous_graphics_register=a,this.update_vga_size());break;case 7:this.color_dont_care=a;y(a);break;case 8:this.planar_bitmap=a;y(a);break;default:y(this.graphics_index),
552
+ y(a)}};Y.prototype.port3CF_read=function(){y(this.graphics_index);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};Y.prototype.port3D4_write=function(a){this.index_crtc=a};Y.prototype.port3D4_write16=
553
+ function(a){this.port3D4_write(a&255);this.port3D5_write(a>>8&255)};Y.prototype.port3D4_read=function(){return this.index_crtc};Y.prototype.port3D5_write=function(a){switch(this.index_crtc){case 1:y(a);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:y(a);var b=this.vertical_display_enable_end;this.vertical_display_enable_end&=255;this.vertical_display_enable_end=
554
+ 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:y(a);this.preset_row_scan=a;this.update_layers();break;case 9:y(a);var c=this.max_scan_line;this.max_scan_line=a;this.line_compare=this.line_compare&511|a<<3&512;
555
+ 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:y(a);this.cursor_scanline_start=a;this.update_cursor_scanline();break;case 11:y(a);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,
556
+ this.update_layers(),~this.crtc_mode&3&&this.complete_replot());y(a);y(this.start_address,4);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());y(a);y(this.start_address,4);break;case 14:y(a);this.cursor_address=this.cursor_address&255|a<<8;this.update_cursor();break;case 15:y(a);this.cursor_address=this.cursor_address&65280|a;this.update_cursor();break;case 18:y(a);(this.vertical_display_enable_end&
557
+ 255)!==a&&(this.vertical_display_enable_end=this.vertical_display_enable_end&768|a,this.update_vga_size());break;case 19:y(a);this.offset_register!==a&&(this.offset_register=a,this.update_vga_size(),~this.crtc_mode&3&&this.complete_replot());break;case 20:y(a);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:y(a);(this.vertical_blank_start&255)!==a&&(this.vertical_blank_start=
558
+ this.vertical_blank_start&768|a,this.update_vga_size());break;case 23:y(a);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:y(a);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),y(this.index_crtc),y(a)}};Y.prototype.port3D5_write16=function(a){y(a,4);this.port3D5_write(a&255)};Y.prototype.port3D5_read=function(){y(this.index_crtc);
559
+ 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>>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>>
560
+ 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;case 24:return this.line_compare&255}return this.index_crtc<this.crtc.length?this.crtc[this.index_crtc]:0};Y.prototype.port3D5_read16=function(){return this.port3D5_read()};Y.prototype.port3DA_read=function(){var a=this.port_3DA_value;this.graphical_mode?
561
+ (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};Y.prototype.port1CE_read=function(){return this.dispi_index};Y.prototype.port1CE_write=function(a){this.dispi_index=a};Y.prototype.port1CF_write=function(a){y(this.dispi_index);y(a);const b=this.svga_enabled;switch(this.dispi_index){case 0:45248<=a&&45253>=a?this.svga_version=a:y(a);break;case 1:this.svga_width=a;2560<this.svga_width&&
562
+ (this.svga_width=2560);break;case 2:this.svga_height=a;1600<this.svga_height&&(this.svga_height=1600);break;case 3:this.svga_bpp=a;break;case 4:this.dispi_enable_value=a;!(a&1)&&this.svga_enabled&&this.cpu.flags[0]&131072||(this.svga_enabled=1===(a&1))&&0===(a&128)&&this.svga_memory.fill(0);break;case 5:y(a<<16);this.svga_bank_offset=a<<16;break;case 8:y(a);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());
563
+ break;case 9:y(a*this.svga_width);y(a);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:y(this.dispi_index)}!this.svga_enabled||this.svga_width&&this.svga_height||(this.svga_enabled=!1);this.svga_enabled&&4===this.dispi_index&&(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,
564
+ this.svga_height,this.svga_width,this.svga_height,this.svga_bpp));b&&!this.svga_enabled&&(this.graphical_mode=a=0!==(this.attribute_mode&1),this.screen.set_mode(a),this.update_vga_size(),this.set_font_bitmap(!1),this.complete_redraw());this.svga_enabled||(this.svga_bank_offset=0);this.update_layers()};Y.prototype.port1CF_read=function(){y(this.dispi_index);return this.svga_register_read(this.dispi_index)};Y.prototype.svga_register_read=function(a){switch(a){case 0:return this.svga_version;case 1:return this.dispi_enable_value&
565
+ 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>>>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:y(this.dispi_index)}return 255};Y.prototype.vga_replot=function(){for(var a=this.diff_plot_min&-16,b=Math.min(this.diff_plot_max|
566
+ 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 g=a>>>c;if(d){var h=a/this.virtual_width|0,l=a-this.virtual_width*h;switch(d){case 1:g=(h&1)<<13;h>>>=1;break;case 2:g=(h&1)<<14;h>>>=1;break;case 3:g=(h&3)<<13,h>>>=2}g|=(h*this.virtual_width+l>>>c)+this.start_address}h=this.plane0[g];l=this.plane1[g];var m=this.plane2[g],n=this.plane3[g];g=new Uint8Array(8);switch(e){case 0:h<<=0;l<<=1;m<<=2;n<<=3;for(var p=7;0<=p;p--)g[7-p]=h>>
567
+ p&1|l>>p&2|m>>p&4|n>>p&8;break;case 32:g[0]=h>>6&3|m>>4&12;g[1]=h>>4&3|m>>2&12;g[2]=h>>2&3|m>>0&12;g[3]=h>>0&3|m<<2&12;g[4]=l>>6&3|n>>4&12;g[5]=l>>4&3|n>>2&12;g[6]=l>>2&3|n>>0&12;g[7]=l>>0&3|n<<2&12;break;case 64:case 96:g[0]=h>>4&15,g[1]=h>>0&15,g[2]=l>>4&15,g[3]=l>>0&15,g[4]=m>>4&15,g[5]=m>>0&15,g[6]=n>>4&15,g[7]=n>>0&15}if(f)for(h=p=0;4>p;p++,a++,h+=2)this.pixel_buffer[a]=g[h]<<4|g[h+1];else for(p=0;8>p;p++,a++)this.pixel_buffer[a]=g[p]}};Y.prototype.vga_redraw=function(){var a=this.diff_addr_min,
568
+ 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=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],
569
+ c[a]=f&65280|f<<16|f>>16|4278190080};Y.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,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,
570
+ 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]=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|
571
+ 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-a}]))}else this.vga_replot(),this.vga_redraw(),this.screen.update_buffer(this.layers);this.reset_diffs()}this.update_vertical_retrace()};Y.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,
572
+ !c&&!(this.clocking_mode&1),c,!!(this.attribute_mode&4),this.plane2,a)}};Y.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)>>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 fd="SWAP_IN SWAP_OUT MAJFLT MINFLT MEMFREE MEMTOT AVAIL CACHES HTLB_PGALLOC HTLB_PGFAIL".split(" ");function gd(a,b){this.bus=b;this.zeroed=
573
+ this.fp_cmd=this.actual=this.num_pages=0;this.virtio=new Lc(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},{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:()=>{}},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);
574
+ 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];if(d.has_request()){d=d.pop_request();const e=new Uint8Array(d.length_readable);d.get_next_blob(e);let f={};for(let g=0;g<d.length_readable;g+=10){let [h,l]=L(["h","d"],e,{offset:g});f[fd[h]]=l}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();
575
+ if(0<f.length_readable){var e=new Uint8Array(f.length_readable);f.get_next_blob(e);[e]=L(["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 g=f.write_buffers[e];this.zeroed+=g.len;this.virtio.cpu.zero_memory(g.addr_low,g.len)}this.virtio.queues[c].push_reply(f)}this.virtio.queues[c].flush_replies()}]},isr_status:{initial_port:55040},
576
+ device_specific:{initial_port:54784,struct:[{bytes:4,name:"num_pages",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:()=>{}}]}})}gd.prototype.Inflate=function(a){this.num_pages+=a;this.virtio.notify_config_changes()};gd.prototype.Deflate=function(a){this.num_pages-=a;this.virtio.notify_config_changes()};gd.prototype.Cleanup=function(a){this.fp_cmd=2;this.free_cb=a;this.zeroed=0;this.virtio.notify_config_changes()};
577
+ gd.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.num_pages;a[2]=this.actual;return a};gd.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.num_pages=a[1];this.actual=a[2]};gd.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()};gd.prototype.Reset=function(){};function hd(a,b,c,d){var e=new Uint8Array(b);const f=new Uint16Array(b);
578
+ var g=new Uint32Array(b),h=e[497]||4,l=f[255];if(43605!==l)y(l);else if(l=f[257]|f[258]<<16,1400005704!==l)y(l);else{l=f[259];var m=e[529],n=f[283],p=g[139],q=g[140],r=e[565],x=518<=l?g[142]:255,E=g[146],z=g[147],u=g[150],K=g[151],v=g[152];y(l);y(m);y(n);y(g[133]);y(p);y(q);y(r);y(x);y(E);y(z);y(K);y(u);y(v);e[528]=255;e[529]=m&-97|128;f[274]=56832;f[253]=65535;y(56832);d+="\x00";y(581632);g[138]=581632;for(e=0;e<d.length;e++)a[581632+e]=d.charCodeAt(e);h=512*(h+1);y(h);d=new Uint8Array(b,0,h);b=
579
+ new Uint8Array(b,h);e=h=0;c&&(h=67108864,e=c.byteLength,a.set(new Uint8Array(c),h));g[134]=h;g[135]=e;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;g=a[c]=0;for(b=0;b<a.length;b++)g+=a[b];a[c]=-g;return{name:"genroms/kernel.bin",
580
+ data:a}}}function R(a,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=k(Uint32Array,b,812,1);this.mem8=new Uint8Array(0);this.mem32s=new Int32Array(this.mem8.buffer);this.segment_is_null=k(Uint8Array,b,724,8);this.segment_offsets=k(Int32Array,b,736,8);this.segment_limits=k(Uint32Array,b,768,8);this.segment_access_bytes=k(Uint8Array,b,512,8);this.protected_mode=k(Int32Array,b,800,1);this.idtr_size=k(Int32Array,
581
+ b,564,1);this.idtr_offset=k(Int32Array,b,568,1);this.gdtr_size=k(Int32Array,b,572,1);this.gdtr_offset=k(Int32Array,b,576,1);this.tss_size_32=k(Int32Array,b,1128,1);this.page_fault=k(Uint32Array,b,540,8);this.cr=k(Int32Array,b,580,8);this.cpl=k(Uint8Array,b,612,1);this.is_32=k(Int32Array,b,804,1);this.stack_size_32=k(Int32Array,b,808,1);this.in_hlt=k(Uint8Array,b,616,1);this.last_virt_eip=k(Int32Array,b,620,1);this.eip_phys=k(Int32Array,b,624,1);this.sysenter_cs=k(Int32Array,b,636,1);this.sysenter_esp=
582
+ k(Int32Array,b,640,1);this.sysenter_eip=k(Int32Array,b,644,1);this.prefixes=k(Int32Array,b,648,1);this.flags=k(Int32Array,b,120,1);this.flags_changed=k(Int32Array,b,100,1);this.last_op_size=k(Int32Array,b,96,1);this.last_op1=k(Int32Array,b,104,1);this.last_result=k(Int32Array,b,112,1);this.current_tsc=k(Uint32Array,b,960,2);this.devices={};this.instruction_pointer=k(Int32Array,b,556,1);this.previous_ip=k(Int32Array,b,560,1);this.apic_enabled=k(Uint8Array,b,548,1);this.acpi_enabled=k(Uint8Array,b,
583
+ 552,1);this.memory_map_read8=[];this.memory_map_write8=[];this.memory_map_read32=[];this.memory_map_write32=[];this.bios={main:null,vga:null};this.instruction_counter=k(Uint32Array,b,664,1);this.reg32=k(Int32Array,b,64,8);this.fpu_st=k(Int32Array,b,1152,32);this.fpu_stack_empty=k(Uint8Array,b,816,1);this.fpu_stack_empty[0]=255;this.fpu_stack_ptr=k(Uint8Array,b,1032,1);this.fpu_stack_ptr[0]=0;this.fpu_control_word=k(Uint16Array,b,1036,1);this.fpu_control_word[0]=895;this.fpu_status_word=k(Uint16Array,
584
+ b,1040,1);this.fpu_status_word[0]=0;this.fpu_ip=k(Int32Array,b,1048,1);this.fpu_ip[0]=0;this.fpu_ip_selector=k(Int32Array,b,1052,1);this.fpu_ip_selector[0]=0;this.fpu_opcode=k(Int32Array,b,1044,1);this.fpu_opcode[0]=0;this.fpu_dp=k(Int32Array,b,1056,1);this.fpu_dp[0]=0;this.fpu_dp_selector=k(Int32Array,b,1060,1);this.fpu_dp_selector[0]=0;this.reg_xmm32s=k(Int32Array,b,832,32);this.mxcsr=k(Int32Array,b,824,1);this.sreg=k(Uint16Array,b,668,8);this.dreg=k(Int32Array,b,684,8);this.reg_pdpte=k(Int32Array,
585
+ b,968,8);this.svga_dirty_bitmap_min_offset=k(Uint32Array,b,716,1);this.svga_dirty_bitmap_max_offset=k(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)}R.prototype.mmap_read8=function(a){return this.memory_map_read8[a>>>17](a)};R.prototype.mmap_write8=function(a,b){this.memory_map_write8[a>>>17](a,b)};R.prototype.mmap_write16=function(a,b){var c=this.memory_map_write8[a>>>17];c(a,b&255);c(a+1|0,b>>8)};R.prototype.mmap_read32=function(a){return this.memory_map_read32[a>>>
586
+ 17](a)};R.prototype.mmap_write32=function(a,b){this.memory_map_write32[a>>>17](a,b)};R.prototype.mmap_write64=function(a,b,c){var d=this.memory_map_write32[a>>>17];d(a,b);d(a+4,c)};R.prototype.mmap_write128=function(a,b,c,d,e){var f=this.memory_map_write32[a>>>17];f(a,b);f(a+4,c);f(a+8,d);f(a+12,e)};R.prototype.write_blob=function(a,b){a.length&&(this.in_mapped_range(b),this.in_mapped_range(b+a.length-1),this.jit_dirty_cache(b,b+a.length),this.mem8.set(a,b))};R.prototype.read_blob=function(a,b){b&&
587
+ (this.in_mapped_range(a),this.in_mapped_range(a+b-1));return this.mem8.subarray(a,a+b)};R.prototype.clear_opstats=function(){(new Uint8Array(this.wasm_memory.buffer,32768,131072)).fill(0);this.wm.exports.profiler_init()};R.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};R.prototype.wasm_patch=function(){const a=
588
+ 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");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");
589
+ 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");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.device_raise_irq=b("device_raise_irq");
590
+ this.device_lower_irq=b("device_lower_irq");this.apic_timer=b("apic_timer");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=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");
591
+ 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.get_apic_addr=b("get_apic_addr");this.get_ioapic_addr=b("get_ioapic_addr");this.zstd_create_ctx=b("zstd_create_ctx");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")};R.prototype.jit_force_generate=function(a){this.jit_force_generate_unsafe&&this.jit_force_generate_unsafe(a)};
592
+ R.prototype.jit_clear_func=function(a){this.wm.wasm_table.set(a+1024,null)};R.prototype.jit_clear_all_funcs=function(){const a=this.wm.wasm_table;for(let b=0;900>b;b++)a.set(1024+b,null)};R.prototype.get_state=function(){var a=[];a[0]=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];
593
+ 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];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;
594
+ this.store_current_tsc();a[43]=this.current_tsc;a[45]=this.devices.virtio_9p;a[46]=this.get_state_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]=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();
595
+ a[61]=this.devices.sb16;a[62]=this.fw_value;a[63]=this.get_state_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]=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;
596
+ a[81]=this.devices.uart3;a[82]=this.devices.virtio_console;a[83]=this.devices.virtio_net;a[84]=this.devices.virtio_balloon;a[86]=this.last_result;a[87]=this.fpu_status_word;a[88]=this.mxcsr;a[89]=this.devices.vmware;return a};R.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];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]=
597
+ 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};R.prototype.get_state_apic=function(){return new Uint8Array(this.wasm_memory.buffer,this.get_apic_addr(),184)};R.prototype.get_state_ioapic=function(){return new Uint8Array(this.wasm_memory.buffer,this.get_ioapic_addr(),208)};R.prototype.set_state=function(a){this.memory_size[0]=a[0];this.mem8.length!==
598
+ 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]),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)));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]=
599
+ 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];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]);
600
+ 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&&this.devices.virtio_9p.set_state(a[45]);a[46]&&this.set_state_apic(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]);
601
+ this.devices.fdc&&this.devices.fdc.set_state(a[55]);if(a[56]||a[57]){var b=[[void 0,void 0],[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 ad(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&&
602
+ 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]);this.devices.virtio_net&&this.devices.virtio_net.set_state(a[83]);this.devices.virtio_balloon&&
603
+ this.devices.virtio_balloon.set_state(a[84]);this.devices.vmware&&a[89]&&this.devices.vmware.set_state(a[89]);this.fw_value=a[62];a[63]&&this.set_state_ioapic(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];void 0!==a[86]&&(this.last_result=a[86]);void 0!==
604
+ a[87]&&(this.fpu_status_word=a[87]);void 0!==a[88]&&(this.mxcsr=a[88]);b=new na(a[78].buffer);this.unpack_memory(b,a[77]);this.update_state_flags();this.full_clear_tlb();this.jit_clear_cache()};R.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]=
605
+ 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]};R.prototype.set_state_apic=function(a){if(a instanceof Array){const b=new Int32Array(this.wasm_memory.buffer,this.get_apic_addr(),46);b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];b[8]=a[6];b[9]=a[7];b[10]=a[8];b[11]=a[9];b[12]=a[10];b[13]=a[11];b[14]=a[12];b[15]=a[13];b.set(a[15],16);b.set(a[15],24);b.set(a[16],32);b[40]=a[17];b[41]=a[18];b[42]=a[19];
606
+ b[43]=a[20];b[44]=a[21];b[45]=a[22]||65536}else(new Uint8Array(this.wasm_memory.buffer,this.get_apic_addr(),184)).set(a)};R.prototype.set_state_ioapic=function(a){if(a instanceof Array){const b=new Int32Array(this.wasm_memory.buffer,this.get_ioapic_addr(),52);b.set(a[0],0);b.set(a[1],24);b[48]=a[2];b[49]=a[3];b[50]=a[4];b[51]=a[5]}else(new Uint8Array(this.wasm_memory.buffer,this.get_ioapic_addr(),208)).set(a)};R.prototype.pack_memory=function(){var a=this.mem8.length>>12,b=[];for(var c=0;c<a;c++)this.is_memory_zeroed(c<<
607
+ 12,4096)||b.push(c);a=new na(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}};R.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++}};R.prototype.reboot_internal=function(){this.reset_cpu();this.fw_value=[];this.devices.virtio_9p&&
608
+ 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()};R.prototype.reset_memory=function(){this.mem8.fill(0)};R.prototype.create_memory=function(a,b){a<b?a=b:0>(a|0)&&(a=Math.pow(2,31)-131072);a=(a-1|131071)+1|0;console.assert(0===this.memory_size[0],"Expected uninitialised memory");this.memory_size[0]=a;b=this.allocate_memory(a);this.mem8=
609
+ k(Uint8Array,this.wasm_memory,b,a);this.mem32s=k(Uint32Array,this.wasm_memory,b,a>>2)};R.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 Da(this);this.io=c;this.bios.main=a.bios;this.bios.vga=a.vga_bios;this.load_bios();if(a.bzimage){const e=hd(this.mem8,a.bzimage,a.initrd,a.cmdline||"");e&&this.option_roms.push(e)}c.register_read(179,
610
+ this,function(){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(){return this.fw_pointer<this.fw_value.length?this.fw_value[this.fw_pointer++]:0});c.register_write(1296,this,void 0,function(e){function f(l){return new Uint8Array(Int32Array.of(l).buffer)}function g(l){return l>>8|l<<8&65280}function h(l){return l<<24|l<<8&16711680|l>>8&65280|l>>>24}va("bios config port, index="+y(e));this.fw_pointer=0;
611
+ 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 l=new Uint8Array(e.buffer);e[0]=h(this.option_roms.length);for(let m=0;m<this.option_roms.length;m++){const {name:n,data:p}=this.option_roms[m],q=4+64*m;e[q+0>>2]=h(p.length);e[q+4>>2]=g(49152+m);
612
+ for(let r=0;r<n.length;r++)l[q+8+r]=n.charCodeAt(r)}this.fw_value=l}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:(va("Warning: Unimplemented fw index: "+y(e)),this.fw_value=f(0))});this.devices={};a.load_devices&&(this.devices.pci=new Gc(this),this.acpi_enabled[0]&&(this.devices.acpi=new Ec(this)),this.devices.rtc=new hb(this),this.fill_cmos(this.devices.rtc,a),this.devices.dma=new B(this),this.devices.vga=new Y(this,
613
+ b,a.screen,a.vga_memory_size||8388608),this.devices.ps2=new Mc(this,b),this.devices.vmware=new Nc(this,b),this.devices.uart0=new Fc(this,1016,b),a.uart1&&(this.devices.uart1=new Fc(this,760,b)),a.uart2&&(this.devices.uart2=new Fc(this,1E3,b)),a.uart3&&(this.devices.uart3=new Fc(this,744,b)),this.devices.fdc=new W(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 ad(this,b,c),this.devices.cdrom=
614
+ this.devices.ide.secondary.master,this.devices.pit=new ib(this,b),"ne2k"===a.net_device.type?this.devices.net=new Jc(this,b,a.preserve_mac_from_state_image,a.mac_address_translation):"virtio"===a.net_device.type&&(this.devices.virtio_net=new cd(this,b,a.preserve_mac_from_state_image,a.net_device.mtu)),a.fs9p?this.devices.virtio_9p=new id(a.fs9p,this,b):a.handle9p?this.devices.virtio_9p=new jd(a.handle9p,this):a.proxy9p&&(this.devices.virtio_9p=new kd(a.proxy9p,this)),a.virtio_console&&(this.devices.virtio_console=
615
+ new Kc(this,b)),a.virtio_balloon&&(this.devices.virtio_balloon=new gd(this,b)),this.devices.sb16=new C(this,b));a.multiboot&&(a=this.load_multiboot_option_rom(a.multiboot,a.initrd,a.cmdline))&&(this.bios.main?this.option_roms.push(a):this.reg32[0]=this.io.port_read32(244));this.debug_init()};R.prototype.load_multiboot=function(a){this.load_multiboot_option_rom(a,void 0,"")&&(this.reg32[0]=this.io.port_read32(244))};R.prototype.load_multiboot_option_rom=function(a,b,c){if(8192>a.byteLength){var d=
616
+ 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)continue}else continue;va("Multiboot magic found, flags: "+y(f>>>0,8),2);var g=this;this.io.register_read(244,this,function(){return 0},function(){return 0},function(){var n,p=31860;let q=0;if(c){q|=4;g.write32(31760,p);c+="\x00";var r=(new TextEncoder).encode(c);g.write_blob(r,p);p+=r.length}if(f&2){q|=64;
617
+ r=0;g.write32(31788,0);g.write32(31792,p);var x=0;var E=!1;for(n=0;4294967296>n;n+=131072)E&&void 0!==g.memory_map_read8[n>>>17]?(g.write32(p,20),g.write32(p+4,x),g.write32(p+8,0),g.write32(p+12,n-x),g.write32(p+16,0),g.write32(p+20,1),p+=24,r+=24,E=!1):E||void 0!==g.memory_map_read8[n>>>17]||(x=n,E=!0);g.write32(31788,r)}x=r=0;if(f&65536){n=d[e+12>>2];r=d[e+16>>2];var z=d[e+20>>2];x=d[e+24>>2];E=d[e+28>>2];y(n,8);y(r,8);y(z,8);y(x,8);y(E,8);n=new Uint8Array(a,e-(n-r),0===z?void 0:z-r);g.write_blob(n,
618
+ r);r=E|0;x=Math.max(z,x)}else if(1179403647===d[0]){E=new DataView(a);const [u,K]=Vc(E,Sc);console.assert(52===K);console.assert(1179403647===u.magic,"Bad magic");console.assert(1===u.class,"Unimplemented: 64 bit elf");console.assert(1===u.data,"Unimplemented: big endian");console.assert(1===u.version0,"Bad version0");console.assert(2===u.type,"Unimplemented type");console.assert(1===u.version1,"Bad version1");console.assert(52===u.ehsize,"Bad header size");console.assert(32===u.phentsize,"Bad program header size");
619
+ console.assert(40===u.shentsize,"Bad section header size");[r]=Wc(new DataView(E.buffer,E.byteOffset+u.phoff,u.phentsize*u.phnum),Tc,u.phnum);Wc(new DataView(E.buffer,E.byteOffset+u.shoff,u.shentsize*u.shnum),Uc,u.shnum);E=u;n=r;r=E.entry;for(z of n)0!==z.type&&(1===z.type?z.paddr+z.memsz<g.memory_size[0]?(z.filesz&&(n=new Uint8Array(a,z.offset,z.filesz),g.write_blob(n,z.paddr)),x=Math.max(x,z.paddr+z.memsz),r===E.entry&&z.vaddr<=r&&z.vaddr+z.memsz>r&&(r=r-z.vaddr+z.paddr)):y(z.paddr):2===z.type||
620
+ 3===z.type||4===z.type||6===z.type||7===z.type||1685382480===z.type||1685382481===z.type||1685382482===z.type||1685382483===z.type||y(z.type))}b&&(q|=8,g.write32(31764,1),g.write32(31768,p),z=x,0!==(z&4095)&&(z=(z&-4096)+4096),x=z+b.byteLength,g.write32(p,z),g.write32(p+4,x),g.write32(p+8,0),g.write32(p+12,0),g.write_blob(new Uint8Array(b),z));g.write32(31744,q);g.reg32[3]=31744;g.cr[0]=1;g.protected_mode[0]=1;g.flags[0]=2;g.is_32[0]=1;g.stack_size_32[0]=1;for(p=0;6>p;p++)g.segment_is_null[p]=0,g.segment_offsets[p]=
621
+ 0,g.segment_limits[p]=4294967295,g.sreg[p]=45058;g.instruction_pointer[0]=g.get_seg_cs()+r|0;g.update_state_flags();g.dump_state();g.dump_regs_short();return 732803074});this.io.register_write_consecutive(244,this,function(n){console.log("Test exited with code "+y(n,2));throw"HALT";},function(){},function(){},function(){});for(let n=0;15>=n;n++){function p(q){y(n);y(q,2);q?this.device_raise_irq(n):this.device_lower_irq(n)}this.io.register_write(8192+n,this,p,p,p)}const l=new Uint8Array(512);(new Uint16Array(l.buffer))[0]=
622
+ 43605;l[2]=1;var h=3;l[h++]=102;l[h++]=229;l[h++]=244;let m=l[h]=0;for(let n=0;n<l.length;n++)m+=l[n];l[h]=-m;return{name:"genroms/multiboot.bin",data:l}}};R.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<=
623
+ 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)};R.prototype.load_bios=function(){var a=this.bios.main,b=this.bios.vga;if(a){var c=new Uint8Array(a);this.write_blob(c,1048576-a.byteLength);if(b){var d=new Uint8Array(b);this.write_blob(d,786432);this.io.mmap_register(4272947200,1048576,function(e){e=
624
+ e-4272947200|0;return e<d.length?d[e]:0},function(){})}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))}};R.prototype.codegen_finalize=function(a,b,c,d,e){const f=new Uint8Array(this.wasm_memory.buffer,d>>>0,e>>>0);WebAssembly.instantiate(f,{e:this.jit_imports}).then(g=>{this.wm.wasm_table.set(a+1024,g.instance.exports.f);this.codegen_finalize_finished(a,b,c);this.test_hook_did_finalize_wasm&&this.test_hook_did_finalize_wasm(f)})};
625
+ R.prototype.log_uncompiled_code=function(){};R.prototype.dump_function_code=function(){};R.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.apic_timer(b));return Math.min(c,d,e,f)};R.prototype.debug_init=function(){};R.prototype.dump_stack=function(){};R.prototype.debug_get_state=function(){};R.prototype.dump_state=function(){};R.prototype.get_regs_short=function(){};R.prototype.dump_regs_short=
626
+ function(){};R.prototype.dump_gdt_ldt=function(){};R.prototype.dump_idt=function(){};R.prototype.dump_page_structures=function(){if(this.cr[4]&32)for(var a=0;4>a;a++){var b=this.read32s(this.cr[3]+8*a);b&1&&this.dump_page_directory(b&4294963200,!0,a<<30)}else this.dump_page_directory(this.cr[3],!1,0)};R.prototype.dump_page_directory=function(){};R.prototype.get_memory_dump=function(){};R.prototype.memory_hex_dump=function(){};R.prototype.used_memory_dump=function(){};R.prototype.debug_interrupt=function(){};
627
+ R.prototype.debug_dump_code=function(){};R.prototype.dump_wasm=function(){};function Lc(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>>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=
628
+ [];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)this.device_feature[c>>>5]|=1<<(c&31),this.driver_feature[c>>>5]|=1<<(c&31);b.common.features.includes(32);this.features_ok=!0;this.device_status=0;this.config_has_changed=!1;this.config_generation=0;this.queues=[];for(const d of b.common.queues)this.queues.push(new Z(a,this,d));this.queue_select=0;this.queue_selected=
629
+ this.queues[0];this.isr_status=0;c=[];c.push(this.create_common_capability(b.common));c.push(this.create_notification_capability(b.notification));c.push(this.create_isr_capability(b.isr_status));b.device_specific&&c.push(this.create_device_specific_capability(b.device_specific));this.init_capabilities(c);a.devices.pci.register_device(this);this.reset()}Lc.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,
630
+ 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=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<
631
+ 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:()=>65535,write:()=>{}},{bytes:2,name:"num_queues",read:()=>this.queues.length,write:()=>{}},{bytes:1,name:"device_status",read:()=>this.device_status,write:b=>{0===b&&this.reset();b&~this.device_status&4&&this.device_status&64&&this.notify_config_changes();this.features_ok||(b&=-9);this.device_status=b;if(b&~this.device_status&4)a.on_driver_ok()}},
632
+ {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&&(b=1<<da(b-1)+1),b>this.queue_selected.size_supported&&(b=this.queue_selected.size_supported),this.queue_selected.set_size(b))}},
633
+ {bytes:2,name:"queue_msix_vector",read:()=>65535,write:()=>{}},{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()}},{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&&
634
+ (this.queue_selected.desc_addr=b)}},{bytes:4,name:"queue_desc (high dword)",read:()=>0,write:()=>{}},{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:()=>{}},{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)}},
635
+ {bytes:4,name:"queue_used (high dword)",read:()=>0,write:()=>{}}]}};Lc.prototype.create_notification_capability=function(a){const b=[];let c;c=a.single_handler?0: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}};Lc.prototype.create_isr_capability=function(a){return{type:3,bar:2,port:a.initial_port,use_mmio:!1,offset:0,
636
+ extra:new Uint8Array(0),struct:[{bytes:1,name:"isr_status",read:()=>{const b=this.isr_status;this.lower_irq();return b},write:()=>{}}]}};Lc.prototype.create_device_specific_capability=function(a){return{type:4,bar:3,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:a.struct}};Lc.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;var d=e.struct.reduce((f,g)=>f+g.bytes,0);d+=e.offset;d=16>d?16:1<<da(d-1)+
637
+ 1;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>>>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,g]of e.extra.entries())this.pci_space[c+
638
+ 16+f]=g;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 g=f.read;a=f.write;if(!e.use_mmio){d=function(m){return g(m&-2)>>((m&1)<<3)&255};const h=function(m){return g(m&-4)>>((m&3)<<3)&255},l=function(m){return g(m)};switch(f.bytes){case 4:this.cpu.io.register_read(c,this,h,void 0,g);this.cpu.io.register_read(c+1,this,h);this.cpu.io.register_read(c+
639
+ 2,this,h);this.cpu.io.register_read(c+3,this,h);this.cpu.io.register_write(c,this,void 0,void 0,a);break;case 2:this.cpu.io.register_read(c,this,d,g,l);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,g),this.cpu.io.register_write(c,this,a)}}c+=f.bytes}}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+
640
+ 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+18]=0;this.pci_space[b+19]=0};Lc.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;
641
+ a[7]=this.config_generation;a[8]=this.isr_status;a[9]=this.queue_select;return a=a.concat(this.queues)};Lc.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]||
642
+ null};Lc.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];for(const a of this.queues)a.reset();this.config_has_changed=!1;this.config_generation=0;this.lower_irq()};Lc.prototype.notify_config_changes=function(){this.config_has_changed=!0;this.device_status&4&&this.raise_irq(2)};Lc.prototype.update_config_generation=function(){this.config_has_changed&&
643
+ (this.config_generation++,this.config_generation&=255,this.config_has_changed=!1)};Lc.prototype.is_feature_negotiated=function(a){return 0<(this.driver_feature[a>>>5]&1<<(a&31))};Lc.prototype.needs_reset=function(){this.device_status|=64;this.device_status&4&&this.notify_config_changes()};Lc.prototype.raise_irq=function(a){y(a);this.isr_status|=a;this.pci.raise_irq(this.pci_id)};Lc.prototype.lower_irq=function(){this.isr_status=0;this.pci.lower_irq(this.pci_id)};function Z(a,b,c){this.cpu=a;this.virtio=
644
+ 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()}Z.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};Z.prototype.set_state=
645
+ 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]};Z.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)};Z.prototype.is_configured=function(){return this.desc_addr&&this.avail_addr&&
646
+ this.used_addr};Z.prototype.enable=function(){this.is_configured();this.enabled=!0};Z.prototype.set_size=function(a){this.size=a;this.mask=a-1};Z.prototype.count_requests=function(){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};Z.prototype.has_request=function(){return 0!==this.count_requests()};Z.prototype.pop_request=function(){this.has_request();var a=this.avail_get_entry(this.avail_last_idx);
647
+ a=new ld(this,a);this.avail_last_idx=this.avail_last_idx+1&65535;return a};Z.prototype.push_reply=function(a){const b=this.used_get_idx()+this.num_staged_replies&this.mask;this.used_set_entry(b,a.head_idx,a.length_written);this.num_staged_replies++};Z.prototype.flush_replies=function(){if(0!==this.num_staged_replies){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)):
648
+ ~this.avail_get_flags()&1&&this.virtio.raise_irq(1)}};Z.prototype.notify_me_after=function(a){a=this.avail_get_idx()+a&65535;this.used_set_avail_event(a)};Z.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)}};Z.prototype.avail_get_flags=function(){return this.cpu.read16(this.avail_addr)};Z.prototype.avail_get_idx=function(){return this.cpu.read16(this.avail_addr+
649
+ 2)};Z.prototype.avail_get_entry=function(a){return this.cpu.read16(this.avail_addr+4+2*(a&this.mask))};Z.prototype.avail_get_used_event=function(){return this.cpu.read16(this.avail_addr+4+2*this.size)};Z.prototype.used_get_flags=function(){return this.cpu.read16(this.used_addr)};Z.prototype.used_set_flags=function(a){this.cpu.write16(this.used_addr,a)};Z.prototype.used_get_idx=function(){return this.cpu.read16(this.used_addr+2)};Z.prototype.used_set_idx=function(a){this.cpu.write16(this.used_addr+
650
+ 2,a)};Z.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)};Z.prototype.used_set_avail_event=function(a){this.cpu.write16(this.used_addr+4+8*this.size,a)};function ld(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=
651
+ a.desc_addr,d=0,e=a.size,f=!1;const g=this.virtio.is_feature_negotiated(28);do{const h=a.get_descriptor(c,b);y(h.addr_high,8);y(h.addr_low,8);y(h.len,8);y(h.flags,4);y(h.next,4);if(g&&h.flags&4)c=h.addr_low,d=b=0,e=h.len/16;else{if(h.flags&2)f=!0,this.write_buffers.push(h),this.length_writable+=h.len;else{if(f)break;this.read_buffers.push(h);this.length_readable+=h.len}d++;if(d>e)break;if(h.flags&1)b=h.next;else break}}while(1)}ld.prototype.get_next_blob=function(a){let b=0,c=a.length;for(;c&&this.read_buffer_idx!==
652
+ this.read_buffers.length;){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};ld.prototype.set_next_blob=function(a){let b=0,c=a.length;for(;c&&this.write_buffer_idx!==this.write_buffers.length;){var d=this.write_buffers[this.write_buffer_idx];const e=d.addr_low+this.write_buffer_offset;d=
653
+ 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};function md(a,b,c,d){const e=new Lc(a,{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:[f=>{if(0===f){for(f=
654
+ e.queues[0];f.has_request();){const g=f.pop_request();d(g)}f.notify_me_after(0)}}]},isr_status:{initial_port:42752},device_specific:{initial_port:42496,struct:[{bytes:2,name:"mount tag length",read:()=>b,write:()=>{}}].concat(Array.from(Array(254).keys()).map(f=>({bytes:1,name:"mount tag name "+f,read:()=>c[f]||0,write:()=>{}})))}});return e}function id(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.virtio=
655
+ md(b,this.configspace_taglen,this.configspace_tagname,this.ReceiveRequest.bind(this));this.virtqueue=this.virtio.queues[0];this.VERSION="9P2000.L";this.msize=this.BLOCKSIZE=8192;this.replybuffer=new Uint8Array(2*this.msize);this.replybuffersize=0;this.fids=[]}id.prototype.get_state=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,
656
+ b.type,b.uid,b.dbg_name]});a[9]=this.fs;return a};id.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],uid:b[2],dbg_name:b[3]}});this.fs.set_state(a[9])};id.prototype.Createfid=function(a,b,c,d){return{inodeid:a,type:b,uid:c,dbg_name:d}};
657
+ id.prototype.update_dbg_name=function(a,b){for(const c of this.fids)c.inodeid===a&&(c.dbg_name=b)};id.prototype.reset=function(){this.fids=[];this.virtio.reset()};id.prototype.BuildReply=function(a,b,c){J(["w","b","h"],[c+7,a+1,b],this.replybuffer,0);this.replybuffersize=c+7};id.prototype.SendError=function(a,b,c){b=J(["w"],[c],this.replybuffer,7);this.BuildReply(6,a,b)};id.prototype.SendReply=function(a){a.set_next_blob(this.replybuffer.subarray(0,this.replybuffersize));this.virtqueue.push_reply(a);
658
+ this.virtqueue.flush_replies()};id.prototype.ReceiveRequest=async function(a){var b=new Uint8Array(a.length_readable);a.get_next_blob(b);var c={offset:0},d=L(["w","b","h"],b,c),e=d[1];d=d[2];switch(e){case 8:var f=this.fs.GetTotalSize();var g=this.fs.GetSpace(),h=[16914839];h[1]=this.BLOCKSIZE;h[2]=Math.floor(g/h[1]);h[3]=h[2]-Math.floor(f/h[1]);h[4]=h[2]-Math.floor(f/h[1]);h[5]=this.fs.CountUsedInodes();h[6]=this.fs.CountFreeInodes();h[7]=0;h[8]=256;f=J("wwddddddw".split(""),h,this.replybuffer,7);
659
+ this.BuildReply(e,d,f);this.SendReply(a);break;case 112:case 12:h=L(["w","w"],b,c);f=h[0];var l=h[1];b=this.fids[f].inodeid;c=this.fs.GetInode(b);await this.fs.OpenInode(b,l);h=[];h[0]=c.qid;h[1]=this.msize-24;J(["Q","w"],h,this.replybuffer,7);this.BuildReply(e,d,17);this.SendReply(a);break;case 70:h=L(["w","w","s"],b,c);b=h[0];f=h[1];g=h[2];f=this.fs.Link(this.fids[b].inodeid,this.fids[f].inodeid,g);if(0>f){this.SendError(d,-1===f?"Operation not permitted":"Unknown error: "+-f,-f);this.SendReply(a);
660
+ break}this.BuildReply(e,d,0);this.SendReply(a);break;case 16:h=L(["w","s","s","w"],b,c);f=h[0];g=h[1];var m=h[3];b=this.fs.CreateSymlink(g,this.fids[f].inodeid,h[2]);c=this.fs.GetInode(b);c.uid=this.fids[f].uid;c.gid=m;J(["Q"],[c.qid],this.replybuffer,7);this.BuildReply(e,d,13);this.SendReply(a);break;case 18:h=L("wswwww".split(""),b,c);f=h[0];g=h[1];l=h[2];b=h[3];c=h[4];m=h[5];b=this.fs.CreateNode(g,this.fids[f].inodeid,b,c);c=this.fs.GetInode(b);c.mode=l;c.uid=this.fids[f].uid;c.gid=m;J(["Q"],[c.qid],
661
+ this.replybuffer,7);this.BuildReply(e,d,13);this.SendReply(a);break;case 22:h=L(["w"],b,c);f=h[0];c=this.fs.GetInode(this.fids[f].inodeid);f=J(["s"],[c.symlink],this.replybuffer,7);this.BuildReply(e,d,f);this.SendReply(a);break;case 72:h=L(["w","s","w","w"],b,c);f=h[0];g=h[1];l=h[2];m=h[3];b=this.fs.CreateDirectory(g,this.fids[f].inodeid);c=this.fs.GetInode(b);c.mode=l|16384;c.uid=this.fids[f].uid;c.gid=m;J(["Q"],[c.qid],this.replybuffer,7);this.BuildReply(e,d,13);this.SendReply(a);break;case 14:h=
662
+ L(["w","s","w","w","w"],b,c);f=h[0];g=h[1];l=h[3];m=h[4];this.bus.send("9p-create",[g,this.fids[f].inodeid]);b=this.fs.CreateFile(g,this.fids[f].inodeid);this.fids[f].inodeid=b;this.fids[f].type=1;this.fids[f].dbg_name=g;c=this.fs.GetInode(b);c.uid=this.fids[f].uid;c.gid=m;c.mode=l|32768;J(["Q","w"],[c.qid,this.msize-24],this.replybuffer,7);this.BuildReply(e,d,17);this.SendReply(a);break;case 52:h=L("wbwddws".split(""),b,c);f=h[0];g=h[2];b=0===h[4]?Infinity:h[4];h=this.fs.DescribeLock(h[1],h[3],b,
663
+ h[5],h[6]);f=this.fs.Lock(this.fids[f].inodeid,h,g);J(["b"],[f],this.replybuffer,7);this.BuildReply(e,d,1);this.SendReply(a);break;case 54:h=L("wbddws".split(""),b,c);f=h[0];b=0===h[3]?Infinity:h[3];h=this.fs.DescribeLock(h[1],h[2],b,h[4],h[5]);f=this.fs.GetLock(this.fids[f].inodeid,h);f||(f=h,f.type=2);f=J(["b","d","d","w","s"],[f.type,f.start,Infinity===f.length?0:f.length,f.proc_id,f.client_id],this.replybuffer,7);this.BuildReply(e,d,f);this.SendReply(a);break;case 24:h=L(["w","d"],b,c);f=h[0];
664
+ c=this.fs.GetInode(this.fids[f].inodeid);if(!c||4===c.status){this.SendError(d,"No such file or directory",2);this.SendReply(a);break}h[0]=h[1];h[1]=c.qid;h[2]=c.mode;h[3]=c.uid;h[4]=c.gid;h[5]=c.nlinks;h[6]=c.major<<8|c.minor;h[7]=c.size;h[8]=this.BLOCKSIZE;h[9]=Math.floor(c.size/512+1);h[10]=c.atime;h[11]=0;h[12]=c.mtime;h[13]=0;h[14]=c.ctime;h[15]=0;h[16]=0;h[17]=0;h[18]=0;h[19]=0;J("dQwwwddddddddddddddd".split(""),h,this.replybuffer,7);this.BuildReply(e,d,153);this.SendReply(a);break;case 26:h=
665
+ L("wwwwwddddd".split(""),b,c);f=h[0];c=this.fs.GetInode(this.fids[f].inodeid);h[1]&1&&(c.mode=h[2]);h[1]&2&&(c.uid=h[3]);h[1]&4&&(c.gid=h[4]);h[1]&16&&(c.atime=Math.floor((new Date).getTime()/1E3));h[1]&32&&(c.mtime=Math.floor((new Date).getTime()/1E3));h[1]&64&&(c.ctime=Math.floor((new Date).getTime()/1E3));h[1]&128&&(c.atime=h[6]);h[1]&256&&(c.mtime=h[8]);h[1]&8&&await this.fs.ChangeSize(this.fids[f].inodeid,h[5]);this.BuildReply(e,d,0);this.SendReply(a);break;case 50:L(["w","d"],b,c);this.BuildReply(e,
666
+ d,0);this.SendReply(a);break;case 40:case 116:h=L(["w","d","w"],b,c);f=h[0];g=h[1];l=h[2];c=this.fs.GetInode(this.fids[f].inodeid);if(!c||4===c.status){this.SendError(d,"No such file or directory",2);this.SendReply(a);break}if(2===this.fids[f].type)for(c.caps.length<g+l&&(l=c.caps.length-g),h=0;h<l;h++)this.replybuffer[11+h]=c.caps[g+h];else await this.fs.OpenInode(this.fids[f].inodeid,void 0),h=this.fids[f].inodeid,l=Math.min(l,this.replybuffer.length-11),c.size<g+l?l=c.size-g:40===e&&(l=this.fs.RoundToDirentry(h,
667
+ g+l)-g),g>c.size&&(l=0),this.bus.send("9p-read-start",[this.fids[f].dbg_name]),h=await this.fs.Read(h,g,l),this.bus.send("9p-read-end",[this.fids[f].dbg_name,l]),h&&this.replybuffer.set(h,11);J(["w"],[l],this.replybuffer,7);this.BuildReply(e,d,4+l);this.SendReply(a);break;case 118:h=L(["w","d","w"],b,c);f=h[0];g=h[1];l=h[2];h=this.fids[f].dbg_name;if(2===this.fids[f].type){this.SendError(d,"Setxattr not supported",95);this.SendReply(a);break}else await this.fs.Write(this.fids[f].inodeid,g,l,b.subarray(c.offset));
668
+ this.bus.send("9p-write-end",[h,l]);J(["w"],[l],this.replybuffer,7);this.BuildReply(e,d,4);this.SendReply(a);break;case 74:h=L(["w","s","w","s"],b,c);f=await this.fs.Rename(this.fids[h[0]].inodeid,h[1],this.fids[h[2]].inodeid,h[3]);if(0>f){this.SendError(d,-2===f?"No such file or directory":-1===f?"Operation not permitted":-39===f?"Directory not empty":"Unknown error: "+-f,-f);this.SendReply(a);break}this.BuildReply(e,d,0);this.SendReply(a);break;case 76:h=L(["w","s","w"],b,c);b=h[0];g=h[1];f=this.fs.Search(this.fids[b].inodeid,
669
+ g);if(-1===f){this.SendError(d,"No such file or directory",2);this.SendReply(a);break}f=this.fs.Unlink(this.fids[b].inodeid,g);if(0>f){this.SendError(d,-39===f?"Directory not empty":-1===f?"Operation not permitted":"Unknown error: "+-f,-f);this.SendReply(a);break}this.BuildReply(e,d,0);this.SendReply(a);break;case 100:f=L(["w","s"],b,c);this.msize!==f[0]&&(this.msize=f[0],this.replybuffer=new Uint8Array(Math.min(16777216,2*this.msize)));f=J(["w","s"],[this.msize,this.VERSION],this.replybuffer,7);
670
+ this.BuildReply(e,d,f);this.SendReply(a);break;case 104:h=L(["w","w","s","s","w"],b,c);f=h[0];g=h[4];y(h[1]);this.fids[f]=this.Createfid(0,1,g,"");c=this.fs.GetInode(this.fids[f].inodeid);J(["Q"],[c.qid],this.replybuffer,7);this.BuildReply(e,d,13);this.SendReply(a);this.bus.send("9p-attach");break;case 108:L(["h"],b,c);this.BuildReply(e,d,0);this.SendReply(a);break;case 110:h=L(["w","w","h"],b,c);f=h[0];l=h[1];m=h[2];if(0===m){this.fids[l]=this.Createfid(this.fids[f].inodeid,1,this.fids[f].uid,this.fids[f].dbg_name);
671
+ J(["h"],[0],this.replybuffer,7);this.BuildReply(e,d,2);this.SendReply(a);break}g=[];for(h=0;h<m;h++)g.push("s");c=L(g,b,c);b=this.fids[f].inodeid;g=9;var n=0;for(h=0;h<m;h++){b=this.fs.Search(b,c[h]);if(-1===b)break;g+=J(["Q"],[this.fs.GetInode(b).qid],this.replybuffer,g);n++;this.fids[l]=this.Createfid(b,1,this.fids[f].uid,c[h])}J(["h"],[n],this.replybuffer,7);this.BuildReply(e,d,g-7);this.SendReply(a);break;case 120:h=L(["w"],b,c);this.fids[h[0]]&&0<=this.fids[h[0]].inodeid&&(await this.fs.CloseInode(this.fids[h[0]].inodeid),
672
+ this.fids[h[0]].inodeid=-1,this.fids[h[0]].type=-1);this.BuildReply(e,d,0);this.SendReply(a);break;case 32:h=L(["w","s","d","w"],b,c);f=h[0];this.fids[f].type=2;this.BuildReply(e,d,0);this.SendReply(a);break;case 30:L(["w","w","s"],b,c),this.SendError(d,"Setxattr not supported",95),this.SendReply(a)}};function jd(a,b){this.handle_fn=a;this.tag_bufchain=new Map;this.configspace_tagname=[104,111,115,116,57,112];this.configspace_taglen=this.configspace_tagname.length;this.virtio=md(b,this.configspace_taglen,
673
+ this.configspace_tagname,async c=>{const d=new Uint8Array(c.length_readable);c.get_next_blob(d);var e=L(["w","b","h"],d,{offset:0})[2];this.tag_bufchain.set(e,c);this.handle_fn(d,f=>{var g=L(["w","b","h"],f,{offset:0})[2];const h=this.tag_bufchain.get(g);h?(h.set_next_blob(f),this.virtqueue.push_reply(h),this.virtqueue.flush_replies(),this.tag_bufchain.delete(g)):console.error("No bufchain found for tag: "+g)})});this.virtqueue=this.virtio.queues[0]}jd.prototype.get_state=function(){var a=[];a[0]=
674
+ this.configspace_tagname;a[1]=this.configspace_taglen;a[2]=this.virtio;a[3]=this.tag_bufchain;return a};jd.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.tag_bufchain=a[3]};jd.prototype.reset=function(){this.virtio.reset()};function kd(a,b){this.socket=void 0;this.cpu=b;this.send_queue=[];this.url=a;this.reconnect_interval=1E4;this.last_connect_attempt=Date.now()-this.reconnect_interval;
675
+ this.send_queue_limit=64;this.destroyed=!1;this.tag_bufchain=new Map;this.configspace_tagname=[104,111,115,116,57,112];this.configspace_taglen=this.configspace_tagname.length;this.virtio=md(b,this.configspace_taglen,this.configspace_tagname,async c=>{const d=new Uint8Array(c.length_readable);c.get_next_blob(d);const e=L(["w","b","h"],d,{offset:0})[2];this.tag_bufchain.set(e,c);this.send(d)});this.virtqueue=this.virtio.queues[0]}kd.prototype.get_state=function(){var a=[];a[0]=this.configspace_tagname;
676
+ a[1]=this.configspace_taglen;a[2]=this.virtio;a[3]=this.tag_bufchain;return a};kd.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.tag_bufchain=a[3]};kd.prototype.reset=function(){this.virtio.reset()};kd.prototype.handle_message=function(a){a=new Uint8Array(a.data);const b=L(["w","b","h"],a,{offset:0})[2],c=this.tag_bufchain.get(b);c?(c.set_next_blob(a),this.virtqueue.push_reply(c),this.virtqueue.flush_replies(),
677
+ this.tag_bufchain.delete(b)):console.error("Virtio9pProxy: No bufchain found for tag: "+b)};kd.prototype.handle_close=function(){this.destroyed||(this.connect(),setTimeout(this.connect.bind(this),this.reconnect_interval))};kd.prototype.handle_open=function(){for(var a=0;a<this.send_queue.length;a++)this.send(this.send_queue[a]);this.send_queue=[]};kd.prototype.handle_error=function(){};kd.prototype.destroy=function(){this.destroyed=!0;this.socket&&this.socket.close()};kd.prototype.connect=function(){if("undefined"!==
678
+ typeof WebSocket){if(this.socket){var a=this.socket.readyState;if(0===a||1===a)return}a=Date.now();if(!(this.last_connect_attempt+this.reconnect_interval>a)){this.last_connect_attempt=Date.now();try{this.socket=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)}}};
679
+ kd.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)),this.connect())};kd.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)};export{};; export default module.exports.V86; export let {V86, CPU} = module.exports;