v86 0.5.12 → 0.5.14

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.js CHANGED
@@ -1,28 +1,28 @@
1
1
  ;(function(){'use strict';var h=h||{};h.exportSymbol=function(a,b){"undefined"!==typeof module&&"undefined"!==typeof module.exports?module.exports[a]=b:"undefined"!==typeof window?window[a]=b:"function"===typeof importScripts&&(self[a]=b)};h.exportProperty=function(){};function aa(a,b){return(a||0===a?a+"":"").padEnd(b," ")}function v(a,b,c,d){return new Proxy({},{get:function(e,f){e=new a(b.buffer,c,d);const g=e[f];if("function"===typeof g)return g.bind(e);/^\d+$/.test(f);return g},set:function(e,f,g){/^\d+$/.test(f);(new a(b.buffer,c,d))[f]=g;return!0}})}function A(a,b){a=(a?a.toString(16):"").toUpperCase();return"0x"+(a||0===a?a+"":"").padStart(b||1,"0")}var ba;
2
2
  if("undefined"!==typeof crypto&&crypto.getRandomValues){const a=new Int32Array(1);ba=function(){crypto.getRandomValues(a);return a[0]}}else if("undefined"!==typeof require){const a=require("crypto");ba=function(){return a.randomBytes(4).readInt32LE(0)}}else"undefined"!==typeof process&&import("node:crypto").then(a=>{ba=function(){return a.randomBytes(4).readInt32LE(0)}});var ca;
3
3
  if("function"===typeof Math.clz32)ca=function(a){return 31-Math.clz32(a)};else{for(var da=new Int8Array(256),ea=0,fa=-2;256>ea;ea++)ea&ea-1||fa++,da[ea]=fa;ca=function(a){a>>>=0;var b=a>>>16;if(b){var c=b>>>8;return c?24+da[c]:16+da[b]}return(c=a>>>8)?8+da[c]:da[a]}}function ha(a){return 1>=a?1:1<<1+ca(a-1)}
4
- function ja(a){var b=new Uint8Array(a),c,d;this.length=0;this.push=function(e){this.length!==a&&this.length++;b[d]=e;d=d+1&a-1};this.shift=function(){if(this.length){var e=b[c];c=c+1&a-1;this.length--;return e}return-1};this.peek=function(){return this.length?b[c]:-1};this.clear=function(){this.length=d=c=0};this.clear()}function la(a){this.size=a;this.data=new Float32Array(a);this.length=this.end=this.start=0}
5
- la.prototype.push=function(a){this.length===this.size?this.start=this.start+1&this.size-1:this.length++;this.data[this.end]=a;this.end=this.end+1&this.size-1};la.prototype.shift=function(){if(this.length){var a=this.data[this.start];this.start=this.start+1&this.size-1;this.length--;return a}};
6
- la.prototype.shift_block=function(a){var b=new Float32Array(a);a>this.length&&(a=this.length);var c=this.start+a,d=this.data.subarray(this.start,c);b.set(d);c>=this.size&&(c-=this.size,b.set(this.data.subarray(0,c),d.length));this.start=c;this.length-=a;return b};la.prototype.peek=function(){if(this.length)return this.data[this.start]};la.prototype.clear=function(){this.length=this.end=this.start=0};
4
+ function ja(a){var b=new Uint8Array(a),c,d;this.length=0;this.push=function(e){this.length!==a&&this.length++;b[d]=e;d=d+1&a-1};this.shift=function(){if(this.length){var e=b[c];c=c+1&a-1;this.length--;return e}return-1};this.peek=function(){return this.length?b[c]:-1};this.clear=function(){this.length=d=c=0};this.clear()}function ka(a){this.size=a;this.data=new Float32Array(a);this.length=this.end=this.start=0}
5
+ ka.prototype.push=function(a){this.length===this.size?this.start=this.start+1&this.size-1:this.length++;this.data[this.end]=a;this.end=this.end+1&this.size-1};ka.prototype.shift=function(){if(this.length){var a=this.data[this.start];this.start=this.start+1&this.size-1;this.length--;return a}};
6
+ ka.prototype.shift_block=function(a){var b=new Float32Array(a);a>this.length&&(a=this.length);var c=this.start+a,d=this.data.subarray(this.start,c);b.set(d);c>=this.size&&(c-=this.size,b.set(this.data.subarray(0,c),d.length));this.start=c;this.length-=a;return b};ka.prototype.peek=function(){if(this.length)return this.data[this.start]};ka.prototype.clear=function(){this.length=this.end=this.start=0};
7
7
  function ma(a){"number"===typeof a?this.view=new Uint8Array(a+7>>3):a instanceof ArrayBuffer&&(this.view=new Uint8Array(a))}ma.prototype.set=function(a,b){const c=a>>3;a=1<<(a&7);this.view[c]=b?this.view[c]|a:this.view[c]&~a};ma.prototype.get=function(a){return this.view[a>>3]>>(a&7)&1};ma.prototype.get_buffer=function(){return this.view.buffer};var na;na="undefined"===typeof XMLHttpRequest?qa:ra;
8
8
  function ra(a,b,c){function d(){const l=c||0;setTimeout(()=>{na(a,b,l+1)},1E3*([1,1,2,3,5,8,13,21][l]||34))}var e=new XMLHttpRequest;e.open(b.method||"get",a,!0);e.responseType=b.as_json?"json":"arraybuffer";if(b.headers)for(var f=Object.keys(b.headers),g=0;g<f.length;g++){var k=f[g];e.setRequestHeader(k,b.headers[k])}b.range&&(f=b.range.start,e.setRequestHeader("Range","bytes="+f+"-"+(f+b.range.length-1)),e.setRequestHeader("X-Accept-Encoding","identity"),e.onreadystatechange=function(){200===e.status&&
9
9
  (console.error("Server sent full file in response to ranged request, aborting",{filename:a}),e.abort())});e.onload=function(){if(4===e.readyState)if(200!==e.status&&206!==e.status)console.error("Loading the image "+a+" failed (status %d)",e.status),500<=e.status&&600>e.status&&d();else if(e.response){if(b.range){const l=e.getResponseHeader("Content-Encoding");l&&"identity"!==l&&console.error("Server sent Content-Encoding in response to ranged request",{filename:a,enc:l})}b.done&&b.done(e.response,
10
10
  e)}};e.onerror=function(l){console.error("Loading the image "+a+" failed",l);d()};b.progress&&(e.onprogress=function(l){b.progress(l)});e.send(null)}
11
- function qa(a,b){if(b.range)import("node:fs").then(d=>d.open(a,"r",(e,f)=>{if(e)throw e;e=b.range.length;var g=Buffer.allocUnsafe(e);d.read(f,g,0,e,b.range.start,k=>{if(k)throw k;b.done&&b.done(new Uint8Array(g));d.close(f,l=>{if(l)throw l;})})}));else{var c={encoding:b.as_json?"utf-8":null};import("node:fs").then(d=>d.readFile(a,c,function(e,f){e?console.log("Could not read file:",a,e):(e=f,e=b.as_json?JSON.parse(e):(new Uint8Array(e)).buffer,b.done(e))}))}};function sa(){}function ta(){};function ua(a,b){function c(w){w=w.toString(16);return"#"+"0".repeat(6-w.length)+w}function d(w){var t=256*oa,E=8*S,J=Ua?Ua.canvas:null;J&&J.width===t&&J.height===E||(J?(J.width=t,J.height=E):(J=new OffscreenCanvas(t,E),Ua=J.getContext("2d")),Ab=Ua.createImageData(t,E));const Q=Ab.data;let P=0,T;E=Bb?function(Y){T=T||Y;Q[P+3]=Y;Q[P+7]=Y;P+=8}:function(Y){T=T||Y;Q[P+3]=Y;P+=4};J=32-S;const ka=t*(S-1)*4;t=4*(oa-t*S);const ia=1020*oa;for(let Y=0,Ea=0;2048>Y;++Y,Ea+=J,P+=t){const Fa=Y%256;Y&&!Fa&&(P+=
12
- ka);T=!1;for(let Ma=0;Ma<S;++Ma,++Ea,P+=ia){const Na=w[Ea];for(let va=128;0<va;va>>=1)E(Na&va?255:0);Cb&&E(Db&&192<=Fa&&223>=Fa&&Na&1?255:0)}Vb[Y]=T?1:0}Ua.putImageData(Ab,0,0)}function e(w,t,E,J){if(t&&E){w.style.width="";w.style.height="";J&&(w.style.transform="");var Q=w.getBoundingClientRect();J?w.style.transform=(1===t?"":" scaleX("+t+")")+(1===E?"":" scaleY("+E+")"):(0===t%1&&0===E%1?(g.style.imageRendering="crisp-edges",g.style.imageRendering="pixelated",g.style["-ms-interpolation-mode"]="nearest-neighbor"):
11
+ function qa(a,b){if(b.range)import("node:fs").then(d=>d.open(a,"r",(e,f)=>{if(e)throw e;e=b.range.length;var g=Buffer.allocUnsafe(e);d.read(f,g,0,e,b.range.start,k=>{if(k)throw k;b.done&&b.done(new Uint8Array(g));d.close(f,l=>{if(l)throw l;})})}));else{var c={encoding:b.as_json?"utf-8":null};import("node:fs").then(d=>d.readFile(a,c,function(e,f){e?console.log("Could not read file:",a,e):(e=f,e=b.as_json?JSON.parse(e):(new Uint8Array(e)).buffer,b.done(e))}))}};function sa(){}function ta(){};function ua(a,b){function c(w){w=w.toString(16);return"#"+"0".repeat(6-w.length)+w}function d(w){var t=256*oa,E=8*S,J=Ua?Ua.canvas:null;J&&J.width===t&&J.height===E||(J?(J.width=t,J.height=E):(J=new OffscreenCanvas(t,E),Ua=J.getContext("2d")),Ab=Ua.createImageData(t,E));const Q=Ab.data;let P=0,T;E=Bb?function(Y){T=T||Y;Q[P+3]=Y;Q[P+7]=Y;P+=8}:function(Y){T=T||Y;Q[P+3]=Y;P+=4};J=32-S;const la=t*(S-1)*4;t=4*(oa-t*S);const ia=1020*oa;for(let Y=0,Ea=0;2048>Y;++Y,Ea+=J,P+=t){const Fa=Y%256;Y&&!Fa&&(P+=
12
+ la);T=!1;for(let Ma=0;Ma<S;++Ma,++Ea,P+=ia){const Na=w[Ea];for(let va=128;0<va;va>>=1)E(Na&va?255:0);Cb&&E(Db&&192<=Fa&&223>=Fa&&Na&1?255:0)}Vb[Y]=T?1:0}Ua.putImageData(Ab,0,0)}function e(w,t,E,J){if(t&&E){w.style.width="";w.style.height="";J&&(w.style.transform="");var Q=w.getBoundingClientRect();J?w.style.transform=(1===t?"":" scaleX("+t+")")+(1===E?"":" scaleY("+E+")"):(0===t%1&&0===E%1?(g.style.imageRendering="crisp-edges",g.style.imageRendering="pixelated",g.style["-ms-interpolation-mode"]="nearest-neighbor"):
13
13
  (g.style.imageRendering="",g.style["-ms-interpolation-mode"]=""),J=window.devicePixelRatio||1,0!==J%1&&(t/=J,E/=J));1!==t&&(w.style.width=Q.width*t+"px");1!==E&&(w.style.height=Q.height*E+"px")}}const f=a.container;this.screen_fill_buffer=b;console.assert(f,"options.container must be provided");this.FLAG_BLINKING=1;this.FLAG_FONT_PAGE_B=2;var g=f.getElementsByTagName("canvas")[0],k=g.getContext("2d",{alpha:!1}),l=f.getElementsByTagName("div")[0],m=document.createElement("div"),n,p,q=void 0!==a.scale?
14
14
  a.scale:1,r=void 0!==a.scale?a.scale:1,z=1,y,u,H,x,I,R,pa,Ua,Ab,Vb=new Int8Array(2048),S,oa,Cb,Bb,Db,Eb=0,Fb=0,nb,Wb=0,ob,Gb,pb,Hb=[],qb=Hb,rb=0,Ib=!1;this.init=function(){const w=new Uint16Array([32,9786,9787,9829,9830,9827,9824,8226,9688,9675,9689,9794,9792,9834,9835,9788,9658,9668,8597,8252,182,167,9644,8616,8593,8595,8594,8592,8735,8596,9650,9660]),t=new Uint16Array([8962,199,252,233,226,228,224,229,231,234,235,232,239,238,236,196,197,201,230,198,244,246,242,251,249,255,214,220,162,163,165,8359,
15
15
  402,225,237,243,250,241,209,170,186,191,8976,172,189,188,161,171,187,9617,9618,9619,9474,9508,9569,9570,9558,9557,9571,9553,9559,9565,9564,9563,9488,9492,9524,9516,9500,9472,9532,9566,9567,9562,9556,9577,9574,9568,9552,9580,9575,9576,9572,9573,9561,9560,9554,9555,9579,9578,9496,9484,9608,9604,9612,9616,9600,945,223,915,960,931,963,181,964,934,920,937,948,8734,966,949,8745,8801,177,8805,8804,8992,8993,247,8776,176,8729,183,8730,8319,178,9632,160]);for(var E=0,J;256>E;E++)J=126<E?t[E-127]:32>E?w[E]:
16
16
  E,Hb.push(String.fromCharCode(J));m.classList.add("cursor");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===u&&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===u||2===u)w.src=g.toDataURL("image/png");else{const t=[9,16],E=document.createElement("canvas");E.width=x*t[0];E.height=I*t[1];const J=E.getContext("2d");
17
- J.imageSmoothingEnabled=!1;J.font=window.getComputedStyle(l).font;J.textBaseline="top";for(let Q=0;Q<I;Q++)for(let P=0;P<x;P++){const T=4*(Q*x+P),ka=H[T+0],ia=H[T+3];J.fillStyle=c(H[T+2]);J.fillRect(P*t[0],Q*t[1],t[0],t[1]);J.fillStyle=c(ia);J.fillText(qb[ka],P*t[0],Q*t[1])}"none"!==m.style.display&&n<I&&p<x&&(J.fillStyle=m.style.backgroundColor,J.fillRect(p*t[0],n*t[1]+parseInt(m.style.marginTop,10),parseInt(m.style.width,10),parseInt(m.style.height,10)));w.src=E.toDataURL("image/png")}return w};
17
+ J.imageSmoothingEnabled=!1;J.font=window.getComputedStyle(l).font;J.textBaseline="top";for(let Q=0;Q<I;Q++)for(let P=0;P<x;P++){const T=4*(Q*x+P),la=H[T+0],ia=H[T+3];J.fillStyle=c(H[T+2]);J.fillRect(P*t[0],Q*t[1],t[0],t[1]);J.fillStyle=c(ia);J.fillText(qb[la],P*t[0],Q*t[1])}"none"!==m.style.display&&n<I&&p<x&&(J.fillStyle=m.style.backgroundColor,J.fillRect(p*t[0],n*t[1]+parseInt(m.style.marginTop,10),parseInt(m.style.width,10),parseInt(m.style.height,10)));w.src=E.toDataURL("image/png")}return w};
18
18
  this.put_char=function(w,t,E,J,Q,P){t=4*(w*x+t);H[t+0]=E;H[t+1]=J;H[t+2]=Q;H[t+3]=P;y[w]=1};this.timer=function(){rb=requestAnimationFrame(()=>this.update_screen())};this.update_screen=function(){Ib||(0===u?this.update_text():1===u?this.update_graphical():this.update_graphical_text());this.timer()};this.update_text=function(){for(var w=0;w<I;w++)y[w]&&(this.text_update_row(w),y[w]=0)};this.update_graphical=function(){this.screen_fill_buffer()};this.update_graphical_text=function(){if(R){var w=performance.now();
19
- if(266<w-Wb){nb=!nb;pb&&(y[n]=1);var t=4*x;for(let ka=0,ia=0;ka<I;++ka)if(y[ka])ia+=t;else for(var E=0;E<x;++E,ia+=4)if(H[ia+1]&1){y[ka]=1;ia+=t-4*E;break}Wb=w}w=Ua.canvas;t=pa.canvas;E=4*x;const Q=x*oa,P=S;let T=0;for(let ka=0,ia=0,Y=0;ka<I;++ka,ia+=S){if(!y[ka]){Y+=E;continue}++T;pa.clearRect(0,P,Q,S);let Ea,Fa,Ma,Na;for(let va=0;va<Q;va+=oa,Y+=4){const Xb=H[Y+0];var J=H[Y+1];const Yb=H[Y+2],Zb=H[Y+3],$b=J&2?Fb:Eb;J=(!(J&1)||nb)&&Vb[($b<<8)+Xb];Ma!==Yb&&(void 0!==Ma&&(R.fillStyle=c(Ma),R.fillRect(Na,
19
+ if(266<w-Wb){nb=!nb;pb&&(y[n]=1);var t=4*x;for(let la=0,ia=0;la<I;++la)if(y[la])ia+=t;else for(var E=0;E<x;++E,ia+=4)if(H[ia+1]&1){y[la]=1;ia+=t-4*E;break}Wb=w}w=Ua.canvas;t=pa.canvas;E=4*x;const Q=x*oa,P=S;let T=0;for(let la=0,ia=0,Y=0;la<I;++la,ia+=S){if(!y[la]){Y+=E;continue}++T;pa.clearRect(0,P,Q,S);let Ea,Fa,Ma,Na;for(let va=0;va<Q;va+=oa,Y+=4){const Xb=H[Y+0];var J=H[Y+1];const Yb=H[Y+2],Zb=H[Y+3],$b=J&2?Fb:Eb;J=(!(J&1)||nb)&&Vb[($b<<8)+Xb];Ma!==Yb&&(void 0!==Ma&&(R.fillStyle=c(Ma),R.fillRect(Na,
20
20
  ia,va-Na,S)),Ma=Yb,Na=va);Ea!==Zb&&(void 0!==Ea&&(pa.fillStyle=c(Ea),pa.fillRect(Fa,0,va-Fa,S)),Ea=Zb,Fa=va);J&&pa.drawImage(w,Xb*oa,$b*S,oa,S,va,P,oa,S)}pa.fillStyle=c(Ea);pa.fillRect(Fa,0,Q-Fa,S);pa.globalCompositeOperation="destination-in";pa.drawImage(t,0,P,Q,S,0,0,Q,S);pa.globalCompositeOperation="source-over";R.fillStyle=c(Ma);R.fillRect(Na,ia,Q-Na,S);R.drawImage(t,0,0,Q,S,0,ia,Q,S)}T&&(nb&&pb&&y[n]&&(R.fillStyle=c(H[4*(n*x+p)+3]),R.fillRect(p*oa,n*S+ob,oa,Gb-ob+1)),y.fill(0));T&&k.drawImage(R.canvas,
21
21
  0,0)}};this.destroy=function(){rb&&(cancelAnimationFrame(rb),rb=0)};this.pause=function(){Ib=!0;m.classList.remove("blinking-cursor")};this.continue=function(){Ib=!1;m.classList.add("blinking-cursor")};this.set_mode=function(w){u=w?1:a.use_graphical_text?2:0;0===u?(l.style.display="block",g.style.display="none"):(l.style.display="none",g.style.display="block",2===u&&y&&y.fill(1))};this.set_font_bitmap=function(w,t,E,J,Q,P){const T=E?16:t?9:8;if(S!==w||oa!==T||Cb!==t||Bb!==E||Db!==J||P)P=oa!==T||S!==
22
22
  w,S=w,oa=T,Cb=t,Bb=E,Db=J,2===u&&(d(Q),y.fill(1),P&&this.set_size_graphical_text())};this.set_font_page=function(w,t){if(Eb!==w||Fb!==t)Eb=w,Fb=t,y.fill(1)};this.clear_screen=function(){k.fillStyle="#000";k.fillRect(0,0,g.width,g.height)};this.set_size_graphical_text=function(){if(Ua){var w=oa*x,t=S*I,E=2*S;R&&R.canvas.width===w&&R.canvas.height===t&&pa.canvas.height===E||(R?(R.canvas.width=w,R.canvas.height=t,pa.canvas.width=w,pa.canvas.height=E):(R=(new OffscreenCanvas(w,t)).getContext("2d",{alpha:!1}),
23
23
  pa=(new OffscreenCanvas(w,E)).getContext("2d")),this.set_size_graphical(w,t,w,t),y.fill(1))}};this.set_size_text=function(w,t){if(w!==x||t!==I)if(y=new Int8Array(t),H=new Int32Array(w*t*4),x=w,I=t,0===u){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===u&&this.set_size_graphical_text()};this.set_size_graphical=function(w,t){g.style.display="block";g.width=w;
24
24
  g.height=t;k.imageSmoothingEnabled=!1;z=640>=w&&2*w<window.innerWidth*window.devicePixelRatio&&2*t<window.innerHeight*window.devicePixelRatio?2:1;e(g,q*z,r*z,!1)};this.set_charmap=function(w){qb=w||Hb};this.set_scale=function(w,t){q=w;r=t;e(l,q,r,!0);e(g,q*z,r*z,!1)};this.update_cursor_scanline=function(w,t,E){if(w!==ob||t!==Gb||E!==pb)0===u?E?(m.style.display="inline",m.style.height=t-w+"px",m.style.marginTop=w+"px"):m.style.display="none":2===u&&n<I&&(y[n]=1),ob=w,Gb=t,pb=E};this.update_cursor=
25
- function(w,t){if(w!==n||t!==p)w<I&&(y[w]=1),n<I&&(y[n]=1),n=w,p=t};this.text_update_row=function(w){var t=4*w*x,E;var J=l.childNodes[w];var Q=document.createElement("div");for(var P=0;P<x;){var T=document.createElement("span");var ka=H[t+1]&1;var ia=H[t+2];var Y=H[t+3];ka&&T.classList.add("blink");T.style.backgroundColor=c(ia);T.style.color=c(Y);for(E="";P<x&&(H[t+1]&1)===ka&&H[t+2]===ia&&H[t+3]===Y;)if(E+=qb[H[t+0]],P++,t+=4,w===n)if(P===p)break;else if(P===p+1){m.style.backgroundColor=T.style.color;
25
+ function(w,t){if(w!==n||t!==p)w<I&&(y[w]=1),n<I&&(y[n]=1),n=w,p=t};this.text_update_row=function(w){var t=4*w*x,E;var J=l.childNodes[w];var Q=document.createElement("div");for(var P=0;P<x;){var T=document.createElement("span");var la=H[t+1]&1;var ia=H[t+2];var Y=H[t+3];la&&T.classList.add("blink");T.style.backgroundColor=c(ia);T.style.color=c(Y);for(E="";P<x&&(H[t+1]&1)===la&&H[t+2]===ia&&H[t+3]===Y;)if(E+=qb[H[t+0]],P++,t+=4,w===n)if(P===p)break;else if(P===p+1){m.style.backgroundColor=T.style.color;
26
26
  Q.appendChild(m);break}T.textContent=E;Q.appendChild(T)}J.parentNode.replaceChild(Q,J)};this.update_buffer=function(w){for(const t of w)k.putImageData(t.image_data,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<I;t++)w.push(this.get_text_row(t));return w};this.get_text_row=function(w){let t="";for(let E=0;E<x;E++)t+=qb[H[4*(w*x+E)]];return t};this.init()};function wa(a){this.buffer=a;this.byteLength=a.byteLength;this.onprogress=this.onload=void 0}wa.prototype.load=function(){this.onload&&this.onload({buffer:this.buffer})};wa.prototype.get=function(a,b,c){c(new Uint8Array(this.buffer,a,b))};wa.prototype.set=function(a,b,c){(new Uint8Array(this.buffer,a,b.byteLength)).set(b);c()};wa.prototype.get_buffer=function(a){a(this.buffer)};wa.prototype.get_state=function(){const a=[];a[0]=this.byteLength;a[1]=new Uint8Array(this.buffer);return a};
27
27
  wa.prototype.set_state=function(a){this.byteLength=a[0];this.buffer=a[1].slice().buffer};function xa(a,b,c){this.filename=a;this.byteLength=b;this.block_cache=new Map;this.block_cache_is_write=new Set;this.fixed_chunk_size=c;this.cache_reads=!!c;this.onprogress=this.onload=void 0}xa.prototype.load=function(){void 0!==this.byteLength?this.onload&&this.onload(Object.create(null)):ya(this.filename,(a,b)=>{if(a)throw Error("Cannot use: "+this.filename+". "+a);this.byteLength=b;this.onload&&this.onload(Object.create(null))})};
28
28
  xa.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};
@@ -68,7 +68,7 @@ var Da={4:"PORT_DMA_ADDR_2",5:"PORT_DMA_CNT_2",10:"PORT_DMA1_MASK_REG",11:"PORT_
68
68
  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",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",
69
69
  1297:"PORT_QEMU_CFG_DATA",45056:"PORT_ACPI_PM_BASE",45312:"PORT_SMB_BASE",35072:"PORT_BIOS_APM"};C.prototype.get_port_description=function(a){return Da[a]?" ("+Da[a]+")":""};var Ga={};function Ha(){this.listeners={};this.pair=void 0}Ha.prototype.register=function(a,b,c){var d=this.listeners[a];void 0===d&&(d=this.listeners[a]=[]);d.push({fn:b,this_value:c})};Ha.prototype.unregister=function(a,b){var c=this.listeners[a];void 0!==c&&(this.listeners[a]=c.filter(function(d){return d.fn!==b}))};Ha.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)}};
70
70
  Ha.prototype.send_async=function(a,b){setTimeout(this.send.bind(this,a,b),0)};Ga.create=function(){var a=new Ha,b=new Ha;a.pair=b;b.pair=a;return[a,b]};var Ia=new Uint8Array(256),Ja=[],Ka=[],La=[],Oa=new Uint8Array(256),Pa=[];
71
- function D(a,b){this.cpu=a;this.bus=b;this.write_buffer=new ja(64);this.read_buffer=new ja(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 la(65536),new la(65536)];this.dma=a.devices.dma;this.dma_channel=this.dma_irq=this.dma_bytes_block=this.dma_bytes_left=
71
+ function D(a,b){this.cpu=a;this.bus=b;this.write_buffer=new ja(64);this.read_buffer=new ja(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 ka(65536),new ka(65536)];this.dma=a.devices.dma;this.dma_channel=this.dma_irq=this.dma_bytes_block=this.dma_bytes_left=
72
72
  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 wa(this.dma_buffer);this.dma_paused=this.dma_waiting_transfer=!1;this.sampling_rate=22050;b.send("dac-tell-sampling-rate",
73
73
  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 ja(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,this.port2x3_read);a.io.register_read_consecutive(904,this,this.port2x0_read,this.port2x1_read);
74
74
  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);a.io.register_read(557,this,this.port2xD_read);a.io.register_read_consecutive(558,this,this.port2xE_read,
@@ -200,9 +200,10 @@ single_handler:!1,handlers:[()=>{},c=>{const d=this.virtio.queues[c],e=3<c?c-3>>
200
200
  read:()=>this.ports,write:()=>{}},{bytes:4,name:"emerg_wr",read:()=>0,write:()=>{}}]}});for(let c=0;c<this.ports;++c){const d=0===c?0:2*c+2;this.bus.register("virtio-console"+c+"-input-bytes",function(e){var f=this.virtio.queues[d];f.has_request()&&(f=f.pop_request(),this.Send(d,f,new Uint8Array(e)))},this);this.bus.register("virtio-console"+c+"-resize",function(e){0===c&&(this.cols=e[0],this.rows=e[1]);this.virtio.queues[2].is_configured()&&this.virtio.queues[2].has_request()&&this.SendWindowSize(c,
201
201
  e[0],e[1])},this)}}lb.prototype.SendWindowSize=function(a,b,c){c=c||this.rows;b=b||this.cols;const d=this.virtio.queues[2].pop_request(),e=new Uint8Array(12);M.Marshall(["w","h","h","h","h"],[a,5,0,c,b],e,0);this.Send(2,d,e)};lb.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);M.Marshall(["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)};
202
202
  lb.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.rows;a[2]=this.cols;a[3]=this.ports;return a};lb.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.rows=a[1];this.cols=a[2];this.ports=a[3]};lb.prototype.reset=function(){this.virtio.reset()};lb.prototype.SendEvent=function(a,b,c){const d=this.virtio.queues[2].pop_request(),e=new Uint8Array(8);M.Marshall(["w","h","h"],[a,b,c],e,0);this.Send(2,d,e)};
203
- lb.prototype.Send=function(a,b,c){b.set_next_blob(c);this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};lb.prototype.Ack=function(a,b){b.set_next_blob(new Uint8Array(0));this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};function sb(a,b){this.cpu=a;this.bus=b;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=this.next_is_mouse_command=this.enable_keyboard_stream=!1;this.kbd_buffer=new ja(1024);this.last_port60_byte=0;this.sample_rate=100;this.mouse_id=this.mouse_detect_state=0;this.mouse_reset_workaround=!1;
204
- this.wheel_movement=0;this.resolution=4;this.scaling2=!1;this.last_mouse_packet=-1;this.mouse_buffer=new ja(1024);this.next_byte_is_aux=this.next_byte_is_ready=!1;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-=
205
- 2*c[1];this.wheel_movement=Math.min(7,Math.max(-8,this.wheel_movement));this.send_mouse_packet(0,0)},this);this.command_register=5;this.controller_output_port=0;this.read_controller_output_port=this.read_command_register=this.read_output_register=!1;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)}
203
+ lb.prototype.Send=function(a,b,c){b.set_next_blob(c);this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};lb.prototype.Ack=function(a,b){b.set_next_blob(new Uint8Array(0));this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};function sb(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));this.send_mouse_packet(0,0)},this);a.io.register_read(96,
204
+ 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)}
205
+ sb.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=this.next_is_mouse_command=this.enable_keyboard_stream=!1;this.kbd_buffer=new ja(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=
206
+ 0;this.resolution=4;this.scaling2=!1;this.last_mouse_packet=-1;this.mouse_buffer=new ja(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=!1};
206
207
  sb.prototype.get_state=function(){var a=[];a[0]=this.enable_mouse_stream;a[1]=this.use_mouse;a[2]=this.have_mouse;a[3]=this.mouse_delta_x;a[4]=this.mouse_delta_y;a[5]=this.mouse_clicks;a[6]=this.have_keyboard;a[7]=this.enable_keyboard_stream;a[8]=this.next_is_mouse_command;a[9]=this.next_read_sample;a[10]=this.next_read_led;a[11]=this.next_handle_scan_code_set;a[12]=this.next_read_rate;a[13]=this.next_read_resolution;a[15]=this.last_port60_byte;a[16]=this.sample_rate;a[17]=this.resolution;a[18]=this.scaling2;
207
208
  a[20]=this.command_register;a[21]=this.read_output_register;a[22]=this.read_command_register;a[23]=this.controller_output_port;a[24]=this.read_controller_output_port;a[25]=this.mouse_id;a[26]=this.mouse_detect_state;a[27]=this.mouse_reset_workaround;return a};
208
209
  sb.prototype.set_state=function(a){this.enable_mouse_stream=a[0];this.use_mouse=a[1];this.have_mouse=a[2];this.mouse_delta_x=a[3];this.mouse_delta_y=a[4];this.mouse_clicks=a[5];this.have_keyboard=a[6];this.enable_keyboard_stream=a[7];this.next_is_mouse_command=a[8];this.next_read_sample=a[9];this.next_read_led=a[10];this.next_handle_scan_code_set=a[11];this.next_read_rate=a[12];this.next_read_resolution=a[13];this.last_port60_byte=a[15];this.sample_rate=a[16];this.resolution=a[17];this.scaling2=a[18];
@@ -422,8 +423,9 @@ this.devices.uart1.set_state(a[79]);this.devices.uart2&&this.devices.uart2.set_s
422
423
  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];const b=new ma(a[78].buffer);this.unpack_memory(b,a[77]);this.update_state_flags();this.full_clear_tlb();this.jit_clear_cache()};
