v86 0.5.65 → 0.5.66
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 +12 -2
- package/build/libv86-debug.mjs +23 -22
- package/build/libv86.js +8 -7
- package/build/libv86.mjs +112 -111
- package/package.json +1 -1
package/build/libv86-debug.js
CHANGED
|
@@ -2312,6 +2312,8 @@ function $restore_state$$module$src$state$$($cpu$jscomp$5$$, $state$jscomp$9$$)
|
|
|
2312
2312
|
this.cmos_a = 38;
|
|
2313
2313
|
this.cmos_b = 2;
|
|
2314
2314
|
this.nmi_disabled = this.cmos_c = 0;
|
|
2315
|
+
this.update_interrupt = !1;
|
|
2316
|
+
this.update_interrupt_time = 0;
|
|
2315
2317
|
$cpu$jscomp$10$$.io.register_write(112, this, function($out_byte$$) {
|
|
2316
2318
|
this.cmos_index = $out_byte$$ & 127;
|
|
2317
2319
|
this.nmi_disabled = $out_byte$$ >> 7;
|
|
@@ -2333,6 +2335,8 @@ $RTC$$module$src$rtc$$.prototype.get_state = function() {
|
|
|
2333
2335
|
$state$jscomp$11$$[9] = this.cmos_b;
|
|
2334
2336
|
$state$jscomp$11$$[10] = this.cmos_c;
|
|
2335
2337
|
$state$jscomp$11$$[11] = this.nmi_disabled;
|
|
2338
|
+
$state$jscomp$11$$[12] = this.update_interrupt;
|
|
2339
|
+
$state$jscomp$11$$[13] = this.update_interrupt_time;
|
|
2336
2340
|
return $state$jscomp$11$$;
|
|
2337
2341
|
};
|
|
2338
2342
|
$RTC$$module$src$rtc$$.prototype.set_state = function($state$jscomp$12$$) {
|
|
@@ -2348,15 +2352,19 @@ $RTC$$module$src$rtc$$.prototype.set_state = function($state$jscomp$12$$) {
|
|
|
2348
2352
|
this.cmos_b = $state$jscomp$12$$[9];
|
|
2349
2353
|
this.cmos_c = $state$jscomp$12$$[10];
|
|
2350
2354
|
this.nmi_disabled = $state$jscomp$12$$[11];
|
|
2355
|
+
this.update_interrupt = $state$jscomp$12$$[12] || !1;
|
|
2356
|
+
this.update_interrupt_time = $state$jscomp$12$$[13] || 0;
|
|
2351
2357
|
};
|
|
2352
2358
|
$RTC$$module$src$rtc$$.prototype.timer = function($time$$) {
|
|
2353
2359
|
$time$$ = Date.now();
|
|
2354
2360
|
this.rtc_time += $time$$ - this.last_update;
|
|
2355
2361
|
this.last_update = $time$$;
|
|
2356
|
-
this.periodic_interrupt && this.next_interrupt < $time$$ ? (this.cpu.device_raise_irq(8), this.cmos_c |= 192, this.next_interrupt += this.periodic_interrupt_time * Math.ceil(($time$$ - this.next_interrupt) / this.periodic_interrupt_time)) : this.next_interrupt_alarm && this.next_interrupt_alarm < $time$$
|
|
2362
|
+
this.periodic_interrupt && this.next_interrupt < $time$$ ? (this.cpu.device_raise_irq(8), this.cmos_c |= 192, this.next_interrupt += this.periodic_interrupt_time * Math.ceil(($time$$ - this.next_interrupt) / this.periodic_interrupt_time)) : this.next_interrupt_alarm && this.next_interrupt_alarm < $time$$ ? (this.cpu.device_raise_irq(8), this.cmos_c |= 160, this.next_interrupt_alarm = 0) : this.update_interrupt && this.update_interrupt_time < $time$$ && (this.cpu.device_raise_irq(8), this.cmos_c |=
|
|
2363
|
+
144, this.update_interrupt_time = $time$$ + 1000);
|
|
2357
2364
|
let $t$jscomp$1$$ = 100;
|
|
2358
2365
|
this.periodic_interrupt && this.next_interrupt && ($t$jscomp$1$$ = Math.min($t$jscomp$1$$, Math.max(0, this.next_interrupt - $time$$)));
|
|
2359
2366
|
this.next_interrupt_alarm && ($t$jscomp$1$$ = Math.min($t$jscomp$1$$, Math.max(0, this.next_interrupt_alarm - $time$$)));
|
|
2367
|
+
this.update_interrupt && ($t$jscomp$1$$ = Math.min($t$jscomp$1$$, Math.max(0, this.update_interrupt_time - $time$$)));
|
|
2360
2368
|
return $t$jscomp$1$$;
|
|
2361
2369
|
};
|
|
2362
2370
|
$RTC$$module$src$rtc$$.prototype.bcd_pack = function($n$jscomp$7$$) {
|
|
@@ -2419,6 +2427,7 @@ $RTC$$module$src$rtc$$.prototype.cmos_port_write = function($data_byte$jscomp$8_
|
|
|
2419
2427
|
break;
|
|
2420
2428
|
case 11:
|
|
2421
2429
|
this.cmos_b = $data_byte$jscomp$8_now$jscomp$1$$;
|
|
2430
|
+
this.cmos_b & 128 && (this.cmos_b &= 239);
|
|
2422
2431
|
this.cmos_b & 64 && (this.next_interrupt = Date.now());
|
|
2423
2432
|
if (this.cmos_b & 32) {
|
|
2424
2433
|
$data_byte$jscomp$8_now$jscomp$1$$ = new Date;
|
|
@@ -2426,7 +2435,7 @@ $RTC$$module$src$rtc$$.prototype.cmos_port_write = function($data_byte$jscomp$8_
|
|
|
2426
2435
|
$dbg_log$$module$src$log$$("RTC alarm scheduled for " + $alarm_date$$ + " hh:mm:ss=" + $hours$$ + ":" + $minutes$$ + ":" + $seconds$$ + " ms_from_now=" + ($alarm_date$$ - $data_byte$jscomp$8_now$jscomp$1$$), 65536);
|
|
2427
2436
|
this.next_interrupt_alarm = +$alarm_date$$;
|
|
2428
2437
|
}
|
|
2429
|
-
this.cmos_b & 16 && $dbg_log$$module$src$log$$("
|
|
2438
|
+
this.cmos_b & 16 && ($dbg_log$$module$src$log$$("update interrupt", 65536), this.update_interrupt_time = Date.now());
|
|
2430
2439
|
$dbg_log$$module$src$log$$("cmos b=" + $h$$module$src$lib$$(this.cmos_b, 2), 65536);
|
|
2431
2440
|
break;
|
|
2432
2441
|
case 1:
|
|
@@ -2437,6 +2446,7 @@ $RTC$$module$src$rtc$$.prototype.cmos_port_write = function($data_byte$jscomp$8_
|
|
|
2437
2446
|
default:
|
|
2438
2447
|
$dbg_log$$module$src$log$$("cmos write index " + $h$$module$src$lib$$(this.cmos_index) + ": " + $h$$module$src$lib$$($data_byte$jscomp$8_now$jscomp$1$$), 65536);
|
|
2439
2448
|
}
|
|
2449
|
+
this.update_interrupt = 16 === (this.cmos_b & 16) && 0 < (this.cmos_a & 15);
|
|
2440
2450
|
this.periodic_interrupt = 64 === (this.cmos_b & 64) && 0 < (this.cmos_a & 15);
|
|
2441
2451
|
};
|
|
2442
2452
|
$RTC$$module$src$rtc$$.prototype.cmos_read = function($index$jscomp$80$$) {
|
package/build/libv86-debug.mjs
CHANGED
|
@@ -121,28 +121,29 @@ h.push(q.buffer);for(var r=0;r<n.length;){var t=n.length-r;k(0<=t);t=Math.min(t,
|
|
|
121
121
|
let v=16+e;v=v+3&-4;e=f.map(y=>{const A=v+y.offset;return b.buffer.slice(A,A+y.length)});n=eb(n,e);a.set_state(n)}}function gb(a,b,c,d,e){let f="";var h=[],l=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 t of[!1,!0]){var p=a.wm.exports.get_opstats_buffer(b,c,d,e,q,!1,t,r);h.push({opcode:q,count:p,is_mem:t,fixed_g:r});p=a.wm.exports.get_opstats_buffer(b,c,d,e,q,!0,t,r);h.push({opcode:3840|q,count:p,is_mem:t,fixed_g:r})}a=
|
|
122
122
|
0;b=new Set([38,46,54,62,100,101,102,103,240,242,243]);for(const {count:q,opcode:r}of h)b.has(r)||(a+=q);if(0===a)return"";c=new Uint32Array(256);b=new Uint32Array(256);for(const {opcode:q,count:r}of h)3840===(q&65280)?b[q&255]+=r:c[q&255]+=r;f=f+"------------------\nTotal: "+(a+"\n");const n=1E7<a?1E3:1;d=Math.max.apply(Math,h.map(({count:q})=>Math.round(q/n)));d=String(d).length;f+=`Instruction counts ${l} (in ${n}):\n`;for(e=0;256>e;e++)f+=e.toString(16).padStart(2,"0")+":"+ba(Math.round(c[e]/
|
|
123
123
|
n),d),f=15===e%16?f+"\n":f+" ";f=f+"\n"+`Instruction counts ${l} (0f, in ${n}):\n`;for(l=0;256>l;l++)f+=(l&255).toString(16).padStart(2,"0")+":"+ba(Math.round(b[l]/n),d),f=15===l%16?f+"\n":f+" ";f+="\n";h=h.filter(({count:q})=>q).sort(({count:q},{count:r})=>r-q);for(const {opcode:q,is_mem:r,fixed_g:t,count:v}of h.slice(0,200))h=q.toString(16)+"_"+t+(r?"_m":"_r"),f+=h+":"+(v/a*100).toFixed(2)+" ";return f+"\n"}function hb(a){this.cpu=a;this.cmos_index=0;this.cmos_data=new Uint8Array(128);this.last_update=
|
|
124
|
-
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_c=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)}hb.prototype.get_state=function(){var a=[];a[0]=this.cmos_index;
|
|
125
|
-
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;return a};hb.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=
|
|
126
|
-
a[11]};hb.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&&
|
|
127
|
-
(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)));
|
|
128
|
-
function(){var a=
|
|
129
|
-
case
|
|
130
|
-
m(this.encode_time((new Date(this.rtc_time)).
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
a.io.
|
|
136
|
-
this.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
C("
|
|
143
|
-
|
|
144
|
-
this.audio_context.
|
|
145
|
-
this.
|
|
124
|
+
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_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)}hb.prototype.get_state=function(){var a=[];a[0]=this.cmos_index;
|
|
125
|
+
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;return a};hb.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=
|
|
126
|
+
a[6];this.periodic_interrupt_time=a[7];this.cmos_a=a[8];this.cmos_b=a[9];this.cmos_c=a[10];this.nmi_disabled=a[11];this.update_interrupt=a[12]||!1;this.update_interrupt_time=a[13]||0};hb.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&&
|
|
127
|
+
this.next_interrupt_alarm<a?(this.cpu.device_raise_irq(8),this.cmos_c|=160,this.next_interrupt_alarm=0):this.update_interrupt&&this.update_interrupt_time<a&&(this.cpu.device_raise_irq(8),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-
|
|
128
|
+
a)));return b};hb.prototype.bcd_pack=function(a){for(var b=0,c=0,d;a;)d=a%10,c|=d<<4*b,b++,a=(a-d)/10;return c};hb.prototype.bcd_unpack=function(a){const b=a&15,c=a>>4&15;k(256>a);k(10>b);k(10>c);return b+10*c};hb.prototype.encode_time=function(a){return this.cmos_b&4?a:this.bcd_pack(a)};hb.prototype.decode_time=function(a){return this.cmos_b&4?a:this.bcd_unpack(a)};hb.prototype.cmos_port_read=function(){var a=this.cmos_index;switch(a){case 0:return C("read second: "+m(this.encode_time((new Date(this.rtc_time)).getUTCSeconds())),
|
|
129
|
+
65536),this.encode_time((new Date(this.rtc_time)).getUTCSeconds());case 2:return C("read minute: "+m(this.encode_time((new Date(this.rtc_time)).getUTCMinutes())),65536),this.encode_time((new Date(this.rtc_time)).getUTCMinutes());case 4:return C("read hour: "+m(this.encode_time((new Date(this.rtc_time)).getUTCHours())),65536),this.encode_time((new Date(this.rtc_time)).getUTCHours());case 6:return C("read day: "+m(this.encode_time((new Date(this.rtc_time)).getUTCDay()+1)),65536),this.encode_time((new Date(this.rtc_time)).getUTCDay()+
|
|
130
|
+
1);case 7:return C("read day of month: "+m(this.encode_time((new Date(this.rtc_time)).getUTCDate())),65536),this.encode_time((new Date(this.rtc_time)).getUTCDate());case 8:return C("read month: "+m(this.encode_time((new Date(this.rtc_time)).getUTCMonth()+1)),65536),this.encode_time((new Date(this.rtc_time)).getUTCMonth()+1);case 9:return C("read year: "+m(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<=
|
|
131
|
+
I.microtick()%1E3?this.cmos_a|128:this.cmos_a;case 11:return this.cmos_b;case 12:return this.cpu.device_lower_irq(8),C("cmos reg C read",65536),a=this.cmos_c,this.cmos_c&=-241,a;case 13:return 0;case 50:case 55:return C("read century: "+m(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 C("cmos read from index "+m(a),65536),this.cmos_data[this.cmos_index]}};hb.prototype.cmos_port_write=function(a){switch(this.cmos_index){case 10:this.cmos_a=
|
|
132
|
+
a&127;this.periodic_interrupt_time=1E3/(32768>>(this.cmos_a&15)-1);C("Periodic interrupt, a="+m(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]),e=new Date(Date.UTC(a.getUTCFullYear(),a.getUTCMonth(),a.getUTCDate(),d,c,b));C("RTC alarm scheduled for "+
|
|
133
|
+
e+" hh:mm:ss="+d+":"+c+":"+b+" ms_from_now="+(e-a),65536);this.next_interrupt_alarm=+e}this.cmos_b&16&&(C("update interrupt",65536),this.update_interrupt_time=Date.now());C("cmos b="+m(this.cmos_b,2),65536);break;case 1:case 3:case 5:this.cmos_write(this.cmos_index,a);break;default:C("cmos write index "+m(this.cmos_index)+": "+m(a),65536)}this.update_interrupt=16===(this.cmos_b&16)&&0<(this.cmos_a&15);this.periodic_interrupt=64===(this.cmos_b&64)&&0<(this.cmos_a&15)};hb.prototype.cmos_read=function(a){k(128>
|
|
134
|
+
a);return this.cmos_data[a]};hb.prototype.cmos_write=function(a,b){C("cmos "+m(a)+" <- "+m(b),65536);k(128>a);this.cmos_data[a]=b};function jb(a,b){this.cpu=a;this.bus=b;this.counter_start_time=new Float64Array(3);this.counter_start_value=new Uint16Array(3);this.counter_next_low=new Uint8Array(4);this.counter_enabled=new Uint8Array(4);this.counter_mode=new Uint8Array(4);this.counter_read_mode=new Uint8Array(4);this.counter_latch=new Uint8Array(4);this.counter_latch_value=new Uint16Array(3);this.counter_reload=
|
|
135
|
+
new Uint16Array(3);a.io.register_read(97,this,function(){var c=I.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,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,
|
|
136
|
+
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)}jb.prototype.get_state=function(){var a=[];a[0]=this.counter_next_low;a[1]=this.counter_enabled;a[2]=this.counter_mode;a[3]=this.counter_read_mode;a[4]=this.counter_latch;a[5]=this.counter_latch_value;a[6]=this.counter_reload;a[7]=this.counter_start_time;
|
|
137
|
+
a[8]=this.counter_start_value;return a};jb.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]};jb.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,C("pit interrupt. new value: "+
|
|
138
|
+
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])))/1193.1816666));return c};jb.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;C("diff="+
|
|
139
|
+
c+" dticks="+d+" value="+b+" reload="+this.counter_reload[a],512);c=this.counter_reload[a];b>=c?(C("Warning: Counter"+a+" value "+b+" is larger than reload "+c,512),b%=c):0>b&&(b=b%c+c);return b};jb.prototype.did_rollover=function(a,b){b-=this.counter_start_time[a];return 0>b?(C("Warning: PIT timer difference is negative, resetting (timer "+a+")"),!0):this.counter_start_value[a]<Math.floor(1193.1816666*b)};jb.prototype.counter_read=function(a){var b=this.counter_latch[a];if(b)return this.counter_latch[a]--,
|
|
140
|
+
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,I.microtick());return b?a&255:a>>8};jb.prototype.counter_write=function(a,b){this.counter_reload[a]=this.counter_next_low[a]?this.counter_reload[a]&-256|b:this.counter_reload[a]&255|b<<8;3===this.counter_read_mode[a]&&this.counter_next_low[a]||(this.counter_reload[a]||(this.counter_reload[a]=65535),this.counter_start_value[a]=
|
|
141
|
+
this.counter_reload[a],this.counter_enabled[a]=!0,this.counter_start_time[a]=I.microtick(),C("counter"+a+" reload="+m(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)};jb.prototype.port43_write=function(a){var b=a>>1&7,c=a&1,d=a>>6&3;a=a>>4&3;1===d&&C("Unimplemented timer1",512);3===d?C("Unimplemented read back",512):0===a?(this.counter_latch[d]=2,b=this.get_counter_value(d,I.microtick()),C("latch: "+
|
|
142
|
+
b,512),this.counter_latch_value[d]=b?b-1:0):(6<=b&&(b&=-5),C("Control: mode="+b+" ctr="+d+" read_mode="+a+" bcd="+c,512),this.counter_next_low[d]=1===a?0:1,0===d&&this.cpu.device_lower_irq(0),0!==b&&3!==b&&2!==b&&C("Unimplemented counter mode: "+m(b),512),this.counter_mode[d]=b,this.counter_read_mode[d]=a,2===d&&this.bus.send("pcspeaker-update",[this.counter_mode[2],this.counter_reload[2]]))};jb.prototype.dump=function(){const a=this.counter_reload[0];C("counter0 ticks every "+(a||65536)/1193.1816666+
|
|
143
|
+
"ms (reload="+a+")")};function kb(a){if("undefined"!==typeof window)if(window.AudioContext||window.webkitAudioContext){var b=window.AudioWorklet?lb:mb;this.bus=a;this.audio_context=window.AudioContext?new AudioContext:new webkitAudioContext;this.mixer=new nb(a,this.audio_context);this.pcspeaker=new ob(a,this.audio_context,this.mixer);this.dac=new b(a,this.audio_context,this.mixer);this.pcspeaker.start();a.register("emulator-stopped",function(){this.audio_context.suspend()},this);a.register("emulator-started",
|
|
144
|
+
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")}kb.prototype.destroy=function(){this.audio_context&&this.audio_context.close();this.audio_context=null;this.dac&&this.dac.node_processor&&this.dac.node_processor.port.close();this.dac=null};function nb(a,b){function c(d){return function(e){d.gain.setValueAtTime(e,this.audio_context.currentTime)}}
|
|
145
|
+
this.audio_context=b;this.sources=new Map;this.gain_right=this.gain_left=this.volume_right=this.volume_left=this.volume_both=1;this.node_treble_left=this.audio_context.createBiquadFilter();this.node_treble_right=this.audio_context.createBiquadFilter();this.node_treble_left.type="highshelf";this.node_treble_right.type="highshelf";this.node_treble_left.frequency.setValueAtTime(2E3,this.audio_context.currentTime);this.node_treble_right.frequency.setValueAtTime(2E3,this.audio_context.currentTime);this.node_bass_left=
|
|
146
|
+
this.audio_context.createBiquadFilter();this.node_bass_right=this.audio_context.createBiquadFilter();this.node_bass_left.type="lowshelf";this.node_bass_right.type="lowshelf";this.node_bass_left.frequency.setValueAtTime(200,this.audio_context.currentTime);this.node_bass_right.frequency.setValueAtTime(200,this.audio_context.currentTime);this.node_gain_left=this.audio_context.createGain();this.node_gain_right=this.audio_context.createGain();this.node_merger=this.audio_context.createChannelMerger(2);
|
|
146
147
|
this.input_left=this.node_treble_left;this.input_right=this.node_treble_right;this.node_treble_left.connect(this.node_bass_left);this.node_bass_left.connect(this.node_gain_left);this.node_gain_left.connect(this.node_merger,0,0);this.node_treble_right.connect(this.node_bass_right);this.node_bass_right.connect(this.node_gain_right);this.node_gain_right.connect(this.node_merger,0,1);this.node_merger.connect(this.audio_context.destination);a.register("mixer-connect",function(d){this.connect_source(d[0],
|
|
147
148
|
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 h=0===e?this:this.sources.get(e);void 0===h?k(!1,"Mixer set volume - cannot set volume for undefined source: "+e):h.set_volume(d,f)},this);a.register("mixer-gain-left",function(d){this.gain_left=Math.pow(10,d/20);this.update()},this);a.register("mixer-gain-right",function(d){this.gain_right=Math.pow(10,d/20);this.update()},
|
|
148
149
|
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)}nb.prototype.add_source=function(a,b){a=new pb(this.audio_context,a,this.input_left,this.input_right);k(!this.sources.has(b),"Mixer add source - overwritting source: "+b);this.sources.set(b,a);return a};nb.prototype.connect_source=function(a,b){var c=
|
package/build/libv86.js
CHANGED
|
@@ -119,16 +119,17 @@ a.zstd_create_ctx(b.length);(new Uint8Array(a.wasm_memory.buffer,a.zstd_get_src_
|
|
|
119
119
|
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);k+=l+m.length}f=bb(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 Za("Invalid info block length: "+e);m=b.subarray(16,16+e);f=d(m);m=f.state;f=f.buffer_infos;let q=16+e;q=q+3&-4;e=f.map(r=>{const y=q+r.offset;return b.buffer.slice(y,
|
|
120
120
|
y+r.length)});m=bb(m,e);a.set_state(m)}};function db(a,b,c,d,e){let f="";var g=[],k=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
121
|
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 ${k} (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 ${k} (0f, in ${m}):\n`;for(k=0;256>k;k++)f+=(k&255).toString(16).padStart(2,
|
|
122
|
-
"0")+":"+aa(Math.round(b[k]/m),d),f=15===k%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 eb(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_c=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,
|
|
123
|
-
eb.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;return a};
|
|
124
|
-
eb.prototype.set_state=function(a){this.cmos_index=a[0];this.cmos_data=a[1];this.rtc_time=a[2];this.last_update=a[3];this.next_interrupt=a[4];this.next_interrupt_alarm=a[5];this.periodic_interrupt=a[6];this.periodic_interrupt_time=a[7];this.cmos_a=a[8];this.cmos_b=a[9];this.cmos_c=a[10];this.nmi_disabled=a[11]};
|
|
125
|
-
eb.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
|
|
126
|
-
Math.max(0,this.next_interrupt-a)));this.next_interrupt_alarm&&(b=Math.min(b,Math.max(0,this.next_interrupt_alarm-a)));return b};eb.prototype.bcd_pack=function(a){for(var b=0,c=0,d;a;)d=a%10,c|=d<<4*b,b++,a=(a-d)/10;return c};eb.prototype.bcd_unpack=function(a){return(a&15)+10*(a>>4&15)};
|
|
122
|
+
"0")+":"+aa(Math.round(b[k]/m),d),f=15===k%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 eb(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_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,
|
|
123
|
+
this,this.cmos_port_read)}eb.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;return a};
|
|
124
|
+
eb.prototype.set_state=function(a){this.cmos_index=a[0];this.cmos_data=a[1];this.rtc_time=a[2];this.last_update=a[3];this.next_interrupt=a[4];this.next_interrupt_alarm=a[5];this.periodic_interrupt=a[6];this.periodic_interrupt_time=a[7];this.cmos_a=a[8];this.cmos_b=a[9];this.cmos_c=a[10];this.nmi_disabled=a[11];this.update_interrupt=a[12]||!1;this.update_interrupt_time=a[13]||0};
|
|
125
|
+
eb.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|=160,this.next_interrupt_alarm=0):this.update_interrupt&&this.update_interrupt_time<a&&(this.cpu.device_raise_irq(8),
|
|
126
|
+
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};eb.prototype.bcd_pack=function(a){for(var b=0,c=0,d;a;)d=a%10,c|=d<<4*b,b++,a=(a-d)/10;return c};eb.prototype.bcd_unpack=function(a){return(a&15)+10*(a>>4&15)};
|
|
127
|
+
eb.prototype.encode_time=function(a){return this.cmos_b&4?a:this.bcd_pack(a)};eb.prototype.decode_time=function(a){return this.cmos_b&4?a:this.bcd_unpack(a)};
|
|
127
128
|
eb.prototype.cmos_port_read=function(){var a=this.cmos_index;switch(a){case 0:return z(this.encode_time((new Date(this.rtc_time)).getUTCSeconds())),this.encode_time((new Date(this.rtc_time)).getUTCSeconds());case 2:return z(this.encode_time((new Date(this.rtc_time)).getUTCMinutes())),this.encode_time((new Date(this.rtc_time)).getUTCMinutes());case 4:return z(this.encode_time((new Date(this.rtc_time)).getUTCHours())),this.encode_time((new Date(this.rtc_time)).getUTCHours());case 6:return z(this.encode_time((new Date(this.rtc_time)).getUTCDay()+
|
|
128
129
|
1)),this.encode_time((new Date(this.rtc_time)).getUTCDay()+1);case 7:return z(this.encode_time((new Date(this.rtc_time)).getUTCDate())),this.encode_time((new Date(this.rtc_time)).getUTCDate());case 8:return z(this.encode_time((new Date(this.rtc_time)).getUTCMonth()+1)),this.encode_time((new Date(this.rtc_time)).getUTCMonth()+1);case 9:return z(this.encode_time((new Date(this.rtc_time)).getUTCFullYear()%100)),this.encode_time((new Date(this.rtc_time)).getUTCFullYear()%100);case 10:return 999<=H.microtick()%
|
|
129
130
|
1E3?this.cmos_a|128:this.cmos_a;case 11:return this.cmos_b;case 12:return this.cpu.device_lower_irq(8),a=this.cmos_c,this.cmos_c&=-241,a;case 13:return 0;case 50:case 55:return z(this.encode_time((new Date(this.rtc_time)).getUTCFullYear()/100|0)),this.encode_time((new Date(this.rtc_time)).getUTCFullYear()/100|0);default:return z(a),this.cmos_data[this.cmos_index]}};
|
|
130
|
-
eb.prototype.cmos_port_write=function(a){switch(this.cmos_index){case 10:this.cmos_a=a&127;this.periodic_interrupt_time=1E3/(32768>>(this.cmos_a&15)-1);z(this.cmos_a,2);break;case 11:this.cmos_b=a;this.cmos_b&64&&(this.next_interrupt=Date.now());if(this.cmos_b&32){a=new Date;const b=this.decode_time(this.cmos_data[1]),c=this.decode_time(this.cmos_data[3]),d=this.decode_time(this.cmos_data[5]);this.next_interrupt_alarm=+new Date(Date.UTC(a.getUTCFullYear(),a.getUTCMonth(),
|
|
131
|
-
2);break;case 1:case 3:case 5:this.cmos_write(this.cmos_index,a);break;default:z(this.cmos_index),z(a)}this.periodic_interrupt=64===(this.cmos_b&64)&&0<(this.cmos_a&15)};eb.prototype.cmos_read=function(a){return this.cmos_data[a]};eb.prototype.cmos_write=function(a,b){z(a);z(b);this.cmos_data[a]=b};function fb(a,b){this.cpu=a;this.bus=b;this.counter_start_time=new Float64Array(3);this.counter_start_value=new Uint16Array(3);this.counter_next_low=new Uint8Array(4);this.counter_enabled=new Uint8Array(4);this.counter_mode=new Uint8Array(4);this.counter_read_mode=new Uint8Array(4);this.counter_latch=new Uint8Array(4);this.counter_latch_value=new Uint16Array(3);this.counter_reload=new Uint16Array(3);a.io.register_read(97,this,function(){var c=H.microtick(),d=66.66666666666667*c&1;c=this.did_rollover(2,
|
|
131
|
+
eb.prototype.cmos_port_write=function(a){switch(this.cmos_index){case 10:this.cmos_a=a&127;this.periodic_interrupt_time=1E3/(32768>>(this.cmos_a&15)-1);z(this.cmos_a,2);break;case 11:this.cmos_b=a;this.cmos_b&128&&(this.cmos_b&=239);this.cmos_b&64&&(this.next_interrupt=Date.now());if(this.cmos_b&32){a=new Date;const b=this.decode_time(this.cmos_data[1]),c=this.decode_time(this.cmos_data[3]),d=this.decode_time(this.cmos_data[5]);this.next_interrupt_alarm=+new Date(Date.UTC(a.getUTCFullYear(),a.getUTCMonth(),
|
|
132
|
+
a.getUTCDate(),d,c,b))}this.cmos_b&16&&(this.update_interrupt_time=Date.now());z(this.cmos_b,2);break;case 1:case 3:case 5:this.cmos_write(this.cmos_index,a);break;default:z(this.cmos_index),z(a)}this.update_interrupt=16===(this.cmos_b&16)&&0<(this.cmos_a&15);this.periodic_interrupt=64===(this.cmos_b&64)&&0<(this.cmos_a&15)};eb.prototype.cmos_read=function(a){return this.cmos_data[a]};eb.prototype.cmos_write=function(a,b){z(a);z(b);this.cmos_data[a]=b};function fb(a,b){this.cpu=a;this.bus=b;this.counter_start_time=new Float64Array(3);this.counter_start_value=new Uint16Array(3);this.counter_next_low=new Uint8Array(4);this.counter_enabled=new Uint8Array(4);this.counter_mode=new Uint8Array(4);this.counter_read_mode=new Uint8Array(4);this.counter_latch=new Uint8Array(4);this.counter_latch_value=new Uint16Array(3);this.counter_reload=new Uint16Array(3);a.io.register_read(97,this,function(){var c=H.microtick(),d=66.66666666666667*c&1;c=this.did_rollover(2,
|
|
132
133
|
c);return d<<4|c<<5});a.io.register_write(97,this,function(c){c&1?this.bus.send("pcspeaker-enable"):this.bus.send("pcspeaker-disable")});a.io.register_read(64,this,function(){return this.counter_read(0)});a.io.register_read(65,this,function(){return this.counter_read(1)});a.io.register_read(66,this,function(){return this.counter_read(2)});a.io.register_write(64,this,function(c){this.counter_write(0,c)});a.io.register_write(65,this,function(c){this.counter_write(1,c)});a.io.register_write(66,this,
|
|
133
134
|
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)}fb.prototype.get_state=function(){var a=[];a[0]=this.counter_next_low;a[1]=this.counter_enabled;a[2]=this.counter_mode;a[3]=this.counter_read_mode;a[4]=this.counter_latch;a[5]=this.counter_latch_value;a[6]=this.counter_reload;a[7]=this.counter_start_time;a[8]=this.counter_start_value;return a};
|
|
134
135
|
fb.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]};
|
package/build/libv86.mjs
CHANGED
|
@@ -108,117 +108,118 @@ p+=q}}else n=a.zstd_read(e,l+m.length),p=n+l,g.push(a.wasm_memory.buffer.slice(p
|
|
|
108
108
|
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===a)return"";c=new Uint32Array(256);b=new Uint32Array(256);for(const {opcode:n,
|
|
109
109
|
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 ${k} (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 ${k} (0f, in ${m}):\n`;for(k=0;256>k;k++)f+=(k&255).toString(16).padStart(2,"0")+":"+aa(Math.round(b[k]/m),d),f=15===k%16?f+"\n":
|
|
110
110
|
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 eb(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=
|
|
111
|
-
this.cmos_c=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)}eb.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]=
|
|
112
|
-
this.nmi_disabled;return a};eb.prototype.set_state=function(a){this.cmos_index=a[0];this.cmos_data=a[1];this.rtc_time=a[2];this.last_update=a[3];this.next_interrupt=a[4];this.next_interrupt_alarm=a[5];this.periodic_interrupt=a[6];this.periodic_interrupt_time=a[7];this.cmos_a=a[8];this.cmos_b=a[9];this.cmos_c=a[10];this.nmi_disabled=a[11]
|
|
113
|
-
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
|
|
114
|
-
0,c=0,d;a;)d=a%10,c|=d<<4*b,b++,a=(a-d)/10;return c};eb.prototype.bcd_unpack=function(a){return(a&15)+10*(a>>4&15)};eb.prototype.encode_time=
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
100
|
|
118
|
-
a.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
this.
|
|
125
|
-
this.
|
|
126
|
-
this.
|
|
127
|
-
this.
|
|
128
|
-
this.dac.
|
|
129
|
-
this.
|
|
130
|
-
this.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
function(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
this.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
this.source_offset=
|
|
142
|
-
this.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
this)
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
this.socket.
|
|
155
|
-
a.
|
|
156
|
-
a.length
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
m.
|
|
161
|
-
m.
|
|
162
|
-
|
|
163
|
-
n.
|
|
164
|
-
|
|
165
|
-
src
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
d?(d=new DataView(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
{sport:this.sport,dport:this.dport,
|
|
182
|
-
this.state="
|
|
183
|
-
a
|
|
184
|
-
|
|
185
|
-
{}
|
|
186
|
-
this.
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
this.
|
|
199
|
-
this.
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
1
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
111
|
+
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)}eb.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]=
|
|
112
|
+
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;return a};eb.prototype.set_state=function(a){this.cmos_index=a[0];this.cmos_data=a[1];this.rtc_time=a[2];this.last_update=a[3];this.next_interrupt=a[4];this.next_interrupt_alarm=a[5];this.periodic_interrupt=a[6];this.periodic_interrupt_time=a[7];this.cmos_a=a[8];this.cmos_b=a[9];this.cmos_c=a[10];this.nmi_disabled=a[11];this.update_interrupt=a[12]||!1;this.update_interrupt_time=
|
|
113
|
+
a[13]||0};eb.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|=160,this.next_interrupt_alarm=0):this.update_interrupt&&this.update_interrupt_time<a&&(this.cpu.device_raise_irq(8),
|
|
114
|
+
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};eb.prototype.bcd_pack=function(a){for(var b=0,c=0,d;a;)d=a%10,c|=d<<4*b,b++,a=(a-d)/10;return c};eb.prototype.bcd_unpack=function(a){return(a&15)+10*(a>>4&15)};eb.prototype.encode_time=
|
|
115
|
+
function(a){return this.cmos_b&4?a:this.bcd_pack(a)};eb.prototype.decode_time=function(a){return this.cmos_b&4?a:this.bcd_unpack(a)};eb.prototype.cmos_port_read=function(){var a=this.cmos_index;switch(a){case 0:return z(this.encode_time((new Date(this.rtc_time)).getUTCSeconds())),this.encode_time((new Date(this.rtc_time)).getUTCSeconds());case 2:return z(this.encode_time((new Date(this.rtc_time)).getUTCMinutes())),this.encode_time((new Date(this.rtc_time)).getUTCMinutes());case 4:return z(this.encode_time((new Date(this.rtc_time)).getUTCHours())),
|
|
116
|
+
this.encode_time((new Date(this.rtc_time)).getUTCHours());case 6:return z(this.encode_time((new Date(this.rtc_time)).getUTCDay()+1)),this.encode_time((new Date(this.rtc_time)).getUTCDay()+1);case 7:return z(this.encode_time((new Date(this.rtc_time)).getUTCDate())),this.encode_time((new Date(this.rtc_time)).getUTCDate());case 8:return z(this.encode_time((new Date(this.rtc_time)).getUTCMonth()+1)),this.encode_time((new Date(this.rtc_time)).getUTCMonth()+1);case 9:return z(this.encode_time((new Date(this.rtc_time)).getUTCFullYear()%
|
|
117
|
+
100)),this.encode_time((new Date(this.rtc_time)).getUTCFullYear()%100);case 10:return 999<=H.microtick()%1E3?this.cmos_a|128:this.cmos_a;case 11:return this.cmos_b;case 12:return this.cpu.device_lower_irq(8),a=this.cmos_c,this.cmos_c&=-241,a;case 13:return 0;case 50:case 55:return z(this.encode_time((new Date(this.rtc_time)).getUTCFullYear()/100|0)),this.encode_time((new Date(this.rtc_time)).getUTCFullYear()/100|0);default:return z(a),this.cmos_data[this.cmos_index]}};eb.prototype.cmos_port_write=
|
|
118
|
+
function(a){switch(this.cmos_index){case 10:this.cmos_a=a&127;this.periodic_interrupt_time=1E3/(32768>>(this.cmos_a&15)-1);z(this.cmos_a,2);break;case 11:this.cmos_b=a;this.cmos_b&128&&(this.cmos_b&=239);this.cmos_b&64&&(this.next_interrupt=Date.now());if(this.cmos_b&32){a=new Date;const b=this.decode_time(this.cmos_data[1]),c=this.decode_time(this.cmos_data[3]),d=this.decode_time(this.cmos_data[5]);this.next_interrupt_alarm=+new Date(Date.UTC(a.getUTCFullYear(),a.getUTCMonth(),a.getUTCDate(),d,c,
|
|
119
|
+
b))}this.cmos_b&16&&(this.update_interrupt_time=Date.now());z(this.cmos_b,2);break;case 1:case 3:case 5:this.cmos_write(this.cmos_index,a);break;default:z(this.cmos_index),z(a)}this.update_interrupt=16===(this.cmos_b&16)&&0<(this.cmos_a&15);this.periodic_interrupt=64===(this.cmos_b&64)&&0<(this.cmos_a&15)};eb.prototype.cmos_read=function(a){return this.cmos_data[a]};eb.prototype.cmos_write=function(a,b){z(a);z(b);this.cmos_data[a]=b};function fb(a,b){this.cpu=a;this.bus=b;this.counter_start_time=
|
|
120
|
+
new Float64Array(3);this.counter_start_value=new Uint16Array(3);this.counter_next_low=new Uint8Array(4);this.counter_enabled=new Uint8Array(4);this.counter_mode=new Uint8Array(4);this.counter_read_mode=new Uint8Array(4);this.counter_latch=new Uint8Array(4);this.counter_latch_value=new Uint16Array(3);this.counter_reload=new Uint16Array(3);a.io.register_read(97,this,function(){var c=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&
|
|
121
|
+
1?this.bus.send("pcspeaker-enable"):this.bus.send("pcspeaker-disable")});a.io.register_read(64,this,function(){return this.counter_read(0)});a.io.register_read(65,this,function(){return this.counter_read(1)});a.io.register_read(66,this,function(){return this.counter_read(2)});a.io.register_write(64,this,function(c){this.counter_write(0,c)});a.io.register_write(65,this,function(c){this.counter_write(1,c)});a.io.register_write(66,this,function(c){this.counter_write(2,c);this.bus.send("pcspeaker-update",
|
|
122
|
+
[this.counter_mode[2],this.counter_reload[2]])});a.io.register_write(67,this,this.port43_write)}fb.prototype.get_state=function(){var a=[];a[0]=this.counter_next_low;a[1]=this.counter_enabled;a[2]=this.counter_mode;a[3]=this.counter_read_mode;a[4]=this.counter_latch;a[5]=this.counter_latch_value;a[6]=this.counter_reload;a[7]=this.counter_start_time;a[8]=this.counter_start_value;return a};fb.prototype.set_state=function(a){this.counter_next_low=a[0];this.counter_enabled=a[1];this.counter_mode=a[2];
|
|
123
|
+
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]};fb.prototype.timer=function(a,b){var c=100;b||(this.counter_enabled[0]&&this.did_rollover(0,a)?(this.counter_start_value[0]=this.get_counter_value(0,a),this.counter_start_time[0]=a,this.cpu.device_lower_irq(0),this.cpu.device_raise_irq(0),0===this.counter_mode[0]&&(this.counter_enabled[0]=0)):this.cpu.device_lower_irq(0),this.counter_enabled[0]&&
|
|
124
|
+
(c=(this.counter_start_value[0]-Math.floor(1193.1816666*(a-this.counter_start_time[0])))/1193.1816666));return c};fb.prototype.get_counter_value=function(a,b){if(!this.counter_enabled[a])return 0;b=this.counter_start_value[a]-Math.floor(1193.1816666*(b-this.counter_start_time[a]));a=this.counter_reload[a];b>=a?b%=a:0>b&&(b=b%a+a);return b};fb.prototype.did_rollover=function(a,b){b-=this.counter_start_time[a];return 0>b?!0:this.counter_start_value[a]<Math.floor(1193.1816666*b)};fb.prototype.counter_read=
|
|
125
|
+
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};fb.prototype.counter_write=function(a,b){this.counter_reload[a]=this.counter_next_low[a]?this.counter_reload[a]&-256|b:this.counter_reload[a]&255|b<<8;3===this.counter_read_mode[a]&&this.counter_next_low[a]||(this.counter_reload[a]||
|
|
126
|
+
(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(),z(this.counter_reload[a]));3===this.counter_read_mode[a]&&(this.counter_next_low[a]^=1)};fb.prototype.port43_write=function(a){var b=a>>1&7,c=a>>6&3;a=a>>4&3;3!==c&&(0===a?(this.counter_latch[c]=2,b=this.get_counter_value(c,H.microtick()),this.counter_latch_value[c]=b?b-1:0):(6<=b&&(b&=-5),this.counter_next_low[c]=1===a?0:1,0===c&&this.cpu.device_lower_irq(0),
|
|
127
|
+
0!==b&&3!==b&&2!==b&&z(b),this.counter_mode[c]=b,this.counter_read_mode[c]=a,2===c&&this.bus.send("pcspeaker-update",[this.counter_mode[2],this.counter_reload[2]])))};fb.prototype.dump=function(){};function gb(a){if("undefined"!==typeof window)if(window.AudioContext||window.webkitAudioContext){var b=window.AudioWorklet?hb:ib;this.bus=a;this.audio_context=window.AudioContext?new AudioContext:new webkitAudioContext;this.mixer=new jb(a,this.audio_context);this.pcspeaker=new kb(a,this.audio_context,this.mixer);
|
|
128
|
+
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")}gb.prototype.destroy=function(){this.audio_context&&this.audio_context.close();this.audio_context=
|
|
129
|
+
null;this.dac&&this.dac.node_processor&&this.dac.node_processor.port.close();this.dac=null};function jb(a,b){function c(d){return function(e){d.gain.setValueAtTime(e,this.audio_context.currentTime)}}this.audio_context=b;this.sources=new Map;this.gain_right=this.gain_left=this.volume_right=this.volume_left=this.volume_both=1;this.node_treble_left=this.audio_context.createBiquadFilter();this.node_treble_right=this.audio_context.createBiquadFilter();this.node_treble_left.type="highshelf";this.node_treble_right.type=
|
|
130
|
+
"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,
|
|
131
|
+
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);
|
|
132
|
+
this.node_gain_right.connect(this.node_merger,0,1);this.node_merger.connect(this.audio_context.destination);a.register("mixer-connect",function(d){this.connect_source(d[0],d[1])},this);a.register("mixer-disconnect",function(d){this.disconnect_source(d[0],d[1])},this);a.register("mixer-volume",function(d){var e=d[0],f=d[1];d=Math.pow(10,d[2]/20);e=0===e?this:this.sources.get(e);void 0===e||e.set_volume(d,f)},this);a.register("mixer-gain-left",function(d){this.gain_left=Math.pow(10,d/20);this.update()},
|
|
133
|
+
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)}jb.prototype.add_source=function(a,b){a=new lb(this.audio_context,a,this.input_left,this.input_right);this.sources.has(b);this.sources.set(b,a);return a};
|
|
134
|
+
jb.prototype.connect_source=function(a,b){a=this.sources.get(a);void 0===a||a.connect(b)};jb.prototype.disconnect_source=function(a,b){a=this.sources.get(a);void 0===a||a.disconnect(b)};jb.prototype.set_volume=function(a,b){void 0===b&&(b=2);switch(b){case 0:this.volume_left=a;break;case 1:this.volume_right=a;break;case 2:this.volume_both=a;break;default:return}this.update()};jb.prototype.update=function(){var a=this.volume_both*this.volume_right*this.gain_right;this.node_gain_left.gain.setValueAtTime(this.volume_both*
|
|
135
|
+
this.volume_left*this.gain_left,this.audio_context.currentTime);this.node_gain_right.gain.setValueAtTime(a,this.audio_context.currentTime)};function lb(a,b,c,d){this.audio_context=a;this.connected_right=this.connected_left=!0;this.volume_right=this.volume_left=this.volume_both=this.gain_hidden=1;this.node_splitter=a.createChannelSplitter(2);this.node_gain_left=a.createGain();this.node_gain_right=a.createGain();b.connect(this.node_splitter);this.node_splitter.connect(this.node_gain_left,0);this.node_gain_left.connect(c);
|
|
136
|
+
this.node_splitter.connect(this.node_gain_right,1);this.node_gain_right.connect(d)}lb.prototype.update=function(){var a=this.connected_right*this.gain_hidden*this.volume_both*this.volume_right;this.node_gain_left.gain.setValueAtTime(this.connected_left*this.gain_hidden*this.volume_both*this.volume_left,this.audio_context.currentTime);this.node_gain_right.gain.setValueAtTime(a,this.audio_context.currentTime)};lb.prototype.connect=function(a){var b=!a||2===a;if(b||0===a)this.connected_left=!0;if(b||
|
|
137
|
+
1===a)this.connected_right=!0;this.update()};lb.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()};lb.prototype.set_volume=function(a,b){void 0===b&&(b=2);switch(b){case 0:this.volume_left=a;break;case 1:this.volume_right=a;break;case 2:this.volume_both=a;break;default:return}this.update()};lb.prototype.set_gain_hidden=function(a){this.gain_hidden=a};function kb(a,b,c){this.node_oscillator=b.createOscillator();this.node_oscillator.type=
|
|
138
|
+
"square";this.node_oscillator.frequency.setValueAtTime(440,b.currentTime);this.mixer_connection=c.add_source(this.node_oscillator,1);this.mixer_connection.disconnect();a.register("pcspeaker-enable",function(){c.connect_source(1)},this);a.register("pcspeaker-disable",function(){c.disconnect_source(1)},this);a.register("pcspeaker-update",function(d){var e=d[1],f=0;3===d[0]&&(f=Math.min(1193181.6665999999/e,this.node_oscillator.frequency.maxValue),f=Math.max(f,0));this.node_oscillator.frequency.setValueAtTime(f,
|
|
139
|
+
b.currentTime)},this)}kb.prototype.start=function(){this.node_oscillator.start()};function hb(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=48E3;b=function(){function g(m){if(0===m)return 1;m*=Math.PI;return Math.sin(m)/m}function k(){var m=Reflect.construct(AudioWorkletProcessor,[],k);m.kernel_size=3;m.queue_data=Array(1024);m.queue_start=0;m.queue_end=0;m.queue_length=0;m.queue_size=m.queue_data.length;m.queued_samples=0;m.source_buffer_previous=l;m.source_buffer_current=
|
|
140
|
+
l;m.source_samples_per_destination=1;m.source_block_start=0;m.source_time=0;m.source_offset=0;m.port.onmessage=n=>{switch(n.data.type){case "queue":m.queue_push(n.data.value);break;case "sampling-rate":m.source_samples_per_destination=n.data.value/sampleRate}};return m}var l=[new Float32Array(256),new Float32Array(256)];Reflect.setPrototypeOf(k.prototype,AudioWorkletProcessor.prototype);Reflect.setPrototypeOf(k,AudioWorkletProcessor);k.prototype.process=k.prototype.process=function(m,n){for(m=0;m<
|
|
141
|
+
n[0][0].length;m++){for(var p=0,q=0,r=this.source_offset+this.kernel_size,y=this.source_offset-this.kernel_size+1;y<=r;y++){var x=this.source_block_start+y;p+=this.get_sample(x,0)*this.kernel(this.source_time-y);q+=this.get_sample(x,1)*this.kernel(this.source_time-y)}if(isNaN(p)||isNaN(q))p=q=0,this.dbg_log("ERROR: NaN values! Ignoring for now.");n[0][0][m]=p;n[0][1][m]=q;this.source_time+=this.source_samples_per_destination;this.source_offset=Math.floor(this.source_time)}n=this.source_offset;n+=
|
|
142
|
+
this.kernel_size+2;this.source_time-=this.source_offset;this.source_block_start+=this.source_offset;this.source_offset=0;this.ensure_enough_data(n);return!0};k.prototype.kernel=function(m){return g(m)*g(m/this.kernel_size)};k.prototype.get_sample=function(m,n){return 0>m?(m+=this.source_buffer_previous[0].length,this.source_buffer_previous[n][m]):this.source_buffer_current[n][m]};k.prototype.ensure_enough_data=function(m){var n=this.source_buffer_current[0].length;n-this.source_block_start<m&&(this.prepare_next_buffer(),
|
|
143
|
+
this.source_block_start-=n)};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");this.source_buffer_previous=this.source_buffer_current;this.source_buffer_current=this.queue_shift();var m=this.source_buffer_current[0].length;if(256>m){for(var n=this.queue_start,p=0;256>m&&p<this.queue_length;)m+=this.queue_data[n][0].length,n=n+1&this.queue_size-1,p++;m=Math.max(m,256);m=[new Float32Array(m),
|
|
144
|
+
new Float32Array(m)];m[0].set(this.source_buffer_current[0]);m[1].set(this.source_buffer_current[1]);n=this.source_buffer_current[0].length;for(var q=0;q<p;q++){var r=this.queue_shift();m[0].set(r[0],n);m[1].set(r[1],n);n+=r[0].length}this.source_buffer_current=m}this.pump()};k.prototype.pump=function(){1024>this.queued_samples/this.source_samples_per_destination&&this.port.postMessage({type:"pump"})};k.prototype.queue_push=function(m){this.queue_length<this.queue_size&&(this.queue_data[this.queue_end]=
|
|
145
|
+
m,this.queue_end=this.queue_end+1&this.queue_size-1,this.queue_length++,this.queued_samples+=m[0].length,this.pump())};k.prototype.queue_shift=function(){if(!this.queue_length)return l;var m=this.queue_data[this.queue_start];this.queue_data[this.queue_start]=null;this.queue_start=this.queue_start+1&this.queue_size-1;this.queue_length--;this.queued_samples-=m[0].length;return m};k.prototype.dbg_log=function(){};registerProcessor("dac-processor",k)}.toString();var d=b.indexOf("{")+1,e=b.lastIndexOf("}");
|
|
146
|
+
b=b.substring(d,e);b=new Blob([b],{type:"application/javascript"});var f=URL.createObjectURL(b);this.node_processor=null;this.node_output=this.audio_context.createGain();this.audio_context.audioWorklet.addModule(f).then(()=>{URL.revokeObjectURL(f);this.node_processor=new AudioWorkletNode(this.audio_context,"dac-processor",{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[2],parameterData:{},processorOptions:{}});this.node_processor.port.postMessage({type:"sampling-rate",value:this.sampling_rate});
|
|
147
|
+
this.node_processor.port.onmessage=g=>{switch(g.data.type){case "pump":this.pump()}};this.node_processor.connect(this.node_output)});this.mixer_connection=c.add_source(this.node_output,2);this.mixer_connection.set_gain_hidden(3);a.register("dac-send-data",function(g){this.queue(g)},this);a.register("dac-enable",function(){this.enabled=!0},this);a.register("dac-disable",function(){this.enabled=!1},this);a.register("dac-tell-sampling-rate",function(g){this.sampling_rate=g;this.node_processor&&this.node_processor.port.postMessage({type:"sampling-rate",
|
|
148
|
+
value:g})},this)}hb.prototype.queue=function(a){this.node_processor&&this.node_processor.port.postMessage({type:"queue",value:a},[a[0].buffer,a[1].buffer])};hb.prototype.pump=function(){this.enabled&&this.bus.send("dac-request-data")};function ib(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=22050;this.buffered_time=0;this.rate_ratio=1;this.node_lowpass=this.audio_context.createBiquadFilter();this.node_lowpass.type="lowpass";this.node_output=this.node_lowpass;this.mixer_connection=
|
|
149
|
+
c.add_source(this.node_output,2);this.mixer_connection.set_gain_hidden(3);a.register("dac-send-data",function(d){this.queue(d)},this);a.register("dac-enable",function(){this.enabled=!0;this.pump()},this);a.register("dac-disable",function(){this.enabled=!1},this);a.register("dac-tell-sampling-rate",function(d){this.sampling_rate=d;this.rate_ratio=Math.ceil(8E3/d);this.node_lowpass.frequency.setValueAtTime(d/2,this.audio_context.currentTime)},this)}ib.prototype.queue=function(a){var b=a[0].length,c=
|
|
150
|
+
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 l=0;l<this.rate_ratio;l++,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],0),d.copyToChannel(a[1],1)):(d.getChannelData(0).set(a[0]),d.getChannelData(1).set(a[1]));a=this.audio_context.createBufferSource();
|
|
151
|
+
a.buffer=d;a.connect(this.node_lowpass);a.addEventListener("ended",this.pump.bind(this));d=this.audio_context.currentTime;if(this.buffered_time<d)for(this.buffered_time=d,d=.2-c,b=0;b<=d;)b+=c,this.buffered_time+=c,setTimeout(()=>this.pump(),1E3*b);a.start(this.buffered_time);this.buffered_time+=c;setTimeout(()=>this.pump(),0)};ib.prototype.pump=function(){this.enabled&&(.2<this.buffered_time-this.audio_context.currentTime||this.bus.send("dac-request-data"))};function rb(a,b,c){this.bus=b;this.socket=
|
|
152
|
+
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)}rb.prototype.handle_message=function(a){this.bus&&this.bus.send("net"+this.id+"-receive",new Uint8Array(a.data))};rb.prototype.handle_close=function(){this.destroyed||(this.connect(),setTimeout(this.connect.bind(this),this.reconnect_interval))};rb.prototype.handle_open=
|
|
153
|
+
function(){for(var a=0;a<this.send_queue.length;a++)this.send(this.send_queue[a]);this.send_queue=[]};rb.prototype.handle_error=function(){};rb.prototype.destroy=function(){this.destroyed=!0;this.socket&&this.socket.close()};rb.prototype.connect=function(){if("undefined"!==typeof WebSocket){if(this.socket){var a=this.socket.readyState;if(0===a||1===a)return}a=Date.now();if(!(this.last_connect_attempt+this.reconnect_interval>a)){this.last_connect_attempt=Date.now();try{this.socket=new WebSocket(this.url)}catch(b){console.error(b);
|
|
154
|
+
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)}}};rb.prototype.send=function(a){this.socket&&1===this.socket.readyState?this.socket.send(a):(this.send_queue.push(a),this.send_queue.length>2*this.send_queue_limit&&(this.send_queue=this.send_queue.slice(-this.send_queue_limit)),this.connect())};rb.prototype.change_proxy=
|
|
155
|
+
function(a){this.url=a;this.socket&&(this.socket.onclose=function(){},this.socket.onerror=function(){},this.socket.close(),this.socket=void 0)};const sb=(new Date("1970-01-01T00:00:00Z")).getTime(),tb=(new Date("1900-01-01T00:00:00Z")).getTime(),ub=sb-tb,vb=Math.pow(2,32),wb=[118,56,54];function xb(a){return[0,1,2,3,4,5].map(b=>a[b].toString(16)).map(b=>1===b.length?"0"+b:b).join(":")}function yb(a){return a[0]<<24|a[1]<<16|a[2]<<8|a[3]}class zb{constructor(a,b){a=Math.min(a,16);this.maximum_capacity=
|
|
156
|
+
b?Math.max(b,a):0;this.length=this.head=this.tail=0;this.buffer=new Uint8Array(a)}write(a){const b=a.length;var c=this.length+b;let d=this.buffer.length;if(d<c){for(;d<c;)d*=2;if(this.maximum_capacity&&d>this.maximum_capacity)throw Error("stream capacity overflow in GrowableRingbuffer.write(), package dropped");c=new Uint8Array(d);this.peek(c);this.tail=0;this.head=this.length;this.buffer=c}c=this.buffer;const e=this.head+b;if(e>d){const f=d-this.head;c.set(a.subarray(0,f),this.head);c.set(a.subarray(f))}else c.set(a,
|
|
157
|
+
this.head);this.head=e%d;this.length+=b}peek(a){const b=Math.min(this.length,a.length);if(b){const e=this.buffer;var c=e.length,d=this.tail+b;d>c?(d%=c,c-=this.tail,a.set(e.subarray(this.tail)),a.set(e.subarray(0,d),c)):a.set(e.subarray(this.tail,d))}return b}remove(a){a>this.length&&(a=this.length);a&&(this.tail=(this.tail+a)%this.buffer.length,this.length-=a);return a}}function Jb(){const a=new Uint8Array(1518),b=a.buffer,c=a.byteOffset;return{eth_frame:a,eth_frame_view:new DataView(b),eth_payload_view:new DataView(b,
|
|
158
|
+
c+14,1500),ipv4_payload_view:new DataView(b,c+34,1480),udp_payload_view:new DataView(b,c+42,1472),text_encoder:new TextEncoder}}function Kb(a,b,c,d){d.eth_frame.set(b,c.byteOffset+a);return b.length}function Lb(a,b,c,d){const e=c.byteOffset+(a&-2);d=d.eth_frame;for(c=c.byteOffset;c<e;c+=2)b+=d[c]<<8|d[c+1];for(a&1&&(b+=d[e]<<8);b>>>16;)b=(b&65535)+(b>>>16);return~b&65535}function J(a,b){a.eth_frame.fill(0);var c=a.eth_frame,d=c.subarray,e=a.eth_frame_view;Kb(0,b.eth.dest,e,a);Kb(6,b.eth.src,e,a);
|
|
159
|
+
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);Kb(8,b.arp.sha,f,a);Kb(14,b.arp.spa,f,a);Kb(18,b.arp.tha,f,a);Kb(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 l=4+Kb(4,b.icmp.data,k,a);k.setUint16(2,Lb(l,
|
|
160
|
+
0,k,a));g+=l}else if(b.udp){k=a.ipv4_payload_view;var m=8;if(b.dhcp){l=m;var n=a.udp_payload_view;n.setUint8(0,b.dhcp.op);n.setUint8(1,b.dhcp.htype);n.setUint8(2,b.dhcp.hlen);n.setUint8(3,b.dhcp.hops);n.setUint32(4,b.dhcp.xid);n.setUint16(8,b.dhcp.secs);n.setUint16(10,b.dhcp.flags);n.setUint32(12,b.dhcp.ciaddr);n.setUint32(16,b.dhcp.yiaddr);n.setUint32(20,b.dhcp.siaddr);n.setUint32(24,b.dhcp.giaddr);Kb(28,b.dhcp.chaddr,n,a);n.setUint32(236,1669485411);m=240;for(var p of b.dhcp.options)m+=Kb(m,p,n,
|
|
161
|
+
a);l+=m}else if(b.dns){p=m;m=a.udp_payload_view;m.setUint16(0,b.dns.id);m.setUint16(2,b.dns.flags);m.setUint16(4,b.dns.questions.length);m.setUint16(6,b.dns.answers.length);let y=12;for(var q=0;q<b.dns.questions.length;++q){var r=b.dns.questions[q];for(n of r.name){const x=a.text_encoder.encodeInto(n,a.eth_frame.subarray(m.byteOffset+(y+1))).written;m.setUint8(y,x);y+=1+x}m.setUint16(y,r.type);y+=2;m.setUint16(y,r.class);y+=2}for(q=0;q<b.dns.answers.length;++q){n=b.dns.answers[q];for(l of n.name)r=
|
|
162
|
+
a.text_encoder.encodeInto(l,a.eth_frame.subarray(m.byteOffset+(y+1))).written,m.setUint8(y,r),y+=1+r;m.setUint16(y,n.type);y+=2;m.setUint16(y,n.class);y+=2;m.setUint32(y,n.ttl);y+=4;m.setUint16(y,n.data.length);y+=2;y+=Kb(y,n.data,m,a)}l=p+y}else b.ntp?(l=m,n=a.udp_payload_view,n.setUint8(0,b.ntp.flags),n.setUint8(1,b.ntp.stratum),n.setUint8(2,b.ntp.poll),n.setUint8(3,b.ntp.precision),n.setUint32(4,b.ntp.root_delay),n.setUint32(8,b.ntp.root_disp),n.setUint32(12,b.ntp.ref_id),n.setUint32(16,b.ntp.ref_ts_i),
|
|
163
|
+
n.setUint32(20,b.ntp.ref_ts_f),n.setUint32(24,b.ntp.ori_ts_i),n.setUint32(28,b.ntp.ori_ts_f),n.setUint32(32,b.ntp.rec_ts_i),n.setUint32(36,b.ntp.rec_ts_f),n.setUint32(40,b.ntp.trans_ts_i),n.setUint32(44,b.ntp.trans_ts_f),l+=48):l=m+Kb(0,b.udp.data,a.udp_payload_view,a);m=l;k.setUint16(0,b.udp.sport);k.setUint16(2,b.udp.dport);k.setUint16(4,m);k.setUint16(6,0);k.setUint16(6,Lb(m,(b.ipv4.src[0]<<8|b.ipv4.src[1])+(b.ipv4.src[2]<<8|b.ipv4.src[3])+(b.ipv4.dest[0]<<8|b.ipv4.dest[1])+(b.ipv4.dest[2]<<8|
|
|
164
|
+
b.ipv4.dest[3])+17+m,k,a));g+=m}else b.tcp&&(k=a.ipv4_payload_view,l=0,n=b.tcp,n.fin&&(l|=1),n.syn&&(l|=2),n.rst&&(l|=4),n.psh&&(l|=8),n.ack&&(l|=16),n.urg&&(l|=32),n.ece&&(l|=64),n.cwr&&(l|=128),k.setUint16(0,n.sport),k.setUint16(2,n.dport),k.setUint32(4,n.seq),k.setUint32(8,n.ackn),k.setUint8(12,80),k.setUint8(13,l),k.setUint16(14,n.winsize),k.setUint16(16,0),k.setUint16(18,n.urgent||0),l=20,b.tcp_data&&(l+=Kb(20,b.tcp_data,k,a)),k.setUint16(16,Lb(l,(b.ipv4.src[0]<<8|b.ipv4.src[1])+(b.ipv4.src[2]<<
|
|
165
|
+
8|b.ipv4.src[3])+(b.ipv4.dest[0]<<8|b.ipv4.dest[1])+(b.ipv4.dest[2]<<8|b.ipv4.dest[3])+6+l,k,a)),g+=l);f.setUint8(0,69);f.setUint8(1,b.ipv4.tos||0);f.setUint16(2,g);f.setUint16(4,b.ipv4.id||0);f.setUint8(6,64);f.setUint8(8,b.ipv4.ttl||32);f.setUint8(9,b.ipv4.proto);f.setUint16(10,0);Kb(12,b.ipv4.src,f,a);Kb(16,b.ipv4.dest,f,a);f.setUint16(10,Lb(20,0,f,a));e+=g}return d.call(c,0,e)}function Mb(a,b){fetch(`https://${b.doh_server||"cloudflare-dns.com"}/dns-query`,{method:"POST",headers:[["content-type",
|
|
166
|
+
"application/dns-message"]],body:a.udp.data}).then(async c=>{c={eth:{ethertype:2048,src:b.router_mac,dest:a.eth.src},ipv4:{proto:17,src:b.router_ip,dest:a.ipv4.src},udp:{sport:53,dport:a.udp.sport,data:new Uint8Array(await c.arrayBuffer())}};b.receive(J(b.eth_encoder_buf,c))});return!0}function Nb(a,b){let c={};c.eth={ethertype:2048,src:b.router_mac,dest:a.eth.src};c.ipv4={proto:17,src:b.router_ip,dest:b.vm_ip};c.udp={sport:67,dport:68};c.dhcp={htype:1,hlen:6,hops:0,xid:a.dhcp.xid,secs:0,flags:0,
|
|
167
|
+
ciaddr:0,yiaddr:yb(b.vm_ip),siaddr:yb(b.router_ip),giaddr:yb(b.router_ip),chaddr:a.dhcp.chaddr};let d=[],e=a.dhcp.options.find(function(f){return 53===f[0]});e&&3===e[2]&&(a.dhcp.op=3);1===a.dhcp.op&&(c.dhcp.op=2,d.push(new Uint8Array([53,1,2])));3===a.dhcp.op&&(c.dhcp.op=2,d.push(new Uint8Array([53,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))),
|
|
168
|
+
d.push(new Uint8Array([6,4].concat(a))));d.push(new Uint8Array([54,4].concat(a)));d.push(new Uint8Array([60,3].concat(wb)));d.push(new Uint8Array([255,0]));c.dhcp.options=d;b.receive(J(b.eth_encoder_buf,c))}function Ob(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:xb(a.subarray(0,6)),src:a.subarray(6,12),src_s:xb(a.subarray(6,12))};c.eth=e;a=a.subarray(14,a.length);if(2048===d){var f=new DataView(a.buffer,a.byteOffset,
|
|
169
|
+
a.byteLength),g=a[0]>>4&15;e=a[0]&15;var k=f.getUint8(1),l=f.getUint16(2);let m=f.getUint8(8);d=f.getUint8(9);f=f.getUint16(10);g={version:g,ihl:e,tos:k,len:l,ttl:m,proto:d,ip_checksum:f,src:a.subarray(12,16),dest:a.subarray(16,20)};c.ipv4=g;e=a.subarray(4*e,l);if(1===d)a=new DataView(e.buffer,e.byteOffset,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),
|
|
170
|
+
dport:d.getUint16(2),seq:d.getUint32(4),ackn:d.getUint32(8),doff:d.getUint8(12)>>4,winsize:d.getUint16(14),checksum:d.getUint16(16),urgent:d.getUint16(18)},d=d.getUint8(13),a.fin=!!(d&1),a.syn=!!(d&2),a.rst=!!(d&4),a.psh=!!(d&8),a.ack=!!(d&16),a.urg=!!(d&32),a.ece=!!(d&64),a.cwr=!!(d&128),c.tcp=a,c.tcp_data=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),
|
|
171
|
+
data_s:(new TextDecoder).decode(e.subarray(8))};if(67===a.dport||67===a.sport){e=e.subarray(8);d=new DataView(e.buffer,e.byteOffset,e.byteLength);e.subarray(44,236);d={op:d.getUint8(0),htype:d.getUint8(1),hlen:d.getUint8(2),hops:d.getUint8(3),xid:d.getUint32(4),secs:d.getUint16(8),flags:d.getUint16(10),ciaddr:d.getUint32(12),yiaddr:d.getUint32(16),siaddr:d.getUint32(20),giaddr:d.getUint32(24),chaddr:e.subarray(28,44),magic:d.getUint32(236),options:[]};e=e.subarray(240);for(l=0;l<e.length;++l)g=l,
|
|
172
|
+
0!==e[l]&&(++l,k=e[l],l+=k,d.options.push(e.subarray(g,g+k+2)));c.dhcp=d;c.dhcp_options=d.options}else 53===a.dport||53===a.sport?Pb(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),
|
|
173
|
+
rec_ts_f:d.getUint32(36),trans_ts_i:d.getUint32(40),trans_ts_f:d.getUint32(44)});c.udp=a}}else 2054===d?(d=new DataView(a.buffer,a.byteOffset,a.byteLength),a={htype:d.getUint16(0),ptype:d.getUint16(2),oper:d.getUint16(6),sha:a.subarray(8,14),spa:a.subarray(14,18),tha:a.subarray(18,24),tpa:a.subarray(24,28)},c.arp=a):34525!==d&&z(d);if(c.ipv4)if(c.tcp){if(a=`${c.ipv4.src.join(".")}:${c.tcp.sport}:${c.ipv4.dest.join(".")}:${c.tcp.dport}`,!c.tcp.syn||!b.on_tcp_connection(c,a))if(b.tcp_conn[a])b.tcp_conn[a].process(c);
|
|
174
|
+
else{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(J(b.eth_encoder_buf,d))}}else if(c.udp)if(c.dns)if("static"===b.dns_method){a={};a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src};a.ipv4={proto:17,src:b.router_ip,dest:c.ipv4.src};a.udp={sport:53,dport:c.udp.sport};
|
|
175
|
+
d=[];for(e=0;e<c.dns.questions.length;++e)switch(l=c.dns.questions[e],l.type){case 1:d.push({name:l.name,type:l.type,class:l.class,ttl:600,data:[192,168,87,1]})}a.dns={id:c.dns.id,flags:33152,questions:c.dns.questions,answers:d};b.receive(J(b.eth_encoder_buf,a))}else Mb(c,b);else c.dhcp?Nb(c,b):c.ntp?(a=Date.now()+ub,d=a%1E3/1E3*vb,e={},e.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},e.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},e.udp={sport:123,dport:c.udp.sport},e.ntp=Object.assign({},
|
|
176
|
+
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(J(b.eth_encoder_buf,e))):8===c.udp.dport&&(a={},a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},a.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},a.udp={sport:c.udp.dport,dport:c.udp.sport,data:(new TextEncoder).encode(c.udp.data_s)},b.receive(J(b.eth_encoder_buf,a)));else c.icmp&&8===c.icmp.type&&
|
|
177
|
+
(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(J(b.eth_encoder_buf,a)));else c.arp&&1===c.arp.oper&&2048===c.arp.ptype&&(a=yb(c.arp.tpa)&4294967040,d=yb(b.router_ip)&4294967040,!b.masquerade&&a!==d||a===d&&99<c.arp.tpa[3]||(a={},a.eth={ethertype:2054,src:b.router_mac,dest:c.eth.src},a.arp={htype:1,ptype:2048,oper:2,sha:b.router_mac,spa:c.arp.tpa,tha:c.eth.src,tpa:c.arp.spa},b.receive(J(b.eth_encoder_buf,
|
|
178
|
+
a))))}function Pb(a,b){function c(){let m=[],n;do n=d.getUint8(k),m.push((new TextDecoder).decode(a.subarray(k+1,k+1+n))),k+=n+1;while(0<n);return m}let d=new DataView(a.buffer,a.byteOffset,a.byteLength),e={id:d.getUint16(0),flags:d.getUint16(2),questions:[],answers:[]};var f=d.getUint16(4);let g=d.getUint16(6);d.getUint16(8);d.getUint16(10);let k=12;for(var l=0;l<f;l++)e.questions.push({name:c(),type:d.getInt16(k),class:d.getInt16(k+2)}),k+=4;for(f=0;f<g;f++){l={name:c(),type:d.getInt16(k),class:d.getUint16(k+
|
|
179
|
+
2),ttl:d.getUint32(k+4)};k+=8;let m=d.getUint16(k);k+=2;l.data=a.subarray(k,k+m);k+=m;e.answers.push(l)}b.dns=e}function Qb(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");c=new Rb;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;
|
|
180
|
+
c.net=b;b.tcp_conn[g]=c;c.connect();return c}function Sb(a,b){return new Promise(c=>{let d=Qb(a,b);d.state="syn-probe";d.on("probe",c)})}function Rb(){this.state="closed";this.net=null;this.send_buffer=new zb(2048,0);this.send_chunk_buf=new Uint8Array(1460);this.delayed_send_fin=this.in_active_close=!1;this.delayed_state=void 0;this.events_handlers={}}Rb.prototype.on=function(a,b){this.events_handlers[a]=b};Rb.prototype.emit=function(a,...b){this.events_handlers[a]&&this.events_handlers[a].apply(this,
|
|
181
|
+
b)};Rb.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};Rb.prototype.packet_reply=function(a,b){a={sport:a.tcp.dport,dport:a.tcp.sport,winsize:a.tcp.winsize,ackn:this.ack,seq:this.seq};if(b)for(const c in b)a[c]=b[c];b=this.ipv4_reply();b.tcp=a;return b};Rb.prototype.connect=function(){this.seq=1338;this.ack=
|
|
182
|
+
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(J(this.net.eth_encoder_buf,a))};Rb.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;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();
|
|
183
|
+
b.tcp={sport:this.sport,dport:this.dport,seq:1337,ackn:this.ack,winsize:a.tcp.winsize,syn:!0,ack:!0};this.state="established";this.net.receive(J(this.net.eth_encoder_buf,b))};Rb.prototype.process=function(a){if("closed"===this.state)a=this.packet_reply(a,{rst:!0}),this.net.receive(J(this.net.eth_encoder_buf,a));else if(a.tcp.rst){if("syn-probe"===this.state)this.emit("probe",!1);else this.on_close();this.release()}else if(a.tcp.syn)"syn-sent"===this.state&&a.tcp.ack?(this.ack=a.tcp.seq+1,this.start_seq=
|
|
184
|
+
a.tcp.seq,this.last_received_ackn=a.tcp.ackn,a=this.ipv4_reply(),this.net.receive(J(this.net.eth_encoder_buf,a)),this.state="established",this.emit("connect")):"syn-probe"===this.state&&a.tcp.ack&&(this.emit("probe",!0),a=this.packet_reply(a,{rst:!0}),this.net.receive(J(this.net.eth_encoder_buf,a)),this.release());else{if(a.tcp.ack)if("syn-received"===this.state)this.state="established";else if("fin-wait-1"===this.state)a.tcp.fin||(this.state="fin-wait-2");else if("closing"===this.state||"last-ack"===
|
|
185
|
+
this.state){this.release();return}if(void 0===this.last_received_ackn)this.last_received_ackn=a.tcp.ackn;else{var b=a.tcp.ackn-this.last_received_ackn;if(0<b){if(this.last_received_ackn=a.tcp.ackn,this.send_buffer.remove(b),this.seq+=b,this.pending=!1,this.delayed_send_fin&&!this.send_buffer.length){this.delayed_send_fin=!1;this.state=this.delayed_state;a=this.ipv4_reply();a.tcp.fin=!0;this.net.receive(J(this.net.eth_encoder_buf,a));return}}else if(0>b){a=this.packet_reply(a,{rst:!0});this.net.receive(J(this.net.eth_encoder_buf,
|
|
186
|
+
a));this.on_close();this.release();return}}a.tcp.fin?(++this.ack,b=this.packet_reply(a,{}),"established"===this.state?(b.tcp.ack=!0,this.state="close-wait",this.on_shutdown()):"fin-wait-1"===this.state?(a.tcp.ack?this.release():this.state="closing",b.tcp.ack=!0):"fin-wait-2"===this.state?(this.release(),b.tcp.ack=!0):(this.release(),this.on_close(),b.tcp.rst=!0),this.net.receive(J(this.net.eth_encoder_buf,b))):this.ack!==a.tcp.seq?(a=this.packet_reply(a,{ack:!0}),this.net.receive(J(this.net.eth_encoder_buf,
|
|
187
|
+
a))):a.tcp.ack&&0<a.tcp_data.length&&(this.ack+=a.tcp_data.length,b=this.ipv4_reply(),this.net.receive(J(this.net.eth_encoder_buf,b)),this.emit("data",a.tcp_data));this.pump()}};Rb.prototype.write=function(a){this.in_active_close||this.send_buffer.write(a);this.pump()};Rb.prototype.writev=function(a){if(!this.in_active_close)for(const b of a)this.send_buffer.write(b);this.pump()};Rb.prototype.close=function(){if(!this.in_active_close){this.in_active_close=!0;if("established"===this.state||"syn-received"===
|
|
188
|
+
this.state)var a="fin-wait-1";else if("close-wait"===this.state)a="last-ack";else{this.release();return}this.send_buffer.length||this.pending?(this.delayed_send_fin=!0,this.delayed_state=a):(this.state=a,a=this.ipv4_reply(),a.tcp.fin=!0,this.net.receive(J(this.net.eth_encoder_buf,a)))}this.pump()};Rb.prototype.on_shutdown=function(){this.emit("shutdown")};Rb.prototype.on_close=function(){this.emit("close")};Rb.prototype.release=function(){this.net.tcp_conn[this.tuple]&&(this.state="closed",delete this.net.tcp_conn[this.tuple])};
|
|
189
|
+
Rb.prototype.pump=function(){if(this.send_buffer.length&&!this.pending){const a=this.send_chunk_buf,b=this.send_buffer.peek(a),c=this.ipv4_reply();c.tcp.psh=!0;c.tcp_data=a.subarray(0,b);this.net.receive(J(this.net.eth_encoder_buf,c));this.pending=!0}};function Tb(a,b){b=b||{};this.bus=a;this.id=b.id||0;this.router_mac=new Uint8Array((b.router_mac||"52:54:0:1:2:3").split(":").map(function(c){return parseInt(c,16)}));this.router_ip=new Uint8Array((b.router_ip||"192.168.86.1").split(".").map(function(c){return parseInt(c,
|
|
190
|
+
10)}));this.vm_ip=new Uint8Array((b.vm_ip||"192.168.86.100").split(".").map(function(c){return parseInt(c,10)}));this.masquerade=void 0===b.masquerade||!!b.masquerade;this.vm_mac=new Uint8Array(6);this.dns_method=b.dns_method||"static";this.doh_server=b.doh_server;this.tcp_conn={};this.eth_encoder_buf=Jb();this.fetch=(...c)=>fetch(...c);this.cors_proxy=b.cors_proxy;this.bus.register("net"+this.id+"-mac",function(c){this.vm_mac=new Uint8Array(c.split(":").map(function(d){return parseInt(d,16)}))},
|
|
191
|
+
this);this.bus.register("net"+this.id+"-send",function(c){this.send(c)},this)}Tb.prototype.destroy=function(){};Tb.prototype.on_tcp_connection=function(a,b){if(80===a.tcp.dport){let c=new Rb;c.state="syn-received";c.net=this;c.on("data",$b);c.tuple=b;c.accept(a);this.tcp_conn[b]=c;return!0}return!1};Tb.prototype.connect=function(a){return Qb(a,this)};Tb.prototype.tcp_probe=function(a){return Sb(a,this)};async function $b(a){this.read=this.read||"";if((this.read+=(new TextDecoder).decode(a))&&-1!==
|
|
192
|
+
this.read.indexOf("\r\n\r\n")){a=this.read.indexOf("\r\n\r\n");var b=this.read.substring(0,a).split(/\r\n/);a=this.read.substring(a+4);this.read="";let c=b[0].split(" "),d;d=/^https?:/.test(c[1])?new URL(c[1]):new URL("http://host"+c[1]);"undefined"!==typeof window&&"http:"===d.protocol&&"https:"===window.location.protocol&&(d.protocol="https:");let e=new Headers;for(let k=1;k<b.length;++k){const l=this.net.parse_http_header(b[k]);if(!l){console.warn('The request contains an invalid header: "%s"',
|
|
193
|
+
b[k]);this.net.respond_text_and_close(this,400,"Bad Request",`Invalid header in request: ${b[k]}`);return}"host"===l.key.toLowerCase()?d.host=l.value:e.append(l.key,l.value)}if(!this.net.cors_proxy&&/^\d+\.external$/.test(d.hostname))if(b=parseInt(d.hostname.split(".")[0],10),!isNaN(b)&&0<b&&65536>b)d.protocol="http:",d.hostname="localhost",d.port=b.toString(10);else{console.warn('Unknown port for localhost: "%s"',d.href);this.net.respond_text_and_close(this,400,"Bad Request",`Unknown port for localhost: ${d.href}`);
|
|
194
|
+
return}this.name=d.href;b={method:c[0],headers:e};-1!==["put","post"].indexOf(b.method.toLowerCase())&&(b.body=a);const f=this.net.cors_proxy?this.net.cors_proxy+encodeURIComponent(d.href):d.href;new TextEncoder;let g=!1;this.net.fetch(f,b).then(k=>{let l=new Headers(k.headers);l.delete("content-encoding");l.delete("keep-alive");l.delete("content-length");l.delete("transfer-encoding");l.set("x-was-fetch-redirected",`${!!k.redirected}`);l.set("x-fetch-resp-url",k.url);l.set("connection","close");this.write(this.net.form_response_head(k.status,
|
|
195
|
+
k.statusText,l));g=!0;if(k.body&&k.body.getReader){const m=k.body.getReader(),n=({value:p,done:q})=>{p&&this.write(p);if(q)this.close();else return m.read().then(n)};m.read().then(n)}else k.arrayBuffer().then(m=>{this.write(new Uint8Array(m));this.close()})}).catch(k=>{console.warn("Fetch Failed: "+f+"\n"+k);g||this.net.respond_text_and_close(this,502,"Fetch Error",`Fetch ${f} failed:\n\n${k.stack||k.message}`);this.close()})}}Tb.prototype.fetch=async function(a,b){this.cors_proxy&&(a=this.cors_proxy+
|
|
196
|
+
encodeURIComponent(a));try{const c=await fetch(a,b),d=await c.arrayBuffer();return[c,d]}catch(c){return console.warn("Fetch Failed: "+a+"\n"+c),[{status:502,statusText:"Fetch Error",headers:new Headers({"Content-Type":"text/plain"})},(new TextEncoder).encode(`Fetch ${a} failed:\n\n${c.stack}`).buffer]}};Tb.prototype.form_response_head=function(a,b,c){a=[`HTTP/1.1 ${a} ${b}`];for(const [d,e]of c.entries())a.push(`${d}: ${e}`);return(new TextEncoder).encode(a.join("\r\n")+"\r\n\r\n")};Tb.prototype.respond_text_and_close=
|
|
197
|
+
function(a,b,c,d){const e=new Headers({"content-type":"text/plain","content-length":d.length.toString(10),connection:"close"});a.writev([this.form_response_head(b,c,e),(new TextEncoder).encode(d)]);a.close()};Tb.prototype.parse_http_header=function(a){var b=a.match(/^([^:]*):(.*)$/);if(b&&(a=b[1],b=b[2].trim(),0!==a.length&&0!==b.length&&/^[\w-]+$/.test(a)&&/^[\x20-\x7E]+$/.test(b)))return{key:a,value:b}};Tb.prototype.send=function(a){Ob(a,this)};Tb.prototype.receive=function(a){this.bus.send("net"+
|
|
198
|
+
this.id+"-receive",new Uint8Array(a))};function ac(a,b,c){this.register_ws(a);this.last_stream=1;this.connections={0:{congestion:0}};this.congested_buffer=[];c=c||{};this.bus=b;this.id=c.id||0;this.router_mac=new Uint8Array((c.router_mac||"52:54:0:1:2:3").split(":").map(function(d){return parseInt(d,16)}));this.router_ip=new Uint8Array((c.router_ip||"192.168.86.1").split(".").map(function(d){return parseInt(d,10)}));this.vm_ip=new Uint8Array((c.vm_ip||"192.168.86.100").split(".").map(function(d){return parseInt(d,
|
|
199
|
+
10)}));this.masquerade=void 0===c.masquerade||!!c.masquerade;this.vm_mac=new Uint8Array(6);this.dns_method=c.dns_method||"doh";this.doh_server=c.doh_server;this.tcp_conn={};this.eth_encoder_buf=Jb();this.bus.register("net"+this.id+"-mac",function(d){this.vm_mac=new Uint8Array(d.split(":").map(function(e){return parseInt(e,16)}))},this);this.bus.register("net"+this.id+"-send",function(d){this.send(d)},this)}ac.prototype.register_ws=function(a){this.wispws=new WebSocket(a.replace("wisp://","ws://").replace("wisps://",
|
|
200
|
+
"wss://"));this.wispws.binaryType="arraybuffer";this.wispws.onmessage=b=>{this.process_incoming_wisp_frame(new Uint8Array(b.data))};this.wispws.onclose=()=>{setTimeout(()=>{this.register_ws(a)},1E4)}};ac.prototype.send_packet=function(a,b,c){this.connections[c]&&(0<this.connections[c].congestion?("DATA"===b&&this.connections[c].congestion--,this.wispws.send(a)):(this.connections[c].congested=!0,this.congested_buffer.push({data:a,type:b})))};ac.prototype.process_incoming_wisp_frame=function(a){const b=
|
|
201
|
+
new DataView(a.buffer),c=b.getUint32(1,!0);switch(a[0]){case 2:if(this.connections[c])this.connections[c].data_callback(a.slice(5));else throw Error("Got a DATA packet but stream not registered. ID: "+c);break;case 3:this.connections[c]&&(this.connections[c].congestion=b.getUint32(5,!0));if(this.connections[c].congested){for(const d of this.congested_buffer)this.send_packet(d.data,d.type,c);this.connections[c].congested=!1}break;case 4:this.connections[c]&&this.connections[c].close_callback(b.getUint8(5)),
|
|
202
|
+
delete this.connections[c]}};ac.prototype.send_wisp_frame=function(a){let b,c;switch(a.type){case "CONNECT":const d=(new TextEncoder).encode(a.hostname);b=new Uint8Array(8+d.length);c=new DataView(b.buffer);c.setUint8(0,1);c.setUint32(1,a.stream_id,!0);c.setUint8(5,1);c.setUint16(6,a.port,!0);b.set(d,8);this.connections[a.stream_id]={data_callback:a.data_callback,close_callback:a.close_callback,congestion:this.connections[0].congestion};break;case "DATA":b=new Uint8Array(5+a.data.length);c=new DataView(b.buffer);
|
|
203
|
+
c.setUint8(0,2);c.setUint32(1,a.stream_id,!0);b.set(a.data,5);break;case "CLOSE":b=new Uint8Array(6),c=new DataView(b.buffer),c.setUint8(0,4),c.setUint32(1,a.stream_id,!0),c.setUint8(5,a.reason)}this.send_packet(b,a.type,a.stream_id)};ac.prototype.destroy=function(){this.wispws&&(this.wispws.onmessage=null,this.wispws.onclose=null,this.wispws.close(),this.wispws=null)};ac.prototype.on_tcp_connection=function(a,b){let c=new Rb;c.state="syn-received";c.net=this;c.tuple=b;c.stream_id=this.last_stream++;
|
|
204
|
+
this.tcp_conn[b]=c;c.on("data",d=>{0!==d.length&&this.send_wisp_frame({type:"DATA",stream_id:c.stream_id,data:d})});c.on_close=()=>{this.send_wisp_frame({type:"CLOSE",stream_id:c.stream_id,reason:2})};c.on_shutdown=c.on_close;this.send_wisp_frame({type:"CONNECT",stream_id:c.stream_id,hostname:a.ipv4.dest.join("."),port:a.tcp.dport,data_callback:d=>{c.write(d)},close_callback:()=>{c.close()}});c.accept(a);return!0};ac.prototype.send=function(a){Ob(a,this)};ac.prototype.receive=function(a){this.bus.send("net"+
|
|
205
|
+
this.id+"-receive",new Uint8Array(a))};const bc="undefined"!==typeof window&&0<=window.navigator.platform.toString().toLowerCase().search("win");function cc(a){function b(w){return w.shiftKey&&w.ctrlKey&&(73===w.keyCode||74===w.keyCode||75===w.keyCode)||!r.emu_enabled?!1:w.target?w.target.classList.contains("phone_keyboard")||"INPUT"!==w.target.nodeName&&"TEXTAREA"!==w.target.nodeName:!0}function c(w){!w.altKey&&m[56]&&k(56,!1);return f(w,!1)}function d(w){!w.altKey&&m[56]&&k(56,!1);return f(w,!0)}
|
|
206
|
+
function e(){for(var w=Object.keys(m),G,P=0;P<w.length;P++)G=+w[P],m[G]&&k(G,!1);m={}}function f(w,G){if(r.bus&&b(w)){w.preventDefault&&w.preventDefault();if(bc&&(n&&(clearTimeout(q),w.getModifierState&&w.getModifierState("AltGraph")&&p===G&&"ControlLeft"===n.code&&"AltRight"===w.code||g(n,p),n=null),"ControlLeft"===w.code))return n=w,p=G,q=setTimeout(()=>{g(n,p);n=null},10),!1;g(w,G);return!1}}function g(w,G){a:{if(void 0!==w.code){var P=F[w.code];if(void 0!==P)break a}P=y[w.keyCode]}P?k(P,G,w.repeat):
|
|
207
|
+
console.log("Missing char in map: keyCode="+(w.keyCode||-1).toString(16)+" code="+w.code)}function k(w,G,P){if(G)m[w]&&!P&&k(w,!1);else if(!m[w])return;(m[w]=G)||(w|=128);255<w?(l(w>>8),l(w&255)):l(w)}function l(w){r.bus.send("keyboard-code",w)}var m={},n=null,p=!1,q=0,r=this;this.emu_enabled=!0;const y=new Uint16Array([0,0,0,0,0,0,0,0,14,15,0,0,0,28,0,0,42,29,56,0,58,0,0,0,0,0,0,1,0,0,0,0,57,57417,57425,57423,57415,57419,57416,57421,80,0,0,0,0,82,83,0,11,2,3,4,5,6,7,8,9,10,0,39,0,13,0,0,0,30,48,
|
|
208
|
+
46,32,18,33,34,35,23,36,37,38,50,49,24,25,16,19,31,20,22,47,17,45,21,44,57435,57436,57437,0,0,82,79,80,81,75,76,77,71,72,73,0,0,0,0,0,0,59,60,61,62,63,64,65,66,67,68,87,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,39,13,51,12,52,53,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,26,43,27,40,0,57435,57400,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),x={8:8,10:13,32:32,39:222,44:188,45:189,46:190,47:191,48:48,49:49,50:50,51:51,
|
|
209
|
+
52:52,53:53,54:54,55:55,56:56,57:57,59:186,61:187,91:219,92:220,93:221,96:192,97:65,98:66,99:67,100:68,101:69,102:70,103:71,104:72,105:73,106:74,107:75,108:76,109:77,110:78,111:79,112:80,113:81,114:82,115:83,116:84,117:85,118:86,119:87,120:88,121:89,122:90},u={33:49,34:222,35:51,36:52,37:53,38:55,40:57,41:48,42:56,43:187,58:186,60:188,62:190,63:191,64:50,65:65,66:66,67:67,68:68,69:69,70:70,71:71,72:72,73:73,74:74,75:75,76:76,77:77,78:78,79:79,80:80,81:81,82:82,83:83,84:84,85:85,86:86,87:87,88:88,
|
|
210
|
+
89:89,90:90,94:54,95:189,123:219,124:220,125:221,126:192};var F={Escape:1,Digit1:2,Digit2:3,Digit3:4,Digit4:5,Digit5:6,Digit6:7,Digit7:8,Digit8:9,Digit9:10,Digit0:11,Minus:12,Equal:13,Backspace:14,Tab:15,KeyQ:16,KeyW:17,KeyE:18,KeyR:19,KeyT:20,KeyY:21,KeyU:22,KeyI:23,KeyO:24,KeyP:25,BracketLeft:26,BracketRight:27,Enter:28,ControlLeft:29,KeyA:30,KeyS:31,KeyD:32,KeyF:33,KeyG:34,KeyH:35,KeyJ:36,KeyK:37,KeyL:38,Semicolon:39,Quote:40,Backquote:41,ShiftLeft:42,Backslash:43,KeyZ:44,KeyX:45,KeyC:46,KeyV:47,
|
|
211
|
+
KeyB:48,KeyN:49,KeyM:50,Comma:51,Period:52,Slash:53,IntlRo:53,ShiftRight:54,NumpadMultiply:55,AltLeft:56,Space:57,CapsLock:58,F1:59,F2:60,F3:61,F4:62,F5:63,F6:64,F7:65,F8:66,F9:67,F10:68,NumLock:69,ScrollLock:70,Numpad7:71,Numpad8:72,Numpad9:73,NumpadSubtract:74,Numpad4:75,Numpad5:76,Numpad6:77,NumpadAdd:78,Numpad1:79,Numpad2:80,Numpad3:81,Numpad0:82,NumpadDecimal:83,IntlBackslash:86,F11:87,F12:88,NumpadEnter:57372,ControlRight:57373,NumpadDivide:57397,AltRight:57400,Home:57415,ArrowUp:57416,PageUp:57417,
|
|
212
|
+
ArrowLeft:57419,ArrowRight:57421,End:57423,ArrowDown:57424,PageDown:57425,Insert:57426,Delete:57427,OSLeft:57435,OSRight:57436,ContextMenu:57437};this.bus=a;this.destroy=function(){"undefined"!==typeof window&&(window.removeEventListener("keyup",c,!1),window.removeEventListener("keydown",d,!1),window.removeEventListener("blur",e,!1))};this.init=function(){"undefined"!==typeof window&&(this.destroy(),window.addEventListener("keyup",c,!1),window.addEventListener("keydown",d,!1),window.addEventListener("blur",
|
|
213
|
+
e,!1))};this.init();this.simulate_press=function(w){w={keyCode:w};f(w,!0);f(w,!1)};this.simulate_char=function(w){var G=w.charCodeAt(0);G in x?this.simulate_press(x[G]):G in u?(l(42),this.simulate_press(u[G]),l(170)):console.log("ascii -> keyCode not found: ",G,w)}}function dc(a,b){function c(u){if(!x.enabled||!x.emu_enabled)return!1;var F=b||document.body,w;if(!(w=document.pointerLockElement))a:{for(u=u.target;u.parentNode;){if(u===F){w=!0;break a}u=u.parentNode}w=!1}return w}function d(u){c(u)&&
|
|
214
|
+
(u=u.changedTouches)&&u.length&&(u=u[u.length-1],r=u.clientX,y=u.clientY)}function e(){if(n||q||p)x.bus.send("mouse-click",[!1,!1,!1]),n=q=p=!1}function f(u){if(x.bus&&c(u)&&x.is_running){var F=0,w=0,G=u.changedTouches;G?G.length&&(G=G[G.length-1],F=G.clientX-r,w=G.clientY-y,r=G.clientX,y=G.clientY,u.preventDefault()):"number"===typeof u.movementX?(F=u.movementX,w=u.movementY):"number"===typeof u.webkitMovementX?(F=u.webkitMovementX,w=u.webkitMovementY):"number"===typeof u.mozMovementX?(F=u.mozMovementX,
|
|
215
|
+
w=u.mozMovementY):(F=u.clientX-r,w=u.clientY-y,r=u.clientX,y=u.clientY);x.bus.send("mouse-delta",[.15*F,-(.15*w)]);b&&x.bus.send("mouse-absolute",[u.pageX-b.offsetLeft,u.pageY-b.offsetTop,b.offsetWidth,b.offsetHeight])}}function g(u){c(u)&&l(u,!0)}function k(u){c(u)&&l(u,!1)}function l(u,F){x.bus&&(1===u.which?n=F:2===u.which?q=F:3===u.which&&(p=F),x.bus.send("mouse-click",[n,q,p]),u.preventDefault())}function m(u){if(c(u)){var F=u.wheelDelta||-u.detail;0>F?F=-1:0<F&&(F=1);x.bus.send("mouse-wheel",
|
|
216
|
+
[F,0]);u.preventDefault()}}var n=!1,p=!1,q=!1,r=0,y=0,x=this;this.enabled=!1;this.emu_enabled=!0;this.bus=a;this.bus.register("mouse-enable",function(u){this.enabled=u},this);this.is_running=!1;this.bus.register("emulator-stopped",function(){this.is_running=!1},this);this.bus.register("emulator-started",function(){this.is_running=!0},this);this.destroy=function(){"undefined"!==typeof window&&(window.removeEventListener("touchstart",d,!1),window.removeEventListener("touchend",e,!1),window.removeEventListener("touchmove",
|
|
217
|
+
f,!1),window.removeEventListener("mousemove",f,!1),window.removeEventListener("mousedown",g,!1),window.removeEventListener("mouseup",k,!1),window.removeEventListener("wheel",m,{passive:!1}))};this.init=function(){"undefined"!==typeof window&&(this.destroy(),window.addEventListener("touchstart",d,!1),window.addEventListener("touchend",e,!1),window.addEventListener("touchmove",f,!1),window.addEventListener("mousemove",f,!1),window.addEventListener("mousedown",g,!1),window.addEventListener("mouseup",
|
|
218
|
+
k,!1),window.addEventListener("wheel",m,{passive:!1}))};this.init()}function ec(){var a,b=0,c=0;this.put_char=function(d,e,f){a[d*b+e]=f};this.destroy=function(){};this.pause=function(){};this.continue=function(){};this.set_mode=function(){};this.set_font_bitmap=function(){};this.set_font_page=function(){};this.clear_screen=function(){};this.set_size_text=function(d,e){if(d!==b||e!==c)a=new Uint8Array(d*e),b=d,c=e};this.set_size_graphical=function(){};this.set_scale=function(){};this.update_cursor_scanline=
|
|
219
|
+
function(){};this.update_cursor=function(){};this.update_buffer=function(){};this.get_text_screen=function(){for(var d=[],e=0;e<c;e++)d.push(this.get_text_row(e));return d};this.get_text_row=function(d){d*=b;return String.fromCharCode.apply(String,a.subarray(d,d+b))};this.set_size_text(80,25)}function fc(a,b){function c(k){g.bus&&g.enabled&&(g.send_char(k.which),k.preventDefault())}function d(k){var l=k.which;8===l?(g.send_char(127),k.preventDefault()):9===l&&(g.send_char(9),k.preventDefault())}function e(k){if(g.enabled){for(var l=
|
|
220
|
+
k.clipboardData.getData("text/plain"),m=0;m<l.length;m++)g.send_char(l.charCodeAt(m));k.preventDefault()}}function f(k){k.target!==a&&a.blur()}var g=this;this.enabled=!0;this.bus=b;this.text="";this.text_new_line=!1;this.last_update=0;this.bus.register("serial0-output-byte",function(k){k=String.fromCharCode(k);this.show_char(k)},this);this.destroy=function(){a.removeEventListener("keypress",c,!1);a.removeEventListener("keydown",d,!1);a.removeEventListener("paste",e,!1);window.removeEventListener("mousedown",
|
|
221
|
+
f,!1)};this.init=function(){this.destroy();a.style.display="block";a.addEventListener("keypress",c,!1);a.addEventListener("keydown",d,!1);a.addEventListener("paste",e,!1);window.addEventListener("mousedown",f,!1)};this.init();this.show_char=function(k){"\b"===k?(this.text=this.text.slice(0,-1),this.update()):"\r"!==k&&(this.text+=k,"\n"===k&&(this.text_new_line=!0),this.update())};this.update=function(){var k=Date.now(),l=k-this.last_update;16>l?void 0===this.update_timer&&(this.update_timer=setTimeout(()=>
|
|
222
|
+
{this.update_timer=void 0;this.last_update=Date.now();this.render()},16-l)):(void 0!==this.update_timer&&(clearTimeout(this.update_timer),this.update_timer=void 0),this.last_update=k,this.render())};this.render=function(){a.value=this.text;this.text_new_line&&(this.text_new_line=!1,a.scrollTop=1E9)};this.send_char=function(k){g.bus&&g.bus.send("serial0-input",k)}}function gc(a,b){this.element=a;if(window.Terminal){var c=this.term=new window.Terminal({logLevel:"off",convertEol:"true"});c.write("This is the serial console. Whatever you type or paste here will be sent to COM1");
|
|
222
223
|
var d=c.onData(function(e){for(let f=0;f<e.length;f++)b.send("serial0-input",e.charCodeAt(f))});b.register("serial0-output-byte",function(e){c.write(Uint8Array.of(e))},this);this.destroy=function(){d.dispose();c.dispose()}}}gc.prototype.show=function(){this.term&&this.term.open(this.element)};function hc(a,b){b=b.id||0;this.bus=a;this.bus_send_msgid=`net${b}-send`;this.bus_recv_msgid=`net${b}-receive`;this.channel=new BroadcastChannel(`v86-inbrowser-${b}`);this.is_open=!0;this.nic_to_hub_fn=c=>{this.channel.postMessage(c)};
|
|
223
224
|
this.bus.register(this.bus_send_msgid,this.nic_to_hub_fn,this);this.hub_to_nic_fn=c=>{this.bus.send(this.bus_recv_msgid,c.data)};this.channel.addEventListener("message",this.hub_to_nic_fn)}hc.prototype.destroy=function(){this.is_open&&(this.bus.unregister(this.bus_send_msgid,this.nic_to_hub_fn),this.channel.removeEventListener("message",this.hub_to_nic_fn),this.channel.close(),this.is_open=!1)};function ic(){this.filedata=new Map}ic.prototype.read=async function(a,b,c){return(a=this.filedata.get(a))?
|
|
224
225
|
a.subarray(b,b+c):null};ic.prototype.cache=async function(a,b){this.filedata.set(a,b)};ic.prototype.uncache=function(a){this.filedata.delete(a)};function jc(a,b){b.endsWith("/")||(b+="/");this.storage=a;this.baseurl=b}jc.prototype.load_from_server=function(a){return new Promise(b=>{pa(this.baseurl+a,{done:async c=>{c=new Uint8Array(c);await this.cache(a,c);b(c)}})})};jc.prototype.read=async function(a,b,c){const d=await this.storage.read(a,b,c);return d?d:(await this.load_from_server(a)).subarray(b,
|