v86 0.5.460 → 0.5.462

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Readme.md CHANGED
@@ -171,7 +171,7 @@ See [tests/Readme.md](tests/Readme.md) for more information.
171
171
  ## API examples
172
172
 
173
173
  - [Basic](examples/basic.html)
174
- - [Programatically using the serial terminal](examples/serial.html)
174
+ - [Programmatically using the serial terminal](examples/serial.html)
175
175
  - [A Lua interpreter](examples/lua.html)
176
176
  - [Two instances in one window](examples/two_instances.html)
177
177
  - [Networking between browser windows/tabs using the Broadcast Channel API](examples/broadcast-network.html)
@@ -2590,26 +2590,39 @@ $PIT$$module$src$pit$$.prototype.set_state = function($state$jscomp$14$$) {
2590
2590
  this.counter_start_time = $state$jscomp$14$$[7];
2591
2591
  this.counter_start_value = $state$jscomp$14$$[8];
2592
2592
  };
2593
- $PIT$$module$src$pit$$.prototype.timer = function($now$jscomp$3$$, $no_irq$$) {
2593
+ $PIT$$module$src$pit$$.prototype.timer = function($now$jscomp$3$$, $diff_no_irq$$) {
2594
2594
  var $time_to_next_interrupt$$ = 100;
2595
- $no_irq$$ || (this.counter_enabled[0] && this.did_rollover(0, $now$jscomp$3$$) ? (this.counter_start_value[0] = this.get_counter_value(0, $now$jscomp$3$$), this.counter_start_time[0] = $now$jscomp$3$$, $dbg_log$$module$src$log$$("pit interrupt. new value: " + this.counter_start_value[0], 512), this.cpu.device_lower_irq(0), this.cpu.device_raise_irq(0), 0 === this.counter_mode[0] && (this.counter_enabled[0] = 0)) : this.cpu.device_lower_irq(0), this.counter_enabled[0] && ($time_to_next_interrupt$$ =
2596
- (this.counter_start_value[0] - Math.floor(1193.1816666 * ($now$jscomp$3$$ - this.counter_start_time[0]))) / 1193.1816666));
2595
+ if (!$diff_no_irq$$) {
2596
+ if (this.counter_enabled[0] && this.did_rollover(0, $now$jscomp$3$$)) {
2597
+ $diff_no_irq$$ = $now$jscomp$3$$ - this.counter_start_time[0];
2598
+ const $diff_in_ticks$$ = Math.floor(1193.1816666 * $diff_no_irq$$);
2599
+ this.counter_start_value[0] = this.get_counter_value(0, $now$jscomp$3$$);
2600
+ this.counter_start_time[0] = 0 > $diff_no_irq$$ ? $now$jscomp$3$$ : this.counter_start_time[0] + $diff_in_ticks$$ / 1193.1816666;
2601
+ $dbg_log$$module$src$log$$("pit interrupt. new value: " + this.counter_start_value[0], 512);
2602
+ this.cpu.device_lower_irq(0);
2603
+ this.cpu.device_raise_irq(0);
2604
+ 0 === this.counter_mode[0] && (this.counter_enabled[0] = 0);
2605
+ } else {
2606
+ this.cpu.device_lower_irq(0);
2607
+ }
2608
+ this.counter_enabled[0] && ($time_to_next_interrupt$$ = (this.counter_start_value[0] - Math.floor(1193.1816666 * ($now$jscomp$3$$ - this.counter_start_time[0]))) / 1193.1816666);
2609
+ }
2597
2610
  return $time_to_next_interrupt$$;
2598
2611
  };
2599
2612
  $PIT$$module$src$pit$$.prototype.get_counter_value = function($i$jscomp$35$$, $now$jscomp$4_value$jscomp$129$$) {
2600
2613
  if (!this.counter_enabled[$i$jscomp$35$$]) {
2601
2614
  return 0;
2602
2615
  }
2603
- var $diff$jscomp$1_reload$$ = $now$jscomp$4_value$jscomp$129$$ - this.counter_start_time[$i$jscomp$35$$], $diff_in_ticks$jscomp$1$$ = Math.floor(1193.1816666 * $diff$jscomp$1_reload$$);
2604
- $now$jscomp$4_value$jscomp$129$$ = this.counter_start_value[$i$jscomp$35$$] - $diff_in_ticks$jscomp$1$$;
2605
- $dbg_log$$module$src$log$$("diff=" + $diff$jscomp$1_reload$$ + " dticks=" + $diff_in_ticks$jscomp$1$$ + " value=" + $now$jscomp$4_value$jscomp$129$$ + " reload=" + this.counter_reload[$i$jscomp$35$$], 512);
2606
- $diff$jscomp$1_reload$$ = this.counter_reload[$i$jscomp$35$$];
2607
- $now$jscomp$4_value$jscomp$129$$ >= $diff$jscomp$1_reload$$ ? ($dbg_log$$module$src$log$$("Warning: Counter" + $i$jscomp$35$$ + " value " + $now$jscomp$4_value$jscomp$129$$ + " is larger than reload " + $diff$jscomp$1_reload$$, 512), $now$jscomp$4_value$jscomp$129$$ %= $diff$jscomp$1_reload$$) : 0 > $now$jscomp$4_value$jscomp$129$$ && ($now$jscomp$4_value$jscomp$129$$ = $now$jscomp$4_value$jscomp$129$$ % $diff$jscomp$1_reload$$ + $diff$jscomp$1_reload$$);
2616
+ var $diff$jscomp$2_reload$$ = $now$jscomp$4_value$jscomp$129$$ - this.counter_start_time[$i$jscomp$35$$], $diff_in_ticks$jscomp$2$$ = Math.floor(1193.1816666 * $diff$jscomp$2_reload$$);
2617
+ $now$jscomp$4_value$jscomp$129$$ = this.counter_start_value[$i$jscomp$35$$] - $diff_in_ticks$jscomp$2$$;
2618
+ $dbg_log$$module$src$log$$("diff=" + $diff$jscomp$2_reload$$ + " dticks=" + $diff_in_ticks$jscomp$2$$ + " value=" + $now$jscomp$4_value$jscomp$129$$ + " reload=" + this.counter_reload[$i$jscomp$35$$], 512);
2619
+ $diff$jscomp$2_reload$$ = this.counter_reload[$i$jscomp$35$$];
2620
+ $now$jscomp$4_value$jscomp$129$$ >= $diff$jscomp$2_reload$$ ? ($dbg_log$$module$src$log$$("Warning: Counter" + $i$jscomp$35$$ + " value " + $now$jscomp$4_value$jscomp$129$$ + " is larger than reload " + $diff$jscomp$2_reload$$, 512), $now$jscomp$4_value$jscomp$129$$ %= $diff$jscomp$2_reload$$) : 0 > $now$jscomp$4_value$jscomp$129$$ && ($now$jscomp$4_value$jscomp$129$$ = $now$jscomp$4_value$jscomp$129$$ % $diff$jscomp$2_reload$$ + $diff$jscomp$2_reload$$);
2608
2621
  return $now$jscomp$4_value$jscomp$129$$;
2609
2622
  };
2610
- $PIT$$module$src$pit$$.prototype.did_rollover = function($i$jscomp$36$$, $diff$jscomp$2_now$jscomp$5$$) {
2611
- $diff$jscomp$2_now$jscomp$5$$ -= this.counter_start_time[$i$jscomp$36$$];
2612
- return 0 > $diff$jscomp$2_now$jscomp$5$$ ? ($dbg_log$$module$src$log$$("Warning: PIT timer difference is negative, resetting (timer " + $i$jscomp$36$$ + ")"), !0) : this.counter_start_value[$i$jscomp$36$$] < Math.floor(1193.1816666 * $diff$jscomp$2_now$jscomp$5$$);
2623
+ $PIT$$module$src$pit$$.prototype.did_rollover = function($i$jscomp$36$$, $diff$jscomp$3_now$jscomp$5$$) {
2624
+ $diff$jscomp$3_now$jscomp$5$$ -= this.counter_start_time[$i$jscomp$36$$];
2625
+ return 0 > $diff$jscomp$3_now$jscomp$5$$ ? ($dbg_log$$module$src$log$$("Warning: PIT timer difference is negative, resetting (timer " + $i$jscomp$36$$ + ")"), !0) : this.counter_start_value[$i$jscomp$36$$] < Math.floor(1193.1816666 * $diff$jscomp$3_now$jscomp$5$$);
2613
2626
  };
2614
2627
  $PIT$$module$src$pit$$.prototype.counter_read = function($i$jscomp$37_value$jscomp$130$$) {
2615
2628
  var $latch_next_low$$ = this.counter_latch[$i$jscomp$37_value$jscomp$130$$];
@@ -2589,26 +2589,39 @@ $PIT$$module$src$pit$$.prototype.set_state = function($state$jscomp$14$$) {
2589
2589
  this.counter_start_time = $state$jscomp$14$$[7];
2590
2590
  this.counter_start_value = $state$jscomp$14$$[8];
2591
2591
  };
2592
- $PIT$$module$src$pit$$.prototype.timer = function($now$jscomp$3$$, $no_irq$$) {
2592
+ $PIT$$module$src$pit$$.prototype.timer = function($now$jscomp$3$$, $diff_no_irq$$) {
2593
2593
  var $time_to_next_interrupt$$ = 100;
2594
- $no_irq$$ || (this.counter_enabled[0] && this.did_rollover(0, $now$jscomp$3$$) ? (this.counter_start_value[0] = this.get_counter_value(0, $now$jscomp$3$$), this.counter_start_time[0] = $now$jscomp$3$$, $dbg_log$$module$src$log$$("pit interrupt. new value: " + this.counter_start_value[0], 512), this.cpu.device_lower_irq(0), this.cpu.device_raise_irq(0), 0 === this.counter_mode[0] && (this.counter_enabled[0] = 0)) : this.cpu.device_lower_irq(0), this.counter_enabled[0] && ($time_to_next_interrupt$$ =
2595
- (this.counter_start_value[0] - Math.floor(1193.1816666 * ($now$jscomp$3$$ - this.counter_start_time[0]))) / 1193.1816666));
2594
+ if (!$diff_no_irq$$) {
2595
+ if (this.counter_enabled[0] && this.did_rollover(0, $now$jscomp$3$$)) {
2596
+ $diff_no_irq$$ = $now$jscomp$3$$ - this.counter_start_time[0];
2597
+ const $diff_in_ticks$$ = Math.floor(1193.1816666 * $diff_no_irq$$);
2598
+ this.counter_start_value[0] = this.get_counter_value(0, $now$jscomp$3$$);
2599
+ this.counter_start_time[0] = 0 > $diff_no_irq$$ ? $now$jscomp$3$$ : this.counter_start_time[0] + $diff_in_ticks$$ / 1193.1816666;
2600
+ $dbg_log$$module$src$log$$("pit interrupt. new value: " + this.counter_start_value[0], 512);
2601
+ this.cpu.device_lower_irq(0);
2602
+ this.cpu.device_raise_irq(0);
2603
+ 0 === this.counter_mode[0] && (this.counter_enabled[0] = 0);
2604
+ } else {
2605
+ this.cpu.device_lower_irq(0);
2606
+ }
2607
+ this.counter_enabled[0] && ($time_to_next_interrupt$$ = (this.counter_start_value[0] - Math.floor(1193.1816666 * ($now$jscomp$3$$ - this.counter_start_time[0]))) / 1193.1816666);
2608
+ }
2596
2609
  return $time_to_next_interrupt$$;
2597
2610
  };
2598
2611
  $PIT$$module$src$pit$$.prototype.get_counter_value = function($i$jscomp$35$$, $now$jscomp$4_value$jscomp$129$$) {
2599
2612
  if (!this.counter_enabled[$i$jscomp$35$$]) {
2600
2613
  return 0;
2601
2614
  }
2602
- var $diff$jscomp$1_reload$$ = $now$jscomp$4_value$jscomp$129$$ - this.counter_start_time[$i$jscomp$35$$], $diff_in_ticks$jscomp$1$$ = Math.floor(1193.1816666 * $diff$jscomp$1_reload$$);
2603
- $now$jscomp$4_value$jscomp$129$$ = this.counter_start_value[$i$jscomp$35$$] - $diff_in_ticks$jscomp$1$$;
2604
- $dbg_log$$module$src$log$$("diff=" + $diff$jscomp$1_reload$$ + " dticks=" + $diff_in_ticks$jscomp$1$$ + " value=" + $now$jscomp$4_value$jscomp$129$$ + " reload=" + this.counter_reload[$i$jscomp$35$$], 512);
2605
- $diff$jscomp$1_reload$$ = this.counter_reload[$i$jscomp$35$$];
2606
- $now$jscomp$4_value$jscomp$129$$ >= $diff$jscomp$1_reload$$ ? ($dbg_log$$module$src$log$$("Warning: Counter" + $i$jscomp$35$$ + " value " + $now$jscomp$4_value$jscomp$129$$ + " is larger than reload " + $diff$jscomp$1_reload$$, 512), $now$jscomp$4_value$jscomp$129$$ %= $diff$jscomp$1_reload$$) : 0 > $now$jscomp$4_value$jscomp$129$$ && ($now$jscomp$4_value$jscomp$129$$ = $now$jscomp$4_value$jscomp$129$$ % $diff$jscomp$1_reload$$ + $diff$jscomp$1_reload$$);
2615
+ var $diff$jscomp$2_reload$$ = $now$jscomp$4_value$jscomp$129$$ - this.counter_start_time[$i$jscomp$35$$], $diff_in_ticks$jscomp$2$$ = Math.floor(1193.1816666 * $diff$jscomp$2_reload$$);
2616
+ $now$jscomp$4_value$jscomp$129$$ = this.counter_start_value[$i$jscomp$35$$] - $diff_in_ticks$jscomp$2$$;
2617
+ $dbg_log$$module$src$log$$("diff=" + $diff$jscomp$2_reload$$ + " dticks=" + $diff_in_ticks$jscomp$2$$ + " value=" + $now$jscomp$4_value$jscomp$129$$ + " reload=" + this.counter_reload[$i$jscomp$35$$], 512);
2618
+ $diff$jscomp$2_reload$$ = this.counter_reload[$i$jscomp$35$$];
2619
+ $now$jscomp$4_value$jscomp$129$$ >= $diff$jscomp$2_reload$$ ? ($dbg_log$$module$src$log$$("Warning: Counter" + $i$jscomp$35$$ + " value " + $now$jscomp$4_value$jscomp$129$$ + " is larger than reload " + $diff$jscomp$2_reload$$, 512), $now$jscomp$4_value$jscomp$129$$ %= $diff$jscomp$2_reload$$) : 0 > $now$jscomp$4_value$jscomp$129$$ && ($now$jscomp$4_value$jscomp$129$$ = $now$jscomp$4_value$jscomp$129$$ % $diff$jscomp$2_reload$$ + $diff$jscomp$2_reload$$);
2607
2620
  return $now$jscomp$4_value$jscomp$129$$;
2608
2621
  };
2609
- $PIT$$module$src$pit$$.prototype.did_rollover = function($i$jscomp$36$$, $diff$jscomp$2_now$jscomp$5$$) {
2610
- $diff$jscomp$2_now$jscomp$5$$ -= this.counter_start_time[$i$jscomp$36$$];
2611
- return 0 > $diff$jscomp$2_now$jscomp$5$$ ? ($dbg_log$$module$src$log$$("Warning: PIT timer difference is negative, resetting (timer " + $i$jscomp$36$$ + ")"), !0) : this.counter_start_value[$i$jscomp$36$$] < Math.floor(1193.1816666 * $diff$jscomp$2_now$jscomp$5$$);
2622
+ $PIT$$module$src$pit$$.prototype.did_rollover = function($i$jscomp$36$$, $diff$jscomp$3_now$jscomp$5$$) {
2623
+ $diff$jscomp$3_now$jscomp$5$$ -= this.counter_start_time[$i$jscomp$36$$];
2624
+ return 0 > $diff$jscomp$3_now$jscomp$5$$ ? ($dbg_log$$module$src$log$$("Warning: PIT timer difference is negative, resetting (timer " + $i$jscomp$36$$ + ")"), !0) : this.counter_start_value[$i$jscomp$36$$] < Math.floor(1193.1816666 * $diff$jscomp$3_now$jscomp$5$$);
2612
2625
  };
2613
2626
  $PIT$$module$src$pit$$.prototype.counter_read = function($i$jscomp$37_value$jscomp$130$$) {
2614
2627
  var $latch_next_low$$ = this.counter_latch[$i$jscomp$37_value$jscomp$130$$];
package/build/libv86.js CHANGED
@@ -138,8 +138,8 @@ a.getUTCDate(),d,c,b))}this.cmos_b&16&&(this.update_interrupt_time=Date.now());y
138
138
  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,
139
139
  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)}ib.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};
