Seamless mouse (VMware backdoor + VBADOS) and fs-backed TOOLS share (#355)

* Seamless mouse via VMware backdoor + fs-backed TOOLS share

v86 (rebuilt libv86.js from fork branch vmware-mouse): new VMwareMouse
device on port 0x5658 implementing GETVERSION/ABSPOINTER_* fed by the
existing mouse-absolute bus event. Move-only packets are coalesced so
the guest cursor never falls more than one frame behind. Emits
vmware-absolute-mouse on the bus when the guest driver toggles mode.

Renderer: listens for that event, keeps the v86 mouse enabled without
pointer lock, drops the startup auto-capture, and hides the host cursor
over the canvas (.seamless-mouse) while the driver is active. Falls back
to click-to-capture when no driver is present.

SMB: TOOLS share is now backed by the bundled guest-tools/ directory
(subdirectories work) with the synthetic README.TXT/_MAPZ.BAT overlaid
at the root. resolve() routes by tid; SEARCH and FIND_FIRST2 share a
single listForSearch helper.

guest-tools/mouse-driver/: VBMOUSE.EXE + VBMOUSE.DRV from VBADOS
(Javier S. Pedro, GPLv2). Load the TSR from AUTOEXEC.BAT and set
mouse.drv=vbmouse.drv in SYSTEM.INI to enable seamless mouse.

Also: tsconfig rootDir "." for TS 6.0 (preserves dist/src/ layout).

* docs: windows95-base now includes vmware-abspointer
This commit is contained in:
Felix Rieseberg
2026-04-11 13:54:32 -07:00
committed by Felix Rieseberg
parent 1dbb853fe6
commit 27b9e0eb7a
14 changed files with 278 additions and 172 deletions

View File

@@ -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

23
guest-tools/README.md Normal file
View File

@@ -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.

View File

@@ -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

View File

@@ -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

Binary file not shown.

View File

@@ -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 <ACTION> <ARGS..>
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 <ON|OFF> Enable/disable wheel API support.
0.7: wheelkey <KEY|OFF> Emulate a specific keystroke on wheel scroll.
0.8: Supported keys: updn, pageupdn.
0.9: integ <ON|OFF> Enable/disable VirtualBox integration.
0.10: hostcur <ON|OFF> 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

Binary file not shown.

View File

@@ -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 = {

View File

@@ -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 {

View File

@@ -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()}
<div id="emulator">
<div
id="emulator"
className={this.state.hasAbsoluteMouse ? "seamless-mouse" : undefined}
>
<div id="emulator-text-screen"></div>
<canvas id="emulator-canvas"></canvas>
</div>
@@ -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);

View File

@@ -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)=>31<b&&128>b?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<R;++La,++Ea,P+=fa){const Ma=w[Ea];for(let ta=128;0<ta;ta>>=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)=>31<b&&128>b?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<R;++La,++Ea,P+=fa){const Ma=w[Ea];for(let ta=128;0<ta;ta>>=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;Q<v;Q++)for(let P=0;P<M;P++){const S=4*(Q*M+P),ja=A[S+0],fa=A[S+3];K.fillStyle=c(A[S+2]);K.fillRect(P*u[0],Q*u[1],u[0],u[1]);K.fillStyle=c(fa);K.fillText(Rb[ja],
P*u[0],Q*u[1])}"none"!==m.style.display&&n<v&&p<M&&(K.fillStyle=m.style.backgroundColor,K.fillRect(p*u[0],n*u[1]+parseInt(m.style.marginTop,10),parseInt(m.style.width,10),parseInt(m.style.height,10)));w.src=H.toDataURL("image/png")}return w};this.put_char=function(w,u,H,K,Q,P){u=4*(w*M+u);A[u+0]=H;A[u+1]=K;A[u+2]=Q;A[u+3]=P;C[w]=1};this.timer=function(){vb=requestAnimationFrame(()=>this.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;w<v;w++)C[w]&&(this.text_update_row(w),C[w]=0)};this.update_graphical=function(){this.screen_fill_buffer()};this.update_graphical_text=function(){if(L){var w=performance.now();if(266<w-gc){sb=!sb;ub&&(C[n]=1);var u=4*M;for(let ja=0,fa=0;ja<v;++ja)if(C[ja])fa+=u;else for(var H=0;H<M;++H,fa+=4)if(A[fa+1]&1){C[ja]=1;fa+=u-4*H;break}gc=w}w=Ta.canvas;u=T.canvas;H=4*M;const Q=M*na,P=R;let S=0;for(let ja=0,fa=0,Z=0;ja<v;++ja,fa+=R){if(!C[ja]){Z+=H;continue}++S;
T.clearRect(0,P,Q,R);let Ea,Fa,La,Ma;for(let ta=0;ta<Q;ta+=na,Z+=4){const hc=A[Z+0];var K=A[Z+1];const ic=A[Z+2],jc=A[Z+3],kc=K&2?Pb:Ob;K=(!(K&1)||sb)&&fc[(kc<<8)+hc];La!==ic&&(void 0!==La&&(L.fillStyle=c(La),L.fillRect(Ma,fa,ta-Ma,R)),La=ic,Ma=ta);Ea!==jc&&(void 0!==Ea&&(T.fillStyle=c(Ea),T.fillRect(Fa,0,ta-Fa,R)),Ea=jc,Fa=ta);K&&T.drawImage(w,hc*na,kc*R,na,R,ta,P,na,R)}T.fillStyle=c(Ea);T.fillRect(Fa,0,Q-Fa,R);T.globalCompositeOperation="destination-in";T.drawImage(u,0,P,Q,R,0,0,Q,R);T.globalCompositeOperation=
"source-over";L.fillStyle=c(La);L.fillRect(Ma,fa,Q-Ma,R);L.drawImage(u,0,0,Q,R,0,fa,Q,R)}S&&(sb&&ub&&C[n]&&(L.fillStyle=c(A[4*(n*M+p)+3]),L.fillRect(p*na,n*R+tb,na,Qb-tb+1)),C.fill(0));S&&h.drawImage(L.canvas,0,0)}};this.destroy=function(){vb&&(cancelAnimationFrame(vb),vb=0)};this.pause=function(){Sb=!0;m.classList.remove("blinking-cursor")};this.continue=function(){Sb=!1;m.classList.add("blinking-cursor")};this.set_mode=function(w){t=w?1:a.use_graphical_text?2:0;0===t?(l.style.display="block",g.style.display=
"none"):(l.style.display="none",g.style.display="block",2===t&&C&&C.fill(1))};this.set_font_bitmap=function(w,u,H,K,Q,P){const S=H?16:u?9:8;if(R!==w||na!==S||Mb!==u||Lb!==H||Nb!==K||P)P=na!==S||R!==w,R=w,na=S,Mb=u,Lb=H,Nb=K,2===t&&(d(Q),C.fill(1),P&&this.set_size_graphical_text())};this.set_font_page=function(w,u){if(Ob!==w||Pb!==u)Ob=w,Pb=u,C.fill(1)};this.clear_screen=function(){h.fillStyle="#000";h.fillRect(0,0,g.width,g.height)};this.set_size_graphical_text=function(){if(Ta){var w=na*M,u=R*v,
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,Lb,gc=new Int8Array(2048),R,na,Nb,Mb,Ob,Pb=0,Qb=0,tb,hc=0,ub,Rb,vb,Sb=sa(a.encoding),wb=0,Tb=!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;Q<v;Q++)for(let P=0;P<M;P++){const S=4*(Q*M+P),ja=A[S+0],fa=A[S+3];K.fillStyle=c(A[S+2]);K.fillRect(P*u[0],Q*u[1],u[0],u[1]);K.fillStyle=c(fa);K.fillText(Sb[ja],
P*u[0],Q*u[1])}"none"!==m.style.display&&n<v&&p<M&&(K.fillStyle=m.style.backgroundColor,K.fillRect(p*u[0],n*u[1]+parseInt(m.style.marginTop,10),parseInt(m.style.width,10),parseInt(m.style.height,10)));w.src=H.toDataURL("image/png")}return w};this.put_char=function(w,u,H,K,Q,P){u=4*(w*M+u);A[u+0]=H;A[u+1]=K;A[u+2]=Q;A[u+3]=P;C[w]=1};this.timer=function(){wb=requestAnimationFrame(()=>this.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;w<v;w++)C[w]&&(this.text_update_row(w),C[w]=0)};this.update_graphical=function(){this.screen_fill_buffer()};this.update_graphical_text=function(){if(L){var w=performance.now();if(266<w-hc){tb=!tb;vb&&(C[n]=1);var u=4*M;for(let ja=0,fa=0;ja<v;++ja)if(C[ja])fa+=u;else for(var H=0;H<M;++H,fa+=4)if(A[fa+1]&1){C[ja]=1;fa+=u-4*H;break}hc=w}w=Ta.canvas;u=T.canvas;H=4*M;const Q=M*na,P=R;let S=0;for(let ja=0,fa=0,Z=0;ja<v;++ja,fa+=R){if(!C[ja]){Z+=H;continue}++S;
T.clearRect(0,P,Q,R);let Ea,Fa,La,Ma;for(let ta=0;ta<Q;ta+=na,Z+=4){const ic=A[Z+0];var K=A[Z+1];const jc=A[Z+2],kc=A[Z+3],lc=K&2?Qb:Pb;K=(!(K&1)||tb)&&gc[(lc<<8)+ic];La!==jc&&(void 0!==La&&(L.fillStyle=c(La),L.fillRect(Ma,fa,ta-Ma,R)),La=jc,Ma=ta);Ea!==kc&&(void 0!==Ea&&(T.fillStyle=c(Ea),T.fillRect(Fa,0,ta-Fa,R)),Ea=kc,Fa=ta);K&&T.drawImage(w,ic*na,lc*R,na,R,ta,P,na,R)}T.fillStyle=c(Ea);T.fillRect(Fa,0,Q-Fa,R);T.globalCompositeOperation="destination-in";T.drawImage(u,0,P,Q,R,0,0,Q,R);T.globalCompositeOperation=
"source-over";L.fillStyle=c(La);L.fillRect(Ma,fa,Q-Ma,R);L.drawImage(u,0,0,Q,R,0,fa,Q,R)}S&&(tb&&vb&&C[n]&&(L.fillStyle=c(A[4*(n*M+p)+3]),L.fillRect(p*na,n*R+ub,na,Rb-ub+1)),C.fill(0));S&&h.drawImage(L.canvas,0,0)}};this.destroy=function(){wb&&(cancelAnimationFrame(wb),wb=0)};this.pause=function(){Tb=!0;m.classList.remove("blinking-cursor")};this.continue=function(){Tb=!1;m.classList.add("blinking-cursor")};this.set_mode=function(w){t=w?1:a.use_graphical_text?2:0;0===t?(l.style.display="block",g.style.display=
"none"):(l.style.display="none",g.style.display="block",2===t&&C&&C.fill(1))};this.set_font_bitmap=function(w,u,H,K,Q,P){const S=H?16:u?9:8;if(R!==w||na!==S||Nb!==u||Mb!==H||Ob!==K||P)P=na!==S||R!==w,R=w,na=S,Nb=u,Mb=H,Ob=K,2===t&&(d(Q),C.fill(1),P&&this.set_size_graphical_text())};this.set_font_page=function(w,u){if(Pb!==w||Qb!==u)Pb=w,Qb=u,C.fill(1)};this.clear_screen=function(){h.fillStyle="#000";h.fillRect(0,0,g.width,g.height)};this.set_size_graphical_text=function(){if(Ta){var w=na*M,u=R*v,
H=2*R;L&&L.canvas.width===w&&L.canvas.height===u&&T.canvas.height===H||(L?(L.canvas.width=w,L.canvas.height=u,T.canvas.width=w,T.canvas.height=H):(L=(new OffscreenCanvas(w,u)).getContext("2d",{alpha:!1}),T=(new OffscreenCanvas(w,H)).getContext("2d")),this.set_size_graphical(w,u,w,u),C.fill(1))}};this.set_size_text=function(w,u){if(w!==M||u!==v)if(C=new Int8Array(u),A=new Int32Array(w*u*4),M=w,v=u,0===t){for(;l.childNodes.length>u;)l.removeChild(l.firstChild);for(;l.childNodes.length<u;)l.appendChild(document.createElement("div"));
for(w=0;w<u;w++)this.text_update_row(w);e(l,q,r,!0)}else 2===t&&this.set_size_graphical_text()};this.set_size_graphical=function(w,u){g.style.display="block";g.width=w;g.height=u;h.imageSmoothingEnabled=!1;x=640>=w&&2*w<window.innerWidth*window.devicePixelRatio&&2*u<window.innerHeight*window.devicePixelRatio?2:1;e(g,q*x,r*x,!1)};this.set_scale=function(w,u){q=w;r=u;e(l,q,r,!0);e(g,q*x,r*x,!1)};this.update_cursor_scanline=function(w,u,H){if(w!==tb||u!==Qb||H!==ub)0===t?H?(m.style.display="inline",
m.style.height=u-w+"px",m.style.marginTop=w+"px"):m.style.display="none":2===t&&n<v&&(C[n]=1),tb=w,Qb=u,ub=H};this.update_cursor=function(w,u){if(w!==n||u!==p)w<v&&(C[w]=1),n<v&&(C[n]=1),n=w,p=u};this.text_update_row=function(w){var u=4*w*M,H;var K=l.childNodes[w];var Q=document.createElement("div");for(var P=0;P<M;){var S=document.createElement("span");var ja=A[u+1]&1;var fa=A[u+2];var Z=A[u+3];ja&&S.classList.add("blink");S.style.backgroundColor=c(fa);S.style.color=c(Z);for(H="";P<M&&(A[u+1]&1)===
ja&&A[u+2]===fa&&A[u+3]===Z;)if(H+=Rb[A[u+0]],P++,u+=4,w===n)if(P===p)break;else if(P===p+1){m.style.backgroundColor=S.style.color;Q.appendChild(m);break}S.textContent=H;Q.appendChild(S)}K.parentNode.replaceChild(Q,K)};this.update_buffer=function(w){for(const u of w)h.putImageData(u.image_data,u.screen_x-u.buffer_x,u.screen_y-u.buffer_y,u.buffer_x,u.buffer_y,u.buffer_width,u.buffer_height)};this.get_text_screen=function(){for(var w=[],u=0;u<v;u++)w.push(this.get_text_row(u));return w};this.get_text_row=
function(w){var u=w*M*4;w=u+4*M;let H="";for(;u<w;u+=4)H+=Rb[A[u]];return H};this.init()};function z(a){this.buffer=a;this.byteLength=a.byteLength;this.onprogress=this.onload=void 0}z.prototype.load=function(){this.onload&&this.onload({buffer:this.buffer})};z.prototype.get=function(a,b,c){c(new Uint8Array(this.buffer,a,b))};z.prototype.set=function(a,b,c){(new Uint8Array(this.buffer,a,b.byteLength)).set(b);c()};z.prototype.get_buffer=function(a){a(this.buffer)};z.prototype.get_state=function(){const a=[];a[0]=this.byteLength;a[1]=new Uint8Array(this.buffer);return a};
for(w=0;w<u;w++)this.text_update_row(w);e(l,q,r,!0)}else 2===t&&this.set_size_graphical_text()};this.set_size_graphical=function(w,u){g.style.display="block";g.width=w;g.height=u;h.imageSmoothingEnabled=!1;x=640>=w&&2*w<window.innerWidth*window.devicePixelRatio&&2*u<window.innerHeight*window.devicePixelRatio?2:1;e(g,q*x,r*x,!1)};this.set_scale=function(w,u){q=w;r=u;e(l,q,r,!0);e(g,q*x,r*x,!1)};this.update_cursor_scanline=function(w,u,H){if(w!==ub||u!==Rb||H!==vb)0===t?H?(m.style.display="inline",
m.style.height=u-w+"px",m.style.marginTop=w+"px"):m.style.display="none":2===t&&n<v&&(C[n]=1),ub=w,Rb=u,vb=H};this.update_cursor=function(w,u){if(w!==n||u!==p)w<v&&(C[w]=1),n<v&&(C[n]=1),n=w,p=u};this.text_update_row=function(w){var u=4*w*M,H;var K=l.childNodes[w];var Q=document.createElement("div");for(var P=0;P<M;){var S=document.createElement("span");var ja=A[u+1]&1;var fa=A[u+2];var Z=A[u+3];ja&&S.classList.add("blink");S.style.backgroundColor=c(fa);S.style.color=c(Z);for(H="";P<M&&(A[u+1]&1)===
ja&&A[u+2]===fa&&A[u+3]===Z;)if(H+=Sb[A[u+0]],P++,u+=4,w===n)if(P===p)break;else if(P===p+1){m.style.backgroundColor=S.style.color;Q.appendChild(m);break}S.textContent=H;Q.appendChild(S)}K.parentNode.replaceChild(Q,K)};this.update_buffer=function(w){for(const u of w)h.putImageData(u.image_data,u.screen_x-u.buffer_x,u.screen_y-u.buffer_y,u.buffer_x,u.buffer_y,u.buffer_width,u.buffer_height)};this.get_text_screen=function(){for(var w=[],u=0;u<v;u++)w.push(this.get_text_row(u));return w};this.get_text_row=
function(w){var u=w*M*4;w=u+4*M;let H="";for(;u<w;u+=4)H+=Sb[A[u]];return H};this.init()};function z(a){this.buffer=a;this.byteLength=a.byteLength;this.onprogress=this.onload=void 0}z.prototype.load=function(){this.onload&&this.onload({buffer:this.buffer})};z.prototype.get=function(a,b,c){c(new Uint8Array(this.buffer,a,b))};z.prototype.set=function(a,b,c){(new Uint8Array(this.buffer,a,b.byteLength)).set(b);c()};z.prototype.get_buffer=function(a){a(this.buffer)};z.prototype.get_state=function(){const a=[];a[0]=this.byteLength;a[1]=new Uint8Array(this.buffer);return a};
z.prototype.set_state=function(a){this.byteLength=a[0];this.buffer=a[1].slice().buffer};function xa(a,b,c){this.filename=a;this.byteLength=b;this.block_cache=new Map;this.block_cache_is_write=new Set;this.fixed_chunk_size=c;this.cache_reads=!!c;this.onprogress=this.onload=void 0}xa.prototype.load=async function(){void 0===this.byteLength&&(this.byteLength=await pa(this.filename));this.onload&&this.onload(Object.create(null))};
xa.prototype.get_from_cache=function(a,b){var c=b/256;a/=256;for(var d=0;d<c;d++)if(!this.block_cache.get(a+d))return;if(1===c)return this.block_cache.get(a);b=new Uint8Array(b);for(d=0;d<c;d++)b.set(this.block_cache.get(a+d),256*d);return b};
xa.prototype.get=function(a,b,c){var d=this.get_from_cache(a,b);if(d)c(d);else{var e=a,f=b;this.fixed_chunk_size&&(e=a-a%this.fixed_chunk_size,f=Math.ceil((a-e+b)/this.fixed_chunk_size)*this.fixed_chunk_size);oa(this.filename,{done:function(g){g=new Uint8Array(g);this.handle_read(e,f,g);e===a&&f===b?c(g):c(g.subarray(a-e,a-e+b))}.bind(this),range:{start:e,length:f}})}};
@@ -170,7 +170,7 @@ kb.prototype.queue=function(a){var b=a[0].length,c=b/this.sampling_rate;if(1<thi
a=this.audio_context.createBufferSource();a.buffer=d;a.connect(this.node_lowpass);a.addEventListener("ended",this.pump.bind(this));d=this.audio_context.currentTime;if(this.buffered_time<d)for(this.buffered_time=d,d=.2-c,b=0;b<=d;)b+=c,this.buffered_time+=c,setTimeout(()=>this.pump(),1E3*b);a.start(this.buffered_time);this.buffered_time+=c;setTimeout(()=>this.pump(),0)};kb.prototype.pump=function(){this.enabled&&(.2<this.buffered_time-this.audio_context.currentTime||this.bus.send("dac-request-data"))};function ob(a,b,c){this.bus=b;this.socket=void 0;this.id=c||0;this.send_queue=[];this.url=a;this.reconnect_interval=1E4;this.last_connect_attempt=Date.now()-this.reconnect_interval;this.send_queue_limit=64;this.destroyed=!1;this.bus.register("net"+this.id+"-send",function(d){this.send(d)},this)}ob.prototype.handle_message=function(a){this.bus&&this.bus.send("net"+this.id+"-receive",new Uint8Array(a.data))};
ob.prototype.handle_close=function(){this.destroyed||(this.connect(),setTimeout(this.connect.bind(this),this.reconnect_interval))};ob.prototype.handle_open=function(){for(var a=0;a<this.send_queue.length;a++)this.send(this.send_queue[a]);this.send_queue=[]};ob.prototype.handle_error=function(){};ob.prototype.destroy=function(){this.destroyed=!0;this.socket&&this.socket.close()};
ob.prototype.connect=function(){if("undefined"!==typeof WebSocket){if(this.socket){var a=this.socket.readyState;if(0===a||1===a)return}a=Date.now();if(!(this.last_connect_attempt+this.reconnect_interval>a)){this.last_connect_attempt=Date.now();try{this.socket=new WebSocket(this.url)}catch(b){console.error(b);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(d<c){for(;d<c;)d*=2;if(this.maximum_capacity&&d>this.maximum_capacity)throw Error("stream capacity overflow in GrowableRingbuffer.write(), package dropped");c=new Uint8Array(d);this.peek(c);this.tail=0;this.head=this.length;this.buffer=c}c=this.buffer;const e=this.head+b;if(e>d){const f=
d-this.head;c.set(a.subarray(0,f),this.head);c.set(a.subarray(f))}else c.set(a,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<c.dns.questions.length;++e)switch(l=c.dns.questions[e],l.type){case 1:d.push({name:l.name,type:l.type,class:l.class,ttl:600,data:[192,168,87,1]})}a.dns={id:c.dns.id,flags:33152,questions:c.dns.questions,answers:d};b.receive(Eb(b.eth_encoder_buf,a))}else Fb(c,b);else c.dhcp?Gb(c,b):c.ntp?(a=Date.now()+rb,d=a%1E3/1E3*wb,e={},e.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},
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<c.dns.questions.length;++e)switch(l=c.dns.questions[e],l.type){case 1:d.push({name:l.name,type:l.type,class:l.class,ttl:600,data:[192,168,87,1]})}a.dns={id:c.dns.id,flags:33152,questions:c.dns.questions,answers:d};b.receive(Eb(b.eth_encoder_buf,a))}else Fb(c,b);else c.dhcp?Gb(c,b):c.ntp?(a=Date.now()+rb,d=a%1E3/1E3*sb,e={},e.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},
e.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},e.udp={sport:123,dport:c.udp.sport},e.ntp=Object.assign({},c.ntp),e.ntp.flags=36,e.ntp.poll=10,e.ntp.ori_ts_i=c.ntp.trans_ts_i,e.ntp.ori_ts_f=c.ntp.trans_ts_f,e.ntp.rec_ts_i=a/1E3,e.ntp.rec_ts_f=d,e.ntp.trans_ts_i=a/1E3,e.ntp.trans_ts_f=d,e.ntp.stratum=2,b.receive(Eb(b.eth_encoder_buf,e))):8===c.udp.dport&&(a={},a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},a.ipv4={proto:17,src:c.ipv4.dest,dest:c.ipv4.src},a.udp={sport:c.udp.dport,dport:c.udp.sport,
data:(new TextEncoder).encode(c.udp.data_s)},b.receive(Eb(b.eth_encoder_buf,a)));else c.icmp&&8===c.icmp.type&&(a={},a.eth={ethertype:2048,src:b.router_mac,dest:c.eth.src},a.ipv4={proto:1,src:c.ipv4.dest,dest:c.ipv4.src},a.icmp={type:0,code:c.icmp.code,data:c.icmp.data},b.receive(Eb(b.eth_encoder_buf,a)));else c.arp&&1===c.arp.oper&&2048===c.arp.ptype&&(a=zb(c.arp.tpa)&4294967040,d=zb(b.router_ip)&4294967040,!b.masquerade&&a!==d||a===d&&99<c.arp.tpa[3]||(a={},a.eth={ethertype:2054,src:b.router_mac,
dest:c.eth.src},a.arp={htype:1,ptype:2048,oper:2,sha:b.router_mac,spa:c.arp.tpa,tha:c.eth.src,tpa:c.arp.spa},b.receive(Eb(b.eth_encoder_buf,a))))}
function Ib(a,b){function c(){let m=[],n;do n=d.getUint8(h),m.push((new TextDecoder).decode(a.subarray(h+1,h+1+n))),h+=n+1;while(0<n);return m}let d=new DataView(a.buffer,a.byteOffset,a.byteLength),e={id:d.getUint16(0),flags:d.getUint16(2),questions:[],answers:[]};var f=d.getUint16(4);let g=d.getUint16(6);d.getUint16(8);d.getUint16(10);let h=12;for(var l=0;l<f;l++)e.questions.push({name:c(),type:d.getInt16(h),class:d.getInt16(h+2)}),h+=4;for(f=0;f<g;f++){l={name:c(),type:d.getInt16(h),class:d.getUint16(h+
2),ttl:d.getUint32(h+4)};h+=8;let m=d.getUint16(h);h+=2;l.data=a.subarray(h,h+m);h+=m;e.answers.push(l)}b.dns=e}
function Tb(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=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;h<b.length;++h){const l=this.net.parse_http_header(b[h]);
if(!l){console.warn('The request contains an invalid header: "%s"',b[h]);this.net.respond_text_and_close(this,400,"Bad Request",`Invalid header in request: ${b[h]}`);return}"host"===l.key.toLowerCase()?d.host=l.value:e.append(l.key,l.value)}if(!this.net.cors_proxy&&/^\d+\.external$/.test(d.hostname))if(b=parseInt(d.hostname.split(".")[0],10),!isNaN(b)&&0<b&&65536>b)d.protocol="http:",d.hostname="localhost",d.port=b.toString(10);else{console.warn('Unknown port for localhost: "%s"',d.href);this.net.respond_text_and_close(this,
400,"Bad Request",`Unknown port for localhost: ${d.href}`);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<a.length;g++)switch(e=b[g],a[g]){case "w":c[d++]=e&255;c[d++]=e>>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(0<b.size);return{name:c,type:b,size:b.size,get:b.get,set:b.set}})}
function Oc(a,b){const c={};let d=0;for(const e of b)b=e.get.call(a,d,!0),console.assert(void 0===c[e.name]),c[e.name]=b,d+=e.size;return[c,d]}function Pc(a,b,c){const d=[];let e=0;for(var f=0;f<c;f++){const [g,h]=Oc(new DataView(a.buffer,a.byteOffset+e,void 0),b);d.push(g);e+=h}return[d,e]};const Qc={[0]:0,[1]:525,[2]:525,[3]:350,[4]:350,[5]:350};
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)}};function Hc(a,b){this.cpu=a;this.bus=b;this.absolute=this.enabled=!1;this.queue=[];this.buttons=0;this.last_y=this.last_x=-1;this.tail_is_move=!1;this.bus.register("mouse-absolute",function(c){const d=Math.max(0,Math.min(65535,Math.round(c[0]/c[2]*65535)));c=Math.max(0,Math.min(65535,Math.round(c[1]/c[3]*65535)));if(d!==this.last_x||c!==this.last_y)this.last_x=d,this.last_y=c,this.push_packet(0,!0)},this);this.bus.register("mouse-click",function(c){this.buttons=(c[0]?32:0)|(c[1]?8:0)|(c[2]?16:0);
this.push_packet(0,!1)},this);this.bus.register("mouse-wheel",function(c){this.push_packet(-c[0]|0,!1)},this);a.io.register_read(22104,this,void 0,void 0,this.port_read32);a.io.register_write(22104,this,void 0,void 0,this.port_write32)}
Hc.prototype.push_packet=function(a,b){!this.enabled||!this.absolute||0>this.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<this.queue.length+4?(this.enabled=!1,this.queue.length=0):(this.queue.push(this.buttons,this.last_x,this.last_y,a),this.tail_is_move=b))};
Hc.prototype.port_read32=function(){const a=this.cpu.reg32;if(1447909480!==(a[0]|0))return-1;switch(a[1]&65535){case 10:return a[3]=1447909480,6;case 40:return this.enabled?this.queue.length:-65536;case 39:const b=Math.min(a[3]>>>0,4,this.queue.length),c=[0,0,0,0];for(let d=0;d<b;d++)c[d]=this.queue.shift();a[3]=c[1];a[1]=c[2];a[2]=c[3];return c[0];case 41:switch(a[3]|0){case 1161905490:this.enabled=!0;this.queue.length=0;this.tail_is_move=!1;this.queue.push(876762442);break;case 245:this.absolute=
this.enabled=!1;this.queue.length=0;this.bus.send("vmware-absolute-mouse",!1);break;case 1396851026:this.absolute=!0;this.bus.send("vmware-absolute-mouse",!0);break;case 1279611474:this.absolute=!1,this.bus.send("vmware-absolute-mouse",!1)}return 0}return-1};Hc.prototype.port_write32=function(){};Hc.prototype.get_state=function(){return[this.enabled,this.absolute]};Hc.prototype.set_state=function(a){this.enabled=a[0];this.absolute=a[1];this.bus.send("vmware-absolute-mouse",this.absolute)};const Ic=DataView.prototype,Jc={size:1,get:Ic.getUint8,set:Ic.setUint8},Kc={size:2,get:Ic.getUint16,set:Ic.setUint16},U={size:4,get:Ic.getUint32,set:Ic.setUint32},Mc=Lc([{magic:U},{class:Jc},{data:Jc},{version0:Jc},{osabi:Jc},{abiversion:Jc},{pad0:function(a){return{size:a,get:()=>-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<b.size);return{name:c,type:b,size:b.size,get:b.get,set:b.set}})}
function Pc(a,b){const c={};let d=0;for(const e of b)b=e.get.call(a,d,!0),console.assert(void 0===c[e.name]),c[e.name]=b,d+=e.size;return[c,d]}function Qc(a,b,c){const d=[];let e=0;for(var f=0;f<c;f++){const [g,h]=Pc(new DataView(a.buffer,a.byteOffset+e,void 0),b);d.push(g);e+=h}return[d,e]};const Rc={[0]:0,[1]:525,[2]:525,[3]:350,[4]:350,[5]:350};
function V(a,b,c,d){this.io=a.io;this.cpu=a;this.dma=a.devices.dma;this.cmd_table=this.build_cmd_lookup_table();this.sra=0;this.srb=192;this.dor=12;this.tdr=0;this.msr=128;this.dsr=0;this.cmd_phase=1;this.cmd_flags=this.cmd_code=0;this.cmd_buffer=new Uint8Array(17);this.cmd_remaining=this.cmd_cursor=0;this.response_data=new Uint8Array(15);this.reset_sense_int_count=this.curr_drive_no=this.status1=this.status0=this.response_length=this.response_cursor=0;this.locked=!1;this.head_load_time=this.step_rate_interval=
0;this.fdc_config=96;this.eot=this.precomp_trk=0;this.drives=[new Rc("fda",d?.fda,b,4),new Rc("fdb",d?.fdb,c,4)];Object.seal(this);this.cpu.devices.rtc.cmos_write(16,this.drives[0].drive_type<<4|this.drives[1].drive_type);this.io.register_read(1008,this,this.read_reg_sra);this.io.register_read(1009,this,this.read_reg_srb);this.io.register_read(1010,this,this.read_reg_dor);this.io.register_read(1011,this,this.read_reg_tdr);this.io.register_read(1012,this,this.read_reg_msr);this.io.register_read(1013,
0;this.fdc_config=96;this.eot=this.precomp_trk=0;this.drives=[new Sc("fda",d?.fda,b,4),new Sc("fdb",d?.fdb,c,4)];Object.seal(this);this.cpu.devices.rtc.cmos_write(16,this.drives[0].drive_type<<4|this.drives[1].drive_type);this.io.register_read(1008,this,this.read_reg_sra);this.io.register_read(1009,this,this.read_reg_srb);this.io.register_read(1010,this,this.read_reg_dor);this.io.register_read(1011,this,this.read_reg_tdr);this.io.register_read(1012,this,this.read_reg_msr);this.io.register_read(1013,
this,this.read_reg_fifo);this.io.register_read(1015,this,this.read_reg_dir);this.io.register_write(1010,this,this.write_reg_dor);this.io.register_write(1011,this,this.write_reg_tdr);this.io.register_write(1012,this,this.write_reg_dsr);this.io.register_write(1013,this,this.write_reg_fifo);this.io.register_write(1015,this,this.write_reg_ccr)}
V.prototype.build_cmd_lookup_table=function(){const a=[{code:6,mask:31,argc:8,name:"READ",handler:this.exec_read},{code:5,mask:63,argc:8,name:"WRITE",handler:this.exec_write},{code:15,mask:255,argc:2,name:"SEEK",handler:this.exec_seek},{code:8,mask:255,argc:0,name:"SENSE INTERRUPT STATUS",handler:this.exec_sense_interrupt_status},{code:7,mask:255,argc:1,name:"RECALIBRATE",handler:this.exec_recalibrate},{code:13,mask:191,argc:5,name:"FORMAT TRACK",handler:this.exec_format_track},{code:2,mask:191,argc:8,
name:"READ TRACK",handler:this.exec_unimplemented},{code:78,mask:255,argc:17,name:"RESTORE",handler:this.exec_unimplemented},{code:46,mask:255,argc:0,name:"SAVE",handler:this.exec_unimplemented},{code:12,mask:31,argc:8,name:"READ DELETED DATA",handler:this.exec_unimplemented},{code:17,mask:31,argc:8,name:"SCAN EQUAL",handler:this.exec_unimplemented},{code:22,mask:31,argc:8,name:"VERIFY",handler:this.exec_unimplemented},{code:25,mask:31,argc:8,name:"SCAN LOW OR EQUAL",handler:this.exec_unimplemented},
@@ -459,32 +463,32 @@ V.prototype.get_state=function(){const a=[];a[19]=this.sra;a[20]=this.srb;a[21]=
a[41]=this.fdc_config;a[42]=this.precomp_trk;a[43]=this.eot;a[44]=this.drives[0].get_state();a[45]=this.drives[1].get_state();return a};
V.prototype.set_state=function(a){"undefined"!==typeof a[19]&&(this.sra=a[19],this.srb=a[20],this.dor=a[21],this.tdr=a[22],this.msr=a[23],this.dsr=a[24],this.cmd_phase=a[25],this.cmd_code=a[26],this.cmd_flags=a[27],this.cmd_buffer.set(a[28]),this.cmd_cursor=a[29],this.cmd_remaining=a[30],this.response_data.set(a[31]),this.response_cursor=a[32],this.response_length=a[33],this.status0=a[34],this.status1=a[35],this.curr_drive_no=a[36],this.reset_sense_int_count=a[37],this.locked=a[38],this.step_rate_interval=
a[39],this.head_load_time=a[40],this.fdc_config=a[41],this.precomp_trk=a[42],this.eot=a[43],this.drives[0].set_state(a[44]),this.drives[1].set_state(a[45]))};
const Sc=[{drive_type:4,sectors:18,tracks:80,heads:2},{drive_type:4,sectors:20,tracks:80,heads:2},{drive_type:4,sectors:21,tracks:80,heads:2},{drive_type:4,sectors:21,tracks:82,heads:2},{drive_type:4,sectors:21,tracks:83,heads:2},{drive_type:4,sectors:22,tracks:80,heads:2},{drive_type:4,sectors:23,tracks:80,heads:2},{drive_type:4,sectors:24,tracks:80,heads:2},{drive_type:5,sectors:36,tracks:80,heads:2},{drive_type:5,sectors:39,tracks:80,heads:2},{drive_type:5,sectors:40,tracks:80,heads:2},{drive_type:5,
const Tc=[{drive_type:4,sectors:18,tracks:80,heads:2},{drive_type:4,sectors:20,tracks:80,heads:2},{drive_type:4,sectors:21,tracks:80,heads:2},{drive_type:4,sectors:21,tracks:82,heads:2},{drive_type:4,sectors:21,tracks:83,heads:2},{drive_type:4,sectors:22,tracks:80,heads:2},{drive_type:4,sectors:23,tracks:80,heads:2},{drive_type:4,sectors:24,tracks:80,heads:2},{drive_type:5,sectors:36,tracks:80,heads:2},{drive_type:5,sectors:39,tracks:80,heads:2},{drive_type:5,sectors:40,tracks:80,heads:2},{drive_type:5,
sectors:44,tracks:80,heads:2},{drive_type:5,sectors:48,tracks:80,heads:2},{drive_type:4,sectors:8,tracks:80,heads:2},{drive_type:4,sectors:9,tracks:80,heads:2},{drive_type:4,sectors:10,tracks:80,heads:2},{drive_type:4,sectors:10,tracks:82,heads:2},{drive_type:4,sectors:10,tracks:83,heads:2},{drive_type:4,sectors:13,tracks:80,heads:2},{drive_type:4,sectors:14,tracks:80,heads:2},{drive_type:2,sectors:15,tracks:80,heads:2},{drive_type:2,sectors:18,tracks:80,heads:2},{drive_type:2,sectors:18,tracks:82,
heads:2},{drive_type:2,sectors:18,tracks:83,heads:2},{drive_type:2,sectors:20,tracks:80,heads:2},{drive_type:2,sectors:9,tracks:80,heads:2},{drive_type:2,sectors:11,tracks:80,heads:2},{drive_type:2,sectors:9,tracks:40,heads:2},{drive_type:2,sectors:9,tracks:40,heads:1},{drive_type:2,sectors:10,tracks:41,heads:2},{drive_type:2,sectors:10,tracks:42,heads:2},{drive_type:2,sectors:8,tracks:40,heads:2},{drive_type:2,sectors:8,tracks:40,heads:1},{drive_type:4,sectors:9,tracks:80,heads:1},{drive_type:1,
sectors:10,tracks:40,heads:1},{drive_type:1,sectors:10,tracks:40,heads:2}];function Rc(a,b,c,d){this.name=a;this.curr_head=this.curr_track=this.max_sect=this.max_head=this.max_track=this.drive_type=0;this.curr_sect=1;this.perpendicular=0;this.read_only=!1;this.media_changed=!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)}
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;m<Sc.length;m++){const n=Sc[m],p=n.sectors*n.tracks*n.heads*512;if(d===p)if(c||n.drive_type===b){e=m;break}else c||Qc[n.drive_type]!==Qc[b]?g=-1===g?m:g:f=-1===f?m:f;else d<p&&(-1===l||p<l)&&(h=m,l=p)}return-1!==e?[a,Sc[e]]:-1!==f?[a,Sc[f]]:-1!==g?[a,Sc[g]]:-1!==h?(b=new Uint8Array(l),b.set(new Uint8Array(a.buffer)),[new z(b.buffer),Sc[h]]):[null,null]};
Rc.prototype.seek=function(a,b,c){if(b>this.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;m<Tc.length;m++){const n=Tc[m],p=n.sectors*n.tracks*n.heads*512;if(d===p)if(c||n.drive_type===b){e=m;break}else c||Rc[n.drive_type]!==Rc[b]?g=-1===g?m:g:f=-1===f?m:f;else d<p&&(-1===l||p<l)&&(h=m,l=p)}return-1!==e?[a,Tc[e]]:-1!==f?[a,Tc[f]]:-1!==g?[a,Tc[g]]:-1!==h?(b=new Uint8Array(l),b.set(new Uint8Array(a.buffer)),[new z(b.buffer),Tc[h]]):[null,null]};
Sc.prototype.seek=function(a,b,c){if(b>this.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<this.pairs;++c)b.push({size_supported:1024,notify_offset:0}),b.push({size_supported:1024,notify_offset:1});b.push({size_supported:16,notify_offset:2});this.virtio=new Fc(a,{name:"virtio-net",pci_id:80,device_id:4161,subsystem_device_id:1,
this.current_command=a[25];this.data_end=a[26];this.current_atapi_command=a[27];this.data16=new Uint16Array(this.data.buffer);this.data32=new Int32Array(this.data.buffer);this.buffer&&this.buffer.set_state(a[28]);this.drive_connected=this.is_atapi||this.buffer;this.medium_changed=!1};function Xc(a,b,c,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<this.pairs;++c)b.push({size_supported:1024,notify_offset:0}),b.push({size_supported:1024,notify_offset:1});b.push({size_supported:16,notify_offset:2});this.virtio=new Fc(a,{name:"virtio-net",pci_id:80,device_id:4161,subsystem_device_id:1,
common:{initial_port:51200,queues:b,features:[5,16,22,3,17,23,32],on_driver_ok:()=>{}},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<this.vga_memory_size?268435456:ia(this.vga_memory_size);this.pci_space=
[52,18,17,17,3,1,0,0,0,0,0,3,0,0,0,0,8,14680064,57344,224,0,0,0,0,0,0,191,254,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,244,26,0,17,0,0,190,254,0,0,0,0,0,0,0,0,0,0,0,0];this.pci_id=144;this.pci_bars=[{size:this.vga_memory_size}];this.pci_rom_size=65536;this.pci_rom_address=4272947200;this.name="vga";this.dac_state=this.dac_color_index_read=this.dac_color_index_write=this.index_crtc=0;this.dac_mask=255;this.dac_map=new Uint8Array(16);this.attribute_controller_index=-1;this.palette_source=32;this.color_select=
@@ -559,9 +563,9 @@ a[18];this.svga_bpp=a[19];this.svga_bank_offset=a[20];this.svga_offset=a[21];thi
a[37];this.dispi_enable_value=a[38];this.svga_memory.set(a[39]);this.attribute_controller_index=a[41];this.offset_register=a[42];this.planar_setreset=a[43];this.planar_setreset_enable=a[44];this.start_address_latched=a[45];this.crtc.set(a[46]);this.horizontal_display_enable_end=a[47];this.horizontal_blank_start=a[48];this.vertical_display_enable_end=a[49];this.vertical_blank_start=a[50];this.underline_location_register=a[51];this.preset_row_scan=a[52];this.offset_register=a[53];this.palette_source=
a[54];this.attribute_mode=a[55];this.color_plane_enable=a[56];this.horizontal_panning=a[57];this.color_select=a[58];this.clocking_mode=a[59];this.line_compare=a[60];a[61]&&this.pixel_buffer.set(a[61]);this.dac_mask=void 0===a[62]?255:a[62];this.character_map_select=void 0===a[63]?0:a[63];this.font_page_ab_enabled=void 0===a[64]?0:a[64];this.screen.set_mode(this.graphical_mode);this.graphical_mode?(this.screen_height=this.screen_width=0,this.svga_enabled?(this.set_size_graphical(this.svga_width,this.svga_height,
this.svga_width,this.svga_height,this.svga_bpp),this.update_layers()):(this.update_vga_size(),this.update_layers(),this.complete_replot())):(this.set_font_bitmap(!0),this.set_size_text(this.max_cols,this.max_rows),this.set_font_page(),this.update_cursor_scanline(),this.update_cursor());this.complete_redraw()};
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-=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<this.screen_width;e+=this.virtual_width,g++)this.layers.push({image_data:this.image_data,screen_x:e,screen_y:0,buffer_x:0,buffer_y:a+g,buffer_width:this.virtual_width,buffer_height:d});a=0;this.attribute_mode&32||(a=this.vga_addr_to_pixel(c)+b);e=-a;for(g=0;e<this.screen_width;e+=this.virtual_width,g++)this.layers.push({image_data:this.image_data,screen_x:e,screen_y:d,buffer_x:0,buffer_y:g,buffer_width:this.virtual_width,
@@ -618,13 +622,13 @@ X.prototype.screen_fill_buffer=function(){if(this.graphical_mode){if(0===this.im
f=new Uint8Array(this.cpu.wasm_memory.buffer,this.svga_memory.byteOffset,this.vga_memory_size);for(var b=0;b<e.length;b++){var c=this.vga256_palette[f[b]];e[b]=c&65280|c<<16|c>>16|4278190080}}else this.cpu.svga_fill_pixel_buffer(this.svga_bpp,this.svga_offset),b=15===this.svga_bpp?2:this.svga_bpp/8,a=((this.cpu.svga_dirty_bitmap_min_offset[0]/b|0)-this.svga_offset)/this.svga_width|0,d=(((this.cpu.svga_dirty_bitmap_max_offset[0]/b|0)-this.svga_offset)/this.svga_width|0)+1;a<d&&(a=Math.max(a,0),d=Math.min(d,
this.svga_height),this.screen.update_buffer([{image_data:this.image_data,screen_x:0,screen_y:a,buffer_x:0,buffer_y:a,buffer_width:this.svga_width,buffer_height:d-a}]))}else this.vga_replot(),this.vga_redraw(),this.screen.update_buffer(this.layers);this.reset_diffs()}this.update_vertical_retrace()};
X.prototype.set_font_bitmap=function(a){const b=this.max_scan_line&31;if(b&&!this.graphical_mode){const c=!!(this.clocking_mode&8);this.screen.set_font_bitmap(b+1,!c&&!(this.clocking_mode&1),c,!!(this.attribute_mode&4),this.plane2,a)}};
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 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<d.length_readable;g+=10){let [h,l]=I(["h","d"],e,{offset:g});f[Zc[h]]=l}this.virtio.queues[c].push_reply(d);this.stats_cb&&this.stats_cb(f)}},c=>{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<d.length_readable;g+=10){let [h,l]=I(["h","d"],e,{offset:g});f[$c[h]]=l}this.virtio.queues[c].push_reply(d);this.stats_cb&&this.stats_cb(f)}},c=>{const d=
this.virtio.queues[c];for(;d.has_request();){const f=d.pop_request();if(0<f.length_readable){var e=new Uint8Array(f.length_readable);f.get_next_blob(e);[e]=I(["w"],e,{offset:0});0===e&&(this.free_cb&&this.free_cb(this.zeroed),1<this.fp_cmd&&(this.fp_cmd=1),this.virtio.notify_config_changes())}if(0<f.length_writable)for(new Uint8Array(0),e=0;e<f.write_buffers.length;++e){let g=f.write_buffers[e];this.zeroed+=g.len;this.virtio.cpu.zero_memory(g.addr_low,g.len)}this.virtio.queues[c].push_reply(f)}this.virtio.queues[c].flush_replies()}]},
isr_status:{initial_port:55040},device_specific:{initial_port:54784,struct:[{bytes:4,name:"num_pages",read:()=>this.num_pages,write:()=>{}},{bytes:4,name:"actual",read:()=>this.actual,write:()=>{}},{bytes:4,name:"free_page_hint_cmd_id",read:()=>this.fp_cmd,write:()=>{}}]}})}$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;e<d.length;e++)a[581632+
isr_status:{initial_port:55040},device_specific:{initial_port:54784,struct:[{bytes:4,name:"num_pages",read:()=>this.num_pages,write:()=>{}},{bytes:4,name:"actual",read:()=>this.actual,write:()=>{}},{bytes:4,name:"free_page_hint_cmd_id",read:()=>this.fp_cmd,write:()=>{}}]}})}ad.prototype.Inflate=function(a){this.num_pages+=a;this.virtio.notify_config_changes()};ad.prototype.Deflate=function(a){this.num_pages-=a;this.virtio.notify_config_changes()};
ad.prototype.Cleanup=function(a){this.fp_cmd=2;this.free_cb=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<d.length;e++)a[581632+
e]=d.charCodeAt(e);h=512*(h+1);y(h);d=new Uint8Array(b,0,h);b=new Uint8Array(b,h);e=h=0;c&&(h=67108864,e=c.byteLength,a.set(new Uint8Array(c),h));g[134]=h;g[135]=e;a.set(d,524288);a.set(b,1048576);a=new Uint8Array(512);(new Uint16Array(a.buffer))[0]=43605;a[2]=1;c=3;a[c++]=250;a[c++]=184;a[c++]=32768;a[c++]=128;a[c++]=142;a[c++]=192;a[c++]=142;a[c++]=216;a[c++]=142;a[c++]=224;a[c++]=142;a[c++]=232;a[c++]=142;a[c++]=208;a[c++]=188;a[c++]=57344;a[c++]=224;a[c++]=234;a[c++]=0;a[c++]=0;a[c++]=32800;a[c++]=
128;g=a[c]=0;for(b=0;b<a.length;b++)g+=a[b];a[c]=-g;return{name:"genroms/kernel.bin",data:a}}};function O(a,b,c){this.stop_idling=c;this.wm=b;this.wasm_patch();this.create_jit_imports();this.wasm_memory=b=this.wm.exports.memory;this.memory_size=k(Uint32Array,b,812,1);this.mem8=new Uint8Array(0);this.mem32s=new Int32Array(this.mem8.buffer);this.segment_is_null=k(Uint8Array,b,724,8);this.segment_offsets=k(Int32Array,b,736,8);this.segment_limits=k(Uint32Array,b,768,8);this.segment_access_bytes=k(Uint8Array,b,512,8);this.protected_mode=k(Int32Array,b,800,1);this.idtr_size=k(Int32Array,b,564,1);
this.idtr_offset=k(Int32Array,b,568,1);this.gdtr_size=k(Int32Array,b,572,1);this.gdtr_offset=k(Int32Array,b,576,1);this.tss_size_32=k(Int32Array,b,1128,1);this.page_fault=k(Uint32Array,b,540,8);this.cr=k(Int32Array,b,580,8);this.cpl=k(Uint8Array,b,612,1);this.is_32=k(Int32Array,b,804,1);this.stack_size_32=k(Int32Array,b,808,1);this.in_hlt=k(Uint8Array,b,616,1);this.last_virt_eip=k(Int32Array,b,620,1);this.eip_phys=k(Int32Array,b,624,1);this.sysenter_cs=k(Int32Array,b,636,1);this.sysenter_esp=k(Int32Array,
@@ -643,16 +647,16 @@ O.prototype.jit_force_generate=function(a){this.jit_force_generate_unsafe&&this.
O.prototype.get_state=function(){var a=[];a[0]=this.memory_size[0];a[1]=new Uint8Array([...this.segment_is_null,...this.segment_access_bytes]);a[2]=this.segment_offsets;a[3]=this.segment_limits;a[4]=this.protected_mode[0];a[5]=this.idtr_offset[0];a[6]=this.idtr_size[0];a[7]=this.gdtr_offset[0];a[8]=this.gdtr_size[0];a[9]=this.page_fault[0];a[10]=this.cr;a[11]=this.cpl[0];a[13]=this.is_32[0];a[16]=this.stack_size_32[0];a[17]=this.in_hlt[0];a[18]=this.last_virt_eip[0];a[19]=this.eip_phys[0];a[22]=this.sysenter_cs[0];
a[23]=this.sysenter_eip[0];a[24]=this.sysenter_esp[0];a[25]=this.prefixes[0];a[26]=this.flags[0];a[27]=this.flags_changed[0];a[28]=this.last_op1[0];a[30]=this.last_op_size[0];a[37]=this.instruction_pointer[0];a[38]=this.previous_ip[0];a[39]=this.reg32;a[40]=this.sreg;a[41]=this.dreg;a[42]=this.reg_pdpte;this.store_current_tsc();a[43]=this.current_tsc;a[45]=this.devices.virtio_9p;a[46]=this.get_state_apic();a[47]=this.devices.rtc;a[48]=this.devices.pci;a[49]=this.devices.dma;a[50]=this.devices.acpi;
a[52]=this.devices.vga;a[53]=this.devices.ps2;a[54]=this.devices.uart0;a[55]=this.devices.fdc;this.devices.ide.secondary?a[85]=this.devices.ide:this.devices.ide.primary?.master.is_atapi?a[56]=this.devices.ide.primary:a[57]=this.devices.ide.primary;a[58]=this.devices.pit;a[59]=this.devices.net;a[60]=this.get_state_pic();a[61]=this.devices.sb16;a[62]=this.fw_value;a[63]=this.get_state_ioapic();a[64]=this.tss_size_32[0];a[66]=this.reg_xmm32s;a[67]=this.fpu_st;a[68]=this.fpu_stack_empty[0];a[69]=this.fpu_stack_ptr[0];
a[70]=this.fpu_control_word[0];a[71]=this.fpu_ip[0];a[72]=this.fpu_ip_selector[0];a[73]=this.fpu_dp[0];a[74]=this.fpu_dp_selector[0];a[75]=this.fpu_opcode[0];const {packed_memory:b,bitmap:c}=this.pack_memory();a[77]=b;a[78]=new Uint8Array(c.get_buffer());a[79]=this.devices.uart1;a[80]=this.devices.uart2;a[81]=this.devices.uart3;a[82]=this.devices.virtio_console;a[83]=this.devices.virtio_net;a[84]=this.devices.virtio_balloon;a[86]=this.last_result;a[87]=this.fpu_status_word;a[88]=this.mxcsr;return a};
O.prototype.get_state_pic=function(){const a=new Uint8Array(this.wasm_memory.buffer,this.get_pic_addr_master(),13),b=new Uint8Array(this.wasm_memory.buffer,this.get_pic_addr_slave(),13),c=[],d=[];c[0]=a[0];c[1]=a[1];c[2]=a[2];c[3]=a[3];c[4]=a[4];c[5]=d;c[6]=a[6];c[7]=a[7];c[8]=a[8];c[9]=a[9];c[10]=a[10];c[11]=a[11];c[12]=a[12];d[0]=b[0];d[1]=b[1];d[2]=b[2];d[3]=b[3];d[4]=b[4];d[5]=null;d[6]=b[6];d[7]=b[7];d[8]=b[8];d[9]=b[9];d[10]=b[10];d[11]=b[11];d[12]=b[12];return c};
a[70]=this.fpu_control_word[0];a[71]=this.fpu_ip[0];a[72]=this.fpu_ip_selector[0];a[73]=this.fpu_dp[0];a[74]=this.fpu_dp_selector[0];a[75]=this.fpu_opcode[0];const {packed_memory:b,bitmap:c}=this.pack_memory();a[77]=b;a[78]=new Uint8Array(c.get_buffer());a[79]=this.devices.uart1;a[80]=this.devices.uart2;a[81]=this.devices.uart3;a[82]=this.devices.virtio_console;a[83]=this.devices.virtio_net;a[84]=this.devices.virtio_balloon;a[86]=this.last_result;a[87]=this.fpu_status_word;a[88]=this.mxcsr;a[89]=
this.devices.vmware;return a};O.prototype.get_state_pic=function(){const a=new Uint8Array(this.wasm_memory.buffer,this.get_pic_addr_master(),13),b=new Uint8Array(this.wasm_memory.buffer,this.get_pic_addr_slave(),13),c=[],d=[];c[0]=a[0];c[1]=a[1];c[2]=a[2];c[3]=a[3];c[4]=a[4];c[5]=d;c[6]=a[6];c[7]=a[7];c[8]=a[8];c[9]=a[9];c[10]=a[10];c[11]=a[11];c[12]=a[12];d[0]=b[0];d[1]=b[1];d[2]=b[2];d[3]=b[3];d[4]=b[4];d[5]=null;d[6]=b[6];d[7]=b[7];d[8]=b[8];d[9]=b[9];d[10]=b[10];d[11]=b[11];d[12]=b[12];return c};
O.prototype.get_state_apic=function(){return new Uint8Array(this.wasm_memory.buffer,this.get_apic_addr(),184)};O.prototype.get_state_ioapic=function(){return new Uint8Array(this.wasm_memory.buffer,this.get_ioapic_addr(),208)};
O.prototype.set_state=function(a){this.memory_size[0]=a[0];this.mem8.length!==this.memory_size[0]&&console.warn("Note: Memory size mismatch. we="+this.mem8.length+" state="+this.memory_size[0]);8===a[1].length?(this.segment_is_null.set(a[1]),this.segment_access_bytes.fill(242),this.segment_access_bytes[1]=250):16===a[1].length&&(this.segment_is_null.set(a[1].subarray(0,8)),this.segment_access_bytes.set(a[1].subarray(8,16)));this.segment_offsets.set(a[2]);this.segment_limits.set(a[3]);this.protected_mode[0]=
a[4];this.idtr_offset[0]=a[5];this.idtr_size[0]=a[6];this.gdtr_offset[0]=a[7];this.gdtr_size[0]=a[8];this.page_fault[0]=a[9];this.cr.set(a[10]);this.cpl[0]=a[11];this.is_32[0]=a[13];this.stack_size_32[0]=a[16];this.in_hlt[0]=a[17];this.last_virt_eip[0]=a[18];this.eip_phys[0]=a[19];this.sysenter_cs[0]=a[22];this.sysenter_eip[0]=a[23];this.sysenter_esp[0]=a[24];this.prefixes[0]=a[25];this.flags[0]=a[26];this.flags_changed[0]=a[27];this.last_op1[0]=a[28];this.last_op_size[0]=a[30];this.instruction_pointer[0]=
a[37];this.previous_ip[0]=a[38];this.reg32.set(a[39]);this.sreg.set(a[40]);this.dreg.set(a[41]);a[42]&&this.reg_pdpte.set(a[42]);this.set_tsc(a[43][0],a[43][1]);this.devices.virtio_9p&&this.devices.virtio_9p.set_state(a[45]);a[46]&&this.set_state_apic(a[46]);this.devices.rtc&&this.devices.rtc.set_state(a[47]);this.devices.dma&&this.devices.dma.set_state(a[49]);this.devices.acpi&&this.devices.acpi.set_state(a[50]);this.devices.vga&&this.devices.vga.set_state(a[52]);this.devices.ps2&&this.devices.ps2.set_state(a[53]);
this.devices.uart0&&this.devices.uart0.set_state(a[54]);this.devices.fdc&&this.devices.fdc.set_state(a[55]);if(a[56]||a[57]){var b=[[void 0,void 0],[void 0,void 0]];b[0][0]=a[56]?{is_cdrom:!0,buffer:this.devices.cdrom.buffer}:{is_cdrom:!1,buffer:this.devices.ide.primary.master.buffer};this.devices.ide=new Uc(this,this.devices.ide.bus,b);this.devices.cdrom=a[56]?this.devices.ide.primary.master:void 0;this.devices.ide.primary.set_state(a[56]||a[57])}else a[85]&&this.devices.ide.set_state(a[85]);this.devices.pci&&
this.devices.uart0&&this.devices.uart0.set_state(a[54]);this.devices.fdc&&this.devices.fdc.set_state(a[55]);if(a[56]||a[57]){var b=[[void 0,void 0],[void 0,void 0]];b[0][0]=a[56]?{is_cdrom:!0,buffer:this.devices.cdrom.buffer}:{is_cdrom:!1,buffer:this.devices.ide.primary.master.buffer};this.devices.ide=new Vc(this,this.devices.ide.bus,b);this.devices.cdrom=a[56]?this.devices.ide.primary.master:void 0;this.devices.ide.primary.set_state(a[56]||a[57])}else a[85]&&this.devices.ide.set_state(a[85]);this.devices.pci&&
this.devices.pci.set_state(a[48]);this.devices.pit&&this.devices.pit.set_state(a[58]);this.devices.net&&this.devices.net.set_state(a[59]);this.set_state_pic(a[60]);this.devices.sb16&&this.devices.sb16.set_state(a[61]);this.devices.uart1&&this.devices.uart1.set_state(a[79]);this.devices.uart2&&this.devices.uart2.set_state(a[80]);this.devices.uart3&&this.devices.uart3.set_state(a[81]);this.devices.virtio_console&&this.devices.virtio_console.set_state(a[82]);this.devices.virtio_net&&this.devices.virtio_net.set_state(a[83]);
this.devices.virtio_balloon&&this.devices.virtio_balloon.set_state(a[84]);this.fw_value=a[62];a[63]&&this.set_state_ioapic(a[63]);this.tss_size_32[0]=a[64];this.reg_xmm32s.set(a[66]);this.fpu_st.set(a[67]);this.fpu_stack_empty[0]=a[68];this.fpu_stack_ptr[0]=a[69];this.fpu_control_word[0]=a[70];this.fpu_ip[0]=a[71];this.fpu_ip_selector[0]=a[72];this.fpu_dp[0]=a[73];this.fpu_dp_selector[0]=a[74];this.fpu_opcode[0]=a[75];void 0!==a[86]&&(this.last_result=a[86]);void 0!==a[87]&&(this.fpu_status_word=
a[87]);void 0!==a[88]&&(this.mxcsr=a[88]);b=new ma(a[78].buffer);this.unpack_memory(b,a[77]);this.update_state_flags();this.full_clear_tlb();this.jit_clear_cache()};
this.devices.virtio_balloon&&this.devices.virtio_balloon.set_state(a[84]);this.devices.vmware&&a[89]&&this.devices.vmware.set_state(a[89]);this.fw_value=a[62];a[63]&&this.set_state_ioapic(a[63]);this.tss_size_32[0]=a[64];this.reg_xmm32s.set(a[66]);this.fpu_st.set(a[67]);this.fpu_stack_empty[0]=a[68];this.fpu_stack_ptr[0]=a[69];this.fpu_control_word[0]=a[70];this.fpu_ip[0]=a[71];this.fpu_ip_selector[0]=a[72];this.fpu_dp[0]=a[73];this.fpu_dp_selector[0]=a[74];this.fpu_opcode[0]=a[75];void 0!==a[86]&&
(this.last_result=a[86]);void 0!==a[87]&&(this.fpu_status_word=a[87]);void 0!==a[88]&&(this.mxcsr=a[88]);b=new ma(a[78].buffer);this.unpack_memory(b,a[77]);this.update_state_flags();this.full_clear_tlb();this.jit_clear_cache()};
O.prototype.set_state_pic=function(a){const b=new Uint8Array(this.wasm_memory.buffer,this.get_pic_addr_master(),13),c=new Uint8Array(this.wasm_memory.buffer,this.get_pic_addr_slave(),13);b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];const d=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];b[9]=a[9];b[10]=a[10];b[11]=a[11];b[12]=a[12];c[0]=d[0];c[1]=d[1];c[2]=d[2];c[3]=d[3];c[4]=d[4];c[6]=d[6];c[7]=d[7];c[8]=d[8];c[9]=d[9];c[10]=d[10];c[11]=d[11];c[12]=d[12]};
O.prototype.set_state_apic=function(a){if(a instanceof Array){const b=new Int32Array(this.wasm_memory.buffer,this.get_apic_addr(),46);b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];b[8]=a[6];b[9]=a[7];b[10]=a[8];b[11]=a[9];b[12]=a[10];b[13]=a[11];b[14]=a[12];b[15]=a[13];b.set(a[15],16);b.set(a[15],24);b.set(a[16],32);b[40]=a[17];b[41]=a[18];b[42]=a[19];b[43]=a[20];b[44]=a[21];b[45]=a[22]||65536}else(new Uint8Array(this.wasm_memory.buffer,this.get_apic_addr(),184)).set(a)};
O.prototype.set_state_ioapic=function(a){if(a instanceof Array){const b=new Int32Array(this.wasm_memory.buffer,this.get_ioapic_addr(),52);b.set(a[0],0);b.set(a[1],24);b[48]=a[2];b[49]=a[3];b[50]=a[4];b[51]=a[5]}else(new Uint8Array(this.wasm_memory.buffer,this.get_ioapic_addr(),208)).set(a)};
@@ -660,17 +664,17 @@ O.prototype.pack_memory=function(){var a=this.mem8.length>>12,b=[];for(var c=0;c
O.prototype.unpack_memory=function(a,b){this.zero_memory(0,this.memory_size[0]);const c=this.memory_size[0]>>12;let d=0;for(let f=0;f<c;f++)if(a.get(f)){var e=d<<12;e=b.subarray(e,e+4096);this.mem8.set(e,f<<12);d++}};
O.prototype.reboot_internal=function(){this.reset_cpu();this.fw_value=[];this.devices.virtio_9p&&this.devices.virtio_9p.reset();this.devices.virtio_console&&this.devices.virtio_console.reset();this.devices.virtio_net&&this.devices.virtio_net.reset();this.devices.ps2&&this.devices.ps2.reset();this.load_bios()};O.prototype.reset_memory=function(){this.mem8.fill(0)};
O.prototype.create_memory=function(a,b){a<b?a=b:0>(a|0)&&(a=Math.pow(2,31)-131072);a=(a-1|131071)+1|0;console.assert(0===this.memory_size[0],"Expected uninitialised memory");this.memory_size[0]=a;b=this.allocate_memory(a);this.mem8=k(Uint8Array,this.wasm_memory,b,a);this.mem32s=k(Uint32Array,this.wasm_memory,b,a>>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<this.fw_value.length?this.fw_value[this.fw_pointer++]:0});c.register_write(1296,this,void 0,function(e){function f(l){return new Uint8Array(Int32Array.of(l).buffer)}function g(l){return l>>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<this.option_roms.length;m++){const {name:n,data:p}=this.option_roms[m],q=4+64*m;e[q+0>>2]=h(p.length);e[q+4>>2]=g(49152+m);for(let r=0;r<n.length;r++)l[q+8+r]=n.charCodeAt(r)}this.fw_value=
l}else 32768<=e&&49152>e?this.fw_value=f(0):49152<=e&&e-49152<this.option_roms.length?this.fw_value=this.option_roms[e-49152].data:(ua("Warning: Unimplemented fw index: "+y(e)),this.fw_value=f(0))});this.devices={};a.load_devices&&(this.devices.pci=new Ac(this),this.acpi_enabled[0]&&(this.devices.acpi=new yc(this)),this.devices.rtc=new gb(this),this.fill_cmos(this.devices.rtc,a),this.devices.dma=new B(this),this.devices.vga=new X(this,b,a.screen,a.vga_memory_size||8388608),this.devices.ps2=new Gc(this,
b),this.devices.uart0=new zc(this,1016,b),a.uart1&&(this.devices.uart1=new zc(this,760,b)),a.uart2&&(this.devices.uart2=new zc(this,1E3,b)),a.uart3&&(this.devices.uart3=new zc(this,744,b)),this.devices.fdc=new V(this,a.fda,a.fdb),c=[[void 0,void 0],[void 0,void 0]],a.hda&&(c[0][0]={buffer:a.hda},c[0][1]={buffer:a.hdb}),c[1][0]={is_cdrom:!0,buffer:a.cdrom},this.devices.ide=new Uc(this,b,c),this.devices.cdrom=this.devices.ide.secondary.master,this.devices.pit=new hb(this,b),"ne2k"===a.net_device.type?
this.devices.net=new Dc(this,b,a.preserve_mac_from_state_image,a.mac_address_translation):"virtio"===a.net_device.type&&(this.devices.virtio_net=new Wc(this,b,a.preserve_mac_from_state_image,a.net_device.mtu)),a.fs9p?this.devices.virtio_9p=new bd(a.fs9p,this,b):a.handle9p?this.devices.virtio_9p=new cd(a.handle9p,this):a.proxy9p&&(this.devices.virtio_9p=new dd(a.proxy9p,this)),a.virtio_console&&(this.devices.virtio_console=new Ec(this,b)),a.virtio_balloon&&(this.devices.virtio_balloon=new $c(this,
b)),this.devices.sb16=new D(this,b));a.multiboot&&(a=this.load_multiboot_option_rom(a.multiboot,a.initrd,a.cmdline))&&(this.bios.main?this.option_roms.push(a):this.reg32[0]=this.io.port_read32(244));this.debug_init()};O.prototype.load_multiboot=function(a){this.load_multiboot_option_rom(a,void 0,"")&&(this.reg32[0]=this.io.port_read32(244))};
b),this.devices.vmware=new Hc(this,b),this.devices.uart0=new zc(this,1016,b),a.uart1&&(this.devices.uart1=new zc(this,760,b)),a.uart2&&(this.devices.uart2=new zc(this,1E3,b)),a.uart3&&(this.devices.uart3=new zc(this,744,b)),this.devices.fdc=new V(this,a.fda,a.fdb),c=[[void 0,void 0],[void 0,void 0]],a.hda&&(c[0][0]={buffer:a.hda},c[0][1]={buffer:a.hdb}),c[1][0]={is_cdrom:!0,buffer:a.cdrom},this.devices.ide=new Vc(this,b,c),this.devices.cdrom=this.devices.ide.secondary.master,this.devices.pit=new hb(this,
b),"ne2k"===a.net_device.type?this.devices.net=new Dc(this,b,a.preserve_mac_from_state_image,a.mac_address_translation):"virtio"===a.net_device.type&&(this.devices.virtio_net=new Xc(this,b,a.preserve_mac_from_state_image,a.net_device.mtu)),a.fs9p?this.devices.virtio_9p=new cd(a.fs9p,this,b):a.handle9p?this.devices.virtio_9p=new dd(a.handle9p,this):a.proxy9p&&(this.devices.virtio_9p=new ed(a.proxy9p,this)),a.virtio_console&&(this.devices.virtio_console=new Ec(this,b)),a.virtio_balloon&&(this.devices.virtio_balloon=
new ad(this,b)),this.devices.sb16=new D(this,b));a.multiboot&&(a=this.load_multiboot_option_rom(a.multiboot,a.initrd,a.cmdline))&&(this.bios.main?this.option_roms.push(a):this.reg32[0]=this.io.port_read32(244));this.debug_init()};O.prototype.load_multiboot=function(a){this.load_multiboot_option_rom(a,void 0,"")&&(this.reg32[0]=this.io.port_read32(244))};
O.prototype.load_multiboot_option_rom=function(a,b,c){if(8192>a.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.memsz<g.memory_size[0]?(t.filesz&&(n=new Uint8Array(a,t.offset,t.filesz),g.write_blob(n,t.paddr)),x=Math.max(x,t.paddr+t.memsz),r===
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]=Pc(C,Mc);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]=Qc(new DataView(C.buffer,C.byteOffset+A.phoff,A.phentsize*A.phnum),Nc,A.phnum);Qc(new DataView(C.buffer,C.byteOffset+A.shoff,A.shentsize*A.shnum),Oc,A.shnum);C=A;n=r;r=C.entry;for(t of n)0!==t.type&&(1===t.type?t.paddr+t.memsz<g.memory_size[0]?(t.filesz&&(n=new Uint8Array(a,t.offset,t.filesz),g.write_blob(n,t.paddr)),x=Math.max(x,t.paddr+t.memsz),r===
C.entry&&t.vaddr<=r&&t.vaddr+t.memsz>r&&(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;n<l.length;n++)m+=l[n];l[h]=-m;return{name:"genroms/multiboot.bin",data:l}}};
@@ -702,22 +706,22 @@ Fc.prototype.lower_irq=function(){this.isr_status=0;this.pci.lower_irq(this.pci_
Y.prototype.get_state=function(){const a=[];a[0]=this.size;a[1]=this.size_supported;a[2]=this.enabled;a[3]=this.notify_offset;a[4]=this.desc_addr;a[5]=this.avail_addr;a[6]=this.avail_last_idx;a[7]=this.used_addr;a[8]=this.num_staged_replies;a[9]=1;return a};
Y.prototype.set_state=function(a){this.size=a[0];this.size_supported=a[1];this.enabled=a[2];this.notify_offset=a[3];this.desc_addr=a[4];this.avail_addr=a[5];this.avail_last_idx=a[6];this.used_addr=a[7];this.num_staged_replies=a[8];this.mask=this.size-1;this.fix_wrapping=1!==a[9]};Y.prototype.reset=function(){this.enabled=!1;this.num_staged_replies=this.used_addr=this.avail_last_idx=this.avail_addr=this.desc_addr=0;this.set_size(this.size_supported)};
Y.prototype.is_configured=function(){return this.desc_addr&&this.avail_addr&&this.used_addr};Y.prototype.enable=function(){this.is_configured();this.enabled=!0};Y.prototype.set_size=function(a){this.size=a;this.mask=a-1};Y.prototype.count_requests=function(){this.fix_wrapping&&(this.fix_wrapping=!1,this.avail_last_idx=(this.avail_get_idx()&~this.mask)+(this.avail_last_idx&this.mask));return this.avail_get_idx()-this.avail_last_idx&65535};Y.prototype.has_request=function(){return 0!==this.count_requests()};
Y.prototype.pop_request=function(){this.has_request();var a=this.avail_get_entry(this.avail_last_idx);a=new ed(this,a);this.avail_last_idx=this.avail_last_idx+1&65535;return a};Y.prototype.push_reply=function(a){const b=this.used_get_idx()+this.num_staged_replies&this.mask;this.used_set_entry(b,a.head_idx,a.length_written);this.num_staged_replies++};
Y.prototype.pop_request=function(){this.has_request();var a=this.avail_get_entry(this.avail_last_idx);a=new fd(this,a);this.avail_last_idx=this.avail_last_idx+1&65535;return a};Y.prototype.push_reply=function(a){const b=this.used_get_idx()+this.num_staged_replies&this.mask;this.used_set_entry(b,a.head_idx,a.length_written);this.num_staged_replies++};
Y.prototype.flush_replies=function(){if(0!==this.num_staged_replies){var a=this.used_get_idx()+this.num_staged_replies&65535;this.used_set_idx(a);this.num_staged_replies=0;this.virtio.is_feature_negotiated(29)?(this.avail_get_used_event(),this.virtio.raise_irq(1)):~this.avail_get_flags()&1&&this.virtio.raise_irq(1)}};Y.prototype.notify_me_after=function(a){a=this.avail_get_idx()+a&65535;this.used_set_avail_event(a)};
Y.prototype.get_descriptor=function(a,b){return{addr_low:this.cpu.read32s(a+16*b),addr_high:this.cpu.read32s(a+16*b+4),len:this.cpu.read32s(a+16*b+8),flags:this.cpu.read16(a+16*b+12),next:this.cpu.read16(a+16*b+14)}};Y.prototype.avail_get_flags=function(){return this.cpu.read16(this.avail_addr)};Y.prototype.avail_get_idx=function(){return this.cpu.read16(this.avail_addr+2)};Y.prototype.avail_get_entry=function(a){return this.cpu.read16(this.avail_addr+4+2*(a&this.mask))};
Y.prototype.avail_get_used_event=function(){return this.cpu.read16(this.avail_addr+4+2*this.size)};Y.prototype.used_get_flags=function(){return this.cpu.read16(this.used_addr)};Y.prototype.used_set_flags=function(a){this.cpu.write16(this.used_addr,a)};Y.prototype.used_get_idx=function(){return this.cpu.read16(this.used_addr+2)};Y.prototype.used_set_idx=function(a){this.cpu.write16(this.used_addr+2,a)};
Y.prototype.used_set_entry=function(a,b,c){this.cpu.write32(this.used_addr+4+8*a,b);this.cpu.write32(this.used_addr+8+8*a,c)};Y.prototype.used_set_avail_event=function(a){this.cpu.write16(this.used_addr+4+8*this.size,a)};
function ed(a,b){this.cpu=a.cpu;this.virtio=a.virtio;this.head_idx=b;this.read_buffers=[];this.length_readable=this.read_buffer_offset=this.read_buffer_idx=0;this.write_buffers=[];this.length_writable=this.length_written=this.write_buffer_offset=this.write_buffer_idx=0;let c=a.desc_addr,d=0,e=a.size,f=!1;const g=this.virtio.is_feature_negotiated(28);do{const h=a.get_descriptor(c,b);y(h.addr_high,8);y(h.addr_low,8);y(h.len,8);y(h.flags,4);y(h.next,4);if(g&&h.flags&4)c=h.addr_low,d=b=0,e=h.len/16;else{if(h.flags&
function fd(a,b){this.cpu=a.cpu;this.virtio=a.virtio;this.head_idx=b;this.read_buffers=[];this.length_readable=this.read_buffer_offset=this.read_buffer_idx=0;this.write_buffers=[];this.length_writable=this.length_written=this.write_buffer_offset=this.write_buffer_idx=0;let c=a.desc_addr,d=0,e=a.size,f=!1;const g=this.virtio.is_feature_negotiated(28);do{const h=a.get_descriptor(c,b);y(h.addr_high,8);y(h.addr_low,8);y(h.len,8);y(h.flags,4);y(h.next,4);if(g&&h.flags&4)c=h.addr_low,d=b=0,e=h.len/16;else{if(h.flags&
2)f=!0,this.write_buffers.push(h),this.length_writable+=h.len;else{if(f)break;this.read_buffers.push(h);this.length_readable+=h.len}d++;if(d>e)break;if(h.flags&1)b=h.next;else break}}while(1)}
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<m;h++)g.push("s");c=I(g,b,c);b=this.fids[f].inodeid;g=9;var n=0;for(h=0;h<m;h++){b=this.fs.Search(b,c[h]);if(-1===b)break;g+=G(["Q"],[this.fs.GetInode(b).qid],this.replybuffer,g);n++;this.fids[l]=this.Createfid(b,1,this.fids[f].uid,c[h])}G(["h"],[n],this.replybuffer,7);this.BuildReply(e,d,g-7);this.SendReply(a);break;case 120:h=I(["w"],b,c);this.fids[h[0]]&&0<=this.fids[h[0]].inodeid&&(await this.fs.CloseInode(this.fids[h[0]].inodeid),
this.fids[h[0]].inodeid=-1,this.fids[h[0]].type=-1);this.BuildReply(e,d,0);this.SendReply(a);break;case 32:h=I(["w","s","d","w"],b,c);f=h[0];this.fids[f].type=2;this.BuildReply(e,d,0);this.SendReply(a);break;case 30:I(["w","w","s"],b,c),this.SendError(d,"Setxattr not supported",95),this.SendReply(a)}};
function cd(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=fd(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]}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;a<this.send_queue.length;a++)this.send(this.send_queue[a]);this.send_queue=[]};dd.prototype.handle_error=function(){};dd.prototype.destroy=function(){this.destroyed=!0;this.socket&&this.socket.close()};
dd.prototype.connect=function(){if("undefined"!==typeof WebSocket){if(this.socket){var a=this.socket.readyState;if(0===a||1===a)return}a=Date.now();if(!(this.last_connect_attempt+this.reconnect_interval>a)){this.last_connect_attempt=Date.now();try{this.socket=new WebSocket(this.url)}catch(b){console.error(b);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;a<this.send_queue.length;a++)this.send(this.send_queue[a]);this.send_queue=[]};ed.prototype.handle_error=function(){};ed.prototype.destroy=function(){this.destroyed=!0;this.socket&&this.socket.close()};
ed.prototype.connect=function(){if("undefined"!==typeof WebSocket){if(this.socket){var a=this.socket.readyState;if(0===a||1===a)return}a=Date.now();if(!(this.last_connect_attempt+this.reconnect_interval>a)){this.last_connect_attempt=Date.now();try{this.socket=new WebSocket(this.url)}catch(b){console.error(b);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);

View File

@@ -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)) {

View File

@@ -110,6 +110,7 @@ export class SmbSession {
// consult it so clicking "15UNDE~2.PDF" finds the right long-named file.
private sfnMaps = new Map<string, Map<string, string>>();
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<string, Uint8Array>;
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: "<tools>", 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);
}

View File

@@ -1,5 +1,6 @@
{
"compilerOptions": {
"rootDir": ".",
"outDir": "./dist",
"allowJs": true,
"allowSyntheticDefaultImports": true,