;(function(){'use strict';function aa(a,b){function c(C){C=C.toString(16);return"#"+"0".repeat(6-C.length)+C}function d(C,x,M,O){C.style.width="";C.style.height="";O&&(C.style.transform="");var U=C.getBoundingClientRect();O?C.style.transform=(1===x?"":" scaleX("+x+")")+(1===M?"":" scaleY("+M+")"):(0===x%1&&0===M%1?(f.style.imageRendering="crisp-edges",f.style.imageRendering="pixelated",f.style["-ms-interpolation-mode"]="nearest-neighbor"):(f.style.imageRendering="",f.style["-ms-interpolation-mode"]=""),O=window.devicePixelRatio|| 1,0!==O%1&&(x/=O,M/=O));1!==x&&(C.style.width=U.width*x+"px");1!==M&&(C.style.height=U.height*M+"px")}var e=a.container;this.screen_fill_buffer=b;console.assert(e,"options.container must be provided");var f=e.getElementsByTagName("canvas")[0],g=f.getContext("2d",{alpha:!1}),h=e.getElementsByTagName("div")[0],l=document.createElement("div"),m,n,p=1,q=1,r=1,D,y=!!a.use_graphical_text,u,F,w,K=!1,V=!1;b=new Uint16Array([8962,199,252,233,226,228,224,229,231,234,235,232,239,238,236,196,197,201,230,198, 244,246,242,251,249,255,214,220,162,163,165,8359,402,225,237,243,250,241,209,170,186,191,8976,172,189,188,161,171,187,9617,9618,9619,9474,9508,9569,9570,9558,9557,9571,9553,9559,9565,9564,9563,9488,9492,9524,9516,9500,9472,9532,9566,9567,9562,9556,9577,9574,9568,9552,9580,9575,9576,9572,9573,9561,9560,9554,9555,9579,9578,9496,9484,9608,9604,9612,9616,9600,945,223,915,960,931,963,181,964,934,920,937,948,8734,966,949,8745,8801,177,8805,8804,8992,8993,247,8776,176,8729,183,8730,8319,178,9632,160]);e= new Uint16Array([32,9786,9787,9829,9830,9827,9824,8226,9688,9675,9689,9794,9792,9834,9835,9788,9658,9668,8597,8252,182,167,9644,8616,8593,8595,8594,8592,8735,8596,9650,9660]);for(var Ka=[],bb,na=0;256>na;na++)bb=126na?e[na]:na,Ka[na]=String.fromCharCode(bb);g.imageSmoothingEnabled=!1;l.classList.add("cursor");l.style.position="absolute";l.style.backgroundColor="#ccc";l.style.width="7px";l.style.display="inline-block";h.style.display="block";f.style.display="none";this.init=function(){this.set_mode(y); y?this.set_size_graphical(720,400,720,400):this.set_size_text(80,25);this.timer()};this.make_screenshot=function(){const C=new Image;if(y)C.src=f.toDataURL("image/png");else{const x=[9,16],M=document.createElement("canvas");M.width=F*x[0];M.height=w*x[1];const O=M.getContext("2d");O.imageSmoothingEnabled=!1;O.font=window.getComputedStyle(h).font;O.textBaseline="top";for(let U=0;Uy?this.update_graphical():this.update_text())};this.update_text=function(){for(var C= 0;Cx;)h.removeChild(h.firstChild);for(;h.childNodes.length=C&&2*C{}},notification:{initial_port:43264, single_handler:!1,handlers:[d=>{if(0===d){for(;this.virtqueue.has_request();)d=this.virtqueue.pop_request(),this.ReceiveRequest(d);this.virtqueue.notify_me_after(0)}}]},isr_status:{initial_port:42752},device_specific:{initial_port:42496,struct:[{bytes:2,name:"mount tag length",read:()=>this.configspace_taglen,write:()=>{}}].concat(t.range(254).map(d=>({bytes:1,name:"mount tag name "+d,read:()=>this.configspace_tagname[d]||0,write:()=>{}})))}});this.virtqueue=this.virtio.queues[0]} ca.prototype.get_state=function(){var a=[];a[0]=this.configspace_tagname;a[1]=this.configspace_taglen;a[2]=this.virtio;a[3]=this.VERSION;a[4]=this.BLOCKSIZE;a[5]=this.msize;a[6]=this.replybuffer;a[7]=this.replybuffersize;a[8]=this.fids.map(function(b){return[b.inodeid,b.type,b.uid,b.dbg_name]});a[9]=this.fs;return a}; ca.prototype.set_state=function(a){this.configspace_tagname=a[0];this.configspace_taglen=a[1];this.virtio.set_state(a[2]);this.virtqueue=this.virtio.queues[0];this.VERSION=a[3];this.BLOCKSIZE=a[4];this.msize=a[5];this.replybuffer=a[6];this.replybuffersize=a[7];this.fids=a[8].map(function(b){return{inodeid:b[0],type:b[1],uid:b[2],dbg_name:b[3]}});this.fs.set_state(a[9])};ca.prototype.Createfid=function(a,b,c,d){return{inodeid:a,type:b,uid:c,dbg_name:d}}; ca.prototype.update_dbg_name=function(a,b){for(const c of this.fids)c.inodeid===a&&(c.dbg_name=b)};ca.prototype.reset=function(){this.fids=[];this.virtio.reset()};ca.prototype.BuildReply=function(a,b,c){v.Marshall(["w","b","h"],[c+7,a+1,b],this.replybuffer,0);c+7>=this.replybuffer.length&&z.Debug("Error in 9p: payloadsize exceeds maximum length");this.replybuffersize=c+7};ca.prototype.SendError=function(a,b,c){b=v.Marshall(["w"],[c],this.replybuffer,7);this.BuildReply(6,a,b)}; ca.prototype.SendReply=function(a){a.set_next_blob(this.replybuffer.subarray(0,this.replybuffersize));this.virtqueue.push_reply(a);this.virtqueue.flush_replies()}; ca.prototype.ReceiveRequest=async function(a){var b=new Uint8Array(a.length_readable);a.get_next_blob(b);var c={offset:0},d=v.Unmarshall(["w","b","h"],b,c),e=d[0],f=d[1],g=d[2];switch(f){case 8:e=this.fs.GetTotalSize();b=this.fs.GetSpace();d=[16914839];d[1]=this.BLOCKSIZE;d[2]=Math.floor(b/d[1]);d[3]=d[2]-Math.floor(e/d[1]);d[4]=d[2]-Math.floor(e/d[1]);d[5]=this.fs.CountUsedInodes();d[6]=this.fs.CountFreeInodes();d[7]=0;d[8]=256;e=v.Marshall("wwddddddw".split(""),d,this.replybuffer,7);this.BuildReply(f, g,e);this.SendReply(a);break;case 112:case 12:d=v.Unmarshall(["w","w"],b,c);var h=d[0];c=d[1];z.Debug("[open] fid="+h+", mode="+c);b=this.fids[h].inodeid;var l=this.fs.GetInode(b);z.Debug("file open "+this.fids[h].dbg_name);e=this.fs.OpenInode(b,c);this.fs.AddEvent(this.fids[h].inodeid,function(){z.Debug("file opened "+this.fids[h].dbg_name+" tag:"+g);var q=[];q[0]=l.qid;q[1]=this.msize-24;v.Marshall(["Q","w"],q,this.replybuffer,7);this.BuildReply(f,g,17);this.SendReply(a)}.bind(this));break;case 70:d= v.Unmarshall(["w","w","s"],b,c);b=d[0];h=d[1];e=d[2];z.Debug("[link] dfid="+b+", name="+e);e=this.fs.Link(this.fids[b].inodeid,this.fids[h].inodeid,e);if(0>e){this.SendError(g,-1===e?"Operation not permitted":"Unknown error: "+-e,-e);this.SendReply(a);break}this.BuildReply(f,g,0);this.SendReply(a);break;case 16:d=v.Unmarshall(["w","s","s","w"],b,c);h=d[0];e=d[1];b=d[2];d=d[3];z.Debug("[symlink] fid="+h+", name="+e+", symgt="+b+", gid="+d);b=this.fs.CreateSymlink(e,this.fids[h].inodeid,b);l=this.fs.GetInode(b); l.uid=this.fids[h].uid;l.gid=d;v.Marshall(["Q"],[l.qid],this.replybuffer,7);this.BuildReply(f,g,13);this.SendReply(a);break;case 18:d=v.Unmarshall("wswwww".split(""),b,c);h=d[0];e=d[1];c=d[2];b=d[3];var m=d[4];d=d[5];z.Debug("[mknod] fid="+h+", name="+e+", major="+b+", minor="+m);b=this.fs.CreateNode(e,this.fids[h].inodeid,b,m);l=this.fs.GetInode(b);l.mode=c;l.uid=this.fids[h].uid;l.gid=d;v.Marshall(["Q"],[l.qid],this.replybuffer,7);this.BuildReply(f,g,13);this.SendReply(a);break;case 22:d=v.Unmarshall(["w"], b,c);h=d[0];l=this.fs.GetInode(this.fids[h].inodeid);z.Debug("[readlink] fid="+h+" name="+this.fids[h].dbg_name+" target="+l.symlink);e=v.Marshall(["s"],[l.symlink],this.replybuffer,7);this.BuildReply(f,g,e);this.SendReply(a);break;case 72:d=v.Unmarshall(["w","s","w","w"],b,c);h=d[0];e=d[1];c=d[2];d=d[3];z.Debug("[mkdir] fid="+h+", name="+e+", mode="+c+", gid="+d);b=this.fs.CreateDirectory(e,this.fids[h].inodeid);l=this.fs.GetInode(b);l.mode=c|da;l.uid=this.fids[h].uid;l.gid=d;v.Marshall(["Q"],[l.qid], this.replybuffer,7);this.BuildReply(f,g,13);this.SendReply(a);break;case 14:d=v.Unmarshall(["w","s","w","w","w"],b,c);h=d[0];e=d[1];b=d[2];c=d[3];d=d[4];this.bus.send("9p-create",[e,this.fids[h].inodeid]);z.Debug("[create] fid="+h+", name="+e+", flags="+b+", mode="+c+", gid="+d);b=this.fs.CreateFile(e,this.fids[h].inodeid);this.fids[h].inodeid=b;this.fids[h].type=1;this.fids[h].dbg_name=e;l=this.fs.GetInode(b);l.uid=this.fids[h].uid;l.gid=d;l.mode=c|ea;v.Marshall(["Q","w"],[l.qid,this.msize-24],this.replybuffer, 7);this.BuildReply(f,g,17);this.SendReply(a);break;case 52:d=v.Unmarshall("wbwddws".split(""),b,c);h=d[0];b=d[2];e=0===d[4]?Infinity:d[4];d=this.fs.DescribeLock(d[1],d[3],e,d[5],d[6]);z.Debug("[lock] fid="+h+", type="+ba[d.type]+", start="+d.start+", length="+d.length+", proc_id="+d.proc_id);e=this.fs.Lock(this.fids[h].inodeid,d,b);v.Marshall(["b"],[e],this.replybuffer,7);this.BuildReply(f,g,1);this.SendReply(a);break;case 54:d=v.Unmarshall("wbddws".split(""),b,c);h=d[0];e=0===d[3]?Infinity:d[3]; d=this.fs.DescribeLock(d[1],d[2],e,d[4],d[5]);z.Debug("[getlock] fid="+h+", type="+ba[d.type]+", start="+d.start+", length="+d.length+", proc_id="+d.proc_id);e=this.fs.GetLock(this.fids[h].inodeid,d);e||(e=d,e.type=2);e=v.Marshall(["b","d","d","w","s"],[e.type,e.start,Infinity===e.length?0:e.length,e.proc_id,e.client_id],this.replybuffer,7);this.BuildReply(f,g,e);this.SendReply(a);break;case 24:d=v.Unmarshall(["w","d"],b,c);h=d[0];l=this.fs.GetInode(this.fids[h].inodeid);z.Debug("[getattr]: fid="+ h+" name="+this.fids[h].dbg_name+" request mask="+d[1]);if(!l||l.status===fa){z.Debug("getattr: unlinked");this.SendError(g,"No such file or directory",2);this.SendReply(a);break}d[0]=d[1];d[1]=l.qid;d[2]=l.mode;d[3]=l.uid;d[4]=l.gid;d[5]=l.nlinks;d[6]=l.major<<8|l.minor;d[7]=l.size;d[8]=this.BLOCKSIZE;d[9]=Math.floor(l.size/512+1);d[10]=l.atime;d[11]=0;d[12]=l.mtime;d[13]=0;d[14]=l.ctime;d[15]=0;d[16]=0;d[17]=0;d[18]=0;d[19]=0;v.Marshall("dQwwwddddddddddddddd".split(""),d,this.replybuffer,7);this.BuildReply(f, g,153);this.SendReply(a);break;case 26:d=v.Unmarshall("wwwwwddddd".split(""),b,c);h=d[0];l=this.fs.GetInode(this.fids[h].inodeid);z.Debug("[setattr]: fid="+h+" request mask="+d[1]+" name="+this.fids[h].dbg_name);d[1]&1&&(l.mode=d[2]);d[1]&2&&(l.uid=d[3]);d[1]&4&&(l.gid=d[4]);d[1]&16&&(l.atime=Math.floor((new Date).getTime()/1E3));d[1]&32&&(l.mtime=Math.floor((new Date).getTime()/1E3));d[1]&64&&(l.ctime=Math.floor((new Date).getTime()/1E3));d[1]&128&&(l.atime=d[6]);d[1]&256&&(l.mtime=d[8]);d[1]&8&& await this.fs.ChangeSize(this.fids[h].inodeid,d[5]);this.BuildReply(f,g,0);this.SendReply(a);break;case 50:d=v.Unmarshall(["w","d"],b,c);h=d[0];this.BuildReply(f,g,0);this.SendReply(a);break;case 40:case 116:d=v.Unmarshall(["w","d","w"],b,c);h=d[0];e=d[1];m=d[2];l=this.fs.GetInode(this.fids[h].inodeid);40===f&&z.Debug("[treaddir]: fid="+h+" offset="+e+" count="+m);116===f&&z.Debug("[read]: fid="+h+" ("+this.fids[h].dbg_name+") offset="+e+" count="+m+" fidtype="+this.fids[h].type);if(!l||l.status=== fa){z.Debug("read/treaddir: unlinked");this.SendError(g,"No such file or directory",2);this.SendReply(a);break}if(2===this.fids[h].type)for(l.caps.lengthl.size&&(m=0),this.bus.send("9p-read-start",[this.fids[h].dbg_name]),d=await this.fs.Read(d, e,m),this.bus.send("9p-read-end",[this.fids[h].dbg_name,m]),d&&this.replybuffer.set(d,11);v.Marshall(["w"],[m],this.replybuffer,7);this.BuildReply(f,g,4+m);this.SendReply(a);break;case 118:d=v.Unmarshall(["w","d","w"],b,c);h=d[0];e=d[1];m=d[2];d=this.fids[h].dbg_name;z.Debug("[write]: fid="+h+" ("+d+") offset="+e+" count="+m+" fidtype="+this.fids[h].type);if(2===this.fids[h].type){this.SendError(g,"Setxattr not supported",95);this.SendReply(a);break}else await this.fs.Write(this.fids[h].inodeid,e, m,b.subarray(c.offset));this.bus.send("9p-write-end",[d,m]);v.Marshall(["w"],[m],this.replybuffer,7);this.BuildReply(f,g,4);this.SendReply(a);break;case 74:d=v.Unmarshall(["w","s","w","s"],b,c);e=d[0];b=d[1];c=d[2];d=d[3];z.Debug("[renameat]: oldname="+b+" newname="+d);e=await this.fs.Rename(this.fids[e].inodeid,b,this.fids[c].inodeid,d);if(0>e){this.SendError(g,-2===e?"No such file or directory":-1===e?"Operation not permitted":-39===e?"Directory not empty":"Unknown error: "+-e,-e);this.SendReply(a); break}this.BuildReply(f,g,0);this.SendReply(a);break;case 76:d=v.Unmarshall(["w","s","w"],b,c);c=d[0];e=d[1];b=d[2];z.Debug("[unlink]: dirfd="+c+" name="+e+" flags="+b);h=this.fs.Search(this.fids[c].inodeid,e);if(-1===h){this.SendError(g,"No such file or directory",2);this.SendReply(a);break}e=this.fs.Unlink(this.fids[c].inodeid,e);if(0>e){this.SendError(g,-39===e?"Directory not empty":-1===e?"Operation not permitted":"Unknown error: "+-e,-e);this.SendReply(a);break}this.BuildReply(f,g,0);this.SendReply(a); break;case 100:d=v.Unmarshall(["w","s"],b,c);z.Debug("[version]: msize="+d[0]+" version="+d[1]);this.msize!==d[0]&&(this.msize=d[0],this.replybuffer=new Uint8Array(Math.min(16777216,2*this.msize)));e=v.Marshall(["w","s"],[this.msize,this.VERSION],this.replybuffer,7);this.BuildReply(f,g,e);this.SendReply(a);break;case 104:d=v.Unmarshall(["w","w","s","s","w"],b,c);h=d[0];e=d[4];z.Debug("[attach]: fid="+h+" afid="+A(d[1])+" uname="+d[2]+" aname="+d[3]);this.fids[h]=this.Createfid(0,1,e,"");l=this.fs.GetInode(this.fids[h].inodeid); v.Marshall(["Q"],[l.qid],this.replybuffer,7);this.BuildReply(f,g,13);this.SendReply(a);this.bus.send("9p-attach");break;case 108:d=v.Unmarshall(["h"],b,c);z.Debug("[flush] "+g);this.BuildReply(f,g,0);this.SendReply(a);break;case 110:d=v.Unmarshall(["w","w","h"],b,c);h=d[0];m=d[1];var n=d[2];z.Debug("[walk]: fid="+d[0]+" nwfid="+d[1]+" nwname="+n);if(0===n){this.fids[m]=this.Createfid(this.fids[h].inodeid,1,this.fids[h].uid,this.fids[h].dbg_name);v.Marshall(["h"],[0],this.replybuffer,7);this.BuildReply(f, g,2);this.SendReply(a);break}e=[];for(d=0;db;b++)this.ports[b]=this.create_empty_entry();var c=a.memory_size[0];for(b=0;b<<17>>0,8);return 255},function(d,e){A(d>>>0,8);A(e,2)},function(d){A(d>>>0,8);return-1},function(d,e){A(d>>>0,8);A(e>>>0,8)})} B.prototype.create_empty_entry=function(){return{read8:this.empty_port_read8,read16:this.empty_port_read16,read32:this.empty_port_read32,write8:this.empty_port_write,write16:this.empty_port_write,write32:this.empty_port_write,device:void 0}};B.prototype.empty_port_read8=function(){return 255};B.prototype.empty_port_read16=function(){return 65535};B.prototype.empty_port_read32=function(){return-1};B.prototype.empty_port_write=function(){}; B.prototype.register_read=function(a,b,c,d,e){c&&(this.ports[a].read8=c);d&&(this.ports[a].read16=d);e&&(this.ports[a].read32=e);this.ports[a].device=b};B.prototype.register_write=function(a,b,c,d,e){c&&(this.ports[a].write8=c);d&&(this.ports[a].write16=d);e&&(this.ports[a].write32=e);this.ports[a].device=b}; B.prototype.register_read_consecutive=function(a,b,c,d,e,f){function g(){return c.call(this)|d.call(this)<<8}function h(){return e.call(this)|f.call(this)<<8}function l(){return c.call(this)|d.call(this)<<8|e.call(this)<<16|f.call(this)<<24}e&&f?(this.register_read(a,b,c,g,l),this.register_read(a+1,b,d),this.register_read(a+2,b,e,h),this.register_read(a+3,b,f)):(this.register_read(a,b,c,g),this.register_read(a+1,b,d))}; B.prototype.register_write_consecutive=function(a,b,c,d,e,f){function g(m){c.call(this,m&255);d.call(this,m>>8&255)}function h(m){e.call(this,m&255);f.call(this,m>>8&255)}function l(m){c.call(this,m&255);d.call(this,m>>8&255);e.call(this,m>>16&255);f.call(this,m>>>24)}e&&f?(this.register_write(a,b,c,g,l),this.register_write(a+1,b,d),this.register_write(a+2,b,e,h),this.register_write(a+3,b,f)):(this.register_write(a,b,c,g),this.register_write(a+1,b,d))}; B.prototype.mmap_read32_shim=function(a){var b=this.cpu.memory_map_read8[a>>>17];return b(a)|b(a+1)<<8|b(a+2)<<16|b(a+3)<<24};B.prototype.mmap_write32_shim=function(a,b){var c=this.cpu.memory_map_write8[a>>>17];c(a,b&255);c(a+1,b>>8&255);c(a+2,b>>16&255);c(a+3,b>>>24)}; B.prototype.mmap_register=function(a,b,c,d,e,f){A(a>>>0,8);A(b,8);e||(e=this.mmap_read32_shim.bind(this));f||(f=this.mmap_write32_shim.bind(this));for(a>>>=17;0>>0,8),this.get_port_description(a));return c.write32.call(c.device,b)}; B.prototype.port_read8=function(a){var b=this.ports[a];b.read8===this.empty_port_read8&&(A(a,4),this.get_port_description(a));b=b.read8.call(b.device);A(a);return b};B.prototype.port_read16=function(a){var b=this.ports[a];b.read16===this.empty_port_read16&&(A(a,4),this.get_port_description(a));b=b.read16.call(b.device);A(a);return b};B.prototype.port_read32=function(a){var b=this.ports[a];b.read32===this.empty_port_read32&&(A(a,4),this.get_port_description(a));return b.read32.call(b.device)}; var ha={4:"PORT_DMA_ADDR_2",5:"PORT_DMA_CNT_2",10:"PORT_DMA1_MASK_REG",11:"PORT_DMA1_MODE_REG",12:"PORT_DMA1_CLEAR_FF_REG",13:"PORT_DMA1_MASTER_CLEAR",32:"PORT_PIC1_CMD",33:"PORT_PIC1_DATA",64:"PORT_PIT_COUNTER0",65:"PORT_PIT_COUNTER1",66:"PORT_PIT_COUNTER2",67:"PORT_PIT_MODE",96:"PORT_PS2_DATA",97:"PORT_PS2_CTRLB",100:"PORT_PS2_STATUS",112:"PORT_CMOS_INDEX",113:"PORT_CMOS_DATA",128:"PORT_DIAG",129:"PORT_DMA_PAGE_2",146:"PORT_A20",160:"PORT_PIC2_CMD",161:"PORT_PIC2_DATA",178:"PORT_SMI_CMD",179:"PORT_SMI_STATUS", 212:"PORT_DMA2_MASK_REG",214:"PORT_DMA2_MODE_REG",218:"PORT_DMA2_MASTER_CLEAR",240:"PORT_MATH_CLEAR",368:"PORT_ATA2_CMD_BASE",496:"PORT_ATA1_CMD_BASE",632:"PORT_LPT2",744:"PORT_SERIAL4",760:"PORT_SERIAL2",884:"PORT_ATA2_CTRL_BASE",888:"PORT_LPT1",1E3:"PORT_SERIAL3",1008:"PORT_FD_BASE",1010:"PORT_FD_DOR",1012:"PORT_FD_STATUS",1013:"PORT_FD_DATA",1014:"PORT_HD_DATA",1015:"PORT_FD_DIR",1016:"PORT_SERIAL1",3320:"PORT_PCI_CMD",3321:"PORT_PCI_REBOOT",3324:"PORT_PCI_DATA",1026:"PORT_BIOS_DEBUG",1296:"PORT_QEMU_CFG_CTL", 1297:"PORT_QEMU_CFG_DATA",45056:"PORT_ACPI_PM_BASE",45312:"PORT_SMB_BASE",35072:"PORT_BIOS_APM"};B.prototype.get_port_description=function(a){return ha[a]?" ("+ha[a]+")":""};function E(a,b){this.stopping=this.running=!1;this.idle=!0;this.tick_counter=0;this.worker=null;this.cpu=new G(a,b,()=>{this.idle&&this.next_tick(0)});this.bus=a;this.register_yield()}E.prototype.run=function(){this.stopping=!1;this.running||(this.running=!0,this.bus.send("emulator-started"));this.next_tick(0)};E.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)}}; E.prototype.next_tick=function(a){const b=++this.tick_counter;this.idle=!0;this.yield(a,b)};E.prototype.yield_callback=function(a){a===this.tick_counter&&this.do_tick()};E.prototype.stop=function(){this.running&&(this.stopping=!0)};E.prototype.destroy=function(){this.unregister_yield()};E.prototype.restart=function(){this.cpu.reset_cpu();this.cpu.load_bios()};E.prototype.init=function(a){this.cpu.init(a,this.bus);this.bus.send("emulator-ready")}; if("undefined"!==typeof process)E.prototype.yield=function(a,b){1>a?global.setImmediate(c=>this.yield_callback(c),b):setTimeout(c=>this.yield_callback(c),a,b)},E.prototype.register_yield=function(){},E.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)}}E.prototype.register_yield=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)};E.prototype.yield=function(b,c){this.worker.postMessage({t:b,tick:c})};E.prototype.unregister_yield=function(){this.worker&&this.worker.terminate();this.worker=null}}else E.prototype.yield=function(a){setTimeout(()=>{this.do_tick()},a)},E.prototype.register_yield=function(){},E.prototype.unregister_yield=function(){};E.prototype.save_state=function(){return this.cpu.save_state()}; E.prototype.restore_state=function(a){return this.cpu.restore_state(a)};if("object"===typeof performance&&performance.now)E.microtick=performance.now.bind(performance);else if("function"===typeof require){const {performance:a}=require("perf_hooks");E.microtick=a.now.bind(a)}else E.microtick="object"===typeof process&&process.hrtime?function(){var a=process.hrtime();return 1E3*a[0]+a[1]/1E6}:Date.now;var H=H||{};H.exportSymbol=function(){};H.exportProperty=function(){};var t=t||{};t.pads=function(a,b){return(a||0===a?a+"":"").padEnd(b," ")};t.pad0=function(a,b){return(a||0===a?a+"":"").padStart(b,"0")};t.zeros=function(a){return Array(a).fill(0)};t.range=function(a){return Array.from(Array(a).keys())}; t.view=function(a,b,c,d){return new Proxy({},{get:function(e,f){e=new a(b.buffer,c,d);const g=e[f];if("function"===typeof g)return g.bind(e);/^\d+$/.test(f);return g},set:function(e,f,g){/^\d+$/.test(f);(new a(b.buffer,c,d))[f]=g;return!0}})};function A(a,b){a=a?a.toString(16):"";return"0x"+t.pad0(a.toUpperCase(),b||1)} if("undefined"!==typeof crypto&&crypto.getRandomValues){const a=new Int32Array(1);t.get_rand_int=function(){crypto.getRandomValues(a);return a[0]}}else if("undefined"!==typeof require){const a=require("crypto");t.get_rand_int=function(){return a.randomBytes(4).readInt32LE(0)}} (function(){if("function"===typeof Math.clz32)t.int_log2=function(d){return 31-Math.clz32(d)};else{for(var a=new Int8Array(256),b=0,c=-2;256>b;b++)b&b-1||c++,a[b]=c;t.int_log2=function(d){d>>>=0;var e=d>>>16;if(e){var f=e>>>8;return f?24+a[f]:16+a[e]}return(f=d>>>8)?8+a[f]:a[d]}}})();t.round_up_to_next_power_of_2=function(a){return 1>=a?1:1<<1+t.int_log2(a-1)}; function ja(a){var b=new Uint8Array(a),c,d;this.length=0;this.push=function(e){this.length!==a&&this.length++;b[d]=e;d=d+1&a-1};this.shift=function(){if(this.length){var e=b[c];c=c+1&a-1;this.length--;return e}return-1};this.peek=function(){return this.length?b[c]:-1};this.clear=function(){this.length=d=c=0};this.clear()}function la(a){this.size=a;this.data=new Float32Array(a);this.length=this.end=this.start=0} la.prototype.push=function(a){this.length===this.size?this.start=this.start+1&this.size-1:this.length++;this.data[this.end]=a;this.end=this.end+1&this.size-1};la.prototype.shift=function(){if(this.length){var a=this.data[this.start];this.start=this.start+1&this.size-1;this.length--;return a}}; la.prototype.shift_block=function(a){var b=new Float32Array(a);a>this.length&&(a=this.length);var c=this.start+a,d=this.data.subarray(this.start,c);b.set(d);c>=this.size&&(c-=this.size,b.set(this.data.subarray(0,c),d.length));this.start=c;this.length-=a;return b};la.prototype.peek=function(){if(this.length)return this.data[this.start]};la.prototype.clear=function(){this.length=this.end=this.start=0}; t.Bitmap=function(a){"number"===typeof a?this.view=new Uint8Array(a+7>>3):a instanceof ArrayBuffer&&(this.view=new Uint8Array(a))};t.Bitmap.prototype.set=function(a,b){const c=a>>3;a=1<<(a&7);this.view[c]=b?this.view[c]|a:this.view[c]&~a};t.Bitmap.prototype.get=function(a){return this.view[a>>3]>>(a&7)&1};t.Bitmap.prototype.get_buffer=function(){return this.view.buffer};t.load_file="undefined"===typeof XMLHttpRequest?ma:oa; function oa(a,b,c){function d(){const l=c||0;setTimeout(()=>{oa(a,b,l+1)},1E3*([1,1,2,3,5,8,13,21][l]||34))}var e=new XMLHttpRequest;e.open(b.method||"get",a,!0);e.responseType=b.as_json?"json":"arraybuffer";if(b.headers)for(var f=Object.keys(b.headers),g=0;ge.status&&d();else if(e.response){if(b.range){const l=e.getResponseHeader("Content-Encoding");l&&"identity"!==l&&console.error("Server sent Content-Encoding in response to ranged request",{filename:a,enc:l})}b.done&&b.done(e.response,e)}};e.onerror=function(l){console.error("Loading the image "+a+" failed",l);d()};b.progress&& (e.onprogress=function(l){b.progress(l)});e.send(null)}function ma(a,b){const c=require("fs");b.range?c.open(a,"r",(d,e)=>{if(d)throw d;d=b.range.length;var f=Buffer.allocUnsafe(d);c.read(e,f,0,d,b.range.start,g=>{if(g)throw g;b.done&&b.done(new Uint8Array(f));c.close(e,h=>{if(h)throw h;})})}):c.readFile(a,{encoding:b.as_json?"utf-8":null},function(d,e){d?console.log("Could not read file:",a,d):(d=e,d=b.as_json?JSON.parse(d):(new Uint8Array(d)).buffer,b.done(d))})} t.read_sized_string_from_mem=function(a,b,c){return String.fromCharCode(...(new Uint8Array(a.buffer,b>>>0,c>>>0)))};(function(){function a(g){this.buffer=g;this.byteLength=g.byteLength;this.onprogress=this.onload=void 0}function b(g,h,l){this.filename=g;this.byteLength=h;this.block_cache=new Map;this.block_cache_is_write=new Set;this.fixed_chunk_size=l;this.cache_reads=!!l;this.onprogress=this.onload=void 0}function c(g,h,l,m,n){const p=g.match(/\.[^\.]+(\.zst)?$/);this.extension=p?p[0]:"";this.basename=g.substring(0,g.length-this.extension.length);this.is_zstd=this.extension.endsWith(".zst");this.basename.endsWith("/")|| (this.basename+="-");this.block_cache=new Map;this.block_cache_is_write=new Set;this.byteLength=h;this.fixed_chunk_size=l;this.partfile_alt_format=!!m;this.zstd_decompress=n;this.cache_reads=!!l;this.onprogress=this.onload=void 0}function d(g){this.file=g;this.byteLength=g.size;1073741824>20)+" MB ...");this.buffer=new ArrayBuffer(g.size);this.onprogress=this.onload=void 0}function e(g){this.file=g;this.byteLength=g.size;this.block_cache= new Map;this.block_cache_is_write=new Set;this.onprogress=this.onload=void 0}t.SyncBuffer=a;t.AsyncXHRBuffer=b;t.AsyncXHRPartfileBuffer=c;t.AsyncFileBuffer=e;t.SyncFileBuffer=d;t.buffer_from_object=function(g,h){if(g.buffer instanceof ArrayBuffer)return new t.SyncBuffer(g.buffer);if("undefined"!==typeof File&&g.buffer instanceof File)return h=g.async,void 0===h&&(h=268435456<=g.buffer.size),h?new t.AsyncFileBuffer(g.buffer):new t.SyncFileBuffer(g.buffer);if(g.url)return g.use_parts?new t.AsyncXHRPartfileBuffer(g.url, g.size,g.fixed_chunk_size,!1,h):new t.AsyncXHRBuffer(g.url,g.size,g.fixed_chunk_size)};a.prototype.load=function(){this.onload&&this.onload({buffer:this.buffer})};a.prototype.get=function(g,h,l){l(new Uint8Array(this.buffer,g,h))};a.prototype.set=function(g,h,l){(new Uint8Array(this.buffer,g,h.byteLength)).set(h);l()};a.prototype.get_buffer=function(g){g(this.buffer)};a.prototype.get_state=function(){const g=[];g[0]=this.byteLength;g[1]=new Uint8Array(this.buffer);return g};a.prototype.set_state= function(g){this.byteLength=g[0];this.buffer=g[1].slice().buffer};b.prototype.load=function(){void 0!==this.byteLength?this.onload&&this.onload(Object.create(null)):f(this.filename,(g,h)=>{if(g)throw Error("Cannot use: "+this.filename+". "+g);this.byteLength=h;this.onload&&this.onload(Object.create(null))})};b.prototype.get_from_cache=function(g,h){var l=h/256;g/=256;for(var m=0;m{l?h(l):h(null,m.size)})}:function(g,h){t.load_file(g,{done:(l,m)=>{l=m.getResponseHeader("Content-Range")||"";(m=l.match(/\/(\d+)\s*$/))?h(null,+m[1]):h("`Range: bytes=...` header not supported (Got `"+l+"`)")},headers:{Range:"bytes=0-0","X-Accept-Encoding":"identity"}})}})();function pa(a,b,c,d,e,f){this.master=new I(this,a,b,d,e,0,f);this.slave=new I(this,a,c,!1,e,1,f);this.current_interface=this.master;this.cpu=a;0===e?(this.ata_port=496,this.irq=14,this.pci_id=240):1===e&&(this.ata_port=368,this.irq=15,this.pci_id=248);this.ata_port_high=this.ata_port|516;this.master_port=46080;this.pci_space=[134,128,16,112,5,0,160,2,0,128,1,1,0,0,0,0,this.ata_port&255|1,this.ata_port>>8,0,0,this.ata_port_high&255|1,this.ata_port_high>>8,0,0,0,0,0,0,0,0,0,0,this.master_port&255|1, this.master_port>>8,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,this.irq,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.pci_bars=[{size:8},{size:4},void 0,void 0,{size:16}];this.name="ide"+e;this.device_control=2;a.io.register_read(this.ata_port|7,this,function(){this.cpu.device_lower_irq(this.irq);return this.read_status()});a.io.register_read(this.ata_port_high| 2,this,this.read_status);a.io.register_write(this.ata_port_high|2,this,this.write_control);a.io.register_read(this.ata_port|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)});a.io.register_read(this.ata_port|1,this,function(){A(this.current_interface.error&255);return this.current_interface.error&255});a.io.register_read(this.ata_port|2,this,function(){A(this.current_interface.bytecount& 255);return this.current_interface.bytecount&255});a.io.register_read(this.ata_port|3,this,function(){A(this.current_interface.sector&255);return this.current_interface.sector&255});a.io.register_read(this.ata_port|4,this,function(){A(this.current_interface.cylinder_low&255);return this.current_interface.cylinder_low&255});a.io.register_read(this.ata_port|5,this,function(){A(this.current_interface.cylinder_high&255);return this.current_interface.cylinder_high&255});a.io.register_read(this.ata_port| 6,this,function(){return this.current_interface.drive_head&255});a.io.register_write(this.ata_port|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.ata_port|1,this,function(g){A(g);this.master.lba_count=(this.master.lba_count<<8|g)&65535;this.slave.lba_count=(this.slave.lba_count<<8|g)&65535});a.io.register_write(this.ata_port|2,this,function(g){A(g); this.master.bytecount=(this.master.bytecount<<8|g)&65535;this.slave.bytecount=(this.slave.bytecount<<8|g)&65535});a.io.register_write(this.ata_port|3,this,function(g){A(g);this.master.sector=(this.master.sector<<8|g)&65535;this.slave.sector=(this.slave.sector<<8|g)&65535});a.io.register_write(this.ata_port|4,this,function(g){A(g);this.master.cylinder_low=(this.master.cylinder_low<<8|g)&65535;this.slave.cylinder_low=(this.slave.cylinder_low<<8|g)&65535});a.io.register_write(this.ata_port|5,this,function(g){A(g); this.master.cylinder_high=(this.master.cylinder_high<<8|g)&65535;this.slave.cylinder_high=(this.slave.cylinder_high<<8|g)&65535});a.io.register_write(this.ata_port|6,this,function(g){var h=g&16;A(g,2);this.current_interface=h?this.slave:this.master;this.master.drive_head=g;this.slave.drive_head=g;this.master.is_lba=this.slave.is_lba=g>>6&1;this.master.head=this.slave.head=g&15});this.dma_command=this.dma_status=this.prdt_addr=0;a.io.register_write(this.ata_port|7,this,function(g){this.cpu.device_lower_irq(this.irq); this.current_interface.ata_command(g)});a.io.register_read(this.master_port|4,this,void 0,void 0,this.dma_read_addr);a.io.register_write(this.master_port|4,this,void 0,void 0,this.dma_set_addr);a.io.register_read(this.master_port,this,this.dma_read_command8,void 0,this.dma_read_command);a.io.register_write(this.master_port,this,this.dma_write_command8,void 0,this.dma_write_command);a.io.register_read(this.master_port|2,this,this.dma_read_status);a.io.register_write(this.master_port|2,this,this.dma_write_status); a.io.register_read(this.master_port|8,this,function(){return 0});a.io.register_read(this.master_port|10,this,function(){return 0});a.devices.pci.register_device(this)}pa.prototype.read_status=function(){if(this.current_interface.buffer){var a=this.current_interface.status;A(a,2);return a}return 0};pa.prototype.write_control=function(a){A(a,2);a&4&&(this.cpu.device_lower_irq(this.irq),this.master.device_reset(),this.slave.device_reset());this.device_control=a}; pa.prototype.dma_read_addr=function(){A(this.prdt_addr,8);return this.prdt_addr};pa.prototype.dma_set_addr=function(a){A(a,8);this.prdt_addr=a};pa.prototype.dma_read_status=function(){A(this.dma_status);return this.dma_status};pa.prototype.dma_write_status=function(a){A(a);this.dma_status&=~(a&6)};pa.prototype.dma_read_command=function(){return this.dma_read_command8()|this.dma_read_status()<<16};pa.prototype.dma_read_command8=function(){A(this.dma_command);return this.dma_command}; pa.prototype.dma_write_command=function(a){A(a);this.dma_write_command8(a&255);this.dma_write_status(a>>16&255)}; pa.prototype.dma_write_command8=function(a){A(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 37:case 200:this.current_interface.do_ata_read_sectors_dma();break;case 202:case 53:this.current_interface.do_ata_write_sectors_dma();break;case 160:this.current_interface.do_atapi_dma();break;default:A(this.current_interface.current_command)}}; pa.prototype.push_irq=function(){0===(this.device_control&2)&&(this.dma_status|=4,this.cpu.device_raise_irq(this.irq))};pa.prototype.get_state=function(){var a=[];a[0]=this.master;a[1]=this.slave;a[2]=this.ata_port;a[3]=this.irq;a[4]=this.pci_id;a[5]=this.ata_port_high;a[6]=this.master_port;a[7]=this.name;a[8]=this.device_control;a[9]=this.prdt_addr;a[10]=this.dma_status;a[11]=this.current_interface===this.master;a[12]=this.dma_command;return a}; pa.prototype.set_state=function(a){this.master.set_state(a[0]);this.slave.set_state(a[1]);this.ata_port=a[2];this.irq=a[3];this.pci_id=a[4];this.ata_port_high=a[5];this.master_port=a[6];this.name=a[7];this.device_control=a[8];this.prdt_addr=a[9];this.dma_status=a[10];this.current_interface=a[11]?this.master:this.slave;this.dma_command=a[12]}; function I(a,b,c,d,e,f,g){this.device=a;this.bus=g;this.nr=e;this.cpu=b;this.buffer=c;this.sector_size=d?2048:512;this.is_atapi=d;this.cylinder_count=this.sectors_per_track=this.head_count=this.sector_count=0;this.buffer&&(this.sector_count=this.buffer.byteLength/this.sector_size,this.sector_count!==(this.sector_count|0)&&(this.sector_count=Math.ceil(this.sector_count)),d?(this.head_count=1,this.sectors_per_track=0):(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|0)&&(this.cylinder_count=Math.floor(this.cylinder_count)),a=b.devices.rtc,a.cmos_write(57,a.cmos_read(57)|1<<4*this.nr),a.cmos_write(18,a.cmos_read(18)&15|240),a.cmos_write(27,this.cylinder_count&255),a.cmos_write(28,this.cylinder_count>>8&255),a.cmos_write(29,this.head_count&255),a.cmos_write(30,255),a.cmos_write(31,255),a.cmos_write(32,200),a.cmos_write(33,this.cylinder_count&255),a.cmos_write(34,this.cylinder_count>> 8&255),a.cmos_write(35,this.sectors_per_track&255));this.buffer=c;this.drive_head=this.head=this.cylinder_high=this.cylinder_low=this.lba_count=this.sector=this.bytecount=this.is_lba=0;this.status=80;this.sectors_per_drq=128;this.data_pointer=this.error=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_atapi_command=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;Object.seal(this)}I.prototype.device_reset=function(){this.is_atapi?(this.status=0,this.sector=this.error=this.bytecount=1,this.cylinder_low=20,this.cylinder_high=235):(this.status=81,this.sector=this.error=this.bytecount=1,this.cylinder_high=this.cylinder_low=0);this.cancel_io_operations()};I.prototype.push_irq=function(){this.device.push_irq()}; I.prototype.ata_command=function(a){A(a);if(this.buffer)switch(this.current_command=a,this.error=0,a){case 8:this.data_length=this.data_end=this.data_pointer=0;this.device_reset();this.push_irq();break;case 16:this.status=80;this.cylinder_low=0;this.push_irq();break;case 248:this.status=80;a=this.sector_count-1;this.sector=a&255;this.cylinder_low=a>>8&255;this.cylinder_high=a>>16&255;this.drive_head=this.drive_head&240|a>>24&15;this.push_irq();break;case 39:this.status=80;a=this.sector_count-1;this.sector= a&255;this.cylinder_low=a>>8&255;this.cylinder_high=a>>16&255;this.sector|=a>>24<<8&65280;this.push_irq();break;case 32:case 36:case 41:case 196:this.ata_read_sectors(a);break;case 48:case 52:case 57:case 197:this.ata_write_sectors(a);break;case 144:this.push_irq();this.error=257;this.status=80;break;case 145:this.status=80;this.push_irq();break;case 160:this.is_atapi&&(this.status=88,this.data_allocate(12),this.data_end=12,this.bytecount=1,this.push_irq());break;case 161:this.is_atapi?(this.create_identify_packet(), this.status=88,this.cylinder_low=20,this.cylinder_high=235):this.status=65;this.push_irq();break;case 198:A(this.bytecount&255);this.sectors_per_drq=this.bytecount&255;this.status=80;this.push_irq();break;case 37:case 200:this.ata_read_sectors_dma(a);break;case 53:case 202:this.ata_write_sectors_dma(a);break;case 64:this.status=80;this.push_irq();break;case 218:this.status=65;this.error=4;this.push_irq();break;case 224:this.status=80;this.push_irq();break;case 225:this.status=80;this.push_irq();break; case 231:this.status=80;this.push_irq();break;case 236:if(this.is_atapi){this.status=65;this.error=4;this.push_irq();break}this.create_identify_packet();this.status=88;this.push_irq();break;case 234:this.status=80;this.push_irq();break;case 239:A(this.bytecount&255);this.status=80;this.push_irq();break;case 222:this.status=80;this.push_irq();break;case 245:this.status=80;this.push_irq();break;case 249:this.status=65;this.error=4;break;default:A(a),this.status=65,this.error=4}else this.error=4,this.status= 65,this.push_irq()}; I.prototype.atapi_handle=function(){A(this.data[0]);this.data_pointer=0;this.current_atapi_command=this.data[0];switch(this.current_atapi_command){case 0:this.data_allocate(0);this.data_end=this.data_length;this.status=80;break;case 3:this.data_allocate(this.data[4]);this.data_end=this.data_length;this.status=88;this.data[0]=240;this.data[2]=5;this.data[7]=8;break;case 18:var a=this.data[4];this.status=88;A(this.data[1],2);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,46,49,97]);this.data_end=this.data_length=Math.min(36,a);break;case 26:this.data_allocate(this.data[4]);this.data_end=this.data_length;this.status=88;break;case 30:this.data_allocate(0);this.data_end=this.data_length;this.status=80;break;case 37:a=this.sector_count-1;this.data_set(new Uint8Array([a>>24&255,a>>16&255,a>>8&255,a&255,0,0,this.sector_size>>8&255,this.sector_size&255]));this.data_end=this.data_length;this.status=88;break;case 40:this.lba_count&1?this.atapi_read_dma(this.data): this.atapi_read(this.data);break;case 66:a=this.data[8];this.data_allocate(Math.min(8,a));this.data_end=this.data_length;this.status=88;break;case 67:a=this.data[8]|this.data[7]<<8;var b=this.data[9]>>6;this.data_allocate(a);this.data_end=this.data_length;A(b,2);A(this.data[6]);0===b?(a=this.sector_count,this.data.set(new Uint8Array([0,18,1,1,0,20,1,0,0,0,0,0,0,22,170,0,a>>24,a>>16&255,a>>8&255,a&255]))):1===b&&this.data.set(new Uint8Array([0,10,1,1,0,0,0,0,0,0,0,0]));this.status=88;break;case 70:a= this.data[8]|this.data[7]<<8;a=Math.min(a,32);this.data_allocate(a);this.data_end=this.data_length;this.data[0]=a-4>>24&255;this.data[1]=a-4>>16&255;this.data[2]=a-4>>8&255;this.data[3]=a-4&255;this.data[6]=8;this.data[10]=3;this.status=88;break;case 81:this.data_allocate(0);this.data_end=this.data_length;this.status=80;break;case 82:A(this.data[0]);this.status=81;this.data_length=0;this.error=80;break;case 90:a=this.data[8]|this.data[7]<<8;b=this.data[2];A(b);42===b&&this.data_allocate(Math.min(30, a));this.data_end=this.data_length;this.status=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=88;break;case 74:this.status=81;this.data_length=0;this.error=80;A(this.data[0]);break;case 190:A(this.data[0]);this.data_allocate(0);this.data_end=this.data_length;this.status=80;break;default:this.status=81,this.data_length=0,this.error=80,A(this.data[0])}this.bytecount=this.bytecount&-8|2;0===(this.status&128)&&this.push_irq(); 0===(this.status&128)&&0===this.data_length&&(this.bytecount|=1,this.status&=-9)};I.prototype.do_write=function(){this.status=80;var a=this.data.subarray(0,this.data_length);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)}; I.prototype.atapi_read=function(a){var b=a[2]<<24|a[3]<<16|a[4]<<8|a[5],c=a[7]<<8|a[8];a=a[1];var d=c*this.sector_size,e=b*this.sector_size;qa("CD read lba="+A(b)+" lbacount="+A(c)+" bytecount="+A(d)+" flags="+A(a),32768);this.data_length=0;var f=this.cylinder_high<<8&65280|this.cylinder_low&255;qa(A(this.cylinder_high,2)+" "+A(this.cylinder_low,2),32768);this.cylinder_low=this.cylinder_high=0;65535===f&&f--;f>d&&(f=d);e>=this.buffer.byteLength?(ra(!1,"CD read: Outside of disk end="+A(e+d)+" size="+ A(this.buffer.byteLength),32768),this.status=255,this.push_irq()):0===d?(this.status=80,this.data_pointer=0):(d=Math.min(d,this.buffer.byteLength-e),this.status=208,this.report_read_start(),this.read_buffer(e,d,g=>{this.data_set(g);this.status=88;this.bytecount=this.bytecount&-8|2;this.push_irq();this.data_end=f&=-4;this.data_end>this.data_length&&(this.data_end=this.data_length);this.cylinder_low=this.data_end&255;this.cylinder_high=this.data_end>>8&255;this.report_read_end(d)}))}; I.prototype.atapi_read_dma=function(a){var b=a[2]<<24|a[3]<<16|a[4]<<8|a[5],c=a[7]<<8|a[8];a=a[1];var d=c*this.sector_size,e=b*this.sector_size;qa("CD read DMA lba="+A(b)+" lbacount="+A(c)+" bytecount="+A(d)+" flags="+A(a),32768);e>=this.buffer.byteLength?(ra(!1,"CD read: Outside of disk end="+A(e+d)+" size="+A(this.buffer.byteLength),32768),this.status=255,this.push_irq()):(this.status=208,this.report_read_start(),this.read_buffer(e,d,f=>{this.report_read_end(d);this.status=88;this.bytecount=this.bytecount& -8|2;this.data_set(f);this.do_atapi_dma()}))}; I.prototype.do_atapi_dma=function(){if(0!==(this.device.dma_status&1)&&0!==(this.status&8)){var a=this.device.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);A(d);A(e);A(this.data_length);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){A(b);A(this.data_length);A(this.current_command);break}}while(!f);this.status=80;this.device.dma_status&=-2;this.bytecount=this.bytecount& -8|3;this.push_irq()}};I.prototype.read_data=function(a){if(this.data_pointer>>1]:this.data32[this.data_pointer>>>2];this.data_pointer+=a;0===(this.data_pointer&(0===(this.data_end&4095)?4095:255))&&(A(this.data[this.data_pointer],2),A(this.data_pointer),A(this.data_length));this.data_pointer>=this.data_end&&this.read_end();return b}this.data_pointer+=a;return 0}; I.prototype.read_end=function(){A(this.current_command);A(this.data_pointer);A(this.data_end);A(this.data_length);if(160===this.current_command)if(this.data_end===this.data_length)this.status=80,this.bytecount=this.bytecount&-8|3,this.push_irq();else{this.status=88;this.bytecount=this.bytecount&-8|2;this.push_irq();var a=this.cylinder_high<<8&65280|this.cylinder_low&255;this.data_end+a>this.data_length?(this.cylinder_low=this.data_length-this.data_end&255,this.cylinder_high=this.data_length-this.data_end>> 8&255,this.data_end=this.data_length):this.data_end+=a;A(this.data_end)}else this.error=0,this.data_pointer>=this.data_length?this.status=80:(a=196===this.current_command||41===this.current_command?Math.min(this.sectors_per_drq,(this.data_length-this.data_end)/512):1,this.ata_advance(this.current_command,a),this.data_end+=512*a,this.status=88,this.push_irq())}; I.prototype.write_data_port=function(a,b){if(this.data_pointer>=this.data_end)A(a),A(this.data_end),A(this.data_pointer);else{if(0===(this.data_pointer+b&(0===(this.data_end&4095)?4095:255))||20>this.data_end)A(a>>>0),A(this.data_end),A(this.data_pointer);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);this.data_pointer===this.data_end&&this.write_end()}}; I.prototype.write_data_port8=function(a){this.write_data_port(a,1)};I.prototype.write_data_port16=function(a){this.write_data_port(a,2)};I.prototype.write_data_port32=function(a){this.write_data_port(a,4)};I.prototype.write_end=function(){160===this.current_command?this.atapi_handle():(A(this.data_pointer),A(this.data_length),this.data_pointer>=this.data_length?this.do_write():(A(this.current_command),this.status=88,this.data_end+=512,this.push_irq()))}; I.prototype.ata_advance=function(a,b){this.bytecount-=b;36===a||41===a||52===a||57===a||37===a||53===a?(a=b+this.get_lba48(),this.sector=a&255|a>>16&65280,this.cylinder_low=a>>8&255,this.cylinder_high=a>>16&255):this.is_lba?(a=b+this.get_lba28(),this.sector=a&255,this.cylinder_low=a>>8&255,this.cylinder_high=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.cylinder_low=b&255,this.cylinder_high=b>>8&255,this.head=(a/this.sectors_per_track| 0)%this.head_count&15,this.sector=a%this.sectors_per_track+1&255,this.get_chs())}; I.prototype.ata_read_sectors=function(a){var b=36===a||41===a,c=this.get_count(b);b=this.get_lba(b);var d=32===a||36===a,e=c*this.sector_size,f=b*this.sector_size;qa("ATA read cmd="+A(a)+" mode="+(this.is_lba?"lba":"chs")+" lba="+A(b)+" lbacount="+A(c)+" bytecount="+A(e),32768);f+e>this.buffer.byteLength?(this.status=255,this.push_irq()):(this.status=192,this.report_read_start(),this.read_buffer(f,e,g=>{this.data_set(g);this.status=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)}))};I.prototype.ata_read_sectors_dma=function(a){var b=37===a;a=this.get_count(b);b=this.get_lba(b);var c=a*this.sector_size,d=b*this.sector_size;A(b);A(a);A(c);d+c>this.buffer.byteLength?(this.status=255,this.push_irq()):(this.status=88,this.device.dma_status|=1)}; I.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;a*=this.sector_size;this.report_read_start();this.read_buffer(a,c,d=>{var e=this.device.prdt_addr,f=0;do{var g=this.cpu.read32s(e),h=this.cpu.read16(e+4),l=this.cpu.read8(e+7)&128;h||(h=65536);A(g);A(h);this.cpu.write_blob(d.subarray(f,f+h),g);f+=h;e+=8}while(!l);this.ata_advance(this.current_command,b);this.status=80;this.device.dma_status&=-2;this.current_command= -1;this.push_irq();this.report_read_end(c)})};I.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;var d=c*this.sector_size,e=b*this.sector_size;A(b);A(c);A(d);e+d>this.buffer.byteLength?(this.status=255,this.push_irq()):(this.status=88,this.data_allocate_noclear(d),this.data_end=a?512:Math.min(d,512*this.sectors_per_drq),this.write_dest=e)}; I.prototype.ata_write_sectors_dma=function(a){var b=53===a;a=this.get_count(b);b=this.get_lba(b);var c=a*this.sector_size,d=b*this.sector_size;A(b);A(a);A(c);d+c>this.buffer.byteLength?(this.status=255,this.push_irq()):(this.status=88,this.device.dma_status|=1)}; I.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.device.prdt_addr,e=0;qa("prdt addr: "+A(d,8),32768);const f=new Uint8Array(a);do{var g=this.cpu.read32s(d),h=this.cpu.read16(d+4),l=this.cpu.read8(d+7)&128;h||(h=65536);qa("dma write transfer dest="+A(g)+" prd_count="+A(h),32768);g=this.cpu.mem8.subarray(g,g+h);f.set(g,e);e+=h;d+=8}while(!l);this.buffer.set(c,f,()=>{this.ata_advance(this.current_command, b);this.status=80;this.push_irq();this.device.dma_status&=-2;this.current_command=-1});this.report_write(a)};I.prototype.get_chs=function(){return((this.cylinder_low&255|this.cylinder_high<<8&65280)*this.head_count+this.head)*this.sectors_per_track+(this.sector&255)-1};I.prototype.get_lba28=function(){return this.sector&255|this.cylinder_low<<8&65280|this.cylinder_high<<16&16711680|(this.head&15)<<24}; I.prototype.get_lba48=function(){return(this.sector&255|this.cylinder_low<<8&65280|this.cylinder_high<<16&16711680|this.sector>>8<<24&4278190080)>>>0};I.prototype.get_lba=function(a){return a?this.get_lba48():this.is_lba?this.get_lba28():this.get_chs()};I.prototype.get_count=function(a){a?(a=this.bytecount,0===a&&(a=65536)):(a=this.bytecount&255,0===a&&(a=256));return a}; I.prototype.create_identify_packet=function(){if(this.drive_head&16)this.data_allocate(0);else{for(var a=0;512>a;a++)this.data[a]=0;a=Math.min(16383,this.cylinder_count);this.data_set([64,this.is_atapi?133:0,a,a>>8,0,0,this.head_count,this.head_count>>8,this.sectors_per_track/512,this.sectors_per_track/512>>8,0,2,this.sectors_per_track,this.sectors_per_track>>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,3,0,0,2,4,0,0,0,0,0,0,0,0,0,56,118,32,54,68,72,32,32,32,32,32,32,32,32,32,32,32,32,32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,128,0,1,0,0,2,0,0,0,2,0,2,7,0,a,a>>8,this.head_count,this.head_count>>8,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,160===this.current_command?0:7,160===this.current_command?0:4,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,126,0, 0,0,0,0,0,116,0,64,0,64,0,116,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]);this.data_end=this.data_length=512}};I.prototype.data_allocate=function(a){this.data_allocate_noclear(a);for(var b=0;b>2;b++)this.data32[b]=0}; I.prototype.data_allocate_noclear=function(a){this.data.length{this.cancelled_io_ids.delete(d)?this.in_progress_io_ids.has(d):(this.in_progress_io_ids.delete(d),c(e))})};I.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()}; I.prototype.get_state=function(){var a=[];a[0]=this.bytecount;a[1]=this.cylinder_count;a[2]=this.cylinder_high;a[3]=this.cylinder_low;a[4]=this.data_pointer;a[5]=0;a[6]=0;a[7]=0;a[8]=0;a[9]=this.drive_head;a[10]=this.error;a[11]=this.head;a[12]=this.head_count;a[13]=this.is_atapi;a[14]=this.is_lba;a[15]=this.lba_count;a[16]=this.data;a[17]=this.data_length;a[18]=this.sector;a[19]=this.sector_count;a[20]=this.sector_size;a[21]=this.sectors_per_drq;a[22]=this.sectors_per_track;a[23]=this.status;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}; I.prototype.set_state=function(a){this.bytecount=a[0];this.cylinder_count=a[1];this.cylinder_high=a[2];this.cylinder_low=a[3];this.data_pointer=a[4];this.drive_head=a[9];this.error=a[10];this.head=a[11];this.head_count=a[12];this.is_atapi=a[13];this.is_lba=a[14];this.lba_count=a[15];this.data=a[16];this.data_length=a[17];this.sector=a[18];this.sector_count=a[19];this.sector_size=a[20];this.sectors_per_drq=a[21];this.sectors_per_track=a[22];this.status=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])};function sa(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);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]+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]},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)?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,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)}sa.prototype.get_state=function(){for(var a=[],b=0;256>b;b++)a[b]=this.device_spaces[b];a[256]=this.pci_addr;a[257]=this.pci_value;a[258]=this.pci_response;a[259]=this.pci_status;return a}; sa.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>3&31;var d="query enabled="+(this.pci_addr[3]>>7)+(" bdf="+A(a,4));d+=" dev="+A(c,2);d+=" addr="+A(b,2);a=this.device_spaces[a];void 0!==a?(this.pci_status32[0]=-2147483648,this.pci_response32[0]=b>2]:0,d+=" "+A(this.pci_addr32[0]>>>0,8)+" -> "+A(this.pci_response32[0]>>>0,8)):(this.pci_response32[0]=-1,this.pci_status32[0]=0)}; sa.prototype.pci_write8=function(a,b){var c=a>>8&65535;a&=255;var d=new Uint8Array(this.device_spaces[c].buffer);A(a);A(c>>3,2);A(a,4);A(b,2);d[a]=b};sa.prototype.pci_write16=function(a,b){var c=a>>8&65535;a&=255;var d=new Uint16Array(this.device_spaces[c].buffer);16<=a&&44>a?A(a):(A(a),A(c>>3,2),A(a,4),A(b,4),d[a>>>1]=b)}; sa.prototype.pci_write32=function(a,b){var c=a>>8&65535;a&=255;var d=this.device_spaces[c],e=this.devices[c];if(d)if(16<=a&&40>a){e=e.pci_bars[a-16>>2];A(b>>>0);A(c>>3,2);if(e){c=a>>2;var f=d[c]&1;-1===(b|3|e.size-1)?(b=~(e.size-1)|f,0===f&&(d[c]=b)):0===f&&(d[c]=e.original_bar);if(1===f){f=d[c]&65534;var g=b&65534;A(f>>>0,8);A(g>>>0,8);this.set_io_bars(e,f,g);d[c]=b|1}}else d[a>>2]=0;A(d[a>>2]>>>0)}else 48===a?(A(c>>3,2),A(b>>>0,8),d[a>>2]=e.pci_rom_size?-1===(b|2047)?-e.pci_rom_size|0:e.pci_rom_address| 0:0):4===a?(A(c>>3,2),A(a,4),A(b>>>0,8)):(A(c>>3,2),A(a,4),A(b>>>0,8),d[a>>>2]=b)};sa.prototype.register_device=function(a){var b=a.pci_id;A(b);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>8&255)-1+((a>>3)-1&255)&3)])};sa.prototype.lower_irq=function(a){this.cpu.device_lower_irq(this.isa_bridge_space8[96+((this.device_spaces[a][15]>>8&255)+(a>>3&255)-2&3)])};function J(a,b){this.io=a.io;this.cpu=a;this.dma=a.devices.dma;this.bytes_expecting=0;this.receiving_command=new Uint8Array(10);this.receiving_index=0;this.next_command=null;this.response_data=new Uint8Array(10);this.last_head=this.last_cylinder=this.drive=this.status_reg2=this.status_reg1=this.status_reg0=this.response_length=this.response_index=0;this.last_sector=1;this.dir=this.dor=0;this.fdb_image=this.fda_image=null;b?this.set_fda(b):(this.eject_fda(),this.cpu.devices.rtc.cmos_write(16,64)); this.io.register_read(1008,this,this.port3F0_read);this.io.register_read(1010,this,this.port3F2_read);this.io.register_read(1012,this,this.port3F4_read);this.io.register_read(1013,this,this.port3F5_read);this.io.register_read(1015,this,this.port3F7_read);this.io.register_write(1010,this,this.port3F2_write);this.io.register_write(1012,this,this.port3F4_write);this.io.register_write(1013,this,this.port3F5_write)} J.prototype.eject_fda=function(){this.fda_image=null;this.number_of_cylinders=this.number_of_heads=this.sectors_per_track=0;this.dir=128}; J.prototype.set_fda=function(a){var b={[163840]:{type:1,tracks:40,sectors:8,heads:1},[184320]:{type:1,tracks:40,sectors:9,heads:1},[204800]:{type:1,tracks:40,sectors:10,heads:1},[327680]:{type:1,tracks:40,sectors:8,heads:2},[368640]:{type:1,tracks:40,sectors:9,heads:2},[409600]:{type:1,tracks:40,sectors:10,heads:2},[737280]:{type:3,tracks:80,sectors:9,heads:2},[1228800]:{type:2,tracks:80,sectors:15,heads:2},[1474560]:{type:4,tracks:80,sectors:18,heads:2},[1763328]:{type:5,tracks:82,sectors:21,heads:2}, [2949120]:{type:5,tracks:80,sectors:36,heads:2},512:{type:1,tracks:1,sectors:1,heads:1}};let c=a.byteLength,d=b[c];d||(c=1474560>4);A(a);this.dor=a};J.prototype.check_drive_status=function(){this.status_reg1=this.fda_image?0:5;this.response_index=0;this.response_length=1;this.response_data[0]=0}; J.prototype.seek=function(a){if(0===(a[0]&3)){var b=a[1];a=a[0]>>2&1;b!==this.last_cylinder&&(this.dir=0);this.status_reg1=this.fda_image?0:5;this.status_reg0=32;this.last_cylinder=b;this.last_head=a}this.raise_irq()};J.prototype.calibrate=function(a){this.seek([a[0],0])};J.prototype.check_interrupt_status=function(){this.response_index=0;this.response_length=2;this.response_data[0]=this.status_reg0;this.response_data[1]=this.last_cylinder}; J.prototype.do_sector=function(a,b){var c=b[2],d=b[1],e=b[3],f=128<this.sectors_per_track&&(d=1,c++,c>=this.number_of_heads&&(c=0,b++)),b!==this.last_cylinder&&(this.dir=0),this.status_reg0=32,this.last_cylinder=b,this.last_head=c,this.last_sector=d,this.response_index=0,this.response_length=7,this.response_data[0]=c<<2|32,this.response_data[1]=0,this.response_data[2]=0,this.response_data[3]=b,this.response_data[4]=c,this.response_data[5]=d,this.response_data[6]=a[4],this.raise_irq())}; J.prototype.fix_drive_data=function(a){a.slice(0,this.bytes_expecting)};J.prototype.configure=function(a){a.slice(0,this.bytes_expecting)};J.prototype.read_sector_id=function(){this.response_index=0;this.response_length=7;this.response_data[0]=0;this.response_data[1]=0;this.response_data[2]=0;this.response_data[3]=0;this.response_data[4]=0;this.response_data[5]=0;this.response_data[6]=0;this.raise_irq()};J.prototype.raise_irq=function(){this.dor&8&&this.cpu.device_raise_irq(6)};G.prototype.mmap_read8=function(a){return this.memory_map_read8[a>>>17](a)};G.prototype.mmap_write8=function(a,b){this.memory_map_write8[a>>>17](a,b)};G.prototype.mmap_read16=function(a){var b=this.memory_map_read8[a>>>17];return b(a)|b(a+1|0)<<8};G.prototype.mmap_write16=function(a,b){var c=this.memory_map_write8[a>>>17];c(a,b&255);c(a+1|0,b>>8)};G.prototype.mmap_read32=function(a){return this.memory_map_read32[a>>>17](a)}; G.prototype.mmap_write32=function(a,b){this.memory_map_write32[a>>>17](a,b)};G.prototype.mmap_write64=function(a,b,c){var d=this.memory_map_write32[a>>>17];d(a,b);d(a+4,c)};G.prototype.mmap_write128=function(a,b,c,d,e){var f=this.memory_map_write32[a>>>17];f(a,b);f(a+4,c);f(a+8,d);f(a+12,e)};G.prototype.write_blob=function(a,b){a.length&&(this.in_mapped_range(b),this.in_mapped_range(b+a.length-1),this.jit_dirty_cache(b,b+a.length),this.mem8.set(a,b))}; G.prototype.read_blob=function(a,b){b&&(this.in_mapped_range(a),this.in_mapped_range(a+b-1));return this.mem8.subarray(a,a+b)};function L(a){this.cpu=a;this.channel_page=new Uint8Array(8);this.channel_pagehi=new Uint8Array(8);this.channel_addr=new Uint16Array(8);this.channel_addr_init=new Uint16Array(8);this.channel_count=new Uint16Array(8);this.channel_count_init=new Uint16Array(8);this.channel_mask=new Uint8Array(8);this.channel_mode=new Uint8Array(8);this.unmask_listeners=[];this.lsb_msb_flipflop=0;a=a.io;a.register_write(0,this,this.port_addr_write.bind(this,0));a.register_write(2,this,this.port_addr_write.bind(this, 1));a.register_write(4,this,this.port_addr_write.bind(this,2));a.register_write(6,this,this.port_addr_write.bind(this,3));a.register_write(1,this,this.port_count_write.bind(this,0));a.register_write(3,this,this.port_count_write.bind(this,1));a.register_write(5,this,this.port_count_write.bind(this,2));a.register_write(7,this,this.port_count_write.bind(this,3));a.register_read(0,this,this.port_addr_read.bind(this,0));a.register_read(2,this,this.port_addr_read.bind(this,1));a.register_read(4,this,this.port_addr_read.bind(this, 2));a.register_read(6,this,this.port_addr_read.bind(this,3));a.register_read(1,this,this.port_count_read.bind(this,0));a.register_read(3,this,this.port_count_read.bind(this,1));a.register_read(5,this,this.port_count_read.bind(this,2));a.register_read(7,this,this.port_count_read.bind(this,3));a.register_write(192,this,this.port_addr_write.bind(this,4));a.register_write(196,this,this.port_addr_write.bind(this,5));a.register_write(200,this,this.port_addr_write.bind(this,6));a.register_write(204,this, this.port_addr_write.bind(this,7));a.register_write(194,this,this.port_count_write.bind(this,4));a.register_write(198,this,this.port_count_write.bind(this,5));a.register_write(202,this,this.port_count_write.bind(this,6));a.register_write(206,this,this.port_count_write.bind(this,7));a.register_read(192,this,this.port_addr_read.bind(this,4));a.register_read(196,this,this.port_addr_read.bind(this,5));a.register_read(200,this,this.port_addr_read.bind(this,6));a.register_read(204,this,this.port_addr_read.bind(this, 7));a.register_read(194,this,this.port_count_read.bind(this,4));a.register_read(198,this,this.port_count_read.bind(this,5));a.register_read(202,this,this.port_count_read.bind(this,6));a.register_read(206,this,this.port_count_read.bind(this,7));a.register_write(135,this,this.port_page_write.bind(this,0));a.register_write(131,this,this.port_page_write.bind(this,1));a.register_write(129,this,this.port_page_write.bind(this,2));a.register_write(130,this,this.port_page_write.bind(this,3));a.register_write(143, this,this.port_page_write.bind(this,4));a.register_write(139,this,this.port_page_write.bind(this,5));a.register_write(137,this,this.port_page_write.bind(this,6));a.register_write(138,this,this.port_page_write.bind(this,7));a.register_read(135,this,this.port_page_read.bind(this,0));a.register_read(131,this,this.port_page_read.bind(this,1));a.register_read(129,this,this.port_page_read.bind(this,2));a.register_read(130,this,this.port_page_read.bind(this,3));a.register_read(143,this,this.port_page_read.bind(this, 4));a.register_read(139,this,this.port_page_read.bind(this,5));a.register_read(137,this,this.port_page_read.bind(this,6));a.register_read(138,this,this.port_page_read.bind(this,7));a.register_write(1159,this,this.port_pagehi_write.bind(this,0));a.register_write(1155,this,this.port_pagehi_write.bind(this,1));a.register_write(1153,this,this.port_pagehi_write.bind(this,2));a.register_write(1154,this,this.port_pagehi_write.bind(this,3));a.register_write(1163,this,this.port_pagehi_write.bind(this,5)); a.register_write(1161,this,this.port_pagehi_write.bind(this,6));a.register_write(1162,this,this.port_pagehi_write.bind(this,7));a.register_read(1159,this,this.port_pagehi_read.bind(this,0));a.register_read(1155,this,this.port_pagehi_read.bind(this,1));a.register_read(1153,this,this.port_pagehi_read.bind(this,2));a.register_read(1154,this,this.port_pagehi_read.bind(this,3));a.register_read(1163,this,this.port_pagehi_read.bind(this,5));a.register_read(1161,this,this.port_pagehi_read.bind(this,6));a.register_read(1162, this,this.port_pagehi_read.bind(this,7));a.register_write(10,this,this.port_singlemask_write.bind(this,0));a.register_write(212,this,this.port_singlemask_write.bind(this,4));a.register_write(15,this,this.port_multimask_write.bind(this,0));a.register_write(222,this,this.port_multimask_write.bind(this,4));a.register_read(15,this,this.port_multimask_read.bind(this,0));a.register_read(222,this,this.port_multimask_read.bind(this,4));a.register_write(11,this,this.port_mode_write.bind(this,0));a.register_write(214, this,this.port_mode_write.bind(this,4));a.register_write(12,this,this.portC_write);a.register_write(216,this,this.portC_write)}L.prototype.get_state=function(){return[this.channel_page,this.channel_pagehi,this.channel_addr,this.channel_addr_init,this.channel_count,this.channel_count_init,this.channel_mask,this.channel_mode,this.lsb_msb_flipflop]}; L.prototype.set_state=function(a){this.channel_page=a[0];this.channel_pagehi=a[1];this.channel_addr=a[2];this.channel_addr_init=a[3];this.channel_count=a[4];this.channel_count_init=a[5];this.channel_mask=a[6];this.channel_mode=a[7];this.lsb_msb_flipflop=a[8]};L.prototype.port_count_write=function(a,b){A(b);this.channel_count[a]=this.flipflop_get(this.channel_count[a],b,!1);this.channel_count_init[a]=this.flipflop_get(this.channel_count_init[a],b,!0)}; L.prototype.port_count_read=function(a){A(this.channel_count[a]);return this.flipflop_read(this.channel_count[a])};L.prototype.port_addr_write=function(a,b){A(b);this.channel_addr[a]=this.flipflop_get(this.channel_addr[a],b,!1);this.channel_addr_init[a]=this.flipflop_get(this.channel_addr_init[a],b,!0)};L.prototype.port_addr_read=function(a){A(this.channel_addr[a]);return this.flipflop_read(this.channel_addr[a])};L.prototype.port_pagehi_write=function(a,b){A(b);this.channel_pagehi[a]=b}; L.prototype.port_pagehi_read=function(a){return this.channel_pagehi[a]};L.prototype.port_page_write=function(a,b){A(b);this.channel_page[a]=b};L.prototype.port_page_read=function(a){return this.channel_page[a]};L.prototype.port_singlemask_write=function(a,b){this.update_mask((b&3)+a,b&4?1:0)};L.prototype.port_multimask_write=function(a,b){A(b);for(var c=0;4>c;c++)this.update_mask(a+c,b&1<a.byteLength)e(!0);else{var h=this.cpu;this.channel_addr[d]+=f;a.get(b,f,function(l){h.write_blob(l,g);e(!1)})}}; L.prototype.do_write=function(a,b,c,d,e){var f=this.channel_count[d]+1&65535,g=5<=d?2:1,h=f*g,l=this.address_get_8bit(d),m=!1,n=!1,p=this.channel_mode[d]&16;qa("to "+A(l)+" len "+A(h),16);ch&&(n=!0);b+h>a.byteLength?e(!0):(this.channel_addr[d]+=f,this.channel_count[d]-=f,!m&&p&&(this.channel_addr[d]=this.channel_addr_init[d],this.channel_count[d]=this.channel_count_init[d]),a.set(b,this.cpu.mem8.subarray(l,l+h),()=>{n&&p?this.do_write(a,b+h,c-h,d,e):e(!1)}))}; L.prototype.address_get_8bit=function(a){var b=this.channel_addr[a];5<=a&&(b<<=1);b=b&65535|this.channel_page[a]<<16;return b|=this.channel_pagehi[a]<<24};L.prototype.count_get_8bit=function(a){var b=this.channel_count[a]+1;5<=a&&(b*=2);return b};L.prototype.flipflop_get=function(a,b,c){c||(this.lsb_msb_flipflop^=1);return this.lsb_msb_flipflop?a&-256|b:a&-65281|b<<8};L.prototype.flipflop_read=function(a){return(this.lsb_msb_flipflop^=1)?a&255:a>>8&255};function ta(a,b){this.cpu=a;this.bus=b;this.counter_start_time=new Float64Array(3);this.counter_start_value=new Uint16Array(3);this.counter_next_low=new Uint8Array(4);this.counter_enabled=new Uint8Array(4);this.counter_mode=new Uint8Array(4);this.counter_read_mode=new Uint8Array(4);this.counter_latch=new Uint8Array(4);this.counter_latch_value=new Uint16Array(3);this.counter_reload=new Uint16Array(3);a.io.register_read(97,this,function(){var c=E.microtick(),d=66.66666666666667*c&1;c=this.did_rollover(2, c);return d<<4|c<<5});a.io.register_write(97,this,function(c){c&1?this.bus.send("pcspeaker-enable"):this.bus.send("pcspeaker-disable")});a.io.register_read(64,this,function(){return this.counter_read(0)});a.io.register_read(65,this,function(){return this.counter_read(1)});a.io.register_read(66,this,function(){return this.counter_read(2)});a.io.register_write(64,this,function(c){this.counter_write(0,c)});a.io.register_write(65,this,function(c){this.counter_write(1,c)});a.io.register_write(66,this, function(c){this.counter_write(2,c);this.bus.send("pcspeaker-update",[this.counter_mode[2],this.counter_reload[2]])});a.io.register_write(67,this,this.port43_write)}ta.prototype.get_state=function(){var a=[];a[0]=this.counter_next_low;a[1]=this.counter_enabled;a[2]=this.counter_mode;a[3]=this.counter_read_mode;a[4]=this.counter_latch;a[5]=this.counter_latch_value;a[6]=this.counter_reload;a[7]=this.counter_start_time;a[8]=this.counter_start_value;return a}; ta.prototype.set_state=function(a){this.counter_next_low=a[0];this.counter_enabled=a[1];this.counter_mode=a[2];this.counter_read_mode=a[3];this.counter_latch=a[4];this.counter_latch_value=a[5];this.counter_reload=a[6];this.counter_start_time=a[7];this.counter_start_value=a[8]}; ta.prototype.timer=function(a,b){var c=100;b||(this.counter_enabled[0]&&this.did_rollover(0,a)?(this.counter_start_value[0]=this.get_counter_value(0,a),this.counter_start_time[0]=a,this.cpu.device_lower_irq(0),this.cpu.device_raise_irq(0),0===this.counter_mode[0]&&(this.counter_enabled[0]=0)):this.cpu.device_lower_irq(0),this.counter_enabled[0]&&(c=(this.counter_start_value[0]-Math.floor(1193.1816666*(a-this.counter_start_time[0])))/1193.1816666));return c}; ta.prototype.get_counter_value=function(a,b){if(!this.counter_enabled[a])return 0;b=this.counter_start_value[a]-Math.floor(1193.1816666*(b-this.counter_start_time[a]));a=this.counter_reload[a];b>=a?b%=a:0>b&&(b=b%a+a);return b};ta.prototype.did_rollover=function(a,b){b-=this.counter_start_time[a];return 0>b?!0:this.counter_start_value[a]>8;b=this.counter_next_low[a];3===this.counter_mode[a]&&(this.counter_next_low[a]^=1);a=this.get_counter_value(a,E.microtick());return b?a&255:a>>8}; ta.prototype.counter_write=function(a,b){this.counter_reload[a]=this.counter_next_low[a]?this.counter_reload[a]&-256|b:this.counter_reload[a]&255|b<<8;3===this.counter_read_mode[a]&&this.counter_next_low[a]||(this.counter_reload[a]||(this.counter_reload[a]=65535),this.counter_start_value[a]=this.counter_reload[a],this.counter_enabled[a]=!0,this.counter_start_time[a]=E.microtick(),A(this.counter_reload[a]));3===this.counter_read_mode[a]&&(this.counter_next_low[a]^=1)}; ta.prototype.port43_write=function(a){var b=a>>1&7,c=a>>6&3;a=a>>4&3;3!==c&&(0===a?(this.counter_latch[c]=2,b=this.get_counter_value(c,E.microtick()),this.counter_latch_value[c]=b?b-1:0):(6<=b&&(b&=-5),this.counter_next_low[c]=1===a?0:1,0===c&&this.cpu.device_lower_irq(0),0!==b&&3!==b&&2!==b&&A(b),this.counter_mode[c]=b,this.counter_read_mode[c]=a,2===c&&this.bus.send("pcspeaker-update",[this.counter_mode[2],this.counter_reload[2]])))};ta.prototype.dump=function(){};const ua=Uint32Array.from([655360,655360,720896,753664]),va=Uint32Array.from([131072,65536,32768,32768]); function N(a,b,c,d,e){this.cpu=a;this.bus=b;this.screen=c;this.vga_memory_size=d;this.cursor_address=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=!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>>0;this.svga_memory=t.view(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= 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,f=>this.vga_memory_read(f),(f,g)=>this.vga_memory_write(f,g));e.use_graphical_text&&(this.graphical_text=new wa(this));a.devices.pci.register_device(this)} N.prototype.grab_text_content=function(a){var b=this.start_address<<1;const c=this.scan_line_to_screen_row(this.line_compare),d=Math.max(0,2*(2*this.offset_register-this.max_cols)),e=[];for(var f=0;f>2&3;a-=ua[b];if(0>a||a>=va[b])return A(a),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&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]}; N.prototype.vga_memory_write=function(a,b){if(this.svga_enabled)this.cpu.write8((a-655360|this.svga_bank_offset)+3758096384|0,b);else{var c=this.miscellaneous_graphics_register>>2&3;a-=ua[c];0>a||a>=va[c]?(A(a),A(b)):this.graphical_mode?this.vga_memory_write_graphical(a,b):this.plane_write_bm&3?this.vga_memory_write_text_mode(a,b):this.plane2[a]=b}}; N.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);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;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)};N.prototype.apply_feed=function(a){return a|a<<8|a<<16|a<<24}; N.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};N.prototype.apply_rotate=function(a){return(a|a<<8)>>>(this.planar_rotate_reg&7)&255};N.prototype.apply_setreset=function(a,b){var c=this.apply_expand(this.planar_setreset);return(a|b&c)&(~b|c)};N.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};N.prototype.apply_bitmask=function(a,b){return b&a|~b&this.latch_dword}; N.prototype.text_mode_redraw=function(){if(!this.graphical_text){var 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=c?7:15,e=this.start_address<<1;for(let f=0;f>4&d]],this.vga256_palette[this.dac_mask& this.dac_map[l&15]]);e+=2}e+=b}}}; N.prototype.vga_memory_write_text_mode=function(a,b){this.vga_memory[a]=b;var c=Math.max(this.max_cols,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;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;f=f?7:15;this.bus.send("screen-put-char",[d,c,b]);this.graphical_text?this.graphical_text.invalidate_row(d): 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&15]])}}; N.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);this.graphical_text?this.graphical_text.set_cursor_pos(b,a):this.screen.update_cursor(b,a)}; N.prototype.complete_redraw=function(){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()};N.prototype.complete_replot=function(){this.graphical_mode&&!this.svga_enabled&&(this.diff_plot_min=0,this.diff_plot_max=524288,this.complete_redraw())};N.prototype.partial_redraw=function(a,b){athis.diff_addr_max&&(this.diff_addr_max=b)}; N.prototype.partial_replot=function(a,b){athis.diff_plot_max&&(this.diff_plot_max=b);this.partial_redraw(a,b)};N.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};N.prototype.destroy=function(){};N.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}; N.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}; N.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*this.virtual_width+c+(this.start_address<>>=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};N.prototype.set_size_text=function(a,b){this.max_cols=a;this.max_rows=b;this.bus.send("screen-set-size",[a,b,0]);this.graphical_text?this.graphical_text.set_size(b,a):this.screen.set_size_text(a,b)}; N.prototype.set_size_graphical=function(a,b,c,d,e){c=Math.max(c,1);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",[a,b,e])}}; N.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;this.attribute_mode&64&&(a>>>=1,c>>>=1);b=this.scan_line_to_screen_row(b);var d=va[0];const e=this.vga_bytes_per_line();this.set_size_graphical(a,b,c,e?Math.ceil(d/e):b,8);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)}}; N.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>>>=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;ethis.attribute_controller_index)A(this.attribute_controller_index),A(a),this.dac_map[this.attribute_controller_index]=a,this.attribute_mode&64||this.complete_redraw();else switch(this.attribute_controller_index){case 16:A(a);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||!!this.graphical_text));(b^a)&64&&this.complete_replot();this.update_vga_size();this.complete_redraw()}break;case 18:A(a);this.color_plane_enable!==a&&(this.color_plane_enable=a,this.complete_redraw());break;case 19:A(a);this.horizontal_panning!==a&&(this.horizontal_panning=a&15,this.update_layers());break;case 20:A(a);this.color_select!== a&&(this.color_select=a,this.complete_redraw());break;default:A(this.attribute_controller_index),A(a)}this.attribute_controller_index=-1}};N.prototype.port3C0_read=function(){return(this.attribute_controller_index|this.palette_source)&255};N.prototype.port3C0_read16=function(){return this.port3C0_read()|this.port3C1_read()<<8&65280}; N.prototype.port3C1_read=function(){if(16>this.attribute_controller_index)return A(this.attribute_controller_index),A(this.dac_map[this.attribute_controller_index]),this.dac_map[this.attribute_controller_index]&255;switch(this.attribute_controller_index){case 16:return A(this.attribute_mode),this.attribute_mode;case 18:return A(this.color_plane_enable),this.color_plane_enable;case 19:return A(this.horizontal_panning),this.horizontal_panning;case 20:return A(this.color_select),this.color_select;default:A(this.attribute_controller_index)}return 255}; N.prototype.port3C2_write=function(a){A(a);this.miscellaneous_output_register=a};N.prototype.port3C4_write=function(a){this.sequencer_index=a};N.prototype.port3C4_read=function(){return this.sequencer_index}; N.prototype.port3C5_write=function(a){switch(this.sequencer_index){case 1:A(a);var b=this.clocking_mode;this.clocking_mode=a;(b^a)&32&&this.update_layers();break;case 2:A(a);b=this.plane_write_bm;this.plane_write_bm=a;this.graphical_text&&15!==b&&b&4&&!(this.plane_write_bm&4)&&this.graphical_text.invalidate_font_shape();break;case 3:A(a);b=this.character_map_select;this.character_map_select=a;this.graphical_text&&b!==this.character_map_select&&this.graphical_text.set_character_map(this.character_map_select); break;case 4:A(a);this.sequencer_memory_mode=a;break;default:A(this.sequencer_index),A(a)}};N.prototype.port3C5_read=function(){A(this.sequencer_index);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};N.prototype.port3C6_write=function(a){this.dac_mask=a};N.prototype.port3C6_read=function(){return this.dac_mask}; N.prototype.port3C7_write=function(a){A(a);this.dac_color_index_read=3*a;this.dac_state&=0};N.prototype.port3C7_read=function(){return this.dac_state};N.prototype.port3C8_write=function(a){this.dac_color_index_write=3*a;this.dac_state|=3};N.prototype.port3C8_read=function(){return this.dac_color_index_write/3&255}; N.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,A(b),A(d));this.vga256_palette[b]!==d&&(this.vga256_palette[b]=d,this.complete_redraw());this.dac_color_index_write++}; N.prototype.port3C9_read=function(){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};N.prototype.port3CC_read=function(){return this.miscellaneous_output_register};N.prototype.port3CE_write=function(a){this.graphics_index=a};N.prototype.port3CE_read=function(){return this.graphics_index}; N.prototype.port3CF_write=function(a){switch(this.graphics_index){case 0:this.planar_setreset=a;A(a);break;case 1:this.planar_setreset_enable=a;A(a);break;case 2:this.color_compare=a;A(a);break;case 3:this.planar_rotate_reg=a;A(a);break;case 4:this.plane_read=a;A(a);break;case 5:var b=this.planar_mode;this.planar_mode=a;A(a);(b^a)&96&&this.complete_replot();break;case 6:A(a);this.miscellaneous_graphics_register!==a&&(this.miscellaneous_graphics_register=a,this.update_vga_size());break;case 7:this.color_dont_care= a;A(a);break;case 8:this.planar_bitmap=a;A(a);break;default:A(this.graphics_index),A(a)}};N.prototype.port3CF_read=function(){A(this.graphics_index);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}; N.prototype.port3D4_write=function(a){this.index_crtc=a};N.prototype.port3D4_write16=function(a){this.port3D4_write(a&255);this.port3D5_write(a>>8&255)};N.prototype.port3D4_read=function(){return this.index_crtc}; N.prototype.port3D5_write=function(a){switch(this.index_crtc){case 1:A(a);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:A(a);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:A(a);this.preset_row_scan=a;this.update_layers();break;case 9:A(a);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();break;case 10:A(a);this.cursor_scanline_start=a;this.update_cursor_scanline();break;case 11:A(a);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());A(a);A(this.start_address,4);break;case 13:(this.start_address&255)!==a&&(this.start_address= this.start_address&65280|a,this.update_layers(),~this.crtc_mode&3&&this.complete_replot());A(a);A(this.start_address,4);break;case 14:A(a);this.cursor_address=this.cursor_address&255|a<<8;this.update_cursor();break;case 15:A(a);this.cursor_address=this.cursor_address&65280|a;this.update_cursor();break;case 18:A(a);(this.vertical_display_enable_end&255)!==a&&(this.vertical_display_enable_end=this.vertical_display_enable_end&768|a,this.update_vga_size());break;case 19:A(a);this.offset_register!==a&& (this.offset_register=a,this.update_vga_size(),~this.crtc_mode&3&&this.complete_replot());break;case 20:A(a);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());break;case 21:A(a);(this.vertical_blank_start&255)!==a&&(this.vertical_blank_start=this.vertical_blank_start&768|a,this.update_vga_size());break;case 23:A(a);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:A(a);this.line_compare=this.line_compare&768|a;this.update_layers();break;default:this.index_crtc>7&2|this.vertical_blank_start>>5&8|this.line_compare>>4&16|this.vertical_display_enable_end>>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;case 24:return this.line_compare&255}return this.index_crtc=a?this.svga_version=a:A(a);break;case 1:this.svga_width=a;2560>>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:A(this.dispi_index)}return 255}; N.prototype.vga_replot=function(){for(var a=this.diff_plot_min&-16,b=Math.min(this.diff_plot_max|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 h=a/this.virtual_width|0,l=a-this.virtual_width*h;switch(d){case 1:g=(h&1)<<13;h>>>=1;break;case 2:g=(h&1)<<14;h>>>=1;break;case 3:g=(h&3)<<13,h>>>=2}g|=(h*this.virtual_width+l>>>c)+this.start_address}h=this.plane0[g];l=this.plane1[g];var m=this.plane2[g],n=this.plane3[g]; g=new Uint8Array(8);switch(e){case 0:h<<=0;l<<=1;m<<=2;n<<=3;for(var p=7;0<=p;p--)g[7-p]=h>>p&1|l>>p&2|m>>p&4|n>>p&8;break;case 32:g[0]=h>>6&3|m>>4&12;g[1]=h>>4&3|m>>2&12;g[2]=h>>2&3|m>>0&12;g[3]=h>>0&3|m<<2&12;g[4]=l>>6&3|n>>4&12;g[5]=l>>4&3|n>>2&12;g[6]=l>>2&3|n>>0&12;g[7]=l>>0&3|n<<2&12;break;case 64:case 96:g[0]=h>>4&15,g[1]=h>>0&15,g[2]=l>>4&15,g[3]=l>>0&15,g[4]=m>>4&15,g[5]=m>>0&15,g[6]=n>>4&15,g[7]=n>>0&15}if(f)for(h=p=0;4>p;p++,a++,h+=2)this.pixel_buffer[a]=g[h]<<4|g[h+1];else for(p=0;8>p;p++, a++)this.pixel_buffer[a]=g[p]}}; N.prototype.vga_redraw=function(){var a=this.diff_addr_min,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],c[a]=f&65280|f<<16|f>>16|4278190080}; N.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,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>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|0)+1;am;++m)for(let n=0;256>n;++n,l+=g)for(let p=0;p>=1)b(q&r?1:0);a&&b(d&&192<=n&&223>=n&&q&1?1:0)}return f};wa.prototype.resize_canvas=function(){this.txt_dirty=1;this.txt_row_dirty.fill(1)}; wa.prototype.rebuild_image_data=function(){const a=this.gfx_width*this.gfx_height*4,b=new Uint8ClampedArray(a);for(let c=3;cF;++F)u[F]=a.vga256_palette[a.dac_mask&a.dac_map[F]]; F=2*c;const w=Math.max(0,2*(2*a.offset_register-c)),K=4*this.font_width,V=4*this.gfx_width,Ka=V*this.font_height,bb=4*(this.font_width-this.font_height*this.gfx_width),na=4*(this.gfx_width-this.font_width),C=4*(this.cursor_row*this.gfx_width*this.font_height+this.cursor_col*this.font_width);let x,M,O=0,U=0,Y=0,ka=0,Ga=0,Ha=0,W,La,mb;a=a.start_address<<1;for(La=0;La> 4&p];Aa=u[Aa&15];M!==ia&&(M=ia,ka=M>>16,Ga=M>>8&255,Ha=M&255);x!==Aa&&(x=Aa,O=x>>16,U=x>>8&255,Y=x&255);ia=q&&C===W;Aa=(Va+Ua)*h;for(Ua=W+Ka;Wa&&0b&&(this.txt_width=b,this.txt_height=a,this.gfx_width=this.txt_width*this.font_width,this.gfx_height=this.txt_height*this.font_height,this.txt_row_dirty=new Uint8Array(this.txt_height),this.vga.screen.set_size_graphical(this.gfx_width,this.gfx_height,this.gfx_width,this.gfx_height),this.mark_dirty(),this.rebuild_image_data())}; wa.prototype.set_character_map=function(a){const b=[0,2,4,6,1,3,5,7],c=b[(a&12)>>2|(a&32)>>3];a=b[a&3|(a&16)>>2];if(this.font_index_A!==c||this.font_index_B!==a)this.font_index_A=c,this.font_index_B=a,this.mark_dirty()};wa.prototype.set_cursor_pos=function(a,b){this.cursor_pos_dirty=!0;this.cursor_row_latch=a;this.cursor_col_latch=b};wa.prototype.set_cursor_attr=function(a,b,c){this.cursor_attr_dirty=!0;this.cursor_enabled_latch=!!c;this.cursor_top_latch=a;this.cursor_bottom_latch=b}; wa.prototype.render=function(){this.frame_count=this.frame_count+1>>>0;const a=this.vga.clocking_mode&9,b=this.vga.attribute_mode&12,c=this.vga.max_scan_line&159;if(this.font_data_dirty||this.vga_clocking_mode!==a||this.vga_attribute_mode!==b||this.vga_max_scan_line!==c){const d=!(a&1),e=!!(a&8),f=(d?9:8)*(e?2:1),g=!!(b&4),h=(c&31)+1,l=this.font_data_dirty||this.font_lge!==g,m=this.font_width!==f||this.font_height!==h;this.font_data_dirty=!1;this.font_width=f;this.font_height=h;this.font_blink_enabled= !!(b&8);this.font_lge=g;this.vga_clocking_mode=a;this.vga_attribute_mode=b;this.vga_max_scan_line=c;if(l||m)m&&(this.gfx_width=this.txt_width*this.font_width,this.gfx_height=this.txt_height*this.font_height,this.rebuild_image_data()),this.font_bitmap=this.rebuild_font_bitmap(d,e);this.mark_dirty()}this.cursor_pos_dirty&&(this.cursor_pos_dirty=!1,this.cursor_row_latch=Math.min(this.cursor_row_latch,this.txt_height-1),this.cursor_col_latch=Math.min(this.cursor_col_latch,this.txt_width-1),this.cursor_row!== this.cursor_row_latch||this.cursor_col!==this.cursor_col_latch)&&(this.txt_row_dirty[this.cursor_row]=this.txt_row_dirty[this.cursor_row_latch]=this.txt_dirty=1,this.cursor_row=this.cursor_row_latch,this.cursor_col=this.cursor_col_latch);this.cursor_attr_dirty&&(this.cursor_attr_dirty=!1,this.cursor_enabled!==this.cursor_enabled_latch||this.cursor_top!==this.cursor_top_latch||this.cursor_bottom!==this.cursor_bottom_latch)&&(this.cursor_enabled=this.cursor_enabled_latch,this.cursor_top=this.cursor_top_latch, this.cursor_bottom=this.cursor_bottom_latch,this.txt_row_dirty[this.cursor_row]=this.txt_dirty=1);this.txt_dirty&&(this.render_dirty_rows(),this.txt_dirty=0,this.txt_row_dirty.fill(0));return this.image_data};function xa(a,b){this.cpu=a;this.bus=b;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 ja(1024);this.last_port60_byte=0;this.sample_rate=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 ja(1024);this.next_byte_is_aux=this.next_byte_is_ready=!1;this.bus.register("keyboard-code",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);this.command_register=5;this.controller_output_port=0;this.read_controller_output_port=this.read_command_register=this.read_output_register=!1;a.io.register_read(96,this,this.port60_read);a.io.register_read(100,this,this.port64_read);a.io.register_write(96,this,this.port60_write);a.io.register_write(100,this,this.port64_write)} xa.prototype.get_state=function(){var a=[];a[0]=this.enable_mouse_stream;a[1]=this.use_mouse;a[2]=this.have_mouse;a[3]=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;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}; xa.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=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",this.use_mouse)}; xa.prototype.raise_irq=function(){this.next_byte_is_ready||(this.kbd_buffer.length?this.kbd_irq():this.mouse_buffer.length&&this.mouse_irq())};xa.prototype.mouse_irq=function(){this.next_byte_is_aux=this.next_byte_is_ready=!0;this.command_register&2&&(this.cpu.device_lower_irq(12),this.cpu.device_raise_irq(12))};xa.prototype.kbd_irq=function(){this.next_byte_is_ready=!0;this.next_byte_is_aux=!1;this.command_register&1&&(this.cpu.device_lower_irq(1),this.cpu.device_raise_irq(1))}; xa.prototype.kbd_send_code=function(a){this.enable_keyboard_stream&&(A(a),this.kbd_buffer.push(a),this.raise_irq())};xa.prototype.mouse_send_delta=function(a,b){if(this.have_mouse&&this.use_mouse){var c=this.resolution*this.sample_rate/80;this.mouse_delta_x+=a*c;this.mouse_delta_y+=b*c;this.enable_mouse_stream&&(a=this.mouse_delta_x|0,b=this.mouse_delta_y|0,a||b)&&(Date.now(),this.mouse_delta_x-=a,this.mouse_delta_y-=b,this.send_mouse_packet(a,b))}}; xa.prototype.mouse_send_click=function(a,b,c){this.have_mouse&&this.use_mouse&&(this.mouse_clicks=a|c<<1|b<<2,this.enable_mouse_stream&&this.send_mouse_packet(0,0))}; xa.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()}; xa.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}}; xa.prototype.port60_read=function(){this.next_byte_is_ready=!1;if(!this.kbd_buffer.length&&!this.mouse_buffer.length)return this.last_port60_byte;this.next_byte_is_aux?(this.cpu.device_lower_irq(12),this.last_port60_byte=this.mouse_buffer.shift()):(this.cpu.device_lower_irq(1),this.last_port60_byte=this.kbd_buffer.shift());A(this.last_port60_byte);(this.kbd_buffer.length||this.mouse_buffer.length)&&this.raise_irq();return this.last_port60_byte}; xa.prototype.port64_read=function(){var a=16;this.next_byte_is_ready&&(a|=1);this.next_byte_is_aux&&(a|=32);A(a);return a}; xa.prototype.port60_write=function(a){A(a);if(this.read_command_register)this.command_register=a,this.read_command_register=!1,A(this.command_register);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=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}A(a);A(this.mouse_id);this.sample_rate||(this.sample_rate=100);this.mouse_irq()}else if(this.next_read_resolution)this.next_read_resolution=!1,this.mouse_buffer.clear(),this.mouse_buffer.push(250), this.resolution=3>7});a.io.register_write(113,this,this.cmos_port_write);a.io.register_read(113,this,this.cmos_port_read)} ya.prototype.get_state=function(){var a=[];a[0]=this.cmos_index;a[1]=this.cmos_data;a[2]=this.rtc_time;a[3]=this.last_update;a[4]=this.next_interrupt;a[5]=this.next_interrupt_alarm;a[6]=this.periodic_interrupt;a[7]=this.periodic_interrupt_time;a[8]=this.cmos_a;a[9]=this.cmos_b;a[10]=this.cmos_c;a[11]=this.nmi_disabled;return a}; ya.prototype.set_state=function(a){this.cmos_index=a[0];this.cmos_data=a[1];this.rtc_time=a[2];this.last_update=a[3];this.next_interrupt=a[4];this.next_interrupt_alarm=a[5];this.periodic_interrupt=a[6];this.periodic_interrupt_time=a[7];this.cmos_a=a[8];this.cmos_b=a[9];this.cmos_c=a[10];this.nmi_disabled=a[11]}; ya.prototype.timer=function(a){a=Date.now();this.rtc_time+=a-this.last_update;this.last_update=a;this.periodic_interrupt&&this.next_interrupt>4&15)};ya.prototype.encode_time=function(a){return this.cmos_b&4?a:this.bcd_pack(a)};ya.prototype.decode_time=function(a){return this.cmos_b&4?a:this.bcd_unpack(a)}; ya.prototype.cmos_port_read=function(){var a=this.cmos_index;switch(a){case 0:return A(this.encode_time((new Date(this.rtc_time)).getUTCSeconds())),this.encode_time((new Date(this.rtc_time)).getUTCSeconds());case 2:return A(this.encode_time((new Date(this.rtc_time)).getUTCMinutes())),this.encode_time((new Date(this.rtc_time)).getUTCMinutes());case 4:return A(this.encode_time((new Date(this.rtc_time)).getUTCHours())),this.encode_time((new Date(this.rtc_time)).getUTCHours());case 6:return A(this.encode_time((new Date(this.rtc_time)).getUTCDay()+ 1)),this.encode_time((new Date(this.rtc_time)).getUTCDay()+1);case 7:return A(this.encode_time((new Date(this.rtc_time)).getUTCDate())),this.encode_time((new Date(this.rtc_time)).getUTCDate());case 8:return A(this.encode_time((new Date(this.rtc_time)).getUTCMonth()+1)),this.encode_time((new Date(this.rtc_time)).getUTCMonth()+1);case 9:return A(this.encode_time((new Date(this.rtc_time)).getUTCFullYear()%100)),this.encode_time((new Date(this.rtc_time)).getUTCFullYear()%100);case 10:return 999<=E.microtick()% 1E3?this.cmos_a|128:this.cmos_a;case 11:return this.cmos_b;case 12:return this.cpu.device_lower_irq(8),a=this.cmos_c,this.cmos_c&=-241,a;case 13:return 0;case 50:case 55:return A(this.encode_time((new Date(this.rtc_time)).getUTCFullYear()/100|0)),this.encode_time((new Date(this.rtc_time)).getUTCFullYear()/100|0);default:return A(a),this.cmos_data[this.cmos_index]}}; ya.prototype.cmos_port_write=function(a){switch(this.cmos_index){case 10:this.cmos_a=a&127;this.periodic_interrupt_time=1E3/(32768>>(this.cmos_a&15)-1);A(this.cmos_a,2);break;case 11:this.cmos_b=a;this.cmos_b&64&&(this.next_interrupt=Date.now());if(this.cmos_b&32){a=new Date;const b=this.decode_time(this.cmos_data[1]),c=this.decode_time(this.cmos_data[3]),d=this.decode_time(this.cmos_data[5]);this.next_interrupt_alarm=+new Date(Date.UTC(a.getUTCFullYear(),a.getUTCMonth(),a.getUTCDate(),d,c,b))}A(this.cmos_b, 2);break;case 1:case 3:case 5:this.cmos_write(this.cmos_index,a);break;default:A(this.cmos_index),A(a)}this.periodic_interrupt=64===(this.cmos_b&64)&&0<(this.cmos_a&15)};ya.prototype.cmos_read=function(a){return this.cmos_data[a]};ya.prototype.cmos_write=function(a,b){A(a);A(b);this.cmos_data[a]=b};function za(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=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:qa("Invalid serial port: "+A(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"+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?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,A(this.baud_rate)):(0===(this.ier&2)&&d&2&&this.ThrowInterrupt(2), this.ier=d&15,A(d),this.CheckInterrupt())});a.register_read(b,this,function(){if(this.line_control&128)return this.baud_rate&255;let d=0;0!==this.input.length&&(d=this.input.shift(),A(d));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;A(this.iir);2===this.iir&&this.ClearInterrupt(2);this.fifo_control& 1&&(d|=192);return d});a.register_write(b|2,this,function(d){A(d);this.fifo_control=d});a.register_read(b|3,this,function(){A(this.line_control);return this.line_control});a.register_write(b|3,this,function(d){A(d);this.line_control=d});a.register_read(b|4,this,function(){return this.modem_control});a.register_write(b|4,this,function(d){A(d);this.modem_control=d});a.register_read(b|5,this,function(){A(this.lsr);return this.lsr});a.register_write(b|5,this,function(){});a.register_read(b|6,this,function(){A(this.modem_status); return this.modem_status&=240});a.register_write(b|6,this,function(d){A(d);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})}za.prototype.get_state=function(){var a=[];a[0]=this.ints;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}; za.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]}; za.prototype.CheckInterrupt=function(){this.ints&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))};za.prototype.ThrowInterrupt=function(a){this.ints|=1<>4;this.modem_status=a;this.modem_status=this.modem_status|c|b};function Ba(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(E.microtick());this.gpe=new Uint8Array(4);b.register_read(45056,this,void 0,function(){return this.pm1_status}); b.register_write(45056,this,void 0,function(c){A(c,4);this.pm1_status&=~c});b.register_read(45058,this,void 0,function(){return this.pm1_enable});b.register_write(45058,this,void 0,function(c){A(c);this.pm1_enable=c});b.register_read(45060,this,void 0,function(){return this.status});b.register_write(45060,this,void 0,function(c){A(c);this.status=c});b.register_read(45064,this,void 0,void 0,function(){return this.get_timer(E.microtick())&16777215});b.register_read(45024,this,function(){return this.gpe[0]}); b.register_read(45025,this,function(){return this.gpe[1]});b.register_read(45026,this,function(){return this.gpe[2]});b.register_read(45027,this,function(){return this.gpe[3]});b.register_write(45024,this,function(c){A(c);this.gpe[0]=c});b.register_write(45025,this,function(c){A(c);this.gpe[1]=c});b.register_write(45026,this,function(c){A(c);this.gpe[2]=c});b.register_write(45027,this,function(c){A(c);this.gpe[3]=c})} Ba.prototype.timer=function(a){a=this.get_timer(a);var b=0!==((a^this.last_timer)&8388608);this.pm1_enable&1&&b?(this.pm1_status|=1,this.cpu.device_raise_irq(9)):this.cpu.device_lower_irq(9);this.last_timer=a;return 100}; Ba.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++:this.timer_last_value+this.timer_imprecision_offset<=a&&(this.timer_imprecision_offset=0,this.timer_last_value=a);return this.timer_last_value+this.timer_imprecision_offset};Ba.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}; Ba.prototype.set_state=function(a){this.status=a[0];this.pm1_status=a[1];this.pm1_enable=a[2];this.gpe=a[3]};function Ca(a){this.cpu=a;this.timer_divider=this.apic_id=0;this.timer_divider_shift=1;this.timer_current_count=this.timer_initial_count=0;this.next_tick=E.microtick();this.lvt_error=this.lvt_int1=this.lvt_int0=this.lvt_perf_counter=this.lvt_timer=65536;this.icr1=this.icr0=this.tpr=0;this.irr=new Int32Array(8);this.isr=new Int32Array(8);this.tmr=new Int32Array(8);this.spurious_vector=254;this.destination_format=-1;this.read_error=this.error=this.local_destination=0;a.io.mmap_register(4276092928,1048576, b=>{A(b>>>0);var c=b&3;return this.read32(b&-4)>>8*c&255},(b,c)=>{A(b);A(c)},b=>this.read32(b),(b,c)=>this.write32(b,c))} Ca.prototype.read32=function(a){a=a-4276092928|0;switch(a){case 32:return this.apic_id;case 48:return 327700;case 128:return this.tpr;case 208:return this.local_destination;case 224:return this.destination_format;case 240:return this.spurious_vector;case 256:case 272:case 288:case 304:case 320:case 336:case 352:case 368:return a=a-256>>4,A(this.isr[a]>>>0,8),this.isr[a];case 384:case 400:case 416:case 432:case 448:case 464:case 480:case 496:return a=a-384>>4,A(this.tmr[a]>>>0,8),this.tmr[a];case 512:case 528:case 544:case 560:case 576:case 592:case 608:case 624:return a= a-512>>4,A(this.irr[a]>>>0,8),this.irr[a];case 640:return A(this.read_error>>>0,8),this.read_error;case 768:return this.icr0;case 784:return this.icr1;case 800:return this.lvt_timer;case 832:return this.lvt_perf_counter;case 848:return this.lvt_int0;case 864:return this.lvt_int1;case 880:return this.lvt_error;case 992:return this.timer_divider;case 896:return this.timer_initial_count;case 912:return A(this.timer_current_count>>>0,8),this.timer_current_count;default:return A(a),0}}; Ca.prototype.write32=function(a,b){a=a-4276092928|0;switch(a){case 32:A(b>>>8,8);this.apic_id=b;break;case 48:A(b>>>0,8);break;case 128:this.tpr=b&255;this.check_vector();break;case 176:b=this.highest_isr();-1!==b&&(this.register_clear_bit(this.isr,b),this.register_get_bit(this.tmr,b)&&this.cpu.devices.ioapic.remote_eoi(b),this.check_vector());break;case 208:A(b>>>0,8);this.local_destination=b&4278190080;break;case 224:A(b>>>0,8);this.destination_format=b|16777215;break;case 240:A(b>>>0,8);this.spurious_vector= b;break;case 640:A(b>>>0,8);this.read_error=this.error;this.error=0;break;case 768:a=b&255;var c=b>>8&7,d=b>>11&1,e=b>>15&1,f=b>>18&3,g=this.icr1>>>24;A(b,8);A(a,2);this.icr0=b&-4097;0===f?this.route(a,c,e,g,d):1===f?this.deliver(a,0,e):2===f&&this.deliver(a,c,e);break;case 784:A(b>>>0,8);this.icr1=b;break;case 800:A(b>>>0,8);this.lvt_timer=b;break;case 832:A(b>>>0,8);this.lvt_perf_counter=b;break;case 848:A(b>>>0,8);this.lvt_int0=b;break;case 864:A(b>>>0,8);this.lvt_int1=b;break;case 880:A(b>>>0, 8);this.lvt_error=b;break;case 992:A(b>>>0,8);this.timer_divider=b;b=b&3|(b&8)>>1;this.timer_divider_shift=7===b?0:b+1;break;case 896:A(b>>>0,8);this.timer_initial_count=b>>>0;this.timer_current_count=b>>>0;this.next_tick=E.microtick();this.timer_active=!0;break;case 912:A(b>>>0,8);break;default:A(a),A(b>>>0,8)}}; Ca.prototype.timer=function(a){if(0===this.timer_current_count)return 100;const b=1E6/(1<>>0;this.next_tick+=a/b;this.timer_current_count-=a;0>=this.timer_current_count&&(a=this.lvt_timer&393216,131072===a?(this.timer_current_count%=this.timer_initial_count,0>=this.timer_current_count&&(this.timer_current_count+=this.timer_initial_count),0===(this.lvt_timer&65536)&&this.deliver(this.lvt_timer&255,0,!1)):0===a&&(this.timer_current_count=0,0===(this.lvt_timer& 65536)&&this.deliver(this.lvt_timer&255,0,!1)));return Math.max(0,this.timer_current_count/b)};Ca.prototype.route=function(a,b,c){this.deliver(a,b,c)};Ca.prototype.deliver=function(a,b,c){5!==b&&4!==b&&(this.register_get_bit(this.irr,a)?A(a,2):(this.register_set_bit(this.irr,a),c?this.register_set_bit(this.tmr,a):this.register_clear_bit(this.tmr,a),this.check_vector()))};Ca.prototype.highest_irr=function(){return this.register_get_highest_bit(this.irr)};Ca.prototype.highest_isr=function(){return this.register_get_highest_bit(this.isr)}; Ca.prototype.check_vector=function(){var a=this.highest_irr();-1!==a&&(this.highest_isr()>=a||(a&240)<=(this.tpr&240)||this.cpu.handle_irqs())};Ca.prototype.acknowledge_irq=function(){var a=this.highest_irr();if(-1===a||this.highest_isr()>=a||(a&240)<=(this.tpr&240))return-1;this.register_clear_bit(this.irr,a);this.register_set_bit(this.isr,a);this.check_vector();return a}; Ca.prototype.get_state=function(){var a=[];a[0]=this.apic_id;a[1]=this.timer_divider;a[2]=this.timer_divider_shift;a[3]=this.timer_initial_count;a[4]=this.timer_current_count;a[5]=this.next_tick;a[6]=this.lvt_timer;a[7]=this.lvt_perf_counter;a[8]=this.lvt_int0;a[9]=this.lvt_int1;a[10]=this.lvt_error;a[11]=this.tpr;a[12]=this.icr0;a[13]=this.icr1;a[14]=this.irr;a[15]=this.isr;a[16]=this.tmr;a[17]=this.spurious_vector;a[18]=this.destination_format;a[19]=this.local_destination;a[20]=this.error;a[21]= this.read_error;return a}; Ca.prototype.set_state=function(a){this.apic_id=a[0];this.timer_divider=a[1];this.timer_divider_shift=a[2];this.timer_initial_count=a[3];this.timer_current_count=a[4];this.next_tick=a[5];this.lvt_timer=a[6];this.lvt_perf_counter=a[7];this.lvt_int0=a[8];this.lvt_int1=a[9];this.lvt_error=a[10];this.tpr=a[11];this.icr0=a[12];this.icr1=a[13];this.irr=a[14];this.isr=a[15];this.tmr=a[16];this.spurious_vector=a[17];this.destination_format=a[18];this.local_destination=a[19];this.error=a[20];this.read_error= a[21]};Ca.prototype.register_get_bit=function(a,b){return a[b>>5]>>(b&31)&1};Ca.prototype.register_set_bit=function(a,b){a[b>>5]|=1<<(b&31)};Ca.prototype.register_clear_bit=function(a,b){a[b>>5]&=~(1<<(b&31))};Ca.prototype.register_get_highest_bit=function(a){for(var b=7;0<=b;b--){var c=a[b];if(c)return t.int_log2(c>>>0)|b<<5}return-1};function Da(a){this.cpu=a;this.ioredtbl_config=new Int32Array(24);this.ioredtbl_destination=new Int32Array(24);for(var b=0;b{c=c-4273995776|0;if(16<=c&&20>c)return c-=16,A(this.ioregsel),this.read(this.ioregsel)>>8*c&255;A(c>>>0);return 0},c=>{A(c>>>0)},c=>{c=c-4273995776|0;if(0===c)return this.ioregsel;if(16===c)return this.read(this.ioregsel); A(c>>>0);return 0},(c,d)=>{c=c-4273995776|0;0===c?this.ioregsel=d:16===c?this.write(this.ioregsel,d):(A(c>>>0),A(d>>>0,8))})}Da.prototype.remote_eoi=function(a){for(var b=0;24>b;b++){var c=this.ioredtbl_config[b];(c&255)===a&&c&16384&&(A(b),this.ioredtbl_config[b]&=-16385,this.check_irq(b))}}; Da.prototype.check_irq=function(a){var b=1<>8&7,e=this.ioredtbl_destination[a]>>>24;if(0===(c&32768))this.irr&=~b;else if(this.ioredtbl_config[a]|=16384,c&16384)return;0!==d&&1!==d||this.cpu.devices.apic.route(c&255,d,32768===(c&32768),e,c>>11&1);this.ioredtbl_config[a]&=-4097}}}; Da.prototype.set_irq=function(a){if(!(24<=a)){var b=1<a){var b=a-16>>1;a=a&1?this.ioredtbl_destination[b]:this.ioredtbl_config[b];A(b);A(a,8);return a}A(a);return 0}; Da.prototype.write=function(a,b){if(0===a)this.ioapic_id=b>>>24&15;else if(1!==a&&2!==a)if(16<=a&&64>a){var c=a-16>>1;a&1?(this.ioredtbl_destination[c]=b&4278190080,A(b>>>0,8),A(c),A(b>>>24,2)):(this.ioredtbl_config[c]=b&110591|this.ioredtbl_config[c]&-110592,a=b&255,A(b>>>0,8),A(c),A(a,2),this.check_irq(c))}else A(a),A(b>>>0,8)}; Da.prototype.get_state=function(){var a=[];a[0]=this.ioredtbl_config;a[1]=this.ioredtbl_destination;a[2]=this.ioregsel;a[3]=this.ioapic_id;a[4]=this.irr;a[5]=this.irq_value;return a};Da.prototype.set_state=function(a){this.ioredtbl_config=a[0];this.ioredtbl_destination=a[1];this.ioregsel=a[2];this.ioapic_id=a[3];this.irr=a[4];this.irq_value=a[5]};function Ea(a){this.message=a}Ea.prototype=Error();const Fa={Uint8Array,Int8Array,Uint16Array,Int16Array,Uint32Array,Int32Array,Float32Array,Float64Array}; function Ia(a,b){if("object"!==typeof a||null===a)return a;if(a instanceof Array)return a.map(e=>Ia(e,b));a.constructor===Object&&console.log(a);if(a.BYTES_PER_ELEMENT){var c=new Uint8Array(a.buffer,a.byteOffset,a.length*a.BYTES_PER_ELEMENT);return{__state_type__:a.constructor.name.replace("bound ",""),buffer_id:b.push(c)-1}}a=a.get_state();c=[];for(var d=0;dr)throw new Ea("Invalid length: "+r);p=new Int32Array(p.buffer,p.byteOffset,4);if(-2039052682!==p[0])throw new Ea("Invalid header: "+A(p[0]>>>0));if(6!==p[1])throw new Ea("Version mismatch: dump="+p[1]+" we=6");if(q&&p[2]!==r)throw new Ea("Length doesn't match header: real="+r+" header="+p[2]);return p[3]}function c(p){p=(new TextDecoder).decode(p);return JSON.parse(p)}a=new Uint8Array(a);if(4247762216===(new Uint32Array(a.buffer, 0,1))[0]){var d=this.zstd_create_ctx(a.length);(new Uint8Array(this.wasm_memory.buffer,this.zstd_get_src_ptr(d),a.length)).set(a);var e=this.zstd_read(d,16),f=new Uint8Array(this.wasm_memory.buffer,e,16),g=b(f,!1);this.zstd_read_free(e,16);e=this.zstd_read(d,g);f=new Uint8Array(this.wasm_memory.buffer,e,g);f=c(f);this.zstd_read_free(e,g);e=f.state;var h=f.buffer_infos;f=[];g=16+g;for(var l of h){h=(g+3&-4)-g;if(1048576d||d+12>=a.length)throw new Ea("Invalid info block length: "+d);l=a.subarray(16,16+d);e=c(l);l=e.state;e= e.buffer_infos;let p=16+d;p=p+3&-4;d=e.map(q=>{const r=p+q.offset;return a.buffer.slice(r,r+q.length)});l=Ja(l,d);this.set_state(l)}};function Ma(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]&&(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]&&(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),4===a[0]>>4&&17===a[9]){a=a.subarray(20);d=a[0]<<8|a[1];var e=a[2]<<8|a[3];A(a[6]<<8|a[7],4);if(67===d||67===e)if(d=a.subarray(8),e=d[236]<<24|d[237]<< 16|d[238]<<8|d[239],1669485411!==e)A(e,8);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]&&(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>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,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",Na(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];this.memory[28]=this.memory[29]=87;this.memory[30]=this.memory[31]= 87;qa("Mac: "+Na(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(){return this.cr});b.register_write(this.port|0,this,function(f){this.cr=f;A(f,2);A(this.txcr,2);this.cr&1||(f&24&&0===this.rcnt&&this.do_interrupt(64),f&4&&(f=this.tpsr<<8,f=this.memory.subarray(f,f+this.tcnt),this.mac_address_in_state&&(f=new Uint8Array(f),Ma(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),A(f.byteLength)))});b.register_read(this.port|13,this,function(){return 1===this.get_page()?this.mar[5]:0});b.register_read(this.port|14,this,function(){return 1===this.get_page()?this.mar[6]:0},function(){this.get_page();return 0});b.register_read(this.port|15,this,function(){return 1===this.get_page()?this.mar[7]:0});b.register_read(this.port|31,this,function(){this.get_page();this.do_interrupt(128);return 0});b.register_write(this.port|31,this,function(f){this.get_page(); A(f,2)});b.register_read(this.port|1,this,function(){var f=this.get_page();return 0===f?this.pstart:1===f?this.mac[0]:2===f?this.pstart:0});b.register_write(this.port|1,this,function(f){var g=this.get_page();0===g?(A(f,2),this.pstart=f):1===g?(A(f),this.mac[0]=f):A(f)});b.register_read(this.port|2,this,function(){var f=this.get_page();return 0===f?this.pstop:1===f?this.mac[1]:2===f?this.pstop:0});b.register_write(this.port|2,this,function(f){var g=this.get_page();0===g?(A(f,2),f>this.memory.length>> 8&&(f=this.memory.length>>8,A(f)),this.pstop=f):1===g?(A(f),this.mac[1]=f):A(f)});b.register_read(this.port|7,this,function(){var f=this.get_page();return 0===f?(A(this.isr,2),this.isr):1===f?(A(this.curpg,2),this.curpg):0});b.register_write(this.port|7,this,function(f){var g=this.get_page();0===g?(A(f,2),this.isr&=~f,this.update_irq()):1===g&&(A(f,2),this.curpg=f)});b.register_write(this.port|13,this,function(f){0===this.get_page()&&(this.txcr=f);A(f,2)});b.register_write(this.port|14,this,function(f){0=== this.get_page()?(A(f,2),this.dcfg=f):A(f,2)});b.register_read(this.port|10,this,function(){var f=this.get_page();return 0===f?80:1===f?this.mar[2]:0});b.register_write(this.port|10,this,function(f){0===this.get_page()?(A(f,2),this.rcnt=this.rcnt&65280|f&255):A(f,2)});b.register_read(this.port|11,this,function(){var f=this.get_page();return 0===f?67:1===f?this.mar[3]:0});b.register_write(this.port|11,this,function(f){0===this.get_page()?(A(f,2),this.rcnt=this.rcnt&255|f<<8&65280):A(f,2)});b.register_read(this.port| 8,this,function(){var f=this.get_page();return 0===f?this.rsar&255:1===f?this.mar[0]:0});b.register_write(this.port|8,this,function(f){0===this.get_page()?(A(f,2),this.rsar=this.rsar&65280|f&255):A(f,2)});b.register_read(this.port|9,this,function(){var f=this.get_page();return 0===f?this.rsar>>8&255:1===f?this.mar[1]:0});b.register_write(this.port|9,this,function(f){0===this.get_page()?(A(f,2),this.rsar=this.rsar&255|f<<8&65280):A(f,2)});b.register_write(this.port|15,this,function(f){0===this.get_page()? (A(f,2),A(this.isr,2),this.imr=f,this.update_irq()):A(f,2)});b.register_read(this.port|3,this,function(){var f=this.get_page();return 0===f?(A(this.boundary,2),this.boundary):1===f?this.mac[2]:0});b.register_write(this.port|3,this,function(f){var g=this.get_page();0===g?(A(f,2),this.boundary=f):1===g?(A(f),this.mac[2]=f):A(f)});b.register_read(this.port|4,this,function(){var f=this.get_page();return 0===f?this.tsr:1===f?this.mac[3]:0});b.register_write(this.port|4,this,function(f){var g=this.get_page(); 0===g?(A(f,2),this.tpsr=f):1===g?(A(f),this.mac[3]=f):A(f)});b.register_read(this.port|5,this,function(){var f=this.get_page();return 0===f?0:1===f?this.mac[4]:0});b.register_write(this.port|5,this,function(f){var g=this.get_page();0===g?(A(f,2),this.tcnt=this.tcnt&-256|f):1===g?(A(f),this.mac[4]=f):A(f)});b.register_read(this.port|6,this,function(){var f=this.get_page();return 0===f?0:1===f?this.mac[5]:0});b.register_write(this.port|6,this,function(f){var g=this.get_page();0===g?(A(f,2),this.tcnt= this.tcnt&255|f<<8):1===g?(A(f),this.mac[5]=f):A(f)});b.register_read(this.port|12,this,function(){var f=this.get_page();return 0===f?9:1===f?this.mar[4]:0});b.register_write(this.port|12,this,function(f){0===this.get_page()?(A(f,2),this.rxcr=f):A(f)});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);a.devices.pci.register_device(this)} Oa.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}; Oa.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=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],Na(this.mac_address_in_state),Na(this.mac));this.bus.send("net"+this.id+"-mac",Na(this.mac))}; Oa.prototype.do_interrupt=function(a){A(a,2);this.isr|=a;this.update_irq()};Oa.prototype.update_irq=function(){this.imr&this.isr?this.pci.raise_irq(this.pci_id):this.pci.lower_irq(this.pci_id)};Oa.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)}; Oa.prototype.data_port_write16=function(a){this.data_port_write(a);this.dcfg&1&&this.data_port_write(a>>8)};Oa.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)};Oa.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}; Oa.prototype.data_port_read8=function(){return this.data_port_read16()&255};Oa.prototype.data_port_read16=function(){return this.dcfg&1?this.data_port_read()|this.data_port_read()<<8:this.data_port_read()};Oa.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}; Oa.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]||a[3]!==this.mac[3]||a[4]!==this.mac[4]||a[5]!==this.mac[5]))){this.mac_address_in_state&&(a=new Uint8Array(a),Ma(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),h=this.boundary>this.curpg?this.boundary-this.curpg:this.pstop-this.curpg+this.boundary-this.pstart;hthis.pstop<<8?(f=(this.pstop<<8)-d,this.memory.set(a.subarray(0,f),d),this.memory.set(a.subarray(f),this.pstart<<8),A(f)):(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,A(b),A(c),A(e),this.do_interrupt(1))}};Oa.prototype.get_page=function(){return this.cr>>6&3};var Pa=new Uint8Array(256),Qa=[],Ra=[],Sa=[],Ta=new Uint8Array(256),Wa=[]; function P(a,b){this.cpu=a;this.bus=b;this.write_buffer=new ja(64);this.read_buffer=new ja(64);this.mixer_current_address=this.command_size=this.command=this.read_buffer_lastvalue=0;this.mixer_registers=new Uint8Array(256);this.mixer_reset();this.dummy_speaker_enabled=!1;this.test_register=0;this.dsp_signed=this.dsp_16bit=this.dsp_stereo=this.dsp_highspeed=!1;this.dac_buffers=[new la(65536),new la(65536)];this.dma=a.devices.dma;this.dma_channel=this.dma_irq=this.dma_bytes_block=this.dma_bytes_left= this.dma_bytes_count=this.dma_sample_count=0;this.dma_channel_8bit=1;this.dma_channel_16bit=5;this.dma_autoinit=!1;this.dma_buffer=new ArrayBuffer(65536);this.dma_buffer_int8=new Int8Array(this.dma_buffer);this.dma_buffer_uint8=new Uint8Array(this.dma_buffer);this.dma_buffer_int16=new Int16Array(this.dma_buffer);this.dma_buffer_uint16=new Uint16Array(this.dma_buffer);this.dma_syncbuffer=new t.SyncBuffer(this.dma_buffer);this.dma_paused=this.dma_waiting_transfer=!1;this.sampling_rate=22050;b.send("dac-tell-sampling-rate", this.sampling_rate);this.bytes_per_sample=1;this.e2_value=170;this.e2_count=0;this.asp_registers=new Uint8Array(256);this.mpu_read_buffer=new ja(64);this.fm_current_address1=this.fm_current_address0=this.mpu_read_buffer_lastvalue=0;this.fm_waveform_select_enable=!1;this.irq=5;this.irq_triggered=new Uint8Array(16);a.io.register_read_consecutive(544,this,this.port2x0_read,this.port2x1_read,this.port2x2_read,this.port2x3_read);a.io.register_read_consecutive(904,this,this.port2x0_read,this.port2x1_read); a.io.register_read_consecutive(548,this,this.port2x4_read,this.port2x5_read);a.io.register_read(550,this,this.port2x6_read);a.io.register_read(551,this,this.port2x7_read);a.io.register_read(552,this,this.port2x8_read);a.io.register_read(553,this,this.port2x9_read);a.io.register_read(554,this,this.port2xA_read);a.io.register_read(555,this,this.port2xB_read);a.io.register_read(556,this,this.port2xC_read);a.io.register_read(557,this,this.port2xD_read);a.io.register_read_consecutive(558,this,this.port2xE_read, this.port2xF_read);a.io.register_write_consecutive(544,this,this.port2x0_write,this.port2x1_write,this.port2x2_write,this.port2x3_write);a.io.register_write_consecutive(904,this,this.port2x0_write,this.port2x1_write);a.io.register_write_consecutive(548,this,this.port2x4_write,this.port2x5_write);a.io.register_write(550,this,this.port2x6_write);a.io.register_write(551,this,this.port2x7_write);a.io.register_write_consecutive(552,this,this.port2x8_write,this.port2x9_write);a.io.register_write(554,this, this.port2xA_write);a.io.register_write(555,this,this.port2xB_write);a.io.register_write(556,this,this.port2xC_write);a.io.register_write(557,this,this.port2xD_write);a.io.register_write(558,this,this.port2xE_write);a.io.register_write(559,this,this.port2xF_write);a.io.register_read_consecutive(816,this,this.port3x0_read,this.port3x1_read);a.io.register_write_consecutive(816,this,this.port3x0_write,this.port3x1_write);this.dma.on_unmask(this.dma_on_unmask,this);b.register("dac-request-data",function(){this.dac_handle_request()}, this);b.register("speaker-has-initialized",function(){this.mixer_reset()},this);b.send("speaker-confirm-initialized");this.dsp_reset()} P.prototype.dsp_reset=function(){this.write_buffer.clear();this.read_buffer.clear();this.command_size=this.command=0;this.dummy_speaker_enabled=!1;this.test_register=0;this.dsp_signed=this.dsp_16bit=this.dsp_stereo=this.dsp_highspeed=!1;this.dac_buffers[0].clear();this.dac_buffers[1].clear();this.dma_channel=this.dma_irq=this.dma_bytes_block=this.dma_bytes_left=this.dma_bytes_count=this.dma_sample_count=0;this.dma_autoinit=!1;this.dma_buffer_uint8.fill(0);this.dma_paused=this.dma_waiting_transfer= !1;this.e2_value=170;this.e2_count=0;this.sampling_rate=22050;this.bytes_per_sample=1;this.lower_irq(1);this.irq_triggered.fill(0);this.asp_registers.fill(0);this.asp_registers[5]=1;this.asp_registers[9]=248}; P.prototype.get_state=function(){var a=[];a[2]=this.read_buffer_lastvalue;a[3]=this.command;a[4]=this.command_size;a[5]=this.mixer_current_address;a[6]=this.mixer_registers;a[7]=this.dummy_speaker_enabled;a[8]=this.test_register;a[9]=this.dsp_highspeed;a[10]=this.dsp_stereo;a[11]=this.dsp_16bit;a[12]=this.dsp_signed;a[15]=this.dma_sample_count;a[16]=this.dma_bytes_count;a[17]=this.dma_bytes_left;a[18]=this.dma_bytes_block;a[19]=this.dma_irq;a[20]=this.dma_channel;a[21]=this.dma_channel_8bit;a[22]= this.dma_channel_16bit;a[23]=this.dma_autoinit;a[24]=this.dma_buffer_uint8;a[25]=this.dma_waiting_transfer;a[26]=this.dma_paused;a[27]=this.sampling_rate;a[28]=this.bytes_per_sample;a[29]=this.e2_value;a[30]=this.e2_count;a[31]=this.asp_registers;a[33]=this.mpu_read_buffer_last_value;a[34]=this.irq;a[35]=this.irq_triggered;return a}; P.prototype.set_state=function(a){this.read_buffer_lastvalue=a[2];this.command=a[3];this.command_size=a[4];this.mixer_current_address=a[5];this.mixer_registers=a[6];this.mixer_full_update();this.dummy_speaker_enabled=a[7];this.test_register=a[8];this.dsp_highspeed=a[9];this.dsp_stereo=a[10];this.dsp_16bit=a[11];this.dsp_signed=a[12];this.dma_sample_count=a[15];this.dma_bytes_count=a[16];this.dma_bytes_left=a[17];this.dma_bytes_block=a[18];this.dma_irq=a[19];this.dma_channel=a[20];this.dma_channel_8bit= a[21];this.dma_channel_16bit=a[22];this.dma_autoinit=a[23];this.dma_buffer_uint8=a[24];this.dma_waiting_transfer=a[25];this.dma_paused=a[26];this.sampling_rate=a[27];this.bytes_per_sample=a[28];this.e2_value=a[29];this.e2_count=a[30];this.asp_registers=a[31];this.mpu_read_buffer_last_value=a[33];this.irq=a[34];this.irq_triggered=a[35];this.dma_buffer=this.dma_buffer_uint8.buffer;this.dma_buffer_int8=new Int8Array(this.dma_buffer);this.dma_buffer_int16=new Int16Array(this.dma_buffer);this.dma_buffer_uint16= new Uint16Array(this.dma_buffer);this.dma_syncbuffer=new t.SyncBuffer(this.dma_buffer);this.dma_paused?this.bus.send("dac-disable"):this.bus.send("dac-enable")};P.prototype.port2x0_read=function(){return 255};P.prototype.port2x1_read=function(){return 255};P.prototype.port2x2_read=function(){return 255};P.prototype.port2x3_read=function(){return 255};P.prototype.port2x4_read=function(){return this.mixer_current_address};P.prototype.port2x5_read=function(){return this.mixer_read(this.mixer_current_address)}; P.prototype.port2x6_read=function(){return 255};P.prototype.port2x7_read=function(){return 255};P.prototype.port2x8_read=function(){return 255};P.prototype.port2x9_read=function(){return 255};P.prototype.port2xA_read=function(){this.read_buffer.length&&(this.read_buffer_lastvalue=this.read_buffer.shift());A(this.read_buffer_lastvalue);String.fromCharCode(this.read_buffer_lastvalue);return this.read_buffer_lastvalue};P.prototype.port2xB_read=function(){return 255};P.prototype.port2xC_read=function(){return 127}; P.prototype.port2xD_read=function(){return 255};P.prototype.port2xE_read=function(){this.irq_triggered[1]&&this.lower_irq(1);return(this.read_buffer.length&&!this.dsp_highspeed)<<7|127};P.prototype.port2xF_read=function(){this.lower_irq(2);return 0};P.prototype.port2x0_write=function(a){A(a);this.fm_current_address0=0};P.prototype.port2x1_write=function(a){A(a);var b=Wa[this.fm_current_address0];b||(b=this.fm_default_write);b.call(this,a,0,this.fm_current_address0)}; P.prototype.port2x2_write=function(a){A(a);this.fm_current_address1=0};P.prototype.port2x3_write=function(a){A(a);var b=Wa[this.fm_current_address1];b||(b=this.fm_default_write);b.call(this,a,1,this.fm_current_address1)};P.prototype.port2x4_write=function(a){A(a);this.mixer_current_address=a};P.prototype.port2x5_write=function(a){A(a);this.mixer_write(this.mixer_current_address,a)}; P.prototype.port2x6_write=function(a){A(a);this.dsp_highspeed?this.dsp_highspeed=!1:a&&this.dsp_reset();this.read_buffer.clear();this.read_buffer.push(170)};P.prototype.port2x7_write=function(){};P.prototype.port2x8_write=function(){};P.prototype.port2x9_write=function(){};P.prototype.port2xA_write=function(){};P.prototype.port2xB_write=function(){}; P.prototype.port2xC_write=function(a){0===this.command?(A(a),this.command=a,this.write_buffer.clear(),this.command_size=Pa[a]):(A(a),this.write_buffer.push(a));this.write_buffer.length>=this.command_size&&this.command_do()};P.prototype.port2xD_write=function(){};P.prototype.port2xE_write=function(){};P.prototype.port2xF_write=function(){}; P.prototype.port3x0_read=function(){this.mpu_read_buffer.length&&(this.mpu_read_buffer_lastvalue=this.mpu_read_buffer.shift());A(this.mpu_read_buffer_lastvalue);return this.mpu_read_buffer_lastvalue};P.prototype.port3x0_write=function(a){A(a)};P.prototype.port3x1_read=function(){return 0|128*!this.mpu_read_buffer.length};P.prototype.port3x1_write=function(a){A(a);255===a&&(this.mpu_read_buffer.clear(),this.mpu_read_buffer.push(254))}; P.prototype.command_do=function(){var a=Qa[this.command];a||(a=this.dsp_default_handler);a.call(this);this.command_size=this.command=0;this.write_buffer.clear()};P.prototype.dsp_default_handler=function(){A(this.command)};function Q(a,b,c){c||(c=P.prototype.dsp_default_handler);for(var d=0;dc;c++)b.push(a+c);return b}Q([14],2,function(){this.asp_registers[this.write_buffer.shift()]=this.write_buffer.shift()}); Q([15],1,function(){this.read_buffer.clear();this.read_buffer.push(this.asp_registers[this.write_buffer.shift()])});Q([16],1,function(){var a=this.write_buffer.shift();a=Ya(a/127.5+-1,-1,1);this.dac_buffers[0].push(a);this.dac_buffers[1].push(a);this.bus.send("dac-enable")});Q([20,21],2,function(){this.dma_irq=1;this.dma_channel=this.dma_channel_8bit;this.dsp_highspeed=this.dsp_16bit=this.dsp_signed=this.dma_autoinit=!1;this.dma_transfer_size_set();this.dma_transfer_start()});Q([22],2);Q([23],2); Q([28],0,function(){this.dma_irq=1;this.dma_channel=this.dma_channel_8bit;this.dma_autoinit=!0;this.dsp_highspeed=this.dsp_16bit=this.dsp_signed=!1;this.dma_transfer_start()});Q([31],0);Q([32],0,function(){this.read_buffer.clear();this.read_buffer.push(127)});Q([36],2);Q([44],0);Q([48],0);Q([49],0);Q([52],0);Q([53],0);Q([54],0);Q([55],0);Q([56],0);Q([64],1,function(){this.sampling_rate_change(1E6/(256-this.write_buffer.shift())/this.get_channel_count())}); Q([65,66],2,function(){this.sampling_rate_change(this.write_buffer.shift()<<8|this.write_buffer.shift())});Q([72],2,function(){this.dma_transfer_size_set()});Q([116],2);Q([117],2);Q([118],2);Q([119],2);Q([125],0);Q([127],0);Q([128],2);Q([144],0,function(){this.dma_irq=1;this.dma_channel=this.dma_channel_8bit;this.dma_autoinit=!0;this.dsp_signed=!1;this.dsp_highspeed=!0;this.dsp_16bit=!1;this.dma_transfer_start()});Q([145],0);Q([152],0);Q([153],0);Q([160],0);Q([168],0); Q(Xa(176),3,function(){if(this.command&8)this.dsp_default_handler();else{var a=this.write_buffer.shift();this.dma_irq=2;this.dma_channel=this.dma_channel_16bit;this.dma_autoinit=!!(this.command&4);this.dsp_signed=!!(a&16);this.dsp_stereo=!!(a&32);this.dsp_16bit=!0;this.dma_transfer_size_set();this.dma_transfer_start()}}); Q(Xa(192),3,function(){if(this.command&8)this.dsp_default_handler();else{var a=this.write_buffer.shift();this.dma_irq=1;this.dma_channel=this.dma_channel_8bit;this.dma_autoinit=!!(this.command&4);this.dsp_signed=!!(a&16);this.dsp_stereo=!!(a&32);this.dsp_16bit=!1;this.dma_transfer_size_set();this.dma_transfer_start()}});Q([208],0,function(){this.dma_paused=!0;this.bus.send("dac-disable")});Q([209],0,function(){this.dummy_speaker_enabled=!0});Q([211],0,function(){this.dummy_speaker_enabled=!1}); Q([212],0,function(){this.dma_paused=!1;this.bus.send("dac-enable")});Q([213],0,function(){this.dma_paused=!0;this.bus.send("dac-disable")});Q([214],0,function(){this.dma_paused=!1;this.bus.send("dac-enable")});Q([216],0,function(){this.read_buffer.clear();this.read_buffer.push(255*this.dummy_speaker_enabled)});Q([217,218],0,function(){this.dma_autoinit=!1});Q([224],1,function(){this.read_buffer.clear();this.read_buffer.push(~this.write_buffer.shift())}); Q([225],0,function(){this.read_buffer.clear();this.read_buffer.push(4);this.read_buffer.push(5)});Q([226],1);Q([227],0,function(){this.read_buffer.clear();for(var a=0;44>a;a++)this.read_buffer.push("COPYRIGHT (C) CREATIVE TECHNOLOGY LTD, 1992.".charCodeAt(a));this.read_buffer.push(0)});Q([228],1,function(){this.test_register=this.write_buffer.shift()});Q([232],0,function(){this.read_buffer.clear();this.read_buffer.push(this.test_register)});Q([242,243],0,function(){this.raise_irq()});var Za=new Uint8Array(256); Za[14]=255;Za[15]=7;Za[55]=56;Q([249],1,function(){var a=this.write_buffer.shift();this.read_buffer.clear();this.read_buffer.push(Za[a])});P.prototype.mixer_read=function(a){var b=Ra[a];b?b=b.call(this):(b=this.mixer_registers[a],A(a),A(b));return b};P.prototype.mixer_write=function(a,b){var c=Sa[a];c?c.call(this,b):(A(a),A(b))};P.prototype.mixer_default_read=function(){A(this.mixer_current_address);return this.mixer_registers[this.mixer_current_address]}; P.prototype.mixer_default_write=function(a){A(this.mixer_current_address);A(a);this.mixer_registers[this.mixer_current_address]=a}; P.prototype.mixer_reset=function(){this.mixer_registers[4]=204;this.mixer_registers[34]=204;this.mixer_registers[38]=204;this.mixer_registers[40]=0;this.mixer_registers[46]=0;this.mixer_registers[10]=0;this.mixer_registers[48]=192;this.mixer_registers[49]=192;this.mixer_registers[50]=192;this.mixer_registers[51]=192;this.mixer_registers[52]=192;this.mixer_registers[53]=192;this.mixer_registers[54]=0;this.mixer_registers[55]=0;this.mixer_registers[56]=0;this.mixer_registers[57]=0;this.mixer_registers[59]= 0;this.mixer_registers[60]=31;this.mixer_registers[61]=21;this.mixer_registers[62]=11;this.mixer_registers[63]=0;this.mixer_registers[64]=0;this.mixer_registers[65]=0;this.mixer_registers[66]=0;this.mixer_registers[67]=0;this.mixer_registers[68]=128;this.mixer_registers[69]=128;this.mixer_registers[70]=128;this.mixer_registers[71]=128;this.mixer_full_update()};P.prototype.mixer_full_update=function(){for(var a=1;a>>4};Sa[a]=function(d){this.mixer_registers[a]=d;var e=d<<4&240|this.mixer_registers[c]&15;this.mixer_write(b,d&240|this.mixer_registers[b]&15);this.mixer_write(c,e)}} function db(a,b,c){Ra[a]=P.prototype.mixer_default_read;Sa[a]=function(d){this.mixer_registers[a]=d;this.bus.send("mixer-volume",[b,c,(d>>>2)-62])}}$a(0,function(){this.mixer_reset();return 0});ab(0);cb(4,50,51);cb(34,48,49);cb(38,52,53);cb(40,54,55);cb(46,56,57);db(48,0,0);db(49,0,1);db(50,2,0);db(51,2,1);$a(59);ab(59,function(a){this.mixer_registers[59]=a;this.bus.send("mixer-volume",[1,2,6*(a>>>6)-18])});$a(65); ab(65,function(a){this.mixer_registers[65]=a;this.bus.send("mixer-gain-left",6*(a>>>6))});$a(66);ab(66,function(a){this.mixer_registers[66]=a;this.bus.send("mixer-gain-right",6*(a>>>6))});$a(68);ab(68,function(a){this.mixer_registers[68]=a;a>>>=3;this.bus.send("mixer-treble-left",a-(16>a?14:16))});$a(69);ab(69,function(a){this.mixer_registers[69]=a;a>>>=3;this.bus.send("mixer-treble-right",a-(16>a?14:16))});$a(70); ab(70,function(a){this.mixer_registers[70]=a;a>>>=3;this.bus.send("mixer-bass-right",a-(16>a?14:16))});$a(71);ab(71,function(a){this.mixer_registers[71]=a;a>>>=3;this.bus.send("mixer-bass-right",a-(16>a?14:16))});$a(128,function(){switch(this.irq){case 2:return 1;case 5:return 2;case 7:return 4;case 10:return 8;default:return 0}});ab(128,function(a){a&1&&(this.irq=2);a&2&&(this.irq=5);a&4&&(this.irq=7);a&8&&(this.irq=10)}); $a(129,function(){var a=0;switch(this.dma_channel_8bit){case 0:a|=1;break;case 1:a|=2;break;case 3:a|=8}switch(this.dma_channel_16bit){case 5:a|=32;break;case 6:a|=64;break;case 7:a|=128}return a});ab(129,function(a){a&1&&(this.dma_channel_8bit=0);a&2&&(this.dma_channel_8bit=1);a&8&&(this.dma_channel_8bit=3);a&32&&(this.dma_channel_16bit=5);a&64&&(this.dma_channel_16bit=6);a&128&&(this.dma_channel_16bit=7)});$a(130,function(){for(var a=32,b=0;16>b;b++)a|=b*this.irq_triggered[b];return a}); P.prototype.fm_default_write=function(a,b,c){A(c);A(a)};function eb(a,b){b||(b=P.prototype.fm_default_write);for(var c=0;c>2&-4,32),this.dma_bytes_block);this.dma_waiting_transfer=!0;this.dma.channel_mask[this.dma_channel]||this.dma_on_unmask(this.dma_channel)}; P.prototype.dma_on_unmask=function(a){a===this.dma_channel&&this.dma_waiting_transfer&&(this.dma_waiting_transfer=!1,this.dma_bytes_left=this.dma_bytes_count,this.dma_paused=!1,this.bus.send("dac-enable"))}; P.prototype.dma_transfer_next=function(){var a=Math.min(this.dma_bytes_left,this.dma_bytes_block),b=Math.floor(a/this.bytes_per_sample);this.dma.do_write(this.dma_syncbuffer,0,a,this.dma_channel,c=>{c||(this.dma_to_dac(b),this.dma_bytes_left-=a,this.dma_bytes_left||(this.raise_irq(this.dma_irq),this.dma_autoinit&&(this.dma_bytes_left=this.dma_bytes_count)))})}; P.prototype.dma_to_dac=function(a){var b=this.dsp_16bit?32767.5:127.5,c=this.dsp_signed?0:-1,d=this.dsp_stereo?1:2;var e=this.dsp_16bit?this.dsp_signed?this.dma_buffer_int16:this.dma_buffer_uint16:this.dsp_signed?this.dma_buffer_int8:this.dma_buffer_uint8;for(var f=0,g=0;gc)*c+(b<=a&&a<=c)*a};function k(a,b){this.cpu=a;this.pci=a.devices.pci;this.device_id=b.device_id;this.pci_space=[244,26,b.device_id&255,b.device_id>>8,7,5,16,0,1,0,2,0,0,0,0,0,1,168,0,0,0,16,191,254,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,244,26,b.subsystem_device_id&255,b.subsystem_device_id>>8,0,0,0,0,64,0,0,0,0,0,0,0,0,1,0,0];this.pci_space=this.pci_space.concat(t.zeros(256-this.pci_space.length));this.pci_id=b.pci_id;this.pci_bars=[];this.name=b.name;this.driver_feature_select=this.device_feature_select=0;this.device_feature= new Uint32Array(4);this.driver_feature=new Uint32Array(4);for(var c of b.common.features)this.device_feature[c>>>5]|=1<<(c&31),this.driver_feature[c>>>5]|=1<<(c&31);b.common.features.includes(32);this.features_ok=!0;this.device_status=0;this.config_has_changed=!1;this.config_generation=0;this.queues=[];for(const d of b.common.queues)this.queues.push(new S(a,this,d));this.queue_select=0;this.queue_selected=this.queues[0];this.isr_status=0;c=[];c.push(this.create_common_capability(b.common));c.push(this.create_notification_capability(b.notification)); c.push(this.create_isr_capability(b.isr_status));b.device_specific&&c.push(this.create_device_specific_capability(b.device_specific));this.init_capabilities(c);a.devices.pci.register_device(this);this.reset()} k.prototype.create_common_capability=function(a){return{type:1,bar:0,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:[{bytes:4,name:"device_feature_select",read:()=>this.device_feature_select,write:b=>{this.device_feature_select=b}},{bytes:4,name:"device_feature",read:()=>this.device_feature[this.device_feature_select]||0,write:()=>{}},{bytes:4,name:"driver_feature_select",read:()=>this.driver_feature_select,write:b=>{this.driver_feature_select=b}},{bytes:4,name:"driver_feature", read:()=>this.driver_feature[this.driver_feature_select]||0,write:b=>{const c=this.device_feature[this.driver_feature_select];this.driver_feature_select65535,write:()=>{}},{bytes:2,name:"num_queues",read:()=>this.queues.length,write:()=>{}},{bytes:1,name:"device_status",read:()=>this.device_status,write:b=>{0===b&&this.reset();b&~this.device_status& 4&&this.device_status&64&&this.notify_config_changes();this.features_ok||(b&=-9);this.device_status=b;if(b&~this.device_status&4)a.on_driver_ok()}},{bytes:1,name:"config_generation",read:()=>this.config_generation,write:()=>{}},{bytes:2,name:"queue_select",read:()=>this.queue_select,write:b=>{this.queue_select=b;this.queue_selected=this.queue_selectthis.queue_selected?this.queue_selected.size:0,write:b=> {this.queue_selected&&(b&b-1&&(b=1<this.queue_selected.size_supported&&(b=this.queue_selected.size_supported),this.queue_selected.set_size(b))}},{bytes:2,name:"queue_msix_vector",read:()=>65535,write:()=>{}},{bytes:2,name:"queue_enable",read:()=>this.queue_selected?this.queue_selected.enabled|0:0,write:b=>{this.queue_selected&&1===b&&this.queue_selected.is_configured()&&this.queue_selected.enable()}},{bytes:2,name:"queue_notify_off",read:()=>this.queue_selected?this.queue_selected.notify_offset: 0,write:()=>{}},{bytes:4,name:"queue_desc (low dword)",read:()=>this.queue_selected?this.queue_selected.desc_addr:0,write:b=>{this.queue_selected&&(this.queue_selected.desc_addr=b)}},{bytes:4,name:"queue_desc (high dword)",read:()=>0,write:()=>{}},{bytes:4,name:"queue_avail (low dword)",read:()=>this.queue_selected?this.queue_selected.avail_addr:0,write:b=>{this.queue_selected&&(this.queue_selected.avail_addr=b)}},{bytes:4,name:"queue_avail (high dword)",read:()=>0,write:()=>{}},{bytes:4,name:"queue_used (low dword)", read:()=>this.queue_selected?this.queue_selected.used_addr:0,write:b=>{this.queue_selected&&(this.queue_selected.used_addr=b)}},{bytes:4,name:"queue_used (high dword)",read:()=>0,write:()=>{}}]}}; k.prototype.create_notification_capability=function(a){const b=[];let c;c=a.single_handler?0:2;for(const [d,e]of a.handlers.entries())b.push({bytes:2,name:"notify"+d,read:()=>65535,write:e||(()=>{})});return{type:2,bar:1,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array([c&255,c>>8&255,c>>16&255,c>>24]),struct:b}}; k.prototype.create_isr_capability=function(a){return{type:3,bar:2,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:[{bytes:1,name:"isr_status",read:()=>{const b=this.isr_status;this.lower_irq();return b},write:()=>{}}]}};k.prototype.create_device_specific_capability=function(a){return{type:4,bar:3,port:a.initial_port,use_mmio:!1,offset:0,extra:new Uint8Array(0),struct:a.struct}}; k.prototype.init_capabilities=function(a){let b=this.pci_space[52]=64;var c=b;for(const e of a){a=16+e.extra.length;c=b;b=c+a;var d=e.struct.reduce((f,g)=>f+g.bytes,0);d+=e.offset;d=16>d?16:1<>>8&255;this.pci_space[c+ 10]=e.offset>>>16&255;this.pci_space[c+11]=e.offset>>>24;this.pci_space[c+12]=d&255;this.pci_space[c+13]=d>>>8&255;this.pci_space[c+14]=d>>>16&255;this.pci_space[c+15]=d>>>24;for(const [f,g]of e.extra.entries())this.pci_space[c+16+f]=g;c=16+4*e.bar;this.pci_space[c]=e.port&254|!e.use_mmio;this.pci_space[c+1]=e.port>>>8&255;this.pci_space[c+2]=e.port>>>16&255;this.pci_space[c+3]=e.port>>>24&255;c=e.port+e.offset;for(const f of e.struct){let g=f.read;a=f.write;if(!e.use_mmio){d=function(l){return g(l& -2)>>((l&1)<<3)&255};const h=function(l){return g(l&-4)>>((l&3)<<3)&255};switch(f.bytes){case 4:this.cpu.io.register_read(c,this,h,void 0,g);this.cpu.io.register_write(c,this,void 0,void 0,a);break;case 2:this.cpu.io.register_read(c,this,d,g);this.cpu.io.register_write(c,this,void 0,a);break;case 1:this.cpu.io.register_read(c,this,g),this.cpu.io.register_write(c,this,a)}}c+=f.bytes}}this.pci_space[b]=9;this.pci_space[b+1]=0;this.pci_space[b+2]=20;this.pci_space[b+3]=5;this.pci_space[b+4]=0;this.pci_space[b+ 5]=0;this.pci_space[b+6]=0;this.pci_space[b+7]=0;this.pci_space[b+8]=0;this.pci_space[b+9]=0;this.pci_space[b+10]=0;this.pci_space[b+11]=0;this.pci_space[b+12]=0;this.pci_space[b+13]=0;this.pci_space[b+14]=0;this.pci_space[b+15]=0;this.pci_space[b+16]=0;this.pci_space[b+17]=0;this.pci_space[b+18]=0;this.pci_space[b+19]=0}; k.prototype.get_state=function(){let a=[];a[0]=this.device_feature_select;a[1]=this.driver_feature_select;a[2]=this.device_feature;a[3]=this.driver_feature;a[4]=this.features_ok;a[5]=this.device_status;a[6]=this.config_has_changed;a[7]=this.config_generation;a[8]=this.isr_status;a[9]=this.queue_select;return a=a.concat(this.queues)}; k.prototype.set_state=function(a){this.device_feature_select=a[0];this.driver_feature_select=a[1];this.device_feature=a[2];this.driver_feature=a[3];this.features_ok=a[4];this.device_status=a[5];this.config_has_changed=a[6];this.config_generation=a[7];this.isr_status=a[8];this.queue_select=a[9];let b=0;for(const c of a.slice(10))this.queues[b].set_state(c),b++;this.queue_selected=this.queues[this.queue_select]||null}; k.prototype.reset=function(){this.driver_feature_select=this.device_feature_select=0;this.driver_feature.set(this.device_feature);this.features_ok=!0;this.queue_select=this.device_status=0;this.queue_selected=this.queues[0];for(const a of this.queues)a.reset();this.config_has_changed=!1;this.config_generation=0;this.lower_irq()};k.prototype.notify_config_changes=function(){this.config_has_changed=!0;this.device_status&4&&this.raise_irq(2)}; k.prototype.update_config_generation=function(){this.config_has_changed&&(this.config_generation++,this.config_generation&=255,this.config_has_changed=!1)};k.prototype.is_feature_negotiated=function(a){return 0<(this.driver_feature[a>>>5]&1<<(a&31))};k.prototype.needs_reset=function(){this.device_status|=64;this.device_status&4&&this.notify_config_changes()};k.prototype.raise_irq=function(a){A(a);this.isr_status|=a;this.pci.raise_irq(this.pci_id)}; k.prototype.lower_irq=function(){this.isr_status=0;this.pci.lower_irq(this.pci_id)};function S(a,b,c){this.cpu=a;this.virtio=b;this.size_supported=this.size=c.size_supported;this.mask=this.size-1;this.enabled=!1;this.notify_offset=c.notify_offset;this.num_staged_replies=this.used_addr=this.avail_last_idx=this.avail_addr=this.desc_addr=0;this.reset()} S.prototype.get_state=function(){const a=[];a[0]=this.size;a[1]=this.size_supported;a[2]=this.enabled;a[3]=this.notify_offset;a[4]=this.desc_addr;a[5]=this.avail_addr;a[6]=this.avail_last_idx;a[7]=this.used_addr;a[8]=this.num_staged_replies;return a}; S.prototype.set_state=function(a){this.size=a[0];this.size_supported=a[1];this.enabled=a[2];this.notify_offset=a[3];this.desc_addr=a[4];this.avail_addr=a[5];this.avail_last_idx=a[6];this.used_addr=a[7];this.num_staged_replies=a[8];this.mask=this.size-1};S.prototype.reset=function(){this.enabled=!1;this.num_staged_replies=this.used_addr=this.avail_last_idx=this.avail_addr=this.desc_addr=0;this.set_size(this.size_supported)}; S.prototype.is_configured=function(){return this.desc_addr&&this.avail_addr&&this.used_addr};S.prototype.enable=function(){this.is_configured();this.enabled=!0};S.prototype.set_size=function(a){this.size=a;this.mask=a-1};S.prototype.count_requests=function(){return this.avail_get_idx()-this.avail_last_idx&this.mask};S.prototype.has_request=function(){return(this.avail_get_idx()&this.mask)!==this.avail_last_idx}; S.prototype.pop_request=function(){this.has_request();var a=this.avail_get_entry(this.avail_last_idx);a=new gb(this,a);this.avail_last_idx=this.avail_last_idx+1&this.mask;return a};S.prototype.push_reply=function(a){const b=this.used_get_idx()+this.num_staged_replies&this.mask;this.used_set_entry(b,a.head_idx,a.length_written);this.num_staged_replies++}; S.prototype.flush_replies=function(){if(0!==this.num_staged_replies){var a=this.used_get_idx()+this.num_staged_replies&65535;this.used_set_idx(a);this.num_staged_replies=0;this.virtio.is_feature_negotiated(29)?(this.avail_get_used_event(),this.virtio.raise_irq(1)):~this.avail_get_flags()&1&&this.virtio.raise_irq(1)}};S.prototype.notify_me_after=function(a){a=this.avail_get_idx()+a&65535;this.used_set_avail_event(a)}; S.prototype.get_descriptor=function(a,b){return{addr_low:this.cpu.read32s(a+16*b),addr_high:this.cpu.read32s(a+16*b+4),len:this.cpu.read32s(a+16*b+8),flags:this.cpu.read16(a+16*b+12),next:this.cpu.read16(a+16*b+14)}};S.prototype.avail_get_flags=function(){return this.cpu.read16(this.avail_addr)};S.prototype.avail_get_idx=function(){return this.cpu.read16(this.avail_addr+2)};S.prototype.avail_get_entry=function(a){return this.cpu.read16(this.avail_addr+4+2*a)}; S.prototype.avail_get_used_event=function(){return this.cpu.read16(this.avail_addr+4+2*this.size)};S.prototype.used_get_flags=function(){return this.cpu.read16(this.used_addr)};S.prototype.used_set_flags=function(a){this.cpu.write16(this.used_addr,a)};S.prototype.used_get_idx=function(){return this.cpu.read16(this.used_addr+2)};S.prototype.used_set_idx=function(a){this.cpu.write16(this.used_addr+2,a)}; S.prototype.used_set_entry=function(a,b,c){this.cpu.write32(this.used_addr+4+8*a,b);this.cpu.write32(this.used_addr+8+8*a,c)};S.prototype.used_set_avail_event=function(a){this.cpu.write16(this.used_addr+4+8*this.size,a)}; function gb(a,b){this.cpu=a.cpu;this.virtio=a.virtio;this.head_idx=b;this.read_buffers=[];this.length_readable=this.read_buffer_offset=this.read_buffer_idx=0;this.write_buffers=[];this.length_writable=this.length_written=this.write_buffer_offset=this.write_buffer_idx=0;let c=a.desc_addr,d=0,e=a.size,f=!1;const g=this.virtio.is_feature_negotiated(28);do{const h=a.get_descriptor(c,b);A(h.addr_high,8);A(h.addr_low,8);A(h.len,8);A(h.flags,4);A(h.next,4);if(g&&h.flags&4)c=h.addr_low,d=b=0,e=h.len/16;else{if(h.flags& 2)f=!0,this.write_buffers.push(h),this.length_writable+=h.len;else{if(f)break;this.read_buffers.push(h);this.length_readable+=h.len}d++;if(d>e)break;if(h.flags&1)b=h.next;else break}}while(1)} gb.prototype.get_next_blob=function(a){let b=0,c=a.length;for(;c&&this.read_buffer_idx!==this.read_buffers.length;){var d=this.read_buffers[this.read_buffer_idx];const e=d.addr_low+this.read_buffer_offset;d=d.len-this.read_buffer_offset;d>c?(d=c,this.read_buffer_offset+=c):(this.read_buffer_idx++,this.read_buffer_offset=0);a.set(this.cpu.read_blob(e,d),b);b+=d;c-=d}return b}; gb.prototype.set_next_blob=function(a){let b=0,c=a.length;for(;c&&this.write_buffer_idx!==this.write_buffers.length;){var d=this.write_buffers[this.write_buffer_idx];const e=d.addr_low+this.write_buffer_offset;d=d.len-this.write_buffer_offset;d>c?(d=c,this.write_buffer_offset+=c):(this.write_buffer_idx++,this.write_buffer_offset=0);this.cpu.write_blob(a.subarray(b,b+d),e);b+=d;c-=d}this.length_written+=b;return b};function hb(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{}},notification:{initial_port:47360, single_handler:!1,handlers:[c=>{for(c=this.virtio.queues[c];c.count_requests()>c.size-2;)c.pop_request()},c=>{const d=this.virtio.queues[c],e=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)for(c=this.virtio.queues[c];c.count_requests()>c.size-2;)c.pop_request()},c=>{if(3===c)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=v.Unmarshall(["w","h","h"],f,{offset:0});f=g[0];g=g[1];this.Ack(c,e);switch(g){case 0:for(e=0;ethis.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:()=>{}}]}});for(let c=0;c{}},notification:{initial_port:51456,single_handler:!1,handlers:[d=>{d=this.virtio.queues[d];var e=d.avail_get_entry(d.avail_last_idx);e=new gb(d,e);d.avail_last_idx=d.avail_last_idx+1&d.mask;this.virtio.queues[0].push_reply(e);this.virtio.queues[0].flush_replies()},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)for(var e=this.virtio.queues[d];e.has_request();){const f=e.pop_request(),g=new Uint8Array(f.length_readable);f.get_next_blob(g);const h=v.Unmarshall(["b","b"],g,{offset:0});switch(h[0]<<8|h[1]){case 1024:v.Unmarshall(["h"],g,{offset:2});this.Send(d,f,new Uint8Array([0]));break;case 257:this.mac=g.subarray(2,8);this.Send(d, f,new Uint8Array([0]));this.bus.send("net"+this.id+"-mac",Na(this.mac));break;default:this.Send(d,f,new Uint8Array([1]));return}}}]},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,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)} ib.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.id;this.preserve_mac_from_state_image&&(this.mac=a[2],this.bus.send("net"+this.id+"-mac",Na(this.mac)));return a};ib.prototype.set_state=function(a){this.virtio.set_state(a[0])};ib.prototype.reset=function(){this.virtio.reset()};ib.prototype.Send=function(a,b,c){b.set_next_blob(c);this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};ib.prototype.Ack=function(a,b){this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};var jb={};function kb(){this.listeners={};this.pair=void 0}kb.prototype.register=function(a,b,c){var d=this.listeners[a];void 0===d&&(d=this.listeners[a]=[]);d.push({fn:b,this_value:c})};kb.prototype.unregister=function(a,b){var c=this.listeners[a];void 0!==c&&(this.listeners[a]=c.filter(function(d){return d.fn!==b}))};kb.prototype.send=function(a,b){if(this.pair&&(a=this.pair.listeners[a],void 0!==a))for(var c=0;cthis.wm.exports[c],b=c=>{const d=a(c);console.assert(d,"Missing import: "+c);return d};this.reset_cpu=b("reset_cpu");this.getiopl=b("getiopl");this.get_eflags=b("get_eflags");this.handle_irqs=b("handle_irqs");this.main_loop=b("main_loop");this.set_jit_config=b("set_jit_config");this.read8=b("read8");this.read16=b("read16");this.read32s=b("read32s");this.write8=b("write8");this.write16=b("write16");this.write32=b("write32");this.in_mapped_range=b("in_mapped_range"); this.fpu_load_tag_word=b("fpu_load_tag_word");this.fpu_load_status_word=b("fpu_load_status_word");this.fpu_get_sti_f64=b("fpu_get_sti_f64");this.translate_address_system_read=b("translate_address_system_read_js");this.get_seg_cs=b("get_seg_cs");this.get_real_eip=b("get_real_eip");this.clear_tlb=b("clear_tlb");this.full_clear_tlb=b("full_clear_tlb");this.update_state_flags=b("update_state_flags");this.set_tsc=b("set_tsc");this.store_current_tsc=b("store_current_tsc");this.set_cpuid_level=b("set_cpuid_level"); this.pic_set_irq=b("pic_set_irq");this.pic_clear_irq=b("pic_clear_irq");this.jit_clear_cache=b("jit_clear_cache_js");this.jit_dirty_cache=b("jit_dirty_cache");this.codegen_finalize_finished=b("codegen_finalize_finished");this.allocate_memory=b("allocate_memory");this.zero_memory=b("zero_memory");this.svga_allocate_memory=b("svga_allocate_memory");this.svga_allocate_dest_buffer=b("svga_allocate_dest_buffer");this.svga_fill_pixel_buffer=b("svga_fill_pixel_buffer");this.svga_mark_dirty=b("svga_mark_dirty"); this.get_pic_addr_master=b("get_pic_addr_master");this.get_pic_addr_slave=b("get_pic_addr_slave");this.zstd_create_ctx=b("zstd_create_ctx");this.zstd_get_src_ptr=b("zstd_get_src_ptr");this.zstd_free_ctx=b("zstd_free_ctx");this.zstd_read=b("zstd_read");this.zstd_read_free=b("zstd_read_free");this.port20_read=b("port20_read");this.port21_read=b("port21_read");this.portA0_read=b("portA0_read");this.portA1_read=b("portA1_read");this.port20_write=b("port20_write");this.port21_write=b("port21_write");this.portA0_write= b("portA0_write");this.portA1_write=b("portA1_write");this.port4D0_read=b("port4D0_read");this.port4D1_read=b("port4D1_read");this.port4D0_write=b("port4D0_write");this.port4D1_write=b("port4D1_write")};G.prototype.jit_force_generate=function(a){this.jit_force_generate_unsafe&&this.jit_force_generate_unsafe(a)};G.prototype.jit_clear_func=function(a){this.wm.wasm_table.set(a+1024,null)};G.prototype.jit_clear_all_funcs=function(){const a=this.wm.wasm_table;for(let b=0;900>b;b++)a.set(1024+b,null)}; G.prototype.get_state=function(){var a=[];a[0]=this.memory_size[0];a[1]=new Uint8Array([...this.segment_is_null,...this.segment_access_bytes]);a[2]=this.segment_offsets;a[3]=this.segment_limits;a[4]=this.protected_mode[0];a[5]=this.idtr_offset[0];a[6]=this.idtr_size[0];a[7]=this.gdtr_offset[0];a[8]=this.gdtr_size[0];a[9]=this.page_fault[0];a[10]=this.cr;a[11]=this.cpl[0];a[13]=this.is_32[0];a[16]=this.stack_size_32[0];a[17]=this.in_hlt[0];a[18]=this.last_virt_eip[0];a[19]=this.eip_phys[0];a[22]=this.sysenter_cs[0]; a[23]=this.sysenter_eip[0];a[24]=this.sysenter_esp[0];a[25]=this.prefixes[0];a[26]=this.flags[0];a[27]=this.flags_changed[0];a[28]=this.last_op1[0];a[30]=this.last_op_size[0];a[37]=this.instruction_pointer[0];a[38]=this.previous_ip[0];a[39]=this.reg32;a[40]=this.sreg;a[41]=this.dreg;a[42]=this.reg_pdpte;this.store_current_tsc();a[43]=this.current_tsc;a[45]=this.devices.virtio_9p;a[46]=this.devices.apic;a[47]=this.devices.rtc;a[48]=this.devices.pci;a[49]=this.devices.dma;a[50]=this.devices.acpi;a[52]= this.devices.vga;a[53]=this.devices.ps2;a[54]=this.devices.uart0;a[55]=this.devices.fdc;a[56]=this.devices.cdrom;a[57]=this.devices.hda;a[58]=this.devices.pit;a[59]=this.devices.net;a[60]=this.get_state_pic();a[61]=this.devices.sb16;a[62]=this.fw_value;a[63]=this.devices.ioapic;a[64]=this.tss_size_32[0];a[66]=this.reg_xmm32s;a[67]=this.fpu_st;a[68]=this.fpu_stack_empty[0];a[69]=this.fpu_stack_ptr[0];a[70]=this.fpu_control_word[0];a[71]=this.fpu_ip[0];a[72]=this.fpu_ip_selector[0];a[73]=this.fpu_dp[0]; a[74]=this.fpu_dp_selector[0];a[75]=this.fpu_opcode[0];const {packed_memory:b,bitmap:c}=this.pack_memory();a[77]=b;a[78]=new Uint8Array(c.get_buffer());a[79]=this.devices.uart1;a[80]=this.devices.uart2;a[81]=this.devices.uart3;a[82]=this.devices.virtio_console;a[83]=this.devices.virtio_net;return a}; G.prototype.get_state_pic=function(){const a=new Uint8Array(this.wasm_memory.buffer,this.get_pic_addr_master(),13),b=new Uint8Array(this.wasm_memory.buffer,this.get_pic_addr_slave(),13),c=[],d=[];c[0]=a[0];c[1]=a[1];c[2]=a[2];c[3]=a[3];c[4]=a[4];c[5]=d;c[6]=a[6];c[7]=a[7];c[8]=a[8];c[9]=a[9];c[10]=a[10];c[11]=a[11];c[12]=a[12];d[0]=b[0];d[1]=b[1];d[2]=b[2];d[3]=b[3];d[4]=b[4];d[5]=null;d[6]=b[6];d[7]=b[7];d[8]=b[8];d[9]=b[9];d[10]=b[10];d[11]=b[11];d[12]=b[12];return c}; G.prototype.set_state=function(a){this.memory_size[0]=a[0];this.mem8.length!==this.memory_size[0]&&console.warn("Note: Memory size mismatch. we="+this.mem8.length+" state="+this.memory_size[0]);8===a[1].length?(this.segment_is_null.set(a[1]),this.segment_access_bytes.fill(242),this.segment_access_bytes[1]=250):16===a[1].length&&(this.segment_is_null.set(a[1].subarray(0,8)),this.segment_access_bytes.set(a[1].subarray(8,16)));this.segment_offsets.set(a[2]);this.segment_limits.set(a[3]);this.protected_mode[0]= a[4];this.idtr_offset[0]=a[5];this.idtr_size[0]=a[6];this.gdtr_offset[0]=a[7];this.gdtr_size[0]=a[8];this.page_fault[0]=a[9];this.cr.set(a[10]);this.cpl[0]=a[11];this.is_32[0]=a[13];this.stack_size_32[0]=a[16];this.in_hlt[0]=a[17];this.last_virt_eip[0]=a[18];this.eip_phys[0]=a[19];this.sysenter_cs[0]=a[22];this.sysenter_eip[0]=a[23];this.sysenter_esp[0]=a[24];this.prefixes[0]=a[25];this.flags[0]=a[26];this.flags_changed[0]=a[27];this.last_op1[0]=a[28];this.last_op_size[0]=a[30];this.instruction_pointer[0]= a[37];this.previous_ip[0]=a[38];this.reg32.set(a[39]);this.sreg.set(a[40]);this.dreg.set(a[41]);a[42]&&this.reg_pdpte.set(a[42]);this.set_tsc(a[43][0],a[43][1]);this.devices.virtio_9p&&this.devices.virtio_9p.set_state(a[45]);this.devices.apic&&this.devices.apic.set_state(a[46]);this.devices.rtc&&this.devices.rtc.set_state(a[47]);this.devices.pci&&this.devices.pci.set_state(a[48]);this.devices.dma&&this.devices.dma.set_state(a[49]);this.devices.acpi&&this.devices.acpi.set_state(a[50]);this.devices.vga&& this.devices.vga.set_state(a[52]);this.devices.ps2&&this.devices.ps2.set_state(a[53]);this.devices.uart0&&this.devices.uart0.set_state(a[54]);this.devices.fdc&&this.devices.fdc.set_state(a[55]);this.devices.cdrom&&this.devices.cdrom.set_state(a[56]);this.devices.hda&&this.devices.hda.set_state(a[57]);this.devices.pit&&this.devices.pit.set_state(a[58]);this.devices.net&&this.devices.net.set_state(a[59]);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.fw_value=a[62];this.devices.ioapic&&this.devices.ioapic.set_state(a[63]);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];const b=new t.Bitmap(a[78].buffer);this.unpack_memory(b,a[77]);this.update_state_flags();this.full_clear_tlb();this.jit_clear_cache()}; G.prototype.set_state_pic=function(a){const b=new Uint8Array(this.wasm_memory.buffer,this.get_pic_addr_master(),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]}; G.prototype.pack_memory=function(){var a=this.mem8.length>>12,b=[];for(var c=0;c>2,d+4096>>2);let e=!0;for(let f=0;f>12;let d=0;for(let f=0;f(a|0)&&(a=Math.pow(2,31)-131072);a=(a-1|131071)+1|0;console.assert(0===this.memory_size[0],"Expected uninitialised memory");this.memory_size[0]=a;b=this.allocate_memory(a);this.mem8=t.view(Uint8Array,this.wasm_memory,b,a);this.mem32s=t.view(Uint32Array,this.wasm_memory,b,a>>2)}; G.prototype.init=function(a,b){this.create_memory(a.memory_size||67108864,a.initrd?67108864:1048576);a.disable_jit&&this.set_jit_config(0,1);a.cpuid_level&&this.set_cpuid_level(a.cpuid_level);this.acpi_enabled[0]=+a.acpi;this.reset_cpu();var c=new B(this);this.io=c;this.bios.main=a.bios;this.bios.vga=a.vga_bios;this.load_bios();if(a.bzimage){const e=lb(this.mem8,a.bzimage,a.initrd,a.cmdline||"");e&&this.option_roms.push(e)}c.register_read(179,this,function(){return 0});var d=0;c.register_read(146, this,function(){return d});c.register_write(146,this,function(e){d=e});c.register_read(1297,this,function(){return this.fw_pointer>8|l<<8&65280}function h(l){return l<<24|l<<8&16711680|l>>8&65280|l>>>24}qa("bios config port, index="+A(e));this.fw_pointer=0;if(0===e)this.fw_value=f(1431127377);else if(1===e)this.fw_value= f(0);else if(3===e)this.fw_value=f(this.memory_size[0]);else if(5===e)this.fw_value=f(1);else if(15===e)this.fw_value=f(1);else if(13===e)this.fw_value=new Uint8Array(16);else if(25===e){e=new Int32Array(4+64*this.option_roms.length);const l=new Uint8Array(e.buffer);e[0]=h(this.option_roms.length);for(let m=0;m>2]=h(p.length);e[q+4>>2]=g(49152+m);for(let r=0;re?this.fw_value=f(0):49152<=e&&e-49152a.byteLength){var d=new Int32Array(2048);(new Uint8Array(d.buffer)).set(new Uint8Array(a))}else d=new Int32Array(a,0,2048);for(var e=0;8192>e;e+=4){if(464367618===d[e>>2]){var f=d[e+4>>2];if(464367618+f+d[e+8>>2]|0)continue}else continue;qa("Multiboot magic found, flags: "+A(f>>>0,8),2);var g=this;this.io.register_read(244,this,function(){return 0},function(){return 0},function(){var n=31860,p=0;if(c){p|=4;g.write32(31760,n);c+="\x00"; var q=(new TextEncoder).encode(c);g.write_blob(q,n);n+=q.length}if(f&2){p|=64;q=0;g.write32(31788,0);g.write32(31792,n);var r=0;var D=!1;for(let u=0;4294967296>u;u+=131072)D&&void 0!==g.memory_map_read8[u>>>17]?(g.write32(n,20),g.write32(n+4,r),g.write32(n+8,0),g.write32(n+12,u-r),g.write32(n+16,0),g.write32(n+20,1),n+=24,q+=24,D=!1):D||void 0!==g.memory_map_read8[u>>>17]||(r=u,D=!0);g.write32(31788,q)}g.write32(31744,p);q=p=0;if(f&65536){D=d[e+12>>2];p=d[e+16>>2];var y=d[e+20>>2];q=d[e+24>>2];r= d[e+28>>2];A(D,8);A(p,8);A(y,8);A(q,8);A(r,8);D=new Uint8Array(a,e-(D-p),0===y?void 0:y-p);g.write_blob(D,p);p=r|0;q=Math.max(y,q)}else if(1179403647===d[0]){r=new DataView(a);const [u,F]=nb(r,ob);console.assert(52===F);console.assert(1179403647===u.magic,"Bad magic");console.assert(1===u.class,"Unimplemented: 64 bit elf");console.assert(1===u.data,"Unimplemented: big endian");console.assert(1===u.version0,"Bad version0");console.assert(2===u.type,"Unimplemented type");console.assert(1===u.version1, "Bad version1");console.assert(52===u.ehsize,"Bad header size");console.assert(32===u.phentsize,"Bad program header size");console.assert(40===u.shentsize,"Bad section header size");[p]=pb(new DataView(r.buffer,r.byteOffset+u.phoff,u.phentsize*u.phnum),qb,u.phnum);pb(new DataView(r.buffer,r.byteOffset+u.shoff,u.shentsize*u.shnum),rb,u.shnum);r=u;D=p;p=r.entry;for(y of D)0!==y.type&&(1===y.type?y.paddr+y.memszp&&(p=p-y.vaddr+y.paddr)):A(y.paddr):2===y.type||3===y.type||4===y.type||6===y.type||7===y.type||1685382480===y.type||1685382481===y.type||1685382482===y.type||1685382483===y.type||A(y.type))}b&&(g.write32(31764,1),g.write32(31768,n),y=q,0!==(y&4095)&&(y=(y&-4096)+4096),q=y+b.byteLength,g.write32(n,y),g.write32(n+4,q),g.write32(n+8,0),g.write32(n+12,0),g.write_blob(new Uint8Array(b),y));g.reg32[3]=31744;g.cr[0]=1;g.protected_mode[0]= 1;g.flags[0]=2;g.is_32[0]=1;g.stack_size_32[0]=1;for(n=0;6>n;n++)g.segment_is_null[n]=0,g.segment_offsets[n]=0,g.segment_limits[n]=4294967295,g.sreg[n]=45058;g.instruction_pointer[0]=g.get_seg_cs()+p|0;g.update_state_flags();g.debug.dump_state();g.debug.dump_regs();return 732803074});this.io.register_write_consecutive(244,this,function(n){console.log("Test exited with code "+A(n,2));throw"HALT";},function(){},function(){},function(){});for(let n=0;15>=n;n++){function p(q){A(n);A(q,2);q?this.device_raise_irq(n): this.device_lower_irq(n)}this.io.register_write(8192+n,this,p,p,p)}const l=new Uint8Array(512);(new Uint16Array(l.buffer))[0]=43605;l[2]=1;var h=3;l[h++]=102;l[h++]=229;l[h++]=244;let m=l[h]=0;for(let n=0;n>4&240);a.cmos_write(61,c&255);a.cmos_write(21,128);a.cmos_write(22,2);c=0;1048576<=this.memory_size[0]&&(c=this.memory_size[0]-1048576>>10,c=Math.min(c,65535));a.cmos_write(23,c&255);a.cmos_write(24,c>>8&255);a.cmos_write(48,c&255);a.cmos_write(49,c>>8&255);c=0;16777216<=this.memory_size[0]&&(c=this.memory_size[0]-16777216>>16,c=Math.min(c,65535));a.cmos_write(52,c&255);a.cmos_write(53,c>>8&255);a.cmos_write(91,0);a.cmos_write(92, 0);a.cmos_write(93,0);a.cmos_write(20,47);a.cmos_write(95,0);b.fastboot&&a.cmos_write(63,1)}; G.prototype.load_bios=function(){var a=this.bios.main,b=this.bios.vga;if(a){var c=new Uint8Array(a);this.write_blob(c,1048576-a.byteLength);if(b){var d=new Uint8Array(b);this.write_blob(d,786432);this.io.mmap_register(4272947200,1048576,function(e){e=e-4272947200|0;return e>>0,e>>>0);WebAssembly.instantiate(f,{e:this.jit_imports}).then(g=>{this.wm.wasm_table.set(a+1024,g.instance.exports.f);this.codegen_finalize_finished(a,b,c);this.test_hook_did_finalize_wasm&&this.test_hook_did_finalize_wasm(f)})};G.prototype.log_uncompiled_code=function(){};G.prototype.dump_function_code=function(){}; G.prototype.run_hardware_timers=function(a,b){const c=this.devices.pit.timer(b,!1),d=this.devices.rtc.timer(b,!1);let e=100,f=100;a&&(e=this.devices.acpi.timer(b),f=this.devices.apic.timer(b));return Math.min(c,d,e,f)};G.prototype.device_raise_irq=function(a){this.pic_set_irq(a);this.devices.ioapic&&this.devices.ioapic.set_irq(a)};G.prototype.device_lower_irq=function(a){this.pic_clear_irq(a);this.devices.ioapic&&this.devices.ioapic.clear_irq(a)};G.prototype.debug_init=function(){var a=this,b={};this.debug=b;b.init=function(){};b.get_regs_short=function(){};b.dump_regs=function(){};b.get_state=function(){};b.dump_state=function(){};b.dump_stack=function(){};b.dump_page_structures=function(){if(a.cr[4]&32)for(var f=0;4>f;f++)a.read32s(a.cr[3]+8*f)};b.dump_gdt_ldt=function(){};b.dump_idt=function(){};b.get_memory_dump=function(){};b.memory_hex_dump=function(){};b.used_memory_dump=function(){};b.debug_interrupt=function(){};let c,d;b.dump_code= function(f,g,h){if(!d){if(void 0===c&&(c="function"===typeof require?require("./capstone-x86.min.js"):window.cs,void 0===c))return;d=[new c.Capstone(c.ARCH_X86,c.MODE_16),new c.Capstone(c.ARCH_X86,c.MODE_32)]}try{d[f].disasm(g,h).forEach(function(l){qa(A(l.address>>>0)+": "+t.pads(l.bytes.map(m=>A(m,2).slice(-2)).join(" "),20)+" "+l.mnemonic+" "+l.op_str)})}catch(l){qa("Could not disassemble: "+Array.from(g).map(m=>A(m,2)).join(" "))}};let e;b.dump_wasm=function(f){if(void 0===e&&(e="function"=== typeof require?require("./libwabt.js"):new window.WabtModule,void 0===e))return;f=f.slice();try{var g=e.readWasm(f,{readDebugNames:!1});g.generateNames();g.applyNames();g.toText({foldExprs:!0,inlineExport:!0})}catch(m){var h=new Blob([f]),l=document.createElement("a");l.download="failed.wasm";l.href=window.URL.createObjectURL(h);l.dataset.downloadurl=["application/octet-stream",l.download,l.href].join(":");l.click();window.URL.revokeObjectURL(l.src);console.log(m.toString())}finally{g&&g.destroy()}}};const sb=DataView.prototype,tb={size:1,get:sb.getUint8,set:sb.setUint8},ub={size:2,get:sb.getUint16,set:sb.setUint16},T={size:4,get:sb.getUint32,set:sb.setUint32},ob=vb([{magic:T},{class:tb},{data:tb},{version0:tb},{osabi:tb},{abiversion:tb},{pad0:function(a){return{size:a,get:()=>-1}}(7)},{type:ub},{machine:ub},{version1:T},{entry:T},{phoff:T},{shoff:T},{flags:T},{ehsize:ub},{phentsize:ub},{phnum:ub},{shentsize:ub},{shnum:ub},{shstrndx:ub}]);console.assert(52===ob.reduce((a,b)=>a+b.size,0)); const qb=vb([{type:T},{offset:T},{vaddr:T},{paddr:T},{filesz:T},{memsz:T},{flags:T},{align:T}]);console.assert(32===qb.reduce((a,b)=>a+b.size,0));const rb=vb([{name:T},{type:T},{flags:T},{addr:T},{offset:T},{size:T},{link:T},{info:T},{addralign:T},{entsize:T}]);console.assert(40===rb.reduce((a,b)=>a+b.size,0));function vb(a){return a.map(function(b){var c=Object.keys(b);console.assert(1===c.length);c=c[0];b=b[c];console.assert(0{g(n,p);n=null},10),!1;g(w,K);return!1}}function g(w,K){a:{if(void 0!==w.code){var V=F[w.code];if(void 0!==V)break a}V=D[w.keyCode]}V?h(V,K,w.repeat):console.log("Missing char in map: keyCode="+(w.keyCode||-1).toString(16)+" code="+w.code)}function h(w,K,V){if(K)m[w]&&!V&&h(w,!1);else if(!m[w])return; (m[w]=K)||(w|=128);255>8),l(w&255)):l(w)}function l(w){r.bus.send("keyboard-code",w)}var m={},n=null,p=!1,q=0,r=this;this.emu_enabled=!0;var D=new Uint16Array([0,0,0,0,0,0,0,0,14,15,0,0,0,28,0,0,42,29,56,0,58,0,0,0,0,0,0,1,0,0,0,0,57,57417,57425,57423,57415,57419,57416,57421,80,0,0,0,0,82,83,0,11,2,3,4,5,6,7,8,9,10,0,39,0,13,0,0,0,30,48,46,32,18,33,34,35,23,36,37,38,50,49,24,25,16,19,31,20,22,47,17,45,21,44,57435,57436,57437,0,0,82,79,80,81,75,76,77,71,72,73,0,0,0,0,0,0,59,60,61,62,63,64, 65,66,67,68,87,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,69,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,39,13,51,12,52,53,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,26,43,27,40,0,57435,57400,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),y={8:8,10:13,32:32,39:222,44:188,45:189,46:190,47:191,48:48,49:49,50:50,51:51,52:52,53:53,54:54,55:55,56:56,57:57,59:186,61:187,91:219,92:220,93:221,96:192,97:65,98:66,99:67,100:68,101:69,102:70,103:71,104:72,105:73,106:74,107:75, 108:76,109:77,110:78,111:79,112:80,113:81,114:82,115:83,116:84,117:85,118:86,119:87,120:88,121:89,122:90},u={33:49,34:222,35:51,36:52,37:53,38:55,40:57,41:48,42:56,43:187,58:186,60:188,62:190,63:191,64:50,65:65,66:66,67:67,68:68,69:69,70:70,71:71,72:72,73:73,74:74,75:75,76:76,77:77,78:78,79:79,80:80,81:81,82:82,83:83,84:84,85:85,86:86,87:87,88:88,89:89,90:90,94:54,95:189,123:219,124:220,125:221,126:192},F={Escape:1,Digit1:2,Digit2:3,Digit3:4,Digit4:5,Digit5:6,Digit6:7,Digit7:8,Digit8:9,Digit9:10, Digit0:11,Minus:12,Equal:13,Backspace:14,Tab:15,KeyQ:16,KeyW:17,KeyE:18,KeyR:19,KeyT:20,KeyY:21,KeyU:22,KeyI:23,KeyO:24,KeyP:25,BracketLeft:26,BracketRight:27,Enter:28,ControlLeft:29,KeyA:30,KeyS:31,KeyD:32,KeyF:33,KeyG:34,KeyH:35,KeyJ:36,KeyK:37,KeyL:38,Semicolon:39,Quote:40,Backquote:41,ShiftLeft:42,Backslash:43,KeyZ:44,KeyX:45,KeyC:46,KeyV:47,KeyB:48,KeyN:49,KeyM:50,Comma:51,Period:52,Slash:53,IntlRo:53,ShiftRight:54,NumpadMultiply:55,AltLeft:56,Space:57,CapsLock:58,F1:59,F2:60,F3:61,F4:62,F5:63, F6:64,F7:65,F8:66,F9:67,F10:68,NumLock:69,ScrollLock:70,Numpad7:71,Numpad8:72,Numpad9:73,NumpadSubtract:74,Numpad4:75,Numpad5:76,Numpad6:77,NumpadAdd:78,Numpad1:79,Numpad2:80,Numpad3:81,Numpad0:82,NumpadDecimal:83,IntlBackslash:86,F11:87,F12:88,NumpadEnter:57372,ControlRight:57373,NumpadDivide:57397,AltRight:57400,Home:57415,ArrowUp:57416,PageUp:57417,ArrowLeft:57419,ArrowRight:57421,End:57423,ArrowDown:57424,PageDown:57425,Insert:57426,Delete:57427,OSLeft:57435,OSRight:57436,ContextMenu:57437};this.bus= a;this.destroy=function(){"undefined"!==typeof window&&(window.removeEventListener("keyup",c,!1),window.removeEventListener("keydown",d,!1),window.removeEventListener("blur",e,!1))};this.init=function(){"undefined"!==typeof window&&(this.destroy(),window.addEventListener("keyup",c,!1),window.addEventListener("keydown",d,!1),window.addEventListener("blur",e,!1))};this.init();this.simulate_press=function(w){w={keyCode:w};f(w,!0);f(w,!1)};this.simulate_char=function(w){var K=w.charCodeAt(0);K in y?this.simulate_press(y[K]): K in u?(l(42),this.simulate_press(u[K]),l(170)):console.log("ascii -> keyCode not found: ",K,w)}};function yb(a,b){function c(u){if(!y.enabled||!y.emu_enabled)return!1;var F=b||document.body,w;if(!(w=document.pointerLockElement))a:{for(u=u.target;u.parentNode;){if(u===F){w=!0;break a}u=u.parentNode}w=!1}return w}function d(u){c(u)&&(u=u.changedTouches)&&u.length&&(u=u[u.length-1],r=u.clientX,D=u.clientY)}function e(){if(n||q||p)y.bus.send("mouse-click",[!1,!1,!1]),n=q=p=!1}function f(u){if(y.bus&&c(u)&&y.is_running){var F=0,w=0,K=u.changedTouches;K?K.length&&(K=K[K.length-1],F=K.clientX-r,w=K.clientY- D,r=K.clientX,D=K.clientY,u.preventDefault()):"number"===typeof u.movementX?(F=u.movementX,w=u.movementY):"number"===typeof u.webkitMovementX?(F=u.webkitMovementX,w=u.webkitMovementY):"number"===typeof u.mozMovementX?(F=u.mozMovementX,w=u.mozMovementY):(F=u.clientX-r,w=u.clientY-D,r=u.clientX,D=u.clientY);y.bus.send("mouse-delta",[.15*F,-(.15*w)]);b&&y.bus.send("mouse-absolute",[u.pageX-b.offsetLeft,u.pageY-b.offsetTop,b.offsetWidth,b.offsetHeight])}}function g(u){c(u)&&l(u,!0)}function h(u){c(u)&& l(u,!1)}function l(u,F){y.bus&&(1===u.which?n=F:2===u.which?q=F:3===u.which&&(p=F),y.bus.send("mouse-click",[n,q,p]),u.preventDefault())}function m(u){if(c(u)){var F=u.wheelDelta||-u.detail;0>F?F=-1:0{switch(n.data.type){case "queue":m.queue_push(n.data.value);break;case "sampling-rate":m.source_samples_per_destination=n.data.value/sampleRate}};return m}var l=[new Float32Array(256),new Float32Array(256)];Reflect.setPrototypeOf(h.prototype,AudioWorkletProcessor.prototype);Reflect.setPrototypeOf(h,AudioWorkletProcessor);h.prototype.process=h.prototype.process=function(m,n){for(m=0;mm?(m+=this.source_buffer_previous[0].length,this.source_buffer_previous[n][m]):this.source_buffer_current[n][m]};h.prototype.ensure_enough_data=function(m){var n=this.source_buffer_current[0].length;n-this.source_block_start this.queued_samples&&this.queue_length&&this.dbg_log("Not enough samples - should not happen during midway of playback");this.source_buffer_previous=this.source_buffer_current;this.source_buffer_current=this.queue_shift();var m=this.source_buffer_current[0].length;if(256>m){for(var n=this.queue_start,p=0;256>m&&pthis.queued_samples/this.source_samples_per_destination&&this.port.postMessage({type:"pump"})};h.prototype.queue_push=function(m){this.queue_length{URL.revokeObjectURL(f);this.node_processor=new AudioWorkletNode(this.audio_context,"dac-processor",{numberOfInputs:0,numberOfOutputs:1,outputChannelCount:[2],parameterData:{},processorOptions:{}});this.node_processor.port.postMessage({type:"sampling-rate",value:this.sampling_rate});this.node_processor.port.onmessage=g=>{switch(g.data.type){case "pump":this.pump()}};this.node_processor.connect(this.node_output)}); this.mixer_connection=c.add_source(this.node_output,2);this.mixer_connection.set_gain_hidden(3);a.register("dac-send-data",function(g){this.queue(g)},this);a.register("dac-enable",function(){this.enabled=!0},this);a.register("dac-disable",function(){this.enabled=!1},this);a.register("dac-tell-sampling-rate",function(g){this.sampling_rate=g;this.node_processor&&this.node_processor.port.postMessage({type:"sampling-rate",value:g})},this)} Ab.prototype.queue=function(a){this.node_processor&&this.node_processor.port.postMessage({type:"queue",value:a},[a[0].buffer,a[1].buffer])};Ab.prototype.pump=function(){this.enabled&&this.bus.send("dac-request-data")}; function Bb(a,b,c){this.bus=a;this.audio_context=b;this.enabled=!1;this.sampling_rate=22050;this.buffered_time=0;this.rate_ratio=1;this.node_lowpass=this.audio_context.createBiquadFilter();this.node_lowpass.type="lowpass";this.node_output=this.node_lowpass;this.mixer_connection=c.add_source(this.node_output,2);this.mixer_connection.set_gain_hidden(3);a.register("dac-send-data",function(d){this.queue(d)},this);a.register("dac-enable",function(){this.enabled=!0;this.pump()},this);a.register("dac-disable", function(){this.enabled=!1},this);a.register("dac-tell-sampling-rate",function(d){this.sampling_rate=d;this.rate_ratio=Math.ceil(8E3/d);this.node_lowpass.frequency.setValueAtTime(d/2,this.audio_context.currentTime)},this)} Bb.prototype.queue=function(a){var b=a[0].length,c=b/this.sampling_rate;if(1this.pump(),1E3*b);a.start(this.buffered_time);this.buffered_time+=c;setTimeout(()=>this.pump(),0)};Bb.prototype.pump=function(){this.enabled&&(.2l?void 0===this.update_timer&&(this.update_timer=setTimeout(()=>{this.update_timer=void 0;this.last_update=Date.now();this.render()},16-l)):(void 0!==this.update_timer&&(clearTimeout(this.update_timer),this.update_timer=void 0),this.last_update=h,this.render())};this.render=function(){a.value=this.text;this.text_new_line&&(this.text_new_line= !1,a.scrollTop=1E9)};this.send_char=function(h){g.bus&&g.bus.send("serial0-input",h)}} function Gb(a,b){this.element=a;if(window.Terminal){var c=this.term=new window.Terminal({logLevel:"off"});c.write("This is the serial console. Whatever you type or paste here will be sent to COM1");var d=c.onData(function(e){for(let f=0;fa)){this.last_connect_attempt=Date.now();try{this.socket=new WebSocket(this.url)}catch(b){console.error(b);return}this.socket.binaryType="arraybuffer";this.socket.onopen=this.handle_open.bind(this);this.socket.onmessage=this.handle_message.bind(this);this.socket.onclose=this.handle_close.bind(this); this.socket.onerror=this.handle_error.bind(this)}}};Hb.prototype.send=function(a){this.socket&&1===this.socket.readyState?this.socket.send(a):(this.send_queue.push(a),this.send_queue.length>2*this.send_queue_limit&&(this.send_queue=this.send_queue.slice(-this.send_queue_limit)),this.connect())};Hb.prototype.change_proxy=function(a){this.url=a;this.socket&&(this.socket.onclose=function(){},this.socket.onerror=function(){},this.socket.close(),this.socket=void 0)};function X(a){this.cpu_is_running=!1;this.cpu_exception_hook=function(){};var b=jb.create();this.bus=b[0];this.emulator_bus=b[1];var c,d;const e=new WebAssembly.Table({element:"anyfunc",initial:1924});b={cpu_exception_hook:g=>this.cpu_exception_hook(g),run_hardware_timers:function(g,h){return c.run_hardware_timers(g,h)},cpu_event_halt:()=>{this.emulator_bus.send("cpu-event-halt")},abort:function(){},microtick:E.microtick,get_rand_int:function(){return t.get_rand_int()},apic_acknowledge_irq:function(){return c.devices.apic.acknowledge_irq()}, stop_idling:function(){return c.stop_idling()},io_port_read8:function(g){return c.io.port_read8(g)},io_port_read16:function(g){return c.io.port_read16(g)},io_port_read32:function(g){return c.io.port_read32(g)},io_port_write8:function(g,h){c.io.port_write8(g,h)},io_port_write16:function(g,h){c.io.port_write16(g,h)},io_port_write32:function(g,h){c.io.port_write32(g,h)},mmap_read8:function(g){return c.mmap_read8(g)},mmap_read16:function(g){return c.mmap_read16(g)},mmap_read32:function(g){return c.mmap_read32(g)}, mmap_write8:function(g,h){c.mmap_write8(g,h)},mmap_write16:function(g,h){c.mmap_write16(g,h)},mmap_write32:function(g,h){c.mmap_write32(g,h)},mmap_write64:function(g,h,l){c.mmap_write64(g,h,l)},mmap_write128:function(g,h,l,m,n){c.mmap_write128(g,h,l,m,n)},log_from_wasm:function(g,h){t.read_sized_string_from_mem(d,g,h)},console_log_from_wasm:function(g,h){g=t.read_sized_string_from_mem(d,g,h);console.error(g)},dbg_trace_from_wasm:function(){},codegen_finalize:(g,h,l,m,n)=>{c.codegen_finalize(g,h,l, m,n)},jit_clear_func:g=>c.jit_clear_func(g),jit_clear_all_funcs:()=>c.jit_clear_all_funcs(),__indirect_function_table:e};let f=a.wasm_fn;f||(f=g=>new Promise(h=>{let l="v86.wasm",m="v86-fallback.wasm";if(a.wasm_path){l=a.wasm_path;const n=l.lastIndexOf("/");m=(-1===n?"":l.substr(0,n))+"/"+m}else"undefined"===typeof window&&"string"===typeof __dirname?(l=__dirname+"/"+l,m=__dirname+"/"+m):(l="build/"+l,m="build/"+m);t.load_file(l,{done:async n=>{try{const {instance:p}=await WebAssembly.instantiate(n, g);this.wasm_source=n;h(p.exports)}catch(p){t.load_file(m,{done:async q=>{const {instance:r}=await WebAssembly.instantiate(q,g);this.wasm_source=q;h(r.exports)}})}},progress:n=>{this.emulator_bus.send("download-progress",{file_index:0,file_count:1,file_name:l,lengthComputable:n.lengthComputable,total:n.total,loaded:n.loaded})}})}));f({env:b}).then(g=>{d=g.memory;g.rust_init();g=this.v86=new E(this.emulator_bus,{exports:g,wasm_table:e});c=g.cpu;this.continue_init(g,a)});this.zstd_worker=null;this.zstd_worker_request_id= 0} X.prototype.continue_init=async function(a,b){function c(q,r){switch(q){case "hda":e.hda=this.disk_images.hda=r;break;case "hdb":e.hdb=this.disk_images.hdb=r;break;case "cdrom":e.cdrom=this.disk_images.cdrom=r;break;case "fda":e.fda=this.disk_images.fda=r;break;case "fdb":e.fdb=this.disk_images.fdb=r;break;case "multiboot":e.multiboot=this.disk_images.multiboot=r.buffer;break;case "bzimage":e.bzimage=this.disk_images.bzimage=r.buffer;break;case "initrd":e.initrd=this.disk_images.initrd=r.buffer;break; case "bios":e.bios=r.buffer;break;case "vga_bios":e.vga_bios=r.buffer;break;case "initial_state":e.initial_state=r.buffer;break;case "fs9p_json":e.fs9p_json=r}}async function d(){if(e.fs9p&&e.fs9p_json&&!e.initial_state&&(e.fs9p.load_from_json(e.fs9p_json),b.bzimage_initrd_from_filesystem)){const {bzimage_path:q,initrd_path:r}=this.get_bzimage_initrd_from_filesystem(e.fs9p),[D,y]=await Promise.all([e.fs9p.read_file(r),e.fs9p.read_file(q)]);c.call(this,"initrd",new t.SyncBuffer(D.buffer));c.call(this, "bzimage",new t.SyncBuffer(y.buffer))}this.serial_adapter&&this.serial_adapter.show&&this.serial_adapter.show();this.v86.init(e);e.initial_state&&(a.restore_state(e.initial_state),e.initial_state=void 0);b.autostart&&this.v86.run();this.emulator_bus.send("emulator-loaded")}this.bus.register("emulator-stopped",function(){this.cpu_is_running=!1;this.screen_adapter.pause()},this);this.bus.register("emulator-started",function(){this.cpu_is_running=!0;this.screen_adapter.continue()},this);var e={};this.disk_images= {fda:void 0,fdb:void 0,hda:void 0,hdb:void 0,cdrom:void 0};var f=b.boot_order?b.boot_order:b.fda?801:b.hda?786:291;e.acpi=b.acpi;e.disable_jit=b.disable_jit;e.load_devices=!0;e.memory_size=b.memory_size||67108864;e.vga_memory_size=b.vga_memory_size||8388608;e.boot_order=f;e.fastboot=b.fastboot||!1;e.fda=void 0;e.fdb=void 0;e.uart1=b.uart1;e.uart2=b.uart2;e.uart3=b.uart3;e.cmdline=b.cmdline;e.preserve_mac_from_state_image=b.preserve_mac_from_state_image;e.mac_address_translation=b.mac_address_translation; e.cpuid_level=b.cpuid_level;e.virtio_console=b.virtio_console;e.virtio_net=b.virtio_net;e.screen_options=b.screen_options;if(f=b.network_relay_url||b.net_device&&b.net_device.relay_url)"fetch"===f?this.network_adapter=new Ib(this.bus):f.startsWith("wisp://")||f.startsWith("wisps://")?this.network_adapter=new Jb(f,this.bus,b):this.network_adapter=new Hb(f,this.bus);e.net_device=b.net_device||{type:"ne2k"};f=b.screen||{};b.screen_container&&(f.container=b.screen_container);b.disable_keyboard||(this.keyboard_adapter= new xb(this.bus));b.disable_mouse||(this.mouse_adapter=new yb(this.bus,f.container));this.screen_adapter=f.container?new aa(f,()=>this.v86.cpu.devices.vga&&this.v86.cpu.devices.vga.screen_fill_buffer()):new Kb;e.screen=this.screen_adapter;e.screen_options=f;b.serial_container&&(this.serial_adapter=new Fb(b.serial_container,this.bus));b.serial_container_xtermjs&&(this.serial_adapter=new Gb(b.serial_container_xtermjs,this.bus));b.disable_speaker||(this.speaker_adapter=new zb(this.bus));var g=[];f=(q, r)=>{if(r)if(r.get&&r.set&&r.load)g.push({name:q,loadable:r});else{if("bios"===q||"vga_bios"===q||"initial_state"===q||"multiboot"===q||"bzimage"===q||"initrd"===q)r.async=!1;if("fda"===q||"fdb"===q)r.async=!1;r.url&&!r.async?g.push({name:q,url:r.url,size:r.size}):g.push({name:q,loadable:t.buffer_from_object(r,this.zstd_decompress_worker.bind(this))})}};b.state&&console.warn("Warning: Unknown option 'state'. Did you mean 'initial_state'?");f("bios",b.bios);f("vga_bios",b.vga_bios);f("cdrom",b.cdrom); f("hda",b.hda);f("hdb",b.hdb);f("fda",b.fda);f("fdb",b.fdb);f("initial_state",b.initial_state);f("multiboot",b.multiboot);f("bzimage",b.bzimage);f("initrd",b.initrd);if(b.filesystem){f=b.filesystem.basefs;var h=b.filesystem.baseurl;let q=new Lb;h&&(q=new Mb(q,h));e.fs9p=this.fs9p=new Z(q);if(f){if("object"===typeof f){var l=f.size;f=f.url}g.push({name:"fs9p_json",url:f,size:l,as_json:!0})}}var m=this,n=g.length,p=function(q){if(q===n)setTimeout(d.bind(this),0);else{var r=g[q];r.loadable?(r.loadable.onload= function(){c.call(this,r.name,r.loadable);p(q+1)}.bind(this),r.loadable.load()):t.load_file(r.url,{done:function(D){r.url.endsWith(".zst")&&"initial_state"!==r.name&&(D=this.zstd_decompress(r.size,new Uint8Array(D)));c.call(this,r.name,r.as_json?D:new t.SyncBuffer(D));p(q+1)}.bind(this),progress:function(D){200===D.target.status?m.emulator_bus.send("download-progress",{file_index:q,file_count:n,file_name:r.url,lengthComputable:D.lengthComputable,total:D.total||r.size,loaded:D.loaded}):m.emulator_bus.send("download-error", {file_index:q,file_count:n,file_name:r.url,request:D.target})},as_json:r.as_json})}}.bind(this);p(0)};X.prototype.zstd_decompress=function(a,b){const c=this.v86.cpu;this.zstd_context=c.zstd_create_ctx(b.length);(new Uint8Array(c.wasm_memory.buffer)).set(b,c.zstd_get_src_ptr(this.zstd_context));b=c.zstd_read(this.zstd_context,a);const d=c.wasm_memory.buffer.slice(b,b+a);c.zstd_read_free(b,a);c.zstd_free_ctx(this.zstd_context);this.zstd_context=null;return d}; X.prototype.zstd_decompress_worker=async function(a,b){if(!this.zstd_worker){const c=URL.createObjectURL(new Blob(["("+function(){let d;globalThis.onmessage=function(e){if(d){var {src:f,decompressed_size:g,id:h}=e.data;e=d.exports;var l=e.zstd_create_ctx(f.length);(new Uint8Array(e.memory.buffer)).set(f,e.zstd_get_src_ptr(l));var m=e.zstd_read(l,g),n=e.memory.buffer.slice(m,m+g);e.zstd_read_free(m,g);e.zstd_free_ctx(l);postMessage({result:n,id:h},[n])}else l=Object.fromEntries("cpu_exception_hook run_hardware_timers cpu_event_halt microtick get_rand_int apic_acknowledge_irq stop_idling io_port_read8 io_port_read16 io_port_read32 io_port_write8 io_port_write16 io_port_write32 mmap_read8 mmap_read16 mmap_read32 mmap_write8 mmap_write16 mmap_write32 mmap_write64 mmap_write128 codegen_finalize jit_clear_func jit_clear_all_funcs".split(" ").map(p=> [p,()=>console.error("zstd worker unexpectedly called "+p)])),l.__indirect_function_table=new WebAssembly.Table({element:"anyfunc",initial:1024}),l.abort=()=>{throw Error("zstd worker aborted");},l.log_from_wasm=l.console_log_from_wasm=(p,q)=>{console.log(String.fromCharCode(...(new Uint8Array(d.exports.memory.buffer,p,q))))},l.dbg_trace_from_wasm=()=>console.trace(),d=new WebAssembly.Instance(new WebAssembly.Module(e.data),{env:l})}}.toString()+")()"],{type:"text/javascript"}));this.zstd_worker= new Worker(c);URL.revokeObjectURL(c);this.zstd_worker.postMessage(this.wasm_source,[this.wasm_source])}return new Promise(c=>{const d=this.zstd_worker_request_id++,e=async f=>{f.data.id===d&&(this.zstd_worker.removeEventListener("message",e),c(f.data.result))};this.zstd_worker.addEventListener("message",e);this.zstd_worker.postMessage({src:b,decompressed_size:a,id:d},[b.buffer])})}; X.prototype.get_bzimage_initrd_from_filesystem=function(a){const b=(a.read_dir("/")||[]).map(e=>"/"+e);a=(a.read_dir("/boot/")||[]).map(e=>"/boot/"+e);let c,d;for(const e of[].concat(b,a)){const f=/old/i.test(e)||/fallback/i.test(e),g=/vmlinuz/i.test(e)||/bzimage/i.test(e),h=/initrd/i.test(e)||/initramfs/i.test(e);!g||d&&f||(d=e);!h||c&&f||(c=e)}c&&d||(console.log("Failed to find bzimage or initrd in filesystem. Files:"),console.log(b.join(" ")),console.log(a.join(" ")));return{initrd_path:c,bzimage_path:d}}; X.prototype.run=async function(){this.v86.run()};H.exportProperty(X.prototype,"run",X.prototype.run);X.prototype.stop=async function(){this.cpu_is_running&&await new Promise(a=>{const b=()=>{this.remove_listener("emulator-stopped",b);a()};this.add_listener("emulator-stopped",b);this.v86.stop()})};H.exportProperty(X.prototype,"stop",X.prototype.stop); X.prototype.destroy=async function(){await this.stop();this.v86.destroy();this.keyboard_adapter&&this.keyboard_adapter.destroy();this.network_adapter&&this.network_adapter.destroy();this.mouse_adapter&&this.mouse_adapter.destroy();this.screen_adapter&&this.screen_adapter.destroy();this.serial_adapter&&this.serial_adapter.destroy();this.speaker_adapter&&this.speaker_adapter.destroy()};H.exportProperty(X.prototype,"destroy",X.prototype.destroy);X.prototype.restart=function(){this.v86.restart()}; H.exportProperty(X.prototype,"restart",X.prototype.restart);X.prototype.add_listener=function(a,b){this.bus.register(a,b,this)};H.exportProperty(X.prototype,"add_listener",X.prototype.add_listener);X.prototype.remove_listener=function(a,b){this.bus.unregister(a,b)};H.exportProperty(X.prototype,"remove_listener",X.prototype.remove_listener);X.prototype.restore_state=async function(a){this.v86.restore_state(a)};H.exportProperty(X.prototype,"restore_state",X.prototype.restore_state); X.prototype.save_state=async function(){return this.v86.save_state()};H.exportProperty(X.prototype,"save_state",X.prototype.save_state);X.prototype.get_instruction_counter=function(){return this.v86?this.v86.cpu.instruction_counter[0]>>>0:0};H.exportProperty(X.prototype,"get_instruction_counter",X.prototype.get_instruction_counter);X.prototype.is_running=function(){return this.cpu_is_running};H.exportProperty(X.prototype,"is_running",X.prototype.is_running); X.prototype.set_fda=async function(a){if(a.url&&!a.async)t.load_file(a.url,{done:b=>{this.v86.cpu.devices.fdc.set_fda(new t.SyncBuffer(b))}});else{const b=t.buffer_from_object(a,this.zstd_decompress_worker.bind(this));b.onload=()=>{this.v86.cpu.devices.fdc.set_fda(b)};await b.load()}};H.exportProperty(X.prototype,"set_fda",X.prototype.set_fda);X.prototype.eject_fda=function(){this.v86.cpu.devices.fdc.eject_fda()};H.exportProperty(X.prototype,"eject_fda",X.prototype.eject_fda); X.prototype.keyboard_send_scancodes=function(a){for(var b=0;ba)throw Error("Failed to mount. Error number: "+-a);};H.exportProperty(X.prototype,"mount_fs",X.prototype.mount_fs);X.prototype.create_file=async function(a,b){var c=this.fs9p;if(c){var d=a.split("/");d=d[d.length-1];a=c.SearchPath(a).parentid;if(""!==d&&-1!==a)await c.CreateBinaryFile(d,a,b);else return Promise.reject(new Nb)}}; H.exportProperty(X.prototype,"create_file",X.prototype.create_file);X.prototype.read_file=async function(a){var b=this.fs9p;if(b)return(a=await b.read_file(a))?a:Promise.reject(new Nb)};H.exportProperty(X.prototype,"read_file",X.prototype.read_file); X.prototype.automatically=function(a){const b=c=>{const d=c[0];if(d){var e=c.slice(1);d.sleep?setTimeout(()=>b(e),1E3*d.sleep):d.vga_text?this.wait_until_vga_screen_contains(d.vga_text).then(()=>b(e)):d.keyboard_send?(d.keyboard_send instanceof Array?this.keyboard_send_scancodes(d.keyboard_send):this.keyboard_send_text(d.keyboard_send),b(e)):d.call&&(d.call(),b(e))}};b(a)}; X.prototype.wait_until_vga_screen_contains=function(a){return new Promise(b=>{function c(g){return"string"===typeof a?g.includes(a):a.test(g)}function d(g){[g]=g;e.add(g)}for(const g of this.screen_adapter.get_text_screen())if(c(g)){b(!0);return}const e=new Set,f=()=>{for(const g of e){const h=this.screen_adapter.get_text_row(g);if(c(h)){this.remove_listener("screen-put-char",d);b();return}}e.clear();setTimeout(f,100)};f();this.add_listener("screen-put-char",d)})}; X.prototype.read_memory=function(a,b){return this.v86.cpu.read_blob(a,b)};X.prototype.write_memory=function(a,b){this.v86.cpu.write_blob(a,b)};X.prototype.set_serial_container_xtermjs=function(a){this.serial_adapter&&this.serial_adapter.destroy&&this.serial_adapter.destroy();this.serial_adapter=new Gb(a,this.bus);this.serial_adapter.show()};function Ob(a){this.message=a||"File already exists"}Ob.prototype=Error.prototype;function Nb(a){this.message=a||"File not found"}Nb.prototype=Error.prototype; "undefined"!==typeof module&&"undefined"!==typeof module.exports?module.exports.V86=X:"undefined"!==typeof window?window.V86=X:"function"===typeof importScripts&&(self.V86=X);var Pb={Connector:function(a){this.listeners={};this.pair=a;a.addEventListener("message",function(b){b=b.data;for(var c=this.listeners[b[0]],d=0;da[b].toString(16)).map(b=>1===b.length?"0"+b:b).join(":")}function Wb(a){return a[0]<<24|a[1]<<16|a[2]<<8|a[3]} function Xb(a,b){let c=Date.now()+Sb,d=c%1E3/1E3*Tb,e={};e.eth={ethertype:2048,src:b.router_mac,dest:a.eth.src};e.ipv4={proto:17,src:a.ipv4.dest,dest:a.ipv4.src};e.udp={sport:123,dport:a.udp.sport};e.ntp=Object.assign({},a.ntp);e.ntp.flags=36;e.ntp.poll=10;e.ntp.ori_ts_i=a.ntp.trans_ts_i;e.ntp.ori_ts_f=a.ntp.trans_ts_f;e.ntp.rec_ts_i=c/1E3;e.ntp.rec_ts_f=d;e.ntp.trans_ts_i=c/1E3;e.ntp.trans_ts_f=d;e.ntp.stratum=2;b.receive(Yb(e));return!0} function Zb(a,b){let c={};c.eth={ethertype:2048,src:b.router_mac,dest:a.eth.src};c.ipv4={proto:17,src:b.router_ip,dest:b.vm_ip};c.udp={sport:67,dport:68};c.dhcp={htype:1,hlen:6,hops:0,xid:a.dhcp.xid,secs:0,flags:0,ciaddr:0,yiaddr:Wb(b.vm_ip),siaddr:Wb(b.router_ip),giaddr:Wb(b.router_ip),chaddr:a.dhcp.chaddr};let d=[],e=a.dhcp.options.find(function(f){return 53===f[0]});e&&3===e[2]&&(a.dhcp.op=3);1===a.dhcp.op&&(c.dhcp.op=2,d.push(new Uint8Array([53,1,2])));3===a.dhcp.op&&(c.dhcp.op=2,d.push(new Uint8Array([53, 1,5])),d.push(new Uint8Array([51,4,8,0,0,0])));a=[b.router_ip[0],b.router_ip[1],b.router_ip[2],b.router_ip[3]];d.push(new Uint8Array([1,4,255,255,255,0]));b.masquerade&&(d.push(new Uint8Array([3,4].concat(a))),d.push(new Uint8Array([6,4].concat(a))));d.push(new Uint8Array([54,4].concat(a)));d.push(new Uint8Array([60,3].concat(Ub)));d.push(new Uint8Array([255,0]));c.dhcp.options=d;b.receive(Yb(c))} function $b(a,b){var c=(new DataView(a.buffer,a.byteOffset,a.byteLength)).getUint16(12),d={ethertype:c,dest:a.subarray(0,6),dest_s:Vb(a.subarray(0,6)),src:a.subarray(6,12),src_s:Vb(a.subarray(6,12))};b.eth=d;a=a.subarray(14,a.length);if(2048===c){var e=new DataView(a.buffer,a.byteOffset,a.byteLength),f=a[0]>>4&15;d=a[0]&15;var g=e.getUint8(1),h=e.getUint16(2),l=e.getUint8(8);c=e.getUint8(9);e=e.getUint16(10);f={version:f,ihl:d,tos:g,len:h,ttl:l,proto:c,ip_checksum:e,src:a.subarray(12,16),dest:a.subarray(16, 20)};b.ipv4=f;a=a.subarray(4*d,h);1===c&&(d=a,h=new DataView(d.buffer,d.byteOffset,d.byteLength),d={type:h.getUint8(0),code:h.getUint8(1),checksum:h.getUint16(2),data:d.subarray(4)},b.icmp=d);6===c&&(d=a,f=new DataView(d.buffer,d.byteOffset,d.byteLength),h={sport:f.getUint16(0),dport:f.getUint16(2),seq:f.getUint32(4),ackn:f.getUint32(8),doff:f.getUint8(12)>>4,winsize:f.getUint16(14),checksum:f.getUint16(16),urgent:f.getUint16(18)},f=f.getUint8(13),h.fin=!!(f&1),h.syn=!!(f&2),h.rst=!!(f&4),h.psh=!!(f& 8),h.ack=!!(f&16),h.urg=!!(f&32),h.ece=!!(f&64),h.cwr=!!(f&128),b.tcp=h,b.tcp_data=d.subarray(4*h.doff));if(17===c){c=new DataView(a.buffer,a.byteOffset,a.byteLength);c={sport:c.getUint16(0),dport:c.getUint16(2),len:c.getUint16(4),checksum:c.getUint16(6),data:a.subarray(8),data_s:(new TextDecoder).decode(a.subarray(8))};if(67===c.dport||67===c.sport){h=a.subarray(8);d=new DataView(h.buffer,h.byteOffset,h.byteLength);h.subarray(44,236);d={op:d.getUint8(0),htype:d.getUint8(1),hlen:d.getUint8(2),hops:d.getUint8(3), xid:d.getUint32(4),secs:d.getUint16(8),flags:d.getUint16(10),ciaddr:d.getUint32(12),yiaddr:d.getUint32(16),siaddr:d.getUint32(20),giaddr:d.getUint32(24),chaddr:h.subarray(28,44),magic:d.getUint32(236),options:[]};h=h.subarray(240);for(f=0;fd;++d)c.setUint8(0+d,a.eth.dest[d]);for(d=0;6>d;++d)c.setUint8(6+d,a.eth.src[d]);c=14;if(a.arp){d=b.subarray(14);d=new DataView(d.buffer,d.byteOffset,d.byteLength);d.setUint16(0,a.arp.htype);d.setUint16(2,a.arp.ptype);d.setUint8(4,a.arp.sha.length);d.setUint8(5,a.arp.spa.length);d.setUint16(6,a.arp.oper);for(var e=0;6>e;++e)d.setUint8(8+e,a.arp.sha[e]),d.setUint8(18+ e,a.arp.tha[e]);for(e=0;4>e;++e)d.setUint8(14+e,a.arp.spa[e]),d.setUint8(24+e,a.arp.tpa[e]);c+=28}if(a.ipv4){e=b.subarray(14);d=new DataView(e.buffer,e.byteOffset,e.byteLength);var f=20;if(a.icmp){var g=e.subarray(20);g=new DataView(g.buffer,g.byteOffset,g.byteLength);g.setUint8(0,a.icmp.type);g.setUint8(1,a.icmp.code);g.setUint16(2,0);for(var h=0;hg;++g)f.setUint8(g,a.ipv4.src[g]),f.setUint8(4+g,a.ipv4.dest[g]);f.setUint8(9,6);f.setUint16(10,p);for(p=0;6>p;++p)n+=f.getUint16(p<<1),65535p;++p)n+=e.getUint16(p<<1),65535e;++e)d.setUint8(12+e,a.ipv4.src[e]),d.setUint8(16+e,a.ipv4.dest[e]);a=0;for(e=0;10>e;++e)a+=d.getUint16(e<<1),65535b||(this.on_data(a.tcp_data),this.pump()))};cc.prototype.write=function(a){if(0this.send_buffer.length&&(b.tcp.fin=!0);b.tcp.psh=!0;b.tcp_data=a;this.net.receive(Yb(b))}}; function dc(a,b){var c=Wb(a.arp.tpa)&4294967040;let d=Wb(b.router_ip)&4294967040;!b.masquerade&&c!==d||c===d&&99{this.process_incoming_wisp_frame(new Uint8Array(b.data))};this.wispws.onclose=()=>{setTimeout(()=>{this.register_ws(a)},1E4)}}; Jb.prototype.send_packet=function(a,b,c){0{0!==e.length&&this.send_wisp_frame({type:"DATA",stream_id:d.stream_id,data:e})};this.send_wisp_frame({type:"CONNECT", stream_id:d.stream_id,hostname:b.ipv4.dest.join("."),port:b.tcp.dport,data_callback:e=>{d.write(e)},close_callback:()=>{d.close()}});d.accept(b);return}if(!this.tcp_conn[c]){c=b.tcp.ackn;if(b.tcp.fin||b.tcp.syn)c+=1;a.tcp={sport:b.tcp.dport,dport:b.tcp.sport,seq:c,ackn:b.tcp.seq+(b.tcp.syn?1:0),winsize:b.tcp.winsize,rst:!0,ack:b.tcp.syn};this.receive(Yb(a));return}this.tcp_conn[c].process(b)}b.arp&&1===b.arp.oper&&2048===b.arp.ptype&&dc(b,this);b.dns&&(async()=>{let d={};d.eth={ethertype:2048,src:this.router_mac, dest:b.eth.src};d.ipv4={proto:17,src:this.router_ip,dest:b.ipv4.src};d.udp={sport:53,dport:b.udp.sport};const e=await (await fetch(`https://${this.doh_server}/dns-query`,{method:"POST",headers:[["content-type","application/dns-message"]],body:b.udp.data})).arrayBuffer();d.udp.data=new Uint8Array(e);this.receive(Yb(d))})();b.ntp?Xb(b,this):b.dhcp?Zb(b,this):b.udp&&8===b.udp.dport&&ec(b,this)};Jb.prototype.receive=function(a){this.bus.send("net"+this.id+"-receive",new Uint8Array(a))};function Ib(a,b){b=b||{};this.bus=a;this.id=b.id||0;this.router_mac=new Uint8Array((b.router_mac||"52:54:0:1:2:3").split(":").map(function(c){return parseInt(c,16)}));this.router_ip=new Uint8Array((b.router_ip||"192.168.86.1").split(".").map(function(c){return parseInt(c,10)}));this.vm_ip=new Uint8Array((b.vm_ip||"192.168.86.100").split(".").map(function(c){return parseInt(c,10)}));this.masquerade=void 0===b.masquerade||!!b.masquerade;this.vm_mac=new Uint8Array(6);this.tcp_conn={};this.cors_proxy= b.cors_proxy;this.bus.register("net"+this.id+"-mac",function(c){this.vm_mac=new Uint8Array(c.split(":").map(function(d){return parseInt(d,16)}))},this);this.bus.register("net"+this.id+"-send",function(c){this.send(c)},this)}Ib.prototype.destroy=function(){};Ib.prototype.on_tcp_connection=function(a,b,c){if(80===b.tcp.dport){let d=new cc;d.state="syn-received";d.net=this;d.on_data=fc;d.tuple=c;d.accept(b);a.tcp_conn[c]=d;return!0}return!1}; async function fc(a){if(a&&(this.read=this.read||"",(this.read+=(new TextDecoder).decode(a))&&-1!==this.read.indexOf("\r\n\r\n"))){var b=this.read.indexOf("\r\n\r\n");a=this.read.substring(0,b).split(/\r\n/);b=this.read.substring(b+4);this.read="";let c=a[0].split(" "),d;d=/^https?:/.test(c[1])?new URL(c[1]):new URL("http://host"+c[1]);"undefined"!==typeof window&&"http:"===d.protocol&&"https:"===window.location.protocol&&(d.protocol="https:");let e=new Headers;for(let l=1;l>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";return b+="MAX_EXTRA_BASIC_BLOCKS="+a.wm.exports.get_jit_config(3)+"\n"},print_instruction_counts:function(a){return[gc.print_instruction_counts_offset(a, !1,!1,!1,!1),gc.print_instruction_counts_offset(a,!0,!1,!1,!1),gc.print_instruction_counts_offset(a,!1,!0,!1,!1),gc.print_instruction_counts_offset(a,!1,!1,!0,!1),gc.print_instruction_counts_offset(a,!1,!1,!1,!0)].join("\n\n")},print_instruction_counts_offset:function(a,b,c,d,e){let f="";var g=[],h=b?"compiled":c?"jit exit":d?"unguarded register":e?"wasm size":"executed";for(let n=0;256>n;n++)for(let p=0;8>p;p++)for(const q of[!1,!0]){var l=a.wm.exports.get_opstats_buffer(b,c,d,e,n,!1,q,p);g.push({opcode:n, count:l,is_mem:q,fixed_g:p});l=a.wm.exports.get_opstats_buffer(b,c,d,e,n,!0,q,p);g.push({opcode:3840|n,count:l,is_mem:q,fixed_g:p})}a=0;b=new Set([38,46,54,62,100,101,102,103,240,242,243]);for(const {count:n,opcode:p}of g)b.has(p)||(a+=n);if(0===a)return"";c=new Uint32Array(256);b=new Uint32Array(256);for(const {opcode:n,count:p}of g)3840===(n&65280)?b[n&255]+=p:c[n&255]+=p;f=f+"------------------\nTotal: "+(a+"\n");const m=1E7Math.round(n/m)));d= String(d).length;f+=`Instruction counts ${h} (in ${m}):\n`;for(e=0;256>e;e++)f+=e.toString(16).padStart(2,"0")+":"+t.pads(Math.round(c[e]/m),d),f=15===e%16?f+"\n":f+" ";f=f+"\n"+`Instruction counts ${h} (0f, in ${m}):\n`;for(h=0;256>h;h++)f+=(h&255).toString(16).padStart(2,"0")+":"+t.pads(Math.round(b[h]/m),d),f=15===h%16?f+"\n":f+" ";f+="\n";g=g.filter(({count:n})=>n).sort(({count:n},{count:p})=>p-n);for(const {opcode:n,is_mem:p,fixed_g:q,count:r}of g.slice(0,200))g=n.toString(16)+"_"+q+(p?"_m": "_r"),f+=g+":"+(r/a*100).toFixed(2)+" ";return f+"\n"}};"undefined"!==typeof module&&"undefined"!==typeof module.exports&&(module.exports.print_stats=gc);function Lb(){this.filedata=new Map}Lb.prototype.read=async function(a,b,c){return(a=this.filedata.get(a))?a.subarray(b,b+c):null};Lb.prototype.cache=async function(a,b){this.filedata.set(a,b)};Lb.prototype.uncache=function(a){this.filedata.delete(a)};function Mb(a,b){b.endsWith("/")||(b+="/");this.storage=a;this.baseurl=b}Mb.prototype.load_from_server=function(a){return new Promise(b=>{t.load_file(this.baseurl+a,{done:async c=>{c=new Uint8Array(c);await this.cache(a,c);b(c)}})})}; Mb.prototype.read=async function(a,b,c){const d=await this.storage.read(a,b,c);return d?d:(await this.load_from_server(a)).subarray(b,b+c)};Mb.prototype.cache=async function(a,b){return await this.storage.cache(a,b)};Mb.prototype.uncache=function(a){this.storage.uncache(a)};var ea=32768,da=16384,fa=4;function Z(a,b){this.inodes=[];this.events=[];this.storage=a;this.qidcounter=b||{last_qidnumber:0};this.inodedata={};this.total_size=274877906944;this.used_size=0;this.mounts=[];this.CreateDirectory("",-1)}Z.prototype.get_state=function(){let a=[];a[0]=this.inodes;a[1]=this.qidcounter.last_qidnumber;a[2]=[];for(const [b,c]of Object.entries(this.inodedata))0===(this.inodes[b].mode&da)&&a[2].push([b,c]);a[3]=this.total_size;a[4]=this.used_size;return a=a.concat(this.mounts)}; Z.prototype.set_state=function(a){this.inodes=a[0].map(b=>{const c=new hc(0);c.set_state(b);return c});this.qidcounter.last_qidnumber=a[1];this.inodedata={};for(let [b,c]of a[2])c.buffer.byteLength!==c.byteLength&&(c=c.slice()),this.inodedata[b]=c;this.total_size=a[3];this.used_size=a[4];this.mounts=a.slice(5)};Z.prototype.AddEvent=function(a,b){var c=this.inodes[a];0===c.status||2===c.status?b():this.is_forwarder(c)?this.follow_fs(c).AddEvent(c.foreign_id,b):this.events.push({id:a,OnEvent:b})}; Z.prototype.HandleEvent=function(a){var b=this.inodes[a];this.is_forwarder(b)&&this.follow_fs(b).HandleEvent(b.foreign_id);b=[];for(var c=0;c>8;this.qid.version=a[11];this.qid.path=a[12];this.nlinks=a[13]}; Z.prototype.divert=function(a,b){const c=this.Search(a,b),d=this.inodes[c],e=new hc(-1);this.IsDirectory(c);Object.assign(e,d);const f=this.inodes.length;this.inodes.push(e);e.fid=f;this.is_forwarder(d)&&this.mounts[d.mount_id].backtrack.set(d.foreign_id,f);this.should_be_linked(d)&&(this.unlink_from_dir(a,b),this.link_under_dir(a,f,b));if(this.IsDirectory(c)&&!this.is_forwarder(d))for(const [g,h]of e.direntries)"."!==g&&".."!==g&&this.IsDirectory(h)&&this.inodes[h].direntries.set("..",f);this.inodedata[f]= this.inodedata[c];delete this.inodedata[c];d.direntries=new Map;d.nlinks=0;return f};Z.prototype.copy_inode=function(a,b){Object.assign(b,a,{fid:b.fid,direntries:b.direntries,nlinks:b.nlinks})};Z.prototype.CreateInode=function(){const a=Math.round(Date.now()/1E3),b=new hc(++this.qidcounter.last_qidnumber);b.atime=b.ctime=b.mtime=a;return b}; Z.prototype.CreateDirectory=function(a,b){var c=this.inodes[b];if(0<=b&&this.is_forwarder(c))return b=c.foreign_id,a=this.follow_fs(c).CreateDirectory(a,b),this.create_forwarder(c.mount_id,a);c=this.CreateInode();c.mode=511|da;0<=b&&(c.uid=this.inodes[b].uid,c.gid=this.inodes[b].gid,c.mode=this.inodes[b].mode&511|da);c.qid.type=da>>8;this.PushInode(c,b,a);this.NotifyListeners(this.inodes.length-1,"newdir");return this.inodes.length-1}; Z.prototype.CreateFile=function(a,b){var c=this.inodes[b];if(this.is_forwarder(c))return b=c.foreign_id,a=this.follow_fs(c).CreateFile(a,b),this.create_forwarder(c.mount_id,a);c=this.CreateInode();c.uid=this.inodes[b].uid;c.gid=this.inodes[b].gid;c.qid.type=ea>>8;c.mode=this.inodes[b].mode&438|ea;this.PushInode(c,b,a);this.NotifyListeners(this.inodes.length-1,"newfile");return this.inodes.length-1}; Z.prototype.CreateNode=function(a,b,c,d){var e=this.inodes[b];if(this.is_forwarder(e))return b=e.foreign_id,a=this.follow_fs(e).CreateNode(a,b,c,d),this.create_forwarder(e.mount_id,a);e=this.CreateInode();e.major=c;e.minor=d;e.uid=this.inodes[b].uid;e.gid=this.inodes[b].gid;e.qid.type=192;e.mode=this.inodes[b].mode&438;this.PushInode(e,b,a);return this.inodes.length-1}; Z.prototype.CreateSymlink=function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,a=this.follow_fs(d).CreateSymlink(a,b,c),this.create_forwarder(d.mount_id,a);d=this.CreateInode();d.uid=this.inodes[b].uid;d.gid=this.inodes[b].gid;d.qid.type=160;d.symlink=c;d.mode=40960;this.PushInode(d,b,a);return this.inodes.length-1}; Z.prototype.CreateTextFile=async function(a,b,c){var d=this.inodes[b];if(this.is_forwarder(d))return b=d.foreign_id,c=await this.follow_fs(d).CreateTextFile(a,b,c),this.create_forwarder(d.mount_id,c);d=this.CreateFile(a,b);b=this.inodes[d];a=new Uint8Array(c.length);b.size=c.length;for(b=0;bg)return g}var h=this.inodes[e],l=this.inodes[a];g=this.inodes[c];if(this.is_forwarder(l)||this.is_forwarder(g))if(this.is_forwarder(l)&&l.mount_id===g.mount_id){if(a=await this.follow_fs(l).Rename(l.foreign_id,b,g.foreign_id,d),0>a)return a}else{if(this.is_a_root(e)||!this.IsDirectory(e)&&1g)return g;await this.DeleteData(l);a=this.Unlink(a,b);if(0>a)return a}else this.unlink_from_dir(a,b),this.link_under_dir(c,e,d),h.qid.version++;this.NotifyListeners(e,"rename",{oldpath:f});return 0}; Z.prototype.Write=async function(a,b,c,d){this.NotifyListeners(a,"write");var e=this.inodes[a];if(this.is_forwarder(e))a=e.foreign_id,await this.follow_fs(e).Write(a,b,c,d);else{var f=await this.get_buffer(a);!f||f.lengthb.nlinks&&z.Debug("Error in filesystem: negative nlinks="+b.nlinks+" at id ="+a);if(this.IsDirectory(a)){b=this.GetInode(a);this.IsDirectory(a)&&0>this.GetParent(a)&&z.Debug("Error in filesystem: negative parent id "+a);for(const [c,d]of b.direntries){0===c.length&&z.Debug("Error in filesystem: inode with no name and id "+d);for(const e of c)32>e&&z.Debug("Error in filesystem: Unallowed char in filename")}}}}; Z.prototype.FillDirectory=function(a){var b=this.inodes[a];if(this.is_forwarder(b))this.follow_fs(b).FillDirectory(b.foreign_id);else{var c=0;for(const d of b.direntries.keys())c+=24+jc.encode(d).length;a=this.inodedata[a]=new Uint8Array(c);b.size=c;c=0;for(const [d,e]of b.direntries)b=this.GetInode(e),c+=v.Marshall(["Q","d","b","s"],[b.qid,c+13+8+1+2+jc.encode(d).length,b.mode>>12,d],a,c)}}; Z.prototype.RoundToDirentry=function(a,b){a=this.inodedata[a];if(b>=a.length)return a.length;let c=0;for(;;){const d=v.Unmarshall(["Q","d"],a,{offset:c})[1];if(d>b)break;c=d}return c};Z.prototype.IsDirectory=function(a){a=this.inodes[a];return this.is_forwarder(a)?this.follow_fs(a).IsDirectory(a.foreign_id):(a.mode&61440)===da}; Z.prototype.IsEmpty=function(a){a=this.inodes[a];if(this.is_forwarder(a))return this.follow_fs(a).IsDirectory(a.foreign_id);for(const b of a.direntries.keys())if("."!==b&&".."!==b)return!1;return!0};Z.prototype.GetChildren=function(a){this.IsDirectory(a);a=this.inodes[a];if(this.is_forwarder(a))return this.follow_fs(a).GetChildren(a.foreign_id);const b=[];for(const c of a.direntries.keys())"."!==c&&".."!==c&&b.push(c);return b}; Z.prototype.GetParent=function(a){this.IsDirectory(a);a=this.inodes[a];if(this.should_be_linked(a))return a.direntries.get("..");const b=this.follow_fs(a).GetParent(a.foreign_id);return this.get_forwarder(a.mount_id,b)}; Z.prototype.PrepareCAPs=function(a){a=this.GetInode(a);if(a.caps)return a.caps.length;a.caps=new Uint8Array(20);a.caps[0]=0;a.caps[1]=0;a.caps[2]=0;a.caps[3]=2;a.caps[4]=255;a.caps[5]=255;a.caps[6]=255;a.caps[7]=255;a.caps[8]=255;a.caps[9]=255;a.caps[10]=255;a.caps[11]=255;a.caps[12]=63;a.caps[13]=0;a.caps[14]=0;a.caps[15]=0;a.caps[16]=63;a.caps[17]=0;a.caps[18]=0;a.caps[19]=0;return a.caps.length};function kc(a){this.fs=a;this.backtrack=new Map} kc.prototype.get_state=function(){const a=[];a[0]=this.fs;a[1]=[...this.backtrack];return a};kc.prototype.set_state=function(a){this.fs=a[0];this.backtrack=new Map(a[1])};Z.prototype.set_forwarder=function(a,b,c){const d=this.inodes[a];this.is_forwarder(d)&&this.mounts[d.mount_id].backtrack.delete(d.foreign_id);d.status=5;d.mount_id=b;d.foreign_id=c;this.mounts[b].backtrack.set(c,a)}; Z.prototype.create_forwarder=function(a,b){const c=this.CreateInode(),d=this.inodes.length;this.inodes.push(c);c.fid=d;this.set_forwarder(d,a,b);return d};Z.prototype.is_forwarder=function(a){return 5===a.status};Z.prototype.is_a_root=function(a){return 0===this.GetInode(a).fid};Z.prototype.get_forwarder=function(a,b){const c=this.mounts[a].backtrack.get(b);return void 0===c?this.create_forwarder(a,b):c};Z.prototype.delete_forwarder=function(a){this.is_forwarder(a);a.status=-1;this.mounts[a.mount_id].backtrack.delete(a.foreign_id)}; Z.prototype.follow_fs=function(a){const b=this.mounts[a.mount_id];this.is_forwarder(a);return b.fs};Z.prototype.Mount=function(a,b){a=this.SearchPath(a);if(-1===a.parentid)return-2;if(-1!==a.id)return-17;if(a.forward_path){var c=this.inodes[a.parentid];b=this.follow_fs(c).Mount(a.forward_path,b);return 0>b?b:this.get_forwarder(c.mount_id,b)}c=this.mounts.length;this.mounts.push(new kc(b));b=this.create_forwarder(c,0);this.link_under_dir(a.parentid,b,a.name);return b}; function ic(){this.type=2;this.start=0;this.length=Infinity;this.proc_id=-1;this.client_id=""}ic.prototype.get_state=function(){const a=[];a[0]=this.type;a[1]=this.start;a[2]=Infinity===this.length?0:this.length;a[3]=this.proc_id;a[4]=this.client_id;return a};ic.prototype.set_state=function(a){this.type=a[0];this.start=a[1];this.length=0===a[2]?Infinity:a[2];this.proc_id=a[3];this.client_id=a[4]};ic.prototype.clone=function(){const a=new ic;a.set_state(this.get_state());return a}; ic.prototype.conflicts_with=function(a){return this.proc_id===a.proc_id&&this.client_id===a.client_id||2===this.type||2===a.type||1!==this.type&&1!==a.type||this.start+this.length<=a.start||a.start+a.length<=this.start?!1:!0};ic.prototype.is_alike=function(a){return a.proc_id===this.proc_id&&a.client_id===this.client_id&&a.type===this.type};ic.prototype.may_merge_after=function(a){return this.is_alike(a)&&a.start+a.length===this.start}; Z.prototype.DescribeLock=function(a,b,c,d,e){const f=new ic;f.type=a;f.start=b;f.length=c;f.proc_id=d;f.client_id=e;return f};Z.prototype.GetLock=function(a,b){a=this.inodes[a];if(this.is_forwarder(a)){var c=a.foreign_id;return this.follow_fs(a).GetLock(c,b)}for(c of a.locks)if(b.conflicts_with(c))return c.clone();return null}; Z.prototype.Lock=function(a,b,c){const d=this.inodes[a];if(this.is_forwarder(d))return a=d.foreign_id,this.follow_fs(d).Lock(a,b,c);b=b.clone();if(2!==b.type&&this.GetLock(a,b))return 1;for(c=0;c=f&&0=f&&(d.locks.splice(c,1),c--)}if(2!==b.type){c=b;a=!1;for(e=0;e"."!==b&&".."!==b)};Z.prototype.read_file=function(a){a=this.SearchPath(a);if(-1===a.id)return Promise.resolve(null);const b=this.GetInode(a.id);return this.Read(a.id,0,b.size)};var z={Debug:function(a){[].slice.apply(arguments).join(" ")},Abort:function(){}};var v={};const lc=new TextDecoder,jc=new TextEncoder; v.Marshall=function(a,b,c,d){for(var e,f=0,g=0;g>8&255;c[d++]=e>>16&255;c[d++]=e>>24&255;f+=4;break;case "d":c[d++]=e&255;c[d++]=e>>8&255;c[d++]=e>>16&255;c[d++]=e>>24&255;c[d++]=0;c[d++]=0;c[d++]=0;c[d++]=0;f+=8;break;case "h":c[d++]=e&255;c[d++]=e>>8;f+=2;break;case "b":c[d++]=e;f+=1;break;case "s":var h=d,l=0;c[d++]=0;c[d++]=0;f+=2;e=jc.encode(e);f+=e.byteLength;l+=e.byteLength;c.set(e,d);d+=e.byteLength;c[h+0]=l&255;c[h+1]=l>>8& 255;break;case "Q":v.Marshall(["b","w","d"],[e.type,e.version,e.path],c,d);d+=13;f+=13;break;default:z.Debug("Marshall: Unknown type="+a[g])}return f}; v.Unmarshall=function(a,b,c){let d=c.offset;for(var e=[],f=0;f>>0;e.push(g);break;case "d":g=b[d++];g+=b[d++]<<8;g+=b[d++]<<16;g+=b[d++]<<24>>>0;d+=4;e.push(g);break;case "h":g=b[d++];e.push(g+(b[d++]<<8));break;case "b":e.push(b[d++]);break;case "s":g=b[d++];g+=b[d++]<<8;var h=b.slice(d,d+g);d+=g;e.push(lc.decode(h));break;case "Q":c.offset=d;g=v.Unmarshall(["b","w","d"],b,c);d=c.offset;e.push({type:g[0],version:g[1], path:g[2]});break;default:z.Debug("Error in Unmarshall: Unknown type="+a[f])}c.offset=d;return e};}).call(this);