140
140
  ib.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]};
141
- ib.prototype.timer=function(a,b){var c=100;b||(this.counter_enabled[0]&&this.did_rollover(0,a)?(this.counter_start_value[0]=this.get_counter_value(0,a),this.counter_start_time[0]=a,this.cpu.device_lower_irq(0),this.cpu.device_raise_irq(0),0===this.counter_mode[0]&&(this.counter_enabled[0]=0)):this.cpu.device_lower_irq(0),this.counter_enabled[0]&&(c=(this.counter_start_value[0]-Math.floor(1193.1816666*(a-this.counter_start_time[0])))/1193.1816666));return c};
142
- ib.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};ib.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)};
141
+ ib.prototype.timer=function(a,b){var c=100;if(!b){if(this.counter_enabled[0]&&this.did_rollover(0,a)){b=a-this.counter_start_time[0];const d=Math.floor(1193.1816666*b);this.counter_start_value[0]=this.get_counter_value(0,a);this.counter_start_time[0]=0>b?a:this.counter_start_time[0]+d/1193.1816666;this.cpu.device_lower_irq(0);this.cpu.device_raise_irq(0);0===this.counter_mode[0]&&(this.counter_enabled[0]=0)}else this.cpu.device_lower_irq(0);this.counter_enabled[0]&&(c=(this.counter_start_value[0]-
142
+ Math.floor(1193.1816666*(a-this.counter_start_time[0])))/1193.1816666)}return c};ib.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};ib.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)};
143
143
  ib.prototype.counter_read=function(a){var b=this.counter_latch[a];if(b)return this.counter_latch[a]--,2===b?this.counter_latch_value[a]&255:this.counter_latch_value[a]>>8;b=this.counter_next_low[a];3===this.counter_mode[a]&&(this.counter_next_low[a]^=1);a=this.get_counter_value(a,G.microtick());return b?a&255:a>>8};