423
424
  K.prototype.set_state_pic=function(a){const b=new Uint8Array(this.wasm_memory.buffer,this.get_pic_addr_master(),13),c=new Uint8Array(this.wasm_memory.buffer,this.get_pic_addr_slave(),13);b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];const d=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];b[9]=a[9];b[10]=a[10];b[11]=a[11];b[12]=a[12];c[0]=d[0];c[1]=d[1];c[2]=d[2];c[3]=d[3];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]};
424
425
  K.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 ma(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}};
425
- K.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++}};K.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.load_bios()};
426
- K.prototype.reset_memory=function(){this.mem8.fill(0)};K.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=v(Uint8Array,this.wasm_memory,b,a);this.mem32s=v(Uint32Array,this.wasm_memory,b,a>>2)};
426
+ K.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++}};
427
+ K.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()};K.prototype.reset_memory=function(){this.mem8.fill(0)};
428
+ K.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=v(Uint8Array,this.wasm_memory,b,a);this.mem32s=v(Uint32Array,this.wasm_memory,b,a>>2)};
427
429
  K.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 C(this);this.io=c;this.bios.main=a.bios;this.bios.vga=a.vga_bios;this.load_bios();if(a.bzimage){const e=Tb(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,
428
430
  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 k(l){return l<<24|l<<8&16711680|l>>8&65280|l>>>24}sa("bios config port, index="+A(e));this.fw_pointer=0;if(0===e)this.fw_value=f(1431127377);else if(1===e)this.fw_value=
429
431
  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]=k(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]=k(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=