v86 0.5.253 → 0.5.262
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 +49 -40
- package/build/libv86-debug.mjs +274 -273
- package/build/libv86.js +4 -3
- package/build/libv86.mjs +141 -141
- package/build/v86-debug.wasm +0 -0
- package/build/v86-fallback.wasm +0 -0
- package/build/v86.wasm +0 -0
- package/package.json +1 -1
package/build/libv86-debug.mjs
CHANGED
|
@@ -335,278 +335,279 @@ d=0;const e={};for(let g=0;g<c.length;g++){const k=c[g];var f=void 0;if(k.includ
|
|
|
335
335
|
b+="JIT_CACHE_SIZE="+a.wm.exports.jit_get_cache_size()+"\n";b+="FLAT_SEGMENTS="+a.wm.exports.has_flat_segmentation()+"\n";b+="wasm memory size: "+(a.wasm_memory.buffer.byteLength>>20)+"m\n";b=b+"Config:\nJIT_DISABLED="+(a.wm.exports.get_jit_config(0)+"\n");b+="MAX_PAGES="+a.wm.exports.get_jit_config(1)+"\n";b+="JIT_USE_LOOP_SAFETY="+!!a.wm.exports.get_jit_config(2)+"\n";b+="MAX_EXTRA_BASIC_BLOCKS="+a.wm.exports.get_jit_config(3)+"\n";a=[jb(a,!1,!1,!1,!1),jb(a,!0,!1,!1,!1),jb(a,!1,!0,!1,!1),jb(a,!1,
|
|
336
336
|
!1,!0,!1),jb(a,!1,!1,!1,!0)].join("\n\n");return b+a};function xc(a){this.message=a||"File not found"}xc.prototype=Error.prototype;"undefined"!==typeof module&&"undefined"!==typeof module.exports?module.exports.V86=N:"undefined"!==typeof window?window.V86=N:"function"===typeof importScripts&&(self.V86=N);function H(a,b){this.stopping=this.running=!1;this.idle=!0;this.tick_counter=0;this.worker=null;this.cpu=new P(a,b,()=>{this.idle&&this.next_tick(0)});this.bus=a;this.register_yield()}H.prototype.run=
|
|
337
337
|
function(){this.stopping=!1;this.running||(this.running=!0,this.bus.send("emulator-started"));this.next_tick(0)};H.prototype.do_tick=function(){if(this.stopping||!this.running)this.stopping=this.running=!1,this.bus.send("emulator-stopped");else{this.idle=!1;var a=this.cpu.main_loop();this.next_tick(a)}};H.prototype.next_tick=function(a){const b=++this.tick_counter;this.idle=!0;this.yield(a,b)};H.prototype.yield_callback=function(a){a===this.tick_counter&&this.do_tick()};H.prototype.stop=function(){this.running&&
|
|
338
|
-
(this.stopping=!0)};H.prototype.destroy=function(){this.unregister_yield()};H.prototype.restart=function(){this.cpu.reset_cpu();this.cpu.load_bios()};H.prototype.init=function(a){this.cpu.init(a,this.bus);this.bus.send("emulator-ready")};if("undefined"!==typeof process)H.prototype.yield=function(a,b){1>a?global.setImmediate(c=>this.yield_callback(c),b):setTimeout(c=>this.yield_callback(c),a,b)},H.prototype.register_yield=function(){},H.prototype.unregister_yield=function(){};else if(
|
|
339
|
-
typeof Worker){function a(){let b;globalThis.onmessage=function(c){const d=c.data.t;b=b&&clearTimeout(b);1>d?postMessage(c.data.tick):b=setTimeout(()=>postMessage(c.data.tick),d)}}H.prototype.register_yield=
|
|
340
|
-
function(){this.worker
|
|
341
|
-
new Int32Array(d,0,4);(new Uint8Array(d,16,b.length)).set(b);f=new Uint8Array(d,e);k[0]=-2039052682;k[1]=6;k[2]=g;k[3]=b.length;for(e=0;e<a.length;e++)g=a[e],l(g.constructor===Uint8Array),f.set(g,c[e].offset);
|
|
342
|
-
require("perf_hooks");H.microtick=a.now.bind(a)}else H.microtick="object"===typeof process&&process.hrtime?function(){var a=process.hrtime();return 1E3*a[0]+a[1]/1E6}:Date.now;
|
|
343
|
-
this.pm1_enable=this.pm1_status=0;this.last_timer=this.get_timer(H.microtick());this.gpe=new Uint8Array(4);b.register_read(45056,this,void 0,function(){B("ACPI pm1_status read",
|
|
344
|
-
262144);this.
|
|
345
|
-
|
|
346
|
-
n(c),262144);this.gpe[
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
this.modem_status|
|
|
351
|
-
this.
|
|
352
|
-
this.
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
this.
|
|
356
|
-
|
|
357
|
-
a),a=String.fromCharCode(a),this.current_line+=a,"\n"===a&&(a=this.current_line.trimRight().replace(/[\x00-\x08\x0b-\x1f\x7f\x80-\xff]/g,""),B("SERIAL: "+a),this.current_line=""))};
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
function(){
|
|
361
|
-
this.register_device({pci_id:0,pci_space:[134,128,55,18,0,0,0,0,2,0,0,6,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,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,0,0,
|
|
362
|
-
this.register_device(this.isa_bridge);this.isa_bridge_space8=new Uint8Array(this.isa_bridge_space.buffer)}Ac.prototype.get_state=function(){for(var a=[],b=0;256>b;b++)a[b]=this.device_spaces[b];
|
|
363
|
-
65534,f&65534)}}this.device_spaces[b].set(d)}else c&&B("Warning: While restoring PCI device: Device exists in current configuration but not in snapshot ("+c.name+")"),d&&B("Warning: While restoring PCI device: Device doesn't exist in current configuration but does in snapshot (device "+
|
|
364
|
-
252,c=a>>3&31;var d="query enabled="+(this.pci_addr[3]>>7)+(" bdf="+n(a,4));d+=" dev="+n(c,2);d+=" addr="+n(b,2);c=this.device_spaces[a];void 0!==c?(this.pci_status32[0]=-2147483648,this.pci_response32[0]=b<c.byteLength?c[b>>2]:0,d+=" "+n(this.pci_addr32[0]>>>0,8)+" -> "+n(this.pci_response32[0]>>>
|
|
365
|
-
new Uint8Array(this.device_spaces[c].buffer),e=this.devices[c];d&&(l(!(16<=a&&44>a||48<=a&&52>a),"PCI: Expected 32-bit write, got 8-bit (addr: "+n(a)+")"),B("PCI write8 dev="+n(c>>3,2)+" ("+e.name+") addr="+n(a,4)+" value="+n(b,2),2048),d[a]=b)};Ac.prototype.pci_write16=function(a,b){l(0===(a&1));var c=
|
|
366
|
-
n(a)+")"),B("PCI writ16 dev="+n(c>>3,2)+" ("+e.name+") addr="+n(a,4)+" value="+n(b,4),2048),d[a>>>1]=b))};Ac.prototype.pci_write32=function(a,b){l(0===(a&3));var c=a>>8&65535;a&=255;var d=this.device_spaces[c],e=this.devices[c];if(d)if(16<=a&&40>a){var f=a-16>>
|
|
367
|
-
1)|e,0===e&&(d[c]=b)):0===e&&(f=g.original_bar,(b&-16)!==(f&-16)&&B("Warning: Changing memory bar not supported, ignored",2048),d[c]=f),1===e&&(l(1===e),e=d[c]&65534,f=b&65534,B("io bar changed from "+n(e>>>0,8)+" to "+n(f>>>0,8)+" size="+g.size,2048),this.set_io_bars(g,
|
|
368
|
-
0:0):4===a?B("PCI write dev="+n(c>>3,2)+" ("+e.name+") addr="+n(a,4)+" value="+n(b>>>0,8),2048):(B("PCI write dev="+n(c>>3,2)+" ("+e.name+") addr="+n(a,4)+" value="+n(b>>>0,8),2048),d[a>>>2]=b)};Ac.prototype.register_device=function(a){l(void 0!==a.pci_id);l(void 0!==
|
|
369
|
-
var c=new Int32Array(64);c.set(new Int32Array((new Uint8Array(a.pci_space)).buffer));this.device_spaces[b]=c;this.devices[b]=a;b=c.slice(4,10);for(var d=0;d<a.pci_bars.length;d++){var e=a.pci_bars[d];if(e){var f=b[d],g=f&1;B("device "+a.name+" register bar of size "+
|
|
370
|
-
" count="+d,2048);for(var e=this.io.ports,f=0;f<d;f++){4096<=b+f&&(e[b+f]=this.io.create_empty_entry());var g=a.entries[f],k=e[c+f];l(g&&k);4096<=c+f&&(e[c+f]=g)}};Ac.prototype.raise_irq=function(a){var b=this.device_spaces[a];l(b);this.cpu.device_raise_irq(this.isa_bridge_space8[96+
|
|
371
|
-
b[0]&&a[1]===b[1]&&a[2]===b[2]&&a[3]===b[3]&&a[4]===b[4]&&a[5]===b[5]&&(B("Replace mac in eth destination field",1048576),a[0]=c[0],a[1]=c[1],a[2]=c[2],a[3]=c[3],a[4]=c[4],a[5]=c[5]);a[6]===b[0]&&a[7]===b[1]&&a[8]===b[2]&&a[9]===b[3]&&a[10]===b[4]&&a[11]===b[5]&&(B("Replace mac in eth source field",
|
|
372
|
-
(a[0]&15),"TODO: ihl!=5"),17===a[9]){a=a.subarray(20);d=a[0]<<8|a[1];var e=a[2]<<8|a[3];B("udp srcport="+d+" dstport="+e+" checksum="+n(a[6]<<8|a[7],4),1048576);if(67===d||67===e)if(d=a.subarray(8),e=d[236]<<24|d[237]<<16|d[238]<<8|d[239],1669485411!==e)B("dhcp packet didn't match magic: "+n(e,8));
|
|
373
|
-
a[7]=0),e=240;e<d.length;){const f=d[e++];if(255===f)break;const g=d[e++];61===f&&1===d[e+0]&&d[e+1]===b[0]&&d[e+2]===b[1]&&d[e+3]===b[2]&&d[e+4]===b[3]&&d[e+5]===b[4]&&d[e+6]===b[5]&&(B("Replace mac in dhcp.clientidentifier",1048576),d[e+1]=c[0],d[e+2]=c[1],d[e+3]=c[2],d[e+4]=c[3],d[e+5]=c[4],d[e+
|
|
374
|
-
b[4]&&a[13]===b[5]&&(B("Replace mac in arp.sha",1048576),a[8]=c[0],a[9]=c[1],a[10]=c[2],a[11]=c[3],a[12]=c[4],a[13]=c[5]))}function Cc(a){return[a[0].toString(16).padStart(2,"0"),a[1].toString(16).padStart(2,"0"),a[2].toString(16).padStart(2,"0"),a[3].toString(16).padStart(2,"0"),a[4].toString(16).padStart(2,
|
|
375
|
-
b;this.bus.register("net"+this.id+"-receive",function(f){this.receive(f)},this);this.port=768+256*this.id;this.name="ne2k";this.pci_space=[236,16,41,128,3,1,0,0,0,0,0,2,0,0,0,0,this.port&255|1,this.port>>8,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,244,26,0,17,0,0,184,254,0,0,0,0,0,0,0,0,0,1,0,
|
|
376
|
-
this.tsr=1;this.mac=new Uint8Array([0,34,21,255*Math.random()|0,255*Math.random()|0,255*Math.random()|0]);this.bus.send("net"+this.id+"-mac",Cc(this.mac));this.mar=Uint8Array.of(255,255,255,255,255,255,255,255);this.mac_address_in_state=null;for(b=0;6>b;b++)this.memory[b<<1]=this.memory[b<<1|1]=this.mac[b];
|
|
377
|
-
0,this,function(){B("Read cmd",1048576);return this.cr},function(){B("Read16 cmd",1048576);return this.cr});b.register_write(this.port|0,this,function(f){this.cr=f;B("Write command: "+n(f,2)+" newpg="+(this.cr>>6)+" txcr="+n(this.txcr,2),1048576);this.cr&1||(f&24&&0===this.rcnt&&this.do_interrupt(64),
|
|
378
|
-
[f.length]),this.cr&=-5,this.do_interrupt(2),B("Command: Transfer. length="+n(f.byteLength),1048576)))});b.register_read(this.port|13,this,function(){var f=this.get_page();if(1===f)return B("Read mar5",1048576),this.mar[5];B("Read counter0 pg="+f,1048576);return 0});b.register_read(this.port|
|
|
379
|
-
|
|
380
|
-
if(2===f)return this.pstart;B("Read pg"+f+"/01");l(!1);return 0});b.register_write(this.port|1,this,function(f){var g=this.get_page();0===g?(B("start page: "+n(f,2),1048576),this.pstart=f):1===g?(B("mac[0] = "+n(f),1048576),this.mac[0]=f):3===g?B("Unimplemented: Write pg3/01 (9346CR): "+
|
|
381
|
-
|
|
382
|
-
this.
|
|
383
|
-
|
|
384
|
-
f
|
|
385
|
-
this.get_page();
|
|
386
|
-
|
|
387
|
-
this.
|
|
388
|
-
this.
|
|
389
|
-
|
|
390
|
-
n(f),1048576),this.mac[4]=f):3===g?B("Unimplemented: Write pg3/05 (CONFIG2): "+n(f),1048576):(B("Write pg"+g+"/05: "+n(f),1048576),l(!1))});b.register_read(this.port|6,this,function(){var f=this.get_page();if(0===f)return l(!1,"TODO"),0;if(1===f)return B("Read pg1/06 (mac[5])",1048576),
|
|
391
|
-
2),1048576),this.tcnt=this.tcnt&255|f<<8):1===g?(B("mac[5] = "+n(f),1048576),this.mac[5]=f):3===g?B("Unimplemented: Write pg3/06 (CONFIG3): "+n(f),1048576):(B("Write pg"+g+"/06: "+n(f),1048576),l(!1))});b.register_read(this.port|12,this,function(){var f=this.get_page();if(0===f)return 9;
|
|
392
|
-
n(f,2),1048576),this.rxcr=f):B("Unimplemented: Write pg"+g+"/0c: "+n(f),1048576)});b.register_read(this.port|16,this,this.data_port_read8,this.data_port_read16,this.data_port_read32);b.register_write(this.port|16,this,this.data_port_write16,this.data_port_write16,this.data_port_write32);
|
|
393
|
-
this.
|
|
394
|
-
(this.mac_address_in_state=a[15],this.memory=a[16],B("Using mac address translation guest_os_mac="+Cc(this.mac_address_in_state)+" real_mac="+Cc(this.mac),1048576));this.bus.send("net"+this.id+"-mac",Cc(this.mac))};Dc.prototype.do_interrupt=function(a){B("Do interrupt "+n(a,2),1048576);
|
|
395
|
-
this.rsar&&32768>this.rsar)this.memory[this.rsar]=a;this.rsar++;this.rcnt--;this.rsar>=this.pstop<<8&&(this.rsar+=this.pstart-this.pstop<<8);0===this.rcnt&&this.do_interrupt(64)};Dc.prototype.data_port_write16=function(a){this.data_port_write(a);this.dcfg&1&&this.data_port_write(a>>8)};
|
|
396
|
-
(a=this.memory[this.rsar]);this.rsar++;this.rcnt--;this.rsar>=this.pstop<<8&&(this.rsar+=this.pstart-this.pstop<<8);0===this.rcnt&&this.do_interrupt(64);return a};Dc.prototype.data_port_read8=function(){return this.data_port_read16()&255};Dc.prototype.data_port_read16=function(){return this.dcfg&
|
|
397
|
-
24};Dc.prototype.receive=function(a){if(!(this.cr&1)&&(this.bus.send("eth-receive-end",[a.length]),this.rxcr&16||this.rxcr&4&&255===a[0]&&255===a[1]&&255===a[2]&&255===a[3]&&255===a[4]&&255===a[5]||!(this.rxcr&8&&1===(a[0]&1)||a[0]!==this.mac[0]||a[1]!==this.mac[1]||a[2]!==this.mac[2]||
|
|
398
|
-
1+(c>>8),f=b+c,g=1+(c>>8),k=this.boundary>this.curpg?this.boundary-this.curpg:this.pstop-this.curpg+this.boundary-this.pstart;k<g&&0!==this.boundary?B("Buffer full, dropping packet pstart="+n(this.pstart)+" pstop="+n(this.pstop)+" curpg="+n(this.curpg)+" needed="+n(g)+" boundary="+n(this.boundary)+
|
|
399
|
-
d),60>a.length&&this.memory.fill(0,d+a.length,d+60)),e>=this.pstop&&(e+=this.pstart-this.pstop),this.memory[b]=1,this.memory[b+1]=e,this.memory[b+2]=c,this.memory[b+3]=c>>8,this.curpg=e,B("rcv offset="+n(b)+" len="+n(c)+" next="+n(e),1048576),this.do_interrupt(1))}};Dc.prototype.get_page=
|
|
400
|
-
notify_offset:3}];for(let c=1;c<this.ports;++c)b.push({size_supported:16,notify_offset:0}),b.push({size_supported:8,notify_offset:1});this.virtio=new Fc(a,{name:"virtio-console",pci_id:96,device_id:4163,subsystem_device_id:3,common:{initial_port:47104,queues:b,features:[0,
|
|
401
|
-
this.bus.send("virtio-console"+e+"-output-bytes",g);this.Ack(c,f)}},c=>{if(2!==c)l(!1,"VirtioConsole Notified for wrong queue: "+c+" (expected queue_id of 2)");else for(c=this.virtio.queues[c];c.count_requests()>c.size-2;)c.pop_request()},c=>{if(3!==c)l(!1,
|
|
402
|
-
g[0];g=g[1];this.Ack(c,e);switch(g){case 0:for(e=0;e<this.ports;++e)this.SendEvent(e,1,0);break;case 3:this.Ack(c,e);this.SendEvent(f,4,1);this.SendName(f,"virtio-"+f);this.SendEvent(f,6,1);break;case 6:this.Ack(c,e);0===f&&this.SendWindowSize(f);break;default:l(!1,
|
|
403
|
-
{}},{bytes:4,name:"max_nr_ports",read:()=>this.ports,write:()=>{}},{bytes:4,name:"emerg_wr",read:()=>0,write:()=>{l(!1,"Emergency write!")}}]}});for(let c=0;c<this.ports;++c){const d=0===c?0:2*c+2;this.bus.register("virtio-console"+c+"-input-bytes",function(e){var f=
|
|
404
|
-
this.virtio.queues[2].has_request()&&this.SendWindowSize(c,e[0],e[1])},this)}}Ec.prototype.SendWindowSize=function(a,b,c){c=c||this.rows;b=b||this.cols;const d=this.virtio.queues[2].pop_request(),e=new Uint8Array(12);I(["w","h","h","h","h"],[a,5,0,c,b],e,0);this.Send(2,
|
|
405
|
-
0;this.Send(2,c,d)};Ec.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.rows;a[2]=this.cols;a[3]=this.ports;return a};Ec.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.rows=a[1];this.cols=a[2];this.ports=a[3]};Ec.prototype.reset=function(){this.virtio.reset()};
|
|
406
|
-
this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};Ec.prototype.Ack=function(a,b){b.set_next_blob(new Uint8Array(0));this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};function Gc(a,b){this.cpu=a;this.bus=b;this.reset();this.bus.register("keyboard-code",
|
|
407
|
-
c[1])},this);this.bus.register("mouse-wheel",function(c){this.wheel_movement-=c[0];this.wheel_movement-=2*c[1];this.wheel_movement=Math.min(7,Math.max(-8,this.wheel_movement));this.send_mouse_packet(0,0)},this);a.io.register_read(96,this,this.port60_read);a.io.register_read(100,this,this.port64_read);
|
|
408
|
-
this.mouse_delta_y=this.mouse_delta_x=0;this.have_keyboard=!0;this.next_read_resolution=this.next_read_rate=this.next_handle_scan_code_set=this.next_read_led=this.next_read_sample=this.next_is_mouse_command=this.enable_keyboard_stream=!1;this.kbd_buffer=new na(1024);this.last_port60_byte=0;this.sample_rate=
|
|
409
|
-
this.next_byte_is_ready=!1;this.command_register=5;this.controller_output_port=0;this.read_controller_output_port=this.read_command_register=this.read_output_register=!1};Gc.prototype.get_state=function(){var a=[];a[0]=this.enable_mouse_stream;a[1]=this.use_mouse;a[2]=this.have_mouse;a[3]=
|
|
410
|
-
this.
|
|
411
|
-
a[
|
|
412
|
-
this.read_command_register=a[22];this.controller_output_port=a[23];this.read_controller_output_port=a[24];this.mouse_id=a[25]||0;this.mouse_detect_state=a[26]||0;this.mouse_reset_workaround=a[27]||!1;this.next_byte_is_aux=this.next_byte_is_ready=!1;this.kbd_buffer.clear();this.mouse_buffer.clear();this.bus.send("mouse-enable",
|
|
413
|
-
function(){this.next_byte_is_aux=this.next_byte_is_ready=!0;this.command_register&2&&(B("Mouse irq",64),this.cpu.device_lower_irq(12),this.cpu.device_raise_irq(12))};Gc.prototype.kbd_irq=function(){this.next_byte_is_ready=!0;this.next_byte_is_aux=!1;this.command_register&1&&(B("Keyboard irq",64),this.cpu.device_lower_irq(1),
|
|
414
|
-
function(a,b){this.have_mouse&&this.use_mouse&&(this.mouse_delta_x+=1*a,this.mouse_delta_y+=1*b,this.enable_mouse_stream&&(a=this.mouse_delta_x|0,b=this.mouse_delta_y|0,a||b))&&(this.mouse_delta_x-=a,this.mouse_delta_y-=b,this.send_mouse_packet(a,b))};Gc.prototype.mouse_send_click=function(a,b,c){this.have_mouse&&
|
|
415
|
-
this.last_mouse_packet=Date.now();this.mouse_buffer.push(c);this.mouse_buffer.push(a);this.mouse_buffer.push(b);4===this.mouse_id?(this.mouse_buffer.push(0|this.wheel_movement&15),this.wheel_movement=0):3===this.mouse_id&&(this.mouse_buffer.push(this.wheel_movement&255),this.wheel_movement=0);this.raise_irq()};
|
|
416
|
-
function(){this.next_byte_is_ready=!1;if(!this.kbd_buffer.length&&!this.mouse_buffer.length)return B("Port 60 read: Empty",64),this.last_port60_byte;this.next_byte_is_aux?(this.cpu.device_lower_irq(12),this.last_port60_byte=this.mouse_buffer.shift(),B("Port 60 read (mouse): "+n(this.last_port60_byte),
|
|
417
|
-
return this.last_port60_byte};Gc.prototype.port64_read=function(){var a=16;this.next_byte_is_ready&&(a|=1);this.next_byte_is_aux&&(a|=32);B("port 64 read: "+n(a),64);return a};Gc.prototype.port60_write=function(a){B("port 60 write: "+n(a),64);if(this.read_command_register)this.command_register=
|
|
418
|
-
this.mouse_irq();else if(this.next_read_sample){this.next_read_sample=!1;this.mouse_buffer.clear();this.mouse_buffer.push(250);this.sample_rate=a;switch(this.mouse_detect_state){case -1:60===a?(this.mouse_reset_workaround=!0,this.mouse_detect_state=0):(this.mouse_reset_workaround=!1,this.mouse_detect_state=
|
|
419
|
-
case 3:80===a&&(this.mouse_id=4),this.mouse_detect_state=-1}B("mouse sample rate: "+n(a)+", mouse id: "+n(this.mouse_id),64);this.sample_rate||(B("invalid sample rate, reset to 100",64),this.sample_rate=100);this.mouse_irq()}else if(this.next_read_resolution)this.next_read_resolution=!1,this.mouse_buffer.clear(),
|
|
420
|
-
|
|
421
|
-
64);this.scaling2=!1;break;case 231:B("Scaling 2:1",64);this.scaling2=!0;break;case 232:this.next_read_resolution=!0;break;case 233:this.send_mouse_packet(0,0);break;case 235:B("unimplemented request single packet",64);this.send_mouse_packet(0,0);break;case 242:B("required id: "+n(this.mouse_id),64);this.mouse_buffer.push(this.mouse_id);
|
|
422
|
-
|
|
423
|
-
0);this.mouse_clicks=this.mouse_delta_x=this.mouse_delta_y=0;break;default:B("Unimplemented mouse command: "+n(a),64)}this.mouse_irq()}}else if(this.read_controller_output_port)this.read_controller_output_port=!1,this.controller_output_port=a;else{B("Port 60 data register write: "+n(a),64);this.mouse_buffer.clear();this.kbd_buffer.clear();
|
|
424
|
-
break;case 243:this.next_read_rate=!0;break;case 244:B("kbd enable scanning",64);this.enable_keyboard_stream=!0;break;case 245:B("kbd disable scanning",64);this.enable_keyboard_stream=!1;break;case 246:break;case 255:this.kbd_buffer.clear();this.kbd_buffer.push(250);this.kbd_buffer.push(170);this.kbd_buffer.push(0);break;
|
|
425
|
-
this.mouse_buffer.clear();this.kbd_buffer.push(this.command_register);this.kbd_irq();break;case 96:this.read_command_register=!0;break;case 209:this.read_controller_output_port=!0;break;case 211:this.read_output_register=!0;break;case 212:this.next_is_mouse_command=!0;break;case 167:B("Disable second port",64);this.command_register|=
|
|
426
|
-
break;case 170:this.kbd_buffer.clear();this.mouse_buffer.clear();this.kbd_buffer.push(85);this.kbd_irq();break;case 171:this.kbd_buffer.clear();this.mouse_buffer.clear();this.kbd_buffer.push(0);this.kbd_irq();break;case 173:B("Disable Keyboard",64);this.command_register|=16;break;case 174:B("Enable Keyboard",64);this.command_register
|
|
427
|
-
Ic={size:1,get:Hc.getUint8,set:Hc.setUint8},Jc={size:2,get:Hc.getUint16,set:Hc.setUint16},Q={size:4,get:Hc.getUint32,set:Hc.setUint32},Lc=Kc([{magic:Q},{class:Ic},{data:Ic},{version0:Ic},{osabi:Ic},{abiversion:Ic},{pad0:function(a){return{size:a,get:()=>-1}}(7)},{type:Jc},{machine:Jc},{version1:Q},{entry:Q},{phoff:Q},{shoff:Q},{flags:Q},
|
|
428
|
-
{vaddr:Q},{paddr:Q},{filesz:Q},{memsz:Q},{flags:Q},{align:Q}]);console.assert(32===Mc.reduce((a,b)=>a+b.size,0));const Nc=Kc([{name:Q},{type:Q},{flags:Q},{addr:Q},{offset:Q},{size:Q},{link:Q},{info:Q},{addralign:Q},{entsize:Q}]);console.assert(40===Nc.reduce((a,b)=>a+b.size,0));function Kc(a){return a.map(function(b){var c=Object.keys(b);
|
|
429
|
-
e.get.call(a,d,!0),console.assert(void 0===c[e.name]),c[e.name]=b,d+=e.size;return[c,d]}function Pc(a,b,c){const d=[];let e=0;for(var f=0;f<c;f++){const [g,k]=Oc(new DataView(a.buffer,a.byteOffset+e,void 0),b);d.push(g);e+=k}return[d,e]}const Qc={[0]:0,[1]:525,[2]:525,[3]:350,[4]:350,[5]:350};function W(a,b,c,d){this.io=
|
|
430
|
-
this.cmd_code=0;this.cmd_buffer=new Uint8Array(17);this.cmd_remaining=this.cmd_cursor=0;this.response_data=new Uint8Array(15);this.reset_sense_int_count=this.curr_drive_no=this.status1=this.status0=this.response_length=this.response_cursor=0;this.locked=!1;this.head_load_time=this.step_rate_interval=0;this.fdc_config=
|
|
431
|
-
this.
|
|
432
|
-
this.io.register_write(1013,this,this.write_reg_fifo);this.io.register_write(1015,this,this.write_reg_ccr);B("floppy controller ready",8192)}W.prototype.build_cmd_lookup_table=function(){const a=[{code:6,mask:31,argc:8,name:"READ",handler:this.exec_read},{code:5,mask:63,argc:8,name:"WRITE",
|
|
433
|
-
handler:this.
|
|
434
|
-
|
|
435
|
-
{code:
|
|
436
|
-
argc:
|
|
437
|
-
for(let c=a.length-1;0<=c;c--){const d=a[c];if(255===d.mask)b[d.code]=d;else for(let e=0;256>e;e++)(e&d.mask)===d.code&&(b[e]=d)}return b};W.prototype.raise_irq=function(a){this.sra&128||(this.cpu.device_raise_irq(6),this.sra|=128,B("IRQ raised, reason: "+a,8192));this.reset_sense_int_count=0};W.prototype.lower_irq=
|
|
438
|
-
1;return this.drives[this.curr_drive_no]};W.prototype.enter_command_phase=function(){this.cmd_phase=1;this.cmd_remaining=this.cmd_cursor=0;this.msr&=-81;this.msr|=128};W.prototype.enter_result_phase=function(a){this.cmd_phase=3;this.response_cursor=0;this.response_length=a;this.msr|=208};W.prototype.reset_fdc=function(){B("resetting controller",
|
|
439
|
-
0;this.drives[0].seek(0,0,1);this.drives[1].seek(0,0,1);this.enter_command_phase();this.raise_irq("controller reset");this.reset_sense_int_count=4};W.prototype.read_reg_sra=function(){B("SRA read: "+n(this.sra),8192);return this.sra};W.prototype.read_reg_srb=function(){B("SRB read: "+n(this.srb),8192);return this.srb};W.prototype.read_reg_dor=
|
|
440
|
-
W.prototype.read_reg_msr=function(){B("MSR read: "+n(this.msr),8192);this.dsr&=-65;this.dor|=4;return this.msr};W.prototype.read_reg_fifo=function(){this.dsr&=-65;if(!(this.msr&128&&this.msr&64))return B("FIFO read rejected: controller not ready for reading",8192),0;if(3!==this.cmd_phase)return B("FIFO read rejected: floppy controller not in RESULT phase, phase: "+
|
|
441
|
-
this.response_length){const b="end of "+this.cmd_table[this.cmd_code].name+" response";this.msr&=-129;this.enter_command_phase();this.lower_irq(b)}return a}B("FIFO read: empty",8192);return 0};W.prototype.read_reg_dir=function(){const a=this.drives[this.curr_drive_no].media_changed?128:0;B("DIR read: "+n(a),8192);return a};W.prototype.write_reg_dor=function(a){this.srb=
|
|
442
|
-
8192));const b=a&3;B("DOR write: "+n(a)+", motors: "+n(a>>4)+", dma: "+!!(a&8)+", reset: "+!(a&4)+", drive: "+b,8192);1<b&&B("*** WARNING: floppy drive number "+b+" not implemented!",8192);this.curr_drive_no=b&1;this.dor=a};W.prototype.write_reg_tdr=function(a){this.dor&4?(B("TDR write: "+n(a),8192),this.tdr=a&4):B("TDR write "+n(a)+" rejected: Floppy controller in RESET mode!",
|
|
443
|
-
this.dor|=4),a&64&&this.reset_fdc(),this.dsr=a):B("DSR write: "+n(a)+" rejected: Floppy controller in RESET mode!",8192)};W.prototype.write_reg_fifo=function(a){this.dsr&=-65;if(this.dor&4)if(!(this.msr&128)||this.msr&64)B("FIFO write "+n(a)+" rejected: controller not ready for writing",8192);else if(1!==this.cmd_phase)B("FIFO write "+n(a)+" rejected: floppy controller not in COMMAND phase, phase: "+
|
|
444
|
-
b.argc;this.cmd_flags=this.cmd_cursor=0;(6===b.code||5===b.code)&&this.cmd_code&128&&(this.cmd_flags|=1);this.cmd_remaining&&(this.msr|=128);this.msr|=16}else this.cmd_buffer[this.cmd_cursor++]=a,this.cmd_remaining--;if(0===this.cmd_remaining){this.cmd_phase=2;a=this.cmd_table[this.cmd_code];b=this.cmd_buffer.slice(0,this.cmd_cursor);const c=[];for(const d of b)c.push(n(d,2));B("FD command "+
|
|
445
|
-
" rejected: floppy controller in RESET mode!",8192)};W.prototype.write_reg_ccr=function(a){this.dor&4?(B("CCR write: "+n(a),8192),this.dsr=this.dsr&-4|a&3):B("CCR write: "+n(a)+" rejected: Floppy controller in RESET mode!",8192)};W.prototype.exec_unimplemented=function(){l(!1,"Unimplemented floppy command code "+n(this.cmd_code)+"!");this.status0=128;this.response_data[0]=this.status0;this.enter_result_phase(1)};
|
|
446
|
-
function(a){this.start_read_write(a,!0)};W.prototype.exec_seek=function(a){const b=this.set_curr_drive_no(a[0]&1);a=a[1];this.enter_command_phase();b.seek(b.curr_head,a,b.curr_sect);this.status0|=32;this.raise_irq("SEEK command")};W.prototype.exec_sense_interrupt_status=function(){const a=this.drives[this.curr_drive_no];let b;if(0<this.reset_sense_int_count)b=192|4-this.reset_sense_int_count--;else if(this.sra&128)b=
|
|
447
|
-
8192);this.response_data[0]=128;this.enter_result_phase(1);return}this.response_data[0]=b;this.response_data[1]=a.curr_track;this.enter_result_phase(2);this.lower_irq("SENSE INTERRUPT command");this.status0=192};W.prototype.exec_recalibrate=function(a){this.set_curr_drive_no(a[0]&1).seek(0,0,1);this.enter_command_phase();this.status0|=32;this.raise_irq("RECALIBRATE command")};W.prototype.exec_format_track=
|
|
448
|
-
c,0)};W.prototype.exec_read_id=function(a){const b=this.drives[this.curr_drive_no];b.curr_head=a[0]>>2&1;0!==b.max_sect&&(b.curr_sect=b.curr_sect%b.max_sect+1);this.end_read_write(0,0,0)};W.prototype.exec_specify=function(a){const b=a[1];this.step_rate_interval=a[0]>>4;this.head_load_time=b>>1;this.dor=b&1?this.dor&-9:this.dor|8;this.enter_command_phase()};W.prototype.exec_sense_drive_status=function(a){a=
|
|
449
|
-
64:0)|(0===b.curr_track?16:0)|b.curr_head<<2|this.curr_drive_no|40;this.enter_result_phase(1)};W.prototype.exec_perpendicular_mode=function(a){a=a[0];a&128&&(this.drives[this.curr_drive_no].perpendicular=a&7);this.enter_command_phase()};W.prototype.exec_configure=function(a){this.fdc_config=a[1];this.precomp_trk=a[2];this.enter_command_phase()};W.prototype.exec_lock=function(){this.cmd_code&128?(this.locked
|
|
450
|
-
W.prototype.exec_dump_regs=function(){const a=this.drives[this.curr_drive_no];this.response_data[0]=this.drives[0].curr_track;this.response_data[1]=this.drives[1].curr_track;this.response_data[2]=0;this.response_data[3]=0;this.response_data[4]=this.step_rate_interval;this.response_data[5]=this.head_load_time<<1|(this.dor&8?1:0);this.response_data[6]=a.max_sect;this.response_data[7]=(this.locked?128:0)|
|
|
451
|
-
this.enter_result_phase(10)};W.prototype.exec_version=function(){this.response_data[0]=144;this.enter_result_phase(1)};W.prototype.exec_part_id=function(){this.response_data[0]=65;this.enter_result_phase(1)};W.prototype.start_read_write=function(a,b){const c=this.set_curr_drive_no(a[0]&1),d=a[1],e=a[2],f=a[3];var g=a[4];const k=a[5];a=128>a[7]?a[7]:128;switch(c.seek(e,d,f)){case 2:this.end_read_write(64,
|
|
452
|
-
128,0);this.response_data[3]=d;this.response_data[4]=e;this.response_data[5]=f;return;case 1:this.status0|=32}const m=128<<(7<g?7:g);g=c.chs2lba(d,e,f)*m;if(128===m)b&&128>a&&l(!1,"dtl="+a+" is less than 128, zero-padding is still unimplemented!");else if(a=this.cmd_flags&1?(2*k-f+1)*m:(k-f+1)*m,0>=a){B("invalid data_length: "+a+" sect="+f+" eot="+k,8192);this.end_read_write(64,1,0);this.response_data[3]=
|
|
453
|
-
" from: "+n(g)+", length: "+n(a)+", C/H/S: "+d+"/"+e+"/"+f+", ro: "+c.read_only+", #S: "+c.max_sect+", #H: "+c.max_head,8192);b&&c.read_only?(this.end_read_write(96,2,0),this.response_data[3]=d,this.response_data[4]=e,this.response_data[5]=f):this.dor&8?(this.msr&=-129,(b?this.dma.do_write:this.dma.do_read).call(this.dma,c.buffer,g,a,2,p=>{p?(B("DMA floppy error",8192),this.end_read_write(64,
|
|
454
|
-
W.prototype.end_read_write=function(a,b,c){const d=this.drives[this.curr_drive_no];this.status0&=-8;this.status0|=this.curr_drive_no;d.curr_head&&(this.status0|=4);this.status0|=a;this.msr|=192;this.msr&=-33;this.response_data[0]=this.status0;this.response_data[1]=b;this.response_data[2]=c;this.response_data[3]=d.curr_track;this.response_data[4]=d.curr_head;this.response_data[5]=
|
|
455
|
-
W.prototype.seek_next_sect=function(){const a=this.drives[this.curr_drive_no];let b=a.curr_track,c=a.curr_head,d=a.curr_sect,e=1;d>=a.max_sect||d===this.eot?(d=1,this.cmd_flags&1?0===c&&2===a.max_head?c=1:(c=0,b++,this.status0|=32,1===a.max_head&&(e=0)):(this.status0|=32,b++,e=0)):d++;a.seek(c,b,d);return e};W.prototype.get_state=function(){const a=[];a[19]=this.sra;a[20]=
|
|
456
|
-
a[28]=this.cmd_buffer;a[29]=this.cmd_cursor;a[30]=this.cmd_remaining;a[31]=this.response_data;a[32]=this.response_cursor;a[33]=this.response_length;a[34]=this.status0;a[35]=this.status1;a[36]=this.curr_drive_no;a[37]=this.reset_sense_int_count;a[38]=this.locked;a[39]=this.step_rate_interval;a[40]=this.head_load_time;a[41]=this.fdc_config;a[42]=this.precomp_trk;a[43]=this.eot;
|
|
457
|
-
typeof a[19]&&(this.sra=a[19],this.srb=a[20],this.dor=a[21],this.tdr=a[22],this.msr=a[23],this.dsr=a[24],this.cmd_phase=a[25],this.cmd_code=a[26],this.cmd_flags=a[27],this.cmd_buffer.set(a[28]),this.cmd_cursor=a[29],this.cmd_remaining=a[30],this.response_data.set(a[31]),this.response_cursor=a[32],this.response_length=a[33],this.status0=a[34],this.status1=a[35],this.curr_drive_no=
|
|
458
|
-
a[41],this.precomp_trk=a[42],this.eot=a[43],this.drives[0].set_state(a[44]),this.drives[1].set_state(a[45]))};const Sc=[{drive_type:4,sectors:18,tracks:80,heads:2},{drive_type:4,sectors:20,tracks:80,heads:2},{drive_type:4,sectors:21,tracks:80,heads:2},{drive_type:4,sectors:21,tracks:82,heads:2},{drive_type:4,sectors:21,tracks:83,heads:2},{drive_type:4,sectors:22,tracks:80,
|
|
459
|
-
heads:2},{drive_type:
|
|
460
|
-
sectors:
|
|
461
|
-
heads:2},{drive_type:2,sectors:8,tracks:40,heads:1},{drive_type:4,sectors:9,tracks:80,heads:1},{drive_type:1,sectors:10,tracks:40,heads:1},{drive_type:1,sectors:10,tracks:40,heads:2}];function Rc(a,b,c,d){this.name=a;this.curr_head=this.curr_track=this.max_sect=this.max_head=this.max_track=this.drive_type=0;this.curr_sect=1;this.perpendicular=0;this.read_only=!1;this.media_changed
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
c-1};Rc.prototype.find_disk_format=function(a,b){const c=0===b,d=a.byteLength;let e=-1,f=-1,g=-1,k=-1,m=-1;for(let p=0;p<Sc.length;p++){const q=Sc[p],r=q.sectors*q.tracks*q.heads*512;if(d===r)if(c||q.drive_type===b){e=p;break}else c||Qc[q.drive_type]!==Qc[b]?g=-1===g?p:g:f=-1===f?p:f;else d<r&&(-1===m||r<m)&&(k=p,m=r)}return-1!==e?[a,Sc[e]]:-1!==f?[a,Sc[f]]:-1!==g?[a,Sc[g]]:-1!==k?(b=new Uint8Array(m),
|
|
465
|
-
b,c){if(b>this.max_track||0!==a&&1===this.max_head)return B("WARNING: attempt to seek to invalid track: head: "+a+", track: "+b+", sect: "+c,8192),2;if(c>this.max_sect)return B("WARNING: attempt to seek beyond last sector: "+c+" (max: "+this.max_sect+")",8192),3;let d=0;const e=this.chs2lba(this.curr_track,this.curr_head,this.curr_sect),f=this.chs2lba(b,a,c);e!==f&&(this.curr_track!==b&&(this.buffer&&
|
|
466
|
-
2);return d};Rc.prototype.get_state=function(){const a=[];a[0]=this.drive_type;a[1]=this.max_track;a[2]=this.max_head;a[3]=this.max_sect;a[4]=this.curr_track;a[5]=this.curr_head;a[6]=this.curr_sect;a[7]=this.perpendicular;a[8]=this.read_only;a[9]=this.media_changed;a[10]=this.buffer?this.buffer.get_state():null;return a};Rc.prototype.set_state=function(a){this.drive_type=a[0];this.max_track=a[1];this.max_head=
|
|
467
|
-
a[7];this.read_only=a[8];this.media_changed=a[9];a[10]?(this.buffer||(this.buffer=new Ba(new ArrayBuffer(0))),this.buffer.set_state(a[10])):this.buffer=null};const Tc={[8]:"DEVICE RESET",[144]:"EXECUTE DEVICE DIAGNOSTIC",[231]:"FLUSH CACHE",[234]:"FLUSH CACHE EXT",[218]:"GET MEDIA STATUS",[236]:"IDENTIFY DEVICE",[161]:"IDENTIFY PACKET DEVICE",[225]:"IDLE IMMEDIATE",[145]:"INITIALIZE DEVICE PARAMETERS",
|
|
468
|
-
[196]:"READ MULTIPLE EXT",[248]:"READ NATIVE MAX ADDRESS",[39]:"READ NATIVE MAX ADDRESS EXT",[32]:"READ SECTORS",[36]:"READ SECTORS EXT",[64]:"READ VERIFY SECTORS",[245]:"SECURITY FREEZE LOCK",[239]:"SET FEATURES",[249]:"SET MAX",[198]:"SET MULTIPLE MODE",[224]:"STANDBY IMMEDIATE",[202]:"WRITE DMA",[53]:"WRITE DMA EXT",[57]:"WRITE MULTIPLE",[197]:"WRITE MULTIPLE EXT",[48]:"WRITE SECTORS",[52]:"WRITE SECTORS EXT",
|
|
469
|
-
flags:0},[74]:{name:"GET EVENT STATUS NOTIFICATION",flags:0},[18]:{name:"INQUIRY",flags:0},[189]:{name:"MECHANISM STATUS",flags:0},[26]:{name:"MODE SENSE (6)",flags:0},[90]:{name:"MODE SENSE (10)",flags:0},[69]:{name:"PAUSE",flags:1},[30]:{name:"PREVENT ALLOW MEDIUM REMOVAL",flags:0},[40]:{name:"READ (10)",flags:1},[168]:{name:"READ (12)",flags:1},[37]:{name:"READ CAPACITY",flags:1},[190]:{name:"READ CD",flags:1},
|
|
470
|
-
flags:1},[82]:{name:"READ TRACK INFORMATION",flags:1},[3]:{name:"REQUEST SENSE",flags:0},[27]:{name:"START STOP UNIT",flags:0},[0]:{name:"TEST UNIT READY",flags:1}};function Vc(a,b,c){this.cpu=a;this.bus=b;this.secondary=this.primary=void 0;b=c&&c[0][0];const d=c&&c[1][0];if(b||d){b&&(this.primary=new Wc(this,0,c[0],496,1014,14));d&&(this.secondary=new Wc(this,1,c[1],368,886,15));c=b?this.primary.command_base:
|
|
471
|
-
0;this.name="ide";this.pci_id=240;this.pci_space=[134,128,16,112,5,0,160,2,0,128,1,1,0,0,0,0,c&255|1,c>>8,0,0,e&255|1,e>>8,0,0,f&255|1,f>>8,0,0,g&255|1,g>>8,0,0,1,180,0,0,0,0,0,0,0,0,0,0,67,16,212,130,0,0,0,0,0,0,0,0,0,0,0,0,0,1,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,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,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,
|
|
472
|
-
void 0,{size:16}];a.devices.pci.register_device(this)}Object.seal(this)}Vc.prototype.get_state=function(){const a=[];a[0]=this.primary;a[1]=this.secondary;return a};Vc.prototype.set_state=function(a){this.primary&&this.primary.set_state(a[0]);this.secondary&&this.secondary.set_state(a[1])};function Wc(a,b,c,d,e,f){this.controller=a;this.channel_nr=b;this.cpu=a.cpu;this.bus=a.bus;this.command_base=
|
|
473
|
-
0,d?.buffer,d?.is_cdrom);this.slave=new X(this,1,c?.buffer,c?.is_cdrom);this.current_interface=this.master;this.device_control_reg=2;this.dma_command=this.dma_status=this.prdt_addr=0;a=a.cpu;a.io.register_read(this.command_base|0,this,function(){return this.current_interface.read_data(1)},function(){return this.current_interface.read_data(2)},function(){return this.current_interface.read_data(4)});
|
|
474
|
-
a.io.register_read(this.command_base|
|
|
475
|
-
255});a.io.register_read(this.command_base|7,this,function(){const g=this.read_status();this.cpu.device_lower_irq(this.irq);return g});a.io.register_write(this.command_base|0,this,function(g){this.current_interface.write_data_port8(g)},function(g){this.current_interface.write_data_port16(g)},function(g){this.current_interface.write_data_port32(g)});a.io.register_write(this.command_base|1,this,function(g){this.current_interface.features_reg=
|
|
476
|
-
2,this,function(g){this.current_interface.sector_count_reg=(this.current_interface.sector_count_reg<<8|g)&65535});a.io.register_write(this.command_base|3,this,function(g){this.current_interface.lba_low_reg=(this.current_interface.lba_low_reg<<8|g)&65535});a.io.register_write(this.command_base|4,this,function(g){this.current_interface.lba_mid_reg=(this.current_interface.lba_mid_reg<<8|g)&65535});a.io.register_write(this.command_base|
|
|
477
|
-
8|g)&65535});a.io.register_write(this.command_base|6,this,function(g){const k=g&16;if(k&&this.current_interface===this.master||!k&&this.current_interface===this.slave)k?(B(`${this.current_interface.name}: select slave device (${this.channel_nr?"secondary":"primary"})`,32768),this.current_interface=this.slave):(B(`${this.current_interface.name}: select master device (${this.channel_nr?"secondary":"primary"})`,
|
|
478
|
-
g>>6&1;this.current_interface.head=g&15});a.io.register_write(this.command_base|7,this,function(g){this.current_interface.status_reg&=-34;this.current_interface.ata_command(g);this.cpu.device_lower_irq(this.irq)});a.io.register_read(this.control_base|0,this,this.read_status);a.io.register_write(this.control_base|0,this,this.write_control);b=46080+8*b;a.io.register_read(b|0,this,this.dma_read_command8,
|
|
479
|
-
a.io.register_read(b|2,this,this.dma_read_status);a.io.register_write(b|2,this,this.dma_write_status);a.io.register_read(b|4,this,void 0,void 0,this.dma_read_addr);a.io.register_write(b|4,this,void 0,void 0,this.dma_set_addr);Object.seal(this)}Wc.prototype.read_status=function(){return this.current_interface.drive_connected?this.current_interface.status_reg:0};Wc.prototype.write_control=
|
|
480
|
-
this.cpu.device_lower_irq(this.irq),this.master.device_reset(),this.slave.device_reset());this.device_control_reg=a};Wc.prototype.dma_read_addr=function(){return this.prdt_addr};Wc.prototype.dma_set_addr=function(a){this.prdt_addr=a};Wc.prototype.dma_read_status=function(){return this.dma_status};Wc.prototype.dma_write_status=function(a){this.dma_status&=~(a&6)};Wc.prototype.dma_read_command=
|
|
481
|
-
Wc.prototype.dma_write_command=function(a){this.dma_write_command8(a&255);this.dma_write_status(a>>16&255)};Wc.prototype.dma_write_command8=function(a){const b=this.dma_command;this.dma_command=a&9;if((b&1)!==(a&1))if(0===(a&1))this.dma_status&=-2;else switch(this.dma_status|=1,this.current_interface.current_command){case 200:case 37:this.current_interface.do_ata_read_sectors_dma();
|
|
482
|
-
break;default:B(this.current_interface.name+": spurious DMA command write, current command: "+n(this.current_interface.current_command),32768),B(this.current_interface.name+": DMA clear status bit 1h, set status bit 2h",32768),this.dma_status&=-2,this.dma_status|=2,this.push_irq()}};Wc.prototype.push_irq=function(){0===(this.device_control_reg&2)&&(this.dma_status|=4,this.cpu.device_raise_irq(this.irq))};
|
|
483
|
-
a[3]=this.irq;a[5]=this.control_base;a[7]=this.name;a[8]=this.device_control_reg;a[9]=this.prdt_addr;a[10]=this.dma_status;a[11]=this.current_interface===this.master;a[12]=this.dma_command;return a};Wc.prototype.set_state=function(a){this.master.set_state(a[0]);this.slave.set_state(a[1]);this.command_base=a[2];this.irq=a[3];this.control_base=a[5];this.name=a[7];this.device_control_reg=a[8];this.prdt_addr=
|
|
484
|
-
a[12]};function X(a,b,c,d){this.channel=a;this.name=a.name+"."+b;this.bus=a.bus;this.channel_nr=a.channel_nr;this.interface_nr=b;this.cpu=a.cpu;this.buffer=null;this.drive_connected=d||!!c;this.sector_size=d?2048:512;this.is_atapi=d;this.sector_count=0;this.head_count=this.is_atapi?1:0;this.device_reg=this.head=this.lba_high_reg=this.lba_mid_reg=this.features_reg=this.lba_low_reg=this.sector_count_reg=
|
|
485
|
-
128;this.data_pointer=this.error_reg=0;this.data=new Uint8Array(65536);this.data16=new Uint16Array(this.data.buffer);this.data32=new Int32Array(this.data.buffer);this.data_end=this.data_length=0;this.current_command=-1;this.last_io_id=this.write_dest=0;this.in_progress_io_ids=new Set;this.cancelled_io_ids=new Set;this.current_atapi_command=-1;this.atapi_add_sense=this.atapi_sense_key=0;this.medium_changed
|
|
486
|
-
"ATA HD"} device ready`,32768);Object.seal(this)}X.prototype.has_disk=function(){return!!this.buffer};X.prototype.eject=function(){this.is_atapi&&this.buffer&&(this.medium_changed=!0,this.buffer=null,this.status_reg=89,this.error_reg=96,this.push_irq())};X.prototype.set_cdrom=function(a){this.is_atapi&&a&&(this.set_disk_buffer(a),this.medium_changed=!0)};X.prototype.set_disk_buffer=function(a){if(a){this.buffer=
|
|
487
|
-
this.sector_size;this.sector_count!==(this.sector_count|0)&&(B(this.name+": warning: disk size not aligned with sector size",32768),this.sector_count=Math.ceil(this.sector_count));this.is_atapi?(this.head_count=1,this.sectors_per_track=2048):(this.head_count=16,this.sectors_per_track=63);this.cylinder_count=this.sector_count/this.head_count/this.sectors_per_track;this.cylinder_count!==(this.cylinder_count|
|
|
488
|
-
this.cylinder_count=Math.floor(this.cylinder_count));if(0===this.interface_nr){a=this.cpu.devices.rtc;a.cmos_write(57,a.cmos_read(57)|1<<4*this.channel_nr);a.cmos_write(18,a.cmos_read(18)&15|240);const b=0===this.channel_nr?27:36;a.cmos_write(b+0,this.cylinder_count&255);a.cmos_write(b+1,this.cylinder_count>>8&255);a.cmos_write(b+2,this.head_count&255);a.cmos_write(b+3,255);a.cmos_write(b+4,255);a.cmos_write(b+
|
|
489
|
-
8&255);a.cmos_write(b+8,this.sectors_per_track&255)}this.channel.cpu&&this.push_irq()}};X.prototype.device_reset=function(){this.is_atapi?(this.status_reg=0,this.lba_low_reg=this.error_reg=this.sector_count_reg=1,this.lba_mid_reg=20,this.lba_high_reg=235):(this.status_reg=81,this.lba_low_reg=this.error_reg=this.sector_count_reg=1,this.lba_high_reg=this.lba_mid_reg=0);this.cancel_io_operations()};X.prototype.push_irq=
|
|
490
|
-
4;this.status_reg=65;this.push_irq()};X.prototype.capture_regs=function(){return`ST=${n(this.status_reg&255)} ER=${n(this.error_reg&255)} `+`SC=${n(this.sector_count_reg&255)} LL=${n(this.lba_low_reg&255)} `+`LM=${n(this.lba_mid_reg&255)} LH=${n(this.lba_high_reg&255)} `+`FE=${n(this.features_reg&255)}`};X.prototype.ata_command=function(a){if(this.drive_connected||144===a){var b=this.capture_regs(),c=!0;this.current_command=
|
|
491
|
-
0;this.device_reset();this.push_irq();break;case 16:this.lba_mid_reg=0;this.status_reg=80;this.push_irq();break;case 248:var d=this.sector_count-1;this.lba_low_reg=d&255;this.lba_mid_reg=d>>8&255;this.lba_high_reg=d>>16&255;this.device_reg=this.device_reg&240|d>>24&15;this.status_reg=80;this.push_irq();break;case 39:d=this.sector_count-1;this.lba_low_reg=d&255;this.lba_mid_reg=d>>8&255;this.lba_high_reg=d>>16&255;
|
|
492
|
-
|
|
493
|
-
this.channel.slave.error_reg=1,this.channel.slave.push_irq());break;case 145:this.status_reg=80;this.push_irq();break;case 160:this.is_atapi?(c=!1,this.data_allocate(12),this.data_end=12,this.sector_count_reg=1,this.status_reg=88,this.push_irq()):this.ata_abort_command();break;case 161:this.is_atapi?(this.create_identify_packet(),this.status_reg=88,this.push_irq()):this.ata_abort_command();break;case 198:B(this.name+": logical sectors per DRQ Block: "+
|
|
494
|
-
this.sector_count_reg&255;this.status_reg=80;this.push_irq();break;case 200:case 37:c=!1;this.ata_read_sectors_dma(a);break;case 202:case 53:c=!1;this.ata_write_sectors_dma(a);break;case 64:this.status_reg=80;this.push_irq();break;case 218:this.is_atapi&&(this.buffer||(this.error_reg|=2),this.medium_changed&&(this.error_reg|=32,this.medium_changed=!1),this.error_reg|=64);this.status_reg=80;this.push_irq();break;case 224:this.status_reg=80;this.push_irq();
|
|
495
|
-
break;case 231:this.status_reg=80;this.push_irq();break;case 234:this.status_reg=80;this.push_irq();break;case 236:this.is_atapi?(this.lba_mid_reg=20,this.lba_high_reg=235,this.ata_abort_command()):(this.create_identify_packet(),this.status_reg=88,this.push_irq());break;case 239:this.status_reg=80;this.push_irq();break;case 222:this.status_reg=64;this.push_irq();break;case 245:this.status_reg=80;this.push_irq();break;case 249:this.ata_abort_command();
|
|
496
|
-
32768);this.ata_abort_command();break;default:l(!1,`${this.name}: error: unimplemented ATA command ${n(a)}: ABORT [${this.capture_regs()}]`,32768),this.ata_abort_command()}c&&(b=`[${b}] -> [${this.capture_regs()}]`,c=this.status_reg&1?this.error_reg&4?"ABORT":"ERROR":"OK",B(`${this.name}: ATA command ${Tc[a]} (${n(a)}): ${c} ${b}`,32768))}else B(`${this.name}: ATA command ${Tc[a]} (${n(a)}) ignored: no slave drive connected`,
|
|
497
|
-
Uc[a].name:"<undefined>";var c=Uc[a]?Uc[a].flags:0,d=this.capture_regs(),e=!0;let f;this.data_pointer=0;this.current_atapi_command=a;3!==a&&(this.atapi_add_sense=this.atapi_sense_key=0);if(!this.buffer&&c&1)this.atapi_check_condition_response(2,58),this.push_irq(),B(`${this.name}: ATAPI command ${b} (${n(a)}) without medium: ERROR [${d}]`,32768);else{switch(a){case 0:this.buffer?(this.data_allocate(0),this.data_end=this.data_length,
|
|
498
|
-
case 3:this.data_allocate(this.data[4]);this.data_end=this.data_length;this.status_reg=88;this.data[0]=240;this.data[2]=this.atapi_sense_key;this.data[7]=8;this.data[12]=this.atapi_add_sense;this.atapi_add_sense=this.atapi_sense_key=0;break;case 18:c=this.data[4];this.status_reg=88;f="lun="+n(this.data[1],2)+" length="+c;this.data.set([5,128,1,49,31,0,0,0,83,79,78,89,32,32,32,32,67,68,45,82,79,77,32,67,68,85,45,49,48,48,48,32,49,
|
|
499
|
-
this.data_end=this.data_length;this.status_reg=88;break;case 30:this.data_allocate(0);this.data_end=this.data_length;this.status_reg=80;break;case 37:c=this.sector_count-1;this.data_set(new Uint8Array([c>>24&255,c>>16&255,c>>8&255,c&255,0,0,this.sector_size>>8&255,this.sector_size&255]));this.data_end=this.data_length;this.status_reg=88;break;case 40:case 168:e=!1;this.features_reg&1?this.atapi_read_dma(this.data):
|
|
500
|
-
c));this.data_end=this.data_length;this.status_reg=88;break;case 67:c=this.data[8]|this.data[7]<<8;var g=this.data[9]>>6;f=`${n(g,2)} length=${c} ${!!(this.data[1]&2)} ${n(this.data[6])}`;this.data_allocate(c);this.data_end=this.data_length;0===g?(c=this.sector_count,this.data.set(new Uint8Array([0,18,1,1,0,20,1,0,0,0,0,0,0,22,170,0,c>>24,c>>16&255,c>>8&255,c&255]))):1===g?this.data.set(new Uint8Array([0,
|
|
501
|
-
88;break;case 70:c=Math.min(this.data[8]|this.data[7]<<8,32);f="length="+c;this.data_allocate(c);this.data_end=this.data_length;this.data[0]=c-4>>24&255;this.data[1]=c-4>>16&255;this.data[2]=c-4>>8&255;this.data[3]=c-4&255;this.data[6]=8;this.data[10]=3;this.status_reg=88;break;case 81:this.data_allocate(0);this.data_end=this.data_length;this.status_reg=80;break;case 82:f="unimplemented";this.atapi_check_condition_response(5,
|
|
502
|
-
n(g)+" length="+c;42===g&&this.data_allocate(Math.min(30,c));this.data_end=this.data_length;this.status_reg=88;break;case 189:this.data_allocate(this.data[9]|this.data[8]<<8);this.data_end=this.data_length;this.data[5]=1;this.status_reg=88;break;case 27:c=this.data[4]&3;f=`Immed=${n(this.data[1]&1)} LoEj/Start=${n(c)}`;this.buffer&&2===c&&(f+=": disk ejected",this.medium_changed=!0,this.buffer=null);this.status_reg=80;
|
|
503
|
-
this.atapi_check_condition_response(5,36);break;case 190:f="unimplemented";this.data_allocate(0);this.data_end=this.data_length;this.status_reg=80;break;default:l(!1,`${this.name}: error: unimplemented ATAPI command ${n(this.data[0])}`,32768),this.atapi_check_condition_response(5,36)}this.sector_count_reg=this.sector_count_reg&-8|2;0===(this.status_reg&128)&&this.push_irq();0===(this.status_reg&128)&&0===
|
|
504
|
-
e=this.status_reg&1?this.error_reg&4?"ABORT":"ERROR":"OK",f=f?` ${f}:`:"",B(`${this.name}: ATAPI command ${b} (${n(a)}):${f} ${e} ${d}`,32768))}};X.prototype.atapi_check_condition_response=function(a,b){this.data_allocate(0);this.data_end=this.data_length;this.status_reg=65;this.error_reg=a<<4;this.sector_count_reg=this.sector_count_reg&-8|3;this.atapi_sense_key=a;this.atapi_add_sense=b};X.prototype.do_write=
|
|
505
|
-
this.data_length);l(0===this.data_length%512);this.ata_advance(this.current_command,this.data_length/512);this.push_irq();this.buffer.set(this.write_dest,a,function(){});this.report_write(this.data_length)};X.prototype.atapi_read=function(a){var b=a[2]<<24|a[3]<<16|a[4]<<8|a[5];a=168===a[0]?a[6]<<24|a[7]<<16|a[8]<<8|a[9]:a[7]<<8|a[8];var c=(a>>>0)*this.sector_size;b*=this.sector_size;this.data_length=0;
|
|
506
|
-
d&&d--;d>c&&(d=c);this.buffer?b>=this.buffer.byteLength?(l(!1,this.name+": CD read: Outside of disk end="+n(b+c)+" size="+n(this.buffer.byteLength),32768),this.status_reg=255,this.push_irq()):0===c?(this.status_reg=80,this.data_pointer=0):(c=Math.min(c,this.buffer.byteLength-b),this.status_reg=208,this.report_read_start(),this.read_buffer(b,c,e=>{this.data_set(e);this.status_reg=88;this.sector_count_reg=
|
|
507
|
-
(this.data_end=this.data_length);this.lba_mid_reg=this.data_end&255;this.lba_high_reg=this.data_end>>8&255;this.report_read_end(c)})):(l(!1,this.name+": CD read: no buffer",32768),this.status_reg=255,this.error_reg=65,this.push_irq())};X.prototype.atapi_read_dma=function(a){var b=a[2]<<24|a[3]<<16|a[4]<<8|a[5],c=168===a[0]?a[6]<<24|a[7]<<16|a[8]<<8|a[9]:a[7]<<8|a[8];c>>>=0;a=a[1];var d=c*this.sector_size,
|
|
508
|
-
" flags="+n(a),32768);e>=this.buffer.byteLength?(l(!1,this.name+": CD read: Outside of disk end="+n(e+d)+" size="+n(this.buffer.byteLength),32768),this.status_reg=255,this.push_irq()):(this.status_reg=208,this.report_read_start(),this.read_buffer(e,d,f=>{B(this.name+": atapi_read_dma: Data arrived",32768);this.report_read_end(d);this.status_reg=88;this.sector_count_reg=this.sector_count_reg&-8|2;this.data_set(f);
|
|
509
|
-
1))B(this.name+": do_atapi_dma: Status not set",32768);else if(0===(this.status_reg&8))B(this.name+": do_atapi_dma: DRQ not set",32768);else{var a=this.channel.prdt_addr,b=0,c=this.data;do{var d=this.cpu.read32s(a),e=this.cpu.read16(a+4),f=this.cpu.read8(a+7)&128;e||(e=65536);this.cpu.write_blob(c.subarray(b,Math.min(b+e,this.data_length)),d);b+=e;a+=8;if(b>=this.data_length&&!f)break}while(!f);this.status_reg=
|
|
510
|
-
X.prototype.read_data=function(a){if(this.data_pointer<this.data_end){l(this.data_pointer+a-1<this.data_end);l(0===this.data_pointer%a,n(this.data_pointer)+" "+a);var b=1===a?this.data[this.data_pointer]:2===a?this.data16[this.data_pointer>>>1]:this.data32[this.data_pointer>>>2];this.data_pointer+=a;this.data_pointer>=this.data_end&&this.read_end();return b}this.data_pointer+=a;return 0};X.prototype.read_end=
|
|
511
|
-
80,this.sector_count_reg=this.sector_count_reg&-8|3,this.push_irq();else{this.status_reg=88;this.sector_count_reg=this.sector_count_reg&-8|2;this.push_irq();var a=this.lba_high_reg<<8&65280|this.lba_mid_reg&255;this.data_end+a>this.data_length?(this.lba_mid_reg=this.data_length-this.data_end&255,this.lba_high_reg=this.data_length-this.data_end>>8&255,this.data_end=this.data_length):this.data_end+=a}else this.error_reg=
|
|
512
|
-
196===this.current_command?(a=Math.min(this.sectors_per_drq,(this.data_length-this.data_end)/512),l(0===a%1)):(l(32===this.current_command||36===this.current_command),a=1),this.ata_advance(this.current_command,a),this.data_end+=512*a,this.status_reg=88,this.push_irq())};X.prototype.write_data_port=function(a,b){l(0===this.data_pointer%b);this.data_pointer>=this.data_end?B(this.name+": redundant write to data port: "+
|
|
513
|
-
a:2===b?(this.data16[this.data_pointer>>>1]=a,this.data_pointer+=2):(this.data32[this.data_pointer>>>2]=a,this.data_pointer+=4),l(this.data_pointer<=this.data_end),this.data_pointer===this.data_end&&this.write_end())};X.prototype.write_data_port8=function(a){this.write_data_port(a,1)};X.prototype.write_data_port16=function(a){this.write_data_port(a,2)};X.prototype.write_data_port32=function(a){this.write_data_port(a,
|
|
514
|
-
this.data_pointer>=this.data_length?this.do_write():(l(48===this.current_command||52===this.current_command||197===this.current_command,"Unexpected command: "+n(this.current_command)),this.status_reg=88,this.data_end+=512,this.push_irq())};X.prototype.ata_advance=function(a,b){this.sector_count_reg-=b;36===a||41===a||37===a||52===a||57===a||53===a?(a=b+this.get_lba48(),this.lba_low_reg=a&255|a>>16&65280,this.lba_mid_reg=
|
|
515
|
-
a&255,this.lba_mid_reg=a>>8&255,this.lba_high_reg=a>>16&255,this.head=this.head&-16|a&15):(a=b+this.get_chs(),b=a/(this.head_count*this.sectors_per_track)|0,this.lba_mid_reg=b&255,this.lba_high_reg=b>>8&255,this.head=(a/this.sectors_per_track|0)%this.head_count&15,this.lba_low_reg=a%this.sectors_per_track+1&255,l(a===this.get_chs()))};X.prototype.ata_read_sectors=function(a){var b=36===a||41===a,c=this.get_count(b);
|
|
516
|
-
e>this.buffer.byteLength?(l(!1,this.name+": ATA read: Outside of disk",32768),this.status_reg=255,this.push_irq()):(this.status_reg=192,this.report_read_start(),this.read_buffer(b,e,f=>{this.data_set(f);this.status_reg=88;this.data_end=d?512:Math.min(e,512*this.sectors_per_drq);this.ata_advance(a,d?1:Math.min(c,this.sectors_per_track));this.push_irq();this.report_read_end(e)}))};X.prototype.ata_read_sectors_dma=function(a){a=
|
|
517
|
-
this.buffer.byteLength?(l(!1,this.name+": ATA read: Outside of disk",32768),this.status_reg=255,this.push_irq()):(this.status_reg=88,this.channel.dma_status|=1)};X.prototype.do_ata_read_sectors_dma=function(){var a=37===this.current_command,b=this.get_count(a);a=this.get_lba(a);var c=b*this.sector_size,d=a*this.sector_size;l(a<this.buffer.byteLength);this.report_read_start();var e=this.channel.prdt_addr;this.read_buffer(d,
|
|
518
|
-
p=this.cpu.read16(g+4),q=this.cpu.read8(g+7)&128;p||(p=65536);this.cpu.write_blob(f.subarray(k,k+p),m);k+=p;g+=8}while(!q);l(k===c);this.ata_advance(this.current_command,b);this.status_reg=80;this.channel.dma_status&=-2;this.current_command=-1;this.report_read_end(c);this.push_irq()})};X.prototype.ata_write_sectors=function(a){var b=52===a||57===a,c=this.get_count(b);b=this.get_lba(b);a=48===a||52===a;c*=this.sector_size;
|
|
519
|
-
32768),this.status_reg=255,this.push_irq()):(this.status_reg=88,this.data_allocate_noclear(c),this.data_end=a?512:Math.min(c,512*this.sectors_per_drq),this.write_dest=b)};X.prototype.ata_write_sectors_dma=function(a){a=53===a;var b=this.get_count(a);this.get_lba(a)*this.sector_size+b*this.sector_size>this.buffer.byteLength?(l(!1,this.name+": ATA DMA write: Outside of disk",32768),this.status_reg=255,this.push_irq()):
|
|
520
|
-
function(){var a=53===this.current_command,b=this.get_count(a),c=this.get_lba(a);a=b*this.sector_size;c*=this.sector_size;var d=this.channel.prdt_addr,e=0;const f=new Uint8Array(a);do{var g=this.cpu.read32s(d),k=this.cpu.read16(d+4),m=this.cpu.read8(d+7)&128;k||(k=65536,B(this.name+": DMA: prd count was 0",32768));g=this.cpu.mem8.subarray(g,g+k);l(g.length===k);f.set(g,e);e+=k;d+=8}while(!m);l(e===f.length);this.buffer.set(c,
|
|
521
|
-
this.channel.dma_status&=-2;this.current_command=-1});this.report_write(a)};X.prototype.get_chs=function(){return((this.lba_mid_reg&255|this.lba_high_reg<<8&65280)*this.head_count+this.head)*this.sectors_per_track+(this.lba_low_reg&255)-1};X.prototype.get_lba28=function(){return this.lba_low_reg&255|this.lba_mid_reg<<8&65280|this.lba_high_reg<<16&16711680|(this.head&15)<<24};X.prototype.get_lba48=function(){return(this.lba_low_reg&
|
|
522
|
-
8<<24&4278190080)>>>0};X.prototype.get_lba=function(a){return a?this.get_lba48():this.is_lba?this.get_lba28():this.get_chs()};X.prototype.get_count=function(a){a?(a=this.sector_count_reg,0===a&&(a=65536)):(a=this.sector_count_reg&255,0===a&&(a=256));return a};X.prototype.create_identify_packet=function(){const a=Math.min(16383,this.cylinder_count),b=(g,k,m,p)=>{k<<=1;var q=m<<1;m=k+q;g.fill(32,k,q);for(q=0;q<p.length&&
|
|
523
|
-
34112:64,d=160===this.current_command?0:1031,e=this.is_atapi?16928:16384,f=this.is_atapi?20480:29696;this.data.fill(0,0,512);this.data_set([c&255,c>>8&255,a&255,a>>8&255,0,0,this.head_count&255,this.head_count>>8&255,this.sectors_per_track/512&255,this.sectors_per_track/512>>8&255,0,2,this.sectors_per_track&255,this.sectors_per_track>>8&255,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,3,0,0,2,4,0,0,0,0,0,0,0,0,
|
|
524
|
-
0,128,0,1,0,0,2,0,0,0,2,0,2,7,0,a&255,a>>8&255,this.head_count&255,this.head_count>>8&255,this.sectors_per_track,0,this.sector_count&255,this.sector_count>>8&255,this.sector_count>>16&255,this.sector_count>>24&255,0,0,this.sector_count&255,this.sector_count>>8&255,this.sector_count>>16&255,this.sector_count>>24&255,0,0,d&255,d>>8&255,0,0,30,0,30,0,30,0,30,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,e&255,e>>
|
|
525
|
-
1,96,0,0,0,0,0,0,0,0,0,0,0,0,this.sector_count&255,this.sector_count>>8&255,this.sector_count>>16&255,this.sector_count>>24&255]);b(this.data,10,10,`8086-86${this.channel_nr}${this.interface_nr}`);b(this.data,23,4,"1.00");b(this.data,27,20,this.is_atapi?"v86 ATAPI CD-ROM":"v86 ATA HD");this.data_end=this.data_length=512};X.prototype.data_allocate=function(a){this.data_allocate_noclear(a);this.data32.fill(0,0,a+3>>2)};
|
|
526
|
-
3&-4),this.data16=new Uint16Array(this.data.buffer),this.data32=new Int32Array(this.data.buffer));this.data_length=a;this.data_pointer=0};X.prototype.data_set=function(a){this.data_allocate_noclear(a.length);this.data.set(a)};X.prototype.report_read_start=function(){this.bus.send("ide-read-start")};X.prototype.report_read_end=function(a){this.bus.send("ide-read-end",[this.channel_nr,a,a/this.sector_size|
|
|
527
|
-
0])};X.prototype.read_buffer=function(a,b,c){const d=this.last_io_id++;this.in_progress_io_ids.add(d);this.buffer.get(a,b,e=>{if(this.cancelled_io_ids.delete(d))l(!this.in_progress_io_ids.has(d));else{var f=this.in_progress_io_ids.delete(d);l(f);c(e)}})};X.prototype.cancel_io_operations=function(){for(const a of this.in_progress_io_ids)this.cancelled_io_ids.add(a);this.in_progress_io_ids.clear()};
|
|
528
|
-
a[3]=this.lba_mid_reg;a[4]=this.data_pointer;a[5]=0;a[6]=0;a[7]=0;a[8]=0;a[9]=this.device_reg;a[10]=this.error_reg;a[11]=this.head;a[12]=this.head_count;a[13]=this.is_atapi;a[14]=this.is_lba;a[15]=this.features_reg;a[16]=this.data;a[17]=this.data_length;a[18]=this.lba_low_reg;a[19]=this.sector_count;a[20]=this.sector_size;a[21]=this.sectors_per_drq;a[22]=this.sectors_per_track;a[23]=
|
|
529
|
-
a[28]=this.buffer;return a};X.prototype.set_state=function(a){this.sector_count_reg=a[0];this.cylinder_count=a[1];this.lba_high_reg=a[2];this.lba_mid_reg=a[3];this.data_pointer=a[4];this.device_reg=a[9];this.error_reg=a[10];this.head=a[11];this.head_count=a[12];this.is_atapi=a[13];this.is_lba=a[14];this.features_reg=a[15];this.data=a[16];this.data_length=a[17];this.lba_low_reg=a[18];
|
|
530
|
-
a[23];this.write_dest=a[24];this.current_command=a[25];this.data_end=a[26];this.current_atapi_command=a[27];this.data16=new Uint16Array(this.data.buffer);this.data32=new Int32Array(this.data.buffer);this.buffer&&this.buffer.set_state(a[28]);this.drive_connected=this.is_atapi||this.buffer;this.medium_changed=!1};function Xc(a,b,c){this.bus=b;this.id=a.devices.net?1:0;this.status=this.pairs=
|
|
531
|
-
0,255*Math.random()|0]);this.bus.send("net"+this.id+"-mac",Cc(this.mac));b=[];for(c=0;c<this.pairs;++c)b.push({size_supported:1024,notify_offset:0}),b.push({size_supported:1024,notify_offset:1});b.push({size_supported:16,notify_offset:2});this.virtio=new Fc(a,{name:"virtio-net",pci_id:80,device_id:4161,subsystem_device_id:1,common:{initial_port:51200,queues:b,features:[5,16,22,3,17,23,32],
|
|
532
|
-
for(;e.has_request();){const f=e.pop_request(),g=new Uint8Array(f.length_readable);f.get_next_blob(g);this.bus.send("net"+this.id+"-send",g.subarray(12));this.bus.send("eth-transmit-end",[g.length-12]);this.virtio.queues[d].push_reply(f)}this.virtio.queues[d].flush_replies()},d=>{if(d!==2*this.pairs)l(!1,"VirtioNet Notified for wrong queue: "+d+" (expected queue_id of 3)");else for(var e=
|
|
533
|
-
var g=J(["b","b"],f,{offset:0});const m=g[0];g=g[1];switch(m<<8|g){case 1024:f=J(["h"],f,{offset:2});l(1===f[0]);this.Send(d,k,new Uint8Array([0]));break;case 257:this.mac=f.subarray(2,8);this.Send(d,k,new Uint8Array([0]));this.bus.send("net"+this.id+"-mac",Cc(this.mac));break;default:l(!1," VirtioNet received unknown command: "+m+":"+g);this.Send(d,k,new Uint8Array([1]));return}}}]},
|
|
534
|
-
e,read:()=>this.mac[e],write:()=>{}})).concat([{bytes:2,name:"status",read:()=>this.status,write:()=>{}},{bytes:2,name:"max_pairs",read:()=>this.pairs,write:()=>{}},{bytes:2,name:"mtu",read:()=>1500,write:()=>{}}])}});this.bus.register("net"+this.id+"-receive",d=>{this.bus.send("eth-receive-end",[d.length]);const e=new Uint8Array(12+d.byteLength);(new DataView(e.buffer,e.byteOffset,
|
|
535
|
-
this.virtio.queues[0].push_reply(d),this.virtio.queues[0].flush_replies()):console.log("No buffer to write into!")},this)}Xc.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.id;a[2]=this.mac;return a};Xc.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.id=a[1];this.preserve_mac_from_state_image&&(this.mac=a[2],this.bus.send("net"+this.id+"-mac",
|
|
536
|
-
this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};Xc.prototype.Ack=function(a,b){this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};const Yc=Uint32Array.from([655360,655360,720896,753664]),Zc=Uint32Array.from([131072,65536,32768,32768]);function Y(a,b,c,d){this.cpu=a;this.bus=b;this.screen=c;this.vga_memory_size=d;this.cursor_address=
|
|
537
|
-
this.screen_height=this.screen_width=0;this.layers=[];this.start_address_latched=this.start_address=0;this.crtc=new Uint8Array(25);this.line_compare=this.offset_register=this.preset_row_scan=this.underline_location_register=this.vertical_blank_start=this.vertical_display_enable_end=this.horizontal_blank_start=this.horizontal_display_enable_end=this.crtc_mode=0;this.graphical_mode
|
|
538
|
-
0;this.svga_enabled=!1;this.svga_bpp=32;this.svga_offset_y=this.svga_offset_x=this.svga_offset=this.svga_bank_offset=0;this.vga_memory_size=void 0===this.vga_memory_size||262144>this.vga_memory_size?262144:268435456<this.vga_memory_size?268435456:ma(this.vga_memory_size);B("effective vga memory size: "+this.vga_memory_size,256);this.pci_space=[52,18,17,17,3,1,0,0,0,0,0,3,0,0,0,0,
|
|
539
|
-
0];this.pci_id=144;this.pci_bars=[{size:this.vga_memory_size}];this.pci_rom_size=65536;this.pci_rom_address=4272947200;this.name="vga";this.dac_state=this.dac_color_index_read=this.dac_color_index_write=this.index_crtc=0;this.dac_mask=255;this.dac_map=new Uint8Array(16);this.attribute_controller_index=-1;this.palette_source=32;this.color_select=this.horizontal_panning=this.color_plane_enable=
|
|
540
|
-
0;this.graphics_index=-1;this.planar_rotate_reg=this.planar_mode=this.plane_read=this.character_map_select=0;this.planar_bitmap=255;this.max_scan_line=this.color_dont_care=this.color_compare=this.miscellaneous_graphics_register=this.planar_setreset_enable=this.planar_setreset=0;this.port_3DA_value=this.miscellaneous_output_register=255;this.font_page_ab_enabled=!1;b=a.io;b.register_write(960,
|
|
541
|
-
this,this.port3C1_read);b.register_write(962,this,this.port3C2_write);b.register_write_consecutive(964,this,this.port3C4_write,this.port3C5_write);b.register_read(964,this,this.port3C4_read);b.register_read(965,this,this.port3C5_read);b.register_write_consecutive(974,this,this.port3CE_write,this.port3CF_write);b.register_read(974,this,this.port3CE_read);b.register_read(975,this,this.port3CF_read);
|
|
542
|
-
this,this.port3C7_write);b.register_read(967,this,this.port3C7_read);b.register_write(968,this,this.port3C8_write);b.register_read(968,this,this.port3C8_read);b.register_write(969,this,this.port3C9_write);b.register_read(969,this,this.port3C9_read);b.register_read(972,this,this.port3CC_read);b.register_write(980,this,this.port3D4_write,this.port3D4_write16);b.register_write(981,this,this.port3D5_write,
|
|
543
|
-
this.port3D5_read16);b.register_write(948,this,this.port3D4_write,this.port3D4_write16);b.register_write(949,this,this.port3D5_write,this.port3D5_write16);b.register_read(948,this,this.port3D4_read);b.register_read(949,this,this.port3D5_read,this.port3D5_read16);b.register_read(970,this,function(){B("3CA read",256);return 0});b.register_read(986,this,this.port3DA_read);b.register_read(954,
|
|
544
|
-
b.register_write(463,this,void 0,this.port1CF_write);b.register_read(463,this,void 0,this.port1CF_read);c=a.svga_allocate_memory(this.vga_memory_size)>>>0;this.svga_memory=h(Uint8Array,a.wasm_memory,c,this.vga_memory_size);this.diff_addr_min=this.vga_memory_size;this.diff_addr_max=0;this.diff_plot_min=this.vga_memory_size;this.diff_plot_max=0;this.image_data=null;this.vga_memory=
|
|
545
|
-
65536,65536);this.plane2=new Uint8Array(this.vga_memory.buffer,131072,65536);this.plane3=new Uint8Array(this.vga_memory.buffer,196608,65536);this.pixel_buffer=new Uint8Array(524288);b.mmap_register(655360,131072,e=>this.vga_memory_read(e),(e,f)=>this.vga_memory_write(e,f));a.devices.pci.register_device(this)}Y.prototype.get_state=function(){var a=[];a[0]=this.vga_memory_size;
|
|
546
|
-
a[6]=this.vga_memory;a[7]=this.dac_state;a[8]=this.start_address;a[9]=this.graphical_mode;a[10]=this.vga256_palette;a[11]=this.latch_dword;a[12]=this.color_compare;a[13]=this.color_dont_care;a[14]=this.miscellaneous_graphics_register;a[15]=this.svga_width;a[16]=this.svga_height;a[17]=this.crtc_mode;a[18]=this.svga_enabled;a[19]=this.svga_bpp;a[20]=this.svga_bank_offset;a[21]=
|
|
547
|
-
a[26]=this.sequencer_index;a[27]=this.plane_write_bm;a[28]=this.sequencer_memory_mode;a[29]=this.graphics_index;a[30]=this.plane_read;a[31]=this.planar_mode;a[32]=this.planar_rotate_reg;a[33]=this.planar_bitmap;a[34]=this.max_scan_line;a[35]=this.miscellaneous_output_register;a[36]=this.port_3DA_value;a[37]=this.dispi_index;a[38]=this.dispi_enable_value;a[39]=this.svga_memory;
|
|
548
|
-
a[
|
|
549
|
-
this.dac_mask;a[63]=this.character_map_select;a[64]=this.font_page_ab_enabled;return a};Y.prototype.set_state=function(a){this.vga_memory_size=a[0];this.cursor_address=a[1];this.cursor_scanline_start=a[2];this.cursor_scanline_end=a[3];this.max_cols=a[4];this.max_rows=a[5];a[6]&&this.vga_memory.set(a[6]);this.dac_state=a[7];this.start_address=a[8];this.graphical_mode=a[9];
|
|
550
|
-
|
|
551
|
-
a[34];this.miscellaneous_output_register=a[35];this.port_3DA_value=a[36];this.dispi_index=a[37];this.dispi_enable_value=a[38];this.svga_memory.set(a[39]);this.attribute_controller_index=a[41];this.offset_register=a[42];this.planar_setreset=a[43];this.planar_setreset_enable=a[44];this.start_address_latched=a[45];this.crtc.set(a[46]);this.horizontal_display_enable_end=a[47];this.horizontal_blank_start=
|
|
552
|
-
a[51];this.preset_row_scan=a[52];this.offset_register=a[53];this.palette_source=a[54];this.attribute_mode=a[55];this.color_plane_enable=a[56];this.horizontal_panning=a[57];this.color_select=a[58];this.clocking_mode=a[59];this.line_compare=a[60];a[61]&&this.pixel_buffer.set(a[61]);this.dac_mask=void 0===a[62]?255:a[62];this.character_map_select=void 0===a[63]?0:a[63];this.font_page_ab_enabled=
|
|
553
|
-
0,this.svga_enabled?(this.set_size_graphical(this.svga_width,this.svga_height,this.svga_width,this.svga_height,this.svga_bpp),this.update_layers()):(this.update_vga_size(),this.update_layers(),this.complete_replot())):(this.set_font_bitmap(!0),this.set_size_text(this.max_cols,this.max_rows),this.set_font_page(),this.update_cursor_scanline(),this.update_cursor());this.complete_redraw()};
|
|
554
|
-
3758096384|0);var b=this.miscellaneous_graphics_register>>2&3;a-=Yc[b];if(0>a||a>=Zc[b])return B("vga read outside memory space: addr:"+n(a>>>0),256),0;this.latch_dword=this.plane0[a];this.latch_dword|=this.plane1[a]<<8;this.latch_dword|=this.plane2[a]<<16;this.latch_dword|=this.plane3[a]<<24;if(this.planar_mode&8)return b=255,this.color_dont_care&1&&(b&=this.plane0[a]^~(this.color_compare&
|
|
555
|
-
(b&=this.plane2[a]^~(this.color_compare&4?255:0)),this.color_dont_care&8&&(b&=this.plane3[a]^~(this.color_compare&8?255:0)),b;b=this.plane_read;this.graphical_mode?this.sequencer_memory_mode&8?(b=a&3,a&=-4):this.planar_mode&16&&(b=a&1,a&=-2):b&=3;return this.vga_memory[b<<16|a]};Y.prototype.vga_memory_write=function(a,b){if(this.svga_enabled)this.cpu.write8((a-655360|this.svga_bank_offset)+
|
|
556
|
-
n(a>>>0)+", value:"+n(b),256):this.graphical_mode?this.vga_memory_write_graphical(a,b):this.plane_write_bm&3?this.vga_memory_write_text_mode(a,b):this.plane_write_bm&4&&(this.plane2[a]=b)}};Y.prototype.vga_memory_write_graphical=function(a,b){var c=this.planar_mode&3,d=this.apply_feed(this.planar_bitmap),e=this.apply_expand(this.planar_setreset),f=this.apply_expand(this.planar_setreset_enable);
|
|
557
|
-
this.latch_dword);g=this.apply_bitmask(g,d);break;case 1:g=this.latch_dword;break;case 2:g=this.apply_expand(b);g=this.apply_logical(g,this.latch_dword);g=this.apply_bitmask(g,d);break;case 3:b=this.apply_rotate(b),d&=this.apply_feed(b),g=this.apply_bitmask(e,d)}b=15;switch(this.sequencer_memory_mode&12){case 0:b=5<<(a&1);a&=-2;break;case 8:case 12:b=1<<(a&3),a&=-4}b&=this.plane_write_bm;
|
|
558
|
-
g>>24&255);a=this.vga_addr_to_pixel(a);this.partial_replot(a,a+7)};Y.prototype.apply_feed=function(a){return a|a<<8|a<<16|a<<24};Y.prototype.apply_expand=function(a){return(a&1?255:0)|(a&2?255:0)<<8|(a&4?255:0)<<16|(a&8?255:0)<<24};Y.prototype.apply_rotate=function(a){return(a|a<<8)>>>(this.planar_rotate_reg&7)&255};Y.prototype.apply_setreset=function(a,b){var c=this.apply_expand(this.planar_setreset);
|
|
559
|
-
b;case 16:return a|b;case 24:return a^b}return a};Y.prototype.apply_bitmask=function(a,b){return b&a|~b&this.latch_dword};Y.prototype.text_mode_redraw=function(){const a=this.scan_line_to_screen_row(this.line_compare),b=Math.max(0,2*(2*this.offset_register-this.max_cols)),c=this.attribute_mode&8,d=this.font_page_ab_enabled?7:15,e=c?7:15,f=this.screen.FLAG_BLINKING,g=this.screen.FLAG_FONT_PAGE_B;
|
|
560
|
-
this.vga_memory[k],r=this.vga_memory[k|1],v=(c&&r&128?f:0)|(!this.font_page_ab_enabled||r&8?0:g);this.bus.send("screen-put-char",[m,p,q]);this.screen.put_char(m,p,q,v,this.vga256_palette[this.dac_mask&this.dac_map[r>>4&e]],this.vga256_palette[this.dac_mask&this.dac_map[r&d]]);k+=2}k+=b}};Y.prototype.vga_memory_write_text_mode=function(a,b){this.vga_memory[a]=b;var c=Math.max(this.max_cols,
|
|
561
|
-
a>>1,d=(e/c|0)+this.scan_line_to_screen_row(this.line_compare),c=e%c;l(0<=d&&0<=c);if(!(c>=this.max_cols||d>=this.max_rows)){a&1?(e=b,b=this.vga_memory[a&-2]):e=this.vga_memory[a|1];var f=this.attribute_mode&8;a=(f&&e&128?this.screen.FLAG_BLINKING:0)|(!this.font_page_ab_enabled||e&8?0:this.screen.FLAG_FONT_PAGE_B);var g=this.font_page_ab_enabled?7:15;f=f?7:15;this.bus.send("screen-put-char",
|
|
562
|
-
this.dac_map[e&g]])}};Y.prototype.update_cursor=function(){var a=Math.max(this.max_cols,2*this.offset_register);let b;this.cursor_address>=this.start_address?(b=(this.cursor_address-this.start_address)/a|0,a=(this.cursor_address-this.start_address)%a):(b=(this.cursor_address/a|0)+this.scan_line_to_screen_row(this.line_compare),a=this.cursor_address%a);l(0<=b&&0<=a);this.screen.update_cursor(b,
|
|
563
|
-
this.cpu.svga_mark_dirty():(this.diff_addr_min=0,this.diff_addr_max=524288):this.text_mode_redraw()};Y.prototype.complete_replot=function(){B("complete replot",256);this.graphical_mode&&!this.svga_enabled&&(this.diff_plot_min=0,this.diff_plot_max=524288,this.complete_redraw())};Y.prototype.partial_redraw=function(a,b){a<this.diff_addr_min&&(this.diff_addr_min=a);b>this.diff_addr_max&&(this.diff_addr_max=
|
|
564
|
-
(this.diff_plot_max=b);this.partial_redraw(a,b)};Y.prototype.reset_diffs=function(){this.diff_addr_min=this.vga_memory_size;this.diff_addr_max=0;this.diff_plot_min=this.vga_memory_size;this.diff_plot_max=0};Y.prototype.destroy=function(){};Y.prototype.vga_bytes_per_line=function(){var a=this.offset_register<<2;this.underline_location_register&64?a<<=1:this.crtc_mode&64&&(a>>>=1);return a};
|
|
565
|
-
this.underline_location_register&64;a-=this.attribute_mode&64;return a>>>6};Y.prototype.vga_addr_to_pixel=function(a){var b=this.vga_addr_shift_count();if(~this.crtc_mode&3){var c=a-this.start_address;c&=this.crtc_mode<<13|-24577;c<<=b;var d=c/this.virtual_width|0;c%=this.virtual_width;switch(this.crtc_mode&3){case 2:d=d<<1|a>>13&1;break;case 1:d=d<<1|a>>14&1;break;case 0:d=d<<2|a>>13&3}return d*
|
|
566
|
-
128&&(a>>>=1);a=Math.ceil(a/(1+(this.max_scan_line&31)));this.crtc_mode&1||(a<<=1);this.crtc_mode&2||(a<<=1);return a};Y.prototype.set_size_text=function(a,b){l(!this.graphical_mode);this.max_cols=a;this.max_rows=b;this.screen.set_size_text(a,b);this.bus.send("screen-set-size",[a,b,0])};Y.prototype.set_size_graphical=function(a,b,c,d,e){l(this.graphical_mode);c=Math.max(c,1);
|
|
567
|
-
a;this.screen_height=b;this.virtual_width=c;this.virtual_height=d;if("undefined"!==typeof ImageData){const f=c*d,g=this.cpu.svga_allocate_dest_buffer(f)>>>0;this.dest_buffet_offset=g;this.image_data=new ImageData(new Uint8ClampedArray(this.cpu.wasm_memory.buffer,g,4*f),c,d);this.cpu.svga_mark_dirty()}this.screen.set_size_graphical(a,b,c,d);this.bus.send("screen-set-size",
|
|
568
|
-
b=Math.min(1+this.vertical_display_enable_end,this.vertical_blank_start);if(a&&b)if(this.graphical_mode){a<<=3;var c=this.offset_register<<4,d=4;this.attribute_mode&64?(a>>>=1,c>>>=1,d=8):this.attribute_mode&2&&(d=1);b=this.scan_line_to_screen_row(b);var e=Zc[0];const f=this.vga_bytes_per_line();this.set_size_graphical(a,b,c,f?Math.ceil(e/f):b,d);
|
|
569
|
-
Y.prototype.update_layers=function(){this.graphical_mode||this.text_mode_redraw();if(this.svga_enabled)this.layers=[];else if(this.virtual_width&&this.screen_width)if(!this.palette_source||this.clocking_mode&32)this.layers=[],this.screen.clear_screen();else{var a=this.start_address_latched,b=this.horizontal_panning;this.attribute_mode&64&&(b>>>=
|
|
570
|
-
d=Math.min(d,this.screen_height);var f=this.screen_height-d;this.layers=[];e=-e;for(var g=0;e<this.screen_width;e+=this.virtual_width,g++)this.layers.push({image_data:this.image_data,screen_x:e,screen_y:0,buffer_x:0,buffer_y:a+g,buffer_width:this.virtual_width,buffer_height:d});a=0;this.attribute_mode&32||(a=this.vga_addr_to_pixel(c)+
|
|
571
|
-
buffer_height:f})}};Y.prototype.update_vertical_retrace=function(){this.port_3DA_value|=8;this.start_address_latched!==this.start_address&&(this.start_address_latched=this.start_address,this.update_layers())};Y.prototype.update_cursor_scanline=function(){var a=this.max_scan_line&31;const b=Math.min(a,this.cursor_scanline_start&
|
|
572
|
-
n(a),256),this.attribute_controller_index=a&31,B("attribute actual index: "+n(this.attribute_controller_index),256),this.palette_source!==(a&32)&&(this.palette_source=a&32,this.update_layers());else{if(16>this.attribute_controller_index)B("internal palette: "+
|
|
573
|
-
if(this.attribute_mode!==a){var b=this.attribute_mode;this.attribute_mode=a;const c=0!==(a&1);this.svga_enabled||this.graphical_mode===c||(this.graphical_mode=c,this.screen.set_mode(this.graphical_mode));(b^a)&64&&this.complete_replot();this.update_vga_size();
|
|
574
|
-
|
|
575
|
-
this.port3C1_read()<<8&65280};Y.prototype.port3C1_read=function(){if(16>this.attribute_controller_index)return B("3C1 / internal palette read: "+n(this.attribute_controller_index)+" -> "+n(this.dac_map[this.attribute_controller_index]),256),this.dac_map[this.attribute_controller_index]&
|
|
576
|
-
|
|
577
|
-
a};Y.prototype.port3C4_read=function(){return this.sequencer_index};Y.prototype.port3C5_write=function(a){switch(this.sequencer_index){case 1:B("clocking mode: "+n(a),256);var b=this.clocking_mode;this.clocking_mode=a;(b^a)&32&&this.update_layers();this.set_font_bitmap(!1);break;case 2:B("plane write mask: "+
|
|
578
|
-
this.character_map_select=a;this.graphical_mode||b===a||this.set_font_page();break;case 4:B("sequencer memory mode: "+n(a),256);this.sequencer_memory_mode=a;break;default:B("3C5 / sequencer write "+n(this.sequencer_index)+": "+n(a),256)}};Y.prototype.port3C5_read=function(){B("3C5 / sequencer read "+
|
|
579
|
-
case 6:return 18}return 0};Y.prototype.port3C6_write=function(a){this.dac_mask!==a&&(this.dac_mask=a,this.complete_redraw())};Y.prototype.port3C6_read=function(){return this.dac_mask};Y.prototype.port3C7_write=function(a){B("3C7 write: "+n(a),256);this.dac_color_index_read=3*a;this.dac_state&=0};
|
|
580
|
-
3&255};Y.prototype.port3C9_write=function(a){var b=this.dac_color_index_write/3|0,c=this.dac_color_index_write%3,d=this.vga256_palette[b];if(0===(this.dispi_enable_value&32)){a&=63;const e=a&1;a=a<<2|e<<1|e}0===c?d=d&-16711681|a<<16:1===c?d=d&-65281|a<<8:(d=d&-256|a,B("dac set color, index="+
|
|
581
|
-
3|0]>>8*(2-this.dac_color_index_read%3)&255;this.dac_color_index_read++;return this.dispi_enable_value&32?a:a>>2};Y.prototype.port3CC_read=function(){B("3CC read",256);return this.miscellaneous_output_register};Y.prototype.port3CE_write=function(a){this.graphics_index=
|
|
582
|
-
a;B("plane set/reset
|
|
583
|
-
break;case 7:this.color_dont_care=a;B("color don't care: "+n(a),256);break;case 8:this.planar_bitmap=a;B("planar bitmap: "+n(a),256);break;default:B("3CF / graphics write "+n(this.graphics_index)+": "+n(a),256)}};Y.prototype.port3CF_read=function(){B("3CF / graphics read "+
|
|
584
|
-
case 5:return this.planar_mode;case 6:return this.miscellaneous_graphics_register;case 7:return this.color_dont_care;case 8:return this.planar_bitmap}return 0};Y.prototype.port3D4_write=function(a){B("3D4 / crtc index: "+a,256);this.index_crtc=a};Y.prototype.port3D4_write16=
|
|
585
|
-
n(a),256);this.horizontal_display_enable_end!==a&&(this.horizontal_display_enable_end=a,this.update_vga_size());break;case 2:this.horizontal_blank_start!==a&&(this.horizontal_blank_start=a,this.update_vga_size());break;case 7:B("3D5 / overflow register write: "+
|
|
586
|
-
this.line_compare&767|a<<4&256;b=this.vertical_blank_start;this.vertical_blank_start=this.vertical_blank_start&767|a<<5&256;b!==this.vertical_blank_start&&this.update_vga_size();this.update_layers();break;case 8:B("3D5 / preset row scan write: "+n(a),
|
|
587
|
-
this.vertical_blank_start&511|a<<4&512;((c^this.max_scan_line)&159||b!==this.vertical_blank_start)&&this.update_vga_size();this.update_cursor_scanline();this.update_layers();this.set_font_bitmap(!1);break;case 10:B("3D5 / cursor scanline start write: "+
|
|
588
|
-
|
|
589
|
-
this.
|
|
590
|
-
break;case
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
(B("
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
this.
|
|
599
|
-
|
|
600
|
-
n(this.dispi_index),256)}return 255};Y.prototype.vga_replot=function(){for(var a=this.diff_plot_min&-16,b=Math.min(this.diff_plot_max|
|
|
601
|
-
|
|
602
|
-
g[k]
|
|
603
|
-
e|=this.color_select<<4&
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
c=>{
|
|
338
|
+
(this.stopping=!0)};H.prototype.destroy=function(){this.unregister_yield()};H.prototype.restart=function(){this.cpu.reset_cpu();this.cpu.load_bios()};H.prototype.init=function(a){this.cpu.init(a,this.bus);this.bus.send("emulator-ready")};if("undefined"!==typeof process)H.prototype.yield=function(a,b){1>a?global.setImmediate(c=>this.yield_callback(c),b):setTimeout(c=>this.yield_callback(c),a,b)},H.prototype.register_yield=function(){},H.prototype.unregister_yield=function(){};else if(window.scheduler&&
|
|
339
|
+
"function"===typeof window.scheduler.postTask&&!location.href.includes("dont-use-scheduling-api"))H.prototype.yield=function(a,b){a=Math.max(0,a);window.scheduler.postTask(()=>this.yield_callback(b),{delay:a})},H.prototype.register_yield=function(){},H.prototype.unregister_yield=function(){};else if("undefined"!==typeof Worker){function a(){let b;globalThis.onmessage=function(c){const d=c.data.t;b=b&&clearTimeout(b);1>d?postMessage(c.data.tick):b=setTimeout(()=>postMessage(c.data.tick),d)}}H.prototype.register_yield=
|
|
340
|
+
function(){const b=URL.createObjectURL(new Blob(["("+a.toString()+")()"],{type:"text/javascript"}));this.worker=new Worker(b);this.worker.onmessage=c=>this.yield_callback(c.data);URL.revokeObjectURL(b)};H.prototype.yield=function(b,c){this.worker.postMessage({t:b,tick:c})};H.prototype.unregister_yield=function(){this.worker&&this.worker.terminate();this.worker=null}}else H.prototype.yield=function(a){setTimeout(()=>{this.do_tick()},a)},H.prototype.register_yield=function(){},H.prototype.unregister_yield=
|
|
341
|
+
function(){};H.prototype.save_state=function(){for(var a=[],b=gb(this.cpu,a),c=[],d=0,e=0;e<a.length;e++){var f=a[e].byteLength;c[e]={offset:d,length:f};d+=f;d=d+3&-4}b=JSON.stringify({buffer_infos:c,state:b});b=(new TextEncoder).encode(b);e=16+b.length;e=e+3&-4;var g=e+d;d=new ArrayBuffer(g);var k=new Int32Array(d,0,4);(new Uint8Array(d,16,b.length)).set(b);f=new Uint8Array(d,e);k[0]=-2039052682;k[1]=6;k[2]=g;k[3]=b.length;for(e=0;e<a.length;e++)g=a[e],l(g.constructor===Uint8Array),f.set(g,c[e].offset);
|
|
342
|
+
B("State: json size "+(b.byteLength>>10)+"k");B("State: Total buffers size "+(f.byteLength>>10)+"k");return d};H.prototype.restore_state=function(a){return ib(this.cpu,a)};if("object"===typeof performance&&performance.now)H.microtick=performance.now.bind(performance);else if("function"===typeof require){const {performance:a}=require("perf_hooks");H.microtick=a.now.bind(a)}else H.microtick="object"===typeof process&&process.hrtime?function(){var a=process.hrtime();return 1E3*a[0]+a[1]/1E6}:Date.now;
|
|
343
|
+
function yc(a){this.cpu=a;var b=a.io;a.devices.pci.register_device({pci_id:56,pci_space:[134,128,19,113,7,0,128,2,8,0,128,6,0,0,128,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,1,0,0],pci_bars:[],name:"acpi"});this.timer_imprecision_offset=this.timer_last_value=0;this.status=1;this.pm1_enable=this.pm1_status=0;this.last_timer=this.get_timer(H.microtick());this.gpe=new Uint8Array(4);b.register_read(45056,this,void 0,function(){B("ACPI pm1_status read",
|
|
344
|
+
262144);return this.pm1_status});b.register_write(45056,this,void 0,function(c){B("ACPI pm1_status write: "+n(c,4),262144);this.pm1_status&=~c});b.register_read(45058,this,void 0,function(){B("ACPI pm1_enable read",262144);return this.pm1_enable});b.register_write(45058,this,void 0,function(c){B("ACPI pm1_enable write: "+n(c),262144);this.pm1_enable=c});b.register_read(45060,this,function(){B("ACPI status read8",262144);return this.status&255},function(){B("ACPI status read",262144);return this.status});
|
|
345
|
+
b.register_write(45060,this,void 0,function(c){B("ACPI status write: "+n(c),262144);this.status=c});b.register_read(45064,this,void 0,void 0,function(){return this.get_timer(H.microtick())&16777215});b.register_read(45024,this,function(){B("Read gpe#0",262144);return this.gpe[0]});b.register_read(45025,this,function(){B("Read gpe#1",262144);return this.gpe[1]});b.register_read(45026,this,function(){B("Read gpe#2",262144);return this.gpe[2]});b.register_read(45027,this,function(){B("Read gpe#3",262144);
|
|
346
|
+
return this.gpe[3]});b.register_write(45024,this,function(c){B("Write gpe#0: "+n(c),262144);this.gpe[0]=c});b.register_write(45025,this,function(c){B("Write gpe#1: "+n(c),262144);this.gpe[1]=c});b.register_write(45026,this,function(c){B("Write gpe#2: "+n(c),262144);this.gpe[2]=c});b.register_write(45027,this,function(c){B("Write gpe#3: "+n(c),262144);this.gpe[3]=c})}yc.prototype.timer=function(a){a=this.get_timer(a);var b=0!==((a^this.last_timer)&8388608);this.pm1_enable&1&&b?(B("ACPI raise irq",
|
|
347
|
+
262144),this.pm1_status|=1,this.cpu.device_raise_irq(9)):this.cpu.device_lower_irq(9);this.last_timer=a;return 100};yc.prototype.get_timer=function(a){a=Math.round(3579.545*a);a===this.timer_last_value?3579.545>this.timer_imprecision_offset&&this.timer_imprecision_offset++:(l(a>this.timer_last_value),this.timer_last_value+this.timer_imprecision_offset<=a?(this.timer_imprecision_offset=0,this.timer_last_value=a):B("Warning: Overshot pmtimer, waiting; current="+a+" last="+this.timer_last_value+" offset="+
|
|
348
|
+
this.timer_imprecision_offset,262144));return this.timer_last_value+this.timer_imprecision_offset};yc.prototype.get_state=function(){var a=[];a[0]=this.status;a[1]=this.pm1_status;a[2]=this.pm1_enable;a[3]=this.gpe;return a};yc.prototype.set_state=function(a){this.status=a[0];this.pm1_status=a[1];this.pm1_enable=a[2];this.gpe=a[3]};function zc(a,b,c){this.bus=c;this.cpu=a;this.ints=4;this.line_control=this.baud_rate=0;this.lsr=96;this.ier=this.fifo_control=0;this.iir=1;this.irq=this.scratch_register=
|
|
349
|
+
this.modem_status=this.modem_control=0;this.input=[];this.current_line="";switch(b){case 1016:this.com=0;this.irq=4;break;case 760:this.com=1;this.irq=3;break;case 1E3:this.com=2;this.irq=4;break;case 744:this.irq=this.com=3;break;default:B("Invalid serial port: "+n(b),16384),this.com=0,this.irq=4}this.bus.register("serial"+this.com+"-input",function(d){this.data_received(d)},this);this.bus.register("serial"+this.com+"-modem-status-input",function(d){this.set_modem_status(d)},this);this.bus.register("serial"+
|
|
350
|
+
this.com+"-carrier-detect-input",function(d){this.set_modem_status(d?this.modem_status|136:this.modem_status&-137)},this);this.bus.register("serial"+this.com+"-ring-indicator-input",function(d){this.set_modem_status(d?this.modem_status|68:this.modem_status&-69)},this);this.bus.register("serial"+this.com+"-data-set-ready-input",function(d){this.set_modem_status(d?this.modem_status|34:this.modem_status&-35)},this);this.bus.register("serial"+this.com+"-clear-to-send-input",function(d){this.set_modem_status(d?
|
|
351
|
+
this.modem_status|17:this.modem_status&-18)},this);a=a.io;a.register_write(b,this,function(d){this.write_data(d)},function(d){this.write_data(d&255);this.write_data(d>>8)});a.register_write(b|1,this,function(d){this.line_control&128?(this.baud_rate=this.baud_rate&255|d<<8,B("baud rate: "+n(this.baud_rate),16384)):(0===(this.ier&2)&&d&2&&this.ThrowInterrupt(2),this.ier=d&15,B("interrupt enable: "+n(d),16384),this.CheckInterrupt())});a.register_read(b,this,function(){if(this.line_control&128)return this.baud_rate&
|
|
352
|
+
255;let d=0;0===this.input.length?B("Read input empty",16384):(d=this.input.shift(),B("Read input: "+n(d),16384));0===this.input.length&&(this.lsr&=-2,this.ClearInterrupt(12),this.ClearInterrupt(4));return d});a.register_read(b|1,this,function(){return this.line_control&128?this.baud_rate>>8:this.ier&15});a.register_read(b|2,this,function(){var d=this.iir&15;B("read interrupt identification: "+n(this.iir),16384);2===this.iir&&this.ClearInterrupt(2);this.fifo_control&1&&(d|=192);return d});a.register_write(b|
|
|
353
|
+
2,this,function(d){B("fifo control: "+n(d),16384);this.fifo_control=d});a.register_read(b|3,this,function(){B("read line control: "+n(this.line_control),16384);return this.line_control});a.register_write(b|3,this,function(d){B("line control: "+n(d),16384);this.line_control=d});a.register_read(b|4,this,function(){return this.modem_control});a.register_write(b|4,this,function(d){B("modem control: "+n(d),16384);this.modem_control=d});a.register_read(b|5,this,function(){B("read line status: "+n(this.lsr),
|
|
354
|
+
16384);return this.lsr});a.register_write(b|5,this,function(){B("Factory test write",16384)});a.register_read(b|6,this,function(){B("read modem status: "+n(this.modem_status),16384);return this.modem_status&=240});a.register_write(b|6,this,function(d){B("write modem status: "+n(d),16384);this.set_modem_status(d)});a.register_read(b|7,this,function(){return this.scratch_register});a.register_write(b|7,this,function(d){this.scratch_register=d})}zc.prototype.get_state=function(){var a=[];a[0]=this.ints;
|
|
355
|
+
a[1]=this.baud_rate;a[2]=this.line_control;a[3]=this.lsr;a[4]=this.fifo_control;a[5]=this.ier;a[6]=this.iir;a[7]=this.modem_control;a[8]=this.modem_status;a[9]=this.scratch_register;a[10]=this.irq;return a};zc.prototype.set_state=function(a){this.ints=a[0];this.baud_rate=a[1];this.line_control=a[2];this.lsr=a[3];this.fifo_control=a[4];this.ier=a[5];this.iir=a[6];this.modem_control=a[7];this.modem_status=a[8];this.scratch_register=a[9];this.irq=a[10]};zc.prototype.CheckInterrupt=function(){this.ints&
|
|
356
|
+
4096&&this.ier&1?(this.iir=12,this.cpu.device_raise_irq(this.irq)):this.ints&16&&this.ier&1?(this.iir=4,this.cpu.device_raise_irq(this.irq)):this.ints&4&&this.ier&2?(this.iir=2,this.cpu.device_raise_irq(this.irq)):this.ints&1&&this.ier&8?(this.iir=0,this.cpu.device_raise_irq(this.irq)):(this.iir=1,this.cpu.device_lower_irq(this.irq))};zc.prototype.ThrowInterrupt=function(a){this.ints|=1<<a;this.CheckInterrupt()};zc.prototype.ClearInterrupt=function(a){this.ints&=~(1<<a);this.CheckInterrupt()};zc.prototype.data_received=
|
|
357
|
+
function(a){B("input: "+n(a),16384);this.input.push(a);this.lsr|=1;this.fifo_control&1?this.ThrowInterrupt(12):this.ThrowInterrupt(4)};zc.prototype.write_data=function(a){this.line_control&128?this.baud_rate=this.baud_rate&-256|a:(B("data: "+n(a),16384),this.ThrowInterrupt(2),this.bus.send("serial"+this.com+"-output-byte",a),a=String.fromCharCode(a),this.current_line+=a,"\n"===a&&(a=this.current_line.trimRight().replace(/[\x00-\x08\x0b-\x1f\x7f\x80-\xff]/g,""),B("SERIAL: "+a),this.current_line=""))};
|
|
358
|
+
zc.prototype.set_modem_status=function(a){B("modem status: "+n(a),16384);const b=this.modem_status&15;let c=(this.modem_status^a)>>4;this.modem_status=a;this.modem_status=this.modem_status|c|b};function Ac(a){this.pci_addr=new Uint8Array(4);this.pci_value=new Uint8Array(4);this.pci_response=new Uint8Array(4);this.pci_status=new Uint8Array(4);this.pci_addr32=new Int32Array(this.pci_addr.buffer);this.pci_value32=new Int32Array(this.pci_value.buffer);this.pci_response32=new Int32Array(this.pci_response.buffer);
|
|
359
|
+
this.pci_status32=new Int32Array(this.pci_status.buffer);this.device_spaces=[];this.devices=[];this.cpu=a;for(var b=0;256>b;b++)this.device_spaces[b]=void 0,this.devices[b]=void 0;this.io=a.io;a.io.register_write(3324,this,function(c){this.pci_write8(this.pci_addr32[0],c)},function(c){this.pci_write16(this.pci_addr32[0],c)},function(c){this.pci_write32(this.pci_addr32[0],c)});a.io.register_write(3325,this,function(c){this.pci_write8(this.pci_addr32[0]+1|0,c)});a.io.register_write(3326,this,function(c){this.pci_write8(this.pci_addr32[0]+
|
|
360
|
+
2|0,c)},function(c){this.pci_write16(this.pci_addr32[0]+2|0,c)});a.io.register_write(3327,this,function(c){this.pci_write8(this.pci_addr32[0]+3|0,c)});a.io.register_read_consecutive(3324,this,function(){return this.pci_response[0]},function(){return this.pci_response[1]},function(){return this.pci_response[2]},function(){return this.pci_response[3]});a.io.register_read_consecutive(3320,this,function(){return this.pci_status[0]},function(){return this.pci_status[1]},function(){return this.pci_status[2]},
|
|
361
|
+
function(){return this.pci_status[3]});a.io.register_write_consecutive(3320,this,function(c){this.pci_addr[0]=c&252},function(c){2===(this.pci_addr[1]&6)&&6===(c&6)?(B("CPU reboot via PCI"),a.reboot_internal()):this.pci_addr[1]=c},function(c){this.pci_addr[2]=c},function(c){this.pci_addr[3]=c;this.pci_query()});this.register_device({pci_id:0,pci_space:[134,128,55,18,0,0,0,0,2,0,0,6,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,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,0,0,
|
|
362
|
+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,0,0,0],pci_bars:[],name:"82441FX PMC"});this.isa_bridge={pci_id:8,pci_space:[134,128,0,112,7,0,0,2,0,0,1,6,0,0,128,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],pci_bars:[],name:"82371SB PIIX3 ISA"};this.isa_bridge_space=this.register_device(this.isa_bridge);this.isa_bridge_space8=new Uint8Array(this.isa_bridge_space.buffer)}Ac.prototype.get_state=function(){for(var a=[],b=0;256>b;b++)a[b]=this.device_spaces[b];
|
|
363
|
+
a[256]=this.pci_addr;a[257]=this.pci_value;a[258]=this.pci_response;a[259]=this.pci_status;return a};Ac.prototype.set_state=function(a){for(var b=0;256>b;b++){var c=this.devices[b],d=a[b];if(c&&d){for(var e=0;e<c.pci_bars.length;e++){var f=d[4+e];if(f&1){var g=c.pci_bars[e];this.set_io_bars(g,g.original_bar&65534,f&65534)}}this.device_spaces[b].set(d)}else c&&B("Warning: While restoring PCI device: Device exists in current configuration but not in snapshot ("+c.name+")"),d&&B("Warning: While restoring PCI device: Device doesn't exist in current configuration but does in snapshot (device "+
|
|
364
|
+
n(b,2)+")")}this.pci_addr.set(a[256]);this.pci_value.set(a[257]);this.pci_response.set(a[258]);this.pci_status.set(a[259])};Ac.prototype.pci_query=function(){var a=this.pci_addr[2]<<8|this.pci_addr[1],b=this.pci_addr[0]&252,c=a>>3&31;var d="query enabled="+(this.pci_addr[3]>>7)+(" bdf="+n(a,4));d+=" dev="+n(c,2);d+=" addr="+n(b,2);c=this.device_spaces[a];void 0!==c?(this.pci_status32[0]=-2147483648,this.pci_response32[0]=b<c.byteLength?c[b>>2]:0,d+=" "+n(this.pci_addr32[0]>>>0,8)+" -> "+n(this.pci_response32[0]>>>
|
|
365
|
+
0,8),b>=c.byteLength&&(d+=" (undef)"),d+=" ("+this.devices[a].name+")",B(d,2048)):(this.pci_response32[0]=-1,this.pci_status32[0]=0)};Ac.prototype.pci_write8=function(a,b){var c=a>>8&65535;a&=255;var d=new Uint8Array(this.device_spaces[c].buffer),e=this.devices[c];d&&(l(!(16<=a&&44>a||48<=a&&52>a),"PCI: Expected 32-bit write, got 8-bit (addr: "+n(a)+")"),B("PCI write8 dev="+n(c>>3,2)+" ("+e.name+") addr="+n(a,4)+" value="+n(b,2),2048),d[a]=b)};Ac.prototype.pci_write16=function(a,b){l(0===(a&1));var c=
|
|
366
|
+
a>>8&65535;a&=255;var d=new Uint16Array(this.device_spaces[c].buffer),e=this.devices[c];d&&(16<=a&&44>a?B("Warning: PCI: Expected 32-bit write, got 16-bit (addr: "+n(a)+")"):(l(!(48<=a&&52>a),"PCI: Expected 32-bit write, got 16-bit (addr: "+n(a)+")"),B("PCI writ16 dev="+n(c>>3,2)+" ("+e.name+") addr="+n(a,4)+" value="+n(b,4),2048),d[a>>>1]=b))};Ac.prototype.pci_write32=function(a,b){l(0===(a&3));var c=a>>8&65535;a&=255;var d=this.device_spaces[c],e=this.devices[c];if(d)if(16<=a&&40>a){var f=a-16>>
|
|
367
|
+
2,g=e.pci_bars[f];B("BAR"+f+" exists="+(g?"y":"n")+" changed from "+n(d[a>>2])+" to "+n(b>>>0)+" dev="+n(c>>3,2)+" ("+e.name+") ",2048);g?(l(!(g.size&g.size-1),"bar size should be power of 2"),c=a>>2,e=d[c]&1,-1===(b|3|g.size-1)?(b=~(g.size-1)|e,0===e&&(d[c]=b)):0===e&&(f=g.original_bar,(b&-16)!==(f&-16)&&B("Warning: Changing memory bar not supported, ignored",2048),d[c]=f),1===e&&(l(1===e),e=d[c]&65534,f=b&65534,B("io bar changed from "+n(e>>>0,8)+" to "+n(f>>>0,8)+" size="+g.size,2048),this.set_io_bars(g,
|
|
368
|
+
e,f),d[c]=b|1)):d[a>>2]=0;B("BAR effective value: "+n(d[a>>2]>>>0),2048)}else 48===a?(B("PCI write rom address dev="+n(c>>3,2)+" ("+e.name+") value="+n(b>>>0,8),2048),d[a>>2]=e.pci_rom_size?-1===(b|2047)?-e.pci_rom_size|0:e.pci_rom_address|0:0):4===a?B("PCI write dev="+n(c>>3,2)+" ("+e.name+") addr="+n(a,4)+" value="+n(b>>>0,8),2048):(B("PCI write dev="+n(c>>3,2)+" ("+e.name+") addr="+n(a,4)+" value="+n(b>>>0,8),2048),d[a>>>2]=b)};Ac.prototype.register_device=function(a){l(void 0!==a.pci_id);l(void 0!==
|
|
369
|
+
a.pci_space);l(void 0!==a.pci_bars);var b=a.pci_id;B("PCI register bdf="+n(b)+" ("+a.name+")",2048);this.devices[b]&&B("warning: overwriting device "+this.devices[b].name+" with "+a.name,2048);l(64<=a.pci_space.length);l(b<this.devices.length);var c=new Int32Array(64);c.set(new Int32Array((new Uint8Array(a.pci_space)).buffer));this.device_spaces[b]=c;this.devices[b]=a;b=c.slice(4,10);for(var d=0;d<a.pci_bars.length;d++){var e=a.pci_bars[d];if(e){var f=b[d],g=f&1;B("device "+a.name+" register bar of size "+
|
|
370
|
+
e.size+" at "+n(f),2048);e.original_bar=f;e.entries=[];if(0!==g)for(l(1===g),f&=-2,g=0;g<e.size;g++)e.entries[g]=this.io.ports[f+g]}}return c};Ac.prototype.set_io_bars=function(a,b,c){var d=a.size;B("Move io bars: from="+n(b)+" to="+n(c)+" count="+d,2048);for(var e=this.io.ports,f=0;f<d;f++){4096<=b+f&&(e[b+f]=this.io.create_empty_entry());var g=a.entries[f],k=e[c+f];l(g&&k);4096<=c+f&&(e[c+f]=g)}};Ac.prototype.raise_irq=function(a){var b=this.device_spaces[a];l(b);this.cpu.device_raise_irq(this.isa_bridge_space8[96+
|
|
371
|
+
((b[15]>>8&255)-1+((a>>3)-1&255)&3)])};Ac.prototype.lower_irq=function(a){var b=this.device_spaces[a];l(b);this.cpu.device_lower_irq(this.isa_bridge_space8[96+((b[15]>>8&255)+(a>>3&255)-2&3)])};function Bc(a,b,c){a[0]===b[0]&&a[1]===b[1]&&a[2]===b[2]&&a[3]===b[3]&&a[4]===b[4]&&a[5]===b[5]&&(B("Replace mac in eth destination field",1048576),a[0]=c[0],a[1]=c[1],a[2]=c[2],a[3]=c[3],a[4]=c[4],a[5]=c[5]);a[6]===b[0]&&a[7]===b[1]&&a[8]===b[2]&&a[9]===b[3]&&a[10]===b[4]&&a[11]===b[5]&&(B("Replace mac in eth source field",
|
|
372
|
+
1048576),a[6]=c[0],a[7]=c[1],a[8]=c[2],a[9]=c[3],a[10]=c[4],a[11]=c[5]);var d=a[12]<<8|a[13];if(2048===d)if(a=a.subarray(14),d=a[0]>>4,4!==d)B("Expected ipv4.version==4 but got: "+d,1048576);else{if(l(5===(a[0]&15),"TODO: ihl!=5"),17===a[9]){a=a.subarray(20);d=a[0]<<8|a[1];var e=a[2]<<8|a[3];B("udp srcport="+d+" dstport="+e+" checksum="+n(a[6]<<8|a[7],4),1048576);if(67===d||67===e)if(d=a.subarray(8),e=d[236]<<24|d[237]<<16|d[238]<<8|d[239],1669485411!==e)B("dhcp packet didn't match magic: "+n(e,8));
|
|
373
|
+
else for(d[28]===b[0]&&d[29]===b[1]&&d[30]===b[2]&&d[31]===b[3]&&d[32]===b[4]&&d[33]===b[5]&&(B("Replace mac in dhcp.chaddr",1048576),d[28]=c[0],d[29]=c[1],d[30]=c[2],d[31]=c[3],d[32]=c[4],d[33]=c[5],a[6]=a[7]=0),e=240;e<d.length;){const f=d[e++];if(255===f)break;const g=d[e++];61===f&&1===d[e+0]&&d[e+1]===b[0]&&d[e+2]===b[1]&&d[e+3]===b[2]&&d[e+4]===b[3]&&d[e+5]===b[4]&&d[e+6]===b[5]&&(B("Replace mac in dhcp.clientidentifier",1048576),d[e+1]=c[0],d[e+2]=c[1],d[e+3]=c[2],d[e+4]=c[3],d[e+5]=c[4],d[e+
|
|
374
|
+
6]=c[5],a[6]=a[7]=0);e+=g}}}else 2054===d&&(a=a.subarray(14),B("arp oper="+a[7]+" "+Cc(a.subarray(8,14))+" "+Cc(a.subarray(18,24)),1048576),a[8]===b[0]&&a[9]===b[1]&&a[10]===b[2]&&a[11]===b[3]&&a[12]===b[4]&&a[13]===b[5]&&(B("Replace mac in arp.sha",1048576),a[8]=c[0],a[9]=c[1],a[10]=c[2],a[11]=c[3],a[12]=c[4],a[13]=c[5]))}function Cc(a){return[a[0].toString(16).padStart(2,"0"),a[1].toString(16).padStart(2,"0"),a[2].toString(16).padStart(2,"0"),a[3].toString(16).padStart(2,"0"),a[4].toString(16).padStart(2,
|
|
375
|
+
"0"),a[5].toString(16).padStart(2,"0")].join(":")}function Dc(a,b,c,d,e){this.cpu=a;this.pci=a.devices.pci;this.id=e||0;this.preserve_mac_from_state_image=c;this.mac_address_translation=d;this.bus=b;this.bus.register("net"+this.id+"-receive",function(f){this.receive(f)},this);this.port=768+256*this.id;this.name="ne2k";this.pci_space=[236,16,41,128,3,1,0,0,0,0,0,2,0,0,0,0,this.port&255|1,this.port>>8,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,244,26,0,17,0,0,184,254,0,0,0,0,0,0,0,0,0,1,0,
|
|
376
|
+
0];this.pci_id=(0===this.id?5:7+this.id)<<3;this.pci_bars=[{size:32}];this.imr=this.isr=0;this.cr=1;this.tpsr=this.tcnt=this.rcnt=this.dcfg=0;this.memory=new Uint8Array(32768);this.txcr=this.rxcr=0;this.tsr=1;this.mac=new Uint8Array([0,34,21,255*Math.random()|0,255*Math.random()|0,255*Math.random()|0]);this.bus.send("net"+this.id+"-mac",Cc(this.mac));this.mar=Uint8Array.of(255,255,255,255,255,255,255,255);this.mac_address_in_state=null;for(b=0;6>b;b++)this.memory[b<<1]=this.memory[b<<1|1]=this.mac[b];
|
|
377
|
+
this.memory[28]=this.memory[29]=87;this.memory[30]=this.memory[31]=87;B("Mac: "+Cc(this.mac),1048576);this.rsar=0;this.pstart=64;this.pstop=128;this.boundary=this.curpg=76;b=a.io;b.register_read(this.port|0,this,function(){B("Read cmd",1048576);return this.cr},function(){B("Read16 cmd",1048576);return this.cr});b.register_write(this.port|0,this,function(f){this.cr=f;B("Write command: "+n(f,2)+" newpg="+(this.cr>>6)+" txcr="+n(this.txcr,2),1048576);this.cr&1||(f&24&&0===this.rcnt&&this.do_interrupt(64),
|
|
378
|
+
f&4&&(f=this.tpsr<<8,f=this.memory.subarray(f,f+this.tcnt),this.mac_address_in_state&&(f=new Uint8Array(f),Bc(f,this.mac_address_in_state,this.mac)),this.bus.send("net"+this.id+"-send",f),this.bus.send("eth-transmit-end",[f.length]),this.cr&=-5,this.do_interrupt(2),B("Command: Transfer. length="+n(f.byteLength),1048576)))});b.register_read(this.port|13,this,function(){var f=this.get_page();if(1===f)return B("Read mar5",1048576),this.mar[5];B("Read counter0 pg="+f,1048576);return 0});b.register_read(this.port|
|
|
379
|
+
14,this,function(){var f=this.get_page();if(1===f)return B("Read mar6",1048576),this.mar[6];B("Read8 counter1 pg="+f,1048576);return 0},function(){B("Read16 counter1 pg="+this.get_page(),1048576);return 0});b.register_read(this.port|15,this,function(){var f=this.get_page();if(1===f)return B("Read mar7",1048576),this.mar[7];B("Read counter2 pg="+f,1048576);return 0});b.register_read(this.port|31,this,function(){this.get_page();B("Read reset",1048576);this.do_interrupt(128);return 0});b.register_write(this.port|
|
|
380
|
+
31,this,function(f){this.get_page();B("Write reset: "+n(f,2),1048576)});b.register_read(this.port|1,this,function(){var f=this.get_page();if(0===f)return this.pstart;if(1===f)return B("Read pg1/01 (mac[0])",1048576),this.mac[0];if(2===f)return this.pstart;B("Read pg"+f+"/01");l(!1);return 0});b.register_write(this.port|1,this,function(f){var g=this.get_page();0===g?(B("start page: "+n(f,2),1048576),this.pstart=f):1===g?(B("mac[0] = "+n(f),1048576),this.mac[0]=f):3===g?B("Unimplemented: Write pg3/01 (9346CR): "+
|
|
381
|
+
n(f),1048576):(B("Write pg"+g+"/01: "+n(f),1048576),l(!1))});b.register_read(this.port|2,this,function(){var f=this.get_page();if(0===f)return this.pstop;if(1===f)return B("Read pg1/02 (mac[1])",1048576),this.mac[1];if(2===f)return this.pstop;B("Read pg"+f+"/02",1048576);l(!1);return 0});b.register_write(this.port|2,this,function(f){var g=this.get_page();0===g?(B("stop page: "+n(f,2),1048576),f>this.memory.length>>8&&(f=this.memory.length>>8,B("XXX: Adjusting stop page to "+n(f),1048576)),this.pstop=
|
|
382
|
+
f):1===g?(B("mac[1] = "+n(f),1048576),this.mac[1]=f):(B("Write pg"+g+"/02: "+n(f),1048576),l(!1))});b.register_read(this.port|7,this,function(){var f=this.get_page();if(0===f)return B("Read isr: "+n(this.isr,2),1048576),this.isr;if(1===f)return B("Read curpg: "+n(this.curpg,2),1048576),this.curpg;l(!1);return 0});b.register_write(this.port|7,this,function(f){var g=this.get_page();0===g?(B("Write isr: "+n(f,2),1048576),this.isr&=~f,this.update_irq()):1===g?(B("Write curpg: "+n(f,2),1048576),this.curpg=
|
|
383
|
+
f):l(!1)});b.register_write(this.port|13,this,function(f){var g=this.get_page();0===g?(this.txcr=f,B("Write tx config: "+n(f,2),1048576)):B("Unimplemented: Write pg"+g+"/0d "+n(f,2),1048576)});b.register_write(this.port|14,this,function(f){var g=this.get_page();0===g?(B("Write data configuration: "+n(f,2),1048576),this.dcfg=f):B("Unimplemented: Write pg"+g+"/0e "+n(f,2),1048576)});b.register_read(this.port|10,this,function(){var f=this.get_page();if(0===f)return B("Read pg0/0a",1048576),80;if(1===
|
|
384
|
+
f)return B("Read mar2",1048576),this.mar[2];l(!1,"TODO");return 0});b.register_write(this.port|10,this,function(f){var g=this.get_page();0===g?(B("Write remote byte count low: "+n(f,2),1048576),this.rcnt=this.rcnt&65280|f&255):B("Unimplemented: Write pg"+g+"/0a "+n(f,2),1048576)});b.register_read(this.port|11,this,function(){var f=this.get_page();if(0===f)return B("Read pg0/0b",1048576),67;if(1===f)return B("Read mar3",1048576),this.mar[3];l(!1,"TODO");return 0});b.register_write(this.port|11,this,
|
|
385
|
+
function(f){var g=this.get_page();0===g?(B("Write remote byte count high: "+n(f,2),1048576),this.rcnt=this.rcnt&255|f<<8&65280):B("Unimplemented: Write pg"+g+"/0b "+n(f,2),1048576)});b.register_read(this.port|8,this,function(){var f=this.get_page();if(0===f)return B("Read remote start address low",1048576),this.rsar&255;if(1===f)return B("Read mar0",1048576),this.mar[0];B("Unimplemented: Read pg"+f+"/08",1048576);l(!1);return 0});b.register_write(this.port|8,this,function(f){var g=this.get_page();
|
|
386
|
+
0===g?(B("Write remote start address low: "+n(f,2),1048576),this.rsar=this.rsar&65280|f&255):B("Unimplemented: Write pg"+g+"/08 "+n(f,2),1048576)});b.register_read(this.port|9,this,function(){var f=this.get_page();if(0===f)return B("Read remote start address high",1048576),this.rsar>>8&255;if(1===f)return B("Read mar1",1048576),this.mar[1];B("Unimplemented: Read pg"+f+"/09",1048576);l(!1);return 0});b.register_write(this.port|9,this,function(f){var g=this.get_page();0===g?(B("Write remote start address low: "+
|
|
387
|
+
n(f,2),1048576),this.rsar=this.rsar&255|f<<8&65280):B("Unimplemented: Write pg"+g+"/09 "+n(f,2),1048576)});b.register_write(this.port|15,this,function(f){var g=this.get_page();0===g?(B("Write interrupt mask register: "+n(f,2)+" isr="+n(this.isr,2),1048576),this.imr=f,this.update_irq()):B("Unimplemented: Write pg"+g+"/0f "+n(f,2),1048576)});b.register_read(this.port|3,this,function(){var f=this.get_page();if(0===f)return B("Read boundary: "+n(this.boundary,2),1048576),this.boundary;if(1===f)return B("Read pg1/03 (mac[2])",
|
|
388
|
+
1048576),this.mac[2];3===f?B("Unimplemented: Read pg3/03 (CONFIG0)",1048576):(B("Read pg"+f+"/03",1048576),l(!1));return 0});b.register_write(this.port|3,this,function(f){var g=this.get_page();0===g?(B("Write boundary: "+n(f,2),1048576),this.boundary=f):1===g?(B("mac[2] = "+n(f),1048576),this.mac[2]=f):(B("Write pg"+g+"/03: "+n(f),1048576),l(!1))});b.register_read(this.port|4,this,function(){var f=this.get_page();if(0===f)return this.tsr;if(1===f)return B("Read pg1/04 (mac[3])",1048576),this.mac[3];
|
|
389
|
+
B("Read pg"+f+"/04",1048576);l(!1);return 0});b.register_write(this.port|4,this,function(f){var g=this.get_page();0===g?(B("Write tpsr: "+n(f,2),1048576),this.tpsr=f):1===g?(B("mac[3] = "+n(f),1048576),this.mac[3]=f):(B("Write pg"+g+"/04: "+n(f),1048576),l(!1))});b.register_read(this.port|5,this,function(){var f=this.get_page();if(0===f)return B("Unimplemented: Read pg0/05 (NCR: Number of Collisions Register)",1048576),0;if(1===f)return B("Read pg1/05 (mac[4])",1048576),this.mac[4];3===f?B("Unimplemented: Read pg3/05 (CONFIG2)",
|
|
390
|
+
1048576):(B("Read pg"+f+"/05",1048576),l(!1));return 0});b.register_write(this.port|5,this,function(f){var g=this.get_page();0===g?(B("Write tcnt low: "+n(f,2),1048576),this.tcnt=this.tcnt&-256|f):1===g?(B("mac[4] = "+n(f),1048576),this.mac[4]=f):3===g?B("Unimplemented: Write pg3/05 (CONFIG2): "+n(f),1048576):(B("Write pg"+g+"/05: "+n(f),1048576),l(!1))});b.register_read(this.port|6,this,function(){var f=this.get_page();if(0===f)return l(!1,"TODO"),0;if(1===f)return B("Read pg1/06 (mac[5])",1048576),
|
|
391
|
+
this.mac[5];3===f?B("Unimplemented: Read pg3/06 (CONFIG3)",1048576):(B("Read pg"+f+"/06",1048576),l(!1));return 0});b.register_write(this.port|6,this,function(f){var g=this.get_page();0===g?(B("Write tcnt high: "+n(f,2),1048576),this.tcnt=this.tcnt&255|f<<8):1===g?(B("mac[5] = "+n(f),1048576),this.mac[5]=f):3===g?B("Unimplemented: Write pg3/06 (CONFIG3): "+n(f),1048576):(B("Write pg"+g+"/06: "+n(f),1048576),l(!1))});b.register_read(this.port|12,this,function(){var f=this.get_page();if(0===f)return 9;
|
|
392
|
+
if(1===f)return B("Read mar4",1048576),this.mar[4];B("Unimplemented: Read pg"+f+"/0c",1048576);l(!1);return 0});b.register_write(this.port|12,this,function(f){var g=this.get_page();0===g?(B("RX configuration reg write: "+n(f,2),1048576),this.rxcr=f):B("Unimplemented: Write pg"+g+"/0c: "+n(f),1048576)});b.register_read(this.port|16,this,this.data_port_read8,this.data_port_read16,this.data_port_read32);b.register_write(this.port|16,this,this.data_port_write16,this.data_port_write16,this.data_port_write32);
|
|
393
|
+
a.devices.pci.register_device(this)}Dc.prototype.get_state=function(){var a=[];a[0]=this.isr;a[1]=this.imr;a[2]=this.cr;a[3]=this.dcfg;a[4]=this.rcnt;a[5]=this.tcnt;a[6]=this.tpsr;a[7]=this.rsar;a[8]=this.pstart;a[9]=this.curpg;a[10]=this.boundary;a[11]=this.pstop;a[12]=this.rxcr;a[13]=this.txcr;a[14]=this.tsr;a[15]=this.mac;a[16]=this.memory;return a};Dc.prototype.set_state=function(a){this.isr=a[0];this.imr=a[1];this.cr=a[2];this.dcfg=a[3];this.rcnt=a[4];this.tcnt=a[5];this.tpsr=a[6];this.rsar=
|
|
394
|
+
a[7];this.pstart=a[8];this.curpg=a[9];this.boundary=a[10];this.pstop=a[11];this.rxcr=a[12];this.txcr=a[13];this.tsr=a[14];this.preserve_mac_from_state_image?(this.mac=a[15],this.memory=a[16]):this.mac_address_translation&&(this.mac_address_in_state=a[15],this.memory=a[16],B("Using mac address translation guest_os_mac="+Cc(this.mac_address_in_state)+" real_mac="+Cc(this.mac),1048576));this.bus.send("net"+this.id+"-mac",Cc(this.mac))};Dc.prototype.do_interrupt=function(a){B("Do interrupt "+n(a,2),1048576);
|
|
395
|
+
this.isr|=a;this.update_irq()};Dc.prototype.update_irq=function(){this.imr&this.isr?this.pci.raise_irq(this.pci_id):this.pci.lower_irq(this.pci_id)};Dc.prototype.data_port_write=function(a){if(16>=this.rsar||16384<=this.rsar&&32768>this.rsar)this.memory[this.rsar]=a;this.rsar++;this.rcnt--;this.rsar>=this.pstop<<8&&(this.rsar+=this.pstart-this.pstop<<8);0===this.rcnt&&this.do_interrupt(64)};Dc.prototype.data_port_write16=function(a){this.data_port_write(a);this.dcfg&1&&this.data_port_write(a>>8)};
|
|
396
|
+
Dc.prototype.data_port_write32=function(a){this.data_port_write(a);this.data_port_write(a>>8);this.data_port_write(a>>16);this.data_port_write(a>>24)};Dc.prototype.data_port_read=function(){let a=0;32768>this.rsar&&(a=this.memory[this.rsar]);this.rsar++;this.rcnt--;this.rsar>=this.pstop<<8&&(this.rsar+=this.pstart-this.pstop<<8);0===this.rcnt&&this.do_interrupt(64);return a};Dc.prototype.data_port_read8=function(){return this.data_port_read16()&255};Dc.prototype.data_port_read16=function(){return this.dcfg&
|
|
397
|
+
1?this.data_port_read()|this.data_port_read()<<8:this.data_port_read()};Dc.prototype.data_port_read32=function(){return this.data_port_read()|this.data_port_read()<<8|this.data_port_read()<<16|this.data_port_read()<<24};Dc.prototype.receive=function(a){if(!(this.cr&1)&&(this.bus.send("eth-receive-end",[a.length]),this.rxcr&16||this.rxcr&4&&255===a[0]&&255===a[1]&&255===a[2]&&255===a[3]&&255===a[4]&&255===a[5]||!(this.rxcr&8&&1===(a[0]&1)||a[0]!==this.mac[0]||a[1]!==this.mac[1]||a[2]!==this.mac[2]||
|
|
398
|
+
a[3]!==this.mac[3]||a[4]!==this.mac[4]||a[5]!==this.mac[5]))){this.mac_address_in_state&&(a=new Uint8Array(a),Bc(a,this.mac,this.mac_address_in_state));var b=this.curpg<<8,c=Math.max(60,a.length)+4,d=b+4,e=this.curpg+1+(c>>8),f=b+c,g=1+(c>>8),k=this.boundary>this.curpg?this.boundary-this.curpg:this.pstop-this.curpg+this.boundary-this.pstart;k<g&&0!==this.boundary?B("Buffer full, dropping packet pstart="+n(this.pstart)+" pstop="+n(this.pstop)+" curpg="+n(this.curpg)+" needed="+n(g)+" boundary="+n(this.boundary)+
|
|
399
|
+
" available="+n(k),1048576):(f>this.pstop<<8?(l(60<=a.length),f=(this.pstop<<8)-d,l(0<=f),this.memory.set(a.subarray(0,f),d),this.memory.set(a.subarray(f),this.pstart<<8),B("rcv cut="+n(f),1048576)):(this.memory.set(a,d),60>a.length&&this.memory.fill(0,d+a.length,d+60)),e>=this.pstop&&(e+=this.pstart-this.pstop),this.memory[b]=1,this.memory[b+1]=e,this.memory[b+2]=c,this.memory[b+3]=c>>8,this.curpg=e,B("rcv offset="+n(b)+" len="+n(c)+" next="+n(e),1048576),this.do_interrupt(1))}};Dc.prototype.get_page=
|
|
400
|
+
function(){return this.cr>>6&3};function Ec(a,b){this.bus=b;this.rows=25;this.cols=80;this.ports=4;b=[{size_supported:16,notify_offset:0},{size_supported:16,notify_offset:1},{size_supported:16,notify_offset:2},{size_supported:16,notify_offset:3}];for(let c=1;c<this.ports;++c)b.push({size_supported:16,notify_offset:0}),b.push({size_supported:8,notify_offset:1});this.virtio=new Fc(a,{name:"virtio-console",pci_id:96,device_id:4163,subsystem_device_id:3,common:{initial_port:47104,queues:b,features:[0,
|
|
401
|
+
1,32],on_driver_ok:()=>{}},notification:{initial_port:47360,single_handler:!1,handlers:[()=>{},c=>{const d=this.virtio.queues[c],e=3<c?c-3>>1:0;for(;d.has_request();){const f=d.pop_request(),g=new Uint8Array(f.length_readable);f.get_next_blob(g);this.bus.send("virtio-console"+e+"-output-bytes",g);this.Ack(c,f)}},c=>{if(2!==c)l(!1,"VirtioConsole Notified for wrong queue: "+c+" (expected queue_id of 2)");else for(c=this.virtio.queues[c];c.count_requests()>c.size-2;)c.pop_request()},c=>{if(3!==c)l(!1,
|
|
402
|
+
"VirtioConsole Notified for wrong queue: "+c+" (expected queue_id of 3)");else for(var d=this.virtio.queues[c];d.has_request();){var e=d.pop_request(),f=new Uint8Array(e.length_readable);e.get_next_blob(f);var g=J(["w","h","h"],f,{offset:0});f=g[0];g=g[1];this.Ack(c,e);switch(g){case 0:for(e=0;e<this.ports;++e)this.SendEvent(e,1,0);break;case 3:this.Ack(c,e);this.SendEvent(f,4,1);this.SendName(f,"virtio-"+f);this.SendEvent(f,6,1);break;case 6:this.Ack(c,e);0===f&&this.SendWindowSize(f);break;default:l(!1,
|
|
403
|
+
" VirtioConsole received unknown event: "+g[1]);return}}}]},isr_status:{initial_port:46848},device_specific:{initial_port:46592,struct:[{bytes:2,name:"cols",read:()=>this.cols,write:()=>{}},{bytes:2,name:"rows",read:()=>this.rows,write:()=>{}},{bytes:4,name:"max_nr_ports",read:()=>this.ports,write:()=>{}},{bytes:4,name:"emerg_wr",read:()=>0,write:()=>{l(!1,"Emergency write!")}}]}});for(let c=0;c<this.ports;++c){const d=0===c?0:2*c+2;this.bus.register("virtio-console"+c+"-input-bytes",function(e){var f=
|
|
404
|
+
this.virtio.queues[d];f.has_request()&&(f=f.pop_request(),this.Send(d,f,new Uint8Array(e)))},this);this.bus.register("virtio-console"+c+"-resize",function(e){0===c&&(this.cols=e[0],this.rows=e[1]);this.virtio.queues[2].is_configured()&&this.virtio.queues[2].has_request()&&this.SendWindowSize(c,e[0],e[1])},this)}}Ec.prototype.SendWindowSize=function(a,b,c){c=c||this.rows;b=b||this.cols;const d=this.virtio.queues[2].pop_request(),e=new Uint8Array(12);I(["w","h","h","h","h"],[a,5,0,c,b],e,0);this.Send(2,
|
|
405
|
+
d,e)};Ec.prototype.SendName=function(a,b){const c=this.virtio.queues[2].pop_request();b=(new TextEncoder).encode(b);const d=new Uint8Array(8+b.length+1);I(["w","h","h"],[a,7,1],d,0);for(a=0;a<b.length;++a)d[a+8]=b[a];d[8+b.length]=0;this.Send(2,c,d)};Ec.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.rows;a[2]=this.cols;a[3]=this.ports;return a};Ec.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.rows=a[1];this.cols=a[2];this.ports=a[3]};Ec.prototype.reset=function(){this.virtio.reset()};
|
|
406
|
+
Ec.prototype.SendEvent=function(a,b,c){const d=this.virtio.queues[2].pop_request(),e=new Uint8Array(8);I(["w","h","h"],[a,b,c],e,0);this.Send(2,d,e)};Ec.prototype.Send=function(a,b,c){b.set_next_blob(c);this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};Ec.prototype.Ack=function(a,b){b.set_next_blob(new Uint8Array(0));this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};function Gc(a,b){this.cpu=a;this.bus=b;this.reset();this.bus.register("keyboard-code",
|
|
407
|
+
function(c){this.kbd_send_code(c)},this);this.bus.register("mouse-click",function(c){this.mouse_send_click(c[0],c[1],c[2])},this);this.bus.register("mouse-delta",function(c){this.mouse_send_delta(c[0],c[1])},this);this.bus.register("mouse-wheel",function(c){this.wheel_movement-=c[0];this.wheel_movement-=2*c[1];this.wheel_movement=Math.min(7,Math.max(-8,this.wheel_movement));this.send_mouse_packet(0,0)},this);a.io.register_read(96,this,this.port60_read);a.io.register_read(100,this,this.port64_read);
|
|
408
|
+
a.io.register_write(96,this,this.port60_write);a.io.register_write(100,this,this.port64_write)}Gc.prototype.reset=function(){this.use_mouse=this.enable_mouse_stream=!1;this.have_mouse=!0;this.mouse_clicks=this.mouse_delta_y=this.mouse_delta_x=0;this.have_keyboard=!0;this.next_read_resolution=this.next_read_rate=this.next_handle_scan_code_set=this.next_read_led=this.next_read_sample=this.next_is_mouse_command=this.enable_keyboard_stream=!1;this.kbd_buffer=new na(1024);this.last_port60_byte=0;this.sample_rate=
|
|
409
|
+
100;this.mouse_id=this.mouse_detect_state=0;this.mouse_reset_workaround=!1;this.wheel_movement=0;this.resolution=4;this.scaling2=!1;this.last_mouse_packet=-1;this.mouse_buffer=new na(1024);this.next_byte_is_aux=this.next_byte_is_ready=!1;this.command_register=5;this.controller_output_port=0;this.read_controller_output_port=this.read_command_register=this.read_output_register=!1};Gc.prototype.get_state=function(){var a=[];a[0]=this.enable_mouse_stream;a[1]=this.use_mouse;a[2]=this.have_mouse;a[3]=
|
|
410
|
+
this.mouse_delta_x;a[4]=this.mouse_delta_y;a[5]=this.mouse_clicks;a[6]=this.have_keyboard;a[7]=this.enable_keyboard_stream;a[8]=this.next_is_mouse_command;a[9]=this.next_read_sample;a[10]=this.next_read_led;a[11]=this.next_handle_scan_code_set;a[12]=this.next_read_rate;a[13]=this.next_read_resolution;a[15]=this.last_port60_byte;a[16]=this.sample_rate;a[17]=this.resolution;a[18]=this.scaling2;a[20]=this.command_register;a[21]=this.read_output_register;a[22]=this.read_command_register;a[23]=this.controller_output_port;
|
|
411
|
+
a[24]=this.read_controller_output_port;a[25]=this.mouse_id;a[26]=this.mouse_detect_state;a[27]=this.mouse_reset_workaround;return a};Gc.prototype.set_state=function(a){this.enable_mouse_stream=a[0];this.use_mouse=a[1];this.have_mouse=a[2];this.mouse_delta_x=a[3];this.mouse_delta_y=a[4];this.mouse_clicks=a[5];this.have_keyboard=a[6];this.enable_keyboard_stream=a[7];this.next_is_mouse_command=a[8];this.next_read_sample=a[9];this.next_read_led=a[10];this.next_handle_scan_code_set=a[11];this.next_read_rate=
|
|
412
|
+
a[12];this.next_read_resolution=a[13];this.last_port60_byte=a[15];this.sample_rate=a[16];this.resolution=a[17];this.scaling2=a[18];this.command_register=a[20];this.read_output_register=a[21];this.read_command_register=a[22];this.controller_output_port=a[23];this.read_controller_output_port=a[24];this.mouse_id=a[25]||0;this.mouse_detect_state=a[26]||0;this.mouse_reset_workaround=a[27]||!1;this.next_byte_is_aux=this.next_byte_is_ready=!1;this.kbd_buffer.clear();this.mouse_buffer.clear();this.bus.send("mouse-enable",
|
|
413
|
+
this.use_mouse)};Gc.prototype.raise_irq=function(){this.next_byte_is_ready||(this.kbd_buffer.length?this.kbd_irq():this.mouse_buffer.length&&this.mouse_irq())};Gc.prototype.mouse_irq=function(){this.next_byte_is_aux=this.next_byte_is_ready=!0;this.command_register&2&&(B("Mouse irq",64),this.cpu.device_lower_irq(12),this.cpu.device_raise_irq(12))};Gc.prototype.kbd_irq=function(){this.next_byte_is_ready=!0;this.next_byte_is_aux=!1;this.command_register&1&&(B("Keyboard irq",64),this.cpu.device_lower_irq(1),
|
|
414
|
+
this.cpu.device_raise_irq(1))};Gc.prototype.kbd_send_code=function(a){this.enable_keyboard_stream&&(B("adding kbd code: "+n(a),64),this.kbd_buffer.push(a),this.raise_irq())};Gc.prototype.mouse_send_delta=function(a,b){this.have_mouse&&this.use_mouse&&(this.mouse_delta_x+=1*a,this.mouse_delta_y+=1*b,this.enable_mouse_stream&&(a=this.mouse_delta_x|0,b=this.mouse_delta_y|0,a||b))&&(this.mouse_delta_x-=a,this.mouse_delta_y-=b,this.send_mouse_packet(a,b))};Gc.prototype.mouse_send_click=function(a,b,c){this.have_mouse&&
|
|
415
|
+
this.use_mouse&&(this.mouse_clicks=a|c<<1|b<<2,this.enable_mouse_stream&&this.send_mouse_packet(0,0))};Gc.prototype.send_mouse_packet=function(a,b){var c=(0>b)<<5|(0>a)<<4|8|this.mouse_clicks;this.last_mouse_packet=Date.now();this.mouse_buffer.push(c);this.mouse_buffer.push(a);this.mouse_buffer.push(b);4===this.mouse_id?(this.mouse_buffer.push(0|this.wheel_movement&15),this.wheel_movement=0):3===this.mouse_id&&(this.mouse_buffer.push(this.wheel_movement&255),this.wheel_movement=0);this.raise_irq()};
|
|
416
|
+
Gc.prototype.apply_scaling2=function(a){var b=a>>31;switch(Math.abs(a)){case 0:case 1:case 3:return a;case 2:return b;case 4:return 6*b;case 5:return 9*b;default:return a<<1}};Gc.prototype.port60_read=function(){this.next_byte_is_ready=!1;if(!this.kbd_buffer.length&&!this.mouse_buffer.length)return B("Port 60 read: Empty",64),this.last_port60_byte;this.next_byte_is_aux?(this.cpu.device_lower_irq(12),this.last_port60_byte=this.mouse_buffer.shift(),B("Port 60 read (mouse): "+n(this.last_port60_byte),
|
|
417
|
+
64)):(this.cpu.device_lower_irq(1),this.last_port60_byte=this.kbd_buffer.shift(),B("Port 60 read (kbd) : "+n(this.last_port60_byte),64));(this.kbd_buffer.length||this.mouse_buffer.length)&&this.raise_irq();return this.last_port60_byte};Gc.prototype.port64_read=function(){var a=16;this.next_byte_is_ready&&(a|=1);this.next_byte_is_aux&&(a|=32);B("port 64 read: "+n(a),64);return a};Gc.prototype.port60_write=function(a){B("port 60 write: "+n(a),64);if(this.read_command_register)this.command_register=
|
|
418
|
+
a,this.read_command_register=!1,B("Keyboard command register = "+n(this.command_register),64);else if(this.read_output_register)this.read_output_register=!1,this.mouse_buffer.clear(),this.mouse_buffer.push(a),this.mouse_irq();else if(this.next_read_sample){this.next_read_sample=!1;this.mouse_buffer.clear();this.mouse_buffer.push(250);this.sample_rate=a;switch(this.mouse_detect_state){case -1:60===a?(this.mouse_reset_workaround=!0,this.mouse_detect_state=0):(this.mouse_reset_workaround=!1,this.mouse_detect_state=
|
|
419
|
+
200===a?1:0);break;case 0:200===a&&(this.mouse_detect_state=1);break;case 1:this.mouse_detect_state=100===a?2:200===a?3:0;break;case 2:80===a&&(this.mouse_id=3);this.mouse_detect_state=-1;break;case 3:80===a&&(this.mouse_id=4),this.mouse_detect_state=-1}B("mouse sample rate: "+n(a)+", mouse id: "+n(this.mouse_id),64);this.sample_rate||(B("invalid sample rate, reset to 100",64),this.sample_rate=100);this.mouse_irq()}else if(this.next_read_resolution)this.next_read_resolution=!1,this.mouse_buffer.clear(),
|
|
420
|
+
this.mouse_buffer.push(250),3<a?(this.resolution=4,B("invalid resolution, resetting to 4",64)):(this.resolution=1<<a,B("resolution: "+this.resolution,64)),this.mouse_irq();else if(this.next_read_led)this.next_read_led=!1,this.kbd_buffer.push(250),this.kbd_irq();else if(this.next_handle_scan_code_set)this.next_handle_scan_code_set=!1,this.kbd_buffer.push(250),this.kbd_irq(),a||this.kbd_buffer.push(1);else if(this.next_read_rate)this.next_read_rate=!1,this.kbd_buffer.push(250),this.kbd_irq();else if(this.next_is_mouse_command){if(this.next_is_mouse_command=
|
|
421
|
+
!1,B("Port 60 data register write: "+n(a),64),this.have_mouse){this.kbd_buffer.clear();this.mouse_buffer.clear();this.mouse_buffer.push(250);switch(a){case 230:B("Scaling 1:1",64);this.scaling2=!1;break;case 231:B("Scaling 2:1",64);this.scaling2=!0;break;case 232:this.next_read_resolution=!0;break;case 233:this.send_mouse_packet(0,0);break;case 235:B("unimplemented request single packet",64);this.send_mouse_packet(0,0);break;case 242:B("required id: "+n(this.mouse_id),64);this.mouse_buffer.push(this.mouse_id);
|
|
422
|
+
this.mouse_clicks=this.mouse_delta_x=this.mouse_delta_y=0;this.raise_irq();break;case 243:this.next_read_sample=!0;break;case 244:this.use_mouse=this.enable_mouse_stream=!0;this.bus.send("mouse-enable",!0);this.mouse_clicks=this.mouse_delta_x=this.mouse_delta_y=0;break;case 245:this.enable_mouse_stream=!1;break;case 246:this.enable_mouse_stream=!1;this.sample_rate=100;this.scaling2=!1;this.resolution=4;break;case 255:B("Mouse reset",64);this.mouse_buffer.push(170);this.mouse_buffer.push(0);this.use_mouse=
|
|
423
|
+
!0;this.bus.send("mouse-enable",!0);this.enable_mouse_stream=!1;this.sample_rate=100;this.scaling2=!1;this.resolution=4;this.mouse_reset_workaround||(this.mouse_id=0);this.mouse_clicks=this.mouse_delta_x=this.mouse_delta_y=0;break;default:B("Unimplemented mouse command: "+n(a),64)}this.mouse_irq()}}else if(this.read_controller_output_port)this.read_controller_output_port=!1,this.controller_output_port=a;else{B("Port 60 data register write: "+n(a),64);this.mouse_buffer.clear();this.kbd_buffer.clear();
|
|
424
|
+
this.kbd_buffer.push(250);switch(a){case 237:this.next_read_led=!0;break;case 240:this.next_handle_scan_code_set=!0;break;case 242:this.kbd_buffer.push(171);this.kbd_buffer.push(131);break;case 243:this.next_read_rate=!0;break;case 244:B("kbd enable scanning",64);this.enable_keyboard_stream=!0;break;case 245:B("kbd disable scanning",64);this.enable_keyboard_stream=!1;break;case 246:break;case 255:this.kbd_buffer.clear();this.kbd_buffer.push(250);this.kbd_buffer.push(170);this.kbd_buffer.push(0);break;
|
|
425
|
+
default:B("Unimplemented keyboard command: "+n(a),64)}this.kbd_irq()}};Gc.prototype.port64_write=function(a){B("port 64 write: "+n(a),64);switch(a){case 32:this.kbd_buffer.clear();this.mouse_buffer.clear();this.kbd_buffer.push(this.command_register);this.kbd_irq();break;case 96:this.read_command_register=!0;break;case 209:this.read_controller_output_port=!0;break;case 211:this.read_output_register=!0;break;case 212:this.next_is_mouse_command=!0;break;case 167:B("Disable second port",64);this.command_register|=
|
|
426
|
+
32;break;case 168:B("Enable second port",64);this.command_register&=-33;break;case 169:this.kbd_buffer.clear();this.mouse_buffer.clear();this.kbd_buffer.push(0);this.kbd_irq();break;case 170:this.kbd_buffer.clear();this.mouse_buffer.clear();this.kbd_buffer.push(85);this.kbd_irq();break;case 171:this.kbd_buffer.clear();this.mouse_buffer.clear();this.kbd_buffer.push(0);this.kbd_irq();break;case 173:B("Disable Keyboard",64);this.command_register|=16;break;case 174:B("Enable Keyboard",64);this.command_register&=
|
|
427
|
+
-17;break;case 254:B("CPU reboot via PS2");this.cpu.reboot_internal();break;default:B("port 64: Unimplemented command byte: "+n(a),64)}};const Hc=DataView.prototype,Ic={size:1,get:Hc.getUint8,set:Hc.setUint8},Jc={size:2,get:Hc.getUint16,set:Hc.setUint16},Q={size:4,get:Hc.getUint32,set:Hc.setUint32},Lc=Kc([{magic:Q},{class:Ic},{data:Ic},{version0:Ic},{osabi:Ic},{abiversion:Ic},{pad0:function(a){return{size:a,get:()=>-1}}(7)},{type:Jc},{machine:Jc},{version1:Q},{entry:Q},{phoff:Q},{shoff:Q},{flags:Q},
|
|
428
|
+
{ehsize:Jc},{phentsize:Jc},{phnum:Jc},{shentsize:Jc},{shnum:Jc},{shstrndx:Jc}]);console.assert(52===Lc.reduce((a,b)=>a+b.size,0));const Mc=Kc([{type:Q},{offset:Q},{vaddr:Q},{paddr:Q},{filesz:Q},{memsz:Q},{flags:Q},{align:Q}]);console.assert(32===Mc.reduce((a,b)=>a+b.size,0));const Nc=Kc([{name:Q},{type:Q},{flags:Q},{addr:Q},{offset:Q},{size:Q},{link:Q},{info:Q},{addralign:Q},{entsize:Q}]);console.assert(40===Nc.reduce((a,b)=>a+b.size,0));function Kc(a){return a.map(function(b){var c=Object.keys(b);
|
|
429
|
+
console.assert(1===c.length);c=c[0];b=b[c];console.assert(0<b.size);return{name:c,type:b,size:b.size,get:b.get,set:b.set}})}function Oc(a,b){const c={};let d=0;for(const e of b)b=e.get.call(a,d,!0),console.assert(void 0===c[e.name]),c[e.name]=b,d+=e.size;return[c,d]}function Pc(a,b,c){const d=[];let e=0;for(var f=0;f<c;f++){const [g,k]=Oc(new DataView(a.buffer,a.byteOffset+e,void 0),b);d.push(g);e+=k}return[d,e]}const Qc={[0]:0,[1]:525,[2]:525,[3]:350,[4]:350,[5]:350};function W(a,b,c,d){this.io=
|
|
430
|
+
a.io;this.cpu=a;this.dma=a.devices.dma;this.cmd_table=this.build_cmd_lookup_table();this.sra=0;this.srb=192;this.dor=12;this.tdr=0;this.msr=128;this.dsr=0;this.cmd_phase=1;this.cmd_flags=this.cmd_code=0;this.cmd_buffer=new Uint8Array(17);this.cmd_remaining=this.cmd_cursor=0;this.response_data=new Uint8Array(15);this.reset_sense_int_count=this.curr_drive_no=this.status1=this.status0=this.response_length=this.response_cursor=0;this.locked=!1;this.head_load_time=this.step_rate_interval=0;this.fdc_config=
|
|
431
|
+
96;this.eot=this.precomp_trk=0;this.drives=[new Rc("fda",d?.fda,b,4),new Rc("fdb",d?.fdb,c,4)];Object.seal(this);this.cpu.devices.rtc.cmos_write(16,this.drives[0].drive_type<<4|this.drives[1].drive_type);this.io.register_read(1008,this,this.read_reg_sra);this.io.register_read(1009,this,this.read_reg_srb);this.io.register_read(1010,this,this.read_reg_dor);this.io.register_read(1011,this,this.read_reg_tdr);this.io.register_read(1012,this,this.read_reg_msr);this.io.register_read(1013,this,this.read_reg_fifo);
|
|
432
|
+
this.io.register_read(1015,this,this.read_reg_dir);this.io.register_write(1010,this,this.write_reg_dor);this.io.register_write(1011,this,this.write_reg_tdr);this.io.register_write(1012,this,this.write_reg_dsr);this.io.register_write(1013,this,this.write_reg_fifo);this.io.register_write(1015,this,this.write_reg_ccr);B("floppy controller ready",8192)}W.prototype.build_cmd_lookup_table=function(){const a=[{code:6,mask:31,argc:8,name:"READ",handler:this.exec_read},{code:5,mask:63,argc:8,name:"WRITE",
|
|
433
|
+
handler:this.exec_write},{code:15,mask:255,argc:2,name:"SEEK",handler:this.exec_seek},{code:8,mask:255,argc:0,name:"SENSE INTERRUPT STATUS",handler:this.exec_sense_interrupt_status},{code:7,mask:255,argc:1,name:"RECALIBRATE",handler:this.exec_recalibrate},{code:13,mask:191,argc:5,name:"FORMAT TRACK",handler:this.exec_format_track},{code:2,mask:191,argc:8,name:"READ TRACK",handler:this.exec_unimplemented},{code:78,mask:255,argc:17,name:"RESTORE",handler:this.exec_unimplemented},{code:46,mask:255,argc:0,
|
|
434
|
+
name:"SAVE",handler:this.exec_unimplemented},{code:12,mask:31,argc:8,name:"READ DELETED DATA",handler:this.exec_unimplemented},{code:17,mask:31,argc:8,name:"SCAN EQUAL",handler:this.exec_unimplemented},{code:22,mask:31,argc:8,name:"VERIFY",handler:this.exec_unimplemented},{code:25,mask:31,argc:8,name:"SCAN LOW OR EQUAL",handler:this.exec_unimplemented},{code:29,mask:31,argc:8,name:"SCAN HIGH OR EQUAL",handler:this.exec_unimplemented},{code:9,mask:63,argc:8,name:"WRITE DELETED DATA",handler:this.exec_unimplemented},
|
|
435
|
+
{code:10,mask:191,argc:1,name:"READ ID",handler:this.exec_read_id},{code:3,mask:255,argc:2,name:"SPECIFY",handler:this.exec_specify},{code:4,mask:255,argc:1,name:"SENSE DRIVE STATUS",handler:this.exec_sense_drive_status},{code:18,mask:255,argc:1,name:"PERPENDICULAR MODE",handler:this.exec_perpendicular_mode},{code:19,mask:255,argc:3,name:"CONFIGURE",handler:this.exec_configure},{code:23,mask:255,argc:2,name:"POWERDOWN MODE",handler:this.exec_unimplemented},{code:51,mask:255,argc:1,name:"OPTION",handler:this.exec_unimplemented},
|
|
436
|
+
{code:142,mask:255,argc:5,name:"DRIVE SPECIFICATION",handler:this.exec_unimplemented},{code:143,mask:255,argc:2,name:"RELATIVE SEEK OUT",handler:this.exec_unimplemented},{code:205,mask:255,argc:10,name:"FORMAT AND WRITE",handler:this.exec_unimplemented},{code:207,mask:255,argc:2,name:"RELATIVE SEEK IN",handler:this.exec_unimplemented},{code:20,mask:127,argc:0,name:"LOCK",handler:this.exec_lock},{code:14,mask:255,argc:0,name:"DUMP REGISTERS",handler:this.exec_dump_regs},{code:16,mask:255,argc:0,name:"VERSION",
|
|
437
|
+
handler:this.exec_version},{code:24,mask:255,argc:0,name:"PART ID",handler:this.exec_part_id},{code:0,mask:0,argc:0,name:"UNKNOWN COMMAND",handler:this.exec_unimplemented}],b=Array(256);for(let c=a.length-1;0<=c;c--){const d=a[c];if(255===d.mask)b[d.code]=d;else for(let e=0;256>e;e++)(e&d.mask)===d.code&&(b[e]=d)}return b};W.prototype.raise_irq=function(a){this.sra&128||(this.cpu.device_raise_irq(6),this.sra|=128,B("IRQ raised, reason: "+a,8192));this.reset_sense_int_count=0};W.prototype.lower_irq=
|
|
438
|
+
function(a){this.status0=0;this.sra&128&&(this.cpu.device_lower_irq(6),this.sra&=-129,B("IRQ lowered, reason: "+a,8192))};W.prototype.set_curr_drive_no=function(a){this.curr_drive_no=a&1;return this.drives[this.curr_drive_no]};W.prototype.enter_command_phase=function(){this.cmd_phase=1;this.cmd_remaining=this.cmd_cursor=0;this.msr&=-81;this.msr|=128};W.prototype.enter_result_phase=function(a){this.cmd_phase=3;this.response_cursor=0;this.response_length=a;this.msr|=208};W.prototype.reset_fdc=function(){B("resetting controller",
|
|
439
|
+
8192);this.lower_irq("controller reset");this.sra=0;this.srb=192;this.dor=12;this.msr=128;this.curr_drive_no=0;this.status0|=192;this.response_length=this.response_cursor=0;this.drives[0].seek(0,0,1);this.drives[1].seek(0,0,1);this.enter_command_phase();this.raise_irq("controller reset");this.reset_sense_int_count=4};W.prototype.read_reg_sra=function(){B("SRA read: "+n(this.sra),8192);return this.sra};W.prototype.read_reg_srb=function(){B("SRB read: "+n(this.srb),8192);return this.srb};W.prototype.read_reg_dor=
|
|
440
|
+
function(){const a=this.dor&-4|this.curr_drive_no;B("DOR read: "+n(a),8192);return a};W.prototype.read_reg_tdr=function(){B("TDR read: "+n(this.tdr),8192);return this.tdr};W.prototype.read_reg_msr=function(){B("MSR read: "+n(this.msr),8192);this.dsr&=-65;this.dor|=4;return this.msr};W.prototype.read_reg_fifo=function(){this.dsr&=-65;if(!(this.msr&128&&this.msr&64))return B("FIFO read rejected: controller not ready for reading",8192),0;if(3!==this.cmd_phase)return B("FIFO read rejected: floppy controller not in RESULT phase, phase: "+
|
|
441
|
+
this.cmd_phase,8192),0;if(this.response_cursor<this.response_length){const a=this.response_data[this.response_cursor++];if(this.response_cursor===this.response_length){const b="end of "+this.cmd_table[this.cmd_code].name+" response";this.msr&=-129;this.enter_command_phase();this.lower_irq(b)}return a}B("FIFO read: empty",8192);return 0};W.prototype.read_reg_dir=function(){const a=this.drives[this.curr_drive_no].media_changed?128:0;B("DIR read: "+n(a),8192);return a};W.prototype.write_reg_dor=function(a){this.srb=
|
|
442
|
+
this.srb&-36|(a&16?1:0)|(a&32?2:0)|(a&1?32:0);this.dor&4?a&4||B("enter RESET state",8192):a&4&&(this.reset_fdc(),this.dsr&=-65,B("exit RESET state",8192));const b=a&3;B("DOR write: "+n(a)+", motors: "+n(a>>4)+", dma: "+!!(a&8)+", reset: "+!(a&4)+", drive: "+b,8192);1<b&&B("*** WARNING: floppy drive number "+b+" not implemented!",8192);this.curr_drive_no=b&1;this.dor=a};W.prototype.write_reg_tdr=function(a){this.dor&4?(B("TDR write: "+n(a),8192),this.tdr=a&4):B("TDR write "+n(a)+" rejected: Floppy controller in RESET mode!",
|
|
443
|
+
8192)};W.prototype.write_reg_dsr=function(a){this.dor&4?(B("DSR write: "+n(a),8192),a&128&&(this.dor&=-5,this.reset_fdc(),this.dor|=4),a&64&&this.reset_fdc(),this.dsr=a):B("DSR write: "+n(a)+" rejected: Floppy controller in RESET mode!",8192)};W.prototype.write_reg_fifo=function(a){this.dsr&=-65;if(this.dor&4)if(!(this.msr&128)||this.msr&64)B("FIFO write "+n(a)+" rejected: controller not ready for writing",8192);else if(1!==this.cmd_phase)B("FIFO write "+n(a)+" rejected: floppy controller not in COMMAND phase, phase: "+
|
|
444
|
+
this.cmd_phase,8192);else{if(0===this.cmd_remaining){var b=this.cmd_table[a];this.cmd_code=a;this.cmd_remaining=b.argc;this.cmd_flags=this.cmd_cursor=0;(6===b.code||5===b.code)&&this.cmd_code&128&&(this.cmd_flags|=1);this.cmd_remaining&&(this.msr|=128);this.msr|=16}else this.cmd_buffer[this.cmd_cursor++]=a,this.cmd_remaining--;if(0===this.cmd_remaining){this.cmd_phase=2;a=this.cmd_table[this.cmd_code];b=this.cmd_buffer.slice(0,this.cmd_cursor);const c=[];for(const d of b)c.push(n(d,2));B("FD command "+
|
|
445
|
+
n(this.cmd_code)+": "+a.name+"("+c.join(", ")+")",8192);a.handler.call(this,b)}}else B("FIFO write "+n(a)+" rejected: floppy controller in RESET mode!",8192)};W.prototype.write_reg_ccr=function(a){this.dor&4?(B("CCR write: "+n(a),8192),this.dsr=this.dsr&-4|a&3):B("CCR write: "+n(a)+" rejected: Floppy controller in RESET mode!",8192)};W.prototype.exec_unimplemented=function(){l(!1,"Unimplemented floppy command code "+n(this.cmd_code)+"!");this.status0=128;this.response_data[0]=this.status0;this.enter_result_phase(1)};
|
|
446
|
+
W.prototype.exec_read=function(a){this.start_read_write(a,!1)};W.prototype.exec_write=function(a){this.start_read_write(a,!0)};W.prototype.exec_seek=function(a){const b=this.set_curr_drive_no(a[0]&1);a=a[1];this.enter_command_phase();b.seek(b.curr_head,a,b.curr_sect);this.status0|=32;this.raise_irq("SEEK command")};W.prototype.exec_sense_interrupt_status=function(){const a=this.drives[this.curr_drive_no];let b;if(0<this.reset_sense_int_count)b=192|4-this.reset_sense_int_count--;else if(this.sra&128)b=
|
|
447
|
+
this.status0&-8|this.curr_drive_no;else{B("No interrupt pending, aborting SENSE INTERRUPT command!",8192);this.response_data[0]=128;this.enter_result_phase(1);return}this.response_data[0]=b;this.response_data[1]=a.curr_track;this.enter_result_phase(2);this.lower_irq("SENSE INTERRUPT command");this.status0=192};W.prototype.exec_recalibrate=function(a){this.set_curr_drive_no(a[0]&1).seek(0,0,1);this.enter_command_phase();this.status0|=32;this.raise_irq("RECALIBRATE command")};W.prototype.exec_format_track=
|
|
448
|
+
function(a){let b=0,c=0;this.set_curr_drive_no(a[0]&1).read_only&&(b=96,c=2);this.end_read_write(b,c,0)};W.prototype.exec_read_id=function(a){const b=this.drives[this.curr_drive_no];b.curr_head=a[0]>>2&1;0!==b.max_sect&&(b.curr_sect=b.curr_sect%b.max_sect+1);this.end_read_write(0,0,0)};W.prototype.exec_specify=function(a){const b=a[1];this.step_rate_interval=a[0]>>4;this.head_load_time=b>>1;this.dor=b&1?this.dor&-9:this.dor|8;this.enter_command_phase()};W.prototype.exec_sense_drive_status=function(a){a=
|
|
449
|
+
a[0];const b=this.set_curr_drive_no(a&1);b.curr_head=a>>2&1;this.response_data[0]=(b.read_only?64:0)|(0===b.curr_track?16:0)|b.curr_head<<2|this.curr_drive_no|40;this.enter_result_phase(1)};W.prototype.exec_perpendicular_mode=function(a){a=a[0];a&128&&(this.drives[this.curr_drive_no].perpendicular=a&7);this.enter_command_phase()};W.prototype.exec_configure=function(a){this.fdc_config=a[1];this.precomp_trk=a[2];this.enter_command_phase()};W.prototype.exec_lock=function(){this.cmd_code&128?(this.locked=
|
|
450
|
+
!0,this.response_data[0]=16):(this.locked=!1,this.response_data[0]=0);this.enter_result_phase(1)};W.prototype.exec_dump_regs=function(){const a=this.drives[this.curr_drive_no];this.response_data[0]=this.drives[0].curr_track;this.response_data[1]=this.drives[1].curr_track;this.response_data[2]=0;this.response_data[3]=0;this.response_data[4]=this.step_rate_interval;this.response_data[5]=this.head_load_time<<1|(this.dor&8?1:0);this.response_data[6]=a.max_sect;this.response_data[7]=(this.locked?128:0)|
|
|
451
|
+
a.perpendicular<<2;this.response_data[8]=this.fdc_config;this.response_data[9]=this.precomp_trk;this.enter_result_phase(10)};W.prototype.exec_version=function(){this.response_data[0]=144;this.enter_result_phase(1)};W.prototype.exec_part_id=function(){this.response_data[0]=65;this.enter_result_phase(1)};W.prototype.start_read_write=function(a,b){const c=this.set_curr_drive_no(a[0]&1),d=a[1],e=a[2],f=a[3];var g=a[4];const k=a[5];a=128>a[7]?a[7]:128;switch(c.seek(e,d,f)){case 2:this.end_read_write(64,
|
|
452
|
+
0,0);this.response_data[3]=d;this.response_data[4]=e;this.response_data[5]=f;return;case 3:this.end_read_write(64,128,0);this.response_data[3]=d;this.response_data[4]=e;this.response_data[5]=f;return;case 1:this.status0|=32}const m=128<<(7<g?7:g);g=c.chs2lba(d,e,f)*m;if(128===m)b&&128>a&&l(!1,"dtl="+a+" is less than 128, zero-padding is still unimplemented!");else if(a=this.cmd_flags&1?(2*k-f+1)*m:(k-f+1)*m,0>=a){B("invalid data_length: "+a+" sect="+f+" eot="+k,8192);this.end_read_write(64,1,0);this.response_data[3]=
|
|
453
|
+
d;this.response_data[4]=e;this.response_data[5]=f;return}this.eot=k;B("Floppy "+this.cmd_table[this.cmd_code].name+" from: "+n(g)+", length: "+n(a)+", C/H/S: "+d+"/"+e+"/"+f+", ro: "+c.read_only+", #S: "+c.max_sect+", #H: "+c.max_head,8192);b&&c.read_only?(this.end_read_write(96,2,0),this.response_data[3]=d,this.response_data[4]=e,this.response_data[5]=f):this.dor&8?(this.msr&=-129,(b?this.dma.do_write:this.dma.do_read).call(this.dma,c.buffer,g,a,2,p=>{p?(B("DMA floppy error",8192),this.end_read_write(64,
|
|
454
|
+
0,0)):(this.seek_next_sect(),this.end_read_write(0,0,0))})):l(!1,this.cmd_table[this.cmd_code].name+" in PIO mode not supported!")};W.prototype.end_read_write=function(a,b,c){const d=this.drives[this.curr_drive_no];this.status0&=-8;this.status0|=this.curr_drive_no;d.curr_head&&(this.status0|=4);this.status0|=a;this.msr|=192;this.msr&=-33;this.response_data[0]=this.status0;this.response_data[1]=b;this.response_data[2]=c;this.response_data[3]=d.curr_track;this.response_data[4]=d.curr_head;this.response_data[5]=
|
|
455
|
+
d.curr_sect;this.response_data[6]=2;this.enter_result_phase(7);this.raise_irq(this.cmd_table[this.cmd_code].name+" command")};W.prototype.seek_next_sect=function(){const a=this.drives[this.curr_drive_no];let b=a.curr_track,c=a.curr_head,d=a.curr_sect,e=1;d>=a.max_sect||d===this.eot?(d=1,this.cmd_flags&1?0===c&&2===a.max_head?c=1:(c=0,b++,this.status0|=32,1===a.max_head&&(e=0)):(this.status0|=32,b++,e=0)):d++;a.seek(c,b,d);return e};W.prototype.get_state=function(){const a=[];a[19]=this.sra;a[20]=
|
|
456
|
+
this.srb;a[21]=this.dor;a[22]=this.tdr;a[23]=this.msr;a[24]=this.dsr;a[25]=this.cmd_phase;a[26]=this.cmd_code;a[27]=this.cmd_flags;a[28]=this.cmd_buffer;a[29]=this.cmd_cursor;a[30]=this.cmd_remaining;a[31]=this.response_data;a[32]=this.response_cursor;a[33]=this.response_length;a[34]=this.status0;a[35]=this.status1;a[36]=this.curr_drive_no;a[37]=this.reset_sense_int_count;a[38]=this.locked;a[39]=this.step_rate_interval;a[40]=this.head_load_time;a[41]=this.fdc_config;a[42]=this.precomp_trk;a[43]=this.eot;
|
|
457
|
+
a[44]=this.drives[0].get_state();a[45]=this.drives[1].get_state();return a};W.prototype.set_state=function(a){"undefined"!==typeof a[19]&&(this.sra=a[19],this.srb=a[20],this.dor=a[21],this.tdr=a[22],this.msr=a[23],this.dsr=a[24],this.cmd_phase=a[25],this.cmd_code=a[26],this.cmd_flags=a[27],this.cmd_buffer.set(a[28]),this.cmd_cursor=a[29],this.cmd_remaining=a[30],this.response_data.set(a[31]),this.response_cursor=a[32],this.response_length=a[33],this.status0=a[34],this.status1=a[35],this.curr_drive_no=
|
|
458
|
+
a[36],this.reset_sense_int_count=a[37],this.locked=a[38],this.step_rate_interval=a[39],this.head_load_time=a[40],this.fdc_config=a[41],this.precomp_trk=a[42],this.eot=a[43],this.drives[0].set_state(a[44]),this.drives[1].set_state(a[45]))};const Sc=[{drive_type:4,sectors:18,tracks:80,heads:2},{drive_type:4,sectors:20,tracks:80,heads:2},{drive_type:4,sectors:21,tracks:80,heads:2},{drive_type:4,sectors:21,tracks:82,heads:2},{drive_type:4,sectors:21,tracks:83,heads:2},{drive_type:4,sectors:22,tracks:80,
|
|
459
|
+
heads:2},{drive_type:4,sectors:23,tracks:80,heads:2},{drive_type:4,sectors:24,tracks:80,heads:2},{drive_type:5,sectors:36,tracks:80,heads:2},{drive_type:5,sectors:39,tracks:80,heads:2},{drive_type:5,sectors:40,tracks:80,heads:2},{drive_type:5,sectors:44,tracks:80,heads:2},{drive_type:5,sectors:48,tracks:80,heads:2},{drive_type:4,sectors:8,tracks:80,heads:2},{drive_type:4,sectors:9,tracks:80,heads:2},{drive_type:4,sectors:10,tracks:80,heads:2},{drive_type:4,sectors:10,tracks:82,heads:2},{drive_type:4,
|
|
460
|
+
sectors:10,tracks:83,heads:2},{drive_type:4,sectors:13,tracks:80,heads:2},{drive_type:4,sectors:14,tracks:80,heads:2},{drive_type:2,sectors:15,tracks:80,heads:2},{drive_type:2,sectors:18,tracks:80,heads:2},{drive_type:2,sectors:18,tracks:82,heads:2},{drive_type:2,sectors:18,tracks:83,heads:2},{drive_type:2,sectors:20,tracks:80,heads:2},{drive_type:2,sectors:9,tracks:80,heads:2},{drive_type:2,sectors:11,tracks:80,heads:2},{drive_type:2,sectors:9,tracks:40,heads:2},{drive_type:2,sectors:9,tracks:40,
|
|
461
|
+
heads:1},{drive_type:2,sectors:10,tracks:41,heads:2},{drive_type:2,sectors:10,tracks:42,heads:2},{drive_type:2,sectors:8,tracks:40,heads:2},{drive_type:2,sectors:8,tracks:40,heads:1},{drive_type:4,sectors:9,tracks:80,heads:1},{drive_type:1,sectors:10,tracks:40,heads:1},{drive_type:1,sectors:10,tracks:40,heads:2}];function Rc(a,b,c,d){this.name=a;this.curr_head=this.curr_track=this.max_sect=this.max_head=this.max_track=this.drive_type=0;this.curr_sect=1;this.perpendicular=0;this.read_only=!1;this.media_changed=
|
|
462
|
+
!0;this.buffer=null;Object.seal(this);a=b?.drive_type;void 0!==a&&0<=a&&5>=a&&(this.drive_type=a);this.insert_disk(c,!!b?.read_only);0===this.drive_type&&void 0===a&&(this.drive_type=d);B("floppy drive "+this.name+" ready, drive type: "+this.drive_type,8192)}Rc.prototype.insert_disk=function(a,b){if(!a)return!1;a instanceof Uint8Array&&(a=new Ba(a.buffer));const [c,d]=this.find_disk_format(a,this.drive_type);if(!c)return B("WARNING: disk rejected, no suitable disk format found for image of size "+
|
|
463
|
+
a.byteLength+" bytes",8192),!1;this.max_track=d.tracks;this.max_head=d.heads;this.max_sect=d.sectors;this.read_only=!!b;this.media_changed=!0;this.buffer=c;0===this.drive_type&&(this.drive_type=d.drive_type);B("disk inserted into "+this.name+": type: "+d.drive_type+", C/H/S: "+d.tracks+"/"+d.heads+"/"+d.sectors+", size: "+c.byteLength,8192);return!0};Rc.prototype.eject_disk=function(){this.max_sect=this.max_head=this.max_track=0;this.media_changed=!0;this.buffer=null};Rc.prototype.get_buffer=function(){return this.buffer?
|
|
464
|
+
this.buffer.buffer:null};Rc.prototype.chs2lba=function(a,b,c){return(a*this.max_head+b)*this.max_sect+c-1};Rc.prototype.find_disk_format=function(a,b){const c=0===b,d=a.byteLength;let e=-1,f=-1,g=-1,k=-1,m=-1;for(let p=0;p<Sc.length;p++){const q=Sc[p],r=q.sectors*q.tracks*q.heads*512;if(d===r)if(c||q.drive_type===b){e=p;break}else c||Qc[q.drive_type]!==Qc[b]?g=-1===g?p:g:f=-1===f?p:f;else d<r&&(-1===m||r<m)&&(k=p,m=r)}return-1!==e?[a,Sc[e]]:-1!==f?[a,Sc[f]]:-1!==g?[a,Sc[g]]:-1!==k?(b=new Uint8Array(m),
|
|
465
|
+
b.set(new Uint8Array(a.buffer)),[new Ba(b.buffer),Sc[k]]):[null,null]};Rc.prototype.seek=function(a,b,c){if(b>this.max_track||0!==a&&1===this.max_head)return B("WARNING: attempt to seek to invalid track: head: "+a+", track: "+b+", sect: "+c,8192),2;if(c>this.max_sect)return B("WARNING: attempt to seek beyond last sector: "+c+" (max: "+this.max_sect+")",8192),3;let d=0;const e=this.chs2lba(this.curr_track,this.curr_head,this.curr_sect),f=this.chs2lba(b,a,c);e!==f&&(this.curr_track!==b&&(this.buffer&&
|
|
466
|
+
(this.media_changed=!1),d=1),this.curr_head=a,this.curr_track=b,this.curr_sect=c);this.buffer||(d=2);return d};Rc.prototype.get_state=function(){const a=[];a[0]=this.drive_type;a[1]=this.max_track;a[2]=this.max_head;a[3]=this.max_sect;a[4]=this.curr_track;a[5]=this.curr_head;a[6]=this.curr_sect;a[7]=this.perpendicular;a[8]=this.read_only;a[9]=this.media_changed;a[10]=this.buffer?this.buffer.get_state():null;return a};Rc.prototype.set_state=function(a){this.drive_type=a[0];this.max_track=a[1];this.max_head=
|
|
467
|
+
a[2];this.max_sect=a[3];this.curr_track=a[4];this.curr_head=a[5];this.curr_sect=a[6];this.perpendicular=a[7];this.read_only=a[8];this.media_changed=a[9];a[10]?(this.buffer||(this.buffer=new Ba(new ArrayBuffer(0))),this.buffer.set_state(a[10])):this.buffer=null};const Tc={[8]:"DEVICE RESET",[144]:"EXECUTE DEVICE DIAGNOSTIC",[231]:"FLUSH CACHE",[234]:"FLUSH CACHE EXT",[218]:"GET MEDIA STATUS",[236]:"IDENTIFY DEVICE",[161]:"IDENTIFY PACKET DEVICE",[225]:"IDLE IMMEDIATE",[145]:"INITIALIZE DEVICE PARAMETERS",
|
|
468
|
+
[222]:"MEDIA LOCK",[0]:"NOP",[160]:"PACKET",[200]:"READ DMA",[37]:"READ DMA EXT",[41]:"READ MULTIPLE",[196]:"READ MULTIPLE EXT",[248]:"READ NATIVE MAX ADDRESS",[39]:"READ NATIVE MAX ADDRESS EXT",[32]:"READ SECTORS",[36]:"READ SECTORS EXT",[64]:"READ VERIFY SECTORS",[245]:"SECURITY FREEZE LOCK",[239]:"SET FEATURES",[249]:"SET MAX",[198]:"SET MULTIPLE MODE",[224]:"STANDBY IMMEDIATE",[202]:"WRITE DMA",[53]:"WRITE DMA EXT",[57]:"WRITE MULTIPLE",[197]:"WRITE MULTIPLE EXT",[48]:"WRITE SECTORS",[52]:"WRITE SECTORS EXT",
|
|
469
|
+
[16]:"<UNKNOWN 10h>",[240]:"<VENDOR-SPECIFIC F0h>"},Uc={[70]:{name:"GET CONFIGURATION",flags:0},[74]:{name:"GET EVENT STATUS NOTIFICATION",flags:0},[18]:{name:"INQUIRY",flags:0},[189]:{name:"MECHANISM STATUS",flags:0},[26]:{name:"MODE SENSE (6)",flags:0},[90]:{name:"MODE SENSE (10)",flags:0},[69]:{name:"PAUSE",flags:1},[30]:{name:"PREVENT ALLOW MEDIUM REMOVAL",flags:0},[40]:{name:"READ (10)",flags:1},[168]:{name:"READ (12)",flags:1},[37]:{name:"READ CAPACITY",flags:1},[190]:{name:"READ CD",flags:1},
|
|
470
|
+
[81]:{name:"READ DISK INFORMATION",flags:1},[66]:{name:"READ SUBCHANNEL",flags:1},[67]:{name:"READ TOC PMA ATIP",flags:1},[82]:{name:"READ TRACK INFORMATION",flags:1},[3]:{name:"REQUEST SENSE",flags:0},[27]:{name:"START STOP UNIT",flags:0},[0]:{name:"TEST UNIT READY",flags:1}};function Vc(a,b,c){this.cpu=a;this.bus=b;this.secondary=this.primary=void 0;b=c&&c[0][0];const d=c&&c[1][0];if(b||d){b&&(this.primary=new Wc(this,0,c[0],496,1014,14));d&&(this.secondary=new Wc(this,1,c[1],368,886,15));c=b?this.primary.command_base:
|
|
471
|
+
0;const e=b?this.primary.control_base:0,f=d?this.secondary.command_base:0,g=d?this.secondary.control_base:0;this.name="ide";this.pci_id=240;this.pci_space=[134,128,16,112,5,0,160,2,0,128,1,1,0,0,0,0,c&255|1,c>>8,0,0,e&255|1,e>>8,0,0,f&255|1,f>>8,0,0,g&255|1,g>>8,0,0,1,180,0,0,0,0,0,0,0,0,0,0,67,16,212,130,0,0,0,0,0,0,0,0,0,0,0,0,0,1,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,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,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,
|
|
472
|
+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.pci_bars=[b?{size:8}:void 0,b?{size:1}:void 0,d?{size:8}:void 0,d?{size:1}:void 0,{size:16}];a.devices.pci.register_device(this)}Object.seal(this)}Vc.prototype.get_state=function(){const a=[];a[0]=this.primary;a[1]=this.secondary;return a};Vc.prototype.set_state=function(a){this.primary&&this.primary.set_state(a[0]);this.secondary&&this.secondary.set_state(a[1])};function Wc(a,b,c,d,e,f){this.controller=a;this.channel_nr=b;this.cpu=a.cpu;this.bus=a.bus;this.command_base=
|
|
473
|
+
d;this.control_base=e;this.irq=f;this.name="ide"+b;d=c?c[0]:void 0;c=c?c[1]:void 0;this.master=new X(this,0,d?.buffer,d?.is_cdrom);this.slave=new X(this,1,c?.buffer,c?.is_cdrom);this.current_interface=this.master;this.device_control_reg=2;this.dma_command=this.dma_status=this.prdt_addr=0;a=a.cpu;a.io.register_read(this.command_base|0,this,function(){return this.current_interface.read_data(1)},function(){return this.current_interface.read_data(2)},function(){return this.current_interface.read_data(4)});
|
|
474
|
+
a.io.register_read(this.command_base|1,this,function(){return this.current_interface.error_reg&255});a.io.register_read(this.command_base|2,this,function(){return this.current_interface.sector_count_reg&255});a.io.register_read(this.command_base|3,this,function(){return this.current_interface.lba_low_reg&255});a.io.register_read(this.command_base|4,this,function(){return this.current_interface.lba_mid_reg&255});a.io.register_read(this.command_base|5,this,function(){return this.current_interface.lba_high_reg&
|
|
475
|
+
255});a.io.register_read(this.command_base|6,this,function(){return this.current_interface.device_reg&255});a.io.register_read(this.command_base|7,this,function(){const g=this.read_status();this.cpu.device_lower_irq(this.irq);return g});a.io.register_write(this.command_base|0,this,function(g){this.current_interface.write_data_port8(g)},function(g){this.current_interface.write_data_port16(g)},function(g){this.current_interface.write_data_port32(g)});a.io.register_write(this.command_base|1,this,function(g){this.current_interface.features_reg=
|
|
476
|
+
(this.current_interface.features_reg<<8|g)&65535});a.io.register_write(this.command_base|2,this,function(g){this.current_interface.sector_count_reg=(this.current_interface.sector_count_reg<<8|g)&65535});a.io.register_write(this.command_base|3,this,function(g){this.current_interface.lba_low_reg=(this.current_interface.lba_low_reg<<8|g)&65535});a.io.register_write(this.command_base|4,this,function(g){this.current_interface.lba_mid_reg=(this.current_interface.lba_mid_reg<<8|g)&65535});a.io.register_write(this.command_base|
|
|
477
|
+
5,this,function(g){this.current_interface.lba_high_reg=(this.current_interface.lba_high_reg<<8|g)&65535});a.io.register_write(this.command_base|6,this,function(g){const k=g&16;if(k&&this.current_interface===this.master||!k&&this.current_interface===this.slave)k?(B(`${this.current_interface.name}: select slave device (${this.channel_nr?"secondary":"primary"})`,32768),this.current_interface=this.slave):(B(`${this.current_interface.name}: select master device (${this.channel_nr?"secondary":"primary"})`,
|
|
478
|
+
32768),this.current_interface=this.master);this.current_interface.device_reg=g;this.current_interface.is_lba=g>>6&1;this.current_interface.head=g&15});a.io.register_write(this.command_base|7,this,function(g){this.current_interface.status_reg&=-34;this.current_interface.ata_command(g);this.cpu.device_lower_irq(this.irq)});a.io.register_read(this.control_base|0,this,this.read_status);a.io.register_write(this.control_base|0,this,this.write_control);b=46080+8*b;a.io.register_read(b|0,this,this.dma_read_command8,
|
|
479
|
+
void 0,this.dma_read_command);a.io.register_write(b|0,this,this.dma_write_command8,void 0,this.dma_write_command);a.io.register_read(b|2,this,this.dma_read_status);a.io.register_write(b|2,this,this.dma_write_status);a.io.register_read(b|4,this,void 0,void 0,this.dma_read_addr);a.io.register_write(b|4,this,void 0,void 0,this.dma_set_addr);Object.seal(this)}Wc.prototype.read_status=function(){return this.current_interface.drive_connected?this.current_interface.status_reg:0};Wc.prototype.write_control=
|
|
480
|
+
function(a){a&4&&(B(`${this.current_interface.name}: soft reset via control port (lower IRQ ${this.irq})`,32768),this.cpu.device_lower_irq(this.irq),this.master.device_reset(),this.slave.device_reset());this.device_control_reg=a};Wc.prototype.dma_read_addr=function(){return this.prdt_addr};Wc.prototype.dma_set_addr=function(a){this.prdt_addr=a};Wc.prototype.dma_read_status=function(){return this.dma_status};Wc.prototype.dma_write_status=function(a){this.dma_status&=~(a&6)};Wc.prototype.dma_read_command=
|
|
481
|
+
function(){return this.dma_read_command8()|this.dma_read_status()<<16};Wc.prototype.dma_read_command8=function(){return this.dma_command};Wc.prototype.dma_write_command=function(a){this.dma_write_command8(a&255);this.dma_write_status(a>>16&255)};Wc.prototype.dma_write_command8=function(a){const b=this.dma_command;this.dma_command=a&9;if((b&1)!==(a&1))if(0===(a&1))this.dma_status&=-2;else switch(this.dma_status|=1,this.current_interface.current_command){case 200:case 37:this.current_interface.do_ata_read_sectors_dma();
|
|
482
|
+
break;case 202:case 53:this.current_interface.do_ata_write_sectors_dma();break;case 160:this.current_interface.do_atapi_dma();break;default:B(this.current_interface.name+": spurious DMA command write, current command: "+n(this.current_interface.current_command),32768),B(this.current_interface.name+": DMA clear status bit 1h, set status bit 2h",32768),this.dma_status&=-2,this.dma_status|=2,this.push_irq()}};Wc.prototype.push_irq=function(){0===(this.device_control_reg&2)&&(this.dma_status|=4,this.cpu.device_raise_irq(this.irq))};
|
|
483
|
+
Wc.prototype.get_state=function(){var a=[];a[0]=this.master;a[1]=this.slave;a[2]=this.command_base;a[3]=this.irq;a[5]=this.control_base;a[7]=this.name;a[8]=this.device_control_reg;a[9]=this.prdt_addr;a[10]=this.dma_status;a[11]=this.current_interface===this.master;a[12]=this.dma_command;return a};Wc.prototype.set_state=function(a){this.master.set_state(a[0]);this.slave.set_state(a[1]);this.command_base=a[2];this.irq=a[3];this.control_base=a[5];this.name=a[7];this.device_control_reg=a[8];this.prdt_addr=
|
|
484
|
+
a[9];this.dma_status=a[10];this.current_interface=a[11]?this.master:this.slave;this.dma_command=a[12]};function X(a,b,c,d){this.channel=a;this.name=a.name+"."+b;this.bus=a.bus;this.channel_nr=a.channel_nr;this.interface_nr=b;this.cpu=a.cpu;this.buffer=null;this.drive_connected=d||!!c;this.sector_size=d?2048:512;this.is_atapi=d;this.sector_count=0;this.head_count=this.is_atapi?1:0;this.device_reg=this.head=this.lba_high_reg=this.lba_mid_reg=this.features_reg=this.lba_low_reg=this.sector_count_reg=
|
|
485
|
+
this.is_lba=this.cylinder_count=this.sectors_per_track=0;this.status_reg=80;this.sectors_per_drq=128;this.data_pointer=this.error_reg=0;this.data=new Uint8Array(65536);this.data16=new Uint16Array(this.data.buffer);this.data32=new Int32Array(this.data.buffer);this.data_end=this.data_length=0;this.current_command=-1;this.last_io_id=this.write_dest=0;this.in_progress_io_ids=new Set;this.cancelled_io_ids=new Set;this.current_atapi_command=-1;this.atapi_add_sense=this.atapi_sense_key=0;this.medium_changed=
|
|
486
|
+
!1;this.set_disk_buffer(c);this.drive_connected&&B(`${this.name}: ${this.is_atapi?"ATAPI CD-ROM":"ATA HD"} device ready`,32768);Object.seal(this)}X.prototype.has_disk=function(){return!!this.buffer};X.prototype.eject=function(){this.is_atapi&&this.buffer&&(this.medium_changed=!0,this.buffer=null,this.status_reg=89,this.error_reg=96,this.push_irq())};X.prototype.set_cdrom=function(a){this.is_atapi&&a&&(this.set_disk_buffer(a),this.medium_changed=!0)};X.prototype.set_disk_buffer=function(a){if(a){this.buffer=
|
|
487
|
+
a;this.is_atapi&&(this.status_reg=89,this.error_reg=96);this.sector_count=this.buffer.byteLength/this.sector_size;this.sector_count!==(this.sector_count|0)&&(B(this.name+": warning: disk size not aligned with sector size",32768),this.sector_count=Math.ceil(this.sector_count));this.is_atapi?(this.head_count=1,this.sectors_per_track=2048):(this.head_count=16,this.sectors_per_track=63);this.cylinder_count=this.sector_count/this.head_count/this.sectors_per_track;this.cylinder_count!==(this.cylinder_count|
|
|
488
|
+
0)&&(B(this.name+": warning: rounding up cylinder count, choose different head number",32768),this.cylinder_count=Math.floor(this.cylinder_count));if(0===this.interface_nr){a=this.cpu.devices.rtc;a.cmos_write(57,a.cmos_read(57)|1<<4*this.channel_nr);a.cmos_write(18,a.cmos_read(18)&15|240);const b=0===this.channel_nr?27:36;a.cmos_write(b+0,this.cylinder_count&255);a.cmos_write(b+1,this.cylinder_count>>8&255);a.cmos_write(b+2,this.head_count&255);a.cmos_write(b+3,255);a.cmos_write(b+4,255);a.cmos_write(b+
|
|
489
|
+
5,200);a.cmos_write(b+6,this.cylinder_count&255);a.cmos_write(b+7,this.cylinder_count>>8&255);a.cmos_write(b+8,this.sectors_per_track&255)}this.channel.cpu&&this.push_irq()}};X.prototype.device_reset=function(){this.is_atapi?(this.status_reg=0,this.lba_low_reg=this.error_reg=this.sector_count_reg=1,this.lba_mid_reg=20,this.lba_high_reg=235):(this.status_reg=81,this.lba_low_reg=this.error_reg=this.sector_count_reg=1,this.lba_high_reg=this.lba_mid_reg=0);this.cancel_io_operations()};X.prototype.push_irq=
|
|
490
|
+
function(){this.channel.push_irq()};X.prototype.ata_abort_command=function(){this.error_reg=4;this.status_reg=65;this.push_irq()};X.prototype.capture_regs=function(){return`ST=${n(this.status_reg&255)} ER=${n(this.error_reg&255)} `+`SC=${n(this.sector_count_reg&255)} LL=${n(this.lba_low_reg&255)} `+`LM=${n(this.lba_mid_reg&255)} LH=${n(this.lba_high_reg&255)} `+`FE=${n(this.features_reg&255)}`};X.prototype.ata_command=function(a){if(this.drive_connected||144===a){var b=this.capture_regs(),c=!0;this.current_command=
|
|
491
|
+
a;this.error_reg=0;switch(a){case 8:this.data_length=this.data_end=this.data_pointer=0;this.device_reset();this.push_irq();break;case 16:this.lba_mid_reg=0;this.status_reg=80;this.push_irq();break;case 248:var d=this.sector_count-1;this.lba_low_reg=d&255;this.lba_mid_reg=d>>8&255;this.lba_high_reg=d>>16&255;this.device_reg=this.device_reg&240|d>>24&15;this.status_reg=80;this.push_irq();break;case 39:d=this.sector_count-1;this.lba_low_reg=d&255;this.lba_mid_reg=d>>8&255;this.lba_high_reg=d>>16&255;
|
|
492
|
+
this.lba_low_reg|=d>>24<<8&65280;this.status_reg=80;this.push_irq();break;case 32:c=!1;this.is_atapi?(this.lba_mid_reg=20,this.lba_high_reg=235,this.ata_abort_command()):this.ata_read_sectors(a);break;case 36:case 41:case 196:c=!1;this.is_atapi?this.ata_abort_command():this.ata_read_sectors(a);break;case 48:case 52:case 57:case 197:c=!1;this.is_atapi?this.ata_abort_command():this.ata_write_sectors(a);break;case 144:this.channel.master.status_reg=80;this.channel.master.error_reg=1;this.channel.master.push_irq();
|
|
493
|
+
this.channel.slave.drive_connected&&(this.channel.slave.status_reg=80,this.channel.slave.error_reg=1,this.channel.slave.push_irq());break;case 145:this.status_reg=80;this.push_irq();break;case 160:this.is_atapi?(c=!1,this.data_allocate(12),this.data_end=12,this.sector_count_reg=1,this.status_reg=88,this.push_irq()):this.ata_abort_command();break;case 161:this.is_atapi?(this.create_identify_packet(),this.status_reg=88,this.push_irq()):this.ata_abort_command();break;case 198:B(this.name+": logical sectors per DRQ Block: "+
|
|
494
|
+
n(this.sector_count_reg&255),32768);this.sectors_per_drq=this.sector_count_reg&255;this.status_reg=80;this.push_irq();break;case 200:case 37:c=!1;this.ata_read_sectors_dma(a);break;case 202:case 53:c=!1;this.ata_write_sectors_dma(a);break;case 64:this.status_reg=80;this.push_irq();break;case 218:this.is_atapi&&(this.buffer||(this.error_reg|=2),this.medium_changed&&(this.error_reg|=32,this.medium_changed=!1),this.error_reg|=64);this.status_reg=80;this.push_irq();break;case 224:this.status_reg=80;this.push_irq();
|
|
495
|
+
break;case 225:this.status_reg=80;this.push_irq();break;case 231:this.status_reg=80;this.push_irq();break;case 234:this.status_reg=80;this.push_irq();break;case 236:this.is_atapi?(this.lba_mid_reg=20,this.lba_high_reg=235,this.ata_abort_command()):(this.create_identify_packet(),this.status_reg=88,this.push_irq());break;case 239:this.status_reg=80;this.push_irq();break;case 222:this.status_reg=64;this.push_irq();break;case 245:this.status_reg=80;this.push_irq();break;case 249:this.ata_abort_command();
|
|
496
|
+
break;case 0:this.ata_abort_command();break;case 240:B(`${this.name}: error: unimplemented vendor-specific ATA command ${n(a)}: ABORT [${this.capture_regs()}]`,32768);this.ata_abort_command();break;default:l(!1,`${this.name}: error: unimplemented ATA command ${n(a)}: ABORT [${this.capture_regs()}]`,32768),this.ata_abort_command()}c&&(b=`[${b}] -> [${this.capture_regs()}]`,c=this.status_reg&1?this.error_reg&4?"ABORT":"ERROR":"OK",B(`${this.name}: ATA command ${Tc[a]} (${n(a)}): ${c} ${b}`,32768))}else B(`${this.name}: ATA command ${Tc[a]} (${n(a)}) ignored: no slave drive connected`,
|
|
497
|
+
32768)};X.prototype.atapi_handle=function(){const a=this.data[0],b=Uc[a]?Uc[a].name:"<undefined>";var c=Uc[a]?Uc[a].flags:0,d=this.capture_regs(),e=!0;let f;this.data_pointer=0;this.current_atapi_command=a;3!==a&&(this.atapi_add_sense=this.atapi_sense_key=0);if(!this.buffer&&c&1)this.atapi_check_condition_response(2,58),this.push_irq(),B(`${this.name}: ATAPI command ${b} (${n(a)}) without medium: ERROR [${d}]`,32768);else{switch(a){case 0:this.buffer?(this.data_allocate(0),this.data_end=this.data_length,
|
|
498
|
+
this.status_reg=80):this.atapi_check_condition_response(2,58);break;case 3:this.data_allocate(this.data[4]);this.data_end=this.data_length;this.status_reg=88;this.data[0]=240;this.data[2]=this.atapi_sense_key;this.data[7]=8;this.data[12]=this.atapi_add_sense;this.atapi_add_sense=this.atapi_sense_key=0;break;case 18:c=this.data[4];this.status_reg=88;f="lun="+n(this.data[1],2)+" length="+c;this.data.set([5,128,1,49,31,0,0,0,83,79,78,89,32,32,32,32,67,68,45,82,79,77,32,67,68,85,45,49,48,48,48,32,49,
|
|
499
|
+
46,49,97]);this.data_end=this.data_length=Math.min(36,c);break;case 26:this.data_allocate(this.data[4]);this.data_end=this.data_length;this.status_reg=88;break;case 30:this.data_allocate(0);this.data_end=this.data_length;this.status_reg=80;break;case 37:c=this.sector_count-1;this.data_set(new Uint8Array([c>>24&255,c>>16&255,c>>8&255,c&255,0,0,this.sector_size>>8&255,this.sector_size&255]));this.data_end=this.data_length;this.status_reg=88;break;case 40:case 168:e=!1;this.features_reg&1?this.atapi_read_dma(this.data):
|
|
500
|
+
this.atapi_read(this.data);break;case 66:c=this.data[8];f="length="+c;this.data_allocate(Math.min(8,c));this.data_end=this.data_length;this.status_reg=88;break;case 67:c=this.data[8]|this.data[7]<<8;var g=this.data[9]>>6;f=`${n(g,2)} length=${c} ${!!(this.data[1]&2)} ${n(this.data[6])}`;this.data_allocate(c);this.data_end=this.data_length;0===g?(c=this.sector_count,this.data.set(new Uint8Array([0,18,1,1,0,20,1,0,0,0,0,0,0,22,170,0,c>>24,c>>16&255,c>>8&255,c&255]))):1===g?this.data.set(new Uint8Array([0,
|
|
501
|
+
10,1,1,0,0,0,0,0,0,0,0])):l(!1,this.name+": error: unimplemented format: "+g);this.status_reg=88;break;case 70:c=Math.min(this.data[8]|this.data[7]<<8,32);f="length="+c;this.data_allocate(c);this.data_end=this.data_length;this.data[0]=c-4>>24&255;this.data[1]=c-4>>16&255;this.data[2]=c-4>>8&255;this.data[3]=c-4&255;this.data[6]=8;this.data[10]=3;this.status_reg=88;break;case 81:this.data_allocate(0);this.data_end=this.data_length;this.status_reg=80;break;case 82:f="unimplemented";this.atapi_check_condition_response(5,
|
|
502
|
+
36);break;case 90:c=this.data[8]|this.data[7]<<8;g=this.data[2];f="page_code="+n(g)+" length="+c;42===g&&this.data_allocate(Math.min(30,c));this.data_end=this.data_length;this.status_reg=88;break;case 189:this.data_allocate(this.data[9]|this.data[8]<<8);this.data_end=this.data_length;this.data[5]=1;this.status_reg=88;break;case 27:c=this.data[4]&3;f=`Immed=${n(this.data[1]&1)} LoEj/Start=${n(c)}`;this.buffer&&2===c&&(f+=": disk ejected",this.medium_changed=!0,this.buffer=null);this.status_reg=80;
|
|
503
|
+
this.data_allocate(0);this.data_end=this.data_length;break;case 69:case 74:f="unimplemented";this.atapi_check_condition_response(5,36);break;case 190:f="unimplemented";this.data_allocate(0);this.data_end=this.data_length;this.status_reg=80;break;default:l(!1,`${this.name}: error: unimplemented ATAPI command ${n(this.data[0])}`,32768),this.atapi_check_condition_response(5,36)}this.sector_count_reg=this.sector_count_reg&-8|2;0===(this.status_reg&128)&&this.push_irq();0===(this.status_reg&128)&&0===
|
|
504
|
+
this.data_length&&(this.sector_count_reg|=1,this.status_reg&=-9);e&&(d=`[${d}] -> [${this.capture_regs()}]`,e=this.status_reg&1?this.error_reg&4?"ABORT":"ERROR":"OK",f=f?` ${f}:`:"",B(`${this.name}: ATAPI command ${b} (${n(a)}):${f} ${e} ${d}`,32768))}};X.prototype.atapi_check_condition_response=function(a,b){this.data_allocate(0);this.data_end=this.data_length;this.status_reg=65;this.error_reg=a<<4;this.sector_count_reg=this.sector_count_reg&-8|3;this.atapi_sense_key=a;this.atapi_add_sense=b};X.prototype.do_write=
|
|
505
|
+
function(){this.status_reg=80;l(this.data_length<=this.data.length);var a=this.data.subarray(0,this.data_length);l(0===this.data_length%512);this.ata_advance(this.current_command,this.data_length/512);this.push_irq();this.buffer.set(this.write_dest,a,function(){});this.report_write(this.data_length)};X.prototype.atapi_read=function(a){var b=a[2]<<24|a[3]<<16|a[4]<<8|a[5];a=168===a[0]?a[6]<<24|a[7]<<16|a[8]<<8|a[9]:a[7]<<8|a[8];var c=(a>>>0)*this.sector_size;b*=this.sector_size;this.data_length=0;
|
|
506
|
+
var d=this.lba_high_reg<<8&65280|this.lba_mid_reg&255;this.lba_mid_reg=this.lba_high_reg=0;65535===d&&d--;d>c&&(d=c);this.buffer?b>=this.buffer.byteLength?(l(!1,this.name+": CD read: Outside of disk end="+n(b+c)+" size="+n(this.buffer.byteLength),32768),this.status_reg=255,this.push_irq()):0===c?(this.status_reg=80,this.data_pointer=0):(c=Math.min(c,this.buffer.byteLength-b),this.status_reg=208,this.report_read_start(),this.read_buffer(b,c,e=>{this.data_set(e);this.status_reg=88;this.sector_count_reg=
|
|
507
|
+
this.sector_count_reg&-8|2;this.push_irq();this.data_end=d&=-4;this.data_end>this.data_length&&(this.data_end=this.data_length);this.lba_mid_reg=this.data_end&255;this.lba_high_reg=this.data_end>>8&255;this.report_read_end(c)})):(l(!1,this.name+": CD read: no buffer",32768),this.status_reg=255,this.error_reg=65,this.push_irq())};X.prototype.atapi_read_dma=function(a){var b=a[2]<<24|a[3]<<16|a[4]<<8|a[5],c=168===a[0]?a[6]<<24|a[7]<<16|a[8]<<8|a[9]:a[7]<<8|a[8];c>>>=0;a=a[1];var d=c*this.sector_size,
|
|
508
|
+
e=b*this.sector_size;B(this.name+": CD read DMA lba="+n(b)+" lbacount="+n(c)+" bytecount="+n(d)+" flags="+n(a),32768);e>=this.buffer.byteLength?(l(!1,this.name+": CD read: Outside of disk end="+n(e+d)+" size="+n(this.buffer.byteLength),32768),this.status_reg=255,this.push_irq()):(this.status_reg=208,this.report_read_start(),this.read_buffer(e,d,f=>{B(this.name+": atapi_read_dma: Data arrived",32768);this.report_read_end(d);this.status_reg=88;this.sector_count_reg=this.sector_count_reg&-8|2;this.data_set(f);
|
|
509
|
+
this.do_atapi_dma()}))};X.prototype.do_atapi_dma=function(){if(0===(this.channel.dma_status&1))B(this.name+": do_atapi_dma: Status not set",32768);else if(0===(this.status_reg&8))B(this.name+": do_atapi_dma: DRQ not set",32768);else{var a=this.channel.prdt_addr,b=0,c=this.data;do{var d=this.cpu.read32s(a),e=this.cpu.read16(a+4),f=this.cpu.read8(a+7)&128;e||(e=65536);this.cpu.write_blob(c.subarray(b,Math.min(b+e,this.data_length)),d);b+=e;a+=8;if(b>=this.data_length&&!f)break}while(!f);this.status_reg=
|
|
510
|
+
80;this.channel.dma_status&=-2;this.sector_count_reg=this.sector_count_reg&-8|3;this.push_irq()}};X.prototype.read_data=function(a){if(this.data_pointer<this.data_end){l(this.data_pointer+a-1<this.data_end);l(0===this.data_pointer%a,n(this.data_pointer)+" "+a);var b=1===a?this.data[this.data_pointer]:2===a?this.data16[this.data_pointer>>>1]:this.data32[this.data_pointer>>>2];this.data_pointer+=a;this.data_pointer>=this.data_end&&this.read_end();return b}this.data_pointer+=a;return 0};X.prototype.read_end=
|
|
511
|
+
function(){if(160===this.current_command)if(this.data_end===this.data_length)this.status_reg=80,this.sector_count_reg=this.sector_count_reg&-8|3,this.push_irq();else{this.status_reg=88;this.sector_count_reg=this.sector_count_reg&-8|2;this.push_irq();var a=this.lba_high_reg<<8&65280|this.lba_mid_reg&255;this.data_end+a>this.data_length?(this.lba_mid_reg=this.data_length-this.data_end&255,this.lba_high_reg=this.data_length-this.data_end>>8&255,this.data_end=this.data_length):this.data_end+=a}else this.error_reg=
|
|
512
|
+
0,this.data_pointer>=this.data_length?this.status_reg=80:(41===this.current_command||196===this.current_command?(a=Math.min(this.sectors_per_drq,(this.data_length-this.data_end)/512),l(0===a%1)):(l(32===this.current_command||36===this.current_command),a=1),this.ata_advance(this.current_command,a),this.data_end+=512*a,this.status_reg=88,this.push_irq())};X.prototype.write_data_port=function(a,b){l(0===this.data_pointer%b);this.data_pointer>=this.data_end?B(this.name+": redundant write to data port: "+
|
|
513
|
+
n(a)+" count="+n(this.data_end)+" cur="+n(this.data_pointer),32768):(1===b?this.data[this.data_pointer++]=a:2===b?(this.data16[this.data_pointer>>>1]=a,this.data_pointer+=2):(this.data32[this.data_pointer>>>2]=a,this.data_pointer+=4),l(this.data_pointer<=this.data_end),this.data_pointer===this.data_end&&this.write_end())};X.prototype.write_data_port8=function(a){this.write_data_port(a,1)};X.prototype.write_data_port16=function(a){this.write_data_port(a,2)};X.prototype.write_data_port32=function(a){this.write_data_port(a,
|
|
514
|
+
4)};X.prototype.write_end=function(){160===this.current_command?this.atapi_handle():this.data_pointer>=this.data_length?this.do_write():(l(48===this.current_command||52===this.current_command||197===this.current_command,"Unexpected command: "+n(this.current_command)),this.status_reg=88,this.data_end+=512,this.push_irq())};X.prototype.ata_advance=function(a,b){this.sector_count_reg-=b;36===a||41===a||37===a||52===a||57===a||53===a?(a=b+this.get_lba48(),this.lba_low_reg=a&255|a>>16&65280,this.lba_mid_reg=
|
|
515
|
+
a>>8&255,this.lba_high_reg=a>>16&255):this.is_lba?(a=b+this.get_lba28(),this.lba_low_reg=a&255,this.lba_mid_reg=a>>8&255,this.lba_high_reg=a>>16&255,this.head=this.head&-16|a&15):(a=b+this.get_chs(),b=a/(this.head_count*this.sectors_per_track)|0,this.lba_mid_reg=b&255,this.lba_high_reg=b>>8&255,this.head=(a/this.sectors_per_track|0)%this.head_count&15,this.lba_low_reg=a%this.sectors_per_track+1&255,l(a===this.get_chs()))};X.prototype.ata_read_sectors=function(a){var b=36===a||41===a,c=this.get_count(b);
|
|
516
|
+
b=this.get_lba(b);var d=32===a||36===a,e=c*this.sector_size;b*=this.sector_size;b+e>this.buffer.byteLength?(l(!1,this.name+": ATA read: Outside of disk",32768),this.status_reg=255,this.push_irq()):(this.status_reg=192,this.report_read_start(),this.read_buffer(b,e,f=>{this.data_set(f);this.status_reg=88;this.data_end=d?512:Math.min(e,512*this.sectors_per_drq);this.ata_advance(a,d?1:Math.min(c,this.sectors_per_track));this.push_irq();this.report_read_end(e)}))};X.prototype.ata_read_sectors_dma=function(a){a=
|
|
517
|
+
37===a;var b=this.get_count(a);this.get_lba(a)*this.sector_size+b*this.sector_size>this.buffer.byteLength?(l(!1,this.name+": ATA read: Outside of disk",32768),this.status_reg=255,this.push_irq()):(this.status_reg=88,this.channel.dma_status|=1)};X.prototype.do_ata_read_sectors_dma=function(){var a=37===this.current_command,b=this.get_count(a);a=this.get_lba(a);var c=b*this.sector_size,d=a*this.sector_size;l(a<this.buffer.byteLength);this.report_read_start();var e=this.channel.prdt_addr;this.read_buffer(d,
|
|
518
|
+
c,f=>{var g=this.channel.prdt_addr,k=0;l(e===g);do{var m=this.cpu.read32s(g),p=this.cpu.read16(g+4),q=this.cpu.read8(g+7)&128;p||(p=65536);this.cpu.write_blob(f.subarray(k,k+p),m);k+=p;g+=8}while(!q);l(k===c);this.ata_advance(this.current_command,b);this.status_reg=80;this.channel.dma_status&=-2;this.current_command=-1;this.report_read_end(c);this.push_irq()})};X.prototype.ata_write_sectors=function(a){var b=52===a||57===a,c=this.get_count(b);b=this.get_lba(b);a=48===a||52===a;c*=this.sector_size;
|
|
519
|
+
b*=this.sector_size;b+c>this.buffer.byteLength?(l(!1,this.name+": ATA write: Outside of disk",32768),this.status_reg=255,this.push_irq()):(this.status_reg=88,this.data_allocate_noclear(c),this.data_end=a?512:Math.min(c,512*this.sectors_per_drq),this.write_dest=b)};X.prototype.ata_write_sectors_dma=function(a){a=53===a;var b=this.get_count(a);this.get_lba(a)*this.sector_size+b*this.sector_size>this.buffer.byteLength?(l(!1,this.name+": ATA DMA write: Outside of disk",32768),this.status_reg=255,this.push_irq()):
|
|
520
|
+
(this.status_reg=88,this.channel.dma_status|=1)};X.prototype.do_ata_write_sectors_dma=function(){var a=53===this.current_command,b=this.get_count(a),c=this.get_lba(a);a=b*this.sector_size;c*=this.sector_size;var d=this.channel.prdt_addr,e=0;const f=new Uint8Array(a);do{var g=this.cpu.read32s(d),k=this.cpu.read16(d+4),m=this.cpu.read8(d+7)&128;k||(k=65536,B(this.name+": DMA: prd count was 0",32768));g=this.cpu.mem8.subarray(g,g+k);l(g.length===k);f.set(g,e);e+=k;d+=8}while(!m);l(e===f.length);this.buffer.set(c,
|
|
521
|
+
f,()=>{this.ata_advance(this.current_command,b);this.status_reg=80;this.push_irq();this.channel.dma_status&=-2;this.current_command=-1});this.report_write(a)};X.prototype.get_chs=function(){return((this.lba_mid_reg&255|this.lba_high_reg<<8&65280)*this.head_count+this.head)*this.sectors_per_track+(this.lba_low_reg&255)-1};X.prototype.get_lba28=function(){return this.lba_low_reg&255|this.lba_mid_reg<<8&65280|this.lba_high_reg<<16&16711680|(this.head&15)<<24};X.prototype.get_lba48=function(){return(this.lba_low_reg&
|
|
522
|
+
255|this.lba_mid_reg<<8&65280|this.lba_high_reg<<16&16711680|this.lba_low_reg>>8<<24&4278190080)>>>0};X.prototype.get_lba=function(a){return a?this.get_lba48():this.is_lba?this.get_lba28():this.get_chs()};X.prototype.get_count=function(a){a?(a=this.sector_count_reg,0===a&&(a=65536)):(a=this.sector_count_reg&255,0===a&&(a=256));return a};X.prototype.create_identify_packet=function(){const a=Math.min(16383,this.cylinder_count),b=(g,k,m,p)=>{k<<=1;var q=m<<1;m=k+q;g.fill(32,k,q);for(q=0;q<p.length&&
|
|
523
|
+
k<m;q++)q&1?(g[k]=p.charCodeAt(q),k+=2):g[k+1]=p.charCodeAt(q)},c=this.is_atapi?34112:64,d=160===this.current_command?0:1031,e=this.is_atapi?16928:16384,f=this.is_atapi?20480:29696;this.data.fill(0,0,512);this.data_set([c&255,c>>8&255,a&255,a>>8&255,0,0,this.head_count&255,this.head_count>>8&255,this.sectors_per_track/512&255,this.sectors_per_track/512>>8&255,0,2,this.sectors_per_track&255,this.sectors_per_track>>8&255,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,3,0,0,2,4,0,0,0,0,0,0,0,0,
|
|
524
|
+
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,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,1,0,0,2,0,0,0,2,0,2,7,0,a&255,a>>8&255,this.head_count&255,this.head_count>>8&255,this.sectors_per_track,0,this.sector_count&255,this.sector_count>>8&255,this.sector_count>>16&255,this.sector_count>>24&255,0,0,this.sector_count&255,this.sector_count>>8&255,this.sector_count>>16&255,this.sector_count>>24&255,0,0,d&255,d>>8&255,0,0,30,0,30,0,30,0,30,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,e&255,e>>
|
|
525
|
+
8&255,f&255,f>>8&255,0,64,e&255,e>>8&255,f&255,f>>8&255,0,64,0,0,0,0,0,0,0,0,0,0,1,96,0,0,0,0,0,0,0,0,0,0,0,0,this.sector_count&255,this.sector_count>>8&255,this.sector_count>>16&255,this.sector_count>>24&255]);b(this.data,10,10,`8086-86${this.channel_nr}${this.interface_nr}`);b(this.data,23,4,"1.00");b(this.data,27,20,this.is_atapi?"v86 ATAPI CD-ROM":"v86 ATA HD");this.data_end=this.data_length=512};X.prototype.data_allocate=function(a){this.data_allocate_noclear(a);this.data32.fill(0,0,a+3>>2)};
|
|
526
|
+
X.prototype.data_allocate_noclear=function(a){this.data.length<a&&(this.data=new Uint8Array(a+3&-4),this.data16=new Uint16Array(this.data.buffer),this.data32=new Int32Array(this.data.buffer));this.data_length=a;this.data_pointer=0};X.prototype.data_set=function(a){this.data_allocate_noclear(a.length);this.data.set(a)};X.prototype.report_read_start=function(){this.bus.send("ide-read-start")};X.prototype.report_read_end=function(a){this.bus.send("ide-read-end",[this.channel_nr,a,a/this.sector_size|
|
|
527
|
+
0])};X.prototype.report_write=function(a){this.bus.send("ide-write-end",[this.channel_nr,a,a/this.sector_size|0])};X.prototype.read_buffer=function(a,b,c){const d=this.last_io_id++;this.in_progress_io_ids.add(d);this.buffer.get(a,b,e=>{if(this.cancelled_io_ids.delete(d))l(!this.in_progress_io_ids.has(d));else{var f=this.in_progress_io_ids.delete(d);l(f);c(e)}})};X.prototype.cancel_io_operations=function(){for(const a of this.in_progress_io_ids)this.cancelled_io_ids.add(a);this.in_progress_io_ids.clear()};
|
|
528
|
+
X.prototype.get_state=function(){var a=[];a[0]=this.sector_count_reg;a[1]=this.cylinder_count;a[2]=this.lba_high_reg;a[3]=this.lba_mid_reg;a[4]=this.data_pointer;a[5]=0;a[6]=0;a[7]=0;a[8]=0;a[9]=this.device_reg;a[10]=this.error_reg;a[11]=this.head;a[12]=this.head_count;a[13]=this.is_atapi;a[14]=this.is_lba;a[15]=this.features_reg;a[16]=this.data;a[17]=this.data_length;a[18]=this.lba_low_reg;a[19]=this.sector_count;a[20]=this.sector_size;a[21]=this.sectors_per_drq;a[22]=this.sectors_per_track;a[23]=
|
|
529
|
+
this.status_reg;a[24]=this.write_dest;a[25]=this.current_command;a[26]=this.data_end;a[27]=this.current_atapi_command;a[28]=this.buffer;return a};X.prototype.set_state=function(a){this.sector_count_reg=a[0];this.cylinder_count=a[1];this.lba_high_reg=a[2];this.lba_mid_reg=a[3];this.data_pointer=a[4];this.device_reg=a[9];this.error_reg=a[10];this.head=a[11];this.head_count=a[12];this.is_atapi=a[13];this.is_lba=a[14];this.features_reg=a[15];this.data=a[16];this.data_length=a[17];this.lba_low_reg=a[18];
|
|
530
|
+
this.sector_count=a[19];this.sector_size=a[20];this.sectors_per_drq=a[21];this.sectors_per_track=a[22];this.status_reg=a[23];this.write_dest=a[24];this.current_command=a[25];this.data_end=a[26];this.current_atapi_command=a[27];this.data16=new Uint16Array(this.data.buffer);this.data32=new Int32Array(this.data.buffer);this.buffer&&this.buffer.set_state(a[28]);this.drive_connected=this.is_atapi||this.buffer;this.medium_changed=!1};function Xc(a,b,c){this.bus=b;this.id=a.devices.net?1:0;this.status=this.pairs=
|
|
531
|
+
1;this.preserve_mac_from_state_image=c;this.mac=new Uint8Array([0,34,21,255*Math.random()|0,255*Math.random()|0,255*Math.random()|0]);this.bus.send("net"+this.id+"-mac",Cc(this.mac));b=[];for(c=0;c<this.pairs;++c)b.push({size_supported:1024,notify_offset:0}),b.push({size_supported:1024,notify_offset:1});b.push({size_supported:16,notify_offset:2});this.virtio=new Fc(a,{name:"virtio-net",pci_id:80,device_id:4161,subsystem_device_id:1,common:{initial_port:51200,queues:b,features:[5,16,22,3,17,23,32],
|
|
532
|
+
on_driver_ok:()=>{}},notification:{initial_port:51456,single_handler:!1,handlers:[()=>{},d=>{const e=this.virtio.queues[d];for(;e.has_request();){const f=e.pop_request(),g=new Uint8Array(f.length_readable);f.get_next_blob(g);this.bus.send("net"+this.id+"-send",g.subarray(12));this.bus.send("eth-transmit-end",[g.length-12]);this.virtio.queues[d].push_reply(f)}this.virtio.queues[d].flush_replies()},d=>{if(d!==2*this.pairs)l(!1,"VirtioNet Notified for wrong queue: "+d+" (expected queue_id of 3)");else for(var e=
|
|
533
|
+
this.virtio.queues[d];e.has_request();){const k=e.pop_request();var f=new Uint8Array(k.length_readable);k.get_next_blob(f);var g=J(["b","b"],f,{offset:0});const m=g[0];g=g[1];switch(m<<8|g){case 1024:f=J(["h"],f,{offset:2});l(1===f[0]);this.Send(d,k,new Uint8Array([0]));break;case 257:this.mac=f.subarray(2,8);this.Send(d,k,new Uint8Array([0]));this.bus.send("net"+this.id+"-mac",Cc(this.mac));break;default:l(!1," VirtioNet received unknown command: "+m+":"+g);this.Send(d,k,new Uint8Array([1]));return}}}]},
|
|
534
|
+
isr_status:{initial_port:50944},device_specific:{initial_port:50688,struct:[0,1,2,3,4,5].map((d,e)=>({bytes:1,name:"mac_"+e,read:()=>this.mac[e],write:()=>{}})).concat([{bytes:2,name:"status",read:()=>this.status,write:()=>{}},{bytes:2,name:"max_pairs",read:()=>this.pairs,write:()=>{}},{bytes:2,name:"mtu",read:()=>1500,write:()=>{}}])}});this.bus.register("net"+this.id+"-receive",d=>{this.bus.send("eth-receive-end",[d.length]);const e=new Uint8Array(12+d.byteLength);(new DataView(e.buffer,e.byteOffset,
|
|
535
|
+
e.byteLength)).setInt16(10,1);e.set(d,12);d=this.virtio.queues[0];d.has_request()?(d=d.pop_request(),d.set_next_blob(e),this.virtio.queues[0].push_reply(d),this.virtio.queues[0].flush_replies()):console.log("No buffer to write into!")},this)}Xc.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.id;a[2]=this.mac;return a};Xc.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.id=a[1];this.preserve_mac_from_state_image&&(this.mac=a[2],this.bus.send("net"+this.id+"-mac",
|
|
536
|
+
Cc(this.mac)))};Xc.prototype.reset=function(){this.virtio.reset()};Xc.prototype.Send=function(a,b,c){b.set_next_blob(c);this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};Xc.prototype.Ack=function(a,b){this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};const Yc=Uint32Array.from([655360,655360,720896,753664]),Zc=Uint32Array.from([131072,65536,32768,32768]);function Y(a,b,c,d){this.cpu=a;this.bus=b;this.screen=c;this.vga_memory_size=d;this.cursor_address=
|
|
537
|
+
0;this.cursor_scanline_start=14;this.cursor_scanline_end=15;this.max_cols=80;this.max_rows=25;this.virtual_height=this.virtual_width=this.screen_height=this.screen_width=0;this.layers=[];this.start_address_latched=this.start_address=0;this.crtc=new Uint8Array(25);this.line_compare=this.offset_register=this.preset_row_scan=this.underline_location_register=this.vertical_blank_start=this.vertical_display_enable_end=this.horizontal_blank_start=this.horizontal_display_enable_end=this.crtc_mode=0;this.graphical_mode=
|
|
538
|
+
!1;this.vga256_palette=new Int32Array(256);this.latch_dword=0;this.svga_version=45253;this.svga_height=this.svga_width=0;this.svga_enabled=!1;this.svga_bpp=32;this.svga_offset_y=this.svga_offset_x=this.svga_offset=this.svga_bank_offset=0;this.vga_memory_size=void 0===this.vga_memory_size||262144>this.vga_memory_size?262144:268435456<this.vga_memory_size?268435456:ma(this.vga_memory_size);B("effective vga memory size: "+this.vga_memory_size,256);this.pci_space=[52,18,17,17,3,1,0,0,0,0,0,3,0,0,0,0,
|
|
539
|
+
8,14680064,57344,224,0,0,0,0,0,0,191,254,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,244,26,0,17,0,0,190,254,0,0,0,0,0,0,0,0,0,0,0,0];this.pci_id=144;this.pci_bars=[{size:this.vga_memory_size}];this.pci_rom_size=65536;this.pci_rom_address=4272947200;this.name="vga";this.dac_state=this.dac_color_index_read=this.dac_color_index_write=this.index_crtc=0;this.dac_mask=255;this.dac_map=new Uint8Array(16);this.attribute_controller_index=-1;this.palette_source=32;this.color_select=this.horizontal_panning=this.color_plane_enable=
|
|
540
|
+
this.attribute_mode=0;this.sequencer_index=-1;this.plane_write_bm=15;this.clocking_mode=this.sequencer_memory_mode=0;this.graphics_index=-1;this.planar_rotate_reg=this.planar_mode=this.plane_read=this.character_map_select=0;this.planar_bitmap=255;this.max_scan_line=this.color_dont_care=this.color_compare=this.miscellaneous_graphics_register=this.planar_setreset_enable=this.planar_setreset=0;this.port_3DA_value=this.miscellaneous_output_register=255;this.font_page_ab_enabled=!1;b=a.io;b.register_write(960,
|
|
541
|
+
this,this.port3C0_write);b.register_read(960,this,this.port3C0_read,this.port3C0_read16);b.register_read(961,this,this.port3C1_read);b.register_write(962,this,this.port3C2_write);b.register_write_consecutive(964,this,this.port3C4_write,this.port3C5_write);b.register_read(964,this,this.port3C4_read);b.register_read(965,this,this.port3C5_read);b.register_write_consecutive(974,this,this.port3CE_write,this.port3CF_write);b.register_read(974,this,this.port3CE_read);b.register_read(975,this,this.port3CF_read);
|
|
542
|
+
b.register_read(966,this,this.port3C6_read);b.register_write(966,this,this.port3C6_write);b.register_write(967,this,this.port3C7_write);b.register_read(967,this,this.port3C7_read);b.register_write(968,this,this.port3C8_write);b.register_read(968,this,this.port3C8_read);b.register_write(969,this,this.port3C9_write);b.register_read(969,this,this.port3C9_read);b.register_read(972,this,this.port3CC_read);b.register_write(980,this,this.port3D4_write,this.port3D4_write16);b.register_write(981,this,this.port3D5_write,
|
|
543
|
+
this.port3D5_write16);b.register_read(980,this,this.port3D4_read);b.register_read(981,this,this.port3D5_read,this.port3D5_read16);b.register_write(948,this,this.port3D4_write,this.port3D4_write16);b.register_write(949,this,this.port3D5_write,this.port3D5_write16);b.register_read(948,this,this.port3D4_read);b.register_read(949,this,this.port3D5_read,this.port3D5_read16);b.register_read(970,this,function(){B("3CA read",256);return 0});b.register_read(986,this,this.port3DA_read);b.register_read(954,
|
|
544
|
+
this,this.port3DA_read);this.dispi_index=-1;this.dispi_enable_value=0;b.register_write(462,this,void 0,this.port1CE_write);b.register_write(463,this,void 0,this.port1CF_write);b.register_read(463,this,void 0,this.port1CF_read);c=a.svga_allocate_memory(this.vga_memory_size)>>>0;this.svga_memory=h(Uint8Array,a.wasm_memory,c,this.vga_memory_size);this.diff_addr_min=this.vga_memory_size;this.diff_addr_max=0;this.diff_plot_min=this.vga_memory_size;this.diff_plot_max=0;this.image_data=null;this.vga_memory=
|
|
545
|
+
new Uint8Array(262144);this.plane0=new Uint8Array(this.vga_memory.buffer,0,65536);this.plane1=new Uint8Array(this.vga_memory.buffer,65536,65536);this.plane2=new Uint8Array(this.vga_memory.buffer,131072,65536);this.plane3=new Uint8Array(this.vga_memory.buffer,196608,65536);this.pixel_buffer=new Uint8Array(524288);b.mmap_register(655360,131072,e=>this.vga_memory_read(e),(e,f)=>this.vga_memory_write(e,f));a.devices.pci.register_device(this)}Y.prototype.get_state=function(){var a=[];a[0]=this.vga_memory_size;
|
|
546
|
+
a[1]=this.cursor_address;a[2]=this.cursor_scanline_start;a[3]=this.cursor_scanline_end;a[4]=this.max_cols;a[5]=this.max_rows;a[6]=this.vga_memory;a[7]=this.dac_state;a[8]=this.start_address;a[9]=this.graphical_mode;a[10]=this.vga256_palette;a[11]=this.latch_dword;a[12]=this.color_compare;a[13]=this.color_dont_care;a[14]=this.miscellaneous_graphics_register;a[15]=this.svga_width;a[16]=this.svga_height;a[17]=this.crtc_mode;a[18]=this.svga_enabled;a[19]=this.svga_bpp;a[20]=this.svga_bank_offset;a[21]=
|
|
547
|
+
this.svga_offset;a[22]=this.index_crtc;a[23]=this.dac_color_index_write;a[24]=this.dac_color_index_read;a[25]=this.dac_map;a[26]=this.sequencer_index;a[27]=this.plane_write_bm;a[28]=this.sequencer_memory_mode;a[29]=this.graphics_index;a[30]=this.plane_read;a[31]=this.planar_mode;a[32]=this.planar_rotate_reg;a[33]=this.planar_bitmap;a[34]=this.max_scan_line;a[35]=this.miscellaneous_output_register;a[36]=this.port_3DA_value;a[37]=this.dispi_index;a[38]=this.dispi_enable_value;a[39]=this.svga_memory;
|
|
548
|
+
a[41]=this.attribute_controller_index;a[42]=this.offset_register;a[43]=this.planar_setreset;a[44]=this.planar_setreset_enable;a[45]=this.start_address_latched;a[46]=this.crtc;a[47]=this.horizontal_display_enable_end;a[48]=this.horizontal_blank_start;a[49]=this.vertical_display_enable_end;a[50]=this.vertical_blank_start;a[51]=this.underline_location_register;a[52]=this.preset_row_scan;a[53]=this.offset_register;a[54]=this.palette_source;a[55]=this.attribute_mode;a[56]=this.color_plane_enable;a[57]=
|
|
549
|
+
this.horizontal_panning;a[58]=this.color_select;a[59]=this.clocking_mode;a[60]=this.line_compare;a[61]=this.pixel_buffer;a[62]=this.dac_mask;a[63]=this.character_map_select;a[64]=this.font_page_ab_enabled;return a};Y.prototype.set_state=function(a){this.vga_memory_size=a[0];this.cursor_address=a[1];this.cursor_scanline_start=a[2];this.cursor_scanline_end=a[3];this.max_cols=a[4];this.max_rows=a[5];a[6]&&this.vga_memory.set(a[6]);this.dac_state=a[7];this.start_address=a[8];this.graphical_mode=a[9];
|
|
550
|
+
this.vga256_palette=a[10];this.latch_dword=a[11];this.color_compare=a[12];this.color_dont_care=a[13];this.miscellaneous_graphics_register=a[14];this.svga_width=a[15];this.svga_height=a[16];this.crtc_mode=a[17];this.svga_enabled=a[18];this.svga_bpp=a[19];this.svga_bank_offset=a[20];this.svga_offset=a[21];this.index_crtc=a[22];this.dac_color_index_write=a[23];this.dac_color_index_read=a[24];this.dac_map=a[25];this.sequencer_index=a[26];this.plane_write_bm=a[27];this.sequencer_memory_mode=a[28];this.graphics_index=
|
|
551
|
+
a[29];this.plane_read=a[30];this.planar_mode=a[31];this.planar_rotate_reg=a[32];this.planar_bitmap=a[33];this.max_scan_line=a[34];this.miscellaneous_output_register=a[35];this.port_3DA_value=a[36];this.dispi_index=a[37];this.dispi_enable_value=a[38];this.svga_memory.set(a[39]);this.attribute_controller_index=a[41];this.offset_register=a[42];this.planar_setreset=a[43];this.planar_setreset_enable=a[44];this.start_address_latched=a[45];this.crtc.set(a[46]);this.horizontal_display_enable_end=a[47];this.horizontal_blank_start=
|
|
552
|
+
a[48];this.vertical_display_enable_end=a[49];this.vertical_blank_start=a[50];this.underline_location_register=a[51];this.preset_row_scan=a[52];this.offset_register=a[53];this.palette_source=a[54];this.attribute_mode=a[55];this.color_plane_enable=a[56];this.horizontal_panning=a[57];this.color_select=a[58];this.clocking_mode=a[59];this.line_compare=a[60];a[61]&&this.pixel_buffer.set(a[61]);this.dac_mask=void 0===a[62]?255:a[62];this.character_map_select=void 0===a[63]?0:a[63];this.font_page_ab_enabled=
|
|
553
|
+
void 0===a[64]?0:a[64];this.screen.set_mode(this.graphical_mode);this.graphical_mode?(this.screen_height=this.screen_width=0,this.svga_enabled?(this.set_size_graphical(this.svga_width,this.svga_height,this.svga_width,this.svga_height,this.svga_bpp),this.update_layers()):(this.update_vga_size(),this.update_layers(),this.complete_replot())):(this.set_font_bitmap(!0),this.set_size_text(this.max_cols,this.max_rows),this.set_font_page(),this.update_cursor_scanline(),this.update_cursor());this.complete_redraw()};
|
|
554
|
+
Y.prototype.vga_memory_read=function(a){if(this.svga_enabled)return this.cpu.read8((a-655360|this.svga_bank_offset)+3758096384|0);var b=this.miscellaneous_graphics_register>>2&3;a-=Yc[b];if(0>a||a>=Zc[b])return B("vga read outside memory space: addr:"+n(a>>>0),256),0;this.latch_dword=this.plane0[a];this.latch_dword|=this.plane1[a]<<8;this.latch_dword|=this.plane2[a]<<16;this.latch_dword|=this.plane3[a]<<24;if(this.planar_mode&8)return b=255,this.color_dont_care&1&&(b&=this.plane0[a]^~(this.color_compare&
|
|
555
|
+
1?255:0)),this.color_dont_care&2&&(b&=this.plane1[a]^~(this.color_compare&2?255:0)),this.color_dont_care&4&&(b&=this.plane2[a]^~(this.color_compare&4?255:0)),this.color_dont_care&8&&(b&=this.plane3[a]^~(this.color_compare&8?255:0)),b;b=this.plane_read;this.graphical_mode?this.sequencer_memory_mode&8?(b=a&3,a&=-4):this.planar_mode&16&&(b=a&1,a&=-2):b&=3;return this.vga_memory[b<<16|a]};Y.prototype.vga_memory_write=function(a,b){if(this.svga_enabled)this.cpu.write8((a-655360|this.svga_bank_offset)+
|
|
556
|
+
3758096384|0,b);else{var c=this.miscellaneous_graphics_register>>2&3;a-=Yc[c];0>a||a>=Zc[c]?B("vga write outside memory space: addr:"+n(a>>>0)+", value:"+n(b),256):this.graphical_mode?this.vga_memory_write_graphical(a,b):this.plane_write_bm&3?this.vga_memory_write_text_mode(a,b):this.plane_write_bm&4&&(this.plane2[a]=b)}};Y.prototype.vga_memory_write_graphical=function(a,b){var c=this.planar_mode&3,d=this.apply_feed(this.planar_bitmap),e=this.apply_expand(this.planar_setreset),f=this.apply_expand(this.planar_setreset_enable);
|
|
557
|
+
switch(c){case 0:b=this.apply_rotate(b);var g=this.apply_feed(b);g=this.apply_setreset(g,f);g=this.apply_logical(g,this.latch_dword);g=this.apply_bitmask(g,d);break;case 1:g=this.latch_dword;break;case 2:g=this.apply_expand(b);g=this.apply_logical(g,this.latch_dword);g=this.apply_bitmask(g,d);break;case 3:b=this.apply_rotate(b),d&=this.apply_feed(b),g=this.apply_bitmask(e,d)}b=15;switch(this.sequencer_memory_mode&12){case 0:b=5<<(a&1);a&=-2;break;case 8:case 12:b=1<<(a&3),a&=-4}b&=this.plane_write_bm;
|
|
558
|
+
b&1&&(this.plane0[a]=g>>0&255);b&2&&(this.plane1[a]=g>>8&255);b&4&&(this.plane2[a]=g>>16&255);b&8&&(this.plane3[a]=g>>24&255);a=this.vga_addr_to_pixel(a);this.partial_replot(a,a+7)};Y.prototype.apply_feed=function(a){return a|a<<8|a<<16|a<<24};Y.prototype.apply_expand=function(a){return(a&1?255:0)|(a&2?255:0)<<8|(a&4?255:0)<<16|(a&8?255:0)<<24};Y.prototype.apply_rotate=function(a){return(a|a<<8)>>>(this.planar_rotate_reg&7)&255};Y.prototype.apply_setreset=function(a,b){var c=this.apply_expand(this.planar_setreset);
|
|
559
|
+
return(a|b&c)&(~b|c)};Y.prototype.apply_logical=function(a,b){switch(this.planar_rotate_reg&24){case 8:return a&b;case 16:return a|b;case 24:return a^b}return a};Y.prototype.apply_bitmask=function(a,b){return b&a|~b&this.latch_dword};Y.prototype.text_mode_redraw=function(){const a=this.scan_line_to_screen_row(this.line_compare),b=Math.max(0,2*(2*this.offset_register-this.max_cols)),c=this.attribute_mode&8,d=this.font_page_ab_enabled?7:15,e=c?7:15,f=this.screen.FLAG_BLINKING,g=this.screen.FLAG_FONT_PAGE_B;
|
|
560
|
+
let k=this.start_address<<1;for(let m=0;m<this.max_rows;m++){m===a&&(k=0);for(let p=0;p<this.max_cols;p++){const q=this.vga_memory[k],r=this.vga_memory[k|1],v=(c&&r&128?f:0)|(!this.font_page_ab_enabled||r&8?0:g);this.bus.send("screen-put-char",[m,p,q]);this.screen.put_char(m,p,q,v,this.vga256_palette[this.dac_mask&this.dac_map[r>>4&e]],this.vga256_palette[this.dac_mask&this.dac_map[r&d]]);k+=2}k+=b}};Y.prototype.vga_memory_write_text_mode=function(a,b){this.vga_memory[a]=b;var c=Math.max(this.max_cols,
|
|
561
|
+
2*this.offset_register);let d;if(a>>1>=this.start_address){var e=(a>>1)-this.start_address;d=e/c|0;c=e%c}else e=a>>1,d=(e/c|0)+this.scan_line_to_screen_row(this.line_compare),c=e%c;l(0<=d&&0<=c);if(!(c>=this.max_cols||d>=this.max_rows)){a&1?(e=b,b=this.vga_memory[a&-2]):e=this.vga_memory[a|1];var f=this.attribute_mode&8;a=(f&&e&128?this.screen.FLAG_BLINKING:0)|(!this.font_page_ab_enabled||e&8?0:this.screen.FLAG_FONT_PAGE_B);var g=this.font_page_ab_enabled?7:15;f=f?7:15;this.bus.send("screen-put-char",
|
|
562
|
+
[d,c,b]);this.screen.put_char(d,c,b,a,this.vga256_palette[this.dac_mask&this.dac_map[e>>4&f]],this.vga256_palette[this.dac_mask&this.dac_map[e&g]])}};Y.prototype.update_cursor=function(){var a=Math.max(this.max_cols,2*this.offset_register);let b;this.cursor_address>=this.start_address?(b=(this.cursor_address-this.start_address)/a|0,a=(this.cursor_address-this.start_address)%a):(b=(this.cursor_address/a|0)+this.scan_line_to_screen_row(this.line_compare),a=this.cursor_address%a);l(0<=b&&0<=a);this.screen.update_cursor(b,
|
|
563
|
+
a)};Y.prototype.complete_redraw=function(){B("complete redraw",256);this.graphical_mode?this.svga_enabled?this.cpu.svga_mark_dirty():(this.diff_addr_min=0,this.diff_addr_max=524288):this.text_mode_redraw()};Y.prototype.complete_replot=function(){B("complete replot",256);this.graphical_mode&&!this.svga_enabled&&(this.diff_plot_min=0,this.diff_plot_max=524288,this.complete_redraw())};Y.prototype.partial_redraw=function(a,b){a<this.diff_addr_min&&(this.diff_addr_min=a);b>this.diff_addr_max&&(this.diff_addr_max=
|
|
564
|
+
b)};Y.prototype.partial_replot=function(a,b){a<this.diff_plot_min&&(this.diff_plot_min=a);b>this.diff_plot_max&&(this.diff_plot_max=b);this.partial_redraw(a,b)};Y.prototype.reset_diffs=function(){this.diff_addr_min=this.vga_memory_size;this.diff_addr_max=0;this.diff_plot_min=this.vga_memory_size;this.diff_plot_max=0};Y.prototype.destroy=function(){};Y.prototype.vga_bytes_per_line=function(){var a=this.offset_register<<2;this.underline_location_register&64?a<<=1:this.crtc_mode&64&&(a>>>=1);return a};
|
|
565
|
+
Y.prototype.vga_addr_shift_count=function(){var a=128+(~this.underline_location_register&this.crtc_mode&64);a-=this.underline_location_register&64;a-=this.attribute_mode&64;return a>>>6};Y.prototype.vga_addr_to_pixel=function(a){var b=this.vga_addr_shift_count();if(~this.crtc_mode&3){var c=a-this.start_address;c&=this.crtc_mode<<13|-24577;c<<=b;var d=c/this.virtual_width|0;c%=this.virtual_width;switch(this.crtc_mode&3){case 2:d=d<<1|a>>13&1;break;case 1:d=d<<1|a>>14&1;break;case 0:d=d<<2|a>>13&3}return d*
|
|
566
|
+
this.virtual_width+c+(this.start_address<<b)}return a<<b};Y.prototype.scan_line_to_screen_row=function(a){this.max_scan_line&128&&(a>>>=1);a=Math.ceil(a/(1+(this.max_scan_line&31)));this.crtc_mode&1||(a<<=1);this.crtc_mode&2||(a<<=1);return a};Y.prototype.set_size_text=function(a,b){l(!this.graphical_mode);this.max_cols=a;this.max_rows=b;this.screen.set_size_text(a,b);this.bus.send("screen-set-size",[a,b,0])};Y.prototype.set_size_graphical=function(a,b,c,d,e){l(this.graphical_mode);c=Math.max(c,1);
|
|
567
|
+
d=Math.max(d,1);if(this.screen_width!==a||this.screen_height!==b||this.virtual_width!==c||this.virtual_height!==d){this.screen_width=a;this.screen_height=b;this.virtual_width=c;this.virtual_height=d;if("undefined"!==typeof ImageData){const f=c*d,g=this.cpu.svga_allocate_dest_buffer(f)>>>0;this.dest_buffet_offset=g;this.image_data=new ImageData(new Uint8ClampedArray(this.cpu.wasm_memory.buffer,g,4*f),c,d);this.cpu.svga_mark_dirty()}this.screen.set_size_graphical(a,b,c,d);this.bus.send("screen-set-size",
|
|
568
|
+
[a,b,e])}};Y.prototype.update_vga_size=function(){if(!this.svga_enabled){var a=Math.min(1+this.horizontal_display_enable_end,this.horizontal_blank_start),b=Math.min(1+this.vertical_display_enable_end,this.vertical_blank_start);if(a&&b)if(this.graphical_mode){a<<=3;var c=this.offset_register<<4,d=4;this.attribute_mode&64?(a>>>=1,c>>>=1,d=8):this.attribute_mode&2&&(d=1);b=this.scan_line_to_screen_row(b);var e=Zc[0];const f=this.vga_bytes_per_line();this.set_size_graphical(a,b,c,f?Math.ceil(e/f):b,d);
|
|
569
|
+
this.update_vertical_retrace();this.update_layers()}else this.max_scan_line&128&&(b>>>=1),c=b/(1+(this.max_scan_line&31))|0,a&&c&&this.set_size_text(a,c)}};Y.prototype.update_layers=function(){this.graphical_mode||this.text_mode_redraw();if(this.svga_enabled)this.layers=[];else if(this.virtual_width&&this.screen_width)if(!this.palette_source||this.clocking_mode&32)this.layers=[],this.screen.clear_screen();else{var a=this.start_address_latched,b=this.horizontal_panning;this.attribute_mode&64&&(b>>>=
|
|
570
|
+
1);var c=this.preset_row_scan>>5&3,d=this.vga_addr_to_pixel(a+c);a=d/this.virtual_width|0;var e=d%this.virtual_width+b;d=this.scan_line_to_screen_row(1+this.line_compare);d=Math.min(d,this.screen_height);var f=this.screen_height-d;this.layers=[];e=-e;for(var g=0;e<this.screen_width;e+=this.virtual_width,g++)this.layers.push({image_data:this.image_data,screen_x:e,screen_y:0,buffer_x:0,buffer_y:a+g,buffer_width:this.virtual_width,buffer_height:d});a=0;this.attribute_mode&32||(a=this.vga_addr_to_pixel(c)+
|
|
571
|
+
b);e=-a;for(g=0;e<this.screen_width;e+=this.virtual_width,g++)this.layers.push({image_data:this.image_data,screen_x:e,screen_y:d,buffer_x:0,buffer_y:g,buffer_width:this.virtual_width,buffer_height:f})}};Y.prototype.update_vertical_retrace=function(){this.port_3DA_value|=8;this.start_address_latched!==this.start_address&&(this.start_address_latched=this.start_address,this.update_layers())};Y.prototype.update_cursor_scanline=function(){var a=this.max_scan_line&31;const b=Math.min(a,this.cursor_scanline_start&
|
|
572
|
+
31);a=Math.min(a,this.cursor_scanline_end&31);this.screen.update_cursor_scanline(b,a,!(this.cursor_scanline_start&32)&&b<a)};Y.prototype.port3C0_write=function(a){if(-1===this.attribute_controller_index)B("attribute controller index register: "+n(a),256),this.attribute_controller_index=a&31,B("attribute actual index: "+n(this.attribute_controller_index),256),this.palette_source!==(a&32)&&(this.palette_source=a&32,this.update_layers());else{if(16>this.attribute_controller_index)B("internal palette: "+
|
|
573
|
+
n(this.attribute_controller_index)+" -> "+n(a),256),this.dac_map[this.attribute_controller_index]=a,this.attribute_mode&64||this.complete_redraw();else switch(this.attribute_controller_index){case 16:B("3C0 / attribute mode control: "+n(a),256);if(this.attribute_mode!==a){var b=this.attribute_mode;this.attribute_mode=a;const c=0!==(a&1);this.svga_enabled||this.graphical_mode===c||(this.graphical_mode=c,this.screen.set_mode(this.graphical_mode));(b^a)&64&&this.complete_replot();this.update_vga_size();
|
|
574
|
+
this.complete_redraw();this.set_font_bitmap(!1)}break;case 18:B("3C0 / color plane enable: "+n(a),256);this.color_plane_enable!==a&&(this.color_plane_enable=a,this.complete_redraw());break;case 19:B("3C0 / horizontal panning: "+n(a),256);this.horizontal_panning!==a&&(this.horizontal_panning=a&15,this.update_layers());break;case 20:B("3C0 / color select: "+n(a),256);this.color_select!==a&&(this.color_select=a,this.complete_redraw());break;default:B("3C0 / attribute controller write "+n(this.attribute_controller_index)+
|
|
575
|
+
": "+n(a),256)}this.attribute_controller_index=-1}};Y.prototype.port3C0_read=function(){B("3C0 read",256);return(this.attribute_controller_index|this.palette_source)&255};Y.prototype.port3C0_read16=function(){B("3C0 read16",256);return this.port3C0_read()|this.port3C1_read()<<8&65280};Y.prototype.port3C1_read=function(){if(16>this.attribute_controller_index)return B("3C1 / internal palette read: "+n(this.attribute_controller_index)+" -> "+n(this.dac_map[this.attribute_controller_index]),256),this.dac_map[this.attribute_controller_index]&
|
|
576
|
+
255;switch(this.attribute_controller_index){case 16:return B("3C1 / attribute mode read: "+n(this.attribute_mode),256),this.attribute_mode;case 18:return B("3C1 / color plane enable read: "+n(this.color_plane_enable),256),this.color_plane_enable;case 19:return B("3C1 / horizontal panning read: "+n(this.horizontal_panning),256),this.horizontal_panning;case 20:return B("3C1 / color select read: "+n(this.color_select),256),this.color_select;default:B("3C1 / attribute controller read "+n(this.attribute_controller_index),
|
|
577
|
+
256)}return 255};Y.prototype.port3C2_write=function(a){B("3C2 / miscellaneous output register = "+n(a),256);this.miscellaneous_output_register=a};Y.prototype.port3C4_write=function(a){this.sequencer_index=a};Y.prototype.port3C4_read=function(){return this.sequencer_index};Y.prototype.port3C5_write=function(a){switch(this.sequencer_index){case 1:B("clocking mode: "+n(a),256);var b=this.clocking_mode;this.clocking_mode=a;(b^a)&32&&this.update_layers();this.set_font_bitmap(!1);break;case 2:B("plane write mask: "+
|
|
578
|
+
n(a),256);b=this.plane_write_bm;this.plane_write_bm=a;this.graphical_mode||!(b&4)||this.plane_write_bm&4||this.set_font_bitmap(!0);break;case 3:B("character map select: "+n(a),256);b=this.character_map_select;this.character_map_select=a;this.graphical_mode||b===a||this.set_font_page();break;case 4:B("sequencer memory mode: "+n(a),256);this.sequencer_memory_mode=a;break;default:B("3C5 / sequencer write "+n(this.sequencer_index)+": "+n(a),256)}};Y.prototype.port3C5_read=function(){B("3C5 / sequencer read "+
|
|
579
|
+
n(this.sequencer_index),256);switch(this.sequencer_index){case 1:return this.clocking_mode;case 2:return this.plane_write_bm;case 3:return this.character_map_select;case 4:return this.sequencer_memory_mode;case 6:return 18}return 0};Y.prototype.port3C6_write=function(a){this.dac_mask!==a&&(this.dac_mask=a,this.complete_redraw())};Y.prototype.port3C6_read=function(){return this.dac_mask};Y.prototype.port3C7_write=function(a){B("3C7 write: "+n(a),256);this.dac_color_index_read=3*a;this.dac_state&=0};
|
|
580
|
+
Y.prototype.port3C7_read=function(){return this.dac_state};Y.prototype.port3C8_write=function(a){this.dac_color_index_write=3*a;this.dac_state|=3};Y.prototype.port3C8_read=function(){return this.dac_color_index_write/3&255};Y.prototype.port3C9_write=function(a){var b=this.dac_color_index_write/3|0,c=this.dac_color_index_write%3,d=this.vga256_palette[b];if(0===(this.dispi_enable_value&32)){a&=63;const e=a&1;a=a<<2|e<<1|e}0===c?d=d&-16711681|a<<16:1===c?d=d&-65281|a<<8:(d=d&-256|a,B("dac set color, index="+
|
|
581
|
+
n(b)+" value="+n(d),256));this.vga256_palette[b]!==d&&(this.vga256_palette[b]=d,this.complete_redraw());this.dac_color_index_write++};Y.prototype.port3C9_read=function(){B("3C9 read",256);var a=this.vga256_palette[this.dac_color_index_read/3|0]>>8*(2-this.dac_color_index_read%3)&255;this.dac_color_index_read++;return this.dispi_enable_value&32?a:a>>2};Y.prototype.port3CC_read=function(){B("3CC read",256);return this.miscellaneous_output_register};Y.prototype.port3CE_write=function(a){this.graphics_index=
|
|
582
|
+
a};Y.prototype.port3CE_read=function(){return this.graphics_index};Y.prototype.port3CF_write=function(a){switch(this.graphics_index){case 0:this.planar_setreset=a;B("plane set/reset: "+n(a),256);break;case 1:this.planar_setreset_enable=a;B("plane set/reset enable: "+n(a),256);break;case 2:this.color_compare=a;B("color compare: "+n(a),256);break;case 3:this.planar_rotate_reg=a;B("plane rotate: "+n(a),256);break;case 4:this.plane_read=a;B("plane read: "+n(a),256);break;case 5:var b=this.planar_mode;
|
|
583
|
+
this.planar_mode=a;B("planar mode: "+n(a),256);(b^a)&96&&this.complete_replot();break;case 6:B("miscellaneous graphics register: "+n(a),256);this.miscellaneous_graphics_register!==a&&(this.miscellaneous_graphics_register=a,this.update_vga_size());break;case 7:this.color_dont_care=a;B("color don't care: "+n(a),256);break;case 8:this.planar_bitmap=a;B("planar bitmap: "+n(a),256);break;default:B("3CF / graphics write "+n(this.graphics_index)+": "+n(a),256)}};Y.prototype.port3CF_read=function(){B("3CF / graphics read "+
|
|
584
|
+
n(this.graphics_index),256);switch(this.graphics_index){case 0:return this.planar_setreset;case 1:return this.planar_setreset_enable;case 2:return this.color_compare;case 3:return this.planar_rotate_reg;case 4:return this.plane_read;case 5:return this.planar_mode;case 6:return this.miscellaneous_graphics_register;case 7:return this.color_dont_care;case 8:return this.planar_bitmap}return 0};Y.prototype.port3D4_write=function(a){B("3D4 / crtc index: "+a,256);this.index_crtc=a};Y.prototype.port3D4_write16=
|
|
585
|
+
function(a){this.port3D4_write(a&255);this.port3D5_write(a>>8&255)};Y.prototype.port3D4_read=function(){B("3D4 read / crtc index: "+this.index_crtc,256);return this.index_crtc};Y.prototype.port3D5_write=function(a){switch(this.index_crtc){case 1:B("3D5 / hdisp enable end write: "+n(a),256);this.horizontal_display_enable_end!==a&&(this.horizontal_display_enable_end=a,this.update_vga_size());break;case 2:this.horizontal_blank_start!==a&&(this.horizontal_blank_start=a,this.update_vga_size());break;case 7:B("3D5 / overflow register write: "+
|
|
586
|
+
n(a),256);var b=this.vertical_display_enable_end;this.vertical_display_enable_end&=255;this.vertical_display_enable_end=this.vertical_display_enable_end|a<<3&512|a<<7&256;b!==this.vertical_display_enable_end&&this.update_vga_size();this.line_compare=this.line_compare&767|a<<4&256;b=this.vertical_blank_start;this.vertical_blank_start=this.vertical_blank_start&767|a<<5&256;b!==this.vertical_blank_start&&this.update_vga_size();this.update_layers();break;case 8:B("3D5 / preset row scan write: "+n(a),
|
|
587
|
+
256);this.preset_row_scan=a;this.update_layers();break;case 9:B("3D5 / max scan line write: "+n(a),256);var c=this.max_scan_line;this.max_scan_line=a;this.line_compare=this.line_compare&511|a<<3&512;b=this.vertical_blank_start;this.vertical_blank_start=this.vertical_blank_start&511|a<<4&512;((c^this.max_scan_line)&159||b!==this.vertical_blank_start)&&this.update_vga_size();this.update_cursor_scanline();this.update_layers();this.set_font_bitmap(!1);break;case 10:B("3D5 / cursor scanline start write: "+
|
|
588
|
+
n(a),256);this.cursor_scanline_start=a;this.update_cursor_scanline();break;case 11:B("3D5 / cursor scanline end write: "+n(a),256);this.cursor_scanline_end=a;this.update_cursor_scanline();break;case 12:(this.start_address>>8&255)!==a&&(this.start_address=this.start_address&255|a<<8,this.update_layers(),~this.crtc_mode&3&&this.complete_replot());B("3D5 / start addr hi write: "+n(a)+" -> "+n(this.start_address,4),256);break;case 13:(this.start_address&255)!==a&&(this.start_address=this.start_address&
|
|
589
|
+
65280|a,this.update_layers(),~this.crtc_mode&3&&this.complete_replot());B("3D5 / start addr lo write: "+n(a)+" -> "+n(this.start_address,4),256);break;case 14:B("3D5 / cursor address hi write: "+n(a),256);this.cursor_address=this.cursor_address&255|a<<8;this.update_cursor();break;case 15:B("3D5 / cursor address lo write: "+n(a),256);this.cursor_address=this.cursor_address&65280|a;this.update_cursor();break;case 18:B("3D5 / vdisp enable end write: "+n(a),256);(this.vertical_display_enable_end&255)!==
|
|
590
|
+
a&&(this.vertical_display_enable_end=this.vertical_display_enable_end&768|a,this.update_vga_size());break;case 19:B("3D5 / offset register write: "+n(a),256);this.offset_register!==a&&(this.offset_register=a,this.update_vga_size(),~this.crtc_mode&3&&this.complete_replot());break;case 20:B("3D5 / underline location write: "+n(a),256);this.underline_location_register!==a&&(b=this.underline_location_register,this.underline_location_register=a,this.update_vga_size(),(b^a)&64&&this.complete_replot());
|
|
591
|
+
break;case 21:B("3D5 / vertical blank start write: "+n(a),256);(this.vertical_blank_start&255)!==a&&(this.vertical_blank_start=this.vertical_blank_start&768|a,this.update_vga_size());break;case 23:B("3D5 / crtc mode write: "+n(a),256);this.crtc_mode!==a&&(b=this.crtc_mode,this.crtc_mode=a,this.update_vga_size(),(b^a)&67&&this.complete_replot());break;case 24:B("3D5 / line compare write: "+n(a),256);this.line_compare=this.line_compare&768|a;this.update_layers();break;default:this.index_crtc<this.crtc.length&&
|
|
592
|
+
(this.crtc[this.index_crtc]=a),B("3D5 / CRTC write "+n(this.index_crtc)+": "+n(a),256)}};Y.prototype.port3D5_write16=function(a){B("16-bit write to 3D5: "+n(a,4),256);this.port3D5_write(a&255)};Y.prototype.port3D5_read=function(){B("3D5 read "+n(this.index_crtc),256);switch(this.index_crtc){case 1:return this.horizontal_display_enable_end;case 2:return this.horizontal_blank_start;case 7:return this.vertical_display_enable_end>>7&2|this.vertical_blank_start>>5&8|this.line_compare>>4&16|this.vertical_display_enable_end>>
|
|
593
|
+
3&64;case 8:return this.preset_row_scan;case 9:return this.max_scan_line;case 10:return this.cursor_scanline_start;case 11:return this.cursor_scanline_end;case 12:return this.start_address&255;case 13:return this.start_address>>8;case 14:return this.cursor_address>>8;case 15:return this.cursor_address&255;case 18:return this.vertical_display_enable_end&255;case 19:return this.offset_register;case 20:return this.underline_location_register;case 21:return this.vertical_blank_start&255;case 23:return this.crtc_mode;
|
|
594
|
+
case 24:return this.line_compare&255}return this.index_crtc<this.crtc.length?this.crtc[this.index_crtc]:0};Y.prototype.port3D5_read16=function(){B("Warning: 16-bit read from 3D5",256);return this.port3D5_read()};Y.prototype.port3DA_read=function(){B("3DA read - status 1 and clear attr index",256);var a=this.port_3DA_value;this.graphical_mode?(this.port_3DA_value^=1,this.port_3DA_value&=1):(this.port_3DA_value&1&&(this.port_3DA_value^=8),this.port_3DA_value^=1);this.attribute_controller_index=-1;return a};
|
|
595
|
+
Y.prototype.port1CE_write=function(a){this.dispi_index=a};Y.prototype.port1CF_write=function(a){B("1CF / dispi write "+n(this.dispi_index)+": "+n(a),256);const b=this.svga_enabled;switch(this.dispi_index){case 0:45248<=a&&45253>=a?this.svga_version=a:B("Invalid version value: "+n(a),256);break;case 1:this.svga_width=a;2560<this.svga_width&&(B("svga_width reduced from "+this.svga_width+" to 2560",256),this.svga_width=2560);break;case 2:this.svga_height=a;1600<this.svga_height&&(B("svga_height reduced from "+
|
|
596
|
+
this.svga_height+" to 1600",256),this.svga_height=1600);break;case 3:this.svga_bpp=a;break;case 4:(this.svga_enabled=1===(a&1))&&0===(a&128)&&this.svga_memory.fill(0);this.dispi_enable_value=a;break;case 5:B("SVGA bank offset: "+n(a<<16),256);this.svga_bank_offset=a<<16;break;case 8:B("SVGA X offset: "+n(a),256);this.svga_offset_x!==a&&(this.svga_offset_x=a,this.svga_offset=this.svga_offset_y*this.svga_width+this.svga_offset_x,this.complete_redraw());break;case 9:B("SVGA Y offset: "+n(a*this.svga_width)+
|
|
597
|
+
" y="+n(a),256);this.svga_offset_y!==a&&(this.svga_offset_y=a,this.svga_offset=this.svga_offset_y*this.svga_width+this.svga_offset_x,this.complete_redraw());break;default:B("Unimplemented dispi write index: "+n(this.dispi_index),256)}!this.svga_enabled||this.svga_width&&this.svga_height||(B("SVGA: disabled because of invalid width/height: "+this.svga_width+"x"+this.svga_height,256),this.svga_enabled=!1);l(4!==this.svga_bpp,"unimplemented svga bpp: 4");l(4===this.svga_bpp||8===this.svga_bpp||15===
|
|
598
|
+
this.svga_bpp||16===this.svga_bpp||24===this.svga_bpp||32===this.svga_bpp,"unexpected svga bpp: "+this.svga_bpp);this.svga_enabled?B("SVGA: enabled, "+this.svga_width+"x"+this.svga_height+"x"+this.svga_bpp,256):B("SVGA: disabled",256);this.svga_enabled&&!b&&(this.svga_offset_y=this.svga_offset_x=this.svga_offset=0,this.graphical_mode=!0,this.screen.set_mode(this.graphical_mode),this.set_size_graphical(this.svga_width,this.svga_height,this.svga_width,this.svga_height,this.svga_bpp));b&&!this.svga_enabled&&
|
|
599
|
+
(this.graphical_mode=a=0!==(this.attribute_mode&1),this.screen.set_mode(a),this.update_vga_size(),this.set_font_bitmap(!1),this.complete_redraw());this.svga_enabled||(this.svga_bank_offset=0);this.update_layers()};Y.prototype.port1CF_read=function(){B("1CF / dispi read "+n(this.dispi_index),256);return this.svga_register_read(this.dispi_index)};Y.prototype.svga_register_read=function(a){switch(a){case 0:return this.svga_version;case 1:return this.dispi_enable_value&2?2560:this.svga_width;case 2:return this.dispi_enable_value&
|
|
600
|
+
2?1600:this.svga_height;case 3:return this.dispi_enable_value&2?32:this.svga_bpp;case 4:return this.dispi_enable_value;case 5:return this.svga_bank_offset>>>16;case 6:return this.screen_width?this.screen_width:1;case 8:return this.svga_offset_x;case 9:return this.svga_offset_y;case 10:return this.vga_memory_size/65536|0;default:B("Unimplemented dispi read index: "+n(this.dispi_index),256)}return 255};Y.prototype.vga_replot=function(){for(var a=this.diff_plot_min&-16,b=Math.min(this.diff_plot_max|
|
|
601
|
+
15,524287),c=this.vga_addr_shift_count(),d=~this.crtc_mode&3,e=this.planar_mode&96,f=this.attribute_mode&64;a<=b;){var g=a>>>c;if(d){var k=a/this.virtual_width|0,m=a-this.virtual_width*k;switch(d){case 1:g=(k&1)<<13;k>>>=1;break;case 2:g=(k&1)<<14;k>>>=1;break;case 3:g=(k&3)<<13,k>>>=2}g|=(k*this.virtual_width+m>>>c)+this.start_address}k=this.plane0[g];m=this.plane1[g];var p=this.plane2[g],q=this.plane3[g];g=new Uint8Array(8);switch(e){case 0:k<<=0;m<<=1;p<<=2;q<<=3;for(var r=7;0<=r;r--)g[7-r]=k>>
|
|
602
|
+
r&1|m>>r&2|p>>r&4|q>>r&8;break;case 32:g[0]=k>>6&3|p>>4&12;g[1]=k>>4&3|p>>2&12;g[2]=k>>2&3|p>>0&12;g[3]=k>>0&3|p<<2&12;g[4]=m>>6&3|q>>4&12;g[5]=m>>4&3|q>>2&12;g[6]=m>>2&3|q>>0&12;g[7]=m>>0&3|q<<2&12;break;case 64:case 96:g[0]=k>>4&15,g[1]=k>>0&15,g[2]=m>>4&15,g[3]=m>>0&15,g[4]=p>>4&15,g[5]=p>>0&15,g[6]=q>>4&15,g[7]=q>>0&15}if(f)for(k=r=0;4>r;r++,a++,k+=2)this.pixel_buffer[a]=g[k]<<4|g[k+1];else for(r=0;8>r;r++,a++)this.pixel_buffer[a]=g[r]}};Y.prototype.vga_redraw=function(){var a=this.diff_addr_min,
|
|
603
|
+
b=Math.min(this.diff_addr_max,524287);const c=new Int32Array(this.cpu.wasm_memory.buffer,this.dest_buffet_offset,this.virtual_width*this.virtual_height);var d=255,e=0;this.attribute_mode&128&&(d&=207,e|=this.color_select<<4&48);if(this.attribute_mode&64)for(;a<=b;a++){var f=this.pixel_buffer[a]&d|e;f=this.vga256_palette[f];c[a]=f&65280|f<<16|f>>16|4278190080}else for(d&=63,e|=this.color_select<<4&192;a<=b;a++)f=this.dac_map[this.pixel_buffer[a]&this.color_plane_enable]&d|e,f=this.vga256_palette[f],
|
|
604
|
+
c[a]=f&65280|f<<16|f>>16|4278190080};Y.prototype.screen_fill_buffer=function(){if(this.graphical_mode){if(0===this.image_data.data.byteLength){var a=new Uint8ClampedArray(this.cpu.wasm_memory.buffer,this.dest_buffet_offset,4*this.virtual_width*this.virtual_height);this.image_data=new ImageData(a,this.virtual_width,this.virtual_height);this.update_layers()}if(this.svga_enabled){a=0;let d=this.svga_height;if(8===this.svga_bpp){const e=new Int32Array(this.cpu.wasm_memory.buffer,this.dest_buffet_offset,
|
|
605
|
+
this.screen_width*this.screen_height),f=new Uint8Array(this.cpu.wasm_memory.buffer,this.svga_memory.byteOffset,this.vga_memory_size);for(var b=0;b<e.length;b++){var c=this.vga256_palette[f[b]];e[b]=c&65280|c<<16|c>>16|4278190080}}else this.cpu.svga_fill_pixel_buffer(this.svga_bpp,this.svga_offset),b=15===this.svga_bpp?2:this.svga_bpp/8,a=((this.cpu.svga_dirty_bitmap_min_offset[0]/b|0)-this.svga_offset)/this.svga_width|0,d=(((this.cpu.svga_dirty_bitmap_max_offset[0]/b|0)-this.svga_offset)/this.svga_width|
|
|
606
|
+
0)+1;a<d&&(a=Math.max(a,0),d=Math.min(d,this.svga_height),this.screen.update_buffer([{image_data:this.image_data,screen_x:0,screen_y:a,buffer_x:0,buffer_y:a,buffer_width:this.svga_width,buffer_height:d-a}]))}else this.vga_replot(),this.vga_redraw(),this.screen.update_buffer(this.layers);this.reset_diffs()}this.update_vertical_retrace()};Y.prototype.set_font_bitmap=function(a){const b=this.max_scan_line&31;if(b&&!this.graphical_mode){const c=!!(this.clocking_mode&8);this.screen.set_font_bitmap(b+1,
|
|
607
|
+
!c&&!(this.clocking_mode&1),c,!!(this.attribute_mode&4),this.plane2,a)}};Y.prototype.set_font_page=function(){const a=[0,2,4,6,1,3,5,7],b=(this.character_map_select&12)>>2|(this.character_map_select&32)>>3,c=this.character_map_select&3|(this.character_map_select&16)>>2;this.font_page_ab_enabled=b!==c;this.screen.set_font_page(a[b],a[c]);this.complete_redraw()};const $c="SWAP_IN SWAP_OUT MAJFLT MINFLT MEMFREE MEMTOT AVAIL CACHES HTLB_PGALLOC HTLB_PGFAIL".split(" ");function ad(a,b){this.bus=b;this.zeroed=
|
|
608
|
+
this.fp_cmd=this.actual=this.num_pages=0;this.virtio=new Fc(a,{name:"virtio-balloon",pci_id:88,device_id:4165,subsystem_device_id:5,common:{initial_port:55296,queues:[{size_supported:32,notify_offset:0},{size_supported:32,notify_offset:0},{size_supported:2,notify_offset:1},{size_supported:64,notify_offset:2}],features:[1,3,32],on_driver_ok:()=>{B("Balloon setup",2048)}},notification:{initial_port:55552,single_handler:!1,handlers:[c=>{const d=this.virtio.queues[c];for(;d.has_request();){var e=d.pop_request();
|
|
609
|
+
const f=new Uint8Array(e.length_readable);e.get_next_blob(f);this.virtio.queues[c].push_reply(e);e=f.byteLength/4;this.actual+=0===c?e:-e}this.virtio.queues[c].flush_replies()},c=>{var d=this.virtio.queues[c];if(d.has_request()){d=d.pop_request();const e=new Uint8Array(d.length_readable);d.get_next_blob(e);let f={};for(let g=0;g<d.length_readable;g+=10){let [k,m]=J(["h","d"],e,{offset:g});f[$c[k]]=m}this.virtio.queues[c].push_reply(d);this.stats_cb&&this.stats_cb(f)}},c=>{const d=this.virtio.queues[c];
|
|
610
|
+
for(;d.has_request();){const f=d.pop_request();if(0<f.length_readable){var e=new Uint8Array(f.length_readable);f.get_next_blob(e);[e]=J(["w"],e,{offset:0});0===e&&(this.free_cb&&this.free_cb(this.zeroed),1<this.fp_cmd&&(this.fp_cmd=1),this.virtio.notify_config_changes())}if(0<f.length_writable)for(new Uint8Array(0),e=0;e<f.write_buffers.length;++e){let g=f.write_buffers[e];this.zeroed+=g.len;this.virtio.cpu.zero_memory(g.addr_low,g.len)}this.virtio.queues[c].push_reply(f)}this.virtio.queues[c].flush_replies()}]},
|
|
610
611
|
isr_status:{initial_port:55040},device_specific:{initial_port:54784,struct:[{bytes:4,name:"num_pages",read:()=>this.num_pages,write:()=>{}},{bytes:4,name:"actual",read:()=>this.actual,write:()=>{}},{bytes:4,name:"free_page_hint_cmd_id",read:()=>this.fp_cmd,write:()=>{}}]}})}ad.prototype.Inflate=function(a){this.num_pages+=a;this.virtio.notify_config_changes()};ad.prototype.Deflate=function(a){this.num_pages-=a;this.virtio.notify_config_changes()};ad.prototype.Cleanup=function(a){this.fp_cmd=2;this.free_cb=
|
|
611
612
|
a;this.zeroed=0;this.virtio.notify_config_changes()};ad.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.num_pages;a[2]=this.actual;return a};ad.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.num_pages=a[1];this.actual=a[2]};ad.prototype.GetStats=function(a){this.stats_cb=a;for(a=this.virtio.queues[2];a.has_request();){const b=a.pop_request();this.virtio.queues[2].push_reply(b)}this.virtio.queues[2].flush_replies()};ad.prototype.Reset=function(){};function bd(a,
|
|
612
613
|
b,c,d){B("Trying to load kernel of size "+b.byteLength);var e=new Uint8Array(b);const f=new Uint16Array(b);var g=new Uint32Array(b),k=e[497]||4,m=f[255];if(43605!==m)B("Bad checksum1: "+n(m));else if(m=f[257]|f[258]<<16,1400005704!==m)B("Bad checksum2: "+n(m));else{m=f[259];l(514<=m);var p=e[529];l(p&1);var q=f[283],r=g[139],v=g[140],t=e[564],z=e[565],A=518<=m?g[142]:255,u=g[146],E=g[147],F=g[150],x=g[151],M=g[152];B("kernel boot protocol version: "+n(m));B("flags="+n(p)+" xflags="+n(q));B("code32_start="+
|
|
@@ -638,7 +639,7 @@ a[43][1]);this.devices.virtio_9p&&this.devices.virtio_9p.set_state(a[45]);a[46]&
|
|
|
638
639
|
this.set_state_pic(a[60]);this.devices.sb16&&this.devices.sb16.set_state(a[61]);this.devices.uart1&&this.devices.uart1.set_state(a[79]);this.devices.uart2&&this.devices.uart2.set_state(a[80]);this.devices.uart3&&this.devices.uart3.set_state(a[81]);this.devices.virtio_console&&this.devices.virtio_console.set_state(a[82]);this.devices.virtio_net&&this.devices.virtio_net.set_state(a[83]);this.devices.virtio_balloon&&this.devices.virtio_balloon.set_state(a[84]);this.fw_value=a[62];a[63]&&this.set_state_ioapic(a[63]);
|
|
639
640
|
this.tss_size_32[0]=a[64];this.reg_xmm32s.set(a[66]);this.fpu_st.set(a[67]);this.fpu_stack_empty[0]=a[68];this.fpu_stack_ptr[0]=a[69];this.fpu_control_word[0]=a[70];this.fpu_ip[0]=a[71];this.fpu_ip_selector[0]=a[72];this.fpu_dp[0]=a[73];this.fpu_dp_selector[0]=a[74];this.fpu_opcode[0]=a[75];b=new ra(a[78].buffer);this.unpack_memory(b,a[77]);this.update_state_flags();this.full_clear_tlb();this.jit_clear_cache()};P.prototype.set_state_pic=function(a){const b=new Uint8Array(this.wasm_memory.buffer,this.get_pic_addr_master(),
|
|
640
641
|
13),c=new Uint8Array(this.wasm_memory.buffer,this.get_pic_addr_slave(),13);b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];const d=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];b[9]=a[9];b[10]=a[10];b[11]=a[11];b[12]=a[12];c[0]=d[0];c[1]=d[1];c[2]=d[2];c[3]=d[3];c[4]=d[4];c[6]=d[6];c[7]=d[7];c[8]=d[8];c[9]=d[9];c[10]=d[10];c[11]=d[11];c[12]=d[12]};P.prototype.set_state_apic=function(a){if(a instanceof Array){var b=new Int32Array(this.wasm_memory.buffer,this.get_apic_addr(),46);b[0]=a[0];b[1]=a[1];b[2]=a[2];
|
|
641
|
-
b[3]=a[3];b[4]=a[4];b[
|
|
642
|
+
b[3]=a[3];b[4]=a[4];b[8]=a[6];b[9]=a[7];b[10]=a[8];b[11]=a[9];b[12]=a[10];b[13]=a[11];b[14]=a[12];b[15]=a[13];b.set(a[15],16);b.set(a[15],24);b.set(a[16],32);b[40]=a[17];b[41]=a[18];b[42]=a[19];b[43]=a[20];b[44]=a[21];b[45]=a[22]||65536}else b=new Uint8Array(this.wasm_memory.buffer,this.get_apic_addr(),184),l(a instanceof Uint8Array),l(a.length===b.length),b.set(a)};P.prototype.set_state_ioapic=function(a){if(a instanceof Array){l(24===a[0].length);l(24===a[1].length);l(6===a.length);var b=new Int32Array(this.wasm_memory.buffer,
|
|
642
643
|
this.get_ioapic_addr(),52);b.set(a[0],0);b.set(a[1],24);b[48]=a[2];b[49]=a[3];b[50]=a[4];b[51]=a[5]}else b=new Uint8Array(this.wasm_memory.buffer,this.get_ioapic_addr(),208),l(a instanceof Uint8Array),l(a.length===b.length),b.set(a)};P.prototype.pack_memory=function(){l(0===(this.mem8.length&4095));var a=this.mem8.length>>12,b=[];for(var c=0;c<a;c++)this.is_memory_zeroed(c<<12,4096)||b.push(c);a=new ra(a);c=new Uint8Array(b.length<<12);for(const [d,e]of b.entries())a.set(e,1),b=e<<12,b=this.mem8.subarray(b,
|
|
643
644
|
b+4096),c.set(b,d<<12);return{bitmap:a,packed_memory:c}};P.prototype.unpack_memory=function(a,b){this.zero_memory(0,this.memory_size[0]);const c=this.memory_size[0]>>12;let d=0;for(let f=0;f<c;f++)if(a.get(f)){var e=d<<12;e=b.subarray(e,e+4096);this.mem8.set(e,f<<12);d++}};P.prototype.reboot_internal=function(){this.reset_cpu();this.fw_value=[];this.devices.virtio_9p&&this.devices.virtio_9p.reset();this.devices.virtio_console&&this.devices.virtio_console.reset();this.devices.virtio_net&&this.devices.virtio_net.reset();
|
|
644
645
|
this.devices.ps2&&this.devices.ps2.reset();this.load_bios()};P.prototype.reset_memory=function(){this.mem8.fill(0)};P.prototype.create_memory=function(a,b){a<b?(a=b,B("Rounding memory size up to "+a,2)):0>(a|0)&&(a=Math.pow(2,31)-131072,B("Rounding memory size down to "+a,2));a=(a-1|131071)+1|0;l(0<(a|0));l(0===(a&131071));console.assert(0===this.memory_size[0],"Expected uninitialised memory");this.memory_size[0]=a;b=this.allocate_memory(a);this.mem8=h(Uint8Array,this.wasm_memory,b,a);this.mem32s=
|