v86 0.5.121 → 0.5.155
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/Readme.md +2 -1
- package/build/libv86-debug.js +675 -687
- package/build/libv86-debug.mjs +490 -489
- package/build/libv86.js +93 -93
- package/build/libv86.mjs +179 -180
- package/build/v86-debug.wasm +0 -0
- package/build/v86-fallback.wasm +0 -0
- package/build/v86.wasm +0 -0
- package/package.json +1 -1
package/build/libv86.js
CHANGED
|
@@ -8,22 +8,22 @@ function oa(a){"number"===typeof a?this.view=new Uint8Array(a+7>>3):a instanceof
|
|
|
8
8
|
if("undefined"===typeof XMLHttpRequest||"undefined"!==typeof process&&process.versions&&process.versions.node){let a;pa=async function(b,c){a||(a=await import("node:fs/promises"));if(c.range){b=await a.open(b,"r");const d=Buffer.allocUnsafe(c.range.length);try{await b.read({buffer:d,position:c.range.start})}finally{await b.close()}c.done&&c.done(new Uint8Array(d))}else b=await a.readFile(b,{encoding:c.as_json?"utf-8":null}),b=c.as_json?JSON.parse(b):(new Uint8Array(b)).buffer,c.done(b)};qa=async function(b){a||
|
|
9
9
|
(a=await import("node:fs/promises"));return(await a.stat(b)).size}}else pa=async function(a,b,c){function d(){const l=c||0;setTimeout(()=>{pa(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 h=f[g];e.setRequestHeader(h,b.headers[h])}b.range&&(f=b.range.start,e.setRequestHeader("Range","bytes="+f+"-"+(f+b.range.length-1)),e.setRequestHeader("X-Accept-Encoding",
|
|
10
10
|
"identity"),e.onreadystatechange=function(){200===e.status&&(console.error("Server sent full file in response to ranged request, aborting",{filename:a}),e.abort())});e.onload=function(){if(4===e.readyState)if(200!==e.status&&206!==e.status)console.error("Loading the image "+a+" failed (status %d)",e.status),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",
|
|
11
|
-
{filename:a,enc:l})}b.done&&b.done(e.response,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)},qa=async function(a){return new Promise((b,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(){}function sa(){};function ta(a,b){function c(v){v=v.toString(16);return"#"+"0".repeat(6-v.length)+v}function d(v){var t=256*ma,C=8*Q,
|
|
12
|
-
ja);R=!1;for(let Ka=0;Ka<Q;++Ka,++Da,N+=fa){const La=v[Da];for(let ua=128;0<ua;ua>>=1)C(La&ua?255:0);
|
|
13
|
-
(g.style.imageRendering="",g.style["-ms-interpolation-mode"]=""),
|
|
14
|
-
a.scale:1,r=void 0!==a.scale?a.scale:1,y=1,x,u,
|
|
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 C=0,
|
|
16
|
-
C,
|
|
17
|
-
|
|
18
|
-
this.put_char=function(v,t,C,
|
|
19
|
-
if(266<v-Xb){mb=!mb;ob&&(x[n]=1);var t=4*w;for(let ja=0,fa=0;ja<
|
|
20
|
-
fa,ua-La,Q)),Ka=Zb,La=ua);Da!==$b&&(void 0!==Da&&(na.fillStyle=c(Da),na.fillRect(Ea,0,ua-Ea,Q)),Da=$b,Ea=ua);
|
|
21
|
-
0,0)}};this.destroy=function(){qb&&(cancelAnimationFrame(qb),qb=0)};this.pause=function(){
|
|
22
|
-
v,Q=v,ma=R,
|
|
23
|
-
na=(new OffscreenCanvas(v,C)).getContext("2d")),this.set_size_graphical(v,t,v,t),x.fill(1))}};this.set_size_text=function(v,t){if(v!==w||t!==
|
|
24
|
-
g.height=t;h.imageSmoothingEnabled=!1;y=640>=v&&2*v<window.innerWidth*window.devicePixelRatio&&2*t<window.innerHeight*window.devicePixelRatio?2:1;e(g,q*y,r*y,!1)};this.set_charmap=function(v){pb=v||
|
|
25
|
-
function(v,t){if(v!==n||t!==p)v<
|
|
26
|
-
O.appendChild(m);break}R.textContent=C;O.appendChild(R)}
|
|
11
|
+
{filename:a,enc:l})}b.done&&b.done(e.response,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)},qa=async function(a){return new Promise((b,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(){}function sa(){};function ta(a,b){function c(v){v=v.toString(16);return"#"+"0".repeat(6-v.length)+v}function d(v){var t=256*ma,C=8*Q,K=Sa?Sa.canvas:null;K&&K.width===t&&K.height===C||(K?(K.width=t,K.height=C):(K=new OffscreenCanvas(t,C),Sa=K.getContext("2d")),Ab=Sa.createImageData(t,C));const O=Ab.data;let N=0,R;C=Bb?function(X){R=R||X;O[N+3]=X;O[N+7]=X;N+=8}:function(X){R=R||X;O[N+3]=X;N+=4};K=32-Q;const ja=t*(Q-1)*4;t=4*(ma-t*Q);const fa=1020*ma;for(let X=0,Da=0;2048>X;++X,Da+=K,N+=t){const Ea=X%256;X&&!Ea&&(N+=
|
|
12
|
+
ja);R=!1;for(let Ka=0;Ka<Q;++Ka,++Da,N+=fa){const La=v[Da];for(let ua=128;0<ua;ua>>=1)C(La&ua?255:0);Cb&&C(Db&&192<=Ea&&223>=Ea&&La&1?255:0)}Wb[X]=R?1:0}Sa.putImageData(Ab,0,0)}function e(v,t,C,K){if(t&&C){v.style.width="";v.style.height="";K&&(v.style.transform="");var O=v.getBoundingClientRect();K?v.style.transform=(1===t?"":" scaleX("+t+")")+(1===C?"":" scaleY("+C+")"):(0===t%1&&0===C%1?(g.style.imageRendering="crisp-edges",g.style.imageRendering="pixelated",g.style["-ms-interpolation-mode"]="nearest-neighbor"):
|
|
13
|
+
(g.style.imageRendering="",g.style["-ms-interpolation-mode"]=""),K=window.devicePixelRatio||1,0!==K%1&&(t/=K,C/=K));1!==t&&(v.style.width=O.width*t+"px");1!==C&&(v.style.height=O.height*C+"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],h=g.getContext("2d",{alpha:!1}),l=f.getElementsByTagName("div")[0],m=document.createElement("div"),n,p,q=void 0!==a.scale?
|
|
14
|
+
a.scale:1,r=void 0!==a.scale?a.scale:1,y=1,x,u,H,w,J,P,na,Sa,Ab,Wb=new Int8Array(2048),Q,ma,Cb,Bb,Db,Eb=0,Fb=0,mb,Xb=0,nb,Gb,ob,Hb=[],pb=Hb,qb=0,Ib=!1;this.init=function(){const v=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
|
+
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 C=0,K;256>C;C++)K=126<C?t[C-127]:32>C?v[C]:
|
|
16
|
+
C,Hb.push(String.fromCharCode(K));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 v=new Image;if(1===u||2===u)v.src=g.toDataURL("image/png");else{const t=[9,16],C=document.createElement("canvas");C.width=w*t[0];C.height=J*t[1];const K=C.getContext("2d");
|
|
17
|
+
K.imageSmoothingEnabled=!1;K.font=window.getComputedStyle(l).font;K.textBaseline="top";for(let O=0;O<J;O++)for(let N=0;N<w;N++){const R=4*(O*w+N),ja=H[R+0],fa=H[R+3];K.fillStyle=c(H[R+2]);K.fillRect(N*t[0],O*t[1],t[0],t[1]);K.fillStyle=c(fa);K.fillText(pb[ja],N*t[0],O*t[1])}"none"!==m.style.display&&n<J&&p<w&&(K.fillStyle=m.style.backgroundColor,K.fillRect(p*t[0],n*t[1]+parseInt(m.style.marginTop,10),parseInt(m.style.width,10),parseInt(m.style.height,10)));v.src=C.toDataURL("image/png")}return v};
|
|
18
|
+
this.put_char=function(v,t,C,K,O,N){t=4*(v*w+t);H[t+0]=C;H[t+1]=K;H[t+2]=O;H[t+3]=N;x[v]=1};this.timer=function(){qb=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 v=0;v<J;v++)x[v]&&(this.text_update_row(v),x[v]=0)};this.update_graphical=function(){this.screen_fill_buffer()};this.update_graphical_text=function(){if(P){var v=performance.now();
|
|
19
|
+
if(266<v-Xb){mb=!mb;ob&&(x[n]=1);var t=4*w;for(let ja=0,fa=0;ja<J;++ja)if(x[ja])fa+=t;else for(var C=0;C<w;++C,fa+=4)if(H[fa+1]&1){x[ja]=1;fa+=t-4*C;break}Xb=v}v=Sa.canvas;t=na.canvas;C=4*w;const O=w*ma,N=Q;let R=0;for(let ja=0,fa=0,X=0;ja<J;++ja,fa+=Q){if(!x[ja]){X+=C;continue}++R;na.clearRect(0,N,O,Q);let Da,Ea,Ka,La;for(let ua=0;ua<O;ua+=ma,X+=4){const Yb=H[X+0];var K=H[X+1];const Zb=H[X+2],$b=H[X+3],ac=K&2?Fb:Eb;K=(!(K&1)||mb)&&Wb[(ac<<8)+Yb];Ka!==Zb&&(void 0!==Ka&&(P.fillStyle=c(Ka),P.fillRect(La,
|
|
20
|
+
fa,ua-La,Q)),Ka=Zb,La=ua);Da!==$b&&(void 0!==Da&&(na.fillStyle=c(Da),na.fillRect(Ea,0,ua-Ea,Q)),Da=$b,Ea=ua);K&&na.drawImage(v,Yb*ma,ac*Q,ma,Q,ua,N,ma,Q)}na.fillStyle=c(Da);na.fillRect(Ea,0,O-Ea,Q);na.globalCompositeOperation="destination-in";na.drawImage(t,0,N,O,Q,0,0,O,Q);na.globalCompositeOperation="source-over";P.fillStyle=c(Ka);P.fillRect(La,fa,O-La,Q);P.drawImage(t,0,0,O,Q,0,fa,O,Q)}R&&(mb&&ob&&x[n]&&(P.fillStyle=c(H[4*(n*w+p)+3]),P.fillRect(p*ma,n*Q+nb,ma,Gb-nb+1)),x.fill(0));R&&h.drawImage(P.canvas,
|
|
21
|
+
0,0)}};this.destroy=function(){qb&&(cancelAnimationFrame(qb),qb=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(v){u=v?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&&x&&x.fill(1))};this.set_font_bitmap=function(v,t,C,K,O,N){const R=C?16:t?9:8;if(Q!==v||ma!==R||Cb!==t||Bb!==C||Db!==K||N)N=ma!==R||Q!==
|
|
22
|
+
v,Q=v,ma=R,Cb=t,Bb=C,Db=K,2===u&&(d(O),x.fill(1),N&&this.set_size_graphical_text())};this.set_font_page=function(v,t){if(Eb!==v||Fb!==t)Eb=v,Fb=t,x.fill(1)};this.clear_screen=function(){h.fillStyle="#000";h.fillRect(0,0,g.width,g.height)};this.set_size_graphical_text=function(){if(Sa){var v=ma*w,t=Q*J,C=2*Q;P&&P.canvas.width===v&&P.canvas.height===t&&na.canvas.height===C||(P?(P.canvas.width=v,P.canvas.height=t,na.canvas.width=v,na.canvas.height=C):(P=(new OffscreenCanvas(v,t)).getContext("2d",{alpha:!1}),
|
|
23
|
+
na=(new OffscreenCanvas(v,C)).getContext("2d")),this.set_size_graphical(v,t,v,t),x.fill(1))}};this.set_size_text=function(v,t){if(v!==w||t!==J)if(x=new Int8Array(t),H=new Int32Array(v*t*4),w=v,J=t,0===u){for(;l.childNodes.length>t;)l.removeChild(l.firstChild);for(;l.childNodes.length<t;)l.appendChild(document.createElement("div"));for(v=0;v<t;v++)this.text_update_row(v);e(l,q,r,!0)}else 2===u&&this.set_size_graphical_text()};this.set_size_graphical=function(v,t){g.style.display="block";g.width=v;
|
|
24
|
+
g.height=t;h.imageSmoothingEnabled=!1;y=640>=v&&2*v<window.innerWidth*window.devicePixelRatio&&2*t<window.innerHeight*window.devicePixelRatio?2:1;e(g,q*y,r*y,!1)};this.set_charmap=function(v){pb=v||Hb};this.set_scale=function(v,t){q=v;r=t;e(l,q,r,!0);e(g,q*y,r*y,!1)};this.update_cursor_scanline=function(v,t,C){if(v!==nb||t!==Gb||C!==ob)0===u?C?(m.style.display="inline",m.style.height=t-v+"px",m.style.marginTop=v+"px"):m.style.display="none":2===u&&n<J&&(x[n]=1),nb=v,Gb=t,ob=C};this.update_cursor=
|
|
25
|
+
function(v,t){if(v!==n||t!==p)v<J&&(x[v]=1),n<J&&(x[n]=1),n=v,p=t};this.text_update_row=function(v){var t=4*v*w,C;var K=l.childNodes[v];var O=document.createElement("div");for(var N=0;N<w;){var R=document.createElement("span");var ja=H[t+1]&1;var fa=H[t+2];var X=H[t+3];ja&&R.classList.add("blink");R.style.backgroundColor=c(fa);R.style.color=c(X);for(C="";N<w&&(H[t+1]&1)===ja&&H[t+2]===fa&&H[t+3]===X;)if(C+=pb[H[t+0]],N++,t+=4,v===n)if(N===p)break;else if(N===p+1){m.style.backgroundColor=R.style.color;
|
|
26
|
+
O.appendChild(m);break}R.textContent=C;O.appendChild(R)}K.parentNode.replaceChild(O,K)};this.update_buffer=function(v){for(const t of v)h.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 v=[],t=0;t<J;t++)v.push(this.get_text_row(t));return v};this.get_text_row=function(v){let t="";for(let C=0;C<w;C++)t+=pb[H[4*(v*w+C)]];return t};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,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};
|
|
27
27
|
A.prototype.set_state=function(a){this.byteLength=a[0];this.buffer=a[1].slice().buffer};function va(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}va.prototype.load=async function(){void 0===this.byteLength&&(this.byteLength=await qa(this.filename));this.onload&&this.onload(Object.create(null))};
|
|
28
28
|
va.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};
|
|
29
29
|
va.prototype.get=function(a,b,c){var d=this.get_from_cache(a,b);if(d)c(d);else{var e=a,f=b;this.fixed_chunk_size&&(e=a-a%this.fixed_chunk_size,f=Math.ceil((a-e+b)/this.fixed_chunk_size)*this.fixed_chunk_size);pa(this.filename,{done:function(g){g=new Uint8Array(g);this.handle_read(e,f,g);e===a&&f===b?c(g):c(g.subarray(a-e,a-e+b))}.bind(this),range:{start:e,length:f}})}};
|
|
@@ -62,7 +62,8 @@ D.prototype.register_write_consecutive=function(a,b,c,d,e,f){function g(m){c.cal
|
|
|
62
62
|
D.prototype.mmap_read32_shim=function(a){var b=this.cpu.memory_map_read8[a>>>17];return b(a)|b(a+1)<<8|b(a+2)<<16|b(a+3)<<24};D.prototype.mmap_write32_shim=function(a,b){var c=this.cpu.memory_map_write8[a>>>17];c(a,b&255);c(a+1,b>>8&255);c(a+2,b>>16&255);c(a+3,b>>>24)};
|
|
63
63
|
D.prototype.mmap_register=function(a,b,c,d,e,f){z(a>>>0,8);z(b,8);e||(e=this.mmap_read32_shim.bind(this));f||(f=this.mmap_write32_shim.bind(this));for(a>>>=17;0<b;a++)this.cpu.memory_map_read8[a]=c,this.cpu.memory_map_write8[a]=d,this.cpu.memory_map_read32[a]=e,this.cpu.memory_map_write32[a]=f,b-=131072};D.prototype.port_write8=function(a,b){var c=this.ports[a];c.write8===this.empty_port_write&&(z(a,4),z(b,2),this.get_port_description(a));return c.write8.call(c.device,b)};
|
|
64
64
|
D.prototype.port_write16=function(a,b){var c=this.ports[a];c.write16===this.empty_port_write&&(z(a,4),z(b,4),this.get_port_description(a));return c.write16.call(c.device,b)};D.prototype.port_write32=function(a,b){var c=this.ports[a];c.write32===this.empty_port_write&&(z(a,4),z(b>>>0,8),this.get_port_description(a));return c.write32.call(c.device,b)};
|
|
65
|
-
D.prototype.port_read8=function(a){var b=this.ports[a];b.read8===this.empty_port_read8&&(z(a,4),this.get_port_description(a));b=b.read8.call(b.device,a);z(a);return b};D.prototype.port_read16=function(a){var b=this.ports[a];b.read16===this.empty_port_read16&&(z(a,4),this.get_port_description(a));b=b.read16.call(b.device,a);
|
|
65
|
+
D.prototype.port_read8=function(a){var b=this.ports[a];b.read8===this.empty_port_read8&&(z(a,4),this.get_port_description(a));b=b.read8.call(b.device,a);(0>b||256<=b)&&z(a);return b};D.prototype.port_read16=function(a){var b=this.ports[a];b.read16===this.empty_port_read16&&(z(a,4),this.get_port_description(a));b=b.read16.call(b.device,a);(0>b||65536<=b)&&z(a);return b};
|
|
66
|
+
D.prototype.port_read32=function(a){var b=this.ports[a];b.read32===this.empty_port_read32&&(z(a,4),this.get_port_description(a));return b.read32.call(b.device,a)};
|
|
66
67
|
var Aa={4:"PORT_DMA_ADDR_2",5:"PORT_DMA_CNT_2",10:"PORT_DMA1_MASK_REG",11:"PORT_DMA1_MODE_REG",12:"PORT_DMA1_CLEAR_FF_REG",13:"PORT_DMA1_MASTER_CLEAR",32:"PORT_PIC1_CMD",33:"PORT_PIC1_DATA",64:"PORT_PIT_COUNTER0",65:"PORT_PIT_COUNTER1",66:"PORT_PIT_COUNTER2",67:"PORT_PIT_MODE",96:"PORT_PS2_DATA",97:"PORT_PS2_CTRLB",100:"PORT_PS2_STATUS",112:"PORT_CMOS_INDEX",113:"PORT_CMOS_DATA",128:"PORT_DIAG",129:"PORT_DMA_PAGE_2",146:"PORT_A20",160:"PORT_PIC2_CMD",161:"PORT_PIC2_DATA",178:"PORT_SMI_CMD",179:"PORT_SMI_STATUS",
|
|
67
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",
|
|
68
69
|
1297:"PORT_QEMU_CFG_DATA",45056:"PORT_ACPI_PM_BASE",45312:"PORT_SMB_BASE",35072:"PORT_BIOS_APM"};D.prototype.get_port_description=function(a){return Aa[a]?" ("+Aa[a]+")":""};var Ba={};function Ca(){this.listeners={};this.pair=void 0}Ca.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})};Ca.prototype.unregister=function(a,b){var c=this.listeners[a];void 0!==c&&(this.listeners[a]=c.filter(function(d){return d.fn!==b}))};Ca.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)}};
|
|
@@ -87,15 +88,15 @@ E.prototype.port2x2_write=function(a){z(a);this.fm_current_address1=0};E.prototy
|
|
|
87
88
|
E.prototype.port2x6_write=function(a){z(a);this.dsp_highspeed?this.dsp_highspeed=!1:a&&this.dsp_reset();this.read_buffer.clear();this.read_buffer.push(170)};E.prototype.port2x7_write=function(){};E.prototype.port2x8_write=function(){};E.prototype.port2x9_write=function(){};E.prototype.port2xA_write=function(){};E.prototype.port2xB_write=function(){};
|
|
88
89
|
E.prototype.port2xC_write=function(a){0===this.command?(z(a),this.command=a,this.write_buffer.clear(),this.command_size=Fa[a]):(z(a),this.write_buffer.push(a));this.write_buffer.length>=this.command_size&&this.command_do()};E.prototype.port2xD_write=function(){};E.prototype.port2xE_write=function(){};E.prototype.port2xF_write=function(){};
|
|
89
90
|
E.prototype.port3x0_read=function(){this.mpu_read_buffer.length&&(this.mpu_read_buffer_lastvalue=this.mpu_read_buffer.shift());z(this.mpu_read_buffer_lastvalue);return this.mpu_read_buffer_lastvalue};E.prototype.port3x0_write=function(a){z(a)};E.prototype.port3x1_read=function(){return 0|128*!this.mpu_read_buffer.length};E.prototype.port3x1_write=function(a){z(a);255===a&&(this.mpu_read_buffer.clear(),this.mpu_read_buffer.push(254))};
|
|
90
|
-
E.prototype.command_do=function(){var a=Ga[this.command];a||(a=this.dsp_default_handler);a.call(this);this.command_size=this.command=0;this.write_buffer.clear()};E.prototype.dsp_default_handler=function(){z(this.command)};function
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
Pa[14]=255;Pa[15]=7;Pa[55]=56;
|
|
91
|
+
E.prototype.command_do=function(){var a=Ga[this.command];a||(a=this.dsp_default_handler);a.call(this);this.command_size=this.command=0;this.write_buffer.clear()};E.prototype.dsp_default_handler=function(){z(this.command)};function F(a,b,c){c||(c=E.prototype.dsp_default_handler);for(var d=0;d<a.length;d++)Fa[a[d]]=b,Ga[a[d]]=c}function Na(a){for(var b=[],c=0;16>c;c++)b.push(a+c);return b}F([14],2,function(){this.asp_registers[this.write_buffer.shift()]=this.write_buffer.shift()});
|
|
92
|
+
F([15],1,function(){this.read_buffer.clear();this.read_buffer.push(this.asp_registers[this.write_buffer.shift()])});F([16],1,function(){var a=this.write_buffer.shift();a=Oa(a/127.5+-1,-1,1);this.dac_buffers[0].push(a);this.dac_buffers[1].push(a);this.bus.send("dac-enable")});F([20,21],2,function(){this.dma_irq=1;this.dma_channel=this.dma_channel_8bit;this.dsp_highspeed=this.dsp_16bit=this.dsp_signed=this.dma_autoinit=!1;this.dma_transfer_size_set();this.dma_transfer_start()});F([22],2);F([23],2);
|
|
93
|
+
F([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()});F([31],0);F([32],0,function(){this.read_buffer.clear();this.read_buffer.push(127)});F([36],2);F([44],0);F([48],0);F([49],0);F([52],0);F([53],0);F([54],0);F([55],0);F([56],0);F([64],1,function(){this.sampling_rate_change(1E6/(256-this.write_buffer.shift())/this.get_channel_count())});
|
|
94
|
+
F([65,66],2,function(){this.sampling_rate_change(this.write_buffer.shift()<<8|this.write_buffer.shift())});F([72],2,function(){this.dma_transfer_size_set()});F([116],2);F([117],2);F([118],2);F([119],2);F([125],0);F([127],0);F([128],2);F([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()});F([145],0);F([152],0);F([153],0);F([160],0);F([168],0);
|
|
95
|
+
F(Na(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()}});
|
|
96
|
+
F(Na(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;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()}});F([208],0,function(){this.dma_paused=!0;this.bus.send("dac-disable")});F([209],0,function(){this.dummy_speaker_enabled=!0});F([211],0,function(){this.dummy_speaker_enabled=!1});
|
|
97
|
+
F([212],0,function(){this.dma_paused=!1;this.bus.send("dac-enable")});F([213],0,function(){this.dma_paused=!0;this.bus.send("dac-disable")});F([214],0,function(){this.dma_paused=!1;this.bus.send("dac-enable")});F([216],0,function(){this.read_buffer.clear();this.read_buffer.push(255*this.dummy_speaker_enabled)});F([217,218],0,function(){this.dma_autoinit=!1});F([224],1,function(){this.read_buffer.clear();this.read_buffer.push(~this.write_buffer.shift())});
|
|
98
|
+
F([225],0,function(){this.read_buffer.clear();this.read_buffer.push(4);this.read_buffer.push(5)});F([226],1);F([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));this.read_buffer.push(0)});F([228],1,function(){this.test_register=this.write_buffer.shift()});F([232],0,function(){this.read_buffer.clear();this.read_buffer.push(this.test_register)});F([242,243],0,function(){this.raise_irq()});var Pa=new Uint8Array(256);
|
|
99
|
+
Pa[14]=255;Pa[15]=7;Pa[55]=56;F([249],1,function(){var a=this.write_buffer.shift();this.read_buffer.clear();this.read_buffer.push(Pa[a])});E.prototype.mixer_read=function(a){var b=Ha[a];b?b=b.call(this):(b=this.mixer_registers[a],z(a),z(b));return b};E.prototype.mixer_write=function(a,b){var c=Ia[a];c?c.call(this,b):(z(a),z(b))};E.prototype.mixer_default_read=function(){z(this.mixer_current_address);return this.mixer_registers[this.mixer_current_address]};
|
|
99
100
|
E.prototype.mixer_default_write=function(a){z(this.mixer_current_address);z(a);this.mixer_registers[this.mixer_current_address]=a};
|
|
100
101
|
E.prototype.mixer_reset=function(){this.mixer_registers[4]=204;this.mixer_registers[34]=204;this.mixer_registers[38]=204;this.mixer_registers[40]=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]=
|
|
101
102
|
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]=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()};E.prototype.mixer_full_update=function(){for(var a=1;a<this.mixer_registers.length;a++)Ja[a]||this.mixer_write(a,this.mixer_registers[a])};
|
|
@@ -126,18 +127,18 @@ db.prototype.timer=function(a){a=Date.now();this.rtc_time+=a-this.last_update;th
|
|
|
126
127
|
this.cmos_c|=144,this.update_interrupt_time=a+1E3);let b=100;this.periodic_interrupt&&this.next_interrupt&&(b=Math.min(b,Math.max(0,this.next_interrupt-a)));this.next_interrupt_alarm&&(b=Math.min(b,Math.max(0,this.next_interrupt_alarm-a)));this.update_interrupt&&(b=Math.min(b,Math.max(0,this.update_interrupt_time-a)));return b};db.prototype.bcd_pack=function(a){for(var b=0,c=0,d;a;)d=a%10,c|=d<<4*b,b++,a=(a-d)/10;return c};db.prototype.bcd_unpack=function(a){return(a&15)+10*(a>>4&15)};
|
|
127
128
|
db.prototype.encode_time=function(a){return this.cmos_b&4?a:this.bcd_pack(a)};db.prototype.decode_time=function(a){return this.cmos_b&4?a:this.bcd_unpack(a)};
|
|
128
129
|
db.prototype.cmos_port_read=function(){var a=this.cmos_index;switch(a){case 0:return z(this.encode_time((new Date(this.rtc_time)).getUTCSeconds())),this.encode_time((new Date(this.rtc_time)).getUTCSeconds());case 2:return z(this.encode_time((new Date(this.rtc_time)).getUTCMinutes())),this.encode_time((new Date(this.rtc_time)).getUTCMinutes());case 4:return z(this.encode_time((new Date(this.rtc_time)).getUTCHours())),this.encode_time((new Date(this.rtc_time)).getUTCHours());case 6:return z(this.encode_time((new Date(this.rtc_time)).getUTCDay()+
|
|
129
|
-
1)),this.encode_time((new Date(this.rtc_time)).getUTCDay()+1);case 7:return z(this.encode_time((new Date(this.rtc_time)).getUTCDate())),this.encode_time((new Date(this.rtc_time)).getUTCDate());case 8:return z(this.encode_time((new Date(this.rtc_time)).getUTCMonth()+1)),this.encode_time((new Date(this.rtc_time)).getUTCMonth()+1);case 9:return z(this.encode_time((new Date(this.rtc_time)).getUTCFullYear()%100)),this.encode_time((new Date(this.rtc_time)).getUTCFullYear()%100);case 10:return 999<=
|
|
130
|
+
1)),this.encode_time((new Date(this.rtc_time)).getUTCDay()+1);case 7:return z(this.encode_time((new Date(this.rtc_time)).getUTCDate())),this.encode_time((new Date(this.rtc_time)).getUTCDate());case 8:return z(this.encode_time((new Date(this.rtc_time)).getUTCMonth()+1)),this.encode_time((new Date(this.rtc_time)).getUTCMonth()+1);case 9:return z(this.encode_time((new Date(this.rtc_time)).getUTCFullYear()%100)),this.encode_time((new Date(this.rtc_time)).getUTCFullYear()%100);case 10:return 999<=G.microtick()%
|
|
130
131
|
1E3?this.cmos_a|128:this.cmos_a;case 11:return this.cmos_b;case 12:return this.cpu.device_lower_irq(8),a=this.cmos_c,this.cmos_c&=-241,a;case 13:return 0;case 50:case 55:return z(this.encode_time((new Date(this.rtc_time)).getUTCFullYear()/100|0)),this.encode_time((new Date(this.rtc_time)).getUTCFullYear()/100|0);default:return z(a),this.cmos_data[this.cmos_index]}};
|
|
131
132
|
db.prototype.cmos_port_write=function(a){switch(this.cmos_index){case 10:this.cmos_a=a&127;this.periodic_interrupt_time=1E3/(32768>>(this.cmos_a&15)-1);z(this.cmos_a,2);break;case 11:this.cmos_b=a;this.cmos_b&128&&(this.cmos_b&=239);this.cmos_b&64&&(this.next_interrupt=Date.now());if(this.cmos_b&32){a=new Date;const b=this.decode_time(this.cmos_data[1]),c=this.decode_time(this.cmos_data[3]),d=this.decode_time(this.cmos_data[5]);this.next_interrupt_alarm=+new Date(Date.UTC(a.getUTCFullYear(),a.getUTCMonth(),
|
|
132
|
-
a.getUTCDate(),d,c,b))}this.cmos_b&16&&(this.update_interrupt_time=Date.now());z(this.cmos_b,2);break;case 1:case 3:case 5:this.cmos_write(this.cmos_index,a);break;default:z(this.cmos_index),z(a)}this.update_interrupt=16===(this.cmos_b&16)&&0<(this.cmos_a&15);this.periodic_interrupt=64===(this.cmos_b&64)&&0<(this.cmos_a&15)};db.prototype.cmos_read=function(a){return this.cmos_data[a]};db.prototype.cmos_write=function(a,b){z(a);z(b);this.cmos_data[a]=b};function eb(a,b){this.cpu=a;this.bus=b;this.counter_start_time=new Float64Array(3);this.counter_start_value=new Uint16Array(3);this.counter_next_low=new Uint8Array(4);this.counter_enabled=new Uint8Array(4);this.counter_mode=new Uint8Array(4);this.counter_read_mode=new Uint8Array(4);this.counter_latch=new Uint8Array(4);this.counter_latch_value=new Uint16Array(3);this.counter_reload=new Uint16Array(3);a.io.register_read(97,this,function(){var c=
|
|
133
|
+
a.getUTCDate(),d,c,b))}this.cmos_b&16&&(this.update_interrupt_time=Date.now());z(this.cmos_b,2);break;case 1:case 3:case 5:this.cmos_write(this.cmos_index,a);break;default:z(this.cmos_index),z(a)}this.update_interrupt=16===(this.cmos_b&16)&&0<(this.cmos_a&15);this.periodic_interrupt=64===(this.cmos_b&64)&&0<(this.cmos_a&15)};db.prototype.cmos_read=function(a){return this.cmos_data[a]};db.prototype.cmos_write=function(a,b){z(a);z(b);this.cmos_data[a]=b};function eb(a,b){this.cpu=a;this.bus=b;this.counter_start_time=new Float64Array(3);this.counter_start_value=new Uint16Array(3);this.counter_next_low=new Uint8Array(4);this.counter_enabled=new Uint8Array(4);this.counter_mode=new Uint8Array(4);this.counter_read_mode=new Uint8Array(4);this.counter_latch=new Uint8Array(4);this.counter_latch_value=new Uint16Array(3);this.counter_reload=new Uint16Array(3);a.io.register_read(97,this,function(){var c=G.microtick(),d=66.66666666666667*c&1;c=this.did_rollover(2,
|
|
133
134
|
c);return d<<4|c<<5});a.io.register_write(97,this,function(c){c&1?this.bus.send("pcspeaker-enable"):this.bus.send("pcspeaker-disable")});a.io.register_read(64,this,function(){return this.counter_read(0)});a.io.register_read(65,this,function(){return this.counter_read(1)});a.io.register_read(66,this,function(){return this.counter_read(2)});a.io.register_write(64,this,function(c){this.counter_write(0,c)});a.io.register_write(65,this,function(c){this.counter_write(1,c)});a.io.register_write(66,this,
|
|
134
135
|
function(c){this.counter_write(2,c);this.bus.send("pcspeaker-update",[this.counter_mode[2],this.counter_reload[2]])});a.io.register_write(67,this,this.port43_write)}eb.prototype.get_state=function(){var a=[];a[0]=this.counter_next_low;a[1]=this.counter_enabled;a[2]=this.counter_mode;a[3]=this.counter_read_mode;a[4]=this.counter_latch;a[5]=this.counter_latch_value;a[6]=this.counter_reload;a[7]=this.counter_start_time;a[8]=this.counter_start_value;return a};
|
|
135
136
|
eb.prototype.set_state=function(a){this.counter_next_low=a[0];this.counter_enabled=a[1];this.counter_mode=a[2];this.counter_read_mode=a[3];this.counter_latch=a[4];this.counter_latch_value=a[5];this.counter_reload=a[6];this.counter_start_time=a[7];this.counter_start_value=a[8]};
|
|
136
137
|
eb.prototype.timer=function(a,b){var c=100;b||(this.counter_enabled[0]&&this.did_rollover(0,a)?(this.counter_start_value[0]=this.get_counter_value(0,a),this.counter_start_time[0]=a,this.cpu.device_lower_irq(0),this.cpu.device_raise_irq(0),0===this.counter_mode[0]&&(this.counter_enabled[0]=0)):this.cpu.device_lower_irq(0),this.counter_enabled[0]&&(c=(this.counter_start_value[0]-Math.floor(1193.1816666*(a-this.counter_start_time[0])))/1193.1816666));return c};
|
|
137
138
|
eb.prototype.get_counter_value=function(a,b){if(!this.counter_enabled[a])return 0;b=this.counter_start_value[a]-Math.floor(1193.1816666*(b-this.counter_start_time[a]));a=this.counter_reload[a];b>=a?b%=a:0>b&&(b=b%a+a);return b};eb.prototype.did_rollover=function(a,b){b-=this.counter_start_time[a];return 0>b?!0:this.counter_start_value[a]<Math.floor(1193.1816666*b)};
|
|
138
|
-
eb.prototype.counter_read=function(a){var b=this.counter_latch[a];if(b)return this.counter_latch[a]--,2===b?this.counter_latch_value[a]&255:this.counter_latch_value[a]>>8;b=this.counter_next_low[a];3===this.counter_mode[a]&&(this.counter_next_low[a]^=1);a=this.get_counter_value(a,
|
|
139
|
-
eb.prototype.counter_write=function(a,b){this.counter_reload[a]=this.counter_next_low[a]?this.counter_reload[a]&-256|b:this.counter_reload[a]&255|b<<8;3===this.counter_read_mode[a]&&this.counter_next_low[a]||(this.counter_reload[a]||(this.counter_reload[a]=65535),this.counter_start_value[a]=this.counter_reload[a],this.counter_enabled[a]=!0,this.counter_start_time[a]=
|
|
140
|
-
eb.prototype.port43_write=function(a){var b=a>>1&7,c=a>>6&3;a=a>>4&3;3!==c&&(0===a?(this.counter_latch[c]=2,b=this.get_counter_value(c,
|
|
139
|
+
eb.prototype.counter_read=function(a){var b=this.counter_latch[a];if(b)return this.counter_latch[a]--,2===b?this.counter_latch_value[a]&255:this.counter_latch_value[a]>>8;b=this.counter_next_low[a];3===this.counter_mode[a]&&(this.counter_next_low[a]^=1);a=this.get_counter_value(a,G.microtick());return b?a&255:a>>8};
|
|
140
|
+
eb.prototype.counter_write=function(a,b){this.counter_reload[a]=this.counter_next_low[a]?this.counter_reload[a]&-256|b:this.counter_reload[a]&255|b<<8;3===this.counter_read_mode[a]&&this.counter_next_low[a]||(this.counter_reload[a]||(this.counter_reload[a]=65535),this.counter_start_value[a]=this.counter_reload[a],this.counter_enabled[a]=!0,this.counter_start_time[a]=G.microtick(),z(this.counter_reload[a]));3===this.counter_read_mode[a]&&(this.counter_next_low[a]^=1)};
|
|
141
|
+
eb.prototype.port43_write=function(a){var b=a>>1&7,c=a>>6&3;a=a>>4&3;3!==c&&(0===a?(this.counter_latch[c]=2,b=this.get_counter_value(c,G.microtick()),this.counter_latch_value[c]=b?b-1:0):(6<=b&&(b&=-5),this.counter_next_low[c]=1===a?0:1,0===c&&this.cpu.device_lower_irq(0),0!==b&&3!==b&&2!==b&&z(b),this.counter_mode[c]=b,this.counter_read_mode[c]=a,2===c&&this.bus.send("pcspeaker-update",[this.counter_mode[2],this.counter_reload[2]])))};eb.prototype.dump=function(){};function fb(a){if("undefined"!==typeof window)if(window.AudioContext||window.webkitAudioContext){var b=window.AudioWorklet?gb:hb;this.bus=a;this.audio_context=window.AudioContext?new AudioContext:new webkitAudioContext;this.mixer=new ib(a,this.audio_context);this.pcspeaker=new jb(a,this.audio_context,this.mixer);this.dac=new b(a,this.audio_context,this.mixer);this.pcspeaker.start();a.register("emulator-stopped",function(){this.audio_context.suspend()},this);a.register("emulator-started",function(){this.audio_context.resume()},
|
|
141
142
|
this);a.register("speaker-confirm-initialized",function(){a.send("speaker-has-initialized")},this);a.send("speaker-has-initialized")}else console.warn("Web browser doesn't support Web Audio API")}fb.prototype.destroy=function(){this.audio_context&&this.audio_context.close();this.audio_context=null;this.dac&&this.dac.node_processor&&this.dac.node_processor.port.close();this.dac=null};
|
|
142
143
|
function ib(a,b){function c(d){return function(e){d.gain.setValueAtTime(e,this.audio_context.currentTime)}}this.audio_context=b;this.sources=new Map;this.gain_right=this.gain_left=this.volume_right=this.volume_left=this.volume_both=1;this.node_treble_left=this.audio_context.createBiquadFilter();this.node_treble_right=this.audio_context.createBiquadFilter();this.node_treble_left.type="highshelf";this.node_treble_right.type="highshelf";this.node_treble_left.frequency.setValueAtTime(2E3,this.audio_context.currentTime);
|
|
143
144
|
this.node_treble_right.frequency.setValueAtTime(2E3,this.audio_context.currentTime);this.node_bass_left=this.audio_context.createBiquadFilter();this.node_bass_right=this.audio_context.createBiquadFilter();this.node_bass_left.type="lowshelf";this.node_bass_right.type="lowshelf";this.node_bass_left.frequency.setValueAtTime(200,this.audio_context.currentTime);this.node_bass_right.frequency.setValueAtTime(200,this.audio_context.currentTime);this.node_gain_left=this.audio_context.createGain();this.node_gain_right=
|
|
@@ -170,15 +171,15 @@ lb.prototype.connect=function(){if("undefined"!==typeof WebSocket){if(this.socke
|
|
|
170
171
|
this.socket.onerror=this.handle_error.bind(this)}}};lb.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())};lb.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 rb=(new Date("1970-01-01T00:00:00Z")).getTime(),sb=(new Date("1900-01-01T00:00:00Z")).getTime(),tb=rb-sb,ub=Math.pow(2,32),vb=[118,56,54];function wb(a){return[0,1,2,3,4,5].map(b=>a[b].toString(16)).map(b=>1===b.length?"0"+b:b).join(":")}function xb(a){return a[0]<<24|a[1]<<16|a[2]<<8|a[3]}
|
|
171
172
|
class yb{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");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=
|
|
172
173
|
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);a&&(this.tail=(this.tail+a)%this.buffer.length,this.length-=a);return a}}
|
|
173
|
-
function zb(){const a=new Uint8Array(1518),b=a.buffer,c=a.byteOffset;return{eth_frame:a,eth_frame_view:new DataView(b),eth_payload_view:new DataView(b,c+14,1500),ipv4_payload_view:new DataView(b,c+34,1480),udp_payload_view:new DataView(b,c+42,1472),text_encoder:new TextEncoder}}function
|
|
174
|
+
function zb(){const a=new Uint8Array(1518),b=a.buffer,c=a.byteOffset;return{eth_frame:a,eth_frame_view:new DataView(b),eth_payload_view:new DataView(b,c+14,1500),ipv4_payload_view:new DataView(b,c+34,1480),udp_payload_view:new DataView(b,c+42,1472),text_encoder:new TextEncoder}}function Jb(a,b,c,d){d.eth_frame.set(b,c.byteOffset+a);return b.length}
|
|
174
175
|
function Kb(a,b,c,d){const e=c.byteOffset+(a&-2);d=d.eth_frame;for(c=c.byteOffset;c<e;c+=2)b+=d[c]<<8|d[c+1];for(a&1&&(b+=d[e]<<8);b>>>16;)b=(b&65535)+(b>>>16);return~b&65535}
|
|
175
|
-
function Lb(a,b){a.eth_frame.fill(0);var c=a.eth_frame,d=c.subarray,e=a.eth_frame_view;
|
|
176
|
-
h.setUint8(0,b.icmp.type);h.setUint8(1,b.icmp.code);h.setUint16(2,0);var l=4+
|
|
177
|
-
b.dhcp.giaddr);
|
|
178
|
-
r.type);y+=2;m.setUint16(y,r.class);y+=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+(y+1))).written,m.setUint8(y,r),y+=1+r;m.setUint16(y,n.type);y+=2;m.setUint16(y,n.class);y+=2;m.setUint32(y,n.ttl);y+=4;m.setUint16(y,n.data.length);y+=2;y+=
|
|
179
|
-
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+
|
|
176
|
+
function Lb(a,b){a.eth_frame.fill(0);var c=a.eth_frame,d=c.subarray,e=a.eth_frame_view;Jb(0,b.eth.dest,e,a);Jb(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);Jb(8,b.arp.sha,f,a);Jb(14,b.arp.spa,f,a);Jb(18,b.arp.tha,f,a);Jb(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;
|
|
177
|
+
h.setUint8(0,b.icmp.type);h.setUint8(1,b.icmp.code);h.setUint16(2,0);var l=4+Jb(4,b.icmp.data,h,a);h.setUint16(2,Kb(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,b.dhcp.flags);n.setUint32(12,b.dhcp.ciaddr);n.setUint32(16,b.dhcp.yiaddr);n.setUint32(20,b.dhcp.siaddr);n.setUint32(24,
|
|
178
|
+
b.dhcp.giaddr);Jb(28,b.dhcp.chaddr,n,a);n.setUint32(236,1669485411);m=240;for(var p of b.dhcp.options)m+=Jb(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 y=12;for(var q=0;q<b.dns.questions.length;++q){var r=b.dns.questions[q];for(n of r.name){const x=a.text_encoder.encodeInto(n,a.eth_frame.subarray(m.byteOffset+(y+1))).written;m.setUint8(y,x);y+=1+x}m.setUint16(y,
|
|
179
|
+
r.type);y+=2;m.setUint16(y,r.class);y+=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+(y+1))).written,m.setUint8(y,r),y+=1+r;m.setUint16(y,n.type);y+=2;m.setUint16(y,n.class);y+=2;m.setUint32(y,n.ttl);y+=4;m.setUint16(y,n.data.length);y+=2;y+=Jb(y,n.data,m,a)}l=p+y}else b.ntp?(l=m,n=a.udp_payload_view,n.setUint8(0,b.ntp.flags),n.setUint8(1,b.ntp.stratum),n.setUint8(2,b.ntp.poll),n.setUint8(3,b.ntp.precision),
|
|
180
|
+
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+Jb(0,b.udp.data,a.udp_payload_view,a);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,Kb(m,
|
|
180
181
|
(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),h.setUint16(0,n.sport),h.setUint16(2,n.dport),h.setUint32(4,n.seq),h.setUint32(8,n.ackn),h.setUint8(12,80),h.setUint8(13,l),h.setUint16(14,n.winsize),h.setUint16(16,0),h.setUint16(18,n.urgent||
|
|
181
|
-
0),l=20,b.tcp_data&&(l+=
|
|
182
|
+
0),l=20,b.tcp_data&&(l+=Jb(20,b.tcp_data,h,a)),h.setUint16(16,Kb(l,(b.ipv4.src[0]<<8|b.ipv4.src[1])+(b.ipv4.src[2]<<8|b.ipv4.src[3])+(b.ipv4.dest[0]<<8|b.ipv4.dest[1])+(b.ipv4.dest[2]<<8|b.ipv4.dest[3])+6+l,h,a)),g+=l);f.setUint8(0,69);f.setUint8(1,b.ipv4.tos||0);f.setUint16(2,g);f.setUint16(4,b.ipv4.id||0);f.setUint8(6,64);f.setUint8(8,b.ipv4.ttl||32);f.setUint8(9,b.ipv4.proto);f.setUint16(10,0);Jb(12,b.ipv4.src,f,a);Jb(16,b.ipv4.dest,f,a);f.setUint16(10,Kb(20,0,f,a));e+=g}return d.call(c,0,e)}
|
|
182
183
|
function Mb(a,b){fetch(`https://${b.doh_server||"cloudflare-dns.com"}/dns-query`,{method:"POST",headers:[["content-type","application/dns-message"]],body:a.udp.data}).then(async c=>{c={eth:{ethertype:2048,src:b.router_mac,dest:a.eth.src},ipv4:{proto:17,src:b.router_ip,dest:a.ipv4.src},udp:{sport:53,dport:a.udp.sport,data:new Uint8Array(await c.arrayBuffer())}};b.receive(Lb(b.eth_encoder_buf,c))});return!0}
|
|
183
184
|
function Nb(a,b){let c={};c.eth={ethertype:2048,src:b.router_mac,dest:a.eth.src};c.ipv4={proto:17,src:b.router_ip,dest:b.vm_ip};c.udp={sport:67,dport:68};c.dhcp={htype:1,hlen:6,hops:0,xid:a.dhcp.xid,secs:0,flags:0,ciaddr:0,yiaddr:xb(b.vm_ip),siaddr:xb(b.router_ip),giaddr:xb(b.router_ip),chaddr:a.dhcp.chaddr};let d=[],e=a.dhcp.options.find(function(f){return 53===f[0]});e&&3===e[2]&&(a.dhcp.op=3);1===a.dhcp.op&&(c.dhcp.op=2,d.push(new Uint8Array([53,1,2])));3===a.dhcp.op&&(c.dhcp.op=2,d.push(new Uint8Array([53,
|
|
184
185
|
1,5])),d.push(new Uint8Array([51,4,8,0,0,0])));a=[b.router_ip[0],b.router_ip[1],b.router_ip[2],b.router_ip[3]];d.push(new Uint8Array([1,4,255,255,255,0]));b.masquerade&&(d.push(new Uint8Array([3,4].concat(a))),d.push(new Uint8Array([6,4].concat(a))));d.push(new Uint8Array([54,4].concat(a)));d.push(new Uint8Array([60,3].concat(vb)));d.push(new Uint8Array([255,0]));c.dhcp.options=d;b.receive(Lb(b.eth_encoder_buf,c))}
|
|
@@ -224,19 +225,19 @@ Vb.prototype.send_wisp_frame=function(a){let b,c;switch(a.type){case "CONNECT":c
|
|
|
224
225
|
2);c.setUint32(1,a.stream_id,!0);b.set(a.data,5);break;case "CLOSE":b=new Uint8Array(6),c=new DataView(b.buffer),c.setUint8(0,4),c.setUint32(1,a.stream_id,!0),c.setUint8(5,a.reason)}this.send_packet(b,a.type,a.stream_id)};Vb.prototype.destroy=function(){this.wispws&&(this.wispws.onmessage=null,this.wispws.onclose=null,this.wispws.close(),this.wispws=null)};
|
|
225
226
|
Vb.prototype.on_tcp_connection=function(a,b){let c=new Rb;c.state="syn-received";c.net=this;c.tuple=b;c.stream_id=this.last_stream++;this.tcp_conn[b]=c;c.on("data",d=>{0!==d.length&&this.send_wisp_frame({type:"DATA",stream_id:c.stream_id,data:d})});c.on_close=()=>{this.send_wisp_frame({type:"CLOSE",stream_id:c.stream_id,reason:2})};c.on_shutdown=c.on_close;this.send_wisp_frame({type:"CONNECT",stream_id:c.stream_id,hostname:a.ipv4.dest.join("."),port:a.tcp.dport,data_callback:d=>{c.write(d)},close_callback:()=>
|
|
226
227
|
{c.close()}});c.accept(a);return!0};Vb.prototype.send=function(a){Ob(a,this)};Vb.prototype.receive=function(a){this.bus.send("net"+this.id+"-receive",new Uint8Array(a))};const bc="undefined"!==typeof window&&0<=window.navigator.platform.toString().toLowerCase().search("win");
|
|
227
|
-
function cc(a){function b(w){return w.shiftKey&&w.ctrlKey&&(73===w.keyCode||74===w.keyCode||75===w.keyCode)||!r.emu_enabled?!1:w.target?w.target.classList.contains("phone_keyboard")||"INPUT"!==w.target.nodeName&&"TEXTAREA"!==w.target.nodeName:!0}function c(w){!w.altKey&&m[56]&&h(56,!1);return f(w,!1)}function d(w){!w.altKey&&m[56]&&h(56,!1);return f(w,!0)}function e(){for(var w=Object.keys(m),
|
|
228
|
-
if(bc&&(n&&(clearTimeout(q),w.getModifierState&&w.getModifierState("AltGraph")&&p===
|
|
229
|
-
(m[w]=
|
|
228
|
+
function cc(a){function b(w){return w.shiftKey&&w.ctrlKey&&(73===w.keyCode||74===w.keyCode||75===w.keyCode)||!r.emu_enabled?!1:w.target?w.target.classList.contains("phone_keyboard")||"INPUT"!==w.target.nodeName&&"TEXTAREA"!==w.target.nodeName:!0}function c(w){!w.altKey&&m[56]&&h(56,!1);return f(w,!1)}function d(w){!w.altKey&&m[56]&&h(56,!1);return f(w,!0)}function e(){for(var w=Object.keys(m),J,P=0;P<w.length;P++)J=+w[P],m[J]&&h(J,!1);m={}}function f(w,J){if(r.bus&&b(w)){w.preventDefault&&w.preventDefault();
|
|
229
|
+
if(bc&&(n&&(clearTimeout(q),w.getModifierState&&w.getModifierState("AltGraph")&&p===J&&"ControlLeft"===n.code&&"AltRight"===w.code||g(n,p),n=null),"ControlLeft"===w.code))return n=w,p=J,q=setTimeout(()=>{g(n,p);n=null},10),!1;g(w,J);return!1}}function g(w,J){a:{if(void 0!==w.code){var P=H[w.code];if(void 0!==P)break a}P=y[w.keyCode]}P?h(P,J,w.repeat):console.log("Missing char in map: keyCode="+(w.keyCode||-1).toString(16)+" code="+w.code)}function h(w,J,P){if(J)m[w]&&!P&&h(w,!1);else if(!m[w])return;
|
|
230
|
+
(m[w]=J)||(w|=128);255<w?(l(w>>8),l(w&255)):l(w)}function l(w){r.bus.send("keyboard-code",w)}var m={},n=null,p=!1,q=0,r=this;this.emu_enabled=!0;const y=new Uint16Array([0,0,0,0,0,0,0,0,14,15,0,0,0,28,0,0,42,29,56,0,58,0,0,0,0,0,0,1,0,0,0,0,57,57417,57425,57423,57415,57419,57416,57421,80,0,0,0,0,82,83,0,11,2,3,4,5,6,7,8,9,10,0,39,0,13,0,0,0,30,48,46,32,18,33,34,35,23,36,37,38,50,49,24,25,16,19,31,20,22,47,17,45,21,44,57435,57436,57437,0,0,82,79,80,81,75,76,77,71,72,73,0,0,0,0,0,0,59,60,61,62,63,64,
|
|
230
231
|
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,0,0,0,0,0,0,0,0]),x={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,
|
|
231
|
-
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,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
|
|
232
|
+
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,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 H={Escape:1,Digit1:2,Digit2:3,Digit3:4,Digit4:5,Digit5:6,Digit6:7,Digit7:8,Digit8:9,Digit9:10,
|
|
232
233
|
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,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,
|
|
233
234
|
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,ControlRight:57373,NumpadDivide:57397,AltRight:57400,Home:57415,ArrowUp:57416,PageUp:57417,ArrowLeft:57419,ArrowRight:57421,End:57423,ArrowDown:57424,PageDown:57425,Insert:57426,Delete:57427,OSLeft:57435,OSRight:57436,ContextMenu:57437};this.bus=
|
|
234
|
-
a;this.destroy=function(){"undefined"!==typeof window&&(window.removeEventListener("keyup",c,!1),window.removeEventListener("keydown",d,!1),window.removeEventListener("blur",e,!1))};this.init=function(){"undefined"!==typeof window&&(this.destroy(),window.addEventListener("keyup",c,!1),window.addEventListener("keydown",d,!1),window.addEventListener("blur",e,!1))};this.init();this.simulate_press=function(w){w={keyCode:w};f(w,!0);f(w,!1)};this.simulate_char=function(w){var
|
|
235
|
-
|
|
236
|
-
y,r=
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
235
|
+
a;this.destroy=function(){"undefined"!==typeof window&&(window.removeEventListener("keyup",c,!1),window.removeEventListener("keydown",d,!1),window.removeEventListener("blur",e,!1))};this.init=function(){"undefined"!==typeof window&&(this.destroy(),window.addEventListener("keyup",c,!1),window.addEventListener("keydown",d,!1),window.addEventListener("blur",e,!1))};this.init();this.simulate_press=function(w){w={keyCode:w};f(w,!0);f(w,!1)};this.simulate_char=function(w){var J=w.charCodeAt(0);J in x?this.simulate_press(x[J]):
|
|
236
|
+
J in u?(l(42),this.simulate_press(u[J]),l(170)):console.log("ascii -> keyCode not found: ",J,w)}};function dc(a,b){function c(u){if(!x.enabled||!x.emu_enabled)return!1;var H=b||document.body,w;if(!(w=document.pointerLockElement))a:{for(u=u.target;u.parentNode;){if(u===H){w=!0;break a}u=u.parentNode}w=!1}return w}function d(u){c(u)&&(u=u.changedTouches)&&u.length&&(u=u[u.length-1],r=u.clientX,y=u.clientY)}function e(){if(n||q||p)x.bus.send("mouse-click",[!1,!1,!1]),n=q=p=!1}function f(u){if(x.bus&&c(u)&&x.is_running){var H=0,w=0,J=u.changedTouches;J?J.length&&(J=J[J.length-1],H=J.clientX-r,w=J.clientY-
|
|
237
|
+
y,r=J.clientX,y=J.clientY,u.preventDefault()):"number"===typeof u.movementX?(H=u.movementX,w=u.movementY):"number"===typeof u.webkitMovementX?(H=u.webkitMovementX,w=u.webkitMovementY):"number"===typeof u.mozMovementX?(H=u.mozMovementX,w=u.mozMovementY):(H=u.clientX-r,w=u.clientY-y,r=u.clientX,y=u.clientY);x.bus.send("mouse-delta",[1*H,-(1*w)]);b&&x.bus.send("mouse-absolute",[u.pageX-b.offsetLeft,u.pageY-b.offsetTop,b.offsetWidth,b.offsetHeight])}}function g(u){c(u)&&l(u,!0)}function h(u){c(u)&&l(u,
|
|
238
|
+
!1)}function l(u,H){x.bus&&(1===u.which?n=H:2===u.which?q=H:3===u.which&&(p=H),x.bus.send("mouse-click",[n,q,p]),u.preventDefault())}function m(u){if(c(u)){var H=u.wheelDelta||-u.detail;0>H?H=-1:0<H&&(H=1);x.bus.send("mouse-wheel",[H,0]);u.preventDefault()}}var n=!1,p=!1,q=!1,r=0,y=0,x=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=!1},this);this.bus.register("emulator-started",
|
|
239
|
+
function(){this.is_running=!0},this);this.destroy=function(){"undefined"!==typeof window&&(window.removeEventListener("touchstart",d,!1),window.removeEventListener("touchend",e,!1),window.removeEventListener("touchmove",f,!1),window.removeEventListener("mousemove",f,!1),window.removeEventListener("mousedown",g,!1),window.removeEventListener("mouseup",h,!1),window.removeEventListener("wheel",m,{passive:!1}))};this.init=function(){"undefined"!==typeof window&&(this.destroy(),window.addEventListener("touchstart",
|
|
240
|
+
d,!1),window.addEventListener("touchend",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 ec(){var a,b=0,c=0;this.put_char=function(d,e,f){a[d*b+e]=f};this.destroy=function(){};this.pause=function(){};this.continue=function(){};this.set_mode=function(){};this.set_font_bitmap=function(){};this.set_font_page=function(){};this.clear_screen=function(){};this.set_size_text=function(d,e){if(d!==b||e!==c)a=new Uint8Array(d*e),b=d,c=e};this.set_size_graphical=function(){};this.set_scale=function(){};this.update_cursor_scanline=function(){};this.update_cursor=function(){};this.update_buffer=
|
|
240
241
|
function(){};this.get_text_screen=function(){for(var d=[],e=0;e<c;e++)d.push(this.get_text_row(e));return d};this.get_text_row=function(d){d*=b;return String.fromCharCode.apply(String,a.subarray(d,d+b))};this.set_size_text(80,25)};function fc(a,b){function c(h){g.bus&&g.enabled&&(g.send_char(h.which),h.preventDefault())}function d(h){var l=h.which;8===l?(g.send_char(127),h.preventDefault()):9===l&&(g.send_char(9),h.preventDefault())}function e(h){if(g.enabled){for(var l=h.clipboardData.getData("text/plain"),m=0;m<l.length;m++)g.send_char(l.charCodeAt(m));h.preventDefault()}}function f(h){h.target!==a&&a.blur()}var g=this;this.enabled=!0;this.bus=b;this.text="";this.text_new_line=!1;this.last_update=0;this.bus.register("serial0-output-byte",
|
|
241
242
|
function(h){h=String.fromCharCode(h);this.show_char(h)},this);this.destroy=function(){a.removeEventListener("keypress",c,!1);a.removeEventListener("keydown",d,!1);a.removeEventListener("paste",e,!1);window.removeEventListener("mousedown",f,!1)};this.init=function(){this.destroy();a.style.display="block";a.addEventListener("keypress",c,!1);a.addEventListener("keydown",d,!1);a.addEventListener("paste",e,!1);window.addEventListener("mousedown",f,!1)};this.init();this.show_char=function(h){"\b"===h?(this.text=
|
|
242
243
|
this.text.slice(0,-1),this.update()):"\r"!==h&&(this.text+=h,"\n"===h&&(this.text_new_line=!0),this.update())};this.update=function(){var h=Date.now(),l=h-this.last_update;16>l?void 0===this.update_timer&&(this.update_timer=setTimeout(()=>{this.update_timer=void 0;this.last_update=Date.now();this.render()},16-l)):(void 0!==this.update_timer&&(clearTimeout(this.update_timer),this.update_timer=void 0),this.last_update=h,this.render())};this.render=function(){a.value=this.text;this.text_new_line&&(this.text_new_line=
|
|
@@ -244,8 +245,8 @@ this.text.slice(0,-1),this.update()):"\r"!==h&&(this.text+=h,"\n"===h&&(this.tex
|
|
|
244
245
|
function gc(a,b){this.element=a;if(window.Terminal){var c=this.term=new window.Terminal({logLevel:"off",convertEol:"true"});c.write("This is the serial console. Whatever you type or paste here will be sent to COM1");var d=c.onData(function(e){for(let f=0;f<e.length;f++)b.send("serial0-input",e.charCodeAt(f))});b.register("serial0-output-byte",function(e){c.write(Uint8Array.of(e))},this);this.destroy=function(){d.dispose();c.dispose()}}}gc.prototype.show=function(){this.term&&this.term.open(this.element)};function hc(a,b){b=b.id||0;this.bus=a;this.bus_send_msgid=`net${b}-send`;this.bus_recv_msgid=`net${b}-receive`;this.channel=new BroadcastChannel(`v86-inbrowser-${b}`);this.is_open=!0;this.nic_to_hub_fn=c=>{this.channel.postMessage(c)};this.bus.register(this.bus_send_msgid,this.nic_to_hub_fn,this);this.hub_to_nic_fn=c=>{this.bus.send(this.bus_recv_msgid,c.data)};this.channel.addEventListener("message",this.hub_to_nic_fn)}
|
|
245
246
|
hc.prototype.destroy=function(){this.is_open&&(this.bus.unregister(this.bus_send_msgid,this.nic_to_hub_fn),this.channel.removeEventListener("message",this.hub_to_nic_fn),this.channel.close(),this.is_open=!1)};function ic(){this.filedata=new Map}ic.prototype.read=async function(a,b,c){return(a=this.filedata.get(a))?a.subarray(b,b+c):null};ic.prototype.cache=async function(a,b){this.filedata.set(a,b)};ic.prototype.uncache=function(a){this.filedata.delete(a)};function jc(a,b){b.endsWith("/")||(b+="/");this.storage=a;this.baseurl=b}jc.prototype.load_from_server=function(a){return new Promise(b=>{pa(this.baseurl+a,{done:async c=>{c=new Uint8Array(c);await this.cache(a,c);b(c)}})})};
|
|
246
247
|
jc.prototype.read=async function(a,b,c){const d=await this.storage.read(a,b,c);return d?d:(await this.load_from_server(a)).subarray(b,b+c)};jc.prototype.cache=async function(a,b){return await this.storage.cache(a,b)};jc.prototype.uncache=function(a){this.storage.uncache(a)};const kc=new TextDecoder,lc=new TextEncoder;
|
|
247
|
-
function
|
|
248
|
-
case "Q":
|
|
248
|
+
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++]=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=lc.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;
|
|
249
|
+
case "Q":I(["b","w","d"],[e.type,e.version,e.path],c,d),d+=13,f+=13}return f}
|
|
249
250
|
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(kc.decode(h));break;case "Q":c.offset=d,g=L(["b","w","d"],b,c),d=c.offset,e.push({type:g[0],version:g[1],path:g[2]})}c.offset=
|
|
250
251
|
d;return e};const mc=new TextEncoder;function M(a,b){this.inodes=[];this.events=[];this.storage=a;this.qidcounter=b||{last_qidnumber:0};this.inodedata={};this.total_size=274877906944;this.used_size=0;this.mounts=[];this.CreateDirectory("",-1)}M.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)};
|
|
251
252
|
M.prototype.set_state=function(a){this.inodes=a[0].map(b=>{const c=new nc(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)};M.prototype.AddEvent=function(a,b){var c=this.inodes[a];0===c.status||2===c.status?b():this.is_forwarder(c)?this.follow_fs(c).AddEvent(c.foreign_id,b):this.events.push({id:a,OnEvent:b})};
|
|
@@ -283,7 +284,7 @@ M.prototype.SearchPath=function(a){a=a.replace("//","/");a=a.split("/");0<a.leng
|
|
|
283
284
|
M.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&&".."!==c&&(b.push({parentid:a,name:c}),this.IsDirectory(d)&&this.GetRecursiveList(d,b))};
|
|
284
285
|
M.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)};M.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)))};M.prototype.NotifyListeners=function(){};
|
|
285
286
|
M.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);}};
|
|
286
|
-
M.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+mc.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+=
|
|
287
|
+
M.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+mc.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+=I(["Q","d","b","s"],[b.qid,c+13+8+1+2+mc.encode(d).length,b.mode>>12,d],a,c)}};
|
|
287
288
|
M.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};M.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)};
|
|
288
289
|
M.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};M.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};
|
|
289
290
|
M.prototype.GetParent=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)};
|
|
@@ -296,19 +297,19 @@ oc.prototype.conflicts_with=function(a){return this.proc_id===a.proc_id&&this.cl
|
|
|
296
297
|
M.prototype.DescribeLock=function(a,b,c,d,e){const f=new oc;f.type=a;f.start=b;f.length=c;f.proc_id=d;f.client_id=e;return f};M.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};
|
|
297
298
|
M.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=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=
|
|
298
299
|
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,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,
|
|
299
|
-
d.locks.splice(e,1));break}}return 0};M.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)};M.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 S(a){this.cpu_is_running=!1;this.cpu_exception_hook=function(){};var b=Ba.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:
|
|
300
|
+
d.locks.splice(e,1));break}}return 0};M.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)};M.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 S(a){this.cpu_is_running=!1;this.cpu_exception_hook=function(){};var b=Ba.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:G.microtick,get_rand_int:function(){return ba()},apic_acknowledge_irq:function(){return c.devices.apic.acknowledge_irq()},
|
|
300
301
|
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_read16:function(g){return c.mmap_read16(g)},mmap_read32:function(g){return c.mmap_read32(g)},
|
|
301
302
|
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,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){String.fromCharCode(...(new Uint8Array(d.buffer,g>>>0,h>>>0)))},console_log_from_wasm:function(g,h){g=String.fromCharCode(...(new Uint8Array(d.buffer,g>>>0,h>>>0)));console.error(g)},dbg_trace_from_wasm:function(){},codegen_finalize:(g,
|
|
302
303
|
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";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,
|
|
303
|
-
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,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
|
|
304
|
+
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,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 G(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=
|
|
304
305
|
0}
|
|
305
306
|
S.prototype.continue_init=async function(a,b){function c(q,r){switch(q){case "hda":e.hda=this.disk_images.hda=r;break;case "hdb":e.hdb=this.disk_images.hdb=r;break;case "cdrom":e.cdrom=this.disk_images.cdrom=r;break;case "fda":e.fda=this.disk_images.fda=r;break;case "fdb":e.fdb=this.disk_images.fdb=r;break;case "multiboot":e.multiboot=this.disk_images.multiboot=r.buffer;break;case "bzimage":e.bzimage=this.disk_images.bzimage=r.buffer;break;case "initrd":e.initrd=this.disk_images.initrd=r.buffer;break;
|
|
306
307
|
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),[y,x]=await Promise.all([e.fs9p.read_file(r),e.fs9p.read_file(q)]);c.call(this,"initrd",new A(y.buffer));c.call(this,"bzimage",
|
|
307
308
|
new A(x.buffer))}this.serial_adapter&&this.serial_adapter.show&&this.serial_adapter.show();this.v86.init(e);e.initial_state&&(a.restore_state(e.initial_state),e.initial_state=void 0);b.autostart&&this.v86.run();this.emulator_bus.send("emulator-loaded")}this.bus.register("emulator-stopped",function(){this.cpu_is_running=!1;this.screen_adapter.pause()},this);this.bus.register("emulator-started",function(){this.cpu_is_running=!0;this.screen_adapter.continue()},this);var e={};this.disk_images={fda:void 0,
|
|
308
309
|
fdb:void 0,hda:void 0,hdb:void 0,cdrom:void 0};var f=b.boot_order?b.boot_order:b.fda?801:b.hda?786:291;e.acpi=b.acpi;e.disable_jit=b.disable_jit;e.load_devices=!0;e.memory_size=b.memory_size||67108864;e.vga_memory_size=b.vga_memory_size||8388608;e.boot_order=f;e.fastboot=b.fastboot||!1;e.fda=void 0;e.fdb=void 0;e.uart1=b.uart1;e.uart2=b.uart2;e.uart3=b.uart3;e.cmdline=b.cmdline;e.preserve_mac_from_state_image=b.preserve_mac_from_state_image;e.mac_address_translation=b.mac_address_translation;e.cpuid_level=
|
|
309
|
-
b.cpuid_level;e.virtio_balloon=b.virtio_balloon;e.virtio_console=b.virtio_console;e.
|
|
310
|
-
{
|
|
311
|
-
|
|
310
|
+
b.cpuid_level;e.virtio_balloon=b.virtio_balloon;e.virtio_console=b.virtio_console;e.screen_options=b.screen_options;if(f=b.network_relay_url||b.net_device&&b.net_device.relay_url)"fetch"===f?this.network_adapter=new Tb(this.bus,b.net_device):"inbrowser"===f?this.network_adapter=new hc(this.bus,b.net_device):f.startsWith("wisp://")||f.startsWith("wisps://")?this.network_adapter=new Vb(f,this.bus,b.net_device):this.network_adapter=new lb(f,this.bus);e.net_device=b.net_device||{type:"ne2k"};f=b.screen||
|
|
311
|
+
{};b.screen_container&&(f.container=b.screen_container);b.disable_keyboard||(this.keyboard_adapter=new cc(this.bus));b.disable_mouse||(this.mouse_adapter=new dc(this.bus,f.container));this.screen_adapter=f.container?new ta(f,()=>this.v86.cpu.devices.vga&&this.v86.cpu.devices.vga.screen_fill_buffer()):new ec;e.screen=this.screen_adapter;e.screen_options=f;b.serial_container&&(this.serial_adapter=new fc(b.serial_container,this.bus));b.serial_container_xtermjs&&(this.serial_adapter=new gc(b.serial_container_xtermjs,
|
|
312
|
+
this.bus));b.disable_speaker||(this.speaker_adapter=new fb(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=!1;r.url&&!r.async?g.push({name:q,url:r.url,size:r.size}):g.push({name:q,loadable:za(r,this.zstd_decompress_worker.bind(this))})}};b.state&&console.warn("Warning: Unknown option 'state'. Did you mean 'initial_state'?");
|
|
312
313
|
f("bios",b.bios);f("vga_bios",b.vga_bios);f("cdrom",b.cdrom);f("hda",b.hda);f("hdb",b.hdb);f("fda",b.fda);f("fdb",b.fdb);f("initial_state",b.initial_state);f("multiboot",b.multiboot);f("bzimage",b.bzimage);f("initrd",b.initrd);if(b.filesystem){f=b.filesystem.basefs;var h=b.filesystem.baseurl;let q=new ic;h&&(q=new jc(q,h));e.fs9p=this.fs9p=new M(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),
|
|
313
314
|
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(y){r.url.endsWith(".zst")&&"initial_state"!==r.name&&(y=this.zstd_decompress(r.size,new Uint8Array(y)));c.call(this,r.name,r.as_json?y:new A(y));p(q+1)}.bind(this),progress:function(y){200===y.target.status?m.emulator_bus.send("download-progress",{file_index:q,file_count:n,file_name:r.url,lengthComputable:y.lengthComputable,total:y.total||r.size,
|
|
314
315
|
loaded:y.loaded}):m.emulator_bus.send("download-error",{file_index:q,file_count:n,file_name:r.url,request:y.target})},as_json:r.as_json})}}.bind(this);p(0)};
|
|
@@ -323,8 +324,8 @@ S.prototype.remove_listener=function(a,b){this.bus.unregister(a,b)};S.prototype.
|
|
|
323
324
|
S.prototype.set_fda=async function(a){if(a.url&&!a.async)pa(a.url,{done:b=>{this.v86.cpu.devices.fdc.set_fda(new A(b))}});else{const b=za(a,this.zstd_decompress_worker.bind(this));b.onload=()=>{this.v86.cpu.devices.fdc.set_fda(b)};await b.load()}};S.prototype.eject_fda=function(){this.v86.cpu.devices.fdc.eject_fda()};
|
|
324
325
|
S.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))}});else{const b=za(a,this.zstd_decompress_worker.bind(this));b.onload=()=>{this.v86.cpu.devices.cdrom.set_cdrom(b)};await b.load()}};S.prototype.eject_cdrom=function(){this.v86.cpu.devices.cdrom.eject()};S.prototype.keyboard_send_scancodes=function(a){for(var b=0;b<a.length;b++)this.bus.send("keyboard-code",a[b])};S.prototype.keyboard_send_keys=function(a){for(var b=0;b<a.length;b++)this.keyboard_adapter.simulate_press(a[b])};
|
|
325
326
|
S.prototype.keyboard_send_text=function(a){for(var b=0;b<a.length;b++)this.keyboard_adapter.simulate_char(a[b])};S.prototype.screen_make_screenshot=function(){return this.screen_adapter?this.screen_adapter.make_screenshot():null};S.prototype.screen_set_scale=function(a,b){this.screen_adapter&&this.screen_adapter.set_scale(a,b)};
|
|
326
|
-
S.prototype.screen_go_fullscreen=function(){if(this.screen_adapter){var a=document.getElementById("screen_container");if(a){var b=a.requestFullScreen||a.webkitRequestFullscreen||a.mozRequestFullScreen||a.msRequestFullScreen;b&&(b.call(a),(a=document.getElementsByClassName("phone_keyboard")[0])&&a.focus());try{navigator.keyboard.lock()}catch(c){}this.lock_mouse()}}};
|
|
327
|
-
S.prototype.
|
|
327
|
+
S.prototype.screen_go_fullscreen=function(){if(this.screen_adapter){var a=document.getElementById("screen_container");if(a){var b=a.requestFullScreen||a.webkitRequestFullscreen||a.mozRequestFullScreen||a.msRequestFullScreen;b&&(b.call(a),(a=document.getElementsByClassName("phone_keyboard")[0])&&a.focus());try{navigator.keyboard.lock()}catch(c){}this.lock_mouse()}}};S.prototype.lock_mouse=async function(){const a=document.body;try{await a.requestPointerLock({unadjustedMovement:!0})}catch(b){await a.requestPointerLock()}};
|
|
328
|
+
S.prototype.mouse_set_enabled=function(a){this.mouse_adapter&&(this.mouse_adapter.emu_enabled=a)};S.prototype.mouse_set_status=S.prototype.mouse_set_enabled;S.prototype.keyboard_set_enabled=function(a){this.keyboard_adapter&&(this.keyboard_adapter.emu_enabled=a)};S.prototype.keyboard_set_status=S.prototype.keyboard_set_enabled;S.prototype.serial0_send=function(a){for(var b=0;b<a.length;b++)this.bus.send("serial0-input",a.charCodeAt(b))};
|
|
328
329
|
S.prototype.serial_send_bytes=function(a,b){for(var c=0;c<b.length;c++)this.bus.send("serial"+a+"-input",b[c])};S.prototype.serial_set_modem_status=function(a,b){this.bus.send("serial"+a+"-modem-status-input",b)};S.prototype.serial_set_carrier_detect=function(a,b){this.bus.send("serial"+a+"-carrier-detect-input",b)};S.prototype.serial_set_ring_indicator=function(a,b){this.bus.send("serial"+a+"-ring-indicator-input",b)};
|
|
329
330
|
S.prototype.serial_set_data_set_ready=function(a,b){this.bus.send("serial"+a+"-data-set-ready-input",b)};S.prototype.serial_set_clear_to_send=function(a,b){this.bus.send("serial"+a+"-clear-to-send-input",b)};S.prototype.mount_fs=async function(a,b,c){var d=new ic;b&&(d=new jc(d,b));d=new M(d,this.fs9p.qidcounter);b&&d.load_from_json(c);a=this.fs9p.Mount(a,d);if(-2===a)throw new qc;if(-17===a)throw new rc;if(0>a)throw Error("Failed to mount. Error number: "+-a);};
|
|
330
331
|
S.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 qc)}};S.prototype.read_file=async function(a){var b=this.fs9p;if(b)return(a=await b.read_file(a))?a:Promise.reject(new qc)};
|
|
@@ -334,19 +335,19 @@ S.prototype.read_memory=function(a,b){return this.v86.cpu.read_blob(a,b)};S.prot
|
|
|
334
335
|
S.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(" "),d=
|
|
335
336
|
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");
|
|
336
337
|
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=[cb(a,!1,!1,!1,!1),cb(a,!0,!1,!1,!1),cb(a,!1,!0,!1,!1),cb(a,!1,
|
|
337
|
-
!1,!0,!1),cb(a,!1,!1,!1,!0)].join("\n\n");return b+a};function rc(a){this.message=a||"File already exists"}rc.prototype=Error.prototype;function qc(a){this.message=a||"File not found"}qc.prototype=Error.prototype;"undefined"!==typeof module&&"undefined"!==typeof module.exports?module.exports.V86=S:"undefined"!==typeof window?window.V86=S:"function"===typeof importScripts&&(self.V86=S);function
|
|
338
|
-
|
|
339
|
-
if("undefined"!==typeof process)
|
|
340
|
-
a.toString()+")()"],{type:"text/javascript"}));this.worker=new Worker(b);this.worker.onmessage=c=>this.yield_callback(c.data);URL.revokeObjectURL(b)};
|
|
341
|
-
|
|
342
|
-
|
|
338
|
+
!1,!0,!1),cb(a,!1,!1,!1,!0)].join("\n\n");return b+a};function rc(a){this.message=a||"File already exists"}rc.prototype=Error.prototype;function qc(a){this.message=a||"File not found"}qc.prototype=Error.prototype;"undefined"!==typeof module&&"undefined"!==typeof module.exports?module.exports.V86=S:"undefined"!==typeof window?window.V86=S:"function"===typeof importScripts&&(self.V86=S);function G(a,b){this.stopping=this.running=!1;this.idle=!0;this.tick_counter=0;this.worker=null;this.cpu=new T(a,b,()=>{this.idle&&this.next_tick(0)});this.bus=a;this.register_yield()}G.prototype.run=function(){this.stopping=!1;this.running||(this.running=!0,this.bus.send("emulator-started"));this.next_tick(0)};G.prototype.do_tick=function(){if(this.stopping||!this.running)this.stopping=this.running=!1,this.bus.send("emulator-stopped");else{this.idle=!1;var a=this.cpu.main_loop();this.next_tick(a)}};
|
|
339
|
+
G.prototype.next_tick=function(a){const b=++this.tick_counter;this.idle=!0;this.yield(a,b)};G.prototype.yield_callback=function(a){a===this.tick_counter&&this.do_tick()};G.prototype.stop=function(){this.running&&(this.stopping=!0)};G.prototype.destroy=function(){this.unregister_yield()};G.prototype.restart=function(){this.cpu.reset_cpu();this.cpu.load_bios()};G.prototype.init=function(a){this.cpu.init(a,this.bus);this.bus.send("emulator-ready")};
|
|
340
|
+
if("undefined"!==typeof process)G.prototype.yield=function(a,b){1>a?global.setImmediate(c=>this.yield_callback(c),b):setTimeout(c=>this.yield_callback(c),a,b)},G.prototype.register_yield=function(){},G.prototype.unregister_yield=function(){};else if("undefined"!==typeof Worker){function a(){let b;globalThis.onmessage=function(c){const d=c.data.t;b=b&&clearTimeout(b);1>d?postMessage(c.data.tick):b=setTimeout(()=>postMessage(c.data.tick),d)}}G.prototype.register_yield=function(){const b=URL.createObjectURL(new Blob(["("+
|
|
341
|
+
a.toString()+")()"],{type:"text/javascript"}));this.worker=new Worker(b);this.worker.onmessage=c=>this.yield_callback(c.data);URL.revokeObjectURL(b)};G.prototype.yield=function(b,c){this.worker.postMessage({t:b,tick:c})};G.prototype.unregister_yield=function(){this.worker&&this.worker.terminate();this.worker=null}}else G.prototype.yield=function(a){setTimeout(()=>{this.do_tick()},a)},G.prototype.register_yield=function(){},G.prototype.unregister_yield=function(){};
|
|
342
|
+
G.prototype.save_state=function(){for(var a=[],b=$a(this.cpu,a),c=[],d=0,e=0;e<a.length;e++){var f=a[e].byteLength;c[e]={offset:d,length:f};d+=f;d=d+3&-4}e=JSON.stringify({buffer_infos:c,state:b});e=(new TextEncoder).encode(e);b=16+e.length;b=b+3&-4;f=b+d;d=new ArrayBuffer(f);var g=new Int32Array(d,0,4);(new Uint8Array(d,16,e.length)).set(e);b=new Uint8Array(d,b);g[0]=-2039052682;g[1]=6;g[2]=f;g[3]=e.length;for(e=0;e<a.length;e++)b.set(a[e],c[e].offset);return d};
|
|
343
|
+
G.prototype.restore_state=function(a){return bb(this.cpu,a)};if("object"===typeof performance&&performance.now)G.microtick=performance.now.bind(performance);else if("function"===typeof require){const {performance:a}=require("perf_hooks");G.microtick=a.now.bind(a)}else G.microtick="object"===typeof process&&process.hrtime?function(){var a=process.hrtime();return 1E3*a[0]+a[1]/1E6}:Date.now;function sc(a){this.cpu=a;this.timer_divider=this.apic_id=0;this.timer_divider_shift=1;this.timer_current_count=this.timer_initial_count=0;this.next_tick=G.microtick();this.lvt_error=this.lvt_int1=this.lvt_int0=this.lvt_perf_counter=this.lvt_thermal_sensor=this.lvt_timer=65536;this.icr1=this.icr0=this.tpr=0;this.irr=new Int32Array(8);this.isr=new Int32Array(8);this.tmr=new Int32Array(8);this.spurious_vector=254;this.destination_format=-1;this.read_error=this.error=this.local_destination=0;a.io.mmap_register(4276092928,
|
|
343
344
|
1048576,b=>{z(b>>>0);var c=b&3;return this.read32(b&-4)>>8*c&255},(b,c)=>{z(b);z(c)},b=>this.read32(b),(b,c)=>this.write32(b,c))}
|
|
344
345
|
sc.prototype.read32=function(a){a=a-4276092928|0;switch(a){case 32:return this.apic_id;case 48:return 327700;case 128:return this.tpr;case 208:return this.local_destination;case 224:return this.destination_format;case 240:return this.spurious_vector;case 256:case 272:case 288:case 304:case 320:case 336:case 352:case 368:return a=a-256>>4,z(this.isr[a]>>>0,8),this.isr[a];case 384:case 400:case 416:case 432:case 448:case 464:case 480:case 496:return a=a-384>>4,z(this.tmr[a]>>>0,8),this.tmr[a];case 512:case 528:case 544:case 560:case 576:case 592:case 608:case 624:return a=
|
|
345
346
|
a-512>>4,z(this.irr[a]>>>0,8),this.irr[a];case 640:return z(this.read_error>>>0,8),this.read_error;case 768:return this.icr0;case 784:return this.icr1;case 800:return this.lvt_timer;case 816:return this.lvt_thermal_sensor;case 832:return this.lvt_perf_counter;case 848:return this.lvt_int0;case 864:return this.lvt_int1;case 880:return this.lvt_error;case 992:return this.timer_divider;case 896:return this.timer_initial_count;case 912:return z(this.timer_current_count>>>0,8),this.timer_current_count;
|
|
346
347
|
default:return z(a),0}};
|
|
347
348
|
sc.prototype.write32=function(a,b){a=a-4276092928|0;switch(a){case 32:z(b>>>8,8);this.apic_id=b;break;case 48:z(b>>>0,8);break;case 128:this.tpr=b&255;this.check_vector();break;case 176:b=this.highest_isr();-1!==b&&(this.register_clear_bit(this.isr,b),this.register_get_bit(this.tmr,b)&&this.cpu.devices.ioapic.remote_eoi(b),this.check_vector());break;case 208:z(b>>>0,8);this.local_destination=b&4278190080;break;case 224:z(b>>>0,8);this.destination_format=b|16777215;break;case 240:z(b>>>0,8);this.spurious_vector=
|
|
348
349
|
b;break;case 640:z(b>>>0,8);this.read_error=this.error;this.error=0;break;case 768:a=b&255;var c=b>>8&7,d=b>>11&1,e=b>>15&1,f=b>>18&3,g=this.icr1>>>24;z(b,8);z(a,2);this.icr0=b&-4097;0===f?this.route(a,c,e,g,d):1===f?this.deliver(a,0,e):2===f&&this.deliver(a,c,e);break;case 784:z(b>>>0,8);this.icr1=b;break;case 800:z(b>>>0,8);this.lvt_timer=b;break;case 816:z(b>>>0,8);this.lvt_thermal_sensor=b;break;case 832:z(b>>>0,8);this.lvt_perf_counter=b;break;case 848:z(b>>>0,8);this.lvt_int0=b;break;case 864:z(b>>>
|
|
349
|
-
0,8);this.lvt_int1=b;break;case 880:z(b>>>0,8);this.lvt_error=b;break;case 992:z(b>>>0,8);this.timer_divider=b;b=b&3|(b&8)>>1;this.timer_divider_shift=7===b?0:b+1;break;case 896:z(b>>>0,8);this.timer_initial_count=b>>>0;this.timer_current_count=b>>>0;this.next_tick=
|
|
350
|
+
0,8);this.lvt_int1=b;break;case 880:z(b>>>0,8);this.lvt_error=b;break;case 992:z(b>>>0,8);this.timer_divider=b;b=b&3|(b&8)>>1;this.timer_divider_shift=7===b?0:b+1;break;case 896:z(b>>>0,8);this.timer_initial_count=b>>>0;this.timer_current_count=b>>>0;this.next_tick=G.microtick();this.timer_active=!0;break;case 912:z(b>>>0,8);break;default:z(a),z(b>>>0,8)}};
|
|
350
351
|
sc.prototype.timer=function(a){if(0===this.timer_current_count)return 100;const b=1E6/(1<<this.timer_divider_shift);a=(a-this.next_tick)*b>>>0;this.next_tick+=a/b;this.timer_current_count-=a;0>=this.timer_current_count&&(a=this.lvt_timer&393216,131072===a?(this.timer_current_count%=this.timer_initial_count,0>=this.timer_current_count&&(this.timer_current_count+=this.timer_initial_count),0===(this.lvt_timer&65536)&&this.deliver(this.lvt_timer&255,0,!1)):0===a&&(this.timer_current_count=0,0===(this.lvt_timer&
|
|
351
352
|
65536)&&this.deliver(this.lvt_timer&255,0,!1)));return Math.max(0,this.timer_current_count/b)};sc.prototype.route=function(a,b,c){this.deliver(a,b,c)};sc.prototype.deliver=function(a,b,c){5!==b&&4!==b&&(this.register_get_bit(this.irr,a)?z(a,2):(this.register_set_bit(this.irr,a),c?this.register_set_bit(this.tmr,a):this.register_clear_bit(this.tmr,a),this.check_vector()))};sc.prototype.highest_irr=function(){return this.register_get_highest_bit(this.irr)};sc.prototype.highest_isr=function(){return this.register_get_highest_bit(this.isr)};
|
|
352
353
|
sc.prototype.check_vector=function(){var a=this.highest_irr();-1!==a&&(this.highest_isr()>=a||(a&240)<=(this.tpr&240)||this.cpu.handle_irqs())};sc.prototype.acknowledge_irq=function(){var a=this.highest_irr();if(-1===a||this.highest_isr()>=a||(a&240)<=(this.tpr&240))return-1;this.register_clear_bit(this.irr,a);this.register_set_bit(this.isr,a);this.check_vector();return a};
|
|
@@ -359,8 +360,8 @@ tc.prototype.check_irq=function(a){var b=1<<a;if(0!==(this.irr&b)){var c=this.io
|
|
|
359
360
|
tc.prototype.set_irq=function(a){if(!(24<=a)){var b=1<<a;0===(this.irq_value&b)&&(this.irq_value|=b,65536!==(this.ioredtbl_config[a]&98304)&&(this.irr|=b,this.check_irq(a)))}};tc.prototype.clear_irq=function(a){if(!(24<=a)){var b=1<<a;(this.irq_value&b)===b&&(this.irq_value&=~b,this.ioredtbl_config[a]&32768&&(this.irr&=~b))}};
|
|
360
361
|
tc.prototype.read=function(a){if(0===a)return this.ioapic_id<<24;if(1===a)return 1507345;if(2===a)return this.ioapic_id<<24;if(16<=a&&64>a){var b=a-16>>1;a=a&1?this.ioredtbl_destination[b]:this.ioredtbl_config[b];z(b);z(a,8);return a}z(a);return 0};
|
|
361
362
|
tc.prototype.write=function(a,b){if(0===a)this.ioapic_id=b>>>24&15;else if(1!==a&&2!==a)if(16<=a&&64>a){var c=a-16>>1;a&1?(this.ioredtbl_destination[c]=b&4278190080,z(b>>>0,8),z(c),z(b>>>24,2)):(this.ioredtbl_config[c]=b&110591|this.ioredtbl_config[c]&-110592,a=b&255,z(b>>>0,8),z(c),z(a,2),this.check_irq(c))}else z(a),z(b>>>0,8)};
|
|
362
|
-
tc.prototype.get_state=function(){var a=[];a[0]=this.ioredtbl_config;a[1]=this.ioredtbl_destination;a[2]=this.ioregsel;a[3]=this.ioapic_id;a[4]=this.irr;a[5]=this.irq_value;return a};tc.prototype.set_state=function(a){this.ioredtbl_config=a[0];this.ioredtbl_destination=a[1];this.ioregsel=a[2];this.ioapic_id=a[3];this.irr=a[4];this.irq_value=a[5]};function uc(a){this.cpu=a;var b=a.io;a.devices.pci.register_device({pci_id:56,pci_space:[134,128,19,113,7,0,128,2,8,0,128,6,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,1,0,0],pci_bars:[],name:"acpi"});this.timer_imprecision_offset=this.timer_last_value=0;this.status=1;this.pm1_enable=this.pm1_status=0;this.last_timer=this.get_timer(
|
|
363
|
-
b.register_write(45056,this,void 0,function(c){z(c,4);this.pm1_status&=~c});b.register_read(45058,this,void 0,function(){return this.pm1_enable});b.register_write(45058,this,void 0,function(c){z(c);this.pm1_enable=c});b.register_read(45060,this,void 0,function(){return this.status});b.register_write(45060,this,void 0,function(c){z(c);this.status=c});b.register_read(45064,this,void 0,void 0,function(){return this.get_timer(
|
|
363
|
+
tc.prototype.get_state=function(){var a=[];a[0]=this.ioredtbl_config;a[1]=this.ioredtbl_destination;a[2]=this.ioregsel;a[3]=this.ioapic_id;a[4]=this.irr;a[5]=this.irq_value;return a};tc.prototype.set_state=function(a){this.ioredtbl_config=a[0];this.ioredtbl_destination=a[1];this.ioregsel=a[2];this.ioapic_id=a[3];this.irr=a[4];this.irq_value=a[5]};function uc(a){this.cpu=a;var b=a.io;a.devices.pci.register_device({pci_id:56,pci_space:[134,128,19,113,7,0,128,2,8,0,128,6,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,1,0,0],pci_bars:[],name:"acpi"});this.timer_imprecision_offset=this.timer_last_value=0;this.status=1;this.pm1_enable=this.pm1_status=0;this.last_timer=this.get_timer(G.microtick());this.gpe=new Uint8Array(4);b.register_read(45056,this,void 0,function(){return this.pm1_status});
|
|
364
|
+
b.register_write(45056,this,void 0,function(c){z(c,4);this.pm1_status&=~c});b.register_read(45058,this,void 0,function(){return this.pm1_enable});b.register_write(45058,this,void 0,function(c){z(c);this.pm1_enable=c});b.register_read(45060,this,void 0,function(){return this.status});b.register_write(45060,this,void 0,function(c){z(c);this.status=c});b.register_read(45064,this,void 0,void 0,function(){return this.get_timer(G.microtick())&16777215});b.register_read(45024,this,function(){return this.gpe[0]});
|
|
364
365
|
b.register_read(45025,this,function(){return this.gpe[1]});b.register_read(45026,this,function(){return this.gpe[2]});b.register_read(45027,this,function(){return this.gpe[3]});b.register_write(45024,this,function(c){z(c);this.gpe[0]=c});b.register_write(45025,this,function(c){z(c);this.gpe[1]=c});b.register_write(45026,this,function(c){z(c);this.gpe[2]=c});b.register_write(45027,this,function(c){z(c);this.gpe[3]=c})}
|
|
365
366
|
uc.prototype.timer=function(a){a=this.get_timer(a);var b=0!==((a^this.last_timer)&8388608);this.pm1_enable&1&&b?(this.pm1_status|=1,this.cpu.device_raise_irq(9)):this.cpu.device_lower_irq(9);this.last_timer=a;return 100};
|
|
366
367
|
uc.prototype.get_timer=function(a){a=Math.round(3579.545*a);a===this.timer_last_value?3579.545>this.timer_imprecision_offset&&this.timer_imprecision_offset++:this.timer_last_value+this.timer_imprecision_offset<=a&&(this.timer_imprecision_offset=0,this.timer_last_value=a);return this.timer_last_value+this.timer_imprecision_offset};uc.prototype.get_state=function(){var a=[];a[0]=this.status;a[1]=this.pm1_status;a[2]=this.pm1_enable;a[3]=this.gpe;return a};
|
|
@@ -379,7 +380,7 @@ a.io.register_read_consecutive(3324,this,function(){return this.pci_response[0]}
|
|
|
379
380
|
6)&&6===(c&6)?a.reboot_internal():this.pci_addr[1]=c},function(c){this.pci_addr[2]=c},function(c){this.pci_addr[3]=c;this.pci_query()});this.register_device({pci_id:0,pci_space:[134,128,55,18,0,0,0,0,2,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,0],pci_bars:[],name:"82441FX PMC"});this.isa_bridge={pci_id:8,pci_space:[134,128,0,112,7,0,0,2,0,0,1,6,0,0,128,0,0,0,0,0,0,0,0,
|
|
380
381
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],pci_bars:[],name:"82371SB PIIX3 ISA"};this.isa_bridge_space=this.register_device(this.isa_bridge);this.isa_bridge_space8=new Uint8Array(this.isa_bridge_space.buffer)}wc.prototype.get_state=function(){for(var a=[],b=0;256>b;b++)a[b]=this.device_spaces[b];a[256]=this.pci_addr;a[257]=this.pci_value;a[258]=this.pci_response;a[259]=this.pci_status;return a};
|
|
381
382
|
wc.prototype.set_state=function(a){for(var b=0;256>b;b++){var c=this.devices[b],d=a[b];if(c&&d){for(var e=0;e<c.pci_bars.length;e++){var f=d[4+e];if(f&1){var g=c.pci_bars[e];this.set_io_bars(g,g.original_bar&65534,f&65534)}}this.device_spaces[b].set(d)}else d&&z(b,2)}this.pci_addr.set(a[256]);this.pci_value.set(a[257]);this.pci_response.set(a[258]);this.pci_status.set(a[259])};
|
|
382
|
-
wc.prototype.pci_query=function(){var a=this.pci_addr[2]<<8|this.pci_addr[1],b=this.pci_addr[0]&252,c=a>>3&31;
|
|
383
|
+
wc.prototype.pci_query=function(){var a=this.pci_addr[2]<<8|this.pci_addr[1],b=this.pci_addr[0]&252,c=a>>3&31;z(a,4);z(c,2);z(b,2);a=this.device_spaces[a];void 0!==a?(this.pci_status32[0]=-2147483648,this.pci_response32[0]=b<a.byteLength?a[b>>2]:0,z(this.pci_addr32[0]>>>0,8),z(this.pci_response32[0]>>>0,8)):(this.pci_response32[0]=-1,this.pci_status32[0]=0)};
|
|
383
384
|
wc.prototype.pci_write8=function(a,b){var c=a>>8&65535;a&=255;var d=new Uint8Array(this.device_spaces[c].buffer);z(a);z(c>>3,2);z(a,4);z(b,2);d[a]=b};wc.prototype.pci_write16=function(a,b){var c=a>>8&65535;a&=255;var d=new Uint16Array(this.device_spaces[c].buffer);16<=a&&44>a?z(a):(z(a),z(c>>3,2),z(a,4),z(b,4),d[a>>>1]=b)};
|
|
384
385
|
wc.prototype.pci_write32=function(a,b){var c=a>>8&65535;a&=255;var d=this.device_spaces[c],e=this.devices[c];if(d)if(16<=a&&40>a){e=e.pci_bars[a-16>>2];z(d[a>>2]);z(b>>>0);z(c>>3,2);if(e){c=a>>2;var f=d[c]&1;-1===(b|3|e.size-1)?(b=~(e.size-1)|f,0===f&&(d[c]=b)):0===f&&(d[c]=e.original_bar);if(1===f){f=d[c]&65534;var g=b&65534;z(f>>>0,8);z(g>>>0,8);this.set_io_bars(e,f,g);d[c]=b|1}}else d[a>>2]=0;z(d[a>>2]>>>0)}else 48===a?(z(c>>3,2),z(b>>>0,8),d[a>>2]=e.pci_rom_size?-1===(b|2047)?-e.pci_rom_size|
|
|
385
386
|
0:e.pci_rom_address|0:0):4===a?(z(c>>3,2),z(a,4),z(b>>>0,8)):(z(c>>3,2),z(a,4),z(b>>>0,8),d[a>>>2]=b)};wc.prototype.register_device=function(a){var b=a.pci_id;z(b);var c=new Int32Array(64);c.set(new Int32Array((new Uint8Array(a.pci_space)).buffer));this.device_spaces[b]=c;this.devices[b]=a;b=c.slice(4,10);for(var d=0;d<a.pci_bars.length;d++){var e=a.pci_bars[d];if(e){var f=b[d],g=f&1;z(f);e.original_bar=f;e.entries=[];if(0!==g)for(f&=-2,g=0;g<e.size;g++)e.entries[g]=this.io.ports[f+g]}}return c};
|
|
@@ -408,8 +409,8 @@ zc.prototype.receive=function(a){if(!(this.cr&1)&&(this.bus.send("eth-receive-en
|
|
|
408
409
|
single_handler:!1,handlers:[()=>{},c=>{const d=this.virtio.queues[c],e=3<c?c-3>>1:0;for(;d.has_request();){const f=d.pop_request(),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(2===c)for(c=this.virtio.queues[c];c.count_requests()>c.size-2;)c.pop_request()},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"],
|
|
409
410
|
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,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",
|
|
410
411
|
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,
|
|
411
|
-
e[0],e[1])},this)}}Ac.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);
|
|
412
|
-
Ac.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.rows;a[2]=this.cols;a[3]=this.ports;return a};Ac.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.rows=a[1];this.cols=a[2];this.ports=a[3]};Ac.prototype.reset=function(){this.virtio.reset()};Ac.prototype.SendEvent=function(a,b,c){const d=this.virtio.queues[2].pop_request(),e=new Uint8Array(8);
|
|
412
|
+
e[0],e[1])},this)}}Ac.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);I(["w","h","h","h","h"],[a,5,0,c,b],e,0);this.Send(2,d,e)};Ac.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)};
|
|
413
|
+
Ac.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.rows;a[2]=this.cols;a[3]=this.ports;return a};Ac.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.rows=a[1];this.cols=a[2];this.ports=a[3]};Ac.prototype.reset=function(){this.virtio.reset()};Ac.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)};
|
|
413
414
|
Ac.prototype.Send=function(a,b,c){b.set_next_blob(c);this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};Ac.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 Cc(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,
|
|
414
415
|
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)}
|
|
415
416
|
Cc.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 ka(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=
|
|
@@ -419,7 +420,7 @@ a[20]=this.command_register;a[21]=this.read_output_register;a[22]=this.read_comm
|
|
|
419
420
|
Cc.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];
|
|
420
421
|
this.command_register=a[20];this.read_output_register=a[21];this.read_command_register=a[22];this.controller_output_port=a[23];this.read_controller_output_port=a[24];this.mouse_id=a[25]||0;this.mouse_detect_state=a[26]||0;this.mouse_reset_workaround=a[27]||!1;this.next_byte_is_aux=this.next_byte_is_ready=!1;this.kbd_buffer.clear();this.mouse_buffer.clear();this.bus.send("mouse-enable",this.use_mouse)};
|
|
421
422
|
Cc.prototype.raise_irq=function(){this.next_byte_is_ready||(this.kbd_buffer.length?this.kbd_irq():this.mouse_buffer.length&&this.mouse_irq())};Cc.prototype.mouse_irq=function(){this.next_byte_is_aux=this.next_byte_is_ready=!0;this.command_register&2&&(this.cpu.device_lower_irq(12),this.cpu.device_raise_irq(12))};Cc.prototype.kbd_irq=function(){this.next_byte_is_ready=!0;this.next_byte_is_aux=!1;this.command_register&1&&(this.cpu.device_lower_irq(1),this.cpu.device_raise_irq(1))};
|
|
422
|
-
Cc.prototype.kbd_send_code=function(a){this.enable_keyboard_stream&&(z(a),this.kbd_buffer.push(a),this.raise_irq())};Cc.prototype.mouse_send_delta=function(a,b){
|
|
423
|
+
Cc.prototype.kbd_send_code=function(a){this.enable_keyboard_stream&&(z(a),this.kbd_buffer.push(a),this.raise_irq())};Cc.prototype.mouse_send_delta=function(a,b){this.have_mouse&&this.use_mouse&&(this.mouse_delta_x+=1*a,this.mouse_delta_y+=1*b,this.enable_mouse_stream&&(a=this.mouse_delta_x|0,b=this.mouse_delta_y|0,a||b))&&(this.mouse_delta_x-=a,this.mouse_delta_y-=b,this.send_mouse_packet(a,b))};
|
|
423
424
|
Cc.prototype.mouse_send_click=function(a,b,c){this.have_mouse&&this.use_mouse&&(this.mouse_clicks=a|c<<1|b<<2,this.enable_mouse_stream&&this.send_mouse_packet(0,0))};
|
|
424
425
|
Cc.prototype.send_mouse_packet=function(a,b){var c=(0>b)<<5|(0>a)<<4|8|this.mouse_clicks;this.last_mouse_packet=Date.now();this.mouse_buffer.push(c);this.mouse_buffer.push(a);this.mouse_buffer.push(b);4===this.mouse_id?(this.mouse_buffer.push(0|this.wheel_movement&15),this.wheel_movement=0):3===this.mouse_id&&(this.mouse_buffer.push(this.wheel_movement&255),this.wheel_movement=0);this.raise_irq()};
|
|
425
426
|
Cc.prototype.apply_scaling2=function(a){var b=a>>31;switch(Math.abs(a)){case 0:case 1:case 3:return a;case 2:return b;case 4:return 6*b;case 5:return 9*b;default:return a<<1}};
|
|
@@ -443,7 +444,7 @@ V.prototype.set_fda=function(a){var b={[163840]:{type:1,tracks:40,sectors:8,head
|
|
|
443
444
|
V.prototype.get_state=function(){var a=[];a[0]=this.bytes_expecting;a[1]=this.receiving_command;a[2]=this.receiving_index;a[4]=this.response_data;a[5]=this.response_index;a[6]=this.response_length;a[8]=this.status_reg0;a[9]=this.status_reg1;a[10]=this.status_reg2;a[11]=this.drive;a[12]=this.last_cylinder;a[13]=this.last_head;a[14]=this.last_sector;a[15]=this.dor;a[16]=this.sectors_per_track;a[17]=this.number_of_heads;a[18]=this.number_of_cylinders;return a};
|
|
444
445
|
V.prototype.set_state=function(a){this.bytes_expecting=a[0];this.receiving_command=a[1];this.receiving_index=a[2];this.next_command=a[3];this.response_data=a[4];this.response_index=a[5];this.response_length=a[6];this.status_reg0=a[8];this.status_reg1=a[9];this.status_reg2=a[10];this.drive=a[11];this.last_cylinder=a[12];this.last_head=a[13];this.last_sector=a[14];this.dor=a[15];this.sectors_per_track=a[16];this.number_of_heads=a[17];this.number_of_cylinders=a[18]};V.prototype.port3F0_read=function(){return 0};
|
|
445
446
|
V.prototype.port3F4_read=function(){var a=128;this.response_index<this.response_length&&(a|=80);0===(this.dor&8)&&(a|=32);return a};V.prototype.port3F7_read=function(){return this.dir};V.prototype.port3F5_read=function(){return this.response_index<this.response_length?(this.cpu.device_lower_irq(6),this.response_data[this.response_index++]):255};V.prototype.port3F4_write=function(a){z(a);a&128&&(this.status_reg0=192,this.cpu.device_raise_irq(6))};
|
|
446
|
-
V.prototype.port3F5_write=function(a){ra("3F5 write "+z(a),8192);if(0<this.bytes_expecting)this.receiving_command[this.receiving_index++]=a,this.bytes_expecting--,0===this.bytes_expecting&&this.next_command.call(this,this.receiving_command);else{switch(a){case 3:this.next_command=this.fix_drive_data;this.bytes_expecting=2;break;case 19:this.next_command=this.configure;this.bytes_expecting=3;break;case 4:this.next_command=this.check_drive_status;this.bytes_expecting=1;break;case 5:case 69:case 197:this.next_command=
|
|
447
|
+
V.prototype.port3F5_write=function(a){ra("3F5 write "+z(a),8192);if(0<this.bytes_expecting)this.receiving_command[this.receiving_index++]=a,this.bytes_expecting--,0===this.bytes_expecting&&this.next_command.call(this,this.receiving_command);else{switch(a){case 3:this.next_command=this.fix_drive_data;this.bytes_expecting=2;break;case 19:this.next_command=this.configure;this.bytes_expecting=3;break;case 4:case 20:this.next_command=this.check_drive_status;this.bytes_expecting=1;break;case 5:case 69:case 197:this.next_command=
|
|
447
448
|
function(b){this.do_sector(!0,b)};this.bytes_expecting=8;break;case 6:case 70:case 198:case 230:this.next_command=function(b){this.do_sector(!1,b)};this.bytes_expecting=8;break;case 7:this.next_command=this.calibrate;this.bytes_expecting=1;break;case 8:this.check_interrupt_status();break;case 74:this.next_command=this.read_sector_id;this.bytes_expecting=1;break;case 15:this.bytes_expecting=2;this.next_command=this.seek;break;case 14:case 16:this.status_reg0=128;this.response_data[0]=this.status_reg0;
|
|
448
449
|
this.response_index=0;this.response_length=1;this.bytes_expecting=0;break;default:sa(!1,"Unimplemented floppy command call "+z(a))}this.receiving_index=0}};V.prototype.port3F2_read=function(){return this.dor};V.prototype.port3F2_write=function(a){!(this.dor&4)&&a&4&&(this.status_reg0=192,a&8&&this.cpu.device_raise_irq(6));z(a>>4);z(a);this.dor=a};V.prototype.check_drive_status=function(){this.status_reg1=this.fda_image?0:5;this.response_index=0;this.response_length=1;this.response_data[0]=0};
|
|
449
450
|
V.prototype.seek=function(a){if(0===(a[0]&3)){var b=a[1];a=a[0]>>2&1;b!==this.last_cylinder&&(this.dir=0);this.status_reg1=this.fda_image?0:5;this.status_reg0=32;this.last_cylinder=b;this.last_head=a}this.raise_irq()};V.prototype.calibrate=function(a){this.seek([a[0],0])};V.prototype.check_interrupt_status=function(){this.response_index=0;this.response_length=2;this.response_data[0]=this.status_reg0;this.response_data[1]=this.last_cylinder};
|
|
@@ -605,14 +606,14 @@ d.pop_request();const f=new Uint8Array(e.length_readable);e.get_next_blob(f);thi
|
|
|
605
606
|
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]=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()}]},
|
|
606
607
|
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:()=>{}}]}})}Tc.prototype.Inflate=function(a){this.num_pages+=a;this.virtio.notify_config_changes()};Tc.prototype.Deflate=function(a){this.num_pages-=a;this.virtio.notify_config_changes()};
|
|
607
608
|
Tc.prototype.Cleanup=function(a){this.fp_cmd=2;this.free_cb=a;this.zeroed=0;this.virtio.notify_config_changes()};Tc.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.num_pages;a[2]=this.actual;return a};Tc.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.num_pages=a[1];this.actual=a[2]};Tc.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()};
|
|
608
|
-
Tc.prototype.Reset=function(){};function Uc(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)z(l);else if(l=f[257]|f[258]<<16,1400005704!==l)z(l);else{l=f[259];var m=e[529],n=f[283],p=g[139],q=g[140],r=e[565],y=518<=l?g[142]:255,x=g[146],u=g[147],
|
|
609
|
+
Tc.prototype.Reset=function(){};function Uc(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)z(l);else if(l=f[257]|f[258]<<16,1400005704!==l)z(l);else{l=f[259];var m=e[529],n=f[283],p=g[139],q=g[140],r=e[565],y=518<=l?g[142]:255,x=g[146],u=g[147],H=g[150],w=g[151],J=g[152];z(l);z(m);z(n);z(g[133]);z(p);z(q);z(r);z(y);z(x);z(u);z(w);z(H);z(J);e[528]=255;e[529]=m&-97|128;f[274]=56832;f[253]=65535;z(56832);d+="\x00";z(581632);g[138]=581632;for(e=0;e<d.length;e++)a[581632+
|
|
609
610
|
e]=d.charCodeAt(e);h=512*(h+1);z(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++]=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++]=
|
|
610
611
|
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 T(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,b,564,1);
|
|
611
612
|
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=k(Int32Array,
|
|
612
613
|
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,552,1);this.memory_map_read8=
|
|
613
614
|
[];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,b,1040,1);this.fpu_status_word[0]=
|
|
614
615
|
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,b,968,8);this.svga_dirty_bitmap_min_offset=
|
|
615
|
-
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)
|
|
616
|
+
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)}T.prototype.mmap_read8=function(a){return this.memory_map_read8[a>>>17](a)};T.prototype.mmap_write8=function(a,b){this.memory_map_write8[a>>>17](a,b)};T.prototype.mmap_read16=function(a){var b=this.memory_map_read8[a>>>17];return b(a)|b(a+1|0)<<8};
|
|
616
617
|
T.prototype.mmap_write16=function(a,b){var c=this.memory_map_write8[a>>>17];c(a,b&255);c(a+1|0,b>>8)};T.prototype.mmap_read32=function(a){return this.memory_map_read32[a>>>17](a)};T.prototype.mmap_write32=function(a,b){this.memory_map_write32[a>>>17](a,b)};T.prototype.mmap_write64=function(a,b,c){var d=this.memory_map_write32[a>>>17];d(a,b);d(a+4,c)};T.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)};
|
|
617
618
|
T.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))};T.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)};T.prototype.clear_opstats=function(){(new Uint8Array(this.wasm_memory.buffer,32768,131072)).fill(0);this.wm.exports.profiler_init()};
|
|
618
619
|
T.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};
|
|
@@ -646,22 +647,21 @@ l}else 32768<=e&&49152>e?this.fw_value=f(0):49152<=e&&e-49152<this.option_roms.l
|
|
|
646
647
|
c.register_write(161,this,this.portA1_write);c.register_read(1232,this,this.port4D0_read);c.register_read(1233,this,this.port4D1_read);c.register_write(1232,this,this.port4D0_write);c.register_write(1233,this,this.port4D1_write);this.devices={};a.load_devices&&(this.devices.pci=new wc(this),this.acpi_enabled[0]&&(this.devices.ioapic=new tc(this),this.devices.apic=new sc(this),this.devices.acpi=new uc(this)),this.devices.rtc=new db(this),this.fill_cmos(this.devices.rtc,a),this.devices.dma=new B(this),
|
|
647
648
|
this.devices.vga=new Y(this,b,a.screen,a.vga_memory_size||8388608),this.devices.ps2=new Cc(this,b),this.devices.uart0=new vc(this,1016,b),a.uart1&&(this.devices.uart1=new vc(this,760,b)),a.uart2&&(this.devices.uart2=new vc(this,1E3,b)),a.uart3&&(this.devices.uart3=new vc(this,744,b)),this.devices.fdc=new V(this,a.fda,a.fdb),c=[[void 0,void 0],[void 0,void 0]],a.hda&&(c[0][0]={buffer:a.hda},c[0][1]={buffer:a.hdb}),c[1][0]={is_cdrom:!0,buffer:a.cdrom},this.devices.ide=new Nc(this,b,c),this.devices.cdrom=
|
|
648
649
|
this.devices.ide.secondary.master,this.devices.pit=new eb(this,b),"ne2k"===a.net_device.type?this.devices.net=new zc(this,b,a.preserve_mac_from_state_image,a.mac_address_translation):"virtio"===a.net_device.type&&(this.devices.virtio_net=new Pc(this,b,a.preserve_mac_from_state_image)),a.fs9p&&(this.devices.virtio_9p=new Vc(a.fs9p,this,b)),a.virtio_console&&(this.devices.virtio_console=new Ac(this,b)),a.virtio_balloon&&(this.devices.virtio_balloon=new Tc(this,b)),this.devices.sb16=new E(this,b));a.multiboot&&
|
|
649
|
-
(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))};T.prototype.load_multiboot=function(a){this.load_multiboot_option_rom(a,void 0,"")&&(this.reg32[0]=this.io.port_read32(244))};
|
|
650
|
+
(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()};T.prototype.load_multiboot=function(a){this.load_multiboot_option_rom(a,void 0,"")&&(this.reg32[0]=this.io.port_read32(244))};
|
|
650
651
|
T.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;ra("Multiboot magic found, flags: "+z(f>>>0,8),2);var g=this;this.io.register_read(244,this,function(){return 0},function(){return 0},function(){var n=31860,p=0;if(c){p|=4;g.write32(31760,n);c+="\x00";
|
|
651
652
|
var q=(new TextEncoder).encode(c);g.write_blob(q,n);n+=q.length}if(f&2){p|=64;q=0;g.write32(31788,0);g.write32(31792,n);var r=0;var y=!1;for(let u=0;4294967296>u;u+=131072)y&&void 0!==g.memory_map_read8[u>>>17]?(g.write32(n,20),g.write32(n+4,r),g.write32(n+8,0),g.write32(n+12,u-r),g.write32(n+16,0),g.write32(n+20,1),n+=24,q+=24,y=!1):y||void 0!==g.memory_map_read8[u>>>17]||(r=u,y=!0);g.write32(31788,q)}g.write32(31744,p);q=p=0;if(f&65536){y=d[e+12>>2];p=d[e+16>>2];var x=d[e+20>>2];q=d[e+24>>2];r=
|
|
652
|
-
d[e+28>>2];z(y,8);z(p,8);z(x,8);z(q,8);z(r,8);y=new Uint8Array(a,e-(y-p),0===x?void 0:x-p);g.write_blob(y,p);p=r|0;q=Math.max(x,q)}else if(1179403647===d[0]){r=new DataView(a);const [u,
|
|
653
|
+
d[e+28>>2];z(y,8);z(p,8);z(x,8);z(q,8);z(r,8);y=new Uint8Array(a,e-(y-p),0===x?void 0:x-p);g.write_blob(y,p);p=r|0;q=Math.max(x,q)}else if(1179403647===d[0]){r=new DataView(a);const [u,H]=Kc(r,Hc);console.assert(52===H);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,
|
|
653
654
|
"Bad version1");console.assert(52===u.ehsize,"Bad header size");console.assert(32===u.phentsize,"Bad program header size");console.assert(40===u.shentsize,"Bad section header size");[p]=Lc(new DataView(r.buffer,r.byteOffset+u.phoff,u.phentsize*u.phnum),Ic,u.phnum);Lc(new DataView(r.buffer,r.byteOffset+u.shoff,u.shentsize*u.shnum),Jc,u.shnum);r=u;y=p;p=r.entry;for(x of y)0!==x.type&&(1===x.type?x.paddr+x.memsz<g.memory_size[0]?(x.filesz&&(y=new Uint8Array(a,x.offset,x.filesz),g.write_blob(y,x.paddr)),
|
|
654
655
|
q=Math.max(q,x.paddr+x.memsz),p===r.entry&&x.vaddr<=p&&x.vaddr+x.memsz>p&&(p=p-x.vaddr+x.paddr)):z(x.paddr):2===x.type||3===x.type||4===x.type||6===x.type||7===x.type||1685382480===x.type||1685382481===x.type||1685382482===x.type||1685382483===x.type||z(x.type))}b&&(g.write32(31764,1),g.write32(31768,n),x=q,0!==(x&4095)&&(x=(x&-4096)+4096),q=x+b.byteLength,g.write32(n,x),g.write32(n+4,q),g.write32(n+8,0),g.write32(n+12,0),g.write_blob(new Uint8Array(b),x));g.reg32[3]=31744;g.cr[0]=1;g.protected_mode[0]=
|
|
655
|
-
1;g.flags[0]=2;g.is_32[0]=1;g.stack_size_32[0]=1;for(n=0;6>n;n++)g.segment_is_null[n]=0,g.segment_offsets[n]=0,g.segment_limits[n]=4294967295,g.sreg[n]=45058;g.instruction_pointer[0]=g.get_seg_cs()+p|0;g.update_state_flags();g.
|
|
656
|
+
1;g.flags[0]=2;g.is_32[0]=1;g.stack_size_32[0]=1;for(n=0;6>n;n++)g.segment_is_null[n]=0,g.segment_offsets[n]=0,g.segment_limits[n]=4294967295,g.sreg[n]=45058;g.instruction_pointer[0]=g.get_seg_cs()+p|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 "+z(n,2));throw"HALT";},function(){},function(){},function(){});for(let n=0;15>=n;n++){function p(q){z(n);z(q,2);q?this.device_raise_irq(n):
|
|
656
657
|
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}}};
|
|
657
658
|
T.prototype.fill_cmos=function(a,b){var c=b.boot_order||291;a.cmos_write(56,1|c>>4&240);a.cmos_write(61,c&255);a.cmos_write(21,128);a.cmos_write(22,2);c=0;1048576<=this.memory_size[0]&&(c=this.memory_size[0]-1048576>>10,c=Math.min(c,65535));a.cmos_write(23,c&255);a.cmos_write(24,c>>8&255);a.cmos_write(48,c&255);a.cmos_write(49,c>>8&255);c=0;16777216<=this.memory_size[0]&&(c=this.memory_size[0]-16777216>>16,c=Math.min(c,65535));a.cmos_write(52,c&255);a.cmos_write(53,c>>8&255);a.cmos_write(91,0);a.cmos_write(92,
|
|
658
659
|
0);a.cmos_write(93,0);a.cmos_write(20,47);a.cmos_write(95,0);b.fastboot&&a.cmos_write(63,1)};
|
|
659
660
|
T.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=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))}};
|
|
660
661
|
T.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)})};T.prototype.log_uncompiled_code=function(){};T.prototype.dump_function_code=function(){};
|
|
661
|
-
T.prototype.run_hardware_timers=function(a,b){const c=this.devices.pit.timer(b,!1),d=this.devices.rtc.timer(b,!1);let e=100,f=100;a&&(e=this.devices.acpi.timer(b),f=this.devices.apic.timer(b));return Math.min(c,d,e,f)};T.prototype.device_raise_irq=function(a){this.pic_set_irq(a);this.devices.ioapic&&this.devices.ioapic.set_irq(a)};T.prototype.device_lower_irq=function(a){this.pic_clear_irq(a);this.devices.ioapic&&this.devices.ioapic.clear_irq(a)};
|
|
662
|
-
T.prototype.
|
|
663
|
-
function(
|
|
664
|
-
require("./libwabt.cjs"):new window.WabtModule,void 0===e))return;f=f.slice();try{var g=e.readWasm(f,{readDebugNames:!1});g.generateNames();g.applyNames();g.toText({foldExprs:!0,inlineExport:!0})}catch(m){var h=new Blob([f]),l=document.createElement("a");l.download="failed.wasm";l.href=window.URL.createObjectURL(h);l.dataset.downloadurl=["application/octet-stream",l.download,l.href].join(":");l.click();window.URL.revokeObjectURL(l.src);console.log(m.toString())}finally{g&&g.destroy()}}};function Bc(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=[];this.name=b.name;this.driver_feature_select=this.device_feature_select=0;
|
|
662
|
+
T.prototype.run_hardware_timers=function(a,b){const c=this.devices.pit.timer(b,!1),d=this.devices.rtc.timer(b,!1);let e=100,f=100;a&&(e=this.devices.acpi.timer(b),f=this.devices.apic.timer(b));return Math.min(c,d,e,f)};T.prototype.device_raise_irq=function(a){this.pic_set_irq(a);this.devices.ioapic&&this.devices.ioapic.set_irq(a)};T.prototype.device_lower_irq=function(a){this.pic_clear_irq(a);this.devices.ioapic&&this.devices.ioapic.clear_irq(a)};T.prototype.debug_init=function(){};
|
|
663
|
+
T.prototype.dump_stack=function(){};T.prototype.debug_get_state=function(){};T.prototype.dump_state=function(){};T.prototype.get_regs_short=function(){};T.prototype.dump_regs_short=function(){};T.prototype.dump_gdt_ldt=function(){};T.prototype.dump_idt=function(){};T.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)};
|
|
664
|
+
T.prototype.dump_page_directory=function(){};T.prototype.get_memory_dump=function(){};T.prototype.memory_hex_dump=function(){};T.prototype.used_memory_dump=function(){};T.prototype.debug_interrupt=function(){};T.prototype.debug_dump_code=function(){};T.prototype.dump_wasm=function(){};function Bc(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=[];this.name=b.name;this.driver_feature_select=this.device_feature_select=0;
|
|
665
665
|
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=this.queues[0];this.isr_status=0;c=[];c.push(this.create_common_capability(b.common));
|
|
666
666
|
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()}
|
|
667
667
|
Bc.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",
|
|
@@ -696,20 +696,20 @@ Wc.prototype.set_next_blob=function(a){let b=0,c=a.length;for(;c&&this.write_buf
|
|
|
696
696
|
single_handler:!1,handlers:[d=>{if(0===d){for(;this.virtqueue.has_request();)d=this.virtqueue.pop_request(),this.ReceiveRequest(d);this.virtqueue.notify_me_after(0)}}]},isr_status:{initial_port:42752},device_specific:{initial_port:42496,struct:[{bytes:2,name:"mount tag length",read:()=>this.configspace_taglen,write:()=>{}}].concat(Array.from(Array(254).keys()).map(d=>({bytes:1,name:"mount tag name "+d,read:()=>this.configspace_tagname[d]||0,write:()=>{}})))}});this.virtqueue=this.virtio.queues[0]}
|
|
697
697
|
Vc.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,b.type,b.uid,b.dbg_name]});a[9]=this.fs;return a};
|
|
698
698
|
Vc.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])};Vc.prototype.Createfid=function(a,b,c,d){return{inodeid:a,type:b,uid:c,dbg_name:d}};
|
|
699
|
-
Vc.prototype.update_dbg_name=function(a,b){for(const c of this.fids)c.inodeid===a&&(c.dbg_name=b)};Vc.prototype.reset=function(){this.fids=[];this.virtio.reset()};Vc.prototype.BuildReply=function(a,b,c){
|
|
699
|
+
Vc.prototype.update_dbg_name=function(a,b){for(const c of this.fids)c.inodeid===a&&(c.dbg_name=b)};Vc.prototype.reset=function(){this.fids=[];this.virtio.reset()};Vc.prototype.BuildReply=function(a,b,c){I(["w","b","h"],[c+7,a+1,b],this.replybuffer,0);this.replybuffersize=c+7};Vc.prototype.SendError=function(a,b,c){b=I(["w"],[c],this.replybuffer,7);this.BuildReply(6,a,b)};
|
|
700
700
|
Vc.prototype.SendReply=function(a){a.set_next_blob(this.replybuffer.subarray(0,this.replybuffersize));this.virtqueue.push_reply(a);this.virtqueue.flush_replies()};
|
|
701
|
-
Vc.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[0],f=d[1],g=d[2];switch(f){case 8:e=this.fs.GetTotalSize();var h=this.fs.GetSpace();d=[16914839];d[1]=this.BLOCKSIZE;d[2]=Math.floor(h/d[1]);d[3]=d[2]-Math.floor(e/d[1]);d[4]=d[2]-Math.floor(e/d[1]);d[5]=this.fs.CountUsedInodes();d[6]=this.fs.CountFreeInodes();d[7]=0;d[8]=256;e=
|
|
702
|
-
break;case 112:case 12:d=L(["w","w"],b,c);e=d[0];c=d[1];b=this.fids[e].inodeid;var l=this.fs.GetInode(b);h=this.fs.OpenInode(b,c);this.fs.AddEvent(this.fids[e].inodeid,function(){var q=[];q[0]=l.qid;q[1]=this.msize-24;
|
|
703
|
-
-h,-h);this.SendReply(a);break}this.BuildReply(f,g,0);this.SendReply(a);break;case 16:d=L(["w","s","s","w"],b,c);e=d[0];h=d[1];var m=d[3];b=this.fs.CreateSymlink(h,this.fids[e].inodeid,d[2]);l=this.fs.GetInode(b);l.uid=this.fids[e].uid;l.gid=m;
|
|
704
|
-
l.gid=m;
|
|
705
|
-
break;case 14:d=L(["w","s","w","w","w"],b,c);e=d[0];h=d[1];b=d[2];c=d[3];m=d[4];this.bus.send("9p-create",[h,this.fids[e].inodeid]);b=this.fs.CreateFile(h,this.fids[e].inodeid);this.fids[e].inodeid=b;this.fids[e].type=1;this.fids[e].dbg_name=h;l=this.fs.GetInode(b);l.uid=this.fids[e].uid;l.gid=m;l.mode=c|32768;
|
|
706
|
-
d[3],h,d[5],d[6]);h=this.fs.Lock(this.fids[e].inodeid,d,b);
|
|
707
|
-
e=d[0];l=this.fs.GetInode(this.fids[e].inodeid);if(!l||4===l.status){this.SendError(g,"No such file or directory",2);this.SendReply(a);break}d[0]=d[1];d[1]=l.qid;d[2]=l.mode;d[3]=l.uid;d[4]=l.gid;d[5]=l.nlinks;d[6]=l.major<<8|l.minor;d[7]=l.size;d[8]=this.BLOCKSIZE;d[9]=Math.floor(l.size/512+1);d[10]=l.atime;d[11]=0;d[12]=l.mtime;d[13]=0;d[14]=l.ctime;d[15]=0;d[16]=0;d[17]=0;d[18]=0;d[19]=0;
|
|
701
|
+
Vc.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[0],f=d[1],g=d[2];switch(f){case 8:e=this.fs.GetTotalSize();var h=this.fs.GetSpace();d=[16914839];d[1]=this.BLOCKSIZE;d[2]=Math.floor(h/d[1]);d[3]=d[2]-Math.floor(e/d[1]);d[4]=d[2]-Math.floor(e/d[1]);d[5]=this.fs.CountUsedInodes();d[6]=this.fs.CountFreeInodes();d[7]=0;d[8]=256;e=I("wwddddddw".split(""),d,this.replybuffer,7);this.BuildReply(f,g,e);this.SendReply(a);
|
|
702
|
+
break;case 112:case 12:d=L(["w","w"],b,c);e=d[0];c=d[1];b=this.fids[e].inodeid;var l=this.fs.GetInode(b);h=this.fs.OpenInode(b,c);this.fs.AddEvent(this.fids[e].inodeid,function(){var q=[];q[0]=l.qid;q[1]=this.msize-24;I(["Q","w"],q,this.replybuffer,7);this.BuildReply(f,g,17);this.SendReply(a)}.bind(this));break;case 70:d=L(["w","w","s"],b,c);b=d[0];e=d[1];h=d[2];h=this.fs.Link(this.fids[b].inodeid,this.fids[e].inodeid,h);if(0>h){this.SendError(g,-1===h?"Operation not permitted":"Unknown error: "+
|
|
703
|
+
-h,-h);this.SendReply(a);break}this.BuildReply(f,g,0);this.SendReply(a);break;case 16:d=L(["w","s","s","w"],b,c);e=d[0];h=d[1];var m=d[3];b=this.fs.CreateSymlink(h,this.fids[e].inodeid,d[2]);l=this.fs.GetInode(b);l.uid=this.fids[e].uid;l.gid=m;I(["Q"],[l.qid],this.replybuffer,7);this.BuildReply(f,g,13);this.SendReply(a);break;case 18:d=L("wswwww".split(""),b,c);e=d[0];h=d[1];c=d[2];b=d[3];var n=d[4];m=d[5];b=this.fs.CreateNode(h,this.fids[e].inodeid,b,n);l=this.fs.GetInode(b);l.mode=c;l.uid=this.fids[e].uid;
|
|
704
|
+
l.gid=m;I(["Q"],[l.qid],this.replybuffer,7);this.BuildReply(f,g,13);this.SendReply(a);break;case 22:d=L(["w"],b,c);e=d[0];l=this.fs.GetInode(this.fids[e].inodeid);e=I(["s"],[l.symlink],this.replybuffer,7);this.BuildReply(f,g,e);this.SendReply(a);break;case 72:d=L(["w","s","w","w"],b,c);e=d[0];h=d[1];c=d[2];m=d[3];b=this.fs.CreateDirectory(h,this.fids[e].inodeid);l=this.fs.GetInode(b);l.mode=c|16384;l.uid=this.fids[e].uid;l.gid=m;I(["Q"],[l.qid],this.replybuffer,7);this.BuildReply(f,g,13);this.SendReply(a);
|
|
705
|
+
break;case 14:d=L(["w","s","w","w","w"],b,c);e=d[0];h=d[1];b=d[2];c=d[3];m=d[4];this.bus.send("9p-create",[h,this.fids[e].inodeid]);b=this.fs.CreateFile(h,this.fids[e].inodeid);this.fids[e].inodeid=b;this.fids[e].type=1;this.fids[e].dbg_name=h;l=this.fs.GetInode(b);l.uid=this.fids[e].uid;l.gid=m;l.mode=c|32768;I(["Q","w"],[l.qid,this.msize-24],this.replybuffer,7);this.BuildReply(f,g,17);this.SendReply(a);break;case 52:d=L("wbwddws".split(""),b,c);e=d[0];b=d[2];h=0===d[4]?Infinity:d[4];d=this.fs.DescribeLock(d[1],
|
|
706
|
+
d[3],h,d[5],d[6]);h=this.fs.Lock(this.fids[e].inodeid,d,b);I(["b"],[h],this.replybuffer,7);this.BuildReply(f,g,1);this.SendReply(a);break;case 54:d=L("wbddws".split(""),b,c);e=d[0];h=0===d[3]?Infinity:d[3];d=this.fs.DescribeLock(d[1],d[2],h,d[4],d[5]);h=this.fs.GetLock(this.fids[e].inodeid,d);h||(h=d,h.type=2);e=I(["b","d","d","w","s"],[h.type,h.start,Infinity===h.length?0:h.length,h.proc_id,h.client_id],this.replybuffer,7);this.BuildReply(f,g,e);this.SendReply(a);break;case 24:d=L(["w","d"],b,c);
|
|
707
|
+
e=d[0];l=this.fs.GetInode(this.fids[e].inodeid);if(!l||4===l.status){this.SendError(g,"No such file or directory",2);this.SendReply(a);break}d[0]=d[1];d[1]=l.qid;d[2]=l.mode;d[3]=l.uid;d[4]=l.gid;d[5]=l.nlinks;d[6]=l.major<<8|l.minor;d[7]=l.size;d[8]=this.BLOCKSIZE;d[9]=Math.floor(l.size/512+1);d[10]=l.atime;d[11]=0;d[12]=l.mtime;d[13]=0;d[14]=l.ctime;d[15]=0;d[16]=0;d[17]=0;d[18]=0;d[19]=0;I("dQwwwddddddddddddddd".split(""),d,this.replybuffer,7);this.BuildReply(f,g,153);this.SendReply(a);break;case 26:d=
|
|
708
708
|
L("wwwwwddddd".split(""),b,c);e=d[0];l=this.fs.GetInode(this.fids[e].inodeid);d[1]&1&&(l.mode=d[2]);d[1]&2&&(l.uid=d[3]);d[1]&4&&(l.gid=d[4]);d[1]&16&&(l.atime=Math.floor((new Date).getTime()/1E3));d[1]&32&&(l.mtime=Math.floor((new Date).getTime()/1E3));d[1]&64&&(l.ctime=Math.floor((new Date).getTime()/1E3));d[1]&128&&(l.atime=d[6]);d[1]&256&&(l.mtime=d[8]);d[1]&8&&await this.fs.ChangeSize(this.fids[e].inodeid,d[5]);this.BuildReply(f,g,0);this.SendReply(a);break;case 50:d=L(["w","d"],b,c);e=d[0];
|
|
709
709
|
this.BuildReply(f,g,0);this.SendReply(a);break;case 40:case 116:d=L(["w","d","w"],b,c);e=d[0];h=d[1];m=d[2];l=this.fs.GetInode(this.fids[e].inodeid);if(!l||4===l.status){this.SendError(g,"No such file or directory",2);this.SendReply(a);break}if(2===this.fids[e].type)for(l.caps.length<h+m&&(m=l.caps.length-h),d=0;d<m;d++)this.replybuffer[11+d]=l.caps[h+d];else this.fs.OpenInode(this.fids[e].inodeid,void 0),d=this.fids[e].inodeid,m=Math.min(m,this.replybuffer.length-11),l.size<h+m?m=l.size-h:40===f&&
|
|
710
|
-
(m=this.fs.RoundToDirentry(d,h+m)-h),h>l.size&&(m=0),this.bus.send("9p-read-start",[this.fids[e].dbg_name]),d=await this.fs.Read(d,h,m),this.bus.send("9p-read-end",[this.fids[e].dbg_name,m]),d&&this.replybuffer.set(d,11);
|
|
711
|
-
h,m,b.subarray(c.offset));this.bus.send("9p-write-end",[d,m]);
|
|
710
|
+
(m=this.fs.RoundToDirentry(d,h+m)-h),h>l.size&&(m=0),this.bus.send("9p-read-start",[this.fids[e].dbg_name]),d=await this.fs.Read(d,h,m),this.bus.send("9p-read-end",[this.fids[e].dbg_name,m]),d&&this.replybuffer.set(d,11);I(["w"],[m],this.replybuffer,7);this.BuildReply(f,g,4+m);this.SendReply(a);break;case 118:d=L(["w","d","w"],b,c);e=d[0];h=d[1];m=d[2];d=this.fids[e].dbg_name;if(2===this.fids[e].type){this.SendError(g,"Setxattr not supported",95);this.SendReply(a);break}else await this.fs.Write(this.fids[e].inodeid,
|
|
711
|
+
h,m,b.subarray(c.offset));this.bus.send("9p-write-end",[d,m]);I(["w"],[m],this.replybuffer,7);this.BuildReply(f,g,4);this.SendReply(a);break;case 74:d=L(["w","s","w","s"],b,c);h=await this.fs.Rename(this.fids[d[0]].inodeid,d[1],this.fids[d[2]].inodeid,d[3]);if(0>h){this.SendError(g,-2===h?"No such file or directory":-1===h?"Operation not permitted":-39===h?"Directory not empty":"Unknown error: "+-h,-h);this.SendReply(a);break}this.BuildReply(f,g,0);this.SendReply(a);break;case 76:d=L(["w","s","w"],
|
|
712
712
|
b,c);c=d[0];h=d[1];b=d[2];e=this.fs.Search(this.fids[c].inodeid,h);if(-1===e){this.SendError(g,"No such file or directory",2);this.SendReply(a);break}h=this.fs.Unlink(this.fids[c].inodeid,h);if(0>h){this.SendError(g,-39===h?"Directory not empty":-1===h?"Operation not permitted":"Unknown error: "+-h,-h);this.SendReply(a);break}this.BuildReply(f,g,0);this.SendReply(a);break;case 100:e=L(["w","s"],b,c);this.msize!==e[0]&&(this.msize=e[0],this.replybuffer=new Uint8Array(Math.min(16777216,2*this.msize)));
|
|
713
|
-
e=
|
|
714
|
-
L(["w","w","h"],b,c);e=d[0];m=d[1];n=d[2];if(0===n){this.fids[m]=this.Createfid(this.fids[e].inodeid,1,this.fids[e].uid,this.fids[e].dbg_name);
|
|
713
|
+
e=I(["w","s"],[this.msize,this.VERSION],this.replybuffer,7);this.BuildReply(f,g,e);this.SendReply(a);break;case 104:d=L(["w","w","s","s","w"],b,c);e=d[0];h=d[4];ra("[attach]: fid="+e+" afid="+z(d[1])+" uname="+d[2]+" aname="+d[3],4194304);this.fids[e]=this.Createfid(0,1,h,"");l=this.fs.GetInode(this.fids[e].inodeid);I(["Q"],[l.qid],this.replybuffer,7);this.BuildReply(f,g,13);this.SendReply(a);this.bus.send("9p-attach");break;case 108:d=L(["h"],b,c);this.BuildReply(f,g,0);this.SendReply(a);break;case 110:d=
|
|
714
|
+
L(["w","w","h"],b,c);e=d[0];m=d[1];n=d[2];if(0===n){this.fids[m]=this.Createfid(this.fids[e].inodeid,1,this.fids[e].uid,this.fids[e].dbg_name);I(["h"],[0],this.replybuffer,7);this.BuildReply(f,g,2);this.SendReply(a);break}h=[];for(d=0;d<n;d++)h.push("s");c=L(h,b,c);b=this.fids[e].inodeid;h=9;var p=0;for(d=0;d<n;d++){b=this.fs.Search(b,c[d]);if(-1===b)break;h+=I(["Q"],[this.fs.GetInode(b).qid],this.replybuffer,h);p++;this.fids[m]=this.Createfid(b,1,this.fids[e].uid,c[d])}I(["h"],[p],this.replybuffer,
|
|
715
715
|
7);this.BuildReply(f,g,h-7);this.SendReply(a);break;case 120:d=L(["w"],b,c);this.fids[d[0]]&&0<=this.fids[d[0]].inodeid&&(await this.fs.CloseInode(this.fids[d[0]].inodeid),this.fids[d[0]].inodeid=-1,this.fids[d[0]].type=-1);this.BuildReply(f,g,0);this.SendReply(a);break;case 32:d=L(["w","s","d","w"],b,c);e=d[0];h=d[1];b=d[3];this.fids[e].type=2;this.BuildReply(f,g,0);this.SendReply(a);break;case 30:d=L(["w","w","s"],b,c),e=d[0],h=d[2],this.SendError(g,"Setxattr not supported",95),this.SendReply(a)}};}).call(this);
|