144
144
  ib.prototype.counter_write=function(a,b){this.counter_reload[a]=this.counter_next_low[a]?this.counter_reload[a]&-256|b:this.counter_reload[a]&255|b<<8;3===this.counter_read_mode[a]&&this.counter_next_low[a]||(this.counter_reload[a]||(this.counter_reload[a]=65535),this.counter_start_value[a]=this.counter_reload[a],this.counter_enabled[a]=!0,this.counter_start_time[a]=G.microtick(),y(this.counter_reload[a]));3===this.counter_read_mode[a]&&(this.counter_next_low[a]^=1)};
145
145
  ib.prototype.port43_write=function(a){var b=a>>1&7,c=a>>6&3;a=a>>4&3;3!==c&&(0===a?(this.counter_latch[c]=2,b=this.get_counter_value(c,G.microtick()),this.counter_latch_value[c]=b?b-1:0):(6<=b&&(b&=-5),this.counter_next_low[c]=1===a?1:2===a?0:1,0===c&&this.cpu.device_lower_irq(0),0!==b&&3!==b&&2!==b&&y(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]])))};ib.prototype.dump=function(){};function jb(a){if("undefined"!==typeof window)if(window.AudioContext||window.webkitAudioContext){var b=window.AudioWorklet?kb:lb;this.bus=a;this.audio_context=window.AudioContext?new AudioContext:new webkitAudioContext;this.mixer=new mb(a,this.audio_context);this.pcspeaker=new nb(a,this.audio_context,this.mixer);this.dac=new b(a,this.audio_context,this.mixer);this.pcspeaker.start();a.register("emulator-stopped",function(){this.audio_context.suspend()},this);a.register("emulator-started",function(){this.audio_context.resume()},
package/build/libv86.mjs CHANGED
@@ -123,40 +123,40 @@ d=this.decode_time(this.cmos_data[5]);this.next_interrupt_alarm=+new Date(Date.U
123
123
  function(a){return this.cmos_data[a]};hb.prototype.cmos_write=function(a,b){y(a);y(b);this.cmos_data[a]=b};function ib(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);
124
124
  a.io.register_read(97,this,function(){var c=G.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,
125
125
  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)}ib.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;
126
- a[8]=this.counter_start_value;return a};ib.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]};ib.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),
127
- 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};ib.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};ib.prototype.did_rollover=
128
- function(a,b){b-=this.counter_start_time[a];return 0>b?!0:this.counter_start_value[a]<Math.floor(1193.1816666*b)};ib.prototype.counter_read=function(a){var b=this.counter_latch[a];if(b)return this.counter_latch[a]--,2===b?this.counter_latch_value[a]&255:this.counter_latch_value[a]>>8;b=this.counter_next_low[a];3===this.counter_mode[a]&&(this.counter_next_low[a]^=1);a=this.get_counter_value(a,G.microtick());return b?a&255:a>>8};ib.prototype.counter_write=function(a,b){this.counter_reload[a]=this.counter_next_low[a]?
129
- this.counter_reload[a]&-256|b:this.counter_reload[a]&255|b<<8;3===this.counter_read_mode[a]&&this.counter_next_low[a]||(this.counter_reload[a]||(this.counter_reload[a]=65535),this.counter_start_value[a]=this.counter_reload[a],this.counter_enabled[a]=!0,this.counter_start_time[a]=G.microtick(),y(this.counter_reload[a]));3===this.counter_read_mode[a]&&(this.counter_next_low[a]^=1)};ib.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,
130
- G.microtick()),this.counter_latch_value[c]=b?b-1:0):(6<=b&&(b&=-5),this.counter_next_low[c]=1===a?1:2===a?0:1,0===c&&this.cpu.device_lower_irq(0),0!==b&&3!==b&&2!==b&&y(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]])))};ib.prototype.dump=function(){};function jb(a){if("undefined"!==typeof window)if(window.AudioContext||window.webkitAudioContext){var b=window.AudioWorklet?kb:lb;this.bus=a;this.audio_context=
131
- window.AudioContext?new AudioContext:new webkitAudioContext;this.mixer=new mb(a,this.audio_context);this.pcspeaker=new nb(a,this.audio_context,this.mixer);this.dac=new b(a,this.audio_context,this.mixer);this.pcspeaker.start();a.register("emulator-stopped",function(){this.audio_context.suspend()},this);a.register("emulator-started",function(){this.audio_context.resume()},this);a.register("speaker-confirm-initialized",function(){a.send("speaker-has-initialized")},this);a.send("speaker-has-initialized")}else console.warn("Web browser doesn't support Web Audio API")}
132
- jb.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 mb(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=
133
- 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=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,
134
- 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);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,
135
- 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],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||
136
- e.set_volume(d,f)},this);a.register("mixer-gain-left",function(d){this.gain_left=Math.pow(10,d/20);this.update()},this);a.register("mixer-gain-right",function(d){this.gain_right=Math.pow(10,d/20);this.update()},this);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)}mb.prototype.add_source=function(a,b){a=
137
- new ob(this.audio_context,a,this.input_left,this.input_right);this.sources.has(b);this.sources.set(b,a);return a};mb.prototype.connect_source=function(a,b){a=this.sources.get(a);void 0===a||a.connect(b)};mb.prototype.disconnect_source=function(a,b){a=this.sources.get(a);void 0===a||a.disconnect(b)};mb.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()};mb.prototype.update=
138
- function(){var a=this.volume_both*this.volume_right*this.gain_right;this.node_gain_left.gain.setValueAtTime(this.volume_both*this.volume_left*this.gain_left,this.audio_context.currentTime);this.node_gain_right.gain.setValueAtTime(a,this.audio_context.currentTime)};function ob(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();
139
- this.node_gain_right=a.createGain();b.connect(this.node_splitter);this.node_splitter.connect(this.node_gain_left,0);this.node_gain_left.connect(c);this.node_splitter.connect(this.node_gain_right,1);this.node_gain_right.connect(d)}ob.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,
140
- this.audio_context.currentTime)};ob.prototype.connect=function(a){var b=!a||2===a;if(b||0===a)this.connected_left=!0;if(b||1===a)this.connected_right=!0;this.update()};ob.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()};ob.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()};ob.prototype.set_gain_hidden=
141
- function(a){this.gain_hidden=a};function nb(a,b,c){this.node_oscillator=b.createOscillator();this.node_oscillator.type="square";this.node_oscillator.frequency.setValueAtTime(440,b.currentTime);this.mixer_connection=c.add_source(this.node_oscillator,1);this.mixer_connection.disconnect();a.register("pcspeaker-enable",function(){c.connect_source(1)},this);a.register("pcspeaker-disable",function(){c.disconnect_source(1)},this);a.register("pcspeaker-update",function(d){var e=d[1],f=0;3===d[0]&&(f=Math.min(1193181.6665999999/
142
- e,this.node_oscillator.frequency.maxValue),f=Math.max(f,0));this.node_oscillator.frequency.setValueAtTime(f,b.currentTime)},this)}nb.prototype.start=function(){this.node_oscillator.start()};function kb(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=48E3;b=function(){function g(l){if(0===l)return 1;l*=Math.PI;return Math.sin(l)/l}function h(){var l=Reflect.construct(AudioWorkletProcessor,[],h);l.kernel_size=3;l.queue_data=Array(1024);l.queue_start=0;l.queue_end=0;l.queue_length=
143
- 0;l.queue_size=l.queue_data.length;l.queued_samples=0;l.source_buffer_previous=m;l.source_buffer_current=m;l.source_samples_per_destination=1;l.source_block_start=0;l.source_time=0;l.source_offset=0;l.port.onmessage=n=>{switch(n.data.type){case "queue":l.queue_push(n.data.value);break;case "sampling-rate":l.source_samples_per_destination=n.data.value/sampleRate}};return l}var m=[new Float32Array(256),new Float32Array(256)];Reflect.setPrototypeOf(h.prototype,AudioWorkletProcessor.prototype);Reflect.setPrototypeOf(h,
144
- AudioWorkletProcessor);h.prototype.process=h.prototype.process=function(l,n){for(l=0;l<n[0][0].length;l++){for(var p=0,q=0,r=this.source_offset+this.kernel_size,x=this.source_offset-this.kernel_size+1;x<=r;x++){var F=this.source_block_start+x;p+=this.get_sample(F,0)*this.kernel(this.source_time-x);q+=this.get_sample(F,1)*this.kernel(this.source_time-x)}if(isNaN(p)||isNaN(q))p=q=0,this.dbg_log("ERROR: NaN values! Ignoring for now.");n[0][0][l]=p;n[0][1][l]=q;this.source_time+=this.source_samples_per_destination;
145
- this.source_offset=Math.floor(this.source_time)}n=this.source_offset;n+=this.kernel_size+2;this.source_time-=this.source_offset;this.source_block_start+=this.source_offset;this.source_offset=0;this.ensure_enough_data(n);return!0};h.prototype.kernel=function(l){return g(l)*g(l/this.kernel_size)};h.prototype.get_sample=function(l,n){return 0>l?(l+=this.source_buffer_previous[0].length,this.source_buffer_previous[n][l]):this.source_buffer_current[n][l]};h.prototype.ensure_enough_data=function(l){var n=
146
- this.source_buffer_current[0].length;n-this.source_block_start<l&&(this.prepare_next_buffer(),this.source_block_start-=n)};h.prototype.prepare_next_buffer=function(){256>this.queued_samples&&this.queue_length&&this.dbg_log("Not enough samples - should not happen during midway of playback");this.source_buffer_previous=this.source_buffer_current;this.source_buffer_current=this.queue_shift();var l=this.source_buffer_current[0].length;if(256>l){for(var n=this.queue_start,p=0;256>l&&p<this.queue_length;)l+=
147
- this.queue_data[n][0].length,n=n+1&this.queue_size-1,p++;l=Math.max(l,256);l=[new Float32Array(l),new Float32Array(l)];l[0].set(this.source_buffer_current[0]);l[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();l[0].set(r[0],n);l[1].set(r[1],n);n+=r[0].length}this.source_buffer_current=l}this.pump()};h.prototype.pump=function(){1024>this.queued_samples/this.source_samples_per_destination&&this.port.postMessage({type:"pump"})};
148
- h.prototype.queue_push=function(l){this.queue_length<this.queue_size&&(this.queue_data[this.queue_end]=l,this.queue_end=this.queue_end+1&this.queue_size-1,this.queue_length++,this.queued_samples+=l[0].length,this.pump())};h.prototype.queue_shift=function(){if(!this.queue_length)return m;var l=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-=l[0].length;return l};h.prototype.dbg_log=
149
- function(){};registerProcessor("dac-processor",h)}.toString();var d=b.indexOf("{")+1,e=b.lastIndexOf("}");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:{},
150
- processorOptions:{}});this.node_processor.port.postMessage({type:"sampling-rate",value:this.sampling_rate});this.node_processor.port.onmessage=g=>{switch(g.data.type){case "pump":this.pump()}};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=
151
- !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",value:g})},this)}kb.prototype.queue=function(a){this.node_processor&&this.node_processor.port.postMessage({type:"queue",value:a},[a[0].buffer,a[1].buffer])};kb.prototype.pump=function(){this.enabled&&this.bus.send("dac-request-data")};function lb(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=22050;this.buffered_time=
152
- 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=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=
153
- Math.ceil(8E3/d);this.node_lowpass.frequency.setValueAtTime(d/2,this.audio_context.currentTime)},this)}lb.prototype.queue=function(a){var b=a[0].length,c=b/this.sampling_rate;if(1<this.rate_ratio){var d=this.audio_context.createBuffer(2,b*this.rate_ratio,this.sampling_rate*this.rate_ratio);for(var e=d.getChannelData(0),f=d.getChannelData(1),g=0,h=0;h<b;h++)for(var m=0;m<this.rate_ratio;m++,g++)e[g]=a[0][h],f[g]=a[1][h]}else d=this.audio_context.createBuffer(2,b,this.sampling_rate),d.copyToChannel?
154
- (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();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)};lb.prototype.pump=
155
- function(){this.enabled&&(.2<this.buffered_time-this.audio_context.currentTime||this.bus.send("dac-request-data"))};function pb(a,b,c){this.bus=b;this.socket=void 0;this.id=c||0;this.send_queue=[];this.url=a;this.reconnect_interval=1E4;this.last_connect_attempt=Date.now()-this.reconnect_interval;this.send_queue_limit=64;this.destroyed=!1;this.bus.register("net"+this.id+"-send",function(d){this.send(d)},this)}pb.prototype.handle_message=function(a){this.bus&&this.bus.send("net"+this.id+"-receive",
156
- new Uint8Array(a.data))};pb.prototype.handle_close=function(){this.destroyed||(this.connect(),setTimeout(this.connect.bind(this),this.reconnect_interval))};pb.prototype.handle_open=function(){for(var a=0;a<this.send_queue.length;a++)this.send(this.send_queue[a]);this.send_queue=[]};pb.prototype.handle_error=function(){};pb.prototype.destroy=function(){this.destroyed=!0;this.socket&&this.socket.close()};pb.prototype.connect=function(){if("undefined"!==typeof WebSocket){if(this.socket){var a=this.socket.readyState;
157
- if(0===a||1===a)return}a=Date.now();if(!(this.last_connect_attempt+this.reconnect_interval>a)){this.last_connect_attempt=Date.now();try{this.socket=new WebSocket(this.url)}catch(b){console.error(b);return}this.socket.binaryType="arraybuffer";this.socket.onopen=this.handle_open.bind(this);this.socket.onmessage=this.handle_message.bind(this);this.socket.onclose=this.handle_close.bind(this);this.socket.onerror=this.handle_error.bind(this)}}};pb.prototype.send=function(a){this.socket&&1===this.socket.readyState?
158
- 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())};pb.prototype.change_proxy=function(a){this.url=a;this.socket&&(this.socket.onclose=function(){},this.socket.onerror=function(){},this.socket.close(),this.socket=void 0)};const qb=(new Date("1970-01-01T00:00:00Z")).getTime(),rb=(new Date("1900-01-01T00:00:00Z")).getTime(),sb=qb-rb,tb=Math.pow(2,32),ub=[118,56,54];function Bb(a){return[0,
159
- 1,2,3,4,5].map(b=>a[b].toString(16)).map(b=>1===b.length?"0"+b:b).join(":")}function Cb(a){return a[0]<<24|a[1]<<16|a[2]<<8|a[3]}class Db{constructor(a,b){a=Math.min(a,16);this.maximum_capacity=b?Math.max(b,a):0;this.length=this.head=this.tail=0;this.buffer=new Uint8Array(a)}write(a){const b=a.length;var c=this.length+b;let d=this.buffer.length;if(d<c){for(;d<c;)d*=2;if(this.maximum_capacity&&d>this.maximum_capacity)throw Error("stream capacity overflow in GrowableRingbuffer.write(), package dropped");
126
+ a[8]=this.counter_start_value;return a};ib.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]};ib.prototype.timer=function(a,b){var c=100;if(!b){if(this.counter_enabled[0]&&this.did_rollover(0,a)){b=a-this.counter_start_time[0];const d=Math.floor(1193.1816666*b);this.counter_start_value[0]=
127
+ this.get_counter_value(0,a);this.counter_start_time[0]=0>b?a:this.counter_start_time[0]+d/1193.1816666;this.cpu.device_lower_irq(0);this.cpu.device_raise_irq(0);0===this.counter_mode[0]&&(this.counter_enabled[0]=0)}else 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};ib.prototype.get_counter_value=function(a,b){if(!this.counter_enabled[a])return 0;b=this.counter_start_value[a]-Math.floor(1193.1816666*
128
+ (b-this.counter_start_time[a]));a=this.counter_reload[a];b>=a?b%=a:0>b&&(b=b%a+a);return b};ib.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)};ib.prototype.counter_read=function(a){var b=this.counter_latch[a];if(b)return this.counter_latch[a]--,2===b?this.counter_latch_value[a]&255:this.counter_latch_value[a]>>8;b=this.counter_next_low[a];3===this.counter_mode[a]&&(this.counter_next_low[a]^=1);a=this.get_counter_value(a,
129
+ G.microtick());return b?a&255:a>>8};ib.prototype.counter_write=function(a,b){this.counter_reload[a]=this.counter_next_low[a]?this.counter_reload[a]&-256|b:this.counter_reload[a]&255|b<<8;3===this.counter_read_mode[a]&&this.counter_next_low[a]||(this.counter_reload[a]||(this.counter_reload[a]=65535),this.counter_start_value[a]=this.counter_reload[a],this.counter_enabled[a]=!0,this.counter_start_time[a]=G.microtick(),y(this.counter_reload[a]));3===this.counter_read_mode[a]&&(this.counter_next_low[a]^=
130
+ 1)};ib.prototype.port43_write=function(a){var b=a>>1&7,c=a>>6&3;a=a>>4&3;3!==c&&(0===a?(this.counter_latch[c]=2,b=this.get_counter_value(c,G.microtick()),this.counter_latch_value[c]=b?b-1:0):(6<=b&&(b&=-5),this.counter_next_low[c]=1===a?1:2===a?0:1,0===c&&this.cpu.device_lower_irq(0),0!==b&&3!==b&&2!==b&&y(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]])))};ib.prototype.dump=function(){};function jb(a){if("undefined"!==
131
+ typeof window)if(window.AudioContext||window.webkitAudioContext){var b=window.AudioWorklet?kb:lb;this.bus=a;this.audio_context=window.AudioContext?new AudioContext:new webkitAudioContext;this.mixer=new mb(a,this.audio_context);this.pcspeaker=new nb(a,this.audio_context,this.mixer);this.dac=new b(a,this.audio_context,this.mixer);this.pcspeaker.start();a.register("emulator-stopped",function(){this.audio_context.suspend()},this);a.register("emulator-started",function(){this.audio_context.resume()},this);
132
+ 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")}jb.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 mb(a,b){function c(d){return function(e){d.gain.setValueAtTime(e,this.audio_context.currentTime)}}this.audio_context=
133
+ 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=this.audio_context.createBiquadFilter();
134
+ 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);this.input_left=this.node_treble_left;this.input_right=
135
+ 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],d[1])},this);a.register("mixer-disconnect",function(d){this.disconnect_source(d[0],
136
+ d[1])},this);a.register("mixer-volume",function(d){var e=d[0],f=d[1];d=Math.pow(10,d[2]/20);e=0===e?this:this.sources.get(e);void 0===e||e.set_volume(d,f)},this);a.register("mixer-gain-left",function(d){this.gain_left=Math.pow(10,d/20);this.update()},this);a.register("mixer-gain-right",function(d){this.gain_right=Math.pow(10,d/20);this.update()},this);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",
137
+ c(this.node_bass_left),this);a.register("mixer-bass-right",c(this.node_bass_right),this)}mb.prototype.add_source=function(a,b){a=new ob(this.audio_context,a,this.input_left,this.input_right);this.sources.has(b);this.sources.set(b,a);return a};mb.prototype.connect_source=function(a,b){a=this.sources.get(a);void 0===a||a.connect(b)};mb.prototype.disconnect_source=function(a,b){a=this.sources.get(a);void 0===a||a.disconnect(b)};mb.prototype.set_volume=function(a,b){void 0===b&&(b=2);switch(b){case 0:this.volume_left=
138
+ a;break;case 1:this.volume_right=a;break;case 2:this.volume_both=a;break;default:return}this.update()};mb.prototype.update=function(){var a=this.volume_both*this.volume_right*this.gain_right;this.node_gain_left.gain.setValueAtTime(this.volume_both*this.volume_left*this.gain_left,this.audio_context.currentTime);this.node_gain_right.gain.setValueAtTime(a,this.audio_context.currentTime)};function ob(a,b,c,d){this.audio_context=a;this.connected_right=this.connected_left=!0;this.volume_right=this.volume_left=
139
+ this.volume_both=this.gain_hidden=1;this.node_splitter=a.createChannelSplitter(2);this.node_gain_left=a.createGain();this.node_gain_right=a.createGain();b.connect(this.node_splitter);this.node_splitter.connect(this.node_gain_left,0);this.node_gain_left.connect(c);this.node_splitter.connect(this.node_gain_right,1);this.node_gain_right.connect(d)}ob.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*
140
+ this.gain_hidden*this.volume_both*this.volume_left,this.audio_context.currentTime);this.node_gain_right.gain.setValueAtTime(a,this.audio_context.currentTime)};ob.prototype.connect=function(a){var b=!a||2===a;if(b||0===a)this.connected_left=!0;if(b||1===a)this.connected_right=!0;this.update()};ob.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()};ob.prototype.set_volume=function(a,b){void 0===b&&(b=2);switch(b){case 0:this.volume_left=
141
+ a;break;case 1:this.volume_right=a;break;case 2:this.volume_both=a;break;default:return}this.update()};ob.prototype.set_gain_hidden=function(a){this.gain_hidden=a};function nb(a,b,c){this.node_oscillator=b.createOscillator();this.node_oscillator.type="square";this.node_oscillator.frequency.setValueAtTime(440,b.currentTime);this.mixer_connection=c.add_source(this.node_oscillator,1);this.mixer_connection.disconnect();a.register("pcspeaker-enable",function(){c.connect_source(1)},this);a.register("pcspeaker-disable",
142
+ function(){c.disconnect_source(1)},this);a.register("pcspeaker-update",function(d){var e=d[1],f=0;3===d[0]&&(f=Math.min(1193181.6665999999/e,this.node_oscillator.frequency.maxValue),f=Math.max(f,0));this.node_oscillator.frequency.setValueAtTime(f,b.currentTime)},this)}nb.prototype.start=function(){this.node_oscillator.start()};function kb(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=48E3;b=function(){function g(l){if(0===l)return 1;l*=Math.PI;return Math.sin(l)/l}function h(){var l=
143
+ Reflect.construct(AudioWorkletProcessor,[],h);l.kernel_size=3;l.queue_data=Array(1024);l.queue_start=0;l.queue_end=0;l.queue_length=0;l.queue_size=l.queue_data.length;l.queued_samples=0;l.source_buffer_previous=m;l.source_buffer_current=m;l.source_samples_per_destination=1;l.source_block_start=0;l.source_time=0;l.source_offset=0;l.port.onmessage=n=>{switch(n.data.type){case "queue":l.queue_push(n.data.value);break;case "sampling-rate":l.source_samples_per_destination=n.data.value/sampleRate}};return l}
144
+ var m=[new Float32Array(256),new Float32Array(256)];Reflect.setPrototypeOf(h.prototype,AudioWorkletProcessor.prototype);Reflect.setPrototypeOf(h,AudioWorkletProcessor);h.prototype.process=h.prototype.process=function(l,n){for(l=0;l<n[0][0].length;l++){for(var p=0,q=0,r=this.source_offset+this.kernel_size,x=this.source_offset-this.kernel_size+1;x<=r;x++){var F=this.source_block_start+x;p+=this.get_sample(F,0)*this.kernel(this.source_time-x);q+=this.get_sample(F,1)*this.kernel(this.source_time-x)}if(isNaN(p)||
145
+ isNaN(q))p=q=0,this.dbg_log("ERROR: NaN values! Ignoring for now.");n[0][0][l]=p;n[0][1][l]=q;this.source_time+=this.source_samples_per_destination;this.source_offset=Math.floor(this.source_time)}n=this.source_offset;n+=this.kernel_size+2;this.source_time-=this.source_offset;this.source_block_start+=this.source_offset;this.source_offset=0;this.ensure_enough_data(n);return!0};h.prototype.kernel=function(l){return g(l)*g(l/this.kernel_size)};h.prototype.get_sample=function(l,n){return 0>l?(l+=this.source_buffer_previous[0].length,
146
+ this.source_buffer_previous[n][l]):this.source_buffer_current[n][l]};h.prototype.ensure_enough_data=function(l){var n=this.source_buffer_current[0].length;n-this.source_block_start<l&&(this.prepare_next_buffer(),this.source_block_start-=n)};h.prototype.prepare_next_buffer=function(){256>this.queued_samples&&this.queue_length&&this.dbg_log("Not enough samples - should not happen during midway of playback");this.source_buffer_previous=this.source_buffer_current;this.source_buffer_current=this.queue_shift();
147
+ var l=this.source_buffer_current[0].length;if(256>l){for(var n=this.queue_start,p=0;256>l&&p<this.queue_length;)l+=this.queue_data[n][0].length,n=n+1&this.queue_size-1,p++;l=Math.max(l,256);l=[new Float32Array(l),new Float32Array(l)];l[0].set(this.source_buffer_current[0]);l[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();l[0].set(r[0],n);l[1].set(r[1],n);n+=r[0].length}this.source_buffer_current=l}this.pump()};h.prototype.pump=
148
+ function(){1024>this.queued_samples/this.source_samples_per_destination&&this.port.postMessage({type:"pump"})};h.prototype.queue_push=function(l){this.queue_length<this.queue_size&&(this.queue_data[this.queue_end]=l,this.queue_end=this.queue_end+1&this.queue_size-1,this.queue_length++,this.queued_samples+=l[0].length,this.pump())};h.prototype.queue_shift=function(){if(!this.queue_length)return m;var l=this.queue_data[this.queue_start];this.queue_data[this.queue_start]=null;this.queue_start=this.queue_start+
149
+ 1&this.queue_size-1;this.queue_length--;this.queued_samples-=l[0].length;return l};h.prototype.dbg_log=function(){};registerProcessor("dac-processor",h)}.toString();var d=b.indexOf("{")+1,e=b.lastIndexOf("}");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,
150
+ "dac-processor",{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[2],parameterData:{},processorOptions:{}});this.node_processor.port.postMessage({type:"sampling-rate",value:this.sampling_rate});this.node_processor.port.onmessage=g=>{switch(g.data.type){case "pump":this.pump()}};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",
151
+ 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",value:g})},this)}kb.prototype.queue=function(a){this.node_processor&&this.node_processor.port.postMessage({type:"queue",value:a},[a[0].buffer,a[1].buffer])};kb.prototype.pump=function(){this.enabled&&this.bus.send("dac-request-data")};function lb(a,b,c){this.bus=
152
+ 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=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=
153
+ !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)}lb.prototype.queue=function(a){var b=a[0].length,c=b/this.sampling_rate;if(1<this.rate_ratio){var d=this.audio_context.createBuffer(2,b*this.rate_ratio,this.sampling_rate*this.rate_ratio);for(var e=d.getChannelData(0),f=d.getChannelData(1),g=0,h=0;h<b;h++)for(var m=0;m<this.rate_ratio;m++,g++)e[g]=a[0][h],
154
+ f[g]=a[1][h]}else d=this.audio_context.createBuffer(2,b,this.sampling_rate),d.copyToChannel?(d.copyToChannel(a[0],0),d.copyToChannel(a[1],1)):(d.getChannelData(0).set(a[0]),d.getChannelData(1).set(a[1]));a=this.audio_context.createBufferSource();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);
155
+ this.buffered_time+=c;setTimeout(()=>this.pump(),0)};lb.prototype.pump=function(){this.enabled&&(.2<this.buffered_time-this.audio_context.currentTime||this.bus.send("dac-request-data"))};function pb(a,b,c){this.bus=b;this.socket=void 0;this.id=c||0;this.send_queue=[];this.url=a;this.reconnect_interval=1E4;this.last_connect_attempt=Date.now()-this.reconnect_interval;this.send_queue_limit=64;this.destroyed=!1;this.bus.register("net"+this.id+"-send",function(d){this.send(d)},this)}pb.prototype.handle_message=
156
+ function(a){this.bus&&this.bus.send("net"+this.id+"-receive",new Uint8Array(a.data))};pb.prototype.handle_close=function(){this.destroyed||(this.connect(),setTimeout(this.connect.bind(this),this.reconnect_interval))};pb.prototype.handle_open=function(){for(var a=0;a<this.send_queue.length;a++)this.send(this.send_queue[a]);this.send_queue=[]};pb.prototype.handle_error=function(){};pb.prototype.destroy=function(){this.destroyed=!0;this.socket&&this.socket.close()};pb.prototype.connect=function(){if("undefined"!==
157
+ 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);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)}}};
158
+ pb.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())};pb.prototype.change_proxy=function(a){this.url=a;this.socket&&(this.socket.onclose=function(){},this.socket.onerror=function(){},this.socket.close(),this.socket=void 0)};const qb=(new Date("1970-01-01T00:00:00Z")).getTime(),rb=(new Date("1900-01-01T00:00:00Z")).getTime(),
159
+ sb=qb-rb,tb=Math.pow(2,32),ub=[118,56,54];function Bb(a){return[0,1,2,3,4,5].map(b=>a[b].toString(16)).map(b=>1===b.length?"0"+b:b).join(":")}function Cb(a){return a[0]<<24|a[1]<<16|a[2]<<8|a[3]}class Db{constructor(a,b){a=Math.min(a,16);this.maximum_capacity=b?Math.max(b,a):0;this.length=this.head=this.tail=0;this.buffer=new Uint8Array(a)}write(a){const b=a.length;var c=this.length+b;let d=this.buffer.length;if(d<c){for(;d<c;)d*=2;if(this.maximum_capacity&&d>this.maximum_capacity)throw Error("stream capacity overflow in GrowableRingbuffer.write(), package dropped");
160
160
  c=new Uint8Array(d);this.peek(c);this.tail=0;this.head=this.length;this.buffer=c}c=this.buffer;const e=this.head+b;if(e>d){const f=d-this.head;c.set(a.subarray(0,f),this.head);c.set(a.subarray(f))}else c.set(a,this.head);this.head=e%d;this.length+=b}peek(a){const b=Math.min(this.length,a.length);if(b){const e=this.buffer;var c=e.length,d=this.tail+b;d>c?(d%=c,c-=this.tail,a.set(e.subarray(this.tail)),a.set(e.subarray(0,d),c)):a.set(e.subarray(this.tail,d))}return b}remove(a){a>this.length&&(a=this.length);
161
161
  a&&(this.tail=(this.tail+a)%this.buffer.length,this.length-=a);return a}}function Eb(a=1500){const b=a-20,c=b-8,d=new Uint8Array(14+a+4),e=d.buffer,f=d.byteOffset;return{eth_frame:d,eth_frame_view:new DataView(e),eth_payload_view:new DataView(e,f+14,a),ipv4_payload_view:new DataView(e,f+34,b),udp_payload_view:new DataView(e,f+42,c),text_encoder:new TextEncoder}}function Fb(a,b,c,d){d.eth_frame.set(b,c.byteOffset+a);return b.length}function Gb(a,b,c,d){const e=c.byteOffset+(a&-2);d=d.eth_frame;for(c=
162
162
  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 Hb(a,b){a.eth_frame.fill(0);var c=a.eth_frame,d=c.subarray,e=a.eth_frame_view;Fb(0,b.eth.dest,e,a);Fb(6,b.eth.src,e,a);e.setUint16(12,b.eth.ethertype);e=14;if(b.arp){var f=a.eth_payload_view;f.setUint16(0,b.arp.htype);f.setUint16(2,b.arp.ptype);f.setUint8(4,b.arp.sha.length);f.setUint8(5,b.arp.spa.length);f.setUint16(6,b.arp.oper);Fb(8,b.arp.sha,f,a);Fb(14,b.arp.spa,f,a);Fb(18,b.arp.tha,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "v86",
3
- "version": "0.5.460+g73077e9",
3
+ "version": "0.5.462+g5f9a90f",
4
4
  "license": "BSD-2-Clause",
5
5
  "description": "x86 PC emulator and x86-to-wasm JIT, running in the browser",
6
6
  "homepage": "https://copy.sh/v86/",