v86 0.5.284 → 0.5.291
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/libv86-debug.js +16 -14
- package/build/libv86-debug.mjs +117 -117
- package/build/libv86.js +10 -10
- package/build/libv86.mjs +32 -31
- package/package.json +1 -1
package/build/libv86-debug.js
CHANGED
|
@@ -2204,12 +2204,12 @@ function $restore_state$$module$src$state$$($cpu$jscomp$5$$, $state$jscomp$9$$)
|
|
|
2204
2204
|
$state$jscomp$9$$ = new Uint8Array($state$jscomp$9$$);
|
|
2205
2205
|
if (4247762216 === (new Uint32Array($state$jscomp$9$$.buffer, 0, 1))[0]) {
|
|
2206
2206
|
var $buffers$jscomp$4_ctx_info_block_len$jscomp$1$$ = $cpu$jscomp$5$$.zstd_create_ctx($state$jscomp$9$$.length);
|
|
2207
|
-
(new Uint8Array($cpu$jscomp$5$$.wasm_memory.buffer, $cpu$jscomp$5$$.zstd_get_src_ptr($buffers$jscomp$4_ctx_info_block_len$jscomp$1$$), $state$jscomp$9$$.length)).set($state$jscomp$9$$);
|
|
2208
|
-
var $buffer_infos$jscomp$2_info_block_obj$jscomp$1_ptr_state_object$$ = $cpu$jscomp$5$$.zstd_read($buffers$jscomp$4_ctx_info_block_len$jscomp$1$$, 16), $buffers$jscomp$3_header_block$jscomp$2_info_block_buffer$jscomp$1_info_block_obj$$ = new Uint8Array($cpu$jscomp$5$$.wasm_memory.buffer, $buffer_infos$jscomp$2_info_block_obj$jscomp$1_ptr_state_object
|
|
2207
|
+
(new Uint8Array($cpu$jscomp$5$$.wasm_memory.buffer, $cpu$jscomp$5$$.zstd_get_src_ptr($buffers$jscomp$4_ctx_info_block_len$jscomp$1$$) >>> 0, $state$jscomp$9$$.length)).set($state$jscomp$9$$);
|
|
2208
|
+
var $buffer_infos$jscomp$2_info_block_obj$jscomp$1_ptr_state_object$$ = $cpu$jscomp$5$$.zstd_read($buffers$jscomp$4_ctx_info_block_len$jscomp$1$$, 16), $buffers$jscomp$3_header_block$jscomp$2_info_block_buffer$jscomp$1_info_block_obj$$ = new Uint8Array($cpu$jscomp$5$$.wasm_memory.buffer, $buffer_infos$jscomp$2_info_block_obj$jscomp$1_ptr_state_object$$ >>> 0, 16), $info_block_len_position$jscomp$1$$ = $read_state_header$$($buffers$jscomp$3_header_block$jscomp$2_info_block_buffer$jscomp$1_info_block_obj$$,
|
|
2209
2209
|
!1);
|
|
2210
2210
|
$cpu$jscomp$5$$.zstd_read_free($buffer_infos$jscomp$2_info_block_obj$jscomp$1_ptr_state_object$$, 16);
|
|
2211
2211
|
$buffer_infos$jscomp$2_info_block_obj$jscomp$1_ptr_state_object$$ = $cpu$jscomp$5$$.zstd_read($buffers$jscomp$4_ctx_info_block_len$jscomp$1$$, $info_block_len_position$jscomp$1$$);
|
|
2212
|
-
$buffers$jscomp$3_header_block$jscomp$2_info_block_buffer$jscomp$1_info_block_obj$$ = new Uint8Array($cpu$jscomp$5$$.wasm_memory.buffer, $buffer_infos$jscomp$2_info_block_obj$jscomp$1_ptr_state_object
|
|
2212
|
+
$buffers$jscomp$3_header_block$jscomp$2_info_block_buffer$jscomp$1_info_block_obj$$ = new Uint8Array($cpu$jscomp$5$$.wasm_memory.buffer, $buffer_infos$jscomp$2_info_block_obj$jscomp$1_ptr_state_object$$ >>> 0, $info_block_len_position$jscomp$1$$);
|
|
2213
2213
|
$buffers$jscomp$3_header_block$jscomp$2_info_block_buffer$jscomp$1_info_block_obj$$ = $read_info_block$$($buffers$jscomp$3_header_block$jscomp$2_info_block_buffer$jscomp$1_info_block_obj$$);
|
|
2214
2214
|
$cpu$jscomp$5$$.zstd_read_free($buffer_infos$jscomp$2_info_block_obj$jscomp$1_ptr_state_object$$, $info_block_len_position$jscomp$1$$);
|
|
2215
2215
|
$buffer_infos$jscomp$2_info_block_obj$jscomp$1_ptr_state_object$$ = $buffers$jscomp$3_header_block$jscomp$2_info_block_buffer$jscomp$1_info_block_obj$$.state;
|
|
@@ -2219,7 +2219,7 @@ function $restore_state$$module$src$state$$($cpu$jscomp$5$$, $state$jscomp$9$$)
|
|
|
2219
2219
|
for (var $buffer_info_info_block_buffer$jscomp$2_state_object$jscomp$1$$ of $buffer_infos$jscomp$1_front_padding$$) {
|
|
2220
2220
|
$buffer_infos$jscomp$1_front_padding$$ = ($info_block_len_position$jscomp$1$$ + 3 & -4) - $info_block_len_position$jscomp$1$$;
|
|
2221
2221
|
if (1048576 < $buffer_info_info_block_buffer$jscomp$2_state_object$jscomp$1$$.length) {
|
|
2222
|
-
var $buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$ = $cpu$jscomp$5$$.zstd_read($buffers$jscomp$4_ctx_info_block_len$jscomp$1$$, $buffer_infos$jscomp$1_front_padding$$);
|
|
2222
|
+
var $buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$ = $cpu$jscomp$5$$.zstd_read($buffers$jscomp$4_ctx_info_block_len$jscomp$1$$, $buffer_infos$jscomp$1_front_padding$$) >>> 0;
|
|
2223
2223
|
$cpu$jscomp$5$$.zstd_read_free($buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$, $buffer_infos$jscomp$1_front_padding$$);
|
|
2224
2224
|
$buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$ = new Uint8Array($buffer_info_info_block_buffer$jscomp$2_state_object$jscomp$1$$.length);
|
|
2225
2225
|
$buffers$jscomp$3_header_block$jscomp$2_info_block_buffer$jscomp$1_info_block_obj$$.push($buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$.buffer);
|
|
@@ -2228,12 +2228,12 @@ function $restore_state$$module$src$state$$($cpu$jscomp$5$$, $state$jscomp$9$$)
|
|
|
2228
2228
|
$dbg_assert$$module$src$log$$(0 <= $remaining_to_read$$);
|
|
2229
2229
|
$remaining_to_read$$ = Math.min($remaining_to_read$$, 1048576);
|
|
2230
2230
|
const $ptr$jscomp$2$$ = $cpu$jscomp$5$$.zstd_read($buffers$jscomp$4_ctx_info_block_len$jscomp$1$$, $remaining_to_read$$);
|
|
2231
|
-
$buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$.set(new Uint8Array($cpu$jscomp$5$$.wasm_memory.buffer, $ptr$jscomp$2
|
|
2231
|
+
$buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$.set(new Uint8Array($cpu$jscomp$5$$.wasm_memory.buffer, $ptr$jscomp$2$$ >>> 0, $remaining_to_read$$), $have_offset$jscomp$39$$);
|
|
2232
2232
|
$cpu$jscomp$5$$.zstd_read_free($ptr$jscomp$2$$, $remaining_to_read$$);
|
|
2233
2233
|
$have_offset$jscomp$39$$ += $remaining_to_read$$;
|
|
2234
2234
|
}
|
|
2235
2235
|
} else {
|
|
2236
|
-
$buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$ = $cpu$jscomp$5$$.zstd_read($buffers$jscomp$4_ctx_info_block_len$jscomp$1$$, $buffer_infos$jscomp$1_front_padding$$ + $buffer_info_info_block_buffer$jscomp$2_state_object$jscomp$1$$.length), $have_offset$jscomp$39$$ = $buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$ + $buffer_infos$jscomp$1_front_padding$$, $buffers$jscomp$3_header_block$jscomp$2_info_block_buffer$jscomp$1_info_block_obj$$.push($cpu$jscomp$5$$.wasm_memory.buffer.slice($have_offset$jscomp$39$$,
|
|
2236
|
+
$buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$ = $cpu$jscomp$5$$.zstd_read($buffers$jscomp$4_ctx_info_block_len$jscomp$1$$, $buffer_infos$jscomp$1_front_padding$$ + $buffer_info_info_block_buffer$jscomp$2_state_object$jscomp$1$$.length), $have_offset$jscomp$39$$ = ($buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$ >>> 0) + $buffer_infos$jscomp$1_front_padding$$, $buffers$jscomp$3_header_block$jscomp$2_info_block_buffer$jscomp$1_info_block_obj$$.push($cpu$jscomp$5$$.wasm_memory.buffer.slice($have_offset$jscomp$39$$,
|
|
2237
2237
|
$have_offset$jscomp$39$$ + $buffer_info_info_block_buffer$jscomp$2_state_object$jscomp$1$$.length)), $cpu$jscomp$5$$.zstd_read_free($buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$, $buffer_infos$jscomp$1_front_padding$$ + $buffer_info_info_block_buffer$jscomp$2_state_object$jscomp$1$$.length);
|
|
2238
2238
|
}
|
|
2239
2239
|
$info_block_len_position$jscomp$1$$ += $buffer_infos$jscomp$1_front_padding$$ + $buffer_info_info_block_buffer$jscomp$2_state_object$jscomp$1$$.length;
|
|
@@ -4480,24 +4480,26 @@ $MemoryFileStorage$$module$src$browser$filestorage$$.prototype.cache = async fun
|
|
|
4480
4480
|
$MemoryFileStorage$$module$src$browser$filestorage$$.prototype.uncache = function($sha256sum$jscomp$5$$) {
|
|
4481
4481
|
this.filedata.delete($sha256sum$jscomp$5$$);
|
|
4482
4482
|
};
|
|
4483
|
-
function $ServerFileStorageWrapper$$module$src$browser$filestorage$$($file_storage$$, $baseurl$$) {
|
|
4483
|
+
function $ServerFileStorageWrapper$$module$src$browser$filestorage$$($file_storage$$, $baseurl$$, $zstd_decompress$jscomp$1$$) {
|
|
4484
4484
|
$dbg_assert$$module$src$log$$($baseurl$$, "ServerMemoryFileStorage: baseurl should not be empty");
|
|
4485
4485
|
$baseurl$$.endsWith("/") || ($baseurl$$ += "/");
|
|
4486
4486
|
this.storage = $file_storage$$;
|
|
4487
4487
|
this.baseurl = $baseurl$$;
|
|
4488
|
+
this.zstd_decompress = $zstd_decompress$jscomp$1$$;
|
|
4488
4489
|
}
|
|
4489
|
-
$ServerFileStorageWrapper$$module$src$browser$filestorage$$.prototype.load_from_server = function($sha256sum$jscomp$6$$) {
|
|
4490
|
+
$ServerFileStorageWrapper$$module$src$browser$filestorage$$.prototype.load_from_server = function($sha256sum$jscomp$6$$, $file_size$jscomp$1$$) {
|
|
4490
4491
|
return new Promise($resolve$jscomp$1$$ => {
|
|
4491
4492
|
$load_file$$module$src$lib$$(this.baseurl + $sha256sum$jscomp$6$$, {done:async $buffer$jscomp$38_data$jscomp$147$$ => {
|
|
4492
4493
|
$buffer$jscomp$38_data$jscomp$147$$ = new Uint8Array($buffer$jscomp$38_data$jscomp$147$$);
|
|
4494
|
+
$sha256sum$jscomp$6$$.endsWith(".zst") && ($buffer$jscomp$38_data$jscomp$147$$ = new Uint8Array(this.zstd_decompress($file_size$jscomp$1$$, $buffer$jscomp$38_data$jscomp$147$$)));
|
|
4493
4495
|
await this.cache($sha256sum$jscomp$6$$, $buffer$jscomp$38_data$jscomp$147$$);
|
|
4494
4496
|
$resolve$jscomp$1$$($buffer$jscomp$38_data$jscomp$147$$);
|
|
4495
4497
|
}});
|
|
4496
4498
|
});
|
|
4497
4499
|
};
|
|
4498
|
-
$ServerFileStorageWrapper$$module$src$browser$filestorage$$.prototype.read = async function($sha256sum$jscomp$7$$, $offset$jscomp$52$$, $count$jscomp$49$$) {
|
|
4499
|
-
const $data$jscomp$148$$ = await this.storage.read($sha256sum$jscomp$7$$, $offset$jscomp$52$$, $count$jscomp$49$$);
|
|
4500
|
-
return $data$jscomp$148$$ ? $data$jscomp$148$$ : (await this.load_from_server($sha256sum$jscomp$7$$)).subarray($offset$jscomp$52$$, $offset$jscomp$52$$ + $count$jscomp$49$$);
|
|
4500
|
+
$ServerFileStorageWrapper$$module$src$browser$filestorage$$.prototype.read = async function($sha256sum$jscomp$7$$, $offset$jscomp$52$$, $count$jscomp$49$$, $file_size$jscomp$2$$) {
|
|
4501
|
+
const $data$jscomp$148$$ = await this.storage.read($sha256sum$jscomp$7$$, $offset$jscomp$52$$, $count$jscomp$49$$, $file_size$jscomp$2$$);
|
|
4502
|
+
return $data$jscomp$148$$ ? $data$jscomp$148$$ : (await this.load_from_server($sha256sum$jscomp$7$$, $file_size$jscomp$2$$)).subarray($offset$jscomp$52$$, $offset$jscomp$52$$ + $count$jscomp$49$$);
|
|
4501
4503
|
};
|
|
4502
4504
|
$ServerFileStorageWrapper$$module$src$browser$filestorage$$.prototype.cache = async function($sha256sum$jscomp$8$$, $data$jscomp$149$$) {
|
|
4503
4505
|
return await this.storage.cache($sha256sum$jscomp$8$$, $data$jscomp$149$$);
|
|
@@ -5048,12 +5050,12 @@ $FS$$module$lib$filesystem$$.prototype.DeleteData = async function($idx$jscomp$7
|
|
|
5048
5050
|
$FS$$module$lib$filesystem$$.prototype.get_buffer = async function($idx$jscomp$8$$) {
|
|
5049
5051
|
const $inode$jscomp$15$$ = this.inodes[$idx$jscomp$8$$];
|
|
5050
5052
|
$dbg_assert$$module$src$log$$($inode$jscomp$15$$, `Filesystem get_buffer: idx ${$idx$jscomp$8$$} does not point to an inode`);
|
|
5051
|
-
return this.inodedata[$idx$jscomp$8$$] ? this.inodedata[$idx$jscomp$8$$] : 2 === $inode$jscomp$15$$.status ? ($dbg_assert$$module$src$log$$($inode$jscomp$15$$.sha256sum, "Filesystem get_data: found inode on server without sha256sum"), await this.storage.read($inode$jscomp$15$$.sha256sum, 0, $inode$jscomp$15$$.size)) : null;
|
|
5053
|
+
return this.inodedata[$idx$jscomp$8$$] ? this.inodedata[$idx$jscomp$8$$] : 2 === $inode$jscomp$15$$.status ? ($dbg_assert$$module$src$log$$($inode$jscomp$15$$.sha256sum, "Filesystem get_data: found inode on server without sha256sum"), await this.storage.read($inode$jscomp$15$$.sha256sum, 0, $inode$jscomp$15$$.size, $inode$jscomp$15$$.size)) : null;
|
|
5052
5054
|
};
|
|
5053
5055
|
$FS$$module$lib$filesystem$$.prototype.get_data = async function($idx$jscomp$9$$, $offset$jscomp$57$$, $count$jscomp$54$$) {
|
|
5054
5056
|
const $inode$jscomp$16$$ = this.inodes[$idx$jscomp$9$$];
|
|
5055
5057
|
$dbg_assert$$module$src$log$$($inode$jscomp$16$$, `Filesystem get_data: idx ${$idx$jscomp$9$$} does not point to an inode`);
|
|
5056
|
-
return this.inodedata[$idx$jscomp$9$$] ? this.inodedata[$idx$jscomp$9$$].subarray($offset$jscomp$57$$, $offset$jscomp$57$$ + $count$jscomp$54$$) : 2 === $inode$jscomp$16$$.status ? ($dbg_assert$$module$src$log$$($inode$jscomp$16$$.sha256sum, "Filesystem get_data: found inode on server without sha256sum"), await this.storage.read($inode$jscomp$16$$.sha256sum, $offset$jscomp$57$$, $count$jscomp$54
|
|
5058
|
+
return this.inodedata[$idx$jscomp$9$$] ? this.inodedata[$idx$jscomp$9$$].subarray($offset$jscomp$57$$, $offset$jscomp$57$$ + $count$jscomp$54$$) : 2 === $inode$jscomp$16$$.status ? ($dbg_assert$$module$src$log$$($inode$jscomp$16$$.sha256sum, "Filesystem get_data: found inode on server without sha256sum"), await this.storage.read($inode$jscomp$16$$.sha256sum, $offset$jscomp$57$$, $count$jscomp$54$$, $inode$jscomp$16$$.size)) : null;
|
|
5057
5059
|
};
|
|
5058
5060
|
$FS$$module$lib$filesystem$$.prototype.set_data = async function($idx$jscomp$10$$, $buffer$jscomp$41$$) {
|
|
5059
5061
|
this.inodedata[$idx$jscomp$10$$] = $buffer$jscomp$41$$;
|
|
@@ -5678,7 +5680,7 @@ $V86$$module$src$browser$starter$$.prototype.continue_init = async function($emu
|
|
|
5678
5680
|
$add_file_boot_order_fs_url_relay_url_screen_options$$ = $options$jscomp$42$$.filesystem.basefs;
|
|
5679
5681
|
var $base_url$$ = $options$jscomp$42$$.filesystem.baseurl;
|
|
5680
5682
|
let $file_storage$jscomp$1$$ = new $MemoryFileStorage$$module$src$browser$filestorage$$;
|
|
5681
|
-
$base_url$$ && ($file_storage$jscomp$1$$ = new $ServerFileStorageWrapper$$module$src$browser$filestorage$$($file_storage$jscomp$1$$, $base_url
|
|
5683
|
+
$base_url$$ && ($file_storage$jscomp$1$$ = new $ServerFileStorageWrapper$$module$src$browser$filestorage$$($file_storage$jscomp$1$$, $base_url$$, this.zstd_decompress.bind(this)));
|
|
5682
5684
|
$settings$$.fs9p = this.fs9p = new $FS$$module$lib$filesystem$$($file_storage$jscomp$1$$);
|
|
5683
5685
|
if ($add_file_boot_order_fs_url_relay_url_screen_options$$) {
|
|
5684
5686
|
$dbg_assert$$module$src$log$$($base_url$$, "Filesystem: baseurl must be specified");
|
package/build/libv86-debug.mjs
CHANGED
|
@@ -116,90 +116,90 @@ this.dma_bytes_block=1024*this.bytes_per_sample;this.dma_bytes_block=Math.min(Ma
|
|
|
116
116
|
b=this.dac_buffers[1].shift_block(this.dac_buffers[1].length);this.bus.send("dac-send-data",[a,b],[a.buffer,b.buffer])}};D.prototype.raise_irq=function(a){B("raise irq",8388608);this.irq_triggered[a]=1;this.cpu.device_raise_irq(this.irq)};D.prototype.lower_irq=function(a){B("lower irq",8388608);this.irq_triggered[a]=0;this.cpu.device_lower_irq(this.irq)};function Va(a,b,c){return(a<b)*b+(a>c)*c+(b<=a&&a<=c)*a}function eb(a){this.message=a}eb.prototype=Error();const fb={Uint8Array,Int8Array,Uint16Array,
|
|
117
117
|
Int16Array,Uint32Array,Int32Array,Float32Array,Float64Array};function gb(a,b){if("object"!==typeof a||null===a)return l("function"!==typeof a),a;if(Array.isArray(a))return a.map(f=>gb(f,b));a.constructor===Object&&(console.log(a),l(a.constructor!==Object,"Expected non-object"));if(a.BYTES_PER_ELEMENT){var c=new Uint8Array(a.buffer,a.byteOffset,a.length*a.BYTES_PER_ELEMENT);a=a.constructor.name.replace("bound ","");l(fb[a]);return{__state_type__:a,buffer_id:b.push(c)-1}}!a.get_state&&console.log("Object without get_state: ",
|
|
118
118
|
a);c=a.get_state();a=[];for(var d=0;d<c.length;d++){var e=c[d];l("function"!==typeof e);a[d]=gb(e,b)}return a}function hb(a,b){if("object"!==typeof a||null===a)return l("function"!==typeof a),a;if(Array.isArray(a)){for(var c=0;c<a.length;c++)a[c]=hb(a[c],b);return a}c=a.__state_type__;l(void 0!==c);const d=fb[c];l(d,"Unkown type: "+c);return new d(b[a.buffer_id])}function ib(a,b){function c(t,z){const A=t.length;if(16>A)throw new eb("Invalid length: "+A);t=new Int32Array(t.buffer,t.byteOffset,4);
|
|
119
|
-
if(-2039052682!==t[0])throw new eb("Invalid header: "+n(t[0]>>>0));if(6!==t[1])throw new eb("Version mismatch: dump="+t[1]+" we=6");if(z&&t[2]!==A)throw new eb("Length doesn't match header: real="+A+" header="+t[2]);return t[3]}function d(t){t=(new TextDecoder).decode(t);return JSON.parse(t)}b=new Uint8Array(b);if(4247762216===(new Uint32Array(b.buffer,0,1))[0]){var e=a.zstd_create_ctx(b.length);(new Uint8Array(a.wasm_memory.buffer,a.zstd_get_src_ptr(e),b.length)).set(b);var f=a.zstd_read(e,16),
|
|
120
|
-
new Uint8Array(a.wasm_memory.buffer,f,16),k=c(g,!1);a.zstd_read_free(f,16);f=a.zstd_read(e,k);g=new Uint8Array(a.wasm_memory.buffer,f,k);g=d(g);a.zstd_read_free(f,k);f=g.state;var m=g.buffer_infos;g=[];k=16+k;for(var p of m){m=(k+3&-4)-k;if(1048576<p.length){var q=a.zstd_read(e,m);a.zstd_read_free(q,m);q=new Uint8Array(p.length);g.push(q.buffer);for(var r=0;r<p.length;){var v=p.length-r;l(0<=v);v=Math.min(v,1048576);const t=a.zstd_read(e,v);q.set(new Uint8Array(a.wasm_memory.buffer,
|
|
121
|
-
v);r+=v}}else q=a.zstd_read(e,m+p.length),r=q+m,g.push(a.wasm_memory.buffer.slice(r,r+p.length)),a.zstd_read_free(q,m+p.length);k+=m+p.length}f=hb(f,g);a.set_state(f);a.zstd_free_ctx(e)}else{e=c(b,!0);if(0>e||e+12>=b.length)throw new eb("Invalid info block length: "+e);p=b.subarray(16,16+e);f=d(p);p=f.state;f=f.buffer_infos;let t=16+e;t=t+3&-4;e=f.map(z=>{const A=t+z.offset;return b.buffer.slice(A,A+z.length)});p=hb(p,e);a.set_state(p)}}function jb(a,b,c,d,e){let f=
|
|
122
|
-
d?"unguarded register":e?"wasm size":"executed";for(let q=0;256>q;q++)for(let r=0;8>r;r++)for(const v of[!1,!0]){var m=a.wm.exports.get_opstats_buffer(b,c,d,e,q,!1,v,r);g.push({opcode:q,count:m,is_mem:v,fixed_g:r});m=a.wm.exports.get_opstats_buffer(b,c,d,e,q,!0,v,r);g.push({opcode:3840|q,count:m,is_mem:v,fixed_g:r})}a=0;b=new Set([38,46,54,62,100,101,102,103,240,242,243]);for(const {count:q,opcode:r}of g)b.has(r)||(a+=q);if(0===a)return"";c=new Uint32Array(256);
|
|
123
|
-
count:r}of g)3840===(q&65280)?b[q&255]+=r:c[q&255]+=r;f=f+"------------------\nTotal: "+(a+"\n");const p=1E7<a?1E3:1;d=Math.max.apply(Math,g.map(({count:q})=>Math.round(q/p)));d=String(d).length;f+=`Instruction counts ${k} (in ${p}):\n`;for(e=0;256>e;e++)f+=e.toString(16).padStart(2,"0")+":"+ca(Math.round(c[e]/p),d),f=15===e%16?f+"\n":f+" ";f=f+"\n"+`Instruction counts ${k} (0f, in ${p}):\n`;for(k=0;256>k;k++)f+=(k&255).toString(16).padStart(2,"0")+":"+ca(Math.round(b[k]/
|
|
124
|
-
f+" ";f+="\n";g=g.filter(({count:q})=>q).sort(({count:q},{count:r})=>r-q);for(const {opcode:q,is_mem:r,fixed_g:v,count:t}of g.slice(0,200))g=q.toString(16)+"_"+v+(r?"_m":"_r"),f+=g+":"+(t/a*100).toFixed(2)+" ";return f+"\n"}function kb(a){this.cpu=a;this.cmos_index=0;this.cmos_data=new Uint8Array(128);this.last_update=this.rtc_time=Date.now();this.next_interrupt_alarm=this.next_interrupt=0;this.periodic_interrupt=!1;this.periodic_interrupt_time=.9765625;this.cmos_a=38;this.cmos_b=
|
|
125
|
-
this.cmos_diag_status=this.cmos_c=0;this.update_interrupt=!1;this.update_interrupt_time=0;a.io.register_write(112,this,function(b){this.cmos_index=b&127;this.nmi_disabled=b>>7});a.io.register_write(113,this,this.cmos_port_write);a.io.register_read(113,this,this.cmos_port_read)}kb.prototype.get_state=function(){var a=[];a[0]=this.cmos_index;a[1]=this.cmos_data;a[2]=this.rtc_time;a[3]=this.last_update;a[4]=this.next_interrupt;a[5]=this.next_interrupt_alarm;a[6]=this.periodic_interrupt;
|
|
126
|
-
a[8]=this.cmos_a;a[9]=this.cmos_b;a[10]=this.cmos_c;a[11]=this.nmi_disabled;a[12]=this.update_interrupt;a[13]=this.update_interrupt_time;a[14]=this.cmos_diag_status;return a};kb.prototype.set_state=function(a){this.cmos_index=a[0];this.cmos_data=a[1];this.rtc_time=a[2];this.last_update=a[3];this.next_interrupt=a[4];this.next_interrupt_alarm=a[5];this.periodic_interrupt=a[6];this.periodic_interrupt_time=a[7];this.cmos_a=a[8];this.cmos_b=a[9];this.cmos_c=a[10];this.nmi_disabled=
|
|
127
|
-
a[12]||!1;this.update_interrupt_time=a[13]||0;this.cmos_diag_status=a[14]||0};kb.prototype.timer=function(a){a=Date.now();this.rtc_time+=a-this.last_update;this.last_update=a;this.periodic_interrupt&&this.next_interrupt<a?(this.cpu.device_raise_irq(8),this.cmos_c|=192,this.next_interrupt+=this.periodic_interrupt_time*Math.ceil((a-this.next_interrupt)/this.periodic_interrupt_time)):this.next_interrupt_alarm&&this.next_interrupt_alarm<a?(this.cpu.device_raise_irq(8),this.cmos_c|=
|
|
128
|
-
0):this.update_interrupt&&this.update_interrupt_time<a&&(this.cpu.device_raise_irq(8),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};kb.prototype.bcd_pack=function(a){for(var b=0,c=0,d;a;)d=
|
|
129
|
-
return c};kb.prototype.bcd_unpack=function(a){const b=a&15,c=a>>4&15;l(256>a);l(10>b);l(10>c);return b+10*c};kb.prototype.encode_time=function(a){return this.cmos_b&4?a:this.bcd_pack(a)};kb.prototype.decode_time=function(a){return this.cmos_b&4?a:this.bcd_unpack(a)};kb.prototype.cmos_port_read=function(){var a=this.cmos_index;switch(a){case 0:return B("read second: "+n(this.encode_time((new Date(this.rtc_time)).getUTCSeconds())),65536),this.encode_time((new Date(this.rtc_time)).getUTCSeconds());
|
|
130
|
-
n(this.encode_time((new Date(this.rtc_time)).getUTCMinutes())),65536),this.encode_time((new Date(this.rtc_time)).getUTCMinutes());case 4:return B("read hour: "+n(this.encode_time((new Date(this.rtc_time)).getUTCHours())),65536),this.encode_time((new Date(this.rtc_time)).getUTCHours());case 6:return B("read day: "+n(this.encode_time((new Date(this.rtc_time)).getUTCDay()+1)),65536),this.encode_time((new Date(this.rtc_time)).getUTCDay()+1);case 7:return B("read day of month: "+
|
|
131
|
-
65536),this.encode_time((new Date(this.rtc_time)).getUTCDate());case 8:return B("read month: "+n(this.encode_time((new Date(this.rtc_time)).getUTCMonth()+1)),65536),this.encode_time((new Date(this.rtc_time)).getUTCMonth()+1);case 9:return B("read year: "+n(this.encode_time((new Date(this.rtc_time)).getUTCFullYear()%100)),65536),this.encode_time((new Date(this.rtc_time)).getUTCFullYear()%100);case 10:return 999<=H.microtick()%1E3?this.cmos_a|
|
|
132
|
-
B("cmos reg C read",65536),a=this.cmos_c,this.cmos_c&=-241,a;case 13:return 128;case 14:return B("cmos diagnostic status read",65536),this.cmos_diag_status;case 50:case 55:return B("read century: "+n(this.encode_time((new Date(this.rtc_time)).getUTCFullYear()/100|0)),65536),this.encode_time((new Date(this.rtc_time)).getUTCFullYear()/100|0);default:return B("cmos read from index "+n(a),65536),this.cmos_data[this.cmos_index]}};
|
|
133
|
-
a&127;this.periodic_interrupt_time=1E3/(32768>>(this.cmos_a&15)-1);B("Periodic interrupt, a="+n(this.cmos_a,2)+" t="+this.periodic_interrupt_time,65536);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]),
|
|
134
|
-
e+" hh:mm:ss="+d+":"+c+":"+b+" ms_from_now="+(e-a),65536);this.next_interrupt_alarm=+e}this.cmos_b&16&&(B("update interrupt",65536),this.update_interrupt_time=Date.now());B("cmos b="+n(this.cmos_b,2),65536);break;case 14:this.cmos_diag_status=a;break;case 1:case 3:case 5:this.cmos_write(this.cmos_index,a);break;default:B("cmos write index "+n(this.cmos_index)+": "+n(a),65536)}this.update_interrupt=
|
|
135
|
-
15)};kb.prototype.cmos_read=function(a){l(128>a);return this.cmos_data[a]};kb.prototype.cmos_write=function(a,b){B("cmos "+n(a)+" <- "+n(b),65536);l(128>a);this.cmos_data[a]=b};function lb(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=
|
|
136
|
-
new Uint16Array(3);this.counter_reload=new Uint16Array(3);a.io.register_read(97,this,function(){var c=H.microtick(),d=66.66666666666667*c&1;c=this.did_rollover(2,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,
|
|
137
|
-
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,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)}lb.prototype.get_state=function(){var a=[];a[0]=this.counter_next_low;
|
|
138
|
-
this.counter_latch_value;a[6]=this.counter_reload;a[7]=this.counter_start_time;a[8]=this.counter_start_value;return a};lb.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]};
|
|
139
|
-
this.get_counter_value(0,a),this.counter_start_time[0]=a,B("pit interrupt. new value: "+this.counter_start_value[0],512),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])))/
|
|
140
|
-
d=Math.floor(1193.1816666*c);b=this.counter_start_value[a]-d;B("diff="+c+" dticks="+d+" value="+b+" reload="+this.counter_reload[a],512);c=this.counter_reload[a];b>=c?(B("Warning: Counter"+a+" value "+b+" is larger than reload "+c,512),b%=c):0>b&&(b=b%c+c);return b};lb.prototype.did_rollover=function(a,b){b-=this.counter_start_time[a];return 0>b?(B("Warning: PIT timer difference is negative, resetting (timer "+
|
|
141
|
-
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,H.microtick());return b?a&255:a>>8};lb.prototype.counter_write=function(a,b){this.counter_reload[a]=this.counter_next_low[a]?this.counter_reload[a]&-256|
|
|
142
|
-
(this.counter_reload[a]=65535),this.counter_start_value[a]=this.counter_reload[a],this.counter_enabled[a]=!0,this.counter_start_time[a]=H.microtick(),B("counter"+a+" reload="+n(this.counter_reload[a])+" tick="+(this.counter_reload[a]||65536)/1193.1816666+"ms",512));3===this.counter_read_mode[a]&&(this.counter_next_low[a]^=1)};lb.prototype.port43_write=function(a){var b=a>>1&7,c=a&1,
|
|
143
|
-
2,b=this.get_counter_value(d,H.microtick()),B("latch: "+b,512),this.counter_latch_value[d]=b?b-1:0):(6<=b&&(b&=-5),B("Control: mode="+b+" ctr="+d+" read_mode="+a+" bcd="+c,512),this.counter_next_low[d]=1===a?1:2===a?0:1,0===d&&this.cpu.device_lower_irq(0),0!==b&&3!==b&&2!==b&&B("Unimplemented counter mode: "+n(b),512),this.counter_mode[d]=b,this.counter_read_mode[d]=a,2===d&&
|
|
144
|
-
B("counter0 ticks every "+(a||65536)/1193.1816666+"ms (reload="+a+")")};function mb(a){if("undefined"!==typeof window)if(window.AudioContext||window.webkitAudioContext){var b=window.AudioWorklet?nb:ob;this.bus=a;this.audio_context=window.AudioContext?new AudioContext:new webkitAudioContext;this.mixer=new pb(a,this.audio_context);this.pcspeaker=new qb(a,this.audio_context,
|
|
145
|
-
this);a.register("emulator-started",function(){this.audio_context.resume()},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")}mb.prototype.destroy=function(){this.audio_context&&this.audio_context.close();
|
|
146
|
-
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";
|
|
147
|
-
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,
|
|
148
|
-
this.input_left=this.node_treble_left;this.input_right=this.node_treble_right;this.node_treble_left.connect(this.node_bass_left);this.node_bass_left.connect(this.node_gain_left);this.node_gain_left.connect(this.node_merger,0,0);this.node_treble_right.connect(this.node_bass_right);this.node_bass_right.connect(this.node_gain_right);
|
|
149
|
-
d[1])},this);a.register("mixer-disconnect",function(d){this.disconnect_source(d[0],d[1])},this);a.register("mixer-volume",function(d){var e=d[0],f=d[1];d=Math.pow(10,d[2]/20);var g=0===e?this:this.sources.get(e);void 0===g?l(!1,"Mixer set volume - cannot set volume for undefined source: "+e):g.set_volume(d,f)},this);a.register("mixer-gain-left",
|
|
150
|
-
this);a.register("mixer-treble-left",c(this.node_treble_left),this);a.register("mixer-treble-right",c(this.node_treble_right),this);a.register("mixer-bass-left",c(this.node_bass_left),this);a.register("mixer-bass-right",c(this.node_bass_right),this)}pb.prototype.add_source=function(a,b){a=new rb(this.audio_context,a,this.input_left,this.input_right);
|
|
151
|
-
this.sources.get(a);void 0===c?l(!1,"Mixer connect - cannot connect undefined source: "+a):c.connect(b)};pb.prototype.disconnect_source=function(a,b){var c=this.sources.get(a);void 0===c?l(!1,"Mixer disconnect - cannot disconnect undefined source: "+a):c.disconnect(b)};pb.prototype.set_volume=function(a,b){void 0===b&&(b=2);switch(b){case 0:this.volume_left=
|
|
152
|
-
pb.prototype.update=function(){var a=this.volume_both*this.volume_right*this.gain_right;this.node_gain_left.gain.setValueAtTime(this.volume_both*this.volume_left*this.gain_left,this.audio_context.currentTime);this.node_gain_right.gain.setValueAtTime(a,this.audio_context.currentTime)};function rb(a,b,c,d){this.audio_context=a;this.connected_right=
|
|
153
|
-
a.createGain();this.node_gain_right=a.createGain();b.connect(this.node_splitter);this.node_splitter.connect(this.node_gain_left,0);this.node_gain_left.connect(c);this.node_splitter.connect(this.node_gain_right,1);this.node_gain_right.connect(d)}rb.prototype.update=function(){var a=this.connected_right*this.gain_hidden*this.volume_both*this.volume_right;
|
|
154
|
-
this.audio_context.currentTime)};rb.prototype.connect=function(a){var b=!a||2===a;if(b||0===a)this.connected_left=!0;if(b||1===a)this.connected_right=!0;this.update()};rb.prototype.disconnect=function(a){var b=!a||2===a;if(b||0===a)this.connected_left=!1;if(b||1===a)this.connected_right=!1;this.update()};rb.prototype.set_volume=
|
|
155
|
-
b);return}this.update()};rb.prototype.set_gain_hidden=function(a){this.gain_hidden=a};function qb(a,b,c){this.node_oscillator=b.createOscillator();this.node_oscillator.type="square";this.node_oscillator.frequency.setValueAtTime(440,b.currentTime);this.mixer_connection=c.add_source(this.node_oscillator,1);this.mixer_connection.disconnect();
|
|
156
|
-
function(d){var e=d[1],f=0;3===d[0]&&(f=Math.min(1193181.6665999999/e,this.node_oscillator.frequency.maxValue),f=Math.max(f,0));this.node_oscillator.frequency.setValueAtTime(f,b.currentTime)},this)}qb.prototype.start=function(){this.node_oscillator.start()};function nb(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=
|
|
157
|
-
3;p.queue_data=Array(1024);p.queue_start=0;p.queue_end=0;p.queue_length=0;p.queue_size=p.queue_data.length;p.queued_samples=0;p.source_buffer_previous=m;p.source_buffer_current=m;p.source_samples_per_destination=1;p.source_block_start=0;p.source_time=0;p.source_offset=0;p.port.onmessage=q=>{switch(q.data.type){case "queue":p.queue_push(q.data.value);
|
|
158
|
-
AudioWorkletProcessor.prototype);Reflect.setPrototypeOf(k,AudioWorkletProcessor);k.prototype.process=k.prototype.process=function(p,q){for(p=0;p<q[0][0].length;p++){for(var r=0,v=0,t=this.source_offset+this.kernel_size,z=this.source_offset-this.kernel_size+1;z<=t;z++){var A=this.source_block_start+z;r+=this.get_sample(A,
|
|
159
|
-
r;q[0][1][p]=v;this.source_time+=this.source_samples_per_destination;this.source_offset=Math.floor(this.source_time)}q=this.source_offset;q+=this.kernel_size+2;this.source_time-=this.source_offset;this.source_block_start+=this.source_offset;this.source_offset=0;this.ensure_enough_data(q);return!0};k.prototype.kernel=
|
|
160
|
-
k.prototype.ensure_enough_data=function(p){var q=this.source_buffer_current[0].length;q-this.source_block_start<p&&(this.prepare_next_buffer(),this.source_block_start-=q)};k.prototype.prepare_next_buffer=function(){256>this.queued_samples&&this.queue_length&&this.dbg_log("Not enough samples - should not happen during midway of playback");
|
|
161
|
-
this.queue_start,r=0;256>p&&r<this.queue_length;)p+=this.queue_data[q][0].length,q=q+1&this.queue_size-1,r++;p=Math.max(p,256);p=[new Float32Array(p),new Float32Array(p)];p[0].set(this.source_buffer_current[0]);p[1].set(this.source_buffer_current[1]);q=this.source_buffer_current[0].length;for(var v=0;v<r;v++){var t=this.queue_shift();p[0].set(t[0],
|
|
162
|
-
this.port.postMessage({type:"pump"})};k.prototype.queue_push=function(p){this.queue_length<this.queue_size&&(this.queue_data[this.queue_end]=p,this.queue_end=this.queue_end+1&this.queue_size-1,this.queue_length++,this.queued_samples+=p[0].length,this.pump())};k.prototype.queue_shift=function(){if(!this.queue_length)return m;var p=this.queue_data[this.queue_start];
|
|
163
|
-
return p};k.prototype.dbg_log=function(p){this.port.postMessage({type:"debug-log",value:p})};registerProcessor("dac-processor",k)}.toString();var d=b.indexOf("{")+1,e=b.lastIndexOf("}");b=b.substring(d,e);b=new Blob(["var DEBUG = true;\n"+b],{type:"application/javascript"});var f=URL.createObjectURL(b);this.node_processor=null;this.node_output=this.audio_context.createGain();
|
|
164
|
-
"dac-processor",{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[2],parameterData:{},processorOptions:{}});this.node_processor.port.postMessage({type:"sampling-rate",value:this.sampling_rate});this.node_processor.port.onmessage=g=>{switch(g.data.type){case "pump":this.pump();break;case "debug-log":B("SpeakerWorkletDAC - Worklet: "+g.data.value)}};this.node_processor.connect(this.node_output)});
|
|
165
|
-
function(g){this.queue(g)},this);a.register("dac-enable",function(){this.enabled=!0},this);a.register("dac-disable",function(){this.enabled=!1},this);a.register("dac-tell-sampling-rate",function(g){l(0<g,"Sampling rate should be nonzero");this.sampling_rate=g;this.node_processor&&this.node_processor.port.postMessage({type:"sampling-rate",value:g})},this);this.debugger=new wb(this.audio_context,
|
|
166
|
-
this.node_processor.port.postMessage({type:"queue",value:a},[a[0].buffer,a[1].buffer]))};nb.prototype.pump=function(){this.enabled&&this.bus.send("dac-request-data")};function ob(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=22050;this.buffered_time=0;this.rate_ratio=1;this.node_lowpass=this.audio_context.createBiquadFilter();this.node_lowpass.type="lowpass";this.node_output=
|
|
167
|
-
a.register("dac-send-data",function(d){this.queue(d)},this);a.register("dac-enable",function(){this.enabled=!0;this.pump()},this);a.register("dac-disable",function(){this.enabled=!1},this);a.register("dac-tell-sampling-rate",function(d){l(0<d,"Sampling rate should be nonzero");this.sampling_rate=d;this.rate_ratio=Math.ceil(8E3/d);this.node_lowpass.frequency.setValueAtTime(d/2,this.audio_context.currentTime)},
|
|
168
|
-
var b=a[0].length,c=b/this.sampling_rate;if(1<this.rate_ratio){var d=this.audio_context.createBuffer(2,b*this.rate_ratio,this.sampling_rate*this.rate_ratio);for(var e=d.getChannelData(0),f=d.getChannelData(1),g=0,k=0;k<b;k++)for(var m=0;m<this.rate_ratio;m++,g++)e[g]=a[0][k],f[g]=a[1][k]}else d=this.audio_context.createBuffer(2,b,this.sampling_rate),d.copyToChannel?(d.copyToChannel(a[0],
|
|
169
|
-
a.buffer=d;a.connect(this.node_lowpass);a.addEventListener("ended",this.pump.bind(this));d=this.audio_context.currentTime;if(this.buffered_time<d)for(B("Speaker DAC - Creating/Recreating reserve - shouldn't occur frequently during playback"),this.buffered_time=d,d=.2-c,b=0;b<=d;)b+=c,this.buffered_time+=c,setTimeout(()=>this.pump(),1E3*b);a.start(this.buffered_time);
|
|
170
|
-
this.bus.send("dac-request-data"))};function wb(a,b){this.audio_context=a;this.node_source=b;this.node_processor=null;this.node_gain=this.audio_context.createGain();this.node_gain.gain.setValueAtTime(0,this.audio_context.currentTime);this.node_gain.connect(this.audio_context.destination);this.is_active=!1;this.queued_history=[];this.output_history=
|
|
171
|
-
this.output_history.push(this.output);this.node_processor=this.audio_context.createScriptProcessor(1024,2,2);this.node_processor.onaudioprocess=b=>{this.output[0].push(b.inputBuffer.getChannelData(0).slice());this.output[1].push(b.inputBuffer.getChannelData(1).slice())};this.node_source.connect(this.node_processor);this.node_processor.connect(this.node_gain);
|
|
172
|
-
this.node_processor=null};wb.prototype.push_queued_data=function(a){this.is_active&&(this.queued[0].push(a[0].slice()),this.queued[1].push(a[1].slice()))};wb.prototype.download_txt=function(a,b){a=this.output_history[a][b].map(c=>c.join(" ")).join(" ");qa(a,"dacdata.txt")};wb.prototype.download_csv=function(a){a=this.output_history[a];for(var b=
|
|
173
|
-
b;this.socket=void 0;this.id=c||0;this.send_queue=[];this.url=a;this.reconnect_interval=1E4;this.last_connect_attempt=Date.now()-this.reconnect_interval;this.send_queue_limit=64;this.destroyed=!1;this.bus.register("net"+this.id+"-send",function(d){this.send(d)},this)}xb.prototype.handle_message=function(a){this.bus&&this.bus.send("net"+this.id+
|
|
174
|
-
xb.prototype.handle_open=function(){for(var a=0;a<this.send_queue.length;a++)this.send(this.send_queue[a]);this.send_queue=[]};xb.prototype.handle_error=function(){};xb.prototype.destroy=function(){this.destroyed=!0;this.socket&&this.socket.close()};xb.prototype.connect=function(){if("undefined"!==typeof WebSocket){if(this.socket){var a=
|
|
175
|
-
new WebSocket(this.url)}catch(b){console.error(b);return}this.socket.binaryType="arraybuffer";this.socket.onopen=this.handle_open.bind(this);this.socket.onmessage=this.handle_message.bind(this);this.socket.onclose=this.handle_close.bind(this);this.socket.onerror=this.handle_error.bind(this)}}};xb.prototype.send=function(a){this.socket&&
|
|
176
|
-
this.connect())};xb.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 yb=(new Date("1970-01-01T00:00:00Z")).getTime(),zb=(new Date("1900-01-01T00:00:00Z")).getTime(),Ab=yb-zb,Bb=Math.pow(2,32),Cb=
|
|
177
|
-
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(l(0<d);d<c;)d*=2;if(this.maximum_capacity&&d>this.maximum_capacity)throw Error("stream capacity overflow in GrowableRingbuffer.write(), package dropped");
|
|
178
|
-
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);
|
|
179
|
-
4),e=d.buffer,f=d.byteOffset;return{eth_frame:d,eth_frame_view:new DataView(e),eth_payload_view:new DataView(e,f+14,a),ipv4_payload_view:new DataView(e,f+34,b),udp_payload_view:new DataView(e,f+42,c),text_encoder:new TextEncoder}}function Hb(a,b,c,d){d.eth_frame.set(b,c.byteOffset+a);return b.length}function Ib(a,b,c,d){const e=c.byteOffset+(a&-2);d=d.eth_frame;for(c=
|
|
180
|
-
a.eth_frame.fill(0);var c=a.eth_frame,d=c.subarray,e=a.eth_frame_view;Hb(0,b.eth.dest,e,a);Hb(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);Hb(8,b.arp.sha,f,a);Hb(14,b.arp.spa,f,a);Hb(18,
|
|
181
|
-
b.icmp.type);k.setUint8(1,b.icmp.code);k.setUint16(2,0);var m=4+Hb(4,b.icmp.data,k,a);k.setUint16(2,Ib(m,0,k,a));g+=m}else if(b.udp){k=a.ipv4_payload_view;var p=8;if(b.dhcp){m=p;var q=a.udp_payload_view;q.setUint8(0,b.dhcp.op);q.setUint8(1,b.dhcp.htype);q.setUint8(2,b.dhcp.hlen);q.setUint8(3,b.dhcp.hops);q.setUint32(4,b.dhcp.xid);q.setUint16(8,b.dhcp.secs);q.setUint16(10,
|
|
182
|
-
Hb(28,b.dhcp.chaddr,q,a);q.setUint32(236,1669485411);p=240;for(var r of b.dhcp.options)p+=Hb(p,r,q,a);m+=p}else if(b.dns){r=p;p=a.udp_payload_view;p.setUint16(0,b.dns.id);p.setUint16(2,b.dns.flags);p.setUint16(4,b.dns.questions.length);p.setUint16(6,b.dns.answers.length);let z=12;for(var v=0;v<b.dns.questions.length;++v){var t=b.dns.questions[v];for(q of t.name){const A=
|
|
183
|
-
p.setUint16(z,t.class);z+=2}for(v=0;v<b.dns.answers.length;++v){q=b.dns.answers[v];for(m of q.name)t=a.text_encoder.encodeInto(m,a.eth_frame.subarray(p.byteOffset+(z+1))).written,p.setUint8(z,t),z+=1+t;p.setUint16(z,q.type);z+=2;p.setUint16(z,q.class);z+=2;p.setUint32(z,q.ttl);z+=4;p.setUint16(z,q.data.length);z+=2;z+=Hb(z,q.data,p,a)}m=r+z}else b.ntp?(m=p,q=a.udp_payload_view,
|
|
184
|
-
b.ntp.root_delay),q.setUint32(8,b.ntp.root_disp),q.setUint32(12,b.ntp.ref_id),q.setUint32(16,b.ntp.ref_ts_i),q.setUint32(20,b.ntp.ref_ts_f),q.setUint32(24,b.ntp.ori_ts_i),q.setUint32(28,b.ntp.ori_ts_f),q.setUint32(32,b.ntp.rec_ts_i),q.setUint32(36,b.ntp.rec_ts_f),q.setUint32(40,b.ntp.trans_ts_i),q.setUint32(44,b.ntp.trans_ts_f),m+=48):m=p+Hb(0,b.udp.data,a.udp_payload_view,a);
|
|
185
|
-
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+p,k,a));g+=p}else b.tcp&&(k=a.ipv4_payload_view,m=0,q=b.tcp,q.fin&&(m|=1),q.syn&&(m|=2),q.rst&&(m|=4),q.psh&&(m|=8),q.ack&&(m|=16),q.urg&&(m|=32),q.ece&&(m|=64),q.cwr&&(m|=128),r=20,q.options&&q.options.mss&&(k.setUint8(r,2),k.setUint8(r+1,4),k.setUint16(r+
|
|
186
|
-
q.sport),k.setUint16(2,q.dport),k.setUint32(4,q.seq),k.setUint32(8,q.ackn),k.setUint8(12,p>>2<<4),k.setUint8(13,m),k.setUint16(14,q.winsize),k.setUint16(16,0),k.setUint16(18,q.urgent||0),b.tcp_data&&(p+=Hb(20,b.tcp_data,k,a)),k.setUint16(16,Ib(p,(b.ipv4.src[0]<<8|b.ipv4.src[1])+(b.ipv4.src[2]<<8|b.ipv4.src[3])+(b.ipv4.dest[0]<<8|b.ipv4.dest[1])+(b.ipv4.dest[2]<<8|b.ipv4.dest[3])+
|
|
187
|
-
64);f.setUint8(8,b.ipv4.ttl||32);f.setUint8(9,b.ipv4.proto);f.setUint16(10,0);Hb(12,b.ipv4.src,f,a);Hb(16,b.ipv4.dest,f,a);f.setUint16(10,Ib(20,0,f,a));e+=g}return d.call(c,0,e)}function Tb(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,
|
|
188
|
-
b.receive(Jb(b.eth_encoder_buf,c))});return!0}function Ub(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:Eb(b.vm_ip),siaddr:Eb(b.router_ip),giaddr:Eb(b.router_ip),chaddr:a.dhcp.chaddr};
|
|
189
|
-
2])));3===a.dhcp.op&&(c.dhcp.op=2,d.push(new Uint8Array([53,1,5])),d.push(new Uint8Array([51,4,8,0,0,0])));a=[b.router_ip[0],b.router_ip[1],b.router_ip[2],b.router_ip[3]];d.push(new Uint8Array([1,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,
|
|
190
|
-
{};var d=(new DataView(a.buffer,a.byteOffset,a.byteLength)).getUint16(12),e={ethertype:d,dest:a.subarray(0,6),dest_s:Db(a.subarray(0,6)),src:a.subarray(6,12),src_s:Db(a.subarray(6,12))};c.eth=e;a=a.subarray(14,a.length);if(2048===d){var f=new DataView(a.buffer,a.byteOffset,a.byteLength),g=a[0]>>4&15;e=a[0]&15;var k=f.getUint8(1),m=f.getUint16(2);let p=f.getUint8(8);d=f.getUint8(9);
|
|
191
|
-
20)};Math.max(m,46)!==a.length&&B(`ipv4 Length mismatch: ${m} != ${a.length}`,16777216);c.ipv4=g;e=a.subarray(4*e,m);if(1===d)a=new DataView(e.buffer,e.byteOffset,e.byteLength),a={type:a.getUint8(0),code:a.getUint8(1),checksum:a.getUint16(2),data:e.subarray(4)},c.icmp=a;else if(6===d)d=new DataView(e.buffer,e.byteOffset,e.byteLength),a={sport:d.getUint16(0),dport:d.getUint16(2),seq:d.getUint32(4),
|
|
192
|
-
d=d.getUint8(13),a.fin=!!(d&1),a.syn=!!(d&2),a.rst=!!(d&4),a.psh=!!(d&8),a.ack=!!(d&16),a.urg=!!(d&32),a.ece=!!(d&64),a.cwr=!!(d&128),c.tcp=a,c.tcp_data=e.subarray(4*a.doff);else if(17===d){a=new DataView(e.buffer,e.byteOffset,e.byteLength);a={sport:a.getUint16(0),dport:a.getUint16(2),len:a.getUint16(4),checksum:a.getUint16(6),data:e.subarray(8),data_s:(new TextDecoder).decode(e.subarray(8))};
|
|
193
|
-
236);d={op:d.getUint8(0),htype:d.getUint8(1),hlen:d.getUint8(2),hops:d.getUint8(3),xid:d.getUint32(4),secs:d.getUint16(8),flags:d.getUint16(10),ciaddr:d.getUint32(12),yiaddr:d.getUint32(16),siaddr:d.getUint32(20),giaddr:d.getUint32(24),chaddr:e.subarray(28,44),magic:d.getUint32(236),options:[]};e=e.subarray(240);for(m=0;m<e.length;++m)g=m,0!==e[m]&&(++m,k=e[m],m+=k,d.options.push(e.subarray(g,
|
|
194
|
-
(d=e.subarray(8),d=new DataView(d.buffer,d.byteOffset,d.byteLength),c.ntp={flags:d.getUint8(0),stratum:d.getUint8(1),poll:d.getUint8(2),precision:d.getUint8(3),root_delay:d.getUint32(4),root_disp:d.getUint32(8),ref_id:d.getUint32(12),ref_ts_i:d.getUint32(16),ref_ts_f:d.getUint32(20),ori_ts_i:d.getUint32(24),ori_ts_f:d.getUint32(28),rec_ts_i:d.getUint32(32),rec_ts_f:d.getUint32(36),trans_ts_i:d.getUint32(40),
|
|
195
|
-
a.byteLength),a={htype:d.getUint16(0),ptype:d.getUint16(2),oper:d.getUint16(6),sha:a.subarray(8,14),spa:a.subarray(14,18),tha:a.subarray(18,24),tpa:a.subarray(24,28)},c.arp=a):34525===d?B("Unimplemented: ipv6"):B("Unknown ethertype: "+n(d),16777216);if(c.ipv4)if(c.tcp)a:{a=`${c.ipv4.src.join(".")}:${c.tcp.sport}:${c.ipv4.dest.join(".")}:${c.tcp.dport}`;if(c.tcp.syn&&(b.tcp_conn[a]&&B("SYN to already opened port",
|
|
196
|
-
else{B(`I dont know about ${a}, so resetting`,16777216);a=c.tcp.ackn;if(c.tcp.fin||c.tcp.syn)a+=1;d={};d.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src};d.ipv4={proto:6,src:c.ipv4.dest,dest:c.ipv4.src};d.tcp={sport:c.tcp.dport,dport:c.tcp.sport,seq:a,ackn:c.tcp.seq+(c.tcp.syn?1:0),winsize:c.tcp.winsize,rst:!0,ack:c.tcp.syn};b.receive(Jb(b.eth_encoder_buf,d))}}else if(c.udp)if(c.dns)if("static"===b.dns_method){a=
|
|
197
|
-
dest:c.ipv4.src};a.udp={sport:53,dport:c.udp.sport};d=[];for(e=0;e<c.dns.questions.length;++e)switch(m=c.dns.questions[e],m.type){case 1:d.push({name:m.name,type:m.type,class:m.class,ttl:600,data:[192,168,87,1]})}a.dns={id:c.dns.id,flags:33152,questions:c.dns.questions,answers:d};b.receive(Jb(b.eth_encoder_buf,a))}else Tb(c,b);else c.dhcp?Ub(c,b):c.ntp?(a=Date.now()+Ab,d=a%1E3/1E3*Bb,e={},e.eth={ethertype:2048,
|
|
198
|
-
{sport:123,dport:c.udp.sport},e.ntp=Object.assign({},c.ntp),e.ntp.flags=36,e.ntp.poll=10,e.ntp.ori_ts_i=c.ntp.trans_ts_i,e.ntp.ori_ts_f=c.ntp.trans_ts_f,e.ntp.rec_ts_i=a/1E3,e.ntp.rec_ts_f=d,e.ntp.trans_ts_i=a/1E3,e.ntp.trans_ts_f=d,e.ntp.stratum=2,b.receive(Jb(b.eth_encoder_buf,e))):8===c.udp.dport&&(a={},a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},a.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},
|
|
199
|
-
b.receive(Jb(b.eth_encoder_buf,a)));else c.icmp&&8===c.icmp.type&&(a={},a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},a.ipv4={proto:1,src:c.ipv4.dest,dest:c.ipv4.src},a.icmp={type:0,code:c.icmp.code,data:c.icmp.data},b.receive(Jb(b.eth_encoder_buf,a)));else c.arp&&1===c.arp.oper&&2048===c.arp.ptype&&(a=Eb(c.arp.tpa)&4294967040,d=Eb(b.router_ip)&4294967040,!b.masquerade&&a!==d||a===d&&99<c.arp.tpa[3]||
|
|
200
|
-
sha:b.router_mac,spa:c.arp.tpa,tha:c.eth.src,tpa:c.arp.spa},b.receive(Jb(b.eth_encoder_buf,a))))}function Wb(a,b){function c(){let p=[],q;do q=d.getUint8(k),p.push((new TextDecoder).decode(a.subarray(k+1,k+1+q))),k+=q+1;while(0<q);return p}let d=new DataView(a.buffer,a.byteOffset,a.byteLength),e={id:d.getUint16(0),flags:d.getUint16(2),questions:[],answers:[]};var f=d.getUint16(4);let g=d.getUint16(6);d.getUint16(8);
|
|
201
|
-
class:d.getInt16(k+2)}),k+=4;for(f=0;f<g;f++){m={name:c(),type:d.getInt16(k),class:d.getUint16(k+2),ttl:d.getUint32(k+4)};k+=8;let p=d.getUint16(k);k+=2;m.data=a.subarray(k,k+p);k+=p;e.answers.push(m)}b.dns=e}function Xb(a,b){var c=b.vm_ip.join(".");const d=b.router_ip.join("."),e=16383*Math.random()|0;let f,g,k=0;do f=49152+(e+k)%16383,g=`${c}:${a}:${d}:${f}`;while(16383>++k&&b.tcp_conn[g]);if(b.tcp_conn[g])throw Error("pool of dynamic TCP port numbers exhausted, connection aborted");
|
|
202
|
-
c.tuple=g;c.hsrc=b.router_mac;c.psrc=b.router_ip;c.sport=f;c.hdest=b.vm_mac;c.dport=a;c.pdest=b.vm_ip;b.tcp_conn[g]=c;c.connect();return c}function Zb(a,b){return new Promise(c=>{let d=Xb(a,b);d.state="syn-probe";d.on("probe",c)})}function Yb(a){this.mtu=a.mtu||1500;const b=this.mtu-20-20;this.state="closed";this.net=a;this.send_buffer=new Fb(2048,0);this.send_chunk_buf=new Uint8Array(b);this.delayed_send_fin=this.in_active_close=!1;this.delayed_state=void 0;this.events_handlers={}}Yb.prototype.on=
|
|
119
|
+
if(-2039052682!==t[0])throw new eb("Invalid header: "+n(t[0]>>>0));if(6!==t[1])throw new eb("Version mismatch: dump="+t[1]+" we=6");if(z&&t[2]!==A)throw new eb("Length doesn't match header: real="+A+" header="+t[2]);return t[3]}function d(t){t=(new TextDecoder).decode(t);return JSON.parse(t)}b=new Uint8Array(b);if(4247762216===(new Uint32Array(b.buffer,0,1))[0]){var e=a.zstd_create_ctx(b.length);(new Uint8Array(a.wasm_memory.buffer,a.zstd_get_src_ptr(e)>>>0,b.length)).set(b);var f=a.zstd_read(e,16),
|
|
120
|
+
g=new Uint8Array(a.wasm_memory.buffer,f>>>0,16),k=c(g,!1);a.zstd_read_free(f,16);f=a.zstd_read(e,k);g=new Uint8Array(a.wasm_memory.buffer,f>>>0,k);g=d(g);a.zstd_read_free(f,k);f=g.state;var m=g.buffer_infos;g=[];k=16+k;for(var p of m){m=(k+3&-4)-k;if(1048576<p.length){var q=a.zstd_read(e,m)>>>0;a.zstd_read_free(q,m);q=new Uint8Array(p.length);g.push(q.buffer);for(var r=0;r<p.length;){var v=p.length-r;l(0<=v);v=Math.min(v,1048576);const t=a.zstd_read(e,v);q.set(new Uint8Array(a.wasm_memory.buffer,
|
|
121
|
+
t>>>0,v),r);a.zstd_read_free(t,v);r+=v}}else q=a.zstd_read(e,m+p.length),r=(q>>>0)+m,g.push(a.wasm_memory.buffer.slice(r,r+p.length)),a.zstd_read_free(q,m+p.length);k+=m+p.length}f=hb(f,g);a.set_state(f);a.zstd_free_ctx(e)}else{e=c(b,!0);if(0>e||e+12>=b.length)throw new eb("Invalid info block length: "+e);p=b.subarray(16,16+e);f=d(p);p=f.state;f=f.buffer_infos;let t=16+e;t=t+3&-4;e=f.map(z=>{const A=t+z.offset;return b.buffer.slice(A,A+z.length)});p=hb(p,e);a.set_state(p)}}function jb(a,b,c,d,e){let f=
|
|
122
|
+
"";var g=[],k=b?"compiled":c?"jit exit":d?"unguarded register":e?"wasm size":"executed";for(let q=0;256>q;q++)for(let r=0;8>r;r++)for(const v of[!1,!0]){var m=a.wm.exports.get_opstats_buffer(b,c,d,e,q,!1,v,r);g.push({opcode:q,count:m,is_mem:v,fixed_g:r});m=a.wm.exports.get_opstats_buffer(b,c,d,e,q,!0,v,r);g.push({opcode:3840|q,count:m,is_mem:v,fixed_g:r})}a=0;b=new Set([38,46,54,62,100,101,102,103,240,242,243]);for(const {count:q,opcode:r}of g)b.has(r)||(a+=q);if(0===a)return"";c=new Uint32Array(256);
|
|
123
|
+
b=new Uint32Array(256);for(const {opcode:q,count:r}of g)3840===(q&65280)?b[q&255]+=r:c[q&255]+=r;f=f+"------------------\nTotal: "+(a+"\n");const p=1E7<a?1E3:1;d=Math.max.apply(Math,g.map(({count:q})=>Math.round(q/p)));d=String(d).length;f+=`Instruction counts ${k} (in ${p}):\n`;for(e=0;256>e;e++)f+=e.toString(16).padStart(2,"0")+":"+ca(Math.round(c[e]/p),d),f=15===e%16?f+"\n":f+" ";f=f+"\n"+`Instruction counts ${k} (0f, in ${p}):\n`;for(k=0;256>k;k++)f+=(k&255).toString(16).padStart(2,"0")+":"+ca(Math.round(b[k]/
|
|
124
|
+
p),d),f=15===k%16?f+"\n":f+" ";f+="\n";g=g.filter(({count:q})=>q).sort(({count:q},{count:r})=>r-q);for(const {opcode:q,is_mem:r,fixed_g:v,count:t}of g.slice(0,200))g=q.toString(16)+"_"+v+(r?"_m":"_r"),f+=g+":"+(t/a*100).toFixed(2)+" ";return f+"\n"}function kb(a){this.cpu=a;this.cmos_index=0;this.cmos_data=new Uint8Array(128);this.last_update=this.rtc_time=Date.now();this.next_interrupt_alarm=this.next_interrupt=0;this.periodic_interrupt=!1;this.periodic_interrupt_time=.9765625;this.cmos_a=38;this.cmos_b=
|
|
125
|
+
2;this.nmi_disabled=this.cmos_diag_status=this.cmos_c=0;this.update_interrupt=!1;this.update_interrupt_time=0;a.io.register_write(112,this,function(b){this.cmos_index=b&127;this.nmi_disabled=b>>7});a.io.register_write(113,this,this.cmos_port_write);a.io.register_read(113,this,this.cmos_port_read)}kb.prototype.get_state=function(){var a=[];a[0]=this.cmos_index;a[1]=this.cmos_data;a[2]=this.rtc_time;a[3]=this.last_update;a[4]=this.next_interrupt;a[5]=this.next_interrupt_alarm;a[6]=this.periodic_interrupt;
|
|
126
|
+
a[7]=this.periodic_interrupt_time;a[8]=this.cmos_a;a[9]=this.cmos_b;a[10]=this.cmos_c;a[11]=this.nmi_disabled;a[12]=this.update_interrupt;a[13]=this.update_interrupt_time;a[14]=this.cmos_diag_status;return a};kb.prototype.set_state=function(a){this.cmos_index=a[0];this.cmos_data=a[1];this.rtc_time=a[2];this.last_update=a[3];this.next_interrupt=a[4];this.next_interrupt_alarm=a[5];this.periodic_interrupt=a[6];this.periodic_interrupt_time=a[7];this.cmos_a=a[8];this.cmos_b=a[9];this.cmos_c=a[10];this.nmi_disabled=
|
|
127
|
+
a[11];this.update_interrupt=a[12]||!1;this.update_interrupt_time=a[13]||0;this.cmos_diag_status=a[14]||0};kb.prototype.timer=function(a){a=Date.now();this.rtc_time+=a-this.last_update;this.last_update=a;this.periodic_interrupt&&this.next_interrupt<a?(this.cpu.device_raise_irq(8),this.cmos_c|=192,this.next_interrupt+=this.periodic_interrupt_time*Math.ceil((a-this.next_interrupt)/this.periodic_interrupt_time)):this.next_interrupt_alarm&&this.next_interrupt_alarm<a?(this.cpu.device_raise_irq(8),this.cmos_c|=
|
|
128
|
+
160,this.next_interrupt_alarm=0):this.update_interrupt&&this.update_interrupt_time<a&&(this.cpu.device_raise_irq(8),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};kb.prototype.bcd_pack=function(a){for(var b=0,c=0,d;a;)d=
|
|
129
|
+
a%10,c|=d<<4*b,b++,a=(a-d)/10;return c};kb.prototype.bcd_unpack=function(a){const b=a&15,c=a>>4&15;l(256>a);l(10>b);l(10>c);return b+10*c};kb.prototype.encode_time=function(a){return this.cmos_b&4?a:this.bcd_pack(a)};kb.prototype.decode_time=function(a){return this.cmos_b&4?a:this.bcd_unpack(a)};kb.prototype.cmos_port_read=function(){var a=this.cmos_index;switch(a){case 0:return B("read second: "+n(this.encode_time((new Date(this.rtc_time)).getUTCSeconds())),65536),this.encode_time((new Date(this.rtc_time)).getUTCSeconds());
|
|
130
|
+
case 2:return B("read minute: "+n(this.encode_time((new Date(this.rtc_time)).getUTCMinutes())),65536),this.encode_time((new Date(this.rtc_time)).getUTCMinutes());case 4:return B("read hour: "+n(this.encode_time((new Date(this.rtc_time)).getUTCHours())),65536),this.encode_time((new Date(this.rtc_time)).getUTCHours());case 6:return B("read day: "+n(this.encode_time((new Date(this.rtc_time)).getUTCDay()+1)),65536),this.encode_time((new Date(this.rtc_time)).getUTCDay()+1);case 7:return B("read day of month: "+
|
|
131
|
+
n(this.encode_time((new Date(this.rtc_time)).getUTCDate())),65536),this.encode_time((new Date(this.rtc_time)).getUTCDate());case 8:return B("read month: "+n(this.encode_time((new Date(this.rtc_time)).getUTCMonth()+1)),65536),this.encode_time((new Date(this.rtc_time)).getUTCMonth()+1);case 9:return B("read year: "+n(this.encode_time((new Date(this.rtc_time)).getUTCFullYear()%100)),65536),this.encode_time((new Date(this.rtc_time)).getUTCFullYear()%100);case 10:return 999<=H.microtick()%1E3?this.cmos_a|
|
|
132
|
+
128:this.cmos_a;case 11:return this.cmos_b;case 12:return this.cpu.device_lower_irq(8),B("cmos reg C read",65536),a=this.cmos_c,this.cmos_c&=-241,a;case 13:return 128;case 14:return B("cmos diagnostic status read",65536),this.cmos_diag_status;case 50:case 55:return B("read century: "+n(this.encode_time((new Date(this.rtc_time)).getUTCFullYear()/100|0)),65536),this.encode_time((new Date(this.rtc_time)).getUTCFullYear()/100|0);default:return B("cmos read from index "+n(a),65536),this.cmos_data[this.cmos_index]}};
|
|
133
|
+
kb.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);B("Periodic interrupt, a="+n(this.cmos_a,2)+" t="+this.periodic_interrupt_time,65536);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]),
|
|
134
|
+
e=new Date(Date.UTC(a.getUTCFullYear(),a.getUTCMonth(),a.getUTCDate(),d,c,b));B("RTC alarm scheduled for "+e+" hh:mm:ss="+d+":"+c+":"+b+" ms_from_now="+(e-a),65536);this.next_interrupt_alarm=+e}this.cmos_b&16&&(B("update interrupt",65536),this.update_interrupt_time=Date.now());B("cmos b="+n(this.cmos_b,2),65536);break;case 14:this.cmos_diag_status=a;break;case 1:case 3:case 5:this.cmos_write(this.cmos_index,a);break;default:B("cmos write index "+n(this.cmos_index)+": "+n(a),65536)}this.update_interrupt=
|
|
135
|
+
16===(this.cmos_b&16)&&0<(this.cmos_a&15);this.periodic_interrupt=64===(this.cmos_b&64)&&0<(this.cmos_a&15)};kb.prototype.cmos_read=function(a){l(128>a);return this.cmos_data[a]};kb.prototype.cmos_write=function(a,b){B("cmos "+n(a)+" <- "+n(b),65536);l(128>a);this.cmos_data[a]=b};function lb(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=
|
|
136
|
+
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=H.microtick(),d=66.66666666666667*c&1;c=this.did_rollover(2,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,
|
|
137
|
+
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,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)}lb.prototype.get_state=function(){var a=[];a[0]=this.counter_next_low;
|
|
138
|
+
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};lb.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]};
|
|
139
|
+
lb.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,B("pit interrupt. new value: "+this.counter_start_value[0],512),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])))/
|
|
140
|
+
1193.1816666));return c};lb.prototype.get_counter_value=function(a,b){if(!this.counter_enabled[a])return 0;var c=b-this.counter_start_time[a],d=Math.floor(1193.1816666*c);b=this.counter_start_value[a]-d;B("diff="+c+" dticks="+d+" value="+b+" reload="+this.counter_reload[a],512);c=this.counter_reload[a];b>=c?(B("Warning: Counter"+a+" value "+b+" is larger than reload "+c,512),b%=c):0>b&&(b=b%c+c);return b};lb.prototype.did_rollover=function(a,b){b-=this.counter_start_time[a];return 0>b?(B("Warning: PIT timer difference is negative, resetting (timer "+
|
|
141
|
+
a+")"),!0):this.counter_start_value[a]<Math.floor(1193.1816666*b)};lb.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,H.microtick());return b?a&255:a>>8};lb.prototype.counter_write=function(a,b){this.counter_reload[a]=this.counter_next_low[a]?this.counter_reload[a]&-256|
|
|
142
|
+
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]=H.microtick(),B("counter"+a+" reload="+n(this.counter_reload[a])+" tick="+(this.counter_reload[a]||65536)/1193.1816666+"ms",512));3===this.counter_read_mode[a]&&(this.counter_next_low[a]^=1)};lb.prototype.port43_write=function(a){var b=a>>1&7,c=a&1,
|
|
143
|
+
d=a>>6&3;a=a>>4&3;1===d&&B("Unimplemented timer1",512);3===d?B("Unimplemented read back",512):0===a?(this.counter_latch[d]=2,b=this.get_counter_value(d,H.microtick()),B("latch: "+b,512),this.counter_latch_value[d]=b?b-1:0):(6<=b&&(b&=-5),B("Control: mode="+b+" ctr="+d+" read_mode="+a+" bcd="+c,512),this.counter_next_low[d]=1===a?1:2===a?0:1,0===d&&this.cpu.device_lower_irq(0),0!==b&&3!==b&&2!==b&&B("Unimplemented counter mode: "+n(b),512),this.counter_mode[d]=b,this.counter_read_mode[d]=a,2===d&&
|
|
144
|
+
this.bus.send("pcspeaker-update",[this.counter_mode[2],this.counter_reload[2]]))};lb.prototype.dump=function(){const a=this.counter_reload[0];B("counter0 ticks every "+(a||65536)/1193.1816666+"ms (reload="+a+")")};function mb(a){if("undefined"!==typeof window)if(window.AudioContext||window.webkitAudioContext){var b=window.AudioWorklet?nb:ob;this.bus=a;this.audio_context=window.AudioContext?new AudioContext:new webkitAudioContext;this.mixer=new pb(a,this.audio_context);this.pcspeaker=new qb(a,this.audio_context,
|
|
145
|
+
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()},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")}mb.prototype.destroy=function(){this.audio_context&&this.audio_context.close();
|
|
146
|
+
this.audio_context=null;this.dac&&this.dac.node_processor&&this.dac.node_processor.port.close();this.dac=null};function pb(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";
|
|
147
|
+
this.node_treble_right.type="highshelf";this.node_treble_left.frequency.setValueAtTime(2E3,this.audio_context.currentTime);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,
|
|
148
|
+
this.audio_context.currentTime);this.node_gain_left=this.audio_context.createGain();this.node_gain_right=this.audio_context.createGain();this.node_merger=this.audio_context.createChannelMerger(2);this.input_left=this.node_treble_left;this.input_right=this.node_treble_right;this.node_treble_left.connect(this.node_bass_left);this.node_bass_left.connect(this.node_gain_left);this.node_gain_left.connect(this.node_merger,0,0);this.node_treble_right.connect(this.node_bass_right);this.node_bass_right.connect(this.node_gain_right);
|
|
149
|
+
this.node_gain_right.connect(this.node_merger,0,1);this.node_merger.connect(this.audio_context.destination);a.register("mixer-connect",function(d){this.connect_source(d[0],d[1])},this);a.register("mixer-disconnect",function(d){this.disconnect_source(d[0],d[1])},this);a.register("mixer-volume",function(d){var e=d[0],f=d[1];d=Math.pow(10,d[2]/20);var g=0===e?this:this.sources.get(e);void 0===g?l(!1,"Mixer set volume - cannot set volume for undefined source: "+e):g.set_volume(d,f)},this);a.register("mixer-gain-left",
|
|
150
|
+
function(d){this.gain_left=Math.pow(10,d/20);this.update()},this);a.register("mixer-gain-right",function(d){this.gain_right=Math.pow(10,d/20);this.update()},this);a.register("mixer-treble-left",c(this.node_treble_left),this);a.register("mixer-treble-right",c(this.node_treble_right),this);a.register("mixer-bass-left",c(this.node_bass_left),this);a.register("mixer-bass-right",c(this.node_bass_right),this)}pb.prototype.add_source=function(a,b){a=new rb(this.audio_context,a,this.input_left,this.input_right);
|
|
151
|
+
l(!this.sources.has(b),"Mixer add source - overwritting source: "+b);this.sources.set(b,a);return a};pb.prototype.connect_source=function(a,b){var c=this.sources.get(a);void 0===c?l(!1,"Mixer connect - cannot connect undefined source: "+a):c.connect(b)};pb.prototype.disconnect_source=function(a,b){var c=this.sources.get(a);void 0===c?l(!1,"Mixer disconnect - cannot disconnect undefined source: "+a):c.disconnect(b)};pb.prototype.set_volume=function(a,b){void 0===b&&(b=2);switch(b){case 0:this.volume_left=
|
|
152
|
+
a;break;case 1:this.volume_right=a;break;case 2:this.volume_both=a;break;default:l(!1,"Mixer set master volume - unknown channel: "+b);return}this.update()};pb.prototype.update=function(){var a=this.volume_both*this.volume_right*this.gain_right;this.node_gain_left.gain.setValueAtTime(this.volume_both*this.volume_left*this.gain_left,this.audio_context.currentTime);this.node_gain_right.gain.setValueAtTime(a,this.audio_context.currentTime)};function rb(a,b,c,d){this.audio_context=a;this.connected_right=
|
|
153
|
+
this.connected_left=!0;this.volume_right=this.volume_left=this.volume_both=this.gain_hidden=1;this.node_splitter=a.createChannelSplitter(2);this.node_gain_left=a.createGain();this.node_gain_right=a.createGain();b.connect(this.node_splitter);this.node_splitter.connect(this.node_gain_left,0);this.node_gain_left.connect(c);this.node_splitter.connect(this.node_gain_right,1);this.node_gain_right.connect(d)}rb.prototype.update=function(){var a=this.connected_right*this.gain_hidden*this.volume_both*this.volume_right;
|
|
154
|
+
this.node_gain_left.gain.setValueAtTime(this.connected_left*this.gain_hidden*this.volume_both*this.volume_left,this.audio_context.currentTime);this.node_gain_right.gain.setValueAtTime(a,this.audio_context.currentTime)};rb.prototype.connect=function(a){var b=!a||2===a;if(b||0===a)this.connected_left=!0;if(b||1===a)this.connected_right=!0;this.update()};rb.prototype.disconnect=function(a){var b=!a||2===a;if(b||0===a)this.connected_left=!1;if(b||1===a)this.connected_right=!1;this.update()};rb.prototype.set_volume=
|
|
155
|
+
function(a,b){void 0===b&&(b=2);switch(b){case 0:this.volume_left=a;break;case 1:this.volume_right=a;break;case 2:this.volume_both=a;break;default:l(!1,"Mixer set volume - unknown channel: "+b);return}this.update()};rb.prototype.set_gain_hidden=function(a){this.gain_hidden=a};function qb(a,b,c){this.node_oscillator=b.createOscillator();this.node_oscillator.type="square";this.node_oscillator.frequency.setValueAtTime(440,b.currentTime);this.mixer_connection=c.add_source(this.node_oscillator,1);this.mixer_connection.disconnect();
|
|
156
|
+
a.register("pcspeaker-enable",function(){c.connect_source(1)},this);a.register("pcspeaker-disable",function(){c.disconnect_source(1)},this);a.register("pcspeaker-update",function(d){var e=d[1],f=0;3===d[0]&&(f=Math.min(1193181.6665999999/e,this.node_oscillator.frequency.maxValue),f=Math.max(f,0));this.node_oscillator.frequency.setValueAtTime(f,b.currentTime)},this)}qb.prototype.start=function(){this.node_oscillator.start()};function nb(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=
|
|
157
|
+
48E3;b=function(){function g(p){if(0===p)return 1;p*=Math.PI;return Math.sin(p)/p}function k(){var p=Reflect.construct(AudioWorkletProcessor,[],k);p.kernel_size=3;p.queue_data=Array(1024);p.queue_start=0;p.queue_end=0;p.queue_length=0;p.queue_size=p.queue_data.length;p.queued_samples=0;p.source_buffer_previous=m;p.source_buffer_current=m;p.source_samples_per_destination=1;p.source_block_start=0;p.source_time=0;p.source_offset=0;p.port.onmessage=q=>{switch(q.data.type){case "queue":p.queue_push(q.data.value);
|
|
158
|
+
break;case "sampling-rate":p.source_samples_per_destination=q.data.value/sampleRate}};return p}var m=[new Float32Array(256),new Float32Array(256)];Reflect.setPrototypeOf(k.prototype,AudioWorkletProcessor.prototype);Reflect.setPrototypeOf(k,AudioWorkletProcessor);k.prototype.process=k.prototype.process=function(p,q){for(p=0;p<q[0][0].length;p++){for(var r=0,v=0,t=this.source_offset+this.kernel_size,z=this.source_offset-this.kernel_size+1;z<=t;z++){var A=this.source_block_start+z;r+=this.get_sample(A,
|
|
159
|
+
0)*this.kernel(this.source_time-z);v+=this.get_sample(A,1)*this.kernel(this.source_time-z)}if(isNaN(r)||isNaN(v))r=v=0,this.dbg_log("ERROR: NaN values! Ignoring for now.");q[0][0][p]=r;q[0][1][p]=v;this.source_time+=this.source_samples_per_destination;this.source_offset=Math.floor(this.source_time)}q=this.source_offset;q+=this.kernel_size+2;this.source_time-=this.source_offset;this.source_block_start+=this.source_offset;this.source_offset=0;this.ensure_enough_data(q);return!0};k.prototype.kernel=
|
|
160
|
+
function(p){return g(p)*g(p/this.kernel_size)};k.prototype.get_sample=function(p,q){return 0>p?(p+=this.source_buffer_previous[0].length,this.source_buffer_previous[q][p]):this.source_buffer_current[q][p]};k.prototype.ensure_enough_data=function(p){var q=this.source_buffer_current[0].length;q-this.source_block_start<p&&(this.prepare_next_buffer(),this.source_block_start-=q)};k.prototype.prepare_next_buffer=function(){256>this.queued_samples&&this.queue_length&&this.dbg_log("Not enough samples - should not happen during midway of playback");
|
|
161
|
+
this.source_buffer_previous=this.source_buffer_current;this.source_buffer_current=this.queue_shift();var p=this.source_buffer_current[0].length;if(256>p){for(var q=this.queue_start,r=0;256>p&&r<this.queue_length;)p+=this.queue_data[q][0].length,q=q+1&this.queue_size-1,r++;p=Math.max(p,256);p=[new Float32Array(p),new Float32Array(p)];p[0].set(this.source_buffer_current[0]);p[1].set(this.source_buffer_current[1]);q=this.source_buffer_current[0].length;for(var v=0;v<r;v++){var t=this.queue_shift();p[0].set(t[0],
|
|
162
|
+
q);p[1].set(t[1],q);q+=t[0].length}this.source_buffer_current=p}this.pump()};k.prototype.pump=function(){1024>this.queued_samples/this.source_samples_per_destination&&this.port.postMessage({type:"pump"})};k.prototype.queue_push=function(p){this.queue_length<this.queue_size&&(this.queue_data[this.queue_end]=p,this.queue_end=this.queue_end+1&this.queue_size-1,this.queue_length++,this.queued_samples+=p[0].length,this.pump())};k.prototype.queue_shift=function(){if(!this.queue_length)return m;var p=this.queue_data[this.queue_start];
|
|
163
|
+
this.queue_data[this.queue_start]=null;this.queue_start=this.queue_start+1&this.queue_size-1;this.queue_length--;this.queued_samples-=p[0].length;return p};k.prototype.dbg_log=function(p){this.port.postMessage({type:"debug-log",value:p})};registerProcessor("dac-processor",k)}.toString();var d=b.indexOf("{")+1,e=b.lastIndexOf("}");b=b.substring(d,e);b=new Blob(["var DEBUG = true;\n"+b],{type:"application/javascript"});var f=URL.createObjectURL(b);this.node_processor=null;this.node_output=this.audio_context.createGain();
|
|
164
|
+
this.audio_context.audioWorklet.addModule(f).then(()=>{URL.revokeObjectURL(f);this.node_processor=new AudioWorkletNode(this.audio_context,"dac-processor",{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[2],parameterData:{},processorOptions:{}});this.node_processor.port.postMessage({type:"sampling-rate",value:this.sampling_rate});this.node_processor.port.onmessage=g=>{switch(g.data.type){case "pump":this.pump();break;case "debug-log":B("SpeakerWorkletDAC - Worklet: "+g.data.value)}};this.node_processor.connect(this.node_output)});
|
|
165
|
+
this.mixer_connection=c.add_source(this.node_output,2);this.mixer_connection.set_gain_hidden(3);a.register("dac-send-data",function(g){this.queue(g)},this);a.register("dac-enable",function(){this.enabled=!0},this);a.register("dac-disable",function(){this.enabled=!1},this);a.register("dac-tell-sampling-rate",function(g){l(0<g,"Sampling rate should be nonzero");this.sampling_rate=g;this.node_processor&&this.node_processor.port.postMessage({type:"sampling-rate",value:g})},this);this.debugger=new wb(this.audio_context,
|
|
166
|
+
this.node_output)}nb.prototype.queue=function(a){this.node_processor&&(this.debugger.push_queued_data(a),this.node_processor.port.postMessage({type:"queue",value:a},[a[0].buffer,a[1].buffer]))};nb.prototype.pump=function(){this.enabled&&this.bus.send("dac-request-data")};function ob(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=22050;this.buffered_time=0;this.rate_ratio=1;this.node_lowpass=this.audio_context.createBiquadFilter();this.node_lowpass.type="lowpass";this.node_output=
|
|
167
|
+
this.node_lowpass;this.mixer_connection=c.add_source(this.node_output,2);this.mixer_connection.set_gain_hidden(3);a.register("dac-send-data",function(d){this.queue(d)},this);a.register("dac-enable",function(){this.enabled=!0;this.pump()},this);a.register("dac-disable",function(){this.enabled=!1},this);a.register("dac-tell-sampling-rate",function(d){l(0<d,"Sampling rate should be nonzero");this.sampling_rate=d;this.rate_ratio=Math.ceil(8E3/d);this.node_lowpass.frequency.setValueAtTime(d/2,this.audio_context.currentTime)},
|
|
168
|
+
this);this.debugger=new wb(this.audio_context,this.node_output)}ob.prototype.queue=function(a){this.debugger.push_queued_data(a);var b=a[0].length,c=b/this.sampling_rate;if(1<this.rate_ratio){var d=this.audio_context.createBuffer(2,b*this.rate_ratio,this.sampling_rate*this.rate_ratio);for(var e=d.getChannelData(0),f=d.getChannelData(1),g=0,k=0;k<b;k++)for(var m=0;m<this.rate_ratio;m++,g++)e[g]=a[0][k],f[g]=a[1][k]}else d=this.audio_context.createBuffer(2,b,this.sampling_rate),d.copyToChannel?(d.copyToChannel(a[0],
|
|
169
|
+
0),d.copyToChannel(a[1],1)):(d.getChannelData(0).set(a[0]),d.getChannelData(1).set(a[1]));a=this.audio_context.createBufferSource();a.buffer=d;a.connect(this.node_lowpass);a.addEventListener("ended",this.pump.bind(this));d=this.audio_context.currentTime;if(this.buffered_time<d)for(B("Speaker DAC - Creating/Recreating reserve - shouldn't occur frequently during playback"),this.buffered_time=d,d=.2-c,b=0;b<=d;)b+=c,this.buffered_time+=c,setTimeout(()=>this.pump(),1E3*b);a.start(this.buffered_time);
|
|
170
|
+
this.buffered_time+=c;setTimeout(()=>this.pump(),0)};ob.prototype.pump=function(){this.enabled&&(.2<this.buffered_time-this.audio_context.currentTime||this.bus.send("dac-request-data"))};function wb(a,b){this.audio_context=a;this.node_source=b;this.node_processor=null;this.node_gain=this.audio_context.createGain();this.node_gain.gain.setValueAtTime(0,this.audio_context.currentTime);this.node_gain.connect(this.audio_context.destination);this.is_active=!1;this.queued_history=[];this.output_history=
|
|
171
|
+
[];this.queued=[[],[]];this.output=[[],[]]}wb.prototype.start=function(a){this.is_active=!0;this.queued=[[],[]];this.output=[[],[]];this.queued_history.push(this.queued);this.output_history.push(this.output);this.node_processor=this.audio_context.createScriptProcessor(1024,2,2);this.node_processor.onaudioprocess=b=>{this.output[0].push(b.inputBuffer.getChannelData(0).slice());this.output[1].push(b.inputBuffer.getChannelData(1).slice())};this.node_source.connect(this.node_processor);this.node_processor.connect(this.node_gain);
|
|
172
|
+
setTimeout(()=>{this.stop()},a)};wb.prototype.stop=function(){this.is_active=!1;this.node_source.disconnect(this.node_processor);this.node_processor.disconnect();this.node_processor=null};wb.prototype.push_queued_data=function(a){this.is_active&&(this.queued[0].push(a[0].slice()),this.queued[1].push(a[1].slice()))};wb.prototype.download_txt=function(a,b){a=this.output_history[a][b].map(c=>c.join(" ")).join(" ");qa(a,"dacdata.txt")};wb.prototype.download_csv=function(a){a=this.output_history[a];for(var b=
|
|
173
|
+
[],c=0;c<a[0].length;c++)for(var d=0;d<a[0][c].length;d++)b.push(`${a[0][c][d]},${a[1][c][d]}`);qa(b.join("\n"),"dacdata.csv")};function xb(a,b,c){this.bus=b;this.socket=void 0;this.id=c||0;this.send_queue=[];this.url=a;this.reconnect_interval=1E4;this.last_connect_attempt=Date.now()-this.reconnect_interval;this.send_queue_limit=64;this.destroyed=!1;this.bus.register("net"+this.id+"-send",function(d){this.send(d)},this)}xb.prototype.handle_message=function(a){this.bus&&this.bus.send("net"+this.id+
|
|
174
|
+
"-receive",new Uint8Array(a.data))};xb.prototype.handle_close=function(){this.destroyed||(this.connect(),setTimeout(this.connect.bind(this),this.reconnect_interval))};xb.prototype.handle_open=function(){for(var a=0;a<this.send_queue.length;a++)this.send(this.send_queue[a]);this.send_queue=[]};xb.prototype.handle_error=function(){};xb.prototype.destroy=function(){this.destroyed=!0;this.socket&&this.socket.close()};xb.prototype.connect=function(){if("undefined"!==typeof WebSocket){if(this.socket){var a=
|
|
175
|
+
this.socket.readyState;if(0===a||1===a)return}a=Date.now();if(!(this.last_connect_attempt+this.reconnect_interval>a)){this.last_connect_attempt=Date.now();try{this.socket=new WebSocket(this.url)}catch(b){console.error(b);return}this.socket.binaryType="arraybuffer";this.socket.onopen=this.handle_open.bind(this);this.socket.onmessage=this.handle_message.bind(this);this.socket.onclose=this.handle_close.bind(this);this.socket.onerror=this.handle_error.bind(this)}}};xb.prototype.send=function(a){this.socket&&
|
|
176
|
+
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())};xb.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 yb=(new Date("1970-01-01T00:00:00Z")).getTime(),zb=(new Date("1900-01-01T00:00:00Z")).getTime(),Ab=yb-zb,Bb=Math.pow(2,32),Cb=
|
|
177
|
+
[118,56,54];function Db(a){return[0,1,2,3,4,5].map(b=>a[b].toString(16)).map(b=>1===b.length?"0"+b:b).join(":")}function Eb(a){return a[0]<<24|a[1]<<16|a[2]<<8|a[3]}class Fb{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(l(0<d);d<c;)d*=2;if(this.maximum_capacity&&d>this.maximum_capacity)throw Error("stream capacity overflow in GrowableRingbuffer.write(), package dropped");
|
|
178
|
+
c=new Uint8Array(d);this.peek(c);this.tail=0;this.head=this.length;this.buffer=c}c=this.buffer;const e=this.head+b;if(e>d){const f=d-this.head;c.set(a.subarray(0,f),this.head);c.set(a.subarray(f))}else c.set(a,this.head);this.head=e%d;this.length+=b}peek(a){const b=Math.min(this.length,a.length);if(b){const e=this.buffer;var c=e.length,d=this.tail+b;d>c?(d%=c,c-=this.tail,a.set(e.subarray(this.tail)),a.set(e.subarray(0,d),c)):a.set(e.subarray(this.tail,d))}return b}remove(a){a>this.length&&(a=this.length);
|
|
179
|
+
a&&(this.tail=(this.tail+a)%this.buffer.length,this.length-=a);return a}}function Gb(a=1500){const b=a-20,c=b-8,d=new Uint8Array(14+a+4),e=d.buffer,f=d.byteOffset;return{eth_frame:d,eth_frame_view:new DataView(e),eth_payload_view:new DataView(e,f+14,a),ipv4_payload_view:new DataView(e,f+34,b),udp_payload_view:new DataView(e,f+42,c),text_encoder:new TextEncoder}}function Hb(a,b,c,d){d.eth_frame.set(b,c.byteOffset+a);return b.length}function Ib(a,b,c,d){const e=c.byteOffset+(a&-2);d=d.eth_frame;for(c=
|
|
180
|
+
c.byteOffset;c<e;c+=2)b+=d[c]<<8|d[c+1];for(a&1&&(b+=d[e]<<8);b>>>16;)b=(b&65535)+(b>>>16);return~b&65535}function Jb(a,b){l(b.eth);a.eth_frame.fill(0);var c=a.eth_frame,d=c.subarray,e=a.eth_frame_view;Hb(0,b.eth.dest,e,a);Hb(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);Hb(8,b.arp.sha,f,a);Hb(14,b.arp.spa,f,a);Hb(18,
|
|
181
|
+
b.arp.tha,f,a);Hb(24,b.arp.tpa,f,a);e+=28}else if(b.ipv4){f=a.eth_payload_view;var g=20;if(b.icmp){var k=a.ipv4_payload_view;k.setUint8(0,b.icmp.type);k.setUint8(1,b.icmp.code);k.setUint16(2,0);var m=4+Hb(4,b.icmp.data,k,a);k.setUint16(2,Ib(m,0,k,a));g+=m}else if(b.udp){k=a.ipv4_payload_view;var p=8;if(b.dhcp){m=p;var q=a.udp_payload_view;q.setUint8(0,b.dhcp.op);q.setUint8(1,b.dhcp.htype);q.setUint8(2,b.dhcp.hlen);q.setUint8(3,b.dhcp.hops);q.setUint32(4,b.dhcp.xid);q.setUint16(8,b.dhcp.secs);q.setUint16(10,
|
|
182
|
+
b.dhcp.flags);q.setUint32(12,b.dhcp.ciaddr);q.setUint32(16,b.dhcp.yiaddr);q.setUint32(20,b.dhcp.siaddr);q.setUint32(24,b.dhcp.giaddr);Hb(28,b.dhcp.chaddr,q,a);q.setUint32(236,1669485411);p=240;for(var r of b.dhcp.options)p+=Hb(p,r,q,a);m+=p}else if(b.dns){r=p;p=a.udp_payload_view;p.setUint16(0,b.dns.id);p.setUint16(2,b.dns.flags);p.setUint16(4,b.dns.questions.length);p.setUint16(6,b.dns.answers.length);let z=12;for(var v=0;v<b.dns.questions.length;++v){var t=b.dns.questions[v];for(q of t.name){const A=
|
|
183
|
+
a.text_encoder.encodeInto(q,a.eth_frame.subarray(p.byteOffset+(z+1))).written;p.setUint8(z,A);z+=1+A}p.setUint16(z,t.type);z+=2;p.setUint16(z,t.class);z+=2}for(v=0;v<b.dns.answers.length;++v){q=b.dns.answers[v];for(m of q.name)t=a.text_encoder.encodeInto(m,a.eth_frame.subarray(p.byteOffset+(z+1))).written,p.setUint8(z,t),z+=1+t;p.setUint16(z,q.type);z+=2;p.setUint16(z,q.class);z+=2;p.setUint32(z,q.ttl);z+=4;p.setUint16(z,q.data.length);z+=2;z+=Hb(z,q.data,p,a)}m=r+z}else b.ntp?(m=p,q=a.udp_payload_view,
|
|
184
|
+
q.setUint8(0,b.ntp.flags),q.setUint8(1,b.ntp.stratum),q.setUint8(2,b.ntp.poll),q.setUint8(3,b.ntp.precision),q.setUint32(4,b.ntp.root_delay),q.setUint32(8,b.ntp.root_disp),q.setUint32(12,b.ntp.ref_id),q.setUint32(16,b.ntp.ref_ts_i),q.setUint32(20,b.ntp.ref_ts_f),q.setUint32(24,b.ntp.ori_ts_i),q.setUint32(28,b.ntp.ori_ts_f),q.setUint32(32,b.ntp.rec_ts_i),q.setUint32(36,b.ntp.rec_ts_f),q.setUint32(40,b.ntp.trans_ts_i),q.setUint32(44,b.ntp.trans_ts_f),m+=48):m=p+Hb(0,b.udp.data,a.udp_payload_view,a);
|
|
185
|
+
p=m;k.setUint16(0,b.udp.sport);k.setUint16(2,b.udp.dport);k.setUint16(4,p);k.setUint16(6,0);k.setUint16(6,Ib(p,(b.ipv4.src[0]<<8|b.ipv4.src[1])+(b.ipv4.src[2]<<8|b.ipv4.src[3])+(b.ipv4.dest[0]<<8|b.ipv4.dest[1])+(b.ipv4.dest[2]<<8|b.ipv4.dest[3])+17+p,k,a));g+=p}else b.tcp&&(k=a.ipv4_payload_view,m=0,q=b.tcp,q.fin&&(m|=1),q.syn&&(m|=2),q.rst&&(m|=4),q.psh&&(m|=8),q.ack&&(m|=16),q.urg&&(m|=32),q.ece&&(m|=64),q.cwr&&(m|=128),r=20,q.options&&q.options.mss&&(k.setUint8(r,2),k.setUint8(r+1,4),k.setUint16(r+
|
|
186
|
+
2,q.options.mss),r+=4),p=4*Math.ceil(r/4),q.options&&0<p-r&&a.eth_frame.fill(0,k.byteOffset+r,k.byteOffset+r+(p-r)),k.setUint16(0,q.sport),k.setUint16(2,q.dport),k.setUint32(4,q.seq),k.setUint32(8,q.ackn),k.setUint8(12,p>>2<<4),k.setUint8(13,m),k.setUint16(14,q.winsize),k.setUint16(16,0),k.setUint16(18,q.urgent||0),b.tcp_data&&(p+=Hb(20,b.tcp_data,k,a)),k.setUint16(16,Ib(p,(b.ipv4.src[0]<<8|b.ipv4.src[1])+(b.ipv4.src[2]<<8|b.ipv4.src[3])+(b.ipv4.dest[0]<<8|b.ipv4.dest[1])+(b.ipv4.dest[2]<<8|b.ipv4.dest[3])+
|
|
187
|
+
6+p,k,a)),g+=p);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);Hb(12,b.ipv4.src,f,a);Hb(16,b.ipv4.dest,f,a);f.setUint16(10,Ib(20,0,f,a));e+=g}return d.call(c,0,e)}function Tb(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,
|
|
188
|
+
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(Jb(b.eth_encoder_buf,c))});return!0}function Ub(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:Eb(b.vm_ip),siaddr:Eb(b.router_ip),giaddr:Eb(b.router_ip),chaddr:a.dhcp.chaddr};
|
|
189
|
+
let d=[],e=a.dhcp.options.find(function(f){return 53===f[0]});e&&3===e[2]&&(a.dhcp.op=3);1===a.dhcp.op&&(c.dhcp.op=2,d.push(new Uint8Array([53,1,2])));3===a.dhcp.op&&(c.dhcp.op=2,d.push(new Uint8Array([53,1,5])),d.push(new Uint8Array([51,4,8,0,0,0])));a=[b.router_ip[0],b.router_ip[1],b.router_ip[2],b.router_ip[3]];d.push(new Uint8Array([1,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,
|
|
190
|
+
3].concat(Cb)));d.push(new Uint8Array([255,0]));c.dhcp.options=d;b.receive(Jb(b.eth_encoder_buf,c))}function Vb(a,b){let c={};var d=(new DataView(a.buffer,a.byteOffset,a.byteLength)).getUint16(12),e={ethertype:d,dest:a.subarray(0,6),dest_s:Db(a.subarray(0,6)),src:a.subarray(6,12),src_s:Db(a.subarray(6,12))};c.eth=e;a=a.subarray(14,a.length);if(2048===d){var f=new DataView(a.buffer,a.byteOffset,a.byteLength),g=a[0]>>4&15;e=a[0]&15;var k=f.getUint8(1),m=f.getUint16(2);let p=f.getUint8(8);d=f.getUint8(9);
|
|
191
|
+
f=f.getUint16(10);g={version:g,ihl:e,tos:k,len:m,ttl:p,proto:d,ip_checksum:f,src:a.subarray(12,16),dest:a.subarray(16,20)};Math.max(m,46)!==a.length&&B(`ipv4 Length mismatch: ${m} != ${a.length}`,16777216);c.ipv4=g;e=a.subarray(4*e,m);if(1===d)a=new DataView(e.buffer,e.byteOffset,e.byteLength),a={type:a.getUint8(0),code:a.getUint8(1),checksum:a.getUint16(2),data:e.subarray(4)},c.icmp=a;else if(6===d)d=new DataView(e.buffer,e.byteOffset,e.byteLength),a={sport:d.getUint16(0),dport:d.getUint16(2),seq:d.getUint32(4),
|
|
192
|
+
ackn:d.getUint32(8),doff:d.getUint8(12)>>4,winsize:d.getUint16(14),checksum:d.getUint16(16),urgent:d.getUint16(18)},d=d.getUint8(13),a.fin=!!(d&1),a.syn=!!(d&2),a.rst=!!(d&4),a.psh=!!(d&8),a.ack=!!(d&16),a.urg=!!(d&32),a.ece=!!(d&64),a.cwr=!!(d&128),c.tcp=a,c.tcp_data=e.subarray(4*a.doff);else if(17===d){a=new DataView(e.buffer,e.byteOffset,e.byteLength);a={sport:a.getUint16(0),dport:a.getUint16(2),len:a.getUint16(4),checksum:a.getUint16(6),data:e.subarray(8),data_s:(new TextDecoder).decode(e.subarray(8))};
|
|
193
|
+
if(67===a.dport||67===a.sport){e=e.subarray(8);d=new DataView(e.buffer,e.byteOffset,e.byteLength);e.subarray(44,236);d={op:d.getUint8(0),htype:d.getUint8(1),hlen:d.getUint8(2),hops:d.getUint8(3),xid:d.getUint32(4),secs:d.getUint16(8),flags:d.getUint16(10),ciaddr:d.getUint32(12),yiaddr:d.getUint32(16),siaddr:d.getUint32(20),giaddr:d.getUint32(24),chaddr:e.subarray(28,44),magic:d.getUint32(236),options:[]};e=e.subarray(240);for(m=0;m<e.length;++m)g=m,0!==e[m]&&(++m,k=e[m],m+=k,d.options.push(e.subarray(g,
|
|
194
|
+
g+k+2)));c.dhcp=d;c.dhcp_options=d.options}else 53===a.dport||53===a.sport?Wb(e.subarray(8),c):123===a.dport&&(d=e.subarray(8),d=new DataView(d.buffer,d.byteOffset,d.byteLength),c.ntp={flags:d.getUint8(0),stratum:d.getUint8(1),poll:d.getUint8(2),precision:d.getUint8(3),root_delay:d.getUint32(4),root_disp:d.getUint32(8),ref_id:d.getUint32(12),ref_ts_i:d.getUint32(16),ref_ts_f:d.getUint32(20),ori_ts_i:d.getUint32(24),ori_ts_f:d.getUint32(28),rec_ts_i:d.getUint32(32),rec_ts_f:d.getUint32(36),trans_ts_i:d.getUint32(40),
|
|
195
|
+
trans_ts_f:d.getUint32(44)});c.udp=a}}else 2054===d?(d=new DataView(a.buffer,a.byteOffset,a.byteLength),a={htype:d.getUint16(0),ptype:d.getUint16(2),oper:d.getUint16(6),sha:a.subarray(8,14),spa:a.subarray(14,18),tha:a.subarray(18,24),tpa:a.subarray(24,28)},c.arp=a):34525===d?B("Unimplemented: ipv6"):B("Unknown ethertype: "+n(d),16777216);if(c.ipv4)if(c.tcp)a:{a=`${c.ipv4.src.join(".")}:${c.tcp.sport}:${c.ipv4.dest.join(".")}:${c.tcp.dport}`;if(c.tcp.syn&&(b.tcp_conn[a]&&B("SYN to already opened port",
|
|
196
|
+
16777216),b.on_tcp_connection(c,a)))break a;if(b.tcp_conn[a])b.tcp_conn[a].process(c);else{B(`I dont know about ${a}, so resetting`,16777216);a=c.tcp.ackn;if(c.tcp.fin||c.tcp.syn)a+=1;d={};d.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src};d.ipv4={proto:6,src:c.ipv4.dest,dest:c.ipv4.src};d.tcp={sport:c.tcp.dport,dport:c.tcp.sport,seq:a,ackn:c.tcp.seq+(c.tcp.syn?1:0),winsize:c.tcp.winsize,rst:!0,ack:c.tcp.syn};b.receive(Jb(b.eth_encoder_buf,d))}}else if(c.udp)if(c.dns)if("static"===b.dns_method){a=
|
|
197
|
+
{};a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src};a.ipv4={proto:17,src:b.router_ip,dest:c.ipv4.src};a.udp={sport:53,dport:c.udp.sport};d=[];for(e=0;e<c.dns.questions.length;++e)switch(m=c.dns.questions[e],m.type){case 1:d.push({name:m.name,type:m.type,class:m.class,ttl:600,data:[192,168,87,1]})}a.dns={id:c.dns.id,flags:33152,questions:c.dns.questions,answers:d};b.receive(Jb(b.eth_encoder_buf,a))}else Tb(c,b);else c.dhcp?Ub(c,b):c.ntp?(a=Date.now()+Ab,d=a%1E3/1E3*Bb,e={},e.eth={ethertype:2048,
|
|
198
|
+
src:b.router_mac,dest:c.eth.src},e.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},e.udp={sport:123,dport:c.udp.sport},e.ntp=Object.assign({},c.ntp),e.ntp.flags=36,e.ntp.poll=10,e.ntp.ori_ts_i=c.ntp.trans_ts_i,e.ntp.ori_ts_f=c.ntp.trans_ts_f,e.ntp.rec_ts_i=a/1E3,e.ntp.rec_ts_f=d,e.ntp.trans_ts_i=a/1E3,e.ntp.trans_ts_f=d,e.ntp.stratum=2,b.receive(Jb(b.eth_encoder_buf,e))):8===c.udp.dport&&(a={},a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},a.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},
|
|
199
|
+
a.udp={sport:c.udp.dport,dport:c.udp.sport,data:(new TextEncoder).encode(c.udp.data_s)},b.receive(Jb(b.eth_encoder_buf,a)));else c.icmp&&8===c.icmp.type&&(a={},a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},a.ipv4={proto:1,src:c.ipv4.dest,dest:c.ipv4.src},a.icmp={type:0,code:c.icmp.code,data:c.icmp.data},b.receive(Jb(b.eth_encoder_buf,a)));else c.arp&&1===c.arp.oper&&2048===c.arp.ptype&&(a=Eb(c.arp.tpa)&4294967040,d=Eb(b.router_ip)&4294967040,!b.masquerade&&a!==d||a===d&&99<c.arp.tpa[3]||
|
|
200
|
+
(a={},a.eth={ethertype:2054,src:b.router_mac,dest:c.eth.src},a.arp={htype:1,ptype:2048,oper:2,sha:b.router_mac,spa:c.arp.tpa,tha:c.eth.src,tpa:c.arp.spa},b.receive(Jb(b.eth_encoder_buf,a))))}function Wb(a,b){function c(){let p=[],q;do q=d.getUint8(k),p.push((new TextDecoder).decode(a.subarray(k+1,k+1+q))),k+=q+1;while(0<q);return p}let d=new DataView(a.buffer,a.byteOffset,a.byteLength),e={id:d.getUint16(0),flags:d.getUint16(2),questions:[],answers:[]};var f=d.getUint16(4);let g=d.getUint16(6);d.getUint16(8);
|
|
201
|
+
d.getUint16(10);let k=12;for(var m=0;m<f;m++)e.questions.push({name:c(),type:d.getInt16(k),class:d.getInt16(k+2)}),k+=4;for(f=0;f<g;f++){m={name:c(),type:d.getInt16(k),class:d.getUint16(k+2),ttl:d.getUint32(k+4)};k+=8;let p=d.getUint16(k);k+=2;m.data=a.subarray(k,k+p);k+=p;e.answers.push(m)}b.dns=e}function Xb(a,b){var c=b.vm_ip.join(".");const d=b.router_ip.join("."),e=16383*Math.random()|0;let f,g,k=0;do f=49152+(e+k)%16383,g=`${c}:${a}:${d}:${f}`;while(16383>++k&&b.tcp_conn[g]);if(b.tcp_conn[g])throw Error("pool of dynamic TCP port numbers exhausted, connection aborted");
|
|
202
|
+
c=new Yb(b);c.tuple=g;c.hsrc=b.router_mac;c.psrc=b.router_ip;c.sport=f;c.hdest=b.vm_mac;c.dport=a;c.pdest=b.vm_ip;b.tcp_conn[g]=c;c.connect();return c}function Zb(a,b){return new Promise(c=>{let d=Xb(a,b);d.state="syn-probe";d.on("probe",c)})}function Yb(a){this.mtu=a.mtu||1500;const b=this.mtu-20-20;this.state="closed";this.net=a;this.send_buffer=new Fb(2048,0);this.send_chunk_buf=new Uint8Array(b);this.delayed_send_fin=this.in_active_close=!1;this.delayed_state=void 0;this.events_handlers={}}Yb.prototype.on=
|
|
203
203
|
function(a,b){this.events_handlers[a]=b};Yb.prototype.emit=function(a,...b){this.events_handlers[a]&&this.events_handlers[a].apply(this,b)};Yb.prototype.ipv4_reply=function(){let a={};a.eth={ethertype:2048,src:this.hsrc,dest:this.hdest};a.ipv4={proto:6,src:this.psrc,dest:this.pdest};a.tcp={sport:this.sport,dport:this.dport,winsize:this.winsize,ackn:this.ack,seq:this.seq,ack:!0};return a};Yb.prototype.packet_reply=function(a,b){a={sport:a.tcp.dport,dport:a.tcp.sport,winsize:a.tcp.winsize,ackn:this.ack,
|
|
204
204
|
seq:this.seq};if(b)for(const c in b)a[c]=b[c];b=this.ipv4_reply();b.tcp=a;return b};Yb.prototype.connect=function(){this.seq=1338;this.ack=1;this.start_seq=0;this.winsize=64240;this.state="syn-sent";let a=this.ipv4_reply();a.ipv4.id=2345;a.tcp={sport:this.sport,dport:this.dport,seq:1337,ackn:0,winsize:0,syn:!0};this.net.receive(Jb(this.net.eth_encoder_buf,a))};Yb.prototype.accept=function(a){this.seq=1338;this.ack=a.tcp.seq+1;this.start_seq=a.tcp.seq;this.hsrc=this.net.router_mac;this.psrc=a.ipv4.dest;
|
|
205
205
|
this.sport=a.tcp.dport;this.hdest=a.eth.src;this.dport=a.tcp.sport;this.pdest=a.ipv4.src;this.winsize=a.tcp.winsize;let b=this.ipv4_reply();b.tcp={sport:this.sport,dport:this.dport,seq:1337,ackn:this.ack,winsize:a.tcp.winsize,syn:!0,ack:!0,options:{mss:this.mtu-20-20}};this.state="established";this.net.receive(Jb(this.net.eth_encoder_buf,b))};Yb.prototype.process=function(a){if("closed"===this.state)a=this.packet_reply(a,{rst:!0}),this.net.receive(Jb(this.net.eth_encoder_buf,a));else if(a.tcp.rst){if("syn-probe"===
|
|
@@ -248,37 +248,37 @@ e,!1);window.removeEventListener("mousedown",f,!1)};this.init=function(){this.de
|
|
|
248
248
|
this.update_timer&&(this.update_timer=setTimeout(()=>{this.update_timer=void 0;var p=Date.now();l(15<=p-this.last_update);this.last_update=p;this.render()},16-m)):(void 0!==this.update_timer&&(clearTimeout(this.update_timer),this.update_timer=void 0),this.last_update=k,this.render())};this.render=function(){a.value=this.text;this.text_new_line&&(this.text_new_line=!1,a.scrollTop=1E9)};this.send_char=function(k){g.bus&&g.bus.send("serial0-input",k)}}function nc(a,b){this.element=a;if(window.Terminal){var c=
|
|
249
249
|
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=new TextEncoder,e=c.onData(function(f){for(const g of d.encode(f))b.send("serial0-input",g)});b.register("serial0-output-byte",function(f){c.write(Uint8Array.of(f))},this);this.destroy=function(){e.dispose();c.dispose()}}}nc.prototype.show=function(){this.term&&this.term.open(this.element)};function oc(a,b){b=b.id||0;this.bus=a;this.bus_send_msgid=
|
|
250
250
|
`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)}oc.prototype.destroy=function(){this.is_open&&(this.bus.unregister(this.bus_send_msgid,this.nic_to_hub_fn),this.channel.removeEventListener("message",
|
|
251
|
-
this.hub_to_nic_fn),this.channel.close(),this.is_open=!1)};function pc(){this.filedata=new Map}pc.prototype.read=async function(a,b,c){l(a,"MemoryFileStorage read: sha256sum should be a non-empty string");return(a=this.filedata.get(a))?a.subarray(b,b+c):null};pc.prototype.cache=async function(a,b){l(a,"MemoryFileStorage cache: sha256sum should be a non-empty string");this.filedata.set(a,b)};pc.prototype.uncache=function(a){this.filedata.delete(a)};function qc(a,b){l(b,"ServerMemoryFileStorage: baseurl should not be empty");
|
|
252
|
-
b.endsWith("/")||(b+="/");this.storage=a;this.baseurl=b}qc.prototype.load_from_server=function(a){return new Promise(
|
|
253
|
-
sc=new TextEncoder;function I(a,b,c,d){for(var e,f=0,g=0;g<a.length;g++)switch(e=b[g],a[g]){case "w":c[d++]=e&255;c[d++]=e>>8&255;c[d++]=e>>16&255;c[d++]=e>>24&255;f+=4;break;case "d":c[d++]=e&255;c[d++]=e>>8&255;c[d++]=e>>16&255;c[d++]=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 k=d,m=0;c[d++]=0;c[d++]=0;f+=2;e=
|
|
254
|
-
1]=m>>8&255;break;case "Q":I(["b","w","d"],[e.type,e.version,e.path],c,d);d+=13;f+=13;break;default:B("Marshall: Unknown type="+a[g])}return f}function J(a,b,c){let d=c.offset;for(var e=[],f=0;f<a.length;f++)switch(a[f]){case "w":var g=b[d++];g+=b[d++]<<8;g+=b[d++]<<16;g+=b[d++]<<24>>>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+
|
|
255
|
-
b.slice(d,d+g);d+=g;e.push(rc.decode(k));break;case "Q":c.offset=d;g=J(["b","w","d"],b,c);d=c.offset;e.push({type:g[0],version:g[1],path:g[2]});break;default:B("Error in Unmarshall: Unknown type="+a[f])}c.offset=d;return e}const tc=new TextEncoder;function L(a,b){this.inodes=[];this.storage=a;this.qidcounter=b||{last_qidnumber:0};this.inodedata={};this.total_size=274877906944;this.used_size=0;this.mounts=[];this.CreateDirectory(""
|
|
256
|
-
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)};L.prototype.set_state=function(a){this.inodes=a[0].map(b=>{const c=new uc(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()),
|
|
257
|
-
a.slice(5)};L.prototype.load_from_json=function(a){l(a,"Invalid fs passed to load_from_json");if(3!==a.version)throw"The filesystem JSON format has changed. Please recreate the filesystem JSON.";var b=a.fsroot;this.used_size=a.size;for(a=0;a<b.length;a++)this.LoadRecursive(b[a],0)};L.prototype.LoadRecursive=function(a,b){var c=this.CreateInode();const d=a[0];c.size=a[1];c.mtime=a[2];c.ctime=c.mtime;c.atime=c.mtime;c.mode=a[3];
|
|
258
|
-
d),this.LoadDir(this.inodes.length-1,a[6])):32768===e?(c.status=2,c.sha256sum=a[6],l(c.sha256sum),this.PushInode(c,b,d)):40960===e?(c.symlink=a[6],this.PushInode(c,b,d)):49152!==e&&B("Unexpected ifmt: "+n(e)+" ("+d+")",4194304)};L.prototype.LoadDir=function(a,b){for(var c=0;c<b.length;c++)this.LoadRecursive(b[c],a)};L.prototype.should_be_linked=function(a){return!this.is_forwarder(a)||0===a.foreign_id};L.prototype.link_under_dir=
|
|
259
|
-
"Filesystem: Shouldn't link under fowarder parents");l(this.IsDirectory(a),"Filesystem: Can't link under non-directories");l(this.should_be_linked(d),"Filesystem: Can't link across filesystems apart from their root");l(0<=d.nlinks,"Filesystem: Found negative nlinks value of "+d.nlinks);l(!e.direntries.has(c),"Filesystem: Name '"+c+"' is already taken");e.direntries.set(c,b);d.nlinks++;this.IsDirectory(b)&&(l(!d.direntries.has(".."),
|
|
260
|
-
d.nlinks++,d.direntries.set(".",b),d.direntries.set("..",a),e.nlinks++)};L.prototype.unlink_from_dir=function(a,b){const c=this.Search(a,b),d=this.inodes[c],e=this.inodes[a];l(!this.is_forwarder(e),"Filesystem: Can't unlink from forwarders");l(this.IsDirectory(a),"Filesystem: Can't unlink from non-directories");e.direntries.delete(b)?(d.nlinks--,this.IsDirectory(c)&&(l(d.direntries.get("..")===a,"Filesystem: Found directory with bad parent id"),
|
|
261
|
-
"Filesystem: Found negative nlinks value of "+d.nlinks)):l(!1,"Filesystem: Can't unlink non-existent file: "+b)};L.prototype.PushInode=function(a,b,c){-1!==b?(this.inodes.push(a),a.fid=this.inodes.length-1,this.link_under_dir(b,a.fid,c)):0===this.inodes.length?(this.inodes.push(a),a.direntries.set(".",0),a.direntries.set("..",0),a.nlinks=2):l(!1,"Error in Filesystem: Pushed inode with name = "+c+" has no parent")};function uc(a){this.direntries=
|
|
262
|
-
this.ctime=this.fid=this.gid=this.uid=this.size=this.status=0;this.symlink="";this.mode=493;this.qid={type:0,version:0,path:a};this.caps=void 0;this.nlinks=0;this.sha256sum="";this.locks=[];this.foreign_id=this.mount_id=-1}uc.prototype.get_state=function(){const a=[];a[0]=this.mode;a[1]=16384===(this.mode&61440)?[...this.direntries]:32768===(this.mode&61440)?this.sha256sum:40960===(this.mode&61440)?this.symlink:49152===(this.mode&61440)?[this.minor,
|
|
263
|
-
a[4]=this.size;a[5]=this.uid;a[6]=this.gid;a[7]=this.fid;a[8]=this.ctime;a[9]=this.atime;a[10]=this.mtime;a[11]=this.qid.version;a[12]=this.qid.path;a[13]=this.nlinks;return a};uc.prototype.set_state=function(a){this.mode=a[0];if(16384===(this.mode&61440)){this.direntries=new Map;for(const [b,c]of a[1])this.direntries.set(b,c)}else 32768===(this.mode&61440)?this.sha256sum=a[1]:40960===(this.mode&61440)?this.symlink=a[1]:49152===(this.mode&61440)&&
|
|
264
|
-
new vc;c.set_state(b);this.locks.push(c)}this.status=a[3];this.size=a[4];this.uid=a[5];this.gid=a[6];this.fid=a[7];this.ctime=a[8];this.atime=a[9];this.mtime=a[10];this.qid.type=(this.mode&61440)>>8;this.qid.version=a[11];this.qid.path=a[12];this.nlinks=a[13]};L.prototype.divert=function(a,b){const c=this.Search(a,b),d=this.inodes[c],e=new uc(-1);l(d,"Filesystem divert: name ("+b+") not found");l(this.IsDirectory(c)||1>=d.nlinks,
|
|
265
|
-
Object.assign(e,d);const f=this.inodes.length;this.inodes.push(e);e.fid=f;this.is_forwarder(d)&&this.mounts[d.mount_id].backtrack.set(d.foreign_id,f);this.should_be_linked(d)&&(this.unlink_from_dir(a,b),this.link_under_dir(a,f,b));if(this.IsDirectory(c)&&!this.is_forwarder(d))for(const [g,k]of e.direntries)"."!==g&&".."!==g&&this.IsDirectory(k)&&this.inodes[k].direntries.set("..",f);this.inodedata[f]=this.inodedata[c];delete this.inodedata[c];
|
|
266
|
-
function(a,b){Object.assign(b,a,{fid:b.fid,direntries:b.direntries,nlinks:b.nlinks})};L.prototype.CreateInode=function(){const a=Math.round(Date.now()/1E3),b=new uc(++this.qidcounter.last_qidnumber);b.atime=b.ctime=b.mtime=a;return b};L.prototype.CreateDirectory=function(a,b){var c=this.inodes[b];if(0<=b&&this.is_forwarder(c))return b=c.foreign_id,a=this.follow_fs(c).CreateDirectory(a,b),this.create_forwarder(c.mount_id,a);c=this.CreateInode();
|
|
267
|
-
c.mode=this.inodes[b].mode&511|16384);c.qid.type=64;this.PushInode(c,b,a);this.NotifyListeners(this.inodes.length-1,"newdir");return this.inodes.length-1};L.prototype.CreateFile=function(a,b){var c=this.inodes[b];if(this.is_forwarder(c))return b=c.foreign_id,a=this.follow_fs(c).CreateFile(a,b),this.create_forwarder(c.mount_id,a);c=this.CreateInode();c.uid=this.inodes[b].uid;c.gid=this.inodes[b].gid;c.qid.type=128;c.mode=this.inodes[b].mode&
|
|
268
|
-
1,"newfile");return this.inodes.length-1};L.prototype.CreateNode=function(a,b,c,d){var e=this.inodes[b];if(this.is_forwarder(e))return b=e.foreign_id,a=this.follow_fs(e).CreateNode(a,b,c,d),this.create_forwarder(e.mount_id,a);e=this.CreateInode();e.major=c;e.minor=d;e.uid=this.inodes[b].uid;e.gid=this.inodes[b].gid;e.qid.type=192;e.mode=this.inodes[b].mode&438;this.PushInode(e,b,a);return this.inodes.length-1};L.prototype.CreateSymlink=
|
|
269
|
-
d.foreign_id,a=this.follow_fs(d).CreateSymlink(a,b,c),this.create_forwarder(d.mount_id,a);d=this.CreateInode();d.uid=this.inodes[b].uid;d.gid=this.inodes[b].gid;d.qid.type=160;d.symlink=c;d.mode=40960;this.PushInode(d,b,a);return this.inodes.length-1};L.prototype.CreateTextFile=async function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,c=await this.follow_fs(d).CreateTextFile(a,b,c),this.create_forwarder(d.mount_id,
|
|
270
|
-
b.size=c.length;for(b=0;b<c.length;b++)a[b]=c.charCodeAt(b);await this.set_data(d,a);return d};L.prototype.CreateBinaryFile=async function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,c=await this.follow_fs(d).CreateBinaryFile(a,b,c),this.create_forwarder(d.mount_id,c);d=this.CreateFile(a,b);a=this.inodes[d];b=new Uint8Array(c.length);b.set(c);await this.set_data(d,b);a.size=c.length;return d};L.prototype.OpenInode=
|
|
271
|
-
b);16384===(c.mode&61440)&&this.FillDirectory(a)};L.prototype.CloseInode=async function(a){var b=this.inodes[a];if(this.is_forwarder(b))return await this.follow_fs(b).CloseInode(b.foreign_id);2===b.status&&this.storage.uncache(b.sha256sum);4===b.status&&(b.status=-1,await this.DeleteData(a))};L.prototype.Rename=async function(a,b,c,d){if(a===c&&b===d)return 0;var e=this.Search(a,
|
|
272
|
-
this.inodes[e],m=this.inodes[a];g=this.inodes[c];if(this.is_forwarder(m)||this.is_forwarder(g))if(this.is_forwarder(m)&&m.mount_id===g.mount_id){if(a=await this.follow_fs(m).Rename(m.foreign_id,b,g.foreign_id,d),0>a)return a}else{if(this.is_a_root(e))return B("XXX: Attempted to move mountpoint ("+b+") - skipped",4194304),-1;if(!this.IsDirectory(e)&&1<this.GetInode(e).nlinks)return B("XXX: Attempted to move hardlinked file ("+
|
|
273
|
-
this.GetInode(e),q=await this.Read(m,0,p.size);this.is_forwarder(g)?(c=this.follow_fs(g),d=this.IsDirectory(m)?c.CreateDirectory(d,g.foreign_id):c.CreateFile(d,g.foreign_id),c=c.GetInode(d),this.copy_inode(p,c),this.set_forwarder(e,g.mount_id,d)):(this.delete_forwarder(k),this.copy_inode(p,k),this.link_under_dir(c,e,d));await this.ChangeSize(e,p.size);q&&q.length&&await this.Write(e,0,q.length,q);if(this.IsDirectory(e))for(const r of this.GetChildren(m))if(g=
|
|
274
|
-
await this.DeleteData(m);a=this.Unlink(a,b);if(0>a)return a}else this.unlink_from_dir(a,b),this.link_under_dir(c,e,d),k.qid.version++;this.NotifyListeners(e,"rename",{oldpath:f});return 0};L.prototype.Write=async function(a,b,c,d){this.NotifyListeners(a,"write");var e=this.inodes[a];if(this.is_forwarder(e))a=e.foreign_id,await this.follow_fs(e).Write(a,b,c,d);else{var f=await this.get_buffer(a);!f||f.length<b+c?(await this.ChangeSize(a,Math.floor(3*(b+c)/2)),
|
|
275
|
-
e.size<b+c&&(e.size=b+c);d&&f.set(d.subarray(0,c),b);await this.set_data(a,f)}};L.prototype.Read=async function(a,b,c){const d=this.inodes[a];return this.is_forwarder(d)?(a=d.foreign_id,await this.follow_fs(d).Read(a,b,c)):await this.get_data(a,b,c)};L.prototype.Search=function(a,b){a=this.inodes[a];if(this.is_forwarder(a)){const c=a.foreign_id;b=this.follow_fs(a).Search(c,b);return-1===b?-1:this.get_forwarder(a.mount_id,b)}b=a.direntries.get(b);return void 0===
|
|
276
|
-
function(){let a=this.inodes.length;for(const {fs:b,backtrack:c}of this.mounts)a+=b.CountUsedInodes(),a-=c.size;return a};L.prototype.CountFreeInodes=function(){let a=1048576;for(const {fs:b}of this.mounts)a+=b.CountFreeInodes();return a};L.prototype.GetTotalSize=function(){let a=this.used_size;for(const {fs:b}of this.mounts)a+=b.GetTotalSize();return a};L.prototype.GetSpace=function(){let a=this.total_size;for(const {fs:b}of this.mounts)a+=b.GetSpace();return this.total_size};
|
|
277
|
-
function(a){const b=this.inodes[this.GetParent(a)];if(this.is_forwarder(b))return this.follow_fs(b).GetDirectoryName(this.inodes[a].foreign_id);if(!b)return"";for(const [c,d]of b.direntries)if(d===a)return c;l(!1,"Filesystem: Found directory inode whose parent doesn't link to it");return""};L.prototype.GetFullPath=function(a){l(this.IsDirectory(a),"Filesystem: Cannot get full path of non-directory inode");for(var b="";0!==a;)b="/"+this.GetDirectoryName(a)+b,a=this.GetParent(a);
|
|
278
|
-
L.prototype.Link=function(a,b,c){if(this.IsDirectory(b))return-1;const d=this.inodes[a],e=this.inodes[b];if(this.is_forwarder(d))return this.is_forwarder(e)&&e.mount_id===d.mount_id?this.follow_fs(d).Link(d.foreign_id,e.foreign_id,c):(B("XXX: Attempted to hardlink a file into a child filesystem - skipped",4194304),-1);if(this.is_forwarder(e))return B("XXX: Attempted to hardlink file across filesystems - skipped",4194304),-1;this.link_under_dir(a,b,c);return 0};L.prototype.Unlink=
|
|
279
|
-
b||".."===b)return-1;const c=this.Search(a,b),d=this.inodes[c],e=this.inodes[a];if(this.is_forwarder(e))return l(this.is_forwarder(d),"Children of forwarders should be forwarders"),a=e.foreign_id,this.follow_fs(e).Unlink(a,b);if(this.IsDirectory(c)&&!this.IsEmpty(c))return-39;this.unlink_from_dir(a,b);0===d.nlinks&&(d.status=4,this.NotifyListeners(c,"delete"));return 0};L.prototype.DeleteData=async function(a){const b=this.inodes[a];this.is_forwarder(b)?await this.follow_fs(b).DeleteData(b.foreign_id):
|
|
280
|
-
(b.size=0,delete this.inodedata[a])};L.prototype.get_buffer=async function(a){const b=this.inodes[a];l(b,`Filesystem get_buffer: idx ${a} does not point to an inode`);return this.inodedata[a]?this.inodedata[a]:2===b.status?(l(b.sha256sum,"Filesystem get_data: found inode on server without sha256sum"),await this.storage.read(b.sha256sum,0,b.size)):null};L.prototype.get_data=async function(a,b,c){const d=this.inodes[a];l(d,`Filesystem get_data: idx ${a} does not point to an inode`);return this.inodedata[a]?
|
|
281
|
-
this.inodedata[a].subarray(b,b+c):2===d.status?(l(d.sha256sum,"Filesystem get_data: found inode on server without sha256sum"),await this.storage.read(d.sha256sum,b,c)):null};L.prototype.set_data=async function(a,b){this.inodedata[a]=b;2===this.inodes[a].status&&(this.inodes[a].status=0,this.storage.uncache(this.inodes[a].sha256sum))};L.prototype.GetInode=function(a){l(!isNaN(a),"Filesystem GetInode: NaN idx");l(0<=a&&a<this.inodes.length,"Filesystem GetInode: out of range idx:"+a);a=this.inodes[a];
|
|
251
|
+
this.hub_to_nic_fn),this.channel.close(),this.is_open=!1)};function pc(){this.filedata=new Map}pc.prototype.read=async function(a,b,c){l(a,"MemoryFileStorage read: sha256sum should be a non-empty string");return(a=this.filedata.get(a))?a.subarray(b,b+c):null};pc.prototype.cache=async function(a,b){l(a,"MemoryFileStorage cache: sha256sum should be a non-empty string");this.filedata.set(a,b)};pc.prototype.uncache=function(a){this.filedata.delete(a)};function qc(a,b,c){l(b,"ServerMemoryFileStorage: baseurl should not be empty");
|
|
252
|
+
b.endsWith("/")||(b+="/");this.storage=a;this.baseurl=b;this.zstd_decompress=c}qc.prototype.load_from_server=function(a,b){return new Promise(c=>{ta(this.baseurl+a,{done:async d=>{d=new Uint8Array(d);a.endsWith(".zst")&&(d=new Uint8Array(this.zstd_decompress(b,d)));await this.cache(a,d);c(d)}})})};qc.prototype.read=async function(a,b,c,d){const e=await this.storage.read(a,b,c,d);return e?e:(await this.load_from_server(a,d)).subarray(b,b+c)};qc.prototype.cache=async function(a,b){return await this.storage.cache(a,
|
|
253
|
+
b)};qc.prototype.uncache=function(a){this.storage.uncache(a)};const rc=new TextDecoder,sc=new TextEncoder;function I(a,b,c,d){for(var e,f=0,g=0;g<a.length;g++)switch(e=b[g],a[g]){case "w":c[d++]=e&255;c[d++]=e>>8&255;c[d++]=e>>16&255;c[d++]=e>>24&255;f+=4;break;case "d":c[d++]=e&255;c[d++]=e>>8&255;c[d++]=e>>16&255;c[d++]=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 k=d,m=0;c[d++]=0;c[d++]=0;f+=2;e=
|
|
254
|
+
sc.encode(e);f+=e.byteLength;m+=e.byteLength;c.set(e,d);d+=e.byteLength;c[k+0]=m&255;c[k+1]=m>>8&255;break;case "Q":I(["b","w","d"],[e.type,e.version,e.path],c,d);d+=13;f+=13;break;default:B("Marshall: Unknown type="+a[g])}return f}function J(a,b,c){let d=c.offset;for(var e=[],f=0;f<a.length;f++)switch(a[f]){case "w":var g=b[d++];g+=b[d++]<<8;g+=b[d++]<<16;g+=b[d++]<<24>>>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+
|
|
255
|
+
(b[d++]<<8));break;case "b":e.push(b[d++]);break;case "s":g=b[d++];g+=b[d++]<<8;var k=b.slice(d,d+g);d+=g;e.push(rc.decode(k));break;case "Q":c.offset=d;g=J(["b","w","d"],b,c);d=c.offset;e.push({type:g[0],version:g[1],path:g[2]});break;default:B("Error in Unmarshall: Unknown type="+a[f])}c.offset=d;return e}const tc=new TextEncoder;function L(a,b){this.inodes=[];this.storage=a;this.qidcounter=b||{last_qidnumber:0};this.inodedata={};this.total_size=274877906944;this.used_size=0;this.mounts=[];this.CreateDirectory("",
|
|
256
|
+
-1)}L.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)};L.prototype.set_state=function(a){this.inodes=a[0].map(b=>{const c=new uc(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()),
|
|
257
|
+
this.inodedata[b]=c;this.total_size=a[3];this.used_size=a[4];this.mounts=a.slice(5)};L.prototype.load_from_json=function(a){l(a,"Invalid fs passed to load_from_json");if(3!==a.version)throw"The filesystem JSON format has changed. Please recreate the filesystem JSON.";var b=a.fsroot;this.used_size=a.size;for(a=0;a<b.length;a++)this.LoadRecursive(b[a],0)};L.prototype.LoadRecursive=function(a,b){var c=this.CreateInode();const d=a[0];c.size=a[1];c.mtime=a[2];c.ctime=c.mtime;c.atime=c.mtime;c.mode=a[3];
|
|
258
|
+
c.uid=a[4];c.gid=a[5];var e=c.mode&61440;16384===e?(this.PushInode(c,b,d),this.LoadDir(this.inodes.length-1,a[6])):32768===e?(c.status=2,c.sha256sum=a[6],l(c.sha256sum),this.PushInode(c,b,d)):40960===e?(c.symlink=a[6],this.PushInode(c,b,d)):49152!==e&&B("Unexpected ifmt: "+n(e)+" ("+d+")",4194304)};L.prototype.LoadDir=function(a,b){for(var c=0;c<b.length;c++)this.LoadRecursive(b[c],a)};L.prototype.should_be_linked=function(a){return!this.is_forwarder(a)||0===a.foreign_id};L.prototype.link_under_dir=
|
|
259
|
+
function(a,b,c){const d=this.inodes[b],e=this.inodes[a];l(!this.is_forwarder(e),"Filesystem: Shouldn't link under fowarder parents");l(this.IsDirectory(a),"Filesystem: Can't link under non-directories");l(this.should_be_linked(d),"Filesystem: Can't link across filesystems apart from their root");l(0<=d.nlinks,"Filesystem: Found negative nlinks value of "+d.nlinks);l(!e.direntries.has(c),"Filesystem: Name '"+c+"' is already taken");e.direntries.set(c,b);d.nlinks++;this.IsDirectory(b)&&(l(!d.direntries.has(".."),
|
|
260
|
+
"Filesystem: Cannot link a directory twice"),d.direntries.has(".")||d.nlinks++,d.direntries.set(".",b),d.direntries.set("..",a),e.nlinks++)};L.prototype.unlink_from_dir=function(a,b){const c=this.Search(a,b),d=this.inodes[c],e=this.inodes[a];l(!this.is_forwarder(e),"Filesystem: Can't unlink from forwarders");l(this.IsDirectory(a),"Filesystem: Can't unlink from non-directories");e.direntries.delete(b)?(d.nlinks--,this.IsDirectory(c)&&(l(d.direntries.get("..")===a,"Filesystem: Found directory with bad parent id"),
|
|
261
|
+
d.direntries.delete(".."),e.nlinks--),l(0<=d.nlinks,"Filesystem: Found negative nlinks value of "+d.nlinks)):l(!1,"Filesystem: Can't unlink non-existent file: "+b)};L.prototype.PushInode=function(a,b,c){-1!==b?(this.inodes.push(a),a.fid=this.inodes.length-1,this.link_under_dir(b,a.fid,c)):0===this.inodes.length?(this.inodes.push(a),a.direntries.set(".",0),a.direntries.set("..",0),a.nlinks=2):l(!1,"Error in Filesystem: Pushed inode with name = "+c+" has no parent")};function uc(a){this.direntries=
|
|
262
|
+
new Map;this.minor=this.major=this.mtime=this.atime=this.ctime=this.fid=this.gid=this.uid=this.size=this.status=0;this.symlink="";this.mode=493;this.qid={type:0,version:0,path:a};this.caps=void 0;this.nlinks=0;this.sha256sum="";this.locks=[];this.foreign_id=this.mount_id=-1}uc.prototype.get_state=function(){const a=[];a[0]=this.mode;a[1]=16384===(this.mode&61440)?[...this.direntries]:32768===(this.mode&61440)?this.sha256sum:40960===(this.mode&61440)?this.symlink:49152===(this.mode&61440)?[this.minor,
|
|
263
|
+
this.major]:null;a[2]=this.locks;a[3]=this.status;a[4]=this.size;a[5]=this.uid;a[6]=this.gid;a[7]=this.fid;a[8]=this.ctime;a[9]=this.atime;a[10]=this.mtime;a[11]=this.qid.version;a[12]=this.qid.path;a[13]=this.nlinks;return a};uc.prototype.set_state=function(a){this.mode=a[0];if(16384===(this.mode&61440)){this.direntries=new Map;for(const [b,c]of a[1])this.direntries.set(b,c)}else 32768===(this.mode&61440)?this.sha256sum=a[1]:40960===(this.mode&61440)?this.symlink=a[1]:49152===(this.mode&61440)&&
|
|
264
|
+
([this.minor,this.major]=a[1]);this.locks=[];for(const b of a[2]){const c=new vc;c.set_state(b);this.locks.push(c)}this.status=a[3];this.size=a[4];this.uid=a[5];this.gid=a[6];this.fid=a[7];this.ctime=a[8];this.atime=a[9];this.mtime=a[10];this.qid.type=(this.mode&61440)>>8;this.qid.version=a[11];this.qid.path=a[12];this.nlinks=a[13]};L.prototype.divert=function(a,b){const c=this.Search(a,b),d=this.inodes[c],e=new uc(-1);l(d,"Filesystem divert: name ("+b+") not found");l(this.IsDirectory(c)||1>=d.nlinks,
|
|
265
|
+
"Filesystem: can't divert hardlinked file '"+b+"' with nlinks="+d.nlinks);Object.assign(e,d);const f=this.inodes.length;this.inodes.push(e);e.fid=f;this.is_forwarder(d)&&this.mounts[d.mount_id].backtrack.set(d.foreign_id,f);this.should_be_linked(d)&&(this.unlink_from_dir(a,b),this.link_under_dir(a,f,b));if(this.IsDirectory(c)&&!this.is_forwarder(d))for(const [g,k]of e.direntries)"."!==g&&".."!==g&&this.IsDirectory(k)&&this.inodes[k].direntries.set("..",f);this.inodedata[f]=this.inodedata[c];delete this.inodedata[c];
|
|
266
|
+
d.direntries=new Map;d.nlinks=0;return f};L.prototype.copy_inode=function(a,b){Object.assign(b,a,{fid:b.fid,direntries:b.direntries,nlinks:b.nlinks})};L.prototype.CreateInode=function(){const a=Math.round(Date.now()/1E3),b=new uc(++this.qidcounter.last_qidnumber);b.atime=b.ctime=b.mtime=a;return b};L.prototype.CreateDirectory=function(a,b){var c=this.inodes[b];if(0<=b&&this.is_forwarder(c))return b=c.foreign_id,a=this.follow_fs(c).CreateDirectory(a,b),this.create_forwarder(c.mount_id,a);c=this.CreateInode();
|
|
267
|
+
c.mode=16895;0<=b&&(c.uid=this.inodes[b].uid,c.gid=this.inodes[b].gid,c.mode=this.inodes[b].mode&511|16384);c.qid.type=64;this.PushInode(c,b,a);this.NotifyListeners(this.inodes.length-1,"newdir");return this.inodes.length-1};L.prototype.CreateFile=function(a,b){var c=this.inodes[b];if(this.is_forwarder(c))return b=c.foreign_id,a=this.follow_fs(c).CreateFile(a,b),this.create_forwarder(c.mount_id,a);c=this.CreateInode();c.uid=this.inodes[b].uid;c.gid=this.inodes[b].gid;c.qid.type=128;c.mode=this.inodes[b].mode&
|
|
268
|
+
438|32768;this.PushInode(c,b,a);this.NotifyListeners(this.inodes.length-1,"newfile");return this.inodes.length-1};L.prototype.CreateNode=function(a,b,c,d){var e=this.inodes[b];if(this.is_forwarder(e))return b=e.foreign_id,a=this.follow_fs(e).CreateNode(a,b,c,d),this.create_forwarder(e.mount_id,a);e=this.CreateInode();e.major=c;e.minor=d;e.uid=this.inodes[b].uid;e.gid=this.inodes[b].gid;e.qid.type=192;e.mode=this.inodes[b].mode&438;this.PushInode(e,b,a);return this.inodes.length-1};L.prototype.CreateSymlink=
|
|
269
|
+
function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,a=this.follow_fs(d).CreateSymlink(a,b,c),this.create_forwarder(d.mount_id,a);d=this.CreateInode();d.uid=this.inodes[b].uid;d.gid=this.inodes[b].gid;d.qid.type=160;d.symlink=c;d.mode=40960;this.PushInode(d,b,a);return this.inodes.length-1};L.prototype.CreateTextFile=async function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,c=await this.follow_fs(d).CreateTextFile(a,b,c),this.create_forwarder(d.mount_id,
|
|
270
|
+
c);d=this.CreateFile(a,b);b=this.inodes[d];a=new Uint8Array(c.length);b.size=c.length;for(b=0;b<c.length;b++)a[b]=c.charCodeAt(b);await this.set_data(d,a);return d};L.prototype.CreateBinaryFile=async function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,c=await this.follow_fs(d).CreateBinaryFile(a,b,c),this.create_forwarder(d.mount_id,c);d=this.CreateFile(a,b);a=this.inodes[d];b=new Uint8Array(c.length);b.set(c);await this.set_data(d,b);a.size=c.length;return d};L.prototype.OpenInode=
|
|
271
|
+
async function(a,b){var c=this.inodes[a];if(this.is_forwarder(c))return await this.follow_fs(c).OpenInode(c.foreign_id,b);16384===(c.mode&61440)&&this.FillDirectory(a)};L.prototype.CloseInode=async function(a){var b=this.inodes[a];if(this.is_forwarder(b))return await this.follow_fs(b).CloseInode(b.foreign_id);2===b.status&&this.storage.uncache(b.sha256sum);4===b.status&&(b.status=-1,await this.DeleteData(a))};L.prototype.Rename=async function(a,b,c,d){if(a===c&&b===d)return 0;var e=this.Search(a,
|
|
272
|
+
b);if(-1===e)return-2;var f=this.GetFullPath(a)+"/"+b;if(-1!==this.Search(c,d)){var g=this.Unlink(c,d);if(0>g)return g}var k=this.inodes[e],m=this.inodes[a];g=this.inodes[c];if(this.is_forwarder(m)||this.is_forwarder(g))if(this.is_forwarder(m)&&m.mount_id===g.mount_id){if(a=await this.follow_fs(m).Rename(m.foreign_id,b,g.foreign_id,d),0>a)return a}else{if(this.is_a_root(e))return B("XXX: Attempted to move mountpoint ("+b+") - skipped",4194304),-1;if(!this.IsDirectory(e)&&1<this.GetInode(e).nlinks)return B("XXX: Attempted to move hardlinked file ("+
|
|
273
|
+
b+") across filesystems - skipped",4194304),-1;m=this.divert(a,b);const p=this.GetInode(e),q=await this.Read(m,0,p.size);this.is_forwarder(g)?(c=this.follow_fs(g),d=this.IsDirectory(m)?c.CreateDirectory(d,g.foreign_id):c.CreateFile(d,g.foreign_id),c=c.GetInode(d),this.copy_inode(p,c),this.set_forwarder(e,g.mount_id,d)):(this.delete_forwarder(k),this.copy_inode(p,k),this.link_under_dir(c,e,d));await this.ChangeSize(e,p.size);q&&q.length&&await this.Write(e,0,q.length,q);if(this.IsDirectory(e))for(const r of this.GetChildren(m))if(g=
|
|
274
|
+
await this.Rename(m,r,e,r),0>g)return g;await this.DeleteData(m);a=this.Unlink(a,b);if(0>a)return a}else this.unlink_from_dir(a,b),this.link_under_dir(c,e,d),k.qid.version++;this.NotifyListeners(e,"rename",{oldpath:f});return 0};L.prototype.Write=async function(a,b,c,d){this.NotifyListeners(a,"write");var e=this.inodes[a];if(this.is_forwarder(e))a=e.foreign_id,await this.follow_fs(e).Write(a,b,c,d);else{var f=await this.get_buffer(a);!f||f.length<b+c?(await this.ChangeSize(a,Math.floor(3*(b+c)/2)),
|
|
275
|
+
e.size=b+c,f=await this.get_buffer(a)):e.size<b+c&&(e.size=b+c);d&&f.set(d.subarray(0,c),b);await this.set_data(a,f)}};L.prototype.Read=async function(a,b,c){const d=this.inodes[a];return this.is_forwarder(d)?(a=d.foreign_id,await this.follow_fs(d).Read(a,b,c)):await this.get_data(a,b,c)};L.prototype.Search=function(a,b){a=this.inodes[a];if(this.is_forwarder(a)){const c=a.foreign_id;b=this.follow_fs(a).Search(c,b);return-1===b?-1:this.get_forwarder(a.mount_id,b)}b=a.direntries.get(b);return void 0===
|
|
276
|
+
b?-1:b};L.prototype.CountUsedInodes=function(){let a=this.inodes.length;for(const {fs:b,backtrack:c}of this.mounts)a+=b.CountUsedInodes(),a-=c.size;return a};L.prototype.CountFreeInodes=function(){let a=1048576;for(const {fs:b}of this.mounts)a+=b.CountFreeInodes();return a};L.prototype.GetTotalSize=function(){let a=this.used_size;for(const {fs:b}of this.mounts)a+=b.GetTotalSize();return a};L.prototype.GetSpace=function(){let a=this.total_size;for(const {fs:b}of this.mounts)a+=b.GetSpace();return this.total_size};
|
|
277
|
+
L.prototype.GetDirectoryName=function(a){const b=this.inodes[this.GetParent(a)];if(this.is_forwarder(b))return this.follow_fs(b).GetDirectoryName(this.inodes[a].foreign_id);if(!b)return"";for(const [c,d]of b.direntries)if(d===a)return c;l(!1,"Filesystem: Found directory inode whose parent doesn't link to it");return""};L.prototype.GetFullPath=function(a){l(this.IsDirectory(a),"Filesystem: Cannot get full path of non-directory inode");for(var b="";0!==a;)b="/"+this.GetDirectoryName(a)+b,a=this.GetParent(a);
|
|
278
|
+
return b.substring(1)};L.prototype.Link=function(a,b,c){if(this.IsDirectory(b))return-1;const d=this.inodes[a],e=this.inodes[b];if(this.is_forwarder(d))return this.is_forwarder(e)&&e.mount_id===d.mount_id?this.follow_fs(d).Link(d.foreign_id,e.foreign_id,c):(B("XXX: Attempted to hardlink a file into a child filesystem - skipped",4194304),-1);if(this.is_forwarder(e))return B("XXX: Attempted to hardlink file across filesystems - skipped",4194304),-1;this.link_under_dir(a,b,c);return 0};L.prototype.Unlink=
|
|
279
|
+
function(a,b){if("."===b||".."===b)return-1;const c=this.Search(a,b),d=this.inodes[c],e=this.inodes[a];if(this.is_forwarder(e))return l(this.is_forwarder(d),"Children of forwarders should be forwarders"),a=e.foreign_id,this.follow_fs(e).Unlink(a,b);if(this.IsDirectory(c)&&!this.IsEmpty(c))return-39;this.unlink_from_dir(a,b);0===d.nlinks&&(d.status=4,this.NotifyListeners(c,"delete"));return 0};L.prototype.DeleteData=async function(a){const b=this.inodes[a];this.is_forwarder(b)?await this.follow_fs(b).DeleteData(b.foreign_id):
|
|
280
|
+
(b.size=0,delete this.inodedata[a])};L.prototype.get_buffer=async function(a){const b=this.inodes[a];l(b,`Filesystem get_buffer: idx ${a} does not point to an inode`);return this.inodedata[a]?this.inodedata[a]:2===b.status?(l(b.sha256sum,"Filesystem get_data: found inode on server without sha256sum"),await this.storage.read(b.sha256sum,0,b.size,b.size)):null};L.prototype.get_data=async function(a,b,c){const d=this.inodes[a];l(d,`Filesystem get_data: idx ${a} does not point to an inode`);return this.inodedata[a]?
|
|
281
|
+
this.inodedata[a].subarray(b,b+c):2===d.status?(l(d.sha256sum,"Filesystem get_data: found inode on server without sha256sum"),await this.storage.read(d.sha256sum,b,c,d.size)):null};L.prototype.set_data=async function(a,b){this.inodedata[a]=b;2===this.inodes[a].status&&(this.inodes[a].status=0,this.storage.uncache(this.inodes[a].sha256sum))};L.prototype.GetInode=function(a){l(!isNaN(a),"Filesystem GetInode: NaN idx");l(0<=a&&a<this.inodes.length,"Filesystem GetInode: out of range idx:"+a);a=this.inodes[a];
|
|
282
282
|
return this.is_forwarder(a)?this.follow_fs(a).GetInode(a.foreign_id):a};L.prototype.ChangeSize=async function(a,b){var c=this.GetInode(a),d=await this.get_data(a,0,c.size);if(b!==c.size){var e=new Uint8Array(b);c.size=b;d&&e.set(d.subarray(0,Math.min(d.length,c.size)),0);await this.set_data(a,e)}};L.prototype.SearchPath=function(a){a=a.replace("//","/");a=a.split("/");0<a.length&&0===a[a.length-1].length&&a.pop();0<a.length&&0===a[0].length&&a.shift();const b=a.length;var c=-1,d=0;let e=null;for(var f=
|
|
283
283
|
0;f<b;f++)if(c=d,d=this.Search(c,a[f]),!e&&this.is_forwarder(this.inodes[c])&&(e="/"+a.slice(f).join("/")),-1===d)return f<b-1?{id:-1,parentid:-1,name:a[f],forward_path:e}:{id:-1,parentid:c,name:a[f],forward_path:e};return{id:d,parentid:c,name:a[f],forward_path:e}};L.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=
|
|
284
284
|
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))};L.prototype.RecursiveDelete=function(a){var b=[];a=this.SearchPath(a);if(-1!==a.id)for(this.GetRecursiveList(a.id,b),a=b.length-1;0<=a;a--){const c=this.Unlink(b[a].parentid,b[a].name);l(0===c,"Filesystem RecursiveDelete failed at parent="+b[a].parentid+", name='"+b[a].name+"' with error code: "+-c)}};L.prototype.DeleteNode=
|
|
@@ -311,8 +311,8 @@ b.preserve_mac_from_state_image;e.mac_address_translation=b.mac_address_translat
|
|
|
311
311
|
this.bus);e.net_device=b.net_device||{type:"ne2k"};f=b.screen||{};b.screen_container&&(f.container=b.screen_container);b.disable_keyboard||(this.keyboard_adapter=new dc(this.bus));b.disable_mouse||(this.mouse_adapter=new ec(this.bus,f.container));this.screen_adapter=f.container?new Aa(f,()=>this.v86.cpu.devices.vga&&this.v86.cpu.devices.vga.screen_fill_buffer()):new fc(f);e.screen=this.screen_adapter;e.screen_options=f;b.serial_container_xtermjs?this.serial_adapter=new nc(b.serial_container_xtermjs,
|
|
312
312
|
this.bus):b.serial_container&&(this.serial_adapter=new mc(b.serial_container,this.bus));b.disable_speaker||(this.speaker_adapter=new mb(this.bus));var g=[];f=(v,t)=>{if(t)if(t.get&&t.set&&t.load)g.push({name:v,loadable:t});else{if("bios"===v||"vga_bios"===v||"initial_state"===v||"multiboot"===v||"bzimage"===v||"initrd"===v)t.async=!1;if("fda"===v||"fdb"===v)t.async=!1;t.url&&!t.async?g.push({name:v,url:t.url,size:t.size}):g.push({name:v,loadable:Ga(t,this.zstd_decompress_worker.bind(this))})}};b.state&&
|
|
313
313
|
console.warn("Warning: Unknown option 'state'. Did you mean 'initial_state'?");f("bios",b.bios);f("vga_bios",b.vga_bios);f("cdrom",b.cdrom);f("hda",b.hda);f("hdb",b.hdb);f("fda",b.fda);f("fdb",b.fdb);f("initial_state",b.initial_state);f("multiboot",b.multiboot);f("bzimage",b.bzimage);f("initrd",b.initrd);if(b.filesystem&&b.filesystem.handle9p)e.handle9p=b.filesystem.handle9p;else if(b.filesystem&&b.filesystem.proxy_url)e.proxy9p=b.filesystem.proxy_url;else if(b.filesystem){f=b.filesystem.basefs;var k=
|
|
314
|
-
b.filesystem.baseurl;let v=new pc;k&&(v=new qc(v,k));e.fs9p=this.fs9p=new L(v);if(f){l(k,"Filesystem: baseurl must be specified");if("object"===typeof f){var m=f.size;f=f.url}l("string"===typeof f);g.push({name:"fs9p_json",url:f,size:m,as_json:!0})}}var p=this,q=g.length,r=function(v){if(v===q)setTimeout(d.bind(this),0);else{var t=g[v];t.loadable?(t.loadable.onload=function(){c.call(this,t.name,t.loadable);r(v+1)}.bind(this),t.loadable.load()):ta(t.url,{done:function(z){t.url.endsWith(".zst")&&
|
|
315
|
-
t.name&&(l(t.size,"A size must be provided for compressed images"),z=this.zstd_decompress(t.size,new Uint8Array(z)));c.call(this,t.name,t.as_json?z:new Ba(z));r(v+1)}.bind(this),progress:function(z){200===z.target.status?p.emulator_bus.send("download-progress",{file_index:v,file_count:q,file_name:t.url,lengthComputable:z.lengthComputable,total:z.total||t.size,loaded:z.loaded}):p.emulator_bus.send("download-error",{file_index:v,file_count:q,file_name:t.url,request:z.target})},as_json:t.as_json})}}.bind(this);
|
|
314
|
+
b.filesystem.baseurl;let v=new pc;k&&(v=new qc(v,k,this.zstd_decompress.bind(this)));e.fs9p=this.fs9p=new L(v);if(f){l(k,"Filesystem: baseurl must be specified");if("object"===typeof f){var m=f.size;f=f.url}l("string"===typeof f);g.push({name:"fs9p_json",url:f,size:m,as_json:!0})}}var p=this,q=g.length,r=function(v){if(v===q)setTimeout(d.bind(this),0);else{var t=g[v];t.loadable?(t.loadable.onload=function(){c.call(this,t.name,t.loadable);r(v+1)}.bind(this),t.loadable.load()):ta(t.url,{done:function(z){t.url.endsWith(".zst")&&
|
|
315
|
+
"initial_state"!==t.name&&(l(t.size,"A size must be provided for compressed images"),z=this.zstd_decompress(t.size,new Uint8Array(z)));c.call(this,t.name,t.as_json?z:new Ba(z));r(v+1)}.bind(this),progress:function(z){200===z.target.status?p.emulator_bus.send("download-progress",{file_index:v,file_count:q,file_name:t.url,lengthComputable:z.lengthComputable,total:z.total||t.size,loaded:z.loaded}):p.emulator_bus.send("download-error",{file_index:v,file_count:q,file_name:t.url,request:z.target})},as_json:t.as_json})}}.bind(this);
|
|
316
316
|
r(0)};N.prototype.zstd_decompress=function(a,b){const c=this.v86.cpu;l(!this.zstd_context);this.zstd_context=c.zstd_create_ctx(b.length);(new Uint8Array(c.wasm_memory.buffer)).set(b,c.zstd_get_src_ptr(this.zstd_context));b=c.zstd_read(this.zstd_context,a);const d=c.wasm_memory.buffer.slice(b,b+a);c.zstd_read_free(b,a);c.zstd_free_ctx(this.zstd_context);this.zstd_context=null;return d};N.prototype.zstd_decompress_worker=async function(a,b){if(!this.zstd_worker){const c=URL.createObjectURL(new Blob(["("+
|
|
317
317
|
function(){let d;globalThis.onmessage=function(e){if(d){var {src:f,decompressed_size:g,id:k}=e.data;e=d.exports;var m=e.zstd_create_ctx(f.length);(new Uint8Array(e.memory.buffer)).set(f,e.zstd_get_src_ptr(m));var p=e.zstd_read(m,g),q=e.memory.buffer.slice(p,p+g);e.zstd_read_free(p,g);e.zstd_free_ctx(m);postMessage({result:q,id:k},[q])}else m=Object.fromEntries("cpu_exception_hook run_hardware_timers cpu_event_halt microtick get_rand_int stop_idling io_port_read8 io_port_read16 io_port_read32 io_port_write8 io_port_write16 io_port_write32 mmap_read8 mmap_read16 mmap_read32 mmap_write8 mmap_write16 mmap_write32 mmap_write64 mmap_write128 codegen_finalize jit_clear_func jit_clear_all_funcs".split(" ").map(r=>
|
|
318
318
|
[r,()=>console.error("zstd worker unexpectedly called "+r)])),m.__indirect_function_table=new WebAssembly.Table({element:"anyfunc",initial:1024}),m.abort=()=>{throw Error("zstd worker aborted");},m.log_from_wasm=m.console_log_from_wasm=(r,v)=>{console.log(va(d.exports.memory.buffer,r,v))},m.dbg_trace_from_wasm=()=>console.trace(),d=new WebAssembly.Instance(new WebAssembly.Module(e.data),{env:m})}}.toString()+")()"],{type:"text/javascript"}));this.zstd_worker=new Worker(c);URL.revokeObjectURL(c);this.zstd_worker.postMessage(this.wasm_source,
|
package/build/libv86.js
CHANGED
|
@@ -118,9 +118,9 @@ C.prototype.dac_send=function(){if(this.dac_buffers[0].length){var a=this.dac_bu
|
|
|
118
118
|
function cb(a,b){if("object"!==typeof a||null===a)return a;if(Array.isArray(a))return a.map(e=>cb(e,b));a.constructor===Object&&console.log(a);if(a.BYTES_PER_ELEMENT){var c=new Uint8Array(a.buffer,a.byteOffset,a.length*a.BYTES_PER_ELEMENT);return{__state_type__:a.constructor.name.replace("bound ",""),buffer_id:b.push(c)-1}}a=a.get_state();c=[];for(var d=0;d<a.length;d++)c[d]=cb(a[d],b);return c}
|
|
119
119
|
function db(a,b){if("object"!==typeof a||null===a)return a;if(Array.isArray(a)){for(let c=0;c<a.length;c++)a[c]=db(a[c],b);return a}return new bb[a.__state_type__](b[a.buffer_id])}
|
|
120
120
|
function eb(a,b){function c(q,r){const x=q.length;if(16>x)throw new ab("Invalid length: "+x);q=new Int32Array(q.buffer,q.byteOffset,4);if(-2039052682!==q[0])throw new ab("Invalid header: "+z(q[0]>>>0));if(6!==q[1])throw new ab("Version mismatch: dump="+q[1]+" we=6");if(r&&q[2]!==x)throw new ab("Length doesn't match header: real="+x+" header="+q[2]);return q[3]}function d(q){q=(new TextDecoder).decode(q);return JSON.parse(q)}b=new Uint8Array(b);if(4247762216===(new Uint32Array(b.buffer,0,1))[0]){var e=
|
|
121
|
-
a.zstd_create_ctx(b.length);(new Uint8Array(a.wasm_memory.buffer,a.zstd_get_src_ptr(e),b.length)).set(b);var f=a.zstd_read(e,16),g=new Uint8Array(a.wasm_memory.buffer,f,16),h=c(g,!1);a.zstd_read_free(f,16);f=a.zstd_read(e,h);g=new Uint8Array(a.wasm_memory.buffer,f,h);g=d(g);a.zstd_read_free(f,h);f=g.state;var l=g.buffer_infos;g=[];h=16+h;for(var m of l){l=(h+3&-4)-h;if(1048576<m.length){var n=a.zstd_read(e,l);a.zstd_read_free(n,l);n=new Uint8Array(m.length);g.push(n.buffer);for(var p=
|
|
122
|
-
Math.min(m.length-p,1048576),r=a.zstd_read(e,q);n.set(new Uint8Array(a.wasm_memory.buffer,r,q),p);a.zstd_read_free(r,q);p+=q}}else n=a.zstd_read(e,l+m.length),p=n+l,g.push(a.wasm_memory.buffer.slice(p,p+m.length)),a.zstd_read_free(n,l+m.length);h+=l+m.length}f=db(f,g);a.set_state(f);a.zstd_free_ctx(e)}else{e=c(b,!0);if(0>e||e+12>=b.length)throw new ab("Invalid info block length: "+e);m=b.subarray(16,16+e);f=d(m);m=f.state;f=f.buffer_infos;let q=16+e;q=q+3&-4;e=f.map(r=>
|
|
123
|
-
x+r.length)});m=db(m,e);a.set_state(m)}};function fb(a,b,c,d,e){let f="";var g=[],h=b?"compiled":c?"jit exit":d?"unguarded register":e?"wasm size":"executed";for(let n=0;256>n;n++)for(let p=0;8>p;p++)for(const q of[!1,!0]){var l=a.wm.exports.get_opstats_buffer(b,c,d,e,n,!1,q,p);g.push({opcode:n,count:l,is_mem:q,fixed_g:p});l=a.wm.exports.get_opstats_buffer(b,c,d,e,n,!0,q,p);g.push({opcode:3840|n,count:l,is_mem:q,fixed_g:p})}a=0;b=new Set([38,46,54,62,100,101,102,103,240,242,243]);for(const {count:n,opcode:p}of g)b.has(p)||(a+=n);if(0===
|
|
121
|
+
a.zstd_create_ctx(b.length);(new Uint8Array(a.wasm_memory.buffer,a.zstd_get_src_ptr(e)>>>0,b.length)).set(b);var f=a.zstd_read(e,16),g=new Uint8Array(a.wasm_memory.buffer,f>>>0,16),h=c(g,!1);a.zstd_read_free(f,16);f=a.zstd_read(e,h);g=new Uint8Array(a.wasm_memory.buffer,f>>>0,h);g=d(g);a.zstd_read_free(f,h);f=g.state;var l=g.buffer_infos;g=[];h=16+h;for(var m of l){l=(h+3&-4)-h;if(1048576<m.length){var n=a.zstd_read(e,l)>>>0;a.zstd_read_free(n,l);n=new Uint8Array(m.length);g.push(n.buffer);for(var p=
|
|
122
|
+
0;p<m.length;){const q=Math.min(m.length-p,1048576),r=a.zstd_read(e,q);n.set(new Uint8Array(a.wasm_memory.buffer,r>>>0,q),p);a.zstd_read_free(r,q);p+=q}}else n=a.zstd_read(e,l+m.length),p=(n>>>0)+l,g.push(a.wasm_memory.buffer.slice(p,p+m.length)),a.zstd_read_free(n,l+m.length);h+=l+m.length}f=db(f,g);a.set_state(f);a.zstd_free_ctx(e)}else{e=c(b,!0);if(0>e||e+12>=b.length)throw new ab("Invalid info block length: "+e);m=b.subarray(16,16+e);f=d(m);m=f.state;f=f.buffer_infos;let q=16+e;q=q+3&-4;e=f.map(r=>
|
|
123
|
+
{const x=q+r.offset;return b.buffer.slice(x,x+r.length)});m=db(m,e);a.set_state(m)}};function fb(a,b,c,d,e){let f="";var g=[],h=b?"compiled":c?"jit exit":d?"unguarded register":e?"wasm size":"executed";for(let n=0;256>n;n++)for(let p=0;8>p;p++)for(const q of[!1,!0]){var l=a.wm.exports.get_opstats_buffer(b,c,d,e,n,!1,q,p);g.push({opcode:n,count:l,is_mem:q,fixed_g:p});l=a.wm.exports.get_opstats_buffer(b,c,d,e,n,!0,q,p);g.push({opcode:3840|n,count:l,is_mem:q,fixed_g:p})}a=0;b=new Set([38,46,54,62,100,101,102,103,240,242,243]);for(const {count:n,opcode:p}of g)b.has(p)||(a+=n);if(0===
|
|
124
124
|
a)return"";c=new Uint32Array(256);b=new Uint32Array(256);for(const {opcode:n,count:p}of g)3840===(n&65280)?b[n&255]+=p:c[n&255]+=p;f=f+"------------------\nTotal: "+(a+"\n");const m=1E7<a?1E3:1;d=Math.max.apply(Math,g.map(({count:n})=>Math.round(n/m)));d=String(d).length;f+=`Instruction counts ${h} (in ${m}):\n`;for(e=0;256>e;e++)f+=e.toString(16).padStart(2,"0")+":"+aa(Math.round(c[e]/m),d),f=15===e%16?f+"\n":f+" ";f=f+"\n"+`Instruction counts ${h} (0f, in ${m}):\n`;for(h=0;256>h;h++)f+=(h&255).toString(16).padStart(2,
|
|
125
125
|
"0")+":"+aa(Math.round(b[h]/m),d),f=15===h%16?f+"\n":f+" ";f+="\n";g=g.filter(({count:n})=>n).sort(({count:n},{count:p})=>p-n);for(const {opcode:n,is_mem:p,fixed_g:q,count:r}of g.slice(0,200))g=n.toString(16)+"_"+q+(p?"_m":"_r"),f+=g+":"+(r/a*100).toFixed(2)+" ";return f+"\n"};function gb(a){this.cpu=a;this.cmos_index=0;this.cmos_data=new Uint8Array(128);this.last_update=this.rtc_time=Date.now();this.next_interrupt_alarm=this.next_interrupt=0;this.periodic_interrupt=!1;this.periodic_interrupt_time=.9765625;this.cmos_a=38;this.cmos_b=2;this.nmi_disabled=this.cmos_diag_status=this.cmos_c=0;this.update_interrupt=!1;this.update_interrupt_time=0;a.io.register_write(112,this,function(b){this.cmos_index=b&127;this.nmi_disabled=b>>7});a.io.register_write(113,this,this.cmos_port_write);
|
|
126
126
|
a.io.register_read(113,this,this.cmos_port_read)}gb.prototype.get_state=function(){var a=[];a[0]=this.cmos_index;a[1]=this.cmos_data;a[2]=this.rtc_time;a[3]=this.last_update;a[4]=this.next_interrupt;a[5]=this.next_interrupt_alarm;a[6]=this.periodic_interrupt;a[7]=this.periodic_interrupt_time;a[8]=this.cmos_a;a[9]=this.cmos_b;a[10]=this.cmos_c;a[11]=this.nmi_disabled;a[12]=this.update_interrupt;a[13]=this.update_interrupt_time;a[14]=this.cmos_diag_status;return a};
|
|
@@ -247,8 +247,8 @@ function(h){h=String.fromCharCode(h);this.show_char(h)},this);this.destroy=funct
|
|
|
247
247
|
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=
|
|
248
248
|
!1,a.scrollTop=1E9)};this.send_char=function(h){g.bus&&g.bus.send("serial0-input",h)}}
|
|
249
249
|
function ic(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=new TextEncoder,e=c.onData(function(f){for(const g of d.encode(f))b.send("serial0-input",g)});b.register("serial0-output-byte",function(f){c.write(Uint8Array.of(f))},this);this.destroy=function(){e.dispose();c.dispose()}}}ic.prototype.show=function(){this.term&&this.term.open(this.element)};function jc(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)}
|
|
250
|
-
jc.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 kc(){this.filedata=new Map}kc.prototype.read=async function(a,b,c){return(a=this.filedata.get(a))?a.subarray(b,b+c):null};kc.prototype.cache=async function(a,b){this.filedata.set(a,b)};kc.prototype.uncache=function(a){this.filedata.delete(a)};function lc(a,b){b.endsWith("/")||(b+="/");this.storage=a;this.baseurl=b
|
|
251
|
-
lc.prototype.read=async function(a,b,c){const
|
|
250
|
+
jc.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 kc(){this.filedata=new Map}kc.prototype.read=async function(a,b,c){return(a=this.filedata.get(a))?a.subarray(b,b+c):null};kc.prototype.cache=async function(a,b){this.filedata.set(a,b)};kc.prototype.uncache=function(a){this.filedata.delete(a)};function lc(a,b,c){b.endsWith("/")||(b+="/");this.storage=a;this.baseurl=b;this.zstd_decompress=c}
|
|
251
|
+
lc.prototype.load_from_server=function(a,b){return new Promise(c=>{oa(this.baseurl+a,{done:async d=>{d=new Uint8Array(d);a.endsWith(".zst")&&(d=new Uint8Array(this.zstd_decompress(b,d)));await this.cache(a,d);c(d)}})})};lc.prototype.read=async function(a,b,c,d){const e=await this.storage.read(a,b,c,d);return e?e:(await this.load_from_server(a,d)).subarray(b,b+c)};lc.prototype.cache=async function(a,b){return await this.storage.cache(a,b)};lc.prototype.uncache=function(a){this.storage.uncache(a)};const mc=new TextDecoder,nc=new TextEncoder;
|
|
252
252
|
function F(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=nc.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;
|
|
253
253
|
case "Q":F(["b","w","d"],[e.type,e.version,e.path],c,d),d+=13,f+=13}return f}
|
|
254
254
|
function I(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(mc.decode(h));break;case "Q":c.offset=d,g=I(["b","w","d"],b,c),d=c.offset,e.push({type:g[0],version:g[1],path:g[2]})}c.offset=
|
|
@@ -280,8 +280,8 @@ J.prototype.CountUsedInodes=function(){let a=this.inodes.length;for(const {fs:b,
|
|
|
280
280
|
J.prototype.GetDirectoryName=function(a){const b=this.inodes[this.GetParent(a)];if(this.is_forwarder(b))return this.follow_fs(b).GetDirectoryName(this.inodes[a].foreign_id);if(!b)return"";for(const [c,d]of b.direntries)if(d===a)return c;return""};J.prototype.GetFullPath=function(a){this.IsDirectory(a);for(var b="";0!==a;)b="/"+this.GetDirectoryName(a)+b,a=this.GetParent(a);return b.substring(1)};
|
|
281
281
|
J.prototype.Link=function(a,b,c){if(this.IsDirectory(b))return-1;const d=this.inodes[a],e=this.inodes[b];if(this.is_forwarder(d))return this.is_forwarder(e)&&e.mount_id===d.mount_id?this.follow_fs(d).Link(d.foreign_id,e.foreign_id,c):-1;if(this.is_forwarder(e))return-1;this.link_under_dir(a,b,c);return 0};
|
|
282
282
|
J.prototype.Unlink=function(a,b){if("."===b||".."===b)return-1;const c=this.Search(a,b),d=this.inodes[c],e=this.inodes[a];if(this.is_forwarder(e))return this.is_forwarder(d),a=e.foreign_id,this.follow_fs(e).Unlink(a,b);if(this.IsDirectory(c)&&!this.IsEmpty(c))return-39;this.unlink_from_dir(a,b);0===d.nlinks&&(d.status=4,this.NotifyListeners(c,"delete"));return 0};
|
|
283
|
-
J.prototype.DeleteData=async function(a){const b=this.inodes[a];this.is_forwarder(b)?await this.follow_fs(b).DeleteData(b.foreign_id):(b.size=0,delete this.inodedata[a])};J.prototype.get_buffer=async function(a){const b=this.inodes[a];return this.inodedata[a]?this.inodedata[a]:2===b.status?await this.storage.read(b.sha256sum,0,b.size):null};
|
|
284
|
-
J.prototype.get_data=async function(a,b,c){const d=this.inodes[a];return this.inodedata[a]?this.inodedata[a].subarray(b,b+c):2===d.status?await this.storage.read(d.sha256sum,b,c):null};J.prototype.set_data=async function(a,b){this.inodedata[a]=b;2===this.inodes[a].status&&(this.inodes[a].status=0,this.storage.uncache(this.inodes[a].sha256sum))};J.prototype.GetInode=function(a){isNaN(a);a=this.inodes[a];return this.is_forwarder(a)?this.follow_fs(a).GetInode(a.foreign_id):a};
|
|
283
|
+
J.prototype.DeleteData=async function(a){const b=this.inodes[a];this.is_forwarder(b)?await this.follow_fs(b).DeleteData(b.foreign_id):(b.size=0,delete this.inodedata[a])};J.prototype.get_buffer=async function(a){const b=this.inodes[a];return this.inodedata[a]?this.inodedata[a]:2===b.status?await this.storage.read(b.sha256sum,0,b.size,b.size):null};
|
|
284
|
+
J.prototype.get_data=async function(a,b,c){const d=this.inodes[a];return this.inodedata[a]?this.inodedata[a].subarray(b,b+c):2===d.status?await this.storage.read(d.sha256sum,b,c,d.size):null};J.prototype.set_data=async function(a,b){this.inodedata[a]=b;2===this.inodes[a].status&&(this.inodes[a].status=0,this.storage.uncache(this.inodes[a].sha256sum))};J.prototype.GetInode=function(a){isNaN(a);a=this.inodes[a];return this.is_forwarder(a)?this.follow_fs(a).GetInode(a.foreign_id):a};
|
|
285
285
|
J.prototype.ChangeSize=async function(a,b){var c=this.GetInode(a),d=await this.get_data(a,0,c.size);if(b!==c.size){var e=new Uint8Array(b);c.size=b;d&&e.set(d.subarray(0,Math.min(d.length,c.size)),0);await this.set_data(a,e)}};
|
|
286
286
|
J.prototype.SearchPath=function(a){a=a.replace("//","/");a=a.split("/");0<a.length&&0===a[a.length-1].length&&a.pop();0<a.length&&0===a[0].length&&a.shift();const b=a.length;var c=-1,d=0;let e=null;for(var f=0;f<b;f++)if(c=d,d=this.Search(c,a[f]),!e&&this.is_forwarder(this.inodes[c])&&(e="/"+a.slice(f).join("/")),-1===d)return f<b-1?{id:-1,parentid:-1,name:a[f],forward_path:e}:{id:-1,parentid:c,name:a[f],forward_path:e};return{id:d,parentid:c,name:a[f],forward_path:e}};
|
|
287
287
|
J.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))};
|
|
@@ -312,9 +312,9 @@ fdb:void 0,hda:void 0,hdb:void 0,cdrom:void 0};var f=b.boot_order?b.boot_order:b
|
|
|
312
312
|
b.cpuid_level;e.virtio_balloon=b.virtio_balloon;e.virtio_console=b.virtio_console;if(f=b.network_relay_url||b.net_device&&b.net_device.relay_url)"fetch"===f?this.network_adapter=new Vb(this.bus,b.net_device):"inbrowser"===f?this.network_adapter=new jc(this.bus,b.net_device):f.startsWith("wisp://")||f.startsWith("wisps://")?this.network_adapter=new Xb(f,this.bus,b.net_device):this.network_adapter=new sb(f,this.bus);e.net_device=b.net_device||{type:"ne2k"};f=b.screen||{};b.screen_container&&(f.container=
|
|
313
313
|
b.screen_container);b.disable_keyboard||(this.keyboard_adapter=new Zb(this.bus));b.disable_mouse||(this.mouse_adapter=new $b(this.bus,f.container));this.screen_adapter=f.container?new wa(f,()=>this.v86.cpu.devices.vga&&this.v86.cpu.devices.vga.screen_fill_buffer()):new gc(f);e.screen=this.screen_adapter;e.screen_options=f;b.serial_container_xtermjs?this.serial_adapter=new ic(b.serial_container_xtermjs,this.bus):b.serial_container&&(this.serial_adapter=new hc(b.serial_container,this.bus));b.disable_speaker||
|
|
314
314
|
(this.speaker_adapter=new ib(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:Ba(r,this.zstd_decompress_worker.bind(this))})}};b.state&&console.warn("Warning: Unknown option 'state'. Did you mean 'initial_state'?");f("bios",b.bios);f("vga_bios",
|
|
315
|
-
b.vga_bios);f("cdrom",b.cdrom);f("hda",b.hda);f("hdb",b.hdb);f("fda",b.fda);f("fdb",b.fdb);f("initial_state",b.initial_state);f("multiboot",b.multiboot);f("bzimage",b.bzimage);f("initrd",b.initrd);if(b.filesystem&&b.filesystem.handle9p)e.handle9p=b.filesystem.handle9p;else if(b.filesystem&&b.filesystem.proxy_url)e.proxy9p=b.filesystem.proxy_url;else if(b.filesystem){f=b.filesystem.basefs;var h=b.filesystem.baseurl;let q=new kc;h&&(q=new lc(q,h));e.fs9p=this.fs9p=new J(q);
|
|
316
|
-
f.size;f=f.url}g.push({name:"fs9p_json",url:f,size:l,as_json:!0})}}var m=this,n=g.length,p=function(q){if(q===n)setTimeout(d.bind(this),0);else{var r=g[q];r.loadable?(r.loadable.onload=function(){c.call(this,r.name,r.loadable);p(q+1)}.bind(this),r.loadable.load()):oa(r.url,{done:function(x){r.url.endsWith(".zst")&&"initial_state"!==r.name&&(x=this.zstd_decompress(r.size,new Uint8Array(x)));c.call(this,r.name,r.as_json?x:new A(x));p(q+1)}.bind(this),progress:function(x){200===
|
|
317
|
-
{file_index:q,file_count:n,file_name:r.url,lengthComputable:x.lengthComputable,total:x.total||r.size,loaded:x.loaded}):m.emulator_bus.send("download-error",{file_index:q,file_count:n,file_name:r.url,request:x.target})},as_json:r.as_json})}}.bind(this);p(0)};
|
|
315
|
+
b.vga_bios);f("cdrom",b.cdrom);f("hda",b.hda);f("hdb",b.hdb);f("fda",b.fda);f("fdb",b.fdb);f("initial_state",b.initial_state);f("multiboot",b.multiboot);f("bzimage",b.bzimage);f("initrd",b.initrd);if(b.filesystem&&b.filesystem.handle9p)e.handle9p=b.filesystem.handle9p;else if(b.filesystem&&b.filesystem.proxy_url)e.proxy9p=b.filesystem.proxy_url;else if(b.filesystem){f=b.filesystem.basefs;var h=b.filesystem.baseurl;let q=new kc;h&&(q=new lc(q,h,this.zstd_decompress.bind(this)));e.fs9p=this.fs9p=new J(q);
|
|
316
|
+
if(f){if("object"===typeof f){var l=f.size;f=f.url}g.push({name:"fs9p_json",url:f,size:l,as_json:!0})}}var m=this,n=g.length,p=function(q){if(q===n)setTimeout(d.bind(this),0);else{var r=g[q];r.loadable?(r.loadable.onload=function(){c.call(this,r.name,r.loadable);p(q+1)}.bind(this),r.loadable.load()):oa(r.url,{done:function(x){r.url.endsWith(".zst")&&"initial_state"!==r.name&&(x=this.zstd_decompress(r.size,new Uint8Array(x)));c.call(this,r.name,r.as_json?x:new A(x));p(q+1)}.bind(this),progress:function(x){200===
|
|
317
|
+
x.target.status?m.emulator_bus.send("download-progress",{file_index:q,file_count:n,file_name:r.url,lengthComputable:x.lengthComputable,total:x.total||r.size,loaded:x.loaded}):m.emulator_bus.send("download-error",{file_index:q,file_count:n,file_name:r.url,request:x.target})},as_json:r.as_json})}}.bind(this);p(0)};
|
|
318
318
|
M.prototype.zstd_decompress=function(a,b){const c=this.v86.cpu;this.zstd_context=c.zstd_create_ctx(b.length);(new Uint8Array(c.wasm_memory.buffer)).set(b,c.zstd_get_src_ptr(this.zstd_context));b=c.zstd_read(this.zstd_context,a);const d=c.wasm_memory.buffer.slice(b,b+a);c.zstd_read_free(b,a);c.zstd_free_ctx(this.zstd_context);this.zstd_context=null;return d};
|
|
319
319
|
M.prototype.zstd_decompress_worker=async function(a,b){if(!this.zstd_worker){const c=URL.createObjectURL(new Blob(["("+function(){let d;globalThis.onmessage=function(e){if(d){var {src:f,decompressed_size:g,id:h}=e.data;e=d.exports;var l=e.zstd_create_ctx(f.length);(new Uint8Array(e.memory.buffer)).set(f,e.zstd_get_src_ptr(l));var m=e.zstd_read(l,g),n=e.memory.buffer.slice(m,m+g);e.zstd_read_free(m,g);e.zstd_free_ctx(l);postMessage({result:n,id:h},[n])}else l=Object.fromEntries("cpu_exception_hook run_hardware_timers cpu_event_halt microtick get_rand_int stop_idling io_port_read8 io_port_read16 io_port_read32 io_port_write8 io_port_write16 io_port_write32 mmap_read8 mmap_read16 mmap_read32 mmap_write8 mmap_write16 mmap_write32 mmap_write64 mmap_write128 codegen_finalize jit_clear_func jit_clear_all_funcs".split(" ").map(p=>
|
|
320
320
|
[p,()=>console.error("zstd worker unexpectedly called "+p)])),l.__indirect_function_table=new WebAssembly.Table({element:"anyfunc",initial:1024}),l.abort=()=>{throw Error("zstd worker aborted");},l.log_from_wasm=l.console_log_from_wasm=(p,q)=>{console.log(qa(d.exports.memory.buffer,p,q))},l.dbg_trace_from_wasm=()=>console.trace(),d=new WebAssembly.Instance(new WebAssembly.Module(e.data),{env:l})}}.toString()+")()"],{type:"text/javascript"}));this.zstd_worker=new Worker(c);URL.revokeObjectURL(c);this.zstd_worker.postMessage(this.wasm_source,
|
package/build/libv86.mjs
CHANGED
|
@@ -103,8 +103,8 @@ function(a){var b=this.dsp_16bit?32767.5:127.5,c=this.dsp_signed?0:-1,d=this.dsp
|
|
|
103
103
|
this.dac_buffers[0].shift_block(this.dac_buffers[0].length),b=this.dac_buffers[1].shift_block(this.dac_buffers[1].length);this.bus.send("dac-send-data",[a,b],[a.buffer,b.buffer])}};C.prototype.raise_irq=function(a){this.irq_triggered[a]=1;this.cpu.device_raise_irq(this.irq)};C.prototype.lower_irq=function(a){this.irq_triggered[a]=0;this.cpu.device_lower_irq(this.irq)};function Ra(a,b,c){return(a<b)*b+(a>c)*c+(b<=a&&a<=c)*a}function ab(a){this.message=a}ab.prototype=Error();const bb={Uint8Array,Int8Array,
|
|
104
104
|
Uint16Array,Int16Array,Uint32Array,Int32Array,Float32Array,Float64Array};function cb(a,b){if("object"!==typeof a||null===a)return a;if(Array.isArray(a))return a.map(e=>cb(e,b));a.constructor===Object&&console.log(a);if(a.BYTES_PER_ELEMENT){var c=new Uint8Array(a.buffer,a.byteOffset,a.length*a.BYTES_PER_ELEMENT);return{__state_type__:a.constructor.name.replace("bound ",""),buffer_id:b.push(c)-1}}a=a.get_state();c=[];for(var d=0;d<a.length;d++)c[d]=cb(a[d],b);return c}function db(a,b){if("object"!==
|
|
105
105
|
typeof a||null===a)return a;if(Array.isArray(a)){for(let c=0;c<a.length;c++)a[c]=db(a[c],b);return a}return new bb[a.__state_type__](b[a.buffer_id])}function eb(a,b){function c(q,r){const x=q.length;if(16>x)throw new ab("Invalid length: "+x);q=new Int32Array(q.buffer,q.byteOffset,4);if(-2039052682!==q[0])throw new ab("Invalid header: "+z(q[0]>>>0));if(6!==q[1])throw new ab("Version mismatch: dump="+q[1]+" we=6");if(r&&q[2]!==x)throw new ab("Length doesn't match header: real="+x+" header="+q[2]);return q[3]}
|
|
106
|
-
function d(q){q=(new TextDecoder).decode(q);return JSON.parse(q)}b=new Uint8Array(b);if(4247762216===(new Uint32Array(b.buffer,0,1))[0]){var e=a.zstd_create_ctx(b.length);(new Uint8Array(a.wasm_memory.buffer,a.zstd_get_src_ptr(e),b.length)).set(b);var f=a.zstd_read(e,16),g=new Uint8Array(a.wasm_memory.buffer,f,16),h=c(g,!1);a.zstd_read_free(f,16);f=a.zstd_read(e,h);g=new Uint8Array(a.wasm_memory.buffer,f,h);g=d(g);a.zstd_read_free(f,h);f=g.state;var l=g.buffer_infos;g=[];h=16+h;for(var m of l){l=
|
|
107
|
-
(h+3&-4)-h;if(1048576<m.length){var n=a.zstd_read(e,l);a.zstd_read_free(n,l);n=new Uint8Array(m.length);g.push(n.buffer);for(var p=0;p<m.length;){const q=Math.min(m.length-p,1048576),r=a.zstd_read(e,q);n.set(new Uint8Array(a.wasm_memory.buffer,r,q),p);a.zstd_read_free(r,q);p+=q}}else n=a.zstd_read(e,l+m.length),p=n+l,g.push(a.wasm_memory.buffer.slice(p,p+m.length)),a.zstd_read_free(n,l+m.length);h+=l+m.length}f=db(f,g);a.set_state(f);a.zstd_free_ctx(e)}else{e=c(b,!0);if(0>e||e+12>=b.length)throw new ab("Invalid info block length: "+
|
|
106
|
+
function d(q){q=(new TextDecoder).decode(q);return JSON.parse(q)}b=new Uint8Array(b);if(4247762216===(new Uint32Array(b.buffer,0,1))[0]){var e=a.zstd_create_ctx(b.length);(new Uint8Array(a.wasm_memory.buffer,a.zstd_get_src_ptr(e)>>>0,b.length)).set(b);var f=a.zstd_read(e,16),g=new Uint8Array(a.wasm_memory.buffer,f>>>0,16),h=c(g,!1);a.zstd_read_free(f,16);f=a.zstd_read(e,h);g=new Uint8Array(a.wasm_memory.buffer,f>>>0,h);g=d(g);a.zstd_read_free(f,h);f=g.state;var l=g.buffer_infos;g=[];h=16+h;for(var m of l){l=
|
|
107
|
+
(h+3&-4)-h;if(1048576<m.length){var n=a.zstd_read(e,l)>>>0;a.zstd_read_free(n,l);n=new Uint8Array(m.length);g.push(n.buffer);for(var p=0;p<m.length;){const q=Math.min(m.length-p,1048576),r=a.zstd_read(e,q);n.set(new Uint8Array(a.wasm_memory.buffer,r>>>0,q),p);a.zstd_read_free(r,q);p+=q}}else n=a.zstd_read(e,l+m.length),p=(n>>>0)+l,g.push(a.wasm_memory.buffer.slice(p,p+m.length)),a.zstd_read_free(n,l+m.length);h+=l+m.length}f=db(f,g);a.set_state(f);a.zstd_free_ctx(e)}else{e=c(b,!0);if(0>e||e+12>=b.length)throw new ab("Invalid info block length: "+
|
|
108
108
|
e);m=b.subarray(16,16+e);f=d(m);m=f.state;f=f.buffer_infos;let q=16+e;q=q+3&-4;e=f.map(r=>{const x=q+r.offset;return b.buffer.slice(x,x+r.length)});m=db(m,e);a.set_state(m)}}function fb(a,b,c,d,e){let f="";var g=[],h=b?"compiled":c?"jit exit":d?"unguarded register":e?"wasm size":"executed";for(let n=0;256>n;n++)for(let p=0;8>p;p++)for(const q of[!1,!0]){var l=a.wm.exports.get_opstats_buffer(b,c,d,e,n,!1,q,p);g.push({opcode:n,count:l,is_mem:q,fixed_g:p});l=a.wm.exports.get_opstats_buffer(b,c,d,e,n,
|
|
109
109
|
!0,q,p);g.push({opcode:3840|n,count:l,is_mem:q,fixed_g:p})}a=0;b=new Set([38,46,54,62,100,101,102,103,240,242,243]);for(const {count:n,opcode:p}of g)b.has(p)||(a+=n);if(0===a)return"";c=new Uint32Array(256);b=new Uint32Array(256);for(const {opcode:n,count:p}of g)3840===(n&65280)?b[n&255]+=p:c[n&255]+=p;f=f+"------------------\nTotal: "+(a+"\n");const m=1E7<a?1E3:1;d=Math.max.apply(Math,g.map(({count:n})=>Math.round(n/m)));d=String(d).length;f+=`Instruction counts ${h} (in ${m}):\n`;for(e=0;256>e;e++)f+=
|
|
110
110
|
e.toString(16).padStart(2,"0")+":"+aa(Math.round(c[e]/m),d),f=15===e%16?f+"\n":f+" ";f=f+"\n"+`Instruction counts ${h} (0f, in ${m}):\n`;for(h=0;256>h;h++)f+=(h&255).toString(16).padStart(2,"0")+":"+aa(Math.round(b[h]/m),d),f=15===h%16?f+"\n":f+" ";f+="\n";g=g.filter(({count:n})=>n).sort(({count:n},{count:p})=>p-n);for(const {opcode:n,is_mem:p,fixed_g:q,count:r}of g.slice(0,200))g=n.toString(16)+"_"+q+(p?"_m":"_r"),f+=g+":"+(r/a*100).toFixed(2)+" ";return f+"\n"}function gb(a){this.cpu=a;this.cmos_index=
|
|
@@ -224,12 +224,12 @@ this.show_char(h)},this);this.destroy=function(){a.removeEventListener("keypress
|
|
|
224
224
|
"\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=!1,a.scrollTop=1E9)};
|
|
225
225
|
this.send_char=function(h){g.bus&&g.bus.send("serial0-input",h)}}function ic(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=new TextEncoder,e=c.onData(function(f){for(const g of d.encode(f))b.send("serial0-input",g)});b.register("serial0-output-byte",function(f){c.write(Uint8Array.of(f))},this);this.destroy=function(){e.dispose();c.dispose()}}}
|
|
226
226
|
ic.prototype.show=function(){this.term&&this.term.open(this.element)};function jc(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)}jc.prototype.destroy=
|
|
227
|
-
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 kc(){this.filedata=new Map}kc.prototype.read=async function(a,b,c){return(a=this.filedata.get(a))?a.subarray(b,b+c):null};kc.prototype.cache=async function(a,b){this.filedata.set(a,b)};kc.prototype.uncache=function(a){this.filedata.delete(a)};function lc(a,b){b.endsWith("/")||(b+="/");this.storage=a;this.baseurl=
|
|
228
|
-
b}lc.prototype.load_from_server=function(a){return new Promise(
|
|
229
|
-
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=nc.encode(e);f+=e.byteLength;l+=e.byteLength;c.set(e,d);d+=e.byteLength;
|
|
230
|
-
e.version,e.path],c,d),d+=13,f+=13}return f}function I(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(mc.decode(h));
|
|
231
|
-
e.push({type:g[0],version:g[1],path:g[2]})}c.offset=d;return e}const oc=new TextEncoder;function J(a,b){this.inodes=[];this.storage=a;this.qidcounter=b||{last_qidnumber:0};this.inodedata={};this.total_size=274877906944;this.used_size=0;this.mounts=[];this.CreateDirectory("",-1)}J.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&
|
|
232
|
-
a[4]=this.used_size;return a=a.concat(this.mounts)};J.prototype.set_state=function(a){this.inodes=a[0].map(b=>{const c=new pc(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)};J.prototype.load_from_json=function(a){if(3!==a.version)throw"The filesystem JSON format has changed. Please recreate the filesystem JSON.";
|
|
227
|
+
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 kc(){this.filedata=new Map}kc.prototype.read=async function(a,b,c){return(a=this.filedata.get(a))?a.subarray(b,b+c):null};kc.prototype.cache=async function(a,b){this.filedata.set(a,b)};kc.prototype.uncache=function(a){this.filedata.delete(a)};function lc(a,b,c){b.endsWith("/")||(b+="/");this.storage=a;this.baseurl=
|
|
228
|
+
b;this.zstd_decompress=c}lc.prototype.load_from_server=function(a,b){return new Promise(c=>{oa(this.baseurl+a,{done:async d=>{d=new Uint8Array(d);a.endsWith(".zst")&&(d=new Uint8Array(this.zstd_decompress(b,d)));await this.cache(a,d);c(d)}})})};lc.prototype.read=async function(a,b,c,d){const e=await this.storage.read(a,b,c,d);return e?e:(await this.load_from_server(a,d)).subarray(b,b+c)};lc.prototype.cache=async function(a,b){return await this.storage.cache(a,b)};lc.prototype.uncache=function(a){this.storage.uncache(a)};
|
|
229
|
+
const mc=new TextDecoder,nc=new TextEncoder;function F(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=nc.encode(e);f+=e.byteLength;l+=e.byteLength;c.set(e,d);d+=e.byteLength;
|
|
230
|
+
c[h+0]=l&255;c[h+1]=l>>8&255;break;case "Q":F(["b","w","d"],[e.type,e.version,e.path],c,d),d+=13,f+=13}return f}function I(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(mc.decode(h));
|
|
231
|
+
break;case "Q":c.offset=d,g=I(["b","w","d"],b,c),d=c.offset,e.push({type:g[0],version:g[1],path:g[2]})}c.offset=d;return e}const oc=new TextEncoder;function J(a,b){this.inodes=[];this.storage=a;this.qidcounter=b||{last_qidnumber:0};this.inodedata={};this.total_size=274877906944;this.used_size=0;this.mounts=[];this.CreateDirectory("",-1)}J.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&
|
|
232
|
+
16384)&&a[2].push([b,c]);a[3]=this.total_size;a[4]=this.used_size;return a=a.concat(this.mounts)};J.prototype.set_state=function(a){this.inodes=a[0].map(b=>{const c=new pc(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)};J.prototype.load_from_json=function(a){if(3!==a.version)throw"The filesystem JSON format has changed. Please recreate the filesystem JSON.";
|
|
233
233
|
var b=a.fsroot;this.used_size=a.size;for(a=0;a<b.length;a++)this.LoadRecursive(b[a],0)};J.prototype.LoadRecursive=function(a,b){var c=this.CreateInode();const d=a[0];c.size=a[1];c.mtime=a[2];c.ctime=c.mtime;c.atime=c.mtime;c.mode=a[3];c.uid=a[4];c.gid=a[5];var e=c.mode&61440;16384===e?(this.PushInode(c,b,d),this.LoadDir(this.inodes.length-1,a[6])):32768===e?(c.status=2,c.sha256sum=a[6],this.PushInode(c,b,d)):40960===e?(c.symlink=a[6],this.PushInode(c,b,d)):49152!==e&&z(e)};J.prototype.LoadDir=function(a,
|
|
234
234
|
b){for(var c=0;c<b.length;c++)this.LoadRecursive(b[c],a)};J.prototype.should_be_linked=function(a){return!this.is_forwarder(a)||0===a.foreign_id};J.prototype.link_under_dir=function(a,b,c){const d=this.inodes[b],e=this.inodes[a];this.is_forwarder(e);this.IsDirectory(a);this.should_be_linked(d);e.direntries.has(c);e.direntries.set(c,b);d.nlinks++;this.IsDirectory(b)&&(d.direntries.has(".."),d.direntries.has(".")||d.nlinks++,d.direntries.set(".",b),d.direntries.set("..",a),e.nlinks++)};J.prototype.unlink_from_dir=
|
|
235
235
|
function(a,b){const c=this.Search(a,b),d=this.inodes[c],e=this.inodes[a];this.is_forwarder(e);this.IsDirectory(a);e.direntries.delete(b)&&(d.nlinks--,this.IsDirectory(c)&&(d.direntries.get(".."),d.direntries.delete(".."),e.nlinks--))};J.prototype.PushInode=function(a,b,c){-1!==b?(this.inodes.push(a),a.fid=this.inodes.length-1,this.link_under_dir(b,a.fid,c)):0===this.inodes.length&&(this.inodes.push(a),a.direntries.set(".",0),a.direntries.set("..",0),a.nlinks=2)};function pc(a){this.direntries=new Map;
|
|
@@ -250,9 +250,9 @@ await this.follow_fs(d).Read(a,b,c)):await this.get_data(a,b,c)};J.prototype.Sea
|
|
|
250
250
|
b.CountFreeInodes();return a};J.prototype.GetTotalSize=function(){let a=this.used_size;for(const {fs:b}of this.mounts)a+=b.GetTotalSize();return a};J.prototype.GetSpace=function(){let a=this.total_size;for(const {fs:b}of this.mounts)a+=b.GetSpace();return this.total_size};J.prototype.GetDirectoryName=function(a){const b=this.inodes[this.GetParent(a)];if(this.is_forwarder(b))return this.follow_fs(b).GetDirectoryName(this.inodes[a].foreign_id);if(!b)return"";for(const [c,d]of b.direntries)if(d===a)return c;
|
|
251
251
|
return""};J.prototype.GetFullPath=function(a){this.IsDirectory(a);for(var b="";0!==a;)b="/"+this.GetDirectoryName(a)+b,a=this.GetParent(a);return b.substring(1)};J.prototype.Link=function(a,b,c){if(this.IsDirectory(b))return-1;const d=this.inodes[a],e=this.inodes[b];if(this.is_forwarder(d))return this.is_forwarder(e)&&e.mount_id===d.mount_id?this.follow_fs(d).Link(d.foreign_id,e.foreign_id,c):-1;if(this.is_forwarder(e))return-1;this.link_under_dir(a,b,c);return 0};J.prototype.Unlink=function(a,b){if("."===
|
|
252
252
|
b||".."===b)return-1;const c=this.Search(a,b),d=this.inodes[c],e=this.inodes[a];if(this.is_forwarder(e))return this.is_forwarder(d),a=e.foreign_id,this.follow_fs(e).Unlink(a,b);if(this.IsDirectory(c)&&!this.IsEmpty(c))return-39;this.unlink_from_dir(a,b);0===d.nlinks&&(d.status=4,this.NotifyListeners(c,"delete"));return 0};J.prototype.DeleteData=async function(a){const b=this.inodes[a];this.is_forwarder(b)?await this.follow_fs(b).DeleteData(b.foreign_id):(b.size=0,delete this.inodedata[a])};J.prototype.get_buffer=
|
|
253
|
-
async function(a){const b=this.inodes[a];return this.inodedata[a]?this.inodedata[a]:2===b.status?await this.storage.read(b.sha256sum,0,b.size):null};J.prototype.get_data=async function(a,b,c){const d=this.inodes[a];return this.inodedata[a]?this.inodedata[a].subarray(b,b+c):2===d.status?await this.storage.read(d.sha256sum,b,c):null};J.prototype.set_data=async function(a,b){this.inodedata[a]=b;2===this.inodes[a].status&&(this.inodes[a].status=0,this.storage.uncache(this.inodes[a].sha256sum))};
|
|
254
|
-
function(a){isNaN(a);a=this.inodes[a];return this.is_forwarder(a)?this.follow_fs(a).GetInode(a.foreign_id):a};J.prototype.ChangeSize=async function(a,b){var c=this.GetInode(a),d=await this.get_data(a,0,c.size);if(b!==c.size){var e=new Uint8Array(b);c.size=b;d&&e.set(d.subarray(0,Math.min(d.length,c.size)),0);await this.set_data(a,e)}};J.prototype.SearchPath=function(a){a=a.replace("//","/");a=a.split("/");0<a.length&&0===a[a.length-1].length&&a.pop();0<a.length&&0===a[0].length&&
|
|
255
|
-
a.length;var c=-1,d=0;let e=null;for(var f=0;f<b;f++)if(c=d,d=this.Search(c,a[f]),!e&&this.is_forwarder(this.inodes[c])&&(e="/"+a.slice(f).join("/")),-1===d)return f<b-1?{id:-1,parentid:-1,name:a[f],forward_path:e}:{id:-1,parentid:c,name:a[f],forward_path:e};return{id:d,parentid:c,name:a[f],forward_path:e}};J.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,
|
|
253
|
+
async function(a){const b=this.inodes[a];return this.inodedata[a]?this.inodedata[a]:2===b.status?await this.storage.read(b.sha256sum,0,b.size,b.size):null};J.prototype.get_data=async function(a,b,c){const d=this.inodes[a];return this.inodedata[a]?this.inodedata[a].subarray(b,b+c):2===d.status?await this.storage.read(d.sha256sum,b,c,d.size):null};J.prototype.set_data=async function(a,b){this.inodedata[a]=b;2===this.inodes[a].status&&(this.inodes[a].status=0,this.storage.uncache(this.inodes[a].sha256sum))};
|
|
254
|
+
J.prototype.GetInode=function(a){isNaN(a);a=this.inodes[a];return this.is_forwarder(a)?this.follow_fs(a).GetInode(a.foreign_id):a};J.prototype.ChangeSize=async function(a,b){var c=this.GetInode(a),d=await this.get_data(a,0,c.size);if(b!==c.size){var e=new Uint8Array(b);c.size=b;d&&e.set(d.subarray(0,Math.min(d.length,c.size)),0);await this.set_data(a,e)}};J.prototype.SearchPath=function(a){a=a.replace("//","/");a=a.split("/");0<a.length&&0===a[a.length-1].length&&a.pop();0<a.length&&0===a[0].length&&
|
|
255
|
+
a.shift();const b=a.length;var c=-1,d=0;let e=null;for(var f=0;f<b;f++)if(c=d,d=this.Search(c,a[f]),!e&&this.is_forwarder(this.inodes[c])&&(e="/"+a.slice(f).join("/")),-1===d)return f<b-1?{id:-1,parentid:-1,name:a[f],forward_path:e}:{id:-1,parentid:c,name:a[f],forward_path:e};return{id:d,parentid:c,name:a[f],forward_path:e}};J.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,
|
|
256
256
|
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))};J.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)};J.prototype.DeleteNode=function(a){var b=this.SearchPath(a);-1!==b.id&&(32768===(this.inodes[b.id].mode&
|
|
257
257
|
61440)?this.Unlink(b.parentid,b.name):16384===(this.inodes[b.id].mode&61440)&&(this.RecursiveDelete(a),this.Unlink(b.parentid,b.name)))};J.prototype.NotifyListeners=function(){};J.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);}};J.prototype.FillDirectory=function(a){var b=this.inodes[a];if(this.is_forwarder(b))this.follow_fs(b).FillDirectory(b.foreign_id);
|
|
258
258
|
else{var c=0;for(const d of b.direntries.keys())c+=24+oc.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+=F(["Q","d","b","s"],[b.qid,c+13+8+1+2+oc.encode(d).length,b.mode>>12,d],a,c)}};J.prototype.RoundToDirentry=function(a,b){a=this.inodedata[a];if(b>=a.length)return a.length;let c=0;for(;;){const d=I(["Q","d"],a,{offset:c})[1];if(d>b)break;c=d}return c};J.prototype.IsDirectory=function(a){a=this.inodes[a];return this.is_forwarder(a)?
|
|
@@ -278,26 +278,27 @@ b.disable_jit;e.load_devices=!0;e.memory_size=b.memory_size||67108864;e.vga_memo
|
|
|
278
278
|
b.net_device.relay_url)"fetch"===f?this.network_adapter=new Vb(this.bus,b.net_device):"inbrowser"===f?this.network_adapter=new jc(this.bus,b.net_device):f.startsWith("wisp://")||f.startsWith("wisps://")?this.network_adapter=new Xb(f,this.bus,b.net_device):this.network_adapter=new sb(f,this.bus);e.net_device=b.net_device||{type:"ne2k"};f=b.screen||{};b.screen_container&&(f.container=b.screen_container);b.disable_keyboard||(this.keyboard_adapter=new Zb(this.bus));b.disable_mouse||(this.mouse_adapter=
|
|
279
279
|
new $b(this.bus,f.container));this.screen_adapter=f.container?new wa(f,()=>this.v86.cpu.devices.vga&&this.v86.cpu.devices.vga.screen_fill_buffer()):new gc(f);e.screen=this.screen_adapter;e.screen_options=f;b.serial_container_xtermjs?this.serial_adapter=new ic(b.serial_container_xtermjs,this.bus):b.serial_container&&(this.serial_adapter=new hc(b.serial_container,this.bus));b.disable_speaker||(this.speaker_adapter=new ib(this.bus));var g=[];f=(q,r)=>{if(r)if(r.get&&r.set&&r.load)g.push({name:q,loadable:r});
|
|
280
280
|
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:Ba(r,this.zstd_decompress_worker.bind(this))})}};b.state&&console.warn("Warning: Unknown option 'state'. Did you mean 'initial_state'?");f("bios",b.bios);f("vga_bios",b.vga_bios);f("cdrom",b.cdrom);f("hda",b.hda);f("hdb",b.hdb);f("fda",b.fda);f("fdb",b.fdb);f("initial_state",
|
|
281
|
-
b.initial_state);f("multiboot",b.multiboot);f("bzimage",b.bzimage);f("initrd",b.initrd);if(b.filesystem&&b.filesystem.handle9p)e.handle9p=b.filesystem.handle9p;else if(b.filesystem&&b.filesystem.proxy_url)e.proxy9p=b.filesystem.proxy_url;else if(b.filesystem){f=b.filesystem.basefs;var h=b.filesystem.baseurl;let q=new kc;h&&(q=new lc(q,h));e.fs9p=this.fs9p=new J(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=
|
|
282
|
-
n)setTimeout(d.bind(this),0);else{var r=g[q];r.loadable?(r.loadable.onload=function(){c.call(this,r.name,r.loadable);p(q+1)}.bind(this),r.loadable.load()):oa(r.url,{done:function(x){r.url.endsWith(".zst")&&"initial_state"!==r.name&&(x=this.zstd_decompress(r.size,new Uint8Array(x)));c.call(this,r.name,r.as_json?x:new A(x));p(q+1)}.bind(this),progress:function(x){200===x.target.status?m.emulator_bus.send("download-progress",{file_index:q,file_count:n,file_name:r.url,
|
|
283
|
-
total:x.total||r.size,loaded:x.loaded}):m.emulator_bus.send("download-error",{file_index:q,file_count:n,file_name:r.url,request:x.target})},as_json:r.as_json})}}.bind(this);p(0)};M.prototype.zstd_decompress=function(a,b){const c=this.v86.cpu;this.zstd_context=c.zstd_create_ctx(b.length);(new Uint8Array(c.wasm_memory.buffer)).set(b,c.zstd_get_src_ptr(this.zstd_context));b=c.zstd_read(this.zstd_context,a);const d=c.wasm_memory.buffer.slice(b,b+a);c.zstd_read_free(b,
|
|
284
|
-
this.zstd_context=null;return d};M.prototype.zstd_decompress_worker=async function(a,b){if(!this.zstd_worker){const c=URL.createObjectURL(new Blob(["("+function(){let d;globalThis.onmessage=function(e){if(d){var {src:f,decompressed_size:g,id:h}=e.data;e=d.exports;var l=e.zstd_create_ctx(f.length);(new Uint8Array(e.memory.buffer)).set(f,e.zstd_get_src_ptr(l));var m=e.zstd_read(l,g),n=e.memory.buffer.slice(m,m+g);e.zstd_read_free(m,g);e.zstd_free_ctx(l);postMessage({result:n,
|
|
285
|
-
[p,()=>console.error("zstd worker unexpectedly called "+p)])),l.__indirect_function_table=new WebAssembly.Table({element:"anyfunc",
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
b)
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
b&&await new Promise(d=>setTimeout(d,b))};M.prototype.
|
|
294
|
-
|
|
295
|
-
M.prototype.
|
|
296
|
-
function(a,b){this.bus.send("serial"+a+"-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
this.
|
|
281
|
+
b.initial_state);f("multiboot",b.multiboot);f("bzimage",b.bzimage);f("initrd",b.initrd);if(b.filesystem&&b.filesystem.handle9p)e.handle9p=b.filesystem.handle9p;else if(b.filesystem&&b.filesystem.proxy_url)e.proxy9p=b.filesystem.proxy_url;else if(b.filesystem){f=b.filesystem.basefs;var h=b.filesystem.baseurl;let q=new kc;h&&(q=new lc(q,h,this.zstd_decompress.bind(this)));e.fs9p=this.fs9p=new J(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=
|
|
282
|
+
this,n=g.length,p=function(q){if(q===n)setTimeout(d.bind(this),0);else{var r=g[q];r.loadable?(r.loadable.onload=function(){c.call(this,r.name,r.loadable);p(q+1)}.bind(this),r.loadable.load()):oa(r.url,{done:function(x){r.url.endsWith(".zst")&&"initial_state"!==r.name&&(x=this.zstd_decompress(r.size,new Uint8Array(x)));c.call(this,r.name,r.as_json?x:new A(x));p(q+1)}.bind(this),progress:function(x){200===x.target.status?m.emulator_bus.send("download-progress",{file_index:q,file_count:n,file_name:r.url,
|
|
283
|
+
lengthComputable:x.lengthComputable,total:x.total||r.size,loaded:x.loaded}):m.emulator_bus.send("download-error",{file_index:q,file_count:n,file_name:r.url,request:x.target})},as_json:r.as_json})}}.bind(this);p(0)};M.prototype.zstd_decompress=function(a,b){const c=this.v86.cpu;this.zstd_context=c.zstd_create_ctx(b.length);(new Uint8Array(c.wasm_memory.buffer)).set(b,c.zstd_get_src_ptr(this.zstd_context));b=c.zstd_read(this.zstd_context,a);const d=c.wasm_memory.buffer.slice(b,b+a);c.zstd_read_free(b,
|
|
284
|
+
a);c.zstd_free_ctx(this.zstd_context);this.zstd_context=null;return d};M.prototype.zstd_decompress_worker=async function(a,b){if(!this.zstd_worker){const c=URL.createObjectURL(new Blob(["("+function(){let d;globalThis.onmessage=function(e){if(d){var {src:f,decompressed_size:g,id:h}=e.data;e=d.exports;var l=e.zstd_create_ctx(f.length);(new Uint8Array(e.memory.buffer)).set(f,e.zstd_get_src_ptr(l));var m=e.zstd_read(l,g),n=e.memory.buffer.slice(m,m+g);e.zstd_read_free(m,g);e.zstd_free_ctx(l);postMessage({result:n,
|
|
285
|
+
id:h},[n])}else l=Object.fromEntries("cpu_exception_hook run_hardware_timers cpu_event_halt microtick get_rand_int stop_idling io_port_read8 io_port_read16 io_port_read32 io_port_write8 io_port_write16 io_port_write32 mmap_read8 mmap_read16 mmap_read32 mmap_write8 mmap_write16 mmap_write32 mmap_write64 mmap_write128 codegen_finalize jit_clear_func jit_clear_all_funcs".split(" ").map(p=>[p,()=>console.error("zstd worker unexpectedly called "+p)])),l.__indirect_function_table=new WebAssembly.Table({element:"anyfunc",
|
|
286
|
+
initial:1024}),l.abort=()=>{throw Error("zstd worker aborted");},l.log_from_wasm=l.console_log_from_wasm=(p,q)=>{console.log(qa(d.exports.memory.buffer,p,q))},l.dbg_trace_from_wasm=()=>console.trace(),d=new WebAssembly.Instance(new WebAssembly.Module(e.data),{env:l})}}.toString()+")()"],{type:"text/javascript"}));this.zstd_worker=new Worker(c);URL.revokeObjectURL(c);this.zstd_worker.postMessage(this.wasm_source,[this.wasm_source])}return new Promise(c=>{const d=this.zstd_worker_request_id++,e=async f=>
|
|
287
|
+
{f.data.id===d&&(this.zstd_worker.removeEventListener("message",e),c(f.data.result))};this.zstd_worker.addEventListener("message",e);this.zstd_worker.postMessage({src:b,decompressed_size:a,id:d},[b.buffer])})};M.prototype.get_bzimage_initrd_from_filesystem=function(a){const b=(a.read_dir("/")||[]).map(e=>"/"+e);a=(a.read_dir("/boot/")||[]).map(e=>"/boot/"+e);let c,d;for(const e of[].concat(b,a)){const f=/old/i.test(e)||/fallback/i.test(e),g=/vmlinuz/i.test(e)||/bzimage/i.test(e),h=/initrd/i.test(e)||
|
|
288
|
+
/initramfs/i.test(e);!g||d&&f||(d=e);!h||c&&f||(c=e)}c&&d||(console.log("Failed to find bzimage or initrd in filesystem. Files:"),console.log(b.join(" ")),console.log(a.join(" ")));return{initrd_path:c,bzimage_path:d}};M.prototype.run=async function(){this.v86.run()};M.prototype.stop=async function(){this.cpu_is_running&&await new Promise(a=>{const b=()=>{this.remove_listener("emulator-stopped",b);a()};this.add_listener("emulator-stopped",b);this.v86.stop()})};M.prototype.destroy=async function(){await this.stop();
|
|
289
|
+
this.v86.destroy();this.keyboard_adapter&&this.keyboard_adapter.destroy();this.network_adapter&&this.network_adapter.destroy();this.mouse_adapter&&this.mouse_adapter.destroy();this.screen_adapter&&this.screen_adapter.destroy();this.serial_adapter&&this.serial_adapter.destroy();this.speaker_adapter&&this.speaker_adapter.destroy()};M.prototype.restart=function(){this.v86.restart()};M.prototype.add_listener=function(a,b){this.bus.register(a,b,this)};M.prototype.remove_listener=function(a,b){this.bus.unregister(a,
|
|
290
|
+
b)};M.prototype.restore_state=async function(a){this.v86.restore_state(a)};M.prototype.save_state=async function(){return this.v86.save_state()};M.prototype.get_instruction_counter=function(){return this.v86?this.v86.cpu.instruction_counter[0]>>>0:0};M.prototype.is_running=function(){return this.cpu_is_running};M.prototype.set_fda=async function(a){const b=this.v86.cpu.devices.fdc.drives[0];if(a.url&&!a.async)await new Promise(c=>{oa(a.url,{done:d=>{b.insert_disk(new A(d));c()}})});else{const c=Ba(a,
|
|
291
|
+
this.zstd_decompress_worker.bind(this));c.onload=()=>{b.insert_disk(c)};await c.load()}};M.prototype.set_fdb=async function(a){const b=this.v86.cpu.devices.fdc.drives[1];if(a.url&&!a.async)await new Promise(c=>{oa(a.url,{done:d=>{b.insert_disk(new A(d));c()}})});else{const c=Ba(a,this.zstd_decompress_worker.bind(this));c.onload=()=>{b.insert_disk(c)};await c.load()}};M.prototype.eject_fda=function(){this.v86.cpu.devices.fdc.drives[0].eject_disk()};M.prototype.eject_fdb=function(){this.v86.cpu.devices.fdc.drives[1].eject_disk()};
|
|
292
|
+
M.prototype.get_disk_fda=function(){return this.v86.cpu.devices.fdc.drives[0].get_buffer()};M.prototype.get_disk_fdb=function(){return this.v86.cpu.devices.fdc.drives[1].get_buffer()};M.prototype.set_cdrom=async function(a){if(a.url&&!a.async)oa(a.url,{done:b=>{this.v86.cpu.devices.cdrom.set_cdrom(new A(b))}});else{const b=Ba(a,this.zstd_decompress_worker.bind(this));b.onload=()=>{this.v86.cpu.devices.cdrom.set_cdrom(b)};await b.load()}};M.prototype.eject_cdrom=function(){this.v86.cpu.devices.cdrom.eject()};
|
|
293
|
+
M.prototype.keyboard_send_scancodes=async function(a,b){for(var c=0;c<a.length;c++)this.bus.send("keyboard-code",a[c]),b&&await new Promise(d=>setTimeout(d,b))};M.prototype.keyboard_send_keys=async function(a,b){for(var c=0;c<a.length;c++)this.keyboard_adapter.simulate_press(a[c]),b&&await new Promise(d=>setTimeout(d,b))};M.prototype.keyboard_send_text=async function(a,b){for(var c=0;c<a.length;c++)this.keyboard_adapter.simulate_char(a[c]),b&&await new Promise(d=>setTimeout(d,b))};M.prototype.screen_make_screenshot=
|
|
294
|
+
function(){return this.screen_adapter?this.screen_adapter.make_screenshot():null};M.prototype.screen_set_scale=function(a,b){this.screen_adapter&&this.screen_adapter.set_scale(a,b)};M.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()}}};
|
|
295
|
+
M.prototype.lock_mouse=async function(){const a=document.body;try{await a.requestPointerLock({unadjustedMovement:!0})}catch(b){await a.requestPointerLock()}};M.prototype.mouse_set_enabled=function(a){this.mouse_adapter&&(this.mouse_adapter.emu_enabled=a)};M.prototype.mouse_set_status=M.prototype.mouse_set_enabled;M.prototype.keyboard_set_enabled=function(a){this.keyboard_adapter&&(this.keyboard_adapter.emu_enabled=a)};M.prototype.keyboard_set_status=M.prototype.keyboard_set_enabled;M.prototype.serial0_send=
|
|
296
|
+
function(a){for(var b=0;b<a.length;b++)this.bus.send("serial0-input",a.charCodeAt(b))};M.prototype.serial_send_bytes=function(a,b){for(var c=0;c<b.length;c++)this.bus.send("serial"+a+"-input",b[c])};M.prototype.serial_set_modem_status=function(a,b){this.bus.send("serial"+a+"-modem-status-input",b)};M.prototype.serial_set_carrier_detect=function(a,b){this.bus.send("serial"+a+"-carrier-detect-input",b)};M.prototype.serial_set_ring_indicator=function(a,b){this.bus.send("serial"+a+"-ring-indicator-input",
|
|
297
|
+
b)};M.prototype.serial_set_data_set_ready=function(a,b){this.bus.send("serial"+a+"-data-set-ready-input",b)};M.prototype.serial_set_clear_to_send=function(a,b){this.bus.send("serial"+a+"-clear-to-send-input",b)};M.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 sc)}};M.prototype.read_file=async function(a){var b=this.fs9p;if(b)return(a=await b.read_file(a))?
|
|
298
|
+
a:Promise.reject(new sc)};M.prototype.automatically=function(a){const b=c=>{const d=c[0];if(d){var e=c.slice(1);d.sleep?setTimeout(()=>b(e),1E3*d.sleep):d.vga_text?this.wait_until_vga_screen_contains(d.vga_text).then(()=>b(e)):d.keyboard_send?(Array.isArray(d.keyboard_send)?this.keyboard_send_scancodes(d.keyboard_send):this.keyboard_send_text(d.keyboard_send),b(e)):d.call&&(d.call(),b(e))}};b(a)};M.prototype.wait_until_vga_screen_contains=async function(a,b){const c=Array.isArray(a);var d=b?.timeout_msec||
|
|
299
|
+
0;const e=new Set;b=m=>e.add(m[0]);const f=(m,n)=>n.test?n.test(m):m.startsWith(n),g=[];this.add_listener("screen-put-char",b);for(var h of this.screen_adapter.get_text_screen())if(c)g.push(h.trimRight());else if(f(h,a))return this.remove_listener("screen-put-char",b),!0;h=!1;d=d?performance.now()+d:0;a:for(;!d||performance.now()<d;){if(c){for(var l=g.length;0<l&&""===g[l-1];)l--;l-=a.length;if(0<=l){let m=!0;for(let n=0;n<a.length&&m;n++)m=f(g[l+n],a[n]);if(m){h=!0;break}}}await new Promise(m=>setTimeout(m,
|
|
300
|
+
100));for(const m of e)if(l=this.screen_adapter.get_text_row(m),c)g[m]=l.trimRight();else if(f(l,a)){h=!0;break a}e.clear()}this.remove_listener("screen-put-char",b);return h};M.prototype.read_memory=function(a,b){return this.v86.cpu.read_blob(a,b)};M.prototype.write_memory=function(a,b){this.v86.cpu.write_blob(a,b)};M.prototype.set_serial_container_xtermjs=function(a){this.serial_adapter&&this.serial_adapter.destroy&&this.serial_adapter.destroy();this.serial_adapter=new ic(a,this.bus);this.serial_adapter.show()};
|
|
301
|
+
M.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(" "),
|
|
301
302
|
d=0;const e={};for(let g=0;g<c.length;g++){const h=c[g];var f=void 0;if(h.includes("/")){d++;const [l,m]=h.split("/");f=e[l]/e[m]}else f=e[h]=a.wm.exports.profiler_stat_get(g-d),f=1E8<=f?Math.round(f/1E6)+"m":1E5<=f?Math.round(f/1E3)+"k":f;b+=h+"="+f+"\n"}b+="\n";c=a.wm.exports.get_valid_tlb_entries_count();d=a.wm.exports.get_valid_global_tlb_entries_count();b=b+("TLB_ENTRIES="+c+" ("+d+" global, "+(c-d)+" non-global)\nWASM_TABLE_FREE=")+(a.wm.exports.jit_get_wasm_table_index_free_list_count()+"\n");
|
|
302
303
|
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=[fb(a,!1,!1,!1,!1),fb(a,!0,!1,!1,!1),fb(a,!1,!0,!1,!1),fb(a,!1,
|
|
303
304
|
!1,!0,!1),fb(a,!1,!1,!1,!0)].join("\n\n");return b+a};function sc(a){this.message=a||"File not found"}sc.prototype=Error.prototype;"undefined"!==typeof module&&"undefined"!==typeof module.exports?module.exports.V86=M:"undefined"!==typeof window?window.V86=M:"function"===typeof importScripts&&(self.V86=M);function E(a,b){this.stopping=this.running=!1;this.idle=!0;this.tick_counter=0;this.worker=null;this.cpu=new O(a,b,()=>{this.idle&&this.next_tick(0)});this.bus=a;this.register_yield()}E.prototype.run=
|