v86 0.5.290 → 0.5.292
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 +6 -6
- package/build/libv86-debug.mjs +84 -84
- package/build/libv86.js +3 -3
- package/build/libv86.mjs +2 -2
- package/package.json +1 -1
package/build/libv86-debug.js
CHANGED
|
@@ -2204,12 +2204,12 @@ function $restore_state$$module$src$state$$($cpu$jscomp$5$$, $state$jscomp$9$$)
|
|
|
2204
2204
|
$state$jscomp$9$$ = new Uint8Array($state$jscomp$9$$);
|
|
2205
2205
|
if (4247762216 === (new Uint32Array($state$jscomp$9$$.buffer, 0, 1))[0]) {
|
|
2206
2206
|
var $buffers$jscomp$4_ctx_info_block_len$jscomp$1$$ = $cpu$jscomp$5$$.zstd_create_ctx($state$jscomp$9$$.length);
|
|
2207
|
-
(new Uint8Array($cpu$jscomp$5$$.wasm_memory.buffer, $cpu$jscomp$5$$.zstd_get_src_ptr($buffers$jscomp$4_ctx_info_block_len$jscomp$1$$), $state$jscomp$9$$.length)).set($state$jscomp$9$$);
|
|
2208
|
-
var $buffer_infos$jscomp$2_info_block_obj$jscomp$1_ptr_state_object$$ = $cpu$jscomp$5$$.zstd_read($buffers$jscomp$4_ctx_info_block_len$jscomp$1$$, 16), $buffers$jscomp$3_header_block$jscomp$2_info_block_buffer$jscomp$1_info_block_obj$$ = new Uint8Array($cpu$jscomp$5$$.wasm_memory.buffer, $buffer_infos$jscomp$2_info_block_obj$jscomp$1_ptr_state_object
|
|
2207
|
+
(new Uint8Array($cpu$jscomp$5$$.wasm_memory.buffer, $cpu$jscomp$5$$.zstd_get_src_ptr($buffers$jscomp$4_ctx_info_block_len$jscomp$1$$) >>> 0, $state$jscomp$9$$.length)).set($state$jscomp$9$$);
|
|
2208
|
+
var $buffer_infos$jscomp$2_info_block_obj$jscomp$1_ptr_state_object$$ = $cpu$jscomp$5$$.zstd_read($buffers$jscomp$4_ctx_info_block_len$jscomp$1$$, 16), $buffers$jscomp$3_header_block$jscomp$2_info_block_buffer$jscomp$1_info_block_obj$$ = new Uint8Array($cpu$jscomp$5$$.wasm_memory.buffer, $buffer_infos$jscomp$2_info_block_obj$jscomp$1_ptr_state_object$$ >>> 0, 16), $info_block_len_position$jscomp$1$$ = $read_state_header$$($buffers$jscomp$3_header_block$jscomp$2_info_block_buffer$jscomp$1_info_block_obj$$,
|
|
2209
2209
|
!1);
|
|
2210
2210
|
$cpu$jscomp$5$$.zstd_read_free($buffer_infos$jscomp$2_info_block_obj$jscomp$1_ptr_state_object$$, 16);
|
|
2211
2211
|
$buffer_infos$jscomp$2_info_block_obj$jscomp$1_ptr_state_object$$ = $cpu$jscomp$5$$.zstd_read($buffers$jscomp$4_ctx_info_block_len$jscomp$1$$, $info_block_len_position$jscomp$1$$);
|
|
2212
|
-
$buffers$jscomp$3_header_block$jscomp$2_info_block_buffer$jscomp$1_info_block_obj$$ = new Uint8Array($cpu$jscomp$5$$.wasm_memory.buffer, $buffer_infos$jscomp$2_info_block_obj$jscomp$1_ptr_state_object
|
|
2212
|
+
$buffers$jscomp$3_header_block$jscomp$2_info_block_buffer$jscomp$1_info_block_obj$$ = new Uint8Array($cpu$jscomp$5$$.wasm_memory.buffer, $buffer_infos$jscomp$2_info_block_obj$jscomp$1_ptr_state_object$$ >>> 0, $info_block_len_position$jscomp$1$$);
|
|
2213
2213
|
$buffers$jscomp$3_header_block$jscomp$2_info_block_buffer$jscomp$1_info_block_obj$$ = $read_info_block$$($buffers$jscomp$3_header_block$jscomp$2_info_block_buffer$jscomp$1_info_block_obj$$);
|
|
2214
2214
|
$cpu$jscomp$5$$.zstd_read_free($buffer_infos$jscomp$2_info_block_obj$jscomp$1_ptr_state_object$$, $info_block_len_position$jscomp$1$$);
|
|
2215
2215
|
$buffer_infos$jscomp$2_info_block_obj$jscomp$1_ptr_state_object$$ = $buffers$jscomp$3_header_block$jscomp$2_info_block_buffer$jscomp$1_info_block_obj$$.state;
|
|
@@ -2219,7 +2219,7 @@ function $restore_state$$module$src$state$$($cpu$jscomp$5$$, $state$jscomp$9$$)
|
|
|
2219
2219
|
for (var $buffer_info_info_block_buffer$jscomp$2_state_object$jscomp$1$$ of $buffer_infos$jscomp$1_front_padding$$) {
|
|
2220
2220
|
$buffer_infos$jscomp$1_front_padding$$ = ($info_block_len_position$jscomp$1$$ + 3 & -4) - $info_block_len_position$jscomp$1$$;
|
|
2221
2221
|
if (1048576 < $buffer_info_info_block_buffer$jscomp$2_state_object$jscomp$1$$.length) {
|
|
2222
|
-
var $buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$ = $cpu$jscomp$5$$.zstd_read($buffers$jscomp$4_ctx_info_block_len$jscomp$1$$, $buffer_infos$jscomp$1_front_padding$$);
|
|
2222
|
+
var $buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$ = $cpu$jscomp$5$$.zstd_read($buffers$jscomp$4_ctx_info_block_len$jscomp$1$$, $buffer_infos$jscomp$1_front_padding$$) >>> 0;
|
|
2223
2223
|
$cpu$jscomp$5$$.zstd_read_free($buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$, $buffer_infos$jscomp$1_front_padding$$);
|
|
2224
2224
|
$buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$ = new Uint8Array($buffer_info_info_block_buffer$jscomp$2_state_object$jscomp$1$$.length);
|
|
2225
2225
|
$buffers$jscomp$3_header_block$jscomp$2_info_block_buffer$jscomp$1_info_block_obj$$.push($buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$.buffer);
|
|
@@ -2228,12 +2228,12 @@ function $restore_state$$module$src$state$$($cpu$jscomp$5$$, $state$jscomp$9$$)
|
|
|
2228
2228
|
$dbg_assert$$module$src$log$$(0 <= $remaining_to_read$$);
|
|
2229
2229
|
$remaining_to_read$$ = Math.min($remaining_to_read$$, 1048576);
|
|
2230
2230
|
const $ptr$jscomp$2$$ = $cpu$jscomp$5$$.zstd_read($buffers$jscomp$4_ctx_info_block_len$jscomp$1$$, $remaining_to_read$$);
|
|
2231
|
-
$buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$.set(new Uint8Array($cpu$jscomp$5$$.wasm_memory.buffer, $ptr$jscomp$2
|
|
2231
|
+
$buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$.set(new Uint8Array($cpu$jscomp$5$$.wasm_memory.buffer, $ptr$jscomp$2$$ >>> 0, $remaining_to_read$$), $have_offset$jscomp$39$$);
|
|
2232
2232
|
$cpu$jscomp$5$$.zstd_read_free($ptr$jscomp$2$$, $remaining_to_read$$);
|
|
2233
2233
|
$have_offset$jscomp$39$$ += $remaining_to_read$$;
|
|
2234
2234
|
}
|
|
2235
2235
|
} else {
|
|
2236
|
-
$buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$ = $cpu$jscomp$5$$.zstd_read($buffers$jscomp$4_ctx_info_block_len$jscomp$1$$, $buffer_infos$jscomp$1_front_padding$$ + $buffer_info_info_block_buffer$jscomp$2_state_object$jscomp$1$$.length), $have_offset$jscomp$39$$ = $buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$ + $buffer_infos$jscomp$1_front_padding$$, $buffers$jscomp$3_header_block$jscomp$2_info_block_buffer$jscomp$1_info_block_obj$$.push($cpu$jscomp$5$$.wasm_memory.buffer.slice($have_offset$jscomp$39$$,
|
|
2236
|
+
$buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$ = $cpu$jscomp$5$$.zstd_read($buffers$jscomp$4_ctx_info_block_len$jscomp$1$$, $buffer_infos$jscomp$1_front_padding$$ + $buffer_info_info_block_buffer$jscomp$2_state_object$jscomp$1$$.length), $have_offset$jscomp$39$$ = ($buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$ >>> 0) + $buffer_infos$jscomp$1_front_padding$$, $buffers$jscomp$3_header_block$jscomp$2_info_block_buffer$jscomp$1_info_block_obj$$.push($cpu$jscomp$5$$.wasm_memory.buffer.slice($have_offset$jscomp$39$$,
|
|
2237
2237
|
$have_offset$jscomp$39$$ + $buffer_info_info_block_buffer$jscomp$2_state_object$jscomp$1$$.length)), $cpu$jscomp$5$$.zstd_read_free($buffer$jscomp$31_ptr$jscomp$1_ptr$jscomp$3$$, $buffer_infos$jscomp$1_front_padding$$ + $buffer_info_info_block_buffer$jscomp$2_state_object$jscomp$1$$.length);
|
|
2238
2238
|
}
|
|
2239
2239
|
$info_block_len_position$jscomp$1$$ += $buffer_infos$jscomp$1_front_padding$$ + $buffer_info_info_block_buffer$jscomp$2_state_object$jscomp$1$$.length;
|
package/build/libv86-debug.mjs
CHANGED
|
@@ -116,90 +116,90 @@ this.dma_bytes_block=1024*this.bytes_per_sample;this.dma_bytes_block=Math.min(Ma
|
|
|
116
116
|
b=this.dac_buffers[1].shift_block(this.dac_buffers[1].length);this.bus.send("dac-send-data",[a,b],[a.buffer,b.buffer])}};D.prototype.raise_irq=function(a){B("raise irq",8388608);this.irq_triggered[a]=1;this.cpu.device_raise_irq(this.irq)};D.prototype.lower_irq=function(a){B("lower irq",8388608);this.irq_triggered[a]=0;this.cpu.device_lower_irq(this.irq)};function Va(a,b,c){return(a<b)*b+(a>c)*c+(b<=a&&a<=c)*a}function eb(a){this.message=a}eb.prototype=Error();const fb={Uint8Array,Int8Array,Uint16Array,
|
|
117
117
|
Int16Array,Uint32Array,Int32Array,Float32Array,Float64Array};function gb(a,b){if("object"!==typeof a||null===a)return l("function"!==typeof a),a;if(Array.isArray(a))return a.map(f=>gb(f,b));a.constructor===Object&&(console.log(a),l(a.constructor!==Object,"Expected non-object"));if(a.BYTES_PER_ELEMENT){var c=new Uint8Array(a.buffer,a.byteOffset,a.length*a.BYTES_PER_ELEMENT);a=a.constructor.name.replace("bound ","");l(fb[a]);return{__state_type__:a,buffer_id:b.push(c)-1}}!a.get_state&&console.log("Object without get_state: ",
|
|
118
118
|
a);c=a.get_state();a=[];for(var d=0;d<c.length;d++){var e=c[d];l("function"!==typeof e);a[d]=gb(e,b)}return a}function hb(a,b){if("object"!==typeof a||null===a)return l("function"!==typeof a),a;if(Array.isArray(a)){for(var c=0;c<a.length;c++)a[c]=hb(a[c],b);return a}c=a.__state_type__;l(void 0!==c);const d=fb[c];l(d,"Unkown type: "+c);return new d(b[a.buffer_id])}function ib(a,b){function c(t,z){const A=t.length;if(16>A)throw new eb("Invalid length: "+A);t=new Int32Array(t.buffer,t.byteOffset,4);
|
|
119
|
-
if(-2039052682!==t[0])throw new eb("Invalid header: "+n(t[0]>>>0));if(6!==t[1])throw new eb("Version mismatch: dump="+t[1]+" we=6");if(z&&t[2]!==A)throw new eb("Length doesn't match header: real="+A+" header="+t[2]);return t[3]}function d(t){t=(new TextDecoder).decode(t);return JSON.parse(t)}b=new Uint8Array(b);if(4247762216===(new Uint32Array(b.buffer,0,1))[0]){var e=a.zstd_create_ctx(b.length);(new Uint8Array(a.wasm_memory.buffer,a.zstd_get_src_ptr(e),b.length)).set(b);var f=a.zstd_read(e,16),
|
|
120
|
-
new Uint8Array(a.wasm_memory.buffer,f,16),k=c(g,!1);a.zstd_read_free(f,16);f=a.zstd_read(e,k);g=new Uint8Array(a.wasm_memory.buffer,f,k);g=d(g);a.zstd_read_free(f,k);f=g.state;var m=g.buffer_infos;g=[];k=16+k;for(var p of m){m=(k+3&-4)-k;if(1048576<p.length){var q=a.zstd_read(e,m);a.zstd_read_free(q,m);q=new Uint8Array(p.length);g.push(q.buffer);for(var r=0;r<p.length;){var v=p.length-r;l(0<=v);v=Math.min(v,1048576);const t=a.zstd_read(e,v);q.set(new Uint8Array(a.wasm_memory.buffer,
|
|
121
|
-
v);r+=v}}else q=a.zstd_read(e,m+p.length),r=q+m,g.push(a.wasm_memory.buffer.slice(r,r+p.length)),a.zstd_read_free(q,m+p.length);k+=m+p.length}f=hb(f,g);a.set_state(f);a.zstd_free_ctx(e)}else{e=c(b,!0);if(0>e||e+12>=b.length)throw new eb("Invalid info block length: "+e);p=b.subarray(16,16+e);f=d(p);p=f.state;f=f.buffer_infos;let t=16+e;t=t+3&-4;e=f.map(z=>{const A=t+z.offset;return b.buffer.slice(A,A+z.length)});p=hb(p,e);a.set_state(p)}}function jb(a,b,c,d,e){let f=
|
|
122
|
-
d?"unguarded register":e?"wasm size":"executed";for(let q=0;256>q;q++)for(let r=0;8>r;r++)for(const v of[!1,!0]){var m=a.wm.exports.get_opstats_buffer(b,c,d,e,q,!1,v,r);g.push({opcode:q,count:m,is_mem:v,fixed_g:r});m=a.wm.exports.get_opstats_buffer(b,c,d,e,q,!0,v,r);g.push({opcode:3840|q,count:m,is_mem:v,fixed_g:r})}a=0;b=new Set([38,46,54,62,100,101,102,103,240,242,243]);for(const {count:q,opcode:r}of g)b.has(r)||(a+=q);if(0===a)return"";c=new Uint32Array(256);
|
|
123
|
-
count:r}of g)3840===(q&65280)?b[q&255]+=r:c[q&255]+=r;f=f+"------------------\nTotal: "+(a+"\n");const p=1E7<a?1E3:1;d=Math.max.apply(Math,g.map(({count:q})=>Math.round(q/p)));d=String(d).length;f+=`Instruction counts ${k} (in ${p}):\n`;for(e=0;256>e;e++)f+=e.toString(16).padStart(2,"0")+":"+ca(Math.round(c[e]/p),d),f=15===e%16?f+"\n":f+" ";f=f+"\n"+`Instruction counts ${k} (0f, in ${p}):\n`;for(k=0;256>k;k++)f+=(k&255).toString(16).padStart(2,"0")+":"+ca(Math.round(b[k]/
|
|
124
|
-
f+" ";f+="\n";g=g.filter(({count:q})=>q).sort(({count:q},{count:r})=>r-q);for(const {opcode:q,is_mem:r,fixed_g:v,count:t}of g.slice(0,200))g=q.toString(16)+"_"+v+(r?"_m":"_r"),f+=g+":"+(t/a*100).toFixed(2)+" ";return f+"\n"}function kb(a){this.cpu=a;this.cmos_index=0;this.cmos_data=new Uint8Array(128);this.last_update=this.rtc_time=Date.now();this.next_interrupt_alarm=this.next_interrupt=0;this.periodic_interrupt=!1;this.periodic_interrupt_time=.9765625;this.cmos_a=38;this.cmos_b=
|
|
125
|
-
this.cmos_diag_status=this.cmos_c=0;this.update_interrupt=!1;this.update_interrupt_time=0;a.io.register_write(112,this,function(b){this.cmos_index=b&127;this.nmi_disabled=b>>7});a.io.register_write(113,this,this.cmos_port_write);a.io.register_read(113,this,this.cmos_port_read)}kb.prototype.get_state=function(){var a=[];a[0]=this.cmos_index;a[1]=this.cmos_data;a[2]=this.rtc_time;a[3]=this.last_update;a[4]=this.next_interrupt;a[5]=this.next_interrupt_alarm;a[6]=this.periodic_interrupt;
|
|
126
|
-
a[8]=this.cmos_a;a[9]=this.cmos_b;a[10]=this.cmos_c;a[11]=this.nmi_disabled;a[12]=this.update_interrupt;a[13]=this.update_interrupt_time;a[14]=this.cmos_diag_status;return a};kb.prototype.set_state=function(a){this.cmos_index=a[0];this.cmos_data=a[1];this.rtc_time=a[2];this.last_update=a[3];this.next_interrupt=a[4];this.next_interrupt_alarm=a[5];this.periodic_interrupt=a[6];this.periodic_interrupt_time=a[7];this.cmos_a=a[8];this.cmos_b=a[9];this.cmos_c=a[10];this.nmi_disabled=
|
|
127
|
-
a[12]||!1;this.update_interrupt_time=a[13]||0;this.cmos_diag_status=a[14]||0};kb.prototype.timer=function(a){a=Date.now();this.rtc_time+=a-this.last_update;this.last_update=a;this.periodic_interrupt&&this.next_interrupt<a?(this.cpu.device_raise_irq(8),this.cmos_c|=192,this.next_interrupt+=this.periodic_interrupt_time*Math.ceil((a-this.next_interrupt)/this.periodic_interrupt_time)):this.next_interrupt_alarm&&this.next_interrupt_alarm<a?(this.cpu.device_raise_irq(8),this.cmos_c|=
|
|
128
|
-
0):this.update_interrupt&&this.update_interrupt_time<a&&(this.cpu.device_raise_irq(8),this.cmos_c|=144,this.update_interrupt_time=a+1E3);let b=100;this.periodic_interrupt&&this.next_interrupt&&(b=Math.min(b,Math.max(0,this.next_interrupt-a)));this.next_interrupt_alarm&&(b=Math.min(b,Math.max(0,this.next_interrupt_alarm-a)));this.update_interrupt&&(b=Math.min(b,Math.max(0,this.update_interrupt_time-a)));return b};kb.prototype.bcd_pack=function(a){for(var b=0,c=0,d;a;)d=
|
|
129
|
-
return c};kb.prototype.bcd_unpack=function(a){const b=a&15,c=a>>4&15;l(256>a);l(10>b);l(10>c);return b+10*c};kb.prototype.encode_time=function(a){return this.cmos_b&4?a:this.bcd_pack(a)};kb.prototype.decode_time=function(a){return this.cmos_b&4?a:this.bcd_unpack(a)};kb.prototype.cmos_port_read=function(){var a=this.cmos_index;switch(a){case 0:return B("read second: "+n(this.encode_time((new Date(this.rtc_time)).getUTCSeconds())),65536),this.encode_time((new Date(this.rtc_time)).getUTCSeconds());
|
|
130
|
-
n(this.encode_time((new Date(this.rtc_time)).getUTCMinutes())),65536),this.encode_time((new Date(this.rtc_time)).getUTCMinutes());case 4:return B("read hour: "+n(this.encode_time((new Date(this.rtc_time)).getUTCHours())),65536),this.encode_time((new Date(this.rtc_time)).getUTCHours());case 6:return B("read day: "+n(this.encode_time((new Date(this.rtc_time)).getUTCDay()+1)),65536),this.encode_time((new Date(this.rtc_time)).getUTCDay()+1);case 7:return B("read day of month: "+
|
|
131
|
-
65536),this.encode_time((new Date(this.rtc_time)).getUTCDate());case 8:return B("read month: "+n(this.encode_time((new Date(this.rtc_time)).getUTCMonth()+1)),65536),this.encode_time((new Date(this.rtc_time)).getUTCMonth()+1);case 9:return B("read year: "+n(this.encode_time((new Date(this.rtc_time)).getUTCFullYear()%100)),65536),this.encode_time((new Date(this.rtc_time)).getUTCFullYear()%100);case 10:return 999<=H.microtick()%1E3?this.cmos_a|
|
|
132
|
-
B("cmos reg C read",65536),a=this.cmos_c,this.cmos_c&=-241,a;case 13:return 128;case 14:return B("cmos diagnostic status read",65536),this.cmos_diag_status;case 50:case 55:return B("read century: "+n(this.encode_time((new Date(this.rtc_time)).getUTCFullYear()/100|0)),65536),this.encode_time((new Date(this.rtc_time)).getUTCFullYear()/100|0);default:return B("cmos read from index "+n(a),65536),this.cmos_data[this.cmos_index]}};
|
|
133
|
-
a&127;this.periodic_interrupt_time=1E3/(32768>>(this.cmos_a&15)-1);B("Periodic interrupt, a="+n(this.cmos_a,2)+" t="+this.periodic_interrupt_time,65536);break;case 11:this.cmos_b=a;this.cmos_b&128&&(this.cmos_b&=239);this.cmos_b&64&&(this.next_interrupt=Date.now());if(this.cmos_b&32){a=new Date;const b=this.decode_time(this.cmos_data[1]),c=this.decode_time(this.cmos_data[3]),d=this.decode_time(this.cmos_data[5]),
|
|
134
|
-
e+" hh:mm:ss="+d+":"+c+":"+b+" ms_from_now="+(e-a),65536);this.next_interrupt_alarm=+e}this.cmos_b&16&&(B("update interrupt",65536),this.update_interrupt_time=Date.now());B("cmos b="+n(this.cmos_b,2),65536);break;case 14:this.cmos_diag_status=a;break;case 1:case 3:case 5:this.cmos_write(this.cmos_index,a);break;default:B("cmos write index "+n(this.cmos_index)+": "+n(a),65536)}this.update_interrupt=
|
|
135
|
-
15)};kb.prototype.cmos_read=function(a){l(128>a);return this.cmos_data[a]};kb.prototype.cmos_write=function(a,b){B("cmos "+n(a)+" <- "+n(b),65536);l(128>a);this.cmos_data[a]=b};function lb(a,b){this.cpu=a;this.bus=b;this.counter_start_time=new Float64Array(3);this.counter_start_value=new Uint16Array(3);this.counter_next_low=new Uint8Array(4);this.counter_enabled=new Uint8Array(4);this.counter_mode=
|
|
136
|
-
new Uint16Array(3);this.counter_reload=new Uint16Array(3);a.io.register_read(97,this,function(){var c=H.microtick(),d=66.66666666666667*c&1;c=this.did_rollover(2,c);return d<<4|c<<5});a.io.register_write(97,this,function(c){c&1?this.bus.send("pcspeaker-enable"):this.bus.send("pcspeaker-disable")});a.io.register_read(64,this,function(){return this.counter_read(0)});a.io.register_read(65,
|
|
137
|
-
a.io.register_write(64,this,function(c){this.counter_write(0,c)});a.io.register_write(65,this,function(c){this.counter_write(1,c)});a.io.register_write(66,this,function(c){this.counter_write(2,c);this.bus.send("pcspeaker-update",[this.counter_mode[2],this.counter_reload[2]])});a.io.register_write(67,this,this.port43_write)}lb.prototype.get_state=function(){var a=[];a[0]=this.counter_next_low;
|
|
138
|
-
this.counter_latch_value;a[6]=this.counter_reload;a[7]=this.counter_start_time;a[8]=this.counter_start_value;return a};lb.prototype.set_state=function(a){this.counter_next_low=a[0];this.counter_enabled=a[1];this.counter_mode=a[2];this.counter_read_mode=a[3];this.counter_latch=a[4];this.counter_latch_value=a[5];this.counter_reload=a[6];this.counter_start_time=a[7];this.counter_start_value=a[8]};
|
|
139
|
-
this.get_counter_value(0,a),this.counter_start_time[0]=a,B("pit interrupt. new value: "+this.counter_start_value[0],512),this.cpu.device_lower_irq(0),this.cpu.device_raise_irq(0),0===this.counter_mode[0]&&(this.counter_enabled[0]=0)):this.cpu.device_lower_irq(0),this.counter_enabled[0]&&(c=(this.counter_start_value[0]-Math.floor(1193.1816666*(a-this.counter_start_time[0])))/
|
|
140
|
-
d=Math.floor(1193.1816666*c);b=this.counter_start_value[a]-d;B("diff="+c+" dticks="+d+" value="+b+" reload="+this.counter_reload[a],512);c=this.counter_reload[a];b>=c?(B("Warning: Counter"+a+" value "+b+" is larger than reload "+c,512),b%=c):0>b&&(b=b%c+c);return b};lb.prototype.did_rollover=function(a,b){b-=this.counter_start_time[a];return 0>b?(B("Warning: PIT timer difference is negative, resetting (timer "+
|
|
141
|
-
function(a){var b=this.counter_latch[a];if(b)return this.counter_latch[a]--,2===b?this.counter_latch_value[a]&255:this.counter_latch_value[a]>>8;b=this.counter_next_low[a];3===this.counter_mode[a]&&(this.counter_next_low[a]^=1);a=this.get_counter_value(a,H.microtick());return b?a&255:a>>8};lb.prototype.counter_write=function(a,b){this.counter_reload[a]=this.counter_next_low[a]?this.counter_reload[a]&-256|
|
|
142
|
-
(this.counter_reload[a]=65535),this.counter_start_value[a]=this.counter_reload[a],this.counter_enabled[a]=!0,this.counter_start_time[a]=H.microtick(),B("counter"+a+" reload="+n(this.counter_reload[a])+" tick="+(this.counter_reload[a]||65536)/1193.1816666+"ms",512));3===this.counter_read_mode[a]&&(this.counter_next_low[a]^=1)};lb.prototype.port43_write=function(a){var b=a>>1&7,c=a&1,
|
|
143
|
-
2,b=this.get_counter_value(d,H.microtick()),B("latch: "+b,512),this.counter_latch_value[d]=b?b-1:0):(6<=b&&(b&=-5),B("Control: mode="+b+" ctr="+d+" read_mode="+a+" bcd="+c,512),this.counter_next_low[d]=1===a?1:2===a?0:1,0===d&&this.cpu.device_lower_irq(0),0!==b&&3!==b&&2!==b&&B("Unimplemented counter mode: "+n(b),512),this.counter_mode[d]=b,this.counter_read_mode[d]=a,2===d&&
|
|
144
|
-
B("counter0 ticks every "+(a||65536)/1193.1816666+"ms (reload="+a+")")};function mb(a){if("undefined"!==typeof window)if(window.AudioContext||window.webkitAudioContext){var b=window.AudioWorklet?nb:ob;this.bus=a;this.audio_context=window.AudioContext?new AudioContext:new webkitAudioContext;this.mixer=new pb(a,this.audio_context);this.pcspeaker=new qb(a,this.audio_context,
|
|
145
|
-
this);a.register("emulator-started",function(){this.audio_context.resume()},this);a.register("speaker-confirm-initialized",function(){a.send("speaker-has-initialized")},this);a.send("speaker-has-initialized")}else console.warn("Web browser doesn't support Web Audio API")}mb.prototype.destroy=function(){this.audio_context&&this.audio_context.close();
|
|
146
|
-
this.audio_context.currentTime)}}this.audio_context=b;this.sources=new Map;this.gain_right=this.gain_left=this.volume_right=this.volume_left=this.volume_both=1;this.node_treble_left=this.audio_context.createBiquadFilter();this.node_treble_right=this.audio_context.createBiquadFilter();this.node_treble_left.type="highshelf";
|
|
147
|
-
this.node_bass_left=this.audio_context.createBiquadFilter();this.node_bass_right=this.audio_context.createBiquadFilter();this.node_bass_left.type="lowshelf";this.node_bass_right.type="lowshelf";this.node_bass_left.frequency.setValueAtTime(200,this.audio_context.currentTime);this.node_bass_right.frequency.setValueAtTime(200,
|
|
148
|
-
this.input_left=this.node_treble_left;this.input_right=this.node_treble_right;this.node_treble_left.connect(this.node_bass_left);this.node_bass_left.connect(this.node_gain_left);this.node_gain_left.connect(this.node_merger,0,0);this.node_treble_right.connect(this.node_bass_right);this.node_bass_right.connect(this.node_gain_right);
|
|
149
|
-
d[1])},this);a.register("mixer-disconnect",function(d){this.disconnect_source(d[0],d[1])},this);a.register("mixer-volume",function(d){var e=d[0],f=d[1];d=Math.pow(10,d[2]/20);var g=0===e?this:this.sources.get(e);void 0===g?l(!1,"Mixer set volume - cannot set volume for undefined source: "+e):g.set_volume(d,f)},this);a.register("mixer-gain-left",
|
|
150
|
-
this);a.register("mixer-treble-left",c(this.node_treble_left),this);a.register("mixer-treble-right",c(this.node_treble_right),this);a.register("mixer-bass-left",c(this.node_bass_left),this);a.register("mixer-bass-right",c(this.node_bass_right),this)}pb.prototype.add_source=function(a,b){a=new rb(this.audio_context,a,this.input_left,this.input_right);
|
|
151
|
-
this.sources.get(a);void 0===c?l(!1,"Mixer connect - cannot connect undefined source: "+a):c.connect(b)};pb.prototype.disconnect_source=function(a,b){var c=this.sources.get(a);void 0===c?l(!1,"Mixer disconnect - cannot disconnect undefined source: "+a):c.disconnect(b)};pb.prototype.set_volume=function(a,b){void 0===b&&(b=2);switch(b){case 0:this.volume_left=
|
|
152
|
-
pb.prototype.update=function(){var a=this.volume_both*this.volume_right*this.gain_right;this.node_gain_left.gain.setValueAtTime(this.volume_both*this.volume_left*this.gain_left,this.audio_context.currentTime);this.node_gain_right.gain.setValueAtTime(a,this.audio_context.currentTime)};function rb(a,b,c,d){this.audio_context=a;this.connected_right=
|
|
153
|
-
a.createGain();this.node_gain_right=a.createGain();b.connect(this.node_splitter);this.node_splitter.connect(this.node_gain_left,0);this.node_gain_left.connect(c);this.node_splitter.connect(this.node_gain_right,1);this.node_gain_right.connect(d)}rb.prototype.update=function(){var a=this.connected_right*this.gain_hidden*this.volume_both*this.volume_right;
|
|
154
|
-
this.audio_context.currentTime)};rb.prototype.connect=function(a){var b=!a||2===a;if(b||0===a)this.connected_left=!0;if(b||1===a)this.connected_right=!0;this.update()};rb.prototype.disconnect=function(a){var b=!a||2===a;if(b||0===a)this.connected_left=!1;if(b||1===a)this.connected_right=!1;this.update()};rb.prototype.set_volume=
|
|
155
|
-
b);return}this.update()};rb.prototype.set_gain_hidden=function(a){this.gain_hidden=a};function qb(a,b,c){this.node_oscillator=b.createOscillator();this.node_oscillator.type="square";this.node_oscillator.frequency.setValueAtTime(440,b.currentTime);this.mixer_connection=c.add_source(this.node_oscillator,1);this.mixer_connection.disconnect();
|
|
156
|
-
function(d){var e=d[1],f=0;3===d[0]&&(f=Math.min(1193181.6665999999/e,this.node_oscillator.frequency.maxValue),f=Math.max(f,0));this.node_oscillator.frequency.setValueAtTime(f,b.currentTime)},this)}qb.prototype.start=function(){this.node_oscillator.start()};function nb(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=
|
|
157
|
-
3;p.queue_data=Array(1024);p.queue_start=0;p.queue_end=0;p.queue_length=0;p.queue_size=p.queue_data.length;p.queued_samples=0;p.source_buffer_previous=m;p.source_buffer_current=m;p.source_samples_per_destination=1;p.source_block_start=0;p.source_time=0;p.source_offset=0;p.port.onmessage=q=>{switch(q.data.type){case "queue":p.queue_push(q.data.value);
|
|
158
|
-
AudioWorkletProcessor.prototype);Reflect.setPrototypeOf(k,AudioWorkletProcessor);k.prototype.process=k.prototype.process=function(p,q){for(p=0;p<q[0][0].length;p++){for(var r=0,v=0,t=this.source_offset+this.kernel_size,z=this.source_offset-this.kernel_size+1;z<=t;z++){var A=this.source_block_start+z;r+=this.get_sample(A,
|
|
159
|
-
r;q[0][1][p]=v;this.source_time+=this.source_samples_per_destination;this.source_offset=Math.floor(this.source_time)}q=this.source_offset;q+=this.kernel_size+2;this.source_time-=this.source_offset;this.source_block_start+=this.source_offset;this.source_offset=0;this.ensure_enough_data(q);return!0};k.prototype.kernel=
|
|
160
|
-
k.prototype.ensure_enough_data=function(p){var q=this.source_buffer_current[0].length;q-this.source_block_start<p&&(this.prepare_next_buffer(),this.source_block_start-=q)};k.prototype.prepare_next_buffer=function(){256>this.queued_samples&&this.queue_length&&this.dbg_log("Not enough samples - should not happen during midway of playback");
|
|
161
|
-
this.queue_start,r=0;256>p&&r<this.queue_length;)p+=this.queue_data[q][0].length,q=q+1&this.queue_size-1,r++;p=Math.max(p,256);p=[new Float32Array(p),new Float32Array(p)];p[0].set(this.source_buffer_current[0]);p[1].set(this.source_buffer_current[1]);q=this.source_buffer_current[0].length;for(var v=0;v<r;v++){var t=this.queue_shift();p[0].set(t[0],
|
|
162
|
-
this.port.postMessage({type:"pump"})};k.prototype.queue_push=function(p){this.queue_length<this.queue_size&&(this.queue_data[this.queue_end]=p,this.queue_end=this.queue_end+1&this.queue_size-1,this.queue_length++,this.queued_samples+=p[0].length,this.pump())};k.prototype.queue_shift=function(){if(!this.queue_length)return m;var p=this.queue_data[this.queue_start];
|
|
163
|
-
return p};k.prototype.dbg_log=function(p){this.port.postMessage({type:"debug-log",value:p})};registerProcessor("dac-processor",k)}.toString();var d=b.indexOf("{")+1,e=b.lastIndexOf("}");b=b.substring(d,e);b=new Blob(["var DEBUG = true;\n"+b],{type:"application/javascript"});var f=URL.createObjectURL(b);this.node_processor=null;this.node_output=this.audio_context.createGain();
|
|
164
|
-
"dac-processor",{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[2],parameterData:{},processorOptions:{}});this.node_processor.port.postMessage({type:"sampling-rate",value:this.sampling_rate});this.node_processor.port.onmessage=g=>{switch(g.data.type){case "pump":this.pump();break;case "debug-log":B("SpeakerWorkletDAC - Worklet: "+g.data.value)}};this.node_processor.connect(this.node_output)});
|
|
165
|
-
function(g){this.queue(g)},this);a.register("dac-enable",function(){this.enabled=!0},this);a.register("dac-disable",function(){this.enabled=!1},this);a.register("dac-tell-sampling-rate",function(g){l(0<g,"Sampling rate should be nonzero");this.sampling_rate=g;this.node_processor&&this.node_processor.port.postMessage({type:"sampling-rate",value:g})},this);this.debugger=new wb(this.audio_context,
|
|
166
|
-
this.node_processor.port.postMessage({type:"queue",value:a},[a[0].buffer,a[1].buffer]))};nb.prototype.pump=function(){this.enabled&&this.bus.send("dac-request-data")};function ob(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=22050;this.buffered_time=0;this.rate_ratio=1;this.node_lowpass=this.audio_context.createBiquadFilter();this.node_lowpass.type="lowpass";this.node_output=
|
|
167
|
-
a.register("dac-send-data",function(d){this.queue(d)},this);a.register("dac-enable",function(){this.enabled=!0;this.pump()},this);a.register("dac-disable",function(){this.enabled=!1},this);a.register("dac-tell-sampling-rate",function(d){l(0<d,"Sampling rate should be nonzero");this.sampling_rate=d;this.rate_ratio=Math.ceil(8E3/d);this.node_lowpass.frequency.setValueAtTime(d/2,this.audio_context.currentTime)},
|
|
168
|
-
var b=a[0].length,c=b/this.sampling_rate;if(1<this.rate_ratio){var d=this.audio_context.createBuffer(2,b*this.rate_ratio,this.sampling_rate*this.rate_ratio);for(var e=d.getChannelData(0),f=d.getChannelData(1),g=0,k=0;k<b;k++)for(var m=0;m<this.rate_ratio;m++,g++)e[g]=a[0][k],f[g]=a[1][k]}else d=this.audio_context.createBuffer(2,b,this.sampling_rate),d.copyToChannel?(d.copyToChannel(a[0],
|
|
169
|
-
a.buffer=d;a.connect(this.node_lowpass);a.addEventListener("ended",this.pump.bind(this));d=this.audio_context.currentTime;if(this.buffered_time<d)for(B("Speaker DAC - Creating/Recreating reserve - shouldn't occur frequently during playback"),this.buffered_time=d,d=.2-c,b=0;b<=d;)b+=c,this.buffered_time+=c,setTimeout(()=>this.pump(),1E3*b);a.start(this.buffered_time);
|
|
170
|
-
this.bus.send("dac-request-data"))};function wb(a,b){this.audio_context=a;this.node_source=b;this.node_processor=null;this.node_gain=this.audio_context.createGain();this.node_gain.gain.setValueAtTime(0,this.audio_context.currentTime);this.node_gain.connect(this.audio_context.destination);this.is_active=!1;this.queued_history=[];this.output_history=
|
|
171
|
-
this.output_history.push(this.output);this.node_processor=this.audio_context.createScriptProcessor(1024,2,2);this.node_processor.onaudioprocess=b=>{this.output[0].push(b.inputBuffer.getChannelData(0).slice());this.output[1].push(b.inputBuffer.getChannelData(1).slice())};this.node_source.connect(this.node_processor);this.node_processor.connect(this.node_gain);
|
|
172
|
-
this.node_processor=null};wb.prototype.push_queued_data=function(a){this.is_active&&(this.queued[0].push(a[0].slice()),this.queued[1].push(a[1].slice()))};wb.prototype.download_txt=function(a,b){a=this.output_history[a][b].map(c=>c.join(" ")).join(" ");qa(a,"dacdata.txt")};wb.prototype.download_csv=function(a){a=this.output_history[a];for(var b=
|
|
173
|
-
b;this.socket=void 0;this.id=c||0;this.send_queue=[];this.url=a;this.reconnect_interval=1E4;this.last_connect_attempt=Date.now()-this.reconnect_interval;this.send_queue_limit=64;this.destroyed=!1;this.bus.register("net"+this.id+"-send",function(d){this.send(d)},this)}xb.prototype.handle_message=function(a){this.bus&&this.bus.send("net"+this.id+
|
|
174
|
-
xb.prototype.handle_open=function(){for(var a=0;a<this.send_queue.length;a++)this.send(this.send_queue[a]);this.send_queue=[]};xb.prototype.handle_error=function(){};xb.prototype.destroy=function(){this.destroyed=!0;this.socket&&this.socket.close()};xb.prototype.connect=function(){if("undefined"!==typeof WebSocket){if(this.socket){var a=
|
|
175
|
-
new WebSocket(this.url)}catch(b){console.error(b);return}this.socket.binaryType="arraybuffer";this.socket.onopen=this.handle_open.bind(this);this.socket.onmessage=this.handle_message.bind(this);this.socket.onclose=this.handle_close.bind(this);this.socket.onerror=this.handle_error.bind(this)}}};xb.prototype.send=function(a){this.socket&&
|
|
176
|
-
this.connect())};xb.prototype.change_proxy=function(a){this.url=a;this.socket&&(this.socket.onclose=function(){},this.socket.onerror=function(){},this.socket.close(),this.socket=void 0)};const yb=(new Date("1970-01-01T00:00:00Z")).getTime(),zb=(new Date("1900-01-01T00:00:00Z")).getTime(),Ab=yb-zb,Bb=Math.pow(2,32),Cb=
|
|
177
|
-
b){a=Math.min(a,16);this.maximum_capacity=b?Math.max(b,a):0;this.length=this.head=this.tail=0;this.buffer=new Uint8Array(a)}write(a){const b=a.length;var c=this.length+b;let d=this.buffer.length;if(d<c){for(l(0<d);d<c;)d*=2;if(this.maximum_capacity&&d>this.maximum_capacity)throw Error("stream capacity overflow in GrowableRingbuffer.write(), package dropped");
|
|
178
|
-
c.set(a.subarray(0,f),this.head);c.set(a.subarray(f))}else c.set(a,this.head);this.head=e%d;this.length+=b}peek(a){const b=Math.min(this.length,a.length);if(b){const e=this.buffer;var c=e.length,d=this.tail+b;d>c?(d%=c,c-=this.tail,a.set(e.subarray(this.tail)),a.set(e.subarray(0,d),c)):a.set(e.subarray(this.tail,d))}return b}remove(a){a>this.length&&(a=this.length);
|
|
179
|
-
4),e=d.buffer,f=d.byteOffset;return{eth_frame:d,eth_frame_view:new DataView(e),eth_payload_view:new DataView(e,f+14,a),ipv4_payload_view:new DataView(e,f+34,b),udp_payload_view:new DataView(e,f+42,c),text_encoder:new TextEncoder}}function Hb(a,b,c,d){d.eth_frame.set(b,c.byteOffset+a);return b.length}function Ib(a,b,c,d){const e=c.byteOffset+(a&-2);d=d.eth_frame;for(c=
|
|
180
|
-
a.eth_frame.fill(0);var c=a.eth_frame,d=c.subarray,e=a.eth_frame_view;Hb(0,b.eth.dest,e,a);Hb(6,b.eth.src,e,a);e.setUint16(12,b.eth.ethertype);e=14;if(b.arp){var f=a.eth_payload_view;f.setUint16(0,b.arp.htype);f.setUint16(2,b.arp.ptype);f.setUint8(4,b.arp.sha.length);f.setUint8(5,b.arp.spa.length);f.setUint16(6,b.arp.oper);Hb(8,b.arp.sha,f,a);Hb(14,b.arp.spa,f,a);Hb(18,
|
|
181
|
-
b.icmp.type);k.setUint8(1,b.icmp.code);k.setUint16(2,0);var m=4+Hb(4,b.icmp.data,k,a);k.setUint16(2,Ib(m,0,k,a));g+=m}else if(b.udp){k=a.ipv4_payload_view;var p=8;if(b.dhcp){m=p;var q=a.udp_payload_view;q.setUint8(0,b.dhcp.op);q.setUint8(1,b.dhcp.htype);q.setUint8(2,b.dhcp.hlen);q.setUint8(3,b.dhcp.hops);q.setUint32(4,b.dhcp.xid);q.setUint16(8,b.dhcp.secs);q.setUint16(10,
|
|
182
|
-
Hb(28,b.dhcp.chaddr,q,a);q.setUint32(236,1669485411);p=240;for(var r of b.dhcp.options)p+=Hb(p,r,q,a);m+=p}else if(b.dns){r=p;p=a.udp_payload_view;p.setUint16(0,b.dns.id);p.setUint16(2,b.dns.flags);p.setUint16(4,b.dns.questions.length);p.setUint16(6,b.dns.answers.length);let z=12;for(var v=0;v<b.dns.questions.length;++v){var t=b.dns.questions[v];for(q of t.name){const A=
|
|
183
|
-
p.setUint16(z,t.class);z+=2}for(v=0;v<b.dns.answers.length;++v){q=b.dns.answers[v];for(m of q.name)t=a.text_encoder.encodeInto(m,a.eth_frame.subarray(p.byteOffset+(z+1))).written,p.setUint8(z,t),z+=1+t;p.setUint16(z,q.type);z+=2;p.setUint16(z,q.class);z+=2;p.setUint32(z,q.ttl);z+=4;p.setUint16(z,q.data.length);z+=2;z+=Hb(z,q.data,p,a)}m=r+z}else b.ntp?(m=p,q=a.udp_payload_view,
|
|
184
|
-
b.ntp.root_delay),q.setUint32(8,b.ntp.root_disp),q.setUint32(12,b.ntp.ref_id),q.setUint32(16,b.ntp.ref_ts_i),q.setUint32(20,b.ntp.ref_ts_f),q.setUint32(24,b.ntp.ori_ts_i),q.setUint32(28,b.ntp.ori_ts_f),q.setUint32(32,b.ntp.rec_ts_i),q.setUint32(36,b.ntp.rec_ts_f),q.setUint32(40,b.ntp.trans_ts_i),q.setUint32(44,b.ntp.trans_ts_f),m+=48):m=p+Hb(0,b.udp.data,a.udp_payload_view,a);
|
|
185
|
-
8|b.ipv4.src[1])+(b.ipv4.src[2]<<8|b.ipv4.src[3])+(b.ipv4.dest[0]<<8|b.ipv4.dest[1])+(b.ipv4.dest[2]<<8|b.ipv4.dest[3])+17+p,k,a));g+=p}else b.tcp&&(k=a.ipv4_payload_view,m=0,q=b.tcp,q.fin&&(m|=1),q.syn&&(m|=2),q.rst&&(m|=4),q.psh&&(m|=8),q.ack&&(m|=16),q.urg&&(m|=32),q.ece&&(m|=64),q.cwr&&(m|=128),r=20,q.options&&q.options.mss&&(k.setUint8(r,2),k.setUint8(r+1,4),k.setUint16(r+
|
|
186
|
-
q.sport),k.setUint16(2,q.dport),k.setUint32(4,q.seq),k.setUint32(8,q.ackn),k.setUint8(12,p>>2<<4),k.setUint8(13,m),k.setUint16(14,q.winsize),k.setUint16(16,0),k.setUint16(18,q.urgent||0),b.tcp_data&&(p+=Hb(20,b.tcp_data,k,a)),k.setUint16(16,Ib(p,(b.ipv4.src[0]<<8|b.ipv4.src[1])+(b.ipv4.src[2]<<8|b.ipv4.src[3])+(b.ipv4.dest[0]<<8|b.ipv4.dest[1])+(b.ipv4.dest[2]<<8|b.ipv4.dest[3])+
|
|
187
|
-
64);f.setUint8(8,b.ipv4.ttl||32);f.setUint8(9,b.ipv4.proto);f.setUint16(10,0);Hb(12,b.ipv4.src,f,a);Hb(16,b.ipv4.dest,f,a);f.setUint16(10,Ib(20,0,f,a));e+=g}return d.call(c,0,e)}function Tb(a,b){fetch(`https://${b.doh_server||"cloudflare-dns.com"}/dns-query`,{method:"POST",headers:[["content-type","application/dns-message"]],body:a.udp.data}).then(async c=>{c={eth:{ethertype:2048,
|
|
188
|
-
b.receive(Jb(b.eth_encoder_buf,c))});return!0}function Ub(a,b){let c={};c.eth={ethertype:2048,src:b.router_mac,dest:a.eth.src};c.ipv4={proto:17,src:b.router_ip,dest:b.vm_ip};c.udp={sport:67,dport:68};c.dhcp={htype:1,hlen:6,hops:0,xid:a.dhcp.xid,secs:0,flags:0,ciaddr:0,yiaddr:Eb(b.vm_ip),siaddr:Eb(b.router_ip),giaddr:Eb(b.router_ip),chaddr:a.dhcp.chaddr};
|
|
189
|
-
2])));3===a.dhcp.op&&(c.dhcp.op=2,d.push(new Uint8Array([53,1,5])),d.push(new Uint8Array([51,4,8,0,0,0])));a=[b.router_ip[0],b.router_ip[1],b.router_ip[2],b.router_ip[3]];d.push(new Uint8Array([1,4,255,255,255,0]));b.masquerade&&(d.push(new Uint8Array([3,4].concat(a))),d.push(new Uint8Array([6,4].concat(a))));d.push(new Uint8Array([54,4].concat(a)));d.push(new Uint8Array([60,
|
|
190
|
-
{};var d=(new DataView(a.buffer,a.byteOffset,a.byteLength)).getUint16(12),e={ethertype:d,dest:a.subarray(0,6),dest_s:Db(a.subarray(0,6)),src:a.subarray(6,12),src_s:Db(a.subarray(6,12))};c.eth=e;a=a.subarray(14,a.length);if(2048===d){var f=new DataView(a.buffer,a.byteOffset,a.byteLength),g=a[0]>>4&15;e=a[0]&15;var k=f.getUint8(1),m=f.getUint16(2);let p=f.getUint8(8);d=f.getUint8(9);
|
|
191
|
-
20)};Math.max(m,46)!==a.length&&B(`ipv4 Length mismatch: ${m} != ${a.length}`,16777216);c.ipv4=g;e=a.subarray(4*e,m);if(1===d)a=new DataView(e.buffer,e.byteOffset,e.byteLength),a={type:a.getUint8(0),code:a.getUint8(1),checksum:a.getUint16(2),data:e.subarray(4)},c.icmp=a;else if(6===d)d=new DataView(e.buffer,e.byteOffset,e.byteLength),a={sport:d.getUint16(0),dport:d.getUint16(2),seq:d.getUint32(4),
|
|
192
|
-
d=d.getUint8(13),a.fin=!!(d&1),a.syn=!!(d&2),a.rst=!!(d&4),a.psh=!!(d&8),a.ack=!!(d&16),a.urg=!!(d&32),a.ece=!!(d&64),a.cwr=!!(d&128),c.tcp=a,c.tcp_data=e.subarray(4*a.doff);else if(17===d){a=new DataView(e.buffer,e.byteOffset,e.byteLength);a={sport:a.getUint16(0),dport:a.getUint16(2),len:a.getUint16(4),checksum:a.getUint16(6),data:e.subarray(8),data_s:(new TextDecoder).decode(e.subarray(8))};
|
|
193
|
-
236);d={op:d.getUint8(0),htype:d.getUint8(1),hlen:d.getUint8(2),hops:d.getUint8(3),xid:d.getUint32(4),secs:d.getUint16(8),flags:d.getUint16(10),ciaddr:d.getUint32(12),yiaddr:d.getUint32(16),siaddr:d.getUint32(20),giaddr:d.getUint32(24),chaddr:e.subarray(28,44),magic:d.getUint32(236),options:[]};e=e.subarray(240);for(m=0;m<e.length;++m)g=m,0!==e[m]&&(++m,k=e[m],m+=k,d.options.push(e.subarray(g,
|
|
194
|
-
(d=e.subarray(8),d=new DataView(d.buffer,d.byteOffset,d.byteLength),c.ntp={flags:d.getUint8(0),stratum:d.getUint8(1),poll:d.getUint8(2),precision:d.getUint8(3),root_delay:d.getUint32(4),root_disp:d.getUint32(8),ref_id:d.getUint32(12),ref_ts_i:d.getUint32(16),ref_ts_f:d.getUint32(20),ori_ts_i:d.getUint32(24),ori_ts_f:d.getUint32(28),rec_ts_i:d.getUint32(32),rec_ts_f:d.getUint32(36),trans_ts_i:d.getUint32(40),
|
|
195
|
-
a.byteLength),a={htype:d.getUint16(0),ptype:d.getUint16(2),oper:d.getUint16(6),sha:a.subarray(8,14),spa:a.subarray(14,18),tha:a.subarray(18,24),tpa:a.subarray(24,28)},c.arp=a):34525===d?B("Unimplemented: ipv6"):B("Unknown ethertype: "+n(d),16777216);if(c.ipv4)if(c.tcp)a:{a=`${c.ipv4.src.join(".")}:${c.tcp.sport}:${c.ipv4.dest.join(".")}:${c.tcp.dport}`;if(c.tcp.syn&&(b.tcp_conn[a]&&B("SYN to already opened port",
|
|
196
|
-
else{B(`I dont know about ${a}, so resetting`,16777216);a=c.tcp.ackn;if(c.tcp.fin||c.tcp.syn)a+=1;d={};d.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src};d.ipv4={proto:6,src:c.ipv4.dest,dest:c.ipv4.src};d.tcp={sport:c.tcp.dport,dport:c.tcp.sport,seq:a,ackn:c.tcp.seq+(c.tcp.syn?1:0),winsize:c.tcp.winsize,rst:!0,ack:c.tcp.syn};b.receive(Jb(b.eth_encoder_buf,d))}}else if(c.udp)if(c.dns)if("static"===b.dns_method){a=
|
|
197
|
-
dest:c.ipv4.src};a.udp={sport:53,dport:c.udp.sport};d=[];for(e=0;e<c.dns.questions.length;++e)switch(m=c.dns.questions[e],m.type){case 1:d.push({name:m.name,type:m.type,class:m.class,ttl:600,data:[192,168,87,1]})}a.dns={id:c.dns.id,flags:33152,questions:c.dns.questions,answers:d};b.receive(Jb(b.eth_encoder_buf,a))}else Tb(c,b);else c.dhcp?Ub(c,b):c.ntp?(a=Date.now()+Ab,d=a%1E3/1E3*Bb,e={},e.eth={ethertype:2048,
|
|
198
|
-
{sport:123,dport:c.udp.sport},e.ntp=Object.assign({},c.ntp),e.ntp.flags=36,e.ntp.poll=10,e.ntp.ori_ts_i=c.ntp.trans_ts_i,e.ntp.ori_ts_f=c.ntp.trans_ts_f,e.ntp.rec_ts_i=a/1E3,e.ntp.rec_ts_f=d,e.ntp.trans_ts_i=a/1E3,e.ntp.trans_ts_f=d,e.ntp.stratum=2,b.receive(Jb(b.eth_encoder_buf,e))):8===c.udp.dport&&(a={},a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},a.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},
|
|
199
|
-
b.receive(Jb(b.eth_encoder_buf,a)));else c.icmp&&8===c.icmp.type&&(a={},a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},a.ipv4={proto:1,src:c.ipv4.dest,dest:c.ipv4.src},a.icmp={type:0,code:c.icmp.code,data:c.icmp.data},b.receive(Jb(b.eth_encoder_buf,a)));else c.arp&&1===c.arp.oper&&2048===c.arp.ptype&&(a=Eb(c.arp.tpa)&4294967040,d=Eb(b.router_ip)&4294967040,!b.masquerade&&a!==d||a===d&&99<c.arp.tpa[3]||
|
|
200
|
-
sha:b.router_mac,spa:c.arp.tpa,tha:c.eth.src,tpa:c.arp.spa},b.receive(Jb(b.eth_encoder_buf,a))))}function Wb(a,b){function c(){let p=[],q;do q=d.getUint8(k),p.push((new TextDecoder).decode(a.subarray(k+1,k+1+q))),k+=q+1;while(0<q);return p}let d=new DataView(a.buffer,a.byteOffset,a.byteLength),e={id:d.getUint16(0),flags:d.getUint16(2),questions:[],answers:[]};var f=d.getUint16(4);let g=d.getUint16(6);d.getUint16(8);
|
|
201
|
-
class:d.getInt16(k+2)}),k+=4;for(f=0;f<g;f++){m={name:c(),type:d.getInt16(k),class:d.getUint16(k+2),ttl:d.getUint32(k+4)};k+=8;let p=d.getUint16(k);k+=2;m.data=a.subarray(k,k+p);k+=p;e.answers.push(m)}b.dns=e}function Xb(a,b){var c=b.vm_ip.join(".");const d=b.router_ip.join("."),e=16383*Math.random()|0;let f,g,k=0;do f=49152+(e+k)%16383,g=`${c}:${a}:${d}:${f}`;while(16383>++k&&b.tcp_conn[g]);if(b.tcp_conn[g])throw Error("pool of dynamic TCP port numbers exhausted, connection aborted");
|
|
202
|
-
c.tuple=g;c.hsrc=b.router_mac;c.psrc=b.router_ip;c.sport=f;c.hdest=b.vm_mac;c.dport=a;c.pdest=b.vm_ip;b.tcp_conn[g]=c;c.connect();return c}function Zb(a,b){return new Promise(c=>{let d=Xb(a,b);d.state="syn-probe";d.on("probe",c)})}function Yb(a){this.mtu=a.mtu||1500;const b=this.mtu-20-20;this.state="closed";this.net=a;this.send_buffer=new Fb(2048,0);this.send_chunk_buf=new Uint8Array(b);this.delayed_send_fin=this.in_active_close=!1;this.delayed_state=void 0;this.events_handlers={}}Yb.prototype.on=
|
|
119
|
+
if(-2039052682!==t[0])throw new eb("Invalid header: "+n(t[0]>>>0));if(6!==t[1])throw new eb("Version mismatch: dump="+t[1]+" we=6");if(z&&t[2]!==A)throw new eb("Length doesn't match header: real="+A+" header="+t[2]);return t[3]}function d(t){t=(new TextDecoder).decode(t);return JSON.parse(t)}b=new Uint8Array(b);if(4247762216===(new Uint32Array(b.buffer,0,1))[0]){var e=a.zstd_create_ctx(b.length);(new Uint8Array(a.wasm_memory.buffer,a.zstd_get_src_ptr(e)>>>0,b.length)).set(b);var f=a.zstd_read(e,16),
|
|
120
|
+
g=new Uint8Array(a.wasm_memory.buffer,f>>>0,16),k=c(g,!1);a.zstd_read_free(f,16);f=a.zstd_read(e,k);g=new Uint8Array(a.wasm_memory.buffer,f>>>0,k);g=d(g);a.zstd_read_free(f,k);f=g.state;var m=g.buffer_infos;g=[];k=16+k;for(var p of m){m=(k+3&-4)-k;if(1048576<p.length){var q=a.zstd_read(e,m)>>>0;a.zstd_read_free(q,m);q=new Uint8Array(p.length);g.push(q.buffer);for(var r=0;r<p.length;){var v=p.length-r;l(0<=v);v=Math.min(v,1048576);const t=a.zstd_read(e,v);q.set(new Uint8Array(a.wasm_memory.buffer,
|
|
121
|
+
t>>>0,v),r);a.zstd_read_free(t,v);r+=v}}else q=a.zstd_read(e,m+p.length),r=(q>>>0)+m,g.push(a.wasm_memory.buffer.slice(r,r+p.length)),a.zstd_read_free(q,m+p.length);k+=m+p.length}f=hb(f,g);a.set_state(f);a.zstd_free_ctx(e)}else{e=c(b,!0);if(0>e||e+12>=b.length)throw new eb("Invalid info block length: "+e);p=b.subarray(16,16+e);f=d(p);p=f.state;f=f.buffer_infos;let t=16+e;t=t+3&-4;e=f.map(z=>{const A=t+z.offset;return b.buffer.slice(A,A+z.length)});p=hb(p,e);a.set_state(p)}}function jb(a,b,c,d,e){let f=
|
|
122
|
+
"";var g=[],k=b?"compiled":c?"jit exit":d?"unguarded register":e?"wasm size":"executed";for(let q=0;256>q;q++)for(let r=0;8>r;r++)for(const v of[!1,!0]){var m=a.wm.exports.get_opstats_buffer(b,c,d,e,q,!1,v,r);g.push({opcode:q,count:m,is_mem:v,fixed_g:r});m=a.wm.exports.get_opstats_buffer(b,c,d,e,q,!0,v,r);g.push({opcode:3840|q,count:m,is_mem:v,fixed_g:r})}a=0;b=new Set([38,46,54,62,100,101,102,103,240,242,243]);for(const {count:q,opcode:r}of g)b.has(r)||(a+=q);if(0===a)return"";c=new Uint32Array(256);
|
|
123
|
+
b=new Uint32Array(256);for(const {opcode:q,count:r}of g)3840===(q&65280)?b[q&255]+=r:c[q&255]+=r;f=f+"------------------\nTotal: "+(a+"\n");const p=1E7<a?1E3:1;d=Math.max.apply(Math,g.map(({count:q})=>Math.round(q/p)));d=String(d).length;f+=`Instruction counts ${k} (in ${p}):\n`;for(e=0;256>e;e++)f+=e.toString(16).padStart(2,"0")+":"+ca(Math.round(c[e]/p),d),f=15===e%16?f+"\n":f+" ";f=f+"\n"+`Instruction counts ${k} (0f, in ${p}):\n`;for(k=0;256>k;k++)f+=(k&255).toString(16).padStart(2,"0")+":"+ca(Math.round(b[k]/
|
|
124
|
+
p),d),f=15===k%16?f+"\n":f+" ";f+="\n";g=g.filter(({count:q})=>q).sort(({count:q},{count:r})=>r-q);for(const {opcode:q,is_mem:r,fixed_g:v,count:t}of g.slice(0,200))g=q.toString(16)+"_"+v+(r?"_m":"_r"),f+=g+":"+(t/a*100).toFixed(2)+" ";return f+"\n"}function kb(a){this.cpu=a;this.cmos_index=0;this.cmos_data=new Uint8Array(128);this.last_update=this.rtc_time=Date.now();this.next_interrupt_alarm=this.next_interrupt=0;this.periodic_interrupt=!1;this.periodic_interrupt_time=.9765625;this.cmos_a=38;this.cmos_b=
|
|
125
|
+
2;this.nmi_disabled=this.cmos_diag_status=this.cmos_c=0;this.update_interrupt=!1;this.update_interrupt_time=0;a.io.register_write(112,this,function(b){this.cmos_index=b&127;this.nmi_disabled=b>>7});a.io.register_write(113,this,this.cmos_port_write);a.io.register_read(113,this,this.cmos_port_read)}kb.prototype.get_state=function(){var a=[];a[0]=this.cmos_index;a[1]=this.cmos_data;a[2]=this.rtc_time;a[3]=this.last_update;a[4]=this.next_interrupt;a[5]=this.next_interrupt_alarm;a[6]=this.periodic_interrupt;
|
|
126
|
+
a[7]=this.periodic_interrupt_time;a[8]=this.cmos_a;a[9]=this.cmos_b;a[10]=this.cmos_c;a[11]=this.nmi_disabled;a[12]=this.update_interrupt;a[13]=this.update_interrupt_time;a[14]=this.cmos_diag_status;return a};kb.prototype.set_state=function(a){this.cmos_index=a[0];this.cmos_data=a[1];this.rtc_time=a[2];this.last_update=a[3];this.next_interrupt=a[4];this.next_interrupt_alarm=a[5];this.periodic_interrupt=a[6];this.periodic_interrupt_time=a[7];this.cmos_a=a[8];this.cmos_b=a[9];this.cmos_c=a[10];this.nmi_disabled=
|
|
127
|
+
a[11];this.update_interrupt=a[12]||!1;this.update_interrupt_time=a[13]||0;this.cmos_diag_status=a[14]||0};kb.prototype.timer=function(a){a=Date.now();this.rtc_time+=a-this.last_update;this.last_update=a;this.periodic_interrupt&&this.next_interrupt<a?(this.cpu.device_raise_irq(8),this.cmos_c|=192,this.next_interrupt+=this.periodic_interrupt_time*Math.ceil((a-this.next_interrupt)/this.periodic_interrupt_time)):this.next_interrupt_alarm&&this.next_interrupt_alarm<a?(this.cpu.device_raise_irq(8),this.cmos_c|=
|
|
128
|
+
160,this.next_interrupt_alarm=0):this.update_interrupt&&this.update_interrupt_time<a&&(this.cpu.device_raise_irq(8),this.cmos_c|=144,this.update_interrupt_time=a+1E3);let b=100;this.periodic_interrupt&&this.next_interrupt&&(b=Math.min(b,Math.max(0,this.next_interrupt-a)));this.next_interrupt_alarm&&(b=Math.min(b,Math.max(0,this.next_interrupt_alarm-a)));this.update_interrupt&&(b=Math.min(b,Math.max(0,this.update_interrupt_time-a)));return b};kb.prototype.bcd_pack=function(a){for(var b=0,c=0,d;a;)d=
|
|
129
|
+
a%10,c|=d<<4*b,b++,a=(a-d)/10;return c};kb.prototype.bcd_unpack=function(a){const b=a&15,c=a>>4&15;l(256>a);l(10>b);l(10>c);return b+10*c};kb.prototype.encode_time=function(a){return this.cmos_b&4?a:this.bcd_pack(a)};kb.prototype.decode_time=function(a){return this.cmos_b&4?a:this.bcd_unpack(a)};kb.prototype.cmos_port_read=function(){var a=this.cmos_index;switch(a){case 0:return B("read second: "+n(this.encode_time((new Date(this.rtc_time)).getUTCSeconds())),65536),this.encode_time((new Date(this.rtc_time)).getUTCSeconds());
|
|
130
|
+
case 2:return B("read minute: "+n(this.encode_time((new Date(this.rtc_time)).getUTCMinutes())),65536),this.encode_time((new Date(this.rtc_time)).getUTCMinutes());case 4:return B("read hour: "+n(this.encode_time((new Date(this.rtc_time)).getUTCHours())),65536),this.encode_time((new Date(this.rtc_time)).getUTCHours());case 6:return B("read day: "+n(this.encode_time((new Date(this.rtc_time)).getUTCDay()+1)),65536),this.encode_time((new Date(this.rtc_time)).getUTCDay()+1);case 7:return B("read day of month: "+
|
|
131
|
+
n(this.encode_time((new Date(this.rtc_time)).getUTCDate())),65536),this.encode_time((new Date(this.rtc_time)).getUTCDate());case 8:return B("read month: "+n(this.encode_time((new Date(this.rtc_time)).getUTCMonth()+1)),65536),this.encode_time((new Date(this.rtc_time)).getUTCMonth()+1);case 9:return B("read year: "+n(this.encode_time((new Date(this.rtc_time)).getUTCFullYear()%100)),65536),this.encode_time((new Date(this.rtc_time)).getUTCFullYear()%100);case 10:return 999<=H.microtick()%1E3?this.cmos_a|
|
|
132
|
+
128:this.cmos_a;case 11:return this.cmos_b;case 12:return this.cpu.device_lower_irq(8),B("cmos reg C read",65536),a=this.cmos_c,this.cmos_c&=-241,a;case 13:return 128;case 14:return B("cmos diagnostic status read",65536),this.cmos_diag_status;case 50:case 55:return B("read century: "+n(this.encode_time((new Date(this.rtc_time)).getUTCFullYear()/100|0)),65536),this.encode_time((new Date(this.rtc_time)).getUTCFullYear()/100|0);default:return B("cmos read from index "+n(a),65536),this.cmos_data[this.cmos_index]}};
|
|
133
|
+
kb.prototype.cmos_port_write=function(a){switch(this.cmos_index){case 10:this.cmos_a=a&127;this.periodic_interrupt_time=1E3/(32768>>(this.cmos_a&15)-1);B("Periodic interrupt, a="+n(this.cmos_a,2)+" t="+this.periodic_interrupt_time,65536);break;case 11:this.cmos_b=a;this.cmos_b&128&&(this.cmos_b&=239);this.cmos_b&64&&(this.next_interrupt=Date.now());if(this.cmos_b&32){a=new Date;const b=this.decode_time(this.cmos_data[1]),c=this.decode_time(this.cmos_data[3]),d=this.decode_time(this.cmos_data[5]),
|
|
134
|
+
e=new Date(Date.UTC(a.getUTCFullYear(),a.getUTCMonth(),a.getUTCDate(),d,c,b));B("RTC alarm scheduled for "+e+" hh:mm:ss="+d+":"+c+":"+b+" ms_from_now="+(e-a),65536);this.next_interrupt_alarm=+e}this.cmos_b&16&&(B("update interrupt",65536),this.update_interrupt_time=Date.now());B("cmos b="+n(this.cmos_b,2),65536);break;case 14:this.cmos_diag_status=a;break;case 1:case 3:case 5:this.cmos_write(this.cmos_index,a);break;default:B("cmos write index "+n(this.cmos_index)+": "+n(a),65536)}this.update_interrupt=
|
|
135
|
+
16===(this.cmos_b&16)&&0<(this.cmos_a&15);this.periodic_interrupt=64===(this.cmos_b&64)&&0<(this.cmos_a&15)};kb.prototype.cmos_read=function(a){l(128>a);return this.cmos_data[a]};kb.prototype.cmos_write=function(a,b){B("cmos "+n(a)+" <- "+n(b),65536);l(128>a);this.cmos_data[a]=b};function lb(a,b){this.cpu=a;this.bus=b;this.counter_start_time=new Float64Array(3);this.counter_start_value=new Uint16Array(3);this.counter_next_low=new Uint8Array(4);this.counter_enabled=new Uint8Array(4);this.counter_mode=
|
|
136
|
+
new Uint8Array(4);this.counter_read_mode=new Uint8Array(4);this.counter_latch=new Uint8Array(4);this.counter_latch_value=new Uint16Array(3);this.counter_reload=new Uint16Array(3);a.io.register_read(97,this,function(){var c=H.microtick(),d=66.66666666666667*c&1;c=this.did_rollover(2,c);return d<<4|c<<5});a.io.register_write(97,this,function(c){c&1?this.bus.send("pcspeaker-enable"):this.bus.send("pcspeaker-disable")});a.io.register_read(64,this,function(){return this.counter_read(0)});a.io.register_read(65,
|
|
137
|
+
this,function(){return this.counter_read(1)});a.io.register_read(66,this,function(){return this.counter_read(2)});a.io.register_write(64,this,function(c){this.counter_write(0,c)});a.io.register_write(65,this,function(c){this.counter_write(1,c)});a.io.register_write(66,this,function(c){this.counter_write(2,c);this.bus.send("pcspeaker-update",[this.counter_mode[2],this.counter_reload[2]])});a.io.register_write(67,this,this.port43_write)}lb.prototype.get_state=function(){var a=[];a[0]=this.counter_next_low;
|
|
138
|
+
a[1]=this.counter_enabled;a[2]=this.counter_mode;a[3]=this.counter_read_mode;a[4]=this.counter_latch;a[5]=this.counter_latch_value;a[6]=this.counter_reload;a[7]=this.counter_start_time;a[8]=this.counter_start_value;return a};lb.prototype.set_state=function(a){this.counter_next_low=a[0];this.counter_enabled=a[1];this.counter_mode=a[2];this.counter_read_mode=a[3];this.counter_latch=a[4];this.counter_latch_value=a[5];this.counter_reload=a[6];this.counter_start_time=a[7];this.counter_start_value=a[8]};
|
|
139
|
+
lb.prototype.timer=function(a,b){var c=100;b||(this.counter_enabled[0]&&this.did_rollover(0,a)?(this.counter_start_value[0]=this.get_counter_value(0,a),this.counter_start_time[0]=a,B("pit interrupt. new value: "+this.counter_start_value[0],512),this.cpu.device_lower_irq(0),this.cpu.device_raise_irq(0),0===this.counter_mode[0]&&(this.counter_enabled[0]=0)):this.cpu.device_lower_irq(0),this.counter_enabled[0]&&(c=(this.counter_start_value[0]-Math.floor(1193.1816666*(a-this.counter_start_time[0])))/
|
|
140
|
+
1193.1816666));return c};lb.prototype.get_counter_value=function(a,b){if(!this.counter_enabled[a])return 0;var c=b-this.counter_start_time[a],d=Math.floor(1193.1816666*c);b=this.counter_start_value[a]-d;B("diff="+c+" dticks="+d+" value="+b+" reload="+this.counter_reload[a],512);c=this.counter_reload[a];b>=c?(B("Warning: Counter"+a+" value "+b+" is larger than reload "+c,512),b%=c):0>b&&(b=b%c+c);return b};lb.prototype.did_rollover=function(a,b){b-=this.counter_start_time[a];return 0>b?(B("Warning: PIT timer difference is negative, resetting (timer "+
|
|
141
|
+
a+")"),!0):this.counter_start_value[a]<Math.floor(1193.1816666*b)};lb.prototype.counter_read=function(a){var b=this.counter_latch[a];if(b)return this.counter_latch[a]--,2===b?this.counter_latch_value[a]&255:this.counter_latch_value[a]>>8;b=this.counter_next_low[a];3===this.counter_mode[a]&&(this.counter_next_low[a]^=1);a=this.get_counter_value(a,H.microtick());return b?a&255:a>>8};lb.prototype.counter_write=function(a,b){this.counter_reload[a]=this.counter_next_low[a]?this.counter_reload[a]&-256|
|
|
142
|
+
b:this.counter_reload[a]&255|b<<8;3===this.counter_read_mode[a]&&this.counter_next_low[a]||(this.counter_reload[a]||(this.counter_reload[a]=65535),this.counter_start_value[a]=this.counter_reload[a],this.counter_enabled[a]=!0,this.counter_start_time[a]=H.microtick(),B("counter"+a+" reload="+n(this.counter_reload[a])+" tick="+(this.counter_reload[a]||65536)/1193.1816666+"ms",512));3===this.counter_read_mode[a]&&(this.counter_next_low[a]^=1)};lb.prototype.port43_write=function(a){var b=a>>1&7,c=a&1,
|
|
143
|
+
d=a>>6&3;a=a>>4&3;1===d&&B("Unimplemented timer1",512);3===d?B("Unimplemented read back",512):0===a?(this.counter_latch[d]=2,b=this.get_counter_value(d,H.microtick()),B("latch: "+b,512),this.counter_latch_value[d]=b?b-1:0):(6<=b&&(b&=-5),B("Control: mode="+b+" ctr="+d+" read_mode="+a+" bcd="+c,512),this.counter_next_low[d]=1===a?1:2===a?0:1,0===d&&this.cpu.device_lower_irq(0),0!==b&&3!==b&&2!==b&&B("Unimplemented counter mode: "+n(b),512),this.counter_mode[d]=b,this.counter_read_mode[d]=a,2===d&&
|
|
144
|
+
this.bus.send("pcspeaker-update",[this.counter_mode[2],this.counter_reload[2]]))};lb.prototype.dump=function(){const a=this.counter_reload[0];B("counter0 ticks every "+(a||65536)/1193.1816666+"ms (reload="+a+")")};function mb(a){if("undefined"!==typeof window)if(window.AudioContext||window.webkitAudioContext){var b=window.AudioWorklet?nb:ob;this.bus=a;this.audio_context=window.AudioContext?new AudioContext:new webkitAudioContext;this.mixer=new pb(a,this.audio_context);this.pcspeaker=new qb(a,this.audio_context,
|
|
145
|
+
this.mixer);this.dac=new b(a,this.audio_context,this.mixer);this.pcspeaker.start();a.register("emulator-stopped",function(){this.audio_context.suspend()},this);a.register("emulator-started",function(){this.audio_context.resume()},this);a.register("speaker-confirm-initialized",function(){a.send("speaker-has-initialized")},this);a.send("speaker-has-initialized")}else console.warn("Web browser doesn't support Web Audio API")}mb.prototype.destroy=function(){this.audio_context&&this.audio_context.close();
|
|
146
|
+
this.audio_context=null;this.dac&&this.dac.node_processor&&this.dac.node_processor.port.close();this.dac=null};function pb(a,b){function c(d){return function(e){d.gain.setValueAtTime(e,this.audio_context.currentTime)}}this.audio_context=b;this.sources=new Map;this.gain_right=this.gain_left=this.volume_right=this.volume_left=this.volume_both=1;this.node_treble_left=this.audio_context.createBiquadFilter();this.node_treble_right=this.audio_context.createBiquadFilter();this.node_treble_left.type="highshelf";
|
|
147
|
+
this.node_treble_right.type="highshelf";this.node_treble_left.frequency.setValueAtTime(2E3,this.audio_context.currentTime);this.node_treble_right.frequency.setValueAtTime(2E3,this.audio_context.currentTime);this.node_bass_left=this.audio_context.createBiquadFilter();this.node_bass_right=this.audio_context.createBiquadFilter();this.node_bass_left.type="lowshelf";this.node_bass_right.type="lowshelf";this.node_bass_left.frequency.setValueAtTime(200,this.audio_context.currentTime);this.node_bass_right.frequency.setValueAtTime(200,
|
|
148
|
+
this.audio_context.currentTime);this.node_gain_left=this.audio_context.createGain();this.node_gain_right=this.audio_context.createGain();this.node_merger=this.audio_context.createChannelMerger(2);this.input_left=this.node_treble_left;this.input_right=this.node_treble_right;this.node_treble_left.connect(this.node_bass_left);this.node_bass_left.connect(this.node_gain_left);this.node_gain_left.connect(this.node_merger,0,0);this.node_treble_right.connect(this.node_bass_right);this.node_bass_right.connect(this.node_gain_right);
|
|
149
|
+
this.node_gain_right.connect(this.node_merger,0,1);this.node_merger.connect(this.audio_context.destination);a.register("mixer-connect",function(d){this.connect_source(d[0],d[1])},this);a.register("mixer-disconnect",function(d){this.disconnect_source(d[0],d[1])},this);a.register("mixer-volume",function(d){var e=d[0],f=d[1];d=Math.pow(10,d[2]/20);var g=0===e?this:this.sources.get(e);void 0===g?l(!1,"Mixer set volume - cannot set volume for undefined source: "+e):g.set_volume(d,f)},this);a.register("mixer-gain-left",
|
|
150
|
+
function(d){this.gain_left=Math.pow(10,d/20);this.update()},this);a.register("mixer-gain-right",function(d){this.gain_right=Math.pow(10,d/20);this.update()},this);a.register("mixer-treble-left",c(this.node_treble_left),this);a.register("mixer-treble-right",c(this.node_treble_right),this);a.register("mixer-bass-left",c(this.node_bass_left),this);a.register("mixer-bass-right",c(this.node_bass_right),this)}pb.prototype.add_source=function(a,b){a=new rb(this.audio_context,a,this.input_left,this.input_right);
|
|
151
|
+
l(!this.sources.has(b),"Mixer add source - overwritting source: "+b);this.sources.set(b,a);return a};pb.prototype.connect_source=function(a,b){var c=this.sources.get(a);void 0===c?l(!1,"Mixer connect - cannot connect undefined source: "+a):c.connect(b)};pb.prototype.disconnect_source=function(a,b){var c=this.sources.get(a);void 0===c?l(!1,"Mixer disconnect - cannot disconnect undefined source: "+a):c.disconnect(b)};pb.prototype.set_volume=function(a,b){void 0===b&&(b=2);switch(b){case 0:this.volume_left=
|
|
152
|
+
a;break;case 1:this.volume_right=a;break;case 2:this.volume_both=a;break;default:l(!1,"Mixer set master volume - unknown channel: "+b);return}this.update()};pb.prototype.update=function(){var a=this.volume_both*this.volume_right*this.gain_right;this.node_gain_left.gain.setValueAtTime(this.volume_both*this.volume_left*this.gain_left,this.audio_context.currentTime);this.node_gain_right.gain.setValueAtTime(a,this.audio_context.currentTime)};function rb(a,b,c,d){this.audio_context=a;this.connected_right=
|
|
153
|
+
this.connected_left=!0;this.volume_right=this.volume_left=this.volume_both=this.gain_hidden=1;this.node_splitter=a.createChannelSplitter(2);this.node_gain_left=a.createGain();this.node_gain_right=a.createGain();b.connect(this.node_splitter);this.node_splitter.connect(this.node_gain_left,0);this.node_gain_left.connect(c);this.node_splitter.connect(this.node_gain_right,1);this.node_gain_right.connect(d)}rb.prototype.update=function(){var a=this.connected_right*this.gain_hidden*this.volume_both*this.volume_right;
|
|
154
|
+
this.node_gain_left.gain.setValueAtTime(this.connected_left*this.gain_hidden*this.volume_both*this.volume_left,this.audio_context.currentTime);this.node_gain_right.gain.setValueAtTime(a,this.audio_context.currentTime)};rb.prototype.connect=function(a){var b=!a||2===a;if(b||0===a)this.connected_left=!0;if(b||1===a)this.connected_right=!0;this.update()};rb.prototype.disconnect=function(a){var b=!a||2===a;if(b||0===a)this.connected_left=!1;if(b||1===a)this.connected_right=!1;this.update()};rb.prototype.set_volume=
|
|
155
|
+
function(a,b){void 0===b&&(b=2);switch(b){case 0:this.volume_left=a;break;case 1:this.volume_right=a;break;case 2:this.volume_both=a;break;default:l(!1,"Mixer set volume - unknown channel: "+b);return}this.update()};rb.prototype.set_gain_hidden=function(a){this.gain_hidden=a};function qb(a,b,c){this.node_oscillator=b.createOscillator();this.node_oscillator.type="square";this.node_oscillator.frequency.setValueAtTime(440,b.currentTime);this.mixer_connection=c.add_source(this.node_oscillator,1);this.mixer_connection.disconnect();
|
|
156
|
+
a.register("pcspeaker-enable",function(){c.connect_source(1)},this);a.register("pcspeaker-disable",function(){c.disconnect_source(1)},this);a.register("pcspeaker-update",function(d){var e=d[1],f=0;3===d[0]&&(f=Math.min(1193181.6665999999/e,this.node_oscillator.frequency.maxValue),f=Math.max(f,0));this.node_oscillator.frequency.setValueAtTime(f,b.currentTime)},this)}qb.prototype.start=function(){this.node_oscillator.start()};function nb(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=
|
|
157
|
+
48E3;b=function(){function g(p){if(0===p)return 1;p*=Math.PI;return Math.sin(p)/p}function k(){var p=Reflect.construct(AudioWorkletProcessor,[],k);p.kernel_size=3;p.queue_data=Array(1024);p.queue_start=0;p.queue_end=0;p.queue_length=0;p.queue_size=p.queue_data.length;p.queued_samples=0;p.source_buffer_previous=m;p.source_buffer_current=m;p.source_samples_per_destination=1;p.source_block_start=0;p.source_time=0;p.source_offset=0;p.port.onmessage=q=>{switch(q.data.type){case "queue":p.queue_push(q.data.value);
|
|
158
|
+
break;case "sampling-rate":p.source_samples_per_destination=q.data.value/sampleRate}};return p}var m=[new Float32Array(256),new Float32Array(256)];Reflect.setPrototypeOf(k.prototype,AudioWorkletProcessor.prototype);Reflect.setPrototypeOf(k,AudioWorkletProcessor);k.prototype.process=k.prototype.process=function(p,q){for(p=0;p<q[0][0].length;p++){for(var r=0,v=0,t=this.source_offset+this.kernel_size,z=this.source_offset-this.kernel_size+1;z<=t;z++){var A=this.source_block_start+z;r+=this.get_sample(A,
|
|
159
|
+
0)*this.kernel(this.source_time-z);v+=this.get_sample(A,1)*this.kernel(this.source_time-z)}if(isNaN(r)||isNaN(v))r=v=0,this.dbg_log("ERROR: NaN values! Ignoring for now.");q[0][0][p]=r;q[0][1][p]=v;this.source_time+=this.source_samples_per_destination;this.source_offset=Math.floor(this.source_time)}q=this.source_offset;q+=this.kernel_size+2;this.source_time-=this.source_offset;this.source_block_start+=this.source_offset;this.source_offset=0;this.ensure_enough_data(q);return!0};k.prototype.kernel=
|
|
160
|
+
function(p){return g(p)*g(p/this.kernel_size)};k.prototype.get_sample=function(p,q){return 0>p?(p+=this.source_buffer_previous[0].length,this.source_buffer_previous[q][p]):this.source_buffer_current[q][p]};k.prototype.ensure_enough_data=function(p){var q=this.source_buffer_current[0].length;q-this.source_block_start<p&&(this.prepare_next_buffer(),this.source_block_start-=q)};k.prototype.prepare_next_buffer=function(){256>this.queued_samples&&this.queue_length&&this.dbg_log("Not enough samples - should not happen during midway of playback");
|
|
161
|
+
this.source_buffer_previous=this.source_buffer_current;this.source_buffer_current=this.queue_shift();var p=this.source_buffer_current[0].length;if(256>p){for(var q=this.queue_start,r=0;256>p&&r<this.queue_length;)p+=this.queue_data[q][0].length,q=q+1&this.queue_size-1,r++;p=Math.max(p,256);p=[new Float32Array(p),new Float32Array(p)];p[0].set(this.source_buffer_current[0]);p[1].set(this.source_buffer_current[1]);q=this.source_buffer_current[0].length;for(var v=0;v<r;v++){var t=this.queue_shift();p[0].set(t[0],
|
|
162
|
+
q);p[1].set(t[1],q);q+=t[0].length}this.source_buffer_current=p}this.pump()};k.prototype.pump=function(){1024>this.queued_samples/this.source_samples_per_destination&&this.port.postMessage({type:"pump"})};k.prototype.queue_push=function(p){this.queue_length<this.queue_size&&(this.queue_data[this.queue_end]=p,this.queue_end=this.queue_end+1&this.queue_size-1,this.queue_length++,this.queued_samples+=p[0].length,this.pump())};k.prototype.queue_shift=function(){if(!this.queue_length)return m;var p=this.queue_data[this.queue_start];
|
|
163
|
+
this.queue_data[this.queue_start]=null;this.queue_start=this.queue_start+1&this.queue_size-1;this.queue_length--;this.queued_samples-=p[0].length;return p};k.prototype.dbg_log=function(p){this.port.postMessage({type:"debug-log",value:p})};registerProcessor("dac-processor",k)}.toString();var d=b.indexOf("{")+1,e=b.lastIndexOf("}");b=b.substring(d,e);b=new Blob(["var DEBUG = true;\n"+b],{type:"application/javascript"});var f=URL.createObjectURL(b);this.node_processor=null;this.node_output=this.audio_context.createGain();
|
|
164
|
+
this.audio_context.audioWorklet.addModule(f).then(()=>{URL.revokeObjectURL(f);this.node_processor=new AudioWorkletNode(this.audio_context,"dac-processor",{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[2],parameterData:{},processorOptions:{}});this.node_processor.port.postMessage({type:"sampling-rate",value:this.sampling_rate});this.node_processor.port.onmessage=g=>{switch(g.data.type){case "pump":this.pump();break;case "debug-log":B("SpeakerWorkletDAC - Worklet: "+g.data.value)}};this.node_processor.connect(this.node_output)});
|
|
165
|
+
this.mixer_connection=c.add_source(this.node_output,2);this.mixer_connection.set_gain_hidden(3);a.register("dac-send-data",function(g){this.queue(g)},this);a.register("dac-enable",function(){this.enabled=!0},this);a.register("dac-disable",function(){this.enabled=!1},this);a.register("dac-tell-sampling-rate",function(g){l(0<g,"Sampling rate should be nonzero");this.sampling_rate=g;this.node_processor&&this.node_processor.port.postMessage({type:"sampling-rate",value:g})},this);this.debugger=new wb(this.audio_context,
|
|
166
|
+
this.node_output)}nb.prototype.queue=function(a){this.node_processor&&(this.debugger.push_queued_data(a),this.node_processor.port.postMessage({type:"queue",value:a},[a[0].buffer,a[1].buffer]))};nb.prototype.pump=function(){this.enabled&&this.bus.send("dac-request-data")};function ob(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=22050;this.buffered_time=0;this.rate_ratio=1;this.node_lowpass=this.audio_context.createBiquadFilter();this.node_lowpass.type="lowpass";this.node_output=
|
|
167
|
+
this.node_lowpass;this.mixer_connection=c.add_source(this.node_output,2);this.mixer_connection.set_gain_hidden(3);a.register("dac-send-data",function(d){this.queue(d)},this);a.register("dac-enable",function(){this.enabled=!0;this.pump()},this);a.register("dac-disable",function(){this.enabled=!1},this);a.register("dac-tell-sampling-rate",function(d){l(0<d,"Sampling rate should be nonzero");this.sampling_rate=d;this.rate_ratio=Math.ceil(8E3/d);this.node_lowpass.frequency.setValueAtTime(d/2,this.audio_context.currentTime)},
|
|
168
|
+
this);this.debugger=new wb(this.audio_context,this.node_output)}ob.prototype.queue=function(a){this.debugger.push_queued_data(a);var b=a[0].length,c=b/this.sampling_rate;if(1<this.rate_ratio){var d=this.audio_context.createBuffer(2,b*this.rate_ratio,this.sampling_rate*this.rate_ratio);for(var e=d.getChannelData(0),f=d.getChannelData(1),g=0,k=0;k<b;k++)for(var m=0;m<this.rate_ratio;m++,g++)e[g]=a[0][k],f[g]=a[1][k]}else d=this.audio_context.createBuffer(2,b,this.sampling_rate),d.copyToChannel?(d.copyToChannel(a[0],
|
|
169
|
+
0),d.copyToChannel(a[1],1)):(d.getChannelData(0).set(a[0]),d.getChannelData(1).set(a[1]));a=this.audio_context.createBufferSource();a.buffer=d;a.connect(this.node_lowpass);a.addEventListener("ended",this.pump.bind(this));d=this.audio_context.currentTime;if(this.buffered_time<d)for(B("Speaker DAC - Creating/Recreating reserve - shouldn't occur frequently during playback"),this.buffered_time=d,d=.2-c,b=0;b<=d;)b+=c,this.buffered_time+=c,setTimeout(()=>this.pump(),1E3*b);a.start(this.buffered_time);
|
|
170
|
+
this.buffered_time+=c;setTimeout(()=>this.pump(),0)};ob.prototype.pump=function(){this.enabled&&(.2<this.buffered_time-this.audio_context.currentTime||this.bus.send("dac-request-data"))};function wb(a,b){this.audio_context=a;this.node_source=b;this.node_processor=null;this.node_gain=this.audio_context.createGain();this.node_gain.gain.setValueAtTime(0,this.audio_context.currentTime);this.node_gain.connect(this.audio_context.destination);this.is_active=!1;this.queued_history=[];this.output_history=
|
|
171
|
+
[];this.queued=[[],[]];this.output=[[],[]]}wb.prototype.start=function(a){this.is_active=!0;this.queued=[[],[]];this.output=[[],[]];this.queued_history.push(this.queued);this.output_history.push(this.output);this.node_processor=this.audio_context.createScriptProcessor(1024,2,2);this.node_processor.onaudioprocess=b=>{this.output[0].push(b.inputBuffer.getChannelData(0).slice());this.output[1].push(b.inputBuffer.getChannelData(1).slice())};this.node_source.connect(this.node_processor);this.node_processor.connect(this.node_gain);
|
|
172
|
+
setTimeout(()=>{this.stop()},a)};wb.prototype.stop=function(){this.is_active=!1;this.node_source.disconnect(this.node_processor);this.node_processor.disconnect();this.node_processor=null};wb.prototype.push_queued_data=function(a){this.is_active&&(this.queued[0].push(a[0].slice()),this.queued[1].push(a[1].slice()))};wb.prototype.download_txt=function(a,b){a=this.output_history[a][b].map(c=>c.join(" ")).join(" ");qa(a,"dacdata.txt")};wb.prototype.download_csv=function(a){a=this.output_history[a];for(var b=
|
|
173
|
+
[],c=0;c<a[0].length;c++)for(var d=0;d<a[0][c].length;d++)b.push(`${a[0][c][d]},${a[1][c][d]}`);qa(b.join("\n"),"dacdata.csv")};function xb(a,b,c){this.bus=b;this.socket=void 0;this.id=c||0;this.send_queue=[];this.url=a;this.reconnect_interval=1E4;this.last_connect_attempt=Date.now()-this.reconnect_interval;this.send_queue_limit=64;this.destroyed=!1;this.bus.register("net"+this.id+"-send",function(d){this.send(d)},this)}xb.prototype.handle_message=function(a){this.bus&&this.bus.send("net"+this.id+
|
|
174
|
+
"-receive",new Uint8Array(a.data))};xb.prototype.handle_close=function(){this.destroyed||(this.connect(),setTimeout(this.connect.bind(this),this.reconnect_interval))};xb.prototype.handle_open=function(){for(var a=0;a<this.send_queue.length;a++)this.send(this.send_queue[a]);this.send_queue=[]};xb.prototype.handle_error=function(){};xb.prototype.destroy=function(){this.destroyed=!0;this.socket&&this.socket.close()};xb.prototype.connect=function(){if("undefined"!==typeof WebSocket){if(this.socket){var a=
|
|
175
|
+
this.socket.readyState;if(0===a||1===a)return}a=Date.now();if(!(this.last_connect_attempt+this.reconnect_interval>a)){this.last_connect_attempt=Date.now();try{this.socket=new WebSocket(this.url)}catch(b){console.error(b);return}this.socket.binaryType="arraybuffer";this.socket.onopen=this.handle_open.bind(this);this.socket.onmessage=this.handle_message.bind(this);this.socket.onclose=this.handle_close.bind(this);this.socket.onerror=this.handle_error.bind(this)}}};xb.prototype.send=function(a){this.socket&&
|
|
176
|
+
1===this.socket.readyState?this.socket.send(a):(this.send_queue.push(a),this.send_queue.length>2*this.send_queue_limit&&(this.send_queue=this.send_queue.slice(-this.send_queue_limit)),this.connect())};xb.prototype.change_proxy=function(a){this.url=a;this.socket&&(this.socket.onclose=function(){},this.socket.onerror=function(){},this.socket.close(),this.socket=void 0)};const yb=(new Date("1970-01-01T00:00:00Z")).getTime(),zb=(new Date("1900-01-01T00:00:00Z")).getTime(),Ab=yb-zb,Bb=Math.pow(2,32),Cb=
|
|
177
|
+
[118,56,54];function Db(a){return[0,1,2,3,4,5].map(b=>a[b].toString(16)).map(b=>1===b.length?"0"+b:b).join(":")}function Eb(a){return a[0]<<24|a[1]<<16|a[2]<<8|a[3]}class Fb{constructor(a,b){a=Math.min(a,16);this.maximum_capacity=b?Math.max(b,a):0;this.length=this.head=this.tail=0;this.buffer=new Uint8Array(a)}write(a){const b=a.length;var c=this.length+b;let d=this.buffer.length;if(d<c){for(l(0<d);d<c;)d*=2;if(this.maximum_capacity&&d>this.maximum_capacity)throw Error("stream capacity overflow in GrowableRingbuffer.write(), package dropped");
|
|
178
|
+
c=new Uint8Array(d);this.peek(c);this.tail=0;this.head=this.length;this.buffer=c}c=this.buffer;const e=this.head+b;if(e>d){const f=d-this.head;c.set(a.subarray(0,f),this.head);c.set(a.subarray(f))}else c.set(a,this.head);this.head=e%d;this.length+=b}peek(a){const b=Math.min(this.length,a.length);if(b){const e=this.buffer;var c=e.length,d=this.tail+b;d>c?(d%=c,c-=this.tail,a.set(e.subarray(this.tail)),a.set(e.subarray(0,d),c)):a.set(e.subarray(this.tail,d))}return b}remove(a){a>this.length&&(a=this.length);
|
|
179
|
+
a&&(this.tail=(this.tail+a)%this.buffer.length,this.length-=a);return a}}function Gb(a=1500){const b=a-20,c=b-8,d=new Uint8Array(14+a+4),e=d.buffer,f=d.byteOffset;return{eth_frame:d,eth_frame_view:new DataView(e),eth_payload_view:new DataView(e,f+14,a),ipv4_payload_view:new DataView(e,f+34,b),udp_payload_view:new DataView(e,f+42,c),text_encoder:new TextEncoder}}function Hb(a,b,c,d){d.eth_frame.set(b,c.byteOffset+a);return b.length}function Ib(a,b,c,d){const e=c.byteOffset+(a&-2);d=d.eth_frame;for(c=
|
|
180
|
+
c.byteOffset;c<e;c+=2)b+=d[c]<<8|d[c+1];for(a&1&&(b+=d[e]<<8);b>>>16;)b=(b&65535)+(b>>>16);return~b&65535}function Jb(a,b){l(b.eth);a.eth_frame.fill(0);var c=a.eth_frame,d=c.subarray,e=a.eth_frame_view;Hb(0,b.eth.dest,e,a);Hb(6,b.eth.src,e,a);e.setUint16(12,b.eth.ethertype);e=14;if(b.arp){var f=a.eth_payload_view;f.setUint16(0,b.arp.htype);f.setUint16(2,b.arp.ptype);f.setUint8(4,b.arp.sha.length);f.setUint8(5,b.arp.spa.length);f.setUint16(6,b.arp.oper);Hb(8,b.arp.sha,f,a);Hb(14,b.arp.spa,f,a);Hb(18,
|
|
181
|
+
b.arp.tha,f,a);Hb(24,b.arp.tpa,f,a);e+=28}else if(b.ipv4){f=a.eth_payload_view;var g=20;if(b.icmp){var k=a.ipv4_payload_view;k.setUint8(0,b.icmp.type);k.setUint8(1,b.icmp.code);k.setUint16(2,0);var m=4+Hb(4,b.icmp.data,k,a);k.setUint16(2,Ib(m,0,k,a));g+=m}else if(b.udp){k=a.ipv4_payload_view;var p=8;if(b.dhcp){m=p;var q=a.udp_payload_view;q.setUint8(0,b.dhcp.op);q.setUint8(1,b.dhcp.htype);q.setUint8(2,b.dhcp.hlen);q.setUint8(3,b.dhcp.hops);q.setUint32(4,b.dhcp.xid);q.setUint16(8,b.dhcp.secs);q.setUint16(10,
|
|
182
|
+
b.dhcp.flags);q.setUint32(12,b.dhcp.ciaddr);q.setUint32(16,b.dhcp.yiaddr);q.setUint32(20,b.dhcp.siaddr);q.setUint32(24,b.dhcp.giaddr);Hb(28,b.dhcp.chaddr,q,a);q.setUint32(236,1669485411);p=240;for(var r of b.dhcp.options)p+=Hb(p,r,q,a);m+=p}else if(b.dns){r=p;p=a.udp_payload_view;p.setUint16(0,b.dns.id);p.setUint16(2,b.dns.flags);p.setUint16(4,b.dns.questions.length);p.setUint16(6,b.dns.answers.length);let z=12;for(var v=0;v<b.dns.questions.length;++v){var t=b.dns.questions[v];for(q of t.name){const A=
|
|
183
|
+
a.text_encoder.encodeInto(q,a.eth_frame.subarray(p.byteOffset+(z+1))).written;p.setUint8(z,A);z+=1+A}p.setUint16(z,t.type);z+=2;p.setUint16(z,t.class);z+=2}for(v=0;v<b.dns.answers.length;++v){q=b.dns.answers[v];for(m of q.name)t=a.text_encoder.encodeInto(m,a.eth_frame.subarray(p.byteOffset+(z+1))).written,p.setUint8(z,t),z+=1+t;p.setUint16(z,q.type);z+=2;p.setUint16(z,q.class);z+=2;p.setUint32(z,q.ttl);z+=4;p.setUint16(z,q.data.length);z+=2;z+=Hb(z,q.data,p,a)}m=r+z}else b.ntp?(m=p,q=a.udp_payload_view,
|
|
184
|
+
q.setUint8(0,b.ntp.flags),q.setUint8(1,b.ntp.stratum),q.setUint8(2,b.ntp.poll),q.setUint8(3,b.ntp.precision),q.setUint32(4,b.ntp.root_delay),q.setUint32(8,b.ntp.root_disp),q.setUint32(12,b.ntp.ref_id),q.setUint32(16,b.ntp.ref_ts_i),q.setUint32(20,b.ntp.ref_ts_f),q.setUint32(24,b.ntp.ori_ts_i),q.setUint32(28,b.ntp.ori_ts_f),q.setUint32(32,b.ntp.rec_ts_i),q.setUint32(36,b.ntp.rec_ts_f),q.setUint32(40,b.ntp.trans_ts_i),q.setUint32(44,b.ntp.trans_ts_f),m+=48):m=p+Hb(0,b.udp.data,a.udp_payload_view,a);
|
|
185
|
+
p=m;k.setUint16(0,b.udp.sport);k.setUint16(2,b.udp.dport);k.setUint16(4,p);k.setUint16(6,0);k.setUint16(6,Ib(p,(b.ipv4.src[0]<<8|b.ipv4.src[1])+(b.ipv4.src[2]<<8|b.ipv4.src[3])+(b.ipv4.dest[0]<<8|b.ipv4.dest[1])+(b.ipv4.dest[2]<<8|b.ipv4.dest[3])+17+p,k,a));g+=p}else b.tcp&&(k=a.ipv4_payload_view,m=0,q=b.tcp,q.fin&&(m|=1),q.syn&&(m|=2),q.rst&&(m|=4),q.psh&&(m|=8),q.ack&&(m|=16),q.urg&&(m|=32),q.ece&&(m|=64),q.cwr&&(m|=128),r=20,q.options&&q.options.mss&&(k.setUint8(r,2),k.setUint8(r+1,4),k.setUint16(r+
|
|
186
|
+
2,q.options.mss),r+=4),p=4*Math.ceil(r/4),q.options&&0<p-r&&a.eth_frame.fill(0,k.byteOffset+r,k.byteOffset+r+(p-r)),k.setUint16(0,q.sport),k.setUint16(2,q.dport),k.setUint32(4,q.seq),k.setUint32(8,q.ackn),k.setUint8(12,p>>2<<4),k.setUint8(13,m),k.setUint16(14,q.winsize),k.setUint16(16,0),k.setUint16(18,q.urgent||0),b.tcp_data&&(p+=Hb(20,b.tcp_data,k,a)),k.setUint16(16,Ib(p,(b.ipv4.src[0]<<8|b.ipv4.src[1])+(b.ipv4.src[2]<<8|b.ipv4.src[3])+(b.ipv4.dest[0]<<8|b.ipv4.dest[1])+(b.ipv4.dest[2]<<8|b.ipv4.dest[3])+
|
|
187
|
+
6+p,k,a)),g+=p);f.setUint8(0,69);f.setUint8(1,b.ipv4.tos||0);f.setUint16(2,g);f.setUint16(4,b.ipv4.id||0);f.setUint8(6,64);f.setUint8(8,b.ipv4.ttl||32);f.setUint8(9,b.ipv4.proto);f.setUint16(10,0);Hb(12,b.ipv4.src,f,a);Hb(16,b.ipv4.dest,f,a);f.setUint16(10,Ib(20,0,f,a));e+=g}return d.call(c,0,e)}function Tb(a,b){fetch(`https://${b.doh_server||"cloudflare-dns.com"}/dns-query`,{method:"POST",headers:[["content-type","application/dns-message"]],body:a.udp.data}).then(async c=>{c={eth:{ethertype:2048,
|
|
188
|
+
src:b.router_mac,dest:a.eth.src},ipv4:{proto:17,src:b.router_ip,dest:a.ipv4.src},udp:{sport:53,dport:a.udp.sport,data:new Uint8Array(await c.arrayBuffer())}};b.receive(Jb(b.eth_encoder_buf,c))});return!0}function Ub(a,b){let c={};c.eth={ethertype:2048,src:b.router_mac,dest:a.eth.src};c.ipv4={proto:17,src:b.router_ip,dest:b.vm_ip};c.udp={sport:67,dport:68};c.dhcp={htype:1,hlen:6,hops:0,xid:a.dhcp.xid,secs:0,flags:0,ciaddr:0,yiaddr:Eb(b.vm_ip),siaddr:Eb(b.router_ip),giaddr:Eb(b.router_ip),chaddr:a.dhcp.chaddr};
|
|
189
|
+
let d=[],e=a.dhcp.options.find(function(f){return 53===f[0]});e&&3===e[2]&&(a.dhcp.op=3);1===a.dhcp.op&&(c.dhcp.op=2,d.push(new Uint8Array([53,1,2])));3===a.dhcp.op&&(c.dhcp.op=2,d.push(new Uint8Array([53,1,5])),d.push(new Uint8Array([51,4,8,0,0,0])));a=[b.router_ip[0],b.router_ip[1],b.router_ip[2],b.router_ip[3]];d.push(new Uint8Array([1,4,255,255,255,0]));b.masquerade&&(d.push(new Uint8Array([3,4].concat(a))),d.push(new Uint8Array([6,4].concat(a))));d.push(new Uint8Array([54,4].concat(a)));d.push(new Uint8Array([60,
|
|
190
|
+
3].concat(Cb)));d.push(new Uint8Array([255,0]));c.dhcp.options=d;b.receive(Jb(b.eth_encoder_buf,c))}function Vb(a,b){let c={};var d=(new DataView(a.buffer,a.byteOffset,a.byteLength)).getUint16(12),e={ethertype:d,dest:a.subarray(0,6),dest_s:Db(a.subarray(0,6)),src:a.subarray(6,12),src_s:Db(a.subarray(6,12))};c.eth=e;a=a.subarray(14,a.length);if(2048===d){var f=new DataView(a.buffer,a.byteOffset,a.byteLength),g=a[0]>>4&15;e=a[0]&15;var k=f.getUint8(1),m=f.getUint16(2);let p=f.getUint8(8);d=f.getUint8(9);
|
|
191
|
+
f=f.getUint16(10);g={version:g,ihl:e,tos:k,len:m,ttl:p,proto:d,ip_checksum:f,src:a.subarray(12,16),dest:a.subarray(16,20)};Math.max(m,46)!==a.length&&B(`ipv4 Length mismatch: ${m} != ${a.length}`,16777216);c.ipv4=g;e=a.subarray(4*e,m);if(1===d)a=new DataView(e.buffer,e.byteOffset,e.byteLength),a={type:a.getUint8(0),code:a.getUint8(1),checksum:a.getUint16(2),data:e.subarray(4)},c.icmp=a;else if(6===d)d=new DataView(e.buffer,e.byteOffset,e.byteLength),a={sport:d.getUint16(0),dport:d.getUint16(2),seq:d.getUint32(4),
|
|
192
|
+
ackn:d.getUint32(8),doff:d.getUint8(12)>>4,winsize:d.getUint16(14),checksum:d.getUint16(16),urgent:d.getUint16(18)},d=d.getUint8(13),a.fin=!!(d&1),a.syn=!!(d&2),a.rst=!!(d&4),a.psh=!!(d&8),a.ack=!!(d&16),a.urg=!!(d&32),a.ece=!!(d&64),a.cwr=!!(d&128),c.tcp=a,c.tcp_data=e.subarray(4*a.doff);else if(17===d){a=new DataView(e.buffer,e.byteOffset,e.byteLength);a={sport:a.getUint16(0),dport:a.getUint16(2),len:a.getUint16(4),checksum:a.getUint16(6),data:e.subarray(8),data_s:(new TextDecoder).decode(e.subarray(8))};
|
|
193
|
+
if(67===a.dport||67===a.sport){e=e.subarray(8);d=new DataView(e.buffer,e.byteOffset,e.byteLength);e.subarray(44,236);d={op:d.getUint8(0),htype:d.getUint8(1),hlen:d.getUint8(2),hops:d.getUint8(3),xid:d.getUint32(4),secs:d.getUint16(8),flags:d.getUint16(10),ciaddr:d.getUint32(12),yiaddr:d.getUint32(16),siaddr:d.getUint32(20),giaddr:d.getUint32(24),chaddr:e.subarray(28,44),magic:d.getUint32(236),options:[]};e=e.subarray(240);for(m=0;m<e.length;++m)g=m,0!==e[m]&&(++m,k=e[m],m+=k,d.options.push(e.subarray(g,
|
|
194
|
+
g+k+2)));c.dhcp=d;c.dhcp_options=d.options}else 53===a.dport||53===a.sport?Wb(e.subarray(8),c):123===a.dport&&(d=e.subarray(8),d=new DataView(d.buffer,d.byteOffset,d.byteLength),c.ntp={flags:d.getUint8(0),stratum:d.getUint8(1),poll:d.getUint8(2),precision:d.getUint8(3),root_delay:d.getUint32(4),root_disp:d.getUint32(8),ref_id:d.getUint32(12),ref_ts_i:d.getUint32(16),ref_ts_f:d.getUint32(20),ori_ts_i:d.getUint32(24),ori_ts_f:d.getUint32(28),rec_ts_i:d.getUint32(32),rec_ts_f:d.getUint32(36),trans_ts_i:d.getUint32(40),
|
|
195
|
+
trans_ts_f:d.getUint32(44)});c.udp=a}}else 2054===d?(d=new DataView(a.buffer,a.byteOffset,a.byteLength),a={htype:d.getUint16(0),ptype:d.getUint16(2),oper:d.getUint16(6),sha:a.subarray(8,14),spa:a.subarray(14,18),tha:a.subarray(18,24),tpa:a.subarray(24,28)},c.arp=a):34525===d?B("Unimplemented: ipv6"):B("Unknown ethertype: "+n(d),16777216);if(c.ipv4)if(c.tcp)a:{a=`${c.ipv4.src.join(".")}:${c.tcp.sport}:${c.ipv4.dest.join(".")}:${c.tcp.dport}`;if(c.tcp.syn&&(b.tcp_conn[a]&&B("SYN to already opened port",
|
|
196
|
+
16777216),b.on_tcp_connection(c,a)))break a;if(b.tcp_conn[a])b.tcp_conn[a].process(c);else{B(`I dont know about ${a}, so resetting`,16777216);a=c.tcp.ackn;if(c.tcp.fin||c.tcp.syn)a+=1;d={};d.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src};d.ipv4={proto:6,src:c.ipv4.dest,dest:c.ipv4.src};d.tcp={sport:c.tcp.dport,dport:c.tcp.sport,seq:a,ackn:c.tcp.seq+(c.tcp.syn?1:0),winsize:c.tcp.winsize,rst:!0,ack:c.tcp.syn};b.receive(Jb(b.eth_encoder_buf,d))}}else if(c.udp)if(c.dns)if("static"===b.dns_method){a=
|
|
197
|
+
{};a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src};a.ipv4={proto:17,src:b.router_ip,dest:c.ipv4.src};a.udp={sport:53,dport:c.udp.sport};d=[];for(e=0;e<c.dns.questions.length;++e)switch(m=c.dns.questions[e],m.type){case 1:d.push({name:m.name,type:m.type,class:m.class,ttl:600,data:[192,168,87,1]})}a.dns={id:c.dns.id,flags:33152,questions:c.dns.questions,answers:d};b.receive(Jb(b.eth_encoder_buf,a))}else Tb(c,b);else c.dhcp?Ub(c,b):c.ntp?(a=Date.now()+Ab,d=a%1E3/1E3*Bb,e={},e.eth={ethertype:2048,
|
|
198
|
+
src:b.router_mac,dest:c.eth.src},e.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},e.udp={sport:123,dport:c.udp.sport},e.ntp=Object.assign({},c.ntp),e.ntp.flags=36,e.ntp.poll=10,e.ntp.ori_ts_i=c.ntp.trans_ts_i,e.ntp.ori_ts_f=c.ntp.trans_ts_f,e.ntp.rec_ts_i=a/1E3,e.ntp.rec_ts_f=d,e.ntp.trans_ts_i=a/1E3,e.ntp.trans_ts_f=d,e.ntp.stratum=2,b.receive(Jb(b.eth_encoder_buf,e))):8===c.udp.dport&&(a={},a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},a.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},
|
|
199
|
+
a.udp={sport:c.udp.dport,dport:c.udp.sport,data:(new TextEncoder).encode(c.udp.data_s)},b.receive(Jb(b.eth_encoder_buf,a)));else c.icmp&&8===c.icmp.type&&(a={},a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},a.ipv4={proto:1,src:c.ipv4.dest,dest:c.ipv4.src},a.icmp={type:0,code:c.icmp.code,data:c.icmp.data},b.receive(Jb(b.eth_encoder_buf,a)));else c.arp&&1===c.arp.oper&&2048===c.arp.ptype&&(a=Eb(c.arp.tpa)&4294967040,d=Eb(b.router_ip)&4294967040,!b.masquerade&&a!==d||a===d&&99<c.arp.tpa[3]||
|
|
200
|
+
(a={},a.eth={ethertype:2054,src:b.router_mac,dest:c.eth.src},a.arp={htype:1,ptype:2048,oper:2,sha:b.router_mac,spa:c.arp.tpa,tha:c.eth.src,tpa:c.arp.spa},b.receive(Jb(b.eth_encoder_buf,a))))}function Wb(a,b){function c(){let p=[],q;do q=d.getUint8(k),p.push((new TextDecoder).decode(a.subarray(k+1,k+1+q))),k+=q+1;while(0<q);return p}let d=new DataView(a.buffer,a.byteOffset,a.byteLength),e={id:d.getUint16(0),flags:d.getUint16(2),questions:[],answers:[]};var f=d.getUint16(4);let g=d.getUint16(6);d.getUint16(8);
|
|
201
|
+
d.getUint16(10);let k=12;for(var m=0;m<f;m++)e.questions.push({name:c(),type:d.getInt16(k),class:d.getInt16(k+2)}),k+=4;for(f=0;f<g;f++){m={name:c(),type:d.getInt16(k),class:d.getUint16(k+2),ttl:d.getUint32(k+4)};k+=8;let p=d.getUint16(k);k+=2;m.data=a.subarray(k,k+p);k+=p;e.answers.push(m)}b.dns=e}function Xb(a,b){var c=b.vm_ip.join(".");const d=b.router_ip.join("."),e=16383*Math.random()|0;let f,g,k=0;do f=49152+(e+k)%16383,g=`${c}:${a}:${d}:${f}`;while(16383>++k&&b.tcp_conn[g]);if(b.tcp_conn[g])throw Error("pool of dynamic TCP port numbers exhausted, connection aborted");
|
|
202
|
+
c=new Yb(b);c.tuple=g;c.hsrc=b.router_mac;c.psrc=b.router_ip;c.sport=f;c.hdest=b.vm_mac;c.dport=a;c.pdest=b.vm_ip;b.tcp_conn[g]=c;c.connect();return c}function Zb(a,b){return new Promise(c=>{let d=Xb(a,b);d.state="syn-probe";d.on("probe",c)})}function Yb(a){this.mtu=a.mtu||1500;const b=this.mtu-20-20;this.state="closed";this.net=a;this.send_buffer=new Fb(2048,0);this.send_chunk_buf=new Uint8Array(b);this.delayed_send_fin=this.in_active_close=!1;this.delayed_state=void 0;this.events_handlers={}}Yb.prototype.on=
|
|
203
203
|
function(a,b){this.events_handlers[a]=b};Yb.prototype.emit=function(a,...b){this.events_handlers[a]&&this.events_handlers[a].apply(this,b)};Yb.prototype.ipv4_reply=function(){let a={};a.eth={ethertype:2048,src:this.hsrc,dest:this.hdest};a.ipv4={proto:6,src:this.psrc,dest:this.pdest};a.tcp={sport:this.sport,dport:this.dport,winsize:this.winsize,ackn:this.ack,seq:this.seq,ack:!0};return a};Yb.prototype.packet_reply=function(a,b){a={sport:a.tcp.dport,dport:a.tcp.sport,winsize:a.tcp.winsize,ackn:this.ack,
|
|
204
204
|
seq:this.seq};if(b)for(const c in b)a[c]=b[c];b=this.ipv4_reply();b.tcp=a;return b};Yb.prototype.connect=function(){this.seq=1338;this.ack=1;this.start_seq=0;this.winsize=64240;this.state="syn-sent";let a=this.ipv4_reply();a.ipv4.id=2345;a.tcp={sport:this.sport,dport:this.dport,seq:1337,ackn:0,winsize:0,syn:!0};this.net.receive(Jb(this.net.eth_encoder_buf,a))};Yb.prototype.accept=function(a){this.seq=1338;this.ack=a.tcp.seq+1;this.start_seq=a.tcp.seq;this.hsrc=this.net.router_mac;this.psrc=a.ipv4.dest;
|
|
205
205
|
this.sport=a.tcp.dport;this.hdest=a.eth.src;this.dport=a.tcp.sport;this.pdest=a.ipv4.src;this.winsize=a.tcp.winsize;let b=this.ipv4_reply();b.tcp={sport:this.sport,dport:this.dport,seq:1337,ackn:this.ack,winsize:a.tcp.winsize,syn:!0,ack:!0,options:{mss:this.mtu-20-20}};this.state="established";this.net.receive(Jb(this.net.eth_encoder_buf,b))};Yb.prototype.process=function(a){if("closed"===this.state)a=this.packet_reply(a,{rst:!0}),this.net.receive(Jb(this.net.eth_encoder_buf,a));else if(a.tcp.rst){if("syn-probe"===
|
package/build/libv86.js
CHANGED
|
@@ -118,9 +118,9 @@ C.prototype.dac_send=function(){if(this.dac_buffers[0].length){var a=this.dac_bu
|
|
|
118
118
|
function cb(a,b){if("object"!==typeof a||null===a)return a;if(Array.isArray(a))return a.map(e=>cb(e,b));a.constructor===Object&&console.log(a);if(a.BYTES_PER_ELEMENT){var c=new Uint8Array(a.buffer,a.byteOffset,a.length*a.BYTES_PER_ELEMENT);return{__state_type__:a.constructor.name.replace("bound ",""),buffer_id:b.push(c)-1}}a=a.get_state();c=[];for(var d=0;d<a.length;d++)c[d]=cb(a[d],b);return c}
|
|
119
119
|
function db(a,b){if("object"!==typeof a||null===a)return a;if(Array.isArray(a)){for(let c=0;c<a.length;c++)a[c]=db(a[c],b);return a}return new bb[a.__state_type__](b[a.buffer_id])}
|
|
120
120
|
function eb(a,b){function c(q,r){const x=q.length;if(16>x)throw new ab("Invalid length: "+x);q=new Int32Array(q.buffer,q.byteOffset,4);if(-2039052682!==q[0])throw new ab("Invalid header: "+z(q[0]>>>0));if(6!==q[1])throw new ab("Version mismatch: dump="+q[1]+" we=6");if(r&&q[2]!==x)throw new ab("Length doesn't match header: real="+x+" header="+q[2]);return q[3]}function d(q){q=(new TextDecoder).decode(q);return JSON.parse(q)}b=new Uint8Array(b);if(4247762216===(new Uint32Array(b.buffer,0,1))[0]){var e=
|
|
121
|
-
a.zstd_create_ctx(b.length);(new Uint8Array(a.wasm_memory.buffer,a.zstd_get_src_ptr(e),b.length)).set(b);var f=a.zstd_read(e,16),g=new Uint8Array(a.wasm_memory.buffer,f,16),h=c(g,!1);a.zstd_read_free(f,16);f=a.zstd_read(e,h);g=new Uint8Array(a.wasm_memory.buffer,f,h);g=d(g);a.zstd_read_free(f,h);f=g.state;var l=g.buffer_infos;g=[];h=16+h;for(var m of l){l=(h+3&-4)-h;if(1048576<m.length){var n=a.zstd_read(e,l);a.zstd_read_free(n,l);n=new Uint8Array(m.length);g.push(n.buffer);for(var p=
|
|
122
|
-
Math.min(m.length-p,1048576),r=a.zstd_read(e,q);n.set(new Uint8Array(a.wasm_memory.buffer,r,q),p);a.zstd_read_free(r,q);p+=q}}else n=a.zstd_read(e,l+m.length),p=n+l,g.push(a.wasm_memory.buffer.slice(p,p+m.length)),a.zstd_read_free(n,l+m.length);h+=l+m.length}f=db(f,g);a.set_state(f);a.zstd_free_ctx(e)}else{e=c(b,!0);if(0>e||e+12>=b.length)throw new ab("Invalid info block length: "+e);m=b.subarray(16,16+e);f=d(m);m=f.state;f=f.buffer_infos;let q=16+e;q=q+3&-4;e=f.map(r=>
|
|
123
|
-
x+r.length)});m=db(m,e);a.set_state(m)}};function fb(a,b,c,d,e){let f="";var g=[],h=b?"compiled":c?"jit exit":d?"unguarded register":e?"wasm size":"executed";for(let n=0;256>n;n++)for(let p=0;8>p;p++)for(const q of[!1,!0]){var l=a.wm.exports.get_opstats_buffer(b,c,d,e,n,!1,q,p);g.push({opcode:n,count:l,is_mem:q,fixed_g:p});l=a.wm.exports.get_opstats_buffer(b,c,d,e,n,!0,q,p);g.push({opcode:3840|n,count:l,is_mem:q,fixed_g:p})}a=0;b=new Set([38,46,54,62,100,101,102,103,240,242,243]);for(const {count:n,opcode:p}of g)b.has(p)||(a+=n);if(0===
|
|
121
|
+
a.zstd_create_ctx(b.length);(new Uint8Array(a.wasm_memory.buffer,a.zstd_get_src_ptr(e)>>>0,b.length)).set(b);var f=a.zstd_read(e,16),g=new Uint8Array(a.wasm_memory.buffer,f>>>0,16),h=c(g,!1);a.zstd_read_free(f,16);f=a.zstd_read(e,h);g=new Uint8Array(a.wasm_memory.buffer,f>>>0,h);g=d(g);a.zstd_read_free(f,h);f=g.state;var l=g.buffer_infos;g=[];h=16+h;for(var m of l){l=(h+3&-4)-h;if(1048576<m.length){var n=a.zstd_read(e,l)>>>0;a.zstd_read_free(n,l);n=new Uint8Array(m.length);g.push(n.buffer);for(var p=
|
|
122
|
+
0;p<m.length;){const q=Math.min(m.length-p,1048576),r=a.zstd_read(e,q);n.set(new Uint8Array(a.wasm_memory.buffer,r>>>0,q),p);a.zstd_read_free(r,q);p+=q}}else n=a.zstd_read(e,l+m.length),p=(n>>>0)+l,g.push(a.wasm_memory.buffer.slice(p,p+m.length)),a.zstd_read_free(n,l+m.length);h+=l+m.length}f=db(f,g);a.set_state(f);a.zstd_free_ctx(e)}else{e=c(b,!0);if(0>e||e+12>=b.length)throw new ab("Invalid info block length: "+e);m=b.subarray(16,16+e);f=d(m);m=f.state;f=f.buffer_infos;let q=16+e;q=q+3&-4;e=f.map(r=>
|
|
123
|
+
{const x=q+r.offset;return b.buffer.slice(x,x+r.length)});m=db(m,e);a.set_state(m)}};function fb(a,b,c,d,e){let f="";var g=[],h=b?"compiled":c?"jit exit":d?"unguarded register":e?"wasm size":"executed";for(let n=0;256>n;n++)for(let p=0;8>p;p++)for(const q of[!1,!0]){var l=a.wm.exports.get_opstats_buffer(b,c,d,e,n,!1,q,p);g.push({opcode:n,count:l,is_mem:q,fixed_g:p});l=a.wm.exports.get_opstats_buffer(b,c,d,e,n,!0,q,p);g.push({opcode:3840|n,count:l,is_mem:q,fixed_g:p})}a=0;b=new Set([38,46,54,62,100,101,102,103,240,242,243]);for(const {count:n,opcode:p}of g)b.has(p)||(a+=n);if(0===
|
|
124
124
|
a)return"";c=new Uint32Array(256);b=new Uint32Array(256);for(const {opcode:n,count:p}of g)3840===(n&65280)?b[n&255]+=p:c[n&255]+=p;f=f+"------------------\nTotal: "+(a+"\n");const m=1E7<a?1E3:1;d=Math.max.apply(Math,g.map(({count:n})=>Math.round(n/m)));d=String(d).length;f+=`Instruction counts ${h} (in ${m}):\n`;for(e=0;256>e;e++)f+=e.toString(16).padStart(2,"0")+":"+aa(Math.round(c[e]/m),d),f=15===e%16?f+"\n":f+" ";f=f+"\n"+`Instruction counts ${h} (0f, in ${m}):\n`;for(h=0;256>h;h++)f+=(h&255).toString(16).padStart(2,
|
|
125
125
|
"0")+":"+aa(Math.round(b[h]/m),d),f=15===h%16?f+"\n":f+" ";f+="\n";g=g.filter(({count:n})=>n).sort(({count:n},{count:p})=>p-n);for(const {opcode:n,is_mem:p,fixed_g:q,count:r}of g.slice(0,200))g=n.toString(16)+"_"+q+(p?"_m":"_r"),f+=g+":"+(r/a*100).toFixed(2)+" ";return f+"\n"};function gb(a){this.cpu=a;this.cmos_index=0;this.cmos_data=new Uint8Array(128);this.last_update=this.rtc_time=Date.now();this.next_interrupt_alarm=this.next_interrupt=0;this.periodic_interrupt=!1;this.periodic_interrupt_time=.9765625;this.cmos_a=38;this.cmos_b=2;this.nmi_disabled=this.cmos_diag_status=this.cmos_c=0;this.update_interrupt=!1;this.update_interrupt_time=0;a.io.register_write(112,this,function(b){this.cmos_index=b&127;this.nmi_disabled=b>>7});a.io.register_write(113,this,this.cmos_port_write);
|
|
126
126
|
a.io.register_read(113,this,this.cmos_port_read)}gb.prototype.get_state=function(){var a=[];a[0]=this.cmos_index;a[1]=this.cmos_data;a[2]=this.rtc_time;a[3]=this.last_update;a[4]=this.next_interrupt;a[5]=this.next_interrupt_alarm;a[6]=this.periodic_interrupt;a[7]=this.periodic_interrupt_time;a[8]=this.cmos_a;a[9]=this.cmos_b;a[10]=this.cmos_c;a[11]=this.nmi_disabled;a[12]=this.update_interrupt;a[13]=this.update_interrupt_time;a[14]=this.cmos_diag_status;return a};
|
package/build/libv86.mjs
CHANGED
|
@@ -103,8 +103,8 @@ function(a){var b=this.dsp_16bit?32767.5:127.5,c=this.dsp_signed?0:-1,d=this.dsp
|
|
|
103
103
|
this.dac_buffers[0].shift_block(this.dac_buffers[0].length),b=this.dac_buffers[1].shift_block(this.dac_buffers[1].length);this.bus.send("dac-send-data",[a,b],[a.buffer,b.buffer])}};C.prototype.raise_irq=function(a){this.irq_triggered[a]=1;this.cpu.device_raise_irq(this.irq)};C.prototype.lower_irq=function(a){this.irq_triggered[a]=0;this.cpu.device_lower_irq(this.irq)};function Ra(a,b,c){return(a<b)*b+(a>c)*c+(b<=a&&a<=c)*a}function ab(a){this.message=a}ab.prototype=Error();const bb={Uint8Array,Int8Array,
|
|
104
104
|
Uint16Array,Int16Array,Uint32Array,Int32Array,Float32Array,Float64Array};function cb(a,b){if("object"!==typeof a||null===a)return a;if(Array.isArray(a))return a.map(e=>cb(e,b));a.constructor===Object&&console.log(a);if(a.BYTES_PER_ELEMENT){var c=new Uint8Array(a.buffer,a.byteOffset,a.length*a.BYTES_PER_ELEMENT);return{__state_type__:a.constructor.name.replace("bound ",""),buffer_id:b.push(c)-1}}a=a.get_state();c=[];for(var d=0;d<a.length;d++)c[d]=cb(a[d],b);return c}function db(a,b){if("object"!==
|
|
105
105
|
typeof a||null===a)return a;if(Array.isArray(a)){for(let c=0;c<a.length;c++)a[c]=db(a[c],b);return a}return new bb[a.__state_type__](b[a.buffer_id])}function eb(a,b){function c(q,r){const x=q.length;if(16>x)throw new ab("Invalid length: "+x);q=new Int32Array(q.buffer,q.byteOffset,4);if(-2039052682!==q[0])throw new ab("Invalid header: "+z(q[0]>>>0));if(6!==q[1])throw new ab("Version mismatch: dump="+q[1]+" we=6");if(r&&q[2]!==x)throw new ab("Length doesn't match header: real="+x+" header="+q[2]);return q[3]}
|
|
106
|
-
function d(q){q=(new TextDecoder).decode(q);return JSON.parse(q)}b=new Uint8Array(b);if(4247762216===(new Uint32Array(b.buffer,0,1))[0]){var e=a.zstd_create_ctx(b.length);(new Uint8Array(a.wasm_memory.buffer,a.zstd_get_src_ptr(e),b.length)).set(b);var f=a.zstd_read(e,16),g=new Uint8Array(a.wasm_memory.buffer,f,16),h=c(g,!1);a.zstd_read_free(f,16);f=a.zstd_read(e,h);g=new Uint8Array(a.wasm_memory.buffer,f,h);g=d(g);a.zstd_read_free(f,h);f=g.state;var l=g.buffer_infos;g=[];h=16+h;for(var m of l){l=
|
|
107
|
-
(h+3&-4)-h;if(1048576<m.length){var n=a.zstd_read(e,l);a.zstd_read_free(n,l);n=new Uint8Array(m.length);g.push(n.buffer);for(var p=0;p<m.length;){const q=Math.min(m.length-p,1048576),r=a.zstd_read(e,q);n.set(new Uint8Array(a.wasm_memory.buffer,r,q),p);a.zstd_read_free(r,q);p+=q}}else n=a.zstd_read(e,l+m.length),p=n+l,g.push(a.wasm_memory.buffer.slice(p,p+m.length)),a.zstd_read_free(n,l+m.length);h+=l+m.length}f=db(f,g);a.set_state(f);a.zstd_free_ctx(e)}else{e=c(b,!0);if(0>e||e+12>=b.length)throw new ab("Invalid info block length: "+
|
|
106
|
+
function d(q){q=(new TextDecoder).decode(q);return JSON.parse(q)}b=new Uint8Array(b);if(4247762216===(new Uint32Array(b.buffer,0,1))[0]){var e=a.zstd_create_ctx(b.length);(new Uint8Array(a.wasm_memory.buffer,a.zstd_get_src_ptr(e)>>>0,b.length)).set(b);var f=a.zstd_read(e,16),g=new Uint8Array(a.wasm_memory.buffer,f>>>0,16),h=c(g,!1);a.zstd_read_free(f,16);f=a.zstd_read(e,h);g=new Uint8Array(a.wasm_memory.buffer,f>>>0,h);g=d(g);a.zstd_read_free(f,h);f=g.state;var l=g.buffer_infos;g=[];h=16+h;for(var m of l){l=
|
|
107
|
+
(h+3&-4)-h;if(1048576<m.length){var n=a.zstd_read(e,l)>>>0;a.zstd_read_free(n,l);n=new Uint8Array(m.length);g.push(n.buffer);for(var p=0;p<m.length;){const q=Math.min(m.length-p,1048576),r=a.zstd_read(e,q);n.set(new Uint8Array(a.wasm_memory.buffer,r>>>0,q),p);a.zstd_read_free(r,q);p+=q}}else n=a.zstd_read(e,l+m.length),p=(n>>>0)+l,g.push(a.wasm_memory.buffer.slice(p,p+m.length)),a.zstd_read_free(n,l+m.length);h+=l+m.length}f=db(f,g);a.set_state(f);a.zstd_free_ctx(e)}else{e=c(b,!0);if(0>e||e+12>=b.length)throw new ab("Invalid info block length: "+
|
|
108
108
|
e);m=b.subarray(16,16+e);f=d(m);m=f.state;f=f.buffer_infos;let q=16+e;q=q+3&-4;e=f.map(r=>{const x=q+r.offset;return b.buffer.slice(x,x+r.length)});m=db(m,e);a.set_state(m)}}function fb(a,b,c,d,e){let f="";var g=[],h=b?"compiled":c?"jit exit":d?"unguarded register":e?"wasm size":"executed";for(let n=0;256>n;n++)for(let p=0;8>p;p++)for(const q of[!1,!0]){var l=a.wm.exports.get_opstats_buffer(b,c,d,e,n,!1,q,p);g.push({opcode:n,count:l,is_mem:q,fixed_g:p});l=a.wm.exports.get_opstats_buffer(b,c,d,e,n,
|
|
109
109
|
!0,q,p);g.push({opcode:3840|n,count:l,is_mem:q,fixed_g:p})}a=0;b=new Set([38,46,54,62,100,101,102,103,240,242,243]);for(const {count:n,opcode:p}of g)b.has(p)||(a+=n);if(0===a)return"";c=new Uint32Array(256);b=new Uint32Array(256);for(const {opcode:n,count:p}of g)3840===(n&65280)?b[n&255]+=p:c[n&255]+=p;f=f+"------------------\nTotal: "+(a+"\n");const m=1E7<a?1E3:1;d=Math.max.apply(Math,g.map(({count:n})=>Math.round(n/m)));d=String(d).length;f+=`Instruction counts ${h} (in ${m}):\n`;for(e=0;256>e;e++)f+=
|
|
110
110
|
e.toString(16).padStart(2,"0")+":"+aa(Math.round(c[e]/m),d),f=15===e%16?f+"\n":f+" ";f=f+"\n"+`Instruction counts ${h} (0f, in ${m}):\n`;for(h=0;256>h;h++)f+=(h&255).toString(16).padStart(2,"0")+":"+aa(Math.round(b[h]/m),d),f=15===h%16?f+"\n":f+" ";f+="\n";g=g.filter(({count:n})=>n).sort(({count:n},{count:p})=>p-n);for(const {opcode:n,is_mem:p,fixed_g:q,count:r}of g.slice(0,200))g=n.toString(16)+"_"+q+(p?"_m":"_r"),f+=g+":"+(r/a*100).toFixed(2)+" ";return f+"\n"}function gb(a){this.cpu=a;this.cmos_index=
|