diff --git a/.claude/skills/update-v86/SKILL.md b/.claude/skills/update-v86/SKILL.md index 2a38149..95bcfcc 100644 --- a/.claude/skills/update-v86/SKILL.md +++ b/.claude/skills/update-v86/SKILL.md @@ -23,7 +23,7 @@ fallbacks, no fetching from copy.sh. ## The fork branch v86 should be checked out on **`felixrieseberg/v86:windows95-base`**. -That branch merges two bugfix branches, each with an open upstream PR: +That branch merges three feature branches, each upstreamable on its own: - **`electron-renderer-fs-loader`** (PR #1540) — `src/lib.js` uses `require("fs")` instead of `await import("node:fs/promises")`. Dynamic @@ -35,6 +35,11 @@ That branch merges two bugfix branches, each with an open upstream PR: writes to target only `current_interface`, but per ATA spec they're channel-shared (one register file on the IDE cable; both drives latch the same value). +- **`vmware-abspointer`** — `src/vmware.js` implements the VMware mouse + backdoor (port `0x5658`, GETVERSION + ABSPOINTER_*) so a guest driver + (VBADOS VBMOUSE) can read absolute cursor position and track the host + cursor 1:1 without pointer lock. Consumes the `mouse-absolute` bus + event that `MouseAdapter` already emits. ## Prerequisites diff --git a/guest-tools/README.md b/guest-tools/README.md new file mode 100644 index 0000000..cb58cf6 --- /dev/null +++ b/guest-tools/README.md @@ -0,0 +1,23 @@ +# guest-tools + +Files and folders in this directory are exposed read-only inside the VM at +`\\HOST\TOOLS` (alongside the synthetic `_MAPZ.BAT` and `README.TXT`). +Drop drivers and utilities here that you want available from within +Windows 95. + +## mouse-driver/ — seamless mouse (VBADOS) + +`VBMOUSE.EXE` (DOS TSR) + `VBMOUSE.DRV` (Windows 3.x/9x driver) from +[VBADOS](https://git.javispedro.com/cgit/vbados.git/) by Javier S. Pedro, +GPLv2. Talks to v86's VMware mouse backdoor (port 0x5658) so the Windows +95 cursor tracks the host cursor pixel-for-pixel without pointer lock. + +Install inside the guest: + +1. Copy `\\HOST\TOOLS\mouse-driver\VBMOUSE.EXE` to `C:\` and add a + `C:\VBMOUSE.EXE` line to `C:\AUTOEXEC.BAT`. +2. Windows Setup (or Control Panel → Mouse → General → Change → Have + Disk) → browse to `\\HOST\TOOLS\mouse-driver` → pick **VBMouse int33 + absolute mouse driver**. +3. Reboot. The app detects the driver and stops grabbing pointer lock; + ESC still toggles lock for games that want raw relative input. diff --git a/guest-tools/mouse-driver/LICENSE.TXT b/guest-tools/mouse-driver/LICENSE.TXT new file mode 100644 index 0000000..81754c7 --- /dev/null +++ b/guest-tools/mouse-driver/LICENSE.TXT @@ -0,0 +1,6 @@ +VBMouse - DOS/Windows absolute mouse driver +Copyright (C) 2022 Javier S. Pedro +Licensed under the GNU General Public License, version 2 or later. + +Source: https://git.javispedro.com/cgit/vbados.git/ +Binaries extracted from https://depot.javispedro.com/vbox/vbados/vbados.flp diff --git a/guest-tools/mouse-driver/OEMSETUP.INF b/guest-tools/mouse-driver/OEMSETUP.INF new file mode 100644 index 0000000..db56056 --- /dev/null +++ b/guest-tools/mouse-driver/OEMSETUP.INF @@ -0,0 +1,8 @@ +[data] + Version = "3.0" + +[disks] + 1 =., "VBADOS driver disk", disk1 + +[pointing.device] + vbmouse = 1:vbmouse.drv, "VBMouse int33 absolute mouse driver", x:*vmd, vbmouse diff --git a/guest-tools/mouse-driver/VBMOUSE.DRV b/guest-tools/mouse-driver/VBMOUSE.DRV new file mode 100644 index 0000000..7024e05 Binary files /dev/null and b/guest-tools/mouse-driver/VBMOUSE.DRV differ diff --git a/guest-tools/mouse-driver/VBMOUSE.EN b/guest-tools/mouse-driver/VBMOUSE.EN new file mode 100644 index 0000000..3febaba --- /dev/null +++ b/guest-tools/mouse-driver/VBMOUSE.EN @@ -0,0 +1,54 @@ +# Language: English +# Codepage: 437 +# +# Spaces before text must be kept. Be sure that no spaces are +# added to the end of the lines. +# +0.0:Usage: +0.1: VBMOUSE +0.2:Supported actions and options: +0.3: install Install the driver (default). +0.4: low Install in conventional memory (otherwise UMB). +0.5: uninstall Uninstall the driver from memory. +0.6: wheel Enable/disable wheel API support. +0.7: wheelkey Emulate a specific keystroke on wheel scroll. +0.8: Supported keys: updn, pageupdn. +0.9: integ Enable/disable VirtualBox integration. +0.10: hostcur Enable/disable mouse cursor rendering in the host. +0.11: reset Reset mouse driver. +1.0:Wheel mouse found and enabled\n +1.1:Setting wheel support to %s\n +1.2:enabled +1.3:disabled +1.4:Generate Up Arrow / Down Arrow key presses on wheel movement\n +1.5:Generate PageUp / PageDown key presses on wheel movement\n +1.6:Disabling wheel keystroke generation\n +1.7:VirtualBox integration enabled\n +1.8:Disabled VirtualBox integration\n +1.9:VirtualBox integration already disabled or not available\n +1.10:Setting host cursor to %s\n +1.11:Found VMware protocol version %ld\n +1.12:VMware integration enabled\n +1.13:Disabled VMware integration\n +1.14:VMware integration already disabled or not available\n +1.15:Neither VirtualBox nor VMware integration available\n +1.16:VirtualBox integration not available\n +1.17:Driver installed\n +1.18:Driver uninstalled\n +1.19:Reset mouse driver\n +1.20:\nVBMouse %x.%x (like MSMOUSE %x.%x)\n +1.21:VBMouse already installed\n +3.0:Could not find PS/2 wheel mouse\n +3.1:Wheel not detected or support not enabled\n +3.2:Unknown key '%s'\n +3.3:Cannot find VirtualBox PCI device, err=%d\n +3.4:Cannot lock buffer used for VirtualBox communication, err=%d\n +3.5:VirtualBox communication is not working, err=%d\n +3.6:Could not detect VMware, err=%ld\n +3.7:VMware absolute pointer error, err=0x%lx\n +3.8:Cannot init PS/2 mouse BIOS, err=%d\n +3.9:INT33 has been hooked by someone else, cannot safely remove\n +3.10:INT2F has been hooked by someone else, cannot safely remove\n +3.11:Driver data not found (driver not installed?)\n +3.12:Invalid argument '%s'\n +3.13:Argument required for '%s'\n diff --git a/guest-tools/mouse-driver/VBMOUSE.EXE b/guest-tools/mouse-driver/VBMOUSE.EXE new file mode 100644 index 0000000..811ccf0 Binary files /dev/null and b/guest-tools/mouse-driver/VBMOUSE.EXE differ diff --git a/src/constants.ts b/src/constants.ts index d327a44..dad90e0 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -7,6 +7,7 @@ export const CONSTANTS = { IMAGE_PATH: path.join(IMAGES_PATH, "windows95.img"), IMAGE_DEFAULT_SIZE: 1073741824, // 1GB DEFAULT_STATE_PATH: path.join(IMAGES_PATH, "default-state.bin"), + TOOLS_PATH: path.join(__dirname, "../../guest-tools"), }; export const IPC_COMMANDS = { diff --git a/src/css/emulator.css b/src/css/emulator.css index 5009dc6..94af618 100644 --- a/src/css/emulator.css +++ b/src/css/emulator.css @@ -13,6 +13,13 @@ display: none; margin: auto; } + + /* Guest absolute-mouse driver active: hide the host cursor over the VM so + only the Windows 95 cursor shows. Has to beat `* { cursor: default }`. */ + &.seamless-mouse, + &.seamless-mouse * { + cursor: none; + } } .paused { diff --git a/src/renderer/emulator.tsx b/src/renderer/emulator.tsx index fbcb447..c9cc789 100644 --- a/src/renderer/emulator.tsx +++ b/src/renderer/emulator.tsx @@ -36,6 +36,7 @@ export interface EmulatorState { smbSharePath: string; isBootingFresh: boolean; isCursorCaptured: boolean; + hasAbsoluteMouse: boolean; isInfoDisplayed: boolean; isRunning: boolean; infoBarSettings: InfoBarSettings; @@ -44,6 +45,9 @@ export interface EmulatorState { export class Emulator extends React.Component<{}, EmulatorState> { private isQuitting = false; private isResetting = false; + // Mirrors state.hasAbsoluteMouse but updated synchronously — setState is + // batched, and the lock/unlock decisions can't wait for a render. + private absoluteMouse = false; constructor(props: {}) { super(props); @@ -57,6 +61,7 @@ export class Emulator extends React.Component<{}, EmulatorState> { this.state = { isBootingFresh: PROBE, isCursorCaptured: false, + hasAbsoluteMouse: false, isRunning: false, currentUiCard: "start", isInfoDisplayed: true, @@ -105,21 +110,24 @@ export class Emulator extends React.Component<{}, EmulatorState> { // Click document.addEventListener("click", () => { - const { isRunning } = this.state; - - if (isRunning) { + if (this.state.isRunning && !this.absoluteMouse) { this.lockMouse(); } }); // Only forward mouse input to the VM while the pointer is actually - // captured. Browsers can release pointer lock on their own (Esc, focus - // loss), so we sync v86's mouse status off the real lock state instead of + // captured (or while the guest's absolute-pointer driver is active — + // VBMOUSE/vmwmouse via the VMware backdoor — in which case the guest + // cursor tracks the host cursor 1:1 and we don't need pointer lock at + // all). Browsers can release pointer lock on their own (Esc, focus loss), + // so we sync v86's mouse status off the real lock state instead of // assuming our lock/unlock calls succeeded. document.addEventListener("pointerlockchange", () => { const isCursorCaptured = !!document.pointerLockElement; this.setState({ isCursorCaptured }); - this.state.emulator?.mouse_set_status(isCursorCaptured); + this.state.emulator?.mouse_set_status( + isCursorCaptured || this.absoluteMouse, + ); }); } @@ -267,7 +275,10 @@ export class Emulator extends React.Component<{}, EmulatorState> { <> {this.renderInfo()} {this.renderUI()} -
+
@@ -371,7 +382,7 @@ export class Emulator extends React.Component<{}, EmulatorState> { // probe harness can point at a fixture dir without touching settings. const smbRoot = process.env.WIN95_SMB_SHARE || this.state.smbSharePath; if (smbRoot) { - setupSmbShare(window["emulator"], smbRoot); + setupSmbShare(window["emulator"], smbRoot, CONSTANTS.TOOLS_PATH); } if (PROBE) { @@ -379,9 +390,17 @@ export class Emulator extends React.Component<{}, EmulatorState> { } // New v86 instance - // Mouse stays disabled until the pointerlockchange listener confirms the - // cursor is actually captured. + // Mouse stays disabled until either the pointer is captured or the guest's + // VMware-backdoor mouse driver requests absolute mode. window["emulator"].mouse_set_status(false); + window["emulator"].add_listener("vmware-absolute-mouse", (on: boolean) => { + this.absoluteMouse = on; + this.setState({ hasAbsoluteMouse: on }); + window["emulator"].mouse_set_status(on || !!document.pointerLockElement); + if (on && document.pointerLockElement) { + this.unlockMouse(); + } + }); this.setState({ emulator: window["emulator"], isRunning: true, @@ -397,7 +416,6 @@ export class Emulator extends React.Component<{}, EmulatorState> { this.restoreState(); } - this.lockMouse(); this.state.emulator.run(); this.state.emulator.screen_set_scale(this.state.scale); }, 500); diff --git a/src/renderer/lib/libv86.js b/src/renderer/lib/libv86.js index ba29af1..fbf1008 100644 --- a/src/renderer/lib/libv86.js +++ b/src/renderer/lib/libv86.js @@ -11,21 +11,21 @@ e.setRequestHeader("Range","bytes="+f+"-"+(f+b.range.length-1)),e.setRequestHead 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)},pa=async function(a){return new Promise((b,c)=>{oa(a,{done:(d,e)=>{d=e.getResponseHeader("Content-Range")||"";(e=d.match(/\/(\d+)\s*$/))?b(+e[1]):c(Error("`Range: bytes=...` header not supported (Got `"+d+"`)"))}, headers:{Range:"bytes=0-0","X-Accept-Encoding":"identity"}})})};function qa(a,b,c){return String.fromCharCode(...(new Uint8Array(a.buffer,b>>>0,c>>>0)))} const ra={cp437:" \u263a\u263b\u2665\u2666\u2663\u2660\u2022\u25d8\u25cb\u25d9\u2642\u2640\u266a\u266b\u263c\u25ba\u25c4\u2195\u203c\u00b6\u00a7\u25ac\u21a8\u2191\u2193\u2192\u2190\u221f\u2194\u25b2\u25bc !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u2302\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00a2\u00a3\u00a5\u20a7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u2310\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580\u03b1\u00df\u0393\u03c0\u03a3\u03c3\u00b5\u03c4\u03a6\u0398\u03a9\u03b4\u221e\u03c6\u03b5\u2229\u2261\u00b1\u2265\u2264\u2320\u2321\u00f7\u2248\u00b0\u2219\u00b7\u221a\u207f\u00b2\u25a0 ",cp858:"\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00f8\u00a3\u00d8\u00d7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00d1\u00aa\u00ba\u00bf\u00ae\u00ac\u00bd\u00bc\u00a1\u00ab\u00bb\u2591\u2592\u2593\u2502\u2524\u00c1\u00c2\u00c0\u00a9\u2563\u2551\u2557\u255d\u00a2\u00a5\u2510\u2514\u2534\u252c\u251c\u2500\u253c\u00e3\u00c3\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u00a4\u00f0\u00d0\u00ca\u00cb\u00c8\u20ac\u00cd\u00ce\u00cf\u2518\u250c\u2588\u2584\u00a6\u00cc\u2580\u00d3\u00df\u00d4\u00d2\u00f5\u00d5\u00b5\u00fe\u00de\u00da\u00db\u00d9\u00fd\u00dd\u00af\u00b4\u00ad\u00b1\u2017\u00be\u00b6\u00a7\u00f7\u00b8\u00b0\u00a8\u00b7\u00b9\u00b3\u00b2\u25a0 "}; -ra.cp858=ra.cp437.slice(0,128)+ra.cp858;ra.ascii=ra.cp437.split("").map((a,b)=>31b?a:".").join("");function sa(a){return a&&ra[a]?ra[a]:ra.cp437};function ua(){}function va(){};function wa(a,b){function c(w){w=w.toString(16);return"#"+"0".repeat(6-w.length)+w}function d(w){var u=256*na,H=8*R,K=Ta?Ta.canvas:null;K&&K.width===u&&K.height===H||(K?(K.width=u,K.height=H):(K=new OffscreenCanvas(u,H),Ta=K.getContext("2d")),Kb=Ta.createImageData(u,H));const Q=Kb.data;let P=0,S;H=Lb?function(Z){S=S||Z;Q[P+3]=Z;Q[P+7]=Z;P+=8}:function(Z){S=S||Z;Q[P+3]=Z;P+=4};K=32-R;const ja=u*(R-1)*4;u=4*(na-u*R);const fa=1020*na;for(let Z=0,Ea=0;2048>Z;++Z,Ea+=K,P+=u){const Fa=Z%256;Z&&!Fa&&(P+= -ja);S=!1;for(let La=0;La>=1)H(Ma&ta?255:0);Mb&&H(Nb&&192<=Fa&&223>=Fa&&Ma&1?255:0)}fc[Z]=S?1:0}Ta.putImageData(Kb,0,0)}function e(w,u,H,K){if(u&&H){w.style.width="";w.style.height="";K&&(w.style.transform="");var Q=w.getBoundingClientRect();K?w.style.transform=(1===u?"":" scaleX("+u+")")+(1===H?"":" scaleY("+H+")"):(0===u%1&&0===H%1?(g.style.imageRendering="crisp-edges",g.style.imageRendering="pixelated",g.style["-ms-interpolation-mode"]="nearest-neighbor"): +ra.cp858=ra.cp437.slice(0,128)+ra.cp858;ra.ascii=ra.cp437.split("").map((a,b)=>31b?a:".").join("");function sa(a){return a&&ra[a]?ra[a]:ra.cp437};function ua(){}function va(){};function wa(a,b){function c(w){w=w.toString(16);return"#"+"0".repeat(6-w.length)+w}function d(w){var u=256*na,H=8*R,K=Ta?Ta.canvas:null;K&&K.width===u&&K.height===H||(K?(K.width=u,K.height=H):(K=new OffscreenCanvas(u,H),Ta=K.getContext("2d")),Lb=Ta.createImageData(u,H));const Q=Lb.data;let P=0,S;H=Mb?function(Z){S=S||Z;Q[P+3]=Z;Q[P+7]=Z;P+=8}:function(Z){S=S||Z;Q[P+3]=Z;P+=4};K=32-R;const ja=u*(R-1)*4;u=4*(na-u*R);const fa=1020*na;for(let Z=0,Ea=0;2048>Z;++Z,Ea+=K,P+=u){const Fa=Z%256;Z&&!Fa&&(P+= +ja);S=!1;for(let La=0;La>=1)H(Ma&ta?255:0);Nb&&H(Ob&&192<=Fa&&223>=Fa&&Ma&1?255:0)}gc[Z]=S?1:0}Ta.putImageData(Lb,0,0)}function e(w,u,H,K){if(u&&H){w.style.width="";w.style.height="";K&&(w.style.transform="");var Q=w.getBoundingClientRect();K?w.style.transform=(1===u?"":" scaleX("+u+")")+(1===H?"":" scaleY("+H+")"):(0===u%1&&0===H%1?(g.style.imageRendering="crisp-edges",g.style.imageRendering="pixelated",g.style["-ms-interpolation-mode"]="nearest-neighbor"): (g.style.imageRendering="",g.style["-ms-interpolation-mode"]=""),K=window.devicePixelRatio||1,0!==K%1&&(u/=K,H/=K));1!==u&&(w.style.width=Q.width*u+"px");1!==H&&(w.style.height=Q.height*H+"px")}}const f=a.container;this.screen_fill_buffer=b;console.assert(f,"options.container must be provided");this.FLAG_BLINKING=1;this.FLAG_FONT_PAGE_B=2;let g=f.getElementsByTagName("canvas")[0];g||(g=document.createElement("canvas"),f.appendChild(g));const h=g.getContext("2d",{alpha:!1});let l=f.getElementsByTagName("div")[0]; -l||(l=document.createElement("div"),f.appendChild(l));const m=document.createElement("div");var n,p,q=void 0!==a.scale?a.scale:1,r=void 0!==a.scale?a.scale:1,x=1,C,t,A,M,v,L,T,Ta,Kb,fc=new Int8Array(2048),R,na,Mb,Lb,Nb,Ob=0,Pb=0,sb,gc=0,tb,Qb,ub,Rb=sa(a.encoding),vb=0,Sb=!1;this.init=function(){m.classList.add("cursor");m.style.position="absolute";m.style.backgroundColor="#ccc";m.style.width="7px";m.style.display="inline-block";this.set_mode(!1);this.set_size_text(80,25);2===t&&this.set_size_graphical(720, -400,720,400);this.set_scale(q,r);this.timer()};this.make_screenshot=function(){const w=new Image;if(1===t||2===t)w.src=g.toDataURL("image/png");else{const u=[9,16],H=document.createElement("canvas");H.width=M*u[0];H.height=v*u[1];const K=H.getContext("2d");K.imageSmoothingEnabled=!1;K.font=window.getComputedStyle(l).font;K.textBaseline="top";for(let Q=0;Qthis.update_screen())};this.update_screen=function(){Sb||(0===t?this.update_text():1===t?this.update_graphical():this.update_graphical_text()); -this.timer()};this.update_text=function(){for(var w=0;wthis.update_screen())};this.update_screen=function(){Tb||(0===t?this.update_text():1===t?this.update_graphical():this.update_graphical_text()); +this.timer()};this.update_text=function(){for(var w=0;wu;)l.removeChild(l.firstChild);for(;l.childNodes.length=w&&2*w=w&&2*wthis.pump(),1E3*b);a.start(this.buffered_time);this.buffered_time+=c;setTimeout(()=>this.pump(),0)};kb.prototype.pump=function(){this.enabled&&(.2a)){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)}}};ob.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())};ob.prototype.change_proxy=function(a){this.url=a;this.socket&&(this.socket.onclose=function(){},this.socket.onerror=function(){},this.socket.close(),this.socket=void 0)};const pb=(new Date("1970-01-01T00:00:00Z")).getTime(),qb=(new Date("1900-01-01T00:00:00Z")).getTime(),rb=pb-qb,wb=Math.pow(2,32),xb=[118,56,54];function yb(a){return[0,1,2,3,4,5].map(b=>a[b].toString(16)).map(b=>1===b.length?"0"+b:b).join(":")}function zb(a){return a[0]<<24|a[1]<<16|a[2]<<8|a[3]} +this.socket.onerror=this.handle_error.bind(this)}}};ob.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())};ob.prototype.change_proxy=function(a){this.url=a;this.socket&&(this.socket.onclose=function(){},this.socket.onerror=function(){},this.socket.close(),this.socket=void 0)};const pb=(new Date("1970-01-01T00:00:00Z")).getTime(),qb=(new Date("1900-01-01T00:00:00Z")).getTime(),rb=pb-qb,sb=Math.pow(2,32),xb=[118,56,54];function yb(a){return[0,1,2,3,4,5].map(b=>a[b].toString(16)).map(b=>1===b.length?"0"+b:b).join(":")}function zb(a){return a[0]<<24|a[1]<<16|a[2]<<8|a[3]} class Ab{constructor(a,b){a=Math.min(a,16);this.maximum_capacity=b?Math.max(b,a):0;this.length=this.head=this.tail=0;this.buffer=new Uint8Array(a)}write(a){const b=a.length;var c=this.length+b;let d=this.buffer.length;if(dthis.maximum_capacity)throw Error("stream capacity overflow in GrowableRingbuffer.write(), package dropped");c=new Uint8Array(d);this.peek(c);this.tail=0;this.head=this.length;this.buffer=c}c=this.buffer;const e=this.head+b;if(e>d){const f= d-this.head;c.set(a.subarray(0,f),this.head);c.set(a.subarray(f))}else c.set(a,this.head);this.head=e%d;this.length+=b}peek(a){const b=Math.min(this.length,a.length);if(b){const e=this.buffer;var c=e.length,d=this.tail+b;d>c?(d%=c,c-=this.tail,a.set(e.subarray(this.tail)),a.set(e.subarray(0,d),c)):a.set(e.subarray(this.tail,d))}return b}remove(a){a>this.length&&(a=this.length);a&&(this.tail=(this.tail+a)%this.buffer.length,this.length-=a);return a}} function Bb(a=1500){const b=a-20,c=b-8,d=new Uint8Array(14+a+4),e=d.buffer,f=d.byteOffset;return{eth_frame:d,eth_frame_view:new DataView(e),eth_payload_view:new DataView(e,f+14,a),ipv4_payload_view:new DataView(e,f+34,b),udp_payload_view:new DataView(e,f+42,c),text_encoder:new TextEncoder}}function Cb(a,b,c,d){d.eth_frame.set(b,c.byteOffset+a);return b.length} @@ -193,14 +193,14 @@ hlen:d.getUint8(2),hops:d.getUint8(3),xid:d.getUint32(4),secs:d.getUint16(8),fla d.byteOffset,d.byteLength),c.ntp={flags:d.getUint8(0),stratum:d.getUint8(1),poll:d.getUint8(2),precision:d.getUint8(3),root_delay:d.getUint32(4),root_disp:d.getUint32(8),ref_id:d.getUint32(12),ref_ts_i:d.getUint32(16),ref_ts_f:d.getUint32(20),ori_ts_i:d.getUint32(24),ori_ts_f:d.getUint32(28),rec_ts_i:d.getUint32(32),rec_ts_f:d.getUint32(36),trans_ts_i:d.getUint32(40),trans_ts_f:d.getUint32(44)});c.udp=a}}else 2054===d?(d=new DataView(a.buffer,a.byteOffset,a.byteLength),a={htype:d.getUint16(0),ptype:d.getUint16(2), oper:d.getUint16(6),sha:a.subarray(8,14),spa:a.subarray(14,18),tha:a.subarray(18,24),tpa:a.subarray(24,28)},c.arp=a):34525!==d&&y(d);if(c.ipv4)if(c.tcp)a:{a=`${c.ipv4.src.join(".")}:${c.tcp.sport}:${c.ipv4.dest.join(".")}:${c.tcp.dport}`;if(c.tcp.syn&&!c.tcp.ack){b.tcp_conn[a]&&delete b.tcp_conn[a];d=new Jb(b);d.state="syn-received";d.tuple=a;d.last=c;d.hsrc=c.eth.dest;d.psrc=c.ipv4.dest;d.sport=c.tcp.dport;d.hdest=c.eth.src;d.dport=c.tcp.sport;d.pdest=c.ipv4.src;b.bus.pair.send("tcp-connection", d);if(b.on_tcp_connection)b.on_tcp_connection(d,c);if(b.tcp_conn[a])break a}if(b.tcp_conn[a])b.tcp_conn[a].process(c);else{a=c.tcp.ackn;if(c.tcp.fin||c.tcp.syn)a+=1;d={};d.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src};d.ipv4={proto:6,src:c.ipv4.dest,dest:c.ipv4.src};d.tcp={sport:c.tcp.dport,dport:c.tcp.sport,seq:a,ackn:c.tcp.seq+(c.tcp.syn?1:0),winsize:c.tcp.winsize,rst:!0,ack:c.tcp.syn};b.receive(Eb(b.eth_encoder_buf,d))}}else if(c.udp)if(c.dns)if("static"===b.dns_method){a={};a.eth={ethertype:2048, -src:b.router_mac,dest:c.eth.src};a.ipv4={proto:17,src:b.router_ip,dest:c.ipv4.src};a.udp={sport:53,dport:c.udp.sport};d=[];for(e=0;e++h&&b.tcp_conn[g]);if(b.tcp_conn[g])throw Error("pool of dynamic TCP port numbers exhausted, connection aborted");c=new Jb(b);c.tuple=g;c.hsrc=b.router_mac;c.psrc=b.router_ip;c.sport=f;c.hdest=b.vm_mac;c.dport=a;c.pdest=b.vm_ip;b.tcp_conn[g]=c;c.connect();return c} -function Ub(a,b){return new Promise(c=>{let d=Tb(a,b);d.state="syn-probe";d.on("probe",c)})}function Jb(a){this.mtu=a.mtu||1500;const b=this.mtu-20-20;this.state="closed";this.net=a;this.send_buffer=new Ab(2048,0);this.send_chunk_buf=new Uint8Array(b);this.delayed_send_fin=this.in_active_close=!1;this.delayed_state=void 0;this.events_handlers={}}Jb.prototype.on=function(a,b){this.events_handlers[a]=b};Jb.prototype.emit=function(a,...b){this.events_handlers[a]&&this.events_handlers[a].apply(this,b)}; +function Kb(a,b){var c=b.vm_ip.join(".");const d=b.router_ip.join("."),e=16383*Math.random()|0;let f,g,h=0;do f=49152+(e+h)%16383,g=`${c}:${a}:${d}:${f}`;while(16383>++h&&b.tcp_conn[g]);if(b.tcp_conn[g])throw Error("pool of dynamic TCP port numbers exhausted, connection aborted");c=new Jb(b);c.tuple=g;c.hsrc=b.router_mac;c.psrc=b.router_ip;c.sport=f;c.hdest=b.vm_mac;c.dport=a;c.pdest=b.vm_ip;b.tcp_conn[g]=c;c.connect();return c} +function Ub(a,b){return new Promise(c=>{let d=Kb(a,b);d.state="syn-probe";d.on("probe",c)})}function Jb(a){this.mtu=a.mtu||1500;const b=this.mtu-20-20;this.state="closed";this.net=a;this.send_buffer=new Ab(2048,0);this.send_chunk_buf=new Uint8Array(b);this.delayed_send_fin=this.in_active_close=!1;this.delayed_state=void 0;this.events_handlers={}}Jb.prototype.on=function(a,b){this.events_handlers[a]=b};Jb.prototype.emit=function(a,...b){this.events_handlers[a]&&this.events_handlers[a].apply(this,b)}; Jb.prototype.ipv4_reply=function(){let a={};a.eth={ethertype:2048,src:this.hsrc,dest:this.hdest};a.ipv4={proto:6,src:this.psrc,dest:this.pdest};a.tcp={sport:this.sport,dport:this.dport,winsize:this.winsize,ackn:this.ack,seq:this.seq,ack:!0};return a};Jb.prototype.packet_reply=function(a,b){a={sport:a.tcp.dport,dport:a.tcp.sport,winsize:a.tcp.winsize,ackn:this.ack,seq:this.seq};if(b)for(const c in b)a[c]=b[c];b=this.ipv4_reply();b.tcp=a;return b}; Jb.prototype.connect=function(){this.seq=1338;this.ack=1;this.start_seq=0;this.winsize=64240;"syn-probe"!==this.state&&(this.state="syn-sent");let a=this.ipv4_reply();a.ipv4.id=2345;a.tcp={sport:this.sport,dport:this.dport,seq:1337,ackn:0,winsize:0,syn:!0};this.net.receive(Eb(this.net.eth_encoder_buf,a))}; Jb.prototype.accept=function(a){a=a||this.last;this.net.tcp_conn[this.tuple]=this;this.seq=1338;this.ack=a.tcp.seq+1;this.start_seq=a.tcp.seq;this.winsize=a.tcp.winsize;let b=this.ipv4_reply();b.tcp={sport:this.sport,dport:this.dport,seq:1337,ackn:this.ack,winsize:a.tcp.winsize,syn:!0,ack:!0,options:{mss:this.mtu-20-20}};this.state="established";this.net.receive(Eb(this.net.eth_encoder_buf,b))}; @@ -212,7 +212,7 @@ b)),this.emit("data",a.tcp_data));this.pump()}};Jb.prototype.write=function(a){t Jb.prototype.close=function(){if(!this.in_active_close){this.in_active_close=!0;if("established"===this.state||"syn-received"===this.state)var a="fin-wait-1";else if("close-wait"===this.state)a="last-ack";else{this.release();return}this.send_buffer.length||this.pending?(this.delayed_send_fin=!0,this.delayed_state=a):(this.state=a,a=this.ipv4_reply(),a.tcp.fin=!0,this.net.receive(Eb(this.net.eth_encoder_buf,a)))}this.pump()};Jb.prototype.on_shutdown=function(){this.emit("shutdown")}; Jb.prototype.on_close=function(){this.emit("close")};Jb.prototype.release=function(){this.net.tcp_conn[this.tuple]&&(this.state="closed",delete this.net.tcp_conn[this.tuple])};Jb.prototype.pump=function(){if(this.send_buffer.length&&!this.pending){const a=this.send_chunk_buf,b=this.send_buffer.peek(a),c=this.ipv4_reply();c.tcp.psh=!0;c.tcp_data=a.subarray(0,b);this.net.receive(Eb(this.net.eth_encoder_buf,c));this.pending=!0}};function Vb(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.dns_method=b.dns_method||"static"; this.doh_server=b.doh_server;this.tcp_conn={};this.mtu=b.mtu;this.eth_encoder_buf=Bb(this.mtu);this.fetch=(...c)=>fetch(...c);this.cors_proxy=b.cors_proxy;this.bus.register("net"+this.id+"-mac",function(c){this.vm_mac=new Uint8Array(c.split(":").map(function(d){return parseInt(d,16)}))},this);this.bus.register("net"+this.id+"-send",function(c){this.send(c)},this);this.bus.register("tcp-connection",c=>{80===c.sport&&(c.on("data",Wb),c.accept())},this)}Vb.prototype.destroy=function(){}; -Vb.prototype.connect=function(a){return Tb(a,this)};Vb.prototype.tcp_probe=function(a){return Ub(a,this)}; +Vb.prototype.connect=function(a){return Kb(a,this)};Vb.prototype.tcp_probe=function(a){return Ub(a,this)}; async function Wb(a){this.read=this.read||"";if((this.read+=(new TextDecoder).decode(a))&&-1!==this.read.indexOf("\r\n\r\n")){a=this.read.indexOf("\r\n\r\n");var b=this.read.substring(0,a).split(/\r\n/);a=this.read.substring(a+4);this.read="";let c=b[0].split(" "),d;d=/^https?:/.test(c[1])?new URL(c[1]):new URL("http://host"+c[1]);"undefined"!==typeof window&&"http:"===d.protocol&&"https:"===window.location.protocol&&(d.protocol="https:");let e=new Headers;for(let h=1;hb)d.protocol="http:",d.hostname="localhost",d.port=b.toString(10);else{console.warn('Unknown port for localhost: "%s"',d.href);this.net.respond_text_and_close(this, 400,"Bad Request",`Unknown port for localhost: ${d.href}`);return}this.name=d.href;b={method:c[0],headers:e};-1!==["put","post"].indexOf(b.method.toLowerCase())&&(b.body=a);const f=this.net.cors_proxy?this.net.cors_proxy+encodeURIComponent(d.href):d.href;new TextEncoder;let g=!1;this.net.fetch(f,b).then(h=>{let l=new Headers(h.headers);l.delete("content-encoding");l.delete("keep-alive");l.delete("content-length");l.delete("transfer-encoding");l.set("x-was-fetch-redirected",`${!!h.redirected}`);l.set("x-fetch-resp-url", @@ -250,9 +250,9 @@ b,!1);a.removeEventListener("keydown",c,!1);a.removeEventListener("paste",d,!1); this.update())};this.update=function(){var g=Date.now(),h=g-this.last_update;16>h?void 0===this.update_timer&&(this.update_timer=setTimeout(()=>{this.update_timer=void 0;this.last_update=Date.now();this.render()},16-h)):(void 0!==this.update_timer&&(clearTimeout(this.update_timer),this.update_timer=void 0),this.last_update=g,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(){}} function dc(a,b){var c=Reflect.construct(cc,[a],dc);c.send_char=function(d){b.send("serial0-input",d)};b.register("serial0-output-byte",function(d){d=String.fromCharCode(d);c.show_char&&c.show_char(d)},c);return c}Reflect.setPrototypeOf(dc.prototype,cc.prototype);Reflect.setPrototypeOf(dc,cc); function ec(a,b){var c=Reflect.construct(cc,[a],ec);c.send_char=function(e){b.send("virtio-console0-input-bytes",new Uint8Array([e]))};const d=new TextDecoder;b.register("virtio-console0-output-bytes",function(e){for(const f of d.decode(e))c.show_char&&c.show_char(f)},c);return c}Reflect.setPrototypeOf(ec.prototype,cc.prototype);Reflect.setPrototypeOf(ec,cc); -function lc(a,b){this.element=a;var c=this.term=new b({logLevel:"off",convertEol:"true"});this.destroy=function(){this.on_data_disposable&&this.on_data_disposable.dispose();c.dispose()}}lc.prototype.show=function(){this.term&&this.term.open(this.element)}; -function mc(a,b,c){if(c){var d=Reflect.construct(lc,[a,c],mc);b.register("serial0-output-byte",function(f){d.term.write(Uint8Array.of(f))},d);var e=new TextEncoder;d.on_data_disposable=d.term.onData(function(f){for(const g of e.encode(f))b.send("serial0-input",g)});return d}}Reflect.setPrototypeOf(mc.prototype,lc.prototype);Reflect.setPrototypeOf(mc,lc); -function nc(a,b,c){if(c){var d=Reflect.construct(lc,[a,c],nc);b.register("virtio-console0-output-bytes",function(f){d.term.write(f)},d);var e=new TextEncoder;d.on_data_disposable=d.term.onData(function(f){b.send("virtio-console0-input-bytes",e.encode(f))});return d}}Reflect.setPrototypeOf(nc.prototype,lc.prototype);Reflect.setPrototypeOf(nc,lc);function oc(a,b){b=b.id||0;this.bus=a;this.bus_send_msgid=`net${b}-send`;this.bus_recv_msgid=`net${b}-receive`;this.channel=new BroadcastChannel(`v86-inbrowser-${b}`);this.is_open=!0;this.nic_to_hub_fn=c=>{this.channel.postMessage(c)};this.bus.register(this.bus_send_msgid,this.nic_to_hub_fn,this);this.hub_to_nic_fn=c=>{this.bus.send(this.bus_recv_msgid,c.data)};this.channel.addEventListener("message",this.hub_to_nic_fn)} +function fc(a,b){this.element=a;var c=this.term=new b({logLevel:"off",convertEol:"true"});this.destroy=function(){this.on_data_disposable&&this.on_data_disposable.dispose();c.dispose()}}fc.prototype.show=function(){this.term&&this.term.open(this.element)}; +function mc(a,b,c){if(c){var d=Reflect.construct(fc,[a,c],mc);b.register("serial0-output-byte",function(f){d.term.write(Uint8Array.of(f))},d);var e=new TextEncoder;d.on_data_disposable=d.term.onData(function(f){for(const g of e.encode(f))b.send("serial0-input",g)});return d}}Reflect.setPrototypeOf(mc.prototype,fc.prototype);Reflect.setPrototypeOf(mc,fc); +function nc(a,b,c){if(c){var d=Reflect.construct(fc,[a,c],nc);b.register("virtio-console0-output-bytes",function(f){d.term.write(f)},d);var e=new TextEncoder;d.on_data_disposable=d.term.onData(function(f){b.send("virtio-console0-input-bytes",e.encode(f))});return d}}Reflect.setPrototypeOf(nc.prototype,fc.prototype);Reflect.setPrototypeOf(nc,fc);function oc(a,b){b=b.id||0;this.bus=a;this.bus_send_msgid=`net${b}-send`;this.bus_recv_msgid=`net${b}-receive`;this.channel=new BroadcastChannel(`v86-inbrowser-${b}`);this.is_open=!0;this.nic_to_hub_fn=c=>{this.channel.postMessage(c)};this.bus.register(this.bus_send_msgid,this.nic_to_hub_fn,this);this.hub_to_nic_fn=c=>{this.bus.send(this.bus_recv_msgid,c.data)};this.channel.addEventListener("message",this.hub_to_nic_fn)} oc.prototype.destroy=function(){this.is_open&&(this.bus.unregister(this.bus_send_msgid,this.nic_to_hub_fn),this.channel.removeEventListener("message",this.hub_to_nic_fn),this.channel.close(),this.is_open=!1)};function pc(){this.filedata=new Map}pc.prototype.read=async function(a,b,c){return(a=this.filedata.get(a))?a.subarray(b,b+c):null};pc.prototype.cache=async function(a,b){this.filedata.set(a,b)};pc.prototype.uncache=function(a){this.filedata.delete(a)};function qc(a,b,c){b.endsWith("/")||(b+="/");this.storage=a;this.baseurl=b;this.zstd_decompress=c} qc.prototype.load_from_server=function(a,b){return new Promise(c=>{oa(this.baseurl+a,{done:async d=>{d=new Uint8Array(d);a.endsWith(".zst")&&(d=new Uint8Array(this.zstd_decompress(b,d)));await this.cache(a,d);c(d)}})})};qc.prototype.read=async function(a,b,c,d){const e=await this.storage.read(a,b,c,d);return e?e:(await this.load_from_server(a,d)).subarray(b,b+c)};qc.prototype.cache=async function(a,b){return await this.storage.cache(a,b)};qc.prototype.uncache=function(a){this.storage.uncache(a)};const rc=new TextDecoder,sc=new TextEncoder; function G(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=sc.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; @@ -426,11 +426,15 @@ this.mouse_clicks=this.mouse_delta_x=this.mouse_delta_y=0;break;case 245:this.en 0;break;default:y(a)}this.mouse_irq()}}else if(this.read_controller_output_port)this.read_controller_output_port=!1,this.controller_output_port=a;else{y(a);this.mouse_buffer.clear();this.kbd_buffer.clear();this.kbd_buffer.push(250);switch(a){case 237:this.next_read_led=!0;break;case 240:this.next_handle_scan_code_set=!0;break;case 242:this.kbd_buffer.push(171);this.kbd_buffer.push(131);break;case 243:this.next_read_rate=!0;break;case 244:this.enable_keyboard_stream=!0;break;case 245:this.enable_keyboard_stream= !1;break;case 246:break;case 255:this.kbd_buffer.clear();this.kbd_buffer.push(250);this.kbd_buffer.push(170);this.kbd_buffer.push(0);break;default:y(a)}this.kbd_irq()}}; Gc.prototype.port64_write=function(a){y(a);switch(a){case 32:this.kbd_buffer.clear();this.mouse_buffer.clear();this.kbd_buffer.push(this.command_register);this.kbd_irq();break;case 96:this.read_command_register=!0;break;case 209:this.read_controller_output_port=!0;break;case 211:this.read_output_register=!0;break;case 212:this.next_is_mouse_command=!0;break;case 167:this.command_register|=32;break;case 168:this.command_register&=-33;break;case 169:this.kbd_buffer.clear();this.mouse_buffer.clear(); -this.kbd_buffer.push(0);this.kbd_irq();break;case 170:this.kbd_buffer.clear();this.mouse_buffer.clear();this.kbd_buffer.push(85);this.kbd_irq();break;case 171:this.kbd_buffer.clear();this.mouse_buffer.clear();this.kbd_buffer.push(0);this.kbd_irq();break;case 173:this.command_register|=16;break;case 174:this.command_register&=-17;break;case 254:this.cpu.reboot_internal();break;default:y(a)}};const Hc=DataView.prototype,Ic={size:1,get:Hc.getUint8,set:Hc.setUint8},Jc={size:2,get:Hc.getUint16,set:Hc.setUint16},U={size:4,get:Hc.getUint32,set:Hc.setUint32},Lc=Kc([{magic:U},{class:Ic},{data:Ic},{version0:Ic},{osabi:Ic},{abiversion:Ic},{pad0:function(a){return{size:a,get:()=>-1}}(7)},{type:Jc},{machine:Jc},{version1:U},{entry:U},{phoff:U},{shoff:U},{flags:U},{ehsize:Jc},{phentsize:Jc},{phnum:Jc},{shentsize:Jc},{shnum:Jc},{shstrndx:Jc}]);console.assert(52===Lc.reduce((a,b)=>a+b.size,0)); -const Mc=Kc([{type:U},{offset:U},{vaddr:U},{paddr:U},{filesz:U},{memsz:U},{flags:U},{align:U}]);console.assert(32===Mc.reduce((a,b)=>a+b.size,0));const Nc=Kc([{name:U},{type:U},{flags:U},{addr:U},{offset:U},{size:U},{link:U},{info:U},{addralign:U},{entsize:U}]);console.assert(40===Nc.reduce((a,b)=>a+b.size,0));function Kc(a){return a.map(function(b){var c=Object.keys(b);console.assert(1===c.length);c=c[0];b=b[c];console.assert(0this.last_x||(b&&this.tail_is_move&&4<=this.queue.length?(this.queue[this.queue.length-3]=this.last_x,this.queue[this.queue.length-2]=this.last_y):1024>>0,4,this.queue.length),c=[0,0,0,0];for(let d=0;d-1}}(7)},{type:Kc},{machine:Kc},{version1:U},{entry:U},{phoff:U},{shoff:U},{flags:U},{ehsize:Kc},{phentsize:Kc},{phnum:Kc},{shentsize:Kc},{shnum:Kc},{shstrndx:Kc}]);console.assert(52===Mc.reduce((a,b)=>a+b.size,0)); +const Nc=Lc([{type:U},{offset:U},{vaddr:U},{paddr:U},{filesz:U},{memsz:U},{flags:U},{align:U}]);console.assert(32===Nc.reduce((a,b)=>a+b.size,0));const Oc=Lc([{name:U},{type:U},{flags:U},{addr:U},{offset:U},{size:U},{link:U},{info:U},{addralign:U},{entsize:U}]);console.assert(40===Oc.reduce((a,b)=>a+b.size,0));function Lc(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=a&&(this.drive_type=a);this.insert_disk(c,!!b?.read_only);0===this.drive_type&&void 0===a&&(this.drive_type=d)} -Rc.prototype.insert_disk=function(a,b){if(!a)return!1;a instanceof Uint8Array&&(a=new z(a.buffer));const [c,d]=this.find_disk_format(a,this.drive_type);if(!c)return!1;this.max_track=d.tracks;this.max_head=d.heads;this.max_sect=d.sectors;this.read_only=!!b;this.media_changed=!0;this.buffer=c;0===this.drive_type&&(this.drive_type=d.drive_type);return!0};Rc.prototype.eject_disk=function(){this.max_sect=this.max_head=this.max_track=0;this.media_changed=!0;this.buffer=null}; -Rc.prototype.get_buffer=function(){return this.buffer?new Uint8Array(this.buffer.buffer):null};Rc.prototype.chs2lba=function(a,b,c){return(a*this.max_head+b)*this.max_sect+c-1}; -Rc.prototype.find_disk_format=function(a,b){const c=0===b,d=a.byteLength;let e=-1,f=-1,g=-1,h=-1,l=-1;for(let m=0;mthis.max_track||0!==a&&1===this.max_head)return 2;if(c>this.max_sect)return 3;let d=0;const e=this.chs2lba(this.curr_track,this.curr_head,this.curr_sect),f=this.chs2lba(b,a,c);e!==f&&(this.curr_track!==b&&(this.buffer&&(this.media_changed=!1),d=1),this.curr_head=a,this.curr_track=b,this.curr_sect=c);this.buffer||(d=2);return d}; -Rc.prototype.get_state=function(){const a=[];a[0]=this.drive_type;a[1]=this.max_track;a[2]=this.max_head;a[3]=this.max_sect;a[4]=this.curr_track;a[5]=this.curr_head;a[6]=this.curr_sect;a[7]=this.perpendicular;a[8]=this.read_only;a[9]=this.media_changed;a[10]=this.buffer?this.buffer.get_state():null;return a}; -Rc.prototype.set_state=function(a){this.drive_type=a[0];this.max_track=a[1];this.max_head=a[2];this.max_sect=a[3];this.curr_track=a[4];this.curr_head=a[5];this.curr_sect=a[6];this.perpendicular=a[7];this.read_only=a[8];this.media_changed=a[9];a[10]?(this.buffer||(this.buffer=new z(new ArrayBuffer(0))),this.buffer.set_state(a[10])):this.buffer=null};const Tc={[70]:{name:"GET CONFIGURATION",flags:0},[74]:{name:"GET EVENT STATUS NOTIFICATION",flags:0},[18]:{name:"INQUIRY",flags:0},[189]:{name:"MECHANISM STATUS",flags:0},[26]:{name:"MODE SENSE (6)",flags:0},[90]:{name:"MODE SENSE (10)",flags:0},[69]:{name:"PAUSE",flags:1},[30]:{name:"PREVENT ALLOW MEDIUM REMOVAL",flags:0},[40]:{name:"READ (10)",flags:1},[168]:{name:"READ (12)",flags:1},[37]:{name:"READ CAPACITY",flags:1},[190]:{name:"READ CD",flags:1},[81]:{name:"READ DISK INFORMATION",flags:1}, +sectors:10,tracks:40,heads:1},{drive_type:1,sectors:10,tracks:40,heads:2}];function Sc(a,b,c,d){this.name=a;this.curr_head=this.curr_track=this.max_sect=this.max_head=this.max_track=this.drive_type=0;this.curr_sect=1;this.perpendicular=0;this.read_only=!1;this.media_changed=!0;this.buffer=null;Object.seal(this);a=b?.drive_type;void 0!==a&&0<=a&&5>=a&&(this.drive_type=a);this.insert_disk(c,!!b?.read_only);0===this.drive_type&&void 0===a&&(this.drive_type=d)} +Sc.prototype.insert_disk=function(a,b){if(!a)return!1;a instanceof Uint8Array&&(a=new z(a.buffer));const [c,d]=this.find_disk_format(a,this.drive_type);if(!c)return!1;this.max_track=d.tracks;this.max_head=d.heads;this.max_sect=d.sectors;this.read_only=!!b;this.media_changed=!0;this.buffer=c;0===this.drive_type&&(this.drive_type=d.drive_type);return!0};Sc.prototype.eject_disk=function(){this.max_sect=this.max_head=this.max_track=0;this.media_changed=!0;this.buffer=null}; +Sc.prototype.get_buffer=function(){return this.buffer?new Uint8Array(this.buffer.buffer):null};Sc.prototype.chs2lba=function(a,b,c){return(a*this.max_head+b)*this.max_sect+c-1}; +Sc.prototype.find_disk_format=function(a,b){const c=0===b,d=a.byteLength;let e=-1,f=-1,g=-1,h=-1,l=-1;for(let m=0;mthis.max_track||0!==a&&1===this.max_head)return 2;if(c>this.max_sect)return 3;let d=0;const e=this.chs2lba(this.curr_track,this.curr_head,this.curr_sect),f=this.chs2lba(b,a,c);e!==f&&(this.curr_track!==b&&(this.buffer&&(this.media_changed=!1),d=1),this.curr_head=a,this.curr_track=b,this.curr_sect=c);this.buffer||(d=2);return d}; +Sc.prototype.get_state=function(){const a=[];a[0]=this.drive_type;a[1]=this.max_track;a[2]=this.max_head;a[3]=this.max_sect;a[4]=this.curr_track;a[5]=this.curr_head;a[6]=this.curr_sect;a[7]=this.perpendicular;a[8]=this.read_only;a[9]=this.media_changed;a[10]=this.buffer?this.buffer.get_state():null;return a}; +Sc.prototype.set_state=function(a){this.drive_type=a[0];this.max_track=a[1];this.max_head=a[2];this.max_sect=a[3];this.curr_track=a[4];this.curr_head=a[5];this.curr_sect=a[6];this.perpendicular=a[7];this.read_only=a[8];this.media_changed=a[9];a[10]?(this.buffer||(this.buffer=new z(new ArrayBuffer(0))),this.buffer.set_state(a[10])):this.buffer=null};const Uc={[70]:{name:"GET CONFIGURATION",flags:0},[74]:{name:"GET EVENT STATUS NOTIFICATION",flags:0},[18]:{name:"INQUIRY",flags:0},[189]:{name:"MECHANISM STATUS",flags:0},[26]:{name:"MODE SENSE (6)",flags:0},[90]:{name:"MODE SENSE (10)",flags:0},[69]:{name:"PAUSE",flags:1},[30]:{name:"PREVENT ALLOW MEDIUM REMOVAL",flags:0},[40]:{name:"READ (10)",flags:1},[168]:{name:"READ (12)",flags:1},[37]:{name:"READ CAPACITY",flags:1},[190]:{name:"READ CD",flags:1},[81]:{name:"READ DISK INFORMATION",flags:1}, [66]:{name:"READ SUBCHANNEL",flags:1},[67]:{name:"READ TOC PMA ATIP",flags:1},[82]:{name:"READ TRACK INFORMATION",flags:1},[3]:{name:"REQUEST SENSE",flags:0},[27]:{name:"START STOP UNIT",flags:0},[0]:{name:"TEST UNIT READY",flags:1}}; -function Uc(a,b,c){this.cpu=a;this.bus=b;this.secondary=this.primary=void 0;b=c&&c[0][0];const d=c&&c[1][0];if(b||d){b&&(this.primary=new Vc(this,0,c[0],496,1014,14));d&&(this.secondary=new Vc(this,1,c[1],368,886,15));c=b?this.primary.command_base:0;const e=b?this.primary.control_base:0,f=d?this.secondary.command_base:0,g=d?this.secondary.control_base:0;this.name="ide";this.pci_id=240;this.pci_space=[134,128,16,112,5,0,160,2,0,128,1,1,0,0,0,0,c&255|1,c>>8,0,0,e&255|1,e>>8,0,0,f&255|1,f>>8,0,0,g&255| +function Vc(a,b,c){this.cpu=a;this.bus=b;this.secondary=this.primary=void 0;b=c&&c[0][0];const d=c&&c[1][0];if(b||d){b&&(this.primary=new Wc(this,0,c[0],496,1014,14));d&&(this.secondary=new Wc(this,1,c[1],368,886,15));c=b?this.primary.command_base:0;const e=b?this.primary.control_base:0,f=d?this.secondary.command_base:0,g=d?this.secondary.control_base:0;this.name="ide";this.pci_id=240;this.pci_space=[134,128,16,112,5,0,160,2,0,128,1,1,0,0,0,0,c&255|1,c>>8,0,0,e&255|1,e>>8,0,0,f&255|1,f>>8,0,0,g&255| 1,g>>8,0,0,1,180,0,0,0,0,0,0,0,0,0,0,67,16,212,130,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.pci_bars=[b?{size:8}:void 0,b?{size:1}:void 0,d?{size:8}:void 0,d?{size:1}:void 0,{size:16}];a.devices.pci.register_device(this)}Object.seal(this)} -Uc.prototype.get_state=function(){const a=[];a[0]=this.primary;a[1]=this.secondary;return a};Uc.prototype.set_state=function(a){this.primary&&this.primary.set_state(a[0]);this.secondary&&this.secondary.set_state(a[1])}; -function Vc(a,b,c,d,e,f){this.controller=a;this.channel_nr=b;this.cpu=a.cpu;this.bus=a.bus;this.command_base=d;this.control_base=e;this.irq=f;this.name="ide"+b;d=c?c[0]:void 0;c=c?c[1]:void 0;this.master=new W(this,0,d?.buffer,d?.is_cdrom);this.slave=new W(this,1,c?.buffer,c?.is_cdrom);this.current_interface=this.master;this.device_control_reg=2;this.dma_command=this.dma_status=this.prdt_addr=0;a=a.cpu;a.io.register_read(this.command_base|0,this,function(){return this.current_interface.read_data(1)}, +Vc.prototype.get_state=function(){const a=[];a[0]=this.primary;a[1]=this.secondary;return a};Vc.prototype.set_state=function(a){this.primary&&this.primary.set_state(a[0]);this.secondary&&this.secondary.set_state(a[1])}; +function Wc(a,b,c,d,e,f){this.controller=a;this.channel_nr=b;this.cpu=a.cpu;this.bus=a.bus;this.command_base=d;this.control_base=e;this.irq=f;this.name="ide"+b;d=c?c[0]:void 0;c=c?c[1]:void 0;this.master=new W(this,0,d?.buffer,d?.is_cdrom);this.slave=new W(this,1,c?.buffer,c?.is_cdrom);this.current_interface=this.master;this.device_control_reg=2;this.dma_command=this.dma_status=this.prdt_addr=0;a=a.cpu;a.io.register_read(this.command_base|0,this,function(){return this.current_interface.read_data(1)}, function(){return this.current_interface.read_data(2)},function(){return this.current_interface.read_data(4)});a.io.register_read(this.command_base|1,this,function(){return this.current_interface.error_reg&255});a.io.register_read(this.command_base|2,this,function(){return this.current_interface.sector_count_reg&255});a.io.register_read(this.command_base|3,this,function(){return this.current_interface.lba_low_reg&255});a.io.register_read(this.command_base|4,this,function(){return this.current_interface.lba_mid_reg& 255});a.io.register_read(this.command_base|5,this,function(){return this.current_interface.lba_high_reg&255});a.io.register_read(this.command_base|6,this,function(){return this.current_interface.device_reg&255});a.io.register_read(this.command_base|7,this,function(){const g=this.read_status();this.cpu.device_lower_irq(this.irq);return g});a.io.register_write(this.command_base|0,this,function(g){this.current_interface.write_data_port8(g)},function(g){this.current_interface.write_data_port16(g)},function(g){this.current_interface.write_data_port32(g)}); a.io.register_write(this.command_base|1,this,function(g){this.master.features_reg=(this.master.features_reg<<8|g)&65535;this.slave.features_reg=(this.slave.features_reg<<8|g)&65535});a.io.register_write(this.command_base|2,this,function(g){this.master.sector_count_reg=(this.master.sector_count_reg<<8|g)&65535;this.slave.sector_count_reg=(this.slave.sector_count_reg<<8|g)&65535});a.io.register_write(this.command_base|3,this,function(g){this.master.lba_low_reg=(this.master.lba_low_reg<<8|g)&65535;this.slave.lba_low_reg= (this.slave.lba_low_reg<<8|g)&65535});a.io.register_write(this.command_base|4,this,function(g){this.master.lba_mid_reg=(this.master.lba_mid_reg<<8|g)&65535;this.slave.lba_mid_reg=(this.slave.lba_mid_reg<<8|g)&65535});a.io.register_write(this.command_base|5,this,function(g){this.master.lba_high_reg=(this.master.lba_high_reg<<8|g)&65535;this.slave.lba_high_reg=(this.slave.lba_high_reg<<8|g)&65535});a.io.register_write(this.command_base|6,this,function(g){const h=g&16;if(h&&this.current_interface=== this.master||!h&&this.current_interface===this.slave)this.current_interface=h?this.slave:this.master;this.current_interface.device_reg=g;this.current_interface.is_lba=g>>6&1;this.current_interface.head=g&15});a.io.register_write(this.command_base|7,this,function(g){this.current_interface.status_reg&=-34;this.current_interface.ata_command(g);this.cpu.device_lower_irq(this.irq)});a.io.register_read(this.control_base|0,this,this.read_status);a.io.register_write(this.control_base|0,this,this.write_control); b=46080+8*b;a.io.register_read(b|0,this,this.dma_read_command8,void 0,this.dma_read_command);a.io.register_write(b|0,this,this.dma_write_command8,void 0,this.dma_write_command);a.io.register_read(b|2,this,this.dma_read_status);a.io.register_write(b|2,this,this.dma_write_status);a.io.register_read(b|4,this,void 0,void 0,this.dma_read_addr);a.io.register_write(b|4,this,void 0,void 0,this.dma_set_addr)} -Vc.prototype.read_status=function(){return this.current_interface.drive_connected?this.current_interface.status_reg:0};Vc.prototype.write_control=function(a){a&4&&(this.cpu.device_lower_irq(this.irq),this.master.device_reset(),this.slave.device_reset());this.device_control_reg=a};Vc.prototype.dma_read_addr=function(){return this.prdt_addr};Vc.prototype.dma_set_addr=function(a){this.prdt_addr=a};Vc.prototype.dma_read_status=function(){return this.dma_status}; -Vc.prototype.dma_write_status=function(a){this.dma_status&=~(a&6)};Vc.prototype.dma_read_command=function(){return this.dma_read_command8()|this.dma_read_status()<<16};Vc.prototype.dma_read_command8=function(){return this.dma_command};Vc.prototype.dma_write_command=function(a){this.dma_write_command8(a&255);this.dma_write_status(a>>16&255)}; -Vc.prototype.dma_write_command8=function(a){const b=this.dma_command;this.dma_command=a&9;if((b&1)!==(a&1))if(0===(a&1))this.dma_status&=-2;else switch(this.dma_status|=1,this.current_interface.current_command){case 200:case 37:this.current_interface.do_ata_read_sectors_dma();break;case 202:case 53:this.current_interface.do_ata_write_sectors_dma();break;case 160:this.current_interface.do_atapi_dma();break;default:y(this.current_interface.current_command),this.dma_status&=-2,this.dma_status|=2,this.push_irq()}}; -Vc.prototype.push_irq=function(){0===(this.device_control_reg&2)&&(this.dma_status|=4,this.cpu.device_raise_irq(this.irq))};Vc.prototype.get_state=function(){var a=[];a[0]=this.master;a[1]=this.slave;a[2]=this.command_base;a[3]=this.irq;a[5]=this.control_base;a[7]=this.name;a[8]=this.device_control_reg;a[9]=this.prdt_addr;a[10]=this.dma_status;a[11]=this.current_interface===this.master;a[12]=this.dma_command;return a}; -Vc.prototype.set_state=function(a){this.master.set_state(a[0]);this.slave.set_state(a[1]);this.command_base=a[2];this.irq=a[3];this.control_base=a[5];this.name=a[7];this.device_control_reg=a[8];this.prdt_addr=a[9];this.dma_status=a[10];this.current_interface=a[11]?this.master:this.slave;this.dma_command=a[12]}; +Wc.prototype.read_status=function(){return this.current_interface.drive_connected?this.current_interface.status_reg:0};Wc.prototype.write_control=function(a){a&4&&(this.cpu.device_lower_irq(this.irq),this.master.device_reset(),this.slave.device_reset());this.device_control_reg=a};Wc.prototype.dma_read_addr=function(){return this.prdt_addr};Wc.prototype.dma_set_addr=function(a){this.prdt_addr=a};Wc.prototype.dma_read_status=function(){return this.dma_status}; +Wc.prototype.dma_write_status=function(a){this.dma_status&=~(a&6)};Wc.prototype.dma_read_command=function(){return this.dma_read_command8()|this.dma_read_status()<<16};Wc.prototype.dma_read_command8=function(){return this.dma_command};Wc.prototype.dma_write_command=function(a){this.dma_write_command8(a&255);this.dma_write_status(a>>16&255)}; +Wc.prototype.dma_write_command8=function(a){const b=this.dma_command;this.dma_command=a&9;if((b&1)!==(a&1))if(0===(a&1))this.dma_status&=-2;else switch(this.dma_status|=1,this.current_interface.current_command){case 200:case 37:this.current_interface.do_ata_read_sectors_dma();break;case 202:case 53:this.current_interface.do_ata_write_sectors_dma();break;case 160:this.current_interface.do_atapi_dma();break;default:y(this.current_interface.current_command),this.dma_status&=-2,this.dma_status|=2,this.push_irq()}}; +Wc.prototype.push_irq=function(){0===(this.device_control_reg&2)&&(this.dma_status|=4,this.cpu.device_raise_irq(this.irq))};Wc.prototype.get_state=function(){var a=[];a[0]=this.master;a[1]=this.slave;a[2]=this.command_base;a[3]=this.irq;a[5]=this.control_base;a[7]=this.name;a[8]=this.device_control_reg;a[9]=this.prdt_addr;a[10]=this.dma_status;a[11]=this.current_interface===this.master;a[12]=this.dma_command;return a}; +Wc.prototype.set_state=function(a){this.master.set_state(a[0]);this.slave.set_state(a[1]);this.command_base=a[2];this.irq=a[3];this.control_base=a[5];this.name=a[7];this.device_control_reg=a[8];this.prdt_addr=a[9];this.dma_status=a[10];this.current_interface=a[11]?this.master:this.slave;this.dma_command=a[12]}; function W(a,b,c,d){this.channel=a;this.name=a.name+"."+b;this.bus=a.bus;this.channel_nr=a.channel_nr;this.interface_nr=b;this.cpu=a.cpu;this.buffer=null;this.drive_connected=d||!!c;this.sector_size=d?2048:512;this.is_atapi=d;this.sector_count=0;this.head_count=this.is_atapi?1:0;this.device_reg=this.head=this.lba_high_reg=this.lba_mid_reg=this.features_reg=this.lba_low_reg=this.sector_count_reg=this.is_lba=this.cylinder_count=this.sectors_per_track=0;this.status_reg=80;this.sectors_per_drq=128;this.data_pointer= this.error_reg=0;this.data=new Uint8Array(65536);this.data16=new Uint16Array(this.data.buffer);this.data32=new Int32Array(this.data.buffer);this.data_end=this.data_length=0;this.current_command=-1;this.last_io_id=this.write_dest=0;this.in_progress_io_ids=new Set;this.cancelled_io_ids=new Set;this.current_atapi_command=-1;this.atapi_add_sense=this.atapi_sense_key=0;this.medium_changed=!1;this.set_disk_buffer(c);Object.seal(this)}W.prototype.has_disk=function(){return!!this.buffer}; W.prototype.eject=function(){this.is_atapi&&this.buffer&&(this.medium_changed=!0,this.buffer=null,this.status_reg=89,this.error_reg=96,this.push_irq())};W.prototype.set_cdrom=function(a){this.is_atapi&&a&&(this.set_disk_buffer(a),this.medium_changed=!0)}; @@ -498,7 +502,7 @@ W.prototype.ata_command=function(a){if(this.drive_connected||144===a)switch(this break;case 198:y(this.sector_count_reg&255);this.sectors_per_drq=this.sector_count_reg&255;this.status_reg=80;this.push_irq();break;case 200:case 37:this.ata_read_sectors_dma(a);break;case 202:case 53:this.ata_write_sectors_dma(a);break;case 64:this.status_reg=80;this.push_irq();break;case 218:this.is_atapi&&(this.buffer||(this.error_reg|=2),this.medium_changed&&(this.error_reg|=32,this.medium_changed=!1),this.error_reg|=64);this.status_reg=80;this.push_irq();break;case 224:this.status_reg=80;this.push_irq(); break;case 225:this.status_reg=80;this.push_irq();break;case 231:this.status_reg=80;this.push_irq();break;case 234:this.status_reg=80;this.push_irq();break;case 236:this.is_atapi?(this.lba_mid_reg=20,this.lba_high_reg=235,this.ata_abort_command()):(this.create_identify_packet(),this.status_reg=88,this.push_irq());break;case 239:this.status_reg=80;this.push_irq();break;case 222:this.status_reg=64;this.push_irq();break;case 245:this.status_reg=80;this.push_irq();break;case 249:this.ata_abort_command(); break;case 0:this.ata_abort_command();break;case 240:y(a);this.capture_regs();this.ata_abort_command();break;default:y(a),this.capture_regs(),this.ata_abort_command()}else y(a)}; -W.prototype.atapi_handle=function(){var a=this.data[0],b=Tc[a]?Tc[a].flags:0;this.data_pointer=0;this.current_atapi_command=a;3!==a&&(this.atapi_add_sense=this.atapi_sense_key=0);if(!this.buffer&&b&1)this.atapi_check_condition_response(2,58),this.push_irq();else{switch(a){case 0:this.buffer?(this.data_allocate(0),this.data_end=this.data_length,this.status_reg=80):this.atapi_check_condition_response(2,58);break;case 3:this.data_allocate(this.data[4]);this.data_end=this.data_length;this.status_reg= +W.prototype.atapi_handle=function(){var a=this.data[0],b=Uc[a]?Uc[a].flags:0;this.data_pointer=0;this.current_atapi_command=a;3!==a&&(this.atapi_add_sense=this.atapi_sense_key=0);if(!this.buffer&&b&1)this.atapi_check_condition_response(2,58),this.push_irq();else{switch(a){case 0:this.buffer?(this.data_allocate(0),this.data_end=this.data_length,this.status_reg=80):this.atapi_check_condition_response(2,58);break;case 3:this.data_allocate(this.data[4]);this.data_end=this.data_length;this.status_reg= 88;this.data[0]=240;this.data[2]=this.atapi_sense_key;this.data[7]=8;this.data[12]=this.atapi_add_sense;this.atapi_add_sense=this.atapi_sense_key=0;break;case 18:a=this.data[4];this.status_reg=88;y(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_reg=88;break;case 30:this.data_allocate(0); this.data_end=this.data_length;this.status_reg=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_reg=88;break;case 40:case 168:this.features_reg&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_reg=88;break;case 67:a=this.data[8]|this.data[7]<< 8;b=this.data[9]>>6;y(b,2);y(this.data[6]);this.data_allocate(a);this.data_end=this.data_length;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_reg=88;break;case 70:a=Math.min(this.data[8]|this.data[7]<<8,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]= @@ -535,12 +539,12 @@ W.prototype.cancel_io_operations=function(){for(const a of this.in_progress_io_i W.prototype.get_state=function(){var a=[];a[0]=this.sector_count_reg;a[1]=this.cylinder_count;a[2]=this.lba_high_reg;a[3]=this.lba_mid_reg;a[4]=this.data_pointer;a[5]=0;a[6]=0;a[7]=0;a[8]=0;a[9]=this.device_reg;a[10]=this.error_reg;a[11]=this.head;a[12]=this.head_count;a[13]=this.is_atapi;a[14]=this.is_lba;a[15]=this.features_reg;a[16]=this.data;a[17]=this.data_length;a[18]=this.lba_low_reg;a[19]=this.sector_count;a[20]=this.sector_size;a[21]=this.sectors_per_drq;a[22]=this.sectors_per_track;a[23]= this.status_reg;a[24]=this.write_dest;a[25]=this.current_command;a[26]=this.data_end;a[27]=this.current_atapi_command;a[28]=this.buffer;return a}; W.prototype.set_state=function(a){this.sector_count_reg=a[0];this.cylinder_count=a[1];this.lba_high_reg=a[2];this.lba_mid_reg=a[3];this.data_pointer=a[4];this.device_reg=a[9];this.error_reg=a[10];this.head=a[11];this.head_count=a[12];this.is_atapi=a[13];this.is_lba=a[14];this.features_reg=a[15];this.data=a[16];this.data_length=a[17];this.lba_low_reg=a[18];this.sector_count=a[19];this.sector_size=a[20];this.sectors_per_drq=a[21];this.sectors_per_track=a[22];this.status_reg=a[23];this.write_dest=a[24]; -this.current_command=a[25];this.data_end=a[26];this.current_atapi_command=a[27];this.data16=new Uint16Array(this.data.buffer);this.data32=new Int32Array(this.data.buffer);this.buffer&&this.buffer.set_state(a[28]);this.drive_connected=this.is_atapi||this.buffer;this.medium_changed=!1};function Wc(a,b,c,d=1500){this.bus=b;this.id=a.devices.net?1:0;this.status=this.pairs=1;this.preserve_mac_from_state_image=c;this.mac=new Uint8Array([0,34,21,255*Math.random()|0,255*Math.random()|0,255*Math.random()|0]);this.bus.send("net"+this.id+"-mac",Cc(this.mac));b=[];for(c=0;c{}},notification:{initial_port:51456,single_handler:!1,handlers:[()=>{},e=>{const f=this.virtio.queues[e];for(;f.has_request();){const g=f.pop_request(),h=new Uint8Array(g.length_readable);g.get_next_blob(h);this.bus.send("net"+this.id+"-send",h.subarray(12));this.bus.send("eth-transmit-end",[h.length-12]);this.virtio.queues[e].push_reply(g)}this.virtio.queues[e].flush_replies()},e=>{if(e===2*this.pairs)for(var f=this.virtio.queues[e];f.has_request();){const g= f.pop_request(),h=new Uint8Array(g.length_readable);g.get_next_blob(h);const l=I(["b","b"],h,{offset:0});switch(l[0]<<8|l[1]){case 1024:I(["h"],h,{offset:2});this.Send(e,g,new Uint8Array([0]));break;case 257:this.mac=h.subarray(2,8);this.Send(e,g,new Uint8Array([0]));this.bus.send("net"+this.id+"-mac",Cc(this.mac));break;default:this.Send(e,g,new Uint8Array([1]));return}}}]},isr_status:{initial_port:50944},device_specific:{initial_port:50688,struct:[0,1,2,3,4,5].map((e,f)=>({bytes:1,name:"mac_"+f, read:()=>this.mac[f],write:()=>{}})).concat([{bytes:2,name:"status",read:()=>this.status,write:()=>{}},{bytes:2,name:"max_pairs",read:()=>this.pairs,write:()=>{}},{bytes:2,name:"mtu",read:()=>d,write:()=>{}}])}});this.bus.register("net"+this.id+"-receive",e=>{this.bus.send("eth-receive-end",[e.length]);const f=new Uint8Array(12+e.byteLength);(new DataView(f.buffer,f.byteOffset,f.byteLength)).setInt16(10,1);f.set(e,12);e=this.virtio.queues[0];e.has_request()?(e=e.pop_request(),e.set_next_blob(f),this.virtio.queues[0].push_reply(e), -this.virtio.queues[0].flush_replies()):console.log("No buffer to write into!")},this)}Wc.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.id;a[2]=this.mac;return a};Wc.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.id=a[1];this.preserve_mac_from_state_image&&(this.mac=a[2],this.bus.send("net"+this.id+"-mac",Cc(this.mac)))};Wc.prototype.reset=function(){this.virtio.reset()}; -Wc.prototype.Send=function(a,b,c){b.set_next_blob(c);this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};Wc.prototype.Ack=function(a,b){this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};const Xc=Uint32Array.from([655360,655360,720896,753664]),Yc=Uint32Array.from([131072,65536,32768,32768]); +this.virtio.queues[0].flush_replies()):console.log("No buffer to write into!")},this)}Xc.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.id;a[2]=this.mac;return a};Xc.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.id=a[1];this.preserve_mac_from_state_image&&(this.mac=a[2],this.bus.send("net"+this.id+"-mac",Cc(this.mac)))};Xc.prototype.reset=function(){this.virtio.reset()}; +Xc.prototype.Send=function(a,b,c){b.set_next_blob(c);this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};Xc.prototype.Ack=function(a,b){this.virtio.queues[a].push_reply(b);this.virtio.queues[a].flush_replies()};const Yc=Uint32Array.from([655360,655360,720896,753664]),Zc=Uint32Array.from([131072,65536,32768,32768]); function X(a,b,c,d){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>2&3;a-=Xc[b];if(0>a||a>=Yc[b])return y(a>>>0),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&= +X.prototype.vga_memory_read=function(a){if(this.svga_enabled)return this.cpu.read8((a-655360|this.svga_bank_offset)+3758096384|0);var b=this.miscellaneous_graphics_register>>2&3;a-=Yc[b];if(0>a||a>=Zc[b])return y(a>>>0),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]}; -X.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-=Xc[c];0>a||a>=Yc[c]?(y(a>>>0),y(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.plane_write_bm&4&&(this.plane2[a]=b)}}; +X.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-=Yc[c];0>a||a>=Zc[c]?(y(a>>>0),y(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.plane_write_bm&4&&(this.plane2[a]=b)}}; X.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)};X.prototype.apply_feed=function(a){return a|a<<8|a<<16|a<<24}; X.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};X.prototype.apply_rotate=function(a){return(a|a<<8)>>>(this.planar_rotate_reg&7)&255};X.prototype.apply_setreset=function(a,b){var c=this.apply_expand(this.planar_setreset);return(a|b&c)&(~b|c)};X.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};X.prototype.apply_bitmask=function(a,b){return b&a|~b&this.latch_dword}; @@ -577,7 +581,7 @@ X.prototype.vga_addr_to_pixel=function(a){var b=this.vga_addr_shift_count();if(~ X.prototype.scan_line_to_screen_row=function(a){this.max_scan_line&128&&(a>>>=1);a=Math.ceil(a/(1+(this.max_scan_line&31)));this.crtc_mode&1||(a<<=1);this.crtc_mode&2||(a<<=1);return a};X.prototype.set_size_text=function(a,b){this.max_cols=a;this.max_rows=b;this.screen.set_size_text(a,b);this.bus.send("screen-set-size",[a,b,0])}; X.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])}}; -X.prototype.update_vga_size=function(){if(!this.svga_enabled){var a=Math.min(1+this.horizontal_display_enable_end,this.horizontal_blank_start),b=Math.min(1+this.vertical_display_enable_end,this.vertical_blank_start);if(a&&b)if(this.graphical_mode){a<<=3;var c=this.offset_register<<4,d=4;this.attribute_mode&64?(a>>>=1,c>>>=1,d=8):this.attribute_mode&2&&(d=1);b=this.scan_line_to_screen_row(b);var e=Yc[0];const f=this.vga_bytes_per_line();this.set_size_graphical(a,b,c,f?Math.ceil(e/f):b,d);this.update_vertical_retrace(); +X.prototype.update_vga_size=function(){if(!this.svga_enabled){var a=Math.min(1+this.horizontal_display_enable_end,this.horizontal_blank_start),b=Math.min(1+this.vertical_display_enable_end,this.vertical_blank_start);if(a&&b)if(this.graphical_mode){a<<=3;var c=this.offset_register<<4,d=4;this.attribute_mode&64?(a>>>=1,c>>>=1,d=8):this.attribute_mode&2&&(d=1);b=this.scan_line_to_screen_row(b);var e=Zc[0];const f=this.vga_bytes_per_line();this.set_size_graphical(a,b,c,f?Math.ceil(e/f):b,d);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)}}; X.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;e>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;a>2|(this.character_map_select&32)>>3,c=this.character_map_select&3|(this.character_map_select&16)>>2;this.font_page_ab_enabled=b!==c;this.screen.set_font_page(a[b],a[c]);this.complete_redraw()};const Zc="SWAP_IN SWAP_OUT MAJFLT MINFLT MEMFREE MEMTOT AVAIL CACHES HTLB_PGALLOC HTLB_PGFAIL".split(" "); -function $c(a,b){this.bus=b;this.zeroed=this.fp_cmd=this.actual=this.num_pages=0;this.virtio=new Fc(a,{name:"virtio-balloon",pci_id:88,device_id:4165,subsystem_device_id:5,common:{initial_port:55296,queues:[{size_supported:32,notify_offset:0},{size_supported:32,notify_offset:0},{size_supported:2,notify_offset:1},{size_supported:64,notify_offset:2}],features:[1,3,32],on_driver_ok:()=>{}},notification:{initial_port:55552,single_handler:!1,handlers:[c=>{const d=this.virtio.queues[c];for(;d.has_request();){var e= -d.pop_request();const f=new Uint8Array(e.length_readable);e.get_next_blob(f);this.virtio.queues[c].push_reply(e);e=f.byteLength/4;this.actual+=0===c?e:-e}this.virtio.queues[c].flush_replies()},c=>{var d=this.virtio.queues[c];if(d.has_request()){d=d.pop_request();const e=new Uint8Array(d.length_readable);d.get_next_blob(e);let f={};for(let g=0;g{const d= +X.prototype.set_font_page=function(){const a=[0,2,4,6,1,3,5,7],b=(this.character_map_select&12)>>2|(this.character_map_select&32)>>3,c=this.character_map_select&3|(this.character_map_select&16)>>2;this.font_page_ab_enabled=b!==c;this.screen.set_font_page(a[b],a[c]);this.complete_redraw()};const $c="SWAP_IN SWAP_OUT MAJFLT MINFLT MEMFREE MEMTOT AVAIL CACHES HTLB_PGALLOC HTLB_PGFAIL".split(" "); +function ad(a,b){this.bus=b;this.zeroed=this.fp_cmd=this.actual=this.num_pages=0;this.virtio=new Fc(a,{name:"virtio-balloon",pci_id:88,device_id:4165,subsystem_device_id:5,common:{initial_port:55296,queues:[{size_supported:32,notify_offset:0},{size_supported:32,notify_offset:0},{size_supported:2,notify_offset:1},{size_supported:64,notify_offset:2}],features:[1,3,32],on_driver_ok:()=>{}},notification:{initial_port:55552,single_handler:!1,handlers:[c=>{const d=this.virtio.queues[c];for(;d.has_request();){var e= +d.pop_request();const f=new Uint8Array(e.length_readable);e.get_next_blob(f);this.virtio.queues[c].push_reply(e);e=f.byteLength/4;this.actual+=0===c?e:-e}this.virtio.queues[c].flush_replies()},c=>{var d=this.virtio.queues[c];if(d.has_request()){d=d.pop_request();const e=new Uint8Array(d.length_readable);d.get_next_blob(e);let f={};for(let g=0;g{const d= this.virtio.queues[c];for(;d.has_request();){const f=d.pop_request();if(0this.num_pages,write:()=>{}},{bytes:4,name:"actual",read:()=>this.actual,write:()=>{}},{bytes:4,name:"free_page_hint_cmd_id",read:()=>this.fp_cmd,write:()=>{}}]}})}$c.prototype.Inflate=function(a){this.num_pages+=a;this.virtio.notify_config_changes()};$c.prototype.Deflate=function(a){this.num_pages-=a;this.virtio.notify_config_changes()}; -$c.prototype.Cleanup=function(a){this.fp_cmd=2;this.free_cb=a;this.zeroed=0;this.virtio.notify_config_changes()};$c.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.num_pages;a[2]=this.actual;return a};$c.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.num_pages=a[1];this.actual=a[2]};$c.prototype.GetStats=function(a){this.stats_cb=a;for(a=this.virtio.queues[2];a.has_request();){const b=a.pop_request();this.virtio.queues[2].push_reply(b)}this.virtio.queues[2].flush_replies()}; -$c.prototype.Reset=function(){};function ad(a,b,c,d){var e=new Uint8Array(b);const f=new Uint16Array(b);var g=new Uint32Array(b),h=e[497]||4,l=f[255];if(43605!==l)y(l);else if(l=f[257]|f[258]<<16,1400005704!==l)y(l);else{l=f[259];var m=e[529],n=f[283],p=g[139],q=g[140],r=e[565],x=518<=l?g[142]:255,C=g[146],t=g[147],A=g[150],M=g[151],v=g[152];y(l);y(m);y(n);y(g[133]);y(p);y(q);y(r);y(x);y(C);y(t);y(M);y(A);y(v);e[528]=255;e[529]=m&-97|128;f[274]=56832;f[253]=65535;y(56832);d+="\x00";y(581632);g[138]=581632;for(e=0;ethis.num_pages,write:()=>{}},{bytes:4,name:"actual",read:()=>this.actual,write:()=>{}},{bytes:4,name:"free_page_hint_cmd_id",read:()=>this.fp_cmd,write:()=>{}}]}})}ad.prototype.Inflate=function(a){this.num_pages+=a;this.virtio.notify_config_changes()};ad.prototype.Deflate=function(a){this.num_pages-=a;this.virtio.notify_config_changes()}; +ad.prototype.Cleanup=function(a){this.fp_cmd=2;this.free_cb=a;this.zeroed=0;this.virtio.notify_config_changes()};ad.prototype.get_state=function(){const a=[];a[0]=this.virtio;a[1]=this.num_pages;a[2]=this.actual;return a};ad.prototype.set_state=function(a){this.virtio.set_state(a[0]);this.num_pages=a[1];this.actual=a[2]};ad.prototype.GetStats=function(a){this.stats_cb=a;for(a=this.virtio.queues[2];a.has_request();){const b=a.pop_request();this.virtio.queues[2].push_reply(b)}this.virtio.queues[2].flush_replies()}; +ad.prototype.Reset=function(){};function bd(a,b,c,d){var e=new Uint8Array(b);const f=new Uint16Array(b);var g=new Uint32Array(b),h=e[497]||4,l=f[255];if(43605!==l)y(l);else if(l=f[257]|f[258]<<16,1400005704!==l)y(l);else{l=f[259];var m=e[529],n=f[283],p=g[139],q=g[140],r=e[565],x=518<=l?g[142]:255,C=g[146],t=g[147],A=g[150],M=g[151],v=g[152];y(l);y(m);y(n);y(g[133]);y(p);y(q);y(r);y(x);y(C);y(t);y(M);y(A);y(v);e[528]=255;e[529]=m&-97|128;f[274]=56832;f[253]=65535;y(56832);d+="\x00";y(581632);g[138]=581632;for(e=0;e>2)}; -O.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 Ca(this);this.io=c;this.bios.main=a.bios;this.bios.vga=a.vga_bios;this.load_bios();if(a.bzimage){const e=ad(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, +O.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 Ca(this);this.io=c;this.bios.main=a.bios;this.bios.vga=a.vga_bios;this.load_bios();if(a.bzimage){const e=bd(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}ua("bios config port, index="+y(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;ua("Multiboot magic found, flags: "+y(f>>>0,8),2);var g=this;this.io.register_read(244,this,function(){return 0},function(){return 0},function(){var n,p=31860;let q=0;if(c){q|=4;g.write32(31760,p);c+="\x00"; var r=(new TextEncoder).encode(c);g.write_blob(r,p);p+=r.length}if(f&2){q|=64;r=0;g.write32(31788,0);g.write32(31792,p);var x=0;var C=!1;for(n=0;4294967296>n;n+=131072)C&&void 0!==g.memory_map_read8[n>>>17]?(g.write32(p,20),g.write32(p+4,x),g.write32(p+8,0),g.write32(p+12,n-x),g.write32(p+16,0),g.write32(p+20,1),p+=24,r+=24,C=!1):C||void 0!==g.memory_map_read8[n>>>17]||(x=n,C=!0);g.write32(31788,r)}x=r=0;if(f&65536){n=d[e+12>>2];r=d[e+16>>2];var t=d[e+20>>2];x=d[e+24>>2];C=d[e+28>>2];y(n,8);y(r,8); -y(t,8);y(x,8);y(C,8);n=new Uint8Array(a,e-(n-r),0===t?void 0:t-r);g.write_blob(n,r);r=C|0;x=Math.max(t,x)}else if(1179403647===d[0]){C=new DataView(a);const [A,M]=Oc(C,Lc);console.assert(52===M);console.assert(1179403647===A.magic,"Bad magic");console.assert(1===A.class,"Unimplemented: 64 bit elf");console.assert(1===A.data,"Unimplemented: big endian");console.assert(1===A.version0,"Bad version0");console.assert(2===A.type,"Unimplemented type");console.assert(1===A.version1,"Bad version1");console.assert(52=== -A.ehsize,"Bad header size");console.assert(32===A.phentsize,"Bad program header size");console.assert(40===A.shentsize,"Bad section header size");[r]=Pc(new DataView(C.buffer,C.byteOffset+A.phoff,A.phentsize*A.phnum),Mc,A.phnum);Pc(new DataView(C.buffer,C.byteOffset+A.shoff,A.shentsize*A.shnum),Nc,A.shnum);C=A;n=r;r=C.entry;for(t of n)0!==t.type&&(1===t.type?t.paddr+t.memszr&&(r=r-t.vaddr+t.paddr)):y(t.paddr):2===t.type||3===t.type||4===t.type||6===t.type||7===t.type||1685382480===t.type||1685382481===t.type||1685382482===t.type||1685382483===t.type||y(t.type))}b&&(q|=8,g.write32(31764,1),g.write32(31768,p),t=x,0!==(t&4095)&&(t=(t&-4096)+4096),x=t+b.byteLength,g.write32(p,t),g.write32(p+4,x),g.write32(p+8,0),g.write32(p+12,0),g.write_blob(new Uint8Array(b),t));g.write32(31744,q);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(p=0;6>p;p++)g.segment_is_null[p]=0,g.segment_offsets[p]=0,g.segment_limits[p]=4294967295,g.sreg[p]=45058;g.instruction_pointer[0]=g.get_seg_cs()+r|0;g.update_state_flags();g.dump_state();g.dump_regs_short();return 732803074});this.io.register_write_consecutive(244,this,function(n){console.log("Test exited with code "+y(n,2));throw"HALT";},function(){},function(){},function(){});for(let n=0;15>=n;n++){function p(q){y(n);y(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;ne)break;if(h.flags&1)b=h.next;else break}}while(1)} -ed.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}; -ed.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 fd(a,b,c,d){const e=new Fc(a,{name:"virtio-9p",pci_id:48,device_id:4169,subsystem_device_id:9,common:{initial_port:43008,queues:[{size_supported:32,notify_offset:0}],features:[0,32,29,28],on_driver_ok:()=>{}},notification:{initial_port:43264,single_handler:!1,handlers:[f=>{if(0===f){for(f=e.queues[0];f.has_request();){const g=f.pop_request();d(g)}f.notify_me_after(0)}}]},isr_status:{initial_port:42752},device_specific:{initial_port:42496,struct:[{bytes:2,name:"mount tag length",read:()=> +fd.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}; +fd.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 gd(a,b,c,d){const e=new Fc(a,{name:"virtio-9p",pci_id:48,device_id:4169,subsystem_device_id:9,common:{initial_port:43008,queues:[{size_supported:32,notify_offset:0}],features:[0,32,29,28],on_driver_ok:()=>{}},notification:{initial_port:43264,single_handler:!1,handlers:[f=>{if(0===f){for(f=e.queues[0];f.has_request();){const g=f.pop_request();d(g)}f.notify_me_after(0)}}]},isr_status:{initial_port:42752},device_specific:{initial_port:42496,struct:[{bytes:2,name:"mount tag length",read:()=> b,write:()=>{}}].concat(Array.from(Array(254).keys()).map(f=>({bytes:1,name:"mount tag name "+f,read:()=>c[f]||0,write:()=>{}})))}});return e} -function bd(a,b,c){this.fs=a;this.bus=c;this.configspace_tagname=[104,111,115,116,57,112];this.configspace_taglen=this.configspace_tagname.length;this.virtio=fd(b,this.configspace_taglen,this.configspace_tagname,this.ReceiveRequest.bind(this));this.virtqueue=this.virtio.queues[0];this.VERSION="9P2000.L";this.msize=this.BLOCKSIZE=8192;this.replybuffer=new Uint8Array(2*this.msize);this.replybuffersize=0;this.fids=[]} -bd.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}; -bd.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])};bd.prototype.Createfid=function(a,b,c,d){return{inodeid:a,type:b,uid:c,dbg_name:d}}; -bd.prototype.update_dbg_name=function(a,b){for(const c of this.fids)c.inodeid===a&&(c.dbg_name=b)};bd.prototype.reset=function(){this.fids=[];this.virtio.reset()};bd.prototype.BuildReply=function(a,b,c){G(["w","b","h"],[c+7,a+1,b],this.replybuffer,0);this.replybuffersize=c+7};bd.prototype.SendError=function(a,b,c){b=G(["w"],[c],this.replybuffer,7);this.BuildReply(6,a,b)}; -bd.prototype.SendReply=function(a){a.set_next_blob(this.replybuffer.subarray(0,this.replybuffersize));this.virtqueue.push_reply(a);this.virtqueue.flush_replies()}; -bd.prototype.ReceiveRequest=async function(a){var b=new Uint8Array(a.length_readable);a.get_next_blob(b);var c={offset:0},d=I(["w","b","h"],b,c),e=d[1];d=d[2];switch(e){case 8:var f=this.fs.GetTotalSize();var g=this.fs.GetSpace(),h=[16914839];h[1]=this.BLOCKSIZE;h[2]=Math.floor(g/h[1]);h[3]=h[2]-Math.floor(f/h[1]);h[4]=h[2]-Math.floor(f/h[1]);h[5]=this.fs.CountUsedInodes();h[6]=this.fs.CountFreeInodes();h[7]=0;h[8]=256;f=G("wwddddddw".split(""),h,this.replybuffer,7);this.BuildReply(e,d,f);this.SendReply(a); +function cd(a,b,c){this.fs=a;this.bus=c;this.configspace_tagname=[104,111,115,116,57,112];this.configspace_taglen=this.configspace_tagname.length;this.virtio=gd(b,this.configspace_taglen,this.configspace_tagname,this.ReceiveRequest.bind(this));this.virtqueue=this.virtio.queues[0];this.VERSION="9P2000.L";this.msize=this.BLOCKSIZE=8192;this.replybuffer=new Uint8Array(2*this.msize);this.replybuffersize=0;this.fids=[]} +cd.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}; +cd.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])};cd.prototype.Createfid=function(a,b,c,d){return{inodeid:a,type:b,uid:c,dbg_name:d}}; +cd.prototype.update_dbg_name=function(a,b){for(const c of this.fids)c.inodeid===a&&(c.dbg_name=b)};cd.prototype.reset=function(){this.fids=[];this.virtio.reset()};cd.prototype.BuildReply=function(a,b,c){G(["w","b","h"],[c+7,a+1,b],this.replybuffer,0);this.replybuffersize=c+7};cd.prototype.SendError=function(a,b,c){b=G(["w"],[c],this.replybuffer,7);this.BuildReply(6,a,b)}; +cd.prototype.SendReply=function(a){a.set_next_blob(this.replybuffer.subarray(0,this.replybuffersize));this.virtqueue.push_reply(a);this.virtqueue.flush_replies()}; +cd.prototype.ReceiveRequest=async function(a){var b=new Uint8Array(a.length_readable);a.get_next_blob(b);var c={offset:0},d=I(["w","b","h"],b,c),e=d[1];d=d[2];switch(e){case 8:var f=this.fs.GetTotalSize();var g=this.fs.GetSpace(),h=[16914839];h[1]=this.BLOCKSIZE;h[2]=Math.floor(g/h[1]);h[3]=h[2]-Math.floor(f/h[1]);h[4]=h[2]-Math.floor(f/h[1]);h[5]=this.fs.CountUsedInodes();h[6]=this.fs.CountFreeInodes();h[7]=0;h[8]=256;f=G("wwddddddw".split(""),h,this.replybuffer,7);this.BuildReply(e,d,f);this.SendReply(a); break;case 112:case 12:h=I(["w","w"],b,c);f=h[0];var l=h[1];b=this.fids[f].inodeid;c=this.fs.GetInode(b);await this.fs.OpenInode(b,l);h=[];h[0]=c.qid;h[1]=this.msize-24;G(["Q","w"],h,this.replybuffer,7);this.BuildReply(e,d,17);this.SendReply(a);break;case 70:h=I(["w","w","s"],b,c);b=h[0];f=h[1];g=h[2];f=this.fs.Link(this.fids[b].inodeid,this.fids[f].inodeid,g);if(0>f){this.SendError(d,-1===f?"Operation not permitted":"Unknown error: "+-f,-f);this.SendReply(a);break}this.BuildReply(e,d,0);this.SendReply(a); break;case 16:h=I(["w","s","s","w"],b,c);f=h[0];g=h[1];var m=h[3];b=this.fs.CreateSymlink(g,this.fids[f].inodeid,h[2]);c=this.fs.GetInode(b);c.uid=this.fids[f].uid;c.gid=m;G(["Q"],[c.qid],this.replybuffer,7);this.BuildReply(e,d,13);this.SendReply(a);break;case 18:h=I("wswwww".split(""),b,c);f=h[0];g=h[1];l=h[2];b=h[3];c=h[4];m=h[5];b=this.fs.CreateNode(g,this.fids[f].inodeid,b,c);c=this.fs.GetInode(b);c.mode=l;c.uid=this.fids[f].uid;c.gid=m;G(["Q"],[c.qid],this.replybuffer,7);this.BuildReply(e,d, 13);this.SendReply(a);break;case 22:h=I(["w"],b,c);f=h[0];c=this.fs.GetInode(this.fids[f].inodeid);f=G(["s"],[c.symlink],this.replybuffer,7);this.BuildReply(e,d,f);this.SendReply(a);break;case 72:h=I(["w","s","w","w"],b,c);f=h[0];g=h[1];l=h[2];m=h[3];b=this.fs.CreateDirectory(g,this.fids[f].inodeid);c=this.fs.GetInode(b);c.mode=l|16384;c.uid=this.fids[f].uid;c.gid=m;G(["Q"],[c.qid],this.replybuffer,7);this.BuildReply(e,d,13);this.SendReply(a);break;case 14:h=I(["w","s","w","w","w"],b,c);f=h[0];g= @@ -732,12 +736,12 @@ f){this.SendError(d,"No such file or directory",2);this.SendReply(a);break}f=thi d,f);this.SendReply(a);break;case 104:h=I(["w","w","s","s","w"],b,c);f=h[0];g=h[4];y(h[1]);this.fids[f]=this.Createfid(0,1,g,"");c=this.fs.GetInode(this.fids[f].inodeid);G(["Q"],[c.qid],this.replybuffer,7);this.BuildReply(e,d,13);this.SendReply(a);this.bus.send("9p-attach");break;case 108:I(["h"],b,c);this.BuildReply(e,d,0);this.SendReply(a);break;case 110:h=I(["w","w","h"],b,c);f=h[0];l=h[1];m=h[2];if(0===m){this.fids[l]=this.Createfid(this.fids[f].inodeid,1,this.fids[f].uid,this.fids[f].dbg_name); G(["h"],[0],this.replybuffer,7);this.BuildReply(e,d,2);this.SendReply(a);break}g=[];for(h=0;h{const d=new Uint8Array(c.length_readable);c.get_next_blob(d);var e=I(["w","b","h"],d,{offset:0})[2];this.tag_bufchain.set(e,c);this.handle_fn(d,f=>{var g=I(["w","b","h"],f,{offset:0})[2];const h=this.tag_bufchain.get(g);h?(h.set_next_blob(f),this.virtqueue.push_reply(h), -this.virtqueue.flush_replies(),this.tag_bufchain.delete(g)):console.error("No bufchain found for tag: "+g)})});this.virtqueue=this.virtio.queues[0]}cd.prototype.get_state=function(){var a=[];a[0]=this.configspace_tagname;a[1]=this.configspace_taglen;a[2]=this.virtio;a[3]=this.tag_bufchain;return a};cd.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.tag_bufchain=a[3]}; -cd.prototype.reset=function(){this.virtio.reset()}; -function dd(a,b){this.socket=void 0;this.cpu=b;this.send_queue=[];this.url=a;this.reconnect_interval=1E4;this.last_connect_attempt=Date.now()-this.reconnect_interval;this.send_queue_limit=64;this.destroyed=!1;this.tag_bufchain=new Map;this.configspace_tagname=[104,111,115,116,57,112];this.configspace_taglen=this.configspace_tagname.length;this.virtio=fd(b,this.configspace_taglen,this.configspace_tagname,async c=>{const d=new Uint8Array(c.length_readable);c.get_next_blob(d);const e=I(["w","b","h"], -d,{offset:0})[2];this.tag_bufchain.set(e,c);this.send(d)});this.virtqueue=this.virtio.queues[0]}dd.prototype.get_state=function(){var a=[];a[0]=this.configspace_tagname;a[1]=this.configspace_taglen;a[2]=this.virtio;a[3]=this.tag_bufchain;return a};dd.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.tag_bufchain=a[3]};dd.prototype.reset=function(){this.virtio.reset()}; -dd.prototype.handle_message=function(a){a=new Uint8Array(a.data);const b=I(["w","b","h"],a,{offset:0})[2],c=this.tag_bufchain.get(b);c?(c.set_next_blob(a),this.virtqueue.push_reply(c),this.virtqueue.flush_replies(),this.tag_bufchain.delete(b)):console.error("Virtio9pProxy: No bufchain found for tag: "+b)};dd.prototype.handle_close=function(){this.destroyed||(this.connect(),setTimeout(this.connect.bind(this),this.reconnect_interval))}; -dd.prototype.handle_open=function(){for(var a=0;aa)){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)}}};dd.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())};dd.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)};}).call(this); +function dd(a,b){this.handle_fn=a;this.tag_bufchain=new Map;this.configspace_tagname=[104,111,115,116,57,112];this.configspace_taglen=this.configspace_tagname.length;this.virtio=gd(b,this.configspace_taglen,this.configspace_tagname,async c=>{const d=new Uint8Array(c.length_readable);c.get_next_blob(d);var e=I(["w","b","h"],d,{offset:0})[2];this.tag_bufchain.set(e,c);this.handle_fn(d,f=>{var g=I(["w","b","h"],f,{offset:0})[2];const h=this.tag_bufchain.get(g);h?(h.set_next_blob(f),this.virtqueue.push_reply(h), +this.virtqueue.flush_replies(),this.tag_bufchain.delete(g)):console.error("No bufchain found for tag: "+g)})});this.virtqueue=this.virtio.queues[0]}dd.prototype.get_state=function(){var a=[];a[0]=this.configspace_tagname;a[1]=this.configspace_taglen;a[2]=this.virtio;a[3]=this.tag_bufchain;return a};dd.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.tag_bufchain=a[3]}; +dd.prototype.reset=function(){this.virtio.reset()}; +function ed(a,b){this.socket=void 0;this.cpu=b;this.send_queue=[];this.url=a;this.reconnect_interval=1E4;this.last_connect_attempt=Date.now()-this.reconnect_interval;this.send_queue_limit=64;this.destroyed=!1;this.tag_bufchain=new Map;this.configspace_tagname=[104,111,115,116,57,112];this.configspace_taglen=this.configspace_tagname.length;this.virtio=gd(b,this.configspace_taglen,this.configspace_tagname,async c=>{const d=new Uint8Array(c.length_readable);c.get_next_blob(d);const e=I(["w","b","h"], +d,{offset:0})[2];this.tag_bufchain.set(e,c);this.send(d)});this.virtqueue=this.virtio.queues[0]}ed.prototype.get_state=function(){var a=[];a[0]=this.configspace_tagname;a[1]=this.configspace_taglen;a[2]=this.virtio;a[3]=this.tag_bufchain;return a};ed.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.tag_bufchain=a[3]};ed.prototype.reset=function(){this.virtio.reset()}; +ed.prototype.handle_message=function(a){a=new Uint8Array(a.data);const b=I(["w","b","h"],a,{offset:0})[2],c=this.tag_bufchain.get(b);c?(c.set_next_blob(a),this.virtqueue.push_reply(c),this.virtqueue.flush_replies(),this.tag_bufchain.delete(b)):console.error("Virtio9pProxy: No bufchain found for tag: "+b)};ed.prototype.handle_close=function(){this.destroyed||(this.connect(),setTimeout(this.connect.bind(this),this.reconnect_interval))}; +ed.prototype.handle_open=function(){for(var a=0;aa)){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)}}};ed.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())};ed.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)};}).call(this); diff --git a/src/renderer/smb/index.ts b/src/renderer/smb/index.ts index 7c45ca4..aaf3789 100644 --- a/src/renderer/smb/index.ts +++ b/src/renderer/smb/index.ts @@ -56,9 +56,9 @@ interface V86 { const log = (...a: unknown[]) => console.log("[smb]", ...a); -export function setupSmbShare(emulator: V86, hostPath: string) { +export function setupSmbShare(emulator: V86, hostPath: string, toolsRoot?: string) { log(`serving ${hostPath} on \\\\HOST\\${shareNameFor(hostPath)} ` + - `(+ \\\\HOST\\${TOOLS_SHARE}) port 139`); + `(+ \\\\HOST\\${TOOLS_SHARE}${toolsRoot ? ` ← ${toolsRoot}` : ""}) port 139`); // SPIKE diagnostic: count every ethernet frame so we know if the NIC is // emitting anything at all (DHCP, ARP, anything). Logged on a timer so @@ -101,7 +101,7 @@ export function setupSmbShare(emulator: V86, hostPath: string) { const wireConn = (conn: TCPConnection) => { log(`← TCP SYN ${conn.tuple}`); const framer = new NetBIOSFramer(); - const session = new SmbSession(hostPath); + const session = new SmbSession(hostPath, toolsRoot); const handler = (data: Uint8Array) => { for (const msg of framer.push(data)) { diff --git a/src/renderer/smb/server.ts b/src/renderer/smb/server.ts index 393fa07..281d44c 100644 --- a/src/renderer/smb/server.ts +++ b/src/renderer/smb/server.ts @@ -110,6 +110,7 @@ export class SmbSession { // consult it so clicking "15UNDE~2.PDF" finds the right long-named file. private sfnMaps = new Map>(); private readonly realRoot: string; + private readonly toolsRoot?: string; public readonly shareName: string; public capture = true; @@ -120,7 +121,7 @@ export class SmbSession { // makes the mapping survive reboots. private readonly virtuals: Map; - constructor(rootPath: string) { + constructor(rootPath: string, toolsRoot?: string) { this.realRoot = fs.realpathSync(rootPath); this.shareName = shareNameFor(this.realRoot); const enc = (s: string) => new TextEncoder().encode(s); @@ -128,8 +129,8 @@ export class SmbSession { ["README.TXT", enc( "windows95 tools\r\n" + "----------------\r\n" + - "These files are generated by the windows95 app and do not exist on\r\n" + - "your host disk.\r\n\r\n" + + "These files are served by the windows95 app from\r\n" + + ` ${toolsRoot ?? "(in-memory)"}\r\n\r\n` + ` \\\\HOST\\${this.shareName.padEnd(12)} your shared folder (${this.realRoot})\r\n` + ` \\\\HOST\\${TOOLS_SHARE.padEnd(12)} this folder\r\n\r\n` + "_MAPZ.BAT maps your shared folder to drive Z:. Copy it to\r\n" + @@ -145,6 +146,9 @@ export class SmbSession { "PAUSE\r\n" )], ]); + this.toolsRoot = toolsRoot && fs.existsSync(toolsRoot) + ? fs.realpathSync(toolsRoot) + : undefined; } private getVirtual(tid: number, smbPath: string): Uint8Array | undefined { @@ -161,6 +165,26 @@ export class SmbSession { ({ name, sfn: name, attr: ATTR_ARCHIVE, stat: stat(bytes.length) })); } + /** + * Directory listing for SEARCH/FIND_FIRST2. Overlays the synthetic + * README/_MAPZ at the TOOLS root; everything else hits the backing fs. + * Returns null when the directory doesn't resolve (caller emits BADPATH). + */ + private listForSearch(tid: number, dirPart: string): + { all: DirEntry[]; dotStat: DirEntry["stat"] } | null { + const hostDir = this.resolve(tid, dirPart || "\\"); + const hostOk = !!hostDir && fs.existsSync(hostDir); + if (tid === TID_TOOLS && isRootPath(dirPart)) { + return { + all: hostOk ? [...this.listTools(), ...this.listDir(hostDir!)] : this.listTools(), + dotStat: hostOk ? fs.statSync(hostDir!) + : { isDirectory: () => true, size: 0, mtime: new Date() }, + }; + } + if (!hostOk) return null; + return { all: this.listDir(hostDir!), dotStat: fs.statSync(hostDir!) }; + } + /** * Read a host directory once, generate stable 8.3 names, cache the mapping. * The cache lives for the session — directory contents changing underneath @@ -387,7 +411,10 @@ export class SmbSession { // including via symlinks. // ─────────────────────────────────────────────────────────────────────────── private resolve(tid: number, smbPath: string): string | null { - if (tid !== TID_SHARE) return null; // TOOLS/IPC have no backing fs + const root = tid === TID_SHARE ? this.realRoot + : tid === TID_TOOLS ? this.toolsRoot + : undefined; + if (!root) return null; let p = smbPath.replace(/\\/g, "/"); if (p.startsWith("/")) p = p.slice(1); @@ -396,7 +423,7 @@ export class SmbSession { // names (if the client somehow learned them) or they'll fail existence // checks below. const parts = p ? p.split("/") : []; - let cur = this.realRoot; + let cur = root; for (const part of parts) { if (!part || part === ".") continue; const map = this.sfnMaps.get(cur); @@ -406,7 +433,7 @@ export class SmbSession { const candidate = cur; // Lexical check first — fast reject for ../../ without touching disk - const lex = path.relative(this.realRoot, candidate); + const lex = path.relative(root, candidate); if (lex.startsWith("..") || path.isAbsolute(lex)) return null; // Symlink check: realpath the deepest existing ancestor, then re-append @@ -427,7 +454,7 @@ export class SmbSession { } const real = tail ? path.join(probe, tail) : probe; - if (real !== this.realRoot && !real.startsWith(this.realRoot + path.sep)) { + if (real !== root && !real.startsWith(root + path.sep)) { return null; } return real; @@ -446,16 +473,12 @@ export class SmbSession { private queryInfo(req: SmbHeader): Uint8Array { const smbPath = this.smbPathFromBytes(req); - if (req.tid === TID_TOOLS) { - const v = this.getVirtual(req.tid, smbPath); - if (!v && !isRootPath(smbPath)) { - return buildSmb(req, CMD_QUERY_INFORMATION, dosError(ERRDOS, ERR_BADFILE), - new Uint8Array(0), new Uint8Array(0)); - } + const v = this.getVirtual(req.tid, smbPath); + if (v) { const words = new Writer() - .u16(v ? ATTR_ARCHIVE : ATTR_DIRECTORY) + .u16(ATTR_ARCHIVE) .u32(unixToSmbTime(new Date())) - .u32(v?.length ?? 0) + .u32(v.length) .zero(10) .build(); return buildSmb(req, CMD_QUERY_INFORMATION, 0, words, new Uint8Array(0)); @@ -478,11 +501,6 @@ export class SmbSession { private checkDirectory(req: SmbHeader): Uint8Array { const smbPath = this.smbPathFromBytes(req); - if (req.tid === TID_TOOLS) { - const ok = isRootPath(smbPath); - return buildSmb(req, CMD_CHECK_DIRECTORY, ok ? 0 : dosError(ERRDOS, ERR_BADPATH), - new Uint8Array(0), new Uint8Array(0)); - } const hostPath = this.resolve(req.tid, smbPath); if (!hostPath || !fs.existsSync(hostPath) || !fs.statSync(hostPath).isDirectory()) { return buildSmb(req, CMD_CHECK_DIRECTORY, dosError(ERRDOS, ERR_BADPATH), @@ -530,15 +548,6 @@ export class SmbSession { log(`open "${smbPath}" → virtual (${vbytes.length} bytes)`); return this.buildOpenReply(req, cmd, fid, ATTR_ARCHIVE, vbytes.length, new Date()); } - if (req.tid === TID_TOOLS) { - if (isRootPath(smbPath)) { - const fid = this.nextFid++; - this.fids.set(fid, { hostPath: "", fd: -1, size: 0, isDir: true }); - return this.buildOpenReply(req, cmd, fid, ATTR_DIRECTORY, 0, new Date()); - } - return buildSmb(req, cmd, dosError(ERRDOS, ERR_BADFILE), - new Uint8Array(0), new Uint8Array(0)); - } const hostPath = this.resolve(req.tid, smbPath); log(`open "${smbPath}" → ${hostPath}`); @@ -736,24 +745,12 @@ export class SmbSession { const dirPart = lastSep >= 0 ? pattern.slice(0, lastSep) : ""; const namePart = lastSep >= 0 ? pattern.slice(lastSep + 1) : pattern; log(`SEARCH "${pattern}" tid=${req.tid}`); - let all: DirEntry[]; - let dotStat: DirEntry["stat"]; - if (req.tid === TID_TOOLS) { - if (!isRootPath(dirPart)) { - return buildSmb(req, CMD_SEARCH, dosError(ERRDOS, ERR_BADPATH), - new Uint8Array(0), new Uint8Array(0)); - } - all = this.listTools(); - dotStat = { isDirectory: () => true, size: 0, mtime: new Date() }; - } else { - const hostDir = this.resolve(req.tid, dirPart || "\\"); - if (!hostDir || !fs.existsSync(hostDir)) { - return buildSmb(req, CMD_SEARCH, dosError(ERRDOS, ERR_BADPATH), - new Uint8Array(0), new Uint8Array(0)); - } - all = this.listDir(hostDir); - dotStat = fs.statSync(hostDir); + const listed = this.listForSearch(req.tid, dirPart); + if (!listed) { + return buildSmb(req, CMD_SEARCH, dosError(ERRDOS, ERR_BADPATH), + new Uint8Array(0), new Uint8Array(0)); } + const { all, dotStat } = listed; const matcher = wildcardMatcher(namePart); // Match against the SFN — that's what the client sees and asks for const entries = all.filter(e => matcher(e.sfn)); @@ -878,24 +875,12 @@ export class SmbSession { const lastSep = Math.max(pattern.lastIndexOf("\\"), pattern.lastIndexOf("/")); const dirPart = lastSep >= 0 ? pattern.slice(0, lastSep) : ""; const namePart = lastSep >= 0 ? pattern.slice(lastSep + 1) : pattern; - let all: DirEntry[]; - let dotStat: DirEntry["stat"]; - if (req.tid === TID_TOOLS) { - if (!isRootPath(dirPart)) { - return buildSmb(req, CMD_TRANSACTION2, dosError(ERRDOS, ERR_BADPATH), - new Uint8Array(0), new Uint8Array(0)); - } - all = this.listTools(); - dotStat = { isDirectory: () => true, size: 0, mtime: new Date() }; - } else { - const hostDir = this.resolve(req.tid, dirPart || "\\"); - if (!hostDir || !fs.existsSync(hostDir)) { - return buildSmb(req, CMD_TRANSACTION2, dosError(ERRDOS, ERR_BADPATH), - new Uint8Array(0), new Uint8Array(0)); - } - all = this.listDir(hostDir); - dotStat = fs.statSync(hostDir); + const listed = this.listForSearch(req.tid, dirPart); + if (!listed) { + return buildSmb(req, CMD_TRANSACTION2, dosError(ERRDOS, ERR_BADPATH), + new Uint8Array(0), new Uint8Array(0)); } + const { all, dotStat } = listed; const matcher = wildcardMatcher(namePart); const entries = all.filter(e => matcher(e.sfn) || matcher(e.name)); @@ -1075,19 +1060,13 @@ export class SmbSession { pr.u32(); const smbPath = (req.flags2 & 0x8000) ? pr.ucs2() : pr.cstr(); log(`QUERY_PATH_INFO level=0x${level.toString(16)} "${smbPath}"`); - if (req.tid === TID_TOOLS) { - const v = this.getVirtual(req.tid, smbPath); - const isDir = !v && isRootPath(smbPath); - if (!v && !isDir) { - return buildSmb(req, CMD_TRANSACTION2, dosError(ERRDOS, ERR_BADFILE), - new Uint8Array(0), new Uint8Array(0)); - } + const v = this.getVirtual(req.tid, smbPath); + if (v) { const dd = unixToDosDateTime(new Date()); - const sz = v?.length ?? 0; const data = new Writer() .u16(dd.date).u16(dd.time).u16(dd.date).u16(dd.time).u16(dd.date).u16(dd.time) - .u32(sz).u32(sz) - .u16(isDir ? ATTR_DIRECTORY : ATTR_ARCHIVE) + .u32(v.length).u32(v.length) + .u16(ATTR_ARCHIVE) .build(); return this.trans2Reply(req, new Writer().u16(0).build(), data); } diff --git a/tsconfig.json b/tsconfig.json index 27e5de2..fe94bd8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "rootDir": ".", "outDir": "./dist", "allowJs": true, "allowSyntheticDefaultImports": true,