v86 0.5.299 → 0.5.300
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 +7 -4
- package/build/libv86-debug.mjs +7 -4
- package/build/libv86.js +27 -27
- package/build/libv86.mjs +127 -127
- package/package.json +1 -1
package/build/libv86-debug.js
CHANGED
|
@@ -2138,7 +2138,7 @@ function $audio_clip$$module$src$sb16$$($value$jscomp$125$$, $low$$, $high$$) {
|
|
|
2138
2138
|
this.message = $msg$jscomp$2$$;
|
|
2139
2139
|
}
|
|
2140
2140
|
$StateLoadError$$module$src$state$$.prototype = Error();
|
|
2141
|
-
const $CONSTRUCTOR_TABLE$$module$src$state$$ = {Uint8Array, Int8Array, Uint16Array, Int16Array, Uint32Array, Int32Array, Float32Array, Float64Array, };
|
|
2141
|
+
const $CONSTRUCTOR_TABLE$$module$src$state$$ = {Map, Uint8Array, Int8Array, Uint16Array, Int16Array, Uint32Array, Int32Array, Float32Array, Float64Array, };
|
|
2142
2142
|
function $save_object$$module$src$state$$($constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$, $saved_buffers$$) {
|
|
2143
2143
|
if ("object" !== typeof $constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$ || null === $constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$) {
|
|
2144
2144
|
return $dbg_assert$$module$src$log$$("function" !== typeof $constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$), $constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$;
|
|
@@ -2146,6 +2146,9 @@ function $save_object$$module$src$state$$($constructor$jscomp$1_obj$jscomp$27_re
|
|
|
2146
2146
|
if (Array.isArray($constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$)) {
|
|
2147
2147
|
return $constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$.map($x$jscomp$98$$ => $save_object$$module$src$state$$($x$jscomp$98$$, $saved_buffers$$));
|
|
2148
2148
|
}
|
|
2149
|
+
if ($constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$ instanceof Map) {
|
|
2150
|
+
return {__state_type__:"Map", args:Array.from($constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$.entries()).map(([$k$$, $v$$]) => [$save_object$$module$src$state$$($k$$, $saved_buffers$$), $save_object$$module$src$state$$($v$$, $saved_buffers$$), ]), };
|
|
2151
|
+
}
|
|
2149
2152
|
$constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$.constructor === Object && (console.log($constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$), $dbg_assert$$module$src$log$$($constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$.constructor !== Object, "Expected non-object"));
|
|
2150
2153
|
if ($constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$.BYTES_PER_ELEMENT) {
|
|
2151
2154
|
var $buffer$jscomp$28_state$jscomp$7$$ = new Uint8Array($constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$.buffer, $constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$.byteOffset, $constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$.length * $constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$.BYTES_PER_ELEMENT);
|
|
@@ -2177,7 +2180,7 @@ function $restore_buffers$$module$src$state$$($obj$jscomp$28$$, $buffers$jscomp$
|
|
|
2177
2180
|
$dbg_assert$$module$src$log$$(void 0 !== $i$jscomp$28_type$jscomp$150$$);
|
|
2178
2181
|
const $constructor$jscomp$2$$ = $CONSTRUCTOR_TABLE$$module$src$state$$[$i$jscomp$28_type$jscomp$150$$];
|
|
2179
2182
|
$dbg_assert$$module$src$log$$($constructor$jscomp$2$$, "Unkown type: " + $i$jscomp$28_type$jscomp$150$$);
|
|
2180
|
-
return new $constructor$jscomp$2$$($buffers$jscomp$2$$[$obj$jscomp$28$$.buffer_id]);
|
|
2183
|
+
return void 0 !== $obj$jscomp$28$$.args ? new $constructor$jscomp$2$$($obj$jscomp$28$$.args) : new $constructor$jscomp$2$$($buffers$jscomp$2$$[$obj$jscomp$28$$.buffer_id]);
|
|
2181
2184
|
}
|
|
2182
2185
|
function $restore_state$$module$src$state$$($cpu$jscomp$5$$, $state$jscomp$9$$) {
|
|
2183
2186
|
function $read_state_header$$($header_block$jscomp$1_state$jscomp$10$$, $check_length$$) {
|
|
@@ -3056,7 +3059,7 @@ $SpeakerDACDebugger$$module$src$browser$speaker$$.prototype.push_queued_data = f
|
|
|
3056
3059
|
this.is_active && (this.queued[0].push($data$jscomp$114$$[0].slice()), this.queued[1].push($data$jscomp$114$$[1].slice()));
|
|
3057
3060
|
};
|
|
3058
3061
|
$SpeakerDACDebugger$$module$src$browser$speaker$$.prototype.download_txt = function($history_id_txt$$, $channel$jscomp$30$$) {
|
|
3059
|
-
$history_id_txt$$ = this.output_history[$history_id_txt$$][$channel$jscomp$30$$].map($v$$ => $v$$.join(" ")).join(" ");
|
|
3062
|
+
$history_id_txt$$ = this.output_history[$history_id_txt$$][$channel$jscomp$30$$].map($v$jscomp$1$$ => $v$jscomp$1$$.join(" ")).join(" ");
|
|
3060
3063
|
$dump_file$$module$src$lib$$($history_id_txt$$, "dacdata.txt");
|
|
3061
3064
|
};
|
|
3062
3065
|
$SpeakerDACDebugger$$module$src$browser$speaker$$.prototype.download_csv = function($buffers$jscomp$5_history_id$jscomp$1$$) {
|
|
@@ -9196,7 +9199,7 @@ function $VirtioNet$$module$src$virtio_net$$($cpu$jscomp$23$$, $bus$jscomp$23_qu
|
|
|
9196
9199
|
}
|
|
9197
9200
|
}
|
|
9198
9201
|
}
|
|
9199
|
-
}, ], }, isr_status:{initial_port:50944, }, device_specific:{initial_port:50688, struct:[0, 1, 2, 3, 4, 5].map(($v$jscomp$
|
|
9202
|
+
}, ], }, isr_status:{initial_port:50944, }, device_specific:{initial_port:50688, struct:[0, 1, 2, 3, 4, 5].map(($v$jscomp$2$$, $k$jscomp$1$$) => ({bytes:1, name:"mac_" + $k$jscomp$1$$, read:() => this.mac[$k$jscomp$1$$], write:() => {
|
|
9200
9203
|
}, })).concat([{bytes:2, name:"status", read:() => this.status, write:() => {
|
|
9201
9204
|
}, }, {bytes:2, name:"max_pairs", read:() => this.pairs, write:() => {
|
|
9202
9205
|
}, }, {bytes:2, name:"mtu", read:() => $mtu$jscomp$1$$, write:() => {
|
package/build/libv86-debug.mjs
CHANGED
|
@@ -2137,7 +2137,7 @@ function $StateLoadError$$module$src$state$$($msg$jscomp$2$$) {
|
|
|
2137
2137
|
this.message = $msg$jscomp$2$$;
|
|
2138
2138
|
}
|
|
2139
2139
|
$StateLoadError$$module$src$state$$.prototype = Error();
|
|
2140
|
-
const $CONSTRUCTOR_TABLE$$module$src$state$$ = {Uint8Array, Int8Array, Uint16Array, Int16Array, Uint32Array, Int32Array, Float32Array, Float64Array, };
|
|
2140
|
+
const $CONSTRUCTOR_TABLE$$module$src$state$$ = {Map, Uint8Array, Int8Array, Uint16Array, Int16Array, Uint32Array, Int32Array, Float32Array, Float64Array, };
|
|
2141
2141
|
function $save_object$$module$src$state$$($constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$, $saved_buffers$$) {
|
|
2142
2142
|
if ("object" !== typeof $constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$ || null === $constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$) {
|
|
2143
2143
|
return $dbg_assert$$module$src$log$$("function" !== typeof $constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$), $constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$;
|
|
@@ -2145,6 +2145,9 @@ function $save_object$$module$src$state$$($constructor$jscomp$1_obj$jscomp$27_re
|
|
|
2145
2145
|
if (Array.isArray($constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$)) {
|
|
2146
2146
|
return $constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$.map($x$jscomp$98$$ => $save_object$$module$src$state$$($x$jscomp$98$$, $saved_buffers$$));
|
|
2147
2147
|
}
|
|
2148
|
+
if ($constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$ instanceof Map) {
|
|
2149
|
+
return {__state_type__:"Map", args:Array.from($constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$.entries()).map(([$k$$, $v$$]) => [$save_object$$module$src$state$$($k$$, $saved_buffers$$), $save_object$$module$src$state$$($v$$, $saved_buffers$$), ]), };
|
|
2150
|
+
}
|
|
2148
2151
|
$constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$.constructor === Object && (console.log($constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$), $dbg_assert$$module$src$log$$($constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$.constructor !== Object, "Expected non-object"));
|
|
2149
2152
|
if ($constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$.BYTES_PER_ELEMENT) {
|
|
2150
2153
|
var $buffer$jscomp$28_state$jscomp$7$$ = new Uint8Array($constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$.buffer, $constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$.byteOffset, $constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$.length * $constructor$jscomp$1_obj$jscomp$27_result$jscomp$5$$.BYTES_PER_ELEMENT);
|
|
@@ -2176,7 +2179,7 @@ function $restore_buffers$$module$src$state$$($obj$jscomp$28$$, $buffers$jscomp$
|
|
|
2176
2179
|
$dbg_assert$$module$src$log$$(void 0 !== $i$jscomp$28_type$jscomp$150$$);
|
|
2177
2180
|
const $constructor$jscomp$2$$ = $CONSTRUCTOR_TABLE$$module$src$state$$[$i$jscomp$28_type$jscomp$150$$];
|
|
2178
2181
|
$dbg_assert$$module$src$log$$($constructor$jscomp$2$$, "Unkown type: " + $i$jscomp$28_type$jscomp$150$$);
|
|
2179
|
-
return new $constructor$jscomp$2$$($buffers$jscomp$2$$[$obj$jscomp$28$$.buffer_id]);
|
|
2182
|
+
return void 0 !== $obj$jscomp$28$$.args ? new $constructor$jscomp$2$$($obj$jscomp$28$$.args) : new $constructor$jscomp$2$$($buffers$jscomp$2$$[$obj$jscomp$28$$.buffer_id]);
|
|
2180
2183
|
}
|
|
2181
2184
|
function $restore_state$$module$src$state$$($cpu$jscomp$5$$, $state$jscomp$9$$) {
|
|
2182
2185
|
function $read_state_header$$($header_block$jscomp$1_state$jscomp$10$$, $check_length$$) {
|
|
@@ -3055,7 +3058,7 @@ $SpeakerDACDebugger$$module$src$browser$speaker$$.prototype.push_queued_data = f
|
|
|
3055
3058
|
this.is_active && (this.queued[0].push($data$jscomp$114$$[0].slice()), this.queued[1].push($data$jscomp$114$$[1].slice()));
|
|
3056
3059
|
};
|
|
3057
3060
|
$SpeakerDACDebugger$$module$src$browser$speaker$$.prototype.download_txt = function($history_id_txt$$, $channel$jscomp$30$$) {
|
|
3058
|
-
$history_id_txt$$ = this.output_history[$history_id_txt$$][$channel$jscomp$30$$].map($v$$ => $v$$.join(" ")).join(" ");
|
|
3061
|
+
$history_id_txt$$ = this.output_history[$history_id_txt$$][$channel$jscomp$30$$].map($v$jscomp$1$$ => $v$jscomp$1$$.join(" ")).join(" ");
|
|
3059
3062
|
$dump_file$$module$src$lib$$($history_id_txt$$, "dacdata.txt");
|
|
3060
3063
|
};
|
|
3061
3064
|
$SpeakerDACDebugger$$module$src$browser$speaker$$.prototype.download_csv = function($buffers$jscomp$5_history_id$jscomp$1$$) {
|
|
@@ -9195,7 +9198,7 @@ function $VirtioNet$$module$src$virtio_net$$($cpu$jscomp$23$$, $bus$jscomp$23_qu
|
|
|
9195
9198
|
}
|
|
9196
9199
|
}
|
|
9197
9200
|
}
|
|
9198
|
-
}, ], }, isr_status:{initial_port:50944, }, device_specific:{initial_port:50688, struct:[0, 1, 2, 3, 4, 5].map(($v$jscomp$
|
|
9201
|
+
}, ], }, isr_status:{initial_port:50944, }, device_specific:{initial_port:50688, struct:[0, 1, 2, 3, 4, 5].map(($v$jscomp$2$$, $k$jscomp$1$$) => ({bytes:1, name:"mac_" + $k$jscomp$1$$, read:() => this.mac[$k$jscomp$1$$], write:() => {
|
|
9199
9202
|
}, })).concat([{bytes:2, name:"status", read:() => this.status, write:() => {
|
|
9200
9203
|
}, }, {bytes:2, name:"max_pairs", read:() => this.pairs, write:() => {
|
|
9201
9204
|
}, }, {bytes:2, name:"mtu", read:() => $mtu$jscomp$1$$, write:() => {
|
package/build/libv86.js
CHANGED
|
@@ -11,21 +11,21 @@ if("undefined"===typeof XMLHttpRequest||"undefined"!==typeof process&&process.ve
|
|
|
11
11
|
{filename:a,enc:l})}b.done&&b.done(e.response,e)}};e.onerror=function(l){console.error("Loading the image "+a+" failed",l);d()};b.progress&&(e.onprogress=function(l){b.progress(l)});e.send(null)},pa=async function(a){return new Promise((b,c)=>{oa(a,{done:(d,e)=>{d=e.getResponseHeader("Content-Range")||"";(e=d.match(/\/(\d+)\s*$/))?b(+e[1]):c(Error("`Range: bytes=...` header not supported (Got `"+d+"`)"))},headers:{Range:"bytes=0-0","X-Accept-Encoding":"identity"}})})};
|
|
12
12
|
function qa(a,b,c){return String.fromCharCode(...(new Uint8Array(a.buffer,b>>>0,c>>>0)))}
|
|
13
13
|
const ra={cp437:" \u263a\u263b\u2665\u2666\u2663\u2660\u2022\u25d8\u25cb\u25d9\u2642\u2640\u266a\u266b\u263c\u25ba\u25c4\u2195\u203c\u00b6\u00a7\u25ac\u21a8\u2191\u2193\u2192\u2190\u221f\u2194\u25b2\u25bc !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u2302\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00a2\u00a3\u00a5\u20a7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u2310\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580\u03b1\u00df\u0393\u03c0\u03a3\u03c3\u00b5\u03c4\u03a6\u0398\u03a9\u03b4\u221e\u03c6\u03b5\u2229\u2261\u00b1\u2265\u2264\u2320\u2321\u00f7\u2248\u00b0\u2219\u00b7\u221a\u207f\u00b2\u25a0 ",cp858:"\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00f8\u00a3\u00d8\u00d7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u00ae\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u00c1\u00c2\u00c0\u00a9\u2563\u2551\u2557\u255d\u00a2\u00a5\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u00e3\u00c3\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u00a4\u00f0\u00d0\u00ca\u00cb\u00c8\u20ac\u00cd\u00ce\u00cf\u2518\u250c\u2588\u2584\u00a6\u00cc\u2580\u00d3\u00df\u00d4\u00d2\u00f5\u00d5\u00b5\u00fe\u00de\u00da\u00db\u00d9\u00fd\u00dd\u00af\u00b4\u00ad\u00b1\u2017\u00be\u00b6\u00a7\u00f7\u00b8\u00b0\u00a8\u00b7\u00b9\u00b3\u00b2\u25a0 "};
|
|
14
|
-
ra.cp858=ra.cp437.slice(0,128)+ra.cp858;ra.ascii=ra.cp437.split("").map((a,b)=>31<b&&128>b?a:".").join("");function sa(a){return a&&ra[a]?ra[a]:ra.cp437};function ua(){}function va(){};function wa(a,b){function c(w){w=w.toString(16);return"#"+"0".repeat(6-w.length)+w}function d(w){var t=256*na,H=8*R,K=Ta?Ta.canvas:null;K&&K.width===t&&K.height===H||(K?(K.width=t,K.height=H):(K=new OffscreenCanvas(t,H),Ta=K.getContext("2d")),
|
|
15
|
-
ja);S=!1;for(let La=0;La<R;++La,++Ea,P+=fa){const Ma=w[Ea];for(let ta=128;0<ta;ta>>=1)H(Ma&ta?255:0);
|
|
14
|
+
ra.cp858=ra.cp437.slice(0,128)+ra.cp858;ra.ascii=ra.cp437.split("").map((a,b)=>31<b&&128>b?a:".").join("");function sa(a){return a&&ra[a]?ra[a]:ra.cp437};function ua(){}function va(){};function wa(a,b){function c(w){w=w.toString(16);return"#"+"0".repeat(6-w.length)+w}function d(w){var t=256*na,H=8*R,K=Ta?Ta.canvas:null;K&&K.width===t&&K.height===H||(K?(K.width=t,K.height=H):(K=new OffscreenCanvas(t,H),Ta=K.getContext("2d")),Db=Ta.createImageData(t,H));const Q=Db.data;let P=0,S;H=Eb?function(Z){S=S||Z;Q[P+3]=Z;Q[P+7]=Z;P+=8}:function(Z){S=S||Z;Q[P+3]=Z;P+=4};K=32-R;const ja=t*(R-1)*4;t=4*(na-t*R);const fa=1020*na;for(let Z=0,Ea=0;2048>Z;++Z,Ea+=K,P+=t){const Fa=Z%256;Z&&!Fa&&(P+=
|
|
15
|
+
ja);S=!1;for(let La=0;La<R;++La,++Ea,P+=fa){const Ma=w[Ea];for(let ta=128;0<ta;ta>>=1)H(Ma&ta?255:0);Fb&&H(Gb&&192<=Fa&&223>=Fa&&Ma&1?255:0)}ac[Z]=S?1:0}Ta.putImageData(Db,0,0)}function e(w,t,H,K){if(t&&H){w.style.width="";w.style.height="";K&&(w.style.transform="");var Q=w.getBoundingClientRect();K?w.style.transform=(1===t?"":" scaleX("+t+")")+(1===H?"":" scaleY("+H+")"):(0===t%1&&0===H%1?(g.style.imageRendering="crisp-edges",g.style.imageRendering="pixelated",g.style["-ms-interpolation-mode"]="nearest-neighbor"):
|
|
16
16
|
(g.style.imageRendering="",g.style["-ms-interpolation-mode"]=""),K=window.devicePixelRatio||1,0!==K%1&&(t/=K,H/=K));1!==t&&(w.style.width=Q.width*t+"px");1!==H&&(w.style.height=Q.height*H+"px")}}const f=a.container;this.screen_fill_buffer=b;console.assert(f,"options.container must be provided");this.FLAG_BLINKING=1;this.FLAG_FONT_PAGE_B=2;var g=f.getElementsByTagName("canvas")[0],h=g.getContext("2d",{alpha:!1}),l=f.getElementsByTagName("div")[0],m=document.createElement("div"),n,p,q=void 0!==a.scale?
|
|
17
|
-
a.scale:1,r=void 0!==a.scale?a.scale:1,x=1,y,u,G,N,v,L,T,Ta,
|
|
18
|
-
u)w.src=g.toDataURL("image/png");else{const t=[9,16],H=document.createElement("canvas");H.width=N*t[0];H.height=v*t[1];const K=H.getContext("2d");K.imageSmoothingEnabled=!1;K.font=window.getComputedStyle(l).font;K.textBaseline="top";for(let Q=0;Q<v;Q++)for(let P=0;P<N;P++){const S=4*(Q*N+P),ja=G[S+0],fa=G[S+3];K.fillStyle=c(G[S+2]);K.fillRect(P*t[0],Q*t[1],t[0],t[1]);K.fillStyle=c(fa);K.fillText(
|
|
19
|
-
t[0],n*t[1]+parseInt(m.style.marginTop,10),parseInt(m.style.width,10),parseInt(m.style.height,10)));w.src=H.toDataURL("image/png")}return w};this.put_char=function(w,t,H,K,Q,P){t=4*(w*N+t);G[t+0]=H;G[t+1]=K;G[t+2]=Q;G[t+3]=P;y[w]=1};this.timer=function(){
|
|
20
|
-
y[w]=0)};this.update_graphical=function(){this.screen_fill_buffer()};this.update_graphical_text=function(){if(L){var w=performance.now();if(266<w-bc){
|
|
21
|
-
var K=G[Z+1];const dc=G[Z+2],ec=G[Z+3],fc=K&2?Hb
|
|
22
|
-
0,0,Q,R,0,fa,Q,R)}S&&(
|
|
23
|
-
u&&y&&y.fill(1))};this.set_font_bitmap=function(w,t,H,K,Q,P){const S=H?16:t?9:8;if(R!==w||na!==S||
|
|
17
|
+
a.scale:1,r=void 0!==a.scale?a.scale:1,x=1,y,u,G,N,v,L,T,Ta,Db,ac=new Int8Array(2048),R,na,Fb,Eb,Gb,Hb=0,Ib=0,ob,bc=0,pb,Jb,qb,Kb=sa(a.encoding),rb=0,Lb=!1;this.init=function(){m.classList.add("cursor");m.style.position="absolute";m.style.backgroundColor="#ccc";m.style.width="7px";m.style.display="inline-block";this.set_mode(!1);this.set_size_text(80,25);2===u&&this.set_size_graphical(720,400,720,400);this.set_scale(q,r);this.timer()};this.make_screenshot=function(){const w=new Image;if(1===u||2===
|
|
18
|
+
u)w.src=g.toDataURL("image/png");else{const t=[9,16],H=document.createElement("canvas");H.width=N*t[0];H.height=v*t[1];const K=H.getContext("2d");K.imageSmoothingEnabled=!1;K.font=window.getComputedStyle(l).font;K.textBaseline="top";for(let Q=0;Q<v;Q++)for(let P=0;P<N;P++){const S=4*(Q*N+P),ja=G[S+0],fa=G[S+3];K.fillStyle=c(G[S+2]);K.fillRect(P*t[0],Q*t[1],t[0],t[1]);K.fillStyle=c(fa);K.fillText(Kb[ja],P*t[0],Q*t[1])}"none"!==m.style.display&&n<v&&p<N&&(K.fillStyle=m.style.backgroundColor,K.fillRect(p*
|
|
19
|
+
t[0],n*t[1]+parseInt(m.style.marginTop,10),parseInt(m.style.width,10),parseInt(m.style.height,10)));w.src=H.toDataURL("image/png")}return w};this.put_char=function(w,t,H,K,Q,P){t=4*(w*N+t);G[t+0]=H;G[t+1]=K;G[t+2]=Q;G[t+3]=P;y[w]=1};this.timer=function(){rb=requestAnimationFrame(()=>this.update_screen())};this.update_screen=function(){Lb||(0===u?this.update_text():1===u?this.update_graphical():this.update_graphical_text());this.timer()};this.update_text=function(){for(var w=0;w<v;w++)y[w]&&(this.text_update_row(w),
|
|
20
|
+
y[w]=0)};this.update_graphical=function(){this.screen_fill_buffer()};this.update_graphical_text=function(){if(L){var w=performance.now();if(266<w-bc){ob=!ob;qb&&(y[n]=1);var t=4*N;for(let ja=0,fa=0;ja<v;++ja)if(y[ja])fa+=t;else for(var H=0;H<N;++H,fa+=4)if(G[fa+1]&1){y[ja]=1;fa+=t-4*H;break}bc=w}w=Ta.canvas;t=T.canvas;H=4*N;const Q=N*na,P=R;let S=0;for(let ja=0,fa=0,Z=0;ja<v;++ja,fa+=R){if(!y[ja]){Z+=H;continue}++S;T.clearRect(0,P,Q,R);let Ea,Fa,La,Ma;for(let ta=0;ta<Q;ta+=na,Z+=4){const cc=G[Z+0];
|
|
21
|
+
var K=G[Z+1];const dc=G[Z+2],ec=G[Z+3],fc=K&2?Ib:Hb;K=(!(K&1)||ob)&&ac[(fc<<8)+cc];La!==dc&&(void 0!==La&&(L.fillStyle=c(La),L.fillRect(Ma,fa,ta-Ma,R)),La=dc,Ma=ta);Ea!==ec&&(void 0!==Ea&&(T.fillStyle=c(Ea),T.fillRect(Fa,0,ta-Fa,R)),Ea=ec,Fa=ta);K&&T.drawImage(w,cc*na,fc*R,na,R,ta,P,na,R)}T.fillStyle=c(Ea);T.fillRect(Fa,0,Q-Fa,R);T.globalCompositeOperation="destination-in";T.drawImage(t,0,P,Q,R,0,0,Q,R);T.globalCompositeOperation="source-over";L.fillStyle=c(La);L.fillRect(Ma,fa,Q-Ma,R);L.drawImage(t,
|
|
22
|
+
0,0,Q,R,0,fa,Q,R)}S&&(ob&&qb&&y[n]&&(L.fillStyle=c(G[4*(n*N+p)+3]),L.fillRect(p*na,n*R+pb,na,Jb-pb+1)),y.fill(0));S&&h.drawImage(L.canvas,0,0)}};this.destroy=function(){rb&&(cancelAnimationFrame(rb),rb=0)};this.pause=function(){Lb=!0;m.classList.remove("blinking-cursor")};this.continue=function(){Lb=!1;m.classList.add("blinking-cursor")};this.set_mode=function(w){u=w?1:a.use_graphical_text?2:0;0===u?(l.style.display="block",g.style.display="none"):(l.style.display="none",g.style.display="block",2===
|
|
23
|
+
u&&y&&y.fill(1))};this.set_font_bitmap=function(w,t,H,K,Q,P){const S=H?16:t?9:8;if(R!==w||na!==S||Fb!==t||Eb!==H||Gb!==K||P)P=na!==S||R!==w,R=w,na=S,Fb=t,Eb=H,Gb=K,2===u&&(d(Q),y.fill(1),P&&this.set_size_graphical_text())};this.set_font_page=function(w,t){if(Hb!==w||Ib!==t)Hb=w,Ib=t,y.fill(1)};this.clear_screen=function(){h.fillStyle="#000";h.fillRect(0,0,g.width,g.height)};this.set_size_graphical_text=function(){if(Ta){var w=na*N,t=R*v,H=2*R;L&&L.canvas.width===w&&L.canvas.height===t&&T.canvas.height===
|
|
24
24
|
H||(L?(L.canvas.width=w,L.canvas.height=t,T.canvas.width=w,T.canvas.height=H):(L=(new OffscreenCanvas(w,t)).getContext("2d",{alpha:!1}),T=(new OffscreenCanvas(w,H)).getContext("2d")),this.set_size_graphical(w,t,w,t),y.fill(1))}};this.set_size_text=function(w,t){if(w!==N||t!==v)if(y=new Int8Array(t),G=new Int32Array(w*t*4),N=w,v=t,0===u){for(;l.childNodes.length>t;)l.removeChild(l.firstChild);for(;l.childNodes.length<t;)l.appendChild(document.createElement("div"));for(w=0;w<t;w++)this.text_update_row(w);
|
|
25
|
-
e(l,q,r,!0)}else 2===u&&this.set_size_graphical_text()};this.set_size_graphical=function(w,t){g.style.display="block";g.width=w;g.height=t;h.imageSmoothingEnabled=!1;x=640>=w&&2*w<window.innerWidth*window.devicePixelRatio&&2*t<window.innerHeight*window.devicePixelRatio?2:1;e(g,q*x,r*x,!1)};this.set_scale=function(w,t){q=w;r=t;e(l,q,r,!0);e(g,q*x,r*x,!1)};this.update_cursor_scanline=function(w,t,H){if(w!==
|
|
26
|
-
w+"px"):m.style.display="none":2===u&&n<v&&(y[n]=1),
|
|
25
|
+
e(l,q,r,!0)}else 2===u&&this.set_size_graphical_text()};this.set_size_graphical=function(w,t){g.style.display="block";g.width=w;g.height=t;h.imageSmoothingEnabled=!1;x=640>=w&&2*w<window.innerWidth*window.devicePixelRatio&&2*t<window.innerHeight*window.devicePixelRatio?2:1;e(g,q*x,r*x,!1)};this.set_scale=function(w,t){q=w;r=t;e(l,q,r,!0);e(g,q*x,r*x,!1)};this.update_cursor_scanline=function(w,t,H){if(w!==pb||t!==Jb||H!==qb)0===u?H?(m.style.display="inline",m.style.height=t-w+"px",m.style.marginTop=
|
|
26
|
+
w+"px"):m.style.display="none":2===u&&n<v&&(y[n]=1),pb=w,Jb=t,qb=H};this.update_cursor=function(w,t){if(w!==n||t!==p)w<v&&(y[w]=1),n<v&&(y[n]=1),n=w,p=t};this.text_update_row=function(w){var t=4*w*N,H;var K=l.childNodes[w];var Q=document.createElement("div");for(var P=0;P<N;){var S=document.createElement("span");var ja=G[t+1]&1;var fa=G[t+2];var Z=G[t+3];ja&&S.classList.add("blink");S.style.backgroundColor=c(fa);S.style.color=c(Z);for(H="";P<N&&(G[t+1]&1)===ja&&G[t+2]===fa&&G[t+3]===Z;)if(H+=Kb[G[t+
|
|
27
27
|
0]],P++,t+=4,w===n)if(P===p)break;else if(P===p+1){m.style.backgroundColor=S.style.color;Q.appendChild(m);break}S.textContent=H;Q.appendChild(S)}K.parentNode.replaceChild(Q,K)};this.update_buffer=function(w){for(const t of w)h.putImageData(t.image_data,t.screen_x-t.buffer_x,t.screen_y-t.buffer_y,t.buffer_x,t.buffer_y,t.buffer_width,t.buffer_height)};this.get_text_screen=function(){for(var w=[],t=0;t<v;t++)w.push(this.get_text_row(t));return w};this.get_text_row=function(w){var t=w*N*4;w=t+4*N;let H=
|
|
28
|
-
"";for(;t<w;t+=4)H+=
|
|
28
|
+
"";for(;t<w;t+=4)H+=Kb[G[t]];return H};this.init()};function A(a){this.buffer=a;this.byteLength=a.byteLength;this.onprogress=this.onload=void 0}A.prototype.load=function(){this.onload&&this.onload({buffer:this.buffer})};A.prototype.get=function(a,b,c){c(new Uint8Array(this.buffer,a,b))};A.prototype.set=function(a,b,c){(new Uint8Array(this.buffer,a,b.byteLength)).set(b);c()};A.prototype.get_buffer=function(a){a(this.buffer)};A.prototype.get_state=function(){const a=[];a[0]=this.byteLength;a[1]=new Uint8Array(this.buffer);return a};
|
|
29
29
|
A.prototype.set_state=function(a){this.byteLength=a[0];this.buffer=a[1].slice().buffer};function xa(a,b,c){this.filename=a;this.byteLength=b;this.block_cache=new Map;this.block_cache_is_write=new Set;this.fixed_chunk_size=c;this.cache_reads=!!c;this.onprogress=this.onload=void 0}xa.prototype.load=async function(){void 0===this.byteLength&&(this.byteLength=await pa(this.filename));this.onload&&this.onload(Object.create(null))};
|
|
30
30
|
xa.prototype.get_from_cache=function(a,b){var c=b/256;a/=256;for(var d=0;d<c;d++)if(!this.block_cache.get(a+d))return;if(1===c)return this.block_cache.get(a);b=new Uint8Array(b);for(d=0;d<c;d++)b.set(this.block_cache.get(a+d),256*d);return b};
|
|
31
31
|
xa.prototype.get=function(a,b,c){var d=this.get_from_cache(a,b);if(d)c(d);else{var e=a,f=b;this.fixed_chunk_size&&(e=a-a%this.fixed_chunk_size,f=Math.ceil((a-e+b)/this.fixed_chunk_size)*this.fixed_chunk_size);oa(this.filename,{done:function(g){g=new Uint8Array(g);this.handle_read(e,f,g);e===a&&f===b?c(g):c(g.subarray(a-e,a-e+b))}.bind(this),range:{start:e,length:f}})}};
|
|
@@ -114,9 +114,9 @@ C.prototype.dma_transfer_start=function(){this.bytes_per_sample=1;this.dsp_16bit
|
|
|
114
114
|
C.prototype.dma_on_unmask=function(a){a===this.dma_channel&&this.dma_waiting_transfer&&(this.dma_waiting_transfer=!1,this.dma_bytes_left=this.dma_bytes_count,this.dma_paused=!1,this.bus.send("dac-enable"))};
|
|
115
115
|
C.prototype.dma_transfer_next=function(){var a=Math.min(this.dma_bytes_left,this.dma_bytes_block),b=Math.floor(a/this.bytes_per_sample);this.dma.do_write(this.dma_syncbuffer,0,a,this.dma_channel,c=>{c||(this.dma_to_dac(b),this.dma_bytes_left-=a,this.dma_bytes_left||(this.raise_irq(this.dma_irq),this.dma_autoinit&&(this.dma_bytes_left=this.dma_bytes_count)))})};
|
|
116
116
|
C.prototype.dma_to_dac=function(a){var b=this.dsp_16bit?32767.5:127.5,c=this.dsp_signed?0:-1,d=this.dsp_stereo?1:2;var e=this.dsp_16bit?this.dsp_signed?this.dma_buffer_int16:this.dma_buffer_uint16:this.dsp_signed?this.dma_buffer_int8:this.dma_buffer_uint8;for(var f=0,g=0;g<a;g++)for(var h=Ra(e[g]/b+c,-1,1),l=0;l<d;l++)this.dac_buffers[f].push(h),f^=1;this.dac_send()};C.prototype.dac_handle_request=function(){!this.dma_bytes_left||this.dma_paused?this.dac_send():this.dma_transfer_next()};
|
|
117
|
-
C.prototype.dac_send=function(){if(this.dac_buffers[0].length){var a=this.dac_buffers[0].shift_block(this.dac_buffers[0].length),b=this.dac_buffers[1].shift_block(this.dac_buffers[1].length);this.bus.send("dac-send-data",[a,b],[a.buffer,b.buffer])}};C.prototype.raise_irq=function(a){this.irq_triggered[a]=1;this.cpu.device_raise_irq(this.irq)};C.prototype.lower_irq=function(a){this.irq_triggered[a]=0;this.cpu.device_lower_irq(this.irq)};function 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,Uint16Array,Int16Array,Uint32Array,Int32Array,Float32Array,Float64Array};
|
|
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
|
-
function db(a,b){if("object"!==typeof a||null===a)return a;if(Array.isArray(a)){for(
|
|
117
|
+
C.prototype.dac_send=function(){if(this.dac_buffers[0].length){var a=this.dac_buffers[0].shift_block(this.dac_buffers[0].length),b=this.dac_buffers[1].shift_block(this.dac_buffers[1].length);this.bus.send("dac-send-data",[a,b],[a.buffer,b.buffer])}};C.prototype.raise_irq=function(a){this.irq_triggered[a]=1;this.cpu.device_raise_irq(this.irq)};C.prototype.lower_irq=function(a){this.irq_triggered[a]=0;this.cpu.device_lower_irq(this.irq)};function 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={Map,Uint8Array,Int8Array,Uint16Array,Int16Array,Uint32Array,Int32Array,Float32Array,Float64Array};
|
|
118
|
+
function cb(a,b){if("object"!==typeof a||null===a)return a;if(Array.isArray(a))return a.map(e=>cb(e,b));if(a instanceof Map)return{__state_type__:"Map",args:Array.from(a.entries()).map(([e,f])=>[cb(e,b),cb(f,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
|
+
function db(a,b){if("object"!==typeof a||null===a)return a;if(Array.isArray(a)){for(var c=0;c<a.length;c++)a[c]=db(a[c],b);return a}c=bb[a.__state_type__];return void 0!==a.args?new c(a.args):new c(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
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
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=>
|
|
@@ -146,12 +146,12 @@ function lb(a,b){function c(d){return function(e){d.gain.setValueAtTime(e,this.a
|
|
|
146
146
|
this.node_treble_right.frequency.setValueAtTime(2E3,this.audio_context.currentTime);this.node_bass_left=this.audio_context.createBiquadFilter();this.node_bass_right=this.audio_context.createBiquadFilter();this.node_bass_left.type="lowshelf";this.node_bass_right.type="lowshelf";this.node_bass_left.frequency.setValueAtTime(200,this.audio_context.currentTime);this.node_bass_right.frequency.setValueAtTime(200,this.audio_context.currentTime);this.node_gain_left=this.audio_context.createGain();this.node_gain_right=
|
|
147
147
|
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);this.node_gain_right.connect(this.node_merger,0,1);this.node_merger.connect(this.audio_context.destination);
|
|
148
148
|
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);e=0===e?this:this.sources.get(e);void 0===e||e.set_volume(d,f)},this);a.register("mixer-gain-left",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);
|
|
149
|
-
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)}lb.prototype.add_source=function(a,b){a=new
|
|
149
|
+
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)}lb.prototype.add_source=function(a,b){a=new nb(this.audio_context,a,this.input_left,this.input_right);this.sources.has(b);this.sources.set(b,a);return a};lb.prototype.connect_source=function(a,b){a=this.sources.get(a);void 0===a||a.connect(b)};
|
|
150
150
|
lb.prototype.disconnect_source=function(a,b){a=this.sources.get(a);void 0===a||a.disconnect(b)};lb.prototype.set_volume=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:return}this.update()};
|
|
151
151
|
lb.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)};
|
|
152
|
-
function
|
|
153
|
-
|
|
154
|
-
|
|
152
|
+
function nb(a,b,c,d){this.audio_context=a;this.connected_right=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)}
|
|
153
|
+
nb.prototype.update=function(){var a=this.connected_right*this.gain_hidden*this.volume_both*this.volume_right;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)};nb.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()};
|
|
154
|
+
nb.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()};nb.prototype.set_volume=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:return}this.update()};nb.prototype.set_gain_hidden=function(a){this.gain_hidden=a};
|
|
155
155
|
function mb(a,b,c){this.node_oscillator=b.createOscillator();this.node_oscillator.type="square";this.node_oscillator.frequency.setValueAtTime(440,b.currentTime);this.mixer_connection=c.add_source(this.node_oscillator,1);this.mixer_connection.disconnect();a.register("pcspeaker-enable",function(){c.connect_source(1)},this);a.register("pcspeaker-disable",function(){c.disconnect_source(1)},this);a.register("pcspeaker-update",function(d){var e=d[1],f=0;3===d[0]&&(f=Math.min(1193181.6665999999/e,this.node_oscillator.frequency.maxValue),
|
|
156
156
|
f=Math.max(f,0));this.node_oscillator.frequency.setValueAtTime(f,b.currentTime)},this)}mb.prototype.start=function(){this.node_oscillator.start()};
|
|
157
157
|
function jb(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=48E3;b=function(){function g(m){if(0===m)return 1;m*=Math.PI;return Math.sin(m)/m}function h(){var m=Reflect.construct(AudioWorkletProcessor,[],h);m.kernel_size=3;m.queue_data=Array(1024);m.queue_start=0;m.queue_end=0;m.queue_length=0;m.queue_size=m.queue_data.length;m.queued_samples=0;m.source_buffer_previous=l;m.source_buffer_current=l;m.source_samples_per_destination=1;m.source_block_start=0;m.source_time=0;m.source_offset=
|
|
@@ -173,16 +173,16 @@ sb.prototype.connect=function(){if("undefined"!==typeof WebSocket){if(this.socke
|
|
|
173
173
|
this.socket.onerror=this.handle_error.bind(this)}}};sb.prototype.send=function(a){this.socket&&1===this.socket.readyState?this.socket.send(a):(this.send_queue.push(a),this.send_queue.length>2*this.send_queue_limit&&(this.send_queue=this.send_queue.slice(-this.send_queue_limit)),this.connect())};sb.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 tb=(new Date("1970-01-01T00:00:00Z")).getTime(),ub=(new Date("1900-01-01T00:00:00Z")).getTime(),vb=tb-ub,wb=Math.pow(2,32),xb=[118,56,54];function yb(a){return[0,1,2,3,4,5].map(b=>a[b].toString(16)).map(b=>1===b.length?"0"+b:b).join(":")}function zb(a){return a[0]<<24|a[1]<<16|a[2]<<8|a[3]}
|
|
174
174
|
class Ab{constructor(a,b){a=Math.min(a,16);this.maximum_capacity=b?Math.max(b,a):0;this.length=this.head=this.tail=0;this.buffer=new Uint8Array(a)}write(a){const b=a.length;var c=this.length+b;let d=this.buffer.length;if(d<c){for(;d<c;)d*=2;if(this.maximum_capacity&&d>this.maximum_capacity)throw Error("stream capacity overflow in GrowableRingbuffer.write(), package dropped");c=new Uint8Array(d);this.peek(c);this.tail=0;this.head=this.length;this.buffer=c}c=this.buffer;const e=this.head+b;if(e>d){const f=
|
|
175
175
|
d-this.head;c.set(a.subarray(0,f),this.head);c.set(a.subarray(f))}else c.set(a,this.head);this.head=e%d;this.length+=b}peek(a){const b=Math.min(this.length,a.length);if(b){const e=this.buffer;var c=e.length,d=this.tail+b;d>c?(d%=c,c-=this.tail,a.set(e.subarray(this.tail)),a.set(e.subarray(0,d),c)):a.set(e.subarray(this.tail,d))}return b}remove(a){a>this.length&&(a=this.length);a&&(this.tail=(this.tail+a)%this.buffer.length,this.length-=a);return a}}
|
|
176
|
-
function Bb(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
|
|
176
|
+
function Bb(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 Cb(a,b,c,d){d.eth_frame.set(b,c.byteOffset+a);return b.length}
|
|
177
177
|
function Mb(a,b,c,d){const e=c.byteOffset+(a&-2);d=d.eth_frame;for(c=c.byteOffset;c<e;c+=2)b+=d[c]<<8|d[c+1];for(a&1&&(b+=d[e]<<8);b>>>16;)b=(b&65535)+(b>>>16);return~b&65535}
|
|
178
|
-
function Nb(a,b){a.eth_frame.fill(0);var c=a.eth_frame,d=c.subarray,e=a.eth_frame_view;
|
|
179
|
-
h.setUint8(0,b.icmp.type);h.setUint8(1,b.icmp.code);h.setUint16(2,0);var l=4+
|
|
180
|
-
b.dhcp.giaddr);
|
|
181
|
-
r.type);x+=2;m.setUint16(x,r.class);x+=2}for(q=0;q<b.dns.answers.length;++q){n=b.dns.answers[q];for(l of n.name)r=a.text_encoder.encodeInto(l,a.eth_frame.subarray(m.byteOffset+(x+1))).written,m.setUint8(x,r),x+=1+r;m.setUint16(x,n.type);x+=2;m.setUint16(x,n.class);x+=2;m.setUint32(x,n.ttl);x+=4;m.setUint16(x,n.data.length);x+=2;x+=
|
|
182
|
-
n.setUint32(4,b.ntp.root_delay),n.setUint32(8,b.ntp.root_disp),n.setUint32(12,b.ntp.ref_id),n.setUint32(16,b.ntp.ref_ts_i),n.setUint32(20,b.ntp.ref_ts_f),n.setUint32(24,b.ntp.ori_ts_i),n.setUint32(28,b.ntp.ori_ts_f),n.setUint32(32,b.ntp.rec_ts_i),n.setUint32(36,b.ntp.rec_ts_f),n.setUint32(40,b.ntp.trans_ts_i),n.setUint32(44,b.ntp.trans_ts_f),l+=48):l=m+
|
|
178
|
+
function Nb(a,b){a.eth_frame.fill(0);var c=a.eth_frame,d=c.subarray,e=a.eth_frame_view;Cb(0,b.eth.dest,e,a);Cb(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);Cb(8,b.arp.sha,f,a);Cb(14,b.arp.spa,f,a);Cb(18,b.arp.tha,f,a);Cb(24,b.arp.tpa,f,a);e+=28}else if(b.ipv4){f=a.eth_payload_view;var g=20;if(b.icmp){var h=a.ipv4_payload_view;
|
|
179
|
+
h.setUint8(0,b.icmp.type);h.setUint8(1,b.icmp.code);h.setUint16(2,0);var l=4+Cb(4,b.icmp.data,h,a);h.setUint16(2,Mb(l,0,h,a));g+=l}else if(b.udp){h=a.ipv4_payload_view;var m=8;if(b.dhcp){l=m;var n=a.udp_payload_view;n.setUint8(0,b.dhcp.op);n.setUint8(1,b.dhcp.htype);n.setUint8(2,b.dhcp.hlen);n.setUint8(3,b.dhcp.hops);n.setUint32(4,b.dhcp.xid);n.setUint16(8,b.dhcp.secs);n.setUint16(10,b.dhcp.flags);n.setUint32(12,b.dhcp.ciaddr);n.setUint32(16,b.dhcp.yiaddr);n.setUint32(20,b.dhcp.siaddr);n.setUint32(24,
|
|
180
|
+
b.dhcp.giaddr);Cb(28,b.dhcp.chaddr,n,a);n.setUint32(236,1669485411);m=240;for(var p of b.dhcp.options)m+=Cb(m,p,n,a);l+=m}else if(b.dns){p=m;m=a.udp_payload_view;m.setUint16(0,b.dns.id);m.setUint16(2,b.dns.flags);m.setUint16(4,b.dns.questions.length);m.setUint16(6,b.dns.answers.length);let x=12;for(var q=0;q<b.dns.questions.length;++q){var r=b.dns.questions[q];for(n of r.name){const y=a.text_encoder.encodeInto(n,a.eth_frame.subarray(m.byteOffset+(x+1))).written;m.setUint8(x,y);x+=1+y}m.setUint16(x,
|
|
181
|
+
r.type);x+=2;m.setUint16(x,r.class);x+=2}for(q=0;q<b.dns.answers.length;++q){n=b.dns.answers[q];for(l of n.name)r=a.text_encoder.encodeInto(l,a.eth_frame.subarray(m.byteOffset+(x+1))).written,m.setUint8(x,r),x+=1+r;m.setUint16(x,n.type);x+=2;m.setUint16(x,n.class);x+=2;m.setUint32(x,n.ttl);x+=4;m.setUint16(x,n.data.length);x+=2;x+=Cb(x,n.data,m,a)}l=p+x}else b.ntp?(l=m,n=a.udp_payload_view,n.setUint8(0,b.ntp.flags),n.setUint8(1,b.ntp.stratum),n.setUint8(2,b.ntp.poll),n.setUint8(3,b.ntp.precision),
|
|
182
|
+
n.setUint32(4,b.ntp.root_delay),n.setUint32(8,b.ntp.root_disp),n.setUint32(12,b.ntp.ref_id),n.setUint32(16,b.ntp.ref_ts_i),n.setUint32(20,b.ntp.ref_ts_f),n.setUint32(24,b.ntp.ori_ts_i),n.setUint32(28,b.ntp.ori_ts_f),n.setUint32(32,b.ntp.rec_ts_i),n.setUint32(36,b.ntp.rec_ts_f),n.setUint32(40,b.ntp.trans_ts_i),n.setUint32(44,b.ntp.trans_ts_f),l+=48):l=m+Cb(0,b.udp.data,a.udp_payload_view,a);m=l;h.setUint16(0,b.udp.sport);h.setUint16(2,b.udp.dport);h.setUint16(4,m);h.setUint16(6,0);h.setUint16(6,Mb(m,
|
|
183
183
|
(b.ipv4.src[0]<<8|b.ipv4.src[1])+(b.ipv4.src[2]<<8|b.ipv4.src[3])+(b.ipv4.dest[0]<<8|b.ipv4.dest[1])+(b.ipv4.dest[2]<<8|b.ipv4.dest[3])+17+m,h,a));g+=m}else b.tcp&&(h=a.ipv4_payload_view,l=0,n=b.tcp,n.fin&&(l|=1),n.syn&&(l|=2),n.rst&&(l|=4),n.psh&&(l|=8),n.ack&&(l|=16),n.urg&&(l|=32),n.ece&&(l|=64),n.cwr&&(l|=128),p=20,n.options&&n.options.mss&&(h.setUint8(p,2),h.setUint8(p+1,4),h.setUint16(p+2,n.options.mss),p+=4),m=4*Math.ceil(p/4),n.options&&0<m-p&&a.eth_frame.fill(0,h.byteOffset+p,h.byteOffset+
|
|
184
|
-
p+(m-p)),h.setUint16(0,n.sport),h.setUint16(2,n.dport),h.setUint32(4,n.seq),h.setUint32(8,n.ackn),h.setUint8(12,m>>2<<4),h.setUint8(13,l),h.setUint16(14,n.winsize),h.setUint16(16,0),h.setUint16(18,n.urgent||0),b.tcp_data&&(m+=
|
|
185
|
-
0);f.setUint8(6,64);f.setUint8(8,b.ipv4.ttl||32);f.setUint8(9,b.ipv4.proto);f.setUint16(10,0);
|
|
184
|
+
p+(m-p)),h.setUint16(0,n.sport),h.setUint16(2,n.dport),h.setUint32(4,n.seq),h.setUint32(8,n.ackn),h.setUint8(12,m>>2<<4),h.setUint8(13,l),h.setUint16(14,n.winsize),h.setUint16(16,0),h.setUint16(18,n.urgent||0),b.tcp_data&&(m+=Cb(20,b.tcp_data,h,a)),h.setUint16(16,Mb(m,(b.ipv4.src[0]<<8|b.ipv4.src[1])+(b.ipv4.src[2]<<8|b.ipv4.src[3])+(b.ipv4.dest[0]<<8|b.ipv4.dest[1])+(b.ipv4.dest[2]<<8|b.ipv4.dest[3])+6+m,h,a)),g+=m);f.setUint8(0,69);f.setUint8(1,b.ipv4.tos||0);f.setUint16(2,g);f.setUint16(4,b.ipv4.id||
|
|
185
|
+
0);f.setUint8(6,64);f.setUint8(8,b.ipv4.ttl||32);f.setUint8(9,b.ipv4.proto);f.setUint16(10,0);Cb(12,b.ipv4.src,f,a);Cb(16,b.ipv4.dest,f,a);f.setUint16(10,Mb(20,0,f,a));e+=g}return d.call(c,0,e)}
|
|
186
186
|
function Ob(a,b){fetch(`https://${b.doh_server||"cloudflare-dns.com"}/dns-query`,{method:"POST",headers:[["content-type","application/dns-message"]],body:a.udp.data}).then(async c=>{c={eth:{ethertype:2048,src:b.router_mac,dest:a.eth.src},ipv4:{proto:17,src:b.router_ip,dest:a.ipv4.src},udp:{sport:53,dport:a.udp.sport,data:new Uint8Array(await c.arrayBuffer())}};b.receive(Nb(b.eth_encoder_buf,c))});return!0}
|
|
187
187
|
function Pb(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:zb(b.vm_ip),siaddr:zb(b.router_ip),giaddr:zb(b.router_ip),chaddr:a.dhcp.chaddr};let d=[],e=a.dhcp.options.find(function(f){return 53===f[0]});e&&3===e[2]&&(a.dhcp.op=3);1===a.dhcp.op&&(c.dhcp.op=2,d.push(new Uint8Array([53,1,2])));3===a.dhcp.op&&(c.dhcp.op=2,d.push(new Uint8Array([53,
|
|
188
188
|
1,5])),d.push(new Uint8Array([51,4,8,0,0,0])));a=[b.router_ip[0],b.router_ip[1],b.router_ip[2],b.router_ip[3]];d.push(new Uint8Array([1,4,255,255,255,0]));b.masquerade&&(d.push(new Uint8Array([3,4].concat(a))),d.push(new Uint8Array([6,4].concat(a))));d.push(new Uint8Array([54,4].concat(a)));d.push(new Uint8Array([60,3].concat(xb)));d.push(new Uint8Array([255,0]));c.dhcp.options=d;b.receive(Nb(b.eth_encoder_buf,c))}
|
package/build/libv86.mjs
CHANGED
|
@@ -9,21 +9,21 @@ pa;if("undefined"===typeof XMLHttpRequest||"undefined"!==typeof process&&process
|
|
|
9
9
|
{filename:a,enc:l})}b.done&&b.done(e.response,e)}};e.onerror=function(l){console.error("Loading the image "+a+" failed",l);d()};b.progress&&(e.onprogress=function(l){b.progress(l)});e.send(null)},pa=async function(a){return new Promise((b,c)=>{oa(a,{done:(d,e)=>{d=e.getResponseHeader("Content-Range")||"";(e=d.match(/\/(\d+)\s*$/))?b(+e[1]):c(Error("`Range: bytes=...` header not supported (Got `"+d+"`)"))},headers:{Range:"bytes=0-0","X-Accept-Encoding":"identity"}})})};function qa(a,b,c){return String.fromCharCode(...(new Uint8Array(a.buffer,
|
|
10
10
|
b>>>0,c>>>0)))}const ra={cp437:" \u263a\u263b\u2665\u2666\u2663\u2660\u2022\u25d8\u25cb\u25d9\u2642\u2640\u266a\u266b\u263c\u25ba\u25c4\u2195\u203c\u00b6\u00a7\u25ac\u21a8\u2191\u2193\u2192\u2190\u221f\u2194\u25b2\u25bc !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u2302\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00a2\u00a3\u00a5\u20a7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u2310\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580\u03b1\u00df\u0393\u03c0\u03a3\u03c3\u00b5\u03c4\u03a6\u0398\u03a9\u03b4\u221e\u03c6\u03b5\u2229\u2261\u00b1\u2265\u2264\u2320\u2321\u00f7\u2248\u00b0\u2219\u00b7\u221a\u207f\u00b2\u25a0 ",
|
|
11
11
|
cp858:"\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00f8\u00a3\u00d8\u00d7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u00ae\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u00c1\u00c2\u00c0\u00a9\u2563\u2551\u2557\u255d\u00a2\u00a5\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u00e3\u00c3\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u00a4\u00f0\u00d0\u00ca\u00cb\u00c8\u20ac\u00cd\u00ce\u00cf\u2518\u250c\u2588\u2584\u00a6\u00cc\u2580\u00d3\u00df\u00d4\u00d2\u00f5\u00d5\u00b5\u00fe\u00de\u00da\u00db\u00d9\u00fd\u00dd\u00af\u00b4\u00ad\u00b1\u2017\u00be\u00b6\u00a7\u00f7\u00b8\u00b0\u00a8\u00b7\u00b9\u00b3\u00b2\u25a0 "};
|
|
12
|
-
ra.cp858=ra.cp437.slice(0,128)+ra.cp858;ra.ascii=ra.cp437.split("").map((a,b)=>31<b&&128>b?a:".").join("");function sa(a){return a&&ra[a]?ra[a]:ra.cp437}function ua(){}function va(){}function wa(a,b){function c(w){w=w.toString(16);return"#"+"0".repeat(6-w.length)+w}function d(w){var t=256*na,H=8*R,K=Ta?Ta.canvas:null;K&&K.width===t&&K.height===H||(K?(K.width=t,K.height=H):(K=new OffscreenCanvas(t,H),Ta=K.getContext("2d")),
|
|
13
|
-
Z;Q[P+3]=Z;Q[P+7]=Z;P+=8}:function(Z){S=S||Z;Q[P+3]=Z;P+=4};K=32-R;const ja=t*(R-1)*4;t=4*(na-t*R);const fa=1020*na;for(let Z=0,Ea=0;2048>Z;++Z,Ea+=K,P+=t){const Fa=Z%256;Z&&!Fa&&(P+=ja);S=!1;for(let La=0;La<R;++La,++Ea,P+=fa){const Ma=w[Ea];for(let ta=128;0<ta;ta>>=1)H(Ma&ta?255:0);
|
|
12
|
+
ra.cp858=ra.cp437.slice(0,128)+ra.cp858;ra.ascii=ra.cp437.split("").map((a,b)=>31<b&&128>b?a:".").join("");function sa(a){return a&&ra[a]?ra[a]:ra.cp437}function ua(){}function va(){}function wa(a,b){function c(w){w=w.toString(16);return"#"+"0".repeat(6-w.length)+w}function d(w){var t=256*na,H=8*R,K=Ta?Ta.canvas:null;K&&K.width===t&&K.height===H||(K?(K.width=t,K.height=H):(K=new OffscreenCanvas(t,H),Ta=K.getContext("2d")),Db=Ta.createImageData(t,H));const Q=Db.data;let P=0,S;H=Eb?function(Z){S=S||
|
|
13
|
+
Z;Q[P+3]=Z;Q[P+7]=Z;P+=8}:function(Z){S=S||Z;Q[P+3]=Z;P+=4};K=32-R;const ja=t*(R-1)*4;t=4*(na-t*R);const fa=1020*na;for(let Z=0,Ea=0;2048>Z;++Z,Ea+=K,P+=t){const Fa=Z%256;Z&&!Fa&&(P+=ja);S=!1;for(let La=0;La<R;++La,++Ea,P+=fa){const Ma=w[Ea];for(let ta=128;0<ta;ta>>=1)H(Ma&ta?255:0);Fb&&H(Gb&&192<=Fa&&223>=Fa&&Ma&1?255:0)}ac[Z]=S?1:0}Ta.putImageData(Db,0,0)}function e(w,t,H,K){if(t&&H){w.style.width="";w.style.height="";K&&(w.style.transform="");var Q=w.getBoundingClientRect();K?w.style.transform=
|
|
14
14
|
(1===t?"":" scaleX("+t+")")+(1===H?"":" scaleY("+H+")"):(0===t%1&&0===H%1?(g.style.imageRendering="crisp-edges",g.style.imageRendering="pixelated",g.style["-ms-interpolation-mode"]="nearest-neighbor"):(g.style.imageRendering="",g.style["-ms-interpolation-mode"]=""),K=window.devicePixelRatio||1,0!==K%1&&(t/=K,H/=K));1!==t&&(w.style.width=Q.width*t+"px");1!==H&&(w.style.height=Q.height*H+"px")}}const f=a.container;this.screen_fill_buffer=b;console.assert(f,"options.container must be provided");this.FLAG_BLINKING=
|
|
15
|
-
1;this.FLAG_FONT_PAGE_B=2;var g=f.getElementsByTagName("canvas")[0],h=g.getContext("2d",{alpha:!1}),l=f.getElementsByTagName("div")[0],m=document.createElement("div"),n,p,q=void 0!==a.scale?a.scale:1,r=void 0!==a.scale?a.scale:1,x=1,y,u,G,N,v,L,T,Ta,
|
|
15
|
+
1;this.FLAG_FONT_PAGE_B=2;var g=f.getElementsByTagName("canvas")[0],h=g.getContext("2d",{alpha:!1}),l=f.getElementsByTagName("div")[0],m=document.createElement("div"),n,p,q=void 0!==a.scale?a.scale:1,r=void 0!==a.scale?a.scale:1,x=1,y,u,G,N,v,L,T,Ta,Db,ac=new Int8Array(2048),R,na,Fb,Eb,Gb,Hb=0,Ib=0,ob,bc=0,pb,Jb,qb,Kb=sa(a.encoding),rb=0,Lb=!1;this.init=function(){m.classList.add("cursor");m.style.position="absolute";m.style.backgroundColor="#ccc";m.style.width="7px";m.style.display="inline-block";
|
|
16
16
|
this.set_mode(!1);this.set_size_text(80,25);2===u&&this.set_size_graphical(720,400,720,400);this.set_scale(q,r);this.timer()};this.make_screenshot=function(){const w=new Image;if(1===u||2===u)w.src=g.toDataURL("image/png");else{const t=[9,16],H=document.createElement("canvas");H.width=N*t[0];H.height=v*t[1];const K=H.getContext("2d");K.imageSmoothingEnabled=!1;K.font=window.getComputedStyle(l).font;K.textBaseline="top";for(let Q=0;Q<v;Q++)for(let P=0;P<N;P++){const S=4*(Q*N+P),ja=G[S+0],fa=G[S+3];
|
|
17
|
-
K.fillStyle=c(G[S+2]);K.fillRect(P*t[0],Q*t[1],t[0],t[1]);K.fillStyle=c(fa);K.fillText(
|
|
18
|
-
this.update_screen=function(){
|
|
19
|
-
w}w=Ta.canvas;t=T.canvas;H=4*N;const Q=N*na,P=R;let S=0;for(let ja=0,fa=0,Z=0;ja<v;++ja,fa+=R){if(!y[ja]){Z+=H;continue}++S;T.clearRect(0,P,Q,R);let Ea,Fa,La,Ma;for(let ta=0;ta<Q;ta+=na,Z+=4){const cc=G[Z+0];var K=G[Z+1];const dc=G[Z+2],ec=G[Z+3],fc=K&2?Hb
|
|
20
|
-
c(Ea);T.fillRect(Fa,0,Q-Fa,R);T.globalCompositeOperation="destination-in";T.drawImage(t,0,P,Q,R,0,0,Q,R);T.globalCompositeOperation="source-over";L.fillStyle=c(La);L.fillRect(Ma,fa,Q-Ma,R);L.drawImage(t,0,0,Q,R,0,fa,Q,R)}S&&(
|
|
21
|
-
!1;m.classList.add("blinking-cursor")};this.set_mode=function(w){u=w?1:a.use_graphical_text?2:0;0===u?(l.style.display="block",g.style.display="none"):(l.style.display="none",g.style.display="block",2===u&&y&&y.fill(1))};this.set_font_bitmap=function(w,t,H,K,Q,P){const S=H?16:t?9:8;if(R!==w||na!==S||
|
|
17
|
+
K.fillStyle=c(G[S+2]);K.fillRect(P*t[0],Q*t[1],t[0],t[1]);K.fillStyle=c(fa);K.fillText(Kb[ja],P*t[0],Q*t[1])}"none"!==m.style.display&&n<v&&p<N&&(K.fillStyle=m.style.backgroundColor,K.fillRect(p*t[0],n*t[1]+parseInt(m.style.marginTop,10),parseInt(m.style.width,10),parseInt(m.style.height,10)));w.src=H.toDataURL("image/png")}return w};this.put_char=function(w,t,H,K,Q,P){t=4*(w*N+t);G[t+0]=H;G[t+1]=K;G[t+2]=Q;G[t+3]=P;y[w]=1};this.timer=function(){rb=requestAnimationFrame(()=>this.update_screen())};
|
|
18
|
+
this.update_screen=function(){Lb||(0===u?this.update_text():1===u?this.update_graphical():this.update_graphical_text());this.timer()};this.update_text=function(){for(var w=0;w<v;w++)y[w]&&(this.text_update_row(w),y[w]=0)};this.update_graphical=function(){this.screen_fill_buffer()};this.update_graphical_text=function(){if(L){var w=performance.now();if(266<w-bc){ob=!ob;qb&&(y[n]=1);var t=4*N;for(let ja=0,fa=0;ja<v;++ja)if(y[ja])fa+=t;else for(var H=0;H<N;++H,fa+=4)if(G[fa+1]&1){y[ja]=1;fa+=t-4*H;break}bc=
|
|
19
|
+
w}w=Ta.canvas;t=T.canvas;H=4*N;const Q=N*na,P=R;let S=0;for(let ja=0,fa=0,Z=0;ja<v;++ja,fa+=R){if(!y[ja]){Z+=H;continue}++S;T.clearRect(0,P,Q,R);let Ea,Fa,La,Ma;for(let ta=0;ta<Q;ta+=na,Z+=4){const cc=G[Z+0];var K=G[Z+1];const dc=G[Z+2],ec=G[Z+3],fc=K&2?Ib:Hb;K=(!(K&1)||ob)&&ac[(fc<<8)+cc];La!==dc&&(void 0!==La&&(L.fillStyle=c(La),L.fillRect(Ma,fa,ta-Ma,R)),La=dc,Ma=ta);Ea!==ec&&(void 0!==Ea&&(T.fillStyle=c(Ea),T.fillRect(Fa,0,ta-Fa,R)),Ea=ec,Fa=ta);K&&T.drawImage(w,cc*na,fc*R,na,R,ta,P,na,R)}T.fillStyle=
|
|
20
|
+
c(Ea);T.fillRect(Fa,0,Q-Fa,R);T.globalCompositeOperation="destination-in";T.drawImage(t,0,P,Q,R,0,0,Q,R);T.globalCompositeOperation="source-over";L.fillStyle=c(La);L.fillRect(Ma,fa,Q-Ma,R);L.drawImage(t,0,0,Q,R,0,fa,Q,R)}S&&(ob&&qb&&y[n]&&(L.fillStyle=c(G[4*(n*N+p)+3]),L.fillRect(p*na,n*R+pb,na,Jb-pb+1)),y.fill(0));S&&h.drawImage(L.canvas,0,0)}};this.destroy=function(){rb&&(cancelAnimationFrame(rb),rb=0)};this.pause=function(){Lb=!0;m.classList.remove("blinking-cursor")};this.continue=function(){Lb=
|
|
21
|
+
!1;m.classList.add("blinking-cursor")};this.set_mode=function(w){u=w?1:a.use_graphical_text?2:0;0===u?(l.style.display="block",g.style.display="none"):(l.style.display="none",g.style.display="block",2===u&&y&&y.fill(1))};this.set_font_bitmap=function(w,t,H,K,Q,P){const S=H?16:t?9:8;if(R!==w||na!==S||Fb!==t||Eb!==H||Gb!==K||P)P=na!==S||R!==w,R=w,na=S,Fb=t,Eb=H,Gb=K,2===u&&(d(Q),y.fill(1),P&&this.set_size_graphical_text())};this.set_font_page=function(w,t){if(Hb!==w||Ib!==t)Hb=w,Ib=t,y.fill(1)};this.clear_screen=
|
|
22
22
|
function(){h.fillStyle="#000";h.fillRect(0,0,g.width,g.height)};this.set_size_graphical_text=function(){if(Ta){var w=na*N,t=R*v,H=2*R;L&&L.canvas.width===w&&L.canvas.height===t&&T.canvas.height===H||(L?(L.canvas.width=w,L.canvas.height=t,T.canvas.width=w,T.canvas.height=H):(L=(new OffscreenCanvas(w,t)).getContext("2d",{alpha:!1}),T=(new OffscreenCanvas(w,H)).getContext("2d")),this.set_size_graphical(w,t,w,t),y.fill(1))}};this.set_size_text=function(w,t){if(w!==N||t!==v)if(y=new Int8Array(t),G=new Int32Array(w*
|
|
23
23
|
t*4),N=w,v=t,0===u){for(;l.childNodes.length>t;)l.removeChild(l.firstChild);for(;l.childNodes.length<t;)l.appendChild(document.createElement("div"));for(w=0;w<t;w++)this.text_update_row(w);e(l,q,r,!0)}else 2===u&&this.set_size_graphical_text()};this.set_size_graphical=function(w,t){g.style.display="block";g.width=w;g.height=t;h.imageSmoothingEnabled=!1;x=640>=w&&2*w<window.innerWidth*window.devicePixelRatio&&2*t<window.innerHeight*window.devicePixelRatio?2:1;e(g,q*x,r*x,!1)};this.set_scale=function(w,
|
|
24
|
-
t){q=w;r=t;e(l,q,r,!0);e(g,q*x,r*x,!1)};this.update_cursor_scanline=function(w,t,H){if(w!==
|
|
25
|
-
G[t+1]&1;var fa=G[t+2];var Z=G[t+3];ja&&S.classList.add("blink");S.style.backgroundColor=c(fa);S.style.color=c(Z);for(H="";P<N&&(G[t+1]&1)===ja&&G[t+2]===fa&&G[t+3]===Z;)if(H+=
|
|
26
|
-
t.buffer_width,t.buffer_height)};this.get_text_screen=function(){for(var w=[],t=0;t<v;t++)w.push(this.get_text_row(t));return w};this.get_text_row=function(w){var t=w*N*4;w=t+4*N;let H="";for(;t<w;t+=4)H+=
|
|
24
|
+
t){q=w;r=t;e(l,q,r,!0);e(g,q*x,r*x,!1)};this.update_cursor_scanline=function(w,t,H){if(w!==pb||t!==Jb||H!==qb)0===u?H?(m.style.display="inline",m.style.height=t-w+"px",m.style.marginTop=w+"px"):m.style.display="none":2===u&&n<v&&(y[n]=1),pb=w,Jb=t,qb=H};this.update_cursor=function(w,t){if(w!==n||t!==p)w<v&&(y[w]=1),n<v&&(y[n]=1),n=w,p=t};this.text_update_row=function(w){var t=4*w*N,H;var K=l.childNodes[w];var Q=document.createElement("div");for(var P=0;P<N;){var S=document.createElement("span");var ja=
|
|
25
|
+
G[t+1]&1;var fa=G[t+2];var Z=G[t+3];ja&&S.classList.add("blink");S.style.backgroundColor=c(fa);S.style.color=c(Z);for(H="";P<N&&(G[t+1]&1)===ja&&G[t+2]===fa&&G[t+3]===Z;)if(H+=Kb[G[t+0]],P++,t+=4,w===n)if(P===p)break;else if(P===p+1){m.style.backgroundColor=S.style.color;Q.appendChild(m);break}S.textContent=H;Q.appendChild(S)}K.parentNode.replaceChild(Q,K)};this.update_buffer=function(w){for(const t of w)h.putImageData(t.image_data,t.screen_x-t.buffer_x,t.screen_y-t.buffer_y,t.buffer_x,t.buffer_y,
|
|
26
|
+
t.buffer_width,t.buffer_height)};this.get_text_screen=function(){for(var w=[],t=0;t<v;t++)w.push(this.get_text_row(t));return w};this.get_text_row=function(w){var t=w*N*4;w=t+4*N;let H="";for(;t<w;t+=4)H+=Kb[G[t]];return H};this.init()}function A(a){this.buffer=a;this.byteLength=a.byteLength;this.onprogress=this.onload=void 0}A.prototype.load=function(){this.onload&&this.onload({buffer:this.buffer})};A.prototype.get=function(a,b,c){c(new Uint8Array(this.buffer,a,b))};A.prototype.set=function(a,b,
|
|
27
27
|
c){(new Uint8Array(this.buffer,a,b.byteLength)).set(b);c()};A.prototype.get_buffer=function(a){a(this.buffer)};A.prototype.get_state=function(){const a=[];a[0]=this.byteLength;a[1]=new Uint8Array(this.buffer);return a};A.prototype.set_state=function(a){this.byteLength=a[0];this.buffer=a[1].slice().buffer};function xa(a,b,c){this.filename=a;this.byteLength=b;this.block_cache=new Map;this.block_cache_is_write=new Set;this.fixed_chunk_size=c;this.cache_reads=!!c;this.onprogress=this.onload=void 0}xa.prototype.load=
|
|
28
28
|
async function(){void 0===this.byteLength&&(this.byteLength=await pa(this.filename));this.onload&&this.onload(Object.create(null))};xa.prototype.get_from_cache=function(a,b){var c=b/256;a/=256;for(var d=0;d<c;d++)if(!this.block_cache.get(a+d))return;if(1===c)return this.block_cache.get(a);b=new Uint8Array(b);for(d=0;d<c;d++)b.set(this.block_cache.get(a+d),256*d);return b};xa.prototype.get=function(a,b,c){var d=this.get_from_cache(a,b);if(d)c(d);else{var e=a,f=b;this.fixed_chunk_size&&(e=a-a%this.fixed_chunk_size,
|
|
29
29
|
f=Math.ceil((a-e+b)/this.fixed_chunk_size)*this.fixed_chunk_size);oa(this.filename,{done:function(g){g=new Uint8Array(g);this.handle_read(e,f,g);e===a&&f===b?c(g):c(g.subarray(a-e,a-e+b))}.bind(this),range:{start:e,length:f}})}};xa.prototype.set=function(a,b,c){a/=256;for(var d=b.length/256,e=0;e<d;e++){var f=this.block_cache.get(a+e);if(void 0===f)f=b.slice(256*e,256*(e+1)),this.block_cache.set(a+e,f);else{const g=b.subarray(256*e,256*(e+1));f.set(g)}this.block_cache_is_write.add(a+e)}c()};xa.prototype.handle_read=
|
|
@@ -100,122 +100,122 @@ Ya(Za(128,149),function(){});Ya(Za(160,168),function(){});Ya(Za(176,184),functio
|
|
|
100
100
|
8)};C.prototype.dma_transfer_start=function(){this.bytes_per_sample=1;this.dsp_16bit&&(this.bytes_per_sample*=2);this.dma_bytes_count=this.dma_sample_count*this.bytes_per_sample;this.dma_bytes_block=1024*this.bytes_per_sample;this.dma_bytes_block=Math.min(Math.max(this.dma_bytes_count>>2&-4,32),this.dma_bytes_block);this.dma_waiting_transfer=!0;this.dma.channel_mask[this.dma_channel]||this.dma_on_unmask(this.dma_channel)};C.prototype.dma_on_unmask=function(a){a===this.dma_channel&&this.dma_waiting_transfer&&
|
|
101
101
|
(this.dma_waiting_transfer=!1,this.dma_bytes_left=this.dma_bytes_count,this.dma_paused=!1,this.bus.send("dac-enable"))};C.prototype.dma_transfer_next=function(){var a=Math.min(this.dma_bytes_left,this.dma_bytes_block),b=Math.floor(a/this.bytes_per_sample);this.dma.do_write(this.dma_syncbuffer,0,a,this.dma_channel,c=>{c||(this.dma_to_dac(b),this.dma_bytes_left-=a,this.dma_bytes_left||(this.raise_irq(this.dma_irq),this.dma_autoinit&&(this.dma_bytes_left=this.dma_bytes_count)))})};C.prototype.dma_to_dac=
|
|
102
102
|
function(a){var b=this.dsp_16bit?32767.5:127.5,c=this.dsp_signed?0:-1,d=this.dsp_stereo?1:2;var e=this.dsp_16bit?this.dsp_signed?this.dma_buffer_int16:this.dma_buffer_uint16:this.dsp_signed?this.dma_buffer_int8:this.dma_buffer_uint8;for(var f=0,g=0;g<a;g++)for(var h=Ra(e[g]/b+c,-1,1),l=0;l<d;l++)this.dac_buffers[f].push(h),f^=1;this.dac_send()};C.prototype.dac_handle_request=function(){!this.dma_bytes_left||this.dma_paused?this.dac_send():this.dma_transfer_next()};C.prototype.dac_send=function(){if(this.dac_buffers[0].length){var a=
|
|
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,
|
|
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)-
|
|
105
|
-
typeof a||null===a)return a;if(Array.isArray(a)){for(
|
|
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,
|
|
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+
|
|
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=
|
|
109
|
-
|
|
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,
|
|
111
|
-
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,
|
|
112
|
-
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;
|
|
113
|
-
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=a[11];this.update_interrupt=a[12]||!1;this.update_interrupt_time=a[13]||0;this.cmos_diag_status=a[14]||0};gb.prototype.timer=
|
|
114
|
-
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|=160,this.next_interrupt_alarm=0):this.update_interrupt&&this.update_interrupt_time<a&&(this.cpu.device_raise_irq(8),
|
|
115
|
-
(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};gb.prototype.bcd_pack=function(a){for(var b=0,c=0,d;a;)d=a%10,c|=d<<4*b,b++,a=(a-d)/10;return c};gb.prototype.bcd_unpack=function(a){return(a&15)+10*(a>>4&15)};gb.prototype.encode_time=
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
1E3?this.cmos_a|128:this.cmos_a;case 11:return this.cmos_b;case 12:return this.cpu.device_lower_irq(8),a=this.cmos_c,this.cmos_c&=-241,a;case 13:return 128;case 14:return this.cmos_diag_status;case 50:case 55:return z(this.encode_time((new Date(this.rtc_time)).getUTCFullYear()/100|0)),this.encode_time((new Date(this.rtc_time)).getUTCFullYear()/100|0);default:return z(a),this.cmos_data[this.cmos_index]}};
|
|
119
|
-
1E3/(32768>>(this.cmos_a&15)-1);z(this.cmos_a,2);break;case 11:this.cmos_b=a;this.cmos_b&128&&(this.cmos_b&=239);this.cmos_b&64&&(this.next_interrupt=Date.now());if(this.cmos_b&32){a=new Date;const b=this.decode_time(this.cmos_data[1]),c=this.decode_time(this.cmos_data[3]),d=this.decode_time(this.cmos_data[5]);this.next_interrupt_alarm=+new Date(Date.UTC(a.getUTCFullYear(),a.getUTCMonth(),
|
|
120
|
-
a;break;case 1:case 3:case 5:this.cmos_write(this.cmos_index,a);break;default:z(this.cmos_index),z(a)}this.update_interrupt=16===(this.cmos_b&16)&&0<(this.cmos_a&15);this.periodic_interrupt=64===(this.cmos_b&64)&&0<(this.cmos_a&15)};gb.prototype.cmos_read=function(a){return this.cmos_data[a]};gb.prototype.cmos_write=function(a,b){z(a);z(b);this.cmos_data[a]=b};function hb(a,
|
|
121
|
-
new Uint8Array(4);this.counter_enabled=new Uint8Array(4);this.counter_mode=new Uint8Array(4);this.counter_read_mode=new Uint8Array(4);this.counter_latch=new Uint8Array(4);this.counter_latch_value=new Uint16Array(3);this.counter_reload=new Uint16Array(3);a.io.register_read(97,this,function(){var c=E.microtick(),d=66.66666666666667*c&1;c=this.did_rollover(2,c);return d<<
|
|
122
|
-
this,function(){return this.counter_read(0)});a.io.register_read(65,this,function(){return this.counter_read(1)});a.io.register_read(66,this,function(){return this.counter_read(2)});a.io.register_write(64,this,function(c){this.counter_write(0,c)});a.io.register_write(65,this,function(c){this.counter_write(1,c)});a.io.register_write(66,this,function(c){this.counter_write(2,
|
|
123
|
-
hb.prototype.get_state=function(){var a=[];a[0]=this.counter_next_low;a[1]=this.counter_enabled;a[2]=this.counter_mode;a[3]=this.counter_read_mode;a[4]=this.counter_latch;a[5]=this.counter_latch_value;a[6]=this.counter_reload;a[7]=this.counter_start_time;a[8]=this.counter_start_value;return a};hb.prototype.set_state=function(a){this.counter_next_low=a[0];this.counter_enabled=
|
|
124
|
-
a[6];this.counter_start_time=a[7];this.counter_start_value=a[8]};hb.prototype.timer=function(a,b){var c=100;b||(this.counter_enabled[0]&&this.did_rollover(0,a)?(this.counter_start_value[0]=this.get_counter_value(0,a),this.counter_start_time[0]=a,this.cpu.device_lower_irq(0),this.cpu.device_raise_irq(0),0===this.counter_mode[0]&&(this.counter_enabled[0]=0)):this.cpu.device_lower_irq(0),
|
|
125
|
-
1193.1816666));return c};hb.prototype.get_counter_value=function(a,b){if(!this.counter_enabled[a])return 0;b=this.counter_start_value[a]-Math.floor(1193.1816666*(b-this.counter_start_time[a]));a=this.counter_reload[a];b>=a?b%=a:0>b&&(b=b%a+a);return b};hb.prototype.did_rollover=function(a,b){b-=this.counter_start_time[a];return 0>b?!0:this.counter_start_value[a]<Math.floor(1193.1816666*
|
|
126
|
-
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,E.microtick());return b?a&255:a>>8};hb.prototype.counter_write=function(a,b){this.counter_reload[a]=this.counter_next_low[a]?this.counter_reload[a]&-256|b:this.counter_reload[a]&255|b<<8;3===this.counter_read_mode[a]&&
|
|
127
|
-
this.counter_reload[a],this.counter_enabled[a]=!0,this.counter_start_time[a]=E.microtick(),z(this.counter_reload[a]));3===this.counter_read_mode[a]&&(this.counter_next_low[a]^=1)};hb.prototype.port43_write=function(a){var b=a>>1&7,c=a>>6&3;a=a>>4&3;3!==c&&(0===a?(this.counter_latch[c]=2,b=this.get_counter_value(c,E.microtick()),this.counter_latch_value[c]=b?b-1:0):(6<=b&&(b&=-5),this.counter_next_low[c]=
|
|
128
|
-
b,this.counter_read_mode[c]=a,2===c&&this.bus.send("pcspeaker-update",[this.counter_mode[2],this.counter_reload[2]])))};hb.prototype.dump=function(){};function ib(a){if("undefined"!==typeof window)if(window.AudioContext||window.webkitAudioContext){var b=window.AudioWorklet?jb:kb;this.bus=a;this.audio_context=window.AudioContext?new AudioContext:new webkitAudioContext;this.mixer=new lb(a,this.audio_context);
|
|
129
|
-
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")}ib.prototype.destroy=function(){this.audio_context&&
|
|
130
|
-
this.dac.node_processor.port.close();this.dac=null};function lb(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=
|
|
131
|
-
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,
|
|
132
|
-
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);
|
|
133
|
-
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);e=0===e?this:this.sources.get(e);void 0===e||e.set_volume(d,f)},this);a.register("mixer-gain-left",function(d){this.gain_left=Math.pow(10,d/20);this.update()},
|
|
134
|
-
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)}lb.prototype.add_source=function(a,b){a=new
|
|
135
|
-
function(a,b){a=this.sources.get(a);void 0===a||a.disconnect(b)};lb.prototype.set_volume=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:return}this.update()};lb.prototype.update=function(){var a=this.volume_both*this.volume_right*this.gain_right;this.node_gain_left.gain.setValueAtTime(this.volume_both*
|
|
136
|
-
this.audio_context.currentTime)};function
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
this.mixer_connection=c.add_source(this.node_oscillator,1);this.mixer_connection.disconnect();a.register("pcspeaker-enable",function(){c.connect_source(1)},this);a.register("pcspeaker-disable",function(){c.disconnect_source(1)},this);a.register("pcspeaker-update",function(d){var e=d[1],f=0;3===d[0]&&(f=Math.min(1193181.6665999999/e,this.node_oscillator.frequency.maxValue),f=Math.max(f,0));this.node_oscillator.frequency.setValueAtTime(f,
|
|
140
|
-
function jb(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=48E3;b=function(){function g(m){if(0===m)return 1;m*=Math.PI;return Math.sin(m)/m}function h(){var m=Reflect.construct(AudioWorkletProcessor,[],h);m.kernel_size=3;m.queue_data=Array(1024);m.queue_start=0;m.queue_end=0;m.queue_length=0;m.queue_size=m.queue_data.length;m.queued_samples=0;m.source_buffer_previous=l;m.source_buffer_current=
|
|
141
|
-
0;m.port.onmessage=n=>{switch(n.data.type){case "queue":m.queue_push(n.data.value);break;case "sampling-rate":m.source_samples_per_destination=n.data.value/sampleRate}};return m}var l=[new Float32Array(256),new Float32Array(256)];Reflect.setPrototypeOf(h.prototype,AudioWorkletProcessor.prototype);Reflect.setPrototypeOf(h,AudioWorkletProcessor);h.prototype.process=h.prototype.process=function(m,n){for(m=0;m<
|
|
142
|
-
this.kernel_size+1;x<=r;x++){var y=this.source_block_start+x;p+=this.get_sample(y,0)*this.kernel(this.source_time-x);q+=this.get_sample(y,1)*this.kernel(this.source_time-x)}if(isNaN(p)||isNaN(q))p=q=0,this.dbg_log("ERROR: NaN values! Ignoring for now.");n[0][0][m]=p;n[0][1][m]=q;this.source_time+=this.source_samples_per_destination;this.source_offset=Math.floor(this.source_time)}n=this.source_offset;n+=
|
|
143
|
-
this.source_offset=0;this.ensure_enough_data(n);return!0};h.prototype.kernel=function(m){return g(m)*g(m/this.kernel_size)};h.prototype.get_sample=function(m,n){return 0>m?(m+=this.source_buffer_previous[0].length,this.source_buffer_previous[n][m]):this.source_buffer_current[n][m]};h.prototype.ensure_enough_data=function(m){var n=this.source_buffer_current[0].length;n-this.source_block_start<m&&(this.prepare_next_buffer(),
|
|
144
|
-
this.queued_samples&&this.queue_length&&this.dbg_log("Not enough samples - should not happen during midway of playback");this.source_buffer_previous=this.source_buffer_current;this.source_buffer_current=this.queue_shift();var m=this.source_buffer_current[0].length;if(256>m){for(var n=this.queue_start,p=0;256>m&&p<this.queue_length;)m+=this.queue_data[n][0].length,n=n+1&this.queue_size-1,p++;m=Math.max(m,256);m=[new Float32Array(m),
|
|
145
|
-
n=this.source_buffer_current[0].length;for(var q=0;q<p;q++){var r=this.queue_shift();m[0].set(r[0],n);m[1].set(r[1],n);n+=r[0].length}this.source_buffer_current=m}this.pump()};h.prototype.pump=function(){1024>this.queued_samples/this.source_samples_per_destination&&this.port.postMessage({type:"pump"})};h.prototype.queue_push=function(m){this.queue_length<this.queue_size&&(this.queue_data[this.queue_end]=
|
|
146
|
-
this.pump())};h.prototype.queue_shift=function(){if(!this.queue_length)return l;var m=this.queue_data[this.queue_start];this.queue_data[this.queue_start]=null;this.queue_start=this.queue_start+1&this.queue_size-1;this.queue_length--;this.queued_samples-=m[0].length;return m};h.prototype.dbg_log=function(){};registerProcessor("dac-processor",h)}.toString();var d=b.indexOf("{")+1,e=b.lastIndexOf("}");
|
|
147
|
-
null;this.node_output=this.audio_context.createGain();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});
|
|
148
|
-
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){this.sampling_rate=g;this.node_processor&&this.node_processor.port.postMessage({type:"sampling-rate",
|
|
149
|
-
value:a},[a[0].buffer,a[1].buffer])};jb.prototype.pump=function(){this.enabled&&this.bus.send("dac-request-data")};function kb(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=this.node_lowpass;this.mixer_connection=
|
|
150
|
-
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){this.sampling_rate=d;this.rate_ratio=Math.ceil(8E3/d);this.node_lowpass.frequency.setValueAtTime(d/2,this.audio_context.currentTime)},this)}kb.prototype.queue=function(a){var b=a[0].length,c=
|
|
151
|
-
for(var e=d.getChannelData(0),f=d.getChannelData(1),g=0,h=0;h<b;h++)for(var l=0;l<this.rate_ratio;l++,g++)e[g]=a[0][h],f[g]=a[1][h]}else d=this.audio_context.createBuffer(2,b,this.sampling_rate),d.copyToChannel?(d.copyToChannel(a[0],0),d.copyToChannel(a[1],1)):(d.getChannelData(0).set(a[0]),d.getChannelData(1).set(a[1]));a=this.audio_context.createBufferSource();
|
|
152
|
-
d)for(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);this.buffered_time+=c;setTimeout(()=>this.pump(),0)};kb.prototype.pump=function(){this.enabled&&(.2<this.buffered_time-this.audio_context.currentTime||this.bus.send("dac-request-data"))};function sb(a,b,c){this.bus=b;this.socket=
|
|
153
|
-
this.send_queue_limit=64;this.destroyed=!1;this.bus.register("net"+this.id+"-send",function(d){this.send(d)},this)}sb.prototype.handle_message=function(a){this.bus&&this.bus.send("net"+this.id+"-receive",new Uint8Array(a.data))};sb.prototype.handle_close=function(){this.destroyed||(this.connect(),setTimeout(this.connect.bind(this),this.reconnect_interval))};sb.prototype.handle_open=
|
|
154
|
-
function(){};sb.prototype.destroy=function(){this.destroyed=!0;this.socket&&this.socket.close()};sb.prototype.connect=function(){if("undefined"!==typeof WebSocket){if(this.socket){var a=this.socket.readyState;if(0===a||1===a)return}a=Date.now();if(!(this.last_connect_attempt+this.reconnect_interval>a)){this.last_connect_attempt=Date.now();try{this.socket=new WebSocket(this.url)}catch(b){console.error(b);
|
|
155
|
-
this.handle_message.bind(this);this.socket.onclose=this.handle_close.bind(this);this.socket.onerror=this.handle_error.bind(this)}}};sb.prototype.send=function(a){this.socket&&1===this.socket.readyState?this.socket.send(a):(this.send_queue.push(a),this.send_queue.length>2*this.send_queue_limit&&(this.send_queue=this.send_queue.slice(-this.send_queue_limit)),this.connect())};sb.prototype.change_proxy=
|
|
156
|
-
this.socket.close(),this.socket=void 0)};const tb=(new Date("1970-01-01T00:00:00Z")).getTime(),ub=(new Date("1900-01-01T00:00:00Z")).getTime(),vb=tb-ub,wb=Math.pow(2,32),xb=[118,56,54];function yb(a){return[0,1,2,3,4,5].map(b=>a[b].toString(16)).map(b=>1===b.length?"0"+b:b).join(":")}function zb(a){return a[0]<<24|a[1]<<16|a[2]<<8|a[3]}class Ab{constructor(a,b){a=Math.min(a,16);this.maximum_capacity=
|
|
157
|
-
a.length;var c=this.length+b;let d=this.buffer.length;if(d<c){for(;d<c;)d*=2;if(this.maximum_capacity&&d>this.maximum_capacity)throw Error("stream capacity overflow in GrowableRingbuffer.write(), package dropped");c=new Uint8Array(d);this.peek(c);this.tail=0;this.head=this.length;this.buffer=c}c=this.buffer;const e=this.head+b;if(e>d){const f=d-this.head;c.set(a.subarray(0,f),this.head);c.set(a.subarray(f))}else c.set(a,
|
|
158
|
-
a.length);if(b){const e=this.buffer;var c=e.length,d=this.tail+b;d>c?(d%=c,c-=this.tail,a.set(e.subarray(this.tail)),a.set(e.subarray(0,d),c)):a.set(e.subarray(this.tail,d))}return b}remove(a){a>this.length&&(a=this.length);a&&(this.tail=(this.tail+a)%this.buffer.length,this.length-=a);return a}}function Bb(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),
|
|
159
|
-
f+34,b),udp_payload_view:new DataView(e,f+42,c),text_encoder:new TextEncoder}}function
|
|
160
|
-
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);
|
|
161
|
-
var m=8;if(b.dhcp){l=m;var n=a.udp_payload_view;n.setUint8(0,b.dhcp.op);n.setUint8(1,b.dhcp.htype);n.setUint8(2,b.dhcp.hlen);n.setUint8(3,b.dhcp.hops);n.setUint32(4,b.dhcp.xid);n.setUint16(8,b.dhcp.secs);n.setUint16(10,b.dhcp.flags);n.setUint32(12,b.dhcp.ciaddr);n.setUint32(16,b.dhcp.yiaddr);n.setUint32(20,b.dhcp.siaddr);n.setUint32(24,b.dhcp.giaddr);
|
|
162
|
-
b.dns.id);m.setUint16(2,b.dns.flags);m.setUint16(4,b.dns.questions.length);m.setUint16(6,b.dns.answers.length);let x=12;for(var q=0;q<b.dns.questions.length;++q){var r=b.dns.questions[q];for(n of r.name){const y=a.text_encoder.encodeInto(n,a.eth_frame.subarray(m.byteOffset+(x+1))).written;m.setUint8(x,y);x+=1+y}m.setUint16(x,r.type);x+=2;m.setUint16(x,r.class);x+=2}for(q=0;q<b.dns.answers.length;++q){n=b.dns.answers[q];for(l of n.name)r=
|
|
163
|
-
(x+1))).written,m.setUint8(x,r),x+=1+r;m.setUint16(x,n.type);x+=2;m.setUint16(x,n.class);x+=2;m.setUint32(x,n.ttl);x+=4;m.setUint16(x,n.data.length);x+=2;x+=
|
|
164
|
-
n.setUint32(28,b.ntp.ori_ts_f),n.setUint32(32,b.ntp.rec_ts_i),n.setUint32(36,b.ntp.rec_ts_f),n.setUint32(40,b.ntp.trans_ts_i),n.setUint32(44,b.ntp.trans_ts_f),l+=48):l=m+
|
|
165
|
-
l=0,n=b.tcp,n.fin&&(l|=1),n.syn&&(l|=2),n.rst&&(l|=4),n.psh&&(l|=8),n.ack&&(l|=16),n.urg&&(l|=32),n.ece&&(l|=64),n.cwr&&(l|=128),p=20,n.options&&n.options.mss&&(h.setUint8(p,2),h.setUint8(p+1,4),h.setUint16(p+2,n.options.mss),p+=4),m=4*Math.ceil(p/4),n.options&&0<m-p&&a.eth_frame.fill(0,h.byteOffset+p,h.byteOffset+p+(m-p)),h.setUint16(0,n.sport),h.setUint16(2,n.dport),h.setUint32(4,n.seq),h.setUint32(8,n.ackn),h.setUint8(12,m>>2<<
|
|
166
|
-
n.urgent||0),b.tcp_data&&(m+=
|
|
167
|
-
e)}function Ob(a,b){fetch(`https://${b.doh_server||"cloudflare-dns.com"}/dns-query`,{method:"POST",headers:[["content-type","application/dns-message"]],body:a.udp.data}).then(async c=>{c={eth:{ethertype:2048,src:b.router_mac,dest:a.eth.src},ipv4:{proto:17,src:b.router_ip,dest:a.ipv4.src},udp:{sport:53,dport:a.udp.sport,data:new Uint8Array(await c.arrayBuffer())}};b.receive(Nb(b.eth_encoder_buf,c))});return!0}function Pb(a,
|
|
168
|
-
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:zb(b.vm_ip),siaddr:zb(b.router_ip),giaddr:zb(b.router_ip),chaddr:a.dhcp.chaddr};let d=[],e=a.dhcp.options.find(function(f){return 53===f[0]});e&&3===e[2]&&(a.dhcp.op=3);1===a.dhcp.op&&(c.dhcp.op=2,d.push(new Uint8Array([53,1,2])));3===a.dhcp.op&&(c.dhcp.op=2,d.push(new Uint8Array([53,
|
|
169
|
-
b.router_ip[3]];d.push(new Uint8Array([1,4,255,255,255,0]));b.masquerade&&(d.push(new Uint8Array([3,4].concat(a))),d.push(new Uint8Array([6,4].concat(a))));d.push(new Uint8Array([54,4].concat(a)));d.push(new Uint8Array([60,3].concat(xb)));d.push(new Uint8Array([255,0]));c.dhcp.options=d;b.receive(Nb(b.eth_encoder_buf,c))}function Qb(a,b){let c={};var d=(new DataView(a.buffer,a.byteOffset,a.byteLength)).getUint16(12),
|
|
170
|
-
src_s:yb(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 h=f.getUint8(1),l=f.getUint16(2);let m=f.getUint8(8);d=f.getUint8(9);f=f.getUint16(10);g={version:g,ihl:e,tos:h,len:l,ttl:m,proto:d,ip_checksum:f,src:a.subarray(12,16),dest:a.subarray(16,20)};c.ipv4=g;e=a.subarray(4*e,l);if(1===d)a=new DataView(e.buffer,e.byteOffset,
|
|
171
|
-
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),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=
|
|
172
|
-
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))};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),
|
|
173
|
-
chaddr:e.subarray(28,44),magic:d.getUint32(236),options:[]};e=e.subarray(240);for(l=0;l<e.length;++l)g=l,0!==e[l]&&(++l,h=e[l],l+=h,d.options.push(e.subarray(g,g+h+2)));c.dhcp=d;c.dhcp_options=d.options}else 53===a.dport||53===a.sport?Rb(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),
|
|
174
|
-
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),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&&
|
|
175
|
-
if(c.tcp.syn&&!c.tcp.ack){b.tcp_conn[a]&&delete b.tcp_conn[a];d=new Sb(b);d.state="syn-received";d.tuple=a;d.last=c;d.hsrc=c.eth.dest;d.psrc=c.ipv4.dest;d.sport=c.tcp.dport;d.hdest=c.eth.src;d.dport=c.tcp.sport;d.pdest=c.ipv4.src;b.bus.pair.send("tcp-connection",d);if(b.on_tcp_connection)b.on_tcp_connection(d,c);if(b.tcp_conn[a])break a}if(b.tcp_conn[a])b.tcp_conn[a].process(c);else{a=c.tcp.ackn;
|
|
176
|
-
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(Nb(b.eth_encoder_buf,d))}}else if(c.udp)if(c.dns)if("static"===b.dns_method){a={};a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src};a.ipv4={proto:17,src:b.router_ip,dest:c.ipv4.src};a.udp={sport:53,dport:c.udp.sport};d=[];for(e=
|
|
177
|
-
class:l.class,ttl:600,data:[192,168,87,1]})}a.dns={id:c.dns.id,flags:33152,questions:c.dns.questions,answers:d};b.receive(Nb(b.eth_encoder_buf,a))}else Ob(c,b);else c.dhcp?Pb(c,b):c.ntp?(a=Date.now()+vb,d=a%1E3/1E3*wb,e={},e.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},e.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},e.udp={sport:123,dport:c.udp.sport},e.ntp=Object.assign({},c.ntp),e.ntp.flags=
|
|
178
|
-
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(Nb(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},a.udp={sport:c.udp.dport,dport:c.udp.sport,data:(new TextEncoder).encode(c.udp.data_s)},b.receive(Nb(b.eth_encoder_buf,a)));else c.icmp&&8===c.icmp.type&&(a={},
|
|
179
|
-
a.icmp={type:0,code:c.icmp.code,data:c.icmp.data},b.receive(Nb(b.eth_encoder_buf,a)));else c.arp&&1===c.arp.oper&&2048===c.arp.ptype&&(a=zb(c.arp.tpa)&4294967040,d=zb(b.router_ip)&4294967040,!b.masquerade&&a!==d||a===d&&99<c.arp.tpa[3]||(a={},a.eth={ethertype:2054,src:b.router_mac,dest:c.eth.src},a.arp={htype:1,ptype:2048,oper:2,sha:b.router_mac,spa:c.arp.tpa,tha:c.eth.src,tpa:c.arp.spa},b.receive(Nb(b.eth_encoder_buf,
|
|
180
|
-
1,h+1+n))),h+=n+1;while(0<n);return m}let d=new DataView(a.buffer,a.byteOffset,a.byteLength),e={id:d.getUint16(0),flags:d.getUint16(2),questions:[],answers:[]};var f=d.getUint16(4);let g=d.getUint16(6);d.getUint16(8);d.getUint16(10);let h=12;for(var l=0;l<f;l++)e.questions.push({name:c(),type:d.getInt16(h),class:d.getInt16(h+2)}),h+=4;for(f=0;f<g;f++){l={name:c(),type:d.getInt16(h),class:d.getUint16(h+
|
|
181
|
-
e}function Tb(a,b){var c=b.vm_ip.join(".");const d=b.router_ip.join("."),e=16383*Math.random()|0;let f,g,h=0;do f=49152+(e+h)%16383,g=`${c}:${a}:${d}:${f}`;while(16383>++h&&b.tcp_conn[g]);if(b.tcp_conn[g])throw Error("pool of dynamic TCP port numbers exhausted, connection aborted");c=new Sb(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;
|
|
182
|
-
d.on("probe",c)})}function Sb(a){this.mtu=a.mtu||1500;const b=this.mtu-20-20;this.state="closed";this.net=a;this.send_buffer=new Ab(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={}}Sb.prototype.on=function(a,b){this.events_handlers[a]=b};Sb.prototype.emit=function(a,...b){this.events_handlers[a]&&
|
|
183
|
-
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};Sb.prototype.packet_reply=function(a,b){a={sport:a.tcp.dport,dport:a.tcp.sport,winsize:a.tcp.winsize,ackn:this.ack,seq:this.seq};if(b)for(const c in b)a[c]=b[c];b=this.ipv4_reply();b.tcp=a;return b};Sb.prototype.connect=
|
|
184
|
-
"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(Nb(this.net.eth_encoder_buf,a))};Sb.prototype.accept=function(a){a=a||this.last;this.net.tcp_conn[this.tuple]=this;this.seq=1338;this.ack=a.tcp.seq+1;this.start_seq=a.tcp.seq;this.winsize=a.tcp.winsize;let b=this.ipv4_reply();b.tcp={sport:this.sport,
|
|
185
|
-
"established";this.net.receive(Nb(this.net.eth_encoder_buf,b))};Sb.prototype.process=function(a){this.last=a;if("closed"===this.state)a=this.packet_reply(a,{rst:!0}),this.net.receive(Nb(this.net.eth_encoder_buf,a));else if(a.tcp.rst){if("syn-probe"===this.state)this.emit("probe",!1);else this.on_close();this.release()}else if(a.tcp.syn)"syn-sent"===this.state&&a.tcp.ack?(this.ack=a.tcp.seq+
|
|
186
|
-
a)),this.state="established",this.emit("connect")):"syn-probe"===this.state&&a.tcp.ack&&(this.emit("probe",!0),a=this.packet_reply(a,{rst:!0}),this.net.receive(Nb(this.net.eth_encoder_buf,a)),this.release());else{if(a.tcp.ack)if("syn-received"===this.state)this.state="established";else if("fin-wait-1"===this.state)a.tcp.fin||(this.state="fin-wait-2");else if("closing"===this.state||
|
|
187
|
-
else{var b=a.tcp.ackn-this.last_received_ackn;if(0<b){if(this.last_received_ackn=a.tcp.ackn,this.send_buffer.remove(b),this.seq+=b,this.pending=!1,this.delayed_send_fin&&!this.send_buffer.length){this.delayed_send_fin=!1;this.state=this.delayed_state;a=this.ipv4_reply();a.tcp.fin=!0;this.net.receive(Nb(this.net.eth_encoder_buf,a));return}}else if(0>b){a=this.packet_reply(a,{rst:!0});
|
|
188
|
-
{}),"established"===this.state?(b.tcp.ack=!0,this.state="close-wait",this.on_shutdown()):"fin-wait-1"===this.state?(a.tcp.ack?this.release():this.state="closing",b.tcp.ack=!0):"fin-wait-2"===this.state?(this.release(),b.tcp.ack=!0):(this.release(),this.on_close(),b.tcp.rst=!0),this.net.receive(Nb(this.net.eth_encoder_buf,b))):this.ack!==a.tcp.seq?(a=this.packet_reply(a,
|
|
189
|
-
this.net.receive(Nb(this.net.eth_encoder_buf,b)),this.emit("data",a.tcp_data));this.pump()}};Sb.prototype.write=function(a){this.in_active_close||this.send_buffer.write(a);this.pump()};Sb.prototype.writev=function(a){if(!this.in_active_close)for(const b of a)this.send_buffer.write(b);this.pump()};Sb.prototype.close=function(){if(!this.in_active_close){this.in_active_close
|
|
190
|
-
else{this.release();return}this.send_buffer.length||this.pending?(this.delayed_send_fin=!0,this.delayed_state=a):(this.state=a,a=this.ipv4_reply(),a.tcp.fin=!0,this.net.receive(Nb(this.net.eth_encoder_buf,a)))}this.pump()};Sb.prototype.on_shutdown=function(){this.emit("shutdown")};Sb.prototype.on_close=function(){this.emit("close")};Sb.prototype.release=function(){this.net.tcp_conn[this.tuple]&&
|
|
191
|
-
|
|
192
|
-
"192.168.86.100").split(".").map(function(c){return parseInt(c,10)}));this.masquerade=void 0===b.masquerade||!!b.masquerade;this.vm_mac=new Uint8Array(6);this.dns_method=b.dns_method||"static";this.doh_server=b.doh_server;this.tcp_conn={};this.mtu=b.mtu;this.eth_encoder_buf=Bb(this.mtu);this.fetch=(...c)=>fetch(...c);this.cors_proxy=b.cors_proxy;this.bus.register("net"+this.id+"-mac",function(c){this.vm_mac=
|
|
193
|
-
this.id+"-send",function(c){this.send(c)},this);this.bus.register("tcp-connection",c=>{80===c.sport&&(c.on("data",Wb),c.accept())},this)}Vb.prototype.destroy=function(){};Vb.prototype.connect=function(a){return Tb(a,this)};Vb.prototype.tcp_probe=function(a){return Ub(a,this)};async function Wb(a){this.read=this.read||"";if((this.read+=(new TextDecoder).decode(a))&&-1!==this.read.indexOf("\r\n\r\n")){a=
|
|
194
|
-
4);this.read="";let c=b[0].split(" "),d;d=/^https?:/.test(c[1])?new URL(c[1]):new URL("http://host"+c[1]);"undefined"!==typeof window&&"http:"===d.protocol&&"https:"===window.location.protocol&&(d.protocol="https:");let e=new Headers;for(let h=1;h<b.length;++h){const l=this.net.parse_http_header(b[h]);if(!l){console.warn('The request contains an invalid header: "%s"',b[h]);this.net.respond_text_and_close(this,
|
|
195
|
-
d.host=l.value:e.append(l.key,l.value)}if(!this.net.cors_proxy&&/^\d+\.external$/.test(d.hostname))if(b=parseInt(d.hostname.split(".")[0],10),!isNaN(b)&&0<b&&65536>b)d.protocol="http:",d.hostname="localhost",d.port=b.toString(10);else{console.warn('Unknown port for localhost: "%s"',d.href);this.net.respond_text_and_close(this,400,"Bad Request",`Unknown port for localhost: ${d.href}`);return}this.name=d.href;
|
|
196
|
-
const f=this.net.cors_proxy?this.net.cors_proxy+encodeURIComponent(d.href):d.href;new TextEncoder;let g=!1;this.net.fetch(f,b).then(h=>{let l=new Headers(h.headers);l.delete("content-encoding");l.delete("keep-alive");l.delete("content-length");l.delete("transfer-encoding");l.set("x-was-fetch-redirected",`${!!h.redirected}`);l.set("x-fetch-resp-url",h.url);l.set("connection","close");this.write(this.net.form_response_head(h.status,
|
|
197
|
-
n=({value:p,done:q})=>{p&&this.write(p);if(q)this.close();else return m.read().then(n)};m.read().then(n)}else h.arrayBuffer().then(m=>{this.write(new Uint8Array(m));this.close()})}).catch(h=>{console.warn("Fetch Failed: "+f+"\n"+h);g||this.net.respond_text_and_close(this,502,"Fetch Error",`Fetch ${f} failed:\n\n${h.stack||h.message}`);this.close()})}}Vb.prototype.fetch=async function(a,b){this.cors_proxy&&(a=this.cors_proxy+
|
|
198
|
-
return[c,d]}catch(c){return console.warn("Fetch Failed: "+a+"\n"+c),[{status:502,statusText:"Fetch Error",headers:new Headers({"Content-Type":"text/plain"})},(new TextEncoder).encode(`Fetch ${a} failed:\n\n${c.stack}`).buffer]}};Vb.prototype.form_response_head=function(a,b,c){a=[`HTTP/1.1 ${a} ${b}`];for(const [d,e]of c.entries())a.push(`${d}: ${e}`);return(new TextEncoder).encode(a.join("\r\n")+"\r\n\r\n")};Vb.prototype.respond_text_and_close=
|
|
199
|
-
"content-length":d.length.toString(10),connection:"close"});a.writev([this.form_response_head(b,c,e),(new TextEncoder).encode(d)]);a.close()};Vb.prototype.parse_http_header=function(a){var b=a.match(/^([^:]*):(.*)$/);if(b&&(a=b[1],b=b[2].trim(),0!==a.length&&0!==b.length&&/^[\w-]+$/.test(a)&&/^[\x20-\x7E]+$/.test(b)))return{key:a,value:b}};Vb.prototype.send=function(a){Qb(a,this)};Vb.prototype.receive=function(a){this.bus.send("net"+
|
|
200
|
-
this.last_stream=1;this.connections={0:{congestion:0}};this.congested_buffer=[];c=c||{};this.bus=b;this.id=c.id||0;this.router_mac=new Uint8Array((c.router_mac||"52:54:0:1:2:3").split(":").map(function(d){return parseInt(d,16)}));this.router_ip=new Uint8Array((c.router_ip||"192.168.86.1").split(".").map(function(d){return parseInt(d,10)}));this.vm_ip=new Uint8Array((c.vm_ip||"192.168.86.100").split(".").map(function(d){return parseInt(d,
|
|
201
|
-
this.vm_mac=new Uint8Array(6);this.dns_method=c.dns_method||"doh";this.doh_server=c.doh_server;this.tcp_conn={};this.mtu=c.mtu;this.eth_encoder_buf=Bb(this.mtu);this.bus.register("net"+this.id+"-mac",function(d){this.vm_mac=new Uint8Array(d.split(":").map(function(e){return parseInt(e,16)}))},this);this.bus.register("net"+this.id+"-send",function(d){this.send(d)},this)}Xb.prototype.register_ws=function(a){this.wispws=new WebSocket(a.replace("wisp://",
|
|
202
|
-
"arraybuffer";this.wispws.onmessage=b=>{this.process_incoming_wisp_frame(new Uint8Array(b.data))};this.wispws.onclose=()=>{setTimeout(()=>{this.register_ws(a)},1E4)}};Xb.prototype.send_packet=function(a,b,c){this.connections[c]&&(0<this.connections[c].congestion?("DATA"===b&&this.connections[c].congestion--,this.wispws.send(a)):(this.connections[c].congested=!0,this.congested_buffer.push({data:a,type:b})))};Xb.prototype.process_incoming_wisp_frame=
|
|
203
|
-
|
|
204
|
-
delete this.connections[c]}};Xb.prototype.send_wisp_frame=function(a){let b,c;switch(a.type){case "CONNECT":const d=(new TextEncoder).encode(a.hostname);b=new Uint8Array(8+d.length);c=new DataView(b.buffer);c.setUint8(0,1);c.setUint32(1,a.stream_id,!0);c.setUint8(5,1);c.setUint16(6,a.port,!0);b.set(d,8);this.connections[a.stream_id]={data_callback:a.data_callback,close_callback:a.close_callback,congestion:this.connections[0].congestion};break;case "DATA":b=
|
|
205
|
-
c.setUint8(0,2);c.setUint32(1,a.stream_id,!0);b.set(a.data,5);break;case "CLOSE":b=new Uint8Array(6),c=new DataView(b.buffer),c.setUint8(0,4),c.setUint32(1,a.stream_id,!0),c.setUint8(5,a.reason)}this.send_packet(b,a.type,a.stream_id)};Xb.prototype.destroy=function(){this.wispws&&(this.wispws.onmessage=null,this.wispws.onclose=null,this.wispws.close(),this.wispws=null)};Xb.prototype.on_tcp_connection=function(a,b){a.stream_id=this.last_stream++;
|
|
206
|
-
stream_id:a.stream_id,data:c})});a.on_close=()=>{this.send_wisp_frame({type:"CLOSE",stream_id:a.stream_id,reason:2})};a.on_shutdown=a.on_close;this.send_wisp_frame({type:"CONNECT",stream_id:a.stream_id,hostname:b.ipv4.dest.join("."),port:a.sport,data_callback:c=>{a.write(c)},close_callback:()=>{a.close()}});a.accept();return!0};Xb.prototype.send=function(a){Qb(a,this)};Xb.prototype.receive=function(a){this.bus.send("net"+this.id+"-receive",
|
|
207
|
-
0<=window.navigator.platform.toString().toLowerCase().search("win");function Zb(a){function b(v){return v.shiftKey&&v.ctrlKey&&(73===v.keyCode||74===v.keyCode||75===v.keyCode)||!x.emu_enabled?!1:v.target?v.target.classList.contains("phone_keyboard")||"INPUT"!==v.target.nodeName&&"TEXTAREA"!==v.target.nodeName:!0}function c(v){!v.altKey&&n[56]&&l(56,!1);return g(v,!1)}function d(v){!v.altKey&&n[56]&&l(56,!1);return g(v,!0)}function e(){for(var v=
|
|
208
|
-
|
|
209
|
-
v.code||h(p,q),p=null),"ControlLeft"===v.code))return p=v,q=L,r=setTimeout(()=>{h(p,q);p=null},10),!1;h(v,L);return!1}}function h(v,L){a:{if(void 0!==v.code){var T=N[v.code];if(void 0!==T)break a}T=y[v.keyCode]}T?l(T,L,v.repeat):console.log("Missing char in map: keyCode="+(v.keyCode||-1).toString(16)+" code="+v.code)}function l(v,L,T){if(L)n[v]&&!T&&l(v,!1);else if(!n[v])return;(n[v]=L)||(v|=128);255<v?(m(v>>8),m(v&255)):m(v)}function m(v){x.bus.send("keyboard-code",
|
|
210
|
-
this;this.emu_enabled=!0;const y=new Uint16Array([0,0,0,0,0,0,0,0,14,15,0,0,0,28,0,0,42,29,56,0,58,0,0,0,0,0,0,1,0,0,0,0,57,57417,57425,57423,57415,57419,57416,57421,80,0,0,0,0,82,83,0,11,2,3,4,5,6,7,8,9,10,0,39,0,13,0,0,0,30,48,46,32,18,33,34,35,23,36,37,38,50,49,24,25,16,19,31,20,22,47,17,45,21,44,57435,57436,57437,0,0,82,79,80,81,75,76,77,71,72,73,0,0,0,0,0,0,59,60,61,62,63,64,65,66,67,68,87,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
211
|
-
0,0,0,0,0,0,0,0,0,0,0,0,39,13,51,12,52,53,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,26,43,27,40,0,57435,57400,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),u={8:8,10:13,32:32,39:222,44:188,45:189,46:190,47:191,48:48,49:49,50:50,51:51,52:52,53:53,54:54,55:55,56:56,57:57,59:186,61:187,91:219,92:220,93:221,96:192,97:65,98:66,99:67,100:68,101:69,102:70,103:71,104:72,105:73,106:74,107:75,108:76,109:77,110:78,111:79,112:80,113:81,114:82,115:83,116:84,117:85,118:86,119:87,120:88,
|
|
212
|
-
35:51,36:52,37:53,38:55,40:57,41:48,42:56,43:187,58:186,60:188,62:190,63:191,64:50,65:65,66:66,67:67,68:68,69:69,70:70,71:71,72:72,73:73,74:74,75:75,76:76,77:77,78:78,79:79,80:80,81:81,82:82,83:83,84:84,85:85,86:86,87:87,88:88,89:89,90:90,94:54,95:189,123:219,124:220,125:221,126:192};var N={Escape:1,Digit1:2,Digit2:3,Digit3:4,Digit4:5,Digit5:6,Digit6:7,Digit7:8,Digit8:9,Digit9:10,Digit0:11,Minus:12,Equal:13,Backspace:14,Tab:15,KeyQ:16,KeyW:17,KeyE:18,KeyR:19,KeyT:20,
|
|
213
|
-
KeyP:25,BracketLeft:26,BracketRight:27,Enter:28,ControlLeft:29,KeyA:30,KeyS:31,KeyD:32,KeyF:33,KeyG:34,KeyH:35,KeyJ:36,KeyK:37,KeyL:38,Semicolon:39,Quote:40,Backquote:41,ShiftLeft:42,Backslash:43,KeyZ:44,KeyX:45,KeyC:46,KeyV:47,KeyB:48,KeyN:49,KeyM:50,Comma:51,Period:52,Slash:53,IntlRo:53,ShiftRight:54,NumpadMultiply:55,AltLeft:56,Space:57,CapsLock:58,F1:59,F2:60,F3:61,F4:62,F5:63,F6:64,F7:65,F8:66,F9:67,F10:68,NumLock:69,ScrollLock:70,Numpad7:71,Numpad8:72,Numpad9:73,
|
|
214
|
-
Numpad5:76,Numpad6:77,NumpadAdd:78,Numpad1:79,Numpad2:80,Numpad3:81,Numpad0:82,NumpadDecimal:83,IntlBackslash:86,F11:87,F12:88,NumpadEnter:57372,ControlRight:57373,NumpadDivide:57397,AltRight:57400,Home:57415,ArrowUp:57416,PageUp:57417,ArrowLeft:57419,ArrowRight:57421,End:57423,ArrowDown:57424,PageDown:57425,Insert:57426,Delete:57427,MetaLeft:57435,OSLeft:57435,MetaRight:57436,OSRight:57436,ContextMenu:57437};this.bus=a;this.destroy=function(){"undefined"!==typeof window&&
|
|
215
|
-
c,!1),window.removeEventListener("keydown",d,!1),window.removeEventListener("blur",e,!1),window.removeEventListener("input",f,!1))};this.init=function(){"undefined"!==typeof window&&(this.destroy(),window.addEventListener("keyup",c,!1),window.addEventListener("keydown",d,!1),window.addEventListener("blur",e,!1),window.addEventListener("input",f,!1))};this.init();this.simulate_press=function(v){v={keyCode:v};g(v,!0);g(v,!1)};this.simulate_char=function(v){var L=
|
|
216
|
-
L in G?(m(42),this.simulate_press(G[L]),m(170)):console.log("ascii -> keyCode not found: ",L,v)}}function $b(a,b){function c(u){if(!y.enabled||!y.emu_enabled)return!1;var G=b||document.body,N;if(!(N=document.pointerLockElement))a:{for(u=u.target;u.parentNode;){if(u===G){N=!0;break a}u=u.parentNode}N=!1}return N}function d(u){c(u)&&(u=u.changedTouches)&&u.length&&(u=u[u.length-1],r=u.clientX,x=u.clientY)}function e(){if(n||q||p)y.bus.send("mouse-click",
|
|
217
|
-
c(u)&&y.is_running){var G=0,N=0,v=u.changedTouches;v?v.length&&(v=v[v.length-1],G=v.clientX-r,N=v.clientY-x,r=v.clientX,x=v.clientY,u.preventDefault()):"number"===typeof u.movementX?(G=u.movementX,N=u.movementY):"number"===typeof u.webkitMovementX?(G=u.webkitMovementX,N=u.webkitMovementY):"number"===typeof u.mozMovementX?(G=u.mozMovementX,N=u.mozMovementY):(G=u.clientX-r,N=u.clientY-x,r=u.clientX,x=u.clientY);y.bus.send("mouse-delta",[1*G,-(1*N)]);b&&y.bus.send("mouse-absolute",
|
|
218
|
-
u.pageY-b.offsetTop,b.offsetWidth,b.offsetHeight])}}function g(u){c(u)&&l(u,!0)}function h(u){c(u)&&l(u,!1)}function l(u,G){y.bus&&(1===u.which?n=G:2===u.which?q=G:3===u.which&&(p=G),y.bus.send("mouse-click",[n,q,p]),u.preventDefault())}function m(u){if(c(u)){var G=u.wheelDelta||-u.detail;0>G?G=-1:0<G&&(G=1);y.bus.send("mouse-wheel",[G,0]);u.preventDefault()}}var n=!1,p=!1,q=!1,r=0,x=0,y=this;this.enabled=!1;this.emu_enabled=!0;this.bus=a;this.bus.register("mouse-enable",function(u){this.enabled=
|
|
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={Map,Uint8Array,
|
|
104
|
+
Int8Array,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));if(a instanceof Map)return{__state_type__:"Map",args:Array.from(a.entries()).map(([e,f])=>[cb(e,b),cb(f,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)-
|
|
105
|
+
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"!==typeof a||null===a)return a;if(Array.isArray(a)){for(var c=0;c<a.length;c++)a[c]=db(a[c],b);return a}c=bb[a.__state_type__];return void 0!==a.args?new c(a.args):new c(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="+
|
|
106
|
+
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=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,
|
|
107
|
+
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=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+
|
|
108
|
+
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=>{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=
|
|
109
|
+
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===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?
|
|
110
|
+
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,"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,
|
|
111
|
+
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,
|
|
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)}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;
|
|
113
|
+
a[13]=this.update_interrupt_time;a[14]=this.cmos_diag_status;return a};gb.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=a[11];this.update_interrupt=a[12]||!1;this.update_interrupt_time=a[13]||0;this.cmos_diag_status=a[14]||0};gb.prototype.timer=
|
|
114
|
+
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|=160,this.next_interrupt_alarm=0):this.update_interrupt&&this.update_interrupt_time<a&&(this.cpu.device_raise_irq(8),
|
|
115
|
+
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};gb.prototype.bcd_pack=function(a){for(var b=0,c=0,d;a;)d=a%10,c|=d<<4*b,b++,a=(a-d)/10;return c};gb.prototype.bcd_unpack=function(a){return(a&15)+10*(a>>4&15)};gb.prototype.encode_time=
|
|
116
|
+
function(a){return this.cmos_b&4?a:this.bcd_pack(a)};gb.prototype.decode_time=function(a){return this.cmos_b&4?a:this.bcd_unpack(a)};gb.prototype.cmos_port_read=function(){var a=this.cmos_index;switch(a){case 0:return z(this.encode_time((new Date(this.rtc_time)).getUTCSeconds())),this.encode_time((new Date(this.rtc_time)).getUTCSeconds());case 2:return z(this.encode_time((new Date(this.rtc_time)).getUTCMinutes())),this.encode_time((new Date(this.rtc_time)).getUTCMinutes());case 4:return z(this.encode_time((new Date(this.rtc_time)).getUTCHours())),
|
|
117
|
+
this.encode_time((new Date(this.rtc_time)).getUTCHours());case 6:return z(this.encode_time((new Date(this.rtc_time)).getUTCDay()+1)),this.encode_time((new Date(this.rtc_time)).getUTCDay()+1);case 7:return z(this.encode_time((new Date(this.rtc_time)).getUTCDate())),this.encode_time((new Date(this.rtc_time)).getUTCDate());case 8:return z(this.encode_time((new Date(this.rtc_time)).getUTCMonth()+1)),this.encode_time((new Date(this.rtc_time)).getUTCMonth()+1);case 9:return z(this.encode_time((new Date(this.rtc_time)).getUTCFullYear()%
|
|
118
|
+
100)),this.encode_time((new Date(this.rtc_time)).getUTCFullYear()%100);case 10:return 999<=E.microtick()%1E3?this.cmos_a|128:this.cmos_a;case 11:return this.cmos_b;case 12:return this.cpu.device_lower_irq(8),a=this.cmos_c,this.cmos_c&=-241,a;case 13:return 128;case 14:return this.cmos_diag_status;case 50:case 55:return z(this.encode_time((new Date(this.rtc_time)).getUTCFullYear()/100|0)),this.encode_time((new Date(this.rtc_time)).getUTCFullYear()/100|0);default:return z(a),this.cmos_data[this.cmos_index]}};
|
|
119
|
+
gb.prototype.cmos_port_write=function(a){switch(this.cmos_index){case 10:this.cmos_a=a&127;this.periodic_interrupt_time=1E3/(32768>>(this.cmos_a&15)-1);z(this.cmos_a,2);break;case 11:this.cmos_b=a;this.cmos_b&128&&(this.cmos_b&=239);this.cmos_b&64&&(this.next_interrupt=Date.now());if(this.cmos_b&32){a=new Date;const b=this.decode_time(this.cmos_data[1]),c=this.decode_time(this.cmos_data[3]),d=this.decode_time(this.cmos_data[5]);this.next_interrupt_alarm=+new Date(Date.UTC(a.getUTCFullYear(),a.getUTCMonth(),
|
|
120
|
+
a.getUTCDate(),d,c,b))}this.cmos_b&16&&(this.update_interrupt_time=Date.now());z(this.cmos_b,2);break;case 14:this.cmos_diag_status=a;break;case 1:case 3:case 5:this.cmos_write(this.cmos_index,a);break;default:z(this.cmos_index),z(a)}this.update_interrupt=16===(this.cmos_b&16)&&0<(this.cmos_a&15);this.periodic_interrupt=64===(this.cmos_b&64)&&0<(this.cmos_a&15)};gb.prototype.cmos_read=function(a){return this.cmos_data[a]};gb.prototype.cmos_write=function(a,b){z(a);z(b);this.cmos_data[a]=b};function hb(a,
|
|
121
|
+
b){this.cpu=a;this.bus=b;this.counter_start_time=new Float64Array(3);this.counter_start_value=new Uint16Array(3);this.counter_next_low=new Uint8Array(4);this.counter_enabled=new Uint8Array(4);this.counter_mode=new Uint8Array(4);this.counter_read_mode=new Uint8Array(4);this.counter_latch=new Uint8Array(4);this.counter_latch_value=new Uint16Array(3);this.counter_reload=new Uint16Array(3);a.io.register_read(97,this,function(){var c=E.microtick(),d=66.66666666666667*c&1;c=this.did_rollover(2,c);return d<<
|
|
122
|
+
4|c<<5});a.io.register_write(97,this,function(c){c&1?this.bus.send("pcspeaker-enable"):this.bus.send("pcspeaker-disable")});a.io.register_read(64,this,function(){return this.counter_read(0)});a.io.register_read(65,this,function(){return this.counter_read(1)});a.io.register_read(66,this,function(){return this.counter_read(2)});a.io.register_write(64,this,function(c){this.counter_write(0,c)});a.io.register_write(65,this,function(c){this.counter_write(1,c)});a.io.register_write(66,this,function(c){this.counter_write(2,
|
|
123
|
+
c);this.bus.send("pcspeaker-update",[this.counter_mode[2],this.counter_reload[2]])});a.io.register_write(67,this,this.port43_write)}hb.prototype.get_state=function(){var a=[];a[0]=this.counter_next_low;a[1]=this.counter_enabled;a[2]=this.counter_mode;a[3]=this.counter_read_mode;a[4]=this.counter_latch;a[5]=this.counter_latch_value;a[6]=this.counter_reload;a[7]=this.counter_start_time;a[8]=this.counter_start_value;return a};hb.prototype.set_state=function(a){this.counter_next_low=a[0];this.counter_enabled=
|
|
124
|
+
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]};hb.prototype.timer=function(a,b){var c=100;b||(this.counter_enabled[0]&&this.did_rollover(0,a)?(this.counter_start_value[0]=this.get_counter_value(0,a),this.counter_start_time[0]=a,this.cpu.device_lower_irq(0),this.cpu.device_raise_irq(0),0===this.counter_mode[0]&&(this.counter_enabled[0]=0)):this.cpu.device_lower_irq(0),
|
|
125
|
+
this.counter_enabled[0]&&(c=(this.counter_start_value[0]-Math.floor(1193.1816666*(a-this.counter_start_time[0])))/1193.1816666));return c};hb.prototype.get_counter_value=function(a,b){if(!this.counter_enabled[a])return 0;b=this.counter_start_value[a]-Math.floor(1193.1816666*(b-this.counter_start_time[a]));a=this.counter_reload[a];b>=a?b%=a:0>b&&(b=b%a+a);return b};hb.prototype.did_rollover=function(a,b){b-=this.counter_start_time[a];return 0>b?!0:this.counter_start_value[a]<Math.floor(1193.1816666*
|
|
126
|
+
b)};hb.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,E.microtick());return b?a&255:a>>8};hb.prototype.counter_write=function(a,b){this.counter_reload[a]=this.counter_next_low[a]?this.counter_reload[a]&-256|b:this.counter_reload[a]&255|b<<8;3===this.counter_read_mode[a]&&
|
|
127
|
+
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]=E.microtick(),z(this.counter_reload[a]));3===this.counter_read_mode[a]&&(this.counter_next_low[a]^=1)};hb.prototype.port43_write=function(a){var b=a>>1&7,c=a>>6&3;a=a>>4&3;3!==c&&(0===a?(this.counter_latch[c]=2,b=this.get_counter_value(c,E.microtick()),this.counter_latch_value[c]=b?b-1:0):(6<=b&&(b&=-5),this.counter_next_low[c]=
|
|
128
|
+
1===a?1:2===a?0:1,0===c&&this.cpu.device_lower_irq(0),0!==b&&3!==b&&2!==b&&z(b),this.counter_mode[c]=b,this.counter_read_mode[c]=a,2===c&&this.bus.send("pcspeaker-update",[this.counter_mode[2],this.counter_reload[2]])))};hb.prototype.dump=function(){};function ib(a){if("undefined"!==typeof window)if(window.AudioContext||window.webkitAudioContext){var b=window.AudioWorklet?jb:kb;this.bus=a;this.audio_context=window.AudioContext?new AudioContext:new webkitAudioContext;this.mixer=new lb(a,this.audio_context);
|
|
129
|
+
this.pcspeaker=new mb(a,this.audio_context,this.mixer);this.dac=new b(a,this.audio_context,this.mixer);this.pcspeaker.start();a.register("emulator-stopped",function(){this.audio_context.suspend()},this);a.register("emulator-started",function(){this.audio_context.resume()},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")}ib.prototype.destroy=function(){this.audio_context&&
|
|
130
|
+
this.audio_context.close();this.audio_context=null;this.dac&&this.dac.node_processor&&this.dac.node_processor.port.close();this.dac=null};function lb(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=
|
|
131
|
+
"highshelf";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,
|
|
132
|
+
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);
|
|
133
|
+
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);e=0===e?this:this.sources.get(e);void 0===e||e.set_volume(d,f)},this);a.register("mixer-gain-left",function(d){this.gain_left=Math.pow(10,d/20);this.update()},
|
|
134
|
+
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)}lb.prototype.add_source=function(a,b){a=new nb(this.audio_context,a,this.input_left,this.input_right);this.sources.has(b);this.sources.set(b,a);return a};
|
|
135
|
+
lb.prototype.connect_source=function(a,b){a=this.sources.get(a);void 0===a||a.connect(b)};lb.prototype.disconnect_source=function(a,b){a=this.sources.get(a);void 0===a||a.disconnect(b)};lb.prototype.set_volume=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:return}this.update()};lb.prototype.update=function(){var a=this.volume_both*this.volume_right*this.gain_right;this.node_gain_left.gain.setValueAtTime(this.volume_both*
|
|
136
|
+
this.volume_left*this.gain_left,this.audio_context.currentTime);this.node_gain_right.gain.setValueAtTime(a,this.audio_context.currentTime)};function nb(a,b,c,d){this.audio_context=a;this.connected_right=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);
|
|
137
|
+
this.node_splitter.connect(this.node_gain_right,1);this.node_gain_right.connect(d)}nb.prototype.update=function(){var a=this.connected_right*this.gain_hidden*this.volume_both*this.volume_right;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)};nb.prototype.connect=function(a){var b=!a||2===a;if(b||0===a)this.connected_left=!0;if(b||
|
|
138
|
+
1===a)this.connected_right=!0;this.update()};nb.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()};nb.prototype.set_volume=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:return}this.update()};nb.prototype.set_gain_hidden=function(a){this.gain_hidden=a};function mb(a,b,c){this.node_oscillator=b.createOscillator();this.node_oscillator.type=
|
|
139
|
+
"square";this.node_oscillator.frequency.setValueAtTime(440,b.currentTime);this.mixer_connection=c.add_source(this.node_oscillator,1);this.mixer_connection.disconnect();a.register("pcspeaker-enable",function(){c.connect_source(1)},this);a.register("pcspeaker-disable",function(){c.disconnect_source(1)},this);a.register("pcspeaker-update",function(d){var e=d[1],f=0;3===d[0]&&(f=Math.min(1193181.6665999999/e,this.node_oscillator.frequency.maxValue),f=Math.max(f,0));this.node_oscillator.frequency.setValueAtTime(f,
|
|
140
|
+
b.currentTime)},this)}mb.prototype.start=function(){this.node_oscillator.start()};function jb(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=48E3;b=function(){function g(m){if(0===m)return 1;m*=Math.PI;return Math.sin(m)/m}function h(){var m=Reflect.construct(AudioWorkletProcessor,[],h);m.kernel_size=3;m.queue_data=Array(1024);m.queue_start=0;m.queue_end=0;m.queue_length=0;m.queue_size=m.queue_data.length;m.queued_samples=0;m.source_buffer_previous=l;m.source_buffer_current=
|
|
141
|
+
l;m.source_samples_per_destination=1;m.source_block_start=0;m.source_time=0;m.source_offset=0;m.port.onmessage=n=>{switch(n.data.type){case "queue":m.queue_push(n.data.value);break;case "sampling-rate":m.source_samples_per_destination=n.data.value/sampleRate}};return m}var l=[new Float32Array(256),new Float32Array(256)];Reflect.setPrototypeOf(h.prototype,AudioWorkletProcessor.prototype);Reflect.setPrototypeOf(h,AudioWorkletProcessor);h.prototype.process=h.prototype.process=function(m,n){for(m=0;m<
|
|
142
|
+
n[0][0].length;m++){for(var p=0,q=0,r=this.source_offset+this.kernel_size,x=this.source_offset-this.kernel_size+1;x<=r;x++){var y=this.source_block_start+x;p+=this.get_sample(y,0)*this.kernel(this.source_time-x);q+=this.get_sample(y,1)*this.kernel(this.source_time-x)}if(isNaN(p)||isNaN(q))p=q=0,this.dbg_log("ERROR: NaN values! Ignoring for now.");n[0][0][m]=p;n[0][1][m]=q;this.source_time+=this.source_samples_per_destination;this.source_offset=Math.floor(this.source_time)}n=this.source_offset;n+=
|
|
143
|
+
this.kernel_size+2;this.source_time-=this.source_offset;this.source_block_start+=this.source_offset;this.source_offset=0;this.ensure_enough_data(n);return!0};h.prototype.kernel=function(m){return g(m)*g(m/this.kernel_size)};h.prototype.get_sample=function(m,n){return 0>m?(m+=this.source_buffer_previous[0].length,this.source_buffer_previous[n][m]):this.source_buffer_current[n][m]};h.prototype.ensure_enough_data=function(m){var n=this.source_buffer_current[0].length;n-this.source_block_start<m&&(this.prepare_next_buffer(),
|
|
144
|
+
this.source_block_start-=n)};h.prototype.prepare_next_buffer=function(){256>this.queued_samples&&this.queue_length&&this.dbg_log("Not enough samples - should not happen during midway of playback");this.source_buffer_previous=this.source_buffer_current;this.source_buffer_current=this.queue_shift();var m=this.source_buffer_current[0].length;if(256>m){for(var n=this.queue_start,p=0;256>m&&p<this.queue_length;)m+=this.queue_data[n][0].length,n=n+1&this.queue_size-1,p++;m=Math.max(m,256);m=[new Float32Array(m),
|
|
145
|
+
new Float32Array(m)];m[0].set(this.source_buffer_current[0]);m[1].set(this.source_buffer_current[1]);n=this.source_buffer_current[0].length;for(var q=0;q<p;q++){var r=this.queue_shift();m[0].set(r[0],n);m[1].set(r[1],n);n+=r[0].length}this.source_buffer_current=m}this.pump()};h.prototype.pump=function(){1024>this.queued_samples/this.source_samples_per_destination&&this.port.postMessage({type:"pump"})};h.prototype.queue_push=function(m){this.queue_length<this.queue_size&&(this.queue_data[this.queue_end]=
|
|
146
|
+
m,this.queue_end=this.queue_end+1&this.queue_size-1,this.queue_length++,this.queued_samples+=m[0].length,this.pump())};h.prototype.queue_shift=function(){if(!this.queue_length)return l;var m=this.queue_data[this.queue_start];this.queue_data[this.queue_start]=null;this.queue_start=this.queue_start+1&this.queue_size-1;this.queue_length--;this.queued_samples-=m[0].length;return m};h.prototype.dbg_log=function(){};registerProcessor("dac-processor",h)}.toString();var d=b.indexOf("{")+1,e=b.lastIndexOf("}");
|
|
147
|
+
b=b.substring(d,e);b=new Blob([b],{type:"application/javascript"});var f=URL.createObjectURL(b);this.node_processor=null;this.node_output=this.audio_context.createGain();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});
|
|
148
|
+
this.node_processor.port.onmessage=g=>{switch(g.data.type){case "pump":this.pump()}};this.node_processor.connect(this.node_output)});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){this.sampling_rate=g;this.node_processor&&this.node_processor.port.postMessage({type:"sampling-rate",
|
|
149
|
+
value:g})},this)}jb.prototype.queue=function(a){this.node_processor&&this.node_processor.port.postMessage({type:"queue",value:a},[a[0].buffer,a[1].buffer])};jb.prototype.pump=function(){this.enabled&&this.bus.send("dac-request-data")};function kb(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=this.node_lowpass;this.mixer_connection=
|
|
150
|
+
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){this.sampling_rate=d;this.rate_ratio=Math.ceil(8E3/d);this.node_lowpass.frequency.setValueAtTime(d/2,this.audio_context.currentTime)},this)}kb.prototype.queue=function(a){var b=a[0].length,c=
|
|
151
|
+
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,h=0;h<b;h++)for(var l=0;l<this.rate_ratio;l++,g++)e[g]=a[0][h],f[g]=a[1][h]}else d=this.audio_context.createBuffer(2,b,this.sampling_rate),d.copyToChannel?(d.copyToChannel(a[0],0),d.copyToChannel(a[1],1)):(d.getChannelData(0).set(a[0]),d.getChannelData(1).set(a[1]));a=this.audio_context.createBufferSource();
|
|
152
|
+
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(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);this.buffered_time+=c;setTimeout(()=>this.pump(),0)};kb.prototype.pump=function(){this.enabled&&(.2<this.buffered_time-this.audio_context.currentTime||this.bus.send("dac-request-data"))};function sb(a,b,c){this.bus=b;this.socket=
|
|
153
|
+
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)}sb.prototype.handle_message=function(a){this.bus&&this.bus.send("net"+this.id+"-receive",new Uint8Array(a.data))};sb.prototype.handle_close=function(){this.destroyed||(this.connect(),setTimeout(this.connect.bind(this),this.reconnect_interval))};sb.prototype.handle_open=
|
|
154
|
+
function(){for(var a=0;a<this.send_queue.length;a++)this.send(this.send_queue[a]);this.send_queue=[]};sb.prototype.handle_error=function(){};sb.prototype.destroy=function(){this.destroyed=!0;this.socket&&this.socket.close()};sb.prototype.connect=function(){if("undefined"!==typeof WebSocket){if(this.socket){var a=this.socket.readyState;if(0===a||1===a)return}a=Date.now();if(!(this.last_connect_attempt+this.reconnect_interval>a)){this.last_connect_attempt=Date.now();try{this.socket=new WebSocket(this.url)}catch(b){console.error(b);
|
|
155
|
+
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)}}};sb.prototype.send=function(a){this.socket&&1===this.socket.readyState?this.socket.send(a):(this.send_queue.push(a),this.send_queue.length>2*this.send_queue_limit&&(this.send_queue=this.send_queue.slice(-this.send_queue_limit)),this.connect())};sb.prototype.change_proxy=
|
|
156
|
+
function(a){this.url=a;this.socket&&(this.socket.onclose=function(){},this.socket.onerror=function(){},this.socket.close(),this.socket=void 0)};const tb=(new Date("1970-01-01T00:00:00Z")).getTime(),ub=(new Date("1900-01-01T00:00:00Z")).getTime(),vb=tb-ub,wb=Math.pow(2,32),xb=[118,56,54];function yb(a){return[0,1,2,3,4,5].map(b=>a[b].toString(16)).map(b=>1===b.length?"0"+b:b).join(":")}function zb(a){return a[0]<<24|a[1]<<16|a[2]<<8|a[3]}class Ab{constructor(a,b){a=Math.min(a,16);this.maximum_capacity=
|
|
157
|
+
b?Math.max(b,a):0;this.length=this.head=this.tail=0;this.buffer=new Uint8Array(a)}write(a){const b=a.length;var c=this.length+b;let d=this.buffer.length;if(d<c){for(;d<c;)d*=2;if(this.maximum_capacity&&d>this.maximum_capacity)throw Error("stream capacity overflow in GrowableRingbuffer.write(), package dropped");c=new Uint8Array(d);this.peek(c);this.tail=0;this.head=this.length;this.buffer=c}c=this.buffer;const e=this.head+b;if(e>d){const f=d-this.head;c.set(a.subarray(0,f),this.head);c.set(a.subarray(f))}else c.set(a,
|
|
158
|
+
this.head);this.head=e%d;this.length+=b}peek(a){const b=Math.min(this.length,a.length);if(b){const e=this.buffer;var c=e.length,d=this.tail+b;d>c?(d%=c,c-=this.tail,a.set(e.subarray(this.tail)),a.set(e.subarray(0,d),c)):a.set(e.subarray(this.tail,d))}return b}remove(a){a>this.length&&(a=this.length);a&&(this.tail=(this.tail+a)%this.buffer.length,this.length-=a);return a}}function Bb(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),
|
|
159
|
+
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 Cb(a,b,c,d){d.eth_frame.set(b,c.byteOffset+a);return b.length}function Mb(a,b,c,d){const e=c.byteOffset+(a&-2);d=d.eth_frame;for(c=c.byteOffset;c<e;c+=2)b+=d[c]<<8|d[c+1];for(a&1&&(b+=d[e]<<8);b>>>16;)b=(b&65535)+(b>>>16);return~b&65535}function Nb(a,b){a.eth_frame.fill(0);var c=a.eth_frame,d=c.subarray,e=a.eth_frame_view;Cb(0,b.eth.dest,e,
|
|
160
|
+
a);Cb(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);Cb(8,b.arp.sha,f,a);Cb(14,b.arp.spa,f,a);Cb(18,b.arp.tha,f,a);Cb(24,b.arp.tpa,f,a);e+=28}else if(b.ipv4){f=a.eth_payload_view;var g=20;if(b.icmp){var h=a.ipv4_payload_view;h.setUint8(0,b.icmp.type);h.setUint8(1,b.icmp.code);h.setUint16(2,0);var l=4+Cb(4,b.icmp.data,
|
|
161
|
+
h,a);h.setUint16(2,Mb(l,0,h,a));g+=l}else if(b.udp){h=a.ipv4_payload_view;var m=8;if(b.dhcp){l=m;var n=a.udp_payload_view;n.setUint8(0,b.dhcp.op);n.setUint8(1,b.dhcp.htype);n.setUint8(2,b.dhcp.hlen);n.setUint8(3,b.dhcp.hops);n.setUint32(4,b.dhcp.xid);n.setUint16(8,b.dhcp.secs);n.setUint16(10,b.dhcp.flags);n.setUint32(12,b.dhcp.ciaddr);n.setUint32(16,b.dhcp.yiaddr);n.setUint32(20,b.dhcp.siaddr);n.setUint32(24,b.dhcp.giaddr);Cb(28,b.dhcp.chaddr,n,a);n.setUint32(236,1669485411);m=240;for(var p of b.dhcp.options)m+=
|
|
162
|
+
Cb(m,p,n,a);l+=m}else if(b.dns){p=m;m=a.udp_payload_view;m.setUint16(0,b.dns.id);m.setUint16(2,b.dns.flags);m.setUint16(4,b.dns.questions.length);m.setUint16(6,b.dns.answers.length);let x=12;for(var q=0;q<b.dns.questions.length;++q){var r=b.dns.questions[q];for(n of r.name){const y=a.text_encoder.encodeInto(n,a.eth_frame.subarray(m.byteOffset+(x+1))).written;m.setUint8(x,y);x+=1+y}m.setUint16(x,r.type);x+=2;m.setUint16(x,r.class);x+=2}for(q=0;q<b.dns.answers.length;++q){n=b.dns.answers[q];for(l of n.name)r=
|
|
163
|
+
a.text_encoder.encodeInto(l,a.eth_frame.subarray(m.byteOffset+(x+1))).written,m.setUint8(x,r),x+=1+r;m.setUint16(x,n.type);x+=2;m.setUint16(x,n.class);x+=2;m.setUint32(x,n.ttl);x+=4;m.setUint16(x,n.data.length);x+=2;x+=Cb(x,n.data,m,a)}l=p+x}else b.ntp?(l=m,n=a.udp_payload_view,n.setUint8(0,b.ntp.flags),n.setUint8(1,b.ntp.stratum),n.setUint8(2,b.ntp.poll),n.setUint8(3,b.ntp.precision),n.setUint32(4,b.ntp.root_delay),n.setUint32(8,b.ntp.root_disp),n.setUint32(12,b.ntp.ref_id),n.setUint32(16,b.ntp.ref_ts_i),
|
|
164
|
+
n.setUint32(20,b.ntp.ref_ts_f),n.setUint32(24,b.ntp.ori_ts_i),n.setUint32(28,b.ntp.ori_ts_f),n.setUint32(32,b.ntp.rec_ts_i),n.setUint32(36,b.ntp.rec_ts_f),n.setUint32(40,b.ntp.trans_ts_i),n.setUint32(44,b.ntp.trans_ts_f),l+=48):l=m+Cb(0,b.udp.data,a.udp_payload_view,a);m=l;h.setUint16(0,b.udp.sport);h.setUint16(2,b.udp.dport);h.setUint16(4,m);h.setUint16(6,0);h.setUint16(6,Mb(m,(b.ipv4.src[0]<<8|b.ipv4.src[1])+(b.ipv4.src[2]<<8|b.ipv4.src[3])+(b.ipv4.dest[0]<<8|b.ipv4.dest[1])+(b.ipv4.dest[2]<<8|
|
|
165
|
+
b.ipv4.dest[3])+17+m,h,a));g+=m}else b.tcp&&(h=a.ipv4_payload_view,l=0,n=b.tcp,n.fin&&(l|=1),n.syn&&(l|=2),n.rst&&(l|=4),n.psh&&(l|=8),n.ack&&(l|=16),n.urg&&(l|=32),n.ece&&(l|=64),n.cwr&&(l|=128),p=20,n.options&&n.options.mss&&(h.setUint8(p,2),h.setUint8(p+1,4),h.setUint16(p+2,n.options.mss),p+=4),m=4*Math.ceil(p/4),n.options&&0<m-p&&a.eth_frame.fill(0,h.byteOffset+p,h.byteOffset+p+(m-p)),h.setUint16(0,n.sport),h.setUint16(2,n.dport),h.setUint32(4,n.seq),h.setUint32(8,n.ackn),h.setUint8(12,m>>2<<
|
|
166
|
+
4),h.setUint8(13,l),h.setUint16(14,n.winsize),h.setUint16(16,0),h.setUint16(18,n.urgent||0),b.tcp_data&&(m+=Cb(20,b.tcp_data,h,a)),h.setUint16(16,Mb(m,(b.ipv4.src[0]<<8|b.ipv4.src[1])+(b.ipv4.src[2]<<8|b.ipv4.src[3])+(b.ipv4.dest[0]<<8|b.ipv4.dest[1])+(b.ipv4.dest[2]<<8|b.ipv4.dest[3])+6+m,h,a)),g+=m);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);Cb(12,b.ipv4.src,
|
|
167
|
+
f,a);Cb(16,b.ipv4.dest,f,a);f.setUint16(10,Mb(20,0,f,a));e+=g}return d.call(c,0,e)}function Ob(a,b){fetch(`https://${b.doh_server||"cloudflare-dns.com"}/dns-query`,{method:"POST",headers:[["content-type","application/dns-message"]],body:a.udp.data}).then(async c=>{c={eth:{ethertype:2048,src:b.router_mac,dest:a.eth.src},ipv4:{proto:17,src:b.router_ip,dest:a.ipv4.src},udp:{sport:53,dport:a.udp.sport,data:new Uint8Array(await c.arrayBuffer())}};b.receive(Nb(b.eth_encoder_buf,c))});return!0}function Pb(a,
|
|
168
|
+
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:zb(b.vm_ip),siaddr:zb(b.router_ip),giaddr:zb(b.router_ip),chaddr:a.dhcp.chaddr};let d=[],e=a.dhcp.options.find(function(f){return 53===f[0]});e&&3===e[2]&&(a.dhcp.op=3);1===a.dhcp.op&&(c.dhcp.op=2,d.push(new Uint8Array([53,1,2])));3===a.dhcp.op&&(c.dhcp.op=2,d.push(new Uint8Array([53,
|
|
169
|
+
1,5])),d.push(new Uint8Array([51,4,8,0,0,0])));a=[b.router_ip[0],b.router_ip[1],b.router_ip[2],b.router_ip[3]];d.push(new Uint8Array([1,4,255,255,255,0]));b.masquerade&&(d.push(new Uint8Array([3,4].concat(a))),d.push(new Uint8Array([6,4].concat(a))));d.push(new Uint8Array([54,4].concat(a)));d.push(new Uint8Array([60,3].concat(xb)));d.push(new Uint8Array([255,0]));c.dhcp.options=d;b.receive(Nb(b.eth_encoder_buf,c))}function Qb(a,b){let c={};var d=(new DataView(a.buffer,a.byteOffset,a.byteLength)).getUint16(12),
|
|
170
|
+
e={ethertype:d,dest:a.subarray(0,6),dest_s:yb(a.subarray(0,6)),src:a.subarray(6,12),src_s:yb(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 h=f.getUint8(1),l=f.getUint16(2);let m=f.getUint8(8);d=f.getUint8(9);f=f.getUint16(10);g={version:g,ihl:e,tos:h,len:l,ttl:m,proto:d,ip_checksum:f,src:a.subarray(12,16),dest:a.subarray(16,20)};c.ipv4=g;e=a.subarray(4*e,l);if(1===d)a=new DataView(e.buffer,e.byteOffset,
|
|
171
|
+
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),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=
|
|
172
|
+
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))};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),
|
|
173
|
+
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(l=0;l<e.length;++l)g=l,0!==e[l]&&(++l,h=e[l],l+=h,d.options.push(e.subarray(g,g+h+2)));c.dhcp=d;c.dhcp_options=d.options}else 53===a.dport||53===a.sport?Rb(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),
|
|
174
|
+
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),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&&
|
|
175
|
+
z(d);if(c.ipv4)if(c.tcp)a:{a=`${c.ipv4.src.join(".")}:${c.tcp.sport}:${c.ipv4.dest.join(".")}:${c.tcp.dport}`;if(c.tcp.syn&&!c.tcp.ack){b.tcp_conn[a]&&delete b.tcp_conn[a];d=new Sb(b);d.state="syn-received";d.tuple=a;d.last=c;d.hsrc=c.eth.dest;d.psrc=c.ipv4.dest;d.sport=c.tcp.dport;d.hdest=c.eth.src;d.dport=c.tcp.sport;d.pdest=c.ipv4.src;b.bus.pair.send("tcp-connection",d);if(b.on_tcp_connection)b.on_tcp_connection(d,c);if(b.tcp_conn[a])break a}if(b.tcp_conn[a])b.tcp_conn[a].process(c);else{a=c.tcp.ackn;
|
|
176
|
+
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(Nb(b.eth_encoder_buf,d))}}else if(c.udp)if(c.dns)if("static"===b.dns_method){a={};a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src};a.ipv4={proto:17,src:b.router_ip,dest:c.ipv4.src};a.udp={sport:53,dport:c.udp.sport};d=[];for(e=
|
|
177
|
+
0;e<c.dns.questions.length;++e)switch(l=c.dns.questions[e],l.type){case 1:d.push({name:l.name,type:l.type,class:l.class,ttl:600,data:[192,168,87,1]})}a.dns={id:c.dns.id,flags:33152,questions:c.dns.questions,answers:d};b.receive(Nb(b.eth_encoder_buf,a))}else Ob(c,b);else c.dhcp?Pb(c,b):c.ntp?(a=Date.now()+vb,d=a%1E3/1E3*wb,e={},e.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},e.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},e.udp={sport:123,dport:c.udp.sport},e.ntp=Object.assign({},c.ntp),e.ntp.flags=
|
|
178
|
+
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(Nb(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},a.udp={sport:c.udp.dport,dport:c.udp.sport,data:(new TextEncoder).encode(c.udp.data_s)},b.receive(Nb(b.eth_encoder_buf,a)));else c.icmp&&8===c.icmp.type&&(a={},
|
|
179
|
+
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(Nb(b.eth_encoder_buf,a)));else c.arp&&1===c.arp.oper&&2048===c.arp.ptype&&(a=zb(c.arp.tpa)&4294967040,d=zb(b.router_ip)&4294967040,!b.masquerade&&a!==d||a===d&&99<c.arp.tpa[3]||(a={},a.eth={ethertype:2054,src:b.router_mac,dest:c.eth.src},a.arp={htype:1,ptype:2048,oper:2,sha:b.router_mac,spa:c.arp.tpa,tha:c.eth.src,tpa:c.arp.spa},b.receive(Nb(b.eth_encoder_buf,
|
|
180
|
+
a))))}function Rb(a,b){function c(){let m=[],n;do n=d.getUint8(h),m.push((new TextDecoder).decode(a.subarray(h+1,h+1+n))),h+=n+1;while(0<n);return m}let d=new DataView(a.buffer,a.byteOffset,a.byteLength),e={id:d.getUint16(0),flags:d.getUint16(2),questions:[],answers:[]};var f=d.getUint16(4);let g=d.getUint16(6);d.getUint16(8);d.getUint16(10);let h=12;for(var l=0;l<f;l++)e.questions.push({name:c(),type:d.getInt16(h),class:d.getInt16(h+2)}),h+=4;for(f=0;f<g;f++){l={name:c(),type:d.getInt16(h),class:d.getUint16(h+
|
|
181
|
+
2),ttl:d.getUint32(h+4)};h+=8;let m=d.getUint16(h);h+=2;l.data=a.subarray(h,h+m);h+=m;e.answers.push(l)}b.dns=e}function Tb(a,b){var c=b.vm_ip.join(".");const d=b.router_ip.join("."),e=16383*Math.random()|0;let f,g,h=0;do f=49152+(e+h)%16383,g=`${c}:${a}:${d}:${f}`;while(16383>++h&&b.tcp_conn[g]);if(b.tcp_conn[g])throw Error("pool of dynamic TCP port numbers exhausted, connection aborted");c=new Sb(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;
|
|
182
|
+
b.tcp_conn[g]=c;c.connect();return c}function Ub(a,b){return new Promise(c=>{let d=Tb(a,b);d.state="syn-probe";d.on("probe",c)})}function Sb(a){this.mtu=a.mtu||1500;const b=this.mtu-20-20;this.state="closed";this.net=a;this.send_buffer=new Ab(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={}}Sb.prototype.on=function(a,b){this.events_handlers[a]=b};Sb.prototype.emit=function(a,...b){this.events_handlers[a]&&
|
|
183
|
+
this.events_handlers[a].apply(this,b)};Sb.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};Sb.prototype.packet_reply=function(a,b){a={sport:a.tcp.dport,dport:a.tcp.sport,winsize:a.tcp.winsize,ackn:this.ack,seq:this.seq};if(b)for(const c in b)a[c]=b[c];b=this.ipv4_reply();b.tcp=a;return b};Sb.prototype.connect=
|
|
184
|
+
function(){this.seq=1338;this.ack=1;this.start_seq=0;this.winsize=64240;"syn-probe"!==this.state&&(this.state="syn-sent");let a=this.ipv4_reply();a.ipv4.id=2345;a.tcp={sport:this.sport,dport:this.dport,seq:1337,ackn:0,winsize:0,syn:!0};this.net.receive(Nb(this.net.eth_encoder_buf,a))};Sb.prototype.accept=function(a){a=a||this.last;this.net.tcp_conn[this.tuple]=this;this.seq=1338;this.ack=a.tcp.seq+1;this.start_seq=a.tcp.seq;this.winsize=a.tcp.winsize;let b=this.ipv4_reply();b.tcp={sport:this.sport,
|
|
185
|
+
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(Nb(this.net.eth_encoder_buf,b))};Sb.prototype.process=function(a){this.last=a;if("closed"===this.state)a=this.packet_reply(a,{rst:!0}),this.net.receive(Nb(this.net.eth_encoder_buf,a));else if(a.tcp.rst){if("syn-probe"===this.state)this.emit("probe",!1);else this.on_close();this.release()}else if(a.tcp.syn)"syn-sent"===this.state&&a.tcp.ack?(this.ack=a.tcp.seq+
|
|
186
|
+
1,this.start_seq=a.tcp.seq,this.last_received_ackn=a.tcp.ackn,a=this.ipv4_reply(),this.net.receive(Nb(this.net.eth_encoder_buf,a)),this.state="established",this.emit("connect")):"syn-probe"===this.state&&a.tcp.ack&&(this.emit("probe",!0),a=this.packet_reply(a,{rst:!0}),this.net.receive(Nb(this.net.eth_encoder_buf,a)),this.release());else{if(a.tcp.ack)if("syn-received"===this.state)this.state="established";else if("fin-wait-1"===this.state)a.tcp.fin||(this.state="fin-wait-2");else if("closing"===this.state||
|
|
187
|
+
"last-ack"===this.state){this.release();return}if(void 0===this.last_received_ackn)this.last_received_ackn=a.tcp.ackn;else{var b=a.tcp.ackn-this.last_received_ackn;if(0<b){if(this.last_received_ackn=a.tcp.ackn,this.send_buffer.remove(b),this.seq+=b,this.pending=!1,this.delayed_send_fin&&!this.send_buffer.length){this.delayed_send_fin=!1;this.state=this.delayed_state;a=this.ipv4_reply();a.tcp.fin=!0;this.net.receive(Nb(this.net.eth_encoder_buf,a));return}}else if(0>b){a=this.packet_reply(a,{rst:!0});
|
|
188
|
+
this.net.receive(Nb(this.net.eth_encoder_buf,a));this.on_close();this.release();return}}a.tcp.fin?(++this.ack,b=this.packet_reply(a,{}),"established"===this.state?(b.tcp.ack=!0,this.state="close-wait",this.on_shutdown()):"fin-wait-1"===this.state?(a.tcp.ack?this.release():this.state="closing",b.tcp.ack=!0):"fin-wait-2"===this.state?(this.release(),b.tcp.ack=!0):(this.release(),this.on_close(),b.tcp.rst=!0),this.net.receive(Nb(this.net.eth_encoder_buf,b))):this.ack!==a.tcp.seq?(a=this.packet_reply(a,
|
|
189
|
+
{ack:!0}),this.net.receive(Nb(this.net.eth_encoder_buf,a))):a.tcp.ack&&0<a.tcp_data.length&&(this.ack+=a.tcp_data.length,b=this.ipv4_reply(),this.net.receive(Nb(this.net.eth_encoder_buf,b)),this.emit("data",a.tcp_data));this.pump()}};Sb.prototype.write=function(a){this.in_active_close||this.send_buffer.write(a);this.pump()};Sb.prototype.writev=function(a){if(!this.in_active_close)for(const b of a)this.send_buffer.write(b);this.pump()};Sb.prototype.close=function(){if(!this.in_active_close){this.in_active_close=
|
|
190
|
+
!0;if("established"===this.state||"syn-received"===this.state)var a="fin-wait-1";else if("close-wait"===this.state)a="last-ack";else{this.release();return}this.send_buffer.length||this.pending?(this.delayed_send_fin=!0,this.delayed_state=a):(this.state=a,a=this.ipv4_reply(),a.tcp.fin=!0,this.net.receive(Nb(this.net.eth_encoder_buf,a)))}this.pump()};Sb.prototype.on_shutdown=function(){this.emit("shutdown")};Sb.prototype.on_close=function(){this.emit("close")};Sb.prototype.release=function(){this.net.tcp_conn[this.tuple]&&
|
|
191
|
+
(this.state="closed",delete this.net.tcp_conn[this.tuple])};Sb.prototype.pump=function(){if(this.send_buffer.length&&!this.pending){const a=this.send_chunk_buf,b=this.send_buffer.peek(a),c=this.ipv4_reply();c.tcp.psh=!0;c.tcp_data=a.subarray(0,b);this.net.receive(Nb(this.net.eth_encoder_buf,c));this.pending=!0}};function Vb(a,b){b=b||{};this.bus=a;this.id=b.id||0;this.router_mac=new Uint8Array((b.router_mac||"52:54:0:1:2:3").split(":").map(function(c){return parseInt(c,16)}));this.router_ip=new Uint8Array((b.router_ip||
|
|
192
|
+
"192.168.86.1").split(".").map(function(c){return parseInt(c,10)}));this.vm_ip=new Uint8Array((b.vm_ip||"192.168.86.100").split(".").map(function(c){return parseInt(c,10)}));this.masquerade=void 0===b.masquerade||!!b.masquerade;this.vm_mac=new Uint8Array(6);this.dns_method=b.dns_method||"static";this.doh_server=b.doh_server;this.tcp_conn={};this.mtu=b.mtu;this.eth_encoder_buf=Bb(this.mtu);this.fetch=(...c)=>fetch(...c);this.cors_proxy=b.cors_proxy;this.bus.register("net"+this.id+"-mac",function(c){this.vm_mac=
|
|
193
|
+
new Uint8Array(c.split(":").map(function(d){return parseInt(d,16)}))},this);this.bus.register("net"+this.id+"-send",function(c){this.send(c)},this);this.bus.register("tcp-connection",c=>{80===c.sport&&(c.on("data",Wb),c.accept())},this)}Vb.prototype.destroy=function(){};Vb.prototype.connect=function(a){return Tb(a,this)};Vb.prototype.tcp_probe=function(a){return Ub(a,this)};async function Wb(a){this.read=this.read||"";if((this.read+=(new TextDecoder).decode(a))&&-1!==this.read.indexOf("\r\n\r\n")){a=
|
|
194
|
+
this.read.indexOf("\r\n\r\n");var b=this.read.substring(0,a).split(/\r\n/);a=this.read.substring(a+4);this.read="";let c=b[0].split(" "),d;d=/^https?:/.test(c[1])?new URL(c[1]):new URL("http://host"+c[1]);"undefined"!==typeof window&&"http:"===d.protocol&&"https:"===window.location.protocol&&(d.protocol="https:");let e=new Headers;for(let h=1;h<b.length;++h){const l=this.net.parse_http_header(b[h]);if(!l){console.warn('The request contains an invalid header: "%s"',b[h]);this.net.respond_text_and_close(this,
|
|
195
|
+
400,"Bad Request",`Invalid header in request: ${b[h]}`);return}"host"===l.key.toLowerCase()?d.host=l.value:e.append(l.key,l.value)}if(!this.net.cors_proxy&&/^\d+\.external$/.test(d.hostname))if(b=parseInt(d.hostname.split(".")[0],10),!isNaN(b)&&0<b&&65536>b)d.protocol="http:",d.hostname="localhost",d.port=b.toString(10);else{console.warn('Unknown port for localhost: "%s"',d.href);this.net.respond_text_and_close(this,400,"Bad Request",`Unknown port for localhost: ${d.href}`);return}this.name=d.href;
|
|
196
|
+
b={method:c[0],headers:e};-1!==["put","post"].indexOf(b.method.toLowerCase())&&(b.body=a);const f=this.net.cors_proxy?this.net.cors_proxy+encodeURIComponent(d.href):d.href;new TextEncoder;let g=!1;this.net.fetch(f,b).then(h=>{let l=new Headers(h.headers);l.delete("content-encoding");l.delete("keep-alive");l.delete("content-length");l.delete("transfer-encoding");l.set("x-was-fetch-redirected",`${!!h.redirected}`);l.set("x-fetch-resp-url",h.url);l.set("connection","close");this.write(this.net.form_response_head(h.status,
|
|
197
|
+
h.statusText,l));g=!0;if(h.body&&h.body.getReader){const m=h.body.getReader(),n=({value:p,done:q})=>{p&&this.write(p);if(q)this.close();else return m.read().then(n)};m.read().then(n)}else h.arrayBuffer().then(m=>{this.write(new Uint8Array(m));this.close()})}).catch(h=>{console.warn("Fetch Failed: "+f+"\n"+h);g||this.net.respond_text_and_close(this,502,"Fetch Error",`Fetch ${f} failed:\n\n${h.stack||h.message}`);this.close()})}}Vb.prototype.fetch=async function(a,b){this.cors_proxy&&(a=this.cors_proxy+
|
|
198
|
+
encodeURIComponent(a));try{const c=await fetch(a,b),d=await c.arrayBuffer();return[c,d]}catch(c){return console.warn("Fetch Failed: "+a+"\n"+c),[{status:502,statusText:"Fetch Error",headers:new Headers({"Content-Type":"text/plain"})},(new TextEncoder).encode(`Fetch ${a} failed:\n\n${c.stack}`).buffer]}};Vb.prototype.form_response_head=function(a,b,c){a=[`HTTP/1.1 ${a} ${b}`];for(const [d,e]of c.entries())a.push(`${d}: ${e}`);return(new TextEncoder).encode(a.join("\r\n")+"\r\n\r\n")};Vb.prototype.respond_text_and_close=
|
|
199
|
+
function(a,b,c,d){const e=new Headers({"content-type":"text/plain","content-length":d.length.toString(10),connection:"close"});a.writev([this.form_response_head(b,c,e),(new TextEncoder).encode(d)]);a.close()};Vb.prototype.parse_http_header=function(a){var b=a.match(/^([^:]*):(.*)$/);if(b&&(a=b[1],b=b[2].trim(),0!==a.length&&0!==b.length&&/^[\w-]+$/.test(a)&&/^[\x20-\x7E]+$/.test(b)))return{key:a,value:b}};Vb.prototype.send=function(a){Qb(a,this)};Vb.prototype.receive=function(a){this.bus.send("net"+
|
|
200
|
+
this.id+"-receive",new Uint8Array(a))};function Xb(a,b,c){this.register_ws(a);this.last_stream=1;this.connections={0:{congestion:0}};this.congested_buffer=[];c=c||{};this.bus=b;this.id=c.id||0;this.router_mac=new Uint8Array((c.router_mac||"52:54:0:1:2:3").split(":").map(function(d){return parseInt(d,16)}));this.router_ip=new Uint8Array((c.router_ip||"192.168.86.1").split(".").map(function(d){return parseInt(d,10)}));this.vm_ip=new Uint8Array((c.vm_ip||"192.168.86.100").split(".").map(function(d){return parseInt(d,
|
|
201
|
+
10)}));this.masquerade=void 0===c.masquerade||!!c.masquerade;this.vm_mac=new Uint8Array(6);this.dns_method=c.dns_method||"doh";this.doh_server=c.doh_server;this.tcp_conn={};this.mtu=c.mtu;this.eth_encoder_buf=Bb(this.mtu);this.bus.register("net"+this.id+"-mac",function(d){this.vm_mac=new Uint8Array(d.split(":").map(function(e){return parseInt(e,16)}))},this);this.bus.register("net"+this.id+"-send",function(d){this.send(d)},this)}Xb.prototype.register_ws=function(a){this.wispws=new WebSocket(a.replace("wisp://",
|
|
202
|
+
"ws://").replace("wisps://","wss://"));this.wispws.binaryType="arraybuffer";this.wispws.onmessage=b=>{this.process_incoming_wisp_frame(new Uint8Array(b.data))};this.wispws.onclose=()=>{setTimeout(()=>{this.register_ws(a)},1E4)}};Xb.prototype.send_packet=function(a,b,c){this.connections[c]&&(0<this.connections[c].congestion?("DATA"===b&&this.connections[c].congestion--,this.wispws.send(a)):(this.connections[c].congested=!0,this.congested_buffer.push({data:a,type:b})))};Xb.prototype.process_incoming_wisp_frame=
|
|
203
|
+
function(a){const b=new DataView(a.buffer),c=b.getUint32(1,!0);switch(a[0]){case 2:if(this.connections[c])this.connections[c].data_callback(a.slice(5));else throw Error("Got a DATA packet but stream not registered. ID: "+c);break;case 3:this.connections[c]&&(this.connections[c].congestion=b.getUint32(5,!0));if(this.connections[c].congested){a=this.congested_buffer.slice(0);this.congested_buffer.length=0;this.connections[c].congested=!1;for(const d of a)this.send_packet(d.data,d.type,c)}break;case 4:this.connections[c]&&
|
|
204
|
+
this.connections[c].close_callback(b.getUint8(5)),delete this.connections[c]}};Xb.prototype.send_wisp_frame=function(a){let b,c;switch(a.type){case "CONNECT":const d=(new TextEncoder).encode(a.hostname);b=new Uint8Array(8+d.length);c=new DataView(b.buffer);c.setUint8(0,1);c.setUint32(1,a.stream_id,!0);c.setUint8(5,1);c.setUint16(6,a.port,!0);b.set(d,8);this.connections[a.stream_id]={data_callback:a.data_callback,close_callback:a.close_callback,congestion:this.connections[0].congestion};break;case "DATA":b=
|
|
205
|
+
new Uint8Array(5+a.data.length);c=new DataView(b.buffer);c.setUint8(0,2);c.setUint32(1,a.stream_id,!0);b.set(a.data,5);break;case "CLOSE":b=new Uint8Array(6),c=new DataView(b.buffer),c.setUint8(0,4),c.setUint32(1,a.stream_id,!0),c.setUint8(5,a.reason)}this.send_packet(b,a.type,a.stream_id)};Xb.prototype.destroy=function(){this.wispws&&(this.wispws.onmessage=null,this.wispws.onclose=null,this.wispws.close(),this.wispws=null)};Xb.prototype.on_tcp_connection=function(a,b){a.stream_id=this.last_stream++;
|
|
206
|
+
a.on("data",c=>{0!==c.length&&this.send_wisp_frame({type:"DATA",stream_id:a.stream_id,data:c})});a.on_close=()=>{this.send_wisp_frame({type:"CLOSE",stream_id:a.stream_id,reason:2})};a.on_shutdown=a.on_close;this.send_wisp_frame({type:"CONNECT",stream_id:a.stream_id,hostname:b.ipv4.dest.join("."),port:a.sport,data_callback:c=>{a.write(c)},close_callback:()=>{a.close()}});a.accept();return!0};Xb.prototype.send=function(a){Qb(a,this)};Xb.prototype.receive=function(a){this.bus.send("net"+this.id+"-receive",
|
|
207
|
+
new Uint8Array(a))};const Yb="undefined"!==typeof window&&0<=window.navigator.platform.toString().toLowerCase().search("win");function Zb(a){function b(v){return v.shiftKey&&v.ctrlKey&&(73===v.keyCode||74===v.keyCode||75===v.keyCode)||!x.emu_enabled?!1:v.target?v.target.classList.contains("phone_keyboard")||"INPUT"!==v.target.nodeName&&"TEXTAREA"!==v.target.nodeName:!0}function c(v){!v.altKey&&n[56]&&l(56,!1);return g(v,!1)}function d(v){!v.altKey&&n[56]&&l(56,!1);return g(v,!0)}function e(){for(var v=
|
|
208
|
+
Object.keys(n),L,T=0;T<v.length;T++)L=+v[T],n[L]&&l(L,!1);n={}}function f(v){if(x.bus&&b(v))switch(v.inputType){case "insertText":for(var L=0;L<v.data.length;L++)x.simulate_char(v.data[L]);break;case "insertLineBreak":x.simulate_press(13);break;case "deleteContentBackward":x.simulate_press(8)}}function g(v,L){if(x.bus&&b(v)&&""!==v.code&&"Process"!==v.key&&"Unidentified"!==v.key&&229!==v.keyCode){v.preventDefault&&v.preventDefault();if(Yb&&(p&&(clearTimeout(r),v.getModifierState&&v.getModifierState("AltGraph")&&
|
|
209
|
+
q===L&&"ControlLeft"===p.code&&"AltRight"===v.code||h(p,q),p=null),"ControlLeft"===v.code))return p=v,q=L,r=setTimeout(()=>{h(p,q);p=null},10),!1;h(v,L);return!1}}function h(v,L){a:{if(void 0!==v.code){var T=N[v.code];if(void 0!==T)break a}T=y[v.keyCode]}T?l(T,L,v.repeat):console.log("Missing char in map: keyCode="+(v.keyCode||-1).toString(16)+" code="+v.code)}function l(v,L,T){if(L)n[v]&&!T&&l(v,!1);else if(!n[v])return;(n[v]=L)||(v|=128);255<v?(m(v>>8),m(v&255)):m(v)}function m(v){x.bus.send("keyboard-code",
|
|
210
|
+
v)}var n={},p=null,q=!1,r=0,x=this;this.emu_enabled=!0;const y=new Uint16Array([0,0,0,0,0,0,0,0,14,15,0,0,0,28,0,0,42,29,56,0,58,0,0,0,0,0,0,1,0,0,0,0,57,57417,57425,57423,57415,57419,57416,57421,80,0,0,0,0,82,83,0,11,2,3,4,5,6,7,8,9,10,0,39,0,13,0,0,0,30,48,46,32,18,33,34,35,23,36,37,38,50,49,24,25,16,19,31,20,22,47,17,45,21,44,57435,57436,57437,0,0,82,79,80,81,75,76,77,71,72,73,0,0,0,0,0,0,59,60,61,62,63,64,65,66,67,68,87,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
211
|
+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,39,13,51,12,52,53,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,26,43,27,40,0,57435,57400,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),u={8:8,10:13,32:32,39:222,44:188,45:189,46:190,47:191,48:48,49:49,50:50,51:51,52:52,53:53,54:54,55:55,56:56,57:57,59:186,61:187,91:219,92:220,93:221,96:192,97:65,98:66,99:67,100:68,101:69,102:70,103:71,104:72,105:73,106:74,107:75,108:76,109:77,110:78,111:79,112:80,113:81,114:82,115:83,116:84,117:85,118:86,119:87,120:88,
|
|
212
|
+
121:89,122:90},G={33:49,34:222,35:51,36:52,37:53,38:55,40:57,41:48,42:56,43:187,58:186,60:188,62:190,63:191,64:50,65:65,66:66,67:67,68:68,69:69,70:70,71:71,72:72,73:73,74:74,75:75,76:76,77:77,78:78,79:79,80:80,81:81,82:82,83:83,84:84,85:85,86:86,87:87,88:88,89:89,90:90,94:54,95:189,123:219,124:220,125:221,126:192};var N={Escape:1,Digit1:2,Digit2:3,Digit3:4,Digit4:5,Digit5:6,Digit6:7,Digit7:8,Digit8:9,Digit9:10,Digit0:11,Minus:12,Equal:13,Backspace:14,Tab:15,KeyQ:16,KeyW:17,KeyE:18,KeyR:19,KeyT:20,
|
|
213
|
+
KeyY:21,KeyU:22,KeyI:23,KeyO:24,KeyP:25,BracketLeft:26,BracketRight:27,Enter:28,ControlLeft:29,KeyA:30,KeyS:31,KeyD:32,KeyF:33,KeyG:34,KeyH:35,KeyJ:36,KeyK:37,KeyL:38,Semicolon:39,Quote:40,Backquote:41,ShiftLeft:42,Backslash:43,KeyZ:44,KeyX:45,KeyC:46,KeyV:47,KeyB:48,KeyN:49,KeyM:50,Comma:51,Period:52,Slash:53,IntlRo:53,ShiftRight:54,NumpadMultiply:55,AltLeft:56,Space:57,CapsLock:58,F1:59,F2:60,F3:61,F4:62,F5:63,F6:64,F7:65,F8:66,F9:67,F10:68,NumLock:69,ScrollLock:70,Numpad7:71,Numpad8:72,Numpad9:73,
|
|
214
|
+
NumpadSubtract:74,Numpad4:75,Numpad5:76,Numpad6:77,NumpadAdd:78,Numpad1:79,Numpad2:80,Numpad3:81,Numpad0:82,NumpadDecimal:83,IntlBackslash:86,F11:87,F12:88,NumpadEnter:57372,ControlRight:57373,NumpadDivide:57397,AltRight:57400,Home:57415,ArrowUp:57416,PageUp:57417,ArrowLeft:57419,ArrowRight:57421,End:57423,ArrowDown:57424,PageDown:57425,Insert:57426,Delete:57427,MetaLeft:57435,OSLeft:57435,MetaRight:57436,OSRight:57436,ContextMenu:57437};this.bus=a;this.destroy=function(){"undefined"!==typeof window&&
|
|
215
|
+
(window.removeEventListener("keyup",c,!1),window.removeEventListener("keydown",d,!1),window.removeEventListener("blur",e,!1),window.removeEventListener("input",f,!1))};this.init=function(){"undefined"!==typeof window&&(this.destroy(),window.addEventListener("keyup",c,!1),window.addEventListener("keydown",d,!1),window.addEventListener("blur",e,!1),window.addEventListener("input",f,!1))};this.init();this.simulate_press=function(v){v={keyCode:v};g(v,!0);g(v,!1)};this.simulate_char=function(v){var L=
|
|
216
|
+
v.charCodeAt(0);L in u?this.simulate_press(u[L]):L in G?(m(42),this.simulate_press(G[L]),m(170)):console.log("ascii -> keyCode not found: ",L,v)}}function $b(a,b){function c(u){if(!y.enabled||!y.emu_enabled)return!1;var G=b||document.body,N;if(!(N=document.pointerLockElement))a:{for(u=u.target;u.parentNode;){if(u===G){N=!0;break a}u=u.parentNode}N=!1}return N}function d(u){c(u)&&(u=u.changedTouches)&&u.length&&(u=u[u.length-1],r=u.clientX,x=u.clientY)}function e(){if(n||q||p)y.bus.send("mouse-click",
|
|
217
|
+
[!1,!1,!1]),n=q=p=!1}function f(u){if(y.bus&&c(u)&&y.is_running){var G=0,N=0,v=u.changedTouches;v?v.length&&(v=v[v.length-1],G=v.clientX-r,N=v.clientY-x,r=v.clientX,x=v.clientY,u.preventDefault()):"number"===typeof u.movementX?(G=u.movementX,N=u.movementY):"number"===typeof u.webkitMovementX?(G=u.webkitMovementX,N=u.webkitMovementY):"number"===typeof u.mozMovementX?(G=u.mozMovementX,N=u.mozMovementY):(G=u.clientX-r,N=u.clientY-x,r=u.clientX,x=u.clientY);y.bus.send("mouse-delta",[1*G,-(1*N)]);b&&y.bus.send("mouse-absolute",
|
|
218
|
+
[u.pageX-b.offsetLeft,u.pageY-b.offsetTop,b.offsetWidth,b.offsetHeight])}}function g(u){c(u)&&l(u,!0)}function h(u){c(u)&&l(u,!1)}function l(u,G){y.bus&&(1===u.which?n=G:2===u.which?q=G:3===u.which&&(p=G),y.bus.send("mouse-click",[n,q,p]),u.preventDefault())}function m(u){if(c(u)){var G=u.wheelDelta||-u.detail;0>G?G=-1:0<G&&(G=1);y.bus.send("mouse-wheel",[G,0]);u.preventDefault()}}var n=!1,p=!1,q=!1,r=0,x=0,y=this;this.enabled=!1;this.emu_enabled=!0;this.bus=a;this.bus.register("mouse-enable",function(u){this.enabled=
|
|
219
219
|
u},this);this.is_running=!1;this.bus.register("emulator-stopped",function(){this.is_running=!1},this);this.bus.register("emulator-started",function(){this.is_running=!0},this);this.destroy=function(){"undefined"!==typeof window&&(window.removeEventListener("touchstart",d,!1),window.removeEventListener("touchend",e,!1),window.removeEventListener("touchmove",f,!1),window.removeEventListener("mousemove",f,!1),window.removeEventListener("mousedown",g,!1),window.removeEventListener("mouseup",h,!1),window.removeEventListener("wheel",
|
|
220
220
|
m,{passive:!1}))};this.init=function(){"undefined"!==typeof window&&(this.destroy(),window.addEventListener("touchstart",d,!1),window.addEventListener("touchend",e,!1),window.addEventListener("touchmove",f,!1),window.addEventListener("mousemove",f,!1),window.addEventListener("mousedown",g,!1),window.addEventListener("mouseup",h,!1),window.addEventListener("wheel",m,{passive:!1}))};this.init()}function gc(a){var b,c=0,d=0,e=sa(a?.encoding);this.put_char=function(f,g,h){b[f*c+g]=h};this.destroy=function(){};
|
|
221
221
|
this.pause=function(){};this.continue=function(){};this.set_mode=function(){};this.set_font_bitmap=function(){};this.set_font_page=function(){};this.clear_screen=function(){};this.set_size_text=function(f,g){if(f!==c||g!==d)b=new Uint8Array(f*g),c=f,d=g};this.set_size_graphical=function(){};this.set_scale=function(){};this.update_cursor_scanline=function(){};this.update_cursor=function(){};this.update_buffer=function(){};this.get_text_screen=function(){for(var f=[],g=0;g<d;g++)f.push(this.get_text_row(g));
|